From 61463d50fca2f07b39231f88ebeffbf1617d2094 Mon Sep 17 00:00:00 2001 From: mikaeladev Date: Sun, 22 Mar 2026 11:38:25 +0000 Subject: [PATCH] qt: add kvantum options --- modules/misc/qt/kvantum.nix | 132 ++++++++++++++++++ modules/modules.nix | 1 + tests/modules/misc/qt/default.nix | 2 + tests/modules/misc/qt/qt-kvantum-settings.nix | 54 +++++++ tests/modules/misc/qt/qt-kvantum-themes.nix | 29 ++++ 5 files changed, 218 insertions(+) create mode 100644 modules/misc/qt/kvantum.nix create mode 100644 tests/modules/misc/qt/qt-kvantum-settings.nix create mode 100644 tests/modules/misc/qt/qt-kvantum-themes.nix diff --git a/modules/misc/qt/kvantum.nix b/modules/misc/qt/kvantum.nix new file mode 100644 index 00000000..08fa5cf2 --- /dev/null +++ b/modules/misc/qt/kvantum.nix @@ -0,0 +1,132 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + inherit (lib) + concatMapStringsSep + generators + literalExpression + mkIf + mkOption + types + ; + + kvconfigFormat = pkgs.formats.ini { + listToValue = concatMapStringsSep ", " (generators.mkValueStringDefault { }); + }; + + kvconfigAtom = kvconfigFormat.lib.types.atom; + + kvconfigSection = (types.attrsOf kvconfigAtom) // { + description = "section of a kvconfig file (attrs of ${kvconfigAtom.description})"; + }; + + cfg = config.qt.kvantum; +in + +{ + options.qt.kvantum = { + settings = mkOption { + type = types.submodule { + freeformType = types.attrsOf kvconfigSection; + + options = { + General = mkOption { + type = types.submodule { + freeformType = kvconfigSection; + + options = { + theme = mkOption { + type = with types; nullOr str; + default = null; + example = "KvAdapta"; + description = '' + The default Kvantum theme to use. + ''; + }; + }; + }; + default = { }; + example = { + theme = "KvAdapta"; + }; + description = '' + General configuration settings for Kvantum. + ''; + }; + + Applications = mkOption { + type = with types; attrsOf (listOf str); + default = { }; + example = { + KvArc = [ + "app1" + "app2" + ]; + KvFlat = [ "app3" ]; + }; + description = '' + Application configuration settings for Kvantum. + + Themes set here will override {option}`qt.kvantum.settings.General.theme` + for their specific applications. + ''; + }; + }; + }; + default = { }; + example = { + General = { + theme = "KvAdapta"; + }; + Applications = { + KvArc = [ + "app1" + "app2" + ]; + KvFlat = [ "app3" ]; + }; + SomethingElse = { + foo = "bar"; + }; + }; + description = '' + Global configuration settings written to {file}`$XDG_CONFIG_HOME/Kvantum/kvantum.kvconfig`. + ''; + }; + + themes = mkOption { + type = with types; listOf package; + default = [ ]; + example = literalExpression '' + with pkgs; [ + gruvbox-kvantum + catppuccin-kvantum + ]''; + description = '' + Theme packages to install to {file}`$XDG_CONFIG_HOME/Kvantum/`. + ''; + }; + }; + + config = { + xdg.configFile = { + "Kvantum" = mkIf (cfg.themes != [ ]) { + recursive = true; + source = pkgs.symlinkJoin { + name = "kvantum-themes"; + paths = cfg.themes; + stripPrefix = "/share/Kvantum"; + }; + }; + + "Kvantum/kvantum.kvconfig" = mkIf (cfg.settings != { }) { + source = kvconfigFormat.generate "kvantum-config" cfg.settings; + }; + }; + }; +} diff --git a/modules/modules.nix b/modules/modules.nix index 6092ac81..9101b84f 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -45,6 +45,7 @@ let ./misc/pam.nix ./misc/qt.nix ./misc/qt/kconfig.nix + ./misc/qt/kvantum.nix ./misc/shell.nix ./misc/specialisation.nix ./misc/submodule-support.nix diff --git a/tests/modules/misc/qt/default.nix b/tests/modules/misc/qt/default.nix index bfdfea91..5af7658c 100644 --- a/tests/modules/misc/qt/default.nix +++ b/tests/modules/misc/qt/default.nix @@ -1,5 +1,7 @@ { qt-basic = ./qt-basic.nix; + qt-kvantum-settings = ./qt-kvantum-settings.nix; + qt-kvantum-themes = ./qt-kvantum-themes.nix; qt-platform-theme-gtk = ./qt-platform-theme-gtk.nix; qt-platform-theme-gtk3 = ./qt-platform-theme-gtk3.nix; qt-platform-theme-gnome = ./qt-platform-theme-gnome.nix; diff --git a/tests/modules/misc/qt/qt-kvantum-settings.nix b/tests/modules/misc/qt/qt-kvantum-settings.nix new file mode 100644 index 00000000..7d482c4e --- /dev/null +++ b/tests/modules/misc/qt/qt-kvantum-settings.nix @@ -0,0 +1,54 @@ +{ pkgs, ... }: + +{ + qt = { + enable = true; + kvantum = { + settings = { + General = { + theme = "KvAdapta"; + hello = "world"; + }; + Applications = { + KvArc = [ + "app1" + "app2" + ]; + KvFlat = [ "app3" ]; + }; + SomethingElse = { + foo = "bar"; + baz = [ + "qux" + 123 + true + null + ]; + }; + }; + }; + }; + + nmt.script = + let + configPath = "home-files/.config/Kvantum/kvantum.kvconfig"; + + expectedContent = pkgs.writeText "expected.kvconfig" '' + [Applications] + KvArc=app1, app2 + KvFlat=app3 + + [General] + hello=world + theme=KvAdapta + + [SomethingElse] + baz=qux, 123, true, null + foo=bar + ''; + in + '' + assertFileExists "${configPath}" + assertFileContent "${configPath}" "${expectedContent}" + ''; +} diff --git a/tests/modules/misc/qt/qt-kvantum-themes.nix b/tests/modules/misc/qt/qt-kvantum-themes.nix new file mode 100644 index 00000000..a7f3632a --- /dev/null +++ b/tests/modules/misc/qt/qt-kvantum-themes.nix @@ -0,0 +1,29 @@ +{ pkgs, ... }: + +{ + qt = { + enable = true; + kvantum = { + settings = { + general = { + theme = "KvAdapta"; + }; + }; + themes = [ + (pkgs.runCommand "kvantum-test-theme" { } '' + mkdir -p $out/share/Kvantum/TestTheme + touch $out/share/Kvantum/TestTheme/TestTheme.kvconfig + '') + ]; + }; + }; + + nmt.script = + let + configDir = "home-files/.config/Kvantum"; + in + '' + assertFileExists "${configDir}/kvantum.kvconfig" + assertFileExists "${configDir}/TestTheme/TestTheme.kvconfig" + ''; +}