You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Impurity: Hash of relative paths depends on parent directory name #166
Consider the following Nix expression, stored in default.nix:
with (import <nixpkgs> {});
writeText "out" ''
${./.}
''
Then look at the following console session:
/tmp/nixtest $ nix-build --no-out-link
these derivations will be built:
/nix/store/wvarg2d7f0dhfgz0wvwhm8ibzkb1pfrc-out.drv
building path(s) `/nix/store/1664687s61dyki8b1pqw8fa1k2314pwz-out'
�building /nix/store/1664687s61dyki8b1pqw8fa1k2314pwz-out
�/nix/store/1664687s61dyki8b1pqw8fa1k2314pwz-out
/tmp/nixtest $ cd ..
/tmp $ mv nixtest/ nixtest2
/tmp $ cd nixtest2/
/tmp/nixtest2 $ nix-build --no-out-link
these derivations will be built:
/nix/store/piwxsvbn6myy4xajazg0pwlh7k46sfzq-out.drv
building path(s) `/nix/store/4z5vzja4gk0mifrn4dxd2d17fwfsy86w-out'
�building /nix/store/4z5vzja4gk0mifrn4dxd2d17fwfsy86w-out
�/nix/store/4z5vzja4gk0mifrn4dxd2d17fwfsy86w-out
/tmp/nixtest2 $ cd ..
/tmp $ mv nixtest2/ nixtest
/tmp $ cd nixtest/
/tmp/nixtest $ nix-build --no-out-link
/nix/store/1664687s61dyki8b1pqw8fa1k2314pwz-out
As you can see, the hash of the build depends on the name of directory that contains default.nix. I had expected that only the files and directories contained inside this directory would matter. This is an impurity, I would say, since you can't recreate a build if you don't know the name of the directory that the build was originally performed in.
That's not really an impurity. As long as the name and contents of the file are the same, you should get the same hash. That the name might change is simply a reason not to use ./. in this case.
But the parent directory is not really part of the content, I think. If I clone Nix sources from github, should it really impact my build what I named the target directory?
My example may seem contrived, but I discovered this when building NixOS. I keep different NixOS configurations in the following directory layout:
let
nixos = import ./nixos {
nixpkgs = ./nixpkgs;
configuration = ./configuration.nix;
};
in {
inherit (nixos) system;
}
Then I can build a system in the following way:
cd machine1
nix-build -A system
But if I change the names of the machine1 or machine2 directories, I get a rebuild even though nothing that should have an impact on the build has changed.
Activity
edolstra commentedon Sep 4, 2013
That's not really an impurity. As long as the name and contents of the file are the same, you should get the same hash. That the name might change is simply a reason not to use ./. in this case.
rickynils commentedon Sep 4, 2013
But the parent directory is not really part of the content, I think. If I clone Nix sources from github, should it really impact my build what I named the target directory?
My example may seem contrived, but I discovered this when building NixOS. I keep different NixOS configurations in the following directory layout:
My
default.nixfiles contains the following:Then I can build a system in the following way:
But if I change the names of the
machine1ormachine2directories, I get a rebuild even though nothing that should have an impact on the build has changed.edolstra commentedon Feb 26, 2014
Closing since this is intended (if not always desirable) behaviour.
Merge pull request NixOS#166 from nix-dot-dev/rpi-firmware
Merge pull request NixOS#166 from DeterminateSystems/fixup-perpetual-…
doc/inventory: consolidate four-pass review into the catalog
doc/inventory: integrate 19 review reports and finalise resumption docs
v3 ARCH S1.1: confirm GcRoot is the relocation-aware movable-root han…