diff options
author | tdback <tyler@tdback.net> | 2025-01-26 11:34:28 -0500 |
---|---|---|
committer | tdback <tyler@tdback.net> | 2025-01-26 11:34:28 -0500 |
commit | 99e940770b61db350379d692df7cf3831ef4bd92 (patch) | |
tree | d927d171b483b9ae07de4ab615f250edf25e535a /modules/services/website | |
parent | bc7b54af5193f8ac7333ce3f27f414f9a69a80c0 (diff) |
services: major overhaul on service modules
Diffstat (limited to 'modules/services/website')
-rw-r--r-- | modules/services/website/default.nix | 63 |
1 files changed, 63 insertions, 0 deletions
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 + ''; + }; + }; + }; +} |