From 83ace87bc75eac42d93463c6cc2bac18336fc9d3 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 9 May 2026 11:41:40 +0200 Subject: [PATCH] fetchPnpmDeps,pnpmConfigHook: add support for pnpm 11 pnpm 11 does not support configuring some options through its new global config format. As a workaround, we can define these environment variables instead. This also adds support for the new pmOnFail option in pnpm 11 that replaces managePackageManagerVersions. Signed-off-by: Sefa Eyeoglu --- .../node/fetch-pnpm-deps/default.nix | 35 +++++++++++++------ .../node/fetch-pnpm-deps/pnpm-config-hook.sh | 22 +++++++++--- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/pkgs/build-support/node/fetch-pnpm-deps/default.nix b/pkgs/build-support/node/fetch-pnpm-deps/default.nix index bba11ef60560..79dcddbb4a81 100644 --- a/pkgs/build-support/node/fetch-pnpm-deps/default.nix +++ b/pkgs/build-support/node/fetch-pnpm-deps/default.nix @@ -99,6 +99,11 @@ in installPhase = '' runHook preInstall + versionAtLeast () { + local cur_version=$1 min_version=$2 + printf "%s\0%s" "$min_version" "$cur_version" | sort -zVC + } + lockfileVersion="$(yq -r .lockfileVersion pnpm-lock.yaml)" if [[ ''${lockfileVersion:0:1} -gt ${lib.versions.major pnpm.version} ]]; then echo "ERROR: lockfileVersion $lockfileVersion in pnpm-lock.yaml is too new for the provided pnpm version ${lib.versions.major pnpm.version}!" @@ -115,19 +120,29 @@ in storePath=$out fi - # If the packageManager field in package.json is set to a different pnpm version than what is in nixpkgs, - # any pnpm command would fail in that directory, the following disables this - pushd .. - pnpm config set manage-package-manager-versions false + pushd "$HOME" + pnpmVersion=$(pnpm --version) + + if versionAtLeast "$pnpmVersion" "11"; then + # pnpm 11 uses a different mechanism to manage package manager versions + export pnpm_config_pm_on_fail=ignore + + # Some packages produce platform dependent outputs. We do not want to cache those in the global store + export pnpm_config_side_effects_cache false + + export pnpm_config_update_notifier false + else + pnpm config set manage-package-manager-versions false + pnpm config set side-effects-cache false + pnpm config set update-notifier false + fi popd pnpm config set store-dir $storePath - # Some packages produce platform dependent outputs. We do not want to cache those in the global store - pnpm config set side-effects-cache false - # As we pin pnpm versions, we don't really care about updates - pnpm config set update-notifier false + # Run any additional pnpm configuration commands that users provide. ${prePnpmInstall} + # pnpm is going to warn us about using --force # --force allows us to fetch all dependencies including ones that aren't meant for our host platform pnpm install \ @@ -150,7 +165,7 @@ in runHook preFixup # Remove timestamp and sort the json files - rm -rf $storePath/{v3,v10}/tmp + rm -rf $storePath/{v3,v10,v11}/tmp for f in $(find $storePath -name "*.json"); do jq --sort-keys "del(.. | .checkedAt?)" $f | sponge $f done @@ -161,7 +176,7 @@ in # This folder contains symlinks to /build/source which we don't need # since https://github.com/pnpm/pnpm/releases/tag/v10.27.0 - rm -rf $storePath/{v3,v10}/projects + rm -rf $storePath/{v3,v10,v11}/projects # Ensure consistent permissions # NOTE: For reasons not yet fully understood, pnpm might create files with diff --git a/pkgs/build-support/node/fetch-pnpm-deps/pnpm-config-hook.sh b/pkgs/build-support/node/fetch-pnpm-deps/pnpm-config-hook.sh index 2590de95343a..f9c19341d00b 100644 --- a/pkgs/build-support/node/fetch-pnpm-deps/pnpm-config-hook.sh +++ b/pkgs/build-support/node/fetch-pnpm-deps/pnpm-config-hook.sh @@ -1,5 +1,10 @@ # shellcheck shell=bash +versionAtLeast () { + local cur_version=$1 min_version=$2 + printf "%s\0%s" "$min_version" "$cur_version" | sort -zVC +} + pnpmConfigHook() { echo "Executing pnpmConfigHook" @@ -17,13 +22,18 @@ pnpmConfigHook() { exit 1 fi - # If the packageManager field in package.json is set to a different pnpm version than what is in nixpkgs, - # any pnpm command would fail in that directory, the following disables this - pushd $HOME - pnpm config set manage-package-manager-versions false + pushd "$HOME" + pnpmVersion=$(pnpm --version) + + if versionAtLeast "$pnpmVersion" "11"; then + # pnpm 11 uses a different mechanism to manage package manager versions + export pnpm_config_pm_on_fail=ignore + else + pnpm config set manage-package-manager-versions false + fi popd - echo "Found 'pnpm' with version '$(pnpm --version)'" + echo "Found 'pnpm' with version '$pnpmVersion'" fetcherVersion=$(cat "${pnpmDeps}/.fetcher-version" || echo 1) @@ -33,7 +43,9 @@ pnpmConfigHook() { export STORE_PATH=$(mktemp -d) export npm_config_arch="@npmArch@" + export pnpm_config_arch="@npmArch@" export npm_config_platform="@npmPlatform@" + export pnpm_config_platform="@npmPlatform@" if [[ $fetcherVersion -ge 3 ]]; then tar --zstd -xf "$pnpmDeps/pnpm-store.tar.zst" -C "$STORE_PATH"