gnu: r-rgraphviz: Move to (gnu packages bioconductor).
[jackhill/guix/guix.git] / guix / hg-download.scm
CommitLineData
c4e48b68 1;;; GNU Guix --- Functional package management for GNU
67c2db17 2;;; Copyright © 2014, 2015, 2016, 2017, 2019 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."
e9f8a7e2
MO
63 (define guile-zlib
64 (module-ref (resolve-interface '(gnu packages guile)) 'guile-zlib))
37ce440d
LC
65
66 (define modules
e9f8a7e2
MO
67 (delete '(guix config)
68 (source-module-closure '((guix build hg)
69 (guix build download-nar)))))
37ce440d 70
c4e48b68 71 (define build
37ce440d 72 (with-imported-modules modules
e9f8a7e2
MO
73 (with-extensions (list guile-zlib)
74 #~(begin
75 (use-modules (guix build hg)
76 (guix build download-nar))
c4e48b68 77
e9f8a7e2
MO
78 (or (hg-fetch '#$(hg-reference-url ref)
79 '#$(hg-reference-changeset ref)
80 #$output
81 #:hg-command (string-append #+hg "/bin/hg"))
82 (download-nar #$output))))))
c4e48b68
RW
83
84 (mlet %store-monad ((guile (package->derivation guile system)))
85 (gexp->derivation (or name "hg-checkout") build
67c2db17
LC
86 #:leaked-env-vars '("http_proxy" "https_proxy"
87 "LC_ALL" "LC_MESSAGES" "LANG"
88 "COLUMNS")
c4e48b68
RW
89 #:system system
90 #:local-build? #t ;don't offload repo cloning
91 #:hash-algo hash-algo
92 #:hash hash
93 #:recursive? #t
c4e48b68
RW
94 #:guile-for-build guile)))
95
96;;; hg-download.scm ends here