1{
2 lib,
3 stdenvNoCC,
4 callPackages,
5 fetchurl,
6 installShellFiles,
7 nodejs,
8 testers,
9 withNode ? true,
10
11 version,
12 hash,
13}: stdenvNoCC.mkDerivation (finalAttrs: {
14 pname = "pnpm";
15 inherit version;
16
17 src = fetchurl {
18 url = "https://registry.npmjs.org/pnpm/-/pnpm-${finalAttrs.version}.tgz";
19 inherit hash;
20 };
21 # Remove binary files from src, we don't need them, and this way we make sure
22 # our distribution is free of binaryNativeCode
23 preConfigure = ''
24 rm -r dist/reflink.*node dist/vendor
25 '';
26
27 buildInputs = lib.optionals withNode [ nodejs ];
28
29 nativeBuildInputs = [ installShellFiles nodejs ];
30
31 installPhase = ''
32 runHook preInstall
33
34 install -d $out/{bin,libexec}
35 cp -R . $out/libexec/pnpm
36 ln -s $out/libexec/pnpm/bin/pnpm.cjs $out/bin/pnpm
37 ln -s $out/libexec/pnpm/bin/pnpx.cjs $out/bin/pnpx
38
39 runHook postInstall
40 '';
41
42 postInstall =
43 if lib.toInt (lib.versions.major version) < 9 then ''
44 export HOME="$PWD"
45 node $out/bin/pnpm install-completion bash
46 node $out/bin/pnpm install-completion fish
47 node $out/bin/pnpm install-completion zsh
48 sed -i '1 i#compdef pnpm' .config/tabtab/zsh/pnpm.zsh
49 installShellCompletion \
50 .config/tabtab/bash/pnpm.bash \
51 .config/tabtab/fish/pnpm.fish \
52 .config/tabtab/zsh/pnpm.zsh
53 '' else ''
54 node $out/bin/pnpm completion bash >pnpm.bash
55 node $out/bin/pnpm completion fish >pnpm.fish
56 node $out/bin/pnpm completion zsh >pnpm.zsh
57 sed -i '1 i#compdef pnpm' pnpm.zsh
58 installShellCompletion pnpm.{bash,fish,zsh}
59 '';
60
61 passthru = let
62 fetchDepsAttrs = callPackages ./fetch-deps { pnpm = finalAttrs.finalPackage; };
63 in {
64 inherit (fetchDepsAttrs) fetchDeps configHook;
65
66 tests.version = lib.optionalAttrs withNode (
67 testers.testVersion { package = finalAttrs.finalPackage; }
68 );
69 };
70
71 meta = with lib; {
72 description = "Fast, disk space efficient package manager for JavaScript";
73 homepage = "https://pnpm.io/";
74 changelog = "https://github.com/pnpm/pnpm/releases/tag/v${finalAttrs.version}";
75 license = licenses.mit;
76 maintainers = with maintainers; [ Scrumplex ];
77 platforms = platforms.all;
78 mainProgram = "pnpm";
79 };
80})