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:
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

1
examples/.gitignore vendored Normal file
View File

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

View File

@ -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).

View File

@ -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).

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";
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 = {

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";
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 = {

View File

@ -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": {

View File

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

View File

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

View File

@ -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";
}
)
(

View File

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

View File

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

View File

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

View File

@ -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)
];

View File

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

View File

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

View File

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

View File

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

View File

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