gnu: Add r-depecher.
[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.
afe7408e 26* Packaging Guidelines:: Growing the distribution.
8c01b9d0
ML
27* Coding Style:: Hygiene of the contributor.
28* Submitting Patches:: Share your work.
29@end menu
30
31@node Building from Git
32@section Building from Git
33
34If you want to hack Guix itself, it is recommended to use the latest
dbfcadfc
LC
35version from the Git repository:
36
37@example
38git clone https://git.savannah.gnu.org/git/guix.git
39@end example
40
5fb95cc5
LC
41The easiest way to set up a development environment for Guix is, of
42course, by using Guix! The following command starts a new shell where
43all the dependencies and appropriate environment variables are set up to
44hack on Guix:
8c01b9d0 45
5fb95cc5 46@example
43ec98ef 47guix environment guix --pure
5fb95cc5
LC
48@end example
49
50@xref{Invoking guix environment}, for more information on that command.
0636742b
FP
51
52If you are unable to use Guix when building Guix from a checkout, the
53following are the required packages in addition to those mentioned in the
54installation instructions (@pxref{Requirements}).
55
56@itemize
57@item @url{http://gnu.org/software/autoconf/, GNU Autoconf};
58@item @url{http://gnu.org/software/automake/, GNU Automake};
59@item @url{http://gnu.org/software/gettext/, GNU Gettext};
60@item @url{http://gnu.org/software/texinfo/, GNU Texinfo};
61@item @url{http://www.graphviz.org/, Graphviz};
62@item @url{http://www.gnu.org/software/help2man/, GNU Help2man (optional)}.
63@end itemize
64
65On Guix, extra dependencies can be added by instead running @command{guix
66environment} with @option{--ad-hoc}:
5fb95cc5
LC
67
68@example
43ec98ef 69guix environment guix --pure --ad-hoc help2man git strace
5fb95cc5
LC
70@end example
71
72Run @command{./bootstrap} to generate the build system infrastructure
73using Autoconf and Automake. If you get an error like this one:
8c01b9d0
ML
74
75@example
76configure.ac:46: error: possibly undefined macro: PKG_CHECK_MODULES
77@end example
78
5fb95cc5 79@noindent
8c01b9d0 80it probably means that Autoconf couldn’t find @file{pkg.m4}, which is
5fb95cc5
LC
81provided by pkg-config. Make sure that @file{pkg.m4} is available. The
82same holds for the @file{guile.m4} set of macros provided by Guile. For
83instance, if you installed Automake in @file{/usr/local}, it wouldn’t
84look for @file{.m4} files in @file{/usr/share}. In that case, you have
85to invoke the following command:
8c01b9d0
ML
86
87@example
88export ACLOCAL_PATH=/usr/share/aclocal
89@end example
90
aabe6d38 91@xref{Macro Search Path,,, automake, The GNU Automake Manual}, for
8c01b9d0
ML
92more information.
93
3a25c631
LC
94Then, run @command{./configure} as usual. Make sure to pass
95@code{--localstatedir=@var{directory}} where @var{directory} is the
96@code{localstatedir} value used by your current installation (@pxref{The
97Store}, for information about this).
8c01b9d0 98
3a25c631
LC
99Finally, you have to invoke @code{make check} to run tests
100(@pxref{Running the Test Suite}). If anything
8c01b9d0
ML
101fails, take a look at installation instructions (@pxref{Installation})
102or send a message to the @email{guix-devel@@gnu.org, mailing list}.
103
104
105@node Running Guix Before It Is Installed
106@section Running Guix Before It Is Installed
107
108In order to keep a sane working environment, you will find it useful to
109test the changes made in your local source tree checkout without
110actually installing them. So that you can distinguish between your
111``end-user'' hat and your ``motley'' costume.
112
113To that end, all the command-line tools can be used even if you have not
0207768f
LC
114run @code{make install}. To do that, you first need to have an environment
115with all the dependencies available (@pxref{Building from Git}), and then
116simply prefix each command with
8c01b9d0 117@command{./pre-inst-env} (the @file{pre-inst-env} script lives in the
0636742b
FP
118top build tree of Guix; it is generated by @command{./configure}).
119An example@footnote{The @option{-E} flag to
67441b9a
LC
120@command{sudo} guarantees that @code{GUILE_LOAD_PATH} is correctly set
121such that @command{guix-daemon} and the tools it uses can find the Guile
122modules they need.}:
8c01b9d0
ML
123
124@example
67441b9a 125$ sudo -E ./pre-inst-env guix-daemon --build-users-group=guixbuild
8c01b9d0
ML
126$ ./pre-inst-env guix build hello
127@end example
128
129@noindent
0636742b 130Similarly, an example for a Guile session using the Guix modules:
8c01b9d0
ML
131
132@example
133$ ./pre-inst-env guile -c '(use-modules (guix utils)) (pk (%current-system))'
96856613
LC
134
135;;; ("x86_64-linux")
136@end example
137
138@noindent
139@cindex REPL
140@cindex read-eval-print loop
141@dots{} and for a REPL (@pxref{Using Guile Interactively,,, guile, Guile
142Reference Manual}):
143
144@example
145$ ./pre-inst-env guile
146scheme@@(guile-user)> ,use(guix)
147scheme@@(guile-user)> ,use(gnu)
148scheme@@(guile-user)> (define snakes
149 (fold-packages
150 (lambda (package lst)
151 (if (string-prefix? "python"
152 (package-name package))
153 (cons package lst)
154 lst))
155 '()))
156scheme@@(guile-user)> (length snakes)
157$1 = 361
8c01b9d0
ML
158@end example
159
160The @command{pre-inst-env} script sets up all the environment variables
161necessary to support this, including @env{PATH} and @env{GUILE_LOAD_PATH}.
162
ef54b61d 163Note that @command{./pre-inst-env guix pull} does @emph{not} upgrade the
75e24d7b 164local source tree; it simply updates the @file{~/.config/guix/current}
ef54b61d 165symlink (@pxref{Invoking guix pull}). Run @command{git pull} instead if
75e24d7b 166you want to upgrade your local source tree.
ef54b61d 167
8c01b9d0
ML
168
169@node The Perfect Setup
170@section The Perfect Setup
171
172The Perfect Setup to hack on Guix is basically the perfect setup used
173for Guile hacking (@pxref{Using Guile in Emacs,,, guile, Guile Reference
174Manual}). First, you need more than an editor, you need
175@url{http://www.gnu.org/software/emacs, Emacs}, empowered by the
f73ab814
LC
176wonderful @url{http://nongnu.org/geiser/, Geiser}. To set that up, run:
177
178@example
179guix package -i emacs guile emacs-geiser
180@end example
8c01b9d0
ML
181
182Geiser allows for interactive and incremental development from within
183Emacs: code compilation and evaluation from within buffers, access to
184on-line documentation (docstrings), context-sensitive completion,
185@kbd{M-.} to jump to an object definition, a REPL to try out your code,
186and more (@pxref{Introduction,,, geiser, Geiser User Manual}). For
187convenient Guix development, make sure to augment Guile’s load path so
188that it finds source files from your checkout:
189
190@lisp
191;; @r{Assuming the Guix checkout is in ~/src/guix.}
bb38ece4
AK
192(with-eval-after-load 'geiser-guile
193 (add-to-list 'geiser-guile-load-path "~/src/guix"))
8c01b9d0
ML
194@end lisp
195
196To actually edit the code, Emacs already has a neat Scheme mode. But in
197addition to that, you must not miss
198@url{http://www.emacswiki.org/emacs/ParEdit, Paredit}. It provides
199facilities to directly operate on the syntax tree, such as raising an
200s-expression or wrapping it, swallowing or rejecting the following
201s-expression, etc.
202
42cdcdff
RW
203@cindex code snippets
204@cindex templates
205@cindex reducing boilerplate
206We also provide templates for common git commit messages and package
207definitions in the @file{etc/snippets} directory. These templates can
208be used with @url{http://joaotavora.github.io/yasnippet/, YASnippet} to
209expand short trigger strings to interactive text snippets. You may want
210to add the snippets directory to the @var{yas-snippet-dirs} variable in
211Emacs.
212
213@lisp
214;; @r{Assuming the Guix checkout is in ~/src/guix.}
215(with-eval-after-load 'yasnippet
216 (add-to-list 'yas-snippet-dirs "~/src/guix/etc/snippets"))
217@end lisp
218
219The commit message snippets depend on @url{https://magit.vc/, Magit} to
220display staged files. When editing a commit message type @code{add}
221followed by @kbd{TAB} to insert a commit message template for adding a
222package; type @code{update} followed by @kbd{TAB} to insert a template
9286c295
AI
223for updating a package; type @code{https} followed by @kbd{TAB} to
224insert a template for changing the home page URI of a package to HTTPS.
42cdcdff
RW
225
226The main snippet for @code{scheme-mode} is triggered by typing
227@code{package...} followed by @kbd{TAB}. This snippet also inserts the
228trigger string @code{origin...}, which can be expanded further. The
229@code{origin} snippet in turn may insert other trigger strings ending on
230@code{...}, which also can be expanded further.
231
8c01b9d0 232
afe7408e
LC
233@node Packaging Guidelines
234@section Packaging Guidelines
235
236@cindex packages, creating
237The GNU distribution is nascent and may well lack some of your favorite
238packages. This section describes how you can help make the distribution
239grow.
240
241Free software packages are usually distributed in the form of
242@dfn{source code tarballs}---typically @file{tar.gz} files that contain
243all the source files. Adding a package to the distribution means
244essentially two things: adding a @dfn{recipe} that describes how to
245build the package, including a list of other packages required to build
246it, and adding @dfn{package metadata} along with that recipe, such as a
247description and licensing information.
248
249In Guix all this information is embodied in @dfn{package definitions}.
250Package definitions provide a high-level view of the package. They are
251written using the syntax of the Scheme programming language; in fact,
252for each package we define a variable bound to the package definition,
253and export that variable from a module (@pxref{Package Modules}).
254However, in-depth Scheme knowledge is @emph{not} a prerequisite for
255creating packages. For more information on package definitions,
256@pxref{Defining Packages}.
257
258Once a package definition is in place, stored in a file in the Guix
259source tree, it can be tested using the @command{guix build} command
260(@pxref{Invoking guix build}). For example, assuming the new package is
261called @code{gnew}, you may run this command from the Guix build tree
262(@pxref{Running Guix Before It Is Installed}):
263
264@example
265./pre-inst-env guix build gnew --keep-failed
266@end example
267
268Using @code{--keep-failed} makes it easier to debug build failures since
269it provides access to the failed build tree. Another useful
270command-line option when debugging is @code{--log-file}, to access the
271build log.
272
273If the package is unknown to the @command{guix} command, it may be that
274the source file contains a syntax error, or lacks a @code{define-public}
275clause to export the package variable. To figure it out, you may load
276the module from Guile to get more information about the actual error:
277
278@example
279./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
280@end example
281
282Once your package builds correctly, please send us a patch
283(@pxref{Submitting Patches}). Well, if you need help, we will be happy to
284help you too. Once the patch is committed in the Guix repository, the
285new package automatically gets built on the supported platforms by
44b5f28a 286@url{@value{SUBSTITUTE-SERVER}, our continuous integration system}.
afe7408e
LC
287
288@cindex substituter
289Users can obtain the new package definition simply by running
290@command{guix pull} (@pxref{Invoking guix pull}). When
291@code{@value{SUBSTITUTE-SERVER}} is done building the package, installing the
292package automatically downloads binaries from there
293(@pxref{Substitutes}). The only place where human intervention is
294needed is to review and apply the patch.
295
296
297@menu
298* Software Freedom:: What may go into the distribution.
299* Package Naming:: What's in a name?
300* Version Numbers:: When the name is not enough.
301* Synopses and Descriptions:: Helping users find the right package.
302* Python Modules:: A touch of British comedy.
303* Perl Modules:: Little pearls.
304* Java Packages:: Coffee break.
305* Fonts:: Fond of fonts.
306@end menu
307
308@node Software Freedom
309@subsection Software Freedom
310
311@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
312@cindex free software
313The GNU operating system has been developed so that users can have
314freedom in their computing. GNU is @dfn{free software}, meaning that
315users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
316essential freedoms}: to run the program, to study and change the program
317in source code form, to redistribute exact copies, and to distribute
318modified versions. Packages found in the GNU distribution provide only
319software that conveys these four freedoms.
320
321In addition, the GNU distribution follow the
322@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
323software distribution guidelines}. Among other things, these guidelines
324reject non-free firmware, recommendations of non-free software, and
325discuss ways to deal with trademarks and patents.
326
327Some otherwise free upstream package sources contain a small and optional
328subset that violates the above guidelines, for instance because this subset
329is itself non-free code. When that happens, the offending items are removed
330with appropriate patches or code snippets in the @code{origin} form of the
331package (@pxref{Defining Packages}). This way, @code{guix
332build --source} returns the ``freed'' source rather than the unmodified
333upstream source.
334
335
336@node Package Naming
337@subsection Package Naming
338
339@cindex package name
340A package has actually two names associated with it:
341First, there is the name of the @emph{Scheme variable}, the one following
342@code{define-public}. By this name, the package can be made known in the
343Scheme code, for instance as input to another package. Second, there is
344the string in the @code{name} field of a package definition. This name
345is used by package management commands such as
346@command{guix package} and @command{guix build}.
347
348Both are usually the same and correspond to the lowercase conversion of
349the project name chosen upstream, with underscores replaced with
350hyphens. For instance, GNUnet is available as @code{gnunet}, and
351SDL_net as @code{sdl-net}.
352
353We do not add @code{lib} prefixes for library packages, unless these are
354already part of the official project name. But @pxref{Python
355Modules} and @ref{Perl Modules} for special rules concerning modules for
356the Python and Perl languages.
357
358Font package names are handled differently, @pxref{Fonts}.
359
360
361@node Version Numbers
362@subsection Version Numbers
363
364@cindex package version
365We usually package only the latest version of a given free software
366project. But sometimes, for instance for incompatible library versions,
367two (or more) versions of the same package are needed. These require
368different Scheme variable names. We use the name as defined
369in @ref{Package Naming}
370for the most recent version; previous versions use the same name, suffixed
371by @code{-} and the smallest prefix of the version number that may
372distinguish the two versions.
373
374The name inside the package definition is the same for all versions of a
375package and does not contain any version number.
376
377For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
378
379@example
380(define-public gtk+
381 (package
382 (name "gtk+")
383 (version "3.9.12")
384 ...))
385(define-public gtk+-2
386 (package
387 (name "gtk+")
388 (version "2.24.20")
389 ...))
390@end example
391If we also wanted GTK+ 3.8.2, this would be packaged as
392@example
393(define-public gtk+-3.8
394 (package
395 (name "gtk+")
396 (version "3.8.2")
397 ...))
398@end example
399
400@c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
401@c for a discussion of what follows.
402@cindex version number, for VCS snapshots
403Occasionally, we package snapshots of upstream's version control system
404(VCS) instead of formal releases. This should remain exceptional,
405because it is up to upstream developers to clarify what the stable
406release is. Yet, it is sometimes necessary. So, what should we put in
407the @code{version} field?
408
409Clearly, we need to make the commit identifier of the VCS snapshot
410visible in the version string, but we also need to make sure that the
411version string is monotonically increasing so that @command{guix package
412--upgrade} can determine which version is newer. Since commit
413identifiers, notably with Git, are not monotonically increasing, we add
414a revision number that we increase each time we upgrade to a newer
415snapshot. The resulting version string looks like this:
416
417@example
4182.0.11-3.cabba9e
419 ^ ^ ^
420 | | `-- upstream commit ID
421 | |
422 | `--- Guix package revision
423 |
424latest upstream version
425@end example
426
427It is a good idea to strip commit identifiers in the @code{version}
428field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
429aesthetics have a role to play here) as well as problems related to OS
430limits such as the maximum shebang length (127 bytes for the Linux
431kernel.) It is best to use the full commit identifiers in
432@code{origin}s, though, to avoid ambiguities. A typical package
433definition may look like this:
434
435@example
436(define my-package
437 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7")
438 (revision "1")) ;Guix package revision
439 (package
440 (version (git-version "0.9" revision commit))
441 (source (origin
442 (method git-fetch)
443 (uri (git-reference
444 (url "git://example.org/my-package.git")
445 (commit commit)))
446 (sha256 (base32 "1mbikn@dots{}"))
447 (file-name (git-file-name name version))))
448 ;; @dots{}
449 )))
450@end example
451
452@node Synopses and Descriptions
453@subsection Synopses and Descriptions
454
455@cindex package description
456@cindex package synopsis
457As we have seen before, each package in GNU@tie{}Guix includes a
458synopsis and a description (@pxref{Defining Packages}). Synopses and
459descriptions are important: They are what @command{guix package
460--search} searches, and a crucial piece of information to help users
461determine whether a given package suits their needs. Consequently,
462packagers should pay attention to what goes into them.
463
464Synopses must start with a capital letter and must not end with a
465period. They must not start with ``a'' or ``the'', which usually does
466not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
467tool that frobs files''. The synopsis should say what the package
468is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
469used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
470matching a pattern''.
471
472Keep in mind that the synopsis must be meaningful for a very wide
473audience. For example, ``Manipulate alignments in the SAM format''
474might make sense for a seasoned bioinformatics researcher, but might be
475fairly unhelpful or even misleading to a non-specialized audience. It
476is a good idea to come up with a synopsis that gives an idea of the
477application domain of the package. In this example, this might give
478something like ``Manipulate nucleotide sequence alignments'', which
479hopefully gives the user a better idea of whether this is what they are
480looking for.
481
482Descriptions should take between five and ten lines. Use full
483sentences, and avoid using acronyms without first introducing them.
484Please avoid marketing phrases such as ``world-leading'',
485``industrial-strength'', and ``next-generation'', and avoid superlatives
486like ``the most advanced''---they are not helpful to users looking for a
487package and may even sound suspicious. Instead, try to be factual,
488mentioning use cases and features.
489
490@cindex Texinfo markup, in package descriptions
491Descriptions can include Texinfo markup, which is useful to introduce
492ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
493hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
494should be careful when using some characters for example @samp{@@} and
495curly braces which are the basic special characters in Texinfo
496(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
497such as @command{guix package --show} take care of rendering it
498appropriately.
499
500Synopses and descriptions are translated by volunteers
501@uref{http://translationproject.org/domain/guix-packages.html, at the
502Translation Project} so that as many users as possible can read them in
503their native language. User interfaces search them and display them in
504the language specified by the current locale.
505
506To allow @command{xgettext} to extract them as translatable strings,
507synopses and descriptions @emph{must be literal strings}. This means
508that you cannot use @code{string-append} or @code{format} to construct
509these strings:
510
511@lisp
512(package
513 ;; @dots{}
514 (synopsis "This is translatable")
515 (description (string-append "This is " "*not*" " translatable.")))
516@end lisp
517
518Translation is a lot of work so, as a packager, please pay even more
519attention to your synopses and descriptions as every change may entail
520additional work for translators. In order to help them, it is possible
521to make recommendations or instructions visible to them by inserting
522special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
523Gettext}):
524
525@example
526;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
527(description "ARandR is designed to provide a simple visual front end
528for the X11 resize-and-rotate (RandR) extension. @dots{}")
529@end example
530
531
532@node Python Modules
533@subsection Python Modules
534
535@cindex python
536We currently package Python 2 and Python 3, under the Scheme variable names
537@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
538To avoid confusion and naming clashes with other programming languages, it
539seems desirable that the name of a package for a Python module contains
540the word @code{python}.
541
542Some modules are compatible with only one version of Python, others with both.
543If the package Foo compiles only with Python 3, we name it
544@code{python-foo}; if it compiles only with Python 2, we name it
545@code{python2-foo}. If it is compatible with both versions, we create two
546packages with the corresponding names.
547
548If a project already contains the word @code{python}, we drop this;
549for instance, the module python-dateutil is packaged under the names
550@code{python-dateutil} and @code{python2-dateutil}. If the project name
551starts with @code{py} (e.g.@: @code{pytz}), we keep it and prefix it as
552described above.
553
554@subsubsection Specifying Dependencies
555@cindex inputs, for Python packages
556
557Dependency information for Python packages is usually available in the
558package source tree, with varying degrees of accuracy: in the
559@file{setup.py} file, in @file{requirements.txt}, or in @file{tox.ini}.
560
561Your mission, when writing a recipe for a Python package, is to map
562these dependencies to the appropriate type of ``input'' (@pxref{package
563Reference, inputs}). Although the @code{pypi} importer normally does a
564good job (@pxref{Invoking guix import}), you may want to check the
565following check list to determine which dependency goes where.
566
567@itemize
568
569@item
570We currently package Python 2 with @code{setuptools} and @code{pip}
571installed like Python 3.4 has per default. Thus you don't need to
572specify either of these as an input. @command{guix lint} will warn you
573if you do.
574
575@item
576Python dependencies required at run time go into
577@code{propagated-inputs}. They are typically defined with the
578@code{install_requires} keyword in @file{setup.py}, or in the
579@file{requirements.txt} file.
580
581@item
582Python packages required only at build time---e.g., those listed with
583the @code{setup_requires} keyword in @file{setup.py}---or only for
584testing---e.g., those in @code{tests_require}---go into
585@code{native-inputs}. The rationale is that (1) they do not need to be
586propagated because they are not needed at run time, and (2) in a
587cross-compilation context, it's the ``native'' input that we'd want.
588
589Examples are the @code{pytest}, @code{mock}, and @code{nose} test
590frameworks. Of course if any of these packages is also required at
591run-time, it needs to go to @code{propagated-inputs}.
592
593@item
594Anything that does not fall in the previous categories goes to
595@code{inputs}, for example programs or C libraries required for building
596Python packages containing C extensions.
597
598@item
599If a Python package has optional dependencies (@code{extras_require}),
600it is up to you to decide whether to add them or not, based on their
601usefulness/overhead ratio (@pxref{Submitting Patches, @command{guix
602size}}).
603
604@end itemize
605
606
607@node Perl Modules
608@subsection Perl Modules
609
610@cindex perl
611Perl programs standing for themselves are named as any other package,
612using the lowercase upstream name.
613For Perl packages containing a single class, we use the lowercase class name,
614replace all occurrences of @code{::} by dashes and prepend the prefix
615@code{perl-}.
616So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
617Modules containing several classes keep their lowercase upstream name and
618are also prepended by @code{perl-}. Such modules tend to have the word
619@code{perl} somewhere in their name, which gets dropped in favor of the
620prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
621
622
623@node Java Packages
624@subsection Java Packages
625
626@cindex java
627Java programs standing for themselves are named as any other package,
628using the lowercase upstream name.
629
630To avoid confusion and naming clashes with other programming languages,
631it is desirable that the name of a package for a Java package is
632prefixed with @code{java-}. If a project already contains the word
633@code{java}, we drop this; for instance, the package @code{ngsjava} is
634packaged under the name @code{java-ngs}.
635
636For Java packages containing a single class or a small class hierarchy,
637we use the lowercase class name, replace all occurrences of @code{.} by
638dashes and prepend the prefix @code{java-}. So the class
639@code{apache.commons.cli} becomes package
640@code{java-apache-commons-cli}.
641
642
643@node Fonts
644@subsection Fonts
645
646@cindex fonts
647For fonts that are in general not installed by a user for typesetting
648purposes, or that are distributed as part of a larger software package,
649we rely on the general packaging rules for software; for instance, this
650applies to the fonts delivered as part of the X.Org system or fonts that
651are part of TeX Live.
652
653To make it easier for a user to search for fonts, names for other packages
654containing only fonts are constructed as follows, independently of the
655upstream package name.
656
657The name of a package containing only one font family starts with
658@code{font-}; it is followed by the foundry name and a dash @code{-}
659if the foundry is known, and the font family name, in which spaces are
660replaced by dashes (and as usual, all upper case letters are transformed
661to lower case).
662For example, the Gentium font family by SIL is packaged under the name
663@code{font-sil-gentium}.
664
665For a package containing several font families, the name of the collection
666is used in the place of the font family name.
667For instance, the Liberation fonts consist of three families,
668Liberation Sans, Liberation Serif and Liberation Mono.
669These could be packaged separately under the names
670@code{font-liberation-sans} and so on; but as they are distributed together
671under a common name, we prefer to package them together as
672@code{font-liberation}.
673
674In the case where several formats of the same font family or font collection
675are packaged separately, a short form of the format, prepended by a dash,
676is added to the package name. We use @code{-ttf} for TrueType fonts,
677@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
678fonts.
679
680
8c01b9d0
ML
681@node Coding Style
682@section Coding Style
683
684In general our code follows the GNU Coding Standards (@pxref{Top,,,
685standards, GNU Coding Standards}). However, they do not say much about
686Scheme, so here are some additional rules.
687
688@menu
689* Programming Paradigm:: How to compose your elements.
690* Modules:: Where to store your code?
691* Data Types and Pattern Matching:: Implementing data structures.
692* Formatting Code:: Writing conventions.
693@end menu
694
695@node Programming Paradigm
696@subsection Programming Paradigm
697
698Scheme code in Guix is written in a purely functional style. One
699exception is code that involves input/output, and procedures that
700implement low-level concepts, such as the @code{memoize} procedure.
701
702@node Modules
703@subsection Modules
704
705Guile modules that are meant to be used on the builder side must live in
706the @code{(guix build @dots{})} name space. They must not refer to
707other Guix or GNU modules. However, it is OK for a ``host-side'' module
708to use a build-side module.
709
710Modules that deal with the broader GNU system should be in the
711@code{(gnu @dots{})} name space rather than @code{(guix @dots{})}.
712
713@node Data Types and Pattern Matching
714@subsection Data Types and Pattern Matching
715
716The tendency in classical Lisp is to use lists to represent everything,
717and then to browse them ``by hand'' using @code{car}, @code{cdr},
718@code{cadr}, and co. There are several problems with that style,
719notably the fact that it is hard to read, error-prone, and a hindrance
720to proper type error reports.
721
722Guix code should define appropriate data types (for instance, using
723@code{define-record-type*}) rather than abuse lists. In addition, it
724should use pattern matching, via Guile’s @code{(ice-9 match)} module,
725especially when matching lists.
726
727@node Formatting Code
728@subsection Formatting Code
729
7bb2b10c
LC
730@cindex formatting code
731@cindex coding style
8c01b9d0
ML
732When writing Scheme code, we follow common wisdom among Scheme
733programmers. In general, we follow the
734@url{http://mumble.net/~campbell/scheme/style.txt, Riastradh's Lisp
735Style Rules}. This document happens to describe the conventions mostly
736used in Guile’s code too. It is very thoughtful and well written, so
737please do read it.
738
739Some special forms introduced in Guix, such as the @code{substitute*}
740macro, have special indentation rules. These are defined in the
8ca0c88a
AK
741@file{.dir-locals.el} file, which Emacs automatically uses. Also note
742that Emacs-Guix provides @code{guix-devel-mode} mode that indents and
743highlights Guix code properly (@pxref{Development,,, emacs-guix, The
744Emacs-Guix Reference Manual}).
7bb2b10c
LC
745
746@cindex indentation, of code
747@cindex formatting, of code
748If you do not use Emacs, please make sure to let your editor knows these
749rules. To automatically indent a package definition, you can also run:
750
751@example
557d9c8d 752./etc/indent-code.el gnu/packages/@var{file}.scm @var{package}
7bb2b10c
LC
753@end example
754
755@noindent
756This automatically indents the definition of @var{package} in
557d9c8d
LC
757@file{gnu/packages/@var{file}.scm} by running Emacs in batch mode. To
758indent a whole file, omit the second argument:
759
760@example
761./etc/indent-code.el gnu/services/@var{file}.scm
762@end example
8c01b9d0 763
60912a88
LC
764@cindex Vim, Scheme code editing
765If you are editing code with Vim, we recommend that you run @code{:set
766autoindent} so that your code is automatically indented as you type.
767Additionally,
768@uref{https://www.vim.org/scripts/script.php?script_id=3998,
769@code{paredit.vim}} may help you deal with all these parentheses.
770
8c01b9d0
ML
771We require all top-level procedures to carry a docstring. This
772requirement can be relaxed for simple private procedures in the
773@code{(guix build @dots{})} name space, though.
774
775Procedures should not have more than four positional parameters. Use
776keyword parameters for procedures that take more than four parameters.
777
778
779@node Submitting Patches
780@section Submitting Patches
781
782Development is done using the Git distributed version control system.
783Thus, access to the repository is not strictly necessary. We welcome
784contributions in the form of patches as produced by @code{git
230efa87
LC
785format-patch} sent to the @email{guix-patches@@gnu.org} mailing list.
786
787This mailing list is backed by a Debbugs instance accessible at
788@uref{https://bugs.gnu.org/guix-patches}, which allows us to keep track
789of submissions. Each message sent to that mailing list gets a new
790tracking number assigned; people can then follow up on the submission by
791sending email to @code{@var{NNN}@@debbugs.gnu.org}, where @var{NNN} is
5a183a1e 792the tracking number (@pxref{Sending a Patch Series}).
230efa87 793
8c01b9d0
ML
794Please write commit logs in the ChangeLog format (@pxref{Change Logs,,,
795standards, GNU Coding Standards}); you can check the commit history for
796examples.
797
798Before submitting a patch that adds or modifies a package definition,
fcc58db6
LC
799please run through this check list:
800
801@enumerate
308c08d3
RW
802@item
803If the authors of the packaged software provide a cryptographic
804signature for the release tarball, make an effort to verify the
805authenticity of the archive. For a detached GPG signature file this
806would be done with the @code{gpg --verify} command.
807
cbd02397
LC
808@item
809Take some time to provide an adequate synopsis and description for the
810package. @xref{Synopses and Descriptions}, for some guidelines.
811
fcc58db6
LC
812@item
813Run @code{guix lint @var{package}}, where @var{package} is the
8c01b9d0 814name of the new or modified package, and fix any errors it reports
fcc58db6
LC
815(@pxref{Invoking guix lint}).
816
817@item
818Make sure the package builds on your platform, using @code{guix build
819@var{package}}.
820
89339a35
DM
821@item
822We recommend you also try building the package on other supported
823platforms. As you may not have access to actual hardware platforms, we
824recommend using the @code{qemu-binfmt-service-type} to emulate them. In
825order to enable it, add the following service to the list of services in
826your @code{operating-system} configuration:
827
828@example
829(service qemu-binfmt-service-type
830 (qemu-binfmt-configuration
b28e4e3c 831 (platforms (lookup-qemu-platforms "arm" "aarch64" "mips64el"))
89339a35
DM
832 (guix-support? #t)))
833@end example
834
835Then reconfigure your system.
836
837You can then build packages for different platforms by specifying the
838@code{--system} option. For example, to build the "hello" package for
b28e4e3c
EF
839the armhf, aarch64, or mips64 architectures, you would run the following
840commands, respectively:
89339a35
DM
841@example
842guix build --system=armhf-linux --rounds=2 hello
843guix build --system=aarch64-linux --rounds=2 hello
89339a35
DM
844guix build --system=mips64el-linux --rounds=2 hello
845@end example
846
d222522e
LC
847@item
848@cindex bundling
849Make sure the package does not use bundled copies of software already
850available as separate packages.
851
852Sometimes, packages include copies of the source code of their
853dependencies as a convenience for users. However, as a distribution, we
854want to make sure that such packages end up using the copy we already
855have in the distribution, if there is one. This improves resource usage
856(the dependency is built and stored only once), and allows the
857distribution to make transverse changes such as applying security
858updates for a given software package in a single place and have them
859affect the whole system---something that bundled copies prevent.
860
fcc58db6
LC
861@item
862Take a look at the profile reported by @command{guix size}
863(@pxref{Invoking guix size}). This will allow you to notice references
864to other packages unwillingly retained. It may also help determine
865whether to split the package (@pxref{Packages with Multiple Outputs}),
024e358c 866and which optional dependencies should be used. In particular, avoid adding
0afeb746
PN
867@code{texlive} as a dependency: because of its extreme size, use
868@code{texlive-tiny} or @code{texlive-union} instead.
fcc58db6
LC
869
870@item
871For important changes, check that dependent package (if applicable) are
872not affected by the change; @code{guix refresh --list-dependent
8c01b9d0
ML
873@var{package}} will help you do that (@pxref{Invoking guix refresh}).
874
916b5eba
LC
875@c See <https://lists.gnu.org/archive/html/guix-devel/2016-10/msg00933.html>.
876@cindex branching strategy
877@cindex rebuild scheduling strategy
878Depending on the number of dependent packages and thus the amount of
879rebuilding induced, commits go to different branches, along these lines:
880
881@table @asis
882@item 300 dependent packages or less
883@code{master} branch (non-disruptive changes).
884
885@item between 300 and 1,200 dependent packages
886@code{staging} branch (non-disruptive changes). This branch is intended
887to be merged in @code{master} every 3 weeks or so. Topical changes
888(e.g., an update of the GNOME stack) can instead go to a specific branch
889(say, @code{gnome-updates}).
890
891@item more than 1,200 dependent packages
892@code{core-updates} branch (may include major and potentially disruptive
893changes). This branch is intended to be merged in @code{master} every
8942.5 months or so.
895@end table
896
44b5f28a 897All these branches are @uref{@value{SUBSTITUTE-SERVER},
38ab778f 898tracked by our build farm} and merged into @code{master} once
189b1543
LC
899everything has been successfully built. This allows us to fix issues
900before they hit users, and to reduce the window during which pre-built
901binaries are not available.
902
38ab778f
MB
903Generally, branches other than @code{master} are considered
904@emph{frozen} if there has been a recent evaluation, or there is a
905corresponding @code{-next} branch. Please ask on the mailing list or
906IRC if unsure where to place a patch.
907@c TODO: It would be good with badges on the website that tracks these
908@c branches. Or maybe even a status page.
909
d23c20f1 910@item
5b74fe06
LC
911@cindex determinism, of build processes
912@cindex reproducible builds, checking
d23c20f1
LC
913Check whether the package's build process is deterministic. This
914typically means checking whether an independent build of the package
915yields the exact same result that you obtained, bit for bit.
916
5b74fe06
LC
917A simple way to do that is by building the same package several times in
918a row on your machine (@pxref{Invoking guix build}):
919
920@example
921guix build --rounds=2 my-package
922@end example
923
924This is enough to catch a class of common non-determinism issues, such
925as timestamps or randomly-generated output in the build result.
926
927Another option is to use @command{guix challenge} (@pxref{Invoking guix
928challenge}). You may run it once the package has been committed and
0bc02bec 929built by @code{@value{SUBSTITUTE-SERVER}} to check whether it obtains the same
5b74fe06
LC
930result as you did. Better yet: Find another machine that can build it
931and run @command{guix publish}. Since the remote build machine is
932likely different from yours, this can catch non-determinism issues
933related to the hardware---e.g., use of different instruction set
934extensions---or to the operating system kernel---e.g., reliance on
935@code{uname} or @file{/proc} files.
d23c20f1 936
3c2d03a2
LC
937@item
938When writing documentation, please use gender-neutral wording when
939referring to people, such as
940@uref{https://en.wikipedia.org/wiki/Singular_they, singular
941``they''@comma{} ``their''@comma{} ``them''}, and so forth.
942
3a78fab8 943@item
944Verify that your patch contains only one set of related changes.
945Bundling unrelated changes together makes reviewing harder and slower.
946
947Examples of unrelated changes include the addition of several packages,
948or a package update along with fixes to that package.
949
7bb2b10c
LC
950@item
951Please follow our code formatting rules, possibly running the
557d9c8d 952@command{etc/indent-code.el} script to do that automatically for you
7bb2b10c
LC
953(@pxref{Formatting Code}).
954
4feb589b
PN
955@item
956When possible, use mirrors in the source URL (@pxref{Invoking guix download}).
957Use reliable URLs, not generated ones. For instance, GitHub archives are not
958necessarily identical from one generation to the next, so in this case it's
959often better to clone the repository. Don't use the @command{name} field in
960the URL: it is not very useful and if the name changes, the URL will probably
961be wrong.
962
fcc58db6
LC
963@end enumerate
964
a40424bd
CM
965When posting a patch to the mailing list, use @samp{[PATCH] @dots{}} as
966a subject. You may use your email client or the @command{git
5a183a1e
JN
967send-email} command (@pxref{Sending a Patch Series}). We prefer to get
968patches in plain text messages, either inline or as MIME attachments.
969You are advised to pay attention if your email client changes anything
970like line breaks or indentation which could potentially break the
971patches.
972
4619b59c
JN
973When a bug is resolved, please close the thread by sending an email to
974@email{@var{NNN}-done@@debbugs.gnu.org}.
975
5a183a1e
JN
976@unnumberedsubsec Sending a Patch Series
977@anchor{Sending a Patch Series}
978@cindex patch series
979@cindex @code{git send-email}
980@cindex @code{git-send-email}
981
982When sending a patch series (e.g., using @code{git send-email}), please
983first send one message to @email{guix-patches@@gnu.org}, and then send
984subsequent patches to @email{@var{NNN}@@debbugs.gnu.org} to make sure
985they are kept together. See
986@uref{https://debbugs.gnu.org/Advanced.html, the Debbugs documentation}
fb8b99a5
AB
987for more information. You can install @command{git send-email} with
988@command{guix install git:send-email}.
5a183a1e 989@c Debbugs bug: https://debbugs.gnu.org/db/15/15361.html