Add 'guix challenge'.
[jackhill/guix/guix.git] / doc / contributing.texi
CommitLineData
8c01b9d0
ML
1@node Contributing
2@chapter Contributing
3
4This project is a cooperative effort, and we need your help to make it
5grow! Please get in touch with us on @email{guix-devel@@gnu.org} and
6@code{#guix} on the Freenode IRC network. We welcome ideas, bug
7reports, patches, and anything that may be helpful to the project. We
8particularly welcome help on packaging (@pxref{Packaging Guidelines}).
9
10@menu
11* Building from Git:: The latest and greatest.
12* Running Guix Before It Is Installed:: Hacker tricks.
13* The Perfect Setup:: The right tools.
14* Coding Style:: Hygiene of the contributor.
15* Submitting Patches:: Share your work.
16@end menu
17
18@node Building from Git
19@section Building from Git
20
21If you want to hack Guix itself, it is recommended to use the latest
22version from the Git repository. When building Guix from a checkout,
23the following packages are required in addition to those mentioned in
24the installation instructions (@pxref{Requirements}).
25
26@itemize
27@item @url{http://gnu.org/software/autoconf/, GNU Autoconf};
28@item @url{http://gnu.org/software/automake/, GNU Automake};
29@item @url{http://gnu.org/software/gettext/, GNU Gettext};
30@item @url{http://www.graphviz.org/, Graphviz};
31@item @url{http://www.gnu.org/software/help2man/, GNU Help2man (optional)}.
32@end itemize
33
34Run @command{./bootstrap} to download the Nix daemon source code and to
35generate the build system infrastructure using autoconf. It reports an
36error if an inappropriate version of the above packages is being used.
37
38@noindent
39If you get an error like this one:
40
41@example
42configure.ac:46: error: possibly undefined macro: PKG_CHECK_MODULES
43@end example
44
45it probably means that Autoconf couldn’t find @file{pkg.m4}, which is
46provided by @command{pkg-config}. Make sure that @file{pkg.m4} is
47available. For instance, if you installed Automake in
48@file{/usr/local}, it wouldn’t look for @file{.m4} files in
49@file{/usr/share}. So you have to invoke the following command in that
50case
51
52@example
53export ACLOCAL_PATH=/usr/share/aclocal
54@end example
55
56See @pxref{Macro Search Path,,, automake, The GNU Automake Manual} for
57more information.
58
59Then, run @command{./configure} as usual.
60
61Finally, you have to invoke @code{make check} to run tests. If anything
62fails, take a look at installation instructions (@pxref{Installation})
63or send a message to the @email{guix-devel@@gnu.org, mailing list}.
64
65
66@node Running Guix Before It Is Installed
67@section Running Guix Before It Is Installed
68
69In order to keep a sane working environment, you will find it useful to
70test the changes made in your local source tree checkout without
71actually installing them. So that you can distinguish between your
72``end-user'' hat and your ``motley'' costume.
73
74To that end, all the command-line tools can be used even if you have not
75run @code{make install}. To do that, prefix each command with
76@command{./pre-inst-env} (the @file{pre-inst-env} script lives in the
77top build tree of Guix), as in:
78
79@example
80$ sudo ./pre-inst-env guix-daemon --build-users-group=guixbuild
81$ ./pre-inst-env guix build hello
82@end example
83
84@noindent
85Similarly, for a Guile session using the Guix modules:
86
87@example
88$ ./pre-inst-env guile -c '(use-modules (guix utils)) (pk (%current-system))'
89@end example
90
91The @command{pre-inst-env} script sets up all the environment variables
92necessary to support this, including @env{PATH} and @env{GUILE_LOAD_PATH}.
93
94
95@node The Perfect Setup
96@section The Perfect Setup
97
98The Perfect Setup to hack on Guix is basically the perfect setup used
99for Guile hacking (@pxref{Using Guile in Emacs,,, guile, Guile Reference
100Manual}). First, you need more than an editor, you need
101@url{http://www.gnu.org/software/emacs, Emacs}, empowered by the
102wonderful @url{http://nongnu.org/geiser/, Geiser}.
103
104Geiser allows for interactive and incremental development from within
105Emacs: code compilation and evaluation from within buffers, access to
106on-line documentation (docstrings), context-sensitive completion,
107@kbd{M-.} to jump to an object definition, a REPL to try out your code,
108and more (@pxref{Introduction,,, geiser, Geiser User Manual}). For
109convenient Guix development, make sure to augment Guile’s load path so
110that it finds source files from your checkout:
111
112@lisp
113;; @r{Assuming the Guix checkout is in ~/src/guix.}
114(add-to-list 'geiser-guile-load-path "~/src/guix")
115@end lisp
116
117To actually edit the code, Emacs already has a neat Scheme mode. But in
118addition to that, you must not miss
119@url{http://www.emacswiki.org/emacs/ParEdit, Paredit}. It provides
120facilities to directly operate on the syntax tree, such as raising an
121s-expression or wrapping it, swallowing or rejecting the following
122s-expression, etc.
123
187f80c6
AK
124GNU Guix also comes with a minor mode that provides some additional
125functionality for Scheme buffers (@pxref{Emacs Development}).
126
8c01b9d0
ML
127
128@node Coding Style
129@section Coding Style
130
131In general our code follows the GNU Coding Standards (@pxref{Top,,,
132standards, GNU Coding Standards}). However, they do not say much about
133Scheme, so here are some additional rules.
134
135@menu
136* Programming Paradigm:: How to compose your elements.
137* Modules:: Where to store your code?
138* Data Types and Pattern Matching:: Implementing data structures.
139* Formatting Code:: Writing conventions.
140@end menu
141
142@node Programming Paradigm
143@subsection Programming Paradigm
144
145Scheme code in Guix is written in a purely functional style. One
146exception is code that involves input/output, and procedures that
147implement low-level concepts, such as the @code{memoize} procedure.
148
149@node Modules
150@subsection Modules
151
152Guile modules that are meant to be used on the builder side must live in
153the @code{(guix build @dots{})} name space. They must not refer to
154other Guix or GNU modules. However, it is OK for a ``host-side'' module
155to use a build-side module.
156
157Modules that deal with the broader GNU system should be in the
158@code{(gnu @dots{})} name space rather than @code{(guix @dots{})}.
159
160@node Data Types and Pattern Matching
161@subsection Data Types and Pattern Matching
162
163The tendency in classical Lisp is to use lists to represent everything,
164and then to browse them ``by hand'' using @code{car}, @code{cdr},
165@code{cadr}, and co. There are several problems with that style,
166notably the fact that it is hard to read, error-prone, and a hindrance
167to proper type error reports.
168
169Guix code should define appropriate data types (for instance, using
170@code{define-record-type*}) rather than abuse lists. In addition, it
171should use pattern matching, via Guile’s @code{(ice-9 match)} module,
172especially when matching lists.
173
174@node Formatting Code
175@subsection Formatting Code
176
177When writing Scheme code, we follow common wisdom among Scheme
178programmers. In general, we follow the
179@url{http://mumble.net/~campbell/scheme/style.txt, Riastradh's Lisp
180Style Rules}. This document happens to describe the conventions mostly
181used in Guile’s code too. It is very thoughtful and well written, so
182please do read it.
183
184Some special forms introduced in Guix, such as the @code{substitute*}
185macro, have special indentation rules. These are defined in the
186@file{.dir-locals.el} file, which Emacs automatically uses. If you do
187not use Emacs, please make sure to let your editor know the rules.
188
189We require all top-level procedures to carry a docstring. This
190requirement can be relaxed for simple private procedures in the
191@code{(guix build @dots{})} name space, though.
192
193Procedures should not have more than four positional parameters. Use
194keyword parameters for procedures that take more than four parameters.
195
196
197@node Submitting Patches
198@section Submitting Patches
199
200Development is done using the Git distributed version control system.
201Thus, access to the repository is not strictly necessary. We welcome
202contributions in the form of patches as produced by @code{git
203format-patch} sent to the @email{guix-devel@@gnu.org, mailing list}.
204Please write commit logs in the ChangeLog format (@pxref{Change Logs,,,
205standards, GNU Coding Standards}); you can check the commit history for
206examples.
207
208Before submitting a patch that adds or modifies a package definition,
fcc58db6
LC
209please run through this check list:
210
211@enumerate
cbd02397
LC
212@item
213Take some time to provide an adequate synopsis and description for the
214package. @xref{Synopses and Descriptions}, for some guidelines.
215
fcc58db6
LC
216@item
217Run @code{guix lint @var{package}}, where @var{package} is the
8c01b9d0 218name of the new or modified package, and fix any errors it reports
fcc58db6
LC
219(@pxref{Invoking guix lint}).
220
221@item
222Make sure the package builds on your platform, using @code{guix build
223@var{package}}.
224
225@item
226Take a look at the profile reported by @command{guix size}
227(@pxref{Invoking guix size}). This will allow you to notice references
228to other packages unwillingly retained. It may also help determine
229whether to split the package (@pxref{Packages with Multiple Outputs}),
230and which optional dependencies should be used.
231
232@item
233For important changes, check that dependent package (if applicable) are
234not affected by the change; @code{guix refresh --list-dependent
8c01b9d0
ML
235@var{package}} will help you do that (@pxref{Invoking guix refresh}).
236
d23c20f1
LC
237@item
238Check whether the package's build process is deterministic. This
239typically means checking whether an independent build of the package
240yields the exact same result that you obtained, bit for bit.
241
242A simple way to do that is with @command{guix challenge}
243(@pxref{Invoking guix challenge}). You may run it once the package has
244been committed and built by @code{hydra.gnu.org} to check whether it
245obtains the same result as you did. Better yet: Find another machine
246that can build it and run @command{guix publish}.
247
fcc58db6
LC
248@end enumerate
249
8c01b9d0
ML
250When posting a patch to the mailing list, use @samp{[PATCH] @dots{}} as a
251subject. You may use your email client or the @command{git send-mail}
252command.