mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-25 16:33:15 +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:
parent
a2437d8075
commit
15dab820a6
@ -6,31 +6,29 @@
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.services.mailpit;
|
||||
inherit (config.services.mailpit) instances;
|
||||
inherit (lib)
|
||||
cli
|
||||
concatStringsSep
|
||||
const
|
||||
filterAttrs
|
||||
getExe
|
||||
mkEnableOption
|
||||
mapAttrs'
|
||||
mkIf
|
||||
mkOption
|
||||
nameValuePair
|
||||
types
|
||||
;
|
||||
|
||||
isNonNull = v: v != null;
|
||||
cliFlags = concatStringsSep " " (
|
||||
cli.toGNUCommandLine { } (filterAttrs (const isNonNull) cfg.settings)
|
||||
);
|
||||
genCliFlags =
|
||||
settings: concatStringsSep " " (cli.toGNUCommandLine { } (filterAttrs (const isNonNull) settings));
|
||||
in
|
||||
{
|
||||
options.services.mailpit = {
|
||||
enable = mkEnableOption "mailpit";
|
||||
|
||||
settings = mkOption {
|
||||
default = { };
|
||||
type = types.submodule {
|
||||
options.services.mailpit.instances = mkOption {
|
||||
default = { };
|
||||
type = types.attrsOf (
|
||||
types.submodule {
|
||||
freeformType = types.attrsOf (
|
||||
types.oneOf [
|
||||
types.str
|
||||
@ -75,28 +73,33 @@ in
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
description = ''
|
||||
Attribute-set of all flags passed to mailpit. See
|
||||
[upstream docs](https://mailpit.axllent.org/docs/configuration/runtime-options/)
|
||||
for all available options.
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
description = ''
|
||||
Configure mailpit instances. The attribute-set values are
|
||||
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 {
|
||||
systemd.services.mailpit = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
serviceConfig = {
|
||||
DynamicUser = true;
|
||||
StateDirectory = "mailpit";
|
||||
WorkingDirectory = "%S/mailpit";
|
||||
ExecStart = "${getExe pkgs.mailpit} ${cliFlags}";
|
||||
Restart = "on-failure";
|
||||
};
|
||||
};
|
||||
config = mkIf (instances != { }) {
|
||||
systemd.services = mapAttrs' (
|
||||
name: cfg:
|
||||
nameValuePair "mailpit-${name}" {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
serviceConfig = {
|
||||
DynamicUser = true;
|
||||
StateDirectory = "mailpit";
|
||||
WorkingDirectory = "%S/mailpit";
|
||||
ExecStart = "${getExe pkgs.mailpit} ${genCliFlags cfg}";
|
||||
Restart = "on-failure";
|
||||
};
|
||||
}
|
||||
) instances;
|
||||
};
|
||||
|
||||
meta.maintainers = lib.teams.flyingcircus.members;
|
||||
|
@ -7,7 +7,7 @@ import ./make-test-python.nix (
|
||||
nodes.machine =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
services.mailpit.enable = true;
|
||||
services.mailpit.instances.default = { };
|
||||
|
||||
environment.systemPackages = with pkgs; [ swaks ];
|
||||
};
|
||||
@ -17,7 +17,7 @@ import ./make-test-python.nix (
|
||||
|
||||
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(8025)
|
||||
machine.succeed(
|
||||
|
Loading…
Reference in New Issue
Block a user