mirror of
https://github.com/NixOS/nix.git
synced 2024-11-22 06:42:28 +00:00
* The `import' primop now accepts derivations. These are first
realised, and then the file at the derivation's output path is loaded as a Nix expression.
This commit is contained in:
parent
321be4649d
commit
fa50c0849e
@ -6,9 +6,35 @@
|
||||
Expr primImport(EvalState & state, Expr arg)
|
||||
{
|
||||
ATMatcher m;
|
||||
string path;
|
||||
if (!(atMatch(m, arg) >> "Path" >> path))
|
||||
throw Error("path expected");
|
||||
ATermList es;
|
||||
Path path;
|
||||
|
||||
arg = evalExpr(state, arg);
|
||||
|
||||
if (atMatch(m, arg) >> "Path" >> path)
|
||||
;
|
||||
|
||||
else if (atMatch(m, arg) >> "Attrs" >> es) {
|
||||
Expr a = queryAttr(arg, "type");
|
||||
|
||||
/* If it is a derivation, we have to realise it and load the
|
||||
Nix expression created at the derivation's output path. */
|
||||
if (a && evalString(state, a) == "derivation") {
|
||||
a = queryAttr(arg, "drvPath");
|
||||
if (!a) throw Error("bad derivation in import");
|
||||
Path drvPath = evalPath(state, a);
|
||||
|
||||
realiseStoreExpr(drvPath);
|
||||
|
||||
a = queryAttr(arg, "outPath");
|
||||
if (!a) throw Error("bad derivation in import");
|
||||
path = evalPath(state, a);
|
||||
}
|
||||
}
|
||||
|
||||
if (path == "")
|
||||
throw Error("path or derivation expected in import");
|
||||
|
||||
return evalFile(state, path);
|
||||
}
|
||||
|
||||
@ -267,7 +293,7 @@ Expr primToString(EvalState & state, Expr arg)
|
||||
atMatch(m, arg) >> "Path" >> s ||
|
||||
atMatch(m, arg) >> "Uri" >> s)
|
||||
return ATmake("Str(<str>)", s.c_str());
|
||||
else throw Error("cannot coerce value to string");
|
||||
throw Error("cannot coerce value to string");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user