aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/worker-protocol.cc
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-04 04:59:31 +0100
committereldritch horrors <pennae@lix.systems>2024-03-04 04:59:31 +0100
commit7f590ea7096d1e1bbbe73697358fef962d0fb494 (patch)
tree379ef50da30c3ff0b49df6ac1c28d3cfac7e0f69 /src/libstore/worker-protocol.cc
parent4d9dde15efbc05af471acb3efc5b04c087ceeef0 (diff)
Merge pull request #6223 from obsidiansystems/worker-proto-with-version
Give `nix daemon` and `nix-store --serve` protocols separate serializers with version info (cherry picked from commit 8b68bbb77745fda0d14939b6c23d31cc89da41ce) Change-Id: Ia3d3b9fbaf9f0ae62ab225020b7d14790e793655
Diffstat (limited to 'src/libstore/worker-protocol.cc')
-rw-r--r--src/libstore/worker-protocol.cc124
1 files changed, 101 insertions, 23 deletions
diff --git a/src/libstore/worker-protocol.cc b/src/libstore/worker-protocol.cc
index 415e66f16..ad94c79ee 100644
--- a/src/libstore/worker-protocol.cc
+++ b/src/libstore/worker-protocol.cc
@@ -6,7 +6,7 @@
#include "worker-protocol.hh"
#include "worker-protocol-impl.hh"
#include "archive.hh"
-#include "derivations.hh"
+#include "path-info.hh"
#include <nlohmann/json.hpp>
@@ -51,12 +51,34 @@ void WorkerProto::Serialise<std::optional<TrustedFlag>>::write(const Store & sto
DerivedPath WorkerProto::Serialise<DerivedPath>::read(const Store & store, WorkerProto::ReadConn conn)
{
auto s = readString(conn.from);
- return DerivedPath::parseLegacy(store, s);
+ if (GET_PROTOCOL_MINOR(conn.version) >= 30) {
+ return DerivedPath::parseLegacy(store, s);
+ } else {
+ return parsePathWithOutputs(store, s).toDerivedPath();
+ }
}
void WorkerProto::Serialise<DerivedPath>::write(const Store & store, WorkerProto::WriteConn conn, const DerivedPath & req)
{
- conn.to << req.to_string_legacy(store);
+ if (GET_PROTOCOL_MINOR(conn.version) >= 30) {
+ conn.to << req.to_string_legacy(store);
+ } else {
+ auto sOrDrvPath = StorePathWithOutputs::tryFromDerivedPath(req);
+ std::visit(overloaded {
+ [&](const StorePathWithOutputs & s) {
+ conn.to << s.to_string(store);
+ },
+ [&](const StorePath & drvPath) {
+ throw Error("trying to request '%s', but daemon protocol %d.%d is too old (< 1.29) to request a derivation file",
+ store.printStorePath(drvPath),
+ GET_PROTOCOL_MAJOR(conn.version),
+ GET_PROTOCOL_MINOR(conn.version));
+ },
+ [&](std::monostate) {
+ throw Error("wanted to build a derivation that is itself a build product, but protocols do not support that. Try upgrading the Nix on the other end of this connection");
+ },
+ }, sOrDrvPath);
+ }
}
@@ -81,17 +103,21 @@ BuildResult WorkerProto::Serialise<BuildResult>::read(const Store & store, Worke
{
BuildResult res;
res.status = (BuildResult::Status) readInt(conn.from);
- conn.from
- >> res.errorMsg
- >> res.timesBuilt
- >> res.isNonDeterministic
- >> res.startTime
- >> res.stopTime;
- auto builtOutputs = WorkerProto::Serialise<DrvOutputs>::read(store, conn);
- for (auto && [output, realisation] : builtOutputs)
- res.builtOutputs.insert_or_assign(
- std::move(output.outputName),
- std::move(realisation));
+ conn.from >> res.errorMsg;
+ if (GET_PROTOCOL_MINOR(conn.version) >= 29) {
+ conn.from
+ >> res.timesBuilt
+ >> res.isNonDeterministic
+ >> res.startTime
+ >> res.stopTime;
+ }
+ if (GET_PROTOCOL_MINOR(conn.version) >= 28) {
+ auto builtOutputs = WorkerProto::Serialise<DrvOutputs>::read(store, conn);
+ for (auto && [output, realisation] : builtOutputs)
+ res.builtOutputs.insert_or_assign(
+ std::move(output.outputName),
+ std::move(realisation));
+ }
return res;
}
@@ -99,16 +125,68 @@ void WorkerProto::Serialise<BuildResult>::write(const Store & store, WorkerProto
{
conn.to
<< res.status
- << res.errorMsg
- << res.timesBuilt
- << res.isNonDeterministic
- << res.startTime
- << res.stopTime;
- DrvOutputs builtOutputs;
- for (auto & [output, realisation] : res.builtOutputs)
- builtOutputs.insert_or_assign(realisation.id, realisation);
- WorkerProto::write(store, conn, builtOutputs);
+ << res.errorMsg;
+ if (GET_PROTOCOL_MINOR(conn.version) >= 29) {
+ conn.to
+ << res.timesBuilt
+ << res.isNonDeterministic
+ << res.startTime
+ << res.stopTime;
+ }
+ if (GET_PROTOCOL_MINOR(conn.version) >= 28) {
+ DrvOutputs builtOutputs;
+ for (auto & [output, realisation] : res.builtOutputs)
+ builtOutputs.insert_or_assign(realisation.id, realisation);
+ WorkerProto::write(store, conn, builtOutputs);
+ }
}
+ValidPathInfo WorkerProto::Serialise<ValidPathInfo>::read(const Store & store, ReadConn conn)
+{
+ auto path = WorkerProto::Serialise<StorePath>::read(store, conn);
+ return ValidPathInfo {
+ std::move(path),
+ WorkerProto::Serialise<UnkeyedValidPathInfo>::read(store, conn),
+ };
+}
+
+void WorkerProto::Serialise<ValidPathInfo>::write(const Store & store, WriteConn conn, const ValidPathInfo & pathInfo)
+{
+ WorkerProto::write(store, conn, pathInfo.path);
+ WorkerProto::write(store, conn, static_cast<const UnkeyedValidPathInfo &>(pathInfo));
+}
+
+
+UnkeyedValidPathInfo WorkerProto::Serialise<UnkeyedValidPathInfo>::read(const Store & store, ReadConn conn)
+{
+ auto deriver = readString(conn.from);
+ auto narHash = Hash::parseAny(readString(conn.from), htSHA256);
+ UnkeyedValidPathInfo info(narHash);
+ if (deriver != "") info.deriver = store.parseStorePath(deriver);
+ info.references = WorkerProto::Serialise<StorePathSet>::read(store, conn);
+ conn.from >> info.registrationTime >> info.narSize;
+ if (GET_PROTOCOL_MINOR(conn.version) >= 16) {
+ conn.from >> info.ultimate;
+ info.sigs = readStrings<StringSet>(conn.from);
+ info.ca = ContentAddress::parseOpt(readString(conn.from));
+ }
+ return info;
+}
+
+void WorkerProto::Serialise<UnkeyedValidPathInfo>::write(const Store & store, WriteConn conn, const UnkeyedValidPathInfo & pathInfo)
+{
+ conn.to
+ << (pathInfo.deriver ? store.printStorePath(*pathInfo.deriver) : "")
+ << pathInfo.narHash.to_string(Base16, false);
+ WorkerProto::write(store, conn, pathInfo.references);
+ conn.to << pathInfo.registrationTime << pathInfo.narSize;
+ if (GET_PROTOCOL_MINOR(conn.version) >= 16) {
+ conn.to
+ << pathInfo.ultimate
+ << pathInfo.sigs
+ << renderContentAddress(pathInfo.ca);
+ }
+}
+
}