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
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:
@@ -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 <nixpkgs> {}; 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)
|
||||
|
||||
@@ -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 <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
|
||||
, 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 <<WRAPPER
|
||||
#!/usr/bin/env bash
|
||||
export NODE_ENV=production
|
||||
export PORT=4016
|
||||
cd /home/code/mcpedia/apps/web
|
||||
rm -f .next
|
||||
ln -s "$NEXT_DIR" .next
|
||||
exec "$BUN_BIN" x next start -p 4016
|
||||
WRAPPER
|
||||
chmod +x $out/bin/mcpedia-web
|
||||
'';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user