matrix: drop c0re /matrix mount, use targetFlags --base-href, surface availability via env (mara on #634)
This commit is contained in:
parent
433c972db1
commit
effe00889f
3 changed files with 44 additions and 51 deletions
|
|
@ -51,17 +51,6 @@ pub async fn serve(port: u16, coord: Arc<Coordinator>) -> Result<()> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
tracing::info!(static_dir = %static_dir.display(), "dashboard static dir resolved");
|
tracing::info!(static_dir = %static_dir.display(), "dashboard static dir resolved");
|
||||||
// Optional matrix-GUI static dist (#607). When `HIVE_MATRIX_GUI_DIR`
|
|
||||||
// is set and the dir exists, mount it at `/matrix/` as a sibling
|
|
||||||
// ServeDir before the SPA fallback. Pre-#15 (nginx front) this
|
|
||||||
// is the simplest way to put fluffychat-web on the same origin as
|
|
||||||
// the dashboard so the operator has matrix chat one tab away.
|
|
||||||
let matrix_gui_dir: Option<PathBuf> = std::env::var_os("HIVE_MATRIX_GUI_DIR")
|
|
||||||
.map(PathBuf::from)
|
|
||||||
.filter(|p| p.is_dir());
|
|
||||||
if let Some(dir) = &matrix_gui_dir {
|
|
||||||
tracing::info!(matrix_gui_dir = %dir.display(), "matrix GUI mount enabled at /matrix");
|
|
||||||
}
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/api/state", get(api_state))
|
.route("/api/state", get(api_state))
|
||||||
.route("/approve/{id}", post(post_approve))
|
.route("/approve/{id}", post(post_approve))
|
||||||
|
|
@ -103,14 +92,6 @@ pub async fn serve(port: u16, coord: Arc<Coordinator>) -> Result<()> {
|
||||||
// /static/dashboard.css → dist/static/dashboard.css, etc.).
|
// /static/dashboard.css → dist/static/dashboard.css, etc.).
|
||||||
.fallback_service(ServeDir::new(&static_dir))
|
.fallback_service(ServeDir::new(&static_dir))
|
||||||
.with_state(AppState { coord });
|
.with_state(AppState { coord });
|
||||||
// Sibling static mount for the optional matrix GUI dist. Layered
|
|
||||||
// before the SPA fallback so `/matrix/...` resolves there instead
|
|
||||||
// of falling through to the dashboard.
|
|
||||||
let app = if let Some(dir) = matrix_gui_dir {
|
|
||||||
app.nest_service("/matrix", ServeDir::new(dir))
|
|
||||||
} else {
|
|
||||||
app
|
|
||||||
};
|
|
||||||
let addr = SocketAddr::from(([0, 0, 0, 0], port));
|
let addr = SocketAddr::from(([0, 0, 0, 0], port));
|
||||||
let listener = bind_with_retry(addr).await?;
|
let listener = bind_with_retry(addr).await?;
|
||||||
tracing::info!(%port, "dashboard listening");
|
tracing::info!(%port, "dashboard listening");
|
||||||
|
|
@ -242,10 +223,13 @@ struct StateSnapshot {
|
||||||
/// links each container's config + each approval's commit into the
|
/// links each container's config + each approval's commit into the
|
||||||
/// forge's `agent-configs` repos.
|
/// forge's `agent-configs` repos.
|
||||||
forge_present: bool,
|
forge_present: bool,
|
||||||
/// Whether the matrix GUI static dist is mounted at `/matrix/`
|
/// Whether the matrix GUI is reachable at `/matrix/`. Sourced from
|
||||||
/// (`HIVE_MATRIX_GUI_DIR` set + dir exists). Drives the dashboard's
|
/// `HIVE_MATRIX_GUI_ENABLED` env var (set by the c0re NixOS module
|
||||||
/// `M4TR1X →` tab-strip entry so it doesn't flash a dead link when
|
/// when `services.hyperhive.matrix.gui.enable` is on). The gateway
|
||||||
/// the operator hasn't opted in (#607).
|
/// (hive-gateway.nix) does the actual `/matrix/` static serving;
|
||||||
|
/// this flag is just an availability signal for iris's dashboard
|
||||||
|
/// chrome so the `M4TR1X →` tab doesn't flash when the GUI is off
|
||||||
|
/// (#607, #634).
|
||||||
matrix_gui_enabled: bool,
|
matrix_gui_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -439,9 +423,13 @@ async fn api_state(headers: HeaderMap, State(state): State<AppState>) -> axum::J
|
||||||
port_conflicts,
|
port_conflicts,
|
||||||
rebuild_queue: state.coord.rebuild_queue.snapshot(),
|
rebuild_queue: state.coord.rebuild_queue.snapshot(),
|
||||||
forge_present: crate::forge::is_present().await,
|
forge_present: crate::forge::is_present().await,
|
||||||
matrix_gui_enabled: std::env::var_os("HIVE_MATRIX_GUI_DIR")
|
matrix_gui_enabled: std::env::var_os("HIVE_MATRIX_GUI_ENABLED").is_some_and(|v| {
|
||||||
.map(PathBuf::from)
|
// Accept any truthy string ("1", "true", "yes") since the
|
||||||
.is_some_and(|p| p.is_dir()),
|
// env var is set by NixOS module wiring with the literal
|
||||||
|
// "1"; defensive parse so manual overrides also work.
|
||||||
|
let s = v.to_string_lossy().to_ascii_lowercase();
|
||||||
|
matches!(s.as_str(), "1" | "true" | "yes")
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -241,6 +241,15 @@ in
|
||||||
# Agents poll this URL for Forgejo notifications. Derived from
|
# Agents poll this URL for Forgejo notifications. Derived from
|
||||||
# services.hyperhive.forge.{domain,httpPort} so it tracks forge config changes.
|
# services.hyperhive.forge.{domain,httpPort} so it tracks forge config changes.
|
||||||
HIVE_FORGE_URL = "http://${config.services.hyperhive.forge.domain}:${toString config.services.hyperhive.forge.httpPort}";
|
HIVE_FORGE_URL = "http://${config.services.hyperhive.forge.domain}:${toString config.services.hyperhive.forge.httpPort}";
|
||||||
|
}
|
||||||
|
// lib.optionalAttrs config.services.hyperhive.matrix.gui.enable {
|
||||||
|
# Availability flag for `/api/state.matrix_gui_enabled`. The
|
||||||
|
# gateway (hive-gateway.nix) does the actual static serving of
|
||||||
|
# fluffychat-web at `/matrix/`; c0re doesn't host the dist
|
||||||
|
# itself (#634, mara on PR #620). This env var just tells the
|
||||||
|
# dashboard chrome whether the GUI is reachable so iris's
|
||||||
|
# `M4TR1X →` tab doesn't show when the GUI is off.
|
||||||
|
HIVE_MATRIX_GUI_ENABLED = "1";
|
||||||
};
|
};
|
||||||
# Matrix GUI static serving lives entirely on the hive-gateway
|
# Matrix GUI static serving lives entirely on the hive-gateway
|
||||||
# nginx since #609 — when gateway is off the operator opts out
|
# nginx since #609 — when gateway is off the operator opts out
|
||||||
|
|
|
||||||
|
|
@ -183,34 +183,30 @@ in
|
||||||
type = lib.types.package;
|
type = lib.types.package;
|
||||||
default = pkgs.fluffychat-web.overrideAttrs (old: {
|
default = pkgs.fluffychat-web.overrideAttrs (old: {
|
||||||
# fluffychat-web ships with `<base href="/">` baked into its
|
# fluffychat-web ships with `<base href="/">` baked into its
|
||||||
# index.html — that's the placeholder flutter would replace
|
# index.html — flutter's `--base-href` build flag replaces
|
||||||
# via `--base-href` at build time. Since hyperhive serves the
|
# that placeholder. Default upstream build is `--base-href "/"`
|
||||||
# dist at `/matrix/` (not the document root), the literal
|
# which is wrong for hyperhive's `/matrix/` sub-path mount:
|
||||||
# `<base href="/">` would resolve every relative asset path
|
# the browser resolves relative asset paths (`Imaging.js`,
|
||||||
# (`Imaging.js`, `flutter.js`, `splash/*`, etc.) against the
|
# `flutter.js`, `splash/*`) against the document ROOT,
|
||||||
# ROOT of the origin, leading to 404s on every load (#634).
|
# producing 404s for every asset (#634). Inject the right
|
||||||
# Patch the placeholder to `<base href="/matrix/">` at install
|
# base-href into the build via nixpkgs's `buildFlutterApplication`
|
||||||
# time so the SPA boots correctly under the sub-path mount.
|
# targetFlags. When subdomain routing lands (#609 —
|
||||||
# If/when we move to subdomain routing (#609 −
|
# `matrix.${hyperhiveDomain}`), drop this override; upstream's
|
||||||
# `matrix.${hyperhiveDomain}`), drop this override and revert
|
# `/` base-href is correct at the root of a dedicated subdomain.
|
||||||
# to upstream `pkgs.fluffychat-web` — it'll be at the root
|
targetFlags = (old.targetFlags or [ ]) ++ [
|
||||||
# again.
|
"--base-href"
|
||||||
postInstall = (old.postInstall or "") + ''
|
"/matrix/"
|
||||||
${pkgs.gnused}/bin/sed -i \
|
];
|
||||||
's|<base href="/">|<base href="/matrix/">|' \
|
|
||||||
$out/index.html
|
|
||||||
'';
|
|
||||||
});
|
});
|
||||||
defaultText = lib.literalExpression "pkgs.fluffychat-web (patched for /matrix/ base href)";
|
defaultText = lib.literalExpression "pkgs.fluffychat-web with --base-href /matrix/";
|
||||||
description = ''
|
description = ''
|
||||||
Static web client dist to serve at `/matrix/`. Defaults to
|
Static web client dist to serve at `/matrix/`. Defaults to
|
||||||
`pkgs.fluffychat-web` (with the `<base href>` patched to
|
`pkgs.fluffychat-web` rebuilt with `--base-href "/matrix/"`
|
||||||
`/matrix/` so relative asset paths resolve under the
|
so relative asset paths resolve under the sub-path mount
|
||||||
sub-path mount, #634). Override to swap for `hydrogen-web`
|
(#634). Override to swap for `hydrogen-web` (lightest),
|
||||||
(lightest), `cinny` (no threads), `element-web` (heaviest,
|
`cinny` (no threads), `element-web` (heaviest, full
|
||||||
full features), or an out-of-tree client dist — any
|
features), or an out-of-tree client dist — any replacement
|
||||||
replacement also needs its `<base href>` aligned with the
|
also needs its `<base href>` aligned with the mount path.
|
||||||
mount path.
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue