node.scm 4.6 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. ;;;
  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. (define-module (guix build-system node)
  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 (%node-build-system-modules
  28. node-build
  29. node-build-system))
  30. (define %node-build-system-modules
  31. ;; Build-side modules imported by default.
  32. `((guix build node-build-system)
  33. (guix build json)
  34. ,@%gnu-build-system-modules))
  35. (define (default-node)
  36. "Return the default Node package."
  37. ;; Lazily resolve the binding to avoid a circular dependency.
  38. (let ((node (resolve-interface '(gnu packages node))))
  39. (module-ref node 'node-lts)))
  40. (define* (lower name
  41. #:key source inputs native-inputs outputs system target
  42. (node (default-node))
  43. #:allow-other-keys
  44. #:rest arguments)
  45. "Return a bag for NAME."
  46. (define private-keywords
  47. '(#:source #:target #:node #:inputs #:native-inputs))
  48. (and (not target) ;XXX: no cross-compilation
  49. (bag
  50. (name name)
  51. (system system)
  52. (host-inputs `(,@(if source
  53. `(("source" ,source))
  54. '())
  55. ,@inputs
  56. ;; Keep the standard inputs of 'gnu-build-system'.
  57. ,@(standard-packages)))
  58. (build-inputs `(("node" ,node)
  59. ,@native-inputs))
  60. (outputs outputs)
  61. (build node-build)
  62. (arguments (strip-keyword-arguments private-keywords arguments)))))
  63. (define* (node-build store name inputs
  64. #:key
  65. (test-target "test")
  66. (tests? #t)
  67. (phases '(@ (guix build node-build-system)
  68. %standard-phases))
  69. (outputs '("out"))
  70. (search-paths '())
  71. (system (%current-system))
  72. (guile #f)
  73. (imported-modules %node-build-system-modules)
  74. (modules '((guix build node-build-system)
  75. (guix build utils))))
  76. "Build SOURCE using NODE and INPUTS."
  77. (define builder
  78. `(begin
  79. (use-modules ,@modules)
  80. (node-build #:name ,name
  81. #:source ,(match (assoc-ref inputs "source")
  82. (((? derivation? source))
  83. (derivation->output-path source))
  84. ((source) source)
  85. (source source))
  86. #:system ,system
  87. #:test-target ,test-target
  88. #:tests? ,tests?
  89. #:phases ,phases
  90. #:outputs %outputs
  91. #:search-paths ',(map search-path-specification->sexp
  92. search-paths)
  93. #:inputs %build-inputs)))
  94. (define guile-for-build
  95. (match guile
  96. ((? package?)
  97. (package-derivation store guile system #:graft? #f))
  98. (#f
  99. (let* ((distro (resolve-interface '(gnu packages commencement)))
  100. (guile (module-ref distro 'guile-final)))
  101. (package-derivation store guile system #:graft? #f)))))
  102. (build-expression->derivation store name builder
  103. #:inputs inputs
  104. #:system system
  105. #:modules imported-modules
  106. #:outputs outputs
  107. #:guile-for-build guile-for-build))
  108. (define node-build-system
  109. (build-system
  110. (name 'node)
  111. (description "The Node build system")
  112. (lower lower)))