1{ lib, stdenv, fetchurl, openssl, python, zlib, libuv, util-linux, http-parser
2, pkg-config, which
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 baseName = 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 version;
47
48 name = "${baseName}-${version}";
49
50 src = fetchurl {
51 url = "https://nodejs.org/dist/v${version}/node-v${version}.tar.xz";
52 inherit sha256;
53 };
54
55 buildInputs = optionals stdenv.isDarwin [ CoreServices ApplicationServices ]
56 ++ [ zlib libuv openssl http-parser icu ];
57
58 nativeBuildInputs = [ which pkg-config python ]
59 ++ optionals stdenv.isDarwin [ xcbuild ];
60
61 configureFlags = let
62 isCross = stdenv.hostPlatform != stdenv.buildPlatform;
63 inherit (stdenv.hostPlatform) gcc isAarch32;
64 in sharedConfigureFlags ++ [
65 "--without-dtrace"
66 ] ++ (optionals isCross [
67 "--cross-compiling"
68 "--without-intl"
69 "--without-snapshot"
70 ]) ++ (optionals (isCross && isAarch32 && hasAttr "fpu" gcc) [
71 "--with-arm-fpu=${gcc.fpu}"
72 ]) ++ (optionals (isCross && isAarch32 && hasAttr "float-abi" gcc) [
73 "--with-arm-float-abi=${gcc.float-abi}"
74 ]) ++ (optionals (isCross && isAarch32) [
75 "--dest-cpu=arm"
76 ]) ++ extraConfigFlags;
77
78 configurePlatforms = [];
79
80 dontDisableStatic = true;
81
82 enableParallelBuilding = true;
83
84 passthru.interpreterName = "nodejs";
85
86 passthru.pkgs = callPackage ../../node-packages/default.nix {
87 nodejs = self;
88 };
89
90 setupHook = ./setup-hook.sh;
91
92 pos = builtins.unsafeGetAttrPos "version" args;
93
94 inherit patches;
95
96 postPatch = ''
97 patchShebangs .
98
99 # fix tests
100 for a in test/parallel/test-child-process-env.js \
101 test/parallel/test-child-process-exec-env.js \
102 test/parallel/test-child-process-default-options.js \
103 test/fixtures/syntax/good_syntax_shebang.js \
104 test/fixtures/syntax/bad_syntax_shebang.js ; do
105 substituteInPlace $a \
106 --replace "/usr/bin/env" "${coreutils}/bin/env"
107 done
108 '' + optionalString stdenv.isDarwin ''
109 sed -i 's/raise.*No Xcode or CLT version detected.*/version = "7.0.0"/' tools/gyp/pylib/gyp/xcode_emulation.py
110 sed -i -e "s|tr1/type_traits|type_traits|g" \
111 -e "s|std::tr1|std|" src/util.h
112 '';
113
114 checkInputs = [ procps ];
115 doCheck = false; # fails 4 out of 1453 tests
116
117 postInstall = ''
118 PATH=$out/bin:$PATH patchShebangs $out
119
120 ${optionalString (enableNpm && stdenv.hostPlatform == stdenv.buildPlatform) ''
121 mkdir -p $out/share/bash-completion/completions/
122 $out/bin/npm completion > $out/share/bash-completion/completions/npm
123 for dir in "$out/lib/node_modules/npm/man/"*; do
124 mkdir -p $out/share/man/$(basename "$dir")
125 for page in "$dir"/*; do
126 ln -rs $page $out/share/man/$(basename "$dir")
127 done
128 done
129 ''}
130
131 # install the missing headers for node-gyp
132 cp -r ${concatStringsSep " " copyLibHeaders} $out/include/node
133 '' + optionalString (stdenv.isDarwin && enableNpm) ''
134 sed -i 's/raise.*No Xcode or CLT version detected.*/version = "7.0.0"/' $out/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py
135 '';
136
137 passthru.updateScript = import ./update.nix {
138 inherit writeScript coreutils gnugrep jq curl common-updater-scripts gnupg nix runtimeShell;
139 inherit lib;
140 inherit majorVersion;
141 };
142
143 meta = {
144 description = "Event-driven I/O framework for the V8 JavaScript engine";
145 homepage = "https://nodejs.org";
146 changelog = "https://github.com/nodejs/node/releases/tag/v${version}";
147 license = licenses.mit;
148 maintainers = with maintainers; [ goibhniu gilligan cko marsam ];
149 platforms = platforms.linux ++ platforms.darwin;
150 mainProgram = "node";
151 };
152
153 passthru.python = python; # to ensure nodeEnv uses the same version
154 };
155in self