query
On this page

toKeyValue

lib.generators.toKeyValue

Docs pulled from | This Revision | about 2 hours 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
listsAsDuplicateKeys (optional, default: false)
allow lists as values for duplicate keys
indent (optional, default: "")
Initial indentation level

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));