at 23.11-pre 3.6 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.qt; 8 9 isQGnome = cfg.platformTheme == "gnome" && builtins.elem cfg.style ["adwaita" "adwaita-dark"]; 10 isQtStyle = cfg.platformTheme == "gtk2" && !(builtins.elem cfg.style ["adwaita" "adwaita-dark"]); 11 isQt5ct = cfg.platformTheme == "qt5ct"; 12 isLxqt = cfg.platformTheme == "lxqt"; 13 isKde = cfg.platformTheme == "kde"; 14 15 packages = 16 if isQGnome then [ 17 pkgs.qgnomeplatform 18 pkgs.adwaita-qt 19 pkgs.qgnomeplatform-qt6 20 pkgs.adwaita-qt6 21 ] 22 else if isQtStyle then [ pkgs.libsForQt5.qtstyleplugins ] 23 else if isQt5ct then [ pkgs.libsForQt5.qt5ct ] 24 else if isLxqt then [ pkgs.lxqt.lxqt-qtplugin pkgs.lxqt.lxqt-config ] 25 else if isKde then [ pkgs.libsForQt5.plasma-integration pkgs.libsForQt5.systemsettings ] 26 else throw "`qt.platformTheme` ${cfg.platformTheme} and `qt.style` ${cfg.style} are not compatible."; 27 28in 29 30{ 31 meta.maintainers = [ maintainers.romildo ]; 32 33 imports = [ 34 (mkRenamedOptionModule ["qt5" "enable" ] ["qt" "enable" ]) 35 (mkRenamedOptionModule ["qt5" "platformTheme" ] ["qt" "platformTheme" ]) 36 (mkRenamedOptionModule ["qt5" "style" ] ["qt" "style" ]) 37 ]; 38 39 options = { 40 qt = { 41 42 enable = mkEnableOption (lib.mdDoc "Qt theming configuration"); 43 44 platformTheme = mkOption { 45 type = types.enum [ 46 "gtk2" 47 "gnome" 48 "lxqt" 49 "qt5ct" 50 "kde" 51 ]; 52 example = "gnome"; 53 relatedPackages = [ 54 "qgnomeplatform" 55 "qgnomeplatform-qt6" 56 ["libsForQt5" "qtstyleplugins"] 57 ["libsForQt5" "qt5ct"] 58 ["lxqt" "lxqt-qtplugin"] 59 ["libsForQt5" "plasma-integration"] 60 ]; 61 description = lib.mdDoc '' 62 Selects the platform theme to use for Qt applications. 63 64 The options are 65 - `gtk`: Use GTK theme with [qtstyleplugins](https://github.com/qt/qtstyleplugins) 66 - `gnome`: Use GNOME theme with [qgnomeplatform](https://github.com/FedoraQt/QGnomePlatform) 67 - `lxqt`: Use LXQt style set using the [lxqt-config-appearance](https://github.com/lxqt/lxqt-config) 68 application. 69 - `qt5ct`: Use Qt style set using the [qt5ct](https://sourceforge.net/projects/qt5ct/) 70 application. 71 - `kde`: Use Qt settings from Plasma. 72 ''; 73 }; 74 75 style = mkOption { 76 type = types.enum [ 77 "adwaita" 78 "adwaita-dark" 79 "cleanlooks" 80 "gtk2" 81 "motif" 82 "plastique" 83 ]; 84 example = "adwaita"; 85 relatedPackages = [ 86 "adwaita-qt" 87 "adwaita-qt6" 88 ["libsForQt5" "qtstyleplugins"] 89 ]; 90 description = lib.mdDoc '' 91 Selects the style to use for Qt applications. 92 93 The options are 94 - `adwaita`, `adwaita-dark`: Use Adwaita Qt style with 95 [adwaita](https://github.com/FedoraQt/adwaita-qt) 96 - `cleanlooks`, `gtk2`, `motif`, `plastique`: Use styles from 97 [qtstyleplugins](https://github.com/qt/qtstyleplugins) 98 ''; 99 }; 100 }; 101 }; 102 103 config = mkIf cfg.enable { 104 105 environment.variables = { 106 QT_QPA_PLATFORMTHEME = cfg.platformTheme; 107 QT_STYLE_OVERRIDE = mkIf (! (isQt5ct || isLxqt || isKde)) cfg.style; 108 }; 109 110 environment.profileRelativeSessionVariables = let 111 qtVersions = with pkgs; [ qt5 qt6 ]; 112 in { 113 QT_PLUGIN_PATH = map (qt: "/${qt.qtbase.qtPluginPrefix}") qtVersions; 114 QML2_IMPORT_PATH = map (qt: "/${qt.qtbase.qtQmlPrefix}") qtVersions; 115 }; 116 117 environment.systemPackages = packages; 118 119 }; 120}