download.scm 27 KB

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