libfetchers: asyncify Input::fetch

Change-Id: I2d032b46eaa7daf20018f4f0cf71439d807eb10a
This commit is contained in:
eldritch horrors
2025-02-01 21:48:48 +00:00
parent 083c6de22c
commit d7e6721c66
7 changed files with 19 additions and 11 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
#include "lix/libexpr/flake/flakeref.hh"
#include "lix/libstore/store-api.hh"
#include "lix/libutil/async.hh"
#include "lix/libutil/url.hh"
#include "lix/libutil/url-parts.hh"
#include "lix/libfetchers/fetchers.hh"
@@ -239,7 +240,7 @@ FlakeRef FlakeRef::fromAttrs(const fetchers::Attrs & attrs)
std::pair<fetchers::Tree, FlakeRef> FlakeRef::fetchTree(ref<Store> store) const
{
auto [tree, lockedInput] = input.fetch(store);
auto [tree, lockedInput] = RUN_ASYNC_IN_NEW_THREAD(input.fetch(store));
return {std::move(tree), FlakeRef(std::move(lockedInput), subdir)};
}
+1 -1
View File
@@ -65,7 +65,7 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value * * a
auto input = fetchers::Input::fromAttrs(std::move(attrs));
// FIXME: use name
auto [tree, input2] = input.fetch(state.ctx.store);
auto [tree, input2] = state.aio.blockOn(input.fetch(state.ctx.store));
auto attrs2 = state.ctx.buildBindings(8);
state.ctx.paths.mkStorePathString(tree.storePath, attrs2.alloc(state.ctx.s.outPath));
+1 -1
View File
@@ -192,7 +192,7 @@ static void fetchTree(
state.ctx.errors.make<EvalError>("in pure evaluation mode, 'fetchTree' requires a locked input").atPos(pos).debugThrow();
}
auto [tree, input2] = input.fetch(state.ctx.store);
auto [tree, input2] = state.aio.blockOn(input.fetch(state.ctx.store));
state.ctx.paths.allowPath(tree.storePath);
+10 -5
View File
@@ -123,8 +123,8 @@ bool Input::contains(const Input & other) const
return false;
}
std::pair<Tree, Input> Input::fetch(ref<Store> store) const
{
kj::Promise<Result<std::pair<Tree, Input>>> Input::fetch(ref<Store> store) const
try {
if (!scheme)
throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs()));
@@ -135,12 +135,15 @@ std::pair<Tree, Input> Input::fetch(ref<Store> store) const
try {
auto storePath = computeStorePath(*store);
RUN_ASYNC_IN_NEW_THREAD(store->ensurePath(storePath));
TRY_AWAIT(store->ensurePath(storePath));
debug("using substituted/cached input '%s' in '%s'",
to_string(), store->printStorePath(storePath));
return {Tree { .actualPath = store->toRealPath(storePath), .storePath = std::move(storePath) }, *this};
co_return {
Tree{.actualPath = store->toRealPath(storePath), .storePath = std::move(storePath)},
*this
};
} catch (Error & e) {
debug("substitution of input '%s' failed: %s", to_string(), e.what());
}
@@ -197,7 +200,9 @@ std::pair<Tree, Input> Input::fetch(ref<Store> store) const
assert(input.hasAllInfo());
return {std::move(tree), input};
co_return {std::move(tree), input};
} catch (...) {
co_return result::current_exception();
}
Input Input::applyOverrides(
+3 -1
View File
@@ -1,6 +1,7 @@
#pragma once
///@file
#include "lix/libutil/result.hh"
#include "lix/libutil/types.hh"
#include "lix/libutil/hash.hh"
#include "lix/libutil/canon-path.hh"
@@ -10,6 +11,7 @@
#include "lix/libutil/ref.hh"
#include "lix/libutil/strings.hh"
#include <kj/async.h>
#include <memory>
namespace nix { class Store; }
@@ -90,7 +92,7 @@ public:
* Fetch the input into the Nix store, returning the location in
* the Nix store and the locked input.
*/
std::pair<Tree, Input> fetch(ref<Store> store) const;
kj::Promise<Result<std::pair<Tree, Input>>> fetch(ref<Store> store) const;
Input applyOverrides(
std::optional<std::string> ref,
+1 -1
View File
@@ -1070,7 +1070,7 @@ struct CmdFlakeArchive : FlakeCommand, MixJSON, MixDryRun
auto storePath =
dryRun
? (*inputNode)->lockedRef.input.computeStorePath(*store)
: (*inputNode)->lockedRef.input.fetch(store).first.storePath;
: aio().blockOn((*inputNode)->lockedRef.input.fetch(store)).first.storePath;
if (json) {
auto& jsonObj3 = jsonObj2[inputName];
jsonObj3["path"] = store->printStorePath(storePath);
+1 -1
View File
@@ -196,7 +196,7 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand
auto ref = parseFlakeRef(url);
auto lockedRef = parseFlakeRef(locked);
registry->remove(ref.input);
auto [tree, resolved] = lockedRef.resolve(store).input.fetch(store);
auto [tree, resolved] = aio().blockOn(lockedRef.resolve(store).input.fetch(store));
fetchers::Attrs extraAttrs;
if (ref.subdir != "") extraAttrs["dir"] = ref.subdir;
registry->add(ref.input, resolved, extraAttrs);