server.nix/caddy.nix

164 lines
4.1 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.caddy.withPlugins {
# https://github.com/NixOS/nixpkgs/pull/358586#issuecomment-2564016652
plugins = [ "github.com/caddy-dns/cloudflare@v0.1.0" ];
hash = "sha256-KnXqw7asSfAvKNSIRap9HfSvnijG07NYI3Yfknblcl4=";
};
2024-02-23 01:56:51 +02:00
virtualHosts = {
2025-01-15 02:46:55 +02:00
"kaya.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2024-11-27 19:12:36 +02:00
2025-01-15 02:46:55 +02:00
respond owo
'';
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://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
}
'';
2025-01-15 02:46:55 +02:00
"files.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2025-01-15 02:46:55 +02:00
basic_auth {
mrow {env.FILES_PASSWORD_HASH}
}
2024-03-05 21:21:27 +02:00
2025-01-15 02:46:55 +02:00
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
'';
2025-01-15 02:46:55 +02:00
"matrix.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2025-01-15 02:46:55 +02:00
reverse_proxy :${toString settings.ports.synapse}
2024-02-23 01:56:51 +02:00
2025-01-15 02:46:55 +02:00
redir /telegram /telegram/
2024-02-23 01:56:51 +02:00
2025-01-15 02:46:55 +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/"}}`
2025-01-15 02:46:55 +02:00
}
handle /.well-known/matrix/server {
header Content-Type application/json
header Access-Control-Allow-Origin *
respond `{"m.server": "matrix.catnip.ee:443"}`
}
2025-01-15 02:46:55 +02:00
handle /telegram/* {
reverse_proxy :${toString config.services.mautrix-telegram.settings.appservice.port}
2025-01-15 02:46:55 +02:00
}
'';
2024-02-23 01:56:51 +02:00
2025-01-15 02:46:55 +02:00
"catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2025-01-15 02:46:55 +02:00
root * ${inputs.catnip-website}
file_server browse {
hide .git
}
2024-03-27 15:26:19 +02:00
2025-01-15 02:46:55 +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/"}}`
2025-01-15 02:46:55 +02:00
}
handle /.well-known/matrix/server {
header Content-Type application/json
header Access-Control-Allow-Origin *
respond `{"m.server": "matrix.catnip.ee:443"}`
}
'';
"www.catnip.ee".extraConfig = ''
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
2025-01-15 02:46:55 +02:00
redir https://catnip.ee{uri} permanent
'';
2024-02-23 01:56:51 +02:00
":80".extraConfig = ''
respond awawaw
'';
};
};
}