gnu: Add limnoria.
[jackhill/guix/guix.git] / gnu / packages / bootstrap.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
52c0c82f 2;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
2959dbe9 3;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
18633d4f 4;;;
233e7676 5;;; This file is part of GNU Guix.
18633d4f 6;;;
233e7676 7;;; GNU Guix is free software; you can redistribute it and/or modify it
18633d4f
LC
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
233e7676 12;;; GNU Guix is distributed in the hope that it will be useful, but
18633d4f
LC
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
233e7676 18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18633d4f 19
1ffa7090 20(define-module (gnu packages bootstrap)
4a44e743 21 #:use-module (guix licenses)
59a43334 22 #:use-module (gnu packages)
18633d4f 23 #:use-module (guix packages)
62cab99c 24 #:use-module (guix download)
18633d4f
LC
25 #:use-module (guix build-system)
26 #:use-module (guix build-system gnu)
27 #:use-module (guix build-system trivial)
28 #:use-module ((guix store) #:select (add-to-store add-text-to-store))
29 #:use-module ((guix derivations) #:select (derivation))
958dd3ce
LC
30 #:use-module ((guix utils) #:select (gnu-triplet->nix-system))
31 #:use-module (guix combinators)
18633d4f
LC
32 #:use-module (srfi srfi-1)
33 #:use-module (srfi srfi-26)
34 #:use-module (ice-9 match)
35 #:export (bootstrap-origin
36 package-with-bootstrap-guile
37 glibc-dynamic-linker
38
39 %bootstrap-guile
40 %bootstrap-coreutils&co
41 %bootstrap-binutils
42 %bootstrap-gcc
43 %bootstrap-glibc
44 %bootstrap-inputs))
45
46;;; Commentary:
47;;;
48;;; Pre-built packages that are used to bootstrap the
49;;; distribution--i.e., to build all the core packages from scratch.
50;;;
51;;; Code:
52
53
54\f
55;;;
56;;; Helper procedures.
57;;;
58
59(define (bootstrap-origin source)
60 "Return a variant of SOURCE, an <origin> instance, whose method uses
61%BOOTSTRAP-GUILE to do its job."
62 (define (boot fetch)
f220a838 63 (lambda* (url hash-algo hash
18633d4f 64 #:optional name #:key system)
52c0c82f 65 (fetch url hash-algo hash name
18633d4f
LC
66 #:guile %bootstrap-guile
67 #:system system)))
68
5fbeb4e6
LC
69 (define %bootstrap-patch-inputs
70 ;; Packages used when an <origin> has a non-empty 'patches' field.
71 `(("tar" ,%bootstrap-coreutils&co)
72 ("xz" ,%bootstrap-coreutils&co)
73 ("bzip2" ,%bootstrap-coreutils&co)
74 ("gzip" ,%bootstrap-coreutils&co)
75 ("patch" ,%bootstrap-coreutils&co)))
76
18633d4f
LC
77 (let ((orig-method (origin-method source)))
78 (origin (inherit source)
87f5d366 79 (method (cond ((eq? orig-method url-fetch)
62cab99c 80 (boot url-fetch))
5fbeb4e6
LC
81 (else orig-method)))
82 (patch-guile %bootstrap-guile)
ce517b20
LC
83 (patch-inputs %bootstrap-patch-inputs)
84
85 ;; Patches can be origins as well, so process them.
86 (patches (map (match-lambda
87 ((? origin? patch)
88 (bootstrap-origin patch))
89 (patch patch))
90 (origin-patches source))))))
18633d4f 91
2959dbe9
MW
92(define* (package-from-tarball name source program-to-test description
93 #:key snippet)
dfb52abb
LC
94 "Return a package that correspond to the extraction of SOURCE.
95PROGRAM-TO-TEST is a program to run after extraction of SOURCE, to
2959dbe9
MW
96check whether everything is alright. If SNIPPET is provided, it is
97evaluated after extracting SOURCE. SNIPPET should return true if
98successful, or false to signal an error."
18633d4f 99 (package
dfb52abb 100 (name name)
18633d4f 101 (version "0")
18633d4f
LC
102 (build-system trivial-build-system)
103 (arguments
104 `(#:guile ,%bootstrap-guile
105 #:modules ((guix build utils))
106 #:builder
107 (let ((out (assoc-ref %outputs "out"))
108 (tar (assoc-ref %build-inputs "tar"))
109 (xz (assoc-ref %build-inputs "xz"))
110 (tarball (assoc-ref %build-inputs "tarball")))
111 (use-modules (guix build utils))
112
113 (mkdir out)
114 (copy-file tarball "binaries.tar.xz")
115 (system* xz "-d" "binaries.tar.xz")
116 (let ((builddir (getcwd)))
117 (with-directory-excursion out
118 (and (zero? (system* tar "xvf"
119 (string-append builddir "/binaries.tar")))
2959dbe9 120 ,@(if snippet (list snippet) '())
18633d4f
LC
121 (zero? (system* (string-append "bin/" ,program-to-test)
122 "--version"))))))))
123 (inputs
dd6b9a37
LC
124 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
125 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
dfb52abb
LC
126 ("tarball" ,(bootstrap-origin (source (%current-system))))))
127 (source #f)
128 (synopsis description)
7de1f103 129 (description description)
1fb78cb2 130 (home-page #f)
90f2801e 131 (license gpl3+)))
18633d4f
LC
132
133(define package-with-bootstrap-guile
134 (memoize
135 (lambda (p)
136 "Return a variant of P such that all its origins are fetched with
137%BOOTSTRAP-GUILE."
138 (define rewritten-input
139 (match-lambda
140 ((name (? origin? o))
141 `(,name ,(bootstrap-origin o)))
142 ((name (? package? p) sub-drvs ...)
143 `(,name ,(package-with-bootstrap-guile p) ,@sub-drvs))
144 (x x)))
145
146 (package (inherit p)
147 (source (match (package-source p)
148 ((? origin? o) (bootstrap-origin o))
149 (s s)))
150 (inputs (map rewritten-input
151 (package-inputs p)))
152 (native-inputs (map rewritten-input
153 (package-native-inputs p)))
154 (propagated-inputs (map rewritten-input
05962f29
LC
155 (package-propagated-inputs p)))
156 (replacement (and=> (package-replacement p)
157 package-with-bootstrap-guile))))))
18633d4f 158
e7133c76
LC
159(define* (glibc-dynamic-linker
160 #:optional (system (or (and=> (%current-target-system)
161 gnu-triplet->nix-system)
162 (%current-system))))
18633d4f
LC
163 "Return the name of Glibc's dynamic linker for SYSTEM."
164 (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2")
165 ((string=? system "i686-linux") "/lib/ld-linux.so.2")
3f00ff8b 166 ((string=? system "armhf-linux") "/lib/ld-linux-armhf.so.3")
827d2891 167 ((string=? system "mips64el-linux") "/lib/ld.so.1")
66feaa32
MB
168 ((string=? system "i586-gnu") "/lib/ld.so.1")
169 ((string=? system "i686-gnu") "/lib/ld.so.1")
19c444f4 170 ((string=? system "aarch64-linux") "/lib/ld-linux-aarch64.so.1")
9d307460
LC
171
172 ;; XXX: This one is used bare-bones, without a libc, so add a case
173 ;; here just so we can keep going.
174 ((string=? system "xtensa-elf") "no-ld.so")
a5b60e3c 175 ((string=? system "avr") "no-ld.so")
3135b95f 176 ((string=? system "i686-mingw") "no-ld.so")
9d307460 177
18633d4f
LC
178 (else (error "dynamic linker name not known for this system"
179 system))))
180
181\f
182;;;
183;;; Bootstrap packages.
184;;;
185
0d5a559f
LC
186(define* (raw-build store name inputs
187 #:key outputs system search-paths
188 #:allow-other-keys)
189 (define (->store file)
190 (add-to-store store file #t "sha256"
191 (or (search-bootstrap-binary file
192 system)
193 (error "bootstrap binary not found"
194 file system))))
195
196 (let* ((tar (->store "tar"))
197 (xz (->store "xz"))
198 (mkdir (->store "mkdir"))
199 (bash (->store "bash"))
aa1e1947
MW
200 (guile (->store (match system
201 ("armhf-linux"
202 "guile-2.0.11.tar.xz")
203 (_
204 "guile-2.0.9.tar.xz"))))
5d6792f0
MW
205 ;; The following code, run by the bootstrap guile after it is
206 ;; unpacked, creates a wrapper for itself to set its load path.
207 ;; This replaces the previous non-portable method based on
208 ;; reading the /proc/self/exe symlink.
209 (make-guile-wrapper
210 '(begin
211 (use-modules (ice-9 match))
212 (match (command-line)
213 ((_ out bash)
214 (let ((bin-dir (string-append out "/bin"))
215 (guile (string-append out "/bin/guile"))
216 (guile-real (string-append out "/bin/.guile-real"))
217 ;; We must avoid using a bare dollar sign in this code,
218 ;; because it would be interpreted by the shell.
219 (dollar (string (integer->char 36))))
220 (chmod bin-dir #o755)
221 (rename-file guile guile-real)
222 (call-with-output-file guile
223 (lambda (p)
224 (format p "\
225#!~a
226export GUILE_SYSTEM_PATH=~a/share/guile/2.0
227export GUILE_SYSTEM_COMPILED_PATH=~a/lib/guile/2.0/ccache
228exec -a \"~a0\" ~a \"~a@\"\n"
229 bash out out dollar guile-real dollar)))
230 (chmod guile #o555)
231 (chmod bin-dir #o555))))))
0d5a559f
LC
232 (builder
233 (add-text-to-store store
234 "build-bootstrap-guile.sh"
235 (format #f "
236echo \"unpacking bootstrap Guile to '$out'...\"
237~a $out
238cd $out
239~a -dc < ~a | ~a xv
240
5d6792f0
MW
241# Use the bootstrap guile to create its own wrapper to set the load path.
242GUILE_SYSTEM_PATH=$out/share/guile/2.0 \
243GUILE_SYSTEM_COMPILED_PATH=$out/lib/guile/2.0/ccache \
244$out/bin/guile -c ~s $out ~a
245
0d5a559f
LC
246# Sanity check.
247$out/bin/guile --version~%"
5d6792f0
MW
248 mkdir xz guile tar
249 (format #f "~s" make-guile-wrapper)
250 bash)
251 (list mkdir xz guile tar bash))))
0d5a559f
LC
252 (derivation store name
253 bash `(,builder)
254 #:system system
255 #:inputs `((,bash) (,builder)))))
256
257(define* (make-raw-bag name
d3d337d2
LC
258 #:key source inputs native-inputs outputs
259 system target)
0d5a559f
LC
260 (bag
261 (name name)
d3d337d2 262 (system system)
0d5a559f
LC
263 (build-inputs inputs)
264 (build raw-build)))
265
18633d4f
LC
266(define %bootstrap-guile
267 ;; The Guile used to run the build scripts of the initial derivations.
268 ;; It is just unpacked from a tarball containing a pre-built binary.
269 ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
270 ;;
271 ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
272 ;; support (for /etc/services).
273 (let ((raw (build-system
0d5a559f
LC
274 (name 'raw)
275 (description "Raw build system with direct store access")
276 (lower make-raw-bag))))
18633d4f
LC
277 (package
278 (name "guile-bootstrap")
279 (version "2.0")
280 (source #f)
281 (build-system raw)
282 (synopsis "Bootstrap Guile")
283 (description "Pre-built Guile for bootstrapping purposes.")
284 (home-page #f)
4a44e743 285 (license lgpl3+))))
18633d4f 286
04732c37 287(define %bootstrap-base-urls
18633d4f 288 ;; This is where the initial binaries come from.
04732c37
LC
289 '("http://alpha.gnu.org/gnu/guix/bootstrap"
290 "http://www.fdn.fr/~lcourtes/software/guix/packages"))
18633d4f
LC
291
292(define %bootstrap-coreutils&co
293 (package-from-tarball "bootstrap-binaries"
294 (lambda (system)
295 (origin
87f5d366 296 (method url-fetch)
04732c37 297 (uri (map (cut string-append <> "/" system
aa1e1947
MW
298 (match system
299 ("armhf-linux"
300 "/20150101/static-binaries.tar.xz")
301 (_
302 "/20131110/static-binaries.tar.xz")))
04732c37 303 %bootstrap-base-urls))
18633d4f
LC
304 (sha256
305 (match system
306 ("x86_64-linux"
307 (base32
06213498 308 "0c533p9dhczzcsa1117gmfq3pc8w362g4mx84ik36srpr7cx2bg4"))
18633d4f
LC
309 ("i686-linux"
310 (base32
06213498 311 "0s5b3jb315n13m1k8095l0a5hfrsz8g0fv1b6riyc5hnxqyphlak"))
aa1e1947
MW
312 ("armhf-linux"
313 (base32
314 "0gf0fn2kbpxkjixkmx5f4z6hv6qpmgixl69zgg74dbsfdfj8jdv5"))
f57ff219
MW
315 ("mips64el-linux"
316 (base32
06213498 317 "072y4wyfsj1bs80r6vbybbafy8ya4vfy7qj25dklwk97m6g71753"))))))
84cbe39c
MW
318 "fgrep" ; the program to test
319 "Bootstrap binaries of Coreutils, Awk, etc."
320 #:snippet
321 '(let ((path (list (string-append (getcwd) "/bin"))))
322 (chmod "bin" #o755)
323 (patch-shebang "bin/egrep" path)
324 (patch-shebang "bin/fgrep" path)
325 (chmod "bin" #o555)
326 #t)))
18633d4f
LC
327
328(define %bootstrap-binutils
329 (package-from-tarball "binutils-bootstrap"
330 (lambda (system)
331 (origin
87f5d366 332 (method url-fetch)
04732c37 333 (uri (map (cut string-append <> "/" system
aa1e1947
MW
334 (match system
335 ("armhf-linux"
336 "/20150101/binutils-2.25.tar.xz")
337 (_
338 "/20131110/binutils-2.23.2.tar.xz")))
04732c37 339 %bootstrap-base-urls))
18633d4f
LC
340 (sha256
341 (match system
342 ("x86_64-linux"
343 (base32
06213498 344 "1j5yivz7zkjqfsfmxzrrrffwyayjqyfxgpi89df0w4qziqs2dg20"))
18633d4f
LC
345 ("i686-linux"
346 (base32
06213498 347 "14jgwf9gscd7l2pnz610b1zia06dvcm2qyzvni31b8zpgmcai2v9"))
aa1e1947
MW
348 ("armhf-linux"
349 (base32
350 "1v7dj6bzn6m36f20gw31l99xaabq4xrhrx3gwqkhhig0mdlmr69q"))
f57ff219
MW
351 ("mips64el-linux"
352 (base32
06213498 353 "1x8kkhcxmfyzg1ddpz2pxs6fbdl6412r7x0nzbmi5n7mj8zw2gy7"))))))
18633d4f
LC
354 "ld" ; the program to test
355 "Bootstrap binaries of the GNU Binutils"))
356
357(define %bootstrap-glibc
358 ;; The initial libc.
359 (package
360 (name "glibc-bootstrap")
361 (version "0")
362 (source #f)
363 (build-system trivial-build-system)
364 (arguments
365 `(#:guile ,%bootstrap-guile
366 #:modules ((guix build utils))
367 #:builder
368 (let ((out (assoc-ref %outputs "out"))
369 (tar (assoc-ref %build-inputs "tar"))
370 (xz (assoc-ref %build-inputs "xz"))
371 (tarball (assoc-ref %build-inputs "tarball")))
372 (use-modules (guix build utils))
373
374 (mkdir out)
375 (copy-file tarball "binaries.tar.xz")
376 (system* xz "-d" "binaries.tar.xz")
377 (let ((builddir (getcwd)))
378 (with-directory-excursion out
379 (system* tar "xvf"
380 (string-append builddir
381 "/binaries.tar"))
382 (chmod "lib" #o755)
383
384 ;; Patch libc.so so it refers to the right path.
385 (substitute* "lib/libc.so"
386 (("/[^ ]+/lib/(libc|ld)" _ prefix)
387 (string-append out "/lib/" prefix))))))))
388 (inputs
dd6b9a37
LC
389 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
390 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
391 ("tarball" ,(bootstrap-origin
392 (origin
393 (method url-fetch)
394 (uri (map (cut string-append <> "/" (%current-system)
aa1e1947
MW
395 (match (%current-system)
396 ("armhf-linux"
397 "/20150101/glibc-2.20.tar.xz")
398 (_
399 "/20131110/glibc-2.18.tar.xz")))
dd6b9a37
LC
400 %bootstrap-base-urls))
401 (sha256
402 (match (%current-system)
403 ("x86_64-linux"
404 (base32
06213498 405 "0jlqrgavvnplj1b083s20jj9iddr4lzfvwybw5xrcis9spbfzk7v"))
dd6b9a37
LC
406 ("i686-linux"
407 (base32
06213498 408 "1hgrccw1zqdc7lvgivwa54d9l3zsim5pqm0dykxg0z522h6gr05w"))
aa1e1947
MW
409 ("armhf-linux"
410 (base32
411 "18cmgvpllqfpn6khsmivqib7ys8ymnq0hdzi3qp24prik0ykz8gn"))
f57ff219
MW
412 ("mips64el-linux"
413 (base32
06213498 414 "0k97a3whzx3apsi9n2cbsrr79ad6lh00klxph9hw4fqyp1abkdsg")))))))))
18633d4f 415 (synopsis "Bootstrap binaries and headers of the GNU C Library")
7de1f103 416 (description synopsis)
1fb78cb2
LC
417 (home-page #f)
418 (license lgpl2.1+)))
18633d4f
LC
419
420(define %bootstrap-gcc
421 ;; The initial GCC. Uses binaries from a tarball typically built by
422 ;; %GCC-BOOTSTRAP-TARBALL.
423 (package
424 (name "gcc-bootstrap")
425 (version "0")
426 (source #f)
427 (build-system trivial-build-system)
428 (arguments
21c203a5
LC
429 `(#:guile ,%bootstrap-guile
430 #:modules ((guix build utils))
431 #:builder
432 (let ((out (assoc-ref %outputs "out"))
433 (tar (assoc-ref %build-inputs "tar"))
434 (xz (assoc-ref %build-inputs "xz"))
435 (bash (assoc-ref %build-inputs "bash"))
436 (libc (assoc-ref %build-inputs "libc"))
437 (tarball (assoc-ref %build-inputs "tarball")))
438 (use-modules (guix build utils)
439 (ice-9 popen))
18633d4f 440
21c203a5
LC
441 (mkdir out)
442 (copy-file tarball "binaries.tar.xz")
443 (system* xz "-d" "binaries.tar.xz")
444 (let ((builddir (getcwd))
445 (bindir (string-append out "/bin")))
446 (with-directory-excursion out
447 (system* tar "xvf"
448 (string-append builddir "/binaries.tar")))
18633d4f 449
21c203a5
LC
450 (with-directory-excursion bindir
451 (chmod "." #o755)
452 (rename-file "gcc" ".gcc-wrapped")
453 (call-with-output-file "gcc"
454 (lambda (p)
455 (format p "#!~a
18633d4f
LC
456exec ~a/bin/.gcc-wrapped -B~a/lib \
457 -Wl,-rpath -Wl,~a/lib \
458 -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
21c203a5
LC
459 bash
460 out libc libc libc
461 ,(glibc-dynamic-linker))))
18633d4f 462
21c203a5 463 (chmod "gcc" #o555))))))
18633d4f 464 (inputs
dd6b9a37
LC
465 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
466 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
467 ("bash" ,(search-bootstrap-binary "bash" (%current-system)))
18633d4f 468 ("libc" ,%bootstrap-glibc)
dd6b9a37
LC
469 ("tarball" ,(bootstrap-origin
470 (origin
471 (method url-fetch)
472 (uri (map (cut string-append <> "/" (%current-system)
aa1e1947
MW
473 (match (%current-system)
474 ("armhf-linux"
475 "/20150101/gcc-4.8.4.tar.xz")
476 (_
477 "/20131110/gcc-4.8.2.tar.xz")))
dd6b9a37
LC
478 %bootstrap-base-urls))
479 (sha256
480 (match (%current-system)
481 ("x86_64-linux"
482 (base32
06213498 483 "17ga4m6195n4fnbzdkmik834znkhs53nkypp6557pl1ps7dgqbls"))
dd6b9a37
LC
484 ("i686-linux"
485 (base32
06213498 486 "150c1arrf2k8vfy6dpxh59vcgs4p1bgiz2av5m19dynpks7rjnyw"))
aa1e1947
MW
487 ("armhf-linux"
488 (base32
489 "0ghz825yzp43fxw53kd6afm8nkz16f7dxi9xi40bfwc8x3nbbr8v"))
f57ff219
MW
490 ("mips64el-linux"
491 (base32
06213498 492 "1m5miqkyng45l745n0sfafdpjkqv9225xf44jqkygwsipj2cv9ks")))))))))
a18eda27
LC
493 (native-search-paths
494 (list (search-path-specification
495 (variable "CPATH")
af070955 496 (files '("include")))
a18eda27
LC
497 (search-path-specification
498 (variable "LIBRARY_PATH")
af070955 499 (files '("lib" "lib64")))))
18633d4f 500 (synopsis "Bootstrap binaries of the GNU Compiler Collection")
7de1f103 501 (description synopsis)
1fb78cb2
LC
502 (home-page #f)
503 (license gpl3+)))
18633d4f
LC
504
505(define %bootstrap-inputs
506 ;; The initial, pre-built inputs. From now on, we can start building our
507 ;; own packages.
508 `(("libc" ,%bootstrap-glibc)
509 ("gcc" ,%bootstrap-gcc)
510 ("binutils" ,%bootstrap-binutils)
9d1d434c
LC
511 ("coreutils&co" ,%bootstrap-coreutils&co)
512
513 ;; In gnu-build-system.scm, we rely on the availability of Bash.
514 ("bash" ,%bootstrap-coreutils&co)))
18633d4f
LC
515
516;;; bootstrap.scm ends here