diff --git a/modules/lib/generators.nix b/modules/lib/generators.nix index 2aebd92c..1316445d 100644 --- a/modules/lib/generators.nix +++ b/modules/lib/generators.nix @@ -1,6 +1,35 @@ { lib }: { + toSwayConf = { outerBlock ? true, indent ? "", indentSpace ? " " }@args: + v: + let + outroSpace = "\n" + lib.strings.removeSuffix indentSpace indent; + outro = outroSpace + lib.optionalString (!outerBlock) "}"; + intro = lib.optionalString (!outerBlock) '' + { + '' + indent; + + innerArgs = args // { + outerBlock = false; + indent = indent + indentSpace; + }; + genInner = key: value: + builtins.toString key + indentSpace + + lib.hm.generators.toSwayConf innerArgs value; + concatItems = lib.concatStringsSep '' + + ${indent}''; + in if lib.isInt v || lib.isFloat v || lib.isString v then + (builtins.toString v) + else if lib.isAttrs v then + (if v == { } then + abort "toSwayConfig: empty attribute set is unsupported" + else + intro + concatItems (lib.mapAttrsToList genInner v) + outro) + else + (abort "toSwayConfig: type ${builtins.typeOf v} is unsupported"); + toHyprconf = { attrs, indentLevel ? 0, importantPrefixes ? [ "$" ], }: let inherit (lib)