gnu: Add mpg321.
[jackhill/guix/guix.git] / HACKING
CommitLineData
450ccdc3
LC
1-*- mode: org; coding: utf-8; -*-
2
08ba7ff3 3#+TITLE: Hacking GNU Guix and Its Incredible Distro
450ccdc3 4
9149f1a0 5Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
450ccdc3
LC
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
08ba7ff3
LC
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
9bf3c1a7 17 ./pre-inst-env guix build --help
08ba7ff3
LC
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
c6dbd505
LC
26* The Perfect Setup
27
28The Perfect Setup to hack on Guix is basically the perfect setup used
29for Guile hacking (info "(guile) Using Guile in Emacs"). First, you
30need more than an editor, you need [[http://www.gnu.org/software/emacs][Emacs]], empowered by the wonderful
31[[http://nongnu.org/geiser/][Geiser]].
32
33Geiser allows for interactive and incremental development from within
34Emacs: code compilation and evaluation from within buffers, access to
35on-line documentation (docstrings), context-sensitive completion, M-. to
36jump to an object definition, a REPL to try out your code, and more.
37
38To actually edit the code, Emacs already has a neat Scheme mode. But in
39addition to that, you must not miss [[http://www.emacswiki.org/emacs/ParEdit][Paredit]]. It provides facilities to
40directly operate on the syntax tree, such as raising an s-expression or
41wrapping it, swallowing or rejecting the following s-expression, etc.
42
9bf3c1a7
LC
43* Packaging Guidelines
44
45The GNU distribution is about respecting the freedom of users. Consequently,
46it contains only free software as defined at
47http://www.gnu.org/philosophy/free-sw.html .
48
49In addition, we follow the [[http://www.gnu.org/distros/free-system-distribution-guidelines.html][free software distribution guidelines]]. Among other
50things, this means that the distribution tries hard not to steer users towards
51obtaining information about non-free software.
52
59b775cc
LC
53* Adding new packages
54
55Package recipes in Guix look like this:
56
57#+BEGIN_SRC scheme
58 (package
59 (name "nettle")
60 (version "2.5")
61 (source
62 (origin
3dc1970d
LC
63 (method url-fetch)
64 (uri (string-append "mirror://gnu/nettle/nettle-"
59b775cc
LC
65 version ".tar.gz"))
66 (sha256
67 (base32
68 "0wicr7amx01l03rm0pzgr1qvw3f9blaw17vjsy1301dh13ll58aa"))))
69 (build-system gnu-build-system)
08ba7ff3 70 (inputs `(("m4" ,m4)))
59b775cc
LC
71 (propagated-inputs `(("gmp" ,gmp)))
72 (home-page
73 "http://www.lysator.liu.se/~nisse/nettle/")
74 (synopsis "GNU Nettle, a cryptographic library")
75 (description
76 "Nettle is a cryptographic library...")
08ba7ff3 77 (license gpl2+))
59b775cc
LC
78#+END_SRC
79
80Such a recipe can be written by hand, and then tested by running
9bf3c1a7 81‘./pre-inst-env guix build nettle’.
59b775cc
LC
82
83When writing the recipe, the base32-encoded SHA256 hash of the source
84code tarball, which can be seen in the example above, can be obtained by
85running:
86
9bf3c1a7 87 guix download http://ftp.gnu.org/gnu/nettle/nettle-2.5.tar.gz
59b775cc
LC
88
89Alternatively, it is possible to semi-automatically import recipes from
90the [[http://nixos.org/nixpkgs/][Nixpkgs]] software distribution using this command:
91
9bf3c1a7 92 guix import /path/to/nixpkgs/checkout nettle
59b775cc
LC
93
94The command automatically fetches and converts to Guix the “Nix
95expression” of Nettle.
96
9bf3c1a7
LC
97* Submitting Patches
98
99Development is done using the Git distributed version control system. Thus,
100access to the repository is not strictly necessary. We welcome contributions
101in the form of patches as produced by ‘git format-patch’ sent to
102bug-guix@gnu.org. Please write commit logs in the [[http://www.gnu.org/prep/standards/html_node/Change-Logs.html#Change-Logs][GNU ChangeLog format]].
103
104As you become a regular contributor, you may find it convenient to have write
105access to the repository (see below.)
106
107* Commit Access
108
109For frequent contributors, having write access to the repository is
110convenient. When you deem it necessary, feel free to ask for it on the
111mailing list. When you get commit access, please make sure to follow the
112policy below (discussions of the policy can take place on bug-guix@gnu.org.)
113
114Non-trivial patches should always be posted to bug-guix@gnu.org (trivial
115patches include fixing typos, etc.)
116
117For patches that just add a new package, and a simple one, it’s OK to commit,
118if you’re confident (which means you successfully built it in a chroot setup.)
119Likewise for package upgrades. We have a mailing list for commit
120notifications (guix-commits@gnu.org), so people can notice. Before pushing
121your changes, make sure to run ‘git pull --rebase’.
122
123For anything else, please post to bug-guix@gnu.org and leave time for a
124review, without committing anything. If you didn’t receive any reply
125after two weeks, and if you’re confident, it’s OK to commit.
126
127That last part is subject to being adjusted, allowing individuals to commit
128directly on non-controversial changes on parts they’re familiar with.
129
450ccdc3
LC
130* Porting the Guix distro on a new platform
131
132** Introduction
133
134Unlike Make or similar build tools, Guix requires absolutely /all/ the
135dependencies of a build process to be specified.
136
137For a user-land software distribution, that means that the process that
138builds GCC (then used to build all other programs) must itself be
139specified; and the process to build the C library to build that GCC; and
140the process to build the GCC to build that library; and... See the
141problem? Chicken-and-egg.
142
143To break that cycle, the distro starts from a set of pre-built
144binaries–usually referred to as “bootstrap binaries.” These include
e0b27375 145statically-linked versions of Guile, GCC, Coreutils, Grep, sed,
450ccdc3
LC
146etc., and the GNU C Library.
147
148This section describes how to build those bootstrap binaries when
149porting to a new platform.
150
151** When the platform is supported by Nixpkgs
152
153In that case, the easiest thing is to bootstrap the distro using
154binaries from Nixpkgs.
155
156To do that, you need to comment out the definitions of
e0b27375 157‘%bootstrap-guile’ and ‘%bootstrap-inputs’ in gnu/packages/bootstrap.scm
450ccdc3
LC
158to force the use of Nixpkgs derivations. For instance, when porting to
159‘i686-linux’, you should redefine these variables along these lines:
160
161#+BEGIN_SRC scheme
162 (define %bootstrap-guile
163 (nixpkgs-derivation "guile" "i686-linux"))
164
165 (define %bootstrap-inputs
166 (compile-time-value
167 `(("libc" ,(nixpkgs-derivation "glibc" "i686-linux"))
168 ,@(map (lambda (name)
169 (list name (nixpkgs-derivation name "i686-linux")))
170 '("gnutar" "gzip" "bzip2" "xz" "patch"
171 "coreutils" "gnused" "gnugrep" "bash"
172 "gawk" ; used by `config.status'
173 "gcc" "binutils")))))
174#+END_SRC
175
176That should allow the distro to be bootstrapped.
177
178Then, the tarballs containing the initial binaries of Guile, Coreutils,
179GCC, libc, etc. need to be built. To that end, run the following
180commands:
181
182#+BEGIN_SRC sh
9bf3c1a7 183 ./pre-inst-env guix build -K \
e1f8f477 184 -e '(@ (gnu packages make-bootstrap) %bootstrap-tarballs)' \
450ccdc3 185 --system=i686-linux
9149f1a0 186
450ccdc3
LC
187#+END_SRC
188
189These should build tarballs containing statically-linked tools usable on
190that system.
191
192In the source tree, you need to install binaries for ‘mkdir’, ‘bash’,
e0b27375 193‘tar’, and ‘xz’ under ‘gnu/packages/bootstrap/i686-linux’. These
450ccdc3
LC
194binaries can be extracted from the static-binaries tarball built above.
195
e0b27375 196A rule for ‘gnu/packages/bootstrap/i686-linux/guile-2.0.7.tar.xz’
450ccdc3
LC
197needs to be added in ‘Makefile.am’, with the appropriate hexadecimal
198vrepresentation of its SHA256 hash.
199
9149f1a0 200You may then revert your changes to ‘bootstrap.scm’. For the variables
450ccdc3
LC
201‘%bootstrap-coreutils&co’, ‘%bootstrap-binutils’, ‘%bootstrap-glibc’,
202and ‘%bootstrap-gcc’, the expected SHA256 of the corresponding tarballs
203for ‘i686-linux’ (built above) must be added.
204
205This should be enough to bootstrap the distro without resorting to
206Nixpkgs.
207
208** When the platform is *not* supported by Nixpkgs
209
210In that case, the bootstrap binaries should be built using whatever
211tools are available on the target platform. That is, the tarballs and
212binaries show above must first be built manually, using the available
213tools.
214
215They should have the same properties as those built by the Guix recipes
216shown above. For example, all the binaries (except for glibc) must be
217statically-linked; the bootstrap Guile must be relocatable (see patch in
218the Guix distro); the static-binaries tarball must contain the same
219programs (Coreutils, Grep, sed, Awk, etc.); and so on.