nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 113 lines 3.3 kB view raw
1{ 2 lib, 3 buildNpmPackage, 4 nodejs_22, 5 fetchFromGitHub, 6 nix-update-script, 7 jq, 8 git, 9 ripgrep, 10 pkg-config, 11 glib, 12 libsecret, 13}: 14 15buildNpmPackage (finalAttrs: { 16 pname = "qwen-code"; 17 version = "0.4.0"; 18 19 src = fetchFromGitHub { 20 owner = "QwenLM"; 21 repo = "qwen-code"; 22 tag = "v${finalAttrs.version}"; 23 hash = "sha256-B7dL0pWSCPwPKwwTHycgC3/qHB66AUWZc62sen7U/7c="; 24 }; 25 26 npmDepsHash = "sha256-SPb+TSi4MCiAr9ruS1Idg3KfTbX6gtMK7f/+vdnabt8="; 27 28 # npm 11 incompatible with fetchNpmDeps 29 # https://github.com/NixOS/nixpkgs/issues/474535 30 nodejs = nodejs_22; 31 32 nativeBuildInputs = [ 33 jq 34 pkg-config 35 git 36 ]; 37 38 buildInputs = [ 39 ripgrep 40 glib 41 libsecret 42 ]; 43 44 postPatch = '' 45 # patches below remove node-pty and keytar dependencies which cause build fail on Darwin 46 # should be conditional on platform but since package-lock.json is patched it changes its hash 47 # though seems like these dependencies are not really required by the package 48 ${jq}/bin/jq ' 49 del(.packages."node_modules/node-pty") | 50 del(.packages."node_modules/@lydell/node-pty") | 51 del(.packages."node_modules/@lydell/node-pty-darwin-arm64") | 52 del(.packages."node_modules/@lydell/node-pty-darwin-x64") | 53 del(.packages."node_modules/@lydell/node-pty-linux-arm64") | 54 del(.packages."node_modules/@lydell/node-pty-linux-x64") | 55 del(.packages."node_modules/@lydell/node-pty-win32-arm64") | 56 del(.packages."node_modules/@lydell/node-pty-win32-x64") | 57 del(.packages."node_modules/keytar") | 58 walk( 59 if type == "object" and has("dependencies") then 60 .dependencies |= with_entries(select(.key | (contains("node-pty") | not) and (contains("keytar") | not))) 61 elif type == "object" and has("optionalDependencies") then 62 .optionalDependencies |= with_entries(select(.key | (contains("node-pty") | not) and (contains("keytar") | not))) 63 else . 64 end 65 ) | 66 walk( 67 if type == "object" and has("peerDependencies") then 68 .peerDependencies |= with_entries(select(.key | (contains("node-pty") | not) and (contains("keytar") | not))) 69 else . 70 end 71 ) 72 ' package-lock.json > package-lock.json.tmp && mv package-lock.json.tmp package-lock.json 73 ''; 74 75 buildPhase = '' 76 runHook preBuild 77 78 npm run generate 79 npm run bundle 80 81 runHook postBuild 82 ''; 83 84 installPhase = '' 85 runHook preInstall 86 87 mkdir -p $out/bin $out/share/qwen-code 88 cp -r dist/* $out/share/qwen-code/ 89 # Install production dependencies only 90 npm prune --production 91 cp -r node_modules $out/share/qwen-code/ 92 # Remove broken symlinks that cause issues in Nix environment 93 find $out/share/qwen-code/node_modules -type l -delete || true 94 patchShebangs $out/share/qwen-code 95 ln -s $out/share/qwen-code/cli.js $out/bin/qwen 96 97 runHook postInstall 98 ''; 99 100 passthru.updateScript = nix-update-script { }; 101 102 meta = { 103 description = "Coding agent that lives in digital world"; 104 homepage = "https://github.com/QwenLM/qwen-code"; 105 mainProgram = "qwen"; 106 license = lib.licenses.asl20; 107 platforms = lib.platforms.all; 108 maintainers = with lib.maintainers; [ 109 lonerOrz 110 taranarmo 111 ]; 112 }; 113})