at 25.11-pre 2.8 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7 8let 9 inherit (config.services.mailpit) instances; 10 inherit (lib) 11 cli 12 concatStringsSep 13 const 14 filterAttrs 15 getExe 16 mapAttrs' 17 mkIf 18 mkOption 19 nameValuePair 20 types 21 ; 22 23 isNonNull = v: v != null; 24 genCliFlags = 25 settings: concatStringsSep " " (cli.toGNUCommandLine { } (filterAttrs (const isNonNull) settings)); 26in 27{ 28 options.services.mailpit.instances = mkOption { 29 default = { }; 30 type = types.attrsOf ( 31 types.submodule { 32 freeformType = types.attrsOf ( 33 types.oneOf [ 34 types.str 35 types.int 36 types.bool 37 ] 38 ); 39 options = { 40 database = mkOption { 41 type = types.nullOr types.str; 42 default = null; 43 example = "mailpit.db"; 44 description = '' 45 Specify the local database filename to store persistent data. 46 If `null`, a temporary file will be created that will be removed when the application stops. 47 It's recommended to specify a relative path. The database will be written into the service's 48 state directory then. 49 ''; 50 }; 51 max = mkOption { 52 type = types.ints.unsigned; 53 default = 500; 54 description = '' 55 Maximum number of emails to keep. If the number is exceeded, old emails 56 will be deleted. 57 58 Set to `0` to never prune old emails. 59 ''; 60 }; 61 listen = mkOption { 62 default = "127.0.0.1:8025"; 63 type = types.str; 64 description = '' 65 HTTP bind interface and port for UI. 66 ''; 67 }; 68 smtp = mkOption { 69 default = "127.0.0.1:1025"; 70 type = types.str; 71 description = '' 72 SMTP bind interface and port. 73 ''; 74 }; 75 }; 76 } 77 ); 78 description = '' 79 Configure mailpit instances. The attribute-set values are 80 CLI flags passed to the `mailpit` CLI. 81 82 See [upstream docs](https://mailpit.axllent.org/docs/configuration/runtime-options/) 83 for all available options. 84 ''; 85 }; 86 87 config = mkIf (instances != { }) { 88 systemd.services = mapAttrs' ( 89 name: cfg: 90 nameValuePair "mailpit-${name}" { 91 wantedBy = [ "multi-user.target" ]; 92 after = [ "network-online.target" ]; 93 wants = [ "network-online.target" ]; 94 serviceConfig = { 95 DynamicUser = true; 96 StateDirectory = "mailpit"; 97 WorkingDirectory = "%S/mailpit"; 98 ExecStart = "${getExe pkgs.mailpit} ${genCliFlags cfg}"; 99 Restart = "on-failure"; 100 }; 101 } 102 ) instances; 103 }; 104 105 meta.maintainers = lib.teams.flyingcircus.members; 106}