open-design/nix/package-web.nix
Marc Chan d5659d82d4
chore(nix): streamline pnpm deps hash maintenance (#2919)
* chore(nix): streamline pnpm deps hash maintenance

Generated-By: looper 0.9.0 (runner=worker, agent=opencode)

* fix(ci): satisfy actionlint in nix hash autofix

Generated-By: looper 0.9.0 (runner=fixer, agent=opencode)

* fix(ci): allow nix hash autofix on fork PRs

Generated-By: looper 0.9.0 (runner=fixer, agent=opencode)

* fix(ci): follow up nix hash review

Generated-By: looper 0.9.0 (runner=fixer, agent=opencode)

* fix(ci): tolerate nix hash bot token failures

Generated-By: looper 0.9.0 (runner=fixer, agent=opencode)
2026-05-26 07:35:38 +00:00

87 lines
2.3 KiB
Nix

{
lib,
stdenv,
dream2nix,
nixpkgs,
system,
nodejs,
pnpm_10,
fetchPnpmDeps,
pnpmConfigHook,
src,
workspacePaths,
}:
# Builds the @open-design/web Next.js static export.
#
# Output layout: $out/ contains the contents of `apps/web/out/` (an
# index.html plus _next/ and asset subdirectories). Drop $out into any
# static file server.
#
# OD_DAEMON_URL is set to "" at build time so the bundled JS issues
# relative requests (`/api/*`, `/artifacts/*`, `/frames/*`) instead of
# baking a build-time daemon URL into the export. The serving
# environment is therefore expected to be same-origin with the daemon —
# the bundled caddy in the modules reverse-proxies those paths to
# `127.0.0.1:<cfg.port>`, and a custom nginx/caddy must do the same.
let
pname = "open-design-web";
version = (lib.importJSON ../package.json).version;
pnpmDepsHash = (import ./pnpm-deps.nix).webHash;
pnpmWorkspaceFilters = map (workspacePath: "./${workspacePath}") workspacePaths;
dependencyBuildPaths = lib.filter (workspacePath: workspacePath != "apps/web") workspacePaths;
in
stdenv.mkDerivation (finalAttrs: {
inherit pname version src;
pnpmWorkspaces = pnpmWorkspaceFilters;
nativeBuildInputs = [
nodejs
pnpm_10
pnpmConfigHook
];
pnpmDeps = fetchPnpmDeps {
inherit (finalAttrs) pname version src;
hash = pnpmDepsHash;
pnpmWorkspaces = pnpmWorkspaceFilters;
fetcherVersion = 3;
};
env = {
NODE_ENV = "production";
OD_DAEMON_URL = "";
};
buildPhase = ''
runHook preBuild
for target in ${lib.escapeShellArgs dependencyBuildPaths}; do
pnpm -C "$target" run --if-present build
done
# next.config.ts gates static-export emission on NODE_ENV=production
# and writes to apps/web/out/.
pnpm --filter @open-design/web run build
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r apps/web/out/. $out/
runHook postInstall
'';
passthru = {
inherit nodejs;
pnpmDeps = finalAttrs.pnpmDeps;
};
meta = with lib; {
description = "Open Design Next.js static SPA (apps/web)";
homepage = "https://github.com/nexu-io/open-design";
license = licenses.asl20;
platforms = platforms.linux ++ platforms.darwin;
};
})