at 23.05-pre 7.2 kB view raw
1{ lib, stdenv, fetchurl, openssl, python, zlib, libuv, util-linux, http-parser 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 12with lib; 13 14{ enableNpm ? true, version, sha256, patches ? [] } @args: 15 16let 17 inherit (darwin.apple_sdk.frameworks) CoreServices ApplicationServices; 18 19 majorVersion = versions.major version; 20 minorVersion = versions.minor version; 21 22 pname = if enableNpm then "nodejs" else "nodejs-slim"; 23 24 useSharedHttpParser = !stdenv.isDarwin && versionOlder "${majorVersion}.${minorVersion}" "11.4"; 25 26 sharedLibDeps = { inherit openssl zlib libuv; } // (optionalAttrs useSharedHttpParser { inherit http-parser; }); 27 28 sharedConfigureFlags = concatMap (name: [ 29 "--shared-${name}" 30 "--shared-${name}-libpath=${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 ]; 38 39 copyLibHeaders = 40 map 41 (name: "${getDev sharedLibDeps.${name}}/include/*") 42 (builtins.attrNames sharedLibDeps); 43 44 extraConfigFlags = optionals (!enableNpm) [ "--without-npm" ]; 45 self = stdenv.mkDerivation { 46 inherit pname version; 47 48 src = fetchurl { 49 url = "https://nodejs.org/dist/v${version}/node-v${version}.tar.xz"; 50 inherit sha256; 51 }; 52 53 CC_host = "cc"; 54 CXX_host = "c++"; 55 depsBuildBuild = [ buildPackages.stdenv.cc openssl libuv zlib ]; 56 57 buildInputs = optionals stdenv.isDarwin [ CoreServices ApplicationServices ] 58 ++ [ zlib libuv openssl http-parser icu ]; 59 60 nativeBuildInputs = [ which pkg-config python ] 61 ++ optionals stdenv.isDarwin [ xcbuild ]; 62 63 outputs = [ "out" "libv8" ]; 64 setOutputFlags = false; 65 moveToDev = false; 66 67 configureFlags = let 68 isCross = stdenv.hostPlatform != stdenv.buildPlatform; 69 inherit (stdenv.hostPlatform) gcc isAarch32; 70 in sharedConfigureFlags ++ optionals (versionOlder version "19") [ 71 "--without-dtrace" 72 ] ++ (optionals isCross [ 73 "--cross-compiling" 74 "--without-intl" 75 "--without-snapshot" 76 "--dest-cpu=${let platform = stdenv.hostPlatform; in 77 if platform.isAarch32 then "arm" 78 else if platform.isAarch64 then "arm64" 79 else if platform.isMips32 && platform.isLittleEndian then "mipsel" 80 else if platform.isMips32 && !platform.isLittleEndian then "mips" 81 else if platform.isMips64 && platform.isLittleEndian then "mips64el" 82 else if platform.isPower && platform.is32bit then "ppc" 83 else if platform.isPower && platform.is64bit then "ppc64" 84 else if platform.isx86_64 then "x86_64" 85 else if platform.isx86_32 then "x86" 86 else if platform.isS390 && platform.is64bit then "s390x" 87 else if platform.isRiscV && platform.is64bit then "riscv64" 88 else throw "unsupported cpu ${stdenv.hostPlatform.uname.processor}"}" 89 ]) ++ (optionals (isCross && isAarch32 && hasAttr "fpu" gcc) [ 90 "--with-arm-fpu=${gcc.fpu}" 91 ]) ++ (optionals (isCross && isAarch32 && hasAttr "float-abi" gcc) [ 92 "--with-arm-float-abi=${gcc.float-abi}" 93 ]) ++ extraConfigFlags; 94 95 configurePlatforms = []; 96 97 dontDisableStatic = true; 98 99 enableParallelBuilding = true; 100 101 passthru.interpreterName = "nodejs"; 102 103 passthru.pkgs = callPackage ../../node-packages/default.nix { 104 nodejs = self; 105 }; 106 107 setupHook = ./setup-hook.sh; 108 109 pos = builtins.unsafeGetAttrPos "version" args; 110 111 inherit patches; 112 113 postPatch = '' 114 patchShebangs . 115 116 # fix tests 117 for a in test/parallel/test-child-process-env.js \ 118 test/parallel/test-child-process-exec-env.js \ 119 test/parallel/test-child-process-default-options.js \ 120 test/fixtures/syntax/good_syntax_shebang.js \ 121 test/fixtures/syntax/bad_syntax_shebang.js ; do 122 substituteInPlace $a \ 123 --replace "/usr/bin/env" "${coreutils}/bin/env" 124 done 125 '' + optionalString stdenv.isDarwin '' 126 sed -i -e "s|tr1/type_traits|type_traits|g" \ 127 -e "s|std::tr1|std|" src/util.h 128 ''; 129 130 checkInputs = [ procps ]; 131 doCheck = false; # fails 4 out of 1453 tests 132 133 postInstall = '' 134 PATH=$out/bin:$PATH patchShebangs $out 135 136 ${optionalString (enableNpm && stdenv.hostPlatform == stdenv.buildPlatform) '' 137 mkdir -p $out/share/bash-completion/completions/ 138 HOME=$TMPDIR $out/bin/npm completion > $out/share/bash-completion/completions/npm 139 for dir in "$out/lib/node_modules/npm/man/"*; do 140 mkdir -p $out/share/man/$(basename "$dir") 141 for page in "$dir"/*; do 142 ln -rs $page $out/share/man/$(basename "$dir") 143 done 144 done 145 ''} 146 147 # install the missing headers for node-gyp 148 cp -r ${concatStringsSep " " copyLibHeaders} $out/include/node 149 150 # assemble a static v8 library and put it in the 'libv8' output 151 mkdir -p $libv8/lib 152 pushd out/Release/obj.target 153 find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" | sort -u >files 154 ${if stdenv.buildPlatform.isGnu then '' 155 ar -cqs $libv8/lib/libv8.a @files 156 '' else '' 157 cat files | while read -r file; do 158 ar -cqS $libv8/lib/libv8.a $file 159 done 160 ''} 161 popd 162 163 # copy v8 headers 164 cp -r deps/v8/include $libv8/ 165 166 # create a pkgconfig file for v8 167 major=$(grep V8_MAJOR_VERSION deps/v8/include/v8-version.h | cut -d ' ' -f 3) 168 minor=$(grep V8_MINOR_VERSION deps/v8/include/v8-version.h | cut -d ' ' -f 3) 169 patch=$(grep V8_PATCH_LEVEL deps/v8/include/v8-version.h | cut -d ' ' -f 3) 170 mkdir -p $libv8/lib/pkgconfig 171 cat > $libv8/lib/pkgconfig/v8.pc << EOF 172 Name: v8 173 Description: V8 JavaScript Engine 174 Version: $major.$minor.$patch 175 Libs: -L$libv8/lib -lv8 -pthread -licui18n 176 Cflags: -I$libv8/include 177 EOF 178 ''; 179 180 passthru.updateScript = import ./update.nix { 181 inherit writeScript coreutils gnugrep jq curl common-updater-scripts gnupg nix runtimeShell; 182 inherit lib; 183 inherit majorVersion; 184 }; 185 186 meta = { 187 description = "Event-driven I/O framework for the V8 JavaScript engine"; 188 homepage = "https://nodejs.org"; 189 changelog = "https://github.com/nodejs/node/releases/tag/v${version}"; 190 license = licenses.mit; 191 maintainers = with maintainers; [ goibhniu gilligan cko marsam ]; 192 platforms = platforms.linux ++ platforms.darwin; 193 mainProgram = "node"; 194 knownVulnerabilities = optional (versionOlder version "14") "This NodeJS release has reached its end of life. See https://nodejs.org/en/about/releases/."; 195 }; 196 197 passthru.python = python; # to ensure nodeEnv uses the same version 198 }; 199in self