machines/nix/systems/aarch64-linux/mx.kaareskovgaard.net/mailserver/default.nix
Kaare Hoff Skovgaard 619984cd89
Some checks failed
/ dev-shell (push) Successful in 3m23s
/ check (push) Failing after 12m13s
/ rust-packages (push) Successful in 11m56s
/ terraform-providers (push) Successful in 17m7s
/ systems (push) Successful in 53m59s
Get email alerting working
2025-08-17 00:42:33 +02:00

131 lines
2.8 KiB
Nix

{
config,
lib,
inputs,
...
}:
let
cfg = config.khscodes."mx.kaareskovgaard.net";
fqdn = config.khscodes.networking.fqdn;
in
{
options.khscodes."mx.kaareskovgaard.net" = {
domains = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
};
postmaster = lib.mkOption {
type = lib.types.str;
};
abuse = lib.mkOption {
type = lib.types.str;
};
};
imports = [
inputs.simple-nixos-mailserver.nixosModules.mailserver
./accounts.nix
./acme.nix
./dmarc.nix
./dane.nix
./dkim.nix
./managesieve.nix
./mta-sts.nix
./spf.nix
./tls-rpt.nix
./prometheus.nix
./openid-connect.nix
./ldap.nix
./roundcube.nix
];
config = {
khscodes.infrastructure.hetzner-instance.extraFirewallRules = [
{
direction = "out";
protocol = "tcp";
port = 25;
destination_ips = [
"0.0.0.0/0"
"::/0"
];
description = "smtp";
}
];
khscodes.infrastructure.provisioning.compute.modules = [
(
{ ... }:
{
khscodes.cloudflare.dns.mxRecords = (
lib.lists.map (domain: {
fqdn = domain;
priority = 10;
content = fqdn;
ttl = 600;
}) cfg.domains
);
khscodes.cloudflare.dns.srvRecords = lib.lists.flatten (
lib.lists.map (domain: [
{
fqdn = "_imaps._tcp.${domain}";
content = fqdn;
priority = 0;
weight = 1;
port = 993;
ttl = 600;
}
{
fqdn = "_submissions._tcp.${domain}";
content = fqdn;
priority = 0;
weight = 1;
port = 465;
ttl = 600;
}
]) cfg.domains
);
}
)
];
mailserver = {
inherit (cfg) domains;
enable = true;
enableImap = false;
enableImapSsl = true;
enableSubmission = true;
enableSubmissionSsl = true;
fqdn = config.khscodes.networking.fqdn;
useUTF8FolderNames = true;
certificateScheme = "acme";
fullTextSearch = {
enable = true;
autoIndex = true;
enforced = "body";
};
};
services.fail2ban.jails = {
postfix = {
settings = {
enabled = true;
mode = "aggressive";
findtime = 600;
bantime = "1d";
maxretry = 3;
};
};
dovecot = {
settings = {
enabled = true;
mode = "aggressive";
findtime = 600;
bantime = "1d";
maxretry = 3;
};
};
};
networking.firewall.allowedTCPPorts = [
25
465
993
];
};
}