1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 Cyrill Schenkel <cyrill.schenkel@gmail.com>
3 ;;; Copyright © 2015 Andreas Enge <andreas@enge.fr>
4 ;;; Copyright © 2015, 2016 David Thompson <davet@gnu.org>
5 ;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
6 ;;; Copyright © 2017 Mike Gerwitz <mtg@gnu.org>
7 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
8 ;;; Copyright © 2018, 2019, 2020 Marius Bakke <mbakke@fastmail.com>
9 ;;; Copyright © 2020 Pierre Langlois <pierre.langlois@gmx.com>
11 ;;; This file is part of GNU Guix.
13 ;;; GNU Guix is free software; you can redistribute it and/or modify it
14 ;;; under the terms of the GNU General Public License as published by
15 ;;; the Free Software Foundation; either version 3 of the License, or (at
16 ;;; your option) any later version.
18 ;;; GNU Guix is distributed in the hope that it will be useful, but
19 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;;; GNU General Public License for more details.
23 ;;; You should have received a copy of the GNU General Public License
24 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26 (define-module (gnu packages node)
27 #:use-module ((guix licenses) #:select (expat))
28 #:use-module ((guix build utils) #:select (alist-replace))
29 #:use-module (guix packages)
30 #:use-module (guix derivations)
31 #:use-module (guix download)
32 #:use-module (guix utils)
33 #:use-module (guix build-system gnu)
34 #:use-module (gnu packages)
35 #:use-module (gnu packages adns)
36 #:use-module (gnu packages base)
37 #:use-module (gnu packages compression)
38 #:use-module (gnu packages gcc)
39 #:use-module (gnu packages icu4c)
40 #:use-module (gnu packages libevent)
41 #:use-module (gnu packages linux)
42 #:use-module (gnu packages perl)
43 #:use-module (gnu packages pkg-config)
44 #:use-module (gnu packages python)
45 #:use-module (gnu packages tls)
46 #:use-module (gnu packages web))
54 (uri (string-append "https://nodejs.org/dist/v" version
55 "/node-v" version ".tar.xz"))
58 "0cvjwnl0wkcsyw3kannbdv01s235wrnp11n2s6swzjx95gpichfi"))
59 (modules '((guix build utils)))
62 ;; Remove bundled software.
63 (for-each delete-file-recursively
71 (substitute* "Makefile"
72 ;; Remove references to bundled software.
73 (("deps/http_parser/http_parser.gyp") "")
74 (("deps/uv/include/\\*.h") "")
75 (("deps/uv/uv.gyp") "")
76 (("deps/zlib/zlib.gyp") ""))
78 (build-system gnu-build-system)
80 `(#:configure-flags '("--shared-cares"
81 "--shared-http-parser"
87 "--with-intl=system-icu")
88 ;; Run only the CI tests. The default test target requires additional
89 ;; add-ons from NPM that are not distributed with the source.
90 #:test-target "test-ci-js"
92 (modify-phases %standard-phases
93 (add-before 'configure 'patch-files
94 (lambda* (#:key inputs #:allow-other-keys)
95 ;; Fix hardcoded /bin/sh references.
96 (substitute* '("lib/child_process.js"
97 "lib/internal/v8_prof_polyfill.js"
98 "test/parallel/test-child-process-spawnsync-shell.js"
99 "test/parallel/test-stdio-closed.js"
100 "test/sequential/test-child-process-emfile.js")
102 (string-append "'" (which "sh") "'")))
104 ;; Fix hardcoded /usr/bin/env references.
105 (substitute* '("test/parallel/test-child-process-default-options.js"
106 "test/parallel/test-child-process-env.js"
107 "test/parallel/test-child-process-exec-env.js")
109 (string-append "'" (which "env") "'")))
111 ;; FIXME: These tests fail in the build container, but they don't
112 ;; seem to be indicative of real problems in practice.
113 (for-each delete-file
114 '("test/parallel/test-cluster-master-error.js"
115 "test/parallel/test-cluster-master-kill.js"
116 ;; See also <https://github.com/nodejs/node/issues/25903>.
117 "test/sequential/test-performance.js"))
119 ;; This requires a DNS resolver.
120 (delete-file "test/parallel/test-dns.js")
122 ;; FIXME: This test fails randomly:
123 ;; https://github.com/nodejs/node/issues/31213
124 (delete-file "test/parallel/test-net-listen-after-destroying-stdin.js")
126 ;; FIXME: These tests fail on armhf-linux:
127 ;; https://github.com/nodejs/node/issues/31970
128 ,@(if (string-prefix? "arm" (%current-system))
129 '((for-each delete-file
130 '("test/parallel/test-zlib.js"
131 "test/parallel/test-zlib-brotli.js"
132 "test/parallel/test-zlib-brotli-flush.js"
133 "test/parallel/test-zlib-brotli-from-brotli.js"
134 "test/parallel/test-zlib-brotli-from-string.js"
135 "test/parallel/test-zlib-convenience-methods.js"
136 "test/parallel/test-zlib-random-byte-pipes.js"
137 "test/parallel/test-zlib-write-after-flush.js")))
140 ;; These tests have an expiry date: they depend on the validity of
141 ;; TLS certificates that are bundled with the source. We want this
142 ;; package to be reproducible forever, so remove those.
143 ;; TODO: Regenerate certs instead.
144 (for-each delete-file
145 '("test/parallel/test-tls-passphrase.js"
146 "test/parallel/test-tls-server-verify.js"))
149 ;; Node's configure script is actually a python script, so we can't
151 (lambda* (#:key outputs (configure-flags '()) inputs
153 (let* ((prefix (assoc-ref outputs "out"))
154 (flags (cons (string-append "--prefix=" prefix)
156 (format #t "build directory: ~s~%" (getcwd))
157 (format #t "configure flags: ~s~%" flags)
158 ;; Node's configure script expects the CC environment variable to
160 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
162 (string-append (assoc-ref inputs "python")
164 "configure" flags))))
165 (add-after 'patch-shebangs 'patch-npm-shebang
166 (lambda* (#:key outputs #:allow-other-keys)
167 (let* ((bindir (string-append (assoc-ref outputs "out")
169 (npm (string-append bindir "/npm"))
170 (target (readlink npm)))
171 (with-directory-excursion bindir
172 (patch-shebang target (list bindir))
175 `(("python" ,python-2)
177 ("pkg-config" ,pkg-config)
179 ("util-linux" ,util-linux)
182 (list (search-path-specification
183 (variable "NODE_PATH")
184 (files '("lib/node_modules")))))
187 ("http-parser" ,http-parser)
190 ("nghttp2" ,nghttp2 "lib")
193 (synopsis "Evented I/O for V8 JavaScript")
194 (description "Node.js is a platform built on Chrome's JavaScript runtime
195 for easily building fast, scalable network applications. Node.js uses an
196 event-driven, non-blocking I/O model that makes it lightweight and efficient,
197 perfect for data-intensive real-time applications that run across distributed
199 (home-page "https://nodejs.org/")
201 (properties '((max-silent-time . 7200) ;2h, needed on ARM
202 (timeout . 21600))))) ;6h
204 ;; TODO: Make this the default node on core-updates. This cannot be done on
205 ;; master since this version of node requires a newer nghttp2 library at link
207 (define-public node-10.22
212 (inherit (package-source node))
213 (uri (string-append "https://nodejs.org/dist/v" version
214 "/node-v" version ".tar.xz"))
217 "1nz18fa550li10r0kzsm28c2rvvq61nq8bqdygip0rmvbi2paxg0"))))
219 (alist-replace "nghttp2" (list nghttp2-1.41 "lib")
220 (package-inputs node)))))
222 (define-public libnode
227 (substitute-keyword-arguments (package-arguments node)
228 ((#:configure-flags flags ''())
229 `(cons* "--shared" "--without-npm" ,flags))
230 ((#:phases phases '%standard-phases)
231 `(modify-phases ,phases
232 (delete 'patch-npm-shebang)))))))