aboutsummaryrefslogtreecommitdiffstats
path: root/module/default.nix
blob: 774a36188dea07b8073fdc4f2a51b5b52fc64bdc (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
flake: { lib, config, pkgs, ... }:
with lib;
let
  inherit (flake.packages.${pkgs.stdenv.hostPlatform.system}) icalproxy;
  
  cfg = config.services.icalproxy;
in {
  options.services.icalproxy = with types; {
    enable = mkEnableOption "icalproxy";
    calendarUrl = mkOption {
      type = str;
    };
    ignore = mkOption {
      type = submodule {
        options = {
          locationRegexes = mkOption {
            type = listOf str;
          };
          summaryRegexes = mkOption {
            type = listOf str;
          };
        };
      };
    };
    port = mkOption {
      type = str;
    };
    userTokens = mkOption {
      type = attrsOf (submodule {
        options = {
          hash = mkOption {
            type = str;
          };
          salt = mkOption {
            type = str;
          };
        };
      });
    };
  };

  config = mkIf cfg.enable {
    users.users.icalproxy = {
      description = "icalproxy service user";
      isSystemUser = true;
      group = "icalproxy";
    };

    users.groups.icalproxy = {};

    systemd.services.icalproxy = {
      wants = [ "network-online.target" ];
      wantedBy = [ "multi-user.target" ];
      environment = {
        CONFIG_FILE = pkgs.writeText "icalproxy-config.json" (builtins.toJSON {
          calendar_url = cfg.calendarUrl;
          ignore = {
            location_regexes = cfg.ignore.locationRegexes;
            summary_regexes = cfg.ignore.summaryRegexes;
          };
          port = cfg.port;
          user_tokens = cfg.userTokens;
        });
      };
      serviceConfig = {
        User = config.users.users.icalproxy.name;
        Group = config.users.users.icalproxy.group;
        Restart = "always";
        ExecStart = "${lib.getBin icalproxy}/bin/icalproxy";
      };
    };
  };
}