download.scm 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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. (url-fetch* . 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. "https://sunsite.icm.edu.pl/packages/ImageMagick/releases"
  246. "http://mirror.checkdomain.de/imagemagick/releases"
  247. "ftp://ftp.u-aizu.ac.jp/pub/graphics/image/ImageMagick/imagemagick.org/releases"
  248. "ftp://ftp.nluug.nl/pub/ImageMagick/"
  249. "http://www.imagemagick.org/download/releases/"
  250. ;; Try this if all else fails (normally contains just the latest version).
  251. "http://www.imagemagick.org/download/")
  252. (debian
  253. "http://ftp.de.debian.org/debian/"
  254. "http://ftp.fr.debian.org/debian/"
  255. "http://ftp.debian.org/debian/"
  256. "http://archive.debian.org/debian/")
  257. (kde
  258. "http://download.kde.org"
  259. "http://download.kde.org/Attic" ; for when it gets archived.
  260. ;; Mirrors from http://files.kde.org/extra/mirrors.html
  261. ;; Europe
  262. "http://mirror.easyname.at/kde"
  263. "http://mirror.karneval.cz/pub/kde"
  264. "http://ftp.fi.muni.cz/pub/kde/"
  265. "http://mirror.oss.maxcdn.com/kde/"
  266. "http://ftp5.gwdg.de/pub/linux/kde/"
  267. "http://ftp-stud.fht-esslingen.de/Mirrors/ftp.kde.org/pub/kde/"
  268. "http://mirror.klaus-uwe.me/kde/ftp/"
  269. "http://kde.beta.mirror.ga/"
  270. "http://kde.alpha.mirror.ga/"
  271. "http://mirror.netcologne.de/kde"
  272. "http://vesta.informatik.rwth-aachen.de/ftp/pub/mirror/kde/"
  273. "http://ftp.rz.uni-wuerzburg.de/pub/unix/kde/"
  274. "http://mirrors.dotsrc.org/kde/"
  275. "http://ftp.funet.fi/pub/mirrors/ftp.kde.org/pub/kde/"
  276. "http://kde-mirror.freenux.org/"
  277. "http://mirrors.ircam.fr/pub/KDE/"
  278. "http://www-ftp.lip6.fr/pub/X11/kde/"
  279. "http://fr2.rpmfind.net/linux/KDE/"
  280. "http://kde.mirror.anlx.net/"
  281. "http://www.mirrorservice.org/sites/ftp.kde.org/pub/kde/"
  282. "http://ftp.heanet.ie/mirrors/ftp.kde.org/"
  283. "http://ftp.nluug.nl/pub/windowing/kde/"
  284. "http://ftp.surfnet.nl/windowing/kde/"
  285. "http://ftp.icm.edu.pl/pub/unix/kde/"
  286. "http://ftp.pbone.net/pub/kde/"
  287. "http://piotrkosoft.net/pub/mirrors/ftp.kde.org/"
  288. "http://mirrors.fe.up.pt/pub/kde/"
  289. "http://ftp.iasi.roedu.net/pub/mirrors/ftp.kde.org/"
  290. "http://ftp.acc.umu.se/mirror/kde.org/ftp/"
  291. "http://kde.ip-connect.vn.ua/"
  292. ;; North America
  293. "http://mirror.its.dal.ca/kde/"
  294. "http://mirror.csclub.uwaterloo.ca/kde/"
  295. "http://mirror.cc.columbia.edu/pub/software/kde/"
  296. "http://kde.mirrors.hoobly.com/"
  297. "http://ftp.ussg.iu.edu/kde/"
  298. "http://mirrors.mit.edu/kde/"
  299. "http://kde.mirrors.tds.net/pub/kde/"
  300. ;; Oceania
  301. "http://ftp.kddlabs.co.jp/pub/X11/kde/"
  302. "http://kde.mirror.uber.com.au/")
  303. (openbsd
  304. "https://ftp.openbsd.org/pub/OpenBSD/"
  305. ;; Anycast CDN redirecting to your friendly local mirror.
  306. "https://mirrors.evowise.com/pub/OpenBSD/"
  307. ;; Other HTTPS mirrors from https://www.openbsd.org/ftp.html
  308. "https://mirror.aarnet.edu.au/pub/OpenBSD/"
  309. "https://ftp2.eu.openbsd.org/pub/OpenBSD/"
  310. "https://openbsd.c3sl.ufpr.br/pub/OpenBSD/"
  311. "https://openbsd.ipacct.com/pub/OpenBSD/"
  312. "https://ftp.OpenBSD.org/pub/OpenBSD/"
  313. "https://openbsd.cs.toronto.edu/pub/OpenBSD/"
  314. "https://openbsd.delfic.org/pub/OpenBSD/"
  315. "https://openbsd.mirror.netelligent.ca/pub/OpenBSD/"
  316. "https://mirrors.ucr.ac.cr/pub/OpenBSD/"
  317. "https://mirrors.dotsrc.org/pub/OpenBSD/"
  318. "https://mirror.one.com/pub/OpenBSD/"
  319. "https://ftp.fr.openbsd.org/pub/OpenBSD/"
  320. "https://ftp2.fr.openbsd.org/pub/OpenBSD/"
  321. "https://mirrors.ircam.fr/pub/OpenBSD/"
  322. "https://ftp.spline.de/pub/OpenBSD/"
  323. "https://mirror.hs-esslingen.de/pub/OpenBSD/"
  324. "https://ftp.halifax.rwth-aachen.de/openbsd/"
  325. "https://ftp.hostserver.de/pub/OpenBSD/"
  326. "https://ftp.fau.de/pub/OpenBSD/"
  327. "https://ftp.cc.uoc.gr/pub/OpenBSD/"
  328. "https://openbsd.hk/pub/OpenBSD/"
  329. "https://ftp.heanet.ie/pub/OpenBSD/"
  330. "https://openbsd.mirror.garr.it/pub/OpenBSD/"
  331. "https://mirror.litnet.lt/pub/OpenBSD/"
  332. "https://mirror.meerval.net/pub/OpenBSD/"
  333. "https://ftp.nluug.nl/pub/OpenBSD/"
  334. "https://ftp.bit.nl/pub/OpenBSD/"
  335. "https://mirrors.dalenys.com/pub/OpenBSD/"
  336. "https://ftp.icm.edu.pl/pub/OpenBSD/"
  337. "https://ftp.rnl.tecnico.ulisboa.pt/pub/OpenBSD/"
  338. "https://mirrors.pidginhost.com/pub/OpenBSD/"
  339. "https://mirror.yandex.ru/pub/OpenBSD/"
  340. "https://ftp.eu.openbsd.org/pub/OpenBSD/"
  341. "https://ftp.yzu.edu.tw/pub/OpenBSD/"
  342. "https://www.mirrorservice.org/pub/OpenBSD/"
  343. "https://anorien.csc.warwick.ac.uk/pub/OpenBSD/"
  344. "https://mirror.bytemark.co.uk/pub/OpenBSD/"
  345. "https://mirrors.sonic.net/pub/OpenBSD/"
  346. "https://ftp3.usa.openbsd.org/pub/OpenBSD/"
  347. "https://mirrors.syringanetworks.net/pub/OpenBSD/"
  348. "https://openbsd.mirror.constant.com/pub/OpenBSD/"
  349. "https://ftp4.usa.openbsd.org/pub/OpenBSD/"
  350. "https://ftp5.usa.openbsd.org/pub/OpenBSD/"
  351. "https://mirror.esc7.net/pub/OpenBSD/")
  352. (mate
  353. "https://pub.mate-desktop.org/releases/"
  354. "http://pub.mate-desktop.org/releases/"))))
  355. (define %mirror-file
  356. ;; Copy of the list of mirrors to a file. This allows us to keep a single
  357. ;; copy in the store, and computing it here avoids repeated calls to
  358. ;; 'object->string'.
  359. (plain-file "mirrors" (object->string %mirrors)))
  360. (define %content-addressed-mirrors
  361. ;; List of content-addressed mirrors. Each mirror is represented as a
  362. ;; procedure that takes a file name, an algorithm (symbol) and a hash
  363. ;; (bytevector), and returns a URL or #f.
  364. '(begin
  365. (use-modules (guix base32))
  366. (define (guix-publish host)
  367. (lambda (file algo hash)
  368. ;; Files served by 'guix publish' are accessible under a single
  369. ;; hash algorithm.
  370. (string-append "https://" host "/file/"
  371. file "/" (symbol->string algo) "/"
  372. (bytevector->nix-base32-string hash))))
  373. ;; XXX: (guix base16) appeared in March 2017 (and thus 0.13.0) so old
  374. ;; installations of the daemon might lack it. Thus, load it lazily to
  375. ;; avoid gratuitous errors. See <https://bugs.gnu.org/33542>.
  376. (module-autoload! (current-module)
  377. '(guix base16) '(bytevector->base16-string))
  378. (list (guix-publish "ci.guix.gnu.org")
  379. (lambda (file algo hash)
  380. ;; 'tarballs.nixos.org' supports several algorithms.
  381. (string-append "https://tarballs.nixos.org/"
  382. (symbol->string algo) "/"
  383. (bytevector->nix-base32-string hash)))
  384. (lambda (file algo hash)
  385. ;; Software Heritage usually archives VCS history rather than
  386. ;; tarballs, but tarballs are sometimes available (and can be
  387. ;; explicitly stored there.) For example, see
  388. ;; <https://archive.softwareheritage.org/api/1/content/sha256:92d0fa1c311cacefa89853bdb53c62f4110cdfda3820346b59cbd098f40f955e/>.
  389. (string-append "https://archive.softwareheritage.org/api/1/content/"
  390. (symbol->string algo) ":"
  391. (bytevector->base16-string hash) "/raw/")))))
  392. (define %content-addressed-mirror-file
  393. ;; Content-addressed mirrors stored in a file.
  394. (plain-file "content-addressed-mirrors"
  395. (object->string %content-addressed-mirrors)))
  396. (define %disarchive-mirrors
  397. '("https://disarchive.ngyro.com/"))
  398. (define %disarchive-mirror-file
  399. (plain-file "disarchive-mirrors" (object->string %disarchive-mirrors)))
  400. (define built-in-builders*
  401. (store-lift built-in-builders))
  402. (define* (built-in-download file-name url
  403. #:key system hash-algo hash
  404. mirrors content-addressed-mirrors
  405. disarchive-mirrors
  406. executable?
  407. (guile 'unused))
  408. "Download FILE-NAME from URL using the built-in 'download' builder. When
  409. EXECUTABLE? is true, make the downloaded file executable.
  410. This is an \"out-of-band\" download in that the returned derivation does not
  411. explicitly depend on Guile, GnuTLS, etc. Instead, the daemon performs the
  412. download by itself using its own dependencies."
  413. (mlet %store-monad ((mirrors (lower-object mirrors))
  414. (content-addressed-mirrors
  415. (lower-object content-addressed-mirrors))
  416. (disarchive-mirrors (lower-object disarchive-mirrors)))
  417. (raw-derivation file-name "builtin:download" '()
  418. #:system system
  419. #:hash-algo hash-algo
  420. #:hash hash
  421. #:recursive? executable?
  422. #:sources (list mirrors
  423. content-addressed-mirrors
  424. disarchive-mirrors)
  425. ;; Honor the user's proxy and locale settings.
  426. #:leaked-env-vars '("http_proxy" "https_proxy"
  427. "LC_ALL" "LC_MESSAGES" "LANG"
  428. "COLUMNS")
  429. #:env-vars `(("url" . ,(object->string url))
  430. ("mirrors" . ,mirrors)
  431. ("content-addressed-mirrors"
  432. . ,content-addressed-mirrors)
  433. ("disarchive-mirrors" . ,disarchive-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 data from URL (a string, or a
  448. list of strings denoting alternate URLs), which is expected to have hash HASH
  449. of type HASH-ALGO (a symbol). By default, the file name is the base name of
  450. URL; optionally, NAME can specify a different file name. When EXECUTABLE? is
  451. true, 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. Alternatively, when URL starts with file://, return the corresponding file
  455. name 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. #:disarchive-mirrors
  483. %disarchive-mirror-file)))))
  484. (define* (url-fetch/executable url hash-algo hash
  485. #:optional name
  486. #:key (system (%current-system))
  487. (guile (default-guile)))
  488. "Like 'url-fetch', but make the downloaded file executable."
  489. (url-fetch* url hash-algo hash name
  490. #:system system
  491. #:guile guile
  492. #:executable? #t))
  493. (define* (url-fetch/tarbomb url hash-algo hash
  494. #:optional name
  495. #:key (system (%current-system))
  496. (guile (default-guile)))
  497. "Similar to 'url-fetch' but unpack the file from URL in a directory of its
  498. own. This helper makes it easier to deal with \"tar bombs\"."
  499. (define file-name
  500. (match url
  501. ((head _ ...)
  502. (basename head))
  503. (_
  504. (basename url))))
  505. (define gzip
  506. (module-ref (resolve-interface '(gnu packages compression)) 'gzip))
  507. (define tar
  508. (module-ref (resolve-interface '(gnu packages base)) 'tar))
  509. (mlet %store-monad ((drv (url-fetch* url hash-algo hash
  510. (string-append "tarbomb-"
  511. (or name file-name))
  512. #:system system
  513. #:guile guile))
  514. (guile (package->derivation guile system)))
  515. ;; Take the tar bomb, and simply unpack it as a directory.
  516. ;; Use ungrafted tar/gzip so that the resulting tarball doesn't depend on
  517. ;; whether grafts are enabled.
  518. (gexp->derivation (or name file-name)
  519. (with-imported-modules '((guix build utils))
  520. #~(begin
  521. (use-modules (guix build utils))
  522. (mkdir #$output)
  523. (setenv "PATH" (string-append #+gzip "/bin"))
  524. (chdir #$output)
  525. (invoke (string-append #+tar "/bin/tar")
  526. "xf" #$drv)))
  527. #:system system
  528. #:guile-for-build guile
  529. #:graft? #f
  530. #:local-build? #t)))
  531. (define* (url-fetch/zipbomb url hash-algo hash
  532. #:optional name
  533. #:key (system (%current-system))
  534. (guile (default-guile)))
  535. "Similar to 'url-fetch' but unpack the zip file at URL in a directory of its
  536. own. This helper makes it easier to deal with \"zip bombs\"."
  537. (define file-name
  538. (match url
  539. ((head _ ...)
  540. (basename head))
  541. (_
  542. (basename url))))
  543. (define unzip
  544. (module-ref (resolve-interface '(gnu packages compression)) 'unzip))
  545. (mlet %store-monad ((drv (url-fetch* url hash-algo hash
  546. (string-append "zipbomb-"
  547. (or name file-name))
  548. #:system system
  549. #:guile guile))
  550. (guile (package->derivation guile system)))
  551. ;; Take the zip bomb, and simply unpack it as a directory.
  552. ;; Use ungrafted unzip so that the resulting tarball doesn't depend on
  553. ;; whether grafts are enabled.
  554. (gexp->derivation (or name file-name)
  555. (with-imported-modules '((guix build utils))
  556. #~(begin
  557. (use-modules (guix build utils))
  558. (mkdir #$output)
  559. (chdir #$output)
  560. (invoke (string-append #+unzip "/bin/unzip")
  561. #$drv)))
  562. #:system system
  563. #:guile-for-build guile
  564. #:graft? #f
  565. #:local-build? #t)))
  566. (define* (download-to-store store url #:optional (name (basename url))
  567. #:key (log (current-error-port)) recursive?
  568. (verify-certificate? #t))
  569. "Download from URL to STORE, either under NAME or URL's basename if
  570. omitted. Write progress reports to LOG. RECURSIVE? has the same effect as
  571. the same-named parameter of 'add-to-store'. VERIFY-CERTIFICATE? determines
  572. whether or not to validate HTTPS server certificates."
  573. (define uri
  574. (string->uri url))
  575. (if (or (not uri) (memq (uri-scheme uri) '(file #f)))
  576. (add-to-store store name recursive? "sha256"
  577. (if uri (uri-path uri) url))
  578. (call-with-temporary-output-file
  579. (lambda (temp port)
  580. (let ((result
  581. (parameterize ((current-output-port log))
  582. (url-fetch url temp
  583. #:mirrors %mirrors
  584. #:verify-certificate? verify-certificate?))))
  585. (close port)
  586. (and result
  587. (add-to-store store name recursive? "sha256" temp)))))))
  588. ;;; download.scm ends here