From 1add77677f25af67ff7c3709fb8ebd806b25ffbe Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Wed, 11 Feb 2026 09:05:20 -0500 Subject: [PATCH 1/2] store-config: remove unnecessary `const` from `Setting<>` fields Stores hold their config as `ref` or `const Config &`, so `Setting<>` fields are already immutable after store construction. The field-level `const` is redundant and prevents pre-construction mutation which is sometimes useful. This commit updates these settings by dropping the `const` qualifier, as it's not needed. --- .../include/nix/store/binary-cache-store.hh | 16 ++++++++-------- .../include/nix/store/common-ssh-store-config.hh | 8 ++++---- .../include/nix/store/http-binary-cache-store.hh | 10 +++++----- .../include/nix/store/legacy-ssh-store.hh | 6 +++--- .../include/nix/store/local-overlay-store.hh | 6 +++--- src/libstore/include/nix/store/remote-store.hh | 4 ++-- .../include/nix/store/s3-binary-cache-store.hh | 16 ++++++++-------- src/libstore/include/nix/store/ssh-store.hh | 2 +- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/libstore/include/nix/store/binary-cache-store.hh b/src/libstore/include/nix/store/binary-cache-store.hh index 6a1fad9649e..a41bf515dc6 100644 --- a/src/libstore/include/nix/store/binary-cache-store.hh +++ b/src/libstore/include/nix/store/binary-cache-store.hh @@ -18,7 +18,7 @@ struct BinaryCacheStoreConfig : virtual StoreConfig { using StoreConfig::StoreConfig; - const Setting compression{ + Setting compression{ this, CompressionAlgo::xz, "compression", @@ -27,10 +27,10 @@ struct BinaryCacheStoreConfig : virtual StoreConfig To use a particular compression method Nix has to be built with a version of libarchive that natively supports that compression algorithm. )"}; - const Setting writeNARListing{ + Setting writeNARListing{ this, false, "write-nar-listing", "Whether to write a JSON file that lists the files in each NAR."}; - const Setting writeDebugInfo{ + Setting writeDebugInfo{ this, false, "index-debug-info", @@ -39,24 +39,24 @@ struct BinaryCacheStoreConfig : virtual StoreConfig fetch debug info on demand )"}; - const Setting secretKeyFile{this, "", "secret-key", "Path to the secret key used to sign the binary cache."}; + Setting secretKeyFile{this, "", "secret-key", "Path to the secret key used to sign the binary cache."}; - const Setting secretKeyFiles{ + Setting secretKeyFiles{ this, "", "secret-keys", "List of comma-separated paths to the secret keys used to sign the binary cache."}; - const Setting> localNarCache{ + Setting> localNarCache{ this, std::nullopt, "local-nar-cache", "Path to a local cache of NARs fetched from this binary cache, used by commands such as `nix store cat`."}; - const Setting parallelCompression{ + Setting parallelCompression{ this, false, "parallel-compression", "Enable multi-threaded compression of NARs. This is currently only available for `xz` and `zstd`."}; - const Setting compressionLevel{ + Setting compressionLevel{ this, -1, "compression-level", diff --git a/src/libstore/include/nix/store/common-ssh-store-config.hh b/src/libstore/include/nix/store/common-ssh-store-config.hh index bbd81835d4f..0f2cea5e5fb 100644 --- a/src/libstore/include/nix/store/common-ssh-store-config.hh +++ b/src/libstore/include/nix/store/common-ssh-store-config.hh @@ -15,15 +15,15 @@ struct CommonSSHStoreConfig : virtual StoreConfig CommonSSHStoreConfig(std::string_view scheme, const ParsedURL::Authority & authority, const Params & params); CommonSSHStoreConfig(std::string_view scheme, std::string_view authority, const Params & params); - const Setting sshKey{ + Setting sshKey{ this, "", "ssh-key", "Path to the SSH private key used to authenticate to the remote machine."}; - const Setting sshPublicHostKey{ + Setting sshPublicHostKey{ this, "", "base64-ssh-public-host-key", "The public host key of the remote machine."}; - const Setting compress{this, false, "compress", "Whether to enable SSH compression."}; + Setting compress{this, false, "compress", "Whether to enable SSH compression."}; - const Setting remoteStore{ + Setting remoteStore{ this, "", "remote-store", diff --git a/src/libstore/include/nix/store/http-binary-cache-store.hh b/src/libstore/include/nix/store/http-binary-cache-store.hh index 9047233acf4..e32362efb59 100644 --- a/src/libstore/include/nix/store/http-binary-cache-store.hh +++ b/src/libstore/include/nix/store/http-binary-cache-store.hh @@ -21,13 +21,13 @@ struct HttpBinaryCacheStoreConfig : std::enable_shared_from_this> narinfoCompression{ + Setting> narinfoCompression{ this, std::nullopt, "narinfo-compression", "Compression method for `.narinfo` files."}; - const Setting> lsCompression{ + Setting> lsCompression{ this, std::nullopt, "ls-compression", "Compression method for `.ls` files."}; - const Setting> logCompression{ + Setting> logCompression{ this, std::nullopt, "log-compression", @@ -37,10 +37,10 @@ struct HttpBinaryCacheStoreConfig : std::enable_shared_from_this> tlsCert{ + Setting> tlsCert{ this, std::nullopt, "tls-certificate", "Path to an optional TLS client certificate in PEM format."}; - const Setting> tlsKey{ + Setting> tlsKey{ this, std::nullopt, "tls-private-key", "Path to an optional TLS client certificate private key in PEM format."}; static const std::string name() diff --git a/src/libstore/include/nix/store/legacy-ssh-store.hh b/src/libstore/include/nix/store/legacy-ssh-store.hh index 8b18176b10e..d07b917357f 100644 --- a/src/libstore/include/nix/store/legacy-ssh-store.hh +++ b/src/libstore/include/nix/store/legacy-ssh-store.hh @@ -20,15 +20,15 @@ struct LegacySSHStoreConfig : std::enable_shared_from_this // 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"}; + Setting logFD{this, INVALID_DESCRIPTOR, "log-fd", "file descriptor to which SSH's stderr is connected"}; #else Descriptor logFD = INVALID_DESCRIPTOR; #endif - const Setting remoteProgram{ + 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."}; + Setting maxConnections{this, 1, "max-connections", "Maximum number of concurrent SSH connections."}; /** * Hack for hydra diff --git a/src/libstore/include/nix/store/local-overlay-store.hh b/src/libstore/include/nix/store/local-overlay-store.hh index c0efdece845..181c8cc90c6 100644 --- a/src/libstore/include/nix/store/local-overlay-store.hh +++ b/src/libstore/include/nix/store/local-overlay-store.hh @@ -19,7 +19,7 @@ struct LocalOverlayStoreConfig : virtual LocalStoreConfig { } - const Setting lowerStoreUri{ + Setting lowerStoreUri{ (StoreConfig *) this, "", "lower-store", @@ -31,7 +31,7 @@ struct LocalOverlayStoreConfig : virtual LocalStoreConfig Must be used as OverlayFS lower layer for this store's store dir. )"}; - const PathSetting upperLayer{ + PathSetting upperLayer{ (StoreConfig *) this, "", "upper-layer", @@ -53,7 +53,7 @@ struct LocalOverlayStoreConfig : virtual LocalStoreConfig default, but can be disabled if needed. )"}; - const PathSetting remountHook{ + PathSetting remountHook{ (StoreConfig *) this, "", "remount-hook", diff --git a/src/libstore/include/nix/store/remote-store.hh b/src/libstore/include/nix/store/remote-store.hh index 73de1795def..0df2b5bab66 100644 --- a/src/libstore/include/nix/store/remote-store.hh +++ b/src/libstore/include/nix/store/remote-store.hh @@ -25,10 +25,10 @@ struct RemoteStoreConfig : virtual StoreConfig { using StoreConfig::StoreConfig; - const Setting maxConnections{ + Setting maxConnections{ this, 1, "max-connections", "Maximum number of concurrent connections to the Nix daemon."}; - const Setting maxConnectionAge{ + Setting maxConnectionAge{ this, std::numeric_limits::max(), "max-connection-age", diff --git a/src/libstore/include/nix/store/s3-binary-cache-store.hh b/src/libstore/include/nix/store/s3-binary-cache-store.hh index 5896293f1c4..73fedeecf80 100644 --- a/src/libstore/include/nix/store/s3-binary-cache-store.hh +++ b/src/libstore/include/nix/store/s3-binary-cache-store.hh @@ -12,7 +12,7 @@ struct S3BinaryCacheStoreConfig : HttpBinaryCacheStoreConfig S3BinaryCacheStoreConfig(std::string_view uriScheme, std::string_view bucketName, const Params & params); - const Setting profile{ + Setting profile{ this, "default", "profile", @@ -21,7 +21,7 @@ struct S3BinaryCacheStoreConfig : HttpBinaryCacheStoreConfig Nix uses the `default` profile. )"}; - const Setting region{ + Setting region{ this, "us-east-1", "region", @@ -31,7 +31,7 @@ struct S3BinaryCacheStoreConfig : HttpBinaryCacheStoreConfig parameter. )"}; - const Setting scheme{ + Setting scheme{ this, "https", "scheme", @@ -46,7 +46,7 @@ struct S3BinaryCacheStoreConfig : HttpBinaryCacheStoreConfig > information. )"}; - const Setting endpoint{ + Setting endpoint{ this, "", "endpoint", @@ -61,7 +61,7 @@ struct S3BinaryCacheStoreConfig : HttpBinaryCacheStoreConfig > addressing instead of virtual host based addressing. )"}; - const Setting multipartUpload{ + Setting multipartUpload{ this, false, "multipart-upload", @@ -72,7 +72,7 @@ struct S3BinaryCacheStoreConfig : HttpBinaryCacheStoreConfig can improve performance and reliability for large uploads. )"}; - const Setting multipartChunkSize{ + Setting multipartChunkSize{ this, 5 * 1024 * 1024, "multipart-chunk-size", @@ -83,7 +83,7 @@ struct S3BinaryCacheStoreConfig : HttpBinaryCacheStoreConfig )", {"buffer-size"}}; - const Setting multipartThreshold{ + Setting multipartThreshold{ this, 100 * 1024 * 1024, "multipart-threshold", @@ -93,7 +93,7 @@ struct S3BinaryCacheStoreConfig : HttpBinaryCacheStoreConfig Default is 100 MiB. Only takes effect when multipart-upload is enabled. )"}; - const Setting> storageClass{ + Setting> storageClass{ this, std::nullopt, "storage-class", diff --git a/src/libstore/include/nix/store/ssh-store.hh b/src/libstore/include/nix/store/ssh-store.hh index 9584a1a862c..2c27bdb13ba 100644 --- a/src/libstore/include/nix/store/ssh-store.hh +++ b/src/libstore/include/nix/store/ssh-store.hh @@ -17,7 +17,7 @@ struct SSHStoreConfig : std::enable_shared_from_this, SSHStoreConfig(std::string_view scheme, std::string_view authority, const Params & params); - const Setting remoteProgram{ + Setting remoteProgram{ this, {"nix-daemon"}, "remote-program", "Path to the `nix-daemon` executable on the remote machine."}; static const std::string name() From 8020a847ab897428f4c2db588fccd8b46334315d Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Tue, 10 Feb 2026 22:37:26 -0500 Subject: [PATCH 2/2] nix-copy-closure: create `LegacySSHStoreConfig` directly Instead of constructing a `StoreReference` and letting `openStore()` resolve it, this commit creates the store config directly and calls `openStore()` on it. This avoids the indirection through the store registry. --- src/nix/nix-copy-closure/nix-copy-closure.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/nix/nix-copy-closure/nix-copy-closure.cc b/src/nix/nix-copy-closure/nix-copy-closure.cc index 7b56840cd53..8141a7f62ac 100644 --- a/src/nix/nix-copy-closure/nix-copy-closure.cc +++ b/src/nix/nix-copy-closure/nix-copy-closure.cc @@ -1,5 +1,6 @@ #include "nix/main/shared.hh" #include "nix/store/realisation.hh" +#include "nix/store/legacy-ssh-store.hh" #include "nix/store/store-open.hh" #include "nix/cmd/legacy.hh" #include "man-pages.hh" @@ -48,13 +49,10 @@ static int main_nix_copy_closure(int argc, char ** argv) if (sshHost.empty()) throw UsageError("no host name specified"); - StoreReference remoteRef{ - .variant = StoreReference::Specified{.scheme = "ssh", .authority = sshHost}, - }; - if (gzip) - remoteRef.params["compress"] = "true"; - auto to = toMode ? openStore(StoreReference{remoteRef}) : openStore(); - auto from = toMode ? openStore() : openStore(StoreReference{remoteRef}); + auto remoteConfig = make_ref("ssh", sshHost, LegacySSHStoreConfig::Params{}); + remoteConfig->compress |= gzip; + auto to = toMode ? remoteConfig->openStore() : openStore(); + auto from = toMode ? openStore() : remoteConfig->openStore(); RealisedPath::Set storePaths2; for (auto & path : storePaths)