From 6ee48af3cf10421a52f2493674cf01a12766c951 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Mon, 29 Apr 2024 16:45:10 -0400 Subject: [PATCH] Add optional simplified configuration syntax (#144) * Also tweaked the CI a little bit. --------- Co-authored-by: magnouvean <85435692+magnouvean@users.noreply.github.com> --- .github/workflows/ci.yml | 4 +- examples/.gitignore | 1 + examples/home.nix | 4 +- examples/homeManager/home.nix | 4 +- examples/homeManagerFlake/flake.lock | 73 ---------------------------- examples/homeManagerFlake/flake.nix | 4 +- examples/systemFlake/flake.lock | 73 ---------------------------- examples/systemFlake/flake.nix | 4 +- flake.lock | 12 ++--- lib/types.nix | 3 ++ modules/apps/kate/default.nix | 18 +++---- modules/apps/konsole.nix | 2 +- modules/files.nix | 4 +- modules/fonts.nix | 41 ++++++++-------- modules/hotkeys.nix | 14 +++--- modules/kwin.nix | 18 +++---- modules/shortcuts.nix | 19 +++----- modules/windows.nix | 2 +- modules/workspace.nix | 4 +- script/rc2nix.rb | 2 +- test/basic.nix | 9 ++++ 21 files changed, 90 insertions(+), 225 deletions(-) create mode 100644 examples/.gitignore delete mode 100644 examples/homeManagerFlake/flake.lock delete mode 100644 examples/systemFlake/flake.lock diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c18188e..1fd529b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,5 +14,5 @@ jobs: with: extra_nix_config: "system-features = kvm nixos-test" - run: nix flake check -L --keep-going - - run: nix flake check -L --keep-going ./examples/homeManagerFlake - - run: nix flake check -L --keep-going ./examples/systemFlake + - run: nix flake check -L --keep-going --override-input plasma-manager . ./examples/homeManagerFlake + - run: nix flake check -L --keep-going --override-input plasma-manager . ./examples/systemFlake diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 0000000..aad2760 --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1 @@ +*/flake.lock diff --git a/examples/home.nix b/examples/home.nix index 2998f94..1c6d7c0 100644 --- a/examples/home.nix +++ b/examples/home.nix @@ -86,8 +86,8 @@ # Some low-level settings: # configFile = { - "baloofilerc"."Basic Settings"."Indexing-Enabled".value = false; - "kwinrc"."org.kde.kdecoration2"."ButtonsOnLeft".value = "SF"; + "baloofilerc"."Basic Settings"."Indexing-Enabled" = false; + "kwinrc"."org.kde.kdecoration2"."ButtonsOnLeft" = "SF"; "kwinrc"."Desktops"."Number" = { value = 8; # Forces kde to not change this value (even through the settings app). diff --git a/examples/homeManager/home.nix b/examples/homeManager/home.nix index bb450d2..ededc63 100644 --- a/examples/homeManager/home.nix +++ b/examples/homeManager/home.nix @@ -70,8 +70,8 @@ # Some low-level settings: # configFile = { - "baloofilerc"."Basic Settings"."Indexing-Enabled".value = false; - "kwinrc"."org.kde.kdecoration2"."ButtonsOnLeft".value = "SF"; + "baloofilerc"."Basic Settings"."Indexing-Enabled" = false; + "kwinrc"."org.kde.kdecoration2"."ButtonsOnLeft" = "SF"; "kwinrc"."Desktops"."Number" = { value = 8; # Forces kde to not change this value (even through the settings app). diff --git a/examples/homeManagerFlake/flake.lock b/examples/homeManagerFlake/flake.lock deleted file mode 100644 index 8b73a1b..0000000 --- a/examples/homeManagerFlake/flake.lock +++ /dev/null @@ -1,73 +0,0 @@ -{ - "nodes": { - "home-manager": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1710888565, - "narHash": "sha256-s9Hi4RHhc6yut4EcYD50sZWRDKsugBJHSbON8KFwoTw=", - "owner": "nix-community", - "repo": "home-manager", - "rev": "f33900124c23c4eca5831b9b5eb32ea5894375ce", - "type": "github" - }, - "original": { - "owner": "nix-community", - "ref": "release-23.11", - "repo": "home-manager", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1711668574, - "narHash": "sha256-u1dfs0ASQIEr1icTVrsKwg2xToIpn7ZXxW3RHfHxshg=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "219951b495fc2eac67b1456824cc1ec1fd2ee659", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-23.11", - "repo": "nixpkgs", - "type": "github" - } - }, - "plasma-manager": { - "inputs": { - "home-manager": [ - "home-manager" - ], - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1711880258, - "narHash": "sha256-4lcNTaKYxKXqAD+OrTC68T2W/Cr69VSogS+R5tjdn+M=", - "owner": "pjones", - "repo": "plasma-manager", - "rev": "22b423b9c6f157373d56413835d1d65ea4c5f481", - "type": "github" - }, - "original": { - "owner": "pjones", - "repo": "plasma-manager", - "type": "github" - } - }, - "root": { - "inputs": { - "home-manager": "home-manager", - "nixpkgs": "nixpkgs", - "plasma-manager": "plasma-manager" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/examples/homeManagerFlake/flake.nix b/examples/homeManagerFlake/flake.nix index ef97b91..563cfdf 100644 --- a/examples/homeManagerFlake/flake.nix +++ b/examples/homeManagerFlake/flake.nix @@ -2,9 +2,9 @@ description = "Plasma Manager Example with standalone home-manager flake"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; home-manager = { - url = "github:nix-community/home-manager/release-23.11"; + url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; plasma-manager = { diff --git a/examples/systemFlake/flake.lock b/examples/systemFlake/flake.lock deleted file mode 100644 index 8b73a1b..0000000 --- a/examples/systemFlake/flake.lock +++ /dev/null @@ -1,73 +0,0 @@ -{ - "nodes": { - "home-manager": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1710888565, - "narHash": "sha256-s9Hi4RHhc6yut4EcYD50sZWRDKsugBJHSbON8KFwoTw=", - "owner": "nix-community", - "repo": "home-manager", - "rev": "f33900124c23c4eca5831b9b5eb32ea5894375ce", - "type": "github" - }, - "original": { - "owner": "nix-community", - "ref": "release-23.11", - "repo": "home-manager", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1711668574, - "narHash": "sha256-u1dfs0ASQIEr1icTVrsKwg2xToIpn7ZXxW3RHfHxshg=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "219951b495fc2eac67b1456824cc1ec1fd2ee659", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-23.11", - "repo": "nixpkgs", - "type": "github" - } - }, - "plasma-manager": { - "inputs": { - "home-manager": [ - "home-manager" - ], - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1711880258, - "narHash": "sha256-4lcNTaKYxKXqAD+OrTC68T2W/Cr69VSogS+R5tjdn+M=", - "owner": "pjones", - "repo": "plasma-manager", - "rev": "22b423b9c6f157373d56413835d1d65ea4c5f481", - "type": "github" - }, - "original": { - "owner": "pjones", - "repo": "plasma-manager", - "type": "github" - } - }, - "root": { - "inputs": { - "home-manager": "home-manager", - "nixpkgs": "nixpkgs", - "plasma-manager": "plasma-manager" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/examples/systemFlake/flake.nix b/examples/systemFlake/flake.nix index 4727600..f1008e3 100644 --- a/examples/systemFlake/flake.nix +++ b/examples/systemFlake/flake.nix @@ -2,9 +2,9 @@ description = "Plasma Manager Example with system configuration flake"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; home-manager = { - url = "github:nix-community/home-manager/release-23.11"; + url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; plasma-manager = { diff --git a/flake.lock b/flake.lock index 557821d..426b065 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1713789879, - "narHash": "sha256-4Wt3Bg6uOnvwZcECBZaFEdzlWRlGLgd8DqLL4ugLdxg=", + "lastModified": 1714377222, + "narHash": "sha256-UsDsjWCKlWn8vbXi8Zza9Hkq3xyk8fpvFNo2VM5S74E=", "owner": "nix-community", "repo": "home-manager", - "rev": "46833c3115e8858370880d892748f0927d8193c3", + "rev": "2af7c78b7bb9cf18406a193eba13ef9f99388f49", "type": "github" }, "original": { @@ -22,11 +22,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1713714899, - "narHash": "sha256-+z/XjO3QJs5rLE5UOf015gdVauVRQd2vZtsFkaXBq2Y=", + "lastModified": 1714253743, + "narHash": "sha256-mdTQw2XlariysyScCv2tTE45QSU9v/ezLcHJ22f0Nxc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "6143fc5eeb9c4f00163267708e26191d1e918932", + "rev": "58a1abdbae3217ca6b702f03d3b35125d88a2994", "type": "github" }, "original": { diff --git a/lib/types.nix b/lib/types.nix index 8853338..67f3c4f 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -37,8 +37,11 @@ let }; }; }); + coercedSettingsType = with lib.types; + coercedTo basicSettingsType (value: { inherit value; }) advancedSettingsType; in { inherit basicSettingsType; inherit advancedSettingsType; + inherit coercedSettingsType; } diff --git a/modules/apps/kate/default.nix b/modules/apps/kate/default.nix index 8054090..468906b 100644 --- a/modules/apps/kate/default.nix +++ b/modules/apps/kate/default.nix @@ -114,23 +114,23 @@ in config.programs.plasma.configFile."katerc" = lib.mkIf cfg.enable { "KTextEditor Document" = { - "Auto Detect Indent".value = cfg.editor.indent.autodetect; - "Indentation Width".value = cfg.editor.indent.width; - "Tab Handling".value = (tabHandlingMode cfg.editor.indent); - "Tab Width".value = cfg.editor.tabWidth; - "Keep Extra Spaces".value = cfg.editor.indent.keepExtraSpaces; - "ReplaceTabsDyn".value = cfg.editor.indent.replaceWithSpaces; + "Auto Detect Indent" = cfg.editor.indent.autodetect; + "Indentation Width" = cfg.editor.indent.width; + "Tab Handling" = (tabHandlingMode cfg.editor.indent); + "Tab Width" = cfg.editor.tabWidth; + "Keep Extra Spaces" = cfg.editor.indent.keepExtraSpaces; + "ReplaceTabsDyn" = cfg.editor.indent.replaceWithSpaces; }; "KTextEditor Renderer" = { - "Show Indentation Lines".value = cfg.editor.indent.showLines; + "Show Indentation Lines" = cfg.editor.indent.showLines; # COLORTHEME (cannot define this below) # Do pick the theme if the user chose one, # Do not touch the theme settings otherwise - "Auto Color Theme Selection".value = lib.mkIf (cfg.editor.theme.name != "") false; - "Color Theme".value = lib.mkIf (cfg.editor.theme.name != "") cfg.editor.theme.name; + "Auto Color Theme Selection" = lib.mkIf (cfg.editor.theme.name != "") false; + "Color Theme" = lib.mkIf (cfg.editor.theme.name != "") cfg.editor.theme.name; }; }; diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix index 60068a4..7ffbc09 100644 --- a/modules/apps/konsole.nix +++ b/modules/apps/konsole.nix @@ -97,7 +97,7 @@ in programs.plasma.configFile."konsolerc" = lib.mkMerge [ ( lib.mkIf (cfg.defaultProfile != null) { - "Desktop Entry"."DefaultProfile".value = "${cfg.defaultProfile}.profile"; + "Desktop Entry"."DefaultProfile" = "${cfg.defaultProfile}.profile"; } ) ( diff --git a/modules/files.nix b/modules/files.nix index 211100a..3fb72e1 100644 --- a/modules/files.nix +++ b/modules/files.nix @@ -3,7 +3,7 @@ let inherit (import ../lib/writeconfig.nix { inherit lib pkgs config; }) writeConfig; - inherit (import ../lib/types.nix { inherit lib; }) advancedSettingsType; + inherit (import ../lib/types.nix { inherit lib; }) coercedSettingsType; # Helper function to prepend the appropriate path prefix (e.g. XDG_CONFIG_HOME) to file prependPath = prefix: attrset: @@ -16,7 +16,7 @@ let (prependPath config.xdg.configHome plasmaCfg.configFile) // (prependPath config.xdg.dataHome plasmaCfg.dataFile); - fileSettingsType = with lib.types; attrsOf (attrsOf (attrsOf advancedSettingsType)); + fileSettingsType = with lib.types; attrsOf (attrsOf (attrsOf coercedSettingsType)); ############################################################################## # Generate a script that will use write_config.py to update all diff --git a/modules/fonts.nix b/modules/fonts.nix index 89a667f..d63d6fb 100644 --- a/modules/fonts.nix +++ b/modules/fonts.nix @@ -1,10 +1,10 @@ -{ - lib, - config, - ... -}: let +{ lib +, config +, ... +}: +let inherit (lib) mkIf mkOption types; - qfont = import ../lib/qfont.nix {inherit lib;}; + qfont = import ../lib/qfont.nix { inherit lib; }; styleStrategyType = types.submodule { options = with qfont.styleStrategy; { @@ -180,7 +180,7 @@ }; styleStrategy = mkOption { type = styleStrategyType; - default = {}; + default = { }; description = '' The strategy for matching similar fonts to this font. @@ -200,7 +200,8 @@ inherit (config.programs.plasma) enable; cfg = lib.filterAttrs (_: v: v != null) config.programs.plasma.fonts; -in { +in +{ options.programs.plasma.fonts = { general = mkOption { type = types.nullOr fontType; @@ -270,16 +271,18 @@ in { }; }; - config.programs.plasma.configFile.kdeglobals = let - mkFont = f: mkIf (enable && builtins.hasAttr f cfg) (qfont.fontToString cfg.${f}); - in { - General = { - font.value = mkFont "general"; - fixed.value = mkFont "fixedWidth"; - smallestReadableFont.value = mkFont "small"; - toolBarFont.value = mkFont "toolbar"; - menuFont.value = mkFont "menu"; + config.programs.plasma.configFile.kdeglobals = + let + mkFont = f: mkIf (enable && builtins.hasAttr f cfg) (qfont.fontToString cfg.${f}); + in + { + General = { + font = mkFont "general"; + fixed = mkFont "fixedWidth"; + smallestReadableFont = mkFont "small"; + toolBarFont = mkFont "toolbar"; + menuFont = mkFont "menu"; + }; + WM.activeFont = mkFont "windowTitle"; }; - WM.activeFont.value = mkFont "windowTitle"; - }; } diff --git a/modules/hotkeys.nix b/modules/hotkeys.nix index 2ddd3bc..976772b 100644 --- a/modules/hotkeys.nix +++ b/modules/hotkeys.nix @@ -94,19 +94,17 @@ in }; programs.plasma.configFile."kglobalshortcutsrc"."${group.desktop}" = { - _k_friendly_name.value = group.description; + _k_friendly_name = group.description; } // lib.mapAttrs (_: command: let keys = command.keys ++ lib.optionals (command.key != "") [ command.key ]; in - { - value = lib.concatStringsSep "," [ - (lib.concatStringsSep "\t" (map (lib.escape [ "," ]) keys)) - "" # List of default keys, not needed. - command.comment - ]; - }) + lib.concatStringsSep "," [ + (lib.concatStringsSep "\t" (map (lib.escape [ "," ]) keys)) + "" # List of default keys, not needed. + command.comment + ]) cfg.hotkeys.commands; }; } diff --git a/modules/kwin.nix b/modules/kwin.nix index 44f30a1..a39d926 100644 --- a/modules/kwin.nix +++ b/modules/kwin.nix @@ -54,7 +54,7 @@ let virtualDesktopNameAttrs = names: builtins.listToAttrs - (imap1 (i: v: (nameValuePair "Name_${builtins.toString i}" { value = v; })) names); + (imap1 (i: v: (nameValuePair "Name_${builtins.toString i}" v)) names); in { options.programs.plasma.kwin = { @@ -142,37 +142,37 @@ in # Titlebar buttons ( mkIf (cfg.kwin.titlebarButtons.left != null) { - "org.kde.kdecoration2".ButtonsOnLeft.value = strings.concatStrings (getShortNames cfg.kwin.titlebarButtons.left); + "org.kde.kdecoration2".ButtonsOnLeft = strings.concatStrings (getShortNames cfg.kwin.titlebarButtons.left); } ) ( mkIf (cfg.kwin.titlebarButtons.right != null) { - "org.kde.kdecoration2".ButtonsOnRight.value = strings.concatStrings (getShortNames cfg.kwin.titlebarButtons.right); + "org.kde.kdecoration2".ButtonsOnRight = strings.concatStrings (getShortNames cfg.kwin.titlebarButtons.right); } ) # Effects ( mkIf (cfg.kwin.effects.shakeCursor.enable != null) { - Plugins.shakecursorEnabled.value = cfg.kwin.effects.shakeCursor.enable; + Plugins.shakecursorEnabled = cfg.kwin.effects.shakeCursor.enable; } ) # Virtual Desktops (mkIf (cfg.kwin.virtualDesktops.animation != null) { - Plugins.slideEnabled.value = cfg.kwin.virtualDesktops.animation == "slide"; - Plugins.fadedesktopEnabled.value = cfg.kwin.virtualDesktops.animation == "fade"; + Plugins.slideEnabled = cfg.kwin.virtualDesktops.animation == "slide"; + Plugins.fadedesktopEnabled = cfg.kwin.virtualDesktops.animation == "fade"; }) (mkIf (cfg.kwin.virtualDesktops.number != null) { - Desktops.Number.value = cfg.kwin.virtualDesktops.number; + Desktops.Number = cfg.kwin.virtualDesktops.number; }) (mkIf (cfg.kwin.virtualDesktops.rows != null) { - Desktops.Rows.value = cfg.kwin.virtualDesktops.rows; + Desktops.Rows = cfg.kwin.virtualDesktops.rows; }) (mkIf (cfg.kwin.virtualDesktops.names != null) { Desktops = mkMerge [ { - Number.value = builtins.length cfg.kwin.virtualDesktops.names; + Number = builtins.length cfg.kwin.virtualDesktops.names; } (virtualDesktopNameAttrs cfg.kwin.virtualDesktops.names) ]; diff --git a/modules/shortcuts.nix b/modules/shortcuts.nix index f636102..d9077f5 100644 --- a/modules/shortcuts.nix +++ b/modules/shortcuts.nix @@ -26,17 +26,14 @@ let escape = lib.escape [ "," ]; keysStr = (if ((builtins.length keys) == 1) then (escape (builtins.head keys)) else "\t" + (lib.concatStringsSep "\t" (map escape keys))); in - { - value = - if (isService group) then - keysStr - else - (lib.concatStringsSep "," [ - keysStr - "" # List of default keys, not needed. - "" # Display string, not needed. - ]); - }; + (if (isService group) then + keysStr + else + (lib.concatStringsSep "," [ + keysStr + "" # List of default keys, not needed. + "" # Display string, not needed. + ])); shortcutsToSettings = groups: lib.mapAttrs diff --git a/modules/windows.nix b/modules/windows.nix index 02cdcc8..e4a5346 100644 --- a/modules/windows.nix +++ b/modules/windows.nix @@ -19,7 +19,7 @@ in config = lib.mkIf cfg.enable { programs.plasma.configFile = { kdeglobals = { - General.AllowKDEAppsToRememberWindowPositions.value = + General.AllowKDEAppsToRememberWindowPositions = lib.mkDefault cfg.windows.allowWindowsToRememberPositions; }; }; diff --git a/modules/workspace.nix b/modules/workspace.nix index 0910833..f837f2d 100644 --- a/modules/workspace.nix +++ b/modules/workspace.nix @@ -139,12 +139,12 @@ in } { programs.plasma.configFile.kdeglobals = { - KDE.SingleClick.value = lib.mkDefault (cfg.workspace.clickItemTo == "open"); + KDE.SingleClick = lib.mkDefault (cfg.workspace.clickItemTo == "open"); }; } (lib.mkIf (cfg.workspace.tooltipDelay > 0) { programs.plasma.configFile.plasmarc = { - PlasmaToolTips.Delay.value = cfg.workspace.tooltipDelay; + PlasmaToolTips.Delay = cfg.workspace.tooltipDelay; }; }) (lib.mkIf diff --git a/script/rc2nix.rb b/script/rc2nix.rb index 76cff06..54ae4cd 100755 --- a/script/rc2nix.rb +++ b/script/rc2nix.rb @@ -206,7 +206,7 @@ module Rc2Nix print(" " * indent) print("\"#{file}\".") print("\"#{group}\".") - print("\"#{key}\".value = ") + print("\"#{key}\" = ") print(nix_val(settings[file][group][key])) print(";\n") end diff --git a/test/basic.nix b/test/basic.nix index 4c5b8cc..616be9e 100644 --- a/test/basic.nix +++ b/test/basic.nix @@ -21,6 +21,8 @@ let assert_eq KDE SingleClick false assert_eq General AllowKDEAppsToRememberWindowPositions true + assert_eq group key1 1 + assert_eq group key2 2 ''; in testers.nixosTest { @@ -41,6 +43,13 @@ testers.nixosTest { programs.plasma = { enable = true; workspace.clickItemTo = "select"; + configFile.kdeglobals.group = { + key1 = 1; + key2 = { + value = 2; + immutable = true; + }; + }; }; }; };