nixos/mailhog: run with DynamicUser
This commit is contained in:
parent
d3b47f1556
commit
9123308be5
|
@ -4,17 +4,59 @@ with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.mailhog;
|
cfg = config.services.mailhog;
|
||||||
in {
|
|
||||||
|
args = lib.concatStringsSep " " (
|
||||||
|
[
|
||||||
|
"-api-bind-addr :${toString cfg.apiPort}"
|
||||||
|
"-smtp-bind-addr :${toString cfg.smtpPort}"
|
||||||
|
"-ui-bind-addr :${toString cfg.uiPort}"
|
||||||
|
"-storage ${cfg.storage}"
|
||||||
|
] ++ lib.optional (cfg.storage == "maildir")
|
||||||
|
"-maildir-path $STATE_DIRECTORY"
|
||||||
|
++ cfg.extraArgs
|
||||||
|
);
|
||||||
|
|
||||||
|
in
|
||||||
|
{
|
||||||
###### interface
|
###### interface
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
(mkRemovedOptionModule [ "services" "mailhog" "user" ] "")
|
||||||
|
];
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
services.mailhog = {
|
services.mailhog = {
|
||||||
enable = mkEnableOption "MailHog";
|
enable = mkEnableOption "MailHog";
|
||||||
user = mkOption {
|
|
||||||
type = types.str;
|
storage = mkOption {
|
||||||
default = "mailhog";
|
type = types.enum [ "maildir" "memory" ];
|
||||||
description = "User account under which mailhog runs.";
|
default = "memory";
|
||||||
|
description = "Store mails on disk or in memory.";
|
||||||
|
};
|
||||||
|
|
||||||
|
apiPort = mkOption {
|
||||||
|
type = types.port;
|
||||||
|
default = 8025;
|
||||||
|
description = "Port on which the API endpoint will listen.";
|
||||||
|
};
|
||||||
|
|
||||||
|
smtpPort = mkOption {
|
||||||
|
type = types.port;
|
||||||
|
default = 1025;
|
||||||
|
description = "Port on which the SMTP endpoint will listen.";
|
||||||
|
};
|
||||||
|
|
||||||
|
uiPort = mkOption {
|
||||||
|
type = types.port;
|
||||||
|
default = 8025;
|
||||||
|
description = "Port on which the HTTP UI will listen.";
|
||||||
|
};
|
||||||
|
|
||||||
|
extraArgs = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [];
|
||||||
|
description = "List of additional arguments to pass to the MailHog process.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -24,20 +66,16 @@ in {
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
users.users.mailhog = {
|
|
||||||
name = cfg.user;
|
|
||||||
description = "MailHog service user";
|
|
||||||
isSystemUser = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
systemd.services.mailhog = {
|
systemd.services.mailhog = {
|
||||||
description = "MailHog service";
|
description = "MailHog - Web and API based SMTP testing";
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "simple";
|
Type = "exec";
|
||||||
ExecStart = "${pkgs.mailhog}/bin/MailHog";
|
ExecStart = "${pkgs.mailhog}/bin/MailHog ${args}";
|
||||||
User = cfg.user;
|
DynamicUser = true;
|
||||||
|
Restart = "on-failure";
|
||||||
|
StateDirectory = "mailhog";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue