diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 31f64fd5a..7361e58b5 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -360,6 +360,8 @@ void MixEnvironment::setEnviron() for (const auto & [name, value] : setVars) env[name] = value; + env["IN_NIX_SHELL"] = ignoreEnvironment ? "pure" : "impure"; + if (!unsetVars.empty()) std::erase_if(env, [&](const auto & var) { return unsetVars.contains(var.first); }); diff --git a/tests/functional/flakes/run.sh b/tests/functional/flakes/run.sh index c92ddca2b..b9e12ef07 100755 --- a/tests/functional/flakes/run.sh +++ b/tests/functional/flakes/run.sh @@ -43,6 +43,7 @@ nix run -f shell-hello.nix env > $TEST_ROOT/actual-env # - __CF_USER_TEXT_ENCODING is set by macOS and is beyond our control sed -i \ -e 's/PATH=.*/PATH=.../' \ + -e '/^IN_NIX_SHELL=.*/d' \ -e 's/_=.*/_=.../' \ -e '/^TMPDIR=\/var\/folders\/.*/d' \ -e '/^__CF_USER_TEXT_ENCODING=.*$/d' \ diff --git a/tests/functional/shell.sh b/tests/functional/shell.sh index 51032ff1b..043ab0c9c 100755 --- a/tests/functional/shell.sh +++ b/tests/functional/shell.sh @@ -36,6 +36,7 @@ nix shell -f shell-hello.nix hello -c env > "$TEST_ROOT/actual-env" # - __CF_USER_TEXT_ENCODING is set by macOS and is beyond our control sed -i \ -e 's/PATH=.*/PATH=.../' \ + -e '/^IN_NIX_SHELL=.*/d' \ -e 's/_=.*/_=.../' \ -e '/^TMPDIR=\/var\/folders\/.*/d' \ -e '/^__CF_USER_TEXT_ENCODING=.*$/d' \