2024-08-28 14:22:48 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2017-06-24 12:05:34 -04:00
|
|
|
let
|
|
|
|
cfg = config.services.mailhog;
|
2020-09-07 13:08:42 +08: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}"
|
2024-08-28 14:22:48 +02:00
|
|
|
]
|
|
|
|
++ lib.optional (cfg.storage == "maildir") "-maildir-path $STATE_DIRECTORY"
|
2020-09-07 13:08:42 +08:00
|
|
|
++ cfg.extraArgs
|
|
|
|
);
|
|
|
|
|
2024-08-28 14:22:48 +02:00
|
|
|
mhsendmail = pkgs.writeShellScriptBin "mailhog-sendmail" ''
|
|
|
|
exec ${lib.getExe pkgs.mailhog} sendmail $@
|
|
|
|
'';
|
2020-09-07 13:08:42 +08:00
|
|
|
in
|
|
|
|
{
|
2017-06-24 12:05:34 -04:00
|
|
|
###### interface
|
|
|
|
|
2020-09-07 13:08:42 +08:00
|
|
|
imports = [
|
2024-08-28 14:22:48 +02:00
|
|
|
(lib.mkRemovedOptionModule [
|
|
|
|
"services"
|
|
|
|
"mailhog"
|
|
|
|
"user"
|
|
|
|
] "")
|
2020-09-07 13:08:42 +08:00
|
|
|
];
|
|
|
|
|
2017-06-24 12:05:34 -04:00
|
|
|
options = {
|
|
|
|
|
|
|
|
services.mailhog = {
|
2024-08-24 22:05:34 +02:00
|
|
|
enable = lib.mkEnableOption "MailHog, web and API based SMTP testing";
|
2020-09-07 13:08:42 +08:00
|
|
|
|
2024-08-28 14:22:48 +02:00
|
|
|
setSendmail = lib.mkEnableOption "set the system sendmail to mailhogs's" // {
|
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:34 +02:00
|
|
|
storage = lib.mkOption {
|
2024-08-28 14:22:48 +02:00
|
|
|
type = lib.types.enum [
|
|
|
|
"maildir"
|
|
|
|
"memory"
|
|
|
|
];
|
2020-09-07 13:08:42 +08:00
|
|
|
default = "memory";
|
|
|
|
description = "Store mails on disk or in memory.";
|
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:34 +02:00
|
|
|
apiPort = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
2020-09-07 13:08:42 +08:00
|
|
|
default = 8025;
|
|
|
|
description = "Port on which the API endpoint will listen.";
|
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:34 +02:00
|
|
|
smtpPort = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
2020-09-07 13:08:42 +08:00
|
|
|
default = 1025;
|
|
|
|
description = "Port on which the SMTP endpoint will listen.";
|
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:34 +02:00
|
|
|
uiPort = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
2020-09-07 13:08:42 +08:00
|
|
|
default = 8025;
|
|
|
|
description = "Port on which the HTTP UI will listen.";
|
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:34 +02:00
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2024-08-28 14:22:48 +02:00
|
|
|
default = [ ];
|
2020-09-07 13:08:42 +08:00
|
|
|
description = "List of additional arguments to pass to the MailHog process.";
|
2017-06-24 12:05:34 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2024-08-24 22:05:34 +02:00
|
|
|
config = lib.mkIf cfg.enable {
|
2017-06-24 12:05:34 -04:00
|
|
|
|
|
|
|
systemd.services.mailhog = {
|
2020-09-07 13:08:42 +08:00
|
|
|
description = "MailHog - Web and API based SMTP testing";
|
2017-06-24 12:05:34 -04:00
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
2020-09-07 13:08:42 +08:00
|
|
|
Type = "exec";
|
2024-08-28 14:22:48 +02:00
|
|
|
ExecStart = "${lib.getExe pkgs.mailhog} ${args}";
|
2020-09-07 13:08:42 +08:00
|
|
|
DynamicUser = true;
|
|
|
|
Restart = "on-failure";
|
|
|
|
StateDirectory = "mailhog";
|
2017-06-24 12:05:34 -04:00
|
|
|
};
|
|
|
|
};
|
2024-08-28 14:22:48 +02:00
|
|
|
|
|
|
|
services.mail.sendmailSetuidWrapper = lib.mkIf cfg.setSendmail {
|
|
|
|
program = "sendmail";
|
|
|
|
source = lib.getExe mhsendmail;
|
|
|
|
# Communication happens through the network, no data is written to disk
|
|
|
|
owner = "nobody";
|
|
|
|
group = "nogroup";
|
|
|
|
};
|
2017-06-24 12:05:34 -04:00
|
|
|
};
|
2024-08-28 14:22:48 +02:00
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ RTUnreal ];
|
2017-06-24 12:05:34 -04:00
|
|
|
}
|