doc: Slightly improve the "System Configuration" node.
[jackhill/guix/guix.git] / doc / guix.texi
1 \input texinfo
2 @c -*-texinfo-*-
3
4 @c %**start of header
5 @setfilename guix.info
6 @documentencoding UTF-8
7 @settitle GNU Guix Reference Manual
8 @c %**end of header
9
10 @include version.texi
11
12 @copying
13 Copyright @copyright{} 2012, 2013 Ludovic Courtès@*
14 Copyright @copyright{} 2013 Andreas Enge@*
15 Copyright @copyright{} 2013 Nikita Karetnikov
16
17 Permission is granted to copy, distribute and/or modify this document
18 under the terms of the GNU Free Documentation License, Version 1.3 or
19 any later version published by the Free Software Foundation; with no
20 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
21 copy of the license is included in the section entitled ``GNU Free
22 Documentation License''.
23 @end copying
24
25 @dircategory Package management
26 @direntry
27 * guix: (guix). Guix, the functional package manager.
28 * guix package: (guix)Invoking guix package
29 Managing packages with Guix.
30 * guix build: (guix)Invoking guix build
31 Building packages with Guix.
32 @end direntry
33
34 @titlepage
35 @title GNU Guix Reference Manual
36 @subtitle Using the GNU Guix Functional Package Manager
37 @author Ludovic Courtès
38 @author Andreas Enge
39 @author Nikita Karetnikov
40
41 @page
42 @vskip 0pt plus 1filll
43 Edition @value{EDITION} @*
44 @value{UPDATED} @*
45
46 @insertcopying
47 @end titlepage
48
49 @contents
50
51 @c *********************************************************************
52 @node Top
53 @top GNU Guix
54
55 This document describes GNU Guix version @value{VERSION}, a functional
56 package management tool written for the GNU system.
57
58 @menu
59 * Introduction:: What is Guix about?
60 * Installation:: Installing Guix.
61 * Package Management:: Package installation, upgrade, etc.
62 * Programming Interface:: Using Guix in Scheme.
63 * Utilities:: Package management commands.
64 * GNU Distribution:: Software for your friendly GNU system.
65 * Contributing:: Your help needed!
66
67 * Acknowledgments:: Thanks!
68 * GNU Free Documentation License:: The license of this manual.
69 * Concept Index:: Concepts.
70 * Function Index:: Functions.
71 @end menu
72
73 @c *********************************************************************
74 @node Introduction
75 @chapter Introduction
76
77 GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
78 using the international phonetic alphabet (IPA).} is a functional
79 package management tool for the GNU system. Package management consists
80 of all activities that relate to building packages from sources,
81 honoring their build-time and run-time dependencies,
82 installing packages in user environments, upgrading installed packages
83 to new versions or rolling back to a previous set, removing unused
84 software packages, etc.
85
86 @cindex functional package management
87 The term @dfn{functional} refers to a specific package management
88 discipline. In Guix, the package build and installation process is seen
89 as a function, in the mathematical sense. That function takes inputs,
90 such as build scripts, a compiler, and libraries, and
91 returns an installed package. As a pure function, its result depends
92 solely on its inputs---for instance, it cannot refer to software or
93 scripts that were not explicitly passed as inputs. A build function
94 always produces the same result when passed a given set of inputs. It
95 cannot alter the system's environment in
96 any way; for instance, it cannot create, modify, or delete files outside
97 of its build and installation directories. This is achieved by running
98 build processes in isolated environments (or @dfn{containers}), where only their
99 explicit inputs are visible.
100
101 @cindex store
102 The result of package build functions is @dfn{cached} in the file
103 system, in a special directory called @dfn{the store} (@pxref{The
104 Store}). Each package is installed in a directory of its own, in the
105 store---by default under @file{/nix/store}. The directory name contains
106 a hash of all the inputs used to build that package; thus, changing an
107 input yields a different directory name.
108
109 This approach is the foundation of Guix's salient features: support for
110 transactional package upgrade and rollback, per-user installation, and
111 garbage collection of packages (@pxref{Features}).
112
113 Guix has a command-line interface, which allows users to build, install,
114 upgrade, and remove packages, as well as a Scheme programming interface.
115
116 Last but not least, Guix is used to build a distribution of the GNU
117 system, with many GNU and non-GNU free software packages. @xref{GNU
118 Distribution}.
119
120 @c *********************************************************************
121 @node Installation
122 @chapter Installation
123
124 GNU Guix is available for download from its website at
125 @url{http://www.gnu.org/software/guix/}. This section describes the
126 software requirements of Guix, as well as how to install it and get
127 ready to use it.
128
129 The build procedure for Guix is the same as for other GNU software, and
130 is not covered here. Please see the files @file{README} and
131 @file{INSTALL} in the Guix source tree for additional details.
132
133 @menu
134 * Requirements:: Software needed to build and run Guix.
135 * Setting Up the Daemon:: Preparing the build daemon's environment.
136 * Invoking guix-daemon:: Running the build daemon.
137 @end menu
138
139 @node Requirements
140 @section Requirements
141
142 GNU Guix depends on the following packages:
143
144 @itemize
145 @item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.5 or later;
146 @item @url{http://gnupg.org/, GNU libgcrypt}
147 @end itemize
148
149 Unless @code{--disable-daemon} was passed to @command{configure}, the
150 following packages are also needed:
151
152 @itemize
153 @item @url{http://sqlite.org, SQLite 3}
154 @item @url{http://www.bzip.org, libbz2}
155 @item @url{http://gcc.gnu.org, GCC's g++}
156 @end itemize
157
158 When a working installation of @url{http://nixos.org/nix/, the Nix package
159 manager} is available, you
160 can instead configure Guix with @code{--disable-daemon}. In that case,
161 Nix replaces the three dependencies above.
162
163 Guix is compatible with Nix, so it is possible to share the same store
164 between both. To do so, you must pass @command{configure} not only the
165 same @code{--with-store-dir} value, but also the same
166 @code{--localstatedir} value. The latter is essential because it
167 specifies where the database that stores metadata about the store is
168 located, among other things. The default values are
169 @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
170 Note that @code{--disable-daemon} is not required if
171 your goal is to share the store with Nix.
172
173 @node Setting Up the Daemon
174 @section Setting Up the Daemon
175
176 @cindex daemon
177 Operations such as building a package or running the garbage collector
178 are all performed by a specialized process, the @dfn{Guix daemon}, on
179 behalf of clients. Only the daemon may access the store and its
180 associated database. Thus, any operation that manipulates the store
181 goes through the daemon. For instance, command-line tools such as
182 @command{guix package} and @command{guix build} communicate with the
183 daemon (@i{via} remote procedure calls) to instruct it what to do.
184
185 In a standard multi-user setup, Guix and its daemon---the
186 @command{guix-daemon} program---are installed by the system
187 administrator; @file{/nix/store} is owned by @code{root} and
188 @command{guix-daemon} runs as @code{root}. Unprivileged users may use
189 Guix tools to build packages or otherwise access the store, and the
190 daemon will do it on their behalf, ensuring that the store is kept in a
191 consistent state, and allowing built packages to be shared among users.
192
193 @cindex build users
194 When @command{guix-daemon} runs as @code{root}, you may not want package
195 build processes themselves to run as @code{root} too, for obvious
196 security reasons. To avoid that, a special pool of @dfn{build users}
197 should be created for use by build processes started by the daemon.
198 These build users need not have a shell and a home directory: they will
199 just be used when the daemon drops @code{root} privileges in build
200 processes. Having several such users allows the daemon to launch
201 distinct build processes under separate UIDs, which guarantees that they
202 do not interfere with each other---an essential feature since builds are
203 regarded as pure functions (@pxref{Introduction}).
204
205 On a GNU/Linux system, a build user pool may be created like this (using
206 Bash syntax and the @code{shadow} commands):
207
208 @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
209 @c for why `-G' is needed.
210 @example
211 # groupadd guix-builder
212 # for i in `seq 1 10`;
213 do
214 useradd -g guix-builder -G guix-builder \
215 -d /var/empty -s `which nologin` \
216 -c "Guix build user $i" guix-builder$i;
217 done
218 @end example
219
220 @noindent
221 The @code{guix-daemon} program may then be run as @code{root} with:
222
223 @example
224 # guix-daemon --build-users-group=guix-builder
225 @end example
226
227 @cindex chroot
228 @noindent
229 This way, the daemon starts build processes in a chroot, under one of
230 the @code{guix-builder} users. On GNU/Linux, by default, the chroot
231 environment contains nothing but the @code{/dev} and @code{/proc}
232 directories@footnote{On some systems @code{/dev/shm}, which supports
233 shared memory, is a symlink to another directory such as
234 @code{/run/shm}, that is @emph{not} is the chroot. When that is the
235 case, shared memory support is unavailable in the chroot environment.
236 The workaround is to make sure that @file{/dev/shm} is directly a
237 @code{tmpfs} mount point.}.
238
239 Guix may also be used in a single-user setup, with @command{guix-daemon}
240 running as an unprivileged user. However, to maximize non-interference
241 of build processes, the daemon still needs to perform certain operations
242 that are restricted to @code{root} on GNU/Linux: it should be able to
243 run build processes in a chroot, and to run them under different UIDs.
244 To that end, the @command{nix-setuid-helper} program is provided; it is
245 a small C program (less than 300 lines) that, if it is made setuid
246 @code{root}, can be executed by the daemon to perform these operations
247 on its behalf. The @code{root}-owned @file{/etc/nix-setuid.conf} file
248 is read by @command{nix-setuid-helper}; it should contain exactly two
249 words: the user name under which the authorized @command{guix-daemon}
250 runs, and the name of the build users group.
251
252 If you are installing Guix as an unprivileged user and do not have the
253 ability to make @file{nix-setuid-helper} setuid-@code{root}, it is still
254 possible to run @command{guix-daemon}. However, build processes will
255 not be isolated from one another, and not from the rest of the system.
256 Thus, build processes may interfere with each other, and may access
257 programs, libraries, and other files available on the system---making it
258 much harder to view them as @emph{pure} functions.
259
260 @node Invoking guix-daemon
261 @section Invoking @command{guix-daemon}
262
263 The @command{guix-daemon} program implements all the functionality to
264 access the store. This includes launching build processes, running the
265 garbage collector, querying the availability of a build result, etc. It
266 is normally run as @code{root} like this:
267
268 @example
269 # guix-daemon --build-users-group=guix-builder
270 @end example
271
272 @noindent
273 For details on how to set it up, @ref{Setting Up the Daemon}.
274
275 @cindex chroot
276 @cindex container, build environment
277 @cindex build environment
278 @cindex reproducible builds
279 By default, @command{guix-daemon} launches build processes under
280 different UIDs, taken from the build group specified with
281 @code{--build-users-group}. In addition, each build process is run in a
282 chroot environment that only contains the subset of the store that the
283 build process depends on, as specified by its derivation
284 (@pxref{Programming Interface, derivation}), plus a set of specific
285 system directories. By default, the latter contains @file{/dev} and
286 @file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
287 @dfn{container}: in addition to having its own file system tree, it has
288 a separate mount name space, its own PID name space, network name space,
289 etc. This helps achieve reproducible builds (@pxref{Features}).
290
291 The following command-line options are supported:
292
293 @table @code
294 @item --build-users-group=@var{group}
295 Take users from @var{group} to run build processes (@pxref{Setting Up
296 the Daemon, build users}).
297
298 @item --no-substitutes
299 @cindex substitutes
300 Do not use substitutes for build products. That is, always build things
301 locally instead of allowing downloads of pre-built binaries.
302
303 By default substitutes are used, unless the client---such as the
304 @command{guix package} command---is explicitly invoked with
305 @code{--no-substitutes}.
306
307 When the daemon runs with @code{--no-substitutes}, clients can still
308 explicitly enable substitution @i{via} the @code{set-build-options}
309 remote procedure call (@pxref{The Store}).
310
311 @item --cache-failures
312 Cache build failures. By default, only successful builds are cached.
313
314 @item --cores=@var{n}
315 @itemx -c @var{n}
316 Use @var{n} CPU cores to build each derivation; @code{0} means as many
317 as available.
318
319 The default value is @code{1}, but it may be overridden by clients, such
320 as the @code{--cores} option of @command{guix build} (@pxref{Invoking
321 guix build}).
322
323 The effect is to define the @code{NIX_BUILD_CORES} environment variable
324 in the build process, which can then use it to exploit internal
325 parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
326
327 @item --max-jobs=@var{n}
328 @itemx -M @var{n}
329 Allow at most @var{n} build jobs in parallel. The default value is
330 @code{1}.
331
332 @item --debug
333 Produce debugging output.
334
335 This is useful to debug daemon start-up issues, but then it may be
336 overridden by clients, for example the @code{--verbosity} option of
337 @command{guix build} (@pxref{Invoking guix build}).
338
339 @item --chroot-directory=@var{dir}
340 Add @var{dir} to the build chroot.
341
342 Doing this may change the result of build processes---for instance if
343 they use optional dependencies found in @var{dir} when it is available,
344 and not otherwise. For that reason, it is not recommended to do so.
345 Instead, make sure that each derivation declares all the inputs that it
346 needs.
347
348 @item --disable-chroot
349 Disable chroot builds.
350
351 Using this option is not recommended since, again, it would allow build
352 processes to gain access to undeclared dependencies.
353
354 @item --disable-log-compression
355 Disable compression of the build logs.
356
357 Unless @code{--lose-logs} is used, all the build logs are kept in the
358 @var{localstatedir}. To save space, the daemon automatically compresses
359 them with bzip2 by default. This option disables that.
360
361 @item --disable-store-optimization
362 Disable automatic file ``deduplication'' in the store.
363
364 By default, files added to the store are automatically ``deduplicated'':
365 if a newly added file is identical as another one found in the store,
366 the daemon makes the new file a hard link to the other file. This
367 slightly increases the input/output load at the end of a build process.
368 This option disables this.
369
370 @item --impersonate-linux-2.6
371 On Linux-based systems, impersonate Linux 2.6. This means that the
372 kernel's @code{uname} system call will report 2.6 as the release number.
373
374 This might be helpful to build programs that (usually wrongfully) depend
375 on the kernel version number.
376
377 @item --lose-logs
378 Do not keep build logs. By default they are kept under
379 @code{@var{localstatedir}/nix/log}.
380
381 @item --system=@var{system}
382 Assume @var{system} as the current system type. By default it is the
383 architecture/kernel pair found at configure time, such as
384 @code{x86_64-linux}.
385
386 @item --listen=@var{socket}
387 Listen for connections on @var{socket}, the file name of a Unix-domain
388 socket. The default socket is
389 @file{@var{localstatedir}/daemon-socket/socket}. This option is only
390 useful in exceptional circumstances, such as if you need to run several
391 daemons on the same machine.
392 @end table
393
394
395 @c *********************************************************************
396 @node Package Management
397 @chapter Package Management
398
399 The purpose of GNU Guix is to allow users to easily install, upgrade, and
400 remove software packages, without having to know about their build
401 procedure or dependencies. Guix also goes beyond this obvious set of
402 features.
403
404 This chapter describes the main features of Guix, as well as the package
405 management tools it provides.
406
407 @menu
408 * Features:: How Guix will make your life brighter.
409 * Invoking guix package:: Package installation, removal, etc.
410 * Packages with Multiple Outputs:: Single source package, multiple outputs.
411 * Invoking guix gc:: Running the garbage collector.
412 * Invoking guix pull:: Fetching the latest Guix and distribution.
413 @end menu
414
415 @node Features
416 @section Features
417
418 When using Guix, each package ends up in the @dfn{package store}, in its
419 own directory---something that resembles
420 @file{/nix/store/xxx-package-1.2}, where @code{xxx} is a base32 string.
421
422 Instead of referring to these directories, users have their own
423 @dfn{profile}, which points to the packages that they actually want to
424 use. These profiles are stored within each user's home directory, at
425 @code{$HOME/.guix-profile}.
426
427 For example, @code{alice} installs GCC 4.7.2. As a result,
428 @file{/home/alice/.guix-profile/bin/gcc} points to
429 @file{/nix/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
430 @code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
431 simply continues to point to
432 @file{/nix/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
433 coexist on the same system without any interference.
434
435 The @command{guix package} command is the central tool to manage
436 packages (@pxref{Invoking guix package}). It operates on those per-user
437 profiles, and can be used @emph{with normal user privileges}.
438
439 The command provides the obvious install, remove, and upgrade
440 operations. Each invocation is actually a @emph{transaction}: either
441 the specified operation succeeds, or nothing happens. Thus, if the
442 @command{guix package} process is terminated during the transaction,
443 or if a power outage occurs during the transaction, then the user's
444 profile remains in its previous state, and remains usable.
445
446 In addition, any package transaction may be @emph{rolled back}. So, if,
447 for example, an upgrade installs a new version of a package that turns
448 out to have a serious bug, users may roll back to the previous instance
449 of their profile, which was known to work well. Similarly, the global
450 system configuration is subject to transactional upgrades and roll-back
451 (@pxref{Using the Configuration System}).
452
453 All those packages in the package store may be @emph{garbage-collected}.
454 Guix can determine which packages are still referenced by the user
455 profiles, and remove those that are provably no longer referenced
456 (@pxref{Invoking guix gc}). Users may also explicitly remove old
457 generations of their profile so that the packages they refer to can be
458 collected.
459
460 @cindex reproducibility
461 @cindex reproducible builds
462 Finally, Guix takes a @dfn{purely functional} approach to package
463 management, as described in the introduction (@pxref{Introduction}).
464 Each @file{/nix/store} package directory name contains a hash of all the
465 inputs that were used to build that package---compiler, libraries, build
466 scripts, etc. This direct correspondence allows users to make sure a
467 given package installation matches the current state of their
468 distribution. It also helps maximize @dfn{build reproducibility}:
469 thanks to the isolated build environments that are used, a given build
470 is likely to yield bit-identical files when performed on different
471 machines (@pxref{Invoking guix-daemon, container}).
472
473 @cindex substitute
474 This foundation allows Guix to support @dfn{transparent binary/source
475 deployment}. When a pre-built binary for a @file{/nix/store} path is
476 available from an external source---a @dfn{substitute}, Guix just
477 downloads it@footnote{@c XXX: Remove me when outdated.
478 As of version @value{VERSION}, substitutes are downloaded from
479 @url{http://hydra.gnu.org/} but are @emph{not} authenticated---i.e.,
480 Guix cannot tell whether binaries it downloaded have been tampered with,
481 nor whether they come from the genuine @code{gnu.org} build farm. This
482 will be fixed in future versions. In the meantime, concerned users can
483 opt for @code{--no-substitutes} (@pxref{Invoking guix-daemon}).};
484 otherwise, it builds the package from source, locally.
485
486 @node Invoking guix package
487 @section Invoking @command{guix package}
488
489 The @command{guix package} command is the tool that allows users to
490 install, upgrade, and remove packages, as well as rolling back to
491 previous configurations. It operates only on the user's own profile,
492 and works with normal user privileges (@pxref{Features}). Its syntax
493 is:
494
495 @example
496 guix package @var{options}
497 @end example
498
499 Primarily, @var{options} specifies the operations to be performed during
500 the transaction. Upon completion, a new profile is created, but
501 previous generations of the profile remain available, should the user
502 want to roll back.
503
504 For each user, a symlink to the user's default profile is automatically
505 created in @file{$HOME/.guix-profile}. This symlink always points to the
506 current generation of the user's default profile. Thus, users can add
507 @file{$HOME/.guix-profile/bin} to their @code{PATH} environment
508 variable, and so on.
509
510 In a multi-user setup, user profiles must be stored in a place
511 registered as a @dfn{garbage-collector root}, which
512 @file{$HOME/.guix-profile} points to (@pxref{Invoking guix gc}). That
513 directory is normally
514 @code{@var{localstatedir}/profiles/per-user/@var{user}}, where
515 @var{localstatedir} is the value passed to @code{configure} as
516 @code{--localstatedir}, and @var{user} is the user name. It must be
517 created by @code{root}, with @var{user} as the owner. When it does not
518 exist, or is not owned by @var{user}, @command{guix package} emits an
519 error about it.
520
521 The @var{options} can be among the following:
522
523 @table @code
524
525 @item --install=@var{package}
526 @itemx -i @var{package}
527 Install @var{package}.
528
529 @var{package} may specify either a simple package name, such as
530 @code{guile}, or a package name followed by a hyphen and version number,
531 such as @code{guile-1.8.8}. If no version number is specified, the
532 newest available version will be selected. In addition, @var{package}
533 may contain a colon, followed by the name of one of the outputs of the
534 package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
535 (@pxref{Packages with Multiple Outputs}).
536
537 @cindex propagated inputs
538 Sometimes packages have @dfn{propagated inputs}: these are dependencies
539 that automatically get installed along with the required package.
540
541 An example is the GNU MPC library: its C header files refer to those of
542 the GNU MPFR library, which in turn refer to those of the GMP library.
543 Thus, when installing MPC, the MPFR and GMP libraries also get installed
544 in the profile; removing MPC also removes MPFR and GMP---unless they had
545 also been explicitly installed independently.
546
547 Besides, packages sometimes rely on the definition of environment
548 variables for their search paths (see explanation of
549 @code{--search-paths} below). Any missing or possibly incorrect
550 environment variable definitions are reported here.
551
552 @c XXX: keep me up-to-date
553 Finally, when installing a GNU package, the tool reports the
554 availability of a newer upstream version. In the future, it may provide
555 the option of installing directly from the upstream version, even if
556 that version is not yet in the distribution.
557
558 @item --install-from-expression=@var{exp}
559 @itemx -e @var{exp}
560 Install the package @var{exp} evaluates to.
561
562 @var{exp} must be a Scheme expression that evaluates to a
563 @code{<package>} object. This option is notably useful to disambiguate
564 between same-named variants of a package, with expressions such as
565 @code{(@@ (gnu packages base) guile-final)}.
566
567 Note that this option installs the first output of the specified
568 package, which may be insufficient when needing a specific output of a
569 multiple-output package.
570
571 @item --remove=@var{package}
572 @itemx -r @var{package}
573 Remove @var{package}.
574
575 As for @code{--install}, @var{package} may specify a version number
576 and/or output name in addition to the package name. For instance,
577 @code{-r glibc:debug} would remove the @code{debug} output of
578 @code{glibc}.
579
580 @item --upgrade[=@var{regexp}]
581 @itemx -u [@var{regexp}]
582 Upgrade all the installed packages. When @var{regexp} is specified, upgrade
583 only installed packages whose name matches @var{regexp}.
584
585 Note that this upgrades package to the latest version of packages found
586 in the distribution currently installed. To update your distribution,
587 you should regularly run @command{guix pull} (@pxref{Invoking guix
588 pull}).
589
590 @item --roll-back
591 Roll back to the previous @dfn{generation} of the profile---i.e., undo
592 the last transaction.
593
594 When combined with options such as @code{--install}, roll back occurs
595 before any other actions.
596
597 When rolling back from the first generation that actually contains
598 installed packages, the profile is made to point to the @dfn{zeroth
599 generation}, which contains no files apart from its own meta-data.
600
601 Installing, removing, or upgrading packages from a generation that has
602 been rolled back to overwrites previous future generations. Thus, the
603 history of a profile's generations is always linear.
604
605 @item --search-paths
606 @cindex search paths
607 Report environment variable definitions, in Bash syntax, that may be
608 needed in order to use the set of installed packages. These environment
609 variables are used to specify @dfn{search paths} for files used by some
610 of the installed packages.
611
612 For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
613 environment variables to be defined so it can look for headers and
614 libraries in the user's profile (@pxref{Environment Variables,,, gcc,
615 Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
616 library are installed in the profile, then @code{--search-paths} will
617 suggest setting these variables to @code{@var{profile}/include} and
618 @code{@var{profile}/lib}, respectively.
619
620 @item --profile=@var{profile}
621 @itemx -p @var{profile}
622 Use @var{profile} instead of the user's default profile.
623
624 @item --dry-run
625 @itemx -n
626 Show what would be done without actually doing it.
627
628 @item --fallback
629 When substituting a pre-built binary fails, fall back to building
630 packages locally.
631
632 @item --no-substitutes
633 Do not use substitutes for build products. That is, always build things
634 locally instead of allowing downloads of pre-built binaries.
635
636 @item --max-silent-time=@var{seconds}
637 Same as for @command{guix build} (@pxref{Invoking guix build}).
638
639 @item --verbose
640 Produce verbose output. In particular, emit the environment's build log
641 on the standard error port.
642
643 @item --bootstrap
644 Use the bootstrap Guile to build the profile. This option is only
645 useful to distribution developers.
646
647 @end table
648
649 In addition to these actions @command{guix package} supports the
650 following options to query the current state of a profile, or the
651 availability of packages:
652
653 @table @option
654
655 @item --search=@var{regexp}
656 @itemx -s @var{regexp}
657 List the available packages whose synopsis or description matches
658 @var{regexp}. Print all the meta-data of matching packages in
659 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
660 GNU recutils manual}).
661
662 This allows specific fields to be extracted using the @command{recsel}
663 command, for instance:
664
665 @example
666 $ guix package -s malloc | recsel -p name,version
667 name: glibc
668 version: 2.17
669
670 name: libgc
671 version: 7.2alpha6
672 @end example
673
674 @item --list-installed[=@var{regexp}]
675 @itemx -I [@var{regexp}]
676 List the currently installed packages in the specified profile, with the
677 most recently installed packages shown last. When @var{regexp} is
678 specified, list only installed packages whose name matches @var{regexp}.
679
680 For each installed package, print the following items, separated by
681 tabs: the package name, its version string, the part of the package that
682 is installed (for instance, @code{out} for the default output,
683 @code{include} for its headers, etc.), and the path of this package in
684 the store.
685
686 @item --list-available[=@var{regexp}]
687 @itemx -A [@var{regexp}]
688 List packages currently available in the software distribution
689 (@pxref{GNU Distribution}). When @var{regexp} is specified, list only
690 installed packages whose name matches @var{regexp}.
691
692 For each package, print the following items separated by tabs: its name,
693 its version string, the parts of the package (@pxref{Packages with
694 Multiple Outputs}), and the source location of its definition.
695
696 @item --list-generations[=@var{pattern}]
697 @itemx -l [@var{pattern}]
698 Return a list of generations along with their creation dates; for each
699 generation, show the installed packages, with the most recently
700 installed packages shown last. Note that the zeroth generation is never
701 shown.
702
703 For each installed package, print the following items, separated by
704 tabs: the name of a package, its version string, the part of the package
705 that is installed (@pxref{Packages with Multiple Outputs}), and the
706 location of this package in the store.
707
708 When @var{pattern} is used, the command returns only matching
709 generations. Valid patterns include:
710
711 @itemize
712 @item @emph{Integers and comma-separated integers}. Both patterns denote
713 generation numbers. For instance, @code{--list-generations=1} returns
714 the first one.
715
716 And @code{--list-generations=1,8,2} outputs three generations in the
717 specified order. Neither spaces nor trailing commas are allowed.
718
719 @item @emph{Ranges}. @code{--list-generations=2..9} prints the
720 specified generations and everything in between. Note that the start of
721 a range must be lesser than its end.
722
723 It is also possible to omit the endpoint. For example,
724 @code{--list-generations=2..}, returns all generations starting from the
725 second one.
726
727 @item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
728 or months by passing an integer along with the first letter of the
729 duration. For example, @code{--list-generations=20d} lists generations
730 that are up to 20 days old.
731 @end itemize
732
733 @item --delete-generations[=@var{pattern}]
734 @itemx -d [@var{pattern}]
735 When @var{pattern} is omitted, delete all generations except the current
736 one.
737
738 This command accepts the same patterns as @option{--list-generations}.
739 When @var{pattern} is specified, delete the matching generations. When
740 @var{pattern} specifies a duration, generations @emph{older} than the
741 specified duration match. For instance, @code{--delete-generations=1m}
742 deletes generations that are more than one month old.
743
744 If the current generation matches, it is deleted atomically---i.e., by
745 switching to the previous available generation. Note that the zeroth
746 generation is never deleted.
747
748 Note that deleting generations prevents roll-back to them.
749 Consequently, this command must be used with care.
750
751 @end table
752
753 @node Packages with Multiple Outputs
754 @section Packages with Multiple Outputs
755
756 @cindex multiple-output packages
757 @cindex package outputs
758
759 Often, packages defined in Guix have a single @dfn{output}---i.e., the
760 source package leads exactly one directory in the store. When running
761 @command{guix package -i glibc}, one installs the default output of the
762 GNU libc package; the default output is called @code{out}, but its name
763 can be omitted as shown in this command. In this particular case, the
764 default output of @code{glibc} contains all the C header files, shared
765 libraries, static libraries, Info documentation, and other supporting
766 files.
767
768 Sometimes it is more appropriate to separate the various types of files
769 produced from a single source package into separate outputs. For
770 instance, the GLib C library (used by GTK+ and related packages)
771 installs more than 20 MiB of reference documentation as HTML pages.
772 To save space for users who do not need it, the documentation goes to a
773 separate output, called @code{doc}. To install the main GLib output,
774 which contains everything but the documentation, one would run:
775
776 @example
777 guix package -i glib
778 @end example
779
780 The command to install its documentation is:
781
782 @example
783 guix package -i glib:doc
784 @end example
785
786 Some packages install programs with different ``dependency footprints''.
787 For instance, the WordNet package install both command-line tools and
788 graphical user interfaces (GUIs). The former depend solely on the C
789 library, whereas the latter depend on Tcl/Tk and the underlying X
790 libraries. In this case, we leave the command-line tools in the default
791 output, whereas the GUIs are in a separate output. This allows users
792 who do not need the GUIs to save space.
793
794 There are several such multiple-output packages in the GNU distribution.
795 Other conventional output names include @code{lib} for libraries and
796 possibly header files, @code{bin} for stand-alone programs, and
797 @code{debug} for debugging information (@pxref{Installing Debugging
798 Files}). The outputs of a packages are listed in the third column of
799 the output of @command{guix package --list-available} (@pxref{Invoking
800 guix package}).
801
802
803 @node Invoking guix gc
804 @section Invoking @command{guix gc}
805
806 @cindex garbage collector
807 Packages that are installed but not used may be @dfn{garbage-collected}.
808 The @command{guix gc} command allows users to explicitly run the garbage
809 collector to reclaim space from the @file{/nix/store} directory.
810
811 The garbage collector has a set of known @dfn{roots}: any file under
812 @file{/nix/store} reachable from a root is considered @dfn{live} and
813 cannot be deleted; any other file is considered @dfn{dead} and may be
814 deleted. The set of garbage collector roots includes default user
815 profiles, and may be augmented with @command{guix build --root}, for
816 example (@pxref{Invoking guix build}).
817
818 Prior to running @code{guix gc --collect-garbage} to make space, it is
819 often useful to remove old generations from user profiles; that way, old
820 package builds referenced by those generations can be reclaimed. This
821 is achieved by running @code{guix package --delete-generations}
822 (@pxref{Invoking guix package}).
823
824 The @command{guix gc} command has three modes of operation: it can be
825 used to garbage-collect any dead files (the default), to delete specific
826 files (the @code{--delete} option), or to print garbage-collector
827 information. The available options are listed below:
828
829 @table @code
830 @item --collect-garbage[=@var{min}]
831 @itemx -C [@var{min}]
832 Collect garbage---i.e., unreachable @file{/nix/store} files and
833 sub-directories. This is the default operation when no option is
834 specified.
835
836 When @var{min} is given, stop once @var{min} bytes have been collected.
837 @var{min} may be a number of bytes, or it may include a unit as a
838 suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes.
839
840 When @var{min} is omitted, collect all the garbage.
841
842 @item --delete
843 @itemx -d
844 Attempt to delete all the store files and directories specified as
845 arguments. This fails if some of the files are not in the store, or if
846 they are still live.
847
848 @item --list-dead
849 Show the list of dead files and directories still present in the
850 store---i.e., files and directories no longer reachable from any root.
851
852 @item --list-live
853 Show the list of live store files and directories.
854
855 @end table
856
857 In addition, the references among existing store files can be queried:
858
859 @table @code
860
861 @item --references
862 @itemx --referrers
863 List the references (respectively, the referrers) of store files given
864 as arguments.
865
866 @item --requisites
867 @itemx -R
868 List the requisites of the store files passed as arguments. Requisites
869 include the store files themselves, their references, and the references
870 of these, recursively. In other words, the returned list is the
871 @dfn{transitive closure} of the store files.
872
873 @end table
874
875
876 @node Invoking guix pull
877 @section Invoking @command{guix pull}
878
879 Packages are installed or upgraded to the latest version available in
880 the distribution currently available on your local machine. To update
881 that distribution, along with the Guix tools, you must run @command{guix
882 pull}: the command downloads the latest Guix source code and package
883 descriptions, and deploys it.
884
885 On completion, @command{guix package} will use packages and package
886 versions from this just-retrieved copy of Guix. Not only that, but all
887 the Guix commands and Scheme modules will also be taken from that latest
888 version. New @command{guix} sub-commands added by the update also
889 become available.
890
891 The @command{guix pull} command is usually invoked with no arguments,
892 but it supports the following options:
893
894 @table @code
895 @item --verbose
896 Produce verbose output, writing build logs to the standard error output.
897
898 @item --url=@var{url}
899 Download the source tarball of Guix from @var{url}.
900
901 By default, the tarball is taken from its canonical address at
902 @code{gnu.org}, for the stable branch of Guix.
903
904 @item --bootstrap
905 Use the bootstrap Guile to build the latest Guix. This option is only
906 useful to Guix developers.
907 @end table
908
909 @c *********************************************************************
910 @node Programming Interface
911 @chapter Programming Interface
912
913 GNU Guix provides several Scheme programming interfaces (APIs) to
914 define, build, and query packages. The first interface allows users to
915 write high-level package definitions. These definitions refer to
916 familiar packaging concepts, such as the name and version of a package,
917 its build system, and its dependencies. These definitions can then be
918 turned into concrete build actions.
919
920 Build actions are performed by the Guix daemon, on behalf of users. In a
921 standard setup, the daemon has write access to the store---the
922 @file{/nix/store} directory---whereas users do not. The recommended
923 setup also has the daemon perform builds in chroots, under a specific
924 build users, to minimize interference with the rest of the system.
925
926 @cindex derivation
927 Lower-level APIs are available to interact with the daemon and the
928 store. To instruct the daemon to perform a build action, users actually
929 provide it with a @dfn{derivation}. A derivation is a low-level
930 representation of the build actions to be taken, and the environment in
931 which they should occur---derivations are to package definitions what
932 assembly is to C programs.
933
934 This chapter describes all these APIs in turn, starting from high-level
935 package definitions.
936
937 @menu
938 * Defining Packages:: Defining new packages.
939 * The Store:: Manipulating the package store.
940 * Derivations:: Low-level interface to package derivations.
941 * The Store Monad:: Purely functional interface to the store.
942 @end menu
943
944 @node Defining Packages
945 @section Defining Packages
946
947 The high-level interface to package definitions is implemented in the
948 @code{(guix packages)} and @code{(guix build-system)} modules. As an
949 example, the package definition, or @dfn{recipe}, for the GNU Hello
950 package looks like this:
951
952 @example
953 (use-modules (guix packages)
954 (guix download)
955 (guix build-system gnu)
956 (guix licenses))
957
958 (define hello
959 (package
960 (name "hello")
961 (version "2.8")
962 (source (origin
963 (method url-fetch)
964 (uri (string-append "mirror://gnu/hello/hello-" version
965 ".tar.gz"))
966 (sha256
967 (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
968 (build-system gnu-build-system)
969 (inputs `(("gawk" ,gawk)))
970 (synopsis "GNU Hello")
971 (description "Yeah...")
972 (home-page "http://www.gnu.org/software/hello/")
973 (license gpl3+)))
974 @end example
975
976 @noindent
977 Without being a Scheme expert, the reader may have guessed the meaning
978 of the various fields here. This expression binds variable @var{hello}
979 to a @code{<package>} object, which is essentially a record
980 (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
981 This package object can be inspected using procedures found in the
982 @code{(guix packages)} module; for instance, @code{(package-name hello)}
983 returns---surprise!---@code{"hello"}.
984
985 There are a few points worth noting in the above package definition:
986
987 @itemize
988 @item
989 The @code{source} field of the package is an @code{<origin>} object.
990 Here, the @code{url-fetch} method from @code{(guix download)} is used,
991 meaning that the source is a file to be downloaded over FTP or HTTP.
992
993 The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
994 the GNU mirrors defined in @code{(guix download)}.
995
996 The @code{sha256} field specifies the expected SHA256 hash of the file
997 being downloaded. It is mandatory, and allows Guix to check the
998 integrity of the file. The @code{(base32 @dots{})} form introduces the
999 base32 representation of the hash. You can obtain this information with
1000 @code{guix download} (@pxref{Invoking guix download}) and @code{guix
1001 hash} (@pxref{Invoking guix hash}).
1002
1003 @cindex patches
1004 When needed, the @code{origin} form can also have a @code{patches} field
1005 listing patches to be applied, and a @code{snippet} field giving a
1006 Scheme expression to modify the source code.
1007
1008 @item
1009 @cindex GNU Build System
1010 The @code{build-system} field is set to @var{gnu-build-system}. The
1011 @var{gnu-build-system} variable is defined in the @code{(guix
1012 build-system gnu)} module, and is bound to a @code{<build-system>}
1013 object.
1014
1015 Naturally, @var{gnu-build-system} represents the familiar GNU Build
1016 System, and variants thereof (@pxref{Configuration, configuration and
1017 makefile conventions,, standards, GNU Coding Standards}). In a
1018 nutshell, packages using the GNU Build System may be configured, built,
1019 and installed with the usual @code{./configure && make && make check &&
1020 make install} command sequence. This is what @var{gnu-build-system}
1021 does.
1022
1023 In addition, @var{gnu-build-system} ensures that the ``standard''
1024 environment for GNU packages is available. This includes tools such as
1025 GCC, Coreutils, Bash, Make, Diffutils, and Patch.
1026
1027 @item
1028 The @code{inputs} field specifies inputs to the build process---i.e.,
1029 build-time or run-time dependencies of the package. Here, we define an
1030 input called @code{"gawk"} whose value is that of the @var{gawk}
1031 variable; @var{gawk} is itself bound to a @code{<package>} object.
1032
1033 Note that GCC, Coreutils, Bash, and other essential tools do not need to
1034 be specified as inputs here. Instead, @var{gnu-build-system} takes care
1035 of ensuring that they are present.
1036
1037 However, any other dependencies need to be specified in the
1038 @code{inputs} field. Any dependency not specified here will simply be
1039 unavailable to the build process, possibly leading to a build failure.
1040 @end itemize
1041
1042 There are other fields that package definitions may provide. Of
1043 particular interest is the @code{arguments} field. When specified, it
1044 must be bound to a list of additional arguments to be passed to the
1045 build system. For instance, the above definition could be augmented
1046 with the following field initializer:
1047
1048 @example
1049 (arguments `(#:tests? #f
1050 #:configure-flags '("--enable-silent-rules")))
1051 @end example
1052
1053 @noindent
1054 These are keyword arguments (@pxref{Optional Arguments, keyword
1055 arguments in Guile,, guile, GNU Guile Reference Manual}). They are
1056 passed to @var{gnu-build-system}, which interprets them as meaning ``do
1057 not run @code{make check}'', and ``run @file{configure} with the
1058 @code{--enable-silent-rules} flag''. The value of these keyword
1059 parameters is actually evaluated in the @dfn{build stratum}---i.e., by a
1060 Guile process launched by the daemon (@pxref{Derivations}).
1061
1062 Once a package definition is in place@footnote{Simple package
1063 definitions like the one above may be automatically converted from the
1064 Nixpkgs distribution using the @command{guix import} command.}, the
1065 package may actually be built using the @code{guix build} command-line
1066 tool (@pxref{Invoking guix build}). Eventually, updating the package
1067 definition to a new upstream version can be partly automated by the
1068 @command{guix refresh} command (@pxref{Invoking guix refresh}).
1069
1070 Behind the scenes, a derivation corresponding to the @code{<package>}
1071 object is first computed by the @code{package-derivation} procedure.
1072 That derivation is stored in a @code{.drv} file under @file{/nix/store}.
1073 The build actions it prescribes may then be realized by using the
1074 @code{build-derivations} procedure (@pxref{The Store}).
1075
1076 @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
1077 Return the @code{<derivation>} object of @var{package} for @var{system}
1078 (@pxref{Derivations}).
1079
1080 @var{package} must be a valid @code{<package>} object, and @var{system}
1081 must be a string denoting the target system type---e.g.,
1082 @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
1083 must be a connection to the daemon, which operates on the store
1084 (@pxref{The Store}).
1085 @end deffn
1086
1087 @noindent
1088 @cindex cross-compilation
1089 Similarly, it is possible to compute a derivation that cross-builds a
1090 package for some other system:
1091
1092 @deffn {Scheme Procedure} package-cross-derivation @var{store} @
1093 @var{package} @var{target} [@var{system}]
1094 Return the @code{<derivation>} object of @var{package} cross-built from
1095 @var{system} to @var{target}.
1096
1097 @var{target} must be a valid GNU triplet denoting the target hardware
1098 and operating system, such as @code{"mips64el-linux-gnu"}
1099 (@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
1100 Configure and Build System}).
1101 @end deffn
1102
1103
1104 @node The Store
1105 @section The Store
1106
1107 @cindex store
1108 @cindex store paths
1109
1110 Conceptually, the @dfn{store} is where derivations that have been
1111 successfully built are stored---by default, under @file{/nix/store}.
1112 Sub-directories in the store are referred to as @dfn{store paths}. The
1113 store has an associated database that contains information such has the
1114 store paths referred to by each store path, and the list of @emph{valid}
1115 store paths---paths that result from a successful build.
1116
1117 The store is always accessed by the daemon on behalf of its clients
1118 (@pxref{Invoking guix-daemon}). To manipulate the store, clients
1119 connect to the daemon over a Unix-domain socket, send it requests, and
1120 read the result---these are remote procedure calls, or RPCs.
1121
1122 The @code{(guix store)} module provides procedures to connect to the
1123 daemon, and to perform RPCs. These are described below.
1124
1125 @deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
1126 Connect to the daemon over the Unix-domain socket at @var{file}. When
1127 @var{reserve-space?} is true, instruct it to reserve a little bit of
1128 extra space on the file system so that the garbage collector can still
1129 operate, should the disk become full. Return a server object.
1130
1131 @var{file} defaults to @var{%default-socket-path}, which is the normal
1132 location given the options that were passed to @command{configure}.
1133 @end deffn
1134
1135 @deffn {Scheme Procedure} close-connection @var{server}
1136 Close the connection to @var{server}.
1137 @end deffn
1138
1139 @defvr {Scheme Variable} current-build-output-port
1140 This variable is bound to a SRFI-39 parameter, which refers to the port
1141 where build and error logs sent by the daemon should be written.
1142 @end defvr
1143
1144 Procedures that make RPCs all take a server object as their first
1145 argument.
1146
1147 @deffn {Scheme Procedure} valid-path? @var{server} @var{path}
1148 Return @code{#t} when @var{path} is a valid store path.
1149 @end deffn
1150
1151 @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
1152 Add @var{text} under file @var{name} in the store, and return its store
1153 path. @var{references} is the list of store paths referred to by the
1154 resulting store path.
1155 @end deffn
1156
1157 @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
1158 Build @var{derivations} (a list of @code{<derivation>} objects or
1159 derivation paths), and return when the worker is done building them.
1160 Return @code{#t} on success.
1161 @end deffn
1162
1163 Note that the @code{(guix monads)} module provides a monad as well as
1164 monadic versions of the above procedures, with the goal of making it
1165 more convenient to work with code that accesses the store (@pxref{The
1166 Store Monad}).
1167
1168 @c FIXME
1169 @i{This section is currently incomplete.}
1170
1171 @node Derivations
1172 @section Derivations
1173
1174 @cindex derivations
1175 Low-level build actions and the environment in which they are performed
1176 are represented by @dfn{derivations}. A derivation contain the
1177 following pieces of information:
1178
1179 @itemize
1180 @item
1181 The outputs of the derivation---derivations produce at least one file or
1182 directory in the store, but may produce more.
1183
1184 @item
1185 The inputs of the derivations, which may be other derivations or plain
1186 files in the store (patches, build scripts, etc.)
1187
1188 @item
1189 The system type targeted by the derivation---e.g., @code{x86_64-linux}.
1190
1191 @item
1192 The file name of a build script in the store, along with the arguments
1193 to be passed.
1194
1195 @item
1196 A list of environment variables to be defined.
1197
1198 @end itemize
1199
1200 @cindex derivation path
1201 Derivations allow clients of the daemon to communicate build actions to
1202 the store. They exist in two forms: as an in-memory representation,
1203 both on the client- and daemon-side, and as files in the store whose
1204 name end in @code{.drv}---these files are referred to as @dfn{derivation
1205 paths}. Derivations paths can be passed to the @code{build-derivations}
1206 procedure to perform the build actions they prescribe (@pxref{The
1207 Store}).
1208
1209 The @code{(guix derivations)} module provides a representation of
1210 derivations as Scheme objects, along with procedures to create and
1211 otherwise manipulate derivations. The lowest-level primitive to create
1212 a derivation is the @code{derivation} procedure:
1213
1214 @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] [#:hash-mode #f] [#:inputs '()] [#:env-vars '()] [#:system (%current-system)] [#:references-graphs #f]
1215 Build a derivation with the given arguments, and return the resulting
1216 @code{<derivation>} object.
1217
1218 When @var{hash}, @var{hash-algo}, and @var{hash-mode} are given, a
1219 @dfn{fixed-output derivation} is created---i.e., one whose result is
1220 known in advance, such as a file download.
1221
1222 When @var{references-graphs} is true, it must be a list of file
1223 name/store path pairs. In that case, the reference graph of each store
1224 path is exported in the build environment in the corresponding file, in
1225 a simple text format.
1226 @end deffn
1227
1228 @noindent
1229 Here's an example with a shell script as its builder, assuming
1230 @var{store} is an open connection to the daemon, and @var{bash} points
1231 to a Bash executable in the store:
1232
1233 @lisp
1234 (use-modules (guix utils)
1235 (guix store)
1236 (guix derivations))
1237
1238 (let ((builder ; add the Bash script to the store
1239 (add-text-to-store store "my-builder.sh"
1240 "echo hello world > $out\n" '())))
1241 (derivation store "foo"
1242 bash `("-e" ,builder)
1243 #:env-vars '(("HOME" . "/homeless"))))
1244 @result{} #<derivation /nix/store/@dots{}-foo.drv => /nix/store/@dots{}-foo>
1245 @end lisp
1246
1247 As can be guessed, this primitive is cumbersome to use directly. An
1248 improved variant is @code{build-expression->derivation}, which allows
1249 the caller to directly pass a Guile expression as the build script:
1250
1251 @deffn {Scheme Procedure} build-expression->derivation @var{store} @
1252 @var{name} @var{exp} @
1253 [#:system (%current-system)] [#:inputs '()] @
1254 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
1255 [#:env-vars '()] [#:modules '()] @
1256 [#:references-graphs #f] [#:guile-for-build #f]
1257 Return a derivation that executes Scheme expression @var{exp} as a
1258 builder for derivation @var{name}. @var{inputs} must be a list of
1259 @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
1260 @code{"out"} is assumed. @var{modules} is a list of names of Guile
1261 modules from the current search path to be copied in the store,
1262 compiled, and made available in the load path during the execution of
1263 @var{exp}---e.g., @code{((guix build utils) (guix build
1264 gnu-build-system))}.
1265
1266 @var{exp} is evaluated in an environment where @code{%outputs} is bound
1267 to a list of output/path pairs, and where @code{%build-inputs} is bound
1268 to a list of string/output-path pairs made from @var{inputs}.
1269 Optionally, @var{env-vars} is a list of string pairs specifying the name
1270 and value of environment variables visible to the builder. The builder
1271 terminates by passing the result of @var{exp} to @code{exit}; thus, when
1272 @var{exp} returns @code{#f}, the build is considered to have failed.
1273
1274 @var{exp} is built using @var{guile-for-build} (a derivation). When
1275 @var{guile-for-build} is omitted or is @code{#f}, the value of the
1276 @code{%guile-for-build} fluid is used instead.
1277
1278 See the @code{derivation} procedure for the meaning of @var{references-graphs}.
1279 @end deffn
1280
1281 @noindent
1282 Here's an example of a single-output derivation that creates a directory
1283 containing one file:
1284
1285 @lisp
1286 (let ((builder '(let ((out (assoc-ref %outputs "out")))
1287 (mkdir out) ; create /nix/store/@dots{}-goo
1288 (call-with-output-file (string-append out "/test")
1289 (lambda (p)
1290 (display '(hello guix) p))))))
1291 (build-expression->derivation store "goo" builder))
1292
1293 @result{} #<derivation /nix/store/@dots{}-goo.drv => @dots{}>
1294 @end lisp
1295
1296 @cindex strata of code
1297 Remember that the build expression passed to
1298 @code{build-expression->derivation} is run by a separate Guile process
1299 than the one that calls @code{build-expression->derivation}: it is run
1300 by a Guile process launched by the daemon, typically in a chroot. So,
1301 while there is a single language for both the @dfn{host} and the build
1302 side, there are really two @dfn{strata} of code: the host-side, and the
1303 build-side code@footnote{The term @dfn{stratum} in this context was
1304 coined by Manuel Serrano et al. in the context of their work on Hop.}.
1305 This distinction is important to keep in mind, notably when using
1306 higher-level constructs such as @var{gnu-build-system} (@pxref{Defining
1307 Packages}). For this reason, Guix modules that are meant to be used in
1308 the build stratum are kept in the @code{(guix build @dots{})} name
1309 space.
1310
1311 @node The Store Monad
1312 @section The Store Monad
1313
1314 @cindex monad
1315
1316 The procedures that operate on the store described in the previous
1317 sections all take an open connection to the build daemon as their first
1318 argument. Although the underlying model is functional, they either have
1319 side effects or depend on the current state of the store.
1320
1321 The former is inconvenient: the connection to the build daemon has to be
1322 carried around in all those functions, making it impossible to compose
1323 functions that do not take that parameter with functions that do. The
1324 latter can be problematic: since store operations have side effects
1325 and/or depend on external state, they have to be properly sequenced.
1326
1327 @cindex monadic values
1328 @cindex monadic functions
1329 This is where the @code{(guix monads)} module comes in. This module
1330 provides a framework for working with @dfn{monads}, and a particularly
1331 useful monad for our uses, the @dfn{store monad}. Monads are a
1332 construct that allows two things: associating ``context'' with values
1333 (in our case, the context is the store), and building sequences of
1334 computations (here computations includes accesses to the store.) Values
1335 in a monad---values that carry this additional context---are called
1336 @dfn{monadic values}; procedures that return such values are called
1337 @dfn{monadic procedures}.
1338
1339 Consider this ``normal'' procedure:
1340
1341 @example
1342 (define (profile.sh store)
1343 ;; Return the name of a shell script in the store that
1344 ;; initializes the 'PATH' environment variable.
1345 (let* ((drv (package-derivation store coreutils))
1346 (out (derivation->output-path drv)))
1347 (add-text-to-store store "profile.sh"
1348 (format #f "export PATH=~a/bin" out))))
1349 @end example
1350
1351 Using @code{(guix monads)}, it may be rewritten as a monadic function:
1352
1353 @example
1354 (define (profile.sh)
1355 ;; Same, but return a monadic value.
1356 (mlet %store-monad ((bin (package-file coreutils "bin")))
1357 (text-file "profile.sh"
1358 (string-append "export PATH=" bin))))
1359 @end example
1360
1361 There are two things to note in the second version: the @code{store}
1362 parameter is now implicit, and the monadic value returned by
1363 @code{package-file}---a wrapper around @code{package-derivation} and
1364 @code{derivation->output-path}---is @dfn{bound} using @code{mlet}
1365 instead of plain @code{let}.
1366
1367 Calling the monadic @code{profile.sh} has no effect. To get the desired
1368 effect, one must use @code{run-with-store}:
1369
1370 @example
1371 (run-with-store (open-connection) (profile.sh))
1372 @result{} /nix/store/...-profile.sh
1373 @end example
1374
1375 The main syntactic forms to deal with monads in general are described
1376 below.
1377
1378 @deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
1379 Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
1380 in @var{monad}.
1381 @end deffn
1382
1383 @deffn {Scheme Syntax} return @var{val}
1384 Return a monadic value that encapsulates @var{val}.
1385 @end deffn
1386
1387 @deffn {Scheme Syntax} >>= @var{mval} @var{mproc}
1388 @dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
1389 procedure @var{mproc}@footnote{This operation is commonly referred to as
1390 ``bind'', but that name denotes an unrelated procedure in Guile. Thus
1391 we use this somewhat cryptic symbol inherited from the Haskell
1392 language.}.
1393 @end deffn
1394
1395 @deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
1396 @var{body} ...
1397 @deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
1398 @var{body} ...
1399 Bind the variables @var{var} to the monadic values @var{mval} in
1400 @var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
1401 ``normal'' value @var{val}, as per @code{let}.
1402
1403 @code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
1404 (@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
1405 @end deffn
1406
1407 The interface to the store monad provided by @code{(guix monads)} is as
1408 follows.
1409
1410 @defvr {Scheme Variable} %store-monad
1411 The store monad. Values in the store monad encapsulate accesses to the
1412 store. When its effect is needed, a value of the store monad must be
1413 ``evaluated'' by passing it to the @code{run-with-store} procedure (see
1414 below.)
1415 @end defvr
1416
1417 @deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
1418 Run @var{mval}, a monadic value in the store monad, in @var{store}, an
1419 open store connection.
1420 @end deffn
1421
1422 @deffn {Monadic Procedure} text-file @var{name} @var{text}
1423 Return as a monadic value the absolute file name in the store of the file
1424 containing @var{text}.
1425 @end deffn
1426
1427 @deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
1428 [#:system (%current-system)] [#:output "out"] Return as a monadic
1429 value in the absolute file name of @var{file} within the @var{output}
1430 directory of @var{package}. When @var{file} is omitted, return the name
1431 of the @var{output} directory of @var{package}.
1432 @end deffn
1433
1434 @deffn {Monadic Procedure} derivation-expression @var{name} @var{exp} @
1435 [#:system (%current-system)] [#:inputs '()] @
1436 [#:outputs '("out")] [#:hash #f] @
1437 [#:hash-algo #f] [#:env-vars '()] [#:modules '()] @
1438 [#:references-graphs #f] [#:guile-for-build #f]
1439 Monadic version of @code{build-expression->derivation}
1440 (@pxref{Derivations}).
1441 @end deffn
1442
1443 @deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
1444 Monadic version of @code{package-derivation} (@pxref{Defining
1445 Packages}).
1446 @end deffn
1447
1448
1449 @c *********************************************************************
1450 @node Utilities
1451 @chapter Utilities
1452
1453 This section describes tools primarily targeted at developers and users
1454 who write new package definitions. They complement the Scheme
1455 programming interface of Guix in a convenient way.
1456
1457 @menu
1458 * Invoking guix build:: Building packages from the command line.
1459 * Invoking guix download:: Downloading a file and printing its hash.
1460 * Invoking guix hash:: Computing the cryptographic hash of a file.
1461 * Invoking guix refresh:: Updating package definitions.
1462 @end menu
1463
1464 @node Invoking guix build
1465 @section Invoking @command{guix build}
1466
1467 The @command{guix build} command builds packages or derivations and
1468 their dependencies, and prints the resulting store paths. Note that it
1469 does not modify the user's profile---this is the job of the
1470 @command{guix package} command (@pxref{Invoking guix package}). Thus,
1471 it is mainly useful for distribution developers.
1472
1473 The general syntax is:
1474
1475 @example
1476 guix build @var{options} @var{package-or-derivation}@dots{}
1477 @end example
1478
1479 @var{package-or-derivation} may be either the name of a package found in
1480 the software distribution such as @code{coreutils} or
1481 @code{coreutils-8.20}, or a derivation such as
1482 @file{/nix/store/@dots{}-coreutils-8.19.drv}. Alternatively, the
1483 @code{--expression} option may be used to specify a Scheme expression
1484 that evaluates to a package; this is useful when disambiguation among
1485 several same-named packages or package variants is needed.
1486
1487 The @var{options} may be zero or more of the following:
1488
1489 @table @code
1490
1491 @item --expression=@var{expr}
1492 @itemx -e @var{expr}
1493 Build the package or derivation @var{expr} evaluates to.
1494
1495 For example, @var{expr} may be @code{(@@ (gnu packages guile)
1496 guile-1.8)}, which unambiguously designates this specific variant of
1497 version 1.8 of Guile.
1498
1499 Alternately, @var{expr} may refer to a zero-argument monadic procedure
1500 (@pxref{The Store Monad}). The procedure must return a derivation as a
1501 monadic value, which is then passed through @code{run-with-store}.
1502
1503 @item --source
1504 @itemx -S
1505 Build the packages' source derivations, rather than the packages
1506 themselves.
1507
1508 For instance, @code{guix build -S gcc} returns something like
1509 @file{/nix/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
1510
1511 The returned source tarball is the result of applying any patches and
1512 code snippets specified in the package's @code{origin} (@pxref{Defining
1513 Packages}).
1514
1515 @item --system=@var{system}
1516 @itemx -s @var{system}
1517 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
1518 the host's system type.
1519
1520 An example use of this is on Linux-based systems, which can emulate
1521 different personalities. For instance, passing
1522 @code{--system=i686-linux} on an @code{x86_64-linux} system allows users
1523 to build packages in a complete 32-bit environment.
1524
1525 @item --target=@var{triplet}
1526 @cindex cross-compilation
1527 Cross-build for @var{triplet}, which must be a valid GNU triplet, such
1528 as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
1529 configuration triplets,, configure, GNU Configure and Build System}).
1530
1531 @item --derivations
1532 @itemx -d
1533 Return the derivation paths, not the output paths, of the given
1534 packages.
1535
1536 @item --keep-failed
1537 @itemx -K
1538 Keep the build tree of failed builds. Thus, if a build fail, its build
1539 tree is kept under @file{/tmp}, in a directory whose name is shown at
1540 the end of the build log. This is useful when debugging build issues.
1541
1542 @item --dry-run
1543 @itemx -n
1544 Do not build the derivations.
1545
1546 @item --fallback
1547 When substituting a pre-built binary fails, fall back to building
1548 packages locally.
1549
1550 @item --no-substitutes
1551 Do not use substitutes for build products. That is, always build things
1552 locally instead of allowing downloads of pre-built binaries.
1553
1554 @item --max-silent-time=@var{seconds}
1555 When the build or substitution process remains silent for more than
1556 @var{seconds}, terminate it and report a build failure.
1557
1558 @item --cores=@var{n}
1559 @itemx -c @var{n}
1560 Allow the use of up to @var{n} CPU cores for the build. The special
1561 value @code{0} means to use as many CPU cores as available.
1562
1563 @item --root=@var{file}
1564 @itemx -r @var{file}
1565 Make @var{file} a symlink to the result, and register it as a garbage
1566 collector root.
1567
1568 @item --verbosity=@var{level}
1569 Use the given verbosity level. @var{level} must be an integer between 0
1570 and 5; higher means more verbose output. Setting a level of 4 or more
1571 may be helpful when debugging setup issues with the build daemon.
1572
1573 @item --log-file
1574 Return the build log file names for the given
1575 @var{package-or-derivation}s, or raise an error if build logs are
1576 missing.
1577
1578 This works regardless of how packages or derivations are specified. For
1579 instance, the following invocations are equivalent:
1580
1581 @example
1582 guix build --log-file `guix build -d guile`
1583 guix build --log-file `guix build guile`
1584 guix build --log-file guile
1585 guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
1586 @end example
1587
1588
1589 @end table
1590
1591 Behind the scenes, @command{guix build} is essentially an interface to
1592 the @code{package-derivation} procedure of the @code{(guix packages)}
1593 module, and to the @code{build-derivations} procedure of the @code{(guix
1594 store)} module.
1595
1596 @node Invoking guix download
1597 @section Invoking @command{guix download}
1598
1599 When writing a package definition, developers typically need to download
1600 the package's source tarball, compute its SHA256 hash, and write that
1601 hash in the package definition (@pxref{Defining Packages}). The
1602 @command{guix download} tool helps with this task: it downloads a file
1603 from the given URI, adds it to the store, and prints both its file name
1604 in the store and its SHA256 hash.
1605
1606 The fact that the downloaded file is added to the store saves bandwidth:
1607 when the developer eventually tries to build the newly defined package
1608 with @command{guix build}, the source tarball will not have to be
1609 downloaded again because it is already in the store. It is also a
1610 convenient way to temporarily stash files, which may be deleted
1611 eventually (@pxref{Invoking guix gc}).
1612
1613 The @command{guix download} command supports the same URIs as used in
1614 package definitions. In particular, it supports @code{mirror://} URIs.
1615 @code{https} URIs (HTTP over TLS) are supported @emph{provided} the
1616 Guile bindings for GnuTLS are available in the user's environment; when
1617 they are not available, an error is raised.
1618
1619 The following option is available:
1620
1621 @table @code
1622 @item --format=@var{fmt}
1623 @itemx -f @var{fmt}
1624 Write the hash in the format specified by @var{fmt}. For more
1625 information on the valid values for @var{fmt}, @ref{Invoking guix hash}.
1626 @end table
1627
1628 @node Invoking guix hash
1629 @section Invoking @command{guix hash}
1630
1631 The @command{guix hash} command computes the SHA256 hash of a file.
1632 It is primarily a convenience tool for anyone contributing to the
1633 distribution: it computes the cryptographic hash of a file, which can be
1634 used in the definition of a package (@pxref{Defining Packages}).
1635
1636 The general syntax is:
1637
1638 @example
1639 guix hash @var{option} @var{file}
1640 @end example
1641
1642 @command{guix hash} has the following option:
1643
1644 @table @code
1645
1646 @item --format=@var{fmt}
1647 @itemx -f @var{fmt}
1648 Write the hash in the format specified by @var{fmt}.
1649
1650 Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
1651 (@code{hex} and @code{hexadecimal} can be used as well).
1652
1653 If the @option{--format} option is not specified, @command{guix hash}
1654 will output the hash in @code{nix-base32}. This representation is used
1655 in the definitions of packages.
1656
1657 @end table
1658
1659 @node Invoking guix refresh
1660 @section Invoking @command{guix refresh}
1661
1662 The primary audience of the @command{guix refresh} command is developers
1663 of the GNU software distribution. By default, it reports any packages
1664 provided by the distribution that are outdated compared to the latest
1665 upstream version, like this:
1666
1667 @example
1668 $ guix refresh
1669 gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
1670 gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
1671 @end example
1672
1673 It does so by browsing each package's FTP directory and determining the
1674 highest version number of the source tarballs
1675 therein@footnote{Currently, this only works for GNU packages.}.
1676
1677 When passed @code{--update}, it modifies distribution source files to
1678 update the version numbers and source tarball hashes of those packages'
1679 recipes (@pxref{Defining Packages}). This is achieved by downloading
1680 each package's latest source tarball and its associated OpenPGP
1681 signature, authenticating the downloaded tarball against its signature
1682 using @command{gpg}, and finally computing its hash. When the public
1683 key used to sign the tarball is missing from the user's keyring, an
1684 attempt is made to automatically retrieve it from a public key server;
1685 when it's successful, the key is added to the user's keyring; otherwise,
1686 @command{guix refresh} reports an error.
1687
1688 The following options are supported:
1689
1690 @table @code
1691
1692 @item --update
1693 @itemx -u
1694 Update distribution source files (package recipes) in place.
1695 @ref{Defining Packages}, for more information on package definitions.
1696
1697 @item --select=[@var{subset}]
1698 @itemx -s @var{subset}
1699 Select all the packages in @var{subset}, one of @code{core} or
1700 @code{non-core}.
1701
1702 The @code{core} subset refers to all the packages at the core of the
1703 distribution---i.e., packages that are used to build ``everything
1704 else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
1705 changing one of these packages in the distribution entails a rebuild of
1706 all the others. Thus, such updates are an inconvenience to users in
1707 terms of build time or bandwidth used to achieve the upgrade.
1708
1709 The @code{non-core} subset refers to the remaining packages. It is
1710 typically useful in cases where an update of the core packages would be
1711 inconvenient.
1712
1713 @end table
1714
1715 In addition, @command{guix refresh} can be passed one or more package
1716 names, as in this example:
1717
1718 @example
1719 guix refresh -u emacs idutils
1720 @end example
1721
1722 @noindent
1723 The command above specifically updates the @code{emacs} and
1724 @code{idutils} packages. The @code{--select} option would have no
1725 effect in this case.
1726
1727 The following options can be used to customize GnuPG operation:
1728
1729 @table @code
1730
1731 @item --key-server=@var{host}
1732 Use @var{host} as the OpenPGP key server when importing a public key.
1733
1734 @item --gpg=@var{command}
1735 Use @var{command} as the GnuPG 2.x command. @var{command} is searched
1736 for in @code{$PATH}.
1737
1738 @end table
1739
1740
1741 @c *********************************************************************
1742 @node GNU Distribution
1743 @chapter GNU Distribution
1744
1745 Guix comes with a distribution of free software@footnote{The term
1746 ``free'' here refers to the
1747 @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
1748 users of that software}.} that forms the basis of the GNU system. This
1749 includes core GNU packages such as GNU libc, GCC, and Binutils, as well
1750 as many GNU and non-GNU applications. The complete list of available
1751 packages can be browsed
1752 @url{http://www.gnu.org/software/guix/package-list.html,on-line} or by
1753 running @command{guix package} (@pxref{Invoking guix package}):
1754
1755 @example
1756 guix package --list-available
1757 @end example
1758
1759 Our goal is to build a practical 100% free software distribution of
1760 Linux-based and other variants of GNU, with a focus on the promotion and
1761 tight integration of GNU components, and an emphasis on programs and
1762 tools that help users exert that freedom.
1763
1764 The GNU distribution is currently available on the following platforms:
1765
1766 @table @code
1767
1768 @item x86_64-linux
1769 Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
1770
1771 @item i686-linux
1772 Intel 32-bit architecture (IA32), Linux-Libre kernel;
1773
1774 @item mips64el-linux
1775 little-endian 64-bit MIPS processors, specifically the Loongson series,
1776 n32 application binary interface (ABI), and Linux-Libre kernel.
1777
1778 @end table
1779
1780 @noindent
1781 For information on porting to other architectures or kernels,
1782 @xref{Porting}.
1783
1784 @menu
1785 * Installing Debugging Files:: Feeding the debugger.
1786 * Package Modules:: Packages from the programmer's viewpoint.
1787 * Packaging Guidelines:: Growing the distribution.
1788 * Bootstrapping:: GNU/Linux built from scratch.
1789 * Porting:: Targeting another platform or kernel.
1790 * System Configuration:: Configuring a GNU system.
1791 @end menu
1792
1793 Building this distribution is a cooperative effort, and you are invited
1794 to join! @ref{Contributing}, for information about how you can help.
1795
1796
1797 @node Installing Debugging Files
1798 @section Installing Debugging Files
1799
1800 Program binaries, as produced by the GCC compilers for instance, are
1801 typically written in the ELF format, with a section containing
1802 @dfn{debugging information}. Debugging information is what allows the
1803 debugger, GDB, to map binary code to source code; it is required to
1804 debug a compiled program in good conditions.
1805
1806 The problem with debugging information is that is takes up a fair amount
1807 of disk space. For example, debugging information for the GNU C Library
1808 weighs in at more than 60 MiB. Thus, as a user, keeping all the
1809 debugging info of all the installed programs is usually not an option.
1810 Yet, space savings should not come at the cost of an impediment to
1811 debugging---especially in the GNU system, which should make it easier
1812 for users to exert their computing freedom (@pxref{GNU Distribution}).
1813
1814 Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
1815 mechanism that allows users to get the best of both worlds: debugging
1816 information can be stripped from the binaries and stored in separate
1817 files. GDB is then able to load debugging information from those files,
1818 when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
1819 with GDB}).
1820
1821 The GNU distribution takes advantage of this by storing debugging
1822 information in the @code{lib/debug} sub-directory of a separate package
1823 output unimaginatively called @code{debug} (@pxref{Packages with
1824 Multiple Outputs}). Users can choose to install the @code{debug} output
1825 of a package when they need it. For instance, the following command
1826 installs the debugging information for the GNU C Library and for GNU
1827 Guile:
1828
1829 @example
1830 guix package -i glibc:debug -i guile:debug
1831 @end example
1832
1833 GDB must then be told to look for debug files in the user's profile, by
1834 setting the @code{debug-file-directory} variable (consider setting it
1835 from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
1836 GDB}):
1837
1838 @example
1839 (gdb) set debug-file-directory ~/.guix-profile/lib/debug
1840 @end example
1841
1842 From there on, GDB will pick up debugging information from the
1843 @code{.debug} files under @file{~/.guix-profile/lib/debug}.
1844
1845 @c XXX: keep me up-to-date
1846 The @code{debug} output mechanism in Guix is implemented by the
1847 @code{gnu-build-system} (@pxref{Defining Packages}). Currently, it is
1848 opt-in---debugging information is available only for those packages
1849 whose definition explicitly declares a @code{debug} output. This may be
1850 changed to opt-out in the future, if our build farm servers can handle
1851 the load. To check whether a package has a @code{debug} output, use
1852 @command{guix package --list-available} (@pxref{Invoking guix package}).
1853
1854
1855 @node Package Modules
1856 @section Package Modules
1857
1858 From a programming viewpoint, the package definitions of the
1859 distribution are provided by Guile modules in the @code{(gnu packages
1860 ...)} name space (@pxref{Modules, Guile modules,, guile, GNU Guile
1861 Reference Manual}). For instance, the @code{(gnu packages emacs)}
1862 module exports a variable named @code{emacs}, which is bound to a
1863 @code{<package>} object (@pxref{Defining Packages}). The @code{(gnu
1864 packages)} module provides facilities for searching for packages.
1865
1866 The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
1867 each package is built based solely on other packages in the
1868 distribution. The root of this dependency graph is a small set of
1869 @dfn{bootstrap binaries}, provided by the @code{(gnu packages
1870 bootstrap)} module. For more information on bootstrapping,
1871 @ref{Bootstrapping}.
1872
1873 @node Packaging Guidelines
1874 @section Packaging Guidelines
1875
1876 The GNU distribution is nascent and may well lack some of your favorite
1877 packages. This section describes how you can help make the distribution
1878 grow. @xref{Contributing}, for additional information on how you can
1879 help.
1880
1881 Free software packages are usually distributed in the form of
1882 @dfn{source code tarballs}---typically @file{tar.gz} files that contain
1883 all the source files. Adding a package to the distribution means
1884 essentially two things: adding a @dfn{recipe} that describes how to
1885 build the package, including a list of other packages required to build
1886 it, and adding @dfn{package meta-data} along with that recipe, such as a
1887 description and licensing information.
1888
1889 In Guix all this information is embodied in @dfn{package definitions}.
1890 Package definitions provide a high-level view of the package. They are
1891 written using the syntax of the Scheme programming language; in fact,
1892 for each package we define a variable bound to the package definition,
1893 and export that variable from a module (@pxref{Package Modules}).
1894 However, in-depth Scheme knowledge is @emph{not} a prerequisite for
1895 creating packages. For more information on package definitions,
1896 @ref{Defining Packages}.
1897
1898 Once a package definition is in place, stored in a file in the Guix
1899 source tree, it can be tested using the @command{guix build} command
1900 (@pxref{Invoking guix build}). For example, assuming the new package is
1901 called @code{gnew}, you may run this command from the Guix build tree:
1902
1903 @example
1904 ./pre-inst-env guix build gnew --keep-failed
1905 @end example
1906
1907 Using @code{--keep-failed} makes it easier to debug build failures since
1908 it provides access to the failed build tree.
1909
1910 Once your package builds correctly, please send us a patch
1911 (@pxref{Contributing}). Well, if you need help, we will be happy to
1912 help you too. Once the patch is committed in the Guix repository, the
1913 new package automatically gets built on the supported platforms by
1914 @url{http://hydra.gnu.org/gnu/master, our continuous integration
1915 system}.
1916
1917 @cindex substituter
1918 Users can obtain the new package definition simply by running
1919 @command{guix pull} (@pxref{Invoking guix pull}). When
1920 @code{hydra.gnu.org} is done building the package, installing the
1921 package automatically downloads binaries from there (except when using
1922 @code{--no-substitutes}). The only place where human intervention is
1923 needed is to review and apply the patch.
1924
1925
1926 @menu
1927 * Software Freedom:: What may go into the distribution.
1928 * Package Naming:: What's in a name?
1929 * Version Numbers:: When the name is not enough.
1930 * Python Modules:: Taming the snake.
1931 @end menu
1932
1933 @node Software Freedom
1934 @subsection Software Freedom
1935
1936 @c Adapted from http://www.gnu.org/philosophy/philosophy.html.
1937
1938 The GNU operating system has been developed so that users can have
1939 freedom in their computing. GNU is @dfn{free software}, meaning that
1940 users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
1941 essential freedoms}: to run the program, to study and change the program
1942 in source code form, to redistribute exact copies, and to distribute
1943 modified versions. Packages found in the GNU distribution provide only
1944 software that conveys these four freedoms.
1945
1946 In addition, the GNU distribution follow the
1947 @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
1948 software distribution guidelines}. Among other things, these guidelines
1949 reject non-free firmware, recommendations of non-free software, and
1950 discuss ways to deal with trademarks and patents.
1951
1952 Some packages contain a small and optional subset that violates the
1953 above guidelines, for instance because this subset is itself non-free
1954 code. When that happens, the offending items are removed with
1955 appropriate patches or code snippets in the package definition's
1956 @code{origin} form (@pxref{Defining Packages}). That way, @code{guix
1957 build --source} returns the ``freed'' source rather than the unmodified
1958 upstream source.
1959
1960
1961 @node Package Naming
1962 @subsection Package Naming
1963
1964 A package has actually two names associated with it:
1965 First, there is the name of the @emph{Scheme variable}, the one following
1966 @code{define-public}. By this name, the package can be made known in the
1967 Scheme code, for instance as input to another package. Second, there is
1968 the string in the @code{name} field of a package definition. This name
1969 is used by package management commands such as
1970 @command{guix package} and @command{guix build}.
1971
1972 Both are usually the same and correspond to the lowercase conversion of the
1973 project name chosen upstream. For instance, the GNUnet project is packaged
1974 as @code{gnunet}. We do not add @code{lib} prefixes for library packages,
1975 unless these are already part of the official project name. But see
1976 @ref{Python Modules} for special rules concerning modules for
1977 the Python language.
1978
1979
1980 @node Version Numbers
1981 @subsection Version Numbers
1982
1983 We usually package only the latest version of a given free software
1984 project. But sometimes, for instance for incompatible library versions,
1985 two (or more) versions of the same package are needed. These require
1986 different Scheme variable names. We use the name as defined
1987 in @ref{Package Naming}
1988 for the most recent version; previous versions use the same name, suffixed
1989 by @code{-} and the smallest prefix of the version number that may
1990 distinguish the two versions.
1991
1992 The name inside the package definition is the same for all versions of a
1993 package and does not contain any version number.
1994
1995 For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
1996
1997 @example
1998 (define-public gtk+
1999 (package
2000 (name "gtk+")
2001 (version "3.9.12")
2002 ...))
2003 (define-public gtk+-2
2004 (package
2005 (name "gtk+")
2006 (version "2.24.20")
2007 ...))
2008 @end example
2009 If we also wanted GTK+ 3.8.2, this would be packaged as
2010 @example
2011 (define-public gtk+-3.8
2012 (package
2013 (name "gtk+")
2014 (version "3.8.2")
2015 ...))
2016 @end example
2017
2018
2019 @node Python Modules
2020 @subsection Python Modules
2021
2022 We currently package Python 2 and Python 3, under the Scheme variable names
2023 @code{python-2} and @code{python} as explained in @ref{Version Numbers}.
2024 To avoid confusion and naming clashes with other programming languages, it
2025 seems desirable that the name of a package for a Python module contains
2026 the word @code{python}.
2027
2028 Some modules are compatible with only one version of Python, others with both.
2029 If the package Foo compiles only with Python 3, we name it
2030 @code{python-foo}; if it compiles only with Python 2, we name it
2031 @code{python2-foo}. If it is compatible with both versions, we create two
2032 packages with the corresponding names.
2033
2034 If a project already contains the word @code{python}, we drop this;
2035 for instance, the module python-dateutil is packaged under the names
2036 @code{python-dateutil} and @code{python2-dateutil}.
2037
2038
2039
2040
2041
2042 @node Bootstrapping
2043 @section Bootstrapping
2044
2045 @c Adapted from the ELS 2013 paper.
2046
2047 @cindex bootstrapping
2048
2049 Bootstrapping in our context refers to how the distribution gets built
2050 ``from nothing''. Remember that the build environment of a derivation
2051 contains nothing but its declared inputs (@pxref{Introduction}). So
2052 there's an obvious chicken-and-egg problem: how does the first package
2053 get built? How does the first compiler get compiled? Note that this is
2054 a question of interest only to the curious hacker, not to the regular
2055 user, so you can shamelessly skip this section if you consider yourself
2056 a ``regular user''.
2057
2058 @cindex bootstrap binaries
2059 The GNU system is primarily made of C code, with libc at its core. The
2060 GNU build system itself assumes the availability of a Bourne shell and
2061 command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
2062 `grep'. Furthermore, build programs---programs that run
2063 @code{./configure}, @code{make}, etc.---are written in Guile Scheme
2064 (@pxref{Derivations}). Consequently, to be able to build anything at
2065 all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
2066 Binutils, libc, and the other packages mentioned above---the
2067 @dfn{bootstrap binaries}.
2068
2069 These bootstrap binaries are ``taken for granted'', though we can also
2070 re-create them if needed (more on that later).
2071
2072 @unnumberedsubsec Preparing to Use the Bootstrap Binaries
2073
2074 @c As of Emacs 24.3, Info-mode displays the image, but since it's a
2075 @c large image, it's hard to scroll. Oh well.
2076 @image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
2077
2078 The figure above shows the very beginning of the dependency graph of the
2079 distribution, corresponding to the package definitions of the @code{(gnu
2080 packages bootstrap)} module. At this level of detail, things are
2081 slightly complex. First, Guile itself consists of an ELF executable,
2082 along with many source and compiled Scheme files that are dynamically
2083 loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
2084 tarball shown in this graph. This tarball is part of Guix's ``source''
2085 distribution, and gets inserted into the store with @code{add-to-store}
2086 (@pxref{The Store}).
2087
2088 But how do we write a derivation that unpacks this tarball and adds it
2089 to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
2090 derivation---the first one that gets built---uses @code{bash} as its
2091 builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
2092 @code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
2093 @file{xz}, and @file{mkdir} are statically-linked binaries, also part of
2094 the Guix source distribution, whose sole purpose is to allow the Guile
2095 tarball to be unpacked.
2096
2097 Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
2098 Guile that can be used to run subsequent build programs. Its first task
2099 is to download tarballs containing the other pre-built binaries---this
2100 is what the @code{.tar.xz.drv} derivations do. Guix modules such as
2101 @code{ftp-client.scm} are used for this purpose. The
2102 @code{module-import.drv} derivations import those modules in a directory
2103 in the store, using the original layout. The
2104 @code{module-import-compiled.drv} derivations compile those modules, and
2105 write them in an output directory with the right layout. This
2106 corresponds to the @code{#:modules} argument of
2107 @code{build-expression->derivation} (@pxref{Derivations}).
2108
2109 Finally, the various tarballs are unpacked by the
2110 derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
2111 etc., at which point we have a working C tool chain.
2112
2113
2114 @unnumberedsubsec Building the Build Tools
2115
2116 @c TODO: Add a package-level dependency graph generated from (gnu
2117 @c packages base).
2118
2119 Bootstrapping is complete when we have a full tool chain that does not
2120 depend on the pre-built bootstrap tools discussed above. This
2121 no-dependency requirement is verified by checking whether the files of
2122 the final tool chain contain references to the @file{/nix/store}
2123 directories of the bootstrap inputs. The process that leads to this
2124 ``final'' tool chain is described by the package definitions found in
2125 the @code{(gnu packages base)} module.
2126
2127 @c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
2128 The first tool that gets built with the bootstrap binaries is
2129 GNU Make, which is a prerequisite for all the following packages.
2130 From there Findutils and Diffutils get built.
2131
2132 Then come the first-stage Binutils and GCC, built as pseudo cross
2133 tools---i.e., with @code{--target} equal to @code{--host}. They are
2134 used to build libc. Thanks to this cross-build trick, this libc is
2135 guaranteed not to hold any reference to the initial tool chain.
2136
2137 From there the final Binutils and GCC are built. GCC uses @code{ld}
2138 from the final Binutils, and links programs against the just-built libc.
2139 This tool chain is used to build the other packages used by Guix and by
2140 the GNU Build System: Guile, Bash, Coreutils, etc.
2141
2142 And voilà! At this point we have the complete set of build tools that
2143 the GNU Build System expects. These are in the @code{%final-inputs}
2144 variables of the @code{(gnu packages base)} module, and are implicitly
2145 used by any package that uses @code{gnu-build-system} (@pxref{Defining
2146 Packages}).
2147
2148
2149 @unnumberedsubsec Building the Bootstrap Binaries
2150
2151 Because the final tool chain does not depend on the bootstrap binaries,
2152 those rarely need to be updated. Nevertheless, it is useful to have an
2153 automated way to produce them, should an update occur, and this is what
2154 the @code{(gnu packages make-bootstrap)} module provides.
2155
2156 The following command builds the tarballs containing the bootstrap
2157 binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
2158 of Coreutils and other basic command-line tools):
2159
2160 @example
2161 guix build bootstrap-tarballs
2162 @end example
2163
2164 The generated tarballs are those that should be referred to in the
2165 @code{(gnu packages bootstrap)} module mentioned at the beginning of
2166 this section.
2167
2168 Still here? Then perhaps by now you've started to wonder: when do we
2169 reach a fixed point? That is an interesting question! The answer is
2170 unknown, but if you would like to investigate further (and have
2171 significant computational and storage resources to do so), then let us
2172 know.
2173
2174 @node Porting
2175 @section Porting to a New Platform
2176
2177 As discussed above, the GNU distribution is self-contained, and
2178 self-containment is achieved by relying on pre-built ``bootstrap
2179 binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
2180 operating system kernel, CPU architecture, and application binary
2181 interface (ABI). Thus, to port the distribution to a platform that is
2182 not yet supported, one must build those bootstrap binaries, and update
2183 the @code{(gnu packages bootstrap)} module to use them on that platform.
2184
2185 Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
2186 When everything goes well, and assuming the GNU tool chain supports the
2187 target platform, this can be as simple as running a command like this
2188 one:
2189
2190 @example
2191 guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
2192 @end example
2193
2194 Once these are built, the @code{(gnu packages bootstrap)} module needs
2195 to be updated to refer to these binaries on the target platform. In
2196 addition, the @code{glibc-dynamic-linker} procedure in that module must
2197 be augmented to return the right file name for libc's dynamic linker on
2198 that platform; likewise, @code{system->linux-architecture} in @code{(gnu
2199 packages linux)} must be taught about the new platform.
2200
2201 In practice, there may be some complications. First, it may be that the
2202 extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
2203 above) is not recognized by all the GNU tools. Typically, glibc
2204 recognizes some of these, whereas GCC uses an extra @code{--with-abi}
2205 configure flag (see @code{gcc.scm} for examples of how to handle this).
2206 Second, some of the required packages could fail to build for that
2207 platform. Lastly, the generated binaries could be broken for some
2208 reason.
2209
2210
2211 @node System Configuration
2212 @section System Configuration
2213
2214 @emph{This section documents work-in-progress. As such it may be
2215 incomplete, outdated, or open to discussions. Please discuss it on
2216 @email{guix-devel@@gnu.org}.}
2217
2218 @cindex system configuration
2219 The GNU system supports a consistent whole-system configuration
2220 mechanism. By that we mean that all aspects of the global system
2221 configuration---such as the available system services, timezone and
2222 locale settings, user accounts---are declared in a single place. Such
2223 a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
2224
2225 One of the advantages of putting all the system configuration under the
2226 control of Guix is that it supports transactional system upgrades, and
2227 makes it possible to roll-back to a previous system instantiation,
2228 should something go wrong with the new one (@pxref{Features}). Another
2229 one is that it makes it easy to replicate the exact same configuration
2230 across different machines, or at different points in time, without
2231 having to resort to additional administration tools layered on top of
2232 the system's own tools.
2233 @c Yes, we're talking of Puppet, Chef, & co. here. ↑
2234
2235 This section describes this mechanism. First we focus on the system
2236 administrator's viewpoint---explaining how the system is configured and
2237 instantiated. Then we show how this mechanism can be extended, for
2238 instance to support new system services.
2239
2240 @menu
2241 * Using the Configuration System:: Customizing your GNU system.
2242 * Defining Services:: Adding new service definitions.
2243 @end menu
2244
2245 @node Using the Configuration System
2246 @subsection Using the Configuration System
2247
2248 The operating system is configured by filling in an
2249 @code{operating-system} structure, as defined by the @code{(gnu system)}
2250 module. A simple setup, with the default system services, the default
2251 Linux-Libre kernel, initial RAM disk, and boot loader looks like this:
2252
2253 @findex operating-system
2254 @lisp
2255 (use-modules (gnu system)
2256 (gnu system shadow) ; for 'user-account'
2257 (gnu system service) ; for 'lsh-service'
2258 (gnu packages base) ; Coreutils, grep, etc.
2259 (gnu packages bash) ; Bash
2260 (gnu packages system) ; dmd, Inetutils
2261 (gnu packages zile) ; Zile
2262 (gnu packages less) ; less
2263 (gnu packages guile) ; Guile
2264 (gnu packages linux)) ; procps, psmisc
2265
2266 (define komputilo
2267 (operating-system
2268 (host-name "komputilo")
2269 (timezone "Europe/Paris")
2270 (locale "fr_FR.UTF-8")
2271 (users (list (user-account
2272 (name "alice")
2273 (password "")
2274 (uid 1000) (gid 100)
2275 (comment "Bob's sister")
2276 (home-directory "/home/alice"))))
2277 (packages (list coreutils bash guile-2.0
2278 guix dmd
2279 inetutils
2280 findutils grep sed
2281 procps psmisc
2282 zile less))
2283 (services (cons (lsh-service #:port 2222 #:allow-root-login? #t)
2284 %standard-services))))
2285 @end lisp
2286
2287 This example should be self-describing. The @code{packages} field lists
2288 packages provided by the various @code{(gnu packages ...)} modules above
2289 (@pxref{Package Modules}). These are the packages that will be globally
2290 visible on the system, for all user accounts---i.e., in every user's
2291 @code{PATH} environment variable---in addition to the per-user profiles
2292 (@pxref{Invoking guix package}).
2293
2294 The @code{services} field lists @dfn{system services} to be made
2295 available when the system starts. The @var{%standard-services} list,
2296 from the @code{(gnu system)} module, provides the basic services one
2297 would expect from a GNU system: a login service (mingetty) on each tty,
2298 syslogd, libc's name service cache daemon (nscd), etc.
2299
2300 The @code{operating-system} declaration above specifies that, in
2301 addition to those services, we want the @command{lshd} secure shell
2302 daemon listening on port 2222, and allowing remote @code{root} logins
2303 (@pxref{Invoking lshd,,, lsh, GNU lsh Manual}). Under the hood,
2304 @code{lsh-service} arranges so that @code{lshd} is started with the
2305 right command-line options, possibly with supporting configuration files
2306 generated as needed (@pxref{Defining Services}).
2307
2308 @c TODO: update when that command exists
2309 Assuming the above snippet is stored in the @file{my-system-config.scm}
2310 file, the (yet unwritten!) @command{guix system --boot
2311 my-system-config.scm} command instantiates that configuration, and makes
2312 it the default GRUB boot entry. The normal way to change the system's
2313 configuration is by updating this file and re-running the @command{guix
2314 system} command.
2315
2316 At the Scheme level, the bulk of an @code{operating-system} declaration
2317 is instantiated with the following monadic procedure (@pxref{The Store
2318 Monad}):
2319
2320 @deffn {Monadic Procedure} operating-system-derivation os
2321 Return a derivation that builds @var{os}, an @code{operating-system}
2322 object (@pxref{Derivations}).
2323
2324 The output of the derivation is a single directory that refers to all
2325 the packages, configuration files, and other supporting files needed to
2326 instantiate @var{os}.
2327 @end deffn
2328
2329
2330 @node Defining Services
2331 @subsection Defining Services
2332
2333 The @code{(gnu system dmd)} module defines several procedures that allow
2334 users to declare the operating system's services (@pxref{Using the
2335 Configuration System}). These procedures are @emph{monadic
2336 procedures}---i.e., procedures that return a monadic value in the store
2337 monad (@pxref{The Store Monad}). Examples of such procedures include:
2338
2339 @table @code
2340 @item mingetty-service
2341 return the definition of a service that runs @command{mingetty} to
2342 offer a login service on the given console tty;
2343
2344 @item nscd-service
2345 return a definition for libc's name service cache daemon (nscd);
2346
2347 @item guix-service
2348 return a definition for a service that runs @command{guix-daemon}
2349 (@pxref{Invoking guix-daemon}).
2350 @end table
2351
2352 @cindex service definition
2353 The monadic value returned by those procedures is a @dfn{service
2354 definition}---a structure as returned by the @code{service} form.
2355 Service definitions specifies the inputs the service depends on, and an
2356 expression to start and stop the service. Behind the scenes, service
2357 definitions are ``translated'' into the form suitable for the
2358 configuration file of dmd, the init system (@pxref{Services,,, dmd, GNU
2359 dmd Manual}).
2360
2361 As an example, here is what the @code{nscd-service} procedure looks
2362 like:
2363
2364 @lisp
2365 (define (nscd-service)
2366 (mlet %store-monad ((nscd (package-file glibc "sbin/nscd")))
2367 (return (service
2368 (documentation "Run libc's name service cache daemon.")
2369 (provision '(nscd))
2370 (start `(make-forkexec-constructor ,nscd "-f" "/dev/null"
2371 "--foreground"))
2372 (stop `(make-kill-destructor))
2373
2374 (respawn? #f)
2375 (inputs `(("glibc" ,glibc)))))))
2376 @end lisp
2377
2378 @noindent
2379 The @code{inputs} field specifies that this service depends on the
2380 @var{glibc} package---the package that contains the @command{nscd}
2381 program. The @code{start} and @code{stop} fields are expressions that
2382 make use of dmd's facilities to start and stop processes (@pxref{Service
2383 De- and Constructors,,, dmd, GNU dmd Manual}). The @code{provision}
2384 field specifies the name under which this service is known to dmd, and
2385 @code{documentation} specifies on-line documentation. Thus, the
2386 commands @command{deco start ncsd}, @command{deco stop nscd}, and
2387 @command{deco doc nscd} will do what you would expect (@pxref{Invoking
2388 deco,,, dmd, GNU dmd Manual}).
2389
2390
2391 @c *********************************************************************
2392 @node Contributing
2393 @chapter Contributing
2394
2395 This project is a cooperative effort, and we need your help to make it
2396 grow! Please get in touch with us on @email{guix-devel@@gnu.org}. We
2397 welcome ideas, bug reports, patches, and anything that may be helpful to
2398 the project. We particularly welcome help on packaging
2399 (@pxref{Packaging Guidelines}).
2400
2401 Please see the
2402 @url{http://git.savannah.gnu.org/cgit/guix.git/tree/HACKING,
2403 @file{HACKING} file} that comes with the Guix source code for practical
2404 details about contributions.
2405
2406
2407 @c *********************************************************************
2408 @node Acknowledgments
2409 @chapter Acknowledgments
2410
2411 Guix is based on the Nix package manager, which was designed and
2412 implemented by Eelco Dolstra. Nix pioneered functional package
2413 management, and promoted unprecedented features, such as transactional
2414 package upgrades and rollbacks, per-user profiles, and referentially
2415 transparent build processes. Without this work, Guix would not exist.
2416
2417 The Nix-based software distributions, Nixpkgs and NixOS, have also been
2418 an inspiration for Guix.
2419
2420 @c *********************************************************************
2421 @node GNU Free Documentation License
2422 @appendix GNU Free Documentation License
2423
2424 @include fdl-1.3.texi
2425
2426 @c *********************************************************************
2427 @node Concept Index
2428 @unnumbered Concept Index
2429 @printindex cp
2430
2431 @node Function Index
2432 @unnumbered Function Index
2433 @printindex fn
2434
2435 @bye
2436
2437 @c Local Variables:
2438 @c ispell-local-dictionary: "american";
2439 @c End: