From dd8a2e89a0e4b0a1638826065a4b78022e5b60e6 Mon Sep 17 00:00:00 2001 From: John Soo Date: Thu, 21 Apr 2022 11:41:31 -0700 Subject: [PATCH] Simplify top-level value fetching. --- src/nix-eval-jobs.cc | 43 +++++++------------------------------------ 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/src/nix-eval-jobs.cc b/src/nix-eval-jobs.cc index 59d15dc..8ef43b2 100644 --- a/src/nix-eval-jobs.cc +++ b/src/nix-eval-jobs.cc @@ -162,6 +162,12 @@ static Value* flakeTopLevelValue(EvalState & state, Bindings & autoArgs) { return vRoot; } +Value * topLevelValue(EvalState & state, Bindings & autoArgs) { + return myArgs.flake + ? flakeTopLevelValue(state, autoArgs) + : releaseExprTopLevelValue(state, autoArgs); +} + static void worker( EvalState & state, Bindings & autoArgs, @@ -169,42 +175,7 @@ static void worker( AutoCloseFD & from, const Path &gcRootsDir) { - Value vTop; - - if (myArgs.flake) { - 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); - 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; - } - - } else { - state.evalFile(lookupFileArg(state, myArgs.releaseExpr), vTop); - } - - auto vRoot = state.allocValue(); - state.autoCallFunction(autoArgs, vTop, *vRoot); + auto vRoot = topLevelValue(state, autoArgs); while (true) { /* Wait for the master to send us a job name. */