1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-29 23:13:14 +02:00

print-dev-env: Avoid using unbound shellHook variable

Some tools which consume the "nix print-dev-env" rc script (such as
"nix-direnv") are sensitive to the use of unbound variables. They use
"set -u".

The "nix print-dev-env" rc script initially unsets "shellHook", then
loads variables from the derivation, and then evaluates "shellHook".
However, most derivations don't have a "shellHook" attribute.

So users get the error "shellHook: unbound variable". This can be
demonstrated with the command:

    nix print-dev-env nixpkgs#hello | bash -u

This commit changes the rc script to provide an empty fallback value
for the "shellHook" variable.

Closes: #7951 #8253
This commit is contained in:
Rodney Lorrimar 2024-02-04 12:02:06 +08:00
parent 49cf090cb2
commit e1131b5927
No known key found for this signature in database
GPG key ID: D8B75C95FB4D1143
2 changed files with 3 additions and 3 deletions

View file

@ -354,7 +354,7 @@ struct Common : InstallableCommand, MixProfile
for (auto & i : {"TMP", "TMPDIR", "TEMP", "TEMPDIR"})
out << fmt("export %s=\"$NIX_BUILD_TOP\"\n", i);
out << "eval \"$shellHook\"\n";
out << "eval \"${shellHook:-}\"\n";
auto script = out.str();