node.scm 4.9 KB

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