mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 06:52:43 +01: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
1 changed files with 30 additions and 4 deletions
|
|
@ -6,9 +6,35 @@
|
||||||
Expr primImport(EvalState & state, Expr arg)
|
Expr primImport(EvalState & state, Expr arg)
|
||||||
{
|
{
|
||||||
ATMatcher m;
|
ATMatcher m;
|
||||||
string path;
|
ATermList es;
|
||||||
if (!(atMatch(m, arg) >> "Path" >> path))
|
Path path;
|
||||||
throw Error("path expected");
|
|
||||||
|
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);
|
return evalFile(state, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -267,7 +293,7 @@ Expr primToString(EvalState & state, Expr arg)
|
||||||
atMatch(m, arg) >> "Path" >> s ||
|
atMatch(m, arg) >> "Path" >> s ||
|
||||||
atMatch(m, arg) >> "Uri" >> s)
|
atMatch(m, arg) >> "Uri" >> s)
|
||||||
return ATmake("Str(<str>)", s.c_str());
|
return ATmake("Str(<str>)", s.c_str());
|
||||||
else throw Error("cannot coerce value to string");
|
throw Error("cannot coerce value to string");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue