node.scm 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 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. (define-module (gnu packages node)
  25. #:use-module ((guix licenses) #:select (expat))
  26. #:use-module (guix packages)
  27. #:use-module (guix derivations)
  28. #:use-module (guix download)
  29. #:use-module (guix build-system gnu)
  30. #:use-module (gnu packages)
  31. #:use-module (gnu packages adns)
  32. #:use-module (gnu packages base)
  33. #:use-module (gnu packages compression)
  34. #:use-module (gnu packages gcc)
  35. #:use-module (gnu packages icu4c)
  36. #:use-module (gnu packages libevent)
  37. #:use-module (gnu packages linux)
  38. #:use-module (gnu packages perl)
  39. #:use-module (gnu packages pkg-config)
  40. #:use-module (gnu packages python)
  41. #:use-module (gnu packages tls)
  42. #:use-module (gnu packages web))
  43. (define-public node
  44. (package
  45. (name "node")
  46. (version "9.11.1")
  47. (source (origin
  48. (method url-fetch)
  49. (uri (string-append "https://nodejs.org/dist/v" version
  50. "/node-v" version ".tar.gz"))
  51. (sha256
  52. (base32
  53. "1vjh9zvw7wkdz6b0l99ya7mqjk0l8lbg9isr1q8rxwp400dhkk32"))
  54. (modules '((guix build utils)))
  55. (snippet
  56. `(begin
  57. ;; Remove bundled software.
  58. (for-each delete-file-recursively
  59. '("deps/cares"
  60. "deps/http_parser"
  61. "deps/icu-small"
  62. "deps/nghttp2"
  63. "deps/openssl"
  64. "deps/uv"
  65. "deps/zlib"))
  66. (substitute* "Makefile"
  67. ;; Remove references to bundled software.
  68. (("deps/http_parser/http_parser.gyp") "")
  69. (("deps/uv/include/\\*.h") "")
  70. (("deps/uv/uv.gyp") "")
  71. (("deps/zlib/zlib.gyp") ""))
  72. #t))))
  73. (build-system gnu-build-system)
  74. (arguments
  75. ;; TODO: Purge the bundled copies from the source.
  76. '(#:configure-flags '("--shared-cares"
  77. "--shared-http-parser"
  78. "--shared-libuv"
  79. "--shared-nghttp2"
  80. "--shared-openssl"
  81. "--shared-zlib"
  82. "--without-snapshot"
  83. "--with-intl=system-icu")
  84. #:phases
  85. (modify-phases %standard-phases
  86. (add-before 'configure 'patch-files
  87. (lambda* (#:key inputs #:allow-other-keys)
  88. ;; This phase is inherited by Node LTS, which does not have all
  89. ;; the files listed here. Use this helper for convenience.
  90. (define (delete-if-exists file)
  91. (if (file-exists? file)
  92. (delete-file file)
  93. '()))
  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. (("'/bin/sh'")
  100. (string-append "'" (which "sh") "'")))
  101. ;; Fix hardcoded /usr/bin/env references.
  102. (substitute* '("test/parallel/test-child-process-default-options.js"
  103. "test/parallel/test-child-process-env.js"
  104. "test/parallel/test-child-process-exec-env.js")
  105. (("'/usr/bin/env'")
  106. (string-append "'" (which "env") "'")))
  107. ;; FIXME: These tests depend on being able to install eslint.
  108. ;; See https://github.com/nodejs/node/issues/17098.
  109. (for-each delete-if-exists
  110. '("test/parallel/test-eslint-alphabetize-errors.js"
  111. "test/parallel/test-eslint-buffer-constructor.js"
  112. "test/parallel/test-eslint-documented-errors.js"
  113. "test/parallel/test-eslint-inspector-check.js"))
  114. ;; FIXME: These tests fail in the build container, but they don't
  115. ;; seem to be indicative of real problems in practice.
  116. (for-each delete-if-exists
  117. '("test/async-hooks/test-ttywrap.readstream.js"
  118. "test/parallel/test-util-inspect.js"
  119. "test/parallel/test-v8-serdes.js"
  120. "test/parallel/test-dgram-membership.js"
  121. "test/parallel/test-dns-cancel-reverse-lookup.js"
  122. "test/parallel/test-dns-resolveany.js"
  123. "test/parallel/test-cluster-master-error.js"
  124. "test/parallel/test-cluster-master-kill.js"
  125. "test/parallel/test-net-listen-after-destroying-stdin.js"
  126. "test/parallel/test-npm-install.js"
  127. "test/sequential/test-child-process-emfile.js"
  128. "test/sequential/test-benchmark-child-process.js"
  129. "test/sequential/test-http-regr-gh-2928.js"))
  130. ;; These tests have an expiry date: they depend on the validity of
  131. ;; TLS certificates that are bundled with the source. We want this
  132. ;; package to be reproducible forever, so remove those.
  133. ;; TODO: Regenerate certs instead.
  134. (for-each delete-if-exists
  135. '("test/parallel/test-tls-passphrase.js"
  136. "test/parallel/test-tls-server-verify.js"))
  137. #t))
  138. (replace 'configure
  139. ;; Node's configure script is actually a python script, so we can't
  140. ;; run it with bash.
  141. (lambda* (#:key outputs (configure-flags '()) inputs
  142. #:allow-other-keys)
  143. (let* ((prefix (assoc-ref outputs "out"))
  144. (flags (cons (string-append "--prefix=" prefix)
  145. configure-flags)))
  146. (format #t "build directory: ~s~%" (getcwd))
  147. (format #t "configure flags: ~s~%" flags)
  148. ;; Node's configure script expects the CC environment variable to
  149. ;; be set.
  150. (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
  151. (apply invoke
  152. (string-append (assoc-ref inputs "python")
  153. "/bin/python")
  154. "configure" flags))))
  155. (add-after 'patch-shebangs 'patch-npm-shebang
  156. (lambda* (#:key outputs #:allow-other-keys)
  157. (let* ((bindir (string-append (assoc-ref outputs "out")
  158. "/bin"))
  159. (npm (string-append bindir "/npm"))
  160. (target (readlink npm)))
  161. (with-directory-excursion bindir
  162. (patch-shebang target (list bindir))
  163. #t)))))))
  164. (native-inputs
  165. `(("python" ,python-2)
  166. ("perl" ,perl)
  167. ("pkg-config" ,pkg-config)
  168. ("procps" ,procps)
  169. ("util-linux" ,util-linux)
  170. ("which" ,which)))
  171. (native-search-paths
  172. (list (search-path-specification
  173. (variable "NODE_PATH")
  174. (files '("lib/node_modules")))))
  175. (inputs
  176. `(("c-ares" ,c-ares)
  177. ("http-parser" ,http-parser)
  178. ("icu4c" ,icu4c)
  179. ("libuv" ,libuv-1.19)
  180. ("nghttp2" ,nghttp2 "lib")
  181. ("openssl" ,openssl)
  182. ("zlib" ,zlib)))
  183. (synopsis "Evented I/O for V8 JavaScript")
  184. (description "Node.js is a platform built on Chrome's JavaScript runtime
  185. for easily building fast, scalable network applications. Node.js uses an
  186. event-driven, non-blocking I/O model that makes it lightweight and efficient,
  187. perfect for data-intensive real-time applications that run across distributed
  188. devices.")
  189. (home-page "https://nodejs.org/")
  190. (license expat)
  191. (properties '((timeout . 3600))))) ; 1 h
  192. (define-public node-lts
  193. (package
  194. (inherit node)
  195. (name "node-lts")
  196. (version "8.12.0")
  197. (source (origin
  198. (inherit (package-source node))
  199. (uri (string-append "https://nodejs.org/dist/v" version
  200. "/node-v" version ".tar.xz"))
  201. (sha256
  202. (base32
  203. "16j1rrxkhmvpcw689ndw1raql1gz4jqn7n82z55zn63c05cgz7as"))))))