From 379c3f685c925f57dc38805a602a96d2f35db130 Mon Sep 17 00:00:00 2001 From: gnidorah Date: Sun, 13 Oct 2019 08:38:32 +0300 Subject: [PATCH] nixos/qt5: extend qt5 theming support --- nixos/modules/config/qt5.nix | 120 ++++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) diff --git a/nixos/modules/config/qt5.nix b/nixos/modules/config/qt5.nix index bc3be7068a0e..fb3e03c4b3fe 100644 --- a/nixos/modules/config/qt5.nix +++ b/nixos/modules/config/qt5.nix @@ -6,6 +6,43 @@ let cfg = config.qt5; + toQtIni = generators.toINI { + mkKeyValue = key: value: + let + value' = + if isBool value then (if value then "true" else "false") + else toString value; + in + "${key}=${value'}"; + }; + + general = + optionalAttrs (cfg.font != null) + { + font = cfg.font.name; + menuFont = cfg.font.name; + toolBarFont = cfg.font.name; + } + // + optionalAttrs (cfg.style != null) + { widgetStyle = cfg.style.name; }; + icons = + optionalAttrs (cfg.iconTheme != null) + { Theme = cfg.iconTheme.name; }; + + fontType = types.submodule { + options = { + package = mkOption { + internal = true; + type = types.nullOr types.package; + default = null; + }; + name = mkOption { + internal = true; + type = types.str; + }; + }; + }; themeType = types.submodule { options = { package = mkOption { @@ -40,6 +77,10 @@ let assertion = cfg.style != null && any (name: name == cfg.style.name) styles; message = "`qt5.style.name` is not one of [ ${toString styles} ]."; } + { + assertion = cfg.font == null && cfg.iconTheme == null; + message = "`qt5.font` and `qt5.iconTheme` are only supported by kde platform."; + } ]; environment.variables.QT_QPA_PLATFORMTHEME = "gtk2"; environment.variables.QT_STYLE_OVERRIDE = cfg.style.name; @@ -55,6 +96,12 @@ let ''; + assertions = [ + { + assertion = cfg.font == null && cfg.iconTheme == null; + message = "`qt5.font` and `qt5.iconTheme` are only supported by kde platform."; + } + ]; 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 @@ -62,6 +109,47 @@ let environment.variables.XDG_DATA_DIRS = [ "${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}" ]; environment.systemPackages = [ pkgs.qgnomeplatform ]; }; + gtk3 = { + description = '' + + gtk3 + Use GNOME theme with + gtk3 + + + ''; + + assertions = [ + { + assertion = cfg.style != null; + message = "`qt5.platformTheme` gtk3 requires `qt5.style` to be set."; + } + { + assertion = cfg.font == null && cfg.iconTheme == null; + message = "`qt5.font` and `qt5.iconTheme` are only supported by kde platform."; + } + ]; + environment.variables.QT_QPA_PLATFORMTHEME = "gtk3"; + environment.variables.QT_STYLE_OVERRIDE = cfg.style.name; + }; + kde = { + description = '' + + kde + Use Qt theme with + qkdetheme + + + ''; + + environment.variables.XDG_CURRENT_DESKTOP = mkForce "KDE"; + environment.variables.KDE_SESSION_VERSION = "5"; + environment.etc."xdg/kdeglobals".text = + toQtIni { + General = general; + Icons = icons; + }; + }; }; in @@ -84,6 +172,32 @@ in ''; }; + font = mkOption { + type = types.nullOr fontType; + default = null; + example = literalExample '' + { + name = "Noto Sans,10,-1,5,50,0,0,0,0,0,Regular"; + package = pkgs.noto-fonts; + } + ''; + description = '' + The font to use in Qt applications. + ''; + }; + + iconTheme = mkOption { + type = types.nullOr themeType; + default = null; + example = literalExample '' + { + name = "breeze"; + package = pkgs.breeze-icons; + } + ''; + description = "The icon theme to use."; + }; + style = mkOption { type = types.nullOr themeType; default = null; @@ -105,8 +219,12 @@ in environment.variables = attrByPath [ cfg.platformTheme "environment" "variables" ] {} platforms; + environment.etc = attrByPath [ cfg.platformTheme "environment" "etc" ] {} platforms; + environment.systemPackages = attrByPath [ cfg.platformTheme "environment" "systemPackages" ] [] platforms - ++ optionalPackage cfg.style; + ++ optionalPackage cfg.font + ++ optionalPackage cfg.style + ++ optionalPackage cfg.iconTheme; };