lol

nixos/qt: multiple fixes

- Removal of top-level `with lib`
- Allow usage of module without setting `platformTheme`, so we can set
the QT_PLUGIN_PATH/QML2_IMPORT_PATH paths without theming
- Add support for kvantum and some other styles
- Add myself as maintainer

+92 -66
+92 -66
nixos/modules/config/qt.nix
··· 1 1 { config, lib, pkgs, ... }: 2 2 3 - with lib; 4 - 5 3 let 6 - 7 4 cfg = config.qt; 8 5 9 - isQGnome = cfg.platformTheme == "gnome" && builtins.elem cfg.style ["adwaita" "adwaita-dark"]; 10 - isQtStyle = cfg.platformTheme == "gtk2" && !(builtins.elem cfg.style ["adwaita" "adwaita-dark"]); 11 - isQt5ct = cfg.platformTheme == "qt5ct"; 12 - isLxqt = cfg.platformTheme == "lxqt"; 13 - isKde = cfg.platformTheme == "kde"; 6 + platformPackages = with pkgs; { 7 + gnome = [ qgnomeplatform qgnomeplatform-qt6 ]; 8 + gtk2 = [ libsForQt5.qtstyleplugins qt6Packages.qt6gtk2 ]; 9 + kde = [ libsForQt5.plasma-integration libsForQt5.systemsettings ]; 10 + lxqt = [ lxqt.lxqt-qtplugin lxqt.lxqt-config ]; 11 + qt5ct = [ libsForQt5.qt5ct qt6Packages.qt6ct ]; 12 + }; 14 13 15 - packages = 16 - if isQGnome then [ 17 - pkgs.qgnomeplatform 18 - pkgs.adwaita-qt 19 - pkgs.qgnomeplatform-qt6 20 - pkgs.adwaita-qt6 21 - ] 22 - else if isQtStyle then [ pkgs.libsForQt5.qtstyleplugins pkgs.qt6Packages.qt6gtk2 ] 23 - else if isQt5ct then [ pkgs.libsForQt5.qt5ct pkgs.qt6Packages.qt6ct ] 24 - else if isLxqt then [ pkgs.lxqt.lxqt-qtplugin pkgs.lxqt.lxqt-config ] 25 - else if isKde then [ pkgs.libsForQt5.plasma-integration pkgs.libsForQt5.systemsettings ] 26 - else throw "`qt.platformTheme` ${cfg.platformTheme} and `qt.style` ${cfg.style} are not compatible."; 14 + stylePackages = with pkgs; { 15 + bb10bright = [ libsForQt5.qtstyleplugins ]; 16 + bb10dark = [ libsForQt5.qtstyleplugins ]; 17 + cde = [ libsForQt5.qtstyleplugins ]; 18 + cleanlooks = [ libsForQt5.qtstyleplugins ]; 19 + gtk2 = [ libsForQt5.qtstyleplugins qt6Packages.qt6gtk2 ]; 20 + motif = [ libsForQt5.qtstyleplugins ]; 21 + plastique = [ libsForQt5.qtstyleplugins ]; 22 + 23 + adwaita = [ adwaita-qt adwaita-qt6 ]; 24 + adwaita-dark = [ adwaita-qt adwaita-qt6 ]; 25 + adwaita-highcontrast = [ adwaita-qt adwaita-qt6 ]; 26 + adwaita-highcontrastinverse = [ adwaita-qt adwaita-qt6 ]; 27 + 28 + breeze = [ libsForQt5.breeze-qt5 ]; 27 29 30 + kvantum = [ libsForQt5.qtstyleplugin-kvantum qt6Packages.qtstyleplugin-kvantum ]; 31 + }; 28 32 in 29 - 30 33 { 31 - meta.maintainers = [ maintainers.romildo ]; 34 + meta.maintainers = with lib.maintainers; [ romildo thiagokokada ]; 32 35 33 36 imports = [ 34 - (mkRenamedOptionModule ["qt5" "enable" ] ["qt" "enable" ]) 35 - (mkRenamedOptionModule ["qt5" "platformTheme" ] ["qt" "platformTheme" ]) 36 - (mkRenamedOptionModule ["qt5" "style" ] ["qt" "style" ]) 37 + (lib.mkRenamedOptionModule [ "qt5" "enable" ] [ "qt" "enable" ]) 38 + (lib.mkRenamedOptionModule [ "qt5" "platformTheme" ] [ "qt" "platformTheme" ]) 39 + (lib.mkRenamedOptionModule [ "qt5" "style" ] [ "qt" "style" ]) 37 40 ]; 38 41 39 42 options = { 40 43 qt = { 41 - 42 - enable = mkEnableOption (lib.mdDoc "Qt theming configuration"); 44 + enable = lib.mkEnableOption (lib.mdDoc "Qt theming configuration"); 43 45 44 - platformTheme = mkOption { 45 - type = types.enum [ 46 - "gtk2" 47 - "gnome" 48 - "lxqt" 49 - "qt5ct" 50 - "kde" 51 - ]; 46 + platformTheme = lib.mkOption { 47 + type = with lib.types; nullOr (enum (lib.attrNames platformPackages)); 48 + default = null; 52 49 example = "gnome"; 53 50 relatedPackages = [ 54 51 "qgnomeplatform" 55 52 "qgnomeplatform-qt6" 56 - ["libsForQt5" "qtstyleplugins"] 57 - ["libsForQt5" "qt5ct"] 58 - ["lxqt" "lxqt-qtplugin"] 59 - ["libsForQt5" "plasma-integration"] 53 + [ "libsForQt5" "plasma-integration" ] 54 + [ "libsForQt5" "qt5ct" ] 55 + [ "libsForQt5" "qtstyleplugins" ] 56 + [ "libsForQt5" "systemsettings" ] 57 + [ "lxqt" "lxqt-config" ] 58 + [ "lxqt" "lxqt-qtplugin" ] 59 + [ "qt6Packages" "qt6ct" ] 60 + [ "qt6Packages" "qt6gtk2" ] 60 61 ]; 61 62 description = lib.mdDoc '' 62 63 Selects the platform theme to use for Qt applications. 63 64 64 65 The options are 65 - - `gtk`: Use GTK theme with [qtstyleplugins](https://github.com/qt/qtstyleplugins) 66 66 - `gnome`: Use GNOME theme with [qgnomeplatform](https://github.com/FedoraQt/QGnomePlatform) 67 + - `gtk2`: Use GTK theme with [qtstyleplugins](https://github.com/qt/qtstyleplugins) 68 + - `kde`: Use Qt settings from Plasma. 67 69 - `lxqt`: Use LXQt style set using the [lxqt-config-appearance](https://github.com/lxqt/lxqt-config) 68 70 application. 69 71 - `qt5ct`: Use Qt style set using the [qt5ct](https://sourceforge.net/projects/qt5ct/) 70 - application. 71 - - `kde`: Use Qt settings from Plasma. 72 + and [qt6ct](https://github.com/trialuser02/qt6ct) applications. 72 73 ''; 73 74 }; 74 75 75 - style = mkOption { 76 - type = types.enum [ 77 - "adwaita" 78 - "adwaita-dark" 79 - "cleanlooks" 80 - "gtk2" 81 - "motif" 82 - "plastique" 83 - ]; 76 + style = lib.mkOption { 77 + type = with lib.types; nullOr (enum (lib.attrNames stylePackages)); 78 + default = null; 84 79 example = "adwaita"; 85 80 relatedPackages = [ 86 81 "adwaita-qt" 87 82 "adwaita-qt6" 88 - ["libsForQt5" "qtstyleplugins"] 89 - ["qt6Packages" "qt6gtk2"] 83 + [ "libsForQt5" "breeze-qt5" ] 84 + [ "libsForQt5" "qtstyleplugin-kvantum" ] 85 + [ "libsForQt5" "qtstyleplugins" ] 86 + [ "qt6Packages" "qt6gtk2" ] 87 + [ "qt6Packages" "qtstyleplugin-kvantum" ] 90 88 ]; 91 89 description = lib.mdDoc '' 92 90 Selects the style to use for Qt applications. 93 91 94 92 The options are 95 - - `adwaita`, `adwaita-dark`: Use Adwaita Qt style with 93 + - `adwaita`, `adwaita-dark`, `adwaita-highcontrast`, `adawaita-highcontrastinverse`: 94 + Use Adwaita Qt style with 96 95 [adwaita](https://github.com/FedoraQt/adwaita-qt) 97 - - `cleanlooks`, `gtk2`, `motif`, `plastique`: Use styles from 96 + - `breeze`: Use the Breeze style from 97 + [breeze](https://github.com/KDE/breeze) 98 + - `bb10bright`, `bb10dark`, `cleanlooks`, `gtk2`, `motif`, `plastique`: 99 + Use styles from 98 100 [qtstyleplugins](https://github.com/qt/qtstyleplugins) 101 + - `kvantum`: Use styles from 102 + [kvantum](https://github.com/tsujan/Kvantum) 99 103 ''; 100 104 }; 101 105 }; 102 106 }; 103 107 104 - config = mkIf cfg.enable { 108 + config = lib.mkIf cfg.enable { 109 + assertions = 110 + let 111 + gnomeStyles = [ 112 + "adwaita" 113 + "adwaita-dark" 114 + "adwaita-highcontrast" 115 + "adwaita-highcontrastinverse" 116 + "breeze" 117 + ]; 118 + in 119 + [ 120 + { 121 + assertion = cfg.platformTheme == "gnome" -> (builtins.elem cfg.style gnomeStyles); 122 + message = '' 123 + `qt.platformTheme` "gnome" must have `qt.style` set to a theme that supports both Qt and Gtk, 124 + for example: ${lib.concatStringsSep ", " gnomeStyles}. 125 + ''; 126 + } 127 + ]; 105 128 106 129 environment.variables = { 107 - QT_QPA_PLATFORMTHEME = cfg.platformTheme; 108 - QT_STYLE_OVERRIDE = mkIf (! (isQt5ct || isLxqt || isKde)) cfg.style; 130 + QT_QPA_PLATFORMTHEME = lib.mkIf (cfg.platformTheme != null) cfg.platformTheme; 131 + QT_STYLE_OVERRIDE = lib.mkIf (cfg.style != null) cfg.style; 109 132 }; 110 133 111 - environment.profileRelativeSessionVariables = let 112 - qtVersions = with pkgs; [ qt5 qt6 ]; 113 - in { 114 - QT_PLUGIN_PATH = map (qt: "/${qt.qtbase.qtPluginPrefix}") qtVersions; 115 - QML2_IMPORT_PATH = map (qt: "/${qt.qtbase.qtQmlPrefix}") qtVersions; 116 - }; 134 + environment.profileRelativeSessionVariables = 135 + let 136 + qtVersions = with pkgs; [ qt5 qt6 ]; 137 + in 138 + { 139 + QT_PLUGIN_PATH = map (qt: "/${qt.qtbase.qtPluginPrefix}") qtVersions; 140 + QML2_IMPORT_PATH = map (qt: "/${qt.qtbase.qtQmlPrefix}") qtVersions; 141 + }; 117 142 118 - environment.systemPackages = packages; 119 - 143 + environment.systemPackages = 144 + lib.optionals (cfg.platformTheme != null) (platformPackages.${cfg.platformTheme}) 145 + ++ lib.optionals (cfg.style != null) (stylePackages.${cfg.style}); 120 146 }; 121 147 }