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