Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/manual/src/release-notes/rl-next.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
arguments will be ignored and the resulting derivation will have
`__impure` set to `true`, making it an impure derivation.

* `nix-shell` now spawns a child process instead of `exec`ing immediately.

* `nix-shell` creates temp roots for as long as the executed shell
process is alive.
23 changes: 21 additions & 2 deletions src/nix-build/nix-build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,28 @@ static void main_nix_build(int argc, char * * argv)

logger->stop();

execvp(shell->c_str(), argPtrs.data());
pid_t pid = fork();

throw SysError("executing shell '%s'", *shell);
if (pid == -1)
throw SysError("forking shell");

if (pid == 0) {
for (auto & [outputName, output] : drv.outputsAndOptPaths(*store))
if (output.second) store->addTempRoot(*output.second);

execvp(shell->c_str(), argPtrs.data());

throw SysError("executing shell '%s'", *shell);
}

siginfo_t shellStatus;

auto shellExited = waitid(P_PID, pid, &shellStatus, WEXITED);

if (shellExited == -1)
throw SysError("waiting on shell");

throw Exit(shellStatus.si_status);
}

else {
Expand Down
3 changes: 3 additions & 0 deletions tests/nix-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ chmod a+rx $TEST_ROOT/spaced\ \\\'\"shell.shebang.rb
output=$($TEST_ROOT/spaced\ \\\'\"shell.shebang.rb abc ruby)
[ "$output" = '-e load(ARGV.shift) -- '"$TEST_ROOT"'/spaced \'\''"shell.shebang.rb abc ruby' ]

# Text nix-shell --run preserves exit code
test ! $(nix-shell -p foo --run 'exit 1')

# Test 'nix develop'.
nix develop -f "$shellDotNix" shellDrv -c bash -c '[[ -n $stdenv ]]'

Expand Down