qt: migrate to mkTarget (#2266)

Link: https://github.com/nix-community/stylix/pull/2266

Reviewed-by: Noah Biewesch <dev@noahbiewesch.com>
This commit is contained in:
0xda157 2026-06-05 11:27:27 -07:00 committed by GitHub
parent 6c382b2867
commit e3fcc65e63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 155 additions and 112 deletions

View file

@ -1,23 +1,27 @@
{
mkTarget,
pkgs,
config,
lib,
nixosConfig ? null,
...
}:
{
options.stylix.targets.qt = {
# TODO: Replace `nixosConfig != null` with
# `pkgs.stdenv.hostPlatform.isLinux` once [1] ("bug: setting qt.style.name
# = kvantum makes host systemd unusable") is resolved.
#
# [1]: https://github.com/nix-community/home-manager/issues/6565
enable = config.lib.stylix.mkEnableTargetWith {
name = "QT";
autoEnable = nixosConfig != null;
autoEnableExpr = "nixosConfig != null";
};
let
qtctSettings = attrs: {
qt5ctSettings = lib.mkIf (config.qt.platformTheme.name == "qtct") attrs;
qt6ctSettings = lib.mkIf (config.qt.platformTheme.name == "qtct") attrs;
};
in
mkTarget {
# TODO: Replace `nixosConfig != null` with
# `pkgs.stdenv.hostPlatform.isLinux` once [1] ("bug: setting qt.style.name
# = kvantum makes host systemd unusable") is resolved.
#
# [1]: https://github.com/nix-community/home-manager/issues/6565
autoEnable = nixosConfig != null;
autoEnableExpr = "nixosConfig != null";
options = {
platform = lib.mkOption {
description = ''
Selects the platform theme to use for Qt applications.
@ -28,7 +32,6 @@
type = lib.types.str;
default = "qtct";
};
standardDialogs = lib.mkOption {
description = ''
Selects the standard dialogs theme to be used by Qt.
@ -50,81 +53,106 @@
default = "default";
};
recommendedStyles.gnome = lib.mkOption {
internal = true;
type = lib.types.singleLineStr;
default = "adwaita";
};
};
config = lib.mkIf (config.stylix.enable && config.stylix.targets.qt.enable) (
let
icons =
if (config.stylix.polarity == "dark") then
config.stylix.icons.dark
else
config.stylix.icons.light;
config = [
(
{ cfg }:
let
recommendedStyles = {
gnome = cfg.recommendedStyles.gnome;
kde = "breeze";
qtct = "kvantum";
};
recommendedStyles = {
gnome = if config.stylix.polarity == "dark" then "adwaita-dark" else "adwaita";
kde = "breeze";
qtct = "kvantum";
};
recommendedStyle = recommendedStyles."${config.qt.platformTheme.name}" or null;
in
{
warnings =
(lib.optional (cfg.platform != "qtct")
"stylix: qt: `config.stylix.targets.qt.platform` other than 'qtct' are currently unsupported: ${cfg.platform}. Support may be added in the future."
)
++ (lib.optional (config.qt.style.name != recommendedStyle)
"stylix: qt: Changing `config.qt.style` is unsupported and may result in breakage! Use with caution!"
);
recommendedStyle = recommendedStyles."${config.qt.platformTheme.name}" or null;
kvantumPackage =
let
kvconfig = config.lib.stylix.colors {
template = ./kvconfig.mustache;
extension = ".kvconfig";
};
svg = config.lib.stylix.colors {
template = ./kvantum.svg.mustache;
extension = ".svg";
};
in
pkgs.runCommandLocal "base16-kvantum" { } ''
directory="$out/share/Kvantum/Base16Kvantum"
mkdir --parents "$directory"
cp ${kvconfig} "$directory/Base16Kvantum.kvconfig"
cp ${svg} "$directory/Base16Kvantum.svg"
'';
in
{
warnings =
(lib.optional (config.stylix.targets.qt.platform != "qtct")
"stylix: qt: `config.stylix.targets.qt.platform` other than 'qtct' are currently unsupported: ${config.stylix.targets.qt.platform}. Support may be added in the future."
)
++ (lib.optional (config.qt.style.name != recommendedStyle)
"stylix: qt: Changing `config.qt.style` is unsupported and may result in breakage! Use with caution!"
);
qt =
let
qtctSettings = {
qt = lib.mkMerge [
{
enable = true;
style.name = recommendedStyle;
platformTheme.name = cfg.platform;
}
(qtctSettings {
Appearance = {
custom_palette = true;
standard_dialogs = config.stylix.targets.qt.standardDialogs;
standard_dialogs = cfg.standardDialogs;
style = lib.mkIf (config.qt.style ? name) config.qt.style.name;
icon_theme = lib.mkIf (icons != null) icons;
};
Fonts = {
fixed = ''"${config.stylix.fonts.monospace.name},${toString config.stylix.fonts.sizes.applications}"'';
general = ''"${config.stylix.fonts.sansSerif.name},${toString config.stylix.fonts.sizes.applications}"'';
})
];
}
)
(
{ polarity }:
{
stylix.targets.qt.recommendedStyles.gnome =
if polarity == "dark" then "adwaita-dark" else "adwaita";
}
)
(
{ colors }:
let
kvantumPackage =
let
kvconfig = colors {
template = ./kvconfig.mustache;
extension = ".kvconfig";
};
};
in
{
svg = colors {
template = ./kvantum.svg.mustache;
extension = ".svg";
};
in
pkgs.runCommandLocal "base16-kvantum" { } ''
directory="$out/share/Kvantum/Base16Kvantum"
mkdir --parents "$directory"
cp ${kvconfig} "$directory/Base16Kvantum.kvconfig"
cp ${svg} "$directory/Base16Kvantum.svg"
'';
in
{
qt.kvantum = lib.mkIf (config.qt.style.name == "kvantum") {
enable = true;
style.name = recommendedStyle;
platformTheme.name = config.stylix.targets.qt.platform;
qt5ctSettings = lib.mkIf (config.qt.platformTheme.name == "qtct") qtctSettings;
qt6ctSettings = lib.mkIf (config.qt.platformTheme.name == "qtct") qtctSettings;
kvantum = lib.mkIf (config.qt.style.name == "kvantum") {
enable = true;
settings.General.theme = "Base16Kvantum";
themes = [ kvantumPackage ];
settings.General.theme = "Base16Kvantum";
themes = [ kvantumPackage ];
};
}
)
(
{ icons, polarity }:
{
qt = qtctSettings {
Appearance.icon_theme =
if (polarity == "dark") then icons.dark else icons.light;
};
}
)
(
{ fonts }:
{
qt = qtctSettings {
Fonts = {
fixed = ''"${fonts.monospace.name},${toString fonts.sizes.applications}"'';
general = ''"${fonts.sansSerif.name},${toString fonts.sizes.applications}"'';
};
};
}
);
}
)
];
}

View file

@ -1,14 +1,11 @@
{ lib, config, ... }:
let
recommendedStyle = {
gnome = if config.stylix.polarity == "dark" then "adwaita-dark" else "adwaita";
kde = "breeze";
qtct = "kvantum";
};
in
{
options.stylix.targets.qt = {
enable = config.lib.stylix.mkEnableTarget "QT" true;
mkTarget,
lib,
config,
...
}:
mkTarget {
options = {
platform = lib.mkOption {
description = ''
Selects the platform theme to use for Qt applications.
@ -18,31 +15,49 @@ in
type = lib.types.str;
default = "qtct";
};
_recommendedGnome = lib.mkOption {
internal = true;
type = lib.types.singleLineStr;
default = "adwaita";
};
};
config =
let
inherit (config.services.xserver.desktopManager) lxqt;
inherit (config.services.desktopManager) gnome plasma6;
in
lib.mkIf (config.stylix.enable && config.stylix.targets.qt.enable) {
stylix.targets.qt.platform =
if gnome.enable && !(plasma6.enable || lxqt.enable) then
"gnome"
else if plasma6.enable && !(gnome.enable || lxqt.enable) then
"kde"
else if lxqt.enable && !(gnome.enable || plasma6.enable) then
"lxqt"
else
"qtct";
qt = {
enable = true;
style = recommendedStyle."${config.qt.platformTheme}" or null;
platformTheme =
if config.stylix.targets.qt.platform == "qtct" then
"qt5ct"
config = [
(
{ cfg }:
let
recommendedStyle = {
gnome = cfg._recommendedGnome;
kde = "breeze";
qtct = "kvantum";
};
inherit (config.services.xserver.desktopManager) lxqt;
inherit (config.services.desktopManager) gnome plasma6;
in
{
stylix.targets.qt.platform =
if gnome.enable && !(plasma6.enable || lxqt.enable) then
"gnome"
else if plasma6.enable && !(gnome.enable || lxqt.enable) then
"kde"
else if lxqt.enable && !(gnome.enable || plasma6.enable) then
"lxqt"
else
config.stylix.targets.qt.platform;
};
};
"qtct";
qt = {
enable = true;
style = recommendedStyle."${config.qt.platformTheme}" or null;
platformTheme = if cfg.platform == "qtct" then "qt5ct" else cfg.platform;
};
}
)
(
{ polarity }:
{
stylix.targets.qt._recommendedGnome =
if polarity == "dark" then "adwaita-dark" else "adwaita";
}
)
];
}