From b7ab1fa981ffbc2adbc63de403c2b49368ca8c6b Mon Sep 17 00:00:00 2001 From: Diogo Correia Date: Thu, 29 May 2025 12:11:58 +0100 Subject: [PATCH] nixos/stalwart-mail: fix incorrect config for webadmin and spam-filter Stalwart 0.11.0 changed the `config.resource.spam-filter` and `config.resource.webadmin` keys to be `spam-filter.resource` and `webadmin.resource` respectively. The NixOS has been updated accordingly, but unfortunately it has mistakenly used `config.spam-filter.resource` and `config.webadmin.resource`, which are incorrect and do not do anything. This commit changes the default configuration to use the correct keys. Note that due to infinite recursion, the `optionalAttrs` has been replaced with `mkIf`. Additionally, some tests were added to catch this regression in the future. Fixes #411351 --- nixos/modules/services/mail/stalwart-mail.nix | 26 ++++++++----------- nixos/tests/stalwart-mail.nix | 9 +++++++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/nixos/modules/services/mail/stalwart-mail.nix b/nixos/modules/services/mail/stalwart-mail.nix index 42198573ec09..6622a2dcd114 100644 --- a/nixos/modules/services/mail/stalwart-mail.nix +++ b/nixos/modules/services/mail/stalwart-mail.nix @@ -107,21 +107,17 @@ in resolver.public-suffix = lib.mkDefault [ "file://${pkgs.publicsuffix-list}/share/publicsuffix/public_suffix_list.dat" ]; - config = { - spam-filter.resource = lib.mkDefault "file://${cfg.package}/etc/stalwart/spamfilter.toml"; - webadmin = - let - hasHttpListener = builtins.any (listener: listener.protocol == "http") ( - lib.attrValues cfg.settings.server.listener - ); - in - { - path = "/var/cache/stalwart-mail"; - } - // lib.optionalAttrs ((builtins.hasAttr "listener" cfg.settings.server) && hasHttpListener) { - resource = lib.mkDefault "file://${cfg.package.webadmin}/webadmin.zip"; - }; - }; + spam-filter.resource = lib.mkDefault "file://${cfg.package}/etc/stalwart/spamfilter.toml"; + webadmin = + let + hasHttpListener = builtins.any (listener: listener.protocol == "http") ( + lib.attrValues (cfg.settings.server.listener or { }) + ); + in + { + path = "/var/cache/stalwart-mail"; + resource = lib.mkIf (hasHttpListener) (lib.mkDefault "file://${cfg.package.webadmin}/webadmin.zip"); + }; }; # This service stores a potentially large amount of data. diff --git a/nixos/tests/stalwart-mail.nix b/nixos/tests/stalwart-mail.nix index cfc0d3bb1c5b..361fd85e34a6 100644 --- a/nixos/tests/stalwart-mail.nix +++ b/nixos/tests/stalwart-mail.nix @@ -42,6 +42,11 @@ in bind = [ "[::]:143" ]; protocol = "imap"; }; + + "http" = { + bind = [ "[::]:80" ]; + protocol = "http"; + }; }; session.auth.mechanisms = "[plain]"; @@ -114,9 +119,13 @@ in main.wait_for_unit("stalwart-mail.service") main.wait_for_open_port(587) main.wait_for_open_port(143) + main.wait_for_open_port(80) main.succeed("test-smtp-submission") main.succeed("test-imap-read") + + main.succeed("test -d /var/cache/stalwart-mail/STALWART_WEBADMIN") + main.succeed("curl --fail http://localhost") ''; meta = {