Commit | Line | Data |
---|---|---|
233e7676 | 1 | ;;; GNU Guix --- Functional package management for GNU |
483f1158 | 2 | ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org> |
62cab99c | 3 | ;;; |
233e7676 | 4 | ;;; This file is part of GNU Guix. |
62cab99c | 5 | ;;; |
233e7676 | 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it |
62cab99c LC |
7 | ;;; under the terms of the GNU General Public License as published by |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
233e7676 | 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but |
62cab99c LC |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
233e7676 | 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
62cab99c LC |
18 | |
19 | (define-module (guix download) | |
20 | #:use-module (ice-9 match) | |
21 | #:use-module (guix derivations) | |
22 | #:use-module (guix packages) | |
23 | #:use-module ((guix store) #:select (derivation-path?)) | |
24 | #:use-module (guix utils) | |
483f1158 LC |
25 | #:use-module (srfi srfi-1) |
26 | #:use-module (srfi srfi-11) | |
94d222ad | 27 | #:use-module (srfi srfi-26) |
ec4d308a LC |
28 | #:export (%mirrors |
29 | url-fetch)) | |
62cab99c LC |
30 | |
31 | ;;; Commentary: | |
32 | ;;; | |
33 | ;;; Produce fixed-output derivations with data fetched over HTTP or FTP. | |
34 | ;;; | |
35 | ;;; Code: | |
36 | ||
94d222ad LC |
37 | (define %mirrors |
38 | ;; Mirror lists used when `mirror://' URLs are passed. | |
39 | (let* ((gnu-mirrors | |
40 | '(;; This one redirects to a (supposedly) nearby and (supposedly) | |
41 | ;; up-to-date mirror. | |
42 | "http://ftpmirror.gnu.org/" | |
43 | ||
44 | "ftp://ftp.cs.tu-berlin.de/pub/gnu/" | |
45 | "ftp://ftp.chg.ru/pub/gnu/" | |
46 | "ftp://ftp.funet.fi/pub/mirrors/ftp.gnu.org/gnu/" | |
47 | ||
48 | ;; This one is the master repository, and thus it's always | |
49 | ;; up-to-date. | |
50 | "http://ftp.gnu.org/pub/gnu/"))) | |
51 | `((gnu ,@gnu-mirrors) | |
52 | (gcc | |
53 | "ftp://ftp.nluug.nl/mirror/languages/gcc/" | |
54 | "ftp://ftp.fu-berlin.de/unix/languages/gcc/" | |
55 | "ftp://ftp.irisa.fr/pub/mirrors/gcc.gnu.org/gcc/" | |
56 | "ftp://gcc.gnu.org/pub/gcc/" | |
57 | ,@(map (cut string-append <> "/gcc") gnu-mirrors)) | |
58 | (gnupg | |
59 | "ftp://gd.tuwien.ac.at/privacy/gnupg/" | |
60 | "ftp://gnupg.x-zone.org/pub/gnupg/" | |
61 | "ftp://ftp.gnupg.cz/pub/gcrypt/" | |
62 | "ftp://sunsite.dk/pub/security/gcrypt/" | |
63 | "http://gnupg.wildyou.net/" | |
64 | "http://ftp.gnupg.zone-h.org/" | |
65 | "ftp://ftp.jyu.fi/pub/crypt/gcrypt/" | |
66 | "ftp://trumpetti.atm.tut.fi/gcrypt/" | |
67 | "ftp://mirror.cict.fr/gnupg/" | |
68 | "ftp://ftp.strasbourg.linuxfr.org/pub/gnupg/") | |
69 | (savannah | |
a4eabecd | 70 | "http://download.savannah.gnu.org/releases/" |
94d222ad LC |
71 | "ftp://ftp.twaren.net/Unix/NonGNU/" |
72 | "ftp://mirror.csclub.uwaterloo.ca/nongnu/" | |
73 | "ftp://mirror.publicns.net/pub/nongnu/" | |
74 | "ftp://savannah.c3sl.ufpr.br/" | |
75 | "http://ftp.cc.uoc.gr/mirrors/nongnu.org/" | |
76 | "http://ftp.twaren.net/Unix/NonGNU/" | |
77 | "http://mirror.csclub.uwaterloo.ca/nongnu/" | |
78 | "http://nongnu.askapache.com/" | |
79 | "http://savannah.c3sl.ufpr.br/" | |
80 | "http://www.centervenus.com/mirrors/nongnu/") | |
81 | (sourceforge | |
82 | "http://prdownloads.sourceforge.net/" | |
83 | "http://heanet.dl.sourceforge.net/sourceforge/" | |
84 | "http://surfnet.dl.sourceforge.net/sourceforge/" | |
85 | "http://dfn.dl.sourceforge.net/sourceforge/" | |
86 | "http://mesh.dl.sourceforge.net/sourceforge/" | |
87 | "http://ovh.dl.sourceforge.net/sourceforge/" | |
c43e0061 | 88 | "http://osdn.dl.sourceforge.net/sourceforge/") |
b40b259f LC |
89 | (kernel.org |
90 | "http://www.all.kernel.org/pub/" | |
91 | "http://ramses.wh2.tu-dresden.de/pub/mirrors/kernel.org/" | |
92 | "http://linux-kernel.uio.no/pub/" | |
93 | "http://kernel.osuosl.org/pub/" | |
47f9db41 LC |
94 | "ftp://ftp.funet.fi/pub/mirrors/ftp.kernel.org/pub/") |
95 | (apache ; from http://www.apache.org/mirrors/dist.html | |
96 | "http://www.eu.apache.org/dist/" | |
97 | "http://www.us.apache.org/dist/" | |
98 | "ftp://gd.tuwien.ac.at/pub/infosys/servers/http/apache/dist/" | |
99 | "http://apache.belnet.be/" | |
100 | "http://mirrors.ircam.fr/pub/apache/" | |
101 | "http://apache-mirror.rbc.ru/pub/apache/")))) | |
94d222ad | 102 | |
483f1158 LC |
103 | (define (gnutls-derivation store system) |
104 | "Return the GnuTLS derivation for SYSTEM." | |
105 | (let* ((module (resolve-interface '(gnu packages gnutls))) | |
106 | (gnutls (module-ref module 'gnutls))) | |
107 | (package-derivation store gnutls system))) | |
94d222ad | 108 | |
62cab99c LC |
109 | (define* (url-fetch store url hash-algo hash |
110 | #:optional name | |
94d222ad LC |
111 | #:key (system (%current-system)) guile |
112 | (mirrors %mirrors)) | |
62cab99c LC |
113 | "Return the path of a fixed-output derivation in STORE that fetches |
114 | URL (a string, or a list of strings denoting alternate URLs), which is | |
115 | expected to have hash HASH of type HASH-ALGO (a symbol). By default, | |
116 | the file name is the base name of URL; optionally, NAME can specify a | |
94d222ad LC |
117 | different file name. |
118 | ||
119 | When one of the URL starts with mirror://, then its host part is | |
120 | interpreted as the name of a mirror scheme, taken from MIRRORS; MIRRORS | |
121 | must be a list of symbol/URL-list pairs." | |
62cab99c LC |
122 | (define builder |
123 | `(begin | |
124 | (use-modules (guix build download)) | |
94d222ad LC |
125 | (url-fetch ',url %output |
126 | #:mirrors ',mirrors))) | |
62cab99c LC |
127 | |
128 | (define guile-for-build | |
129 | (match guile | |
130 | ((? package?) | |
131 | (package-derivation store guile system)) | |
132 | ((and (? string?) (? derivation-path?)) | |
133 | guile) | |
134 | (#f ; the default | |
1ffa7090 | 135 | (let* ((distro (resolve-interface '(gnu packages base))) |
62cab99c LC |
136 | (guile (module-ref distro 'guile-final))) |
137 | (package-derivation store guile system))))) | |
138 | ||
139 | (define file-name | |
140 | (match url | |
141 | ((head _ ...) | |
142 | (basename head)) | |
143 | (_ | |
144 | (basename url)))) | |
145 | ||
483f1158 LC |
146 | (define need-gnutls? |
147 | ;; True if any of the URLs need TLS support. | |
148 | (let ((https? (cut string-prefix? "https://" <>))) | |
149 | (match url | |
150 | ((? string?) | |
151 | (https? url)) | |
152 | ((url ...) | |
153 | (any https? url))))) | |
154 | ||
155 | (let*-values (((gnutls-drv-path gnutls-drv) | |
156 | (if need-gnutls? | |
157 | (gnutls-derivation store system) | |
158 | (values #f #f))) | |
159 | ((gnutls) | |
160 | (and gnutls-drv | |
161 | (derivation-output-path | |
162 | (assoc-ref (derivation-outputs gnutls-drv) | |
163 | "out")))) | |
164 | ((env-vars) | |
165 | (if gnutls | |
166 | (let ((dir (string-append gnutls "/share/guile/site"))) | |
167 | ;; XXX: `GUILE_LOAD_COMPILED_PATH' is overridden | |
168 | ;; by `build-expression->derivation', so we can't | |
169 | ;; set it here. | |
170 | `(("GUILE_LOAD_PATH" . ,dir))) | |
171 | '()))) | |
172 | (build-expression->derivation store (or name file-name) system | |
173 | builder | |
174 | (if gnutls-drv | |
175 | `(("gnutls" ,gnutls-drv-path)) | |
176 | '()) | |
177 | #:hash-algo hash-algo | |
178 | #:hash hash | |
179 | #:modules '((guix build download) | |
180 | (guix build utils) | |
181 | (guix ftp-client)) | |
182 | #:guile-for-build guile-for-build | |
183 | #:env-vars env-vars))) | |
62cab99c LC |
184 | |
185 | ;;; download.scm ends here |