fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
10.7 KiB346 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.mako;
8
9in {
10  meta.maintainers = [ maintainers.onny ];
11
12  imports =
13    [ (mkRenamedOptionModule [ "programs" "mako" ] [ "services" "mako" ]) ];
14
15  options = {
16    services.mako = {
17      enable = mkEnableOption ''
18        Mako, lightweight notification daemon for Wayland
19      '';
20
21      package = mkOption {
22        type = types.package;
23        default = pkgs.mako;
24        defaultText = literalExpression "pkgs.mako";
25        description = "The mako package to use.";
26      };
27
28      maxVisible = mkOption {
29        default = 5;
30        type = types.nullOr types.int;
31        description = ''
32          Set maximum number of visible notifications. Set -1 to show all.
33        '';
34      };
35
36      sort = mkOption {
37        default = "-time";
38        type =
39          types.nullOr (types.enum [ "+time" "-time" "+priority" "-priority" ]);
40        description = ''
41          Sorts incoming notifications by time and/or priority in ascending(+)
42          or descending(-) order.
43        '';
44      };
45
46      output = mkOption {
47        default = null;
48        type = types.nullOr types.str;
49        description = ''
50          Show notifications on the specified output. If empty, notifications
51          will appear on the focused output. Requires the compositor to support
52          the Wayland protocol xdg-output-unstable-v1 version 2.
53        '';
54      };
55
56      layer = mkOption {
57        default = "top";
58        type =
59          types.nullOr (types.enum [ "background" "bottom" "top" "overlay" ]);
60        description = ''
61          Arrange mako at the specified layer, relative to normal windows.
62          Supported values are background, bottom, top, and overlay. Using
63          overlay will cause notifications to be displayed above fullscreen
64          windows, though this may also occur at top depending on your
65          compositor.
66        '';
67      };
68
69      anchor = mkOption {
70        default = "top-right";
71        type = types.nullOr (types.enum [
72          "top-right"
73          "top-center"
74          "top-left"
75          "bottom-right"
76          "bottom-center"
77          "bottom-left"
78          "center"
79        ]);
80        description = ''
81          Show notifications at the specified position on the output.
82          Supported values are top-right, top-center, top-left, bottom-right,
83          bottom-center, bottom-left, and center.
84        '';
85      };
86
87      font = mkOption {
88        default = "monospace 10";
89        type = types.nullOr types.str;
90        description = ''
91          Font to use, in Pango format.
92        '';
93      };
94
95      backgroundColor = mkOption {
96        default = "#285577FF";
97        type = types.nullOr types.str;
98        description = ''
99          Set popup background color to a specific color, represented in hex
100          color code.
101        '';
102      };
103
104      textColor = mkOption {
105        default = "#FFFFFFFF";
106        type = types.nullOr types.str;
107        description = ''
108          Set popup text color to a specific color, represented in hex color
109          code.
110        '';
111      };
112
113      width = mkOption {
114        default = 300;
115        type = types.nullOr types.int;
116        description = ''
117          Set width of notification popups in specified number of pixels.
118        '';
119      };
120
121      height = mkOption {
122        default = 100;
123        type = types.nullOr types.int;
124        description = ''
125          Set maximum height of notification popups. Notifications whose text
126          takes up less space are shrunk to fit.
127        '';
128      };
129
130      margin = mkOption {
131        default = "10";
132        type = types.nullOr types.str;
133        description = ''
134          Set margin of each edge specified in pixels. Specify single value to
135          apply margin on all sides. Two comma-separated values will set
136          vertical and horizontal edges separately. Four comma-separated will
137          give each edge a separate value.
138          For example: 10,20,5 will set top margin to 10, left and right to 20
139          and bottom to five.
140        '';
141      };
142
143      padding = mkOption {
144        default = "5";
145        type = types.nullOr types.str;
146        description = ''
147          Set padding of each edge specified in pixels. Specify single value to
148          apply margin on all sides. Two comma-separated values will set
149          vertical and horizontal edges separately. Four comma-separated will
150          give each edge a separate value.
151          For example: 10,20,5 will set top margin to 10, left and right to 20
152          and bottom to five.
153        '';
154      };
155
156      borderSize = mkOption {
157        default = 1;
158        type = types.nullOr types.int;
159        description = ''
160          Set popup border size to the specified number of pixels.
161        '';
162      };
163
164      borderColor = mkOption {
165        default = "#4C7899FF";
166        type = types.nullOr types.str;
167        description = ''
168          Set popup border color to a specific color, represented in hex color
169          code.
170        '';
171      };
172
173      borderRadius = mkOption {
174        default = 0;
175        type = types.nullOr types.int;
176        description = ''
177          Set popup corner radius to the specified number of pixels.
178        '';
179      };
180
181      progressColor = mkOption {
182        default = "over #5588AAFF";
183        type = types.nullOr types.str;
184        description = ''
185          Set popup progress indicator color to a specific color,
186          represented in hex color code. To draw the progress
187          indicator on top of the background color, use the
188          `over` attribute. To replace the background
189          color, use the `source` attribute (this can
190          be useful when the notification is semi-transparent).
191        '';
192      };
193
194      icons = mkOption {
195        default = true;
196        type = types.nullOr types.bool;
197        description = ''
198          Whether or not to show icons in notifications.
199        '';
200      };
201
202      maxIconSize = mkOption {
203        default = 64;
204        type = types.nullOr types.int;
205        description = ''
206          Set maximum icon size to the specified number of pixels.
207        '';
208      };
209
210      iconPath = mkOption {
211        default = null;
212        type = types.nullOr types.str;
213        description = ''
214          Paths to search for icons when a notification specifies a name
215          instead of a full path. Colon-delimited. This approximates the search
216          algorithm used by the XDG Icon Theme Specification, but does not
217          support any of the theme metadata. Therefore, if you want to search
218          parent themes, you'll need to add them to the path manually.
219
220          The {file}`/usr/share/icons/hicolor` and
221          {file}`/usr/share/pixmaps` directories are
222          always searched.
223        '';
224      };
225
226      markup = mkOption {
227        default = true;
228        type = types.nullOr types.bool;
229        description = ''
230          If 1, enable Pango markup. If 0, disable Pango markup. If enabled,
231          Pango markup will be interpreted in your format specifier and in the
232          body of notifications.
233        '';
234      };
235
236      actions = mkOption {
237        default = true;
238        type = types.nullOr types.bool;
239        description = ''
240          Applications may request an action to be associated with activating a
241          notification. Disabling this will cause mako to ignore these requests.
242        '';
243      };
244
245      format = mkOption {
246        default = "<b>%s</b>\\n%b";
247        type = types.nullOr types.str;
248        description = ''
249          Set notification format string to format. See FORMAT SPECIFIERS for
250          more information. To change this for grouped notifications, set it
251          within a grouped criteria.
252        '';
253      };
254
255      defaultTimeout = mkOption {
256        default = 0;
257        type = types.nullOr types.int;
258        description = ''
259          Set the default timeout to timeout in milliseconds. To disable the
260          timeout, set it to zero.
261        '';
262      };
263
264      ignoreTimeout = mkOption {
265        default = false;
266        type = types.nullOr types.bool;
267        description = ''
268          If set, mako will ignore the expire timeout sent by notifications
269          and use the one provided by default-timeout instead.
270        '';
271      };
272
273      groupBy = mkOption {
274        default = null;
275        type = types.nullOr types.str;
276        description = ''
277          A comma-separated list of criteria fields that will be compared to
278          other visible notifications to determine if this one should form a
279          group with them. All listed criteria must be exactly equal for two
280          notifications to group.
281        '';
282      };
283
284      extraConfig = mkOption {
285        default = "";
286        type = types.lines;
287        example = literalExpression ''
288          [urgency=low]
289          border-color=#b8bb26
290        '';
291        description = "Additional configuration.";
292      };
293    };
294  };
295
296  config = let
297    boolToString = v: if v then "true" else "false";
298    optionalBoolean = name: val:
299      lib.optionalString (val != null) "${name}=${boolToString val}";
300    optionalInteger = name: val:
301      lib.optionalString (val != null) "${name}=${toString val}";
302    optionalString = name: val:
303      lib.optionalString (val != null) "${name}=${val}";
304  in mkIf cfg.enable {
305    assertions =
306      [ (hm.assertions.assertPlatform "services.mako" pkgs platforms.linux) ];
307
308    home.packages = [ cfg.package ];
309
310    xdg.configFile."mako/config" = {
311      onChange = ''
312        ${cfg.package}/bin/makoctl reload || true
313      '';
314      text = ''
315        ${optionalInteger "max-visible" cfg.maxVisible}
316        ${optionalString "sort" cfg.sort}
317        ${optionalString "output" cfg.output}
318        ${optionalString "layer" cfg.layer}
319        ${optionalString "anchor" cfg.anchor}
320
321        ${optionalString "font" cfg.font}
322        ${optionalString "background-color" cfg.backgroundColor}
323        ${optionalString "text-color" cfg.textColor}
324        ${optionalInteger "width" cfg.width}
325        ${optionalInteger "height" cfg.height}
326        ${optionalString "margin" cfg.margin}
327        ${optionalString "padding" cfg.padding}
328        ${optionalInteger "border-size" cfg.borderSize}
329        ${optionalString "border-color" cfg.borderColor}
330        ${optionalInteger "border-radius" cfg.borderRadius}
331        ${optionalString "progress-color" cfg.progressColor}
332        ${optionalBoolean "icons" cfg.icons}
333        ${optionalInteger "max-icon-size" cfg.maxIconSize}
334        ${optionalString "icon-path" cfg.iconPath}
335        ${optionalBoolean "markup" cfg.markup}
336        ${optionalBoolean "actions" cfg.actions}
337        ${optionalString "format" cfg.format}
338        ${optionalInteger "default-timeout" cfg.defaultTimeout}
339        ${optionalBoolean "ignore-timeout" cfg.ignoreTimeout}
340        ${optionalString "group-by" cfg.groupBy}
341
342        ${cfg.extraConfig}
343      '';
344    };
345  };
346}