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