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