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) | |
6119ebf1 LC |
20 | #:use-module (guix gexp) |
21 | #:use-module (guix monads) | |
9b5b5c17 | 22 | #:use-module (guix records) |
9b5b5c17 | 23 | #:use-module (guix packages) |
6750877f | 24 | #:autoload (guix build-system gnu) (standard-inputs) |
9b5b5c17 LC |
25 | #:use-module (ice-9 match) |
26 | #:export (git-reference | |
27 | git-reference? | |
28 | git-reference-url | |
29 | git-reference-commit | |
6750877f | 30 | git-reference-recursive? |
9b5b5c17 LC |
31 | |
32 | git-fetch)) | |
33 | ||
34 | ;;; Commentary: | |
35 | ;;; | |
36 | ;;; An <origin> method that fetches a specific commit from a Git repository. | |
37 | ;;; The repository URL and commit hash are specified with a <git-reference> | |
38 | ;;; object. | |
39 | ;;; | |
40 | ;;; Code: | |
41 | ||
42 | (define-record-type* <git-reference> | |
43 | git-reference make-git-reference | |
44 | git-reference? | |
6750877f LC |
45 | (url git-reference-url) |
46 | (commit git-reference-commit) | |
47 | (recursive? git-reference-recursive? ; whether to recurse into sub-modules | |
48 | (default #f))) | |
9b5b5c17 | 49 | |
6119ebf1 LC |
50 | (define (git-package) |
51 | "Return the default Git package." | |
52 | (let ((distro (resolve-interface '(gnu packages version-control)))) | |
53 | (module-ref distro 'git))) | |
54 | ||
9b5b5c17 LC |
55 | (define* (git-fetch store ref hash-algo hash |
56 | #:optional name | |
6119ebf1 LC |
57 | #:key (system (%current-system)) guile |
58 | (git (git-package))) | |
9b5b5c17 LC |
59 | "Return a fixed-output derivation in STORE that fetches REF, a |
60 | <git-reference> object. The output is expected to have recursive hash HASH of | |
61 | type HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if | |
62 | #f." | |
63 | (define guile-for-build | |
64 | (match guile | |
65 | ((? package?) | |
66 | (package-derivation store guile system)) | |
67 | (#f ; the default | |
bdb36958 | 68 | (let* ((distro (resolve-interface '(gnu packages commencement))) |
9b5b5c17 LC |
69 | (guile (module-ref distro 'guile-final))) |
70 | (package-derivation store guile system))))) | |
71 | ||
6750877f LC |
72 | (define inputs |
73 | ;; When doing 'git clone --recursive', we need sed, grep, etc. to be | |
74 | ;; available so that 'git submodule' works. | |
75 | (if (git-reference-recursive? ref) | |
76 | (standard-inputs (%current-system)) | |
77 | '())) | |
78 | ||
6119ebf1 LC |
79 | (define build |
80 | #~(begin | |
81 | (use-modules (guix build git) | |
82 | (guix build utils) | |
83 | (ice-9 match)) | |
84 | ||
85 | ;; The 'git submodule' commands expects Coreutils, sed, | |
86 | ;; grep, etc. to be in $PATH. | |
87 | (set-path-environment-variable "PATH" '("bin") | |
88 | (match '#$inputs | |
89 | (((names dirs) ...) | |
90 | dirs))) | |
6750877f | 91 | |
6119ebf1 LC |
92 | (git-fetch '#$(git-reference-url ref) |
93 | '#$(git-reference-commit ref) | |
94 | #$output | |
95 | #:recursive? '#$(git-reference-recursive? ref) | |
96 | #:git-command (string-append #$git "/bin/git")))) | |
6750877f | 97 | |
6119ebf1 LC |
98 | (run-with-store store |
99 | (gexp->derivation (or name "git-checkout") build | |
100 | #:system system | |
101 | #:local-build? #t | |
102 | #:hash-algo hash-algo | |
103 | #:hash hash | |
104 | #:recursive? #t | |
105 | #:modules '((guix build git) | |
106 | (guix build utils)) | |
107 | #:guile-for-build guile-for-build | |
108 | #:local-build? #t) | |
109 | #:guile-for-build guile-for-build | |
110 | #:system system)) | |
9b5b5c17 LC |
111 | |
112 | ;;; git-download.scm ends here |