From 8cf114864a7e805103fdc131aa53ccc02ae1c04e Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 6 Jan 2023 17:51:16 -0500 Subject: [PATCH] Try to make Config a bit easier to use - Use references, not pointers, to indicate Config must be initializd. - Wrap cast to avoid the GCC bug in a helper function, so if we need to move it, it's not so bad. --- src/libexpr/eval.cc | 2 +- src/libexpr/eval.hh | 20 ++-- src/libfetchers/fetch-settings.cc | 2 +- src/libfetchers/fetch-settings.hh | 14 +-- src/libstore/binary-cache-store.hh | 14 +-- src/libstore/filetransfer.cc | 2 +- src/libstore/filetransfer.hh | 12 +-- src/libstore/globals.cc | 2 +- src/libstore/globals.hh | 146 +++++++++++++------------- src/libstore/legacy-ssh-store.cc | 14 +-- src/libstore/local-fs-store.hh | 11 +- src/libstore/local-store.hh | 2 +- src/libstore/remote-store.hh | 4 +- src/libstore/s3-binary-cache-store.cc | 18 ++-- src/libstore/ssh-store.cc | 10 +- src/libstore/store-api.hh | 24 +++-- src/libutil/archive.cc | 6 +- src/libutil/config.cc | 4 +- src/libutil/config.hh | 10 +- src/libutil/logging.cc | 2 +- src/libutil/logging.hh | 2 +- src/libutil/tests/config.cc | 26 ++--- src/nix/develop.cc | 8 +- tests/plugins/plugintest.cc | 4 +- 24 files changed, 183 insertions(+), 176 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 72c2b104f19b..3663c98a73d0 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -2522,7 +2522,7 @@ std::string EvalSettings::resolvePseudoUrl(std::string_view url) EvalSettings evalSettings; -static GlobalConfig::Register rEvalSettings(&evalSettings); +static GlobalConfig::Register rEvalSettings { evalSettings }; } diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 9b3d160eabef..fc2cbe006d7a 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -577,15 +577,15 @@ struct EvalSettings : Config static std::string resolvePseudoUrl(std::string_view url); - Setting enableNativeCode{this, false, "allow-unsafe-native-code-during-evaluation", + Setting enableNativeCode{*this, false, "allow-unsafe-native-code-during-evaluation", "Whether builtin functions that allow executing native code should be enabled."}; Setting nixPath{ - this, getDefaultNixPath(), "nix-path", + *this, getDefaultNixPath(), "nix-path", "List of directories to be searched for `<...>` file references."}; Setting restrictEval{ - this, false, "restrict-eval", + *this, false, "restrict-eval", R"( If set to `true`, the Nix evaluator will not allow access to any files outside of the Nix search path (as set via the `NIX_PATH` @@ -593,11 +593,11 @@ struct EvalSettings : Config `allowed-uri`. The default is `false`. )"}; - Setting pureEval{this, false, "pure-eval", + Setting pureEval{*this, false, "pure-eval", "Whether to restrict file system and network access to files specified by cryptographic hash."}; Setting enableImportFromDerivation{ - this, true, "allow-import-from-derivation", + *this, true, "allow-import-from-derivation", R"( By default, Nix allows you to `import` from a derivation, allowing building at evaluation time. With this option set to false, Nix will @@ -606,7 +606,7 @@ struct EvalSettings : Config builds to take place. )"}; - Setting allowedUris{this, {}, "allowed-uris", + Setting allowedUris{*this, {}, "allowed-uris", R"( A list of URI prefixes to which access is allowed in restricted evaluation mode. For example, when set to @@ -614,7 +614,7 @@ struct EvalSettings : Config allowed to access `https://github.com/NixOS/patchelf.git`. )"}; - Setting traceFunctionCalls{this, false, "trace-function-calls", + Setting traceFunctionCalls{*this, false, "trace-function-calls", R"( If set to `true`, the Nix evaluator will trace every function call. Nix will print a log message at the "vomit" level for every function @@ -632,16 +632,16 @@ struct EvalSettings : Config `flamegraph.pl`. )"}; - Setting useEvalCache{this, true, "eval-cache", + Setting useEvalCache{*this, true, "eval-cache", "Whether to use the flake evaluation cache."}; - Setting ignoreExceptionsDuringTry{this, false, "ignore-try", + Setting ignoreExceptionsDuringTry{*this, false, "ignore-try", R"( If set to true, ignore exceptions inside 'tryEval' calls when evaluating nix expressions in debug mode (using the --debugger flag). By default the debugger will pause on all exceptions. )"}; - Setting traceVerbose{this, false, "trace-verbose", + Setting traceVerbose{*this, false, "trace-verbose", "Whether `builtins.traceVerbose` should trace its first argument when evaluated."}; }; diff --git a/src/libfetchers/fetch-settings.cc b/src/libfetchers/fetch-settings.cc index e7d5244dc2cd..52800fb39420 100644 --- a/src/libfetchers/fetch-settings.cc +++ b/src/libfetchers/fetch-settings.cc @@ -8,6 +8,6 @@ FetchSettings::FetchSettings() FetchSettings fetchSettings; -static GlobalConfig::Register rFetchSettings(&fetchSettings); +static GlobalConfig::Register rFetchSettings { fetchSettings }; } diff --git a/src/libfetchers/fetch-settings.hh b/src/libfetchers/fetch-settings.hh index f33cbdcfc989..b2f8287add95 100644 --- a/src/libfetchers/fetch-settings.hh +++ b/src/libfetchers/fetch-settings.hh @@ -15,7 +15,7 @@ struct FetchSettings : public Config { FetchSettings(); - Setting accessTokens{this, {}, "access-tokens", + Setting accessTokens{*this, {}, "access-tokens", R"( Access tokens used to access protected GitHub, GitLab, or other locations requiring token-based authentication. @@ -64,13 +64,13 @@ struct FetchSettings : public Config value. )"}; - Setting allowDirty{this, true, "allow-dirty", + Setting allowDirty{*this, true, "allow-dirty", "Whether to allow dirty Git/Mercurial trees."}; - Setting warnDirty{this, true, "warn-dirty", + Setting warnDirty{*this, true, "warn-dirty", "Whether to warn about dirty Git/Mercurial trees."}; - Setting flakeRegistry{this, "https://channels.nixos.org/flake-registry.json", "flake-registry", + Setting flakeRegistry{*this, "https://channels.nixos.org/flake-registry.json", "flake-registry", R"( Path or URI of the global flake registry. @@ -78,14 +78,14 @@ struct FetchSettings : public Config )"}; - Setting useRegistries{this, true, "use-registries", + Setting useRegistries{*this, true, "use-registries", "Whether to use flake registries to resolve flake references."}; - Setting acceptFlakeConfig{this, false, "accept-flake-config", + Setting acceptFlakeConfig{*this, false, "accept-flake-config", "Whether to accept nix configuration from a flake without prompting."}; Setting commitLockFileSummary{ - this, "", "commit-lockfile-summary", + *this, "", "commit-lockfile-summary", R"( The commit summary to use when committing changed flake lock files. If empty, the summary is generated based on the action performed. diff --git a/src/libstore/binary-cache-store.hh b/src/libstore/binary-cache-store.hh index 8c82e23878d2..ce2e5361f512 100644 --- a/src/libstore/binary-cache-store.hh +++ b/src/libstore/binary-cache-store.hh @@ -16,14 +16,14 @@ struct BinaryCacheStoreConfig : virtual StoreConfig { using StoreConfig::StoreConfig; - const Setting compression{(StoreConfig*) this, "xz", "compression", "NAR compression method ('xz', 'bzip2', 'gzip', 'zstd', or 'none')"}; - const Setting writeNARListing{(StoreConfig*) this, false, "write-nar-listing", "whether to write a JSON file listing the files in each NAR"}; - const Setting writeDebugInfo{(StoreConfig*) this, false, "index-debug-info", "whether to index DWARF debug info files by build ID"}; - const Setting secretKeyFile{(StoreConfig*) this, "", "secret-key", "path to secret key used to sign the binary cache"}; - const Setting localNarCache{(StoreConfig*) this, "", "local-nar-cache", "path to a local cache of NARs"}; - const Setting parallelCompression{(StoreConfig*) this, false, "parallel-compression", + const Setting compression{this->dodgeGcc80431(), "xz", "compression", "NAR compression method ('xz', 'bzip2', 'gzip', 'zstd', or 'none')"}; + const Setting writeNARListing{this->dodgeGcc80431(), false, "write-nar-listing", "whether to write a JSON file listing the files in each NAR"}; + const Setting writeDebugInfo{this->dodgeGcc80431(), false, "index-debug-info", "whether to index DWARF debug info files by build ID"}; + const Setting secretKeyFile{this->dodgeGcc80431(), "", "secret-key", "path to secret key used to sign the binary cache"}; + const Setting localNarCache{this->dodgeGcc80431(), "", "local-nar-cache", "path to a local cache of NARs"}; + const Setting parallelCompression{this->dodgeGcc80431(), false, "parallel-compression", "enable multi-threading compression for NARs, available for xz and zstd only currently"}; - const Setting compressionLevel{(StoreConfig*) this, -1, "compression-level", + const Setting compressionLevel{this->dodgeGcc80431(), -1, "compression-level", "specify 'preset level' of compression to be used with NARs: " "meaning and accepted range of values depends on compression method selected, " "other than -1 which we reserve to indicate Nix defaults should be used"}; diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 756bd44230cc..00e77403a774 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -31,7 +31,7 @@ namespace nix { FileTransferSettings fileTransferSettings; -static GlobalConfig::Register rFileTransferSettings(&fileTransferSettings); +static GlobalConfig::Register rFileTransferSettings {fileTransferSettings }; struct curlFileTransfer : public FileTransfer { diff --git a/src/libstore/filetransfer.hh b/src/libstore/filetransfer.hh index 07d58f53aa70..0b3e2714396f 100644 --- a/src/libstore/filetransfer.hh +++ b/src/libstore/filetransfer.hh @@ -11,14 +11,14 @@ namespace nix { struct FileTransferSettings : Config { - Setting enableHttp2{this, true, "http2", + Setting enableHttp2{*this, true, "http2", "Whether to enable HTTP/2 support."}; - Setting userAgentSuffix{this, "", "user-agent-suffix", + Setting userAgentSuffix{*this, "", "user-agent-suffix", "String appended to the user agent in HTTP requests."}; Setting httpConnections{ - this, 25, "http-connections", + *this, 25, "http-connections", R"( The maximum number of parallel TCP connections used to fetch files from binary caches and by other downloads. It defaults @@ -27,7 +27,7 @@ struct FileTransferSettings : Config {"binary-caches-parallel-connections"}}; Setting connectTimeout{ - this, 0, "connect-timeout", + *this, 0, "connect-timeout", R"( The timeout (in seconds) for establishing connections in the binary cache substituter. It corresponds to `curl`’s @@ -35,14 +35,14 @@ struct FileTransferSettings : Config )"}; Setting stalledDownloadTimeout{ - this, 300, "stalled-download-timeout", + *this, 300, "stalled-download-timeout", R"( The timeout (in seconds) for receiving data from servers during download. Nix cancels idle downloads after this timeout's duration. )"}; - Setting tries{this, 5, "download-attempts", + Setting tries{*this, 5, "download-attempts", "How often Nix will attempt to download a file before giving up."}; }; diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index 130c5b670b1a..eae2352e9bc9 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -26,7 +26,7 @@ namespace nix { Settings settings; -static GlobalConfig::Register rSettings(&settings); +static GlobalConfig::Register rSettings { settings }; Settings::Settings() : nixPrefix(NIX_PREFIX) diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index f026c880881c..cf9e1ff2f554 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -16,14 +16,14 @@ typedef enum { smEnabled, smRelaxed, smDisabled } SandboxMode; struct MaxBuildJobsSetting : public BaseSetting { - MaxBuildJobsSetting(Config * options, + MaxBuildJobsSetting(Config & options, unsigned int def, const std::string & name, const std::string & description, const std::set & aliases = {}) : BaseSetting(def, true, name, description, aliases) { - options->addSetting(this); + options.addSetting(this); } void set(const std::string & str, bool append = false) override; @@ -33,14 +33,14 @@ struct PluginFilesSetting : public BaseSetting { bool pluginsLoaded = false; - PluginFilesSetting(Config * options, + PluginFilesSetting(Config & options, const Paths & def, const std::string & name, const std::string & description, const std::set & aliases = {}) : BaseSetting(def, true, name, description, aliases) { - options->addSetting(this); + options.addSetting(this); } void set(const std::string & str, bool append = false) override; @@ -96,17 +96,17 @@ public: /* File name of the socket the daemon listens to. */ Path nixDaemonSocketFile; - Setting storeUri{this, getEnv("NIX_REMOTE").value_or("auto"), "store", + Setting storeUri{*this, getEnv("NIX_REMOTE").value_or("auto"), "store", "The default Nix store to use."}; - Setting keepFailed{this, false, "keep-failed", + Setting keepFailed{*this, false, "keep-failed", "Whether to keep temporary directories of failed builds."}; - Setting keepGoing{this, false, "keep-going", + Setting keepGoing{*this, false, "keep-going", "Whether to keep building derivations when another build fails."}; Setting tryFallback{ - this, false, "fallback", + *this, false, "fallback", R"( If set to `true`, Nix will fall back to building from source if a binary substitute fails. This is equivalent to the `--fallback` @@ -117,12 +117,12 @@ public: /* Whether to show build log output in real time. */ bool verboseBuild = true; - Setting logLines{this, 10, "log-lines", + Setting logLines{*this, 10, "log-lines", "The number of lines of the tail of " "the log to show if a build fails."}; MaxBuildJobsSetting maxBuildJobs{ - this, 1, "max-jobs", + *this, 1, "max-jobs", R"( This option defines the maximum number of jobs that Nix will try to build in parallel. The default is `1`. The special value `auto` @@ -135,7 +135,7 @@ public: {"build-max-jobs"}}; Setting buildCores{ - this, + *this, getDefaultCores(), "cores", R"( @@ -155,7 +155,7 @@ public: bool readOnlyMode = false; Setting thisSystem{ - this, SYSTEM, "system", + *this, SYSTEM, "system", R"( This option specifies the canonical Nix system name of the current installation, such as `i686-linux` or `x86_64-darwin`. Nix can only @@ -172,7 +172,7 @@ public: )"}; Setting maxSilentTime{ - this, 0, "max-silent-time", + *this, 0, "max-silent-time", R"( This option defines the maximum number of seconds that a builder can go without producing any data on standard output or standard error. @@ -187,7 +187,7 @@ public: {"build-max-silent-time"}}; Setting buildTimeout{ - this, 0, "timeout", + *this, 0, "timeout", R"( This option defines the maximum number of seconds that a builder can run. This is useful (for instance in an automated build system) to @@ -200,18 +200,18 @@ public: )", {"build-timeout"}}; - PathSetting buildHook{this, true, "", "build-hook", + PathSetting buildHook{*this, true, "", "build-hook", "The path of the helper program that executes builds to remote machines."}; Setting builders{ - this, "@" + nixConfDir + "/machines", "builders", + *this, "@" + nixConfDir + "/machines", "builders", R"( A semicolon-separated list of build machines. For the exact format and examples, see [the manual chapter on remote builds](../advanced-topics/distributed-builds.md) )"}; Setting buildersUseSubstitutes{ - this, false, "builders-use-substitutes", + *this, false, "builders-use-substitutes", R"( If set to `true`, Nix will instruct remote build machines to use their own binary substitutes if available. In practical terms, this @@ -222,11 +222,11 @@ public: this computer and the remote build host is slow. )"}; - Setting reservedSize{this, 8 * 1024 * 1024, "gc-reserved-space", + Setting reservedSize{*this, 8 * 1024 * 1024, "gc-reserved-space", "Amount of reserved disk space for the garbage collector."}; Setting fsyncMetadata{ - this, true, "fsync-metadata", + *this, true, "fsync-metadata", R"( If set to `true`, changes to the Nix store metadata (in `/nix/var/nix/db`) are synchronously flushed to disk. This improves @@ -234,14 +234,14 @@ public: default is `true`. )"}; - Setting useSQLiteWAL{this, !isWSL1(), "use-sqlite-wal", + Setting useSQLiteWAL{*this, !isWSL1(), "use-sqlite-wal", "Whether SQLite should use WAL mode."}; - Setting syncBeforeRegistering{this, false, "sync-before-registering", + Setting syncBeforeRegistering{*this, false, "sync-before-registering", "Whether to call `sync()` before registering a path as valid."}; Setting useSubstitutes{ - this, true, "substitute", + *this, true, "substitute", R"( If set to `true` (default), Nix will use binary substitutes if available. This option can be disabled to force building from @@ -250,7 +250,7 @@ public: {"build-use-substitutes"}}; Setting buildUsersGroup{ - this, "", "build-users-group", + *this, "", "build-users-group", R"( This options specifies the Unix group containing the Nix build user accounts. In multi-user Nix installations, builds should not be @@ -286,7 +286,7 @@ public: )", {}, false}; - Setting autoAllocateUids{this, false, "auto-allocate-uids", + Setting autoAllocateUids{*this, false, "auto-allocate-uids", R"( Whether to select UIDs for builds automatically, instead of using the users in `build-users-group`. @@ -304,7 +304,7 @@ public: ``` )"}; - Setting startId{this, + Setting startId{*this, #if __linux__ 0x34000000, #else @@ -313,7 +313,7 @@ public: "start-id", "The first UID and GID to use for dynamic ID allocation."}; - Setting uidCount{this, + Setting uidCount{*this, #if __linux__ maxIdsPerBuild * 128, #else @@ -324,7 +324,7 @@ public: #if __linux__ Setting useCgroups{ - this, false, "use-cgroups", + *this, false, "use-cgroups", R"( Whether to execute builds inside cgroups. This is only supported on Linux. @@ -344,12 +344,12 @@ public: )"}; #endif - Setting impersonateLinux26{this, false, "impersonate-linux-26", + Setting impersonateLinux26{*this, false, "impersonate-linux-26", "Whether to impersonate a Linux 2.6 machine on newer kernels.", {"build-impersonate-linux-26"}}; Setting keepLog{ - this, true, "keep-build-log", + *this, true, "keep-build-log", R"( If set to `true` (the default), Nix will write the build log of a derivation (i.e. the standard output and error of its builder) to @@ -359,7 +359,7 @@ public: {"build-keep-log"}}; Setting compressLog{ - this, true, "compress-build-log", + *this, true, "compress-build-log", R"( If set to `true` (the default), build logs written to `/nix/var/log/nix/drvs` will be compressed on the fly using bzip2. @@ -368,7 +368,7 @@ public: {"build-compress-log"}}; Setting maxLogSize{ - this, 0, "max-build-log-size", + *this, 0, "max-build-log-size", R"( This option defines the maximum number of bytes that a builder can write to its stdout/stderr. If the builder exceeds this limit, it’s @@ -376,11 +376,11 @@ public: )", {"build-max-log-size"}}; - Setting pollInterval{this, 5, "build-poll-interval", + Setting pollInterval{*this, 5, "build-poll-interval", "How often (in seconds) to poll for locks."}; Setting gcKeepOutputs{ - this, false, "keep-outputs", + *this, false, "keep-outputs", R"( If `true`, the garbage collector will keep the outputs of non-garbage derivations. If `false` (default), outputs will be @@ -396,7 +396,7 @@ public: {"gc-keep-outputs"}}; Setting gcKeepDerivations{ - this, true, "keep-derivations", + *this, true, "keep-derivations", R"( If `true` (default), the garbage collector will keep the derivations from which non-garbage store paths were built. If `false`, they will @@ -412,7 +412,7 @@ public: {"gc-keep-derivations"}}; Setting autoOptimiseStore{ - this, false, "auto-optimise-store", + *this, false, "auto-optimise-store", R"( If set to `true`, Nix automatically detects files in the store that have identical contents, and replaces them with hard links to @@ -422,7 +422,7 @@ public: )"}; Setting envKeepDerivations{ - this, false, "keep-env-derivations", + *this, false, "keep-env-derivations", R"( If `false` (default), derivations are not stored in Nix user environments. That is, the derivations of any build-time-only @@ -446,7 +446,7 @@ public: bool lockCPU; Setting sandboxMode{ - this, + *this, #if __linux__ smEnabled #else @@ -481,7 +481,7 @@ public: {"build-use-chroot", "build-use-sandbox"}}; Setting sandboxPaths{ - this, {}, "sandbox-paths", + *this, {}, "sandbox-paths", R"( A list of paths bind-mounted into Nix sandbox environments. You can use the syntax `target=source` to mount a path in a different @@ -499,12 +499,12 @@ public: )", {"build-chroot-dirs", "build-sandbox-paths"}}; - Setting sandboxFallback{this, true, "sandbox-fallback", + Setting sandboxFallback{*this, true, "sandbox-fallback", "Whether to disable sandboxing when the kernel doesn't allow it."}; #if __linux__ Setting sandboxShmSize{ - this, "50%", "sandbox-dev-shm-size", + *this, "50%", "sandbox-dev-shm-size", R"( This option determines the maximum size of the `tmpfs` filesystem mounted on `/dev/shm` in Linux sandboxes. For the format, see the @@ -512,20 +512,20 @@ public: is `50%`. )"}; - Setting sandboxBuildDir{this, "/build", "sandbox-build-dir", + Setting sandboxBuildDir{*this, "/build", "sandbox-build-dir", "The build directory inside the sandbox."}; #endif - Setting allowedImpureHostPrefixes{this, {}, "allowed-impure-host-deps", + Setting allowedImpureHostPrefixes{*this, {}, "allowed-impure-host-deps", "Which prefixes to allow derivations to ask for access to (primarily for Darwin)."}; #if __APPLE__ - Setting darwinLogSandboxViolations{this, false, "darwin-log-sandbox-violations", + Setting darwinLogSandboxViolations{*this, false, "darwin-log-sandbox-violations", "Whether to log Darwin sandbox access violations to the system log."}; #endif Setting runDiffHook{ - this, false, "run-diff-hook", + *this, false, "run-diff-hook", R"( If true, enable the execution of the `diff-hook` program. @@ -535,7 +535,7 @@ public: )"}; PathSetting diffHook{ - this, true, "", "diff-hook", + *this, true, "", "diff-hook", R"( Absolute path to an executable capable of diffing build results. The hook is executed if `run-diff-hook` is true, and the @@ -566,7 +566,7 @@ public: )"}; Setting trustedPublicKeys{ - this, + *this, {"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="}, "trusted-public-keys", R"( @@ -579,7 +579,7 @@ public: {"binary-cache-public-keys"}}; Setting secretKeyFiles{ - this, {}, "secret-key-files", + *this, {}, "secret-key-files", R"( A whitespace-separated list of files containing secret (private) keys. These are used to sign locally-built paths. They can be @@ -589,7 +589,7 @@ public: )"}; Setting tarballTtl{ - this, 60 * 60, "tarball-ttl", + *this, 60 * 60, "tarball-ttl", R"( The number of seconds a downloaded tarball is considered fresh. If the cached tarball is stale, Nix will check whether it is still up @@ -606,7 +606,7 @@ public: )"}; Setting requireSigs{ - this, true, "require-sigs", + *this, true, "require-sigs", R"( If set to `true` (the default), any non-content-addressed path added or copied to the Nix store (e.g. when substituting from a binary @@ -622,7 +622,7 @@ public: )"}; Setting extraPlatforms{ - this, + *this, getDefaultExtraPlatforms(), "extra-platforms", R"( @@ -641,7 +641,7 @@ public: )", {}, false}; Setting systemFeatures{ - this, + *this, getDefaultSystemFeatures(), "system-features", R"( @@ -661,7 +661,7 @@ public: )", {}, false}; Setting substituters{ - this, + *this, Strings{"https://cache.nixos.org/"}, "substituters", R"( @@ -681,7 +681,7 @@ public: {"binary-caches"}}; Setting trustedSubstituters{ - this, {}, "trusted-substituters", + *this, {}, "trusted-substituters", R"( A list of URLs of substituters, separated by whitespace. These are not used by default, but can be enabled by users of the Nix daemon @@ -692,7 +692,7 @@ public: {"trusted-binary-caches"}}; Setting trustedUsers{ - this, {"root"}, "trusted-users", + *this, {"root"}, "trusted-users", R"( A list of names of users (separated by whitespace) that have additional rights when connecting to the Nix daemon, such as the @@ -710,7 +710,7 @@ public: )"}; Setting ttlNegativeNarInfoCache{ - this, 3600, "narinfo-cache-negative-ttl", + *this, 3600, "narinfo-cache-negative-ttl", R"( The TTL in seconds for negative lookups. If a store path is queried from a substituter but was not found, there will be a negative @@ -719,7 +719,7 @@ public: )"}; Setting ttlPositiveNarInfoCache{ - this, 30 * 24 * 3600, "narinfo-cache-positive-ttl", + *this, 30 * 24 * 3600, "narinfo-cache-positive-ttl", R"( The TTL in seconds for positive lookups. If a store path is queried from a substituter, the result of the query will be cached in the @@ -733,7 +733,7 @@ public: /* ?Who we trust to use the daemon in safe ways */ Setting allowedUsers{ - this, {"*"}, "allowed-users", + *this, {"*"}, "allowed-users", R"( A list of names of users (separated by whitespace) that are allowed to connect to the Nix daemon. As with the `trusted-users` option, @@ -743,11 +743,11 @@ public: Note that trusted users are always allowed to connect. )"}; - Setting printMissing{this, true, "print-missing", + Setting printMissing{*this, true, "print-missing", "Whether to print what paths need to be built or downloaded."}; Setting preBuildHook{ - this, "", "pre-build-hook", + *this, "", "pre-build-hook", R"( If set, the path to a program that can set extra derivation-specific settings for this system. This is used for settings that can't be @@ -766,7 +766,7 @@ public: )"}; Setting postBuildHook{ - this, "", "post-build-hook", + *this, "", "post-build-hook", R"( Optional. The path to a program to execute after each build. @@ -811,14 +811,14 @@ public: )"}; Setting downloadSpeed { - this, 0, "download-speed", + *this, 0, "download-speed", R"( Specify the maximum transfer rate in kilobytes per second you want Nix to use for downloads. )"}; Setting netrcFile{ - this, fmt("%s/%s", nixConfDir, "netrc"), "netrc-file", + *this, fmt("%s/%s", nixConfDir, "netrc"), "netrc-file", R"( If set to an absolute path to a `netrc` file, Nix will use the HTTP authentication credentials in this file when trying to download from @@ -847,7 +847,7 @@ public: #if __linux__ Setting filterSyscalls{ - this, true, "filter-syscalls", + *this, true, "filter-syscalls", R"( Whether to prevent certain dangerous system calls, such as creation of setuid/setgid files or adding ACLs or extended @@ -856,7 +856,7 @@ public: )"}; Setting allowNewPrivileges{ - this, false, "allow-new-privileges", + *this, false, "allow-new-privileges", R"( (Linux-specific.) By default, builders on Linux cannot acquire new privileges by calling setuid/setgid programs or programs that have @@ -870,7 +870,7 @@ public: )"}; Setting ignoredAcls{ - this, {"security.selinux", "system.nfs4_acl", "security.csm"}, "ignored-acls", + *this, {"security.selinux", "system.nfs4_acl", "security.csm"}, "ignored-acls", R"( A list of ACLs that should be ignored, normally Nix attempts to remove all ACLs from files and directories in the Nix store, but @@ -880,7 +880,7 @@ public: #endif Setting hashedMirrors{ - this, {}, "hashed-mirrors", + *this, {}, "hashed-mirrors", R"( A list of web servers used by `builtins.fetchurl` to obtain files by hash. The default is `http://tarballs.nixos.org/`. Given a hash type @@ -903,7 +903,7 @@ public: )"}; Setting minFree{ - this, 0, "min-free", + *this, 0, "min-free", R"( When free disk space in `/nix/store` drops below `min-free` during a build, Nix performs a garbage-collection until `max-free` bytes are @@ -912,18 +912,18 @@ public: )"}; Setting maxFree{ - this, std::numeric_limits::max(), "max-free", + *this, std::numeric_limits::max(), "max-free", R"( When a garbage collection is triggered by the `min-free` option, it stops as soon as `max-free` bytes are available. The default is infinity (i.e. delete all garbage). )"}; - Setting minFreeCheckInterval{this, 5, "min-free-check-interval", + Setting minFreeCheckInterval{*this, 5, "min-free-check-interval", "Number of seconds between checking free disk space."}; PluginFilesSetting pluginFiles{ - this, {}, "plugin-files", + *this, {}, "plugin-files", R"( A list of plugin files to be loaded by Nix. Each of these files will be dlopened by Nix, allowing them to affect execution through static @@ -948,18 +948,18 @@ public: are loaded as plugins (non-recursively). )"}; - Setting> experimentalFeatures{this, {}, "experimental-features", + Setting> experimentalFeatures{*this, {}, "experimental-features", "Experimental Nix features to enable."}; bool isExperimentalFeatureEnabled(const ExperimentalFeature &); void requireExperimentalFeature(const ExperimentalFeature &); - Setting narBufferSize{this, 32 * 1024 * 1024, "nar-buffer-size", + Setting narBufferSize{*this, 32 * 1024 * 1024, "nar-buffer-size", "Maximum size of NARs before spilling them to disk."}; Setting allowSymlinkedStore{ - this, false, "allow-symlinked-store", + *this, false, "allow-symlinked-store", R"( If set to `true`, Nix will stop complaining if the store directory (typically /nix/store) contains symlink components. diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index 4d398b21d855..264b1ed25f6d 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -15,12 +15,12 @@ namespace nix { struct LegacySSHStoreConfig : virtual StoreConfig { using StoreConfig::StoreConfig; - const Setting maxConnections{(StoreConfig*) this, 1, "max-connections", "maximum number of concurrent SSH connections"}; - const Setting sshKey{(StoreConfig*) this, "", "ssh-key", "path to an SSH private key"}; - const Setting sshPublicHostKey{(StoreConfig*) this, "", "base64-ssh-public-host-key", "The public half of the host's SSH key"}; - const Setting compress{(StoreConfig*) this, false, "compress", "whether to compress the connection"}; - const Setting remoteProgram{(StoreConfig*) this, "nix-store", "remote-program", "path to the nix-store executable on the remote system"}; - const Setting remoteStore{(StoreConfig*) this, "", "remote-store", "URI of the store on the remote system"}; + const Setting maxConnections{this->dodgeGcc80431(), 1, "max-connections", "maximum number of concurrent SSH connections"}; + const Setting sshKey{this->dodgeGcc80431(), "", "ssh-key", "path to an SSH private key"}; + const Setting sshPublicHostKey{this->dodgeGcc80431(), "", "base64-ssh-public-host-key", "The public half of the host's SSH key"}; + const Setting compress{this->dodgeGcc80431(), false, "compress", "whether to compress the connection"}; + const Setting remoteProgram{this->dodgeGcc80431(), "nix-store", "remote-program", "path to the nix-store executable on the remote system"}; + const Setting remoteStore{this->dodgeGcc80431(), "", "remote-store", "URI of the store on the remote system"}; const std::string name() override { return "Legacy SSH Store"; } }; @@ -30,7 +30,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor // Hack for getting remote build log output. // Intentionally not in `LegacySSHStoreConfig` so that it doesn't appear in // the documentation - const Setting logFD{(StoreConfig*) this, -1, "log-fd", "file descriptor to which SSH's stderr is connected"}; + const Setting logFD{this->dodgeGcc80431(), -1, "log-fd", "file descriptor to which SSH's stderr is connected"}; struct Connection { diff --git a/src/libstore/local-fs-store.hh b/src/libstore/local-fs-store.hh index e6fb3201a496..db3398779bfc 100644 --- a/src/libstore/local-fs-store.hh +++ b/src/libstore/local-fs-store.hh @@ -9,18 +9,15 @@ namespace nix { struct LocalFSStoreConfig : virtual StoreConfig { using StoreConfig::StoreConfig; - // FIXME: the (StoreConfig*) cast works around a bug in gcc that causes - // it to omit the call to the Setting constructor. Clang works fine - // either way. - const PathSetting rootDir{(StoreConfig*) this, true, "", + const PathSetting rootDir{this->dodgeGcc80431(), true, "", "root", "directory prefixed to all other paths"}; - const PathSetting stateDir{(StoreConfig*) this, false, + const PathSetting stateDir{this->dodgeGcc80431(), false, rootDir != "" ? rootDir + "/nix/var/nix" : settings.nixStateDir, "state", "directory where Nix will store state"}; - const PathSetting logDir{(StoreConfig*) this, false, + const PathSetting logDir{this->dodgeGcc80431(), false, rootDir != "" ? rootDir + "/nix/var/log/nix" : settings.nixLogDir, "log", "directory where Nix will store state"}; - const PathSetting realStoreDir{(StoreConfig*) this, false, + const PathSetting realStoreDir{this->dodgeGcc80431(), false, rootDir != "" ? rootDir + "/nix/store" : storeDir, "real", "physical path to the Nix store"}; }; diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 06d36a7d5cbb..31193dd27e98 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -36,7 +36,7 @@ struct LocalStoreConfig : virtual LocalFSStoreConfig { using LocalFSStoreConfig::LocalFSStoreConfig; - Setting requireSigs{(StoreConfig*) this, + Setting requireSigs{this->dodgeGcc80431(), settings.requireSigs, "require-sigs", "whether store paths should have a trusted signature on import"}; diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index 11d089cd2450..29506955a0cb 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -22,10 +22,10 @@ struct RemoteStoreConfig : virtual StoreConfig { using StoreConfig::StoreConfig; - const Setting maxConnections{(StoreConfig*) this, 1, + const Setting maxConnections{this->dodgeGcc80431(), 1, "max-connections", "maximum number of concurrent connections to the Nix daemon"}; - const Setting maxConnectionAge{(StoreConfig*) this, std::numeric_limits::max(), + const Setting maxConnectionAge{this->dodgeGcc80431(), std::numeric_limits::max(), "max-connection-age", "number of seconds to reuse a connection"}; }; diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc index 844553ad3094..ef70fe06c1a2 100644 --- a/src/libstore/s3-binary-cache-store.cc +++ b/src/libstore/s3-binary-cache-store.cc @@ -192,17 +192,17 @@ S3BinaryCacheStore::S3BinaryCacheStore(const Params & params) struct S3BinaryCacheStoreConfig : virtual BinaryCacheStoreConfig { using BinaryCacheStoreConfig::BinaryCacheStoreConfig; - const Setting profile{(StoreConfig*) this, "", "profile", "The name of the AWS configuration profile to use."}; - const Setting region{(StoreConfig*) this, Aws::Region::US_EAST_1, "region", {"aws-region"}}; - const Setting scheme{(StoreConfig*) this, "", "scheme", "The scheme to use for S3 requests, https by default."}; - const Setting endpoint{(StoreConfig*) this, "", "endpoint", "An optional override of the endpoint to use when talking to S3."}; - const Setting narinfoCompression{(StoreConfig*) this, "", "narinfo-compression", "compression method for .narinfo files"}; - const Setting lsCompression{(StoreConfig*) this, "", "ls-compression", "compression method for .ls files"}; - const Setting logCompression{(StoreConfig*) this, "", "log-compression", "compression method for log/* files"}; + const Setting profile{this->dodgeGcc80431(), "", "profile", "The name of the AWS configuration profile to use."}; + const Setting region{this->dodgeGcc80431(), Aws::Region::US_EAST_1, "region", {"aws-region"}}; + const Setting scheme{this->dodgeGcc80431(), "", "scheme", "The scheme to use for S3 requests, https by default."}; + const Setting endpoint{this->dodgeGcc80431(), "", "endpoint", "An optional override of the endpoint to use when talking to S3."}; + const Setting narinfoCompression{this->dodgeGcc80431(), "", "narinfo-compression", "compression method for .narinfo files"}; + const Setting lsCompression{this->dodgeGcc80431(), "", "ls-compression", "compression method for .ls files"}; + const Setting logCompression{this->dodgeGcc80431(), "", "log-compression", "compression method for log/* files"}; const Setting multipartUpload{ - (StoreConfig*) this, false, "multipart-upload", "whether to use multi-part uploads"}; + this->dodgeGcc80431(), false, "multipart-upload", "whether to use multi-part uploads"}; const Setting bufferSize{ - (StoreConfig*) this, 5 * 1024 * 1024, "buffer-size", "size (in bytes) of each part in multi-part uploads"}; + this->dodgeGcc80431(), 5 * 1024 * 1024, "buffer-size", "size (in bytes) of each part in multi-part uploads"}; const std::string name() override { return "S3 Binary Cache Store"; } }; diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc index 62daa838ce63..897bbd40762e 100644 --- a/src/libstore/ssh-store.cc +++ b/src/libstore/ssh-store.cc @@ -12,11 +12,11 @@ struct SSHStoreConfig : virtual RemoteStoreConfig { using RemoteStoreConfig::RemoteStoreConfig; - const Setting sshKey{(StoreConfig*) this, "", "ssh-key", "path to an SSH private key"}; - const Setting sshPublicHostKey{(StoreConfig*) this, "", "base64-ssh-public-host-key", "The public half of the host's SSH key"}; - const Setting compress{(StoreConfig*) this, false, "compress", "whether to compress the connection"}; - const Setting remoteProgram{(StoreConfig*) this, "nix-daemon", "remote-program", "path to the nix-daemon executable on the remote system"}; - const Setting remoteStore{(StoreConfig*) this, "", "remote-store", "URI of the store on the remote system"}; + const Setting sshKey{this->dodgeGcc80431(), "", "ssh-key", "path to an SSH private key"}; + const Setting sshPublicHostKey{this->dodgeGcc80431(), "", "base64-ssh-public-host-key", "The public half of the host's SSH key"}; + const Setting compress{this->dodgeGcc80431(), false, "compress", "whether to compress the connection"}; + const Setting remoteProgram{this->dodgeGcc80431(), "nix-daemon", "remote-program", "path to the nix-daemon executable on the remote system"}; + const Setting remoteStore{this->dodgeGcc80431(), "", "remote-store", "URI of the store on the remote system"}; const std::string name() override { return "SSH Store"; } }; diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 4a88d721608c..8185649fb331 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -92,26 +92,36 @@ struct StoreConfig : public Config StringSet getDefaultSystemFeatures(); - virtual ~StoreConfig() { } + virtual ~StoreConfig() = default; virtual const std::string name() = 0; - const PathSetting storeDir_{this, false, settings.nixStore, + const PathSetting storeDir_{this->dodgeGcc80431(), false, settings.nixStore, "store", "path to the Nix store"}; const Path storeDir = storeDir_; - const Setting pathInfoCacheSize{this, 65536, "path-info-cache-size", "size of the in-memory store path information cache"}; + const Setting pathInfoCacheSize{this->dodgeGcc80431(), 65536, "path-info-cache-size", "size of the in-memory store path information cache"}; - const Setting isTrusted{this, false, "trusted", "whether paths from this store can be used as substitutes even when they lack trusted signatures"}; + const Setting isTrusted{this->dodgeGcc80431(), false, "trusted", "whether paths from this store can be used as substitutes even when they lack trusted signatures"}; - Setting priority{this, 0, "priority", "priority of this substituter (lower value means higher priority)"}; + Setting priority{this->dodgeGcc80431(), 0, "priority", "priority of this substituter (lower value means higher priority)"}; - Setting wantMassQuery{this, false, "want-mass-query", "whether this substituter can be queried efficiently for path validity"}; + Setting wantMassQuery{this->dodgeGcc80431(), false, "want-mass-query", "whether this substituter can be queried efficiently for path validity"}; - Setting systemFeatures{this, getDefaultSystemFeatures(), + Setting systemFeatures{this->dodgeGcc80431(), getDefaultSystemFeatures(), "system-features", "Optional features that the system this store builds on implements (like \"kvm\")."}; +protected: + + // FIXME: the cast works around a bug in gcc, + // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431, that causes + // it to omit the call to the Setting constructor. Clang works fine + // either way. + inline Config & dodgeGcc80431() + { + return static_cast(*this); + } }; class Store : public std::enable_shared_from_this, public virtual StoreConfig diff --git a/src/libutil/archive.cc b/src/libutil/archive.cc index 0e2b9d12c840..1f858a4da330 100644 --- a/src/libutil/archive.cc +++ b/src/libutil/archive.cc @@ -19,7 +19,7 @@ namespace nix { struct ArchiveSettings : Config { - Setting useCaseHack{this, + Setting useCaseHack{*this, #if __APPLE__ true, #else @@ -27,13 +27,13 @@ struct ArchiveSettings : Config #endif "use-case-hack", "Whether to enable a Darwin-specific hack for dealing with file name collisions."}; - Setting preallocateContents{this, false, "preallocate-contents", + Setting preallocateContents{*this, false, "preallocate-contents", "Whether to preallocate files when writing objects with known size."}; }; static ArchiveSettings archiveSettings; -static GlobalConfig::Register rArchiveSettings(&archiveSettings); +static GlobalConfig::Register rArchiveSettings { archiveSettings }; PathFilter defaultPathFilter = [](const Path &) { return true; }; diff --git a/src/libutil/config.cc b/src/libutil/config.cc index 9bb412b4f5ea..a5e398764c53 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -437,11 +437,11 @@ GlobalConfig globalConfig; GlobalConfig::ConfigRegistrations * GlobalConfig::configRegistrations; -GlobalConfig::Register::Register(Config * config) +GlobalConfig::Register::Register(Config & config) { if (!configRegistrations) configRegistrations = new ConfigRegistrations; - configRegistrations->emplace_back(config); + configRegistrations->emplace_back(&config); } } diff --git a/src/libutil/config.hh b/src/libutil/config.hh index 79ec0f9cf363..f15cd815d347 100644 --- a/src/libutil/config.hh +++ b/src/libutil/config.hh @@ -287,7 +287,7 @@ template class Setting : public BaseSetting { public: - Setting(Config * options, + Setting(Config & options, const T & def, const std::string & name, const std::string & description, @@ -295,7 +295,7 @@ public: const bool documentDefault = true) : BaseSetting(def, documentDefault, name, description, aliases) { - options->addSetting(this); + options.addSetting(this); } void operator =(const T & v) { this->assign(v); } @@ -309,7 +309,7 @@ class PathSetting : public BaseSetting public: - PathSetting(Config * options, + PathSetting(Config & options, bool allowEmpty, const Path & def, const std::string & name, @@ -318,7 +318,7 @@ public: : BaseSetting(def, true, name, description, aliases) , allowEmpty(allowEmpty) { - options->addSetting(this); + options.addSetting(this); } void set(const std::string & str, bool append = false) override; @@ -347,7 +347,7 @@ struct GlobalConfig : public AbstractConfig struct Register { - Register(Config * config); + Register(Config & config); }; }; diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index 904ba6ebee48..6da48cf9f4b3 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -10,7 +10,7 @@ namespace nix { LoggerSettings loggerSettings; -static GlobalConfig::Register rLoggerSettings(&loggerSettings); +static GlobalConfig::Register rLoggerSettings { loggerSettings }; static thread_local ActivityId curActivity = 0; diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index 4642c49f7ed0..e6b8d5278720 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -40,7 +40,7 @@ typedef uint64_t ActivityId; struct LoggerSettings : Config { Setting showTrace{ - this, false, "show-trace", + *this, false, "show-trace", R"( Whether Nix should print out a stack trace in case of Nix expression evaluation errors. diff --git a/src/libutil/tests/config.cc b/src/libutil/tests/config.cc index 8be6730dd8df..d9806a55b9fa 100644 --- a/src/libutil/tests/config.cc +++ b/src/libutil/tests/config.cc @@ -19,7 +19,7 @@ namespace nix { TEST(Config, setDefinedSetting) { Config config; std::string value; - Setting foo{&config, value, "name-of-the-setting", "description"}; + Setting foo{config, value, "name-of-the-setting", "description"}; ASSERT_EQ(config.set("name-of-the-setting", "value"), true); } @@ -27,7 +27,7 @@ namespace nix { Config config; std::string value; std::map settings; - Setting foo{&config, value, "name-of-the-setting", "description"}; + Setting foo{config, value, "name-of-the-setting", "description"}; config.getSettings(settings, /* overriddenOnly = */ false); const auto iter = settings.find("name-of-the-setting"); @@ -40,7 +40,7 @@ namespace nix { Config config; std::string value; std::map settings; - Setting foo{&config, value, "name-of-the-setting", "description"}; + Setting foo{config, value, "name-of-the-setting", "description"}; config.getSettings(settings, /* overriddenOnly = */ true); const auto e = settings.find("name-of-the-setting"); @@ -51,7 +51,7 @@ namespace nix { Config config; std::string value; std::map settings; - Setting setting{&config, value, "name-of-the-setting", "description"}; + Setting setting{config, value, "name-of-the-setting", "description"}; setting.assign("value"); @@ -65,7 +65,7 @@ namespace nix { TEST(Config, getDefinedSettingSet2) { Config config; std::map settings; - Setting setting{&config, "", "name-of-the-setting", "description"}; + Setting setting{config, "", "name-of-the-setting", "description"}; ASSERT_TRUE(config.set("name-of-the-setting", "value")); @@ -104,7 +104,7 @@ namespace nix { ASSERT_EQ(settings.find("key"), settings.end()); } - Setting setting{&config, "default-value", "key", "description"}; + Setting setting{config, "default-value", "key", "description"}; { std::map settings; @@ -120,7 +120,7 @@ namespace nix { TEST(Config, resetOverriddenWithSetting) { Config config; - Setting setting{&config, "", "name-of-the-setting", "description"}; + Setting setting{config, "", "name-of-the-setting", "description"}; { std::map settings; @@ -158,7 +158,7 @@ namespace nix { TEST(Config, toJSONOnNonEmptyConfig) { Config config; std::map settings; - Setting setting{&config, "", "name-of-the-setting", "description"}; + Setting setting{config, "", "name-of-the-setting", "description"}; setting.assign("value"); ASSERT_EQ(config.toJSON().dump(), R"#({"name-of-the-setting":{"aliases":[],"defaultValue":"","description":"description\n","documentDefault":true,"value":"value"}})#"); @@ -166,7 +166,7 @@ namespace nix { TEST(Config, setSettingAlias) { Config config; - Setting setting{&config, "", "some-int", "best number", { "another-int" }}; + Setting setting{config, "", "some-int", "best number", { "another-int" }}; ASSERT_TRUE(config.set("some-int", "1")); ASSERT_EQ(setting.get(), "1"); ASSERT_TRUE(config.set("another-int", "2")); @@ -183,7 +183,7 @@ namespace nix { TEST(Config, DISABLED_reapplyUnknownSettings) { Config config; ASSERT_FALSE(config.set("name-of-the-setting", "unknownvalue")); - Setting setting{&config, "default", "name-of-the-setting", "description"}; + Setting setting{config, "default", "name-of-the-setting", "description"}; ASSERT_EQ(setting.get(), "default"); config.reapplyUnknownSettings(); ASSERT_EQ(setting.get(), "unknownvalue"); @@ -208,7 +208,7 @@ namespace nix { TEST(Config, applyConfigAssignment) { Config config; std::map settings; - Setting setting{&config, "", "name-of-the-setting", "description"}; + Setting setting{config, "", "name-of-the-setting", "description"}; config.applyConfig( "name-of-the-setting = value-from-file #useful comment\n" "# name-of-the-setting = foo\n" @@ -221,7 +221,7 @@ namespace nix { TEST(Config, applyConfigWithReassignedSetting) { Config config; std::map settings; - Setting setting{&config, "", "name-of-the-setting", "description"}; + Setting setting{config, "", "name-of-the-setting", "description"}; config.applyConfig( "name-of-the-setting = first-value\n" "name-of-the-setting = second-value\n" @@ -234,7 +234,7 @@ namespace nix { TEST(Config, applyConfigFailsOnMissingIncludes) { Config config; std::map settings; - Setting setting{&config, "", "name-of-the-setting", "description"}; + Setting setting{config, "", "name-of-the-setting", "description"}; ASSERT_THROW(config.applyConfig( "name-of-the-setting = value-from-file\n" diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 1d90d1dac4b4..154f7664f0f1 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -15,19 +15,19 @@ using namespace nix; struct DevelopSettings : Config { - Setting bashPrompt{this, "", "bash-prompt", + Setting bashPrompt{*this, "", "bash-prompt", "The bash prompt (`PS1`) in `nix develop` shells."}; - Setting bashPromptPrefix{this, "", "bash-prompt-prefix", + Setting bashPromptPrefix{*this, "", "bash-prompt-prefix", "Prefix prepended to the `PS1` environment variable in `nix develop` shells."}; - Setting bashPromptSuffix{this, "", "bash-prompt-suffix", + Setting bashPromptSuffix{*this, "", "bash-prompt-suffix", "Suffix appended to the `PS1` environment variable in `nix develop` shells."}; }; static DevelopSettings developSettings; -static GlobalConfig::Register rDevelopSettings(&developSettings); +static GlobalConfig::Register rDevelopSettings { developSettings }; struct BuildEnvironment { diff --git a/tests/plugins/plugintest.cc b/tests/plugins/plugintest.cc index 04b7910216bd..dc723c248499 100644 --- a/tests/plugins/plugintest.cc +++ b/tests/plugins/plugintest.cc @@ -5,13 +5,13 @@ using namespace nix; struct MySettings : Config { - Setting settingSet{this, false, "setting-set", + Setting settingSet{*this, false, "setting-set", "Whether the plugin-defined setting was set"}; }; MySettings mySettings; -static GlobalConfig::Register rs(&mySettings); +static GlobalConfig::Register rs { mySettings }; static void prim_anotherNull (EvalState & state, const PosIdx pos, Value ** args, Value & v) {