diff --git a/example/home.nix b/example/home.nix index 2f28e07a..9f8768d8 100644 --- a/example/home.nix +++ b/example/home.nix @@ -65,8 +65,7 @@ # configFile = { "baloofilerc"."Basic Settings"."Indexing-Enabled" = false; - # If a group name has dots you need to escape them - "kwinrc"."org\\.kde\\.kdecoration2"."ButtonsOnLeft" = "SF"; + "kwinrc"."org.kde.kdecoration2"."ButtonsOnLeft" = "SF"; }; }; } diff --git a/modules/files.nix b/modules/files.nix index 47d17e3c..335cc808 100644 --- a/modules/files.nix +++ b/modules/files.nix @@ -16,31 +16,38 @@ let (prependPath config.xdg.configHome plasmaCfg.configFile) // (prependPath config.xdg.dataHome plasmaCfg.dataFile); - ############################################################################## - # A module for storing settings. - settingType = { name, ... }: { - freeformType = with lib.types; - attrsOf (nullOr (oneOf [ bool float int str ])); + # Flatten nested sections + flatten = config: builtins.listToAttrs (lib.flatten (lib.mapAttrsToList + (n: v: + let + keySet = lib.filterAttrs (n: v: !builtins.isAttrs v) v; + sectionSet = flatten (lib.filterAttrs (n: v: builtins.isAttrs v) v); + in + lib.optionals (keySet != { }) [{ + name = n; + value = keySet; + }] ++ lib.mapAttrsToList + (group: v: { + name = "${n}][${group}"; + value = v; + }) + sectionSet) + config)); - options = { - configGroupNesting = lib.mkOption { - type = lib.types.nonEmptyListOf lib.types.str; - # We allow escaping periods using \\. - default = (map - (e: builtins.replaceStrings [ "\\u002E" ] [ "." ] e) - (lib.splitString "." - (builtins.replaceStrings [ "\\." ] [ "\\u002E" ] name) - ) - ); - description = "Group name, and sub-group names."; - }; - }; - }; + flatCfg = builtins.mapAttrs (file: flatten) cfg; + + ############################################################################## + # A type for storing settings. + settingsFileType = with lib.types; let + valueType = attrsOf (nullOr (oneOf [ bool float int str valueType ])) // + { description = "Plasma settings"; }; + in + attrsOf (attrsOf (valueType)); ############################################################################## # Generate a script that will use write_config.py to update all # settings. - script = pkgs.writeScript "plasma-config" (writeConfig cfg); + script = pkgs.writeScript "plasma-config" (writeConfig flatCfg); ############################################################################## # Generate a script that will remove all the current config files. @@ -98,7 +105,7 @@ in { options.programs.plasma = { file = lib.mkOption { - type = with lib.types; attrsOf (attrsOf (submodule settingType)); + type = settingsFileType; default = { }; description = '' An attribute set where the keys are file names (relative to @@ -107,7 +114,7 @@ in ''; }; configFile = lib.mkOption { - type = with lib.types; attrsOf (attrsOf (submodule settingType)); + type = settingsFileType; default = { }; description = '' An attribute set where the keys are file names (relative to @@ -116,7 +123,7 @@ in ''; }; dataFile = lib.mkOption { - type = with lib.types; attrsOf (attrsOf (submodule settingType)); + type = settingsFileType; default = { }; description = '' An attribute set where the keys are file names (relative to diff --git a/modules/kwin.nix b/modules/kwin.nix index 95e03732..9ebe58d9 100644 --- a/modules/kwin.nix +++ b/modules/kwin.nix @@ -74,7 +74,7 @@ in config = mkIf cfg.enable { # Titlebar buttons - programs.plasma.configFile."kwinrc"."org\\.kde\\.kdecoration2" = mkMerge [ + programs.plasma.configFile."kwinrc"."org.kde.kdecoration2" = mkMerge [ ( mkIf (cfg.kwin.titlebarButtons.left != null) { "ButtonsOnLeft" = strings.concatStrings (getShortNames cfg.kwin.titlebarButtons.left); diff --git a/modules/shortcuts.nix b/modules/shortcuts.nix index ff599852..0ad622b1 100644 --- a/modules/shortcuts.nix +++ b/modules/shortcuts.nix @@ -25,12 +25,7 @@ let shortcutsToSettings = groups: lib.mapAttrs - (group: attrs: - (lib.mapAttrs shortcutToNameValuePair attrs) // { - # Some shortcut groups have a dot in their name so we - # explicitly set the group nesting to only one level deep: - configGroupNesting = [ group ]; - }) + (group: attrs: (lib.mapAttrs shortcutToNameValuePair attrs)) groups; in { diff --git a/script/rc2nix.rb b/script/rc2nix.rb index 22d015b4..d97de637 100755 --- a/script/rc2nix.rb +++ b/script/rc2nix.rb @@ -144,8 +144,8 @@ def parse ############################################################################ def parse_group(line) line.gsub(/\s*\[([^\]]+)\]\s*/) do |match| - $1 + "." - end.sub(/\.$/, '') + $1 + "\".\"" + end.sub(/\"."$/, '') end end diff --git a/script/write_config.py b/script/write_config.py index b4dbb225..eab6b935 100644 --- a/script/write_config.py +++ b/script/write_config.py @@ -105,13 +105,8 @@ def key_value_to_line(key: str, value: str) -> str: def write_config_single(filepath: str, items: Dict): config = KConfParser(filepath) - for entry in items.values(): - group = f"{']['.join(entry['configGroupNesting'])}" - + for group, entry in items.items(): for key, value in entry.items(): - if key == "configGroupNesting": - continue - # If the nix expression is null, resulting in the value None here, # we remove the key/option (and the group/section if it is empty # after removal).