Commit | Line | Data |
---|---|---|
9b5b5c17 LC |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2014 Ludovic Courtès <ludo@gnu.org> | |
3 | ;;; | |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
7 | ;;; under the terms of the GNU General Public License as published by | |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
19 | (define-module (guix git-download) | |
20 | #:use-module (guix records) | |
21 | #:use-module (guix derivations) | |
22 | #:use-module (guix packages) | |
23 | #:use-module (ice-9 match) | |
24 | #:export (git-reference | |
25 | git-reference? | |
26 | git-reference-url | |
27 | git-reference-commit | |
28 | ||
29 | git-fetch)) | |
30 | ||
31 | ;;; Commentary: | |
32 | ;;; | |
33 | ;;; An <origin> method that fetches a specific commit from a Git repository. | |
34 | ;;; The repository URL and commit hash are specified with a <git-reference> | |
35 | ;;; object. | |
36 | ;;; | |
37 | ;;; Code: | |
38 | ||
39 | (define-record-type* <git-reference> | |
40 | git-reference make-git-reference | |
41 | git-reference? | |
42 | (url git-reference-url) | |
43 | (commit git-reference-commit)) | |
44 | ||
45 | (define* (git-fetch store ref hash-algo hash | |
46 | #:optional name | |
47 | #:key (system (%current-system)) guile git) | |
48 | "Return a fixed-output derivation in STORE that fetches REF, a | |
49 | <git-reference> object. The output is expected to have recursive hash HASH of | |
50 | type 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 git-for-build | |
62 | (match git | |
63 | ((? package?) | |
64 | (package-derivation store git system)) | |
65 | (#f ; the default | |
66 | (let* ((distro (resolve-interface '(gnu packages version-control))) | |
67 | (git (module-ref distro 'git))) | |
68 | (package-derivation store git system))))) | |
69 | ||
70 | (let* ((command (string-append (derivation->output-path git-for-build) | |
71 | "/bin/git")) | |
72 | (builder `(begin | |
73 | (use-modules (guix build git)) | |
74 | (git-fetch ',(git-reference-url ref) | |
75 | ',(git-reference-commit ref) | |
76 | %output | |
77 | #:git-command ',command)))) | |
78 | (build-expression->derivation store (or name "git-checkout") builder | |
79 | #:system system | |
80 | #:local-build? #t | |
81 | #:inputs `(("git" ,git-for-build)) | |
82 | #:hash-algo hash-algo | |
83 | #:hash hash | |
84 | #:recursive? #t | |
85 | #:modules '((guix build git) | |
86 | (guix build utils)) | |
87 | #:guile-for-build guile-for-build))) | |
88 | ||
89 | ;;; git-download.scm ends here |