The hash was hardcoded independently in nix/packages/frontend.nix, nix/packages/swarm-ui.nix, and nix/checks.nix's inline swarm-ui-typecheck derivation, all three building from the one frontend/package-lock.json. Nothing enforced the three copies staying in sync, and on a recent PR only some of them got updated when the lockfile changed. Moved the hash into a new file, frontend/npm-deps-hash (plain text, no trailing newline, co-located with package-lock.json so it reads as the lockfile's other half), and all three derivations now builtins.readFile it instead of hardcoding their own copy. A lockfile change now only needs prefetch-npm-deps + one file overwrite; the other two derivations pick it up automatically. Verified: nix eval against all three derivations' npmDepsHash attribute (eval-only, not a build) confirms all three resolve to the same value read from the one file.
70 lines
2.9 KiB
Nix
70 lines
2.9 KiB
Nix
{
|
|
buildNpmPackage,
|
|
lib,
|
|
branding-svg,
|
|
}:
|
|
|
|
# Hermetic build of the npm-managed frontend workspaces (see
|
|
# `frontend/README.md`). Consumes `frontend/package-lock.json` as the
|
|
# source of truth for dependency versions; `npmDepsHash` pins the
|
|
# vendor-tarball hash so a stale lockfile fails the build instead of
|
|
# silently fetching different upstream tarballs.
|
|
#
|
|
# Output layout (`$out`) — two subdirectories, one per surface, that
|
|
# the Rust binaries serve via `tower_http::ServeDir`:
|
|
#
|
|
# $out/dashboard/ the hive-c0re dashboard assets (full layout in
|
|
# frontend/packages/dashboard/build.mjs):
|
|
# index.html (H0M3 hub, served at /) dashboard.html (operator SPA,
|
|
# served at /dashboard.html) flow.html logs.html settings.html
|
|
# stats.html favicon.svg
|
|
# static/{home,tabs,flow,logs,settings,stats,stream-worker}.js{,.map}
|
|
# static/{colors,theme,common,home,dashboard,flow,logs,settings,stats}.css
|
|
# $out/agent/ the per-agent default UI (layered with
|
|
# hyperhive.frontend.extraFiles at activation time)
|
|
# index.html stats.html screen.html
|
|
# static/{app,stats}.js{,.map}
|
|
# static/{colors,theme,agent}.css
|
|
#
|
|
# The dashboard favicon lives outside the npm tree (`branding/hyperhive
|
|
# .svg` at the repo root) — we copy it in during the install phase so
|
|
# the served prefix has everything in one place.
|
|
|
|
buildNpmPackage {
|
|
pname = "hyperhive-frontend";
|
|
version = "0.0.0";
|
|
src = ../../frontend;
|
|
|
|
# Read from `../../frontend/npm-deps-hash`, the single source of
|
|
# truth `./swarm-ui.nix` and `../checks.nix`'s `swarm-ui-typecheck`
|
|
# also read — all three build from the one `frontend/package-lock.json`,
|
|
# so one file keeps them from drifting independently (this used to be
|
|
# a hardcoded copy per derivation, and only some of the three got
|
|
# updated the one time the lockfile changed). Regenerate with
|
|
# `prefetch-npm-deps frontend/package-lock.json` and overwrite the
|
|
# file whenever the lockfile changes.
|
|
npmDepsHash = builtins.readFile ../../frontend/npm-deps-hash;
|
|
|
|
# `npm run build` recurses into all workspaces (`--workspaces
|
|
# --if-present`). The workspaces' build scripts each run their own
|
|
# `build.mjs` (esbuild).
|
|
npmBuildScript = "build";
|
|
|
|
# buildNpmPackage's default install phase copies the working dir into
|
|
# $out, which is overkill — we only want the dist trees. Hand-roll
|
|
# the install to keep $out tight.
|
|
dontNpmInstall = true;
|
|
installPhase = ''
|
|
runHook preInstall
|
|
mkdir -p $out/dashboard $out/agent
|
|
cp -r packages/dashboard/dist/. $out/dashboard/
|
|
cp -r packages/agent/dist/. $out/agent/
|
|
cp ${branding-svg} $out/dashboard/favicon.svg
|
|
runHook postInstall
|
|
'';
|
|
|
|
meta = {
|
|
description = "Bundled browser-facing assets for the hyperhive dashboard and per-agent UI";
|
|
homepage = "https://forge.darkest.space/hyperhive/hyperhive";
|
|
};
|
|
}
|