os/hosts/frikandel/email.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
2.5 KiB
Nix
Raw Normal View History

2023-11-12 17:33:58 +00:00
{
2023-11-13 14:48:05 +00:00
flake,
config,
2023-11-12 17:33:58 +00:00
pkgs,
lib,
...
2023-11-13 14:48:05 +00:00
}: let
restartMaddyOnCertRenewal = pkgs.writeShellScriptBin "restart-maddy-on-cert-renewal" ''
if [ "$1" == "mail.b12f.io"]; then
${pkgs.systemd}/bin/systemctl restart maddy.service;
fi
'';
in {
age.secrets."b12f.io-dkim-private-rsa" = {
file = "${flake.self}/secrets/b12f.io-dkim-private-rsa.age";
mode = "400";
owner = "rspamd";
};
2023-11-12 17:33:58 +00:00
age.secrets."mail@b12f.io-password" = {
file = "${flake.self}/secrets/mail@b12f.io-password.age";
mode = "400";
2023-11-13 14:48:05 +00:00
owner = "maddy";
2023-11-12 17:33:58 +00:00
};
2023-11-13 14:48:05 +00:00
services.caddy = {
globalConfig = ''
events {
on cert_obtained exec ${restartMaddyOnCertRenewal}/bin/restart-maddy-on-cert-renewal {event.data.name}
}
'';
virtualHosts = {
"mail.b12f.io".extraConfig = ''
2023-11-12 20:45:02 +00:00
respond "404 Not Found"
'';
2023-11-13 14:48:05 +00:00
"mta-sts.b12f.io".extraConfig = ''
encode gzip
file_server
root * ${
pkgs.runCommand "testdir" {} ''
mkdir -p "$out/.well-known"
echo "
version: STSv1
mode: enforce
max_age: 604800
mx: mail.b12f.io
" > "$out/.well-known/mta-sts.txt"
''
}
'';
2023-11-12 20:45:02 +00:00
};
};
2023-11-12 17:33:58 +00:00
services.maddy = {
2023-11-12 20:45:02 +00:00
enable = false;
openFirewall = true;
2023-11-13 14:48:05 +00:00
hostname = "mail.b12f.io";
2023-11-12 17:33:58 +00:00
primaryDomain = "b12f.io";
ensureAccounts = [
"mail@b12f.io"
];
ensureCredentials = {
# Do not use this in production. This will make passwords world-readable
# in the Nix store
2023-11-13 14:48:05 +00:00
"mail@b12f.io".passwordFile = config.age.secrets."mail@b12f.io-password".path;
2023-11-12 17:33:58 +00:00
};
tls = {
certificates = [
{
2023-11-13 14:48:05 +00:00
keyPath = "/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/mail.b12f.io/mail.b12f.io.key";
certPath = "/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/mail.b12f.io/mail.b12f.io.crt";
2023-11-12 17:33:58 +00:00
}
];
};
2023-11-13 14:48:05 +00:00
config = (builtins.replaceStrings ["msgpipeline local_routing {"] [''msgpipeline local_routing {
check {
rspamd {
api_path http://localhost:11334
}
}''] config.services.maddy.config.default) ++ ''
modify {
domains b12f.io
selector default
key_path ${config.age.secrets."b12f.io-dkim-private-rsa".path}
}
'';
2023-11-12 17:33:58 +00:00
};
2023-11-13 14:48:05 +00:00
services.rspamd = {
enable = true;
locals."dkim_signing.conf".text = ''
enabled = false;
'';
};
systemd.services.rspamd.serviceConfig.SupplementaryGroups = [ "maddy" ];
2023-11-12 17:33:58 +00:00
}