fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , options , lib , pkgs , ...} : 2 3let 4inherit ( builtins ) elemAt isAttrs isBool length mapAttrs toJSON ; 5inherit ( lib ) 6boolToString concatMapStringsSep concatStringsSep escape literalExpression 7mapAttrsToList mkEnableOption mkRenamedOptionModule mkRemovedOptionModule 8mkDefault mkIf mkOption optional types warn ; 9 10cfg = config . services . picom ; 11opt = options . services . picom ; 12 13pairOf = x : 14with types ; 15addCheck ( listOf x ) ( y :length y == 2 ) // { 16description = "pair of ${ x . description } " ; 17}; 18 19mkDefaultAttrs = mapAttrs ( n :v :mkDefault v ); 20 21# Basically a tinkered lib.generators.mkKeyValueDefault 22# It either serializes a top-level definition "key: { values };" 23# or an expression "key = { values };" 24mkAttrsString = top : 25mapAttrsToList ( k :v : 26let sep = if ( top && isAttrs v ) then ": " else " = " ; 27in " ${ escape [ sep ] k }${ sep }${ mkValueString v } ;" ); 28 29# This serializes a Nix expression to the libconfig format. 30mkValueString = v : 31if types . bool . check v then 32boolToString v 33else if types . int . check v then 34toString v 35else if types . float . check v then 36toString v 37else if types . str . check v then 38''" ${ escape [ ''"'' ] v } "'' 39else if builtins . isList v then 40"[ ${ concatMapStringsSep " , " mkValueString v } ]" 41else if types . attrs . check v then 42"{ ${ concatStringsSep " " ( mkAttrsString false v )} }" 43else 44throw '' 45invalid expression used in option services.picom.settings: 46${ v } 47'' ; 48 49toConf = attrs :concatStringsSep "\n" ( mkAttrsString true cfg . settings ); 50 51configFile = toConf cfg . settings ; 52 53in { 54imports = [ 55( mkRemovedOptionModule [ "services" "picom" "refreshRate" ] 56"The option `refresh-rate` has been deprecated by upstream." ) 57( mkRemovedOptionModule [ "services" "picom" "experimentalBackends" ] 58"The option `--experimental-backends` has been removed by upstream." ) 59( mkRemovedOptionModule [ "services" "picom" "extraOptions" ] 60"This option has been replaced by `services.picom.settings`." ) 61( mkRenamedOptionModule [ "services" "picom" "opacityRule" ] [ 62"services" 63"picom" 64"opacityRules" 65]) 66]; 67 68options . services . picom = { 69enable = mkEnableOption "Picom X11 compositor" ; 70 71fade = mkOption { 72type = types . bool ; 73default = false ; 74description = '' 75Fade windows in and out. 76'' ; 77}; 78 79fadeDelta = mkOption { 80type = types . ints . positive ; 81default = 10 ; 82example = 5 ; 83description = '' 84Time between fade animation step (in ms). 85'' ; 86}; 87 88fadeSteps = mkOption { 89type = pairOf ( types . numbers . between 1.0e-2 1 ); 90default = [ 2.8e-2 3.0e-2 ]; 91example = [ 4.0e-2 4.0e-2 ]; 92description = '' 93Opacity change between fade steps (in and out). 94'' ; 95}; 96 97fadeExclude = mkOption { 98type = types . listOf types . str ; 99default = [ ]; 100example = [ "window_type *= 'menu'" "name ~= 'Firefox$'" "focused = 1" ]; 101description = '' 102List of conditions of windows that should not be faded. 103See `picom(1)` man page for more examples. 104'' ; 105}; 106 107shadow = mkOption { 108type = types . bool ; 109default = false ; 110description = '' 111Draw window shadows. 112'' ; 113}; 114 115shadowOffsets = mkOption { 116type = pairOf types . int ; 117default = [ ( - 15 ) ( - 15 ) ]; 118example = [ ( - 10 ) ( - 15 ) ]; 119description = '' 120Left and right offset for shadows (in pixels). 121'' ; 122}; 123 124shadowOpacity = mkOption { 125type = types . numbers . between 0 1 ; 126default = 0.75 ; 127example = 0.8 ; 128description = '' 129Window shadows opacity. 130'' ; 131}; 132 133shadowExclude = mkOption { 134type = types . listOf types . str ; 135default = [ ]; 136example = [ "window_type *= 'menu'" "name ~= 'Firefox$'" "focused = 1" ]; 137description = '' 138List of conditions of windows that should have no shadow. 139See `picom(1)` man page for more examples. 140'' ; 141}; 142 143activeOpacity = mkOption { 144type = types . numbers . between 0 1 ; 145default = 1.0 ; 146example = 0.8 ; 147description = '' 148Opacity of active windows. 149'' ; 150}; 151 152inactiveOpacity = mkOption { 153type = types . numbers . between 0.1 1 ; 154default = 1.0 ; 155example = 0.8 ; 156description = '' 157Opacity of inactive windows. 158'' ; 159}; 160 161menuOpacity = mkOption { 162type = types . numbers . between 0 1 ; 163default = 1.0 ; 164example = 0.8 ; 165description = '' 166Opacity of dropdown and popup menu. 167'' ; 168}; 169 170wintypes = mkOption { 171type = types . attrs ; 172default = { 173popup_menu = { opacity = cfg . menuOpacity ; }; 174dropdown_menu = { opacity = cfg . menuOpacity ; }; 175}; 176defaultText = literalExpression '' 177{ 178popup_menu = { opacity = config. ${ opt . menuOpacity } ; }; 179dropdown_menu = { opacity = config. ${ opt . menuOpacity } ; }; 180} 181'' ; 182example = { }; 183description = '' 184Rules for specific window types. 185'' ; 186}; 187 188opacityRules = mkOption { 189type = types . listOf types . str ; 190default = [ ]; 191example = [ 192"95:class_g = 'URxvt' && !_NET_WM_STATE@:32a" 193"0:_NET_WM_STATE@:32a *= '_NET_WM_STATE_HIDDEN'" 194]; 195description = '' 196Rules that control the opacity of windows, in format PERCENT:PATTERN. 197'' ; 198}; 199 200backend = mkOption { 201type = types . enum [ "egl" "glx" "xrender" "xr_glx_hybrid" ]; 202default = "xrender" ; 203description = '' 204Backend to use: `egl`, `glx`, `xrender` or `xr_glx_hybrid`. 205'' ; 206}; 207 208vSync = mkOption { 209type = types . bool ; 210default = false ; 211description = '' 212Enable vertical synchronization. 213'' ; 214}; 215 216extraArgs = mkOption { 217type = with types ; listOf str ; 218default = [ ]; 219example = literalExpression ''[ "--legacy-backends" ]'' ; 220description = '' 221Extra arguments to be passed to the picom executable. 222'' ; 223}; 224 225package = mkOption { 226type = types . package ; 227default = pkgs . picom ; 228defaultText = literalExpression "pkgs.picom" ; 229example = literalExpression "pkgs.picom" ; 230description = '' 231Picom derivation to use. 232'' ; 233}; 234 235settings = with types ; 236let 237scalar = oneOf [ bool int float str ] // { 238description = "scalar types" ; 239}; 240 241libConfig = oneOf [ scalar ( listOf libConfig ) ( attrsOf libConfig ) ] // { 242description = "libconfig type" ; 243}; 244 245topLevel = attrsOf libConfig // { 246description = '' 247libconfig configuration. The format consists of an attributes 248set (called a group) of settings. Each setting can be a scalar type 249(boolean, integer, floating point number or string), a list of 250scalars or a group itself 251'' ; 252}; 253 254in mkOption { 255type = topLevel ; 256default = { }; 257example = literalExpression '' 258blur = 259{ method = "gaussian"; 260size = 10; 261deviation = 5.0; 262}; 263'' ; 264description = '' 265Picom settings. Use this option to configure Picom settings not exposed 266in a NixOS option or to bypass one. For the available options see the 267CONFIGURATION FILES section at `picom(1)`. 268'' ; 269}; 270}; 271 272config = mkIf cfg . enable { 273assertions = [ 274( lib . hm . assertions . assertPlatform "services.picom" pkgs 275lib . platforms . linux ) 276]; 277 278services . picom . settings = mkDefaultAttrs { 279# fading 280fading = cfg . fade ; 281fade-delta = cfg . fadeDelta ; 282fade-in-step = elemAt cfg . fadeSteps 0 ; 283fade-out-step = elemAt cfg . fadeSteps 1 ; 284fade-exclude = cfg . fadeExclude ; 285 286# shadows 287shadow = cfg . shadow ; 288shadow-offset-x = elemAt cfg . shadowOffsets 0 ; 289shadow-offset-y = elemAt cfg . shadowOffsets 1 ; 290shadow-opacity = cfg . shadowOpacity ; 291shadow-exclude = cfg . shadowExclude ; 292 293# opacity 294active-opacity = cfg . activeOpacity ; 295inactive-opacity = cfg . inactiveOpacity ; 296 297wintypes = cfg . wintypes ; 298 299opacity-rule = cfg . opacityRules ; 300 301# other options 302backend = cfg . backend ; 303vsync = cfg . vSync ; 304}; 305 306home . packages = [ cfg . package ]; 307 308xdg . configFile . "picom/picom.conf" . text = configFile ; 309 310systemd . user . services . picom = { 311Unit = { 312Description = "Picom X11 compositor" ; 313After = [ "graphical-session-pre.target" ]; 314PartOf = [ "graphical-session.target" ]; 315}; 316 317Install = { WantedBy = [ "graphical-session.target" ]; }; 318 319Service = { 320ExecStart = concatStringsSep " " ([ 321" ${ cfg . package } /bin/picom" 322"--config ${ config . xdg . configFile . "picom/picom.conf" . source } " 323] ++ cfg . extraArgs ); 324Restart = "always" ; 325RestartSec = 3 ; 326}; 327}; 328}; 329 330meta . maintainers = with lib . maintainers ; [ thiagokokada ]; 331}