hg-download.scm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 zlib
  58. (module-ref (resolve-interface '(gnu packages compression)) 'zlib))
  59. (define config.scm
  60. (scheme-file "config.scm"
  61. #~(begin
  62. (define-module (guix config)
  63. #:export (%libz))
  64. (define %libz
  65. #+(file-append zlib "/lib/libz")))))
  66. (define modules
  67. (cons `((guix config) => ,config.scm)
  68. (delete '(guix config)
  69. (source-module-closure '((guix build hg)
  70. (guix build download-nar))))))
  71. (define build
  72. (with-imported-modules modules
  73. #~(begin
  74. (use-modules (guix build hg)
  75. (guix build download-nar))
  76. (or (hg-fetch '#$(hg-reference-url ref)
  77. '#$(hg-reference-changeset ref)
  78. #$output
  79. #:hg-command (string-append #+hg "/bin/hg"))
  80. (download-nar #$output)))))
  81. (mlet %store-monad ((guile (package->derivation guile system)))
  82. (gexp->derivation (or name "hg-checkout") build
  83. #:leaked-env-vars '("http_proxy" "https_proxy"
  84. "LC_ALL" "LC_MESSAGES" "LANG"
  85. "COLUMNS")
  86. #:system system
  87. #:local-build? #t ;don't offload repo cloning
  88. #:hash-algo hash-algo
  89. #:hash hash
  90. #:recursive? #t
  91. #:guile-for-build guile)))
  92. ;;; hg-download.scm ends here