fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Federico Rampazzoqt: remove qtstyleplugin-kvantum-qt41d813ff5

master
5.6 KiB183 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.qt;
8
9  # Maps known lowercase style names to style packages. Non-exhaustive.
10  stylePackages = with pkgs; {
11    bb10bright = libsForQt5.qtstyleplugins;
12    bb10dark = libsForQt5.qtstyleplugins;
13    cleanlooks = libsForQt5.qtstyleplugins;
14    gtk2 = libsForQt5.qtstyleplugins;
15    motif = libsForQt5.qtstyleplugins;
16    cde = libsForQt5.qtstyleplugins;
17    plastique = libsForQt5.qtstyleplugins;
18
19    adwaita = adwaita-qt;
20    adwaita-dark = adwaita-qt;
21    adwaita-highcontrast = adwaita-qt;
22    adwaita-highcontrastinverse = adwaita-qt;
23
24    breeze = libsForQt5.breeze-qt5;
25
26    kvantum =
27      [ libsForQt5.qtstyleplugin-kvantum qt6Packages.qtstyleplugin-kvantum ];
28  };
29
30in {
31  meta.maintainers = with maintainers; [ rycee thiagokokada ];
32
33  imports = [
34    (mkChangedOptionModule [ "qt" "useGtkTheme" ] [ "qt" "platformTheme" ]
35      (config:
36        if getAttrFromPath [ "qt" "useGtkTheme" ] config then "gtk" else null))
37  ];
38
39  options = {
40    qt = {
41      enable = mkEnableOption "Qt 4, 5 and 6 configuration";
42
43      platformTheme = mkOption {
44        type = types.nullOr (types.enum [ "gtk" "gnome" "qtct" "kde" ]);
45        default = null;
46        example = "gnome";
47        relatedPackages = [
48          "qgnomeplatform"
49          [ "libsForQt5" "qtstyleplugins" ]
50          [ "libsForQt5" "qt5ct" ]
51          [ "qt6Packages" "qt6ct" ]
52          [ "libsForQt5" "plasma-integration" ]
53          [ "libsForQt5" "systemsettings" ]
54        ];
55        description = ''
56          Platform theme to use for Qt applications.
57
58          The options are
59
60          `gtk`
61          : Use GTK theme with
62            [`qtstyleplugins`](https://github.com/qt/qtstyleplugins)
63
64          `gnome`
65          : Use GNOME theme with
66            [`qgnomeplatform`](https://github.com/FedoraQt/QGnomePlatform)
67
68          `qtct`
69          : Use Qt style set using
70            [`qt5ct`](https://github.com/desktop-app/qt5ct)
71            and [`qt6ct`](https://github.com/trialuser02/qt6ct)
72            applications
73
74          `kde`
75          : Use Qt settings from Plasma
76        '';
77      };
78
79      style = {
80        name = mkOption {
81          type = types.nullOr types.str;
82          default = null;
83          example = "adwaita-dark";
84          relatedPackages = [
85            "adwaita-qt"
86            [ "libsForQt5" "breeze-qt5" ]
87            [ "libsForQt5" "qtstyleplugins" ]
88            [ "libsForQt5" "qtstyleplugin-kvantum" ]
89            [ "qt6Packages" "qtstyleplugin-kvantum" ]
90          ];
91          description = ''
92            Style to use for Qt5/Qt6 applications. Case-insensitive.
93
94            Some examples are
95
96            `adwaita`, `adwaita-dark`, `adwaita-highcontrast`, `adwaita-highcontrastinverse`
97            : Use the Adwaita style from
98              [`adwaita-qt`](https://github.com/FedoraQt/adwaita-qt)
99
100            `breeze`
101            : Use the Breeze style from
102              [`breeze`](https://github.com/KDE/breeze)
103
104            `bb10bright`, `bb10dark`, `cde`, `cleanlooks`, `gtk2`, `motif`, `plastique`
105            : Use styles from
106              [`qtstyleplugins`](https://github.com/qt/qtstyleplugins)
107
108            `kvantum`
109            : Use styles from
110              [`kvantum`](https://github.com/tsujan/Kvantum)
111          '';
112        };
113
114        package = mkOption {
115          type = with types; nullOr (either package (listOf package));
116          default = null;
117          example = literalExpression "pkgs.adwaita-qt";
118          description = ''
119            Theme package to be used in Qt5/Qt6 applications.
120            Auto-detected from {option}`qt.style.name` if possible.
121          '';
122        };
123      };
124    };
125  };
126
127  config = let
128
129    # Necessary because home.sessionVariables doesn't support mkIf
130    envVars = filterAttrs (n: v: v != null) {
131      QT_QPA_PLATFORMTHEME = if cfg.platformTheme == "gtk" then
132        "gtk2"
133      else if cfg.platformTheme == "qtct" then
134        "qt5ct"
135      else
136        cfg.platformTheme;
137      QT_STYLE_OVERRIDE = cfg.style.name;
138    };
139
140  in mkIf (cfg.enable && cfg.platformTheme != null) {
141    assertions = [{
142      assertion = cfg.platformTheme == "gnome" -> cfg.style.name != null
143        && cfg.style.package != null;
144      message = ''
145        `qt.platformTheme` "gnome" must have `qt.style` set to a theme that
146        supports both Qt and Gtk, for example "adwaita", "adwaita-dark", or "breeze".
147      '';
148    }];
149
150    qt.style.package = mkIf (cfg.style.name != null)
151      (mkDefault (stylePackages.${toLower cfg.style.name} or null));
152
153    home.sessionVariables = envVars;
154
155    # Apply theming also to apps started by systemd.
156    systemd.user.sessionVariables = envVars;
157
158    home.packages = (if cfg.platformTheme == "gnome" then
159      [ pkgs.qgnomeplatform ]
160    else if cfg.platformTheme == "qtct" then [
161      pkgs.libsForQt5.qt5ct
162      pkgs.qt6Packages.qt6ct
163    ] else if cfg.platformTheme == "kde" then [
164      pkgs.libsForQt5.plasma-integration
165      pkgs.libsForQt5.systemsettings
166    ] else
167      [ pkgs.libsForQt5.qtstyleplugins ])
168      ++ lib.optionals (cfg.style.package != null)
169      (lib.toList cfg.style.package);
170
171    xsession.importedVariables = [ "QT_QPA_PLATFORMTHEME" ]
172      ++ lib.optionals (cfg.style.name != null) [ "QT_STYLE_OVERRIDE" ];
173
174    # Enable GTK+ style for Qt4 in Gtk/GNOME.
175    # It doesn’t support the platform theme packages.
176    home.activation.useGtkThemeInQt4 =
177      mkIf (cfg.platformTheme == "gtk" || cfg.platformTheme == "gnome")
178      (hm.dag.entryAfter [ "writeBoundary" ] ''
179        $DRY_RUN_CMD ${pkgs.crudini}/bin/crudini $VERBOSE_ARG \
180          --set "${config.xdg.configHome}/Trolltech.conf" Qt style GTK+
181      '');
182  };
183}