You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

113 lines
4.0 KiB

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