1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

Merge pull request #13916 from sinanmohd/fix/develop-interactive-shell

nix/develop: pass down the interactive shell to subshells
This commit is contained in:
Jörg Thalheim 2025-09-07 10:14:25 +02:00 committed by GitHub
commit 5ae1b5f88b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -627,13 +627,12 @@ struct CmdDevelop : Common, MixEnvironment
fmt("[ -n \"$PS1\" ] && PS1+=%s;\n", escapeShellArgAlways(developSettings.bashPromptSuffix.get())); fmt("[ -n \"$PS1\" ] && PS1+=%s;\n", escapeShellArgAlways(developSettings.bashPromptSuffix.get()));
} }
writeFull(rcFileFd.get(), script);
setEnviron(); setEnviron();
// prevent garbage collection until shell exits // prevent garbage collection until shell exits
setEnv("NIX_GCROOT", gcroot.c_str()); setEnv("NIX_GCROOT", gcroot.c_str());
Path shell = "bash"; Path shell = "bash";
bool foundInteractive = false;
try { try {
auto state = getEvalState(); auto state = getEvalState();
@ -656,19 +655,17 @@ struct CmdDevelop : Common, MixEnvironment
Strings{"legacyPackages." + settings.thisSystem.get() + "."}, Strings{"legacyPackages." + settings.thisSystem.get() + "."},
nixpkgsLockFlags); nixpkgsLockFlags);
bool found = false;
for (auto & path : Installable::toStorePathSet( for (auto & path : Installable::toStorePathSet(
getEvalStore(), store, Realise::Outputs, OperateOn::Output, {bashInstallable})) { getEvalStore(), store, Realise::Outputs, OperateOn::Output, {bashInstallable})) {
auto s = store->printStorePath(path) + "/bin/bash"; auto s = store->printStorePath(path) + "/bin/bash";
if (pathExists(s)) { if (pathExists(s)) {
shell = s; shell = s;
found = true; foundInteractive = true;
break; break;
} }
} }
if (!found) if (!foundInteractive)
throw Error("package 'nixpkgs#bashInteractive' does not provide a 'bin/bash'"); throw Error("package 'nixpkgs#bashInteractive' does not provide a 'bin/bash'");
} catch (Error &) { } catch (Error &) {
@ -678,6 +675,11 @@ struct CmdDevelop : Common, MixEnvironment
// Override SHELL with the one chosen for this environment. // Override SHELL with the one chosen for this environment.
// This is to make sure the system shell doesn't leak into the build environment. // This is to make sure the system shell doesn't leak into the build environment.
setEnv("SHELL", shell.c_str()); setEnv("SHELL", shell.c_str());
// https://github.com/NixOS/nix/issues/5873
script += fmt("SHELL=\"%s\"\n", shell);
if (foundInteractive)
script += fmt("PATH=\"%s${PATH:+:$PATH}\"\n", std::filesystem::path(shell).parent_path());
writeFull(rcFileFd.get(), script);
#ifdef _WIN32 // TODO re-enable on Windows #ifdef _WIN32 // TODO re-enable on Windows
throw UnimplementedError("Cannot yet spawn processes on Windows"); throw UnimplementedError("Cannot yet spawn processes on Windows");