···50 </varlistentry>
51 <varlistentry>
52 <term>
53- <varname>pkgs.formats.ini</varname> { <replaceable>listsAsDuplicateKeys</replaceable> ? false, ... }
54 </term>
55 <listitem>
56 <para>
···63 <listitem>
64 <para>
65 A boolean for controlling whether list values can be used to represent duplicate INI keys
000000000066 </para>
67 </listitem>
68 </varlistentry>
···50 </varlistentry>
51 <varlistentry>
52 <term>
53+ <varname>pkgs.formats.ini</varname> { <replaceable>listsAsDuplicateKeys</replaceable> ? false, <replaceable>listToValue</replaceable> ? null, ... }
54 </term>
55 <listitem>
56 <para>
···63 <listitem>
64 <para>
65 A boolean for controlling whether list values can be used to represent duplicate INI keys
66+ </para>
67+ </listitem>
68+ </varlistentry>
69+ <varlistentry>
70+ <term>
71+ <varname>listToValue</varname>
72+ </term>
73+ <listitem>
74+ <para>
75+ A function for turning a list of values into a single value.
76 </para>
77 </listitem>
78 </varlistentry>
+24-2
pkgs/pkgs-lib/formats.nix
···56 };
57 };
5859- ini = { listsAsDuplicateKeys ? false, ... }@args: {
0000000006061 type = with lib.types; let
62···74 coercedTo singleIniAtom lib.singleton (listOf singleIniAtom) // {
75 description = singleIniAtom.description + " or a list of them for duplicate keys";
76 }
000077 else
78 singleIniAtom;
7980 in attrsOf (attrsOf iniAtom);
8182- generate = name: value: pkgs.writeText name (lib.generators.toINI args value);
0000000008384 };
85
···56 };
57 };
5859+ ini = {
60+ # Represents lists as duplicate keys
61+ listsAsDuplicateKeys ? false,
62+ # Alternative to listsAsDuplicateKeys, converts list to non-list
63+ # listToValue :: [IniAtom] -> IniAtom
64+ listToValue ? null,
65+ ...
66+ }@args:
67+ assert !listsAsDuplicateKeys || listToValue == null;
68+ {
6970 type = with lib.types; let
71···83 coercedTo singleIniAtom lib.singleton (listOf singleIniAtom) // {
84 description = singleIniAtom.description + " or a list of them for duplicate keys";
85 }
86+ else if listToValue != null then
87+ coercedTo singleIniAtom lib.singleton (nonEmptyListOf singleIniAtom) // {
88+ description = singleIniAtom.description + " or a non-empty list of them";
89+ }
90 else
91 singleIniAtom;
9293 in attrsOf (attrsOf iniAtom);
9495+ generate = name: value:
96+ let
97+ transformedValue =
98+ if listToValue != null
99+ then
100+ lib.mapAttrs (section: lib.mapAttrs (key: val:
101+ if lib.isList val then listToValue val else val
102+ )) value
103+ else value;
104+ in pkgs.writeText name (lib.generators.toINI (removeAttrs args ["listToValue"]) transformedValue);
105106 };
107