node.scm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (guix build-system node)
  21. #:use-module (guix utils)
  22. #:use-module (guix packages)
  23. #:use-module (guix gexp)
  24. #:use-module (guix monads)
  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 (%node-build-system-modules
  30. node-build
  31. node-build-system))
  32. (define %node-build-system-modules
  33. ;; Build-side modules imported by default.
  34. `((guix build node-build-system)
  35. (guix build json)
  36. ,@%gnu-build-system-modules))
  37. (define (default-node)
  38. "Return the default Node package."
  39. ;; Lazily resolve the binding to avoid a circular dependency.
  40. (let ((node (resolve-interface '(gnu packages node))))
  41. (module-ref node 'node-lts)))
  42. (define* (lower name
  43. #:key source inputs native-inputs outputs system target
  44. (node (default-node))
  45. #:allow-other-keys
  46. #:rest arguments)
  47. "Return a bag for NAME."
  48. (define private-keywords
  49. '(#:target #:node #:inputs #:native-inputs))
  50. (and (not target) ;XXX: no cross-compilation
  51. (bag
  52. (name name)
  53. (system system)
  54. (host-inputs `(,@(if source
  55. `(("source" ,source))
  56. '())
  57. ,@inputs
  58. ;; Keep the standard inputs of 'gnu-build-system'.
  59. ,@(standard-packages)))
  60. (build-inputs `(("node" ,node)
  61. ,@native-inputs))
  62. (outputs outputs)
  63. (build node-build)
  64. (arguments (strip-keyword-arguments private-keywords arguments)))))
  65. (define* (node-build name inputs
  66. #:key
  67. source
  68. (npm-flags ''())
  69. (test-target "test")
  70. (tests? #t)
  71. (phases '%standard-phases)
  72. (outputs '("out"))
  73. (search-paths '())
  74. (system (%current-system))
  75. (guile #f)
  76. (imported-modules %node-build-system-modules)
  77. (modules '((guix build node-build-system)
  78. (guix build utils))))
  79. "Build SOURCE using NODE and INPUTS."
  80. (define builder
  81. (with-imported-modules imported-modules
  82. #~(begin
  83. (use-modules #$@(sexp->gexp modules))
  84. (node-build #:name #$name
  85. #:source #+source
  86. #:system #$system
  87. #:npm-flags #$npm-flags
  88. #:test-target #$test-target
  89. #:tests? #$tests?
  90. #:phases #$phases
  91. #:outputs #$(outputs->gexp outputs)
  92. #:search-paths '#$(sexp->gexp
  93. (map search-path-specification->sexp
  94. search-paths))
  95. #:inputs #$(input-tuples->gexp inputs)))))
  96. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  97. system #:graft? #f)))
  98. (gexp->derivation name builder
  99. #:system system
  100. #:guile-for-build guile)))
  101. (define node-build-system
  102. (build-system
  103. (name 'node)
  104. (description "The Node build system")
  105. (lower lower)))