1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu packages bootstrap)
20 #:use-module (guix licenses)
21 #:use-module (gnu packages)
22 #:use-module (guix packages)
23 #:use-module (guix download)
24 #:use-module (guix build-system)
25 #:use-module (guix build-system gnu)
26 #:use-module (guix build-system trivial)
27 #:use-module ((guix store) #:select (add-to-store add-text-to-store))
28 #:use-module ((guix derivations) #:select (derivation))
29 #:use-module (guix utils)
30 #:use-module (srfi srfi-1)
31 #:use-module (srfi srfi-26)
32 #:use-module (ice-9 match)
33 #:export (bootstrap-origin
34 package-with-bootstrap-guile
38 %bootstrap-coreutils&co
46 ;;; Pre-built packages that are used to bootstrap the
47 ;;; distribution--i.e., to build all the core packages from scratch.
54 ;;; Helper procedures.
57 (define (bootstrap-origin source)
58 "Return a variant of SOURCE, an <origin> instance, whose method uses
59 %BOOTSTRAP-GUILE to do its job."
61 (lambda* (store url hash-algo hash
62 #:optional name #:key system)
63 (fetch store url hash-algo hash
64 #:guile %bootstrap-guile
67 (define %bootstrap-patch-inputs
68 ;; Packages used when an <origin> has a non-empty 'patches' field.
69 `(("tar" ,%bootstrap-coreutils&co)
70 ("xz" ,%bootstrap-coreutils&co)
71 ("bzip2" ,%bootstrap-coreutils&co)
72 ("gzip" ,%bootstrap-coreutils&co)
73 ("patch" ,%bootstrap-coreutils&co)))
75 (let ((orig-method (origin-method source)))
76 (origin (inherit source)
77 (method (cond ((eq? orig-method url-fetch)
80 (patch-guile %bootstrap-guile)
81 (patch-inputs %bootstrap-patch-inputs))))
83 (define (package-from-tarball name source program-to-test description)
84 "Return a package that correspond to the extraction of SOURCE.
85 PROGRAM-TO-TEST is a program to run after extraction of SOURCE, to
86 check whether everything is alright."
90 (build-system trivial-build-system)
92 `(#:guile ,%bootstrap-guile
93 #:modules ((guix build utils))
95 (let ((out (assoc-ref %outputs "out"))
96 (tar (assoc-ref %build-inputs "tar"))
97 (xz (assoc-ref %build-inputs "xz"))
98 (tarball (assoc-ref %build-inputs "tarball")))
99 (use-modules (guix build utils))
102 (copy-file tarball "binaries.tar.xz")
103 (system* xz "-d" "binaries.tar.xz")
104 (let ((builddir (getcwd)))
105 (with-directory-excursion out
106 (and (zero? (system* tar "xvf"
107 (string-append builddir "/binaries.tar")))
108 (zero? (system* (string-append "bin/" ,program-to-test)
111 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
112 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
113 ("tarball" ,(bootstrap-origin (source (%current-system))))))
115 (synopsis description)
120 (define package-with-bootstrap-guile
123 "Return a variant of P such that all its origins are fetched with
125 (define rewritten-input
127 ((name (? origin? o))
128 `(,name ,(bootstrap-origin o)))
129 ((name (? package? p) sub-drvs ...)
130 `(,name ,(package-with-bootstrap-guile p) ,@sub-drvs))
134 (source (match (package-source p)
135 ((? origin? o) (bootstrap-origin o))
137 (inputs (map rewritten-input
139 (native-inputs (map rewritten-input
140 (package-native-inputs p)))
141 (propagated-inputs (map rewritten-input
142 (package-propagated-inputs p)))))))
144 (define* (glibc-dynamic-linker
145 #:optional (system (or (and=> (%current-target-system)
146 gnu-triplet->nix-system)
148 "Return the name of Glibc's dynamic linker for SYSTEM."
149 (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2")
150 ((string=? system "i686-linux") "/lib/ld-linux.so.2")
151 ((string=? system "mips64el-linux") "/lib/ld.so.1")
152 (else (error "dynamic linker name not known for this system"
157 ;;; Bootstrap packages.
160 (define %bootstrap-guile
161 ;; The Guile used to run the build scripts of the initial derivations.
162 ;; It is just unpacked from a tarball containing a pre-built binary.
163 ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
165 ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
166 ;; support (for /etc/services).
167 (let ((raw (build-system
169 (description "Raw build system with direct store access")
170 (build (lambda* (store name source inputs
171 #:key outputs system search-paths)
172 (define (->store file)
173 (add-to-store store file #t "sha256"
174 (or (search-bootstrap-binary file
176 (error "bootstrap binary not found"
179 (let* ((tar (->store "tar"))
181 (mkdir (->store "mkdir"))
182 (bash (->store "bash"))
183 (guile (->store "guile-2.0.9.tar.xz"))
185 (add-text-to-store store
186 "build-bootstrap-guile.sh"
188 echo \"unpacking bootstrap Guile to '$out'...\"
194 $out/bin/guile --version~%"
196 (list mkdir xz guile tar))))
197 (derivation store name
200 #:inputs `((,bash) (,builder)))))))))
202 (name "guile-bootstrap")
206 (synopsis "Bootstrap Guile")
207 (description "Pre-built Guile for bootstrapping purposes.")
211 (define %bootstrap-base-urls
212 ;; This is where the initial binaries come from.
213 '("http://alpha.gnu.org/gnu/guix/bootstrap"
214 "http://www.fdn.fr/~lcourtes/software/guix/packages"))
216 (define %bootstrap-coreutils&co
217 (package-from-tarball "bootstrap-binaries"
221 (uri (map (cut string-append <> "/" system
222 "/20131110/static-binaries.tar.xz")
223 %bootstrap-base-urls))
228 "0c533p9dhczzcsa1117gmfq3pc8w362g4mx84ik36srpr7cx2bg4"))
231 "0s5b3jb315n13m1k8095l0a5hfrsz8g0fv1b6riyc5hnxqyphlak"))
234 "072y4wyfsj1bs80r6vbybbafy8ya4vfy7qj25dklwk97m6g71753"))))))
235 "true" ; the program to test
236 "Bootstrap binaries of Coreutils, Awk, etc."))
238 (define %bootstrap-binutils
239 (package-from-tarball "binutils-bootstrap"
243 (uri (map (cut string-append <> "/" system
244 "/20131110/binutils-2.23.2.tar.xz")
245 %bootstrap-base-urls))
250 "1j5yivz7zkjqfsfmxzrrrffwyayjqyfxgpi89df0w4qziqs2dg20"))
253 "14jgwf9gscd7l2pnz610b1zia06dvcm2qyzvni31b8zpgmcai2v9"))
256 "1x8kkhcxmfyzg1ddpz2pxs6fbdl6412r7x0nzbmi5n7mj8zw2gy7"))))))
257 "ld" ; the program to test
258 "Bootstrap binaries of the GNU Binutils"))
260 (define %bootstrap-glibc
263 (name "glibc-bootstrap")
266 (build-system trivial-build-system)
268 `(#:guile ,%bootstrap-guile
269 #:modules ((guix build utils))
271 (let ((out (assoc-ref %outputs "out"))
272 (tar (assoc-ref %build-inputs "tar"))
273 (xz (assoc-ref %build-inputs "xz"))
274 (tarball (assoc-ref %build-inputs "tarball")))
275 (use-modules (guix build utils))
278 (copy-file tarball "binaries.tar.xz")
279 (system* xz "-d" "binaries.tar.xz")
280 (let ((builddir (getcwd)))
281 (with-directory-excursion out
283 (string-append builddir
287 ;; Patch libc.so so it refers to the right path.
288 (substitute* "lib/libc.so"
289 (("/[^ ]+/lib/(libc|ld)" _ prefix)
290 (string-append out "/lib/" prefix))))))))
292 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
293 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
294 ("tarball" ,(bootstrap-origin
297 (uri (map (cut string-append <> "/" (%current-system)
298 "/20131110/glibc-2.18.tar.xz")
299 %bootstrap-base-urls))
301 (match (%current-system)
304 "0jlqrgavvnplj1b083s20jj9iddr4lzfvwybw5xrcis9spbfzk7v"))
307 "1hgrccw1zqdc7lvgivwa54d9l3zsim5pqm0dykxg0z522h6gr05w"))
310 "0k97a3whzx3apsi9n2cbsrr79ad6lh00klxph9hw4fqyp1abkdsg")))))))))
311 (synopsis "Bootstrap binaries and headers of the GNU C Library")
316 (define %bootstrap-gcc
317 ;; The initial GCC. Uses binaries from a tarball typically built by
318 ;; %GCC-BOOTSTRAP-TARBALL.
320 (name "gcc-bootstrap")
323 (build-system trivial-build-system)
325 `(#:guile ,%bootstrap-guile
326 #:modules ((guix build utils))
328 (let ((out (assoc-ref %outputs "out"))
329 (tar (assoc-ref %build-inputs "tar"))
330 (xz (assoc-ref %build-inputs "xz"))
331 (bash (assoc-ref %build-inputs "bash"))
332 (libc (assoc-ref %build-inputs "libc"))
333 (tarball (assoc-ref %build-inputs "tarball")))
334 (use-modules (guix build utils)
338 (copy-file tarball "binaries.tar.xz")
339 (system* xz "-d" "binaries.tar.xz")
340 (let ((builddir (getcwd))
341 (bindir (string-append out "/bin")))
342 (with-directory-excursion out
344 (string-append builddir "/binaries.tar")))
346 (with-directory-excursion bindir
348 (rename-file "gcc" ".gcc-wrapped")
349 (call-with-output-file "gcc"
352 exec ~a/bin/.gcc-wrapped -B~a/lib \
353 -Wl,-rpath -Wl,~a/lib \
354 -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
357 ,(glibc-dynamic-linker))))
359 (chmod "gcc" #o555))))))
361 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
362 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
363 ("bash" ,(search-bootstrap-binary "bash" (%current-system)))
364 ("libc" ,%bootstrap-glibc)
365 ("tarball" ,(bootstrap-origin
368 (uri (map (cut string-append <> "/" (%current-system)
369 "/20131110/gcc-4.8.2.tar.xz")
370 %bootstrap-base-urls))
372 (match (%current-system)
375 "17ga4m6195n4fnbzdkmik834znkhs53nkypp6557pl1ps7dgqbls"))
378 "150c1arrf2k8vfy6dpxh59vcgs4p1bgiz2av5m19dynpks7rjnyw"))
381 "1m5miqkyng45l745n0sfafdpjkqv9225xf44jqkygwsipj2cv9ks")))))))))
383 (list (search-path-specification
385 (directories '("include")))
386 (search-path-specification
387 (variable "LIBRARY_PATH")
388 (directories '("lib" "lib64")))))
389 (synopsis "Bootstrap binaries of the GNU Compiler Collection")
394 (define %bootstrap-inputs
395 ;; The initial, pre-built inputs. From now on, we can start building our
397 `(("libc" ,%bootstrap-glibc)
398 ("gcc" ,%bootstrap-gcc)
399 ("binutils" ,%bootstrap-binutils)
400 ("coreutils&co" ,%bootstrap-coreutils&co)
402 ;; In gnu-build-system.scm, we rely on the availability of Bash.
403 ("bash" ,%bootstrap-coreutils&co)))
405 ;;; bootstrap.scm ends here