From 4a3d2e00085722005323a08122d8babfee5b7240 Mon Sep 17 00:00:00 2001 From: John Soo Date: Thu, 21 Apr 2022 11:34:49 -0700 Subject: [PATCH 1/3] Make function to get top-level value from releaseExpr. --- src/nix-eval-jobs.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/nix-eval-jobs.cc b/src/nix-eval-jobs.cc index 51fb27e..2615f30 100644 --- a/src/nix-eval-jobs.cc +++ b/src/nix-eval-jobs.cc @@ -116,6 +116,18 @@ struct MyArgs : MixEvalArgs, MixCommonArgs static MyArgs myArgs; +static Value* releaseExprTopLevelValue(EvalState & state, Bindings & autoArgs) { + Value vTop; + + state.evalFile(lookupFileArg(state, myArgs.releaseExpr), vTop); + + auto vRoot = state.allocValue(); + + state.autoCallFunction(autoArgs, vTop, *vRoot); + + return vRoot; +} + static void worker( EvalState & state, Bindings & autoArgs, From e05e6254112abbec259e100d055075af87b1359f Mon Sep 17 00:00:00 2001 From: John Soo Date: Thu, 21 Apr 2022 09:15:20 -0700 Subject: [PATCH 2/3] Make function to get top-level value from a flake. --- src/nix-eval-jobs.cc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/nix-eval-jobs.cc b/src/nix-eval-jobs.cc index 2615f30..59d15dc 100644 --- a/src/nix-eval-jobs.cc +++ b/src/nix-eval-jobs.cc @@ -128,6 +128,40 @@ static Value* releaseExprTopLevelValue(EvalState & state, Bindings & autoArgs) { 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( EvalState & state, Bindings & autoArgs, From dd8a2e89a0e4b0a1638826065a4b78022e5b60e6 Mon Sep 17 00:00:00 2001 From: John Soo Date: Thu, 21 Apr 2022 11:41:31 -0700 Subject: [PATCH 3/3] 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. */