Commit | Line | Data |
---|---|---|
09a1f92f JL |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2016 Jelle Licht <jlicht@fsfe.org> | |
23ea84cd | 3 | ;;; Copyright © 2019 Timothy Sample <samplet@ngyro.com> |
09a1f92f JL |
4 | ;;; |
5 | ;;; This file is part of GNU Guix. | |
6 | ;;; | |
7 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
8 | ;;; under the terms of the GNU General Public License as published by | |
9 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
10 | ;;; your option) any later version. | |
11 | ;;; | |
12 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
13 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ;;; GNU General Public License for more details. | |
16 | ;;; | |
17 | ;;; You should have received a copy of the GNU General Public License | |
18 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
19 | ||
20 | (define-module (guix build-system node) | |
09a1f92f JL |
21 | #:use-module (guix utils) |
22 | #:use-module (guix packages) | |
23 | #:use-module (guix derivations) | |
24 | #:use-module (guix search-paths) | |
25 | #:use-module (guix build-system) | |
26 | #:use-module (guix build-system gnu) | |
27 | #:use-module (ice-9 match) | |
23ea84cd | 28 | #:export (%node-build-system-modules |
09a1f92f JL |
29 | node-build |
30 | node-build-system)) | |
31 | ||
09a1f92f JL |
32 | (define %node-build-system-modules |
33 | ;; Build-side modules imported by default. | |
34 | `((guix build node-build-system) | |
a4bb1892 | 35 | (guix build json) |
23ea84cd | 36 | ,@%gnu-build-system-modules)) |
09a1f92f JL |
37 | |
38 | (define (default-node) | |
39 | "Return the default Node package." | |
40 | ;; Lazily resolve the binding to avoid a circular dependency. | |
41 | (let ((node (resolve-interface '(gnu packages node)))) | |
f6c43c93 | 42 | (module-ref node 'node-lts))) |
09a1f92f JL |
43 | |
44 | (define* (lower name | |
45 | #:key source inputs native-inputs outputs system target | |
46 | (node (default-node)) | |
47 | #:allow-other-keys | |
48 | #:rest arguments) | |
49 | "Return a bag for NAME." | |
50 | (define private-keywords | |
51 | '(#:source #:target #:node #:inputs #:native-inputs)) | |
52 | ||
53 | (and (not target) ;XXX: no cross-compilation | |
54 | (bag | |
55 | (name name) | |
56 | (system system) | |
57 | (host-inputs `(,@(if source | |
58 | `(("source" ,source)) | |
59 | '()) | |
60 | ,@inputs | |
61 | ||
62 | ;; Keep the standard inputs of 'gnu-build-system'. | |
63 | ,@(standard-packages))) | |
64 | (build-inputs `(("node" ,node) | |
65 | ,@native-inputs)) | |
66 | (outputs outputs) | |
67 | (build node-build) | |
68 | (arguments (strip-keyword-arguments private-keywords arguments))))) | |
69 | ||
70 | (define* (node-build store name inputs | |
71 | #:key | |
23ea84cd | 72 | (test-target "test") |
09a1f92f JL |
73 | (tests? #t) |
74 | (phases '(@ (guix build node-build-system) | |
75 | %standard-phases)) | |
76 | (outputs '("out")) | |
77 | (search-paths '()) | |
78 | (system (%current-system)) | |
79 | (guile #f) | |
80 | (imported-modules %node-build-system-modules) | |
81 | (modules '((guix build node-build-system) | |
a4bb1892 | 82 | (guix build utils)))) |
09a1f92f JL |
83 | "Build SOURCE using NODE and INPUTS." |
84 | (define builder | |
85 | `(begin | |
86 | (use-modules ,@modules) | |
87 | (node-build #:name ,name | |
88 | #:source ,(match (assoc-ref inputs "source") | |
89 | (((? derivation? source)) | |
90 | (derivation->output-path source)) | |
23ea84cd JL |
91 | ((source) source) |
92 | (source source)) | |
09a1f92f | 93 | #:system ,system |
23ea84cd | 94 | #:test-target ,test-target |
09a1f92f JL |
95 | #:tests? ,tests? |
96 | #:phases ,phases | |
97 | #:outputs %outputs | |
98 | #:search-paths ',(map search-path-specification->sexp | |
99 | search-paths) | |
100 | #:inputs %build-inputs))) | |
101 | ||
102 | (define guile-for-build | |
103 | (match guile | |
104 | ((? package?) | |
105 | (package-derivation store guile system #:graft? #f)) | |
106 | (#f | |
107 | (let* ((distro (resolve-interface '(gnu packages commencement))) | |
108 | (guile (module-ref distro 'guile-final))) | |
109 | (package-derivation store guile system #:graft? #f))))) | |
110 | ||
111 | (build-expression->derivation store name builder | |
112 | #:inputs inputs | |
113 | #:system system | |
114 | #:modules imported-modules | |
115 | #:outputs outputs | |
116 | #:guile-for-build guile-for-build)) | |
117 | ||
118 | (define node-build-system | |
119 | (build-system | |
120 | (name 'node) | |
23ea84cd | 121 | (description "The Node build system") |
09a1f92f | 122 | (lower lower))) |