lib/generators/toKeyValue: add indent parameter

toKeyValue is generic enough that it is sometimes used as part of other
format generators, where it might be useful to specify the indentation
level.
This commit is contained in:
Naïm Favier 2023-07-22 13:49:30 +02:00
parent 4b7ad2c7ea
commit 383fa81e6f
No known key found for this signature in database
GPG key ID: 95AFCE8211908325

View file

@ -81,9 +81,10 @@ rec {
*/
toKeyValue = {
mkKeyValue ? mkKeyValueDefault {} "=",
listsAsDuplicateKeys ? false
listsAsDuplicateKeys ? false,
indent ? ""
}:
let mkLine = k: v: mkKeyValue k v + "\n";
let mkLine = k: v: indent + mkKeyValue k v + "\n";
mkLines = if listsAsDuplicateKeys
then k: v: map (mkLine k) (if lib.isList v then v else [v])
else k: v: [ (mkLine k v) ];