1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-17 19:21:04 +00:00

nixos/mailpit: allow multiple instances

Now it's possible to start multiple mailpit instances - for e.g.
multiple testing environments - on the same machine:

    {
      services.mailpit.instances = {
        dev = { /* ... */ };
        staging = { /* ... */ };
      };
    }

The simplest way to start a single instance is by declaring

    services.mailpit.instances.default = {};
This commit is contained in:
Maximilian Bosch 2024-07-29 15:12:35 +02:00
parent a2437d8075
commit 15dab820a6
No known key found for this signature in database
GPG key ID: 797C8FD26F815B0E
2 changed files with 36 additions and 33 deletions

View file

@ -6,31 +6,29 @@
}: }:
let let
cfg = config.services.mailpit; inherit (config.services.mailpit) instances;
inherit (lib) inherit (lib)
cli cli
concatStringsSep concatStringsSep
const const
filterAttrs filterAttrs
getExe getExe
mkEnableOption mapAttrs'
mkIf mkIf
mkOption mkOption
nameValuePair
types types
; ;
isNonNull = v: v != null; isNonNull = v: v != null;
cliFlags = concatStringsSep " " ( genCliFlags =
cli.toGNUCommandLine { } (filterAttrs (const isNonNull) cfg.settings) settings: concatStringsSep " " (cli.toGNUCommandLine { } (filterAttrs (const isNonNull) settings));
);
in in
{ {
options.services.mailpit = { options.services.mailpit.instances = mkOption {
enable = mkEnableOption "mailpit"; default = { };
type = types.attrsOf (
settings = mkOption { types.submodule {
default = { };
type = types.submodule {
freeformType = types.attrsOf ( freeformType = types.attrsOf (
types.oneOf [ types.oneOf [
types.str types.str
@ -75,28 +73,33 @@ in
''; '';
}; };
}; };
}; }
description = '' );
Attribute-set of all flags passed to mailpit. See description = ''
[upstream docs](https://mailpit.axllent.org/docs/configuration/runtime-options/) Configure mailpit instances. The attribute-set values are
for all available options. CLI flags passed to the `mailpit` CLI.
'';
}; See [upstream docs](https://mailpit.axllent.org/docs/configuration/runtime-options/)
for all available options.
'';
}; };
config = mkIf cfg.enable { config = mkIf (instances != { }) {
systemd.services.mailpit = { systemd.services = mapAttrs' (
wantedBy = [ "multi-user.target" ]; name: cfg:
after = [ "network-online.target" ]; nameValuePair "mailpit-${name}" {
wants = [ "network-online.target" ]; wantedBy = [ "multi-user.target" ];
serviceConfig = { after = [ "network-online.target" ];
DynamicUser = true; wants = [ "network-online.target" ];
StateDirectory = "mailpit"; serviceConfig = {
WorkingDirectory = "%S/mailpit"; DynamicUser = true;
ExecStart = "${getExe pkgs.mailpit} ${cliFlags}"; StateDirectory = "mailpit";
Restart = "on-failure"; WorkingDirectory = "%S/mailpit";
}; ExecStart = "${getExe pkgs.mailpit} ${genCliFlags cfg}";
}; Restart = "on-failure";
};
}
) instances;
}; };
meta.maintainers = lib.teams.flyingcircus.members; meta.maintainers = lib.teams.flyingcircus.members;

View file

@ -7,7 +7,7 @@ import ./make-test-python.nix (
nodes.machine = nodes.machine =
{ pkgs, ... }: { pkgs, ... }:
{ {
services.mailpit.enable = true; services.mailpit.instances.default = { };
environment.systemPackages = with pkgs; [ swaks ]; environment.systemPackages = with pkgs; [ swaks ];
}; };
@ -17,7 +17,7 @@ import ./make-test-python.nix (
from json import loads from json import loads
machine.wait_for_unit("mailpit.service") machine.wait_for_unit("mailpit-default.service")
machine.wait_for_open_port(1025) machine.wait_for_open_port(1025)
machine.wait_for_open_port(8025) machine.wait_for_open_port(8025)
machine.succeed( machine.succeed(