1 { config, pkgs, lib, ... }:
4 cfg = config.services.mailcatcher;
6 inherit (lib) mkEnableOption mkIf mkOption types optionalString;
13 services.mailcatcher = {
14 enable = mkEnableOption "MailCatcher, an SMTP server and web interface to locally test outbound emails";
18 default = "127.0.0.1";
19 description = "The ip address of the http server.";
22 http.port = mkOption {
25 description = "The port address of the http server.";
28 http.path = mkOption {
29 type = with types; nullOr str;
31 description = "Prefix to all HTTP paths.";
32 example = "/mailcatcher";
37 default = "127.0.0.1";
38 description = "The ip address of the smtp server.";
41 smtp.port = mkOption {
44 description = "The port address of the smtp server.";
52 config = mkIf cfg.enable {
53 environment.systemPackages = [ pkgs.mailcatcher ];
55 systemd.services.mailcatcher = {
56 description = "MailCatcher Service";
57 after = [ "network.target" ];
58 wantedBy = [ "multi-user.target" ];
63 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}";
64 AmbientCapabilities = optionalString (cfg.http.port < 1024 || cfg.smtp.port < 1024) "cap_net_bind_service";