Commit | Line | Data |
---|---|---|
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/") |
cb7e4867 RW |
167 | (cran |
168 | ;; Arbitrary mirrors from http://cran.r-project.org/mirrors.html | |
169 | ;; This one automatically redirects to servers worldwide | |
170 | "http://cran.rstudio.com/" | |
171 | "http://cran.univ-lyon1.fr/" | |
172 | "http://cran.r-mirror.de/" | |
173 | "http://cran.ism.ac.jp/" | |
174 | "http://cran.stat.auckland.ac.nz/" | |
175 | "http://cran.mirror.ac.za/" | |
176 | "http://cran.csie.ntu.edu.tw/") | |
6d763bdd AE |
177 | (imagemagick |
178 | ;; from http://www.imagemagick.org/script/download.php | |
179 | ;; (without mirrors that are unavailable or not up to date) | |
180 | ;; mirrors keeping old versions at the top level | |
6d763bdd AE |
181 | "ftp://sunsite.icm.edu.pl/packages/ImageMagick/" |
182 | ;; mirrors moving old versions to "legacy" | |
183 | "http://mirrors-au.go-parts.com/mirrors/ImageMagick/" | |
184 | "ftp://mirror.aarnet.edu.au/pub/imagemagick/" | |
7fa37abc | 185 | "http://mirror.checkdomain.de/imagemagick/" |
6d763bdd AE |
186 | "ftp://ftp.kddlabs.co.jp/graphics/ImageMagick/" |
187 | "ftp://ftp.u-aizu.ac.jp/pub/graphics/image/ImageMagick/imagemagick.org/" | |
188 | "ftp://ftp.nluug.nl/pub/ImageMagick/" | |
189 | "http://ftp.surfnet.nl/pub/ImageMagick/" | |
190 | "http://mirror.searchdaimon.com/ImageMagick" | |
191 | "ftp://ftp.tpnet.pl/pub/graphics/ImageMagick/" | |
192 | "http://mirrors-ru.go-parts.com/mirrors/ImageMagick/" | |
7fa37abc | 193 | "http://mirror.is.co.za/pub/imagemagick/" |
6d763bdd AE |
194 | "http://mirrors-uk.go-parts.com/mirrors/ImageMagick/" |
195 | "http://mirrors-usa.go-parts.com/mirrors/ImageMagick/" | |
196 | "ftp://ftp.fifi.org/pub/ImageMagick/" | |
197 | "http://www.imagemagick.org/download/" | |
198 | ;; one legacy location as a last resort | |
199 | "http://www.imagemagick.org/download/legacy/") | |
e0029b74 LC |
200 | (debian |
201 | "http://ftp.de.debian.org/debian/" | |
202 | "http://ftp.fr.debian.org/debian/" | |
203 | "http://ftp.debian.org/debian/")))) | |
94d222ad | 204 | |
6f8f8ccb | 205 | (define (gnutls-package) |
6119ebf1 | 206 | "Return the default GnuTLS package." |
6f8f8ccb LC |
207 | (let ((module (resolve-interface '(gnu packages gnutls)))) |
208 | (module-ref module 'gnutls))) | |
94d222ad | 209 | |
f220a838 | 210 | (define* (url-fetch url hash-algo hash |
62cab99c | 211 | #:optional name |
f220a838 LC |
212 | #:key (system (%current-system)) |
213 | (guile (default-guile)) | |
94d222ad | 214 | (mirrors %mirrors)) |
f220a838 LC |
215 | "Return a fixed-output derivation that fetches URL (a string, or a list of |
216 | strings denoting alternate URLs), which is expected to have hash HASH of type | |
217 | HASH-ALGO (a symbol). By default, the file name is the base name of URL; | |
218 | optionally, NAME can specify a different file name. | |
94d222ad LC |
219 | |
220 | When one of the URL starts with mirror://, then its host part is | |
221 | interpreted as the name of a mirror scheme, taken from MIRRORS; MIRRORS | |
f220a838 | 222 | must be a list of symbol/URL-list pairs. |
62cab99c | 223 | |
f220a838 LC |
224 | Alternately, when URL starts with file://, return the corresponding file name |
225 | in the store." | |
62cab99c LC |
226 | (define file-name |
227 | (match url | |
228 | ((head _ ...) | |
229 | (basename head)) | |
230 | (_ | |
231 | (basename url)))) | |
232 | ||
483f1158 LC |
233 | (define need-gnutls? |
234 | ;; True if any of the URLs need TLS support. | |
235 | (let ((https? (cut string-prefix? "https://" <>))) | |
236 | (match url | |
237 | ((? string?) | |
238 | (https? url)) | |
239 | ((url ...) | |
240 | (any https? url))))) | |
241 | ||
6f8f8ccb LC |
242 | (define builder |
243 | #~(begin | |
1590e8a1 | 244 | #+(if need-gnutls? |
6f8f8ccb LC |
245 | |
246 | ;; Add GnuTLS to the inputs and to the load path. | |
247 | #~(eval-when (load expand eval) | |
248 | (set! %load-path | |
1590e8a1 | 249 | (cons (string-append #+(gnutls-package) |
e0ea3f8a LC |
250 | "/share/guile/site/" |
251 | (effective-version)) | |
6f8f8ccb LC |
252 | %load-path))) |
253 | #~#t) | |
254 | ||
255 | (use-modules (guix build download)) | |
256 | (url-fetch '#$url #$output | |
257 | #:mirrors '#$mirrors))) | |
258 | ||
882383a9 LC |
259 | (let ((uri (and (string? url) (string->uri url)))) |
260 | (if (or (and (string? url) (not uri)) | |
261 | (and uri (memq (uri-scheme uri) '(#f file)))) | |
f220a838 LC |
262 | (interned-file (if uri (uri-path uri) url) |
263 | (or name file-name)) | |
264 | (mlet %store-monad ((guile (package->derivation guile system))) | |
882383a9 | 265 | (gexp->derivation (or name file-name) builder |
f220a838 | 266 | #:guile-for-build guile |
882383a9 LC |
267 | #:system system |
268 | #:hash-algo hash-algo | |
269 | #:hash hash | |
270 | #:modules '((guix build download) | |
271 | (guix build utils) | |
272 | (guix ftp-client)) | |
56c72822 | 273 | |
882383a9 | 274 | ;; In general, offloading downloads is not a good idea. |
347e17b4 LC |
275 | ;;#:local-build? #t |
276 | ;; FIXME: The above would also disable use of | |
277 | ;; substitutes, so comment it out; see | |
278 | ;; <https://bugs.gnu.org/18747>. | |
f220a838 | 279 | ))))) |
62cab99c | 280 | |
861693f3 LC |
281 | (define* (download-to-store store url #:optional (name (basename url)) |
282 | #:key (log (current-error-port))) | |
283 | "Download from URL to STORE, either under NAME or URL's basename if | |
284 | omitted. Write progress reports to LOG." | |
d8907ac4 LC |
285 | (define uri |
286 | (string->uri url)) | |
287 | ||
d91a8791 LC |
288 | (if (or (not uri) (memq (uri-scheme uri) '(file #f))) |
289 | (add-to-store store name #f "sha256" | |
290 | (if uri (uri-path uri) url)) | |
d8907ac4 LC |
291 | (call-with-temporary-output-file |
292 | (lambda (temp port) | |
293 | (let ((result | |
294 | (parameterize ((current-output-port log)) | |
295 | (build:url-fetch url temp #:mirrors %mirrors)))) | |
296 | (close port) | |
297 | (and result | |
298 | (add-to-store store name #f "sha256" temp))))))) | |
861693f3 | 299 | |
62cab99c | 300 | ;;; download.scm ends here |