diff --git a/nixos/modules/services/mail/dovecot.nix b/nixos/modules/services/mail/dovecot.nix index 135d3b277378..6057acc531a3 100644 --- a/nixos/modules/services/mail/dovecot.nix +++ b/nixos/modules/services/mail/dovecot.nix @@ -9,6 +9,8 @@ let baseDir = "/run/dovecot2"; stateDir = "/var/lib/dovecot"; + canCreateMailUserGroup = cfg.mailUser != null && cfg.mailGroup != null; + dovecotConf = concatStrings [ '' base_dir = ${baseDir} @@ -314,17 +316,18 @@ in description = "Dovecot user"; group = cfg.group; } - ++ optional cfg.createMailUser - { name = cfg.mailUser; - description = "Virtual Mail User"; + ++ optional (cfg.createMailUser && cfg.mailUser != null) + ({ name = cfg.mailUser; + description = "Virtual Mail User"; + } // optionalAttrs (cfg.mailGroup != null) { group = cfg.mailGroup; - }; + }); users.extraGroups = optional (cfg.group == "dovecot2") { name = "dovecot2"; gid = config.ids.gids.dovecot2; } - ++ optional cfg.createMailUser + ++ optional (cfg.createMailUser && cfg.mailGroup != null) { name = cfg.mailGroup; }; diff --git a/nixos/release.nix b/nixos/release.nix index f8d2e3145324..cbb566af7863 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -236,6 +236,7 @@ in rec { tests.containers-macvlans = callTest tests/containers-macvlans.nix {}; tests.docker = hydraJob (import tests/docker.nix { system = "x86_64-linux"; }); tests.docker-edge = hydraJob (import tests/docker-edge.nix { system = "x86_64-linux"; }); + tests.dovecot = callTest tests/dovecot.nix {}; tests.dnscrypt-proxy = callTest tests/dnscrypt-proxy.nix { system = "x86_64-linux"; }; tests.ecryptfs = callTest tests/ecryptfs.nix {}; tests.etcd = hydraJob (import tests/etcd.nix { system = "x86_64-linux"; }); diff --git a/nixos/tests/dovecot.nix b/nixos/tests/dovecot.nix new file mode 100644 index 000000000000..3814855ed8e7 --- /dev/null +++ b/nixos/tests/dovecot.nix @@ -0,0 +1,64 @@ +import ./make-test.nix { + name = "dovecot"; + + machine = { pkgs, ... }: { + imports = [ common/user-account.nix ]; + services.postfix.enable = true; + services.dovecot2.enable = true; + services.dovecot2.protocols = [ "imap" "pop3" ]; + environment.systemPackages = let + sendTestMail = pkgs.writeScriptBin "send-testmail" '' + #!${pkgs.stdenv.shell} + exec sendmail -vt <waitForUnit('postfix.service'); + $machine->waitForUnit('dovecot2.service'); + $machine->succeed('send-testmail'); + $machine->waitUntilFails('[ "$(postqueue -p)" != "Mail queue is empty" ]'); + $machine->succeed('test-imap'); + $machine->succeed('test-pop'); + ''; +}