about summary refs log tree commit diff
path: root/modules/user/profpatsch/services/dunst.nix
blob: 0c4871b29b500b43f6e89a73d81397b18d88e8b0 (plain) (blame)
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
# dunst notification daemon (user service)
# partially stolen from https://github.com/nix-community/home-manager/blob/9b1b55ba0264a55add4b7b4e022bdc2832b531f6/modules/services/dunst.nix
# but simplified
{ pkgs, lib, config, ... }:

let
  cfg = config.vuizvui.user.profpatsch.services.dunst;

  eitherStrBoolIntList = with lib.types;
    either str (either bool (either int (listOf str)));

  toDunstINI = lib.generators.toINI {
    mkKeyValue = key: value:
      let
        value' = if builtins.isBool value then
          (if value then "yes" else "no")
        else if builtins.isString value then
          ''"${value}"''
        else
          toString value;
      in "${key}=${value'}";
  };


  themeType = lib.types.submodule {
    options = {
      package = lib.mkOption {
        type = lib.types.package;
        example = lib.literalExample "pkgs.gnome.adwaita-icon-theme";
        description = "Package providing the theme.";
      };

      name = lib.mkOption {
        type = lib.types.str;
        example = "Adwaita";
        description = "The name of the theme within the package.";
      };
    };
  };


  themeSize = "32x32";

in {
  options.vuizvui.user.profpatsch.services.dunst = {
    enable = lib.mkEnableOption "dunst libnotify server";

    settings = lib.mkOption {
      type = with lib.types; attrsOf (attrsOf eitherStrBoolIntList);
      default = { };
      description = ''
        Settings for the dunst daemon which are directly translated
        to the used <literal>dunstrc</literal> config file. See
        <link xlink:href="https://github.com/dunst-project/dunst/blob/v${pkgs.dunst.version}/dunstrc" />
        for a list of available options.
      '';
    };

    verbosity = lib.mkOption {
      type = lib.types.enum [ "crit" "warn" "mesg" "info" "debug"];
      default = "mesg";
      description = ''
        Verbosity of the dunst daemon on stderr.
      '';
    };

    iconTheme = lib.mkOption {
      type = themeType;
      description = "Set the icon theme.";
    };
  };

  config = lib.mkIf cfg.enable {
    systemd.user.services.dunst = {
      description = "dunst libnotify daemon";
      serviceConfig = {
        Type = "dbus";
        BusName = "org.freedesktop.Notifications";
        ExecStart = "${lib.getBin pkgs.dunst}/bin/dunst -verbosity ${cfg.verbosity} -config ${pkgs.writeText "dunst.conf" (toDunstINI cfg.settings)}";
        Restart = "on-failure";
        RestartSec = "1";
      };
      partOf = [ "graphical-session.target" ];
      wantedBy = [ "graphical-session.target" ];
    };


    vuizvui.user.profpatsch.services.dunst.settings = {
      global = {
        icon_position = "left";
        icon_path = let
          theme = cfg.iconTheme;

          categories = [
            "actions"
            "animations"
            "apps"
            "categories"
            "devices"
            "emblems"
            "emotes"
            "filesystem"
            "intl"
            "mimetypes"
            "places"
            "status"
            "stock"
            "legacy"
          ];
        in lib.concatMapStringsSep ":"
            (category: "${cfg.iconTheme.package}/share/icons/${theme.name}/${themeSize}/${category}")
            categories;

        dmenu = "${pkgs.dmenu}/bin/dmenu -p dunst:";
        browser = "xdg-open";
      };
      # TODO: set better urgency colors for low and high
      urgency_low = {
        background = "#F1EAD7";
        foreground = "#504D47";
      };
      urgency_normal = {
        background = "#F1EAD7";
        foreground = "#504D47";
      };
      urgency_high = {
        background = "#F1EAD7";
        foreground = "#504D47";
      };
    };

  };

}