diff --git a/src/libcmd/common-eval-args.cc b/src/libcmd/common-eval-args.cc index decadd751cc..fc75f047f4b 100644 --- a/src/libcmd/common-eval-args.cc +++ b/src/libcmd/common-eval-args.cc @@ -9,7 +9,7 @@ #include "registry.hh" #include "flake/flakeref.hh" #include "flake/settings.hh" -#include "store-api.hh" +#include "store-open.hh" #include "command.hh" #include "tarball.hh" #include "fetch-to-store.hh" diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index b5d0816dd2c..4dd41ca663d 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -12,7 +12,7 @@ #include "eval-settings.hh" #include "attr-path.hh" #include "signals.hh" -#include "store-api.hh" +#include "store-open.hh" #include "log-store.hh" #include "common-eval-args.hh" #include "get-drvs.hh" @@ -635,7 +635,7 @@ ProcessLineResult NixRepl::processLine(std::string line) // When missing, trigger the normal exception // e.g. :doc builtins.foo // behaves like - // nix-repl> builtins.foo + // nix-repl> builtins.foo // error: attribute 'foo' missing evalString(arg, v); assert(false); diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index e8c8892b337..4adc599007e 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -13,6 +13,7 @@ #include "callback.hh" #include "signals.hh" #include "archive.hh" +#include "config-parse-impl.hh" #include #include @@ -24,9 +25,74 @@ namespace nix { -BinaryCacheStore::BinaryCacheStore(const Params & params) - : BinaryCacheStoreConfig(params) - , Store(params) +BinaryCacheStore::Config::Descriptions::Descriptions() + : Store::Config::Descriptions{Store::Config::descriptions} + , BinaryCacheStoreConfigT{ + .compression = { + .name = "compression", + .description = "NAR compression method (`xz`, `bzip2`, `gzip`, `zstd`, or `none`).", + }, + .writeNARListing = { + .name = "write-nar-listing", + .description = "Whether to write a JSON file that lists the files in each NAR.", + }, + .writeDebugInfo = { + .name = "index-debug-info", + .description = R"( + Whether to index DWARF debug info files by build ID. This allows [`dwarffs`](https://github.com/edolstra/dwarffs) to + fetch debug info on demand + )", + }, + .secretKeyFile{ + .name = "secret-key", + .description = "Path to the secret key used to sign the binary cache.", + }, + .localNarCache{ + .name = "local-nar-cache", + .description = "Path to a local cache of NARs fetched from this binary cache, used by commands such as `nix store cat`.", + }, + .parallelCompression{ + .name = "parallel-compression", + .description = "Enable multi-threaded compression of NARs. This is currently only available for `xz` and `zstd`.", + }, + .compressionLevel{ + .name = "compression-level", + .description = R"( + The *preset level* to be used when compressing NARs. + The meaning and accepted values depend on the compression method selected. + `-1` specifies that the default compression level should be used. + )", + }, + } +{} + +const BinaryCacheStore::Config::Descriptions BinaryCacheStore::Config::descriptions{}; + +decltype(BinaryCacheStore::Config::defaults) BinaryCacheStore::Config::defaults = { + .compression = {"xz"}, + .writeNARListing{false}, + .writeDebugInfo{false}, + .secretKeyFile{""}, + .localNarCache{""}, + .parallelCompression{false}, + .compressionLevel{-1}, +}; + +BinaryCacheStore::Config::BinaryCacheStoreConfig(const StoreReference::Params & params) + : StoreConfig{params} + , BinaryCacheStoreConfigT{ + CONFIG_ROW(compression), + CONFIG_ROW(secretKeyFile), + CONFIG_ROW(localNarCache), + CONFIG_ROW(parallelCompression), + CONFIG_ROW(compressionLevel), + } +{ +} + +BinaryCacheStore::BinaryCacheStore(const Config & config) + : Config{config} + , Store{static_cast(*this)} { if (secretKeyFile != "") signer = std::make_unique( diff --git a/src/libstore/binary-cache-store.hh b/src/libstore/binary-cache-store.hh index 234c39caf3a..27d7a845ab7 100644 --- a/src/libstore/binary-cache-store.hh +++ b/src/libstore/binary-cache-store.hh @@ -13,48 +13,46 @@ namespace nix { struct NarInfo; -struct BinaryCacheStoreConfig : virtual StoreConfig +template class F> +struct BinaryCacheStoreConfigT { - using StoreConfig::StoreConfig; - - const Setting compression{this, "xz", "compression", - "NAR compression method (`xz`, `bzip2`, `gzip`, `zstd`, or `none`)."}; - - const Setting writeNARListing{this, false, "write-nar-listing", - "Whether to write a JSON file that lists the files in each NAR."}; - - const Setting writeDebugInfo{this, false, "index-debug-info", - R"( - Whether to index DWARF debug info files by build ID. This allows [`dwarffs`](https://github.com/edolstra/dwarffs) to - fetch debug info on demand - )"}; + const F compression; + const F writeNARListing; + const F writeDebugInfo; + const F secretKeyFile; + const F localNarCache; + const F parallelCompression; + const F compressionLevel; +}; - const Setting secretKeyFile{this, "", "secret-key", - "Path to the secret key used to sign the binary cache."}; +struct BinaryCacheStoreConfig : + virtual Store::Config, + BinaryCacheStoreConfigT +{ + struct Descriptions : + virtual Store::Config::Descriptions, + BinaryCacheStoreConfigT + { + Descriptions(); + }; - const Setting localNarCache{this, "", "local-nar-cache", - "Path to a local cache of NARs fetched from this binary cache, used by commands such as `nix store cat`."}; + static const Descriptions descriptions; - const Setting parallelCompression{this, false, "parallel-compression", - "Enable multi-threaded compression of NARs. This is currently only available for `xz` and `zstd`."}; + static BinaryCacheStoreConfigT defaults; - const Setting compressionLevel{this, -1, "compression-level", - R"( - The *preset level* to be used when compressing NARs. - The meaning and accepted values depend on the compression method selected. - `-1` specifies that the default compression level should be used. - )"}; + BinaryCacheStoreConfig(const StoreReference::Params &); }; - /** * @note subclasses must implement at least one of the two * virtual getFile() methods. */ -class BinaryCacheStore : public virtual BinaryCacheStoreConfig, - public virtual Store, - public virtual LogStore +struct BinaryCacheStore : + virtual BinaryCacheStoreConfig, + virtual Store, + virtual LogStore { + using Config = BinaryCacheStoreConfig; private: std::unique_ptr signer; @@ -64,7 +62,7 @@ protected: // The prefix under which realisation infos will be stored const std::string realisationsPrefix = "realisations"; - BinaryCacheStore(const Params & params); + BinaryCacheStore(const Config &); public: diff --git a/src/libstore/build/substitution-goal.cc b/src/libstore/build/substitution-goal.cc index 7deeb47487d..32189ca7ae5 100644 --- a/src/libstore/build/substitution-goal.cc +++ b/src/libstore/build/substitution-goal.cc @@ -1,4 +1,5 @@ #include "worker.hh" +#include "store-open.hh" #include "substitution-goal.hh" #include "nar-info.hh" #include "finally.hh" diff --git a/src/libstore/common-ssh-store-config.cc b/src/libstore/common-ssh-store-config.cc index 05332b9bb5c..e1448b4b4eb 100644 --- a/src/libstore/common-ssh-store-config.cc +++ b/src/libstore/common-ssh-store-config.cc @@ -2,9 +2,45 @@ #include "common-ssh-store-config.hh" #include "ssh.hh" +#include "config-parse-impl.hh" namespace nix { +CommonSSHStoreConfig::Descriptions::Descriptions() + : Store::Config::Descriptions{Store::Config::descriptions} + , CommonSSHStoreConfigT{ + .sshKey{ + .name = "ssh-key", + .description = "Path to the SSH private key used to authenticate to the remote machine.", + }, + .sshPublicHostKey = { + .name = "base64-ssh-public-host-key", + .description = "The public host key of the remote machine.", + }, + .compress = { + .name = "compress", + .description = "Whether to enable SSH compression.", + }, + .remoteStore{ + .name = "remote-store", + .description = R"( + [Store URL](@docroot@/store/types/index.md#store-url-format) + to be used on the remote machine. The default is `auto` + (i.e. use the Nix daemon or `/nix/store` directly). + )", + }, + } +{} + +const CommonSSHStoreConfig::Descriptions CommonSSHStoreConfig::descriptions{}; + +decltype(CommonSSHStoreConfig::defaults) CommonSSHStoreConfig::defaults = { + .sshKey{""}, + .sshPublicHostKey{""}, + .compress{false}, + .remoteStore{""}, +}; + static std::string extractConnStr(std::string_view scheme, std::string_view _connStr) { if (_connStr.empty()) @@ -22,8 +58,17 @@ static std::string extractConnStr(std::string_view scheme, std::string_view _con return connStr; } -CommonSSHStoreConfig::CommonSSHStoreConfig(std::string_view scheme, std::string_view host, const Params & params) - : StoreConfig(params) +CommonSSHStoreConfig::CommonSSHStoreConfig( + std::string_view scheme, + std::string_view host, + const StoreReference::Params & params) + : Store::Config(params) + , CommonSSHStoreConfigT{ + CONFIG_ROW(sshKey), + CONFIG_ROW(sshPublicHostKey), + CONFIG_ROW(compress), + CONFIG_ROW(remoteStore), + } , host(extractConnStr(scheme, host)) { } diff --git a/src/libstore/common-ssh-store-config.hh b/src/libstore/common-ssh-store-config.hh index 5deb6f4c9e9..4def51da0e5 100644 --- a/src/libstore/common-ssh-store-config.hh +++ b/src/libstore/common-ssh-store-config.hh @@ -7,27 +7,38 @@ namespace nix { class SSHMaster; -struct CommonSSHStoreConfig : virtual StoreConfig +template class F> +struct CommonSSHStoreConfigT { - using StoreConfig::StoreConfig; - - CommonSSHStoreConfig(std::string_view scheme, std::string_view host, const Params & params); + const F sshKey; + const F sshPublicHostKey; + const F compress; + const F remoteStore; +}; - const Setting sshKey{this, "", "ssh-key", - "Path to the SSH private key used to authenticate to the remote machine."}; +struct CommonSSHStoreConfig : + virtual Store::Config, + CommonSSHStoreConfigT +{ + struct Descriptions : + virtual Store::Config::Descriptions, + CommonSSHStoreConfigT + { + Descriptions(); + }; - const Setting sshPublicHostKey{this, "", "base64-ssh-public-host-key", - "The public host key of the remote machine."}; + static const Descriptions descriptions; - const Setting compress{this, false, "compress", - "Whether to enable SSH compression."}; + static CommonSSHStoreConfigT defaults; - const Setting remoteStore{this, "", "remote-store", - R"( - [Store URL](@docroot@/store/types/index.md#store-url-format) - to be used on the remote machine. The default is `auto` - (i.e. use the Nix daemon or `/nix/store` directly). - )"}; + /** + * @param scheme Note this isn't stored by this mix-in class, but + * just used for better error messages. + */ + CommonSSHStoreConfig( + std::string_view scheme, + std::string_view host, + const StoreReference::Params & params); /** * The `parseURL` function supports both IPv6 URIs as defined in diff --git a/src/libstore/local-fs-store.cc b/src/libstore/local-fs-store.cc index a8b23996159..12035c1efe7 100644 --- a/src/libstore/local-fs-store.cc +++ b/src/libstore/local-fs-store.cc @@ -33,15 +33,15 @@ LocalFSStore::Config::Descriptions::Descriptions() const LocalFSStore::Config::Descriptions LocalFSStore::Config::descriptions{}; -LocalFSStoreConfigT LocalFSStoreConfig::defaults( +LocalFSStoreConfigT LocalFSStore::Config::defaults( const Store::Config & storeConfig, const std::optional rootDir) { return { - .rootDir = {.value = std::nullopt }, - .stateDir = {.value = rootDir ? *rootDir + "/nix/var/nix" : settings.nixStateDir }, - .logDir = {.value = rootDir ? *rootDir + "/nix/var/log/nix" : settings.nixLogDir }, - .realStoreDir = {.value = rootDir ? *rootDir + "/nix/store" : storeConfig.storeDir }, + .rootDir = {std::nullopt}, + .stateDir = {rootDir ? *rootDir + "/nix/var/nix" : settings.nixStateDir}, + .logDir = {rootDir ? *rootDir + "/nix/var/log/nix" : settings.nixLogDir}, + .realStoreDir = {rootDir ? *rootDir + "/nix/store" : storeConfig.storeDir}, }; } diff --git a/src/libstore/local-fs-store.hh b/src/libstore/local-fs-store.hh index 654dd210f40..051e4494012 100644 --- a/src/libstore/local-fs-store.hh +++ b/src/libstore/local-fs-store.hh @@ -11,11 +11,8 @@ template class F> struct LocalFSStoreConfigT { const F> rootDir; - const F stateDir; - const F logDir; - const F realStoreDir; }; diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 2dfc78ebda3..aff70589d18 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -89,8 +89,8 @@ LocalStore::Config::Descriptions::Descriptions() const LocalStore::Config::Descriptions LocalStore::Config::descriptions{}; decltype(LocalStore::Config::defaults) LocalStore::Config::defaults = { - .requireSigs = {.value = settings.requireSigs }, - .readOnly = {.value = false }, + .requireSigs = {settings.requireSigs}, + .readOnly = {false}, }; LocalStore::Config::LocalStoreConfig( diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 13e26922c0a..06e402f80f9 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -38,7 +38,6 @@ template class F> struct LocalStoreConfigT { const F requireSigs; - const F readOnly; }; diff --git a/src/libstore/remote-fs-accessor.hh b/src/libstore/remote-fs-accessor.hh index d09762a53c4..6946074affa 100644 --- a/src/libstore/remote-fs-accessor.hh +++ b/src/libstore/remote-fs-accessor.hh @@ -19,7 +19,7 @@ class RemoteFSAccessor : public SourceAccessor std::pair, CanonPath> fetch(const CanonPath & path); - friend class BinaryCacheStore; + friend struct BinaryCacheStore; Path makeCacheFile(std::string_view hashPart, const std::string & ext); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 6e8931ca2e4..30d1523b550 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -23,6 +23,24 @@ namespace nix { +#if 0 + const Setting maxConnections{this, 1, "max-connections", + "Maximum number of concurrent connections to the Nix daemon."}; + + const Setting maxConnectionAge{this, + std::numeric_limits::max(), + "max-connection-age", + "Maximum age of a connection before it is closed."}; + + const Setting maxConnections{this, 1, "max-connections", + "Maximum number of concurrent connections to the Nix daemon."}; + + const Setting maxConnectionAge{this, + std::numeric_limits::max(), + "max-connection-age", + "Maximum age of a connection before it is closed."}; +#endif + /* TODO: Separate these store types into different files, give them better names */ RemoteStore::RemoteStore(const Params & params) : RemoteStoreConfig(params) diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index f19aa0fc57b..437c4aee734 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -18,17 +18,31 @@ struct FdSink; struct FdSource; template class Pool; -struct RemoteStoreConfig : virtual StoreConfig +template class F> +struct RemoteStoreConfigT { - using StoreConfig::StoreConfig; + const F maxConnections; - const Setting maxConnections{this, 1, "max-connections", - "Maximum number of concurrent connections to the Nix daemon."}; + const F maxConnectionAge; +}; + +struct RemoteStoreConfig : + virtual Store::Config, + RemoteStoreConfigT +{ + struct Descriptions : + virtual Store::Config::Descriptions, + RemoteStoreConfigT + { + Descriptions(); + }; - const Setting maxConnectionAge{this, - std::numeric_limits::max(), - "max-connection-age", - "Maximum age of a connection before it is closed."}; + static const Descriptions descriptions; + + /** + * The other defaults depend on the choice of `storeDir` and `rootDir` + */ + static RemoteStoreConfigT defaults; }; /** diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index c4bb9d594b0..b67faf38a5e 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -239,11 +239,11 @@ const Store::Config::Descriptions Store::Config::descriptions{}; decltype(Store::Config::defaults) Store::Config::defaults = { - .pathInfoCacheSize = { .value = 65536 }, - .isTrusted = { .value = false }, - .priority = { .value = 0 }, - .wantMassQuery = { .value = false }, - .systemFeatures = { .value = Store::Config::getDefaultSystemFeatures() }, + .pathInfoCacheSize = {65536}, + .isTrusted = {false}, + .priority = {0}, + .wantMassQuery = {false}, + .systemFeatures = {Store::Config::getDefaultSystemFeatures()}, }; diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 09352e601ba..7e9a5fa53f5 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -100,13 +100,9 @@ template class F> struct StoreConfigT { const F pathInfoCacheSize; - const F isTrusted; - F priority; - F wantMassQuery; - F systemFeatures; }; diff --git a/src/libstore/store-dir-config.cc b/src/libstore/store-dir-config.cc index a51962d7fa9..026a6cd9837 100644 --- a/src/libstore/store-dir-config.cc +++ b/src/libstore/store-dir-config.cc @@ -17,7 +17,7 @@ const StoreDirConfigT StoreDirConfig::descriptions = { }; const StoreDirConfigT StoreDirConfig::defaults = { - ._storeDir = {.value = settings.nixStore}, + ._storeDir = {settings.nixStore}, }; StoreDirConfig::StoreDirConfig(const StoreReference::Params & params) diff --git a/src/libstore/uds-remote-store.hh b/src/libstore/uds-remote-store.hh index a8e57166416..8d19ad5f5bc 100644 --- a/src/libstore/uds-remote-store.hh +++ b/src/libstore/uds-remote-store.hh @@ -7,7 +7,9 @@ namespace nix { -struct UDSRemoteStoreConfig : virtual LocalFSStoreConfig, virtual RemoteStoreConfig +struct UDSRemoteStoreConfig : + virtual LocalFSStoreConfig, + virtual RemoteStoreConfig { // TODO(fzakaria): Delete this constructor once moved over to the factory pattern // outlined in https://github.com/NixOS/nix/issues/10766 @@ -34,7 +36,7 @@ struct UDSRemoteStoreConfig : virtual LocalFSStoreConfig, virtual RemoteStoreCon */ Path path; -protected: +private: static constexpr char const * scheme = "unix"; public: @@ -42,24 +44,12 @@ public: { return {scheme}; } }; -class UDSRemoteStore : public virtual UDSRemoteStoreConfig - , public virtual IndirectRootStore - , public virtual RemoteStore +struct UDSRemoteStore : + virtual UDSRemoteStoreConfig, + virtual IndirectRootStore, + virtual RemoteStore { -public: - - /** - * @deprecated This is the old API to construct the store. - */ - UDSRemoteStore(const Params & params); - - /** - * @param authority is the socket path. - */ - UDSRemoteStore( - std::string_view scheme, - std::string_view authority, - const Params & params); + UDSRemoteStore(const UDSRemoteStoreConfig &); std::string getUri() override; diff --git a/src/libutil/config-abstract.hh b/src/libutil/config-abstract.hh index 10c98f0a73f..fcde0696b98 100644 --- a/src/libutil/config-abstract.hh +++ b/src/libutil/config-abstract.hh @@ -12,14 +12,26 @@ struct JustValue { return value; } + operator T &() { return value; } + const T & get() const { return value; } + + bool operator==(auto && v2) const + { + return value == v2; + } + + bool operator!=(auto && v2) const + { + return value != v2; + } }; template