server.nix/caddy/default.nix

297 lines
8.4 KiB
Nix
Raw Normal View History

2024-05-02 14:09:52 +03:00
{ config
, pkgs
, inputs
2024-05-03 00:54:08 +03:00
, settings
2024-05-02 14:09:52 +03:00
, ...
}:
let
2024-02-23 01:56:51 +02:00
elementClient = pkgs.element-web.override {
conf = {
default_server_config.default_server_name = "catnip.ee";
element_call.use_exclusively = true;
features = {
feature_video_rooms = true;
feature_element_call_video_rooms = true;
2024-02-23 01:56:51 +02:00
};
};
};
2024-05-07 16:26:34 +03:00
synapse-admin = pkgs.synapse-admin.override {
baseUrl = "https://matrix.catnip.ee";
};
2024-05-02 14:09:52 +03:00
in
{
systemd.services.caddy = {
serviceConfig = {
# Required to use ports < 1024
AmbientCapabilities = "cap_net_bind_service";
CapabilityBoundingSet = "cap_net_bind_service";
EnvironmentFile = "/etc/secrets/caddy.env";
TimeoutStartSec = "5m";
};
};
2024-02-23 01:56:51 +02:00
services.caddy = {
enable = true;
2024-03-22 13:52:30 +02:00
email = "ssl@catnip.ee";
package = (pkgs.callPackage ./custom-caddy.nix {
plugins = [ "github.com/caddy-dns/cloudflare" ];
});
2024-02-23 01:56:51 +02:00
virtualHosts = {
2024-11-14 22:11:37 +02:00
"kaya.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
respond owo
'';
2024-11-01 19:29:28 +02:00
"bsky.ee" = {
extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2024-11-12 18:10:07 +02:00
handle /xrpc/* {
reverse_proxy :${config.services.pds.settings.PDS_PORT}
}
handle /.well-known/* {
reverse_proxy :${config.services.pds.settings.PDS_PORT}
}
2024-11-12 18:10:07 +02:00
root * ${inputs.bsky-website}
file_server browse {
hide .git
}
2024-11-01 19:29:28 +02:00
'';
serverAliases = [ "*.bsky.ee" ];
};
2024-04-22 11:05:42 +03:00
2024-03-27 14:45:33 +02:00
${config.services.coturn.realm} = {
extraConfig = ''
root /.well-known/acme-challenge/* ${settings.turnAcmeDir}
file_server
'';
useACMEHost = config.services.coturn.realm;
};
2024-02-23 01:56:51 +02:00
"lastfm.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2024-10-25 21:04:10 +03:00
reverse_proxy :${toString config.services.lastfm-status.port}
2024-02-23 01:56:51 +02:00
'';
"forge.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2024-10-25 21:04:10 +03:00
reverse_proxy :${toString config.services.forgejo.settings.server.HTTP_PORT}
2024-02-23 01:56:51 +02:00
'';
"waka.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
reverse_proxy :${toString config.services.wakapi.settings.server.port}
'';
2024-10-25 20:12:49 +03:00
"http://syncthing.internal".extraConfig = ''
@local remote_ip private_ranges 100.64.0.0/10
reverse_proxy @local http://${config.services.syncthing.guiAddress}
'';
"http://epic.internal".extraConfig = ''
2024-04-25 13:41:52 +03:00
@local remote_ip private_ranges 100.64.0.0/10
reverse_proxy @local :${toString settings.ports.epicgames-freegames-node}
'';
"http://bazarr.internal".extraConfig = ''
2024-02-23 01:56:51 +02:00
@local remote_ip private_ranges 100.64.0.0/10
2024-10-25 21:04:10 +03:00
reverse_proxy @local :${toString config.services.bazarr.listenPort}
2024-02-23 01:56:51 +02:00
'';
"http://scrutiny.internal".extraConfig = ''
2024-02-23 01:56:51 +02:00
@local remote_ip private_ranges 100.64.0.0/10
2024-10-25 21:04:10 +03:00
reverse_proxy @local :${toString config.services.scrutiny.settings.web.listen.port}
2024-02-23 01:56:51 +02:00
'';
"http://prowlarr.internal".extraConfig = ''
2024-02-23 01:56:51 +02:00
@local remote_ip private_ranges 100.64.0.0/10
reverse_proxy @local :${toString settings.ports.prowlarr}
'';
"http://radarr.internal".extraConfig = ''
2024-02-23 01:56:51 +02:00
@local remote_ip private_ranges 100.64.0.0/10
reverse_proxy @local :${toString settings.ports.radarr}
'';
"http://sonarr.internal".extraConfig = ''
2024-02-23 01:56:51 +02:00
@local remote_ip private_ranges 100.64.0.0/10
reverse_proxy @local :${toString settings.ports.sonarr}
'';
"http://lidarr.internal".extraConfig = ''
2024-04-05 10:41:54 +03:00
@local remote_ip private_ranges 100.64.0.0/10
reverse_proxy @local :${toString settings.ports.lidarr}
'';
"http://qbittorrent.internal".extraConfig = ''
2024-02-23 01:56:51 +02:00
@local remote_ip private_ranges 100.64.0.0/10
reverse_proxy @local :${toString settings.ports.qbittorrent}
'';
"http://files.internal".extraConfig = ''
2024-02-23 01:56:51 +02:00
@local remote_ip private_ranges 100.64.0.0/10
root * /mnt/media
file_server @local browse {
hide .Trash-1000
}
'';
2024-03-05 21:21:27 +02:00
"files.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
basic_auth {
2024-03-05 21:21:27 +02:00
mrow {env.FILES_PASSWORD_HASH}
}
root * /mnt/media
file_server browse {
hide .Trash-1000
}
'';
2024-02-23 01:56:51 +02:00
"chat.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2024-02-23 01:56:51 +02:00
root * ${elementClient}
file_server
'';
2024-05-07 16:26:34 +03:00
"synapse-admin.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2024-05-07 16:26:34 +03:00
root * ${synapse-admin}
file_server
'';
2024-02-23 01:56:51 +02:00
"matrix.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2024-02-23 01:56:51 +02:00
reverse_proxy :${toString settings.ports.synapse}
2024-10-25 21:04:10 +03:00
redir /telegram /telegram/
handle /.well-known/matrix/client {
header Content-Type application/json
header Access-Control-Allow-Origin *
respond `{"m.homeserver":{"base_url":"https://matrix.catnip.ee/"},"org.matrix.msc3575.proxy":{"url":"https://sliding-sync.catnip.ee"}}`
}
handle /.well-known/matrix/server {
header Content-Type application/json
header Access-Control-Allow-Origin *
respond `{"m.server": "matrix.catnip.ee:443"}`
}
2024-02-23 01:56:51 +02:00
handle /telegram/* {
reverse_proxy :${toString settings.ports.mautrix-telegram}
}
'';
"ntfy.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2024-03-05 21:21:27 +02:00
reverse_proxy ${config.services.ntfy-sh.settings.listen-http}
2024-02-23 01:56:51 +02:00
2024-03-05 21:21:27 +02:00
# Redirect HTTP to HTTPS, but only for GET topic addresses, since we want
# it to work with curl without the annoying https:// prefix.
@httpget {
protocol http
method GET
path_regexp ^/([-_a-z0-9]{0,64}$|docs/|static/)
}
redir @httpget https://{host}{uri}
2024-02-23 01:56:51 +02:00
'';
"cloud.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
redir /.well-known/carddav /remote.php/dav 301
redir /.well-known/caldav /remote.php/dav 301
2024-02-23 01:56:51 +02:00
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains"
Referrer-Policy no-referrer
Referrer-Policy same-origin
Referrer-Policy strict-origin
Referrer-Policy strict-origin-when-cross-origin
Referrer-Policy no-referrer-when-downgrade
}
reverse_proxy 127.0.0.1:${toString settings.ports.nextcloud}
'';
2024-03-27 15:26:19 +02:00
"catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2024-03-27 15:26:19 +02:00
root * ${inputs.catnip-website}
file_server browse {
hide .git
}
2024-03-28 13:03:11 +02:00
handle /.well-known/matrix/client {
header Content-Type application/json
header Access-Control-Allow-Origin *
respond `{"m.homeserver":{"base_url":"https://matrix.catnip.ee/"},"org.matrix.msc3575.proxy":{"url":"https://sliding-sync.catnip.ee"}}`
}
handle /.well-known/matrix/server {
header Content-Type application/json
header Access-Control-Allow-Origin *
respond `{"m.server": "matrix.catnip.ee:443"}`
}
2024-03-27 15:26:19 +02:00
'';
"www.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2024-03-27 15:26:19 +02:00
redir https://catnip.ee{uri} permanent
'';
2024-02-23 01:56:51 +02:00
2024-06-08 16:41:43 +03:00
"confess.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2024-10-25 21:04:10 +03:00
reverse_proxy :${toString config.services.confess-web.port}
2024-06-08 16:41:43 +03:00
'';
2024-02-23 01:56:51 +02:00
":80".extraConfig = ''
respond awawaw
'';
};
};
}