Commit | Line | Data |
---|---|---|
233e7676 | 1 | ;;; GNU Guix --- Functional package management for GNU |
95001d4b | 2 | ;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org> |
9884d7ec | 3 | ;;; Copyright © 2013, 2014, 2015 Andreas Enge <andreas@enge.fr> |
95001d4b | 4 | ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch> |
fe224d20 | 5 | ;;; Copyright © 2016 Alex Griffin <a@ajgrf.com> |
9c97afe8 | 6 | ;;; Copyright © 2016 David Craven <david@craven.ch> |
62cab99c | 7 | ;;; |
233e7676 | 8 | ;;; This file is part of GNU Guix. |
62cab99c | 9 | ;;; |
233e7676 | 10 | ;;; GNU Guix is free software; you can redistribute it and/or modify it |
62cab99c LC |
11 | ;;; under the terms of the GNU General Public License as published by |
12 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
13 | ;;; your option) any later version. | |
14 | ;;; | |
233e7676 | 15 | ;;; GNU Guix is distributed in the hope that it will be useful, but |
62cab99c LC |
16 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;;; GNU General Public License for more details. | |
19 | ;;; | |
20 | ;;; You should have received a copy of the GNU General Public License | |
233e7676 | 21 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
62cab99c LC |
22 | |
23 | (define-module (guix download) | |
24 | #:use-module (ice-9 match) | |
25 | #:use-module (guix derivations) | |
26 | #:use-module (guix packages) | |
e87f0591 | 27 | #:use-module (guix store) |
b5b73a82 | 28 | #:use-module ((guix build download) #:prefix build:) |
6f8f8ccb LC |
29 | #:use-module (guix monads) |
30 | #:use-module (guix gexp) | |
62cab99c | 31 | #:use-module (guix utils) |
d8907ac4 | 32 | #:use-module (web uri) |
483f1158 | 33 | #:use-module (srfi srfi-1) |
94d222ad | 34 | #:use-module (srfi srfi-26) |
ec4d308a | 35 | #:export (%mirrors |
861693f3 | 36 | url-fetch |
95001d4b | 37 | url-fetch/tarbomb |
861693f3 | 38 | download-to-store)) |
62cab99c LC |
39 | |
40 | ;;; Commentary: | |
41 | ;;; | |
42 | ;;; Produce fixed-output derivations with data fetched over HTTP or FTP. | |
43 | ;;; | |
44 | ;;; Code: | |
45 | ||
94d222ad LC |
46 | (define %mirrors |
47 | ;; Mirror lists used when `mirror://' URLs are passed. | |
48 | (let* ((gnu-mirrors | |
49 | '(;; This one redirects to a (supposedly) nearby and (supposedly) | |
50 | ;; up-to-date mirror. | |
51 | "http://ftpmirror.gnu.org/" | |
52 | ||
53 | "ftp://ftp.cs.tu-berlin.de/pub/gnu/" | |
94d222ad LC |
54 | "ftp://ftp.funet.fi/pub/mirrors/ftp.gnu.org/gnu/" |
55 | ||
56 | ;; This one is the master repository, and thus it's always | |
57 | ;; up-to-date. | |
58 | "http://ftp.gnu.org/pub/gnu/"))) | |
59 | `((gnu ,@gnu-mirrors) | |
60 | (gcc | |
61 | "ftp://ftp.nluug.nl/mirror/languages/gcc/" | |
62 | "ftp://ftp.fu-berlin.de/unix/languages/gcc/" | |
63 | "ftp://ftp.irisa.fr/pub/mirrors/gcc.gnu.org/gcc/" | |
64 | "ftp://gcc.gnu.org/pub/gcc/" | |
65 | ,@(map (cut string-append <> "/gcc") gnu-mirrors)) | |
66 | (gnupg | |
67 | "ftp://gd.tuwien.ac.at/privacy/gnupg/" | |
d57b88be | 68 | "ftp://mirrors.dotsrc.org/gcrypt/" |
94d222ad | 69 | "ftp://mirror.cict.fr/gnupg/" |
d57b88be AE |
70 | "http://artfiles.org/gnupg.org" |
71 | "ftp://ftp.franken.de/pub/crypt/mirror/ftp.gnupg.org/gcrypt/" | |
72 | "ftp://ftp.freenet.de/pub/ftp.gnupg.org/gcrypt/" | |
73 | "http://www.crysys.hu/" | |
74 | "ftp://ftp.hi.is/pub/mirrors/gnupg/" | |
75 | "ftp://ftp.heanet.ie/mirrors/ftp.gnupg.org/gcrypt/" | |
76 | "ftp://ftp.bit.nl/mirror/gnupg/" | |
77 | "ftp://ftp.surfnet.nl/pub/security/gnupg/" | |
78 | "ftp://ftp.iasi.roedu.net/pub/mirrors/ftp.gnupg.org/" | |
79 | "ftp://ftp.sunet.se/pub/security/gnupg/" | |
80 | "ftp://mirror.switch.ch/mirror/gnupg/" | |
81 | "ftp://mirror.tje.me.uk/pub/mirrors/ftp.gnupg.org/" | |
82 | "ftp://ftp.mirrorservice.org/sites/ftp.gnupg.org/gcrypt/" | |
83 | "ftp://ftp.ring.gr.jp/pub/net/gnupg/" | |
84 | "ftp://ftp.gnupg.org/gcrypt/") | |
71eb5c10 LC |
85 | (gnome |
86 | "http://ftp.belnet.be/ftp.gnome.org/" | |
87 | "http://ftp.linux.org.uk/mirrors/ftp.gnome.org/" | |
88 | "http://ftp.gnome.org/pub/GNOME/" | |
89 | "http://mirror.yandex.ru/mirrors/ftp.gnome.org/") | |
94d222ad | 90 | (savannah |
a4eabecd | 91 | "http://download.savannah.gnu.org/releases/" |
94d222ad LC |
92 | "ftp://ftp.twaren.net/Unix/NonGNU/" |
93 | "ftp://mirror.csclub.uwaterloo.ca/nongnu/" | |
94 | "ftp://mirror.publicns.net/pub/nongnu/" | |
95 | "ftp://savannah.c3sl.ufpr.br/" | |
96 | "http://ftp.cc.uoc.gr/mirrors/nongnu.org/" | |
97 | "http://ftp.twaren.net/Unix/NonGNU/" | |
98 | "http://mirror.csclub.uwaterloo.ca/nongnu/" | |
99 | "http://nongnu.askapache.com/" | |
100 | "http://savannah.c3sl.ufpr.br/" | |
3bba7b0a LC |
101 | "http://www.centervenus.com/mirrors/nongnu/" |
102 | "http://download.savannah.gnu.org/releases-noredirect/") | |
321dc4df | 103 | (sourceforge ; https://sourceforge.net/p/forge/documentation/Mirrors/ |
fe224d20 | 104 | "http://downloads.sourceforge.net/project/" |
cd4c41fd LC |
105 | "http://ufpr.dl.sourceforge.net/project/" |
106 | "http://heanet.dl.sourceforge.net/project/" | |
107 | "http://freefr.dl.sourceforge.net/project/" | |
108 | "http://internode.dl.sourceforge.net/project/" | |
109 | "http://jaist.dl.sourceforge.net/project/" | |
110 | "http://kent.dl.sourceforge.net/project/" | |
111 | "http://liquidtelecom.dl.sourceforge.net/project/" | |
112 | "http://nbtelecom.dl.sourceforge.net/project/" | |
113 | "http://nchc.dl.sourceforge.net/project/" | |
114 | "http://ncu.dl.sourceforge.net/project/" | |
115 | "http://netcologne.dl.sourceforge.net/project/" | |
116 | "http://netix.dl.sourceforge.net/project/" | |
117 | "http://pilotfiber.dl.sourceforge.net/project/" | |
118 | "http://superb-sea2.dl.sourceforge.net/project/" | |
119 | "http://tenet.dl.sourceforge.net/project/" | |
120 | "http://vorboss.dl.sourceforge.net/project/" | |
121 | "http://netassist.dl.sourceforge.net/project/") | |
b40b259f LC |
122 | (kernel.org |
123 | "http://www.all.kernel.org/pub/" | |
124 | "http://ramses.wh2.tu-dresden.de/pub/mirrors/kernel.org/" | |
125 | "http://linux-kernel.uio.no/pub/" | |
126 | "http://kernel.osuosl.org/pub/" | |
5d9cd707 LC |
127 | "ftp://ftp.funet.fi/pub/mirrors/ftp.kernel.org/pub/" |
128 | "http://ftp.be.debian.org/pub/" | |
129 | "http://mirror.linux.org.au/") | |
47f9db41 LC |
130 | (apache ; from http://www.apache.org/mirrors/dist.html |
131 | "http://www.eu.apache.org/dist/" | |
132 | "http://www.us.apache.org/dist/" | |
133 | "ftp://gd.tuwien.ac.at/pub/infosys/servers/http/apache/dist/" | |
134 | "http://apache.belnet.be/" | |
135 | "http://mirrors.ircam.fr/pub/apache/" | |
f06afd4d LC |
136 | "http://apache-mirror.rbc.ru/pub/apache/" |
137 | ||
138 | ;; As a last resort, try the archive. | |
139 | "http://archive.apache.org/dist/") | |
149acc29 | 140 | (xorg ; from http://www.x.org/wiki/Releases/Download |
0820a58b | 141 | "http://www.x.org/releases/" ; main mirrors |
149acc29 AE |
142 | "ftp://mirror.csclub.uwaterloo.ca/x.org/" ; North America |
143 | "ftp://xorg.mirrors.pair.com/" | |
144 | "http://mirror.csclub.uwaterloo.ca/x.org/" | |
145 | "http://xorg.mirrors.pair.com/" | |
146 | "http://mirror.us.leaseweb.net/xorg/" | |
147 | "ftp://artfiles.org/x.org/" ; Europe | |
148 | "ftp://ftp.chg.ru/pub/X11/x.org/" | |
149 | "ftp://ftp.fu-berlin.de/unix/X11/FTP.X.ORG/" | |
150 | "ftp://ftp.gwdg.de/pub/x11/x.org/" | |
151 | "ftp://ftp.mirrorservice.org/sites/ftp.x.org/" | |
152 | "ftp://ftp.ntua.gr/pub/X11/" | |
153 | "ftp://ftp.piotrkosoft.net/pub/mirrors/ftp.x.org/" | |
154 | "ftp://ftp.portal-to-web.de/pub/mirrors/x.org/" | |
155 | "ftp://ftp.solnet.ch/mirror/x.org/" | |
149acc29 AE |
156 | "ftp://gd.tuwien.ac.at/X11/" |
157 | "ftp://mi.mirror.garr.it/mirrors/x.org/" | |
158 | "ftp://mirror.cict.fr/x.org/" | |
159 | "ftp://mirror.switch.ch/mirror/X11/" | |
160 | "ftp://mirrors.ircam.fr/pub/x.org/" | |
161 | "ftp://x.mirrors.skynet.be/pub/ftp.x.org/" | |
162 | "ftp://ftp.cs.cuhk.edu.hk/pub/X11" ; East Asia | |
163 | "ftp://ftp.u-aizu.ac.jp/pub/x11/x.org/" | |
164 | "ftp://ftp.yz.yamagata-u.ac.jp/pub/X11/x.org/" | |
165 | "ftp://ftp.kaist.ac.kr/x.org/" | |
166 | "ftp://mirrors.go-part.com/xorg/" | |
167 | "http://x.cs.pu.edu.tw/" | |
6af31019 LC |
168 | "ftp://ftp.is.co.za/pub/x.org") ; South Africa |
169 | (cpan ; from http://www.cpan.org/SITES.html | |
8aa5e15e | 170 | "http://mirror.ibcp.fr/pub/CPAN/" |
6af31019 LC |
171 | "ftp://ftp.ciril.fr/pub/cpan/" |
172 | "ftp://artfiles.org/cpan.org/" | |
173 | "http://www.cpan.org/" | |
174 | "ftp://cpan.rinet.ru/pub/mirror/CPAN/" | |
6af31019 LC |
175 | "ftp://cpan.inode.at/" |
176 | "ftp://cpan.iht.co.il/" | |
177 | "ftp://ftp.osuosl.org/pub/CPAN/" | |
178 | "ftp://ftp.nara.wide.ad.jp/pub/CPAN/" | |
179 | "http://mirrors.163.com/cpan/" | |
552ffa02 EF |
180 | "ftp://cpan.mirror.ac.za/" |
181 | "http://cpan.mirrors.ionfish.org/" | |
182 | "http://cpan.mirror.dkm.cz/pub/CPAN/" | |
183 | "http://cpan.mirror.iphh.net/" | |
184 | "http://mirrors.teentelecom.net/CPAN/" | |
185 | "http://mirror.teklinks.com/CPAN/" | |
186 | "http://cpan.weepeetelecom.be/" | |
187 | "http://mirrors.xservers.ro/CPAN/" | |
188 | "http://cpan.yimg.com/" | |
189 | "http://mirror.yazd.ac.ir/cpan/" | |
190 | "http://ftp.belnet.be/ftp.cpan.org/") | |
cb7e4867 RW |
191 | (cran |
192 | ;; Arbitrary mirrors from http://cran.r-project.org/mirrors.html | |
193 | ;; This one automatically redirects to servers worldwide | |
c009bb5a | 194 | "http://cran.r-project.org/" |
cb7e4867 RW |
195 | "http://cran.rstudio.com/" |
196 | "http://cran.univ-lyon1.fr/" | |
cb7e4867 RW |
197 | "http://cran.ism.ac.jp/" |
198 | "http://cran.stat.auckland.ac.nz/" | |
199 | "http://cran.mirror.ac.za/" | |
200 | "http://cran.csie.ntu.edu.tw/") | |
6d763bdd AE |
201 | (imagemagick |
202 | ;; from http://www.imagemagick.org/script/download.php | |
203 | ;; (without mirrors that are unavailable or not up to date) | |
204 | ;; mirrors keeping old versions at the top level | |
6d763bdd AE |
205 | "ftp://sunsite.icm.edu.pl/packages/ImageMagick/" |
206 | ;; mirrors moving old versions to "legacy" | |
207 | "http://mirrors-au.go-parts.com/mirrors/ImageMagick/" | |
208 | "ftp://mirror.aarnet.edu.au/pub/imagemagick/" | |
7fa37abc | 209 | "http://mirror.checkdomain.de/imagemagick/" |
6d763bdd AE |
210 | "ftp://ftp.kddlabs.co.jp/graphics/ImageMagick/" |
211 | "ftp://ftp.u-aizu.ac.jp/pub/graphics/image/ImageMagick/imagemagick.org/" | |
212 | "ftp://ftp.nluug.nl/pub/ImageMagick/" | |
213 | "http://ftp.surfnet.nl/pub/ImageMagick/" | |
214 | "http://mirror.searchdaimon.com/ImageMagick" | |
215 | "ftp://ftp.tpnet.pl/pub/graphics/ImageMagick/" | |
216 | "http://mirrors-ru.go-parts.com/mirrors/ImageMagick/" | |
7fa37abc | 217 | "http://mirror.is.co.za/pub/imagemagick/" |
6d763bdd AE |
218 | "http://mirrors-uk.go-parts.com/mirrors/ImageMagick/" |
219 | "http://mirrors-usa.go-parts.com/mirrors/ImageMagick/" | |
220 | "ftp://ftp.fifi.org/pub/ImageMagick/" | |
221 | "http://www.imagemagick.org/download/" | |
222 | ;; one legacy location as a last resort | |
223 | "http://www.imagemagick.org/download/legacy/") | |
e0029b74 LC |
224 | (debian |
225 | "http://ftp.de.debian.org/debian/" | |
226 | "http://ftp.fr.debian.org/debian/" | |
6b287c5c | 227 | "http://ftp.debian.org/debian/" |
ff02b826 DC |
228 | "http://archive.debian.org/debian/") |
229 | (kde | |
230 | ;; Mirrors from http://files.kde.org/extra/mirrors.html | |
231 | ;; Europe | |
232 | "http://mirror.easyname.at/kde" | |
233 | "http://mirror.karneval.cz/pub/kde" | |
234 | "http://ftp.fi.muni.cz/pub/kde/" | |
235 | "http://mirror.oss.maxcdn.com/kde/" | |
236 | "http://ftp5.gwdg.de/pub/linux/kde/" | |
237 | "http://ftp-stud.fht-esslingen.de/Mirrors/ftp.kde.org/pub/kde/" | |
238 | "http://mirror.klaus-uwe.me/kde/ftp/" | |
239 | "http://kde.beta.mirror.ga/" | |
240 | "http://kde.alpha.mirror.ga/" | |
241 | "http://mirror.netcologne.de/kde" | |
242 | "http://vesta.informatik.rwth-aachen.de/ftp/pub/mirror/kde/" | |
243 | "http://ftp.rz.uni-wuerzburg.de/pub/unix/kde/" | |
244 | "http://mirrors.dotsrc.org/kde/" | |
245 | "http://ftp.funet.fi/pub/mirrors/ftp.kde.org/pub/kde/" | |
246 | "http://kde-mirror.freenux.org/" | |
247 | "http://mirrors.ircam.fr/pub/KDE/" | |
248 | "http://www-ftp.lip6.fr/pub/X11/kde/" | |
249 | "http://fr2.rpmfind.net/linux/KDE/" | |
250 | "http://kde.mirror.anlx.net/" | |
251 | "http://www.mirrorservice.org/sites/ftp.kde.org/pub/kde/" | |
252 | "http://ftp.heanet.ie/mirrors/ftp.kde.org/" | |
253 | "http://ftp.nluug.nl/pub/windowing/kde/" | |
254 | "http://ftp.surfnet.nl/windowing/kde/" | |
255 | "http://ftp.icm.edu.pl/pub/unix/kde/" | |
256 | "http://ftp.pbone.net/pub/kde/" | |
257 | "http://piotrkosoft.net/pub/mirrors/ftp.kde.org/" | |
258 | "http://mirrors.fe.up.pt/pub/kde/" | |
259 | "http://ftp.iasi.roedu.net/pub/mirrors/ftp.kde.org/" | |
260 | "http://ftp.acc.umu.se/mirror/kde.org/ftp/" | |
261 | "http://kde.ip-connect.vn.ua/" | |
262 | ;; North America | |
263 | "http://mirror.its.dal.ca/kde/" | |
264 | "http://mirror.csclub.uwaterloo.ca/kde/" | |
265 | "http://mirror.cc.columbia.edu/pub/software/kde/" | |
266 | "http://mirrors-usa.go-parts.com/kde" | |
267 | "http://kde.mirrors.hoobly.com/" | |
268 | "http://ftp.ussg.iu.edu/kde/" | |
269 | "http://mirrors.mit.edu/kde/" | |
270 | "http://kde.mirrors.tds.net/pub/kde/" | |
271 | ;; Oceania | |
272 | "http://ftp.kddlabs.co.jp/pub/X11/kde/" | |
273 | "http://kde.mirror.uber.com.au/")))) | |
94d222ad | 274 | |
53216419 LC |
275 | (define %mirror-file |
276 | ;; Copy of the list of mirrors to a file. This allows us to keep a single | |
277 | ;; copy in the store, and computing it here avoids repeated calls to | |
278 | ;; 'object->string'. | |
279 | (plain-file "mirrors" (object->string %mirrors))) | |
280 | ||
cd436bf0 LC |
281 | (define %content-addressed-mirrors |
282 | ;; List of content-addressed mirrors. Each mirror is represented as a | |
ab84b927 LC |
283 | ;; procedure that takes a file name, an algorithm (symbol) and a hash |
284 | ;; (bytevector), and returns a URL or #f. | |
40f788b9 | 285 | ;; Note: Avoid 'https' to mitigate <http://bugs.gnu.org/22774>. |
cd436bf0 | 286 | ;; TODO: Add more. |
ab84b927 | 287 | '(list (lambda (file algo hash) |
40f788b9 LC |
288 | ;; Files served by 'guix publish' are accessible under a single |
289 | ;; hash algorithm. | |
290 | (string-append "http://mirror.hydra.gnu.org/file/" | |
291 | file "/" (symbol->string algo) "/" | |
292 | (bytevector->nix-base32-string hash))) | |
293 | (lambda (file algo hash) | |
cd436bf0 LC |
294 | ;; 'tarballs.nixos.org' supports several algorithms. |
295 | (string-append "http://tarballs.nixos.org/" | |
296 | (symbol->string algo) "/" | |
297 | (bytevector->nix-base32-string hash))))) | |
298 | ||
299 | (define %content-addressed-mirror-file | |
300 | ;; Content-addressed mirrors stored in a file. | |
301 | (plain-file "content-addressed-mirrors" | |
302 | (object->string %content-addressed-mirrors))) | |
303 | ||
6f8f8ccb | 304 | (define (gnutls-package) |
6119ebf1 | 305 | "Return the default GnuTLS package." |
9884d7ec | 306 | (let ((module (resolve-interface '(gnu packages tls)))) |
6f8f8ccb | 307 | (module-ref module 'gnutls))) |
94d222ad | 308 | |
f220a838 | 309 | (define* (url-fetch url hash-algo hash |
62cab99c | 310 | #:optional name |
f220a838 | 311 | #:key (system (%current-system)) |
53216419 | 312 | (guile (default-guile))) |
f220a838 LC |
313 | "Return a fixed-output derivation that fetches URL (a string, or a list of |
314 | strings denoting alternate URLs), which is expected to have hash HASH of type | |
315 | HASH-ALGO (a symbol). By default, the file name is the base name of URL; | |
316 | optionally, NAME can specify a different file name. | |
94d222ad LC |
317 | |
318 | When one of the URL starts with mirror://, then its host part is | |
53216419 | 319 | interpreted as the name of a mirror scheme, taken from %MIRROR-FILE. |
62cab99c | 320 | |
f220a838 LC |
321 | Alternately, when URL starts with file://, return the corresponding file name |
322 | in the store." | |
62cab99c LC |
323 | (define file-name |
324 | (match url | |
325 | ((head _ ...) | |
326 | (basename head)) | |
327 | (_ | |
328 | (basename url)))) | |
329 | ||
483f1158 LC |
330 | (define need-gnutls? |
331 | ;; True if any of the URLs need TLS support. | |
332 | (let ((https? (cut string-prefix? "https://" <>))) | |
333 | (match url | |
334 | ((? string?) | |
335 | (https? url)) | |
336 | ((url ...) | |
337 | (any https? url))))) | |
338 | ||
6f8f8ccb | 339 | (define builder |
e9b046fd LC |
340 | (with-imported-modules '((guix build download) |
341 | (guix build utils) | |
342 | (guix ftp-client) | |
343 | (guix base32) | |
344 | (guix base64)) | |
345 | #~(begin | |
346 | #+(if need-gnutls? | |
6f8f8ccb | 347 | |
e9b046fd LC |
348 | ;; Add GnuTLS to the inputs and to the load path. |
349 | #~(eval-when (load expand eval) | |
350 | (set! %load-path | |
351 | (cons (string-append #+(gnutls-package) | |
352 | "/share/guile/site/" | |
353 | (effective-version)) | |
354 | %load-path))) | |
355 | #~#t) | |
6f8f8ccb | 356 | |
e9b046fd LC |
357 | (use-modules (guix build download) |
358 | (guix base32)) | |
cd436bf0 | 359 | |
e9b046fd LC |
360 | (let ((value-from-environment (lambda (variable) |
361 | (call-with-input-string | |
362 | (getenv variable) | |
363 | read)))) | |
364 | (url-fetch (value-from-environment "guix download url") | |
365 | #$output | |
366 | #:mirrors (call-with-input-file #$%mirror-file read) | |
ced20032 | 367 | |
e9b046fd LC |
368 | ;; Content-addressed mirrors. |
369 | #:hashes | |
370 | (value-from-environment "guix download hashes") | |
371 | #:content-addressed-mirrors | |
372 | (primitive-load #$%content-addressed-mirror-file)))))) | |
6f8f8ccb | 373 | |
882383a9 LC |
374 | (let ((uri (and (string? url) (string->uri url)))) |
375 | (if (or (and (string? url) (not uri)) | |
376 | (and uri (memq (uri-scheme uri) '(#f file)))) | |
f220a838 LC |
377 | (interned-file (if uri (uri-path uri) url) |
378 | (or name file-name)) | |
379 | (mlet %store-monad ((guile (package->derivation guile system))) | |
882383a9 | 380 | (gexp->derivation (or name file-name) builder |
f220a838 | 381 | #:guile-for-build guile |
882383a9 LC |
382 | #:system system |
383 | #:hash-algo hash-algo | |
384 | #:hash hash | |
56c72822 | 385 | |
ced20032 LC |
386 | ;; Use environment variables and a fixed script |
387 | ;; name so there's only one script in store for | |
388 | ;; all the downloads. | |
389 | #:script-name "download" | |
390 | #:env-vars | |
cd436bf0 LC |
391 | `(("guix download url" . ,(object->string url)) |
392 | ("guix download hashes" | |
393 | . ,(object->string `((,hash-algo . ,hash))))) | |
ced20032 | 394 | |
0d883137 LC |
395 | ;; Honor the user's proxy settings. |
396 | #:leaked-env-vars '("http_proxy" "https_proxy") | |
397 | ||
6b44a097 LC |
398 | ;; In general, offloading downloads is not a good |
399 | ;; idea. Daemons before 0.8.3 would also | |
400 | ;; interpret this as "do not substitute" (see | |
401 | ;; <https://bugs.gnu.org/18747>.) | |
402 | #:local-build? #t))))) | |
62cab99c | 403 | |
95001d4b LC |
404 | (define* (url-fetch/tarbomb url hash-algo hash |
405 | #:optional name | |
406 | #:key (system (%current-system)) | |
407 | (guile (default-guile))) | |
408 | "Similar to 'url-fetch' but unpack the file from URL in a directory of its | |
409 | own. This helper makes it easier to deal with \"tar bombs\"." | |
410 | (define gzip | |
411 | (module-ref (resolve-interface '(gnu packages compression)) 'gzip)) | |
412 | (define tar | |
413 | (module-ref (resolve-interface '(gnu packages base)) 'tar)) | |
414 | ||
415 | (mlet %store-monad ((drv (url-fetch url hash-algo hash | |
416 | (string-append "tarbomb-" name) | |
417 | #:system system | |
418 | #:guile guile))) | |
419 | ;; Take the tar bomb, and simply unpack it as a directory. | |
420 | (gexp->derivation name | |
421 | #~(begin | |
422 | (mkdir #$output) | |
423 | (setenv "PATH" (string-append #$gzip "/bin")) | |
424 | (chdir #$output) | |
425 | (zero? (system* (string-append #$tar "/bin/tar") | |
426 | "xf" #$drv))) | |
427 | #:local-build? #t))) | |
428 | ||
861693f3 | 429 | (define* (download-to-store store url #:optional (name (basename url)) |
a43b55f1 | 430 | #:key (log (current-error-port)) recursive?) |
861693f3 | 431 | "Download from URL to STORE, either under NAME or URL's basename if |
a43b55f1 LC |
432 | omitted. Write progress reports to LOG. RECURSIVE? has the same effect as |
433 | the same-named parameter of 'add-to-store'." | |
d8907ac4 LC |
434 | (define uri |
435 | (string->uri url)) | |
436 | ||
d91a8791 | 437 | (if (or (not uri) (memq (uri-scheme uri) '(file #f))) |
a43b55f1 | 438 | (add-to-store store name recursive? "sha256" |
d91a8791 | 439 | (if uri (uri-path uri) url)) |
d8907ac4 LC |
440 | (call-with-temporary-output-file |
441 | (lambda (temp port) | |
442 | (let ((result | |
443 | (parameterize ((current-output-port log)) | |
444 | (build:url-fetch url temp #:mirrors %mirrors)))) | |
445 | (close port) | |
446 | (and result | |
a43b55f1 | 447 | (add-to-store store name recursive? "sha256" temp))))))) |
861693f3 | 448 | |
62cab99c | 449 | ;;; download.scm ends here |