mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 15:56:18 +02:00
Commit 3000!
* Make the `derivation' primitive much more lazy. The expression `derivation attrs' now evaluates to (essentially) attrs // { type = "derivation"; outPath = derivation! attrs; drvPath = derivation! attrs; } where `derivation!' is a primop that does the actual derivation instantiation (i.e., it does what `derivation' used to do). The advantage is that it allows commands such as `nix-env -qa' and `nix-env -i' to be much faster since they no longer need to instantiate all derivations, just the `name' attribute. (However, `nix-env' doesn't yet take advantage of this since it still always evaluates the `outPath' and `drvPath' attributes). Also, this allows derivations to cyclically reference each other, for example, webServer = derivation { ... hostName = "svn.cs.uu.nl"; services = [svnService]; }; svnService = derivation { ... hostName = webServer.hostName; }; Previously, this would yield a black hole (infinite recursion).
This commit is contained in:
parent
6057b51835
commit
77557a6f06
1 changed files with 23 additions and 7 deletions
|
@ -213,14 +213,12 @@ static string concatStrings(const Strings & ss)
|
||||||
derivation; `drvPath' containing the path of the Nix expression;
|
derivation; `drvPath' containing the path of the Nix expression;
|
||||||
and `type' set to `derivation' to indicate that this is a
|
and `type' set to `derivation' to indicate that this is a
|
||||||
derivation. */
|
derivation. */
|
||||||
static Expr primDerivation(EvalState & state, const ATermVector & _args)
|
static Expr primDerivationStrict(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
startNest(nest, lvlVomit, "evaluating derivation");
|
startNest(nest, lvlVomit, "evaluating derivation");
|
||||||
|
|
||||||
ATermMap attrs;
|
ATermMap attrs;
|
||||||
Expr args = _args[0];
|
queryAllAttrs(evalExpr(state, args[0]), attrs, true);
|
||||||
args = evalExpr(state, args);
|
|
||||||
queryAllAttrs(args, attrs, true);
|
|
||||||
|
|
||||||
/* Build the derivation expression by processing the attributes. */
|
/* Build the derivation expression by processing the attributes. */
|
||||||
Derivation drv;
|
Derivation drv;
|
||||||
|
@ -341,10 +339,27 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
|
||||||
state.drvHashes[drvPath] = hashDerivationModulo(state, drv);
|
state.drvHashes[drvPath] = hashDerivationModulo(state, drv);
|
||||||
|
|
||||||
/* !!! assumes a single output */
|
/* !!! assumes a single output */
|
||||||
attrs.set("outPath", makeAttrRHS(makePath(toATerm(outPath)), makeNoPos()));
|
ATermMap outAttrs;
|
||||||
attrs.set("drvPath", makeAttrRHS(makePath(toATerm(drvPath)), makeNoPos()));
|
outAttrs.set("outPath", makeAttrRHS(makePath(toATerm(outPath)), makeNoPos()));
|
||||||
|
outAttrs.set("drvPath", makeAttrRHS(makePath(toATerm(drvPath)), makeNoPos()));
|
||||||
|
|
||||||
|
return makeAttrs(outAttrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static Expr primDerivationLazy(EvalState & state, const ATermVector & args)
|
||||||
|
{
|
||||||
|
Expr eAttrs = evalExpr(state, args[0]);
|
||||||
|
ATermMap attrs;
|
||||||
|
queryAllAttrs(eAttrs, attrs, true);
|
||||||
|
|
||||||
attrs.set("type", makeAttrRHS(makeStr(toATerm("derivation")), makeNoPos()));
|
attrs.set("type", makeAttrRHS(makeStr(toATerm("derivation")), makeNoPos()));
|
||||||
|
|
||||||
|
Expr drvStrict = makeCall(makeVar(toATerm("derivation!")), eAttrs);
|
||||||
|
|
||||||
|
attrs.set("outPath", makeAttrRHS(makeSelect(drvStrict, toATerm("outPath")), makeNoPos()));
|
||||||
|
attrs.set("drvPath", makeAttrRHS(makeSelect(drvStrict, toATerm("drvPath")), makeNoPos()));
|
||||||
|
|
||||||
return makeAttrs(attrs);
|
return makeAttrs(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,7 +453,8 @@ void EvalState::addPrimOps()
|
||||||
addPrimOp("__currentTime", 0, primCurrentTime);
|
addPrimOp("__currentTime", 0, primCurrentTime);
|
||||||
|
|
||||||
addPrimOp("import", 1, primImport);
|
addPrimOp("import", 1, primImport);
|
||||||
addPrimOp("derivation", 1, primDerivation);
|
addPrimOp("derivation!", 1, primDerivationStrict);
|
||||||
|
addPrimOp("derivation", 1, primDerivationLazy);
|
||||||
addPrimOp("baseNameOf", 1, primBaseNameOf);
|
addPrimOp("baseNameOf", 1, primBaseNameOf);
|
||||||
addPrimOp("toString", 1, primToString);
|
addPrimOp("toString", 1, primToString);
|
||||||
addPrimOp("isNull", 1, primIsNull);
|
addPrimOp("isNull", 1, primIsNull);
|
||||||
|
|
Loading…
Reference in a new issue