fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
3.3 KiB116 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6  cfg = config.services.fnott;
7
8  concatStringsSep' = sep: list: concatStringsSep sep (remove "" list);
9
10  iniFormat = pkgs.formats.ini { };
11in {
12  meta.maintainers = with maintainers; [ polykernel ];
13
14  options = {
15    services.fnott = {
16      enable = mkEnableOption ''
17        fnott, a lightweight Wayland notification daemon for wlroots-based compositors
18      '';
19
20      package = mkOption {
21        type = types.package;
22        default = pkgs.fnott;
23        defaultText = literalExpression "pkgs.fnott";
24        description = "Package providing {command}`fnott`.";
25      };
26
27      extraFlags = mkOption {
28        type = types.listOf types.str;
29        default = [ ];
30        example = [ "-s" ];
31        description = ''
32          Extra arguments to use for executing fnott.
33        '';
34      };
35
36      configFile = mkOption {
37        type = types.either types.str types.path;
38        default = "${config.xdg.configHome}/fnott/fnott.ini";
39        defaultText = "$XDG_CONFIG_HOME/fnott/fnott.ini";
40        description = ''
41          Path to the configuration file read by fnott.
42
43          Note that environment variables in the path won't be properly expanded.
44
45          The configuration specified under
46          {option}`services.fnott.settings` will be generated and
47          written to {file}`$XDG_CONFIG_HOME/fnott/fnott.ini`
48          regardless of this option. This allows using a mutable configuration file
49          generated from the immutable one, useful in scenarios where live reloading is desired.
50        '';
51      };
52
53      settings = mkOption {
54        type = iniFormat.type;
55        default = { };
56        description = ''
57          Configuration written to
58          {file}`$XDG_CONFIG_HOME/fnott/fnott.ini`.
59
60          See
61          {manpage}`fnott.ini(5)` for a list of available options and <https://codeberg.org/dnkl/fnott/src/branch/master/fnott.ini>
62          for an example configuration.
63        '';
64        example = literalExpression ''
65          {
66            main = {
67              notification-margin = 5;
68            };
69
70            low = {
71              timeout = 5;
72              title-font = "Dina:weight=bold:slant=italic";
73              title-color = "ffffff";
74            };
75          }
76        '';
77      };
78    };
79  };
80
81  config = mkIf cfg.enable {
82    assertions =
83      [ (hm.assertions.assertPlatform "services.fnott" pkgs platforms.linux) ];
84
85    home.packages = [ cfg.package ];
86
87    systemd.user.services.fnott = {
88      Unit = {
89        Description = "Fnott notification daemon";
90        Documentation = "man:fnott(1)";
91        After = [ "graphical-session-pre.target" ];
92        PartOf = [ "graphical-session.target" ];
93      };
94
95      Service = {
96        Type = "dbus";
97        BusName = "org.freedesktop.Notifications";
98        ExecStart = concatStringsSep' " " [
99          "${cfg.package}/bin/fnott"
100          "-c ${escapeShellArg cfg.configFile}"
101          (escapeShellArgs cfg.extraFlags)
102        ];
103      };
104    };
105
106    xdg.dataFile."dbus-1/services/fnott.service".text = ''
107      [D-BUS Service]
108      Name=org.freedesktop.Notifications
109      Exec=${cfg.package}/bin/fnott
110      SystemdService=fnott.service
111    '';
112
113    xdg.configFile."fnott/fnott.ini".source =
114      iniFormat.generate "fnott.ini" cfg.settings;
115  };
116}