Add optional simplified configuration syntax (#144)

* Also tweaked the CI a little bit.

---------

Co-authored-by: magnouvean <85435692+magnouvean@users.noreply.github.com>
This commit is contained in:
Quentin Smith 2024-04-29 16:45:10 -04:00 committed by GitHub
parent 60b9bc166d
commit 6ee48af3cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 90 additions and 225 deletions

View File

@ -14,5 +14,5 @@ jobs:
with: with:
extra_nix_config: "system-features = kvm nixos-test" extra_nix_config: "system-features = kvm nixos-test"
- run: nix flake check -L --keep-going - run: nix flake check -L --keep-going
- run: nix flake check -L --keep-going ./examples/homeManagerFlake - run: nix flake check -L --keep-going --override-input plasma-manager . ./examples/homeManagerFlake
- run: nix flake check -L --keep-going ./examples/systemFlake - run: nix flake check -L --keep-going --override-input plasma-manager . ./examples/systemFlake

1
examples/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*/flake.lock

View File

@ -86,8 +86,8 @@
# Some low-level settings: # Some low-level settings:
# #
configFile = { configFile = {
"baloofilerc"."Basic Settings"."Indexing-Enabled".value = false; "baloofilerc"."Basic Settings"."Indexing-Enabled" = false;
"kwinrc"."org.kde.kdecoration2"."ButtonsOnLeft".value = "SF"; "kwinrc"."org.kde.kdecoration2"."ButtonsOnLeft" = "SF";
"kwinrc"."Desktops"."Number" = { "kwinrc"."Desktops"."Number" = {
value = 8; value = 8;
# Forces kde to not change this value (even through the settings app). # Forces kde to not change this value (even through the settings app).

View File

@ -70,8 +70,8 @@
# Some low-level settings: # Some low-level settings:
# #
configFile = { configFile = {
"baloofilerc"."Basic Settings"."Indexing-Enabled".value = false; "baloofilerc"."Basic Settings"."Indexing-Enabled" = false;
"kwinrc"."org.kde.kdecoration2"."ButtonsOnLeft".value = "SF"; "kwinrc"."org.kde.kdecoration2"."ButtonsOnLeft" = "SF";
"kwinrc"."Desktops"."Number" = { "kwinrc"."Desktops"."Number" = {
value = 8; value = 8;
# Forces kde to not change this value (even through the settings app). # Forces kde to not change this value (even through the settings app).

View File

@ -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
}

View File

@ -2,9 +2,9 @@
description = "Plasma Manager Example with standalone home-manager flake"; description = "Plasma Manager Example with standalone home-manager flake";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = { home-manager = {
url = "github:nix-community/home-manager/release-23.11"; url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
plasma-manager = { plasma-manager = {

View File

@ -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
}

View File

@ -2,9 +2,9 @@
description = "Plasma Manager Example with system configuration flake"; description = "Plasma Manager Example with system configuration flake";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = { home-manager = {
url = "github:nix-community/home-manager/release-23.11"; url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
plasma-manager = { plasma-manager = {

View File

@ -7,11 +7,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1713789879, "lastModified": 1714377222,
"narHash": "sha256-4Wt3Bg6uOnvwZcECBZaFEdzlWRlGLgd8DqLL4ugLdxg=", "narHash": "sha256-UsDsjWCKlWn8vbXi8Zza9Hkq3xyk8fpvFNo2VM5S74E=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "46833c3115e8858370880d892748f0927d8193c3", "rev": "2af7c78b7bb9cf18406a193eba13ef9f99388f49",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -22,11 +22,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1713714899, "lastModified": 1714253743,
"narHash": "sha256-+z/XjO3QJs5rLE5UOf015gdVauVRQd2vZtsFkaXBq2Y=", "narHash": "sha256-mdTQw2XlariysyScCv2tTE45QSU9v/ezLcHJ22f0Nxc=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "6143fc5eeb9c4f00163267708e26191d1e918932", "rev": "58a1abdbae3217ca6b702f03d3b35125d88a2994",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -37,8 +37,11 @@ let
}; };
}; };
}); });
coercedSettingsType = with lib.types;
coercedTo basicSettingsType (value: { inherit value; }) advancedSettingsType;
in in
{ {
inherit basicSettingsType; inherit basicSettingsType;
inherit advancedSettingsType; inherit advancedSettingsType;
inherit coercedSettingsType;
} }

View File

@ -114,23 +114,23 @@ in
config.programs.plasma.configFile."katerc" = lib.mkIf cfg.enable { config.programs.plasma.configFile."katerc" = lib.mkIf cfg.enable {
"KTextEditor Document" = { "KTextEditor Document" = {
"Auto Detect Indent".value = cfg.editor.indent.autodetect; "Auto Detect Indent" = cfg.editor.indent.autodetect;
"Indentation Width".value = cfg.editor.indent.width; "Indentation Width" = cfg.editor.indent.width;
"Tab Handling".value = (tabHandlingMode cfg.editor.indent); "Tab Handling" = (tabHandlingMode cfg.editor.indent);
"Tab Width".value = cfg.editor.tabWidth; "Tab Width" = cfg.editor.tabWidth;
"Keep Extra Spaces".value = cfg.editor.indent.keepExtraSpaces; "Keep Extra Spaces" = cfg.editor.indent.keepExtraSpaces;
"ReplaceTabsDyn".value = cfg.editor.indent.replaceWithSpaces; "ReplaceTabsDyn" = cfg.editor.indent.replaceWithSpaces;
}; };
"KTextEditor Renderer" = { "KTextEditor Renderer" = {
"Show Indentation Lines".value = cfg.editor.indent.showLines; "Show Indentation Lines" = cfg.editor.indent.showLines;
# COLORTHEME (cannot define this below) # COLORTHEME (cannot define this below)
# Do pick the theme if the user chose one, # Do pick the theme if the user chose one,
# Do not touch the theme settings otherwise # Do not touch the theme settings otherwise
"Auto Color Theme Selection".value = lib.mkIf (cfg.editor.theme.name != "") false; "Auto Color Theme Selection" = lib.mkIf (cfg.editor.theme.name != "") false;
"Color Theme".value = lib.mkIf (cfg.editor.theme.name != "") cfg.editor.theme.name; "Color Theme" = lib.mkIf (cfg.editor.theme.name != "") cfg.editor.theme.name;
}; };
}; };

View File

@ -97,7 +97,7 @@ in
programs.plasma.configFile."konsolerc" = lib.mkMerge [ programs.plasma.configFile."konsolerc" = lib.mkMerge [
( (
lib.mkIf (cfg.defaultProfile != null) { lib.mkIf (cfg.defaultProfile != null) {
"Desktop Entry"."DefaultProfile".value = "${cfg.defaultProfile}.profile"; "Desktop Entry"."DefaultProfile" = "${cfg.defaultProfile}.profile";
} }
) )
( (

View File

@ -3,7 +3,7 @@
let let
inherit (import ../lib/writeconfig.nix { inherit lib pkgs config; }) writeConfig; 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 # Helper function to prepend the appropriate path prefix (e.g. XDG_CONFIG_HOME) to file
prependPath = prefix: attrset: prependPath = prefix: attrset:
@ -16,7 +16,7 @@ let
(prependPath config.xdg.configHome plasmaCfg.configFile) // (prependPath config.xdg.configHome plasmaCfg.configFile) //
(prependPath config.xdg.dataHome plasmaCfg.dataFile); (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 # Generate a script that will use write_config.py to update all

View File

@ -1,10 +1,10 @@
{ { lib
lib, , config
config, , ...
... }:
}: let let
inherit (lib) mkIf mkOption types; inherit (lib) mkIf mkOption types;
qfont = import ../lib/qfont.nix {inherit lib;}; qfont = import ../lib/qfont.nix { inherit lib; };
styleStrategyType = types.submodule { styleStrategyType = types.submodule {
options = with qfont.styleStrategy; { options = with qfont.styleStrategy; {
@ -180,7 +180,7 @@
}; };
styleStrategy = mkOption { styleStrategy = mkOption {
type = styleStrategyType; type = styleStrategyType;
default = {}; default = { };
description = '' description = ''
The strategy for matching similar fonts to this font. The strategy for matching similar fonts to this font.
@ -200,7 +200,8 @@
inherit (config.programs.plasma) enable; inherit (config.programs.plasma) enable;
cfg = lib.filterAttrs (_: v: v != null) config.programs.plasma.fonts; cfg = lib.filterAttrs (_: v: v != null) config.programs.plasma.fonts;
in { in
{
options.programs.plasma.fonts = { options.programs.plasma.fonts = {
general = mkOption { general = mkOption {
type = types.nullOr fontType; type = types.nullOr fontType;
@ -270,16 +271,18 @@ in {
}; };
}; };
config.programs.plasma.configFile.kdeglobals = let config.programs.plasma.configFile.kdeglobals =
mkFont = f: mkIf (enable && builtins.hasAttr f cfg) (qfont.fontToString cfg.${f}); let
in { mkFont = f: mkIf (enable && builtins.hasAttr f cfg) (qfont.fontToString cfg.${f});
General = { in
font.value = mkFont "general"; {
fixed.value = mkFont "fixedWidth"; General = {
smallestReadableFont.value = mkFont "small"; font = mkFont "general";
toolBarFont.value = mkFont "toolbar"; fixed = mkFont "fixedWidth";
menuFont.value = mkFont "menu"; smallestReadableFont = mkFont "small";
toolBarFont = mkFont "toolbar";
menuFont = mkFont "menu";
};
WM.activeFont = mkFont "windowTitle";
}; };
WM.activeFont.value = mkFont "windowTitle";
};
} }

View File

@ -94,19 +94,17 @@ in
}; };
programs.plasma.configFile."kglobalshortcutsrc"."${group.desktop}" = { programs.plasma.configFile."kglobalshortcutsrc"."${group.desktop}" = {
_k_friendly_name.value = group.description; _k_friendly_name = group.description;
} // lib.mapAttrs } // lib.mapAttrs
(_: command: (_: command:
let let
keys = command.keys ++ lib.optionals (command.key != "") [ command.key ]; keys = command.keys ++ lib.optionals (command.key != "") [ command.key ];
in in
{ lib.concatStringsSep "," [
value = lib.concatStringsSep "," [ (lib.concatStringsSep "\t" (map (lib.escape [ "," ]) keys))
(lib.concatStringsSep "\t" (map (lib.escape [ "," ]) keys)) "" # List of default keys, not needed.
"" # List of default keys, not needed. command.comment
command.comment ])
];
})
cfg.hotkeys.commands; cfg.hotkeys.commands;
}; };
} }

View File

@ -54,7 +54,7 @@ let
virtualDesktopNameAttrs = names: virtualDesktopNameAttrs = names:
builtins.listToAttrs builtins.listToAttrs
(imap1 (i: v: (nameValuePair "Name_${builtins.toString i}" { value = v; })) names); (imap1 (i: v: (nameValuePair "Name_${builtins.toString i}" v)) names);
in in
{ {
options.programs.plasma.kwin = { options.programs.plasma.kwin = {
@ -142,37 +142,37 @@ in
# Titlebar buttons # Titlebar buttons
( (
mkIf (cfg.kwin.titlebarButtons.left != null) { 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) { 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 # Effects
( (
mkIf (cfg.kwin.effects.shakeCursor.enable != null) { mkIf (cfg.kwin.effects.shakeCursor.enable != null) {
Plugins.shakecursorEnabled.value = cfg.kwin.effects.shakeCursor.enable; Plugins.shakecursorEnabled = cfg.kwin.effects.shakeCursor.enable;
} }
) )
# Virtual Desktops # Virtual Desktops
(mkIf (cfg.kwin.virtualDesktops.animation != null) { (mkIf (cfg.kwin.virtualDesktops.animation != null) {
Plugins.slideEnabled.value = cfg.kwin.virtualDesktops.animation == "slide"; Plugins.slideEnabled = cfg.kwin.virtualDesktops.animation == "slide";
Plugins.fadedesktopEnabled.value = cfg.kwin.virtualDesktops.animation == "fade"; Plugins.fadedesktopEnabled = cfg.kwin.virtualDesktops.animation == "fade";
}) })
(mkIf (cfg.kwin.virtualDesktops.number != null) { (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) { (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) { (mkIf (cfg.kwin.virtualDesktops.names != null) {
Desktops = mkMerge [ Desktops = mkMerge [
{ {
Number.value = builtins.length cfg.kwin.virtualDesktops.names; Number = builtins.length cfg.kwin.virtualDesktops.names;
} }
(virtualDesktopNameAttrs cfg.kwin.virtualDesktops.names) (virtualDesktopNameAttrs cfg.kwin.virtualDesktops.names)
]; ];

View File

@ -26,17 +26,14 @@ let
escape = lib.escape [ "," ]; escape = lib.escape [ "," ];
keysStr = (if ((builtins.length keys) == 1) then (escape (builtins.head keys)) else "\t" + (lib.concatStringsSep "\t" (map escape keys))); keysStr = (if ((builtins.length keys) == 1) then (escape (builtins.head keys)) else "\t" + (lib.concatStringsSep "\t" (map escape keys)));
in in
{ (if (isService group) then
value = keysStr
if (isService group) then else
keysStr (lib.concatStringsSep "," [
else keysStr
(lib.concatStringsSep "," [ "" # List of default keys, not needed.
keysStr "" # Display string, not needed.
"" # List of default keys, not needed. ]));
"" # Display string, not needed.
]);
};
shortcutsToSettings = groups: shortcutsToSettings = groups:
lib.mapAttrs lib.mapAttrs

View File

@ -19,7 +19,7 @@ in
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
programs.plasma.configFile = { programs.plasma.configFile = {
kdeglobals = { kdeglobals = {
General.AllowKDEAppsToRememberWindowPositions.value = General.AllowKDEAppsToRememberWindowPositions =
lib.mkDefault cfg.windows.allowWindowsToRememberPositions; lib.mkDefault cfg.windows.allowWindowsToRememberPositions;
}; };
}; };

View File

@ -139,12 +139,12 @@ in
} }
{ {
programs.plasma.configFile.kdeglobals = { 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) { (lib.mkIf (cfg.workspace.tooltipDelay > 0) {
programs.plasma.configFile.plasmarc = { programs.plasma.configFile.plasmarc = {
PlasmaToolTips.Delay.value = cfg.workspace.tooltipDelay; PlasmaToolTips.Delay = cfg.workspace.tooltipDelay;
}; };
}) })
(lib.mkIf (lib.mkIf

View File

@ -206,7 +206,7 @@ module Rc2Nix
print(" " * indent) print(" " * indent)
print("\"#{file}\".") print("\"#{file}\".")
print("\"#{group}\".") print("\"#{group}\".")
print("\"#{key}\".value = ") print("\"#{key}\" = ")
print(nix_val(settings[file][group][key])) print(nix_val(settings[file][group][key]))
print(";\n") print(";\n")
end end

View File

@ -21,6 +21,8 @@ let
assert_eq KDE SingleClick false assert_eq KDE SingleClick false
assert_eq General AllowKDEAppsToRememberWindowPositions true assert_eq General AllowKDEAppsToRememberWindowPositions true
assert_eq group key1 1
assert_eq group key2 2
''; '';
in in
testers.nixosTest { testers.nixosTest {
@ -41,6 +43,13 @@ testers.nixosTest {
programs.plasma = { programs.plasma = {
enable = true; enable = true;
workspace.clickItemTo = "select"; workspace.clickItemTo = "select";
configFile.kdeglobals.group = {
key1 = 1;
key2 = {
value = 2;
immutable = true;
};
};
}; };
}; };
}; };