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