From dcc37c236c66ba463bd61fec23d046485d8a412f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 1 Feb 2005 12:36:25 +0000 Subject: * 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. --- scripts/nix-build.in | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/nix-build.in b/scripts/nix-build.in index 5ae591f35168..33fbc61a3d20 100644 --- a/scripts/nix-build.in +++ b/scripts/nix-build.in @@ -10,6 +10,9 @@ fi extraArgs= noLink= +userName=$USER +if test -z "$username"; then userName="unknown"; fi + for i in "$@"; do case "$i" in --no-link) @@ -19,11 +22,15 @@ for i in "$@"; do extraArgs="$extraArgs $i" ;; *) - storeExprs=$(@bindir@/nix-instantiate "$i") + storeExprs=$(@bindir@/nix-instantiate \ + --add-root "@localstatedir@/nix/gcroots/nix-build/$userName-drv" \ + "$i") for j in $storeExprs; do echo "store expression is $j" >&2 done - outPaths=$(@bindir@/nix-store -rv $extraArgs $storeExprs) + outPaths=$(@bindir@/nix-store \ + --add-root "@localstatedir@/nix/gcroots/nix-build/$userName-out" \ + -rv $extraArgs $storeExprs) for j in $outPaths; do echo "$j" if test -z "$noLink"; then -- cgit 1.4.1