about summary refs log tree commit diff
path: root/src/nix-instantiate
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-07-12T16·06+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-07-12T16·06+0000
commit22d3587f3b850e8fc34add4d8e62911c6598ad78 (patch)
tree57fa568df896e82c7fb575d08fad78d039d86830 /src/nix-instantiate
parent928a7c06dc830455c246e1ccb8fd980c882b1637 (diff)
* In nix-instantiate, at top-level, call functions that have arguments
  with default values automatically.  I.e., e -> e {}.

  This feature makes convenience expressions such as
  pkgs/system/i686-linux.nix in Nixpkgs obsolete, since we can just do

  $ nix-instantiate ./pkgs/system/all-packages.nix

  since all-packages.nix takes a single argument (system) that has a
  default value (__thisSystem).

Diffstat (limited to 'src/nix-instantiate')
-rw-r--r--src/nix-instantiate/main.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/nix-instantiate/main.cc b/src/nix-instantiate/main.cc
index 3e9fad4ae4c3..3161d17f42ec 100644
--- a/src/nix-instantiate/main.cc
+++ b/src/nix-instantiate/main.cc
@@ -73,6 +73,23 @@ static void printDrvPaths(EvalState & state, Expr e)
         return;
     }
 
+    ATermList formals;
+    ATerm body, pos;
+    if (matchFunction(e, formals, body, pos)) {
+        for (ATermIterator i(formals); i; ++i) {
+            Expr name, def;
+            if (matchNoDefFormal(*i, name))
+                throw Error(format("expression evaluates to a function with no-default arguments (`%1%')")
+                    % aterm2String(name));
+            else if (!matchDefFormal(*i, name, def))
+                abort(); /* can't happen */
+        }
+
+        printDrvPaths(state, evalExpr(state,
+            makeCall(e, makeAttrs(ATermMap()))));
+        return;
+    }
+
     throw Error("expression does not evaluate to one or more derivations");
 }