gnu: gnupg: Upgrade to 2.0.22.
[jackhill/guix/guix.git] / guix / download.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
483f1158 2;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
149acc29 3;;; Copyright © 2013 Andreas Enge <andreas@enge.fr>
62cab99c 4;;;
233e7676 5;;; This file is part of GNU Guix.
62cab99c 6;;;
233e7676 7;;; GNU Guix is free software; you can redistribute it and/or modify it
62cab99c
LC
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
233e7676 12;;; GNU Guix is distributed in the hope that it will be useful, but
62cab99c
LC
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
233e7676 18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
62cab99c
LC
19
20(define-module (guix download)
21 #:use-module (ice-9 match)
22 #:use-module (guix derivations)
23 #:use-module (guix packages)
861693f3
LC
24 #:use-module ((guix store) #:select (derivation-path? add-to-store))
25 #:use-module ((guix build download) #:renamer (symbol-prefix-proc 'build:))
62cab99c 26 #:use-module (guix utils)
483f1158 27 #:use-module (srfi srfi-1)
94d222ad 28 #:use-module (srfi srfi-26)
ec4d308a 29 #:export (%mirrors
861693f3
LC
30 url-fetch
31 download-to-store))
62cab99c
LC
32
33;;; Commentary:
34;;;
35;;; Produce fixed-output derivations with data fetched over HTTP or FTP.
36;;;
37;;; Code:
38
94d222ad
LC
39(define %mirrors
40 ;; Mirror lists used when `mirror://' URLs are passed.
41 (let* ((gnu-mirrors
42 '(;; This one redirects to a (supposedly) nearby and (supposedly)
43 ;; up-to-date mirror.
44 "http://ftpmirror.gnu.org/"
45
46 "ftp://ftp.cs.tu-berlin.de/pub/gnu/"
94d222ad
LC
47 "ftp://ftp.funet.fi/pub/mirrors/ftp.gnu.org/gnu/"
48
49 ;; This one is the master repository, and thus it's always
50 ;; up-to-date.
51 "http://ftp.gnu.org/pub/gnu/")))
52 `((gnu ,@gnu-mirrors)
53 (gcc
54 "ftp://ftp.nluug.nl/mirror/languages/gcc/"
55 "ftp://ftp.fu-berlin.de/unix/languages/gcc/"
56 "ftp://ftp.irisa.fr/pub/mirrors/gcc.gnu.org/gcc/"
57 "ftp://gcc.gnu.org/pub/gcc/"
58 ,@(map (cut string-append <> "/gcc") gnu-mirrors))
59 (gnupg
60 "ftp://gd.tuwien.ac.at/privacy/gnupg/"
61 "ftp://gnupg.x-zone.org/pub/gnupg/"
62 "ftp://ftp.gnupg.cz/pub/gcrypt/"
63 "ftp://sunsite.dk/pub/security/gcrypt/"
64 "http://gnupg.wildyou.net/"
65 "http://ftp.gnupg.zone-h.org/"
66 "ftp://ftp.jyu.fi/pub/crypt/gcrypt/"
67 "ftp://trumpetti.atm.tut.fi/gcrypt/"
68 "ftp://mirror.cict.fr/gnupg/"
69 "ftp://ftp.strasbourg.linuxfr.org/pub/gnupg/")
71eb5c10
LC
70 (gnome
71 "http://ftp.belnet.be/ftp.gnome.org/"
72 "http://ftp.linux.org.uk/mirrors/ftp.gnome.org/"
73 "http://ftp.gnome.org/pub/GNOME/"
74 "http://mirror.yandex.ru/mirrors/ftp.gnome.org/")
94d222ad 75 (savannah
a4eabecd 76 "http://download.savannah.gnu.org/releases/"
94d222ad
LC
77 "ftp://ftp.twaren.net/Unix/NonGNU/"
78 "ftp://mirror.csclub.uwaterloo.ca/nongnu/"
79 "ftp://mirror.publicns.net/pub/nongnu/"
80 "ftp://savannah.c3sl.ufpr.br/"
81 "http://ftp.cc.uoc.gr/mirrors/nongnu.org/"
82 "http://ftp.twaren.net/Unix/NonGNU/"
83 "http://mirror.csclub.uwaterloo.ca/nongnu/"
84 "http://nongnu.askapache.com/"
85 "http://savannah.c3sl.ufpr.br/"
3bba7b0a
LC
86 "http://www.centervenus.com/mirrors/nongnu/"
87 "http://download.savannah.gnu.org/releases-noredirect/")
94d222ad
LC
88 (sourceforge
89 "http://prdownloads.sourceforge.net/"
90 "http://heanet.dl.sourceforge.net/sourceforge/"
91 "http://surfnet.dl.sourceforge.net/sourceforge/"
92 "http://dfn.dl.sourceforge.net/sourceforge/"
93 "http://mesh.dl.sourceforge.net/sourceforge/"
94 "http://ovh.dl.sourceforge.net/sourceforge/"
c43e0061 95 "http://osdn.dl.sourceforge.net/sourceforge/")
b40b259f
LC
96 (kernel.org
97 "http://www.all.kernel.org/pub/"
98 "http://ramses.wh2.tu-dresden.de/pub/mirrors/kernel.org/"
99 "http://linux-kernel.uio.no/pub/"
100 "http://kernel.osuosl.org/pub/"
5d9cd707
LC
101 "ftp://ftp.funet.fi/pub/mirrors/ftp.kernel.org/pub/"
102 "http://ftp.be.debian.org/pub/"
103 "http://mirror.linux.org.au/")
47f9db41
LC
104 (apache ; from http://www.apache.org/mirrors/dist.html
105 "http://www.eu.apache.org/dist/"
106 "http://www.us.apache.org/dist/"
107 "ftp://gd.tuwien.ac.at/pub/infosys/servers/http/apache/dist/"
108 "http://apache.belnet.be/"
109 "http://mirrors.ircam.fr/pub/apache/"
149acc29
AE
110 "http://apache-mirror.rbc.ru/pub/apache/")
111 (xorg ; from http://www.x.org/wiki/Releases/Download
0820a58b 112 "http://www.x.org/releases/" ; main mirrors
149acc29
AE
113 "ftp://mirror.csclub.uwaterloo.ca/x.org/" ; North America
114 "ftp://xorg.mirrors.pair.com/"
115 "http://mirror.csclub.uwaterloo.ca/x.org/"
116 "http://xorg.mirrors.pair.com/"
117 "http://mirror.us.leaseweb.net/xorg/"
118 "ftp://artfiles.org/x.org/" ; Europe
119 "ftp://ftp.chg.ru/pub/X11/x.org/"
120 "ftp://ftp.fu-berlin.de/unix/X11/FTP.X.ORG/"
121 "ftp://ftp.gwdg.de/pub/x11/x.org/"
122 "ftp://ftp.mirrorservice.org/sites/ftp.x.org/"
123 "ftp://ftp.ntua.gr/pub/X11/"
124 "ftp://ftp.piotrkosoft.net/pub/mirrors/ftp.x.org/"
125 "ftp://ftp.portal-to-web.de/pub/mirrors/x.org/"
126 "ftp://ftp.solnet.ch/mirror/x.org/"
127 "ftp://ftp.sunet.se/pub/X11/"
128 "ftp://gd.tuwien.ac.at/X11/"
129 "ftp://mi.mirror.garr.it/mirrors/x.org/"
130 "ftp://mirror.cict.fr/x.org/"
131 "ftp://mirror.switch.ch/mirror/X11/"
132 "ftp://mirrors.ircam.fr/pub/x.org/"
133 "ftp://x.mirrors.skynet.be/pub/ftp.x.org/"
134 "ftp://ftp.cs.cuhk.edu.hk/pub/X11" ; East Asia
135 "ftp://ftp.u-aizu.ac.jp/pub/x11/x.org/"
136 "ftp://ftp.yz.yamagata-u.ac.jp/pub/X11/x.org/"
137 "ftp://ftp.kaist.ac.kr/x.org/"
138 "ftp://mirrors.go-part.com/xorg/"
139 "http://x.cs.pu.edu.tw/"
6af31019
LC
140 "ftp://ftp.is.co.za/pub/x.org") ; South Africa
141 (cpan ; from http://www.cpan.org/SITES.html
142 "http://cpan.enstimac.fr/"
143 "ftp://ftp.ciril.fr/pub/cpan/"
144 "ftp://artfiles.org/cpan.org/"
145 "http://www.cpan.org/"
146 "ftp://cpan.rinet.ru/pub/mirror/CPAN/"
147 "http://cpan.cu.be/"
148 "ftp://cpan.inode.at/"
149 "ftp://cpan.iht.co.il/"
150 "ftp://ftp.osuosl.org/pub/CPAN/"
151 "ftp://ftp.nara.wide.ad.jp/pub/CPAN/"
152 "http://mirrors.163.com/cpan/"
7fa37abc
LC
153 "ftp://cpan.mirror.ac.za/")
154 (imagemagick ; from http://www.imagemagick.org/script/download.php
155 "http://mirror.checkdomain.de/imagemagick/"
156 "ftp://gd.tuwien.ac.at/pub/graphics/ImageMagick/"
157 "http://www.imagemagick.org/download"
158 "ftp://mirror.searchdaimon.com/ImageMagick"
159 "http://mirror.is.co.za/pub/imagemagick/"
160 "ftp://mirror.aarnet.edu.au/pub/imagemagick/"))))
94d222ad 161
483f1158
LC
162(define (gnutls-derivation store system)
163 "Return the GnuTLS derivation for SYSTEM."
164 (let* ((module (resolve-interface '(gnu packages gnutls)))
165 (gnutls (module-ref module 'gnutls)))
166 (package-derivation store gnutls system)))
94d222ad 167
62cab99c
LC
168(define* (url-fetch store url hash-algo hash
169 #:optional name
94d222ad
LC
170 #:key (system (%current-system)) guile
171 (mirrors %mirrors))
62cab99c
LC
172 "Return the path of a fixed-output derivation in STORE that fetches
173URL (a string, or a list of strings denoting alternate URLs), which is
174expected to have hash HASH of type HASH-ALGO (a symbol). By default,
175the file name is the base name of URL; optionally, NAME can specify a
94d222ad
LC
176different file name.
177
178When one of the URL starts with mirror://, then its host part is
179interpreted as the name of a mirror scheme, taken from MIRRORS; MIRRORS
180must be a list of symbol/URL-list pairs."
62cab99c
LC
181 (define builder
182 `(begin
183 (use-modules (guix build download))
94d222ad
LC
184 (url-fetch ',url %output
185 #:mirrors ',mirrors)))
62cab99c
LC
186
187 (define guile-for-build
188 (match guile
189 ((? package?)
190 (package-derivation store guile system))
191 ((and (? string?) (? derivation-path?))
192 guile)
193 (#f ; the default
1ffa7090 194 (let* ((distro (resolve-interface '(gnu packages base)))
62cab99c
LC
195 (guile (module-ref distro 'guile-final)))
196 (package-derivation store guile system)))))
197
198 (define file-name
199 (match url
200 ((head _ ...)
201 (basename head))
202 (_
203 (basename url))))
204
483f1158
LC
205 (define need-gnutls?
206 ;; True if any of the URLs need TLS support.
207 (let ((https? (cut string-prefix? "https://" <>)))
208 (match url
209 ((? string?)
210 (https? url))
211 ((url ...)
212 (any https? url)))))
213
59688fc4
LC
214 (let* ((gnutls-drv (if need-gnutls?
215 (gnutls-derivation store system)
216 (values #f #f)))
217 (gnutls (and gnutls-drv
218 (derivation->output-path gnutls-drv "out")))
219 (env-vars (if gnutls
220 (let ((dir (string-append gnutls "/share/guile/site")))
221 ;; XXX: `GUILE_LOAD_COMPILED_PATH' is overridden
222 ;; by `build-expression->derivation', so we can't
223 ;; set it here.
224 `(("GUILE_LOAD_PATH" . ,dir)))
225 '())))
483f1158
LC
226 (build-expression->derivation store (or name file-name) system
227 builder
228 (if gnutls-drv
59688fc4 229 `(("gnutls" ,gnutls-drv))
483f1158
LC
230 '())
231 #:hash-algo hash-algo
232 #:hash hash
233 #:modules '((guix build download)
234 (guix build utils)
235 (guix ftp-client))
236 #:guile-for-build guile-for-build
237 #:env-vars env-vars)))
62cab99c 238
861693f3
LC
239(define* (download-to-store store url #:optional (name (basename url))
240 #:key (log (current-error-port)))
241 "Download from URL to STORE, either under NAME or URL's basename if
242omitted. Write progress reports to LOG."
243 (call-with-temporary-output-file
244 (lambda (temp port)
245 (let ((result
246 (parameterize ((current-output-port log))
247 (build:url-fetch url temp #:mirrors %mirrors))))
248 (close port)
249 (and result
250 (add-to-store store name #f "sha256" temp))))))
251
62cab99c 252;;; download.scm ends here