From a92104f7acd9c36d0f665ab2540d8b070feb1a00 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 14 Feb 2025 17:25:38 -0500 Subject: [PATCH] Bare minimum `ssh-ng://` extensions for Hydra MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is not as comprehensive as #10748, but I am also interested in figuring out whether all those additions are in fact necessary. This is bare minimum needed for https://github.com/NixOS/hydra/pull/1445, which has notable gaps but nevertheless reimplements enough with `ssh-ng://` to past all tests. I would like to merge this change as definitely necessary, and unclear whether sufficient. Then I would iterate on the corresponding Hydra PR until it seems potentially correct, seeing what, if any, further Nix API changes are necessary. Co-authored-by: Jörg Thalheim --- src/libstore/remote-store.cc | 17 ++++++++++++++++- src/libstore/remote-store.hh | 12 ++++++++++++ src/libstore/ssh-store.cc | 2 +- src/libstore/ssh-store.hh | 5 +++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 533ea557d25..3bc1c38204b 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -767,7 +767,22 @@ BuildResult RemoteStore::buildDerivation(const StorePath & drvPath, const BasicD auto conn(getConnection()); conn->putBuildDerivationRequest(*this, &conn.daemonException, drvPath, drv, buildMode); conn.processStderr(); - return WorkerProto::Serialise::read(*this, *conn); + return conn->getBuildDerivationResponse(*this, &conn.daemonException); +} + + +std::function RemoteStore::buildDerivationAsync( + const StorePath & drvPath, const BasicDerivation & drv, + BuildMode buildMode) +{ + // Until we have C++23 std::move_only_function + auto conn = std::make_shared(getConnection()); + (*conn)->putBuildDerivationRequest(*this, &conn->daemonException, drvPath, drv, buildMode); + conn->processStderr(); + + return [this,conn]() -> BuildResult { + return (*conn)->getBuildDerivationResponse(*this, &conn->daemonException); + }; } diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index ea6cd471eb5..3645fb2074f 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -122,6 +122,18 @@ public: BuildResult buildDerivation(const StorePath & drvPath, const BasicDerivation & drv, BuildMode buildMode) override; + /** + * Note, the returned function must only be called once, or we'll + * try to read from the connection twice. + * + * This function is used by Hydra. + * + * @todo Use C++23 `std::move_only_function`. + */ + std::function buildDerivationAsync( + const StorePath & drvPath, const BasicDerivation & drv, + BuildMode buildMode); + void ensurePath(const StorePath & path) override; void addTempRoot(const StorePath & path) override; diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc index 954a9746774..8adece3efed 100644 --- a/src/libstore/ssh-store.cc +++ b/src/libstore/ssh-store.cc @@ -209,7 +209,7 @@ ref SSHStore::openConnection() } command.insert(command.end(), extraRemoteProgramArgs.begin(), extraRemoteProgramArgs.end()); - conn->sshConn = master.startCommand(std::move(command)); + conn->sshConn = master.startCommand(std::move(command), std::list{extraSshArgs}); conn->to = FdSink(conn->sshConn->in.get()); conn->from = FdSource(conn->sshConn->out.get()); return conn; diff --git a/src/libstore/ssh-store.hh b/src/libstore/ssh-store.hh index 29a2a8b2c2d..be15836985c 100644 --- a/src/libstore/ssh-store.hh +++ b/src/libstore/ssh-store.hh @@ -18,6 +18,11 @@ struct SSHStoreConfig : virtual RemoteStoreConfig, virtual CommonSSHStoreConfig const Setting remoteProgram{ this, {"nix-daemon"}, "remote-program", "Path to the `nix-daemon` executable on the remote machine."}; + /** + * Hack for hydra + */ + Strings extraSshArgs = {}; + const std::string name() override { return "Experimental SSH Store";