at 24.05-pre 8.7 kB view raw
1{ lib, stdenv, fetchurl, openssl, python, zlib, libuv, util-linux, http-parser, bash 2, pkg-config, which, buildPackages 3# for `.pkgs` attribute 4, callPackage 5# Updater dependencies 6, writeScript, coreutils, gnugrep, jq, curl, common-updater-scripts, nix, runtimeShell 7, gnupg 8, darwin, xcbuild 9, procps, icu 10}: 11 12{ enableNpm ? true, version, sha256, patches ? [] } @args: 13 14let 15 inherit (darwin.apple_sdk.frameworks) CoreServices ApplicationServices; 16 17 isCross = stdenv.hostPlatform != stdenv.buildPlatform; 18 19 majorVersion = lib.versions.major version; 20 minorVersion = lib.versions.minor version; 21 22 pname = if enableNpm then "nodejs" else "nodejs-slim"; 23 24 useSharedHttpParser = !stdenv.isDarwin && lib.versionOlder "${majorVersion}.${minorVersion}" "11.4"; 25 26 sharedLibDeps = { inherit openssl zlib libuv; } // (lib.optionalAttrs useSharedHttpParser { inherit http-parser; }); 27 28 sharedConfigureFlags = lib.concatMap (name: [ 29 "--shared-${name}" 30 "--shared-${name}-libpath=${lib.getLib sharedLibDeps.${name}}/lib" 31 /** Closure notes: we explicitly avoid specifying --shared-*-includes, 32 * as that would put the paths into bin/nodejs. 33 * Including pkg-config in build inputs would also have the same effect! 34 */ 35 ]) (builtins.attrNames sharedLibDeps) ++ [ 36 "--with-intl=system-icu" 37 "--openssl-use-def-ca-store" 38 ]; 39 40 copyLibHeaders = 41 map 42 (name: "${lib.getDev sharedLibDeps.${name}}/include/*") 43 (builtins.attrNames sharedLibDeps); 44 45 extraConfigFlags = lib.optionals (!enableNpm) [ "--without-npm" ]; 46 self = stdenv.mkDerivation { 47 inherit pname version; 48 49 src = fetchurl { 50 url = "https://nodejs.org/dist/v${version}/node-v${version}.tar.xz"; 51 inherit sha256; 52 }; 53 54 strictDeps = true; 55 56 env = lib.optionalAttrs (stdenv.isDarwin && stdenv.isx86_64) { 57 # Make sure libc++ uses `posix_memalign` instead of `aligned_alloc` on x86_64-darwin. 58 # Otherwise, nodejs would require the 11.0 SDK and macOS 10.15+. 59 NIX_CFLAGS_COMPILE = "-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=101300"; 60 }; 61 62 CC_host = "cc"; 63 CXX_host = "c++"; 64 depsBuildBuild = [ buildPackages.stdenv.cc openssl libuv zlib icu ]; 65 66 # NB: technically, we do not need bash in build inputs since all scripts are 67 # wrappers over the corresponding JS scripts. There are some packages though 68 # that use bash wrappers, e.g. polaris-web. 69 buildInputs = lib.optionals stdenv.isDarwin [ CoreServices ApplicationServices ] 70 ++ [ zlib libuv openssl http-parser icu bash ]; 71 72 nativeBuildInputs = [ which pkg-config python ] 73 ++ lib.optionals stdenv.isDarwin [ xcbuild ]; 74 75 outputs = [ "out" "libv8" ]; 76 setOutputFlags = false; 77 moveToDev = false; 78 79 configureFlags = let 80 inherit (stdenv.hostPlatform) gcc isAarch32; 81 in sharedConfigureFlags ++ lib.optionals (lib.versionOlder version "19") [ 82 "--without-dtrace" 83 ] ++ (lib.optionals isCross [ 84 "--cross-compiling" 85 "--dest-cpu=${let platform = stdenv.hostPlatform; in 86 if platform.isAarch32 then "arm" 87 else if platform.isAarch64 then "arm64" 88 else if platform.isMips32 && platform.isLittleEndian then "mipsel" 89 else if platform.isMips32 && !platform.isLittleEndian then "mips" 90 else if platform.isMips64 && platform.isLittleEndian then "mips64el" 91 else if platform.isPower && platform.is32bit then "ppc" 92 else if platform.isPower && platform.is64bit then "ppc64" 93 else if platform.isx86_64 then "x86_64" 94 else if platform.isx86_32 then "x86" 95 else if platform.isS390 && platform.is64bit then "s390x" 96 else if platform.isRiscV && platform.is64bit then "riscv64" 97 else throw "unsupported cpu ${stdenv.hostPlatform.uname.processor}"}" 98 ]) ++ (lib.optionals (isCross && isAarch32 && lib.hasAttr "fpu" gcc) [ 99 "--with-arm-fpu=${gcc.fpu}" 100 ]) ++ (lib.optionals (isCross && isAarch32 && lib.hasAttr "float-abi" gcc) [ 101 "--with-arm-float-abi=${gcc.float-abi}" 102 ]) ++ extraConfigFlags; 103 104 configurePlatforms = []; 105 106 dontDisableStatic = true; 107 108 enableParallelBuilding = true; 109 110 # Don't allow enabling content addressed conversion as `nodejs` 111 # checksums it's image before conversion happens and image loading 112 # breaks: 113 # $ nix build -f. nodejs --arg config '{ contentAddressedByDefault = true; }' 114 # $ ./result/bin/node 115 # Check failed: VerifyChecksum(blob). 116 __contentAddressed = false; 117 118 passthru.interpreterName = "nodejs"; 119 120 passthru.pkgs = callPackage ../../node-packages/default.nix { 121 nodejs = self; 122 }; 123 124 setupHook = ./setup-hook.sh; 125 126 pos = builtins.unsafeGetAttrPos "version" args; 127 128 inherit patches; 129 130 doCheck = lib.versionAtLeast version "16"; # some tests fail on v14 131 132 # Some dependencies required for tools/doc/node_modules (and therefore 133 # test-addons, jstest and others) target are not included in the tarball. 134 # Run test targets that do not require network access. 135 checkTarget = lib.concatStringsSep " " [ 136 "build-js-native-api-tests" 137 "build-node-api-tests" 138 "tooltest" 139 "cctest" 140 ]; 141 142 # Do not create __pycache__ when running tests. 143 checkFlags = [ "PYTHONDONTWRITEBYTECODE=1" ]; 144 145 postInstall = '' 146 HOST_PATH=$out/bin patchShebangs --host $out 147 148 ${lib.optionalString (enableNpm) '' 149 mkdir -p $out/share/bash-completion/completions 150 ln -s $out/lib/node_modules/npm/lib/utils/completion.sh \ 151 $out/share/bash-completion/completions/npm 152 for dir in "$out/lib/node_modules/npm/man/"*; do 153 mkdir -p $out/share/man/$(basename "$dir") 154 for page in "$dir"/*; do 155 ln -rs $page $out/share/man/$(basename "$dir") 156 done 157 done 158 ''} 159 160 # install the missing headers for node-gyp 161 cp -r ${lib.concatStringsSep " " copyLibHeaders} $out/include/node 162 163 # assemble a static v8 library and put it in the 'libv8' output 164 mkdir -p $libv8/lib 165 pushd out/Release/obj.target 166 find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" | sort -u >files 167 ${if stdenv.buildPlatform.isGnu then '' 168 ar -cqs $libv8/lib/libv8.a @files 169 '' else '' 170 # llvm-ar supports response files, so take advantage of it if its available. 171 if [ "$(basename $(readlink -f $(command -v ar)))" = "llvm-ar" ]; then 172 ar -cqs $libv8/lib/libv8.a @files 173 else 174 cat files | while read -r file; do 175 ar -cqS $libv8/lib/libv8.a $file 176 done 177 fi 178 ''} 179 popd 180 181 # copy v8 headers 182 cp -r deps/v8/include $libv8/ 183 184 # create a pkgconfig file for v8 185 major=$(grep V8_MAJOR_VERSION deps/v8/include/v8-version.h | cut -d ' ' -f 3) 186 minor=$(grep V8_MINOR_VERSION deps/v8/include/v8-version.h | cut -d ' ' -f 3) 187 patch=$(grep V8_PATCH_LEVEL deps/v8/include/v8-version.h | cut -d ' ' -f 3) 188 mkdir -p $libv8/lib/pkgconfig 189 cat > $libv8/lib/pkgconfig/v8.pc << EOF 190 Name: v8 191 Description: V8 JavaScript Engine 192 Version: $major.$minor.$patch 193 Libs: -L$libv8/lib -lv8 -pthread -licui18n -licuuc 194 Cflags: -I$libv8/include 195 EOF 196 ''; 197 198 passthru.updateScript = import ./update.nix { 199 inherit writeScript coreutils gnugrep jq curl common-updater-scripts gnupg nix runtimeShell; 200 inherit lib; 201 inherit majorVersion; 202 }; 203 204 meta = with lib; { 205 description = "Event-driven I/O framework for the V8 JavaScript engine"; 206 homepage = "https://nodejs.org"; 207 changelog = "https://github.com/nodejs/node/releases/tag/v${version}"; 208 license = licenses.mit; 209 maintainers = with maintainers; [ goibhniu gilligan cko marsam ]; 210 platforms = platforms.linux ++ platforms.darwin; 211 mainProgram = "node"; 212 knownVulnerabilities = optional (versionOlder version "18") "This NodeJS release has reached its end of life. See https://nodejs.org/en/about/releases/."; 213 214 # Node.js build system does not have separate host and target OS 215 # configurations (architectures are defined as host_arch and target_arch, 216 # but there is no such thing as host_os and target_os). 217 # 218 # We may be missing something here, but it doesn’t look like it is 219 # possible to cross-compile between different operating systems. 220 broken = stdenv.buildPlatform.parsed.kernel.name != stdenv.hostPlatform.parsed.kernel.name; 221 }; 222 223 passthru.python = python; # to ensure nodeEnv uses the same version 224 }; 225in self