fork/home-manager
git clone https://git.julia.blue/fork/home-manager
1d813ff5
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . qt ; 8 9# Maps known lowercase style names to style packages. Non-exhaustive. 10stylePackages = with pkgs ; { 11bb10bright = libsForQt5 . qtstyleplugins ; 12bb10dark = libsForQt5 . qtstyleplugins ; 13cleanlooks = libsForQt5 . qtstyleplugins ; 14gtk2 = libsForQt5 . qtstyleplugins ; 15motif = libsForQt5 . qtstyleplugins ; 16cde = libsForQt5 . qtstyleplugins ; 17plastique = libsForQt5 . qtstyleplugins ; 18 19adwaita = adwaita-qt ; 20adwaita-dark = adwaita-qt ; 21adwaita-highcontrast = adwaita-qt ; 22adwaita-highcontrastinverse = adwaita-qt ; 23 24breeze = libsForQt5 . breeze-qt5 ; 25 26kvantum = 27[ libsForQt5 . qtstyleplugin-kvantum qt6Packages . qtstyleplugin-kvantum ]; 28}; 29 30in { 31meta . maintainers = with maintainers ; [ rycee thiagokokada ]; 32 33imports = [ 34( mkChangedOptionModule [ "qt" "useGtkTheme" ] [ "qt" "platformTheme" ] 35( config : 36if getAttrFromPath [ "qt" "useGtkTheme" ] config then "gtk" else null )) 37]; 38 39options = { 40qt = { 41enable = mkEnableOption "Qt 4, 5 and 6 configuration" ; 42 43platformTheme = mkOption { 44type = types . nullOr ( types . enum [ "gtk" "gnome" "qtct" "kde" ]); 45default = null ; 46example = "gnome" ; 47relatedPackages = [ 48"qgnomeplatform" 49[ "libsForQt5" "qtstyleplugins" ] 50[ "libsForQt5" "qt5ct" ] 51[ "qt6Packages" "qt6ct" ] 52[ "libsForQt5" "plasma-integration" ] 53[ "libsForQt5" "systemsettings" ] 54]; 55description = '' 56Platform theme to use for Qt applications. 57 58The options are 59 60`gtk` 61: Use GTK theme with 62[`qtstyleplugins`](https://github.com/qt/qtstyleplugins) 63 64`gnome` 65: Use GNOME theme with 66[`qgnomeplatform`](https://github.com/FedoraQt/QGnomePlatform) 67 68`qtct` 69: Use Qt style set using 70[`qt5ct`](https://github.com/desktop-app/qt5ct) 71and [`qt6ct`](https://github.com/trialuser02/qt6ct) 72applications 73 74`kde` 75: Use Qt settings from Plasma 76'' ; 77}; 78 79style = { 80name = mkOption { 81type = types . nullOr types . str ; 82default = null ; 83example = "adwaita-dark" ; 84relatedPackages = [ 85"adwaita-qt" 86[ "libsForQt5" "breeze-qt5" ] 87[ "libsForQt5" "qtstyleplugins" ] 88[ "libsForQt5" "qtstyleplugin-kvantum" ] 89[ "qt6Packages" "qtstyleplugin-kvantum" ] 90]; 91description = '' 92Style to use for Qt5/Qt6 applications. Case-insensitive. 93 94Some examples are 95 96`adwaita`, `adwaita-dark`, `adwaita-highcontrast`, `adwaita-highcontrastinverse` 97: Use the Adwaita style from 98[`adwaita-qt`](https://github.com/FedoraQt/adwaita-qt) 99 100`breeze` 101: Use the Breeze style from 102[`breeze`](https://github.com/KDE/breeze) 103 104`bb10bright`, `bb10dark`, `cde`, `cleanlooks`, `gtk2`, `motif`, `plastique` 105: Use styles from 106[`qtstyleplugins`](https://github.com/qt/qtstyleplugins) 107 108`kvantum` 109: Use styles from 110[`kvantum`](https://github.com/tsujan/Kvantum) 111'' ; 112}; 113 114package = mkOption { 115type = with types ; nullOr ( either package ( listOf package )); 116default = null ; 117example = literalExpression "pkgs.adwaita-qt" ; 118description = '' 119Theme package to be used in Qt5/Qt6 applications. 120Auto-detected from {option}`qt.style.name` if possible. 121'' ; 122}; 123}; 124}; 125}; 126 127config = let 128 129# Necessary because home.sessionVariables doesn't support mkIf 130envVars = filterAttrs ( n :v :v != null ) { 131QT_QPA_PLATFORMTHEME = if cfg . platformTheme == "gtk" then 132"gtk2" 133else if cfg . platformTheme == "qtct" then 134"qt5ct" 135else 136cfg . platformTheme ; 137QT_STYLE_OVERRIDE = cfg . style . name ; 138}; 139 140in mkIf ( cfg . enable && cfg . platformTheme != null ) { 141assertions = [{ 142assertion = cfg . platformTheme == "gnome" -> cfg . style . name != null 143&& cfg . style . package != null ; 144message = '' 145`qt.platformTheme` "gnome" must have `qt.style` set to a theme that 146supports both Qt and Gtk, for example "adwaita", "adwaita-dark", or "breeze". 147'' ; 148}]; 149 150qt . style . package = mkIf ( cfg . style . name != null ) 151( mkDefault ( stylePackages .${ toLower cfg . style . name } or null )); 152 153home . sessionVariables = envVars ; 154 155# Apply theming also to apps started by systemd. 156systemd . user . sessionVariables = envVars ; 157 158home . packages = ( if cfg . platformTheme == "gnome" then 159[ pkgs . qgnomeplatform ] 160else if cfg . platformTheme == "qtct" then [ 161pkgs . libsForQt5 . qt5ct 162pkgs . qt6Packages . qt6ct 163] else if cfg . platformTheme == "kde" then [ 164pkgs . libsForQt5 . plasma-integration 165pkgs . libsForQt5 . systemsettings 166] else 167[ pkgs . libsForQt5 . qtstyleplugins ]) 168++ lib . optionals ( cfg . style . package != null ) 169( lib . toList cfg . style . package ); 170 171xsession . importedVariables = [ "QT_QPA_PLATFORMTHEME" ] 172++ lib . optionals ( cfg . style . name != null ) [ "QT_STYLE_OVERRIDE" ]; 173 174# Enable GTK+ style for Qt4 in Gtk/GNOME. 175# It doesn’t support the platform theme packages. 176home . activation . useGtkThemeInQt4 = 177mkIf ( cfg . platformTheme == "gtk" || cfg . platformTheme == "gnome" ) 178( hm . dag . entryAfter [ "writeBoundary" ] '' 179$DRY_RUN_CMD ${ pkgs . crudini } /bin/crudini $VERBOSE_ARG \ 180--set " ${ config . xdg . configHome } /Trolltech.conf" Qt style GTK+ 181'' ); 182}; 183}