diff --git a/lib/types.nix b/lib/types.nix index e57ceafcbaa4e..dbbf0848d3474 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -1439,6 +1439,9 @@ let # Either value of type `t1` or `t2`. either = t1: t2: + let + isEitherOrSubmodule = t: t.name == "either" || t.name == "submodule"; + in mkOptionType rec { name = "either"; description = @@ -1520,6 +1523,32 @@ let t2 ]; }; + # We have to be really careful of recursively-defined types here. either is the type used + # to allow finitely-sized values for recursively-defined types, so we have to put limits + # on how we recurse when looking for submodules. To that end, we'll look for submodule + # children, and only recurse into either itself. This means `either str submodule` will + # work, and `either str (attrsOf submodule)` won't, but that's better than nothing. + getSubOptions = + prefix: + lib.recursiveUpdateUntil + ( + _: a: b: + lib.isOption a || lib.isOption b + ) + (optionalAttrs (isEitherOrSubmodule t2) (t2.getSubOptions prefix)) + (optionalAttrs (isEitherOrSubmodule t1) (t1.getSubOptions prefix)); + getSubModules = + let + t1sm = if isEitherOrSubmodule t1 then t1.getSubModules else null; + t2sm = if isEitherOrSubmodule t2 then t2.getSubModules else null; + in + if t1sm == null then t2sm else t1sm; + substSubModules = + m: + let + t1sm = if isEitherOrSubmodule t1 then t1.getSubModules else null; + in + if t1sm == null then either t1 (t2.substSubModules m) else either (t1.substSubModules m) t2; nestedTypes.left = t1; nestedTypes.right = t2; }; diff --git a/nixos/modules/programs/dconf.nix b/nixos/modules/programs/dconf.nix index 767a0bf9632f2..c8bd55a4ecb43 100644 --- a/nixos/modules/programs/dconf.nix +++ b/nixos/modules/programs/dconf.nix @@ -122,7 +122,7 @@ let type = attrs; default = { }; description = "An attrset used to generate dconf keyfile."; - example = literalExpression '' + example = lib.literalExpression '' with lib.gvariant; { "com/raggesilver/BlackBox" = { @@ -139,7 +139,7 @@ let A list of dconf keys to be lockdown. This doesn't take effect if `lockAll` is set. ''; - example = literalExpression '' + example = lib.literalExpression '' [ "/org/gnome/desktop/background/picture-uri" ] ''; }; diff --git a/nixos/modules/programs/pay-respects.nix b/nixos/modules/programs/pay-respects.nix index b8fc8e3749367..42ae360bdb41a 100644 --- a/nixos/modules/programs/pay-respects.nix +++ b/nixos/modules/programs/pay-respects.nix @@ -143,6 +143,7 @@ in }; locale = mkOption { default = toLower (replaceStrings [ "_" ] [ "-" ] (substring 0 5 config.i18n.defaultLocale)); + defaultText = literalExpression ''toLower (replaceStrings [ "_" ] [ "-" ] (substring 0 5 config.i18n.defaultLocale))''; example = "nl-be"; type = str; description = '' diff --git a/nixos/modules/services/backup/libvirtd-autosnapshot.nix b/nixos/modules/services/backup/libvirtd-autosnapshot.nix index 51412aa4f810b..d2b0a7e87c236 100644 --- a/nixos/modules/services/backup/libvirtd-autosnapshot.nix +++ b/nixos/modules/services/backup/libvirtd-autosnapshot.nix @@ -185,7 +185,7 @@ in default = null; description = '' Type of snapshot to create (internal or external). - If not specified, uses global snapshotType (${toString cfg.snapshotType}). + If not specified, uses global snapshotType. ''; }; keep = lib.mkOption { @@ -193,7 +193,7 @@ in default = null; description = '' Number of snapshots to keep for this VM. - If not specified, uses global keep (${toString cfg.keep}). + If not specified, uses global keep. ''; }; }; diff --git a/nixos/modules/services/mail/rspamd.nix b/nixos/modules/services/mail/rspamd.nix index 715376e24f883..fb750507d902f 100644 --- a/nixos/modules/services/mail/rspamd.nix +++ b/nixos/modules/services/mail/rspamd.nix @@ -33,11 +33,13 @@ let owner = mkOption { type = types.str; default = "${cfg.user}"; + defaultText = literalExpression "config.services.rspamd.user"; description = "Owner to set on unix socket"; }; group = mkOption { type = types.str; default = "${cfg.group}"; + defaultText = literalExpression "config.services.rspamd.group"; description = "Group to set on unix socket"; }; rawEntry = mkOption { diff --git a/nixos/modules/services/security/tor.nix b/nixos/modules/services/security/tor.nix index 1c2cc65862e6b..b8652f67b0f2c 100644 --- a/nixos/modules/services/security/tor.nix +++ b/nixos/modules/services/security/tor.nix @@ -91,6 +91,9 @@ let (enum [ "auto" ]) ]); default = null; + description = '' + Port number or "auto". + ''; }; optionPorts = optionName: @@ -114,6 +117,7 @@ let SessionGroup = lib.mkOption { type = nullOr int; default = null; + description = descriptionGeneric "SocksPort"; }; } // lib.genAttrs isolateFlags ( @@ -121,6 +125,7 @@ let lib.mkOption { type = types.bool; default = false; + description = descriptionGeneric "SocksPort"; } ); config = { @@ -183,6 +188,7 @@ let SessionGroup = lib.mkOption { type = nullOr int; default = null; + description = descriptionGeneric "SocksPort"; }; } // lib.genAttrs flags ( @@ -190,6 +196,7 @@ let lib.mkOption { type = types.bool; default = false; + description = descriptionGeneric "SocksPort"; } ); config = lib.mkIf doConfig { @@ -204,6 +211,7 @@ let optionFlags = lib.mkOption { type = with lib.types; listOf str; default = [ ]; + internal = true; }; optionORPort = optionName: @@ -239,6 +247,7 @@ let lib.mkOption { type = types.bool; default = false; + description = descriptionGeneric "ORPort"; } ); config = { @@ -727,7 +736,9 @@ in { ... }: { options = { - port = optionPort; + port = optionPort // { + description = "Virtual port number."; + }; target = lib.mkOption { default = null; type = nullOr ( @@ -737,11 +748,14 @@ in options = { unix = optionUnix; addr = optionAddress; - port = optionPort; + port = optionPort // { + description = "Port number."; # we shouldn't accept auto here + }; }; } ) ); + description = descriptionGeneric "HiddenServicePort"; }; }; } @@ -924,6 +938,7 @@ in lib.mkOption { type = types.bool; default = false; + description = descriptionGeneric "ControlPort"; } ); config = { diff --git a/nixos/modules/services/web-apps/movim.nix b/nixos/modules/services/web-apps/movim.nix index 766798dd06022..e1d3367276a96 100644 --- a/nixos/modules/services/web-apps/movim.nix +++ b/nixos/modules/services/web-apps/movim.nix @@ -295,11 +295,12 @@ in }; }; }; + description = "Script minification options"; }; style = mkOption { type = types.submodule { options = { - enable = mkEnableOption "Script minification via Lightning CSS"; + enable = mkEnableOption "Style minification via Lightning CSS"; target = mkOption { type = types.nullOr types.nonEmptyStr; default = null; @@ -311,6 +312,7 @@ in }; }; }; + description = "Style minification options"; }; svg = mkOption { type = types.submodule { @@ -318,6 +320,7 @@ in enable = mkEnableOption "SVG minification via Scour"; }; }; + description = "SVG minification options"; }; }; }