diff --git a/lix/legacy/nix-build.cc b/lix/legacy/nix-build.cc index db0cc80cc..c11ec1b9a 100644 --- a/lix/legacy/nix-build.cc +++ b/lix/legacy/nix-build.cc @@ -503,11 +503,13 @@ static int main_nix_build(AsyncIoRoot & aio, std::string programName, Strings ar auto rcfile = (Path) tmpDir + "/rc"; auto tz = getEnv("TZ"); std::string rc = - fmt("%1%" + fmt("#!%1%\n" + "%2%" // always clear PATH. // when nix-shell is run impure, we rehydrate it with the `p=$PATH` above "unset PATH;" "dontAddDisableDepTrack=1;\n", + *shell, (pure ? "" : "[ -n \"$PS1\" ] && [ -e ~/.bashrc ] && source ~/.bashrc; p=$PATH; ")); rc += structuredAttrsRC; rc += fmt( diff --git a/tests/functional/nix-shell/shell.nix b/tests/functional/nix-shell/shell.nix index 1beeb3357..dc756d0f5 100644 --- a/tests/functional/nix-shell/shell.nix +++ b/tests/functional/nix-shell/shell.nix @@ -63,14 +63,16 @@ let pkgs = rec { foo = runCommand "foo" {} '' mkdir -p $out/bin - echo 'echo ${fooContents}' > $out/bin/foo + echo '#!${shell}' >> $out/bin/foo + echo 'echo ${fooContents}' >> $out/bin/foo chmod a+rx $out/bin/foo ln -s ${shell} $out/bin/bash ''; bar = runCommand "bar" {} '' mkdir -p $out/bin - echo 'echo bar' > $out/bin/bar + echo '#!${shell}' > $out/bin/bar + echo 'echo bar' >> $out/bin/bar chmod a+rx $out/bin/bar ''; @@ -83,7 +85,8 @@ let pkgs = rec { # ruby "interpreter" that outputs "$@" ruby = runCommand "ruby" {} '' mkdir -p $out/bin - echo 'printf %s "$*"' > $out/bin/ruby + echo '#!${shell}' > $out/bin/ruby + echo 'printf %s "$*"' >> $out/bin/ruby chmod a+rx $out/bin/ruby ''; diff --git a/tests/functional/user-envs.builder.sh b/tests/functional/user-envs.builder.sh old mode 100644 new mode 100755 index 5fafa797f..b690b1248 --- a/tests/functional/user-envs.builder.sh +++ b/tests/functional/user-envs.builder.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash mkdir $out mkdir $out/bin echo "#! $shell" > $out/bin/$progName