swarm-controller: serve swarm-wide service quick links (hyperhive#3289)
New `services.hyperhive.swarm.controller.links` option (listOf {label,
icon, url}, same shape as the per-agent hyperhive.dashboardLinks) plus
a new GET /api/links route serving it, same pattern as the existing
hives/GET /api/hives.
Rather than one central hardcoded list, each service's own module
contributes its own entry when actually enabled on the controller's
host: swarm-authelia.nix, hive-matrix.nix (gated on gui.enable too,
since / on that vhost only serves fluffychat then) and
hive-forge/default.nix (gated on behindGateway) each push one entry,
the same list-merge idiom services.hyperhive.gateway.localNames
already uses. swarm-ui.nix contributes a static entry for its own
same-origin swagger docs. Adding a future service's link is a nix-only
change to that service's own module.
Verified: cargo build/clippy/test -p swarm-controller clean, a
throwaway nixosSystem eval confirms all 4 entries merge correctly into
SWARM_CONTROLLER_LINKS, nix build .#swarm-controller succeeds.
This commit is contained in:
parent
176d95c0f0
commit
ba3a9ed94f
6 changed files with 206 additions and 1 deletions
|
|
@ -409,6 +409,16 @@ in
|
|||
# vhost nor answer DNS for it.
|
||||
services.hyperhive.gateway.localNames = lib.optional cfg.behindGateway cfg.domain;
|
||||
|
||||
# This swarm-ui quick-links entry, same `behindGateway` guard as the
|
||||
# vhost/DNS name above — with it off, this host doesn't actually
|
||||
# serve `cfg.domain`, so linking to it would be dead. See
|
||||
# `services.hyperhive.swarm.controller.links`'s description.
|
||||
services.hyperhive.swarm.controller.links = lib.optional cfg.behindGateway {
|
||||
label = "Forge";
|
||||
icon = "⚒";
|
||||
url = "https://${cfg.domain}/";
|
||||
};
|
||||
|
||||
# `server_name = forge.domain`, proxies all `/` → forgejo. Tuned for
|
||||
# git: `client_max_body_size 1G`, `proxy_read_timeout 1h` (multi-GB
|
||||
# clones). SSH stays direct on `forge.sshPort`. See
|
||||
|
|
|
|||
|
|
@ -508,6 +508,20 @@ in
|
|||
# every clause below carries that guard.
|
||||
services.hyperhive.gateway.localNames = lib.optional (cfg.gatewayHost != null) cfg.gatewayHost;
|
||||
|
||||
# This swarm-ui quick-links entry. Gated on `gui.enable` too, not just
|
||||
# `gatewayHost != null`: `/` on that vhost only serves fluffychat
|
||||
# (below) when the GUI is on — otherwise the link would 404, the same
|
||||
# reason the old dashboard's H0M3 page hides its Matrix tile on
|
||||
# `state.matrix_gui_enabled` rather than `gatewayHost` alone. See
|
||||
# `services.hyperhive.swarm.controller.links`'s description.
|
||||
services.hyperhive.swarm.controller.links =
|
||||
lib.optional (cfg.gatewayHost != null && cfg.gui.enable)
|
||||
{
|
||||
label = "Matrix";
|
||||
icon = "💬";
|
||||
url = "https://${cfg.gatewayHost}/";
|
||||
};
|
||||
|
||||
# Accept-header SPA map, used only by the `/` location below (see
|
||||
# docs/gateway.md "SPA fallback"): text/html → index.html, else a
|
||||
# sentinel so `try_files` falls through to 404. `appendHttpConfig`
|
||||
|
|
|
|||
|
|
@ -485,6 +485,18 @@ in
|
|||
# bridge at that wrong answer.
|
||||
services.hyperhive.gateway.localNames = [ cfg.domain ];
|
||||
|
||||
# This swarm-ui quick-links entry, same guard as the vhost/DNS name
|
||||
# above (only the host actually running the container claims it —
|
||||
# see `services.hyperhive.swarm.controller.links`'s description for
|
||||
# the contribute-your-own-entry idiom).
|
||||
services.hyperhive.swarm.controller.links = [
|
||||
{
|
||||
label = "Authelia";
|
||||
icon = "🔑";
|
||||
url = "https://${cfg.domain}/";
|
||||
}
|
||||
];
|
||||
|
||||
# `server_name = authelia.domain`, all of `/` → authelia.
|
||||
#
|
||||
# ⚠️ The server name must be exactly `cfg.domain`, not a near-miss:
|
||||
|
|
|
|||
|
|
@ -112,6 +112,53 @@ in
|
|||
new directory, not just the daemon.
|
||||
'';
|
||||
};
|
||||
|
||||
links = lib.mkOption {
|
||||
type = lib.types.listOf (
|
||||
lib.types.submodule {
|
||||
options = {
|
||||
label = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "Display label for the link.";
|
||||
};
|
||||
icon = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
description = "Optional icon emoji or short glyph.";
|
||||
};
|
||||
url = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "Full URL.";
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
default = [ ];
|
||||
example = lib.literalExpression ''
|
||||
[ { label = "Wiki"; icon = "📖"; url = "https://wiki.example.com/"; } ]
|
||||
'';
|
||||
description = ''
|
||||
Quick links to swarm-wide services, surfaced by the swarm UI's
|
||||
links menu (`GET /api/links`). Same shape and same
|
||||
zero-code-change-to-extend idea as `hyperhive.dashboardLinks`
|
||||
(`nix/agent-modules/dashboard-links.nix`), one level up: rather
|
||||
than one central hardcoded list, each service's own module
|
||||
contributes its own entry when it is actually enabled on this
|
||||
host — `swarm-authelia.nix`, `hive-matrix.nix` and
|
||||
`hive-forge/default.nix` all do — the same list-merge idiom
|
||||
`services.hyperhive.gateway.localNames` already uses. A future
|
||||
service module can push its own entry the same way, and an
|
||||
operator can add arbitrary extra entries here directly; neither
|
||||
needs a swarm-controller or swarm-ui change.
|
||||
|
||||
Only meaningful on the host that actually runs the controller —
|
||||
entries contributed on any other host are computed but never
|
||||
read. In a swarm that splits `swarm-authelia`/`hive-matrix`/
|
||||
`hive-forge` across hosts other than the controller's, this list
|
||||
only reflects what is enabled locally; see each contributing
|
||||
module's own activation condition.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf (config.services.hyperhive.enable && cfg.enable) {
|
||||
|
|
@ -184,6 +231,10 @@ in
|
|||
inherit (h) domain;
|
||||
}) config.services.hyperhive.swarm.hives
|
||||
);
|
||||
# The merged links list — see `links`' description above for who
|
||||
# contributes to it. Consumed by `GET /api/links`
|
||||
# (swarm-controller/src/main.rs::load_links).
|
||||
environment.SWARM_CONTROLLER_LINKS = builtins.toJSON cfg.links;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,6 +124,19 @@ in
|
|||
# makes the name resolve at all.
|
||||
services.hyperhive.gateway.localNames = [ cfg.domain ];
|
||||
|
||||
# This UI's own swagger docs, always same-origin (`/api/docs/` below)
|
||||
# so — unlike authelia/matrix/forge's entries — this one needs no
|
||||
# host name and is never conditional on anything but this module
|
||||
# being enabled at all. See
|
||||
# `services.hyperhive.swarm.controller.links`'s description.
|
||||
services.hyperhive.swarm.controller.links = [
|
||||
{
|
||||
label = "API docs";
|
||||
icon = "🧬";
|
||||
url = "/api/docs/";
|
||||
}
|
||||
];
|
||||
|
||||
# The swarm's front page, and the FIRST `auth_request` anywhere in
|
||||
# this gateway (everything else is `auth_basic` + htpasswd).
|
||||
#
|
||||
|
|
|
|||
Loading…
Reference in a new issue