dotfiles/nixos/modules/services/castopod.nix

103 lines
2.3 KiB
Nix
Raw Normal View History

2024-10-06 15:25:05 -05:00
{
flake,
config,
...
}: let
inherit (flake.config.people) user0;
inherit (flake.config.people.user.${user0}) domain email;
inherit (flake.config.system.device) server wildcard;
inherit (flake.config.service.instance.castopod) paths ports subdomain name sops ssl;
inherit (flake.config.service.instance) nginx;
localhost = wildcard.ip.address0;
host = "${subdomain}.${domain.url1}";
in {
services = {
castopod = {
enable = true;
localDomain = host;
configureNginx = false;
environmentFile = config.sops.secrets."${name}-smtp".path;
maxUploadSize = "1024M";
database = {
createLocally = true;
# passwordFile = config.sops.secrets."${name}-database".path;
};
poolSettings = {
pm = "dynamic";
"pm.max_children" = "32";
"pm.max_requests" = "500";
"pm.max_spare_servers" = "4";
"pm.min_spare_servers" = "2";
"pm.start_servers" = "2";
};
settings = {
"email.fromEmail" = email.address6;
"email.protocol" = "smtp";
"email.SMTPHost" = localhost;
"email.SMTPPort" = 587;
"email.SMTPUser" = "smtp.protonmail.ch";
};
};
nginx = {
enable = true;
virtualHosts = {
"${host}" = {
};
};
};
caddy = {
virtualHosts = {
"${host}" = {
extraConfig = ''
reverse_proxy ${localhost}:${toString ports.port0}
tls ${ssl.cert} ${ssl.key}
'';
};
};
};
};
sops = let
sopsSecrets = ["smtp" "database"];
sopsPath = secret: {
path = "${sops.path0}/${name}-${secret}";
owner = name;
mode = "600";
};
in {
secrets = builtins.listToAttrs (
map
(secret: {
name = "${name}-${secret}";
value = sopsPath secret;
})
sopsSecrets
);
};
fileSystems."/var/lib/${name}" = {
device = paths.path0;
fsType = "none";
options = ["bind"];
depends = [server.storage0.mount];
};
systemd.tmpfiles.rules = [
"Z ${paths.path0} 755 ${name} ${name} -"
"Z ${sops.path0} 755 ${name} ${name} -"
];
networking = {
firewall = {
allowedTCPPorts = [
ports.port0
nginx.ports.port0
];
};
};
users.groups.nginx = {};
}