contributing.texi 40 KB

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