Fix Nix build — compute npmDepsHash and get flake building #9

Closed
opened 2026-05-20 01:10:24 +00:00 by agent-cos · 1 comment

Goal

Get nix build working for the spatial-office flake. Currently:

  • flake.nix has npmDepsHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" (placeholder)
  • packages/frontend/package.json depends on react, @react-three/fiber, @react-three/drei, three, zustand, gsap
  • packages/backend/package.json depends on ws, zod, tsx, typescript

Steps

  1. Create or update pnpm-lock.yaml / package-lock.json files for both packages (use pnpm since pnpm-workspace.yaml exists)
  2. Run the Nix build and compute actual npmDepsHash values (or use nix run nixpkgs#prefetch-npm-deps / nix build --impure trick)
  3. Update flake.nix with real hashes
  4. Ensure nix build succeeds end-to-end

Technical Notes

  • The project uses pnpm (has pnpm-workspace.yaml)
  • buildNpmPackage in nixpkgs works with pnpm if pnpmConfigHook is used, or switch to npm for simplicity
  • The frontend build step is corepack pnpm run build — needs pnpm + proper lockfile
  • The backend build step is also corepack pnpm run build

Dependencies

  • #7 (frontend) and #8 (backend) should be complete or at least have working package.json

Deliverable

Updated flake.nix with correct npmDepsHash values + confirmation that nix build .#frontend, nix build .#backend, and nix build all succeed.

## Goal Get `nix build` working for the spatial-office flake. Currently: - `flake.nix` has `npmDepsHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="` (placeholder) - `packages/frontend/package.json` depends on react, @react-three/fiber, @react-three/drei, three, zustand, gsap - `packages/backend/package.json` depends on ws, zod, tsx, typescript ## Steps 1. Create or update `pnpm-lock.yaml` / `package-lock.json` files for both packages (use pnpm since `pnpm-workspace.yaml` exists) 2. Run the Nix build and compute actual npmDepsHash values (or use `nix run nixpkgs#prefetch-npm-deps` / `nix build --impure` trick) 3. Update `flake.nix` with real hashes 4. Ensure `nix build` succeeds end-to-end ## Technical Notes - The project uses pnpm (has `pnpm-workspace.yaml`) - `buildNpmPackage` in nixpkgs works with pnpm if `pnpmConfigHook` is used, or switch to `npm` for simplicity - The frontend build step is `corepack pnpm run build` — needs pnpm + proper lockfile - The backend build step is also `corepack pnpm run build` ## Dependencies - #7 (frontend) and #8 (backend) should be complete or at least have working package.json ## Deliverable Updated flake.nix with correct npmDepsHash values + confirmation that `nix build .#frontend`, `nix build .#backend`, and `nix build` all succeed.

✅ All three Nix builds pass now:

  • nix build .#frontend — React/Three.js frontend built with Vite, outputs assets/ + index.html
  • nix build .#backend — WebSocket server with ws+zod, outputs bin/spatial-office-backend
  • nix build (default) — combined symlink forest of both

What changed:

  1. Copied working source from src/frontend/ into packages/frontend/src/ (the real React/Three.js code: App, OfficeScene, AgentSprite, store, WebSocketClient)
  2. Added proper backend source at packages/backend/src/index.ts — real WebSocket server with agent state management
  3. Switched flake from pnpm to npm — buildNpmPackage uses npm lockfiles, so buildPhase now uses npm run build instead of corepack pnpm run build
  4. Force-added npm lockfiles to git (they were gitignored, but Nix flakes need them in the source tree)
  5. Fixed npmDepsHash for both packages:
    • Frontend: sha256-yZajnZGRNnZo+zm8b0N9+nNOoyxt2EOoxwWYINl6FZU=
    • Backend: sha256-GB3oOOAD7RJwkUR21zA9R66b5MlLXMU0IwOOgflfE14=
  6. Added packages/frontend/index.html and vite.config.js (previously only in src/frontend/)

Two commits on master: 03eaea3 (source files) and d1cc325 (flake hash updates).

✅ All three Nix builds pass now: - `nix build .#frontend` — React/Three.js frontend built with Vite, outputs `assets/` + `index.html` - `nix build .#backend` — WebSocket server with ws+zod, outputs `bin/spatial-office-backend` - `nix build` (default) — combined symlink forest of both ### What changed: 1. **Copied working source** from `src/frontend/` into `packages/frontend/src/` (the real React/Three.js code: App, OfficeScene, AgentSprite, store, WebSocketClient) 2. **Added proper backend source** at `packages/backend/src/index.ts` — real WebSocket server with agent state management 3. **Switched flake from pnpm to npm** — `buildNpmPackage` uses npm lockfiles, so buildPhase now uses `npm run build` instead of `corepack pnpm run build` 4. **Force-added npm lockfiles** to git (they were gitignored, but Nix flakes need them in the source tree) 5. **Fixed npmDepsHash** for both packages: - Frontend: `sha256-yZajnZGRNnZo+zm8b0N9+nNOoyxt2EOoxwWYINl6FZU=` - Backend: `sha256-GB3oOOAD7RJwkUR21zA9R66b5MlLXMU0IwOOgflfE14=` 6. **Added `packages/frontend/index.html`** and **vite.config.js** (previously only in `src/frontend/`) Two commits on master: `03eaea3` (source files) and `d1cc325` (flake hash updates).
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: sscoble/spatial-office#9
No description provided.