diff --git a/modules/misc/qt.nix b/modules/misc/qt.nix index 0fe00d777..6bee4217e 100644 --- a/modules/misc/qt.nix +++ b/modules/misc/qt.nix @@ -8,6 +8,10 @@ let cfg = config.qt; + qtctFormat = pkgs.formats.ini { + listToValue = values: lib.concatStringsSep ", " values; + }; + # Map platform names to their packages. platformPackages = with pkgs; { gnome = [ @@ -286,7 +290,34 @@ in ''; }; }; - }; + } + // (lib.genAttrs' [ "qt5ct" "qt6ct" ] ( + name: + lib.nameValuePair "${name}Settings" ( + lib.mkOption { + type = lib.types.nullOr qtctFormat.type; + default = null; + example = lib.literalExpression '' + { + Appearance = { + style = "kvantum"; + icon_theme = "Papirus-Dark"; + standar_dialogs = "xdgdesktopportal"; + }; + Fonts = { + fixed = "\"DejaVuSansM Nerd Font Mono,12\""; + general = "\"DejaVu Sans,12\""; + }; + } + ''; + description = '' + Qtct configuration. Writes settings to `${name}/${name}.conf` + file. Lists will be translated to comma-separated strings. + Fonts must be quoted (see example). + ''; + } + ) + )); }; config = @@ -397,5 +428,18 @@ in ] ++ lib.optionals (platformTheme.name != null) [ "QT_QPA_PLATFORMTHEME" ] ++ lib.optionals (cfg.style.name != null) [ "QT_STYLE_OVERRIDE" ]; + + xdg.configFile = + lib.pipe + [ "qt5ct" "qt6ct" ] + [ + (lib.filter (qtct: cfg."${qtct}Settings" != null)) + (lib.flip lib.genAttrs' ( + qtct: + lib.nameValuePair "${qtct}/${qtct}.conf" { + source = qtctFormat.generate "${qtct}-config" cfg."${qtct}Settings"; + } + )) + ]; }; } diff --git a/tests/modules/misc/qt/default.nix b/tests/modules/misc/qt/default.nix index 88ba03f43..bfdfea91f 100644 --- a/tests/modules/misc/qt/default.nix +++ b/tests/modules/misc/qt/default.nix @@ -4,4 +4,7 @@ qt-platform-theme-gtk3 = ./qt-platform-theme-gtk3.nix; qt-platform-theme-gnome = ./qt-platform-theme-gnome.nix; qt-platform-theme-kde6-migration = ./qt-platform-theme-kde6-migration.nix; + qt-qt5ct-settings = ./qt-qt5ct-settings.nix; + qt-qt6ct-settings = ./qt-qt6ct-settings.nix; + qt-qtct-settings = ./qt-qtct-settings.nix; } diff --git a/tests/modules/misc/qt/qt-qt5ct-settings.nix b/tests/modules/misc/qt/qt-qt5ct-settings.nix new file mode 100644 index 000000000..152cdbf61 --- /dev/null +++ b/tests/modules/misc/qt/qt-qt5ct-settings.nix @@ -0,0 +1,13 @@ +{ + qt = { + enable = true; + qt5ctSettings = { + test_section.test_option = "test"; + }; + }; + + nmt.script = '' + assertFileExists "home-files/.config/qt5ct/qt5ct.conf" + assertPathNotExists "home-files/.config/qt6ct/qt6ct.conf" + ''; +} diff --git a/tests/modules/misc/qt/qt-qt6ct-settings.nix b/tests/modules/misc/qt/qt-qt6ct-settings.nix new file mode 100644 index 000000000..d363d8818 --- /dev/null +++ b/tests/modules/misc/qt/qt-qt6ct-settings.nix @@ -0,0 +1,13 @@ +{ + qt = { + enable = true; + qt6ctSettings = { + test_section.test_option = "test"; + }; + }; + + nmt.script = '' + assertFileExists "home-files/.config/qt6ct/qt6ct.conf" + assertPathNotExists "home-files/.config/qt5ct/qt5ct.conf" + ''; +} diff --git a/tests/modules/misc/qt/qt-qtct-settings.nix b/tests/modules/misc/qt/qt-qtct-settings.nix new file mode 100644 index 000000000..e58050096 --- /dev/null +++ b/tests/modules/misc/qt/qt-qtct-settings.nix @@ -0,0 +1,16 @@ +{ + qt = { + enable = true; + qt5ctSettings = { + test_section.test_option = "test"; + }; + qt6ctSettings = { + test_section.test_option = "test"; + }; + }; + + nmt.script = '' + assertFileExists "home-files/.config/qt5ct/qt5ct.conf" + assertFileExists "home-files/.config/qt6ct/qt6ct.conf" + ''; +}