gnu: Add libnode.
[jackhill/guix/guix.git] / gnu / packages / node.scm
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 ;;;
10 ;;; This file is part of GNU Guix.
11 ;;;
12 ;;; GNU Guix is free software; you can redistribute it and/or modify it
13 ;;; under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 3 of the License, or (at
15 ;;; your option) any later version.
16 ;;;
17 ;;; GNU Guix is distributed in the hope that it will be useful, but
18 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details.
21 ;;;
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24
25 (define-module (gnu packages node)
26 #:use-module ((guix licenses) #:select (expat))
27 #:use-module (guix packages)
28 #:use-module (guix derivations)
29 #:use-module (guix download)
30 #:use-module (guix utils)
31 #:use-module (guix build-system gnu)
32 #:use-module (gnu packages)
33 #:use-module (gnu packages adns)
34 #:use-module (gnu packages base)
35 #:use-module (gnu packages compression)
36 #:use-module (gnu packages gcc)
37 #:use-module (gnu packages icu4c)
38 #:use-module (gnu packages libevent)
39 #:use-module (gnu packages linux)
40 #:use-module (gnu packages perl)
41 #:use-module (gnu packages pkg-config)
42 #:use-module (gnu packages python)
43 #:use-module (gnu packages tls)
44 #:use-module (gnu packages web))
45
46 (define-public node
47 (package
48 (name "node")
49 (version "10.19.0")
50 (source (origin
51 (method url-fetch)
52 (uri (string-append "https://nodejs.org/dist/v" version
53 "/node-v" version ".tar.xz"))
54 (sha256
55 (base32
56 "0sginvcsf7lrlzsnpahj4bj1f673wfvby8kaxgvzlrbb7sy229v2"))
57 (modules '((guix build utils)))
58 (snippet
59 `(begin
60 ;; Remove bundled software.
61 (for-each delete-file-recursively
62 '("deps/cares"
63 "deps/http_parser"
64 "deps/icu-small"
65 "deps/nghttp2"
66 "deps/openssl"
67 "deps/uv"
68 "deps/zlib"))
69 (substitute* "Makefile"
70 ;; Remove references to bundled software.
71 (("deps/http_parser/http_parser.gyp") "")
72 (("deps/uv/include/\\*.h") "")
73 (("deps/uv/uv.gyp") "")
74 (("deps/zlib/zlib.gyp") ""))
75 #t))))
76 (build-system gnu-build-system)
77 (arguments
78 `(#:configure-flags '("--shared"
79 "--shared-cares"
80 "--shared-http-parser"
81 "--shared-libuv"
82 "--shared-nghttp2"
83 "--shared-openssl"
84 "--shared-zlib"
85 "--without-snapshot"
86 "--with-intl=system-icu")
87 ;; Run only the CI tests. The default test target requires additional
88 ;; add-ons from NPM that are not distributed with the source.
89 #:test-target "test-ci-js"
90 #:phases
91 (modify-phases %standard-phases
92 (add-before 'configure 'patch-files
93 (lambda* (#:key inputs #:allow-other-keys)
94 ;; Fix hardcoded /bin/sh references.
95 (substitute* '("lib/child_process.js"
96 "lib/internal/v8_prof_polyfill.js"
97 "test/parallel/test-child-process-spawnsync-shell.js"
98 "test/parallel/test-stdio-closed.js"
99 "test/sequential/test-child-process-emfile.js")
100 (("'/bin/sh'")
101 (string-append "'" (which "sh") "'")))
102
103 ;; Fix hardcoded /usr/bin/env references.
104 (substitute* '("test/parallel/test-child-process-default-options.js"
105 "test/parallel/test-child-process-env.js"
106 "test/parallel/test-child-process-exec-env.js")
107 (("'/usr/bin/env'")
108 (string-append "'" (which "env") "'")))
109
110 ;; FIXME: These tests fail in the build container, but they don't
111 ;; seem to be indicative of real problems in practice.
112 (for-each delete-file
113 '("test/parallel/test-cluster-master-error.js"
114 "test/parallel/test-cluster-master-kill.js"
115 ;; See also <https://github.com/nodejs/node/issues/25903>.
116 "test/sequential/test-performance.js"))
117
118 ;; This requires a DNS resolver.
119 (delete-file "test/parallel/test-dns.js")
120
121 ;; FIXME: This test fails randomly:
122 ;; https://github.com/nodejs/node/issues/31213
123 (delete-file "test/parallel/test-net-listen-after-destroying-stdin.js")
124
125 ;; FIXME: These tests fail on armhf-linux:
126 ;; https://github.com/nodejs/node/issues/31970
127 ,@(if (string-prefix? "arm" (%current-system))
128 '((for-each delete-file
129 '("test/parallel/test-zlib.js"
130 "test/parallel/test-zlib-brotli.js"
131 "test/parallel/test-zlib-brotli-flush.js"
132 "test/parallel/test-zlib-brotli-from-brotli.js"
133 "test/parallel/test-zlib-brotli-from-string.js"
134 "test/parallel/test-zlib-convenience-methods.js"
135 "test/parallel/test-zlib-random-byte-pipes.js"
136 "test/parallel/test-zlib-write-after-flush.js")))
137 '())
138
139 ;; These tests have an expiry date: they depend on the validity of
140 ;; TLS certificates that are bundled with the source. We want this
141 ;; package to be reproducible forever, so remove those.
142 ;; TODO: Regenerate certs instead.
143 (for-each delete-file
144 '("test/parallel/test-tls-passphrase.js"
145 "test/parallel/test-tls-server-verify.js"))
146 #t))
147 (replace 'configure
148 ;; Node's configure script is actually a python script, so we can't
149 ;; run it with bash.
150 (lambda* (#:key outputs (configure-flags '()) inputs
151 #:allow-other-keys)
152 (let* ((prefix (assoc-ref outputs "out"))
153 (flags (cons (string-append "--prefix=" prefix)
154 configure-flags)))
155 (format #t "build directory: ~s~%" (getcwd))
156 (format #t "configure flags: ~s~%" flags)
157 ;; Node's configure script expects the CC environment variable to
158 ;; be set.
159 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
160 (apply invoke
161 (string-append (assoc-ref inputs "python")
162 "/bin/python")
163 "configure" flags))))
164 (add-after 'patch-shebangs 'patch-npm-shebang
165 (lambda* (#:key outputs #:allow-other-keys)
166 (let* ((bindir (string-append (assoc-ref outputs "out")
167 "/bin"))
168 (npm (string-append bindir "/npm"))
169 (target (readlink npm)))
170 (with-directory-excursion bindir
171 (patch-shebang target (list bindir))
172 #t)))))))
173 (native-inputs
174 `(("python" ,python-2)
175 ("perl" ,perl)
176 ("pkg-config" ,pkg-config)
177 ("procps" ,procps)
178 ("util-linux" ,util-linux)
179 ("which" ,which)))
180 (native-search-paths
181 (list (search-path-specification
182 (variable "NODE_PATH")
183 (files '("lib/node_modules")))))
184 (inputs
185 `(("c-ares" ,c-ares)
186 ("http-parser" ,http-parser)
187 ("icu4c" ,icu4c)
188 ("libuv" ,libuv)
189 ("nghttp2" ,nghttp2 "lib")
190 ("openssl" ,openssl)
191 ("zlib" ,zlib)))
192 (synopsis "Evented I/O for V8 JavaScript")
193 (description "Node.js is a platform built on Chrome's JavaScript runtime
194 for easily building fast, scalable network applications. Node.js uses an
195 event-driven, non-blocking I/O model that makes it lightweight and efficient,
196 perfect for data-intensive real-time applications that run across distributed
197 devices.")
198 (home-page "https://nodejs.org/")
199 (license expat)
200 (properties '((max-silent-time . 7200) ;2h, needed on ARM
201 (timeout . 21600))))) ;6h
202
203 (define-public libnode
204 (package
205 (inherit node)
206 (name "libnode")
207 (arguments
208 (substitute-keyword-arguments (package-arguments node)
209 ((#:configure-flags flags ''())
210 `(cons* "--shared" "--without-npm" ,flags))))))