about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-02-10T17·37+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-02-10T17·37+0000
commit982399bb144ca1c6d21834fd9a6f61b49db1bfce (patch)
tree5e4080d581dec2cac6ecde92772fe50908e0550c
parentc6120352b3fd25380ff21726982e22b97ee43e0b (diff)
* Enable the --attr in nix-build as well (and add -A as an alias).
  Example:

    $ nix-build ./all-packages.nix -A xlibs.libX11

  So finally it's easy to perform a test build of a Nix expression!

-rw-r--r--scripts/nix-build.in21
-rw-r--r--src/nix-instantiate/main.cc2
2 files changed, 16 insertions, 7 deletions
diff --git a/scripts/nix-build.in b/scripts/nix-build.in
index cb7137a47bc3..5c02f765dc3c 100644
--- a/scripts/nix-build.in
+++ b/scripts/nix-build.in
@@ -3,6 +3,7 @@
 nixExpr=$1
 
 extraArgs=
+extraInstArgs=
 addDrvLink=0
 addOutLink=1
 
@@ -11,9 +12,11 @@ trap 'rm -f ./.nix-build-tmp-*' EXIT
 
 
 # Process the arguments.
-exprs=
-for i in "$@"; do
-    case "$i" in
+args=("$@")
+for ((i = 0; i < ${#args[*]}; )); do
+    arg=${args[$i]}
+    i=$((i + 1))
+    case "$arg" in
 
         --help)
             echo "syntax: $0 [NIX-EXPR...]" >&2
@@ -27,13 +30,19 @@ for i in "$@"; do
         --no-link)
             addOutLink=0
             ;;
+
+        --attr|-A)
+            arg2=${args[$i]}
+            i=$((i + 1))
+            extraInstArgs="$extraInstArgs $arg $arg2"
+            ;;
             
         -*)
-            extraArgs="$extraArgs $i"
+            extraArgs="$extraArgs $arg"
             ;;
             
         *)
-            exprs="$exprs $i"
+            exprs="$exprs $arg"
             ;;
     esac
 done
@@ -50,7 +59,7 @@ for i in $exprs; do
     if test "$addDrvLink" = 0; then prefix=.nix-build-tmp-; fi
     storeExprs=$(@bindir@/nix-instantiate \
         --add-root ./${prefix}derivation --indirect \
-        "$i")
+        $extraInstArgs "$i")
                 
     for j in $storeExprs; do
         echo "store expression is $(readlink "$j")" >&2
diff --git a/src/nix-instantiate/main.cc b/src/nix-instantiate/main.cc
index 7668958fca17..d73d0e613f72 100644
--- a/src/nix-instantiate/main.cc
+++ b/src/nix-instantiate/main.cc
@@ -84,7 +84,7 @@ void run(Strings args)
                 throw UsageError("`--add-root requires an argument");
             gcRoot = absPath(*i++);
         }
-        else if (arg == "--attr") {
+        else if (arg == "--attr" || arg == "-A") {
             if (i == args.end())
                 throw UsageError("`--attr requires an argument");
             attrPath = *i++;