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