gnu: Add r-flowsom.
[jackhill/guix/guix.git] / guix / hg-download.scm
CommitLineData
c4e48b68 1;;; GNU Guix --- Functional package management for GNU
37ce440d 2;;; Copyright © 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
c4e48b68
RW
3;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (guix hg-download)
21 #:use-module (guix gexp)
22 #:use-module (guix store)
23 #:use-module (guix monads)
24 #:use-module (guix records)
37ce440d 25 #:use-module (guix modules)
c4e48b68
RW
26 #:use-module (guix packages)
27 #:autoload (guix build-system gnu) (standard-packages)
28 #:use-module (ice-9 match)
29 #:export (hg-reference
30 hg-reference?
31 hg-reference-url
32 hg-reference-changeset
33 hg-reference-recursive?
34
35 hg-fetch))
36
37;;; Commentary:
38;;;
39;;; An <origin> method that fetches a specific changeset from a Mercurial
40;;; repository. The repository URL and changeset ID are specified with a
41;;; <hg-reference> object.
42;;;
43;;; Code:
44
45(define-record-type* <hg-reference>
46 hg-reference make-hg-reference
47 hg-reference?
48 (url hg-reference-url)
49 (changeset hg-reference-changeset))
50
51(define (hg-package)
52 "Return the default Mercurial package."
53 (let ((distro (resolve-interface '(gnu packages version-control))))
54 (module-ref distro 'mercurial)))
55
56(define* (hg-fetch ref hash-algo hash
57 #:optional name
58 #:key (system (%current-system)) (guile (default-guile))
59 (hg (hg-package)))
60 "Return a fixed-output derivation that fetches REF, a <hg-reference>
61object. The output is expected to have recursive hash HASH of type
62HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
37ce440d
LC
63 (define zlib
64 (module-ref (resolve-interface '(gnu packages compression)) 'zlib))
65
66 (define config.scm
67 (scheme-file "config.scm"
68 #~(begin
69 (define-module (guix config)
70 #:export (%libz))
71
72 (define %libz
73 #+(file-append zlib "/lib/libz")))))
74
75 (define modules
76 (cons `((guix config) => ,config.scm)
77 (delete '(guix config)
78 (source-module-closure '((guix build hg)
79 (guix build download-nar))))))
80
c4e48b68 81 (define build
37ce440d 82 (with-imported-modules modules
e9b046fd
LC
83 #~(begin
84 (use-modules (guix build hg)
37ce440d 85 (guix build download-nar))
c4e48b68 86
37ce440d
LC
87 (or (hg-fetch '#$(hg-reference-url ref)
88 '#$(hg-reference-changeset ref)
89 #$output
90 #:hg-command (string-append #+hg "/bin/hg"))
91 (download-nar #$output)))))
c4e48b68
RW
92
93 (mlet %store-monad ((guile (package->derivation guile system)))
94 (gexp->derivation (or name "hg-checkout") build
95 #:system system
96 #:local-build? #t ;don't offload repo cloning
97 #:hash-algo hash-algo
98 #:hash hash
99 #:recursive? #t
c4e48b68
RW
100 #:guile-for-build guile)))
101
102;;; hg-download.scm ends here