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