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