gnu.scm 4.8 KB

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