diff options
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/primops.cc | 27 |
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) |