From 2af7732077322cabd096687b78657605e0e25029 Mon Sep 17 00:00:00 2001 From: Oleks Date: Fri, 15 May 2026 13:02:31 +0300 Subject: [PATCH] style: auto-format from pre-push hooks --- packages/metamcp.nix | 79 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/packages/metamcp.nix b/packages/metamcp.nix index 82fa8d7..eed2648 100644 --- a/packages/metamcp.nix +++ b/packages/metamcp.nix @@ -36,7 +36,7 @@ let owner = "metatool-ai"; repo = "metamcp"; rev = "v${version}"; - hash = lib.fakeHash; # nix build will print the right one + hash = "sha256-EEb3RUjsaJ5ZSHSIkAxfdV/BAjZEAvw3rtjALM4RpSc="; }; in stdenv.mkDerivation (finalAttrs: { @@ -45,7 +45,7 @@ stdenv.mkDerivation (finalAttrs: { pnpmDeps = fetchPnpmDeps { inherit pname version src; fetcherVersion = 3; - hash = lib.fakeHash; # nix build will print the right one + hash = "sha256-nHHLLu5wBzzP4i/oTnOkuIiPQvvvBAIIVtKdfpDiXQw="; }; nativeBuildInputs = [ @@ -55,6 +55,20 @@ stdenv.mkDerivation (finalAttrs: { makeWrapper ]; + # Upstream pins `packageManager: pnpm@9.0.0`; nixpkgs ships pnpm 10. The + # lockfile is v9 (forward-compatible). Rewrite the pin to the pnpm we + # actually have so pnpm 10 doesn't try to network-fetch pnpm@9 and Turbo + # (which *requires* the field) still finds it. + postPatch = '' + ${nodejs_20}/bin/node -e ' + const fs = require("fs"); + const pkg = JSON.parse(fs.readFileSync("package.json", "utf8")); + pkg.packageManager = "pnpm@${pnpm_10.version}"; + if (pkg.engines) delete pkg.engines.pnpm; + fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2) + "\n"); + ' + ''; + # pnpmConfigHook places node_modules; build the workspace with Turbo. buildPhase = '' runHook preBuild @@ -91,19 +105,24 @@ stdenv.mkDerivation (finalAttrs: { pnpm-workspace.yaml \ pnpm-lock.yaml \ turbo.json \ - docker-entrypoint.sh \ $out/lib/metamcp/ - # Sanitise the entrypoint: drop the hard-coded `cd /app/...` paths, - # set our launch root via $METAMCP_ROOT, keep the orchestration logic. - substituteInPlace $out/lib/metamcp/docker-entrypoint.sh \ - --replace-fail "/app" "$out/lib/metamcp" + # Next.js standalone post-processing: `output: "standalone"` produces + # apps/frontend/.next/standalone/apps/frontend/server.js but does NOT + # copy .next/static or public/ into the standalone tree. Do it here + # so the runtime UI has its CSS, JS chunks and static assets. + SA=$out/lib/metamcp/apps/frontend/.next/standalone/apps/frontend + cp -r $out/lib/metamcp/apps/frontend/.next/static $SA/.next/static + cp -r $out/lib/metamcp/apps/frontend/public $SA/public - # Launcher: identical sequence to docker-entrypoint.sh, with PATH - # carrying pg_isready (for the readiness wait) and node. + # Launcher: re-implementation of upstream's docker-entrypoint.sh. + # Cleaner than substituteInPlace-ing the upstream script (the original + # has overlapping `/app` substrings that break naive replacement) and + # gives us a single place to keep the orchestration logic in sync. cat > $out/bin/metamcp </dev/null || { echo "Backend died"; exit 1; } + + echo "Starting frontend on :12008..." + cd "\$ROOT/apps/frontend/.next/standalone/apps/frontend" + # Next.js standalone uses \$HOSTNAME as the bind address. The shell + # inherits HOSTNAME=, leaving the server unreachable + # on 127.0.0.1 — force 0.0.0.0 unless overridden via METAMCP_HOSTNAME. + PORT=12008 HOSTNAME="\''${METAMCP_HOSTNAME:-0.0.0.0}" node server.js & + FRONTEND_PID=\$! + sleep 3 + kill -0 \$FRONTEND_PID 2>/dev/null || { kill \$BACKEND_PID 2>/dev/null; echo "Frontend died"; exit 1; } + + trap 'kill \$BACKEND_PID \$FRONTEND_PID 2>/dev/null || true' TERM INT + wait \$BACKEND_PID \$FRONTEND_PID EOF chmod +x $out/bin/metamcp @@ -124,9 +174,8 @@ stdenv.mkDerivation (finalAttrs: { cat > $out/bin/metamcp-frontend <