From 22d3587f3b850e8fc34add4d8e62911c6598ad78 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 12 Jul 2005 16:06:25 +0000 Subject: [PATCH] * 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). --- src/nix-instantiate/main.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/nix-instantiate/main.cc b/src/nix-instantiate/main.cc index 3e9fad4ae..3161d17f4 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"); }