at 23.11-pre 1.9 kB view raw
1{ config, pkgs, lib, ... }: 2 3let 4 cfg = config.services.mailcatcher; 5 6 inherit (lib) mkEnableOption mkIf mkOption types optionalString; 7in 8{ 9 # interface 10 11 options = { 12 13 services.mailcatcher = { 14 enable = mkEnableOption (lib.mdDoc "MailCatcher"); 15 16 http.ip = mkOption { 17 type = types.str; 18 default = "127.0.0.1"; 19 description = lib.mdDoc "The ip address of the http server."; 20 }; 21 22 http.port = mkOption { 23 type = types.port; 24 default = 1080; 25 description = lib.mdDoc "The port address of the http server."; 26 }; 27 28 http.path = mkOption { 29 type = with types; nullOr str; 30 default = null; 31 description = lib.mdDoc "Prefix to all HTTP paths."; 32 example = "/mailcatcher"; 33 }; 34 35 smtp.ip = mkOption { 36 type = types.str; 37 default = "127.0.0.1"; 38 description = lib.mdDoc "The ip address of the smtp server."; 39 }; 40 41 smtp.port = mkOption { 42 type = types.port; 43 default = 1025; 44 description = lib.mdDoc "The port address of the smtp server."; 45 }; 46 }; 47 48 }; 49 50 # implementation 51 52 config = mkIf cfg.enable { 53 environment.systemPackages = [ pkgs.mailcatcher ]; 54 55 systemd.services.mailcatcher = { 56 description = "MailCatcher Service"; 57 after = [ "network.target" ]; 58 wantedBy = [ "multi-user.target" ]; 59 60 serviceConfig = { 61 DynamicUser = true; 62 Restart = "always"; 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"; 65 }; 66 }; 67 }; 68}