From 6a94c1a59737783c282c4031555a289c28b961e4 Mon Sep 17 00:00:00 2001 From: Kilian Mio <86004375+Mikilio@users.noreply.github.com> Date: Thu, 17 Aug 2023 10:27:17 +0200 Subject: [PATCH] fix(qt): allow theming for apps started by systemd (#4349) --- modules/misc/qt.nix | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/modules/misc/qt.nix b/modules/misc/qt.nix index 554072e2f..2eb592615 100644 --- a/modules/misc/qt.nix +++ b/modules/misc/qt.nix @@ -128,7 +128,20 @@ in { }; }; - config = mkIf (cfg.enable && cfg.platformTheme != null) { + config = let + + # Necessary because home.sessionVariables doesn't support mkIf + envVars = filterAttrs (n: v: v != null) { + QT_QPA_PLATFORMTHEME = if cfg.platformTheme == "gtk" then + "gtk2" + else if cfg.platformTheme == "qtct" then + "qt5ct" + else + cfg.platformTheme; + QT_STYLE_OVERRIDE = cfg.style.name; + }; + + in mkIf (cfg.enable && cfg.platformTheme != null) { assertions = [{ assertion = cfg.platformTheme == "gnome" -> cfg.style.name != null && cfg.style.package != null; @@ -141,16 +154,10 @@ in { qt.style.package = mkIf (cfg.style.name != null) (mkDefault (stylePackages.${toLower cfg.style.name} or null)); - # Necessary because home.sessionVariables doesn't support mkIf - home.sessionVariables = filterAttrs (n: v: v != null) { - QT_QPA_PLATFORMTHEME = if cfg.platformTheme == "gtk" then - "gtk2" - else if cfg.platformTheme == "qtct" then - "qt5ct" - else - cfg.platformTheme; - QT_STYLE_OVERRIDE = cfg.style.name; - }; + home.sessionVariables = envVars; + + # Apply theming also to apps started by systemd. + systemd.user.sessionVariables = envVars; home.packages = (if cfg.platformTheme == "gnome" then [ pkgs.qgnomeplatform ]