A store path is derived from the recipe (“derivation” in Nix lingo) to build the store path and not from its content.
Different recipes (derivations) can produce identical store contents, but they’ll be stored under different paths. Example:
To find out why your derivations differ, copy the Libsystem derivation from machine A to machine B:
# Run the following on machine A
nix-instantiate '<nixpkgs>' -A stdenv.cc.libc
# => /nix/store/...-Libsystem-osx-10.12.6.drv
nix copy --no-check-sigs --to ssh://machine-b $(nix-instantiate '<nixpkgs>' -A stdenv.cc.libc)
# If you can't use SSH, try nix-store --export/import
Then run nix-diff on machine B to compare the derivations (.drv files):
nix-diff /nix/store/...-Libsystem-osx-10.12.6.drv $(nix-instantiate '<nixpkgs>' -A stdenv.cc.libc)
Thanks for the explanation. I went ahead and compared the derivations. It looks like path names for the dependencies are different in the derivations for the same package.
So i’m guessing this is due to some package that a lot of things depend on getting updated and causing a chain reaction. I noticed it is time based: the old stuff has different path hashes than the new stuff.
The problem is that sometimes I want to use a nix package on a computer at work that doesn’t have internet and packages must be installed in a special manual way, and it’s just so many things to install if I need duplicates of everything.
Is there any solution you can think of that updates some dependent package and keeps the same path for the parent package?
No. If the input changes, then the current package will change as well, even if it is a bit by bit copy of the one that was created using the old input.
The nix store gives you opportunity to adhere to this fact by beeing able to hardlink identical stuff. nix optimise-store will optimise and hardlink what is already in the store.
There is also auto-optimise-store in nix.conf which will optimise any path as you add it. This will of course take a bit longer than, but saves space and takes writes from the drive and might be healthier for SSD.