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