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