1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 03:56:01 +01:00

Split out UnkeyedRealisation from Realisation

Realisations are conceptually key-value pairs, mapping `DrvOutputs` (the
key) to information about that derivation output.

This separate the value type, which will be useful in maps, etc., where
we don't want to denormalize by including the key twice.

This matches similar changes for existing types:

| keyed              | unkeyed                |
|--------------------|------------------------|
| `ValidPathInfo`    | `UnkeyedValidPathInfo` |
| `KeyedBuildResult` | `BuildResult`          |
| `Realisation`      | `UnkeyedRealisation`   |
This commit is contained in:
John Ericson 2025-09-24 00:06:47 -04:00
parent 28adcfda32
commit e06968ec25
28 changed files with 363 additions and 251 deletions

View file

@ -502,10 +502,15 @@ StorePath BinaryCacheStore::addToStore(
->path;
}
void BinaryCacheStore::queryRealisationUncached(
const DrvOutput & id, Callback<std::shared_ptr<const Realisation>> callback) noexcept
std::string BinaryCacheStore::makeRealisationPath(const DrvOutput & id)
{
auto outputInfoFilePath = realisationsPrefix + "/" + id.to_string() + ".doi";
return realisationsPrefix + "/" + id.to_string() + ".doi";
}
void BinaryCacheStore::queryRealisationUncached(
const DrvOutput & id, Callback<std::shared_ptr<const UnkeyedRealisation>> callback) noexcept
{
auto outputInfoFilePath = makeRealisationPath(id);
auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
@ -515,11 +520,12 @@ void BinaryCacheStore::queryRealisationUncached(
if (!data)
return (*callbackPtr)({});
std::shared_ptr<const Realisation> realisation;
std::shared_ptr<const UnkeyedRealisation> realisation;
try {
realisation = std::make_shared<const Realisation>(nlohmann::json::parse(*data));
realisation = std::make_shared<const UnkeyedRealisation>(nlohmann::json::parse(*data));
} catch (Error & e) {
e.addTrace({}, "while parsing file '%s' as a realisation", outputInfoFilePath);
e.addTrace(
{}, "while parsing file '%s' as a realisation for key '%s'", outputInfoFilePath, id.to_string());
throw;
}
return (*callbackPtr)(std::move(realisation));
@ -535,8 +541,7 @@ void BinaryCacheStore::registerDrvOutput(const Realisation & info)
{
if (diskCache)
diskCache->upsertRealisation(config.getReference().render(/*FIXME withParams=*/false), info);
auto filePath = realisationsPrefix + "/" + info.id.to_string() + ".doi";
upsertFile(filePath, static_cast<nlohmann::json>(info).dump(), "application/json");
upsertFile(makeRealisationPath(info.id), static_cast<nlohmann::json>(info).dump(), "application/json");
}
ref<RemoteFSAccessor> BinaryCacheStore::getRemoteFSAccessor(bool requireValidPath)