aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/modules/services/mail/mailhog.nix
blob: b113f4ff3decd972f66364b4d5ce83dc19071f2e (plain)
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
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.mailhog;

  args = lib.concatStringsSep " " (
    [
      "-api-bind-addr :${toString cfg.apiPort}"
      "-smtp-bind-addr :${toString cfg.smtpPort}"
      "-ui-bind-addr :${toString cfg.uiPort}"
      "-storage ${cfg.storage}"
    ] ++ lib.optional (cfg.storage == "maildir")
      "-maildir-path $STATE_DIRECTORY"
    ++ cfg.extraArgs
  );

in
{
  ###### interface

  imports = [
    (mkRemovedOptionModule [ "services" "mailhog" "user" ] "")
  ];

  options = {

    services.mailhog = {
      enable = mkEnableOption "MailHog";

      storage = mkOption {
        type = types.enum [ "maildir" "memory" ];
        default = "memory";
        description = "Store mails on disk or in memory.";
      };

      apiPort = mkOption {
        type = types.port;
        default = 8025;
        description = "Port on which the API endpoint will listen.";
      };

      smtpPort = mkOption {
        type = types.port;
        default = 1025;
        description = "Port on which the SMTP endpoint will listen.";
      };

      uiPort = mkOption {
        type = types.port;
        default = 8025;
        description = "Port on which the HTTP UI will listen.";
      };

      extraArgs = mkOption {
        type = types.listOf types.str;
        default = [];
        description = "List of additional arguments to pass to the MailHog process.";
      };
    };
  };


  ###### implementation

  config = mkIf cfg.enable {

    systemd.services.mailhog = {
      description = "MailHog - Web and API based SMTP testing";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        Type = "exec";
        ExecStart = "${pkgs.mailhog}/bin/MailHog ${args}";
        DynamicUser = true;
        Restart = "on-failure";
        StateDirectory = "mailhog";
      };
    };
  };
}