download.scm 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2013, 2014, 2015 Andreas Enge <andreas@enge.fr>
  4. ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
  5. ;;; Copyright © 2016 Alex Griffin <a@ajgrf.com>
  6. ;;; Copyright © 2016 David Craven <david@craven.ch>
  7. ;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
  8. ;;; Copyright © 2019 Guy Fleury Iteriteka <hoonandon@gmail.com>
  9. ;;;
  10. ;;; This file is part of GNU Guix.
  11. ;;;
  12. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  13. ;;; under the terms of the GNU General Public License as published by
  14. ;;; the Free Software Foundation; either version 3 of the License, or (at
  15. ;;; your option) any later version.
  16. ;;;
  17. ;;; GNU Guix is distributed in the hope that it will be useful, but
  18. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. ;;; GNU General Public License for more details.
  21. ;;;
  22. ;;; You should have received a copy of the GNU General Public License
  23. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  24. (define-module (guix download)
  25. #:use-module (ice-9 match)
  26. #:use-module (guix derivations)
  27. #:use-module (guix packages)
  28. #:use-module (guix store)
  29. #:use-module ((guix build download) #:prefix build:)
  30. #:use-module (guix monads)
  31. #:use-module (guix gexp)
  32. #:use-module (guix utils)
  33. #:use-module (web uri)
  34. #:use-module (srfi srfi-1)
  35. #:use-module (srfi srfi-26)
  36. #:export (%mirrors
  37. url-fetch
  38. url-fetch/executable
  39. url-fetch/tarbomb
  40. url-fetch/zipbomb
  41. download-to-store))
  42. ;;; Commentary:
  43. ;;;
  44. ;;; Produce fixed-output derivations with data fetched over HTTP or FTP.
  45. ;;;
  46. ;;; Code:
  47. (define %mirrors
  48. ;; Mirror lists used when `mirror://' URLs are passed.
  49. (let* ((gnu-mirrors
  50. '(;; This one redirects to a (supposedly) nearby and (supposedly)
  51. ;; up-to-date mirror.
  52. "https://ftpmirror.gnu.org/gnu/"
  53. "ftp://ftp.cs.tu-berlin.de/pub/gnu/"
  54. "ftp://ftp.funet.fi/pub/mirrors/ftp.gnu.org/gnu/"
  55. ;; This one is the master repository, and thus it's always
  56. ;; up-to-date.
  57. "http://ftp.gnu.org/pub/gnu/")))
  58. `((gnu ,@gnu-mirrors)
  59. (gcc
  60. "ftp://ftp.nluug.nl/mirror/languages/gcc/"
  61. "ftp://ftp.fu-berlin.de/unix/languages/gcc/"
  62. "ftp://ftp.irisa.fr/pub/mirrors/gcc.gnu.org/gcc/"
  63. "ftp://gcc.gnu.org/pub/gcc/"
  64. ,@(map (cut string-append <> "/gcc") gnu-mirrors))
  65. (gnupg
  66. "http://artfiles.org/gnupg.org"
  67. "http://www.crysys.hu/"
  68. "https://gnupg.org/ftp/gcrypt/"
  69. "ftp://mirrors.dotsrc.org/gcrypt/"
  70. "ftp://mirror.cict.fr/gnupg/"
  71. "ftp://ftp.franken.de/pub/crypt/mirror/ftp.gnupg.org/gcrypt/"
  72. "ftp://ftp.freenet.de/pub/ftp.gnupg.org/gcrypt/"
  73. "ftp://ftp.hi.is/pub/mirrors/gnupg/"
  74. "ftp://ftp.heanet.ie/mirrors/ftp.gnupg.org/gcrypt/"
  75. "ftp://ftp.bit.nl/mirror/gnupg/"
  76. "ftp://ftp.surfnet.nl/pub/security/gnupg/"
  77. "ftp://ftp.iasi.roedu.net/pub/mirrors/ftp.gnupg.org/"
  78. "ftp://ftp.sunet.se/pub/security/gnupg/"
  79. "ftp://mirror.switch.ch/mirror/gnupg/"
  80. "ftp://mirror.tje.me.uk/pub/mirrors/ftp.gnupg.org/"
  81. "ftp://ftp.mirrorservice.org/sites/ftp.gnupg.org/gcrypt/"
  82. "ftp://ftp.ring.gr.jp/pub/net/gnupg/"
  83. "ftp://ftp.gnupg.org/gcrypt/")
  84. (gnome
  85. "http://ftp.belnet.be/ftp.gnome.org/"
  86. "http://ftp.linux.org.uk/mirrors/ftp.gnome.org/"
  87. "http://ftp.gnome.org/pub/GNOME/"
  88. "https://download.gnome.org/"
  89. "http://mirror.yandex.ru/mirrors/ftp.gnome.org/")
  90. (hackage
  91. "http://hackage.haskell.org/")
  92. (savannah ; http://download0.savannah.gnu.org/mirmon/savannah/
  93. "http://download.savannah.gnu.org/releases/"
  94. "http://nongnu.freemirror.org/nongnu/"
  95. "http://ftp.cc.uoc.gr/mirrors/nongnu.org/"
  96. "http://ftp.twaren.net/Unix/NonGNU/"
  97. "http://mirror.csclub.uwaterloo.ca/nongnu/"
  98. "http://nongnu.askapache.com/"
  99. "http://savannah.c3sl.ufpr.br/"
  100. "http://download.savannah.gnu.org/releases-noredirect/"
  101. "http://download-mirror.savannah.gnu.org/releases/"
  102. "ftp://ftp.twaren.net/Unix/NonGNU/"
  103. "ftp://mirror.csclub.uwaterloo.ca/nongnu/"
  104. "ftp://mirror.publicns.net/pub/nongnu/"
  105. "ftp://savannah.c3sl.ufpr.br/")
  106. (sourceforge ; https://sourceforge.net/p/forge/documentation/Mirrors/
  107. "http://downloads.sourceforge.net/project/"
  108. "http://ufpr.dl.sourceforge.net/project/"
  109. "http://heanet.dl.sourceforge.net/project/"
  110. "http://freefr.dl.sourceforge.net/project/"
  111. "http://internode.dl.sourceforge.net/project/"
  112. "http://jaist.dl.sourceforge.net/project/"
  113. "http://kent.dl.sourceforge.net/project/"
  114. "http://liquidtelecom.dl.sourceforge.net/project/"
  115. ;; "http://nbtelecom.dl.sourceforge.net/project/" ;never returns 404s
  116. "http://nchc.dl.sourceforge.net/project/"
  117. "http://ncu.dl.sourceforge.net/project/"
  118. "http://netcologne.dl.sourceforge.net/project/"
  119. "http://netix.dl.sourceforge.net/project/"
  120. "http://pilotfiber.dl.sourceforge.net/project/"
  121. "http://superb-sea2.dl.sourceforge.net/project/"
  122. "http://tenet.dl.sourceforge.net/project/"
  123. "http://vorboss.dl.sourceforge.net/project/"
  124. "http://netassist.dl.sourceforge.net/project/")
  125. (netfilter.org ; https://www.netfilter.org/mirrors.html
  126. "http://ftp.netfilter.org/pub/"
  127. "ftp://ftp.es.netfilter.org/mirrors/netfilter/"
  128. "ftp://ftp.hu.netfilter.org/"
  129. "ftp://www.lt.netfilter.org/pub/")
  130. (kernel.org
  131. "http://linux-kernel.uio.no/pub/"
  132. "http://kernel.osuosl.org/pub/"
  133. "http://ftp.be.debian.org/pub/"
  134. "http://mirror.linux.org.au/"
  135. "ftp://ftp.funet.fi/pub/mirrors/ftp.kernel.org/pub/")
  136. (apache ; from http://www.apache.org/mirrors/dist.html
  137. "http://www.eu.apache.org/dist/"
  138. "http://www.us.apache.org/dist/"
  139. "https://ftp.nluug.nl/internet/apache/"
  140. "http://apache.mirror.iweb.ca/"
  141. "http://mirrors.ircam.fr/pub/apache/"
  142. "http://apache.mirrors.ovh.net/ftp.apache.org/dist/"
  143. "http://apache-mirror.rbc.ru/pub/apache/"
  144. "ftp://ftp.osuosl.org/pub/apache/"
  145. "http://mirrors.ibiblio.org/apache/"
  146. ;; As a last resort, try the archive.
  147. "http://archive.apache.org/dist/")
  148. (xorg ; from http://www.x.org/wiki/Releases/Download
  149. "http://www.x.org/releases/" ; main mirrors
  150. "http://mirror.csclub.uwaterloo.ca/x.org/" ; North America
  151. "http://xorg.mirrors.pair.com/"
  152. "http://mirror.us.leaseweb.net/xorg/"
  153. "ftp://mirror.csclub.uwaterloo.ca/x.org/"
  154. "ftp://xorg.mirrors.pair.com/"
  155. "ftp://artfiles.org/x.org/" ; Europe
  156. "ftp://ftp.chg.ru/pub/X11/x.org/"
  157. "ftp://ftp.fu-berlin.de/unix/X11/FTP.X.ORG/"
  158. "ftp://ftp.gwdg.de/pub/x11/x.org/"
  159. "ftp://ftp.mirrorservice.org/sites/ftp.x.org/"
  160. "ftp://ftp.ntua.gr/pub/X11/"
  161. "ftp://ftp.piotrkosoft.net/pub/mirrors/ftp.x.org/"
  162. "ftp://ftp.portal-to-web.de/pub/mirrors/x.org/"
  163. "ftp://ftp.solnet.ch/mirror/x.org/"
  164. "ftp://mi.mirror.garr.it/mirrors/x.org/"
  165. "ftp://mirror.cict.fr/x.org/"
  166. "ftp://mirror.switch.ch/mirror/X11/"
  167. "ftp://mirrors.ircam.fr/pub/x.org/"
  168. "ftp://x.mirrors.skynet.be/pub/ftp.x.org/"
  169. "http://x.cs.pu.edu.tw/" ; East Asia
  170. "ftp://ftp.cs.cuhk.edu.hk/pub/X11"
  171. "ftp://ftp.u-aizu.ac.jp/pub/x11/x.org/"
  172. "ftp://ftp.yz.yamagata-u.ac.jp/pub/X11/x.org/"
  173. "ftp://ftp.kaist.ac.kr/x.org/"
  174. "ftp://mirrors.go-part.com/xorg/"
  175. "ftp://ftp.is.co.za/pub/x.org") ; South Africa
  176. (cpan
  177. "http://www.cpan.org/"
  178. "http://cpan.metacpan.org/"
  179. ;; A selection of HTTP mirrors from http://www.cpan.org/SITES.html.
  180. ;; Europe.
  181. "http://ftp.belnet.be/mirror/ftp.cpan.org/"
  182. "http://mirrors.nic.cz/CPAN/"
  183. "http://mirror.ibcp.fr/pub/CPAN/"
  184. "http://ftp.ntua.gr/pub/lang/perl/"
  185. "http://mirror.as43289.net/pub/CPAN/"
  186. "http://cpan.cs.uu.nl/"
  187. "http://cpan.uib.no/"
  188. "http://cpan-mirror.rbc.ru/pub/CPAN/"
  189. "http://mirror.sbb.rs/CPAN/"
  190. "http://cpan.lnx.sk/"
  191. "http://ftp.rediris.es/mirror/CPAN/"
  192. "http://mirror.ox.ac.uk/sites/www.cpan.org/"
  193. ;; Africa.
  194. "http://mirror.liquidtelecom.com/CPAN/"
  195. "http://cpan.mirror.ac.za/"
  196. "http://mirror.is.co.za/pub/cpan/"
  197. "http://cpan.saix.net/"
  198. "http://mirror.ucu.ac.ug/cpan/"
  199. ;; North America.
  200. "http://mirrors.gossamer-threads.com/CPAN/"
  201. "http://mirror.csclub.uwaterloo.ca/CPAN/"
  202. "http://mirrors.ucr.ac.cr/CPAN/"
  203. "http://www.msg.com.mx/CPAN/"
  204. "http://mirrors.namecheap.com/CPAN/"
  205. "http://mirror.uic.edu/CPAN/"
  206. "http://mirror.datapipe.net/CPAN/"
  207. "http://mirror.cc.columbia.edu/pub/software/cpan/"
  208. "http://mirror.uta.edu/CPAN/"
  209. ;; South America.
  210. "http://cpan.mmgdesigns.com.ar/"
  211. "http://mirror.nbtelecom.com.br/CPAN/"
  212. "http://linorg.usp.br/CPAN/"
  213. "http://cpan.dcc.uchile.cl/"
  214. "http://mirror.cedia.org.ec/CPAN/"
  215. ;; Oceania.
  216. "http://cpan.mirror.serversaustralia.com.au/"
  217. "http://mirror.waia.asn.au/pub/cpan/"
  218. "http://mirror.as24220.net/pub/cpan/"
  219. "http://cpan.lagoon.nc/pub/CPAN/"
  220. "http://cpan.inspire.net.nz/"
  221. ;; Asia.
  222. "http://mirror.dhakacom.com/CPAN/"
  223. "http://mirrors.ustc.edu.cn/CPAN/"
  224. "http://ftp.cuhk.edu.hk/pub/packages/perl/CPAN/"
  225. "http://kambing.ui.ac.id/cpan/"
  226. "http://cpan.hostiran.ir/"
  227. "http://ftp.nara.wide.ad.jp/pub/CPAN/"
  228. "http://mirror.neolabs.kz/CPAN/"
  229. "http://cpan.nctu.edu.tw/"
  230. "http://cpan.ulak.net.tr/"
  231. "http://mirrors.vinahost.vn/CPAN/")
  232. (cran
  233. ;; Arbitrary mirrors from http://cran.r-project.org/mirrors.html
  234. ;; This one automatically redirects to servers worldwide
  235. "http://cran.r-project.org/"
  236. "http://cran.rstudio.com/"
  237. "http://cran.univ-lyon1.fr/"
  238. "http://cran.ism.ac.jp/"
  239. "http://cran.stat.auckland.ac.nz/"
  240. "http://cran.mirror.ac.za/"
  241. "http://cran.csie.ntu.edu.tw/")
  242. (imagemagick
  243. ;; from http://www.imagemagick.org/script/download.php
  244. ;; (without mirrors that are unavailable or not up to date)
  245. ;; mirrors keeping old versions at the top level
  246. "https://sunsite.icm.edu.pl/packages/ImageMagick/"
  247. ;; mirrors moving old versions to "legacy"
  248. "http://mirror.checkdomain.de/imagemagick/"
  249. "http://ftp.surfnet.nl/pub/ImageMagick/"
  250. "http://mirror.searchdaimon.com/ImageMagick"
  251. "http://mirror.is.co.za/pub/imagemagick/"
  252. "http://www.imagemagick.org/download/"
  253. "ftp://mirror.aarnet.edu.au/pub/imagemagick/"
  254. "ftp://ftp.kddlabs.co.jp/graphics/ImageMagick/"
  255. "ftp://ftp.u-aizu.ac.jp/pub/graphics/image/ImageMagick/imagemagick.org/"
  256. "ftp://ftp.nluug.nl/pub/ImageMagick/"
  257. "ftp://ftp.tpnet.pl/pub/graphics/ImageMagick/"
  258. "ftp://ftp.fifi.org/pub/ImageMagick/"
  259. ;; one legacy location as a last resort
  260. "http://www.imagemagick.org/download/legacy/")
  261. (debian
  262. "http://ftp.de.debian.org/debian/"
  263. "http://ftp.fr.debian.org/debian/"
  264. "http://ftp.debian.org/debian/"
  265. "http://archive.debian.org/debian/")
  266. (kde
  267. "http://download.kde.org"
  268. "http://download.kde.org/Attic" ; for when it gets archived.
  269. ;; Mirrors from http://files.kde.org/extra/mirrors.html
  270. ;; Europe
  271. "http://mirror.easyname.at/kde"
  272. "http://mirror.karneval.cz/pub/kde"
  273. "http://ftp.fi.muni.cz/pub/kde/"
  274. "http://mirror.oss.maxcdn.com/kde/"
  275. "http://ftp5.gwdg.de/pub/linux/kde/"
  276. "http://ftp-stud.fht-esslingen.de/Mirrors/ftp.kde.org/pub/kde/"
  277. "http://mirror.klaus-uwe.me/kde/ftp/"
  278. "http://kde.beta.mirror.ga/"
  279. "http://kde.alpha.mirror.ga/"
  280. "http://mirror.netcologne.de/kde"
  281. "http://vesta.informatik.rwth-aachen.de/ftp/pub/mirror/kde/"
  282. "http://ftp.rz.uni-wuerzburg.de/pub/unix/kde/"
  283. "http://mirrors.dotsrc.org/kde/"
  284. "http://ftp.funet.fi/pub/mirrors/ftp.kde.org/pub/kde/"
  285. "http://kde-mirror.freenux.org/"
  286. "http://mirrors.ircam.fr/pub/KDE/"
  287. "http://www-ftp.lip6.fr/pub/X11/kde/"
  288. "http://fr2.rpmfind.net/linux/KDE/"
  289. "http://kde.mirror.anlx.net/"
  290. "http://www.mirrorservice.org/sites/ftp.kde.org/pub/kde/"
  291. "http://ftp.heanet.ie/mirrors/ftp.kde.org/"
  292. "http://ftp.nluug.nl/pub/windowing/kde/"
  293. "http://ftp.surfnet.nl/windowing/kde/"
  294. "http://ftp.icm.edu.pl/pub/unix/kde/"
  295. "http://ftp.pbone.net/pub/kde/"
  296. "http://piotrkosoft.net/pub/mirrors/ftp.kde.org/"
  297. "http://mirrors.fe.up.pt/pub/kde/"
  298. "http://ftp.iasi.roedu.net/pub/mirrors/ftp.kde.org/"
  299. "http://ftp.acc.umu.se/mirror/kde.org/ftp/"
  300. "http://kde.ip-connect.vn.ua/"
  301. ;; North America
  302. "http://mirror.its.dal.ca/kde/"
  303. "http://mirror.csclub.uwaterloo.ca/kde/"
  304. "http://mirror.cc.columbia.edu/pub/software/kde/"
  305. "http://kde.mirrors.hoobly.com/"
  306. "http://ftp.ussg.iu.edu/kde/"
  307. "http://mirrors.mit.edu/kde/"
  308. "http://kde.mirrors.tds.net/pub/kde/"
  309. ;; Oceania
  310. "http://ftp.kddlabs.co.jp/pub/X11/kde/"
  311. "http://kde.mirror.uber.com.au/")
  312. (openbsd
  313. "https://ftp.openbsd.org/pub/OpenBSD/"
  314. ;; Anycast CDN redirecting to your friendly local mirror.
  315. "https://mirrors.evowise.com/pub/OpenBSD/"
  316. ;; Other HTTPS mirrors from https://www.openbsd.org/ftp.html
  317. "https://mirror.aarnet.edu.au/pub/OpenBSD/"
  318. "https://ftp2.eu.openbsd.org/pub/OpenBSD/"
  319. "https://openbsd.c3sl.ufpr.br/pub/OpenBSD/"
  320. "https://openbsd.ipacct.com/pub/OpenBSD/"
  321. "https://ftp.OpenBSD.org/pub/OpenBSD/"
  322. "https://openbsd.cs.toronto.edu/pub/OpenBSD/"
  323. "https://openbsd.delfic.org/pub/OpenBSD/"
  324. "https://openbsd.mirror.netelligent.ca/pub/OpenBSD/"
  325. "https://mirrors.ucr.ac.cr/pub/OpenBSD/"
  326. "https://mirrors.dotsrc.org/pub/OpenBSD/"
  327. "https://mirror.one.com/pub/OpenBSD/"
  328. "https://ftp.fr.openbsd.org/pub/OpenBSD/"
  329. "https://ftp2.fr.openbsd.org/pub/OpenBSD/"
  330. "https://mirrors.ircam.fr/pub/OpenBSD/"
  331. "https://ftp.spline.de/pub/OpenBSD/"
  332. "https://mirror.hs-esslingen.de/pub/OpenBSD/"
  333. "https://ftp.halifax.rwth-aachen.de/openbsd/"
  334. "https://ftp.hostserver.de/pub/OpenBSD/"
  335. "https://ftp.fau.de/pub/OpenBSD/"
  336. "https://ftp.cc.uoc.gr/pub/OpenBSD/"
  337. "https://openbsd.hk/pub/OpenBSD/"
  338. "https://ftp.heanet.ie/pub/OpenBSD/"
  339. "https://openbsd.mirror.garr.it/pub/OpenBSD/"
  340. "https://mirror.litnet.lt/pub/OpenBSD/"
  341. "https://mirror.meerval.net/pub/OpenBSD/"
  342. "https://ftp.nluug.nl/pub/OpenBSD/"
  343. "https://ftp.bit.nl/pub/OpenBSD/"
  344. "https://mirrors.dalenys.com/pub/OpenBSD/"
  345. "https://ftp.icm.edu.pl/pub/OpenBSD/"
  346. "https://ftp.rnl.tecnico.ulisboa.pt/pub/OpenBSD/"
  347. "https://mirrors.pidginhost.com/pub/OpenBSD/"
  348. "https://mirror.yandex.ru/pub/OpenBSD/"
  349. "https://ftp.eu.openbsd.org/pub/OpenBSD/"
  350. "https://ftp.yzu.edu.tw/pub/OpenBSD/"
  351. "https://www.mirrorservice.org/pub/OpenBSD/"
  352. "https://anorien.csc.warwick.ac.uk/pub/OpenBSD/"
  353. "https://mirror.bytemark.co.uk/pub/OpenBSD/"
  354. "https://mirrors.sonic.net/pub/OpenBSD/"
  355. "https://ftp3.usa.openbsd.org/pub/OpenBSD/"
  356. "https://mirrors.syringanetworks.net/pub/OpenBSD/"
  357. "https://openbsd.mirror.constant.com/pub/OpenBSD/"
  358. "https://ftp4.usa.openbsd.org/pub/OpenBSD/"
  359. "https://ftp5.usa.openbsd.org/pub/OpenBSD/"
  360. "https://mirror.esc7.net/pub/OpenBSD/")
  361. (mate
  362. "https://pub.mate-desktop.org/releases/"
  363. "http://pub.mate-desktop.org/releases/"))))
  364. (define %mirror-file
  365. ;; Copy of the list of mirrors to a file. This allows us to keep a single
  366. ;; copy in the store, and computing it here avoids repeated calls to
  367. ;; 'object->string'.
  368. (plain-file "mirrors" (object->string %mirrors)))
  369. (define %content-addressed-mirrors
  370. ;; List of content-addressed mirrors. Each mirror is represented as a
  371. ;; procedure that takes a file name, an algorithm (symbol) and a hash
  372. ;; (bytevector), and returns a URL or #f.
  373. '(begin
  374. (use-modules (guix base32))
  375. (define (guix-publish host)
  376. (lambda (file algo hash)
  377. ;; Files served by 'guix publish' are accessible under a single
  378. ;; hash algorithm.
  379. (string-append "https://" host "/file/"
  380. file "/" (symbol->string algo) "/"
  381. (bytevector->nix-base32-string hash))))
  382. ;; XXX: (guix base16) appeared in March 2017 (and thus 0.13.0) so old
  383. ;; installations of the daemon might lack it. Thus, load it lazily to
  384. ;; avoid gratuitous errors. See <https://bugs.gnu.org/33542>.
  385. (module-autoload! (current-module)
  386. '(guix base16) '(bytevector->base16-string))
  387. (list (guix-publish "ci.guix.gnu.org")
  388. (lambda (file algo hash)
  389. ;; 'tarballs.nixos.org' supports several algorithms.
  390. (string-append "https://tarballs.nixos.org/"
  391. (symbol->string algo) "/"
  392. (bytevector->nix-base32-string hash)))
  393. (lambda (file algo hash)
  394. ;; Software Heritage usually archives VCS history rather than
  395. ;; tarballs, but tarballs are sometimes available (and can be
  396. ;; explicitly stored there.) For example, see
  397. ;; <https://archive.softwareheritage.org/api/1/content/sha256:92d0fa1c311cacefa89853bdb53c62f4110cdfda3820346b59cbd098f40f955e/>.
  398. (string-append "https://archive.softwareheritage.org/api/1/content/"
  399. (symbol->string algo) ":"
  400. (bytevector->base16-string hash) "/raw/")))))
  401. (define %content-addressed-mirror-file
  402. ;; Content-addressed mirrors stored in a file.
  403. (plain-file "content-addressed-mirrors"
  404. (object->string %content-addressed-mirrors)))
  405. (define built-in-builders*
  406. (store-lift built-in-builders))
  407. (define* (built-in-download file-name url
  408. #:key system hash-algo hash
  409. mirrors content-addressed-mirrors
  410. executable?
  411. (guile 'unused))
  412. "Download FILE-NAME from URL using the built-in 'download' builder. When
  413. EXECUTABLE? is true, make the downloaded file executable.
  414. This is an \"out-of-band\" download in that the returned derivation does not
  415. explicitly depend on Guile, GnuTLS, etc. Instead, the daemon performs the
  416. download by itself using its own dependencies."
  417. (mlet %store-monad ((mirrors (lower-object mirrors))
  418. (content-addressed-mirrors
  419. (lower-object content-addressed-mirrors)))
  420. (raw-derivation file-name "builtin:download" '()
  421. #:system system
  422. #:hash-algo hash-algo
  423. #:hash hash
  424. #:recursive? executable?
  425. #:sources (list mirrors content-addressed-mirrors)
  426. ;; Honor the user's proxy and locale settings.
  427. #:leaked-env-vars '("http_proxy" "https_proxy"
  428. "LC_ALL" "LC_MESSAGES" "LANG"
  429. "COLUMNS")
  430. #:env-vars `(("url" . ,(object->string url))
  431. ("mirrors" . ,mirrors)
  432. ("content-addressed-mirrors"
  433. . ,content-addressed-mirrors)
  434. ,@(if executable?
  435. '(("executable" . "1"))
  436. '()))
  437. ;; Do not offload this derivation because we cannot be
  438. ;; sure that the remote daemon supports the 'download'
  439. ;; built-in. We may remove this limitation when support
  440. ;; for that built-in is widespread.
  441. #:local-build? #t)))
  442. (define* (url-fetch url hash-algo hash
  443. #:optional name
  444. #:key (system (%current-system))
  445. (guile (default-guile))
  446. executable?)
  447. "Return a fixed-output derivation that fetches URL (a string, or a list of
  448. strings denoting alternate URLs), which is expected to have hash HASH of type
  449. HASH-ALGO (a symbol). By default, the file name is the base name of URL;
  450. optionally, NAME can specify a different file name. When EXECUTABLE? is true,
  451. make the downloaded file executable.
  452. When one of the URL starts with mirror://, then its host part is
  453. interpreted as the name of a mirror scheme, taken from %MIRROR-FILE.
  454. Alternately, when URL starts with file://, return the corresponding file name
  455. in the store."
  456. (define file-name
  457. (match url
  458. ((head _ ...)
  459. (basename head))
  460. (_
  461. (basename url))))
  462. (let ((uri (and (string? url) (string->uri url))))
  463. (if (or (and (string? url) (not uri))
  464. (and uri (memq (uri-scheme uri) '(#f file))))
  465. (interned-file (if uri (uri-path uri) url)
  466. (or name file-name))
  467. (mlet %store-monad ((builtins (built-in-builders*)))
  468. ;; The "download" built-in builder was added in guix-daemon in
  469. ;; Nov. 2016 and made it in the 0.12.0 release of Dec. 2016. We now
  470. ;; require it.
  471. (unless (member "download" builtins)
  472. (error "'guix-daemon' is too old, please upgrade" builtins))
  473. (built-in-download (or name file-name) url
  474. #:guile guile
  475. #:system system
  476. #:hash-algo hash-algo
  477. #:hash hash
  478. #:executable? executable?
  479. #:mirrors %mirror-file
  480. #:content-addressed-mirrors
  481. %content-addressed-mirror-file)))))
  482. (define* (url-fetch/executable url hash-algo hash
  483. #:optional name
  484. #:key (system (%current-system))
  485. (guile (default-guile)))
  486. "Like 'url-fetch', but make the downloaded file executable."
  487. (url-fetch url hash-algo hash name
  488. #:system system
  489. #:guile guile
  490. #:executable? #t))
  491. (define* (url-fetch/tarbomb url hash-algo hash
  492. #:optional name
  493. #:key (system (%current-system))
  494. (guile (default-guile)))
  495. "Similar to 'url-fetch' but unpack the file from URL in a directory of its
  496. own. This helper makes it easier to deal with \"tar bombs\"."
  497. (define file-name
  498. (match url
  499. ((head _ ...)
  500. (basename head))
  501. (_
  502. (basename url))))
  503. (define gzip
  504. (module-ref (resolve-interface '(gnu packages compression)) 'gzip))
  505. (define tar
  506. (module-ref (resolve-interface '(gnu packages base)) 'tar))
  507. (mlet %store-monad ((drv (url-fetch url hash-algo hash
  508. (string-append "tarbomb-"
  509. (or name file-name))
  510. #:system system
  511. #:guile guile))
  512. (guile (package->derivation guile system)))
  513. ;; Take the tar bomb, and simply unpack it as a directory.
  514. ;; Use ungrafted tar/gzip so that the resulting tarball doesn't depend on
  515. ;; whether grafts are enabled.
  516. (gexp->derivation (or name file-name)
  517. (with-imported-modules '((guix build utils))
  518. #~(begin
  519. (use-modules (guix build utils))
  520. (mkdir #$output)
  521. (setenv "PATH" (string-append #$gzip "/bin"))
  522. (chdir #$output)
  523. (invoke (string-append #$tar "/bin/tar")
  524. "xf" #$drv)))
  525. #:system system
  526. #:guile-for-build guile
  527. #:graft? #f
  528. #:local-build? #t)))
  529. (define* (url-fetch/zipbomb url hash-algo hash
  530. #:optional name
  531. #:key (system (%current-system))
  532. (guile (default-guile)))
  533. "Similar to 'url-fetch' but unpack the zip file at URL in a directory of its
  534. own. This helper makes it easier to deal with \"zip bombs\"."
  535. (define file-name
  536. (match url
  537. ((head _ ...)
  538. (basename head))
  539. (_
  540. (basename url))))
  541. (define unzip
  542. (module-ref (resolve-interface '(gnu packages compression)) 'unzip))
  543. (mlet %store-monad ((drv (url-fetch url hash-algo hash
  544. (string-append "zipbomb-"
  545. (or name file-name))
  546. #:system system
  547. #:guile guile))
  548. (guile (package->derivation guile system)))
  549. ;; Take the zip bomb, and simply unpack it as a directory.
  550. ;; Use ungrafted unzip so that the resulting tarball doesn't depend on
  551. ;; whether grafts are enabled.
  552. (gexp->derivation (or name file-name)
  553. (with-imported-modules '((guix build utils))
  554. #~(begin
  555. (use-modules (guix build utils))
  556. (mkdir #$output)
  557. (chdir #$output)
  558. (invoke (string-append #$unzip "/bin/unzip")
  559. #$drv)))
  560. #:system system
  561. #:guile-for-build guile
  562. #:graft? #f
  563. #:local-build? #t)))
  564. (define* (download-to-store store url #:optional (name (basename url))
  565. #:key (log (current-error-port)) recursive?
  566. (verify-certificate? #t))
  567. "Download from URL to STORE, either under NAME or URL's basename if
  568. omitted. Write progress reports to LOG. RECURSIVE? has the same effect as
  569. the same-named parameter of 'add-to-store'. VERIFY-CERTIFICATE? determines
  570. whether or not to validate HTTPS server certificates."
  571. (define uri
  572. (string->uri url))
  573. (if (or (not uri) (memq (uri-scheme uri) '(file #f)))
  574. (add-to-store store name recursive? "sha256"
  575. (if uri (uri-path uri) url))
  576. (call-with-temporary-output-file
  577. (lambda (temp port)
  578. (let ((result
  579. (parameterize ((current-output-port log))
  580. (build:url-fetch url temp
  581. #:mirrors %mirrors
  582. #:verify-certificate?
  583. verify-certificate?))))
  584. (close port)
  585. (and result
  586. (add-to-store store name recursive? "sha256" temp)))))))
  587. ;;; download.scm ends here