libstore: asyncify Store::read{,Invalid}Derivation

Change-Id: Id1af47e5f35ea81ede9c47dba8f50045a2b9bde2
This commit is contained in:
eldritch horrors
2025-03-05 18:49:45 +01:00
parent f6ce58ac72
commit 19b8502ced
16 changed files with 39 additions and 31 deletions
+1 -1
View File
@@ -297,7 +297,7 @@ connected:
uploadLock.reset();
auto drv = store->readDerivation(*drvPath);
auto drv = aio.blockOn(store->readDerivation(*drvPath));
std::optional<BuildResult> optResult;
+3 -2
View File
@@ -142,8 +142,9 @@ try {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
[&](const BuiltPath::Built & p) -> kj::Promise<Result<void>> {
try {
auto drvHashes =
TRY_AWAIT(staticOutputHashes(store, store.readDerivation(p.drvPath->outPath())));
auto drvHashes = TRY_AWAIT(
staticOutputHashes(store, TRY_AWAIT(store.readDerivation(p.drvPath->outPath())))
);
for (auto& [outputName, outputPath] : p.outputs) {
if (experimentalFeatureSettings.isEnabled(
Xp::CaDerivations)) {
+1 -1
View File
@@ -776,7 +776,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
.outputs = OutputsSpec::All { },
},
}));
auto drv = evaluator.store->readDerivation(drvPath);
auto drv = state.aio.blockOn(evaluator.store->readDerivation(drvPath));
logger->cout("\nThis derivation produced the following outputs:");
for (auto & [outputName, outputPath] :
state.aio.blockOn(evaluator.store->queryDerivationOutputMap(drvPath)))
+1 -1
View File
@@ -921,7 +921,7 @@ std::string EvalState::mkSingleDerivedPathStringRaw(
[&](const SingleDerivedPath::Built & b) {
auto optStaticOutputPath = std::visit(overloaded {
[&](const SingleDerivedPath::Opaque & o) {
auto drv = ctx.store->readDerivation(o.path);
auto drv = aio.blockOn(ctx.store->readDerivation(o.path));
auto i = drv.outputs.find(b.output);
if (i == drv.outputs.end())
throw Error("derivation '%s' does not have output '%s'", b.drvPath->to_string(*ctx.store), b.output);
+3 -2
View File
@@ -190,7 +190,7 @@ static void import(EvalState & state, const PosIdx pos, Value & vPath, Value * v
};
if (auto storePath = isValidDerivationInStore()) {
Derivation drv = state.ctx.store->readDerivation(*storePath);
Derivation drv = state.aio.blockOn(state.ctx.store->readDerivation(*storePath));
auto attrs = state.ctx.buildBindings(3 + drv.outputs.size());
attrs.alloc(state.ctx.s.drvPath).mkString(path2, {
NixStringContextElem::DrvDeep { .drvPath = *storePath },
@@ -982,7 +982,8 @@ drvName, Bindings * attrs, Value & v)
for (auto & j : refs) {
drv.inputSrcs.insert(j);
if (j.isDerivation()) {
drv.inputDrvs.map[j].value = state.ctx.store->readDerivation(j).outputNames();
drv.inputDrvs.map[j].value =
state.aio.blockOn(state.ctx.store->readDerivation(j)).outputNames();
}
}
},
+2 -2
View File
@@ -206,7 +206,7 @@ try {
*/
for (auto * drvStore : { &worker.evalStore, &worker.store }) {
if (drvStore->isValidPath(drvPath)) {
drv = std::make_unique<Derivation>(drvStore->readDerivation(drvPath));
drv = std::make_unique<Derivation>(TRY_AWAIT(drvStore->readDerivation(drvPath)));
break;
}
}
@@ -412,7 +412,7 @@ try {
/* Ensure that pure, non-fixed-output derivations don't
depend on impure derivations. */
if (experimentalFeatureSettings.isEnabled(Xp::ImpureDerivations) && drv->type().isPure() && !drv->type().isFixed()) {
auto inputDrv = worker.evalStore.readDerivation(inputDrvPath);
auto inputDrv = TRY_AWAIT(worker.evalStore.readDerivation(inputDrvPath));
if (!inputDrv.type().isPure())
throw Error("pure derivation '%s' depends on impure derivation '%s'",
worker.store.printStorePath(drvPath),
+1 -1
View File
@@ -378,7 +378,7 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref<Store> store
REMOVE_AFTER_DROPPING_PROTO_MINOR(31);
auto path = store->parseStorePath(readString(from));
logger->startWork();
auto names = store->readDerivation(path).outputNames();
auto names = aio.blockOn(store->readDerivation(path)).outputNames();
logger->stopWork();
to << names;
break;
+1 -1
View File
@@ -794,7 +794,7 @@ try {
}
auto h = TRY_AWAIT(hashDerivationModulo(
store,
store.readInvalidDerivation(drvPath),
TRY_AWAIT(store.readInvalidDerivation(drvPath)),
false));
// Cache it
drvHashes.lock()->insert_or_assign(drvPath, h);
+4 -2
View File
@@ -887,7 +887,7 @@ try {
efficiently query whether a path is an output of some
derivation. */
if (info.path.isDerivation()) {
auto drv = readInvalidDerivation(info.path);
auto drv = TRY_AWAIT(readInvalidDerivation(info.path));
/* Verify that the output paths in the derivation are correct
(i.e., follow the scheme for computing output paths from
@@ -1228,7 +1228,9 @@ try {
for (auto & [_, i] : infos)
if (i.path.isDerivation()) {
// FIXME: inefficient; we already loaded the derivation in addValidPath().
TRY_AWAIT(readInvalidDerivation(i.path).checkInvariants(*this, i.path));
TRY_AWAIT(
TRY_AWAIT(readInvalidDerivation(i.path)).checkInvariants(*this, i.path)
);
}
/* Do a topological sort of the paths. This will throw an
+3 -2
View File
@@ -424,8 +424,9 @@ try {
) -> kj::Promise<Result<void>> {
try {
if (!inputNode.value.empty()) {
auto outputHashes =
TRY_AWAIT(staticOutputHashes(evalStore, evalStore.readDerivation(inputDrv)));
auto outputHashes = TRY_AWAIT(
staticOutputHashes(evalStore, TRY_AWAIT(evalStore.readDerivation(inputDrv)))
);
for (const auto & outputName : inputNode.value) {
auto outputHash = get(outputHashes, outputName);
if (!outputHash)
+1 -1
View File
@@ -757,7 +757,7 @@ try {
OutputPathMap outputs;
auto drvPath = TRY_AWAIT(resolveDerivedPath(*evalStore, *bfd.drvPath));
auto drv = evalStore->readDerivation(drvPath);
auto drv = TRY_AWAIT(evalStore->readDerivation(drvPath));
const auto outputHashes =
TRY_AWAIT(staticOutputHashes(*evalStore, drv)); // FIXME: expensive
auto built = TRY_AWAIT(resolveDerivedPath(*this, bfd, &*evalStore));
+12 -9
View File
@@ -510,7 +510,7 @@ kj::Promise<Result<std::map<std::string, std::optional<StorePath>>>>
Store::queryStaticPartialDerivationOutputMap(const StorePath & path)
try {
std::map<std::string, std::optional<StorePath>> outputs;
auto drv = readInvalidDerivation(path);
auto drv = TRY_AWAIT(readInvalidDerivation(path));
for (auto & [outputName, output] : drv.outputsAndOptPaths(*this)) {
outputs.emplace(outputName, output.second);
}
@@ -529,7 +529,7 @@ try {
if (!experimentalFeatureSettings.isEnabled(Xp::CaDerivations))
co_return outputs;
auto drv = evalStore.readInvalidDerivation(path);
auto drv = TRY_AWAIT(evalStore.readInvalidDerivation(path));
auto drvHashes = TRY_AWAIT(staticOutputHashes(*this, drv));
for (auto & [outputName, hash] : drvHashes) {
auto realisation = TRY_AWAIT(queryRealisation(DrvOutput{hash, outputName}));
@@ -1382,21 +1382,24 @@ std::string showPaths(const PathSet & paths)
kj::Promise<Result<Derivation>> Store::derivationFromPath(const StorePath & drvPath)
try {
TRY_AWAIT(ensurePath(drvPath));
co_return readDerivation(drvPath);
co_return TRY_AWAIT(readDerivation(drvPath));
} catch (...) {
co_return result::current_exception();
}
Derivation readDerivationCommon(Store& store, const StorePath& drvPath, bool requireValidPath)
{
kj::Promise<Result<Derivation>>
readDerivationCommon(Store& store, const StorePath& drvPath, bool requireValidPath)
try {
auto accessor = store.getFSAccessor();
try {
return parseDerivation(store,
co_return parseDerivation(store,
accessor->readFile(store.printStorePath(drvPath), requireValidPath),
Derivation::nameFromPath(drvPath));
} catch (FormatError & e) {
throw Error("error parsing derivation '%s': %s", store.printStorePath(drvPath), e.msg());
}
} catch (...) {
co_return result::current_exception();
}
kj::Promise<Result<std::optional<StorePath>>> Store::getBuildDerivationPath(const StorePath & path)
@@ -1414,7 +1417,7 @@ try {
if (!experimentalFeatureSettings.isEnabled(Xp::CaDerivations) || !isValidPath(path))
co_return path;
auto drv = readDerivation(path);
auto drv = TRY_AWAIT(readDerivation(path));
if (!drv.type().hasKnownOutputPaths()) {
// The build log is actually attached to the corresponding
// resolved derivation, so we need to get it first
@@ -1428,10 +1431,10 @@ try {
co_return result::current_exception();
}
Derivation Store::readDerivation(const StorePath & drvPath)
kj::Promise<Result<Derivation>> Store::readDerivation(const StorePath & drvPath)
{ return readDerivationCommon(*this, drvPath, true); }
Derivation Store::readInvalidDerivation(const StorePath & drvPath)
kj::Promise<Result<Derivation>> Store::readInvalidDerivation(const StorePath & drvPath)
{ return readDerivationCommon(*this, drvPath, false); }
}
+2 -2
View File
@@ -770,12 +770,12 @@ public:
/**
* Read a derivation (which must already be valid).
*/
Derivation readDerivation(const StorePath & drvPath);
kj::Promise<Result<Derivation>> readDerivation(const StorePath & drvPath);
/**
* Read a derivation from a potentially invalid path.
*/
Derivation readInvalidDerivation(const StorePath & drvPath);
kj::Promise<Result<Derivation>> readInvalidDerivation(const StorePath & drvPath);
/**
* @param [out] out Place in here the set of all store paths in the
+1 -1
View File
@@ -56,7 +56,7 @@ struct CmdShowDerivation : InstallablesCommand
if (!drvPath.isDerivation()) continue;
jsonRoot[store->printStorePath(drvPath)] =
store->readDerivation(drvPath).toJSON(*store);
aio().blockOn(store->readDerivation(drvPath)).toJSON(*store);
}
logger->cout(jsonRoot.dump(2));
}
@@ -125,13 +125,13 @@ void rewriteAggregates(std::map<std::string, nlohmann::json> &jobs,
for (const auto &aggregateJob : aggregateJobs) {
auto &job = jobs.find(aggregateJob.name)->second;
auto drvPath = store->parseStorePath(std::string(job["drvPath"]));
auto drv = store->readDerivation(drvPath);
auto drv = aio.blockOn(store->readDerivation(drvPath));
if (aggregateJob.brokenJobs.empty()) {
for (const auto &childJobName : aggregateJob.dependencies) {
auto childDrvPath = store->parseStorePath(
std::string(jobs.find(childJobName)->second["drvPath"]));
auto childDrv = store->readDerivation(childDrvPath);
auto childDrv = aio.blockOn(store->readDerivation(childDrvPath));
job["constituents"].push_back(
store->printStorePath(childDrvPath));
drv.inputDrvs.map[childDrvPath].value = {
+1 -1
View File
@@ -100,7 +100,7 @@ Drv::Drv(std::string &attrPath, nix::EvalState &state, nix::DrvInfo &drvInfo,
drvPath = localStore->printStorePath(drvInfo.requireDrvPath(state));
auto drv = localStore->readDerivation(drvInfo.requireDrvPath(state));
auto drv = state.aio.blockOn(localStore->readDerivation(drvInfo.requireDrvPath(state)));
for (const auto &[inputDrvPath, inputNode] : drv.inputDrvs.map) {
std::set<std::string> inputDrvOutputs;
for (auto &outputName : inputNode.value) {