From 6e5d7fc5d88b5fab7788c84b8dd85e4d9de5419a Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 18 Jul 2024 15:23:24 -0400 Subject: [PATCH] Convert ssh:// to new system --- src/libstore/legacy-ssh-store.cc | 58 +++++++++++++++++++++------ src/libstore/legacy-ssh-store.hh | 51 +++++++++++++---------- src/libstore/s3-binary-cache-store.hh | 11 ++--- 3 files changed, 80 insertions(+), 40 deletions(-) diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index eac360a4f7a..c27c7bc563e 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -12,18 +12,55 @@ #include "ssh.hh" #include "derivations.hh" #include "callback.hh" +#include "config-parse-impl.hh" +#include "store-registration.hh" namespace nix { -LegacySSHStoreConfig::LegacySSHStoreConfig( +LegacySSHStore::Config::Descriptions::Descriptions() + : Store::Config::Descriptions{Store::Config::descriptions} + , CommonSSHStoreConfig::Descriptions{CommonSSHStoreConfig::descriptions} + , LegacySSHStoreConfigT{ + .remoteProgram{ + .name = "remote-program", + .description = "Path to the `nix-store` executable on the remote machine.", + }, + .maxConnections{ + .name = "max-connections", + .description = "Maximum number of concurrent SSH connections.", + }, + } +{} + + +const LegacySSHStore::Config::Descriptions LegacySSHStore::Config::descriptions{}; + + +decltype(LegacySSHStore::Config::defaults) LegacySSHStore::Config::defaults = { + .remoteProgram = {{"nix-store"}}, + .maxConnections = {1}, +}; + + +LegacySSHStore::Config::LegacySSHStoreConfig( std::string_view scheme, std::string_view authority, - const Params & params) - : StoreConfig(params) + const StoreReference::Params & params) + : Store::Config(params) , CommonSSHStoreConfig(scheme, authority, params) + , LegacySSHStoreConfigT{ + CONFIG_ROW(remoteProgram), + CONFIG_ROW(maxConnections), + } { +#ifndef _WIN32 + if (auto * p = get(params, "log-fd")) { + logFD = p->get(); + } +#endif } + std::string LegacySSHStoreConfig::doc() { return @@ -38,14 +75,11 @@ struct LegacySSHStore::Connection : public ServeProto::BasicClientConnection bool good = true; }; -LegacySSHStore::LegacySSHStore( - std::string_view scheme, - std::string_view host, - const Params & params) - : StoreConfig(params) - , CommonSSHStoreConfig(scheme, host, params) - , LegacySSHStoreConfig(scheme, host, params) - , Store(params) +LegacySSHStore::LegacySSHStore(const Config & config) + : Store::Config(config) + , CommonSSHStoreConfig(config) + , LegacySSHStore::Config(config) + , Store(static_cast(*this)) , connections(make_ref>( std::max(1, (int) maxConnections), [this]() { return openConnection(); }, @@ -317,6 +351,6 @@ std::optional isTrustedClient() } -static RegisterStoreImplementation regLegacySSHStore; +static RegisterStoreImplementation regLegacySSHStore; } diff --git a/src/libstore/legacy-ssh-store.hh b/src/libstore/legacy-ssh-store.hh index b541455b4e5..0a58c803126 100644 --- a/src/libstore/legacy-ssh-store.hh +++ b/src/libstore/legacy-ssh-store.hh @@ -9,38 +9,50 @@ namespace nix { -struct LegacySSHStoreConfig : virtual CommonSSHStoreConfig +template class F> +struct LegacySSHStoreConfigT { - using CommonSSHStoreConfig::CommonSSHStoreConfig; + const F remoteProgram; + const F maxConnections; +}; + +struct LegacySSHStoreConfig : + virtual CommonSSHStoreConfig, + LegacySSHStoreConfigT +{ + struct Descriptions : + virtual CommonSSHStoreConfig::Descriptions, + LegacySSHStoreConfigT + { + Descriptions(); + }; + + static const Descriptions descriptions; + + static LegacySSHStoreConfigT defaults; + /** + * Hack for getting remote build log output. Intentionally not a + * documented user-visible setting. + */ + Descriptor logFD = INVALID_DESCRIPTOR; LegacySSHStoreConfig( std::string_view scheme, std::string_view authority, - const Params & params); - - const Setting remoteProgram{this, {"nix-store"}, "remote-program", - "Path to the `nix-store` executable on the remote machine."}; - - const Setting maxConnections{this, 1, "max-connections", - "Maximum number of concurrent SSH connections."}; + const StoreReference::Params & params); const std::string name() override { return "SSH Store"; } static std::set uriSchemes() { return {"ssh"}; } std::string doc() override; + + ref openStore() const override; }; struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Store { -#ifndef _WIN32 - // Hack for getting remote build log output. - // Intentionally not in `LegacySSHStoreConfig` so that it doesn't appear in - // the documentation - const Setting logFD{this, INVALID_DESCRIPTOR, "log-fd", "file descriptor to which SSH's stderr is connected"}; -#else - Descriptor logFD = INVALID_DESCRIPTOR; -#endif + using Config = LegacySSHStoreConfig; struct Connection; @@ -48,10 +60,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor SSHMaster master; - LegacySSHStore( - std::string_view scheme, - std::string_view host, - const Params & params); + LegacySSHStore(const Config &); ref openConnection(); diff --git a/src/libstore/s3-binary-cache-store.hh b/src/libstore/s3-binary-cache-store.hh index bff26f6b3d0..df7197113ae 100644 --- a/src/libstore/s3-binary-cache-store.hh +++ b/src/libstore/s3-binary-cache-store.hh @@ -21,14 +21,11 @@ struct S3BinaryCacheStoreConfigT const F bufferSize; }; -struct S3BinaryCacheStoreConfig : - virtual BinaryCacheStoreConfig, - S3BinaryCacheStoreConfigT +struct S3BinaryCacheStoreConfig : virtual BinaryCacheStoreConfig, S3BinaryCacheStoreConfigT { - struct Descriptions : - virtual Store::Config::Descriptions, - virtual BinaryCacheStore::Config::Descriptions, - S3BinaryCacheStoreConfigT + struct Descriptions : virtual Store::Config::Descriptions, + virtual BinaryCacheStore::Config::Descriptions, + S3BinaryCacheStoreConfigT { Descriptions(); };