gnu: bear: Fix python path.
[guix.git] / guix / hg-download.scm
blob6b25b87b6bddb6922d4b73d4a25dee28df13be5b
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
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/>.
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)
25   #:use-module (guix modules)
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?
35             hg-fetch))
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:
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))
51 (define (hg-package)
52   "Return the default Mercurial package."
53   (let ((distro (resolve-interface '(gnu packages version-control))))
54     (module-ref distro 'mercurial)))
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>
61 object.  The output is expected to have recursive hash HASH of type
62 HASH-ALGO (a symbol).  Use NAME as the file name, or a generic name if #f."
63   (define zlib
64     (module-ref (resolve-interface '(gnu packages compression)) 'zlib))
66   (define config.scm
67     (scheme-file "config.scm"
68                  #~(begin
69                      (define-module (guix config)
70                        #:export (%libz))
72                      (define %libz
73                        #+(file-append zlib "/lib/libz")))))
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))))))
81   (define build
82     (with-imported-modules modules
83       #~(begin
84           (use-modules (guix build hg)
85                        (guix build download-nar))
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)))))
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
100                       #:guile-for-build guile)))
102 ;;; hg-download.scm ends here