Created
July 26, 2024 13:45
-
-
Save RafaelKr/e9ac5850da8b674a92f0bf4bb5bb9b7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
services.mailpit = { | |
"project-dev" = { | |
enable = true; | |
listenPort = 8026; | |
smtpPort = 1026; | |
webroot = "/mailpit/"; | |
}; | |
"project-staging" = { | |
enable = true; | |
listenPort = 8025; | |
smtpPort = 1025; | |
webroot = "/mailpit/"; | |
}; | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
pkgs, | |
lib, | |
config, | |
... | |
}: | |
{ | |
options = { | |
services.mailpit = | |
with lib; | |
mkOption { | |
default = { }; | |
type = types.attrsOf ( | |
types.submodule { | |
options = { | |
enable = mkEnableOption "Mailpit - a simple email testing tool"; | |
package = mkPackageOption pkgs "mailpit" { | |
extraDescription = '' | |
Use this if you require specific features to be enabled. The default package has no features. | |
''; | |
}; | |
listenAddress = mkOption { | |
description = "Mailpit listen address."; | |
default = "127.0.0.1"; | |
type = types.str; | |
}; | |
listenPort = mkOption { | |
description = "Mailpit port to listen on."; | |
default = 8025; | |
type = types.port; | |
}; | |
smtpAddress = mkOption { | |
description = "Mailpit SMTP listen address."; | |
default = "127.0.0.1"; | |
type = types.str; | |
}; | |
smtpPort = mkOption { | |
description = "Mailpit SMTP port to listen on."; | |
default = 1025; | |
type = types.port; | |
}; | |
webroot = mkOption { | |
description = "Mailpit webroot."; | |
default = "/"; | |
type = types.str; | |
}; | |
}; | |
} | |
); | |
}; | |
}; | |
config = | |
let | |
mailpitServices = | |
let | |
f = ( | |
env: cfg: | |
let | |
stateDirectory = "mailpit/${env}"; | |
in | |
{ | |
"mailpit-${env}" = lib.mkIf cfg.enable { | |
description = "Mailpit ${env} daemon"; | |
wantedBy = [ "multi-user.target" ]; | |
after = [ "network.target" ]; | |
environment = { | |
# TODO: remove MP_DATA_FILE after mailpit is updated to the latest version. | |
# pre v1.16.0 | |
MP_DATA_FILE = "/var/lib/${stateDirectory}/database.db"; | |
# post v1.16.0 | |
MP_DATABASE = "/var/lib/${stateDirectory}/database.db"; | |
MP_UI_BIND_ADDR = "${cfg.listenAddress}:${toString cfg.listenPort}"; | |
MP_SMTP_BIND_ADDR = "${cfg.smtpAddress}:${toString cfg.smtpPort}"; | |
MP_WEBROOT = cfg.webroot; | |
}; | |
serviceConfig = { | |
ExecStart = "${cfg.package}/bin/mailpit"; | |
DynamicUser = true; | |
StateDirectory = stateDirectory; | |
}; | |
}; | |
} | |
); | |
in | |
(lib.attrsets.concatMapAttrs f config.services.mailpit); | |
in | |
{ | |
systemd.services = mailpitServices; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment