Move search path specifications to (guix search-paths).
[guix.git] / guix / build-system / haskell.scm
blob1cb734631c6da7a2c74d38a4ad0dd875f6a91981
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/>.
19 (define-module (guix build-system haskell)
20   #:use-module (guix store)
21   #:use-module (guix utils)
22   #:use-module (guix packages)
23   #:use-module (guix derivations)
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))
33 ;; Commentary:
35 ;; Standard build procedure for Haskell packages using 'Setup.hs'.  This is
36 ;; implemented as an extension of 'gnu-build-system'.
38 ;; Code:
40 (define %haskell-build-system-modules
41   ;; Build-side modules imported by default.
42   `((guix build haskell-build-system)
43     ,@%gnu-build-system-modules))
45 (define (default-haskell)
46   "Return the default Haskell package."
47   ;; Lazily resolve the binding to avoid a circular dependency.
48   (let ((haskell (resolve-interface '(gnu packages haskell))))
49     (module-ref haskell 'ghc)))
51 (define* (lower name
52                 #:key source inputs native-inputs outputs system target
53                 (haskell (default-haskell))
54                 #:allow-other-keys
55                 #:rest arguments)
56   "Return a bag for NAME."
57   (define private-keywords
58     '(#:target #:haskell #:inputs #:native-inputs))
60   (and (not target)                               ;XXX: no cross-compilation
61        (bag
62          (name name)
63          (system system)
64          (host-inputs `(,@(if source
65                               `(("source" ,source))
66                               '())
67                         ,@inputs
69                         ;; Keep the standard inputs of 'gnu-build-system'.
70                         ,@(standard-packages)))
71          (build-inputs `(("haskell" ,haskell)
72                          ,@native-inputs))
73          (outputs outputs)
74          (build haskell-build)
75          (arguments (strip-keyword-arguments private-keywords arguments)))))
77 (define* (haskell-build store name inputs
78                         #:key source
79                         (haddock? #t)
80                         (haddock-flags ''())
81                         (tests? #t)
82                         (test-target "test")
83                         (configure-flags ''())
84                         (phases '(@ (guix build haskell-build-system)
85                                     %standard-phases))
86                         (outputs '("out"))
87                         (search-paths '())
88                         (system (%current-system))
89                         (guile #f)
90                         (imported-modules %haskell-build-system-modules)
91                         (modules '((guix build haskell-build-system)
92                                    (guix build utils))))
93   "Build SOURCE using HASKELL, and with INPUTS.  This assumes that SOURCE
94 provides a 'Setup.hs' file as its build system."
95   (define builder
96     `(begin
97        (use-modules ,@modules)
98        (haskell-build #:name ,name
99                       #:source ,(match (assoc-ref inputs "source")
100                                   (((? derivation? source))
101                                    (derivation->output-path source))
102                                   ((source)
103                                    source)
104                                   (source
105                                    source))
106                       #:configure-flags ,configure-flags
107                       #:haddock-flags ,haddock-flags
108                       #:system ,system
109                       #:test-target ,test-target
110                       #:tests? ,tests?
111                       #:haddock? ,haddock?
112                       #:phases ,phases
113                       #:outputs %outputs
114                       #:search-paths ',(map search-path-specification->sexp
115                                             search-paths)
116                       #:inputs %build-inputs)))
118   (define guile-for-build
119     (match guile
120       ((? package?)
121        (package-derivation store guile system #:graft? #f))
122       (#f                                         ; the default
123        (let* ((distro (resolve-interface '(gnu packages commencement)))
124               (guile  (module-ref distro 'guile-final)))
125          (package-derivation store guile system #:graft? #f)))))
127   (build-expression->derivation store name builder
128                                 #:inputs inputs
129                                 #:system system
130                                 #:modules imported-modules
131                                 #:outputs outputs
132                                 #:guile-for-build guile-for-build))
134 (define haskell-build-system
135   (build-system
136     (name 'haskell)
137     (description "The standard Haskell build system")
138     (lower lower)))
140 ;;; haskell.scm ends here