gnu: python-setuptools: Update to 12.1.
[jackhill/guix/guix.git] / guix / download.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
e87f0591 2;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
6d763bdd 3;;; Copyright © 2013, 2014 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)
e87f0591 24 #:use-module (guix store)
b5b73a82 25 #:use-module ((guix build download) #:prefix build:)
6f8f8ccb
LC
26 #:use-module (guix monads)
27 #:use-module (guix gexp)
62cab99c 28 #:use-module (guix utils)
d8907ac4 29 #:use-module (web uri)
483f1158 30 #:use-module (srfi srfi-1)
94d222ad 31 #:use-module (srfi srfi-26)
ec4d308a 32 #:export (%mirrors
861693f3
LC
33 url-fetch
34 download-to-store))
62cab99c
LC
35
36;;; Commentary:
37;;;
38;;; Produce fixed-output derivations with data fetched over HTTP or FTP.
39;;;
40;;; Code:
41
94d222ad
LC
42(define %mirrors
43 ;; Mirror lists used when `mirror://' URLs are passed.
44 (let* ((gnu-mirrors
45 '(;; This one redirects to a (supposedly) nearby and (supposedly)
46 ;; up-to-date mirror.
47 "http://ftpmirror.gnu.org/"
48
49 "ftp://ftp.cs.tu-berlin.de/pub/gnu/"
94d222ad
LC
50 "ftp://ftp.funet.fi/pub/mirrors/ftp.gnu.org/gnu/"
51
52 ;; This one is the master repository, and thus it's always
53 ;; up-to-date.
54 "http://ftp.gnu.org/pub/gnu/")))
55 `((gnu ,@gnu-mirrors)
56 (gcc
57 "ftp://ftp.nluug.nl/mirror/languages/gcc/"
58 "ftp://ftp.fu-berlin.de/unix/languages/gcc/"
59 "ftp://ftp.irisa.fr/pub/mirrors/gcc.gnu.org/gcc/"
60 "ftp://gcc.gnu.org/pub/gcc/"
61 ,@(map (cut string-append <> "/gcc") gnu-mirrors))
62 (gnupg
63 "ftp://gd.tuwien.ac.at/privacy/gnupg/"
d57b88be 64 "ftp://mirrors.dotsrc.org/gcrypt/"
94d222ad 65 "ftp://mirror.cict.fr/gnupg/"
d57b88be
AE
66 "http://artfiles.org/gnupg.org"
67 "ftp://ftp.franken.de/pub/crypt/mirror/ftp.gnupg.org/gcrypt/"
68 "ftp://ftp.freenet.de/pub/ftp.gnupg.org/gcrypt/"
69 "http://www.crysys.hu/"
70 "ftp://ftp.hi.is/pub/mirrors/gnupg/"
71 "ftp://ftp.heanet.ie/mirrors/ftp.gnupg.org/gcrypt/"
72 "ftp://ftp.bit.nl/mirror/gnupg/"
73 "ftp://ftp.surfnet.nl/pub/security/gnupg/"
74 "ftp://ftp.iasi.roedu.net/pub/mirrors/ftp.gnupg.org/"
75 "ftp://ftp.sunet.se/pub/security/gnupg/"
76 "ftp://mirror.switch.ch/mirror/gnupg/"
77 "ftp://mirror.tje.me.uk/pub/mirrors/ftp.gnupg.org/"
78 "ftp://ftp.mirrorservice.org/sites/ftp.gnupg.org/gcrypt/"
79 "ftp://ftp.ring.gr.jp/pub/net/gnupg/"
80 "ftp://ftp.gnupg.org/gcrypt/")
71eb5c10
LC
81 (gnome
82 "http://ftp.belnet.be/ftp.gnome.org/"
83 "http://ftp.linux.org.uk/mirrors/ftp.gnome.org/"
84 "http://ftp.gnome.org/pub/GNOME/"
85 "http://mirror.yandex.ru/mirrors/ftp.gnome.org/")
94d222ad 86 (savannah
a4eabecd 87 "http://download.savannah.gnu.org/releases/"
94d222ad
LC
88 "ftp://ftp.twaren.net/Unix/NonGNU/"
89 "ftp://mirror.csclub.uwaterloo.ca/nongnu/"
90 "ftp://mirror.publicns.net/pub/nongnu/"
91 "ftp://savannah.c3sl.ufpr.br/"
92 "http://ftp.cc.uoc.gr/mirrors/nongnu.org/"
93 "http://ftp.twaren.net/Unix/NonGNU/"
94 "http://mirror.csclub.uwaterloo.ca/nongnu/"
95 "http://nongnu.askapache.com/"
96 "http://savannah.c3sl.ufpr.br/"
3bba7b0a
LC
97 "http://www.centervenus.com/mirrors/nongnu/"
98 "http://download.savannah.gnu.org/releases-noredirect/")
94d222ad
LC
99 (sourceforge
100 "http://prdownloads.sourceforge.net/"
101 "http://heanet.dl.sourceforge.net/sourceforge/"
102 "http://surfnet.dl.sourceforge.net/sourceforge/"
103 "http://dfn.dl.sourceforge.net/sourceforge/"
104 "http://mesh.dl.sourceforge.net/sourceforge/"
105 "http://ovh.dl.sourceforge.net/sourceforge/"
c43e0061 106 "http://osdn.dl.sourceforge.net/sourceforge/")
b40b259f
LC
107 (kernel.org
108 "http://www.all.kernel.org/pub/"
109 "http://ramses.wh2.tu-dresden.de/pub/mirrors/kernel.org/"
110 "http://linux-kernel.uio.no/pub/"
111 "http://kernel.osuosl.org/pub/"
5d9cd707
LC
112 "ftp://ftp.funet.fi/pub/mirrors/ftp.kernel.org/pub/"
113 "http://ftp.be.debian.org/pub/"
114 "http://mirror.linux.org.au/")
47f9db41
LC
115 (apache ; from http://www.apache.org/mirrors/dist.html
116 "http://www.eu.apache.org/dist/"
117 "http://www.us.apache.org/dist/"
118 "ftp://gd.tuwien.ac.at/pub/infosys/servers/http/apache/dist/"
119 "http://apache.belnet.be/"
120 "http://mirrors.ircam.fr/pub/apache/"
f06afd4d
LC
121 "http://apache-mirror.rbc.ru/pub/apache/"
122
123 ;; As a last resort, try the archive.
124 "http://archive.apache.org/dist/")
149acc29 125 (xorg ; from http://www.x.org/wiki/Releases/Download
0820a58b 126 "http://www.x.org/releases/" ; main mirrors
149acc29
AE
127 "ftp://mirror.csclub.uwaterloo.ca/x.org/" ; North America
128 "ftp://xorg.mirrors.pair.com/"
129 "http://mirror.csclub.uwaterloo.ca/x.org/"
130 "http://xorg.mirrors.pair.com/"
131 "http://mirror.us.leaseweb.net/xorg/"
132 "ftp://artfiles.org/x.org/" ; Europe
133 "ftp://ftp.chg.ru/pub/X11/x.org/"
134 "ftp://ftp.fu-berlin.de/unix/X11/FTP.X.ORG/"
135 "ftp://ftp.gwdg.de/pub/x11/x.org/"
136 "ftp://ftp.mirrorservice.org/sites/ftp.x.org/"
137 "ftp://ftp.ntua.gr/pub/X11/"
138 "ftp://ftp.piotrkosoft.net/pub/mirrors/ftp.x.org/"
139 "ftp://ftp.portal-to-web.de/pub/mirrors/x.org/"
140 "ftp://ftp.solnet.ch/mirror/x.org/"
149acc29
AE
141 "ftp://gd.tuwien.ac.at/X11/"
142 "ftp://mi.mirror.garr.it/mirrors/x.org/"
143 "ftp://mirror.cict.fr/x.org/"
144 "ftp://mirror.switch.ch/mirror/X11/"
145 "ftp://mirrors.ircam.fr/pub/x.org/"
146 "ftp://x.mirrors.skynet.be/pub/ftp.x.org/"
147 "ftp://ftp.cs.cuhk.edu.hk/pub/X11" ; East Asia
148 "ftp://ftp.u-aizu.ac.jp/pub/x11/x.org/"
149 "ftp://ftp.yz.yamagata-u.ac.jp/pub/X11/x.org/"
150 "ftp://ftp.kaist.ac.kr/x.org/"
151 "ftp://mirrors.go-part.com/xorg/"
152 "http://x.cs.pu.edu.tw/"
6af31019
LC
153 "ftp://ftp.is.co.za/pub/x.org") ; South Africa
154 (cpan ; from http://www.cpan.org/SITES.html
155 "http://cpan.enstimac.fr/"
156 "ftp://ftp.ciril.fr/pub/cpan/"
157 "ftp://artfiles.org/cpan.org/"
158 "http://www.cpan.org/"
159 "ftp://cpan.rinet.ru/pub/mirror/CPAN/"
160 "http://cpan.cu.be/"
161 "ftp://cpan.inode.at/"
162 "ftp://cpan.iht.co.il/"
163 "ftp://ftp.osuosl.org/pub/CPAN/"
164 "ftp://ftp.nara.wide.ad.jp/pub/CPAN/"
165 "http://mirrors.163.com/cpan/"
7fa37abc 166 "ftp://cpan.mirror.ac.za/")
6d763bdd
AE
167 (imagemagick
168 ;; from http://www.imagemagick.org/script/download.php
169 ;; (without mirrors that are unavailable or not up to date)
170 ;; mirrors keeping old versions at the top level
6d763bdd
AE
171 "ftp://sunsite.icm.edu.pl/packages/ImageMagick/"
172 ;; mirrors moving old versions to "legacy"
173 "http://mirrors-au.go-parts.com/mirrors/ImageMagick/"
174 "ftp://mirror.aarnet.edu.au/pub/imagemagick/"
7fa37abc 175 "http://mirror.checkdomain.de/imagemagick/"
6d763bdd
AE
176 "ftp://ftp.kddlabs.co.jp/graphics/ImageMagick/"
177 "ftp://ftp.u-aizu.ac.jp/pub/graphics/image/ImageMagick/imagemagick.org/"
178 "ftp://ftp.nluug.nl/pub/ImageMagick/"
179 "http://ftp.surfnet.nl/pub/ImageMagick/"
180 "http://mirror.searchdaimon.com/ImageMagick"
181 "ftp://ftp.tpnet.pl/pub/graphics/ImageMagick/"
182 "http://mirrors-ru.go-parts.com/mirrors/ImageMagick/"
7fa37abc 183 "http://mirror.is.co.za/pub/imagemagick/"
6d763bdd
AE
184 "http://mirrors-uk.go-parts.com/mirrors/ImageMagick/"
185 "http://mirrors-usa.go-parts.com/mirrors/ImageMagick/"
186 "ftp://ftp.fifi.org/pub/ImageMagick/"
187 "http://www.imagemagick.org/download/"
188 ;; one legacy location as a last resort
189 "http://www.imagemagick.org/download/legacy/")
e0029b74
LC
190 (debian
191 "http://ftp.de.debian.org/debian/"
192 "http://ftp.fr.debian.org/debian/"
193 "http://ftp.debian.org/debian/"))))
94d222ad 194
6f8f8ccb 195(define (gnutls-package)
6119ebf1 196 "Return the default GnuTLS package."
6f8f8ccb
LC
197 (let ((module (resolve-interface '(gnu packages gnutls))))
198 (module-ref module 'gnutls)))
94d222ad 199
f220a838 200(define* (url-fetch url hash-algo hash
62cab99c 201 #:optional name
f220a838
LC
202 #:key (system (%current-system))
203 (guile (default-guile))
94d222ad 204 (mirrors %mirrors))
f220a838
LC
205 "Return a fixed-output derivation that fetches URL (a string, or a list of
206strings denoting alternate URLs), which is expected to have hash HASH of type
207HASH-ALGO (a symbol). By default, the file name is the base name of URL;
208optionally, NAME can specify a different file name.
94d222ad
LC
209
210When one of the URL starts with mirror://, then its host part is
211interpreted as the name of a mirror scheme, taken from MIRRORS; MIRRORS
f220a838 212must be a list of symbol/URL-list pairs.
62cab99c 213
f220a838
LC
214Alternately, when URL starts with file://, return the corresponding file name
215in the store."
62cab99c
LC
216 (define file-name
217 (match url
218 ((head _ ...)
219 (basename head))
220 (_
221 (basename url))))
222
483f1158
LC
223 (define need-gnutls?
224 ;; True if any of the URLs need TLS support.
225 (let ((https? (cut string-prefix? "https://" <>)))
226 (match url
227 ((? string?)
228 (https? url))
229 ((url ...)
230 (any https? url)))))
231
6f8f8ccb
LC
232 (define builder
233 #~(begin
234 #$(if need-gnutls?
235
236 ;; Add GnuTLS to the inputs and to the load path.
237 #~(eval-when (load expand eval)
238 (set! %load-path
239 (cons (string-append #$(gnutls-package)
e0ea3f8a
LC
240 "/share/guile/site/"
241 (effective-version))
6f8f8ccb
LC
242 %load-path)))
243 #~#t)
244
245 (use-modules (guix build download))
246 (url-fetch '#$url #$output
247 #:mirrors '#$mirrors)))
248
882383a9
LC
249 (let ((uri (and (string? url) (string->uri url))))
250 (if (or (and (string? url) (not uri))
251 (and uri (memq (uri-scheme uri) '(#f file))))
f220a838
LC
252 (interned-file (if uri (uri-path uri) url)
253 (or name file-name))
254 (mlet %store-monad ((guile (package->derivation guile system)))
882383a9 255 (gexp->derivation (or name file-name) builder
f220a838 256 #:guile-for-build guile
882383a9
LC
257 #:system system
258 #:hash-algo hash-algo
259 #:hash hash
260 #:modules '((guix build download)
261 (guix build utils)
262 (guix ftp-client))
56c72822 263
882383a9 264 ;; In general, offloading downloads is not a good idea.
347e17b4
LC
265 ;;#:local-build? #t
266 ;; FIXME: The above would also disable use of
267 ;; substitutes, so comment it out; see
268 ;; <https://bugs.gnu.org/18747>.
f220a838 269 )))))
62cab99c 270
861693f3
LC
271(define* (download-to-store store url #:optional (name (basename url))
272 #:key (log (current-error-port)))
273 "Download from URL to STORE, either under NAME or URL's basename if
274omitted. Write progress reports to LOG."
d8907ac4
LC
275 (define uri
276 (string->uri url))
277
d91a8791
LC
278 (if (or (not uri) (memq (uri-scheme uri) '(file #f)))
279 (add-to-store store name #f "sha256"
280 (if uri (uri-path uri) url))
d8907ac4
LC
281 (call-with-temporary-output-file
282 (lambda (temp port)
283 (let ((result
284 (parameterize ((current-output-port log))
285 (build:url-fetch url temp #:mirrors %mirrors))))
286 (close port)
287 (and result
288 (add-to-store store name #f "sha256" temp)))))))
861693f3 289
62cab99c 290;;; download.scm ends here