2019-03-27 00:56:24 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.mailcatcher;
|
|
|
|
|
2019-09-22 19:49:26 +00:00
|
|
|
inherit (lib) mkEnableOption mkIf mkOption types optionalString;
|
2019-03-27 00:56:24 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
# interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.mailcatcher = {
|
2019-04-20 01:41:48 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "MailCatcher");
|
2019-03-27 00:56:24 +00:00
|
|
|
|
|
|
|
http.ip = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
|
|
|
description = lib.mdDoc "The ip address of the http server.";
|
|
|
|
};
|
|
|
|
|
|
|
|
http.port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 1080;
|
|
|
|
description = lib.mdDoc "The port address of the http server.";
|
|
|
|
};
|
|
|
|
|
2019-11-12 15:11:24 +00:00
|
|
|
http.path = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = lib.mdDoc "Prefix to all HTTP paths.";
|
|
|
|
example = "/mailcatcher";
|
|
|
|
};
|
|
|
|
|
2019-03-27 00:56:24 +00:00
|
|
|
smtp.ip = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
|
|
|
description = lib.mdDoc "The ip address of the smtp server.";
|
|
|
|
};
|
|
|
|
|
|
|
|
smtp.port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 1025;
|
|
|
|
description = lib.mdDoc "The port address of the smtp server.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
# 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";
|
2019-11-12 15:11:24 +00:00
|
|
|
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}";
|
2019-09-22 19:49:26 +00:00
|
|
|
AmbientCapabilities = optionalString (cfg.http.port < 1024 || cfg.smtp.port < 1024) "cap_net_bind_service";
|
2019-03-27 00:56:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|