node.scm 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #:use-module (ice-9 match)
  32. #:export (%node-build-system-modules
  33. node-build
  34. node-build-system))
  35. (define %node-build-system-modules
  36. ;; Build-side modules imported by default.
  37. `((guix build node-build-system)
  38. (guix build json)
  39. ,@%gnu-build-system-modules))
  40. (define (default-node)
  41. "Return the default Node package."
  42. ;; Lazily resolve the binding to avoid a circular dependency.
  43. (let ((node (resolve-interface '(gnu packages node))))
  44. (module-ref node 'node-lts)))
  45. (define* (lower name
  46. #:key source inputs native-inputs outputs system target
  47. (node (default-node))
  48. #:allow-other-keys
  49. #:rest arguments)
  50. "Return a bag for NAME."
  51. (define private-keywords
  52. '(#:target #:node #:inputs #:native-inputs))
  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. ;; Keep the standard inputs of 'gnu-build-system'.
  62. ,@(standard-packages)))
  63. (build-inputs `(("node" ,node)
  64. ;; Many packages with native addons need
  65. ;; libuv headers. The libuv version must
  66. ;; be exactly the same as for the node
  67. ;; package we are adding implicitly,
  68. ;; so we take care of adding libuv, too.
  69. ("libuv" ,@(assoc-ref (package-inputs node) "libuv"))
  70. ,@native-inputs))
  71. (outputs outputs)
  72. (build node-build)
  73. (arguments (strip-keyword-arguments private-keywords arguments)))))
  74. (define* (node-build name inputs
  75. #:key
  76. source
  77. (npm-flags ''())
  78. (test-target "test")
  79. (tests? #t)
  80. (phases '%standard-phases)
  81. (outputs '("out"))
  82. (search-paths '())
  83. (system (%current-system))
  84. (guile #f)
  85. (imported-modules %node-build-system-modules)
  86. (modules '((guix build node-build-system)
  87. (guix build utils))))
  88. "Build SOURCE using NODE and INPUTS."
  89. (define builder
  90. (with-imported-modules imported-modules
  91. #~(begin
  92. (use-modules #$@(sexp->gexp modules))
  93. (node-build #:name #$name
  94. #:source #+source
  95. #:system #$system
  96. #:npm-flags #$npm-flags
  97. #:test-target #$test-target
  98. #:tests? #$tests?
  99. #:phases #$phases
  100. #:outputs #$(outputs->gexp outputs)
  101. #:search-paths '#$(sexp->gexp
  102. (map search-path-specification->sexp
  103. search-paths))
  104. #:inputs #$(input-tuples->gexp inputs)))))
  105. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  106. system #:graft? #f)))
  107. (gexp->derivation name builder
  108. #:system system
  109. #:guile-for-build guile)))
  110. (define node-build-system
  111. (build-system
  112. (name 'node)
  113. (description "The Node build system")
  114. (lower lower)))