1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014, 2015, 2018 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
5 ;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
7 ;;; This file is part of GNU Guix.
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 (define-module (gnu packages bootstrap)
23 #:use-module (guix licenses)
24 #:use-module (gnu packages)
25 #:use-module (guix packages)
26 #:use-module (guix download)
27 #:use-module (guix build-system)
28 #:use-module (guix build-system gnu)
29 #:use-module (guix build-system trivial)
30 #:use-module ((guix store)
31 #:select (run-with-store add-to-store add-text-to-store))
32 #:use-module ((guix derivations)
33 #:select (derivation derivation->output-path))
34 #:use-module ((guix utils) #:select (gnu-triplet->nix-system))
35 #:use-module (guix memoization)
36 #:use-module (srfi srfi-1)
37 #:use-module (srfi srfi-26)
38 #:use-module (ice-9 match)
39 #:export (bootstrap-origin
40 package-with-bootstrap-guile
43 bootstrap-guile-origin
46 %bootstrap-coreutils&co
47 %bootstrap-linux-libre-headers
59 ;;; Pre-built packages that are used to bootstrap the
60 ;;; distribution--i.e., to build all the core packages from scratch.
67 ;;; Helper procedures.
70 (define (bootstrap-origin source)
71 "Return a variant of SOURCE, an <origin> instance, whose method uses
72 %BOOTSTRAP-GUILE to do its job."
74 (lambda* (url hash-algo hash
75 #:optional name #:key system)
76 (fetch url hash-algo hash name
77 #:guile %bootstrap-guile
80 (define %bootstrap-patch-inputs
81 ;; Packages used when an <origin> has a non-empty 'patches' field.
82 `(("tar" ,%bootstrap-coreutils&co)
83 ("xz" ,%bootstrap-coreutils&co)
84 ("bzip2" ,%bootstrap-coreutils&co)
85 ("gzip" ,%bootstrap-coreutils&co)
86 ("patch" ,%bootstrap-coreutils&co)))
88 (let ((orig-method (origin-method source)))
89 (origin (inherit source)
90 (method (cond ((eq? orig-method url-fetch)
93 (patch-guile %bootstrap-guile)
94 (patch-inputs %bootstrap-patch-inputs)
96 ;; Patches can be origins as well, so process them.
97 (patches (map (match-lambda
99 (bootstrap-origin patch))
101 (origin-patches source))))))
103 (define* (package-from-tarball name source program-to-test description
105 "Return a package that correspond to the extraction of SOURCE.
106 PROGRAM-TO-TEST is #f or a string: the program to run after extraction of
107 SOURCE to check whether everything is alright. If SNIPPET is provided, it is
108 evaluated after extracting SOURCE. SNIPPET should return true if successful,
109 or false to signal an error."
113 (build-system trivial-build-system)
115 `(#:guile ,%bootstrap-guile
116 #:modules ((guix build utils))
118 (let ((out (assoc-ref %outputs "out"))
119 (tar (assoc-ref %build-inputs "tar"))
120 (xz (assoc-ref %build-inputs "xz"))
121 (tarball (assoc-ref %build-inputs "tarball")))
122 (use-modules (guix build utils))
125 (copy-file tarball "binaries.tar.xz")
126 (invoke xz "-d" "binaries.tar.xz")
127 (let ((builddir (getcwd)))
128 (with-directory-excursion out
130 (string-append builddir "/binaries.tar"))
131 ,@(if snippet (list snippet) '())
132 (or (not ,program-to-test)
133 (invoke (string-append "bin/" ,program-to-test)
136 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
137 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
138 ("tarball" ,(bootstrap-origin (source (%current-system))))))
140 (synopsis description)
141 (description description)
145 (define package-with-bootstrap-guile
147 "Return a variant of P such that all its origins are fetched with
149 (define rewritten-input
151 ((name (? origin? o))
152 `(,name ,(bootstrap-origin o)))
153 ((name (? package? p) sub-drvs ...)
154 `(,name ,(package-with-bootstrap-guile p) ,@sub-drvs))
158 (source (match (package-source p)
159 ((? origin? o) (bootstrap-origin o))
161 (inputs (map rewritten-input
163 (native-inputs (map rewritten-input
164 (package-native-inputs p)))
165 (propagated-inputs (map rewritten-input
166 (package-propagated-inputs p)))
167 (replacement (and=> (package-replacement p)
168 package-with-bootstrap-guile)))))
170 (define* (glibc-dynamic-linker
171 #:optional (system (or (and=> (%current-target-system)
172 gnu-triplet->nix-system)
174 "Return the name of Glibc's dynamic linker for SYSTEM."
175 ;; See the 'SYSDEP_KNOWN_INTERPRETER_NAMES' cpp macro in libc.
176 (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2")
177 ((string=? system "i686-linux") "/lib/ld-linux.so.2")
178 ((string=? system "armhf-linux") "/lib/ld-linux-armhf.so.3")
179 ((string=? system "mips64el-linux") "/lib/ld.so.1")
180 ((string=? system "i586-gnu") "/lib/ld.so.1")
181 ((string=? system "i686-gnu") "/lib/ld.so.1")
182 ((string=? system "aarch64-linux") "/lib/ld-linux-aarch64.so.1")
183 ((string=? system "powerpc-linux") "/lib/ld.so.1")
184 ((string=? system "powerpc64le-linux") "/lib/ld64.so.2")
185 ((string=? system "alpha-linux") "/lib/ld-linux.so.2")
186 ((string=? system "s390x-linux") "/lib/ld64.so.1")
188 ;; XXX: This one is used bare-bones, without a libc, so add a case
189 ;; here just so we can keep going.
190 ((string=? system "arm-eabi") "no-ld.so")
191 ((string=? system "xtensa-elf") "no-ld.so")
192 ((string=? system "avr") "no-ld.so")
193 ((string=? system "propeller-elf") "no-ld.so")
194 ((string=? system "i686-mingw") "no-ld.so")
195 ((string=? system "vc4-elf") "no-ld.so")
197 (else (error "dynamic linker name not known for this system"
202 ;;; Bootstrap packages.
205 (define %bootstrap-base-urls
206 ;; This is where the initial binaries come from.
207 '("https://alpha.gnu.org/gnu/guix/bootstrap"
208 "http://alpha.gnu.org/gnu/guix/bootstrap"
209 "ftp://alpha.gnu.org/gnu/guix/bootstrap"
210 "http://www.fdn.fr/~lcourtes/software/guix/packages"
211 "http://flashner.co.il/guix/bootstrap"))
213 (define (bootstrap-guile-url-path system)
214 "Return the URI for FILE."
215 (string-append "/" system
218 "/20170217/guile-2.0.14.tar.xz")
220 "/20150101/guile-2.0.11.tar.xz")
222 "/20131110/guile-2.0.9.tar.xz"))))
224 (define (bootstrap-guile-hash system)
225 "Return the SHA256 hash of the Guile bootstrap tarball for SYSTEM."
228 (base32 "1w2p5zyrglzzniqgvyn1b55vprfzhgk8vzbzkkbdgl5248si0yq3"))
230 (base32 "0im800m30abgh7msh331pcbjvb4n02smz5cfzf1srv0kpx3csmxp"))
232 (base32 "0fzp93lvi0hn54acc0fpvhc7bvl0yc853k62l958cihk03q80ilr"))
234 (base32 "1mi3brl7l58aww34rawhvja84xc7l1b4hmwdmc36fp9q9mfx0lg5"))
236 (base32 "1giy2aprjmn5fp9c4s9r125fljw4wv6ixy5739i5bffw4jgr0f9r"))))
238 (define (bootstrap-guile-origin system)
239 "Return an <origin> object for the Guile tarball of SYSTEM."
242 (uri (map (cute string-append <> (bootstrap-guile-url-path system))
243 %bootstrap-base-urls))
244 (sha256 (bootstrap-guile-hash system))))
246 (define (download-bootstrap-guile store system)
247 "Return a derivation that downloads the bootstrap Guile tarball for SYSTEM."
248 (let* ((path (bootstrap-guile-url-path system))
249 (base (basename path))
250 (urls (map (cut string-append <> path) %bootstrap-base-urls)))
251 (run-with-store store
252 (url-fetch urls 'sha256 (bootstrap-guile-hash system)
255 (define* (raw-build store name inputs
256 #:key outputs system search-paths
258 (define (->store file)
259 (add-to-store store file #t "sha256"
260 (or (search-bootstrap-binary file
262 (error "bootstrap binary not found"
265 (let* ((tar (->store "tar"))
267 (mkdir (->store "mkdir"))
268 (bash (->store "bash"))
269 (guile (download-bootstrap-guile store system))
270 ;; The following code, run by the bootstrap guile after it is
271 ;; unpacked, creates a wrapper for itself to set its load path.
272 ;; This replaces the previous non-portable method based on
273 ;; reading the /proc/self/exe symlink.
276 (use-modules (ice-9 match))
277 (match (command-line)
279 (let ((bin-dir (string-append out "/bin"))
280 (guile (string-append out "/bin/guile"))
281 (guile-real (string-append out "/bin/.guile-real"))
282 ;; We must avoid using a bare dollar sign in this code,
283 ;; because it would be interpreted by the shell.
284 (dollar (string (integer->char 36))))
285 (chmod bin-dir #o755)
286 (rename-file guile guile-real)
287 (call-with-output-file guile
291 export GUILE_SYSTEM_PATH=~a/share/guile/2.0
292 export GUILE_SYSTEM_COMPILED_PATH=~a/lib/guile/2.0/ccache
293 exec -a \"~a0\" ~a \"~a@\"\n"
294 bash out out dollar guile-real dollar)))
296 (chmod bin-dir #o555))))))
298 (add-text-to-store store
299 "build-bootstrap-guile.sh"
301 echo \"unpacking bootstrap Guile to '$out'...\"
304 ~a -dc < $GUILE_TARBALL | ~a xv
306 # Use the bootstrap guile to create its own wrapper to set the load path.
307 GUILE_SYSTEM_PATH=$out/share/guile/2.0 \
308 GUILE_SYSTEM_COMPILED_PATH=$out/lib/guile/2.0/ccache \
309 $out/bin/guile -c ~s $out ~a
312 $out/bin/guile --version~%"
314 (format #f "~s" make-guile-wrapper)
316 (list mkdir xz tar bash))))
317 (derivation store name
320 #:inputs `((,bash) (,builder) (,guile))
321 #:env-vars `(("GUILE_TARBALL"
322 . ,(derivation->output-path guile))))))
324 (define* (make-raw-bag name
325 #:key source inputs native-inputs outputs
330 (build-inputs inputs)
333 (define %bootstrap-guile
334 ;; The Guile used to run the build scripts of the initial derivations.
335 ;; It is just unpacked from a tarball containing a pre-built binary.
336 ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
338 ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
339 ;; support (for /etc/services).
340 (let ((raw (build-system
342 (description "Raw build system with direct store access")
343 (lower make-raw-bag))))
345 (name "guile-bootstrap")
349 (synopsis "Bootstrap Guile")
350 (description "Pre-built Guile for bootstrapping purposes.")
354 (define %bootstrap-coreutils&co
355 (package-from-tarball "bootstrap-binaries"
359 (uri (map (cut string-append <> "/" system
362 "/20150101/static-binaries.tar.xz")
364 "/20170217/static-binaries.tar.xz")
366 "/20131110/static-binaries.tar.xz")))
367 %bootstrap-base-urls))
372 "0c533p9dhczzcsa1117gmfq3pc8w362g4mx84ik36srpr7cx2bg4"))
375 "0s5b3jb315n13m1k8095l0a5hfrsz8g0fv1b6riyc5hnxqyphlak"))
378 "0gf0fn2kbpxkjixkmx5f4z6hv6qpmgixl69zgg74dbsfdfj8jdv5"))
381 "18dfiq6c6xhsdpbidigw6480wh0vdgsxqq3xindq4lpdgqlccpfh"))
384 "072y4wyfsj1bs80r6vbybbafy8ya4vfy7qj25dklwk97m6g71753"))))))
385 "fgrep" ; the program to test
386 "Bootstrap binaries of Coreutils, Awk, etc."
388 '(let ((path (list (string-append (getcwd) "/bin"))))
390 (patch-shebang "bin/egrep" path)
391 (patch-shebang "bin/fgrep" path)
392 ;; Starting with grep@2.25 'egrep' and 'fgrep' are shell files
393 ;; that call 'grep'. If the bootstrap 'egrep' and 'fgrep'
394 ;; are not binaries then patch them to execute 'grep' via its
395 ;; absolute file name instead of searching for it in $PATH.
396 (if (not (elf-file? "bin/egrep"))
397 (substitute* '("bin/egrep" "bin/fgrep")
398 (("^exec grep") (string-append (getcwd) "/bin/grep"))))
399 (chmod "bin" #o555))))
401 (define-public %bootstrap-linux-libre-headers
402 (package-from-tarball
403 "linux-libre-headers-bootstrap"
410 "http://lilypond.org/janneke/mes/linux-libre-headers-stripped-4.14.26-i686-linux.tar.xz")
411 (_ (error "linux-libre-headers-bootstrap: system not supported"))))
414 "0nwspwydn089xbd28nnas762iwl6l9ymbcz170qvfi50ywgim1ma"))))
415 #f ; no program to test
416 "Bootstrap linux-libre-headers"))
418 (define %bootstrap-binutils
419 (package-from-tarball "binutils-bootstrap"
423 (uri (map (cut string-append <> "/" system
426 "/20150101/binutils-2.25.tar.xz")
428 "/20170217/binutils-2.27.tar.xz")
430 "/20131110/binutils-2.23.2.tar.xz")))
431 %bootstrap-base-urls))
436 "1j5yivz7zkjqfsfmxzrrrffwyayjqyfxgpi89df0w4qziqs2dg20"))
439 "14jgwf9gscd7l2pnz610b1zia06dvcm2qyzvni31b8zpgmcai2v9"))
442 "1v7dj6bzn6m36f20gw31l99xaabq4xrhrx3gwqkhhig0mdlmr69q"))
445 "111s7ilfiby033rczc71797xrmaa3qlv179wdvsaq132pd51xv3n"))
448 "1x8kkhcxmfyzg1ddpz2pxs6fbdl6412r7x0nzbmi5n7mj8zw2gy7"))))))
449 "ld" ; the program to test
450 "Bootstrap binaries of the GNU Binutils"))
452 (define %bootstrap-glibc
455 (name "glibc-bootstrap")
458 (build-system trivial-build-system)
460 `(#:guile ,%bootstrap-guile
461 #:modules ((guix build utils))
463 (let ((out (assoc-ref %outputs "out"))
464 (tar (assoc-ref %build-inputs "tar"))
465 (xz (assoc-ref %build-inputs "xz"))
466 (tarball (assoc-ref %build-inputs "tarball")))
467 (use-modules (guix build utils))
470 (copy-file tarball "binaries.tar.xz")
471 (invoke xz "-d" "binaries.tar.xz")
472 (let ((builddir (getcwd)))
473 (with-directory-excursion out
475 (string-append builddir
479 ;; Patch libc.so so it refers to the right path.
480 (substitute* "lib/libc.so"
481 (("/[^ ]+/lib/(libc|ld)" _ prefix)
482 (string-append out "/lib/" prefix)))
486 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
487 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
488 ("tarball" ,(bootstrap-origin
491 (uri (map (cut string-append <> "/" (%current-system)
492 (match (%current-system)
494 "/20150101/glibc-2.20.tar.xz")
496 "/20170217/glibc-2.25.tar.xz")
498 "/20131110/glibc-2.18.tar.xz")))
499 %bootstrap-base-urls))
501 (match (%current-system)
504 "0jlqrgavvnplj1b083s20jj9iddr4lzfvwybw5xrcis9spbfzk7v"))
507 "1hgrccw1zqdc7lvgivwa54d9l3zsim5pqm0dykxg0z522h6gr05w"))
510 "18cmgvpllqfpn6khsmivqib7ys8ymnq0hdzi3qp24prik0ykz8gn"))
513 "07nx3x8598i2924rjnlrncg6rm61c9bmcczbbcpbx0fb742nvv5c"))
516 "0k97a3whzx3apsi9n2cbsrr79ad6lh00klxph9hw4fqyp1abkdsg")))))))))
517 (synopsis "Bootstrap binaries and headers of the GNU C Library")
518 (description synopsis)
522 (define %bootstrap-gcc
523 ;; The initial GCC. Uses binaries from a tarball typically built by
524 ;; %GCC-BOOTSTRAP-TARBALL.
526 (name "gcc-bootstrap")
529 (build-system trivial-build-system)
531 `(#:guile ,%bootstrap-guile
532 #:modules ((guix build utils))
534 (let ((out (assoc-ref %outputs "out"))
535 (tar (assoc-ref %build-inputs "tar"))
536 (xz (assoc-ref %build-inputs "xz"))
537 (bash (assoc-ref %build-inputs "bash"))
538 (libc (assoc-ref %build-inputs "libc"))
539 (tarball (assoc-ref %build-inputs "tarball")))
540 (use-modules (guix build utils)
544 (copy-file tarball "binaries.tar.xz")
545 (invoke xz "-d" "binaries.tar.xz")
546 (let ((builddir (getcwd))
547 (bindir (string-append out "/bin")))
548 (with-directory-excursion out
550 (string-append builddir "/binaries.tar")))
552 (with-directory-excursion bindir
554 (rename-file "gcc" ".gcc-wrapped")
555 (call-with-output-file "gcc"
558 exec ~a/bin/.gcc-wrapped -B~a/lib \
559 -Wl,-rpath -Wl,~a/lib \
560 -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
563 ,(glibc-dynamic-linker))))
568 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
569 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
570 ("bash" ,(search-bootstrap-binary "bash" (%current-system)))
571 ("libc" ,%bootstrap-glibc)
572 ("tarball" ,(bootstrap-origin
575 (uri (map (cut string-append <> "/" (%current-system)
576 (match (%current-system)
578 "/20150101/gcc-4.8.4.tar.xz")
580 "/20170217/gcc-5.4.0.tar.xz")
582 "/20131110/gcc-4.8.2.tar.xz")))
583 %bootstrap-base-urls))
585 (match (%current-system)
588 "17ga4m6195n4fnbzdkmik834znkhs53nkypp6557pl1ps7dgqbls"))
591 "150c1arrf2k8vfy6dpxh59vcgs4p1bgiz2av5m19dynpks7rjnyw"))
594 "0ghz825yzp43fxw53kd6afm8nkz16f7dxi9xi40bfwc8x3nbbr8v"))
597 "1ar3vdzyqbfm0z36kmvazvfswxhcihlacl2dzdjgiq25cqnq9ih1"))
600 "1m5miqkyng45l745n0sfafdpjkqv9225xf44jqkygwsipj2cv9ks")))))))))
602 (list (search-path-specification
604 (files '("include")))
605 (search-path-specification
606 (variable "LIBRARY_PATH")
607 (files '("lib" "lib64")))))
608 (synopsis "Bootstrap binaries of the GNU Compiler Collection")
609 (description synopsis)
613 (define %mescc-tools-seed ; todo: add tarballs to alpha.gnu.org/pub/mes/bootstrap/
614 (let ((commit "dc4e20e74924a5c80a2b7a77b4d7b927234fa71c"))
617 (uri (string-append "https://gitlab.com/janneke/mescc-tools-seed"
619 "/mescc-tools-seed-" commit ".tar.gz"))
622 "1lj7df73vxanmffmiwkhcn83r7yd9n8568nkki06bqq5zg526nyz")))))
625 (let ((commit "057fd36735b5605fe582d6b3625f793a62922206"))
628 (uri (string-append "https://gitlab.com/janneke/mes-seed"
630 "/mes-seed-" commit ".tar.gz"))
633 "0vdb4kc05a1kdpmsi8dg425d5f33kp28sgl2fi3s320pc0v4dv13")))))
636 (let ((commit "843d47ca682617f21333b50c67851797b8c3fd04"))
639 (uri (string-append "https://gitlab.com/janneke/tinycc-seed"
641 "/tinycc-seed-" commit ".tar.gz"))
644 "0599wwv30js03l1rpmvzfclq3jadzvq04pi29j45nf6fyfg5hhqb")))))
649 (uri "http://git.savannah.gnu.org/cgit/guile.git/plain/module/srfi/srfi-43.scm?h=stable-2.0")
650 (file-name "srfi-43.scm")
653 "0rnkppwdkxbzkgp9s9ccmby9f7p3ijxjlmvj0pzqxwmrmpy7jwmb"))))
655 (define (%bootstrap-inputs)
656 ;; The initial, pre-built inputs. From now on, we can start building our
658 `(,@(match (%current-system)
659 ((or "i686-linux" "x86_64-linux")
660 `(("linux-libre-headers" ,%bootstrap-linux-libre-headers)
661 ("mescc-tools-seed" ,%mescc-tools-seed)
662 ("mes-seed" ,%mes-seed)
663 ("srfi-43" ,%srfi-43 )
664 ("tinycc-seed" ,%tinycc-seed)))
666 `(("libc" ,%bootstrap-glibc)
667 ("gcc" ,%bootstrap-gcc)
668 ("binutils" ,%bootstrap-binutils))))
669 ("coreutils&co" ,%bootstrap-coreutils&co)
671 ;; In gnu-build-system.scm, we rely on the availability of Bash.
672 ("bash" ,%bootstrap-coreutils&co)))
674 ;;; bootstrap.scm ends here