123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- (define-module (guix build-system haskell)
- #:use-module (guix store)
- #:use-module (guix utils)
- #:use-module (guix packages)
- #:use-module (guix derivations)
- #:use-module (guix download)
- #:use-module (guix search-paths)
- #:use-module (guix build-system)
- #:use-module (guix build-system gnu)
- #:use-module (ice-9 match)
- #:use-module (srfi srfi-1)
- #:use-module (srfi srfi-26)
- #:export (%haskell-build-system-modules
- haskell-build
- haskell-build-system))
- (define %haskell-build-system-modules
-
- `((guix build haskell-build-system)
- ,@%gnu-build-system-modules))
- (define (default-haskell)
- "Return the default Haskell package."
-
- (let ((haskell (resolve-interface '(gnu packages haskell))))
- (module-ref haskell 'ghc)))
- (define (source-url->revision-url url revision)
- "Convert URL (a Hackage source URL) to the URL for the Cabal file at
- version REVISION."
- (let* ((last-slash (string-rindex url #\/))
- (next-slash (string-rindex url #\/ 0 last-slash)))
- (string-append (substring url 0 next-slash)
- (substring url last-slash (- (string-length url)
- (string-length ".tar.gz")))
- "/revision/" revision ".cabal")))
- (define* (lower name
- #:key source inputs native-inputs outputs system target
- (haskell (default-haskell))
- cabal-revision
- #:allow-other-keys
- #:rest arguments)
- "Return a bag for NAME."
- (define private-keywords
- '(#:target #:haskell #:cabal-revision #:inputs #:native-inputs #:outputs))
- (define (cabal-revision->origin cabal-revision)
- (match cabal-revision
- ((revision hash)
- (origin
- (method url-fetch)
- (uri (source-url->revision-url (origin-uri source) revision))
- (sha256 (base32 hash))
- (file-name (string-append name "-" revision ".cabal"))))
- (#f #f)))
- (and (not target)
- (bag
- (name name)
- (system system)
- (host-inputs `(,@(if source
- `(("source" ,source))
- '())
- ,@(match (cabal-revision->origin cabal-revision)
- (#f '())
- (revision `(("cabal-revision" ,revision))))
- ,@inputs
-
- ,@(standard-packages)))
- (build-inputs `(("haskell" ,haskell)
- ,@native-inputs))
-
- (outputs (match outputs
- (("out") (cons "static" outputs))
- (_ outputs)))
- (build haskell-build)
- (arguments
- (substitute-keyword-arguments
- (strip-keyword-arguments private-keywords arguments)
- ((#:extra-directories extra-directories)
- `(list ,@(append-map
- (lambda (name)
- (match (assoc name inputs)
- ((_ pkg)
- (match (package-transitive-propagated-inputs pkg)
- (((propagated-names . _) ...)
- (cons name propagated-names))))))
- extra-directories))))))))
- (define* (haskell-build store name inputs
- #:key source
- (haddock? #t)
- (haddock-flags ''())
- (tests? #t)
- (test-target "test")
- (parallel-build? #t)
- (configure-flags ''())
- (extra-directories ''())
- (phases '(@ (guix build haskell-build-system)
- %standard-phases))
- (outputs '("out" "static"))
- (search-paths '())
- (system (%current-system))
- (guile #f)
- (imported-modules %haskell-build-system-modules)
- (modules '((guix build haskell-build-system)
- (guix build utils))))
- "Build SOURCE using HASKELL, and with INPUTS. This assumes that SOURCE
- provides a 'Setup.hs' file as its build system."
- (define builder
- `(begin
- (use-modules ,@modules)
- (haskell-build #:name ,name
- #:source ,(match (assoc-ref inputs "source")
- (((? derivation? source))
- (derivation->output-path source))
- ((source)
- source)
- (source
- source))
- #:cabal-revision ,(match (assoc-ref inputs
- "cabal-revision")
- (((? derivation? revision))
- (derivation->output-path revision))
- (revision revision))
- #:configure-flags ,configure-flags
- #:extra-directories ,extra-directories
- #:haddock-flags ,haddock-flags
- #:system ,system
- #:test-target ,test-target
- #:tests? ,tests?
- #:parallel-build? ,parallel-build?
- #:haddock? ,haddock?
- #:phases ,phases
- #:outputs %outputs
- #:search-paths ',(map search-path-specification->sexp
- search-paths)
- #:inputs %build-inputs)))
- (define guile-for-build
- (match guile
- ((? package?)
- (package-derivation store guile system #:graft? #f))
- (#f
- (let* ((distro (resolve-interface '(gnu packages commencement)))
- (guile (module-ref distro 'guile-final)))
- (package-derivation store guile system #:graft? #f)))))
- (build-expression->derivation store name builder
- #:inputs inputs
- #:system system
- #:modules imported-modules
- #:outputs outputs
- #:guile-for-build guile-for-build))
- (define haskell-build-system
- (build-system
- (name 'haskell)
- (description "The standard Haskell build system")
- (lower lower)))
|