diff --git a/nixos/doc/manual/development/settings-options.section.md b/nixos/doc/manual/development/settings-options.section.md index 48cc62bb424c..b37cd1d34525 100644 --- a/nixos/doc/manual/development/settings-options.section.md +++ b/nixos/doc/manual/development/settings-options.section.md @@ -312,6 +312,8 @@ have a predefined type and string generator already declared under may be transformed into multiple key-value pairs depending on `listToValue`). + The attribute `lib.type.atom` contains the used INI atom. + `pkgs.formats.iniWithGlobalSection` { *`listsAsDuplicateKeys`* ? false, *`listToValue`* ? null, \.\.\. } : A function taking an attribute set with values @@ -333,6 +335,8 @@ have a predefined type and string generator already declared under attrset of key-value pairs for a single section, the global section which preceedes the section definitions. + The attribute `lib.type.atom` contains the used INI atom. + `pkgs.formats.toml` { } : A function taking an empty attribute set (for future extensibility) diff --git a/nixos/modules/services/mail/public-inbox.nix b/nixos/modules/services/mail/public-inbox.nix index 98063e0331bd..1f7c8c44ace1 100644 --- a/nixos/modules/services/mail/public-inbox.nix +++ b/nixos/modules/services/mail/public-inbox.nix @@ -7,7 +7,7 @@ let stateDir = "/var/lib/public-inbox"; gitIni = pkgs.formats.gitIni { listsAsDuplicateKeys = true; }; - iniAtom = elemAt gitIni.type/*attrsOf*/.functor.wrapped/*attrsOf*/.functor.wrapped/*either*/.functor.wrapped 0; + iniAtom = gitIni.lib.types.atom; useSpamAssassin = cfg.settings.publicinboxmda.spamcheck == "spamc" || cfg.settings.publicinboxwatch.spamcheck == "spamc"; diff --git a/pkgs/pkgs-lib/formats.nix b/pkgs/pkgs-lib/formats.nix index 03663ad96b97..1a8df5ff380b 100644 --- a/pkgs/pkgs-lib/formats.nix +++ b/pkgs/pkgs-lib/formats.nix @@ -123,9 +123,9 @@ rec { } else singleIniAtom; - iniSection = { listsAsDuplicateKeys, listToValue, atomsCoercedToLists }@args: - attrsOf (iniAtom args) // { - description = "section of an INI file (attrs of " + (iniAtom args).description + ")"; + iniSection = atom: + attrsOf atom // { + description = "section of an INI file (attrs of " + atom.description + ")"; }; maybeToList = listToValue: if listToValue != null then lib.mapAttrs (key: val: if lib.isList val then listToValue val else val) else lib.id; @@ -144,12 +144,14 @@ rec { assert atomsCoercedToLists != null -> (listsAsDuplicateKeys || listToValue != null); let atomsCoercedToLists' = if atomsCoercedToLists == null then false else atomsCoercedToLists; + atom = iniAtom { inherit listsAsDuplicateKeys listToValue; atomsCoercedToLists = atomsCoercedToLists'; }; in { type = lib.types.attrsOf ( - iniSection { inherit listsAsDuplicateKeys listToValue; atomsCoercedToLists = atomsCoercedToLists'; } + iniSection atom ); + lib.types.atom = atom; generate = name: value: lib.pipe value @@ -174,24 +176,26 @@ rec { assert atomsCoercedToLists != null -> (listsAsDuplicateKeys || listToValue != null); let atomsCoercedToLists' = if atomsCoercedToLists == null then false else atomsCoercedToLists; + atom = iniAtom { inherit listsAsDuplicateKeys listToValue; atomsCoercedToLists = atomsCoercedToLists'; }; in { type = lib.types.submodule { options = { sections = lib.mkOption rec { type = lib.types.attrsOf ( - iniSection { inherit listsAsDuplicateKeys listToValue; atomsCoercedToLists = atomsCoercedToLists'; } + iniSection atom ); default = {}; description = type.description; }; globalSection = lib.mkOption rec { - type = iniSection { inherit listsAsDuplicateKeys listToValue; atomsCoercedToLists = atomsCoercedToLists'; }; + type = iniSection atom; default = {}; description = "global " + type.description; }; }; }; + lib.types.atom = atom; generate = name: { sections ? {}, globalSection ? {}, ... }: pkgs.writeText name (lib.generators.toINIWithGlobalSection (removeAttrs args ["listToValue" "atomsCoercedToLists"]) { @@ -200,17 +204,19 @@ rec { }); }; - gitIni = { listsAsDuplicateKeys ? false, ... }@args: { - type = let + gitIni = { listsAsDuplicateKeys ? false, ... }@args: + let atom = iniAtom { - listsAsDuplicateKeys = listsAsDuplicateKeys; + inherit listsAsDuplicateKeys; listToValue = null; atomsCoercedToLists = false; }; - in attrsOf (attrsOf (either atom (attrsOf atom))); - - generate = name: value: pkgs.writeText name (lib.generators.toGitINI value); - }; + in + { + type = attrsOf (attrsOf (either atom (attrsOf atom))); + lib.types.atom = atom; + generate = name: value: pkgs.writeText name (lib.generators.toGitINI value); + }; }) ini iniWithGlobalSection gitIni;