From cf8432578f514476648fb4f0927f369d2eb935d1 Mon Sep 17 00:00:00 2001 From: Mikilio Date: Sat, 18 Jan 2025 19:20:14 +0100 Subject: [PATCH] feat(qt): integrate qt hm module with NixOS for sensible defaults These changes make the PR apply the Kvatum theme only when appropriate and creates the framework to allow for Qt styling based on the DE. --- modules/qt/hm.nix | 120 +++++++++++++++++----------- modules/qt/nixos.nix | 57 +++++++++++++ stylix/home-manager-integration.nix | 8 ++ 3 files changed, 138 insertions(+), 47 deletions(-) create mode 100644 modules/qt/nixos.nix diff --git a/modules/qt/hm.nix b/modules/qt/hm.nix index 195aca1a7..2f2e5e6c8 100644 --- a/modules/qt/hm.nix +++ b/modules/qt/hm.nix @@ -3,62 +3,88 @@ config, lib, ... -}: { +}: +{ options.stylix.targets.qt = { enable = config.lib.stylix.mkEnableTarget "QT" pkgs.stdenv.hostPlatform.isLinux; - iconThemeName = lib.mkOption { - description = "Default QT Icons"; + platform = lib.mkOption { + description = '' + Platform for QT. + + Defaults to the standard platform of the configured DE in NixOS when + `stylix.homeManagerIntegration.followSystem = true`. + + Fallback to qtct. + ''; type = lib.types.str; - default = "ePapirus-Dark"; + default = "qtct"; }; }; - config = lib.mkIf config.stylix.targets.qt.enable (let - cfg = config.stylix.targets.qt; - kvconfig = config.lib.stylix.colors { - template = ./kvconfig.mustache; - extension = ".kvconfig"; - }; - svg = config.lib.stylix.colors { - template = ./kvantum-svg.mustache; - extension = "svg"; - }; - kvantumPackage = pkgs.runCommandLocal "base16-kvantum" {} '' - directory="$out/share/Kvantum/Base16Kvantum" - mkdir --parents "$directory" - cat ${kvconfig} >>"$directory/Base16Kvantum.kvconfig" - cat ${svg} >>"$directory/Base16Kvantum.svg" - ''; - in { - home.packages = with pkgs; [ - qt5ct - libsForQt5.qtstyleplugin-kvantum - qt6Packages.qtstyleplugin-kvantum - kvantumPackage - papirus-icon-theme - ]; + config = lib.mkIf config.stylix.targets.qt.enable ( + let + cfg = config.stylix; + iconTheme = + if (cfg.polarity == "dark") then cfg.iconTheme.dark else cfg.iconTheme.light; - qt = { - enable = true; - platformTheme.name = "qtct"; - }; + kvantumPackage = + let + kvconfig = config.lib.stylix.colors { + template = ./kvconfig.mustache; + extension = ".kvconfig"; + }; + svg = config.lib.stylix.colors { + template = ./kvantum-svg.mustache; + extension = "svg"; + }; + in + pkgs.runCommandLocal "base16-kvantum" { } '' + directory="$out/share/Kvantum/Base16Kvantum" + mkdir --parents "$directory" + ln -s ${kvconfig} "$directory/Base16Kvantum.kvconfig" + ln -s ${svg} "$directory/Base16Kvantum.svg" + ''; + in + { + warnings = lib.optional (cfg.platform != "qtct") '' + Stylix has not yet implemented qt styling for any platforms other than "qtct". + We are working on it. + ''; - xdg.configFile."Kvantum/kvantum.kvconfig".source = (pkgs.formats.ini {}).generate "kvantum.kvconfig" { - General.theme = "Base16Kvantum"; - }; + home.packages = lib.optional (config.qt.style.name == "kvantum") kvantumPackage; + + qt = { + enable = true; + style.name = + if cfg.targets.qt.platform == "qtct" then "kvantum" else lib.mkDefault null; + platformTheme.name = cfg.targets.qt.platform; + }; - xdg.configFile."Kvantum/Base16Kvantum".source = "${kvantumPackage}/share/Kvantum/Base16Kvantum"; + xdg.configFile = lib.mkMerge [ + (lib.mkIf (config.qt.style.name == "kvantum") { + "Kvantum/kvantum.kvconfig".source = + (pkgs.formats.ini { }).generate "kvantum.kvconfig" + { + General.theme = "Base16Kvantum"; + }; - xdg.configFile."qt5ct/qt5ct.conf".text = '' - [Appearance] - style=kvantum - icon_theme=${cfg.iconThemeName} - ''; + "Kvantum/Base16Kvantum".source = + "${kvantumPackage}/share/Kvantum/Base16Kvantum"; + }) - xdg.configFile."qt6ct/qt6ct.conf".text = '' - [Appearance] - style=kvantum - icon_theme=${cfg.iconThemeName} - ''; - }); + (lib.mkIf (config.qt.platformTheme == "qtct") { + "qt5ct/qt5ct.conf".text = '' + [Appearance] + style=${config.qt.style.name} + icon_theme=${iconTheme} + ''; + "qt6ct/qt6ct.conf".text = '' + [Appearance] + style=${config.qt.style.name} + icon_theme=${iconTheme} + ''; + }) + ]; + } + ); } diff --git a/modules/qt/nixos.nix b/modules/qt/nixos.nix new file mode 100644 index 000000000..17d77d3ab --- /dev/null +++ b/modules/qt/nixos.nix @@ -0,0 +1,57 @@ +{ + lib, + pkgs, + config, + ... +}: + +let + + recommendedStyle = { + gnome = if config.stylix.polarity == "dark" then "adwaita-dark" else "adawaita"; + kde = "breeze"; + qtct = "kvantum"; + }; + +in +{ + options.stylix.targets.qt = { + enable = config.lib.stylix.mkEnableTarget "QT" pkgs.stdenv.hostPlatform.isLinux; + platform = lib.mkOption { + description = '' + Platform for QT. + + Defaults to the standard platform of the configured DE. + + Fallback to qtct. + ''; + type = lib.types.str; + default = "qtct"; + }; + }; + + config = lib.mkIf (config.stylix.enable && config.stylix.targets.qt.enable) { + + stylix.targets.qt.platform = + if config.services.xserver.desktopManager.gnome.enable then + lib.mkDefault "gnome" + else if config.services.xserver.desktopManager.plasma5.enable then + lib.mkDefault "kde" + else if config.services.xserver.desktopManager.lxqt.enable then + lib.mkDefault "lxqt" + else + lib.mkDefault "qt5ct"; + qt = { + enable = true; + style = lib.mkIf ( + recommendedStyle ? "${config.qt.platformTheme}" + ) recommendedStyle."${config.qt.platformTheme}"; + platformTheme = + if config.stylix.targets.qt.platform == "qtct" then + "qt5ct" + else + config.stylix.targets.qt.platform; + }; + + }; +} diff --git a/stylix/home-manager-integration.nix b/stylix/home-manager-integration.nix index eb4a3bb02..fefae0479 100644 --- a/stylix/home-manager-integration.nix +++ b/stylix/home-manager-integration.nix @@ -174,6 +174,14 @@ let "polarity" ]; } + { + path = [ + "stylix" + "targets" + "qt" + "platform" + ]; + } ]; in