fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

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