at 25.11-pre 6.7 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.qt; 9 10 platformPackages = with pkgs; { 11 gnome = [ 12 qgnomeplatform 13 qgnomeplatform-qt6 14 ]; 15 gtk2 = [ 16 libsForQt5.qtstyleplugins 17 qt6Packages.qt6gtk2 18 ]; 19 kde = [ 20 libsForQt5.kio 21 libsForQt5.plasma-integration 22 libsForQt5.systemsettings 23 ]; 24 kde6 = [ 25 kdePackages.kio 26 kdePackages.plasma-integration 27 kdePackages.systemsettings 28 ]; 29 lxqt = [ 30 lxqt.lxqt-qtplugin 31 lxqt.lxqt-config 32 ]; 33 qt5ct = [ 34 libsForQt5.qt5ct 35 qt6Packages.qt6ct 36 ]; 37 }; 38 39 # Maps style names to their QT_QPA_PLATFORMTHEME, if necessary. 40 styleNames = { 41 kde6 = "kde"; 42 }; 43 44 stylePackages = with pkgs; { 45 bb10bright = [ libsForQt5.qtstyleplugins ]; 46 bb10dark = [ libsForQt5.qtstyleplugins ]; 47 cde = [ libsForQt5.qtstyleplugins ]; 48 cleanlooks = [ libsForQt5.qtstyleplugins ]; 49 gtk2 = [ 50 libsForQt5.qtstyleplugins 51 qt6Packages.qt6gtk2 52 ]; 53 motif = [ libsForQt5.qtstyleplugins ]; 54 plastique = [ libsForQt5.qtstyleplugins ]; 55 56 adwaita = [ 57 adwaita-qt 58 adwaita-qt6 59 ]; 60 adwaita-dark = [ 61 adwaita-qt 62 adwaita-qt6 63 ]; 64 adwaita-highcontrast = [ 65 adwaita-qt 66 adwaita-qt6 67 ]; 68 adwaita-highcontrastinverse = [ 69 adwaita-qt 70 adwaita-qt6 71 ]; 72 73 breeze = [ 74 libsForQt5.breeze-qt5 75 kdePackages.breeze 76 ]; 77 78 kvantum = [ 79 libsForQt5.qtstyleplugin-kvantum 80 qt6Packages.qtstyleplugin-kvantum 81 ]; 82 }; 83in 84{ 85 meta.maintainers = with lib.maintainers; [ 86 romildo 87 thiagokokada 88 ]; 89 90 imports = [ 91 (lib.mkRenamedOptionModule [ "qt5" "enable" ] [ "qt" "enable" ]) 92 (lib.mkRenamedOptionModule [ "qt5" "platformTheme" ] [ "qt" "platformTheme" ]) 93 (lib.mkRenamedOptionModule [ "qt5" "style" ] [ "qt" "style" ]) 94 ]; 95 96 options = { 97 qt = { 98 enable = lib.mkEnableOption "" // { 99 description = '' 100 Whether to enable Qt configuration, including theming. 101 102 Enabling this option is necessary for Qt plugins to work in the 103 installed profiles (e.g.: `nix-env -i` or `environment.systemPackages`). 104 ''; 105 }; 106 107 platformTheme = lib.mkOption { 108 type = with lib.types; nullOr (enum (lib.attrNames platformPackages)); 109 default = null; 110 example = "gnome"; 111 relatedPackages = [ 112 "qgnomeplatform" 113 "qgnomeplatform-qt6" 114 [ 115 "libsForQt5" 116 "plasma-integration" 117 ] 118 [ 119 "libsForQt5" 120 "qt5ct" 121 ] 122 [ 123 "libsForQt5" 124 "qtstyleplugins" 125 ] 126 [ 127 "libsForQt5" 128 "systemsettings" 129 ] 130 [ 131 "kdePackages" 132 "plasma-integration" 133 ] 134 [ 135 "kdePackages" 136 "systemsettings" 137 ] 138 [ 139 "lxqt" 140 "lxqt-config" 141 ] 142 [ 143 "lxqt" 144 "lxqt-qtplugin" 145 ] 146 [ 147 "qt6Packages" 148 "qt6ct" 149 ] 150 [ 151 "qt6Packages" 152 "qt6gtk2" 153 ] 154 ]; 155 description = '' 156 Selects the platform theme to use for Qt applications. 157 158 The options are 159 - `gnome`: Use GNOME theme with [qgnomeplatform](https://github.com/FedoraQt/QGnomePlatform) 160 - `gtk2`: Use GTK theme with [qtstyleplugins](https://github.com/qt/qtstyleplugins) 161 - `kde`: Use Qt settings from Plasma 5. 162 - `kde6`: Use Qt settings from Plasma 6. 163 - `lxqt`: Use LXQt style set using the [lxqt-config-appearance](https://github.com/lxqt/lxqt-config) 164 application. 165 - `qt5ct`: Use Qt style set using the [qt5ct](https://sourceforge.net/projects/qt5ct/) 166 and [qt6ct](https://github.com/trialuser02/qt6ct) applications. 167 ''; 168 }; 169 170 style = lib.mkOption { 171 type = with lib.types; nullOr (enum (lib.attrNames stylePackages)); 172 default = null; 173 example = "adwaita"; 174 relatedPackages = [ 175 "adwaita-qt" 176 "adwaita-qt6" 177 [ 178 "libsForQt5" 179 "breeze-qt5" 180 ] 181 [ 182 "libsForQt5" 183 "qtstyleplugin-kvantum" 184 ] 185 [ 186 "libsForQt5" 187 "qtstyleplugins" 188 ] 189 [ 190 "qt6Packages" 191 "qt6gtk2" 192 ] 193 [ 194 "qt6Packages" 195 "qtstyleplugin-kvantum" 196 ] 197 ]; 198 description = '' 199 Selects the style to use for Qt applications. 200 201 The options are 202 - `adwaita`, `adwaita-dark`, `adwaita-highcontrast`, `adawaita-highcontrastinverse`: 203 Use Adwaita Qt style with 204 [adwaita](https://github.com/FedoraQt/adwaita-qt) 205 - `breeze`: Use the Breeze style from 206 [breeze](https://github.com/KDE/breeze) 207 - `bb10bright`, `bb10dark`, `cleanlooks`, `gtk2`, `motif`, `plastique`: 208 Use styles from 209 [qtstyleplugins](https://github.com/qt/qtstyleplugins) 210 - `kvantum`: Use styles from 211 [kvantum](https://github.com/tsujan/Kvantum) 212 ''; 213 }; 214 }; 215 }; 216 217 config = lib.mkIf cfg.enable { 218 assertions = 219 let 220 gnomeStyles = [ 221 "adwaita" 222 "adwaita-dark" 223 "adwaita-highcontrast" 224 "adwaita-highcontrastinverse" 225 "breeze" 226 ]; 227 in 228 [ 229 { 230 assertion = cfg.platformTheme == "gnome" -> (builtins.elem cfg.style gnomeStyles); 231 message = '' 232 `qt.platformTheme` "gnome" must have `qt.style` set to a theme that supports both Qt and Gtk, 233 for example: ${lib.concatStringsSep ", " gnomeStyles}. 234 ''; 235 } 236 ]; 237 238 environment.variables = { 239 QT_QPA_PLATFORMTHEME = 240 lib.mkIf (cfg.platformTheme != null) 241 styleNames.${cfg.platformTheme} or cfg.platformTheme; 242 QT_STYLE_OVERRIDE = lib.mkIf (cfg.style != null) cfg.style; 243 }; 244 245 environment.profileRelativeSessionVariables = 246 let 247 qtVersions = with pkgs; [ 248 qt5 249 qt6 250 ]; 251 in 252 { 253 QT_PLUGIN_PATH = map (qt: "/${qt.qtbase.qtPluginPrefix}") qtVersions; 254 QML2_IMPORT_PATH = map (qt: "/${qt.qtbase.qtQmlPrefix}") qtVersions; 255 }; 256 257 environment.systemPackages = 258 lib.optionals (cfg.platformTheme != null) (platformPackages.${cfg.platformTheme}) 259 ++ lib.optionals (cfg.style != null) (stylePackages.${cfg.style}); 260 }; 261}