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