Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/qwen-code/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{ pkgs }:
let
npmPackumentSupport = pkgs.callPackage ./fetch-npm-deps.nix { };
in
pkgs.callPackage ./package.nix {
darwinOpenptyHook = pkgs.callPackage ../darwinOpenptyHook { };
inherit (npmPackumentSupport) fetchNpmDepsWithPackuments npmConfigHook;
}
160 changes: 160 additions & 0 deletions packages/qwen-code/fetch-npm-deps.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Custom fetchNpmDeps with packument caching support (cacheVersion = 2)
# This builds a vendored prefetch-npm-deps with packument fetching support,
# which is needed for npm workspace support.
# TODO: Remove this once the upstream PR is merged into nixpkgs.
{
lib,
stdenv,
stdenvNoCC,
rustPlatform,
makeSetupHook,
makeWrapper,
pkg-config,
curl,
gnutar,
gzip,
cacert,
config,
nodejs,
srcOnly,
diffutils,
jq,
}:
let
# Build prefetch-npm-deps from vendored source with packument support
prefetch-npm-deps = rustPlatform.buildRustPackage {
pname = "prefetch-npm-deps";
version = "0.1.0-packument";

src = ./prefetch-npm-deps;

cargoLock.lockFile = ./prefetch-npm-deps/Cargo.lock;

nativeBuildInputs = [
makeWrapper
pkg-config
];
buildInputs = [ curl ];

postInstall = ''
wrapProgram "$out/bin/prefetch-npm-deps" --prefix PATH : ${
lib.makeBinPath [
gnutar
gzip
]
}
'';

meta = {
description = "Prefetch dependencies from npm with packument support";
mainProgram = "prefetch-npm-deps";
license = lib.licenses.mit;
};
};

# Custom npmConfigHook that uses our patched prefetch-npm-deps
npmConfigHook = makeSetupHook {
name = "npm-config-hook-packument";
substitutions = {
nodeSrc = srcOnly nodejs;
nodeGyp = "${nodejs}/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js";
npmArch = stdenv.targetPlatform.node.arch;
npmPlatform = stdenv.targetPlatform.node.platform;
diff = "${diffutils}/bin/diff";
jq = "${jq}/bin/jq";
prefetchNpmDeps = "${prefetch-npm-deps}/bin/prefetch-npm-deps";
nodeVersion = nodejs.version;
nodeVersionMajor = lib.versions.major nodejs.version;
};
} ./npm-config-hook.sh;

fetchNpmDepsWithPackuments =
{
name ? "npm-deps",
hash ? "",
forceGitDeps ? false,
forceEmptyCache ? false,
nativeBuildInputs ? [ ],
npmRegistryOverridesString ? config.npmRegistryOverridesString or "{}",
# Cache format version. Set to 2 to enable packument caching for workspace support.
cacheVersion ? 1,
...
}@args:
let
hash_ =
if hash != "" then
{ outputHash = hash; }
else
{
outputHash = "";
outputHashAlgo = "sha256";
};

forceGitDeps_ = lib.optionalAttrs forceGitDeps { FORCE_GIT_DEPS = true; };
forceEmptyCache_ = lib.optionalAttrs forceEmptyCache { FORCE_EMPTY_CACHE = true; };
in
stdenvNoCC.mkDerivation (
args
// {
inherit name;

nativeBuildInputs = nativeBuildInputs ++ [ prefetch-npm-deps ];

buildPhase = ''
runHook preBuild

if [[ -f npm-shrinkwrap.json ]]; then
local -r srcLockfile="npm-shrinkwrap.json"
elif [[ -f package-lock.json ]]; then
local -r srcLockfile="package-lock.json"
else
echo
echo "ERROR: No lock file!"
echo
echo "package-lock.json or npm-shrinkwrap.json is required to make sure"
echo "that npmDepsHash doesn't change when packages are updated on npm."
echo
echo "Hint: You can copy a vendored package-lock.json file via postPatch."
echo

exit 1
fi

prefetch-npm-deps $srcLockfile $out

runHook postBuild
'';

dontInstall = true;

impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ "NIX_NPM_TOKENS" ];

NIX_NPM_REGISTRY_OVERRIDES = npmRegistryOverridesString;

# Cache version controls which features are enabled in prefetch-npm-deps
# Version 2+ enables packument fetching for workspace support
NPM_CACHE_VERSION = toString cacheVersion;

SSL_CERT_FILE =
if
(
hash_.outputHash == ""
|| hash_.outputHash == lib.fakeSha256
|| hash_.outputHash == lib.fakeSha512
|| hash_.outputHash == lib.fakeHash
)
then
"${cacert}/etc/ssl/certs/ca-bundle.crt"
else
"/no-cert-file.crt";

outputHashMode = "recursive";
}
// hash_
// forceGitDeps_
// forceEmptyCache_
);
in
{
inherit fetchNpmDepsWithPackuments npmConfigHook prefetch-npm-deps;
}
134 changes: 134 additions & 0 deletions packages/qwen-code/npm-config-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# shellcheck shell=bash
# Vendored from nixpkgs with packument support additions
# SC2016: Single quotes intentional - showing Nix syntax, not shell expansion
# SC2086: Word splitting intentional for npm flags
# SC2154: Variables set by buildNpmPackage, not this script
# SC2164: pushd/popd in build hooks - failure will fail the build anyway

