From bd0c40e1e93d2239b44bd1f73c2587cd62e66e4d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 10 Oct 2006 15:07:23 +0000 Subject: [PATCH] * `import': unwrap the context. Necessary to make `import (x + y)' work, where x is a store path. --- src/libexpr/primops.cc | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index babd6df37..0b1ea7f39 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)