···17171818rec {
19192020- /* Generates an INI-style config file from an
2020+ /* Generate a line of key k and value v, separated by
2121+ * character sep. If sep appears in k, it is escaped.
2222+ * Helper for synaxes with different separators.
2323+ *
2424+ * mkKeyValueLine ":" "f:oo" "bar"
2525+ * > "f\:oo:bar"
2626+ */
2727+ mkKeyValueLine = sep: k: v:
2828+ "${libStr.escape [sep] k}${sep}${toString v}";
2929+3030+3131+ /* Generate a key-value-style config file from an attrset.
3232+ *
3333+ * mkKeyValue is the same as in toINI.
3434+ */
3535+ toKeyValue = {
3636+ mkKeyValue ? mkKeyValueLine "="
3737+ }: attrs:
3838+ let mkLine = k: v: mkKeyValue k v + "\n";
3939+ in libStr.concatStrings (libAttr.mapAttrsToList mkLine attrs);
4040+4141+4242+ /* Generate an INI-style config file from an
2143 * attrset of sections to an attrset of key-value pairs.
2244 *
2345 * generators.toINI {} {
···4163 # apply transformations (e.g. escapes) to section names
4264 mkSectionName ? (name: libStr.escape [ "[" "]" ] name),
4365 # format a setting line from key and value
4444- mkKeyValue ? (k: v: "${libStr.escape ["="] k}=${toString v}")
6666+ mkKeyValue ? mkKeyValueLine "="
4567 }: attrsOfAttrs:
4668 let
4769 # map function to string for each key val
4870 mapAttrsToStringsSep = sep: mapFn: attrs:
4971 libStr.concatStringsSep sep
5072 (libAttr.mapAttrsToList mapFn attrs);
5151- mkLine = k: v: mkKeyValue k v + "\n";
5273 mkSection = sectName: sectValues: ''
5374 [${mkSectionName sectName}]
5454- '' + libStr.concatStrings (libAttr.mapAttrsToList mkLine sectValues);
7575+ '' + toKeyValue { inherit mkKeyValue; } sectValues;
5576 in
5677 # map input to ini sections
5778 mapAttrsToStringsSep "\n" mkSection attrsOfAttrs;