1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (guix import gnu)
20 #:use-module (guix gnu-maintenance)
21 #:use-module (guix import utils)
22 #:use-module (guix utils)
23 #:use-module (guix store)
24 #:use-module (gcrypt hash)
25 #:use-module (guix base32)
26 #:use-module (guix upstream)
27 #:use-module (srfi srfi-1)
28 #:use-module (srfi srfi-11)
29 #:use-module (srfi srfi-26)
30 #:use-module (srfi srfi-34)
31 #:use-module (srfi srfi-35)
32 #:use-module (web uri)
33 #:use-module (ice-9 match)
34 #:use-module (ice-9 regex)
35 #:export (gnu->guix-package))
39 ;;; Generate a package declaration template for the latest version of a GNU
40 ;;; package, using meta-data available upstream for the package.
44 (define (qualified-url url)
45 "Return a fully-qualified URL based on URL."
46 (if (string-prefix? "/" url)
47 (string-append "http://www.gnu.org" 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")))
55 (define* (gnu-package->sexp package release
56 #:key (key-download 'interactive))
57 "Return the 'package' sexp for the RELEASE (a <gnu-release>) of PACKAGE (a
58 <gnu-package>), or #f upon failure. Use KEY-DOWNLOAD as the OpenPGP key
59 download policy (see 'download-tarball' for details.)"
61 (gnu-package-name package))
64 ;; XXX: We assume that RELEASE's directory starts with "/gnu".
65 (string-append "mirror:/"
66 (match (upstream-source-urls release)
68 (dirname (uri-path (string->uri url)))))
72 (preferred-archive-type release))
75 (find (cut string-suffix? archive-type <>)
76 (upstream-source-urls release)))
79 (find (cute string-suffix? (string-append archive-type ".sig") <>)
80 (upstream-source-signature-urls release)))
83 (match (download-tarball store url sig-url
84 #:key-download key-download)
88 (version ,(upstream-source-version release))
91 (uri (string-append ,url-base version
92 ,(string-append ".tar." archive-type)))
95 ,(bytevector->nix-base32-string
96 (file-sha256 tarball))))))
97 (build-system gnu-build-system)
98 (synopsis ,(gnu-package-doc-summary package))
99 (description ,(gnu-package-doc-description package))
100 (home-page ,(match (gnu-package-doc-urls package)
101 ((head . tail) (qualified-url head))))
102 (license find-by-yourself!)))
103 (#f ;failure to download or authenticate the tarball
106 (define* (gnu->guix-package name
107 #:key (key-download 'interactive))
108 "Return the package declaration for NAME as an s-expression. Use
109 KEY-DOWNLOAD as the OpenPGP key download policy (see 'download-tarball' for
111 (match (latest-release name)
112 ((? upstream-source? release)
113 (let ((version (upstream-source-version release)))
114 (match (find-package name)
118 (message "couldn't find meta-data for GNU package")))))
120 (gnu-package->sexp info release #:key-download key-download)))))
125 "failed to determine latest release of GNU package")))))))
127 ;;; gnu.scm ends here