@@ -1,25 +1,37 @@
{ config , lib , pkgs , . . . }:
with lib ;
let
cfg = config . qt ;
# Map platform names to their packages.
platformPackages = with pkgs ; {
gnome = [ qgnomeplatform qgnomeplatform-qt6 ] ;
gtk = [ libsForQt5 . qtstyleplugins qt6Packages . qt6gtk2 ] ;
kde = [ libsForQt5 . plasma-integration libsForQt5 . systemsettings ] ;
lxqt = [ lxqt . lxqt-qtplugin lxqt . lxqt-config ] ;
qtct = [ libsForQt5 . qt5ct qt6Packages . qt6ct ] ;
} ;
# Maps style names to their QT_QPA_PLATFORMTHEME, if necessary.
styleNames = {
gtk = " g t k 2 " ;
qtct = " q t 5 c t " ;
} ;
# Maps known lowercase style names to style packages. Non-exhaustive.
stylePackages = with pkgs ; {
bb10bright = libsForQt5 . qtstyleplugins ;
bb10dark = libsForQt5 . qtstyleplugins ;
cleanlooks = libsForQt5 . qtstyleplugins ;
gtk2 = libsForQt5 . qtstyleplugins ;
gtk2 = [ libsForQt5 . qtstyleplugins qt6Packages . qt6gtk2 ] ;
motif = libsForQt5 . qtstyleplugins ;
cde = libsForQt5 . qtstyleplugins ;
plastique = libsForQt5 . qtstyleplugins ;
adwaita = adwaita-qt ;
adwaita-dark = adwaita-qt ;
adwaita-highcontrast = adwaita-qt ;
adwaita-highcontrastinverse = adwaita-qt ;
adwaita = [ adwaita-qt adwaita-qt6 ] ;
adwaita-dark = [ adwaita-qt adwaita-qt6 ] ;
adwaita-highcontrast = [ adwaita-qt adwaita-qt6 ] ;
adwaita-highcontrastinverse = [ adwaita-qt adwaita-qt6 ] ;
breeze = libsForQt5 . breeze-qt5 ;
@@ -28,29 +40,37 @@ let
} ;
in {
meta . maintainers = with maintainers ; [ rycee thiagokokada ] ;
meta . maintainers = with lib . maintainers; [ rycee thiagokokada ] ;
imports = [
( mkChangedOptionModule [ " q t " " u s e G t k T h e m e " ] [ " q t " " p l a t f o r m T h e m e " ]
( lib . mkChangedOptionModule [ " q t " " u s e G t k T h e m e " ] [ " q t " " p l a t f o r m T h e m e " ]
( config :
if getAttrFromPath [ " q t " " u s e G t k T h e m e " ] config then " g t k " else null ) )
if lib . getAttrFromPath [ " q t " " u s e G t k T h e m e " ] config then
" g t k "
else
null ) )
] ;
options = {
qt = {
enable = mkEnableOption " Q t 4 , 5 a n d 6 c o n f i g u r a t i o n " ;
enable = lib . mkEnableOption " Q t 5 a n d 6 c o n f i g u r a t i o n " ;
platformTheme = mkOption {
type = types . nullOr ( types . enum [ " g t k " " g n o m e " " q t c t " " k d e " ] ) ;
platformTheme = lib . mkOption {
type = with lib . types ;
nullOr ( enum [ " g t k " " g t k 3 " " g n o m e " " l x q t " " q t c t " " k d e " ] ) ;
default = null ;
example = " g n o m e " ;
relatedPackages = [
" q g n o m e p l a t f o r m "
[ " l i b s F o r Q t 5 " " q t s t y l e p l u g i n s " ]
[ " l i b s F o r Q t 5 " " q t 5 c t " ]
[ " q t 6 P a c k a g e s " " q t 6 c t " ]
" q g n o m e p l a t f o r m - q t 6 "
[ " l i b s F o r Q t 5 " " p l a s m a - i n t e g r a t i o n " ]
[ " l i b s F o r Q t 5 " " q t 5 c t " ]
[ " l i b s F o r Q t 5 " " q t s t y l e p l u g i n s " ]
[ " l i b s F o r Q t 5 " " s y s t e m s e t t i n g s " ]
[ " l x q t " " l x q t - c o n f i g " ]
[ " l x q t " " l x q t - q t p l u g i n " ]
[ " q t 6 P a c k a g e s " " q t 6 c t " ]
[ " q t 6 P a c k a g e s " " q t 6 g t k 2 " ]
] ;
description = ''
P l a t f o r m t h e m e t o u s e f o r Q t a p p l i c a t i o n s .
@@ -61,10 +81,19 @@ in {
: U s e G T K t h e m e w i t h
[ ` q t s t y l e p l u g i n s ` ] ( h t t p s : / / g i t h u b . c o m / q t / q t s t y l e p l u g i n s )
` g t k 3 `
: U s e [ G T K 3 i n t e g r a t i o n ] ( h t t p s : / / g i t h u b . c o m / q t / q t b a s e / t r e e / d e v / s r c / p l u g i n s / p l a t f o r m t h e m e s / g t k 3 )
f o r f i l e p i c k e r d i a l o g s , f o n t a n d t h e m e c o n f i g u r a t i o n
` g n o m e `
: U s e G N O M E t h e m e w i t h
[ ` q g n o m e p l a t f o r m ` ] ( h t t p s : / / g i t h u b . c o m / F e d o r a Q t / Q G n o m e P l a t f o r m )
` l x q t `
: U s e L X Q t t h e m e s t y l e s e t u s i n g t h e
[ ` l x q t - c o n f i g - a p p e a r a n c e ` ] ( h t t p s : / / g i t h u b . c o m / l x q t / l x q t - c o n f i g )
a p p l i c a t i o n
` q t c t `
: U s e Q t s t y l e s e t u s i n g
[ ` q t 5 c t ` ] ( h t t p s : / / g i t h u b . c o m / d e s k t o p - a p p / q t 5 c t )
@@ -77,15 +106,17 @@ in {
} ;
style = {
name = mkOption {
type = types . nullOr types . str ;
name = lib . mkOption {
type = with lib . types ; nullOr str ;
default = null ;
example = " a d w a i t a - d a r k " ;
relatedPackages = [
" a d w a i t a - q t "
" a d w a i t a - q t 6 "
[ " l i b s F o r Q t 5 " " b r e e z e - q t 5 " ]
[ " l i b s F o r Q t 5 " " q t s t y l e p l u g i n s " ]
[ " l i b s F o r Q t 5 " " q t s t y l e p l u g i n - k v a n t u m " ]
[ " l i b s F o r Q t 5 " " q t s t y l e p l u g i n s " ]
[ " q t 6 P a c k a g e s " " q t 6 g t k 2 " ]
[ " q t 6 P a c k a g e s " " q t s t y l e p l u g i n - k v a n t u m " ]
] ;
description = ''
@@ -111,10 +142,10 @@ in {
'' ;
} ;
package = mkOption {
type = with types ; nullOr ( either package ( listOf package ) ) ;
package = lib . mkOption {
type = with lib . types; nullOr ( either package ( listOf package ) ) ;
default = null ;
example = literalExpression " p k g s . a d w a i t a - q t " ;
example = lib . literalExpression " p k g s . a d w a i t a - q t " ;
description = ''
T h e m e p a c k a g e t o b e u s e d i n Q t 5 / Q t 6 a p p l i c a t i o n s .
A u t o - d e t e c t e d f r o m { o p t i o n } ` q t . s t y l e . n a m e ` i f p o s s i b l e .
@@ -127,17 +158,26 @@ in {
config = let
# Necessary because home.sessionVariables doesn't support mkIf
envVars = filterAttrs ( n : v : v != null ) {
QT_QPA_PLATFORMTHEME = if cfg . platformTheme = = " g t k " then
" g t k 2 "
else if cfg . platformTheme = = " q t c t " then
" q t 5 c t "
else
cfg . platformTheme ;
envVars = lib . filterAttrs ( n : v : v != null ) {
QT_QPA_PLATFORMTHEME =
styleNames . ${ cfg . platformTheme } or cfg . platformTheme ;
QT_STYLE_OVERRIDE = cfg . style . name ;
} ;
in mkIf ( cfg . enable && cfg . platformTheme ! = null ) {
envVarsExtra = let
inherit ( config . home ) profileDirectory ;
qtVersions = with pkgs ; [ qt5 qt6 ] ;
makeQtPath = prefix :
lib . concatStringsSep " : "
( map ( qt : " ${ profileDirectory } / ${ qt . qtbase . ${ prefix } } " ) qtVersions ) ;
in {
QT_PLUGIN_PATH = " $ Q T _ P L U G I N _ P A T H \$ { Q T _ P L U G I N _ P A T H : + : } "
+ ( makeQtPath " q t P l u g i n P r e f i x " ) ;
QML2_IMPORT_PATH = " $ Q M L 2 _ I M P O R T _ P A T H \$ { Q M L 2 _ I M P O R T _ P A T H : + : } "
+ ( makeQtPath " q t Q m l P r e f i x " ) ;
} ;
in lib . mkIf cfg . enable {
assertions = [ {
assertion = cfg . platformTheme = = " g n o m e " -> cfg . style . name != null
&& cfg . style . package != null ;
@@ -147,37 +187,31 @@ in {
'' ;
} ] ;
qt . style . package = mkIf ( cfg . style . name != null )
( mkDefault ( stylePackages . ${ toLower cfg . style . name } or null ) ) ;
qt . style . package = lib . mkIf ( cfg . style . name != null )
( lib . mkDefault ( stylePackages . ${ lib . toLower cfg . style . name } or null ) ) ;
home . sessionVariables = envVars ;
home = {
sessionVariables = envVars ;
# home.sessionVariables does not support setting the same environment
# variable to different values.
# Since some other modules may set the QT_PLUGIN_PATH or QML2_IMPORT_PATH
# to their own value, e.g.: fcitx5, we avoid conflicts by setting
# the values in home.sessionVariablesExtra instead.
sessionVariablesExtra = ''
e x p o r t Q T _ P L U G I N _ P A T H = ${ envVarsExtra . QT_PLUGIN_PATH }
e x p o r t Q M L 2 _ I M P O R T _ P A T H = ${ envVarsExtra . QML2_IMPORT_PATH }
'' ;
} ;
# Apply theming also to apps started by systemd.
systemd . user . sessionVariables = envVars ;
systemd . user . sessionVariables = envVars // envVarsExtra ;
home . packages = ( if cfg . platformTheme = = " g n o m e " then
[ pkgs . qgnomeplatform ]
else if cfg . platformTheme = = " q t c t " then [
pkgs . libsForQt5 . qt5ct
pkgs . qt6Packages . qt6ct
] else if cfg . platformTheme = = " k d e " then [
pkgs . libsForQt5 . plasma-integration
pkgs . libsForQt5 . systemsettings
] else
[ pkgs . libsForQt5 . qtstyleplugins ] )
home . packages = ( platformPackages . ${ cfg . platformTheme } or [ ] )
++ lib . optionals ( cfg . style . package != null )
( lib . toList cfg . style . package ) ;
xsession . importedVariables = [ " Q T _ Q P A _ P L A T F O R M T H E M E " ]
xsession . importedVariables = [ " Q T _ P L U G I N _ P A T H " " Q M L 2 _ I M P O R T _ P A T H " ]
++ lib . optionals ( cfg . platformTheme != null ) [ " Q T _ Q P A _ P L A T F O R M T H E M E " ]
++ lib . optionals ( cfg . style . name != null ) [ " Q T _ S T Y L E _ O V E R R I D E " ] ;
# Enable GTK+ style for Qt4 in Gtk/GNOME.
# It doesn’ t support the platform theme packages.
home . activation . useGtkThemeInQt4 =
mkIf ( cfg . platformTheme = = " g t k " || cfg . platformTheme = = " g n o m e " )
( hm . dag . entryAfter [ " w r i t e B o u n d a r y " ] ''
$D R Y _ R U N _ C M D ${ pkgs . crudini } / b i n / c r u d i n i $V E R B O S E _ A R G \
- - s e t " ${ config . xdg . configHome } / T r o l l t e c h . c o n f " Q t s t y l e G T K +
'' ) ;
} ;
}