nix store ping: Report Nix daemon version

Fixes #5952.
This commit is contained in:
Eelco Dolstra 2022-01-25 21:14:27 +01:00
parent fcf3528ad1
commit 35dbdbedd4
9 changed files with 37 additions and 3 deletions

View file

@ -1,2 +1,3 @@
# Release X.Y (202?-??-??) # Release X.Y (202?-??-??)
* `nix store ping` now reports the version of the remote Nix daemon.

View file

@ -981,8 +981,12 @@ void processConnection(
readInt(from); readInt(from);
} }
if (GET_PROTOCOL_MINOR(clientVersion) >= 11)
readInt(from); // obsolete reserveSpace readInt(from); // obsolete reserveSpace
if (GET_PROTOCOL_MINOR(clientVersion) >= 33)
to << nixVersion;
/* Send startup error messages to the client. */ /* Send startup error messages to the client. */
tunnelLogger->startWork(); tunnelLogger->startWork();

View file

@ -1919,4 +1919,10 @@ void LocalStore::addBuildLog(const StorePath & drvPath, std::string_view log)
throw SysError("renaming '%1%' to '%2%'", tmpFile, logPath); throw SysError("renaming '%1%' to '%2%'", tmpFile, logPath);
} }
std::optional<std::string> LocalStore::getVersion()
{
return nixVersion;
}
} // namespace nix } // namespace nix

View file

@ -211,6 +211,8 @@ public:
void queryRealisationUncached(const DrvOutput&, void queryRealisationUncached(const DrvOutput&,
Callback<std::shared_ptr<const Realisation>> callback) noexcept override; Callback<std::shared_ptr<const Realisation>> callback) noexcept override;
std::optional<std::string> getVersion() override;
private: private:
int getSchema(); int getSchema();

View file

@ -188,7 +188,12 @@ void RemoteStore::initConnection(Connection & conn)
} }
if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 11) 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(); auto ex = conn.processStderr();
if (ex) std::rethrow_exception(ex); if (ex) std::rethrow_exception(ex);
@ -920,6 +925,13 @@ void RemoteStore::addBuildLog(const StorePath & drvPath, std::string_view log)
} }
std::optional<std::string> RemoteStore::getVersion()
{
auto conn(getConnection());
return conn->daemonNixVersion;
}
void RemoteStore::connect() void RemoteStore::connect()
{ {
auto conn(getConnection()); auto conn(getConnection());

View file

@ -118,6 +118,8 @@ public:
void addBuildLog(const StorePath & drvPath, std::string_view log) override; void addBuildLog(const StorePath & drvPath, std::string_view log) override;
std::optional<std::string> getVersion() override;
void connect() override; void connect() override;
unsigned int getProtocol() override; unsigned int getProtocol() override;
@ -129,6 +131,7 @@ public:
FdSink to; FdSink to;
FdSource from; FdSource from;
unsigned int daemonVersion; unsigned int daemonVersion;
std::optional<std::string> daemonNixVersion;
std::chrono::time_point<std::chrono::steady_clock> startTime; std::chrono::time_point<std::chrono::steady_clock> startTime;
virtual ~Connection(); virtual ~Connection();

View file

@ -765,6 +765,9 @@ public:
* (a no-op when theres no daemon) * (a no-op when theres no daemon)
*/ */
virtual void setOptions() { } virtual void setOptions() { }
virtual std::optional<std::string> getVersion() { return {}; }
protected: protected:
Stats stats; Stats stats;

View file

@ -9,7 +9,7 @@ namespace nix {
#define WORKER_MAGIC_1 0x6e697863 #define WORKER_MAGIC_1 0x6e697863
#define WORKER_MAGIC_2 0x6478696f #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_MAJOR(x) ((x) & 0xff00)
#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff) #define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)

View file

@ -20,7 +20,10 @@ struct CmdPingStore : StoreCommand
void run(ref<Store> store) override void run(ref<Store> store) override
{ {
notice("Store URL: %s", store->getUri());
store->connect(); store->connect();
if (auto version = store->getVersion())
notice("Version: %s", *version);
} }
}; };