1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (guix git-download)
20 #:use-module (guix gexp)
21 #:use-module (guix store)
22 #:use-module (guix monads)
23 #:use-module (guix records)
24 #:use-module (guix packages)
25 #:autoload (guix build-system gnu) (standard-packages)
26 #:use-module (ice-9 match)
27 #:export (git-reference
31 git-reference-recursive?
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>
43 (define-record-type* <git-reference>
44 git-reference make-git-reference
46 (url git-reference-url)
47 (commit git-reference-commit)
48 (recursive? git-reference-recursive? ; whether to recurse into sub-modules
52 "Return the default Git package."
53 (let ((distro (resolve-interface '(gnu packages version-control))))
54 (module-ref distro 'git)))
56 (define* (git-fetch ref hash-algo hash
58 #:key (system (%current-system)) (guile (default-guile))
60 "Return a fixed-output derivation that fetches REF, a <git-reference>
61 object. The output is expected to have recursive hash HASH of type
62 HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
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)
72 (use-modules (guix build git)
76 ;; The 'git submodule' commands expects Coreutils, sed,
77 ;; grep, etc. to be in $PATH.
78 (set-path-environment-variable "PATH" '("bin")
83 (git-fetch '#$(git-reference-url ref)
84 '#$(git-reference-commit ref)
86 #:recursive? '#$(git-reference-recursive? ref)
87 #:git-command (string-append #+git "/bin/git"))))
89 (mlet %store-monad ((guile (package->derivation guile system)))
90 (gexp->derivation (or name "git-checkout") build
92 ;; FIXME: See <https://bugs.gnu.org/18747>.
97 #:modules '((guix build git)
99 #:guile-for-build guile
102 ;;; git-download.scm ends here