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
2024-11-04 20:49:43 -06:00
inherit (flake.config.machines.devices) server;
inherit (flake.config.services.instances) castopod nginx web;
2024-10-19 18:22:29 -05:00
service = castopod;
localhost = web.localhost.address0;
host = "${service.subdomain}.${web.domains.url1}";
2024-10-06 15:25:05 -05:00
in {
services = {
castopod = {
enable = true;
localDomain = host;
configureNginx = false;
2024-10-19 18:22:29 -05:00
environmentFile = config.sops.secrets."${service.name}-smtp".path;
2024-10-06 15:25:05 -05:00
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 = {
2024-10-19 18:22:29 -05:00
"email.fromEmail" = service.email.address0;
2024-10-06 15:25:05 -05:00
"email.protocol" = "smtp";
"email.SMTPHost" = localhost;
"email.SMTPPort" = 587;
"email.SMTPUser" = "smtp.protonmail.ch";
};
};
nginx = {
enable = true;
virtualHosts = {
"${host}" = {
};
};
};
caddy = {
virtualHosts = {
"${host}" = {
extraConfig = ''
2024-10-19 18:22:29 -05:00
reverse_proxy ${localhost}:${toString service.ports.port0}
2024-10-06 15:25:05 -05:00
2024-10-19 18:22:29 -05:00
tls ${service.ssl.cert} ${service.ssl.key}
2024-10-06 15:25:05 -05:00
'';
};
};
};
};
sops = let
sopsPath = secret: {
2024-10-19 18:22:29 -05:00
path = "${service.sops.path0}/${service.name}-${secret}";
owner = service.name;
2024-10-06 15:25:05 -05:00
mode = "600";
};
in {
secrets = builtins.listToAttrs (
map
(secret: {
2024-10-19 18:22:29 -05:00
name = "${service.name}-${secret}";
2024-10-06 15:25:05 -05:00
value = sopsPath secret;
})
2024-11-04 02:09:15 -06:00
[
"smtp"
"database"
]
2024-10-06 15:25:05 -05:00
);
};
2024-10-19 18:22:29 -05:00
fileSystems."/var/lib/${service.name}" = {
device = service.paths.path0;
2024-10-06 15:25:05 -05:00
fsType = "none";
options = ["bind"];
depends = [server.storage0.mount];
};
systemd.tmpfiles.rules = [
2024-10-19 18:22:29 -05:00
"Z ${service.paths.path0} 755 ${service.name} ${service.name} -"
"Z ${service.sops.path0} 755 ${service.name} ${service.name} -"
2024-10-06 15:25:05 -05:00
];
networking = {
firewall = {
allowedTCPPorts = [
2024-10-19 18:22:29 -05:00
service.ports.port0
2024-10-06 15:25:05 -05:00
nginx.ports.port0
];
};
};
users.groups.nginx = {};
}