download.scm 27 KB

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