Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

125 lines
3.3 KiB
Nix
Raw Permalink Normal View History

{
lib,
stdenvNoCC,
writeScript,
callPackages,
fetchurl,
2024-06-15 12:23:28 -07:00
installShellFiles,
nodejs,
testers,
withNode ? true,
version,
hash,
2025-04-12 11:30:06 +02:00
buildPackages,
2024-10-19 09:47:53 +02:00
}:
let
majorVersion = lib.versions.major version;
in
2024-10-19 09:47:53 +02:00
stdenvNoCC.mkDerivation (finalAttrs: {
pname = "pnpm";
inherit version;
src = fetchurl {
url = "https://registry.npmjs.org/pnpm/-/pnpm-${finalAttrs.version}.tgz";
inherit hash;
};
# Remove binary files from src, we don't need them, and this way we make sure
# our distribution is free of binaryNativeCode
preConfigure = ''
rm -r dist/reflink.*node dist/vendor
'';
buildInputs = lib.optionals withNode [ nodejs ];
2024-10-19 09:47:53 +02:00
nativeBuildInputs = [
installShellFiles
nodejs
];
2024-06-15 12:23:28 -07:00
installPhase = ''
runHook preInstall
install -d $out/{bin,libexec}
cp -R . $out/libexec/pnpm
ln -s $out/libexec/pnpm/bin/pnpm.cjs $out/bin/pnpm
ln -s $out/libexec/pnpm/bin/pnpx.cjs $out/bin/pnpx
runHook postInstall
'';
2024-06-15 12:23:28 -07:00
postInstall =
2024-10-19 09:47:53 +02:00
if lib.toInt (lib.versions.major version) < 9 then
''
export HOME="$PWD"
node $out/bin/pnpm install-completion bash
node $out/bin/pnpm install-completion fish
node $out/bin/pnpm install-completion zsh
sed -i '1 i#compdef pnpm' .config/tabtab/zsh/pnpm.zsh
installShellCompletion \
.config/tabtab/bash/pnpm.bash \
.config/tabtab/fish/pnpm.fish \
.config/tabtab/zsh/pnpm.zsh
''
else
''
node $out/bin/pnpm completion bash >pnpm.bash
node $out/bin/pnpm completion fish >pnpm.fish
node $out/bin/pnpm completion zsh >pnpm.zsh
sed -i '1 i#compdef pnpm' pnpm.zsh
installShellCompletion pnpm.{bash,fish,zsh}
'';
2024-06-15 12:23:28 -07:00
2024-10-19 09:47:53 +02:00
passthru =
let
2025-04-12 11:30:06 +02:00
fetchDepsAttrs = callPackages ./fetch-deps {
pnpm = buildPackages."pnpm_${lib.versions.major version}";
};
2024-10-19 09:47:53 +02:00
in
{
inherit (fetchDepsAttrs) fetchDeps configHook;
inherit majorVersion;
2024-10-19 09:47:53 +02:00
tests.version = lib.optionalAttrs withNode (
testers.testVersion { package = finalAttrs.finalPackage; }
);
updateScript = writeScript "pnpm-update-script" ''
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq common-updater-scripts
set -eou pipefail
curl_github() {
curl -L ''${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} "$@"
}
latestTag=$(
curl_github https://api.github.com/repos/pnpm/pnpm/releases?per_page=100 | \
jq -r --arg major "v${majorVersion}" \
'[.[] | select(.tag_name | startswith($major)) | select(.prerelease == false)][0].tag_name'
)
# Exit if there is no tag with this major version
if [ "$latestTag" = "null" ]; then
echo "No releases starting with v${majorVersion}"
exit 0
fi
latestVersion="''${latestTag#v}"
update-source-version pnpm_${majorVersion} "$latestVersion" --file=./pkgs/development/tools/pnpm/default.nix
'';
2024-10-19 09:47:53 +02:00
};
2024-10-19 10:17:45 +02:00
meta = {
description = "Fast, disk space efficient package manager for JavaScript";
homepage = "https://pnpm.io/";
changelog = "https://github.com/pnpm/pnpm/releases/tag/v${finalAttrs.version}";
2024-10-19 10:17:45 +02:00
license = lib.licenses.mit;
maintainers = with lib.maintainers; [
2024-10-19 09:47:53 +02:00
Scrumplex
gepbird
];
2024-10-19 10:17:45 +02:00
platforms = lib.platforms.all;
mainProgram = "pnpm";
};
})