1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-14 13:01:05 +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`   |

Co-authored-by: Sergei Zimmerman <sergei@zimmerman.foo>
This commit is contained in:
John Ericson 2025-09-24 00:06:47 -04:00
parent a543519ca9
commit 6995d325ef
28 changed files with 363 additions and 251 deletions

View file

@ -501,7 +501,7 @@ void RemoteStore::registerDrvOutput(const Realisation & info)
}
void RemoteStore::queryRealisationUncached(
const DrvOutput & id, Callback<std::shared_ptr<const Realisation>> callback) noexcept
const DrvOutput & id, Callback<std::shared_ptr<const UnkeyedRealisation>> callback) noexcept
{
try {
auto conn(getConnection());
@ -515,21 +515,21 @@ void RemoteStore::queryRealisationUncached(
conn->to << id.to_string();
conn.processStderr();
auto real = [&]() -> std::shared_ptr<const Realisation> {
auto real = [&]() -> std::shared_ptr<const UnkeyedRealisation> {
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 31) {
auto outPaths = WorkerProto::Serialise<std::set<StorePath>>::read(*this, *conn);
if (outPaths.empty())
return nullptr;
return std::make_shared<const Realisation>(Realisation{.id = id, .outPath = *outPaths.begin()});
return std::make_shared<const UnkeyedRealisation>(UnkeyedRealisation{.outPath = *outPaths.begin()});
} else {
auto realisations = WorkerProto::Serialise<std::set<Realisation>>::read(*this, *conn);
if (realisations.empty())
return nullptr;
return std::make_shared<const Realisation>(*realisations.begin());
return std::make_shared<const UnkeyedRealisation>(*realisations.begin());
}
}();
callback(std::shared_ptr<const Realisation>(real));
callback(std::shared_ptr<const UnkeyedRealisation>(real));
} catch (...) {
return callback.rethrow();
}
@ -626,13 +626,15 @@ std::vector<KeyedBuildResult> RemoteStore::buildPathsWithResults(
auto realisation = queryRealisation(outputId);
if (!realisation)
throw MissingRealisation(outputId);
success.builtOutputs.emplace(output, *realisation);
success.builtOutputs.emplace(output, Realisation{*realisation, outputId});
} else {
success.builtOutputs.emplace(
output,
Realisation{
.id = outputId,
.outPath = outputPath,
UnkeyedRealisation{
.outPath = outputPath,
},
outputId,
});
}
}