Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Jul 18, 2024
1 parent 6e5d7fc commit 74620b9
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 87 deletions.
12 changes: 6 additions & 6 deletions src/libstore/legacy-ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ LegacySSHStore::Config::LegacySSHStoreConfig(
std::string_view scheme,
std::string_view authority,
const StoreReference::Params & params)
: Store::Config(params)
, CommonSSHStoreConfig(scheme, authority, params)
: Store::Config{params}
, CommonSSHStoreConfig{scheme, authority, params}
, LegacySSHStoreConfigT<config::JustValue>{
CONFIG_ROW(remoteProgram),
CONFIG_ROW(maxConnections),
Expand Down Expand Up @@ -76,10 +76,10 @@ struct LegacySSHStore::Connection : public ServeProto::BasicClientConnection
};

LegacySSHStore::LegacySSHStore(const Config & config)
: Store::Config(config)
, CommonSSHStoreConfig(config)
, LegacySSHStore::Config(config)
, Store(static_cast<const Store::Config &>(*this))
: 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
1 change: 1 addition & 0 deletions src/libstore/legacy-ssh-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct LegacySSHStoreConfig :
static const Descriptions descriptions;

static LegacySSHStoreConfigT<config::JustValue> defaults;

/**
* Hack for getting remote build log output. Intentionally not a
* documented user-visible setting.
Expand Down
53 changes: 35 additions & 18 deletions src/libstore/remote-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,50 @@
#include "callback.hh"
#include "filetransfer.hh"
#include "signals.hh"
#include "config-parse-impl.hh"

#include <nlohmann/json.hpp>

namespace nix {

#if 0
const Setting<int> maxConnections{this, 1, "max-connections",
"Maximum number of concurrent connections to the Nix daemon."};
RemoteStore::Config::Descriptions::Descriptions()
: Store::Config::Descriptions{Store::Config::descriptions}
, RemoteStoreConfigT<config::SettingInfo>{
.maxConnections{
.name = "max-connections",
.description = "Maximum number of concurrent connections to the Nix daemon.",
},
.maxConnectionAge{
.name = "max-connection-age",
.description = "Maximum age of a connection before it is closed.",
},
}
{}


const RemoteStore::Config::Descriptions RemoteStore::Config::descriptions{};


const Setting<unsigned int> maxConnectionAge{this,
std::numeric_limits<unsigned int>::max(),
"max-connection-age",
"Maximum age of a connection before it is closed."};
decltype(RemoteStore::Config::defaults) RemoteStore::Config::defaults = {
.maxConnections = {1},
.maxConnectionAge = {std::numeric_limits<unsigned int>::max()},
};

const Setting<int> maxConnections{this, 1, "max-connections",
"Maximum number of concurrent connections to the Nix daemon."};

const Setting<unsigned int> maxConnectionAge{this,
std::numeric_limits<unsigned int>::max(),
"max-connection-age",
"Maximum age of a connection before it is closed."};
#endif
RemoteStore::Config::RemoteStoreConfig(const StoreReference::Params & params)
: Store::Config(params)
, RemoteStoreConfigT<config::JustValue>{
CONFIG_ROW(maxConnections),
CONFIG_ROW(maxConnectionAge),
}
{
}


/* TODO: Separate these store types into different files, give them better names */
RemoteStore::RemoteStore(const Params & params)
: RemoteStoreConfig(params)
, Store(params)
RemoteStore::RemoteStore(const Config & config)
: RemoteStore::Config(config)
, Store(static_cast<const Store::Config &>(*this))
, connections(make_ref<Pool<Connection>>(
std::max(1, (int) maxConnections),
[this]() {
Expand Down Expand Up @@ -134,7 +151,7 @@ void RemoteStore::setOptions(Connection & conn)
<< settings.useSubstitutes;

if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 12) {
std::map<std::string, Config::SettingInfo> overrides;
std::map<std::string, nix::Config::SettingInfo> overrides;
settings.getSettings(overrides, true); // libstore settings
fileTransferSettings.getSettings(overrides, true);
overrides.erase(settings.keepFailed.name);
Expand Down
3 changes: 2 additions & 1 deletion src/libstore/remote-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ template<template<typename> class F>
struct RemoteStoreConfigT
{
const F<int> maxConnections;

const F<unsigned int> maxConnectionAge;
};

Expand All @@ -43,6 +42,8 @@ struct RemoteStoreConfig :
* The other defaults depend on the choice of `storeDir` and `rootDir`
*/
static RemoteStoreConfigT<config::JustValue> defaults;

RemoteStoreConfig(const StoreReference::Params &);
};

/**
Expand Down
118 changes: 67 additions & 51 deletions src/libstore/ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,65 @@
#include "worker-protocol-impl.hh"
#include "pool.hh"
#include "ssh.hh"
#include "config-parse-impl.hh"
#include "store-registration.hh"

namespace nix {

SSHStoreConfig::Descriptions::Descriptions()
: Store::Config::Descriptions{Store::Config::descriptions}
, CommonSSHStoreConfig::Descriptions{CommonSSHStoreConfig::descriptions}
, SSHStoreConfigT<config::SettingInfo>{
.remoteProgram{
.name = "remote-program",
.description = "Path to the `nix-daemon` executable on the remote machine.",
},
}
{}


const SSHStoreConfig::Descriptions SSHStoreConfig::descriptions{};


decltype(SSHStoreConfig::defaults) SSHStoreConfig::defaults = {
.remoteProgram = {{"nix-daemon"}},
};


SSHStoreConfig::SSHStoreConfig(
std::string_view scheme,
std::string_view authority,
const Params & params)
: StoreConfig(params)
, RemoteStoreConfig(params)
, CommonSSHStoreConfig(scheme, authority, params)
const StoreReference::Params & params)
: Store::Config{params}
, RemoteStore::Config{params}
, CommonSSHStoreConfig{scheme, authority, params}
, SSHStoreConfigT<config::JustValue>{
CONFIG_ROW(remoteProgram),
}
{
}


std::string SSHStoreConfig::doc()
{
return
#include "ssh-store.md"
;
}

class SSHStore : public virtual SSHStoreConfig, public virtual RemoteStore
struct SSHStore :
public virtual SSHStoreConfig,
public virtual RemoteStore
{
public:

SSHStore(
std::string_view scheme,
std::string_view host,
const Params & params)
: StoreConfig(params)
, RemoteStoreConfig(params)
, CommonSSHStoreConfig(scheme, host, params)
, SSHStoreConfig(scheme, host, params)
, Store(params)
, RemoteStore(params)
using Config = SSHStoreConfig;

SSHStore(const Config & config)
: Store::Config{config}
, RemoteStore::Config{config}
, CommonSSHStoreConfig{config}
, SSHStore::Config{config}
, Store{static_cast<const Store::Config &>(*this)}
, RemoteStore{static_cast<const RemoteStore::Config &>(*this)}
, master(createSSHMaster(
// Use SSH master only if using more than 1 connection.
connections->capacity() > 1))
Expand Down Expand Up @@ -88,21 +113,15 @@ class SSHStore : public virtual SSHStoreConfig, public virtual RemoteStore
};


MountedSSHStoreConfig::MountedSSHStoreConfig(StringMap params)
: StoreConfig(params)
, RemoteStoreConfig(params)
, CommonSSHStoreConfig(params)
, SSHStoreConfig(params)
, LocalFSStoreConfig(params)
{
}

MountedSSHStoreConfig::MountedSSHStoreConfig(std::string_view scheme, std::string_view host, StringMap params)
: StoreConfig(params)
, RemoteStoreConfig(params)
, CommonSSHStoreConfig(scheme, host, params)
, SSHStoreConfig(params)
, LocalFSStoreConfig(params)
MountedSSHStoreConfig::MountedSSHStoreConfig(
std::string_view scheme,
std::string_view host,
const StoreReference::Params & params)
: Store::Config{params}
, RemoteStore::Config{params}
, CommonSSHStoreConfig{scheme, host, params}
, SSHStoreConfig{scheme, host, params}
, LocalFSStoreConfig{params}
{
}

Expand All @@ -128,24 +147,21 @@ std::string MountedSSHStoreConfig::doc()
* The difference lies in how they manage GC roots. See addPermRoot
* below for details.
*/
class MountedSSHStore : public virtual MountedSSHStoreConfig, public virtual SSHStore, public virtual LocalFSStore
struct MountedSSHStore : virtual MountedSSHStoreConfig, virtual SSHStore, virtual LocalFSStore
{
public:

MountedSSHStore(
std::string_view scheme,
std::string_view host,
const Params & params)
: StoreConfig(params)
, RemoteStoreConfig(params)
, CommonSSHStoreConfig(scheme, host, params)
, SSHStoreConfig(params)
, LocalFSStoreConfig(params)
, MountedSSHStoreConfig(params)
, Store(params)
, RemoteStore(params)
, SSHStore(scheme, host, params)
, LocalFSStore(params)
using Config = MountedSSHStoreConfig;

MountedSSHStore(const Config & config)
: Store::Config{config}
, RemoteStore::Config{config}
, CommonSSHStoreConfig{config}
, SSHStore::Config{config}
, LocalFSStore::Config{config}
, MountedSSHStore::Config{config}
, Store{static_cast<const Store::Config &>(*this)}
, RemoteStore{static_cast<const RemoteStore::Config &>(*this)}
, SSHStore{static_cast<const SSHStore::Config &>(*this)}
, LocalFSStore{static_cast<const LocalFSStore::Config &>(*this)}
{
extraRemoteProgramArgs = {
"--process-ops",
Expand Down Expand Up @@ -215,7 +231,7 @@ ref<RemoteStore::Connection> SSHStore::openConnection()
return conn;
}

static RegisterStoreImplementation<SSHStore, SSHStoreConfig> regSSHStore;
static RegisterStoreImplementation<MountedSSHStore, MountedSSHStoreConfig> regMountedSSHStore;
static RegisterStoreImplementation<SSHStore> regSSHStore;
static RegisterStoreImplementation<MountedSSHStore> regMountedSSHStore;

}
39 changes: 28 additions & 11 deletions src/libstore/ssh-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,26 @@

namespace nix {

struct SSHStoreConfig : virtual RemoteStoreConfig, virtual CommonSSHStoreConfig
template<template<typename> class F>
struct SSHStoreConfigT
{
using CommonSSHStoreConfig::CommonSSHStoreConfig;
using RemoteStoreConfig::RemoteStoreConfig;
const F<Strings> remoteProgram;
};

struct SSHStoreConfig : virtual RemoteStoreConfig,
virtual CommonSSHStoreConfig,
SSHStoreConfigT<config::JustValue>
{
struct Descriptions : virtual CommonSSHStoreConfig::Descriptions, SSHStoreConfigT<config::SettingInfo>
{
Descriptions();
};

SSHStoreConfig(std::string_view scheme, std::string_view authority, const Params & params);
static const Descriptions descriptions;

const Setting<Strings> remoteProgram{
this, {"nix-daemon"}, "remote-program", "Path to the `nix-daemon` executable on the remote machine."};
static SSHStoreConfigT<config::JustValue> defaults;

SSHStoreConfig(std::string_view scheme, std::string_view authority, const StoreReference::Params & params);

const std::string name() override
{
Expand All @@ -29,16 +40,20 @@ struct SSHStoreConfig : virtual RemoteStoreConfig, virtual CommonSSHStoreConfig
}

std::string doc() override;

ref<Store> openStore() const override;
};

struct MountedSSHStoreConfig : virtual SSHStoreConfig, virtual LocalFSStoreConfig
struct MountedSSHStoreConfig : virtual SSHStoreConfig, virtual LocalFSStore::Config
{
using LocalFSStoreConfig::LocalFSStoreConfig;
using SSHStoreConfig::SSHStoreConfig;
struct Descriptions : virtual SSHStoreConfig::Descriptions, virtual LocalFSStore::Config::Descriptions
{
Descriptions();
};

MountedSSHStoreConfig(StringMap params);
static const Descriptions descriptions;

MountedSSHStoreConfig(std::string_view scheme, std::string_view host, StringMap params);
MountedSSHStoreConfig(std::string_view scheme, std::string_view host, const StoreReference::Params & params);

const std::string name() override
{
Expand All @@ -56,6 +71,8 @@ struct MountedSSHStoreConfig : virtual SSHStoreConfig, virtual LocalFSStoreConfi
{
return ExperimentalFeature::MountedSSHStore;
}

ref<Store> openStore() const override;
};

}

0 comments on commit 74620b9

Please sign in to comment.