aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/services/mako.nix
blob: 77ea301167845844d91b128979f77573a923e17c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.programs.mako;

in {
  meta.maintainers = [ maintainers.onny ];

  options = {
    programs.mako = {
      enable = mkEnableOption ''
        Mako, lightweight notification daemon for Wayland
      '';

      maxVisible = mkOption {
        default = 5;
        type = types.nullOr types.int;
        description = ''
          Set maximum number of visible notifications. Set -1 to show all.
        '';
      };

      sort = mkOption {
        default = "-time";
        type =
          types.nullOr (types.enum [ "+time" "-time" "+priority" "-priority" ]);
        description = ''
          Sorts incoming notifications by time and/or priority in ascending(+)
          or descending(-) order.
        '';
      };

      output = mkOption {
        default = null;
        type = types.nullOr types.str;
        description = ''
          Show notifications on the specified output. If empty, notifications
          will appear on the focused output. Requires the compositor to support
          the Wayland protocol xdg-output-unstable-v1 version 2.
        '';
      };

      layer = mkOption {
        default = "top";
        type =
          types.nullOr (types.enum [ "background" "bottom" "top" "overlay" ]);
        description = ''
          Arrange mako at the specified layer, relative to normal windows.
          Supported values are background, bottom, top, and overlay. Using
          overlay will cause notifications to be displayed above fullscreen
          windows, though this may also occur at top depending on your
          compositor.
        '';
      };

      anchor = mkOption {
        default = "top-right";
        type = types.nullOr (types.enum [
          "top-right"
          "top-center"
          "top-left"
          "bottom-right"
          "bottom-center"
          "bottom-left"
          "center"
        ]);
        description = ''
          Show notifications at the specified position on the output.
          Supported values are top-right, top-center, top-left, bottom-right,
          bottom-center, bottom-left, and center.
        '';
      };

      font = mkOption {
        default = "monospace 10";
        type = types.nullOr types.str;
        description = ''
          Font to use, in Pango format.
        '';
      };

      backgroundColor = mkOption {
        default = "#285577FF";
        type = types.nullOr types.str;
        description = ''
          Set popup background color to a specific color, represented in hex
          color code.
        '';
      };

      textColor = mkOption {
        default = "#FFFFFFFF";
        type = types.nullOr types.str;
        description = ''
          Set popup text color to a specific color, represented in hex color
          code.
        '';
      };

      width = mkOption {
        default = 300;
        type = types.nullOr types.int;
        description = ''
          Set width of notification popups in specified number of pixels.
        '';
      };

      height = mkOption {
        default = 100;
        type = types.nullOr types.int;
        description = ''
          Set maximum height of notification popups. Notifications whose text
          takes up less space are shrunk to fit.
        '';
      };

      margin = mkOption {
        default = "10";
        type = types.nullOr types.str;
        description = ''
          Set margin of each edge specified in pixels. Specify single value to
          apply margin on all sides. Two comma-seperated values will set
          vertical and horizontal edges seperately. Four comma-seperated will
          give each edge a seperate value.
          For example: 10,20,5 will set top margin to 10, left and right to 20
          and bottom to five.
        '';
      };

      padding = mkOption {
        default = "5";
        type = types.nullOr types.str;
        description = ''
          Set padding of each edge specified in pixels. Specify single value to
          apply margin on all sides. Two comma-seperated values will set
          vertical and horizontal edges seperately. Four comma-seperated will
          give each edge a seperate value.
          For example: 10,20,5 will set top margin to 10, left and right to 20
          and bottom to five.
        '';
      };

      borderSize = mkOption {
        default = 1;
        type = types.nullOr types.int;
        description = ''
          Set popup border size to the specified number of pixels.
        '';
      };

      borderColor = mkOption {
        default = "#4C7899FF";
        type = types.nullOr types.str;
        description = ''
          Set popup border color to a specific color, represented in hex color
          code.
        '';
      };

      borderRadius = mkOption {
        default = 0;
        type = types.nullOr types.int;
        description = ''
          Set popup corner radius to the specified number of pixels.
        '';
      };

      progressColor = mkOption {
        default = "over #5588AAFF";
        type = types.nullOr types.str;
        description = ''
          Set popup progress indicator color to a specific color,
          represented in hex color code. To draw the progress
          indicator on top of the background color, use the
          <literal>over</literal> attribute. To replace the background
          color, use the <literal>source</literal> attribute (this can
          be useful when the notification is semi-transparent).
        '';
      };

      icons = mkOption {
        default = true;
        type = types.nullOr types.bool;
        description = ''
          Whether or not to show icons in notifications.
        '';
      };

      maxIconSize = mkOption {
        default = 64;
        type = types.nullOr types.int;
        description = ''
          Set maximum icon size to the specified number of pixels.
        '';
      };

      iconPath = mkOption {
        default = null;
        type = types.nullOr types.str;
        description = ''
          Paths to search for icons when a notification specifies a name
          instead of a full path. Colon-delimited. This approximates the search
          algorithm used by the XDG Icon Theme Specification, but does not
          support any of the theme metadata. Therefore, if you want to search
          parent themes, you'll need to add them to the path manually.
          </para><para>
          The <filename>/usr/share/icons/hicolor</filename> and
          <filename>/usr/share/pixmaps</filename> directories are
          always searched.
        '';
      };

      markup = mkOption {
        default = true;
        type = types.nullOr types.bool;
        description = ''
          If 1, enable Pango markup. If 0, disable Pango markup. If enabled,
          Pango markup will be interpreted in your format specifier and in the
          body of notifications.
        '';
      };

      actions = mkOption {
        default = true;
        type = types.nullOr types.bool;
        description = ''
          Applications may request an action to be associated with activating a
          notification. Disabling this will cause mako to ignore these requests.
        '';
      };

      format = mkOption {
        default = "<b>%s</b>\\n%b";
        type = types.nullOr types.str;
        description = ''
          Set notification format string to format. See FORMAT SPECIFIERS for
          more information. To change this for grouped notifications, set it
          within a grouped criteria.
        '';
      };

      defaultTimeout = mkOption {
        default = 0;
        type = types.nullOr types.int;
        description = ''
          Set the default timeout to timeout in milliseconds. To disable the
          timeout, set it to zero.
        '';
      };

      ignoreTimeout = mkOption {
        default = false;
        type = types.nullOr types.bool;
        description = ''
          If set, mako will ignore the expire timeout sent by notifications
          and use the one provided by default-timeout instead.
        '';
      };

      groupBy = mkOption {
        default = null;
        type = types.nullOr types.str;
        description = ''
          A comma-separated list of criteria fields that will be compared to
          other visible notifications to determine if this one should form a
          group with them. All listed criteria must be exactly equal for two
          notifications to group.
        '';
      };

    };
  };

  config = let
    boolToString = v: if v then "true" else "false";
    optionalBoolean = name: val:
      lib.optionalString (val != null) "${name}=${boolToString val}";
    optionalInteger = name: val:
      lib.optionalString (val != null) "${name}=${toString val}";
    optionalString = name: val:
      lib.optionalString (val != null) "${name}=${val}";
  in mkIf cfg.enable {
    home.packages = [ pkgs.mako ];
    xdg.configFile."mako/config".text = ''
      ${optionalInteger "max-visible" cfg.maxVisible}
      ${optionalString "sort" cfg.sort}
      ${optionalString "output" cfg.output}
      ${optionalString "layer" cfg.layer}
      ${optionalString "anchor" cfg.anchor}

      ${optionalString "font" cfg.font}
      ${optionalString "background-color" cfg.backgroundColor}
      ${optionalString "text-color" cfg.textColor}
      ${optionalInteger "width" cfg.width}
      ${optionalInteger "height" cfg.height}
      ${optionalString "margin" cfg.margin}
      ${optionalString "padding" cfg.padding}
      ${optionalInteger "border-size" cfg.borderSize}
      ${optionalString "border-color" cfg.borderColor}
      ${optionalInteger "border-radius" cfg.borderRadius}
      ${optionalString "progress-color" cfg.progressColor}
      ${optionalBoolean "icons" cfg.icons}
      ${optionalInteger "max-icon-size" cfg.maxIconSize}
      ${optionalString "icon-path" cfg.iconPath}
      ${optionalBoolean "markup" cfg.markup}
      ${optionalBoolean "actions" cfg.actions}
      ${optionalString "format" cfg.format}
      ${optionalInteger "default-timeout" cfg.defaultTimeout}
      ${optionalBoolean "ignore-timeout" cfg.ignoreTimeout}
      ${optionalString "group-by" cfg.groupBy}
    '';
  };
}