gnu: mit-scheme: Match all the system types in 'inputs'.
[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
dbfcadfc
LC
34version from the Git repository:
35
36@example
37git clone https://git.savannah.gnu.org/git/guix.git
38@end example
39
40When building Guix from a checkout,
8c01b9d0
ML
41the following packages are required in addition to those mentioned in
42the installation instructions (@pxref{Requirements}).
43
44@itemize
45@item @url{http://gnu.org/software/autoconf/, GNU Autoconf};
46@item @url{http://gnu.org/software/automake/, GNU Automake};
47@item @url{http://gnu.org/software/gettext/, GNU Gettext};
0431ed00 48@item @url{http://gnu.org/software/texinfo/, GNU Texinfo};
8c01b9d0
ML
49@item @url{http://www.graphviz.org/, Graphviz};
50@item @url{http://www.gnu.org/software/help2man/, GNU Help2man (optional)}.
51@end itemize
52
5fb95cc5
LC
53The easiest way to set up a development environment for Guix is, of
54course, by using Guix! The following command starts a new shell where
55all the dependencies and appropriate environment variables are set up to
56hack on Guix:
8c01b9d0 57
5fb95cc5
LC
58@example
59guix environment guix
60@end example
61
62@xref{Invoking guix environment}, for more information on that command.
63Extra dependencies can be added with @option{--ad-hoc}:
64
65@example
66guix environment guix --ad-hoc help2man git strace
67@end example
68
69Run @command{./bootstrap} to generate the build system infrastructure
70using Autoconf and Automake. If you get an error like this one:
8c01b9d0
ML
71
72@example
73configure.ac:46: error: possibly undefined macro: PKG_CHECK_MODULES
74@end example
75
5fb95cc5 76@noindent
8c01b9d0 77it probably means that Autoconf couldn’t find @file{pkg.m4}, which is
5fb95cc5
LC
78provided by pkg-config. Make sure that @file{pkg.m4} is available. The
79same holds for the @file{guile.m4} set of macros provided by Guile. For
80instance, if you installed Automake in @file{/usr/local}, it wouldn’t
81look for @file{.m4} files in @file{/usr/share}. In that case, you have
82to invoke the following command:
8c01b9d0
ML
83
84@example
85export ACLOCAL_PATH=/usr/share/aclocal
86@end example
87
aabe6d38 88@xref{Macro Search Path,,, automake, The GNU Automake Manual}, for
8c01b9d0
ML
89more information.
90
3a25c631
LC
91Then, run @command{./configure} as usual. Make sure to pass
92@code{--localstatedir=@var{directory}} where @var{directory} is the
93@code{localstatedir} value used by your current installation (@pxref{The
94Store}, for information about this).
8c01b9d0 95
3a25c631
LC
96Finally, you have to invoke @code{make check} to run tests
97(@pxref{Running the Test Suite}). If anything
8c01b9d0
ML
98fails, take a look at installation instructions (@pxref{Installation})
99or send a message to the @email{guix-devel@@gnu.org, mailing list}.
100
101
102@node Running Guix Before It Is Installed
103@section Running Guix Before It Is Installed
104
105In order to keep a sane working environment, you will find it useful to
106test the changes made in your local source tree checkout without
107actually installing them. So that you can distinguish between your
108``end-user'' hat and your ``motley'' costume.
109
110To that end, all the command-line tools can be used even if you have not
0207768f
LC
111run @code{make install}. To do that, you first need to have an environment
112with all the dependencies available (@pxref{Building from Git}), and then
113simply prefix each command with
8c01b9d0 114@command{./pre-inst-env} (the @file{pre-inst-env} script lives in the
bca63967
LC
115top build tree of Guix; it is generated by @command{./configure}),
116as in@footnote{The @option{-E} flag to
67441b9a
LC
117@command{sudo} guarantees that @code{GUILE_LOAD_PATH} is correctly set
118such that @command{guix-daemon} and the tools it uses can find the Guile
119modules they need.}:
8c01b9d0
ML
120
121@example
67441b9a 122$ sudo -E ./pre-inst-env guix-daemon --build-users-group=guixbuild
8c01b9d0
ML
123$ ./pre-inst-env guix build hello
124@end example
125
126@noindent
127Similarly, for a Guile session using the Guix modules:
128
129@example
130$ ./pre-inst-env guile -c '(use-modules (guix utils)) (pk (%current-system))'
96856613
LC
131
132;;; ("x86_64-linux")
133@end example
134
135@noindent
136@cindex REPL
137@cindex read-eval-print loop
138@dots{} and for a REPL (@pxref{Using Guile Interactively,,, guile, Guile
139Reference Manual}):
140
141@example
142$ ./pre-inst-env guile
143scheme@@(guile-user)> ,use(guix)
144scheme@@(guile-user)> ,use(gnu)
145scheme@@(guile-user)> (define snakes
146 (fold-packages
147 (lambda (package lst)
148 (if (string-prefix? "python"
149 (package-name package))
150 (cons package lst)
151 lst))
152 '()))
153scheme@@(guile-user)> (length snakes)
154$1 = 361
8c01b9d0
ML
155@end example
156
157The @command{pre-inst-env} script sets up all the environment variables
158necessary to support this, including @env{PATH} and @env{GUILE_LOAD_PATH}.
159
ef54b61d 160Note that @command{./pre-inst-env guix pull} does @emph{not} upgrade the
75e24d7b 161local source tree; it simply updates the @file{~/.config/guix/current}
ef54b61d 162symlink (@pxref{Invoking guix pull}). Run @command{git pull} instead if
75e24d7b 163you want to upgrade your local source tree.
ef54b61d 164
8c01b9d0
ML
165
166@node The Perfect Setup
167@section The Perfect Setup
168
169The Perfect Setup to hack on Guix is basically the perfect setup used
170for Guile hacking (@pxref{Using Guile in Emacs,,, guile, Guile Reference
171Manual}). First, you need more than an editor, you need
172@url{http://www.gnu.org/software/emacs, Emacs}, empowered by the
173wonderful @url{http://nongnu.org/geiser/, Geiser}.
174
175Geiser allows for interactive and incremental development from within
176Emacs: code compilation and evaluation from within buffers, access to
177on-line documentation (docstrings), context-sensitive completion,
178@kbd{M-.} to jump to an object definition, a REPL to try out your code,
179and more (@pxref{Introduction,,, geiser, Geiser User Manual}). For
180convenient Guix development, make sure to augment Guile’s load path so
181that it finds source files from your checkout:
182
183@lisp
184;; @r{Assuming the Guix checkout is in ~/src/guix.}
bb38ece4
AK
185(with-eval-after-load 'geiser-guile
186 (add-to-list 'geiser-guile-load-path "~/src/guix"))
8c01b9d0
ML
187@end lisp
188
189To actually edit the code, Emacs already has a neat Scheme mode. But in
190addition to that, you must not miss
191@url{http://www.emacswiki.org/emacs/ParEdit, Paredit}. It provides
192facilities to directly operate on the syntax tree, such as raising an
193s-expression or wrapping it, swallowing or rejecting the following
194s-expression, etc.
195
42cdcdff
RW
196@cindex code snippets
197@cindex templates
198@cindex reducing boilerplate
199We also provide templates for common git commit messages and package
200definitions in the @file{etc/snippets} directory. These templates can
201be used with @url{http://joaotavora.github.io/yasnippet/, YASnippet} to
202expand short trigger strings to interactive text snippets. You may want
203to add the snippets directory to the @var{yas-snippet-dirs} variable in
204Emacs.
205
206@lisp
207;; @r{Assuming the Guix checkout is in ~/src/guix.}
208(with-eval-after-load 'yasnippet
209 (add-to-list 'yas-snippet-dirs "~/src/guix/etc/snippets"))
210@end lisp
211
212The commit message snippets depend on @url{https://magit.vc/, Magit} to
213display staged files. When editing a commit message type @code{add}
214followed by @kbd{TAB} to insert a commit message template for adding a
215package; type @code{update} followed by @kbd{TAB} to insert a template
9286c295
AI
216for updating a package; type @code{https} followed by @kbd{TAB} to
217insert a template for changing the home page URI of a package to HTTPS.
42cdcdff
RW
218
219The main snippet for @code{scheme-mode} is triggered by typing
220@code{package...} followed by @kbd{TAB}. This snippet also inserts the
221trigger string @code{origin...}, which can be expanded further. The
222@code{origin} snippet in turn may insert other trigger strings ending on
223@code{...}, which also can be expanded further.
224
8c01b9d0
ML
225
226@node Coding Style
227@section Coding Style
228
229In general our code follows the GNU Coding Standards (@pxref{Top,,,
230standards, GNU Coding Standards}). However, they do not say much about
231Scheme, so here are some additional rules.
232
233@menu
234* Programming Paradigm:: How to compose your elements.
235* Modules:: Where to store your code?
236* Data Types and Pattern Matching:: Implementing data structures.
237* Formatting Code:: Writing conventions.
238@end menu
239
240@node Programming Paradigm
241@subsection Programming Paradigm
242
243Scheme code in Guix is written in a purely functional style. One
244exception is code that involves input/output, and procedures that
245implement low-level concepts, such as the @code{memoize} procedure.
246
247@node Modules
248@subsection Modules
249
250Guile modules that are meant to be used on the builder side must live in
251the @code{(guix build @dots{})} name space. They must not refer to
252other Guix or GNU modules. However, it is OK for a ``host-side'' module
253to use a build-side module.
254
255Modules that deal with the broader GNU system should be in the
256@code{(gnu @dots{})} name space rather than @code{(guix @dots{})}.
257
258@node Data Types and Pattern Matching
259@subsection Data Types and Pattern Matching
260
261The tendency in classical Lisp is to use lists to represent everything,
262and then to browse them ``by hand'' using @code{car}, @code{cdr},
263@code{cadr}, and co. There are several problems with that style,
264notably the fact that it is hard to read, error-prone, and a hindrance
265to proper type error reports.
266
267Guix code should define appropriate data types (for instance, using
268@code{define-record-type*}) rather than abuse lists. In addition, it
269should use pattern matching, via Guile’s @code{(ice-9 match)} module,
270especially when matching lists.
271
272@node Formatting Code
273@subsection Formatting Code
274
7bb2b10c
LC
275@cindex formatting code
276@cindex coding style
8c01b9d0
ML
277When writing Scheme code, we follow common wisdom among Scheme
278programmers. In general, we follow the
279@url{http://mumble.net/~campbell/scheme/style.txt, Riastradh's Lisp
280Style Rules}. This document happens to describe the conventions mostly
281used in Guile’s code too. It is very thoughtful and well written, so
282please do read it.
283
284Some special forms introduced in Guix, such as the @code{substitute*}
285macro, have special indentation rules. These are defined in the
8ca0c88a
AK
286@file{.dir-locals.el} file, which Emacs automatically uses. Also note
287that Emacs-Guix provides @code{guix-devel-mode} mode that indents and
288highlights Guix code properly (@pxref{Development,,, emacs-guix, The
289Emacs-Guix Reference Manual}).
7bb2b10c
LC
290
291@cindex indentation, of code
292@cindex formatting, of code
293If you do not use Emacs, please make sure to let your editor knows these
294rules. To automatically indent a package definition, you can also run:
295
296@example
557d9c8d 297./etc/indent-code.el gnu/packages/@var{file}.scm @var{package}
7bb2b10c
LC
298@end example
299
300@noindent
301This automatically indents the definition of @var{package} in
557d9c8d
LC
302@file{gnu/packages/@var{file}.scm} by running Emacs in batch mode. To
303indent a whole file, omit the second argument:
304
305@example
306./etc/indent-code.el gnu/services/@var{file}.scm
307@end example
8c01b9d0 308
60912a88
LC
309@cindex Vim, Scheme code editing
310If you are editing code with Vim, we recommend that you run @code{:set
311autoindent} so that your code is automatically indented as you type.
312Additionally,
313@uref{https://www.vim.org/scripts/script.php?script_id=3998,
314@code{paredit.vim}} may help you deal with all these parentheses.
315
8c01b9d0
ML
316We require all top-level procedures to carry a docstring. This
317requirement can be relaxed for simple private procedures in the
318@code{(guix build @dots{})} name space, though.
319
320Procedures should not have more than four positional parameters. Use
321keyword parameters for procedures that take more than four parameters.
322
323
324@node Submitting Patches
325@section Submitting Patches
326
327Development is done using the Git distributed version control system.
328Thus, access to the repository is not strictly necessary. We welcome
329contributions in the form of patches as produced by @code{git
230efa87
LC
330format-patch} sent to the @email{guix-patches@@gnu.org} mailing list.
331
332This mailing list is backed by a Debbugs instance accessible at
333@uref{https://bugs.gnu.org/guix-patches}, which allows us to keep track
334of submissions. Each message sent to that mailing list gets a new
335tracking number assigned; people can then follow up on the submission by
336sending email to @code{@var{NNN}@@debbugs.gnu.org}, where @var{NNN} is
5a183a1e 337the tracking number (@pxref{Sending a Patch Series}).
230efa87 338
8c01b9d0
ML
339Please write commit logs in the ChangeLog format (@pxref{Change Logs,,,
340standards, GNU Coding Standards}); you can check the commit history for
341examples.
342
343Before submitting a patch that adds or modifies a package definition,
fcc58db6
LC
344please run through this check list:
345
346@enumerate
308c08d3
RW
347@item
348If the authors of the packaged software provide a cryptographic
349signature for the release tarball, make an effort to verify the
350authenticity of the archive. For a detached GPG signature file this
351would be done with the @code{gpg --verify} command.
352
cbd02397
LC
353@item
354Take some time to provide an adequate synopsis and description for the
355package. @xref{Synopses and Descriptions}, for some guidelines.
356
fcc58db6
LC
357@item
358Run @code{guix lint @var{package}}, where @var{package} is the
8c01b9d0 359name of the new or modified package, and fix any errors it reports
fcc58db6
LC
360(@pxref{Invoking guix lint}).
361
362@item
363Make sure the package builds on your platform, using @code{guix build
364@var{package}}.
365
d222522e
LC
366@item
367@cindex bundling
368Make sure the package does not use bundled copies of software already
369available as separate packages.
370
371Sometimes, packages include copies of the source code of their
372dependencies as a convenience for users. However, as a distribution, we
373want to make sure that such packages end up using the copy we already
374have in the distribution, if there is one. This improves resource usage
375(the dependency is built and stored only once), and allows the
376distribution to make transverse changes such as applying security
377updates for a given software package in a single place and have them
378affect the whole system---something that bundled copies prevent.
379
fcc58db6
LC
380@item
381Take a look at the profile reported by @command{guix size}
382(@pxref{Invoking guix size}). This will allow you to notice references
383to other packages unwillingly retained. It may also help determine
384whether to split the package (@pxref{Packages with Multiple Outputs}),
385and which optional dependencies should be used.
386
387@item
388For important changes, check that dependent package (if applicable) are
389not affected by the change; @code{guix refresh --list-dependent
8c01b9d0
ML
390@var{package}} will help you do that (@pxref{Invoking guix refresh}).
391
916b5eba
LC
392@c See <https://lists.gnu.org/archive/html/guix-devel/2016-10/msg00933.html>.
393@cindex branching strategy
394@cindex rebuild scheduling strategy
395Depending on the number of dependent packages and thus the amount of
396rebuilding induced, commits go to different branches, along these lines:
397
398@table @asis
399@item 300 dependent packages or less
400@code{master} branch (non-disruptive changes).
401
402@item between 300 and 1,200 dependent packages
403@code{staging} branch (non-disruptive changes). This branch is intended
404to be merged in @code{master} every 3 weeks or so. Topical changes
405(e.g., an update of the GNOME stack) can instead go to a specific branch
406(say, @code{gnome-updates}).
407
408@item more than 1,200 dependent packages
409@code{core-updates} branch (may include major and potentially disruptive
410changes). This branch is intended to be merged in @code{master} every
4112.5 months or so.
412@end table
413
38ab778f
MB
414All these branches are @uref{https://hydra.gnu.org/project/gnu,
415tracked by our build farm} and merged into @code{master} once
189b1543
LC
416everything has been successfully built. This allows us to fix issues
417before they hit users, and to reduce the window during which pre-built
418binaries are not available.
419
38ab778f
MB
420Generally, branches other than @code{master} are considered
421@emph{frozen} if there has been a recent evaluation, or there is a
422corresponding @code{-next} branch. Please ask on the mailing list or
423IRC if unsure where to place a patch.
424@c TODO: It would be good with badges on the website that tracks these
425@c branches. Or maybe even a status page.
426
d23c20f1 427@item
5b74fe06
LC
428@cindex determinism, of build processes
429@cindex reproducible builds, checking
d23c20f1
LC
430Check whether the package's build process is deterministic. This
431typically means checking whether an independent build of the package
432yields the exact same result that you obtained, bit for bit.
433
5b74fe06
LC
434A simple way to do that is by building the same package several times in
435a row on your machine (@pxref{Invoking guix build}):
436
437@example
438guix build --rounds=2 my-package
439@end example
440
441This is enough to catch a class of common non-determinism issues, such
442as timestamps or randomly-generated output in the build result.
443
444Another option is to use @command{guix challenge} (@pxref{Invoking guix
445challenge}). You may run it once the package has been committed and
0bc02bec 446built by @code{@value{SUBSTITUTE-SERVER}} to check whether it obtains the same
5b74fe06
LC
447result as you did. Better yet: Find another machine that can build it
448and run @command{guix publish}. Since the remote build machine is
449likely different from yours, this can catch non-determinism issues
450related to the hardware---e.g., use of different instruction set
451extensions---or to the operating system kernel---e.g., reliance on
452@code{uname} or @file{/proc} files.
d23c20f1 453
3c2d03a2
LC
454@item
455When writing documentation, please use gender-neutral wording when
456referring to people, such as
457@uref{https://en.wikipedia.org/wiki/Singular_they, singular
458``they''@comma{} ``their''@comma{} ``them''}, and so forth.
459
3a78fab8 460@item
461Verify that your patch contains only one set of related changes.
462Bundling unrelated changes together makes reviewing harder and slower.
463
464Examples of unrelated changes include the addition of several packages,
465or a package update along with fixes to that package.
466
7bb2b10c
LC
467@item
468Please follow our code formatting rules, possibly running the
557d9c8d 469@command{etc/indent-code.el} script to do that automatically for you
7bb2b10c
LC
470(@pxref{Formatting Code}).
471
4feb589b
PN
472@item
473When possible, use mirrors in the source URL (@pxref{Invoking guix download}).
474Use reliable URLs, not generated ones. For instance, GitHub archives are not
475necessarily identical from one generation to the next, so in this case it's
476often better to clone the repository. Don't use the @command{name} field in
477the URL: it is not very useful and if the name changes, the URL will probably
478be wrong.
479
dc56dc02
PN
480@item
481Try to minimize the weight of the inputs to make the transitive closure as
482small as possible (@pxref{Invoking guix size}). Use @command{native-inputs}
483and @command{inputs} appropriately. It's sometimes sufficient to use the
484@command{-minimal} version of a package as input, e.g. @command{bash-minimal}
485instead of @command{bash}. In particular, avoid adding @command{texlive} as a
486dependency: because of its extreme size, it's both heavy on the build farms
487and on the users who would like to build or hack the package from source. Use
488@command{texlive-tiny} or @command{texlive-union} instead.
489
fcc58db6
LC
490@end enumerate
491
a40424bd
CM
492When posting a patch to the mailing list, use @samp{[PATCH] @dots{}} as
493a subject. You may use your email client or the @command{git
5a183a1e
JN
494send-email} command (@pxref{Sending a Patch Series}). We prefer to get
495patches in plain text messages, either inline or as MIME attachments.
496You are advised to pay attention if your email client changes anything
497like line breaks or indentation which could potentially break the
498patches.
499
4619b59c
JN
500When a bug is resolved, please close the thread by sending an email to
501@email{@var{NNN}-done@@debbugs.gnu.org}.
502
5a183a1e
JN
503@unnumberedsubsec Sending a Patch Series
504@anchor{Sending a Patch Series}
505@cindex patch series
506@cindex @code{git send-email}
507@cindex @code{git-send-email}
508
509When sending a patch series (e.g., using @code{git send-email}), please
510first send one message to @email{guix-patches@@gnu.org}, and then send
511subsequent patches to @email{@var{NNN}@@debbugs.gnu.org} to make sure
512they are kept together. See
513@uref{https://debbugs.gnu.org/Advanced.html, the Debbugs documentation}
514for more information.
515@c Debbugs bug: https://debbugs.gnu.org/db/15/15361.html