From ab07651f7409782187806cddb9e79830d19f5971 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Fri, 14 Jul 2023 12:34:20 +0800 Subject: [PATCH] Small refactor to avoid optional values --- src/nix-eval-jobs.cc | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/nix-eval-jobs.cc b/src/nix-eval-jobs.cc index 2fce82c..72f784d 100644 --- a/src/nix-eval-jobs.cc +++ b/src/nix-eval-jobs.cc @@ -154,12 +154,6 @@ static Value *releaseExprTopLevelValue(EvalState &state, Bindings &autoArgs) { return vRoot; } -Value *topLevelValue(EvalState &state, Bindings &autoArgs, - std::optional flake) { - return flake.has_value() ? flake.value().toValue(state).first - : releaseExprTopLevelValue(state, autoArgs); -} - bool queryIsCached(Store &store, std::map &outputs) { uint64_t downloadSize, narSize; StorePathSet willBuild, willSubstitute, unknown; @@ -264,22 +258,25 @@ std::string attrPathJoin(json input) { static void worker(ref state, Bindings &autoArgs, AutoCloseFD &to, AutoCloseFD &from) { - std::optional flake; - if (myArgs.flake) { - auto [flakeRef, fragment, outputSpec] = - parseFlakeRefWithFragmentAndExtendedOutputsSpec(myArgs.releaseExpr, - absPath(".")); + nix::Value *vRoot = [&]() { + if (myArgs.flake) { + auto [flakeRef, fragment, outputSpec] = + parseFlakeRefWithFragmentAndExtendedOutputsSpec(myArgs.releaseExpr, + absPath(".")); + InstallableFlake flake { + {}, state, std::move(flakeRef), fragment, + outputSpec, {}, {}, + flake::LockFlags{ + .updateLockFile = false, + .useRegistries = false, + .allowUnlocked = false, + }}; - flake.emplace(InstallableFlake({}, state, std::move(flakeRef), fragment, - outputSpec, {}, {}, - flake::LockFlags{ - .updateLockFile = false, - .useRegistries = false, - .allowUnlocked = false, - })); - }; - - auto vRoot = topLevelValue(*state, autoArgs, flake); + return flake.toValue(*state).first; + } else { + return releaseExprTopLevelValue(*state, autoArgs); + } + }(); while (true) { /* Wait for the collector to send us a job name. */