nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 128 lines 4.3 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 makeWrapper, 6 nodejs, 7 pnpm_9, 8 autoPatchelfHook, 9 cacert, 10 llvmPackages, 11 musl, 12 xorg, 13 jq, 14 moreutils, 15 nix-update-script, 16 versionCheckHook, 17}: 18stdenv.mkDerivation (finalAttrs: { 19 pname = "wrangler"; 20 version = "4.26.1"; 21 22 src = fetchFromGitHub { 23 owner = "cloudflare"; 24 repo = "workers-sdk"; 25 rev = "wrangler@${finalAttrs.version}"; 26 hash = "sha256-7Z2MCG9YKwIkZ2eJucSgFr9R+rR+GFKiSXQX0xR5Xas="; 27 }; 28 29 pnpmDeps = pnpm_9.fetchDeps { 30 inherit (finalAttrs) 31 pname 32 version 33 src 34 postPatch 35 ; 36 fetcherVersion = 2; 37 hash = "sha256-Gsiq0+PIA3rJ0D9JryqaO0ThQcY+hC02AtzxdS+wSPg="; 38 }; 39 # pnpm packageManager version in workers-sdk root package.json may not match nixpkgs 40 postPatch = '' 41 jq 'del(.packageManager)' package.json | sponge package.json 42 ''; 43 44 passthru.updateScript = nix-update-script { 45 extraArgs = [ 46 "--version-regex=wrangler@(.*)" 47 ]; 48 }; 49 50 buildInputs = [ 51 llvmPackages.libcxx 52 llvmPackages.libunwind 53 ] 54 ++ lib.optionals (stdenv.hostPlatform.isLinux) [ 55 musl # not used, but requires extra work to remove 56 xorg.libX11 # for the clipboardy package 57 ]; 58 59 nativeBuildInputs = [ 60 makeWrapper 61 nodejs 62 pnpm_9.configHook 63 jq 64 moreutils 65 ] 66 ++ lib.optionals (stdenv.hostPlatform.isLinux) [ 67 autoPatchelfHook 68 ]; 69 70 # @cloudflare/vitest-pool-workers wanted to run a server as part of the build process 71 # so I simply removed it 72 postBuild = '' 73 mv packages/vitest-pool-workers packages/~vitest-pool-workers 74 NODE_ENV="production" pnpm --filter workers-shared run build 75 NODE_ENV="production" pnpm --filter miniflare run build 76 NODE_ENV="production" pnpm --filter wrangler run build 77 ''; 78 79 # I'm sure this is suboptimal but it seems to work. Points: 80 # - when build is run in the original repo, no specific executable seems to be generated; you run the resulting build with pnpm run start 81 # - this means we need to add a dedicated script - perhaps it is possible to create this from the workers-sdk dir, but I don't know how to do this 82 # - the build process builds a version of miniflare which is used by wrangler; for this reason, the miniflare package is copied also 83 # - pnpm stores all content in the top-level node_modules directory, but it is linked to from a node_modules directory inside wrangler 84 # - as they are linked via symlinks, the relative location of them on the filesystem should be maintained 85 # - Update: Now we're copying everything over due to broken symlink errors 86 installPhase = '' 87 runHook preInstall 88 mkdir -p $out/bin $out/lib $out/lib/packages/wrangler 89 mv packages/~vitest-pool-workers packages/vitest-pool-workers 90 cp -r fixtures $out/lib 91 cp -r packages $out/lib 92 cp -r node_modules $out/lib 93 cp -r tools $out/lib/tools 94 rm -rf node_modules/typescript node_modules/eslint node_modules/prettier node_modules/bin node_modules/.bin node_modules/**/bin node_modules/**/.bin 95 rm -rf $out/lib/**/bin $out/lib/**/.bin 96 NODE_PATH_ARRAY=( "$out/lib/node_modules" "$out/lib/packages/wrangler/node_modules" ) 97 makeWrapper ${lib.getExe nodejs} $out/bin/wrangler \ 98 --inherit-argv0 \ 99 --prefix-each NODE_PATH : "$${NODE_PATH_ARRAY[@]}" \ 100 --add-flags $out/lib/packages/wrangler/bin/wrangler.js \ 101 --set-default SSL_CERT_FILE "${cacert}/etc/ssl/certs/ca-bundle.crt" # https://github.com/cloudflare/workers-sdk/issues/3264 102 runHook postInstall 103 ''; 104 doInstallCheck = true; 105 nativeInstallCheckInputs = [ 106 versionCheckHook 107 ]; 108 meta = { 109 description = "Command-line interface for all things Cloudflare Workers"; 110 homepage = "https://github.com/cloudflare/workers-sdk#readme"; 111 license = with lib.licenses; [ 112 mit 113 apsl20 114 ]; 115 maintainers = with lib.maintainers; [ 116 seanrmurphy 117 dezren39 118 ryand56 119 ezrizhu 120 ]; 121 mainProgram = "wrangler"; 122 # Tunneling and other parts of wrangler, which require workerd won't run on 123 # other systems where precompiled binaries are not provided, but most 124 # commands are will still work everywhere. 125 # Potential improvements: build workerd from source instead. 126 inherit (nodejs.meta) platforms; 127 }; 128})