fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . gtk ; 8cfg2 = config . gtk . gtk2 ; 9cfg3 = config . gtk . gtk3 ; 10cfg4 = config . gtk . gtk4 ; 11 12toGtk3Ini = generators . toINI { 13mkKeyValue = key :value : 14let value' = if isBool value then boolToString value else toString value ; 15in " ${ escape [ "=" ] key } = ${ value' } " ; 16}; 17 18formatGtk2Option = n :v : 19let 20v' = if isBool v then 21boolToString value 22else if isString v then 23''" ${ v } "'' 24else 25toString v ; 26in " ${ escape [ "=" ] n } = ${ v' } " ; 27 28themeType = types . submodule { 29options = { 30package = mkOption { 31type = types . nullOr types . package ; 32default = null ; 33example = literalExpression "pkgs.gnome.gnome-themes-extra" ; 34description = '' 35Package providing the theme. This package will be installed 36to your profile. If `null` then the theme 37is assumed to already be available in your profile. 38'' ; 39}; 40 41name = mkOption { 42type = types . str ; 43example = "Adwaita" ; 44description = "The name of the theme within the package." ; 45}; 46}; 47}; 48 49iconThemeType = types . submodule { 50options = { 51package = mkOption { 52type = types . nullOr types . package ; 53default = null ; 54example = literalExpression "pkgs.gnome.adwaita-icon-theme" ; 55description = '' 56Package providing the icon theme. This package will be installed 57to your profile. If `null` then the theme 58is assumed to already be available in your profile. 59'' ; 60}; 61 62name = mkOption { 63type = types . str ; 64example = "Adwaita" ; 65description = "The name of the icon theme within the package." ; 66}; 67}; 68}; 69 70cursorThemeType = types . submodule { 71options = { 72package = mkOption { 73type = types . nullOr types . package ; 74default = null ; 75example = literalExpression "pkgs.vanilla-dmz" ; 76description = '' 77Package providing the cursor theme. This package will be installed 78to your profile. If `null` then the theme 79is assumed to already be available in your profile. 80'' ; 81}; 82 83name = mkOption { 84type = types . str ; 85example = "Vanilla-DMZ" ; 86description = "The name of the cursor theme within the package." ; 87}; 88 89size = mkOption { 90type = types . nullOr types . int ; 91default = null ; 92example = 16 ; 93description = '' 94The size of the cursor. 95'' ; 96}; 97}; 98}; 99 100in { 101meta . maintainers = [ maintainers . rycee ]; 102 103imports = [ 104( mkRemovedOptionModule [ "gtk" "gtk3" "waylandSupport" ] '' 105This options is not longer needed and can be removed. 106'' ) 107]; 108 109options = { 110gtk = { 111enable = mkEnableOption "GTK 2/3 configuration" ; 112 113font = mkOption { 114type = types . nullOr hm . types . fontType ; 115default = null ; 116description = '' 117The font to use in GTK+ 2/3 applications. 118'' ; 119}; 120 121cursorTheme = mkOption { 122type = types . nullOr cursorThemeType ; 123default = null ; 124description = "The cursor theme to use." ; 125}; 126 127iconTheme = mkOption { 128type = types . nullOr iconThemeType ; 129default = null ; 130description = "The icon theme to use." ; 131}; 132 133theme = mkOption { 134type = types . nullOr themeType ; 135default = null ; 136description = "The GTK+2/3 theme to use." ; 137}; 138 139gtk2 = { 140extraConfig = mkOption { 141type = types . lines ; 142default = "" ; 143example = "gtk-can-change-accels = 1" ; 144description = '' 145Extra configuration lines to add verbatim to 146{file}`~/.gtkrc-2.0`. 147'' ; 148}; 149 150configLocation = mkOption { 151type = types . path ; 152default = " ${ config . home . homeDirectory } /.gtkrc-2.0" ; 153defaultText = 154literalExpression ''"''${config.home.homeDirectory}/.gtkrc-2.0"'' ; 155example = 156literalExpression ''"''${config.xdg.configHome}/gtk-2.0/gtkrc"'' ; 157description = '' 158The location to put the GTK configuration file. 159'' ; 160}; 161}; 162 163gtk3 = { 164bookmarks = mkOption { 165type = types . listOf types . str ; 166default = [ ]; 167example = [ "file:///home/jane/Documents" ]; 168description = "Bookmarks in the sidebar of the GTK file browser" ; 169}; 170 171extraConfig = mkOption { 172type = with types ; attrsOf ( oneOf [ bool int str ]); 173default = { }; 174example = { 175gtk-cursor-blink = false ; 176gtk-recent-files-limit = 20 ; 177}; 178description = '' 179Extra configuration options to add to 180{file}`$XDG_CONFIG_HOME/gtk-3.0/settings.ini`. 181'' ; 182}; 183 184extraCss = mkOption { 185type = types . lines ; 186default = "" ; 187description = '' 188Extra configuration lines to add verbatim to 189{file}`$XDG_CONFIG_HOME/gtk-3.0/gtk.css`. 190'' ; 191}; 192}; 193 194gtk4 = { 195extraConfig = mkOption { 196type = with types ; attrsOf ( either bool ( either int str )); 197default = { }; 198example = { 199gtk-cursor-blink = false ; 200gtk-recent-files-limit = 20 ; 201}; 202description = '' 203Extra configuration options to add to 204{file}`$XDG_CONFIG_HOME/gtk-4.0/settings.ini`. 205'' ; 206}; 207 208extraCss = mkOption { 209type = types . lines ; 210default = "" ; 211description = '' 212Extra configuration lines to add verbatim to 213{file}`$XDG_CONFIG_HOME/gtk-4.0/gtk.css`. 214'' ; 215}; 216}; 217}; 218}; 219 220config = mkIf cfg . enable ( let 221gtkIni = optionalAttrs ( cfg . font != null ) { 222gtk-font-name = let 223fontSize = 224optionalString ( cfg . font . size != null ) " ${ toString cfg . font . size } " ; 225in " ${ cfg . font . name } " + fontSize ; 226} // optionalAttrs ( cfg . theme != null ) { gtk-theme-name = cfg . theme . name ; } 227// optionalAttrs ( cfg . iconTheme != null ) { 228gtk-icon-theme-name = cfg . iconTheme . name ; 229} // optionalAttrs ( cfg . cursorTheme != null ) { 230gtk-cursor-theme-name = cfg . cursorTheme . name ; 231} // optionalAttrs 232( cfg . cursorTheme != null && cfg . cursorTheme . size != null ) { 233gtk-cursor-theme-size = cfg . cursorTheme . size ; 234}; 235 236dconfIni = optionalAttrs ( cfg . font != null ) { 237font-name = let 238fontSize = 239optionalString ( cfg . font . size != null ) " ${ toString cfg . font . size } " ; 240in " ${ cfg . font . name } " + fontSize ; 241} // optionalAttrs ( cfg . theme != null ) { gtk-theme = cfg . theme . name ; } 242// optionalAttrs ( cfg . iconTheme != null ) { 243icon-theme = cfg . iconTheme . name ; 244} // optionalAttrs ( cfg . cursorTheme != null ) { 245cursor-theme = cfg . cursorTheme . name ; 246} // optionalAttrs 247( cfg . cursorTheme != null && cfg . cursorTheme . size != null ) { 248cursor-size = cfg . cursorTheme . size ; 249}; 250 251optionalPackage = opt : 252optional ( opt != null && opt . package != null ) opt . package ; 253in { 254home . packages = concatMap optionalPackage [ 255cfg . font 256cfg . theme 257cfg . iconTheme 258cfg . cursorTheme 259]; 260 261home . file .${ cfg2 . configLocation }. text = 262concatMapStrings ( l :l + "\n" ) ( mapAttrsToList formatGtk2Option gtkIni ) 263+ cfg2 . extraConfig + "\n" ; 264 265home . sessionVariables . GTK2_RC_FILES = cfg2 . configLocation ; 266 267xdg . configFile . "gtk-3.0/settings.ini" . text = 268toGtk3Ini { Settings = gtkIni // cfg3 . extraConfig ; }; 269 270xdg . configFile . "gtk-3.0/gtk.css" = 271mkIf ( cfg3 . extraCss != "" ) { text = cfg3 . extraCss ; }; 272 273xdg . configFile . "gtk-3.0/bookmarks" = mkIf ( cfg3 . bookmarks != [ ]) { 274text = concatMapStrings ( l :l + "\n" ) cfg3 . bookmarks ; 275}; 276 277xdg . configFile . "gtk-4.0/settings.ini" . text = 278toGtk3Ini { Settings = gtkIni // cfg4 . extraConfig ; }; 279 280xdg . configFile . "gtk-4.0/gtk.css" = 281mkIf ( cfg4 . extraCss != "" ) { text = cfg4 . extraCss ; }; 282 283dconf . settings . "org/gnome/desktop/interface" = dconfIni ; 284}); 285}