From e8813b86eb31c0a4c5f7060b0345413f25eba46c Mon Sep 17 00:00:00 2001 From: atlas Date: Sun, 30 Aug 2026 15:08:27 +0200 Subject: [PATCH] matrix: forward the homeserver URL from client hives too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HIVE_MATRIX_URL was conditioned on this host deploying the homeserver, so a hive that is a client of the swarm's matrix forwarded nothing and every agent's hive-matrix-daemon no-opped. hive-c0re already provisions those agents' accounts against a remote homeserver through HIVE_MATRIX_API_URL three lines below, whose gate is `apiUrl != null` — it registered the users and then never told them where to log in. gatewayHost is swarm-scoped and defaults to chat., so it names the swarm's one homeserver from any member hive. Its being set is the real question, and a null swarm domain is already caught by the assertion in hive-network.nix rather than by this expression. --- nix/host-modules/hive-c0re/environment.nix | 42 +++++++++++----------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/nix/host-modules/hive-c0re/environment.nix b/nix/host-modules/hive-c0re/environment.nix index 11088fc3..ffe9ba18 100644 --- a/nix/host-modules/hive-c0re/environment.nix +++ b/nix/host-modules/hive-c0re/environment.nix @@ -159,28 +159,26 @@ in # a reading no correctly-built hive should ever have to make. HIVE_RESERVED_NAMES = lib.concatStringsSep " " (import ../../reserved-names.nix); } -// - lib.optionalAttrs - ( - config.services.hyperhive.deploy.matrix.enable - && config.services.hyperhive.swarm.matrix.gatewayHost != null - ) - { - # In-cluster matrix homeserver URL for each agent's - # hive-matrix-daemon — the gateway vhost (`matrix.`). - # Forwarded to agents by meta.rs alongside HIVE_FORGE_URL; shares the - # same env-forwarding ordering caveat (value baked at - # config-generation time). - # - # A domain-less config forwards nothing rather than falling back to - # loopback. The old fallback read as harmless because hive-c0re shares - # the host netns — but the value it produced was handed to *agents*, - # which do not, so `127.0.0.1` there names the agent itself. An absent - # forward leaves `hyperhive.matrix.url` null and the daemon no-ops; - # that is the honest answer when the hive has no matrix vhost to point - # at. - HIVE_MATRIX_URL = "http://${config.services.hyperhive.swarm.matrix.gatewayHost}"; - } +// lib.optionalAttrs (config.services.hyperhive.swarm.matrix.gatewayHost != null) { + # Matrix homeserver URL for each agent's hive-matrix-daemon — the + # gateway vhost (`chat.`). Forwarded to agents by meta.rs + # alongside HIVE_FORGE_URL; shares the same env-forwarding ordering + # caveat (value baked at config-generation time). + # + # Deliberately NOT conditioned on this host running the homeserver. A + # swarm has one matrix, and every hive's agents talk to it — the hive + # that hosts it is not the only hive whose agents need its address. + # `gatewayHost` is swarm-scoped and names that one homeserver from any + # member hive, so its being set is the whole question. + # + # Null forwards nothing rather than falling back to loopback. That + # fallback reads as harmless because hive-c0re shares the host netns — + # but the value is handed to *agents*, which do not, so `127.0.0.1` + # there names the agent itself. An absent forward leaves + # `hyperhive.matrix.url` null and the daemon no-ops; that is the honest + # answer when there is no matrix vhost to point at. + HIVE_MATRIX_URL = "http://${config.services.hyperhive.swarm.matrix.gatewayHost}"; +} // lib.optionalAttrs (config.services.hyperhive.swarm.matrix.apiUrl != null) { # Client-server API base hive-c0re uses to provision matrix (register # agent users, create the hive space + chat room, invite members).