Watch
0
0
Fork
You've already forked hyperhive
0

frontend: remove the stylix overlay and add hyperhive and Catppuccin light and dark themes

This commit is contained in:
iris 2026-11-22 16:43:49 +01:00 • committed by mara
commit 91e2d26133
7 changed files with 486 additions and 413 deletions

View file

@ -1,7 +1,6 @@
# The hive-c0re coordinator daemon (runs as the unprivileged
# `hive-core` user), socket-activated at /run/hyperhive/host.sock.
# Layout: ./options.nix (option declarations), ./theme.nix (stylix
# frontend theming → `servedFrontend`), ./vhosts.nix (its gateway vhosts),
# Layout: ./options.nix (option declarations), ./vhosts.nix (its gateway vhosts),
# ./environment.nix (the daemon unit's env attrset). The root privileged
# helper it delegates to is its own module (../hive-priv.nix).
{
@ -102,7 +101,6 @@ in
{
imports = [
./options.nix
./theme.nix
./vhosts.nix
# Hive-CA trust for this daemon's outbound TLS. The swarm services it
# reaches over https serve a leaf chaining to the store's pki root —

View file

@ -62,7 +62,7 @@ in
# nix store directly; dynamic API paths still proxied to the
# agent daemon. nginx runs on the host, which is where this
# store path already is, so it is reachable as written.
HIVE_AGENT_FRONTEND_DIR = "${controllerCfg.servedFrontend}/agent";
HIVE_AGENT_FRONTEND_DIR = "${controllerCfg.frontend}/agent";
}
// {
# Identity env vars threaded into c0re's own service env and

View file

@ -3,9 +3,7 @@
# own outputs (they carry no in-module defaults; see ../../../flake.nix)
# live under `services.hyperhive.deploy.hive-controller`, alongside the
# values the meta-flake render hands the hive's agents. The flake-source
# option the swarm builder also reads is `services.hyperhive.deploy.hyperhiveFlake`. The read-only
# `servedFrontend` option lives in ./theme.nix with the stylix wiring
# that computes it.
# option the swarm builder also reads is `services.hyperhive.deploy.hyperhiveFlake`.
{
lib,
...

View file

@ -1,58 +0,0 @@
# Stylix theme integration (zero-op auto-detect). When the operator's
# host config has stylix enabled, generate a base16 `colors.css` from
# its palette and overlay it onto the bundled frontend dist so the
# dashboard re-themes with no operator action and no npm/esbuild
# rebuild (a pure file-copy over the prebuilt dist). `colors.css` is
# the entire swap contract — `theme.css` derives every semantic var
# from the 16 base16 slots (see docs/4-implementation/web-ui/css-vars.md). The guarded
# access makes this a clean no-op when stylix isn't imported into the
# host config. Exposed as the read-only `deploy.hive-controller.servedFrontend` option.
#
# Detection + CSS-generation itself lives in `../stylix-theme.nix`
# (shared with `swarm-ui.nix`) — this file is the c0re-specific overlay
# consumer (which subtrees, which option).
{
pkgs,
lib,
config,
...
}:
let
cfg = config.services.hyperhive.deploy.hive-controller;
stylixTheme = import ../stylix-theme.nix { inherit lib config pkgs; };
inherit (stylixTheme) stylixThemeColors themedColorsCss;
# Overlay the generated colors.css onto both dist subtrees. Both the
# dashboard (served by hive-c0re via HIVE_STATIC_DIR) and the agent UIs
# (served by the gateway from HIVE_AGENT_FRONTEND_DIR — static files
# straight from the store) read their colors.css from this host-side
# tree, so swapping both re-themes both surfaces.
#
# Not covered here: an agent reached directly on its own harness web
# server (no gateway) serves from its per-agent `mergedDist`, built in
# the agent's own nixosSystem with no access to the host's stylix
# colours — theming that path needs the base16 palette forwarded
# host→agent, tracked separately.
themedFrontend =
c:
pkgs.runCommand "hyperhive-frontend-themed" { } ''
cp -r ${cfg.frontend} $out
chmod -R u+w $out
install -m644 ${themedColorsCss c} $out/dashboard/static/colors.css
install -m644 ${themedColorsCss c} $out/agent/static/colors.css
'';
in
{
options.services.hyperhive.deploy.hive-controller.servedFrontend = lib.mkOption {
type = lib.types.package;
internal = true;
readOnly = true;
default = if stylixThemeColors != null then themedFrontend stylixThemeColors else cfg.frontend;
defaultText = lib.literalExpression "<stylix-themed overlay of `frontend`>";
description = ''
Internal, read-only: `frontend` re-themed with the active stylix
palette (or `frontend` verbatim when unthemed); has `dashboard/`
and `agent/`. Exposed so the hive-gateway module can static-serve
`dashboard/` as an nginx root instead of proxying to hive-c0re.
'';
};
}

View file

@ -17,7 +17,7 @@ let
inherit (gatewayCfg.lib) errorPages;
# Dashboard SPA dist, static-served by nginx.
dashboardDist = "${hyperhiveCfg.deploy.hive-controller.servedFrontend}/dashboard";
dashboardDist = "${hyperhiveCfg.deploy.hive-controller.frontend}/dashboard";
# `/agent/` catch-all 404 + the two internal error-page targets it
# points at. Per-agent `location /agent/<name>/` blocks live in the

View file

@ -1,59 +0,0 @@
# Shared stylix theming helper: detects an active stylix palette on the
# host and renders it as a base16 `colors.css` overlay file. `colors.css`
# is the entire theme-swap contract for every frontend bundle in this
# project (`theme.css` derives every semantic var from these 16 slots —
# see docs/4-implementation/web-ui/css-vars.md), so "apply the operator's stylix palette"
# always reduces to "write this one file over the prebuilt dist's own
# `colors.css`" — no npm/esbuild rebuild needed.
#
# Two consumers today: `hive-c0re/theme.nix` (dashboard + agent
# frontend), `swarm-ui.nix` (the swarm-level UI). Factored out here
# rather than duplicated in both — same "one source, not a copy that
# agrees by inspection" reasoning `hive-gateway/vhost-lib.nix` gives for
# its own split. Both callers `import` this directly (not published via
# an option): unlike the gateway's vhost kit, this needs no per-service
# knowledge to construct, it's a pure read of the host's own top-level
# `config` — an option indirection would add a layer with nothing to
# publish through it.
#
# Guarded access makes `stylixThemeColors` a clean `null` when stylix
# isn't imported into the host config at all, so every caller's own
# `if stylixThemeColors != null then ... else <untouched package>`
# stays a zero-op when the operator hasn't opted in.
{
lib,
config,
pkgs,
}:
let
stylixThemeColors =
if (config.stylix.enable or false) && ((config.lib.stylix or { }) ? colors) then
config.lib.stylix.colors.withHashtag
else
null;
themedColorsCss =
c:
pkgs.writeText "hyperhive-colors.css" ''
:root {
--base00: ${c.base00};
--base01: ${c.base01};
--base02: ${c.base02};
--base03: ${c.base03};
--base04: ${c.base04};
--base05: ${c.base05};
--base06: ${c.base06};
--base07: ${c.base07};
--base08: ${c.base08};
--base09: ${c.base09};
--base0A: ${c.base0A};
--base0B: ${c.base0B};
--base0C: ${c.base0C};
--base0D: ${c.base0D};
--base0E: ${c.base0E};
--base0F: ${c.base0F};
}
'';
in
{
inherit stylixThemeColors themedColorsCss;
}

View file

@ -17,26 +17,6 @@ let
gatewayCfg = config.services.hyperhive.gateway;
autheliaCfg = config.services.hyperhive.swarm.authelia;
# Same stylix auto-theming `hive-c0re/theme.nix` gives the dashboard —
# this UI was left out of that overlay entirely (an operator with a
# stylix-themed host saw the dashboard in their own colours but this
# UI still on the default Catppuccin palette), because nothing here
# ever served a themed `colors.css` in place of `deployCfg.swarm-controller.ui.package`'s own.
# Detection + CSS-generation is shared (`./stylix-theme.nix`).
#
# No package-copy derivation: this vhost has exactly one location
# serving `deployCfg.swarm-controller.ui.package` (unlike hive-c0re's `servedFrontend`, which
# backs both the dashboard root AND every per-agent gateway route, so
# a single swapped tree covers both) — an `= /static/colors.css`
# exact-match location overriding just that one file, same idiom
# every other single-path override on this vhost already uses
# (`/api/whoami`, `/api/docs`), is simpler than copying the whole
# static tree to change one file inside it. mara, on review: "i
# thought we just swap a css file via nginx config?" — yes, and this
# is that.
stylixTheme = import ./stylix-theme.nix { inherit lib config pkgs; };
inherit (stylixTheme) stylixThemeColors themedColorsCss;
# Repeated verbatim by every location that should be operator-gated
# (`/`, `/api/docs/`; `/api/` takes `authRequest` with its own 401
# handler) rather than set once on the server:
@ -78,7 +58,7 @@ let
# The cache rule has no `always`, so an error answer (a 404 for a hash that
# is gone) is never marked cacheable.
# Everything else the page loads by a fixed name (the entry document,
# `sw.js`, the manifest, `colors.css`, which the theme swaps) must be
# `sw.js`, the manifest, `colors.css`, which holds the palettes) must be
# revalidated, or a deploy can leave a browser on an old document that points
# at scripts that no longer exist.
staticHeaders = cache: ''
@ -282,26 +262,16 @@ in
try_files $uri =404;
'';
};
# The one unhashed file under `/static/`: the theme swaps it (see the
# stylix note above), so it is revalidated, not immutable.
"= /static/colors.css" =
if stylixThemeColors != null then
{
alias = "${themedColorsCss stylixThemeColors}";
extraConfig = ''
${swarmAuthRequest}
${staticHeaders revalidate}
'';
}
else
{
root = "${deployCfg.swarm-controller.ui.package}";
extraConfig = ''
${swarmAuthRequest}
${staticHeaders revalidate}
try_files $uri =404;
'';
};
# The one unhashed file under `/static/`, so it is revalidated, not
# immutable.
"= /static/colors.css" = {
root = "${deployCfg.swarm-controller.ui.package}";
extraConfig = ''
${swarmAuthRequest}
${staticHeaders revalidate}
try_files $uri =404;
'';
};
}
// lib.optionalAttrs servesMatrixDiscovery {
# Same JSON, headers and `:443` as the hive-domain copy in