at 18.09-beta 3.7 kB view raw
1{ stdenv, fetchurl, openssl, python2, zlib, libuv, utillinux, http-parser 2, pkgconfig, which 3# Updater dependencies 4, writeScript, coreutils, gnugrep, jq, curl, common-updater-scripts, nix 5, gnupg 6, darwin, xcbuild 7, procps 8}: 9 10with stdenv.lib; 11 12{ enableNpm ? true, version, sha256, patches ? [] } @args: 13 14let 15 16 inherit (darwin.apple_sdk.frameworks) CoreServices ApplicationServices; 17 18 baseName = if enableNpm then "nodejs" else "nodejs-slim"; 19 20 sharedLibDeps = { inherit openssl zlib libuv; } // (optionalAttrs (!stdenv.isDarwin) { inherit http-parser; }); 21 22 sharedConfigureFlags = concatMap (name: [ 23 "--shared-${name}" 24 "--shared-${name}-libpath=${getLib sharedLibDeps.${name}}/lib" 25 /** Closure notes: we explicitly avoid specifying --shared-*-includes, 26 * as that would put the paths into bin/nodejs. 27 * Including pkgconfig in build inputs would also have the same effect! 28 */ 29 ]) (builtins.attrNames sharedLibDeps); 30 31 copyLibHeaders = 32 map 33 (name: "${getDev sharedLibDeps.${name}}/include/*") 34 (builtins.attrNames sharedLibDeps); 35 36 extraConfigFlags = optionals (!enableNpm) [ "--without-npm" ]; 37in 38 39 stdenv.mkDerivation { 40 inherit version; 41 42 name = "${baseName}-${version}"; 43 44 src = fetchurl { 45 url = "http://nodejs.org/dist/v${version}/node-v${version}.tar.xz"; 46 inherit sha256; 47 }; 48 49 buildInputs = optionals stdenv.isDarwin [ CoreServices ApplicationServices ] 50 ++ [ python2 zlib libuv openssl http-parser ]; 51 52 nativeBuildInputs = [ which utillinux ] 53 ++ optionals stdenv.isDarwin [ pkgconfig xcbuild ]; 54 55 configureFlags = sharedConfigureFlags ++ [ "--without-dtrace" ] ++ extraConfigFlags; 56 57 dontDisableStatic = true; 58 59 enableParallelBuilding = true; 60 61 passthru.interpreterName = "nodejs"; 62 63 setupHook = ./setup-hook.sh; 64 65 pos = builtins.unsafeGetAttrPos "version" args; 66 67 inherit patches; 68 69 postPatch = '' 70 patchShebangs . 71 sed -i 's/raise.*No Xcode or CLT version detected.*/version = "7.0.0"/' tools/gyp/pylib/gyp/xcode_emulation.py 72 73 # fix tests 74 for a in test/parallel/test-child-process-env.js \ 75 test/parallel/test-child-process-exec-env.js \ 76 test/parallel/test-child-process-default-options.js \ 77 test/fixtures/syntax/good_syntax_shebang.js \ 78 test/fixtures/syntax/bad_syntax_shebang.js ; do 79 substituteInPlace $a \ 80 --replace "/usr/bin/env" "${coreutils}/bin/env" 81 done 82 '' + optionalString stdenv.isDarwin '' 83 sed -i -e "s|tr1/type_traits|type_traits|g" \ 84 -e "s|std::tr1|std|" src/util.h 85 ''; 86 87 checkInputs = [ procps ]; 88 doCheck = false; # fails 4 out of 1453 tests 89 90 postInstall = '' 91 paxmark m $out/bin/node 92 PATH=$out/bin:$PATH patchShebangs $out 93 94 ${optionalString enableNpm '' 95 mkdir -p $out/share/bash-completion/completions/ 96 $out/bin/npm completion > $out/share/bash-completion/completions/npm 97 ''} 98 99 # install the missing headers for node-gyp 100 cp -r ${concatStringsSep " " copyLibHeaders} $out/include/node 101 ''; 102 103 passthru.updateScript = import ./update.nix { 104 inherit writeScript coreutils gnugrep jq curl common-updater-scripts gnupg nix; 105 inherit (stdenv) lib; 106 majorVersion = with stdenv.lib; elemAt (splitString "." version) 0; 107 }; 108 109 meta = { 110 description = "Event-driven I/O framework for the V8 JavaScript engine"; 111 homepage = https://nodejs.org; 112 license = licenses.mit; 113 maintainers = with maintainers; [ goibhniu gilligan cko ]; 114 platforms = platforms.linux ++ platforms.darwin; 115 }; 116 117 passthru.python = python2; # to ensure nodeEnv uses the same version 118}