2023-08-09 15:11:04 +01:00
|
|
|
{
|
2023-09-18 03:56:58 +01:00
|
|
|
self,
|
2023-08-09 15:11:04 +01:00
|
|
|
tree,
|
|
|
|
lib,
|
|
|
|
inputs,
|
|
|
|
config,
|
2023-09-16 16:06:16 +01:00
|
|
|
pkgs,
|
2023-09-18 03:56:58 +01:00
|
|
|
hostPath,
|
2023-08-09 15:11:04 +01:00
|
|
|
...
|
|
|
|
}: let
|
2023-09-18 03:56:58 +01:00
|
|
|
inherit (lib.modules) mkMerge;
|
|
|
|
inherit (lib.lists) forEach;
|
|
|
|
|
2023-08-09 15:11:04 +01:00
|
|
|
ports = [
|
|
|
|
# SMTP
|
|
|
|
25
|
|
|
|
# Submission
|
|
|
|
587
|
|
|
|
# Submission w/ SSL
|
|
|
|
465
|
|
|
|
# IMAP
|
|
|
|
143
|
|
|
|
# IMAP w/ SSL
|
|
|
|
993
|
|
|
|
# Sieve
|
|
|
|
4190
|
|
|
|
];
|
|
|
|
|
2023-09-18 03:56:58 +01:00
|
|
|
containerLib = import "${self}/lib/containerLib.nix" {
|
|
|
|
inherit lib;
|
|
|
|
};
|
|
|
|
|
2023-08-09 15:11:04 +01:00
|
|
|
# Using secrets from Host
|
|
|
|
secrets = config.services.secrets.secrets;
|
2023-09-18 03:56:58 +01:00
|
|
|
secretsList = [
|
2023-08-09 15:11:04 +01:00
|
|
|
"mail_restic_password"
|
|
|
|
"mail_restic_env"
|
|
|
|
"private_mail_aliases"
|
|
|
|
"chaos_mail_passwd"
|
|
|
|
"system_mail_passwd"
|
2023-09-02 18:17:03 +01:00
|
|
|
"gotosocial_mail_passwd"
|
2023-08-09 15:11:04 +01:00
|
|
|
];
|
2023-09-18 03:56:58 +01:00
|
|
|
sharedFiles = [
|
2023-08-09 15:11:04 +01:00
|
|
|
"/var/lib/acme/mail.owo.monster/fullchain.pem"
|
|
|
|
"/var/lib/acme/mail.owo.monster/key.pem"
|
|
|
|
];
|
|
|
|
in {
|
|
|
|
containers.mail = {
|
|
|
|
autoStart = true;
|
2023-08-09 20:53:22 +01:00
|
|
|
|
2023-09-18 03:56:58 +01:00
|
|
|
bindMounts = mkMerge [
|
|
|
|
(containerLib.genBindHostsForSecrets secrets secretsList)
|
|
|
|
|
|
|
|
(mkMerge (forEach sharedFiles (file: {
|
2023-08-09 15:11:04 +01:00
|
|
|
"${file}" = {
|
|
|
|
hostPath = "${file}";
|
|
|
|
};
|
|
|
|
})))
|
|
|
|
];
|
|
|
|
|
2023-09-16 16:06:16 +01:00
|
|
|
specialArgs = {
|
|
|
|
inherit inputs;
|
|
|
|
inherit tree;
|
2023-09-18 03:56:58 +01:00
|
|
|
inherit self;
|
|
|
|
inherit hostPath;
|
|
|
|
hostSecrets = secrets;
|
2023-09-16 16:06:16 +01:00
|
|
|
};
|
|
|
|
|
2023-09-11 23:22:18 +01:00
|
|
|
config = {config, ...}: {
|
2023-09-16 16:06:16 +01:00
|
|
|
nixpkgs.pkgs = pkgs;
|
2023-08-09 15:11:04 +01:00
|
|
|
|
|
|
|
imports = with tree;
|
|
|
|
[
|
|
|
|
profiles.base
|
|
|
|
inputs.home-manager-unstable.nixosModules.home-manager
|
|
|
|
|
2023-09-02 17:42:27 +01:00
|
|
|
profiles.nginx
|
2023-08-09 15:11:04 +01:00
|
|
|
modules.nixos.secrets
|
|
|
|
|
|
|
|
users.root
|
|
|
|
]
|
|
|
|
++ (with hosts.hetzner-vm.containers.mail; [
|
2023-08-09 15:47:01 +01:00
|
|
|
modules.mailserver
|
2023-08-09 15:11:04 +01:00
|
|
|
profiles.mailserver
|
|
|
|
profiles.restic
|
|
|
|
]);
|
|
|
|
|
|
|
|
# For Shared Secrets
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d ${config.services.secrets.secretsDir} - root root"
|
|
|
|
"d /var/lib/acme - root root"
|
|
|
|
"d /var/lib/acme/mail.owo.monster - root root"
|
|
|
|
];
|
|
|
|
|
|
|
|
networking.firewall = {
|
2023-08-09 20:53:22 +01:00
|
|
|
enable = false;
|
2023-08-09 15:11:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
home-manager.users.root = {
|
|
|
|
imports = with tree; [home.base home.dev.small];
|
|
|
|
|
|
|
|
home.stateVersion = "23.05";
|
|
|
|
};
|
|
|
|
|
|
|
|
# Manually configure nameserver. Using resolved inside the container seems to fail
|
|
|
|
# currently
|
|
|
|
environment.etc."resolv.conf".text = "nameserver 8.8.8.8";
|
|
|
|
system.stateVersion = "23.05";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# users for secrets
|
|
|
|
users.users."dovecot2" = {
|
|
|
|
uid = config.ids.uids.dovecot2;
|
|
|
|
group = "dovecot2";
|
|
|
|
};
|
|
|
|
users.groups."dovecot2".gid = config.ids.gids.dovecot2;
|
|
|
|
|
|
|
|
# ssl for mail
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts."mail.owo.monster" = {
|
|
|
|
serverName = "mail.owo.monster";
|
|
|
|
serverAliases = ["owo.monster"];
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
acmeRoot = "/var/lib/acme/acme-challenge";
|
|
|
|
# also being used for webmail
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://unix:/var/lib/nixos-containers/mail/var/sockets/roundcube.sock";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-08-09 20:53:22 +01:00
|
|
|
networking.firewall = {
|
|
|
|
allowedTCPPorts = ports;
|
|
|
|
allowedUDPPorts = ports;
|
|
|
|
};
|
2023-08-09 15:11:04 +01:00
|
|
|
}
|