projects/guix·blob v0.1 · refs

160 lines · 5.6 KiB

1-*- mode: org; coding: utf-8; -*-
2
3#+TITLE: Hacking GNU Guix and Its Incredible Distro
4
5Copyright © 2012, 2013 Ludovic Courtès <[email protected]>
6
7 Copying and distribution of this file, with or without modification,
8 are permitted in any medium without royalty provided the copyright
9 notice and this notice are preserved.
10
11
12* Running Guix before it is installed
13
14Command-line tools can be used even if you have not run "make install".
15To do that, prefix each command with ‘./pre-inst-env’, as in:
16
17 ./pre-inst-env guix-build --help
18
19Similarly, for a Guile session using the Guix modules:
20
21 ./pre-inst-env guile -c '(use-modules (guix utils)) (pk (%current-system))'
22
23The ‘pre-inst-env’ script sets up all the environment variables
24necessary to support this.
25
26* Adding new packages
27
28Package recipes in Guix look like this:
29
30#+BEGIN_SRC scheme
31 (package
32 (name "nettle")
33 (version "2.5")
34 (source
35 (origin
36 (method url-fetch)
37 (uri (string-append "mirror://gnu/nettle/nettle-"
38 version ".tar.gz"))
39 (sha256
40 (base32
41 "0wicr7amx01l03rm0pzgr1qvw3f9blaw17vjsy1301dh13ll58aa"))))
42 (build-system gnu-build-system)
43 (inputs `(("m4" ,m4)))
44 (propagated-inputs `(("gmp" ,gmp)))
45 (home-page
46 "http://www.lysator.liu.se/~nisse/nettle/")
47 (synopsis "GNU Nettle, a cryptographic library")
48 (description
49 "Nettle is a cryptographic library...")
50 (license gpl2+))
51#+END_SRC
52
53Such a recipe can be written by hand, and then tested by running
54‘./pre-inst-env guix-build nettle’.
55
56When writing the recipe, the base32-encoded SHA256 hash of the source
57code tarball, which can be seen in the example above, can be obtained by
58running:
59
60 guix-download http://ftp.gnu.org/gnu/nettle/nettle-2.5.tar.gz
61
62Alternatively, it is possible to semi-automatically import recipes from
63the [[http://nixos.org/nixpkgs/][Nixpkgs]] software distribution using this command:
64
65 guix-import /path/to/nixpkgs/checkout nettle
66
67The command automatically fetches and converts to Guix the “Nix
68expression” of Nettle.
69
70* Porting the Guix distro on a new platform
71
72** Introduction
73
74Unlike Make or similar build tools, Guix requires absolutely /all/ the
75dependencies of a build process to be specified.
76
77For a user-land software distribution, that means that the process that
78builds GCC (then used to build all other programs) must itself be
79specified; and the process to build the C library to build that GCC; and
80the process to build the GCC to build that library; and... See the
81problem? Chicken-and-egg.
82
83To break that cycle, the distro starts from a set of pre-built
84binaries–usually referred to as “bootstrap binaries.” These include
85statically-linked versions of Guile, GCC, Coreutils, Make, Grep, sed,
86etc., and the GNU C Library.
87
88This section describes how to build those bootstrap binaries when
89porting to a new platform.
90
91** When the platform is supported by Nixpkgs
92
93In that case, the easiest thing is to bootstrap the distro using
94binaries from Nixpkgs.
95
96To do that, you need to comment out the definitions of
97‘%bootstrap-guile’ and ‘%bootstrap-inputs’ in distro/packages/bootstrap.scm
98to force the use of Nixpkgs derivations. For instance, when porting to
99‘i686-linux’, you should redefine these variables along these lines:
100
101#+BEGIN_SRC scheme
102 (define %bootstrap-guile
103 (nixpkgs-derivation "guile" "i686-linux"))
104
105 (define %bootstrap-inputs
106 (compile-time-value
107 `(("libc" ,(nixpkgs-derivation "glibc" "i686-linux"))
108 ,@(map (lambda (name)
109 (list name (nixpkgs-derivation name "i686-linux")))
110 '("gnutar" "gzip" "bzip2" "xz" "patch"
111 "coreutils" "gnused" "gnugrep" "bash"
112 "gawk" ; used by `config.status'
113 "gcc" "binutils")))))
114#+END_SRC
115
116That should allow the distro to be bootstrapped.
117
118Then, the tarballs containing the initial binaries of Guile, Coreutils,
119GCC, libc, etc. need to be built. To that end, run the following
120commands:
121
122#+BEGIN_SRC sh
123 ./pre-inst-env guix-build \
124 -e '(@ (distro packages make-bootstrap) bootstrap-tarballs)' \
125 --system=i686-linux
126
127#+END_SRC
128
129These should build tarballs containing statically-linked tools usable on
130that system.
131
132In the source tree, you need to install binaries for ‘mkdir’, ‘bash’,
133‘tar’, and ‘xz’ under ‘distro/packages/bootstrap/i686-linux’. These
134binaries can be extracted from the static-binaries tarball built above.
135
136A rule for ‘distro/packages/bootstrap/i686-linux/guile-2.0.7.tar.xz’
137needs to be added in ‘Makefile.am’, with the appropriate hexadecimal
138vrepresentation of its SHA256 hash.
139
140You may then revert your changes to ‘bootstrap.scm’. For the variables
141‘%bootstrap-coreutils&co’, ‘%bootstrap-binutils’, ‘%bootstrap-glibc’,
142and ‘%bootstrap-gcc’, the expected SHA256 of the corresponding tarballs
143for ‘i686-linux’ (built above) must be added.
144
145This should be enough to bootstrap the distro without resorting to
146Nixpkgs.
147
148** When the platform is *not* supported by Nixpkgs
149
150In that case, the bootstrap binaries should be built using whatever
151tools are available on the target platform. That is, the tarballs and
152binaries show above must first be built manually, using the available
153tools.
154
155They should have the same properties as those built by the Guix recipes
156shown above. For example, all the binaries (except for glibc) must be
157statically-linked; the bootstrap Guile must be relocatable (see patch in
158the Guix distro); the static-binaries tarball must contain the same
159programs (Coreutils, Grep, sed, Awk, etc.); and so on.
160