summaryrefslogtreecommitdiff
path: root/modules/openarc.nix
blob: 9dc49de1b857b2006de87643627c04242908daef (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
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.services.openarc;

  defaultSock = "local:/run/openarc/openarc.sock";

  args = [ "-f"
           "-p" cfg.socket
         ] ++ optionals (cfg.configFile != null) [ "-c" cfg.configFile ];

in {

  ###### interface

  options = {

    services.openarc = {

      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable the OpenARC sender authentication system.";
      };

      socket = mkOption {
        type = types.str;
        default = defaultSock;
        description = "Socket which is used for communication with OpenARC.";
      };

      user = mkOption {
        type = types.str;
        default = "opendmarc";
        description = "User for the daemon.";
      };

      group = mkOption {
        type = types.str;
        default = "opendmarc";
        description = "Group for the daemon.";
      };

      configFile = mkOption {
        type = types.nullOr types.path;
        default = null;
        description = "Additional OpenARC configuration.";
      };

    };

  };


  ###### implementation

  config = mkIf cfg.enable {

    users.users = optionalAttrs (cfg.user == "openarc") (singleton
      { name = "openarc";
        group = cfg.group;
        uid = config.ids.uids.openarc;
      });

    users.groups = optionalAttrs (cfg.group == "openarc") (singleton
      { name = "openarc";
        gid = config.ids.gids.openarc;
      });

    environment.systemPackages = [ pkgs.openarc ];

    systemd.services.openarc = {
      description = "OpenARC daemon";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];

      serviceConfig = {
        ExecStart = "${pkgs.openarc}/bin/openarc ${escapeShellArgs args}";
        User = cfg.user;
        Group = cfg.group;
        RuntimeDirectory = optional (cfg.socket == defaultSock) "openarc";
        PermissionsStartOnly = true;
      };
    };

  };
}