1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.mailhog;
7
8 args = lib.concatStringsSep " " (
9 [
10 "-api-bind-addr :${toString cfg.apiPort}"
11 "-smtp-bind-addr :${toString cfg.smtpPort}"
12 "-ui-bind-addr :${toString cfg.uiPort}"
13 "-storage ${cfg.storage}"
14 ] ++ lib.optional (cfg.storage == "maildir")
15 "-maildir-path $STATE_DIRECTORY"
16 ++ cfg.extraArgs
17 );
18
19in
20{
21 ###### interface
22
23 imports = [
24 (mkRemovedOptionModule [ "services" "mailhog" "user" ] "")
25 ];
26
27 options = {
28
29 services.mailhog = {
30 enable = mkEnableOption (lib.mdDoc "MailHog");
31
32 storage = mkOption {
33 type = types.enum [ "maildir" "memory" ];
34 default = "memory";
35 description = lib.mdDoc "Store mails on disk or in memory.";
36 };
37
38 apiPort = mkOption {
39 type = types.port;
40 default = 8025;
41 description = lib.mdDoc "Port on which the API endpoint will listen.";
42 };
43
44 smtpPort = mkOption {
45 type = types.port;
46 default = 1025;
47 description = lib.mdDoc "Port on which the SMTP endpoint will listen.";
48 };
49
50 uiPort = mkOption {
51 type = types.port;
52 default = 8025;
53 description = lib.mdDoc "Port on which the HTTP UI will listen.";
54 };
55
56 extraArgs = mkOption {
57 type = types.listOf types.str;
58 default = [];
59 description = lib.mdDoc "List of additional arguments to pass to the MailHog process.";
60 };
61 };
62 };
63
64
65 ###### implementation
66
67 config = mkIf cfg.enable {
68
69 systemd.services.mailhog = {
70 description = "MailHog - Web and API based SMTP testing";
71 after = [ "network.target" ];
72 wantedBy = [ "multi-user.target" ];
73 serviceConfig = {
74 Type = "exec";
75 ExecStart = "${pkgs.mailhog}/bin/MailHog ${args}";
76 DynamicUser = true;
77 Restart = "on-failure";
78 StateDirectory = "mailhog";
79 };
80 };
81 };
82}