Commit | Line | Data |
---|---|---|
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 LC |
27 | #:use-module (srfi srfi-1) |
28 | #:use-module (srfi srfi-11) | |
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/" | |
47f9db41 LC |
102 | "ftp://ftp.funet.fi/pub/mirrors/ftp.kernel.org/pub/") |
103 | (apache ; from http://www.apache.org/mirrors/dist.html | |
104 | "http://www.eu.apache.org/dist/" | |
105 | "http://www.us.apache.org/dist/" | |
106 | "ftp://gd.tuwien.ac.at/pub/infosys/servers/http/apache/dist/" | |
107 | "http://apache.belnet.be/" | |
108 | "http://mirrors.ircam.fr/pub/apache/" | |
149acc29 AE |
109 | "http://apache-mirror.rbc.ru/pub/apache/") |
110 | (xorg ; from http://www.x.org/wiki/Releases/Download | |
0820a58b | 111 | "http://www.x.org/releases/" ; main mirrors |
149acc29 AE |
112 | "ftp://mirror.csclub.uwaterloo.ca/x.org/" ; North America |
113 | "ftp://xorg.mirrors.pair.com/" | |
114 | "http://mirror.csclub.uwaterloo.ca/x.org/" | |
115 | "http://xorg.mirrors.pair.com/" | |
116 | "http://mirror.us.leaseweb.net/xorg/" | |
117 | "ftp://artfiles.org/x.org/" ; Europe | |
118 | "ftp://ftp.chg.ru/pub/X11/x.org/" | |
119 | "ftp://ftp.fu-berlin.de/unix/X11/FTP.X.ORG/" | |
120 | "ftp://ftp.gwdg.de/pub/x11/x.org/" | |
121 | "ftp://ftp.mirrorservice.org/sites/ftp.x.org/" | |
122 | "ftp://ftp.ntua.gr/pub/X11/" | |
123 | "ftp://ftp.piotrkosoft.net/pub/mirrors/ftp.x.org/" | |
124 | "ftp://ftp.portal-to-web.de/pub/mirrors/x.org/" | |
125 | "ftp://ftp.solnet.ch/mirror/x.org/" | |
126 | "ftp://ftp.sunet.se/pub/X11/" | |
127 | "ftp://gd.tuwien.ac.at/X11/" | |
128 | "ftp://mi.mirror.garr.it/mirrors/x.org/" | |
129 | "ftp://mirror.cict.fr/x.org/" | |
130 | "ftp://mirror.switch.ch/mirror/X11/" | |
131 | "ftp://mirrors.ircam.fr/pub/x.org/" | |
132 | "ftp://x.mirrors.skynet.be/pub/ftp.x.org/" | |
133 | "ftp://ftp.cs.cuhk.edu.hk/pub/X11" ; East Asia | |
134 | "ftp://ftp.u-aizu.ac.jp/pub/x11/x.org/" | |
135 | "ftp://ftp.yz.yamagata-u.ac.jp/pub/X11/x.org/" | |
136 | "ftp://ftp.kaist.ac.kr/x.org/" | |
137 | "ftp://mirrors.go-part.com/xorg/" | |
138 | "http://x.cs.pu.edu.tw/" | |
6af31019 LC |
139 | "ftp://ftp.is.co.za/pub/x.org") ; South Africa |
140 | (cpan ; from http://www.cpan.org/SITES.html | |
141 | "http://cpan.enstimac.fr/" | |
142 | "ftp://ftp.ciril.fr/pub/cpan/" | |
143 | "ftp://artfiles.org/cpan.org/" | |
144 | "http://www.cpan.org/" | |
145 | "ftp://cpan.rinet.ru/pub/mirror/CPAN/" | |
146 | "http://cpan.cu.be/" | |
147 | "ftp://cpan.inode.at/" | |
148 | "ftp://cpan.iht.co.il/" | |
149 | "ftp://ftp.osuosl.org/pub/CPAN/" | |
150 | "ftp://ftp.nara.wide.ad.jp/pub/CPAN/" | |
151 | "http://mirrors.163.com/cpan/" | |
7fa37abc LC |
152 | "ftp://cpan.mirror.ac.za/") |
153 | (imagemagick ; from http://www.imagemagick.org/script/download.php | |
154 | "http://mirror.checkdomain.de/imagemagick/" | |
155 | "ftp://gd.tuwien.ac.at/pub/graphics/ImageMagick/" | |
156 | "http://www.imagemagick.org/download" | |
157 | "ftp://mirror.searchdaimon.com/ImageMagick" | |
158 | "http://mirror.is.co.za/pub/imagemagick/" | |
159 | "ftp://mirror.aarnet.edu.au/pub/imagemagick/")))) | |
94d222ad | 160 | |
483f1158 LC |
161 | (define (gnutls-derivation store system) |
162 | "Return the GnuTLS derivation for SYSTEM." | |
163 | (let* ((module (resolve-interface '(gnu packages gnutls))) | |
164 | (gnutls (module-ref module 'gnutls))) | |
165 | (package-derivation store gnutls system))) | |
94d222ad | 166 | |
62cab99c LC |
167 | (define* (url-fetch store url hash-algo hash |
168 | #:optional name | |
94d222ad LC |
169 | #:key (system (%current-system)) guile |
170 | (mirrors %mirrors)) | |
62cab99c LC |
171 | "Return the path of a fixed-output derivation in STORE that fetches |
172 | URL (a string, or a list of strings denoting alternate URLs), which is | |
173 | expected to have hash HASH of type HASH-ALGO (a symbol). By default, | |
174 | the file name is the base name of URL; optionally, NAME can specify a | |
94d222ad LC |
175 | different file name. |
176 | ||
177 | When one of the URL starts with mirror://, then its host part is | |
178 | interpreted as the name of a mirror scheme, taken from MIRRORS; MIRRORS | |
179 | must be a list of symbol/URL-list pairs." | |
62cab99c LC |
180 | (define builder |
181 | `(begin | |
182 | (use-modules (guix build download)) | |
94d222ad LC |
183 | (url-fetch ',url %output |
184 | #:mirrors ',mirrors))) | |
62cab99c LC |
185 | |
186 | (define guile-for-build | |
187 | (match guile | |
188 | ((? package?) | |
189 | (package-derivation store guile system)) | |
190 | ((and (? string?) (? derivation-path?)) | |
191 | guile) | |
192 | (#f ; the default | |
1ffa7090 | 193 | (let* ((distro (resolve-interface '(gnu packages base))) |
62cab99c LC |
194 | (guile (module-ref distro 'guile-final))) |
195 | (package-derivation store guile system))))) | |
196 | ||
197 | (define file-name | |
198 | (match url | |
199 | ((head _ ...) | |
200 | (basename head)) | |
201 | (_ | |
202 | (basename url)))) | |
203 | ||
483f1158 LC |
204 | (define need-gnutls? |
205 | ;; True if any of the URLs need TLS support. | |
206 | (let ((https? (cut string-prefix? "https://" <>))) | |
207 | (match url | |
208 | ((? string?) | |
209 | (https? url)) | |
210 | ((url ...) | |
211 | (any https? url))))) | |
212 | ||
213 | (let*-values (((gnutls-drv-path gnutls-drv) | |
214 | (if need-gnutls? | |
215 | (gnutls-derivation store system) | |
216 | (values #f #f))) | |
217 | ((gnutls) | |
218 | (and gnutls-drv | |
219 | (derivation-output-path | |
220 | (assoc-ref (derivation-outputs gnutls-drv) | |
221 | "out")))) | |
222 | ((env-vars) | |
223 | (if gnutls | |
224 | (let ((dir (string-append gnutls "/share/guile/site"))) | |
225 | ;; XXX: `GUILE_LOAD_COMPILED_PATH' is overridden | |
226 | ;; by `build-expression->derivation', so we can't | |
227 | ;; set it here. | |
228 | `(("GUILE_LOAD_PATH" . ,dir))) | |
229 | '()))) | |
230 | (build-expression->derivation store (or name file-name) system | |
231 | builder | |
232 | (if gnutls-drv | |
233 | `(("gnutls" ,gnutls-drv-path)) | |
234 | '()) | |
235 | #:hash-algo hash-algo | |
236 | #:hash hash | |
237 | #:modules '((guix build download) | |
238 | (guix build utils) | |
239 | (guix ftp-client)) | |
240 | #:guile-for-build guile-for-build | |
241 | #:env-vars env-vars))) | |
62cab99c | 242 | |
861693f3 LC |
243 | (define* (download-to-store store url #:optional (name (basename url)) |
244 | #:key (log (current-error-port))) | |
245 | "Download from URL to STORE, either under NAME or URL's basename if | |
246 | omitted. Write progress reports to LOG." | |
247 | (call-with-temporary-output-file | |
248 | (lambda (temp port) | |
249 | (let ((result | |
250 | (parameterize ((current-output-port log)) | |
251 | (build:url-fetch url temp #:mirrors %mirrors)))) | |
252 | (close port) | |
253 | (and result | |
254 | (add-to-store store name #f "sha256" temp)))))) | |
255 | ||
62cab99c | 256 | ;;; download.scm ends here |