nixos-config/linux/singularity/caddy.nix

89 lines
2.5 KiB
Nix
Raw Normal View History

2023-10-09 10:44:07 -07:00
{
2024-08-14 11:14:20 -07:00
config,
pkgs,
...
2024-08-31 21:13:43 -07:00
}:
with config.constants; {
2023-10-09 10:44:07 -07:00
services.caddy = {
enable = true;
2024-08-31 21:13:43 -07:00
email = postMaster;
2024-08-14 11:14:20 -07:00
virtualHosts = let
2024-08-31 23:53:22 -07:00
acme = fqdns:
builtins.listToAttrs (map (fqdn: {
name = fqdn;
value = {
extraConfig = ''
file_server ${wn "acme-challenge"}/* {
root ${config.security.acme.defaults.webroot}/
}
'';
useACMEHost = fqdn;
};
})
fqdns);
portStr = builtins.mapAttrs (n: v: toString v) port;
2024-08-14 11:14:20 -07:00
homeSrv = s: "nebula:${portStr.${s}}";
2024-08-31 21:13:43 -07:00
localSrv = s: "${localhost}:${portStr.${s}}";
mtfqdn = "matrix.${domain}";
2024-08-14 11:14:20 -07:00
wn = s: "/.well-known/${s}";
2024-08-31 23:53:22 -07:00
in
{
"${domain}".extraConfig = let
wnm = wn "matrix";
in ''
header ${wnm}/* Content-Type application/json
header ${wnm}/* Access-Control-Allow-Origin *
respond ${wnm}/server `{ "m.server": "${mtfqdn}:${portStr.https}" }`
respond ${wnm}/client `{
"m.homeserver": { "base_url": "https://${mtfqdn}" },
"m.identity_server": { "base_url": "https://${mtfqdn}" }
}`
'';
"aria2.${domain}".extraConfig = ''
reverse_proxy /jsonrpc ${homeSrv "aria2"}
file_server {
root ${pkgs.ariang}/share/ariang
2024-04-12 15:03:20 -07:00
}
'';
2024-08-31 23:53:22 -07:00
"forgejo.${domain}".extraConfig = ''
reverse_proxy ${homeSrv "forgejo"}
'';
"headscale.${domain}".extraConfig = ''
reverse_proxy ${localSrv "headscale"}
'';
"jellyfin.${domain}".extraConfig = ''
reverse_proxy ${homeSrv "jellyfin"}
'';
"jellyseerr.${domain}".extraConfig = ''
reverse_proxy ${homeSrv "jellyseerr"}
'';
"matrix.${domain}".extraConfig = ''
reverse_proxy /_matrix/* ${homeSrv "conduit"}
file_server {
root ${pkgs.fluffychat-web}
}
'';
"vault.${domain}".extraConfig = ''
reverse_proxy ${localSrv "vault"} {
header_up X-Real-IP {remote_host}
}
'';
"writefreely.${domain}".extraConfig = ''
reverse_proxy ${homeSrv "writefreely"}
'';
}
// (acme [
config.mailserver.fqdn
config.services.coturn.realm
]);
2023-10-09 10:44:07 -07:00
};
security.acme = {
acceptTerms = true;
defaults = {
2024-08-31 21:13:43 -07:00
email = postMaster;
2023-10-09 10:44:07 -07:00
webroot = "/var/lib/acme/acme-challenge";
};
};
}