Skip to content

Commit 2268d9a

Browse files
authored
Merge pull request #1364 from numtide/qwen-code-2
qwen-code: 0.4.0 -> 0.4.1
2 parents b360b13 + 0d3f111 commit 2268d9a

File tree

11 files changed

+3084
-3
lines changed

11 files changed

+3084
-3
lines changed

packages/qwen-code/default.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{ pkgs }:
2+
let
3+
npmPackumentSupport = pkgs.callPackage ./fetch-npm-deps.nix { };
4+
in
25
pkgs.callPackage ./package.nix {
36
darwinOpenptyHook = pkgs.callPackage ../darwinOpenptyHook { };
7+
inherit (npmPackumentSupport) fetchNpmDepsWithPackuments npmConfigHook;
48
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Custom fetchNpmDeps with packument caching support (cacheVersion = 2)
2+
# This builds a vendored prefetch-npm-deps with packument fetching support,
3+
# which is needed for npm workspace support.
4+
# TODO: Remove this once the upstream PR is merged into nixpkgs.
5+
{
6+
lib,
7+
stdenv,
8+
stdenvNoCC,
9+
rustPlatform,
10+
makeSetupHook,
11+
makeWrapper,
12+
pkg-config,
13+
curl,
14+
gnutar,
15+
gzip,
16+
cacert,
17+
config,
18+
nodejs,
19+
srcOnly,
20+
diffutils,
21+
jq,
22+
}:
23+
let
24+
# Build prefetch-npm-deps from vendored source with packument support
25+
prefetch-npm-deps = rustPlatform.buildRustPackage {
26+
pname = "prefetch-npm-deps";
27+
version = "0.1.0-packument";
28+
29+
src = ./prefetch-npm-deps;
30+
31+
cargoLock.lockFile = ./prefetch-npm-deps/Cargo.lock;
32+
33+
nativeBuildInputs = [
34+
makeWrapper
35+
pkg-config
36+
];
37+
buildInputs = [ curl ];
38+
39+
postInstall = ''
40+
wrapProgram "$out/bin/prefetch-npm-deps" --prefix PATH : ${
41+
lib.makeBinPath [
42+
gnutar
43+
gzip
44+
]
45+
}
46+
'';
47+
48+
meta = {
49+
description = "Prefetch dependencies from npm with packument support";
50+
mainProgram = "prefetch-npm-deps";
51+
license = lib.licenses.mit;
52+
};
53+
};
54+
55+
# Custom npmConfigHook that uses our patched prefetch-npm-deps
56+
npmConfigHook = makeSetupHook {
57+
name = "npm-config-hook-packument";
58+
substitutions = {
59+
nodeSrc = srcOnly nodejs;
60+
nodeGyp = "${nodejs}/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js";
61+
npmArch = stdenv.targetPlatform.node.arch;
62+
npmPlatform = stdenv.targetPlatform.node.platform;
63+
diff = "${diffutils}/bin/diff";
64+
jq = "${jq}/bin/jq";
65+
prefetchNpmDeps = "${prefetch-npm-deps}/bin/prefetch-npm-deps";
66+
nodeVersion = nodejs.version;
67+
nodeVersionMajor = lib.versions.major nodejs.version;
68+
};
69+
} ./npm-config-hook.sh;
70+
71+
fetchNpmDepsWithPackuments =
72+
{
73+
name ? "npm-deps",
74+
hash ? "",
75+
forceGitDeps ? false,
76+
forceEmptyCache ? false,
77+
nativeBuildInputs ? [ ],
78+
npmRegistryOverridesString ? config.npmRegistryOverridesString or "{}",
79+
# Cache format version. Set to 2 to enable packument caching for workspace support.
80+
cacheVersion ? 1,
81+
...
82+
}@args:
83+
let
84+
hash_ =
85+
if hash != "" then
86+
{ outputHash = hash; }
87+
else
88+
{
89+
outputHash = "";
90+
outputHashAlgo = "sha256";
91+
};
92+
93+
forceGitDeps_ = lib.optionalAttrs forceGitDeps { FORCE_GIT_DEPS = true; };
94+
forceEmptyCache_ = lib.optionalAttrs forceEmptyCache { FORCE_EMPTY_CACHE = true; };
95+
in
96+
stdenvNoCC.mkDerivation (
97+
args
98+
// {
99+
inherit name;
100+
101+
nativeBuildInputs = nativeBuildInputs ++ [ prefetch-npm-deps ];
102+
103+
buildPhase = ''
104+
runHook preBuild
105+
106+
if [[ -f npm-shrinkwrap.json ]]; then
107+
local -r srcLockfile="npm-shrinkwrap.json"
108+
elif [[ -f package-lock.json ]]; then
109+
local -r srcLockfile="package-lock.json"
110+
else
111+
echo
112+
echo "ERROR: No lock file!"
113+
echo
114+
echo "package-lock.json or npm-shrinkwrap.json is required to make sure"
115+
echo "that npmDepsHash doesn't change when packages are updated on npm."
116+
echo
117+
echo "Hint: You can copy a vendored package-lock.json file via postPatch."
118+
echo
119+
120+
exit 1
121+
fi
122+
123+
prefetch-npm-deps $srcLockfile $out
124+
125+
runHook postBuild
126+
'';
127+
128+
dontInstall = true;
129+
130+
impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ "NIX_NPM_TOKENS" ];
131+
132+
NIX_NPM_REGISTRY_OVERRIDES = npmRegistryOverridesString;
133+
134+
# Cache version controls which features are enabled in prefetch-npm-deps
135+
# Version 2+ enables packument fetching for workspace support
136+
NPM_CACHE_VERSION = toString cacheVersion;
137+
138+
SSL_CERT_FILE =
139+
if
140+
(
141+
hash_.outputHash == ""
142+
|| hash_.outputHash == lib.fakeSha256
143+
|| hash_.outputHash == lib.fakeSha512
144+
|| hash_.outputHash == lib.fakeHash
145+
)
146+
then
147+
"${cacert}/etc/ssl/certs/ca-bundle.crt"
148+
else
149+
"/no-cert-file.crt";
150+
151+
outputHashMode = "recursive";
152+
}
153+
// hash_
154+
// forceGitDeps_
155+
// forceEmptyCache_
156+
);
157+
in
158+
{
159+
inherit fetchNpmDepsWithPackuments npmConfigHook prefetch-npm-deps;
160+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# shellcheck shell=bash
2+
# Vendored from nixpkgs with packument support additions
3+
# SC2016: Single quotes intentional - showing Nix syntax, not shell expansion
4+
# SC2086: Word splitting intentional for npm flags
5+
# SC2154: Variables set by buildNpmPackage, not this script
6+
# SC2164: pushd/popd in build hooks - failure will fail the build anyway
7+
8+
# shellcheck disable=SC2016,SC2086,SC2154,SC2164
9+
10+
npmConfigHook() {
11+
echo "Executing npmConfigHook"
12+
13+
# Use npm patches in the nodejs package
14+
export NIX_NODEJS_BUILDNPMPACKAGE=1
15+
export prefetchNpmDeps="@prefetchNpmDeps@"
16+
17+
if [ -n "${npmRoot-}" ]; then
18+
pushd "$npmRoot"
19+
fi
20+
21+
echo "Configuring npm"
22+
23+
export HOME="$TMPDIR"
24+
export npm_config_nodedir="@nodeSrc@"
25+
export npm_config_node_gyp="@nodeGyp@"
26+
export npm_config_arch="@npmArch@"
27+
export npm_config_platform="@npmPlatform@"
28+
29+
if [ -z "${npmDeps-}" ]; then
30+
echo
31+
echo "ERROR: no dependencies were specified"
32+
echo 'Hint: set `npmDeps` if using these hooks individually. If this is happening with `buildNpmPackage`, please open an issue.'
33+
echo
34+
35+
exit 1
36+
fi
37+
38+
local -r cacheLockfile="$npmDeps/package-lock.json"
39+
if [[ -f npm-shrinkwrap.json ]]; then
40+
local -r srcLockfile="$PWD/npm-shrinkwrap.json"
41+
else
42+
local -r srcLockfile="$PWD/package-lock.json"
43+
fi
44+
45+
echo "Validating consistency between $srcLockfile and $cacheLockfile"
46+
47+
if ! @diff@ "$srcLockfile" "$cacheLockfile"; then
48+
# If the diff failed, first double-check that the file exists, so we can
49+
# give a friendlier error msg.
50+
if ! [ -e "$srcLockfile" ]; then
51+
echo
52+
echo "ERROR: Missing package-lock.json from src. Expected to find it at: $srcLockfile"
53+
echo "Hint: You can copy a vendored package-lock.json file via postPatch."
54+
echo
55+
56+
exit 1
57+
fi
58+
59+
if ! [ -e "$cacheLockfile" ]; then
60+
echo
61+
echo "ERROR: Missing lockfile from cache. Expected to find it at: $cacheLockfile"
62+
echo
63+
64+
exit 1
65+
fi
66+
67+
echo
68+
echo "ERROR: npmDepsHash is out of date"
69+
echo
70+
echo "The package-lock.json in src is not the same as the in $npmDeps."
71+
echo
72+
echo "To fix the issue:"
73+
echo '1. Use `lib.fakeHash` as the npmDepsHash value'
74+
echo "2. Build the derivation and wait for it to fail with a hash mismatch"
75+
echo "3. Copy the 'got: sha256-' value back into the npmDepsHash field"
76+
echo
77+
78+
exit 1
79+
fi
80+
81+
export CACHE_MAP_PATH="$TMP/MEOW"
82+
@prefetchNpmDeps@ --map-cache
83+
84+
@prefetchNpmDeps@ --fixup-lockfile "$srcLockfile"
85+
86+
local cachePath
87+
88+
if [ -z "${makeCacheWritable-}" ]; then
89+
cachePath="$npmDeps"
90+
else
91+
echo "Making cache writable"
92+
cp -r "$npmDeps" "$TMPDIR/cache"
93+
chmod -R 700 "$TMPDIR/cache"
94+
cachePath="$TMPDIR/cache"
95+
fi
96+
97+
echo "Setting npm_config_cache to $cachePath"
98+
# do not use npm config to avoid modifying .npmrc
99+
export npm_config_cache="$cachePath"
100+
export npm_config_offline="true"
101+
export npm_config_progress="false"
102+
103+
echo "Installing dependencies"
104+
105+
if ! npm ci --ignore-scripts $npmInstallFlags "${npmInstallFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}"; then
106+
echo
107+
echo "ERROR: npm failed to install dependencies"
108+
echo
109+
echo "Here are a few things you can try, depending on the error:"
110+
echo '1. Set `makeCacheWritable = true`'
111+
echo " Note that this won't help if npm is complaining about not being able to write to the logs directory -- look above that for the actual error."
112+
echo '2. Set `npmFlags = [ "--legacy-peer-deps" ]`'
113+
echo
114+
115+
exit 1
116+
fi
117+
118+
patchShebangs node_modules
119+
120+
npm rebuild $npmRebuildFlags "${npmRebuildFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}"
121+
122+
patchShebangs node_modules
123+
124+
rm "$CACHE_MAP_PATH"
125+
unset CACHE_MAP_PATH
126+
127+
if [ -n "${npmRoot-}" ]; then
128+
popd
129+
fi
130+
131+
echo "Finished npmConfigHook"
132+
}
133+
134+
postPatchHooks+=(npmConfigHook)

packages/qwen-code/package.nix

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,29 @@
1010
libsecret,
1111
darwinOpenptyHook,
1212
clang_20,
13+
fetchNpmDepsWithPackuments,
14+
npmConfigHook,
1315
}:
1416