# shellcheck disable=SC2016,SC2086,SC2154,SC2164

npmConfigHook() {
echo "Executing npmConfigHook"

# Use npm patches in the nodejs package
export NIX_NODEJS_BUILDNPMPACKAGE=1
export prefetchNpmDeps="@prefetchNpmDeps@"

if [ -n "${npmRoot-}" ]; then
pushd "$npmRoot"
fi

echo "Configuring npm"

export HOME="$TMPDIR"
export npm_config_nodedir="@nodeSrc@"
export npm_config_node_gyp="@nodeGyp@"
export npm_config_arch="@npmArch@"
export npm_config_platform="@npmPlatform@"

if [ -z "${npmDeps-}" ]; then
echo
echo "ERROR: no dependencies were specified"
echo 'Hint: set `npmDeps` if using these hooks individually. If this is happening with `buildNpmPackage`, please open an issue.'
echo

exit 1
fi

local -r cacheLockfile="$npmDeps/package-lock.json"
if [[ -f npm-shrinkwrap.json ]]; then
local -r srcLockfile="$PWD/npm-shrinkwrap.json"
else
local -r srcLockfile="$PWD/package-lock.json"
fi

echo "Validating consistency between $srcLockfile and $cacheLockfile"

if ! @diff@ "$srcLockfile" "$cacheLockfile"; then
# If the diff failed, first double-check that the file exists, so we can
# give a friendlier error msg.
if ! [ -e "$srcLockfile" ]; then
echo
echo "ERROR: Missing package-lock.json from src. Expected to find it at: $srcLockfile"
echo "Hint: You can copy a vendored package-lock.json file via postPatch."
echo

exit 1
fi

if ! [ -e "$cacheLockfile" ]; then
echo
echo "ERROR: Missing lockfile from cache. Expected to find it at: $cacheLockfile"
echo

exit 1
fi

echo
echo "ERROR: npmDepsHash is out of date"
echo
echo "The package-lock.json in src is not the same as the in $npmDeps."
echo
echo "To fix the issue:"
echo '1. Use `lib.fakeHash` as the npmDepsHash value'
echo "2. Build the derivation and wait for it to fail with a hash mismatch"
echo "3. Copy the 'got: sha256-' value back into the npmDepsHash field"
echo

exit 1
fi

export CACHE_MAP_PATH="$TMP/MEOW"
@prefetchNpmDeps@ --map-cache

@prefetchNpmDeps@ --fixup-lockfile "$srcLockfile"

local cachePath

if [ -z "${makeCacheWritable-}" ]; then
cachePath="$npmDeps"
else
echo "Making cache writable"
cp -r "$npmDeps" "$TMPDIR/cache"
chmod -R 700 "$TMPDIR/cache"
cachePath="$TMPDIR/cache"
fi

echo "Setting npm_config_cache to $cachePath"
# do not use npm config to avoid modifying .npmrc
export npm_config_cache="$cachePath"
export npm_config_offline="true"
export npm_config_progress="false"

echo "Installing dependencies"

if ! npm ci --ignore-scripts $npmInstallFlags "${npmInstallFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}"; then
echo
echo "ERROR: npm failed to install dependencies"
echo
echo "Here are a few things you can try, depending on the error:"
echo '1. Set `makeCacheWritable = true`'
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."
echo '2. Set `npmFlags = [ "--legacy-peer-deps" ]`'
echo

exit 1
fi

patchShebangs node_modules

npm rebuild $npmRebuildFlags "${npmRebuildFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}"

patchShebangs node_modules

rm "$CACHE_MAP_PATH"
unset CACHE_MAP_PATH

if [ -n "${npmRoot-}" ]; then
popd
fi

echo "Finished npmConfigHook"
}

postPatchHooks+=(npmConfigHook)
15 changes: 12 additions & 3 deletions packages/qwen-code/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,29 @@
libsecret,
darwinOpenptyHook,
clang_20,
fetchNpmDepsWithPackuments,
npmConfigHook,
}:

buildNpmPackage (finalAttrs: {
inherit npmConfigHook;
pname = "qwen-code";
version = "0.4.0";
version = "0.4.1";

src = fetchFromGitHub {
owner = "QwenLM";
repo = "qwen-code";
tag = "v${finalAttrs.version}";
hash = "sha256-B7dL0pWSCPwPKwwTHycgC3/qHB66AUWZc62sen7U/7c=";
hash = "sha256-x0ZGeD6qb7UkENfmiF00tx4JDLJbRk46MFquPcOoQLY=";
};

npmDepsHash = "sha256-Vz6zTdNWkM1tnDMW6wM8cRCaed1pLihX7hYB2DaVBYg=";
npmDeps = fetchNpmDepsWithPackuments {
inherit (finalAttrs) src;
name = "${finalAttrs.pname}-${finalAttrs.version}-npm-deps";
hash = "sha256-f76tY+A09Oxj/D25LKygsPdgYjp7b0RMEtMHsCvl9tY=";
cacheVersion = 2;
};
makeCacheWritable = true;

nativeBuildInputs = [
pkg-config
Expand Down
Loading