2020-04-24 23:36:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.mailcatcher;
|
|
|
|
|
|
|
|
inherit (lib) mkEnableOption mkIf mkOption types optionalString;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
# interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.mailcatcher = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "MailCatcher");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
http.ip = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The ip address of the http server.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
http.port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 1080;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The port address of the http server.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
http.path = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Prefix to all HTTP paths.";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = "/mailcatcher";
|
|
|
|
};
|
|
|
|
|
|
|
|
smtp.ip = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The ip address of the smtp server.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
smtp.port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 1025;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The port address of the smtp server.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
# implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ pkgs.mailcatcher ];
|
|
|
|
|
|
|
|
systemd.services.mailcatcher = {
|
|
|
|
description = "MailCatcher Service";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
Restart = "always";
|
|
|
|
ExecStart = "${pkgs.mailcatcher}/bin/mailcatcher --foreground --no-quit --http-ip ${cfg.http.ip} --http-port ${toString cfg.http.port} --smtp-ip ${cfg.smtp.ip} --smtp-port ${toString cfg.smtp.port}" + optionalString (cfg.http.path != null) " --http-path ${cfg.http.path}";
|
|
|
|
AmbientCapabilities = optionalString (cfg.http.port < 1024 || cfg.smtp.port < 1024) "cap_net_bind_service";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|