fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3let 4 5cfg = config . xsession . windowManager . herbstluftwm ; 6 7renderValue = val : 8if lib . isBool val then 9if val then "true" else "false" 10else 11lib . escapeShellArg val ; 12 13renderSettings = settings : 14lib . concatStringsSep "\n" ( lib . mapAttrsToList 15( name :value :"herbstclient set ${ name } ${ renderValue value } " ) settings ); 16 17renderKeybinds = keybinds : 18lib . concatStringsSep "\n" 19( lib . mapAttrsToList ( key :cmd :"herbstclient keybind ${ key } ${ cmd } " ) 20keybinds ); 21 22renderMousebinds = mousebinds : 23lib . concatStringsSep "\n" 24( lib . mapAttrsToList ( btn :cmd :"herbstclient mousebind ${ btn } ${ cmd } " ) 25mousebinds ); 26 27renderRules = rules : 28lib . concatStringsSep "\n" ( map ( rule :"herbstclient rule ${ rule } " ) rules ); 29 30settingType = lib . types . oneOf [ lib . types . bool lib . types . int lib . types . str ]; 31 32escapedTags = map lib . escapeShellArg cfg . tags ; 33 34in { 35meta . maintainers = [ lib . hm . maintainers . olmokramer ]; 36 37options . xsession . windowManager . herbstluftwm = { 38enable = lib . mkEnableOption "herbstluftwm window manager" ; 39 40package = lib . mkOption { 41type = lib . types . package ; 42default = pkgs . herbstluftwm ; 43defaultText = lib . literalExpression "pkgs.herbstluftwm" ; 44description = '' 45Package providing the {command}`herbstluftwm` and 46{command}`herbstclient` commands. 47'' ; 48}; 49 50settings = lib . mkOption { 51type = lib . types . attrsOf settingType ; 52default = { }; 53example = lib . literalExpression '' 54{ 55gapless_grid = false; 56window_border_width = 1; 57window_border_active_color = "#FF0000"; 58} 59'' ; 60description = "Herbstluftwm settings." ; 61}; 62 63keybinds = lib . mkOption { 64type = lib . types . attrsOf lib . types . str ; 65default = { }; 66example = lib . literalExpression '' 67{ 68Mod4-o = "split right"; 69Mod4-u = "split bottom"; 70} 71'' ; 72description = "Herbstluftwm keybinds." ; 73}; 74 75mousebinds = lib . mkOption { 76type = lib . types . attrsOf lib . types . str ; 77default = { }; 78example = lib . literalExpression '' 79{ 80Mod4-B1 = "move"; 81Mod4-B3 = "resize"; 82} 83'' ; 84description = "Herbstluftwm mousebinds." ; 85}; 86 87rules = lib . mkOption { 88type = lib . types . listOf lib . types . str ; 89default = [ ]; 90example = lib . literalExpression '' 91[ 92"windowtype~'_NET_WM_WINDOW_TYPE_(DIALOG|UTILITY|SPLASH)' focus=on pseudotile=on" 93"windowtype~'_NET_WM_WINDOW_TYPE_(NOTIFICATION|DOCK|DESKTOP)' manage=off" 94] 95'' ; 96description = "Herbstluftwm rules." ; 97}; 98 99tags = lib . mkOption { 100type = lib . types . listOf lib . types . str ; 101default = [ ]; 102example = lib . literalExpression '' 103[ "work" "browser" "music" "gaming" ] 104'' ; 105description = "Tags to create on startup." ; 106}; 107 108extraConfig = lib . mkOption { 109type = lib . types . lines ; 110default = "" ; 111example = '' 112herbstclient set_layout max 113herbstclient detect_monitors 114'' ; 115description = '' 116Extra configuration lines to add verbatim to 117{file}`$XDG_CONFIG_HOME/herbstluftwm/autostart`. 118'' ; 119}; 120}; 121 122config = lib . mkIf cfg . enable { 123assertions = [ 124( lib . hm . assertions . assertPlatform "xsession.windowManager.herbstluftwm" 125pkgs lib . platforms . linux ) 126]; 127 128home . packages = [ cfg . package ]; 129 130xsession . windowManager . command = " ${ cfg . package } /bin/herbstluftwm --locked" ; 131 132xdg . configFile . "herbstluftwm/autostart" . source = 133pkgs . writeShellScript "herbstluftwm-autostart" '' 134shopt -s expand_aliases 135 136# shellcheck disable=SC2142 137alias herbstclient='set -- "$@" ";"' 138set -- 139 140herbstclient emit_hook reload 141 142# Reset everything. 143herbstclient attr theme.tiling.reset 1 144herbstclient attr theme.floating.reset 1 145herbstclient keyunbind --all 146herbstclient mouseunbind --all 147herbstclient unrule --all 148 149${ renderSettings cfg . settings } 150 151${ lib . optionalString ( cfg . tags != [ ]) '' 152for tag in ${ lib . concatStringsSep " " escapedTags } ; do 153herbstclient add "$tag" 154done 155 156if ${ cfg . package } /bin/herbstclient object_tree tags.by-name.default &>/dev/null; then 157herbstclient use ${ lib . head escapedTags } 158herbstclient merge_tag default ${ lib . head escapedTags } 159fi 160'' } 161 162${ renderKeybinds cfg . keybinds } 163 164${ renderMousebinds cfg . mousebinds } 165 166${ renderRules cfg . rules } 167 168${ cfg . extraConfig } 169 170herbstclient unlock 171 172${ cfg . package } /bin/herbstclient chain ";" " $ @" 173'' ; 174}; 175}