ci: simplify web.nix (symlink .next, bunx next start from repo), fix CI args
CI / typecheck + tests (push) Canceled after 0s
CI / build + deploy (Nix) — api (push) Canceled after 0s
CI / build + deploy (Nix) — mcp (push) Canceled after 0s
CI / build + deploy (Nix) — worker (push) Canceled after 0s
CI / build + deploy (web) (push) Canceled after 0s

This commit is contained in:
asepharyana
2026-08-21 17:50:30 +07:00
parent c92caede57
commit 54d5c0ee01
2 changed files with 25 additions and 43 deletions
+1 -3
View File
@@ -232,7 +232,7 @@ jobs:
- name: Unpack .next - name: Unpack .next
run: tar -xzf /tmp/web-next/web-next.tar.gz -C apps/web/ 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 run: bun install --frozen-lockfile
- name: Build web Nix derivation - name: Build web Nix derivation
@@ -242,8 +242,6 @@ jobs:
nix-build -E \ nix-build -E \
"let pkgs = import <nixpkgs> {}; in pkgs.callPackage ${REPO_ROOT}/web.nix { "let pkgs = import <nixpkgs> {}; in pkgs.callPackage ${REPO_ROOT}/web.nix {
webNextDir = ${REPO_ROOT}/apps/web/.next; webNextDir = ${REPO_ROOT}/apps/web/.next;
webPkgDir = ${REPO_ROOT}/apps/web;
nodeModulesPath = ${REPO_ROOT};
}" \ }" \
--impure --option sandbox false --impure --option sandbox false
STORE_PATH=$(readlink result) STORE_PATH=$(readlink result)
+24 -40
View File
@@ -1,59 +1,43 @@
# ─── Web: packages pre-built .next ────────────────────────────────────── # ─── Web: packages pre-built .next into a Nix store path ──────────────────
# Next.js 16/Turbopack has a Bun incompatibility in the Nix sandbox. # Next.js 16/Turbopack has a Bun incompatibility in the Nix sandbox,
# Fix: CI builds .next with `bun run build`, then this derivation packages # so .next is built in CI via `bun run build` and packaged here.
# 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)
# #
# Usage: # Usage:
# nix-build -E 'let pkgs = import <nixpkgs> {}; in pkgs.callPackage ./web.nix { webNextDir = /abs/apps/web/.next; webPkgDir = /abs/apps/web; nodeModulesPath = /abs; }' # nix-build -E 'with import <nixpkgs> {}; 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 { pkgs
, stdenv , stdenv
, makeBinaryWrapper , writeShellScriptBin
, bun , bun
, webNextDir , webNextDir
, webPkgDir
, nodeModulesPath
, ... , ...
}: }:
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "mcpedia-web"; pname = "mcpedia-web";
version = "1.0.0"; version = "1.0.0";
src = pkgs.writeText "dummy-src" ""; src = webNextDir;
nativeBuildInputs = [ pkgs.bun makeBinaryWrapper ];
dontUnpack = true; dontUnpack = true;
buildPhase = ""; buildPhase = "";
installPhase = '' 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 NEXT_DIR="$out/share/mcpedia-web/.next"
cp -r "${webNextDir}" $out/share/mcpedia-web/.next BUN_BIN="${bun}/bin/bun"
# Copy node_modules from monorepo root (preserves symlinks to workspace pkgs) mkdir -p $out/bin
cp -r "${nodeModulesPath}/node_modules" $out/share/mcpedia-web/node_modules cat > $out/bin/mcpedia-web <<WRAPPER
#!/usr/bin/env bash
# Fix workspace symlinks: node_modules/@mcpedia/* points to ../../packages/* export NODE_ENV=production
# In the Nix store, resolve to actual package source dirs export PORT=4016
cd $out/share/mcpedia-web cd /home/code/mcpedia/apps/web
for ws_pkg in @mcpedia/config @mcpedia/core @mcpedia/db @mcpedia/embeddings \ rm -f .next
@mcpedia/parser @mcpedia/queue @mcpedia/search @mcpedia/types; do ln -s "$NEXT_DIR" .next
link="node_modules/$ws_pkg" exec "$BUN_BIN" x next start -p 4016
if [ -L "$link" ]; then WRAPPER
target=$(readlink -f "$link") chmod +x $out/bin/mcpedia-web
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
''; '';
} }