Skip to content

Commit

Permalink
feat(qt): integrate qt hm module with NixOS for sensible defaults
Browse files Browse the repository at this point in the history
These changes make the PR apply the Kvatum theme only when appropriate
and creates the framework to allow for Qt styling based on the DE.
  • Loading branch information
Mikilio committed Jan 18, 2025
1 parent 513b62b commit cf84325
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 47 deletions.
120 changes: 73 additions & 47 deletions modules/qt/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,88 @@
config,
lib,
...
}: {
}:
{
options.stylix.targets.qt = {
enable = config.lib.stylix.mkEnableTarget "QT" pkgs.stdenv.hostPlatform.isLinux;
iconThemeName = lib.mkOption {
description = "Default QT Icons";
platform = lib.mkOption {
description = ''
Platform for QT.
Defaults to the standard platform of the configured DE in NixOS when
`stylix.homeManagerIntegration.followSystem = true`.
Fallback to qtct.
'';
type = lib.types.str;
default = "ePapirus-Dark";
default = "qtct";
};
};

config = lib.mkIf config.stylix.targets.qt.enable (let
cfg = config.stylix.targets.qt;
kvconfig = config.lib.stylix.colors {
template = ./kvconfig.mustache;
extension = ".kvconfig";
};
svg = config.lib.stylix.colors {
template = ./kvantum-svg.mustache;
extension = "svg";
};
kvantumPackage = pkgs.runCommandLocal "base16-kvantum" {} ''
directory="$out/share/Kvantum/Base16Kvantum"
mkdir --parents "$directory"
cat ${kvconfig} >>"$directory/Base16Kvantum.kvconfig"
cat ${svg} >>"$directory/Base16Kvantum.svg"
'';
in {
home.packages = with pkgs; [
qt5ct
libsForQt5.qtstyleplugin-kvantum
qt6Packages.qtstyleplugin-kvantum
kvantumPackage
papirus-icon-theme
];
config = lib.mkIf config.stylix.targets.qt.enable (
let
cfg = config.stylix;
iconTheme =
if (cfg.polarity == "dark") then cfg.iconTheme.dark else cfg.iconTheme.light;

qt = {
enable = true;
platformTheme.name = "qtct";
};
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"
ln -s ${kvconfig} "$directory/Base16Kvantum.kvconfig"
ln -s ${svg} "$directory/Base16Kvantum.svg"
'';
in
{
warnings = lib.optional (cfg.platform != "qtct") ''
Stylix has not yet implemented qt styling for any platforms other than "qtct".
We are working on it.
'';

xdg.configFile."Kvantum/kvantum.kvconfig".source = (pkgs.formats.ini {}).generate "kvantum.kvconfig" {
General.theme = "Base16Kvantum";
};
home.packages = lib.optional (config.qt.style.name == "kvantum") kvantumPackage;

qt = {
enable = true;
style.name =
if cfg.targets.qt.platform == "qtct" then "kvantum" else lib.mkDefault null;
platformTheme.name = cfg.targets.qt.platform;
};

xdg.configFile."Kvantum/Base16Kvantum".source = "${kvantumPackage}/share/Kvantum/Base16Kvantum";
xdg.configFile = lib.mkMerge [
(lib.mkIf (config.qt.style.name == "kvantum") {
"Kvantum/kvantum.kvconfig".source =
(pkgs.formats.ini { }).generate "kvantum.kvconfig"
{
General.theme = "Base16Kvantum";
};

xdg.configFile."qt5ct/qt5ct.conf".text = ''
[Appearance]
style=kvantum
icon_theme=${cfg.iconThemeName}
'';
"Kvantum/Base16Kvantum".source =
"${kvantumPackage}/share/Kvantum/Base16Kvantum";
})

xdg.configFile."qt6ct/qt6ct.conf".text = ''
[Appearance]
style=kvantum
icon_theme=${cfg.iconThemeName}
'';
});
(lib.mkIf (config.qt.platformTheme == "qtct") {
"qt5ct/qt5ct.conf".text = ''
[Appearance]
style=${config.qt.style.name}
icon_theme=${iconTheme}
'';
"qt6ct/qt6ct.conf".text = ''
[Appearance]
style=${config.qt.style.name}
icon_theme=${iconTheme}
'';
})
];
}
);
}
57 changes: 57 additions & 0 deletions modules/qt/nixos.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
lib,
pkgs,
config,
...
}:

let

recommendedStyle = {
gnome = if config.stylix.polarity == "dark" then "adwaita-dark" else "adawaita";
kde = "breeze";
qtct = "kvantum";
};

in
{
options.stylix.targets.qt = {
enable = config.lib.stylix.mkEnableTarget "QT" pkgs.stdenv.hostPlatform.isLinux;
platform = lib.mkOption {
description = ''
Platform for QT.
Defaults to the standard platform of the configured DE.
Fallback to qtct.
'';
type = lib.types.str;
default = "qtct";
};
};

config = lib.mkIf (config.stylix.enable && config.stylix.targets.qt.enable) {

stylix.targets.qt.platform =
if config.services.xserver.desktopManager.gnome.enable then
lib.mkDefault "gnome"
else if config.services.xserver.desktopManager.plasma5.enable then
lib.mkDefault "kde"
else if config.services.xserver.desktopManager.lxqt.enable then
lib.mkDefault "lxqt"
else
lib.mkDefault "qt5ct";
qt = {
enable = true;
style = lib.mkIf (
recommendedStyle ? "${config.qt.platformTheme}"
) recommendedStyle."${config.qt.platformTheme}";
platformTheme =
if config.stylix.targets.qt.platform == "qtct" then
"qt5ct"
else
config.stylix.targets.qt.platform;
};

};
}
8 changes: 8 additions & 0 deletions stylix/home-manager-integration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ let
"polarity"
];
}
{
path = [
"stylix"
"targets"
"qt"
"platform"
];
}
];

in
Expand Down

0 comments on commit cf84325

Please sign in to comment.