mirror of
https://github.com/nix-community/home-manager
synced 2024-11-26 21:19:45 +01:00
home-manager: make sure switch generation is GC root
Using `--no-out-link` is convenient but it does not set up a GC root, so an unfortunately timed GC could remove the generation before activation completes. Many thanks to @nonsequitur for noting this problem.
This commit is contained in:
parent
f5289c546e
commit
39fc16954b
1 changed files with 11 additions and 1 deletions
|
@ -77,8 +77,18 @@ function doBuild() {
|
|||
function doSwitch() {
|
||||
local generation
|
||||
local exitCode=0
|
||||
local wrkdir
|
||||
|
||||
generation=$(doBuild "--no-out-link") && $generation/activate || exitCode=1
|
||||
# Build the generation and run the activate script. Note, we
|
||||
# specify an output link si that it is treated as a GC root. This
|
||||
# prevents an unfortunately timed GC from removing the generation
|
||||
# before activation completes.
|
||||
wrkdir="$(mktemp -d)"
|
||||
generation=$(doBuild "-o $wrkdir/result") && $generation/activate || exitCode=1
|
||||
|
||||
# Because the previous command never fails, the script keeps
|
||||
# running and $wrkdir is always removed.
|
||||
rm -r "$wrkdir"
|
||||
|
||||
return $exitCode
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue