qt: add kvantum options

This commit is contained in:
mikaeladev 2026-03-22 11:38:25 +00:00 committed by Austin Horstman
parent bc357c75e3
commit 61463d50fc
5 changed files with 218 additions and 0 deletions

132
modules/misc/qt/kvantum.nix Normal file
View file

@ -0,0 +1,132 @@
{
config,
lib,
pkgs,
...
}:
let
inherit (lib)
concatMapStringsSep
generators
literalExpression
mkIf
mkOption
types
;
kvconfigFormat = pkgs.formats.ini {
listToValue = concatMapStringsSep ", " (generators.mkValueStringDefault { });
};
kvconfigAtom = kvconfigFormat.lib.types.atom;
kvconfigSection = (types.attrsOf kvconfigAtom) // {
description = "section of a kvconfig file (attrs of ${kvconfigAtom.description})";
};
cfg = config.qt.kvantum;
in
{
options.qt.kvantum = {
settings = mkOption {
type = types.submodule {
freeformType = types.attrsOf kvconfigSection;
options = {
General = mkOption {
type = types.submodule {
freeformType = kvconfigSection;
options = {
theme = mkOption {
type = with types; nullOr str;
default = null;
example = "KvAdapta";
description = ''
The default Kvantum theme to use.
'';
};
};
};
default = { };
example = {
theme = "KvAdapta";
};
description = ''
General configuration settings for Kvantum.
'';
};
Applications = mkOption {
type = with types; attrsOf (listOf str);
default = { };
example = {
KvArc = [
"app1"
"app2"
];
KvFlat = [ "app3" ];
};
description = ''
Application configuration settings for Kvantum.
Themes set here will override {option}`qt.kvantum.settings.General.theme`
for their specific applications.
'';
};
};
};
default = { };
example = {
General = {
theme = "KvAdapta";
};
Applications = {
KvArc = [
"app1"
"app2"
];
KvFlat = [ "app3" ];
};
SomethingElse = {
foo = "bar";
};
};
description = ''
Global configuration settings written to {file}`$XDG_CONFIG_HOME/Kvantum/kvantum.kvconfig`.
'';
};
themes = mkOption {
type = with types; listOf package;
default = [ ];
example = literalExpression ''
with pkgs; [
gruvbox-kvantum
catppuccin-kvantum
]'';
description = ''
Theme packages to install to {file}`$XDG_CONFIG_HOME/Kvantum/`.
'';
};
};
config = {
xdg.configFile = {
"Kvantum" = mkIf (cfg.themes != [ ]) {
recursive = true;
source = pkgs.symlinkJoin {
name = "kvantum-themes";
paths = cfg.themes;
stripPrefix = "/share/Kvantum";
};
};
"Kvantum/kvantum.kvconfig" = mkIf (cfg.settings != { }) {
source = kvconfigFormat.generate "kvantum-config" cfg.settings;
};
};
};
}

View file

@ -45,6 +45,7 @@ let
./misc/pam.nix
./misc/qt.nix
./misc/qt/kconfig.nix
./misc/qt/kvantum.nix
./misc/shell.nix
./misc/specialisation.nix
./misc/submodule-support.nix

View file

@ -1,5 +1,7 @@
{
qt-basic = ./qt-basic.nix;
qt-kvantum-settings = ./qt-kvantum-settings.nix;
qt-kvantum-themes = ./qt-kvantum-themes.nix;
qt-platform-theme-gtk = ./qt-platform-theme-gtk.nix;
qt-platform-theme-gtk3 = ./qt-platform-theme-gtk3.nix;
qt-platform-theme-gnome = ./qt-platform-theme-gnome.nix;

View file

@ -0,0 +1,54 @@
{ pkgs, ... }:
{
qt = {
enable = true;
kvantum = {
settings = {
General = {
theme = "KvAdapta";
hello = "world";
};
Applications = {
KvArc = [
"app1"
"app2"
];
KvFlat = [ "app3" ];
};
SomethingElse = {
foo = "bar";
baz = [
"qux"
123
true
null
];
};
};
};
};
nmt.script =
let
configPath = "home-files/.config/Kvantum/kvantum.kvconfig";
expectedContent = pkgs.writeText "expected.kvconfig" ''
[Applications]
KvArc=app1, app2
KvFlat=app3
[General]
hello=world
theme=KvAdapta
[SomethingElse]
baz=qux, 123, true, null
foo=bar
'';
in
''
assertFileExists "${configPath}"
assertFileContent "${configPath}" "${expectedContent}"
'';
}

View file

@ -0,0 +1,29 @@
{ pkgs, ... }:
{
qt = {
enable = true;
kvantum = {
settings = {
general = {
theme = "KvAdapta";
};
};
themes = [
(pkgs.runCommand "kvantum-test-theme" { } ''
mkdir -p $out/share/Kvantum/TestTheme
touch $out/share/Kvantum/TestTheme/TestTheme.kvconfig
'')
];
};
};
nmt.script =
let
configDir = "home-files/.config/Kvantum";
in
''
assertFileExists "${configDir}/kvantum.kvconfig"
assertFileExists "${configDir}/TestTheme/TestTheme.kvconfig"
'';
}