···
1
-
{ lib, stdenv, fetchurl, openssl, python, zlib, libuv, util-linux, http-parser, bash
1
+
{ lib, stdenv, fetchurl, openssl, python, zlib, libuv, http-parser, icu, bash
, pkg-config, which, buildPackages
···
, writeScript, coreutils, gnugrep, jq, curl, common-updater-scripts, nix, runtimeShell
···
inherit (darwin.apple_sdk.frameworks) CoreServices ApplicationServices;
19
-
isCross = stdenv.hostPlatform != stdenv.buildPlatform;
majorVersion = lib.versions.major version;
minorVersion = lib.versions.minor version;
pname = if enableNpm then "nodejs" else "nodejs-slim";
23
+
canExecute = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
24
+
emulator = stdenv.hostPlatform.emulator buildPackages;
26
+
# See valid_os and valid_arch in configure.py.
29
+
platform = stdenv.hostPlatform;
31
+
if platform.isiOS then
33
+
else if platform.isAndroid then
35
+
else if platform.isWindows then
37
+
else if platform.isDarwin then
39
+
else if platform.isLinux then
41
+
else if platform.isOpenBSD then
43
+
else if platform.isFreeBSD then
46
+
throw "unsupported os ${platform.uname.system}";
49
+
platform = stdenv.hostPlatform;
51
+
if platform.isAarch then
52
+
"arm" + lib.optionalString platform.is64bit "64"
53
+
else if platform.isMips32 then
54
+
"mips" + lib.optionalString platform.isLittleEndian "le"
55
+
else if platform.isMips64 && platform.isLittleEndian then
57
+
else if platform.isPower then
58
+
"ppc" + lib.optionalString platform.is64bit "64"
59
+
else if platform.isx86_64 then
61
+
else if platform.isx86_32 then
63
+
else if platform.isS390x then
65
+
else if platform.isRiscV64 then
67
+
else if platform.isLoongArch64 then
70
+
throw "unsupported cpu ${platform.uname.processor}";
73
+
platform = stdenv.hostPlatform;
75
+
if platform.isAarch32 && platform ? gcc.fpu then
76
+
lib.throwIfNot (builtins.elem platform.gcc.fpu [
81
+
]) "unsupported ARM FPU ${platform.gcc.fpu}" platform.gcc.fpu
86
+
platform = stdenv.hostPlatform;
88
+
if platform.isAarch32 && platform ? gcc.float-abi then
89
+
lib.throwIfNot (builtins.elem platform.gcc.float-abi [
93
+
]) "unsupported ARM float ABI ${platform.gcc.float-abi}" platform.gcc.float-abi
96
+
# TODO: also handle MIPS flags (mips_arch, mips_fpu, mips_float_abi).
useSharedHttpParser = !stdenv.isDarwin && lib.versionOlder "${majorVersion}.${minorVersion}" "11.4";
sharedLibDeps = { inherit openssl zlib libuv; } // (lib.optionalAttrs useSharedHttpParser { inherit http-parser; });
30
-
sharedConfigureFlags = lib.concatMap (name: [
32
-
"--shared-${name}-libpath=${lib.getLib sharedLibDeps.${name}}/lib"
33
-
/** Closure notes: we explicitly avoid specifying --shared-*-includes,
34
-
* as that would put the paths into bin/nodejs.
35
-
* Including pkg-config in build inputs would also have the same effect!
37
-
]) (builtins.attrNames sharedLibDeps) ++ [
38
-
"--with-intl=system-icu"
39
-
"--openssl-use-def-ca-store"
(name: "${lib.getDev sharedLibDeps.${name}}/include/*")
(builtins.attrNames sharedLibDeps);
47
-
extraConfigFlags = lib.optionals (!enableNpm) [ "--without-npm" ];
package = stdenv.mkDerivation (finalAttrs:
···
# Otherwise, nodejs would require the 11.0 SDK and macOS 10.15+.
NIX_CFLAGS_COMPILE = "-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=101300";
70
-
depsBuildBuild = [ buildPackages.stdenv.cc openssl libuv zlib icu ];
# NB: technically, we do not need bash in build inputs since all scripts are
# wrappers over the corresponding JS scripts. There are some packages though
···
85
-
configureFlags = let
86
-
inherit (stdenv.hostPlatform) gcc isAarch32;
87
-
in sharedConfigureFlags ++ lib.optionals (lib.versionOlder version "19") [
89
-
] ++ (lib.optionals isCross [
91
-
"--dest-cpu=${let platform = stdenv.hostPlatform; in
92
-
if platform.isAarch32 then "arm"
93
-
else if platform.isAarch64 then "arm64"
94
-
else if platform.isMips32 && platform.isLittleEndian then "mipsel"
95
-
else if platform.isMips32 && !platform.isLittleEndian then "mips"
96
-
else if platform.isMips64 && platform.isLittleEndian then "mips64el"
97
-
else if platform.isPower && platform.is32bit then "ppc"
98
-
else if platform.isPower && platform.is64bit then "ppc64"
99
-
else if platform.isx86_64 then "x86_64"
100
-
else if platform.isx86_32 then "x86"
101
-
else if platform.isS390 && platform.is64bit then "s390x"
102
-
else if platform.isRiscV && platform.is64bit then "riscv64"
103
-
else throw "unsupported cpu ${stdenv.hostPlatform.uname.processor}"}"
104
-
]) ++ (lib.optionals (isCross && isAarch32 && lib.hasAttr "fpu" gcc) [
105
-
"--with-arm-fpu=${gcc.fpu}"
106
-
]) ++ (lib.optionals (isCross && isAarch32 && lib.hasAttr "float-abi" gcc) [
107
-
"--with-arm-float-abi=${gcc.float-abi}"
108
-
]) ++ extraConfigFlags;
143
+
"--no-cross-compiling"
144
+
"--dest-os=${destOS}"
145
+
"--dest-cpu=${destCPU}"
147
+
++ lib.optionals (destARMFPU != null) [ "--with-arm-fpu=${destARMFPU}" ]
148
+
++ lib.optionals (destARMFloatABI != null) [ "--with-arm-float-abi=${destARMFloatABI}" ]
149
+
++ lib.optionals (!canExecute) [
150
+
# Node.js requires matching bitness between build and host platforms, e.g.
151
+
# for V8 startup snapshot builder (see tools/snapshot) and some other
152
+
# tools. We apply a patch that runs these tools using a host platform
153
+
# emulator and avoid cross-compiling altogether (from the build system’s
155
+
"--emulator=${emulator}"
157
+
++ lib.optionals (lib.versionOlder version "19") [ "--without-dtrace" ]
158
+
++ lib.optionals (!enableNpm) [ "--without-npm" ]
159
+
++ lib.concatMap (name: [
161
+
"--shared-${name}-libpath=${lib.getLib sharedLibDeps.${name}}/lib"
163
+
Closure notes: we explicitly avoid specifying --shared-*-includes,
164
+
as that would put the paths into bin/nodejs.
165
+
Including pkg-config in build inputs would also have the same effect!
167
+
FIXME: the statement above is outdated, we have to include pkg-config
168
+
in build inputs for system-icu.
170
+
]) (builtins.attrNames sharedLibDeps)
172
+
"--with-intl=system-icu"
173
+
"--openssl-use-def-ca-store"
110
-
configurePlatforms = [];
176
+
configurePlatforms = [ ];
dontDisableStatic = true;
configureScript = writeScript "nodejs-configure" ''
115
-
export CC_host="$CC_FOR_BUILD" CXX_host="$CXX_FOR_BUILD"
exec ${python.executable} configure.py "$@"
···
__darwinAllowLocalNetworking = true; # for tests
143
-
# TODO: what about tests when cross-compiling?
144
-
# Note that currently stdenv does not run check phase if build ≠ host.
208
+
doCheck = canExecute;
# Some dependencies required for tools/doc/node_modules (and therefore
# test-addons, jstest and others) target are not included in the tarball.
···
HOST_PATH=$out/bin patchShebangs --host $out
216
-
${lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
217
-
$out/bin/${self.meta.mainProgram} --completion-bash > ${self.meta.mainProgram}.bash
218
-
installShellCompletion ${self.meta.mainProgram}.bash
279
+
${lib.optionalString canExecute ''
280
+
$out/bin/node --completion-bash > node.bash
281
+
installShellCompletion node.bash
221
-
${lib.optionalString (enableNpm) ''
284
+
${lib.optionalString enableNpm ''
mkdir -p $out/share/bash-completion/completions
ln -s $out/lib/node_modules/npm/lib/utils/completion.sh \
$out/share/bash-completion/completions/npm
···
# install the missing headers for node-gyp
297
+
# TODO: add dev output and use propagatedBuildInputs instead of copying headers.
cp -r ${lib.concatStringsSep " " copyLibHeaders} $out/include/node
# assemble a static v8 library and put it in the 'libv8' output
pushd out/Release/obj.target
find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" | sort -u >files
240
-
${if stdenv.buildPlatform.isGnu then ''
241
-
ar -cqs $libv8/lib/libv8.a @files
243
-
# llvm-ar supports response files, so take advantage of it if it’s available.
244
-
if [ "$(basename $(readlink -f $(command -v ar)))" = "llvm-ar" ]; then
245
-
ar -cqs $libv8/lib/libv8.a @files
247
-
cat files | while read -r file; do
248
-
ar -cqS $libv8/lib/libv8.a $file
304
+
$AR -cqs $libv8/lib/libv8.a @files
···
platforms = platforms.linux ++ platforms.darwin;
knownVulnerabilities = optional (versionOlder version "18") "This NodeJS release has reached its end of life. See https://nodejs.org/en/about/releases/.";
294
-
# Node.js build system does not have separate host and target OS
295
-
# configurations (architectures are defined as host_arch and target_arch,
296
-
# but there is no such thing as host_os and target_os).
298
-
# We may be missing something here, but it doesn’t look like it is
299
-
# possible to cross-compile between different operating systems.
300
-
broken = stdenv.buildPlatform.parsed.kernel.name != stdenv.hostPlatform.parsed.kernel.name;
passthru.python = python; # to ensure nodeEnv uses the same version