diff --git a/src/libstore/common-ssh-store-config.cc b/src/libstore/common-ssh-store-config.cc index e1448b4b4eb..a2d7e2ebad6 100644 --- a/src/libstore/common-ssh-store-config.cc +++ b/src/libstore/common-ssh-store-config.cc @@ -9,28 +9,29 @@ 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). + .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{}; diff --git a/src/libstore/dummy-store.cc b/src/libstore/dummy-store.cc index c6dd71ba669..968c2d3fbac 100644 --- a/src/libstore/dummy-store.cc +++ b/src/libstore/dummy-store.cc @@ -36,7 +36,7 @@ struct DummyStoreConfig : virtual StoreConfig { return {"dummy"}; } - std::shared_ptr openStore() override; + std::shared_ptr openStore() const override; }; @@ -100,7 +100,7 @@ struct DummyStore : public virtual DummyStoreConfig, public virtual Store { unsupported("getFSAccessor"); } }; -std::shared_ptr DummyStore::Config::openStore() +std::shared_ptr DummyStore::Config::openStore() const { return std::make_shared(*this); } diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index cbbb0fe7a34..ce296668798 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -715,7 +715,7 @@ struct curlFileTransfer : public FileTransfer } #if ENABLE_S3 - std::tuple parseS3Uri(std::string uri) + std::tuple parseS3Uri(std::string uri) { auto [path, params] = splitUriAndParams(uri); diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc index b15ef4e4cba..0a663ec036d 100644 --- a/src/libstore/http-binary-cache-store.cc +++ b/src/libstore/http-binary-cache-store.cc @@ -3,6 +3,7 @@ #include "globals.hh" #include "nar-info-disk-cache.hh" #include "callback.hh" +#include "store-registration.hh" namespace nix { @@ -12,7 +13,7 @@ MakeError(UploadToHTTP, Error); HttpBinaryCacheStoreConfig::HttpBinaryCacheStoreConfig( std::string_view scheme, std::string_view _cacheUri, - const Params & params) + const StoreReference::Params & params) : StoreConfig(params) , BinaryCacheStoreConfig(params) , cacheUri( @@ -35,10 +36,10 @@ std::string HttpBinaryCacheStoreConfig::doc() } -class HttpBinaryCacheStore : public virtual HttpBinaryCacheStoreConfig, public virtual BinaryCacheStore +class HttpBinaryCacheStore : + public virtual HttpBinaryCacheStoreConfig, + public virtual BinaryCacheStore { -private: - struct State { bool enabled = true; @@ -49,15 +50,14 @@ class HttpBinaryCacheStore : public virtual HttpBinaryCacheStoreConfig, public v public: - HttpBinaryCacheStore( - std::string_view scheme, - PathView cacheUri, - const Params & params) - : StoreConfig(params) - , BinaryCacheStoreConfig(params) - , HttpBinaryCacheStoreConfig(scheme, cacheUri, params) - , Store(params) - , BinaryCacheStore(params) + using Config = HttpBinaryCacheStoreConfig; + + HttpBinaryCacheStore(const Config & config) + : Store::Config{config} + , BinaryCacheStore::Config{config} + , HttpBinaryCacheStore::Config{config} + , Store{static_cast(*this)} + , BinaryCacheStore{static_cast(*this)} { diskCache = getNarInfoDiskCache(); } @@ -207,6 +207,10 @@ class HttpBinaryCacheStore : public virtual HttpBinaryCacheStoreConfig, public v } }; -static RegisterStoreImplementation regHttpBinaryCacheStore; +std::shared_ptr HttpBinaryCacheStore::Config::openStore() const { + return std::make_shared(*this); +} + +static RegisterStoreImplementation regHttpBinaryCacheStore; } diff --git a/src/libstore/http-binary-cache-store.hh b/src/libstore/http-binary-cache-store.hh index d2fc43210a2..d15c6e3d0db 100644 --- a/src/libstore/http-binary-cache-store.hh +++ b/src/libstore/http-binary-cache-store.hh @@ -4,9 +4,8 @@ namespace nix { struct HttpBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig { - using BinaryCacheStoreConfig::BinaryCacheStoreConfig; - - HttpBinaryCacheStoreConfig(std::string_view scheme, std::string_view _cacheUri, const Params & params); + HttpBinaryCacheStoreConfig( + std::string_view scheme, std::string_view cacheUri, const StoreReference::Params & params); Path cacheUri; @@ -25,6 +24,8 @@ struct HttpBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig } std::string doc() override; + + std::shared_ptr openStore() const override; }; } diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc index dcc6affe4a1..8fb163e3064 100644 --- a/src/libstore/local-binary-cache-store.cc +++ b/src/libstore/local-binary-cache-store.cc @@ -2,6 +2,7 @@ #include "globals.hh" #include "nar-info-disk-cache.hh" #include "signals.hh" +#include "store-registration.hh" #include @@ -10,7 +11,7 @@ namespace nix { LocalBinaryCacheStoreConfig::LocalBinaryCacheStoreConfig( std::string_view scheme, PathView binaryCacheDir, - const Params & params) + const StoreReference::Params & params) : StoreConfig(params) , BinaryCacheStoreConfig(params) , binaryCacheDir(binaryCacheDir) @@ -26,21 +27,18 @@ std::string LocalBinaryCacheStoreConfig::doc() } -struct LocalBinaryCacheStore : virtual LocalBinaryCacheStoreConfig, virtual BinaryCacheStore +struct LocalBinaryCacheStore : + virtual LocalBinaryCacheStoreConfig, + virtual BinaryCacheStore { - /** - * @param binaryCacheDir `file://` is a short-hand for `file:///` - * for now. - */ - LocalBinaryCacheStore( - std::string_view scheme, - PathView binaryCacheDir, - const Params & params) - : StoreConfig(params) - , BinaryCacheStoreConfig(params) - , LocalBinaryCacheStoreConfig(scheme, binaryCacheDir, params) - , Store(params) - , BinaryCacheStore(params) + using Config = LocalBinaryCacheStoreConfig; + + LocalBinaryCacheStore(const Config & config) + : Store::Config{config} + , BinaryCacheStore::Config{config} + , LocalBinaryCacheStore::Config{config} + , Store{static_cast(*this)} + , BinaryCacheStore{static_cast(*this)} { } @@ -127,6 +125,6 @@ std::set LocalBinaryCacheStoreConfig::uriSchemes() return {"file"}; } -static RegisterStoreImplementation regLocalBinaryCacheStore; +static RegisterStoreImplementation regLocalBinaryCacheStore; } diff --git a/src/libstore/local-binary-cache-store.hh b/src/libstore/local-binary-cache-store.hh index 997e8ecbb51..01f7969eb61 100644 --- a/src/libstore/local-binary-cache-store.hh +++ b/src/libstore/local-binary-cache-store.hh @@ -4,9 +4,12 @@ namespace nix { struct LocalBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig { - using BinaryCacheStoreConfig::BinaryCacheStoreConfig; - - LocalBinaryCacheStoreConfig(std::string_view scheme, PathView binaryCacheDir, const Params & params); + /** + * @param binaryCacheDir `file://` is a short-hand for `file:///` + * for now. + */ + LocalBinaryCacheStoreConfig( + std::string_view scheme, PathView binaryCacheDir, const StoreReference::Params & params); Path binaryCacheDir; @@ -18,6 +21,8 @@ struct LocalBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig static std::set uriSchemes(); std::string doc() override; + + std::shared_ptr openStore() const override; }; } diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index aff70589d18..d3677fdeb39 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -113,7 +113,7 @@ std::string LocalStoreConfig::doc() ; } -std::shared_ptr LocalStore::Config::openStore() +std::shared_ptr LocalStore::Config::openStore() const { return std::make_shared(*this); } diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 06e402f80f9..45cb04b7159 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -56,9 +56,6 @@ struct LocalStoreConfig : static const Descriptions descriptions; - /** - * The other defaults depend on the choice of `storeDir` and `rootDir` - */ static LocalStoreConfigT defaults; LocalStoreConfig(const StoreReference::Params &); @@ -75,7 +72,7 @@ struct LocalStoreConfig : std::string doc() override; - std::shared_ptr openStore() override; + std::shared_ptr openStore() const override; }; class LocalStore : diff --git a/src/libstore/machines.cc b/src/libstore/machines.cc index 256cf918892..9e4145e0ac5 100644 --- a/src/libstore/machines.cc +++ b/src/libstore/machines.cc @@ -1,6 +1,6 @@ #include "machines.hh" #include "globals.hh" -#include "store-api.hh" +#include "store-open.hh" #include diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc index bcc02206bc9..31762f34d2c 100644 --- a/src/libstore/misc.cc +++ b/src/libstore/misc.cc @@ -3,7 +3,7 @@ #include "derivations.hh" #include "parsed-derivations.hh" #include "globals.hh" -#include "store-api.hh" +#include "store-open.hh" #include "thread-pool.hh" #include "realisation.hh" #include "topo-sort.hh" diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc index 1a0ec11112e..abd2727194b 100644 --- a/src/libstore/s3-binary-cache-store.cc +++ b/src/libstore/s3-binary-cache-store.cc @@ -1,7 +1,5 @@ #if ENABLE_S3 -#include - #include "s3.hh" #include "s3-binary-cache-store.hh" #include "nar-info.hh" @@ -187,6 +185,75 @@ S3Helper::FileTransferResult S3Helper::getObject( return res; } + const Setting profile{ + this, + "", + "profile", + R"( + The name of the AWS configuration profile to use. By default + Nix will use the `default` profile. + )"}; + + const Setting region{ + this, + Aws::Region::US_EAST_1, + "region", + R"( + The region of the S3 bucket. If your bucket is not in + `us–east-1`, you should always explicitly specify the region + parameter. + )"}; + + const Setting scheme{ + this, + "", + "scheme", + R"( + The scheme used for S3 requests, `https` (default) or `http`. This + option allows you to disable HTTPS for binary caches which don't + support it. + + > **Note** + > + > HTTPS should be used if the cache might contain sensitive + > information. + )"}; + + const Setting endpoint{ + this, + "", + "endpoint", + R"( + The URL of the endpoint of an S3-compatible service such as MinIO. + Do not specify this setting if you're using Amazon S3. + + > **Note** + > + > This endpoint must support HTTPS and will use path-based + > addressing instead of virtual host based addressing. + )"}; + + const Setting narinfoCompression{ + this, "", "narinfo-compression", "Compression method for `.narinfo` files."}; + + const Setting lsCompression{this, "", "ls-compression", "Compression method for `.ls` files."}; + + const Setting logCompression{ + this, + "", + "log-compression", + R"( + Compression method for `log/*` files. It is recommended to + use a compression method supported by most web browsers + (e.g. `brotli`). + )"}; + + const Setting multipartUpload{this, false, "multipart-upload", "Whether to use multi-part uploads."}; + + const Setting bufferSize{ + this, 5 * 1024 * 1024, "buffer-size", "Size (in bytes) of each part in multi-part uploads."}; + + S3BinaryCacheStore::S3BinaryCacheStore(const Params & params) : BinaryCacheStoreConfig(params) , BinaryCacheStore(params) @@ -201,11 +268,6 @@ S3BinaryCacheStoreConfig::S3BinaryCacheStoreConfig( , BinaryCacheStoreConfig(params) , bucketName(bucketName) { - // Don't want to use use AWS SDK in header, so we check the default - // here. TODO do this better after we overhaul the store settings - // system. - assert(std::string{defaultRegion} == std::string{Aws::Region::US_EAST_1}); - if (bucketName.empty()) throw UsageError("`%s` store requires a bucket name in its Store URI", uriScheme); } diff --git a/src/libstore/s3-binary-cache-store.hh b/src/libstore/s3-binary-cache-store.hh index 7d303a115f4..c28e9320378 100644 --- a/src/libstore/s3-binary-cache-store.hh +++ b/src/libstore/s3-binary-cache-store.hh @@ -7,87 +7,40 @@ namespace nix { -struct S3BinaryCacheStoreConfig : virtual BinaryCacheStoreConfig +template class F> +struct S3BinaryCacheStoreConfigT { - std::string bucketName; - - using BinaryCacheStoreConfig::BinaryCacheStoreConfig; - - S3BinaryCacheStoreConfig(std::string_view uriScheme, std::string_view bucketName, const Params & params); + const F profile; + const F region; + const F scheme; + const F endpoint; + const F narinfoCompression; + const F lsCompression; + const F logCompression; + const F multipartUpload; + const F bufferSize; +}; - const Setting profile{ - this, - "", - "profile", - R"( - The name of the AWS configuration profile to use. By default - Nix will use the `default` profile. - )"}; +struct S3BinaryCacheStoreConfig : + virtual BinaryCacheStoreConfig, + S3BinaryCacheStoreConfigT +{ + struct Descriptions : + virtual Store::Config::Descriptions, + virtual BinaryCacheStore::Config::Descriptions, + S3BinaryCacheStoreConfigT + { + Descriptions(); + }; -protected: + static const Descriptions descriptions; - constexpr static const char * defaultRegion = "us-east-1"; + static S3BinaryCacheStoreConfigT defaults; -public: + S3BinaryCacheStoreConfig( + std::string_view uriScheme, std::string_view bucketName, const StoreReference::Params & params); - const Setting region{ - this, - defaultRegion, - "region", - R"( - The region of the S3 bucket. If your bucket is not in - `us–east-1`, you should always explicitly specify the region - parameter. - )"}; - - const Setting scheme{ - this, - "", - "scheme", - R"( - The scheme used for S3 requests, `https` (default) or `http`. This - option allows you to disable HTTPS for binary caches which don't - support it. - - > **Note** - > - > HTTPS should be used if the cache might contain sensitive - > information. - )"}; - - const Setting endpoint{ - this, - "", - "endpoint", - R"( - The URL of the endpoint of an S3-compatible service such as MinIO. - Do not specify this setting if you're using Amazon S3. - - > **Note** - > - > This endpoint must support HTTPS and will use path-based - > addressing instead of virtual host based addressing. - )"}; - - const Setting narinfoCompression{ - this, "", "narinfo-compression", "Compression method for `.narinfo` files."}; - - const Setting lsCompression{this, "", "ls-compression", "Compression method for `.ls` files."}; - - const Setting logCompression{ - this, - "", - "log-compression", - R"( - Compression method for `log/*` files. It is recommended to - use a compression method supported by most web browsers - (e.g. `brotli`). - )"}; - - const Setting multipartUpload{this, false, "multipart-upload", "Whether to use multi-part uploads."}; - - const Setting bufferSize{ - this, 5 * 1024 * 1024, "buffer-size", "Size (in bytes) of each part in multi-part uploads."}; + std::string bucketName; const std::string name() override { @@ -102,11 +55,13 @@ public: std::string doc() override; }; -class S3BinaryCacheStore : public virtual BinaryCacheStore +struct S3BinaryCacheStore : virtual BinaryCacheStore { + using Config = S3BinaryCacheStoreConfig; + protected: - S3BinaryCacheStore(const Params & params); + S3BinaryCacheStore(const Config &); public: diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 7e9a5fa53f5..6571fd37c10 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -154,7 +154,7 @@ struct StoreConfig : * Open a store of the type corresponding to this configuration * type. */ - virtual std::shared_ptr openStore() = 0; + virtual std::shared_ptr openStore() const = 0; }; class Store : public std::enable_shared_from_this, public virtual StoreConfig