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