Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docker/nixpacks/install-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Installs a pinned official Node.js build into /app/.node for the Railway
# (Nixpacks) build and links it into /usr/bin. Nixpacks' own Node comes from a
# nixpkgs snapshot that lags Node security releases, so we pin the release.
# To update: change NODE_VERSION and both hashes from
# https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt
set -euo pipefail

NODE_VERSION="22.23.5"
case "$(uname -m)" in
x86_64) ARCH="x64"; SHA256="cdeb8670a0c81f51b4dc4ac61919f9b1ad917b304bf8221eb939570663d240f8" ;;
aarch64 | arm64) ARCH="arm64"; SHA256="2babb9eb5264860d540849f4b064a6fbdebcdc323657d9d382ce23d313fd5e09" ;;
*) echo "install-node: unsupported architecture $(uname -m)" >&2; exit 1 ;;
esac

TARBALL="node-v${NODE_VERSION}-linux-${ARCH}.tar.xz"
DEST="/app/.node"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT

curl -fsSL --retry 3 -o "$TMP/$TARBALL" "https://nodejs.org/dist/v${NODE_VERSION}/${TARBALL}"
echo "${SHA256} $TMP/$TARBALL" | sha256sum -c -

rm -rf "$DEST"
mkdir -p "$DEST"
tar -xJf "$TMP/$TARBALL" -C "$DEST" --strip-components=1

# On the default PATH, so both build steps and the running server use it.
ln -sf "$DEST/bin/node" "$DEST/bin/npm" "$DEST/bin/npx" /usr/bin/

node -v
21 changes: 21 additions & 0 deletions nixpacks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Railway builds with Nixpacks. Its Node comes from a nixpkgs snapshot that lags
# Node security releases, so Node (and Nix's pnpm, which pulls in its own Node)
# isn't taken from Nix: docker/nixpacks/install-node.sh installs a pinned
# official release instead, used for both the build and the server. pnpm comes
# from corepack (packageManager in package.json).
# Update the version and hashes in that script with each Node security release.
[phases.setup]
nixPkgs = ["openssl"]

[phases.node]
dependsOn = ["setup"]
cmds = ["bash docker/nixpacks/install-node.sh"]
# Only the script, so code changes don't redownload Node.
onlyIncludeFiles = ["docker/nixpacks/install-node.sh"]

[phases.install]
dependsOn = ["node"]
cmds = [
"npm install -g corepack@0.24.1 && ln -sf /app/.node/bin/corepack /usr/bin/corepack && corepack enable --install-directory /usr/bin",
"pnpm i --frozen-lockfile",
]
Loading