gerd.starwart: setup domain for stalwart automatically

This commit is contained in:
eyjhb 2024-08-22 18:54:06 +02:00
parent bd70d0a603
commit 26ce9ac33b
No known key found for this signature in database
GPG key ID: 609F508E3239F920

View file

@ -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 = [