diff --git a/nixos/modules/config/qt5.nix b/nixos/modules/config/qt5.nix
index d9dec74f155..bc3be7068a0 100644
--- a/nixos/modules/config/qt5.nix
+++ b/nixos/modules/config/qt5.nix
@@ -6,13 +6,63 @@ let
cfg = config.qt5;
- isQGnome = cfg.platformTheme == "gnome" && cfg.style == "adwaita";
- isQtStyle = cfg.platformTheme == "gtk2" && cfg.style != "adwaita";
+ themeType = types.submodule {
+ options = {
+ package = mkOption {
+ internal = true;
+ type = types.nullOr types.package;
+ default = null;
+ };
+ name = mkOption {
+ internal = true;
+ type = types.str;
+ };
+ };
+ };
- packages = if isQGnome then [ pkgs.qgnomeplatform pkgs.adwaita-qt ]
- else if isQtStyle then [ pkgs.libsForQt5.qtstyleplugins ]
- else throw "`qt5.platformTheme` ${cfg.platformTheme} and `qt5.style` ${cfg.style} are not compatible.";
+ optionalPackage = opt:
+ optional (opt != null && opt.package != null) opt.package;
+ platforms = {
+ gtk2 = rec {
+ description = ''
+
+ gtk2
+ Use GTK2 theme with
+ qtstyleplugins
+
+
+ '';
+ styles = [ "cleanlooks" "gtk2" "cde" "motif" "plastique" ];
+
+ assertions = [
+ {
+ assertion = cfg.style != null && any (name: name == cfg.style.name) styles;
+ message = "`qt5.style.name` is not one of [ ${toString styles} ].";
+ }
+ ];
+ environment.variables.QT_QPA_PLATFORMTHEME = "gtk2";
+ environment.variables.QT_STYLE_OVERRIDE = cfg.style.name;
+ environment.systemPackages = [ pkgs.libsForQt5.qtstyleplugins ];
+ };
+ qgnomeplatform = {
+ description = ''
+
+ qgnomeplatform
+ Use GNOME theme with
+ qgnomeplatform
+
+
+ '';
+
+ environment.variables.QT_QPA_PLATFORMTHEME = "qgnomeplatform";
+ # TODO: make this optional once https://github.com/NixOS/nixpkgs/issues/54150 is fixed
+ # qgnomeplatform reads theme and other settings from dconf db
+ environment.variables.QT_STYLE_OVERRIDE = cfg.style.name;
+ environment.variables.XDG_DATA_DIRS = [ "${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}" ];
+ environment.systemPackages = [ pkgs.qgnomeplatform ];
+ };
+ };
in
{
@@ -23,80 +73,42 @@ in
enable = mkEnableOption "Qt5 theming configuration";
platformTheme = mkOption {
- type = types.enum [
- "gtk2"
- "gnome"
- ];
- example = "gnome";
- relatedPackages = [
- "qgnomeplatform"
- ["libsForQt5" "qtstyleplugins"]
- ];
+ type = types.enum (attrNames platforms);
+ example = head (attrNames platforms);
description = ''
Selects the platform theme to use for Qt5 applications.
The options are
-
- gtk
- Use GTK theme with
- qtstyleplugins
-
-
-
- gnome
- Use GNOME theme with
- qgnomeplatform
-
-
+ ${concatStrings (mapAttrsToList (name: value: value.description) platforms)}
'';
};
style = mkOption {
- type = types.enum [
- "adwaita"
- "cleanlooks"
- "gtk2"
- "motif"
- "plastique"
- ];
- example = "adwaita";
- relatedPackages = [
- "adwaita-qt"
- ["libsForQt5" "qtstyleplugins"]
- ];
- description = ''
- Selects the style to use for Qt5 applications.
- The options are
-
-
- adwaita
- Use Adwaita Qt style with
- adwaita
-
-
-
- cleanlooks
- gtk2
- motif
- plastique
- Use styles from
- qtstyleplugins
-
-
-
+ type = types.nullOr themeType;
+ default = null;
+ example = literalExample ''
+ {
+ name = "Breeze";
+ package = pkgs.breeze-qt5;
+ };
'';
+ description = "The Qt style to use.";
};
+
};
};
config = mkIf cfg.enable {
- environment.variables.QT_QPA_PLATFORMTHEME = cfg.platformTheme;
+ assertions = attrByPath [ cfg.platformTheme "assertions" ] [] platforms;
- environment.variables.QT_STYLE_OVERRIDE = cfg.style;
+ environment.variables = attrByPath [ cfg.platformTheme "environment" "variables" ] {} platforms;
- environment.systemPackages = packages;
+ environment.systemPackages = attrByPath [ cfg.platformTheme "environment" "systemPackages" ] [] platforms
+ ++ optionalPackage cfg.style;
};
+
+ meta.maintainers = with maintainers; [ worldofpeace gnidorah ];
}