matrix: forward the homeserver URL from client hives too

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.<swarm-domain>, 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.
This commit is contained in:
atlas 2026-08-30 15:08:27 +02:00 committed by mara
commit e8813b86eb

View file

@ -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.<domain>`).
# 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.<swarm-domain>`). 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).