From 54d5c0ee010508226104de3f65dfd3259c7b0077 Mon Sep 17 00:00:00 2001 From: asepharyana Date: Fri, 21 Aug 2026 17:50:30 +0700 Subject: [PATCH] ci: simplify web.nix (symlink .next, bunx next start from repo), fix CI args --- .github/workflows/ci.yml | 4 +-- web.nix | 64 +++++++++++++++------------------------- 2 files changed, 25 insertions(+), 43 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de5e3fb..47fd056 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -232,7 +232,7 @@ jobs: - name: Unpack .next run: tar -xzf /tmp/web-next/web-next.tar.gz -C apps/web/ - - name: Install deps (for node_modules in web.nix) + - name: Install deps (for bunx in web.nix) run: bun install --frozen-lockfile - name: Build web Nix derivation @@ -242,8 +242,6 @@ jobs: nix-build -E \ "let pkgs = import {}; in pkgs.callPackage ${REPO_ROOT}/web.nix { webNextDir = ${REPO_ROOT}/apps/web/.next; - webPkgDir = ${REPO_ROOT}/apps/web; - nodeModulesPath = ${REPO_ROOT}; }" \ --impure --option sandbox false STORE_PATH=$(readlink result) diff --git a/web.nix b/web.nix index 1f0a640..94b8ae6 100644 --- a/web.nix +++ b/web.nix @@ -1,59 +1,43 @@ -# ─── Web: packages pre-built .next ────────────────────────────────────── -# Next.js 16/Turbopack has a Bun incompatibility in the Nix sandbox. -# Fix: CI builds .next with `bun run build`, then this derivation packages -# the .next + node_modules (from a full monorepo install) into a Nix store path. -# -# `webNextDir` = Nix path to pre-built .next directory -# `webPkgDir` = Nix path to apps/web -# `nodeModulesPath` = Nix path to monorepo node_modules (root) +# ─── Web: packages pre-built .next into a Nix store path ────────────────── +# Next.js 16/Turbopack has a Bun incompatibility in the Nix sandbox, +# so .next is built in CI via `bun run build` and packaged here. # # Usage: -# nix-build -E 'let pkgs = import {}; in pkgs.callPackage ./web.nix { webNextDir = /abs/apps/web/.next; webPkgDir = /abs/apps/web; nodeModulesPath = /abs; }' - +# nix-build -E 'with import {}; callPackage ./web.nix { webNextDir = /abs/apps/web/.next; }' +# +# The wrapper symlinks .next from the Nix store (read-only, instant), +# then runs `bunx next start` from the repo checkout. { pkgs , stdenv -, makeBinaryWrapper +, writeShellScriptBin , bun , webNextDir -, webPkgDir -, nodeModulesPath , ... }: stdenv.mkDerivation { pname = "mcpedia-web"; version = "1.0.0"; - src = pkgs.writeText "dummy-src" ""; - nativeBuildInputs = [ pkgs.bun makeBinaryWrapper ]; + src = webNextDir; dontUnpack = true; buildPhase = ""; installPhase = '' - mkdir -p $out/share/mcpedia-web + mkdir -p $out/share/mcpedia-web/.next + cp -r "${webNextDir}/." $out/share/mcpedia-web/.next/ - # Copy pre-built .next - cp -r "${webNextDir}" $out/share/mcpedia-web/.next + NEXT_DIR="$out/share/mcpedia-web/.next" + BUN_BIN="${bun}/bin/bun" - # Copy node_modules from monorepo root (preserves symlinks to workspace pkgs) - cp -r "${nodeModulesPath}/node_modules" $out/share/mcpedia-web/node_modules - - # Fix workspace symlinks: node_modules/@mcpedia/* points to ../../packages/* - # In the Nix store, resolve to actual package source dirs - cd $out/share/mcpedia-web - for ws_pkg in @mcpedia/config @mcpedia/core @mcpedia/db @mcpedia/embeddings \ - @mcpedia/parser @mcpedia/queue @mcpedia/search @mcpedia/types; do - link="node_modules/$ws_pkg" - if [ -L "$link" ]; then - target=$(readlink -f "$link") - rm "$link" - mkdir -p "$(dirname "$link")" - cp -rL "$target" "$link" - fi - done - - cp "${webPkgDir}/package.json" $out/share/mcpedia-web/ - - makeBinaryWrapper ${pkgs.bun}/bin/bun $out/bin/mcpedia-web \ - --add-flags "run node_modules/.bin/next start" \ - --chdir $out/share/mcpedia-web + mkdir -p $out/bin + cat > $out/bin/mcpedia-web <