about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-10-10T15·07+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-10-10T15·07+0000
commitbd0c40e1e93d2239b44bd1f73c2587cd62e66e4d (patch)
tree0569c1671b4308f6e74ce1c1838a7e016813e14b /src/libexpr
parent7bada48b36a091bb30c905229e16df3c36c90d7d (diff)
* `import': unwrap the context. Necessary to make `import (x + y)'
  work, where x is a store path.

Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/primops.cc27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index babd6df37b8a..0b1ea7f39bf4 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -13,6 +13,16 @@
 namespace nix {
 
 
+static Expr unwrapContext(EvalState & state, Expr e, ATermList & context)
+{
+    context = ATempty;
+    e = evalExpr(state, e);
+    if (matchContext(e, context, e))
+        e = evalExpr(state, e);
+    return e;
+}
+
+
 static Expr primBuiltins(EvalState & state, const ATermVector & args)
 {
     /* Return an attribute set containing all primops.  This allows
@@ -43,8 +53,9 @@ static Expr primImport(EvalState & state, const ATermVector & args)
 {
     ATermList es;
     Path path;
-
-    Expr arg = evalExpr(state, args[0]), arg2;
+    ATermList context; /* don't care the context */
+    
+    Expr arg = unwrapContext(state, args[0], context), arg2;
     
     if (matchPath(arg, arg2))
         path = aterm2String(arg2);
@@ -67,7 +78,7 @@ static Expr primImport(EvalState & state, const ATermVector & args)
         }
     }
 
-    else throw TypeError("`import' requires a path or derivation as its argument");
+    else throw TypeError(format("argument of `import' is %1% while a path or derivation is required") % showType(arg));
 
     return evalFile(state, path);
 }
@@ -513,16 +524,6 @@ static Expr primToXML(EvalState & state, const ATermVector & args)
 }
 
 
-static Expr unwrapContext(EvalState & state, Expr e, ATermList & context)
-{
-    context = ATempty;
-    e = evalExpr(state, e);
-    if (matchContext(e, context, e))
-        e = evalExpr(state, e);
-    return e;
-}
-
-
 /* Store a string in the Nix store as a source file that can be used
    as an input by derivations. */
 static Expr primToFile(EvalState & state, const ATermVector & args)