-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2015a5d
commit 479ea46
Showing
5 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ lib | ||
, stdenvNoCC | ||
, nodePackages | ||
, jq | ||
, moreutils | ||
, cacert | ||
, makeSetupHook | ||
}: { | ||
fetchPnpmDeps = | ||
{ src | ||
, hash ? "" | ||
, pname | ||
, pnpm ? nodePackages.pnpm | ||
, ... | ||
} @ args: | ||
let | ||
args' = builtins.removeAttrs args [ "hash" "pname" "pnpm" "supportedArchitectures" ]; | ||
hash' = | ||
if hash != "" then { | ||
outputHash = hash; | ||
} else { | ||
outputHash = ""; | ||
outputHashAlgo = "sha256"; | ||
}; | ||
in | ||
# NOTE: This requires pnpm 8.10.0 or newer | ||
# https://github.com/pnpm/pnpm/pull/7214 | ||
assert lib.versionAtLeast pnpm.version "8.10.0"; | ||
stdenvNoCC.mkDerivation (args' // { | ||
name = "${pname}-pnpm-deps"; | ||
|
||
nativeBuildInputs = [ | ||
jq | ||
moreutils | ||
pnpm | ||
cacert | ||
]; | ||
|
||
# https://github.com/NixOS/nixpkgs/blob/763e59ffedb5c25774387bf99bc725df5df82d10/pkgs/applications/misc/pot/default.nix#L56 | ||
installPhase = '' | ||
runHook preInstall | ||
export HOME=$(mktemp -d) | ||
pnpm config set store-dir $out | ||
# 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 --frozen-lockfile --ignore-script --force | ||
runHook postInstall | ||
''; | ||
|
||
fixupPhase = '' | ||
runHook preFixup | ||
rm -rf $out/v3/tmp | ||
for f in $(find $out -name "*.json"); do | ||
sed -i -E -e 's/"checkedAt":[0-9]+,//g' $f | ||
jq --sort-keys . $f | sponge $f | ||
done | ||
runHook postFixup | ||
''; | ||
|
||
dontConfigure = true; | ||
dontBuild = true; | ||
outputHashMode = "recursive"; | ||
} // hash'); | ||
|
||
pnpmConfigHook = makeSetupHook | ||
{ | ||
name = "pnpm-config-hook"; | ||
} ./pnpm-config-hook.sh; | ||
} |
36 changes: 36 additions & 0 deletions
36
pkgs/build-support/node/fetch-pnpm-deps/pnpm-config-hook.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# shellcheck shell=bash | ||
|
||
pnpmConfigHook() { | ||
echo "Executing pnpmConfigHook" | ||
|
||
if [ -z "${pnpmDeps-}" ]; then | ||
echo "Error: 'npmDeps' should be set when using npmConfigHook." | ||
exit 1 | ||
fi | ||
|
||
echo "Configuring pnpm store" | ||
|
||
export HOME=$(mktemp -d) | ||
export STORE_PATH=$(mktemp -d) | ||
|
||
cp -Tr "$pnpmDeps" "$STORE_PATH" | ||
chmod -R +w "$STORE_PATH" | ||
|
||
pnpm config set store-dir "$STORE_PATH" | ||
|
||
echo "Installing dependencies" | ||
|
||
if ! pnpm install --offline --frozen-lockfile --ignore-script; then | ||
echo | ||
echo "ERROR: pnpm failed to install dependencies" | ||
echo | ||
|
||
exit 1 | ||
fi | ||
|
||
patchShebangs node_modules/{*,.*} | ||
|
||
echo "Finished pnpmConfigHook" | ||
} | ||
|
||
postConfigureHooks+=(pnpmConfigHook) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters