aboutsummaryrefslogtreecommitdiff
path: root/src/nix-build/nix-build.cc
diff options
context:
space:
mode:
authorFarid Zakaria <fmzakari@google.com>2021-08-06 15:30:49 -0700
committerFarid Zakaria <fmzakari@google.com>2021-08-06 15:30:49 -0700
commitfbf42c55acf1fe1f9f39aee091133b8e7931843f (patch)
treec00316702cf07dba6bdb25db547a077f2ab3cb3e /src/nix-build/nix-build.cc
parente277c0c479d58bcd0f55e71ec9ebe43a6161a1d4 (diff)
nix-shell --pure: Let it work for any derivation
`nix-shell --pure` when applied to a non stdenv derivation doesn't seem to clear the PATH. It expects the stdenv/setup file to do so. This adds an explicit `unset PATH` by nix-build.cc (nix-shell) itself so that it's not reliant on stdenv/setup anymore. This does not break impure nix-shell since the PATH is persisted as the variable `p` prior in the bash rcfile fixes #5092
Diffstat (limited to 'src/nix-build/nix-build.cc')
-rwxr-xr-xsrc/nix-build/nix-build.cc3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc
index 9e3538394..77594f046 100755
--- a/src/nix-build/nix-build.cc
+++ b/src/nix-build/nix-build.cc
@@ -489,6 +489,9 @@ static void main_nix_build(int argc, char * * argv)
"_nix_shell_clean_tmpdir; ") +
(pure ? "" : "[ -n \"$PS1\" ] && [ -e ~/.bashrc ] && source ~/.bashrc;") +
"%2%"
+ // always clear PATH.
+ // when nix-shell is run impure, we rehydrate it with the `p=$PATH` above
+ "unset PATH;"
"dontAddDisableDepTrack=1;\n"
+ structuredAttrsRC +
"\n[ -e $stdenv/setup ] && source $stdenv/setup; "