about summary refs log tree commit diff
path: root/scripts/nix-build.in
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-02-01T13·48+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-02-01T13·48+0000
commit630ae0c9d7f65a2d6bef85a5194b4d704e54eded (patch)
tree1cbb2dce71e58abb4617239857bbd144b1f355c1 /scripts/nix-build.in
parentdcc37c236c66ba463bd61fec23d046485d8a412f (diff)
* nix-build: use an indirection scheme to make it easier for users to
  get rid of GC roots.  Nix-build places a symlink `result' in the
  current directory.  Previously, removing that symlink would not
  remove the store path being linked to as a GC root.  Now, the GC
  root created by nix-build is actually a symlink in
  `/nix/var/nix/gcroots/auto' to `result'.  So if that symlink is
  removed the GC root automatically becomes invalid (since it can no
  longer be resolved).  The root itself is not automatically removed -
  the garbage collector should delete dangling roots.

Diffstat (limited to 'scripts/nix-build.in')
-rw-r--r--scripts/nix-build.in45
1 files changed, 28 insertions, 17 deletions
diff --git a/scripts/nix-build.in b/scripts/nix-build.in
index 33fbc61a3d20..e11a88dcd0df 100644
--- a/scripts/nix-build.in
+++ b/scripts/nix-build.in
@@ -8,41 +8,52 @@ if test -z "$nixExpr"; then
 fi
 
 extraArgs=
-noLink=
+addDrvLink=0
+addOutLink=1
 
-userName=$USER
-if test -z "$username"; then userName="unknown"; fi
 
+trap 'rm -f ./.nix-build-tmp-*' EXIT
+
+
+# Process the arguments.
 for i in "$@"; do
     case "$i" in
+    
+        --add-drv-link)
+            addDrvLink=1
+            ;;
+            
         --no-link)
-            noLink=1
+            addOutLink=0
             ;;
+            
         -*)
             extraArgs="$extraArgs $i"
             ;;
+            
         *)
+            # Instantiate the Nix expression.
+            prefix=
+            if test "$addDrvLink" = 0; then prefix=.nix-build-tmp-; fi
             storeExprs=$(@bindir@/nix-instantiate \
-                --add-root "@localstatedir@/nix/gcroots/nix-build/$userName-drv" \
+                --add-root ./${prefix}derivation --indirect \
                 "$i")
+                
             for j in $storeExprs; do
-                echo "store expression is $j" >&2
+                echo "store expression is $j $(readlink "$j")" >&2
             done
+
+            # Build the resulting store derivation.
+            prefix=
+            if test "$addOutLink" = 0; then prefix=.nix-build-tmp-; fi
             outPaths=$(@bindir@/nix-store \
-                --add-root "@localstatedir@/nix/gcroots/nix-build/$userName-out" \
+                --add-root ./${prefix}result --indirect \
                 -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
+                echo "$j $(readlink "$j")"
             done
+            
             ;;
     esac
 done