1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7
8let
9 cfg = config.services.mailcatcher;
10
11 inherit (lib)
12 mkEnableOption
13 mkIf
14 mkOption
15 types
16 optionalString
17 ;
18in
19{
20 # interface
21
22 options = {
23
24 services.mailcatcher = {
25 enable = mkEnableOption "MailCatcher, an SMTP server and web interface to locally test outbound emails";
26
27 http.ip = mkOption {
28 type = types.str;
29 default = "127.0.0.1";
30 description = "The ip address of the http server.";
31 };
32
33 http.port = mkOption {
34 type = types.port;
35 default = 1080;
36 description = "The port address of the http server.";
37 };
38
39 http.path = mkOption {
40 type = with types; nullOr str;
41 default = null;
42 description = "Prefix to all HTTP paths.";
43 example = "/mailcatcher";
44 };
45
46 smtp.ip = mkOption {
47 type = types.str;
48 default = "127.0.0.1";
49 description = "The ip address of the smtp server.";
50 };
51
52 smtp.port = mkOption {
53 type = types.port;
54 default = 1025;
55 description = "The port address of the smtp server.";
56 };
57 };
58
59 };
60
61 # implementation
62
63 config = mkIf cfg.enable {
64 environment.systemPackages = [ pkgs.mailcatcher ];
65
66 systemd.services.mailcatcher = {
67 description = "MailCatcher Service";
68 after = [ "network.target" ];
69 wantedBy = [ "multi-user.target" ];
70
71 serviceConfig = {
72 DynamicUser = true;
73 Restart = "always";
74 ExecStart =
75 "${pkgs.mailcatcher}/bin/mailcatcher --foreground --no-quit --http-ip ${cfg.http.ip} --http-port ${toString cfg.http.port} --smtp-ip ${cfg.smtp.ip} --smtp-port ${toString cfg.smtp.port}"
76 + optionalString (cfg.http.path != null) " --http-path ${cfg.http.path}";
77 AmbientCapabilities = optionalString (
78 cfg.http.port < 1024 || cfg.smtp.port < 1024
79 ) "cap_net_bind_service";
80 };
81 };
82 };
83}