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 | |
8c01b9d0 ML |
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 | ||
26 | @node Building from Git | |
27 | @section Building from Git | |
28 | ||
29 | If you want to hack Guix itself, it is recommended to use the latest | |
30 | version from the Git repository. When building Guix from a checkout, | |
31 | the following packages are required in addition to those mentioned in | |
32 | the installation instructions (@pxref{Requirements}). | |
33 | ||
34 | @itemize | |
35 | @item @url{http://gnu.org/software/autoconf/, GNU Autoconf}; | |
36 | @item @url{http://gnu.org/software/automake/, GNU Automake}; | |
37 | @item @url{http://gnu.org/software/gettext/, GNU Gettext}; | |
0431ed00 | 38 | @item @url{http://gnu.org/software/texinfo/, GNU Texinfo}; |
8c01b9d0 ML |
39 | @item @url{http://www.graphviz.org/, Graphviz}; |
40 | @item @url{http://www.gnu.org/software/help2man/, GNU Help2man (optional)}. | |
41 | @end itemize | |
42 | ||
5fb95cc5 LC |
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: | |
8c01b9d0 | 47 | |
5fb95cc5 LC |
48 | @example |
49 | guix environment guix | |
50 | @end example | |
51 | ||
52 | @xref{Invoking guix environment}, for more information on that command. | |
53 | Extra dependencies can be added with @option{--ad-hoc}: | |
54 | ||
55 | @example | |
56 | guix environment guix --ad-hoc help2man git strace | |
57 | @end example | |
58 | ||
59 | Run @command{./bootstrap} to generate the build system infrastructure | |
60 | using Autoconf and Automake. If you get an error like this one: | |
8c01b9d0 ML |
61 | |
62 | @example | |
63 | configure.ac:46: error: possibly undefined macro: PKG_CHECK_MODULES | |
64 | @end example | |
65 | ||
5fb95cc5 | 66 | @noindent |
8c01b9d0 | 67 | it probably means that Autoconf couldn’t find @file{pkg.m4}, which is |
5fb95cc5 LC |
68 | provided by pkg-config. Make sure that @file{pkg.m4} is available. The |
69 | same holds for the @file{guile.m4} set of macros provided by Guile. For | |
70 | instance, if you installed Automake in @file{/usr/local}, it wouldn’t | |
71 | look for @file{.m4} files in @file{/usr/share}. In that case, you have | |
72 | to invoke the following command: | |
8c01b9d0 ML |
73 | |
74 | @example | |
75 | export ACLOCAL_PATH=/usr/share/aclocal | |
76 | @end example | |
77 | ||
aabe6d38 | 78 | @xref{Macro Search Path,,, automake, The GNU Automake Manual}, for |
8c01b9d0 ML |
79 | more information. |
80 | ||
81 | Then, run @command{./configure} as usual. | |
82 | ||
83 | Finally, you have to invoke @code{make check} to run tests. If anything | |
84 | fails, take a look at installation instructions (@pxref{Installation}) | |
85 | or send a message to the @email{guix-devel@@gnu.org, mailing list}. | |
86 | ||
87 | ||
88 | @node Running Guix Before It Is Installed | |
89 | @section Running Guix Before It Is Installed | |
90 | ||
91 | In order to keep a sane working environment, you will find it useful to | |
92 | test the changes made in your local source tree checkout without | |
93 | actually installing them. So that you can distinguish between your | |
94 | ``end-user'' hat and your ``motley'' costume. | |
95 | ||
96 | To that end, all the command-line tools can be used even if you have not | |
97 | run @code{make install}. To do that, prefix each command with | |
98 | @command{./pre-inst-env} (the @file{pre-inst-env} script lives in the | |
99 | top build tree of Guix), as in: | |
100 | ||
101 | @example | |
102 | $ sudo ./pre-inst-env guix-daemon --build-users-group=guixbuild | |
103 | $ ./pre-inst-env guix build hello | |
104 | @end example | |
105 | ||
106 | @noindent | |
107 | Similarly, for a Guile session using the Guix modules: | |
108 | ||
109 | @example | |
110 | $ ./pre-inst-env guile -c '(use-modules (guix utils)) (pk (%current-system))' | |
96856613 LC |
111 | |
112 | ;;; ("x86_64-linux") | |
113 | @end example | |
114 | ||
115 | @noindent | |
116 | @cindex REPL | |
117 | @cindex read-eval-print loop | |
118 | @dots{} and for a REPL (@pxref{Using Guile Interactively,,, guile, Guile | |
119 | Reference Manual}): | |
120 | ||
121 | @example | |
122 | $ ./pre-inst-env guile | |
123 | scheme@@(guile-user)> ,use(guix) | |
124 | scheme@@(guile-user)> ,use(gnu) | |
125 | scheme@@(guile-user)> (define snakes | |
126 | (fold-packages | |
127 | (lambda (package lst) | |
128 | (if (string-prefix? "python" | |
129 | (package-name package)) | |
130 | (cons package lst) | |
131 | lst)) | |
132 | '())) | |
133 | scheme@@(guile-user)> (length snakes) | |
134 | $1 = 361 | |
8c01b9d0 ML |
135 | @end example |
136 | ||
137 | The @command{pre-inst-env} script sets up all the environment variables | |
138 | necessary to support this, including @env{PATH} and @env{GUILE_LOAD_PATH}. | |
139 | ||
ef54b61d AV |
140 | Note that @command{./pre-inst-env guix pull} does @emph{not} upgrade the |
141 | local source tree; it simply updates the @file{~/.config/guix/latest} | |
142 | symlink (@pxref{Invoking guix pull}). Run @command{git pull} instead if | |
143 | you want to upgrade your local source tree. | |
144 | ||
8c01b9d0 ML |
145 | |
146 | @node The Perfect Setup | |
147 | @section The Perfect Setup | |
148 | ||
149 | The Perfect Setup to hack on Guix is basically the perfect setup used | |
150 | for Guile hacking (@pxref{Using Guile in Emacs,,, guile, Guile Reference | |
151 | Manual}). First, you need more than an editor, you need | |
152 | @url{http://www.gnu.org/software/emacs, Emacs}, empowered by the | |
153 | wonderful @url{http://nongnu.org/geiser/, Geiser}. | |
154 | ||
155 | Geiser allows for interactive and incremental development from within | |
156 | Emacs: code compilation and evaluation from within buffers, access to | |
157 | on-line documentation (docstrings), context-sensitive completion, | |
158 | @kbd{M-.} to jump to an object definition, a REPL to try out your code, | |
159 | and more (@pxref{Introduction,,, geiser, Geiser User Manual}). For | |
160 | convenient Guix development, make sure to augment Guile’s load path so | |
161 | that it finds source files from your checkout: | |
162 | ||
163 | @lisp | |
164 | ;; @r{Assuming the Guix checkout is in ~/src/guix.} | |
bb38ece4 AK |
165 | (with-eval-after-load 'geiser-guile |
166 | (add-to-list 'geiser-guile-load-path "~/src/guix")) | |
8c01b9d0 ML |
167 | @end lisp |
168 | ||
169 | To actually edit the code, Emacs already has a neat Scheme mode. But in | |
170 | addition to that, you must not miss | |
171 | @url{http://www.emacswiki.org/emacs/ParEdit, Paredit}. It provides | |
172 | facilities to directly operate on the syntax tree, such as raising an | |
173 | s-expression or wrapping it, swallowing or rejecting the following | |
174 | s-expression, etc. | |
175 | ||
187f80c6 AK |
176 | GNU Guix also comes with a minor mode that provides some additional |
177 | functionality for Scheme buffers (@pxref{Emacs Development}). | |
178 | ||
8c01b9d0 ML |
179 | |
180 | @node Coding Style | |
181 | @section Coding Style | |
182 | ||
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 | ||
187 | @menu | |
188 | * Programming Paradigm:: How to compose your elements. | |
189 | * Modules:: Where to store your code? | |
190 | * Data Types and Pattern Matching:: Implementing data structures. | |
191 | * Formatting Code:: Writing conventions. | |
192 | @end menu | |
193 | ||
194 | @node Programming Paradigm | |
195 | @subsection Programming Paradigm | |
196 | ||
197 | Scheme code in Guix is written in a purely functional style. One | |
198 | exception is code that involves input/output, and procedures that | |
199 | implement low-level concepts, such as the @code{memoize} procedure. | |
200 | ||
201 | @node Modules | |
202 | @subsection Modules | |
203 | ||
204 | Guile modules that are meant to be used on the builder side must live in | |
205 | the @code{(guix build @dots{})} name space. They must not refer to | |
206 | other Guix or GNU modules. However, it is OK for a ``host-side'' module | |
207 | to use a build-side module. | |
208 | ||
209 | Modules that deal with the broader GNU system should be in the | |
210 | @code{(gnu @dots{})} name space rather than @code{(guix @dots{})}. | |
211 | ||
212 | @node Data Types and Pattern Matching | |
213 | @subsection Data Types and Pattern Matching | |
214 | ||
215 | The tendency in classical Lisp is to use lists to represent everything, | |
216 | and then to browse them ``by hand'' using @code{car}, @code{cdr}, | |
217 | @code{cadr}, and co. There are several problems with that style, | |
218 | notably the fact that it is hard to read, error-prone, and a hindrance | |
219 | to proper type error reports. | |
220 | ||
221 | Guix code should define appropriate data types (for instance, using | |
222 | @code{define-record-type*}) rather than abuse lists. In addition, it | |
223 | should use pattern matching, via Guile’s @code{(ice-9 match)} module, | |
224 | especially when matching lists. | |
225 | ||
226 | @node Formatting Code | |
227 | @subsection Formatting Code | |
228 | ||
229 | When writing Scheme code, we follow common wisdom among Scheme | |
230 | programmers. In general, we follow the | |
231 | @url{http://mumble.net/~campbell/scheme/style.txt, Riastradh's Lisp | |
232 | Style Rules}. This document happens to describe the conventions mostly | |
233 | used in Guile’s code too. It is very thoughtful and well written, so | |
234 | please do read it. | |
235 | ||
236 | Some special forms introduced in Guix, such as the @code{substitute*} | |
237 | macro, have special indentation rules. These are defined in the | |
238 | @file{.dir-locals.el} file, which Emacs automatically uses. If you do | |
239 | not use Emacs, please make sure to let your editor know the rules. | |
240 | ||
241 | We require all top-level procedures to carry a docstring. This | |
242 | requirement can be relaxed for simple private procedures in the | |
243 | @code{(guix build @dots{})} name space, though. | |
244 | ||
245 | Procedures should not have more than four positional parameters. Use | |
246 | keyword parameters for procedures that take more than four parameters. | |
247 | ||
248 | ||
249 | @node Submitting Patches | |
250 | @section Submitting Patches | |
251 | ||
252 | Development is done using the Git distributed version control system. | |
253 | Thus, access to the repository is not strictly necessary. We welcome | |
254 | contributions in the form of patches as produced by @code{git | |
255 | format-patch} sent to the @email{guix-devel@@gnu.org, mailing list}. | |
256 | Please write commit logs in the ChangeLog format (@pxref{Change Logs,,, | |
257 | standards, GNU Coding Standards}); you can check the commit history for | |
258 | examples. | |
259 | ||
260 | Before submitting a patch that adds or modifies a package definition, | |
fcc58db6 LC |
261 | please run through this check list: |
262 | ||
263 | @enumerate | |
cbd02397 LC |
264 | @item |
265 | Take some time to provide an adequate synopsis and description for the | |
266 | package. @xref{Synopses and Descriptions}, for some guidelines. | |
267 | ||
fcc58db6 LC |
268 | @item |
269 | Run @code{guix lint @var{package}}, where @var{package} is the | |
8c01b9d0 | 270 | name of the new or modified package, and fix any errors it reports |
fcc58db6 LC |
271 | (@pxref{Invoking guix lint}). |
272 | ||
273 | @item | |
274 | Make sure the package builds on your platform, using @code{guix build | |
275 | @var{package}}. | |
276 | ||
277 | @item | |
278 | Take a look at the profile reported by @command{guix size} | |
279 | (@pxref{Invoking guix size}). This will allow you to notice references | |
280 | to other packages unwillingly retained. It may also help determine | |
281 | whether to split the package (@pxref{Packages with Multiple Outputs}), | |
282 | and which optional dependencies should be used. | |
283 | ||
284 | @item | |
285 | For important changes, check that dependent package (if applicable) are | |
286 | not affected by the change; @code{guix refresh --list-dependent | |
8c01b9d0 ML |
287 | @var{package}} will help you do that (@pxref{Invoking guix refresh}). |
288 | ||
d23c20f1 | 289 | @item |
5b74fe06 LC |
290 | @cindex determinism, of build processes |
291 | @cindex reproducible builds, checking | |
d23c20f1 LC |
292 | Check whether the package's build process is deterministic. This |
293 | typically means checking whether an independent build of the package | |
294 | yields the exact same result that you obtained, bit for bit. | |
295 | ||
5b74fe06 LC |
296 | A simple way to do that is by building the same package several times in |
297 | a row on your machine (@pxref{Invoking guix build}): | |
298 | ||
299 | @example | |
300 | guix build --rounds=2 my-package | |
301 | @end example | |
302 | ||
303 | This is enough to catch a class of common non-determinism issues, such | |
304 | as timestamps or randomly-generated output in the build result. | |
305 | ||
306 | Another option is to use @command{guix challenge} (@pxref{Invoking guix | |
307 | challenge}). You may run it once the package has been committed and | |
308 | built by @code{hydra.gnu.org} to check whether it obtains the same | |
309 | result as you did. Better yet: Find another machine that can build it | |
310 | and run @command{guix publish}. Since the remote build machine is | |
311 | likely different from yours, this can catch non-determinism issues | |
312 | related to the hardware---e.g., use of different instruction set | |
313 | extensions---or to the operating system kernel---e.g., reliance on | |
314 | @code{uname} or @file{/proc} files. | |
d23c20f1 | 315 | |
fcc58db6 LC |
316 | @end enumerate |
317 | ||
8c01b9d0 ML |
318 | When posting a patch to the mailing list, use @samp{[PATCH] @dots{}} as a |
319 | subject. You may use your email client or the @command{git send-mail} | |
320 | command. |