Merge branch 'core-updates'
[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 @set YEARS 2012, 2013
12
13 @dircategory Package management
14 @direntry
15 * guix: (guix). Guix, the functional package manager.
16 * guix package: (guix)Invoking guix package
17 Managing packages with Guix.
18 * guix build: (guix)Invoking guix build
19 Building packages with Guix.
20 @end direntry
21
22 @titlepage
23 @title GNU Guix Reference Manual
24 @subtitle Using the GNU Guix Functional Package Manager
25 @author Ludovic Courtès
26 @author Nikita Karetnikov
27
28 @page
29 @vskip 0pt plus 1filll
30 Edition @value{EDITION} @*
31 @value{UPDATED} @*
32
33 Copyright @copyright{} @value{YEARS} Ludovic Court@`es
34
35 @quotation
36 Permission is granted to copy, distribute and/or modify this document
37 under the terms of the GNU Free Documentation License, Version 1.3 or
38 any later version published by the Free Software Foundation; with no
39 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
40 copy of the license is included in the section entitled ``GNU Free
41 Documentation License''.
42 @end quotation
43 @end titlepage
44
45 @copying
46 This manual documents GNU Guix version @value{VERSION}.
47
48 Copyright @copyright{} @value{YEARS} Ludovic Courtès
49
50 Permission is granted to copy, distribute and/or modify this document
51 under the terms of the GNU Free Documentation License, Version 1.3 or
52 any later version published by the Free Software Foundation; with no
53 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
54 copy of the license is included in the section entitled ``GNU Free
55 Documentation License.''
56 @end copying
57
58 @contents
59
60 @c *********************************************************************
61 @node Top
62 @top GNU Guix
63
64 This document describes GNU Guix version @value{VERSION}, a functional
65 package management tool written for the GNU system.
66
67 @quotation
68 Copyright @copyright{} @value{YEARS} Ludovic Courtès
69
70 Permission is granted to copy, distribute and/or modify this document
71 under the terms of the GNU Free Documentation License, Version 1.3 or
72 any later version published by the Free Software Foundation; with no
73 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
74 copy of the license is included in the section entitled ``GNU Free
75 Documentation License.''
76 @end quotation
77
78 @menu
79 * Introduction:: What is Guix about?
80 * Installation:: Installing Guix.
81 * Package Management:: Package installation, upgrade, etc.
82 * Programming Interface:: Using Guix in Scheme.
83 * Utilities:: Package management commands.
84 * GNU Distribution:: Software for your friendly GNU system.
85 * Contributing:: Your help needed!
86
87 * Acknowledgments:: Thanks!
88 * GNU Free Documentation License:: The license of this manual.
89 * Concept Index:: Concepts.
90 * Function Index:: Functions.
91 @end menu
92
93 @c *********************************************************************
94 @node Introduction
95 @chapter Introduction
96
97 GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
98 using the international phonetic alphabet (IPA).} is a functional
99 package management tool for the GNU system. Package management consists
100 of all activities that relate to building packages from sources,
101 honoring their build-time and run-time dependencies,
102 installing packages in user environments, upgrading installed packages
103 to new versions or rolling back to a previous set, removing unused
104 software packages, etc.
105
106 @cindex functional package management
107 The term @dfn{functional} refers to a specific package management
108 discipline. In Guix, the package build and installation process is seen
109 as a function, in the mathematical sense. That function takes inputs,
110 such as build scripts, a compiler, and libraries, and
111 returns an installed package. As a pure function, its result depends
112 solely on its inputs---for instance, it cannot refer to software or
113 scripts that were not explicitly passed as inputs. A build function
114 always produces the same result when passed a given set of inputs. It
115 cannot alter the system's environment in
116 any way; for instance, it cannot create, modify, or delete files outside
117 of its build and installation directories. This is achieved by running
118 build processes in isolated environments (or @dfn{chroots}), where only their
119 explicit inputs are visible.
120
121 @cindex store
122 The result of package build functions is @dfn{cached} in the file
123 system, in a special directory called @dfn{the store} (@pxref{The
124 Store}). Each package is installed in a directory of its own, in the
125 store---by default under @file{/nix/store}. The directory name contains
126 a hash of all the inputs used to build that package; thus, changing an
127 input yields a different directory name.
128
129 This approach is the foundation of Guix's salient features: support for
130 transactional package upgrade and rollback, per-user installation, and
131 garbage collection of packages (@pxref{Features}).
132
133 Guix has a command-line interface, which allows users to build, install,
134 upgrade, and remove packages, as well as a Scheme programming interface.
135
136 Last but not least, Guix is used to build a distribution of the GNU
137 system, with many GNU and non-GNU free software packages. @xref{GNU
138 Distribution}.
139
140 @c *********************************************************************
141 @node Installation
142 @chapter Installation
143
144 GNU Guix is available for download from its website at
145 @url{http://www.gnu.org/software/guix/}. This section describes the
146 software requirements of Guix, as well as how to install it and get
147 ready to use it.
148
149 The build procedure for Guix is the same as for other GNU software, and
150 is not covered here. Please see the files @file{README} and
151 @file{INSTALL} in the Guix source tree for additional details.
152
153 @menu
154 * Requirements:: Software needed to build and run Guix.
155 * Setting Up the Daemon:: Preparing the build daemon's environment.
156 * Invoking guix-daemon:: Running the build daemon.
157 @end menu
158
159 @node Requirements
160 @section Requirements
161
162 GNU Guix depends on the following packages:
163
164 @itemize
165 @item @url{http://gnu.org/software/guile/, GNU Guile 2.0.x};
166 @item @url{http://gnupg.org/, GNU libgcrypt}
167 @end itemize
168
169 Unless @code{--disable-daemon} was passed to @command{configure}, the
170 following packages are also needed:
171
172 @itemize
173 @item @url{http://sqlite.org, SQLite 3}
174 @item @url{http://www.bzip.org, libbz2}
175 @item @url{http://gcc.gnu.org, GCC's g++}
176 @end itemize
177
178 When a working installation of @url{http://nixos.org/nix/, the Nix package
179 manager} is available, you
180 can instead configure Guix with @code{--disable-daemon}. In that case,
181 Nix replaces the three dependencies above.
182
183 Guix is compatible with Nix, so it is possible to share the same store
184 between both. To do so, you must pass @command{configure} not only the
185 same @code{--with-store-dir} value, but also the same
186 @code{--localstatedir} value. The latter is essential because it
187 specifies where the database that stores metadata about the store is
188 located, among other things. The default values are
189 @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
190 Note that @code{--disable-daemon} is not required if
191 your goal is to share the store with Nix.
192
193 @node Setting Up the Daemon
194 @section Setting Up the Daemon
195
196 @cindex daemon
197 Operations such as building a package or running the garbage collector
198 are all performed by a specialized process, the @dfn{Guix daemon}, on
199 behalf of clients. Only the daemon may access the store and its
200 associated database. Thus, any operation that manipulates the store
201 goes through the daemon. For instance, command-line tools such as
202 @command{guix package} and @command{guix build} communicate with the
203 daemon (@i{via} remote procedure calls) to instruct it what to do.
204
205 In a standard multi-user setup, Guix and its daemon---the
206 @command{guix-daemon} program---are installed by the system
207 administrator; @file{/nix/store} is owned by @code{root} and
208 @command{guix-daemon} runs as @code{root}. Unprivileged users may use
209 Guix tools to build packages or otherwise access the store, and the
210 daemon will do it on their behalf, ensuring that the store is kept in a
211 consistent state, and allowing built packages to be shared among users.
212
213 @cindex build users
214 When @command{guix-daemon} runs as @code{root}, you may not want package
215 build processes themselves to run as @code{root} too, for obvious
216 security reasons. To avoid that, a special pool of @dfn{build users}
217 should be created for use by build processes started by the daemon.
218 These build users need not have a shell and a home directory: they will
219 just be used when the daemon drops @code{root} privileges in build
220 processes. Having several such users allows the daemon to launch
221 distinct build processes under separate UIDs, which guarantees that they
222 do not interfere with each other---an essential feature since builds are
223 regarded as pure functions (@pxref{Introduction}).
224
225 On a GNU/Linux system, a build user pool may be created like this (using
226 Bash syntax and the @code{shadow} commands):
227
228 @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
229 @c for why `-G' is needed.
230 @example
231 # groupadd guix-builder
232 # for i in `seq 1 10`;
233 do
234 useradd -g guix-builder -G guix-builder \
235 -d /var/empty -s `which nologin` \
236 -c "Guix build user $i" guix-builder$i;
237 done
238 @end example
239
240 @noindent
241 The @code{guix-daemon} program may then be run as @code{root} with:
242
243 @example
244 # guix-daemon --build-users-group=guix-builder
245 @end example
246
247 Guix may also be used in a single-user setup, with @command{guix-daemon}
248 running as an unprivileged user. However, to maximize non-interference
249 of build processes, the daemon still needs to perform certain operations
250 that are restricted to @code{root} on GNU/Linux: it should be able to
251 run build processes in a chroot, and to run them under different UIDs.
252 To that end, the @command{nix-setuid-helper} program is provided; it is
253 a small C program (less than 300 lines) that, if it is made setuid
254 @code{root}, can be executed by the daemon to perform these operations
255 on its behalf. The @code{root}-owned @file{/etc/nix-setuid.conf} file
256 is read by @command{nix-setuid-helper}; it should contain exactly two
257 words: the user name under which the authorized @command{guix-daemon}
258 runs, and the name of the build users group.
259
260 If you are installing Guix as an unprivileged user and do not have the
261 ability to make @file{nix-setuid-helper} setuid-@code{root}, it is still
262 possible to run @command{guix-daemon}. However, build processes will
263 not be isolated from one another, and not from the rest of the system.
264 Thus, build processes may interfere with each other, and may access
265 programs, libraries, and other files available on the system---making it
266 much harder to view them as @emph{pure} functions.
267
268 @node Invoking guix-daemon
269 @section Invoking @command{guix-daemon}
270
271 The @command{guix-daemon} program implements all the functionality to
272 access the store. This includes launching build processes, running the
273 garbage collector, querying the availability of a build result, etc. It
274 is normally run as @code{root} like this:
275
276 @example
277 # guix-daemon --build-users-group=guix-builder
278 @end example
279
280 @noindent
281 For details on how to set it up, @ref{Setting Up the Daemon}.
282
283 By default, @command{guix-daemon} launches build processes under
284 different UIDs, taken from the build group specified with
285 @code{--build-users-group}. In addition, each build process is run in a
286 chroot environment that only contains the subset of the store that the
287 build process depends on, as specified by its derivation
288 (@pxref{Programming Interface, derivation}), plus a set of specific
289 system directories. By default, the latter contains @file{/dev} and
290 @file{/dev/pts}.
291
292 The following command-line options are supported:
293
294 @table @code
295 @item --build-users-group=@var{group}
296 Take users from @var{group} to run build processes (@pxref{Setting Up
297 the Daemon, build users}).
298
299 @item --no-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 @item --cache-failures
304 Cache build failures. By default, only successful builds are cached.
305
306 @item --cores=@var{n}
307 @itemx -c @var{n}
308 Use @var{n} CPU cores to build each derivation; @code{0} means as many
309 as available.
310
311 The default value is @code{1}, but it may be overridden by clients, such
312 as the @code{--cores} option of @command{guix build} (@pxref{Invoking
313 guix build}).
314
315 The effect is to define the @code{NIX_BUILD_CORES} environment variable
316 in the build process, which can then use it to exploit internal
317 parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
318
319 @item --max-jobs=@var{n}
320 @itemx -M @var{n}
321 Allow at most @var{n} build jobs in parallel. The default value is
322 @code{1}.
323
324 @item --debug
325 Produce debugging output.
326
327 This is useful to debug daemon start-up issues, but then it may be
328 overridden by clients, for example the @code{--verbosity} option of
329 @command{guix build} (@pxref{Invoking guix build}).
330
331 @item --chroot-directory=@var{dir}
332 Add @var{dir} to the build chroot.
333
334 Doing this may change the result of build processes---for instance if
335 they use optional dependencies found in @var{dir} when it is available,
336 and not otherwise. For that reason, it is not recommended to do so.
337 Instead, make sure that each derivation declares all the inputs that it
338 needs.
339
340 @item --disable-chroot
341 Disable chroot builds.
342
343 Using this option is not recommended since, again, it would allow build
344 processes to gain access to undeclared dependencies.
345
346 @item --disable-log-compression
347 Disable compression of the build logs.
348
349 Unless @code{--lose-logs} is used, all the build logs are kept in the
350 @var{localstatedir}. To save space, the daemon automatically compresses
351 them with bzip2 by default. This option disables that.
352
353 @item --disable-store-optimization
354 Disable automatic file ``deduplication'' in the store.
355
356 By default, files added to the store are automatically ``deduplicated'':
357 if a newly added file is identical as another one found in the store,
358 the daemon makes the new file a hard link to the other file. This
359 slightly increases the input/output load at the end of a build process.
360 This option disables this.
361
362 @item --impersonate-linux-2.6
363 On Linux-based systems, impersonate Linux 2.6. This means that the
364 kernel's @code{uname} system call will report 2.6 as the release number.
365
366 This might be helpful to build programs that (usually wrongfully) depend
367 on the kernel version number.
368
369 @item --lose-logs
370 Do not keep build logs. By default they are kept under
371 @code{@var{localstatedir}/nix/log}.
372
373 @item --system=@var{system}
374 Assume @var{system} as the current system type. By default it is the
375 architecture/kernel pair found at configure time, such as
376 @code{x86_64-linux}.
377
378 @item --listen=@var{socket}
379 Listen for connections on @var{socket}, the file name of a Unix-domain
380 socket. The default socket is
381 @file{@var{localstatedir}/daemon-socket/socket}. This option is only
382 useful in exceptional circumstances, such as if you need to run several
383 daemons on the same machine.
384 @end table
385
386
387 @c *********************************************************************
388 @node Package Management
389 @chapter Package Management
390
391 The purpose of GNU Guix is to allow users to easily install, upgrade, and
392 remove software packages, without having to know about their build
393 procedure or dependencies. Guix also goes beyond this obvious set of
394 features.
395
396 This chapter describes the main features of Guix, as well as the package
397 management tools it provides.
398
399 @menu
400 * Features:: How Guix will make your life brighter.
401 * Invoking guix package:: Package installation, removal, etc.
402 * Packages with Multiple Outputs:: Single source package, multiple outputs.
403 * Invoking guix gc:: Running the garbage collector.
404 * Invoking guix pull:: Fetching the latest Guix and distribution.
405 @end menu
406
407 @node Features
408 @section Features
409
410 When using Guix, each package ends up in the @dfn{package store}, in its
411 own directory---something that resembles
412 @file{/nix/store/xxx-package-1.2}, where @code{xxx} is a base32 string.
413
414 Instead of referring to these directories, users have their own
415 @dfn{profile}, which points to the packages that they actually want to
416 use. These profiles are stored within each user's home directory, at
417 @code{$HOME/.guix-profile}.
418
419 For example, @code{alice} installs GCC 4.7.2. As a result,
420 @file{/home/alice/.guix-profile/bin/gcc} points to
421 @file{/nix/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
422 @code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
423 simply continues to point to
424 @file{/nix/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
425 coexist on the same system without any interference.
426
427 The @command{guix package} command is the central tool to manage
428 packages (@pxref{Invoking guix package}). It operates on those per-user
429 profiles, and can be used @emph{with normal user privileges}.
430
431 The command provides the obvious install, remove, and upgrade
432 operations. Each invocation is actually a @emph{transaction}: either
433 the specified operation succeeds, or nothing happens. Thus, if the
434 @command{guix package} process is terminated during the transaction,
435 or if a power outage occurs during the transaction, then the user's
436 profile remains in its previous state, and remains usable.
437
438 In addition, any package transaction may be @emph{rolled back}. So, if,
439 for example, an upgrade installs a new version of a package that turns
440 out to have a serious bug, users may roll back to the previous instance
441 of their profile, which was known to work well.
442
443 All those packages in the package store may be @emph{garbage-collected}.
444 Guix can determine which packages are still referenced by the user
445 profiles, and remove those that are provably no longer referenced
446 (@pxref{Invoking guix gc}). Users may also explicitly remove old
447 generations of their profile so that the packages they refer to can be
448 collected.
449
450 Finally, Guix takes a @dfn{purely functional} approach to package
451 management, as described in the introduction (@pxref{Introduction}).
452 Each @file{/nix/store} package directory name contains a hash of all the
453 inputs that were used to build that package---compiler, libraries, build
454 scripts, etc. This direct correspondence allows users to make sure a
455 given package installation matches the current state of their
456 distribution, and helps maximize @dfn{reproducibility}.
457
458 This foundation allows Guix to support @dfn{transparent binary/source
459 deployment}. When a pre-built binary for a @file{/nix/store} path is
460 available from an external source, Guix just downloads it; otherwise, it
461 builds the package from source, locally.
462
463 @node Invoking guix package
464 @section Invoking @command{guix package}
465
466 The @command{guix package} command is the tool that allows users to
467 install, upgrade, and remove packages, as well as rolling back to
468 previous configurations. It operates only on the user's own profile,
469 and works with normal user privileges (@pxref{Features}). Its syntax
470 is:
471
472 @example
473 guix package @var{options}
474 @end example
475
476 Primarily, @var{options} specifies the operations to be performed during
477 the transaction. Upon completion, a new profile is created, but
478 previous generations of the profile remain available, should the user
479 want to roll back.
480
481 For each user, a symlink to the user's default profile is automatically
482 created in @file{$HOME/.guix-profile}. This symlink always points to the
483 current generation of the user's default profile. Thus, users can add
484 @file{$HOME/.guix-profile/bin} to their @code{PATH} environment
485 variable, and so on.
486
487 In a multi-user setup, user profiles must be stored in a place
488 registered as a @dfn{garbage-collector root}, which
489 @file{$HOME/.guix-profile} points to (@pxref{Invoking guix gc}). That
490 directory is normally
491 @code{@var{localstatedir}/profiles/per-user/@var{user}}, where
492 @var{localstatedir} is the value passed to @code{configure} as
493 @code{--localstatedir}, and @var{user} is the user name. It must be
494 created by @code{root}, with @var{user} as the owner. When it does not
495 exist, or is not owned by @var{user}, @command{guix package} emits an
496 error about it.
497
498 The @var{options} can be among the following:
499
500 @table @code
501
502 @item --install=@var{package}
503 @itemx -i @var{package}
504 Install @var{package}.
505
506 @var{package} may specify either a simple package name, such as
507 @code{guile}, or a package name followed by a hyphen and version number,
508 such as @code{guile-1.8.8}. If no version number is specified, the
509 newest available version will be selected. In addition, @var{package}
510 may contain a colon, followed by the name of one of the outputs of the
511 package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
512 (@pxref{Packages with Multiple Outputs}).
513
514 @cindex propagated inputs
515 Sometimes packages have @dfn{propagated inputs}: these are dependencies
516 that automatically get installed along with the required package.
517
518 An example is the GNU MPC library: its C header files refer to those of
519 the GNU MPFR library, which in turn refer to those of the GMP library.
520 Thus, when installing MPC, the MPFR and GMP libraries also get installed
521 in the profile; removing MPC also removes MPFR and GMP---unless they had
522 also been explicitly installed independently.
523
524 Besides, packages sometime rely on the definition of environment
525 variables for their search paths (see explanation of
526 @code{--search-paths} below.) Any missing or possibly incorrect
527 environment variable definitions are reported here.
528
529 @c XXX: keep me up-to-date
530 Finally, when installing a GNU package, the tool reports the
531 availability of a newer upstream version. In the future, it may provide
532 the option of installing directly from the upstream version, even if
533 that version is not yet in the distribution.
534
535 @item --install-from-expression=@var{exp}
536 @itemx -e @var{exp}
537 Install the package @var{exp} evaluates to.
538
539 @var{exp} must be a Scheme expression that evaluates to a
540 @code{<package>} object. This option is notably useful to disambiguate
541 between same-named variants of a package, with expressions such as
542 @code{(@@ (gnu packages base) guile-final)}.
543
544 Note that this option installs the first output of the specified
545 package, which may be insufficient when needing a specific output of a
546 multiple-output package.
547
548 @item --remove=@var{package}
549 @itemx -r @var{package}
550 Remove @var{package}.
551
552 @item --upgrade[=@var{regexp}]
553 @itemx -u [@var{regexp}]
554 Upgrade all the installed packages. When @var{regexp} is specified, upgrade
555 only installed packages whose name matches @var{regexp}.
556
557 Note that this upgrades package to the latest version of packages found
558 in the distribution currently installed. To update your distribution,
559 you should regularly run @command{guix pull} (@pxref{Invoking guix
560 pull}).
561
562 @item --roll-back
563 Roll back to the previous @dfn{generation} of the profile---i.e., undo
564 the last transaction.
565
566 When combined with options such as @code{--install}, roll back occurs
567 before any other actions.
568
569 When rolling back from the first generation that actually contains
570 installed packages, the profile is made to point to the @dfn{empty
571 profile}, also known as @dfn{profile zero}---i.e., it contains no files
572 apart from its own meta-data.
573
574 Installing, removing, or upgrading packages from a generation that has
575 been rolled back to overwrites previous future generations. Thus, the
576 history of a profile's generations is always linear.
577
578 @item --search-paths
579 @cindex search paths
580 Report environment variable definitions, in Bash syntax, that may be
581 needed in order to use the set of installed packages. These environment
582 variables are used to specify @dfn{search paths} for files used by some
583 of the installed packages.
584
585 For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
586 environment variables to be defined so it can look for headers and
587 libraries in the user's profile (@pxref{Environment Variables,,, gcc,
588 Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
589 library are installed in the profile, then @code{--search-paths} will
590 suggest setting these variables to @code{@var{profile}/include} and
591 @code{@var{profile}/lib}, respectively.
592
593 @item --profile=@var{profile}
594 @itemx -p @var{profile}
595 Use @var{profile} instead of the user's default profile.
596
597 @item --dry-run
598 @itemx -n
599 Show what would be done without actually doing it.
600
601 @item --fallback
602 When substituting a pre-built binary fails, fall back to building
603 packages locally.
604
605 @item --no-substitutes
606 @itemx --max-silent-time=@var{seconds}
607 Same as for @command{guix build} (@pxref{Invoking guix build}).
608
609 @item --verbose
610 Produce verbose output. In particular, emit the environment's build log
611 on the standard error port.
612
613 @item --bootstrap
614 Use the bootstrap Guile to build the profile. This option is only
615 useful to distribution developers.
616
617 @end table
618
619 In addition to these actions @command{guix package} supports the
620 following options to query the current state of a profile, or the
621 availability of packages:
622
623 @table @option
624
625 @item --search=@var{regexp}
626 @itemx -s @var{regexp}
627 List the available packages whose synopsis or description matches
628 @var{regexp}. Print all the meta-data of matching packages in
629 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
630 GNU recutils manual}).
631
632 This allows specific fields to be extracted using the @command{recsel}
633 command, for instance:
634
635 @example
636 $ guix package -s malloc | recsel -p name,version
637 name: glibc
638 version: 2.17
639
640 name: libgc
641 version: 7.2alpha6
642 @end example
643
644 @item --list-installed[=@var{regexp}]
645 @itemx -I [@var{regexp}]
646 List currently installed packages in the specified profile. When
647 @var{regexp} is specified, list only installed packages whose name
648 matches @var{regexp}.
649
650 For each installed package, print the following items, separated by
651 tabs: the package name, its version string, the part of the package that
652 is installed (for instance, @code{out} for the default output,
653 @code{include} for its headers, etc.), and the path of this package in
654 the store.
655
656 @item --list-available[=@var{regexp}]
657 @itemx -A [@var{regexp}]
658 List packages currently available in the software distribution
659 (@pxref{GNU Distribution}). When @var{regexp} is specified, list only
660 installed packages whose name matches @var{regexp}.
661
662 For each package, print the following items separated by tabs: its name,
663 its version string, the parts of the package (@pxref{Packages with
664 Multiple Outputs}), and the source location of its definition.
665
666 @end table
667
668 @node Packages with Multiple Outputs
669 @section Packages with Multiple Outputs
670
671 @cindex multiple-output packages
672 @cindex package outputs
673
674 Often, packages defined in Guix have a single @dfn{output}---i.e., the
675 source package leads exactly one directory in the store. When running
676 @command{guix package -i glibc}, one installs the default output of the
677 GNU libc package; the default output is called @code{out}, but its name
678 can be omitted as shown in this command. In this particular case, the
679 default output of @code{glibc} contains all the C header files, shared
680 libraries, static libraries, Info documentation, and other supporting
681 files.
682
683 Sometimes it is more appropriate to separate the various types of files
684 produced from a single source package into separate outputs. For
685 instance, the GLib C library (used by GTK+ and related packages)
686 installs more than 20 MiB of reference documentation as HTML pages.
687 To save space for users who do not need it, the documentation goes to a
688 separate output, called @code{doc}. To install the main GLib output,
689 which contains everything but the documentation, one would run:
690
691 @example
692 guix package -i glib
693 @end example
694
695 The command to install its documentation is:
696
697 @example
698 guix package -i glib:doc
699 @end example
700
701 Some packages install programs with different ``dependency footprints''.
702 For instance, the WordNet package install both command-line tools and
703 graphical user interfaces (GUIs). The former depend solely on the C
704 library, whereas the latter depend on Tcl/Tk and the underlying X
705 libraries. In this case, we leave the command-line tools in the default
706 output, whereas the GUIs are in a separate output. This allows users
707 who do not need the GUIs to save space.
708
709 There are several such multiple-output packages in the GNU distribution.
710 Other conventional output names include @code{lib} for libraries and
711 possibly header files, @code{bin} for stand-alone programs, and
712 @code{debug} for debugging information (@pxref{Installing Debugging
713 Files}). The outputs of a packages are listed in the third column of
714 the output of @command{guix package --list-available} (@pxref{Invoking
715 guix package}).
716
717
718 @node Invoking guix gc
719 @section Invoking @command{guix gc}
720
721 @cindex garbage collector
722 Packages that are installed but not used may be @dfn{garbage-collected}.
723 The @command{guix gc} command allows users to explicitly run the garbage
724 collector to reclaim space from the @file{/nix/store} directory.
725
726 The garbage collector has a set of known @dfn{roots}: any file under
727 @file{/nix/store} reachable from a root is considered @dfn{live} and
728 cannot be deleted; any other file is considered @dfn{dead} and may be
729 deleted. The set of garbage collector roots includes default user
730 profiles, and may be augmented with @command{guix build --root}, for
731 example (@pxref{Invoking guix build}).
732
733 The @command{guix gc} command has three modes of operation: it can be
734 used to garbage-collect any dead files (the default), to delete specific
735 files (the @code{--delete} option), or to print garbage-collector
736 information. The available options are listed below:
737
738 @table @code
739 @item --collect-garbage[=@var{min}]
740 @itemx -C [@var{min}]
741 Collect garbage---i.e., unreachable @file{/nix/store} files and
742 sub-directories. This is the default operation when no option is
743 specified.
744
745 When @var{min} is given, stop once @var{min} bytes have been collected.
746 @var{min} may be a number of bytes, or it may include a unit as a
747 suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes.
748
749 When @var{min} is omitted, collect all the garbage.
750
751 @item --delete
752 @itemx -d
753 Attempt to delete all the store files and directories specified as
754 arguments. This fails if some of the files are not in the store, or if
755 they are still live.
756
757 @item --list-dead
758 Show the list of dead files and directories still present in the
759 store---i.e., files and directories no longer reachable from any root.
760
761 @item --list-live
762 Show the list of live store files and directories.
763
764 @end table
765
766 In addition, the references among existing store files can be queried:
767
768 @table @code
769
770 @item --references
771 @itemx --referrers
772 List the references (respectively, the referrers) of store files given
773 as arguments.
774
775 @item --requisites
776 @itemx -R
777 List the requisites of the store files passed as arguments. Requisites
778 include the store files themselves, their references, and the references
779 of these, recursively. In other words, the returned list is the
780 @dfn{transitive closure} of the store files.
781
782 @end table
783
784
785 @node Invoking guix pull
786 @section Invoking @command{guix pull}
787
788 Packages are installed or upgraded to the latest version available in
789 the distribution currently available on your local machine. To update
790 that distribution, along with the Guix tools, you must run @command{guix
791 pull}: the command downloads the latest Guix source code and package
792 descriptions, and deploys it.
793
794 On completion, @command{guix package} will use packages and package
795 versions from this just-retrieved copy of Guix. Not only that, but all
796 the Guix commands and Scheme modules will also be taken from that latest
797 version. New @command{guix} sub-commands added by the update also
798 become available.
799
800 The @command{guix pull} command is usually invoked with no arguments,
801 but it supports the following options:
802
803 @table @code
804 @item --verbose
805 Produce verbose output, writing build logs to the standard error output.
806
807 @item --bootstrap
808 Use the bootstrap Guile to build the latest Guix. This option is only
809 useful to Guix developers.
810 @end table
811
812 @c *********************************************************************
813 @node Programming Interface
814 @chapter Programming Interface
815
816 GNU Guix provides several Scheme programming interfaces (APIs) to
817 define, build, and query packages. The first interface allows users to
818 write high-level package definitions. These definitions refer to
819 familiar packaging concepts, such as the name and version of a package,
820 its build system, and its dependencies. These definitions can then be
821 turned into concrete build actions.
822
823 Build actions are performed by the Guix daemon, on behalf of users. In a
824 standard setup, the daemon has write access to the store---the
825 @file{/nix/store} directory---whereas users do not. The recommended
826 setup also has the daemon perform builds in chroots, under a specific
827 build users, to minimize interference with the rest of the system.
828
829 @cindex derivation
830 Lower-level APIs are available to interact with the daemon and the
831 store. To instruct the daemon to perform a build action, users actually
832 provide it with a @dfn{derivation}. A derivation is a low-level
833 representation of the build actions to be taken, and the environment in
834 which they should occur---derivations are to package definitions what
835 assembly is to C programs.
836
837 This chapter describes all these APIs in turn, starting from high-level
838 package definitions.
839
840 @menu
841 * Defining Packages:: Defining new packages.
842 * The Store:: Manipulating the package store.
843 * Derivations:: Low-level interface to package derivations.
844 @end menu
845
846 @node Defining Packages
847 @section Defining Packages
848
849 The high-level interface to package definitions is implemented in the
850 @code{(guix packages)} and @code{(guix build-system)} modules. As an
851 example, the package definition, or @dfn{recipe}, for the GNU Hello
852 package looks like this:
853
854 @example
855 (use-modules (guix packages)
856 (guix download)
857 (guix build-system gnu)
858 (guix licenses))
859
860 (define hello
861 (package
862 (name "hello")
863 (version "2.8")
864 (source (origin
865 (method url-fetch)
866 (uri (string-append "mirror://gnu/hello/hello-" version
867 ".tar.gz"))
868 (sha256
869 (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
870 (build-system gnu-build-system)
871 (inputs `(("gawk" ,gawk)))
872 (synopsis "GNU Hello")
873 (description "Yeah...")
874 (home-page "http://www.gnu.org/software/hello/")
875 (license gpl3+)))
876 @end example
877
878 @noindent
879 Without being a Scheme expert, the reader may have guessed the meaning
880 of the various fields here. This expression binds variable @var{hello}
881 to a @code{<package>} object, which is essentially a record
882 (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
883 This package object can be inspected using procedures found in the
884 @code{(guix packages)} module; for instance, @code{(package-name hello)}
885 returns---surprise!---@code{"hello"}.
886
887 There are a few points worth noting in the above package definition:
888
889 @itemize
890 @item
891 The @code{source} field of the package is an @code{<origin>} object.
892 Here, the @code{url-fetch} method from @code{(guix download)} is used,
893 meaning that the source is a file to be downloaded over FTP or HTTP.
894
895 The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
896 the GNU mirrors defined in @code{(guix download)}.
897
898 The @code{sha256} field specifies the expected SHA256 hash of the file
899 being downloaded. It is mandatory, and allows Guix to check the
900 integrity of the file. The @code{(base32 @dots{})} form introduces the
901 base32 representation of the hash. You can obtain this information with
902 @code{guix download} (@pxref{Invoking guix download}) and @code{guix
903 hash} (@pxref{Invoking guix hash}).
904
905 @item
906 @cindex GNU Build System
907 The @code{build-system} field is set to @var{gnu-build-system}. The
908 @var{gnu-build-system} variable is defined in the @code{(guix
909 build-system gnu)} module, and is bound to a @code{<build-system>}
910 object.
911
912 Naturally, @var{gnu-build-system} represents the familiar GNU Build
913 System, and variants thereof (@pxref{Configuration, configuration and
914 makefile conventions,, standards, GNU Coding Standards}). In a
915 nutshell, packages using the GNU Build System may be configured, built,
916 and installed with the usual @code{./configure && make && make check &&
917 make install} command sequence. This is what @var{gnu-build-system}
918 does.
919
920 In addition, @var{gnu-build-system} ensures that the ``standard''
921 environment for GNU packages is available. This includes tools such as
922 GCC, Coreutils, Bash, Make, Diffutils, and Patch.
923
924 @item
925 The @code{inputs} field specifies inputs to the build process---i.e.,
926 build-time or run-time dependencies of the package. Here, we define an
927 input called @code{"gawk"} whose value is that of the @var{gawk}
928 variable; @var{gawk} is itself bound to a @code{<package>} object.
929
930 Note that GCC, Coreutils, Bash, and other essential tools do not need to
931 be specified as inputs here. Instead, @var{gnu-build-system} takes care
932 of ensuring that they are present.
933
934 However, any other dependencies need to be specified in the
935 @code{inputs} field. Any dependency not specified here will simply be
936 unavailable to the build process, possibly leading to a build failure.
937 @end itemize
938
939 There are other fields that package definitions may provide. Of
940 particular interest is the @code{arguments} field. When specified, it
941 must be bound to a list of additional arguments to be passed to the
942 build system. For instance, the above definition could be augmented
943 with the following field initializer:
944
945 @example
946 (arguments `(#:tests? #f
947 #:configure-flags '("--enable-silent-rules")))
948 @end example
949
950 @noindent
951 These are keyword arguments (@pxref{Optional Arguments, keyword
952 arguments in Guile,, guile, GNU Guile Reference Manual}). They are
953 passed to @var{gnu-build-system}, which interprets them as meaning ``do
954 not run @code{make check}'', and ``run @file{configure} with the
955 @code{--enable-silent-rules} flag''. The value of these keyword
956 parameters is actually evaluated in the @dfn{build stratum}---i.e., by a
957 Guile process launched by the daemon (@pxref{Derivations}).
958
959 Once a package definition is in place@footnote{Simple package
960 definitions like the one above may be automatically converted from the
961 Nixpkgs distribution using the @command{guix import} command.}, the
962 package may actually be built using the @code{guix build} command-line
963 tool (@pxref{Invoking guix build}). Eventually, updating the package
964 definition to a new upstream version can be partly automated by the
965 @command{guix refresh} command (@pxref{Invoking guix refresh}).
966
967 Behind the scenes, a derivation corresponding to the @code{<package>}
968 object is first computed by the @code{package-derivation} procedure.
969 That derivation is stored in a @code{.drv} file under @file{/nix/store}.
970 The build actions it prescribes may then be realized by using the
971 @code{build-derivations} procedure (@pxref{The Store}).
972
973 @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
974 Return the derivation path and corresponding @code{<derivation>} object
975 of @var{package} for @var{system} (@pxref{Derivations}).
976
977 @var{package} must be a valid @code{<package>} object, and @var{system}
978 must be a string denoting the target system type---e.g.,
979 @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
980 must be a connection to the daemon, which operates on the store
981 (@pxref{The Store}).
982 @end deffn
983
984 @noindent
985 @cindex cross-compilation
986 Similarly, it is possible to compute a derivation that cross-builds a
987 package for some other system:
988
989 @deffn {Scheme Procedure} package-cross-derivation @var{store} @
990 @var{package} @var{target} [@var{system}]
991 Return the derivation path and corresponding @code{<derivation>} object
992 of @var{package} cross-built from @var{system} to @var{target}.
993
994 @var{target} must be a valid GNU triplet denoting the target hardware
995 and operating system, such as @code{"mips64el-linux-gnu"}
996 (@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
997 Configure and Build System}).
998 @end deffn
999
1000
1001 @node The Store
1002 @section The Store
1003
1004 @cindex store
1005 @cindex store paths
1006
1007 Conceptually, the @dfn{store} is where derivations that have been
1008 successfully built are stored---by default, under @file{/nix/store}.
1009 Sub-directories in the store are referred to as @dfn{store paths}. The
1010 store has an associated database that contains information such has the
1011 store paths referred to by each store path, and the list of @emph{valid}
1012 store paths---paths that result from a successful build.
1013
1014 The store is always accessed by the daemon on behalf of its clients
1015 (@pxref{Invoking guix-daemon}). To manipulate the store, clients
1016 connect to the daemon over a Unix-domain socket, send it requests, and
1017 read the result---these are remote procedure calls, or RPCs.
1018
1019 The @code{(guix store)} module provides procedures to connect to the
1020 daemon, and to perform RPCs. These are described below.
1021
1022 @deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
1023 Connect to the daemon over the Unix-domain socket at @var{file}. When
1024 @var{reserve-space?} is true, instruct it to reserve a little bit of
1025 extra space on the file system so that the garbage collector can still
1026 operate, should the disk become full. Return a server object.
1027
1028 @var{file} defaults to @var{%default-socket-path}, which is the normal
1029 location given the options that were passed to @command{configure}.
1030 @end deffn
1031
1032 @deffn {Scheme Procedure} close-connection @var{server}
1033 Close the connection to @var{server}.
1034 @end deffn
1035
1036 @defvr {Scheme Variable} current-build-output-port
1037 This variable is bound to a SRFI-39 parameter, which refers to the port
1038 where build and error logs sent by the daemon should be written.
1039 @end defvr
1040
1041 Procedures that make RPCs all take a server object as their first
1042 argument.
1043
1044 @deffn {Scheme Procedure} valid-path? @var{server} @var{path}
1045 Return @code{#t} when @var{path} is a valid store path.
1046 @end deffn
1047
1048 @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} @var{references}
1049 Add @var{text} under file @var{name} in the store, and return its store
1050 path. @var{references} is the list of store paths referred to by the
1051 resulting store path.
1052 @end deffn
1053
1054 @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
1055 Build @var{derivations} (a list of derivation paths), and return when
1056 the worker is done building them. Return @code{#t} on success.
1057 @end deffn
1058
1059 @c FIXME
1060 @i{This section is currently incomplete.}
1061
1062 @node Derivations
1063 @section Derivations
1064
1065 @cindex derivations
1066 Low-level build actions and the environment in which they are performed
1067 are represented by @dfn{derivations}. A derivation contain the
1068 following pieces of information:
1069
1070 @itemize
1071 @item
1072 The outputs of the derivation---derivations produce at least one file or
1073 directory in the store, but may produce more.
1074
1075 @item
1076 The inputs of the derivations, which may be other derivations or plain
1077 files in the store (patches, build scripts, etc.)
1078
1079 @item
1080 The system type targeted by the derivation---e.g., @code{x86_64-linux}.
1081
1082 @item
1083 The file name of a build script in the store, along with the arguments
1084 to be passed.
1085
1086 @item
1087 A list of environment variables to be defined.
1088
1089 @end itemize
1090
1091 @cindex derivation path
1092 Derivations allow clients of the daemon to communicate build actions to
1093 the store. They exist in two forms: as an in-memory representation,
1094 both on the client- and daemon-side, and as files in the store whose
1095 name end in @code{.drv}---these files are referred to as @dfn{derivation
1096 paths}. Derivations paths can be passed to the @code{build-derivations}
1097 procedure to perform the build actions they prescribe (@pxref{The
1098 Store}).
1099
1100 The @code{(guix derivations)} module provides a representation of
1101 derivations as Scheme objects, along with procedures to create and
1102 otherwise manipulate derivations. The lowest-level primitive to create
1103 a derivation is the @code{derivation} procedure:
1104
1105 @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{system} @var{builder} @var{args} @var{env-vars} @var{inputs} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] [#:hash-mode #f]
1106 Build a derivation with the given arguments. Return the resulting store
1107 path and @code{<derivation>} object.
1108
1109 When @var{hash}, @var{hash-algo}, and @var{hash-mode} are given, a
1110 @dfn{fixed-output derivation} is created---i.e., one whose result is
1111 known in advance, such as a file download.
1112 @end deffn
1113
1114 @noindent
1115 Here's an example with a shell script as its builder, assuming
1116 @var{store} is an open connection to the daemon, and @var{bash} points
1117 to a Bash executable in the store:
1118
1119 @lisp
1120 (use-modules (guix utils)
1121 (guix store)
1122 (guix derivations))
1123
1124 (call-with-values
1125 (lambda ()
1126 (let ((builder ; add the Bash script to the store
1127 (add-text-to-store store "my-builder.sh"
1128 "echo hello world > $out\n" '())))
1129 (derivation store "foo" (%current-system)
1130 bash `("-e" ,builder)
1131 '(("HOME" . "/homeless")) '())))
1132 list)
1133 @result{} ("/nix/store/@dots{}-foo.drv" #<<derivation> @dots{}>)
1134 @end lisp
1135
1136 As can be guessed, this primitive is cumbersome to use directly. An
1137 improved variant is @code{build-expression->derivation}, which allows
1138 the caller to directly pass a Guile expression as the build script:
1139
1140 @deffn {Scheme Procedure} build-expression->derivation @var{store} @var{name} @var{system} @var{exp} @var{inputs} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] [#:env-vars '()] [#:modules '()] [#:guile-for-build #f]
1141 Return a derivation that executes Scheme expression @var{exp} as a
1142 builder for derivation @var{name}. @var{inputs} must be a list of
1143 @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
1144 @code{"out"} is assumed. @var{modules} is a list of names of Guile
1145 modules from the current search path to be copied in the store,
1146 compiled, and made available in the load path during the execution of
1147 @var{exp}---e.g., @code{((guix build utils) (guix build
1148 gnu-build-system))}.
1149
1150 @var{exp} is evaluated in an environment where @code{%outputs} is bound
1151 to a list of output/path pairs, and where @code{%build-inputs} is bound
1152 to a list of string/output-path pairs made from @var{inputs}.
1153 Optionally, @var{env-vars} is a list of string pairs specifying the name
1154 and value of environment variables visible to the builder. The builder
1155 terminates by passing the result of @var{exp} to @code{exit}; thus, when
1156 @var{exp} returns @code{#f}, the build is considered to have failed.
1157
1158 @var{exp} is built using @var{guile-for-build} (a derivation). When
1159 @var{guile-for-build} is omitted or is @code{#f}, the value of the
1160 @code{%guile-for-build} fluid is used instead.
1161 @end deffn
1162
1163 @noindent
1164 Here's an example of a single-output derivation that creates a directory
1165 containing one file:
1166
1167 @lisp
1168 (let ((builder '(let ((out (assoc-ref %outputs "out")))
1169 (mkdir out) ; create /nix/store/@dots{}-goo
1170 (call-with-output-file (string-append out "/test")
1171 (lambda (p)
1172 (display '(hello guix) p))))))
1173 (build-expression->derivation store "goo" (%current-system)
1174 builder '()))
1175
1176 @result{} "/nix/store/@dots{}-goo.drv"
1177 @result{} #<<derivation> @dots{}>
1178 @end lisp
1179
1180 @cindex strata of code
1181 Remember that the build expression passed to
1182 @code{build-expression->derivation} is run by a separate Guile process
1183 than the one that calls @code{build-expression->derivation}: it is run
1184 by a Guile process launched by the daemon, typically in a chroot. So,
1185 while there is a single language for both the @dfn{host} and the build
1186 side, there are really two @dfn{strata} of code: the host-side, and the
1187 build-side code@footnote{The term @dfn{stratum} in this context was
1188 coined by Manuel Serrano et al. in the context of their work on Hop.}.
1189 This distinction is important to keep in mind, notably when using
1190 higher-level constructs such as @var{gnu-build-system} (@pxref{Defining
1191 Packages}). For this reason, Guix modules that are meant to be used in
1192 the build stratum are kept in the @code{(guix build @dots{})} name
1193 space.
1194
1195 @c *********************************************************************
1196 @node Utilities
1197 @chapter Utilities
1198
1199 This section describes tools primarily targeted at developers and users
1200 who write new package definitions. They complement the Scheme
1201 programming interface of Guix in a convenient way.
1202
1203 @menu
1204 * Invoking guix build:: Building packages from the command line.
1205 * Invoking guix download:: Downloading a file and printing its hash.
1206 * Invoking guix hash:: Computing the cryptographic hash of a file.
1207 * Invoking guix refresh:: Updating package definitions.
1208 @end menu
1209
1210 @node Invoking guix build
1211 @section Invoking @command{guix build}
1212
1213 The @command{guix build} command builds packages or derivations and
1214 their dependencies, and prints the resulting store paths. Note that it
1215 does not modify the user's profile---this is the job of the
1216 @command{guix package} command (@pxref{Invoking guix package}). Thus,
1217 it is mainly useful for distribution developers.
1218
1219 The general syntax is:
1220
1221 @example
1222 guix build @var{options} @var{package-or-derivation}@dots{}
1223 @end example
1224
1225 @var{package-or-derivation} may be either the name of a package found in
1226 the software distribution such as @code{coreutils} or
1227 @code{coreutils-8.20}, or a derivation such as
1228 @file{/nix/store/@dots{}-coreutils-8.19.drv}. Alternatively, the
1229 @code{--expression} option may be used to specify a Scheme expression
1230 that evaluates to a package; this is useful when disambiguation among
1231 several same-named packages or package variants is needed.
1232
1233 The @var{options} may be zero or more of the following:
1234
1235 @table @code
1236
1237 @item --expression=@var{expr}
1238 @itemx -e @var{expr}
1239 Build the package @var{expr} evaluates to.
1240
1241 For example, @var{expr} may be @code{(@@ (gnu packages guile)
1242 guile-1.8)}, which unambiguously designates this specific variant of
1243 version 1.8 of Guile.
1244
1245 @item --source
1246 @itemx -S
1247 Build the packages' source derivations, rather than the packages
1248 themselves.
1249
1250 For instance, @code{guix build -S gcc} returns something like
1251 @file{/nix/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
1252
1253 @item --system=@var{system}
1254 @itemx -s @var{system}
1255 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
1256 the host's system type.
1257
1258 An example use of this is on Linux-based systems, which can emulate
1259 different personalities. For instance, passing
1260 @code{--system=i686-linux} on an @code{x86_64-linux} system allows users
1261 to build packages in a complete 32-bit environment.
1262
1263 @item --target=@var{triplet}
1264 @cindex cross-compilation
1265 Cross-build for @var{triplet}, which must be a valid GNU triplet, such
1266 as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
1267 configuration triplets,, configure, GNU Configure and Build System}).
1268
1269 @item --derivations
1270 @itemx -d
1271 Return the derivation paths, not the output paths, of the given
1272 packages.
1273
1274 @item --keep-failed
1275 @itemx -K
1276 Keep the build tree of failed builds. Thus, if a build fail, its build
1277 tree is kept under @file{/tmp}, in a directory whose name is shown at
1278 the end of the build log. This is useful when debugging build issues.
1279
1280 @item --dry-run
1281 @itemx -n
1282 Do not build the derivations.
1283
1284 @item --fallback
1285 When substituting a pre-built binary fails, fall back to building
1286 packages locally.
1287
1288 @item --no-substitutes
1289 Build instead of resorting to pre-built substitutes.
1290
1291 @item --max-silent-time=@var{seconds}
1292 When the build or substitution process remains silent for more than
1293 @var{seconds}, terminate it and report a build failure.
1294
1295 @item --cores=@var{n}
1296 @itemx -c @var{n}
1297 Allow the use of up to @var{n} CPU cores for the build. The special
1298 value @code{0} means to use as many CPU cores as available.
1299
1300 @item --root=@var{file}
1301 @itemx -r @var{file}
1302 Make @var{file} a symlink to the result, and register it as a garbage
1303 collector root.
1304
1305 @item --verbosity=@var{level}
1306 Use the given verbosity level. @var{level} must be an integer between 0
1307 and 5; higher means more verbose output. Setting a level of 4 or more
1308 may be helpful when debugging setup issues with the build daemon.
1309
1310 @end table
1311
1312 Behind the scenes, @command{guix build} is essentially an interface to
1313 the @code{package-derivation} procedure of the @code{(guix packages)}
1314 module, and to the @code{build-derivations} procedure of the @code{(guix
1315 store)} module.
1316
1317 @node Invoking guix download
1318 @section Invoking @command{guix download}
1319
1320 When writing a package definition, developers typically need to download
1321 the package's source tarball, compute its SHA256 hash, and write that
1322 hash in the package definition (@pxref{Defining Packages}). The
1323 @command{guix download} tool helps with this task: it downloads a file
1324 from the given URI, adds it to the store, and prints both its file name
1325 in the store and its SHA256 hash.
1326
1327 The fact that the downloaded file is added to the store saves bandwidth:
1328 when the developer eventually tries to build the newly defined package
1329 with @command{guix build}, the source tarball will not have to be
1330 downloaded again because it is already in the store. It is also a
1331 convenient way to temporarily stash files, which may be deleted
1332 eventually (@pxref{Invoking guix gc}).
1333
1334 The @command{guix download} command supports the same URIs as used in
1335 package definitions. In particular, it supports @code{mirror://} URIs.
1336 @code{https} URIs (HTTP over TLS) are supported @emph{provided} the
1337 Guile bindings for GnuTLS are available in the user's environment; when
1338 they are not available, an error is raised.
1339
1340 The following option is available:
1341
1342 @table @code
1343 @item --format=@var{fmt}
1344 @itemx -f @var{fmt}
1345 Write the hash in the format specified by @var{fmt}. For more
1346 information on the valid values for @var{fmt}, @ref{Invoking guix hash}.
1347 @end table
1348
1349 @node Invoking guix hash
1350 @section Invoking @command{guix hash}
1351
1352 The @command{guix hash} command computes the SHA256 hash of a file.
1353 It is primarily a convenience tool for anyone contributing to the
1354 distribution: it computes the cryptographic hash of a file, which can be
1355 used in the definition of a package (@pxref{Defining Packages}).
1356
1357 The general syntax is:
1358
1359 @example
1360 guix hash @var{option} @var{file}
1361 @end example
1362
1363 @command{guix hash} has the following option:
1364
1365 @table @code
1366
1367 @item --format=@var{fmt}
1368 @itemx -f @var{fmt}
1369 Write the hash in the format specified by @var{fmt}.
1370
1371 Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
1372 (@code{hex} and @code{hexadecimal} can be used as well).
1373
1374 If the @option{--format} option is not specified, @command{guix hash}
1375 will output the hash in @code{nix-base32}. This representation is used
1376 in the definitions of packages.
1377
1378 @end table
1379
1380 @node Invoking guix refresh
1381 @section Invoking @command{guix refresh}
1382
1383 The primary audience of the @command{guix refresh} command is developers
1384 of the GNU software distribution. By default, it reports any packages
1385 provided by the distribution that are outdated compared to the latest
1386 upstream version, like this:
1387
1388 @example
1389 $ guix refresh
1390 gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
1391 gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
1392 @end example
1393
1394 It does so by browsing each package's FTP directory and determining the
1395 highest version number of the source tarballs
1396 therein@footnote{Currently, this only works for GNU packages.}.
1397
1398 When passed @code{--update}, it modifies distribution source files to
1399 update the version numbers and source tarball hashes of those packages'
1400 recipes (@pxref{Defining Packages}). This is achieved by downloading
1401 each package's latest source tarball and its associated OpenPGP
1402 signature, authenticating the downloaded tarball against its signature
1403 using @command{gpg}, and finally computing its hash. When the public
1404 key used to sign the tarball is missing from the user's keyring, an
1405 attempt is made to automatically retrieve it from a public key server;
1406 when it's successful, the key is added to the user's keyring; otherwise,
1407 @command{guix refresh} reports an error.
1408
1409 The following options are supported:
1410
1411 @table @code
1412
1413 @item --update
1414 @itemx -u
1415 Update distribution source files (package recipes) in place.
1416 @ref{Defining Packages}, for more information on package definitions.
1417
1418 @item --select=[@var{subset}]
1419 @itemx -s @var{subset}
1420 Select all the packages in @var{subset}, one of @code{core} or
1421 @code{non-core}.
1422
1423 The @code{core} subset refers to all the packages at the core of the
1424 distribution---i.e., packages that are used to build ``everything
1425 else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
1426 changing one of these packages in the distribution entails a rebuild of
1427 all the others. Thus, such updates are an inconvenience to users in
1428 terms of build time or bandwidth used to achieve the upgrade.
1429
1430 The @code{non-core} subset refers to the remaining packages. It is
1431 typically useful in cases where an update of the core packages would be
1432 inconvenient.
1433
1434 @end table
1435
1436 In addition, @command{guix refresh} can be passed one or more package
1437 names, as in this example:
1438
1439 @example
1440 guix refresh -u emacs idutils
1441 @end example
1442
1443 @noindent
1444 The command above specifically updates the @code{emacs} and
1445 @code{idutils} packages. The @code{--select} option would have no
1446 effect in this case.
1447
1448 The following options can be used to customize GnuPG operation:
1449
1450 @table @code
1451
1452 @item --key-server=@var{host}
1453 Use @var{host} as the OpenPGP key server when importing a public key.
1454
1455 @item --gpg=@var{command}
1456 Use @var{command} as the GnuPG 2.x command. @var{command} is searched
1457 for in @code{$PATH}.
1458
1459 @end table
1460
1461
1462 @c *********************************************************************
1463 @node GNU Distribution
1464 @chapter GNU Distribution
1465
1466 Guix comes with a distribution of free software@footnote{The term
1467 ``free'' here refers to the
1468 @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
1469 users of that software}.} that form the basis of the GNU system. This
1470 includes core GNU packages such as GNU libc, GCC, and Binutils, as well
1471 as many GNU and non-GNU applications. The complete list of available
1472 packages can be seen by running @command{guix package} (@pxref{Invoking
1473 guix package}):
1474
1475 @example
1476 guix package --list-available
1477 @end example
1478
1479 Our goal is to build a practical 100% free software distribution of
1480 Linux-based and other variants of GNU, with a focus on the promotion and
1481 tight integration of GNU components, and an emphasis on programs and
1482 tools that help users exert that freedom.
1483
1484 @menu
1485 * Packaging Guidelines:: What goes into the distribution.
1486 * Installing Debugging Files:: Feeding the debugger.
1487 * Package Modules:: Packages from the programmer's viewpoint.
1488 * Bootstrapping:: GNU/Linux built from scratch.
1489 * Porting:: Targeting another platform or kernel.
1490 @end menu
1491
1492 Building this distribution is a cooperative effort, and you are invited
1493 to join! @ref{Contributing}, for information about how you can help.
1494
1495 @node Packaging Guidelines
1496 @section Packaging Guidelines
1497
1498 @c Adapted from http://www.gnu.org/philosophy/philosophy.html.
1499
1500 The GNU operating system has been developed so that users can have
1501 freedom in their computing. GNU is @dfn{free software}, meaning that
1502 users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
1503 essential freedoms}: to run the program, to study and change the program
1504 in source code form, to redistribute exact copies, and to distribute
1505 modified versions. Packages found in the GNU distribution provide only
1506 software that conveys these four freedoms.
1507
1508 In addition, the GNU distribution follow the
1509 @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
1510 software distribution guidelines}. Among other things, these guidelines
1511 reject non-free firmware, recommendations of non-free software, and
1512 discuss ways to deal with trademarks and patents.
1513
1514
1515 @node Installing Debugging Files
1516 @section Installing Debugging Files
1517
1518 Program binaries, as produced by the GCC compilers for instance, are
1519 typically written in the ELF format, with a section containing
1520 @dfn{debugging information}. Debugging information is what allows the
1521 debugger, GDB, to map binary code to source code; it is required to
1522 debug a compiled program in good conditions.
1523
1524 The problem with debugging information is that is takes up a fair amount
1525 of disk space. For example, debugging information for the GNU C Library
1526 weighs in at more than 60 MiB. Thus, as a user, keeping all the
1527 debugging info of all the installed programs is usually not an option.
1528 Yet, space savings should not come at the cost of an impediment to
1529 debugging---especially in the GNU system, which should make it easier
1530 for users to exert their computing freedom (@pxref{GNU Distribution}).
1531
1532 Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
1533 mechanism that allows users to get the best of both worlds: debugging
1534 information can be stripped from the binaries and stored in separate
1535 files. GDB is then able to load debugging information from those files,
1536 when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
1537 with GDB}).
1538
1539 The GNU distribution takes advantage of this by storing debugging
1540 information in the @code{lib/debug} sub-directory of a separate package
1541 output unimaginatively called @code{debug} (@pxref{Packages with
1542 Multiple Outputs}). Users can choose to install the @code{debug} output
1543 of a package when they need it. For instance, the following command
1544 installs the debugging information for the GNU C Library and for GNU
1545 Guile:
1546
1547 @example
1548 guix package -i glibc:debug -i guile:debug
1549 @end example
1550
1551 GDB must then be told to look for debug files in the user's profile, by
1552 setting the @code{debug-file-directory} variable (consider setting it
1553 from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
1554 GDB}):
1555
1556 @example
1557 (gdb) set debug-file-directory ~/.guix-profile/lib/debug
1558 @end example
1559
1560 From there on, GDB will pick up debugging information from the
1561 @code{.debug} files under @file{~/.guix-profile/lib/debug}.
1562
1563 @c XXX: keep me up-to-date
1564 The @code{debug} output mechanism in Guix is implemented by the
1565 @code{gnu-build-system} (@pxref{Defining Packages}). Currently, it is
1566 opt-in---debugging information is available only for those packages
1567 whose definition explicitly declares a @code{debug} output. This may be
1568 changed to opt-out in the future, if our build farm servers can handle
1569 the load. To check whether a package has a @code{debug} output, use
1570 @command{guix package --list-available} (@pxref{Invoking guix package}).
1571
1572
1573 @node Package Modules
1574 @section Package Modules
1575
1576 From a programming viewpoint, the package definitions of the
1577 distribution are provided by Guile modules in the @code{(gnu packages
1578 ...)} name space---for instance, the @code{(gnu packages emacs)} module
1579 exports a variable named @code{emacs}, which is bound to a
1580 @code{<package>} object (@pxref{Defining Packages}). The @code{(gnu
1581 packages)} module provides facilities for searching for packages.
1582
1583 The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
1584 each package is built based solely on other packages in the
1585 distribution. The root of this dependency graph is a small set of
1586 @dfn{bootstrap binaries}, provided by the @code{(gnu packages
1587 bootstrap)} module. More on this in the next section.
1588
1589
1590 @node Bootstrapping
1591 @section Bootstrapping
1592
1593 @c Adapted from the ELS 2013 paper.
1594
1595 @cindex bootstrapping
1596
1597 Bootstrapping in our context refers to how the distribution gets built
1598 ``from nothing''. Remember that the build environment of a derivation
1599 contains nothing but its declared inputs (@pxref{Introduction}). So
1600 there's an obvious chicken-and-egg problem: how does the first package
1601 get built? How does the first compiler get compiled? Note that this is
1602 a question of interest only to the curious hacker, not to the regular
1603 user, so you can shamelessly skip this section if you consider yourself
1604 a ``regular user''.
1605
1606 @cindex bootstrap binaries
1607 The GNU system is primarily made of C code, with libc at its core. The
1608 GNU build system itself assumes the availability of a Bourne shell and
1609 command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
1610 `grep'. Furthermore, build programs---programs that run
1611 @code{./configure}, @code{make}, etc.---are written in Guile Scheme
1612 (@pxref{Derivations}). Consequently, to be able to build anything at
1613 all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
1614 Binutils, libc, and the other packages mentioned above---the
1615 @dfn{bootstrap binaries}.
1616
1617 These bootstrap binaries are ``taken for granted'', though we can also
1618 re-create them if needed (more on that later.)
1619
1620 @unnumberedsubsec Preparing to Use the Bootstrap Binaries
1621
1622 @c As of Emacs 24.3, Info-mode displays the image, but since it's a
1623 @c large image, it's hard to scroll. Oh well.
1624 @image{images/bootstrap-graph,,,Dependency graph of the early bootstrap derivations}
1625
1626 The figure above shows the very beginning of the dependency graph of the
1627 distribution, corresponding to the package definitions of the @code{(gnu
1628 packages bootstrap)} module. At this level of detail, things are
1629 slightly complex. First, Guile itself consists of an ELF executable,
1630 along with many source and compiled Scheme files that are dynamically
1631 loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
1632 tarball shown in this graph. This tarball is part of Guix's ``source''
1633 distribution, and gets inserted into the store with @code{add-to-store}
1634 (@pxref{The Store}).
1635
1636 But how do we write a derivation that unpacks this tarball and adds it
1637 to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
1638 derivation---the first one that gets built---uses @code{bash} as its
1639 builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
1640 @code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
1641 @file{xz}, and @file{mkdir} are statically-linked binaries, also part of
1642 the Guix source distribution, whose sole purpose is to allow the Guile
1643 tarball to be unpacked.
1644
1645 Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
1646 Guile that can be used to run subsequent build programs. Its first task
1647 is to download tarballs containing the other pre-built binaries---this
1648 is what the @code{.tar.xz.drv} derivations do. Guix modules such as
1649 @code{ftp-client.scm} are used for this purpose. The
1650 @code{module-import.drv} derivations import those modules in a directory
1651 in the store, using the original layout. The
1652 @code{module-import-compiled.drv} derivations compile those modules, and
1653 write them in an output directory with the right layout. This
1654 corresponds to the @code{#:modules} argument of
1655 @code{build-expression->derivation} (@pxref{Derivations}).
1656
1657 Finally, the various tarballs are unpacked by the
1658 derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
1659 etc., at which point we have a working C tool chain.
1660
1661
1662 @unnumberedsubsec Building the Build Tools
1663
1664 @c TODO: Add a package-level dependency graph generated from (gnu
1665 @c packages base).
1666
1667 Bootstrapping is complete when we have a full tool chain that does not
1668 depend on the pre-built bootstrap tools discussed above. This
1669 no-dependency requirement is verified by checking whether the files of
1670 the final tool chain contain references to the @file{/nix/store}
1671 directories of the bootstrap inputs. The process that leads to this
1672 ``final'' tool chain is described by the package definitions found in
1673 the @code{(gnu packages base)} module.
1674
1675 @c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
1676 The first tool that gets built with the bootstrap binaries is
1677 GNU Make, which is a prerequisite for all the following packages.
1678 From there Findutils and Diffutils get built.
1679
1680 Then come the first-stage Binutils and GCC, built as pseudo cross
1681 tools---i.e., with @code{--target} equal to @code{--host}. They are
1682 used to build libc. Thanks to this cross-build trick, this libc is
1683 guaranteed not to hold any reference to the initial tool chain.
1684
1685 From there the final Binutils and GCC are built. GCC uses @code{ld}
1686 from the final Binutils, and links programs against the just-built libc.
1687 This tool chain is used to build the other packages used by Guix and by
1688 the GNU Build System: Guile, Bash, Coreutils, etc.
1689
1690 And voilà! At this point we have the complete set of build tools that
1691 the GNU Build System expects. These are in the @code{%final-inputs}
1692 variables of the @code{(gnu packages base)} module, and are implicitly
1693 used by any package that uses @code{gnu-build-system} (@pxref{Defining
1694 Packages}).
1695
1696
1697 @unnumberedsubsec Building the Bootstrap Binaries
1698
1699 Because the final tool chain does not depend on the bootstrap binaries,
1700 those rarely need to be updated. Nevertheless, it is useful to have an
1701 automated way to produce them, should an update occur, and this is what
1702 the @code{(gnu packages make-bootstrap)} module provides.
1703
1704 The following command builds the tarballs containing the bootstrap
1705 binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
1706 of Coreutils and other basic command-line tools):
1707
1708 @example
1709 guix build bootstrap-tarballs
1710 @end example
1711
1712 The generated tarballs are those that should be referred to in the
1713 @code{(gnu packages bootstrap)} module mentioned at the beginning of
1714 this section.
1715
1716 Still here? Then perhaps by now you've started to wonder: when do we
1717 reach a fixed point? That is an interesting question! The answer is
1718 unknown, but if you would like to investigate further (and have
1719 significant computational and storage resources to do so), then let us
1720 know.
1721
1722 @node Porting
1723 @section Porting to a New Platform
1724
1725 As discussed above, the GNU distribution is self-contained, and
1726 self-containment is achieved by relying on pre-built ``bootstrap
1727 binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
1728 operating system kernel, CPU architecture, and application binary
1729 interface (ABI). Thus, to port the distribution to a platform that is
1730 not yet supported, one must build those bootstrap binaries, and update
1731 the @code{(gnu packages bootstrap)} module to use them on that platform.
1732
1733 Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
1734 When everything goes well, and assuming the GNU tool chain supports the
1735 target platform, this can be as simple as running a command like this
1736 one:
1737
1738 @example
1739 guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
1740 @end example
1741
1742 In practice, there may be some complications. First, it may be that the
1743 extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
1744 above) is not recognized by all the GNU tools. Typically, glibc
1745 recognizes some of these, whereas GCC uses an extra @code{--with-abi}
1746 configure flag (see @code{gcc.scm} for examples of how to handle this.)
1747 Second, some of the required packages could fail to build for that
1748 platform. Lastly, the generated binaries could be broken for some
1749 reason.
1750
1751
1752 @c *********************************************************************
1753 @node Contributing
1754 @chapter Contributing
1755
1756 This project is a cooperative effort, and we need your help to make it
1757 grow! Please get in touch with us on @email{bug-guix@@gnu.org}. We
1758 welcome ideas, bug reports, patches, and anything that may be helpful to
1759 the project.
1760
1761 Please see the
1762 @url{http://git.savannah.gnu.org/cgit/guix.git/tree/HACKING,
1763 @file{HACKING} file} that comes with the Guix source code for practical
1764 details about contributions.
1765
1766
1767 @c *********************************************************************
1768 @node Acknowledgments
1769 @chapter Acknowledgments
1770
1771 Guix is based on the Nix package manager, which was designed and
1772 implemented by Eelco Dolstra. Nix pioneered functional package
1773 management, and promoted unprecedented features, such as transactional
1774 package upgrades and rollbacks, per-user profiles, and referentially
1775 transparent build processes. Without this work, Guix would not exist.
1776
1777 The Nix-based software distributions, Nixpkgs and NixOS, have also been
1778 an inspiration for Guix.
1779
1780 @c *********************************************************************
1781 @node GNU Free Documentation License
1782 @appendix GNU Free Documentation License
1783
1784 @include fdl-1.3.texi
1785
1786 @c *********************************************************************
1787 @node Concept Index
1788 @unnumbered Concept Index
1789 @printindex cp
1790
1791 @node Function Index
1792 @unnumbered Function Index
1793 @printindex fn
1794
1795 @bye
1796
1797 @c Local Variables:
1798 @c ispell-local-dictionary: "american";
1799 @c End: