-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
nix develop silently breaks file side-effects in hooks #8987
Description
Describe the bug
In NixOS/nixpkgs#255192 I attemtped to create temporary file in setupHook to use it later in buildPhase. It works for nix build but fails in nix develop.
Looks like nix develop runs setup hook in a separate derivation which breaks this use case. Is it intentional? Should nixpkgs also run hook in a separate derivation to make the error more consistent? I did not see any documentation that forbids such side-effects in setup hooks.
Steps To Reproduce
Here is an example default.nix file:
{ pkgs ? import <nixpkgs> {} }:
let
hook = pkgs.stdenv.mkDerivation {
dontUnpack = true;
name = "hook-with-a-temp-file-side-effect";
setupHook = pkgs.writeScript "temp-file-creation-hook.sh" ''
file_with_important_bits="$NIX_BUILD_TOP/important-file"
echo "$NIX_BUILD_TOP" > "$file_with_important_bits"
'';
};
in
pkgs.stdenv.mkDerivation {
dontUnpack = true;
name = "package-uses-hook";
nativeBuildInputs = [ hook ];
postBuild = ''
echo file=$file_with_important_bits
cat $file_with_important_bits
cat $file_with_important_bits > $out
'';
}It defines a hook with a side-effect of a temporary file and the package that tries to read the temp file.
Good (nix-build):
$ nix build -f. -L
hook-with-a-temp-file-side-effect> patching sources
hook-with-a-temp-file-side-effect> updateAutotoolsGnuConfigScriptsPhase
hook-with-a-temp-file-side-effect> configuring
hook-with-a-temp-file-side-effect> no configure script, doing nothing
hook-with-a-temp-file-side-effect> building
hook-with-a-temp-file-side-effect> no Makefile or custom buildPhase, doing nothing
hook-with-a-temp-file-side-effect> installing
hook-with-a-temp-file-side-effect> no Makefile or custom installPhase, doing nothing
hook-with-a-temp-file-side-effect> post-installation fixup
package-uses-hook> patching sources
package-uses-hook> updateAutotoolsGnuConfigScriptsPhase
package-uses-hook> configuring
package-uses-hook> no configure script, doing nothing
package-uses-hook> building
package-uses-hook> no Makefile or custom buildPhase, doing nothing
package-uses-hook> file=/build/important-file
package-uses-hook> /build
package-uses-hook> installing
package-uses-hook> no Makefile or custom installPhase, doing nothing
package-uses-hook> post-installation fixup
package-uses-hook> shrinking RPATHs of ELF executables and libraries in /nix/store/krn74k3jdlh69gggjym6z1im73ivfn2k-package-uses-hook
package-uses-hook> checking for references to /build/ in /nix/store/krn74k3jdlh69gggjym6z1im73ivfn2k-package-uses-hook...
package-uses-hook> patching script interpreter paths in /nix/store/krn74k3jdlh69gggjym6z1im73ivfn2k-package-uses-hook
Bad (nix develop):
$ nix develop -f. -L
hook-with-a-temp-file-side-effect> patching sources
hook-with-a-temp-file-side-effect> updateAutotoolsGnuConfigScriptsPhase
hook-with-a-temp-file-side-effect> configuring
hook-with-a-temp-file-side-effect> no configure script, doing nothing
hook-with-a-temp-file-side-effect> building
hook-with-a-temp-file-side-effect> no Makefile or custom buildPhase, doing nothing
hook-with-a-temp-file-side-effect> installing
hook-with-a-temp-file-side-effect> no Makefile or custom installPhase, doing nothing
hook-with-a-temp-file-side-effect> post-installation fixup
$$ genericBuild
patching sources
updateAutotoolsGnuConfigScriptsPhase
configuring
no configure script, doing nothing
building
no Makefile or custom buildPhase, doing nothing
file=/build/important-file
cat: /build/important-file: No such file or directory
bash: /home/slyfox/dev/bugs/nix-setup-hook-file/outputs/out: No such file or directory
installing
no Makefile or custom installPhase, doing nothing
post-installation fixup
Note: I ran genericBuild explicitly here to run build phase.
Expected behavior
nix develop should run the hooks the same way nix build does.
nix-env (Nix) 2.17.0
Additional context
It looks like nix develop intentionally creates a separate $pkg-env derivation and dumps/restores bash variables this way.
Priorities
Add 👍 to issues you find important.