From 35dbdbedd41dea45bf38ae11d74f72c39eb304c3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 25 Jan 2022 21:14:27 +0100 Subject: [PATCH] nix store ping: Report Nix daemon version Fixes #5952. --- doc/manual/src/release-notes/rl-next.md | 1 + src/libstore/daemon.cc | 6 +++++- src/libstore/local-store.cc | 6 ++++++ src/libstore/local-store.hh | 2 ++ src/libstore/remote-store.cc | 14 +++++++++++++- src/libstore/remote-store.hh | 3 +++ src/libstore/store-api.hh | 3 +++ src/libstore/worker-protocol.hh | 2 +- src/nix/ping-store.cc | 3 +++ 9 files changed, 37 insertions(+), 3 deletions(-) diff --git a/doc/manual/src/release-notes/rl-next.md b/doc/manual/src/release-notes/rl-next.md index 78ae99f4b..d795e7b11 100644 --- a/doc/manual/src/release-notes/rl-next.md +++ b/doc/manual/src/release-notes/rl-next.md @@ -1,2 +1,3 @@ # Release X.Y (202?-??-??) +* `nix store ping` now reports the version of the remote Nix daemon. diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index 101aa13a5..1ddd1a4d5 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -981,7 +981,11 @@ void processConnection( readInt(from); } - readInt(from); // obsolete reserveSpace + if (GET_PROTOCOL_MINOR(clientVersion) >= 11) + readInt(from); // obsolete reserveSpace + + if (GET_PROTOCOL_MINOR(clientVersion) >= 33) + to << nixVersion; /* Send startup error messages to the client. */ tunnelLogger->startWork(); diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 1807940d8..284e385e6 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1919,4 +1919,10 @@ void LocalStore::addBuildLog(const StorePath & drvPath, std::string_view log) throw SysError("renaming '%1%' to '%2%'", tmpFile, logPath); } +std::optional LocalStore::getVersion() +{ + return nixVersion; +} + + } // namespace nix diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 6d867d778..8cf9c68b3 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -211,6 +211,8 @@ public: void queryRealisationUncached(const DrvOutput&, Callback> callback) noexcept override; + std::optional getVersion() override; + private: int getSchema(); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index aac2965e0..573becfbd 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -188,7 +188,12 @@ void RemoteStore::initConnection(Connection & conn) } if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 11) - conn.to << false; + conn.to << false; // obsolete reserveSpace + + if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 33) { + conn.to.flush(); + conn.daemonNixVersion = readString(conn.from); + } auto ex = conn.processStderr(); if (ex) std::rethrow_exception(ex); @@ -920,6 +925,13 @@ void RemoteStore::addBuildLog(const StorePath & drvPath, std::string_view log) } +std::optional RemoteStore::getVersion() +{ + auto conn(getConnection()); + return conn->daemonNixVersion; +} + + void RemoteStore::connect() { auto conn(getConnection()); diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index 4754ff45a..b91d25fa9 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -118,6 +118,8 @@ public: void addBuildLog(const StorePath & drvPath, std::string_view log) override; + std::optional getVersion() override; + void connect() override; unsigned int getProtocol() override; @@ -129,6 +131,7 @@ public: FdSink to; FdSource from; unsigned int daemonVersion; + std::optional daemonNixVersion; std::chrono::time_point startTime; virtual ~Connection(); diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 8306509f3..4068f8f35 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -765,6 +765,9 @@ public: * (a no-op when there’s no daemon) */ virtual void setOptions() { } + + virtual std::optional getVersion() { return {}; } + protected: Stats stats; diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh index ecf42a5d0..c8332afe6 100644 --- a/src/libstore/worker-protocol.hh +++ b/src/libstore/worker-protocol.hh @@ -9,7 +9,7 @@ namespace nix { #define WORKER_MAGIC_1 0x6e697863 #define WORKER_MAGIC_2 0x6478696f -#define PROTOCOL_VERSION (1 << 8 | 32) +#define PROTOCOL_VERSION (1 << 8 | 33) #define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00) #define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff) diff --git a/src/nix/ping-store.cc b/src/nix/ping-store.cc index 62b645b06..3c3b7bb45 100644 --- a/src/nix/ping-store.cc +++ b/src/nix/ping-store.cc @@ -20,7 +20,10 @@ struct CmdPingStore : StoreCommand void run(ref store) override { + notice("Store URL: %s", store->getUri()); store->connect(); + if (auto version = store->getVersion()) + notice("Version: %s", *version); } };