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