aboutsummaryrefslogtreecommitdiff
path: root/home-manager
diff options
context:
space:
mode:
authorRobert Helgesson <robert@rycee.net>2017-09-04 22:19:56 +0200
committerRobert Helgesson <robert@rycee.net>2017-09-04 22:19:56 +0200
commit39fc16954b48ab2d59015c3615c71919e80bae7e (patch)
tree6eebea5b4b794ff3b00e6a51a51c20ebf734c2bb /home-manager
parentf5289c546e82507537b42f7b26eba2731966cb60 (diff)
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.
Diffstat (limited to 'home-manager')
-rw-r--r--home-manager/home-manager14
1 files changed, 12 insertions, 2 deletions
diff --git a/home-manager/home-manager b/home-manager/home-manager
index 2fbf057f873..8e0bd40c2d5 100644
--- a/home-manager/home-manager
+++ b/home-manager/home-manager
@@ -77,8 +77,18 @@ function doBuild() {
function doSwitch() {
local generation
local exitCode=0
-
- generation=$(doBuild "--no-out-link") && $generation/activate || exitCode=1
+ local wrkdir
+
+ # 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
}