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