node.scm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Jelle Licht <jlicht@fsfe.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  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.
  10. ;;;
  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.
  15. ;;;
  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/>.
  18. (define-module (guix build-system node)
  19. #:use-module (guix store)
  20. #:use-module (guix build json)
  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. #:export (npm-meta-uri
  30. %node-build-system-modules
  31. node-build
  32. node-build-system))
  33. (define (npm-meta-uri name)
  34. "Return a URI string for the metadata of node module NAME found in the npm
  35. registry."
  36. (string-append "https://registry.npmjs.org/" name))
  37. (define %node-build-system-modules
  38. ;; Build-side modules imported by default.
  39. `((guix build node-build-system)
  40. (guix build json)
  41. (guix build union)
  42. ,@%gnu-build-system-modules)) ;; TODO: Might be not needed
  43. (define (default-node)
  44. "Return the default Node package."
  45. ;; Lazily resolve the binding to avoid a circular dependency.
  46. (let ((node (resolve-interface '(gnu packages node))))
  47. (module-ref node 'node)))
  48. (define* (lower name
  49. #:key source inputs native-inputs outputs system target
  50. (node (default-node))
  51. #:allow-other-keys
  52. #:rest arguments)
  53. "Return a bag for NAME."
  54. (define private-keywords
  55. '(#:source #:target #:node #:inputs #:native-inputs))
  56. (and (not target) ;XXX: no cross-compilation
  57. (bag
  58. (name name)
  59. (system system)
  60. (host-inputs `(,@(if source
  61. `(("source" ,source))
  62. '())
  63. ,@inputs
  64. ;; Keep the standard inputs of 'gnu-build-system'.
  65. ,@(standard-packages)))
  66. (build-inputs `(("node" ,node)
  67. ,@native-inputs))
  68. (outputs outputs)
  69. (build node-build)
  70. (arguments (strip-keyword-arguments private-keywords arguments)))))
  71. (define* (node-build store name inputs
  72. #:key
  73. (npm-flags ''())
  74. (tests? #t)
  75. (phases '(@ (guix build node-build-system)
  76. %standard-phases))
  77. (outputs '("out"))
  78. (search-paths '())
  79. (system (%current-system))
  80. (guile #f)
  81. (imported-modules %node-build-system-modules)
  82. (modules '((guix build node-build-system)
  83. (guix build json)
  84. (guix build union)
  85. (guix build utils))))
  86. "Build SOURCE using NODE and INPUTS."
  87. (define builder
  88. `(begin
  89. (use-modules ,@modules)
  90. (node-build #:name ,name
  91. #:source ,(match (assoc-ref inputs "source")
  92. (((? derivation? source))
  93. (derivation->output-path source))
  94. ((source)
  95. source)
  96. (source
  97. source))
  98. #:system ,system
  99. #:npm-flags ,npm-flags
  100. #:tests? ,tests?
  101. #:phases ,phases
  102. #:outputs %outputs
  103. #:search-paths ',(map search-path-specification->sexp
  104. search-paths)
  105. #:inputs %build-inputs)))
  106. (define guile-for-build
  107. (match guile
  108. ((? package?)
  109. (package-derivation store guile system #:graft? #f))
  110. (#f
  111. (let* ((distro (resolve-interface '(gnu packages commencement)))
  112. (guile (module-ref distro 'guile-final)))
  113. (package-derivation store guile system #:graft? #f)))))
  114. (build-expression->derivation store name builder
  115. #:inputs inputs
  116. #:system system
  117. #:modules imported-modules
  118. #:outputs outputs
  119. #:guile-for-build guile-for-build))
  120. (define node-build-system
  121. (build-system
  122. (name 'node)
  123. (description "The standard Node build system")
  124. (lower lower)))