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