diff --git a/lix/libcmd/installable-attr-path.cc b/lix/libcmd/installable-attr-path.cc index 9a0646f04..6a105bf59 100644 --- a/lix/libcmd/installable-attr-path.cc +++ b/lix/libcmd/installable-attr-path.cc @@ -24,16 +24,16 @@ InstallableAttrPath::InstallableAttrPath( , extendedOutputsSpec(std::move(extendedOutputsSpec)) { } -std::pair InstallableAttrPath::toValue(EvalState & state) +std::pair InstallableAttrPath::toValue() { - auto [vRes, pos] = findAlongAttrPath(state, attrPath, *cmd.getAutoArgs(state), **v); - state.forceValue(*vRes, pos); + auto [vRes, pos] = findAlongAttrPath(*state, attrPath, *cmd.getAutoArgs(*state), **v); + state->forceValue(*vRes, pos); return {vRes, pos}; } DerivedPathsWithInfo InstallableAttrPath::toDerivedPaths() { - auto [v, pos] = toValue(*state); + auto [v, pos] = toValue(); if (std::optional derivedPathWithInfo = trySinglePathToDerivedPaths( *v, diff --git a/lix/libcmd/installable-attr-path.hh b/lix/libcmd/installable-attr-path.hh index e71bb649c..7af397b2c 100644 --- a/lix/libcmd/installable-attr-path.hh +++ b/lix/libcmd/installable-attr-path.hh @@ -27,7 +27,7 @@ class InstallableAttrPath : public InstallableValue std::string what() const override { return attrPath; }; - std::pair toValue(EvalState & state) override; + std::pair toValue() override; DerivedPathsWithInfo toDerivedPaths() override; diff --git a/lix/libcmd/installable-flake.cc b/lix/libcmd/installable-flake.cc index 91b019b09..dacf7229a 100644 --- a/lix/libcmd/installable-flake.cc +++ b/lix/libcmd/installable-flake.cc @@ -41,16 +41,16 @@ std::vector InstallableFlake::getActualAttrPaths() return res; } -Value * InstallableFlake::getFlakeOutputs(EvalState & state, const flake::LockedFlake & lockedFlake) +Value * InstallableFlake::getFlakeOutputs(const flake::LockedFlake & lockedFlake) { - auto vFlake = state.mem.allocValue(); + auto vFlake = state->mem.allocValue(); - callFlake(state, lockedFlake, *vFlake); + callFlake(*state, lockedFlake, *vFlake); - auto aOutputs = vFlake->attrs->get(state.symbols.create("outputs")); + auto aOutputs = vFlake->attrs->get(state->symbols.create("outputs")); assert(aOutputs); - state.forceValue(*aOutputs->value, aOutputs->value->determinePos(noPos)); + state->forceValue(*aOutputs->value, aOutputs->value->determinePos(noPos)); return aOutputs->value; } @@ -89,7 +89,7 @@ DerivedPathsWithInfo InstallableFlake::toDerivedPaths() { Activity act(*logger, lvlTalkative, actUnknown, fmt("evaluating derivation '%s'", what())); - auto attr = getCursor(*state); + auto attr = getCursor(); auto attrPath = attr->getAttrPathStr(); @@ -164,15 +164,15 @@ DerivedPathsWithInfo InstallableFlake::toDerivedPaths() }}; } -std::pair InstallableFlake::toValue(EvalState & state) +std::pair InstallableFlake::toValue() { - return {&getCursor(state)->forceValue(), noPos}; + return {&getCursor()->forceValue(), noPos}; } std::vector> -InstallableFlake::getCursors(EvalState & state) +InstallableFlake::getCursors() { - auto evalCache = openEvalCache(state, getLockedFlake()); + auto evalCache = openEvalCache(*state, getLockedFlake()); auto root = evalCache->getRoot(); @@ -184,7 +184,7 @@ InstallableFlake::getCursors(EvalState & state) for (auto & attrPath : attrPaths) { debug("trying flake output attribute '%s'", attrPath); - auto attr = root->findAlongAttrPath(parseAttrPath(state, attrPath)); + auto attr = root->findAlongAttrPath(parseAttrPath(*state, attrPath)); if (attr) { res.push_back(ref(*attr)); } else { diff --git a/lix/libcmd/installable-flake.hh b/lix/libcmd/installable-flake.hh index 89ed9a91c..ecb78f0e3 100644 --- a/lix/libcmd/installable-flake.hh +++ b/lix/libcmd/installable-flake.hh @@ -52,18 +52,17 @@ struct InstallableFlake : InstallableValue std::vector getActualAttrPaths(); - Value * getFlakeOutputs(EvalState & state, const flake::LockedFlake & lockedFlake); + Value * getFlakeOutputs(const flake::LockedFlake & lockedFlake); DerivedPathsWithInfo toDerivedPaths() override; - std::pair toValue(EvalState & state) override; + std::pair toValue() override; /** * Get a cursor to every attrpath in getActualAttrPaths() that * exists. However if none exists, throw an exception. */ - std::vector> - getCursors(EvalState & state) override; + std::vector> getCursors() override; std::shared_ptr getLockedFlake() const; diff --git a/lix/libcmd/installable-value.cc b/lix/libcmd/installable-value.cc index 6191ad63e..096784a8c 100644 --- a/lix/libcmd/installable-value.cc +++ b/lix/libcmd/installable-value.cc @@ -5,20 +5,20 @@ namespace nix { std::vector> -InstallableValue::getCursors(EvalState & state) +InstallableValue::getCursors() { auto evalCache = - std::make_shared(std::nullopt, state, - [&]() { return toValue(state).first; }); + std::make_shared(std::nullopt, *state, + [&]() { return toValue().first; }); return {evalCache->getRoot()}; } ref -InstallableValue::getCursor(EvalState & state) +InstallableValue::getCursor() { /* Although getCursors should return at least one element, in case it doesn't, bound check to avoid an undefined behavior for vector[0] */ - return getCursors(state).at(0); + return getCursors().at(0); } static UsageError nonValueInstallable(Installable & installable) diff --git a/lix/libcmd/installable-value.hh b/lix/libcmd/installable-value.hh index 2ba6d6380..2e5b1311b 100644 --- a/lix/libcmd/installable-value.hh +++ b/lix/libcmd/installable-value.hh @@ -77,24 +77,22 @@ struct InstallableValue : Installable virtual ~InstallableValue() { } - virtual std::pair toValue(EvalState & state) = 0; + virtual std::pair toValue() = 0; /** * Get a cursor to each value this Installable could refer to. * However if none exists, throw exception instead of returning * empty vector. */ - virtual std::vector> - getCursors(EvalState & state); + virtual std::vector> getCursors(); /** * Get the first and most preferred cursor this Installable could * refer to, or throw an exception if none exists. */ - virtual ref - getCursor(EvalState & state); + virtual ref getCursor(); - UnresolvedApp toApp(EvalState & state); + UnresolvedApp toApp(); static InstallableValue & require(Installable & installable); static ref require(ref installable); diff --git a/lix/nix/app.cc b/lix/nix/app.cc index 03a94d2d4..32de7050d 100644 --- a/lix/nix/app.cc +++ b/lix/nix/app.cc @@ -51,15 +51,15 @@ std::string resolveString( return rewriteStrings(toResolve, rewrites); } -UnresolvedApp InstallableValue::toApp(EvalState & state) +UnresolvedApp InstallableValue::toApp() { - auto cursor = getCursor(state); + auto cursor = getCursor(); auto attrPath = cursor->getAttrPath(); auto type = cursor->getAttr("type")->getString(); std::string expected = !attrPath.empty() && - (state.symbols[attrPath[0]] == "apps" || state.symbols[attrPath[0]] == "defaultApp") + (state->symbols[attrPath[0]] == "apps" || state->symbols[attrPath[0]] == "defaultApp") ? "app" : "derivation"; if (type != expected) throw Error("attribute '%s' should have type '%s'", cursor->getAttrPathStr(), expected); @@ -99,11 +99,11 @@ UnresolvedApp InstallableValue::toApp(EvalState & state) else if (type == "derivation") { auto drvPath = cursor->forceDerivation(); - auto outPath = cursor->getAttr(state.s.outPath)->getString(); - auto outputName = cursor->getAttr(state.s.outputName)->getString(); - auto name = cursor->getAttr(state.s.name)->getString(); + auto outPath = cursor->getAttr(state->s.outPath)->getString(); + auto outputName = cursor->getAttr(state->s.outputName)->getString(); + auto name = cursor->getAttr(state->s.name)->getString(); auto aPname = cursor->maybeGetAttr("pname"); - auto aMeta = cursor->maybeGetAttr(state.s.meta); + auto aMeta = cursor->maybeGetAttr(state->s.meta); auto aMainProgram = aMeta ? aMeta->maybeGetAttr("mainProgram") : nullptr; auto mainProgram = aMainProgram diff --git a/lix/nix/bundle.cc b/lix/nix/bundle.cc index 2c012e3a8..cd1e3cbd2 100644 --- a/lix/nix/bundle.cc +++ b/lix/nix/bundle.cc @@ -77,7 +77,7 @@ struct CmdBundle : InstallableCommand auto const installableValue = InstallableValue::require(installable); - auto val = installableValue->toValue(*evalState).first; + auto val = installableValue->toValue().first; auto [bundlerFlakeRef, bundlerName, extendedOutputsSpec] = parseFlakeRefWithFragmentAndExtendedOutputsSpec(bundler, absPath(".")); const flake::LockFlags lockFlags{ .writeLockFile = false }; @@ -91,7 +91,7 @@ struct CmdBundle : InstallableCommand }; auto vRes = evalState->mem.allocValue(); - evalState->callFunction(*bundler.toValue(*evalState).first, *val, *vRes, noPos); + evalState->callFunction(*bundler.toValue().first, *val, *vRes, noPos); if (!evalState->isDerivation(*vRes)) throw Error("the bundler '%s' does not produce a derivation", bundler.what()); diff --git a/lix/nix/edit.cc b/lix/nix/edit.cc index dc7d06ac5..db97b5c18 100644 --- a/lix/nix/edit.cc +++ b/lix/nix/edit.cc @@ -32,7 +32,7 @@ struct CmdEdit : InstallableCommand auto const installableValue = InstallableValue::require(installable); const auto [file, line] = [&] { - auto [v, pos] = installableValue->toValue(*state); + auto [v, pos] = installableValue->toValue(); try { return findPackageFilename(*state, *v, installable->what()); diff --git a/lix/nix/eval.cc b/lix/nix/eval.cc index bbd866ddb..906e3e57f 100644 --- a/lix/nix/eval.cc +++ b/lix/nix/eval.cc @@ -63,7 +63,7 @@ struct CmdEval : MixJSON, InstallableCommand, MixReadOnlyOption auto state = getEvalState(); - auto [v, pos] = installableValue->toValue(*state); + auto [v, pos] = installableValue->toValue(); NixStringContext context; if (apply) { diff --git a/lix/nix/flake.cc b/lix/nix/flake.cc index 1f581af41..18383247f 100644 --- a/lix/nix/flake.cc +++ b/lix/nix/flake.cc @@ -862,7 +862,7 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand defaultTemplateAttrPathsPrefixes, lockFlags); - auto cursor = installable.getCursor(*evalState); + auto cursor = installable.getCursor(); auto templateDirAttr = cursor->getAttr("path"); auto templateDir = templateDirAttr->getString(); diff --git a/lix/nix/fmt.cc b/lix/nix/fmt.cc index a34f27adc..40d70cf9c 100644 --- a/lix/nix/fmt.cc +++ b/lix/nix/fmt.cc @@ -34,7 +34,7 @@ struct CmdFmt : SourceExprCommand { auto installable_ = parseInstallable(store, "."); auto & installable = InstallableValue::require(*installable_); - auto app = installable.toApp(*evalState).resolve(evalStore, store); + auto app = installable.toApp().resolve(evalStore, store); Strings programArgs{app.program}; diff --git a/lix/nix/repl.cc b/lix/nix/repl.cc index 01458b883..a0943defc 100644 --- a/lix/nix/repl.cc +++ b/lix/nix/repl.cc @@ -71,7 +71,7 @@ struct CmdRepl : RawInstallablesCommand auto & installable = InstallableValue::require(*installable_); auto what = installable.what(); if (file){ - auto [val, pos] = installable.toValue(*state); + auto [val, pos] = installable.toValue(); auto what = installable.what(); state->forceValue(*val, pos); auto autoArgs = getAutoArgs(*state); @@ -80,7 +80,7 @@ struct CmdRepl : RawInstallablesCommand state->forceValue(*valPost, pos); values.push_back( {valPost, what }); } else { - auto [val, pos] = installable.toValue(*state); + auto [val, pos] = installable.toValue(); values.push_back( {val, what} ); } } diff --git a/lix/nix/run.cc b/lix/nix/run.cc index a490dc7f7..31019159c 100644 --- a/lix/nix/run.cc +++ b/lix/nix/run.cc @@ -205,7 +205,7 @@ struct CmdRun : InstallableCommand auto installableValue = InstallableValue::require(installable); lockFlags.applyNixConfig = true; - auto app = installableValue->toApp(*state).resolve(getEvalStore(), store); + auto app = installableValue->toApp().resolve(getEvalStore(), store); Strings allArgs{app.program}; for (auto & i : args) allArgs.push_back(i); diff --git a/lix/nix/search.cc b/lix/nix/search.cc index 12ef32695..a6bafa383 100644 --- a/lix/nix/search.cc +++ b/lix/nix/search.cc @@ -194,7 +194,7 @@ struct CmdSearch : InstallableCommand, MixJSON } }; - for (auto & cursor : installableValue->getCursors(*state)) + for (auto & cursor : installableValue->getCursors()) visit(*cursor, cursor->getAttrPath(), true); if (json)