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