163 lines
8.2 KiB
Nix
163 lines
8.2 KiB
Nix
{prev}: let
|
|
# n8n >= 2.32 replaced the sheetjs-CDN `xlsx@0.20.2` tarball (which lacked an
|
|
# integrity checksum and had to be patched into pnpm-lock.yaml) with the
|
|
# regular npm package `@e965/xlsx@0.20.3`, which already carries an integrity
|
|
# field. The old lockfile-integrity workaround is therefore obsolete and has
|
|
# been removed.
|
|
#
|
|
# n8n >= 2.45 switched to pnpm 12 (packageManager pnpm@12.4.2, engines.pnpm
|
|
# ">=12.4.2"), and its pnpm-lock.yaml now serialises pnpm-12 constructs
|
|
# (packageManagerDependencies, `patch_hash` keys for patchedDependencies).
|
|
# pnpm_11 dies on that lockfile with ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY
|
|
# (no entry for 'lodash@4.18.1(patch_hash=...)'). The pinned nixpkgs ships
|
|
# pnpm_12 (12.9.0 >= 12.4.2), so fetch and build with pnpm_12. The
|
|
# engines.pnpm relaxation stays as a safety net for future upstream floor
|
|
# bumps ahead of nixpkgs — pnpm enforces that gate for ITSELF regardless of
|
|
# engine-strict, so both fetchPnpmDeps and the main build would otherwise
|
|
# die with ERR_PNPM_UNSUPPORTED_ENGINE before any hash mismatch is reached.
|
|
relaxPnpmEngine = ''
|
|
sed -i -E 's/"pnpm": *"[^"]*"/"pnpm": "*"/' package.json
|
|
'';
|
|
|
|
# n8n@2.45.5 ships an internally inconsistent pnpm-lock.yaml: the
|
|
# patchedDependencies section declares lodash@4.18.1 with patch hash
|
|
# 0384abb0…, but two snapshot references (inside @malept/flatpak-bundler
|
|
# and electron-winstaller, both electron-builder dev deps) still point at
|
|
# the hash of a PREVIOUS version of patches/lodash@4.18.1.patch
|
|
# (81ead1b0…), for which no snapshot entry exists. pnpm 12.4.2 (upstream's
|
|
# packageManager) tolerates that, pnpm >= 12.9 refuses with
|
|
# ERR_PNPM_INCONSISTENT_PATCH_HASH. Rewrite the stale references to the
|
|
# declared hash — exactly what `pnpm install --no-frozen-lockfile` would
|
|
# converge to. The sed is a no-op once upstream regenerates the lockfile.
|
|
#
|
|
# n8n@2.47.3 has the same class of defect again: the override
|
|
# `undici@7: catalog:undici-v7` was bumped to ^7.30.1 and the package entry
|
|
# undici@7.29.1 dropped from the lockfile, but the snapshot of
|
|
# @ai-sdk/provider-utils@5.0.70 (added via minimumReleaseAgeExclude) still
|
|
# lists `undici: 7.29.1`. pnpm >= 12.9 refuses with
|
|
# ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY ("no entry for 'undici@7.29.1'").
|
|
# Point the stale reference at the entry that exists (7.30.1), which is
|
|
# exactly where the override resolves it anyway. No-op on clean lockfiles.
|
|
fixUpstreamLockfile = ''
|
|
sed -i 's/patch_hash=81ead1b07fc8efda87bd2724dbd876ab49f4a0aa03f96c3770060b2ea47d9e0b/patch_hash=0384abb0bf57b0811e09219dbce0b926741d818285ee77526ad4cb75a60b87a1/g' pnpm-lock.yaml
|
|
sed -i -E 's/^(\s+undici: )7\.29\.1$/\17.30.1/' pnpm-lock.yaml
|
|
'';
|
|
|
|
# After `pnpm prune --prod` (pnpm 12), walk every workspace package and
|
|
# restore each peerDependency that is no longer linked in its node_modules
|
|
# from the hoisted copy in node_modules/.pnpm/node_modules (see the
|
|
# preInstall comment below). Links are relative so they survive the move
|
|
# into $out. Peers with no hoisted copy (e.g. n8n-workflow in the node-cli
|
|
# templates) are left alone — they were never linked before either.
|
|
relinkPrunedPeers = ''
|
|
echo "Re-linking peer dependencies dropped by pnpm prune"
|
|
find packages -name node_modules -prune -o -name package.json -type f -print \
|
|
| node -e '
|
|
const fs = require("fs"), path = require("path");
|
|
const hoisted = path.resolve("node_modules/.pnpm/node_modules");
|
|
let relinked = 0;
|
|
for (const pkgJson of fs.readFileSync(0, "utf8").split("\n").filter(Boolean)) {
|
|
let pkg;
|
|
try { pkg = JSON.parse(fs.readFileSync(pkgJson, "utf8")); } catch { continue; }
|
|
const pkgDir = path.dirname(pkgJson);
|
|
for (const name of Object.keys(pkg.peerDependencies || {})) {
|
|
const link = path.join(pkgDir, "node_modules", name);
|
|
const target = path.join(hoisted, name);
|
|
if (fs.existsSync(link) || !fs.existsSync(target)) continue;
|
|
try { fs.unlinkSync(link); } catch {} // dangling leftover
|
|
fs.mkdirSync(path.dirname(link), { recursive: true });
|
|
fs.symlinkSync(path.relative(path.dirname(link), target), link);
|
|
relinked++;
|
|
}
|
|
}
|
|
console.log("Re-linked " + relinked + " pruned peer dependencies");
|
|
'
|
|
'';
|
|
in
|
|
prev.n8n.overrideAttrs (finalAttrs: previousAttrs: {
|
|
version = "2.47.7";
|
|
|
|
src = prev.fetchFromGitHub {
|
|
owner = "n8n-io";
|
|
repo = "n8n";
|
|
tag = "n8n@${finalAttrs.version}";
|
|
hash = "sha256-Q9C8hGBwUlXh00+snHUknSAPKySgUm8rwLmcZCuAHmQ=";
|
|
};
|
|
|
|
pnpmDeps = prev.fetchPnpmDeps {
|
|
inherit (finalAttrs) pname version src;
|
|
pnpm = prev.pnpm_12;
|
|
fetcherVersion = 4;
|
|
postPatch = relaxPnpmEngine + fixUpstreamLockfile;
|
|
hash = "sha256-np4qMhJJBwpEJA/Zac1WEueUmaufs2wLBaa1BUiBgcM=";
|
|
};
|
|
|
|
postPatch = (previousAttrs.postPatch or "") + relaxPnpmEngine + fixUpstreamLockfile;
|
|
|
|
# Swap the inherited pnpm (any major < 12) for pnpm_12: upstream n8n
|
|
# calls pnpm directly during the build (install/build/prune) and older
|
|
# majors cannot parse the pnpm-12 lockfile (see comment above). The
|
|
# top-level pnpmConfigHook stays as is — it discovers the fetcher version
|
|
# from pnpmDeps' .fetcher-version. Match by pname/version, never by
|
|
# outPath: forcing e.g. prev.pnpm_10.outPath instantiates that
|
|
# derivation, and on nixpkgs pins where pnpm_10 is insecure-marked (e.g.
|
|
# nixos-26.05's pnpm 10.34.0) the comparison itself throws "Refusing to
|
|
# evaluate" — even though the package is only being discarded here.
|
|
# pname/version are plain attrs and force nothing.
|
|
nativeBuildInputs = builtins.map (x:
|
|
if (x.pname or null) == "pnpm" && prev.lib.versionOlder (x.version or "12") "12"
|
|
then prev.pnpm_12
|
|
else x)
|
|
previousAttrs.nativeBuildInputs;
|
|
|
|
# Upstream preInstall runs `pnpm prune --prod`. n8n >= 2.45 sets
|
|
# `minimumReleaseAge: 2880` in pnpm-workspace.yaml, and pnpm 12 enforces
|
|
# that supply-chain policy on prune by fetching registry metadata for every
|
|
# lockfile entry. In the network-less sandbox that stalls the build
|
|
# indefinitely right after "Removing non-deterministic and unnecessary
|
|
# files". The lockfile is fixed by pnpmDeps' hash anyway, so disable the
|
|
# check for prune and force --offline so any future registry access fails
|
|
# fast instead of hanging.
|
|
#
|
|
# pnpm 12 also changed what `prune --prod` keeps: a peerDependency that a
|
|
# workspace package only satisfies via its own devDependencies (n8n's
|
|
# convention for zod, pg, sqlite3, @langchain/core, …) is now dropped
|
|
# from that package's node_modules, whereas pnpm 11 kept the link. The
|
|
# packages are still in the store (other prod deps need them) and, with
|
|
# `hoist: true`, still linked from node_modules/.pnpm/node_modules — but
|
|
# Node's resolver never looks there, so n8n dies at startup with
|
|
# "Cannot find module 'zod'" from packages/workflow. Re-link every
|
|
# missing peer from the hoisted directory right after the prune.
|
|
preInstall =
|
|
builtins.replaceStrings
|
|
["CI=true pnpm --ignore-scripts prune --prod -w"]
|
|
[
|
|
''
|
|
CI=true pnpm --ignore-scripts --offline --config.minimum-release-age=0 prune --prod -w
|
|
${relinkPrunedPeers}''
|
|
]
|
|
previousAttrs.preInstall;
|
|
|
|
preBuild =
|
|
(previousAttrs.preBuild or "")
|
|
+ ''
|
|
if [ ! -e node_modules/sass-embedded ] && [ -e node_modules/.pnpm/node_modules/sass-embedded ]; then
|
|
ln -s .pnpm/node_modules/sass-embedded node_modules/sass-embedded
|
|
fi
|
|
if [ ! -e node_modules/sqlite3 ] && [ -e node_modules/.pnpm/node_modules/sqlite3 ]; then
|
|
ln -s .pnpm/node_modules/sqlite3 node_modules/sqlite3
|
|
fi
|
|
'';
|
|
|
|
# Self-contained update script (./update.sh) — fetches latest stable
|
|
# release from n8n-io/n8n, recomputes both src and pnpmDeps hashes.
|
|
# The CI workflow in .gitea/workflows/nix-update.yml discovers and runs it.
|
|
passthru = (previousAttrs.passthru or {}) // {updateScript = ./update.sh;};
|
|
|
|
meta =
|
|
previousAttrs.meta
|
|
// {
|
|
changelog = "https://github.com/n8n-io/n8n/releases/tag/n8n@${finalAttrs.version}";
|
|
};
|
|
})
|