From 0deb492b3d3e311b54fc09ac4ad7c824dfccbc08 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Wed, 15 Oct 2025 23:57:06 +0300 Subject: [PATCH] Restore `ServeProto::Command::ImportPaths` This partially reverts commit 5e46df973f496cbdf375bfa24f27c156d24458e9, partially reversing changes made to 8c789db05b0bb4cd8dccc544b930837da52f423a. We do this because Hydra, while using the newer version of the protocol, still uses this command, even though Nix (as a client) doesn't use it. On that basis, we don't want to remove it (or consider it only part of the older versions of the protocol) until Hydra no longer uses the Legacy SSH Protocol. --- .../include/nix/store/serve-protocol-connection.hh | 2 ++ src/libstore/include/nix/store/serve-protocol.hh | 7 +++++++ src/libstore/serve-protocol-connection.cc | 10 ++++++++++ src/nix/nix-store/nix-store.cc | 10 ++++++++++ 4 files changed, 29 insertions(+) diff --git a/src/libstore/include/nix/store/serve-protocol-connection.hh b/src/libstore/include/nix/store/serve-protocol-connection.hh index 873277db9..fa50132c8 100644 --- a/src/libstore/include/nix/store/serve-protocol-connection.hh +++ b/src/libstore/include/nix/store/serve-protocol-connection.hh @@ -82,6 +82,8 @@ struct ServeProto::BasicClientConnection BuildResult getBuildDerivationResponse(const StoreDirConfig & store); void narFromPath(const StoreDirConfig & store, const StorePath & path, std::function fun); + + void importPaths(const StoreDirConfig & store, std::function fun); }; struct ServeProto::BasicServerConnection diff --git a/src/libstore/include/nix/store/serve-protocol.hh b/src/libstore/include/nix/store/serve-protocol.hh index 4c2043f17..974bf42d5 100644 --- a/src/libstore/include/nix/store/serve-protocol.hh +++ b/src/libstore/include/nix/store/serve-protocol.hh @@ -108,6 +108,13 @@ enum struct ServeProto::Command : uint64_t { QueryValidPaths = 1, QueryPathInfos = 2, DumpStorePath = 3, + /** + * @note This is no longer used by Nix (as a client), but it is used + * by Hydra. We should therefore not remove it until Hydra no longer + * uses it either. + */ + ImportPaths = 4, + // ExportPaths = 5, BuildPaths = 6, QueryClosure = 7, BuildDerivation = 8, diff --git a/src/libstore/serve-protocol-connection.cc b/src/libstore/serve-protocol-connection.cc index a90b104a6..baa3bf0ce 100644 --- a/src/libstore/serve-protocol-connection.cc +++ b/src/libstore/serve-protocol-connection.cc @@ -93,4 +93,14 @@ void ServeProto::BasicClientConnection::narFromPath( fun(from); } +void ServeProto::BasicClientConnection::importPaths(const StoreDirConfig & store, std::function fun) +{ + to << ServeProto::Command::ImportPaths; + fun(to); + to.flush(); + + if (readInt(from) != 1) + throw Error("remote machine failed to import closure"); +} + } // namespace nix diff --git a/src/nix/nix-store/nix-store.cc b/src/nix/nix-store/nix-store.cc index 313a6398c..3798c7fa0 100644 --- a/src/nix/nix-store/nix-store.cc +++ b/src/nix/nix-store/nix-store.cc @@ -986,6 +986,16 @@ static void opServe(Strings opFlags, Strings opArgs) store->narFromPath(store->parseStorePath(readString(in)), out); break; + case ServeProto::Command::ImportPaths: { + if (!writeAllowed) + throw Error("importing paths is not allowed"); + // FIXME: should we skip sig checking? + importPaths(*store, in, NoCheckSigs); + // indicate success + out << 1; + break; + } + case ServeProto::Command::BuildPaths: { if (!writeAllowed)