1 ;;; Guix --- Nix package management from Guile. -*- coding: utf-8 -*-
2 ;;; Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of Guix.
6 ;;; 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 ;;; 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 Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (distro packages bootstrap)
20 #:use-module (guix licenses)
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 (let ((orig-method (origin-method source)))
68 (origin (inherit source)
69 (method (cond ((eq? orig-method url-fetch)
71 (else orig-method))))))
73 (define (package-from-tarball name* source* program-to-test description*)
74 "Return a package that correspond to the extraction of SOURCE*.
75 PROGRAM-TO-TEST is a program to run after extraction of SOURCE*, to
76 check whether everything is alright."
81 (build-system trivial-build-system)
83 `(#:guile ,%bootstrap-guile
84 #:modules ((guix build utils))
86 (let ((out (assoc-ref %outputs "out"))
87 (tar (assoc-ref %build-inputs "tar"))
88 (xz (assoc-ref %build-inputs "xz"))
89 (tarball (assoc-ref %build-inputs "tarball")))
90 (use-modules (guix build utils))
93 (copy-file tarball "binaries.tar.xz")
94 (system* xz "-d" "binaries.tar.xz")
95 (let ((builddir (getcwd)))
96 (with-directory-excursion out
97 (and (zero? (system* tar "xvf"
98 (string-append builddir "/binaries.tar")))
99 (zero? (system* (string-append "bin/" ,program-to-test)
102 `(("tar" ,(lambda (system)
103 (search-bootstrap-binary "tar" system)))
104 ("xz" ,(lambda (system)
105 (search-bootstrap-binary "xz" system)))
106 ("tarball" ,(lambda (system)
107 (bootstrap-origin (source* system))))))
108 (synopsis description*)
112 (define package-with-bootstrap-guile
115 "Return a variant of P such that all its origins are fetched with
117 (define rewritten-input
119 ((name (? origin? o))
120 `(,name ,(bootstrap-origin o)))
121 ((name (? package? p) sub-drvs ...)
122 `(,name ,(package-with-bootstrap-guile p) ,@sub-drvs))
126 (source (match (package-source p)
127 ((? origin? o) (bootstrap-origin o))
129 (inputs (map rewritten-input
131 (native-inputs (map rewritten-input
132 (package-native-inputs p)))
133 (propagated-inputs (map rewritten-input
134 (package-propagated-inputs p)))))))
136 (define (glibc-dynamic-linker system)
137 "Return the name of Glibc's dynamic linker for SYSTEM."
138 (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2")
139 ((string=? system "i686-linux") "/lib/ld-linux.so.2")
140 (else (error "dynamic linker name not known for this system"
145 ;;; Bootstrap packages.
148 (define %bootstrap-guile
149 ;; The Guile used to run the build scripts of the initial derivations.
150 ;; It is just unpacked from a tarball containing a pre-built binary.
151 ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
153 ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
154 ;; support (for /etc/services).
155 (let ((raw (build-system
157 (description "Raw build system with direct store access")
158 (build (lambda* (store name source inputs #:key outputs system)
159 (define (->store file)
160 (add-to-store store file #t #t "sha256"
161 (or (search-bootstrap-binary file
163 (error "bootstrap binary not found"
166 (let* ((tar (->store "tar"))
168 (mkdir (->store "mkdir"))
169 (bash (->store "bash"))
170 (guile (->store "guile-bootstrap-2.0.6.tar.xz"))
172 (add-text-to-store store
173 "build-bootstrap-guile.sh"
175 echo \"unpacking bootstrap Guile to '$out'...\"
181 $out/bin/guile --version~%"
183 (list mkdir xz guile tar))))
184 (derivation store name system
186 `((,bash) (,builder)))))))))
188 (name "guile-bootstrap")
192 (synopsis "Bootstrap Guile")
193 (description "Pre-built Guile for bootstrapping purposes.")
197 (define %bootstrap-base-url
198 ;; This is where the initial binaries come from.
199 "http://www.fdn.fr/~lcourtes/software/guix/packages")
201 (define %bootstrap-coreutils&co
202 (package-from-tarball "bootstrap-binaries"
207 %bootstrap-base-url "/"
208 system "/20121115/static-binaries.tar.xz"))
213 "0azisn8l2b3cvgni9k0ahzsxs5cxrj0hmf38zgpq3k6pggk3zbfm"))
216 "16v60frbh0naccanwxcxz0z3444dd8salbg8p7cp7vwz8245nhfk"))))))
217 "true" ; the program to test
218 "Bootstrap binaries of Coreutils, Awk, etc."))
220 (define %bootstrap-binutils
221 (package-from-tarball "binutils-bootstrap"
226 %bootstrap-base-url "/"
227 system "/20121115/binutils-2.22.tar.xz"))
232 "0ms6i035v40n7mhi91n4b8ivwv2qni3mcd5dj9sj9qmvgqb50r84"))
235 "193x62ach4l4x16rbzglrqa1d0a825z2as6czdiv9xjiizmcr0ad"))))))
236 "ld" ; the program to test
237 "Bootstrap binaries of the GNU Binutils"))
239 (define %bootstrap-glibc
242 (name "glibc-bootstrap")
245 (build-system trivial-build-system)
247 `(#:guile ,%bootstrap-guile
248 #:modules ((guix build utils))
250 (let ((out (assoc-ref %outputs "out"))
251 (tar (assoc-ref %build-inputs "tar"))
252 (xz (assoc-ref %build-inputs "xz"))
253 (tarball (assoc-ref %build-inputs "tarball")))
254 (use-modules (guix build utils))
257 (copy-file tarball "binaries.tar.xz")
258 (system* xz "-d" "binaries.tar.xz")
259 (let ((builddir (getcwd)))
260 (with-directory-excursion out
262 (string-append builddir
266 ;; Patch libc.so so it refers to the right path.
267 (substitute* "lib/libc.so"
268 (("/[^ ]+/lib/(libc|ld)" _ prefix)
269 (string-append out "/lib/" prefix))))))))
271 `(("tar" ,(lambda (system)
272 (search-bootstrap-binary "tar" system)))
273 ("xz" ,(lambda (system)
274 (search-bootstrap-binary "xz" system)))
275 ("tarball" ,(lambda (system)
279 (uri (string-append %bootstrap-base-url "/" system
280 "/20121115/glibc-2.16.0.tar.xz"))
285 "1cz587p3scrrx0zgqnmp4nnfj0vvf01zdqdgkz445dnbfh64nl0v"))
288 "0vzybz1577vflm0p0zg1slqj32carj5102b45k7iskkj46viy14z"))))))))))
289 (synopsis "Bootstrap binaries and headers of the GNU C Library")
293 (define %bootstrap-gcc
294 ;; The initial GCC. Uses binaries from a tarball typically built by
295 ;; %GCC-BOOTSTRAP-TARBALL.
297 (name "gcc-bootstrap")
300 (build-system trivial-build-system)
303 `(#:guile ,%bootstrap-guile
304 #:modules ((guix build utils))
306 (let ((out (assoc-ref %outputs "out"))
307 (tar (assoc-ref %build-inputs "tar"))
308 (xz (assoc-ref %build-inputs "xz"))
309 (bash (assoc-ref %build-inputs "bash"))
310 (libc (assoc-ref %build-inputs "libc"))
311 (tarball (assoc-ref %build-inputs "tarball")))
312 (use-modules (guix build utils)
316 (copy-file tarball "binaries.tar.xz")
317 (system* xz "-d" "binaries.tar.xz")
318 (let ((builddir (getcwd))
319 (bindir (string-append out "/bin")))
320 (with-directory-excursion out
322 (string-append builddir "/binaries.tar")))
324 (with-directory-excursion bindir
326 (rename-file "gcc" ".gcc-wrapped")
327 (call-with-output-file "gcc"
330 exec ~a/bin/.gcc-wrapped -B~a/lib \
331 -Wl,-rpath -Wl,~a/lib \
332 -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
335 ,(glibc-dynamic-linker system))))
337 (chmod "gcc" #o555)))))))
339 `(("tar" ,(lambda (system)
340 (search-bootstrap-binary "tar" system)))
341 ("xz" ,(lambda (system)
342 (search-bootstrap-binary "xz" system)))
343 ("bash" ,(lambda (system)
344 (search-bootstrap-binary "bash" system)))
345 ("libc" ,%bootstrap-glibc)
346 ("tarball" ,(lambda (system)
350 (uri (string-append %bootstrap-base-url "/" system
351 "/20121115/gcc-4.7.2.tar.xz"))
356 "0fg65i2qcym8ls5ig3g1cc9ida5cxwwsd6zi95xi1d8dnfrja4zz"))
359 "01hlz98qmc8yhqrxqajpg5kbkhpvqq6wjnbfvplys32n895avzxg"))))))))))
360 (synopsis "Bootstrap binaries of the GNU Compiler Collection")
364 (define %bootstrap-inputs
365 ;; The initial, pre-built inputs. From now on, we can start building our
367 `(("libc" ,%bootstrap-glibc)
368 ("gcc" ,%bootstrap-gcc)
369 ("binutils" ,%bootstrap-binutils)
370 ("coreutils&co" ,%bootstrap-coreutils&co)
372 ;; In gnu-build-system.scm, we rely on the availability of Bash.
373 ("bash" ,%bootstrap-coreutils&co)))
375 ;;; bootstrap.scm ends here