treewide: populate `arch` and `platform` for more node packages (#422938)

Changed files
+62 -61
lib
systems
pkgs
build-support
node
build-npm-package
by-name
af
affine
affine-bin
el
element-desktop
keytar
development
tools
web
nodejs
+45
lib/systems/default.nix
···
# See https://go.dev/wiki/GoArm
GOARM = toString (lib.intersectLists [ (final.parsed.cpu.version or "") ] [ "5" "6" "7" ]);
};
+
+
node = {
+
# See these locations for a list of known architectures/platforms:
+
# - https://nodejs.org/api/os.html#osarch
+
# - https://nodejs.org/api/os.html#osplatform
+
arch =
+
if final.isAarch then
+
"arm" + lib.optionalString final.is64bit "64"
+
else if final.isMips32 then
+
"mips" + lib.optionalString final.isLittleEndian "el"
+
else if final.isMips64 && final.isLittleEndian then
+
"mips64el"
+
else if final.isPower then
+
"ppc" + lib.optionalString final.is64bit "64"
+
else if final.isx86_64 then
+
"x64"
+
else if final.isx86_32 then
+
"ia32"
+
else if final.isS390x then
+
"s390x"
+
else if final.isRiscV64 then
+
"riscv64"
+
else if final.isLoongArch64 then
+
"loong64"
+
else
+
null;
+
+
platform =
+
if final.isAndroid then
+
"android"
+
else if final.isDarwin then
+
"darwin"
+
else if final.isFreeBSD then
+
"freebsd"
+
else if final.isLinux then
+
"linux"
+
else if final.isOpenBSD then
+
"openbsd"
+
else if final.isSunOS then
+
"sunos"
+
else if final.isWindows then
+
"win32"
+
else
+
null;
+
};
};
in
assert final.useAndroidPrebuilt -> final.isAndroid;
-10
pkgs/build-support/node/build-npm-package/default.nix
···
# 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 =
-
{
-
"x86_64" = "x64";
-
"aarch64" = "arm64";
-
}
-
.${stdenv.hostPlatform.parsed.cpu.name} or stdenv.hostPlatform.parsed.cpu.name;
-
npm_config_platform = stdenv.hostPlatform.parsed.kernel.name;
-
} // (args.env or { });
-
meta = (args.meta or { }) // {
platforms = args.meta.platforms or nodejs.meta.platforms;
};
+3
pkgs/build-support/node/build-npm-package/hooks/default.nix
···
{
lib,
srcOnly,
+
stdenv,
makeSetupHook,
makeWrapper,
nodejs,
···
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.
+2
pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh
···
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
+2 -8
pkgs/by-name/af/affine-bin/package.nix
···
}:
let
hostPlatform = stdenvNoCC.hostPlatform;
-
nodePlatform = hostPlatform.parsed.kernel.name; # nodejs's `process.platform`
-
nodeArch = # nodejs's `process.arch`
-
{
-
"x86_64" = "x64";
-
"aarch64" = "arm64";
-
}
-
.${hostPlatform.parsed.cpu.name}
-
or (throw "affine-bin(${buildType}): unsupported CPU family ${hostPlatform.parsed.cpu.name}");
+
nodePlatform = hostPlatform.node.platform;
+
nodeArch = hostPlatform.node.arch;
in
stdenvNoCC.mkDerivation (
finalAttrs:
+2 -8
pkgs/by-name/af/affine/package.nix
···
}:
let
hostPlatform = stdenvNoCC.hostPlatform;
-
nodePlatform = hostPlatform.parsed.kernel.name; # nodejs's `process.platform`
-
nodeArch = # nodejs's `process.arch`
-
{
-
"x86_64" = "x64";
-
"aarch64" = "arm64";
-
}
-
.${hostPlatform.parsed.cpu.name}
-
or (throw "affine(${buildType}): unsupported CPU family ${hostPlatform.parsed.cpu.name}");
+
nodePlatform = hostPlatform.node.platform;
+
nodeArch = hostPlatform.node.arch;
electron = electron_35;
nodejs = nodejs_22;
yarn-berry = yarn-berry_4.override { inherit nodejs; };
+1 -10
pkgs/by-name/el/element-desktop/keytar/default.nix
···
# Make sure the native modules are built against electron's ABI
"--nodedir=${electron.headers}"
# https://nodejs.org/api/os.html#osarch
-
"--arch=${
-
if stdenv.hostPlatform.parsed.cpu.name == "i686" then
-
"ia32"
-
else if stdenv.hostPlatform.parsed.cpu.name == "x86_64" then
-
"x64"
-
else if stdenv.hostPlatform.parsed.cpu.name == "aarch64" then
-
"arm64"
-
else
-
stdenv.hostPlatform.parsed.cpu.name
-
}"
+
"--arch=${stdenv.hostPlatform.node.arch}"
];
installPhase = ''
+4
pkgs/development/tools/pnpm/fetch-deps/default.nix
···
configHook = makeSetupHook {
name = "pnpm-config-hook";
propagatedBuildInputs = [ pnpm ];
+
substitutions = {
+
npmArch = stdenvNoCC.targetPlatform.node.arch;
+
npmPlatform = stdenvNoCC.targetPlatform.node.platform;
+
};
} ./pnpm-config-hook.sh;
}
+2
pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh
···
export HOME=$(mktemp -d)
export STORE_PATH=$(mktemp -d)
+
export npm_config_arch="@npmArch@"
+
export npm_config_platform="@npmPlatform@"
cp -Tr "$pnpmDeps" "$STORE_PATH"
chmod -R +w "$STORE_PATH"
+1 -25
pkgs/development/web/nodejs/nodejs.nix
···
"freebsd"
else
throw "unsupported os ${platform.uname.system}";
-
destCPU =
-
let
-
platform = stdenv.hostPlatform;
-
in
-
if platform.isAarch then
-
"arm" + lib.optionalString platform.is64bit "64"
-
else if platform.isMips32 then
-
"mips" + lib.optionalString platform.isLittleEndian "le"
-
else if platform.isMips64 && platform.isLittleEndian then
-
"mips64el"
-
else if platform.isPower then
-
"ppc" + lib.optionalString platform.is64bit "64"
-
else if platform.isx86_64 then
-
"x64"
-
else if platform.isx86_32 then
-
"ia32"
-
else if platform.isS390x then
-
"s390x"
-
else if platform.isRiscV64 then
-
"riscv64"
-
else if platform.isLoongArch64 then
-
"loong64"
-
else
-
throw "unsupported cpu ${platform.uname.processor}";
destARMFPU =
let
platform = stdenv.hostPlatform;
···
# --cross-compiling flag enables use of CC_host et. al
(if canExecute || canEmulate then "--no-cross-compiling" else "--cross-compiling")
"--dest-os=${destOS}"
-
"--dest-cpu=${destCPU}"
+
"--dest-cpu=${stdenv.hostPlatform.node.arch}"
]
++ lib.optionals (destARMFPU != null) [ "--with-arm-fpu=${destARMFPU}" ]
++ lib.optionals (destARMFloatABI != null) [ "--with-arm-float-abi=${destARMFloatABI}" ]