diff --git a/doc/manual/generate-settings.nix b/doc/manual/generate-settings.nix index 8736bb7933f..9ccabee902d 100644 --- a/doc/manual/generate-settings.nix +++ b/doc/manual/generate-settings.nix @@ -1,5 +1,5 @@ let - inherit (builtins) attrValues concatStringsSep isAttrs isBool mapAttrs; + inherit (builtins) attrValues concatStringsSep isAttrs isBool isString mapAttrs; inherit (import ./utils.nix) concatStrings indent optionalString squash; in @@ -8,7 +8,7 @@ in let - showSetting = prefix: setting: { description, documentDefault, defaultValue, aliases, value, experimentalFeature }: + showSetting = prefix: setting: { description, defaultValue, defaultText, aliases, value, experimentalFeature }: let result = squash '' - ${item} @@ -24,7 +24,7 @@ let ${experimentalFeatureNote} - **Default:** ${showDefault documentDefault defaultValue} + **Default:** ${if isString defaultText then defaultText else showDefault defaultValue} ${showAliases aliases} ''; @@ -45,17 +45,15 @@ let ``` ''; - showDefault = documentDefault: defaultValue: - if documentDefault then - # a StringMap value type is specified as a string, but - # this shows the value type. The empty stringmap is `null` in - # JSON, but that converts to `{ }` here. - if defaultValue == "" || defaultValue == [] || isAttrs defaultValue - then "*empty*" - else if isBool defaultValue then - if defaultValue then "`true`" else "`false`" - else "`${toString defaultValue}`" - else "*machine-specific*"; + showDefault = defaultValue: + # a StringMap value type is specified as a string, but + # this shows the value type. The empty stringmap is `null` in + # JSON, but that converts to `{ }` here. + if defaultValue == "" || defaultValue == [] || isAttrs defaultValue + then "*empty*" + else if isBool defaultValue then + if defaultValue then "`true`" else "`false`" + else "`${toString defaultValue}`"; showAliases = aliases: optionalString (aliases != []) diff --git a/src/libfetchers/fetch-settings.hh b/src/libfetchers/fetch-settings.hh index 6108a179cda..732d8add2be 100644 --- a/src/libfetchers/fetch-settings.hh +++ b/src/libfetchers/fetch-settings.hh @@ -77,16 +77,16 @@ struct FetchSettings : public Config When empty, disables the global flake registry. )", - {}, true, Xp::Flakes}; + {}, std::nullopt, Xp::Flakes}; Setting useRegistries{this, true, "use-registries", "Whether to use flake registries to resolve flake references.", - {}, true, Xp::Flakes}; + {}, std::nullopt, Xp::Flakes}; Setting acceptFlakeConfig{this, false, "accept-flake-config", "Whether to accept nix configuration from a flake without prompting.", - {}, true, Xp::Flakes}; + {}, std::nullopt, Xp::Flakes}; Setting commitLockFileSummary{ this, "", "commit-lockfile-summary", @@ -94,7 +94,7 @@ struct FetchSettings : public Config The commit summary to use when committing changed flake lock files. If empty, the summary is generated based on the action performed. )", - {}, true, Xp::Flakes}; + {}, std::nullopt, Xp::Flakes}; }; // FIXME: don't use a global variable. diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index 12fb48d9383..ab42e271f31 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -21,8 +21,9 @@ struct MaxBuildJobsSetting : public BaseSetting unsigned int def, const std::string & name, const std::string & description, - const std::set & aliases = {}) - : BaseSetting(def, true, name, description, aliases) + const std::set & aliases = {}, + const std::optional defaultText = std::nullopt) + : BaseSetting(def, name, description, aliases, defaultText) { options->addSetting(this); } @@ -38,8 +39,9 @@ struct PluginFilesSetting : public BaseSetting const Paths & def, const std::string & name, const std::string & description, - const std::set & aliases = {}) - : BaseSetting(def, true, name, description, aliases) + const std::set & aliases = {}, + const std::optional defaultText = std::nullopt) + : BaseSetting(def, name, description, aliases, defaultText) { options->addSetting(this); } @@ -183,7 +185,7 @@ public: command line switch and defaults to `1`. The value `0` means that the builder should use all available CPU cores in the system. )", - {"build-cores"}, false}; + {"build-cores"}, "`0`"}; /** * Read-only mode. Don't copy stuff to the store, don't change @@ -260,7 +262,7 @@ public: 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) - )"}; + )", {}, "`@$NIX_CONF_DIR/machines`"}; Setting alwaysAllowSubstitutes{ this, false, "always-allow-substitutes", @@ -295,7 +297,7 @@ public: )"}; Setting useSQLiteWAL{this, !isWSL1(), "use-sqlite-wal", - "Whether SQLite should use WAL mode."}; + "Whether SQLite should use WAL mode.", {}, "`false` if using WSL1, `true` otherwise"}; Setting syncBeforeRegistering{this, false, "sync-before-registering", "Whether to call `sync()` before registering a path as valid."}; @@ -341,10 +343,8 @@ public: `NIX_REMOTE` is empty, the uid under which the Nix daemon runs if `NIX_REMOTE` is `daemon`). Obviously, this should not be used with a nix daemon accessible to untrusted clients. - - Defaults to `nixbld` when running as root, *empty* otherwise. )", - {}, false}; + {}, "`nixbld` when running as root, *empty* otherwise"}; Setting autoAllocateUids{this, false, "auto-allocate-uids", R"( @@ -352,7 +352,7 @@ public: users in `build-users-group`. UIDs are allocated starting at 872415232 (0x34000000) on Linux and 56930 on macOS. - )", {}, true, Xp::AutoAllocateUids}; + )", {}, std::nullopt, Xp::AutoAllocateUids}; Setting startId{this, #if __linux__ @@ -699,7 +699,7 @@ public: Build systems will usually detect the target platform to be the current physical system and therefore produce machine code incompatible with what may be intended in the derivation. You should design your derivation's `builder` accordingly and cross-check the results when using this option against natively-built versions of your derivation. - )", {}, false}; + )", {}, "*machine-specific*"}; Setting systemFeatures{ this, @@ -744,7 +744,7 @@ public: [nspawn]: https://github.com/NixOS/nix/blob/67bcb99700a0da1395fa063d7c6586740b304598/tests/systemd-nspawn.nix. Included by default on Linux if the [`auto-allocate-uids`](#conf-auto-allocate-uids) setting is enabled. - )", {}, false}; + )", {}, "*machine-specific*"}; Setting substituters{ this, @@ -878,8 +878,7 @@ public: 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 - a remote host through HTTP or HTTPS. Defaults to - `$NIX_CONF_DIR/netrc`. + a remote host through HTTP or HTTPS. The `netrc` file consists of a list of accounts in the following format: @@ -896,7 +895,7 @@ public: > This must be an absolute path, and `~` is not resolved. For > example, `~/.netrc` won't resolve to your home directory's > `.netrc`. - )"}; + )", {}, "`$NIX_CONF_DIR/netrc`"}; Setting caFile{ this, getDefaultSSLCertFile(), "ssl-cert-file", @@ -1081,7 +1080,7 @@ public: setting private access tokens when fetching a private repository. )", {}, // aliases - true, // document default + std::nullopt, // default text Xp::ConfigurableImpureEnv }; }; diff --git a/src/libutil/abstract-setting-to-json.hh b/src/libutil/abstract-setting-to-json.hh index d506dfb743f..b70a724f134 100644 --- a/src/libutil/abstract-setting-to-json.hh +++ b/src/libutil/abstract-setting-to-json.hh @@ -12,7 +12,7 @@ std::map BaseSetting::toJSONObject() auto obj = AbstractSetting::toJSONObject(); obj.emplace("value", value); obj.emplace("defaultValue", defaultValue); - obj.emplace("documentDefault", documentDefault); + obj.emplace("defaultText", defaultText); return obj; } } diff --git a/src/libutil/config.cc b/src/libutil/config.cc index 8e06273ee8c..28deb5a8cea 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -407,8 +407,9 @@ PathSetting::PathSetting(Config * options, const Path & def, const std::string & name, const std::string & description, - const std::set & aliases) - : BaseSetting(def, true, name, description, aliases) + const std::set & aliases, + const std::optional defaultText) + : BaseSetting(def, name, description, aliases, defaultText) { options->addSetting(this); } @@ -423,8 +424,9 @@ OptionalPathSetting::OptionalPathSetting(Config * options, const std::optional & def, const std::string & name, const std::string & description, - const std::set & aliases) - : BaseSetting>(def, true, name, description, aliases) + const std::set & aliases, + const std::optional defaultText) + : BaseSetting>(def, name, description, aliases, defaultText) { options->addSetting(this); } diff --git a/src/libutil/config.hh b/src/libutil/config.hh index 38c3ce0c497..55d46f71732 100644 --- a/src/libutil/config.hh +++ b/src/libutil/config.hh @@ -230,7 +230,7 @@ protected: T value; const T defaultValue; - const bool documentDefault; + const std::optional defaultText; /** * Parse the string into a `T`. @@ -252,15 +252,15 @@ protected: public: BaseSetting(const T & def, - const bool documentDefault, const std::string & name, const std::string & description, const std::set & aliases = {}, + const std::optional defaultText = std::nullopt, std::optional experimentalFeature = std::nullopt) : AbstractSetting(name, description, aliases, experimentalFeature) , value(def) , defaultValue(def) - , documentDefault(documentDefault) + , defaultText(defaultText) { } operator const T &() const { return value; } @@ -327,9 +327,9 @@ public: const std::string & name, const std::string & description, const std::set & aliases = {}, - const bool documentDefault = true, + const std::optional defaultText = std::nullopt, std::optional experimentalFeature = std::nullopt) - : BaseSetting(def, documentDefault, name, description, aliases, experimentalFeature) + : BaseSetting(def, name, description, aliases, defaultText, experimentalFeature) { options->addSetting(this); } @@ -352,7 +352,8 @@ public: const Path & def, const std::string & name, const std::string & description, - const std::set & aliases = {}); + const std::set & aliases = {}, + const std::optional defaultText = std::nullopt); Path parse(const std::string & str) const override; @@ -374,7 +375,8 @@ public: const std::optional & def, const std::string & name, const std::string & description, - const std::set & aliases = {}); + const std::set & aliases = {}, + const std::optional defaultText = std::nullopt); std::optional parse(const std::string & str) const override; diff --git a/src/libutil/tests/config.cc b/src/libutil/tests/config.cc index 886e70da50d..c6781ffe610 100644 --- a/src/libutil/tests/config.cc +++ b/src/libutil/tests/config.cc @@ -174,7 +174,7 @@ namespace nix { "aliases": [], "defaultValue": "", "description": "description\n", - "documentDefault": true, + "defaultText": null, "value": "value", "experimentalFeature": null } @@ -190,7 +190,7 @@ namespace nix { "name-of-the-setting", "description", {}, - true, + "default-text", Xp::Flakes, }; setting.assign("value"); @@ -201,7 +201,7 @@ namespace nix { "aliases": [], "defaultValue": "", "description": "description\n", - "documentDefault": true, + "defaultText": "default-text", "value": "value", "experimentalFeature": "flakes" }