Add (guix svn-download).
[jackhill/guix/guix.git] / guix / svn-download.scm
CommitLineData
b3acf365
SHT
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014 Ludovic Courtès <ludo@gnu.org>
3;;; Copyright © 2014 Sree Harsha Totakura <sreeharsha@totakura.in>
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 svn-download)
21 #:use-module (guix records)
22 #:use-module (guix derivations)
23 #:use-module (guix packages)
24 #:use-module (ice-9 match)
25 #:export (svn-reference
26 svn-reference?
27 svn-reference-url
28 svn-reference-revision
29 svn-fetch))
30
31;;; Commentary:
32;;;
33;;; An <origin> method that fetches a specific revision from a Subversion
34;;; repository. The repository URL and REVISION are specified with a
35;;; <svn-reference> object. REVISION should be specified as a number.
36;;;
37;;; Code:
38
39(define-record-type* <svn-reference>
40 svn-reference make-svn-reference
41 svn-reference?
42 (url svn-reference-url) ; string
43 (revision svn-reference-revision)) ; number
44
45(define* (svn-fetch store ref hash-algo hash
46 #:optional name
47 #:key (system (%current-system)) guile svn)
48 "Return a fixed-output derivation in STORE that fetches REF, a
49<svn-reference> object. The output is expected to have recursive hash HASH of
50type HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if
51#f."
52 (define guile-for-build
53 (match guile
54 ((? package?)
55 (package-derivation store guile system))
56 (#f ; the default
57 (let* ((distro (resolve-interface '(gnu packages base)))
58 (guile (module-ref distro 'guile-final)))
59 (package-derivation store guile system)))))
60
61 (define svn-for-build
62 (match svn
63 ((? package?)
64 (package-derivation store svn system))
65 (#f ; the default
66 (let* ((distro (resolve-interface '(gnu packages version-control)))
67 (svn (module-ref distro 'subversion)))
68 (package-derivation store svn system)))))
69
70 (let* ((command (string-append (derivation->output-path svn-for-build)
71 "/bin/svn"))
72 (builder `(begin
73 (use-modules (guix build svn))
74 (svn-fetch ',(svn-reference-url ref)
75 ',(svn-reference-revision ref)
76 %output
77 #:svn-command ',command))))
78 (build-expression->derivation store (or name "svn-checkout") builder
79 #:system system
80 #:local-build? #t
81 #:inputs `(("svn" ,svn-for-build))
82 #:hash-algo hash-algo
83 #:hash hash
84 #:recursive? #t
85 #:modules '((guix build svn)
86 (guix build utils))
87 #:guile-for-build guile-for-build
88 #:local-build? #t)))
89
90;;; svn-download.scm ends here