2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.mailhog;
|
2020-09-25 04:45:31 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2020-04-24 23:36:52 +00:00
|
|
|
###### interface
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "mailhog" "user" ] "")
|
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
options = {
|
|
|
|
|
|
|
|
services.mailhog = {
|
|
|
|
enable = mkEnableOption "MailHog";
|
2020-09-25 04:45:31 +00:00
|
|
|
|
|
|
|
storage = mkOption {
|
|
|
|
type = types.enum [ "maildir" "memory" ];
|
|
|
|
default = "memory";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Store mails on disk or in memory.";
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
apiPort = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8025;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Port on which the API endpoint will listen.";
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
smtpPort = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 1025;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Port on which the SMTP endpoint will listen.";
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
uiPort = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8025;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Port on which the HTTP UI will listen.";
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraArgs = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "List of additional arguments to pass to the MailHog process.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
systemd.services.mailhog = {
|
2020-09-25 04:45:31 +00:00
|
|
|
description = "MailHog - Web and API based SMTP testing";
|
2020-04-24 23:36:52 +00:00
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
2020-09-25 04:45:31 +00:00
|
|
|
Type = "exec";
|
|
|
|
ExecStart = "${pkgs.mailhog}/bin/MailHog ${args}";
|
|
|
|
DynamicUser = true;
|
|
|
|
Restart = "on-failure";
|
|
|
|
StateDirectory = "mailhog";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|