1517
buildNpmPackage (finalAttrs: {
18+
inherit npmConfigHook;
1619
pname = "qwen-code";
17-
version = "0.4.0";
20+
version = "0.4.1";
1821

1922
src = fetchFromGitHub {
2023
owner = "QwenLM";
2124
repo = "qwen-code";
2225
tag = "v${finalAttrs.version}";
23-
hash = "sha256-B7dL0pWSCPwPKwwTHycgC3/qHB66AUWZc62sen7U/7c=";
26+
hash = "sha256-x0ZGeD6qb7UkENfmiF00tx4JDLJbRk46MFquPcOoQLY=";
2427
};
2528

26-
npmDepsHash = "sha256-Vz6zTdNWkM1tnDMW6wM8cRCaed1pLihX7hYB2DaVBYg=";
29+
npmDeps = fetchNpmDepsWithPackuments {
30+
inherit (finalAttrs) src;
31+
name = "${finalAttrs.pname}-${finalAttrs.version}-npm-deps";
32+
hash = "sha256-f76tY+A09Oxj/D25LKygsPdgYjp7b0RMEtMHsCvl9tY=";
33+
cacheVersion = 2;
34+
};
35+
makeCacheWritable = true;
2736

2837
nativeBuildInputs = [
2938
pkg-config

0 commit comments

Comments
 (0)