Make function to get top-level value from a flake.

This commit is contained in:
John Soo 2022-04-21 09:15:20 -07:00
parent 4a3d2e0008
commit e05e625411
No known key found for this signature in database
GPG key ID: D8A148F8CE4DDBC2

View file

@ -128,6 +128,40 @@ static Value* releaseExprTopLevelValue(EvalState & state, Bindings & autoArgs) {
return vRoot; return vRoot;
} }
static Value* flakeTopLevelValue(EvalState & state, Bindings & autoArgs) {
using namespace flake;
auto [flakeRef, fragment] = parseFlakeRefWithFragment(myArgs.releaseExpr, absPath("."));
auto vFlake = state.allocValue();
auto lockedFlake = lockFlake(state, flakeRef,
LockFlags {
.updateLockFile = false,
.useRegistries = false,
.allowMutable = false,
});
callFlake(state, lockedFlake, *vFlake);
auto vOutputs = vFlake->attrs->get(state.symbols.create("outputs"))->value;
state.forceValue(*vOutputs, noPos);
auto vTop = *vOutputs;
if (fragment.length() > 0) {
Bindings & bindings(*state.allocBindings(0));
auto [nTop, pos] = findAlongAttrPath(state, fragment, bindings, vTop);
if (!nTop)
throw Error("error: attribute '%s' missing", nTop);
vTop = *nTop;
}
auto vRoot = state.allocValue();
state.autoCallFunction(autoArgs, vTop, *vRoot);
return vRoot;
}
static void worker( static void worker(
EvalState & state, EvalState & state,
Bindings & autoArgs, Bindings & autoArgs,