nixos/qt5: refactor to support more platform themes

This commit is contained in:
gnidorah 2019-10-13 00:07:36 +03:00
parent 193e2ed86e
commit 23107a32c4

View File

@ -6,13 +6,63 @@ let
cfg = config.qt5; cfg = config.qt5;
isQGnome = cfg.platformTheme == "gnome" && cfg.style == "adwaita"; themeType = types.submodule {
isQtStyle = cfg.platformTheme == "gtk2" && cfg.style != "adwaita"; 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 ] optionalPackage = opt:
else if isQtStyle then [ pkgs.libsForQt5.qtstyleplugins ] optional (opt != null && opt.package != null) opt.package;
else throw "`qt5.platformTheme` ${cfg.platformTheme} and `qt5.style` ${cfg.style} are not compatible.";
platforms = {
gtk2 = rec {
description = ''
<varlistentry>
<term><literal>gtk2</literal></term>
<listitem><para>Use GTK2 theme with
<link xlink:href="https://github.com/qt/qtstyleplugins">qtstyleplugins</link>
</para></listitem>
</varlistentry>
'';
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 = ''
<varlistentry>
<term><literal>qgnomeplatform</literal></term>
<listitem><para>Use GNOME theme with
<link xlink:href="https://github.com/FedoraQt/QGnomePlatform">qgnomeplatform</link>
</para></listitem>
</varlistentry>
'';
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 in
{ {
@ -23,80 +73,42 @@ in
enable = mkEnableOption "Qt5 theming configuration"; enable = mkEnableOption "Qt5 theming configuration";
platformTheme = mkOption { platformTheme = mkOption {
type = types.enum [ type = types.enum (attrNames platforms);
"gtk2" example = head (attrNames platforms);
"gnome"
];
example = "gnome";
relatedPackages = [
"qgnomeplatform"
["libsForQt5" "qtstyleplugins"]
];
description = '' description = ''
Selects the platform theme to use for Qt5 applications.</para> Selects the platform theme to use for Qt5 applications.</para>
<para>The options are <para>The options are
<variablelist> <variablelist>
<varlistentry> ${concatStrings (mapAttrsToList (name: value: value.description) platforms)}
<term><literal>gtk</literal></term>
<listitem><para>Use GTK theme with
<link xlink:href="https://github.com/qt/qtstyleplugins">qtstyleplugins</link>
</para></listitem>
</varlistentry>
<varlistentry>
<term><literal>gnome</literal></term>
<listitem><para>Use GNOME theme with
<link xlink:href="https://github.com/FedoraQt/QGnomePlatform">qgnomeplatform</link>
</para></listitem>
</varlistentry>
</variablelist> </variablelist>
''; '';
}; };
style = mkOption { style = mkOption {
type = types.enum [ type = types.nullOr themeType;
"adwaita" default = null;
"cleanlooks" example = literalExample ''
"gtk2" {
"motif" name = "Breeze";
"plastique" package = pkgs.breeze-qt5;
]; };
example = "adwaita";
relatedPackages = [
"adwaita-qt"
["libsForQt5" "qtstyleplugins"]
];
description = ''
Selects the style to use for Qt5 applications.</para>
<para>The options are
<variablelist>
<varlistentry>
<term><literal>adwaita</literal></term>
<listitem><para>Use Adwaita Qt style with
<link xlink:href="https://github.com/FedoraQt/adwaita-qt">adwaita</link>
</para></listitem>
</varlistentry>
<varlistentry>
<term><literal>cleanlooks</literal></term>
<term><literal>gtk2</literal></term>
<term><literal>motif</literal></term>
<term><literal>plastique</literal></term>
<listitem><para>Use styles from
<link xlink:href="https://github.com/qt/qtstyleplugins">qtstyleplugins</link>
</para></listitem>
</varlistentry>
</variablelist>
''; '';
description = "The Qt style to use.";
}; };
}; };
}; };
config = mkIf cfg.enable { 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 ];
} }