1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015 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 (guix 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>). Use KEY-DOWNLOAD as the OpenPGP key download policy (see
59 '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)))
82 (let ((tarball (with-store store
83 (download-tarball store url sig-url
84 #:key-download key-download))))
87 (version ,(upstream-source-version release))
90 (uri (string-append ,url-base version
91 ,(string-append ".tar." archive-type)))
94 ,(bytevector->nix-base32-string (file-sha256 tarball))))))
95 (build-system gnu-build-system)
96 (synopsis ,(gnu-package-doc-summary package))
97 (description ,(gnu-package-doc-description package))
98 (home-page ,(match (gnu-package-doc-urls package)
99 ((head . tail) (qualified-url head))))
100 (license find-by-yourself!))))
102 (define* (gnu->guix-package name
103 #:key (key-download 'interactive))
104 "Return the package declaration for NAME as an s-expression. Use
105 KEY-DOWNLOAD as the OpenPGP key download policy (see 'download-tarball' for
107 (match (latest-release name)
108 ((? upstream-source? release)
109 (let ((version (upstream-source-version release)))
110 (match (find-packages (regexp-quote name))
112 (gnu-package->sexp info release #:key-download key-download))
116 (message "couldn't find meta-data for GNU package"))))))))
121 "failed to determine latest release of GNU package")))))))
123 ;;; gnu.scm ends here