style: auto-format from pre-push hooks
This commit is contained in:
+64
-15
@@ -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 <<EOF
|
||||
#!${stdenv.shell}
|
||||
export METAMCP_ROOT=$out/lib/metamcp
|
||||
set -e
|
||||
|
||||
export PATH=${
|
||||
lib.makeBinPath [
|
||||
nodejs_20
|
||||
@@ -111,8 +130,39 @@ stdenv.mkDerivation (finalAttrs: {
|
||||
postgresql # for pg_isready
|
||||
]
|
||||
}:\$PATH
|
||||
cd \$METAMCP_ROOT
|
||||
exec ${stdenv.shell} \$METAMCP_ROOT/docker-entrypoint.sh "\$@"
|
||||
|
||||
ROOT=$out/lib/metamcp
|
||||
: "\''${POSTGRES_HOST:=127.0.0.1}"
|
||||
: "\''${POSTGRES_PORT:=5432}"
|
||||
: "\''${POSTGRES_USER:=postgres}"
|
||||
|
||||
echo "Waiting for PostgreSQL at \$POSTGRES_HOST:\$POSTGRES_PORT..."
|
||||
until pg_isready -h "\$POSTGRES_HOST" -p "\$POSTGRES_PORT" -U "\$POSTGRES_USER"; do
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "Running drizzle migrations..."
|
||||
cd "\$ROOT/apps/backend"
|
||||
pnpm exec drizzle-kit migrate
|
||||
|
||||
echo "Starting backend on :12009..."
|
||||
PORT=12009 node "\$ROOT/apps/backend/dist/index.js" &
|
||||
BACKEND_PID=\$!
|
||||
sleep 3
|
||||
kill -0 \$BACKEND_PID 2>/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=<system-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 <<EOF
|
||||
#!${stdenv.shell}
|
||||
export PATH=${lib.makeBinPath [ nodejs_20 pnpm_10 ]}:\$PATH
|
||||
cd $out/lib/metamcp/apps/frontend
|
||||
exec pnpm start "\$@"
|
||||
cd $out/lib/metamcp/apps/frontend/.next/standalone/apps/frontend
|
||||
exec env HOSTNAME="\''${METAMCP_HOSTNAME:-0.0.0.0}" ${nodejs_20}/bin/node server.js "\$@"
|
||||
EOF
|
||||
chmod +x $out/bin/metamcp-frontend
|
||||
|
||||
|
||||
Reference in New Issue
Block a user