Skip to content

Commit

Permalink
Merge pull request #3542 from mkenigs/gcroots
Browse files Browse the repository at this point in the history
Set GCROOT to store path to prevent garbage collection
  • Loading branch information
edolstra authored Apr 28, 2020
2 parents 52a3ca8 + 6d40fe5 commit 06849c3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/nix/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,15 @@ struct Common : InstallableCommand, MixProfile
}
}

BuildEnvironment getBuildEnvironment(ref<Store> store)
std::pair<BuildEnvironment, std::string> getBuildEnvironment(ref<Store> store)
{
auto shellOutPath = getShellOutPath(store);

auto strPath = store->printStorePath(shellOutPath);

updateProfile(shellOutPath);

return readEnvironment(store->printStorePath(shellOutPath));
return {readEnvironment(strPath), strPath};
}
};

Expand Down Expand Up @@ -253,7 +255,7 @@ struct CmdDevShell : Common, MixEnvironment

void run(ref<Store> store) override
{
auto buildEnvironment = getBuildEnvironment(store);
auto [buildEnvironment, gcroot] = getBuildEnvironment(store);

auto [rcFileFd, rcFilePath] = createTempFile("nix-shell");

Expand All @@ -276,6 +278,8 @@ struct CmdDevShell : Common, MixEnvironment
auto shell = getEnv("SHELL").value_or("bash");

setEnviron();
// prevent garbage collection until shell exits
setenv("NIX_GCROOT", gcroot.data(), 1);

auto args = Strings{std::string(baseNameOf(shell)), "--rcfile", rcFilePath};

Expand Down Expand Up @@ -307,7 +311,7 @@ struct CmdPrintDevEnv : Common

void run(ref<Store> store) override
{
auto buildEnvironment = getBuildEnvironment(store);
auto buildEnvironment = getBuildEnvironment(store).first;

stopProgressBar();

Expand Down

0 comments on commit 06849c3

Please sign in to comment.