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