1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-15 15:02:42 +01:00

Merge pull request #13951 from NixOS/drop-old-daemon-protocol

Remove support for worker protocol version < 18
This commit is contained in:
Eelco Dolstra 2025-09-10 10:43:48 +02:00 committed by GitHub
commit f8b15bfc7f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 80 additions and 183 deletions

View file

@ -0,0 +1,6 @@
---
synopsis: "Removed support for daemons and clients older than Nix 2.0"
prs: [13951]
---
We have dropped support in the daemon worker protocol for daemons and clients that don't speak at least version 18 of the protocol. This first Nix release that supports this version is Nix 2.0, released in February 2018.

View file

@ -546,33 +546,9 @@ static void performOp(
break; break;
} }
case WorkerProto::Op::ExportPath: {
auto path = store->parseStorePath(readString(conn.from));
readInt(conn.from); // obsolete
logger->startWork();
TunnelSink sink(conn.to);
store->exportPath(path, sink);
logger->stopWork();
conn.to << 1;
break;
}
case WorkerProto::Op::ImportPaths: {
logger->startWork();
TunnelSource source(conn.from, conn.to);
auto paths = store->importPaths(source, trusted ? NoCheckSigs : CheckSigs);
logger->stopWork();
Strings paths2;
for (auto & i : paths)
paths2.push_back(store->printStorePath(i));
conn.to << paths2;
break;
}
case WorkerProto::Op::BuildPaths: { case WorkerProto::Op::BuildPaths: {
auto drvs = WorkerProto::Serialise<DerivedPaths>::read(*store, rconn); auto drvs = WorkerProto::Serialise<DerivedPaths>::read(*store, rconn);
BuildMode mode = bmNormal; BuildMode mode = bmNormal;
if (GET_PROTOCOL_MINOR(conn.protoVersion) >= 15) {
mode = WorkerProto::Serialise<BuildMode>::read(*store, rconn); mode = WorkerProto::Serialise<BuildMode>::read(*store, rconn);
/* Repairing is not atomic, so disallowed for "untrusted" /* Repairing is not atomic, so disallowed for "untrusted"
@ -586,7 +562,6 @@ static void performOp(
*/ */
if (mode == bmRepair && !trusted) if (mode == bmRepair && !trusted)
throw Error("repairing is not allowed because you are not in 'trusted-users'"); throw Error("repairing is not allowed because you are not in 'trusted-users'");
}
logger->startWork(); logger->startWork();
store->buildPaths(drvs, mode); store->buildPaths(drvs, mode);
logger->stopWork(); logger->stopWork();
@ -805,14 +780,12 @@ static void performOp(
clientSettings.buildCores = readInt(conn.from); clientSettings.buildCores = readInt(conn.from);
clientSettings.useSubstitutes = readInt(conn.from); clientSettings.useSubstitutes = readInt(conn.from);
if (GET_PROTOCOL_MINOR(conn.protoVersion) >= 12) {
unsigned int n = readInt(conn.from); unsigned int n = readInt(conn.from);
for (unsigned int i = 0; i < n; i++) { for (unsigned int i = 0; i < n; i++) {
auto name = readString(conn.from); auto name = readString(conn.from);
auto value = readString(conn.from); auto value = readString(conn.from);
clientSettings.overrides.emplace(name, value); clientSettings.overrides.emplace(name, value);
} }
}
logger->startWork(); logger->startWork();
@ -876,19 +849,12 @@ static void performOp(
auto path = store->parseStorePath(readString(conn.from)); auto path = store->parseStorePath(readString(conn.from));
std::shared_ptr<const ValidPathInfo> info; std::shared_ptr<const ValidPathInfo> info;
logger->startWork(); logger->startWork();
try {
info = store->queryPathInfo(path); info = store->queryPathInfo(path);
} catch (InvalidPath &) {
if (GET_PROTOCOL_MINOR(conn.protoVersion) < 17)
throw;
}
logger->stopWork(); logger->stopWork();
if (info) { if (info) {
if (GET_PROTOCOL_MINOR(conn.protoVersion) >= 17)
conn.to << 1; conn.to << 1;
WorkerProto::write(*store, wconn, static_cast<const UnkeyedValidPathInfo &>(*info)); WorkerProto::write(*store, wconn, static_cast<const UnkeyedValidPathInfo &>(*info));
} else { } else {
assert(GET_PROTOCOL_MINOR(conn.protoVersion) >= 17);
conn.to << 0; conn.to << 0;
} }
break; break;
@ -1063,7 +1029,7 @@ void processConnection(ref<Store> store, FdSource && from, FdSink && to, Trusted
auto [protoVersion, features] = auto [protoVersion, features] =
WorkerProto::BasicServerConnection::handshake(to, from, PROTOCOL_VERSION, WorkerProto::allFeatures); WorkerProto::BasicServerConnection::handshake(to, from, PROTOCOL_VERSION, WorkerProto::allFeatures);
if (protoVersion < 0x10a) if (protoVersion < 256 + 18)
throw Error("the Nix client version is too old"); throw Error("the Nix client version is too old");
WorkerProto::BasicServerConnection conn; WorkerProto::BasicServerConnection conn;

View file

@ -130,8 +130,6 @@ struct WorkerProto::BasicClientConnection : WorkerProto::BasicConnection
bool * daemonException, bool * daemonException,
const StorePath & path, const StorePath & path,
std::function<void(Source &)> fun); std::function<void(Source &)> fun);
void importPaths(const StoreDirConfig & store, bool * daemonException, Source & source);
}; };
struct WorkerProto::BasicServerConnection : WorkerProto::BasicConnection struct WorkerProto::BasicServerConnection : WorkerProto::BasicConnection

View file

@ -152,7 +152,6 @@ enum struct WorkerProto::Op : uint64_t {
AddIndirectRoot = 12, AddIndirectRoot = 12,
SyncWithGC = 13, SyncWithGC = 13,
FindRoots = 14, FindRoots = 14,
ExportPath = 16, // obsolete
QueryDeriver = 18, // obsolete QueryDeriver = 18, // obsolete
SetOptions = 19, SetOptions = 19,
CollectGarbage = 20, CollectGarbage = 20,
@ -162,7 +161,6 @@ enum struct WorkerProto::Op : uint64_t {
QueryFailedPaths = 24, QueryFailedPaths = 24,
ClearFailedPaths = 25, ClearFailedPaths = 25,
QueryPathInfo = 26, QueryPathInfo = 26,
ImportPaths = 27, // obsolete
QueryDerivationOutputNames = 28, // obsolete QueryDerivationOutputNames = 28, // obsolete
QueryPathFromHashPart = 29, QueryPathFromHashPart = 29,
QuerySubstitutablePathInfos = 30, QuerySubstitutablePathInfos = 30,

View file

@ -73,6 +73,8 @@ void RemoteStore::initConnection(Connection & conn)
try { try {
auto [protoVersion, features] = auto [protoVersion, features] =
WorkerProto::BasicClientConnection::handshake(conn.to, tee, PROTOCOL_VERSION, WorkerProto::allFeatures); WorkerProto::BasicClientConnection::handshake(conn.to, tee, PROTOCOL_VERSION, WorkerProto::allFeatures);
if (protoVersion < 256 + 18)
throw Error("the Nix daemon version is too old");
conn.protoVersion = protoVersion; conn.protoVersion = protoVersion;
conn.features = features; conn.features = features;
} catch (SerialisationError & e) { } catch (SerialisationError & e) {
@ -109,7 +111,6 @@ void RemoteStore::setOptions(Connection & conn)
<< 0 /* obsolete print build trace */ << 0 /* obsolete print build trace */
<< settings.buildCores << settings.useSubstitutes; << settings.buildCores << settings.useSubstitutes;
if (GET_PROTOCOL_MINOR(conn.protoVersion) >= 12) {
std::map<std::string, nix::Config::SettingInfo> overrides; std::map<std::string, nix::Config::SettingInfo> overrides;
settings.getSettings(overrides, true); // libstore settings settings.getSettings(overrides, true); // libstore settings
fileTransferSettings.getSettings(overrides, true); fileTransferSettings.getSettings(overrides, true);
@ -126,7 +127,6 @@ void RemoteStore::setOptions(Connection & conn)
conn.to << overrides.size(); conn.to << overrides.size();
for (auto & i : overrides) for (auto & i : overrides)
conn.to << i.first << i.second.value; conn.to << i.first << i.second.value;
}
auto ex = conn.processStderrReturn(); auto ex = conn.processStderrReturn();
if (ex) if (ex)
@ -167,16 +167,8 @@ bool RemoteStore::isValidPathUncached(const StorePath & path)
StorePathSet RemoteStore::queryValidPaths(const StorePathSet & paths, SubstituteFlag maybeSubstitute) StorePathSet RemoteStore::queryValidPaths(const StorePathSet & paths, SubstituteFlag maybeSubstitute)
{ {
auto conn(getConnection()); auto conn(getConnection());
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 12) {
StorePathSet res;
for (auto & i : paths)
if (isValidPath(i))
res.insert(i);
return res;
} else {
return conn->queryValidPaths(*this, &conn.daemonException, paths, maybeSubstitute); return conn->queryValidPaths(*this, &conn.daemonException, paths, maybeSubstitute);
} }
}
StorePathSet RemoteStore::queryAllValidPaths() StorePathSet RemoteStore::queryAllValidPaths()
{ {
@ -189,22 +181,11 @@ StorePathSet RemoteStore::queryAllValidPaths()
StorePathSet RemoteStore::querySubstitutablePaths(const StorePathSet & paths) StorePathSet RemoteStore::querySubstitutablePaths(const StorePathSet & paths)
{ {
auto conn(getConnection()); auto conn(getConnection());
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 12) {
StorePathSet res;
for (auto & i : paths) {
conn->to << WorkerProto::Op::HasSubstitutes << printStorePath(i);
conn.processStderr();
if (readInt(conn->from))
res.insert(i);
}
return res;
} else {
conn->to << WorkerProto::Op::QuerySubstitutablePaths; conn->to << WorkerProto::Op::QuerySubstitutablePaths;
WorkerProto::write(*this, *conn, paths); WorkerProto::write(*this, *conn, paths);
conn.processStderr(); conn.processStderr();
return WorkerProto::Serialise<StorePathSet>::read(*this, *conn); return WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
} }
}
void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, SubstitutablePathInfos & infos) void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, SubstitutablePathInfos & infos)
{ {
@ -213,26 +194,6 @@ void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, S
auto conn(getConnection()); auto conn(getConnection());
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 12) {
for (auto & i : pathsMap) {
SubstitutablePathInfo info;
conn->to << WorkerProto::Op::QuerySubstitutablePathInfo << printStorePath(i.first);
conn.processStderr();
unsigned int reply = readInt(conn->from);
if (reply == 0)
continue;
auto deriver = readString(conn->from);
if (deriver != "")
info.deriver = parseStorePath(deriver);
info.references = WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
info.downloadSize = readLongLong(conn->from);
info.narSize = readLongLong(conn->from);
infos.insert_or_assign(i.first, std::move(info));
}
} else {
conn->to << WorkerProto::Op::QuerySubstitutablePathInfos; conn->to << WorkerProto::Op::QuerySubstitutablePathInfos;
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 22) { if (GET_PROTOCOL_MINOR(conn->protoVersion) < 22) {
StorePathSet paths; StorePathSet paths;
@ -253,7 +214,6 @@ void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, S
info.narSize = readLongLong(conn->from); info.narSize = readLongLong(conn->from);
} }
} }
}
void RemoteStore::queryPathInfoUncached( void RemoteStore::queryPathInfoUncached(
const StorePath & path, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept const StorePath & path, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept
@ -466,21 +426,6 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, Repair
{ {
auto conn(getConnection()); auto conn(getConnection());
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 18) {
auto source2 = sinkToSource([&](Sink & sink) {
sink << 1 // == path follows
;
copyNAR(source, sink);
sink << exportMagic << printStorePath(info.path);
WorkerProto::write(*this, *conn, info.references);
sink << (info.deriver ? printStorePath(*info.deriver) : "") << 0 // == no legacy signature
<< 0 // == no path follows
;
});
conn->importPaths(*this, &conn.daemonException, *source2);
}
else {
conn->to << WorkerProto::Op::AddToStoreNar << printStorePath(info.path) conn->to << WorkerProto::Op::AddToStoreNar << printStorePath(info.path)
<< (info.deriver ? printStorePath(*info.deriver) : "") << (info.deriver ? printStorePath(*info.deriver) : "")
<< info.narHash.to_string(HashFormat::Base16, false); << info.narHash.to_string(HashFormat::Base16, false);
@ -497,7 +442,6 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, Repair
conn.processStderr(0, nullptr); conn.processStderr(0, nullptr);
} }
} }
}
void RemoteStore::addMultipleToStore( void RemoteStore::addMultipleToStore(
PathsSource && pathsToCopy, Activity & act, RepairFlag repair, CheckSigsFlag checkSigs) PathsSource && pathsToCopy, Activity & act, RepairFlag repair, CheckSigsFlag checkSigs)
@ -618,15 +562,8 @@ void RemoteStore::buildPaths(
auto conn(getConnection()); auto conn(getConnection());
conn->to << WorkerProto::Op::BuildPaths; conn->to << WorkerProto::Op::BuildPaths;
assert(GET_PROTOCOL_MINOR(conn->protoVersion) >= 13);
WorkerProto::write(*this, *conn, drvPaths); WorkerProto::write(*this, *conn, drvPaths);
if (GET_PROTOCOL_MINOR(conn->protoVersion) >= 15)
conn->to << buildMode; conn->to << buildMode;
else
/* Old daemons did not take a 'buildMode' parameter, so we
need to validate it here on the client side. */
if (buildMode != bmNormal)
throw Error("repairing or checking is not supported when building through the Nix daemon");
conn.processStderr(); conn.processStderr();
readInt(conn->from); readInt(conn->from);
} }

View file

@ -313,12 +313,4 @@ void WorkerProto::BasicClientConnection::narFromPath(
fun(from); fun(from);
} }
void WorkerProto::BasicClientConnection::importPaths(
const StoreDirConfig & store, bool * daemonException, Source & source)
{
to << WorkerProto::Op::ImportPaths;
processStderr(daemonException, 0, &source);
auto importedPaths = WorkerProto::Serialise<StorePathSet>::read(store, *this);
assert(importedPaths.size() <= importedPaths.size());
}
} // namespace nix } // namespace nix