2024-07-24 13:48:20 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2024-07-29 13:12:35 +00:00
|
|
|
inherit (config.services.mailpit) instances;
|
2024-07-24 13:48:20 +00:00
|
|
|
inherit (lib)
|
|
|
|
cli
|
|
|
|
concatStringsSep
|
|
|
|
const
|
|
|
|
filterAttrs
|
|
|
|
getExe
|
2024-07-29 13:12:35 +00:00
|
|
|
mapAttrs'
|
2024-07-24 13:48:20 +00:00
|
|
|
mkIf
|
|
|
|
mkOption
|
2024-07-29 13:12:35 +00:00
|
|
|
nameValuePair
|
2024-07-24 13:48:20 +00:00
|
|
|
types
|
|
|
|
;
|
|
|
|
|
|
|
|
isNonNull = v: v != null;
|
2024-07-29 13:12:35 +00:00
|
|
|
genCliFlags =
|
|
|
|
settings: concatStringsSep " " (cli.toGNUCommandLine { } (filterAttrs (const isNonNull) settings));
|
2024-07-24 13:48:20 +00:00
|
|
|
in
|
|
|
|
{
|
2024-07-29 13:12:35 +00:00
|
|
|
options.services.mailpit.instances = mkOption {
|
|
|
|
default = { };
|
|
|
|
type = types.attrsOf (
|
|
|
|
types.submodule {
|
2024-07-24 13:48:20 +00:00
|
|
|
freeformType = types.attrsOf (
|
|
|
|
types.oneOf [
|
|
|
|
types.str
|
|
|
|
types.int
|
|
|
|
types.bool
|
|
|
|
]
|
|
|
|
);
|
|
|
|
options = {
|
|
|
|
database = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "mailpit.db";
|
|
|
|
description = ''
|
|
|
|
Specify the local database filename to store persistent data.
|
|
|
|
If `null`, a temporary file will be created that will be removed when the application stops.
|
|
|
|
It's recommended to specify a relative path. The database will be written into the service's
|
|
|
|
state directory then.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
max = mkOption {
|
|
|
|
type = types.ints.unsigned;
|
|
|
|
default = 500;
|
|
|
|
description = ''
|
|
|
|
Maximum number of emails to keep. If the number is exceeded, old emails
|
|
|
|
will be deleted.
|
|
|
|
|
|
|
|
Set to `0` to never prune old emails.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
listen = mkOption {
|
2024-08-14 14:12:57 +00:00
|
|
|
default = "127.0.0.1:8025";
|
2024-07-24 13:48:20 +00:00
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
HTTP bind interface and port for UI.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
smtp = mkOption {
|
2024-08-14 14:12:57 +00:00
|
|
|
default = "127.0.0.1:1025";
|
2024-07-24 13:48:20 +00:00
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
SMTP bind interface and port.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2024-07-29 13:12:35 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
description = ''
|
|
|
|
Configure mailpit instances. The attribute-set values are
|
|
|
|
CLI flags passed to the `mailpit` CLI.
|
|
|
|
|
|
|
|
See [upstream docs](https://mailpit.axllent.org/docs/configuration/runtime-options/)
|
|
|
|
for all available options.
|
|
|
|
'';
|
2024-07-24 13:48:20 +00:00
|
|
|
};
|
|
|
|
|
2024-07-29 13:12:35 +00:00
|
|
|
config = mkIf (instances != { }) {
|
|
|
|
systemd.services = mapAttrs' (
|
|
|
|
name: cfg:
|
|
|
|
nameValuePair "mailpit-${name}" {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
StateDirectory = "mailpit";
|
|
|
|
WorkingDirectory = "%S/mailpit";
|
|
|
|
ExecStart = "${getExe pkgs.mailpit} ${genCliFlags cfg}";
|
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
) instances;
|
2024-07-24 13:48:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = lib.teams.flyingcircus.members;
|
|
|
|
}
|