-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.nix
73 lines (66 loc) · 1.99 KB
/
module.nix
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
{ config, pkgs, lib, ... }:
let
cfg = config.services.post;
in
{
options.services.post = {
enable = lib.mkEnableOption "post";
package = lib.mkPackageOption pkgs "post" { };
listen = {
addr = lib.mkOption {
type = lib.types.str;
description = "The ip address the http listener should be listening on.";
default = "::";
};
port = lib.mkOption {
type = lib.types.port;
description = "The port the http listener should be listening on.";
default = 9876;
};
};
smtp = {
addr = lib.mkOption {
type = lib.types.str;
description = "The ip address the smtp server is listening on.";
default = "::1";
};
port = lib.mkOption {
type = lib.types.port;
description = "The port address the smtp server is listening on.";
default = 25;
};
};
templateGlob = lib.mkOption {
type = lib.types.str;
description = "The glob pattern where email templates can be found.";
};
apiTokenFile = lib.mkOption {
type = lib.types.str;
description = "The path of the while which contains the api token.";
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
systemd.services.post = {
description = "post";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
environment =
let
addrToString = addr: port: "${if (lib.hasInfix ":" addr) then "[${addr}]" else addr}:${toString port}";
in
{
POST_LISTEN_ADDR = addrToString cfg.listen.addr cfg.listen.port;
POST_SMTP_ADDR = addrToString cfg.smtp.addr cfg.smtp.port;
POST_TEMPLATE_GLOB = cfg.templateGlob;
POST_API_TOKEN_FILE = "%d/api_token";
};
serviceConfig = {
ExecStart = lib.getExe cfg.package;
DynamicUser = true;
User = "post";
LoadCredential = "api_token:${cfg.apiTokenFile}";
};
};
};
}