2023-07-18 15:47:45 +00:00
|
|
|
|
{ lib, stdenv, fetchurl, openssl, python, zlib, libuv, util-linux, http-parser, bash
|
2021-11-29 02:14:55 +00:00
|
|
|
|
, pkg-config, which, buildPackages
|
2021-10-14 06:03:13 +00:00
|
|
|
|
# for `.pkgs` attribute
|
|
|
|
|
, callPackage
|
2018-02-18 14:19:01 +00:00
|
|
|
|
# Updater dependencies
|
2019-02-28 06:33:17 +00:00
|
|
|
|
, writeScript, coreutils, gnugrep, jq, curl, common-updater-scripts, nix, runtimeShell
|
2018-02-18 14:19:01 +00:00
|
|
|
|
, gnupg
|
2018-08-15 22:35:56 +00:00
|
|
|
|
, darwin, xcbuild
|
2019-06-02 00:14:59 +00:00
|
|
|
|
, procps, icu
|
2016-04-25 14:10:10 +00:00
|
|
|
|
}:
|
|
|
|
|
|
2018-08-15 22:35:56 +00:00
|
|
|
|
{ enableNpm ? true, version, sha256, patches ? [] } @args:
|
2017-11-01 00:25:13 +00:00
|
|
|
|
|
2016-04-25 14:10:10 +00:00
|
|
|
|
let
|
2016-11-02 16:46:01 +00:00
|
|
|
|
inherit (darwin.apple_sdk.frameworks) CoreServices ApplicationServices;
|
2016-04-25 14:10:10 +00:00
|
|
|
|
|
2023-06-17 15:46:53 +00:00
|
|
|
|
isCross = stdenv.hostPlatform != stdenv.buildPlatform;
|
|
|
|
|
|
2023-01-26 17:31:02 +00:00
|
|
|
|
majorVersion = lib.versions.major version;
|
|
|
|
|
minorVersion = lib.versions.minor version;
|
2018-10-23 19:22:50 +00:00
|
|
|
|
|
2022-01-23 12:53:27 +00:00
|
|
|
|
pname = if enableNpm then "nodejs" else "nodejs-slim";
|
2017-11-01 00:25:13 +00:00
|
|
|
|
|
2023-01-26 17:31:02 +00:00
|
|
|
|
useSharedHttpParser = !stdenv.isDarwin && lib.versionOlder "${majorVersion}.${minorVersion}" "11.4";
|
2018-10-23 19:22:50 +00:00
|
|
|
|
|
2023-01-26 17:31:02 +00:00
|
|
|
|
sharedLibDeps = { inherit openssl zlib libuv; } // (lib.optionalAttrs useSharedHttpParser { inherit http-parser; });
|
2016-11-02 16:46:01 +00:00
|
|
|
|
|
2023-01-26 17:31:02 +00:00
|
|
|
|
sharedConfigureFlags = lib.concatMap (name: [
|
2016-04-25 14:10:10 +00:00
|
|
|
|
"--shared-${name}"
|
2023-01-26 17:31:02 +00:00
|
|
|
|
"--shared-${name}-libpath=${lib.getLib sharedLibDeps.${name}}/lib"
|
2016-11-02 16:49:19 +00:00
|
|
|
|
/** Closure notes: we explicitly avoid specifying --shared-*-includes,
|
|
|
|
|
* as that would put the paths into bin/nodejs.
|
2021-01-19 06:50:56 +00:00
|
|
|
|
* Including pkg-config in build inputs would also have the same effect!
|
2016-11-02 16:49:19 +00:00
|
|
|
|
*/
|
2019-06-02 00:14:59 +00:00
|
|
|
|
]) (builtins.attrNames sharedLibDeps) ++ [
|
|
|
|
|
"--with-intl=system-icu"
|
2023-09-22 20:42:25 +00:00
|
|
|
|
"--openssl-use-def-ca-store"
|
2019-06-02 00:14:59 +00:00
|
|
|
|
];
|
2016-04-25 14:10:10 +00:00
|
|
|
|
|
2018-02-27 13:26:16 +00:00
|
|
|
|
copyLibHeaders =
|
|
|
|
|
map
|
2023-01-26 17:31:02 +00:00
|
|
|
|
(name: "${lib.getDev sharedLibDeps.${name}}/include/*")
|
2018-02-27 13:26:16 +00:00
|
|
|
|
(builtins.attrNames sharedLibDeps);
|
|
|
|
|
|
2023-01-26 17:31:02 +00:00
|
|
|
|
extraConfigFlags = lib.optionals (!enableNpm) [ "--without-npm" ];
|
2021-10-14 06:03:13 +00:00
|
|
|
|
self = stdenv.mkDerivation {
|
2022-01-23 12:53:27 +00:00
|
|
|
|
inherit pname version;
|
2017-11-01 00:25:13 +00:00
|
|
|
|
|
|
|
|
|
src = fetchurl {
|
2018-09-11 03:28:05 +00:00
|
|
|
|
url = "https://nodejs.org/dist/v${version}/node-v${version}.tar.xz";
|
2017-11-01 00:25:13 +00:00
|
|
|
|
inherit sha256;
|
|
|
|
|
};
|
2016-04-25 14:10:10 +00:00
|
|
|
|
|
2023-07-18 15:47:45 +00:00
|
|
|
|
strictDeps = true;
|
|
|
|
|
|
2023-07-16 02:29:42 +00:00
|
|
|
|
env = lib.optionalAttrs (stdenv.isDarwin && stdenv.isx86_64) {
|
|
|
|
|
# Make sure libc++ uses `posix_memalign` instead of `aligned_alloc` on x86_64-darwin.
|
|
|
|
|
# Otherwise, nodejs would require the 11.0 SDK and macOS 10.15+.
|
|
|
|
|
NIX_CFLAGS_COMPILE = "-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=101300";
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-29 02:14:55 +00:00
|
|
|
|
CC_host = "cc";
|
|
|
|
|
CXX_host = "c++";
|
2023-06-19 02:42:58 +00:00
|
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc openssl libuv zlib icu ];
|
2021-11-29 02:14:55 +00:00
|
|
|
|
|
2023-07-18 15:47:45 +00:00
|
|
|
|
# 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
|
|
|
|
|
# that use bash wrappers, e.g. polaris-web.
|
2023-01-26 17:31:02 +00:00
|
|
|
|
buildInputs = lib.optionals stdenv.isDarwin [ CoreServices ApplicationServices ]
|
2023-07-18 15:47:45 +00:00
|
|
|
|
++ [ zlib libuv openssl http-parser icu bash ];
|
2018-08-15 22:35:56 +00:00
|
|
|
|
|
2021-02-13 19:18:49 +00:00
|
|
|
|
nativeBuildInputs = [ which pkg-config python ]
|
2023-01-26 17:31:02 +00:00
|
|
|
|
++ lib.optionals stdenv.isDarwin [ xcbuild ];
|
2016-04-25 14:10:10 +00:00
|
|
|
|
|
2021-11-26 12:39:50 +00:00
|
|
|
|
outputs = [ "out" "libv8" ];
|
|
|
|
|
setOutputFlags = false;
|
|
|
|
|
moveToDev = false;
|
|
|
|
|
|
2019-03-16 15:43:20 +00:00
|
|
|
|
configureFlags = let
|
2021-03-05 01:24:27 +00:00
|
|
|
|
inherit (stdenv.hostPlatform) gcc isAarch32;
|
2023-01-26 17:31:02 +00:00
|
|
|
|
in sharedConfigureFlags ++ lib.optionals (lib.versionOlder version "19") [
|
2019-03-16 15:43:20 +00:00
|
|
|
|
"--without-dtrace"
|
2023-01-26 17:31:02 +00:00
|
|
|
|
] ++ (lib.optionals isCross [
|
2019-03-16 15:43:20 +00:00
|
|
|
|
"--cross-compiling"
|
2021-11-29 02:14:55 +00:00
|
|
|
|
"--dest-cpu=${let platform = stdenv.hostPlatform; in
|
|
|
|
|
if platform.isAarch32 then "arm"
|
|
|
|
|
else if platform.isAarch64 then "arm64"
|
|
|
|
|
else if platform.isMips32 && platform.isLittleEndian then "mipsel"
|
|
|
|
|
else if platform.isMips32 && !platform.isLittleEndian then "mips"
|
|
|
|
|
else if platform.isMips64 && platform.isLittleEndian then "mips64el"
|
|
|
|
|
else if platform.isPower && platform.is32bit then "ppc"
|
|
|
|
|
else if platform.isPower && platform.is64bit then "ppc64"
|
|
|
|
|
else if platform.isx86_64 then "x86_64"
|
|
|
|
|
else if platform.isx86_32 then "x86"
|
|
|
|
|
else if platform.isS390 && platform.is64bit then "s390x"
|
|
|
|
|
else if platform.isRiscV && platform.is64bit then "riscv64"
|
|
|
|
|
else throw "unsupported cpu ${stdenv.hostPlatform.uname.processor}"}"
|
2023-01-26 17:31:02 +00:00
|
|
|
|
]) ++ (lib.optionals (isCross && isAarch32 && lib.hasAttr "fpu" gcc) [
|
2021-01-23 01:33:55 +00:00
|
|
|
|
"--with-arm-fpu=${gcc.fpu}"
|
2023-01-26 17:31:02 +00:00
|
|
|
|
]) ++ (lib.optionals (isCross && isAarch32 && lib.hasAttr "float-abi" gcc) [
|
2021-01-23 01:33:55 +00:00
|
|
|
|
"--with-arm-float-abi=${gcc.float-abi}"
|
2019-03-16 15:43:20 +00:00
|
|
|
|
]) ++ extraConfigFlags;
|
|
|
|
|
|
|
|
|
|
configurePlatforms = [];
|
2016-04-25 14:10:10 +00:00
|
|
|
|
|
2016-11-02 16:46:01 +00:00
|
|
|
|
dontDisableStatic = true;
|
2016-04-25 14:10:10 +00:00
|
|
|
|
|
2016-11-02 16:46:01 +00:00
|
|
|
|
enableParallelBuilding = true;
|
2016-08-08 20:14:01 +00:00
|
|
|
|
|
nodejs: explicitly disable __contentAddressed
Without the change attempt to enable content addressing on nodejs
breaks the `nodejs` binary:
$ nix build -f. nodejs --arg config '{ contentAddressedByDefault = true; }'
$ LANG=C ./result/bin/node
#
# Fatal error in , line 0
# Check failed: VerifyChecksum(blob).
#
#
#
#FailureMessage Object: 0x7ffce2820790
1: 0xb2a2c5 [./result/bin/node]
2: 0x1866d9a V8_Fatal(char const*, ...) [./result/bin/node]
3: 0x12d7473 v8::internal::Snapshot::Initialize(v8::internal::Isolate*) [./result/bin/node]
4: 0xce85e6 v8::Isolate::Initialize(v8::Isolate*, v8::Isolate::CreateParams const&) [./result/bin/node]
5: 0x9e0614 node::NewIsolate(v8::Isolate::CreateParams*, uv_loop_s*, node::MultiIsolatePlatform*, bool) [./result/bin/node]
6: 0xafdcb2 node::NodeMainInstance::NodeMainInstance(node::SnapshotData const*, uv_loop_s*, node::MultiIsolatePlatform*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) [./result/bin/node]
7: 0xa670a3 node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResult const*) [./result/bin/node]
8: 0xa6ac9c node::Start(int, char**) [./result/bin/node]
9: 0x7f2b7002924e [/nix/store/h9w6fix9k2lrbc05p4a6inw2r9sywlb1-glibc-2.35-224/lib/libc.so.6]
10: 0x7f2b70029309 __libc_start_main [/nix/store/h9w6fix9k2lrbc05p4a6inw2r9sywlb1-glibc-2.35-224/lib/libc.so.6]
11: 0x9da7f5 _start [./result/bin/node]
Trace/breakpoint trap (core dumped)
Let's override the default by always disable content addressing.
2023-04-08 06:52:26 +00:00
|
|
|
|
# Don't allow enabling content addressed conversion as `nodejs`
|
|
|
|
|
# checksums it's image before conversion happens and image loading
|
|
|
|
|
# breaks:
|
|
|
|
|
# $ nix build -f. nodejs --arg config '{ contentAddressedByDefault = true; }'
|
|
|
|
|
# $ ./result/bin/node
|
|
|
|
|
# Check failed: VerifyChecksum(blob).
|
|
|
|
|
__contentAddressed = false;
|
|
|
|
|
|
2016-11-02 16:46:01 +00:00
|
|
|
|
passthru.interpreterName = "nodejs";
|
2016-04-25 14:10:10 +00:00
|
|
|
|
|
2021-10-14 06:03:13 +00:00
|
|
|
|
passthru.pkgs = callPackage ../../node-packages/default.nix {
|
|
|
|
|
nodejs = self;
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-02 16:46:01 +00:00
|
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
|
|
2018-02-18 14:06:12 +00:00
|
|
|
|
pos = builtins.unsafeGetAttrPos "version" args;
|
|
|
|
|
|
2017-11-01 00:25:13 +00:00
|
|
|
|
inherit patches;
|
2016-11-02 16:46:01 +00:00
|
|
|
|
|
2023-06-17 21:25:26 +00:00
|
|
|
|
doCheck = lib.versionAtLeast version "16"; # some tests fail on v14
|
|
|
|
|
|
|
|
|
|
# Some dependencies required for tools/doc/node_modules (and therefore
|
|
|
|
|
# test-addons, jstest and others) target are not included in the tarball.
|
|
|
|
|
# Run test targets that do not require network access.
|
|
|
|
|
checkTarget = lib.concatStringsSep " " [
|
|
|
|
|
"build-js-native-api-tests"
|
|
|
|
|
"build-node-api-tests"
|
|
|
|
|
"tooltest"
|
|
|
|
|
"cctest"
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
# Do not create __pycache__ when running tests.
|
|
|
|
|
checkFlags = [ "PYTHONDONTWRITEBYTECODE=1" ];
|
2018-08-08 21:17:04 +00:00
|
|
|
|
|
2016-11-02 16:46:01 +00:00
|
|
|
|
postInstall = ''
|
2023-06-17 22:20:53 +00:00
|
|
|
|
HOST_PATH=$out/bin patchShebangs --host $out
|
2016-12-11 13:57:49 +00:00
|
|
|
|
|
2023-06-17 16:08:10 +00:00
|
|
|
|
${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
|
2019-02-23 01:57:29 +00:00
|
|
|
|
for dir in "$out/lib/node_modules/npm/man/"*; do
|
|
|
|
|
mkdir -p $out/share/man/$(basename "$dir")
|
|
|
|
|
for page in "$dir"/*; do
|
|
|
|
|
ln -rs $page $out/share/man/$(basename "$dir")
|
|
|
|
|
done
|
|
|
|
|
done
|
2016-12-11 13:57:49 +00:00
|
|
|
|
''}
|
2018-02-27 13:26:16 +00:00
|
|
|
|
|
|
|
|
|
# install the missing headers for node-gyp
|
2023-01-26 17:31:02 +00:00
|
|
|
|
cp -r ${lib.concatStringsSep " " copyLibHeaders} $out/include/node
|
2021-11-26 12:39:50 +00:00
|
|
|
|
|
|
|
|
|
# assemble a static v8 library and put it in the 'libv8' output
|
|
|
|
|
mkdir -p $libv8/lib
|
|
|
|
|
pushd out/Release/obj.target
|
|
|
|
|
find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" | sort -u >files
|
|
|
|
|
${if stdenv.buildPlatform.isGnu then ''
|
|
|
|
|
ar -cqs $libv8/lib/libv8.a @files
|
|
|
|
|
'' else ''
|
2023-07-15 16:58:26 +00:00
|
|
|
|
# llvm-ar supports response files, so take advantage of it if it’s available.
|
|
|
|
|
if [ "$(basename $(readlink -f $(command -v ar)))" = "llvm-ar" ]; then
|
|
|
|
|
ar -cqs $libv8/lib/libv8.a @files
|
|
|
|
|
else
|
|
|
|
|
cat files | while read -r file; do
|
|
|
|
|
ar -cqS $libv8/lib/libv8.a $file
|
|
|
|
|
done
|
|
|
|
|
fi
|
2021-11-26 12:39:50 +00:00
|
|
|
|
''}
|
|
|
|
|
popd
|
|
|
|
|
|
|
|
|
|
# copy v8 headers
|
|
|
|
|
cp -r deps/v8/include $libv8/
|
|
|
|
|
|
|
|
|
|
# create a pkgconfig file for v8
|
|
|
|
|
major=$(grep V8_MAJOR_VERSION deps/v8/include/v8-version.h | cut -d ' ' -f 3)
|
|
|
|
|
minor=$(grep V8_MINOR_VERSION deps/v8/include/v8-version.h | cut -d ' ' -f 3)
|
|
|
|
|
patch=$(grep V8_PATCH_LEVEL deps/v8/include/v8-version.h | cut -d ' ' -f 3)
|
|
|
|
|
mkdir -p $libv8/lib/pkgconfig
|
|
|
|
|
cat > $libv8/lib/pkgconfig/v8.pc << EOF
|
|
|
|
|
Name: v8
|
|
|
|
|
Description: V8 JavaScript Engine
|
|
|
|
|
Version: $major.$minor.$patch
|
2023-05-30 09:37:53 +00:00
|
|
|
|
Libs: -L$libv8/lib -lv8 -pthread -licui18n -licuuc
|
2021-11-26 12:39:50 +00:00
|
|
|
|
Cflags: -I$libv8/include
|
|
|
|
|
EOF
|
2016-11-02 16:46:01 +00:00
|
|
|
|
'';
|
2016-04-25 14:10:10 +00:00
|
|
|
|
|
2018-02-18 14:19:01 +00:00
|
|
|
|
passthru.updateScript = import ./update.nix {
|
2019-06-18 11:08:32 +00:00
|
|
|
|
inherit writeScript coreutils gnugrep jq curl common-updater-scripts gnupg nix runtimeShell;
|
2021-01-27 05:44:43 +00:00
|
|
|
|
inherit lib;
|
2018-10-23 19:22:50 +00:00
|
|
|
|
inherit majorVersion;
|
2018-02-18 14:19:01 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-01-26 17:31:02 +00:00
|
|
|
|
meta = with lib; {
|
2016-11-02 16:46:01 +00:00
|
|
|
|
description = "Event-driven I/O framework for the V8 JavaScript engine";
|
2020-04-01 01:11:51 +00:00
|
|
|
|
homepage = "https://nodejs.org";
|
2021-10-20 04:20:00 +00:00
|
|
|
|
changelog = "https://github.com/nodejs/node/releases/tag/v${version}";
|
2016-11-02 16:46:01 +00:00
|
|
|
|
license = licenses.mit;
|
2020-06-30 23:17:35 +00:00
|
|
|
|
maintainers = with maintainers; [ goibhniu gilligan cko marsam ];
|
2016-11-02 16:46:01 +00:00
|
|
|
|
platforms = platforms.linux ++ platforms.darwin;
|
2021-05-03 07:42:48 +00:00
|
|
|
|
mainProgram = "node";
|
2023-05-08 11:35:12 +00:00
|
|
|
|
knownVulnerabilities = optional (versionOlder version "18") "This NodeJS release has reached its end of life. See https://nodejs.org/en/about/releases/.";
|
2023-06-17 20:55:22 +00:00
|
|
|
|
|
|
|
|
|
# Node.js build system does not have separate host and target OS
|
|
|
|
|
# configurations (architectures are defined as host_arch and target_arch,
|
|
|
|
|
# but there is no such thing as host_os and target_os).
|
|
|
|
|
#
|
|
|
|
|
# We may be missing something here, but it doesn’t look like it is
|
|
|
|
|
# possible to cross-compile between different operating systems.
|
|
|
|
|
broken = stdenv.buildPlatform.parsed.kernel.name != stdenv.hostPlatform.parsed.kernel.name;
|
2016-11-02 16:46:01 +00:00
|
|
|
|
};
|
2016-11-18 12:02:01 +00:00
|
|
|
|
|
2020-04-07 11:45:55 +00:00
|
|
|
|
passthru.python = python; # to ensure nodeEnv uses the same version
|
2021-10-14 06:03:13 +00:00
|
|
|
|
};
|
|
|
|
|
in self
|