{ config, lib, ... }: # Public side of services/comms/matrix.nix, on neptun. User IDs are # @user:mgaction.town; the apex only serves delegation, so federation and clients # both land on matrix.mgaction.town:443 (no :8448, no SRV records). let upstream = config.homelab.matrixProxy.upstream; in { options.homelab.matrixProxy.upstream = lib.mkOption { type = lib.types.str; default = "jupiter.orbit.sol"; }; config.services.caddy.virtualHosts = { "mgaction.town".extraConfig = '' header /.well-known/matrix/* Content-Type application/json header /.well-known/matrix/client Access-Control-Allow-Origin * respond /.well-known/matrix/server `{"m.server":"matrix.mgaction.town:443"}` respond /.well-known/matrix/client `{"m.homeserver":{"base_url":"https://matrix.mgaction.town"}}` respond 404 ''; # /_synapse/admin and /_synapse/mas stay tailnet-only. "matrix.mgaction.town".extraConfig = '' request_body { max_size 100MB } @mas path_regexp ^/_matrix/client/[^/]+/(login|logout|refresh) handle @mas { reverse_proxy http://${upstream}:8080 } @synapse path /_matrix/* /_synapse/client/* handle @synapse { reverse_proxy http://${upstream}:8008 } handle { respond 404 } ''; "account.mgaction.town".extraConfig = '' reverse_proxy http://${upstream}:8080 ''; }; }