1 { config, lib, pkgs, ... }:
3 cfg = config.services.mailhog;
5 args = lib.concatStringsSep " " (
7 "-api-bind-addr :${toString cfg.apiPort}"
8 "-smtp-bind-addr :${toString cfg.smtpPort}"
9 "-ui-bind-addr :${toString cfg.uiPort}"
10 "-storage ${cfg.storage}"
11 ] ++ lib.optional (cfg.storage == "maildir")
12 "-maildir-path $STATE_DIRECTORY"
21 (lib.mkRemovedOptionModule [ "services" "mailhog" "user" ] "")
27 enable = lib.mkEnableOption "MailHog, web and API based SMTP testing";
29 storage = lib.mkOption {
30 type = lib.types.enum [ "maildir" "memory" ];
32 description = "Store mails on disk or in memory.";
35 apiPort = lib.mkOption {
36 type = lib.types.port;
38 description = "Port on which the API endpoint will listen.";
41 smtpPort = lib.mkOption {
42 type = lib.types.port;
44 description = "Port on which the SMTP endpoint will listen.";
47 uiPort = lib.mkOption {
48 type = lib.types.port;
50 description = "Port on which the HTTP UI will listen.";
53 extraArgs = lib.mkOption {
54 type = lib.types.listOf lib.types.str;
56 description = "List of additional arguments to pass to the MailHog process.";
64 config = lib.mkIf cfg.enable {
66 systemd.services.mailhog = {
67 description = "MailHog - Web and API based SMTP testing";
68 after = [ "network.target" ];
69 wantedBy = [ "multi-user.target" ];
72 ExecStart = "${pkgs.mailhog}/bin/MailHog ${args}";
74 Restart = "on-failure";
75 StateDirectory = "mailhog";