From b4ea37c633d809eaa1b998f72d9d86c1a6a558cb Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 18 Oct 2023 11:58:05 +0100 Subject: [PATCH 01/11] qt: remove remaining Qt 4 support Qt 4 was removed from nixpkgs so it doesn't make sense to support it anymore. --- modules/misc/qt.nix | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/modules/misc/qt.nix b/modules/misc/qt.nix index d1197683..314a4a2c 100644 --- a/modules/misc/qt.nix +++ b/modules/misc/qt.nix @@ -38,7 +38,7 @@ in { options = { qt = { - enable = mkEnableOption "Qt 4, 5 and 6 configuration"; + enable = mkEnableOption "Qt 5 and 6 configuration"; platformTheme = mkOption { type = types.nullOr (types.enum [ "gtk" "gnome" "qtct" "kde" ]); @@ -170,14 +170,5 @@ in { xsession.importedVariables = [ "QT_QPA_PLATFORMTHEME" ] ++ lib.optionals (cfg.style.name != null) [ "QT_STYLE_OVERRIDE" ]; - - # Enable GTK+ style for Qt4 in Gtk/GNOME. - # It doesn’t support the platform theme packages. - home.activation.useGtkThemeInQt4 = - mkIf (cfg.platformTheme == "gtk" || cfg.platformTheme == "gnome") - (hm.dag.entryAfter [ "writeBoundary" ] '' - $DRY_RUN_CMD ${pkgs.crudini}/bin/crudini $VERBOSE_ARG \ - --set "${config.xdg.configHome}/Trolltech.conf" Qt style GTK+ - ''); }; } From 5744ebf3593ed95516e47d1895b7f19f57de7eb4 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 18 Oct 2023 12:54:36 +0100 Subject: [PATCH 02/11] qt: export QT_PLUGIN_PATH/QML2_IMPORT_PATH Those 2 variables are necessary to make e.g.: qt6ct work correctly. See issue: https://github.com/NixOS/nixpkgs/issues/239909. --- modules/misc/qt.nix | 16 ++++++++++++++-- .../modules/misc/qt/qt-platform-theme-gnome.nix | 4 ++++ tests/modules/misc/qt/qt-platform-theme-gtk.nix | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/modules/misc/qt.nix b/modules/misc/qt.nix index 314a4a2c..e78a8aca 100644 --- a/modules/misc/qt.nix +++ b/modules/misc/qt.nix @@ -127,7 +127,10 @@ in { config = let # Necessary because home.sessionVariables doesn't support mkIf - envVars = filterAttrs (n: v: v != null) { + envVars = let + inherit (config.home) profileDirectory; + qtVersions = with pkgs; [ qt5 qt6 ]; + in filterAttrs (n: v: v != null) { QT_QPA_PLATFORMTHEME = if cfg.platformTheme == "gtk" then "gtk2" else if cfg.platformTheme == "qtct" then @@ -135,6 +138,14 @@ in { else cfg.platformTheme; QT_STYLE_OVERRIDE = cfg.style.name; + QT_PLUGIN_PATH = "$QT_PLUGIN_PATH\${QT_PLUGIN_PATH:+:}" + + (lib.concatStringsSep ":" + (map (qt: "${profileDirectory}/${qt.qtbase.qtPluginPrefix}") + qtVersions)); + QML2_IMPORT_PATH = "$QML2_IMPORT_PATH\${QML2_IMPORT_PATH:+:}" + + (lib.concatStringsSep ":" + (map (qt: "${profileDirectory}/${qt.qtbase.qtQmlPrefix}") + qtVersions)); }; in mkIf (cfg.enable && cfg.platformTheme != null) { @@ -168,7 +179,8 @@ in { ++ lib.optionals (cfg.style.package != null) (lib.toList cfg.style.package); - xsession.importedVariables = [ "QT_QPA_PLATFORMTHEME" ] + xsession.importedVariables = + [ "QT_QPA_PLATFORMTHEME" "QT_PLUGIN_PATH" "QML2_IMPORT_PATH" ] ++ lib.optionals (cfg.style.name != null) [ "QT_STYLE_OVERRIDE" ]; }; } diff --git a/tests/modules/misc/qt/qt-platform-theme-gnome.nix b/tests/modules/misc/qt/qt-platform-theme-gnome.nix index 58b4cd7a..d95ef704 100644 --- a/tests/modules/misc/qt/qt-platform-theme-gnome.nix +++ b/tests/modules/misc/qt/qt-platform-theme-gnome.nix @@ -15,6 +15,10 @@ 'QT_QPA_PLATFORMTHEME="gnome"' assertFileRegex home-path/etc/profile.d/hm-session-vars.sh \ 'QT_STYLE_OVERRIDE="adwaita"' + assertFileRegex home-path/etc/profile.d/hm-session-vars.sh \ + 'QT_PLUGIN_PATH' + assertFileRegex home-path/etc/profile.d/hm-session-vars.sh \ + 'QML2_IMPORT_PATH' ''; }; } diff --git a/tests/modules/misc/qt/qt-platform-theme-gtk.nix b/tests/modules/misc/qt/qt-platform-theme-gtk.nix index d3324652..b91496b5 100644 --- a/tests/modules/misc/qt/qt-platform-theme-gtk.nix +++ b/tests/modules/misc/qt/qt-platform-theme-gtk.nix @@ -10,6 +10,10 @@ nmt.script = '' assertFileRegex home-path/etc/profile.d/hm-session-vars.sh \ 'QT_QPA_PLATFORMTHEME="gtk2"' + assertFileRegex home-path/etc/profile.d/hm-session-vars.sh \ + 'QT_PLUGIN_PATH' + assertFileRegex home-path/etc/profile.d/hm-session-vars.sh \ + 'QML2_IMPORT_PATH' ''; }; } From 4b2d3b03becc184f2d1485e109c6a55f94d5f886 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 18 Oct 2023 13:24:09 +0100 Subject: [PATCH 03/11] qt: remove top-level `with lib` --- modules/misc/qt.nix | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/misc/qt.nix b/modules/misc/qt.nix index e78a8aca..e50f416a 100644 --- a/modules/misc/qt.nix +++ b/modules/misc/qt.nix @@ -1,9 +1,6 @@ { config, lib, pkgs, ... }: -with lib; - let - cfg = config.qt; # Maps known lowercase style names to style packages. Non-exhaustive. @@ -28,20 +25,23 @@ let }; in { - meta.maintainers = with maintainers; [ rycee thiagokokada ]; + meta.maintainers = with lib.maintainers; [ rycee thiagokokada ]; imports = [ - (mkChangedOptionModule [ "qt" "useGtkTheme" ] [ "qt" "platformTheme" ] + (lib.mkChangedOptionModule [ "qt" "useGtkTheme" ] [ "qt" "platformTheme" ] (config: - if getAttrFromPath [ "qt" "useGtkTheme" ] config then "gtk" else null)) + if lib.getAttrFromPath [ "qt" "useGtkTheme" ] config then + "gtk" + else + null)) ]; options = { qt = { - enable = mkEnableOption "Qt 5 and 6 configuration"; + enable = lib.mkEnableOption "Qt 5 and 6 configuration"; - platformTheme = mkOption { - type = types.nullOr (types.enum [ "gtk" "gnome" "qtct" "kde" ]); + platformTheme = lib.mkOption { + type = with lib.types; nullOr (enum [ "gtk" "gnome" "qtct" "kde" ]); default = null; example = "gnome"; relatedPackages = [ @@ -77,8 +77,8 @@ in { }; style = { - name = mkOption { - type = types.nullOr types.str; + name = lib.mkOption { + type = with lib.types; nullOr str; default = null; example = "adwaita-dark"; relatedPackages = [ @@ -111,10 +111,10 @@ in { ''; }; - package = mkOption { - type = with types; nullOr (either package (listOf package)); + package = lib.mkOption { + type = with lib.types; nullOr (either package (listOf package)); default = null; - example = literalExpression "pkgs.adwaita-qt"; + example = lib.literalExpression "pkgs.adwaita-qt"; description = '' Theme package to be used in Qt5/Qt6 applications. Auto-detected from {option}`qt.style.name` if possible. @@ -130,7 +130,7 @@ in { envVars = let inherit (config.home) profileDirectory; qtVersions = with pkgs; [ qt5 qt6 ]; - in filterAttrs (n: v: v != null) { + in lib.filterAttrs (n: v: v != null) { QT_QPA_PLATFORMTHEME = if cfg.platformTheme == "gtk" then "gtk2" else if cfg.platformTheme == "qtct" then @@ -148,7 +148,7 @@ in { qtVersions)); }; - in mkIf (cfg.enable && cfg.platformTheme != null) { + in lib.mkIf (cfg.enable && cfg.platformTheme != null) { assertions = [{ assertion = cfg.platformTheme == "gnome" -> cfg.style.name != null && cfg.style.package != null; @@ -158,8 +158,8 @@ in { ''; }]; - qt.style.package = mkIf (cfg.style.name != null) - (mkDefault (stylePackages.${toLower cfg.style.name} or null)); + qt.style.package = lib.mkIf (cfg.style.name != null) + (lib.mkDefault (stylePackages.${lib.toLower cfg.style.name} or null)); home.sessionVariables = envVars; From 3452e14ec729e0582a5fb120c14ed5c6d7fb64d3 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 18 Oct 2023 16:15:49 +0100 Subject: [PATCH 04/11] qt: workaround issue when i18n.inputMethod.enabled = 'fcitx5' --- modules/i18n/input-method/fcitx5.nix | 5 +++-- modules/misc/qt.nix | 12 ++++++++---- tests/modules/misc/qt/qt-platform-theme-gtk.nix | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/i18n/input-method/fcitx5.nix b/modules/i18n/input-method/fcitx5.nix index 1787a236..371f1cea 100644 --- a/modules/i18n/input-method/fcitx5.nix +++ b/modules/i18n/input-method/fcitx5.nix @@ -28,8 +28,9 @@ in { GTK_IM_MODULE = "fcitx"; QT_IM_MODULE = "fcitx"; XMODIFIERS = "@im=fcitx"; - QT_PLUGIN_PATH = - "${fcitx5Package}/${pkgs.qt6.qtbase.qtPluginPrefix}:\${QT_PLUGIN_PATH}"; + # Using mkDefault here since we override this value in qt module if enabled + QT_PLUGIN_PATH = lib.mkDefault + "$QT_PLUGIN_PATH\${QT_PLUGIN_PATH:+:}${fcitx5Package}/${pkgs.qt6.qtbase.qtPluginPrefix}"; }; systemd.user.services.fcitx5-daemon = { diff --git a/modules/misc/qt.nix b/modules/misc/qt.nix index e50f416a..a5a4f163 100644 --- a/modules/misc/qt.nix +++ b/modules/misc/qt.nix @@ -130,6 +130,7 @@ in { envVars = let inherit (config.home) profileDirectory; qtVersions = with pkgs; [ qt5 qt6 ]; + makeQtPath = prefix: basePath: qt: "${basePath}/${qt.qtbase.${prefix}}"; in lib.filterAttrs (n: v: v != null) { QT_QPA_PLATFORMTHEME = if cfg.platformTheme == "gtk" then "gtk2" @@ -140,12 +141,15 @@ in { QT_STYLE_OVERRIDE = cfg.style.name; QT_PLUGIN_PATH = "$QT_PLUGIN_PATH\${QT_PLUGIN_PATH:+:}" + (lib.concatStringsSep ":" - (map (qt: "${profileDirectory}/${qt.qtbase.qtPluginPrefix}") - qtVersions)); + # Workaround issue with home.sessionVariables that does not support + # multiple different values since fcitx5 also needs to set QT_PLUGIN_PATH. + (lib.optional (config.i18n.inputMethod == "fcitx5") + (makeQtPath "qtPluginPrefix" config.i18n.inputMethod.package + pkgs.qt6) ++ (map (makeQtPath "qtPluginPrefix" profileDirectory) + qtVersions))); QML2_IMPORT_PATH = "$QML2_IMPORT_PATH\${QML2_IMPORT_PATH:+:}" + (lib.concatStringsSep ":" - (map (qt: "${profileDirectory}/${qt.qtbase.qtQmlPrefix}") - qtVersions)); + (map (makeQtPath "qtQmlPrefix" profileDirectory) qtVersions)); }; in lib.mkIf (cfg.enable && cfg.platformTheme != null) { diff --git a/tests/modules/misc/qt/qt-platform-theme-gtk.nix b/tests/modules/misc/qt/qt-platform-theme-gtk.nix index b91496b5..070c8020 100644 --- a/tests/modules/misc/qt/qt-platform-theme-gtk.nix +++ b/tests/modules/misc/qt/qt-platform-theme-gtk.nix @@ -6,6 +6,7 @@ enable = true; platformTheme = "gtk"; }; + i18n.inputMethod.enabled = "fcitx5"; nmt.script = '' assertFileRegex home-path/etc/profile.d/hm-session-vars.sh \ From 4ba652d8a8a02348790100ffec69c8787aca9fe9 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 18 Oct 2023 18:00:45 +0100 Subject: [PATCH 05/11] qt: add style mappings for Qt 6 --- modules/misc/qt.nix | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/misc/qt.nix b/modules/misc/qt.nix index a5a4f163..8c56063c 100644 --- a/modules/misc/qt.nix +++ b/modules/misc/qt.nix @@ -8,15 +8,15 @@ let bb10bright = libsForQt5.qtstyleplugins; bb10dark = libsForQt5.qtstyleplugins; cleanlooks = libsForQt5.qtstyleplugins; - gtk2 = libsForQt5.qtstyleplugins; + gtk2 = [ libsForQt5.qtstyleplugins qt6Packages.qt6gtk2 ]; motif = libsForQt5.qtstyleplugins; cde = libsForQt5.qtstyleplugins; plastique = libsForQt5.qtstyleplugins; - adwaita = adwaita-qt; - adwaita-dark = adwaita-qt; - adwaita-highcontrast = adwaita-qt; - adwaita-highcontrastinverse = adwaita-qt; + adwaita = [ adwaita-qt adwaita-qt6 ]; + adwaita-dark = [ adwaita-qt adwaita-qt6 ]; + adwaita-highcontrast = [ adwaita-qt adwaita-qt6 ]; + adwaita-highcontrastinverse = [ adwaita-qt adwaita-qt6 ]; breeze = libsForQt5.breeze-qt5; @@ -83,9 +83,11 @@ in { example = "adwaita-dark"; relatedPackages = [ "adwaita-qt" + "adwaita-qt6" [ "libsForQt5" "breeze-qt5" ] - [ "libsForQt5" "qtstyleplugins" ] [ "libsForQt5" "qtstyleplugin-kvantum" ] + [ "libsForQt5" "qtstyleplugins" ] + [ "qt6Packages" "qt6gtk2" ] [ "qt6Packages" "qtstyleplugin-kvantum" ] ]; description = '' From 541d32d8b868753b0a627d542182cba9216325d9 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 18 Oct 2023 18:22:06 +0100 Subject: [PATCH 06/11] qt: add support for platformTheme lxqt --- modules/misc/qt.nix | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/modules/misc/qt.nix b/modules/misc/qt.nix index 8c56063c..3040fb1c 100644 --- a/modules/misc/qt.nix +++ b/modules/misc/qt.nix @@ -3,6 +3,14 @@ let cfg = config.qt; + platformPackages = with pkgs; { + gnome = [ qgnomeplatform ]; + gtk = [ libsForQt5.qtstyleplugins qt6Packages.qt6gtk2 ]; + kde = [ libsForQt5.plasma-integration libsForQt5.systemsettings ]; + lxqt = [ lxqt.lxqt-qtplugin lxqt.lxqt-config ]; + qtct = [ libsForQt5.qt5ct qt6Packages.qt6ct ]; + }; + # Maps known lowercase style names to style packages. Non-exhaustive. stylePackages = with pkgs; { bb10bright = libsForQt5.qtstyleplugins; @@ -41,16 +49,20 @@ in { enable = lib.mkEnableOption "Qt 5 and 6 configuration"; platformTheme = lib.mkOption { - type = with lib.types; nullOr (enum [ "gtk" "gnome" "qtct" "kde" ]); + type = with lib.types; + nullOr (enum [ "gtk" "gnome" "lxqt" "qtct" "kde" ]); default = null; example = "gnome"; relatedPackages = [ "qgnomeplatform" - [ "libsForQt5" "qtstyleplugins" ] - [ "libsForQt5" "qt5ct" ] - [ "qt6Packages" "qt6ct" ] [ "libsForQt5" "plasma-integration" ] + [ "libsForQt5" "qt5ct" ] + [ "libsForQt5" "qtstyleplugins" ] [ "libsForQt5" "systemsettings" ] + [ "lxqt" "lxqt-config" ] + [ "lxqt" "lxqt-qtplugin" ] + [ "qt6Packages" "qt6ct" ] + [ "qt6Packages" "qt6gtk2" ] ]; description = '' Platform theme to use for Qt applications. @@ -65,6 +77,11 @@ in { : Use GNOME theme with [`qgnomeplatform`](https://github.com/FedoraQt/QGnomePlatform) + `lxqt` + : Use LXQt theme style set using the + [`lxqt-config-appearance`](https://github.com/lxqt/lxqt-config) + application + `qtct` : Use Qt style set using [`qt5ct`](https://github.com/desktop-app/qt5ct) @@ -172,16 +189,7 @@ in { # Apply theming also to apps started by systemd. systemd.user.sessionVariables = envVars; - home.packages = (if cfg.platformTheme == "gnome" then - [ pkgs.qgnomeplatform ] - else if cfg.platformTheme == "qtct" then [ - pkgs.libsForQt5.qt5ct - pkgs.qt6Packages.qt6ct - ] else if cfg.platformTheme == "kde" then [ - pkgs.libsForQt5.plasma-integration - pkgs.libsForQt5.systemsettings - ] else - [ pkgs.libsForQt5.qtstyleplugins ]) + home.packages = (platformPackages.${cfg.platformTheme} or [ ]) ++ lib.optionals (cfg.style.package != null) (lib.toList cfg.style.package); From bc53e4c240ea71d2f4b271d95c262369ab7adc7c Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 18 Oct 2023 18:36:13 +0100 Subject: [PATCH 07/11] qt: add qgnomeplatform-qt6 when platformTheme is set to gnome --- modules/misc/qt.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/misc/qt.nix b/modules/misc/qt.nix index 3040fb1c..a968f31a 100644 --- a/modules/misc/qt.nix +++ b/modules/misc/qt.nix @@ -4,7 +4,7 @@ let cfg = config.qt; platformPackages = with pkgs; { - gnome = [ qgnomeplatform ]; + gnome = [ qgnomeplatform qgnomeplatform-qt6 ]; gtk = [ libsForQt5.qtstyleplugins qt6Packages.qt6gtk2 ]; kde = [ libsForQt5.plasma-integration libsForQt5.systemsettings ]; lxqt = [ lxqt.lxqt-qtplugin lxqt.lxqt-config ]; @@ -55,6 +55,7 @@ in { example = "gnome"; relatedPackages = [ "qgnomeplatform" + "qgnomeplatform-qt6" [ "libsForQt5" "plasma-integration" ] [ "libsForQt5" "qt5ct" ] [ "libsForQt5" "qtstyleplugins" ] From eaee696b6e77b8ec848fe6c49c9bc0fdfadafb3a Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 18 Oct 2023 19:23:17 +0100 Subject: [PATCH 08/11] qt: simplify style.name mappings --- modules/misc/qt.nix | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/misc/qt.nix b/modules/misc/qt.nix index a968f31a..1655d437 100644 --- a/modules/misc/qt.nix +++ b/modules/misc/qt.nix @@ -3,6 +3,7 @@ let cfg = config.qt; + # Map platform names to their packages. platformPackages = with pkgs; { gnome = [ qgnomeplatform qgnomeplatform-qt6 ]; gtk = [ libsForQt5.qtstyleplugins qt6Packages.qt6gtk2 ]; @@ -11,6 +12,12 @@ let qtct = [ libsForQt5.qt5ct qt6Packages.qt6ct ]; }; + # Maps style names to their QT_QPA_PLATFORMTHEME, if necessary. + styleNames = { + gtk = "gtk2"; + qtct = "qt5ct"; + }; + # Maps known lowercase style names to style packages. Non-exhaustive. stylePackages = with pkgs; { bb10bright = libsForQt5.qtstyleplugins; @@ -152,12 +159,8 @@ in { qtVersions = with pkgs; [ qt5 qt6 ]; makeQtPath = prefix: basePath: qt: "${basePath}/${qt.qtbase.${prefix}}"; in lib.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_QPA_PLATFORMTHEME = + styleNames.${cfg.platformTheme} or cfg.platformTheme; QT_STYLE_OVERRIDE = cfg.style.name; QT_PLUGIN_PATH = "$QT_PLUGIN_PATH\${QT_PLUGIN_PATH:+:}" + (lib.concatStringsSep ":" From 55eee5bd67fee341e86a457646bd4b78c5a77d26 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 18 Oct 2023 19:51:00 +0100 Subject: [PATCH 09/11] qt: use sessionVariablesExtra to export QT_PLUGIN_PATH/QML2_IMPORT_PATH --- modules/i18n/input-method/fcitx5.nix | 3 +- modules/misc/qt.nix | 41 +++++++++++++++++----------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/modules/i18n/input-method/fcitx5.nix b/modules/i18n/input-method/fcitx5.nix index 371f1cea..3599fd2d 100644 --- a/modules/i18n/input-method/fcitx5.nix +++ b/modules/i18n/input-method/fcitx5.nix @@ -28,8 +28,7 @@ in { GTK_IM_MODULE = "fcitx"; QT_IM_MODULE = "fcitx"; XMODIFIERS = "@im=fcitx"; - # Using mkDefault here since we override this value in qt module if enabled - QT_PLUGIN_PATH = lib.mkDefault + QT_PLUGIN_PATH = "$QT_PLUGIN_PATH\${QT_PLUGIN_PATH:+:}${fcitx5Package}/${pkgs.qt6.qtbase.qtPluginPrefix}"; }; diff --git a/modules/misc/qt.nix b/modules/misc/qt.nix index 1655d437..f45b8e3d 100644 --- a/modules/misc/qt.nix +++ b/modules/misc/qt.nix @@ -154,25 +154,23 @@ in { config = let # Necessary because home.sessionVariables doesn't support mkIf - envVars = let - inherit (config.home) profileDirectory; - qtVersions = with pkgs; [ qt5 qt6 ]; - makeQtPath = prefix: basePath: qt: "${basePath}/${qt.qtbase.${prefix}}"; - in lib.filterAttrs (n: v: v != null) { + envVars = lib.filterAttrs (n: v: v != null) { QT_QPA_PLATFORMTHEME = styleNames.${cfg.platformTheme} or cfg.platformTheme; QT_STYLE_OVERRIDE = cfg.style.name; + }; + + envVarsExtra = let + inherit (config.home) profileDirectory; + qtVersions = with pkgs; [ qt5 qt6 ]; + makeQtPath = prefix: + lib.concatStringsSep ":" + (map (qt: "${profileDirectory}/${qt.qtbase.${prefix}}") qtVersions); + in { QT_PLUGIN_PATH = "$QT_PLUGIN_PATH\${QT_PLUGIN_PATH:+:}" - + (lib.concatStringsSep ":" - # Workaround issue with home.sessionVariables that does not support - # multiple different values since fcitx5 also needs to set QT_PLUGIN_PATH. - (lib.optional (config.i18n.inputMethod == "fcitx5") - (makeQtPath "qtPluginPrefix" config.i18n.inputMethod.package - pkgs.qt6) ++ (map (makeQtPath "qtPluginPrefix" profileDirectory) - qtVersions))); + + (makeQtPath "qtPluginPrefix"); QML2_IMPORT_PATH = "$QML2_IMPORT_PATH\${QML2_IMPORT_PATH:+:}" - + (lib.concatStringsSep ":" - (map (makeQtPath "qtQmlPrefix" profileDirectory) qtVersions)); + + (makeQtPath "qtQmlPrefix"); }; in lib.mkIf (cfg.enable && cfg.platformTheme != null) { @@ -188,10 +186,21 @@ in { qt.style.package = lib.mkIf (cfg.style.name != null) (lib.mkDefault (stylePackages.${lib.toLower cfg.style.name} or null)); - home.sessionVariables = envVars; + home = { + sessionVariables = envVars; + # home.sessionVariables does not support setting the same environment + # variable to different values. + # Since some other modules may set the QT_PLUGIN_PATH or QML2_IMPORT_PATH + # to their own value, e.g.: fcitx5, we avoid conflicts by setting + # the values in home.sessionVariablesExtra instead. + sessionVariablesExtra = '' + export QT_PLUGIN_PATH=${envVarsExtra.QT_PLUGIN_PATH} + export QML2_IMPORT_PATH=${envVarsExtra.QML2_IMPORT_PATH} + ''; + }; # Apply theming also to apps started by systemd. - systemd.user.sessionVariables = envVars; + systemd.user.sessionVariables = envVars // envVarsExtra; home.packages = (platformPackages.${cfg.platformTheme} or [ ]) ++ lib.optionals (cfg.style.package != null) From 1e80a0b3d8ef2a9ffc0399b32edcd588ac396fa6 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Sun, 22 Oct 2023 19:13:20 +0100 Subject: [PATCH 10/11] qt: allow usage without setting platformTheme --- modules/misc/qt.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/misc/qt.nix b/modules/misc/qt.nix index f45b8e3d..19986579 100644 --- a/modules/misc/qt.nix +++ b/modules/misc/qt.nix @@ -173,7 +173,7 @@ in { + (makeQtPath "qtQmlPrefix"); }; - in lib.mkIf (cfg.enable && cfg.platformTheme != null) { + in lib.mkIf cfg.enable { assertions = [{ assertion = cfg.platformTheme == "gnome" -> cfg.style.name != null && cfg.style.package != null; @@ -206,8 +206,8 @@ in { ++ lib.optionals (cfg.style.package != null) (lib.toList cfg.style.package); - xsession.importedVariables = - [ "QT_QPA_PLATFORMTHEME" "QT_PLUGIN_PATH" "QML2_IMPORT_PATH" ] + xsession.importedVariables = [ "QT_PLUGIN_PATH" "QML2_IMPORT_PATH" ] + ++ lib.optionals (cfg.platformTheme != null) [ "QT_QPA_PLATFORMTHEME" ] ++ lib.optionals (cfg.style.name != null) [ "QT_STYLE_OVERRIDE" ]; }; } From 1160454c791fa777ce59373fca86c25ad075265a Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Sun, 22 Oct 2023 19:19:51 +0100 Subject: [PATCH 11/11] qt: support gtk3 platform theme This theme is part of qtbase and requires no extra packages. Co-authored-by: novenary --- modules/misc/qt.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/misc/qt.nix b/modules/misc/qt.nix index 19986579..495841ea 100644 --- a/modules/misc/qt.nix +++ b/modules/misc/qt.nix @@ -57,7 +57,7 @@ in { platformTheme = lib.mkOption { type = with lib.types; - nullOr (enum [ "gtk" "gnome" "lxqt" "qtct" "kde" ]); + nullOr (enum [ "gtk" "gtk3" "gnome" "lxqt" "qtct" "kde" ]); default = null; example = "gnome"; relatedPackages = [ @@ -81,6 +81,10 @@ in { : Use GTK theme with [`qtstyleplugins`](https://github.com/qt/qtstyleplugins) + `gtk3` + : Use [GTK3 integration](https://github.com/qt/qtbase/tree/dev/src/plugins/platformthemes/gtk3) + for file picker dialogs, font and theme configuration + `gnome` : Use GNOME theme with [`qgnomeplatform`](https://github.com/FedoraQt/QGnomePlatform)