node.scm 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Jelle Licht <jlicht@fsfe.org>
  3. ;;; Copyright © 2019 Timothy Sample <samplet@ngyro.com>
  4. ;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
  5. ;;; Copyright © 2021 Pierre Langlois <pierre.langlois@gmx.com>
  6. ;;; Copyright © 2021 Philip McGrath <philip@philipmcgrath.com>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  10. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or (at
  13. ;;; your option) any later version.
  14. ;;;
  15. ;;; GNU Guix is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (guix build-system node)
  23. #:use-module (guix store)
  24. #:use-module (guix utils)
  25. #:use-module (guix packages)
  26. #:use-module (guix gexp)
  27. #:use-module (guix monads)
  28. #:use-module (guix search-paths)
  29. #:use-module (guix build-system)
  30. #:use-module (guix build-system gnu)
  31. #:export (%node-build-system-modules
  32. node-build
  33. node-build-system))
  34. (define %node-build-system-modules
  35. ;; Build-side modules imported by default.
  36. `((guix build node-build-system)
  37. (guix build json)
  38. ,@%gnu-build-system-modules))
  39. (define (default-node)
  40. "Return the default Node package."
  41. ;; Lazily resolve the binding to avoid a circular dependency.
  42. (let ((node (resolve-interface '(gnu packages node))))
  43. (module-ref node 'node-lts)))
  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. '(#:target #:node #:inputs #:native-inputs))
  52. (and (not target) ;XXX: no cross-compilation
  53. (bag
  54. (name name)
  55. (system system)
  56. (host-inputs `(,@(if source
  57. `(("source" ,source))
  58. '())
  59. ,@inputs
  60. ;; Keep the standard inputs of 'gnu-build-system'.
  61. ,@(standard-packages)))
  62. (build-inputs `(("node" ,node)
  63. ;; Many packages with native addons need
  64. ;; libuv headers. The libuv version must
  65. ;; be exactly the same as for the node
  66. ;; package we are adding implicitly,
  67. ;; so we take care of adding libuv, too.
  68. ("libuv" ,@(assoc-ref (package-inputs node) "libuv"))
  69. ,@native-inputs))
  70. (outputs outputs)
  71. (build node-build)
  72. (arguments (strip-keyword-arguments private-keywords arguments)))))
  73. (define* (node-build name inputs
  74. #:key
  75. source
  76. (npm-flags ''())
  77. (test-target "test")
  78. (tests? #t)
  79. (phases '%standard-phases)
  80. (outputs '("out"))
  81. (search-paths '())
  82. (system (%current-system))
  83. (guile #f)
  84. (imported-modules %node-build-system-modules)
  85. (modules '((guix build node-build-system)
  86. (guix build utils))))
  87. "Build SOURCE using NODE and INPUTS."
  88. (define builder
  89. (with-imported-modules imported-modules
  90. #~(begin
  91. (use-modules #$@(sexp->gexp modules))
  92. (node-build #:name #$name
  93. #:source #+source
  94. #:system #$system
  95. #:npm-flags #$npm-flags
  96. #:test-target #$test-target
  97. #:tests? #$tests?
  98. #:phases #$phases
  99. #:outputs #$(outputs->gexp outputs)
  100. #:search-paths '#$(sexp->gexp
  101. (map search-path-specification->sexp
  102. search-paths))
  103. #:inputs #$(input-tuples->gexp inputs)))))
  104. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  105. system #:graft? #f)))
  106. (gexp->derivation name builder
  107. #:system system
  108. #:guile-for-build guile)))
  109. (define node-build-system
  110. (build-system
  111. (name 'node)
  112. (description "The Node build system")
  113. (lower lower)))