dcc37c236c
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.
48 lines
1.2 KiB
Text
48 lines
1.2 KiB
Text
#! @shell@ -e
|
|
|
|
nixExpr=$1
|
|
|
|
if test -z "$nixExpr"; then
|
|
echo "syntax: $0 NIX-EXPR..." >&2
|
|
exit 1
|
|
fi
|
|
|
|
extraArgs=
|
|
noLink=
|
|
|
|
userName=$USER
|
|
if test -z "$username"; then userName="unknown"; fi
|
|
|
|
for i in "$@"; do
|
|
case "$i" in
|
|
--no-link)
|
|
noLink=1
|
|
;;
|
|
-*)
|
|
extraArgs="$extraArgs $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 \
|
|
--add-root "@localstatedir@/nix/gcroots/nix-build/$userName-out" \
|
|
-rv $extraArgs $storeExprs)
|
|
for j in $outPaths; do
|
|
echo "$j"
|
|
if test -z "$noLink"; then
|
|
if test -L result; then
|
|
rm result
|
|
elif test -e result; then
|
|
echo "cannot remove \`result' (not a symlink)"
|
|
exit 1
|
|
fi
|
|
ln -s "$j" result
|
|
fi
|
|
done
|
|
;;
|
|
esac
|
|
done
|