read-print: Improve declaration of integer bases.
[jackhill/guix/guix.git] / guix / cvs-download.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016, 2017, 2019 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014 Sree Harsha Totakura <sreeharsha@totakura.in>
4 ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
5 ;;;
6 ;;; This file is part of GNU Guix.
7 ;;;
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
12 ;;;
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
17 ;;;
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21 (define-module (guix cvs-download)
22 #:use-module (guix records)
23 #:use-module (guix gexp)
24 #:use-module (guix store)
25 #:use-module (guix monads)
26 #:use-module (guix modules)
27 #:use-module (guix packages)
28 #:use-module (ice-9 match)
29 #:export (cvs-reference
30 cvs-reference?
31 cvs-reference-root-directory
32 cvs-reference-module
33 cvs-reference-revision
34 cvs-fetch))
35
36 ;;; Commentary:
37 ;;;
38 ;;; An <origin> method that fetches a specific revision or date from a CVS
39 ;;; repository. The CVS-ROOT-DIRECTORY, MODULE and REVISION are specified
40 ;;; with a <cvs-reference> object. REVISION should be specified as either a
41 ;;; date string in ISO-8601 format (e.g. "2012-12-21") or a CVS tag.
42 ;;;
43 ;;; Code:
44
45 (define-record-type* <cvs-reference>
46 cvs-reference make-cvs-reference
47 cvs-reference?
48 (root-directory cvs-reference-root-directory) ; string
49 (module cvs-reference-module) ; string
50 (revision cvs-reference-revision)) ; string
51
52 (define (cvs-package)
53 "Return the default CVS package."
54 (let ((distro (resolve-interface '(gnu packages version-control))))
55 (module-ref distro 'cvs)))
56
57 (define* (cvs-fetch ref hash-algo hash
58 #:optional name
59 #:key (system (%current-system)) (guile (default-guile))
60 (cvs (cvs-package)))
61 "Return a fixed-output derivation that fetches REF, a <cvs-reference>
62 object. The output is expected to have recursive hash HASH of type
63 HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
64 (define guile-zlib
65 (module-ref (resolve-interface '(gnu packages guile)) 'guile-zlib))
66
67 (define guile-json
68 (module-ref (resolve-interface '(gnu packages guile)) 'guile-json-4))
69
70 (define gnutls
71 (module-ref (resolve-interface '(gnu packages tls)) 'gnutls))
72
73 (define modules
74 (delete '(guix config)
75 (source-module-closure '((guix build cvs)
76 (guix build download-nar)))))
77 (define build
78 (with-imported-modules modules
79 (with-extensions (list guile-json gnutls ;for (guix swh)
80 guile-zlib)
81 #~(begin
82 (use-modules (guix build cvs)
83 (guix build download-nar))
84
85 (or (cvs-fetch '#$(cvs-reference-root-directory ref)
86 '#$(cvs-reference-module ref)
87 '#$(cvs-reference-revision ref)
88 #$output
89 #:cvs-command (string-append #+cvs "/bin/cvs"))
90 (download-nar #$output))))))
91
92 (mlet %store-monad ((guile (package->derivation guile system)))
93 (gexp->derivation (or name "cvs-checkout") build
94 #:leaked-env-vars '("http_proxy" "https_proxy"
95 "LC_ALL" "LC_MESSAGES" "LANG"
96 "COLUMNS")
97 #:system system
98 #:hash-algo hash-algo
99 #:hash hash
100 #:recursive? #t
101 #:guile-for-build guile
102 #:local-build? #t)))
103
104 ;;; cvs-download.scm ends here