|
7 | 7 | cacert, |
8 | 8 | makeSetupHook, |
9 | 9 | pnpm, |
| 10 | + pnpm-fixup-state-db, |
10 | 11 | writableTmpDirAsHomeHook, |
11 | 12 | yq, |
12 | 13 | zstd, |
|
47 | 48 | }; |
48 | 49 |
|
49 | 50 | filterFlags = lib.map (package: "--filter=${package}") pnpmWorkspaces; |
| 51 | + |
| 52 | + pnpm-fixup-state-db' = |
| 53 | + if pnpm.nodejs or null != null then |
| 54 | + pnpm-fixup-state-db.override { |
| 55 | + inherit (pnpm) nodejs; |
| 56 | + } |
| 57 | + else |
| 58 | + pnpm-fixup-state-db; |
50 | 59 | in |
51 | 60 | # pnpmWorkspace was deprecated, so throw if it's used. |
52 | 61 | assert (lib.throwIf (args ? pnpmWorkspace) |
|
77 | 86 | jq |
78 | 87 | moreutils |
79 | 88 | pnpm # from args |
| 89 | + pnpm-fixup-state-db' |
| 90 | + writableTmpDirAsHomeHook |
80 | 91 | yq |
81 | 92 | zstd |
82 | 93 | ] |
|
88 | 99 | installPhase = '' |
89 | 100 | runHook preInstall |
90 | 101 |
|
| 102 | + versionAtLeast () { |
| 103 | + local cur_version=$1 min_version=$2 |
| 104 | + printf "%s\0%s" "$min_version" "$cur_version" | sort -zVC |
| 105 | + } |
| 106 | +
|
91 | 107 | lockfileVersion="$(yq -r .lockfileVersion pnpm-lock.yaml)" |
92 | 108 | if [[ ''${lockfileVersion:0:1} -gt ${lib.versions.major pnpm.version} ]]; then |
93 | 109 | echo "ERROR: lockfileVersion $lockfileVersion in pnpm-lock.yaml is too new for the provided pnpm version ${lib.versions.major pnpm.version}!" |
94 | 110 | exit 1 |
95 | 111 | fi |
96 | 112 |
|
97 | | - export HOME=$(mktemp -d) |
98 | | -
|
99 | 113 | # For fetcherVersion < 3, the pnpm store files are placed directly into $out. |
100 | 114 | # For fetcherVersion >= 3, it is bundled into a compressed tarball within $out, |
101 | 115 | # without distributing the uncompressed store files. |
|
106 | 120 | storePath=$out |
107 | 121 | fi |
108 | 122 |
|
109 | | - # If the packageManager field in package.json is set to a different pnpm version than what is in nixpkgs, |
110 | | - # any pnpm command would fail in that directory, the following disables this |
111 | | - pushd .. |
112 | | - pnpm config set manage-package-manager-versions false |
| 123 | + pushd "$HOME" |
| 124 | + pnpmVersion=$(pnpm --version) |
| 125 | +
|
| 126 | + if versionAtLeast "$pnpmVersion" "11"; then |
| 127 | + # pnpm 11 uses a different mechanism to manage package manager versions |
| 128 | + export pnpm_config_pm_on_fail=ignore |
| 129 | +
|
| 130 | + # Some packages produce platform dependent outputs. We do not want to cache those in the global store |
| 131 | + export pnpm_config_side_effects_cache false |
| 132 | +
|
| 133 | + export pnpm_config_update_notifier false |
| 134 | + else |
| 135 | + pnpm config set manage-package-manager-versions false |
| 136 | + pnpm config set side-effects-cache false |
| 137 | + pnpm config set update-notifier false |
| 138 | + fi |
113 | 139 | popd |
114 | 140 |
|
115 | 141 | pnpm config set store-dir $storePath |
116 | | - # Some packages produce platform dependent outputs. We do not want to cache those in the global store |
117 | | - pnpm config set side-effects-cache false |
118 | | - # As we pin pnpm versions, we don't really care about updates |
119 | | - pnpm config set update-notifier false |
| 142 | +
|
120 | 143 | # Run any additional pnpm configuration commands that users provide. |
121 | 144 | ${prePnpmInstall} |
| 145 | +
|
122 | 146 | # pnpm is going to warn us about using --force |
123 | 147 | # --force allows us to fetch all dependencies including ones that aren't meant for our host platform |
124 | 148 | pnpm install \ |
|
141 | 165 | runHook preFixup |
142 | 166 |
|
143 | 167 | # Remove timestamp and sort the json files |
144 | | - rm -rf $storePath/{v3,v10}/tmp |
| 168 | + rm -rf $storePath/{v3,v10,v11}/tmp |
145 | 169 | for f in $(find $storePath -name "*.json"); do |
146 | 170 | jq --sort-keys "del(.. | .checkedAt?)" $f | sponge $f |
147 | 171 | done |
148 | 172 |
|
| 173 | + if [ -f "$storePath/v11/index.db" ]; then |
| 174 | + pnpm-fixup-state-db "$storePath/v11"; |
| 175 | + fi |
| 176 | +
|
149 | 177 | # This folder contains symlinks to /build/source which we don't need |
150 | 178 | # since https://github.com/pnpm/pnpm/releases/tag/v10.27.0 |
151 | | - rm -rf $storePath/{v3,v10}/projects |
| 179 | + rm -rf $storePath/{v3,v10,v11}/projects |
152 | 180 |
|
153 | 181 | # Ensure consistent permissions |
154 | 182 | # NOTE: For reasons not yet fully understood, pnpm might create files with |
|
0 commit comments