1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-24 22:11:15 +02:00

Add a straightforward way to determine if inside a nix3 shell

This commit is contained in:
Ersei Saggi 2024-12-03 16:06:41 -05:00
parent ff00eebb16
commit 1e77a8dd91
No known key found for this signature in database
GPG key ID: 023FF4C1A9D6BAFD
3 changed files with 4 additions and 0 deletions

View file

@ -361,6 +361,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); });

View file

@ -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' \

View file

@ -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' \