vuls: init at 0.27.0
[NixPkgs.git] / nixos / modules / config / qt.nix
blobbf050f17620c47e8753b0dddd41b5a4cf8d352c1
1 { config, lib, pkgs, ... }:
3 let
4   cfg = config.qt;
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   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 ];
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 ];
28     breeze = [ libsForQt5.breeze-qt5 ];
30     kvantum = [ libsForQt5.qtstyleplugin-kvantum qt6Packages.qtstyleplugin-kvantum ];
31   };
34   meta.maintainers = with lib.maintainers; [ romildo thiagokokada ];
36   imports = [
37     (lib.mkRenamedOptionModule [ "qt5" "enable" ] [ "qt" "enable" ])
38     (lib.mkRenamedOptionModule [ "qt5" "platformTheme" ] [ "qt" "platformTheme" ])
39     (lib.mkRenamedOptionModule [ "qt5" "style" ] [ "qt" "style" ])
40   ];
42   options = {
43     qt = {
44       enable = lib.mkEnableOption "" // {
45         description = ''
46           Whether to enable Qt configuration, including theming.
48           Enabling this option is necessary for Qt plugins to work in the
49           installed profiles (e.g.: `nix-env -i` or `environment.systemPackages`).
50         '';
51       };
53       platformTheme = lib.mkOption {
54         type = with lib.types; nullOr (enum (lib.attrNames platformPackages));
55         default = null;
56         example = "gnome";
57         relatedPackages = [
58           "qgnomeplatform"
59           "qgnomeplatform-qt6"
60           [ "libsForQt5" "plasma-integration" ]
61           [ "libsForQt5" "qt5ct" ]
62           [ "libsForQt5" "qtstyleplugins" ]
63           [ "libsForQt5" "systemsettings" ]
64           [ "lxqt" "lxqt-config" ]
65           [ "lxqt" "lxqt-qtplugin" ]
66           [ "qt6Packages" "qt6ct" ]
67           [ "qt6Packages" "qt6gtk2" ]
68         ];
69         description = ''
70           Selects the platform theme to use for Qt applications.
72           The options are
73           - `gnome`: Use GNOME theme with [qgnomeplatform](https://github.com/FedoraQt/QGnomePlatform)
74           - `gtk2`: Use GTK theme with [qtstyleplugins](https://github.com/qt/qtstyleplugins)
75           - `kde`: Use Qt settings from Plasma.
76           - `lxqt`: Use LXQt style set using the [lxqt-config-appearance](https://github.com/lxqt/lxqt-config)
77              application.
78           - `qt5ct`: Use Qt style set using the [qt5ct](https://sourceforge.net/projects/qt5ct/)
79              and [qt6ct](https://github.com/trialuser02/qt6ct) applications.
80         '';
81       };
83       style = lib.mkOption {
84         type = with lib.types; nullOr (enum (lib.attrNames stylePackages));
85         default = null;
86         example = "adwaita";
87         relatedPackages = [
88           "adwaita-qt"
89           "adwaita-qt6"
90           [ "libsForQt5" "breeze-qt5" ]
91           [ "libsForQt5" "qtstyleplugin-kvantum" ]
92           [ "libsForQt5" "qtstyleplugins" ]
93           [ "qt6Packages" "qt6gtk2" ]
94           [ "qt6Packages" "qtstyleplugin-kvantum" ]
95         ];
96         description = ''
97           Selects the style to use for Qt applications.
99           The options are
100           - `adwaita`, `adwaita-dark`, `adwaita-highcontrast`, `adawaita-highcontrastinverse`:
101             Use Adwaita Qt style with
102             [adwaita](https://github.com/FedoraQt/adwaita-qt)
103           - `breeze`: Use the Breeze style from
104             [breeze](https://github.com/KDE/breeze)
105           - `bb10bright`, `bb10dark`, `cleanlooks`, `gtk2`, `motif`, `plastique`:
106             Use styles from
107             [qtstyleplugins](https://github.com/qt/qtstyleplugins)
108           - `kvantum`: Use styles from
109             [kvantum](https://github.com/tsujan/Kvantum)
110         '';
111       };
112     };
113   };
115   config = lib.mkIf cfg.enable {
116     assertions =
117       let
118         gnomeStyles = [
119           "adwaita"
120           "adwaita-dark"
121           "adwaita-highcontrast"
122           "adwaita-highcontrastinverse"
123           "breeze"
124         ];
125       in
126       [
127         {
128           assertion = cfg.platformTheme == "gnome" -> (builtins.elem cfg.style gnomeStyles);
129           message = ''
130             `qt.platformTheme` "gnome" must have `qt.style` set to a theme that supports both Qt and Gtk,
131             for example: ${lib.concatStringsSep ", " gnomeStyles}.
132           '';
133         }
134       ];
136     environment.variables = {
137       QT_QPA_PLATFORMTHEME = lib.mkIf (cfg.platformTheme != null) cfg.platformTheme;
138       QT_STYLE_OVERRIDE = lib.mkIf (cfg.style != null) cfg.style;
139     };
141     environment.profileRelativeSessionVariables =
142       let
143         qtVersions = with pkgs; [ qt5 qt6 ];
144       in
145       {
146         QT_PLUGIN_PATH = map (qt: "/${qt.qtbase.qtPluginPrefix}") qtVersions;
147         QML2_IMPORT_PATH = map (qt: "/${qt.qtbase.qtQmlPrefix}") qtVersions;
148       };
150     environment.systemPackages =
151       lib.optionals (cfg.platformTheme != null) (platformPackages.${cfg.platformTheme})
152       ++ lib.optionals (cfg.style != null) (stylePackages.${cfg.style});
153   };