Add "Contributor Covenant".
[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
e15fcdd1
LC
10@cindex code of conduct, of contributors
11@cindex contributor covenant
12In the interest of welcoming everyone who thinks this is a great project
13to contribute to---which it is, indeed!---contributors express their
14commitment to providing a warm, friendly, and harassment-free experience
15by agreeing to our ``Contributor Covenant'', adapted from
16@url{http://contributor-covenant.org/}, and which can be found in the
17@file{CODE-OF-CONDUCT} file in the source tree.
18
8c01b9d0
ML
19@menu
20* Building from Git:: The latest and greatest.
21* Running Guix Before It Is Installed:: Hacker tricks.
22* The Perfect Setup:: The right tools.
23* Coding Style:: Hygiene of the contributor.
24* Submitting Patches:: Share your work.
25@end menu
26
27@node Building from Git
28@section Building from Git
29
30If you want to hack Guix itself, it is recommended to use the latest
31version from the Git repository. When building Guix from a checkout,
32the following packages are required in addition to those mentioned in
33the installation instructions (@pxref{Requirements}).
34
35@itemize
36@item @url{http://gnu.org/software/autoconf/, GNU Autoconf};
37@item @url{http://gnu.org/software/automake/, GNU Automake};
38@item @url{http://gnu.org/software/gettext/, GNU Gettext};
0431ed00 39@item @url{http://gnu.org/software/texinfo/, GNU Texinfo};
8c01b9d0
ML
40@item @url{http://www.graphviz.org/, Graphviz};
41@item @url{http://www.gnu.org/software/help2man/, GNU Help2man (optional)}.
42@end itemize
43
5fb95cc5
LC
44The easiest way to set up a development environment for Guix is, of
45course, by using Guix! The following command starts a new shell where
46all the dependencies and appropriate environment variables are set up to
47hack on Guix:
8c01b9d0 48
5fb95cc5
LC
49@example
50guix environment guix
51@end example
52
53@xref{Invoking guix environment}, for more information on that command.
54Extra dependencies can be added with @option{--ad-hoc}:
55
56@example
57guix environment guix --ad-hoc help2man git strace
58@end example
59
60Run @command{./bootstrap} to generate the build system infrastructure
61using Autoconf and Automake. If you get an error like this one:
8c01b9d0
ML
62
63@example
64configure.ac:46: error: possibly undefined macro: PKG_CHECK_MODULES
65@end example
66
5fb95cc5 67@noindent
8c01b9d0 68it probably means that Autoconf couldn’t find @file{pkg.m4}, which is
5fb95cc5
LC
69provided by pkg-config. Make sure that @file{pkg.m4} is available. The
70same holds for the @file{guile.m4} set of macros provided by Guile. For
71instance, if you installed Automake in @file{/usr/local}, it wouldn’t
72look for @file{.m4} files in @file{/usr/share}. In that case, you have
73to invoke the following command:
8c01b9d0
ML
74
75@example
76export ACLOCAL_PATH=/usr/share/aclocal
77@end example
78
aabe6d38 79@xref{Macro Search Path,,, automake, The GNU Automake Manual}, for
8c01b9d0
ML
80more information.
81
82Then, run @command{./configure} as usual.
83
84Finally, you have to invoke @code{make check} to run tests. If anything
85fails, take a look at installation instructions (@pxref{Installation})
86or send a message to the @email{guix-devel@@gnu.org, mailing list}.
87
88
89@node Running Guix Before It Is Installed
90@section Running Guix Before It Is Installed
91
92In order to keep a sane working environment, you will find it useful to
93test the changes made in your local source tree checkout without
94actually installing them. So that you can distinguish between your
95``end-user'' hat and your ``motley'' costume.
96
97To that end, all the command-line tools can be used even if you have not
98run @code{make install}. To do that, prefix each command with
99@command{./pre-inst-env} (the @file{pre-inst-env} script lives in the
100top build tree of Guix), as in:
101
102@example
103$ sudo ./pre-inst-env guix-daemon --build-users-group=guixbuild
104$ ./pre-inst-env guix build hello
105@end example
106
107@noindent
108Similarly, for a Guile session using the Guix modules:
109
110@example
111$ ./pre-inst-env guile -c '(use-modules (guix utils)) (pk (%current-system))'
96856613
LC
112
113;;; ("x86_64-linux")
114@end example
115
116@noindent
117@cindex REPL
118@cindex read-eval-print loop
119@dots{} and for a REPL (@pxref{Using Guile Interactively,,, guile, Guile
120Reference Manual}):
121
122@example
123$ ./pre-inst-env guile
124scheme@@(guile-user)> ,use(guix)
125scheme@@(guile-user)> ,use(gnu)
126scheme@@(guile-user)> (define snakes
127 (fold-packages
128 (lambda (package lst)
129 (if (string-prefix? "python"
130 (package-name package))
131 (cons package lst)
132 lst))
133 '()))
134scheme@@(guile-user)> (length snakes)
135$1 = 361
8c01b9d0
ML
136@end example
137
138The @command{pre-inst-env} script sets up all the environment variables
139necessary to support this, including @env{PATH} and @env{GUILE_LOAD_PATH}.
140
ef54b61d
AV
141Note that @command{./pre-inst-env guix pull} does @emph{not} upgrade the
142local source tree; it simply updates the @file{~/.config/guix/latest}
143symlink (@pxref{Invoking guix pull}). Run @command{git pull} instead if
144you want to upgrade your local source tree.
145
8c01b9d0
ML
146
147@node The Perfect Setup
148@section The Perfect Setup
149
150The Perfect Setup to hack on Guix is basically the perfect setup used
151for Guile hacking (@pxref{Using Guile in Emacs,,, guile, Guile Reference
152Manual}). First, you need more than an editor, you need
153@url{http://www.gnu.org/software/emacs, Emacs}, empowered by the
154wonderful @url{http://nongnu.org/geiser/, Geiser}.
155
156Geiser allows for interactive and incremental development from within
157Emacs: code compilation and evaluation from within buffers, access to
158on-line documentation (docstrings), context-sensitive completion,
159@kbd{M-.} to jump to an object definition, a REPL to try out your code,
160and more (@pxref{Introduction,,, geiser, Geiser User Manual}). For
161convenient Guix development, make sure to augment Guile’s load path so
162that it finds source files from your checkout:
163
164@lisp
165;; @r{Assuming the Guix checkout is in ~/src/guix.}
bb38ece4
AK
166(with-eval-after-load 'geiser-guile
167 (add-to-list 'geiser-guile-load-path "~/src/guix"))
8c01b9d0
ML
168@end lisp
169
170To actually edit the code, Emacs already has a neat Scheme mode. But in
171addition to that, you must not miss
172@url{http://www.emacswiki.org/emacs/ParEdit, Paredit}. It provides
173facilities to directly operate on the syntax tree, such as raising an
174s-expression or wrapping it, swallowing or rejecting the following
175s-expression, etc.
176
187f80c6
AK
177GNU Guix also comes with a minor mode that provides some additional
178functionality for Scheme buffers (@pxref{Emacs Development}).
179
8c01b9d0
ML
180
181@node Coding Style
182@section Coding Style
183
184In general our code follows the GNU Coding Standards (@pxref{Top,,,
185standards, GNU Coding Standards}). However, they do not say much about
186Scheme, so here are some additional rules.
187
188@menu
189* Programming Paradigm:: How to compose your elements.
190* Modules:: Where to store your code?
191* Data Types and Pattern Matching:: Implementing data structures.
192* Formatting Code:: Writing conventions.
193@end menu
194
195@node Programming Paradigm
196@subsection Programming Paradigm
197
198Scheme code in Guix is written in a purely functional style. One
199exception is code that involves input/output, and procedures that
200implement low-level concepts, such as the @code{memoize} procedure.
201
202@node Modules
203@subsection Modules
204
205Guile modules that are meant to be used on the builder side must live in
206the @code{(guix build @dots{})} name space. They must not refer to
207other Guix or GNU modules. However, it is OK for a ``host-side'' module
208to use a build-side module.
209
210Modules that deal with the broader GNU system should be in the
211@code{(gnu @dots{})} name space rather than @code{(guix @dots{})}.
212
213@node Data Types and Pattern Matching
214@subsection Data Types and Pattern Matching
215
216The tendency in classical Lisp is to use lists to represent everything,
217and then to browse them ``by hand'' using @code{car}, @code{cdr},
218@code{cadr}, and co. There are several problems with that style,
219notably the fact that it is hard to read, error-prone, and a hindrance
220to proper type error reports.
221
222Guix code should define appropriate data types (for instance, using
223@code{define-record-type*}) rather than abuse lists. In addition, it
224should use pattern matching, via Guile’s @code{(ice-9 match)} module,
225especially when matching lists.
226
227@node Formatting Code
228@subsection Formatting Code
229
230When writing Scheme code, we follow common wisdom among Scheme
231programmers. In general, we follow the
232@url{http://mumble.net/~campbell/scheme/style.txt, Riastradh's Lisp
233Style Rules}. This document happens to describe the conventions mostly
234used in Guile’s code too. It is very thoughtful and well written, so
235please do read it.
236
237Some special forms introduced in Guix, such as the @code{substitute*}
238macro, have special indentation rules. These are defined in the
239@file{.dir-locals.el} file, which Emacs automatically uses. If you do
240not use Emacs, please make sure to let your editor know the rules.
241
242We require all top-level procedures to carry a docstring. This
243requirement can be relaxed for simple private procedures in the
244@code{(guix build @dots{})} name space, though.
245
246Procedures should not have more than four positional parameters. Use
247keyword parameters for procedures that take more than four parameters.
248
249
250@node Submitting Patches
251@section Submitting Patches
252
253Development is done using the Git distributed version control system.
254Thus, access to the repository is not strictly necessary. We welcome
255contributions in the form of patches as produced by @code{git
256format-patch} sent to the @email{guix-devel@@gnu.org, mailing list}.
257Please write commit logs in the ChangeLog format (@pxref{Change Logs,,,
258standards, GNU Coding Standards}); you can check the commit history for
259examples.
260
261Before submitting a patch that adds or modifies a package definition,
fcc58db6
LC
262please run through this check list:
263
264@enumerate
cbd02397
LC
265@item
266Take some time to provide an adequate synopsis and description for the
267package. @xref{Synopses and Descriptions}, for some guidelines.
268
fcc58db6
LC
269@item
270Run @code{guix lint @var{package}}, where @var{package} is the
8c01b9d0 271name of the new or modified package, and fix any errors it reports
fcc58db6
LC
272(@pxref{Invoking guix lint}).
273
274@item
275Make sure the package builds on your platform, using @code{guix build
276@var{package}}.
277
278@item
279Take a look at the profile reported by @command{guix size}
280(@pxref{Invoking guix size}). This will allow you to notice references
281to other packages unwillingly retained. It may also help determine
282whether to split the package (@pxref{Packages with Multiple Outputs}),
283and which optional dependencies should be used.
284
285@item
286For important changes, check that dependent package (if applicable) are
287not affected by the change; @code{guix refresh --list-dependent
8c01b9d0
ML
288@var{package}} will help you do that (@pxref{Invoking guix refresh}).
289
d23c20f1 290@item
5b74fe06
LC
291@cindex determinism, of build processes
292@cindex reproducible builds, checking
d23c20f1
LC
293Check whether the package's build process is deterministic. This
294typically means checking whether an independent build of the package
295yields the exact same result that you obtained, bit for bit.
296
5b74fe06
LC
297A simple way to do that is by building the same package several times in
298a row on your machine (@pxref{Invoking guix build}):
299
300@example
301guix build --rounds=2 my-package
302@end example
303
304This is enough to catch a class of common non-determinism issues, such
305as timestamps or randomly-generated output in the build result.
306
307Another option is to use @command{guix challenge} (@pxref{Invoking guix
308challenge}). You may run it once the package has been committed and
309built by @code{hydra.gnu.org} to check whether it obtains the same
310result as you did. Better yet: Find another machine that can build it
311and run @command{guix publish}. Since the remote build machine is
312likely different from yours, this can catch non-determinism issues
313related to the hardware---e.g., use of different instruction set
314extensions---or to the operating system kernel---e.g., reliance on
315@code{uname} or @file{/proc} files.
d23c20f1 316
fcc58db6
LC
317@end enumerate
318
8c01b9d0
ML
319When posting a patch to the mailing list, use @samp{[PATCH] @dots{}} as a
320subject. You may use your email client or the @command{git send-mail}
321command.