Skip to content

Commit

Permalink
Convert ssh:// to new system
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Jul 18, 2024
1 parent 901b34f commit 6e5d7fc
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 40 deletions.
58 changes: 46 additions & 12 deletions src/libstore/legacy-ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<config::SettingInfo>{
.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::JustValue>{
CONFIG_ROW(remoteProgram),
CONFIG_ROW(maxConnections),
}
{
#ifndef _WIN32
if (auto * p = get(params, "log-fd")) {
logFD = p->get<decltype(logFD)>();
}
#endif
}


std::string LegacySSHStoreConfig::doc()
{
return
Expand All @@ -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<const Store::Config &>(*this))
, connections(make_ref<Pool<Connection>>(
std::max(1, (int) maxConnections),
[this]() { return openConnection(); },
Expand Down Expand Up @@ -317,6 +351,6 @@ std::optional<TrustedFlag> isTrustedClient()
}


static RegisterStoreImplementation<LegacySSHStore, LegacySSHStoreConfig> regLegacySSHStore;
static RegisterStoreImplementation<LegacySSHStore> regLegacySSHStore;

}
51 changes: 30 additions & 21 deletions src/libstore/legacy-ssh-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,58 @@

namespace nix {

struct LegacySSHStoreConfig : virtual CommonSSHStoreConfig
template<template<typename> class F>
struct LegacySSHStoreConfigT
{
using CommonSSHStoreConfig::CommonSSHStoreConfig;
const F<Strings> remoteProgram;
const F<int> maxConnections;
};

struct LegacySSHStoreConfig :
virtual CommonSSHStoreConfig,
LegacySSHStoreConfigT<config::JustValue>
{
struct Descriptions :
virtual CommonSSHStoreConfig::Descriptions,
LegacySSHStoreConfigT<config::SettingInfo>
{
Descriptions();
};

static const Descriptions descriptions;

static LegacySSHStoreConfigT<config::JustValue> 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<Strings> remoteProgram{this, {"nix-store"}, "remote-program",
"Path to the `nix-store` executable on the remote machine."};

const Setting<int> 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<std::string> uriSchemes() { return {"ssh"}; }

std::string doc() override;

ref<Store> 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<int> 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;

ref<Pool<Connection>> connections;

SSHMaster master;

LegacySSHStore(
std::string_view scheme,
std::string_view host,
const Params & params);
LegacySSHStore(const Config &);

ref<Connection> openConnection();

Expand Down
11 changes: 4 additions & 7 deletions src/libstore/s3-binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ struct S3BinaryCacheStoreConfigT
const F<uint64_t> bufferSize;
};

struct S3BinaryCacheStoreConfig :
virtual BinaryCacheStoreConfig,
S3BinaryCacheStoreConfigT<config::JustValue>
struct S3BinaryCacheStoreConfig : virtual BinaryCacheStoreConfig, S3BinaryCacheStoreConfigT<config::JustValue>
{
struct Descriptions :
virtual Store::Config::Descriptions,
virtual BinaryCacheStore::Config::Descriptions,
S3BinaryCacheStoreConfigT<config::SettingInfo>
struct Descriptions : virtual Store::Config::Descriptions,
virtual BinaryCacheStore::Config::Descriptions,
S3BinaryCacheStoreConfigT<config::SettingInfo>
{
Descriptions();
};
Expand Down

0 comments on commit 6e5d7fc

Please sign in to comment.