toKeyValue
lib.generators.toKeyValue
Docs pulled from | This Revision | about 1 hour ago
Generate a key-value-style config file from an attrset.
Inputs
- Structured function argument
-
- mkKeyValue (optional, default:
mkKeyValueDefault {} "="
) - format a setting line from key and value
- mkKeyValue (optional, default:
-
- listsAsDuplicateKeys (optional, default:
false
) - allow lists as values for duplicate keys
- listsAsDuplicateKeys (optional, default:
-
- indent (optional, default:
""
) - Initial indentation level
- indent (optional, default:
Noogle detected
Implementation
The following is the current implementation of this function.
toKeyValue = {
mkKeyValue ? mkKeyValueDefault {} "=",
listsAsDuplicateKeys ? false,
indent ? ""
}:
let mkLine = k: v: indent + mkKeyValue k v + "\n";
mkLines = if listsAsDuplicateKeys
then k: v: map (mkLine k) (if isList v then v else [v])
else k: v: [ (mkLine k v) ];
in attrs: concatStrings (concatLists (mapAttrsToList mkLines attrs));