Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local path repository suddenly has a hash mismatch after GC #6061

Open
viraptor opened this issue Feb 8, 2022 · 4 comments
Open

Local path repository suddenly has a hash mismatch after GC #6061

viraptor opened this issue Feb 8, 2022 · 4 comments
Labels

Comments

@viraptor
Copy link

viraptor commented Feb 8, 2022

Describe the bug

I've been running nix develop on a package while trying to get it built. To clean up some space from temporary builds I've run nix store gc. This somehow broke the expected nix hashes.

Steps To Reproduce

I don't know if that's reproducible, but my actions were:

  1. Create a flake with local nixpkgs checkout:
{
  description = "foo";

  inputs = {
    nixpkgs.url = "path:/Users/viraptor/src/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";
  };
  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem
      (system:
        let pkgs = nixpkgs.legacyPackages.${system}; in
        {
          devShell = import ./shell.nix { inherit pkgs; };
        }
      );
}
  1. nix develop - works as expected
  2. nix store gc
  3. nix develop - gives:
error: NAR hash mismatch in input 'path:/Users/viraptor/src/nixpkgs?narHash=sha256-Cl79qBCjCZjmqRB8gZwRPu6gd5Y8w5YmMNMRjBLODas=' (/nix/store/5zax5bf87k99ag40p2s3kk5r9rgqbsvq-source), expected 'sha256-Cl79qBCjCZjmqRB8gZwRPu6gd5Y8w5YmMNMRjBLODas=', got 'sha256-6p9KNgnvuD/+u64TKoM1rf2a07dNoHXp7aL0cPJZWGA='

       … while realising the context of a path

       at «string»:20:19:

           19|
           20|           flake = import (sourceInfo + (if subdir != "" then "/" else "") + subdir + "/flake.nix");
             |                   ^
           21|

       … while evaluating anonymous lambda

       at «string»:10:13:

            9|     builtins.mapAttrs
           10|       (key: node:
             |             ^
           11|         let

       … from call site

       … while evaluating anonymous lambda

       at «string»:23:25:

           22|           inputs = builtins.mapAttrs
           23|             (inputName: inputSpec: allNodes.${resolveInput inputSpec})
             |                         ^
           24|             (node.inputs or {});

       … from call site

       … while evaluating anonymous lambda

       at /nix/store/i4flq9lpia5b55ik7zc834rbhdk27mvs-source/shell.nix:1:1:

            1| { pkgs ? import <nixpkgs> { } }:
             | ^
            2| with pkgs;

       … from call site

       at /nix/store/i4flq9lpia5b55ik7zc834rbhdk27mvs-source/flake.nix:14:22:

           13|         {
           14|           devShell = import ./shell.nix { inherit pkgs; };
             |                      ^
           15|         }

       … while evaluating the attribute 'devShell'

       at /nix/store/i4flq9lpia5b55ik7zc834rbhdk27mvs-source/flake.nix:14:11:

           13|         {
           14|           devShell = import ./shell.nix { inherit pkgs; };
             |           ^
           15|         }

Expected behavior

Pre and post gc the system should behave the same.

nix-env --version output

nix-env (Nix) 2.6.0

@viraptor viraptor added the bug label Feb 8, 2022
@viraptor viraptor changed the title Local path repository suddenly has a hash mismatch Local path repository suddenly has a hash mismatch after GC Feb 8, 2022
@colemickens
Copy link
Member

This can happen when you:

  • update the source for a package, but forget to update the hash
  • Nix accidentally lets you think you were building the updated pkg, even though you were still using the old cached source
  • GC runs and cleans up that source package with the real hash value
  • Nix will now re-acquire that source code package and notice that you gave it the wrong hash

that's at least one way you can wind up here. Beyond that. the implications get a lot more serious if there's something else going on.

@viraptor
Copy link
Author

viraptor commented Feb 8, 2022

Turns out that removing flake.lock allowed a rebuild, but it is a very confusing experience. /Users/viraptor/src/nixpkgs has not changed between both develop calls.

@stale stale bot added the stale label Aug 12, 2022
@samvv
Copy link

samvv commented Sep 1, 2024

I'm experiencing the same issue here. I kind of expect this workflow, as described by @colemickens, to just work while developing a package. The best example would probably be writing and testing the flake.nix itself.

Removing flake.lock did not fix the issue for me.

@stale stale bot removed the stale label Sep 1, 2024
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/going-crazy-on-flake-with-systemd-service/51488/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants