bootstrap.scm 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  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 © 2014, 2015, 2018, 2019 Mark H Weaver <mhw@netris.org>
  4. ;;; Copyright © 2017, 2020 Efraim Flashner <efraim@flashner.co.il>
  5. ;;; Copyright © 2018, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  6. ;;; Copyright © 2019 Carl Dong <contact@carldong.me>
  7. ;;; Copyright © 2019 Léo Le Bouter <lle-bout@zaclys.net>
  8. ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
  9. ;;; Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
  10. ;;;
  11. ;;; This file is part of GNU Guix.
  12. ;;;
  13. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  14. ;;; under the terms of the GNU General Public License as published by
  15. ;;; the Free Software Foundation; either version 3 of the License, or (at
  16. ;;; your option) any later version.
  17. ;;;
  18. ;;; GNU Guix is distributed in the hope that it will be useful, but
  19. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. ;;; GNU General Public License for more details.
  22. ;;;
  23. ;;; You should have received a copy of the GNU General Public License
  24. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  25. (define-module (gnu packages bootstrap)
  26. #:use-module (guix licenses)
  27. #:use-module (gnu packages)
  28. #:use-module (guix packages)
  29. #:use-module (guix download)
  30. #:use-module (guix build-system)
  31. #:use-module (guix build-system gnu)
  32. #:use-module (guix build-system trivial)
  33. #:use-module ((guix store)
  34. #:select (%store-monad interned-file text-file store-lift))
  35. #:use-module ((guix derivations)
  36. #:select (raw-derivation derivation-input derivation->output-path))
  37. #:use-module (guix utils)
  38. #:use-module ((guix build utils) #:select (elf-file?))
  39. #:use-module ((guix gexp) #:select (lower-object))
  40. #:use-module (guix monads)
  41. #:use-module (guix memoization)
  42. #:use-module (guix i18n)
  43. #:use-module (srfi srfi-1)
  44. #:use-module (srfi srfi-26)
  45. #:use-module (srfi srfi-34)
  46. #:use-module (srfi srfi-35)
  47. #:use-module (ice-9 match)
  48. #:export (bootstrap-origin
  49. package-with-bootstrap-guile
  50. glibc-dynamic-linker
  51. bootstrap-executable
  52. bootstrap-guile-origin
  53. %bootstrap-guile
  54. %bootstrap-coreutils&co
  55. %bootstrap-linux-libre-headers
  56. %bootstrap-binutils
  57. %bootstrap-gcc
  58. %bootstrap-glibc
  59. %bootstrap-inputs
  60. %bootstrap-mescc-tools
  61. %bootstrap-mes
  62. %bootstrap-inputs-for-tests))
  63. ;;; Commentary:
  64. ;;;
  65. ;;; Pre-built packages that are used to bootstrap the
  66. ;;; distribution--i.e., to build all the core packages from scratch.
  67. ;;;
  68. ;;; Code:
  69. ;;;
  70. ;;; The bootstrap executables: 'bash', 'mkdir', 'tar', 'xz'. They allow us to
  71. ;;; extract the very first tarball.
  72. ;;;
  73. (define %bootstrap-executables
  74. ;; List of bootstrap executables and their recursive hashes (as per 'guix
  75. ;; hash -r'), taking their executable bit into account.
  76. `(("aarch64-linux"
  77. ("bash"
  78. ,(base32 "13aqhqb8nydlwq1ah9974q0iadx1pb95v13wzzyf7vgv6nasrwzr"))
  79. ("mkdir"
  80. ,(base32 "1pxhdp7ldwavmm71xbh9wc197cb2nr66acjn26yjx3732cixh9ws"))
  81. ("tar"
  82. ,(base32 "1j51gv08sfg277yxj73xd564wjq3f8xwd6s9rbcg8v9gms47m4cx"))
  83. ("xz"
  84. ,(base32 "1d779rwsrasphg5g3r37qppcqy3p7ay1jb1y83w7x4i3qsc7zjy2")))
  85. ("powerpc-linux"
  86. ("bash"
  87. ,(base32 "0hwlw5lcyjzadprf5fm0cv4zb6jw667g9amnmhq0lbixasy7j72j"))
  88. ("mkdir"
  89. ,(base32 "12lfwh5p8pp06250wgi9mdvjv1jdfpd5xpmvfc0616aj0xqh09hp"))
  90. ("tar"
  91. ,(base32 "00sbmwl8qh6alxv9mw4hvj1j4yipwmw5mrw6qad8bi2pr7ya5386"))
  92. ("xz"
  93. ,(base32 "0hi47y6zh5zz137i59l5ibw92x6g54zn7ris1b1ym9rvavsasg7b")))
  94. ("armhf-linux"
  95. ("bash"
  96. ,(base32 "0s6f1s26g4dsrrkl39zblvwpxmbzi6n9mgqf6vxsqz42gik6bgyn"))
  97. ("mkdir"
  98. ,(base32 "1r5rcp35niyxfkrdf00y2ba8ifrq9bi76cr63lwjf2l655j1i5p7"))
  99. ("tar"
  100. ,(base32 "0dksx5im3fv8ximz7368bsax9f26nn47ds74298flm5lnvpv9xly"))
  101. ("xz"
  102. ,(base32 "1cqqavghjfr0iwxqf61lrssv27wfigysgq2rs4rm1gkmn04yn1k3")))
  103. ("i686-linux"
  104. ("bash"
  105. ,(base32 "0rjaxyzjdllfkf1abczvgaf3cdcc7mmahyvdbkjmjzhgz92pv23g"))
  106. ("mkdir"
  107. ,(base32 "133ybmfpkmsnysrzbngwvbysqnsmfi8is8zifs7i7n6n600h4s1w"))
  108. ("tar"
  109. ,(base32 "07830bx29ad5i0l1ykj0g0b1jayjdblf01sr3ww9wbnwdbzinqms"))
  110. ("xz"
  111. ,(base32 "0i9kxdi17bm5gxfi2xzm0y73p3ii0cqxli1sbljm6rh2fjgyn90k")))
  112. ("i586-gnu"
  113. ("bash"
  114. ,(base32 "1as8649aqaibahhhrvkj10ci8shpi4hq5n7gnik8rhhy0dc1jarg"))
  115. ("mkdir"
  116. ,(base32 "1snqgpfrl00hfn82lm29jqylzjsfb9jd6ha74dp12phwb8fpbmb9"))
  117. ("tar"
  118. ,(base32 "0nq2c1zb3wv5bf7kd83sziaashydazrn7xgq6kijlk0zj2syzc2m"))
  119. ("xz"
  120. ,(base32 "033rhpk6zrpxpd6ffjyg5y2zwq9x9cnq0zljb7k8jlncbalsayq5")))
  121. ("mips64el-linux"
  122. ("bash"
  123. ,(base32 "1aw046dhda240k9pb9iaj5aqkm23gkvxa9j82n4k7fk87nbrixw6"))
  124. ("mkdir"
  125. ,(base32 "0c9j6qgyw84zxbry3ypifzll13gy8ax71w40kdk1h11jbgla3f5k"))
  126. ("tar"
  127. ,(base32 "06gmqdjq3rl8lr47b9fyx4ifnm5x56ymc8lyryp1ax1j2s4y5jb4"))
  128. ("xz"
  129. ,(base32 "09j1d69qr0hhhx4k4ih8wp00dfc9y4rp01hfg3vc15yxd0jxabh5")))
  130. ("powerpc64le-linux"
  131. ("bash"
  132. ,(base32 "1kiw7n6mkdy2x9in97646nb7aiayxr090ws1hbrlazah3fjqi6nj"))
  133. ("mkdir"
  134. ,(base32 "04dpvi231zcl40ig048vqqnyvmnkw1byrm1q1qqvs1f0g16yhrrk"))
  135. ("tar"
  136. ,(base32 "150c8948cz8r208g6qgn2dn4f4zs5kpgbpbg6bwag6yw42rapw2l"))
  137. ("xz"
  138. ,(base32 "0v5738idy9pqzcbrjdpxi5c6qs5m78zrpsydmrpx5cfcfzbkxzjh")))))
  139. (define %bootstrap-executable-base-urls
  140. ;; This is where the bootstrap executables come from.
  141. '("https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/bootstrap/"
  142. "https://alpha.gnu.org/gnu/guix/bootstrap/"
  143. "http://flashner.co.il/guix/bootstrap/"
  144. "http://lilypond.org/janneke/guix/"))
  145. (define (bootstrap-executable-file-name system program)
  146. "Return the FILE-NAME part of url where PROGRAM can be found for SYSTEM."
  147. (match system
  148. ("powerpc64le-linux" (string-append system "/20210106/" program))
  149. ("i586-gnu" (string-append system "/20200326/" program))
  150. ("powerpc-linux" (string-append system "/20200923/bin/" program))
  151. (_ (string-append system "/" program
  152. "?id=44f07d1dc6806e97c4e9ee3e6be883cc59dc666e"))))
  153. (define bootstrap-executable
  154. (mlambda (program system)
  155. "Return an origin for PROGRAM, a statically-linked bootstrap executable
  156. built for SYSTEM."
  157. (let ((system (if (string=? system "x86_64-linux")
  158. "i686-linux"
  159. system)))
  160. (match (assoc-ref (assoc-ref %bootstrap-executables system)
  161. program)
  162. (#f
  163. (raise (condition
  164. (&message
  165. (message
  166. (format #f (G_ "could not find bootstrap binary '~a' \
  167. for system '~a'")
  168. program system))))))
  169. ((bv)
  170. (origin
  171. (method url-fetch/executable)
  172. (uri (map (cute string-append <>
  173. (bootstrap-executable-file-name system program))
  174. %bootstrap-executable-base-urls))
  175. (file-name program)
  176. (hash (content-hash bv sha256))))))))
  177. ;;;
  178. ;;; Helper procedures.
  179. ;;;
  180. (define bootstrap-origin
  181. (mlambdaq (source)
  182. "Return a variant of SOURCE, an <origin> instance, whose method uses
  183. %BOOTSTRAP-GUILE to do its job."
  184. (define (boot fetch)
  185. (lambda* (url hash-algo hash
  186. #:optional name #:key system)
  187. (fetch url hash-algo hash name
  188. #:guile %bootstrap-guile
  189. #:system system)))
  190. (define %bootstrap-patch-inputs
  191. ;; Packages used when an <origin> has a non-empty 'patches' field.
  192. `(("tar" ,%bootstrap-coreutils&co)
  193. ("xz" ,%bootstrap-coreutils&co)
  194. ("bzip2" ,%bootstrap-coreutils&co)
  195. ("gzip" ,%bootstrap-coreutils&co)
  196. ("patch" ,%bootstrap-coreutils&co)))
  197. (let ((orig-method (origin-method source)))
  198. (if (or (not (null? (origin-patches source)))
  199. (origin-snippet source))
  200. (origin (inherit source)
  201. (method (if (eq? orig-method url-fetch)
  202. (boot url-fetch)
  203. orig-method))
  204. (patch-guile %bootstrap-guile)
  205. (patch-inputs %bootstrap-patch-inputs)
  206. ;; Patches can be origins as well, so process them.
  207. (patches (map (match-lambda
  208. ((? origin? patch)
  209. (bootstrap-origin patch))
  210. (patch patch))
  211. (origin-patches source))))
  212. source))))
  213. (define* (package-from-tarball name source program-to-test description
  214. #:key snippet)
  215. "Return a package that correspond to the extraction of SOURCE.
  216. PROGRAM-TO-TEST is #f or a string: the program to run after extraction of
  217. SOURCE to check whether everything is alright. If SNIPPET is provided, it is
  218. evaluated after extracting SOURCE. SNIPPET should return true if successful,
  219. or false to signal an error."
  220. (package
  221. (name name)
  222. (version "0")
  223. (build-system trivial-build-system)
  224. (arguments
  225. `(#:guile ,%bootstrap-guile
  226. #:modules ((guix build utils))
  227. #:builder
  228. (begin
  229. (use-modules (guix build utils))
  230. (let ((out (assoc-ref %outputs "out"))
  231. (tar (assoc-ref %build-inputs "tar"))
  232. (xz (assoc-ref %build-inputs "xz"))
  233. (tarball (assoc-ref %build-inputs "tarball")))
  234. (mkdir out)
  235. (copy-file tarball "binaries.tar.xz")
  236. (invoke xz "-d" "binaries.tar.xz")
  237. (let ((builddir (getcwd)))
  238. (with-directory-excursion out
  239. (invoke tar "xvf"
  240. (string-append builddir "/binaries.tar"))
  241. ,@(if snippet (list snippet) '())
  242. (or (not ,program-to-test)
  243. (invoke (string-append "bin/" ,program-to-test)
  244. "--version"))))))))
  245. (inputs
  246. `(("tar" ,(bootstrap-executable "tar" (%current-system)))
  247. ("xz" ,(bootstrap-executable "xz" (%current-system)))
  248. ("tarball" ,(bootstrap-origin (source (%current-system))))))
  249. (source #f)
  250. (synopsis description)
  251. (description description)
  252. (home-page #f)
  253. (license gpl3+)))
  254. (define package-with-bootstrap-guile
  255. (mlambdaq (p)
  256. "Return a variant of P such that all its origins are fetched with
  257. %BOOTSTRAP-GUILE."
  258. (define rewritten-input
  259. (match-lambda
  260. ((name (? origin? o))
  261. `(,name ,(bootstrap-origin o)))
  262. ((name (? package? p) sub-drvs ...)
  263. `(,name ,(package-with-bootstrap-guile p) ,@sub-drvs))
  264. (x x)))
  265. (package (inherit p)
  266. (source (match (package-source p)
  267. ((? origin? o) (bootstrap-origin o))
  268. (s s)))
  269. (inputs (map rewritten-input
  270. (package-inputs p)))
  271. (native-inputs (map rewritten-input
  272. (package-native-inputs p)))
  273. (propagated-inputs (map rewritten-input
  274. (package-propagated-inputs p)))
  275. (replacement (and=> (package-replacement p)
  276. package-with-bootstrap-guile)))))
  277. (define* (glibc-dynamic-linker
  278. #:optional (system (or (and=> (%current-target-system)
  279. gnu-triplet->nix-system)
  280. (%current-system))))
  281. "Return the name of Glibc's dynamic linker for SYSTEM."
  282. ;; See the 'SYSDEP_KNOWN_INTERPRETER_NAMES' cpp macro in libc.
  283. (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2")
  284. ((string=? system "i686-linux") "/lib/ld-linux.so.2")
  285. ((string=? system "armhf-linux") "/lib/ld-linux-armhf.so.3")
  286. ((string=? system "mips64el-linux") "/lib/ld.so.1")
  287. ((string=? system "i586-gnu") "/lib/ld.so.1")
  288. ((string=? system "i686-gnu") "/lib/ld.so.1")
  289. ((string=? system "aarch64-linux") "/lib/ld-linux-aarch64.so.1")
  290. ((string=? system "powerpc-linux") "/lib/ld.so.1")
  291. ((string=? system "powerpc64-linux") "/lib/ld64.so.1")
  292. ((string=? system "powerpc64le-linux") "/lib/ld64.so.2")
  293. ((string=? system "alpha-linux") "/lib/ld-linux.so.2")
  294. ((string=? system "s390x-linux") "/lib/ld64.so.1")
  295. ((string=? system "riscv64-linux") "/lib/ld-linux-riscv64-lp64d.so.1")
  296. ;; XXX: This one is used bare-bones, without a libc, so add a case
  297. ;; here just so we can keep going.
  298. ((string=? system "arm-elf") "no-ld.so")
  299. ((string=? system "arm-eabi") "no-ld.so")
  300. ((string=? system "xtensa-elf") "no-ld.so")
  301. ((string=? system "avr") "no-ld.so")
  302. ((string=? system "propeller-elf") "no-ld.so")
  303. ((string=? system "i686-mingw") "no-ld.so")
  304. ((string=? system "x86_64-mingw") "no-ld.so")
  305. ((string=? system "vc4-elf") "no-ld.so")
  306. (else (error "dynamic linker name not known for this system"
  307. system))))
  308. ;;;
  309. ;;; Bootstrap packages.
  310. ;;;
  311. (define %bootstrap-base-urls
  312. ;; This is where the initial binaries come from.
  313. '("https://ftp.gnu.org/gnu/guix/bootstrap"
  314. "https://alpha.gnu.org/gnu/guix/bootstrap"
  315. "http://ftp.gnu.org/gnu/guix/bootstrap"
  316. "http://alpha.gnu.org/gnu/guix/bootstrap"
  317. "ftp://alpha.gnu.org/gnu/guix/bootstrap"
  318. "http://www.fdn.fr/~lcourtes/software/guix/packages"
  319. "http://flashner.co.il/guix/bootstrap"
  320. "http://lilypond.org/janneke/guix/"))
  321. (define (bootstrap-guile-url-path system)
  322. "Return the URI for FILE."
  323. (string-append "/" system
  324. (match system
  325. ("aarch64-linux"
  326. "/20170217/guile-2.0.14.tar.xz")
  327. ("powerpc-linux"
  328. "/20200923/guile-2.0.14.tar.xz")
  329. ("armhf-linux"
  330. "/20150101/guile-2.0.11.tar.xz")
  331. ("i586-gnu"
  332. "/20200326/guile-static-stripped-2.0.14-i586-pc-gnu.tar.xz")
  333. ("powerpc64le-linux"
  334. "/20210106/guile-static-stripped-2.0.14-powerpc64le-linux-gnu.tar.xz")
  335. (_
  336. "/20131110/guile-2.0.9.tar.xz"))))
  337. (define (bootstrap-guile-hash system)
  338. "Return the SHA256 hash of the Guile bootstrap tarball for SYSTEM."
  339. (match system
  340. ("x86_64-linux"
  341. (base32 "1w2p5zyrglzzniqgvyn1b55vprfzhgk8vzbzkkbdgl5248si0yq3"))
  342. ("i686-linux"
  343. (base32 "0im800m30abgh7msh331pcbjvb4n02smz5cfzf1srv0kpx3csmxp"))
  344. ("mips64el-linux"
  345. (base32 "0fzp93lvi0hn54acc0fpvhc7bvl0yc853k62l958cihk03q80ilr"))
  346. ("armhf-linux"
  347. (base32 "1mi3brl7l58aww34rawhvja84xc7l1b4hmwdmc36fp9q9mfx0lg5"))
  348. ("powerpc64le-linux"
  349. (base32 "1rnyfz5q38jyvxddj617443bnnzql4vw0mxzqpj8wz48wx4bhbq0"))
  350. ("aarch64-linux"
  351. (base32 "1giy2aprjmn5fp9c4s9r125fljw4wv6ixy5739i5bffw4jgr0f9r"))
  352. ("i586-gnu"
  353. (base32 "0wgqpsmvg25rnqn49ap7kwd2qxccd8dr4lllzp7i3rjvgav27vac"))
  354. ("powerpc-linux"
  355. (base32 "1by2p7s27fbyjzfkcw8h65h4kkqh7d23kv4sgg5jppjn2qx7swq4"))))
  356. (define (bootstrap-guile-origin system)
  357. "Return an <origin> object for the Guile tarball of SYSTEM."
  358. (origin
  359. (method url-fetch)
  360. (uri (map (cute string-append <> (bootstrap-guile-url-path system))
  361. %bootstrap-base-urls))
  362. (sha256 (bootstrap-guile-hash system))))
  363. (define (download-bootstrap-guile system)
  364. "Return a derivation that downloads the bootstrap Guile tarball for SYSTEM."
  365. (let* ((path (bootstrap-guile-url-path system))
  366. (base (basename path))
  367. (urls (map (cut string-append <> path) %bootstrap-base-urls)))
  368. (url-fetch urls 'sha256 (bootstrap-guile-hash system)
  369. #:system system)))
  370. (define* (raw-build name inputs
  371. #:key outputs system search-paths
  372. #:allow-other-keys)
  373. (define (->store file)
  374. (lower-object (bootstrap-executable file system)
  375. system))
  376. (define (make-guile-wrapper bash guile-real)
  377. ;; The following code, run by the bootstrap guile after it is unpacked,
  378. ;; creates a wrapper for itself to set its load path. This replaces the
  379. ;; previous non-portable method based on reading the /proc/self/exe
  380. ;; symlink.
  381. '(begin
  382. (use-modules (ice-9 match))
  383. (match (command-line)
  384. ((_ out bash)
  385. (let ((bin-dir (string-append out "/bin"))
  386. (guile (string-append out "/bin/guile"))
  387. (guile-real (string-append out "/bin/.guile-real"))
  388. ;; We must avoid using a bare dollar sign in this code,
  389. ;; because it would be interpreted by the shell.
  390. (dollar (string (integer->char 36))))
  391. (chmod bin-dir #o755)
  392. (rename-file guile guile-real)
  393. (call-with-output-file guile
  394. (lambda (p)
  395. (format p "\
  396. #!~a
  397. export GUILE_SYSTEM_PATH=~a/share/guile/2.0
  398. export GUILE_SYSTEM_COMPILED_PATH=~a/lib/guile/2.0/ccache
  399. exec -a \"~a0\" ~a \"~a@\"\n"
  400. bash out out dollar guile-real dollar)))
  401. (chmod guile #o555)
  402. (chmod bin-dir #o555))))))
  403. (mlet* %store-monad ((tar (->store "tar"))
  404. (xz (->store "xz"))
  405. (mkdir (->store "mkdir"))
  406. (bash (->store "bash"))
  407. (guile (download-bootstrap-guile system))
  408. (wrapper -> (make-guile-wrapper bash guile))
  409. (builder
  410. (text-file "build-bootstrap-guile.sh"
  411. (format #f "
  412. echo \"unpacking bootstrap Guile to '$out'...\"
  413. ~a $out
  414. cd $out
  415. ~a -dc < $GUILE_TARBALL | ~a xv
  416. # Use the bootstrap guile to create its own wrapper to set the load path.
  417. GUILE_SYSTEM_PATH=$out/share/guile/2.0 \
  418. GUILE_SYSTEM_COMPILED_PATH=$out/lib/guile/2.0/ccache \
  419. $out/bin/guile -c ~s $out ~a
  420. # Sanity check.
  421. $out/bin/guile --version~%"
  422. (derivation->output-path mkdir)
  423. (derivation->output-path xz)
  424. (derivation->output-path tar)
  425. (object->string wrapper)
  426. (derivation->output-path bash)))))
  427. (raw-derivation name
  428. (derivation->output-path bash) `(,builder)
  429. #:system system
  430. #:inputs (map derivation-input
  431. (list bash mkdir tar xz guile))
  432. #:sources (list builder)
  433. #:env-vars `(("GUILE_TARBALL"
  434. . ,(derivation->output-path guile))))))
  435. (define* (make-raw-bag name
  436. #:key source inputs native-inputs outputs
  437. system target)
  438. (bag
  439. (name name)
  440. (system system)
  441. (build-inputs inputs)
  442. (build raw-build)))
  443. (define %bootstrap-guile
  444. ;; The Guile used to run the build scripts of the initial derivations.
  445. ;; It is just unpacked from a tarball containing a pre-built binary.
  446. ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
  447. ;;
  448. ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
  449. ;; support (for /etc/services).
  450. (let ((raw (build-system
  451. (name 'raw)
  452. (description "Raw build system with direct store access")
  453. (lower make-raw-bag))))
  454. (package
  455. (name "guile-bootstrap")
  456. (version "2.0")
  457. (source #f)
  458. (build-system raw)
  459. (synopsis "Bootstrap Guile")
  460. (description "Pre-built Guile for bootstrapping purposes.")
  461. (home-page #f)
  462. (license lgpl3+))))
  463. (define %bootstrap-coreutils&co
  464. (package-from-tarball "bootstrap-binaries"
  465. (lambda (system)
  466. (origin
  467. (method url-fetch)
  468. (uri (map (cut string-append <> "/" system
  469. (match system
  470. ("armhf-linux"
  471. "/20150101/static-binaries.tar.xz")
  472. ("aarch64-linux"
  473. "/20170217/static-binaries.tar.xz")
  474. ("powerpc64le-linux"
  475. "/20210106/static-binaries-0-powerpc64le-linux-gnu.tar.xz")
  476. ("i586-gnu"
  477. "/20200326/static-binaries-0-i586-pc-gnu.tar.xz")
  478. ("powerpc-linux"
  479. "/20200923/static-binaries.tar.xz")
  480. (_
  481. "/20131110/static-binaries.tar.xz")))
  482. %bootstrap-base-urls))
  483. (sha256
  484. (match system
  485. ("x86_64-linux"
  486. (base32
  487. "0c533p9dhczzcsa1117gmfq3pc8w362g4mx84ik36srpr7cx2bg4"))
  488. ("i686-linux"
  489. (base32
  490. "0s5b3jb315n13m1k8095l0a5hfrsz8g0fv1b6riyc5hnxqyphlak"))
  491. ("armhf-linux"
  492. (base32
  493. "0gf0fn2kbpxkjixkmx5f4z6hv6qpmgixl69zgg74dbsfdfj8jdv5"))
  494. ("aarch64-linux"
  495. (base32
  496. "18dfiq6c6xhsdpbidigw6480wh0vdgsxqq3xindq4lpdgqlccpfh"))
  497. ("powerpc64le-linux"
  498. (base32
  499. "0afs2j9z2d1hjq42myz4iwjh0aqgzf59inifw87x6b6p1z9wv92v"))
  500. ("i586-gnu"
  501. (base32
  502. "17kllqnf3fg79gzy9ansgi801c46yh9c23h4d923plvb0nfm1cfn"))
  503. ("powerpc-linux"
  504. (base32
  505. "0kspxy0yczan2vlih6aa9hailr2inz000fqa0gn5x9d1fxxa5y8m"))
  506. ("mips64el-linux"
  507. (base32
  508. "072y4wyfsj1bs80r6vbybbafy8ya4vfy7qj25dklwk97m6g71753"))))))
  509. "fgrep" ; the program to test
  510. "Bootstrap binaries of Coreutils, Awk, etc."
  511. #:snippet
  512. '(let ((path (list (string-append (getcwd) "/bin"))))
  513. (chmod "bin" #o755)
  514. (patch-shebang "bin/egrep" path)
  515. (patch-shebang "bin/fgrep" path)
  516. ;; Starting with grep@2.25 'egrep' and 'fgrep' are shell files
  517. ;; that call 'grep'. If the bootstrap 'egrep' and 'fgrep'
  518. ;; are not binaries then patch them to execute 'grep' via its
  519. ;; absolute file name instead of searching for it in $PATH.
  520. (if (not (elf-file? "bin/egrep"))
  521. (substitute* '("bin/egrep" "bin/fgrep")
  522. (("^exec grep") (string-append (getcwd) "/bin/grep"))))
  523. (chmod "bin" #o555))))
  524. (define-public %bootstrap-linux-libre-headers
  525. (package-from-tarball
  526. "linux-libre-headers-bootstrap"
  527. (lambda (system)
  528. (origin
  529. (method url-fetch)
  530. (uri (map (cute string-append <>
  531. "/i686-linux/20190815/"
  532. "linux-libre-headers-stripped-4.14.67-i686-linux.tar.xz")
  533. %bootstrap-base-urls))
  534. (sha256
  535. (base32
  536. "0sm2z9x4wk45bh6qfs94p0w1d6hsy6dqx9sw38qsqbvxwa1qzk8s"))))
  537. #f ; no program to test
  538. "Bootstrap linux-libre-headers"))
  539. (define %bootstrap-binutils
  540. (package-from-tarball "binutils-bootstrap"
  541. (lambda (system)
  542. (origin
  543. (method url-fetch)
  544. (uri (map (cut string-append <> "/" system
  545. (match system
  546. ("armhf-linux"
  547. "/20150101/binutils-2.25.tar.xz")
  548. ("aarch64-linux"
  549. "/20170217/binutils-2.27.tar.xz")
  550. ("powerpc64le-linux"
  551. "/20210106/binutils-static-stripped-2.34-powerpc64le-linux-gnu.tar.xz")
  552. ("i586-gnu"
  553. "/20200326/binutils-static-stripped-2.34-i586-pc-gnu.tar.xz")
  554. ("powerpc-linux"
  555. "/20200923/binutils-2.35.1.tar.xz")
  556. (_
  557. "/20131110/binutils-2.23.2.tar.xz")))
  558. %bootstrap-base-urls))
  559. (sha256
  560. (match system
  561. ("x86_64-linux"
  562. (base32
  563. "1j5yivz7zkjqfsfmxzrrrffwyayjqyfxgpi89df0w4qziqs2dg20"))
  564. ("i686-linux"
  565. (base32
  566. "14jgwf9gscd7l2pnz610b1zia06dvcm2qyzvni31b8zpgmcai2v9"))
  567. ("armhf-linux"
  568. (base32
  569. "1v7dj6bzn6m36f20gw31l99xaabq4xrhrx3gwqkhhig0mdlmr69q"))
  570. ("aarch64-linux"
  571. (base32
  572. "111s7ilfiby033rczc71797xrmaa3qlv179wdvsaq132pd51xv3n"))
  573. ("powerpc64le-linux"
  574. (base32
  575. "1klxy945c61134mzhqzz2gbk8w0n8jq7arwkrvz78d22ff2q0cwz"))
  576. ("i586-gnu"
  577. (base32
  578. "11kykv1kmqc5wln57rs4klaqa13hm952smkc57qcsyss21kfjprs"))
  579. ("powerpc-linux"
  580. (base32
  581. "0asbg1c4avkrvh057mx0942xwddd136jni382zqsxzn79ls42yq8"))
  582. ("mips64el-linux"
  583. (base32
  584. "1x8kkhcxmfyzg1ddpz2pxs6fbdl6412r7x0nzbmi5n7mj8zw2gy7"))))))
  585. "ld" ; the program to test
  586. "Bootstrap binaries of the GNU Binutils"))
  587. (define %bootstrap-glibc
  588. ;; The initial libc.
  589. (package
  590. (name "glibc-bootstrap")
  591. (version "0")
  592. (source #f)
  593. (build-system trivial-build-system)
  594. (arguments
  595. `(#:guile ,%bootstrap-guile
  596. #:modules ((guix build utils))
  597. #:builder
  598. (begin
  599. (use-modules (guix build utils))
  600. (let ((out (assoc-ref %outputs "out"))
  601. (tar (assoc-ref %build-inputs "tar"))
  602. (xz (assoc-ref %build-inputs "xz"))
  603. (tarball (assoc-ref %build-inputs "tarball")))
  604. (mkdir out)
  605. (copy-file tarball "binaries.tar.xz")
  606. (invoke xz "-d" "binaries.tar.xz")
  607. (let ((builddir (getcwd)))
  608. (with-directory-excursion out
  609. (invoke tar "xvf"
  610. (string-append builddir
  611. "/binaries.tar"))
  612. (chmod "lib" #o755)
  613. ;; Patch libc.so so it refers to the right path.
  614. (substitute* "lib/libc.so"
  615. (("/[^ ]+/lib/(libc|ld)" _ prefix)
  616. (string-append out "/lib/" prefix)))
  617. #t))))))
  618. (inputs
  619. `(("tar" ,(bootstrap-executable "tar" (%current-system)))
  620. ("xz" ,(bootstrap-executable "xz" (%current-system)))
  621. ("tarball" ,(bootstrap-origin
  622. (origin
  623. (method url-fetch)
  624. (uri (map (cut string-append <> "/" (%current-system)
  625. (match (%current-system)
  626. ("armhf-linux"
  627. "/20150101/glibc-2.20.tar.xz")
  628. ("aarch64-linux"
  629. "/20170217/glibc-2.25.tar.xz")
  630. ("powerpc64le-linux"
  631. "/20210106/glibc-stripped-2.31-powerpc64le-linux-gnu.tar.xz")
  632. ("i586-gnu"
  633. "/20200326/glibc-stripped-2.31-i586-pc-gnu.tar.xz")
  634. ("powerpc-linux"
  635. "/20200923/glibc-2.32.tar.xz")
  636. (_
  637. "/20131110/glibc-2.18.tar.xz")))
  638. %bootstrap-base-urls))
  639. (sha256
  640. (match (%current-system)
  641. ("x86_64-linux"
  642. (base32
  643. "0jlqrgavvnplj1b083s20jj9iddr4lzfvwybw5xrcis9spbfzk7v"))
  644. ("i686-linux"
  645. (base32
  646. "1hgrccw1zqdc7lvgivwa54d9l3zsim5pqm0dykxg0z522h6gr05w"))
  647. ("armhf-linux"
  648. (base32
  649. "18cmgvpllqfpn6khsmivqib7ys8ymnq0hdzi3qp24prik0ykz8gn"))
  650. ("aarch64-linux"
  651. (base32
  652. "07nx3x8598i2924rjnlrncg6rm61c9bmcczbbcpbx0fb742nvv5c"))
  653. ("powerpc64le-linux"
  654. (base32
  655. "1a1df6z8gkaq09md3jy94lixnh20599p58p0s856p10xwjaqr1iz"))
  656. ("i586-gnu"
  657. (base32
  658. "14ddm10lpbas8bankmn5bcrlqvz1v5dnn1qjzxb19r57vd2w5952"))
  659. ("powerpc-linux"
  660. (base32
  661. "0smmssyjrlk5cvx49586smmk81gkwff0i6r91n4rir4jm6ba25sb"))
  662. ("mips64el-linux"
  663. (base32
  664. "0k97a3whzx3apsi9n2cbsrr79ad6lh00klxph9hw4fqyp1abkdsg")))))))))
  665. (synopsis "Bootstrap binaries and headers of the GNU C Library")
  666. (description synopsis)
  667. (home-page #f)
  668. (license lgpl2.1+)))
  669. (define %bootstrap-gcc
  670. ;; The initial GCC. Uses binaries from a tarball typically built by
  671. ;; %GCC-BOOTSTRAP-TARBALL.
  672. (package
  673. (name "gcc-bootstrap")
  674. (version "0")
  675. (source #f)
  676. (build-system trivial-build-system)
  677. (arguments
  678. `(#:guile ,%bootstrap-guile
  679. #:modules ((guix build utils))
  680. #:builder
  681. (begin
  682. (use-modules (guix build utils)
  683. (ice-9 popen))
  684. (let ((out (assoc-ref %outputs "out"))
  685. (tar (assoc-ref %build-inputs "tar"))
  686. (xz (assoc-ref %build-inputs "xz"))
  687. (bash (assoc-ref %build-inputs "bash"))
  688. (libc (assoc-ref %build-inputs "libc"))
  689. (tarball (assoc-ref %build-inputs "tarball")))
  690. (mkdir out)
  691. (copy-file tarball "binaries.tar.xz")
  692. (invoke xz "-d" "binaries.tar.xz")
  693. (let ((builddir (getcwd))
  694. (bindir (string-append out "/bin")))
  695. (with-directory-excursion out
  696. (invoke tar "xvf"
  697. (string-append builddir "/binaries.tar")))
  698. (with-directory-excursion bindir
  699. (chmod "." #o755)
  700. (rename-file "gcc" ".gcc-wrapped")
  701. (call-with-output-file "gcc"
  702. (lambda (p)
  703. (format p "#!~a
  704. exec ~a/bin/.gcc-wrapped -B~a/lib \
  705. -Wl,-rpath -Wl,~a/lib \
  706. -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
  707. bash
  708. out libc libc libc
  709. ,(glibc-dynamic-linker))))
  710. (chmod "gcc" #o555)
  711. #t))))))
  712. (inputs
  713. `(("tar" ,(bootstrap-executable "tar" (%current-system)))
  714. ("xz" ,(bootstrap-executable "xz" (%current-system)))
  715. ("bash" ,(bootstrap-executable "bash" (%current-system)))
  716. ("libc" ,%bootstrap-glibc)
  717. ("tarball" ,(bootstrap-origin
  718. (origin
  719. (method url-fetch)
  720. (uri (map (cut string-append <> "/" (%current-system)
  721. (match (%current-system)
  722. ("armhf-linux"
  723. "/20150101/gcc-4.8.4.tar.xz")
  724. ("aarch64-linux"
  725. "/20170217/gcc-5.4.0.tar.xz")
  726. ("powerpc64le-linux"
  727. "/20210106/gcc-stripped-5.5.0-powerpc64le-linux-gnu.tar.xz")
  728. ("i586-gnu"
  729. "/20200326/gcc-stripped-5.5.0-i586-pc-gnu.tar.xz")
  730. ("powerpc-linux"
  731. "/20200923/gcc-5.5.0.tar.xz")
  732. (_
  733. "/20131110/gcc-4.8.2.tar.xz")))
  734. %bootstrap-base-urls))
  735. (sha256
  736. (match (%current-system)
  737. ("x86_64-linux"
  738. (base32
  739. "17ga4m6195n4fnbzdkmik834znkhs53nkypp6557pl1ps7dgqbls"))
  740. ("i686-linux"
  741. (base32
  742. "150c1arrf2k8vfy6dpxh59vcgs4p1bgiz2av5m19dynpks7rjnyw"))
  743. ("armhf-linux"
  744. (base32
  745. "0ghz825yzp43fxw53kd6afm8nkz16f7dxi9xi40bfwc8x3nbbr8v"))
  746. ("aarch64-linux"
  747. (base32
  748. "1ar3vdzyqbfm0z36kmvazvfswxhcihlacl2dzdjgiq25cqnq9ih1"))
  749. ("powerpc64le-linux"
  750. (base32
  751. "151kjsai25vz2s667bgzpisx8f281fpl3n9pxz2yrp9jlnadz3m1"))
  752. ("i586-gnu"
  753. (base32
  754. "1j2zc58wzil71a34h7c70sd68dmqvcscrw3rmn2whq79vd70zvv5"))
  755. ("powerpc-linux"
  756. (base32
  757. "1p7df3yixhm87dw5sccc6yn1i9db1r9hnmsg87wq5xi4rfmirq7w"))
  758. ("mips64el-linux"
  759. (base32
  760. "1m5miqkyng45l745n0sfafdpjkqv9225xf44jqkygwsipj2cv9ks")))))))))
  761. (native-search-paths
  762. (list (search-path-specification
  763. (variable "C_INCLUDE_PATH")
  764. (files '("include")))
  765. (search-path-specification
  766. (variable "CPLUS_INCLUDE_PATH")
  767. (files '("include/c++" "include")))
  768. (search-path-specification
  769. (variable "LIBRARY_PATH")
  770. (files '("lib" "lib64")))))
  771. (synopsis "Bootstrap binaries of the GNU Compiler Collection")
  772. (description synopsis)
  773. (home-page #f)
  774. (license gpl3+)))
  775. (define %bootstrap-mescc-tools
  776. ;; The initial MesCC tools. Uses binaries from a tarball typically built by
  777. ;; %MESCC-TOOLS-BOOTSTRAP-TARBALL.
  778. (package
  779. (name "bootstrap-mescc-tools")
  780. (version "0.5.2")
  781. (source #f)
  782. (build-system trivial-build-system)
  783. (arguments
  784. `(#:guile ,%bootstrap-guile
  785. #:modules ((guix build utils))
  786. #:builder
  787. (begin
  788. (use-modules (guix build utils)
  789. (ice-9 popen))
  790. (let ((out (assoc-ref %outputs "out"))
  791. (tar (assoc-ref %build-inputs "tar"))
  792. (xz (assoc-ref %build-inputs "xz"))
  793. (tarball (assoc-ref %build-inputs "tarball")))
  794. (mkdir out)
  795. (copy-file tarball "binaries.tar.xz")
  796. (invoke xz "-d" "binaries.tar.xz")
  797. (let ((builddir (getcwd))
  798. (bindir (string-append out "/bin")))
  799. (with-directory-excursion out
  800. (invoke tar "xvf"
  801. (string-append builddir "/binaries.tar"))))))))
  802. (inputs
  803. `(("tar" ,(bootstrap-executable "tar" (%current-system)))
  804. ("xz" ,(bootstrap-executable "xz" (%current-system)))
  805. ("tarball"
  806. ,(bootstrap-origin
  807. (origin
  808. (method url-fetch)
  809. (uri (map
  810. (cute string-append <>
  811. "/i686-linux/20190815/"
  812. "mescc-tools-static-stripped-0.5.2-i686-linux.tar.xz")
  813. %bootstrap-base-urls))
  814. (sha256
  815. (base32
  816. "0c3kklgghzh4q2dbpl6asb74cimp7hp6jscdwqwmzxbapgcl6582")))))))
  817. (synopsis "Bootstrap binaries of MesCC Tools")
  818. (description synopsis)
  819. (home-page #f)
  820. (supported-systems '("i686-linux" "x86_64-linux"))
  821. (license gpl3+)))
  822. (define %bootstrap-mes
  823. ;; The initial Mes. Uses binaries from a tarball typically built by
  824. ;; %MES-BOOTSTRAP-TARBALL.
  825. (package
  826. (name "bootstrap-mes")
  827. (version "0")
  828. (source #f)
  829. (build-system trivial-build-system)
  830. (arguments
  831. `(#:guile ,%bootstrap-guile
  832. #:modules ((guix build utils))
  833. #:builder
  834. (begin
  835. (use-modules (guix build utils)
  836. (ice-9 popen))
  837. (let ((out (assoc-ref %outputs "out"))
  838. (tar (assoc-ref %build-inputs "tar"))
  839. (xz (assoc-ref %build-inputs "xz"))
  840. (tarball (assoc-ref %build-inputs "tarball")))
  841. (mkdir out)
  842. (copy-file tarball "binaries.tar.xz")
  843. (invoke xz "-d" "binaries.tar.xz")
  844. (let ((builddir (getcwd))
  845. (bindir (string-append out "/bin")))
  846. (with-directory-excursion out
  847. (invoke tar "xvf"
  848. (string-append builddir "/binaries.tar"))))))))
  849. (inputs
  850. `(("tar" ,(bootstrap-executable "tar" (%current-system)))
  851. ("xz" ,(bootstrap-executable "xz" (%current-system)))
  852. ("tarball"
  853. ,(bootstrap-origin
  854. (origin
  855. (method url-fetch)
  856. (uri (map
  857. (cute string-append <>
  858. "/i686-linux/20190815/"
  859. "mes-minimal-stripped-0.19-i686-linux.tar.xz")
  860. %bootstrap-base-urls))
  861. (sha256
  862. (base32
  863. "1q4xjpx6nbn44kxnilpgl12bhpmwy2bblzwszc2ci7xkf400jcpv")))))))
  864. (supported-systems '("i686-linux" "x86_64-linux"))
  865. (synopsis "Bootstrap binaries of Mes")
  866. (description synopsis)
  867. (home-page #f)
  868. (license gpl3+)))
  869. (define (%bootstrap-inputs)
  870. ;; The initial, pre-built inputs. From now on, we can start building our
  871. ;; own packages.
  872. (match (%current-system)
  873. ((or "i686-linux" "x86_64-linux")
  874. `(("linux-libre-headers" ,%bootstrap-linux-libre-headers)
  875. ("bootstrap-mescc-tools" ,%bootstrap-mescc-tools)
  876. ("mes" ,%bootstrap-mes)))
  877. (_
  878. `(("libc" ,%bootstrap-glibc)
  879. ("gcc" ,%bootstrap-gcc)
  880. ("binutils" ,%bootstrap-binutils)
  881. ("coreutils&co" ,%bootstrap-coreutils&co)
  882. ;; In gnu-build-system.scm, we rely on the availability of Bash.
  883. ("bash" ,%bootstrap-coreutils&co)))))
  884. (define %bootstrap-inputs-for-tests
  885. ;; These are bootstrap inputs that are cheap to produce (no compilation
  886. ;; needed) and that are meant to be used for testing. (These are those we
  887. ;; used before the Mes-based reduced bootstrap.)
  888. `(("libc" ,%bootstrap-glibc)
  889. ("gcc" ,%bootstrap-gcc)
  890. ("binutils" ,%bootstrap-binutils)
  891. ("coreutils&co" ,%bootstrap-coreutils&co)
  892. ("bash" ,%bootstrap-coreutils&co)))
  893. ;;; bootstrap.scm ends here