nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 144 lines 4.0 kB view raw
1{ 2 lib, 3 stdenvNoCC, 4 writeScript, 5 fetchPnpmDeps, 6 pnpmConfigHook, 7 fetchurl, 8 installShellFiles, 9 nodejs, 10 testers, 11 withNode ? true, 12 version, 13 hash, 14 buildPackages, 15}: 16let 17 majorVersion = lib.versions.major version; 18in 19stdenvNoCC.mkDerivation (finalAttrs: { 20 pname = "pnpm"; 21 inherit version; 22 23 src = fetchurl { 24 url = "https://registry.npmjs.org/pnpm/-/pnpm-${finalAttrs.version}.tgz"; 25 inherit hash; 26 }; 27 # Remove binary files from src, we don't need them, and this way we make sure 28 # our distribution is free of binaryNativeCode 29 preConfigure = '' 30 rm -r dist/reflink.*node dist/vendor 31 ''; 32 33 buildInputs = lib.optionals withNode [ nodejs ]; 34 35 nativeBuildInputs = [ 36 installShellFiles 37 nodejs 38 ]; 39 40 installPhase = '' 41 runHook preInstall 42 43 install -d $out/{bin,libexec} 44 cp -R . $out/libexec/pnpm 45 ln -s $out/libexec/pnpm/bin/pnpm.cjs $out/bin/pnpm 46 ln -s $out/libexec/pnpm/bin/pnpx.cjs $out/bin/pnpx 47 48 runHook postInstall 49 ''; 50 51 postInstall = 52 if lib.toInt (lib.versions.major version) < 9 then 53 '' 54 export HOME="$PWD" 55 node $out/bin/pnpm install-completion bash 56 node $out/bin/pnpm install-completion fish 57 node $out/bin/pnpm install-completion zsh 58 sed -i '1 i#compdef pnpm' .config/tabtab/zsh/pnpm.zsh 59 installShellCompletion \ 60 .config/tabtab/bash/pnpm.bash \ 61 .config/tabtab/fish/pnpm.fish \ 62 .config/tabtab/zsh/pnpm.zsh 63 '' 64 else 65 '' 66 node $out/bin/pnpm completion bash >pnpm.bash 67 node $out/bin/pnpm completion fish >pnpm.fish 68 node $out/bin/pnpm completion zsh >pnpm.zsh 69 sed -i '1 i#compdef pnpm' pnpm.zsh 70 installShellCompletion pnpm.{bash,fish,zsh} 71 ''; 72 73 passthru = 74 let 75 pnpm' = buildPackages."pnpm_${lib.versions.major version}"; 76 in 77 { 78 fetchDeps = 79 lib.warn 80 "pnpm.fetchDeps: The package attribute is deprecated. Use the top-level fetchPnpmDeps attribute instead" 81 ( 82 { ... }@args: 83 fetchPnpmDeps ( 84 args 85 // { 86 pnpm = pnpm'; 87 } 88 ) 89 ); 90 configHook = 91 lib.warn 92 "pnpm.configHook: The package attribute is deprecated. Use the top-level pnpmConfigHook attribute instead" 93 ( 94 pnpmConfigHook.overrideAttrs (prevAttrs: { 95 propagatedBuildInputs = prevAttrs.propagatedBuildInputs or [ ] ++ [ 96 pnpm' 97 ]; 98 }) 99 ); 100 inherit majorVersion; 101 102 tests.version = lib.optionalAttrs withNode ( 103 testers.testVersion { package = finalAttrs.finalPackage; } 104 ); 105 updateScript = writeScript "pnpm-update-script" '' 106 #!/usr/bin/env nix-shell 107 #!nix-shell -i bash -p curl jq common-updater-scripts 108 set -eou pipefail 109 110 curl_github() { 111 curl -L ''${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} "$@" 112 } 113 114 latestTag=$( 115 curl_github https://api.github.com/repos/pnpm/pnpm/releases?per_page=100 | \ 116 jq -r --arg major "v${majorVersion}" \ 117 '[.[] | select(.tag_name | startswith($major)) | select(.prerelease == false)][0].tag_name' 118 ) 119 120 # Exit if there is no tag with this major version 121 if [ "$latestTag" = "null" ]; then 122 echo "No releases starting with v${majorVersion}" 123 exit 0 124 fi 125 126 latestVersion="''${latestTag#v}" 127 128 update-source-version pnpm_${majorVersion} "$latestVersion" --file=./pkgs/development/tools/pnpm/default.nix 129 ''; 130 }; 131 132 meta = { 133 description = "Fast, disk space efficient package manager for JavaScript"; 134 homepage = "https://pnpm.io/"; 135 changelog = "https://github.com/pnpm/pnpm/releases/tag/v${finalAttrs.version}"; 136 license = lib.licenses.mit; 137 maintainers = with lib.maintainers; [ 138 Scrumplex 139 gepbird 140 ]; 141 platforms = lib.platforms.all; 142 mainProgram = "pnpm"; 143 }; 144})