Skip to content

Commit a841686

Browse files
committed
Always send the realisations as JSON
Align all the worker protocol with `buildDerivation` which inlines the realisations as one opaque json blob. That way we don’t have to bother changing the remote store protocol when the definition of `Realisation` changes, as long as we keep the json backwards-compatible
1 parent 7234cf3 commit a841686

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

src/libstore/daemon.cc

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -885,10 +885,15 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
885885

886886
case wopRegisterDrvOutput: {
887887
logger->startWork();
888-
auto outputId = DrvOutput::parse(readString(from));
889-
auto outputPath = StorePath(readString(from));
890-
store->registerDrvOutput(Realisation{
891-
.id = outputId, .outPath = outputPath});
888+
if (GET_PROTOCOL_MINOR(clientVersion) < 31) {
889+
auto outputId = DrvOutput::parse(readString(from));
890+
auto outputPath = StorePath(readString(from));
891+
store->registerDrvOutput(Realisation{
892+
.id = outputId, .outPath = outputPath});
893+
} else {
894+
auto realisation = worker_proto::read(*store, from, Phantom<Realisation>());
895+
store->registerDrvOutput(realisation);
896+
}
892897
logger->stopWork();
893898
break;
894899
}
@@ -898,9 +903,15 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
898903
auto outputId = DrvOutput::parse(readString(from));
899904
auto info = store->queryRealisation(outputId);
900905
logger->stopWork();
901-
std::set<StorePath> outPaths;
902-
if (info) outPaths.insert(info->outPath);
903-
worker_proto::write(*store, to, outPaths);
906+
if (GET_PROTOCOL_MINOR(clientVersion) < 31) {
907+
std::set<StorePath> outPaths;
908+
if (info) outPaths.insert(info->outPath);
909+
worker_proto::write(*store, to, outPaths);
910+
} else {
911+
std::set<Realisation> realisations;
912+
if (info) realisations.insert(*info);
913+
worker_proto::write(*store, to, realisations);
914+
}
904915
break;
905916
}
906917

src/libstore/remote-store.cc

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,12 @@ void RemoteStore::registerDrvOutput(const Realisation & info)
653653
{
654654
auto conn(getConnection());
655655
conn->to << wopRegisterDrvOutput;
656-
conn->to << info.id.to_string();
657-
conn->to << std::string(info.outPath.to_string());
656+
if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 31) {
657+
conn->to << info.id.to_string();
658+
conn->to << std::string(info.outPath.to_string());
659+
} else {
660+
worker_proto::write(*this, conn->to, info);
661+
}
658662
conn.processStderr();
659663
}
660664

@@ -664,10 +668,17 @@ std::optional<const Realisation> RemoteStore::queryRealisation(const DrvOutput &
664668
conn->to << wopQueryRealisation;
665669
conn->to << id.to_string();
666670
conn.processStderr();
667-
auto outPaths = worker_proto::read(*this, conn->from, Phantom<std::set<StorePath>>{});
668-
if (outPaths.empty())
669-
return std::nullopt;
670-
return {Realisation{.id = id, .outPath = *outPaths.begin()}};
671+
if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 31) {
672+
auto outPaths = worker_proto::read(*this, conn->from, Phantom<std::set<StorePath>>{});
673+
if (outPaths.empty())
674+
return std::nullopt;
675+
return {Realisation{.id = id, .outPath = *outPaths.begin()}};
676+
} else {
677+
auto realisations = worker_proto::read(*this, conn->from, Phantom<std::set<Realisation>>{});
678+
if (realisations.empty())
679+
return std::nullopt;
680+
return *realisations.begin();
681+
}
671682
}
672683

673684
static void writeDerivedPaths(RemoteStore & store, ConnectionHandle & conn, const std::vector<DerivedPath> & reqs)

src/libstore/worker-protocol.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace nix {
99
#define WORKER_MAGIC_1 0x6e697863
1010
#define WORKER_MAGIC_2 0x6478696f
1111

12-
#define PROTOCOL_VERSION (1 << 8 | 30)
12+
#define PROTOCOL_VERSION (1 << 8 | 31)
1313
#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
1414
#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
1515

0 commit comments

Comments
 (0)