From 3bcb178ae736543098fa4ba2b36f27404d158d3b Mon Sep 17 00:00:00 2001 From: h7x4 Date: Tue, 21 Jul 2026 17:54:09 +0900 Subject: [PATCH] WIP: base/nginx: host well-known content on multiple subdomains --- .../bekkalokk/services/well-known/default.nix | 77 +++++++++++++++---- 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/hosts/bekkalokk/services/well-known/default.nix b/hosts/bekkalokk/services/well-known/default.nix index e78c406..9455e29 100644 --- a/hosts/bekkalokk/services/well-known/default.nix +++ b/hosts/bekkalokk/services/well-known/default.nix @@ -1,25 +1,70 @@ { lib, ... }: { - services.nginx.virtualHosts = lib.genAttrs [ - "pvv.ntnu.no" - "www.pvv.ntnu.no" - "pvv.org" - "www.pvv.org" - ] (_: { - locations = { - "^~ /.well-known/" = { - alias = (toString ./root) + "/"; - }; + # TODO: move this to base so that all virtualHosts take effect on their respecitve hosts - # Proxy the matrix well-known files - # Host has be set before proxy_pass - # The header must be set so nginx on the other side routes it to the right place - "^~ /.well-known/matrix/" = { + # NOTE: automatically hosting well-known files by looping over all existing `virtualHosts` + # unfortunately causes infinite recursuion due to submodule usage within the nginx + # module. For now, the easiest solution was to manually specify a list of virtualHosts + # here, but it would be nice to find a better solution in the future. + services.nginx.virtualHosts = lib.mkMerge [ + (lib.genAttrs [ + "pvv.ntnu.no" + "pvv.org" + + "www.pvv.ntnu.no" + "www.pvv.org" + "www2.pvv.ntnu.no" + "www2.pvv.org" + + # NOTE: this list is probably not complete + "alps.pvv.ntnu.no" + "chat.pvv.ntnu.no" + "grafana.pvv.ntnu.no" + "status.pvv.ntnu.no" + "matrix.pvv.ntnu.no" + "mirrors.pvv.ntnu.no" + "pages.pvv.ntnu.no" + "ooye.pvv.ntnu.no" + "ooye.pvv.ntnu.no" + "dav.pvv.ntnu.no" + "git.pvv.ntnu.no" + "idp.pvv.ntnu.no" + "minecraft.pvv.ntnu.no" + "pw.pvv.ntnu.no" + "snappymail.pvv.ntnu.no" + "webmail.pvv.ntnu.no" + "wiki.pvv.ntnu.no" + ] (_: { + locations."^~ /.well-known/security.txt" = { + alias = toString ./root/security.txt; + }; + })) + + (lib.genAttrs [ + "pvv.ntnu.no" + "pvv.org" + "mail.pvv.ntnu.no" + "mail.pvv.org" + "smtp.pvv.ntnu.no" + "smtp.pvv.org" + ] (_: { + locations."^~ /.well-known/autoconfig/mail/" = { + root = toString ./root/autoconfig/mail; + }; + })) + + (lib.genAttrs [ + "pvv.ntnu.no" + "pvv.org" + "www.pvv.ntnu.no" + "www.pvv.org" + ] (_: { + locations."^~ /.well-known/matrix/" = { extraConfig = '' proxy_set_header Host matrix.pvv.ntnu.no; proxy_pass https://matrix.pvv.ntnu.no/.well-known/matrix/; ''; }; - }; - }); + })) + ]; }