emacs: list: Support displaying URL links.
[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
db5a9444 13Copyright @copyright{} 2012, 2013, 2014, 2015, 2016 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
dd816355 19Copyright @copyright{} 2015 Leo Famulari
7df7a74e
NK
20
21Permission is granted to copy, distribute and/or modify this document
22under the terms of the GNU Free Documentation License, Version 1.3 or
23any later version published by the Free Software Foundation; with no
24Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
25copy of the license is included in the section entitled ``GNU Free
26Documentation License''.
27@end copying
568717fd 28
eeaf4427 29@dircategory Package management
568717fd
LC
30@direntry
31* guix: (guix). Guix, the functional package manager.
e49951eb 32* guix package: (guix)Invoking guix package
eeaf4427 33 Managing packages with Guix.
e49951eb 34* guix build: (guix)Invoking guix build
568717fd 35 Building packages with Guix.
054e8576
LC
36* guix system: (guix)Invoking guix system
37 Managing the operating system configuration.
568717fd 38@end direntry
568717fd 39
372c4bbc
DT
40@dircategory Software development
41@direntry
42* guix environment: (guix)Invoking guix environment
43 Building development environments with Guix.
44@end direntry
45
568717fd 46@titlepage
7730d112
LC
47@title GNU Guix Reference Manual
48@subtitle Using the GNU Guix Functional Package Manager
2cbed07e 49@author The GNU Guix Developers
568717fd
LC
50
51@page
52@vskip 0pt plus 1filll
53Edition @value{EDITION} @*
54@value{UPDATED} @*
55
7df7a74e 56@insertcopying
568717fd
LC
57@end titlepage
58
568717fd
LC
59@contents
60
61@c *********************************************************************
62@node Top
f8348b91 63@top GNU Guix
568717fd 64
f8348b91
LC
65This document describes GNU Guix version @value{VERSION}, a functional
66package management tool written for the GNU system.
568717fd
LC
67
68@menu
69* Introduction:: What is Guix about?
bd5e766b 70* Installation:: Installing Guix.
eeaf4427 71* Package Management:: Package installation, upgrade, etc.
c554de89 72* Emacs Interface:: Using Guix from Emacs.
568717fd
LC
73* Programming Interface:: Using Guix in Scheme.
74* Utilities:: Package management commands.
a1ba8475 75* GNU Distribution:: Software for your friendly GNU system.
9bf3c1a7 76* Contributing:: Your help needed!
568717fd
LC
77
78* Acknowledgments:: Thanks!
79* GNU Free Documentation License:: The license of this manual.
80* Concept Index:: Concepts.
a85b83d2 81* Programming Index:: Data types, functions, and variables.
aaa3eaa9
LC
82
83@detailmenu
84 --- The Detailed Node Listing ---
85
86Installation
87
1b2b8177 88* Binary Installation:: Getting Guix running in no time!
aaa3eaa9 89* Requirements:: Software needed to build and run Guix.
ec0339cd 90* Running the Test Suite:: Testing Guix.
aaa3eaa9
LC
91* Setting Up the Daemon:: Preparing the build daemon's environment.
92* Invoking guix-daemon:: Running the build daemon.
0e2d0213 93* Application Setup:: Application-specific setup.
aaa3eaa9
LC
94
95Setting Up the Daemon
96
97* Build Environment Setup:: Preparing the isolated build environment.
98* Daemon Offload Setup:: Offloading builds to remote machines.
99
100Package Management
101
102* Features:: How Guix will make your life brighter.
103* Invoking guix package:: Package installation, removal, etc.
aaa3eaa9
LC
104* Substitutes:: Downloading pre-built binaries.
105* Packages with Multiple Outputs:: Single source package, multiple outputs.
106* Invoking guix gc:: Running the garbage collector.
107* Invoking guix pull:: Fetching the latest Guix and distribution.
108* Invoking guix archive:: Exporting and importing store files.
109
c554de89
AK
110Emacs Interface
111
112* Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
113* Package Management: Emacs Package Management. Managing packages and generations.
9b0afb0d 114* Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
c554de89 115* Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
34850cd5 116* Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
187f80c6
AK
117* Completions: Emacs Completions. Completing @command{guix} shell command.
118* Development: Emacs Development. Tools for Guix developers.
32950fc8 119* Hydra: Emacs Hydra. Interface for Guix build farm.
c554de89 120
aaa3eaa9
LC
121Programming Interface
122
123* Defining Packages:: Defining new packages.
124* Build Systems:: Specifying how packages are built.
125* The Store:: Manipulating the package store.
126* Derivations:: Low-level interface to package derivations.
127* The Store Monad:: Purely functional interface to the store.
128* G-Expressions:: Manipulating build expressions.
129
92492b23
LC
130Defining Packages
131
132* package Reference:: The package data type.
133* origin Reference:: The origin data type.
134
aaa3eaa9
LC
135Utilities
136
137* Invoking guix build:: Building packages from the command line.
fcc58db6 138* Invoking guix edit:: Editing package definitions.
aaa3eaa9
LC
139* Invoking guix download:: Downloading a file and printing its hash.
140* Invoking guix hash:: Computing the cryptographic hash of a file.
141* Invoking guix import:: Importing package definitions.
142* Invoking guix refresh:: Updating package definitions.
143* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 144* Invoking guix size:: Profiling disk usage.
88856916 145* Invoking guix graph:: Visualizing the graph of packages.
aaa3eaa9 146* Invoking guix environment:: Setting up development environments.
aff8ce7c 147* Invoking guix publish:: Sharing substitutes.
d23c20f1 148* Invoking guix challenge:: Challenging substitute servers.
32efa254 149* Invoking guix container:: Process isolation.
aaa3eaa9
LC
150
151GNU Distribution
152
153* System Installation:: Installing the whole operating system.
35ed9306 154* System Configuration:: Configuring the operating system.
aaa3eaa9
LC
155* Installing Debugging Files:: Feeding the debugger.
156* Security Updates:: Deploying security fixes quickly.
157* Package Modules:: Packages from the programmer's viewpoint.
158* Packaging Guidelines:: Growing the distribution.
159* Bootstrapping:: GNU/Linux built from scratch.
160* Porting:: Targeting another platform or kernel.
161
162System Configuration
163
164* Using the Configuration System:: Customizing your GNU system.
165* operating-system Reference:: Detail of operating-system declarations.
166* File Systems:: Configuring file system mounts.
167* Mapped Devices:: Block device extra processing.
168* User Accounts:: Specifying user accounts.
598e19dc 169* Locales:: Language and cultural convention settings.
aaa3eaa9
LC
170* Services:: Specifying system services.
171* Setuid Programs:: Programs running with root privileges.
1b2b8177 172* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 173* Name Service Switch:: Configuring libc's name service switch.
aaa3eaa9
LC
174* Initial RAM Disk:: Linux-Libre bootstrapping.
175* GRUB Configuration:: Configuring the boot loader.
176* Invoking guix system:: Instantiating a system configuration.
177* Defining Services:: Adding new service definitions.
178
179Services
180
181* Base Services:: Essential system services.
182* Networking Services:: Network setup, SSH daemon, etc.
183* X Window:: Graphical display.
1b2b8177
LC
184* Desktop Services:: D-Bus and desktop services.
185* Database Services:: SQL databases.
d8c18af8 186* Mail Services:: IMAP, POP3, SMTP, and all that.
cbd02397 187* Web Services:: Web servers.
aa4ed923 188* Various Services:: Other services.
aaa3eaa9 189
0adfe95a
LC
190Defining Services
191
192* Service Composition:: The model for composing services.
193* Service Types and Services:: Types and services.
194* Service Reference:: API reference.
195* dmd Services:: A particular type of service.
196
aaa3eaa9
LC
197Packaging Guidelines
198
ec0339cd
LC
199* Software Freedom:: What may go into the distribution.
200* Package Naming:: What's in a name?
201* Version Numbers:: When the name is not enough.
cbd02397 202* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
203* Python Modules:: Taming the snake.
204* Perl Modules:: Little pearls.
205* Fonts:: Fond of fonts.
aaa3eaa9 206
8c01b9d0
ML
207Contributing
208
209* Building from Git:: The latest and greatest.
210* Running Guix Before It Is Installed:: Hacker tricks.
211* The Perfect Setup:: The right tools.
212* Coding Style:: Hygiene of the contributor.
213* Submitting Patches:: Share your work.
214
215Coding Style
216
217* Programming Paradigm:: How to compose your elements.
218* Modules:: Where to store your code?
219* Data Types and Pattern Matching:: Implementing data structures.
220* Formatting Code:: Writing conventions.
221
aaa3eaa9 222@end detailmenu
568717fd
LC
223@end menu
224
225@c *********************************************************************
226@node Introduction
227@chapter Introduction
228
c80e7e55
LC
229GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
230using the international phonetic alphabet (IPA).} is a functional
231package management tool for the GNU system. Package management consists
4bfc4ea3
NK
232of all activities that relate to building packages from sources,
233honoring their build-time and run-time dependencies,
c80e7e55
LC
234installing packages in user environments, upgrading installed packages
235to new versions or rolling back to a previous set, removing unused
236software packages, etc.
568717fd
LC
237
238@cindex functional package management
239The term @dfn{functional} refers to a specific package management
136787cb
LC
240discipline pioneered by Nix (@pxref{Acknowledgments}).
241In Guix, the package build and installation process is seen
4bfc4ea3
NK
242as a function, in the mathematical sense. That function takes inputs,
243such as build scripts, a compiler, and libraries, and
244returns an installed package. As a pure function, its result depends
568717fd
LC
245solely on its inputs---for instance, it cannot refer to software or
246scripts that were not explicitly passed as inputs. A build function
4bfc4ea3
NK
247always produces the same result when passed a given set of inputs. It
248cannot alter the system's environment in
568717fd
LC
249any way; for instance, it cannot create, modify, or delete files outside
250of its build and installation directories. This is achieved by running
e900c503 251build processes in isolated environments (or @dfn{containers}), where only their
4bfc4ea3 252explicit inputs are visible.
568717fd 253
e531ac2a 254@cindex store
568717fd 255The result of package build functions is @dfn{cached} in the file
e531ac2a
LC
256system, in a special directory called @dfn{the store} (@pxref{The
257Store}). Each package is installed in a directory of its own, in the
834129e0 258store---by default under @file{/gnu/store}. The directory name contains
568717fd
LC
259a hash of all the inputs used to build that package; thus, changing an
260input yields a different directory name.
261
262This approach is the foundation of Guix's salient features: support for
4bfc4ea3 263transactional package upgrade and rollback, per-user installation, and
eeaf4427 264garbage collection of packages (@pxref{Features}).
568717fd 265
4bfc4ea3 266Guix has a command-line interface, which allows users to build, install,
568717fd 267upgrade, and remove packages, as well as a Scheme programming interface.
568717fd 268
3ca2731c 269@cindex Guix System Distribution
4705641f 270@cindex GuixSD
a1ba8475 271Last but not least, Guix is used to build a distribution of the GNU
3ca2731c 272system, with many GNU and non-GNU free software packages. The Guix
4705641f
LC
273System Distribution, or GNU@tie{}GuixSD, takes advantage of the core
274properties of Guix at the system level. With GuixSD, users
3ca2731c
LC
275@emph{declare} all aspects of the operating system configuration, and
276Guix takes care of instantiating that configuration in a reproducible,
277stateless fashion. @xref{GNU Distribution}.
a1ba8475 278
bd5e766b
LC
279@c *********************************************************************
280@node Installation
281@chapter Installation
282
48febeb8
LC
283GNU Guix is available for download from its website at
284@url{http://www.gnu.org/software/guix/}. This section describes the
285software requirements of Guix, as well as how to install it and get
286ready to use it.
bd5e766b 287
5af6de3e
LC
288Note that this section is concerned with the installation of the package
289manager, which can be done on top of a running GNU/Linux system. If,
290instead, you want to install the complete GNU operating system,
6621cdb6 291@pxref{System Installation}.
5af6de3e 292
bd5e766b 293@menu
09722b11 294* Binary Installation:: Getting Guix running in no time!
bd5e766b 295* Requirements:: Software needed to build and run Guix.
ec0339cd 296* Running the Test Suite:: Testing Guix.
bd5e766b
LC
297* Setting Up the Daemon:: Preparing the build daemon's environment.
298* Invoking guix-daemon:: Running the build daemon.
0e2d0213 299* Application Setup:: Application-specific setup.
bd5e766b
LC
300@end menu
301
09722b11
LC
302@node Binary Installation
303@section Binary Installation
304
305This section describes how to install Guix on an arbitrary system from a
306self-contained tarball providing binaries for Guix and for all its
307dependencies. This is often quicker than installing from source, which
308is described in the next sections. The only requirement is to have
309GNU@tie{}tar and Xz.
310
311Installing goes along these lines:
312
313@enumerate
314@item
315Download the binary tarball from
daa8922a
LC
316@indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz},
317where @var{system} is @code{x86_64-linux} for an @code{x86_64} machine
318already running the kernel Linux, and so on.
319
320Make sure to download the associated @file{.sig} file and to verify the
321authenticity of the tarball against it, along these lines:
322
323@example
324$ wget ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
325$ gpg --verify guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
326@end example
327
328If that command fails because you don't have the required public key,
329then run this command to import it:
330
331@example
332$ gpg --keyserver keys.gnupg.net --recv-keys 3D9AEBB5
333@end example
334
335@noindent
336and rerun the @code{gpg --verify} command.
09722b11
LC
337
338@item
339As @code{root}, run:
340
341@example
5dc42964 342# cd /tmp
254b1c2e
LC
343# tar --warning=no-timestamp -xf \
344 guix-binary-@value{VERSION}.@var{system}.tar.xz
5dc42964 345# mv var/guix /var/ && mv gnu /
09722b11
LC
346@end example
347
7acd3439
LC
348This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
349The latter contains a ready-to-use profile for @code{root} (see next
350step.)
09722b11 351
5dc3ce5f
LC
352Do @emph{not} unpack the tarball on a working Guix system since that
353would overwrite its own essential files.
354
254b1c2e 355The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
e9ba6357
LC
356not emit warnings about ``implausibly old time stamps'' (such
357warnings were triggered by GNU@tie{}tar 1.26 and older; recent
358versions are fine.)
359They stem from the fact that all the
254b1c2e
LC
360files in the archive have their modification time set to zero (which
361means January 1st, 1970.) This is done on purpose to make sure the
362archive content is independent of its creation time, thus making it
363reproducible.
364
7acd3439
LC
365@item
366Make @code{root}'s profile available under @file{~/.guix-profile}:
367
368@example
369# ln -sf /var/guix/profiles/per-user/root/guix-profile \
370 ~root/.guix-profile
371@end example
372
43c33047
LC
373@item
374Create the group and user accounts for build users as explained below
375(@pxref{Build Environment Setup}).
376
09722b11 377@item
175ced41 378Run the daemon:
09722b11
LC
379
380@example
7acd3439 381# ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
09722b11
LC
382@end example
383
d2825c96
LC
384On hosts using the systemd init system, drop
385@file{~root/.guix-profile/lib/systemd/system/guix-daemon.service} in
386@file{/etc/systemd/system}.
387
ad227484
MDRS
388Likewise, on hosts using the Upstart init system, drop
389@file{~root/.guix-profile/lib/upstart/system/guix-daemon.conf} in
390@file{/etc/init}.
391
09722b11
LC
392@item
393Make the @command{guix} command available to other users on the machine,
394for instance with:
395
396@example
397# mkdir -p /usr/local/bin
398# cd /usr/local/bin
d72d05f9 399# ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
09722b11 400@end example
39f8ed14 401
aca738f3
LC
402It is also a good idea to make the Info version of this manual available
403there:
404
405@example
406# mkdir -p /usr/local/share/info
407# cd /usr/local/share/info
408# for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
409 do ln -s $i ; done
410@end example
411
412That way, assuming @file{/usr/local/share/info} is in the search path,
413running @command{info guix} will open this manual (@pxref{Other Info
414Directories,,, texinfo, GNU Texinfo}, for more details on changing the
415Info search path.)
416
39f8ed14
LC
417@item
418To use substitutes from @code{hydra.gnu.org} (@pxref{Substitutes}),
419authorize them:
420
421@example
7acd3439 422# guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
39f8ed14 423@end example
09722b11
LC
424@end enumerate
425
53de532f
LC
426And that's it! For additional tips and tricks, @pxref{Application
427Setup}.
09722b11 428
5dc3ce5f 429The @code{guix} package must remain available in @code{root}'s
09722b11
LC
430profile, or it would become subject to garbage collection---in which
431case you would find yourself badly handicapped by the lack of the
432@command{guix} command.
433
39f8ed14
LC
434The tarball in question can be (re)produced and verified simply by
435running the following command in the Guix source tree:
09722b11
LC
436
437@example
438make guix-binary.@var{system}.tar.xz
439@end example
440
441
bd5e766b
LC
442@node Requirements
443@section Requirements
444
09722b11
LC
445This section lists requirements when building Guix from source. The
446build procedure for Guix is the same as for other GNU software, and is
447not covered here. Please see the files @file{README} and @file{INSTALL}
448in the Guix source tree for additional details.
449
bd5e766b
LC
450GNU Guix depends on the following packages:
451
452@itemize
47c66da0 453@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
288dca55 454@item @url{http://gnupg.org/, GNU libgcrypt};
f0b98b84 455@item @url{http://www.gnu.org/software/make/, GNU Make}.
8a96bd4b
ID
456@end itemize
457
458The following dependencies are optional:
459
460@itemize
288dca55 461@item
8a96bd4b 462Installing
288dca55 463@url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
2f7d2d91
LC
464allow you to use the @command{guix import pypi} command (@pxref{Invoking
465guix import}). It is of
288dca55 466interest primarily for developers and not for casual users.
8a96bd4b
ID
467@item
468Installing @uref{http://gnutls.org/, GnuTLS-Guile} will
469allow you to access @code{https} URLs with the @command{guix download}
d45dc6da
EB
470command (@pxref{Invoking guix download}), the @command{guix import pypi}
471command, and the @command{guix import cpan} command. This is primarily
472of interest to developers. @xref{Guile Preparations, how to install the
473GnuTLS bindings for Guile,, gnutls-guile, GnuTLS-Guile}.
bd5e766b
LC
474@end itemize
475
476Unless @code{--disable-daemon} was passed to @command{configure}, the
477following packages are also needed:
478
479@itemize
368d08f7
LC
480@item @url{http://sqlite.org, SQLite 3};
481@item @url{http://www.bzip.org, libbz2};
482@item @url{http://gcc.gnu.org, GCC's g++}, with support for the
483C++11 standard.
bd5e766b
LC
484@end itemize
485
4bfc4ea3
NK
486When a working installation of @url{http://nixos.org/nix/, the Nix package
487manager} is available, you
bd5e766b 488can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 489Nix replaces the three dependencies above.
bd5e766b 490
b22a12fd
LC
491Guix is compatible with Nix, so it is possible to share the same store
492between both. To do so, you must pass @command{configure} not only the
493same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
494@code{--localstatedir} value. The latter is essential because it
495specifies where the database that stores metadata about the store is
834129e0 496located, among other things. The default values for Nix are
b22a12fd 497@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
498Note that @code{--disable-daemon} is not required if
499your goal is to share the store with Nix.
b22a12fd 500
ec0339cd
LC
501@node Running the Test Suite
502@section Running the Test Suite
503
504After a successful @command{configure} and @code{make} run, it is a good
505idea to run the test suite. It can help catch issues with the setup or
506environment, or bugs in Guix itself---and really, reporting test
507failures is a good way to help improve the software. To run the test
508suite, type:
509
510@example
511make check
512@end example
513
514Test cases can run in parallel: you can use the @code{-j} option of
515GNU@tie{}make to speed things up. The first run may take a few minutes
516on a recent machine; subsequent runs will be faster because the store
517that is created for test purposes will already have various things in
518cache.
519
a887fd8d
LC
520It is also possible to run a subset of the tests by defining the
521@code{TESTS} makefile variable as in this example:
522
523@example
524make check TESTS="tests/store.scm tests/cpio.scm"
525@end example
526
ec0339cd
LC
527Upon failure, please email @email{bug-guix@@gnu.org} and attach the
528@file{test-suite.log} file. When @file{tests/@var{something}.scm}
529fails, please also attach the @file{@var{something}.log} file available
530in the top-level build directory. Please specify the Guix version being
531used as well as version numbers of the dependencies
532(@pxref{Requirements}) in your message.
533
bd5e766b
LC
534@node Setting Up the Daemon
535@section Setting Up the Daemon
536
537@cindex daemon
538Operations such as building a package or running the garbage collector
49e6291a 539are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
540behalf of clients. Only the daemon may access the store and its
541associated database. Thus, any operation that manipulates the store
542goes through the daemon. For instance, command-line tools such as
e49951eb 543@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
544daemon (@i{via} remote procedure calls) to instruct it what to do.
545
49e6291a 546The following sections explain how to prepare the build daemon's
225dafde
LC
547environment. Also @ref{Substitutes}, for information on how to allow
548the daemon to download pre-built binaries.
49e6291a
LC
549
550@menu
551* Build Environment Setup:: Preparing the isolated build environment.
552* Daemon Offload Setup:: Offloading builds to remote machines.
553@end menu
554
555@node Build Environment Setup
556@subsection Build Environment Setup
557
bd5e766b
LC
558In a standard multi-user setup, Guix and its daemon---the
559@command{guix-daemon} program---are installed by the system
834129e0 560administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
561@command{guix-daemon} runs as @code{root}. Unprivileged users may use
562Guix tools to build packages or otherwise access the store, and the
563daemon will do it on their behalf, ensuring that the store is kept in a
564consistent state, and allowing built packages to be shared among users.
565
566@cindex build users
567When @command{guix-daemon} runs as @code{root}, you may not want package
568build processes themselves to run as @code{root} too, for obvious
569security reasons. To avoid that, a special pool of @dfn{build users}
570should be created for use by build processes started by the daemon.
571These build users need not have a shell and a home directory: they will
572just be used when the daemon drops @code{root} privileges in build
573processes. Having several such users allows the daemon to launch
574distinct build processes under separate UIDs, which guarantees that they
575do not interfere with each other---an essential feature since builds are
576regarded as pure functions (@pxref{Introduction}).
577
578On a GNU/Linux system, a build user pool may be created like this (using
579Bash syntax and the @code{shadow} commands):
580
091196b3
LC
581@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
582@c for why `-G' is needed.
bd5e766b 583@example
cfc149dc
LC
584# groupadd --system guixbuild
585# for i in `seq -w 1 10`;
bd5e766b 586 do
cfc149dc
LC
587 useradd -g guixbuild -G guixbuild \
588 -d /var/empty -s `which nologin` \
589 -c "Guix build user $i" --system \
590 guixbuilder$i;
bd5e766b
LC
591 done
592@end example
593
594@noindent
54eb03ab
LC
595The number of build users determines how many build jobs may run in
596parallel, as specified by the @option{--max-jobs} option
d2825c96
LC
597(@pxref{Invoking guix-daemon, @option{--max-jobs}}). The
598@code{guix-daemon} program may then be run as @code{root} with the
599following command@footnote{If your machine uses the systemd init system,
600dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
601file in @file{/etc/systemd/system} will ensure that
ad227484
MDRS
602@command{guix-daemon} is automatically started. Similarly, if your
603machine uses the Upstart init system, drop the
604@file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
605file in @file{/etc/init}.}:
bd5e766b
LC
606
607@example
cfc149dc 608# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
609@end example
610
e900c503 611@cindex chroot
b095792f
LC
612@noindent
613This way, the daemon starts build processes in a chroot, under one of
cfc149dc 614the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
615environment contains nothing but:
616
617@c Keep this list in sync with libstore/build.cc! -----------------------
618@itemize
619@item
4743a4da
LC
620a minimal @code{/dev} directory, created mostly independently from the
621host @code{/dev}@footnote{``Mostly'', because while the set of files
622that appear in the chroot's @code{/dev} is fixed, most of these files
623can only be created if the host has them.};
624
625@item
626the @code{/proc} directory; it only shows the container's processes
627since a separate PID name space is used;
6dc99317
LC
628
629@item
630@file{/etc/passwd} with an entry for the current user and an entry for
631user @file{nobody};
632
633@item
634@file{/etc/group} with an entry for the user's group;
635
636@item
637@file{/etc/hosts} with an entry that maps @code{localhost} to
638@code{127.0.0.1};
639
640@item
641a writable @file{/tmp} directory.
642@end itemize
b095792f 643
cb960102
ED
644You can influence the directory where the daemon stores build trees
645@i{via} the @code{TMPDIR} environment variable. However, the build tree
7a57c96a 646within the chroot is always @file{/tmp/guix-build-@var{name}.drv-0},
cb960102
ED
647where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
648This way, the value of @code{TMPDIR} does not leak inside build
649environments, which avoids discrepancies in cases where build processes
650capture the name of their build tree.
651
e0c941fe
LC
652@vindex http_proxy
653The daemon also honors the @code{http_proxy} environment variable for
654HTTP downloads it performs, be it for fixed-output derivations
655(@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
656
1e2644bb
LC
657If you are installing Guix as an unprivileged user, it is still possible
658to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
659However, build processes will not be isolated from one another, and not
660from the rest of the system. Thus, build processes may interfere with
661each other, and may access programs, libraries, and other files
662available on the system---making it much harder to view them as
663@emph{pure} functions.
bd5e766b 664
49e6291a
LC
665
666@node Daemon Offload Setup
667@subsection Using the Offload Facility
668
669@cindex offloading
4ec2e92d
LC
670@cindex build hook
671When desired, the build daemon can @dfn{offload}
672derivation builds to other machines
49e6291a
LC
673running Guix, using the @code{offload} @dfn{build hook}. When that
674feature is enabled, a list of user-specified build machines is read from
675@file{/etc/guix/machines.scm}; anytime a build is requested, for
676instance via @code{guix build}, the daemon attempts to offload it to one
677of the machines that satisfies the derivation's constraints, in
678particular its system type---e.g., @file{x86_64-linux}. Missing
679prerequisites for the build are copied over SSH to the target machine,
680which then proceeds with the build; upon success the output(s) of the
681build are copied back to the initial machine.
682
4ec2e92d 683The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
684
685@example
686(list (build-machine
687 (name "eightysix.example.org")
688 (system "x86_64-linux")
689 (user "bob")
690 (speed 2.)) ; incredibly fast!
691
692 (build-machine
693 (name "meeps.example.org")
694 (system "mips64el-linux")
695 (user "alice")
696 (private-key
697 (string-append (getenv "HOME")
c4fdfd6f 698 "/.lsh/identity-for-guix"))))
49e6291a
LC
699@end example
700
701@noindent
702In the example above we specify a list of two build machines, one for
703the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
704architecture.
705
706In fact, this file is---not surprisingly!---a Scheme file that is
707evaluated when the @code{offload} hook is started. Its return value
708must be a list of @code{build-machine} objects. While this example
709shows a fixed list of build machines, one could imagine, say, using
710DNS-SD to return a list of potential build machines discovered in the
711local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
c678a4ee
LC
712Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
713detailed below.
4ec2e92d 714
c678a4ee
LC
715@deftp {Data Type} build-machine
716This data type represents build machines the daemon may offload builds
717to. The important fields are:
49e6291a
LC
718
719@table @code
720
721@item name
722The remote machine's host name.
723
724@item system
c678a4ee 725The remote machine's system type---e.g., @code{"x86_64-linux"}.
49e6291a
LC
726
727@item user
728The user account to use when connecting to the remote machine over SSH.
729Note that the SSH key pair must @emph{not} be passphrase-protected, to
730allow non-interactive logins.
731
732@end table
733
4ec2e92d 734A number of optional fields may be specified:
49e6291a
LC
735
736@table @code
737
cecd72d5
LC
738@item port
739Port number of the machine's SSH server (default: 22).
740
49e6291a
LC
741@item private-key
742The SSH private key file to use when connecting to the machine.
743
c4fdfd6f
LC
744Currently offloading uses GNU@tie{}lsh as its SSH client
745(@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must
746be an lsh key file. This may change in the future, though.
747
49e6291a
LC
748@item parallel-builds
749The number of builds that may run in parallel on the machine (1 by
750default.)
751
752@item speed
753A ``relative speed factor''. The offload scheduler will tend to prefer
754machines with a higher speed factor.
755
756@item features
757A list of strings denoting specific features supported by the machine.
758An example is @code{"kvm"} for machines that have the KVM Linux modules
759and corresponding hardware support. Derivations can request features by
760name, and they will be scheduled on matching build machines.
761
762@end table
c678a4ee 763@end deftp
49e6291a
LC
764
765The @code{guix} command must be in the search path on the build
766machines, since offloading works by invoking the @code{guix archive} and
c4fdfd6f
LC
767@code{guix build} commands. In addition, the Guix modules must be in
768@code{$GUILE_LOAD_PATH} on the build machine---you can check whether
769this is the case by running:
770
771@example
74273b6f 772lsh build-machine guile -c "'(use-modules (guix config))'"
c4fdfd6f 773@end example
49e6291a
LC
774
775There's one last thing to do once @file{machines.scm} is in place. As
776explained above, when offloading, files are transferred back and forth
c4fdfd6f
LC
777between the machine stores. For this to work, you first need to
778generate a key pair on each machine to allow the daemon to export signed
779archives of files from the store (@pxref{Invoking guix archive}):
49e6291a
LC
780
781@example
782# guix archive --generate-key
783@end example
784
785@noindent
c4fdfd6f
LC
786Each build machine must authorize the key of the master machine so that
787it accepts store items it receives from the master:
788
789@example
790# guix archive --authorize < master-public-key.txt
791@end example
792
793@noindent
794Likewise, the master machine must authorize the key of each build machine.
795
796All the fuss with keys is here to express pairwise mutual trust
797relations between the master and the build machines. Concretely, when
798the master receives files from a build machine (and @i{vice versa}), its
799build daemon can make sure they are genuine, have not been tampered
800with, and that they are signed by an authorized key.
49e6291a
LC
801
802
bd5e766b
LC
803@node Invoking guix-daemon
804@section Invoking @command{guix-daemon}
805
806The @command{guix-daemon} program implements all the functionality to
807access the store. This includes launching build processes, running the
808garbage collector, querying the availability of a build result, etc. It
809is normally run as @code{root} like this:
810
811@example
cfc149dc 812# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
813@end example
814
815@noindent
081145cf 816For details on how to set it up, @pxref{Setting Up the Daemon}.
bd5e766b 817
e900c503
LC
818@cindex chroot
819@cindex container, build environment
820@cindex build environment
821@cindex reproducible builds
bd5e766b
LC
822By default, @command{guix-daemon} launches build processes under
823different UIDs, taken from the build group specified with
824@code{--build-users-group}. In addition, each build process is run in a
825chroot environment that only contains the subset of the store that the
826build process depends on, as specified by its derivation
827(@pxref{Programming Interface, derivation}), plus a set of specific
828system directories. By default, the latter contains @file{/dev} and
e900c503
LC
829@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
830@dfn{container}: in addition to having its own file system tree, it has
831a separate mount name space, its own PID name space, network name space,
832etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b 833
cbc538fe
LC
834When the daemon performs a build on behalf of the user, it creates a
835build directory under @file{/tmp} or under the directory specified by
836its @code{TMPDIR} environment variable; this directory is shared with
837the container for the duration of the build. Be aware that using a
838directory other than @file{/tmp} can affect build results---for example,
839with a longer directory name, a build process that uses Unix-domain
840sockets might hit the name length limitation for @code{sun_path}, which
841it would otherwise not hit.
842
843The build directory is automatically deleted upon completion, unless the
844build failed and the client specified @option{--keep-failed}
845(@pxref{Invoking guix build, @option{--keep-failed}}).
846
bd5e766b
LC
847The following command-line options are supported:
848
849@table @code
850@item --build-users-group=@var{group}
851Take users from @var{group} to run build processes (@pxref{Setting Up
852the Daemon, build users}).
853
6858f9d1 854@item --no-substitutes
b5385b52 855@cindex substitutes
6858f9d1 856Do not use substitutes for build products. That is, always build things
c4202d60
LC
857locally instead of allowing downloads of pre-built binaries
858(@pxref{Substitutes}).
6858f9d1 859
b5385b52
LC
860By default substitutes are used, unless the client---such as the
861@command{guix package} command---is explicitly invoked with
862@code{--no-substitutes}.
863
864When the daemon runs with @code{--no-substitutes}, clients can still
865explicitly enable substitution @i{via} the @code{set-build-options}
866remote procedure call (@pxref{The Store}).
867
9176607e 868@item --substitute-urls=@var{urls}
f8a8e0fe 869@anchor{daemon-substitute-urls}
9176607e 870Consider @var{urls} the default whitespace-separated list of substitute
ae806096 871source URLs. When this option is omitted, @indicateurl{http://hydra.gnu.org}
9176607e
LC
872is used.
873
874This means that substitutes may be downloaded from @var{urls}, as long
875as they are signed by a trusted signature (@pxref{Substitutes}).
876
4ec2e92d
LC
877@cindex build hook
878@item --no-build-hook
879Do not use the @dfn{build hook}.
880
881The build hook is a helper program that the daemon can start and to
882which it submits build requests. This mechanism is used to offload
883builds to other machines (@pxref{Daemon Offload Setup}).
884
bd5e766b
LC
885@item --cache-failures
886Cache build failures. By default, only successful builds are cached.
887
30d9aa54
LC
888When this option is used, @command{guix gc --list-failures} can be used
889to query the set of store items marked as failed; @command{guix gc
890--clear-failures} removes store items from the set of cached failures.
891@xref{Invoking guix gc}.
892
bd5e766b
LC
893@item --cores=@var{n}
894@itemx -c @var{n}
895Use @var{n} CPU cores to build each derivation; @code{0} means as many
896as available.
897
6efc160e 898The default value is @code{0}, but it may be overridden by clients, such
e49951eb
MW
899as the @code{--cores} option of @command{guix build} (@pxref{Invoking
900guix build}).
bd5e766b
LC
901
902The effect is to define the @code{NIX_BUILD_CORES} environment variable
903in the build process, which can then use it to exploit internal
904parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
905
906@item --max-jobs=@var{n}
907@itemx -M @var{n}
908Allow at most @var{n} build jobs in parallel. The default value is
f6526eb3
LC
909@code{1}. Setting it to @code{0} means that no builds will be performed
910locally; instead, the daemon will offload builds (@pxref{Daemon Offload
911Setup}), or simply fail.
bd5e766b 912
ecf84b7c
LC
913@item --rounds=@var{N}
914Build each derivation @var{n} times in a row, and raise an error if
915consecutive build results are not bit-for-bit identical. Note that this
916setting can be overridden by clients such as @command{guix build}
917(@pxref{Invoking guix build}).
918
bd5e766b
LC
919@item --debug
920Produce debugging output.
921
922This is useful to debug daemon start-up issues, but then it may be
923overridden by clients, for example the @code{--verbosity} option of
e49951eb 924@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
925
926@item --chroot-directory=@var{dir}
927Add @var{dir} to the build chroot.
928
929Doing this may change the result of build processes---for instance if
930they use optional dependencies found in @var{dir} when it is available,
931and not otherwise. For that reason, it is not recommended to do so.
932Instead, make sure that each derivation declares all the inputs that it
933needs.
934
935@item --disable-chroot
936Disable chroot builds.
937
938Using this option is not recommended since, again, it would allow build
1e2644bb
LC
939processes to gain access to undeclared dependencies. It is necessary,
940though, when @command{guix-daemon} is running under an unprivileged user
941account.
bd5e766b
LC
942
943@item --disable-log-compression
944Disable compression of the build logs.
945
1da983b9
LC
946Unless @code{--lose-logs} is used, all the build logs are kept in the
947@var{localstatedir}. To save space, the daemon automatically compresses
948them with bzip2 by default. This option disables that.
949
ab3893d7
LC
950@item --disable-deduplication
951@cindex deduplication
bd5e766b
LC
952Disable automatic file ``deduplication'' in the store.
953
1da983b9 954By default, files added to the store are automatically ``deduplicated'':
ab3893d7
LC
955if a newly added file is identical to another one found in the store,
956the daemon makes the new file a hard link to the other file. This can
4988dd40 957noticeably reduce disk usage, at the expense of slightly increased
ab3893d7
LC
958input/output load at the end of a build process. This option disables
959this optimization.
1da983b9 960
6e37066e
LC
961@item --gc-keep-outputs[=yes|no]
962Tell whether the garbage collector (GC) must keep outputs of live
963derivations.
964
965When set to ``yes'', the GC will keep the outputs of any live derivation
966available in the store---the @code{.drv} files. The default is ``no'',
967meaning that derivation outputs are kept only if they are GC roots.
968
969@item --gc-keep-derivations[=yes|no]
970Tell whether the garbage collector (GC) must keep derivations
971corresponding to live outputs.
972
973When set to ``yes'', as is the case by default, the GC keeps
974derivations---i.e., @code{.drv} files---as long as at least one of their
975outputs is live. This allows users to keep track of the origins of
976items in their store. Setting it to ``no'' saves a bit of disk space.
977
978Note that when both @code{--gc-keep-derivations} and
979@code{--gc-keep-outputs} are used, the effect is to keep all the build
980prerequisites (the sources, compiler, libraries, and other build-time
981tools) of live objects in the store, regardless of whether these
982prerequisites are live. This is convenient for developers since it
983saves rebuilds or downloads.
984
bd5e766b
LC
985@item --impersonate-linux-2.6
986On Linux-based systems, impersonate Linux 2.6. This means that the
987kernel's @code{uname} system call will report 2.6 as the release number.
988
989This might be helpful to build programs that (usually wrongfully) depend
990on the kernel version number.
991
992@item --lose-logs
993Do not keep build logs. By default they are kept under
ce33631f 994@code{@var{localstatedir}/guix/log}.
bd5e766b
LC
995
996@item --system=@var{system}
997Assume @var{system} as the current system type. By default it is the
998architecture/kernel pair found at configure time, such as
999@code{x86_64-linux}.
b8d2aa26
LC
1000
1001@item --listen=@var{socket}
1002Listen for connections on @var{socket}, the file name of a Unix-domain
1003socket. The default socket is
1004@file{@var{localstatedir}/daemon-socket/socket}. This option is only
1005useful in exceptional circumstances, such as if you need to run several
1006daemons on the same machine.
bd5e766b
LC
1007@end table
1008
1009
0e2d0213
LC
1010@node Application Setup
1011@section Application Setup
1012
85e57214
LC
1013When using Guix on top of GNU/Linux distribution other than GuixSD---a
1014so-called @dfn{foreign distro}---a few additional steps are needed to
1015get everything in place. Here are some of them.
0e2d0213
LC
1016
1017@subsection Locales
1018
5c3c1427 1019@anchor{locales-and-locpath}
0e2d0213 1020@cindex locales, when not on GuixSD
5c3c1427 1021@vindex LOCPATH
85e57214 1022@vindex GUIX_LOCPATH
0e2d0213
LC
1023Packages installed @i{via} Guix will not use the host system's locale
1024data. Instead, you must first install one of the locale packages
85e57214
LC
1025available with Guix and then define the @code{GUIX_LOCPATH} environment
1026variable:
0e2d0213
LC
1027
1028@example
1029$ guix package -i glibc-locales
85e57214 1030$ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
0e2d0213
LC
1031@end example
1032
1033Note that the @code{glibc-locales} package contains data for all the
1034locales supported by the GNU@tie{}libc and weighs in at around
1035110@tie{}MiB. Alternately, the @code{glibc-utf8-locales} is smaller but
1036limited to a few UTF-8 locales.
1037
85e57214
LC
1038The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1039(@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1040Manual}). There are two important differences though:
1041
1042@enumerate
1043@item
1044@code{GUIX_LOCPATH} is honored only by Guix's libc, and not by the libc
1045provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
f9b9a033 1046to make sure the foreign distro's programs will not end up loading
85e57214
LC
1047incompatible locale data.
1048
1049@item
1050libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1051@code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1052should your Guix profile contain a mixture of programs linked against
1053different libc version, each libc version will only try to load locale
1054data in the right format.
1055@end enumerate
1056
1057This is important because the locale data format used by different libc
1058versions may be incompatible.
1059
0e2d0213
LC
1060@subsection X11 Fonts
1061
4988dd40 1062The majority of graphical applications use Fontconfig to locate and
0e2d0213
LC
1063load fonts and perform X11-client-side rendering. Guix's
1064@code{fontconfig} package looks for fonts in @file{$HOME/.guix-profile}
1065by default. Thus, to allow graphical applications installed with Guix
1066to display fonts, you will have to install fonts with Guix as well.
1067Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
8fe5b1d1 1068@code{font-gnu-freefont-ttf}.
0e2d0213 1069
5c36edc8
LC
1070To display text written in Chinese languages, Japanese, or Korean in
1071graphical applications, consider installing
1072@code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1073has multiple outputs, one per language family (@pxref{Packages with
1074Multiple Outputs}). For instance, the following command installs fonts
1075for Chinese languages:
1076
1077@example
1078guix package -i font-adobe-source-han-sans:cn
1079@end example
1080
0e2d0213
LC
1081@c TODO What else?
1082
eeaf4427
LC
1083@c *********************************************************************
1084@node Package Management
1085@chapter Package Management
1086
f8348b91 1087The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427
LC
1088remove software packages, without having to know about their build
1089procedure or dependencies. Guix also goes beyond this obvious set of
1090features.
1091
1092This chapter describes the main features of Guix, as well as the package
c1941588 1093management tools it provides. Two user interfaces are provided for
c554de89
AK
1094routine package management tasks: A command-line interface described below
1095(@pxref{Invoking guix package, @code{guix package}}), as well as a visual user
1096interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}).
eeaf4427
LC
1097
1098@menu
1099* Features:: How Guix will make your life brighter.
e49951eb 1100* Invoking guix package:: Package installation, removal, etc.
c4202d60 1101* Substitutes:: Downloading pre-built binaries.
760c60d6 1102* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 1103* Invoking guix gc:: Running the garbage collector.
f651b477 1104* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 1105* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
1106@end menu
1107
1108@node Features
1109@section Features
1110
1111When using Guix, each package ends up in the @dfn{package store}, in its
1112own directory---something that resembles
9a130e19
AK
1113@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
1114(note that Guix comes with an Emacs extension to shorten those file
081145cf 1115names, @pxref{Emacs Prettify}.)
eeaf4427
LC
1116
1117Instead of referring to these directories, users have their own
1118@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
1119use. These profiles are stored within each user's home directory, at
1120@code{$HOME/.guix-profile}.
eeaf4427 1121
821b0015 1122For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 1123@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 1124@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
1125@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1126simply continues to point to
834129e0 1127@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 1128coexist on the same system without any interference.
eeaf4427 1129
e49951eb
MW
1130The @command{guix package} command is the central tool to manage
1131packages (@pxref{Invoking guix package}). It operates on those per-user
821b0015 1132profiles, and can be used @emph{with normal user privileges}.
eeaf4427
LC
1133
1134The command provides the obvious install, remove, and upgrade
1135operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 1136the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 1137@command{guix package} process is terminated during the transaction,
eeaf4427
LC
1138or if a power outage occurs during the transaction, then the user's
1139profile remains in its previous state, and remains usable.
1140
1141In addition, any package transaction may be @emph{rolled back}. So, if,
1142for example, an upgrade installs a new version of a package that turns
1143out to have a serious bug, users may roll back to the previous instance
4af2447e
LC
1144of their profile, which was known to work well. Similarly, the global
1145system configuration is subject to transactional upgrades and roll-back
1146(@pxref{Using the Configuration System}).
eeaf4427
LC
1147
1148All those packages in the package store may be @emph{garbage-collected}.
1149Guix can determine which packages are still referenced by the user
fe8ff028 1150profiles, and remove those that are provably no longer referenced
e49951eb 1151(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
1152generations of their profile so that the packages they refer to can be
1153collected.
eeaf4427 1154
e900c503
LC
1155@cindex reproducibility
1156@cindex reproducible builds
eeaf4427
LC
1157Finally, Guix takes a @dfn{purely functional} approach to package
1158management, as described in the introduction (@pxref{Introduction}).
834129e0 1159Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
1160inputs that were used to build that package---compiler, libraries, build
1161scripts, etc. This direct correspondence allows users to make sure a
1162given package installation matches the current state of their
e900c503
LC
1163distribution. It also helps maximize @dfn{build reproducibility}:
1164thanks to the isolated build environments that are used, a given build
1165is likely to yield bit-identical files when performed on different
1166machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 1167
c4202d60 1168@cindex substitutes
eeaf4427 1169This foundation allows Guix to support @dfn{transparent binary/source
c4202d60 1170deployment}. When a pre-built binary for a @file{/gnu/store} item is
18f2887b 1171available from an external source---a @dfn{substitute}, Guix just
c4202d60
LC
1172downloads it and unpacks it;
1173otherwise, it builds the package from source, locally
1174(@pxref{Substitutes}).
eeaf4427 1175
f5fd4fd2
LC
1176Control over the build environment is a feature that is also useful for
1177developers. The @command{guix environment} command allows developers of
1178a package to quickly set up the right development environment for their
1179package, without having to manually install the package's dependencies
1180in their profile (@pxref{Invoking guix environment}).
1181
e49951eb
MW
1182@node Invoking guix package
1183@section Invoking @command{guix package}
eeaf4427 1184
e49951eb 1185The @command{guix package} command is the tool that allows users to
eeaf4427
LC
1186install, upgrade, and remove packages, as well as rolling back to
1187previous configurations. It operates only on the user's own profile,
1188and works with normal user privileges (@pxref{Features}). Its syntax
1189is:
1190
1191@example
e49951eb 1192guix package @var{options}
eeaf4427
LC
1193@end example
1194
ba55b1cb 1195Primarily, @var{options} specifies the operations to be performed during
eeaf4427 1196the transaction. Upon completion, a new profile is created, but
99bd74d5 1197previous @dfn{generations} of the profile remain available, should the user
eeaf4427
LC
1198want to roll back.
1199
6447738c
MW
1200For example, to remove @code{lua} and install @code{guile} and
1201@code{guile-cairo} in a single transaction:
1202
1203@example
1204guix package -r lua -i guile guile-cairo
1205@end example
1206
99bd74d5
LC
1207@command{guix package} also supports a @dfn{declarative approach}
1208whereby the user specifies the exact set of packages to be available and
1209passes it @i{via} the @option{--manifest} option
1210(@pxref{profile-manifest, @option{--manifest}}).
1211
b9e5c0a9 1212For each user, a symlink to the user's default profile is automatically
0ec1af59 1213created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
1214current generation of the user's default profile. Thus, users can add
1215@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1216variable, and so on.
d664f1b4
LC
1217@cindex search paths
1218If you are not using the Guix System Distribution, consider adding the
1219following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1220Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1221shells get all the right environment variable definitions:
1222
1223@example
1224GUIX_PROFILE="$HOME/.guix-profile" \
1225source "$HOME/.guix-profile/etc/profile"
1226@end example
b9e5c0a9 1227
4379c35b
LC
1228In a multi-user setup, user profiles are stored in a place registered as
1229a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1230to (@pxref{Invoking guix gc}). That directory is normally
0ec1af59
LC
1231@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1232@var{localstatedir} is the value passed to @code{configure} as
4379c35b
LC
1233@code{--localstatedir}, and @var{user} is the user name. The
1234@file{per-user} directory is created when @command{guix-daemon} is
1235started, and the @var{user} sub-directory is created by @command{guix
1236package}.
0ec1af59
LC
1237
1238The @var{options} can be among the following:
1239
eeaf4427
LC
1240@table @code
1241
6447738c
MW
1242@item --install=@var{package} @dots{}
1243@itemx -i @var{package} @dots{}
1244Install the specified @var{package}s.
eeaf4427 1245
6447738c 1246Each @var{package} may specify either a simple package name, such as
eeaf4427 1247@code{guile}, or a package name followed by a hyphen and version number,
724311a2
LC
1248such as @code{guile-1.8.8} or simply @code{guile-1.8} (in the latter
1249case, the newest version prefixed by @code{1.8} is selected.)
1250
1251If no version number is specified, the
dc5669cd
MW
1252newest available version will be selected. In addition, @var{package}
1253may contain a colon, followed by the name of one of the outputs of the
6e721c4d 1254package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
e7f34eb0
LC
1255(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1256name (and optionally version) are searched for among the GNU
1257distribution modules (@pxref{Package Modules}).
eeaf4427 1258
461572cc
LC
1259@cindex propagated inputs
1260Sometimes packages have @dfn{propagated inputs}: these are dependencies
21461f27
LC
1261that automatically get installed along with the required package
1262(@pxref{package-propagated-inputs, @code{propagated-inputs} in
1263@code{package} objects}, for information about propagated inputs in
1264package definitions).
461572cc 1265
21461f27 1266@anchor{package-cmd-propagated-inputs}
461572cc
LC
1267An example is the GNU MPC library: its C header files refer to those of
1268the GNU MPFR library, which in turn refer to those of the GMP library.
1269Thus, when installing MPC, the MPFR and GMP libraries also get installed
1270in the profile; removing MPC also removes MPFR and GMP---unless they had
1271also been explicitly installed independently.
1272
ba7ea5ce 1273Besides, packages sometimes rely on the definition of environment
5924080d 1274variables for their search paths (see explanation of
ba7ea5ce 1275@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
1276environment variable definitions are reported here.
1277
ef010c0f 1278@c XXX: keep me up-to-date
5924080d 1279Finally, when installing a GNU package, the tool reports the
ef010c0f
LC
1280availability of a newer upstream version. In the future, it may provide
1281the option of installing directly from the upstream version, even if
1282that version is not yet in the distribution.
1283
5d4b411f
LC
1284@item --install-from-expression=@var{exp}
1285@itemx -e @var{exp}
1286Install the package @var{exp} evaluates to.
1287
1288@var{exp} must be a Scheme expression that evaluates to a
1289@code{<package>} object. This option is notably useful to disambiguate
1290between same-named variants of a package, with expressions such as
1291@code{(@@ (gnu packages base) guile-final)}.
1292
1293Note that this option installs the first output of the specified
1294package, which may be insufficient when needing a specific output of a
1295multiple-output package.
1296
0d279400
DT
1297@item --install-from-file=@var{file}
1298@itemx -f @var{file}
1299Install the package that the code within @var{file} evaluates to.
1300
1301As an example, @var{file} might contain a definition like this
1302(@pxref{Defining Packages}):
1303
1304@example
1305@verbatiminclude package-hello.scm
1306@end example
1307
1308Developers may find it useful to include such a @file{package.scm} file
1309in the root of their project's source tree that can be used to test
1310development snapshots and create reproducible development environments
1311(@pxref{Invoking guix environment}).
1312
6447738c
MW
1313@item --remove=@var{package} @dots{}
1314@itemx -r @var{package} @dots{}
1315Remove the specified @var{package}s.
eeaf4427 1316
6447738c 1317As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
1318and/or output name in addition to the package name. For instance,
1319@code{-r glibc:debug} would remove the @code{debug} output of
1320@code{glibc}.
1321
6447738c
MW
1322@item --upgrade[=@var{regexp} @dots{}]
1323@itemx -u [@var{regexp} @dots{}]
1324Upgrade all the installed packages. If one or more @var{regexp}s are
1325specified, upgrade only installed packages whose name matches a
d5f01e48 1326@var{regexp}. Also see the @code{--do-not-upgrade} option below.
eeaf4427 1327
f651b477
LC
1328Note that this upgrades package to the latest version of packages found
1329in the distribution currently installed. To update your distribution,
1330you should regularly run @command{guix pull} (@pxref{Invoking guix
1331pull}).
1332
d5f01e48
MW
1333@item --do-not-upgrade[=@var{regexp} @dots{}]
1334When used together with the @code{--upgrade} option, do @emph{not}
1335upgrade any packages whose name matches a @var{regexp}. For example, to
1336upgrade all packages in the current profile except those containing the
1337substring ``emacs'':
1338
1339@example
1340$ guix package --upgrade . --do-not-upgrade emacs
1341@end example
1342
99bd74d5 1343@item @anchor{profile-manifest}--manifest=@var{file}
1b676447 1344@itemx -m @var{file}
99bd74d5
LC
1345@cindex profile declaration
1346@cindex profile manifest
1347Create a new generation of the profile from the manifest object
1b676447
DT
1348returned by the Scheme code in @var{file}.
1349
99bd74d5
LC
1350This allows you to @emph{declare} the profile's contents rather than
1351constructing it through a sequence of @code{--install} and similar
1352commands. The advantage is that @var{file} can be put under version
1353control, copied to different machines to reproduce the same profile, and
1354so on.
1355
1356@c FIXME: Add reference to (guix profile) documentation when available.
1357@var{file} must return a @dfn{manifest} object, which is roughly a list
1358of packages:
1b676447 1359
99bd74d5 1360@findex packages->manifest
1b676447 1361@example
99bd74d5 1362(use-package-modules guile emacs)
1b676447
DT
1363
1364(packages->manifest
99bd74d5
LC
1365 (list emacs
1366 guile-2.0
1b676447 1367 ;; Use a specific package output.
99bd74d5 1368 (list guile-2.0 "debug")))
1b676447
DT
1369@end example
1370
24e262f0
LC
1371@item --roll-back
1372Roll back to the previous @dfn{generation} of the profile---i.e., undo
1373the last transaction.
1374
1375When combined with options such as @code{--install}, roll back occurs
1376before any other actions.
1377
d9307267 1378When rolling back from the first generation that actually contains
4b2bc804
NK
1379installed packages, the profile is made to point to the @dfn{zeroth
1380generation}, which contains no files apart from its own meta-data.
d9307267 1381
82fe08ed
LC
1382Installing, removing, or upgrading packages from a generation that has
1383been rolled back to overwrites previous future generations. Thus, the
1384history of a profile's generations is always linear.
1385
b3bb82f1
AK
1386@item --switch-generation=@var{pattern}
1387@itemx -S @var{pattern}
1388Switch to a particular generation defined by @var{pattern}.
1389
1390@var{pattern} may be either a generation number or a number prefixed
1391with ``+'' or ``-''. The latter means: move forward/backward by a
1392specified number of generations. For example, if you want to return to
1393the latest generation after @code{--roll-back}, use
1394@code{--switch-generation=+1}.
1395
1396The difference between @code{--roll-back} and
1397@code{--switch-generation=-1} is that @code{--switch-generation} will
1398not make a zeroth generation, so if a specified generation does not
1399exist, the current generation will not be changed.
1400
dbc31ab2 1401@item --search-paths[=@var{kind}]
5924080d
LC
1402@cindex search paths
1403Report environment variable definitions, in Bash syntax, that may be
1404needed in order to use the set of installed packages. These environment
1405variables are used to specify @dfn{search paths} for files used by some
1406of the installed packages.
1407
1408For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1409environment variables to be defined so it can look for headers and
1410libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1411Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1412library are installed in the profile, then @code{--search-paths} will
1413suggest setting these variables to @code{@var{profile}/include} and
1414@code{@var{profile}/lib}, respectively.
1415
dbc31ab2
LC
1416The typical use case is to define these environment variables in the
1417shell:
1418
1419@example
1420$ eval `guix package --search-paths`
1421@end example
1422
1423@var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1424meaning that the returned environment variable definitions will either
1425be exact settings, or prefixes or suffixes of the current value of these
1426variables. When omitted, @var{kind} defaults to @code{exact}.
1427
fc2d2339
LC
1428This option can also be used to compute the @emph{combined} search paths
1429of several profiles. Consider this example:
1430
1431@example
1432$ guix package -p foo -i guile
1433$ guix package -p bar -i guile-json
1434$ guix package -p foo -p bar --search-paths
1435@end example
1436
1437The last command above reports about the @code{GUILE_LOAD_PATH}
1438variable, even though, taken individually, neither @file{foo} nor
1439@file{bar} would lead to that recommendation.
1440
1441
eeaf4427
LC
1442@item --profile=@var{profile}
1443@itemx -p @var{profile}
1444Use @var{profile} instead of the user's default profile.
1445
70915c1a
LC
1446@item --verbose
1447Produce verbose output. In particular, emit the environment's build log
1448on the standard error port.
1449
eeaf4427
LC
1450@item --bootstrap
1451Use the bootstrap Guile to build the profile. This option is only
1452useful to distribution developers.
1453
1454@end table
1455
e49951eb 1456In addition to these actions @command{guix package} supports the
733b4130
LC
1457following options to query the current state of a profile, or the
1458availability of packages:
eeaf4427 1459
733b4130
LC
1460@table @option
1461
acc08466
NK
1462@item --search=@var{regexp}
1463@itemx -s @var{regexp}
b110869d 1464@cindex searching for packages
5763ad92 1465List the available packages whose name, synopsis, or description matches
299112d3
LC
1466@var{regexp}. Print all the meta-data of matching packages in
1467@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1468GNU recutils manual}).
acc08466 1469
299112d3
LC
1470This allows specific fields to be extracted using the @command{recsel}
1471command, for instance:
1472
1473@example
e49951eb 1474$ guix package -s malloc | recsel -p name,version
299112d3
LC
1475name: glibc
1476version: 2.17
1477
1478name: libgc
1479version: 7.2alpha6
1480@end example
acc08466 1481
a12d92f5
LC
1482Similarly, to show the name of all the packages available under the
1483terms of the GNU@tie{}LGPL version 3:
1484
1485@example
1486$ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1487name: elfutils
1488
1489name: gmp
1490@dots{}
1491@end example
1492
db5a9444
LC
1493It is also possible to refine search results using several @code{-s}
1494flags. For example, the following command returns a list of board
1495games:
1496
1497@example
1498$ guix package -s '\<board\>' -s game | recsel -p name
1499name: gnubg
1500@dots{}
1501@end example
1502
1503If we were to omit @code{-s game}, we would also get software packages
1504that deal with printed circuit boards; removing the angle brackets
1505around @code{board} would further add packages that have to do with
1506keyboards.
1507
b110869d
LC
1508And now for a more elaborate example. The following command searches
1509for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1510libraries, and prints the name and synopsis of the matching packages:
1511
1512@example
1513$ guix package -s crypto -s library | \
1514 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1515@end example
1516
1517@noindent
1518@xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1519information on @dfn{selection expressions} for @code{recsel -e}.
1520
2aa6efb0
CR
1521@item --show=@var{package}
1522Show details about @var{package}, taken from the list of available packages, in
1523@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1524recutils manual}).
1525
1526@example
1527$ guix package --show=python | recsel -p name,version
1528name: python
1529version: 2.7.6
1530
1531name: python
1532version: 3.3.5
1533@end example
1534
1535You may also specify the full name of a package to only get details about a
1536specific version of it:
1537@example
1538$ guix package --show=python-3.3.5 | recsel -p name,version
1539name: python
1540version: 3.3.5
1541@end example
1542
1543
1544
733b4130
LC
1545@item --list-installed[=@var{regexp}]
1546@itemx -I [@var{regexp}]
bd9bde1c
LC
1547List the currently installed packages in the specified profile, with the
1548most recently installed packages shown last. When @var{regexp} is
1549specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
1550
1551For each installed package, print the following items, separated by
1552tabs: the package name, its version string, the part of the package that
1553is installed (for instance, @code{out} for the default output,
1554@code{include} for its headers, etc.), and the path of this package in
1555the store.
1556
64fc89b6
LC
1557@item --list-available[=@var{regexp}]
1558@itemx -A [@var{regexp}]
5763ad92 1559List packages currently available in the distribution for this system
a1ba8475
LC
1560(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1561installed packages whose name matches @var{regexp}.
64fc89b6
LC
1562
1563For each package, print the following items separated by tabs: its name,
6e721c4d
LC
1564its version string, the parts of the package (@pxref{Packages with
1565Multiple Outputs}), and the source location of its definition.
64fc89b6 1566
f566d765
LC
1567@item --list-generations[=@var{pattern}]
1568@itemx -l [@var{pattern}]
1569Return a list of generations along with their creation dates; for each
1570generation, show the installed packages, with the most recently
4b2bc804
NK
1571installed packages shown last. Note that the zeroth generation is never
1572shown.
f566d765
LC
1573
1574For each installed package, print the following items, separated by
1575tabs: the name of a package, its version string, the part of the package
1576that is installed (@pxref{Packages with Multiple Outputs}), and the
1577location of this package in the store.
1578
1579When @var{pattern} is used, the command returns only matching
1580generations. Valid patterns include:
1581
1582@itemize
1583@item @emph{Integers and comma-separated integers}. Both patterns denote
1584generation numbers. For instance, @code{--list-generations=1} returns
1585the first one.
1586
1587And @code{--list-generations=1,8,2} outputs three generations in the
1588specified order. Neither spaces nor trailing commas are allowed.
1589
1590@item @emph{Ranges}. @code{--list-generations=2..9} prints the
1591specified generations and everything in between. Note that the start of
1592a range must be lesser than its end.
1593
1594It is also possible to omit the endpoint. For example,
1595@code{--list-generations=2..}, returns all generations starting from the
1596second one.
1597
1598@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1599or months by passing an integer along with the first letter of the
d7ddb257
LC
1600duration. For example, @code{--list-generations=20d} lists generations
1601that are up to 20 days old.
f566d765
LC
1602@end itemize
1603
b7884ca3
NK
1604@item --delete-generations[=@var{pattern}]
1605@itemx -d [@var{pattern}]
d7ddb257
LC
1606When @var{pattern} is omitted, delete all generations except the current
1607one.
b7884ca3
NK
1608
1609This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
1610When @var{pattern} is specified, delete the matching generations. When
1611@var{pattern} specifies a duration, generations @emph{older} than the
1612specified duration match. For instance, @code{--delete-generations=1m}
1613deletes generations that are more than one month old.
1614
391bdd8f
LC
1615If the current generation matches, it is @emph{not} deleted. Also, the
1616zeroth generation is never deleted.
b7884ca3 1617
1bb9900a
LC
1618Note that deleting generations prevents roll-back to them.
1619Consequently, this command must be used with care.
1620
733b4130 1621@end table
eeaf4427 1622
70ee5642
LC
1623Finally, since @command{guix package} may actually start build
1624processes, it supports all the common build options that @command{guix
1625build} supports (@pxref{Invoking guix build, common build options}).
1626
c4202d60
LC
1627@node Substitutes
1628@section Substitutes
1629
1630@cindex substitutes
1631@cindex pre-built binaries
1632Guix supports transparent source/binary deployment, which means that it
1633can either build things locally, or download pre-built items from a
1634server. We call these pre-built items @dfn{substitutes}---they are
1635substitutes for local build results. In many cases, downloading a
1636substitute is much faster than building things locally.
1637
1638Substitutes can be anything resulting from a derivation build
1639(@pxref{Derivations}). Of course, in the common case, they are
1640pre-built package binaries, but source tarballs, for instance, which
1641also result from derivation builds, can be available as substitutes.
1642
1643The @code{hydra.gnu.org} server is a front-end to a build farm that
1644builds packages from the GNU distribution continuously for some
32950fc8
AK
1645architectures, and makes them available as substitutes (@pxref{Emacs
1646Hydra}, for information on how to query the continuous integration
1647server). This is the
f8a8e0fe
LC
1648default source of substitutes; it can be overridden by passing the
1649@option{--substitute-urls} option either to @command{guix-daemon}
1650(@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1651or to client tools such as @command{guix package}
1652(@pxref{client-substitute-urls,, client @option{--substitute-urls}
1653option}).
c4202d60
LC
1654
1655@cindex security
1656@cindex digital signatures
1657To allow Guix to download substitutes from @code{hydra.gnu.org}, you
1658must add its public key to the access control list (ACL) of archive
1659imports, using the @command{guix archive} command (@pxref{Invoking guix
1660archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1661be compromised and to serve genuine substitutes.
1662
1663This public key is installed along with Guix, in
1664@code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1665the installation prefix of Guix. If you installed Guix from source,
1666make sure you checked the GPG signature of
1667@file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1668Then, you can run something like this:
1669
1670@example
1671# guix archive --authorize < hydra.gnu.org.pub
1672@end example
1673
1674Once this is in place, the output of a command like @code{guix build}
1675should change from something like:
1676
1677@example
1678$ guix build emacs --dry-run
1679The following derivations would be built:
1680 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1681 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1682 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1683 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1684@dots{}
1685@end example
1686
1687@noindent
1688to something like:
1689
1690@example
1691$ guix build emacs --dry-run
1692The following files would be downloaded:
1693 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1694 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1695 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1696 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1697@dots{}
1698@end example
1699
1700@noindent
1701This indicates that substitutes from @code{hydra.gnu.org} are usable and
1702will be downloaded, when possible, for future builds.
1703
1704Guix ignores substitutes that are not signed, or that are not signed by
ef27aa9c 1705one of the keys listed in the ACL. It also detects and raises an error
c4202d60
LC
1706when attempting to use a substitute that has been tampered with.
1707
e0c941fe
LC
1708@vindex http_proxy
1709Substitutes are downloaded over HTTP. The @code{http_proxy} environment
1710variable can be set in the environment of @command{guix-daemon} and is
1711honored for downloads of substitutes. Note that the value of
1712@code{http_proxy} in the environment where @command{guix build},
1713@command{guix package}, and other client commands are run has
1714@emph{absolutely no effect}.
1715
c4202d60
LC
1716The substitute mechanism can be disabled globally by running
1717@code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1718guix-daemon}). It can also be disabled temporarily by passing the
1719@code{--no-substitutes} option to @command{guix package}, @command{guix
1720build}, and other command-line tools.
1721
1722
1723Today, each individual's control over their own computing is at the
1724mercy of institutions, corporations, and groups with enough power and
1725determination to subvert the computing infrastructure and exploit its
1726weaknesses. While using @code{hydra.gnu.org} substitutes can be
1727convenient, we encourage users to also build on their own, or even run
1728their own build farm, such that @code{hydra.gnu.org} is less of an
8ce229fc
LC
1729interesting target. One way to help is by publishing the software you
1730build using @command{guix publish} so that others have one more choice
1731of server to download substitutes from (@pxref{Invoking guix publish}).
c4202d60
LC
1732
1733Guix has the foundations to maximize build reproducibility
1734(@pxref{Features}). In most cases, independent builds of a given
1735package or derivation should yield bit-identical results. Thus, through
1736a diverse set of independent package builds, we can strengthen the
d23c20f1
LC
1737integrity of our systems. The @command{guix challenge} command aims to
1738help users assess substitute servers, and to assist developers in
1739finding out about non-deterministic package builds (@pxref{Invoking guix
a8d65643
LC
1740challenge}). Similarly, the @option{--check} option of @command{guix
1741build} allows users to check whether previously-installed substitutes
1742are genuine by rebuilding them locally (@pxref{build-check,
1743@command{guix build --check}}).
c4202d60
LC
1744
1745In the future, we want Guix to have support to publish and retrieve
1746binaries to/from other users, in a peer-to-peer fashion. If you would
1747like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1748
1749
6e721c4d
LC
1750@node Packages with Multiple Outputs
1751@section Packages with Multiple Outputs
1752
1753@cindex multiple-output packages
1754@cindex package outputs
1755
1756Often, packages defined in Guix have a single @dfn{output}---i.e., the
1757source package leads exactly one directory in the store. When running
1758@command{guix package -i glibc}, one installs the default output of the
1759GNU libc package; the default output is called @code{out}, but its name
1760can be omitted as shown in this command. In this particular case, the
1761default output of @code{glibc} contains all the C header files, shared
1762libraries, static libraries, Info documentation, and other supporting
1763files.
1764
1765Sometimes it is more appropriate to separate the various types of files
1766produced from a single source package into separate outputs. For
1767instance, the GLib C library (used by GTK+ and related packages)
1768installs more than 20 MiB of reference documentation as HTML pages.
1769To save space for users who do not need it, the documentation goes to a
1770separate output, called @code{doc}. To install the main GLib output,
1771which contains everything but the documentation, one would run:
1772
1773@example
1774guix package -i glib
1775@end example
1776
1777The command to install its documentation is:
1778
1779@example
1780guix package -i glib:doc
1781@end example
1782
1783Some packages install programs with different ``dependency footprints''.
1784For instance, the WordNet package install both command-line tools and
1785graphical user interfaces (GUIs). The former depend solely on the C
1786library, whereas the latter depend on Tcl/Tk and the underlying X
1787libraries. In this case, we leave the command-line tools in the default
1788output, whereas the GUIs are in a separate output. This allows users
fcc58db6
LC
1789who do not need the GUIs to save space. The @command{guix size} command
1790can help find out about such situations (@pxref{Invoking guix size}).
88856916 1791@command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
6e721c4d
LC
1792
1793There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
1794Other conventional output names include @code{lib} for libraries and
1795possibly header files, @code{bin} for stand-alone programs, and
1796@code{debug} for debugging information (@pxref{Installing Debugging
1797Files}). The outputs of a packages are listed in the third column of
1798the output of @command{guix package --list-available} (@pxref{Invoking
1799guix package}).
6e721c4d 1800
eeaf4427 1801
e49951eb
MW
1802@node Invoking guix gc
1803@section Invoking @command{guix gc}
fe8ff028
LC
1804
1805@cindex garbage collector
1806Packages that are installed but not used may be @dfn{garbage-collected}.
e49951eb 1807The @command{guix gc} command allows users to explicitly run the garbage
c22eb992
LC
1808collector to reclaim space from the @file{/gnu/store} directory. It is
1809the @emph{only} way to remove files from @file{/gnu/store}---removing
1810files or directories manually may break it beyond repair!
fe8ff028
LC
1811
1812The garbage collector has a set of known @dfn{roots}: any file under
834129e0 1813@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
1814cannot be deleted; any other file is considered @dfn{dead} and may be
1815deleted. The set of garbage collector roots includes default user
e49951eb
MW
1816profiles, and may be augmented with @command{guix build --root}, for
1817example (@pxref{Invoking guix build}).
fe8ff028 1818
1bb9900a
LC
1819Prior to running @code{guix gc --collect-garbage} to make space, it is
1820often useful to remove old generations from user profiles; that way, old
1821package builds referenced by those generations can be reclaimed. This
1822is achieved by running @code{guix package --delete-generations}
1823(@pxref{Invoking guix package}).
1824
e49951eb 1825The @command{guix gc} command has three modes of operation: it can be
fe8ff028 1826used to garbage-collect any dead files (the default), to delete specific
7770aafc
LC
1827files (the @code{--delete} option), to print garbage-collector
1828information, or for more advanced queries. The garbage collection
1829options are as follows:
fe8ff028
LC
1830
1831@table @code
1832@item --collect-garbage[=@var{min}]
1833@itemx -C [@var{min}]
834129e0 1834Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
1835sub-directories. This is the default operation when no option is
1836specified.
1837
1838When @var{min} is given, stop once @var{min} bytes have been collected.
1839@var{min} may be a number of bytes, or it may include a unit as a
4a44d7bb
LC
1840suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
1841(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
fe8ff028
LC
1842
1843When @var{min} is omitted, collect all the garbage.
1844
1845@item --delete
1846@itemx -d
1847Attempt to delete all the store files and directories specified as
1848arguments. This fails if some of the files are not in the store, or if
1849they are still live.
1850
30d9aa54
LC
1851@item --list-failures
1852List store items corresponding to cached build failures.
1853
1854This prints nothing unless the daemon was started with
1855@option{--cache-failures} (@pxref{Invoking guix-daemon,
1856@option{--cache-failures}}).
1857
1858@item --clear-failures
1859Remove the specified store items from the failed-build cache.
1860
1861Again, this option only makes sense when the daemon is started with
1862@option{--cache-failures}. Otherwise, it does nothing.
1863
fe8ff028
LC
1864@item --list-dead
1865Show the list of dead files and directories still present in the
1866store---i.e., files and directories no longer reachable from any root.
1867
1868@item --list-live
1869Show the list of live store files and directories.
ba8b732d
LC
1870
1871@end table
1872
1873In addition, the references among existing store files can be queried:
1874
1875@table @code
1876
1877@item --references
1878@itemx --referrers
1879List the references (respectively, the referrers) of store files given
1880as arguments.
1881
8e59fdd5
LC
1882@item --requisites
1883@itemx -R
fcc58db6 1884@cindex closure
8e59fdd5
LC
1885List the requisites of the store files passed as arguments. Requisites
1886include the store files themselves, their references, and the references
1887of these, recursively. In other words, the returned list is the
1888@dfn{transitive closure} of the store files.
1889
fcc58db6 1890@xref{Invoking guix size}, for a tool to profile the size of an
88856916
LC
1891element's closure. @xref{Invoking guix graph}, for a tool to visualize
1892the graph of references.
fcc58db6 1893
fe8ff028
LC
1894@end table
1895
7770aafc
LC
1896Lastly, the following options allow you to check the integrity of the
1897store and to control disk usage.
1898
1899@table @option
1900
1901@item --verify[=@var{options}]
1902@cindex integrity, of the store
1903@cindex integrity checking
1904Verify the integrity of the store.
1905
1906By default, make sure that all the store items marked as valid in the
1907daemon's database actually exist in @file{/gnu/store}.
1908
1909When provided, @var{options} must a comma-separated list containing one
1910or more of @code{contents} and @code{repair}.
1911
1912When passing @option{--verify=contents}, the daemon will compute the
1913content hash of each store item and compare it against its hash in the
1914database. Hash mismatches are reported as data corruptions. Because it
1915traverses @emph{all the files in the store}, this command can take a
1916long time, especially on systems with a slow disk drive.
1917
1918@cindex repairing the store
1919Using @option{--verify=repair} or @option{--verify=contents,repair}
1920causes the daemon to try to repair corrupt store items by fetching
1921substitutes for them (@pxref{Substitutes}). Because repairing is not
1922atomic, and thus potentially dangerous, it is available only to the
1923system administrator.
1924
1925@item --optimize
1926@cindex deduplication
1927Optimize the store by hard-linking identical files---this is
1928@dfn{deduplication}.
1929
1930The daemon performs deduplication after each successful build or archive
1931import, unless it was started with @code{--disable-deduplication}
1932(@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
1933this option is primarily useful when the daemon was running with
1934@code{--disable-deduplication}.
1935
1936@end table
eeaf4427 1937
f651b477
LC
1938@node Invoking guix pull
1939@section Invoking @command{guix pull}
1940
1941Packages are installed or upgraded to the latest version available in
1942the distribution currently available on your local machine. To update
1943that distribution, along with the Guix tools, you must run @command{guix
1944pull}: the command downloads the latest Guix source code and package
1945descriptions, and deploys it.
1946
1947On completion, @command{guix package} will use packages and package
1948versions from this just-retrieved copy of Guix. Not only that, but all
1949the Guix commands and Scheme modules will also be taken from that latest
1950version. New @command{guix} sub-commands added by the update also
ef54b61d
AV
1951become available@footnote{Under the hood, @command{guix pull} updates
1952the @file{~/.config/guix/latest} symbolic link to point to the latest
1953Guix, and the @command{guix} command loads code from there.}.
f651b477
LC
1954
1955The @command{guix pull} command is usually invoked with no arguments,
1956but it supports the following options:
1957
1958@table @code
1959@item --verbose
1960Produce verbose output, writing build logs to the standard error output.
1961
ab5d72ad
LC
1962@item --url=@var{url}
1963Download the source tarball of Guix from @var{url}.
1964
1965By default, the tarball is taken from its canonical address at
1966@code{gnu.org}, for the stable branch of Guix.
1967
f651b477
LC
1968@item --bootstrap
1969Use the bootstrap Guile to build the latest Guix. This option is only
1970useful to Guix developers.
1971@end table
1972
760c60d6
LC
1973
1974@node Invoking guix archive
1975@section Invoking @command{guix archive}
1976
1977The @command{guix archive} command allows users to @dfn{export} files
1978from the store into a single archive, and to later @dfn{import} them.
1979In particular, it allows store files to be transferred from one machine
1980to another machine's store. For example, to transfer the @code{emacs}
1981package to a machine connected over SSH, one would run:
1982
1983@example
56607088 1984guix archive --export -r emacs | ssh the-machine guix archive --import
760c60d6
LC
1985@end example
1986
87236aed 1987@noindent
56607088
LC
1988Similarly, a complete user profile may be transferred from one machine
1989to another like this:
1990
1991@example
1992guix archive --export -r $(readlink -f ~/.guix-profile) | \
1993 ssh the-machine guix-archive --import
1994@end example
1995
1996@noindent
1997However, note that, in both examples, all of @code{emacs} and the
1998profile as well as all of their dependencies are transferred (due to
1999@code{-r}), regardless of what is already available in the target
2000machine's store. The @code{--missing} option can help figure out which
2001items are missing from the target's store.
87236aed 2002
760c60d6 2003Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
0dbd88db
LC
2004comparable in spirit to `tar', but with a few noteworthy differences
2005that make it more appropriate for our purposes. First, rather than
2006recording all Unix meta-data for each file, the Nar format only mentions
2007the file type (regular, directory, or symbolic link); Unix permissions
2008and owner/group are dismissed. Second, the order in which directory
2009entries are stored always follows the order of file names according to
2010the C locale collation order. This makes archive production fully
2011deterministic.
2012
2013When exporting, the daemon digitally signs the contents of the archive,
2014and that digital signature is appended. When importing, the daemon
2015verifies the signature and rejects the import in case of an invalid
2016signature or if the signing key is not authorized.
760c60d6
LC
2017@c FIXME: Add xref to daemon doc about signatures.
2018
2019The main options are:
2020
2021@table @code
2022@item --export
2023Export the specified store files or packages (see below.) Write the
2024resulting archive to the standard output.
2025
56607088
LC
2026Dependencies are @emph{not} included in the output, unless
2027@code{--recursive} is passed.
2028
2029@item -r
2030@itemx --recursive
2031When combined with @code{--export}, this instructs @command{guix
2032archive} to include dependencies of the given items in the archive.
2033Thus, the resulting archive is self-contained: it contains the closure
2034of the exported store items.
2035
760c60d6
LC
2036@item --import
2037Read an archive from the standard input, and import the files listed
2038therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
2039signature, or if it is signed by a public key not among the authorized
2040keys (see @code{--authorize} below.)
554f26ec 2041
87236aed
LC
2042@item --missing
2043Read a list of store file names from the standard input, one per line,
2044and write on the standard output the subset of these files missing from
2045the store.
2046
554f26ec 2047@item --generate-key[=@var{parameters}]
f82cc5fd 2048@cindex signing, archives
554f26ec
LC
2049Generate a new key pair for the daemons. This is a prerequisite before
2050archives can be exported with @code{--export}. Note that this operation
2051usually takes time, because it needs to gather enough entropy to
2052generate the key pair.
2053
2054The generated key pair is typically stored under @file{/etc/guix}, in
2055@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
867d8473
LC
2056key, which must be kept secret.) When @var{parameters} is omitted,
2057an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2058versions before 1.6.0, it is a 4096-bit RSA key.
2059Alternately, @var{parameters} can specify
554f26ec
LC
2060@code{genkey} parameters suitable for Libgcrypt (@pxref{General
2061public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2062Libgcrypt Reference Manual}).
f82cc5fd
LC
2063
2064@item --authorize
2065@cindex authorizing, archives
2066Authorize imports signed by the public key passed on standard input.
2067The public key must be in ``s-expression advanced format''---i.e., the
2068same format as the @file{signing-key.pub} file.
2069
2070The list of authorized keys is kept in the human-editable file
2071@file{/etc/guix/acl}. The file contains
2072@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2073s-expressions''} and is structured as an access-control list in the
2074@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2075(SPKI)}.
c6f8e9dd
LC
2076
2077@item --extract=@var{directory}
2078@itemx -x @var{directory}
2079Read a single-item archive as served by substitute servers
2080(@pxref{Substitutes}) and extract it to @var{directory}. This is a
2081low-level operation needed in only very narrow use cases; see below.
2082
2083For example, the following command extracts the substitute for Emacs
2084served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2085
2086@example
2087$ wget -O - \
2088 http://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
2089 | bunzip2 | guix archive -x /tmp/emacs
2090@end example
2091
2092Single-item archives are different from multiple-item archives produced
2093by @command{guix archive --export}; they contain a single store item,
2094and they do @emph{not} embed a signature. Thus this operation does
2095@emph{no} signature verification and its output should be considered
2096unsafe.
2097
2098The primary purpose of this operation is to facilitate inspection of
2099archive contents coming from possibly untrusted substitute servers.
2100
760c60d6
LC
2101@end table
2102
2103To export store files as an archive to the standard output, run:
2104
2105@example
2106guix archive --export @var{options} @var{specifications}...
2107@end example
2108
2109@var{specifications} may be either store file names or package
2110specifications, as for @command{guix package} (@pxref{Invoking guix
2111package}). For instance, the following command creates an archive
2112containing the @code{gui} output of the @code{git} package and the main
2113output of @code{emacs}:
2114
2115@example
834129e0 2116guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
760c60d6
LC
2117@end example
2118
2119If the specified packages are not built yet, @command{guix archive}
2120automatically builds them. The build process may be controlled with the
2121same options that can be passed to the @command{guix build} command
70ee5642 2122(@pxref{Invoking guix build, common build options}).
760c60d6 2123
c554de89
AK
2124@c *********************************************************************
2125@include emacs.texi
760c60d6 2126
568717fd
LC
2127@c *********************************************************************
2128@node Programming Interface
2129@chapter Programming Interface
2130
3dc1970d
LC
2131GNU Guix provides several Scheme programming interfaces (APIs) to
2132define, build, and query packages. The first interface allows users to
2133write high-level package definitions. These definitions refer to
2134familiar packaging concepts, such as the name and version of a package,
2135its build system, and its dependencies. These definitions can then be
2136turned into concrete build actions.
2137
ba55b1cb 2138Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 2139standard setup, the daemon has write access to the store---the
834129e0 2140@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
2141setup also has the daemon perform builds in chroots, under a specific
2142build users, to minimize interference with the rest of the system.
2143
2144@cindex derivation
2145Lower-level APIs are available to interact with the daemon and the
2146store. To instruct the daemon to perform a build action, users actually
2147provide it with a @dfn{derivation}. A derivation is a low-level
2148representation of the build actions to be taken, and the environment in
2149which they should occur---derivations are to package definitions what
49ad317a
LC
2150assembly is to C programs. The term ``derivation'' comes from the fact
2151that build results @emph{derive} from them.
3dc1970d
LC
2152
2153This chapter describes all these APIs in turn, starting from high-level
2154package definitions.
2155
568717fd 2156@menu
b860f382 2157* Defining Packages:: Defining new packages.
7458bd0a 2158* Build Systems:: Specifying how packages are built.
b860f382
LC
2159* The Store:: Manipulating the package store.
2160* Derivations:: Low-level interface to package derivations.
2161* The Store Monad:: Purely functional interface to the store.
21b679f6 2162* G-Expressions:: Manipulating build expressions.
568717fd
LC
2163@end menu
2164
2165@node Defining Packages
2166@section Defining Packages
2167
3dc1970d
LC
2168The high-level interface to package definitions is implemented in the
2169@code{(guix packages)} and @code{(guix build-system)} modules. As an
2170example, the package definition, or @dfn{recipe}, for the GNU Hello
2171package looks like this:
2172
2173@example
e7f34eb0
LC
2174(define-module (gnu packages hello)
2175 #:use-module (guix packages)
2176 #:use-module (guix download)
2177 #:use-module (guix build-system gnu)
a6dcdcac
SB
2178 #:use-module (guix licenses)
2179 #:use-module (gnu packages gawk))
b22a12fd 2180
79f5dd59 2181(define-public hello
3dc1970d
LC
2182 (package
2183 (name "hello")
17d8e33f 2184 (version "2.10")
3dc1970d 2185 (source (origin
17d8e33f
ML
2186 (method url-fetch)
2187 (uri (string-append "mirror://gnu/hello/hello-" version
2188 ".tar.gz"))
2189 (sha256
2190 (base32
2191 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
3dc1970d 2192 (build-system gnu-build-system)
7458bd0a 2193 (arguments `(#:configure-flags '("--enable-silent-rules")))
3dc1970d 2194 (inputs `(("gawk" ,gawk)))
7458bd0a
LC
2195 (synopsis "Hello, GNU world: An example GNU package")
2196 (description "Guess what GNU Hello prints!")
3dc1970d 2197 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 2198 (license gpl3+)))
3dc1970d
LC
2199@end example
2200
2201@noindent
2202Without being a Scheme expert, the reader may have guessed the meaning
e7f34eb0 2203of the various fields here. This expression binds variable @code{hello}
3dc1970d
LC
2204to a @code{<package>} object, which is essentially a record
2205(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2206This package object can be inspected using procedures found in the
2207@code{(guix packages)} module; for instance, @code{(package-name hello)}
2208returns---surprise!---@code{"hello"}.
2209
2f7d2d91
LC
2210With luck, you may be able to import part or all of the definition of
2211the package you are interested in from another repository, using the
2212@code{guix import} command (@pxref{Invoking guix import}).
2213
e7f34eb0
LC
2214In the example above, @var{hello} is defined into a module of its own,
2215@code{(gnu packages hello)}. Technically, this is not strictly
2216necessary, but it is convenient to do so: all the packages defined in
2217modules under @code{(gnu packages @dots{})} are automatically known to
2218the command-line tools (@pxref{Package Modules}).
2219
3dc1970d
LC
2220There are a few points worth noting in the above package definition:
2221
2222@itemize
2223@item
a2bf4907
LC
2224The @code{source} field of the package is an @code{<origin>} object
2225(@pxref{origin Reference}, for the complete reference).
3dc1970d
LC
2226Here, the @code{url-fetch} method from @code{(guix download)} is used,
2227meaning that the source is a file to be downloaded over FTP or HTTP.
2228
2229The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2230the GNU mirrors defined in @code{(guix download)}.
2231
2232The @code{sha256} field specifies the expected SHA256 hash of the file
2233being downloaded. It is mandatory, and allows Guix to check the
2234integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 2235base32 representation of the hash. You can obtain this information with
210cc920
LC
2236@code{guix download} (@pxref{Invoking guix download}) and @code{guix
2237hash} (@pxref{Invoking guix hash}).
3dc1970d 2238
f9cc8971
LC
2239@cindex patches
2240When needed, the @code{origin} form can also have a @code{patches} field
2241listing patches to be applied, and a @code{snippet} field giving a
2242Scheme expression to modify the source code.
2243
3dc1970d
LC
2244@item
2245@cindex GNU Build System
7458bd0a
LC
2246The @code{build-system} field specifies the procedure to build the
2247package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2248represents the familiar GNU Build System, where packages may be
2249configured, built, and installed with the usual @code{./configure &&
2250make && make check && make install} command sequence.
2251
2252@item
2253The @code{arguments} field specifies options for the build system
2254(@pxref{Build Systems}). Here it is interpreted by
2255@var{gnu-build-system} as a request run @file{configure} with the
2256@code{--enable-silent-rules} flag.
3dc1970d
LC
2257
2258@item
2259The @code{inputs} field specifies inputs to the build process---i.e.,
2260build-time or run-time dependencies of the package. Here, we define an
2261input called @code{"gawk"} whose value is that of the @var{gawk}
2262variable; @var{gawk} is itself bound to a @code{<package>} object.
2263
2264Note that GCC, Coreutils, Bash, and other essential tools do not need to
2265be specified as inputs here. Instead, @var{gnu-build-system} takes care
7458bd0a 2266of ensuring that they are present (@pxref{Build Systems}).
3dc1970d
LC
2267
2268However, any other dependencies need to be specified in the
2269@code{inputs} field. Any dependency not specified here will simply be
2270unavailable to the build process, possibly leading to a build failure.
2271@end itemize
2272
87eafdbd
TUBK
2273@xref{package Reference}, for a full description of possible fields.
2274
2f7d2d91 2275Once a package definition is in place, the
e49951eb 2276package may actually be built using the @code{guix build} command-line
39bee8a2
LC
2277tool (@pxref{Invoking guix build}). You can easily jump back to the
2278package definition using the @command{guix edit} command
2279(@pxref{Invoking guix edit}).
2280@xref{Packaging Guidelines}, for
b4f5e0e8
CR
2281more information on how to test package definitions, and
2282@ref{Invoking guix lint}, for information on how to check a definition
2283for style conformance.
2284
7458bd0a
LC
2285Eventually, updating the package definition to a new upstream version
2286can be partly automated by the @command{guix refresh} command
2287(@pxref{Invoking guix refresh}).
3dc1970d
LC
2288
2289Behind the scenes, a derivation corresponding to the @code{<package>}
2290object is first computed by the @code{package-derivation} procedure.
834129e0 2291That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 2292The build actions it prescribes may then be realized by using the
3dc1970d
LC
2293@code{build-derivations} procedure (@pxref{The Store}).
2294
2295@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
2296Return the @code{<derivation>} object of @var{package} for @var{system}
2297(@pxref{Derivations}).
3dc1970d
LC
2298
2299@var{package} must be a valid @code{<package>} object, and @var{system}
2300must be a string denoting the target system type---e.g.,
2301@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2302must be a connection to the daemon, which operates on the store
2303(@pxref{The Store}).
2304@end deffn
568717fd 2305
9c1edabd
LC
2306@noindent
2307@cindex cross-compilation
2308Similarly, it is possible to compute a derivation that cross-builds a
2309package for some other system:
2310
2311@deffn {Scheme Procedure} package-cross-derivation @var{store} @
2312 @var{package} @var{target} [@var{system}]
59688fc4
LC
2313Return the @code{<derivation>} object of @var{package} cross-built from
2314@var{system} to @var{target}.
9c1edabd
LC
2315
2316@var{target} must be a valid GNU triplet denoting the target hardware
2317and operating system, such as @code{"mips64el-linux-gnu"}
2318(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2319Configure and Build System}).
2320@end deffn
2321
87eafdbd
TUBK
2322@menu
2323* package Reference :: The package data type.
2324* origin Reference:: The origin data type.
2325@end menu
2326
2327
2328@node package Reference
2329@subsection @code{package} Reference
2330
2331This section summarizes all the options available in @code{package}
2332declarations (@pxref{Defining Packages}).
2333
2334@deftp {Data Type} package
2335This is the data type representing a package recipe.
2336
2337@table @asis
2338@item @code{name}
2339The name of the package, as a string.
2340
2341@item @code{version}
2342The version of the package, as a string.
2343
2344@item @code{source}
2345An origin object telling how the source code for the package should be
2346acquired (@pxref{origin Reference}).
2347
2348@item @code{build-system}
2349The build system that should be used to build the package (@pxref{Build
2350Systems}).
2351
2352@item @code{arguments} (default: @code{'()})
2353The arguments that should be passed to the build system. This is a
2354list, typically containing sequential keyword-value pairs.
2355
2356@item @code{inputs} (default: @code{'()})
70650c68
LC
2357@itemx @code{native-inputs} (default: @code{'()})
2358@itemx @code{propagated-inputs} (default: @code{'()})
2359@cindex inputs, of packages
2360These fields list dependencies of the package. Each one is a list of
2361tuples, where each tuple has a label for the input (a string) as its
2362first element, a package, origin, or derivation as its second element,
2363and optionally the name of the output thereof that should be used, which
2364defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
2365more on package outputs). For example, the list below specifies 3
2366inputs:
87eafdbd 2367
70650c68
LC
2368@example
2369`(("libffi" ,libffi)
2370 ("libunistring" ,libunistring)
2371 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
2372@end example
2373
2374@cindex cross compilation, package dependencies
2375The distinction between @code{native-inputs} and @code{inputs} is
2376necessary when considering cross-compilation. When cross-compiling,
2377dependencies listed in @code{inputs} are built for the @emph{target}
2378architecture; conversely, dependencies listed in @code{native-inputs}
2379are built for the architecture of the @emph{build} machine.
2380
2381@code{native-inputs} is typically where you would list tools needed at
2382build time but not at run time, such as Autoconf, Automake, pkg-config,
2383Gettext, or Bison. @command{guix lint} can report likely mistakes in
2384this area (@pxref{Invoking guix lint}).
2385
2386@anchor{package-propagated-inputs}
2387Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
2388specified packages will be force-installed alongside the package they
2389belong to (@pxref{package-cmd-propagated-inputs, @command{guix
2390package}}, for information on how @command{guix package} deals with
2391propagated inputs.)
21461f27 2392
e0508b6b
LC
2393For example this is necessary when a C/C++ library needs headers of
2394another library to compile, or when a pkg-config file refers to another
2395one @i{via} its @code{Requires} field.
2396
2397Another example where @code{propagated-inputs} is useful is for
2398languages that lack a facility to record the run-time search path akin
2399to ELF's @code{RUNPATH}; this includes Guile, Python, Perl, GHC, and
2400more. To ensure that libraries written in those languages can find
2401library code they depend on at run time, run-time dependencies must be
2402listed in @code{propagated-inputs} rather than @code{inputs}.
87eafdbd 2403
87eafdbd
TUBK
2404@item @code{self-native-input?} (default: @code{#f})
2405This is a Boolean field telling whether the package should use itself as
2406a native input when cross-compiling.
2407
2408@item @code{outputs} (default: @code{'("out")})
2409The list of output names of the package. @xref{Packages with Multiple
2410Outputs}, for typical uses of additional outputs.
2411
2412@item @code{native-search-paths} (default: @code{'()})
2413@itemx @code{search-paths} (default: @code{'()})
2414A list of @code{search-path-specification} objects describing
2415search-path environment variables honored by the package.
2416
2417@item @code{replacement} (default: @code{#f})
2418This must either @code{#f} or a package object that will be used as a
2419@dfn{replacement} for this package. @xref{Security Updates, grafts},
2420for details.
2421
2422@item @code{synopsis}
2423A one-line description of the package.
2424
2425@item @code{description}
2426A more elaborate description of the package.
2427
2428@item @code{license}
2429The license of the package; a value from @code{(guix licenses)}.
2430
2431@item @code{home-page}
2432The URL to the home-page of the package, as a string.
2433
2434@item @code{supported-systems} (default: @var{%supported-systems})
2435The list of systems supported by the package, as strings of the form
2436@code{architecture-kernel}, for example @code{"x86_64-linux"}.
2437
2438@item @code{maintainers} (default: @code{'()})
2439The list of maintainers of the package, as @code{maintainer} objects.
2440
2441@item @code{location} (default: source location of the @code{package} form)
2442The source location of the package. It's useful to override this when
2443inheriting from another package, in which case this field is not
2444automatically corrected.
2445@end table
2446@end deftp
2447
2448
2449@node origin Reference
2450@subsection @code{origin} Reference
2451
2452This section summarizes all the options available in @code{origin}
2453declarations (@pxref{Defining Packages}).
2454
2455@deftp {Data Type} origin
2456This is the data type representing a source code origin.
2457
2458@table @asis
2459@item @code{uri}
2460An object containing the URI of the source. The object type depends on
2461the @code{method} (see below). For example, when using the
2462@var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2463values are: a URL represented as a string, or a list thereof.
2464
2465@item @code{method}
2466A procedure that will handle the URI.
2467
2468Examples include:
2469
2470@table @asis
2471@item @var{url-fetch} from @code{(guix download)}
2472download a file the HTTP, HTTPS, or FTP URL specified in the
2473@code{uri} field;
2474
2475@item @var{git-fetch} from @code{(guix git-download)}
2476clone the Git version control repository, and check out the revision
2477specified in the @code{uri} field as a @code{git-reference} object; a
2478@code{git-reference} looks like this:
2479
2480@example
2481(git-reference
2482 (url "git://git.debian.org/git/pkg-shadow/shadow")
2483 (commit "v4.1.5.1"))
2484@end example
2485@end table
2486
2487@item @code{sha256}
2488A bytevector containing the SHA-256 hash of the source. Typically the
2489@code{base32} form is used here to generate the bytevector from a
2490base-32 string.
2491
2492@item @code{file-name} (default: @code{#f})
2493The file name under which the source code should be saved. When this is
2494@code{#f}, a sensible default value will be used in most cases. In case
2495the source is fetched from a URL, the file name from the URL will be
2496used. For version control checkouts, it's recommended to provide the
2497file name explicitly because the default is not very descriptive.
2498
2499@item @code{patches} (default: @code{'()})
2500A list of file names containing patches to be applied to the source.
2501
2502@item @code{snippet} (default: @code{#f})
2503A quoted piece of code that will be run in the source directory to make
2504any modifications, which is sometimes more convenient than a patch.
2505
2506@item @code{patch-flags} (default: @code{'("-p1")})
2507A list of command-line flags that should be passed to the @code{patch}
2508command.
2509
2510@item @code{patch-inputs} (default: @code{#f})
2511Input packages or derivations to the patching process. When this is
2512@code{#f}, the usual set of inputs necessary for patching are provided,
2513such as GNU@tie{}Patch.
2514
2515@item @code{modules} (default: @code{'()})
2516A list of Guile modules that should be loaded during the patching
2517process and while running the code in the @code{snippet} field.
2518
2519@item @code{imported-modules} (default: @code{'()})
2520The list of Guile modules to import in the patch derivation, for use by
2521the @code{snippet}.
2522
2523@item @code{patch-guile} (default: @code{#f})
2524The Guile package that should be used in the patching process. When
2525this is @code{#f}, a sensible default is used.
2526@end table
2527@end deftp
2528
9c1edabd 2529
7458bd0a
LC
2530@node Build Systems
2531@section Build Systems
2532
2533@cindex build system
2534Each package definition specifies a @dfn{build system} and arguments for
2535that build system (@pxref{Defining Packages}). This @code{build-system}
2536field represents the build procedure of the package, as well implicit
2537dependencies of that build procedure.
2538
2539Build systems are @code{<build-system>} objects. The interface to
2540create and manipulate them is provided by the @code{(guix build-system)}
2541module, and actual build systems are exported by specific modules.
2542
f5fd4fd2 2543@cindex bag (low-level package representation)
0d5a559f
LC
2544Under the hood, build systems first compile package objects to
2545@dfn{bags}. A @dfn{bag} is like a package, but with less
2546ornamentation---in other words, a bag is a lower-level representation of
2547a package, which includes all the inputs of that package, including some
2548that were implicitly added by the build system. This intermediate
2549representation is then compiled to a derivation (@pxref{Derivations}).
2550
7458bd0a
LC
2551Build systems accept an optional list of @dfn{arguments}. In package
2552definitions, these are passed @i{via} the @code{arguments} field
2553(@pxref{Defining Packages}). They are typically keyword arguments
2554(@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
2555Guile Reference Manual}). The value of these arguments is usually
2556evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
2557by the daemon (@pxref{Derivations}).
2558
2559The main build system is @var{gnu-build-system}, which implements the
2560standard build procedure for GNU packages and many other packages. It
2561is provided by the @code{(guix build-system gnu)} module.
2562
2563@defvr {Scheme Variable} gnu-build-system
2564@var{gnu-build-system} represents the GNU Build System, and variants
2565thereof (@pxref{Configuration, configuration and makefile conventions,,
2566standards, GNU Coding Standards}).
2567
2568@cindex build phases
2569In a nutshell, packages using it configured, built, and installed with
2570the usual @code{./configure && make && make check && make install}
2571command sequence. In practice, a few additional steps are often needed.
2572All these steps are split up in separate @dfn{phases},
2573notably@footnote{Please see the @code{(guix build gnu-build-system)}
2574modules for more details about the build phases.}:
2575
2576@table @code
2577@item unpack
2578Unpack the source tarball, and change the current directory to the
2579extracted source tree. If the source is actually a directory, copy it
2580to the build tree, and enter that directory.
2581
2582@item patch-source-shebangs
2583Patch shebangs encountered in source files so they refer to the right
2584store file names. For instance, this changes @code{#!/bin/sh} to
2585@code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
2586
2587@item configure
2588Run the @file{configure} script with a number of default options, such
2589as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
2590by the @code{#:configure-flags} argument.
2591
2592@item build
2593Run @code{make} with the list of flags specified with
0917e80e 2594@code{#:make-flags}. If the @code{#:parallel-build?} argument is true
7458bd0a
LC
2595(the default), build with @code{make -j}.
2596
2597@item check
2598Run @code{make check}, or some other target specified with
2599@code{#:test-target}, unless @code{#:tests? #f} is passed. If the
2600@code{#:parallel-tests?} argument is true (the default), run @code{make
2601check -j}.
2602
2603@item install
2604Run @code{make install} with the flags listed in @code{#:make-flags}.
2605
2606@item patch-shebangs
2607Patch shebangs on the installed executable files.
2608
2609@item strip
2610Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
2611is false), copying them to the @code{debug} output when available
2612(@pxref{Installing Debugging Files}).
2613@end table
2614
2615@vindex %standard-phases
2616The build-side module @code{(guix build gnu-build-system)} defines
2617@var{%standard-phases} as the default list of build phases.
2618@var{%standard-phases} is a list of symbol/procedure pairs, where the
2619procedure implements the actual phase.
2620
2621The list of phases used for a particular package can be changed with the
2622@code{#:phases} parameter. For instance, passing:
2623
2624@example
2625#:phases (alist-delete 'configure %standard-phases)
2626@end example
2627
9bf404e9 2628means that all the phases described above will be used, except the
7458bd0a
LC
2629@code{configure} phase.
2630
2631In addition, this build system ensures that the ``standard'' environment
2632for GNU packages is available. This includes tools such as GCC, libc,
2633Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
2634build-system gnu)} module for a complete list.) We call these the
2635@dfn{implicit inputs} of a package, because package definitions don't
2636have to mention them.
2637@end defvr
2638
2639Other @code{<build-system>} objects are defined to support other
2640conventions and tools used by free software packages. They inherit most
2641of @var{gnu-build-system}, and differ mainly in the set of inputs
2642implicitly added to the build process, and in the list of phases
2643executed. Some of these build systems are listed below.
2644
2645@defvr {Scheme Variable} cmake-build-system
2646This variable is exported by @code{(guix build-system cmake)}. It
2647implements the build procedure for packages using the
2648@url{http://www.cmake.org, CMake build tool}.
2649
2650It automatically adds the @code{cmake} package to the set of inputs.
2651Which package is used can be specified with the @code{#:cmake}
2652parameter.
9849cfc1
LC
2653
2654The @code{#:configure-flags} parameter is taken as a list of flags
2655passed to the @command{cmake} command. The @code{#:build-type}
2656parameter specifies in abstract terms the flags passed to the compiler;
2657it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
2658debugging information''), which roughly means that code is compiled with
2659@code{-O2 -g}, as is the case for Autoconf-based packages by default.
7458bd0a
LC
2660@end defvr
2661
3afcf52b
FB
2662@defvr {Scheme Variable} glib-or-gtk-build-system
2663This variable is exported by @code{(guix build-system glib-or-gtk)}. It
2664is intended for use with packages making use of GLib or GTK+.
2665
2666This build system adds the following two phases to the ones defined by
2667@var{gnu-build-system}:
2668
2669@table @code
2670@item glib-or-gtk-wrap
2671The phase @code{glib-or-gtk-wrap} ensures that programs found under
2672@file{bin/} are able to find GLib's ``schemas'' and
2673@uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
2674modules}. This is achieved by wrapping the programs in launch scripts
2675that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
2676environment variables.
2677
73aa8ddb
LC
2678It is possible to exclude specific package outputs from that wrapping
2679process by listing their names in the
2680@code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
2681when an output is known not to contain any GLib or GTK+ binaries, and
2682where wrapping would gratuitously add a dependency of that output on
2683GLib and GTK+.
2684
3afcf52b
FB
2685@item glib-or-gtk-compile-schemas
2686The phase @code{glib-or-gtk-compile-schemas} makes sure that all GLib's
2687@uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
2688GSettings schemas} are compiled. Compilation is performed by the
2689@command{glib-compile-schemas} program. It is provided by the package
2690@code{glib:bin} which is automatically imported by the build system.
2691The @code{glib} package providing @command{glib-compile-schemas} can be
2692specified with the @code{#:glib} parameter.
2693@end table
2694
2695Both phases are executed after the @code{install} phase.
2696@end defvr
2697
7458bd0a
LC
2698@defvr {Scheme Variable} python-build-system
2699This variable is exported by @code{(guix build-system python)}. It
2700implements the more or less standard build procedure used by Python
2701packages, which consists in running @code{python setup.py build} and
2702then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
2703
2704For packages that install stand-alone Python programs under @code{bin/},
2705it takes care of wrapping these programs so their @code{PYTHONPATH}
2706environment variable points to all the Python libraries they depend on.
2707
2708Which Python package is used can be specified with the @code{#:python}
2709parameter.
2710@end defvr
2711
2712@defvr {Scheme Variable} perl-build-system
2713This variable is exported by @code{(guix build-system perl)}. It
2d2a53fc
EB
2714implements the standard build procedure for Perl packages, which either
2715consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
2716followed by @code{Build} and @code{Build install}; or in running
2717@code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
2718@code{make} and @code{make install}; depending on which of
2719@code{Build.PL} or @code{Makefile.PL} is present in the package
2720distribution. Preference is given to the former if both @code{Build.PL}
2721and @code{Makefile.PL} exist in the package distribution. This
2722preference can be reversed by specifying @code{#t} for the
2723@code{#:make-maker?} parameter.
2724
2725The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
2726passes flags specified by the @code{#:make-maker-flags} or
2727@code{#:module-build-flags} parameter, respectively.
7458bd0a
LC
2728
2729Which Perl package is used can be specified with @code{#:perl}.
2730@end defvr
2731
f8f3bef6
RW
2732@defvr {Scheme Variable} r-build-system
2733This variable is exported by @code{(guix build-system r)}. It
2734implements the build procedure used by @uref{http://r-project.org, R}
2735packages, which essentially is little more than running @code{R CMD
2736INSTALL --library=/gnu/store/@dots{}} in an environment where
2737@code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
2738are run after installation using the R function
2739@code{tools::testInstalledPackage}.
2740@end defvr
2741
c08f9818
DT
2742@defvr {Scheme Variable} ruby-build-system
2743This variable is exported by @code{(guix build-system ruby)}. It
2744implements the RubyGems build procedure used by Ruby packages, which
2745involves running @code{gem build} followed by @code{gem install}.
2746
5dc87623
DT
2747The @code{source} field of a package that uses this build system
2748typically references a gem archive, since this is the format that Ruby
2749developers use when releasing their software. The build system unpacks
2750the gem archive, potentially patches the source, runs the test suite,
2751repackages the gem, and installs it. Additionally, directories and
2752tarballs may be referenced to allow building unreleased gems from Git or
2753a traditional source release tarball.
e83c6d00 2754
c08f9818 2755Which Ruby package is used can be specified with the @code{#:ruby}
6e9f2913
PP
2756parameter. A list of additional flags to be passed to the @command{gem}
2757command can be specified with the @code{#:gem-flags} parameter.
c08f9818 2758@end defvr
7458bd0a 2759
a677c726
RW
2760@defvr {Scheme Variable} waf-build-system
2761This variable is exported by @code{(guix build-system waf)}. It
2762implements a build procedure around the @code{waf} script. The common
2763phases---@code{configure}, @code{build}, and @code{install}---are
2764implemented by passing their names as arguments to the @code{waf}
2765script.
2766
2767The @code{waf} script is executed by the Python interpreter. Which
2768Python package is used to run the script can be specified with the
2769@code{#:python} parameter.
2770@end defvr
2771
14dfdf2e
FB
2772@defvr {Scheme Variable} haskell-build-system
2773This variable is exported by @code{(guix build-system haskell)}. It
2774implements the Cabal build procedure used by Haskell packages, which
2775involves running @code{runhaskell Setup.hs configure
2776--prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
2777Instead of installing the package by running @code{runhaskell Setup.hs
2778install}, to avoid trying to register libraries in the read-only
2779compiler store directory, the build system uses @code{runhaskell
2780Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
2781addition, the build system generates the package documentation by
2782running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
2783is passed. Optional Haddock parameters can be passed with the help of
2784the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
2785not found, the build system looks for @code{Setup.lhs} instead.
2786
2787Which Haskell compiler is used can be specified with the @code{#:haskell}
a54bd6d7 2788parameter which defaults to @code{ghc}.
14dfdf2e
FB
2789@end defvr
2790
e9137a53
FB
2791@defvr {Scheme Variable} emacs-build-system
2792This variable is exported by @code{(guix build-system emacs)}. It
2793implements an installation procedure similar to the one of Emacs' own
2794packaging system (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
2795
2796It first creates the @code{@var{package}-autoloads.el} file, then it
2797byte compiles all Emacs Lisp files. Differently from the Emacs
2798packaging system, the Info documentation files are moved to the standard
2799documentation directory and the @file{dir} file is deleted. Each
2800package is installed in its own directory under
2801@file{share/emacs/site-lisp/guix.d}.
2802@end defvr
2803
7458bd0a
LC
2804Lastly, for packages that do not need anything as sophisticated, a
2805``trivial'' build system is provided. It is trivial in the sense that
2806it provides basically no support: it does not pull any implicit inputs,
2807and does not have a notion of build phases.
2808
2809@defvr {Scheme Variable} trivial-build-system
2810This variable is exported by @code{(guix build-system trivial)}.
2811
2812This build system requires a @code{#:builder} argument. This argument
2813must be a Scheme expression that builds the package's output(s)---as
2814with @code{build-expression->derivation} (@pxref{Derivations,
2815@code{build-expression->derivation}}).
2816@end defvr
2817
568717fd
LC
2818@node The Store
2819@section The Store
2820
e531ac2a
LC
2821@cindex store
2822@cindex store paths
2823
2824Conceptually, the @dfn{store} is where derivations that have been
834129e0 2825successfully built are stored---by default, under @file{/gnu/store}.
e531ac2a 2826Sub-directories in the store are referred to as @dfn{store paths}. The
4988dd40 2827store has an associated database that contains information such as the
e531ac2a
LC
2828store paths referred to by each store path, and the list of @emph{valid}
2829store paths---paths that result from a successful build.
2830
2831The store is always accessed by the daemon on behalf of its clients
2832(@pxref{Invoking guix-daemon}). To manipulate the store, clients
2833connect to the daemon over a Unix-domain socket, send it requests, and
2834read the result---these are remote procedure calls, or RPCs.
2835
2836The @code{(guix store)} module provides procedures to connect to the
2837daemon, and to perform RPCs. These are described below.
2838
2839@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
2840Connect to the daemon over the Unix-domain socket at @var{file}. When
2841@var{reserve-space?} is true, instruct it to reserve a little bit of
2842extra space on the file system so that the garbage collector can still
2843operate, should the disk become full. Return a server object.
2844
2845@var{file} defaults to @var{%default-socket-path}, which is the normal
2846location given the options that were passed to @command{configure}.
2847@end deffn
2848
2849@deffn {Scheme Procedure} close-connection @var{server}
2850Close the connection to @var{server}.
2851@end deffn
2852
2853@defvr {Scheme Variable} current-build-output-port
2854This variable is bound to a SRFI-39 parameter, which refers to the port
2855where build and error logs sent by the daemon should be written.
2856@end defvr
2857
2858Procedures that make RPCs all take a server object as their first
2859argument.
2860
2861@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
2862Return @code{#t} when @var{path} is a valid store path.
2863@end deffn
2864
cfbf9160 2865@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
2866Add @var{text} under file @var{name} in the store, and return its store
2867path. @var{references} is the list of store paths referred to by the
2868resulting store path.
2869@end deffn
2870
874e6874 2871@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
2872Build @var{derivations} (a list of @code{<derivation>} objects or
2873derivation paths), and return when the worker is done building them.
2874Return @code{#t} on success.
874e6874
LC
2875@end deffn
2876
b860f382
LC
2877Note that the @code{(guix monads)} module provides a monad as well as
2878monadic versions of the above procedures, with the goal of making it
2879more convenient to work with code that accesses the store (@pxref{The
2880Store Monad}).
2881
e531ac2a
LC
2882@c FIXME
2883@i{This section is currently incomplete.}
568717fd
LC
2884
2885@node Derivations
2886@section Derivations
2887
874e6874
LC
2888@cindex derivations
2889Low-level build actions and the environment in which they are performed
2890are represented by @dfn{derivations}. A derivation contain the
2891following pieces of information:
2892
2893@itemize
2894@item
2895The outputs of the derivation---derivations produce at least one file or
2896directory in the store, but may produce more.
2897
2898@item
2899The inputs of the derivations, which may be other derivations or plain
2900files in the store (patches, build scripts, etc.)
2901
2902@item
2903The system type targeted by the derivation---e.g., @code{x86_64-linux}.
2904
2905@item
2906The file name of a build script in the store, along with the arguments
2907to be passed.
2908
2909@item
2910A list of environment variables to be defined.
2911
2912@end itemize
2913
2914@cindex derivation path
2915Derivations allow clients of the daemon to communicate build actions to
2916the store. They exist in two forms: as an in-memory representation,
2917both on the client- and daemon-side, and as files in the store whose
2918name end in @code{.drv}---these files are referred to as @dfn{derivation
2919paths}. Derivations paths can be passed to the @code{build-derivations}
2920procedure to perform the build actions they prescribe (@pxref{The
2921Store}).
2922
2923The @code{(guix derivations)} module provides a representation of
2924derivations as Scheme objects, along with procedures to create and
2925otherwise manipulate derivations. The lowest-level primitive to create
2926a derivation is the @code{derivation} procedure:
2927
1909431c
LC
2928@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
2929 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 2930 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c 2931 [#:system (%current-system)] [#:references-graphs #f] @
4a6aeb67
LC
2932 [#:allowed-references #f] [#:leaked-env-vars #f] [#:local-build? #f] @
2933 [#:substitutable? #t]
59688fc4
LC
2934Build a derivation with the given arguments, and return the resulting
2935@code{<derivation>} object.
874e6874 2936
2096ef47 2937When @var{hash} and @var{hash-algo} are given, a
874e6874 2938@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
2939known in advance, such as a file download. If, in addition,
2940@var{recursive?} is true, then that fixed output may be an executable
2941file or a directory and @var{hash} must be the hash of an archive
2942containing this output.
5b0c9d16 2943
858e9282 2944When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
2945name/store path pairs. In that case, the reference graph of each store
2946path is exported in the build environment in the corresponding file, in
2947a simple text format.
1909431c 2948
b53be755
LC
2949When @var{allowed-references} is true, it must be a list of store items
2950or outputs that the derivation's output may refer to.
2951
c0468155
LC
2952When @var{leaked-env-vars} is true, it must be a list of strings
2953denoting environment variables that are allowed to ``leak'' from the
2954daemon's environment to the build environment. This is only applicable
2955to fixed-output derivations---i.e., when @var{hash} is true. The main
2956use is to allow variables such as @code{http_proxy} to be passed to
2957derivations that download files.
2958
1909431c
LC
2959When @var{local-build?} is true, declare that the derivation is not a
2960good candidate for offloading and should rather be built locally
2961(@pxref{Daemon Offload Setup}). This is the case for small derivations
2962where the costs of data transfers would outweigh the benefits.
4a6aeb67
LC
2963
2964When @var{substitutable?} is false, declare that substitutes of the
2965derivation's output should not be used (@pxref{Substitutes}). This is
2966useful, for instance, when building packages that capture details of the
2967host CPU instruction set.
874e6874
LC
2968@end deffn
2969
2970@noindent
2971Here's an example with a shell script as its builder, assuming
2972@var{store} is an open connection to the daemon, and @var{bash} points
2973to a Bash executable in the store:
2974
2975@lisp
2976(use-modules (guix utils)
2977 (guix store)
2978 (guix derivations))
2979
59688fc4
LC
2980(let ((builder ; add the Bash script to the store
2981 (add-text-to-store store "my-builder.sh"
2982 "echo hello world > $out\n" '())))
2983 (derivation store "foo"
2984 bash `("-e" ,builder)
21b679f6 2985 #:inputs `((,bash) (,builder))
59688fc4 2986 #:env-vars '(("HOME" . "/homeless"))))
834129e0 2987@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
2988@end lisp
2989
21b679f6
LC
2990As can be guessed, this primitive is cumbersome to use directly. A
2991better approach is to write build scripts in Scheme, of course! The
2992best course of action for that is to write the build code as a
2993``G-expression'', and to pass it to @code{gexp->derivation}. For more
6621cdb6 2994information, @pxref{G-Expressions}.
21b679f6
LC
2995
2996Once upon a time, @code{gexp->derivation} did not exist and constructing
2997derivations with build code written in Scheme was achieved with
2998@code{build-expression->derivation}, documented below. This procedure
2999is now deprecated in favor of the much nicer @code{gexp->derivation}.
874e6874 3000
dd1a5a15
LC
3001@deffn {Scheme Procedure} build-expression->derivation @var{store} @
3002 @var{name} @var{exp} @
3003 [#:system (%current-system)] [#:inputs '()] @
3004 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
36bbbbd1 3005 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
63a42824 3006 [#:references-graphs #f] [#:allowed-references #f] @
4a6aeb67 3007 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
874e6874
LC
3008Return a derivation that executes Scheme expression @var{exp} as a
3009builder for derivation @var{name}. @var{inputs} must be a list of
3010@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
3011@code{"out"} is assumed. @var{modules} is a list of names of Guile
3012modules from the current search path to be copied in the store,
3013compiled, and made available in the load path during the execution of
3014@var{exp}---e.g., @code{((guix build utils) (guix build
3015gnu-build-system))}.
3016
3017@var{exp} is evaluated in an environment where @code{%outputs} is bound
3018to a list of output/path pairs, and where @code{%build-inputs} is bound
3019to a list of string/output-path pairs made from @var{inputs}.
3020Optionally, @var{env-vars} is a list of string pairs specifying the name
3021and value of environment variables visible to the builder. The builder
3022terminates by passing the result of @var{exp} to @code{exit}; thus, when
3023@var{exp} returns @code{#f}, the build is considered to have failed.
3024
3025@var{exp} is built using @var{guile-for-build} (a derivation). When
3026@var{guile-for-build} is omitted or is @code{#f}, the value of the
3027@code{%guile-for-build} fluid is used instead.
9c629a27 3028
63a42824 3029See the @code{derivation} procedure for the meaning of
4a6aeb67
LC
3030@var{references-graphs}, @var{allowed-references}, @var{local-build?},
3031and @var{substitutable?}.
874e6874
LC
3032@end deffn
3033
3034@noindent
3035Here's an example of a single-output derivation that creates a directory
3036containing one file:
3037
3038@lisp
3039(let ((builder '(let ((out (assoc-ref %outputs "out")))
834129e0 3040 (mkdir out) ; create /gnu/store/@dots{}-goo
874e6874
LC
3041 (call-with-output-file (string-append out "/test")
3042 (lambda (p)
3043 (display '(hello guix) p))))))
dd1a5a15 3044 (build-expression->derivation store "goo" builder))
874e6874 3045
834129e0 3046@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
874e6874
LC
3047@end lisp
3048
568717fd 3049
b860f382
LC
3050@node The Store Monad
3051@section The Store Monad
3052
3053@cindex monad
3054
3055The procedures that operate on the store described in the previous
3056sections all take an open connection to the build daemon as their first
3057argument. Although the underlying model is functional, they either have
3058side effects or depend on the current state of the store.
3059
3060The former is inconvenient: the connection to the build daemon has to be
3061carried around in all those functions, making it impossible to compose
3062functions that do not take that parameter with functions that do. The
3063latter can be problematic: since store operations have side effects
3064and/or depend on external state, they have to be properly sequenced.
3065
3066@cindex monadic values
3067@cindex monadic functions
3068This is where the @code{(guix monads)} module comes in. This module
3069provides a framework for working with @dfn{monads}, and a particularly
3070useful monad for our uses, the @dfn{store monad}. Monads are a
3071construct that allows two things: associating ``context'' with values
3072(in our case, the context is the store), and building sequences of
561fb6c3 3073computations (here computations include accesses to the store.) Values
b860f382
LC
3074in a monad---values that carry this additional context---are called
3075@dfn{monadic values}; procedures that return such values are called
3076@dfn{monadic procedures}.
3077
3078Consider this ``normal'' procedure:
3079
3080@example
45adbd62
LC
3081(define (sh-symlink store)
3082 ;; Return a derivation that symlinks the 'bash' executable.
3083 (let* ((drv (package-derivation store bash))
3084 (out (derivation->output-path drv))
3085 (sh (string-append out "/bin/bash")))
3086 (build-expression->derivation store "sh"
3087 `(symlink ,sh %output))))
b860f382
LC
3088@end example
3089
c6f30b81
LC
3090Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3091as a monadic function:
b860f382
LC
3092
3093@example
45adbd62 3094(define (sh-symlink)
b860f382 3095 ;; Same, but return a monadic value.
c6f30b81
LC
3096 (mlet %store-monad ((drv (package->derivation bash)))
3097 (gexp->derivation "sh"
3098 #~(symlink (string-append #$drv "/bin/bash")
3099 #$output))))
b860f382
LC
3100@end example
3101
c6f30b81
LC
3102There several things to note in the second version: the @code{store}
3103parameter is now implicit and is ``threaded'' in the calls to the
3104@code{package->derivation} and @code{gexp->derivation} monadic
3105procedures, and the monadic value returned by @code{package->derivation}
3106is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3107
3108As it turns out, the call to @code{package->derivation} can even be
3109omitted since it will take place implicitly, as we will see later
3110(@pxref{G-Expressions}):
3111
3112@example
3113(define (sh-symlink)
3114 (gexp->derivation "sh"
3115 #~(symlink (string-append #$bash "/bin/bash")
3116 #$output)))
3117@end example
b860f382 3118
7ce21611
LC
3119@c See
3120@c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
3121@c for the funny quote.
3122Calling the monadic @code{sh-symlink} has no effect. As someone once
3123said, ``you exit a monad like you exit a building on fire: by running''.
3124So, to exit the monad and get the desired effect, one must use
3125@code{run-with-store}:
b860f382
LC
3126
3127@example
8e9aa37f
CAW
3128(run-with-store (open-connection) (sh-symlink))
3129@result{} /gnu/store/...-sh-symlink
b860f382
LC
3130@end example
3131
b9b86078
LC
3132Note that the @code{(guix monad-repl)} module extends Guile's REPL with
3133new ``meta-commands'' to make it easier to deal with monadic procedures:
3134@code{run-in-store}, and @code{enter-store-monad}. The former, is used
3135to ``run'' a single monadic value through the store:
3136
3137@example
3138scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3139$1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3140@end example
3141
3142The latter enters a recursive REPL, where all the return values are
3143automatically run through the store:
3144
3145@example
3146scheme@@(guile-user)> ,enter-store-monad
3147store-monad@@(guile-user) [1]> (package->derivation hello)
3148$2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3149store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3150$3 = "/gnu/store/@dots{}-foo"
3151store-monad@@(guile-user) [1]> ,q
3152scheme@@(guile-user)>
3153@end example
3154
3155@noindent
3156Note that non-monadic values cannot be returned in the
3157@code{store-monad} REPL.
3158
e87f0591
LC
3159The main syntactic forms to deal with monads in general are provided by
3160the @code{(guix monads)} module and are described below.
b860f382
LC
3161
3162@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3163Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3164in @var{monad}.
3165@end deffn
3166
3167@deffn {Scheme Syntax} return @var{val}
3168Return a monadic value that encapsulates @var{val}.
3169@end deffn
3170
751630c9 3171@deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
b860f382 3172@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
751630c9
LC
3173procedures @var{mproc}@dots{}@footnote{This operation is commonly
3174referred to as ``bind'', but that name denotes an unrelated procedure in
3175Guile. Thus we use this somewhat cryptic symbol inherited from the
3176Haskell language.}. There can be one @var{mproc} or several of them, as
3177in this example:
3178
3179@example
3180(run-with-state
3181 (with-monad %state-monad
3182 (>>= (return 1)
3183 (lambda (x) (return (+ 1 x)))
3184 (lambda (x) (return (* 2 x)))))
3185 'some-state)
3186
3187@result{} 4
3188@result{} some-state
3189@end example
b860f382
LC
3190@end deffn
3191
3192@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3193 @var{body} ...
3194@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3195 @var{body} ...
3196Bind the variables @var{var} to the monadic values @var{mval} in
3197@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3198``normal'' value @var{val}, as per @code{let}.
3199
3200@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3201(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3202@end deffn
3203
405a9d4e
LC
3204@deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3205Bind @var{mexp} and the following monadic expressions in sequence,
3206returning the result of the last expression.
3207
3208This is akin to @code{mlet}, except that the return values of the
3209monadic expressions are ignored. In that sense, it is analogous to
3210@code{begin}, but applied to monadic expressions.
3211@end deffn
3212
561fb6c3
LC
3213@cindex state monad
3214The @code{(guix monads)} module provides the @dfn{state monad}, which
3215allows an additional value---the state---to be @emph{threaded} through
3216monadic procedure calls.
3217
3218@defvr {Scheme Variable} %state-monad
3219The state monad. Procedures in the state monad can access and change
3220the state that is threaded.
3221
3222Consider the example below. The @code{square} procedure returns a value
3223in the state monad. It returns the square of its argument, but also
3224increments the current state value:
3225
3226@example
3227(define (square x)
3228 (mlet %state-monad ((count (current-state)))
3229 (mbegin %state-monad
3230 (set-current-state (+ 1 count))
3231 (return (* x x)))))
3232
3233(run-with-state (sequence %state-monad (map square (iota 3))) 0)
3234@result{} (0 1 4)
3235@result{} 3
3236@end example
3237
3238When ``run'' through @var{%state-monad}, we obtain that additional state
3239value, which is the number of @code{square} calls.
3240@end defvr
3241
3242@deffn {Monadic Procedure} current-state
3243Return the current state as a monadic value.
3244@end deffn
3245
3246@deffn {Monadic Procedure} set-current-state @var{value}
3247Set the current state to @var{value} and return the previous state as a
3248monadic value.
3249@end deffn
3250
3251@deffn {Monadic Procedure} state-push @var{value}
3252Push @var{value} to the current state, which is assumed to be a list,
3253and return the previous state as a monadic value.
3254@end deffn
3255
3256@deffn {Monadic Procedure} state-pop
3257Pop a value from the current state and return it as a monadic value.
3258The state is assumed to be a list.
3259@end deffn
3260
3261@deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3262Run monadic value @var{mval} starting with @var{state} as the initial
3263state. Return two values: the resulting value, and the resulting state.
3264@end deffn
3265
e87f0591
LC
3266The main interface to the store monad, provided by the @code{(guix
3267store)} module, is as follows.
b860f382
LC
3268
3269@defvr {Scheme Variable} %store-monad
561fb6c3
LC
3270The store monad---an alias for @var{%state-monad}.
3271
3272Values in the store monad encapsulate accesses to the store. When its
3273effect is needed, a value of the store monad must be ``evaluated'' by
3274passing it to the @code{run-with-store} procedure (see below.)
b860f382
LC
3275@end defvr
3276
3277@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3278Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3279open store connection.
3280@end deffn
3281
ad372953 3282@deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
b860f382 3283Return as a monadic value the absolute file name in the store of the file
ad372953
LC
3284containing @var{text}, a string. @var{references} is a list of store items that the
3285resulting text file refers to; it defaults to the empty list.
45adbd62
LC
3286@end deffn
3287
0a90af15
LC
3288@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
3289 [#:recursive? #t]
3290Return the name of @var{file} once interned in the store. Use
3291@var{name} as its store name, or the basename of @var{file} if
3292@var{name} is omitted.
3293
3294When @var{recursive?} is true, the contents of @var{file} are added
3295recursively; if @var{file} designates a flat file and @var{recursive?}
3296is true, its contents are added, and its permission bits are kept.
3297
3298The example below adds a file to the store, under two different names:
3299
3300@example
3301(run-with-store (open-connection)
3302 (mlet %store-monad ((a (interned-file "README"))
3303 (b (interned-file "README" "LEGU-MIN")))
3304 (return (list a b))))
3305
3306@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3307@end example
3308
3309@end deffn
3310
e87f0591
LC
3311The @code{(guix packages)} module exports the following package-related
3312monadic procedures:
3313
b860f382 3314@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4231f05b
LC
3315 [#:system (%current-system)] [#:target #f] @
3316 [#:output "out"] Return as a monadic
b860f382
LC
3317value in the absolute file name of @var{file} within the @var{output}
3318directory of @var{package}. When @var{file} is omitted, return the name
4231f05b
LC
3319of the @var{output} directory of @var{package}. When @var{target} is
3320true, use it as a cross-compilation target triplet.
b860f382
LC
3321@end deffn
3322
b860f382 3323@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4231f05b
LC
3324@deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3325 @var{target} [@var{system}]
3326Monadic version of @code{package-derivation} and
3327@code{package-cross-derivation} (@pxref{Defining Packages}).
b860f382
LC
3328@end deffn
3329
3330
21b679f6
LC
3331@node G-Expressions
3332@section G-Expressions
3333
3334@cindex G-expression
3335@cindex build code quoting
3336So we have ``derivations'', which represent a sequence of build actions
3337to be performed to produce an item in the store (@pxref{Derivations}).
3338Those build actions are performed when asking the daemon to actually
3339build the derivations; they are run by the daemon in a container
3340(@pxref{Invoking guix-daemon}).
3341
3342@cindex strata of code
3343It should come as no surprise that we like to write those build actions
3344in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3345code@footnote{The term @dfn{stratum} in this context was coined by
ef4ab0a4
LC
3346Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3347Kiselyov, who has written insightful
3348@url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3349on this topic}, refers to this kind of code generation as
3350@dfn{staging}.}: the ``host code''---code that defines packages, talks
3351to the daemon, etc.---and the ``build code''---code that actually
3352performs build actions, such as making directories, invoking
3353@command{make}, etc.
21b679f6
LC
3354
3355To describe a derivation and its build actions, one typically needs to
3356embed build code inside host code. It boils down to manipulating build
3357code as data, and Scheme's homoiconicity---code has a direct
3358representation as data---comes in handy for that. But we need more than
3359Scheme's normal @code{quasiquote} mechanism to construct build
3360expressions.
3361
3362The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3363S-expressions adapted to build expressions. G-expressions, or
3364@dfn{gexps}, consist essentially in three syntactic forms: @code{gexp},
3365@code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
3366@code{#$}, and @code{#$@@}), which are comparable respectively to
3367@code{quasiquote}, @code{unquote}, and @code{unquote-splicing}
3368(@pxref{Expression Syntax, @code{quasiquote},, guile, GNU Guile
3369Reference Manual}). However, there are major differences:
3370
3371@itemize
3372@item
3373Gexps are meant to be written to a file and run or manipulated by other
3374processes.
3375
3376@item
b39fc6f7
LC
3377When a high-level object such as a package or derivation is unquoted
3378inside a gexp, the result is as if its output file name had been
3379introduced.
ff40e9b7 3380
21b679f6
LC
3381@item
3382Gexps carry information about the packages or derivations they refer to,
3383and these dependencies are automatically added as inputs to the build
3384processes that use them.
3385@end itemize
3386
c2b84676 3387@cindex lowering, of high-level objects in gexps
343eacbe
LC
3388This mechanism is not limited to package and derivation
3389objects: @dfn{compilers} able to ``lower'' other high-level objects to
c2b84676
LC
3390derivations or files in the store can be defined,
3391such that these objects can also be inserted
343eacbe
LC
3392into gexps. For example, a useful type of high-level object that can be
3393inserted in a gexp is ``file-like objects'', which make it easy to
3394add files to the store and refer to them in
558e8b11
LC
3395derivations and such (see @code{local-file} and @code{plain-file}
3396below.)
b39fc6f7 3397
21b679f6
LC
3398To illustrate the idea, here is an example of a gexp:
3399
3400@example
3401(define build-exp
3402 #~(begin
3403 (mkdir #$output)
3404 (chdir #$output)
aff8ce7c 3405 (symlink (string-append #$coreutils "/bin/ls")
21b679f6
LC
3406 "list-files")))
3407@end example
3408
3409This gexp can be passed to @code{gexp->derivation}; we obtain a
3410derivation that builds a directory containing exactly one symlink to
3411@file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3412
3413@example
3414(gexp->derivation "the-thing" build-exp)
3415@end example
3416
e20fd1bf 3417As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
21b679f6
LC
3418substituted to the reference to the @var{coreutils} package in the
3419actual build code, and @var{coreutils} is automatically made an input to
3420the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
3421output)}) is replaced by a string containing the derivation's output
667b2508
LC
3422directory name.
3423
3424@cindex cross compilation
3425In a cross-compilation context, it is useful to distinguish between
3426references to the @emph{native} build of a package---that can run on the
3427host---versus references to cross builds of a package. To that end, the
3428@code{#+} plays the same role as @code{#$}, but is a reference to a
3429native package build:
3430
3431@example
3432(gexp->derivation "vi"
3433 #~(begin
3434 (mkdir #$output)
3435 (system* (string-append #+coreutils "/bin/ln")
3436 "-s"
3437 (string-append #$emacs "/bin/emacs")
3438 (string-append #$output "/bin/vi")))
3439 #:target "mips64el-linux")
3440@end example
3441
3442@noindent
3443In the example above, the native build of @var{coreutils} is used, so
3444that @command{ln} can actually run on the host; but then the
3445cross-compiled build of @var{emacs} is referenced.
3446
3447The syntactic form to construct gexps is summarized below.
21b679f6
LC
3448
3449@deffn {Scheme Syntax} #~@var{exp}
3450@deffnx {Scheme Syntax} (gexp @var{exp})
3451Return a G-expression containing @var{exp}. @var{exp} may contain one
3452or more of the following forms:
3453
3454@table @code
3455@item #$@var{obj}
3456@itemx (ungexp @var{obj})
b39fc6f7
LC
3457Introduce a reference to @var{obj}. @var{obj} may have one of the
3458supported types, for example a package or a
21b679f6
LC
3459derivation, in which case the @code{ungexp} form is replaced by its
3460output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
3461
b39fc6f7
LC
3462If @var{obj} is a list, it is traversed and references to supported
3463objects are substituted similarly.
21b679f6
LC
3464
3465If @var{obj} is another gexp, its contents are inserted and its
3466dependencies are added to those of the containing gexp.
3467
3468If @var{obj} is another kind of object, it is inserted as is.
3469
b39fc6f7
LC
3470@item #$@var{obj}:@var{output}
3471@itemx (ungexp @var{obj} @var{output})
21b679f6 3472This is like the form above, but referring explicitly to the
b39fc6f7
LC
3473@var{output} of @var{obj}---this is useful when @var{obj} produces
3474multiple outputs (@pxref{Packages with Multiple Outputs}).
21b679f6 3475
667b2508
LC
3476@item #+@var{obj}
3477@itemx #+@var{obj}:output
3478@itemx (ungexp-native @var{obj})
3479@itemx (ungexp-native @var{obj} @var{output})
3480Same as @code{ungexp}, but produces a reference to the @emph{native}
3481build of @var{obj} when used in a cross compilation context.
3482
21b679f6
LC
3483@item #$output[:@var{output}]
3484@itemx (ungexp output [@var{output}])
3485Insert a reference to derivation output @var{output}, or to the main
3486output when @var{output} is omitted.
3487
3488This only makes sense for gexps passed to @code{gexp->derivation}.
3489
3490@item #$@@@var{lst}
3491@itemx (ungexp-splicing @var{lst})
3492Like the above, but splices the contents of @var{lst} inside the
3493containing list.
3494
667b2508
LC
3495@item #+@@@var{lst}
3496@itemx (ungexp-native-splicing @var{lst})
3497Like the above, but refers to native builds of the objects listed in
3498@var{lst}.
3499
21b679f6
LC
3500@end table
3501
3502G-expressions created by @code{gexp} or @code{#~} are run-time objects
3503of the @code{gexp?} type (see below.)
3504@end deffn
3505
3506@deffn {Scheme Procedure} gexp? @var{obj}
3507Return @code{#t} if @var{obj} is a G-expression.
3508@end deffn
3509
3510G-expressions are meant to be written to disk, either as code building
3511some derivation, or as plain files in the store. The monadic procedures
3512below allow you to do that (@pxref{The Store Monad}, for more
3513information about monads.)
3514
3515@deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
ce45eb4c 3516 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
21b679f6
LC
3517 [#:hash #f] [#:hash-algo #f] @
3518 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4684f301 3519 [#:module-path @var{%load-path}] @
c8351d9a 3520 [#:references-graphs #f] [#:allowed-references #f] @
c0468155 3521 [#:leaked-env-vars #f] @
0309e1b0 3522 [#:script-name (string-append @var{name} "-builder")] @
4a6aeb67 3523 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
21b679f6 3524Return a derivation @var{name} that runs @var{exp} (a gexp) with
0309e1b0
LC
3525@var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
3526stored in a file called @var{script-name}. When @var{target} is true,
3527it is used as the cross-compilation target triplet for packages referred
3528to by @var{exp}.
21b679f6 3529
ce45eb4c
LC
3530Make @var{modules} available in the evaluation context of @var{exp};
3531@var{modules} is a list of names of Guile modules searched in
3532@var{module-path} to be copied in the store, compiled, and made available in
21b679f6
LC
3533the load path during the execution of @var{exp}---e.g., @code{((guix
3534build utils) (guix build gnu-build-system))}.
3535
ce45eb4c
LC
3536@var{graft?} determines whether packages referred to by @var{exp} should be grafted when
3537applicable.
3538
b53833b2
LC
3539When @var{references-graphs} is true, it must be a list of tuples of one of the
3540following forms:
3541
3542@example
3543(@var{file-name} @var{package})
3544(@var{file-name} @var{package} @var{output})
3545(@var{file-name} @var{derivation})
3546(@var{file-name} @var{derivation} @var{output})
3547(@var{file-name} @var{store-item})
3548@end example
3549
3550The right-hand-side of each element of @var{references-graphs} is automatically made
3551an input of the build process of @var{exp}. In the build environment, each
3552@var{file-name} contains the reference graph of the corresponding item, in a simple
3553text format.
3554
c8351d9a
LC
3555@var{allowed-references} must be either @code{#f} or a list of output names and packages.
3556In the latter case, the list denotes store items that the result is allowed to
3557refer to. Any reference to another store item will lead to a build error.
3558
e20fd1bf 3559The other arguments are as for @code{derivation} (@pxref{Derivations}).
21b679f6
LC
3560@end deffn
3561
343eacbe 3562@cindex file-like objects
e1c153e0
LC
3563The @code{local-file}, @code{plain-file}, @code{computed-file},
3564@code{program-file}, and @code{scheme-file} procedures below return
3565@dfn{file-like objects}. That is, when unquoted in a G-expression,
3566these objects lead to a file in the store. Consider this G-expression:
343eacbe
LC
3567
3568@example
3569#~(system* (string-append #$glibc "/sbin/nscd") "-f"
3570 #$(local-file "/tmp/my-nscd.conf"))
3571@end example
3572
3573The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
3574to the store. Once expanded, for instance @i{via}
3575@code{gexp->derivation}, the G-expression refers to that copy under
3576@file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
3577does not have any effect on what the G-expression does.
3578@code{plain-file} can be used similarly; it differs in that the file
3579content is directly passed as a string.
3580
d9ae938f
LC
3581@deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
3582 [#:recursive? #t]
3583Return an object representing local file @var{file} to add to the store; this
9d3994f7
LC
3584object can be used in a gexp. If @var{file} is a relative file name, it is looked
3585up relative to the source file where this form appears. @var{file} will be added to
3586the store under @var{name}--by default the base name of @var{file}.
d9ae938f
LC
3587
3588When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
3589designates a flat file and @var{recursive?} is true, its contents are added, and its
3590permission bits are kept.
3591
3592This is the declarative counterpart of the @code{interned-file} monadic
3593procedure (@pxref{The Store Monad, @code{interned-file}}).
3594@end deffn
3595
558e8b11
LC
3596@deffn {Scheme Procedure} plain-file @var{name} @var{content}
3597Return an object representing a text file called @var{name} with the given
3598@var{content} (a string) to be added to the store.
3599
3600This is the declarative counterpart of @code{text-file}.
3601@end deffn
3602
91937029
LC
3603@deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
3604 [#:modules '()] [#:options '(#:local-build? #t)]
3605Return an object representing the store item @var{name}, a file or
3606directory computed by @var{gexp}. @var{modules} specifies the set of
3607modules visible in the execution context of @var{gexp}. @var{options}
3608is a list of additional arguments to pass to @code{gexp->derivation}.
3609
3610This is the declarative counterpart of @code{gexp->derivation}.
3611@end deffn
3612
21b679f6
LC
3613@deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
3614Return an executable script @var{name} that runs @var{exp} using
3615@var{guile} with @var{modules} in its search path.
3616
3617The example below builds a script that simply invokes the @command{ls}
3618command:
3619
3620@example
3621(use-modules (guix gexp) (gnu packages base))
3622
3623(gexp->script "list-files"
3624 #~(execl (string-append #$coreutils "/bin/ls")
3625 "ls"))
3626@end example
3627
3628When ``running'' it through the store (@pxref{The Store Monad,
e20fd1bf 3629@code{run-with-store}}), we obtain a derivation that produces an
21b679f6
LC
3630executable file @file{/gnu/store/@dots{}-list-files} along these lines:
3631
3632@example
3633#!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
3634!#
3635(execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls")
3636 "ls")
3637@end example
3638@end deffn
3639
15a01c72
LC
3640@deffn {Scheme Procedure} program-file @var{name} @var{exp} @
3641 [#:modules '()] [#:guile #f]
3642Return an object representing the executable store item @var{name} that
3643runs @var{gexp}. @var{guile} is the Guile package used to execute that
3644script, and @var{modules} is the list of modules visible to that script.
3645
3646This is the declarative counterpart of @code{gexp->script}.
3647@end deffn
3648
21b679f6
LC
3649@deffn {Monadic Procedure} gexp->file @var{name} @var{exp}
3650Return a derivation that builds a file @var{name} containing @var{exp}.
3651
3652The resulting file holds references to all the dependencies of @var{exp}
3653or a subset thereof.
3654@end deffn
1ed19464 3655
e1c153e0
LC
3656@deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
3657Return an object representing the Scheme file @var{name} that contains
3658@var{exp}.
3659
3660This is the declarative counterpart of @code{gexp->file}.
3661@end deffn
3662
1ed19464
LC
3663@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
3664Return as a monadic value a derivation that builds a text file
3665containing all of @var{text}. @var{text} may list, in addition to
d9ae938f
LC
3666strings, objects of any type that can be used in a gexp: packages,
3667derivations, local file objects, etc. The resulting store file holds
3668references to all these.
1ed19464
LC
3669
3670This variant should be preferred over @code{text-file} anytime the file
3671to create will reference items from the store. This is typically the
3672case when building a configuration file that embeds store file names,
3673like this:
3674
3675@example
3676(define (profile.sh)
3677 ;; Return the name of a shell script in the store that
3678 ;; initializes the 'PATH' environment variable.
3679 (text-file* "profile.sh"
3680 "export PATH=" coreutils "/bin:"
3681 grep "/bin:" sed "/bin\n"))
3682@end example
3683
3684In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
3685will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
3686preventing them from being garbage-collected during its lifetime.
3687@end deffn
21b679f6 3688
b751cde3
LC
3689@deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
3690Return an object representing store file @var{name} containing
3691@var{text}. @var{text} is a sequence of strings and file-like objects,
3692as in:
3693
3694@example
3695(mixed-text-file "profile"
3696 "export PATH=" coreutils "/bin:" grep "/bin")
3697@end example
3698
3699This is the declarative counterpart of @code{text-file*}.
3700@end deffn
3701
21b679f6
LC
3702Of course, in addition to gexps embedded in ``host'' code, there are
3703also modules containing build tools. To make it clear that they are
3704meant to be used in the build stratum, these modules are kept in the
3705@code{(guix build @dots{})} name space.
3706
c2b84676
LC
3707@cindex lowering, of high-level objects in gexps
3708Internally, high-level objects are @dfn{lowered}, using their compiler,
3709to either derivations or store items. For instance, lowering a package
3710yields a derivation, and lowering a @code{plain-file} yields a store
3711item. This is achieved using the @code{lower-object} monadic procedure.
3712
3713@deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
3714 [#:target #f]
3715Return as a value in @var{%store-monad} the derivation or store item
3716corresponding to @var{obj} for @var{system}, cross-compiling for
3717@var{target} if @var{target} is true. @var{obj} must be an object that
3718has an associated gexp compiler, such as a @code{<package>}.
3719@end deffn
3720
21b679f6 3721
568717fd
LC
3722@c *********************************************************************
3723@node Utilities
3724@chapter Utilities
3725
210cc920
LC
3726This section describes tools primarily targeted at developers and users
3727who write new package definitions. They complement the Scheme
3728programming interface of Guix in a convenient way.
3729
568717fd 3730@menu
37166310 3731* Invoking guix build:: Building packages from the command line.
39bee8a2 3732* Invoking guix edit:: Editing package definitions.
210cc920 3733* Invoking guix download:: Downloading a file and printing its hash.
37166310 3734* Invoking guix hash:: Computing the cryptographic hash of a file.
2f7d2d91 3735* Invoking guix import:: Importing package definitions.
37166310 3736* Invoking guix refresh:: Updating package definitions.
b4f5e0e8 3737* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 3738* Invoking guix size:: Profiling disk usage.
88856916 3739* Invoking guix graph:: Visualizing the graph of packages.
372c4bbc 3740* Invoking guix environment:: Setting up development environments.
aff8ce7c 3741* Invoking guix publish:: Sharing substitutes.
d23c20f1 3742* Invoking guix challenge:: Challenging substitute servers.
32efa254 3743* Invoking guix container:: Process isolation.
568717fd
LC
3744@end menu
3745
e49951eb
MW
3746@node Invoking guix build
3747@section Invoking @command{guix build}
568717fd 3748
e49951eb 3749The @command{guix build} command builds packages or derivations and
6798a8e4
LC
3750their dependencies, and prints the resulting store paths. Note that it
3751does not modify the user's profile---this is the job of the
e49951eb 3752@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
3753it is mainly useful for distribution developers.
3754
3755The general syntax is:
c78bd12b
LC
3756
3757@example
e49951eb 3758guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
3759@end example
3760
3761@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
3762the software distribution such as @code{coreutils} or
3763@code{coreutils-8.20}, or a derivation such as
834129e0 3764@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
3765package with the corresponding name (and optionally version) is searched
3766for among the GNU distribution modules (@pxref{Package Modules}).
3767
3768Alternatively, the @code{--expression} option may be used to specify a
3769Scheme expression that evaluates to a package; this is useful when
3770disambiguation among several same-named packages or package variants is
3771needed.
c78bd12b
LC
3772
3773The @var{options} may be zero or more of the following:
3774
3775@table @code
3776
34a1783f
DT
3777@item --file=@var{file}
3778@itemx -f @var{file}
3779
3780Build the package or derivation that the code within @var{file}
3781evaluates to.
3782
3783As an example, @var{file} might contain a package definition like this
3784(@pxref{Defining Packages}):
3785
3786@example
3787@verbatiminclude package-hello.scm
3788@end example
3789
c78bd12b
LC
3790@item --expression=@var{expr}
3791@itemx -e @var{expr}
ac5de156 3792Build the package or derivation @var{expr} evaluates to.
c78bd12b 3793
5401dd75 3794For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
3795guile-1.8)}, which unambiguously designates this specific variant of
3796version 1.8 of Guile.
3797
56b82106
LC
3798Alternately, @var{expr} may be a G-expression, in which case it is used
3799as a build program passed to @code{gexp->derivation}
3800(@pxref{G-Expressions}).
3801
3802Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
3803(@pxref{The Store Monad}). The procedure must return a derivation as a
3804monadic value, which is then passed through @code{run-with-store}.
3805
c78bd12b
LC
3806@item --source
3807@itemx -S
3808Build the packages' source derivations, rather than the packages
3809themselves.
3810
e49951eb 3811For instance, @code{guix build -S gcc} returns something like
834129e0 3812@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
c78bd12b 3813
f9cc8971
LC
3814The returned source tarball is the result of applying any patches and
3815code snippets specified in the package's @code{origin} (@pxref{Defining
3816Packages}).
3817
2cdfe13d
EB
3818@item --sources
3819Fetch and return the source of @var{package-or-derivation} and all their
3820dependencies, recursively. This is a handy way to obtain a local copy
3821of all the source code needed to build @var{packages}, allowing you to
3822eventually build them even without network access. It is an extension
3823of the @code{--source} option and can accept one of the following
3824optional argument values:
3825
3826@table @code
3827@item package
3828This value causes the @code{--sources} option to behave in the same way
3829as the @code{--source} option.
3830
3831@item all
3832Build all packages' source derivations, including any source that might
3833be listed as @code{inputs}. This is the default value.
3834
3835@example
3836$ guix build --sources tzdata
3837The following derivations will be built:
3838 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
3839 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
3840@end example
3841
3842@item transitive
3843Build all packages' source derivations, as well as all source
3844derivations for packages' transitive inputs. This can be used e.g. to
3845prefetch package source for later offline building.
3846
3847@example
3848$ guix build --sources=transitive tzdata
3849The following derivations will be built:
3850 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
3851 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
3852 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
3853 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
3854 /gnu/store/@dots{}-make-4.1.tar.xz.drv
3855 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
3856@dots{}
3857@end example
3858
3859@end table
3860
c78bd12b
LC
3861@item --system=@var{system}
3862@itemx -s @var{system}
3863Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
3864the host's system type.
3865
3866An example use of this is on Linux-based systems, which can emulate
3867different personalities. For instance, passing
3868@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
3869to build packages in a complete 32-bit environment.
3870
e55ec43d
LC
3871@item --target=@var{triplet}
3872@cindex cross-compilation
3873Cross-build for @var{triplet}, which must be a valid GNU triplet, such
3874as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
3875configuration triplets,, configure, GNU Configure and Build System}).
3876
7f3673f2
LC
3877@item --with-source=@var{source}
3878Use @var{source} as the source of the corresponding package.
3879@var{source} must be a file name or a URL, as for @command{guix
3880download} (@pxref{Invoking guix download}).
3881
3882The ``corresponding package'' is taken to be one specified on the
3883command line whose name matches the base of @var{source}---e.g., if
3884@var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
3885package is @code{guile}. Likewise, the version string is inferred from
3886@var{source}; in the previous example, it's @code{2.0.10}.
3887
3888This option allows users to try out versions of packages other than the
3889one provided by the distribution. The example below downloads
3890@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
3891the @code{ed} package:
3892
3893@example
3894guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
3895@end example
3896
3897As a developer, @code{--with-source} makes it easy to test release
3898candidates:
3899
3900@example
3901guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
3902@end example
3903
a43b55f1
LC
3904@dots{} or to build from a checkout in a pristine environment:
3905
3906@example
3907$ git clone git://git.sv.gnu.org/guix.git
3908$ guix build guix --with-source=./guix
3909@end example
3910
a8d65643
LC
3911@anchor{build-check}
3912@item --check
3913@cindex determinism, checking
3914@cindex reproducibility, checking
3915Rebuild @var{package-or-derivation}, which are already available in the
3916store, and raise an error if the build results are not bit-for-bit
3917identical.
3918
3919This mechanism allows you to check whether previously-installed
3920substitutes are genuine (@pxref{Substitutes}), or whether a package's
3921build result is deterministic. @xref{Invoking guix challenge}, for more
3922background information and tools.
3923
05962f29
LC
3924@item --no-grafts
3925Do not ``graft'' packages. In practice, this means that package updates
3926available as grafts are not applied. @xref{Security Updates}, for more
3927information on grafts.
7f3673f2 3928
c78bd12b
LC
3929@item --derivations
3930@itemx -d
3931Return the derivation paths, not the output paths, of the given
3932packages.
3933
70ee5642
LC
3934@item --root=@var{file}
3935@itemx -r @var{file}
3936Make @var{file} a symlink to the result, and register it as a garbage
3937collector root.
3938
3939@item --log-file
3f208ad7 3940Return the build log file names or URLs for the given
70ee5642
LC
3941@var{package-or-derivation}s, or raise an error if build logs are
3942missing.
3943
3944This works regardless of how packages or derivations are specified. For
3945instance, the following invocations are equivalent:
3946
3947@example
3948guix build --log-file `guix build -d guile`
3949guix build --log-file `guix build guile`
3950guix build --log-file guile
3951guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
3952@end example
3953
3f208ad7
LC
3954If a log is unavailable locally, and unless @code{--no-substitutes} is
3955passed, the command looks for a corresponding log on one of the
3956substitute servers (as specified with @code{--substitute-urls}.)
70ee5642 3957
3f208ad7
LC
3958So for instance, let's say you want to see the build log of GDB on MIPS
3959but you're actually on an @code{x86_64} machine:
3960
3961@example
3962$ guix build --log-file gdb -s mips64el-linux
3963http://hydra.gnu.org/log/@dots{}-gdb-7.10
3964@end example
3965
3966You can freely access a huge library of build logs!
70ee5642
LC
3967@end table
3968
3969@cindex common build options
3970In addition, a number of options that control the build process are
3971common to @command{guix build} and other commands that can spawn builds,
3972such as @command{guix package} or @command{guix archive}. These are the
3973following:
3974
3975@table @code
3976
300868ba
LC
3977@item --load-path=@var{directory}
3978@itemx -L @var{directory}
3979Add @var{directory} to the front of the package module search path
3980(@pxref{Package Modules}).
3981
3982This allows users to define their own packages and make them visible to
3983the command-line tools.
3984
c78bd12b
LC
3985@item --keep-failed
3986@itemx -K
3987Keep the build tree of failed builds. Thus, if a build fail, its build
3988tree is kept under @file{/tmp}, in a directory whose name is shown at
3989the end of the build log. This is useful when debugging build issues.
3990
f4953019
LC
3991@item --keep-going
3992@itemx -k
3993Keep going when some of the derivations fail to build; return only once
3994all the builds have either completed or failed.
3995
3996The default behavior is to stop as soon as one of the specified
3997derivations has failed.
3998
c78bd12b
LC
3999@item --dry-run
4000@itemx -n
4001Do not build the derivations.
4002
56b1f4b7
LC
4003@item --fallback
4004When substituting a pre-built binary fails, fall back to building
4005packages locally.
4006
f8a8e0fe
LC
4007@item --substitute-urls=@var{urls}
4008@anchor{client-substitute-urls}
4009Consider @var{urls} the whitespace-separated list of substitute source
4010URLs, overriding the default list of URLs of @command{guix-daemon}
4011(@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
4012
4013This means that substitutes may be downloaded from @var{urls}, provided
4014they are signed by a key authorized by the system administrator
4015(@pxref{Substitutes}).
4016
c78bd12b 4017@item --no-substitutes
b5385b52 4018Do not use substitutes for build products. That is, always build things
c4202d60
LC
4019locally instead of allowing downloads of pre-built binaries
4020(@pxref{Substitutes}).
c78bd12b 4021
5b74fe06
LC
4022@item --rounds=@var{n}
4023Build each derivation @var{n} times in a row, and raise an error if
4024consecutive build results are not bit-for-bit identical.
4025
4026This is a useful way to detect non-deterministic builds processes.
4027Non-deterministic build processes are a problem because they make it
4028practically impossible for users to @emph{verify} whether third-party
4029binaries are genuine. @xref{Invoking guix challenge}, for more.
4030
4031Note that, currently, the differing build results are not kept around,
4032so you will have to manually investigate in case of an error---e.g., by
4033stashing one of the build results with @code{guix archive --export},
4034then rebuilding, and finally comparing the two results.
4035
425b0bfc 4036@item --no-build-hook
4ec2e92d
LC
4037Do not attempt to offload builds @i{via} the daemon's ``build hook''
4038(@pxref{Daemon Offload Setup}). That is, always build things locally
4039instead of offloading builds to remote machines.
425b0bfc 4040
969e678e
LC
4041@item --max-silent-time=@var{seconds}
4042When the build or substitution process remains silent for more than
4043@var{seconds}, terminate it and report a build failure.
4044
002622b6
LC
4045@item --timeout=@var{seconds}
4046Likewise, when the build or substitution process lasts for more than
4047@var{seconds}, terminate it and report a build failure.
4048
4049By default there is no timeout. This behavior can be restored with
4050@code{--timeout=0}.
4051
07ab4bf1
LC
4052@item --verbosity=@var{level}
4053Use the given verbosity level. @var{level} must be an integer between 0
4054and 5; higher means more verbose output. Setting a level of 4 or more
4055may be helpful when debugging setup issues with the build daemon.
4056
70ee5642
LC
4057@item --cores=@var{n}
4058@itemx -c @var{n}
4059Allow the use of up to @var{n} CPU cores for the build. The special
4060value @code{0} means to use as many CPU cores as available.
bf421152 4061
f6526eb3
LC
4062@item --max-jobs=@var{n}
4063@itemx -M @var{n}
4064Allow at most @var{n} build jobs in parallel. @xref{Invoking
4065guix-daemon, @code{--max-jobs}}, for details about this option and the
4066equivalent @command{guix-daemon} option.
4067
c78bd12b
LC
4068@end table
4069
e49951eb 4070Behind the scenes, @command{guix build} is essentially an interface to
c78bd12b
LC
4071the @code{package-derivation} procedure of the @code{(guix packages)}
4072module, and to the @code{build-derivations} procedure of the @code{(guix
01d8ac64 4073derivations)} module.
c78bd12b 4074
16eb115e
DP
4075In addition to options explicitly passed on the command line,
4076@command{guix build} and other @command{guix} commands that support
4077building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
4078
4079@defvr {Environment Variable} GUIX_BUILD_OPTIONS
4080Users can define this variable to a list of command line options that
4081will automatically be used by @command{guix build} and other
4082@command{guix} commands that can perform builds, as in the example
4083below:
4084
4085@example
4086$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
4087@end example
4088
847391fe
DP
4089These options are parsed independently, and the result is appended to
4090the parsed command-line options.
16eb115e
DP
4091@end defvr
4092
4093
39bee8a2
LC
4094@node Invoking guix edit
4095@section Invoking @command{guix edit}
4096
4097@cindex package definition, editing
4098So many packages, so many source files! The @command{guix edit} command
4099facilitates the life of packagers by pointing their editor at the source
4100file containing the definition of the specified packages. For instance:
4101
4102@example
4103guix edit gcc-4.8 vim
4104@end example
4105
4106@noindent
6237b9fa
LC
4107launches the program specified in the @code{VISUAL} or in the
4108@code{EDITOR} environment variable to edit the recipe of GCC@tie{}4.8.4
4109and that of Vim.
39bee8a2
LC
4110
4111If you are using Emacs, note that the Emacs user interface provides
6248e326
AK
4112similar functionality in the ``package info'' and ``package list''
4113buffers created by @kbd{M-x guix-search-by-name} and similar commands
4114(@pxref{Emacs Commands}).
39bee8a2
LC
4115
4116
210cc920
LC
4117@node Invoking guix download
4118@section Invoking @command{guix download}
4119
4120When writing a package definition, developers typically need to download
4121the package's source tarball, compute its SHA256 hash, and write that
4122hash in the package definition (@pxref{Defining Packages}). The
4123@command{guix download} tool helps with this task: it downloads a file
4124from the given URI, adds it to the store, and prints both its file name
4125in the store and its SHA256 hash.
4126
4127The fact that the downloaded file is added to the store saves bandwidth:
4128when the developer eventually tries to build the newly defined package
4129with @command{guix build}, the source tarball will not have to be
4130downloaded again because it is already in the store. It is also a
4131convenient way to temporarily stash files, which may be deleted
4132eventually (@pxref{Invoking guix gc}).
4133
4134The @command{guix download} command supports the same URIs as used in
4135package definitions. In particular, it supports @code{mirror://} URIs.
4136@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
4137Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
4138they are not available, an error is raised. @xref{Guile Preparations,
4139how to install the GnuTLS bindings for Guile,, gnutls-guile,
4140GnuTLS-Guile}, for more information.
210cc920
LC
4141
4142The following option is available:
4143
4144@table @code
4145@item --format=@var{fmt}
4146@itemx -f @var{fmt}
4147Write the hash in the format specified by @var{fmt}. For more
081145cf 4148information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
210cc920
LC
4149@end table
4150
6c365eca
NK
4151@node Invoking guix hash
4152@section Invoking @command{guix hash}
4153
210cc920 4154The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
4155It is primarily a convenience tool for anyone contributing to the
4156distribution: it computes the cryptographic hash of a file, which can be
4157used in the definition of a package (@pxref{Defining Packages}).
4158
4159The general syntax is:
4160
4161@example
4162guix hash @var{option} @var{file}
4163@end example
4164
4165@command{guix hash} has the following option:
4166
4167@table @code
4168
4169@item --format=@var{fmt}
4170@itemx -f @var{fmt}
210cc920 4171Write the hash in the format specified by @var{fmt}.
6c365eca
NK
4172
4173Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4174(@code{hex} and @code{hexadecimal} can be used as well).
4175
4176If the @option{--format} option is not specified, @command{guix hash}
4177will output the hash in @code{nix-base32}. This representation is used
4178in the definitions of packages.
4179
3140f2df
LC
4180@item --recursive
4181@itemx -r
4182Compute the hash on @var{file} recursively.
4183
4184In this case, the hash is computed on an archive containing @var{file},
4185including its children if it is a directory. Some of @var{file}'s
4186meta-data is part of the archive; for instance, when @var{file} is a
4187regular file, the hash is different depending on whether @var{file} is
4188executable or not. Meta-data such as time stamps has no impact on the
4189hash (@pxref{Invoking guix archive}).
4190@c FIXME: Replace xref above with xref to an ``Archive'' section when
4191@c it exists.
4192
6c365eca
NK
4193@end table
4194
2f7d2d91
LC
4195@node Invoking guix import
4196@section Invoking @command{guix import}
4197
4198@cindex importing packages
4199@cindex package import
4200@cindex package conversion
4201The @command{guix import} command is useful for people willing to add a
4202package to the distribution but who'd rather do as little work as
4203possible to get there---a legitimate demand. The command knows of a few
4204repositories from which it can ``import'' package meta-data. The result
4205is a package definition, or a template thereof, in the format we know
4206(@pxref{Defining Packages}).
4207
4208The general syntax is:
4209
4210@example
4211guix import @var{importer} @var{options}@dots{}
4212@end example
4213
4214@var{importer} specifies the source from which to import package
4215meta-data, and @var{options} specifies a package identifier and other
4216options specific to @var{importer}. Currently, the available
4217``importers'' are:
4218
4219@table @code
4220@item gnu
4221Import meta-data for the given GNU package. This provides a template
4222for the latest version of that GNU package, including the hash of its
4223source tarball, and its canonical synopsis and description.
4224
4225Additional information such as the package's dependencies and its
4226license needs to be figured out manually.
4227
4228For example, the following command returns a package definition for
4229GNU@tie{}Hello:
4230
4231@example
4232guix import gnu hello
4233@end example
4234
4235Specific command-line options are:
4236
4237@table @code
4238@item --key-download=@var{policy}
4239As for @code{guix refresh}, specify the policy to handle missing OpenPGP
4240keys when verifying the package's signature. @xref{Invoking guix
4241refresh, @code{--key-download}}.
4242@end table
4243
4244@item pypi
4245@cindex pypi
4246Import meta-data from the @uref{https://pypi.python.org/, Python Package
4247Index}@footnote{This functionality requires Guile-JSON to be installed.
4248@xref{Requirements}.}. Information is taken from the JSON-formatted
4249description available at @code{pypi.python.org} and usually includes all
4250the relevant information, including package dependencies.
4251
4252The command below imports meta-data for the @code{itsdangerous} Python
4253package:
4254
4255@example
4256guix import pypi itsdangerous
4257@end example
4258
3aae8145
DT
4259@item gem
4260@cindex gem
4261Import meta-data from @uref{https://rubygems.org/,
4262RubyGems}@footnote{This functionality requires Guile-JSON to be
4263installed. @xref{Requirements}.}. Information is taken from the
4264JSON-formatted description available at @code{rubygems.org} and includes
4265most relevant information, including runtime dependencies. There are
4266some caveats, however. The meta-data doesn't distinguish between
4267synopses and descriptions, so the same string is used for both fields.
4268Additionally, the details of non-Ruby dependencies required to build
4269native extensions is unavailable and left as an exercise to the
4270packager.
4271
4272The command below imports meta-data for the @code{rails} Ruby package:
4273
4274@example
4275guix import gem rails
4276@end example
4277
d45dc6da
EB
4278@item cpan
4279@cindex CPAN
4280Import meta-data from @uref{https://www.metacpan.org/, MetaCPAN}.
4281Information is taken from the JSON-formatted meta-data provided through
4282@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
4283relevant information, such as module dependencies. License information
4284should be checked closely. If Perl is available in the store, then the
4285@code{corelist} utility will be used to filter core modules out of the
4286list of dependencies.
d45dc6da
EB
4287
4288The command command below imports meta-data for the @code{Acme::Boolean}
4289Perl module:
4290
4291@example
4292guix import cpan Acme::Boolean
4293@end example
4294
e1248602
RW
4295@item cran
4296@cindex CRAN
d0bd632f 4297@cindex Bioconductor
e1248602
RW
4298Import meta-data from @uref{http://cran.r-project.org/, CRAN}, the
4299central repository for the @uref{http://r-project.org, GNU@tie{}R
4300statistical and graphical environment}.
4301
d0bd632f 4302Information is extracted from the package's @code{DESCRIPTION} file.
e1248602
RW
4303
4304The command command below imports meta-data for the @code{Cairo}
4305R package:
4306
4307@example
4308guix import cran Cairo
4309@end example
4310
d0bd632f
RW
4311When @code{--archive=bioconductor} is added, meta-data is imported from
4312@uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
4313packages for for the analysis and comprehension of high-throughput
4314genomic data in bioinformatics.
4315
4316Information is extracted from a package's @code{DESCRIPTION} file
4317published on the web interface of the Bioconductor SVN repository.
4318
4319The command command below imports meta-data for the @code{GenomicRanges}
4320R package:
4321
4322@example
4323guix import cran --archive=bioconductor GenomicRanges
4324@end example
4325
2f7d2d91
LC
4326@item nix
4327Import meta-data from a local copy of the source of the
4328@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
4329relies on the @command{nix-instantiate} command of
4330@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
4331typically written in a mixture of Nix-language and Bash code. This
4332command only imports the high-level package structure that is written in
4333the Nix language. It normally includes all the basic fields of a
4334package definition.
4335
4336When importing a GNU package, the synopsis and descriptions are replaced
4337by their canonical upstream variant.
4338
961d0d2d
LC
4339Usually, you will first need to do:
4340
4341@example
4342export NIX_REMOTE=daemon
4343@end example
4344
4345@noindent
4346so that @command{nix-instantiate} does not try to open the Nix database.
4347
2f7d2d91
LC
4348As an example, the command below imports the package definition of
4349LibreOffice (more precisely, it imports the definition of the package
4350bound to the @code{libreoffice} top-level attribute):
4351
4352@example
4353guix import nix ~/path/to/nixpkgs libreoffice
4354@end example
863af4e1
FB
4355
4356@item hackage
4357@cindex hackage
4358Import meta-data from Haskell community's central package archive
4359@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4360Cabal files and includes all the relevant information, including package
4361dependencies.
4362
4363Specific command-line options are:
4364
4365@table @code
a4154748
FB
4366@item --stdin
4367@itemx -s
4368Read a Cabal file from the standard input.
863af4e1
FB
4369@item --no-test-dependencies
4370@itemx -t
a4154748
FB
4371Do not include dependencies required by the test suites only.
4372@item --cabal-environment=@var{alist}
4373@itemx -e @var{alist}
4374@var{alist} is a Scheme alist defining the environment in which the
4375Cabal conditionals are evaluated. The accepted keys are: @code{os},
4376@code{arch}, @code{impl} and a string representing the name of a flag.
4377The value associated with a flag has to be either the symbol
4378@code{true} or @code{false}. The value associated with other keys
4379has to conform to the Cabal file format definition. The default value
4380associated with the keys @code{os}, @code{arch} and @code{impl} is
4381@samp{linux}, @samp{x86_64} and @samp{ghc} respectively.
863af4e1
FB
4382@end table
4383
4384The command below imports meta-data for the latest version of the
a4154748
FB
4385@code{HTTP} Haskell package without including test dependencies and
4386specifying the value of the flag @samp{network-uri} as @code{false}:
863af4e1
FB
4387
4388@example
a4154748 4389guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
863af4e1
FB
4390@end example
4391
4392A specific package version may optionally be specified by following the
4393package name by a hyphen and a version number as in the following example:
4394
4395@example
4396guix import hackage mtl-2.1.3.1
4397@end example
7f74a931
FB
4398
4399@item elpa
4400@cindex elpa
4401Import meta-data from an Emacs Lisp Package Archive (ELPA) package
4402repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4403
4404Specific command-line options are:
4405
4406@table @code
4407@item --archive=@var{repo}
4408@itemx -a @var{repo}
4409@var{repo} identifies the archive repository from which to retrieve the
4410information. Currently the supported repositories and their identifiers
4411are:
4412@itemize -
4413@item
840bd1d3 4414@uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7f74a931
FB
4415identifier. This is the default.
4416
4417@item
840bd1d3 4418@uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7f74a931
FB
4419@code{melpa-stable} identifier.
4420
4421@item
840bd1d3 4422@uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7f74a931
FB
4423identifier.
4424@end itemize
4425@end table
2f7d2d91
LC
4426@end table
4427
4428The structure of the @command{guix import} code is modular. It would be
4429useful to have more importers for other package formats, and your help
4430is welcome here (@pxref{Contributing}).
4431
37166310
LC
4432@node Invoking guix refresh
4433@section Invoking @command{guix refresh}
4434
4435The primary audience of the @command{guix refresh} command is developers
4436of the GNU software distribution. By default, it reports any packages
4437provided by the distribution that are outdated compared to the latest
4438upstream version, like this:
4439
4440@example
4441$ guix refresh
4442gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
4443gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
4444@end example
4445
4446It does so by browsing each package's FTP directory and determining the
bcb571cb
LC
4447highest version number of the source tarballs therein. The command
4448knows how to update specific types of packages: GNU packages, ELPA
4449packages, etc.---see the documentation for @option{--type} below. The
4450are many packages, though, for which it lacks a method to determine
4451whether a new upstream release is available. However, the mechanism is
4452extensible, so feel free to get in touch with us to add a new method!
37166310
LC
4453
4454When passed @code{--update}, it modifies distribution source files to
4455update the version numbers and source tarball hashes of those packages'
4456recipes (@pxref{Defining Packages}). This is achieved by downloading
4457each package's latest source tarball and its associated OpenPGP
4458signature, authenticating the downloaded tarball against its signature
4459using @command{gpg}, and finally computing its hash. When the public
4460key used to sign the tarball is missing from the user's keyring, an
4461attempt is made to automatically retrieve it from a public key server;
4462when it's successful, the key is added to the user's keyring; otherwise,
4463@command{guix refresh} reports an error.
4464
4465The following options are supported:
4466
4467@table @code
4468
2d7fc7da
LC
4469@item --expression=@var{expr}
4470@itemx -e @var{expr}
4471Consider the package @var{expr} evaluates to.
4472
4473This is useful to precisely refer to a package, as in this example:
4474
4475@example
4476guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
4477@end example
4478
4479This command lists the dependents of the ``final'' libc (essentially all
4480the packages.)
4481
37166310
LC
4482@item --update
4483@itemx -u
38e16b49
LC
4484Update distribution source files (package recipes) in place. This is
4485usually run from a checkout of the Guix source tree (@pxref{Running
4486Guix Before It Is Installed}):
4487
4488@example
4489$ ./pre-inst-env guix refresh -s non-core
4490@end example
4491
081145cf 4492@xref{Defining Packages}, for more information on package definitions.
37166310
LC
4493
4494@item --select=[@var{subset}]
4495@itemx -s @var{subset}
4496Select all the packages in @var{subset}, one of @code{core} or
4497@code{non-core}.
4498
4499The @code{core} subset refers to all the packages at the core of the
4500distribution---i.e., packages that are used to build ``everything
4501else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
4502changing one of these packages in the distribution entails a rebuild of
4503all the others. Thus, such updates are an inconvenience to users in
4504terms of build time or bandwidth used to achieve the upgrade.
4505
4506The @code{non-core} subset refers to the remaining packages. It is
4507typically useful in cases where an update of the core packages would be
4508inconvenient.
4509
bcb571cb
LC
4510@item --type=@var{updater}
4511@itemx -t @var{updater}
7191adc5
AK
4512Select only packages handled by @var{updater} (may be a comma-separated
4513list of updaters). Currently, @var{updater} may be one of:
bcb571cb
LC
4514
4515@table @code
4516@item gnu
4517the updater for GNU packages;
e80c0f85
LC
4518@item gnome
4519the updater for GNOME packages;
bcb571cb 4520@item elpa
d882c235
LC
4521the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
4522@item cran
b9d044ef 4523the updater for @uref{http://cran.r-project.org/, CRAN} packages;
d0bd632f
RW
4524@item bioconductor
4525the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
bab020d7 4526@item pypi
b9d044ef 4527the updater for @uref{https://pypi.python.org, PyPI} packages.
bcb571cb
LC
4528@end table
4529
4530For instance, the following commands only checks for updates of Emacs
d882c235 4531packages hosted at @code{elpa.gnu.org} and updates of CRAN packages:
bcb571cb
LC
4532
4533@example
7191adc5 4534$ guix refresh --type=elpa,cran
d882c235 4535gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
bcb571cb
LC
4536gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
4537@end example
4538
37166310
LC
4539@end table
4540
4541In addition, @command{guix refresh} can be passed one or more package
4542names, as in this example:
4543
4544@example
38e16b49 4545$ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
37166310
LC
4546@end example
4547
4548@noindent
4549The command above specifically updates the @code{emacs} and
4550@code{idutils} packages. The @code{--select} option would have no
4551effect in this case.
4552
7d193ec3
EB
4553When considering whether to upgrade a package, it is sometimes
4554convenient to know which packages would be affected by the upgrade and
4555should be checked for compatibility. For this the following option may
4556be used when passing @command{guix refresh} one or more package names:
4557
4558@table @code
4559
6ffa706b
AK
4560@item --list-updaters
4561@itemx -L
4562List available updaters and exit (see @option{--type} above.)
4563
7d193ec3
EB
4564@item --list-dependent
4565@itemx -l
4566List top-level dependent packages that would need to be rebuilt as a
4567result of upgrading one or more packages.
4568
4569@end table
4570
4571Be aware that the @code{--list-dependent} option only
4572@emph{approximates} the rebuilds that would be required as a result of
4573an upgrade. More rebuilds might be required under some circumstances.
4574
4575@example
7779ab61
LC
4576$ guix refresh --list-dependent flex
4577Building the following 120 packages would ensure 213 dependent packages are rebuilt:
4578hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
4579@end example
4580
4581The command above lists a set of packages that could be built to check
4582for compatibility with an upgraded @code{flex} package.
4583
f9230085
LC
4584The following options can be used to customize GnuPG operation:
4585
4586@table @code
4587
f9230085
LC
4588@item --gpg=@var{command}
4589Use @var{command} as the GnuPG 2.x command. @var{command} is searched
4590for in @code{$PATH}.
4591
2bc53ba9
LC
4592@item --key-download=@var{policy}
4593Handle missing OpenPGP keys according to @var{policy}, which may be one
4594of:
4595
4596@table @code
4597@item always
4598Always download missing OpenPGP keys from the key server, and add them
4599to the user's GnuPG keyring.
4600
4601@item never
4602Never try to download missing OpenPGP keys. Instead just bail out.
4603
4604@item interactive
4605When a package signed with an unknown OpenPGP key is encountered, ask
4606the user whether to download it or not. This is the default behavior.
4607@end table
4608
4609@item --key-server=@var{host}
4610Use @var{host} as the OpenPGP key server when importing a public key.
4611
f9230085
LC
4612@end table
4613
b4f5e0e8
CR
4614@node Invoking guix lint
4615@section Invoking @command{guix lint}
4616The @command{guix lint} is meant to help package developers avoid common
873c4085
LC
4617errors and use a consistent style. It runs a number of checks on a
4618given set of packages in order to find common mistakes in their
4619definitions. Available @dfn{checkers} include (see
4620@code{--list-checkers} for a complete list):
4621
4622@table @code
4623@item synopsis
4624@itemx description
4625Validate certain typographical and stylistic rules about package
4626descriptions and synopses.
4627
4628@item inputs-should-be-native
4629Identify inputs that should most likely be native inputs.
4630
4631@item source
4632@itemx home-page
50f5c46d 4633@itemx source-file-name
873c4085 4634Probe @code{home-page} and @code{source} URLs and report those that are
50f5c46d
EB
4635invalid. Check that the source file name is meaningful, e.g. is not
4636just a version number or ``git-checkout'', and should not have a
4637@code{file-name} declared (@pxref{origin Reference}).
40a7d4e5 4638
5432734b
LC
4639@item cve
4640Report known vulnerabilities found in the Common Vulnerabilities and
4641Exposures (CVE) database
4642@uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
4643NIST}.
4644
40a7d4e5
LC
4645@item formatting
4646Warn about obvious source code formatting issues: trailing white space,
4647use of tabulations, etc.
873c4085 4648@end table
b4f5e0e8
CR
4649
4650The general syntax is:
4651
4652@example
4653guix lint @var{options} @var{package}@dots{}
4654@end example
4655
4656If no package is given on the command line, then all packages are checked.
4657The @var{options} may be zero or more of the following:
4658
4659@table @code
4660
dd7c013d
CR
4661@item --checkers
4662@itemx -c
4663Only enable the checkers specified in a comma-separated list using the
4664names returned by @code{--list-checkers}.
4665
b4f5e0e8
CR
4666@item --list-checkers
4667@itemx -l
4668List and describe all the available checkers that will be run on packages
4669and exit.
4670
4671@end table
37166310 4672
fcc58db6
LC
4673@node Invoking guix size
4674@section Invoking @command{guix size}
4675
4676The @command{guix size} command helps package developers profile the
4677disk usage of packages. It is easy to overlook the impact of an
4678additional dependency added to a package, or the impact of using a
4679single output for a package that could easily be split (@pxref{Packages
4680with Multiple Outputs}). These are the typical issues that
4681@command{guix size} can highlight.
4682
4683The command can be passed a package specification such as @code{gcc-4.8}
4684or @code{guile:debug}, or a file name in the store. Consider this
4685example:
4686
4687@example
4688$ guix size coreutils
4689store item total self
4690/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
4691/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
4692/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
4693/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
4694/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
4695/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
4696@end example
4697
4698@cindex closure
4699The store items listed here constitute the @dfn{transitive closure} of
4700Coreutils---i.e., Coreutils and all its dependencies, recursively---as
4701would be returned by:
4702
4703@example
4704$ guix gc -R /gnu/store/@dots{}-coreutils-8.23
4705@end example
4706
4707Here the output shows 3 columns next to store items. The first column,
4708labeled ``total'', shows the size in mebibytes (MiB) of the closure of
4709the store item---that is, its own size plus the size of all its
4710dependencies. The next column, labeled ``self'', shows the size of the
4711item itself. The last column shows the ratio of the item's size to the
4712space occupied by all the items listed here.
4713
4714In this example, we see that the closure of Coreutils weighs in at
471570@tie{}MiB, half of which is taken by libc. (That libc represents a
4716large fraction of the closure is not a problem @i{per se} because it is
4717always available on the system anyway.)
4718
4719When the package passed to @command{guix size} is available in the
4720store, @command{guix size} queries the daemon to determine its
4721dependencies, and measures its size in the store, similar to @command{du
4722-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
4723Coreutils}).
4724
4725When the given package is @emph{not} in the store, @command{guix size}
4726reports information based on information about the available substitutes
4727(@pxref{Substitutes}). This allows it to profile disk usage of store
4728items that are not even on disk, only available remotely.
4729
a8f996c6 4730The available options are:
fcc58db6
LC
4731
4732@table @option
4733
d490d06e
LC
4734@item --substitute-urls=@var{urls}
4735Use substitute information from @var{urls}.
4736@xref{client-substitute-urls, the same option for @code{guix build}}.
4737
a8f996c6
LC
4738@item --map-file=@var{file}
4739Write to @var{file} a graphical map of disk usage as a PNG file.
4740
4741For the example above, the map looks like this:
4742
4743@image{images/coreutils-size-map,5in,, map of Coreutils disk usage
4744produced by @command{guix size}}
4745
4746This option requires that
4747@uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
4748installed and visible in Guile's module search path. When that is not
4749the case, @command{guix size} fails as it tries to load it.
4750
fcc58db6
LC
4751@item --system=@var{system}
4752@itemx -s @var{system}
4753Consider packages for @var{system}---e.g., @code{x86_64-linux}.
4754
4755@end table
4756
88856916
LC
4757@node Invoking guix graph
4758@section Invoking @command{guix graph}
4759
4760@cindex DAG
4761Packages and their dependencies form a @dfn{graph}, specifically a
4762directed acyclic graph (DAG). It can quickly become difficult to have a
4763mental model of the package DAG, so the @command{guix graph} command is
4764here to provide a visual representation of the DAG. @command{guix
4765graph} emits a DAG representation in the input format of
4766@uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
4767directly to Graphviz's @command{dot} command, for instance. The general
4768syntax is:
4769
4770@example
4771guix graph @var{options} @var{package}@dots{}
4772@end example
4773
4774For example, the following command generates a PDF file representing the
4775package DAG for the GNU@tie{}Core Utilities, showing its build-time
4776dependencies:
4777
4778@example
4779guix graph coreutils | dot -Tpdf > dag.pdf
4780@end example
4781
4782The output looks like this:
4783
4784@image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
4785
4786Nice little graph, no?
4787
4788But there's more than one graph! The one above is concise: it's the
4789graph of package objects, omitting implicit inputs such as GCC, libc,
4790grep, etc. It's often useful to have such a concise graph, but
4791sometimes you want to see more details. @command{guix graph} supports
4792several types of graphs, allowing you to choose the level of details:
4793
4794@table @code
4795@item package
4796This is the default type, the one we used above. It shows the DAG of
4797package objects, excluding implicit dependencies. It is concise, but
4798filters out many details.
4799
4800@item bag-emerged
4801This is the package DAG, @emph{including} implicit inputs.
4802
4803For instance, the following command:
4804
4805@example
4806guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
4807@end example
4808
4809... yields this bigger graph:
4810
4811@image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
4812
4813At the bottom of the graph, we see all the implicit inputs of
4814@var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
4815
4816Now, note that the dependencies of those implicit inputs---that is, the
4817@dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
4818here, for conciseness.
4819
4820@item bag
4821Similar to @code{bag-emerged}, but this time including all the bootstrap
4822dependencies.
4823
38b92daa
LC
4824@item bag-with-origins
4825Similar to @code{bag}, but also showing origins and their dependencies.
4826
88856916
LC
4827@item derivations
4828This is the most detailed representation: It shows the DAG of
4829derivations (@pxref{Derivations}) and plain store items. Compared to
4830the above representation, many additional nodes are visible, including
4831builds scripts, patches, Guile modules, etc.
4832
4833@end table
4834
4835All the above types correspond to @emph{build-time dependencies}. The
4836following graph type represents the @emph{run-time dependencies}:
4837
4838@table @code
4839@item references
4840This is the graph of @dfn{references} of a package output, as returned
4841by @command{guix gc --references} (@pxref{Invoking guix gc}).
4842
4843If the given package output is not available in the store, @command{guix
4844graph} attempts to obtain dependency information from substitutes.
4845@end table
4846
4847The available options are the following:
4848
4849@table @option
4850@item --type=@var{type}
4851@itemx -t @var{type}
4852Produce a graph output of @var{type}, where @var{type} must be one of
4853the values listed above.
4854
4855@item --list-types
4856List the supported graph types.
4c8f997a
LC
4857
4858@item --expression=@var{expr}
4859@itemx -e @var{expr}
4860Consider the package @var{expr} evaluates to.
4861
4862This is useful to precisely refer to a package, as in this example:
4863
4864@example
4865guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
4866@end example
88856916
LC
4867@end table
4868
4869
372c4bbc
DT
4870@node Invoking guix environment
4871@section Invoking @command{guix environment}
4872
f5fd4fd2 4873@cindex reproducible build environments
fe36d84e 4874@cindex development environments
372c4bbc
DT
4875The purpose of @command{guix environment} is to assist hackers in
4876creating reproducible development environments without polluting their
4877package profile. The @command{guix environment} tool takes one or more
4878packages, builds all of the necessary inputs, and creates a shell
4879environment to use them.
4880
4881The general syntax is:
4882
4883@example
4884guix environment @var{options} @var{package}@dots{}
4885@end example
4886
fe36d84e
LC
4887The following example spawns a new shell set up for the development of
4888GNU@tie{}Guile:
372c4bbc
DT
4889
4890@example
4891guix environment guile
4892@end example
4893
4894If the specified packages are not built yet, @command{guix environment}
4895automatically builds them. The new shell's environment is an augmented
4896version of the environment that @command{guix environment} was run in.
4897It contains the necessary search paths for building the given package
4898added to the existing environment variables. To create a ``pure''
4899environment in which the original environment variables have been unset,
50500f7c
LC
4900use the @code{--pure} option@footnote{Users sometimes wrongfully augment
4901environment variables such as @code{PATH} in their @file{~/.bashrc}
4902file. As a consequence, when @code{guix environment} launches it, Bash
4903may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
4904environment variables. It is an error to define such environment
4905variables in @file{.bashrc}; instead, they should be defined in
4906@file{.bash_profile}, which is sourced only by log-in shells.
4907@xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
4908details on Bash start-up files.}.
372c4bbc 4909
28de8d25
LC
4910@vindex GUIX_ENVIRONMENT
4911@command{guix environment} defines the @code{GUIX_ENVIRONMENT}
4912variable in the shell it spaws. This allows users to, say, define a
4913specific prompt for development environments in their @file{.bashrc}
4914(@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
4915
4916@example
4917if [ -n "$GUIX_ENVIRONMENT" ]
4918then
4919 export PS1="\u@@\h \w [dev]\$ "
4920fi
4921@end example
4922
372c4bbc
DT
4923Additionally, more than one package may be specified, in which case the
4924union of the inputs for the given packages are used. For example, the
4925command below spawns a shell where all of the dependencies of both Guile
4926and Emacs are available:
4927
4928@example
4929guix environment guile emacs
4930@end example
4931
1de2fe95
DT
4932Sometimes an interactive shell session is not desired. An arbitrary
4933command may be invoked by placing the @code{--} token to separate the
4934command from the rest of the arguments:
372c4bbc
DT
4935
4936@example
1de2fe95 4937guix environment guile -- make -j4
372c4bbc
DT
4938@end example
4939
fe36d84e
LC
4940In other situations, it is more convenient to specify the list of
4941packages needed in the environment. For example, the following command
4942runs @command{python} from an environment containing Python@tie{}2.7 and
4943NumPy:
4944
4945@example
1de2fe95 4946guix environment --ad-hoc python2-numpy python-2.7 -- python
fe36d84e
LC
4947@end example
4948
cc90fbbf
DT
4949Furthermore, one might want the dependencies of a package and also some
4950additional packages that are not build-time or runtime dependencies, but
4951are useful when developing nonetheless. Because of this, the
4952@code{--ad-hoc} flag is positional. Packages appearing before
4953@code{--ad-hoc} are interpreted as packages whose dependencies will be
4954added to the environment. Packages appearing after are interpreted as
4955packages that will be added to the environment directly. For example,
4956the following command creates a Guix development environment that
4957additionally includes Git and strace:
4958
4959@example
4960guix environment guix --ad-hoc git strace
4961@end example
4962
f535dcbe
DT
4963Sometimes it is desirable to isolate the environment as much as
4964possible, for maximal purity and reproducibility. In particular, when
4965using Guix on a host distro that is not GuixSD, it is desirable to
4966prevent access to @file{/usr/bin} and other system-wide resources from
4967the development environment. For example, the following command spawns
4968a Guile REPL in a ``container'' where only the store and the current
4969working directory are mounted:
4970
4971@example
4972guix environment --ad-hoc --container guile -- guile
4973@end example
4974
0f252e26 4975@quotation Note
cfd35b4e 4976The @code{--container} option requires Linux-libre 3.19 or newer.
0f252e26
DT
4977@end quotation
4978
fe36d84e 4979The available options are summarized below.
372c4bbc
DT
4980
4981@table @code
4982@item --expression=@var{expr}
4983@itemx -e @var{expr}
c9c282ce
DT
4984Create an environment for the package or list of packages that
4985@var{expr} evaluates to.
372c4bbc 4986
fe36d84e
LC
4987For example, running:
4988
4989@example
4990guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
4991@end example
4992
4993starts a shell with the environment for this specific variant of the
4994PETSc package.
4995
c9c282ce
DT
4996Running:
4997
4998@example
5c2b2f00 4999guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
c9c282ce
DT
5000@end example
5001
5002starts a shell with all the GuixSD base packages available.
5003
372c4bbc
DT
5004@item --load=@var{file}
5005@itemx -l @var{file}
c9c282ce
DT
5006Create an environment for the package or list of packages that the code
5007within @var{file} evaluates to.
372c4bbc 5008
fe36d84e
LC
5009As an example, @var{file} might contain a definition like this
5010(@pxref{Defining Packages}):
5011
5012@example
5013@verbatiminclude environment-gdb.scm
5014@end example
5015
a54bd6d7
DT
5016@item --ad-hoc
5017Include all specified packages in the resulting environment, as if an
5018@i{ad hoc} package were defined with them as inputs. This option is
5019useful for quickly creating an environment without having to write a
5020package expression to contain the desired inputs.
5021
5022For instance, the command:
5023
5024@example
1de2fe95 5025guix environment --ad-hoc guile guile-sdl -- guile
a54bd6d7
DT
5026@end example
5027
5028runs @command{guile} in an environment where Guile and Guile-SDL are
5029available.
5030
417c39f1
LC
5031Note that this example implicitly asks for the default output of
5032@code{guile} and @code{guile-sdl} but it is possible to ask for a
5033specific output---e.g., @code{glib:bin} asks for the @code{bin} output
5034of @code{glib} (@pxref{Packages with Multiple Outputs}).
5035
cc90fbbf
DT
5036This option may be composed with the default behavior of @command{guix
5037environment}. Packages appearing before @code{--ad-hoc} are interpreted
5038as packages whose dependencies will be added to the environment, the
5039default behavior. Packages appearing after are interpreted as packages
5040that will be added to the environment directly.
5041
372c4bbc
DT
5042@item --pure
5043Unset existing environment variables when building the new environment.
5044This has the effect of creating an environment in which search paths
5045only contain package inputs.
5046
5047@item --search-paths
5048Display the environment variable definitions that make up the
5049environment.
ce367ef3
LC
5050
5051@item --system=@var{system}
5052@itemx -s @var{system}
5053Attempt to build for @var{system}---e.g., @code{i686-linux}.
f535dcbe
DT
5054
5055@item --container
5056@itemx -C
5057@cindex container
5058Run @var{command} within an isolated container. The current working
56b6befb 5059directory outside the container is mapped inside the
f535dcbe
DT
5060container. Additionally, the spawned process runs as the current user
5061outside the container, but has root privileges in the context of the
5062container.
5063
5064@item --network
5065@itemx -N
5066For containers, share the network namespace with the host system.
5067Containers created without this flag only have access to the loopback
5068device.
5069
5070@item --expose=@var{source}[=@var{target}]
5071For containers, expose the file system @var{source} from the host system
5072as the read-only file system @var{target} within the container. If
5073@var{target} is not specified, @var{source} is used as the target mount
5074point in the container.
5075
5076The example below spawns a Guile REPL in a container in which the user's
5077home directory is accessible read-only via the @file{/exchange}
5078directory:
5079
5080@example
5081guix environment --container --expose=$HOME=/exchange guile -- guile
5082@end example
5083
5c2b2f00 5084@item --share=@var{source}[=@var{target}]
f535dcbe
DT
5085For containers, share the file system @var{source} from the host system
5086as the writable file system @var{target} within the container. If
5087@var{target} is not specified, @var{source} is used as the target mount
5088point in the container.
5089
5090The example below spawns a Guile REPL in a container in which the user's
5091home directory is accessible for both reading and writing via the
5092@file{/exchange} directory:
5093
5094@example
5095guix environment --container --share=$HOME=/exchange guile -- guile
5096@end example
372c4bbc
DT
5097@end table
5098
5099It also supports all of the common build options that @command{guix
5100build} supports (@pxref{Invoking guix build, common build options}).
5101
aff8ce7c
DT
5102@node Invoking guix publish
5103@section Invoking @command{guix publish}
5104
5105The purpose of @command{guix publish} is to enable users to easily share
8ce229fc
LC
5106their store with others, which can then use it as a substitute server
5107(@pxref{Substitutes}).
5108
5109When @command{guix publish} runs, it spawns an HTTP server which allows
5110anyone with network access to obtain substitutes from it. This means
5111that any machine running Guix can also act as if it were a build farm,
5112since the HTTP interface is compatible with Hydra, the software behind
5113the @code{hydra.gnu.org} build farm.
aff8ce7c
DT
5114
5115For security, each substitute is signed, allowing recipients to check
5116their authenticity and integrity (@pxref{Substitutes}). Because
5117@command{guix publish} uses the system's signing key, which is only
5463fe51
LC
5118readable by the system administrator, it must be started as root; the
5119@code{--user} option makes it drop root privileges early on.
aff8ce7c 5120
b18812b6
LC
5121The signing key pair must be generated before @command{guix publish} is
5122launched, using @command{guix archive --generate-key} (@pxref{Invoking
5123guix archive}).
5124
aff8ce7c
DT
5125The general syntax is:
5126
5127@example
5128guix publish @var{options}@dots{}
5129@end example
5130
5131Running @command{guix publish} without any additional arguments will
5132spawn an HTTP server on port 8080:
5133
5134@example
5135guix publish
5136@end example
5137
5138Once a publishing server has been authorized (@pxref{Invoking guix
5139archive}), the daemon may download substitutes from it:
5140
5141@example
5142guix-daemon --substitute-urls=http://example.org:8080
5143@end example
5144
5145The following options are available:
5146
5147@table @code
5148@item --port=@var{port}
5149@itemx -p @var{port}
5150Listen for HTTP requests on @var{port}.
5151
9e2292ef
LC
5152@item --listen=@var{host}
5153Listen on the network interface for @var{host}. The default is to
5154accept connections from any interface.
5155
5463fe51
LC
5156@item --user=@var{user}
5157@itemx -u @var{user}
5158Change privileges to @var{user} as soon as possible---i.e., once the
5159server socket is open and the signing key has been read.
5160
aff8ce7c
DT
5161@item --repl[=@var{port}]
5162@itemx -r [@var{port}]
5163Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8ce229fc
LC
5164Reference Manual}) on @var{port} (37146 by default). This is used
5165primarily for debugging a running @command{guix publish} server.
aff8ce7c
DT
5166@end table
5167
1c52181f
LC
5168Enabling @command{guix publish} on a GuixSD system is a one-liner: just
5169add a call to @code{guix-publish-service} in the @code{services} field
5170of the @code{operating-system} declaration (@pxref{guix-publish-service,
5171@code{guix-publish-service}}).
5172
d23c20f1
LC
5173
5174@node Invoking guix challenge
5175@section Invoking @command{guix challenge}
5176
5177@cindex reproducible builds
5178@cindex verifiable builds
5179
5180Do the binaries provided by this server really correspond to the source
5181code it claims to build? Is this package's build process deterministic?
5182These are the questions the @command{guix challenge} command attempts to
5183answer.
5184
5185The former is obviously an important question: Before using a substitute
5186server (@pxref{Substitutes}), you'd rather @emph{verify} that it
5187provides the right binaries, and thus @emph{challenge} it. The latter
5188is what enables the former: If package builds are deterministic, then
5189independent builds of the package should yield the exact same result,
5190bit for bit; if a server provides a binary different from the one
5191obtained locally, it may be either corrupt or malicious.
5192
5193We know that the hash that shows up in @file{/gnu/store} file names is
5194the hash of all the inputs of the process that built the file or
5195directory---compilers, libraries, build scripts,
5196etc. (@pxref{Introduction}). Assuming deterministic build processes,
5197one store file name should map to exactly one build output.
5198@command{guix challenge} checks whether there is, indeed, a single
5199mapping by comparing the build outputs of several independent builds of
5200any given store item.
5201
5202The command's output looks like this:
5203
5204@smallexample
5205$ guix challenge --substitute-urls="http://hydra.gnu.org http://guix.example.org"
5206updating list of substitutes from 'http://hydra.gnu.org'... 100.0%
5207updating list of substitutes from 'http://guix.example.org'... 100.0%
5208/gnu/store/@dots{}-openssl-1.0.2d contents differ:
5209 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5210 http://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5211 http://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
5212/gnu/store/@dots{}-git-2.5.0 contents differ:
5213 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
5214 http://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
5215 http://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
5216/gnu/store/@dots{}-pius-2.1.1 contents differ:
5217 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5218 http://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5219 http://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
5220@end smallexample
5221
5222@noindent
5223In this example, @command{guix challenge} first scans the store to
5224determine the set of locally-built derivations---as opposed to store
5225items that were downloaded from a substitute server---and then queries
5226all the substitute servers. It then reports those store items for which
5227the servers obtained a result different from the local build.
5228
5229@cindex non-determinism, in package builds
5230As an example, @code{guix.example.org} always gets a different answer.
5231Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
5232case of Git. This might indicate that the build process of Git is
5233non-deterministic, meaning that its output varies as a function of
5234various things that Guix does not fully control, in spite of building
5235packages in isolated environments (@pxref{Features}). Most common
5236sources of non-determinism include the addition of timestamps in build
5237results, the inclusion of random numbers, and directory listings sorted
5238by inode number. See @uref{http://reproducible.debian.net/howto/}, for
5239more information.
5240
5241To find out what's wrong with this Git binary, we can do something along
5242these lines (@pxref{Invoking guix archive}):
5243
5244@example
5245$ wget -q -O - http://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
5246 | guix archive -x /tmp/git
043f4698 5247$ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
d23c20f1
LC
5248@end example
5249
5250This command shows the difference between the files resulting from the
5251local build, and the files resulting from the build on
5252@code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
5253diffutils, Comparing and Merging Files}). The @command{diff} command
5254works great for text files. When binary files differ, a better option
5255is @uref{http://diffoscope.org/, Diffoscope}, a tool that helps
5256visualize differences for all kinds of files.
5257
5258Once you've done that work, you can tell whether the differences are due
5259to a non-deterministic build process or to a malicious server. We try
5260hard to remove sources of non-determinism in packages to make it easier
5261to verify substitutes, but of course, this is a process, one that
5262involves not just Guix but a large part of the free software community.
5263In the meantime, @command{guix challenge} is one tool to help address
5264the problem.
5265
5266If you are writing packages for Guix, you are encouraged to check
5267whether @code{hydra.gnu.org} and other substitute servers obtain the
5268same build result as you did with:
5269
5270@example
5271$ guix challenge @var{package}
5272@end example
5273
5274@noindent
5275... where @var{package} is a package specification such as
5276@code{guile-2.0} or @code{glibc:debug}.
5277
5278The general syntax is:
5279
5280@example
5281guix challenge @var{options} [@var{packages}@dots{}]
5282@end example
5283
5284The one option that matters is:
5285
5286@table @code
5287
5288@item --substitute-urls=@var{urls}
5289Consider @var{urls} the whitespace-separated list of substitute source
5290URLs to compare to.
5291
5292@end table
5293
5294
32efa254
DT
5295@node Invoking guix container
5296@section Invoking @command{guix container}
5297@cindex container
5298
5299@quotation Note
5300As of version @value{VERSION}, this tool is experimental. The interface
5301is subject to radical change in the future.
5302@end quotation
5303
5304The purpose of @command{guix container} is to manipulate processes
5305running within an isolated environment, commonly known as a
46c36586 5306``container'', typically created by the @command{guix environment}
32efa254
DT
5307(@pxref{Invoking guix environment}) and @command{guix system container}
5308(@pxref{Invoking guix system}) commands.
5309
5310The general syntax is:
5311
5312@example
5313guix container @var{action} @var{options}@dots{}
5314@end example
5315
5316@var{action} specifies the operation to perform with a container, and
5317@var{options} specifies the context-specific arguments for the action.
5318
5319The following actions are available:
5320
5321@table @code
5322@item exec
5323Execute a command within the context of a running container.
5324
5325The syntax is:
5326
5327@example
5328guix container exec @var{pid} @var{program} @var{arguments}@dots{}
5329@end example
5330
5331@var{pid} specifies the process ID of the running container.
5332@var{program} specifies an executable file name within the container's
5333root file system. @var{arguments} are the additional options that will
5334be passed to @var{program}.
5335
5336The following command launches an interactive login shell inside a
5337GuixSD container, started by @command{guix system container}, and whose
5338process ID is 9001:
5339
5340@example
5341guix container exec 9001 /run/current-system/profile/bin/bash --login
5342@end example
5343
5344Note that the @var{pid} cannot be the parent process of a container. It
5345must be the container's PID 1 or one of its child processes.
5346
5347@end table
5348
a1ba8475
LC
5349@c *********************************************************************
5350@node GNU Distribution
5351@chapter GNU Distribution
5352
3ca2731c 5353@cindex Guix System Distribution
4705641f 5354@cindex GuixSD
3ca2731c
LC
5355Guix comes with a distribution of the GNU system consisting entirely of
5356free software@footnote{The term ``free'' here refers to the
a1ba8475 5357@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 5358users of that software}.}. The
35ed9306
LC
5359distribution can be installed on its own (@pxref{System Installation}),
5360but it is also possible to install Guix as a package manager on top of
5361an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c 5362between the two, we refer to the standalone distribution as the Guix
4705641f 5363System Distribution, or GuixSD.
35ed9306
LC
5364
5365The distribution provides core GNU packages such as GNU libc, GCC, and
5366Binutils, as well as many GNU and non-GNU applications. The complete
5367list of available packages can be browsed
093ae1be 5368@url{http://www.gnu.org/software/guix/packages,on-line} or by
d03bb653 5369running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
5370
5371@example
e49951eb 5372guix package --list-available
a1ba8475
LC
5373@end example
5374
35ed9306 5375Our goal has been to provide a practical 100% free software distribution of
401c53c4
LC
5376Linux-based and other variants of GNU, with a focus on the promotion and
5377tight integration of GNU components, and an emphasis on programs and
5378tools that help users exert that freedom.
5379
3ca2731c 5380Packages are currently available on the following platforms:
c320011d
LC
5381
5382@table @code
5383
5384@item x86_64-linux
5385Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
5386
5387@item i686-linux
5388Intel 32-bit architecture (IA32), Linux-Libre kernel;
5389
aa1e1947 5390@item armhf-linux
aa725117 5391ARMv7-A architecture with hard float, Thumb-2 and NEON,
aa1e1947
MW
5392using the EABI hard-float ABI, and Linux-Libre kernel.
5393
c320011d
LC
5394@item mips64el-linux
5395little-endian 64-bit MIPS processors, specifically the Loongson series,
5396n32 application binary interface (ABI), and Linux-Libre kernel.
5397
5398@end table
5399
4705641f 5400GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
3ca2731c 5401
c320011d
LC
5402@noindent
5403For information on porting to other architectures or kernels,
5404@xref{Porting}.
5405
401c53c4 5406@menu
5af6de3e 5407* System Installation:: Installing the whole operating system.
35ed9306 5408* System Configuration:: Configuring the operating system.
91ef73d4 5409* Installing Debugging Files:: Feeding the debugger.
05962f29 5410* Security Updates:: Deploying security fixes quickly.
401c53c4 5411* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 5412* Packaging Guidelines:: Growing the distribution.
401c53c4 5413* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 5414* Porting:: Targeting another platform or kernel.
401c53c4
LC
5415@end menu
5416
5417Building this distribution is a cooperative effort, and you are invited
081145cf 5418to join! @xref{Contributing}, for information about how you can help.
401c53c4 5419
5af6de3e
LC
5420@node System Installation
5421@section System Installation
5422
3ca2731c
LC
5423@cindex Guix System Distribution
5424This section explains how to install the Guix System Distribution
5425on a machine. The Guix package manager can
35ed9306
LC
5426also be installed on top of a running GNU/Linux system,
5427@pxref{Installation}.
5af6de3e
LC
5428
5429@ifinfo
5430@c This paragraph is for people reading this from tty2 of the
5431@c installation image.
5432You're reading this documentation with an Info reader. For details on
5433how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
6621cdb6 5434link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit
5af6de3e
LC
5435@kbd{l} afterwards to come back here.
5436@end ifinfo
5437
8aaaae38
LC
5438@subsection Limitations
5439
4705641f 5440As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
3ca2731c 5441not production-ready. It may contain bugs and lack important
8aaaae38
LC
5442features. Thus, if you are looking for a stable production system that
5443respects your freedom as a computer user, a good solution at this point
5444is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
5445more established GNU/Linux distributions}. We hope you can soon switch
4705641f 5446to the GuixSD without fear, of course. In the meantime, you can
8aaaae38
LC
5447also keep using your distribution and try out the package manager on top
5448of it (@pxref{Installation}).
5449
5450Before you proceed with the installation, be aware of the following
5451noteworthy limitations applicable to version @value{VERSION}:
5452
5453@itemize
5454@item
5455The installation process does not include a graphical user interface and
5456requires familiarity with GNU/Linux (see the following subsections to
5457get a feel of what that means.)
5458
5459@item
093ae1be
LC
5460The system does not yet provide full GNOME and KDE desktops. Xfce and
5461Enlightenment are available though, if graphical desktop environments
5462are your thing, as well as a number of X11 window managers.
8aaaae38
LC
5463
5464@item
dbcb0ab1 5465Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
5466
5467@item
5468Few system services are currently supported out-of-the-box
5469(@pxref{Services}).
5470
5471@item
093ae1be 5472More than 2,000 packages are available, but you may
8aaaae38
LC
5473occasionally find that a useful package is missing.
5474@end itemize
5475
5476You've been warned. But more than a disclaimer, this is an invitation
5477to report issues (and success stories!), and join us in improving it.
5478@xref{Contributing}, for more info.
5af6de3e
LC
5479
5480@subsection USB Stick Installation
5481
5482An installation image for USB sticks can be downloaded from
4705641f 5483@indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
5484where @var{system} is one of:
5485
5486@table @code
5487@item x86_64-linux
5488for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
5489
5490@item i686-linux
5491for a 32-bit GNU/Linux system on Intel-compatible CPUs.
5492@end table
5493
5494This image contains a single partition with the tools necessary for an
5495installation. It is meant to be copied @emph{as is} to a large-enough
5496USB stick.
5497
5498To copy the image to a USB stick, follow these steps:
5499
5500@enumerate
5501@item
5502Decompress the image using the @command{xz} command:
5503
5504@example
4705641f 5505xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
5506@end example
5507
5508@item
5509Insert a USB stick of 1@tie{}GiB or more in your machine, and determine
5510its device name. Assuming that USB stick is known as @file{/dev/sdX},
5511copy the image with:
5512
5513@example
4705641f 5514dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
5515@end example
5516
5517Access to @file{/dev/sdX} usually requires root privileges.
5518@end enumerate
5519
5520Once this is done, you should be able to reboot the system and boot from
5521the USB stick. The latter usually requires you to get in the BIOS' boot
5522menu, where you can choose to boot from the USB stick.
5523
5524@subsection Preparing for Installation
5525
5526Once you have successfully booted the image on the USB stick, you should
5527end up with a root prompt. Several console TTYs are configured and can
5528be used to run commands as root. TTY2 shows this documentation,
5529browsable using the Info reader commands (@pxref{Help,,, info, Info: An
ae7ffa9e
LC
5530Introduction}). The installation system runs the GPM mouse daemon,
5531which allows you to select text with the left mouse button and to paste
5532it with the middle button.
5af6de3e
LC
5533
5534To install the system, you would:
5535
5536@enumerate
5537
5538@item
235cba85
LC
5539Configure the network, by running:
5540
5541@example
5542ifconfig eno1 up && dhclient eno1
5543@end example
5544
5545to get an automatically assigned IP address from the wired
152dd61c 5546network interface controller@footnote{
95c559c1
LC
5547@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
5548The name @code{eno1} is for the first on-board Ethernet controller. The
5549interface name for an Ethernet controller that is in the first slot of
5550the first PCI bus, for instance, would be @code{enp1s0}. Use
235cba85 5551@command{ifconfig -a} to list all the available network interfaces.},
95c559c1 5552or using the @command{ifconfig} command.
5af6de3e
LC
5553
5554The system automatically loads drivers for your network interface
5555controllers.
5556
5557Setting up network access is almost always a requirement because the
5558image does not contain all the software and tools that may be needed.
5559
5560@item
316d65be
LC
5561Unless this has already been done, you must partition, and then format
5562the target partition.
5af6de3e 5563
7ab44369
LC
5564Preferably, assign partitions a label so that you can easily and
5565reliably refer to them in @code{file-system} declarations (@pxref{File
5566Systems}). This is typically done using the @code{-L} option of
5567@command{mkfs.ext4} and related commands.
5568
dd816355
LF
5569Be sure that your partition labels match the value of their respective
5570@code{device} fields in your @code{file-system} configuration, if your
5571@code{file-system} configuration sets the value of @code{title} to
5572@code{'label}, as do the example configurations found on the USB
5573installation image under @file{/etc/configuration} (@pxref{Using the
5574Configuration System}).
5575
316d65be
LC
5576@c FIXME: Uncomment this once GRUB fully supports encrypted roots.
5577@c A typical command sequence may be:
5578@c
5579@c @example
5580@c # fdisk /dev/sdX
5581@c @dots{} Create partitions etc.@dots{}
5582@c # cryptsetup luksFormat /dev/sdX1
5583@c # cryptsetup open --type luks /dev/sdX1 my-partition
5584@c # mkfs.ext4 -L my-root /dev/mapper/my-partition
5585@c @end example
6d6e6281 5586
5af6de3e 5587The installation image includes Parted (@pxref{Overview,,, parted, GNU
b419c7f5
LC
5588Parted User Manual}), @command{fdisk}, Cryptsetup/LUKS for disk
5589encryption, and e2fsprogs, the suite of tools to manipulate
5590ext2/ext3/ext4 file systems.
5af6de3e 5591
83a17b62
LC
5592@item
5593Once that is done, mount the target root partition under @file{/mnt}.
5594
5595@item
5596Lastly, run @code{deco start cow-store /mnt}.
5597
5598This will make @file{/gnu/store} copy-on-write, such that packages added
5599to it during the installation phase will be written to the target disk
5600rather than kept in memory.
5601
5af6de3e
LC
5602@end enumerate
5603
5af6de3e
LC
5604
5605@subsection Proceeding with the Installation
5606
5607With the target partitions ready, you now have to edit a file and
5608provide the declaration of the operating system to be installed. To
5609that end, the installation system comes with two text editors: GNU nano
5610(@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
5611It is better to store that file on the target root file system, say, as
5612@file{/mnt/etc/config.scm}.
5613
dd51caac
LC
5614@xref{Using the Configuration System}, for examples of operating system
5615configurations. These examples are available under
5616@file{/etc/configuration} in the installation image, so you can copy
5617them and use them as a starting point for your own configuration.
5af6de3e 5618
dd51caac
LC
5619Once you are done preparing the configuration file, the new system must
5620be initialized (remember that the target root file system is mounted
5621under @file{/mnt}):
5af6de3e
LC
5622
5623@example
5624guix system init /mnt/etc/config.scm /mnt
5625@end example
5626
5627@noindent
5628This will copy all the necessary files, and install GRUB on
5629@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 5630more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
5631downloads or builds of missing packages, which can take some time.
5632
1bd4e6db
LC
5633Once that command has completed---and hopefully succeeded!---you can run
5634@command{reboot} and boot into the new system. The @code{root} password
5635in the new system is initially empty; other users' passwords need to be
5636initialized by running the @command{passwd} command as @code{root},
5637unless your configuration specifies otherwise
5638(@pxref{user-account-password, user account passwords}).
5639
5640Join us on @code{#guix} on the Freenode IRC network or on
5af6de3e
LC
5641@file{guix-devel@@gnu.org} to share your experience---good or not so
5642good.
5643
5644@subsection Building the Installation Image
5645
5646The installation image described above was built using the @command{guix
5647system} command, specifically:
5648
5649@example
8a225c66 5650guix system disk-image --image-size=850MiB gnu/system/install.scm
5af6de3e
LC
5651@end example
5652
5653@xref{Invoking guix system}, for more information. See
5654@file{gnu/system/install.scm} in the source tree for more information
5655about the installation image.
5656
cf4a9129
LC
5657@node System Configuration
5658@section System Configuration
b208a005 5659
cf4a9129 5660@cindex system configuration
3ca2731c 5661The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
5662mechanism. By that we mean that all aspects of the global system
5663configuration---such as the available system services, timezone and
5664locale settings, user accounts---are declared in a single place. Such
5665a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 5666
cf4a9129
LC
5667One of the advantages of putting all the system configuration under the
5668control of Guix is that it supports transactional system upgrades, and
5669makes it possible to roll-back to a previous system instantiation,
5670should something go wrong with the new one (@pxref{Features}). Another
5671one is that it makes it easy to replicate the exact same configuration
5672across different machines, or at different points in time, without
5673having to resort to additional administration tools layered on top of
5674the system's own tools.
5675@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 5676
cf4a9129
LC
5677This section describes this mechanism. First we focus on the system
5678administrator's viewpoint---explaining how the system is configured and
5679instantiated. Then we show how this mechanism can be extended, for
5680instance to support new system services.
91ef73d4 5681
cf4a9129
LC
5682@menu
5683* Using the Configuration System:: Customizing your GNU system.
7313a52e 5684* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 5685* File Systems:: Configuring file system mounts.
510f9d86 5686* Mapped Devices:: Block device extra processing.
cf4a9129 5687* User Accounts:: Specifying user accounts.
598e19dc 5688* Locales:: Language and cultural convention settings.
cf4a9129 5689* Services:: Specifying system services.
0ae8c15a 5690* Setuid Programs:: Programs running with root privileges.
efb5e833 5691* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 5692* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 5693* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 5694* GRUB Configuration:: Configuring the boot loader.
cf4a9129
LC
5695* Invoking guix system:: Instantiating a system configuration.
5696* Defining Services:: Adding new service definitions.
5697@end menu
91ef73d4 5698
cf4a9129
LC
5699@node Using the Configuration System
5700@subsection Using the Configuration System
64d76fa6 5701
cf4a9129
LC
5702The operating system is configured by providing an
5703@code{operating-system} declaration in a file that can then be passed to
5704the @command{guix system} command (@pxref{Invoking guix system}). A
5705simple setup, with the default system services, the default Linux-Libre
5706kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 5707
cf4a9129
LC
5708@findex operating-system
5709@lisp
dd51caac 5710@include os-config-bare-bones.texi
cf4a9129 5711@end lisp
401c53c4 5712
cf4a9129
LC
5713This example should be self-describing. Some of the fields defined
5714above, such as @code{host-name} and @code{bootloader}, are mandatory.
5715Others, such as @code{packages} and @code{services}, can be omitted, in
5716which case they get a default value.
e7f34eb0 5717
5d94ac51
LC
5718Below we discuss the effect of some of the most important fields
5719(@pxref{operating-system Reference}, for details about all the available
5720fields), and how to @dfn{instantiate} the operating system using
5721@command{guix system}.
5722
5723@unnumberedsubsubsec Globally-Visible Packages
5724
cf4a9129 5725@vindex %base-packages
5d94ac51
LC
5726The @code{packages} field lists packages that will be globally visible
5727on the system, for all user accounts---i.e., in every user's @code{PATH}
5728environment variable---in addition to the per-user profiles
5729(@pxref{Invoking guix package}). The @var{%base-packages} variable
5730provides all the tools one would expect for basic user and administrator
5731tasks---including the GNU Core Utilities, the GNU Networking Utilities,
5732the GNU Zile lightweight text editor, @command{find}, @command{grep},
5733etc. The example above adds tcpdump to those, taken from the @code{(gnu
5734packages admin)} module (@pxref{Package Modules}).
e7f34eb0 5735
f6c9fb1b
LC
5736@findex specification->package
5737Referring to packages by variable name, like @var{tcpdump} above, has
5738the advantage of being unambiguous; it also allows typos and such to be
5739diagnosed right away as ``unbound variables''. The downside is that one
5740needs to know which module defines which package, and to augment the
5741@code{use-package-modules} line accordingly. To avoid that, one can use
5742the @code{specification->package} procedure of the @code{(gnu packages)}
5743module, which returns the best package for a given name or name and
5744version:
5745
5746@lisp
5747(use-modules (gnu packages))
5748
5749(operating-system
5750 ;; ...
5751 (packages (append (map specification->package
5752 '("tcpdump" "htop" "gnupg-2.0"))
5753 %base-packages)))
5754@end lisp
5755
5d94ac51
LC
5756@unnumberedsubsubsec System Services
5757
cf4a9129
LC
5758@vindex %base-services
5759The @code{services} field lists @dfn{system services} to be made
5760available when the system starts (@pxref{Services}).
5761The @code{operating-system} declaration above specifies that, in
5762addition to the basic services, we want the @command{lshd} secure shell
cd6f6c22
LC
5763daemon listening on port 2222 (@pxref{Networking Services,
5764@code{lsh-service}}). Under the hood,
cf4a9129
LC
5765@code{lsh-service} arranges so that @code{lshd} is started with the
5766right command-line options, possibly with supporting configuration files
cd6f6c22
LC
5767generated as needed (@pxref{Defining Services}).
5768
5769@cindex customization, of services
5770@findex modify-services
5771Occasionally, instead of using the base services as is, you will want to
5772customize them. For instance, to change the configuration of
5773@code{guix-daemon} and Mingetty (the console log-in), you may write the
5774following instead of @var{%base-services}:
5775
5776@lisp
5777(modify-services %base-services
5778 (guix-service-type config =>
5779 (guix-configuration
5780 (inherit config)
5781 (use-substitutes? #f)
5782 (extra-options '("--gc-keep-outputs"))))
5783 (mingetty-service-type config =>
5784 (mingetty-configuration
5785 (inherit config)
5786 (motd (plain-file "motd" "Hi there!")))))
5787@end lisp
5788
5789@noindent
5790The effect here is to change the options passed to @command{guix-daemon}
5791when it is started, as well as the ``message of the day'' that appears
5792when logging in at the console. @xref{Service Reference,
5793@code{modify-services}}, for more on that.
a1ba8475 5794
dd51caac 5795The configuration for a typical ``desktop'' usage, with the X11 display
cd6f6c22 5796server, a desktop environment, network management, power management, and
dd51caac
LC
5797more, would look like this:
5798
5799@lisp
5800@include os-config-desktop.texi
5801@end lisp
5802
5803@xref{Desktop Services}, for the exact list of services provided by
efb5e833
LC
5804@var{%desktop-services}. @xref{X.509 Certificates}, for background
5805information about the @code{nss-certs} package that is used here.
dd51caac 5806
5d94ac51
LC
5807Again, @var{%desktop-services} is just a list of service objects. If
5808you want to remove services from there, you can do so using the
5809procedures for list filtering (@pxref{SRFI-1 Filtering and
5810Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
5811following expression returns a list that contains all the services in
5812@var{%desktop-services} minus the Avahi service:
5813
5814@example
5815(remove (lambda (service)
5816 (eq? (service-kind service) avahi-service-type))
5817 %desktop-services)
5818@end example
5819
5820@unnumberedsubsubsec Instantiating the System
5821
5822Assuming the @code{operating-system} declaration
5823is stored in the @file{my-system-config.scm}
cf4a9129
LC
5824file, the @command{guix system reconfigure my-system-config.scm} command
5825instantiates that configuration, and makes it the default GRUB boot
65797bff
LC
5826entry (@pxref{Invoking guix system}).
5827
5828The normal way to change the system's configuration is by updating this
5829file and re-running @command{guix system reconfigure}. One should never
5830have to touch files in @command{/etc} or to run commands that modify the
5831system state such as @command{useradd} or @command{grub-install}. In
5832fact, you must avoid that since that would not only void your warranty
5833but also prevent you from rolling back to previous versions of your
5834system, should you ever need to.
5835
5836@cindex roll-back, of the operating system
5837Speaking of roll-back, each time you run @command{guix system
5838reconfigure}, a new @dfn{generation} of the system is created---without
5839modifying or deleting previous generations. Old system generations get
5840an entry in the GRUB boot menu, allowing you to boot them in case
5841something went wrong with the latest generation. Reassuring, no? The
5842@command{guix system list-generations} command lists the system
5843generations available on disk.
b81e1947 5844
5d94ac51
LC
5845@unnumberedsubsubsec The Programming Interface
5846
cf4a9129
LC
5847At the Scheme level, the bulk of an @code{operating-system} declaration
5848is instantiated with the following monadic procedure (@pxref{The Store
5849Monad}):
b81e1947 5850
cf4a9129
LC
5851@deffn {Monadic Procedure} operating-system-derivation os
5852Return a derivation that builds @var{os}, an @code{operating-system}
5853object (@pxref{Derivations}).
b81e1947 5854
cf4a9129
LC
5855The output of the derivation is a single directory that refers to all
5856the packages, configuration files, and other supporting files needed to
5857instantiate @var{os}.
5858@end deffn
b81e1947 5859
5d94ac51
LC
5860This procedure is provided by the @code{(gnu system)} module. Along
5861with @code{(gnu services)} (@pxref{Services}), this module contains the
5862guts of GuixSD. Make sure to visit it!
5863
5864
7313a52e
LC
5865@node operating-system Reference
5866@subsection @code{operating-system} Reference
5867
5868This section summarizes all the options available in
5869@code{operating-system} declarations (@pxref{Using the Configuration
5870System}).
5871
5872@deftp {Data Type} operating-system
5873This is the data type representing an operating system configuration.
5874By that, we mean all the global system configuration, not per-user
5875configuration (@pxref{Using the Configuration System}).
5876
5877@table @asis
5878@item @code{kernel} (default: @var{linux-libre})
fbb25e56 5879The package object of the operating system kernel to use@footnote{Currently
7313a52e
LC
5880only the Linux-libre kernel is supported. In the future, it will be
5881possible to use the GNU@tie{}Hurd.}.
5882
ee2a6304
LC
5883@item @code{kernel-arguments} (default: @code{'()})
5884List of strings or gexps representing additional arguments to pass on
5885the kernel's command-line---e.g., @code{("console=ttyS0")}.
5886
7313a52e 5887@item @code{bootloader}
88faf933 5888The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
5889
5890@item @code{initrd} (default: @code{base-initrd})
5891A two-argument monadic procedure that returns an initial RAM disk for
5892the Linux kernel. @xref{Initial RAM Disk}.
5893
f34c56be
LC
5894@item @code{firmware} (default: @var{%base-firmware})
5895@cindex firmware
5896List of firmware packages loadable by the operating system kernel.
5897
5898The default includes firmware needed for Atheros-based WiFi devices
5899(Linux-libre module @code{ath9k}.)
5900
7313a52e
LC
5901@item @code{host-name}
5902The host name.
5903
5904@item @code{hosts-file}
5905@cindex hosts file
24e02c28 5906A file-like object (@pxref{G-Expressions, file-like objects}) for use as
7313a52e 5907@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
24e02c28 5908Reference Manual}). The default is a file with entries for
7313a52e
LC
5909@code{localhost} and @var{host-name}.
5910
5911@item @code{mapped-devices} (default: @code{'()})
5912A list of mapped devices. @xref{Mapped Devices}.
5913
5914@item @code{file-systems}
5915A list of file systems. @xref{File Systems}.
5916
5917@item @code{swap-devices} (default: @code{'()})
5918@cindex swap devices
5919A list of strings identifying devices to be used for ``swap space''
5920(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
5921For example, @code{'("/dev/sda3")}.
5922
bf87f38a 5923@item @code{users} (default: @code{%base-user-accounts})
7313a52e
LC
5924@itemx @code{groups} (default: @var{%base-groups})
5925List of user accounts and groups. @xref{User Accounts}.
5926
5927@item @code{skeletons} (default: @code{(default-skeletons)})
5928A monadic list of pairs of target file name and files. These are the
5929files that will be used as skeletons as new accounts are created.
5930
5931For instance, a valid value may look like this:
5932
5933@example
5934(mlet %store-monad ((bashrc (text-file "bashrc" "\
5935 export PATH=$HOME/.guix-profile/bin")))
5936 (return `((".bashrc" ,bashrc))))
5937@end example
5938
5939@item @code{issue} (default: @var{%default-issue})
5940A string denoting the contents of the @file{/etc/issue} file, which is
5941what displayed when users log in on a text console.
5942
5943@item @code{packages} (default: @var{%base-packages})
5944The set of packages installed in the global profile, which is accessible
5945at @file{/run/current-system/profile}.
5946
5947The default set includes core utilities, but it is good practice to
5948install non-core utilities in user profiles (@pxref{Invoking guix
5949package}).
5950
5951@item @code{timezone}
5952A timezone identifying string---e.g., @code{"Europe/Paris"}.
5953
598e19dc
LC
5954@item @code{locale} (default: @code{"en_US.utf8"})
5955The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
5956Library Reference Manual}). @xref{Locales}, for more information.
5957
5958@item @code{locale-definitions} (default: @var{%default-locale-definitions})
5959The list of locale definitions to be compiled and that may be used at
5960run time. @xref{Locales}.
7313a52e 5961
34760ae7
LC
5962@item @code{locale-libcs} (default: @code{(list @var{glibc})})
5963The list of GNU@tie{}libc packages whose locale data and tools are used
5964to build the locale definitions. @xref{Locales}, for compatibility
5965considerations that justify this option.
5966
996ed739
LC
5967@item @code{name-service-switch} (default: @var{%default-nss})
5968Configuration of libc's name service switch (NSS)---a
5969@code{<name-service-switch>} object. @xref{Name Service Switch}, for
5970details.
5971
7313a52e 5972@item @code{services} (default: @var{%base-services})
28d939af 5973A list of service objects denoting system services. @xref{Services}.
7313a52e
LC
5974
5975@item @code{pam-services} (default: @code{(base-pam-services)})
5976@cindex PAM
5977@cindex pluggable authentication modules
5978Linux @dfn{pluggable authentication module} (PAM) services.
5979@c FIXME: Add xref to PAM services section.
5980
5981@item @code{setuid-programs} (default: @var{%setuid-programs})
5982List of string-valued G-expressions denoting setuid programs.
5983@xref{Setuid Programs}.
5984
f5a9ffa0
AK
5985@item @code{sudoers-file} (default: @var{%sudoers-specification})
5986@cindex sudoers file
84765839
LC
5987The contents of the @file{/etc/sudoers} file as a file-like object
5988(@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7313a52e
LC
5989
5990This file specifies which users can use the @command{sudo} command, what
5991they are allowed to do, and what privileges they may gain. The default
5992is that only @code{root} and members of the @code{wheel} group may use
5993@code{sudo}.
5994
5995@end table
5996@end deftp
5997
cf4a9129
LC
5998@node File Systems
5999@subsection File Systems
b81e1947 6000
cf4a9129
LC
6001The list of file systems to be mounted is specified in the
6002@code{file-systems} field of the operating system's declaration
6003(@pxref{Using the Configuration System}). Each file system is declared
6004using the @code{file-system} form, like this:
b81e1947
LC
6005
6006@example
cf4a9129
LC
6007(file-system
6008 (mount-point "/home")
6009 (device "/dev/sda3")
6010 (type "ext4"))
b81e1947
LC
6011@end example
6012
cf4a9129
LC
6013As usual, some of the fields are mandatory---those shown in the example
6014above---while others can be omitted. These are described below.
b81e1947 6015
cf4a9129
LC
6016@deftp {Data Type} file-system
6017Objects of this type represent file systems to be mounted. They
6018contain the following members:
5ff3c4b8 6019
cf4a9129
LC
6020@table @asis
6021@item @code{type}
6022This is a string specifying the type of the file system---e.g.,
6023@code{"ext4"}.
5ff3c4b8 6024
cf4a9129
LC
6025@item @code{mount-point}
6026This designates the place where the file system is to be mounted.
b81e1947 6027
cf4a9129
LC
6028@item @code{device}
6029This names the ``source'' of the file system. By default it is the name
6030of a node under @file{/dev}, but its meaning depends on the @code{title}
6031field described below.
401c53c4 6032
cf4a9129
LC
6033@item @code{title} (default: @code{'device})
6034This is a symbol that specifies how the @code{device} field is to be
6035interpreted.
401c53c4 6036
cf4a9129
LC
6037When it is the symbol @code{device}, then the @code{device} field is
6038interpreted as a file name; when it is @code{label}, then @code{device}
6039is interpreted as a partition label name; when it is @code{uuid},
6040@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 6041
661a1d79
LC
6042UUIDs may be converted from their string representation (as shown by the
6043@command{tune2fs -l} command) using the @code{uuid} form, like this:
6044
6045@example
6046(file-system
6047 (mount-point "/home")
6048 (type "ext4")
6049 (title 'uuid)
6050 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
6051@end example
6052
cf4a9129 6053The @code{label} and @code{uuid} options offer a way to refer to disk
661a1d79
LC
6054partitions without having to hard-code their actual device
6055name@footnote{Note that, while it is tempting to use
6056@file{/dev/disk/by-uuid} and similar device names to achieve the same
6057result, this is not recommended: These special device nodes are created
6058by the udev daemon and may be unavailable at the time the device is
6059mounted.}.
da7cabd4 6060
5f86a66e
LC
6061However, when a file system's source is a mapped device (@pxref{Mapped
6062Devices}), its @code{device} field @emph{must} refer to the mapped
6063device name---e.g., @file{/dev/mapper/root-partition}---and consequently
6064@code{title} must be set to @code{'device}. This is required so that
6065the system knows that mounting the file system depends on having the
6066corresponding device mapping established.
6067
cf4a9129
LC
6068@item @code{flags} (default: @code{'()})
6069This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
6070include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
6071access to special files), @code{no-suid} (ignore setuid and setgid
6072bits), and @code{no-exec} (disallow program execution.)
da7cabd4 6073
cf4a9129
LC
6074@item @code{options} (default: @code{#f})
6075This is either @code{#f}, or a string denoting mount options.
da7cabd4 6076
be21979d
LC
6077@item @code{mount?} (default: @code{#t})
6078This value indicates whether to automatically mount the file system when
6079the system is brought up. When set to @code{#f}, the file system gets
6080an entry in @file{/etc/fstab} (read by the @command{mount} command) but
6081is not automatically mounted.
6082
cf4a9129
LC
6083@item @code{needed-for-boot?} (default: @code{#f})
6084This Boolean value indicates whether the file system is needed when
6085booting. If that is true, then the file system is mounted when the
6086initial RAM disk (initrd) is loaded. This is always the case, for
6087instance, for the root file system.
da7cabd4 6088
cf4a9129
LC
6089@item @code{check?} (default: @code{#t})
6090This Boolean indicates whether the file system needs to be checked for
6091errors before being mounted.
f9cc8971 6092
4e469051
LC
6093@item @code{create-mount-point?} (default: @code{#f})
6094When true, the mount point is created if it does not exist yet.
6095
e51710d1
LC
6096@item @code{dependencies} (default: @code{'()})
6097This is a list of @code{<file-system>} objects representing file systems
6098that must be mounted before (and unmounted after) this one.
6099
6100As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
6101a dependency of @file{/sys/fs/cgroup/cpu} and
6102@file{/sys/fs/cgroup/memory}.
6103
cf4a9129
LC
6104@end table
6105@end deftp
da7cabd4 6106
a69576ea
LC
6107The @code{(gnu system file-systems)} exports the following useful
6108variables.
6109
6110@defvr {Scheme Variable} %base-file-systems
6111These are essential file systems that are required on normal systems,
cc0e575a 6112such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
3392ce5d
LC
6113below.) Operating system declarations should always contain at least
6114these.
a69576ea
LC
6115@end defvr
6116
7f239fd3
LC
6117@defvr {Scheme Variable} %pseudo-terminal-file-system
6118This is the file system to be mounted as @file{/dev/pts}. It supports
6119@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
6120functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
6121Manual}). Pseudo-terminals are used by terminal emulators such as
6122@command{xterm}.
6123@end defvr
6124
db17ae5c
LC
6125@defvr {Scheme Variable} %shared-memory-file-system
6126This file system is mounted as @file{/dev/shm} and is used to support
6127memory sharing across processes (@pxref{Memory-mapped I/O,
6128@code{shm_open},, libc, The GNU C Library Reference Manual}).
6129@end defvr
6130
3392ce5d
LC
6131@defvr {Scheme Variable} %immutable-store
6132This file system performs a read-only ``bind mount'' of
6133@file{/gnu/store}, making it read-only for all the users including
6134@code{root}. This prevents against accidental modification by software
6135running as @code{root} or by system administrators.
6136
6137The daemon itself is still able to write to the store: it remounts it
6138read-write in its own ``name space.''
6139@end defvr
6140
a69576ea
LC
6141@defvr {Scheme Variable} %binary-format-file-system
6142The @code{binfmt_misc} file system, which allows handling of arbitrary
6143executable file types to be delegated to user space. This requires the
6144@code{binfmt.ko} kernel module to be loaded.
6145@end defvr
6146
6147@defvr {Scheme Variable} %fuse-control-file-system
6148The @code{fusectl} file system, which allows unprivileged users to mount
6149and unmount user-space FUSE file systems. This requires the
6150@code{fuse.ko} kernel module to be loaded.
6151@end defvr
6152
510f9d86
LC
6153@node Mapped Devices
6154@subsection Mapped Devices
6155
6156@cindex device mapping
6157@cindex mapped devices
6158The Linux kernel has a notion of @dfn{device mapping}: a block device,
6159such as a hard disk partition, can be @dfn{mapped} into another device,
6160with additional processing over the data that flows through
6161it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
6162concept of a ``mapped device'' and that of a file system: both boil down
6163to @emph{translating} input/output operations made on a file to
6164operations on its backing store. Thus, the Hurd implements mapped
6165devices, like file systems, using the generic @dfn{translator} mechanism
6166(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
6167typical example is encryption device mapping: all writes to the mapped
6168device are encrypted, and all reads are deciphered, transparently.
6169
6170Mapped devices are declared using the @code{mapped-device} form:
6171
6172@example
6173(mapped-device
6174 (source "/dev/sda3")
6175 (target "home")
6176 (type luks-device-mapping))
6177@end example
6178
6179@noindent
6180@cindex disk encryption
6181@cindex LUKS
6182This example specifies a mapping from @file{/dev/sda3} to
6183@file{/dev/mapper/home} using LUKS---the
6184@url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
6185standard mechanism for disk encryption. The @file{/dev/mapper/home}
6186device can then be used as the @code{device} of a @code{file-system}
6187declaration (@pxref{File Systems}). The @code{mapped-device} form is
6188detailed below.
6189
6190@deftp {Data Type} mapped-device
6191Objects of this type represent device mappings that will be made when
6192the system boots up.
6193
9cb426b8
LC
6194@table @code
6195@item source
510f9d86
LC
6196This string specifies the name of the block device to be mapped, such as
6197@code{"/dev/sda3"}.
6198
9cb426b8 6199@item target
510f9d86
LC
6200This string specifies the name of the mapping to be established. For
6201example, specifying @code{"my-partition"} will lead to the creation of
6202the @code{"/dev/mapper/my-partition"} device.
6203
9cb426b8 6204@item type
510f9d86
LC
6205This must be a @code{mapped-device-kind} object, which specifies how
6206@var{source} is mapped to @var{target}.
6207@end table
6208@end deftp
6209
6210@defvr {Scheme Variable} luks-device-mapping
6211This defines LUKS block device encryption using the @command{cryptsetup}
6212command, from the same-named package. This relies on the
6213@code{dm-crypt} Linux kernel module.
6214@end defvr
6215
cf4a9129
LC
6216@node User Accounts
6217@subsection User Accounts
ee85f3db 6218
9bea87a5
LC
6219User accounts and groups are entirely managed through the
6220@code{operating-system} declaration. They are specified with the
6221@code{user-account} and @code{user-group} forms:
ee85f3db 6222
cf4a9129
LC
6223@example
6224(user-account
6225 (name "alice")
6226 (group "users")
24e752c0
LC
6227 (supplementary-groups '("wheel" ;allow use of sudo, etc.
6228 "audio" ;sound card
6229 "video" ;video devices such as webcams
6230 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
6231 (comment "Bob's sister")
6232 (home-directory "/home/alice"))
6233@end example
25083588 6234
9bea87a5
LC
6235When booting or upon completion of @command{guix system reconfigure},
6236the system ensures that only the user accounts and groups specified in
6237the @code{operating-system} declaration exist, and with the specified
6238properties. Thus, account or group creations or modifications made by
6239directly invoking commands such as @command{useradd} are lost upon
6240reconfiguration or reboot. This ensures that the system remains exactly
6241as declared.
6242
cf4a9129
LC
6243@deftp {Data Type} user-account
6244Objects of this type represent user accounts. The following members may
6245be specified:
ee85f3db 6246
cf4a9129
LC
6247@table @asis
6248@item @code{name}
6249The name of the user account.
ee85f3db 6250
cf4a9129
LC
6251@item @code{group}
6252This is the name (a string) or identifier (a number) of the user group
6253this account belongs to.
ee85f3db 6254
cf4a9129
LC
6255@item @code{supplementary-groups} (default: @code{'()})
6256Optionally, this can be defined as a list of group names that this
6257account belongs to.
ee85f3db 6258
cf4a9129
LC
6259@item @code{uid} (default: @code{#f})
6260This is the user ID for this account (a number), or @code{#f}. In the
6261latter case, a number is automatically chosen by the system when the
6262account is created.
ee85f3db 6263
cf4a9129
LC
6264@item @code{comment} (default: @code{""})
6265A comment about the account, such as the account's owner full name.
c8c871d1 6266
cf4a9129
LC
6267@item @code{home-directory}
6268This is the name of the home directory for the account.
ee85f3db 6269
cf4a9129
LC
6270@item @code{shell} (default: Bash)
6271This is a G-expression denoting the file name of a program to be used as
6272the shell (@pxref{G-Expressions}).
ee85f3db 6273
cf4a9129
LC
6274@item @code{system?} (default: @code{#f})
6275This Boolean value indicates whether the account is a ``system''
6276account. System accounts are sometimes treated specially; for instance,
6277graphical login managers do not list them.
ee85f3db 6278
1bd4e6db 6279@anchor{user-account-password}
cf4a9129 6280@item @code{password} (default: @code{#f})
eb59595c
LC
6281You would normally leave this field to @code{#f}, initialize user
6282passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
6283users change it with @command{passwd}. Passwords set with
6284@command{passwd} are of course preserved across reboot and
6285reconfiguration.
eb59595c
LC
6286
6287If you @emph{do} want to have a preset password for an account, then
6288this field must contain the encrypted password, as a string.
5d1f1177
LC
6289@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
6290on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 6291Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 6292
cf4a9129
LC
6293@end table
6294@end deftp
ee85f3db 6295
cf4a9129 6296User group declarations are even simpler:
ee85f3db 6297
cf4a9129
LC
6298@example
6299(user-group (name "students"))
6300@end example
ee85f3db 6301
cf4a9129
LC
6302@deftp {Data Type} user-group
6303This type is for, well, user groups. There are just a few fields:
af8a56b8 6304
cf4a9129
LC
6305@table @asis
6306@item @code{name}
6307The group's name.
ee85f3db 6308
cf4a9129
LC
6309@item @code{id} (default: @code{#f})
6310The group identifier (a number). If @code{#f}, a new number is
6311automatically allocated when the group is created.
ee85f3db 6312
c8fa3426
LC
6313@item @code{system?} (default: @code{#f})
6314This Boolean value indicates whether the group is a ``system'' group.
6315System groups have low numerical IDs.
6316
cf4a9129
LC
6317@item @code{password} (default: @code{#f})
6318What, user groups can have a password? Well, apparently yes. Unless
6319@code{#f}, this field specifies the group's password.
ee85f3db 6320
cf4a9129
LC
6321@end table
6322@end deftp
401c53c4 6323
cf4a9129
LC
6324For convenience, a variable lists all the basic user groups one may
6325expect:
401c53c4 6326
cf4a9129
LC
6327@defvr {Scheme Variable} %base-groups
6328This is the list of basic user groups that users and/or packages expect
6329to be present on the system. This includes groups such as ``root'',
6330``wheel'', and ``users'', as well as groups used to control access to
6331specific devices such as ``audio'', ``disk'', and ``cdrom''.
6332@end defvr
401c53c4 6333
bf87f38a
LC
6334@defvr {Scheme Variable} %base-user-accounts
6335This is the list of basic system accounts that programs may expect to
6336find on a GNU/Linux system, such as the ``nobody'' account.
6337
6338Note that the ``root'' account is not included here. It is a
6339special-case and is automatically added whether or not it is specified.
6340@end defvr
6341
598e19dc
LC
6342@node Locales
6343@subsection Locales
6344
6345@cindex locale
6346A @dfn{locale} defines cultural conventions for a particular language
6347and region of the world (@pxref{Locales,,, libc, The GNU C Library
6348Reference Manual}). Each locale has a name that typically has the form
b2636518 6349@code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
598e19dc
LC
6350@code{fr_LU.utf8} designates the locale for the French language, with
6351cultural conventions from Luxembourg, and using the UTF-8 encoding.
6352
6353@cindex locale definition
6354Usually, you will want to specify the default locale for the machine
6355using the @code{locale} field of the @code{operating-system} declaration
6356(@pxref{operating-system Reference, @code{locale}}).
6357
6358That locale must be among the @dfn{locale definitions} that are known to
6359the system---and these are specified in the @code{locale-definitions}
6360slot of @code{operating-system}. The default value includes locale
c4847f49 6361definitions for some widely used locales, but not for all the available
598e19dc
LC
6362locales, in order to save space.
6363
6364If the locale specified in the @code{locale} field is not among the
6365definitions listed in @code{locale-definitions}, @command{guix system}
6366raises an error. In that case, you should add the locale definition to
6367the @code{locale-definitions} field. For instance, to add the North
6368Frisian locale for Germany, the value of that field may be:
6369
6370@example
6371(cons (locale-definition
6372 (name "fy_DE.utf8") (source "fy_DE"))
6373 %default-locale-definitions)
6374@end example
6375
6376Likewise, to save space, one might want @code{locale-definitions} to
6377list only the locales that are actually used, as in:
6378
6379@example
6380(list (locale-definition
6381 (name "ja_JP.eucjp") (source "ja_JP")
6382 (charset "EUC-JP")))
6383@end example
6384
5c3c1427
LC
6385@vindex LOCPATH
6386The compiled locale definitions are available at
46bd6edd
LC
6387@file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
6388version, which is the default location where the GNU@tie{}libc provided
6389by Guix looks for locale data. This can be overridden using the
6390@code{LOCPATH} environment variable (@pxref{locales-and-locpath,
5c3c1427
LC
6391@code{LOCPATH} and locale packages}).
6392
598e19dc
LC
6393The @code{locale-definition} form is provided by the @code{(gnu system
6394locale)} module. Details are given below.
6395
6396@deftp {Data Type} locale-definition
6397This is the data type of a locale definition.
6398
6399@table @asis
6400
6401@item @code{name}
6402The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
6403Reference Manual}, for more information on locale names.
6404
6405@item @code{source}
6406The name of the source for that locale. This is typically the
6407@code{@var{language}_@var{territory}} part of the locale name.
6408
6409@item @code{charset} (default: @code{"UTF-8"})
6410The ``character set'' or ``code set'' for that locale,
6411@uref{http://www.iana.org/assignments/character-sets, as defined by
6412IANA}.
6413
6414@end table
6415@end deftp
6416
6417@defvr {Scheme Variable} %default-locale-definitions
b2636518
LC
6418An arbitrary list of commonly used UTF-8 locales, used as the default
6419value of the @code{locale-definitions} field of @code{operating-system}
598e19dc 6420declarations.
b2636518
LC
6421
6422@cindex locale name
6423@cindex normalized codeset in locale names
6424These locale definitions use the @dfn{normalized codeset} for the part
6425that follows the dot in the name (@pxref{Using gettextized software,
6426normalized codeset,, libc, The GNU C Library Reference Manual}). So for
6427instance it has @code{uk_UA.utf8} but @emph{not}, say,
6428@code{uk_UA.UTF-8}.
598e19dc 6429@end defvr
401c53c4 6430
34760ae7
LC
6431@subsubsection Locale Data Compatibility Considerations
6432
6433@cindex incompatibility, of locale data
6434@code{operating-system} declarations provide a @code{locale-libcs} field
6435to specify the GNU@tie{}libc packages that are used to compile locale
6436declarations (@pxref{operating-system Reference}). ``Why would I
6437care?'', you may ask. Well, it turns out that the binary format of
6438locale data is occasionally incompatible from one libc version to
6439another.
6440
6441@c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
6442@c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
6443For instance, a program linked against libc version 2.21 is unable to
6444read locale data produced with libc 2.22; worse, that program
6445@emph{aborts} instead of simply ignoring the incompatible locale
6446data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
6447the incompatible locale data, which is already an improvement.}.
6448Similarly, a program linked against libc 2.22 can read most, but not
6449all, the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
6450data is incompatible); thus calls to @code{setlocale} may fail, but
6451programs will not abort.
6452
6453The ``problem'' in GuixSD is that users have a lot of freedom: They can
6454choose whether and when to upgrade software in their profiles, and might
6455be using a libc version different from the one the system administrator
6456used to build the system-wide locale data.
6457
6458Fortunately, unprivileged users can also install their own locale data
6459and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
6460@code{GUIX_LOCPATH} and locale packages}).
6461
6462Still, it is best if the system-wide locale data at
6463@file{/run/current-system/locale} is built for all the libc versions
6464actually in use on the system, so that all the programs can access
6465it---this is especially crucial on a multi-user system. To do that, the
6466administrator can specify several libc packages in the
6467@code{locale-libcs} field of @code{operating-system}:
6468
6469@example
6470(use-package-modules base)
6471
6472(operating-system
6473 ;; @dots{}
6474 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
6475@end example
6476
6477This example would lead to a system containing locale definitions for
6478both libc 2.21 and the current version of libc in
6479@file{/run/current-system/locale}.
6480
6481
cf4a9129
LC
6482@node Services
6483@subsection Services
401c53c4 6484
cf4a9129
LC
6485@cindex system services
6486An important part of preparing an @code{operating-system} declaration is
6487listing @dfn{system services} and their configuration (@pxref{Using the
6488Configuration System}). System services are typically daemons launched
6489when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
6490configuring network access.
6491
6492Services are managed by GNU@tie{}dmd (@pxref{Introduction,,, dmd, GNU
6493dmd Manual}). On a running system, the @command{deco} command allows
6494you to list the available services, show their status, start and stop
6495them, or do other specific operations (@pxref{Jump Start,,, dmd, GNU dmd
6496Manual}). For example:
6497
6498@example
6499# deco status dmd
6500@end example
6501
6502The above command, run as @code{root}, lists the currently defined
6503services. The @command{deco doc} command shows a synopsis of the given
6504service:
6505
6506@example
6507# deco doc nscd
6508Run libc's name service cache daemon (nscd).
6509@end example
6510
6511The @command{start}, @command{stop}, and @command{restart} sub-commands
6512have the effect you would expect. For instance, the commands below stop
6513the nscd service and restart the Xorg display server:
6514
6515@example
6516# deco stop nscd
6517Service nscd has been stopped.
6518# deco restart xorg-server
6519Service xorg-server has been stopped.
6520Service xorg-server has been started.
6521@end example
401c53c4 6522
cf4a9129 6523The following sections document the available services, starting with
d8b94dbd
LC
6524the core services, that may be used in an @code{operating-system}
6525declaration.
401c53c4 6526
cf4a9129
LC
6527@menu
6528* Base Services:: Essential system services.
6529* Networking Services:: Network setup, SSH daemon, etc.
6530* X Window:: Graphical display.
fe1a39d3 6531* Desktop Services:: D-Bus and desktop services.
105369a4 6532* Database Services:: SQL databases.
d8c18af8 6533* Mail Services:: IMAP, POP3, SMTP, and all that.
58724c48 6534* Web Services:: Web servers.
aa4ed923 6535* Various Services:: Other services.
cf4a9129 6536@end menu
401c53c4 6537
cf4a9129
LC
6538@node Base Services
6539@subsubsection Base Services
a1ba8475 6540
cf4a9129
LC
6541The @code{(gnu services base)} module provides definitions for the basic
6542services that one expects from the system. The services exported by
6543this module are listed below.
401c53c4 6544
cf4a9129 6545@defvr {Scheme Variable} %base-services
31771497
LC
6546This variable contains a list of basic services (@pxref{Service Types
6547and Services}, for more information on service objects) one would
cf4a9129
LC
6548expect from the system: a login service (mingetty) on each tty, syslogd,
6549libc's name service cache daemon (nscd), the udev device manager, and
6550more.
401c53c4 6551
cf4a9129
LC
6552This is the default value of the @code{services} field of
6553@code{operating-system} declarations. Usually, when customizing a
6554system, you will want to append services to @var{%base-services}, like
6555this:
401c53c4 6556
cf4a9129 6557@example
fa1e31b8 6558(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
6559@end example
6560@end defvr
401c53c4 6561
be1c2c54 6562@deffn {Scheme Procedure} host-name-service @var{name}
cf4a9129
LC
6563Return a service that sets the host name to @var{name}.
6564@end deffn
401c53c4 6565
66e4f01c
LC
6566@deffn {Scheme Procedure} mingetty-service @var{config}
6567Return a service to run mingetty according to @var{config}, a
6568@code{<mingetty-configuration>} object, which specifies the tty to run, among
6569other things.
cf4a9129 6570@end deffn
401c53c4 6571
66e4f01c
LC
6572@deftp {Data Type} mingetty-configuration
6573This is the data type representing the configuration of Mingetty, which
6574implements console log-in.
6575
6576@table @asis
6577
6578@item @code{tty}
6579The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
6580
6581@item @code{motd}
6582A file-like object containing the ``message of the day''.
6583
6584@item @code{auto-login} (default: @code{#f})
6585When true, this field must be a string denoting the user name under
f9b9a033 6586which the system automatically logs in. When it is @code{#f}, a
66e4f01c
LC
6587user name and password must be entered to log in.
6588
6589@item @code{login-program} (default: @code{#f})
6590This must be either @code{#f}, in which case the default log-in program
6591is used (@command{login} from the Shadow tool suite), or a gexp denoting
6592the name of the log-in program.
6593
6594@item @code{login-pause?} (default: @code{#f})
6595When set to @code{#t} in conjunction with @var{auto-login}, the user
6596will have to press a key before the log-in shell is launched.
6597
6598@item @code{mingetty} (default: @var{mingetty})
6599The Mingetty package to use.
6600
6601@end table
6602@end deftp
6603
6454b333
LC
6604@cindex name service cache daemon
6605@cindex nscd
be1c2c54 6606@deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
4aee6e60 6607 [#:name-services '()]
b893f1ae
LC
6608Return a service that runs libc's name service cache daemon (nscd) with the
6609given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
6610Service Switch}, for an example.
cf4a9129 6611@end deffn
401c53c4 6612
6454b333
LC
6613@defvr {Scheme Variable} %nscd-default-configuration
6614This is the default @code{<nscd-configuration>} value (see below) used
6615by @code{nscd-service}. This uses the caches defined by
6616@var{%nscd-default-caches}; see below.
6617@end defvr
6618
6619@deftp {Data Type} nscd-configuration
6620This is the type representing the name service cache daemon (nscd)
6621configuration.
6622
6623@table @asis
6624
b893f1ae
LC
6625@item @code{name-services} (default: @code{'()})
6626List of packages denoting @dfn{name services} that must be visible to
6627the nscd---e.g., @code{(list @var{nss-mdns})}.
6628
6629@item @code{glibc} (default: @var{glibc})
6630Package object denoting the GNU C Library providing the @command{nscd}
6631command.
6632
6454b333
LC
6633@item @code{log-file} (default: @code{"/var/log/nscd.log"})
6634Name of nscd's log file. This is where debugging output goes when
6635@code{debug-level} is strictly positive.
6636
6637@item @code{debug-level} (default: @code{0})
6638Integer denoting the debugging levels. Higher numbers mean more
6639debugging output is logged.
6640
6641@item @code{caches} (default: @var{%nscd-default-caches})
6642List of @code{<nscd-cache>} objects denoting things to be cached; see
6643below.
6644
6645@end table
6646@end deftp
6647
6648@deftp {Data Type} nscd-cache
6649Data type representing a cache database of nscd and its parameters.
6650
6651@table @asis
6652
6653@item @code{database}
6654This is a symbol representing the name of the database to be cached.
6655Valid values are @code{passwd}, @code{group}, @code{hosts}, and
6656@code{services}, which designate the corresponding NSS database
6657(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
6658
6659@item @code{positive-time-to-live}
6660@itemx @code{negative-time-to-live} (default: @code{20})
6661A number representing the number of seconds during which a positive or
6662negative lookup result remains in cache.
6663
6664@item @code{check-files?} (default: @code{#t})
6665Whether to check for updates of the files corresponding to
6666@var{database}.
6667
6668For instance, when @var{database} is @code{hosts}, setting this flag
6669instructs nscd to check for updates in @file{/etc/hosts} and to take
6670them into account.
6671
6672@item @code{persistent?} (default: @code{#t})
6673Whether the cache should be stored persistently on disk.
6674
6675@item @code{shared?} (default: @code{#t})
6676Whether the cache should be shared among users.
6677
6678@item @code{max-database-size} (default: 32@tie{}MiB)
6679Maximum size in bytes of the database cache.
6680
6681@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
6682@c settings, so leave them out.
6683
6684@end table
6685@end deftp
6686
6687@defvr {Scheme Variable} %nscd-default-caches
6688List of @code{<nscd-cache>} objects used by default by
6689@code{nscd-configuration} (see above.)
6690
6691It enables persistent and aggressive caching of service and host name
6692lookups. The latter provides better host name lookup performance,
6693resilience in the face of unreliable name servers, and also better
6694privacy---often the result of host name lookups is in local cache, so
6695external name servers do not even need to be queried.
6696@end defvr
6697
6698
be1c2c54 6699@deffn {Scheme Procedure} syslog-service [#:config-file #f]
1bb76f75
AK
6700Return a service that runs @code{syslogd}. If configuration file name
6701@var{config-file} is not specified, use some reasonable default
cf4a9129
LC
6702settings.
6703@end deffn
401c53c4 6704
0adfe95a
LC
6705@anchor{guix-configuration-type}
6706@deftp {Data Type} guix-configuration
6707This data type represents the configuration of the Guix build daemon.
6708@xref{Invoking guix-daemon}, for more information.
6709
6710@table @asis
6711@item @code{guix} (default: @var{guix})
6712The Guix package to use.
401c53c4 6713
0adfe95a
LC
6714@item @code{build-group} (default: @code{"guixbuild"})
6715Name of the group for build user accounts.
401c53c4 6716
0adfe95a
LC
6717@item @code{build-accounts} (default: @code{10})
6718Number of build user accounts to create.
401c53c4 6719
0adfe95a
LC
6720@item @code{authorize-key?} (default: @code{#t})
6721Whether to authorize the substitute key for @code{hydra.gnu.org}
6722(@pxref{Substitutes}).
6723
6724@item @code{use-substitutes?} (default: @code{#t})
6725Whether to use substitutes.
6726
b0b9f6e0
LC
6727@item @code{substitute-urls} (default: @var{%default-substitute-urls})
6728The list of URLs where to look for substitutes by default.
6729
0adfe95a
LC
6730@item @code{extra-options} (default: @code{'()})
6731List of extra command-line options for @command{guix-daemon}.
6732
6733@item @code{lsof} (default: @var{lsof})
6734@itemx @code{lsh} (default: @var{lsh})
6735The lsof and lsh packages to use.
6736
6737@end table
6738@end deftp
6739
6740@deffn {Scheme Procedure} guix-service @var{config}
6741Return a service that runs the Guix build daemon according to
6742@var{config}.
cf4a9129 6743@end deffn
a1ba8475 6744
be1c2c54 6745@deffn {Scheme Procedure} udev-service [#:udev udev]
cf4a9129
LC
6746Run @var{udev}, which populates the @file{/dev} directory dynamically.
6747@end deffn
401c53c4 6748
be1c2c54 6749@deffn {Scheme Procedure} console-keymap-service @var{file}
5eca9459
AK
6750Return a service to load console keymap from @var{file} using
6751@command{loadkeys} command.
6752@end deffn
6753
8664cc88
LC
6754@deffn {Scheme Procedure} gpm-service-type [#:gpm @var{gpm}] @
6755 [#:options]
6756Run @var{gpm}, the general-purpose mouse daemon, with the given
6757command-line @var{options}. GPM allows users to use the mouse in the console,
6758notably to select, copy, and paste text. The default value of @var{options}
6759uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
6760
6761This service is not part of @var{%base-services}.
6762@end deffn
6763
1c52181f
LC
6764@anchor{guix-publish-service}
6765@deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
6766 [#:port 80] [#:host "localhost"]
6767Return a service that runs @command{guix publish} listening on @var{host}
6768and @var{port} (@pxref{Invoking guix publish}).
6769
6770This assumes that @file{/etc/guix} already contains a signing key pair as
6771created by @command{guix archive --generate-key} (@pxref{Invoking guix
6772archive}). If that is not the case, the service will fail to start.
6773@end deffn
6774
a69576ea 6775
cf4a9129
LC
6776@node Networking Services
6777@subsubsection Networking Services
401c53c4 6778
fa1e31b8 6779The @code{(gnu services networking)} module provides services to configure
cf4a9129 6780the network interface.
a1ba8475 6781
a023cca8 6782@cindex DHCP, networking service
be1c2c54 6783@deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
a023cca8
LC
6784Return a service that runs @var{dhcp}, a Dynamic Host Configuration
6785Protocol (DHCP) client, on all the non-loopback network interfaces.
6786@end deffn
6787
be1c2c54 6788@deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
cf4a9129
LC
6789 [#:gateway #f] [#:name-services @code{'()}]
6790Return a service that starts @var{interface} with address @var{ip}. If
6791@var{gateway} is true, it must be a string specifying the default network
6792gateway.
6793@end deffn
8b315a6d 6794
b7d0c494 6795@cindex wicd
87f40011 6796@cindex network management
be1c2c54 6797@deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
87f40011
LC
6798Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
6799management daemon that aims to simplify wired and wireless networking.
6800
6801This service adds the @var{wicd} package to the global profile, providing
6802several commands to interact with the daemon and configure networking:
6803@command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
6804and @command{wicd-curses} user interfaces.
b7d0c494
MW
6805@end deffn
6806
c0a9589d
SB
6807@cindex NetworkManager
6808@deffn {Scheme Procedure} network-manager-service @
6809 [#:network-manager @var{network-manager}]
6810Return a service that runs NetworkManager, a network connection manager
6811that attempting to keep active network connectivity when available.
6812@end deffn
6813
be1c2c54 6814@deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
63854bcb
LC
6815 [#:name-service @var{%ntp-servers}]
6816Return a service that runs the daemon from @var{ntp}, the
6817@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
6818keep the system clock synchronized with that of @var{servers}.
6819@end deffn
6820
6821@defvr {Scheme Variable} %ntp-servers
6822List of host names used as the default NTP servers.
6823@end defvr
6824
375c6108
LC
6825@deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
6826Return a service to run the @uref{https://torproject.org, Tor} anonymous
6827networking daemon.
8b315a6d 6828
375c6108 6829The daemon runs as the @code{tor} unprivileged user. It is passed
6331bde7
LC
6830@var{config-file}, a file-like object, with an additional @code{User tor} line
6831and lines for hidden services added via @code{tor-hidden-service}. Run
6832@command{man tor} for information about the configuration file.
6833@end deffn
6834
24a8ef3b 6835@cindex hidden service
6331bde7
LC
6836@deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
6837Define a new Tor @dfn{hidden service} called @var{name} and implementing
6838@var{mapping}. @var{mapping} is a list of port/host tuples, such as:
6839
6840@example
24a8ef3b
LC
6841 '((22 "127.0.0.1:22")
6842 (80 "127.0.0.1:8080"))
6331bde7
LC
6843@end example
6844
6845In this example, port 22 of the hidden service is mapped to local port 22, and
6846port 80 is mapped to local port 8080.
6847
6629099a
LC
6848This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
6849the @file{hostname} file contains the @code{.onion} host name for the hidden
6331bde7
LC
6850service.
6851
6852See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
6853project's documentation} for more information.
cf4a9129 6854@end deffn
8b315a6d 6855
be1c2c54 6856@deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
4627a464
LC
6857 [#:interface "127.0.0.1"] [#:port 6667] @
6858 [#:extra-settings ""]
6859Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
6860acts as a gateway between IRC and chat networks.
6861
6862The daemon will listen to the interface corresponding to the IP address
6863specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
6864local clients can connect, whereas @code{0.0.0.0} means that connections can
6865come from any networking interface.
6866
6867In addition, @var{extra-settings} specifies a string to append to the
6868configuration file.
6869@end deffn
6870
f4391bec 6871Furthermore, @code{(gnu services ssh)} provides the following service.
8b315a6d 6872
be1c2c54 6873@deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 6874 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
6875 [#:allow-empty-passwords? #f] [#:root-login? #f] @
6876 [#:syslog-output? #t] [#:x11-forwarding? #t] @
6877 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 6878 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
6879Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
6880@var{host-key} must designate a file containing the host key, and readable
6881only by root.
72e25e35 6882
5833bf33
DP
6883When @var{daemonic?} is true, @command{lshd} will detach from the
6884controlling terminal and log its output to syslogd, unless one sets
6885@var{syslog-output?} to false. Obviously, it also makes lsh-service
6886depend on existence of syslogd service. When @var{pid-file?} is true,
6887@command{lshd} writes its PID to the file called @var{pid-file}.
6888
cf4a9129
LC
6889When @var{initialize?} is true, automatically create the seed and host key
6890upon service activation if they do not exist yet. This may take long and
6891require interaction.
8b315a6d 6892
20dd519c
LC
6893When @var{initialize?} is false, it is up to the user to initialize the
6894randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
6895a key pair with the private key stored in file @var{host-key} (@pxref{lshd
6896basics,,, lsh, LSH Manual}).
6897
cf4a9129
LC
6898When @var{interfaces} is empty, lshd listens for connections on all the
6899network interfaces; otherwise, @var{interfaces} must be a list of host names
6900or addresses.
9bf3c1a7 6901
20dd519c
LC
6902@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
6903passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 6904root.
4af2447e 6905
cf4a9129
LC
6906The other options should be self-descriptive.
6907@end deffn
4af2447e 6908
fa0c1d61
LC
6909@defvr {Scheme Variable} %facebook-host-aliases
6910This variable contains a string for use in @file{/etc/hosts}
6911(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
6912line contains a entry that maps a known server name of the Facebook
6913on-line service---e.g., @code{www.facebook.com}---to the local
6914host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
6915
6916This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
6917@code{operating-system} declaration (@pxref{operating-system Reference,
6918@file{/etc/hosts}}):
fa0c1d61
LC
6919
6920@example
6921(use-modules (gnu) (guix))
6922
6923(operating-system
6924 (host-name "mymachine")
6925 ;; ...
6926 (hosts-file
6927 ;; Create a /etc/hosts file with aliases for "localhost"
6928 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
6929 (plain-file "hosts"
6930 (string-append (local-host-aliases host-name)
6931 %facebook-host-aliases))))
fa0c1d61
LC
6932@end example
6933
6934This mechanism can prevent programs running locally, such as Web
6935browsers, from accessing Facebook.
6936@end defvr
6937
965a7332
LC
6938The @code{(gnu services avahi)} provides the following definition.
6939
be1c2c54 6940@deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
965a7332
LC
6941 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
6942 [#:ipv6? #t] [#:wide-area? #f] @
6943 [#:domains-to-browse '()]
6944Return a service that runs @command{avahi-daemon}, a system-wide
6945mDNS/DNS-SD responder that allows for service discovery and
cc9c1f39
LC
6946"zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
6947extends the name service cache daemon (nscd) so that it can resolve
6948@code{.local} host names using
1065bed9
LC
6949@uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
6950add the @var{avahi} package to the system profile so that commands such as
6951@command{avahi-browse} are directly usable.
965a7332
LC
6952
6953If @var{host-name} is different from @code{#f}, use that as the host name to
6954publish for this machine; otherwise, use the machine's actual host name.
6955
6956When @var{publish?} is true, publishing of host names and services is allowed;
6957in particular, avahi-daemon will publish the machine's host name and IP
6958address via mDNS on the local network.
6959
6960When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
6961
6962Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
6963sockets.
6964@end deffn
6965
6966
cf4a9129
LC
6967@node X Window
6968@subsubsection X Window
68ad877c 6969
cf4a9129
LC
6970Support for the X Window graphical display system---specifically
6971Xorg---is provided by the @code{(gnu services xorg)} module. Note that
6972there is no @code{xorg-service} procedure. Instead, the X server is
6973started by the @dfn{login manager}, currently SLiM.
4af2447e 6974
be1c2c54 6975@deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
6976 [#:auto-login? #f] [#:default-user ""] [#:startx] @
6977 [#:theme @var{%default-slim-theme}] @
4bd43bbe 6978 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
6979Return a service that spawns the SLiM graphical login manager, which in
6980turn starts the X display server with @var{startx}, a command as returned by
6981@code{xorg-start-command}.
4af2447e 6982
04e4e6ab
LC
6983@cindex X session
6984
6985SLiM automatically looks for session types described by the @file{.desktop}
6986files in @file{/run/current-system/profile/share/xsessions} and allows users
6987to choose a session from the log-in screen using @kbd{F1}. Packages such as
6988@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
6989adding them to the system-wide set of packages automatically makes them
6990available at the log-in screen.
6991
6992In addition, @file{~/.xsession} files are honored. When available,
6993@file{~/.xsession} must be an executable that starts a window manager
6994and/or other X clients.
6995
cf4a9129
LC
6996When @var{allow-empty-passwords?} is true, allow logins with an empty
6997password. When @var{auto-login?} is true, log in automatically as
6998@var{default-user}.
0ecc3bf3
LC
6999
7000If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
7001@var{theme} must be a gexp denoting the name of a directory containing the
7002theme to use. In that case, @var{theme-name} specifies the name of the
7003theme.
cf4a9129 7004@end deffn
4af2447e 7005
0ecc3bf3
LC
7006@defvr {Scheme Variable} %default-theme
7007@defvrx {Scheme Variable} %default-theme-name
7008The G-Expression denoting the default SLiM theme and its name.
7009@end defvr
7010
be1c2c54 7011@deffn {Scheme Procedure} xorg-start-command [#:guile] @
d1cdd7ba 7012 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 7013Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
7014from @var{xorg-server}. @var{configuration-file} is the server configuration
7015file or a derivation that builds it; when omitted, the result of
7016@code{xorg-configuration-file} is used.
7017
7018Usually the X server is started by a login manager.
7019@end deffn
7020
be1c2c54 7021@deffn {Scheme Procedure} xorg-configuration-file @
12422c9d 7022 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
7023Return a configuration file for the Xorg server containing search paths for
7024all the common drivers.
f703413e
LC
7025
7026@var{drivers} must be either the empty list, in which case Xorg chooses a
7027graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 7028this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
7029
7030Likewise, when @var{resolutions} is the empty list, Xorg chooses an
7031appropriate screen resolution; otherwise, it must be a list of
7032resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
7033
7034Last, @var{extra-config} is a list of strings or objects appended to the
7035@code{text-file*} argument list. It is used to pass extra text to be added
7036verbatim to the configuration file.
f703413e 7037@end deffn
4af2447e 7038
6726282b
LC
7039@deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
7040Add @var{package}, a package for a screen-locker or screen-saver whose
7041command is @var{program}, to the set of setuid programs and add a PAM entry
7042for it. For example:
7043
7044@lisp
7045(screen-locker-service xlockmore "xlock")
7046@end lisp
7047
7048makes the good ol' XlockMore usable.
7049@end deffn
7050
7051
fe1a39d3
LC
7052@node Desktop Services
7053@subsubsection Desktop Services
aa4ed923 7054
fe1a39d3
LC
7055The @code{(gnu services desktop)} module provides services that are
7056usually useful in the context of a ``desktop'' setup---that is, on a
7057machine running a graphical display server, possibly with graphical user
7058interfaces, etc.
aa4ed923 7059
4467be21
LC
7060To simplify things, the module defines a variable containing the set of
7061services that users typically expect on a machine with a graphical
7062environment and networking:
7063
7064@defvr {Scheme Variable} %desktop-services
7065This is a list of services that builds upon @var{%base-services} and
7066adds or adjust services for a typical ``desktop'' setup.
7067
7068In particular, it adds a graphical login manager (@pxref{X Window,
6726282b
LC
7069@code{slim-service}}), screen lockers,
7070a network management tool (@pxref{Networking
4467be21 7071Services, @code{wicd-service}}), energy and color management services,
4650a77e 7072the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
7073the GeoClue location service, an NTP client (@pxref{Networking
7074Services}), the Avahi daemon, and has the name service switch service
7075configured to be able to use @code{nss-mdns} (@pxref{Name Service
7076Switch, mDNS}).
4467be21
LC
7077@end defvr
7078
7079The @var{%desktop-services} variable can be used as the @code{services}
7080field of an @code{operating-system} declaration (@pxref{operating-system
7081Reference, @code{services}}).
7082
0adfe95a
LC
7083The actual service definitions provided by @code{(gnu services dbus)}
7084and @code{(gnu services desktop)} are described below.
4467be21 7085
0adfe95a 7086@deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
fe1a39d3
LC
7087Return a service that runs the ``system bus'', using @var{dbus}, with
7088support for @var{services}.
aa4ed923 7089
fe1a39d3
LC
7090@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
7091facility. Its system bus is used to allow system services to communicate
7092and be notified of system-wide events.
aa4ed923 7093
fe1a39d3
LC
7094@var{services} must be a list of packages that provide an
7095@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
7096and policy files. For example, to allow avahi-daemon to use the system bus,
7097@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
7098@end deffn
7099
0adfe95a 7100@deffn {Scheme Procedure} elogind-service [#:config @var{config}]
4650a77e
AW
7101Return a service that runs the @code{elogind} login and
7102seat management daemon. @uref{https://github.com/andywingo/elogind,
7103Elogind} exposes a D-Bus interface that can be used to know which users
7104are logged in, know what kind of sessions they have open, suspend the
7105system, inhibit system suspend, reboot the system, and other tasks.
7106
7107Elogind handles most system-level power events for a computer, for
7108example suspending the system when a lid is closed, or shutting it down
7109when the power button is pressed.
7110
7111The @var{config} keyword argument specifies the configuration for
7112elogind, and should be the result of a @code{(elogind-configuration
7113(@var{parameter} @var{value})...)} invocation. Available parameters and
7114their default values are:
7115
7116@table @code
7117@item kill-user-processes?
7118@code{#f}
7119@item kill-only-users
7120@code{()}
7121@item kill-exclude-users
7122@code{("root")}
7123@item inhibit-delay-max-seconds
7124@code{5}
7125@item handle-power-key
7126@code{poweroff}
7127@item handle-suspend-key
7128@code{suspend}
7129@item handle-hibernate-key
7130@code{hibernate}
7131@item handle-lid-switch
7132@code{suspend}
7133@item handle-lid-switch-docked
7134@code{ignore}
7135@item power-key-ignore-inhibited?
7136@code{#f}
7137@item suspend-key-ignore-inhibited?
7138@code{#f}
7139@item hibernate-key-ignore-inhibited?
7140@code{#f}
7141@item lid-switch-ignore-inhibited?
7142@code{#t}
7143@item holdoff-timeout-seconds
7144@code{30}
7145@item idle-action
7146@code{ignore}
7147@item idle-action-seconds
7148@code{(* 30 60)}
7149@item runtime-directory-size-percent
7150@code{10}
7151@item runtime-directory-size
7152@code{#f}
7153@item remove-ipc?
7154@code{#t}
7155@item suspend-state
7156@code{("mem" "standby" "freeze")}
7157@item suspend-mode
7158@code{()}
7159@item hibernate-state
7160@code{("disk")}
7161@item hibernate-mode
7162@code{("platform" "shutdown")}
7163@item hybrid-sleep-state
7164@code{("disk")}
7165@item hybrid-sleep-mode
7166@code{("suspend" "platform" "shutdown")}
7167@end table
7168@end deffn
7169
be1c2c54 7170@deffn {Scheme Procedure} polkit-service @
4650a77e 7171 [#:polkit @var{polkit}]
222e3319
LC
7172Return a service that runs the
7173@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
7174management service}, which allows system administrators to grant access to
7175privileged operations in a structured way. By querying the Polkit service, a
7176privileged system component can know when it should grant additional
7177capabilities to ordinary users. For example, an ordinary user can be granted
7178the capability to suspend the system if the user is logged in locally.
4650a77e
AW
7179@end deffn
7180
be1c2c54 7181@deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
be234128
AW
7182 [#:watts-up-pro? #f] @
7183 [#:poll-batteries? #t] @
7184 [#:ignore-lid? #f] @
7185 [#:use-percentage-for-policy? #f] @
7186 [#:percentage-low 10] @
7187 [#:percentage-critical 3] @
7188 [#:percentage-action 2] @
7189 [#:time-low 1200] @
7190 [#:time-critical 300] @
7191 [#:time-action 120] @
7192 [#:critical-power-action 'hybrid-sleep]
7193Return a service that runs @uref{http://upower.freedesktop.org/,
7194@command{upowerd}}, a system-wide monitor for power consumption and battery
7195levels, with the given configuration settings. It implements the
7196@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
7197GNOME.
7198@end deffn
7199
2b9e0a94
LC
7200@deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
7201Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
7202UDisks}, a @dfn{disk management} daemon that provides user interfaces with
7203notifications and ways to mount/unmount disks. Programs that talk to UDisks
7204include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
7205@end deffn
7206
be1c2c54 7207@deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7ce597ff
AW
7208Return a service that runs @command{colord}, a system service with a D-Bus
7209interface to manage the color profiles of input and output devices such as
7210screens and scanners. It is notably used by the GNOME Color Manager graphical
7211tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
7212site} for more information.
7213@end deffn
7214
cee32ee4
AW
7215@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
7216Return an configuration allowing an application to access GeoClue
7217location data. @var{name} is the Desktop ID of the application, without
7218the @code{.desktop} part. If @var{allowed?} is true, the application
7219will have access to location information by default. The boolean
7220@var{system?} value indicates that an application is a system component
7221or not. Finally @var{users} is a list of UIDs of all users for which
7222this application is allowed location info access. An empty users list
7223means that all users are allowed.
7224@end deffn
7225
7226@defvr {Scheme Variable} %standard-geoclue-applications
7227The standard list of well-known GeoClue application configurations,
7228granting authority to GNOME's date-and-time utility to ask for the
7229current location in order to set the time zone, and allowing the Firefox
7230(IceCat) and Epiphany web browsers to request location information.
7231Firefox and Epiphany both query the user before allowing a web page to
7232know the user's location.
7233@end defvr
7234
be1c2c54 7235@deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
cee32ee4
AW
7236 [#:whitelist '()] @
7237 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
7238 [#:submit-data? #f]
7239 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
7240 [#:submission-nick "geoclue"] @
7241 [#:applications %standard-geoclue-applications]
7242Return a service that runs the GeoClue location service. This service
7243provides a D-Bus interface to allow applications to request access to a
7244user's physical location, and optionally to add information to online
7245location databases. See
7246@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
7247web site} for more information.
7248@end deffn
7249
105369a4
DT
7250@node Database Services
7251@subsubsection Database Services
7252
7253The @code{(gnu services databases)} module provides the following service.
7254
be1c2c54 7255@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
105369a4
DT
7256 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
7257Return a service that runs @var{postgresql}, the PostgreSQL database
7258server.
7259
7260The PostgreSQL daemon loads its runtime configuration from
7261@var{config-file} and stores the database cluster in
7262@var{data-directory}.
7263@end deffn
fe1a39d3 7264
d8c18af8
AW
7265@node Mail Services
7266@subsubsection Mail Services
7267
7268The @code{(gnu services mail)} module provides Guix service definitions
7269for mail services. Currently the only implemented service is Dovecot,
7270an IMAP, POP3, and LMTP server.
7271
7272Guix does not yet have a mail transfer agent (MTA), although for some
7273lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
7274is needed to properly integrate a full MTA, such as Postfix. Patches
7275welcome!
7276
7277To add an IMAP/POP3 server to a GuixSD system, add a
7278@code{dovecot-service} to the operating system definition:
7279
7280@deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
7281Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
7282@end deffn
7283
7284By default, Dovecot doesn't need much configuration; the default
7285configuration object created by @code{(dovecot-configuration)} will
7286suffice if your mail is delivered to @code{~/Maildir}. A self-signed
7287certificate will be generated for TLS-protected connections, though
7288Dovecot will also listen on cleartext ports by default. There are a
7289number of options though which mail administrators might need to change,
7290and as is the case with other services, Guix allows the system
7291administrator to specify these parameters via a uniform Scheme interface.
7292
7293For example, to specify that mail is located at @code{maildir~/.mail},
7294one would instantiate the Dovecot service like this:
7295
7296@example
7297(dovecot-service #:config
7298 (dovecot-configuration
7299 (mail-location "maildir:~/.mail")))
7300@end example
7301
7302The available configuration parameters follow. Each parameter
7303definition is preceded by its type; for example, @samp{string-list foo}
7304indicates that the @code{foo} parameter should be specified as a list of
7305strings. There is also a way to specify the configuration as a string,
7306if you have an old @code{dovecot.conf} file that you want to port over
7307from some other system; see the end for more details.
7308
7309@c The following documentation was initially generated by
7310@c (generate-documentation) in (gnu services mail). Manually maintained
7311@c documentation is better, so we shouldn't hesitate to edit below as
7312@c needed. However if the change you want to make to this documentation
7313@c can be done in an automated way, it's probably easier to change
7314@c (generate-documentation) than to make it below and have to deal with
7315@c the churn as dovecot updates.
7316
7317Available @code{dovecot-configuration} fields are:
7318
7319@deftypevr {@code{dovecot-configuration} parameter} package dovecot
7320The dovecot package.
7321@end deftypevr
7322
7323@deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
7324A list of IPs or hosts where to listen in for connections. @samp{*}
7325listens in all IPv4 interfaces, @samp{::} listens in all IPv6
7326interfaces. If you want to specify non-default ports or anything more
7327complex, customize the address and port fields of the
7328@samp{inet-listener} of the specific services you are interested in.
7329@end deftypevr
7330
7331@deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
7332List of protocols we want to serve. Available protocols include
7333@samp{imap}, @samp{pop3}, and @samp{lmtp}.
7334
7335Available @code{protocol-configuration} fields are:
7336
7337@deftypevr {@code{protocol-configuration} parameter} string name
7338The name of the protocol.
7339@end deftypevr
7340
7341@deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
7342UNIX socket path to master authentication server to find users.
7343This is used by imap (for shared users) and lda.
7344Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
7345@end deftypevr
7346
7347@deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
7348Space separated list of plugins to load.
7349@end deftypevr
7350
7351@deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
7352Maximum number of IMAP connections allowed for a user from each IP
7353address. NOTE: The username is compared case-sensitively.
7354Defaults to @samp{10}.
7355@end deftypevr
7356
7357@end deftypevr
7358
7359@deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
7360List of services to enable. Available services include @samp{imap},
7361@samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
7362@samp{lmtp}.
7363
7364Available @code{service-configuration} fields are:
7365
7366@deftypevr {@code{service-configuration} parameter} string kind
7367The service kind. Valid values include @code{director},
7368@code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
7369@code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
7370@code{tcpwrap}, @code{quota-warning}, or anything else.
7371@end deftypevr
7372
7373@deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
7374Listeners for the service. A listener is either an
7375@code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
7376an @code{inet-listener-configuration}.
7377Defaults to @samp{()}.
7378
7379Available @code{unix-listener-configuration} fields are:
7380
7381@deftypevr {@code{unix-listener-configuration} parameter} file-name path
7382The file name on which to listen.
7383@end deftypevr
7384
7385@deftypevr {@code{unix-listener-configuration} parameter} string mode
7386The access mode for the socket.
7387Defaults to @samp{"0600"}.
7388@end deftypevr
7389
7390@deftypevr {@code{unix-listener-configuration} parameter} string user
f9b9a033 7391The user to own the socket.
d8c18af8
AW
7392Defaults to @samp{""}.
7393@end deftypevr
7394
7395@deftypevr {@code{unix-listener-configuration} parameter} string group
7396The group to own the socket.
7397Defaults to @samp{""}.
7398@end deftypevr
7399
7400
7401Available @code{fifo-listener-configuration} fields are:
7402
7403@deftypevr {@code{fifo-listener-configuration} parameter} file-name path
7404The file name on which to listen.
7405@end deftypevr
7406
7407@deftypevr {@code{fifo-listener-configuration} parameter} string mode
7408The access mode for the socket.
7409Defaults to @samp{"0600"}.
7410@end deftypevr
7411
7412@deftypevr {@code{fifo-listener-configuration} parameter} string user
f9b9a033 7413The user to own the socket.
d8c18af8
AW
7414Defaults to @samp{""}.
7415@end deftypevr
7416
7417@deftypevr {@code{fifo-listener-configuration} parameter} string group
7418The group to own the socket.
7419Defaults to @samp{""}.
7420@end deftypevr
7421
7422
7423Available @code{inet-listener-configuration} fields are:
7424
7425@deftypevr {@code{inet-listener-configuration} parameter} string protocol
7426The protocol to listen for.
7427@end deftypevr
7428
7429@deftypevr {@code{inet-listener-configuration} parameter} string address
7430The address on which to listen, or empty for all addresses.
7431Defaults to @samp{""}.
7432@end deftypevr
7433
7434@deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
7435The port on which to listen.
7436@end deftypevr
7437
7438@deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
7439Whether to use SSL for this service; @samp{yes}, @samp{no}, or
7440@samp{required}.
7441Defaults to @samp{#t}.
7442@end deftypevr
7443
7444@end deftypevr
7445
7446@deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
7447Number of connections to handle before starting a new process.
7448Typically the only useful values are 0 (unlimited) or 1. 1 is more
7449secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
7450Defaults to @samp{1}.
7451@end deftypevr
7452
7453@deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
7454Number of processes to always keep waiting for more connections.
7455Defaults to @samp{0}.
7456@end deftypevr
7457
7458@deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
7459If you set @samp{service-count 0}, you probably need to grow
7460this.
7461Defaults to @samp{256000000}.
7462@end deftypevr
7463
7464@end deftypevr
7465
7466@deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
7467Dict configuration, as created by the @code{dict-configuration}
7468constructor.
7469
7470Available @code{dict-configuration} fields are:
7471
7472@deftypevr {@code{dict-configuration} parameter} free-form-fields entries
7473A list of key-value pairs that this dict should hold.
7474Defaults to @samp{()}.
7475@end deftypevr
7476
7477@end deftypevr
7478
7479@deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
7480List of passdb configurations, each one created by the
7481@code{passdb-configuration} constructor.
7482
7483Available @code{passdb-configuration} fields are:
7484
7485@deftypevr {@code{passdb-configuration} parameter} string driver
7486The driver that the passdb should use. Valid values include
7487@samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
7488@samp{static}.
7489Defaults to @samp{"pam"}.
7490@end deftypevr
7491
7492@deftypevr {@code{passdb-configuration} parameter} free-form-args args
7493A list of key-value args to the passdb driver.
7494Defaults to @samp{()}.
7495@end deftypevr
7496
7497@end deftypevr
7498
7499@deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
7500List of userdb configurations, each one created by the
7501@code{userdb-configuration} constructor.
7502
7503Available @code{userdb-configuration} fields are:
7504
7505@deftypevr {@code{userdb-configuration} parameter} string driver
7506The driver that the userdb should use. Valid values include
7507@samp{passwd} and @samp{static}.
7508Defaults to @samp{"passwd"}.
7509@end deftypevr
7510
7511@deftypevr {@code{userdb-configuration} parameter} free-form-args args
7512A list of key-value args to the userdb driver.
7513Defaults to @samp{()}.
7514@end deftypevr
7515
7516@deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
7517Override fields from passwd.
7518Defaults to @samp{()}.
7519@end deftypevr
7520
7521@end deftypevr
7522
7523@deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
7524Plug-in configuration, created by the @code{plugin-configuration}
7525constructor.
7526@end deftypevr
7527
7528@deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
7529List of namespaces. Each item in the list is created by the
7530@code{namespace-configuration} constructor.
7531
7532Available @code{namespace-configuration} fields are:
7533
7534@deftypevr {@code{namespace-configuration} parameter} string name
7535Name for this namespace.
7536@end deftypevr
7537
7538@deftypevr {@code{namespace-configuration} parameter} string type
7539Namespace type: @samp{private}, @samp{shared} or @samp{public}.
7540Defaults to @samp{"private"}.
7541@end deftypevr
7542
7543@deftypevr {@code{namespace-configuration} parameter} string separator
7544Hierarchy separator to use. You should use the same separator for
7545all namespaces or some clients get confused. @samp{/} is usually a good
7546one. The default however depends on the underlying mail storage
7547format.
7548Defaults to @samp{""}.
7549@end deftypevr
7550
7551@deftypevr {@code{namespace-configuration} parameter} string prefix
7552Prefix required to access this namespace. This needs to be
7553different for all namespaces. For example @samp{Public/}.
7554Defaults to @samp{""}.
7555@end deftypevr
7556
7557@deftypevr {@code{namespace-configuration} parameter} string location
7558Physical location of the mailbox. This is in same format as
7559mail_location, which is also the default for it.
7560Defaults to @samp{""}.
7561@end deftypevr
7562
7563@deftypevr {@code{namespace-configuration} parameter} boolean inbox?
7564There can be only one INBOX, and this setting defines which
7565namespace has it.
7566Defaults to @samp{#f}.
7567@end deftypevr
7568
7569@deftypevr {@code{namespace-configuration} parameter} boolean hidden?
7570If namespace is hidden, it's not advertised to clients via NAMESPACE
7571extension. You'll most likely also want to set @samp{list? #f}. This is mostly
7572useful when converting from another server with different namespaces
7573which you want to deprecate but still keep working. For example you can
7574create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
7575and @samp{mail/}.
7576Defaults to @samp{#f}.
7577@end deftypevr
7578
7579@deftypevr {@code{namespace-configuration} parameter} boolean list?
7580Show the mailboxes under this namespace with LIST command. This
7581makes the namespace visible for clients that don't support NAMESPACE
7582extension. The special @code{children} value lists child mailboxes, but
7583hides the namespace prefix.
7584Defaults to @samp{#t}.
7585@end deftypevr
7586
7587@deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
7588Namespace handles its own subscriptions. If set to @code{#f}, the
7589parent namespace handles them. The empty prefix should always have this
7590as @code{#t}.)
7591Defaults to @samp{#t}.
7592@end deftypevr
7593
7594@deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
7595List of predefined mailboxes in this namespace.
7596Defaults to @samp{()}.
7597
7598Available @code{mailbox-configuration} fields are:
7599
7600@deftypevr {@code{mailbox-configuration} parameter} string name
7601Name for this mailbox.
7602@end deftypevr
7603
7604@deftypevr {@code{mailbox-configuration} parameter} string auto
7605@samp{create} will automatically create this mailbox.
7606@samp{subscribe} will both create and subscribe to the mailbox.
7607Defaults to @samp{"no"}.
7608@end deftypevr
7609
7610@deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
7611List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
7612Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
7613@code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
7614Defaults to @samp{()}.
7615@end deftypevr
7616
7617@end deftypevr
7618
7619@end deftypevr
7620
7621@deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
7622Base directory where to store runtime data.
7623Defaults to @samp{"/var/run/dovecot/"}.
7624@end deftypevr
7625
7626@deftypevr {@code{dovecot-configuration} parameter} string login-greeting
7627Greeting message for clients.
7628Defaults to @samp{"Dovecot ready."}.
7629@end deftypevr
7630
7631@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
7632List of trusted network ranges. Connections from these IPs are
7633allowed to override their IP addresses and ports (for logging and for
7634authentication checks). @samp{disable-plaintext-auth} is also ignored
7635for these networks. Typically you'd specify your IMAP proxy servers
7636here.
7637Defaults to @samp{()}.
7638@end deftypevr
7639
7640@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
7641List of login access check sockets (e.g. tcpwrap).
7642Defaults to @samp{()}.
7643@end deftypevr
7644
7645@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
7646Show more verbose process titles (in ps). Currently shows user name
7647and IP address. Useful for seeing who are actually using the IMAP
7648processes (e.g. shared mailboxes or if same uid is used for multiple
7649accounts).
7650Defaults to @samp{#f}.
7651@end deftypevr
7652
7653@deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
7654Should all processes be killed when Dovecot master process shuts down.
7655Setting this to @code{#f} means that Dovecot can be upgraded without
7656forcing existing client connections to close (although that could also
7657be a problem if the upgrade is e.g. because of a security fix).
7658Defaults to @samp{#t}.
7659@end deftypevr
7660
7661@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
7662If non-zero, run mail commands via this many connections to doveadm
7663server, instead of running them directly in the same process.
7664Defaults to @samp{0}.
7665@end deftypevr
7666
7667@deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
7668UNIX socket or host:port used for connecting to doveadm server.
7669Defaults to @samp{"doveadm-server"}.
7670@end deftypevr
7671
7672@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
7673List of environment variables that are preserved on Dovecot startup
7674and passed down to all of its child processes. You can also give
7675key=value pairs to always set specific settings.
7676@end deftypevr
7677
7678@deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
7679Disable LOGIN command and all other plaintext authentications unless
7680SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
7681matches the local IP (i.e. you're connecting from the same computer),
7682the connection is considered secure and plaintext authentication is
7683allowed. See also ssl=required setting.
7684Defaults to @samp{#t}.
7685@end deftypevr
7686
7687@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
7688Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
7689Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
7690for caching to be used.
7691Defaults to @samp{0}.
7692@end deftypevr
7693
7694@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
7695Time to live for cached data. After TTL expires the cached record
7696is no longer used, *except* if the main database lookup returns internal
7697failure. We also try to handle password changes automatically: If
7698user's previous authentication was successful, but this one wasn't, the
7699cache isn't used. For now this works only with plaintext
7700authentication.
7701Defaults to @samp{"1 hour"}.
7702@end deftypevr
7703
7704@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
7705TTL for negative hits (user not found, password mismatch).
77060 disables caching them completely.
7707Defaults to @samp{"1 hour"}.
7708@end deftypevr
7709
7710@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
7711List of realms for SASL authentication mechanisms that need them.
7712You can leave it empty if you don't want to support multiple realms.
7713Many clients simply use the first one listed here, so keep the default
7714realm first.
7715Defaults to @samp{()}.
7716@end deftypevr
7717
7718@deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
7719Default realm/domain to use if none was specified. This is used for
7720both SASL realms and appending @@domain to username in plaintext
7721logins.
7722Defaults to @samp{""}.
7723@end deftypevr
7724
7725@deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
7726List of allowed characters in username. If the user-given username
7727contains a character not listed in here, the login automatically fails.
7728This is just an extra check to make sure user can't exploit any
7729potential quote escaping vulnerabilities with SQL/LDAP databases. If
7730you want to allow all characters, set this value to empty.
7731Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
7732@end deftypevr
7733
7734@deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
7735Username character translations before it's looked up from
7736databases. The value contains series of from -> to characters. For
7737example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
7738translated to @samp{@@}.
7739Defaults to @samp{""}.
7740@end deftypevr
7741
7742@deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
7743Username formatting before it's looked up from databases. You can
7744use the standard variables here, e.g. %Lu would lowercase the username,
7745%n would drop away the domain if it was given, or @samp{%n-AT-%d} would
7746change the @samp{@@} into @samp{-AT-}. This translation is done after
7747@samp{auth-username-translation} changes.
7748Defaults to @samp{"%Lu"}.
7749@end deftypevr
7750
7751@deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
7752If you want to allow master users to log in by specifying the master
7753username within the normal username string (i.e. not using SASL
7754mechanism's support for it), you can specify the separator character
7755here. The format is then <username><separator><master username>.
7756UW-IMAP uses @samp{*} as the separator, so that could be a good
7757choice.
7758Defaults to @samp{""}.
7759@end deftypevr
7760
7761@deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
7762Username to use for users logging in with ANONYMOUS SASL
7763mechanism.
7764Defaults to @samp{"anonymous"}.
7765@end deftypevr
7766
7767@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
7768Maximum number of dovecot-auth worker processes. They're used to
7769execute blocking passdb and userdb queries (e.g. MySQL and PAM).
7770They're automatically created and destroyed as needed.
7771Defaults to @samp{30}.
7772@end deftypevr
7773
7774@deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
7775Host name to use in GSSAPI principal names. The default is to use
7776the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
7777allow all keytab entries.
7778Defaults to @samp{""}.
7779@end deftypevr
7780
7781@deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
7782Kerberos keytab to use for the GSSAPI mechanism. Will use the
7783system default (usually /etc/krb5.keytab) if not specified. You may
7784need to change the auth service to run as root to be able to read this
7785file.
7786Defaults to @samp{""}.
7787@end deftypevr
7788
7789@deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
7790Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
7791and @samp{ntlm-auth} helper.
7792<doc/wiki/Authentication/Mechanisms/Winbind.txt>.
7793Defaults to @samp{#f}.
7794@end deftypevr
7795
7796@deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
7797Path for Samba's @samp{ntlm-auth} helper binary.
7798Defaults to @samp{"/usr/bin/ntlm_auth"}.
7799@end deftypevr
7800
7801@deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
7802Time to delay before replying to failed authentications.
7803Defaults to @samp{"2 secs"}.
7804@end deftypevr
7805
7806@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
7807Require a valid SSL client certificate or the authentication
7808fails.
7809Defaults to @samp{#f}.
7810@end deftypevr
7811
7812@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
7813Take the username from client's SSL certificate, using
7814@code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
7815CommonName.
7816Defaults to @samp{#f}.
7817@end deftypevr
7818
7819@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
7820List of wanted authentication mechanisms. Supported mechanisms are:
7821@samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
7822@samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
7823@samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
7824@samp{disable-plaintext-auth} setting.
7825@end deftypevr
7826
7827@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
7828List of IPs or hostnames to all director servers, including ourself.
7829Ports can be specified as ip:port. The default port is the same as what
7830director service's @samp{inet-listener} is using.
7831Defaults to @samp{()}.
7832@end deftypevr
7833
7834@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
7835List of IPs or hostnames to all backend mail servers. Ranges are
7836allowed too, like 10.0.0.10-10.0.0.30.
7837Defaults to @samp{()}.
7838@end deftypevr
7839
7840@deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
7841How long to redirect users to a specific server after it no longer
7842has any connections.
7843Defaults to @samp{"15 min"}.
7844@end deftypevr
7845
7846@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
7847TCP/IP port that accepts doveadm connections (instead of director
7848connections) If you enable this, you'll also need to add
7849@samp{inet-listener} for the port.
7850Defaults to @samp{0}.
7851@end deftypevr
7852
7853@deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
7854How the username is translated before being hashed. Useful values
7855include %Ln if user can log in with or without @@domain, %Ld if mailboxes
7856are shared within domain.
7857Defaults to @samp{"%Lu"}.
7858@end deftypevr
7859
7860@deftypevr {@code{dovecot-configuration} parameter} string log-path
7861Log file to use for error messages. @samp{syslog} logs to syslog,
7862@samp{/dev/stderr} logs to stderr.
7863Defaults to @samp{"syslog"}.
7864@end deftypevr
7865
7866@deftypevr {@code{dovecot-configuration} parameter} string info-log-path
7867Log file to use for informational messages. Defaults to
7868@samp{log-path}.
7869Defaults to @samp{""}.
7870@end deftypevr
7871
7872@deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
7873Log file to use for debug messages. Defaults to
7874@samp{info-log-path}.
7875Defaults to @samp{""}.
7876@end deftypevr
7877
7878@deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
7879Syslog facility to use if you're logging to syslog. Usually if you
7880don't want to use @samp{mail}, you'll use local0..local7. Also other
7881standard facilities are supported.
7882Defaults to @samp{"mail"}.
7883@end deftypevr
7884
7885@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
7886Log unsuccessful authentication attempts and the reasons why they
7887failed.
7888Defaults to @samp{#f}.
7889@end deftypevr
7890
7891@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
7892In case of password mismatches, log the attempted password. Valid
7893values are no, plain and sha1. sha1 can be useful for detecting brute
7894force password attempts vs. user simply trying the same password over
7895and over again. You can also truncate the value to n chars by appending
7896":n" (e.g. sha1:6).
7897Defaults to @samp{#f}.
7898@end deftypevr
7899
7900@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
7901Even more verbose logging for debugging purposes. Shows for example
7902SQL queries.
7903Defaults to @samp{#f}.
7904@end deftypevr
7905
7906@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
7907In case of password mismatches, log the passwords and used scheme so
7908the problem can be debugged. Enabling this also enables
7909@samp{auth-debug}.
7910Defaults to @samp{#f}.
7911@end deftypevr
7912
7913@deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
7914Enable mail process debugging. This can help you figure out why
7915Dovecot isn't finding your mails.
7916Defaults to @samp{#f}.
7917@end deftypevr
7918
7919@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
7920Show protocol level SSL errors.
7921Defaults to @samp{#f}.
7922@end deftypevr
7923
7924@deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
7925Prefix for each line written to log file. % codes are in
7926strftime(3) format.
7927Defaults to @samp{"\"%b %d %H:%M:%S \""}.
7928@end deftypevr
7929
7930@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
7931List of elements we want to log. The elements which have a
7932non-empty variable value are joined together to form a comma-separated
7933string.
7934@end deftypevr
7935
7936@deftypevr {@code{dovecot-configuration} parameter} string login-log-format
7937Login log format. %s contains @samp{login-log-format-elements}
7938string, %$ contains the data we want to log.
7939Defaults to @samp{"%$: %s"}.
7940@end deftypevr
7941
7942@deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
7943Log prefix for mail processes. See doc/wiki/Variables.txt for list
7944of possible variables you can use.
7945Defaults to @samp{"\"%s(%u): \""}.
7946@end deftypevr
7947
7948@deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
7949Format to use for logging mail deliveries. You can use variables:
7950@table @code
7951@item %$
7952Delivery status message (e.g. @samp{saved to INBOX})
7953@item %m
7954Message-ID
7955@item %s
7956Subject
7957@item %f
7958From address
7959@item %p
7960Physical size
7961@item %w
7962Virtual size.
7963@end table
7964Defaults to @samp{"msgid=%m: %$"}.
7965@end deftypevr
7966
7967@deftypevr {@code{dovecot-configuration} parameter} string mail-location
7968Location for users' mailboxes. The default is empty, which means
7969that Dovecot tries to find the mailboxes automatically. This won't work
7970if the user doesn't yet have any mail, so you should explicitly tell
7971Dovecot the full location.
7972
7973If you're using mbox, giving a path to the INBOX
7974file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
7975where the other mailboxes are kept. This is called the "root mail
7976directory", and it must be the first path given in the
7977@samp{mail-location} setting.
7978
7979There are a few special variables you can use, eg.:
7980
7981@table @samp
7982@item %u
7983username
7984@item %n
7985user part in user@@domain, same as %u if there's no domain
7986@item %d
7987domain part in user@@domain, empty if there's no domain
7988@item %h
7989home director
7990@end table
7991
7992See doc/wiki/Variables.txt for full list. Some examples:
7993@table @samp
7994@item maildir:~/Maildir
7995@item mbox:~/mail:INBOX=/var/mail/%u
7996@item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
7997@end table
7998Defaults to @samp{""}.
7999@end deftypevr
8000
8001@deftypevr {@code{dovecot-configuration} parameter} string mail-uid
8002System user and group used to access mails. If you use multiple,
8003userdb can override these by returning uid or gid fields. You can use
8004either numbers or names. <doc/wiki/UserIds.txt>.
8005Defaults to @samp{""}.
8006@end deftypevr
8007
8008@deftypevr {@code{dovecot-configuration} parameter} string mail-gid
8009
8010Defaults to @samp{""}.
8011@end deftypevr
8012
8013@deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
8014Group to enable temporarily for privileged operations. Currently
8015this is used only with INBOX when either its initial creation or
8016dotlocking fails. Typically this is set to "mail" to give access to
8017/var/mail.
8018Defaults to @samp{""}.
8019@end deftypevr
8020
8021@deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
8022Grant access to these supplementary groups for mail processes.
8023Typically these are used to set up access to shared mailboxes. Note
8024that it may be dangerous to set these if users can create
8025symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
8026could allow a user to delete others' mailboxes, or ln -s
8027/secret/shared/box ~/mail/mybox would allow reading it).
8028Defaults to @samp{""}.
8029@end deftypevr
8030
8031@deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
8032Allow full filesystem access to clients. There's no access checks
8033other than what the operating system does for the active UID/GID. It
8034works with both maildir and mboxes, allowing you to prefix mailboxes
8035names with e.g. /path/ or ~user/.
8036Defaults to @samp{#f}.
8037@end deftypevr
8038
8039@deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
8040Don't use mmap() at all. This is required if you store indexes to
8041shared filesystems (NFS or clustered filesystem).
8042Defaults to @samp{#f}.
8043@end deftypevr
8044
8045@deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
8046Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
8047supports @samp{O_EXCL} since version 3, so this should be safe to use
8048nowadays by default.
8049Defaults to @samp{#t}.
8050@end deftypevr
8051
8052@deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
8053When to use fsync() or fdatasync() calls:
8054@table @code
8055@item optimized
8056Whenever necessary to avoid losing important data
8057@item always
8058Useful with e.g. NFS when write()s are delayed
8059@item never
8060Never use it (best performance, but crashes can lose data).
8061@end table
8062Defaults to @samp{"optimized"}.
8063@end deftypevr
8064
8065@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
8066Mail storage exists in NFS. Set this to yes to make Dovecot flush
8067NFS caches whenever needed. If you're using only a single mail server
8068this isn't needed.
8069Defaults to @samp{#f}.
8070@end deftypevr
8071
8072@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
8073Mail index files also exist in NFS. Setting this to yes requires
8074@samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
8075Defaults to @samp{#f}.
8076@end deftypevr
8077
8078@deftypevr {@code{dovecot-configuration} parameter} string lock-method
8079Locking method for index files. Alternatives are fcntl, flock and
8080dotlock. Dotlocking uses some tricks which may create more disk I/O
8081than other locking methods. NFS users: flock doesn't work, remember to
8082change @samp{mmap-disable}.
8083Defaults to @samp{"fcntl"}.
8084@end deftypevr
8085
8086@deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
8087Directory in which LDA/LMTP temporarily stores incoming mails >128
8088kB.
8089Defaults to @samp{"/tmp"}.
8090@end deftypevr
8091
8092@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
8093Valid UID range for users. This is mostly to make sure that users can't
8094log in as daemons or other system users. Note that denying root logins is
8095hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
8096is set to 0.
8097Defaults to @samp{500}.
8098@end deftypevr
8099
8100@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
8101
8102Defaults to @samp{0}.
8103@end deftypevr
8104
8105@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
8106Valid GID range for users. Users having non-valid GID as primary group ID
8107aren't allowed to log in. If user belongs to supplementary groups with
8108non-valid GIDs, those groups are not set.
8109Defaults to @samp{1}.
8110@end deftypevr
8111
8112@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
8113
8114Defaults to @samp{0}.
8115@end deftypevr
8116
8117@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
8118Maximum allowed length for mail keyword name. It's only forced when
8119trying to create new keywords.
8120Defaults to @samp{50}.
8121@end deftypevr
8122
8123@deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
8124List of directories under which chrooting is allowed for mail
8125processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
8126too). This setting doesn't affect @samp{login-chroot}
8127@samp{mail-chroot} or auth chroot settings. If this setting is empty,
8128"/./" in home dirs are ignored. WARNING: Never add directories here
8129which local users can modify, that may lead to root exploit. Usually
8130this should be done only if you don't allow shell access for users.
8131<doc/wiki/Chrooting.txt>.
8132Defaults to @samp{()}.
8133@end deftypevr
8134
8135@deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
8136Default chroot directory for mail processes. This can be overridden
8137for specific users in user database by giving /./ in user's home
8138directory (e.g. /home/./user chroots into /home). Note that usually
8139there is no real need to do chrooting, Dovecot doesn't allow users to
8140access files outside their mail directory anyway. If your home
8141directories are prefixed with the chroot directory, append "/." to
8142@samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
8143Defaults to @samp{""}.
8144@end deftypevr
8145
8146@deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
8147UNIX socket path to master authentication server to find users.
8148This is used by imap (for shared users) and lda.
8149Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
8150@end deftypevr
8151
8152@deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
8153Directory where to look up mail plugins.
8154Defaults to @samp{"/usr/lib/dovecot"}.
8155@end deftypevr
8156
8157@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
8158List of plugins to load for all services. Plugins specific to IMAP,
8159LDA, etc. are added to this list in their own .conf files.
8160Defaults to @samp{()}.
8161@end deftypevr
8162
8163@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
8164The minimum number of mails in a mailbox before updates are done to
8165cache file. This allows optimizing Dovecot's behavior to do less disk
8166writes at the cost of more disk reads.
8167Defaults to @samp{0}.
8168@end deftypevr
8169
8170@deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
8171When IDLE command is running, mailbox is checked once in a while to
8172see if there are any new mails or other changes. This setting defines
8173the minimum time to wait between those checks. Dovecot can also use
8174dnotify, inotify and kqueue to find out immediately when changes
8175occur.
8176Defaults to @samp{"30 secs"}.
8177@end deftypevr
8178
8179@deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
8180Save mails with CR+LF instead of plain LF. This makes sending those
8181mails take less CPU, especially with sendfile() syscall with Linux and
8182FreeBSD. But it also creates a bit more disk I/O which may just make it
8183slower. Also note that if other software reads the mboxes/maildirs,
8184they may handle the extra CRs wrong and cause problems.
8185Defaults to @samp{#f}.
8186@end deftypevr
8187
8188@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
8189By default LIST command returns all entries in maildir beginning
8190with a dot. Enabling this option makes Dovecot return only entries
8191which are directories. This is done by stat()ing each entry, so it
8192causes more disk I/O.
8193 (For systems setting struct @samp{dirent->d_type} this check is free
8194and it's done always regardless of this setting).
8195Defaults to @samp{#f}.
8196@end deftypevr
8197
8198@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
8199When copying a message, do it with hard links whenever possible.
8200This makes the performance much better, and it's unlikely to have any
8201side effects.
8202Defaults to @samp{#t}.
8203@end deftypevr
8204
8205@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
8206Assume Dovecot is the only MUA accessing Maildir: Scan cur/
8207directory only when its mtime changes unexpectedly or when we can't find
8208the mail otherwise.
8209Defaults to @samp{#f}.
8210@end deftypevr
8211
8212@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
8213Which locking methods to use for locking mbox. There are four
8214available:
8215
8216@table @code
8217@item dotlock
8218Create <mailbox>.lock file. This is the oldest and most NFS-safe
8219solution. If you want to use /var/mail/ like directory, the users will
8220need write access to that directory.
8221@item dotlock-try
8222Same as dotlock, but if it fails because of permissions or because there
8223isn't enough disk space, just skip it.
8224@item fcntl
8225Use this if possible. Works with NFS too if lockd is used.
8226@item flock
8227May not exist in all systems. Doesn't work with NFS.
8228@item lockf
8229May not exist in all systems. Doesn't work with NFS.
8230@end table
8231
8232You can use multiple locking methods; if you do the order they're declared
8233in is important to avoid deadlocks if other MTAs/MUAs are using multiple
8234locking methods as well. Some operating systems don't allow using some of
8235them simultaneously.
8236@end deftypevr
8237
8238@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
8239
8240@end deftypevr
8241
8242@deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
8243Maximum time to wait for lock (all of them) before aborting.
8244Defaults to @samp{"5 mins"}.
8245@end deftypevr
8246
8247@deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
8248If dotlock exists but the mailbox isn't modified in any way,
8249override the lock file after this much time.
8250Defaults to @samp{"2 mins"}.
8251@end deftypevr
8252
8253@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
8254When mbox changes unexpectedly we have to fully read it to find out
8255what changed. If the mbox is large this can take a long time. Since
8256the change is usually just a newly appended mail, it'd be faster to
8257simply read the new mails. If this setting is enabled, Dovecot does
8258this but still safely fallbacks to re-reading the whole mbox file
8259whenever something in mbox isn't how it's expected to be. The only real
8260downside to this setting is that if some other MUA changes message
8261flags, Dovecot doesn't notice it immediately. Note that a full sync is
8262done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
8263Defaults to @samp{#t}.
8264@end deftypevr
8265
8266@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
8267Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
8268EXAMINE, EXPUNGE or CHECK commands. If this is set,
8269@samp{mbox-dirty-syncs} is ignored.
8270Defaults to @samp{#f}.
8271@end deftypevr
8272
8273@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
8274Delay writing mbox headers until doing a full write sync (EXPUNGE
8275and CHECK commands and when closing the mailbox). This is especially
8276useful for POP3 where clients often delete all mails. The downside is
8277that our changes aren't immediately visible to other MUAs.
8278Defaults to @samp{#t}.
8279@end deftypevr
8280
8281@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
8282If mbox size is smaller than this (e.g. 100k), don't write index
8283files. If an index file already exists it's still read, just not
8284updated.
8285Defaults to @samp{0}.
8286@end deftypevr
8287
8288@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
8289Maximum dbox file size until it's rotated.
8290Defaults to @samp{2000000}.
8291@end deftypevr
8292
8293@deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
8294Maximum dbox file age until it's rotated. Typically in days. Day
8295begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
8296disabled.
8297Defaults to @samp{"1d"}.
8298@end deftypevr
8299
8300@deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
8301When creating new mdbox files, immediately preallocate their size to
8302@samp{mdbox-rotate-size}. This setting currently works only in Linux
8303with some filesystems (ext4, xfs).
8304Defaults to @samp{#f}.
8305@end deftypevr
8306
8307@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
8308sdbox and mdbox support saving mail attachments to external files,
8309which also allows single instance storage for them. Other backends
8310don't support this for now.
8311
8312WARNING: This feature hasn't been tested much yet. Use at your own risk.
8313
8314Directory root where to store mail attachments. Disabled, if empty.
8315Defaults to @samp{""}.
8316@end deftypevr
8317
8318@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
8319Attachments smaller than this aren't saved externally. It's also
8320possible to write a plugin to disable saving specific attachments
8321externally.
8322Defaults to @samp{128000}.
8323@end deftypevr
8324
8325@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
8326Filesystem backend to use for saving attachments:
8327@table @code
8328@item posix
8329No SiS done by Dovecot (but this might help FS's own deduplication)
8330@item sis posix
8331SiS with immediate byte-by-byte comparison during saving
8332@item sis-queue posix
8333SiS with delayed comparison and deduplication.
8334@end table
8335Defaults to @samp{"sis posix"}.
8336@end deftypevr
8337
8338@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
8339Hash format to use in attachment filenames. You can add any text and
8340variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
8341@code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
8342truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
8343Defaults to @samp{"%@{sha1@}"}.
8344@end deftypevr
8345
8346@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
8347
8348Defaults to @samp{100}.
8349@end deftypevr
8350
8351@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
8352
8353Defaults to @samp{1000}.
8354@end deftypevr
8355
8356@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
8357Default VSZ (virtual memory size) limit for service processes.
8358This is mainly intended to catch and kill processes that leak memory
8359before they eat up everything.
8360Defaults to @samp{256000000}.
8361@end deftypevr
8362
8363@deftypevr {@code{dovecot-configuration} parameter} string default-login-user
8364Login user is internally used by login processes. This is the most
8365untrusted user in Dovecot system. It shouldn't have access to anything
8366at all.
8367Defaults to @samp{"dovenull"}.
8368@end deftypevr
8369
8370@deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
8371Internal user is used by unprivileged processes. It should be
8372separate from login user, so that login processes can't disturb other
8373processes.
8374Defaults to @samp{"dovecot"}.
8375@end deftypevr
8376
8377@deftypevr {@code{dovecot-configuration} parameter} string ssl?
8378SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
8379Defaults to @samp{"required"}.
8380@end deftypevr
8381
8382@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
8383PEM encoded X.509 SSL/TLS certificate (public key).
8384Defaults to @samp{"</etc/dovecot/default.pem"}.
8385@end deftypevr
8386
8387@deftypevr {@code{dovecot-configuration} parameter} string ssl-key
8388PEM encoded SSL/TLS private key. The key is opened before
8389dropping root privileges, so keep the key file unreadable by anyone but
8390root.
8391Defaults to @samp{"</etc/dovecot/private/default.pem"}.
8392@end deftypevr
8393
8394@deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
8395If key file is password protected, give the password here.
8396Alternatively give it when starting dovecot with -p parameter. Since
8397this file is often world-readable, you may want to place this setting
8398instead to a different.
8399Defaults to @samp{""}.
8400@end deftypevr
8401
8402@deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
8403PEM encoded trusted certificate authority. Set this only if you
8404intend to use @samp{ssl-verify-client-cert? #t}. The file should
8405contain the CA certificate(s) followed by the matching
8406CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
8407Defaults to @samp{""}.
8408@end deftypevr
8409
8410@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
8411Require that CRL check succeeds for client certificates.
8412Defaults to @samp{#t}.
8413@end deftypevr
8414
8415@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
8416Request client to send a certificate. If you also want to require
8417it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
8418Defaults to @samp{#f}.
8419@end deftypevr
8420
8421@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
8422Which field from certificate to use for username. commonName and
8423x500UniqueIdentifier are the usual choices. You'll also need to set
8424@samp{auth-ssl-username-from-cert? #t}.
8425Defaults to @samp{"commonName"}.
8426@end deftypevr
8427
8428@deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
8429How often to regenerate the SSL parameters file. Generation is
8430quite CPU intensive operation. The value is in hours, 0 disables
8431regeneration entirely.
8432Defaults to @samp{168}.
8433@end deftypevr
8434
8435@deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
8436SSL protocols to use.
8437Defaults to @samp{"!SSLv2"}.
8438@end deftypevr
8439
8440@deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
8441SSL ciphers to use.
8442Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
8443@end deftypevr
8444
8445@deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
8446SSL crypto device to use, for valid values run "openssl engine".
8447Defaults to @samp{""}.
8448@end deftypevr
8449
8450@deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
8451Address to use when sending rejection mails.
8452Default is postmaster@@<your domain>. %d expands to recipient domain.
8453Defaults to @samp{""}.
8454@end deftypevr
8455
8456@deftypevr {@code{dovecot-configuration} parameter} string hostname
8457Hostname to use in various parts of sent mails (e.g. in Message-Id)
8458and in LMTP replies. Default is the system's real hostname@@domain.
8459Defaults to @samp{""}.
8460@end deftypevr
8461
8462@deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
8463If user is over quota, return with temporary failure instead of
8464bouncing the mail.
8465Defaults to @samp{#f}.
8466@end deftypevr
8467
8468@deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
8469Binary to use for sending mails.
8470Defaults to @samp{"/usr/sbin/sendmail"}.
8471@end deftypevr
8472
8473@deftypevr {@code{dovecot-configuration} parameter} string submission-host
8474If non-empty, send mails via this SMTP host[:port] instead of
8475sendmail.
8476Defaults to @samp{""}.
8477@end deftypevr
8478
8479@deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
8480Subject: header to use for rejection mails. You can use the same
8481variables as for @samp{rejection-reason} below.
8482Defaults to @samp{"Rejected: %s"}.
8483@end deftypevr
8484
8485@deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
8486Human readable error message for rejection mails. You can use
8487variables:
8488
8489@table @code
8490@item %n
8491CRLF
8492@item %r
8493reason
8494@item %s
8495original subject
8496@item %t
8497recipient
8498@end table
8499Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
8500@end deftypevr
8501
8502@deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
8503Delimiter character between local-part and detail in email
8504address.
8505Defaults to @samp{"+"}.
8506@end deftypevr
8507
8508@deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
8509Header where the original recipient address (SMTP's RCPT TO:
8510address) is taken from if not available elsewhere. With dovecot-lda -a
8511parameter overrides this. A commonly used header for this is
8512X-Original-To.
8513Defaults to @samp{""}.
8514@end deftypevr
8515
8516@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
8517Should saving a mail to a nonexistent mailbox automatically create
8518it?.
8519Defaults to @samp{#f}.
8520@end deftypevr
8521
8522@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
8523Should automatically created mailboxes be also automatically
8524subscribed?.
8525Defaults to @samp{#f}.
8526@end deftypevr
8527
8528@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
8529Maximum IMAP command line length. Some clients generate very long
8530command lines with huge mailboxes, so you may need to raise this if you
8531get "Too long argument" or "IMAP command line too large" errors
8532often.
8533Defaults to @samp{64000}.
8534@end deftypevr
8535
8536@deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
8537IMAP logout format string:
8538@table @code
8539@item %i
8540total number of bytes read from client
8541@item %o
8542total number of bytes sent to client.
8543@end table
8544Defaults to @samp{"in=%i out=%o"}.
8545@end deftypevr
8546
8547@deftypevr {@code{dovecot-configuration} parameter} string imap-capability
8548Override the IMAP CAPABILITY response. If the value begins with '+',
8549add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
8550Defaults to @samp{""}.
8551@end deftypevr
8552
8553@deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
8554How long to wait between "OK Still here" notifications when client
8555is IDLEing.
8556Defaults to @samp{"2 mins"}.
8557@end deftypevr
8558
8559@deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
8560ID field names and values to send to clients. Using * as the value
8561makes Dovecot use the default value. The following fields have default
8562values currently: name, version, os, os-version, support-url,
8563support-email.
8564Defaults to @samp{""}.
8565@end deftypevr
8566
8567@deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
8568ID fields sent by client to log. * means everything.
8569Defaults to @samp{""}.
8570@end deftypevr
8571
8572@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
8573Workarounds for various client bugs:
8574
8575@table @code
8576@item delay-newmail
8577Send EXISTS/RECENT new mail notifications only when replying to NOOP and
8578CHECK commands. Some clients ignore them otherwise, for example OSX
8579Mail (<v2.1). Outlook Express breaks more badly though, without this it
8580may show user "Message no longer in server" errors. Note that OE6
8581still breaks even with this workaround if synchronization is set to
8582"Headers Only".
8583
8584@item tb-extra-mailbox-sep
8585Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
8586adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
8587ignore the extra @samp{/} instead of treating it as invalid mailbox name.
8588
8589@item tb-lsub-flags
8590Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
8591This makes Thunderbird realize they aren't selectable and show them
8592greyed out, instead of only later giving "not selectable" popup error.
8593@end table
8594Defaults to @samp{()}.
8595@end deftypevr
8596
8597@deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
8598Host allowed in URLAUTH URLs sent by client. "*" allows all.
8599Defaults to @samp{""}.
8600@end deftypevr
8601
8602
8603Whew! Lots of configuration options. The nice thing about it though is
8604that GuixSD has a complete interface to Dovecot's configuration
8605language. This allows not only a nice way to declare configurations,
8606but also offers reflective capabilities as well: users can write code to
8607inspect and transform configurations from within Scheme.
8608
8609However, it could be that you just want to get a @code{dovecot.conf} up
8610and running. In that case, you can pass an
8611@code{opaque-dovecot-configuration} as the @code{#:config} paramter to
8612@code{dovecot-service}. As its name indicates, an opaque configuration
8613does not have easy reflective capabilities.
8614
8615Available @code{opaque-dovecot-configuration} fields are:
8616
8617@deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
8618The dovecot package.
8619@end deftypevr
8620
8621@deftypevr {@code{opaque-dovecot-configuration} parameter} string string
8622The contents of the @code{dovecot.conf}, as a string.
8623@end deftypevr
8624
8625For example, if your @code{dovecot.conf} is just the empty string, you
8626could instantiate a dovecot service like this:
8627
8628@example
8629(dovecot-service #:config
8630 (opaque-dovecot-configuration
8631 (string "")))
8632@end example
8633
58724c48
DT
8634@node Web Services
8635@subsubsection Web Services
8636
8637The @code{(gnu services web)} module provides the following service:
8638
be1c2c54 8639@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
58724c48
DT
8640 [#:log-directory ``/var/log/nginx''] @
8641 [#:run-directory ``/var/run/nginx''] @
8642 [#:config-file]
8643
8644Return a service that runs @var{nginx}, the nginx web server.
8645
8646The nginx daemon loads its runtime configuration from @var{config-file}.
8647Log files are written to @var{log-directory} and temporary runtime data
8648files are written to @var{run-directory}. For proper operation, these
8649arguments should match what is in @var{config-file} to ensure that the
8650directories are created when the service is activated.
8651
8652@end deffn
8653
fe1a39d3
LC
8654@node Various Services
8655@subsubsection Various Services
8656
8657The @code{(gnu services lirc)} module provides the following service.
8658
be1c2c54 8659@deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
fe1a39d3
LC
8660 [#:device #f] [#:driver #f] [#:config-file #f] @
8661 [#:extra-options '()]
8662Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
8663decodes infrared signals from remote controls.
8664
8665Optionally, @var{device}, @var{driver} and @var{config-file}
8666(configuration file name) may be specified. See @command{lircd} manual
8667for details.
8668
8669Finally, @var{extra-options} is a list of additional command-line options
8670passed to @command{lircd}.
8671@end deffn
8672
8673
0ae8c15a
LC
8674@node Setuid Programs
8675@subsection Setuid Programs
8676
8677@cindex setuid programs
8678Some programs need to run with ``root'' privileges, even when they are
8679launched by unprivileged users. A notorious example is the
4d40227c
LC
8680@command{passwd} program, which users can run to change their
8681password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
8682@file{/etc/shadow} files---something normally restricted to root, for
8683obvious security reasons. To address that, these executables are
8684@dfn{setuid-root}, meaning that they always run with root privileges
8685(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
f7e4ae7f 8686for more info about the setuid mechanism.)
0ae8c15a
LC
8687
8688The store itself @emph{cannot} contain setuid programs: that would be a
8689security issue since any user on the system can write derivations that
8690populate the store (@pxref{The Store}). Thus, a different mechanism is
8691used: instead of changing the setuid bit directly on files that are in
8692the store, we let the system administrator @emph{declare} which programs
8693should be setuid root.
8694
8695The @code{setuid-programs} field of an @code{operating-system}
8696declaration contains a list of G-expressions denoting the names of
8697programs to be setuid-root (@pxref{Using the Configuration System}).
8698For instance, the @command{passwd} program, which is part of the Shadow
8699package, can be designated by this G-expression (@pxref{G-Expressions}):
8700
8701@example
8702#~(string-append #$shadow "/bin/passwd")
8703@end example
8704
8705A default set of setuid programs is defined by the
8706@code{%setuid-programs} variable of the @code{(gnu system)} module.
8707
8708@defvr {Scheme Variable} %setuid-programs
8709A list of G-expressions denoting common programs that are setuid-root.
8710
8711The list includes commands such as @command{passwd}, @command{ping},
8712@command{su}, and @command{sudo}.
8713@end defvr
8714
8715Under the hood, the actual setuid programs are created in the
8716@file{/run/setuid-programs} directory at system activation time. The
8717files in this directory refer to the ``real'' binaries, which are in the
8718store.
8719
efb5e833
LC
8720@node X.509 Certificates
8721@subsection X.509 Certificates
8722
8723@cindex HTTPS, certificates
8724@cindex X.509 certificates
8725@cindex TLS
8726Web servers available over HTTPS (that is, HTTP over the transport-layer
8727security mechanism, TLS) send client programs an @dfn{X.509 certificate}
8728that the client can then use to @emph{authenticate} the server. To do
8729that, clients verify that the server's certificate is signed by a
8730so-called @dfn{certificate authority} (CA). But to verify the CA's
8731signature, clients must have first acquired the CA's certificate.
8732
8733Web browsers such as GNU@tie{}IceCat include their own set of CA
8734certificates, such that they are able to verify CA signatures
8735out-of-the-box.
8736
8737However, most other programs that can talk HTTPS---@command{wget},
8738@command{git}, @command{w3m}, etc.---need to be told where CA
8739certificates can be found.
8740
8741@cindex @code{nss-certs}
8742In GuixSD, this is done by adding a package that provides certificates
8743to the @code{packages} field of the @code{operating-system} declaration
8744(@pxref{operating-system Reference}). GuixSD includes one such package,
8745@code{nss-certs}, which is a set of CA certificates provided as part of
8746Mozilla's Network Security Services.
8747
8748Note that it is @emph{not} part of @var{%base-packages}, so you need to
8749explicitly add it. The @file{/etc/ssl/certs} directory, which is where
8750most applications and libraries look for certificates by default, points
8751to the certificates installed globally.
8752
8753Unprivileged users can also install their own certificate package in
8754their profile. A number of environment variables need to be defined so
8755that applications and libraries know where to find them. Namely, the
8756OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
8757variables. Some applications add their own environment variables; for
8758instance, the Git version control system honors the certificate bundle
8759pointed to by the @code{GIT_SSL_CAINFO} environment variable.
8760
8761
996ed739
LC
8762@node Name Service Switch
8763@subsection Name Service Switch
8764
8765@cindex name service switch
8766@cindex NSS
8767The @code{(gnu system nss)} module provides bindings to the
8768configuration file of libc's @dfn{name service switch} or @dfn{NSS}
8769(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
8770Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
8771extended with new ``name'' lookup methods for system databases, which
8772includes host names, service names, user accounts, and more (@pxref{Name
8773Service Switch, System Databases and Name Service Switch,, libc, The GNU
8774C Library Reference Manual}).
8775
8776The NSS configuration specifies, for each system database, which lookup
8777method is to be used, and how the various methods are chained
8778together---for instance, under which circumstances NSS should try the
8779next method in the list. The NSS configuration is given in the
8780@code{name-service-switch} field of @code{operating-system} declarations
8781(@pxref{operating-system Reference, @code{name-service-switch}}).
8782
4c9050c6
LC
8783@cindex nss-mdns
8784@cindex .local, host name lookup
996ed739 8785As an example, the declaration below configures the NSS to use the
4c9050c6
LC
8786@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
8787back-end}, which supports host name lookups over multicast DNS (mDNS)
8788for host names ending in @code{.local}:
996ed739
LC
8789
8790@example
8791(name-service-switch
8792 (hosts (list %files ;first, check /etc/hosts
8793
8794 ;; If the above did not succeed, try
8795 ;; with 'mdns_minimal'.
8796 (name-service
8797 (name "mdns_minimal")
8798
8799 ;; 'mdns_minimal' is authoritative for
8800 ;; '.local'. When it returns "not found",
8801 ;; no need to try the next methods.
8802 (reaction (lookup-specification
8803 (not-found => return))))
8804
8805 ;; Then fall back to DNS.
8806 (name-service
8807 (name "dns"))
8808
8809 ;; Finally, try with the "full" 'mdns'.
8810 (name-service
8811 (name "mdns")))))
8812@end example
8813
15137a29
LC
8814Don't worry: the @code{%mdns-host-lookup-nss} variable (see below)
8815contains this configuration, so you won't have to type it if all you
8816want is to have @code{.local} host lookup working.
8817
4c9050c6
LC
8818Note that, in this case, in addition to setting the
8819@code{name-service-switch} of the @code{operating-system} declaration,
cc9c1f39
LC
8820you also need to use @code{avahi-service} (@pxref{Networking Services,
8821@code{avahi-service}}), or @var{%desktop-services}, which includes it
8822(@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
8823to the name service cache daemon (@pxref{Base Services,
8824@code{nscd-service}}).
15137a29
LC
8825
8826For convenience, the following variables provide typical NSS
8827configurations.
8828
8829@defvr {Scheme Variable} %default-nss
8830This is the default name service switch configuration, a
8831@code{name-service-switch} object.
8832@end defvr
8833
8834@defvr {Scheme Variable} %mdns-host-lookup-nss
8835This is the name service switch configuration with support for host name
8836lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
8837@end defvr
4c9050c6 8838
996ed739
LC
8839The reference for name service switch configuration is given below. It
8840is a direct mapping of the C library's configuration file format, so
8841please refer to the C library manual for more information (@pxref{NSS
8842Configuration File,,, libc, The GNU C Library Reference Manual}).
8843Compared to libc's NSS configuration file format, it has the advantage
8844not only of adding this warm parenthetic feel that we like, but also
8845static checks: you'll know about syntax errors and typos as soon as you
8846run @command{guix system}.
8847
996ed739
LC
8848@deftp {Data Type} name-service-switch
8849
8850This is the data type representation the configuration of libc's name
8851service switch (NSS). Each field below represents one of the supported
8852system databases.
8853
8854@table @code
8855@item aliases
8856@itemx ethers
8857@itemx group
8858@itemx gshadow
8859@itemx hosts
8860@itemx initgroups
8861@itemx netgroup
8862@itemx networks
8863@itemx password
8864@itemx public-key
8865@itemx rpc
8866@itemx services
8867@itemx shadow
8868The system databases handled by the NSS. Each of these fields must be a
8869list of @code{<name-service>} objects (see below.)
8870@end table
8871@end deftp
8872
8873@deftp {Data Type} name-service
8874
8875This is the data type representing an actual name service and the
8876associated lookup action.
8877
8878@table @code
8879@item name
8880A string denoting the name service (@pxref{Services in the NSS
8881configuration,,, libc, The GNU C Library Reference Manual}).
8882
4aee6e60
LC
8883Note that name services listed here must be visible to nscd. This is
8884achieved by passing the @code{#:name-services} argument to
8885@code{nscd-service} the list of packages providing the needed name
8886services (@pxref{Base Services, @code{nscd-service}}).
8887
996ed739
LC
8888@item reaction
8889An action specified using the @code{lookup-specification} macro
8890(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
8891Reference Manual}). For example:
8892
8893@example
8894(lookup-specification (unavailable => continue)
8895 (success => return))
8896@end example
8897@end table
8898@end deftp
0ae8c15a 8899
fd1b1fa2
LC
8900@node Initial RAM Disk
8901@subsection Initial RAM Disk
8902
8903@cindex initial RAM disk (initrd)
8904@cindex initrd (initial RAM disk)
8905For bootstrapping purposes, the Linux-Libre kernel is passed an
8906@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
8907root file system, as well as an initialization script. The latter is
8908responsible for mounting the real root file system, and for loading any
8909kernel modules that may be needed to achieve that.
8910
8911The @code{initrd} field of an @code{operating-system} declaration allows
8912you to specify which initrd you would like to use. The @code{(gnu
8913system linux-initrd)} module provides two ways to build an initrd: the
8914high-level @code{base-initrd} procedure, and the low-level
8915@code{expression->initrd} procedure.
8916
8917The @code{base-initrd} procedure is intended to cover most common uses.
8918For example, if you want to add a bunch of kernel modules to be loaded
8919at boot time, you can define the @code{initrd} field of the operating
8920system declaration like this:
8921
8922@example
52ac153e 8923(initrd (lambda (file-systems . rest)
027981d6
LC
8924 ;; Create a standard initrd that has modules "foo.ko"
8925 ;; and "bar.ko", as well as their dependencies, in
8926 ;; addition to the modules available by default.
52ac153e 8927 (apply base-initrd file-systems
027981d6 8928 #:extra-modules '("foo" "bar")
52ac153e 8929 rest)))
fd1b1fa2
LC
8930@end example
8931
52ac153e
LC
8932The @code{base-initrd} procedure also handles common use cases that
8933involves using the system as a QEMU guest, or as a ``live'' system whose
8934root file system is volatile.
fd1b1fa2 8935
e90cf6c1
LC
8936The initial RAM disk produced by @code{base-initrd} honors several
8937options passed on the Linux kernel command line (that is, arguments
8938passed @i{via} GRUB's @code{linux} command, or with QEMU's
8939@code{-append} option), notably:
8940
8941@table @code
8942@item --load=@var{boot}
8943Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
8944program, once it has mounted the root file system.
8945
8946GuixSD uses this option to yield control to a boot program that runs the
8947service activation programs and then spawns GNU@tie{}dmd, the
8948initialization system.
8949
8950@item --root=@var{root}
8951Mount @var{root} as the root file system. @var{root} can be a device
8952device name like @code{/dev/sda1}, a partition label, or a partition
8953UUID.
8954
8955@item --system=@var{system}
8956Have @file{/run/booted-system} and @file{/run/current-system} point to
8957@var{system}.
8958
8959@item modprobe.blacklist=@var{modules}@dots{}
8960@cindex module, black-listing
8961@cindex black list, of kernel modules
8962Instruct the initial RAM disk as well as the @command{modprobe} command
8963(from the kmod package) to refuse to load @var{modules}. @var{modules}
8964must be a comma-separated list of module names---e.g.,
8965@code{usbkbd,9pnet}.
8966
8967@item --repl
8968Start a read-eval-print loop (REPL) from the initial RAM disk before it
8969tries to load kernel modules and to mount the root file system. Our
8970marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
8971love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
8972Manual}, for more information on Guile's REPL.
8973
8974@end table
8975
8976Now that you know all the features that initial RAM disks produced by
8977@code{base-initrd} provide, here is how to use it and customize it
8978further.
8979
fd1b1fa2 8980@deffn {Monadic Procedure} base-initrd @var{file-systems} @
9059b97d 8981 [#:qemu-networking? #f] [#:virtio? #t] [#:volatile-root? #f] @
52ac153e 8982 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2
LC
8983Return a monadic derivation that builds a generic initrd. @var{file-systems} is
8984a list of file-systems to be mounted by the initrd, possibly in addition to
8985the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
8986@var{mapped-devices} is a list of device mappings to realize before
8987@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
8988
8989When @var{qemu-networking?} is true, set up networking with the standard QEMU
8990parameters. When @var{virtio?} is true, load additional modules so the initrd can
8991be used as a QEMU guest with para-virtualized I/O drivers.
8992
8993When @var{volatile-root?} is true, the root file system is writable but any changes
8994to it are lost.
8995
8996The initrd is automatically populated with all the kernel modules necessary
8997for @var{file-systems} and for the given options. However, additional kernel
8998modules can be listed in @var{extra-modules}. They will be added to the initrd, and
8999loaded at boot time in the order in which they appear.
9000@end deffn
9001
9002Needless to say, the initrds we produce and use embed a
9003statically-linked Guile, and the initialization program is a Guile
9004program. That gives a lot of flexibility. The
9005@code{expression->initrd} procedure builds such an initrd, given the
9006program to run in that initrd.
9007
9008@deffn {Monadic Procedure} expression->initrd @var{exp} @
9009 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
42d10464 9010 [#:modules '()]
fd1b1fa2
LC
9011Return a derivation that builds a Linux initrd (a gzipped cpio archive)
9012containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
9013upon booting. All the derivations referenced by @var{exp} are
9014automatically copied to the initrd.
fd1b1fa2 9015
42d10464
LC
9016@var{modules} is a list of Guile module names to be embedded in the
9017initrd.
fd1b1fa2
LC
9018@end deffn
9019
88faf933
LC
9020@node GRUB Configuration
9021@subsection GRUB Configuration
9022
9023@cindex GRUB
9024@cindex boot loader
9025
9026The operating system uses GNU@tie{}GRUB as its boot loader
9027(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
9028configured using @code{grub-configuration} declarations. This data type
9029is exported by the @code{(gnu system grub)} module, and described below.
9030
9031@deftp {Data Type} grub-configuration
9032The type of a GRUB configuration declaration.
9033
9034@table @asis
9035
9036@item @code{device}
9037This is a string denoting the boot device. It must be a device name
9038understood by the @command{grub-install} command, such as
9039@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
9040GNU GRUB Manual}).
9041
9042@item @code{menu-entries} (default: @code{()})
9043A possibly empty list of @code{menu-entry} objects (see below), denoting
9044entries to appear in the GRUB boot menu, in addition to the current
9045system entry and the entry pointing to previous system generations.
9046
9047@item @code{default-entry} (default: @code{0})
9048The index of the default boot menu entry. Index 0 is for the current
9049system's entry.
9050
9051@item @code{timeout} (default: @code{5})
9052The number of seconds to wait for keyboard input before booting. Set to
90530 to boot immediately, and to -1 to wait indefinitely.
9054
9055@item @code{theme} (default: @var{%default-theme})
9056The @code{grub-theme} object describing the theme to use.
9057@end table
9058
9059@end deftp
9060
9061Should you want to list additional boot menu entries @i{via} the
9062@code{menu-entries} field above, you will need to create them with the
9063@code{menu-entry} form:
9064
9065@deftp {Data Type} menu-entry
9066The type of an entry in the GRUB boot menu.
9067
9068@table @asis
9069
9070@item @code{label}
35ed9306 9071The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
9072
9073@item @code{linux}
9074The Linux kernel to boot.
9075
9076@item @code{linux-arguments} (default: @code{()})
9077The list of extra Linux kernel command-line arguments---e.g.,
9078@code{("console=ttyS0")}.
9079
9080@item @code{initrd}
9081A G-Expression or string denoting the file name of the initial RAM disk
9082to use (@pxref{G-Expressions}).
9083
9084@end table
9085@end deftp
9086
9087@c FIXME: Write documentation once it's stable.
9088Themes are created using the @code{grub-theme} form, which is not
9089documented yet.
9090
9091@defvr {Scheme Variable} %default-theme
9092This is the default GRUB theme used by the operating system, with a
9093fancy background image displaying the GNU and Guix logos.
9094@end defvr
9095
9096
cf4a9129
LC
9097@node Invoking guix system
9098@subsection Invoking @code{guix system}
0918e64a 9099
cf4a9129
LC
9100Once you have written an operating system declaration, as seen in the
9101previous section, it can be @dfn{instantiated} using the @command{guix
9102system} command. The synopsis is:
4af2447e 9103
cf4a9129
LC
9104@example
9105guix system @var{options}@dots{} @var{action} @var{file}
9106@end example
4af2447e 9107
cf4a9129
LC
9108@var{file} must be the name of a file containing an
9109@code{operating-system} declaration. @var{action} specifies how the
9110operating system is instantiate. Currently the following values are
9111supported:
4af2447e 9112
cf4a9129
LC
9113@table @code
9114@item reconfigure
9115Build the operating system described in @var{file}, activate it, and
9116switch to it@footnote{This action is usable only on systems already
65797bff 9117running GuixSD.}.
4af2447e 9118
cf4a9129
LC
9119This effects all the configuration specified in @var{file}: user
9120accounts, system services, global package list, setuid programs, etc.
4af2447e 9121
cf4a9129
LC
9122It also adds a GRUB menu entry for the new OS configuration, and moves
9123entries for older configurations to a submenu---unless
9124@option{--no-grub} is passed.
4af2447e 9125
bf2479c7
LC
9126@c The paragraph below refers to the problem discussed at
9127@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
9128It is highly recommended to run @command{guix pull} once before you run
9129@command{guix system reconfigure} for the first time (@pxref{Invoking
9130guix pull}). Failing to do that you would see an older version of Guix
9131once @command{reconfigure} has completed.
9132
cf4a9129
LC
9133@item build
9134Build the operating system's derivation, which includes all the
9135configuration files and programs needed to boot and run the system.
9136This action does not actually install anything.
113daf62 9137
cf4a9129
LC
9138@item init
9139Populate the given directory with all the files necessary to run the
9140operating system specified in @var{file}. This is useful for first-time
4705641f 9141installations of GuixSD. For instance:
113daf62
LC
9142
9143@example
cf4a9129 9144guix system init my-os-config.scm /mnt
113daf62
LC
9145@end example
9146
cf4a9129
LC
9147copies to @file{/mnt} all the store items required by the configuration
9148specified in @file{my-os-config.scm}. This includes configuration
9149files, packages, and so on. It also creates other essential files
9150needed for the system to operate correctly---e.g., the @file{/etc},
9151@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 9152
cf4a9129
LC
9153This command also installs GRUB on the device specified in
9154@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 9155
cf4a9129
LC
9156@item vm
9157@cindex virtual machine
0276f697 9158@cindex VM
f535dcbe 9159@anchor{guix system vm}
cf4a9129
LC
9160Build a virtual machine that contain the operating system declared in
9161@var{file}, and return a script to run that virtual machine (VM).
810568b3 9162Arguments given to the script are passed as is to QEMU.
113daf62 9163
cf4a9129 9164The VM shares its store with the host system.
113daf62 9165
0276f697
LC
9166Additional file systems can be shared between the host and the VM using
9167the @code{--share} and @code{--expose} command-line options: the former
9168specifies a directory to be shared with write access, while the latter
9169provides read-only access to the shared directory.
9170
9171The example below creates a VM in which the user's home directory is
9172accessible read-only, and where the @file{/exchange} directory is a
9173read-write mapping of the host's @file{$HOME/tmp}:
9174
9175@example
9176guix system vm my-config.scm \
9177 --expose=$HOME --share=$HOME/tmp=/exchange
9178@end example
9179
6aa260af
LC
9180On GNU/Linux, the default is to boot directly to the kernel; this has
9181the advantage of requiring only a very tiny root disk image since the
9182host's store can then be mounted.
9183
9184The @code{--full-boot} option forces a complete boot sequence, starting
9185with the bootloader. This requires more disk space since a root image
9186containing at least the kernel, initrd, and bootloader data files must
9187be created. The @code{--image-size} option can be used to specify the
9188image's size.
ab11f0be 9189
cf4a9129
LC
9190@item vm-image
9191@itemx disk-image
9192Return a virtual machine or disk image of the operating system declared
9193in @var{file} that stands alone. Use the @option{--image-size} option
9194to specify the size of the image.
113daf62 9195
cf4a9129
LC
9196When using @code{vm-image}, the returned image is in qcow2 format, which
9197the QEMU emulator can efficiently use.
113daf62 9198
cf4a9129
LC
9199When using @code{disk-image}, a raw disk image is produced; it can be
9200copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
9201the device corresponding to a USB stick, one can copy the image on it
9202using the following command:
113daf62 9203
cf4a9129
LC
9204@example
9205# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
9206@end example
113daf62 9207
1c8a81b1
DT
9208@item container
9209Return a script to run the operating system declared in @var{file}
9210within a container. Containers are a set of lightweight isolation
9211mechanisms provided by the kernel Linux-libre. Containers are
9212substantially less resource-demanding than full virtual machines since
9213the kernel, shared objects, and other resources can be shared with the
9214host system; this also means they provide thinner isolation.
9215
9216Currently, the script must be run as root in order to support more than
9217a single user and group. The container shares its store with the host
9218system.
9219
9220As with the @code{vm} action (@pxref{guix system vm}), additional file
9221systems to be shared between the host and container can be specified
9222using the @option{--share} and @option{--expose} options:
9223
9224@example
9225guix system container my-config.scm \
9226 --expose=$HOME --share=$HOME/tmp=/exchange
9227@end example
9228
0f252e26 9229@quotation Note
cfd35b4e 9230This option requires Linux-libre 3.19 or newer.
0f252e26
DT
9231@end quotation
9232
cf4a9129 9233@end table
113daf62 9234
cf4a9129
LC
9235@var{options} can contain any of the common build options provided by
9236@command{guix build} (@pxref{Invoking guix build}). In addition,
9237@var{options} can contain one of the following:
113daf62 9238
cf4a9129
LC
9239@table @option
9240@item --system=@var{system}
9241@itemx -s @var{system}
9242Attempt to build for @var{system} instead of the host's system type.
9243This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 9244
f3f427c2
LC
9245@item --derivation
9246@itemx -d
9247Return the derivation file name of the given operating system without
9248building anything.
9249
cf4a9129
LC
9250@item --image-size=@var{size}
9251For the @code{vm-image} and @code{disk-image} actions, create an image
9252of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
9253include a unit as a suffix (@pxref{Block size, size specifications,,
9254coreutils, GNU Coreutils}).
db030303
LC
9255
9256@item --on-error=@var{strategy}
9257Apply @var{strategy} when an error occurs when reading @var{file}.
9258@var{strategy} may be one of the following:
9259
9260@table @code
9261@item nothing-special
9262Report the error concisely and exit. This is the default strategy.
9263
9264@item backtrace
9265Likewise, but also display a backtrace.
9266
9267@item debug
9268Report the error and enter Guile's debugger. From there, you can run
9269commands such as @code{,bt} to get a backtrace, @code{,locals} to
9270display local variable values, and more generally inspect the program's
9271state. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
9272a list of available debugging commands.
9273@end table
113daf62 9274@end table
113daf62 9275
cf4a9129
LC
9276Note that all the actions above, except @code{build} and @code{init},
9277rely on KVM support in the Linux-Libre kernel. Specifically, the
9278machine should have hardware virtualization support, the corresponding
9279KVM kernel module should be loaded, and the @file{/dev/kvm} device node
9280must exist and be readable and writable by the user and by the daemon's
9281build users.
8451a568 9282
65797bff
LC
9283Once you have built, configured, re-configured, and re-re-configured
9284your GuixSD installation, you may find it useful to list the operating
9285system generations available on disk---and that you can choose from the
9286GRUB boot menu:
9287
9288@table @code
9289
9290@item list-generations
9291List a summary of each generation of the operating system available on
9292disk, in a human-readable way. This is similar to the
9293@option{--list-generations} option of @command{guix package}
9294(@pxref{Invoking guix package}).
9295
9296Optionally, one can specify a pattern, with the same syntax that is used
9297in @command{guix package --list-generations}, to restrict the list of
9298generations displayed. For instance, the following command displays
9299generations up to 10-day old:
9300
9301@example
9302$ guix system list-generations 10d
9303@end example
9304
9305@end table
9306
d6c3267a
LC
9307The @command{guix system} command has even more to offer! The following
9308sub-commands allow you to visualize how your system services relate to
9309each other:
9310
9311@anchor{system-extension-graph}
9312@table @code
9313
9314@item extension-graph
9315Emit in Dot/Graphviz format to standard output the @dfn{service
9316extension graph} of the operating system defined in @var{file}
9317(@pxref{Service Composition}, for more information on service
9318extensions.)
9319
9320The command:
9321
9322@example
9323$ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
9324@end example
9325
9326produces a PDF file showing the extension relations among services.
9327
6f305ea5
LC
9328@anchor{system-dmd-graph}
9329@item dmd-graph
9330Emit in Dot/Graphviz format to standard output the @dfn{dependency
9331graph} of dmd services of the operating system defined in @var{file}.
9332@xref{dmd Services}, for more information and for an example graph.
9333
d6c3267a
LC
9334@end table
9335
9336
cf4a9129
LC
9337@node Defining Services
9338@subsection Defining Services
8451a568 9339
eb524192 9340The previous sections show the available services and how one can combine
0adfe95a
LC
9341them in an @code{operating-system} declaration. But how do we define
9342them in the first place? And what is a service anyway?
8451a568 9343
0adfe95a
LC
9344@menu
9345* Service Composition:: The model for composing services.
9346* Service Types and Services:: Types and services.
9347* Service Reference:: API reference.
9348* dmd Services:: A particular type of service.
9349@end menu
9350
9351@node Service Composition
9352@subsubsection Service Composition
9353
9354@cindex services
9355@cindex daemons
9356Here we define a @dfn{service} as, broadly, something that extends the
9357operating system's functionality. Often a service is a process---a
9358@dfn{daemon}---started when the system boots: a secure shell server, a
9359Web server, the Guix build daemon, etc. Sometimes a service is a daemon
9360whose execution can be triggered by another daemon---e.g., an FTP server
9361started by @command{inetd} or a D-Bus service activated by
9362@command{dbus-daemon}. Occasionally, a service does not map to a
9363daemon. For instance, the ``account'' service collects user accounts
9364and makes sure they exist when the system runs; the ``udev'' service
9365collects device management rules and makes them available to the eudev
9366daemon; the @file{/etc} service populates the system's @file{/etc}
9367directory.
9368
d6c3267a 9369@cindex service extensions
0adfe95a
LC
9370GuixSD services are connected by @dfn{extensions}. For instance, the
9371secure shell service @emph{extends} dmd---GuixSD's initialization system,
9372running as PID@tie{}1---by giving it the command lines to start and stop
9373the secure shell daemon (@pxref{Networking Services,
9374@code{lsh-service}}); the UPower service extends the D-Bus service by
9375passing it its @file{.service} specification, and extends the udev
9376service by passing it device management rules (@pxref{Desktop Services,
9377@code{upower-service}}); the Guix daemon service extends dmd by passing
9378it the command lines to start and stop the daemon, and extends the
9379account service by passing it a list of required build user accounts
9380(@pxref{Base Services}).
9381
9382All in all, services and their ``extends'' relations form a directed
9383acyclic graph (DAG). If we represent services as boxes and extensions
9384as arrows, a typical system might provide something like this:
9385
9386@image{images/service-graph,,5in,Typical service extension graph.}
9387
d62e201c
LC
9388@cindex system service
9389At the bottom, we see the @dfn{system service}, which produces the
9390directory containing everything to run and boot the system, as returned
9391by the @command{guix system build} command. @xref{Service Reference},
9392to learn about the other service types shown here.
d6c3267a
LC
9393@xref{system-extension-graph, the @command{guix system extension-graph}
9394command}, for information on how to generate this representation for a
9395particular operating system definition.
0adfe95a
LC
9396
9397@cindex service types
9398Technically, developers can define @dfn{service types} to express these
9399relations. There can be any number of services of a given type on the
9400system---for instance, a system running two instances of the GNU secure
9401shell server (lsh) has two instances of @var{lsh-service-type}, with
9402different parameters.
9403
9404The following section describes the programming interface for service
9405types and services.
9406
9407@node Service Types and Services
9408@subsubsection Service Types and Services
9409
9410A @dfn{service type} is a node in the DAG described above. Let us start
9411with a simple example, the service type for the Guix build daemon
9412(@pxref{Invoking guix-daemon}):
9413
9414@example
9415(define guix-service-type
9416 (service-type
9417 (name 'guix)
9418 (extensions
9419 (list (service-extension dmd-root-service-type guix-dmd-service)
9420 (service-extension account-service-type guix-accounts)
9421 (service-extension activation-service-type guix-activation)))))
9422@end example
8451a568 9423
cf4a9129 9424@noindent
0adfe95a
LC
9425It defines a two things:
9426
9427@enumerate
9428@item
9429A name, whose sole purpose is to make inspection and debugging easier.
9430
9431@item
9432A list of @dfn{service extensions}, where each extension designates the
9433target service type and a procedure that, given the service's
9434parameters, returns a list of object to extend the service of that type.
9435
9436Every service type has at least one service extension. The only
9437exception is the @dfn{boot service type}, which is the ultimate service.
9438@end enumerate
9439
9440In this example, @var{guix-service-type} extends three services:
9441
9442@table @var
9443@item dmd-root-service-type
9444The @var{guix-dmd-service} procedure defines how the dmd service is
9445extended. Namely, it returns a @code{<dmd-service>} object that defines
9446how @command{guix-daemon} is started and stopped (@pxref{dmd Services}).
9447
9448@item account-service-type
9449This extension for this service is computed by @var{guix-accounts},
9450which returns a list of @code{user-group} and @code{user-account}
9451objects representing the build user accounts (@pxref{Invoking
9452guix-daemon}).
9453
9454@item activation-service-type
9455Here @var{guix-activation} is a procedure that returns a gexp, which is
9456a code snippet to run at ``activation time''---e.g., when the service is
9457booted.
9458@end table
9459
9460A service of this type is instantiated like this:
9461
9462@example
9463(service guix-service-type
9464 (guix-configuration
9465 (build-accounts 5)
9466 (use-substitutes? #f)))
9467@end example
9468
9469The second argument to the @code{service} form is a value representing
9470the parameters of this specific service instance.
9471@xref{guix-configuration-type, @code{guix-configuration}}, for
9472information about the @code{guix-configuration} data type.
9473
9474@var{guix-service-type} is quite simple because it extends other
9475services but is not extensible itself.
9476
9477@c @subsubsubsection Extensible Service Types
9478
9479The service type for an @emph{extensible} service looks like this:
9480
9481@example
9482(define udev-service-type
9483 (service-type (name 'udev)
9484 (extensions
9485 (list (service-extension dmd-root-service-type
9486 udev-dmd-service)))
9487
9488 (compose concatenate) ;concatenate the list of rules
9489 (extend (lambda (config rules)
9490 (match config
9491 (($ <udev-configuration> udev initial-rules)
9492 (udev-configuration
9493 (udev udev) ;the udev package to use
9494 (rules (append initial-rules rules)))))))))
9495@end example
9496
9497This is the service type for the
9498@uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
9499management daemon}. Compared to the previous example, in addition to an
9500extension of @var{dmd-root-service-type}, we see two new fields:
9501
9502@table @code
9503@item compose
9504This is the procedure to @dfn{compose} the list of extensions to
9505services of this type.
9506
9507Services can extend the udev service by passing it lists of rules; we
9508compose those extensions simply by concatenating them.
9509
9510@item extend
9511This procedure defines how the service's value is @dfn{extended} with
9512the composition of the extensions.
9513
9514Udev extensions are composed into a list of rules, but the udev service
9515value is itself a @code{<udev-configuration>} record. So here, we
9516extend that record by appending the list of rules is contains to the
9517list of contributed rules.
9518@end table
9519
9520There can be only one instance of an extensible service type such as
9521@var{udev-service-type}. If there were more, the
9522@code{service-extension} specifications would be ambiguous.
9523
9524Still here? The next section provides a reference of the programming
9525interface for services.
9526
9527@node Service Reference
9528@subsubsection Service Reference
9529
9530We have seen an overview of service types (@pxref{Service Types and
9531Services}). This section provides a reference on how to manipulate
9532services and service types. This interface is provided by the
9533@code{(gnu services)} module.
9534
9535@deffn {Scheme Procedure} service @var{type} @var{value}
9536Return a new service of @var{type}, a @code{<service-type>} object (see
9537below.) @var{value} can be any object; it represents the parameters of
9538this particular service instance.
9539@end deffn
9540
9541@deffn {Scheme Procedure} service? @var{obj}
9542Return true if @var{obj} is a service.
9543@end deffn
8451a568 9544
0adfe95a
LC
9545@deffn {Scheme Procedure} service-kind @var{service}
9546Return the type of @var{service}---i.e., a @code{<service-type>} object.
9547@end deffn
9548
9549@deffn {Scheme Procedure} service-parameters @var{service}
9550Return the value associated with @var{service}. It represents its
9551parameters.
9552@end deffn
9553
9554Here is an example of how a service is created and manipulated:
9555
9556@example
9557(define s
9558 (service nginx-service-type
9559 (nginx-configuration
9560 (nginx nginx)
9561 (log-directory log-directory)
9562 (run-directory run-directory)
9563 (file config-file))))
9564
9565(service? s)
9566@result{} #t
9567
9568(eq? (service-kind s) nginx-service-type)
9569@result{} #t
9570@end example
9571
cd6f6c22
LC
9572The @code{modify-services} form provides a handy way to change the
9573parameters of some of the services of a list such as
9574@var{%base-services} (@pxref{Base Services, @code{%base-services}}). Of
9575course, you could always use standard list combinators such as
9576@code{map} and @code{fold} to do that (@pxref{SRFI-1, List Library,,
9577guile, GNU Guile Reference Manual}); @code{modify-services} simply
9578provides a more concise form for this common pattern.
9579
9580@deffn {Scheme Syntax} modify-services @var{services} @
9581 (@var{type} @var{variable} => @var{body}) @dots{}
9582
9583Modify the services listed in @var{services} according to the given
9584clauses. Each clause has the form:
9585
9586@example
9587(@var{type} @var{variable} => @var{body})
9588@end example
9589
9590where @var{type} is a service type, such as @var{guix-service-type}, and
9591@var{variable} is an identifier that is bound within @var{body} to the
9592value of the service of that @var{type}. @xref{Using the Configuration
9593System}, for an example.
9594
9595This is a shorthand for:
9596
9597@example
9598(map (lambda (service) @dots{}) @var{services})
9599@end example
9600@end deffn
9601
9602Next comes the programming interface for service types. This is
9603something you want to know when writing new service definitions, but not
9604necessarily when simply looking for ways to customize your
9605@code{operating-system} declaration.
9606
0adfe95a
LC
9607@deftp {Data Type} service-type
9608@cindex service type
9609This is the representation of a @dfn{service type} (@pxref{Service Types
9610and Services}).
9611
9612@table @asis
9613@item @code{name}
9614This is a symbol, used only to simplify inspection and debugging.
9615
9616@item @code{extensions}
9617A non-empty list of @code{<service-extension>} objects (see below.)
9618
9619@item @code{compose} (default: @code{#f})
9620If this is @code{#f}, then the service type denotes services that cannot
9621be extended---i.e., services that do not receive ``values'' from other
9622services.
9623
9624Otherwise, it must be a one-argument procedure. The procedure is called
9625by @code{fold-services} and is passed a list of values collected from
9626extensions. It must return a value that is a valid parameter value for
9627the service instance.
9628
9629@item @code{extend} (default: @code{#f})
9630If this is @code{#f}, services of this type cannot be extended.
9631
9632Otherwise, it must be a two-argument procedure: @code{fold-services}
9633calls it, passing it the service's initial value as the first argument
9634and the result of applying @code{compose} to the extension values as the
9635second argument.
9636@end table
9637
9638@xref{Service Types and Services}, for examples.
9639@end deftp
9640
9641@deffn {Scheme Procedure} service-extension @var{target-type} @
9642 @var{compute}
9643Return a new extension for services of type @var{target-type}.
9644@var{compute} must be a one-argument procedure: @code{fold-services}
9645calls it, passing it the value associated with the service that provides
9646the extension; it must return a valid value for the target service.
9647@end deffn
9648
9649@deffn {Scheme Procedure} service-extension? @var{obj}
9650Return true if @var{obj} is a service extension.
9651@end deffn
9652
9653At the core of the service abstraction lies the @code{fold-services}
9654procedure, which is responsible for ``compiling'' a list of services
d62e201c
LC
9655down to a single directory that contains everything needed to boot and
9656run the system---the directory shown by the @command{guix system build}
9657command (@pxref{Invoking guix system}). In essence, it propagates
9658service extensions down the service graph, updating each node parameters
9659on the way, until it reaches the root node.
0adfe95a
LC
9660
9661@deffn {Scheme Procedure} fold-services @var{services} @
d62e201c 9662 [#:target-type @var{system-service-type}]
0adfe95a
LC
9663Fold @var{services} by propagating their extensions down to the root of
9664type @var{target-type}; return the root service adjusted accordingly.
9665@end deffn
9666
9667Lastly, the @code{(gnu services)} module also defines several essential
9668service types, some of which are listed below.
9669
d62e201c
LC
9670@defvr {Scheme Variable} system-service-type
9671This is the root of the service graph. It produces the system directory
9672as returned by the @command{guix system build} command.
9673@end defvr
9674
0adfe95a 9675@defvr {Scheme Variable} boot-service-type
d62e201c
LC
9676The type of the ``boot service'', which produces the @dfn{boot script}.
9677The boot script is what the initial RAM disk runs when booting.
0adfe95a
LC
9678@end defvr
9679
9680@defvr {Scheme Variable} etc-service-type
9681The type of the @file{/etc} service. This service can be extended by
9682passing it name/file tuples such as:
9683
9684@example
9685(list `("issue" ,(plain-file "issue" "Welcome!\n")))
9686@end example
9687
9688In this example, the effect would be to add an @file{/etc/issue} file
9689pointing to the given file.
9690@end defvr
9691
9692@defvr {Scheme Variable} setuid-program-service-type
9693Type for the ``setuid-program service''. This service collects lists of
9694executable file names, passed as gexps, and adds them to the set of
9695setuid-root programs on the system (@pxref{Setuid Programs}).
9696@end defvr
9697
af4c3fd5
LC
9698@defvr {Scheme Variable} profile-service-type
9699Type of the service that populates the @dfn{system profile}---i.e., the
9700programs under @file{/run/current-system/profile}. Other services can
9701extend it by passing it lists of packages to add to the system profile.
9702@end defvr
9703
0adfe95a
LC
9704
9705@node dmd Services
9706@subsubsection dmd Services
9707
9708@cindex PID 1
9709@cindex init system
9710The @code{(gnu services dmd)} provides a way to define services managed
9711by GNU@tie{}dmd, which is GuixSD initialization system---the first
9712process that is started when the system boots, aka. PID@tie{}1
6f305ea5
LC
9713(@pxref{Introduction,,, dmd, GNU dmd Manual}).
9714
9715Services in dmd can depend on each other. For instance, the SSH daemon
9716may need to be started after the syslog daemon has been started, which
9717in turn can only happen once all the file systems have been mounted.
9718The simple operating system defined earlier (@pxref{Using the
9719Configuration System}) results in a service graph like this:
9720
9721@image{images/dmd-graph,,5in,Typical dmd service graph.}
9722
9723You can actually generate such a graph for any operating system
9724definition using the @command{guix system dmd-graph} command
9725(@pxref{system-dmd-graph, @command{guix system dmd-graph}}).
9726
9727The @var{%dmd-root-service} is a service object representing PID@tie{}1,
9728of type @var{dmd-root-service-type}; it can be extended by passing it
9729lists of @code{<dmd-service>} objects.
0adfe95a
LC
9730
9731@deftp {Data Type} dmd-service
9732The data type representing a service managed by dmd.
9733
9734@table @asis
9735@item @code{provision}
9736This is a list of symbols denoting what the service provides.
9737
9738These are the names that may be passed to @command{deco start},
9739@command{deco status}, and similar commands (@pxref{Invoking deco,,,
9740dmd, GNU dmd Manual}). @xref{Slots of services, the @code{provides}
9741slot,, dmd, GNU dmd Manual}, for details.
9742
9743@item @code{requirements} (default: @code{'()})
9744List of symbols denoting the dmd services this one depends on.
9745
9746@item @code{respawn?} (default: @code{#t})
9747Whether to restart the service when it stops, for instance when the
9748underlying process dies.
9749
9750@item @code{start}
9751@itemx @code{stop} (default: @code{#~(const #f)})
cf4a9129
LC
9752The @code{start} and @code{stop} fields refer to dmd's facilities to
9753start and stop processes (@pxref{Service De- and Constructors,,, dmd,
0adfe95a
LC
9754GNU dmd Manual}). They are given as G-expressions that get expanded in
9755the dmd configuration file (@pxref{G-Expressions}).
9756
9757@item @code{documentation}
9758A documentation string, as shown when running:
9759
9760@example
9761deco doc @var{service-name}
9762@end example
9763
9764where @var{service-name} is one of the symbols in @var{provision}
9765(@pxref{Invoking deco,,, dmd, GNU dmd Manual}).
fae685b9
LC
9766
9767@item @code{modules} (default: @var{%default-modules})
9768This is the list of modules that must be in scope when @code{start} and
9769@code{stop} are evaluated.
9770
9771@item @code{imported-modules} (default: @var{%default-imported-modules})
9772This is the list of modules to import in the execution environment of
9773dmd.
9774
0adfe95a
LC
9775@end table
9776@end deftp
9777
9778@defvr {Scheme Variable} dmd-root-service-type
9779The service type for the dmd ``root service''---i.e., PID@tie{}1.
9780
9781This is the service type that extensions target when they want to create
9782dmd services (@pxref{Service Types and Services}, for an example). Each
9783extension must pass a list of @code{<dmd-service>}.
9784@end defvr
9785
9786@defvr {Scheme Variable} %dmd-root-service
9787This service represents PID@tie{}1.
9788@end defvr
8451a568 9789
8451a568 9790
cf4a9129
LC
9791@node Installing Debugging Files
9792@section Installing Debugging Files
8451a568 9793
cf4a9129
LC
9794@cindex debugging files
9795Program binaries, as produced by the GCC compilers for instance, are
9796typically written in the ELF format, with a section containing
9797@dfn{debugging information}. Debugging information is what allows the
9798debugger, GDB, to map binary code to source code; it is required to
9799debug a compiled program in good conditions.
8451a568 9800
cf4a9129
LC
9801The problem with debugging information is that is takes up a fair amount
9802of disk space. For example, debugging information for the GNU C Library
9803weighs in at more than 60 MiB. Thus, as a user, keeping all the
9804debugging info of all the installed programs is usually not an option.
9805Yet, space savings should not come at the cost of an impediment to
9806debugging---especially in the GNU system, which should make it easier
9807for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 9808
cf4a9129
LC
9809Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
9810mechanism that allows users to get the best of both worlds: debugging
9811information can be stripped from the binaries and stored in separate
9812files. GDB is then able to load debugging information from those files,
9813when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
9814with GDB}).
8451a568 9815
cf4a9129
LC
9816The GNU distribution takes advantage of this by storing debugging
9817information in the @code{lib/debug} sub-directory of a separate package
9818output unimaginatively called @code{debug} (@pxref{Packages with
9819Multiple Outputs}). Users can choose to install the @code{debug} output
9820of a package when they need it. For instance, the following command
9821installs the debugging information for the GNU C Library and for GNU
9822Guile:
8451a568
LC
9823
9824@example
cf4a9129 9825guix package -i glibc:debug guile:debug
8451a568
LC
9826@end example
9827
cf4a9129
LC
9828GDB must then be told to look for debug files in the user's profile, by
9829setting the @code{debug-file-directory} variable (consider setting it
9830from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
9831GDB}):
8451a568 9832
cf4a9129
LC
9833@example
9834(gdb) set debug-file-directory ~/.guix-profile/lib/debug
9835@end example
8451a568 9836
cf4a9129
LC
9837From there on, GDB will pick up debugging information from the
9838@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 9839
cf4a9129
LC
9840In addition, you will most likely want GDB to be able to show the source
9841code being debugged. To do that, you will have to unpack the source
9842code of the package of interest (obtained with @code{guix build
9843--source}, @pxref{Invoking guix build}), and to point GDB to that source
9844directory using the @code{directory} command (@pxref{Source Path,
9845@code{directory},, gdb, Debugging with GDB}).
8451a568 9846
cf4a9129
LC
9847@c XXX: keep me up-to-date
9848The @code{debug} output mechanism in Guix is implemented by the
9849@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
9850opt-in---debugging information is available only for those packages
9851whose definition explicitly declares a @code{debug} output. This may be
9852changed to opt-out in the future, if our build farm servers can handle
9853the load. To check whether a package has a @code{debug} output, use
9854@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 9855
8451a568 9856
05962f29
LC
9857@node Security Updates
9858@section Security Updates
9859
843858b8
LC
9860@quotation Note
9861As of version @value{VERSION}, the feature described in this section is
9862experimental.
9863@end quotation
05962f29
LC
9864
9865@cindex security updates
9866Occasionally, important security vulnerabilities are discovered in core
9867software packages and must be patched. Guix follows a functional
9868package management discipline (@pxref{Introduction}), which implies
9869that, when a package is changed, @emph{every package that depends on it}
9870must be rebuilt. This can significantly slow down the deployment of
9871fixes in core packages such as libc or Bash, since basically the whole
9872distribution would need to be rebuilt. Using pre-built binaries helps
9873(@pxref{Substitutes}), but deployment may still take more time than
9874desired.
9875
9876@cindex grafts
9877To address that, Guix implements @dfn{grafts}, a mechanism that allows
9878for fast deployment of critical updates without the costs associated
9879with a whole-distribution rebuild. The idea is to rebuild only the
9880package that needs to be patched, and then to ``graft'' it onto packages
9881explicitly installed by the user and that were previously referring to
9882the original package. The cost of grafting is typically very low, and
9883order of magnitudes lower than a full rebuild of the dependency chain.
9884
9885@cindex replacements of packages, for grafts
9886For instance, suppose a security update needs to be applied to Bash.
9887Guix developers will provide a package definition for the ``fixed''
9888Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
9889Packages}). Then, the original package definition is augmented with a
9890@code{replacement} field pointing to the package containing the bug fix:
9891
9892@example
9893(define bash
9894 (package
9895 (name "bash")
9896 ;; @dots{}
9897 (replacement bash-fixed)))
9898@end example
9899
9900From there on, any package depending directly or indirectly on Bash that
9901is installed will automatically be ``rewritten'' to refer to
9902@var{bash-fixed} instead of @var{bash}. This grafting process takes
9903time proportional to the size of the package, but expect less than a
9904minute for an ``average'' package on a recent machine.
9905
9906Currently, the graft and the package it replaces (@var{bash-fixed} and
9907@var{bash} in the example above) must have the exact same @code{name}
9908and @code{version} fields. This restriction mostly comes from the fact
9909that grafting works by patching files, including binary files, directly.
9910Other restrictions may apply: for instance, when adding a graft to a
9911package providing a shared library, the original shared library and its
9912replacement must have the same @code{SONAME} and be binary-compatible.
9913
9914
cf4a9129
LC
9915@node Package Modules
9916@section Package Modules
8451a568 9917
cf4a9129
LC
9918From a programming viewpoint, the package definitions of the
9919GNU distribution are provided by Guile modules in the @code{(gnu packages
9920@dots{})} name space@footnote{Note that packages under the @code{(gnu
9921packages @dots{})} module name space are not necessarily ``GNU
9922packages''. This module naming scheme follows the usual Guile module
9923naming convention: @code{gnu} means that these modules are distributed
9924as part of the GNU system, and @code{packages} identifies modules that
9925define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
9926Reference Manual}). For instance, the @code{(gnu packages emacs)}
9927module exports a variable named @code{emacs}, which is bound to a
9928@code{<package>} object (@pxref{Defining Packages}).
113daf62 9929
300868ba 9930The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
9931automatically scanned for packages by the command-line tools. For
9932instance, when running @code{guix package -i emacs}, all the @code{(gnu
9933packages @dots{})} modules are scanned until one that exports a package
9934object whose name is @code{emacs} is found. This package search
9935facility is implemented in the @code{(gnu packages)} module.
113daf62 9936
300868ba 9937@cindex customization, of packages
8689901f 9938@cindex package module search path
cf4a9129 9939Users can store package definitions in modules with different
60142854 9940names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
9941name and module name must match. For instance, the @code{(my-packages
9942emacs)} module must be stored in a @file{my-packages/emacs.scm} file
9943relative to the load path specified with @option{--load-path} or
9944@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
9945guile, GNU Guile Reference Manual}, for details.}. These package definitions
300868ba
LC
9946will not be visible by default. Thus, users can invoke commands such as
9947@command{guix package} and @command{guix build} have to be used with the
c95ded7e
LC
9948@code{-e} option so that they know where to find the package. Better
9949yet, they can use the
300868ba 9950@code{-L} option of these commands to make those modules visible
8689901f
LC
9951(@pxref{Invoking guix build, @code{--load-path}}), or define the
9952@code{GUIX_PACKAGE_PATH} environment variable. This environment
9953variable makes it easy to extend or customize the distribution and is
9954honored by all the user interfaces.
9955
9956@defvr {Environment Variable} GUIX_PACKAGE_PATH
9957This is a colon-separated list of directories to search for package
9958modules. Directories listed in this variable take precedence over the
9959distribution's own modules.
9960@end defvr
ef5dd60a 9961
cf4a9129
LC
9962The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
9963each package is built based solely on other packages in the
9964distribution. The root of this dependency graph is a small set of
9965@dfn{bootstrap binaries}, provided by the @code{(gnu packages
9966bootstrap)} module. For more information on bootstrapping,
081145cf 9967@pxref{Bootstrapping}.
ef5dd60a 9968
cf4a9129
LC
9969@node Packaging Guidelines
9970@section Packaging Guidelines
ef5dd60a 9971
cf4a9129
LC
9972The GNU distribution is nascent and may well lack some of your favorite
9973packages. This section describes how you can help make the distribution
9974grow. @xref{Contributing}, for additional information on how you can
9975help.
ef5dd60a 9976
cf4a9129
LC
9977Free software packages are usually distributed in the form of
9978@dfn{source code tarballs}---typically @file{tar.gz} files that contain
9979all the source files. Adding a package to the distribution means
9980essentially two things: adding a @dfn{recipe} that describes how to
9981build the package, including a list of other packages required to build
9982it, and adding @dfn{package meta-data} along with that recipe, such as a
9983description and licensing information.
ef5dd60a 9984
cf4a9129
LC
9985In Guix all this information is embodied in @dfn{package definitions}.
9986Package definitions provide a high-level view of the package. They are
9987written using the syntax of the Scheme programming language; in fact,
9988for each package we define a variable bound to the package definition,
9989and export that variable from a module (@pxref{Package Modules}).
9990However, in-depth Scheme knowledge is @emph{not} a prerequisite for
9991creating packages. For more information on package definitions,
081145cf 9992@pxref{Defining Packages}.
ef5dd60a 9993
cf4a9129
LC
9994Once a package definition is in place, stored in a file in the Guix
9995source tree, it can be tested using the @command{guix build} command
9996(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
9997called @code{gnew}, you may run this command from the Guix build tree
9998(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
9999
10000@example
cf4a9129 10001./pre-inst-env guix build gnew --keep-failed
ef5dd60a 10002@end example
ef5dd60a 10003
cf4a9129
LC
10004Using @code{--keep-failed} makes it easier to debug build failures since
10005it provides access to the failed build tree. Another useful
10006command-line option when debugging is @code{--log-file}, to access the
10007build log.
ef5dd60a 10008
cf4a9129
LC
10009If the package is unknown to the @command{guix} command, it may be that
10010the source file contains a syntax error, or lacks a @code{define-public}
10011clause to export the package variable. To figure it out, you may load
10012the module from Guile to get more information about the actual error:
ef5dd60a 10013
cf4a9129
LC
10014@example
10015./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
10016@end example
ef5dd60a 10017
cf4a9129
LC
10018Once your package builds correctly, please send us a patch
10019(@pxref{Contributing}). Well, if you need help, we will be happy to
10020help you too. Once the patch is committed in the Guix repository, the
10021new package automatically gets built on the supported platforms by
2b1cee21 10022@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 10023system}.
ef5dd60a 10024
cf4a9129
LC
10025@cindex substituter
10026Users can obtain the new package definition simply by running
10027@command{guix pull} (@pxref{Invoking guix pull}). When
10028@code{hydra.gnu.org} is done building the package, installing the
10029package automatically downloads binaries from there
10030(@pxref{Substitutes}). The only place where human intervention is
10031needed is to review and apply the patch.
ef5dd60a 10032
ef5dd60a 10033
cf4a9129 10034@menu
ec0339cd
LC
10035* Software Freedom:: What may go into the distribution.
10036* Package Naming:: What's in a name?
10037* Version Numbers:: When the name is not enough.
cbd02397 10038* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
10039* Python Modules:: Taming the snake.
10040* Perl Modules:: Little pearls.
10041* Fonts:: Fond of fonts.
cf4a9129 10042@end menu
ef5dd60a 10043
cf4a9129
LC
10044@node Software Freedom
10045@subsection Software Freedom
ef5dd60a 10046
cf4a9129 10047@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
c11a6eb1 10048
cf4a9129
LC
10049The GNU operating system has been developed so that users can have
10050freedom in their computing. GNU is @dfn{free software}, meaning that
10051users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
10052essential freedoms}: to run the program, to study and change the program
10053in source code form, to redistribute exact copies, and to distribute
10054modified versions. Packages found in the GNU distribution provide only
10055software that conveys these four freedoms.
c11a6eb1 10056
cf4a9129
LC
10057In addition, the GNU distribution follow the
10058@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
10059software distribution guidelines}. Among other things, these guidelines
10060reject non-free firmware, recommendations of non-free software, and
10061discuss ways to deal with trademarks and patents.
ef5dd60a 10062
cf4a9129
LC
10063Some packages contain a small and optional subset that violates the
10064above guidelines, for instance because this subset is itself non-free
10065code. When that happens, the offending items are removed with
10066appropriate patches or code snippets in the package definition's
10067@code{origin} form (@pxref{Defining Packages}). That way, @code{guix
10068build --source} returns the ``freed'' source rather than the unmodified
10069upstream source.
ef5dd60a 10070
ef5dd60a 10071
cf4a9129
LC
10072@node Package Naming
10073@subsection Package Naming
ef5dd60a 10074
cf4a9129
LC
10075A package has actually two names associated with it:
10076First, there is the name of the @emph{Scheme variable}, the one following
10077@code{define-public}. By this name, the package can be made known in the
10078Scheme code, for instance as input to another package. Second, there is
10079the string in the @code{name} field of a package definition. This name
10080is used by package management commands such as
10081@command{guix package} and @command{guix build}.
ef5dd60a 10082
cf4a9129
LC
10083Both are usually the same and correspond to the lowercase conversion of
10084the project name chosen upstream, with underscores replaced with
10085hyphens. For instance, GNUnet is available as @code{gnunet}, and
10086SDL_net as @code{sdl-net}.
927097ef 10087
cf4a9129 10088We do not add @code{lib} prefixes for library packages, unless these are
081145cf 10089already part of the official project name. But @pxref{Python
cf4a9129
LC
10090Modules} and @ref{Perl Modules} for special rules concerning modules for
10091the Python and Perl languages.
927097ef 10092
1b366ee4 10093Font package names are handled differently, @pxref{Fonts}.
7fec52b7 10094
ef5dd60a 10095
cf4a9129
LC
10096@node Version Numbers
10097@subsection Version Numbers
ef5dd60a 10098
cf4a9129
LC
10099We usually package only the latest version of a given free software
10100project. But sometimes, for instance for incompatible library versions,
10101two (or more) versions of the same package are needed. These require
10102different Scheme variable names. We use the name as defined
10103in @ref{Package Naming}
10104for the most recent version; previous versions use the same name, suffixed
10105by @code{-} and the smallest prefix of the version number that may
10106distinguish the two versions.
ef5dd60a 10107
cf4a9129
LC
10108The name inside the package definition is the same for all versions of a
10109package and does not contain any version number.
ef5dd60a 10110
cf4a9129 10111For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 10112
cf4a9129
LC
10113@example
10114(define-public gtk+
10115 (package
17d8e33f
ML
10116 (name "gtk+")
10117 (version "3.9.12")
10118 ...))
cf4a9129
LC
10119(define-public gtk+-2
10120 (package
17d8e33f
ML
10121 (name "gtk+")
10122 (version "2.24.20")
10123 ...))
cf4a9129
LC
10124@end example
10125If we also wanted GTK+ 3.8.2, this would be packaged as
10126@example
10127(define-public gtk+-3.8
10128 (package
17d8e33f
ML
10129 (name "gtk+")
10130 (version "3.8.2")
10131 ...))
cf4a9129 10132@end example
ef5dd60a 10133
880d647d
LC
10134@c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
10135@c for a discussion of what follows.
10136@cindex version number, for VCS snapshots
10137Occasionally, we package snapshots of upstream's version control system
10138(VCS) instead of formal releases. This should remain exceptional,
10139because it is up to upstream developers to clarify what the stable
10140release is. Yet, it is sometimes necessary. So, what should we put in
10141the @code{version} field?
10142
10143Clearly, we need to make the commit identifier of the VCS snapshot
10144visible in the version string, but we also need to make sure that the
10145version string is monotonically increasing so that @command{guix package
10146--upgrade} can determine which version is newer. Since commit
10147identifiers, notably with Git, are not monotonically increasing, we add
10148a revision number that we increase each time we upgrade to a newer
10149snapshot. The resulting version string looks like this:
10150
10151@example
101522.0.11-3.cabba9e
10153 ^ ^ ^
10154 | | `-- upstream commit ID
10155 | |
10156 | `--- Guix package revision
10157 |
10158latest upstream version
10159@end example
10160
10161It is a good idea to strip commit identifiers in the @code{version}
10162field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
10163aesthetics have a role to play here) as well as problems related to OS
10164limits such as the maximum shebang length (127 bytes for the Linux
10165kernel.) It is best to use the full commit identifiers in
10166@code{origin}s, though, to avoid ambiguities.
10167
cbd02397
LC
10168@node Synopses and Descriptions
10169@subsection Synopses and Descriptions
10170
10171As we have seen before, each package in GNU@tie{}Guix includes a
10172synopsis and a description (@pxref{Defining Packages}). Synopses and
10173descriptions are important: They are what @command{guix package
10174--search} searches, and a crucial piece of information to help users
10175determine whether a given package suits their needs. Consequently,
10176packagers should pay attention to what goes into them.
10177
10178Synopses must start with a capital letter and must not end with a
10179period. They must not start with ``a'' or ``the'', which usually does
10180not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
10181tool that frobs files''. The synopsis should say what the package
10182is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
10183used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
10184matching a pattern''.
10185
10186Keep in mind that the synopsis must be meaningful for a very wide
10187audience. For example, ``Manipulate alignments in the SAM format''
10188might make sense for a seasoned bioinformatics researcher, but might be
10189fairly unhelpful or even misleading to a non-specialized audience. It
10190is a good idea to come up with a synopsis that gives an idea of the
10191application domain of the package. In this example, this might give
10192something like ``Manipulate nucleotide sequence alignments'', which
10193hopefully gives the user a better idea of whether this is what they are
10194looking for.
10195
10196@cindex Texinfo markup, in package descriptions
10197Descriptions should take between five and ten lines. Use full
10198sentences, and avoid using acronyms without first introducing them.
10199Descriptions can include Texinfo markup, which is useful to introduce
10200ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
10201hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
10202should be careful when using some characters for example @samp{@@} and
10203curly braces which are the basic special characters in Texinfo
10204(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
10205such as @command{guix package --show} take care of rendering it
10206appropriately.
cbd02397
LC
10207
10208Synopses and descriptions are translated by volunteers
10209@uref{http://translationproject.org/domain/guix-packages.html, at the
10210Translation Project} so that as many users as possible can read them in
10211their native language. User interfaces search them and display them in
10212the language specified by the current locale.
10213
10214Translation is a lot of work so, as a packager, please pay even more
10215attention to your synopses and descriptions as every change may entail
ba7d6c76 10216additional work for translators. In order to help them, it is possible
36743e71 10217to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
10218special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
10219Gettext}):
10220
10221@example
10222;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
10223(description "ARandR is designed to provide a simple visual front end
10224for the X11 resize-and-rotate (RandR) extension. @dots{}")
10225@end example
cbd02397 10226
ef5dd60a 10227
cf4a9129
LC
10228@node Python Modules
10229@subsection Python Modules
ef5dd60a 10230
cf4a9129
LC
10231We currently package Python 2 and Python 3, under the Scheme variable names
10232@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
10233To avoid confusion and naming clashes with other programming languages, it
10234seems desirable that the name of a package for a Python module contains
10235the word @code{python}.
ef5dd60a 10236
cf4a9129
LC
10237Some modules are compatible with only one version of Python, others with both.
10238If the package Foo compiles only with Python 3, we name it
10239@code{python-foo}; if it compiles only with Python 2, we name it
10240@code{python2-foo}. If it is compatible with both versions, we create two
10241packages with the corresponding names.
ef5dd60a 10242
cf4a9129
LC
10243If a project already contains the word @code{python}, we drop this;
10244for instance, the module python-dateutil is packaged under the names
10245@code{python-dateutil} and @code{python2-dateutil}.
113daf62 10246
523e4896 10247
cf4a9129
LC
10248@node Perl Modules
10249@subsection Perl Modules
523e4896 10250
cf4a9129
LC
10251Perl programs standing for themselves are named as any other package,
10252using the lowercase upstream name.
10253For Perl packages containing a single class, we use the lowercase class name,
10254replace all occurrences of @code{::} by dashes and prepend the prefix
10255@code{perl-}.
10256So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
10257Modules containing several classes keep their lowercase upstream name and
10258are also prepended by @code{perl-}. Such modules tend to have the word
10259@code{perl} somewhere in their name, which gets dropped in favor of the
10260prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 10261
523e4896 10262
7fec52b7
AE
10263@node Fonts
10264@subsection Fonts
10265
10266For fonts that are in general not installed by a user for typesetting
10267purposes, or that are distributed as part of a larger software package,
10268we rely on the general packaging rules for software; for instance, this
10269applies to the fonts delivered as part of the X.Org system or fonts that
10270are part of TeX Live.
10271
10272To make it easier for a user to search for fonts, names for other packages
10273containing only fonts are constructed as follows, independently of the
10274upstream package name.
10275
10276The name of a package containing only one font family starts with
10277@code{font-}; it is followed by the foundry name and a dash @code{-}
10278if the foundry is known, and the font family name, in which spaces are
10279replaced by dashes (and as usual, all upper case letters are transformed
10280to lower case).
10281For example, the Gentium font family by SIL is packaged under the name
10282@code{font-sil-gentium}.
10283
10284For a package containing several font families, the name of the collection
10285is used in the place of the font family name.
10286For instance, the Liberation fonts consist of three families,
10287Liberation Sans, Liberation Serif and Liberation Mono.
10288These could be packaged separately under the names
10289@code{font-liberation-sans} and so on; but as they are distributed together
10290under a common name, we prefer to package them together as
10291@code{font-liberation}.
10292
10293In the case where several formats of the same font family or font collection
10294are packaged separately, a short form of the format, prepended by a dash,
10295is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 10296@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
10297fonts.
10298
10299
b25937e3 10300
cf4a9129
LC
10301@node Bootstrapping
10302@section Bootstrapping
b25937e3 10303
cf4a9129 10304@c Adapted from the ELS 2013 paper.
b25937e3 10305
cf4a9129 10306@cindex bootstrapping
7889394e 10307
cf4a9129
LC
10308Bootstrapping in our context refers to how the distribution gets built
10309``from nothing''. Remember that the build environment of a derivation
10310contains nothing but its declared inputs (@pxref{Introduction}). So
10311there's an obvious chicken-and-egg problem: how does the first package
10312get built? How does the first compiler get compiled? Note that this is
10313a question of interest only to the curious hacker, not to the regular
10314user, so you can shamelessly skip this section if you consider yourself
10315a ``regular user''.
72b9d60d 10316
cf4a9129
LC
10317@cindex bootstrap binaries
10318The GNU system is primarily made of C code, with libc at its core. The
10319GNU build system itself assumes the availability of a Bourne shell and
10320command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
10321`grep'. Furthermore, build programs---programs that run
10322@code{./configure}, @code{make}, etc.---are written in Guile Scheme
10323(@pxref{Derivations}). Consequently, to be able to build anything at
10324all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
10325Binutils, libc, and the other packages mentioned above---the
10326@dfn{bootstrap binaries}.
72b9d60d 10327
cf4a9129
LC
10328These bootstrap binaries are ``taken for granted'', though we can also
10329re-create them if needed (more on that later).
72b9d60d 10330
cf4a9129 10331@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 10332
cf4a9129
LC
10333@c As of Emacs 24.3, Info-mode displays the image, but since it's a
10334@c large image, it's hard to scroll. Oh well.
10335@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 10336
cf4a9129
LC
10337The figure above shows the very beginning of the dependency graph of the
10338distribution, corresponding to the package definitions of the @code{(gnu
d33fa0c7
LC
10339packages bootstrap)} module. A similar figure can be generated with
10340@command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
10341
10342@example
10343guix graph -t derivation \
10344 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
10345 | dot -Tps > t.ps
10346@end example
10347
10348At this level of detail, things are
cf4a9129
LC
10349slightly complex. First, Guile itself consists of an ELF executable,
10350along with many source and compiled Scheme files that are dynamically
10351loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
10352tarball shown in this graph. This tarball is part of Guix's ``source''
10353distribution, and gets inserted into the store with @code{add-to-store}
10354(@pxref{The Store}).
2e7b5cea 10355
cf4a9129
LC
10356But how do we write a derivation that unpacks this tarball and adds it
10357to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
10358derivation---the first one that gets built---uses @code{bash} as its
10359builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
10360@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
10361@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
10362the Guix source distribution, whose sole purpose is to allow the Guile
10363tarball to be unpacked.
fb729425 10364
cf4a9129
LC
10365Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
10366Guile that can be used to run subsequent build programs. Its first task
10367is to download tarballs containing the other pre-built binaries---this
10368is what the @code{.tar.xz.drv} derivations do. Guix modules such as
10369@code{ftp-client.scm} are used for this purpose. The
10370@code{module-import.drv} derivations import those modules in a directory
10371in the store, using the original layout. The
10372@code{module-import-compiled.drv} derivations compile those modules, and
10373write them in an output directory with the right layout. This
10374corresponds to the @code{#:modules} argument of
10375@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 10376
cf4a9129
LC
10377Finally, the various tarballs are unpacked by the
10378derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
10379etc., at which point we have a working C tool chain.
fb729425 10380
fb729425 10381
cf4a9129 10382@unnumberedsubsec Building the Build Tools
523e4896 10383
cf4a9129
LC
10384Bootstrapping is complete when we have a full tool chain that does not
10385depend on the pre-built bootstrap tools discussed above. This
10386no-dependency requirement is verified by checking whether the files of
10387the final tool chain contain references to the @file{/gnu/store}
10388directories of the bootstrap inputs. The process that leads to this
10389``final'' tool chain is described by the package definitions found in
1f6f57df 10390the @code{(gnu packages commencement)} module.
df2ce343 10391
d33fa0c7
LC
10392The @command{guix graph} command allows us to ``zoom out'' compared to
10393the graph above, by looking at the level of package objects instead of
10394individual derivations---remember that a package may translate to
10395several derivations, typically one derivation to download its source,
10396one to build the Guile modules it needs, and one to actually build the
10397package from source. The command:
10398
10399@example
10400guix graph -t bag \
10401 -e '(@@@@ (gnu packages commencement)
10402 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
10403@end example
10404
10405@noindent
10406produces the dependency graph leading to the ``final'' C
10407library@footnote{You may notice the @code{glibc-intermediate} label,
10408suggesting that it is not @emph{quite} final, but as a good
10409approximation, we will consider it final.}, depicted below.
10410
10411@image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
10412
cf4a9129
LC
10413@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
10414The first tool that gets built with the bootstrap binaries is
d33fa0c7
LC
10415GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
10416for all the following packages. From there Findutils and Diffutils get
10417built.
523e4896 10418
cf4a9129
LC
10419Then come the first-stage Binutils and GCC, built as pseudo cross
10420tools---i.e., with @code{--target} equal to @code{--host}. They are
10421used to build libc. Thanks to this cross-build trick, this libc is
10422guaranteed not to hold any reference to the initial tool chain.
4af2447e 10423
d33fa0c7
LC
10424From there the final Binutils and GCC (not shown above) are built.
10425GCC uses @code{ld}
cf4a9129
LC
10426from the final Binutils, and links programs against the just-built libc.
10427This tool chain is used to build the other packages used by Guix and by
10428the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 10429
cf4a9129
LC
10430And voilà! At this point we have the complete set of build tools that
10431the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
10432variable of the @code{(gnu packages commencement)} module, and are
10433implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 10434(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 10435
4af2447e 10436
cf4a9129 10437@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 10438
cf4a9129
LC
10439Because the final tool chain does not depend on the bootstrap binaries,
10440those rarely need to be updated. Nevertheless, it is useful to have an
10441automated way to produce them, should an update occur, and this is what
10442the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 10443
cf4a9129
LC
10444The following command builds the tarballs containing the bootstrap
10445binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
10446of Coreutils and other basic command-line tools):
4b2615e1 10447
cf4a9129
LC
10448@example
10449guix build bootstrap-tarballs
10450@end example
10451
10452The generated tarballs are those that should be referred to in the
10453@code{(gnu packages bootstrap)} module mentioned at the beginning of
10454this section.
10455
10456Still here? Then perhaps by now you've started to wonder: when do we
10457reach a fixed point? That is an interesting question! The answer is
10458unknown, but if you would like to investigate further (and have
10459significant computational and storage resources to do so), then let us
10460know.
10461
10462@node Porting
10463@section Porting to a New Platform
10464
10465As discussed above, the GNU distribution is self-contained, and
10466self-containment is achieved by relying on pre-built ``bootstrap
10467binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
10468operating system kernel, CPU architecture, and application binary
10469interface (ABI). Thus, to port the distribution to a platform that is
10470not yet supported, one must build those bootstrap binaries, and update
10471the @code{(gnu packages bootstrap)} module to use them on that platform.
10472
10473Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
10474When everything goes well, and assuming the GNU tool chain supports the
10475target platform, this can be as simple as running a command like this
10476one:
10477
10478@example
10479guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
10480@end example
10481
1c0c417d
LC
10482For this to work, the @code{glibc-dynamic-linker} procedure in
10483@code{(gnu packages bootstrap)} must be augmented to return the right
10484file name for libc's dynamic linker on that platform; likewise,
10485@code{system->linux-architecture} in @code{(gnu packages linux)} must be
10486taught about the new platform.
10487
cf4a9129 10488Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
10489to be updated to refer to these binaries on the target platform. That
10490is, the hashes and URLs of the bootstrap tarballs for the new platform
10491must be added alongside those of the currently supported platforms. The
10492bootstrap Guile tarball is treated specially: it is expected to be
10493available locally, and @file{gnu-system.am} has rules do download it for
10494the supported architectures; a rule for the new platform must be added
10495as well.
cf4a9129
LC
10496
10497In practice, there may be some complications. First, it may be that the
10498extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
10499above) is not recognized by all the GNU tools. Typically, glibc
10500recognizes some of these, whereas GCC uses an extra @code{--with-abi}
10501configure flag (see @code{gcc.scm} for examples of how to handle this).
10502Second, some of the required packages could fail to build for that
10503platform. Lastly, the generated binaries could be broken for some
10504reason.
4af2447e 10505
9bf3c1a7 10506@c *********************************************************************
8c01b9d0 10507@include contributing.texi
c78bd12b 10508
568717fd
LC
10509@c *********************************************************************
10510@node Acknowledgments
10511@chapter Acknowledgments
10512
136787cb
LC
10513Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
10514which was designed and
4c7ac9aa
LC
10515implemented by Eelco Dolstra, with contributions from other people (see
10516the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
10517management, and promoted unprecedented features, such as transactional
10518package upgrades and rollbacks, per-user profiles, and referentially
10519transparent build processes. Without this work, Guix would not exist.
10520
10521The Nix-based software distributions, Nixpkgs and NixOS, have also been
10522an inspiration for Guix.
10523
4c7ac9aa
LC
10524GNU@tie{}Guix itself is a collective work with contributions from a
10525number of people. See the @file{AUTHORS} file in Guix for more
10526information on these fine people. The @file{THANKS} file lists people
10527who have helped by reporting bugs, taking care of the infrastructure,
10528providing artwork and themes, making suggestions, and more---thank you!
10529
10530
568717fd
LC
10531@c *********************************************************************
10532@node GNU Free Documentation License
10533@appendix GNU Free Documentation License
10534
10535@include fdl-1.3.texi
10536
10537@c *********************************************************************
10538@node Concept Index
10539@unnumbered Concept Index
10540@printindex cp
10541
a85b83d2
LC
10542@node Programming Index
10543@unnumbered Programming Index
10544@syncodeindex tp fn
10545@syncodeindex vr fn
568717fd
LC
10546@printindex fn
10547
10548@bye
10549
10550@c Local Variables:
10551@c ispell-local-dictionary: "american";
10552@c End: