refactor(nix): move the matrix host options under services.hyperhive.swarm

Second slice of the swarm-global service consolidation, same shape as
the forge move: the operator-facing host options become
services.hyperhive.swarm.matrix.*, and one mkRenamedOptionModule on the
namespace carries the whole subtree (nested gui.* included), so there is
no leaf list to forget an entry from.

The rename lives in hive-matrix.nix, the module that declares the
options, so each service's migration stays independent of its siblings.

The per-agent hyperhive.matrix.{enable,url} and hyperhive.matrixAccounts
are a different namespace -- a client pointer at the service, not the
service -- and deliberately do not move.
This commit is contained in:
atlas 2026-08-05 10:57:19 +02:00 committed by mara
commit fcdff04b23
5 changed files with 33 additions and 19 deletions

View file

@ -44,7 +44,7 @@ let
boot.loader.grub.enable = false; boot.loader.grub.enable = false;
system.stateVersion = "25.11"; system.stateVersion = "25.11";
services.hyperhive.enable = lib.mkForce false; services.hyperhive.enable = lib.mkForce false;
services.hyperhive.matrix.enable = lib.mkForce false; services.hyperhive.swarm.matrix.enable = lib.mkForce false;
} }
) )
]; ];

View file

@ -102,7 +102,10 @@ in
} }
// //
lib.optionalAttrs lib.optionalAttrs
(config.services.hyperhive.matrix.enable && config.services.hyperhive.matrix.gatewayHost != null) (
config.services.hyperhive.swarm.matrix.enable
&& config.services.hyperhive.swarm.matrix.gatewayHost != null
)
{ {
# In-cluster matrix homeserver URL for each agent's # In-cluster matrix homeserver URL for each agent's
# hive-matrix-daemon — the gateway vhost (`matrix.<domain>`). # hive-matrix-daemon — the gateway vhost (`matrix.<domain>`).
@ -117,12 +120,12 @@ in
# forward leaves `hyperhive.matrix.url` null and the daemon no-ops; # 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 # that is the honest answer when the hive has no matrix vhost to point
# at. # at.
HIVE_MATRIX_URL = "http://${config.services.hyperhive.matrix.gatewayHost}"; HIVE_MATRIX_URL = "http://${config.services.hyperhive.swarm.matrix.gatewayHost}";
} }
// lib.optionalAttrs (config.services.hyperhive.matrix.apiUrl != null) { // lib.optionalAttrs (config.services.hyperhive.swarm.matrix.apiUrl != null) {
# Client-server API base hive-c0re uses to provision matrix (register # Client-server API base hive-c0re uses to provision matrix (register
# agent users, create the hive space + chat room, invite members). # agent users, create the hive space + chat room, invite members).
# Supplied by `services.hyperhive.matrix.apiUrl`, which the matrix # Supplied by `services.hyperhive.swarm.matrix.apiUrl`, which the matrix
# module fills in with its own loopback listener when it is the thing # module fills in with its own loopback listener when it is the thing
# running tuwunel — and which the operator sets by hand when the # running tuwunel — and which the operator sets by hand when the
# homeserver lives on another machine. # homeserver lives on another machine.
@ -131,9 +134,9 @@ in
# vhost, and it is absent whenever there is no vhost. Reusing it here # vhost, and it is absent whenever there is no vhost. Reusing it here
# would silently stop provisioning on a hive that runs matrix without # would silently stop provisioning on a hive that runs matrix without
# one. # one.
HIVE_MATRIX_API_URL = config.services.hyperhive.matrix.apiUrl; HIVE_MATRIX_API_URL = config.services.hyperhive.swarm.matrix.apiUrl;
} }
// lib.optionalAttrs config.services.hyperhive.matrix.gui.enable { // lib.optionalAttrs config.services.hyperhive.swarm.matrix.gui.enable {
# Availability flags read by the dashboard's `/api/state`. # Availability flags read by the dashboard's `/api/state`.
# Matrix GUI lives entirely on the gateway nginx (matrix tab # Matrix GUI lives entirely on the gateway nginx (matrix tab
# only shows when both flags are on). Gateway routing detail: # only shows when both flags are on). Gateway routing detail:
@ -162,14 +165,15 @@ in
// //
lib.optionalAttrs lib.optionalAttrs
( (
config.services.hyperhive.matrix.gui.enable && config.services.hyperhive.matrix.gatewayHost != null config.services.hyperhive.swarm.matrix.gui.enable
&& config.services.hyperhive.swarm.matrix.gatewayHost != null
) )
{ {
# Browser-facing matrix GUI (fluffychat) URL — the gateway # Browser-facing matrix GUI (fluffychat) URL — the gateway
# vhost (`matrix.<domain>`). Surfaced via the daemon's `Urls` # vhost (`matrix.<domain>`). Surfaced via the daemon's `Urls`
# request for `hivectl open matrix`. Absent when the GUI is off # request for `hivectl open matrix`. Absent when the GUI is off
# or no gatewayHost is set (no browser-reachable matrix vhost). # or no gatewayHost is set (no browser-reachable matrix vhost).
HIVE_MATRIX_PUBLIC_URL = "https://${config.services.hyperhive.matrix.gatewayHost}/"; HIVE_MATRIX_PUBLIC_URL = "https://${config.services.hyperhive.swarm.matrix.gatewayHost}/";
} }
// lib.optionalAttrs (config.services.hyperhive.swarm.snapshotStore.address != null) { // lib.optionalAttrs (config.services.hyperhive.swarm.snapshotStore.address != null) {
# `host:port` of the swarm's single snapshot store, for pushing agent # `host:port` of the swarm's single snapshot store, for pushing agent

View file

@ -15,7 +15,7 @@
let let
cfg = config.services.hyperhive.gateway; cfg = config.services.hyperhive.gateway;
hyperhiveDomain = config.services.hyperhive.domain; hyperhiveDomain = config.services.hyperhive.domain;
matrixCfg = config.services.hyperhive.matrix; matrixCfg = config.services.hyperhive.swarm.matrix;
forgeCfg = config.services.hyperhive.swarm.forge; forgeCfg = config.services.hyperhive.swarm.forge;
networkCfg = config.services.hyperhive.network; networkCfg = config.services.hyperhive.network;

View file

@ -5,7 +5,7 @@
... ...
}: }:
let let
cfg = config.services.hyperhive.matrix; cfg = config.services.hyperhive.swarm.matrix;
networkCfg = config.services.hyperhive.network; networkCfg = config.services.hyperhive.network;
hyperhiveDomain = config.services.hyperhive.domain; hyperhiveDomain = config.services.hyperhive.domain;
effectiveServerName = if cfg.serverName != null then cfg.serverName else hyperhiveDomain; effectiveServerName = if cfg.serverName != null then cfg.serverName else hyperhiveDomain;
@ -86,7 +86,17 @@ in
# settings: docs/matrix.md. Vhost map + discovery flow + tuning # settings: docs/matrix.md. Vhost map + discovery flow + tuning
# knobs: docs/gateway.md. # knobs: docs/gateway.md.
options.services.hyperhive.matrix = { # Matrix moved under `swarm` when the swarm-global services were
# consolidated. One rename for the namespace: the subtree comes with it,
# so existing hives keep evaluating and get one warning naming both paths.
imports = [
(lib.mkRenamedOptionModule
[ "services" "hyperhive" "matrix" ]
[ "services" "hyperhive" "swarm" "matrix" ]
)
];
options.services.hyperhive.swarm.matrix = {
enable = lib.mkOption { enable = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = false; default = false;
@ -129,7 +139,7 @@ in
**Breaking change**: this used to default to **Breaking change**: this used to default to
`matrix.''${services.hyperhive.domain}`. matrix IDs embed `matrix.''${services.hyperhive.domain}`. matrix IDs embed
the server_name irrevocably, so existing homeservers must the server_name irrevocably, so existing homeservers must
set `services.hyperhive.matrix.serverName = "matrix.''${services.hyperhive.domain}";` set `services.hyperhive.swarm.matrix.serverName = "matrix.''${services.hyperhive.domain}";`
explicitly to preserve their existing user / room IDs explicitly to preserve their existing user / room IDs
before rebuilding. before rebuilding.
''; '';
@ -151,8 +161,8 @@ in
type = lib.types.nullOr lib.types.str; type = lib.types.nullOr lib.types.str;
default = if cfg.enable then "http://127.0.0.1:${toString cfg.httpPort}" else null; default = if cfg.enable then "http://127.0.0.1:${toString cfg.httpPort}" else null;
defaultText = lib.literalExpression '' defaultText = lib.literalExpression ''
if services.hyperhive.matrix.enable if services.hyperhive.swarm.matrix.enable
then "http://127.0.0.1:''${toString services.hyperhive.matrix.httpPort}" then "http://127.0.0.1:''${toString services.hyperhive.swarm.matrix.httpPort}"
else null else null
''; '';
example = "https://matrix.example.com"; example = "https://matrix.example.com";
@ -213,7 +223,7 @@ in
**Breaking change**: this used to default to `true`. If you **Breaking change**: this used to default to `true`. If you
relied on the old default for external reach, add relied on the old default for external reach, add
`services.hyperhive.matrix.openFirewall = true;` to your host `services.hyperhive.swarm.matrix.openFirewall = true;` to your host
config before rebuilding. config before rebuilding.
Note: federation (the matrix-spec well-known port 8448) is Note: federation (the matrix-spec well-known port 8448) is
@ -290,7 +300,7 @@ in
enable = lib.mkOption { enable = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = cfg.enable; default = cfg.enable;
defaultText = lib.literalExpression "config.services.hyperhive.matrix.enable"; defaultText = lib.literalExpression "config.services.hyperhive.swarm.matrix.enable";
description = '' description = ''
Serve a matrix web client at `matrix.''${services.hyperhive.domain}/`. Serve a matrix web client at `matrix.''${services.hyperhive.domain}/`.
Requires `matrix.gatewayHost != null` (default `matrix.<hive>` Requires `matrix.gatewayHost != null` (default `matrix.<hive>`
@ -330,7 +340,7 @@ in
{ {
assertion = cfg.gatewayHost == null || cfg.gatewayHost != ""; assertion = cfg.gatewayHost == null || cfg.gatewayHost != "";
message = '' message = ''
services.hyperhive.matrix.gatewayHost = "" is rejected. The services.hyperhive.swarm.matrix.gatewayHost = "" is rejected. The
rendered URLs would be invalid (nginx wildcard catch-all for rendered URLs would be invalid (nginx wildcard catch-all for
an empty server_name, /etc/hosts rejects empty entries). an empty server_name, /etc/hosts rejects empty entries).
Use `null` to disable the gateway vhost entirely (tuwunel Use `null` to disable the gateway vhost entirely (tuwunel

View file

@ -36,7 +36,7 @@
example = "darkest.space"; example = "darkest.space";
description = '' description = ''
Canonical host domain for hyperhive subsystems that need a Canonical host domain for hyperhive subsystems that need a
stable name (currently: `services.hyperhive.matrix.serverName` stable name (currently: `services.hyperhive.swarm.matrix.serverName`
derives from this, defaulting to derives from this, defaulting to
`matrix.''${services.hyperhive.domain}` when `serverName` is `matrix.''${services.hyperhive.domain}` when `serverName` is
null). **Required** when `services.hyperhive.enable` eval fails null). **Required** when `services.hyperhive.enable` eval fails