contributing.texi 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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. * Coding Style:: Hygiene of the contributor.
  23. * Submitting Patches:: Share your work.
  24. @end menu
  25. @node Building from Git
  26. @section Building from Git
  27. If you want to hack Guix itself, it is recommended to use the latest
  28. version from the Git repository:
  29. @example
  30. git clone https://git.savannah.gnu.org/git/guix.git
  31. @end example
  32. When building Guix from a checkout,
  33. the following packages are required in addition to those mentioned in
  34. the installation instructions (@pxref{Requirements}).
  35. @itemize
  36. @item @url{http://gnu.org/software/autoconf/, GNU Autoconf};
  37. @item @url{http://gnu.org/software/automake/, GNU Automake};
  38. @item @url{http://gnu.org/software/gettext/, GNU Gettext};
  39. @item @url{http://gnu.org/software/texinfo/, GNU Texinfo};
  40. @item @url{http://www.graphviz.org/, Graphviz};
  41. @item @url{http://www.gnu.org/software/help2man/, GNU Help2man (optional)}.
  42. @end itemize
  43. The easiest way to set up a development environment for Guix is, of
  44. course, by using Guix! The following command starts a new shell where
  45. all the dependencies and appropriate environment variables are set up to
  46. hack on Guix:
  47. @example
  48. guix environment guix
  49. @end example
  50. @xref{Invoking guix environment}, for more information on that command.
  51. Extra dependencies can be added with @option{--ad-hoc}:
  52. @example
  53. guix environment guix --ad-hoc help2man git strace
  54. @end example
  55. Run @command{./bootstrap} to generate the build system infrastructure
  56. using Autoconf and Automake. If you get an error like this one:
  57. @example
  58. configure.ac:46: error: possibly undefined macro: PKG_CHECK_MODULES
  59. @end example
  60. @noindent
  61. it probably means that Autoconf couldn’t find @file{pkg.m4}, which is
  62. provided by pkg-config. Make sure that @file{pkg.m4} is available. The
  63. same holds for the @file{guile.m4} set of macros provided by Guile. For
  64. instance, if you installed Automake in @file{/usr/local}, it wouldn’t
  65. look for @file{.m4} files in @file{/usr/share}. In that case, you have
  66. to invoke the following command:
  67. @example
  68. export ACLOCAL_PATH=/usr/share/aclocal
  69. @end example
  70. @xref{Macro Search Path,,, automake, The GNU Automake Manual}, for
  71. more information.
  72. Then, run @command{./configure} as usual. Make sure to pass
  73. @code{--localstatedir=@var{directory}} where @var{directory} is the
  74. @code{localstatedir} value used by your current installation (@pxref{The
  75. Store}, for information about this).
  76. Finally, you have to invoke @code{make check} to run tests
  77. (@pxref{Running the Test Suite}). If anything
  78. fails, take a look at installation instructions (@pxref{Installation})
  79. or send a message to the @email{guix-devel@@gnu.org, mailing list}.
  80. @node Running Guix Before It Is Installed
  81. @section Running Guix Before It Is Installed
  82. In order to keep a sane working environment, you will find it useful to
  83. test the changes made in your local source tree checkout without
  84. actually installing them. So that you can distinguish between your
  85. ``end-user'' hat and your ``motley'' costume.
  86. To that end, all the command-line tools can be used even if you have not
  87. run @code{make install}. To do that, prefix each command with
  88. @command{./pre-inst-env} (the @file{pre-inst-env} script lives in the
  89. top build tree of Guix), as in:
  90. @example
  91. $ sudo ./pre-inst-env guix-daemon --build-users-group=guixbuild
  92. $ ./pre-inst-env guix build hello
  93. @end example
  94. @noindent
  95. Similarly, for a Guile session using the Guix modules:
  96. @example
  97. $ ./pre-inst-env guile -c '(use-modules (guix utils)) (pk (%current-system))'
  98. ;;; ("x86_64-linux")
  99. @end example
  100. @noindent
  101. @cindex REPL
  102. @cindex read-eval-print loop
  103. @dots{} and for a REPL (@pxref{Using Guile Interactively,,, guile, Guile
  104. Reference Manual}):
  105. @example
  106. $ ./pre-inst-env guile
  107. scheme@@(guile-user)> ,use(guix)
  108. scheme@@(guile-user)> ,use(gnu)
  109. scheme@@(guile-user)> (define snakes
  110. (fold-packages
  111. (lambda (package lst)
  112. (if (string-prefix? "python"
  113. (package-name package))
  114. (cons package lst)
  115. lst))
  116. '()))
  117. scheme@@(guile-user)> (length snakes)
  118. $1 = 361
  119. @end example
  120. The @command{pre-inst-env} script sets up all the environment variables
  121. necessary to support this, including @env{PATH} and @env{GUILE_LOAD_PATH}.
  122. Note that @command{./pre-inst-env guix pull} does @emph{not} upgrade the
  123. local source tree; it simply updates the @file{~/.config/guix/latest}
  124. symlink (@pxref{Invoking guix pull}). Run @command{git pull} instead if
  125. you want to upgrade your local source tree.@footnote{If you would like
  126. to set up @command{guix} to use your Git checkout, you can point the
  127. @file{~/.config/guix/latest} symlink to your Git checkout directory.
  128. If you are the sole user of your system, you may also consider pointing
  129. the @file{/root/.config/guix/latest} symlink to point to
  130. @file{~/.config/guix/latest}; this way it will always use the same
  131. @command{guix} as your user does.}
  132. @node The Perfect Setup
  133. @section The Perfect Setup
  134. The Perfect Setup to hack on Guix is basically the perfect setup used
  135. for Guile hacking (@pxref{Using Guile in Emacs,,, guile, Guile Reference
  136. Manual}). First, you need more than an editor, you need
  137. @url{http://www.gnu.org/software/emacs, Emacs}, empowered by the
  138. wonderful @url{http://nongnu.org/geiser/, Geiser}.
  139. Geiser allows for interactive and incremental development from within
  140. Emacs: code compilation and evaluation from within buffers, access to
  141. on-line documentation (docstrings), context-sensitive completion,
  142. @kbd{M-.} to jump to an object definition, a REPL to try out your code,
  143. and more (@pxref{Introduction,,, geiser, Geiser User Manual}). For
  144. convenient Guix development, make sure to augment Guile’s load path so
  145. that it finds source files from your checkout:
  146. @lisp
  147. ;; @r{Assuming the Guix checkout is in ~/src/guix.}
  148. (with-eval-after-load 'geiser-guile
  149. (add-to-list 'geiser-guile-load-path "~/src/guix"))
  150. @end lisp
  151. To actually edit the code, Emacs already has a neat Scheme mode. But in
  152. addition to that, you must not miss
  153. @url{http://www.emacswiki.org/emacs/ParEdit, Paredit}. It provides
  154. facilities to directly operate on the syntax tree, such as raising an
  155. s-expression or wrapping it, swallowing or rejecting the following
  156. s-expression, etc.
  157. @cindex code snippets
  158. @cindex templates
  159. @cindex reducing boilerplate
  160. We also provide templates for common git commit messages and package
  161. definitions in the @file{etc/snippets} directory. These templates can
  162. be used with @url{http://joaotavora.github.io/yasnippet/, YASnippet} to
  163. expand short trigger strings to interactive text snippets. You may want
  164. to add the snippets directory to the @var{yas-snippet-dirs} variable in
  165. Emacs.
  166. @lisp
  167. ;; @r{Assuming the Guix checkout is in ~/src/guix.}
  168. (with-eval-after-load 'yasnippet
  169. (add-to-list 'yas-snippet-dirs "~/src/guix/etc/snippets"))
  170. @end lisp
  171. The commit message snippets depend on @url{https://magit.vc/, Magit} to
  172. display staged files. When editing a commit message type @code{add}
  173. followed by @kbd{TAB} to insert a commit message template for adding a
  174. package; type @code{update} followed by @kbd{TAB} to insert a template
  175. for updating a package.
  176. The main snippet for @code{scheme-mode} is triggered by typing
  177. @code{package...} followed by @kbd{TAB}. This snippet also inserts the
  178. trigger string @code{origin...}, which can be expanded further. The
  179. @code{origin} snippet in turn may insert other trigger strings ending on
  180. @code{...}, which also can be expanded further.
  181. @node Coding Style
  182. @section Coding Style
  183. In general our code follows the GNU Coding Standards (@pxref{Top,,,
  184. standards, GNU Coding Standards}). However, they do not say much about
  185. Scheme, so here are some additional rules.
  186. @menu
  187. * Programming Paradigm:: How to compose your elements.
  188. * Modules:: Where to store your code?
  189. * Data Types and Pattern Matching:: Implementing data structures.
  190. * Formatting Code:: Writing conventions.
  191. @end menu
  192. @node Programming Paradigm
  193. @subsection Programming Paradigm
  194. Scheme code in Guix is written in a purely functional style. One
  195. exception is code that involves input/output, and procedures that
  196. implement low-level concepts, such as the @code{memoize} procedure.
  197. @node Modules
  198. @subsection Modules
  199. Guile modules that are meant to be used on the builder side must live in
  200. the @code{(guix build @dots{})} name space. They must not refer to
  201. other Guix or GNU modules. However, it is OK for a ``host-side'' module
  202. to use a build-side module.
  203. Modules that deal with the broader GNU system should be in the
  204. @code{(gnu @dots{})} name space rather than @code{(guix @dots{})}.
  205. @node Data Types and Pattern Matching
  206. @subsection Data Types and Pattern Matching
  207. The tendency in classical Lisp is to use lists to represent everything,
  208. and then to browse them ``by hand'' using @code{car}, @code{cdr},
  209. @code{cadr}, and co. There are several problems with that style,
  210. notably the fact that it is hard to read, error-prone, and a hindrance
  211. to proper type error reports.
  212. Guix code should define appropriate data types (for instance, using
  213. @code{define-record-type*}) rather than abuse lists. In addition, it
  214. should use pattern matching, via Guile’s @code{(ice-9 match)} module,
  215. especially when matching lists.
  216. @node Formatting Code
  217. @subsection Formatting Code
  218. @cindex formatting code
  219. @cindex coding style
  220. When writing Scheme code, we follow common wisdom among Scheme
  221. programmers. In general, we follow the
  222. @url{http://mumble.net/~campbell/scheme/style.txt, Riastradh's Lisp
  223. Style Rules}. This document happens to describe the conventions mostly
  224. used in Guile’s code too. It is very thoughtful and well written, so
  225. please do read it.
  226. Some special forms introduced in Guix, such as the @code{substitute*}
  227. macro, have special indentation rules. These are defined in the
  228. @file{.dir-locals.el} file, which Emacs automatically uses. Also note
  229. that Emacs-Guix provides @code{guix-devel-mode} mode that indents and
  230. highlights Guix code properly (@pxref{Development,,, emacs-guix, The
  231. Emacs-Guix Reference Manual}).
  232. @cindex indentation, of code
  233. @cindex formatting, of code
  234. If you do not use Emacs, please make sure to let your editor knows these
  235. rules. To automatically indent a package definition, you can also run:
  236. @example
  237. ./etc/indent-code.el gnu/packages/@var{file}.scm @var{package}
  238. @end example
  239. @noindent
  240. This automatically indents the definition of @var{package} in
  241. @file{gnu/packages/@var{file}.scm} by running Emacs in batch mode. To
  242. indent a whole file, omit the second argument:
  243. @example
  244. ./etc/indent-code.el gnu/services/@var{file}.scm
  245. @end example
  246. We require all top-level procedures to carry a docstring. This
  247. requirement can be relaxed for simple private procedures in the
  248. @code{(guix build @dots{})} name space, though.
  249. Procedures should not have more than four positional parameters. Use
  250. keyword parameters for procedures that take more than four parameters.
  251. @node Submitting Patches
  252. @section Submitting Patches
  253. Development is done using the Git distributed version control system.
  254. Thus, access to the repository is not strictly necessary. We welcome
  255. contributions in the form of patches as produced by @code{git
  256. format-patch} sent to the @email{guix-patches@@gnu.org} mailing list.
  257. This mailing list is backed by a Debbugs instance accessible at
  258. @uref{https://bugs.gnu.org/guix-patches}, which allows us to keep track
  259. of submissions. Each message sent to that mailing list gets a new
  260. tracking number assigned; people can then follow up on the submission by
  261. sending email to @code{@var{NNN}@@debbugs.gnu.org}, where @var{NNN} is
  262. the tracking number (@pxref{Sending a Patch Series}).
  263. Please write commit logs in the ChangeLog format (@pxref{Change Logs,,,
  264. standards, GNU Coding Standards}); you can check the commit history for
  265. examples.
  266. Before submitting a patch that adds or modifies a package definition,
  267. please run through this check list:
  268. @enumerate
  269. @item
  270. If the authors of the packaged software provide a cryptographic
  271. signature for the release tarball, make an effort to verify the
  272. authenticity of the archive. For a detached GPG signature file this
  273. would be done with the @code{gpg --verify} command.
  274. @item
  275. Take some time to provide an adequate synopsis and description for the
  276. package. @xref{Synopses and Descriptions}, for some guidelines.
  277. @item
  278. Run @code{guix lint @var{package}}, where @var{package} is the
  279. name of the new or modified package, and fix any errors it reports
  280. (@pxref{Invoking guix lint}).
  281. @item
  282. Make sure the package builds on your platform, using @code{guix build
  283. @var{package}}.
  284. @item
  285. @cindex bundling
  286. Make sure the package does not use bundled copies of software already
  287. available as separate packages.
  288. Sometimes, packages include copies of the source code of their
  289. dependencies as a convenience for users. However, as a distribution, we
  290. want to make sure that such packages end up using the copy we already
  291. have in the distribution, if there is one. This improves resource usage
  292. (the dependency is built and stored only once), and allows the
  293. distribution to make transverse changes such as applying security
  294. updates for a given software package in a single place and have them
  295. affect the whole system---something that bundled copies prevent.
  296. @item
  297. Take a look at the profile reported by @command{guix size}
  298. (@pxref{Invoking guix size}). This will allow you to notice references
  299. to other packages unwillingly retained. It may also help determine
  300. whether to split the package (@pxref{Packages with Multiple Outputs}),
  301. and which optional dependencies should be used.
  302. @item
  303. For important changes, check that dependent package (if applicable) are
  304. not affected by the change; @code{guix refresh --list-dependent
  305. @var{package}} will help you do that (@pxref{Invoking guix refresh}).
  306. @c See <https://lists.gnu.org/archive/html/guix-devel/2016-10/msg00933.html>.
  307. @cindex branching strategy
  308. @cindex rebuild scheduling strategy
  309. Depending on the number of dependent packages and thus the amount of
  310. rebuilding induced, commits go to different branches, along these lines:
  311. @table @asis
  312. @item 300 dependent packages or less
  313. @code{master} branch (non-disruptive changes).
  314. @item between 300 and 1,200 dependent packages
  315. @code{staging} branch (non-disruptive changes). This branch is intended
  316. to be merged in @code{master} every 3 weeks or so. Topical changes
  317. (e.g., an update of the GNOME stack) can instead go to a specific branch
  318. (say, @code{gnome-updates}).
  319. @item more than 1,200 dependent packages
  320. @code{core-updates} branch (may include major and potentially disruptive
  321. changes). This branch is intended to be merged in @code{master} every
  322. 2.5 months or so.
  323. @end table
  324. All these branches are tracked by our build farm
  325. and merged into @code{master} once
  326. everything has been successfully built. This allows us to fix issues
  327. before they hit users, and to reduce the window during which pre-built
  328. binaries are not available.
  329. @item
  330. @cindex determinism, of build processes
  331. @cindex reproducible builds, checking
  332. Check whether the package's build process is deterministic. This
  333. typically means checking whether an independent build of the package
  334. yields the exact same result that you obtained, bit for bit.
  335. A simple way to do that is by building the same package several times in
  336. a row on your machine (@pxref{Invoking guix build}):
  337. @example
  338. guix build --rounds=2 my-package
  339. @end example
  340. This is enough to catch a class of common non-determinism issues, such
  341. as timestamps or randomly-generated output in the build result.
  342. Another option is to use @command{guix challenge} (@pxref{Invoking guix
  343. challenge}). You may run it once the package has been committed and
  344. built by @code{hydra.gnu.org} to check whether it obtains the same
  345. result as you did. Better yet: Find another machine that can build it
  346. and run @command{guix publish}. Since the remote build machine is
  347. likely different from yours, this can catch non-determinism issues
  348. related to the hardware---e.g., use of different instruction set
  349. extensions---or to the operating system kernel---e.g., reliance on
  350. @code{uname} or @file{/proc} files.
  351. @item
  352. When writing documentation, please use gender-neutral wording when
  353. referring to people, such as
  354. @uref{https://en.wikipedia.org/wiki/Singular_they, singular
  355. ``they''@comma{} ``their''@comma{} ``them''}, and so forth.
  356. @item
  357. Verify that your patch contains only one set of related changes.
  358. Bundling unrelated changes together makes reviewing harder and slower.
  359. Examples of unrelated changes include the addition of several packages,
  360. or a package update along with fixes to that package.
  361. @item
  362. Please follow our code formatting rules, possibly running the
  363. @command{etc/indent-code.el} script to do that automatically for you
  364. (@pxref{Formatting Code}).
  365. @end enumerate
  366. When posting a patch to the mailing list, use @samp{[PATCH] @dots{}} as
  367. a subject. You may use your email client or the @command{git
  368. send-email} command (@pxref{Sending a Patch Series}). We prefer to get
  369. patches in plain text messages, either inline or as MIME attachments.
  370. You are advised to pay attention if your email client changes anything
  371. like line breaks or indentation which could potentially break the
  372. patches.
  373. When a bug is resolved, please close the thread by sending an email to
  374. @email{@var{NNN}-done@@debbugs.gnu.org}.
  375. @unnumberedsubsec Sending a Patch Series
  376. @anchor{Sending a Patch Series}
  377. @cindex patch series
  378. @cindex @code{git send-email}
  379. @cindex @code{git-send-email}
  380. When sending a patch series (e.g., using @code{git send-email}), please
  381. first send one message to @email{guix-patches@@gnu.org}, and then send
  382. subsequent patches to @email{@var{NNN}@@debbugs.gnu.org} to make sure
  383. they are kept together. See
  384. @uref{https://debbugs.gnu.org/Advanced.html, the Debbugs documentation}
  385. for more information.
  386. @c Debbugs bug: https://debbugs.gnu.org/db/15/15361.html