libstore: asyncify writeDerivation

Change-Id: Ia4e25dbc84e522b27c5257564febbd1ccf4df8a3
This commit is contained in:
eldritch horrors
2025-02-10 12:54:19 +00:00
parent e19a1a25e8
commit f18c39f46d
8 changed files with 15 additions and 11 deletions
+1 -1
View File
@@ -1109,7 +1109,7 @@ drvName, Bindings * attrs, Value & v)
}
/* Write the resulting term into the Nix store directory. */
auto drvPath = writeDerivation(*state.ctx.store, drv, state.ctx.repair);
auto drvPath = state.aio.blockOn(writeDerivation(*state.ctx.store, drv, state.ctx.repair));
auto drvPathS = state.ctx.store->printStorePath(drvPath);
printMsg(lvlChatty, "instantiated '%1%' -> '%2%'", drvName, drvPathS);
+1 -1
View File
@@ -604,7 +604,7 @@ try {
assert(attempt);
Derivation drvResolved { std::move(*attempt) };
auto pathResolved = writeDerivation(worker.store, drvResolved);
auto pathResolved = TRY_AWAIT(writeDerivation(worker.store, drvResolved));
auto msg = fmt("resolved derivation: '%s' -> '%s'",
worker.store.printStorePath(drvPath),
+1 -1
View File
@@ -645,7 +645,7 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref<Store> store
Derivation drv2;
static_cast<BasicDerivation &>(drv2) = drv;
drvPath = writeDerivation(*store, Derivation { drv2 });
drvPath = aio.blockOn(writeDerivation(*store, Derivation { drv2 }));
}
auto res = aio.blockOn(store->buildDerivation(drvPath, drv, buildMode));
+5 -3
View File
@@ -134,9 +134,9 @@ bool BasicDerivation::isBuiltin() const
}
StorePath writeDerivation(Store & store,
kj::Promise<Result<StorePath>> writeDerivation(Store & store,
const Derivation & drv, RepairFlag repair, bool readOnly)
{
try {
auto references = drv.inputSrcs;
for (auto & i : drv.inputDrvs.map)
references.insert(i.first);
@@ -145,9 +145,11 @@ StorePath writeDerivation(Store & store,
held during a garbage collection). */
auto suffix = std::string(drv.name) + drvExtension;
auto contents = drv.unparse(store, false);
return readOnly || settings.readOnlyMode
co_return readOnly || settings.readOnlyMode
? store.computeStorePathForText(suffix, contents, references)
: store.addTextToStore(suffix, contents, references, repair);
} catch (...) {
co_return result::current_exception();
}
+3 -1
View File
@@ -2,6 +2,7 @@
///@file
#include "lix/libstore/path.hh"
#include "lix/libutil/result.hh"
#include "lix/libutil/types.hh"
#include "lix/libutil/hash.hh"
#include "lix/libstore/content-address.hh"
@@ -11,6 +12,7 @@
#include "lix/libutil/comparator.hh"
#include "lix/libutil/variant-wrapper.hh"
#include <kj/async.h>
#include <map>
#include <variant>
@@ -382,7 +384,7 @@ class Store;
/**
* Write a derivation to the Nix store, and return its path.
*/
StorePath writeDerivation(Store & store,
kj::Promise<Result<StorePath>> writeDerivation(Store & store,
const Derivation & drv,
RepairFlag repair = NoRepair,
bool readOnly = false);
+1 -1
View File
@@ -1433,7 +1433,7 @@ try {
// resolved derivation, so we need to get it first
auto resolvedDrv = drv.tryResolve(*this);
if (resolvedDrv)
co_return writeDerivation(*this, *resolvedDrv, NoRepair, true);
co_return TRY_AWAIT(writeDerivation(*this, *resolvedDrv, NoRepair, true));
}
co_return path;
+2 -2
View File
@@ -32,11 +32,11 @@ struct CmdAddDerivation : MixDryRun, StoreCommand
auto drv = Derivation::fromJSON(*store, json);
auto drvPath = writeDerivation(*store, drv, NoRepair, /* read only */ dryRun);
auto drvPath = aio().blockOn(writeDerivation(*store, drv, NoRepair, /* read only */ dryRun));
drv.checkInvariants(*store, drvPath);
writeDerivation(*store, drv, NoRepair, dryRun);
aio().blockOn(writeDerivation(*store, drv, NoRepair, dryRun));
logger->cout("%s", store->printStorePath(drvPath));
}
+1 -1
View File
@@ -256,7 +256,7 @@ try {
}
}
auto shellDrvPath = writeDerivation(*evalStore, drv);
auto shellDrvPath = TRY_AWAIT(writeDerivation(*evalStore, drv));
/* Build the derivation. */
TRY_AWAIT(store->buildPaths(