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