From c7777f3d5883c373d5f219fb681f62a27e35938a Mon Sep 17 00:00:00 2001 From: damocles Date: Sun, 31 May 2026 17:12:59 +0200 Subject: [PATCH] =?UTF-8?q?hive-gateway:=20hoist=20publicScheme/Port=20hel?= =?UTF-8?q?pers=20to=20outer=20let=20(argus=20=F0=9F=9F=A1=20on=20#848)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nix/modules/hive-gateway.nix | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/nix/modules/hive-gateway.nix b/nix/modules/hive-gateway.nix index 96fd876e..61b4cd18 100644 --- a/nix/modules/hive-gateway.nix +++ b/nix/modules/hive-gateway.nix @@ -385,6 +385,20 @@ in sslCertificate = tlsCert; sslCertificateKey = tlsKey; }; + + # Public-facing scheme + port-suffix for URLs the gateway + # mints into responses (well-known JSON, the deprecated + # `/matrix/*` 301 redirect, future absolute-URL needs). + # When self-signed TLS is on, prefer `https://` (matrix- + # spec compliance) — 443 elides the port. Otherwise fall back + # to the plain-http listen with the bare port. See + # `docs/gateway.md` ("Self-signed TLS"). Shared at this scope + # (was inlined twice, argus 🟡 on #848). + publicScheme = if cfg.selfSignedTls then "https" else "http"; + publicPort = if cfg.selfSignedTls then cfg.httpsPort else cfg.port; + publicPortDefault = if cfg.selfSignedTls then 443 else 80; + publicPortSuffix = + if publicPort == publicPortDefault then "" else ":${toString publicPort}"; in { system.stateVersion = "26.05"; @@ -458,16 +472,7 @@ in # map. lib.optionalAttrs (matrixCfg.enable && matrixCfg.gui.enable && matrixCfg.gatewayHost != null) ( let - # Public-facing scheme + port-suffix. When self-signed TLS - # is on, prefer https:// (matrix-spec compliance); - # 443 elides the port. Otherwise fall back to the - # plain-http listen with the bare port. See - # `docs/gateway.md` ("Self-signed TLS"). - scheme = if cfg.selfSignedTls then "https" else "http"; - activePort = if cfg.selfSignedTls then cfg.httpsPort else cfg.port; - defaultPort = if cfg.selfSignedTls then 443 else 80; - portSuffix = if activePort == defaultPort then "" else ":${toString activePort}"; - target = "${scheme}://${matrixCfg.gatewayHost}${portSuffix}"; + target = "${publicScheme}://${matrixCfg.gatewayHost}${publicPortSuffix}"; in { "/matrix/" = { @@ -486,18 +491,14 @@ in # client-bootstrap sequence. lib.optionalAttrs (matrixCfg.enable && hyperhiveDomain != null) ( let - scheme = if cfg.selfSignedTls then "https" else "http"; - activePort = if cfg.selfSignedTls then cfg.httpsPort else cfg.port; - defaultPort = if cfg.selfSignedTls then 443 else 80; - portSuffix = if activePort == defaultPort then "" else ":${toString activePort}"; clientBaseUrl = if matrixCfg.gatewayHost != null then - "${scheme}://${matrixCfg.gatewayHost}${portSuffix}" + "${publicScheme}://${matrixCfg.gatewayHost}${publicPortSuffix}" else - "${scheme}://${hyperhiveDomain}:${toString matrixCfg.httpPort}"; + "${publicScheme}://${hyperhiveDomain}:${toString matrixCfg.httpPort}"; serverHostPort = if matrixCfg.gatewayHost != null then - "${matrixCfg.gatewayHost}${portSuffix}" + "${matrixCfg.gatewayHost}${publicPortSuffix}" else "${hyperhiveDomain}:${toString matrixCfg.httpPort}"; in