From 99e940770b61db350379d692df7cf3831ef4bd92 Mon Sep 17 00:00:00 2001 From: tdback Date: Sun, 26 Jan 2025 11:34:28 -0500 Subject: services: major overhaul on service modules --- modules/services/website/default.nix | 63 ++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 modules/services/website/default.nix (limited to 'modules/services/website/default.nix') diff --git a/modules/services/website/default.nix b/modules/services/website/default.nix new file mode 100644 index 0000000..425b69c --- /dev/null +++ b/modules/services/website/default.nix @@ -0,0 +1,63 @@ +{ + config, + lib, + ... +}: +with lib; +let + cfg = config.modules.services.website; +in +{ + options.modules.services.website = { + enable = mkEnableOption "website"; + url = mkOption { + type = types.str; + }; + federating = mkOption { + default = false; + type = types.bool; + description = "Federating a matrix server on this domain."; + }; + }; + + config = mkIf cfg.enable { + networking.firewall.allowedTCPPorts = [ + 80 + 443 + ]; + + services.caddy = { + enable = true; + virtualHosts = { + ${cfg.url}.extraConfig = + let + synapseUrl = "synapse.${cfg.url}"; + synapseBaseUrl = "https://${synapseUrl}"; + in + ( + if cfg.federating then + '' + handle /.well-known/matrix/server { + header Content-Type application/json + header Access-Control-Allow-Origin * + respond `{"m.server": "${synapseUrl}:443"}` + } + + handle /.well-known/matrix/client { + header Content-Type application/json + header Access-Control-Allow-Origin * + respond `{"m.homeserver": {"base_url": "${synapseBaseUrl}"}}` + } + '' + else + "" + ) + + '' + root * /var/www/${cfg.url}/ + encode zstd gzip + file_server + ''; + }; + }; + }; +} -- cgit v1.2.3