2024-11-05 14:39:49 +01:00
|
|
|
{config, ...}: let
|
2024-11-05 18:35:52 +01:00
|
|
|
domain = "gasdev.fr";
|
2024-11-05 14:39:49 +01:00
|
|
|
in {
|
|
|
|
sops.secrets."stalwart-mail/ADMIN_SECRET".owner = "stalwart-mail";
|
2024-11-10 19:52:04 +01:00
|
|
|
sops.secrets."stalwart-mail/ACME_SECRET".owner = "stalwart-mail";
|
2024-11-05 14:39:49 +01:00
|
|
|
|
2024-11-10 19:52:04 +01:00
|
|
|
services.caddy.virtualHosts."mailadmin.${domain}" = {
|
2024-11-11 00:15:07 +01:00
|
|
|
extraConfig = ''
|
|
|
|
reverse_proxy http://127.0.01:40312
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
services.caddy.virtualHosts."mail.${domain}" = {
|
2024-11-10 19:52:04 +01:00
|
|
|
extraConfig = ''
|
|
|
|
reverse_proxy http://127.0.01:8080
|
|
|
|
'';
|
|
|
|
serverAliases = [
|
|
|
|
"mta-sts.${domain}"
|
|
|
|
"autoconfig.${domain}"
|
|
|
|
"autodiscover.${domain}"
|
2024-11-11 00:15:07 +01:00
|
|
|
"${domain}"
|
2024-11-10 19:52:04 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
networking.firewall.allowedTCPPorts = [25 465 587 993];
|
2024-11-05 14:39:49 +01:00
|
|
|
|
|
|
|
services.stalwart-mail = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
server = {
|
2024-11-11 00:15:07 +01:00
|
|
|
hostname = "mail.${domain}";
|
2024-11-10 19:52:04 +01:00
|
|
|
tls = {
|
|
|
|
enable = true;
|
|
|
|
implicit = true;
|
2024-11-05 14:39:49 +01:00
|
|
|
};
|
|
|
|
listener = {
|
|
|
|
smtp = {
|
|
|
|
protocol = "smtp";
|
2024-11-10 19:52:04 +01:00
|
|
|
bind = "[::]:25";
|
2024-11-05 14:39:49 +01:00
|
|
|
};
|
|
|
|
submissions = {
|
2024-11-10 19:52:04 +01:00
|
|
|
bind = "[::]:465";
|
2024-11-05 14:39:49 +01:00
|
|
|
protocol = "smtp";
|
2024-11-11 00:15:07 +01:00
|
|
|
tls.implicit = true;
|
2024-11-05 14:39:49 +01:00
|
|
|
};
|
2024-11-10 19:52:04 +01:00
|
|
|
imaps = {
|
|
|
|
bind = "[::]:993";
|
2024-11-05 14:39:49 +01:00
|
|
|
protocol = "imap";
|
2024-11-11 00:15:07 +01:00
|
|
|
tls.implicit = true;
|
2024-11-05 14:39:49 +01:00
|
|
|
};
|
2024-11-10 19:52:04 +01:00
|
|
|
jmap = {
|
2024-11-05 14:39:49 +01:00
|
|
|
bind = "[::]:8080";
|
2024-11-11 00:15:07 +01:00
|
|
|
protocol = "http";
|
|
|
|
tls.implicit = false;
|
2024-11-10 19:52:04 +01:00
|
|
|
};
|
|
|
|
management = {
|
2024-11-11 00:15:07 +01:00
|
|
|
bind = ["127.0.0.1:40312"];
|
2024-11-05 14:39:49 +01:00
|
|
|
protocol = "http";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-11-10 19:52:04 +01:00
|
|
|
lookup.default = {
|
2024-11-11 00:15:07 +01:00
|
|
|
hostname = "mail.${domain}";
|
2024-11-10 19:52:04 +01:00
|
|
|
domain = "${domain}";
|
2024-11-05 14:39:49 +01:00
|
|
|
};
|
2024-11-11 00:15:07 +01:00
|
|
|
certificate.default = {
|
2024-11-10 22:25:11 +01:00
|
|
|
default = true;
|
2024-11-11 00:15:07 +01:00
|
|
|
cert = "%{file:/var/lib/stalwart-mail/cert/mail.${domain}.pem}%";
|
|
|
|
private-key = "%{file:/var/lib/stalwart-mail/cert/mail.${domain}.priv.pem}%";
|
2024-11-10 19:52:04 +01:00
|
|
|
};
|
|
|
|
session.auth = {
|
2024-11-11 00:15:07 +01:00
|
|
|
mechanisms = "[plain, login]";
|
2024-11-10 19:52:04 +01:00
|
|
|
};
|
|
|
|
directory."imap".lookup.domains = ["${domain}"];
|
2024-11-05 14:39:49 +01:00
|
|
|
storage = {
|
|
|
|
data = "rocksdb";
|
|
|
|
fts = "rocksdb";
|
|
|
|
blob = "rocksdb";
|
|
|
|
lookup = "rocksdb";
|
|
|
|
directory = "internal";
|
|
|
|
};
|
|
|
|
store."rocksdb" = {
|
|
|
|
type = "rocksdb";
|
|
|
|
path = "%{env:STALWART_PATH}%/data";
|
|
|
|
compression = "lz4";
|
|
|
|
};
|
|
|
|
directory."internal" = {
|
|
|
|
type = "internal";
|
|
|
|
store = "rocksdb";
|
|
|
|
};
|
|
|
|
tracer."stdout" = {
|
|
|
|
type = "stdout";
|
|
|
|
level = "info";
|
|
|
|
ansi = false;
|
|
|
|
enable = true;
|
|
|
|
};
|
2024-11-10 22:25:11 +01:00
|
|
|
tracer."journal" = {
|
|
|
|
type = "journal";
|
|
|
|
level = "info";
|
|
|
|
enable = true;
|
|
|
|
};
|
2024-11-05 14:39:49 +01:00
|
|
|
authentication."fallback-admin" = {
|
|
|
|
user = "admin";
|
|
|
|
secret = "%{file:${config.sops.secrets."stalwart-mail/ADMIN_SECRET".path}}%";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.stalwart-mail = {
|
|
|
|
environment = {
|
|
|
|
STALWART_PATH = "/var/lib/stalwart-mail";
|
|
|
|
};
|
|
|
|
serviceConfig = {
|
|
|
|
StateDirectory = "stalwart-mail";
|
|
|
|
StateDirectoryMode = "0740";
|
|
|
|
};
|
|
|
|
};
|
2024-11-11 00:15:07 +01:00
|
|
|
|
|
|
|
systemd.timers."stalwart-mail-update-certs" = {
|
|
|
|
wantedBy = ["timers.target"];
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "daily";
|
|
|
|
Persistent = true;
|
|
|
|
Unit = "stalwart-mail-update-certs.service";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services."stalwart-mail-update-certs" = {
|
|
|
|
script = ''
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
CADDY_CERT_DIR="/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/mail.${domain}"
|
|
|
|
STALWART_CERT_DIR="/var/lib/stalwart-mail/cert"
|
|
|
|
|
|
|
|
mkdir -p "''\${CADDY_CERT_DIR}"
|
|
|
|
mkdir -p "''\${STALWART_CERT_DIR}"
|
|
|
|
|
|
|
|
cat "''\${CADDY_CERT_DIR}/mail.${domain}.crt" > "''\${STALWART_CERT_DIR}/mail.${domain}.pem"
|
|
|
|
cat "''\${CADDY_CERT_DIR}/mail.${domain}.key" > "''\${STALWART_CERT_DIR}/mail.${domain}.priv.pem"
|
|
|
|
|
|
|
|
chown -R stalwart-mail:stalwart-mail "''\${STALWART_CERT_DIR}"
|
|
|
|
chmod -R 0700 "''\${STALWART_CERT_DIR}"
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = "root";
|
|
|
|
};
|
|
|
|
};
|
2024-11-05 14:39:49 +01:00
|
|
|
}
|