mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-23 23:43:30 +00:00
formats.ini: expose INI atom from all ini formats (#354800)
This commit is contained in:
commit
555f0e9f1e
@ -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)
|
||||
|
@ -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";
|
||||
|
@ -124,9 +124,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;
|
||||
@ -145,12 +145,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
|
||||
@ -175,24 +177,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"])
|
||||
{
|
||||
@ -201,17 +205,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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user