1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016 Jelle Licht <jlicht@fsfe.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (guix build-system node)
20 #:use-module (guix store)
21 #:use-module (guix build union)
22 #:use-module (guix utils)
23 #:use-module (guix packages)
24 #:use-module (guix derivations)
25 #:use-module (guix search-paths)
26 #:use-module (guix build-system)
27 #:use-module (guix build-system gnu)
28 #:use-module (ice-9 match)
29 #:use-module (json parser)
30 #:export (npm-meta-uri
31 %node-build-system-modules
35 (define (npm-meta-uri name)
36 "Return a URI string for the metadata of node module NAME found in the npm
38 (string-append "https://registry.npmjs.org/" name))
40 (define %node-build-system-modules
41 ;; Build-side modules imported by default.
42 `((guix build node-build-system)
45 ,@%gnu-build-system-modules)) ;; TODO: Might be not needed
47 (define (default-node)
48 "Return the default Node package."
49 ;; Lazily resolve the binding to avoid a circular dependency.
50 (let ((node (resolve-interface '(gnu packages node))))
51 (module-ref node 'node)))
54 #:key source inputs native-inputs outputs system target
58 "Return a bag for NAME."
59 (define private-keywords
60 '(#:source #:target #:node #:inputs #:native-inputs))
62 (and (not target) ;XXX: no cross-compilation
66 (host-inputs `(,@(if source
71 ;; Keep the standard inputs of 'gnu-build-system'.
72 ,@(standard-packages)))
73 (build-inputs `(("node" ,node)
77 (arguments (strip-keyword-arguments private-keywords arguments)))))
79 (define* (node-build store name inputs
83 (phases '(@ (guix build node-build-system)
87 (system (%current-system))
89 (imported-modules %node-build-system-modules)
90 (modules '((guix build node-build-system)
94 "Build SOURCE using NODE and INPUTS."
97 (use-modules ,@modules)
98 (node-build #:name ,name
99 #:source ,(match (assoc-ref inputs "source")
100 (((? derivation? source))
101 (derivation->output-path source))
107 #:npm-flags ,npm-flags
111 #:search-paths ',(map search-path-specification->sexp
113 #:inputs %build-inputs)))
115 (define guile-for-build
118 (package-derivation store guile system #:graft? #f))
120 (let* ((distro (resolve-interface '(gnu packages commencement)))
121 (guile (module-ref distro 'guile-final)))
122 (package-derivation store guile system #:graft? #f)))))
124 (build-expression->derivation store name builder
127 #:modules imported-modules
129 #:guile-for-build guile-for-build))
131 (define node-build-system
134 (description "The standard Node build system")