From fbf42c55acf1fe1f9f39aee091133b8e7931843f Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Fri, 6 Aug 2021 15:30:49 -0700 Subject: [PATCH] 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 --- src/nix-build/nix-build.cc | 3 +++ 1 file changed, 3 insertions(+) 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; "