diff options
Diffstat (limited to 'modules/openarc.nix')
-rw-r--r-- | modules/openarc.nix | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/modules/openarc.nix b/modules/openarc.nix new file mode 100644 index 00000000..9dc49de1 --- /dev/null +++ b/modules/openarc.nix | |||
@@ -0,0 +1,90 @@ | |||
1 | { config, lib, pkgs, ... }: | ||
2 | |||
3 | with lib; | ||
4 | |||
5 | let | ||
6 | |||
7 | cfg = config.services.openarc; | ||
8 | |||
9 | defaultSock = "local:/run/openarc/openarc.sock"; | ||
10 | |||
11 | args = [ "-f" | ||
12 | "-p" cfg.socket | ||
13 | ] ++ optionals (cfg.configFile != null) [ "-c" cfg.configFile ]; | ||
14 | |||
15 | in { | ||
16 | |||
17 | ###### interface | ||
18 | |||
19 | options = { | ||
20 | |||
21 | services.openarc = { | ||
22 | |||
23 | enable = mkOption { | ||
24 | type = types.bool; | ||
25 | default = false; | ||
26 | description = "Whether to enable the OpenARC sender authentication system."; | ||
27 | }; | ||
28 | |||
29 | socket = mkOption { | ||
30 | type = types.str; | ||
31 | default = defaultSock; | ||
32 | description = "Socket which is used for communication with OpenARC."; | ||
33 | }; | ||
34 | |||
35 | user = mkOption { | ||
36 | type = types.str; | ||
37 | default = "opendmarc"; | ||
38 | description = "User for the daemon."; | ||
39 | }; | ||
40 | |||
41 | group = mkOption { | ||
42 | type = types.str; | ||
43 | default = "opendmarc"; | ||
44 | description = "Group for the daemon."; | ||
45 | }; | ||
46 | |||
47 | configFile = mkOption { | ||
48 | type = types.nullOr types.path; | ||
49 | default = null; | ||
50 | description = "Additional OpenARC configuration."; | ||
51 | }; | ||
52 | |||
53 | }; | ||
54 | |||
55 | }; | ||
56 | |||
57 | |||
58 | ###### implementation | ||
59 | |||
60 | config = mkIf cfg.enable { | ||
61 | |||
62 | users.users = optionalAttrs (cfg.user == "openarc") (singleton | ||
63 | { name = "openarc"; | ||
64 | group = cfg.group; | ||
65 | uid = config.ids.uids.openarc; | ||
66 | }); | ||
67 | |||
68 | users.groups = optionalAttrs (cfg.group == "openarc") (singleton | ||
69 | { name = "openarc"; | ||
70 | gid = config.ids.gids.openarc; | ||
71 | }); | ||
72 | |||
73 | environment.systemPackages = [ pkgs.openarc ]; | ||
74 | |||
75 | systemd.services.openarc = { | ||
76 | description = "OpenARC daemon"; | ||
77 | after = [ "network.target" ]; | ||
78 | wantedBy = [ "multi-user.target" ]; | ||
79 | |||
80 | serviceConfig = { | ||
81 | ExecStart = "${pkgs.openarc}/bin/openarc ${escapeShellArgs args}"; | ||
82 | User = cfg.user; | ||
83 | Group = cfg.group; | ||
84 | RuntimeDirectory = optional (cfg.socket == defaultSock) "openarc"; | ||
85 | PermissionsStartOnly = true; | ||
86 | }; | ||
87 | }; | ||
88 | |||
89 | }; | ||
90 | } | ||