haskell.scm 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
  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 haskell)
  19. #:use-module (guix store)
  20. #:use-module (guix utils)
  21. #:use-module (guix packages)
  22. #:use-module (guix derivations)
  23. #:use-module (guix download)
  24. #:use-module (guix search-paths)
  25. #:use-module (guix build-system)
  26. #:use-module (guix build-system gnu)
  27. #:use-module (ice-9 match)
  28. #:use-module (srfi srfi-26)
  29. #:export (%haskell-build-system-modules
  30. haskell-build
  31. haskell-build-system))
  32. ;; Commentary:
  33. ;;
  34. ;; Standard build procedure for Haskell packages using 'Setup.hs'. This is
  35. ;; implemented as an extension of 'gnu-build-system'.
  36. ;;
  37. ;; Code:
  38. (define %haskell-build-system-modules
  39. ;; Build-side modules imported by default.
  40. `((guix build haskell-build-system)
  41. ,@%gnu-build-system-modules))
  42. (define (default-haskell)
  43. "Return the default Haskell package."
  44. ;; Lazily resolve the binding to avoid a circular dependency.
  45. (let ((haskell (resolve-interface '(gnu packages haskell))))
  46. (module-ref haskell 'ghc)))
  47. (define (source-url->revision-url url revision)
  48. "Convert URL (a Hackage source URL) to the URL for the Cabal file at
  49. version REVISION."
  50. (let* ((last-slash (string-rindex url #\/))
  51. (next-slash (string-rindex url #\/ 0 last-slash)))
  52. (string-append (substring url 0 next-slash)
  53. (substring url last-slash (- (string-length url)
  54. (string-length ".tar.gz")))
  55. "/revision/" revision ".cabal")))
  56. (define* (lower name
  57. #:key source inputs native-inputs outputs system target
  58. (haskell (default-haskell))
  59. cabal-revision
  60. #:allow-other-keys
  61. #:rest arguments)
  62. "Return a bag for NAME."
  63. (define private-keywords
  64. '(#:target #:haskell #:cabal-revision #:inputs #:native-inputs))
  65. (define (cabal-revision->origin cabal-revision)
  66. (match cabal-revision
  67. ((revision hash)
  68. (origin
  69. (method url-fetch)
  70. (uri (source-url->revision-url (origin-uri source) revision))
  71. (sha256 (base32 hash))
  72. (file-name (string-append name "-" revision ".cabal"))))
  73. (#f #f)))
  74. (and (not target) ;XXX: no cross-compilation
  75. (bag
  76. (name name)
  77. (system system)
  78. (host-inputs `(,@(if source
  79. `(("source" ,source))
  80. '())
  81. ,@(match (cabal-revision->origin cabal-revision)
  82. (#f '())
  83. (revision `(("cabal-revision" ,revision))))
  84. ,@inputs
  85. ;; Keep the standard inputs of 'gnu-build-system'.
  86. ,@(standard-packages)))
  87. (build-inputs `(("haskell" ,haskell)
  88. ,@native-inputs))
  89. (outputs outputs)
  90. (build haskell-build)
  91. (arguments (strip-keyword-arguments private-keywords arguments)))))
  92. (define* (haskell-build store name inputs
  93. #:key source
  94. (haddock? #t)
  95. (haddock-flags ''())
  96. (tests? #t)
  97. (test-target "test")
  98. (configure-flags ''())
  99. (phases '(@ (guix build haskell-build-system)
  100. %standard-phases))
  101. (outputs '("out"))
  102. (search-paths '())
  103. (system (%current-system))
  104. (guile #f)
  105. (imported-modules %haskell-build-system-modules)
  106. (modules '((guix build haskell-build-system)
  107. (guix build utils))))
  108. "Build SOURCE using HASKELL, and with INPUTS. This assumes that SOURCE
  109. provides a 'Setup.hs' file as its build system."
  110. (define builder
  111. `(begin
  112. (use-modules ,@modules)
  113. (haskell-build #:name ,name
  114. #:source ,(match (assoc-ref inputs "source")
  115. (((? derivation? source))
  116. (derivation->output-path source))
  117. ((source)
  118. source)
  119. (source
  120. source))
  121. #:cabal-revision ,(match (assoc-ref inputs
  122. "cabal-revision")
  123. (((? derivation? revision))
  124. (derivation->output-path revision))
  125. (revision revision))
  126. #:configure-flags ,configure-flags
  127. #:haddock-flags ,haddock-flags
  128. #:system ,system
  129. #:test-target ,test-target
  130. #:tests? ,tests?
  131. #:haddock? ,haddock?
  132. #:phases ,phases
  133. #:outputs %outputs
  134. #:search-paths ',(map search-path-specification->sexp
  135. search-paths)
  136. #:inputs %build-inputs)))
  137. (define guile-for-build
  138. (match guile
  139. ((? package?)
  140. (package-derivation store guile system #:graft? #f))
  141. (#f ; the default
  142. (let* ((distro (resolve-interface '(gnu packages commencement)))
  143. (guile (module-ref distro 'guile-final)))
  144. (package-derivation store guile system #:graft? #f)))))
  145. (build-expression->derivation store name builder
  146. #:inputs inputs
  147. #:system system
  148. #:modules imported-modules
  149. #:outputs outputs
  150. #:guile-for-build guile-for-build))
  151. (define haskell-build-system
  152. (build-system
  153. (name 'haskell)
  154. (description "The standard Haskell build system")
  155. (lower lower)))
  156. ;;; haskell.scm ends here