From 26ce9ac33bb72c5812aa9d974ecc773881b29c7d Mon Sep 17 00:00:00 2001 From: eyjhb Date: Thu, 22 Aug 2024 18:54:06 +0200 Subject: [PATCH] gerd.starwart: setup domain for stalwart automatically --- machines/gerd/services/stalwart/stalwart.nix | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/machines/gerd/services/stalwart/stalwart.nix b/machines/gerd/services/stalwart/stalwart.nix index 3444e66..f27af6d 100644 --- a/machines/gerd/services/stalwart/stalwart.nix +++ b/machines/gerd/services/stalwart/stalwart.nix @@ -113,6 +113,29 @@ in { }; }; + # ensure that the configured domain is added to stalwart + systemd.services.stalwart-mail.serviceConfig.ExecStartPost = let + stalwart-cli = config.services.stalwart-mail.package + "/bin/stalwart-cli"; + in pkgs.writeShellScript "stalwart-setup" '' + # TODO(eyjhb): at some point this should be changed + sleep 10 + + export URL="http://127.0.0.1:${builtins.toString ports.http_management}" + export CREDENTIALS="$(cat ${config.age.secrets.stalwart-admin-fallback-password.path})" + + if ${stalwart-cli} domain list | grep --quiet -- '${config.mine.shared.settings.domain}'; then + echo "Domain is already created, doing nothing." + else + echo "Domain was not created, creating it now." + ${stalwart-cli} domain create '${config.mine.shared.settings.domain}' + fi + + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + echo "Remember to setup the correct DNS records. Run the following command to get them:" + echo "URL=\"$URL\" stalwart-cli domain dns-records ${config.mine.shared.settings.domain}" + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + ''; + # setup so that stalwart can access and write to the directory systemd.services.stalwart-mail.serviceConfig.ReadWritePaths = [ stateDir ]; systemd.tmpfiles.rules = [