fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
5.6 KiB207 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.dunst;
8
9  eitherStrBoolIntList = with types;
10    either str (either bool (either int (listOf str)));
11
12  toDunstIni = generators.toINI {
13    mkKeyValue = key: value:
14      let
15        value' = if isBool value then
16          (lib.hm.booleans.yesNo value)
17        else if isString value then
18          ''"${value}"''
19        else
20          toString value;
21      in "${key}=${value'}";
22  };
23
24  themeType = types.submodule {
25    options = {
26      package = mkOption {
27        type = types.package;
28        example = literalExpression "pkgs.gnome.adwaita-icon-theme";
29        description = "Package providing the theme.";
30      };
31
32      name = mkOption {
33        type = types.str;
34        example = "Adwaita";
35        description = "The name of the theme within the package.";
36      };
37
38      size = mkOption {
39        type = types.str;
40        default = "32x32";
41        example = "16x16";
42        description = "The desired icon size.";
43      };
44    };
45  };
46
47  hicolorTheme = {
48    package = pkgs.hicolor-icon-theme;
49    name = "hicolor";
50    size = "32x32";
51  };
52
53in {
54  meta.maintainers = [ maintainers.rycee ];
55
56  options = {
57    services.dunst = {
58      enable = mkEnableOption "the dunst notification daemon";
59
60      package = mkOption {
61        type = types.package;
62        default = pkgs.dunst;
63        defaultText = literalExpression "pkgs.dunst";
64        description = "Package providing {command}`dunst`.";
65      };
66
67      configFile = mkOption {
68        type = with types; either str path;
69        default = "${config.xdg.configHome}/dunst/dunstrc";
70        defaultText = "$XDG_CONFIG_HOME/dunst/dunstrc";
71        description = ''
72          Path to the configuration file read by dunst.
73
74          Note that the configuration generated by Home Manager will be
75          written to {file}`$XDG_CONFIG_HOME/dunst/dunstrc`
76          regardless. This allows using a mutable configuration file generated
77          from the immutable one, useful in scenarios where live reloading is
78          desired.
79        '';
80      };
81
82      iconTheme = mkOption {
83        type = themeType;
84        default = hicolorTheme;
85        description = "Set the icon theme.";
86      };
87
88      waylandDisplay = mkOption {
89        type = types.str;
90        default = "";
91        description =
92          "Set the service's {env}`WAYLAND_DISPLAY` environment variable.";
93      };
94
95      settings = mkOption {
96        type = types.submodule {
97          freeformType = with types; attrsOf (attrsOf eitherStrBoolIntList);
98          options = {
99            global.icon_path = mkOption {
100              type = types.separatedString ":";
101              description = "Paths where dunst will look for icons.";
102            };
103          };
104        };
105        default = { };
106        description =
107          "Configuration written to {file}`$XDG_CONFIG_HOME/dunst/dunstrc`.";
108        example = literalExpression ''
109          {
110            global = {
111              width = 300;
112              height = 300;
113              offset = "30x50";
114              origin = "top-right";
115              transparency = 10;
116              frame_color = "#eceff1";
117              font = "Droid Sans 9";
118            };
119
120            urgency_normal = {
121              background = "#37474f";
122              foreground = "#eceff1";
123              timeout = 10;
124            };
125          };
126        '';
127      };
128    };
129  };
130
131  config = mkIf cfg.enable (mkMerge [
132    {
133      assertions = [
134        (hm.assertions.assertPlatform "services.dunst" pkgs platforms.linux)
135      ];
136
137      home.packages = [ cfg.package ];
138
139      xdg.dataFile."dbus-1/services/org.knopwob.dunst.service".source =
140        "${pkgs.dunst}/share/dbus-1/services/org.knopwob.dunst.service";
141
142      services.dunst.settings.global.icon_path = let
143        useCustomTheme = cfg.iconTheme.package != hicolorTheme.package
144          || cfg.iconTheme.name != hicolorTheme.name || cfg.iconTheme.size
145          != hicolorTheme.size;
146
147        basePaths = [
148          "/run/current-system/sw"
149          config.home.profileDirectory
150          cfg.iconTheme.package
151        ] ++ optional useCustomTheme hicolorTheme.package;
152
153        themes = [ cfg.iconTheme ] ++ optional useCustomTheme
154          (hicolorTheme // { size = cfg.iconTheme.size; });
155
156        categories = [
157          "actions"
158          "animations"
159          "apps"
160          "categories"
161          "devices"
162          "emblems"
163          "emotes"
164          "filesystem"
165          "intl"
166          "legacy"
167          "mimetypes"
168          "places"
169          "status"
170          "stock"
171        ];
172
173        mkPath = { basePath, theme, category }:
174          "${basePath}/share/icons/${theme.name}/${theme.size}/${category}";
175      in concatMapStringsSep ":" mkPath (cartesianProductOfSets {
176        basePath = basePaths;
177        theme = themes;
178        category = categories;
179      });
180
181      systemd.user.services.dunst = {
182        Unit = {
183          Description = "Dunst notification daemon";
184          After = [ "graphical-session-pre.target" ];
185          PartOf = [ "graphical-session.target" ];
186        };
187
188        Service = {
189          Type = "dbus";
190          BusName = "org.freedesktop.Notifications";
191          ExecStart = "${cfg.package}/bin/dunst -config ${cfg.configFile}";
192          Environment = optionalString (cfg.waylandDisplay != "")
193            "WAYLAND_DISPLAY=${cfg.waylandDisplay}";
194        };
195      };
196    }
197
198    (mkIf (cfg.settings != { }) {
199      xdg.configFile."dunst/dunstrc" = {
200        text = toDunstIni cfg.settings;
201        onChange = ''
202          ${pkgs.procps}/bin/pkill -u "$USER" ''${VERBOSE+-e} dunst || true
203        '';
204      };
205    })
206  ]);
207}