Files
nixpkgs/tests/n8n-overlay-test.nix
T
2026-11-10 21:15:28 +01:00

82 lines
4.0 KiB
Nix

{
pkgs,
inputs,
self,
}: let
localPackages = import ../pkgs {inherit pkgs inputs;};
mkPkgs = overlays:
import inputs.nixpkgs {
system = pkgs.stdenv.hostPlatform.system;
config.allowUnfree = true;
inherit overlays;
};
upstreamPkgs = mkPkgs [];
modifiedPkgs = mkPkgs [self.overlays.modifications];
defaultPkgs = mkPkgs [self.overlays.default];
expectedVersion = "2.47.3";
expectedSrcHash = "sha256-lw8B5pRY2O+LXWM6gPVHglKJ8SvowfTRoNMeVD8Kd60=";
expectedPnpmHash = "sha256-np4qMhJJBwpEJA/Zac1WEueUmaufs2wLBaa1BUiBgcM=";
expectedChangelog = "https://github.com/n8n-io/n8n/releases/tag/n8n@${expectedVersion}";
expectedRootNodeModuleSymlinks = [
"ln -s .pnpm/node_modules/sass-embedded node_modules/sass-embedded"
"ln -s .pnpm/node_modules/sqlite3 node_modules/sqlite3"
];
# pnpm 12: prune must run offline without the minimumReleaseAge registry
# check, and peers it drops must be re-linked from the hoisted directory.
expectedPreInstallSnippets = [
"pnpm --ignore-scripts --offline --config.minimum-release-age=0 prune --prod -w"
"Re-linking peer dependencies dropped by pnpm prune"
"node_modules/.pnpm/node_modules"
];
checkN8nOverride = overlayName: package:
if package.version != expectedVersion
then throw "${overlayName} n8n version is ${package.version}, expected ${expectedVersion}"
else if package.src.outputHash != expectedSrcHash
then throw "${overlayName} n8n src hash is ${package.src.outputHash}, expected ${expectedSrcHash}"
else if package.pnpmDeps.outputHash != expectedPnpmHash
then throw "${overlayName} n8n pnpmDeps hash is ${package.pnpmDeps.outputHash}, expected ${expectedPnpmHash}"
else if package.meta.changelog != expectedChangelog
then throw "${overlayName} n8n changelog is ${package.meta.changelog}, expected ${expectedChangelog}"
else "ok";
checkBuildPhaseInherited = overlayName: package:
if package.buildPhase != upstreamPkgs.n8n.buildPhase
then throw "${overlayName} n8n buildPhase should be inherited from upstream nixpkgs"
else "ok";
checkRootNodeModuleSymlinks = overlayName: package:
if !(pkgs.lib.all (symlink: pkgs.lib.hasInfix symlink (package.preBuild or "")) expectedRootNodeModuleSymlinks)
then throw "${overlayName} n8n preBuild should create root node_modules symlinks required by the upstream buildPhase"
else "ok";
checkPreInstallPnpm12 = overlayName: package:
if !(pkgs.lib.all (snippet: pkgs.lib.hasInfix snippet (package.preInstall or "")) expectedPreInstallSnippets)
then throw "${overlayName} n8n preInstall should prune offline with pnpm 12 and re-link pruned peer dependencies"
else if pkgs.lib.hasInfix "pnpm --ignore-scripts prune --prod -w" (package.preInstall or "")
then throw "${overlayName} n8n preInstall still contains the unmodified upstream prune command"
else "ok";
in
pkgs.runCommand "n8n-overlay-test" {
n8nOverlayFile =
if builtins.pathExists ../overlays/mods/n8n.nix
then "ok"
else throw "n8n overlay override must live in overlays/mods/n8n.nix";
localN8nAbsent =
if localPackages ? n8n
then throw "pkgs/default.nix must not export a local n8n package"
else "ok";
modificationsOverlayN8n = checkN8nOverride "overlays.modifications" modifiedPkgs.n8n;
defaultOverlayN8n = checkN8nOverride "overlays.default" defaultPkgs.n8n;
modificationsOverlayBuildPhase = checkBuildPhaseInherited "overlays.modifications" modifiedPkgs.n8n;
defaultOverlayBuildPhase = checkBuildPhaseInherited "overlays.default" defaultPkgs.n8n;
modificationsOverlayRootNodeModuleSymlinks = checkRootNodeModuleSymlinks "overlays.modifications" modifiedPkgs.n8n;
defaultOverlayRootNodeModuleSymlinks = checkRootNodeModuleSymlinks "overlays.default" defaultPkgs.n8n;
modificationsOverlayPreInstall = checkPreInstallPnpm12 "overlays.modifications" modifiedPkgs.n8n;
defaultOverlayPreInstall = checkPreInstallPnpm12 "overlays.default" defaultPkgs.n8n;
} ''
touch $out
''