mirror of
https://github.com/NixOS/nix
synced 2025-06-27 04:21:16 +02:00
* nix-store, nix-instantiate: added an option `--add-root' to
immediately add the result as a permanent GC root. This is the only way to prevent a race with the garbage collector. For instance, the old style ln -s $(nix-store -r $(nix-instantiate foo.nix)) \ /nix/var/nix/gcroots/result has two time windows in which the garbage collector can interfere (by GC'ing the derivation and the output, respectively). On the other hand, nix-store --add-root /nix/var/nix/gcroots/result -r \ $(nix-instantiate --add-root /nix/var/nix/gcroots/drv \ foo.nix) is safe. * nix-build: use `--add-root' to prevent GC races.
This commit is contained in:
parent
a6b65fd5e1
commit
dcc37c236c
11 changed files with 165 additions and 17 deletions
|
@ -31,6 +31,28 @@ void sigintHandler(int signo)
|
|||
}
|
||||
|
||||
|
||||
Path makeRootName(const Path & gcRoot, int & counter)
|
||||
{
|
||||
counter++;
|
||||
if (counter == 1)
|
||||
return gcRoot;
|
||||
else
|
||||
return (format("%1%-%2%") % gcRoot % counter).str();
|
||||
}
|
||||
|
||||
|
||||
void printGCWarning()
|
||||
{
|
||||
static bool warned = false;
|
||||
if (!warned) {
|
||||
printMsg(lvlInfo,
|
||||
"warning: you did not specify `--add-root'; "
|
||||
"the result might be removed by the garbage collector");
|
||||
warned = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setLogType(string lt)
|
||||
{
|
||||
if (lt == "pretty") logType = ltPretty;
|
||||
|
@ -183,7 +205,7 @@ static void initAndRun(int argc, char * * argv)
|
|||
|
||||
/* Automatically clean up the temporary roots file when we
|
||||
exit. */
|
||||
RemoveTempRoots removeTempRoots;
|
||||
RemoveTempRoots removeTempRoots; /* unused variable - don't remove */
|
||||
|
||||
run(remaining);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue