build: syscalls: Properly handle clone errors.
[jackhill/guix/guix.git] / guix / git-download.scm
CommitLineData
9b5b5c17 1;;; GNU Guix --- Functional package management for GNU
e87f0591 2;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
9b5b5c17
LC
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 20 #:use-module (guix gexp)
e87f0591 21 #:use-module (guix store)
6119ebf1 22 #:use-module (guix monads)
9b5b5c17 23 #:use-module (guix records)
9b5b5c17 24 #:use-module (guix packages)
0d5a559f 25 #:autoload (guix build-system gnu) (standard-packages)
9b5b5c17
LC
26 #:use-module (ice-9 match)
27 #:export (git-reference
28 git-reference?
29 git-reference-url
30 git-reference-commit
6750877f 31 git-reference-recursive?
9b5b5c17
LC
32
33 git-fetch))
34
35;;; Commentary:
36;;;
37;;; An <origin> method that fetches a specific commit from a Git repository.
38;;; The repository URL and commit hash are specified with a <git-reference>
39;;; object.
40;;;
41;;; Code:
42
43(define-record-type* <git-reference>
44 git-reference make-git-reference
45 git-reference?
6750877f
LC
46 (url git-reference-url)
47 (commit git-reference-commit)
48 (recursive? git-reference-recursive? ; whether to recurse into sub-modules
49 (default #f)))
9b5b5c17 50
6119ebf1
LC
51(define (git-package)
52 "Return the default Git package."
53 (let ((distro (resolve-interface '(gnu packages version-control))))
54 (module-ref distro 'git)))
55
f220a838 56(define* (git-fetch ref hash-algo hash
9b5b5c17 57 #:optional name
f220a838 58 #:key (system (%current-system)) (guile (default-guile))
6119ebf1 59 (git (git-package)))
f220a838
LC
60 "Return a fixed-output derivation that fetches REF, a <git-reference>
61object. The output is expected to have recursive hash HASH of type
62HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
6750877f
LC
63 (define inputs
64 ;; When doing 'git clone --recursive', we need sed, grep, etc. to be
65 ;; available so that 'git submodule' works.
66 (if (git-reference-recursive? ref)
0d5a559f 67 (standard-packages)
6750877f
LC
68 '()))
69
6119ebf1
LC
70 (define build
71 #~(begin
72 (use-modules (guix build git)
73 (guix build utils)
74 (ice-9 match))
75
76 ;; The 'git submodule' commands expects Coreutils, sed,
77 ;; grep, etc. to be in $PATH.
78 (set-path-environment-variable "PATH" '("bin")
1590e8a1 79 (match '#+inputs
6119ebf1
LC
80 (((names dirs) ...)
81 dirs)))
6750877f 82
6119ebf1
LC
83 (git-fetch '#$(git-reference-url ref)
84 '#$(git-reference-commit ref)
85 #$output
86 #:recursive? '#$(git-reference-recursive? ref)
1590e8a1 87 #:git-command (string-append #+git "/bin/git"))))
6750877f 88
f220a838 89 (mlet %store-monad ((guile (package->derivation guile system)))
6119ebf1
LC
90 (gexp->derivation (or name "git-checkout") build
91 #:system system
347e17b4 92 ;; FIXME: See <https://bugs.gnu.org/18747>.
4a6aeb67 93 ;; Uncomment when fixed daemons are widely deployed.
347e17b4 94 ;;#:local-build? #t
6119ebf1
LC
95 #:hash-algo hash-algo
96 #:hash hash
97 #:recursive? #t
98 #:modules '((guix build git)
99 (guix build utils))
f220a838
LC
100 #:guile-for-build guile
101 #:local-build? #t)))
9b5b5c17
LC
102
103;;; git-download.scm ends here