diff --git a/lix/legacy/nix-build.cc b/lix/legacy/nix-build.cc index 1d0dd3d60..152a0b6d4 100644 --- a/lix/legacy/nix-build.cc +++ b/lix/legacy/nix-build.cc @@ -410,7 +410,7 @@ static void main_nix_build(AsyncIoRoot & aio, std::string programName, Strings a } if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations)) { - auto resolvedDrv = drv.tryResolve(*store); + auto resolvedDrv = aio.blockOn(drv.tryResolve(*store)); assert(resolvedDrv && "Successfully resolved the derivation"); drv = *resolvedDrv; } diff --git a/lix/libstore/build/derivation-goal.cc b/lix/libstore/build/derivation-goal.cc index 5a442aed3..85d0786d6 100644 --- a/lix/libstore/build/derivation-goal.cc +++ b/lix/libstore/build/derivation-goal.cc @@ -588,14 +588,14 @@ try { /* We are be able to resolve this derivation based on the now-known results of dependencies. If so, we become a stub goal aliasing that resolved derivation goal. */ - std::optional attempt = fullDrv.tryResolve(worker.store, inputDrvOutputs); + std::optional attempt = TRY_AWAIT(fullDrv.tryResolve(worker.store, inputDrvOutputs)); if (!attempt) { /* TODO (impure derivations-induced tech debt) (see below): The above attempt should have found it, but because we manage inputDrvOutputs statefully, sometimes it gets out of sync with the real source of truth (store). So we query the store directly if there's a problem. */ - attempt = fullDrv.tryResolve(worker.store, &worker.evalStore); + attempt = TRY_AWAIT(fullDrv.tryResolve(worker.store, &worker.evalStore)); } assert(attempt); Derivation drvResolved { std::move(*attempt) }; diff --git a/lix/libstore/derivations.cc b/lix/libstore/derivations.cc index 2460d0f06..281e830c7 100644 --- a/lix/libstore/derivations.cc +++ b/lix/libstore/derivations.cc @@ -1054,8 +1054,9 @@ static void rewriteDerivation(Store & store, BasicDerivation & drv, const String } -std::optional Derivation::tryResolve(Store & store, Store * evalStore) const -{ +kj::Promise>> +Derivation::tryResolve(Store & store, Store * evalStore) const +try { std::map, StorePath> inputDrvOutputs; std::function::ChildNode &)> accum; @@ -1072,7 +1073,9 @@ std::optional Derivation::tryResolve(Store & store, Store * eva for (auto & [inputDrv, node] : inputDrvs.map) accum(inputDrv, node); - return tryResolve(store, inputDrvOutputs); + co_return TRY_AWAIT(tryResolve(store, inputDrvOutputs)); +} catch (...) { + co_return result::current_exception(); } static bool tryResolveInput( @@ -1122,10 +1125,10 @@ static bool tryResolveInput( return true; } -std::optional Derivation::tryResolve( +kj::Promise>> Derivation::tryResolve( Store & store, const std::map, StorePath> & inputDrvOutputs) const -{ +try { BasicDerivation resolved { *this }; // Input paths that we'll want to rewrite in the derivation @@ -1134,11 +1137,13 @@ std::optional Derivation::tryResolve( for (auto & [inputDrv, inputNode] : inputDrvs.map) if (!tryResolveInput(store, resolved.inputSrcs, inputRewrites, nullptr, inputDrv, inputNode, inputDrvOutputs)) - return std::nullopt; + co_return std::nullopt; rewriteDerivation(store, resolved, inputRewrites); - return resolved; + co_return resolved; +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/derivations.hh b/lix/libstore/derivations.hh index 73db36676..1e4723d05 100644 --- a/lix/libstore/derivations.hh +++ b/lix/libstore/derivations.hh @@ -342,14 +342,15 @@ struct Derivation : BasicDerivation * 2. Input placeholders are replaced with realized input store * paths. */ - std::optional tryResolve(Store & store, Store * evalStore = nullptr) const; + kj::Promise>> + tryResolve(Store & store, Store * evalStore = nullptr) const; /** * Like the above, but instead of querying the Nix database for * realisations, uses a given mapping from input derivation paths + * output names to actual output store paths. */ - std::optional tryResolve( + kj::Promise>> tryResolve( Store & store, const std::map, StorePath> & inputDrvOutputs) const; diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index 06d165636..60e927ee6 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -1431,7 +1431,7 @@ try { if (!drv.type().hasKnownOutputPaths()) { // The build log is actually attached to the corresponding // resolved derivation, so we need to get it first - auto resolvedDrv = drv.tryResolve(*this); + auto resolvedDrv = TRY_AWAIT(drv.tryResolve(*this)); if (resolvedDrv) co_return TRY_AWAIT(writeDerivation(*this, *resolvedDrv, NoRepair, true)); }