From faeab3c841ec25e2453297038ffe137868f73c10 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 6 Jul 2025 08:40:29 +0000 Subject: [PATCH] buildNpmPackage: push npm_config_* options into npmHooks.npmConfigHook these options affect npm generally, and aren't specific to our `buildNpmPackage`. pushing these options into the `npmConfigHook` (which is used by `buildNpmPackage`, among others) makes them available to more packages, especially to enable cross compilation. --- pkgs/build-support/node/build-npm-package/default.nix | 5 ----- pkgs/build-support/node/build-npm-package/hooks/default.nix | 3 +++ .../node/build-npm-package/hooks/npm-config-hook.sh | 2 ++ 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/build-support/node/build-npm-package/default.nix b/pkgs/build-support/node/build-npm-package/default.nix index fb57c0cfd0b9..747043e3d12a 100644 --- a/pkgs/build-support/node/build-npm-package/default.nix +++ b/pkgs/build-support/node/build-npm-package/default.nix @@ -103,11 +103,6 @@ lib.extendMkDerivation { # Stripping takes way too long with the amount of files required by a typical Node.js project. dontStrip = args.dontStrip or true; - env = { - npm_config_arch = stdenv.hostPlatform.node.arch; - npm_config_platform = stdenv.hostPlatform.node.platform; - } // (args.env or { }); - meta = (args.meta or { }) // { platforms = args.meta.platforms or nodejs.meta.platforms; }; diff --git a/pkgs/build-support/node/build-npm-package/hooks/default.nix b/pkgs/build-support/node/build-npm-package/hooks/default.nix index 54c9fd2a561b..a28b0fbaa379 100644 --- a/pkgs/build-support/node/build-npm-package/hooks/default.nix +++ b/pkgs/build-support/node/build-npm-package/hooks/default.nix @@ -1,6 +1,7 @@ { lib, srcOnly, + stdenv, makeSetupHook, makeWrapper, nodejs, @@ -18,6 +19,8 @@ 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; # Specify `diff`, `jq`, and `prefetch-npm-deps` by abspath to ensure that the user's build # inputs do not cause us to find the wrong binaries. diff --git a/pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh b/pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh index 6a301e715ef8..7fabd80eec1f 100644 --- a/pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh +++ b/pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh @@ -16,6 +16,8 @@ npmConfigHook() { 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