gnu.scm 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
  4. ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (guix import gnu)
  21. #:use-module ((guix diagnostics) #:select (formatted-message))
  22. #:use-module (guix gnu-maintenance)
  23. #:use-module (guix import utils)
  24. #:use-module (guix i18n)
  25. #:use-module (guix store)
  26. #:use-module (gcrypt hash)
  27. #:use-module (guix base32)
  28. #:use-module (guix upstream)
  29. #:use-module (srfi srfi-1)
  30. #:use-module (srfi srfi-26)
  31. #:use-module (srfi srfi-34)
  32. #:use-module (srfi srfi-35)
  33. #:use-module (web uri)
  34. #:use-module (ice-9 match)
  35. #:export (gnu->guix-package))
  36. ;;; Commentary:
  37. ;;;
  38. ;;; Generate a package declaration template for the latest version of a GNU
  39. ;;; package, using meta-data available upstream for the package.
  40. ;;;
  41. ;;; Code:
  42. (define (qualified-url url)
  43. "Return a fully-qualified URL based on URL."
  44. (if (string-prefix? "/" url)
  45. (string-append "http://www.gnu.org" url)
  46. url))
  47. (define (preferred-archive-type release)
  48. "Return the preferred type of archive for downloading RELEASE."
  49. (find (cute member <> (upstream-source-archive-types release))
  50. '("xz" "lz" "bz2" "tbz2" "gz" "tgz" "Z")))
  51. (define* (gnu-package->sexp package release
  52. #:key (key-download 'interactive))
  53. "Return the 'package' sexp for the RELEASE (a <gnu-release>) of PACKAGE (a
  54. <gnu-package>), or #f upon failure. Use KEY-DOWNLOAD as the OpenPGP key
  55. download policy (see 'download-tarball' for details.)"
  56. (define name
  57. (gnu-package-name package))
  58. (define url-base
  59. ;; XXX: We assume that RELEASE's directory starts with "/gnu".
  60. (string-append "mirror:/"
  61. (match (upstream-source-urls release)
  62. ((url rest ...)
  63. (dirname (uri-path (string->uri url)))))
  64. "/" name "-"))
  65. (define archive-type
  66. (preferred-archive-type release))
  67. (define url
  68. (find (cut string-suffix? archive-type <>)
  69. (upstream-source-urls release)))
  70. (define sig-url
  71. (find (cute string-suffix? (string-append archive-type ".sig") <>)
  72. (upstream-source-signature-urls release)))
  73. (with-store store
  74. (match (download-tarball store url sig-url
  75. #:key-download key-download)
  76. ((? string? tarball)
  77. `(package
  78. (name ,name)
  79. (version ,(upstream-source-version release))
  80. (source (origin
  81. (method url-fetch)
  82. (uri (string-append ,url-base version
  83. ,(string-append ".tar." archive-type)))
  84. (sha256
  85. (base32
  86. ,(bytevector->nix-base32-string
  87. (file-sha256 tarball))))))
  88. (build-system gnu-build-system)
  89. (synopsis ,(gnu-package-doc-summary package))
  90. (description ,(beautify-description
  91. (gnu-package-doc-description package)))
  92. (home-page ,(match (gnu-package-doc-urls package)
  93. ((head . tail) (qualified-url head))))
  94. (license find-by-yourself!)))
  95. (#f ;failure to download or authenticate the tarball
  96. #f))))
  97. (define* (gnu->guix-package name
  98. #:key (key-download 'interactive)
  99. #:allow-other-keys)
  100. "Return the package declaration for NAME as an s-expression. Use
  101. KEY-DOWNLOAD as the OpenPGP key download policy (see 'download-tarball' for
  102. details.)"
  103. (let ((package (find-package name)))
  104. (unless package
  105. (raise (formatted-message (G_ "no GNU package found for ~a") name)))
  106. (match (import-release name)
  107. ((? upstream-source? release)
  108. (let ((version (upstream-source-version release)))
  109. (gnu-package->sexp package release #:key-download key-download)))
  110. (_
  111. (raise (formatted-message
  112. (G_ "failed to determine latest release of GNU ~a")
  113. name))))))
  114. ;;; gnu.scm ends here