hg-download.scm 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014, 2015, 2016, 2017, 2019 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (guix hg-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 modules)
  25. #:use-module (guix packages)
  26. #:autoload (guix build-system gnu) (standard-packages)
  27. #:use-module (ice-9 match)
  28. #:export (hg-reference
  29. hg-reference?
  30. hg-reference-url
  31. hg-reference-changeset
  32. hg-reference-recursive?
  33. hg-fetch))
  34. ;;; Commentary:
  35. ;;;
  36. ;;; An <origin> method that fetches a specific changeset from a Mercurial
  37. ;;; repository. The repository URL and changeset ID are specified with a
  38. ;;; <hg-reference> object.
  39. ;;;
  40. ;;; Code:
  41. (define-record-type* <hg-reference>
  42. hg-reference make-hg-reference
  43. hg-reference?
  44. (url hg-reference-url)
  45. (changeset hg-reference-changeset))
  46. (define (hg-package)
  47. "Return the default Mercurial package."
  48. (let ((distro (resolve-interface '(gnu packages version-control))))
  49. (module-ref distro 'mercurial)))
  50. (define* (hg-fetch ref hash-algo hash
  51. #:optional name
  52. #:key (system (%current-system)) (guile (default-guile))
  53. (hg (hg-package)))
  54. "Return a fixed-output derivation that fetches REF, a <hg-reference>
  55. object. The output is expected to have recursive hash HASH of type
  56. HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
  57. (define guile-zlib
  58. (module-ref (resolve-interface '(gnu packages guile)) 'guile-zlib))
  59. (define modules
  60. (delete '(guix config)
  61. (source-module-closure '((guix build hg)
  62. (guix build download-nar)))))
  63. (define build
  64. (with-imported-modules modules
  65. (with-extensions (list guile-zlib)
  66. #~(begin
  67. (use-modules (guix build hg)
  68. (guix build download-nar))
  69. (or (hg-fetch '#$(hg-reference-url ref)
  70. '#$(hg-reference-changeset ref)
  71. #$output
  72. #:hg-command (string-append #+hg "/bin/hg"))
  73. (download-nar #$output))))))
  74. (mlet %store-monad ((guile (package->derivation guile system)))
  75. (gexp->derivation (or name "hg-checkout") build
  76. #:leaked-env-vars '("http_proxy" "https_proxy"
  77. "LC_ALL" "LC_MESSAGES" "LANG"
  78. "COLUMNS")
  79. #:system system
  80. #:local-build? #t ;don't offload repo cloning
  81. #:hash-algo hash-algo
  82. #:hash hash
  83. #:recursive? #t
  84. #:guile-for-build guile)))
  85. ;;; hg-download.scm ends here