store: Add 'query-failed-paths' and 'clear-failed-paths' RPCs.
[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
4379c35b 13Copyright @copyright{} 2012, 2013, 2014, 2015 Ludovic Courtès@*
af8a56b8 14Copyright @copyright{} 2013, 2014 Andreas Enge@*
87eafdbd 15Copyright @copyright{} 2013 Nikita Karetnikov@*
8c01b9d0
ML
16Copyright @copyright{} 2015 Mathieu Lirzin@*
17Copyright @copyright{} 2014 Pierre-Antoine Rault@*
87eafdbd 18Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer
7df7a74e
NK
19
20Permission is granted to copy, distribute and/or modify this document
21under the terms of the GNU Free Documentation License, Version 1.3 or
22any later version published by the Free Software Foundation; with no
23Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
24copy of the license is included in the section entitled ``GNU Free
25Documentation License''.
26@end copying
568717fd 27
eeaf4427 28@dircategory Package management
568717fd
LC
29@direntry
30* guix: (guix). Guix, the functional package manager.
e49951eb 31* guix package: (guix)Invoking guix package
eeaf4427 32 Managing packages with Guix.
e49951eb 33* guix build: (guix)Invoking guix build
568717fd 34 Building packages with Guix.
054e8576
LC
35* guix system: (guix)Invoking guix system
36 Managing the operating system configuration.
568717fd 37@end direntry
568717fd 38
372c4bbc
DT
39@dircategory Software development
40@direntry
41* guix environment: (guix)Invoking guix environment
42 Building development environments with Guix.
43@end direntry
44
568717fd 45@titlepage
7730d112
LC
46@title GNU Guix Reference Manual
47@subtitle Using the GNU Guix Functional Package Manager
2cbed07e 48@author The GNU Guix Developers
568717fd
LC
49
50@page
51@vskip 0pt plus 1filll
52Edition @value{EDITION} @*
53@value{UPDATED} @*
54
7df7a74e 55@insertcopying
568717fd
LC
56@end titlepage
57
568717fd
LC
58@contents
59
60@c *********************************************************************
61@node Top
f8348b91 62@top GNU Guix
568717fd 63
f8348b91
LC
64This document describes GNU Guix version @value{VERSION}, a functional
65package management tool written for the GNU system.
568717fd
LC
66
67@menu
68* Introduction:: What is Guix about?
bd5e766b 69* Installation:: Installing Guix.
eeaf4427 70* Package Management:: Package installation, upgrade, etc.
c554de89 71* Emacs Interface:: Using Guix from Emacs.
568717fd
LC
72* Programming Interface:: Using Guix in Scheme.
73* Utilities:: Package management commands.
a1ba8475 74* GNU Distribution:: Software for your friendly GNU system.
9bf3c1a7 75* Contributing:: Your help needed!
568717fd
LC
76
77* Acknowledgments:: Thanks!
78* GNU Free Documentation License:: The license of this manual.
79* Concept Index:: Concepts.
a85b83d2 80* Programming Index:: Data types, functions, and variables.
aaa3eaa9
LC
81
82@detailmenu
83 --- The Detailed Node Listing ---
84
85Installation
86
1b2b8177 87* Binary Installation:: Getting Guix running in no time!
aaa3eaa9 88* Requirements:: Software needed to build and run Guix.
ec0339cd 89* Running the Test Suite:: Testing Guix.
aaa3eaa9
LC
90* Setting Up the Daemon:: Preparing the build daemon's environment.
91* Invoking guix-daemon:: Running the build daemon.
0e2d0213 92* Application Setup:: Application-specific setup.
aaa3eaa9
LC
93
94Setting Up the Daemon
95
96* Build Environment Setup:: Preparing the isolated build environment.
97* Daemon Offload Setup:: Offloading builds to remote machines.
98
99Package Management
100
101* Features:: How Guix will make your life brighter.
102* Invoking guix package:: Package installation, removal, etc.
aaa3eaa9
LC
103* Substitutes:: Downloading pre-built binaries.
104* Packages with Multiple Outputs:: Single source package, multiple outputs.
105* Invoking guix gc:: Running the garbage collector.
106* Invoking guix pull:: Fetching the latest Guix and distribution.
107* Invoking guix archive:: Exporting and importing store files.
108
c554de89
AK
109Emacs Interface
110
111* Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
112* Package Management: Emacs Package Management. Managing packages and generations.
9b0afb0d 113* Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
c554de89 114* Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
34850cd5 115* Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
187f80c6
AK
116* Completions: Emacs Completions. Completing @command{guix} shell command.
117* Development: Emacs Development. Tools for Guix developers.
c554de89 118
aaa3eaa9
LC
119Programming Interface
120
121* Defining Packages:: Defining new packages.
122* Build Systems:: Specifying how packages are built.
123* The Store:: Manipulating the package store.
124* Derivations:: Low-level interface to package derivations.
125* The Store Monad:: Purely functional interface to the store.
126* G-Expressions:: Manipulating build expressions.
127
92492b23
LC
128Defining Packages
129
130* package Reference:: The package data type.
131* origin Reference:: The origin data type.
132
aaa3eaa9
LC
133Utilities
134
135* Invoking guix build:: Building packages from the command line.
fcc58db6 136* Invoking guix edit:: Editing package definitions.
aaa3eaa9
LC
137* Invoking guix download:: Downloading a file and printing its hash.
138* Invoking guix hash:: Computing the cryptographic hash of a file.
139* Invoking guix import:: Importing package definitions.
140* Invoking guix refresh:: Updating package definitions.
141* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 142* Invoking guix size:: Profiling disk usage.
88856916 143* Invoking guix graph:: Visualizing the graph of packages.
aaa3eaa9 144* Invoking guix environment:: Setting up development environments.
aff8ce7c 145* Invoking guix publish:: Sharing substitutes.
aaa3eaa9
LC
146
147GNU Distribution
148
149* System Installation:: Installing the whole operating system.
35ed9306 150* System Configuration:: Configuring the operating system.
aaa3eaa9
LC
151* Installing Debugging Files:: Feeding the debugger.
152* Security Updates:: Deploying security fixes quickly.
153* Package Modules:: Packages from the programmer's viewpoint.
154* Packaging Guidelines:: Growing the distribution.
155* Bootstrapping:: GNU/Linux built from scratch.
156* Porting:: Targeting another platform or kernel.
157
158System Configuration
159
160* Using the Configuration System:: Customizing your GNU system.
161* operating-system Reference:: Detail of operating-system declarations.
162* File Systems:: Configuring file system mounts.
163* Mapped Devices:: Block device extra processing.
164* User Accounts:: Specifying user accounts.
598e19dc 165* Locales:: Language and cultural convention settings.
aaa3eaa9
LC
166* Services:: Specifying system services.
167* Setuid Programs:: Programs running with root privileges.
1b2b8177 168* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 169* Name Service Switch:: Configuring libc's name service switch.
aaa3eaa9
LC
170* Initial RAM Disk:: Linux-Libre bootstrapping.
171* GRUB Configuration:: Configuring the boot loader.
172* Invoking guix system:: Instantiating a system configuration.
173* Defining Services:: Adding new service definitions.
174
175Services
176
177* Base Services:: Essential system services.
178* Networking Services:: Network setup, SSH daemon, etc.
179* X Window:: Graphical display.
1b2b8177
LC
180* Desktop Services:: D-Bus and desktop services.
181* Database Services:: SQL databases.
cbd02397 182* Web Services:: Web servers.
aa4ed923 183* Various Services:: Other services.
aaa3eaa9
LC
184
185Packaging Guidelines
186
ec0339cd
LC
187* Software Freedom:: What may go into the distribution.
188* Package Naming:: What's in a name?
189* Version Numbers:: When the name is not enough.
cbd02397 190* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
191* Python Modules:: Taming the snake.
192* Perl Modules:: Little pearls.
193* Fonts:: Fond of fonts.
aaa3eaa9 194
8c01b9d0
ML
195Contributing
196
197* Building from Git:: The latest and greatest.
198* Running Guix Before It Is Installed:: Hacker tricks.
199* The Perfect Setup:: The right tools.
200* Coding Style:: Hygiene of the contributor.
201* Submitting Patches:: Share your work.
202
203Coding Style
204
205* Programming Paradigm:: How to compose your elements.
206* Modules:: Where to store your code?
207* Data Types and Pattern Matching:: Implementing data structures.
208* Formatting Code:: Writing conventions.
209
aaa3eaa9 210@end detailmenu
568717fd
LC
211@end menu
212
213@c *********************************************************************
214@node Introduction
215@chapter Introduction
216
c80e7e55
LC
217GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
218using the international phonetic alphabet (IPA).} is a functional
219package management tool for the GNU system. Package management consists
4bfc4ea3
NK
220of all activities that relate to building packages from sources,
221honoring their build-time and run-time dependencies,
c80e7e55
LC
222installing packages in user environments, upgrading installed packages
223to new versions or rolling back to a previous set, removing unused
224software packages, etc.
568717fd
LC
225
226@cindex functional package management
227The term @dfn{functional} refers to a specific package management
228discipline. In Guix, the package build and installation process is seen
4bfc4ea3
NK
229as a function, in the mathematical sense. That function takes inputs,
230such as build scripts, a compiler, and libraries, and
231returns an installed package. As a pure function, its result depends
568717fd
LC
232solely on its inputs---for instance, it cannot refer to software or
233scripts that were not explicitly passed as inputs. A build function
4bfc4ea3
NK
234always produces the same result when passed a given set of inputs. It
235cannot alter the system's environment in
568717fd
LC
236any way; for instance, it cannot create, modify, or delete files outside
237of its build and installation directories. This is achieved by running
e900c503 238build processes in isolated environments (or @dfn{containers}), where only their
4bfc4ea3 239explicit inputs are visible.
568717fd 240
e531ac2a 241@cindex store
568717fd 242The result of package build functions is @dfn{cached} in the file
e531ac2a
LC
243system, in a special directory called @dfn{the store} (@pxref{The
244Store}). Each package is installed in a directory of its own, in the
834129e0 245store---by default under @file{/gnu/store}. The directory name contains
568717fd
LC
246a hash of all the inputs used to build that package; thus, changing an
247input yields a different directory name.
248
249This approach is the foundation of Guix's salient features: support for
4bfc4ea3 250transactional package upgrade and rollback, per-user installation, and
eeaf4427 251garbage collection of packages (@pxref{Features}).
568717fd 252
4bfc4ea3 253Guix has a command-line interface, which allows users to build, install,
568717fd 254upgrade, and remove packages, as well as a Scheme programming interface.
568717fd 255
3ca2731c 256@cindex Guix System Distribution
4705641f 257@cindex GuixSD
a1ba8475 258Last but not least, Guix is used to build a distribution of the GNU
3ca2731c 259system, with many GNU and non-GNU free software packages. The Guix
4705641f
LC
260System Distribution, or GNU@tie{}GuixSD, takes advantage of the core
261properties of Guix at the system level. With GuixSD, users
3ca2731c
LC
262@emph{declare} all aspects of the operating system configuration, and
263Guix takes care of instantiating that configuration in a reproducible,
264stateless fashion. @xref{GNU Distribution}.
a1ba8475 265
bd5e766b
LC
266@c *********************************************************************
267@node Installation
268@chapter Installation
269
48febeb8
LC
270GNU Guix is available for download from its website at
271@url{http://www.gnu.org/software/guix/}. This section describes the
272software requirements of Guix, as well as how to install it and get
273ready to use it.
bd5e766b 274
5af6de3e
LC
275Note that this section is concerned with the installation of the package
276manager, which can be done on top of a running GNU/Linux system. If,
277instead, you want to install the complete GNU operating system,
6621cdb6 278@pxref{System Installation}.
5af6de3e 279
bd5e766b 280@menu
09722b11 281* Binary Installation:: Getting Guix running in no time!
bd5e766b 282* Requirements:: Software needed to build and run Guix.
ec0339cd 283* Running the Test Suite:: Testing Guix.
bd5e766b
LC
284* Setting Up the Daemon:: Preparing the build daemon's environment.
285* Invoking guix-daemon:: Running the build daemon.
0e2d0213 286* Application Setup:: Application-specific setup.
bd5e766b
LC
287@end menu
288
09722b11
LC
289@node Binary Installation
290@section Binary Installation
291
292This section describes how to install Guix on an arbitrary system from a
293self-contained tarball providing binaries for Guix and for all its
294dependencies. This is often quicker than installing from source, which
295is described in the next sections. The only requirement is to have
296GNU@tie{}tar and Xz.
297
298Installing goes along these lines:
299
300@enumerate
301@item
302Download the binary tarball from
ae806096 303@indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz}@footnote{As
09722b11
LC
304usual, make sure to download the associated @file{.sig} file and to
305verify the authenticity of the tarball against it!}, where @var{system}
306is @code{x86_64-linux} for an @code{x86_64} machine already running the
307kernel Linux, and so on.
308
309@item
310As @code{root}, run:
311
312@example
5dc42964 313# cd /tmp
254b1c2e
LC
314# tar --warning=no-timestamp -xf \
315 guix-binary-@value{VERSION}.@var{system}.tar.xz
5dc42964 316# mv var/guix /var/ && mv gnu /
09722b11
LC
317@end example
318
7acd3439
LC
319This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
320The latter contains a ready-to-use profile for @code{root} (see next
321step.)
09722b11 322
5dc3ce5f
LC
323Do @emph{not} unpack the tarball on a working Guix system since that
324would overwrite its own essential files.
325
254b1c2e 326The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
e9ba6357
LC
327not emit warnings about ``implausibly old time stamps'' (such
328warnings were triggered by GNU@tie{}tar 1.26 and older; recent
329versions are fine.)
330They stem from the fact that all the
254b1c2e
LC
331files in the archive have their modification time set to zero (which
332means January 1st, 1970.) This is done on purpose to make sure the
333archive content is independent of its creation time, thus making it
334reproducible.
335
7acd3439
LC
336@item
337Make @code{root}'s profile available under @file{~/.guix-profile}:
338
339@example
340# ln -sf /var/guix/profiles/per-user/root/guix-profile \
341 ~root/.guix-profile
342@end example
343
43c33047
LC
344@item
345Create the group and user accounts for build users as explained below
346(@pxref{Build Environment Setup}).
347
09722b11 348@item
175ced41 349Run the daemon:
09722b11
LC
350
351@example
7acd3439 352# ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
09722b11
LC
353@end example
354
d2825c96
LC
355On hosts using the systemd init system, drop
356@file{~root/.guix-profile/lib/systemd/system/guix-daemon.service} in
357@file{/etc/systemd/system}.
358
09722b11
LC
359@item
360Make the @command{guix} command available to other users on the machine,
361for instance with:
362
363@example
364# mkdir -p /usr/local/bin
365# cd /usr/local/bin
d72d05f9 366# ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
09722b11 367@end example
39f8ed14
LC
368
369@item
370To use substitutes from @code{hydra.gnu.org} (@pxref{Substitutes}),
371authorize them:
372
373@example
7acd3439 374# guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
39f8ed14 375@end example
09722b11
LC
376@end enumerate
377
53de532f
LC
378And that's it! For additional tips and tricks, @pxref{Application
379Setup}.
09722b11 380
5dc3ce5f 381The @code{guix} package must remain available in @code{root}'s
09722b11
LC
382profile, or it would become subject to garbage collection---in which
383case you would find yourself badly handicapped by the lack of the
384@command{guix} command.
385
39f8ed14
LC
386The tarball in question can be (re)produced and verified simply by
387running the following command in the Guix source tree:
09722b11
LC
388
389@example
390make guix-binary.@var{system}.tar.xz
391@end example
392
393
bd5e766b
LC
394@node Requirements
395@section Requirements
396
09722b11
LC
397This section lists requirements when building Guix from source. The
398build procedure for Guix is the same as for other GNU software, and is
399not covered here. Please see the files @file{README} and @file{INSTALL}
400in the Guix source tree for additional details.
401
bd5e766b
LC
402GNU Guix depends on the following packages:
403
404@itemize
47c66da0 405@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
288dca55 406@item @url{http://gnupg.org/, GNU libgcrypt};
f0b98b84 407@item @url{http://www.gnu.org/software/make/, GNU Make}.
8a96bd4b
ID
408@end itemize
409
410The following dependencies are optional:
411
412@itemize
288dca55 413@item
8a96bd4b 414Installing
288dca55 415@url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
2f7d2d91
LC
416allow you to use the @command{guix import pypi} command (@pxref{Invoking
417guix import}). It is of
288dca55 418interest primarily for developers and not for casual users.
8a96bd4b
ID
419@item
420Installing @uref{http://gnutls.org/, GnuTLS-Guile} will
421allow you to access @code{https} URLs with the @command{guix download}
d45dc6da
EB
422command (@pxref{Invoking guix download}), the @command{guix import pypi}
423command, and the @command{guix import cpan} command. This is primarily
424of interest to developers. @xref{Guile Preparations, how to install the
425GnuTLS bindings for Guile,, gnutls-guile, GnuTLS-Guile}.
bd5e766b
LC
426@end itemize
427
428Unless @code{--disable-daemon} was passed to @command{configure}, the
429following packages are also needed:
430
431@itemize
368d08f7
LC
432@item @url{http://sqlite.org, SQLite 3};
433@item @url{http://www.bzip.org, libbz2};
434@item @url{http://gcc.gnu.org, GCC's g++}, with support for the
435C++11 standard.
bd5e766b
LC
436@end itemize
437
4bfc4ea3
NK
438When a working installation of @url{http://nixos.org/nix/, the Nix package
439manager} is available, you
bd5e766b 440can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 441Nix replaces the three dependencies above.
bd5e766b 442
b22a12fd
LC
443Guix is compatible with Nix, so it is possible to share the same store
444between both. To do so, you must pass @command{configure} not only the
445same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
446@code{--localstatedir} value. The latter is essential because it
447specifies where the database that stores metadata about the store is
834129e0 448located, among other things. The default values for Nix are
b22a12fd 449@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
450Note that @code{--disable-daemon} is not required if
451your goal is to share the store with Nix.
b22a12fd 452
ec0339cd
LC
453@node Running the Test Suite
454@section Running the Test Suite
455
456After a successful @command{configure} and @code{make} run, it is a good
457idea to run the test suite. It can help catch issues with the setup or
458environment, or bugs in Guix itself---and really, reporting test
459failures is a good way to help improve the software. To run the test
460suite, type:
461
462@example
463make check
464@end example
465
466Test cases can run in parallel: you can use the @code{-j} option of
467GNU@tie{}make to speed things up. The first run may take a few minutes
468on a recent machine; subsequent runs will be faster because the store
469that is created for test purposes will already have various things in
470cache.
471
472Upon failure, please email @email{bug-guix@@gnu.org} and attach the
473@file{test-suite.log} file. When @file{tests/@var{something}.scm}
474fails, please also attach the @file{@var{something}.log} file available
475in the top-level build directory. Please specify the Guix version being
476used as well as version numbers of the dependencies
477(@pxref{Requirements}) in your message.
478
bd5e766b
LC
479@node Setting Up the Daemon
480@section Setting Up the Daemon
481
482@cindex daemon
483Operations such as building a package or running the garbage collector
49e6291a 484are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
485behalf of clients. Only the daemon may access the store and its
486associated database. Thus, any operation that manipulates the store
487goes through the daemon. For instance, command-line tools such as
e49951eb 488@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
489daemon (@i{via} remote procedure calls) to instruct it what to do.
490
49e6291a 491The following sections explain how to prepare the build daemon's
225dafde
LC
492environment. Also @ref{Substitutes}, for information on how to allow
493the daemon to download pre-built binaries.
49e6291a
LC
494
495@menu
496* Build Environment Setup:: Preparing the isolated build environment.
497* Daemon Offload Setup:: Offloading builds to remote machines.
498@end menu
499
500@node Build Environment Setup
501@subsection Build Environment Setup
502
bd5e766b
LC
503In a standard multi-user setup, Guix and its daemon---the
504@command{guix-daemon} program---are installed by the system
834129e0 505administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
506@command{guix-daemon} runs as @code{root}. Unprivileged users may use
507Guix tools to build packages or otherwise access the store, and the
508daemon will do it on their behalf, ensuring that the store is kept in a
509consistent state, and allowing built packages to be shared among users.
510
511@cindex build users
512When @command{guix-daemon} runs as @code{root}, you may not want package
513build processes themselves to run as @code{root} too, for obvious
514security reasons. To avoid that, a special pool of @dfn{build users}
515should be created for use by build processes started by the daemon.
516These build users need not have a shell and a home directory: they will
517just be used when the daemon drops @code{root} privileges in build
518processes. Having several such users allows the daemon to launch
519distinct build processes under separate UIDs, which guarantees that they
520do not interfere with each other---an essential feature since builds are
521regarded as pure functions (@pxref{Introduction}).
522
523On a GNU/Linux system, a build user pool may be created like this (using
524Bash syntax and the @code{shadow} commands):
525
091196b3
LC
526@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
527@c for why `-G' is needed.
bd5e766b 528@example
cfc149dc
LC
529# groupadd --system guixbuild
530# for i in `seq -w 1 10`;
bd5e766b 531 do
cfc149dc
LC
532 useradd -g guixbuild -G guixbuild \
533 -d /var/empty -s `which nologin` \
534 -c "Guix build user $i" --system \
535 guixbuilder$i;
bd5e766b
LC
536 done
537@end example
538
539@noindent
54eb03ab
LC
540The number of build users determines how many build jobs may run in
541parallel, as specified by the @option{--max-jobs} option
d2825c96
LC
542(@pxref{Invoking guix-daemon, @option{--max-jobs}}). The
543@code{guix-daemon} program may then be run as @code{root} with the
544following command@footnote{If your machine uses the systemd init system,
545dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
546file in @file{/etc/systemd/system} will ensure that
547@command{guix-daemon} is automatically started.}:
bd5e766b
LC
548
549@example
cfc149dc 550# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
551@end example
552
e900c503 553@cindex chroot
b095792f
LC
554@noindent
555This way, the daemon starts build processes in a chroot, under one of
cfc149dc 556the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
557environment contains nothing but:
558
559@c Keep this list in sync with libstore/build.cc! -----------------------
560@itemize
561@item
4743a4da
LC
562a minimal @code{/dev} directory, created mostly independently from the
563host @code{/dev}@footnote{``Mostly'', because while the set of files
564that appear in the chroot's @code{/dev} is fixed, most of these files
565can only be created if the host has them.};
566
567@item
568the @code{/proc} directory; it only shows the container's processes
569since a separate PID name space is used;
6dc99317
LC
570
571@item
572@file{/etc/passwd} with an entry for the current user and an entry for
573user @file{nobody};
574
575@item
576@file{/etc/group} with an entry for the user's group;
577
578@item
579@file{/etc/hosts} with an entry that maps @code{localhost} to
580@code{127.0.0.1};
581
582@item
583a writable @file{/tmp} directory.
584@end itemize
b095792f 585
1e2644bb
LC
586If you are installing Guix as an unprivileged user, it is still possible
587to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
588However, build processes will not be isolated from one another, and not
589from the rest of the system. Thus, build processes may interfere with
590each other, and may access programs, libraries, and other files
591available on the system---making it much harder to view them as
592@emph{pure} functions.
bd5e766b 593
49e6291a
LC
594
595@node Daemon Offload Setup
596@subsection Using the Offload Facility
597
598@cindex offloading
4ec2e92d
LC
599@cindex build hook
600When desired, the build daemon can @dfn{offload}
601derivation builds to other machines
49e6291a
LC
602running Guix, using the @code{offload} @dfn{build hook}. When that
603feature is enabled, a list of user-specified build machines is read from
604@file{/etc/guix/machines.scm}; anytime a build is requested, for
605instance via @code{guix build}, the daemon attempts to offload it to one
606of the machines that satisfies the derivation's constraints, in
607particular its system type---e.g., @file{x86_64-linux}. Missing
608prerequisites for the build are copied over SSH to the target machine,
609which then proceeds with the build; upon success the output(s) of the
610build are copied back to the initial machine.
611
4ec2e92d 612The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
613
614@example
615(list (build-machine
616 (name "eightysix.example.org")
617 (system "x86_64-linux")
618 (user "bob")
619 (speed 2.)) ; incredibly fast!
620
621 (build-machine
622 (name "meeps.example.org")
623 (system "mips64el-linux")
624 (user "alice")
625 (private-key
626 (string-append (getenv "HOME")
c4fdfd6f 627 "/.lsh/identity-for-guix"))))
49e6291a
LC
628@end example
629
630@noindent
631In the example above we specify a list of two build machines, one for
632the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
633architecture.
634
635In fact, this file is---not surprisingly!---a Scheme file that is
636evaluated when the @code{offload} hook is started. Its return value
637must be a list of @code{build-machine} objects. While this example
638shows a fixed list of build machines, one could imagine, say, using
639DNS-SD to return a list of potential build machines discovered in the
640local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
c678a4ee
LC
641Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
642detailed below.
4ec2e92d 643
c678a4ee
LC
644@deftp {Data Type} build-machine
645This data type represents build machines the daemon may offload builds
646to. The important fields are:
49e6291a
LC
647
648@table @code
649
650@item name
651The remote machine's host name.
652
653@item system
c678a4ee 654The remote machine's system type---e.g., @code{"x86_64-linux"}.
49e6291a
LC
655
656@item user
657The user account to use when connecting to the remote machine over SSH.
658Note that the SSH key pair must @emph{not} be passphrase-protected, to
659allow non-interactive logins.
660
661@end table
662
4ec2e92d 663A number of optional fields may be specified:
49e6291a
LC
664
665@table @code
666
cecd72d5
LC
667@item port
668Port number of the machine's SSH server (default: 22).
669
49e6291a
LC
670@item private-key
671The SSH private key file to use when connecting to the machine.
672
c4fdfd6f
LC
673Currently offloading uses GNU@tie{}lsh as its SSH client
674(@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must
675be an lsh key file. This may change in the future, though.
676
49e6291a
LC
677@item parallel-builds
678The number of builds that may run in parallel on the machine (1 by
679default.)
680
681@item speed
682A ``relative speed factor''. The offload scheduler will tend to prefer
683machines with a higher speed factor.
684
685@item features
686A list of strings denoting specific features supported by the machine.
687An example is @code{"kvm"} for machines that have the KVM Linux modules
688and corresponding hardware support. Derivations can request features by
689name, and they will be scheduled on matching build machines.
690
691@end table
c678a4ee 692@end deftp
49e6291a
LC
693
694The @code{guix} command must be in the search path on the build
695machines, since offloading works by invoking the @code{guix archive} and
c4fdfd6f
LC
696@code{guix build} commands. In addition, the Guix modules must be in
697@code{$GUILE_LOAD_PATH} on the build machine---you can check whether
698this is the case by running:
699
700@example
701lsh build-machine guile -c '(use-modules (guix config))'
702@end example
49e6291a
LC
703
704There's one last thing to do once @file{machines.scm} is in place. As
705explained above, when offloading, files are transferred back and forth
c4fdfd6f
LC
706between the machine stores. For this to work, you first need to
707generate a key pair on each machine to allow the daemon to export signed
708archives of files from the store (@pxref{Invoking guix archive}):
49e6291a
LC
709
710@example
711# guix archive --generate-key
712@end example
713
714@noindent
c4fdfd6f
LC
715Each build machine must authorize the key of the master machine so that
716it accepts store items it receives from the master:
717
718@example
719# guix archive --authorize < master-public-key.txt
720@end example
721
722@noindent
723Likewise, the master machine must authorize the key of each build machine.
724
725All the fuss with keys is here to express pairwise mutual trust
726relations between the master and the build machines. Concretely, when
727the master receives files from a build machine (and @i{vice versa}), its
728build daemon can make sure they are genuine, have not been tampered
729with, and that they are signed by an authorized key.
49e6291a
LC
730
731
bd5e766b
LC
732@node Invoking guix-daemon
733@section Invoking @command{guix-daemon}
734
735The @command{guix-daemon} program implements all the functionality to
736access the store. This includes launching build processes, running the
737garbage collector, querying the availability of a build result, etc. It
738is normally run as @code{root} like this:
739
740@example
cfc149dc 741# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
742@end example
743
744@noindent
081145cf 745For details on how to set it up, @pxref{Setting Up the Daemon}.
bd5e766b 746
e900c503
LC
747@cindex chroot
748@cindex container, build environment
749@cindex build environment
750@cindex reproducible builds
bd5e766b
LC
751By default, @command{guix-daemon} launches build processes under
752different UIDs, taken from the build group specified with
753@code{--build-users-group}. In addition, each build process is run in a
754chroot environment that only contains the subset of the store that the
755build process depends on, as specified by its derivation
756(@pxref{Programming Interface, derivation}), plus a set of specific
757system directories. By default, the latter contains @file{/dev} and
e900c503
LC
758@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
759@dfn{container}: in addition to having its own file system tree, it has
760a separate mount name space, its own PID name space, network name space,
761etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b 762
cbc538fe
LC
763When the daemon performs a build on behalf of the user, it creates a
764build directory under @file{/tmp} or under the directory specified by
765its @code{TMPDIR} environment variable; this directory is shared with
766the container for the duration of the build. Be aware that using a
767directory other than @file{/tmp} can affect build results---for example,
768with a longer directory name, a build process that uses Unix-domain
769sockets might hit the name length limitation for @code{sun_path}, which
770it would otherwise not hit.
771
772The build directory is automatically deleted upon completion, unless the
773build failed and the client specified @option{--keep-failed}
774(@pxref{Invoking guix build, @option{--keep-failed}}).
775
bd5e766b
LC
776The following command-line options are supported:
777
778@table @code
779@item --build-users-group=@var{group}
780Take users from @var{group} to run build processes (@pxref{Setting Up
781the Daemon, build users}).
782
6858f9d1 783@item --no-substitutes
b5385b52 784@cindex substitutes
6858f9d1 785Do not use substitutes for build products. That is, always build things
c4202d60
LC
786locally instead of allowing downloads of pre-built binaries
787(@pxref{Substitutes}).
6858f9d1 788
b5385b52
LC
789By default substitutes are used, unless the client---such as the
790@command{guix package} command---is explicitly invoked with
791@code{--no-substitutes}.
792
793When the daemon runs with @code{--no-substitutes}, clients can still
794explicitly enable substitution @i{via} the @code{set-build-options}
795remote procedure call (@pxref{The Store}).
796
9176607e 797@item --substitute-urls=@var{urls}
f8a8e0fe 798@anchor{daemon-substitute-urls}
9176607e 799Consider @var{urls} the default whitespace-separated list of substitute
ae806096 800source URLs. When this option is omitted, @indicateurl{http://hydra.gnu.org}
9176607e
LC
801is used.
802
803This means that substitutes may be downloaded from @var{urls}, as long
804as they are signed by a trusted signature (@pxref{Substitutes}).
805
4ec2e92d
LC
806@cindex build hook
807@item --no-build-hook
808Do not use the @dfn{build hook}.
809
810The build hook is a helper program that the daemon can start and to
811which it submits build requests. This mechanism is used to offload
812builds to other machines (@pxref{Daemon Offload Setup}).
813
bd5e766b
LC
814@item --cache-failures
815Cache build failures. By default, only successful builds are cached.
816
817@item --cores=@var{n}
818@itemx -c @var{n}
819Use @var{n} CPU cores to build each derivation; @code{0} means as many
820as available.
821
6efc160e 822The default value is @code{0}, but it may be overridden by clients, such
e49951eb
MW
823as the @code{--cores} option of @command{guix build} (@pxref{Invoking
824guix build}).
bd5e766b
LC
825
826The effect is to define the @code{NIX_BUILD_CORES} environment variable
827in the build process, which can then use it to exploit internal
828parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
829
830@item --max-jobs=@var{n}
831@itemx -M @var{n}
832Allow at most @var{n} build jobs in parallel. The default value is
f6526eb3
LC
833@code{1}. Setting it to @code{0} means that no builds will be performed
834locally; instead, the daemon will offload builds (@pxref{Daemon Offload
835Setup}), or simply fail.
bd5e766b
LC
836
837@item --debug
838Produce debugging output.
839
840This is useful to debug daemon start-up issues, but then it may be
841overridden by clients, for example the @code{--verbosity} option of
e49951eb 842@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
843
844@item --chroot-directory=@var{dir}
845Add @var{dir} to the build chroot.
846
847Doing this may change the result of build processes---for instance if
848they use optional dependencies found in @var{dir} when it is available,
849and not otherwise. For that reason, it is not recommended to do so.
850Instead, make sure that each derivation declares all the inputs that it
851needs.
852
853@item --disable-chroot
854Disable chroot builds.
855
856Using this option is not recommended since, again, it would allow build
1e2644bb
LC
857processes to gain access to undeclared dependencies. It is necessary,
858though, when @command{guix-daemon} is running under an unprivileged user
859account.
bd5e766b
LC
860
861@item --disable-log-compression
862Disable compression of the build logs.
863
1da983b9
LC
864Unless @code{--lose-logs} is used, all the build logs are kept in the
865@var{localstatedir}. To save space, the daemon automatically compresses
866them with bzip2 by default. This option disables that.
867
ab3893d7
LC
868@item --disable-deduplication
869@cindex deduplication
bd5e766b
LC
870Disable automatic file ``deduplication'' in the store.
871
1da983b9 872By default, files added to the store are automatically ``deduplicated'':
ab3893d7
LC
873if a newly added file is identical to another one found in the store,
874the daemon makes the new file a hard link to the other file. This can
4988dd40 875noticeably reduce disk usage, at the expense of slightly increased
ab3893d7
LC
876input/output load at the end of a build process. This option disables
877this optimization.
1da983b9 878
6e37066e
LC
879@item --gc-keep-outputs[=yes|no]
880Tell whether the garbage collector (GC) must keep outputs of live
881derivations.
882
883When set to ``yes'', the GC will keep the outputs of any live derivation
884available in the store---the @code{.drv} files. The default is ``no'',
885meaning that derivation outputs are kept only if they are GC roots.
886
887@item --gc-keep-derivations[=yes|no]
888Tell whether the garbage collector (GC) must keep derivations
889corresponding to live outputs.
890
891When set to ``yes'', as is the case by default, the GC keeps
892derivations---i.e., @code{.drv} files---as long as at least one of their
893outputs is live. This allows users to keep track of the origins of
894items in their store. Setting it to ``no'' saves a bit of disk space.
895
896Note that when both @code{--gc-keep-derivations} and
897@code{--gc-keep-outputs} are used, the effect is to keep all the build
898prerequisites (the sources, compiler, libraries, and other build-time
899tools) of live objects in the store, regardless of whether these
900prerequisites are live. This is convenient for developers since it
901saves rebuilds or downloads.
902
bd5e766b
LC
903@item --impersonate-linux-2.6
904On Linux-based systems, impersonate Linux 2.6. This means that the
905kernel's @code{uname} system call will report 2.6 as the release number.
906
907This might be helpful to build programs that (usually wrongfully) depend
908on the kernel version number.
909
910@item --lose-logs
911Do not keep build logs. By default they are kept under
ce33631f 912@code{@var{localstatedir}/guix/log}.
bd5e766b
LC
913
914@item --system=@var{system}
915Assume @var{system} as the current system type. By default it is the
916architecture/kernel pair found at configure time, such as
917@code{x86_64-linux}.
b8d2aa26
LC
918
919@item --listen=@var{socket}
920Listen for connections on @var{socket}, the file name of a Unix-domain
921socket. The default socket is
922@file{@var{localstatedir}/daemon-socket/socket}. This option is only
923useful in exceptional circumstances, such as if you need to run several
924daemons on the same machine.
bd5e766b
LC
925@end table
926
927
0e2d0213
LC
928@node Application Setup
929@section Application Setup
930
931When using Guix on top of GNU/Linux distribution other than GuixSD, a
932few additional steps are needed to get everything in place. Here are
933some of them.
934
935@subsection Locales
936
5c3c1427 937@anchor{locales-and-locpath}
0e2d0213 938@cindex locales, when not on GuixSD
5c3c1427 939@vindex LOCPATH
0e2d0213
LC
940Packages installed @i{via} Guix will not use the host system's locale
941data. Instead, you must first install one of the locale packages
942available with Guix and then define the @code{LOCPATH} environment
943variable (@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library
944Reference Manual}):
945
946@example
947$ guix package -i glibc-locales
948$ export LOCPATH=$HOME/.guix-profile/lib/locale
949@end example
950
951Note that the @code{glibc-locales} package contains data for all the
952locales supported by the GNU@tie{}libc and weighs in at around
953110@tie{}MiB. Alternately, the @code{glibc-utf8-locales} is smaller but
954limited to a few UTF-8 locales.
955
956@subsection X11 Fonts
957
4988dd40 958The majority of graphical applications use Fontconfig to locate and
0e2d0213
LC
959load fonts and perform X11-client-side rendering. Guix's
960@code{fontconfig} package looks for fonts in @file{$HOME/.guix-profile}
961by default. Thus, to allow graphical applications installed with Guix
962to display fonts, you will have to install fonts with Guix as well.
963Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
8fe5b1d1 964@code{font-gnu-freefont-ttf}.
0e2d0213
LC
965
966@c TODO What else?
967
eeaf4427
LC
968@c *********************************************************************
969@node Package Management
970@chapter Package Management
971
f8348b91 972The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427
LC
973remove software packages, without having to know about their build
974procedure or dependencies. Guix also goes beyond this obvious set of
975features.
976
977This chapter describes the main features of Guix, as well as the package
c1941588 978management tools it provides. Two user interfaces are provided for
c554de89
AK
979routine package management tasks: A command-line interface described below
980(@pxref{Invoking guix package, @code{guix package}}), as well as a visual user
981interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}).
eeaf4427
LC
982
983@menu
984* Features:: How Guix will make your life brighter.
e49951eb 985* Invoking guix package:: Package installation, removal, etc.
c4202d60 986* Substitutes:: Downloading pre-built binaries.
760c60d6 987* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 988* Invoking guix gc:: Running the garbage collector.
f651b477 989* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 990* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
991@end menu
992
993@node Features
994@section Features
995
996When using Guix, each package ends up in the @dfn{package store}, in its
997own directory---something that resembles
9a130e19
AK
998@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
999(note that Guix comes with an Emacs extension to shorten those file
081145cf 1000names, @pxref{Emacs Prettify}.)
eeaf4427
LC
1001
1002Instead of referring to these directories, users have their own
1003@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
1004use. These profiles are stored within each user's home directory, at
1005@code{$HOME/.guix-profile}.
eeaf4427 1006
821b0015 1007For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 1008@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 1009@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
1010@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1011simply continues to point to
834129e0 1012@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 1013coexist on the same system without any interference.
eeaf4427 1014
e49951eb
MW
1015The @command{guix package} command is the central tool to manage
1016packages (@pxref{Invoking guix package}). It operates on those per-user
821b0015 1017profiles, and can be used @emph{with normal user privileges}.
eeaf4427
LC
1018
1019The command provides the obvious install, remove, and upgrade
1020operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 1021the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 1022@command{guix package} process is terminated during the transaction,
eeaf4427
LC
1023or if a power outage occurs during the transaction, then the user's
1024profile remains in its previous state, and remains usable.
1025
1026In addition, any package transaction may be @emph{rolled back}. So, if,
1027for example, an upgrade installs a new version of a package that turns
1028out to have a serious bug, users may roll back to the previous instance
4af2447e
LC
1029of their profile, which was known to work well. Similarly, the global
1030system configuration is subject to transactional upgrades and roll-back
1031(@pxref{Using the Configuration System}).
eeaf4427
LC
1032
1033All those packages in the package store may be @emph{garbage-collected}.
1034Guix can determine which packages are still referenced by the user
fe8ff028 1035profiles, and remove those that are provably no longer referenced
e49951eb 1036(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
1037generations of their profile so that the packages they refer to can be
1038collected.
eeaf4427 1039
e900c503
LC
1040@cindex reproducibility
1041@cindex reproducible builds
eeaf4427
LC
1042Finally, Guix takes a @dfn{purely functional} approach to package
1043management, as described in the introduction (@pxref{Introduction}).
834129e0 1044Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
1045inputs that were used to build that package---compiler, libraries, build
1046scripts, etc. This direct correspondence allows users to make sure a
1047given package installation matches the current state of their
e900c503
LC
1048distribution. It also helps maximize @dfn{build reproducibility}:
1049thanks to the isolated build environments that are used, a given build
1050is likely to yield bit-identical files when performed on different
1051machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 1052
c4202d60 1053@cindex substitutes
eeaf4427 1054This foundation allows Guix to support @dfn{transparent binary/source
c4202d60 1055deployment}. When a pre-built binary for a @file{/gnu/store} item is
18f2887b 1056available from an external source---a @dfn{substitute}, Guix just
c4202d60
LC
1057downloads it and unpacks it;
1058otherwise, it builds the package from source, locally
1059(@pxref{Substitutes}).
eeaf4427 1060
f5fd4fd2
LC
1061Control over the build environment is a feature that is also useful for
1062developers. The @command{guix environment} command allows developers of
1063a package to quickly set up the right development environment for their
1064package, without having to manually install the package's dependencies
1065in their profile (@pxref{Invoking guix environment}).
1066
e49951eb
MW
1067@node Invoking guix package
1068@section Invoking @command{guix package}
eeaf4427 1069
e49951eb 1070The @command{guix package} command is the tool that allows users to
eeaf4427
LC
1071install, upgrade, and remove packages, as well as rolling back to
1072previous configurations. It operates only on the user's own profile,
1073and works with normal user privileges (@pxref{Features}). Its syntax
1074is:
1075
1076@example
e49951eb 1077guix package @var{options}
eeaf4427
LC
1078@end example
1079
ba55b1cb 1080Primarily, @var{options} specifies the operations to be performed during
eeaf4427 1081the transaction. Upon completion, a new profile is created, but
99bd74d5 1082previous @dfn{generations} of the profile remain available, should the user
eeaf4427
LC
1083want to roll back.
1084
6447738c
MW
1085For example, to remove @code{lua} and install @code{guile} and
1086@code{guile-cairo} in a single transaction:
1087
1088@example
1089guix package -r lua -i guile guile-cairo
1090@end example
1091
99bd74d5
LC
1092@command{guix package} also supports a @dfn{declarative approach}
1093whereby the user specifies the exact set of packages to be available and
1094passes it @i{via} the @option{--manifest} option
1095(@pxref{profile-manifest, @option{--manifest}}).
1096
b9e5c0a9 1097For each user, a symlink to the user's default profile is automatically
0ec1af59 1098created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
1099current generation of the user's default profile. Thus, users can add
1100@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1101variable, and so on.
d664f1b4
LC
1102@cindex search paths
1103If you are not using the Guix System Distribution, consider adding the
1104following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1105Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1106shells get all the right environment variable definitions:
1107
1108@example
1109GUIX_PROFILE="$HOME/.guix-profile" \
1110source "$HOME/.guix-profile/etc/profile"
1111@end example
b9e5c0a9 1112
4379c35b
LC
1113In a multi-user setup, user profiles are stored in a place registered as
1114a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1115to (@pxref{Invoking guix gc}). That directory is normally
0ec1af59
LC
1116@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1117@var{localstatedir} is the value passed to @code{configure} as
4379c35b
LC
1118@code{--localstatedir}, and @var{user} is the user name. The
1119@file{per-user} directory is created when @command{guix-daemon} is
1120started, and the @var{user} sub-directory is created by @command{guix
1121package}.
0ec1af59
LC
1122
1123The @var{options} can be among the following:
1124
eeaf4427
LC
1125@table @code
1126
6447738c
MW
1127@item --install=@var{package} @dots{}
1128@itemx -i @var{package} @dots{}
1129Install the specified @var{package}s.
eeaf4427 1130
6447738c 1131Each @var{package} may specify either a simple package name, such as
eeaf4427 1132@code{guile}, or a package name followed by a hyphen and version number,
724311a2
LC
1133such as @code{guile-1.8.8} or simply @code{guile-1.8} (in the latter
1134case, the newest version prefixed by @code{1.8} is selected.)
1135
1136If no version number is specified, the
dc5669cd
MW
1137newest available version will be selected. In addition, @var{package}
1138may contain a colon, followed by the name of one of the outputs of the
6e721c4d 1139package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
e7f34eb0
LC
1140(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1141name (and optionally version) are searched for among the GNU
1142distribution modules (@pxref{Package Modules}).
eeaf4427 1143
461572cc
LC
1144@cindex propagated inputs
1145Sometimes packages have @dfn{propagated inputs}: these are dependencies
21461f27
LC
1146that automatically get installed along with the required package
1147(@pxref{package-propagated-inputs, @code{propagated-inputs} in
1148@code{package} objects}, for information about propagated inputs in
1149package definitions).
461572cc 1150
21461f27 1151@anchor{package-cmd-propagated-inputs}
461572cc
LC
1152An example is the GNU MPC library: its C header files refer to those of
1153the GNU MPFR library, which in turn refer to those of the GMP library.
1154Thus, when installing MPC, the MPFR and GMP libraries also get installed
1155in the profile; removing MPC also removes MPFR and GMP---unless they had
1156also been explicitly installed independently.
1157
ba7ea5ce 1158Besides, packages sometimes rely on the definition of environment
5924080d 1159variables for their search paths (see explanation of
ba7ea5ce 1160@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
1161environment variable definitions are reported here.
1162
ef010c0f 1163@c XXX: keep me up-to-date
5924080d 1164Finally, when installing a GNU package, the tool reports the
ef010c0f
LC
1165availability of a newer upstream version. In the future, it may provide
1166the option of installing directly from the upstream version, even if
1167that version is not yet in the distribution.
1168
5d4b411f
LC
1169@item --install-from-expression=@var{exp}
1170@itemx -e @var{exp}
1171Install the package @var{exp} evaluates to.
1172
1173@var{exp} must be a Scheme expression that evaluates to a
1174@code{<package>} object. This option is notably useful to disambiguate
1175between same-named variants of a package, with expressions such as
1176@code{(@@ (gnu packages base) guile-final)}.
1177
1178Note that this option installs the first output of the specified
1179package, which may be insufficient when needing a specific output of a
1180multiple-output package.
1181
0d279400
DT
1182@item --install-from-file=@var{file}
1183@itemx -f @var{file}
1184Install the package that the code within @var{file} evaluates to.
1185
1186As an example, @var{file} might contain a definition like this
1187(@pxref{Defining Packages}):
1188
1189@example
1190@verbatiminclude package-hello.scm
1191@end example
1192
1193Developers may find it useful to include such a @file{package.scm} file
1194in the root of their project's source tree that can be used to test
1195development snapshots and create reproducible development environments
1196(@pxref{Invoking guix environment}).
1197
6447738c
MW
1198@item --remove=@var{package} @dots{}
1199@itemx -r @var{package} @dots{}
1200Remove the specified @var{package}s.
eeaf4427 1201
6447738c 1202As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
1203and/or output name in addition to the package name. For instance,
1204@code{-r glibc:debug} would remove the @code{debug} output of
1205@code{glibc}.
1206
6447738c
MW
1207@item --upgrade[=@var{regexp} @dots{}]
1208@itemx -u [@var{regexp} @dots{}]
1209Upgrade all the installed packages. If one or more @var{regexp}s are
1210specified, upgrade only installed packages whose name matches a
d5f01e48 1211@var{regexp}. Also see the @code{--do-not-upgrade} option below.
eeaf4427 1212
f651b477
LC
1213Note that this upgrades package to the latest version of packages found
1214in the distribution currently installed. To update your distribution,
1215you should regularly run @command{guix pull} (@pxref{Invoking guix
1216pull}).
1217
d5f01e48
MW
1218@item --do-not-upgrade[=@var{regexp} @dots{}]
1219When used together with the @code{--upgrade} option, do @emph{not}
1220upgrade any packages whose name matches a @var{regexp}. For example, to
1221upgrade all packages in the current profile except those containing the
1222substring ``emacs'':
1223
1224@example
1225$ guix package --upgrade . --do-not-upgrade emacs
1226@end example
1227
99bd74d5 1228@item @anchor{profile-manifest}--manifest=@var{file}
1b676447 1229@itemx -m @var{file}
99bd74d5
LC
1230@cindex profile declaration
1231@cindex profile manifest
1232Create a new generation of the profile from the manifest object
1b676447
DT
1233returned by the Scheme code in @var{file}.
1234
99bd74d5
LC
1235This allows you to @emph{declare} the profile's contents rather than
1236constructing it through a sequence of @code{--install} and similar
1237commands. The advantage is that @var{file} can be put under version
1238control, copied to different machines to reproduce the same profile, and
1239so on.
1240
1241@c FIXME: Add reference to (guix profile) documentation when available.
1242@var{file} must return a @dfn{manifest} object, which is roughly a list
1243of packages:
1b676447 1244
99bd74d5 1245@findex packages->manifest
1b676447 1246@example
99bd74d5 1247(use-package-modules guile emacs)
1b676447
DT
1248
1249(packages->manifest
99bd74d5
LC
1250 (list emacs
1251 guile-2.0
1b676447 1252 ;; Use a specific package output.
99bd74d5 1253 (list guile-2.0 "debug")))
1b676447
DT
1254@end example
1255
24e262f0
LC
1256@item --roll-back
1257Roll back to the previous @dfn{generation} of the profile---i.e., undo
1258the last transaction.
1259
1260When combined with options such as @code{--install}, roll back occurs
1261before any other actions.
1262
d9307267 1263When rolling back from the first generation that actually contains
4b2bc804
NK
1264installed packages, the profile is made to point to the @dfn{zeroth
1265generation}, which contains no files apart from its own meta-data.
d9307267 1266
82fe08ed
LC
1267Installing, removing, or upgrading packages from a generation that has
1268been rolled back to overwrites previous future generations. Thus, the
1269history of a profile's generations is always linear.
1270
b3bb82f1
AK
1271@item --switch-generation=@var{pattern}
1272@itemx -S @var{pattern}
1273Switch to a particular generation defined by @var{pattern}.
1274
1275@var{pattern} may be either a generation number or a number prefixed
1276with ``+'' or ``-''. The latter means: move forward/backward by a
1277specified number of generations. For example, if you want to return to
1278the latest generation after @code{--roll-back}, use
1279@code{--switch-generation=+1}.
1280
1281The difference between @code{--roll-back} and
1282@code{--switch-generation=-1} is that @code{--switch-generation} will
1283not make a zeroth generation, so if a specified generation does not
1284exist, the current generation will not be changed.
1285
dbc31ab2 1286@item --search-paths[=@var{kind}]
5924080d
LC
1287@cindex search paths
1288Report environment variable definitions, in Bash syntax, that may be
1289needed in order to use the set of installed packages. These environment
1290variables are used to specify @dfn{search paths} for files used by some
1291of the installed packages.
1292
1293For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1294environment variables to be defined so it can look for headers and
1295libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1296Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1297library are installed in the profile, then @code{--search-paths} will
1298suggest setting these variables to @code{@var{profile}/include} and
1299@code{@var{profile}/lib}, respectively.
1300
dbc31ab2
LC
1301The typical use case is to define these environment variables in the
1302shell:
1303
1304@example
1305$ eval `guix package --search-paths`
1306@end example
1307
1308@var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1309meaning that the returned environment variable definitions will either
1310be exact settings, or prefixes or suffixes of the current value of these
1311variables. When omitted, @var{kind} defaults to @code{exact}.
1312
eeaf4427
LC
1313@item --profile=@var{profile}
1314@itemx -p @var{profile}
1315Use @var{profile} instead of the user's default profile.
1316
70915c1a
LC
1317@item --verbose
1318Produce verbose output. In particular, emit the environment's build log
1319on the standard error port.
1320
eeaf4427
LC
1321@item --bootstrap
1322Use the bootstrap Guile to build the profile. This option is only
1323useful to distribution developers.
1324
1325@end table
1326
e49951eb 1327In addition to these actions @command{guix package} supports the
733b4130
LC
1328following options to query the current state of a profile, or the
1329availability of packages:
eeaf4427 1330
733b4130
LC
1331@table @option
1332
acc08466
NK
1333@item --search=@var{regexp}
1334@itemx -s @var{regexp}
5763ad92 1335List the available packages whose name, synopsis, or description matches
299112d3
LC
1336@var{regexp}. Print all the meta-data of matching packages in
1337@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1338GNU recutils manual}).
acc08466 1339
299112d3
LC
1340This allows specific fields to be extracted using the @command{recsel}
1341command, for instance:
1342
1343@example
e49951eb 1344$ guix package -s malloc | recsel -p name,version
299112d3
LC
1345name: glibc
1346version: 2.17
1347
1348name: libgc
1349version: 7.2alpha6
1350@end example
acc08466 1351
a12d92f5
LC
1352Similarly, to show the name of all the packages available under the
1353terms of the GNU@tie{}LGPL version 3:
1354
1355@example
1356$ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1357name: elfutils
1358
1359name: gmp
1360@dots{}
1361@end example
1362
2aa6efb0
CR
1363@item --show=@var{package}
1364Show details about @var{package}, taken from the list of available packages, in
1365@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1366recutils manual}).
1367
1368@example
1369$ guix package --show=python | recsel -p name,version
1370name: python
1371version: 2.7.6
1372
1373name: python
1374version: 3.3.5
1375@end example
1376
1377You may also specify the full name of a package to only get details about a
1378specific version of it:
1379@example
1380$ guix package --show=python-3.3.5 | recsel -p name,version
1381name: python
1382version: 3.3.5
1383@end example
1384
1385
1386
733b4130
LC
1387@item --list-installed[=@var{regexp}]
1388@itemx -I [@var{regexp}]
bd9bde1c
LC
1389List the currently installed packages in the specified profile, with the
1390most recently installed packages shown last. When @var{regexp} is
1391specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
1392
1393For each installed package, print the following items, separated by
1394tabs: the package name, its version string, the part of the package that
1395is installed (for instance, @code{out} for the default output,
1396@code{include} for its headers, etc.), and the path of this package in
1397the store.
1398
64fc89b6
LC
1399@item --list-available[=@var{regexp}]
1400@itemx -A [@var{regexp}]
5763ad92 1401List packages currently available in the distribution for this system
a1ba8475
LC
1402(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1403installed packages whose name matches @var{regexp}.
64fc89b6
LC
1404
1405For each package, print the following items separated by tabs: its name,
6e721c4d
LC
1406its version string, the parts of the package (@pxref{Packages with
1407Multiple Outputs}), and the source location of its definition.
64fc89b6 1408
f566d765
LC
1409@item --list-generations[=@var{pattern}]
1410@itemx -l [@var{pattern}]
1411Return a list of generations along with their creation dates; for each
1412generation, show the installed packages, with the most recently
4b2bc804
NK
1413installed packages shown last. Note that the zeroth generation is never
1414shown.
f566d765
LC
1415
1416For each installed package, print the following items, separated by
1417tabs: the name of a package, its version string, the part of the package
1418that is installed (@pxref{Packages with Multiple Outputs}), and the
1419location of this package in the store.
1420
1421When @var{pattern} is used, the command returns only matching
1422generations. Valid patterns include:
1423
1424@itemize
1425@item @emph{Integers and comma-separated integers}. Both patterns denote
1426generation numbers. For instance, @code{--list-generations=1} returns
1427the first one.
1428
1429And @code{--list-generations=1,8,2} outputs three generations in the
1430specified order. Neither spaces nor trailing commas are allowed.
1431
1432@item @emph{Ranges}. @code{--list-generations=2..9} prints the
1433specified generations and everything in between. Note that the start of
1434a range must be lesser than its end.
1435
1436It is also possible to omit the endpoint. For example,
1437@code{--list-generations=2..}, returns all generations starting from the
1438second one.
1439
1440@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1441or months by passing an integer along with the first letter of the
d7ddb257
LC
1442duration. For example, @code{--list-generations=20d} lists generations
1443that are up to 20 days old.
f566d765
LC
1444@end itemize
1445
b7884ca3
NK
1446@item --delete-generations[=@var{pattern}]
1447@itemx -d [@var{pattern}]
d7ddb257
LC
1448When @var{pattern} is omitted, delete all generations except the current
1449one.
b7884ca3
NK
1450
1451This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
1452When @var{pattern} is specified, delete the matching generations. When
1453@var{pattern} specifies a duration, generations @emph{older} than the
1454specified duration match. For instance, @code{--delete-generations=1m}
1455deletes generations that are more than one month old.
1456
391bdd8f
LC
1457If the current generation matches, it is @emph{not} deleted. Also, the
1458zeroth generation is never deleted.
b7884ca3 1459
1bb9900a
LC
1460Note that deleting generations prevents roll-back to them.
1461Consequently, this command must be used with care.
1462
733b4130 1463@end table
eeaf4427 1464
70ee5642
LC
1465Finally, since @command{guix package} may actually start build
1466processes, it supports all the common build options that @command{guix
1467build} supports (@pxref{Invoking guix build, common build options}).
1468
c4202d60
LC
1469@node Substitutes
1470@section Substitutes
1471
1472@cindex substitutes
1473@cindex pre-built binaries
1474Guix supports transparent source/binary deployment, which means that it
1475can either build things locally, or download pre-built items from a
1476server. We call these pre-built items @dfn{substitutes}---they are
1477substitutes for local build results. In many cases, downloading a
1478substitute is much faster than building things locally.
1479
1480Substitutes can be anything resulting from a derivation build
1481(@pxref{Derivations}). Of course, in the common case, they are
1482pre-built package binaries, but source tarballs, for instance, which
1483also result from derivation builds, can be available as substitutes.
1484
1485The @code{hydra.gnu.org} server is a front-end to a build farm that
1486builds packages from the GNU distribution continuously for some
9176607e 1487architectures, and makes them available as substitutes. This is the
f8a8e0fe
LC
1488default source of substitutes; it can be overridden by passing the
1489@option{--substitute-urls} option either to @command{guix-daemon}
1490(@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1491or to client tools such as @command{guix package}
1492(@pxref{client-substitute-urls,, client @option{--substitute-urls}
1493option}).
c4202d60
LC
1494
1495@cindex security
1496@cindex digital signatures
1497To allow Guix to download substitutes from @code{hydra.gnu.org}, you
1498must add its public key to the access control list (ACL) of archive
1499imports, using the @command{guix archive} command (@pxref{Invoking guix
1500archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1501be compromised and to serve genuine substitutes.
1502
1503This public key is installed along with Guix, in
1504@code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1505the installation prefix of Guix. If you installed Guix from source,
1506make sure you checked the GPG signature of
1507@file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1508Then, you can run something like this:
1509
1510@example
1511# guix archive --authorize < hydra.gnu.org.pub
1512@end example
1513
1514Once this is in place, the output of a command like @code{guix build}
1515should change from something like:
1516
1517@example
1518$ guix build emacs --dry-run
1519The following derivations would be built:
1520 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1521 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1522 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1523 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1524@dots{}
1525@end example
1526
1527@noindent
1528to something like:
1529
1530@example
1531$ guix build emacs --dry-run
1532The following files would be downloaded:
1533 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1534 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1535 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1536 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1537@dots{}
1538@end example
1539
1540@noindent
1541This indicates that substitutes from @code{hydra.gnu.org} are usable and
1542will be downloaded, when possible, for future builds.
1543
1544Guix ignores substitutes that are not signed, or that are not signed by
ef27aa9c 1545one of the keys listed in the ACL. It also detects and raises an error
c4202d60
LC
1546when attempting to use a substitute that has been tampered with.
1547
1548The substitute mechanism can be disabled globally by running
1549@code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1550guix-daemon}). It can also be disabled temporarily by passing the
1551@code{--no-substitutes} option to @command{guix package}, @command{guix
1552build}, and other command-line tools.
1553
1554
1555Today, each individual's control over their own computing is at the
1556mercy of institutions, corporations, and groups with enough power and
1557determination to subvert the computing infrastructure and exploit its
1558weaknesses. While using @code{hydra.gnu.org} substitutes can be
1559convenient, we encourage users to also build on their own, or even run
1560their own build farm, such that @code{hydra.gnu.org} is less of an
8ce229fc
LC
1561interesting target. One way to help is by publishing the software you
1562build using @command{guix publish} so that others have one more choice
1563of server to download substitutes from (@pxref{Invoking guix publish}).
c4202d60
LC
1564
1565Guix has the foundations to maximize build reproducibility
1566(@pxref{Features}). In most cases, independent builds of a given
1567package or derivation should yield bit-identical results. Thus, through
1568a diverse set of independent package builds, we can strengthen the
1569integrity of our systems.
1570
1571In the future, we want Guix to have support to publish and retrieve
1572binaries to/from other users, in a peer-to-peer fashion. If you would
1573like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1574
1575
6e721c4d
LC
1576@node Packages with Multiple Outputs
1577@section Packages with Multiple Outputs
1578
1579@cindex multiple-output packages
1580@cindex package outputs
1581
1582Often, packages defined in Guix have a single @dfn{output}---i.e., the
1583source package leads exactly one directory in the store. When running
1584@command{guix package -i glibc}, one installs the default output of the
1585GNU libc package; the default output is called @code{out}, but its name
1586can be omitted as shown in this command. In this particular case, the
1587default output of @code{glibc} contains all the C header files, shared
1588libraries, static libraries, Info documentation, and other supporting
1589files.
1590
1591Sometimes it is more appropriate to separate the various types of files
1592produced from a single source package into separate outputs. For
1593instance, the GLib C library (used by GTK+ and related packages)
1594installs more than 20 MiB of reference documentation as HTML pages.
1595To save space for users who do not need it, the documentation goes to a
1596separate output, called @code{doc}. To install the main GLib output,
1597which contains everything but the documentation, one would run:
1598
1599@example
1600guix package -i glib
1601@end example
1602
1603The command to install its documentation is:
1604
1605@example
1606guix package -i glib:doc
1607@end example
1608
1609Some packages install programs with different ``dependency footprints''.
1610For instance, the WordNet package install both command-line tools and
1611graphical user interfaces (GUIs). The former depend solely on the C
1612library, whereas the latter depend on Tcl/Tk and the underlying X
1613libraries. In this case, we leave the command-line tools in the default
1614output, whereas the GUIs are in a separate output. This allows users
fcc58db6
LC
1615who do not need the GUIs to save space. The @command{guix size} command
1616can help find out about such situations (@pxref{Invoking guix size}).
88856916 1617@command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
6e721c4d
LC
1618
1619There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
1620Other conventional output names include @code{lib} for libraries and
1621possibly header files, @code{bin} for stand-alone programs, and
1622@code{debug} for debugging information (@pxref{Installing Debugging
1623Files}). The outputs of a packages are listed in the third column of
1624the output of @command{guix package --list-available} (@pxref{Invoking
1625guix package}).
6e721c4d 1626
eeaf4427 1627
e49951eb
MW
1628@node Invoking guix gc
1629@section Invoking @command{guix gc}
fe8ff028
LC
1630
1631@cindex garbage collector
1632Packages that are installed but not used may be @dfn{garbage-collected}.
e49951eb 1633The @command{guix gc} command allows users to explicitly run the garbage
c22eb992
LC
1634collector to reclaim space from the @file{/gnu/store} directory. It is
1635the @emph{only} way to remove files from @file{/gnu/store}---removing
1636files or directories manually may break it beyond repair!
fe8ff028
LC
1637
1638The garbage collector has a set of known @dfn{roots}: any file under
834129e0 1639@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
1640cannot be deleted; any other file is considered @dfn{dead} and may be
1641deleted. The set of garbage collector roots includes default user
e49951eb
MW
1642profiles, and may be augmented with @command{guix build --root}, for
1643example (@pxref{Invoking guix build}).
fe8ff028 1644
1bb9900a
LC
1645Prior to running @code{guix gc --collect-garbage} to make space, it is
1646often useful to remove old generations from user profiles; that way, old
1647package builds referenced by those generations can be reclaimed. This
1648is achieved by running @code{guix package --delete-generations}
1649(@pxref{Invoking guix package}).
1650
e49951eb 1651The @command{guix gc} command has three modes of operation: it can be
fe8ff028 1652used to garbage-collect any dead files (the default), to delete specific
7770aafc
LC
1653files (the @code{--delete} option), to print garbage-collector
1654information, or for more advanced queries. The garbage collection
1655options are as follows:
fe8ff028
LC
1656
1657@table @code
1658@item --collect-garbage[=@var{min}]
1659@itemx -C [@var{min}]
834129e0 1660Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
1661sub-directories. This is the default operation when no option is
1662specified.
1663
1664When @var{min} is given, stop once @var{min} bytes have been collected.
1665@var{min} may be a number of bytes, or it may include a unit as a
4a44d7bb
LC
1666suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
1667(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
fe8ff028
LC
1668
1669When @var{min} is omitted, collect all the garbage.
1670
1671@item --delete
1672@itemx -d
1673Attempt to delete all the store files and directories specified as
1674arguments. This fails if some of the files are not in the store, or if
1675they are still live.
1676
1677@item --list-dead
1678Show the list of dead files and directories still present in the
1679store---i.e., files and directories no longer reachable from any root.
1680
1681@item --list-live
1682Show the list of live store files and directories.
ba8b732d
LC
1683
1684@end table
1685
1686In addition, the references among existing store files can be queried:
1687
1688@table @code
1689
1690@item --references
1691@itemx --referrers
1692List the references (respectively, the referrers) of store files given
1693as arguments.
1694
8e59fdd5
LC
1695@item --requisites
1696@itemx -R
fcc58db6 1697@cindex closure
8e59fdd5
LC
1698List the requisites of the store files passed as arguments. Requisites
1699include the store files themselves, their references, and the references
1700of these, recursively. In other words, the returned list is the
1701@dfn{transitive closure} of the store files.
1702
fcc58db6 1703@xref{Invoking guix size}, for a tool to profile the size of an
88856916
LC
1704element's closure. @xref{Invoking guix graph}, for a tool to visualize
1705the graph of references.
fcc58db6 1706
fe8ff028
LC
1707@end table
1708
7770aafc
LC
1709Lastly, the following options allow you to check the integrity of the
1710store and to control disk usage.
1711
1712@table @option
1713
1714@item --verify[=@var{options}]
1715@cindex integrity, of the store
1716@cindex integrity checking
1717Verify the integrity of the store.
1718
1719By default, make sure that all the store items marked as valid in the
1720daemon's database actually exist in @file{/gnu/store}.
1721
1722When provided, @var{options} must a comma-separated list containing one
1723or more of @code{contents} and @code{repair}.
1724
1725When passing @option{--verify=contents}, the daemon will compute the
1726content hash of each store item and compare it against its hash in the
1727database. Hash mismatches are reported as data corruptions. Because it
1728traverses @emph{all the files in the store}, this command can take a
1729long time, especially on systems with a slow disk drive.
1730
1731@cindex repairing the store
1732Using @option{--verify=repair} or @option{--verify=contents,repair}
1733causes the daemon to try to repair corrupt store items by fetching
1734substitutes for them (@pxref{Substitutes}). Because repairing is not
1735atomic, and thus potentially dangerous, it is available only to the
1736system administrator.
1737
1738@item --optimize
1739@cindex deduplication
1740Optimize the store by hard-linking identical files---this is
1741@dfn{deduplication}.
1742
1743The daemon performs deduplication after each successful build or archive
1744import, unless it was started with @code{--disable-deduplication}
1745(@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
1746this option is primarily useful when the daemon was running with
1747@code{--disable-deduplication}.
1748
1749@end table
eeaf4427 1750
f651b477
LC
1751@node Invoking guix pull
1752@section Invoking @command{guix pull}
1753
1754Packages are installed or upgraded to the latest version available in
1755the distribution currently available on your local machine. To update
1756that distribution, along with the Guix tools, you must run @command{guix
1757pull}: the command downloads the latest Guix source code and package
1758descriptions, and deploys it.
1759
1760On completion, @command{guix package} will use packages and package
1761versions from this just-retrieved copy of Guix. Not only that, but all
1762the Guix commands and Scheme modules will also be taken from that latest
1763version. New @command{guix} sub-commands added by the update also
1764become available.
1765
1766The @command{guix pull} command is usually invoked with no arguments,
1767but it supports the following options:
1768
1769@table @code
1770@item --verbose
1771Produce verbose output, writing build logs to the standard error output.
1772
ab5d72ad
LC
1773@item --url=@var{url}
1774Download the source tarball of Guix from @var{url}.
1775
1776By default, the tarball is taken from its canonical address at
1777@code{gnu.org}, for the stable branch of Guix.
1778
f651b477
LC
1779@item --bootstrap
1780Use the bootstrap Guile to build the latest Guix. This option is only
1781useful to Guix developers.
1782@end table
1783
760c60d6
LC
1784
1785@node Invoking guix archive
1786@section Invoking @command{guix archive}
1787
1788The @command{guix archive} command allows users to @dfn{export} files
1789from the store into a single archive, and to later @dfn{import} them.
1790In particular, it allows store files to be transferred from one machine
1791to another machine's store. For example, to transfer the @code{emacs}
1792package to a machine connected over SSH, one would run:
1793
1794@example
56607088 1795guix archive --export -r emacs | ssh the-machine guix archive --import
760c60d6
LC
1796@end example
1797
87236aed 1798@noindent
56607088
LC
1799Similarly, a complete user profile may be transferred from one machine
1800to another like this:
1801
1802@example
1803guix archive --export -r $(readlink -f ~/.guix-profile) | \
1804 ssh the-machine guix-archive --import
1805@end example
1806
1807@noindent
1808However, note that, in both examples, all of @code{emacs} and the
1809profile as well as all of their dependencies are transferred (due to
1810@code{-r}), regardless of what is already available in the target
1811machine's store. The @code{--missing} option can help figure out which
1812items are missing from the target's store.
87236aed 1813
760c60d6 1814Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
0dbd88db
LC
1815comparable in spirit to `tar', but with a few noteworthy differences
1816that make it more appropriate for our purposes. First, rather than
1817recording all Unix meta-data for each file, the Nar format only mentions
1818the file type (regular, directory, or symbolic link); Unix permissions
1819and owner/group are dismissed. Second, the order in which directory
1820entries are stored always follows the order of file names according to
1821the C locale collation order. This makes archive production fully
1822deterministic.
1823
1824When exporting, the daemon digitally signs the contents of the archive,
1825and that digital signature is appended. When importing, the daemon
1826verifies the signature and rejects the import in case of an invalid
1827signature or if the signing key is not authorized.
760c60d6
LC
1828@c FIXME: Add xref to daemon doc about signatures.
1829
1830The main options are:
1831
1832@table @code
1833@item --export
1834Export the specified store files or packages (see below.) Write the
1835resulting archive to the standard output.
1836
56607088
LC
1837Dependencies are @emph{not} included in the output, unless
1838@code{--recursive} is passed.
1839
1840@item -r
1841@itemx --recursive
1842When combined with @code{--export}, this instructs @command{guix
1843archive} to include dependencies of the given items in the archive.
1844Thus, the resulting archive is self-contained: it contains the closure
1845of the exported store items.
1846
760c60d6
LC
1847@item --import
1848Read an archive from the standard input, and import the files listed
1849therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
1850signature, or if it is signed by a public key not among the authorized
1851keys (see @code{--authorize} below.)
554f26ec 1852
87236aed
LC
1853@item --missing
1854Read a list of store file names from the standard input, one per line,
1855and write on the standard output the subset of these files missing from
1856the store.
1857
554f26ec 1858@item --generate-key[=@var{parameters}]
f82cc5fd 1859@cindex signing, archives
554f26ec
LC
1860Generate a new key pair for the daemons. This is a prerequisite before
1861archives can be exported with @code{--export}. Note that this operation
1862usually takes time, because it needs to gather enough entropy to
1863generate the key pair.
1864
1865The generated key pair is typically stored under @file{/etc/guix}, in
1866@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
867d8473
LC
1867key, which must be kept secret.) When @var{parameters} is omitted,
1868an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
1869versions before 1.6.0, it is a 4096-bit RSA key.
1870Alternately, @var{parameters} can specify
554f26ec
LC
1871@code{genkey} parameters suitable for Libgcrypt (@pxref{General
1872public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
1873Libgcrypt Reference Manual}).
f82cc5fd
LC
1874
1875@item --authorize
1876@cindex authorizing, archives
1877Authorize imports signed by the public key passed on standard input.
1878The public key must be in ``s-expression advanced format''---i.e., the
1879same format as the @file{signing-key.pub} file.
1880
1881The list of authorized keys is kept in the human-editable file
1882@file{/etc/guix/acl}. The file contains
1883@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
1884s-expressions''} and is structured as an access-control list in the
1885@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
1886(SPKI)}.
760c60d6
LC
1887@end table
1888
1889To export store files as an archive to the standard output, run:
1890
1891@example
1892guix archive --export @var{options} @var{specifications}...
1893@end example
1894
1895@var{specifications} may be either store file names or package
1896specifications, as for @command{guix package} (@pxref{Invoking guix
1897package}). For instance, the following command creates an archive
1898containing the @code{gui} output of the @code{git} package and the main
1899output of @code{emacs}:
1900
1901@example
834129e0 1902guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
760c60d6
LC
1903@end example
1904
1905If the specified packages are not built yet, @command{guix archive}
1906automatically builds them. The build process may be controlled with the
1907same options that can be passed to the @command{guix build} command
70ee5642 1908(@pxref{Invoking guix build, common build options}).
760c60d6 1909
c554de89
AK
1910@c *********************************************************************
1911@include emacs.texi
760c60d6 1912
568717fd
LC
1913@c *********************************************************************
1914@node Programming Interface
1915@chapter Programming Interface
1916
3dc1970d
LC
1917GNU Guix provides several Scheme programming interfaces (APIs) to
1918define, build, and query packages. The first interface allows users to
1919write high-level package definitions. These definitions refer to
1920familiar packaging concepts, such as the name and version of a package,
1921its build system, and its dependencies. These definitions can then be
1922turned into concrete build actions.
1923
ba55b1cb 1924Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 1925standard setup, the daemon has write access to the store---the
834129e0 1926@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
1927setup also has the daemon perform builds in chroots, under a specific
1928build users, to minimize interference with the rest of the system.
1929
1930@cindex derivation
1931Lower-level APIs are available to interact with the daemon and the
1932store. To instruct the daemon to perform a build action, users actually
1933provide it with a @dfn{derivation}. A derivation is a low-level
1934representation of the build actions to be taken, and the environment in
1935which they should occur---derivations are to package definitions what
49ad317a
LC
1936assembly is to C programs. The term ``derivation'' comes from the fact
1937that build results @emph{derive} from them.
3dc1970d
LC
1938
1939This chapter describes all these APIs in turn, starting from high-level
1940package definitions.
1941
568717fd 1942@menu
b860f382 1943* Defining Packages:: Defining new packages.
7458bd0a 1944* Build Systems:: Specifying how packages are built.
b860f382
LC
1945* The Store:: Manipulating the package store.
1946* Derivations:: Low-level interface to package derivations.
1947* The Store Monad:: Purely functional interface to the store.
21b679f6 1948* G-Expressions:: Manipulating build expressions.
568717fd
LC
1949@end menu
1950
1951@node Defining Packages
1952@section Defining Packages
1953
3dc1970d
LC
1954The high-level interface to package definitions is implemented in the
1955@code{(guix packages)} and @code{(guix build-system)} modules. As an
1956example, the package definition, or @dfn{recipe}, for the GNU Hello
1957package looks like this:
1958
1959@example
e7f34eb0
LC
1960(define-module (gnu packages hello)
1961 #:use-module (guix packages)
1962 #:use-module (guix download)
1963 #:use-module (guix build-system gnu)
a6dcdcac
SB
1964 #:use-module (guix licenses)
1965 #:use-module (gnu packages gawk))
b22a12fd 1966
79f5dd59 1967(define-public hello
3dc1970d
LC
1968 (package
1969 (name "hello")
17d8e33f 1970 (version "2.10")
3dc1970d 1971 (source (origin
17d8e33f
ML
1972 (method url-fetch)
1973 (uri (string-append "mirror://gnu/hello/hello-" version
1974 ".tar.gz"))
1975 (sha256
1976 (base32
1977 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
3dc1970d 1978 (build-system gnu-build-system)
7458bd0a 1979 (arguments `(#:configure-flags '("--enable-silent-rules")))
3dc1970d 1980 (inputs `(("gawk" ,gawk)))
7458bd0a
LC
1981 (synopsis "Hello, GNU world: An example GNU package")
1982 (description "Guess what GNU Hello prints!")
3dc1970d 1983 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 1984 (license gpl3+)))
3dc1970d
LC
1985@end example
1986
1987@noindent
1988Without being a Scheme expert, the reader may have guessed the meaning
e7f34eb0 1989of the various fields here. This expression binds variable @code{hello}
3dc1970d
LC
1990to a @code{<package>} object, which is essentially a record
1991(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
1992This package object can be inspected using procedures found in the
1993@code{(guix packages)} module; for instance, @code{(package-name hello)}
1994returns---surprise!---@code{"hello"}.
1995
2f7d2d91
LC
1996With luck, you may be able to import part or all of the definition of
1997the package you are interested in from another repository, using the
1998@code{guix import} command (@pxref{Invoking guix import}).
1999
e7f34eb0
LC
2000In the example above, @var{hello} is defined into a module of its own,
2001@code{(gnu packages hello)}. Technically, this is not strictly
2002necessary, but it is convenient to do so: all the packages defined in
2003modules under @code{(gnu packages @dots{})} are automatically known to
2004the command-line tools (@pxref{Package Modules}).
2005
3dc1970d
LC
2006There are a few points worth noting in the above package definition:
2007
2008@itemize
2009@item
a2bf4907
LC
2010The @code{source} field of the package is an @code{<origin>} object
2011(@pxref{origin Reference}, for the complete reference).
3dc1970d
LC
2012Here, the @code{url-fetch} method from @code{(guix download)} is used,
2013meaning that the source is a file to be downloaded over FTP or HTTP.
2014
2015The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2016the GNU mirrors defined in @code{(guix download)}.
2017
2018The @code{sha256} field specifies the expected SHA256 hash of the file
2019being downloaded. It is mandatory, and allows Guix to check the
2020integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 2021base32 representation of the hash. You can obtain this information with
210cc920
LC
2022@code{guix download} (@pxref{Invoking guix download}) and @code{guix
2023hash} (@pxref{Invoking guix hash}).
3dc1970d 2024
f9cc8971
LC
2025@cindex patches
2026When needed, the @code{origin} form can also have a @code{patches} field
2027listing patches to be applied, and a @code{snippet} field giving a
2028Scheme expression to modify the source code.
2029
3dc1970d
LC
2030@item
2031@cindex GNU Build System
7458bd0a
LC
2032The @code{build-system} field specifies the procedure to build the
2033package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2034represents the familiar GNU Build System, where packages may be
2035configured, built, and installed with the usual @code{./configure &&
2036make && make check && make install} command sequence.
2037
2038@item
2039The @code{arguments} field specifies options for the build system
2040(@pxref{Build Systems}). Here it is interpreted by
2041@var{gnu-build-system} as a request run @file{configure} with the
2042@code{--enable-silent-rules} flag.
3dc1970d
LC
2043
2044@item
2045The @code{inputs} field specifies inputs to the build process---i.e.,
2046build-time or run-time dependencies of the package. Here, we define an
2047input called @code{"gawk"} whose value is that of the @var{gawk}
2048variable; @var{gawk} is itself bound to a @code{<package>} object.
2049
2050Note that GCC, Coreutils, Bash, and other essential tools do not need to
2051be specified as inputs here. Instead, @var{gnu-build-system} takes care
7458bd0a 2052of ensuring that they are present (@pxref{Build Systems}).
3dc1970d
LC
2053
2054However, any other dependencies need to be specified in the
2055@code{inputs} field. Any dependency not specified here will simply be
2056unavailable to the build process, possibly leading to a build failure.
2057@end itemize
2058
87eafdbd
TUBK
2059@xref{package Reference}, for a full description of possible fields.
2060
2f7d2d91 2061Once a package definition is in place, the
e49951eb 2062package may actually be built using the @code{guix build} command-line
39bee8a2
LC
2063tool (@pxref{Invoking guix build}). You can easily jump back to the
2064package definition using the @command{guix edit} command
2065(@pxref{Invoking guix edit}).
2066@xref{Packaging Guidelines}, for
b4f5e0e8
CR
2067more information on how to test package definitions, and
2068@ref{Invoking guix lint}, for information on how to check a definition
2069for style conformance.
2070
7458bd0a
LC
2071Eventually, updating the package definition to a new upstream version
2072can be partly automated by the @command{guix refresh} command
2073(@pxref{Invoking guix refresh}).
3dc1970d
LC
2074
2075Behind the scenes, a derivation corresponding to the @code{<package>}
2076object is first computed by the @code{package-derivation} procedure.
834129e0 2077That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 2078The build actions it prescribes may then be realized by using the
3dc1970d
LC
2079@code{build-derivations} procedure (@pxref{The Store}).
2080
2081@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
2082Return the @code{<derivation>} object of @var{package} for @var{system}
2083(@pxref{Derivations}).
3dc1970d
LC
2084
2085@var{package} must be a valid @code{<package>} object, and @var{system}
2086must be a string denoting the target system type---e.g.,
2087@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2088must be a connection to the daemon, which operates on the store
2089(@pxref{The Store}).
2090@end deffn
568717fd 2091
9c1edabd
LC
2092@noindent
2093@cindex cross-compilation
2094Similarly, it is possible to compute a derivation that cross-builds a
2095package for some other system:
2096
2097@deffn {Scheme Procedure} package-cross-derivation @var{store} @
2098 @var{package} @var{target} [@var{system}]
59688fc4
LC
2099Return the @code{<derivation>} object of @var{package} cross-built from
2100@var{system} to @var{target}.
9c1edabd
LC
2101
2102@var{target} must be a valid GNU triplet denoting the target hardware
2103and operating system, such as @code{"mips64el-linux-gnu"}
2104(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2105Configure and Build System}).
2106@end deffn
2107
87eafdbd
TUBK
2108@menu
2109* package Reference :: The package data type.
2110* origin Reference:: The origin data type.
2111@end menu
2112
2113
2114@node package Reference
2115@subsection @code{package} Reference
2116
2117This section summarizes all the options available in @code{package}
2118declarations (@pxref{Defining Packages}).
2119
2120@deftp {Data Type} package
2121This is the data type representing a package recipe.
2122
2123@table @asis
2124@item @code{name}
2125The name of the package, as a string.
2126
2127@item @code{version}
2128The version of the package, as a string.
2129
2130@item @code{source}
2131An origin object telling how the source code for the package should be
2132acquired (@pxref{origin Reference}).
2133
2134@item @code{build-system}
2135The build system that should be used to build the package (@pxref{Build
2136Systems}).
2137
2138@item @code{arguments} (default: @code{'()})
2139The arguments that should be passed to the build system. This is a
2140list, typically containing sequential keyword-value pairs.
2141
2142@item @code{inputs} (default: @code{'()})
2143Package or derivation inputs to the build. This is a list of lists,
2144where each list has the name of the input (a string) as its first
2145element, a package or derivation object as its second element, and
2146optionally the name of the output of the package or derivation that
2147should be used, which defaults to @code{"out"}.
2148
21461f27
LC
2149@item @anchor{package-propagated-inputs}@code{propagated-inputs} (default: @code{'()})
2150@cindex propagated inputs
87eafdbd 2151This field is like @code{inputs}, but the specified packages will be
21461f27
LC
2152force-installed alongside the package they belong to
2153(@pxref{package-cmd-propagated-inputs, @command{guix package}}, for
2154information on how @command{guix package} deals with propagated inputs.)
2155
2156For example this is necessary when a library needs headers of another
2157library to compile, or needs another shared library to be linked
2158alongside itself when a program wants to link to it.
87eafdbd
TUBK
2159
2160@item @code{native-inputs} (default: @code{'()})
2161This field is like @code{inputs}, but in case of a cross-compilation it
2162will be ensured that packages for the architecture of the build machine
2163are present, such that executables from them can be used during the
21461f27
LC
2164build.
2165
2166This is typically where you would list tools needed at build time but
2167not at run time, such as Autoconf, Automake, pkg-config, Gettext, or
2168Bison. @command{guix lint} can report likely mistakes in this area
2169(@pxref{Invoking guix lint}).
87eafdbd
TUBK
2170
2171@item @code{self-native-input?} (default: @code{#f})
2172This is a Boolean field telling whether the package should use itself as
2173a native input when cross-compiling.
2174
2175@item @code{outputs} (default: @code{'("out")})
2176The list of output names of the package. @xref{Packages with Multiple
2177Outputs}, for typical uses of additional outputs.
2178
2179@item @code{native-search-paths} (default: @code{'()})
2180@itemx @code{search-paths} (default: @code{'()})
2181A list of @code{search-path-specification} objects describing
2182search-path environment variables honored by the package.
2183
2184@item @code{replacement} (default: @code{#f})
2185This must either @code{#f} or a package object that will be used as a
2186@dfn{replacement} for this package. @xref{Security Updates, grafts},
2187for details.
2188
2189@item @code{synopsis}
2190A one-line description of the package.
2191
2192@item @code{description}
2193A more elaborate description of the package.
2194
2195@item @code{license}
2196The license of the package; a value from @code{(guix licenses)}.
2197
2198@item @code{home-page}
2199The URL to the home-page of the package, as a string.
2200
2201@item @code{supported-systems} (default: @var{%supported-systems})
2202The list of systems supported by the package, as strings of the form
2203@code{architecture-kernel}, for example @code{"x86_64-linux"}.
2204
2205@item @code{maintainers} (default: @code{'()})
2206The list of maintainers of the package, as @code{maintainer} objects.
2207
2208@item @code{location} (default: source location of the @code{package} form)
2209The source location of the package. It's useful to override this when
2210inheriting from another package, in which case this field is not
2211automatically corrected.
2212@end table
2213@end deftp
2214
2215
2216@node origin Reference
2217@subsection @code{origin} Reference
2218
2219This section summarizes all the options available in @code{origin}
2220declarations (@pxref{Defining Packages}).
2221
2222@deftp {Data Type} origin
2223This is the data type representing a source code origin.
2224
2225@table @asis
2226@item @code{uri}
2227An object containing the URI of the source. The object type depends on
2228the @code{method} (see below). For example, when using the
2229@var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2230values are: a URL represented as a string, or a list thereof.
2231
2232@item @code{method}
2233A procedure that will handle the URI.
2234
2235Examples include:
2236
2237@table @asis
2238@item @var{url-fetch} from @code{(guix download)}
2239download a file the HTTP, HTTPS, or FTP URL specified in the
2240@code{uri} field;
2241
2242@item @var{git-fetch} from @code{(guix git-download)}
2243clone the Git version control repository, and check out the revision
2244specified in the @code{uri} field as a @code{git-reference} object; a
2245@code{git-reference} looks like this:
2246
2247@example
2248(git-reference
2249 (url "git://git.debian.org/git/pkg-shadow/shadow")
2250 (commit "v4.1.5.1"))
2251@end example
2252@end table
2253
2254@item @code{sha256}
2255A bytevector containing the SHA-256 hash of the source. Typically the
2256@code{base32} form is used here to generate the bytevector from a
2257base-32 string.
2258
2259@item @code{file-name} (default: @code{#f})
2260The file name under which the source code should be saved. When this is
2261@code{#f}, a sensible default value will be used in most cases. In case
2262the source is fetched from a URL, the file name from the URL will be
2263used. For version control checkouts, it's recommended to provide the
2264file name explicitly because the default is not very descriptive.
2265
2266@item @code{patches} (default: @code{'()})
2267A list of file names containing patches to be applied to the source.
2268
2269@item @code{snippet} (default: @code{#f})
2270A quoted piece of code that will be run in the source directory to make
2271any modifications, which is sometimes more convenient than a patch.
2272
2273@item @code{patch-flags} (default: @code{'("-p1")})
2274A list of command-line flags that should be passed to the @code{patch}
2275command.
2276
2277@item @code{patch-inputs} (default: @code{#f})
2278Input packages or derivations to the patching process. When this is
2279@code{#f}, the usual set of inputs necessary for patching are provided,
2280such as GNU@tie{}Patch.
2281
2282@item @code{modules} (default: @code{'()})
2283A list of Guile modules that should be loaded during the patching
2284process and while running the code in the @code{snippet} field.
2285
2286@item @code{imported-modules} (default: @code{'()})
2287The list of Guile modules to import in the patch derivation, for use by
2288the @code{snippet}.
2289
2290@item @code{patch-guile} (default: @code{#f})
2291The Guile package that should be used in the patching process. When
2292this is @code{#f}, a sensible default is used.
2293@end table
2294@end deftp
2295
9c1edabd 2296
7458bd0a
LC
2297@node Build Systems
2298@section Build Systems
2299
2300@cindex build system
2301Each package definition specifies a @dfn{build system} and arguments for
2302that build system (@pxref{Defining Packages}). This @code{build-system}
2303field represents the build procedure of the package, as well implicit
2304dependencies of that build procedure.
2305
2306Build systems are @code{<build-system>} objects. The interface to
2307create and manipulate them is provided by the @code{(guix build-system)}
2308module, and actual build systems are exported by specific modules.
2309
f5fd4fd2 2310@cindex bag (low-level package representation)
0d5a559f
LC
2311Under the hood, build systems first compile package objects to
2312@dfn{bags}. A @dfn{bag} is like a package, but with less
2313ornamentation---in other words, a bag is a lower-level representation of
2314a package, which includes all the inputs of that package, including some
2315that were implicitly added by the build system. This intermediate
2316representation is then compiled to a derivation (@pxref{Derivations}).
2317
7458bd0a
LC
2318Build systems accept an optional list of @dfn{arguments}. In package
2319definitions, these are passed @i{via} the @code{arguments} field
2320(@pxref{Defining Packages}). They are typically keyword arguments
2321(@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
2322Guile Reference Manual}). The value of these arguments is usually
2323evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
2324by the daemon (@pxref{Derivations}).
2325
2326The main build system is @var{gnu-build-system}, which implements the
2327standard build procedure for GNU packages and many other packages. It
2328is provided by the @code{(guix build-system gnu)} module.
2329
2330@defvr {Scheme Variable} gnu-build-system
2331@var{gnu-build-system} represents the GNU Build System, and variants
2332thereof (@pxref{Configuration, configuration and makefile conventions,,
2333standards, GNU Coding Standards}).
2334
2335@cindex build phases
2336In a nutshell, packages using it configured, built, and installed with
2337the usual @code{./configure && make && make check && make install}
2338command sequence. In practice, a few additional steps are often needed.
2339All these steps are split up in separate @dfn{phases},
2340notably@footnote{Please see the @code{(guix build gnu-build-system)}
2341modules for more details about the build phases.}:
2342
2343@table @code
2344@item unpack
2345Unpack the source tarball, and change the current directory to the
2346extracted source tree. If the source is actually a directory, copy it
2347to the build tree, and enter that directory.
2348
2349@item patch-source-shebangs
2350Patch shebangs encountered in source files so they refer to the right
2351store file names. For instance, this changes @code{#!/bin/sh} to
2352@code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
2353
2354@item configure
2355Run the @file{configure} script with a number of default options, such
2356as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
2357by the @code{#:configure-flags} argument.
2358
2359@item build
2360Run @code{make} with the list of flags specified with
2361@code{#:make-flags}. If the @code{#:parallel-builds?} argument is true
2362(the default), build with @code{make -j}.
2363
2364@item check
2365Run @code{make check}, or some other target specified with
2366@code{#:test-target}, unless @code{#:tests? #f} is passed. If the
2367@code{#:parallel-tests?} argument is true (the default), run @code{make
2368check -j}.
2369
2370@item install
2371Run @code{make install} with the flags listed in @code{#:make-flags}.
2372
2373@item patch-shebangs
2374Patch shebangs on the installed executable files.
2375
2376@item strip
2377Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
2378is false), copying them to the @code{debug} output when available
2379(@pxref{Installing Debugging Files}).
2380@end table
2381
2382@vindex %standard-phases
2383The build-side module @code{(guix build gnu-build-system)} defines
2384@var{%standard-phases} as the default list of build phases.
2385@var{%standard-phases} is a list of symbol/procedure pairs, where the
2386procedure implements the actual phase.
2387
2388The list of phases used for a particular package can be changed with the
2389@code{#:phases} parameter. For instance, passing:
2390
2391@example
2392#:phases (alist-delete 'configure %standard-phases)
2393@end example
2394
9bf404e9 2395means that all the phases described above will be used, except the
7458bd0a
LC
2396@code{configure} phase.
2397
2398In addition, this build system ensures that the ``standard'' environment
2399for GNU packages is available. This includes tools such as GCC, libc,
2400Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
2401build-system gnu)} module for a complete list.) We call these the
2402@dfn{implicit inputs} of a package, because package definitions don't
2403have to mention them.
2404@end defvr
2405
2406Other @code{<build-system>} objects are defined to support other
2407conventions and tools used by free software packages. They inherit most
2408of @var{gnu-build-system}, and differ mainly in the set of inputs
2409implicitly added to the build process, and in the list of phases
2410executed. Some of these build systems are listed below.
2411
2412@defvr {Scheme Variable} cmake-build-system
2413This variable is exported by @code{(guix build-system cmake)}. It
2414implements the build procedure for packages using the
2415@url{http://www.cmake.org, CMake build tool}.
2416
2417It automatically adds the @code{cmake} package to the set of inputs.
2418Which package is used can be specified with the @code{#:cmake}
2419parameter.
9849cfc1
LC
2420
2421The @code{#:configure-flags} parameter is taken as a list of flags
2422passed to the @command{cmake} command. The @code{#:build-type}
2423parameter specifies in abstract terms the flags passed to the compiler;
2424it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
2425debugging information''), which roughly means that code is compiled with
2426@code{-O2 -g}, as is the case for Autoconf-based packages by default.
7458bd0a
LC
2427@end defvr
2428
3afcf52b
FB
2429@defvr {Scheme Variable} glib-or-gtk-build-system
2430This variable is exported by @code{(guix build-system glib-or-gtk)}. It
2431is intended for use with packages making use of GLib or GTK+.
2432
2433This build system adds the following two phases to the ones defined by
2434@var{gnu-build-system}:
2435
2436@table @code
2437@item glib-or-gtk-wrap
2438The phase @code{glib-or-gtk-wrap} ensures that programs found under
2439@file{bin/} are able to find GLib's ``schemas'' and
2440@uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
2441modules}. This is achieved by wrapping the programs in launch scripts
2442that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
2443environment variables.
2444
73aa8ddb
LC
2445It is possible to exclude specific package outputs from that wrapping
2446process by listing their names in the
2447@code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
2448when an output is known not to contain any GLib or GTK+ binaries, and
2449where wrapping would gratuitously add a dependency of that output on
2450GLib and GTK+.
2451
3afcf52b
FB
2452@item glib-or-gtk-compile-schemas
2453The phase @code{glib-or-gtk-compile-schemas} makes sure that all GLib's
2454@uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
2455GSettings schemas} are compiled. Compilation is performed by the
2456@command{glib-compile-schemas} program. It is provided by the package
2457@code{glib:bin} which is automatically imported by the build system.
2458The @code{glib} package providing @command{glib-compile-schemas} can be
2459specified with the @code{#:glib} parameter.
2460@end table
2461
2462Both phases are executed after the @code{install} phase.
2463@end defvr
2464
7458bd0a
LC
2465@defvr {Scheme Variable} python-build-system
2466This variable is exported by @code{(guix build-system python)}. It
2467implements the more or less standard build procedure used by Python
2468packages, which consists in running @code{python setup.py build} and
2469then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
2470
2471For packages that install stand-alone Python programs under @code{bin/},
2472it takes care of wrapping these programs so their @code{PYTHONPATH}
2473environment variable points to all the Python libraries they depend on.
2474
2475Which Python package is used can be specified with the @code{#:python}
2476parameter.
2477@end defvr
2478
2479@defvr {Scheme Variable} perl-build-system
2480This variable is exported by @code{(guix build-system perl)}. It
2d2a53fc
EB
2481implements the standard build procedure for Perl packages, which either
2482consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
2483followed by @code{Build} and @code{Build install}; or in running
2484@code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
2485@code{make} and @code{make install}; depending on which of
2486@code{Build.PL} or @code{Makefile.PL} is present in the package
2487distribution. Preference is given to the former if both @code{Build.PL}
2488and @code{Makefile.PL} exist in the package distribution. This
2489preference can be reversed by specifying @code{#t} for the
2490@code{#:make-maker?} parameter.
2491
2492The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
2493passes flags specified by the @code{#:make-maker-flags} or
2494@code{#:module-build-flags} parameter, respectively.
7458bd0a
LC
2495
2496Which Perl package is used can be specified with @code{#:perl}.
2497@end defvr
2498
f8f3bef6
RW
2499@defvr {Scheme Variable} r-build-system
2500This variable is exported by @code{(guix build-system r)}. It
2501implements the build procedure used by @uref{http://r-project.org, R}
2502packages, which essentially is little more than running @code{R CMD
2503INSTALL --library=/gnu/store/@dots{}} in an environment where
2504@code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
2505are run after installation using the R function
2506@code{tools::testInstalledPackage}.
2507@end defvr
2508
c08f9818
DT
2509@defvr {Scheme Variable} ruby-build-system
2510This variable is exported by @code{(guix build-system ruby)}. It
2511implements the RubyGems build procedure used by Ruby packages, which
2512involves running @code{gem build} followed by @code{gem install}.
2513
5dc87623
DT
2514The @code{source} field of a package that uses this build system
2515typically references a gem archive, since this is the format that Ruby
2516developers use when releasing their software. The build system unpacks
2517the gem archive, potentially patches the source, runs the test suite,
2518repackages the gem, and installs it. Additionally, directories and
2519tarballs may be referenced to allow building unreleased gems from Git or
2520a traditional source release tarball.
e83c6d00 2521
c08f9818 2522Which Ruby package is used can be specified with the @code{#:ruby}
6e9f2913
PP
2523parameter. A list of additional flags to be passed to the @command{gem}
2524command can be specified with the @code{#:gem-flags} parameter.
c08f9818 2525@end defvr
7458bd0a 2526
a677c726
RW
2527@defvr {Scheme Variable} waf-build-system
2528This variable is exported by @code{(guix build-system waf)}. It
2529implements a build procedure around the @code{waf} script. The common
2530phases---@code{configure}, @code{build}, and @code{install}---are
2531implemented by passing their names as arguments to the @code{waf}
2532script.
2533
2534The @code{waf} script is executed by the Python interpreter. Which
2535Python package is used to run the script can be specified with the
2536@code{#:python} parameter.
2537@end defvr
2538
14dfdf2e
FB
2539@defvr {Scheme Variable} haskell-build-system
2540This variable is exported by @code{(guix build-system haskell)}. It
2541implements the Cabal build procedure used by Haskell packages, which
2542involves running @code{runhaskell Setup.hs configure
2543--prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
2544Instead of installing the package by running @code{runhaskell Setup.hs
2545install}, to avoid trying to register libraries in the read-only
2546compiler store directory, the build system uses @code{runhaskell
2547Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
2548addition, the build system generates the package documentation by
2549running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
2550is passed. Optional Haddock parameters can be passed with the help of
2551the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
2552not found, the build system looks for @code{Setup.lhs} instead.
2553
2554Which Haskell compiler is used can be specified with the @code{#:haskell}
a54bd6d7 2555parameter which defaults to @code{ghc}.
14dfdf2e
FB
2556@end defvr
2557
e9137a53
FB
2558@defvr {Scheme Variable} emacs-build-system
2559This variable is exported by @code{(guix build-system emacs)}. It
2560implements an installation procedure similar to the one of Emacs' own
2561packaging system (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
2562
2563It first creates the @code{@var{package}-autoloads.el} file, then it
2564byte compiles all Emacs Lisp files. Differently from the Emacs
2565packaging system, the Info documentation files are moved to the standard
2566documentation directory and the @file{dir} file is deleted. Each
2567package is installed in its own directory under
2568@file{share/emacs/site-lisp/guix.d}.
2569@end defvr
2570
7458bd0a
LC
2571Lastly, for packages that do not need anything as sophisticated, a
2572``trivial'' build system is provided. It is trivial in the sense that
2573it provides basically no support: it does not pull any implicit inputs,
2574and does not have a notion of build phases.
2575
2576@defvr {Scheme Variable} trivial-build-system
2577This variable is exported by @code{(guix build-system trivial)}.
2578
2579This build system requires a @code{#:builder} argument. This argument
2580must be a Scheme expression that builds the package's output(s)---as
2581with @code{build-expression->derivation} (@pxref{Derivations,
2582@code{build-expression->derivation}}).
2583@end defvr
2584
568717fd
LC
2585@node The Store
2586@section The Store
2587
e531ac2a
LC
2588@cindex store
2589@cindex store paths
2590
2591Conceptually, the @dfn{store} is where derivations that have been
834129e0 2592successfully built are stored---by default, under @file{/gnu/store}.
e531ac2a 2593Sub-directories in the store are referred to as @dfn{store paths}. The
4988dd40 2594store has an associated database that contains information such as the
e531ac2a
LC
2595store paths referred to by each store path, and the list of @emph{valid}
2596store paths---paths that result from a successful build.
2597
2598The store is always accessed by the daemon on behalf of its clients
2599(@pxref{Invoking guix-daemon}). To manipulate the store, clients
2600connect to the daemon over a Unix-domain socket, send it requests, and
2601read the result---these are remote procedure calls, or RPCs.
2602
2603The @code{(guix store)} module provides procedures to connect to the
2604daemon, and to perform RPCs. These are described below.
2605
2606@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
2607Connect to the daemon over the Unix-domain socket at @var{file}. When
2608@var{reserve-space?} is true, instruct it to reserve a little bit of
2609extra space on the file system so that the garbage collector can still
2610operate, should the disk become full. Return a server object.
2611
2612@var{file} defaults to @var{%default-socket-path}, which is the normal
2613location given the options that were passed to @command{configure}.
2614@end deffn
2615
2616@deffn {Scheme Procedure} close-connection @var{server}
2617Close the connection to @var{server}.
2618@end deffn
2619
2620@defvr {Scheme Variable} current-build-output-port
2621This variable is bound to a SRFI-39 parameter, which refers to the port
2622where build and error logs sent by the daemon should be written.
2623@end defvr
2624
2625Procedures that make RPCs all take a server object as their first
2626argument.
2627
2628@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
2629Return @code{#t} when @var{path} is a valid store path.
2630@end deffn
2631
cfbf9160 2632@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
2633Add @var{text} under file @var{name} in the store, and return its store
2634path. @var{references} is the list of store paths referred to by the
2635resulting store path.
2636@end deffn
2637
874e6874 2638@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
2639Build @var{derivations} (a list of @code{<derivation>} objects or
2640derivation paths), and return when the worker is done building them.
2641Return @code{#t} on success.
874e6874
LC
2642@end deffn
2643
b860f382
LC
2644Note that the @code{(guix monads)} module provides a monad as well as
2645monadic versions of the above procedures, with the goal of making it
2646more convenient to work with code that accesses the store (@pxref{The
2647Store Monad}).
2648
e531ac2a
LC
2649@c FIXME
2650@i{This section is currently incomplete.}
568717fd
LC
2651
2652@node Derivations
2653@section Derivations
2654
874e6874
LC
2655@cindex derivations
2656Low-level build actions and the environment in which they are performed
2657are represented by @dfn{derivations}. A derivation contain the
2658following pieces of information:
2659
2660@itemize
2661@item
2662The outputs of the derivation---derivations produce at least one file or
2663directory in the store, but may produce more.
2664
2665@item
2666The inputs of the derivations, which may be other derivations or plain
2667files in the store (patches, build scripts, etc.)
2668
2669@item
2670The system type targeted by the derivation---e.g., @code{x86_64-linux}.
2671
2672@item
2673The file name of a build script in the store, along with the arguments
2674to be passed.
2675
2676@item
2677A list of environment variables to be defined.
2678
2679@end itemize
2680
2681@cindex derivation path
2682Derivations allow clients of the daemon to communicate build actions to
2683the store. They exist in two forms: as an in-memory representation,
2684both on the client- and daemon-side, and as files in the store whose
2685name end in @code{.drv}---these files are referred to as @dfn{derivation
2686paths}. Derivations paths can be passed to the @code{build-derivations}
2687procedure to perform the build actions they prescribe (@pxref{The
2688Store}).
2689
2690The @code{(guix derivations)} module provides a representation of
2691derivations as Scheme objects, along with procedures to create and
2692otherwise manipulate derivations. The lowest-level primitive to create
2693a derivation is the @code{derivation} procedure:
2694
1909431c
LC
2695@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
2696 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 2697 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c 2698 [#:system (%current-system)] [#:references-graphs #f] @
4a6aeb67
LC
2699 [#:allowed-references #f] [#:leaked-env-vars #f] [#:local-build? #f] @
2700 [#:substitutable? #t]
59688fc4
LC
2701Build a derivation with the given arguments, and return the resulting
2702@code{<derivation>} object.
874e6874 2703
2096ef47 2704When @var{hash} and @var{hash-algo} are given, a
874e6874 2705@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
2706known in advance, such as a file download. If, in addition,
2707@var{recursive?} is true, then that fixed output may be an executable
2708file or a directory and @var{hash} must be the hash of an archive
2709containing this output.
5b0c9d16 2710
858e9282 2711When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
2712name/store path pairs. In that case, the reference graph of each store
2713path is exported in the build environment in the corresponding file, in
2714a simple text format.
1909431c 2715
b53be755
LC
2716When @var{allowed-references} is true, it must be a list of store items
2717or outputs that the derivation's output may refer to.
2718
c0468155
LC
2719When @var{leaked-env-vars} is true, it must be a list of strings
2720denoting environment variables that are allowed to ``leak'' from the
2721daemon's environment to the build environment. This is only applicable
2722to fixed-output derivations---i.e., when @var{hash} is true. The main
2723use is to allow variables such as @code{http_proxy} to be passed to
2724derivations that download files.
2725
1909431c
LC
2726When @var{local-build?} is true, declare that the derivation is not a
2727good candidate for offloading and should rather be built locally
2728(@pxref{Daemon Offload Setup}). This is the case for small derivations
2729where the costs of data transfers would outweigh the benefits.
4a6aeb67
LC
2730
2731When @var{substitutable?} is false, declare that substitutes of the
2732derivation's output should not be used (@pxref{Substitutes}). This is
2733useful, for instance, when building packages that capture details of the
2734host CPU instruction set.
874e6874
LC
2735@end deffn
2736
2737@noindent
2738Here's an example with a shell script as its builder, assuming
2739@var{store} is an open connection to the daemon, and @var{bash} points
2740to a Bash executable in the store:
2741
2742@lisp
2743(use-modules (guix utils)
2744 (guix store)
2745 (guix derivations))
2746
59688fc4
LC
2747(let ((builder ; add the Bash script to the store
2748 (add-text-to-store store "my-builder.sh"
2749 "echo hello world > $out\n" '())))
2750 (derivation store "foo"
2751 bash `("-e" ,builder)
21b679f6 2752 #:inputs `((,bash) (,builder))
59688fc4 2753 #:env-vars '(("HOME" . "/homeless"))))
834129e0 2754@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
2755@end lisp
2756
21b679f6
LC
2757As can be guessed, this primitive is cumbersome to use directly. A
2758better approach is to write build scripts in Scheme, of course! The
2759best course of action for that is to write the build code as a
2760``G-expression'', and to pass it to @code{gexp->derivation}. For more
6621cdb6 2761information, @pxref{G-Expressions}.
21b679f6
LC
2762
2763Once upon a time, @code{gexp->derivation} did not exist and constructing
2764derivations with build code written in Scheme was achieved with
2765@code{build-expression->derivation}, documented below. This procedure
2766is now deprecated in favor of the much nicer @code{gexp->derivation}.
874e6874 2767
dd1a5a15
LC
2768@deffn {Scheme Procedure} build-expression->derivation @var{store} @
2769 @var{name} @var{exp} @
2770 [#:system (%current-system)] [#:inputs '()] @
2771 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
36bbbbd1 2772 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
63a42824 2773 [#:references-graphs #f] [#:allowed-references #f] @
4a6aeb67 2774 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
874e6874
LC
2775Return a derivation that executes Scheme expression @var{exp} as a
2776builder for derivation @var{name}. @var{inputs} must be a list of
2777@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
2778@code{"out"} is assumed. @var{modules} is a list of names of Guile
2779modules from the current search path to be copied in the store,
2780compiled, and made available in the load path during the execution of
2781@var{exp}---e.g., @code{((guix build utils) (guix build
2782gnu-build-system))}.
2783
2784@var{exp} is evaluated in an environment where @code{%outputs} is bound
2785to a list of output/path pairs, and where @code{%build-inputs} is bound
2786to a list of string/output-path pairs made from @var{inputs}.
2787Optionally, @var{env-vars} is a list of string pairs specifying the name
2788and value of environment variables visible to the builder. The builder
2789terminates by passing the result of @var{exp} to @code{exit}; thus, when
2790@var{exp} returns @code{#f}, the build is considered to have failed.
2791
2792@var{exp} is built using @var{guile-for-build} (a derivation). When
2793@var{guile-for-build} is omitted or is @code{#f}, the value of the
2794@code{%guile-for-build} fluid is used instead.
9c629a27 2795
63a42824 2796See the @code{derivation} procedure for the meaning of
4a6aeb67
LC
2797@var{references-graphs}, @var{allowed-references}, @var{local-build?},
2798and @var{substitutable?}.
874e6874
LC
2799@end deffn
2800
2801@noindent
2802Here's an example of a single-output derivation that creates a directory
2803containing one file:
2804
2805@lisp
2806(let ((builder '(let ((out (assoc-ref %outputs "out")))
834129e0 2807 (mkdir out) ; create /gnu/store/@dots{}-goo
874e6874
LC
2808 (call-with-output-file (string-append out "/test")
2809 (lambda (p)
2810 (display '(hello guix) p))))))
dd1a5a15 2811 (build-expression->derivation store "goo" builder))
874e6874 2812
834129e0 2813@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
874e6874
LC
2814@end lisp
2815
568717fd 2816
b860f382
LC
2817@node The Store Monad
2818@section The Store Monad
2819
2820@cindex monad
2821
2822The procedures that operate on the store described in the previous
2823sections all take an open connection to the build daemon as their first
2824argument. Although the underlying model is functional, they either have
2825side effects or depend on the current state of the store.
2826
2827The former is inconvenient: the connection to the build daemon has to be
2828carried around in all those functions, making it impossible to compose
2829functions that do not take that parameter with functions that do. The
2830latter can be problematic: since store operations have side effects
2831and/or depend on external state, they have to be properly sequenced.
2832
2833@cindex monadic values
2834@cindex monadic functions
2835This is where the @code{(guix monads)} module comes in. This module
2836provides a framework for working with @dfn{monads}, and a particularly
2837useful monad for our uses, the @dfn{store monad}. Monads are a
2838construct that allows two things: associating ``context'' with values
2839(in our case, the context is the store), and building sequences of
561fb6c3 2840computations (here computations include accesses to the store.) Values
b860f382
LC
2841in a monad---values that carry this additional context---are called
2842@dfn{monadic values}; procedures that return such values are called
2843@dfn{monadic procedures}.
2844
2845Consider this ``normal'' procedure:
2846
2847@example
45adbd62
LC
2848(define (sh-symlink store)
2849 ;; Return a derivation that symlinks the 'bash' executable.
2850 (let* ((drv (package-derivation store bash))
2851 (out (derivation->output-path drv))
2852 (sh (string-append out "/bin/bash")))
2853 (build-expression->derivation store "sh"
2854 `(symlink ,sh %output))))
b860f382
LC
2855@end example
2856
c6f30b81
LC
2857Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
2858as a monadic function:
b860f382
LC
2859
2860@example
45adbd62 2861(define (sh-symlink)
b860f382 2862 ;; Same, but return a monadic value.
c6f30b81
LC
2863 (mlet %store-monad ((drv (package->derivation bash)))
2864 (gexp->derivation "sh"
2865 #~(symlink (string-append #$drv "/bin/bash")
2866 #$output))))
b860f382
LC
2867@end example
2868
c6f30b81
LC
2869There several things to note in the second version: the @code{store}
2870parameter is now implicit and is ``threaded'' in the calls to the
2871@code{package->derivation} and @code{gexp->derivation} monadic
2872procedures, and the monadic value returned by @code{package->derivation}
2873is @dfn{bound} using @code{mlet} instead of plain @code{let}.
2874
2875As it turns out, the call to @code{package->derivation} can even be
2876omitted since it will take place implicitly, as we will see later
2877(@pxref{G-Expressions}):
2878
2879@example
2880(define (sh-symlink)
2881 (gexp->derivation "sh"
2882 #~(symlink (string-append #$bash "/bin/bash")
2883 #$output)))
2884@end example
b860f382 2885
7ce21611
LC
2886@c See
2887@c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
2888@c for the funny quote.
2889Calling the monadic @code{sh-symlink} has no effect. As someone once
2890said, ``you exit a monad like you exit a building on fire: by running''.
2891So, to exit the monad and get the desired effect, one must use
2892@code{run-with-store}:
b860f382
LC
2893
2894@example
8e9aa37f
CAW
2895(run-with-store (open-connection) (sh-symlink))
2896@result{} /gnu/store/...-sh-symlink
b860f382
LC
2897@end example
2898
b9b86078
LC
2899Note that the @code{(guix monad-repl)} module extends Guile's REPL with
2900new ``meta-commands'' to make it easier to deal with monadic procedures:
2901@code{run-in-store}, and @code{enter-store-monad}. The former, is used
2902to ``run'' a single monadic value through the store:
2903
2904@example
2905scheme@@(guile-user)> ,run-in-store (package->derivation hello)
2906$1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
2907@end example
2908
2909The latter enters a recursive REPL, where all the return values are
2910automatically run through the store:
2911
2912@example
2913scheme@@(guile-user)> ,enter-store-monad
2914store-monad@@(guile-user) [1]> (package->derivation hello)
2915$2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
2916store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
2917$3 = "/gnu/store/@dots{}-foo"
2918store-monad@@(guile-user) [1]> ,q
2919scheme@@(guile-user)>
2920@end example
2921
2922@noindent
2923Note that non-monadic values cannot be returned in the
2924@code{store-monad} REPL.
2925
e87f0591
LC
2926The main syntactic forms to deal with monads in general are provided by
2927the @code{(guix monads)} module and are described below.
b860f382
LC
2928
2929@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
2930Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
2931in @var{monad}.
2932@end deffn
2933
2934@deffn {Scheme Syntax} return @var{val}
2935Return a monadic value that encapsulates @var{val}.
2936@end deffn
2937
751630c9 2938@deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
b860f382 2939@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
751630c9
LC
2940procedures @var{mproc}@dots{}@footnote{This operation is commonly
2941referred to as ``bind'', but that name denotes an unrelated procedure in
2942Guile. Thus we use this somewhat cryptic symbol inherited from the
2943Haskell language.}. There can be one @var{mproc} or several of them, as
2944in this example:
2945
2946@example
2947(run-with-state
2948 (with-monad %state-monad
2949 (>>= (return 1)
2950 (lambda (x) (return (+ 1 x)))
2951 (lambda (x) (return (* 2 x)))))
2952 'some-state)
2953
2954@result{} 4
2955@result{} some-state
2956@end example
b860f382
LC
2957@end deffn
2958
2959@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
2960 @var{body} ...
2961@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
2962 @var{body} ...
2963Bind the variables @var{var} to the monadic values @var{mval} in
2964@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
2965``normal'' value @var{val}, as per @code{let}.
2966
2967@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
2968(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
2969@end deffn
2970
405a9d4e
LC
2971@deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
2972Bind @var{mexp} and the following monadic expressions in sequence,
2973returning the result of the last expression.
2974
2975This is akin to @code{mlet}, except that the return values of the
2976monadic expressions are ignored. In that sense, it is analogous to
2977@code{begin}, but applied to monadic expressions.
2978@end deffn
2979
561fb6c3
LC
2980@cindex state monad
2981The @code{(guix monads)} module provides the @dfn{state monad}, which
2982allows an additional value---the state---to be @emph{threaded} through
2983monadic procedure calls.
2984
2985@defvr {Scheme Variable} %state-monad
2986The state monad. Procedures in the state monad can access and change
2987the state that is threaded.
2988
2989Consider the example below. The @code{square} procedure returns a value
2990in the state monad. It returns the square of its argument, but also
2991increments the current state value:
2992
2993@example
2994(define (square x)
2995 (mlet %state-monad ((count (current-state)))
2996 (mbegin %state-monad
2997 (set-current-state (+ 1 count))
2998 (return (* x x)))))
2999
3000(run-with-state (sequence %state-monad (map square (iota 3))) 0)
3001@result{} (0 1 4)
3002@result{} 3
3003@end example
3004
3005When ``run'' through @var{%state-monad}, we obtain that additional state
3006value, which is the number of @code{square} calls.
3007@end defvr
3008
3009@deffn {Monadic Procedure} current-state
3010Return the current state as a monadic value.
3011@end deffn
3012
3013@deffn {Monadic Procedure} set-current-state @var{value}
3014Set the current state to @var{value} and return the previous state as a
3015monadic value.
3016@end deffn
3017
3018@deffn {Monadic Procedure} state-push @var{value}
3019Push @var{value} to the current state, which is assumed to be a list,
3020and return the previous state as a monadic value.
3021@end deffn
3022
3023@deffn {Monadic Procedure} state-pop
3024Pop a value from the current state and return it as a monadic value.
3025The state is assumed to be a list.
3026@end deffn
3027
3028@deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3029Run monadic value @var{mval} starting with @var{state} as the initial
3030state. Return two values: the resulting value, and the resulting state.
3031@end deffn
3032
e87f0591
LC
3033The main interface to the store monad, provided by the @code{(guix
3034store)} module, is as follows.
b860f382
LC
3035
3036@defvr {Scheme Variable} %store-monad
561fb6c3
LC
3037The store monad---an alias for @var{%state-monad}.
3038
3039Values in the store monad encapsulate accesses to the store. When its
3040effect is needed, a value of the store monad must be ``evaluated'' by
3041passing it to the @code{run-with-store} procedure (see below.)
b860f382
LC
3042@end defvr
3043
3044@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3045Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3046open store connection.
3047@end deffn
3048
ad372953 3049@deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
b860f382 3050Return as a monadic value the absolute file name in the store of the file
ad372953
LC
3051containing @var{text}, a string. @var{references} is a list of store items that the
3052resulting text file refers to; it defaults to the empty list.
45adbd62
LC
3053@end deffn
3054
0a90af15
LC
3055@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
3056 [#:recursive? #t]
3057Return the name of @var{file} once interned in the store. Use
3058@var{name} as its store name, or the basename of @var{file} if
3059@var{name} is omitted.
3060
3061When @var{recursive?} is true, the contents of @var{file} are added
3062recursively; if @var{file} designates a flat file and @var{recursive?}
3063is true, its contents are added, and its permission bits are kept.
3064
3065The example below adds a file to the store, under two different names:
3066
3067@example
3068(run-with-store (open-connection)
3069 (mlet %store-monad ((a (interned-file "README"))
3070 (b (interned-file "README" "LEGU-MIN")))
3071 (return (list a b))))
3072
3073@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3074@end example
3075
3076@end deffn
3077
e87f0591
LC
3078The @code{(guix packages)} module exports the following package-related
3079monadic procedures:
3080
b860f382 3081@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4231f05b
LC
3082 [#:system (%current-system)] [#:target #f] @
3083 [#:output "out"] Return as a monadic
b860f382
LC
3084value in the absolute file name of @var{file} within the @var{output}
3085directory of @var{package}. When @var{file} is omitted, return the name
4231f05b
LC
3086of the @var{output} directory of @var{package}. When @var{target} is
3087true, use it as a cross-compilation target triplet.
b860f382
LC
3088@end deffn
3089
b860f382 3090@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4231f05b
LC
3091@deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3092 @var{target} [@var{system}]
3093Monadic version of @code{package-derivation} and
3094@code{package-cross-derivation} (@pxref{Defining Packages}).
b860f382
LC
3095@end deffn
3096
3097
21b679f6
LC
3098@node G-Expressions
3099@section G-Expressions
3100
3101@cindex G-expression
3102@cindex build code quoting
3103So we have ``derivations'', which represent a sequence of build actions
3104to be performed to produce an item in the store (@pxref{Derivations}).
3105Those build actions are performed when asking the daemon to actually
3106build the derivations; they are run by the daemon in a container
3107(@pxref{Invoking guix-daemon}).
3108
3109@cindex strata of code
3110It should come as no surprise that we like to write those build actions
3111in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3112code@footnote{The term @dfn{stratum} in this context was coined by
ef4ab0a4
LC
3113Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3114Kiselyov, who has written insightful
3115@url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3116on this topic}, refers to this kind of code generation as
3117@dfn{staging}.}: the ``host code''---code that defines packages, talks
3118to the daemon, etc.---and the ``build code''---code that actually
3119performs build actions, such as making directories, invoking
3120@command{make}, etc.
21b679f6
LC
3121
3122To describe a derivation and its build actions, one typically needs to
3123embed build code inside host code. It boils down to manipulating build
3124code as data, and Scheme's homoiconicity---code has a direct
3125representation as data---comes in handy for that. But we need more than
3126Scheme's normal @code{quasiquote} mechanism to construct build
3127expressions.
3128
3129The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3130S-expressions adapted to build expressions. G-expressions, or
3131@dfn{gexps}, consist essentially in three syntactic forms: @code{gexp},
3132@code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
3133@code{#$}, and @code{#$@@}), which are comparable respectively to
3134@code{quasiquote}, @code{unquote}, and @code{unquote-splicing}
3135(@pxref{Expression Syntax, @code{quasiquote},, guile, GNU Guile
3136Reference Manual}). However, there are major differences:
3137
3138@itemize
3139@item
3140Gexps are meant to be written to a file and run or manipulated by other
3141processes.
3142
3143@item
b39fc6f7
LC
3144When a high-level object such as a package or derivation is unquoted
3145inside a gexp, the result is as if its output file name had been
3146introduced.
ff40e9b7 3147
21b679f6
LC
3148@item
3149Gexps carry information about the packages or derivations they refer to,
3150and these dependencies are automatically added as inputs to the build
3151processes that use them.
3152@end itemize
3153
c2b84676 3154@cindex lowering, of high-level objects in gexps
343eacbe
LC
3155This mechanism is not limited to package and derivation
3156objects: @dfn{compilers} able to ``lower'' other high-level objects to
c2b84676
LC
3157derivations or files in the store can be defined,
3158such that these objects can also be inserted
343eacbe
LC
3159into gexps. For example, a useful type of high-level object that can be
3160inserted in a gexp is ``file-like objects'', which make it easy to
3161add files to the store and refer to them in
558e8b11
LC
3162derivations and such (see @code{local-file} and @code{plain-file}
3163below.)
b39fc6f7 3164
21b679f6
LC
3165To illustrate the idea, here is an example of a gexp:
3166
3167@example
3168(define build-exp
3169 #~(begin
3170 (mkdir #$output)
3171 (chdir #$output)
aff8ce7c 3172 (symlink (string-append #$coreutils "/bin/ls")
21b679f6
LC
3173 "list-files")))
3174@end example
3175
3176This gexp can be passed to @code{gexp->derivation}; we obtain a
3177derivation that builds a directory containing exactly one symlink to
3178@file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3179
3180@example
3181(gexp->derivation "the-thing" build-exp)
3182@end example
3183
e20fd1bf 3184As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
21b679f6
LC
3185substituted to the reference to the @var{coreutils} package in the
3186actual build code, and @var{coreutils} is automatically made an input to
3187the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
3188output)}) is replaced by a string containing the derivation's output
667b2508
LC
3189directory name.
3190
3191@cindex cross compilation
3192In a cross-compilation context, it is useful to distinguish between
3193references to the @emph{native} build of a package---that can run on the
3194host---versus references to cross builds of a package. To that end, the
3195@code{#+} plays the same role as @code{#$}, but is a reference to a
3196native package build:
3197
3198@example
3199(gexp->derivation "vi"
3200 #~(begin
3201 (mkdir #$output)
3202 (system* (string-append #+coreutils "/bin/ln")
3203 "-s"
3204 (string-append #$emacs "/bin/emacs")
3205 (string-append #$output "/bin/vi")))
3206 #:target "mips64el-linux")
3207@end example
3208
3209@noindent
3210In the example above, the native build of @var{coreutils} is used, so
3211that @command{ln} can actually run on the host; but then the
3212cross-compiled build of @var{emacs} is referenced.
3213
3214The syntactic form to construct gexps is summarized below.
21b679f6
LC
3215
3216@deffn {Scheme Syntax} #~@var{exp}
3217@deffnx {Scheme Syntax} (gexp @var{exp})
3218Return a G-expression containing @var{exp}. @var{exp} may contain one
3219or more of the following forms:
3220
3221@table @code
3222@item #$@var{obj}
3223@itemx (ungexp @var{obj})
b39fc6f7
LC
3224Introduce a reference to @var{obj}. @var{obj} may have one of the
3225supported types, for example a package or a
21b679f6
LC
3226derivation, in which case the @code{ungexp} form is replaced by its
3227output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
3228
b39fc6f7
LC
3229If @var{obj} is a list, it is traversed and references to supported
3230objects are substituted similarly.
21b679f6
LC
3231
3232If @var{obj} is another gexp, its contents are inserted and its
3233dependencies are added to those of the containing gexp.
3234
3235If @var{obj} is another kind of object, it is inserted as is.
3236
b39fc6f7
LC
3237@item #$@var{obj}:@var{output}
3238@itemx (ungexp @var{obj} @var{output})
21b679f6 3239This is like the form above, but referring explicitly to the
b39fc6f7
LC
3240@var{output} of @var{obj}---this is useful when @var{obj} produces
3241multiple outputs (@pxref{Packages with Multiple Outputs}).
21b679f6 3242
667b2508
LC
3243@item #+@var{obj}
3244@itemx #+@var{obj}:output
3245@itemx (ungexp-native @var{obj})
3246@itemx (ungexp-native @var{obj} @var{output})
3247Same as @code{ungexp}, but produces a reference to the @emph{native}
3248build of @var{obj} when used in a cross compilation context.
3249
21b679f6
LC
3250@item #$output[:@var{output}]
3251@itemx (ungexp output [@var{output}])
3252Insert a reference to derivation output @var{output}, or to the main
3253output when @var{output} is omitted.
3254
3255This only makes sense for gexps passed to @code{gexp->derivation}.
3256
3257@item #$@@@var{lst}
3258@itemx (ungexp-splicing @var{lst})
3259Like the above, but splices the contents of @var{lst} inside the
3260containing list.
3261
667b2508
LC
3262@item #+@@@var{lst}
3263@itemx (ungexp-native-splicing @var{lst})
3264Like the above, but refers to native builds of the objects listed in
3265@var{lst}.
3266
21b679f6
LC
3267@end table
3268
3269G-expressions created by @code{gexp} or @code{#~} are run-time objects
3270of the @code{gexp?} type (see below.)
3271@end deffn
3272
3273@deffn {Scheme Procedure} gexp? @var{obj}
3274Return @code{#t} if @var{obj} is a G-expression.
3275@end deffn
3276
3277G-expressions are meant to be written to disk, either as code building
3278some derivation, or as plain files in the store. The monadic procedures
3279below allow you to do that (@pxref{The Store Monad}, for more
3280information about monads.)
3281
3282@deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
ce45eb4c 3283 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
21b679f6
LC
3284 [#:hash #f] [#:hash-algo #f] @
3285 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4684f301 3286 [#:module-path @var{%load-path}] @
c8351d9a 3287 [#:references-graphs #f] [#:allowed-references #f] @
c0468155 3288 [#:leaked-env-vars #f] @
0309e1b0 3289 [#:script-name (string-append @var{name} "-builder")] @
4a6aeb67 3290 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
21b679f6 3291Return a derivation @var{name} that runs @var{exp} (a gexp) with
0309e1b0
LC
3292@var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
3293stored in a file called @var{script-name}. When @var{target} is true,
3294it is used as the cross-compilation target triplet for packages referred
3295to by @var{exp}.
21b679f6 3296
ce45eb4c
LC
3297Make @var{modules} available in the evaluation context of @var{exp};
3298@var{modules} is a list of names of Guile modules searched in
3299@var{module-path} to be copied in the store, compiled, and made available in
21b679f6
LC
3300the load path during the execution of @var{exp}---e.g., @code{((guix
3301build utils) (guix build gnu-build-system))}.
3302
ce45eb4c
LC
3303@var{graft?} determines whether packages referred to by @var{exp} should be grafted when
3304applicable.
3305
b53833b2
LC
3306When @var{references-graphs} is true, it must be a list of tuples of one of the
3307following forms:
3308
3309@example
3310(@var{file-name} @var{package})
3311(@var{file-name} @var{package} @var{output})
3312(@var{file-name} @var{derivation})
3313(@var{file-name} @var{derivation} @var{output})
3314(@var{file-name} @var{store-item})
3315@end example
3316
3317The right-hand-side of each element of @var{references-graphs} is automatically made
3318an input of the build process of @var{exp}. In the build environment, each
3319@var{file-name} contains the reference graph of the corresponding item, in a simple
3320text format.
3321
c8351d9a
LC
3322@var{allowed-references} must be either @code{#f} or a list of output names and packages.
3323In the latter case, the list denotes store items that the result is allowed to
3324refer to. Any reference to another store item will lead to a build error.
3325
e20fd1bf 3326The other arguments are as for @code{derivation} (@pxref{Derivations}).
21b679f6
LC
3327@end deffn
3328
343eacbe
LC
3329@cindex file-like objects
3330The @code{local-file} and @code{plain-file} procedures below return
3331@dfn{file-like objects}. That is, when unquoted in a G-expression,
3332these objects lead to a file in the store. Consider this G-expression:
3333
3334@example
3335#~(system* (string-append #$glibc "/sbin/nscd") "-f"
3336 #$(local-file "/tmp/my-nscd.conf"))
3337@end example
3338
3339The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
3340to the store. Once expanded, for instance @i{via}
3341@code{gexp->derivation}, the G-expression refers to that copy under
3342@file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
3343does not have any effect on what the G-expression does.
3344@code{plain-file} can be used similarly; it differs in that the file
3345content is directly passed as a string.
3346
d9ae938f
LC
3347@deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
3348 [#:recursive? #t]
3349Return an object representing local file @var{file} to add to the store; this
3350object can be used in a gexp. @var{file} will be added to the store under @var{name}--by
3351default the base name of @var{file}.
3352
3353When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
3354designates a flat file and @var{recursive?} is true, its contents are added, and its
3355permission bits are kept.
3356
3357This is the declarative counterpart of the @code{interned-file} monadic
3358procedure (@pxref{The Store Monad, @code{interned-file}}).
3359@end deffn
3360
558e8b11
LC
3361@deffn {Scheme Procedure} plain-file @var{name} @var{content}
3362Return an object representing a text file called @var{name} with the given
3363@var{content} (a string) to be added to the store.
3364
3365This is the declarative counterpart of @code{text-file}.
3366@end deffn
3367
21b679f6
LC
3368@deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
3369Return an executable script @var{name} that runs @var{exp} using
3370@var{guile} with @var{modules} in its search path.
3371
3372The example below builds a script that simply invokes the @command{ls}
3373command:
3374
3375@example
3376(use-modules (guix gexp) (gnu packages base))
3377
3378(gexp->script "list-files"
3379 #~(execl (string-append #$coreutils "/bin/ls")
3380 "ls"))
3381@end example
3382
3383When ``running'' it through the store (@pxref{The Store Monad,
e20fd1bf 3384@code{run-with-store}}), we obtain a derivation that produces an
21b679f6
LC
3385executable file @file{/gnu/store/@dots{}-list-files} along these lines:
3386
3387@example
3388#!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
3389!#
3390(execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls")
3391 "ls")
3392@end example
3393@end deffn
3394
3395@deffn {Monadic Procedure} gexp->file @var{name} @var{exp}
3396Return a derivation that builds a file @var{name} containing @var{exp}.
3397
3398The resulting file holds references to all the dependencies of @var{exp}
3399or a subset thereof.
3400@end deffn
1ed19464
LC
3401
3402@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
3403Return as a monadic value a derivation that builds a text file
3404containing all of @var{text}. @var{text} may list, in addition to
d9ae938f
LC
3405strings, objects of any type that can be used in a gexp: packages,
3406derivations, local file objects, etc. The resulting store file holds
3407references to all these.
1ed19464
LC
3408
3409This variant should be preferred over @code{text-file} anytime the file
3410to create will reference items from the store. This is typically the
3411case when building a configuration file that embeds store file names,
3412like this:
3413
3414@example
3415(define (profile.sh)
3416 ;; Return the name of a shell script in the store that
3417 ;; initializes the 'PATH' environment variable.
3418 (text-file* "profile.sh"
3419 "export PATH=" coreutils "/bin:"
3420 grep "/bin:" sed "/bin\n"))
3421@end example
3422
3423In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
3424will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
3425preventing them from being garbage-collected during its lifetime.
3426@end deffn
21b679f6
LC
3427
3428Of course, in addition to gexps embedded in ``host'' code, there are
3429also modules containing build tools. To make it clear that they are
3430meant to be used in the build stratum, these modules are kept in the
3431@code{(guix build @dots{})} name space.
3432
c2b84676
LC
3433@cindex lowering, of high-level objects in gexps
3434Internally, high-level objects are @dfn{lowered}, using their compiler,
3435to either derivations or store items. For instance, lowering a package
3436yields a derivation, and lowering a @code{plain-file} yields a store
3437item. This is achieved using the @code{lower-object} monadic procedure.
3438
3439@deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
3440 [#:target #f]
3441Return as a value in @var{%store-monad} the derivation or store item
3442corresponding to @var{obj} for @var{system}, cross-compiling for
3443@var{target} if @var{target} is true. @var{obj} must be an object that
3444has an associated gexp compiler, such as a @code{<package>}.
3445@end deffn
3446
21b679f6 3447
568717fd
LC
3448@c *********************************************************************
3449@node Utilities
3450@chapter Utilities
3451
210cc920
LC
3452This section describes tools primarily targeted at developers and users
3453who write new package definitions. They complement the Scheme
3454programming interface of Guix in a convenient way.
3455
568717fd 3456@menu
37166310 3457* Invoking guix build:: Building packages from the command line.
39bee8a2 3458* Invoking guix edit:: Editing package definitions.
210cc920 3459* Invoking guix download:: Downloading a file and printing its hash.
37166310 3460* Invoking guix hash:: Computing the cryptographic hash of a file.
2f7d2d91 3461* Invoking guix import:: Importing package definitions.
37166310 3462* Invoking guix refresh:: Updating package definitions.
b4f5e0e8 3463* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 3464* Invoking guix size:: Profiling disk usage.
88856916 3465* Invoking guix graph:: Visualizing the graph of packages.
372c4bbc 3466* Invoking guix environment:: Setting up development environments.
aff8ce7c 3467* Invoking guix publish:: Sharing substitutes.
568717fd
LC
3468@end menu
3469
e49951eb
MW
3470@node Invoking guix build
3471@section Invoking @command{guix build}
568717fd 3472
e49951eb 3473The @command{guix build} command builds packages or derivations and
6798a8e4
LC
3474their dependencies, and prints the resulting store paths. Note that it
3475does not modify the user's profile---this is the job of the
e49951eb 3476@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
3477it is mainly useful for distribution developers.
3478
3479The general syntax is:
c78bd12b
LC
3480
3481@example
e49951eb 3482guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
3483@end example
3484
3485@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
3486the software distribution such as @code{coreutils} or
3487@code{coreutils-8.20}, or a derivation such as
834129e0 3488@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
3489package with the corresponding name (and optionally version) is searched
3490for among the GNU distribution modules (@pxref{Package Modules}).
3491
3492Alternatively, the @code{--expression} option may be used to specify a
3493Scheme expression that evaluates to a package; this is useful when
3494disambiguation among several same-named packages or package variants is
3495needed.
c78bd12b
LC
3496
3497The @var{options} may be zero or more of the following:
3498
3499@table @code
3500
3501@item --expression=@var{expr}
3502@itemx -e @var{expr}
ac5de156 3503Build the package or derivation @var{expr} evaluates to.
c78bd12b 3504
5401dd75 3505For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
3506guile-1.8)}, which unambiguously designates this specific variant of
3507version 1.8 of Guile.
3508
56b82106
LC
3509Alternately, @var{expr} may be a G-expression, in which case it is used
3510as a build program passed to @code{gexp->derivation}
3511(@pxref{G-Expressions}).
3512
3513Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
3514(@pxref{The Store Monad}). The procedure must return a derivation as a
3515monadic value, which is then passed through @code{run-with-store}.
3516
c78bd12b
LC
3517@item --source
3518@itemx -S
3519Build the packages' source derivations, rather than the packages
3520themselves.
3521
e49951eb 3522For instance, @code{guix build -S gcc} returns something like
834129e0 3523@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
c78bd12b 3524
f9cc8971
LC
3525The returned source tarball is the result of applying any patches and
3526code snippets specified in the package's @code{origin} (@pxref{Defining
3527Packages}).
3528
2cdfe13d
EB
3529@item --sources
3530Fetch and return the source of @var{package-or-derivation} and all their
3531dependencies, recursively. This is a handy way to obtain a local copy
3532of all the source code needed to build @var{packages}, allowing you to
3533eventually build them even without network access. It is an extension
3534of the @code{--source} option and can accept one of the following
3535optional argument values:
3536
3537@table @code
3538@item package
3539This value causes the @code{--sources} option to behave in the same way
3540as the @code{--source} option.
3541
3542@item all
3543Build all packages' source derivations, including any source that might
3544be listed as @code{inputs}. This is the default value.
3545
3546@example
3547$ guix build --sources tzdata
3548The following derivations will be built:
3549 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
3550 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
3551@end example
3552
3553@item transitive
3554Build all packages' source derivations, as well as all source
3555derivations for packages' transitive inputs. This can be used e.g. to
3556prefetch package source for later offline building.
3557
3558@example
3559$ guix build --sources=transitive tzdata
3560The following derivations will be built:
3561 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
3562 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
3563 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
3564 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
3565 /gnu/store/@dots{}-make-4.1.tar.xz.drv
3566 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
3567@dots{}
3568@end example
3569
3570@end table
3571
c78bd12b
LC
3572@item --system=@var{system}
3573@itemx -s @var{system}
3574Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
3575the host's system type.
3576
3577An example use of this is on Linux-based systems, which can emulate
3578different personalities. For instance, passing
3579@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
3580to build packages in a complete 32-bit environment.
3581
e55ec43d
LC
3582@item --target=@var{triplet}
3583@cindex cross-compilation
3584Cross-build for @var{triplet}, which must be a valid GNU triplet, such
3585as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
3586configuration triplets,, configure, GNU Configure and Build System}).
3587
7f3673f2
LC
3588@item --with-source=@var{source}
3589Use @var{source} as the source of the corresponding package.
3590@var{source} must be a file name or a URL, as for @command{guix
3591download} (@pxref{Invoking guix download}).
3592
3593The ``corresponding package'' is taken to be one specified on the
3594command line whose name matches the base of @var{source}---e.g., if
3595@var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
3596package is @code{guile}. Likewise, the version string is inferred from
3597@var{source}; in the previous example, it's @code{2.0.10}.
3598
3599This option allows users to try out versions of packages other than the
3600one provided by the distribution. The example below downloads
3601@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
3602the @code{ed} package:
3603
3604@example
3605guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
3606@end example
3607
3608As a developer, @code{--with-source} makes it easy to test release
3609candidates:
3610
3611@example
3612guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
3613@end example
3614
a43b55f1
LC
3615@dots{} or to build from a checkout in a pristine environment:
3616
3617@example
3618$ git clone git://git.sv.gnu.org/guix.git
3619$ guix build guix --with-source=./guix
3620@end example
3621
05962f29
LC
3622@item --no-grafts
3623Do not ``graft'' packages. In practice, this means that package updates
3624available as grafts are not applied. @xref{Security Updates}, for more
3625information on grafts.
7f3673f2 3626
c78bd12b
LC
3627@item --derivations
3628@itemx -d
3629Return the derivation paths, not the output paths, of the given
3630packages.
3631
70ee5642
LC
3632@item --root=@var{file}
3633@itemx -r @var{file}
3634Make @var{file} a symlink to the result, and register it as a garbage
3635collector root.
3636
3637@item --log-file
3f208ad7 3638Return the build log file names or URLs for the given
70ee5642
LC
3639@var{package-or-derivation}s, or raise an error if build logs are
3640missing.
3641
3642This works regardless of how packages or derivations are specified. For
3643instance, the following invocations are equivalent:
3644
3645@example
3646guix build --log-file `guix build -d guile`
3647guix build --log-file `guix build guile`
3648guix build --log-file guile
3649guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
3650@end example
3651
3f208ad7
LC
3652If a log is unavailable locally, and unless @code{--no-substitutes} is
3653passed, the command looks for a corresponding log on one of the
3654substitute servers (as specified with @code{--substitute-urls}.)
70ee5642 3655
3f208ad7
LC
3656So for instance, let's say you want to see the build log of GDB on MIPS
3657but you're actually on an @code{x86_64} machine:
3658
3659@example
3660$ guix build --log-file gdb -s mips64el-linux
3661http://hydra.gnu.org/log/@dots{}-gdb-7.10
3662@end example
3663
3664You can freely access a huge library of build logs!
70ee5642
LC
3665@end table
3666
3667@cindex common build options
3668In addition, a number of options that control the build process are
3669common to @command{guix build} and other commands that can spawn builds,
3670such as @command{guix package} or @command{guix archive}. These are the
3671following:
3672
3673@table @code
3674
300868ba
LC
3675@item --load-path=@var{directory}
3676@itemx -L @var{directory}
3677Add @var{directory} to the front of the package module search path
3678(@pxref{Package Modules}).
3679
3680This allows users to define their own packages and make them visible to
3681the command-line tools.
3682
c78bd12b
LC
3683@item --keep-failed
3684@itemx -K
3685Keep the build tree of failed builds. Thus, if a build fail, its build
3686tree is kept under @file{/tmp}, in a directory whose name is shown at
3687the end of the build log. This is useful when debugging build issues.
3688
3689@item --dry-run
3690@itemx -n
3691Do not build the derivations.
3692
56b1f4b7
LC
3693@item --fallback
3694When substituting a pre-built binary fails, fall back to building
3695packages locally.
3696
f8a8e0fe
LC
3697@item --substitute-urls=@var{urls}
3698@anchor{client-substitute-urls}
3699Consider @var{urls} the whitespace-separated list of substitute source
3700URLs, overriding the default list of URLs of @command{guix-daemon}
3701(@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
3702
3703This means that substitutes may be downloaded from @var{urls}, provided
3704they are signed by a key authorized by the system administrator
3705(@pxref{Substitutes}).
3706
c78bd12b 3707@item --no-substitutes
b5385b52 3708Do not use substitutes for build products. That is, always build things
c4202d60
LC
3709locally instead of allowing downloads of pre-built binaries
3710(@pxref{Substitutes}).
c78bd12b 3711
425b0bfc 3712@item --no-build-hook
4ec2e92d
LC
3713Do not attempt to offload builds @i{via} the daemon's ``build hook''
3714(@pxref{Daemon Offload Setup}). That is, always build things locally
3715instead of offloading builds to remote machines.
425b0bfc 3716
969e678e
LC
3717@item --max-silent-time=@var{seconds}
3718When the build or substitution process remains silent for more than
3719@var{seconds}, terminate it and report a build failure.
3720
002622b6
LC
3721@item --timeout=@var{seconds}
3722Likewise, when the build or substitution process lasts for more than
3723@var{seconds}, terminate it and report a build failure.
3724
3725By default there is no timeout. This behavior can be restored with
3726@code{--timeout=0}.
3727
07ab4bf1
LC
3728@item --verbosity=@var{level}
3729Use the given verbosity level. @var{level} must be an integer between 0
3730and 5; higher means more verbose output. Setting a level of 4 or more
3731may be helpful when debugging setup issues with the build daemon.
3732
70ee5642
LC
3733@item --cores=@var{n}
3734@itemx -c @var{n}
3735Allow the use of up to @var{n} CPU cores for the build. The special
3736value @code{0} means to use as many CPU cores as available.
bf421152 3737
f6526eb3
LC
3738@item --max-jobs=@var{n}
3739@itemx -M @var{n}
3740Allow at most @var{n} build jobs in parallel. @xref{Invoking
3741guix-daemon, @code{--max-jobs}}, for details about this option and the
3742equivalent @command{guix-daemon} option.
3743
c78bd12b
LC
3744@end table
3745
e49951eb 3746Behind the scenes, @command{guix build} is essentially an interface to
c78bd12b
LC
3747the @code{package-derivation} procedure of the @code{(guix packages)}
3748module, and to the @code{build-derivations} procedure of the @code{(guix
01d8ac64 3749derivations)} module.
c78bd12b 3750
16eb115e
DP
3751In addition to options explicitly passed on the command line,
3752@command{guix build} and other @command{guix} commands that support
3753building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
3754
3755@defvr {Environment Variable} GUIX_BUILD_OPTIONS
3756Users can define this variable to a list of command line options that
3757will automatically be used by @command{guix build} and other
3758@command{guix} commands that can perform builds, as in the example
3759below:
3760
3761@example
3762$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
3763@end example
3764
847391fe
DP
3765These options are parsed independently, and the result is appended to
3766the parsed command-line options.
16eb115e
DP
3767@end defvr
3768
3769
39bee8a2
LC
3770@node Invoking guix edit
3771@section Invoking @command{guix edit}
3772
3773@cindex package definition, editing
3774So many packages, so many source files! The @command{guix edit} command
3775facilitates the life of packagers by pointing their editor at the source
3776file containing the definition of the specified packages. For instance:
3777
3778@example
3779guix edit gcc-4.8 vim
3780@end example
3781
3782@noindent
3783launches the program specified in the @code{EDITOR} environment variable
3784to edit the recipe of GCC@tie{}4.8.4 and that of Vim.
3785
3786If you are using Emacs, note that the Emacs user interface provides
6248e326
AK
3787similar functionality in the ``package info'' and ``package list''
3788buffers created by @kbd{M-x guix-search-by-name} and similar commands
3789(@pxref{Emacs Commands}).
39bee8a2
LC
3790
3791
210cc920
LC
3792@node Invoking guix download
3793@section Invoking @command{guix download}
3794
3795When writing a package definition, developers typically need to download
3796the package's source tarball, compute its SHA256 hash, and write that
3797hash in the package definition (@pxref{Defining Packages}). The
3798@command{guix download} tool helps with this task: it downloads a file
3799from the given URI, adds it to the store, and prints both its file name
3800in the store and its SHA256 hash.
3801
3802The fact that the downloaded file is added to the store saves bandwidth:
3803when the developer eventually tries to build the newly defined package
3804with @command{guix build}, the source tarball will not have to be
3805downloaded again because it is already in the store. It is also a
3806convenient way to temporarily stash files, which may be deleted
3807eventually (@pxref{Invoking guix gc}).
3808
3809The @command{guix download} command supports the same URIs as used in
3810package definitions. In particular, it supports @code{mirror://} URIs.
3811@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
3812Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
3813they are not available, an error is raised. @xref{Guile Preparations,
3814how to install the GnuTLS bindings for Guile,, gnutls-guile,
3815GnuTLS-Guile}, for more information.
210cc920
LC
3816
3817The following option is available:
3818
3819@table @code
3820@item --format=@var{fmt}
3821@itemx -f @var{fmt}
3822Write the hash in the format specified by @var{fmt}. For more
081145cf 3823information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
210cc920
LC
3824@end table
3825
6c365eca
NK
3826@node Invoking guix hash
3827@section Invoking @command{guix hash}
3828
210cc920 3829The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
3830It is primarily a convenience tool for anyone contributing to the
3831distribution: it computes the cryptographic hash of a file, which can be
3832used in the definition of a package (@pxref{Defining Packages}).
3833
3834The general syntax is:
3835
3836@example
3837guix hash @var{option} @var{file}
3838@end example
3839
3840@command{guix hash} has the following option:
3841
3842@table @code
3843
3844@item --format=@var{fmt}
3845@itemx -f @var{fmt}
210cc920 3846Write the hash in the format specified by @var{fmt}.
6c365eca
NK
3847
3848Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
3849(@code{hex} and @code{hexadecimal} can be used as well).
3850
3851If the @option{--format} option is not specified, @command{guix hash}
3852will output the hash in @code{nix-base32}. This representation is used
3853in the definitions of packages.
3854
3140f2df
LC
3855@item --recursive
3856@itemx -r
3857Compute the hash on @var{file} recursively.
3858
3859In this case, the hash is computed on an archive containing @var{file},
3860including its children if it is a directory. Some of @var{file}'s
3861meta-data is part of the archive; for instance, when @var{file} is a
3862regular file, the hash is different depending on whether @var{file} is
3863executable or not. Meta-data such as time stamps has no impact on the
3864hash (@pxref{Invoking guix archive}).
3865@c FIXME: Replace xref above with xref to an ``Archive'' section when
3866@c it exists.
3867
6c365eca
NK
3868@end table
3869
2f7d2d91
LC
3870@node Invoking guix import
3871@section Invoking @command{guix import}
3872
3873@cindex importing packages
3874@cindex package import
3875@cindex package conversion
3876The @command{guix import} command is useful for people willing to add a
3877package to the distribution but who'd rather do as little work as
3878possible to get there---a legitimate demand. The command knows of a few
3879repositories from which it can ``import'' package meta-data. The result
3880is a package definition, or a template thereof, in the format we know
3881(@pxref{Defining Packages}).
3882
3883The general syntax is:
3884
3885@example
3886guix import @var{importer} @var{options}@dots{}
3887@end example
3888
3889@var{importer} specifies the source from which to import package
3890meta-data, and @var{options} specifies a package identifier and other
3891options specific to @var{importer}. Currently, the available
3892``importers'' are:
3893
3894@table @code
3895@item gnu
3896Import meta-data for the given GNU package. This provides a template
3897for the latest version of that GNU package, including the hash of its
3898source tarball, and its canonical synopsis and description.
3899
3900Additional information such as the package's dependencies and its
3901license needs to be figured out manually.
3902
3903For example, the following command returns a package definition for
3904GNU@tie{}Hello:
3905
3906@example
3907guix import gnu hello
3908@end example
3909
3910Specific command-line options are:
3911
3912@table @code
3913@item --key-download=@var{policy}
3914As for @code{guix refresh}, specify the policy to handle missing OpenPGP
3915keys when verifying the package's signature. @xref{Invoking guix
3916refresh, @code{--key-download}}.
3917@end table
3918
3919@item pypi
3920@cindex pypi
3921Import meta-data from the @uref{https://pypi.python.org/, Python Package
3922Index}@footnote{This functionality requires Guile-JSON to be installed.
3923@xref{Requirements}.}. Information is taken from the JSON-formatted
3924description available at @code{pypi.python.org} and usually includes all
3925the relevant information, including package dependencies.
3926
3927The command below imports meta-data for the @code{itsdangerous} Python
3928package:
3929
3930@example
3931guix import pypi itsdangerous
3932@end example
3933
3aae8145
DT
3934@item gem
3935@cindex gem
3936Import meta-data from @uref{https://rubygems.org/,
3937RubyGems}@footnote{This functionality requires Guile-JSON to be
3938installed. @xref{Requirements}.}. Information is taken from the
3939JSON-formatted description available at @code{rubygems.org} and includes
3940most relevant information, including runtime dependencies. There are
3941some caveats, however. The meta-data doesn't distinguish between
3942synopses and descriptions, so the same string is used for both fields.
3943Additionally, the details of non-Ruby dependencies required to build
3944native extensions is unavailable and left as an exercise to the
3945packager.
3946
3947The command below imports meta-data for the @code{rails} Ruby package:
3948
3949@example
3950guix import gem rails
3951@end example
3952
d45dc6da
EB
3953@item cpan
3954@cindex CPAN
3955Import meta-data from @uref{https://www.metacpan.org/, MetaCPAN}.
3956Information is taken from the JSON-formatted meta-data provided through
3957@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
3958relevant information, such as module dependencies. License information
3959should be checked closely. If Perl is available in the store, then the
3960@code{corelist} utility will be used to filter core modules out of the
3961list of dependencies.
d45dc6da
EB
3962
3963The command command below imports meta-data for the @code{Acme::Boolean}
3964Perl module:
3965
3966@example
3967guix import cpan Acme::Boolean
3968@end example
3969
e1248602
RW
3970@item cran
3971@cindex CRAN
3972Import meta-data from @uref{http://cran.r-project.org/, CRAN}, the
3973central repository for the @uref{http://r-project.org, GNU@tie{}R
3974statistical and graphical environment}.
3975
3976Information is extracted from the HTML package description.
3977
3978The command command below imports meta-data for the @code{Cairo}
3979R package:
3980
3981@example
3982guix import cran Cairo
3983@end example
3984
2f7d2d91
LC
3985@item nix
3986Import meta-data from a local copy of the source of the
3987@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
3988relies on the @command{nix-instantiate} command of
3989@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
3990typically written in a mixture of Nix-language and Bash code. This
3991command only imports the high-level package structure that is written in
3992the Nix language. It normally includes all the basic fields of a
3993package definition.
3994
3995When importing a GNU package, the synopsis and descriptions are replaced
3996by their canonical upstream variant.
3997
3998As an example, the command below imports the package definition of
3999LibreOffice (more precisely, it imports the definition of the package
4000bound to the @code{libreoffice} top-level attribute):
4001
4002@example
4003guix import nix ~/path/to/nixpkgs libreoffice
4004@end example
863af4e1
FB
4005
4006@item hackage
4007@cindex hackage
4008Import meta-data from Haskell community's central package archive
4009@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4010Cabal files and includes all the relevant information, including package
4011dependencies.
4012
4013Specific command-line options are:
4014
4015@table @code
a4154748
FB
4016@item --stdin
4017@itemx -s
4018Read a Cabal file from the standard input.
863af4e1
FB
4019@item --no-test-dependencies
4020@itemx -t
a4154748
FB
4021Do not include dependencies required by the test suites only.
4022@item --cabal-environment=@var{alist}
4023@itemx -e @var{alist}
4024@var{alist} is a Scheme alist defining the environment in which the
4025Cabal conditionals are evaluated. The accepted keys are: @code{os},
4026@code{arch}, @code{impl} and a string representing the name of a flag.
4027The value associated with a flag has to be either the symbol
4028@code{true} or @code{false}. The value associated with other keys
4029has to conform to the Cabal file format definition. The default value
4030associated with the keys @code{os}, @code{arch} and @code{impl} is
4031@samp{linux}, @samp{x86_64} and @samp{ghc} respectively.
863af4e1
FB
4032@end table
4033
4034The command below imports meta-data for the latest version of the
a4154748
FB
4035@code{HTTP} Haskell package without including test dependencies and
4036specifying the value of the flag @samp{network-uri} as @code{false}:
863af4e1
FB
4037
4038@example
a4154748 4039guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
863af4e1
FB
4040@end example
4041
4042A specific package version may optionally be specified by following the
4043package name by a hyphen and a version number as in the following example:
4044
4045@example
4046guix import hackage mtl-2.1.3.1
4047@end example
7f74a931
FB
4048
4049@item elpa
4050@cindex elpa
4051Import meta-data from an Emacs Lisp Package Archive (ELPA) package
4052repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4053
4054Specific command-line options are:
4055
4056@table @code
4057@item --archive=@var{repo}
4058@itemx -a @var{repo}
4059@var{repo} identifies the archive repository from which to retrieve the
4060information. Currently the supported repositories and their identifiers
4061are:
4062@itemize -
4063@item
840bd1d3 4064@uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7f74a931
FB
4065identifier. This is the default.
4066
4067@item
840bd1d3 4068@uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7f74a931
FB
4069@code{melpa-stable} identifier.
4070
4071@item
840bd1d3 4072@uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7f74a931
FB
4073identifier.
4074@end itemize
4075@end table
2f7d2d91
LC
4076@end table
4077
4078The structure of the @command{guix import} code is modular. It would be
4079useful to have more importers for other package formats, and your help
4080is welcome here (@pxref{Contributing}).
4081
37166310
LC
4082@node Invoking guix refresh
4083@section Invoking @command{guix refresh}
4084
4085The primary audience of the @command{guix refresh} command is developers
4086of the GNU software distribution. By default, it reports any packages
4087provided by the distribution that are outdated compared to the latest
4088upstream version, like this:
4089
4090@example
4091$ guix refresh
4092gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
4093gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
4094@end example
4095
4096It does so by browsing each package's FTP directory and determining the
4097highest version number of the source tarballs
4098therein@footnote{Currently, this only works for GNU packages.}.
4099
4100When passed @code{--update}, it modifies distribution source files to
4101update the version numbers and source tarball hashes of those packages'
4102recipes (@pxref{Defining Packages}). This is achieved by downloading
4103each package's latest source tarball and its associated OpenPGP
4104signature, authenticating the downloaded tarball against its signature
4105using @command{gpg}, and finally computing its hash. When the public
4106key used to sign the tarball is missing from the user's keyring, an
4107attempt is made to automatically retrieve it from a public key server;
4108when it's successful, the key is added to the user's keyring; otherwise,
4109@command{guix refresh} reports an error.
4110
4111The following options are supported:
4112
4113@table @code
4114
4115@item --update
4116@itemx -u
4117Update distribution source files (package recipes) in place.
081145cf 4118@xref{Defining Packages}, for more information on package definitions.
37166310
LC
4119
4120@item --select=[@var{subset}]
4121@itemx -s @var{subset}
4122Select all the packages in @var{subset}, one of @code{core} or
4123@code{non-core}.
4124
4125The @code{core} subset refers to all the packages at the core of the
4126distribution---i.e., packages that are used to build ``everything
4127else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
4128changing one of these packages in the distribution entails a rebuild of
4129all the others. Thus, such updates are an inconvenience to users in
4130terms of build time or bandwidth used to achieve the upgrade.
4131
4132The @code{non-core} subset refers to the remaining packages. It is
4133typically useful in cases where an update of the core packages would be
4134inconvenient.
4135
4136@end table
4137
4138In addition, @command{guix refresh} can be passed one or more package
4139names, as in this example:
4140
4141@example
4b9b3cbb 4142guix refresh -u emacs idutils gcc-4.8.4
37166310
LC
4143@end example
4144
4145@noindent
4146The command above specifically updates the @code{emacs} and
4147@code{idutils} packages. The @code{--select} option would have no
4148effect in this case.
4149
7d193ec3
EB
4150When considering whether to upgrade a package, it is sometimes
4151convenient to know which packages would be affected by the upgrade and
4152should be checked for compatibility. For this the following option may
4153be used when passing @command{guix refresh} one or more package names:
4154
4155@table @code
4156
4157@item --list-dependent
4158@itemx -l
4159List top-level dependent packages that would need to be rebuilt as a
4160result of upgrading one or more packages.
4161
4162@end table
4163
4164Be aware that the @code{--list-dependent} option only
4165@emph{approximates} the rebuilds that would be required as a result of
4166an upgrade. More rebuilds might be required under some circumstances.
4167
4168@example
7779ab61
LC
4169$ guix refresh --list-dependent flex
4170Building the following 120 packages would ensure 213 dependent packages are rebuilt:
4171hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
4172@end example
4173
4174The command above lists a set of packages that could be built to check
4175for compatibility with an upgraded @code{flex} package.
4176
f9230085
LC
4177The following options can be used to customize GnuPG operation:
4178
4179@table @code
4180
f9230085
LC
4181@item --gpg=@var{command}
4182Use @var{command} as the GnuPG 2.x command. @var{command} is searched
4183for in @code{$PATH}.
4184
2bc53ba9
LC
4185@item --key-download=@var{policy}
4186Handle missing OpenPGP keys according to @var{policy}, which may be one
4187of:
4188
4189@table @code
4190@item always
4191Always download missing OpenPGP keys from the key server, and add them
4192to the user's GnuPG keyring.
4193
4194@item never
4195Never try to download missing OpenPGP keys. Instead just bail out.
4196
4197@item interactive
4198When a package signed with an unknown OpenPGP key is encountered, ask
4199the user whether to download it or not. This is the default behavior.
4200@end table
4201
4202@item --key-server=@var{host}
4203Use @var{host} as the OpenPGP key server when importing a public key.
4204
f9230085
LC
4205@end table
4206
b4f5e0e8
CR
4207@node Invoking guix lint
4208@section Invoking @command{guix lint}
4209The @command{guix lint} is meant to help package developers avoid common
873c4085
LC
4210errors and use a consistent style. It runs a number of checks on a
4211given set of packages in order to find common mistakes in their
4212definitions. Available @dfn{checkers} include (see
4213@code{--list-checkers} for a complete list):
4214
4215@table @code
4216@item synopsis
4217@itemx description
4218Validate certain typographical and stylistic rules about package
4219descriptions and synopses.
4220
4221@item inputs-should-be-native
4222Identify inputs that should most likely be native inputs.
4223
4224@item source
4225@itemx home-page
50f5c46d 4226@itemx source-file-name
873c4085 4227Probe @code{home-page} and @code{source} URLs and report those that are
50f5c46d
EB
4228invalid. Check that the source file name is meaningful, e.g. is not
4229just a version number or ``git-checkout'', and should not have a
4230@code{file-name} declared (@pxref{origin Reference}).
40a7d4e5
LC
4231
4232@item formatting
4233Warn about obvious source code formatting issues: trailing white space,
4234use of tabulations, etc.
873c4085 4235@end table
b4f5e0e8
CR
4236
4237The general syntax is:
4238
4239@example
4240guix lint @var{options} @var{package}@dots{}
4241@end example
4242
4243If no package is given on the command line, then all packages are checked.
4244The @var{options} may be zero or more of the following:
4245
4246@table @code
4247
dd7c013d
CR
4248@item --checkers
4249@itemx -c
4250Only enable the checkers specified in a comma-separated list using the
4251names returned by @code{--list-checkers}.
4252
b4f5e0e8
CR
4253@item --list-checkers
4254@itemx -l
4255List and describe all the available checkers that will be run on packages
4256and exit.
4257
4258@end table
37166310 4259
fcc58db6
LC
4260@node Invoking guix size
4261@section Invoking @command{guix size}
4262
4263The @command{guix size} command helps package developers profile the
4264disk usage of packages. It is easy to overlook the impact of an
4265additional dependency added to a package, or the impact of using a
4266single output for a package that could easily be split (@pxref{Packages
4267with Multiple Outputs}). These are the typical issues that
4268@command{guix size} can highlight.
4269
4270The command can be passed a package specification such as @code{gcc-4.8}
4271or @code{guile:debug}, or a file name in the store. Consider this
4272example:
4273
4274@example
4275$ guix size coreutils
4276store item total self
4277/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
4278/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
4279/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
4280/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
4281/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
4282/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
4283@end example
4284
4285@cindex closure
4286The store items listed here constitute the @dfn{transitive closure} of
4287Coreutils---i.e., Coreutils and all its dependencies, recursively---as
4288would be returned by:
4289
4290@example
4291$ guix gc -R /gnu/store/@dots{}-coreutils-8.23
4292@end example
4293
4294Here the output shows 3 columns next to store items. The first column,
4295labeled ``total'', shows the size in mebibytes (MiB) of the closure of
4296the store item---that is, its own size plus the size of all its
4297dependencies. The next column, labeled ``self'', shows the size of the
4298item itself. The last column shows the ratio of the item's size to the
4299space occupied by all the items listed here.
4300
4301In this example, we see that the closure of Coreutils weighs in at
430270@tie{}MiB, half of which is taken by libc. (That libc represents a
4303large fraction of the closure is not a problem @i{per se} because it is
4304always available on the system anyway.)
4305
4306When the package passed to @command{guix size} is available in the
4307store, @command{guix size} queries the daemon to determine its
4308dependencies, and measures its size in the store, similar to @command{du
4309-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
4310Coreutils}).
4311
4312When the given package is @emph{not} in the store, @command{guix size}
4313reports information based on information about the available substitutes
4314(@pxref{Substitutes}). This allows it to profile disk usage of store
4315items that are not even on disk, only available remotely.
4316
a8f996c6 4317The available options are:
fcc58db6
LC
4318
4319@table @option
4320
d490d06e
LC
4321@item --substitute-urls=@var{urls}
4322Use substitute information from @var{urls}.
4323@xref{client-substitute-urls, the same option for @code{guix build}}.
4324
a8f996c6
LC
4325@item --map-file=@var{file}
4326Write to @var{file} a graphical map of disk usage as a PNG file.
4327
4328For the example above, the map looks like this:
4329
4330@image{images/coreutils-size-map,5in,, map of Coreutils disk usage
4331produced by @command{guix size}}
4332
4333This option requires that
4334@uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
4335installed and visible in Guile's module search path. When that is not
4336the case, @command{guix size} fails as it tries to load it.
4337
fcc58db6
LC
4338@item --system=@var{system}
4339@itemx -s @var{system}
4340Consider packages for @var{system}---e.g., @code{x86_64-linux}.
4341
4342@end table
4343
88856916
LC
4344@node Invoking guix graph
4345@section Invoking @command{guix graph}
4346
4347@cindex DAG
4348Packages and their dependencies form a @dfn{graph}, specifically a
4349directed acyclic graph (DAG). It can quickly become difficult to have a
4350mental model of the package DAG, so the @command{guix graph} command is
4351here to provide a visual representation of the DAG. @command{guix
4352graph} emits a DAG representation in the input format of
4353@uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
4354directly to Graphviz's @command{dot} command, for instance. The general
4355syntax is:
4356
4357@example
4358guix graph @var{options} @var{package}@dots{}
4359@end example
4360
4361For example, the following command generates a PDF file representing the
4362package DAG for the GNU@tie{}Core Utilities, showing its build-time
4363dependencies:
4364
4365@example
4366guix graph coreutils | dot -Tpdf > dag.pdf
4367@end example
4368
4369The output looks like this:
4370
4371@image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
4372
4373Nice little graph, no?
4374
4375But there's more than one graph! The one above is concise: it's the
4376graph of package objects, omitting implicit inputs such as GCC, libc,
4377grep, etc. It's often useful to have such a concise graph, but
4378sometimes you want to see more details. @command{guix graph} supports
4379several types of graphs, allowing you to choose the level of details:
4380
4381@table @code
4382@item package
4383This is the default type, the one we used above. It shows the DAG of
4384package objects, excluding implicit dependencies. It is concise, but
4385filters out many details.
4386
4387@item bag-emerged
4388This is the package DAG, @emph{including} implicit inputs.
4389
4390For instance, the following command:
4391
4392@example
4393guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
4394@end example
4395
4396... yields this bigger graph:
4397
4398@image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
4399
4400At the bottom of the graph, we see all the implicit inputs of
4401@var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
4402
4403Now, note that the dependencies of those implicit inputs---that is, the
4404@dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
4405here, for conciseness.
4406
4407@item bag
4408Similar to @code{bag-emerged}, but this time including all the bootstrap
4409dependencies.
4410
4411@item derivations
4412This is the most detailed representation: It shows the DAG of
4413derivations (@pxref{Derivations}) and plain store items. Compared to
4414the above representation, many additional nodes are visible, including
4415builds scripts, patches, Guile modules, etc.
4416
4417@end table
4418
4419All the above types correspond to @emph{build-time dependencies}. The
4420following graph type represents the @emph{run-time dependencies}:
4421
4422@table @code
4423@item references
4424This is the graph of @dfn{references} of a package output, as returned
4425by @command{guix gc --references} (@pxref{Invoking guix gc}).
4426
4427If the given package output is not available in the store, @command{guix
4428graph} attempts to obtain dependency information from substitutes.
4429@end table
4430
4431The available options are the following:
4432
4433@table @option
4434@item --type=@var{type}
4435@itemx -t @var{type}
4436Produce a graph output of @var{type}, where @var{type} must be one of
4437the values listed above.
4438
4439@item --list-types
4440List the supported graph types.
4c8f997a
LC
4441
4442@item --expression=@var{expr}
4443@itemx -e @var{expr}
4444Consider the package @var{expr} evaluates to.
4445
4446This is useful to precisely refer to a package, as in this example:
4447
4448@example
4449guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
4450@end example
88856916
LC
4451@end table
4452
4453
372c4bbc
DT
4454@node Invoking guix environment
4455@section Invoking @command{guix environment}
4456
f5fd4fd2 4457@cindex reproducible build environments
fe36d84e 4458@cindex development environments
372c4bbc
DT
4459The purpose of @command{guix environment} is to assist hackers in
4460creating reproducible development environments without polluting their
4461package profile. The @command{guix environment} tool takes one or more
4462packages, builds all of the necessary inputs, and creates a shell
4463environment to use them.
4464
4465The general syntax is:
4466
4467@example
4468guix environment @var{options} @var{package}@dots{}
4469@end example
4470
fe36d84e
LC
4471The following example spawns a new shell set up for the development of
4472GNU@tie{}Guile:
372c4bbc
DT
4473
4474@example
4475guix environment guile
4476@end example
4477
4478If the specified packages are not built yet, @command{guix environment}
4479automatically builds them. The new shell's environment is an augmented
4480version of the environment that @command{guix environment} was run in.
4481It contains the necessary search paths for building the given package
4482added to the existing environment variables. To create a ``pure''
4483environment in which the original environment variables have been unset,
50500f7c
LC
4484use the @code{--pure} option@footnote{Users sometimes wrongfully augment
4485environment variables such as @code{PATH} in their @file{~/.bashrc}
4486file. As a consequence, when @code{guix environment} launches it, Bash
4487may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
4488environment variables. It is an error to define such environment
4489variables in @file{.bashrc}; instead, they should be defined in
4490@file{.bash_profile}, which is sourced only by log-in shells.
4491@xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
4492details on Bash start-up files.}.
372c4bbc 4493
28de8d25
LC
4494@vindex GUIX_ENVIRONMENT
4495@command{guix environment} defines the @code{GUIX_ENVIRONMENT}
4496variable in the shell it spaws. This allows users to, say, define a
4497specific prompt for development environments in their @file{.bashrc}
4498(@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
4499
4500@example
4501if [ -n "$GUIX_ENVIRONMENT" ]
4502then
4503 export PS1="\u@@\h \w [dev]\$ "
4504fi
4505@end example
4506
372c4bbc
DT
4507Additionally, more than one package may be specified, in which case the
4508union of the inputs for the given packages are used. For example, the
4509command below spawns a shell where all of the dependencies of both Guile
4510and Emacs are available:
4511
4512@example
4513guix environment guile emacs
4514@end example
4515
4516Sometimes an interactive shell session is not desired. The
4517@code{--exec} option can be used to specify the command to run instead.
4518
4519@example
4520guix environment guile --exec=make
4521@end example
4522
fe36d84e
LC
4523In other situations, it is more convenient to specify the list of
4524packages needed in the environment. For example, the following command
4525runs @command{python} from an environment containing Python@tie{}2.7 and
4526NumPy:
4527
4528@example
4529guix environment --ad-hoc python2-numpy python-2.7 -E python
4530@end example
4531
4532The available options are summarized below.
372c4bbc
DT
4533
4534@table @code
4535@item --expression=@var{expr}
4536@itemx -e @var{expr}
4537Create an environment for the package that @var{expr} evaluates to.
4538
fe36d84e
LC
4539For example, running:
4540
4541@example
4542guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
4543@end example
4544
4545starts a shell with the environment for this specific variant of the
4546PETSc package.
4547
372c4bbc
DT
4548@item --load=@var{file}
4549@itemx -l @var{file}
4550Create an environment for the package that the code within @var{file}
4551evaluates to.
4552
fe36d84e
LC
4553As an example, @var{file} might contain a definition like this
4554(@pxref{Defining Packages}):
4555
4556@example
4557@verbatiminclude environment-gdb.scm
4558@end example
4559
4560
372c4bbc
DT
4561@item --exec=@var{command}
4562@item -E @var{command}
4563Execute @var{command} in the new environment.
4564
a54bd6d7
DT
4565@item --ad-hoc
4566Include all specified packages in the resulting environment, as if an
4567@i{ad hoc} package were defined with them as inputs. This option is
4568useful for quickly creating an environment without having to write a
4569package expression to contain the desired inputs.
4570
4571For instance, the command:
4572
4573@example
4574guix environment --ad-hoc guile guile-sdl -E guile
4575@end example
4576
4577runs @command{guile} in an environment where Guile and Guile-SDL are
4578available.
4579
417c39f1
LC
4580Note that this example implicitly asks for the default output of
4581@code{guile} and @code{guile-sdl} but it is possible to ask for a
4582specific output---e.g., @code{glib:bin} asks for the @code{bin} output
4583of @code{glib} (@pxref{Packages with Multiple Outputs}).
4584
372c4bbc
DT
4585@item --pure
4586Unset existing environment variables when building the new environment.
4587This has the effect of creating an environment in which search paths
4588only contain package inputs.
4589
4590@item --search-paths
4591Display the environment variable definitions that make up the
4592environment.
ce367ef3
LC
4593
4594@item --system=@var{system}
4595@itemx -s @var{system}
4596Attempt to build for @var{system}---e.g., @code{i686-linux}.
372c4bbc
DT
4597@end table
4598
4599It also supports all of the common build options that @command{guix
4600build} supports (@pxref{Invoking guix build, common build options}).
4601
aff8ce7c
DT
4602@node Invoking guix publish
4603@section Invoking @command{guix publish}
4604
4605The purpose of @command{guix publish} is to enable users to easily share
8ce229fc
LC
4606their store with others, which can then use it as a substitute server
4607(@pxref{Substitutes}).
4608
4609When @command{guix publish} runs, it spawns an HTTP server which allows
4610anyone with network access to obtain substitutes from it. This means
4611that any machine running Guix can also act as if it were a build farm,
4612since the HTTP interface is compatible with Hydra, the software behind
4613the @code{hydra.gnu.org} build farm.
aff8ce7c
DT
4614
4615For security, each substitute is signed, allowing recipients to check
4616their authenticity and integrity (@pxref{Substitutes}). Because
4617@command{guix publish} uses the system's signing key, which is only
5463fe51
LC
4618readable by the system administrator, it must be started as root; the
4619@code{--user} option makes it drop root privileges early on.
aff8ce7c
DT
4620
4621The general syntax is:
4622
4623@example
4624guix publish @var{options}@dots{}
4625@end example
4626
4627Running @command{guix publish} without any additional arguments will
4628spawn an HTTP server on port 8080:
4629
4630@example
4631guix publish
4632@end example
4633
4634Once a publishing server has been authorized (@pxref{Invoking guix
4635archive}), the daemon may download substitutes from it:
4636
4637@example
4638guix-daemon --substitute-urls=http://example.org:8080
4639@end example
4640
4641The following options are available:
4642
4643@table @code
4644@item --port=@var{port}
4645@itemx -p @var{port}
4646Listen for HTTP requests on @var{port}.
4647
9e2292ef
LC
4648@item --listen=@var{host}
4649Listen on the network interface for @var{host}. The default is to
4650accept connections from any interface.
4651
5463fe51
LC
4652@item --user=@var{user}
4653@itemx -u @var{user}
4654Change privileges to @var{user} as soon as possible---i.e., once the
4655server socket is open and the signing key has been read.
4656
aff8ce7c
DT
4657@item --repl[=@var{port}]
4658@itemx -r [@var{port}]
4659Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8ce229fc
LC
4660Reference Manual}) on @var{port} (37146 by default). This is used
4661primarily for debugging a running @command{guix publish} server.
aff8ce7c
DT
4662@end table
4663
a1ba8475
LC
4664@c *********************************************************************
4665@node GNU Distribution
4666@chapter GNU Distribution
4667
3ca2731c 4668@cindex Guix System Distribution
4705641f 4669@cindex GuixSD
3ca2731c
LC
4670Guix comes with a distribution of the GNU system consisting entirely of
4671free software@footnote{The term ``free'' here refers to the
a1ba8475 4672@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 4673users of that software}.}. The
35ed9306
LC
4674distribution can be installed on its own (@pxref{System Installation}),
4675but it is also possible to install Guix as a package manager on top of
4676an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c 4677between the two, we refer to the standalone distribution as the Guix
4705641f 4678System Distribution, or GuixSD.
35ed9306
LC
4679
4680The distribution provides core GNU packages such as GNU libc, GCC, and
4681Binutils, as well as many GNU and non-GNU applications. The complete
4682list of available packages can be browsed
093ae1be 4683@url{http://www.gnu.org/software/guix/packages,on-line} or by
d03bb653 4684running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
4685
4686@example
e49951eb 4687guix package --list-available
a1ba8475
LC
4688@end example
4689
35ed9306 4690Our goal has been to provide a practical 100% free software distribution of
401c53c4
LC
4691Linux-based and other variants of GNU, with a focus on the promotion and
4692tight integration of GNU components, and an emphasis on programs and
4693tools that help users exert that freedom.
4694
3ca2731c 4695Packages are currently available on the following platforms:
c320011d
LC
4696
4697@table @code
4698
4699@item x86_64-linux
4700Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
4701
4702@item i686-linux
4703Intel 32-bit architecture (IA32), Linux-Libre kernel;
4704
aa1e1947 4705@item armhf-linux
aa725117 4706ARMv7-A architecture with hard float, Thumb-2 and NEON,
aa1e1947
MW
4707using the EABI hard-float ABI, and Linux-Libre kernel.
4708
c320011d
LC
4709@item mips64el-linux
4710little-endian 64-bit MIPS processors, specifically the Loongson series,
4711n32 application binary interface (ABI), and Linux-Libre kernel.
4712
4713@end table
4714
4705641f 4715GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
3ca2731c 4716
c320011d
LC
4717@noindent
4718For information on porting to other architectures or kernels,
4719@xref{Porting}.
4720
401c53c4 4721@menu
5af6de3e 4722* System Installation:: Installing the whole operating system.
35ed9306 4723* System Configuration:: Configuring the operating system.
91ef73d4 4724* Installing Debugging Files:: Feeding the debugger.
05962f29 4725* Security Updates:: Deploying security fixes quickly.
401c53c4 4726* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 4727* Packaging Guidelines:: Growing the distribution.
401c53c4 4728* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 4729* Porting:: Targeting another platform or kernel.
401c53c4
LC
4730@end menu
4731
4732Building this distribution is a cooperative effort, and you are invited
081145cf 4733to join! @xref{Contributing}, for information about how you can help.
401c53c4 4734
5af6de3e
LC
4735@node System Installation
4736@section System Installation
4737
3ca2731c
LC
4738@cindex Guix System Distribution
4739This section explains how to install the Guix System Distribution
4740on a machine. The Guix package manager can
35ed9306
LC
4741also be installed on top of a running GNU/Linux system,
4742@pxref{Installation}.
5af6de3e
LC
4743
4744@ifinfo
4745@c This paragraph is for people reading this from tty2 of the
4746@c installation image.
4747You're reading this documentation with an Info reader. For details on
4748how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
6621cdb6 4749link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit
5af6de3e
LC
4750@kbd{l} afterwards to come back here.
4751@end ifinfo
4752
8aaaae38
LC
4753@subsection Limitations
4754
4705641f 4755As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
3ca2731c 4756not production-ready. It may contain bugs and lack important
8aaaae38
LC
4757features. Thus, if you are looking for a stable production system that
4758respects your freedom as a computer user, a good solution at this point
4759is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
4760more established GNU/Linux distributions}. We hope you can soon switch
4705641f 4761to the GuixSD without fear, of course. In the meantime, you can
8aaaae38
LC
4762also keep using your distribution and try out the package manager on top
4763of it (@pxref{Installation}).
4764
4765Before you proceed with the installation, be aware of the following
4766noteworthy limitations applicable to version @value{VERSION}:
4767
4768@itemize
4769@item
4770The installation process does not include a graphical user interface and
4771requires familiarity with GNU/Linux (see the following subsections to
4772get a feel of what that means.)
4773
4774@item
093ae1be
LC
4775The system does not yet provide full GNOME and KDE desktops. Xfce and
4776Enlightenment are available though, if graphical desktop environments
4777are your thing, as well as a number of X11 window managers.
8aaaae38
LC
4778
4779@item
dbcb0ab1 4780Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
4781
4782@item
4783Few system services are currently supported out-of-the-box
4784(@pxref{Services}).
4785
4786@item
093ae1be 4787More than 2,000 packages are available, but you may
8aaaae38
LC
4788occasionally find that a useful package is missing.
4789@end itemize
4790
4791You've been warned. But more than a disclaimer, this is an invitation
4792to report issues (and success stories!), and join us in improving it.
4793@xref{Contributing}, for more info.
5af6de3e
LC
4794
4795@subsection USB Stick Installation
4796
4797An installation image for USB sticks can be downloaded from
4705641f 4798@indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
4799where @var{system} is one of:
4800
4801@table @code
4802@item x86_64-linux
4803for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
4804
4805@item i686-linux
4806for a 32-bit GNU/Linux system on Intel-compatible CPUs.
4807@end table
4808
4809This image contains a single partition with the tools necessary for an
4810installation. It is meant to be copied @emph{as is} to a large-enough
4811USB stick.
4812
4813To copy the image to a USB stick, follow these steps:
4814
4815@enumerate
4816@item
4817Decompress the image using the @command{xz} command:
4818
4819@example
4705641f 4820xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
4821@end example
4822
4823@item
4824Insert a USB stick of 1@tie{}GiB or more in your machine, and determine
4825its device name. Assuming that USB stick is known as @file{/dev/sdX},
4826copy the image with:
4827
4828@example
4705641f 4829dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
4830@end example
4831
4832Access to @file{/dev/sdX} usually requires root privileges.
4833@end enumerate
4834
4835Once this is done, you should be able to reboot the system and boot from
4836the USB stick. The latter usually requires you to get in the BIOS' boot
4837menu, where you can choose to boot from the USB stick.
4838
4839@subsection Preparing for Installation
4840
4841Once you have successfully booted the image on the USB stick, you should
4842end up with a root prompt. Several console TTYs are configured and can
4843be used to run commands as root. TTY2 shows this documentation,
4844browsable using the Info reader commands (@pxref{Help,,, info, Info: An
4845Introduction}).
4846
4847To install the system, you would:
4848
4849@enumerate
4850
4851@item
152dd61c
LC
4852Configure the network, by running @command{ifconfig eno1 up && dhclient
4853eno1} (to get an automatically assigned IP address from the wired
4854network interface controller@footnote{
95c559c1
LC
4855@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
4856The name @code{eno1} is for the first on-board Ethernet controller. The
4857interface name for an Ethernet controller that is in the first slot of
4858the first PCI bus, for instance, would be @code{enp1s0}. Use
4859@command{ifconfig -a} to list all the available network interfaces.}),
4860or using the @command{ifconfig} command.
5af6de3e
LC
4861
4862The system automatically loads drivers for your network interface
4863controllers.
4864
4865Setting up network access is almost always a requirement because the
4866image does not contain all the software and tools that may be needed.
4867
4868@item
4869Unless this has already been done, you must partition and format the
4870target partitions.
4871
7ab44369
LC
4872Preferably, assign partitions a label so that you can easily and
4873reliably refer to them in @code{file-system} declarations (@pxref{File
4874Systems}). This is typically done using the @code{-L} option of
4875@command{mkfs.ext4} and related commands.
4876
5af6de3e 4877The installation image includes Parted (@pxref{Overview,,, parted, GNU
b419c7f5
LC
4878Parted User Manual}), @command{fdisk}, Cryptsetup/LUKS for disk
4879encryption, and e2fsprogs, the suite of tools to manipulate
4880ext2/ext3/ext4 file systems.
5af6de3e 4881
83a17b62
LC
4882@item
4883Once that is done, mount the target root partition under @file{/mnt}.
4884
4885@item
4886Lastly, run @code{deco start cow-store /mnt}.
4887
4888This will make @file{/gnu/store} copy-on-write, such that packages added
4889to it during the installation phase will be written to the target disk
4890rather than kept in memory.
4891
5af6de3e
LC
4892@end enumerate
4893
5af6de3e
LC
4894
4895@subsection Proceeding with the Installation
4896
4897With the target partitions ready, you now have to edit a file and
4898provide the declaration of the operating system to be installed. To
4899that end, the installation system comes with two text editors: GNU nano
4900(@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
4901It is better to store that file on the target root file system, say, as
4902@file{/mnt/etc/config.scm}.
4903
dd51caac
LC
4904@xref{Using the Configuration System}, for examples of operating system
4905configurations. These examples are available under
4906@file{/etc/configuration} in the installation image, so you can copy
4907them and use them as a starting point for your own configuration.
5af6de3e 4908
dd51caac
LC
4909Once you are done preparing the configuration file, the new system must
4910be initialized (remember that the target root file system is mounted
4911under @file{/mnt}):
5af6de3e
LC
4912
4913@example
4914guix system init /mnt/etc/config.scm /mnt
4915@end example
4916
4917@noindent
4918This will copy all the necessary files, and install GRUB on
4919@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 4920more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
4921downloads or builds of missing packages, which can take some time.
4922
1bd4e6db
LC
4923Once that command has completed---and hopefully succeeded!---you can run
4924@command{reboot} and boot into the new system. The @code{root} password
4925in the new system is initially empty; other users' passwords need to be
4926initialized by running the @command{passwd} command as @code{root},
4927unless your configuration specifies otherwise
4928(@pxref{user-account-password, user account passwords}).
4929
4930Join us on @code{#guix} on the Freenode IRC network or on
5af6de3e
LC
4931@file{guix-devel@@gnu.org} to share your experience---good or not so
4932good.
4933
4934@subsection Building the Installation Image
4935
4936The installation image described above was built using the @command{guix
4937system} command, specifically:
4938
4939@example
8a225c66 4940guix system disk-image --image-size=850MiB gnu/system/install.scm
5af6de3e
LC
4941@end example
4942
4943@xref{Invoking guix system}, for more information. See
4944@file{gnu/system/install.scm} in the source tree for more information
4945about the installation image.
4946
cf4a9129
LC
4947@node System Configuration
4948@section System Configuration
b208a005 4949
cf4a9129 4950@cindex system configuration
3ca2731c 4951The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
4952mechanism. By that we mean that all aspects of the global system
4953configuration---such as the available system services, timezone and
4954locale settings, user accounts---are declared in a single place. Such
4955a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 4956
cf4a9129
LC
4957One of the advantages of putting all the system configuration under the
4958control of Guix is that it supports transactional system upgrades, and
4959makes it possible to roll-back to a previous system instantiation,
4960should something go wrong with the new one (@pxref{Features}). Another
4961one is that it makes it easy to replicate the exact same configuration
4962across different machines, or at different points in time, without
4963having to resort to additional administration tools layered on top of
4964the system's own tools.
4965@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 4966
cf4a9129
LC
4967This section describes this mechanism. First we focus on the system
4968administrator's viewpoint---explaining how the system is configured and
4969instantiated. Then we show how this mechanism can be extended, for
4970instance to support new system services.
91ef73d4 4971
cf4a9129
LC
4972@menu
4973* Using the Configuration System:: Customizing your GNU system.
7313a52e 4974* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 4975* File Systems:: Configuring file system mounts.
510f9d86 4976* Mapped Devices:: Block device extra processing.
cf4a9129 4977* User Accounts:: Specifying user accounts.
598e19dc 4978* Locales:: Language and cultural convention settings.
cf4a9129 4979* Services:: Specifying system services.
0ae8c15a 4980* Setuid Programs:: Programs running with root privileges.
efb5e833 4981* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 4982* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 4983* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 4984* GRUB Configuration:: Configuring the boot loader.
cf4a9129
LC
4985* Invoking guix system:: Instantiating a system configuration.
4986* Defining Services:: Adding new service definitions.
4987@end menu
91ef73d4 4988
cf4a9129
LC
4989@node Using the Configuration System
4990@subsection Using the Configuration System
64d76fa6 4991
cf4a9129
LC
4992The operating system is configured by providing an
4993@code{operating-system} declaration in a file that can then be passed to
4994the @command{guix system} command (@pxref{Invoking guix system}). A
4995simple setup, with the default system services, the default Linux-Libre
4996kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 4997
cf4a9129
LC
4998@findex operating-system
4999@lisp
dd51caac 5000@include os-config-bare-bones.texi
cf4a9129 5001@end lisp
401c53c4 5002
cf4a9129
LC
5003This example should be self-describing. Some of the fields defined
5004above, such as @code{host-name} and @code{bootloader}, are mandatory.
5005Others, such as @code{packages} and @code{services}, can be omitted, in
5006which case they get a default value.
e7f34eb0 5007
cf4a9129
LC
5008@vindex %base-packages
5009The @code{packages} field lists
5010packages that will be globally visible on the system, for all user
5011accounts---i.e., in every user's @code{PATH} environment variable---in
5012addition to the per-user profiles (@pxref{Invoking guix package}). The
5013@var{%base-packages} variable provides all the tools one would expect
5014for basic user and administrator tasks---including the GNU Core
5015Utilities, the GNU Networking Utilities, the GNU Zile lightweight text
5016editor, @command{find}, @command{grep}, etc. The example above adds
5017Emacs to those, taken from the @code{(gnu packages emacs)} module
5018(@pxref{Package Modules}).
e7f34eb0 5019
cf4a9129
LC
5020@vindex %base-services
5021The @code{services} field lists @dfn{system services} to be made
5022available when the system starts (@pxref{Services}).
5023The @code{operating-system} declaration above specifies that, in
5024addition to the basic services, we want the @command{lshd} secure shell
5025daemon listening on port 2222, and allowing remote @code{root} logins
5026(@pxref{Invoking lshd,,, lsh, GNU lsh Manual}). Under the hood,
5027@code{lsh-service} arranges so that @code{lshd} is started with the
5028right command-line options, possibly with supporting configuration files
7313a52e
LC
5029generated as needed (@pxref{Defining Services}). @xref{operating-system
5030Reference}, for details about the available @code{operating-system}
5031fields.
a1ba8475 5032
dd51caac
LC
5033The configuration for a typical ``desktop'' usage, with the X11 display
5034server, a desktop environment, network management, an SSH server, and
5035more, would look like this:
5036
5037@lisp
5038@include os-config-desktop.texi
5039@end lisp
5040
5041@xref{Desktop Services}, for the exact list of services provided by
efb5e833
LC
5042@var{%desktop-services}. @xref{X.509 Certificates}, for background
5043information about the @code{nss-certs} package that is used here.
dd51caac 5044
cf4a9129
LC
5045Assuming the above snippet is stored in the @file{my-system-config.scm}
5046file, the @command{guix system reconfigure my-system-config.scm} command
5047instantiates that configuration, and makes it the default GRUB boot
5048entry (@pxref{Invoking guix system}). The normal way to change the
5049system's configuration is by updating this file and re-running the
5050@command{guix system} command.
b81e1947 5051
cf4a9129
LC
5052At the Scheme level, the bulk of an @code{operating-system} declaration
5053is instantiated with the following monadic procedure (@pxref{The Store
5054Monad}):
b81e1947 5055
cf4a9129
LC
5056@deffn {Monadic Procedure} operating-system-derivation os
5057Return a derivation that builds @var{os}, an @code{operating-system}
5058object (@pxref{Derivations}).
b81e1947 5059
cf4a9129
LC
5060The output of the derivation is a single directory that refers to all
5061the packages, configuration files, and other supporting files needed to
5062instantiate @var{os}.
5063@end deffn
b81e1947 5064
7313a52e
LC
5065@node operating-system Reference
5066@subsection @code{operating-system} Reference
5067
5068This section summarizes all the options available in
5069@code{operating-system} declarations (@pxref{Using the Configuration
5070System}).
5071
5072@deftp {Data Type} operating-system
5073This is the data type representing an operating system configuration.
5074By that, we mean all the global system configuration, not per-user
5075configuration (@pxref{Using the Configuration System}).
5076
5077@table @asis
5078@item @code{kernel} (default: @var{linux-libre})
fbb25e56 5079The package object of the operating system kernel to use@footnote{Currently
7313a52e
LC
5080only the Linux-libre kernel is supported. In the future, it will be
5081possible to use the GNU@tie{}Hurd.}.
5082
ee2a6304
LC
5083@item @code{kernel-arguments} (default: @code{'()})
5084List of strings or gexps representing additional arguments to pass on
5085the kernel's command-line---e.g., @code{("console=ttyS0")}.
5086
7313a52e 5087@item @code{bootloader}
88faf933 5088The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
5089
5090@item @code{initrd} (default: @code{base-initrd})
5091A two-argument monadic procedure that returns an initial RAM disk for
5092the Linux kernel. @xref{Initial RAM Disk}.
5093
f34c56be
LC
5094@item @code{firmware} (default: @var{%base-firmware})
5095@cindex firmware
5096List of firmware packages loadable by the operating system kernel.
5097
5098The default includes firmware needed for Atheros-based WiFi devices
5099(Linux-libre module @code{ath9k}.)
5100
7313a52e
LC
5101@item @code{host-name}
5102The host name.
5103
5104@item @code{hosts-file}
5105@cindex hosts file
24e02c28 5106A file-like object (@pxref{G-Expressions, file-like objects}) for use as
7313a52e 5107@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
24e02c28 5108Reference Manual}). The default is a file with entries for
7313a52e
LC
5109@code{localhost} and @var{host-name}.
5110
5111@item @code{mapped-devices} (default: @code{'()})
5112A list of mapped devices. @xref{Mapped Devices}.
5113
5114@item @code{file-systems}
5115A list of file systems. @xref{File Systems}.
5116
5117@item @code{swap-devices} (default: @code{'()})
5118@cindex swap devices
5119A list of strings identifying devices to be used for ``swap space''
5120(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
5121For example, @code{'("/dev/sda3")}.
5122
bf87f38a 5123@item @code{users} (default: @code{%base-user-accounts})
7313a52e
LC
5124@itemx @code{groups} (default: @var{%base-groups})
5125List of user accounts and groups. @xref{User Accounts}.
5126
5127@item @code{skeletons} (default: @code{(default-skeletons)})
5128A monadic list of pairs of target file name and files. These are the
5129files that will be used as skeletons as new accounts are created.
5130
5131For instance, a valid value may look like this:
5132
5133@example
5134(mlet %store-monad ((bashrc (text-file "bashrc" "\
5135 export PATH=$HOME/.guix-profile/bin")))
5136 (return `((".bashrc" ,bashrc))))
5137@end example
5138
5139@item @code{issue} (default: @var{%default-issue})
5140A string denoting the contents of the @file{/etc/issue} file, which is
5141what displayed when users log in on a text console.
5142
5143@item @code{packages} (default: @var{%base-packages})
5144The set of packages installed in the global profile, which is accessible
5145at @file{/run/current-system/profile}.
5146
5147The default set includes core utilities, but it is good practice to
5148install non-core utilities in user profiles (@pxref{Invoking guix
5149package}).
5150
5151@item @code{timezone}
5152A timezone identifying string---e.g., @code{"Europe/Paris"}.
5153
598e19dc
LC
5154@item @code{locale} (default: @code{"en_US.utf8"})
5155The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
5156Library Reference Manual}). @xref{Locales}, for more information.
5157
5158@item @code{locale-definitions} (default: @var{%default-locale-definitions})
5159The list of locale definitions to be compiled and that may be used at
5160run time. @xref{Locales}.
7313a52e 5161
996ed739
LC
5162@item @code{name-service-switch} (default: @var{%default-nss})
5163Configuration of libc's name service switch (NSS)---a
5164@code{<name-service-switch>} object. @xref{Name Service Switch}, for
5165details.
5166
7313a52e
LC
5167@item @code{services} (default: @var{%base-services})
5168A list of monadic values denoting system services. @xref{Services}.
5169
5170@item @code{pam-services} (default: @code{(base-pam-services)})
5171@cindex PAM
5172@cindex pluggable authentication modules
5173Linux @dfn{pluggable authentication module} (PAM) services.
5174@c FIXME: Add xref to PAM services section.
5175
5176@item @code{setuid-programs} (default: @var{%setuid-programs})
5177List of string-valued G-expressions denoting setuid programs.
5178@xref{Setuid Programs}.
5179
f5a9ffa0
AK
5180@item @code{sudoers-file} (default: @var{%sudoers-specification})
5181@cindex sudoers file
84765839
LC
5182The contents of the @file{/etc/sudoers} file as a file-like object
5183(@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7313a52e
LC
5184
5185This file specifies which users can use the @command{sudo} command, what
5186they are allowed to do, and what privileges they may gain. The default
5187is that only @code{root} and members of the @code{wheel} group may use
5188@code{sudo}.
5189
5190@end table
5191@end deftp
5192
cf4a9129
LC
5193@node File Systems
5194@subsection File Systems
b81e1947 5195
cf4a9129
LC
5196The list of file systems to be mounted is specified in the
5197@code{file-systems} field of the operating system's declaration
5198(@pxref{Using the Configuration System}). Each file system is declared
5199using the @code{file-system} form, like this:
b81e1947
LC
5200
5201@example
cf4a9129
LC
5202(file-system
5203 (mount-point "/home")
5204 (device "/dev/sda3")
5205 (type "ext4"))
b81e1947
LC
5206@end example
5207
cf4a9129
LC
5208As usual, some of the fields are mandatory---those shown in the example
5209above---while others can be omitted. These are described below.
b81e1947 5210
cf4a9129
LC
5211@deftp {Data Type} file-system
5212Objects of this type represent file systems to be mounted. They
5213contain the following members:
5ff3c4b8 5214
cf4a9129
LC
5215@table @asis
5216@item @code{type}
5217This is a string specifying the type of the file system---e.g.,
5218@code{"ext4"}.
5ff3c4b8 5219
cf4a9129
LC
5220@item @code{mount-point}
5221This designates the place where the file system is to be mounted.
b81e1947 5222
cf4a9129
LC
5223@item @code{device}
5224This names the ``source'' of the file system. By default it is the name
5225of a node under @file{/dev}, but its meaning depends on the @code{title}
5226field described below.
401c53c4 5227
cf4a9129
LC
5228@item @code{title} (default: @code{'device})
5229This is a symbol that specifies how the @code{device} field is to be
5230interpreted.
401c53c4 5231
cf4a9129
LC
5232When it is the symbol @code{device}, then the @code{device} field is
5233interpreted as a file name; when it is @code{label}, then @code{device}
5234is interpreted as a partition label name; when it is @code{uuid},
5235@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 5236
661a1d79
LC
5237UUIDs may be converted from their string representation (as shown by the
5238@command{tune2fs -l} command) using the @code{uuid} form, like this:
5239
5240@example
5241(file-system
5242 (mount-point "/home")
5243 (type "ext4")
5244 (title 'uuid)
5245 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
5246@end example
5247
cf4a9129 5248The @code{label} and @code{uuid} options offer a way to refer to disk
661a1d79
LC
5249partitions without having to hard-code their actual device
5250name@footnote{Note that, while it is tempting to use
5251@file{/dev/disk/by-uuid} and similar device names to achieve the same
5252result, this is not recommended: These special device nodes are created
5253by the udev daemon and may be unavailable at the time the device is
5254mounted.}.
da7cabd4 5255
5f86a66e
LC
5256However, when a file system's source is a mapped device (@pxref{Mapped
5257Devices}), its @code{device} field @emph{must} refer to the mapped
5258device name---e.g., @file{/dev/mapper/root-partition}---and consequently
5259@code{title} must be set to @code{'device}. This is required so that
5260the system knows that mounting the file system depends on having the
5261corresponding device mapping established.
5262
cf4a9129
LC
5263@item @code{flags} (default: @code{'()})
5264This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
5265include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
5266access to special files), @code{no-suid} (ignore setuid and setgid
5267bits), and @code{no-exec} (disallow program execution.)
da7cabd4 5268
cf4a9129
LC
5269@item @code{options} (default: @code{#f})
5270This is either @code{#f}, or a string denoting mount options.
da7cabd4 5271
cf4a9129
LC
5272@item @code{needed-for-boot?} (default: @code{#f})
5273This Boolean value indicates whether the file system is needed when
5274booting. If that is true, then the file system is mounted when the
5275initial RAM disk (initrd) is loaded. This is always the case, for
5276instance, for the root file system.
da7cabd4 5277
cf4a9129
LC
5278@item @code{check?} (default: @code{#t})
5279This Boolean indicates whether the file system needs to be checked for
5280errors before being mounted.
f9cc8971 5281
4e469051
LC
5282@item @code{create-mount-point?} (default: @code{#f})
5283When true, the mount point is created if it does not exist yet.
5284
e51710d1
LC
5285@item @code{dependencies} (default: @code{'()})
5286This is a list of @code{<file-system>} objects representing file systems
5287that must be mounted before (and unmounted after) this one.
5288
5289As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
5290a dependency of @file{/sys/fs/cgroup/cpu} and
5291@file{/sys/fs/cgroup/memory}.
5292
cf4a9129
LC
5293@end table
5294@end deftp
da7cabd4 5295
a69576ea
LC
5296The @code{(gnu system file-systems)} exports the following useful
5297variables.
5298
5299@defvr {Scheme Variable} %base-file-systems
5300These are essential file systems that are required on normal systems,
cc0e575a 5301such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
3392ce5d
LC
5302below.) Operating system declarations should always contain at least
5303these.
a69576ea
LC
5304@end defvr
5305
7f239fd3
LC
5306@defvr {Scheme Variable} %pseudo-terminal-file-system
5307This is the file system to be mounted as @file{/dev/pts}. It supports
5308@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
5309functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
5310Manual}). Pseudo-terminals are used by terminal emulators such as
5311@command{xterm}.
5312@end defvr
5313
db17ae5c
LC
5314@defvr {Scheme Variable} %shared-memory-file-system
5315This file system is mounted as @file{/dev/shm} and is used to support
5316memory sharing across processes (@pxref{Memory-mapped I/O,
5317@code{shm_open},, libc, The GNU C Library Reference Manual}).
5318@end defvr
5319
3392ce5d
LC
5320@defvr {Scheme Variable} %immutable-store
5321This file system performs a read-only ``bind mount'' of
5322@file{/gnu/store}, making it read-only for all the users including
5323@code{root}. This prevents against accidental modification by software
5324running as @code{root} or by system administrators.
5325
5326The daemon itself is still able to write to the store: it remounts it
5327read-write in its own ``name space.''
5328@end defvr
5329
a69576ea
LC
5330@defvr {Scheme Variable} %binary-format-file-system
5331The @code{binfmt_misc} file system, which allows handling of arbitrary
5332executable file types to be delegated to user space. This requires the
5333@code{binfmt.ko} kernel module to be loaded.
5334@end defvr
5335
5336@defvr {Scheme Variable} %fuse-control-file-system
5337The @code{fusectl} file system, which allows unprivileged users to mount
5338and unmount user-space FUSE file systems. This requires the
5339@code{fuse.ko} kernel module to be loaded.
5340@end defvr
5341
510f9d86
LC
5342@node Mapped Devices
5343@subsection Mapped Devices
5344
5345@cindex device mapping
5346@cindex mapped devices
5347The Linux kernel has a notion of @dfn{device mapping}: a block device,
5348such as a hard disk partition, can be @dfn{mapped} into another device,
5349with additional processing over the data that flows through
5350it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
5351concept of a ``mapped device'' and that of a file system: both boil down
5352to @emph{translating} input/output operations made on a file to
5353operations on its backing store. Thus, the Hurd implements mapped
5354devices, like file systems, using the generic @dfn{translator} mechanism
5355(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
5356typical example is encryption device mapping: all writes to the mapped
5357device are encrypted, and all reads are deciphered, transparently.
5358
5359Mapped devices are declared using the @code{mapped-device} form:
5360
5361@example
5362(mapped-device
5363 (source "/dev/sda3")
5364 (target "home")
5365 (type luks-device-mapping))
5366@end example
5367
5368@noindent
5369@cindex disk encryption
5370@cindex LUKS
5371This example specifies a mapping from @file{/dev/sda3} to
5372@file{/dev/mapper/home} using LUKS---the
5373@url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
5374standard mechanism for disk encryption. The @file{/dev/mapper/home}
5375device can then be used as the @code{device} of a @code{file-system}
5376declaration (@pxref{File Systems}). The @code{mapped-device} form is
5377detailed below.
5378
5379@deftp {Data Type} mapped-device
5380Objects of this type represent device mappings that will be made when
5381the system boots up.
5382
9cb426b8
LC
5383@table @code
5384@item source
510f9d86
LC
5385This string specifies the name of the block device to be mapped, such as
5386@code{"/dev/sda3"}.
5387
9cb426b8 5388@item target
510f9d86
LC
5389This string specifies the name of the mapping to be established. For
5390example, specifying @code{"my-partition"} will lead to the creation of
5391the @code{"/dev/mapper/my-partition"} device.
5392
9cb426b8 5393@item type
510f9d86
LC
5394This must be a @code{mapped-device-kind} object, which specifies how
5395@var{source} is mapped to @var{target}.
5396@end table
5397@end deftp
5398
5399@defvr {Scheme Variable} luks-device-mapping
5400This defines LUKS block device encryption using the @command{cryptsetup}
5401command, from the same-named package. This relies on the
5402@code{dm-crypt} Linux kernel module.
5403@end defvr
5404
cf4a9129
LC
5405@node User Accounts
5406@subsection User Accounts
ee85f3db 5407
9bea87a5
LC
5408User accounts and groups are entirely managed through the
5409@code{operating-system} declaration. They are specified with the
5410@code{user-account} and @code{user-group} forms:
ee85f3db 5411
cf4a9129
LC
5412@example
5413(user-account
5414 (name "alice")
5415 (group "users")
24e752c0
LC
5416 (supplementary-groups '("wheel" ;allow use of sudo, etc.
5417 "audio" ;sound card
5418 "video" ;video devices such as webcams
5419 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
5420 (comment "Bob's sister")
5421 (home-directory "/home/alice"))
5422@end example
25083588 5423
9bea87a5
LC
5424When booting or upon completion of @command{guix system reconfigure},
5425the system ensures that only the user accounts and groups specified in
5426the @code{operating-system} declaration exist, and with the specified
5427properties. Thus, account or group creations or modifications made by
5428directly invoking commands such as @command{useradd} are lost upon
5429reconfiguration or reboot. This ensures that the system remains exactly
5430as declared.
5431
cf4a9129
LC
5432@deftp {Data Type} user-account
5433Objects of this type represent user accounts. The following members may
5434be specified:
ee85f3db 5435
cf4a9129
LC
5436@table @asis
5437@item @code{name}
5438The name of the user account.
ee85f3db 5439
cf4a9129
LC
5440@item @code{group}
5441This is the name (a string) or identifier (a number) of the user group
5442this account belongs to.
ee85f3db 5443
cf4a9129
LC
5444@item @code{supplementary-groups} (default: @code{'()})
5445Optionally, this can be defined as a list of group names that this
5446account belongs to.
ee85f3db 5447
cf4a9129
LC
5448@item @code{uid} (default: @code{#f})
5449This is the user ID for this account (a number), or @code{#f}. In the
5450latter case, a number is automatically chosen by the system when the
5451account is created.
ee85f3db 5452
cf4a9129
LC
5453@item @code{comment} (default: @code{""})
5454A comment about the account, such as the account's owner full name.
c8c871d1 5455
cf4a9129
LC
5456@item @code{home-directory}
5457This is the name of the home directory for the account.
ee85f3db 5458
cf4a9129
LC
5459@item @code{shell} (default: Bash)
5460This is a G-expression denoting the file name of a program to be used as
5461the shell (@pxref{G-Expressions}).
ee85f3db 5462
cf4a9129
LC
5463@item @code{system?} (default: @code{#f})
5464This Boolean value indicates whether the account is a ``system''
5465account. System accounts are sometimes treated specially; for instance,
5466graphical login managers do not list them.
ee85f3db 5467
1bd4e6db 5468@anchor{user-account-password}
cf4a9129 5469@item @code{password} (default: @code{#f})
eb59595c
LC
5470You would normally leave this field to @code{#f}, initialize user
5471passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
5472users change it with @command{passwd}. Passwords set with
5473@command{passwd} are of course preserved across reboot and
5474reconfiguration.
eb59595c
LC
5475
5476If you @emph{do} want to have a preset password for an account, then
5477this field must contain the encrypted password, as a string.
5d1f1177
LC
5478@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
5479on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 5480Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 5481
cf4a9129
LC
5482@end table
5483@end deftp
ee85f3db 5484
cf4a9129 5485User group declarations are even simpler:
ee85f3db 5486
cf4a9129
LC
5487@example
5488(user-group (name "students"))
5489@end example
ee85f3db 5490
cf4a9129
LC
5491@deftp {Data Type} user-group
5492This type is for, well, user groups. There are just a few fields:
af8a56b8 5493
cf4a9129
LC
5494@table @asis
5495@item @code{name}
5496The group's name.
ee85f3db 5497
cf4a9129
LC
5498@item @code{id} (default: @code{#f})
5499The group identifier (a number). If @code{#f}, a new number is
5500automatically allocated when the group is created.
ee85f3db 5501
c8fa3426
LC
5502@item @code{system?} (default: @code{#f})
5503This Boolean value indicates whether the group is a ``system'' group.
5504System groups have low numerical IDs.
5505
cf4a9129
LC
5506@item @code{password} (default: @code{#f})
5507What, user groups can have a password? Well, apparently yes. Unless
5508@code{#f}, this field specifies the group's password.
ee85f3db 5509
cf4a9129
LC
5510@end table
5511@end deftp
401c53c4 5512
cf4a9129
LC
5513For convenience, a variable lists all the basic user groups one may
5514expect:
401c53c4 5515
cf4a9129
LC
5516@defvr {Scheme Variable} %base-groups
5517This is the list of basic user groups that users and/or packages expect
5518to be present on the system. This includes groups such as ``root'',
5519``wheel'', and ``users'', as well as groups used to control access to
5520specific devices such as ``audio'', ``disk'', and ``cdrom''.
5521@end defvr
401c53c4 5522
bf87f38a
LC
5523@defvr {Scheme Variable} %base-user-accounts
5524This is the list of basic system accounts that programs may expect to
5525find on a GNU/Linux system, such as the ``nobody'' account.
5526
5527Note that the ``root'' account is not included here. It is a
5528special-case and is automatically added whether or not it is specified.
5529@end defvr
5530
598e19dc
LC
5531@node Locales
5532@subsection Locales
5533
5534@cindex locale
5535A @dfn{locale} defines cultural conventions for a particular language
5536and region of the world (@pxref{Locales,,, libc, The GNU C Library
5537Reference Manual}). Each locale has a name that typically has the form
b2636518 5538@code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
598e19dc
LC
5539@code{fr_LU.utf8} designates the locale for the French language, with
5540cultural conventions from Luxembourg, and using the UTF-8 encoding.
5541
5542@cindex locale definition
5543Usually, you will want to specify the default locale for the machine
5544using the @code{locale} field of the @code{operating-system} declaration
5545(@pxref{operating-system Reference, @code{locale}}).
5546
5547That locale must be among the @dfn{locale definitions} that are known to
5548the system---and these are specified in the @code{locale-definitions}
5549slot of @code{operating-system}. The default value includes locale
5550definition for some widely used locales, but not for all the available
5551locales, in order to save space.
5552
5553If the locale specified in the @code{locale} field is not among the
5554definitions listed in @code{locale-definitions}, @command{guix system}
5555raises an error. In that case, you should add the locale definition to
5556the @code{locale-definitions} field. For instance, to add the North
5557Frisian locale for Germany, the value of that field may be:
5558
5559@example
5560(cons (locale-definition
5561 (name "fy_DE.utf8") (source "fy_DE"))
5562 %default-locale-definitions)
5563@end example
5564
5565Likewise, to save space, one might want @code{locale-definitions} to
5566list only the locales that are actually used, as in:
5567
5568@example
5569(list (locale-definition
5570 (name "ja_JP.eucjp") (source "ja_JP")
5571 (charset "EUC-JP")))
5572@end example
5573
5c3c1427
LC
5574@vindex LOCPATH
5575The compiled locale definitions are available at
5576@file{/run/current-system/locale}, which is the default location where
5577the GNU@tie{}libc looks for locale data. This can be overridden using
5578the @code{LOCPATH} environment variable (@pxref{locales-and-locpath,
5579@code{LOCPATH} and locale packages}).
5580
598e19dc
LC
5581The @code{locale-definition} form is provided by the @code{(gnu system
5582locale)} module. Details are given below.
5583
5584@deftp {Data Type} locale-definition
5585This is the data type of a locale definition.
5586
5587@table @asis
5588
5589@item @code{name}
5590The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
5591Reference Manual}, for more information on locale names.
5592
5593@item @code{source}
5594The name of the source for that locale. This is typically the
5595@code{@var{language}_@var{territory}} part of the locale name.
5596
5597@item @code{charset} (default: @code{"UTF-8"})
5598The ``character set'' or ``code set'' for that locale,
5599@uref{http://www.iana.org/assignments/character-sets, as defined by
5600IANA}.
5601
5602@end table
5603@end deftp
5604
5605@defvr {Scheme Variable} %default-locale-definitions
b2636518
LC
5606An arbitrary list of commonly used UTF-8 locales, used as the default
5607value of the @code{locale-definitions} field of @code{operating-system}
598e19dc 5608declarations.
b2636518
LC
5609
5610@cindex locale name
5611@cindex normalized codeset in locale names
5612These locale definitions use the @dfn{normalized codeset} for the part
5613that follows the dot in the name (@pxref{Using gettextized software,
5614normalized codeset,, libc, The GNU C Library Reference Manual}). So for
5615instance it has @code{uk_UA.utf8} but @emph{not}, say,
5616@code{uk_UA.UTF-8}.
598e19dc 5617@end defvr
401c53c4 5618
cf4a9129
LC
5619@node Services
5620@subsection Services
401c53c4 5621
cf4a9129
LC
5622@cindex system services
5623An important part of preparing an @code{operating-system} declaration is
5624listing @dfn{system services} and their configuration (@pxref{Using the
5625Configuration System}). System services are typically daemons launched
5626when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
5627configuring network access.
5628
5629Services are managed by GNU@tie{}dmd (@pxref{Introduction,,, dmd, GNU
5630dmd Manual}). On a running system, the @command{deco} command allows
5631you to list the available services, show their status, start and stop
5632them, or do other specific operations (@pxref{Jump Start,,, dmd, GNU dmd
5633Manual}). For example:
5634
5635@example
5636# deco status dmd
5637@end example
5638
5639The above command, run as @code{root}, lists the currently defined
5640services. The @command{deco doc} command shows a synopsis of the given
5641service:
5642
5643@example
5644# deco doc nscd
5645Run libc's name service cache daemon (nscd).
5646@end example
5647
5648The @command{start}, @command{stop}, and @command{restart} sub-commands
5649have the effect you would expect. For instance, the commands below stop
5650the nscd service and restart the Xorg display server:
5651
5652@example
5653# deco stop nscd
5654Service nscd has been stopped.
5655# deco restart xorg-server
5656Service xorg-server has been stopped.
5657Service xorg-server has been started.
5658@end example
401c53c4 5659
cf4a9129 5660The following sections document the available services, starting with
d8b94dbd
LC
5661the core services, that may be used in an @code{operating-system}
5662declaration.
401c53c4 5663
cf4a9129
LC
5664@menu
5665* Base Services:: Essential system services.
5666* Networking Services:: Network setup, SSH daemon, etc.
5667* X Window:: Graphical display.
fe1a39d3 5668* Desktop Services:: D-Bus and desktop services.
105369a4 5669* Database Services:: SQL databases.
58724c48 5670* Web Services:: Web servers.
aa4ed923 5671* Various Services:: Other services.
cf4a9129 5672@end menu
401c53c4 5673
cf4a9129
LC
5674@node Base Services
5675@subsubsection Base Services
a1ba8475 5676
cf4a9129
LC
5677The @code{(gnu services base)} module provides definitions for the basic
5678services that one expects from the system. The services exported by
5679this module are listed below.
401c53c4 5680
cf4a9129
LC
5681@defvr {Scheme Variable} %base-services
5682This variable contains a list of basic services@footnote{Technically,
5683this is a list of monadic services. @xref{The Store Monad}.} one would
5684expect from the system: a login service (mingetty) on each tty, syslogd,
5685libc's name service cache daemon (nscd), the udev device manager, and
5686more.
401c53c4 5687
cf4a9129
LC
5688This is the default value of the @code{services} field of
5689@code{operating-system} declarations. Usually, when customizing a
5690system, you will want to append services to @var{%base-services}, like
5691this:
401c53c4 5692
cf4a9129 5693@example
fa1e31b8 5694(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
5695@end example
5696@end defvr
401c53c4 5697
cf4a9129
LC
5698@deffn {Monadic Procedure} host-name-service @var{name}
5699Return a service that sets the host name to @var{name}.
5700@end deffn
401c53c4 5701
cf4a9129
LC
5702@deffn {Monadic Procedure} mingetty-service @var{tty} [#:motd] @
5703 [#:auto-login #f] [#:login-program] [#:login-pause? #f] @
5704 [#:allow-empty-passwords? #f]
5705Return a service to run mingetty on @var{tty}.
401c53c4 5706
cf4a9129
LC
5707When @var{allow-empty-passwords?} is true, allow empty log-in password. When
5708@var{auto-login} is true, it must be a user name under which to log-in
5709automatically. @var{login-pause?} can be set to @code{#t} in conjunction with
5710@var{auto-login}, in which case the user will have to press a key before the
5711login shell is launched.
401c53c4 5712
0081410d 5713When true, @var{login-program} is a gexp or a monadic gexp denoting the name
cf4a9129
LC
5714of the log-in program (the default is the @code{login} program from the Shadow
5715tool suite.)
401c53c4 5716
cf4a9129
LC
5717@var{motd} is a monadic value containing a text file to use as
5718the ``message of the day''.
5719@end deffn
401c53c4 5720
6454b333
LC
5721@cindex name service cache daemon
5722@cindex nscd
4aee6e60
LC
5723@deffn {Monadic Procedure} nscd-service [@var{config}] [#:glibc glibc] @
5724 [#:name-services '()]
5725Return a service that runs libc's name service cache daemon (nscd) with
5726the given @var{config}---an @code{<nscd-configuration>} object.
5727Optionally, @code{#:name-services} is a list of packages that provide
4c9050c6
LC
5728name service switch (NSS) modules needed by nscd. @xref{Name Service
5729Switch}, for an example.
cf4a9129 5730@end deffn
401c53c4 5731
6454b333
LC
5732@defvr {Scheme Variable} %nscd-default-configuration
5733This is the default @code{<nscd-configuration>} value (see below) used
5734by @code{nscd-service}. This uses the caches defined by
5735@var{%nscd-default-caches}; see below.
5736@end defvr
5737
5738@deftp {Data Type} nscd-configuration
5739This is the type representing the name service cache daemon (nscd)
5740configuration.
5741
5742@table @asis
5743
5744@item @code{log-file} (default: @code{"/var/log/nscd.log"})
5745Name of nscd's log file. This is where debugging output goes when
5746@code{debug-level} is strictly positive.
5747
5748@item @code{debug-level} (default: @code{0})
5749Integer denoting the debugging levels. Higher numbers mean more
5750debugging output is logged.
5751
5752@item @code{caches} (default: @var{%nscd-default-caches})
5753List of @code{<nscd-cache>} objects denoting things to be cached; see
5754below.
5755
5756@end table
5757@end deftp
5758
5759@deftp {Data Type} nscd-cache
5760Data type representing a cache database of nscd and its parameters.
5761
5762@table @asis
5763
5764@item @code{database}
5765This is a symbol representing the name of the database to be cached.
5766Valid values are @code{passwd}, @code{group}, @code{hosts}, and
5767@code{services}, which designate the corresponding NSS database
5768(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
5769
5770@item @code{positive-time-to-live}
5771@itemx @code{negative-time-to-live} (default: @code{20})
5772A number representing the number of seconds during which a positive or
5773negative lookup result remains in cache.
5774
5775@item @code{check-files?} (default: @code{#t})
5776Whether to check for updates of the files corresponding to
5777@var{database}.
5778
5779For instance, when @var{database} is @code{hosts}, setting this flag
5780instructs nscd to check for updates in @file{/etc/hosts} and to take
5781them into account.
5782
5783@item @code{persistent?} (default: @code{#t})
5784Whether the cache should be stored persistently on disk.
5785
5786@item @code{shared?} (default: @code{#t})
5787Whether the cache should be shared among users.
5788
5789@item @code{max-database-size} (default: 32@tie{}MiB)
5790Maximum size in bytes of the database cache.
5791
5792@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
5793@c settings, so leave them out.
5794
5795@end table
5796@end deftp
5797
5798@defvr {Scheme Variable} %nscd-default-caches
5799List of @code{<nscd-cache>} objects used by default by
5800@code{nscd-configuration} (see above.)
5801
5802It enables persistent and aggressive caching of service and host name
5803lookups. The latter provides better host name lookup performance,
5804resilience in the face of unreliable name servers, and also better
5805privacy---often the result of host name lookups is in local cache, so
5806external name servers do not even need to be queried.
5807@end defvr
5808
5809
1bb76f75
AK
5810@deffn {Monadic Procedure} syslog-service [#:config-file #f]
5811Return a service that runs @code{syslogd}. If configuration file name
5812@var{config-file} is not specified, use some reasonable default
cf4a9129
LC
5813settings.
5814@end deffn
401c53c4 5815
cf4a9129
LC
5816@deffn {Monadic Procedure} guix-service [#:guix guix] @
5817 [#:builder-group "guixbuild"] [#:build-accounts 10] @
02bb6b45 5818 [#:authorize-hydra-key? #t] [#:use-substitutes? #t] @
cf4a9129
LC
5819 [#:extra-options '()]
5820Return a service that runs the build daemon from @var{guix}, and has
5821@var{build-accounts} user accounts available under @var{builder-group}.
401c53c4 5822
cf4a9129
LC
5823When @var{authorize-hydra-key?} is true, the @code{hydra.gnu.org} public key
5824provided by @var{guix} is authorized upon activation, meaning that substitutes
5825from @code{hydra.gnu.org} are used by default.
401c53c4 5826
cf4a9129
LC
5827If @var{use-substitutes?} is false, the daemon is run with
5828@option{--no-substitutes} (@pxref{Invoking guix-daemon,
5829@option{--no-substitutes}}).
401c53c4 5830
cf4a9129
LC
5831Finally, @var{extra-options} is a list of additional command-line options
5832passed to @command{guix-daemon}.
5833@end deffn
a1ba8475 5834
cf4a9129
LC
5835@deffn {Monadic Procedure} udev-service [#:udev udev]
5836Run @var{udev}, which populates the @file{/dev} directory dynamically.
5837@end deffn
401c53c4 5838
5eca9459
AK
5839@deffn {Monadic Procedure} console-keymap-service @var{file}
5840Return a service to load console keymap from @var{file} using
5841@command{loadkeys} command.
5842@end deffn
5843
a69576ea 5844
cf4a9129
LC
5845@node Networking Services
5846@subsubsection Networking Services
401c53c4 5847
fa1e31b8 5848The @code{(gnu services networking)} module provides services to configure
cf4a9129 5849the network interface.
a1ba8475 5850
a023cca8
LC
5851@cindex DHCP, networking service
5852@deffn {Monadic Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
5853Return a service that runs @var{dhcp}, a Dynamic Host Configuration
5854Protocol (DHCP) client, on all the non-loopback network interfaces.
5855@end deffn
5856
cf4a9129
LC
5857@deffn {Monadic Procedure} static-networking-service @var{interface} @var{ip} @
5858 [#:gateway #f] [#:name-services @code{'()}]
5859Return a service that starts @var{interface} with address @var{ip}. If
5860@var{gateway} is true, it must be a string specifying the default network
5861gateway.
5862@end deffn
8b315a6d 5863
b7d0c494
MW
5864@cindex wicd
5865@deffn {Monadic Procedure} wicd-service [#:wicd @var{wicd}]
5866Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a
5867network manager that aims to simplify wired and wireless networking.
5868@end deffn
5869
63854bcb
LC
5870@deffn {Monadic Procedure} ntp-service [#:ntp @var{ntp}] @
5871 [#:name-service @var{%ntp-servers}]
5872Return a service that runs the daemon from @var{ntp}, the
5873@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
5874keep the system clock synchronized with that of @var{servers}.
5875@end deffn
5876
5877@defvr {Scheme Variable} %ntp-servers
5878List of host names used as the default NTP servers.
5879@end defvr
5880
cf4a9129
LC
5881@deffn {Monadic Procedure} tor-service [#:tor tor]
5882Return a service to run the @uref{https://torproject.org,Tor} daemon.
8b315a6d 5883
cf4a9129
LC
5884The daemon runs with the default settings (in particular the default exit
5885policy) as the @code{tor} unprivileged user.
5886@end deffn
8b315a6d 5887
4627a464
LC
5888@deffn {Monadic Procedure} bitlbee-service [#:bitlbee bitlbee] @
5889 [#:interface "127.0.0.1"] [#:port 6667] @
5890 [#:extra-settings ""]
5891Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
5892acts as a gateway between IRC and chat networks.
5893
5894The daemon will listen to the interface corresponding to the IP address
5895specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
5896local clients can connect, whereas @code{0.0.0.0} means that connections can
5897come from any networking interface.
5898
5899In addition, @var{extra-settings} specifies a string to append to the
5900configuration file.
5901@end deffn
5902
f4391bec 5903Furthermore, @code{(gnu services ssh)} provides the following service.
8b315a6d 5904
cf4a9129 5905@deffn {Monadic Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 5906 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
5907 [#:allow-empty-passwords? #f] [#:root-login? #f] @
5908 [#:syslog-output? #t] [#:x11-forwarding? #t] @
5909 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 5910 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
5911Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
5912@var{host-key} must designate a file containing the host key, and readable
5913only by root.
72e25e35 5914
5833bf33
DP
5915When @var{daemonic?} is true, @command{lshd} will detach from the
5916controlling terminal and log its output to syslogd, unless one sets
5917@var{syslog-output?} to false. Obviously, it also makes lsh-service
5918depend on existence of syslogd service. When @var{pid-file?} is true,
5919@command{lshd} writes its PID to the file called @var{pid-file}.
5920
cf4a9129
LC
5921When @var{initialize?} is true, automatically create the seed and host key
5922upon service activation if they do not exist yet. This may take long and
5923require interaction.
8b315a6d 5924
20dd519c
LC
5925When @var{initialize?} is false, it is up to the user to initialize the
5926randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
5927a key pair with the private key stored in file @var{host-key} (@pxref{lshd
5928basics,,, lsh, LSH Manual}).
5929
cf4a9129
LC
5930When @var{interfaces} is empty, lshd listens for connections on all the
5931network interfaces; otherwise, @var{interfaces} must be a list of host names
5932or addresses.
9bf3c1a7 5933
20dd519c
LC
5934@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
5935passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 5936root.
4af2447e 5937
cf4a9129
LC
5938The other options should be self-descriptive.
5939@end deffn
4af2447e 5940
fa0c1d61
LC
5941@defvr {Scheme Variable} %facebook-host-aliases
5942This variable contains a string for use in @file{/etc/hosts}
5943(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
5944line contains a entry that maps a known server name of the Facebook
5945on-line service---e.g., @code{www.facebook.com}---to the local
5946host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
5947
5948This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
5949@code{operating-system} declaration (@pxref{operating-system Reference,
5950@file{/etc/hosts}}):
fa0c1d61
LC
5951
5952@example
5953(use-modules (gnu) (guix))
5954
5955(operating-system
5956 (host-name "mymachine")
5957 ;; ...
5958 (hosts-file
5959 ;; Create a /etc/hosts file with aliases for "localhost"
5960 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
5961 (plain-file "hosts"
5962 (string-append (local-host-aliases host-name)
5963 %facebook-host-aliases))))
fa0c1d61
LC
5964@end example
5965
5966This mechanism can prevent programs running locally, such as Web
5967browsers, from accessing Facebook.
5968@end defvr
5969
965a7332
LC
5970The @code{(gnu services avahi)} provides the following definition.
5971
5972@deffn {Monadic Procedure} avahi-service [#:avahi @var{avahi}] @
5973 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
5974 [#:ipv6? #t] [#:wide-area? #f] @
5975 [#:domains-to-browse '()]
5976Return a service that runs @command{avahi-daemon}, a system-wide
5977mDNS/DNS-SD responder that allows for service discovery and
5978"zero-configuration" host name lookups (see @uref{http://avahi.org/}).
5979
5980If @var{host-name} is different from @code{#f}, use that as the host name to
5981publish for this machine; otherwise, use the machine's actual host name.
5982
5983When @var{publish?} is true, publishing of host names and services is allowed;
5984in particular, avahi-daemon will publish the machine's host name and IP
5985address via mDNS on the local network.
5986
5987When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
5988
5989Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
5990sockets.
5991@end deffn
5992
5993
cf4a9129
LC
5994@node X Window
5995@subsubsection X Window
68ad877c 5996
cf4a9129
LC
5997Support for the X Window graphical display system---specifically
5998Xorg---is provided by the @code{(gnu services xorg)} module. Note that
5999there is no @code{xorg-service} procedure. Instead, the X server is
6000started by the @dfn{login manager}, currently SLiM.
4af2447e 6001
cf4a9129 6002@deffn {Monadic Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
6003 [#:auto-login? #f] [#:default-user ""] [#:startx] @
6004 [#:theme @var{%default-slim-theme}] @
4bd43bbe 6005 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
6006Return a service that spawns the SLiM graphical login manager, which in
6007turn starts the X display server with @var{startx}, a command as returned by
6008@code{xorg-start-command}.
4af2447e 6009
04e4e6ab
LC
6010@cindex X session
6011
6012SLiM automatically looks for session types described by the @file{.desktop}
6013files in @file{/run/current-system/profile/share/xsessions} and allows users
6014to choose a session from the log-in screen using @kbd{F1}. Packages such as
6015@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
6016adding them to the system-wide set of packages automatically makes them
6017available at the log-in screen.
6018
6019In addition, @file{~/.xsession} files are honored. When available,
6020@file{~/.xsession} must be an executable that starts a window manager
6021and/or other X clients.
6022
cf4a9129
LC
6023When @var{allow-empty-passwords?} is true, allow logins with an empty
6024password. When @var{auto-login?} is true, log in automatically as
6025@var{default-user}.
0ecc3bf3
LC
6026
6027If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
6028@var{theme} must be a gexp denoting the name of a directory containing the
6029theme to use. In that case, @var{theme-name} specifies the name of the
6030theme.
cf4a9129 6031@end deffn
4af2447e 6032
0ecc3bf3
LC
6033@defvr {Scheme Variable} %default-theme
6034@defvrx {Scheme Variable} %default-theme-name
6035The G-Expression denoting the default SLiM theme and its name.
6036@end defvr
6037
f703413e 6038@deffn {Monadic Procedure} xorg-start-command [#:guile] @
d1cdd7ba 6039 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 6040Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
6041from @var{xorg-server}. @var{configuration-file} is the server configuration
6042file or a derivation that builds it; when omitted, the result of
6043@code{xorg-configuration-file} is used.
6044
6045Usually the X server is started by a login manager.
6046@end deffn
6047
6048@deffn {Monadic Procedure} xorg-configuration-file @
12422c9d 6049 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
6050Return a configuration file for the Xorg server containing search paths for
6051all the common drivers.
f703413e
LC
6052
6053@var{drivers} must be either the empty list, in which case Xorg chooses a
6054graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 6055this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
6056
6057Likewise, when @var{resolutions} is the empty list, Xorg chooses an
6058appropriate screen resolution; otherwise, it must be a list of
6059resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
6060
6061Last, @var{extra-config} is a list of strings or objects appended to the
6062@code{text-file*} argument list. It is used to pass extra text to be added
6063verbatim to the configuration file.
f703413e 6064@end deffn
4af2447e 6065
fe1a39d3
LC
6066@node Desktop Services
6067@subsubsection Desktop Services
aa4ed923 6068
fe1a39d3
LC
6069The @code{(gnu services desktop)} module provides services that are
6070usually useful in the context of a ``desktop'' setup---that is, on a
6071machine running a graphical display server, possibly with graphical user
6072interfaces, etc.
aa4ed923 6073
4467be21
LC
6074To simplify things, the module defines a variable containing the set of
6075services that users typically expect on a machine with a graphical
6076environment and networking:
6077
6078@defvr {Scheme Variable} %desktop-services
6079This is a list of services that builds upon @var{%base-services} and
6080adds or adjust services for a typical ``desktop'' setup.
6081
6082In particular, it adds a graphical login manager (@pxref{X Window,
6083@code{slim-service}}), a network management tool (@pxref{Networking
6084Services, @code{wicd-service}}), energy and color management services,
4650a77e 6085the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
6086the GeoClue location service, an NTP client (@pxref{Networking
6087Services}), the Avahi daemon, and has the name service switch service
6088configured to be able to use @code{nss-mdns} (@pxref{Name Service
6089Switch, mDNS}).
4467be21
LC
6090@end defvr
6091
6092The @var{%desktop-services} variable can be used as the @code{services}
6093field of an @code{operating-system} declaration (@pxref{operating-system
6094Reference, @code{services}}).
6095
6096The actual service definitions provided by @code{(gnu services desktop)}
6097are described below.
6098
fe1a39d3
LC
6099@deffn {Monadic Procedure} dbus-service @var{services} @
6100 [#:dbus @var{dbus}]
6101Return a service that runs the ``system bus'', using @var{dbus}, with
6102support for @var{services}.
aa4ed923 6103
fe1a39d3
LC
6104@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
6105facility. Its system bus is used to allow system services to communicate
6106and be notified of system-wide events.
aa4ed923 6107
fe1a39d3
LC
6108@var{services} must be a list of packages that provide an
6109@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
6110and policy files. For example, to allow avahi-daemon to use the system bus,
6111@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
6112@end deffn
6113
4650a77e
AW
6114@deffn {Monadic Procedure} elogind-service @
6115 [#:elogind @var{elogind}] [#:config @var{config}]
6116Return a service that runs the @code{elogind} login and
6117seat management daemon. @uref{https://github.com/andywingo/elogind,
6118Elogind} exposes a D-Bus interface that can be used to know which users
6119are logged in, know what kind of sessions they have open, suspend the
6120system, inhibit system suspend, reboot the system, and other tasks.
6121
6122Elogind handles most system-level power events for a computer, for
6123example suspending the system when a lid is closed, or shutting it down
6124when the power button is pressed.
6125
6126The @var{config} keyword argument specifies the configuration for
6127elogind, and should be the result of a @code{(elogind-configuration
6128(@var{parameter} @var{value})...)} invocation. Available parameters and
6129their default values are:
6130
6131@table @code
6132@item kill-user-processes?
6133@code{#f}
6134@item kill-only-users
6135@code{()}
6136@item kill-exclude-users
6137@code{("root")}
6138@item inhibit-delay-max-seconds
6139@code{5}
6140@item handle-power-key
6141@code{poweroff}
6142@item handle-suspend-key
6143@code{suspend}
6144@item handle-hibernate-key
6145@code{hibernate}
6146@item handle-lid-switch
6147@code{suspend}
6148@item handle-lid-switch-docked
6149@code{ignore}
6150@item power-key-ignore-inhibited?
6151@code{#f}
6152@item suspend-key-ignore-inhibited?
6153@code{#f}
6154@item hibernate-key-ignore-inhibited?
6155@code{#f}
6156@item lid-switch-ignore-inhibited?
6157@code{#t}
6158@item holdoff-timeout-seconds
6159@code{30}
6160@item idle-action
6161@code{ignore}
6162@item idle-action-seconds
6163@code{(* 30 60)}
6164@item runtime-directory-size-percent
6165@code{10}
6166@item runtime-directory-size
6167@code{#f}
6168@item remove-ipc?
6169@code{#t}
6170@item suspend-state
6171@code{("mem" "standby" "freeze")}
6172@item suspend-mode
6173@code{()}
6174@item hibernate-state
6175@code{("disk")}
6176@item hibernate-mode
6177@code{("platform" "shutdown")}
6178@item hybrid-sleep-state
6179@code{("disk")}
6180@item hybrid-sleep-mode
6181@code{("suspend" "platform" "shutdown")}
6182@end table
6183@end deffn
6184
6185@deffn {Monadic Procedure} polkit-service @
6186 [#:polkit @var{polkit}]
6187Return a service that runs the Polkit privilege manager.
6188@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit} allows
6189system administrators to grant access to privileged operations in a
6190structured way. For example, polkit rules can allow a logged-in user
6191whose session is active to shut down the machine, if there are no other
6192users active.
6193@end deffn
6194
be234128
AW
6195@deffn {Monadic Procedure} upower-service [#:upower @var{upower}] @
6196 [#:watts-up-pro? #f] @
6197 [#:poll-batteries? #t] @
6198 [#:ignore-lid? #f] @
6199 [#:use-percentage-for-policy? #f] @
6200 [#:percentage-low 10] @
6201 [#:percentage-critical 3] @
6202 [#:percentage-action 2] @
6203 [#:time-low 1200] @
6204 [#:time-critical 300] @
6205 [#:time-action 120] @
6206 [#:critical-power-action 'hybrid-sleep]
6207Return a service that runs @uref{http://upower.freedesktop.org/,
6208@command{upowerd}}, a system-wide monitor for power consumption and battery
6209levels, with the given configuration settings. It implements the
6210@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
6211GNOME.
6212@end deffn
6213
7ce597ff
AW
6214@deffn {Monadic Procedure} colord-service [#:colord @var{colord}]
6215Return a service that runs @command{colord}, a system service with a D-Bus
6216interface to manage the color profiles of input and output devices such as
6217screens and scanners. It is notably used by the GNOME Color Manager graphical
6218tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
6219site} for more information.
6220@end deffn
6221
cee32ee4
AW
6222@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
6223Return an configuration allowing an application to access GeoClue
6224location data. @var{name} is the Desktop ID of the application, without
6225the @code{.desktop} part. If @var{allowed?} is true, the application
6226will have access to location information by default. The boolean
6227@var{system?} value indicates that an application is a system component
6228or not. Finally @var{users} is a list of UIDs of all users for which
6229this application is allowed location info access. An empty users list
6230means that all users are allowed.
6231@end deffn
6232
6233@defvr {Scheme Variable} %standard-geoclue-applications
6234The standard list of well-known GeoClue application configurations,
6235granting authority to GNOME's date-and-time utility to ask for the
6236current location in order to set the time zone, and allowing the Firefox
6237(IceCat) and Epiphany web browsers to request location information.
6238Firefox and Epiphany both query the user before allowing a web page to
6239know the user's location.
6240@end defvr
6241
6242@deffn {Monadic Procedure} geoclue-service [#:colord @var{colord}] @
6243 [#:whitelist '()] @
6244 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
6245 [#:submit-data? #f]
6246 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
6247 [#:submission-nick "geoclue"] @
6248 [#:applications %standard-geoclue-applications]
6249Return a service that runs the GeoClue location service. This service
6250provides a D-Bus interface to allow applications to request access to a
6251user's physical location, and optionally to add information to online
6252location databases. See
6253@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
6254web site} for more information.
6255@end deffn
6256
105369a4
DT
6257@node Database Services
6258@subsubsection Database Services
6259
6260The @code{(gnu services databases)} module provides the following service.
6261
6262@deffn {Monadic Procedure} postgresql-service [#:postgresql postgresql] @
6263 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
6264Return a service that runs @var{postgresql}, the PostgreSQL database
6265server.
6266
6267The PostgreSQL daemon loads its runtime configuration from
6268@var{config-file} and stores the database cluster in
6269@var{data-directory}.
6270@end deffn
fe1a39d3 6271
58724c48
DT
6272@node Web Services
6273@subsubsection Web Services
6274
6275The @code{(gnu services web)} module provides the following service:
6276
6277@deffn {Monadic Procedure} nginx-service [#:nginx nginx] @
6278 [#:log-directory ``/var/log/nginx''] @
6279 [#:run-directory ``/var/run/nginx''] @
6280 [#:config-file]
6281
6282Return a service that runs @var{nginx}, the nginx web server.
6283
6284The nginx daemon loads its runtime configuration from @var{config-file}.
6285Log files are written to @var{log-directory} and temporary runtime data
6286files are written to @var{run-directory}. For proper operation, these
6287arguments should match what is in @var{config-file} to ensure that the
6288directories are created when the service is activated.
6289
6290@end deffn
6291
fe1a39d3
LC
6292@node Various Services
6293@subsubsection Various Services
6294
6295The @code{(gnu services lirc)} module provides the following service.
6296
6297@deffn {Monadic Procedure} lirc-service [#:lirc lirc] @
6298 [#:device #f] [#:driver #f] [#:config-file #f] @
6299 [#:extra-options '()]
6300Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
6301decodes infrared signals from remote controls.
6302
6303Optionally, @var{device}, @var{driver} and @var{config-file}
6304(configuration file name) may be specified. See @command{lircd} manual
6305for details.
6306
6307Finally, @var{extra-options} is a list of additional command-line options
6308passed to @command{lircd}.
6309@end deffn
6310
6311
0ae8c15a
LC
6312@node Setuid Programs
6313@subsection Setuid Programs
6314
6315@cindex setuid programs
6316Some programs need to run with ``root'' privileges, even when they are
6317launched by unprivileged users. A notorious example is the
4d40227c
LC
6318@command{passwd} program, which users can run to change their
6319password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
6320@file{/etc/shadow} files---something normally restricted to root, for
6321obvious security reasons. To address that, these executables are
6322@dfn{setuid-root}, meaning that they always run with root privileges
6323(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
6324for more info about the setuid mechanisms.)
6325
6326The store itself @emph{cannot} contain setuid programs: that would be a
6327security issue since any user on the system can write derivations that
6328populate the store (@pxref{The Store}). Thus, a different mechanism is
6329used: instead of changing the setuid bit directly on files that are in
6330the store, we let the system administrator @emph{declare} which programs
6331should be setuid root.
6332
6333The @code{setuid-programs} field of an @code{operating-system}
6334declaration contains a list of G-expressions denoting the names of
6335programs to be setuid-root (@pxref{Using the Configuration System}).
6336For instance, the @command{passwd} program, which is part of the Shadow
6337package, can be designated by this G-expression (@pxref{G-Expressions}):
6338
6339@example
6340#~(string-append #$shadow "/bin/passwd")
6341@end example
6342
6343A default set of setuid programs is defined by the
6344@code{%setuid-programs} variable of the @code{(gnu system)} module.
6345
6346@defvr {Scheme Variable} %setuid-programs
6347A list of G-expressions denoting common programs that are setuid-root.
6348
6349The list includes commands such as @command{passwd}, @command{ping},
6350@command{su}, and @command{sudo}.
6351@end defvr
6352
6353Under the hood, the actual setuid programs are created in the
6354@file{/run/setuid-programs} directory at system activation time. The
6355files in this directory refer to the ``real'' binaries, which are in the
6356store.
6357
efb5e833
LC
6358@node X.509 Certificates
6359@subsection X.509 Certificates
6360
6361@cindex HTTPS, certificates
6362@cindex X.509 certificates
6363@cindex TLS
6364Web servers available over HTTPS (that is, HTTP over the transport-layer
6365security mechanism, TLS) send client programs an @dfn{X.509 certificate}
6366that the client can then use to @emph{authenticate} the server. To do
6367that, clients verify that the server's certificate is signed by a
6368so-called @dfn{certificate authority} (CA). But to verify the CA's
6369signature, clients must have first acquired the CA's certificate.
6370
6371Web browsers such as GNU@tie{}IceCat include their own set of CA
6372certificates, such that they are able to verify CA signatures
6373out-of-the-box.
6374
6375However, most other programs that can talk HTTPS---@command{wget},
6376@command{git}, @command{w3m}, etc.---need to be told where CA
6377certificates can be found.
6378
6379@cindex @code{nss-certs}
6380In GuixSD, this is done by adding a package that provides certificates
6381to the @code{packages} field of the @code{operating-system} declaration
6382(@pxref{operating-system Reference}). GuixSD includes one such package,
6383@code{nss-certs}, which is a set of CA certificates provided as part of
6384Mozilla's Network Security Services.
6385
6386Note that it is @emph{not} part of @var{%base-packages}, so you need to
6387explicitly add it. The @file{/etc/ssl/certs} directory, which is where
6388most applications and libraries look for certificates by default, points
6389to the certificates installed globally.
6390
6391Unprivileged users can also install their own certificate package in
6392their profile. A number of environment variables need to be defined so
6393that applications and libraries know where to find them. Namely, the
6394OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
6395variables. Some applications add their own environment variables; for
6396instance, the Git version control system honors the certificate bundle
6397pointed to by the @code{GIT_SSL_CAINFO} environment variable.
6398
6399
996ed739
LC
6400@node Name Service Switch
6401@subsection Name Service Switch
6402
6403@cindex name service switch
6404@cindex NSS
6405The @code{(gnu system nss)} module provides bindings to the
6406configuration file of libc's @dfn{name service switch} or @dfn{NSS}
6407(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
6408Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
6409extended with new ``name'' lookup methods for system databases, which
6410includes host names, service names, user accounts, and more (@pxref{Name
6411Service Switch, System Databases and Name Service Switch,, libc, The GNU
6412C Library Reference Manual}).
6413
6414The NSS configuration specifies, for each system database, which lookup
6415method is to be used, and how the various methods are chained
6416together---for instance, under which circumstances NSS should try the
6417next method in the list. The NSS configuration is given in the
6418@code{name-service-switch} field of @code{operating-system} declarations
6419(@pxref{operating-system Reference, @code{name-service-switch}}).
6420
4c9050c6
LC
6421@cindex nss-mdns
6422@cindex .local, host name lookup
996ed739 6423As an example, the declaration below configures the NSS to use the
4c9050c6
LC
6424@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
6425back-end}, which supports host name lookups over multicast DNS (mDNS)
6426for host names ending in @code{.local}:
996ed739
LC
6427
6428@example
6429(name-service-switch
6430 (hosts (list %files ;first, check /etc/hosts
6431
6432 ;; If the above did not succeed, try
6433 ;; with 'mdns_minimal'.
6434 (name-service
6435 (name "mdns_minimal")
6436
6437 ;; 'mdns_minimal' is authoritative for
6438 ;; '.local'. When it returns "not found",
6439 ;; no need to try the next methods.
6440 (reaction (lookup-specification
6441 (not-found => return))))
6442
6443 ;; Then fall back to DNS.
6444 (name-service
6445 (name "dns"))
6446
6447 ;; Finally, try with the "full" 'mdns'.
6448 (name-service
6449 (name "mdns")))))
6450@end example
6451
15137a29
LC
6452Don't worry: the @code{%mdns-host-lookup-nss} variable (see below)
6453contains this configuration, so you won't have to type it if all you
6454want is to have @code{.local} host lookup working.
6455
4c9050c6
LC
6456Note that, in this case, in addition to setting the
6457@code{name-service-switch} of the @code{operating-system} declaration,
6458@code{nscd-service} must be told where to find the @code{nss-mdns}
6459shared library (@pxref{Base Services, @code{nscd-service}}). Since the
6460@code{nscd} service is part of @var{%base-services}, you may want to
6461customize it by adding this snippet in the operating system
6462configuration file:
6463
6464@example
6465(use-modules (guix) (gnu))
6466
6467(define %my-base-services
6468 ;; Replace the default nscd service with one that knows
6469 ;; about nss-mdns.
6470 (map (lambda (mservice)
6471 ;; "Bind" the MSERVICE monadic value to inspect it.
6472 (mlet %store-monad ((service mservice))
6473 (if (member 'nscd (service-provision service))
6474 (nscd-service (nscd-configuration)
6475 #:name-services (list nss-mdns))
6476 mservice)))
6477 %base-services))
6478@end example
6479
6480@noindent
6481@dots{} and then refer to @var{%my-base-services} instead of
6482@var{%base-services} in the @code{operating-system} declaration.
15137a29 6483Lastly, this relies on the availability of the Avahi service
965a7332 6484(@pxref{Networking Services, @code{avahi-service}}).
15137a29
LC
6485
6486For convenience, the following variables provide typical NSS
6487configurations.
6488
6489@defvr {Scheme Variable} %default-nss
6490This is the default name service switch configuration, a
6491@code{name-service-switch} object.
6492@end defvr
6493
6494@defvr {Scheme Variable} %mdns-host-lookup-nss
6495This is the name service switch configuration with support for host name
6496lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
6497@end defvr
4c9050c6 6498
996ed739
LC
6499The reference for name service switch configuration is given below. It
6500is a direct mapping of the C library's configuration file format, so
6501please refer to the C library manual for more information (@pxref{NSS
6502Configuration File,,, libc, The GNU C Library Reference Manual}).
6503Compared to libc's NSS configuration file format, it has the advantage
6504not only of adding this warm parenthetic feel that we like, but also
6505static checks: you'll know about syntax errors and typos as soon as you
6506run @command{guix system}.
6507
996ed739
LC
6508@deftp {Data Type} name-service-switch
6509
6510This is the data type representation the configuration of libc's name
6511service switch (NSS). Each field below represents one of the supported
6512system databases.
6513
6514@table @code
6515@item aliases
6516@itemx ethers
6517@itemx group
6518@itemx gshadow
6519@itemx hosts
6520@itemx initgroups
6521@itemx netgroup
6522@itemx networks
6523@itemx password
6524@itemx public-key
6525@itemx rpc
6526@itemx services
6527@itemx shadow
6528The system databases handled by the NSS. Each of these fields must be a
6529list of @code{<name-service>} objects (see below.)
6530@end table
6531@end deftp
6532
6533@deftp {Data Type} name-service
6534
6535This is the data type representing an actual name service and the
6536associated lookup action.
6537
6538@table @code
6539@item name
6540A string denoting the name service (@pxref{Services in the NSS
6541configuration,,, libc, The GNU C Library Reference Manual}).
6542
4aee6e60
LC
6543Note that name services listed here must be visible to nscd. This is
6544achieved by passing the @code{#:name-services} argument to
6545@code{nscd-service} the list of packages providing the needed name
6546services (@pxref{Base Services, @code{nscd-service}}).
6547
996ed739
LC
6548@item reaction
6549An action specified using the @code{lookup-specification} macro
6550(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
6551Reference Manual}). For example:
6552
6553@example
6554(lookup-specification (unavailable => continue)
6555 (success => return))
6556@end example
6557@end table
6558@end deftp
0ae8c15a 6559
fd1b1fa2
LC
6560@node Initial RAM Disk
6561@subsection Initial RAM Disk
6562
6563@cindex initial RAM disk (initrd)
6564@cindex initrd (initial RAM disk)
6565For bootstrapping purposes, the Linux-Libre kernel is passed an
6566@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
6567root file system, as well as an initialization script. The latter is
6568responsible for mounting the real root file system, and for loading any
6569kernel modules that may be needed to achieve that.
6570
6571The @code{initrd} field of an @code{operating-system} declaration allows
6572you to specify which initrd you would like to use. The @code{(gnu
6573system linux-initrd)} module provides two ways to build an initrd: the
6574high-level @code{base-initrd} procedure, and the low-level
6575@code{expression->initrd} procedure.
6576
6577The @code{base-initrd} procedure is intended to cover most common uses.
6578For example, if you want to add a bunch of kernel modules to be loaded
6579at boot time, you can define the @code{initrd} field of the operating
6580system declaration like this:
6581
6582@example
52ac153e 6583(initrd (lambda (file-systems . rest)
027981d6
LC
6584 ;; Create a standard initrd that has modules "foo.ko"
6585 ;; and "bar.ko", as well as their dependencies, in
6586 ;; addition to the modules available by default.
52ac153e 6587 (apply base-initrd file-systems
027981d6 6588 #:extra-modules '("foo" "bar")
52ac153e 6589 rest)))
fd1b1fa2
LC
6590@end example
6591
52ac153e
LC
6592The @code{base-initrd} procedure also handles common use cases that
6593involves using the system as a QEMU guest, or as a ``live'' system whose
6594root file system is volatile.
fd1b1fa2
LC
6595
6596@deffn {Monadic Procedure} base-initrd @var{file-systems} @
6597 [#:qemu-networking? #f] [#:virtio? #f] [#:volatile-root? #f] @
52ac153e 6598 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2
LC
6599Return a monadic derivation that builds a generic initrd. @var{file-systems} is
6600a list of file-systems to be mounted by the initrd, possibly in addition to
6601the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
6602@var{mapped-devices} is a list of device mappings to realize before
6603@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
6604
6605When @var{qemu-networking?} is true, set up networking with the standard QEMU
6606parameters. When @var{virtio?} is true, load additional modules so the initrd can
6607be used as a QEMU guest with para-virtualized I/O drivers.
6608
6609When @var{volatile-root?} is true, the root file system is writable but any changes
6610to it are lost.
6611
6612The initrd is automatically populated with all the kernel modules necessary
6613for @var{file-systems} and for the given options. However, additional kernel
6614modules can be listed in @var{extra-modules}. They will be added to the initrd, and
6615loaded at boot time in the order in which they appear.
6616@end deffn
6617
6618Needless to say, the initrds we produce and use embed a
6619statically-linked Guile, and the initialization program is a Guile
6620program. That gives a lot of flexibility. The
6621@code{expression->initrd} procedure builds such an initrd, given the
6622program to run in that initrd.
6623
6624@deffn {Monadic Procedure} expression->initrd @var{exp} @
6625 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
42d10464 6626 [#:modules '()]
fd1b1fa2
LC
6627Return a derivation that builds a Linux initrd (a gzipped cpio archive)
6628containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
6629upon booting. All the derivations referenced by @var{exp} are
6630automatically copied to the initrd.
fd1b1fa2 6631
42d10464
LC
6632@var{modules} is a list of Guile module names to be embedded in the
6633initrd.
fd1b1fa2
LC
6634@end deffn
6635
88faf933
LC
6636@node GRUB Configuration
6637@subsection GRUB Configuration
6638
6639@cindex GRUB
6640@cindex boot loader
6641
6642The operating system uses GNU@tie{}GRUB as its boot loader
6643(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
6644configured using @code{grub-configuration} declarations. This data type
6645is exported by the @code{(gnu system grub)} module, and described below.
6646
6647@deftp {Data Type} grub-configuration
6648The type of a GRUB configuration declaration.
6649
6650@table @asis
6651
6652@item @code{device}
6653This is a string denoting the boot device. It must be a device name
6654understood by the @command{grub-install} command, such as
6655@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
6656GNU GRUB Manual}).
6657
6658@item @code{menu-entries} (default: @code{()})
6659A possibly empty list of @code{menu-entry} objects (see below), denoting
6660entries to appear in the GRUB boot menu, in addition to the current
6661system entry and the entry pointing to previous system generations.
6662
6663@item @code{default-entry} (default: @code{0})
6664The index of the default boot menu entry. Index 0 is for the current
6665system's entry.
6666
6667@item @code{timeout} (default: @code{5})
6668The number of seconds to wait for keyboard input before booting. Set to
66690 to boot immediately, and to -1 to wait indefinitely.
6670
6671@item @code{theme} (default: @var{%default-theme})
6672The @code{grub-theme} object describing the theme to use.
6673@end table
6674
6675@end deftp
6676
6677Should you want to list additional boot menu entries @i{via} the
6678@code{menu-entries} field above, you will need to create them with the
6679@code{menu-entry} form:
6680
6681@deftp {Data Type} menu-entry
6682The type of an entry in the GRUB boot menu.
6683
6684@table @asis
6685
6686@item @code{label}
35ed9306 6687The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
6688
6689@item @code{linux}
6690The Linux kernel to boot.
6691
6692@item @code{linux-arguments} (default: @code{()})
6693The list of extra Linux kernel command-line arguments---e.g.,
6694@code{("console=ttyS0")}.
6695
6696@item @code{initrd}
6697A G-Expression or string denoting the file name of the initial RAM disk
6698to use (@pxref{G-Expressions}).
6699
6700@end table
6701@end deftp
6702
6703@c FIXME: Write documentation once it's stable.
6704Themes are created using the @code{grub-theme} form, which is not
6705documented yet.
6706
6707@defvr {Scheme Variable} %default-theme
6708This is the default GRUB theme used by the operating system, with a
6709fancy background image displaying the GNU and Guix logos.
6710@end defvr
6711
6712
cf4a9129
LC
6713@node Invoking guix system
6714@subsection Invoking @code{guix system}
0918e64a 6715
cf4a9129
LC
6716Once you have written an operating system declaration, as seen in the
6717previous section, it can be @dfn{instantiated} using the @command{guix
6718system} command. The synopsis is:
4af2447e 6719
cf4a9129
LC
6720@example
6721guix system @var{options}@dots{} @var{action} @var{file}
6722@end example
4af2447e 6723
cf4a9129
LC
6724@var{file} must be the name of a file containing an
6725@code{operating-system} declaration. @var{action} specifies how the
6726operating system is instantiate. Currently the following values are
6727supported:
4af2447e 6728
cf4a9129
LC
6729@table @code
6730@item reconfigure
6731Build the operating system described in @var{file}, activate it, and
6732switch to it@footnote{This action is usable only on systems already
6733running GNU.}.
4af2447e 6734
cf4a9129
LC
6735This effects all the configuration specified in @var{file}: user
6736accounts, system services, global package list, setuid programs, etc.
4af2447e 6737
cf4a9129
LC
6738It also adds a GRUB menu entry for the new OS configuration, and moves
6739entries for older configurations to a submenu---unless
6740@option{--no-grub} is passed.
4af2447e 6741
bf2479c7
LC
6742@c The paragraph below refers to the problem discussed at
6743@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
6744It is highly recommended to run @command{guix pull} once before you run
6745@command{guix system reconfigure} for the first time (@pxref{Invoking
6746guix pull}). Failing to do that you would see an older version of Guix
6747once @command{reconfigure} has completed.
6748
cf4a9129
LC
6749@item build
6750Build the operating system's derivation, which includes all the
6751configuration files and programs needed to boot and run the system.
6752This action does not actually install anything.
113daf62 6753
cf4a9129
LC
6754@item init
6755Populate the given directory with all the files necessary to run the
6756operating system specified in @var{file}. This is useful for first-time
4705641f 6757installations of GuixSD. For instance:
113daf62
LC
6758
6759@example
cf4a9129 6760guix system init my-os-config.scm /mnt
113daf62
LC
6761@end example
6762
cf4a9129
LC
6763copies to @file{/mnt} all the store items required by the configuration
6764specified in @file{my-os-config.scm}. This includes configuration
6765files, packages, and so on. It also creates other essential files
6766needed for the system to operate correctly---e.g., the @file{/etc},
6767@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 6768
cf4a9129
LC
6769This command also installs GRUB on the device specified in
6770@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 6771
cf4a9129
LC
6772@item vm
6773@cindex virtual machine
0276f697 6774@cindex VM
cf4a9129
LC
6775Build a virtual machine that contain the operating system declared in
6776@var{file}, and return a script to run that virtual machine (VM).
810568b3 6777Arguments given to the script are passed as is to QEMU.
113daf62 6778
cf4a9129 6779The VM shares its store with the host system.
113daf62 6780
0276f697
LC
6781Additional file systems can be shared between the host and the VM using
6782the @code{--share} and @code{--expose} command-line options: the former
6783specifies a directory to be shared with write access, while the latter
6784provides read-only access to the shared directory.
6785
6786The example below creates a VM in which the user's home directory is
6787accessible read-only, and where the @file{/exchange} directory is a
6788read-write mapping of the host's @file{$HOME/tmp}:
6789
6790@example
6791guix system vm my-config.scm \
6792 --expose=$HOME --share=$HOME/tmp=/exchange
6793@end example
6794
6aa260af
LC
6795On GNU/Linux, the default is to boot directly to the kernel; this has
6796the advantage of requiring only a very tiny root disk image since the
6797host's store can then be mounted.
6798
6799The @code{--full-boot} option forces a complete boot sequence, starting
6800with the bootloader. This requires more disk space since a root image
6801containing at least the kernel, initrd, and bootloader data files must
6802be created. The @code{--image-size} option can be used to specify the
6803image's size.
ab11f0be 6804
cf4a9129
LC
6805@item vm-image
6806@itemx disk-image
6807Return a virtual machine or disk image of the operating system declared
6808in @var{file} that stands alone. Use the @option{--image-size} option
6809to specify the size of the image.
113daf62 6810
cf4a9129
LC
6811When using @code{vm-image}, the returned image is in qcow2 format, which
6812the QEMU emulator can efficiently use.
113daf62 6813
cf4a9129
LC
6814When using @code{disk-image}, a raw disk image is produced; it can be
6815copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
6816the device corresponding to a USB stick, one can copy the image on it
6817using the following command:
113daf62 6818
cf4a9129
LC
6819@example
6820# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
6821@end example
113daf62 6822
cf4a9129 6823@end table
113daf62 6824
cf4a9129
LC
6825@var{options} can contain any of the common build options provided by
6826@command{guix build} (@pxref{Invoking guix build}). In addition,
6827@var{options} can contain one of the following:
113daf62 6828
cf4a9129
LC
6829@table @option
6830@item --system=@var{system}
6831@itemx -s @var{system}
6832Attempt to build for @var{system} instead of the host's system type.
6833This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 6834
cf4a9129
LC
6835@item --image-size=@var{size}
6836For the @code{vm-image} and @code{disk-image} actions, create an image
6837of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
6838include a unit as a suffix (@pxref{Block size, size specifications,,
6839coreutils, GNU Coreutils}).
db030303
LC
6840
6841@item --on-error=@var{strategy}
6842Apply @var{strategy} when an error occurs when reading @var{file}.
6843@var{strategy} may be one of the following:
6844
6845@table @code
6846@item nothing-special
6847Report the error concisely and exit. This is the default strategy.
6848
6849@item backtrace
6850Likewise, but also display a backtrace.
6851
6852@item debug
6853Report the error and enter Guile's debugger. From there, you can run
6854commands such as @code{,bt} to get a backtrace, @code{,locals} to
6855display local variable values, and more generally inspect the program's
6856state. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
6857a list of available debugging commands.
6858@end table
113daf62 6859@end table
113daf62 6860
cf4a9129
LC
6861Note that all the actions above, except @code{build} and @code{init},
6862rely on KVM support in the Linux-Libre kernel. Specifically, the
6863machine should have hardware virtualization support, the corresponding
6864KVM kernel module should be loaded, and the @file{/dev/kvm} device node
6865must exist and be readable and writable by the user and by the daemon's
6866build users.
8451a568 6867
cf4a9129
LC
6868@node Defining Services
6869@subsection Defining Services
8451a568 6870
cf4a9129
LC
6871The @code{(gnu services @dots{})} modules define several procedures that allow
6872users to declare the operating system's services (@pxref{Using the
6873Configuration System}). These procedures are @emph{monadic
6874procedures}---i.e., procedures that return a monadic value in the store
6875monad (@pxref{The Store Monad}). For examples of such procedures,
6876@xref{Services}.
8451a568 6877
cf4a9129
LC
6878@cindex service definition
6879The monadic value returned by those procedures is a @dfn{service
6880definition}---a structure as returned by the @code{service} form.
6881Service definitions specifies the inputs the service depends on, and an
6882expression to start and stop the service. Behind the scenes, service
6883definitions are ``translated'' into the form suitable for the
6884configuration file of dmd, the init system (@pxref{Services,,, dmd, GNU
6885dmd Manual}).
8451a568 6886
cf4a9129
LC
6887As an example, here is what the @code{nscd-service} procedure looks
6888like:
8451a568 6889
cf4a9129
LC
6890@lisp
6891(define (nscd-service)
6892 (with-monad %store-monad
6893 (return (service
6894 (documentation "Run libc's name service cache daemon.")
6895 (provision '(nscd))
6896 (activate #~(begin
6897 (use-modules (guix build utils))
6898 (mkdir-p "/var/run/nscd")))
6899 (start #~(make-forkexec-constructor
6900 (string-append #$glibc "/sbin/nscd")
6901 "-f" "/dev/null" "--foreground"))
6902 (stop #~(make-kill-destructor))
6903 (respawn? #f)))))
6904@end lisp
8451a568 6905
cf4a9129
LC
6906@noindent
6907The @code{activate}, @code{start}, and @code{stop} fields are G-expressions
6908(@pxref{G-Expressions}). The @code{activate} field contains a script to
6909run at ``activation'' time; it makes sure that the @file{/var/run/nscd}
6910directory exists before @command{nscd} is started.
8451a568 6911
cf4a9129
LC
6912The @code{start} and @code{stop} fields refer to dmd's facilities to
6913start and stop processes (@pxref{Service De- and Constructors,,, dmd,
6914GNU dmd Manual}). The @code{provision} field specifies the name under
6915which this service is known to dmd, and @code{documentation} specifies
6916on-line documentation. Thus, the commands @command{deco start ncsd},
6917@command{deco stop nscd}, and @command{deco doc nscd} will do what you
6918would expect (@pxref{Invoking deco,,, dmd, GNU dmd Manual}).
8451a568 6919
8451a568 6920
cf4a9129
LC
6921@node Installing Debugging Files
6922@section Installing Debugging Files
8451a568 6923
cf4a9129
LC
6924@cindex debugging files
6925Program binaries, as produced by the GCC compilers for instance, are
6926typically written in the ELF format, with a section containing
6927@dfn{debugging information}. Debugging information is what allows the
6928debugger, GDB, to map binary code to source code; it is required to
6929debug a compiled program in good conditions.
8451a568 6930
cf4a9129
LC
6931The problem with debugging information is that is takes up a fair amount
6932of disk space. For example, debugging information for the GNU C Library
6933weighs in at more than 60 MiB. Thus, as a user, keeping all the
6934debugging info of all the installed programs is usually not an option.
6935Yet, space savings should not come at the cost of an impediment to
6936debugging---especially in the GNU system, which should make it easier
6937for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 6938
cf4a9129
LC
6939Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
6940mechanism that allows users to get the best of both worlds: debugging
6941information can be stripped from the binaries and stored in separate
6942files. GDB is then able to load debugging information from those files,
6943when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
6944with GDB}).
8451a568 6945
cf4a9129
LC
6946The GNU distribution takes advantage of this by storing debugging
6947information in the @code{lib/debug} sub-directory of a separate package
6948output unimaginatively called @code{debug} (@pxref{Packages with
6949Multiple Outputs}). Users can choose to install the @code{debug} output
6950of a package when they need it. For instance, the following command
6951installs the debugging information for the GNU C Library and for GNU
6952Guile:
8451a568
LC
6953
6954@example
cf4a9129 6955guix package -i glibc:debug guile:debug
8451a568
LC
6956@end example
6957
cf4a9129
LC
6958GDB must then be told to look for debug files in the user's profile, by
6959setting the @code{debug-file-directory} variable (consider setting it
6960from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
6961GDB}):
8451a568 6962
cf4a9129
LC
6963@example
6964(gdb) set debug-file-directory ~/.guix-profile/lib/debug
6965@end example
8451a568 6966
cf4a9129
LC
6967From there on, GDB will pick up debugging information from the
6968@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 6969
cf4a9129
LC
6970In addition, you will most likely want GDB to be able to show the source
6971code being debugged. To do that, you will have to unpack the source
6972code of the package of interest (obtained with @code{guix build
6973--source}, @pxref{Invoking guix build}), and to point GDB to that source
6974directory using the @code{directory} command (@pxref{Source Path,
6975@code{directory},, gdb, Debugging with GDB}).
8451a568 6976
cf4a9129
LC
6977@c XXX: keep me up-to-date
6978The @code{debug} output mechanism in Guix is implemented by the
6979@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
6980opt-in---debugging information is available only for those packages
6981whose definition explicitly declares a @code{debug} output. This may be
6982changed to opt-out in the future, if our build farm servers can handle
6983the load. To check whether a package has a @code{debug} output, use
6984@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 6985
8451a568 6986
05962f29
LC
6987@node Security Updates
6988@section Security Updates
6989
843858b8
LC
6990@quotation Note
6991As of version @value{VERSION}, the feature described in this section is
6992experimental.
6993@end quotation
05962f29
LC
6994
6995@cindex security updates
6996Occasionally, important security vulnerabilities are discovered in core
6997software packages and must be patched. Guix follows a functional
6998package management discipline (@pxref{Introduction}), which implies
6999that, when a package is changed, @emph{every package that depends on it}
7000must be rebuilt. This can significantly slow down the deployment of
7001fixes in core packages such as libc or Bash, since basically the whole
7002distribution would need to be rebuilt. Using pre-built binaries helps
7003(@pxref{Substitutes}), but deployment may still take more time than
7004desired.
7005
7006@cindex grafts
7007To address that, Guix implements @dfn{grafts}, a mechanism that allows
7008for fast deployment of critical updates without the costs associated
7009with a whole-distribution rebuild. The idea is to rebuild only the
7010package that needs to be patched, and then to ``graft'' it onto packages
7011explicitly installed by the user and that were previously referring to
7012the original package. The cost of grafting is typically very low, and
7013order of magnitudes lower than a full rebuild of the dependency chain.
7014
7015@cindex replacements of packages, for grafts
7016For instance, suppose a security update needs to be applied to Bash.
7017Guix developers will provide a package definition for the ``fixed''
7018Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
7019Packages}). Then, the original package definition is augmented with a
7020@code{replacement} field pointing to the package containing the bug fix:
7021
7022@example
7023(define bash
7024 (package
7025 (name "bash")
7026 ;; @dots{}
7027 (replacement bash-fixed)))
7028@end example
7029
7030From there on, any package depending directly or indirectly on Bash that
7031is installed will automatically be ``rewritten'' to refer to
7032@var{bash-fixed} instead of @var{bash}. This grafting process takes
7033time proportional to the size of the package, but expect less than a
7034minute for an ``average'' package on a recent machine.
7035
7036Currently, the graft and the package it replaces (@var{bash-fixed} and
7037@var{bash} in the example above) must have the exact same @code{name}
7038and @code{version} fields. This restriction mostly comes from the fact
7039that grafting works by patching files, including binary files, directly.
7040Other restrictions may apply: for instance, when adding a graft to a
7041package providing a shared library, the original shared library and its
7042replacement must have the same @code{SONAME} and be binary-compatible.
7043
7044
cf4a9129
LC
7045@node Package Modules
7046@section Package Modules
8451a568 7047
cf4a9129
LC
7048From a programming viewpoint, the package definitions of the
7049GNU distribution are provided by Guile modules in the @code{(gnu packages
7050@dots{})} name space@footnote{Note that packages under the @code{(gnu
7051packages @dots{})} module name space are not necessarily ``GNU
7052packages''. This module naming scheme follows the usual Guile module
7053naming convention: @code{gnu} means that these modules are distributed
7054as part of the GNU system, and @code{packages} identifies modules that
7055define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
7056Reference Manual}). For instance, the @code{(gnu packages emacs)}
7057module exports a variable named @code{emacs}, which is bound to a
7058@code{<package>} object (@pxref{Defining Packages}).
113daf62 7059
300868ba 7060The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
7061automatically scanned for packages by the command-line tools. For
7062instance, when running @code{guix package -i emacs}, all the @code{(gnu
7063packages @dots{})} modules are scanned until one that exports a package
7064object whose name is @code{emacs} is found. This package search
7065facility is implemented in the @code{(gnu packages)} module.
113daf62 7066
300868ba 7067@cindex customization, of packages
8689901f 7068@cindex package module search path
cf4a9129 7069Users can store package definitions in modules with different
60142854 7070names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
7071name and module name must match. For instance, the @code{(my-packages
7072emacs)} module must be stored in a @file{my-packages/emacs.scm} file
7073relative to the load path specified with @option{--load-path} or
7074@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
7075guile, GNU Guile Reference Manual}, for details.}. These package definitions
300868ba
LC
7076will not be visible by default. Thus, users can invoke commands such as
7077@command{guix package} and @command{guix build} have to be used with the
c95ded7e
LC
7078@code{-e} option so that they know where to find the package. Better
7079yet, they can use the
300868ba 7080@code{-L} option of these commands to make those modules visible
8689901f
LC
7081(@pxref{Invoking guix build, @code{--load-path}}), or define the
7082@code{GUIX_PACKAGE_PATH} environment variable. This environment
7083variable makes it easy to extend or customize the distribution and is
7084honored by all the user interfaces.
7085
7086@defvr {Environment Variable} GUIX_PACKAGE_PATH
7087This is a colon-separated list of directories to search for package
7088modules. Directories listed in this variable take precedence over the
7089distribution's own modules.
7090@end defvr
ef5dd60a 7091
cf4a9129
LC
7092The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
7093each package is built based solely on other packages in the
7094distribution. The root of this dependency graph is a small set of
7095@dfn{bootstrap binaries}, provided by the @code{(gnu packages
7096bootstrap)} module. For more information on bootstrapping,
081145cf 7097@pxref{Bootstrapping}.
ef5dd60a 7098
cf4a9129
LC
7099@node Packaging Guidelines
7100@section Packaging Guidelines
ef5dd60a 7101
cf4a9129
LC
7102The GNU distribution is nascent and may well lack some of your favorite
7103packages. This section describes how you can help make the distribution
7104grow. @xref{Contributing}, for additional information on how you can
7105help.
ef5dd60a 7106
cf4a9129
LC
7107Free software packages are usually distributed in the form of
7108@dfn{source code tarballs}---typically @file{tar.gz} files that contain
7109all the source files. Adding a package to the distribution means
7110essentially two things: adding a @dfn{recipe} that describes how to
7111build the package, including a list of other packages required to build
7112it, and adding @dfn{package meta-data} along with that recipe, such as a
7113description and licensing information.
ef5dd60a 7114
cf4a9129
LC
7115In Guix all this information is embodied in @dfn{package definitions}.
7116Package definitions provide a high-level view of the package. They are
7117written using the syntax of the Scheme programming language; in fact,
7118for each package we define a variable bound to the package definition,
7119and export that variable from a module (@pxref{Package Modules}).
7120However, in-depth Scheme knowledge is @emph{not} a prerequisite for
7121creating packages. For more information on package definitions,
081145cf 7122@pxref{Defining Packages}.
ef5dd60a 7123
cf4a9129
LC
7124Once a package definition is in place, stored in a file in the Guix
7125source tree, it can be tested using the @command{guix build} command
7126(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
7127called @code{gnew}, you may run this command from the Guix build tree
7128(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
7129
7130@example
cf4a9129 7131./pre-inst-env guix build gnew --keep-failed
ef5dd60a 7132@end example
ef5dd60a 7133
cf4a9129
LC
7134Using @code{--keep-failed} makes it easier to debug build failures since
7135it provides access to the failed build tree. Another useful
7136command-line option when debugging is @code{--log-file}, to access the
7137build log.
ef5dd60a 7138
cf4a9129
LC
7139If the package is unknown to the @command{guix} command, it may be that
7140the source file contains a syntax error, or lacks a @code{define-public}
7141clause to export the package variable. To figure it out, you may load
7142the module from Guile to get more information about the actual error:
ef5dd60a 7143
cf4a9129
LC
7144@example
7145./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
7146@end example
ef5dd60a 7147
cf4a9129
LC
7148Once your package builds correctly, please send us a patch
7149(@pxref{Contributing}). Well, if you need help, we will be happy to
7150help you too. Once the patch is committed in the Guix repository, the
7151new package automatically gets built on the supported platforms by
2b1cee21 7152@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 7153system}.
ef5dd60a 7154
cf4a9129
LC
7155@cindex substituter
7156Users can obtain the new package definition simply by running
7157@command{guix pull} (@pxref{Invoking guix pull}). When
7158@code{hydra.gnu.org} is done building the package, installing the
7159package automatically downloads binaries from there
7160(@pxref{Substitutes}). The only place where human intervention is
7161needed is to review and apply the patch.
ef5dd60a 7162
ef5dd60a 7163
cf4a9129 7164@menu
ec0339cd
LC
7165* Software Freedom:: What may go into the distribution.
7166* Package Naming:: What's in a name?
7167* Version Numbers:: When the name is not enough.
cbd02397 7168* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
7169* Python Modules:: Taming the snake.
7170* Perl Modules:: Little pearls.
7171* Fonts:: Fond of fonts.
cf4a9129 7172@end menu
ef5dd60a 7173
cf4a9129
LC
7174@node Software Freedom
7175@subsection Software Freedom
ef5dd60a 7176
cf4a9129 7177@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
c11a6eb1 7178
cf4a9129
LC
7179The GNU operating system has been developed so that users can have
7180freedom in their computing. GNU is @dfn{free software}, meaning that
7181users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
7182essential freedoms}: to run the program, to study and change the program
7183in source code form, to redistribute exact copies, and to distribute
7184modified versions. Packages found in the GNU distribution provide only
7185software that conveys these four freedoms.
c11a6eb1 7186
cf4a9129
LC
7187In addition, the GNU distribution follow the
7188@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
7189software distribution guidelines}. Among other things, these guidelines
7190reject non-free firmware, recommendations of non-free software, and
7191discuss ways to deal with trademarks and patents.
ef5dd60a 7192
cf4a9129
LC
7193Some packages contain a small and optional subset that violates the
7194above guidelines, for instance because this subset is itself non-free
7195code. When that happens, the offending items are removed with
7196appropriate patches or code snippets in the package definition's
7197@code{origin} form (@pxref{Defining Packages}). That way, @code{guix
7198build --source} returns the ``freed'' source rather than the unmodified
7199upstream source.
ef5dd60a 7200
ef5dd60a 7201
cf4a9129
LC
7202@node Package Naming
7203@subsection Package Naming
ef5dd60a 7204
cf4a9129
LC
7205A package has actually two names associated with it:
7206First, there is the name of the @emph{Scheme variable}, the one following
7207@code{define-public}. By this name, the package can be made known in the
7208Scheme code, for instance as input to another package. Second, there is
7209the string in the @code{name} field of a package definition. This name
7210is used by package management commands such as
7211@command{guix package} and @command{guix build}.
ef5dd60a 7212
cf4a9129
LC
7213Both are usually the same and correspond to the lowercase conversion of
7214the project name chosen upstream, with underscores replaced with
7215hyphens. For instance, GNUnet is available as @code{gnunet}, and
7216SDL_net as @code{sdl-net}.
927097ef 7217
cf4a9129 7218We do not add @code{lib} prefixes for library packages, unless these are
081145cf 7219already part of the official project name. But @pxref{Python
cf4a9129
LC
7220Modules} and @ref{Perl Modules} for special rules concerning modules for
7221the Python and Perl languages.
927097ef 7222
1b366ee4 7223Font package names are handled differently, @pxref{Fonts}.
7fec52b7 7224
ef5dd60a 7225
cf4a9129
LC
7226@node Version Numbers
7227@subsection Version Numbers
ef5dd60a 7228
cf4a9129
LC
7229We usually package only the latest version of a given free software
7230project. But sometimes, for instance for incompatible library versions,
7231two (or more) versions of the same package are needed. These require
7232different Scheme variable names. We use the name as defined
7233in @ref{Package Naming}
7234for the most recent version; previous versions use the same name, suffixed
7235by @code{-} and the smallest prefix of the version number that may
7236distinguish the two versions.
ef5dd60a 7237
cf4a9129
LC
7238The name inside the package definition is the same for all versions of a
7239package and does not contain any version number.
ef5dd60a 7240
cf4a9129 7241For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 7242
cf4a9129
LC
7243@example
7244(define-public gtk+
7245 (package
17d8e33f
ML
7246 (name "gtk+")
7247 (version "3.9.12")
7248 ...))
cf4a9129
LC
7249(define-public gtk+-2
7250 (package
17d8e33f
ML
7251 (name "gtk+")
7252 (version "2.24.20")
7253 ...))
cf4a9129
LC
7254@end example
7255If we also wanted GTK+ 3.8.2, this would be packaged as
7256@example
7257(define-public gtk+-3.8
7258 (package
17d8e33f
ML
7259 (name "gtk+")
7260 (version "3.8.2")
7261 ...))
cf4a9129 7262@end example
ef5dd60a 7263
cbd02397
LC
7264@node Synopses and Descriptions
7265@subsection Synopses and Descriptions
7266
7267As we have seen before, each package in GNU@tie{}Guix includes a
7268synopsis and a description (@pxref{Defining Packages}). Synopses and
7269descriptions are important: They are what @command{guix package
7270--search} searches, and a crucial piece of information to help users
7271determine whether a given package suits their needs. Consequently,
7272packagers should pay attention to what goes into them.
7273
7274Synopses must start with a capital letter and must not end with a
7275period. They must not start with ``a'' or ``the'', which usually does
7276not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
7277tool that frobs files''. The synopsis should say what the package
7278is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
7279used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
7280matching a pattern''.
7281
7282Keep in mind that the synopsis must be meaningful for a very wide
7283audience. For example, ``Manipulate alignments in the SAM format''
7284might make sense for a seasoned bioinformatics researcher, but might be
7285fairly unhelpful or even misleading to a non-specialized audience. It
7286is a good idea to come up with a synopsis that gives an idea of the
7287application domain of the package. In this example, this might give
7288something like ``Manipulate nucleotide sequence alignments'', which
7289hopefully gives the user a better idea of whether this is what they are
7290looking for.
7291
7292@cindex Texinfo markup, in package descriptions
7293Descriptions should take between five and ten lines. Use full
7294sentences, and avoid using acronyms without first introducing them.
7295Descriptions can include Texinfo markup, which is useful to introduce
7296ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
7297hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
7298should be careful when using some characters for example @samp{@@} and
7299curly braces which are the basic special characters in Texinfo
7300(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
7301such as @command{guix package --show} take care of rendering it
7302appropriately.
cbd02397
LC
7303
7304Synopses and descriptions are translated by volunteers
7305@uref{http://translationproject.org/domain/guix-packages.html, at the
7306Translation Project} so that as many users as possible can read them in
7307their native language. User interfaces search them and display them in
7308the language specified by the current locale.
7309
7310Translation is a lot of work so, as a packager, please pay even more
7311attention to your synopses and descriptions as every change may entail
ba7d6c76 7312additional work for translators. In order to help them, it is possible
36743e71 7313to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
7314special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
7315Gettext}):
7316
7317@example
7318;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
7319(description "ARandR is designed to provide a simple visual front end
7320for the X11 resize-and-rotate (RandR) extension. @dots{}")
7321@end example
cbd02397 7322
ef5dd60a 7323
cf4a9129
LC
7324@node Python Modules
7325@subsection Python Modules
ef5dd60a 7326
cf4a9129
LC
7327We currently package Python 2 and Python 3, under the Scheme variable names
7328@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
7329To avoid confusion and naming clashes with other programming languages, it
7330seems desirable that the name of a package for a Python module contains
7331the word @code{python}.
ef5dd60a 7332
cf4a9129
LC
7333Some modules are compatible with only one version of Python, others with both.
7334If the package Foo compiles only with Python 3, we name it
7335@code{python-foo}; if it compiles only with Python 2, we name it
7336@code{python2-foo}. If it is compatible with both versions, we create two
7337packages with the corresponding names.
ef5dd60a 7338
cf4a9129
LC
7339If a project already contains the word @code{python}, we drop this;
7340for instance, the module python-dateutil is packaged under the names
7341@code{python-dateutil} and @code{python2-dateutil}.
113daf62 7342
523e4896 7343
cf4a9129
LC
7344@node Perl Modules
7345@subsection Perl Modules
523e4896 7346
cf4a9129
LC
7347Perl programs standing for themselves are named as any other package,
7348using the lowercase upstream name.
7349For Perl packages containing a single class, we use the lowercase class name,
7350replace all occurrences of @code{::} by dashes and prepend the prefix
7351@code{perl-}.
7352So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
7353Modules containing several classes keep their lowercase upstream name and
7354are also prepended by @code{perl-}. Such modules tend to have the word
7355@code{perl} somewhere in their name, which gets dropped in favor of the
7356prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 7357
523e4896 7358
7fec52b7
AE
7359@node Fonts
7360@subsection Fonts
7361
7362For fonts that are in general not installed by a user for typesetting
7363purposes, or that are distributed as part of a larger software package,
7364we rely on the general packaging rules for software; for instance, this
7365applies to the fonts delivered as part of the X.Org system or fonts that
7366are part of TeX Live.
7367
7368To make it easier for a user to search for fonts, names for other packages
7369containing only fonts are constructed as follows, independently of the
7370upstream package name.
7371
7372The name of a package containing only one font family starts with
7373@code{font-}; it is followed by the foundry name and a dash @code{-}
7374if the foundry is known, and the font family name, in which spaces are
7375replaced by dashes (and as usual, all upper case letters are transformed
7376to lower case).
7377For example, the Gentium font family by SIL is packaged under the name
7378@code{font-sil-gentium}.
7379
7380For a package containing several font families, the name of the collection
7381is used in the place of the font family name.
7382For instance, the Liberation fonts consist of three families,
7383Liberation Sans, Liberation Serif and Liberation Mono.
7384These could be packaged separately under the names
7385@code{font-liberation-sans} and so on; but as they are distributed together
7386under a common name, we prefer to package them together as
7387@code{font-liberation}.
7388
7389In the case where several formats of the same font family or font collection
7390are packaged separately, a short form of the format, prepended by a dash,
7391is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 7392@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
7393fonts.
7394
7395
b25937e3 7396
cf4a9129
LC
7397@node Bootstrapping
7398@section Bootstrapping
b25937e3 7399
cf4a9129 7400@c Adapted from the ELS 2013 paper.
b25937e3 7401
cf4a9129 7402@cindex bootstrapping
7889394e 7403
cf4a9129
LC
7404Bootstrapping in our context refers to how the distribution gets built
7405``from nothing''. Remember that the build environment of a derivation
7406contains nothing but its declared inputs (@pxref{Introduction}). So
7407there's an obvious chicken-and-egg problem: how does the first package
7408get built? How does the first compiler get compiled? Note that this is
7409a question of interest only to the curious hacker, not to the regular
7410user, so you can shamelessly skip this section if you consider yourself
7411a ``regular user''.
72b9d60d 7412
cf4a9129
LC
7413@cindex bootstrap binaries
7414The GNU system is primarily made of C code, with libc at its core. The
7415GNU build system itself assumes the availability of a Bourne shell and
7416command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
7417`grep'. Furthermore, build programs---programs that run
7418@code{./configure}, @code{make}, etc.---are written in Guile Scheme
7419(@pxref{Derivations}). Consequently, to be able to build anything at
7420all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
7421Binutils, libc, and the other packages mentioned above---the
7422@dfn{bootstrap binaries}.
72b9d60d 7423
cf4a9129
LC
7424These bootstrap binaries are ``taken for granted'', though we can also
7425re-create them if needed (more on that later).
72b9d60d 7426
cf4a9129 7427@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 7428
cf4a9129
LC
7429@c As of Emacs 24.3, Info-mode displays the image, but since it's a
7430@c large image, it's hard to scroll. Oh well.
7431@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 7432
cf4a9129
LC
7433The figure above shows the very beginning of the dependency graph of the
7434distribution, corresponding to the package definitions of the @code{(gnu
7435packages bootstrap)} module. At this level of detail, things are
7436slightly complex. First, Guile itself consists of an ELF executable,
7437along with many source and compiled Scheme files that are dynamically
7438loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
7439tarball shown in this graph. This tarball is part of Guix's ``source''
7440distribution, and gets inserted into the store with @code{add-to-store}
7441(@pxref{The Store}).
2e7b5cea 7442
cf4a9129
LC
7443But how do we write a derivation that unpacks this tarball and adds it
7444to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
7445derivation---the first one that gets built---uses @code{bash} as its
7446builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
7447@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
7448@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
7449the Guix source distribution, whose sole purpose is to allow the Guile
7450tarball to be unpacked.
fb729425 7451
cf4a9129
LC
7452Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
7453Guile that can be used to run subsequent build programs. Its first task
7454is to download tarballs containing the other pre-built binaries---this
7455is what the @code{.tar.xz.drv} derivations do. Guix modules such as
7456@code{ftp-client.scm} are used for this purpose. The
7457@code{module-import.drv} derivations import those modules in a directory
7458in the store, using the original layout. The
7459@code{module-import-compiled.drv} derivations compile those modules, and
7460write them in an output directory with the right layout. This
7461corresponds to the @code{#:modules} argument of
7462@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 7463
cf4a9129
LC
7464Finally, the various tarballs are unpacked by the
7465derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
7466etc., at which point we have a working C tool chain.
fb729425 7467
fb729425 7468
cf4a9129 7469@unnumberedsubsec Building the Build Tools
523e4896 7470
cf4a9129
LC
7471@c TODO: Add a package-level dependency graph generated from (gnu
7472@c packages base).
df2ce343 7473
cf4a9129
LC
7474Bootstrapping is complete when we have a full tool chain that does not
7475depend on the pre-built bootstrap tools discussed above. This
7476no-dependency requirement is verified by checking whether the files of
7477the final tool chain contain references to the @file{/gnu/store}
7478directories of the bootstrap inputs. The process that leads to this
7479``final'' tool chain is described by the package definitions found in
1f6f57df 7480the @code{(gnu packages commencement)} module.
df2ce343 7481
cf4a9129
LC
7482@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
7483The first tool that gets built with the bootstrap binaries is
7484GNU Make, which is a prerequisite for all the following packages.
7485From there Findutils and Diffutils get built.
523e4896 7486
cf4a9129
LC
7487Then come the first-stage Binutils and GCC, built as pseudo cross
7488tools---i.e., with @code{--target} equal to @code{--host}. They are
7489used to build libc. Thanks to this cross-build trick, this libc is
7490guaranteed not to hold any reference to the initial tool chain.
4af2447e 7491
cf4a9129
LC
7492From there the final Binutils and GCC are built. GCC uses @code{ld}
7493from the final Binutils, and links programs against the just-built libc.
7494This tool chain is used to build the other packages used by Guix and by
7495the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 7496
cf4a9129
LC
7497And voilà! At this point we have the complete set of build tools that
7498the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
7499variable of the @code{(gnu packages commencement)} module, and are
7500implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 7501(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 7502
4af2447e 7503
cf4a9129 7504@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 7505
cf4a9129
LC
7506Because the final tool chain does not depend on the bootstrap binaries,
7507those rarely need to be updated. Nevertheless, it is useful to have an
7508automated way to produce them, should an update occur, and this is what
7509the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 7510
cf4a9129
LC
7511The following command builds the tarballs containing the bootstrap
7512binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
7513of Coreutils and other basic command-line tools):
4b2615e1 7514
cf4a9129
LC
7515@example
7516guix build bootstrap-tarballs
7517@end example
7518
7519The generated tarballs are those that should be referred to in the
7520@code{(gnu packages bootstrap)} module mentioned at the beginning of
7521this section.
7522
7523Still here? Then perhaps by now you've started to wonder: when do we
7524reach a fixed point? That is an interesting question! The answer is
7525unknown, but if you would like to investigate further (and have
7526significant computational and storage resources to do so), then let us
7527know.
7528
7529@node Porting
7530@section Porting to a New Platform
7531
7532As discussed above, the GNU distribution is self-contained, and
7533self-containment is achieved by relying on pre-built ``bootstrap
7534binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
7535operating system kernel, CPU architecture, and application binary
7536interface (ABI). Thus, to port the distribution to a platform that is
7537not yet supported, one must build those bootstrap binaries, and update
7538the @code{(gnu packages bootstrap)} module to use them on that platform.
7539
7540Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
7541When everything goes well, and assuming the GNU tool chain supports the
7542target platform, this can be as simple as running a command like this
7543one:
7544
7545@example
7546guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
7547@end example
7548
1c0c417d
LC
7549For this to work, the @code{glibc-dynamic-linker} procedure in
7550@code{(gnu packages bootstrap)} must be augmented to return the right
7551file name for libc's dynamic linker on that platform; likewise,
7552@code{system->linux-architecture} in @code{(gnu packages linux)} must be
7553taught about the new platform.
7554
cf4a9129 7555Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
7556to be updated to refer to these binaries on the target platform. That
7557is, the hashes and URLs of the bootstrap tarballs for the new platform
7558must be added alongside those of the currently supported platforms. The
7559bootstrap Guile tarball is treated specially: it is expected to be
7560available locally, and @file{gnu-system.am} has rules do download it for
7561the supported architectures; a rule for the new platform must be added
7562as well.
cf4a9129
LC
7563
7564In practice, there may be some complications. First, it may be that the
7565extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
7566above) is not recognized by all the GNU tools. Typically, glibc
7567recognizes some of these, whereas GCC uses an extra @code{--with-abi}
7568configure flag (see @code{gcc.scm} for examples of how to handle this).
7569Second, some of the required packages could fail to build for that
7570platform. Lastly, the generated binaries could be broken for some
7571reason.
4af2447e 7572
9bf3c1a7 7573@c *********************************************************************
8c01b9d0 7574@include contributing.texi
c78bd12b 7575
568717fd
LC
7576@c *********************************************************************
7577@node Acknowledgments
7578@chapter Acknowledgments
7579
7580Guix is based on the Nix package manager, which was designed and
4c7ac9aa
LC
7581implemented by Eelco Dolstra, with contributions from other people (see
7582the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
7583management, and promoted unprecedented features, such as transactional
7584package upgrades and rollbacks, per-user profiles, and referentially
7585transparent build processes. Without this work, Guix would not exist.
7586
7587The Nix-based software distributions, Nixpkgs and NixOS, have also been
7588an inspiration for Guix.
7589
4c7ac9aa
LC
7590GNU@tie{}Guix itself is a collective work with contributions from a
7591number of people. See the @file{AUTHORS} file in Guix for more
7592information on these fine people. The @file{THANKS} file lists people
7593who have helped by reporting bugs, taking care of the infrastructure,
7594providing artwork and themes, making suggestions, and more---thank you!
7595
7596
568717fd
LC
7597@c *********************************************************************
7598@node GNU Free Documentation License
7599@appendix GNU Free Documentation License
7600
7601@include fdl-1.3.texi
7602
7603@c *********************************************************************
7604@node Concept Index
7605@unnumbered Concept Index
7606@printindex cp
7607
a85b83d2
LC
7608@node Programming Index
7609@unnumbered Programming Index
7610@syncodeindex tp fn
7611@syncodeindex vr fn
568717fd
LC
7612@printindex fn
7613
7614@bye
7615
7616@c Local Variables:
7617@c ispell-local-dictionary: "american";
7618@c End: