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.
 
 
 
 
 
 

128 lines
4.6 KiB

  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014, 2015, 2016 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 import gnu)
  19. #:use-module (guix gnu-maintenance)
  20. #:use-module (guix import utils)
  21. #:use-module (guix utils)
  22. #:use-module (guix store)
  23. #:use-module (gcrypt hash)
  24. #:use-module (guix base32)
  25. #:use-module (guix upstream)
  26. #:use-module (srfi srfi-1)
  27. #:use-module (srfi srfi-11)
  28. #:use-module (srfi srfi-26)
  29. #:use-module (srfi srfi-34)
  30. #:use-module (srfi srfi-35)
  31. #:use-module (web uri)
  32. #:use-module (ice-9 match)
  33. #:use-module (ice-9 regex)
  34. #:export (gnu->guix-package))
  35. ;;; Commentary:
  36. ;;;
  37. ;;; Generate a package declaration template for the latest version of a GNU
  38. ;;; package, using meta-data available upstream for the package.
  39. ;;;
  40. ;;; Code:
  41. (define (qualified-url url)
  42. "Return a fully-qualified URL based on URL."
  43. (if (string-prefix? "/" url)
  44. (string-append "http://www.gnu.org" url)
  45. url))
  46. (define (preferred-archive-type release)
  47. "Return the preferred type of archive for downloading RELEASE."
  48. (find (cute member <> (upstream-source-archive-types release))
  49. '("xz" "lz" "bz2" "tbz2" "gz" "tgz" "Z")))
  50. (define* (gnu-package->sexp package release
  51. #:key (key-download 'interactive))
  52. "Return the 'package' sexp for the RELEASE (a <gnu-release>) of PACKAGE (a
  53. <gnu-package>), or #f upon failure. Use KEY-DOWNLOAD as the OpenPGP key
  54. download policy (see 'download-tarball' for details.)"
  55. (define name
  56. (gnu-package-name package))
  57. (define url-base
  58. ;; XXX: We assume that RELEASE's directory starts with "/gnu".
  59. (string-append "mirror:/"
  60. (match (upstream-source-urls release)
  61. ((url rest ...)
  62. (dirname (uri-path (string->uri url)))))
  63. "/" name "-"))
  64. (define archive-type
  65. (preferred-archive-type release))
  66. (define url
  67. (find (cut string-suffix? archive-type <>)
  68. (upstream-source-urls release)))
  69. (define sig-url
  70. (find (cute string-suffix? (string-append archive-type ".sig") <>)
  71. (upstream-source-signature-urls release)))
  72. (with-store store
  73. (match (download-tarball store url sig-url
  74. #:key-download key-download)
  75. ((? string? tarball)
  76. `(package
  77. (name ,name)
  78. (version ,(upstream-source-version release))
  79. (source (origin
  80. (method url-fetch)
  81. (uri (string-append ,url-base version
  82. ,(string-append ".tar." archive-type)))
  83. (sha256
  84. (base32
  85. ,(bytevector->nix-base32-string
  86. (file-sha256 tarball))))))
  87. (build-system gnu-build-system)
  88. (synopsis ,(gnu-package-doc-summary package))
  89. (description ,(gnu-package-doc-description package))
  90. (home-page ,(match (gnu-package-doc-urls package)
  91. ((head . tail) (qualified-url head))))
  92. (license find-by-yourself!)))
  93. (#f ;failure to download or authenticate the tarball
  94. #f))))
  95. (define* (gnu->guix-package name
  96. #:key (key-download 'interactive))
  97. "Return the package declaration for NAME as an s-expression. Use
  98. KEY-DOWNLOAD as the OpenPGP key download policy (see 'download-tarball' for
  99. details.)"
  100. (match (latest-release name)
  101. ((? upstream-source? release)
  102. (let ((version (upstream-source-version release)))
  103. (match (find-package name)
  104. (#f
  105. (raise (condition
  106. (&message
  107. (message "couldn't find meta-data for GNU package")))))
  108. (info
  109. (gnu-package->sexp info release #:key-download key-download)))))
  110. (_
  111. (raise (condition
  112. (&message
  113. (message
  114. "failed to determine latest release of GNU package")))))))
  115. ;;; gnu.scm ends here