Closed pennae closed 4 months ago
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
When fetching a patch that contains a nix store path then the build just dies.
3.patch> building '/nix/store/5b7jcfdn1r147bjjvjvp4m6sp6a2f7sl-3.patch.drv'
3.patch>
3.patch> trying https://github.com/serokell/nix-diff/pull/3.patch
3.patch> % Total % Received % Xferd Average Speed Time Time Time Current
3.patch> Dload Upload Total Spent Left Speed
3.patch> 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
3.patch> 100 91015 0 91015 0 0 129k 0 --:--:-- --:--:-- --:--:-- 129k
error: unexpected end-of-file
There's a duplicate of this at https://github.com/NixOS/nix/issues/7150
In https://github.com/NixOS/nixpkgs/pull/241645 the reference is unintentional.
In a fetchClosure
call in a source that's fetched by FOD, this may happen too.
Both are cases of stray dependencies, and may be valid use cases for unsafeDiscardReferences
.
Regardless of that, it seems like a good idea for FOD functions to set allowedReferences
to [ ]
, so that the possibility of having fixed outputs with references is controlled by the expressions rather than a fairly arbitrary design or implementation decision.
And of course, the store needs to at least throw a proper error instead of relying on an assertion.
This appears to be fixed in current Nix (2.23):
nix-repl> :b let a = runCommand "a" { outputHashMode = "flat"; outputHashAlgo = "sha256"; outputHash = "sha256-Q1WkaxnTSNwvV8BG+O9j1FOOu5NgAPPJ7pV1J0YN2GU="; } "echo 1 ${bash} > $out"; in runCommand "b" {} "ls ${a} > $out"
error: fixed output derivation 'a' is not allowed to refer to other store paths.
You may need to use the 'unsafeDiscardReferences' derivation attribute, see the manual for more details.
nix-repl> :b let a = runCommand "a" { outputHashMode = "recursive"; outputHashAlgo = "sha256"; outputHash = "sha256-uCxlVcIPQdSr0mbcwNvsfk1ssvrgA/nK2AFNaCM8VjM="; } "echo 1 ${bash} > $out"; in runCommand "b" {} "ls ${a} >$out"
error: illegal path references in fixed-output derivation '/nix/store/awnqq6a22sad9p96pcrrhzbyr52b6ibi-a.drv'
error: 1 dependencies of derivation '/nix/store/0a6zvx07dkhzys1ap8pfq5akn9vkrbrl-b.drv' failed to build
nix-repl> :b let a = runCommand "a" { outputHashMode = "flat"; outputHashAlgo = "sha256"; outputHash = "sha256-Q1WkaxnTSNwvV8BG+O9j1FOOu5NgAPPJ7pV1J0YN2GU="; __structuredAttrs = true; unsafeDiscardReferences.out = true; } "echo 1 ${bash} > $out"; in runerror: hash mismatch in fixed-output derivation '/nix/store/wavkn1m3sl1y4lixqc3wnkvmzq65ca81-a.drv':
specified: sha256-Q1WkaxnTSNwvV8BG+O9j1FOOu5NgAPPJ7pV1J0YN2GU=
got: sha256-EFzFdQlZoue6mg6e9jY8WWF1reeI+ZbKOxowFSrc36c=
error: 1 dependencies of derivation '/nix/store/riynv93rm8sjqg8ixy511hln44m8hrsj-b.drv' failed to build
Describe the bug
building a FOD that contains input references either crashes nix or returns a nonexistant store path. crashes happen for FODs with flat hashing, recursively hashed FODs produce an invalid store path.
Steps To Reproduce
nix repl '<nixpkgs>'
:b let a = runCommand "a" { outputHashMode = "flat"; outputHashAlgo = "sha256"; outputHash = "sha256-Q1WkaxnTSNwvV8BG+O9j1FOOu5NgAPPJ7pV1J0YN2GU="; } "echo 1 ${bash} > $out"; in runCommand "b" {} "ls ${a} > $out"
: daemon crashes with assertion violation:b let a = runCommand "a" { outputHashMode = "recursive"; outputHashAlgo = "sha256"; outputHash = "sha256-uCxlVcIPQdSr0mbcwNvsfk1ssvrgA/nK2AFNaCM8VjM="; } "echo 1 ${bash} > $out"; in runCommand "b" {} "ls ${a} >$out"
:Expected behavior
maybe some error message about input references being disallowed in FODs.
nix-env --version
outputnix-env (Nix) 2.8.1
Additional context