Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nixos/doc/manual/development/settings-options.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/mail/public-inbox.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
32 changes: 19 additions & 13 deletions pkgs/pkgs-lib/formats.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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"])
{
Expand All @@ -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;

Expand Down