services: avahi: Export service type.
[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
LC
401
402@item
403To use substitutes from @code{hydra.gnu.org} (@pxref{Substitutes}),
404authorize them:
405
406@example
7acd3439 407# guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
39f8ed14 408@end example
09722b11
LC
409@end enumerate
410
53de532f
LC
411And that's it! For additional tips and tricks, @pxref{Application
412Setup}.
09722b11 413
5dc3ce5f 414The @code{guix} package must remain available in @code{root}'s
09722b11
LC
415profile, or it would become subject to garbage collection---in which
416case you would find yourself badly handicapped by the lack of the
417@command{guix} command.
418
39f8ed14
LC
419The tarball in question can be (re)produced and verified simply by
420running the following command in the Guix source tree:
09722b11
LC
421
422@example
423make guix-binary.@var{system}.tar.xz
424@end example
425
426
bd5e766b
LC
427@node Requirements
428@section Requirements
429
09722b11
LC
430This section lists requirements when building Guix from source. The
431build procedure for Guix is the same as for other GNU software, and is
432not covered here. Please see the files @file{README} and @file{INSTALL}
433in the Guix source tree for additional details.
434
bd5e766b
LC
435GNU Guix depends on the following packages:
436
437@itemize
47c66da0 438@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
288dca55 439@item @url{http://gnupg.org/, GNU libgcrypt};
f0b98b84 440@item @url{http://www.gnu.org/software/make/, GNU Make}.
8a96bd4b
ID
441@end itemize
442
443The following dependencies are optional:
444
445@itemize
288dca55 446@item
8a96bd4b 447Installing
288dca55 448@url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
2f7d2d91
LC
449allow you to use the @command{guix import pypi} command (@pxref{Invoking
450guix import}). It is of
288dca55 451interest primarily for developers and not for casual users.
8a96bd4b
ID
452@item
453Installing @uref{http://gnutls.org/, GnuTLS-Guile} will
454allow you to access @code{https} URLs with the @command{guix download}
d45dc6da
EB
455command (@pxref{Invoking guix download}), the @command{guix import pypi}
456command, and the @command{guix import cpan} command. This is primarily
457of interest to developers. @xref{Guile Preparations, how to install the
458GnuTLS bindings for Guile,, gnutls-guile, GnuTLS-Guile}.
bd5e766b
LC
459@end itemize
460
461Unless @code{--disable-daemon} was passed to @command{configure}, the
462following packages are also needed:
463
464@itemize
368d08f7
LC
465@item @url{http://sqlite.org, SQLite 3};
466@item @url{http://www.bzip.org, libbz2};
467@item @url{http://gcc.gnu.org, GCC's g++}, with support for the
468C++11 standard.
bd5e766b
LC
469@end itemize
470
4bfc4ea3
NK
471When a working installation of @url{http://nixos.org/nix/, the Nix package
472manager} is available, you
bd5e766b 473can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 474Nix replaces the three dependencies above.
bd5e766b 475
b22a12fd
LC
476Guix is compatible with Nix, so it is possible to share the same store
477between both. To do so, you must pass @command{configure} not only the
478same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
479@code{--localstatedir} value. The latter is essential because it
480specifies where the database that stores metadata about the store is
834129e0 481located, among other things. The default values for Nix are
b22a12fd 482@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
483Note that @code{--disable-daemon} is not required if
484your goal is to share the store with Nix.
b22a12fd 485
ec0339cd
LC
486@node Running the Test Suite
487@section Running the Test Suite
488
489After a successful @command{configure} and @code{make} run, it is a good
490idea to run the test suite. It can help catch issues with the setup or
491environment, or bugs in Guix itself---and really, reporting test
492failures is a good way to help improve the software. To run the test
493suite, type:
494
495@example
496make check
497@end example
498
499Test cases can run in parallel: you can use the @code{-j} option of
500GNU@tie{}make to speed things up. The first run may take a few minutes
501on a recent machine; subsequent runs will be faster because the store
502that is created for test purposes will already have various things in
503cache.
504
a887fd8d
LC
505It is also possible to run a subset of the tests by defining the
506@code{TESTS} makefile variable as in this example:
507
508@example
509make check TESTS="tests/store.scm tests/cpio.scm"
510@end example
511
ec0339cd
LC
512Upon failure, please email @email{bug-guix@@gnu.org} and attach the
513@file{test-suite.log} file. When @file{tests/@var{something}.scm}
514fails, please also attach the @file{@var{something}.log} file available
515in the top-level build directory. Please specify the Guix version being
516used as well as version numbers of the dependencies
517(@pxref{Requirements}) in your message.
518
bd5e766b
LC
519@node Setting Up the Daemon
520@section Setting Up the Daemon
521
522@cindex daemon
523Operations such as building a package or running the garbage collector
49e6291a 524are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
525behalf of clients. Only the daemon may access the store and its
526associated database. Thus, any operation that manipulates the store
527goes through the daemon. For instance, command-line tools such as
e49951eb 528@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
529daemon (@i{via} remote procedure calls) to instruct it what to do.
530
49e6291a 531The following sections explain how to prepare the build daemon's
225dafde
LC
532environment. Also @ref{Substitutes}, for information on how to allow
533the daemon to download pre-built binaries.
49e6291a
LC
534
535@menu
536* Build Environment Setup:: Preparing the isolated build environment.
537* Daemon Offload Setup:: Offloading builds to remote machines.
538@end menu
539
540@node Build Environment Setup
541@subsection Build Environment Setup
542
bd5e766b
LC
543In a standard multi-user setup, Guix and its daemon---the
544@command{guix-daemon} program---are installed by the system
834129e0 545administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
546@command{guix-daemon} runs as @code{root}. Unprivileged users may use
547Guix tools to build packages or otherwise access the store, and the
548daemon will do it on their behalf, ensuring that the store is kept in a
549consistent state, and allowing built packages to be shared among users.
550
551@cindex build users
552When @command{guix-daemon} runs as @code{root}, you may not want package
553build processes themselves to run as @code{root} too, for obvious
554security reasons. To avoid that, a special pool of @dfn{build users}
555should be created for use by build processes started by the daemon.
556These build users need not have a shell and a home directory: they will
557just be used when the daemon drops @code{root} privileges in build
558processes. Having several such users allows the daemon to launch
559distinct build processes under separate UIDs, which guarantees that they
560do not interfere with each other---an essential feature since builds are
561regarded as pure functions (@pxref{Introduction}).
562
563On a GNU/Linux system, a build user pool may be created like this (using
564Bash syntax and the @code{shadow} commands):
565
091196b3
LC
566@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
567@c for why `-G' is needed.
bd5e766b 568@example
cfc149dc
LC
569# groupadd --system guixbuild
570# for i in `seq -w 1 10`;
bd5e766b 571 do
cfc149dc
LC
572 useradd -g guixbuild -G guixbuild \
573 -d /var/empty -s `which nologin` \
574 -c "Guix build user $i" --system \
575 guixbuilder$i;
bd5e766b
LC
576 done
577@end example
578
579@noindent
54eb03ab
LC
580The number of build users determines how many build jobs may run in
581parallel, as specified by the @option{--max-jobs} option
d2825c96
LC
582(@pxref{Invoking guix-daemon, @option{--max-jobs}}). The
583@code{guix-daemon} program may then be run as @code{root} with the
584following command@footnote{If your machine uses the systemd init system,
585dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
586file in @file{/etc/systemd/system} will ensure that
ad227484
MDRS
587@command{guix-daemon} is automatically started. Similarly, if your
588machine uses the Upstart init system, drop the
589@file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
590file in @file{/etc/init}.}:
bd5e766b
LC
591
592@example
cfc149dc 593# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
594@end example
595
e900c503 596@cindex chroot
b095792f
LC
597@noindent
598This way, the daemon starts build processes in a chroot, under one of
cfc149dc 599the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
600environment contains nothing but:
601
602@c Keep this list in sync with libstore/build.cc! -----------------------
603@itemize
604@item
4743a4da
LC
605a minimal @code{/dev} directory, created mostly independently from the
606host @code{/dev}@footnote{``Mostly'', because while the set of files
607that appear in the chroot's @code{/dev} is fixed, most of these files
608can only be created if the host has them.};
609
610@item
611the @code{/proc} directory; it only shows the container's processes
612since a separate PID name space is used;
6dc99317
LC
613
614@item
615@file{/etc/passwd} with an entry for the current user and an entry for
616user @file{nobody};
617
618@item
619@file{/etc/group} with an entry for the user's group;
620
621@item
622@file{/etc/hosts} with an entry that maps @code{localhost} to
623@code{127.0.0.1};
624
625@item
626a writable @file{/tmp} directory.
627@end itemize
b095792f 628
cb960102
ED
629You can influence the directory where the daemon stores build trees
630@i{via} the @code{TMPDIR} environment variable. However, the build tree
7a57c96a 631within the chroot is always @file{/tmp/guix-build-@var{name}.drv-0},
cb960102
ED
632where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
633This way, the value of @code{TMPDIR} does not leak inside build
634environments, which avoids discrepancies in cases where build processes
635capture the name of their build tree.
636
e0c941fe
LC
637@vindex http_proxy
638The daemon also honors the @code{http_proxy} environment variable for
639HTTP downloads it performs, be it for fixed-output derivations
640(@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
641
1e2644bb
LC
642If you are installing Guix as an unprivileged user, it is still possible
643to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
644However, build processes will not be isolated from one another, and not
645from the rest of the system. Thus, build processes may interfere with
646each other, and may access programs, libraries, and other files
647available on the system---making it much harder to view them as
648@emph{pure} functions.
bd5e766b 649
49e6291a
LC
650
651@node Daemon Offload Setup
652@subsection Using the Offload Facility
653
654@cindex offloading
4ec2e92d
LC
655@cindex build hook
656When desired, the build daemon can @dfn{offload}
657derivation builds to other machines
49e6291a
LC
658running Guix, using the @code{offload} @dfn{build hook}. When that
659feature is enabled, a list of user-specified build machines is read from
660@file{/etc/guix/machines.scm}; anytime a build is requested, for
661instance via @code{guix build}, the daemon attempts to offload it to one
662of the machines that satisfies the derivation's constraints, in
663particular its system type---e.g., @file{x86_64-linux}. Missing
664prerequisites for the build are copied over SSH to the target machine,
665which then proceeds with the build; upon success the output(s) of the
666build are copied back to the initial machine.
667
4ec2e92d 668The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
669
670@example
671(list (build-machine
672 (name "eightysix.example.org")
673 (system "x86_64-linux")
674 (user "bob")
675 (speed 2.)) ; incredibly fast!
676
677 (build-machine
678 (name "meeps.example.org")
679 (system "mips64el-linux")
680 (user "alice")
681 (private-key
682 (string-append (getenv "HOME")
c4fdfd6f 683 "/.lsh/identity-for-guix"))))
49e6291a
LC
684@end example
685
686@noindent
687In the example above we specify a list of two build machines, one for
688the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
689architecture.
690
691In fact, this file is---not surprisingly!---a Scheme file that is
692evaluated when the @code{offload} hook is started. Its return value
693must be a list of @code{build-machine} objects. While this example
694shows a fixed list of build machines, one could imagine, say, using
695DNS-SD to return a list of potential build machines discovered in the
696local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
c678a4ee
LC
697Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
698detailed below.
4ec2e92d 699
c678a4ee
LC
700@deftp {Data Type} build-machine
701This data type represents build machines the daemon may offload builds
702to. The important fields are:
49e6291a
LC
703
704@table @code
705
706@item name
707The remote machine's host name.
708
709@item system
c678a4ee 710The remote machine's system type---e.g., @code{"x86_64-linux"}.
49e6291a
LC
711
712@item user
713The user account to use when connecting to the remote machine over SSH.
714Note that the SSH key pair must @emph{not} be passphrase-protected, to
715allow non-interactive logins.
716
717@end table
718
4ec2e92d 719A number of optional fields may be specified:
49e6291a
LC
720
721@table @code
722
cecd72d5
LC
723@item port
724Port number of the machine's SSH server (default: 22).
725
49e6291a
LC
726@item private-key
727The SSH private key file to use when connecting to the machine.
728
c4fdfd6f
LC
729Currently offloading uses GNU@tie{}lsh as its SSH client
730(@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must
731be an lsh key file. This may change in the future, though.
732
49e6291a
LC
733@item parallel-builds
734The number of builds that may run in parallel on the machine (1 by
735default.)
736
737@item speed
738A ``relative speed factor''. The offload scheduler will tend to prefer
739machines with a higher speed factor.
740
741@item features
742A list of strings denoting specific features supported by the machine.
743An example is @code{"kvm"} for machines that have the KVM Linux modules
744and corresponding hardware support. Derivations can request features by
745name, and they will be scheduled on matching build machines.
746
747@end table
c678a4ee 748@end deftp
49e6291a
LC
749
750The @code{guix} command must be in the search path on the build
751machines, since offloading works by invoking the @code{guix archive} and
c4fdfd6f
LC
752@code{guix build} commands. In addition, the Guix modules must be in
753@code{$GUILE_LOAD_PATH} on the build machine---you can check whether
754this is the case by running:
755
756@example
757lsh build-machine guile -c '(use-modules (guix config))'
758@end example
49e6291a
LC
759
760There's one last thing to do once @file{machines.scm} is in place. As
761explained above, when offloading, files are transferred back and forth
c4fdfd6f
LC
762between the machine stores. For this to work, you first need to
763generate a key pair on each machine to allow the daemon to export signed
764archives of files from the store (@pxref{Invoking guix archive}):
49e6291a
LC
765
766@example
767# guix archive --generate-key
768@end example
769
770@noindent
c4fdfd6f
LC
771Each build machine must authorize the key of the master machine so that
772it accepts store items it receives from the master:
773
774@example
775# guix archive --authorize < master-public-key.txt
776@end example
777
778@noindent
779Likewise, the master machine must authorize the key of each build machine.
780
781All the fuss with keys is here to express pairwise mutual trust
782relations between the master and the build machines. Concretely, when
783the master receives files from a build machine (and @i{vice versa}), its
784build daemon can make sure they are genuine, have not been tampered
785with, and that they are signed by an authorized key.
49e6291a
LC
786
787
bd5e766b
LC
788@node Invoking guix-daemon
789@section Invoking @command{guix-daemon}
790
791The @command{guix-daemon} program implements all the functionality to
792access the store. This includes launching build processes, running the
793garbage collector, querying the availability of a build result, etc. It
794is normally run as @code{root} like this:
795
796@example
cfc149dc 797# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
798@end example
799
800@noindent
081145cf 801For details on how to set it up, @pxref{Setting Up the Daemon}.
bd5e766b 802
e900c503
LC
803@cindex chroot
804@cindex container, build environment
805@cindex build environment
806@cindex reproducible builds
bd5e766b
LC
807By default, @command{guix-daemon} launches build processes under
808different UIDs, taken from the build group specified with
809@code{--build-users-group}. In addition, each build process is run in a
810chroot environment that only contains the subset of the store that the
811build process depends on, as specified by its derivation
812(@pxref{Programming Interface, derivation}), plus a set of specific
813system directories. By default, the latter contains @file{/dev} and
e900c503
LC
814@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
815@dfn{container}: in addition to having its own file system tree, it has
816a separate mount name space, its own PID name space, network name space,
817etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b 818
cbc538fe
LC
819When the daemon performs a build on behalf of the user, it creates a
820build directory under @file{/tmp} or under the directory specified by
821its @code{TMPDIR} environment variable; this directory is shared with
822the container for the duration of the build. Be aware that using a
823directory other than @file{/tmp} can affect build results---for example,
824with a longer directory name, a build process that uses Unix-domain
825sockets might hit the name length limitation for @code{sun_path}, which
826it would otherwise not hit.
827
828The build directory is automatically deleted upon completion, unless the
829build failed and the client specified @option{--keep-failed}
830(@pxref{Invoking guix build, @option{--keep-failed}}).
831
bd5e766b
LC
832The following command-line options are supported:
833
834@table @code
835@item --build-users-group=@var{group}
836Take users from @var{group} to run build processes (@pxref{Setting Up
837the Daemon, build users}).
838
6858f9d1 839@item --no-substitutes
b5385b52 840@cindex substitutes
6858f9d1 841Do not use substitutes for build products. That is, always build things
c4202d60
LC
842locally instead of allowing downloads of pre-built binaries
843(@pxref{Substitutes}).
6858f9d1 844
b5385b52
LC
845By default substitutes are used, unless the client---such as the
846@command{guix package} command---is explicitly invoked with
847@code{--no-substitutes}.
848
849When the daemon runs with @code{--no-substitutes}, clients can still
850explicitly enable substitution @i{via} the @code{set-build-options}
851remote procedure call (@pxref{The Store}).
852
9176607e 853@item --substitute-urls=@var{urls}
f8a8e0fe 854@anchor{daemon-substitute-urls}
9176607e 855Consider @var{urls} the default whitespace-separated list of substitute
ae806096 856source URLs. When this option is omitted, @indicateurl{http://hydra.gnu.org}
9176607e
LC
857is used.
858
859This means that substitutes may be downloaded from @var{urls}, as long
860as they are signed by a trusted signature (@pxref{Substitutes}).
861
4ec2e92d
LC
862@cindex build hook
863@item --no-build-hook
864Do not use the @dfn{build hook}.
865
866The build hook is a helper program that the daemon can start and to
867which it submits build requests. This mechanism is used to offload
868builds to other machines (@pxref{Daemon Offload Setup}).
869
bd5e766b
LC
870@item --cache-failures
871Cache build failures. By default, only successful builds are cached.
872
30d9aa54
LC
873When this option is used, @command{guix gc --list-failures} can be used
874to query the set of store items marked as failed; @command{guix gc
875--clear-failures} removes store items from the set of cached failures.
876@xref{Invoking guix gc}.
877
bd5e766b
LC
878@item --cores=@var{n}
879@itemx -c @var{n}
880Use @var{n} CPU cores to build each derivation; @code{0} means as many
881as available.
882
6efc160e 883The default value is @code{0}, but it may be overridden by clients, such
e49951eb
MW
884as the @code{--cores} option of @command{guix build} (@pxref{Invoking
885guix build}).
bd5e766b
LC
886
887The effect is to define the @code{NIX_BUILD_CORES} environment variable
888in the build process, which can then use it to exploit internal
889parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
890
891@item --max-jobs=@var{n}
892@itemx -M @var{n}
893Allow at most @var{n} build jobs in parallel. The default value is
f6526eb3
LC
894@code{1}. Setting it to @code{0} means that no builds will be performed
895locally; instead, the daemon will offload builds (@pxref{Daemon Offload
896Setup}), or simply fail.
bd5e766b 897
ecf84b7c
LC
898@item --rounds=@var{N}
899Build each derivation @var{n} times in a row, and raise an error if
900consecutive build results are not bit-for-bit identical. Note that this
901setting can be overridden by clients such as @command{guix build}
902(@pxref{Invoking guix build}).
903
bd5e766b
LC
904@item --debug
905Produce debugging output.
906
907This is useful to debug daemon start-up issues, but then it may be
908overridden by clients, for example the @code{--verbosity} option of
e49951eb 909@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
910
911@item --chroot-directory=@var{dir}
912Add @var{dir} to the build chroot.
913
914Doing this may change the result of build processes---for instance if
915they use optional dependencies found in @var{dir} when it is available,
916and not otherwise. For that reason, it is not recommended to do so.
917Instead, make sure that each derivation declares all the inputs that it
918needs.
919
920@item --disable-chroot
921Disable chroot builds.
922
923Using this option is not recommended since, again, it would allow build
1e2644bb
LC
924processes to gain access to undeclared dependencies. It is necessary,
925though, when @command{guix-daemon} is running under an unprivileged user
926account.
bd5e766b
LC
927
928@item --disable-log-compression
929Disable compression of the build logs.
930
1da983b9
LC
931Unless @code{--lose-logs} is used, all the build logs are kept in the
932@var{localstatedir}. To save space, the daemon automatically compresses
933them with bzip2 by default. This option disables that.
934
ab3893d7
LC
935@item --disable-deduplication
936@cindex deduplication
bd5e766b
LC
937Disable automatic file ``deduplication'' in the store.
938
1da983b9 939By default, files added to the store are automatically ``deduplicated'':
ab3893d7
LC
940if a newly added file is identical to another one found in the store,
941the daemon makes the new file a hard link to the other file. This can
4988dd40 942noticeably reduce disk usage, at the expense of slightly increased
ab3893d7
LC
943input/output load at the end of a build process. This option disables
944this optimization.
1da983b9 945
6e37066e
LC
946@item --gc-keep-outputs[=yes|no]
947Tell whether the garbage collector (GC) must keep outputs of live
948derivations.
949
950When set to ``yes'', the GC will keep the outputs of any live derivation
951available in the store---the @code{.drv} files. The default is ``no'',
952meaning that derivation outputs are kept only if they are GC roots.
953
954@item --gc-keep-derivations[=yes|no]
955Tell whether the garbage collector (GC) must keep derivations
956corresponding to live outputs.
957
958When set to ``yes'', as is the case by default, the GC keeps
959derivations---i.e., @code{.drv} files---as long as at least one of their
960outputs is live. This allows users to keep track of the origins of
961items in their store. Setting it to ``no'' saves a bit of disk space.
962
963Note that when both @code{--gc-keep-derivations} and
964@code{--gc-keep-outputs} are used, the effect is to keep all the build
965prerequisites (the sources, compiler, libraries, and other build-time
966tools) of live objects in the store, regardless of whether these
967prerequisites are live. This is convenient for developers since it
968saves rebuilds or downloads.
969
bd5e766b
LC
970@item --impersonate-linux-2.6
971On Linux-based systems, impersonate Linux 2.6. This means that the
972kernel's @code{uname} system call will report 2.6 as the release number.
973
974This might be helpful to build programs that (usually wrongfully) depend
975on the kernel version number.
976
977@item --lose-logs
978Do not keep build logs. By default they are kept under
ce33631f 979@code{@var{localstatedir}/guix/log}.
bd5e766b
LC
980
981@item --system=@var{system}
982Assume @var{system} as the current system type. By default it is the
983architecture/kernel pair found at configure time, such as
984@code{x86_64-linux}.
b8d2aa26
LC
985
986@item --listen=@var{socket}
987Listen for connections on @var{socket}, the file name of a Unix-domain
988socket. The default socket is
989@file{@var{localstatedir}/daemon-socket/socket}. This option is only
990useful in exceptional circumstances, such as if you need to run several
991daemons on the same machine.
bd5e766b
LC
992@end table
993
994
0e2d0213
LC
995@node Application Setup
996@section Application Setup
997
85e57214
LC
998When using Guix on top of GNU/Linux distribution other than GuixSD---a
999so-called @dfn{foreign distro}---a few additional steps are needed to
1000get everything in place. Here are some of them.
0e2d0213
LC
1001
1002@subsection Locales
1003
5c3c1427 1004@anchor{locales-and-locpath}
0e2d0213 1005@cindex locales, when not on GuixSD
5c3c1427 1006@vindex LOCPATH
85e57214 1007@vindex GUIX_LOCPATH
0e2d0213
LC
1008Packages installed @i{via} Guix will not use the host system's locale
1009data. Instead, you must first install one of the locale packages
85e57214
LC
1010available with Guix and then define the @code{GUIX_LOCPATH} environment
1011variable:
0e2d0213
LC
1012
1013@example
1014$ guix package -i glibc-locales
85e57214 1015$ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
0e2d0213
LC
1016@end example
1017
1018Note that the @code{glibc-locales} package contains data for all the
1019locales supported by the GNU@tie{}libc and weighs in at around
1020110@tie{}MiB. Alternately, the @code{glibc-utf8-locales} is smaller but
1021limited to a few UTF-8 locales.
1022
85e57214
LC
1023The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1024(@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1025Manual}). There are two important differences though:
1026
1027@enumerate
1028@item
1029@code{GUIX_LOCPATH} is honored only by Guix's libc, and not by the libc
1030provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
f9b9a033 1031to make sure the foreign distro's programs will not end up loading
85e57214
LC
1032incompatible locale data.
1033
1034@item
1035libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1036@code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1037should your Guix profile contain a mixture of programs linked against
1038different libc version, each libc version will only try to load locale
1039data in the right format.
1040@end enumerate
1041
1042This is important because the locale data format used by different libc
1043versions may be incompatible.
1044
0e2d0213
LC
1045@subsection X11 Fonts
1046
4988dd40 1047The majority of graphical applications use Fontconfig to locate and
0e2d0213
LC
1048load fonts and perform X11-client-side rendering. Guix's
1049@code{fontconfig} package looks for fonts in @file{$HOME/.guix-profile}
1050by default. Thus, to allow graphical applications installed with Guix
1051to display fonts, you will have to install fonts with Guix as well.
1052Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
8fe5b1d1 1053@code{font-gnu-freefont-ttf}.
0e2d0213 1054
5c36edc8
LC
1055To display text written in Chinese languages, Japanese, or Korean in
1056graphical applications, consider installing
1057@code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1058has multiple outputs, one per language family (@pxref{Packages with
1059Multiple Outputs}). For instance, the following command installs fonts
1060for Chinese languages:
1061
1062@example
1063guix package -i font-adobe-source-han-sans:cn
1064@end example
1065
0e2d0213
LC
1066@c TODO What else?
1067
eeaf4427
LC
1068@c *********************************************************************
1069@node Package Management
1070@chapter Package Management
1071
f8348b91 1072The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427
LC
1073remove software packages, without having to know about their build
1074procedure or dependencies. Guix also goes beyond this obvious set of
1075features.
1076
1077This chapter describes the main features of Guix, as well as the package
c1941588 1078management tools it provides. Two user interfaces are provided for
c554de89
AK
1079routine package management tasks: A command-line interface described below
1080(@pxref{Invoking guix package, @code{guix package}}), as well as a visual user
1081interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}).
eeaf4427
LC
1082
1083@menu
1084* Features:: How Guix will make your life brighter.
e49951eb 1085* Invoking guix package:: Package installation, removal, etc.
c4202d60 1086* Substitutes:: Downloading pre-built binaries.
760c60d6 1087* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 1088* Invoking guix gc:: Running the garbage collector.
f651b477 1089* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 1090* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
1091@end menu
1092
1093@node Features
1094@section Features
1095
1096When using Guix, each package ends up in the @dfn{package store}, in its
1097own directory---something that resembles
9a130e19
AK
1098@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
1099(note that Guix comes with an Emacs extension to shorten those file
081145cf 1100names, @pxref{Emacs Prettify}.)
eeaf4427
LC
1101
1102Instead of referring to these directories, users have their own
1103@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
1104use. These profiles are stored within each user's home directory, at
1105@code{$HOME/.guix-profile}.
eeaf4427 1106
821b0015 1107For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 1108@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 1109@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
1110@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1111simply continues to point to
834129e0 1112@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 1113coexist on the same system without any interference.
eeaf4427 1114
e49951eb
MW
1115The @command{guix package} command is the central tool to manage
1116packages (@pxref{Invoking guix package}). It operates on those per-user
821b0015 1117profiles, and can be used @emph{with normal user privileges}.
eeaf4427
LC
1118
1119The command provides the obvious install, remove, and upgrade
1120operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 1121the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 1122@command{guix package} process is terminated during the transaction,
eeaf4427
LC
1123or if a power outage occurs during the transaction, then the user's
1124profile remains in its previous state, and remains usable.
1125
1126In addition, any package transaction may be @emph{rolled back}. So, if,
1127for example, an upgrade installs a new version of a package that turns
1128out to have a serious bug, users may roll back to the previous instance
4af2447e
LC
1129of their profile, which was known to work well. Similarly, the global
1130system configuration is subject to transactional upgrades and roll-back
1131(@pxref{Using the Configuration System}).
eeaf4427
LC
1132
1133All those packages in the package store may be @emph{garbage-collected}.
1134Guix can determine which packages are still referenced by the user
fe8ff028 1135profiles, and remove those that are provably no longer referenced
e49951eb 1136(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
1137generations of their profile so that the packages they refer to can be
1138collected.
eeaf4427 1139
e900c503
LC
1140@cindex reproducibility
1141@cindex reproducible builds
eeaf4427
LC
1142Finally, Guix takes a @dfn{purely functional} approach to package
1143management, as described in the introduction (@pxref{Introduction}).
834129e0 1144Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
1145inputs that were used to build that package---compiler, libraries, build
1146scripts, etc. This direct correspondence allows users to make sure a
1147given package installation matches the current state of their
e900c503
LC
1148distribution. It also helps maximize @dfn{build reproducibility}:
1149thanks to the isolated build environments that are used, a given build
1150is likely to yield bit-identical files when performed on different
1151machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 1152
c4202d60 1153@cindex substitutes
eeaf4427 1154This foundation allows Guix to support @dfn{transparent binary/source
c4202d60 1155deployment}. When a pre-built binary for a @file{/gnu/store} item is
18f2887b 1156available from an external source---a @dfn{substitute}, Guix just
c4202d60
LC
1157downloads it and unpacks it;
1158otherwise, it builds the package from source, locally
1159(@pxref{Substitutes}).
eeaf4427 1160
f5fd4fd2
LC
1161Control over the build environment is a feature that is also useful for
1162developers. The @command{guix environment} command allows developers of
1163a package to quickly set up the right development environment for their
1164package, without having to manually install the package's dependencies
1165in their profile (@pxref{Invoking guix environment}).
1166
e49951eb
MW
1167@node Invoking guix package
1168@section Invoking @command{guix package}
eeaf4427 1169
e49951eb 1170The @command{guix package} command is the tool that allows users to
eeaf4427
LC
1171install, upgrade, and remove packages, as well as rolling back to
1172previous configurations. It operates only on the user's own profile,
1173and works with normal user privileges (@pxref{Features}). Its syntax
1174is:
1175
1176@example
e49951eb 1177guix package @var{options}
eeaf4427
LC
1178@end example
1179
ba55b1cb 1180Primarily, @var{options} specifies the operations to be performed during
eeaf4427 1181the transaction. Upon completion, a new profile is created, but
99bd74d5 1182previous @dfn{generations} of the profile remain available, should the user
eeaf4427
LC
1183want to roll back.
1184
6447738c
MW
1185For example, to remove @code{lua} and install @code{guile} and
1186@code{guile-cairo} in a single transaction:
1187
1188@example
1189guix package -r lua -i guile guile-cairo
1190@end example
1191
99bd74d5
LC
1192@command{guix package} also supports a @dfn{declarative approach}
1193whereby the user specifies the exact set of packages to be available and
1194passes it @i{via} the @option{--manifest} option
1195(@pxref{profile-manifest, @option{--manifest}}).
1196
b9e5c0a9 1197For each user, a symlink to the user's default profile is automatically
0ec1af59 1198created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
1199current generation of the user's default profile. Thus, users can add
1200@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1201variable, and so on.
d664f1b4
LC
1202@cindex search paths
1203If you are not using the Guix System Distribution, consider adding the
1204following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1205Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1206shells get all the right environment variable definitions:
1207
1208@example
1209GUIX_PROFILE="$HOME/.guix-profile" \
1210source "$HOME/.guix-profile/etc/profile"
1211@end example
b9e5c0a9 1212
4379c35b
LC
1213In a multi-user setup, user profiles are stored in a place registered as
1214a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1215to (@pxref{Invoking guix gc}). That directory is normally
0ec1af59
LC
1216@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1217@var{localstatedir} is the value passed to @code{configure} as
4379c35b
LC
1218@code{--localstatedir}, and @var{user} is the user name. The
1219@file{per-user} directory is created when @command{guix-daemon} is
1220started, and the @var{user} sub-directory is created by @command{guix
1221package}.
0ec1af59
LC
1222
1223The @var{options} can be among the following:
1224
eeaf4427
LC
1225@table @code
1226
6447738c
MW
1227@item --install=@var{package} @dots{}
1228@itemx -i @var{package} @dots{}
1229Install the specified @var{package}s.
eeaf4427 1230
6447738c 1231Each @var{package} may specify either a simple package name, such as
eeaf4427 1232@code{guile}, or a package name followed by a hyphen and version number,
724311a2
LC
1233such as @code{guile-1.8.8} or simply @code{guile-1.8} (in the latter
1234case, the newest version prefixed by @code{1.8} is selected.)
1235
1236If no version number is specified, the
dc5669cd
MW
1237newest available version will be selected. In addition, @var{package}
1238may contain a colon, followed by the name of one of the outputs of the
6e721c4d 1239package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
e7f34eb0
LC
1240(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1241name (and optionally version) are searched for among the GNU
1242distribution modules (@pxref{Package Modules}).
eeaf4427 1243
461572cc
LC
1244@cindex propagated inputs
1245Sometimes packages have @dfn{propagated inputs}: these are dependencies
21461f27
LC
1246that automatically get installed along with the required package
1247(@pxref{package-propagated-inputs, @code{propagated-inputs} in
1248@code{package} objects}, for information about propagated inputs in
1249package definitions).
461572cc 1250
21461f27 1251@anchor{package-cmd-propagated-inputs}
461572cc
LC
1252An example is the GNU MPC library: its C header files refer to those of
1253the GNU MPFR library, which in turn refer to those of the GMP library.
1254Thus, when installing MPC, the MPFR and GMP libraries also get installed
1255in the profile; removing MPC also removes MPFR and GMP---unless they had
1256also been explicitly installed independently.
1257
ba7ea5ce 1258Besides, packages sometimes rely on the definition of environment
5924080d 1259variables for their search paths (see explanation of
ba7ea5ce 1260@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
1261environment variable definitions are reported here.
1262
ef010c0f 1263@c XXX: keep me up-to-date
5924080d 1264Finally, when installing a GNU package, the tool reports the
ef010c0f
LC
1265availability of a newer upstream version. In the future, it may provide
1266the option of installing directly from the upstream version, even if
1267that version is not yet in the distribution.
1268
5d4b411f
LC
1269@item --install-from-expression=@var{exp}
1270@itemx -e @var{exp}
1271Install the package @var{exp} evaluates to.
1272
1273@var{exp} must be a Scheme expression that evaluates to a
1274@code{<package>} object. This option is notably useful to disambiguate
1275between same-named variants of a package, with expressions such as
1276@code{(@@ (gnu packages base) guile-final)}.
1277
1278Note that this option installs the first output of the specified
1279package, which may be insufficient when needing a specific output of a
1280multiple-output package.
1281
0d279400
DT
1282@item --install-from-file=@var{file}
1283@itemx -f @var{file}
1284Install the package that the code within @var{file} evaluates to.
1285
1286As an example, @var{file} might contain a definition like this
1287(@pxref{Defining Packages}):
1288
1289@example
1290@verbatiminclude package-hello.scm
1291@end example
1292
1293Developers may find it useful to include such a @file{package.scm} file
1294in the root of their project's source tree that can be used to test
1295development snapshots and create reproducible development environments
1296(@pxref{Invoking guix environment}).
1297
6447738c
MW
1298@item --remove=@var{package} @dots{}
1299@itemx -r @var{package} @dots{}
1300Remove the specified @var{package}s.
eeaf4427 1301
6447738c 1302As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
1303and/or output name in addition to the package name. For instance,
1304@code{-r glibc:debug} would remove the @code{debug} output of
1305@code{glibc}.
1306
6447738c
MW
1307@item --upgrade[=@var{regexp} @dots{}]
1308@itemx -u [@var{regexp} @dots{}]
1309Upgrade all the installed packages. If one or more @var{regexp}s are
1310specified, upgrade only installed packages whose name matches a
d5f01e48 1311@var{regexp}. Also see the @code{--do-not-upgrade} option below.
eeaf4427 1312
f651b477
LC
1313Note that this upgrades package to the latest version of packages found
1314in the distribution currently installed. To update your distribution,
1315you should regularly run @command{guix pull} (@pxref{Invoking guix
1316pull}).
1317
d5f01e48
MW
1318@item --do-not-upgrade[=@var{regexp} @dots{}]
1319When used together with the @code{--upgrade} option, do @emph{not}
1320upgrade any packages whose name matches a @var{regexp}. For example, to
1321upgrade all packages in the current profile except those containing the
1322substring ``emacs'':
1323
1324@example
1325$ guix package --upgrade . --do-not-upgrade emacs
1326@end example
1327
99bd74d5 1328@item @anchor{profile-manifest}--manifest=@var{file}
1b676447 1329@itemx -m @var{file}
99bd74d5
LC
1330@cindex profile declaration
1331@cindex profile manifest
1332Create a new generation of the profile from the manifest object
1b676447
DT
1333returned by the Scheme code in @var{file}.
1334
99bd74d5
LC
1335This allows you to @emph{declare} the profile's contents rather than
1336constructing it through a sequence of @code{--install} and similar
1337commands. The advantage is that @var{file} can be put under version
1338control, copied to different machines to reproduce the same profile, and
1339so on.
1340
1341@c FIXME: Add reference to (guix profile) documentation when available.
1342@var{file} must return a @dfn{manifest} object, which is roughly a list
1343of packages:
1b676447 1344
99bd74d5 1345@findex packages->manifest
1b676447 1346@example
99bd74d5 1347(use-package-modules guile emacs)
1b676447
DT
1348
1349(packages->manifest
99bd74d5
LC
1350 (list emacs
1351 guile-2.0
1b676447 1352 ;; Use a specific package output.
99bd74d5 1353 (list guile-2.0 "debug")))
1b676447
DT
1354@end example
1355
24e262f0
LC
1356@item --roll-back
1357Roll back to the previous @dfn{generation} of the profile---i.e., undo
1358the last transaction.
1359
1360When combined with options such as @code{--install}, roll back occurs
1361before any other actions.
1362
d9307267 1363When rolling back from the first generation that actually contains
4b2bc804
NK
1364installed packages, the profile is made to point to the @dfn{zeroth
1365generation}, which contains no files apart from its own meta-data.
d9307267 1366
82fe08ed
LC
1367Installing, removing, or upgrading packages from a generation that has
1368been rolled back to overwrites previous future generations. Thus, the
1369history of a profile's generations is always linear.
1370
b3bb82f1
AK
1371@item --switch-generation=@var{pattern}
1372@itemx -S @var{pattern}
1373Switch to a particular generation defined by @var{pattern}.
1374
1375@var{pattern} may be either a generation number or a number prefixed
1376with ``+'' or ``-''. The latter means: move forward/backward by a
1377specified number of generations. For example, if you want to return to
1378the latest generation after @code{--roll-back}, use
1379@code{--switch-generation=+1}.
1380
1381The difference between @code{--roll-back} and
1382@code{--switch-generation=-1} is that @code{--switch-generation} will
1383not make a zeroth generation, so if a specified generation does not
1384exist, the current generation will not be changed.
1385
dbc31ab2 1386@item --search-paths[=@var{kind}]
5924080d
LC
1387@cindex search paths
1388Report environment variable definitions, in Bash syntax, that may be
1389needed in order to use the set of installed packages. These environment
1390variables are used to specify @dfn{search paths} for files used by some
1391of the installed packages.
1392
1393For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1394environment variables to be defined so it can look for headers and
1395libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1396Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1397library are installed in the profile, then @code{--search-paths} will
1398suggest setting these variables to @code{@var{profile}/include} and
1399@code{@var{profile}/lib}, respectively.
1400
dbc31ab2
LC
1401The typical use case is to define these environment variables in the
1402shell:
1403
1404@example
1405$ eval `guix package --search-paths`
1406@end example
1407
1408@var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1409meaning that the returned environment variable definitions will either
1410be exact settings, or prefixes or suffixes of the current value of these
1411variables. When omitted, @var{kind} defaults to @code{exact}.
1412
fc2d2339
LC
1413This option can also be used to compute the @emph{combined} search paths
1414of several profiles. Consider this example:
1415
1416@example
1417$ guix package -p foo -i guile
1418$ guix package -p bar -i guile-json
1419$ guix package -p foo -p bar --search-paths
1420@end example
1421
1422The last command above reports about the @code{GUILE_LOAD_PATH}
1423variable, even though, taken individually, neither @file{foo} nor
1424@file{bar} would lead to that recommendation.
1425
1426
eeaf4427
LC
1427@item --profile=@var{profile}
1428@itemx -p @var{profile}
1429Use @var{profile} instead of the user's default profile.
1430
70915c1a
LC
1431@item --verbose
1432Produce verbose output. In particular, emit the environment's build log
1433on the standard error port.
1434
eeaf4427
LC
1435@item --bootstrap
1436Use the bootstrap Guile to build the profile. This option is only
1437useful to distribution developers.
1438
1439@end table
1440
e49951eb 1441In addition to these actions @command{guix package} supports the
733b4130
LC
1442following options to query the current state of a profile, or the
1443availability of packages:
eeaf4427 1444
733b4130
LC
1445@table @option
1446
acc08466
NK
1447@item --search=@var{regexp}
1448@itemx -s @var{regexp}
b110869d 1449@cindex searching for packages
5763ad92 1450List the available packages whose name, synopsis, or description matches
299112d3
LC
1451@var{regexp}. Print all the meta-data of matching packages in
1452@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1453GNU recutils manual}).
acc08466 1454
299112d3
LC
1455This allows specific fields to be extracted using the @command{recsel}
1456command, for instance:
1457
1458@example
e49951eb 1459$ guix package -s malloc | recsel -p name,version
299112d3
LC
1460name: glibc
1461version: 2.17
1462
1463name: libgc
1464version: 7.2alpha6
1465@end example
acc08466 1466
a12d92f5
LC
1467Similarly, to show the name of all the packages available under the
1468terms of the GNU@tie{}LGPL version 3:
1469
1470@example
1471$ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1472name: elfutils
1473
1474name: gmp
1475@dots{}
1476@end example
1477
db5a9444
LC
1478It is also possible to refine search results using several @code{-s}
1479flags. For example, the following command returns a list of board
1480games:
1481
1482@example
1483$ guix package -s '\<board\>' -s game | recsel -p name
1484name: gnubg
1485@dots{}
1486@end example
1487
1488If we were to omit @code{-s game}, we would also get software packages
1489that deal with printed circuit boards; removing the angle brackets
1490around @code{board} would further add packages that have to do with
1491keyboards.
1492
b110869d
LC
1493And now for a more elaborate example. The following command searches
1494for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1495libraries, and prints the name and synopsis of the matching packages:
1496
1497@example
1498$ guix package -s crypto -s library | \
1499 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1500@end example
1501
1502@noindent
1503@xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1504information on @dfn{selection expressions} for @code{recsel -e}.
1505
2aa6efb0
CR
1506@item --show=@var{package}
1507Show details about @var{package}, taken from the list of available packages, in
1508@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1509recutils manual}).
1510
1511@example
1512$ guix package --show=python | recsel -p name,version
1513name: python
1514version: 2.7.6
1515
1516name: python
1517version: 3.3.5
1518@end example
1519
1520You may also specify the full name of a package to only get details about a
1521specific version of it:
1522@example
1523$ guix package --show=python-3.3.5 | recsel -p name,version
1524name: python
1525version: 3.3.5
1526@end example
1527
1528
1529
733b4130
LC
1530@item --list-installed[=@var{regexp}]
1531@itemx -I [@var{regexp}]
bd9bde1c
LC
1532List the currently installed packages in the specified profile, with the
1533most recently installed packages shown last. When @var{regexp} is
1534specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
1535
1536For each installed package, print the following items, separated by
1537tabs: the package name, its version string, the part of the package that
1538is installed (for instance, @code{out} for the default output,
1539@code{include} for its headers, etc.), and the path of this package in
1540the store.
1541
64fc89b6
LC
1542@item --list-available[=@var{regexp}]
1543@itemx -A [@var{regexp}]
5763ad92 1544List packages currently available in the distribution for this system
a1ba8475
LC
1545(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1546installed packages whose name matches @var{regexp}.
64fc89b6
LC
1547
1548For each package, print the following items separated by tabs: its name,
6e721c4d
LC
1549its version string, the parts of the package (@pxref{Packages with
1550Multiple Outputs}), and the source location of its definition.
64fc89b6 1551
f566d765
LC
1552@item --list-generations[=@var{pattern}]
1553@itemx -l [@var{pattern}]
1554Return a list of generations along with their creation dates; for each
1555generation, show the installed packages, with the most recently
4b2bc804
NK
1556installed packages shown last. Note that the zeroth generation is never
1557shown.
f566d765
LC
1558
1559For each installed package, print the following items, separated by
1560tabs: the name of a package, its version string, the part of the package
1561that is installed (@pxref{Packages with Multiple Outputs}), and the
1562location of this package in the store.
1563
1564When @var{pattern} is used, the command returns only matching
1565generations. Valid patterns include:
1566
1567@itemize
1568@item @emph{Integers and comma-separated integers}. Both patterns denote
1569generation numbers. For instance, @code{--list-generations=1} returns
1570the first one.
1571
1572And @code{--list-generations=1,8,2} outputs three generations in the
1573specified order. Neither spaces nor trailing commas are allowed.
1574
1575@item @emph{Ranges}. @code{--list-generations=2..9} prints the
1576specified generations and everything in between. Note that the start of
1577a range must be lesser than its end.
1578
1579It is also possible to omit the endpoint. For example,
1580@code{--list-generations=2..}, returns all generations starting from the
1581second one.
1582
1583@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1584or months by passing an integer along with the first letter of the
d7ddb257
LC
1585duration. For example, @code{--list-generations=20d} lists generations
1586that are up to 20 days old.
f566d765
LC
1587@end itemize
1588
b7884ca3
NK
1589@item --delete-generations[=@var{pattern}]
1590@itemx -d [@var{pattern}]
d7ddb257
LC
1591When @var{pattern} is omitted, delete all generations except the current
1592one.
b7884ca3
NK
1593
1594This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
1595When @var{pattern} is specified, delete the matching generations. When
1596@var{pattern} specifies a duration, generations @emph{older} than the
1597specified duration match. For instance, @code{--delete-generations=1m}
1598deletes generations that are more than one month old.
1599
391bdd8f
LC
1600If the current generation matches, it is @emph{not} deleted. Also, the
1601zeroth generation is never deleted.
b7884ca3 1602
1bb9900a
LC
1603Note that deleting generations prevents roll-back to them.
1604Consequently, this command must be used with care.
1605
733b4130 1606@end table
eeaf4427 1607
70ee5642
LC
1608Finally, since @command{guix package} may actually start build
1609processes, it supports all the common build options that @command{guix
1610build} supports (@pxref{Invoking guix build, common build options}).
1611
c4202d60
LC
1612@node Substitutes
1613@section Substitutes
1614
1615@cindex substitutes
1616@cindex pre-built binaries
1617Guix supports transparent source/binary deployment, which means that it
1618can either build things locally, or download pre-built items from a
1619server. We call these pre-built items @dfn{substitutes}---they are
1620substitutes for local build results. In many cases, downloading a
1621substitute is much faster than building things locally.
1622
1623Substitutes can be anything resulting from a derivation build
1624(@pxref{Derivations}). Of course, in the common case, they are
1625pre-built package binaries, but source tarballs, for instance, which
1626also result from derivation builds, can be available as substitutes.
1627
1628The @code{hydra.gnu.org} server is a front-end to a build farm that
1629builds packages from the GNU distribution continuously for some
32950fc8
AK
1630architectures, and makes them available as substitutes (@pxref{Emacs
1631Hydra}, for information on how to query the continuous integration
1632server). This is the
f8a8e0fe
LC
1633default source of substitutes; it can be overridden by passing the
1634@option{--substitute-urls} option either to @command{guix-daemon}
1635(@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1636or to client tools such as @command{guix package}
1637(@pxref{client-substitute-urls,, client @option{--substitute-urls}
1638option}).
c4202d60
LC
1639
1640@cindex security
1641@cindex digital signatures
1642To allow Guix to download substitutes from @code{hydra.gnu.org}, you
1643must add its public key to the access control list (ACL) of archive
1644imports, using the @command{guix archive} command (@pxref{Invoking guix
1645archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1646be compromised and to serve genuine substitutes.
1647
1648This public key is installed along with Guix, in
1649@code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1650the installation prefix of Guix. If you installed Guix from source,
1651make sure you checked the GPG signature of
1652@file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1653Then, you can run something like this:
1654
1655@example
1656# guix archive --authorize < hydra.gnu.org.pub
1657@end example
1658
1659Once this is in place, the output of a command like @code{guix build}
1660should change from something like:
1661
1662@example
1663$ guix build emacs --dry-run
1664The following derivations would be built:
1665 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1666 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1667 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1668 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1669@dots{}
1670@end example
1671
1672@noindent
1673to something like:
1674
1675@example
1676$ guix build emacs --dry-run
1677The following files would be downloaded:
1678 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1679 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1680 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1681 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1682@dots{}
1683@end example
1684
1685@noindent
1686This indicates that substitutes from @code{hydra.gnu.org} are usable and
1687will be downloaded, when possible, for future builds.
1688
1689Guix ignores substitutes that are not signed, or that are not signed by
ef27aa9c 1690one of the keys listed in the ACL. It also detects and raises an error
c4202d60
LC
1691when attempting to use a substitute that has been tampered with.
1692
e0c941fe
LC
1693@vindex http_proxy
1694Substitutes are downloaded over HTTP. The @code{http_proxy} environment
1695variable can be set in the environment of @command{guix-daemon} and is
1696honored for downloads of substitutes. Note that the value of
1697@code{http_proxy} in the environment where @command{guix build},
1698@command{guix package}, and other client commands are run has
1699@emph{absolutely no effect}.
1700
c4202d60
LC
1701The substitute mechanism can be disabled globally by running
1702@code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1703guix-daemon}). It can also be disabled temporarily by passing the
1704@code{--no-substitutes} option to @command{guix package}, @command{guix
1705build}, and other command-line tools.
1706
1707
1708Today, each individual's control over their own computing is at the
1709mercy of institutions, corporations, and groups with enough power and
1710determination to subvert the computing infrastructure and exploit its
1711weaknesses. While using @code{hydra.gnu.org} substitutes can be
1712convenient, we encourage users to also build on their own, or even run
1713their own build farm, such that @code{hydra.gnu.org} is less of an
8ce229fc
LC
1714interesting target. One way to help is by publishing the software you
1715build using @command{guix publish} so that others have one more choice
1716of server to download substitutes from (@pxref{Invoking guix publish}).
c4202d60
LC
1717
1718Guix has the foundations to maximize build reproducibility
1719(@pxref{Features}). In most cases, independent builds of a given
1720package or derivation should yield bit-identical results. Thus, through
1721a diverse set of independent package builds, we can strengthen the
d23c20f1
LC
1722integrity of our systems. The @command{guix challenge} command aims to
1723help users assess substitute servers, and to assist developers in
1724finding out about non-deterministic package builds (@pxref{Invoking guix
a8d65643
LC
1725challenge}). Similarly, the @option{--check} option of @command{guix
1726build} allows users to check whether previously-installed substitutes
1727are genuine by rebuilding them locally (@pxref{build-check,
1728@command{guix build --check}}).
c4202d60
LC
1729
1730In the future, we want Guix to have support to publish and retrieve
1731binaries to/from other users, in a peer-to-peer fashion. If you would
1732like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1733
1734
6e721c4d
LC
1735@node Packages with Multiple Outputs
1736@section Packages with Multiple Outputs
1737
1738@cindex multiple-output packages
1739@cindex package outputs
1740
1741Often, packages defined in Guix have a single @dfn{output}---i.e., the
1742source package leads exactly one directory in the store. When running
1743@command{guix package -i glibc}, one installs the default output of the
1744GNU libc package; the default output is called @code{out}, but its name
1745can be omitted as shown in this command. In this particular case, the
1746default output of @code{glibc} contains all the C header files, shared
1747libraries, static libraries, Info documentation, and other supporting
1748files.
1749
1750Sometimes it is more appropriate to separate the various types of files
1751produced from a single source package into separate outputs. For
1752instance, the GLib C library (used by GTK+ and related packages)
1753installs more than 20 MiB of reference documentation as HTML pages.
1754To save space for users who do not need it, the documentation goes to a
1755separate output, called @code{doc}. To install the main GLib output,
1756which contains everything but the documentation, one would run:
1757
1758@example
1759guix package -i glib
1760@end example
1761
1762The command to install its documentation is:
1763
1764@example
1765guix package -i glib:doc
1766@end example
1767
1768Some packages install programs with different ``dependency footprints''.
1769For instance, the WordNet package install both command-line tools and
1770graphical user interfaces (GUIs). The former depend solely on the C
1771library, whereas the latter depend on Tcl/Tk and the underlying X
1772libraries. In this case, we leave the command-line tools in the default
1773output, whereas the GUIs are in a separate output. This allows users
fcc58db6
LC
1774who do not need the GUIs to save space. The @command{guix size} command
1775can help find out about such situations (@pxref{Invoking guix size}).
88856916 1776@command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
6e721c4d
LC
1777
1778There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
1779Other conventional output names include @code{lib} for libraries and
1780possibly header files, @code{bin} for stand-alone programs, and
1781@code{debug} for debugging information (@pxref{Installing Debugging
1782Files}). The outputs of a packages are listed in the third column of
1783the output of @command{guix package --list-available} (@pxref{Invoking
1784guix package}).
6e721c4d 1785
eeaf4427 1786
e49951eb
MW
1787@node Invoking guix gc
1788@section Invoking @command{guix gc}
fe8ff028
LC
1789
1790@cindex garbage collector
1791Packages that are installed but not used may be @dfn{garbage-collected}.
e49951eb 1792The @command{guix gc} command allows users to explicitly run the garbage
c22eb992
LC
1793collector to reclaim space from the @file{/gnu/store} directory. It is
1794the @emph{only} way to remove files from @file{/gnu/store}---removing
1795files or directories manually may break it beyond repair!
fe8ff028
LC
1796
1797The garbage collector has a set of known @dfn{roots}: any file under
834129e0 1798@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
1799cannot be deleted; any other file is considered @dfn{dead} and may be
1800deleted. The set of garbage collector roots includes default user
e49951eb
MW
1801profiles, and may be augmented with @command{guix build --root}, for
1802example (@pxref{Invoking guix build}).
fe8ff028 1803
1bb9900a
LC
1804Prior to running @code{guix gc --collect-garbage} to make space, it is
1805often useful to remove old generations from user profiles; that way, old
1806package builds referenced by those generations can be reclaimed. This
1807is achieved by running @code{guix package --delete-generations}
1808(@pxref{Invoking guix package}).
1809
e49951eb 1810The @command{guix gc} command has three modes of operation: it can be
fe8ff028 1811used to garbage-collect any dead files (the default), to delete specific
7770aafc
LC
1812files (the @code{--delete} option), to print garbage-collector
1813information, or for more advanced queries. The garbage collection
1814options are as follows:
fe8ff028
LC
1815
1816@table @code
1817@item --collect-garbage[=@var{min}]
1818@itemx -C [@var{min}]
834129e0 1819Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
1820sub-directories. This is the default operation when no option is
1821specified.
1822
1823When @var{min} is given, stop once @var{min} bytes have been collected.
1824@var{min} may be a number of bytes, or it may include a unit as a
4a44d7bb
LC
1825suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
1826(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
fe8ff028
LC
1827
1828When @var{min} is omitted, collect all the garbage.
1829
1830@item --delete
1831@itemx -d
1832Attempt to delete all the store files and directories specified as
1833arguments. This fails if some of the files are not in the store, or if
1834they are still live.
1835
30d9aa54
LC
1836@item --list-failures
1837List store items corresponding to cached build failures.
1838
1839This prints nothing unless the daemon was started with
1840@option{--cache-failures} (@pxref{Invoking guix-daemon,
1841@option{--cache-failures}}).
1842
1843@item --clear-failures
1844Remove the specified store items from the failed-build cache.
1845
1846Again, this option only makes sense when the daemon is started with
1847@option{--cache-failures}. Otherwise, it does nothing.
1848
fe8ff028
LC
1849@item --list-dead
1850Show the list of dead files and directories still present in the
1851store---i.e., files and directories no longer reachable from any root.
1852
1853@item --list-live
1854Show the list of live store files and directories.
ba8b732d
LC
1855
1856@end table
1857
1858In addition, the references among existing store files can be queried:
1859
1860@table @code
1861
1862@item --references
1863@itemx --referrers
1864List the references (respectively, the referrers) of store files given
1865as arguments.
1866
8e59fdd5
LC
1867@item --requisites
1868@itemx -R
fcc58db6 1869@cindex closure
8e59fdd5
LC
1870List the requisites of the store files passed as arguments. Requisites
1871include the store files themselves, their references, and the references
1872of these, recursively. In other words, the returned list is the
1873@dfn{transitive closure} of the store files.
1874
fcc58db6 1875@xref{Invoking guix size}, for a tool to profile the size of an
88856916
LC
1876element's closure. @xref{Invoking guix graph}, for a tool to visualize
1877the graph of references.
fcc58db6 1878
fe8ff028
LC
1879@end table
1880
7770aafc
LC
1881Lastly, the following options allow you to check the integrity of the
1882store and to control disk usage.
1883
1884@table @option
1885
1886@item --verify[=@var{options}]
1887@cindex integrity, of the store
1888@cindex integrity checking
1889Verify the integrity of the store.
1890
1891By default, make sure that all the store items marked as valid in the
1892daemon's database actually exist in @file{/gnu/store}.
1893
1894When provided, @var{options} must a comma-separated list containing one
1895or more of @code{contents} and @code{repair}.
1896
1897When passing @option{--verify=contents}, the daemon will compute the
1898content hash of each store item and compare it against its hash in the
1899database. Hash mismatches are reported as data corruptions. Because it
1900traverses @emph{all the files in the store}, this command can take a
1901long time, especially on systems with a slow disk drive.
1902
1903@cindex repairing the store
1904Using @option{--verify=repair} or @option{--verify=contents,repair}
1905causes the daemon to try to repair corrupt store items by fetching
1906substitutes for them (@pxref{Substitutes}). Because repairing is not
1907atomic, and thus potentially dangerous, it is available only to the
1908system administrator.
1909
1910@item --optimize
1911@cindex deduplication
1912Optimize the store by hard-linking identical files---this is
1913@dfn{deduplication}.
1914
1915The daemon performs deduplication after each successful build or archive
1916import, unless it was started with @code{--disable-deduplication}
1917(@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
1918this option is primarily useful when the daemon was running with
1919@code{--disable-deduplication}.
1920
1921@end table
eeaf4427 1922
f651b477
LC
1923@node Invoking guix pull
1924@section Invoking @command{guix pull}
1925
1926Packages are installed or upgraded to the latest version available in
1927the distribution currently available on your local machine. To update
1928that distribution, along with the Guix tools, you must run @command{guix
1929pull}: the command downloads the latest Guix source code and package
1930descriptions, and deploys it.
1931
1932On completion, @command{guix package} will use packages and package
1933versions from this just-retrieved copy of Guix. Not only that, but all
1934the Guix commands and Scheme modules will also be taken from that latest
1935version. New @command{guix} sub-commands added by the update also
ef54b61d
AV
1936become available@footnote{Under the hood, @command{guix pull} updates
1937the @file{~/.config/guix/latest} symbolic link to point to the latest
1938Guix, and the @command{guix} command loads code from there.}.
f651b477
LC
1939
1940The @command{guix pull} command is usually invoked with no arguments,
1941but it supports the following options:
1942
1943@table @code
1944@item --verbose
1945Produce verbose output, writing build logs to the standard error output.
1946
ab5d72ad
LC
1947@item --url=@var{url}
1948Download the source tarball of Guix from @var{url}.
1949
1950By default, the tarball is taken from its canonical address at
1951@code{gnu.org}, for the stable branch of Guix.
1952
f651b477
LC
1953@item --bootstrap
1954Use the bootstrap Guile to build the latest Guix. This option is only
1955useful to Guix developers.
1956@end table
1957
760c60d6
LC
1958
1959@node Invoking guix archive
1960@section Invoking @command{guix archive}
1961
1962The @command{guix archive} command allows users to @dfn{export} files
1963from the store into a single archive, and to later @dfn{import} them.
1964In particular, it allows store files to be transferred from one machine
1965to another machine's store. For example, to transfer the @code{emacs}
1966package to a machine connected over SSH, one would run:
1967
1968@example
56607088 1969guix archive --export -r emacs | ssh the-machine guix archive --import
760c60d6
LC
1970@end example
1971
87236aed 1972@noindent
56607088
LC
1973Similarly, a complete user profile may be transferred from one machine
1974to another like this:
1975
1976@example
1977guix archive --export -r $(readlink -f ~/.guix-profile) | \
1978 ssh the-machine guix-archive --import
1979@end example
1980
1981@noindent
1982However, note that, in both examples, all of @code{emacs} and the
1983profile as well as all of their dependencies are transferred (due to
1984@code{-r}), regardless of what is already available in the target
1985machine's store. The @code{--missing} option can help figure out which
1986items are missing from the target's store.
87236aed 1987
760c60d6 1988Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
0dbd88db
LC
1989comparable in spirit to `tar', but with a few noteworthy differences
1990that make it more appropriate for our purposes. First, rather than
1991recording all Unix meta-data for each file, the Nar format only mentions
1992the file type (regular, directory, or symbolic link); Unix permissions
1993and owner/group are dismissed. Second, the order in which directory
1994entries are stored always follows the order of file names according to
1995the C locale collation order. This makes archive production fully
1996deterministic.
1997
1998When exporting, the daemon digitally signs the contents of the archive,
1999and that digital signature is appended. When importing, the daemon
2000verifies the signature and rejects the import in case of an invalid
2001signature or if the signing key is not authorized.
760c60d6
LC
2002@c FIXME: Add xref to daemon doc about signatures.
2003
2004The main options are:
2005
2006@table @code
2007@item --export
2008Export the specified store files or packages (see below.) Write the
2009resulting archive to the standard output.
2010
56607088
LC
2011Dependencies are @emph{not} included in the output, unless
2012@code{--recursive} is passed.
2013
2014@item -r
2015@itemx --recursive
2016When combined with @code{--export}, this instructs @command{guix
2017archive} to include dependencies of the given items in the archive.
2018Thus, the resulting archive is self-contained: it contains the closure
2019of the exported store items.
2020
760c60d6
LC
2021@item --import
2022Read an archive from the standard input, and import the files listed
2023therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
2024signature, or if it is signed by a public key not among the authorized
2025keys (see @code{--authorize} below.)
554f26ec 2026
87236aed
LC
2027@item --missing
2028Read a list of store file names from the standard input, one per line,
2029and write on the standard output the subset of these files missing from
2030the store.
2031
554f26ec 2032@item --generate-key[=@var{parameters}]
f82cc5fd 2033@cindex signing, archives
554f26ec
LC
2034Generate a new key pair for the daemons. This is a prerequisite before
2035archives can be exported with @code{--export}. Note that this operation
2036usually takes time, because it needs to gather enough entropy to
2037generate the key pair.
2038
2039The generated key pair is typically stored under @file{/etc/guix}, in
2040@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
867d8473
LC
2041key, which must be kept secret.) When @var{parameters} is omitted,
2042an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2043versions before 1.6.0, it is a 4096-bit RSA key.
2044Alternately, @var{parameters} can specify
554f26ec
LC
2045@code{genkey} parameters suitable for Libgcrypt (@pxref{General
2046public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2047Libgcrypt Reference Manual}).
f82cc5fd
LC
2048
2049@item --authorize
2050@cindex authorizing, archives
2051Authorize imports signed by the public key passed on standard input.
2052The public key must be in ``s-expression advanced format''---i.e., the
2053same format as the @file{signing-key.pub} file.
2054
2055The list of authorized keys is kept in the human-editable file
2056@file{/etc/guix/acl}. The file contains
2057@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2058s-expressions''} and is structured as an access-control list in the
2059@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2060(SPKI)}.
c6f8e9dd
LC
2061
2062@item --extract=@var{directory}
2063@itemx -x @var{directory}
2064Read a single-item archive as served by substitute servers
2065(@pxref{Substitutes}) and extract it to @var{directory}. This is a
2066low-level operation needed in only very narrow use cases; see below.
2067
2068For example, the following command extracts the substitute for Emacs
2069served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2070
2071@example
2072$ wget -O - \
2073 http://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
2074 | bunzip2 | guix archive -x /tmp/emacs
2075@end example
2076
2077Single-item archives are different from multiple-item archives produced
2078by @command{guix archive --export}; they contain a single store item,
2079and they do @emph{not} embed a signature. Thus this operation does
2080@emph{no} signature verification and its output should be considered
2081unsafe.
2082
2083The primary purpose of this operation is to facilitate inspection of
2084archive contents coming from possibly untrusted substitute servers.
2085
760c60d6
LC
2086@end table
2087
2088To export store files as an archive to the standard output, run:
2089
2090@example
2091guix archive --export @var{options} @var{specifications}...
2092@end example
2093
2094@var{specifications} may be either store file names or package
2095specifications, as for @command{guix package} (@pxref{Invoking guix
2096package}). For instance, the following command creates an archive
2097containing the @code{gui} output of the @code{git} package and the main
2098output of @code{emacs}:
2099
2100@example
834129e0 2101guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
760c60d6
LC
2102@end example
2103
2104If the specified packages are not built yet, @command{guix archive}
2105automatically builds them. The build process may be controlled with the
2106same options that can be passed to the @command{guix build} command
70ee5642 2107(@pxref{Invoking guix build, common build options}).
760c60d6 2108
c554de89
AK
2109@c *********************************************************************
2110@include emacs.texi
760c60d6 2111
568717fd
LC
2112@c *********************************************************************
2113@node Programming Interface
2114@chapter Programming Interface
2115
3dc1970d
LC
2116GNU Guix provides several Scheme programming interfaces (APIs) to
2117define, build, and query packages. The first interface allows users to
2118write high-level package definitions. These definitions refer to
2119familiar packaging concepts, such as the name and version of a package,
2120its build system, and its dependencies. These definitions can then be
2121turned into concrete build actions.
2122
ba55b1cb 2123Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 2124standard setup, the daemon has write access to the store---the
834129e0 2125@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
2126setup also has the daemon perform builds in chroots, under a specific
2127build users, to minimize interference with the rest of the system.
2128
2129@cindex derivation
2130Lower-level APIs are available to interact with the daemon and the
2131store. To instruct the daemon to perform a build action, users actually
2132provide it with a @dfn{derivation}. A derivation is a low-level
2133representation of the build actions to be taken, and the environment in
2134which they should occur---derivations are to package definitions what
49ad317a
LC
2135assembly is to C programs. The term ``derivation'' comes from the fact
2136that build results @emph{derive} from them.
3dc1970d
LC
2137
2138This chapter describes all these APIs in turn, starting from high-level
2139package definitions.
2140
568717fd 2141@menu
b860f382 2142* Defining Packages:: Defining new packages.
7458bd0a 2143* Build Systems:: Specifying how packages are built.
b860f382
LC
2144* The Store:: Manipulating the package store.
2145* Derivations:: Low-level interface to package derivations.
2146* The Store Monad:: Purely functional interface to the store.
21b679f6 2147* G-Expressions:: Manipulating build expressions.
568717fd
LC
2148@end menu
2149
2150@node Defining Packages
2151@section Defining Packages
2152
3dc1970d
LC
2153The high-level interface to package definitions is implemented in the
2154@code{(guix packages)} and @code{(guix build-system)} modules. As an
2155example, the package definition, or @dfn{recipe}, for the GNU Hello
2156package looks like this:
2157
2158@example
e7f34eb0
LC
2159(define-module (gnu packages hello)
2160 #:use-module (guix packages)
2161 #:use-module (guix download)
2162 #:use-module (guix build-system gnu)
a6dcdcac
SB
2163 #:use-module (guix licenses)
2164 #:use-module (gnu packages gawk))
b22a12fd 2165
79f5dd59 2166(define-public hello
3dc1970d
LC
2167 (package
2168 (name "hello")
17d8e33f 2169 (version "2.10")
3dc1970d 2170 (source (origin
17d8e33f
ML
2171 (method url-fetch)
2172 (uri (string-append "mirror://gnu/hello/hello-" version
2173 ".tar.gz"))
2174 (sha256
2175 (base32
2176 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
3dc1970d 2177 (build-system gnu-build-system)
7458bd0a 2178 (arguments `(#:configure-flags '("--enable-silent-rules")))
3dc1970d 2179 (inputs `(("gawk" ,gawk)))
7458bd0a
LC
2180 (synopsis "Hello, GNU world: An example GNU package")
2181 (description "Guess what GNU Hello prints!")
3dc1970d 2182 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 2183 (license gpl3+)))
3dc1970d
LC
2184@end example
2185
2186@noindent
2187Without being a Scheme expert, the reader may have guessed the meaning
e7f34eb0 2188of the various fields here. This expression binds variable @code{hello}
3dc1970d
LC
2189to a @code{<package>} object, which is essentially a record
2190(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2191This package object can be inspected using procedures found in the
2192@code{(guix packages)} module; for instance, @code{(package-name hello)}
2193returns---surprise!---@code{"hello"}.
2194
2f7d2d91
LC
2195With luck, you may be able to import part or all of the definition of
2196the package you are interested in from another repository, using the
2197@code{guix import} command (@pxref{Invoking guix import}).
2198
e7f34eb0
LC
2199In the example above, @var{hello} is defined into a module of its own,
2200@code{(gnu packages hello)}. Technically, this is not strictly
2201necessary, but it is convenient to do so: all the packages defined in
2202modules under @code{(gnu packages @dots{})} are automatically known to
2203the command-line tools (@pxref{Package Modules}).
2204
3dc1970d
LC
2205There are a few points worth noting in the above package definition:
2206
2207@itemize
2208@item
a2bf4907
LC
2209The @code{source} field of the package is an @code{<origin>} object
2210(@pxref{origin Reference}, for the complete reference).
3dc1970d
LC
2211Here, the @code{url-fetch} method from @code{(guix download)} is used,
2212meaning that the source is a file to be downloaded over FTP or HTTP.
2213
2214The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2215the GNU mirrors defined in @code{(guix download)}.
2216
2217The @code{sha256} field specifies the expected SHA256 hash of the file
2218being downloaded. It is mandatory, and allows Guix to check the
2219integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 2220base32 representation of the hash. You can obtain this information with
210cc920
LC
2221@code{guix download} (@pxref{Invoking guix download}) and @code{guix
2222hash} (@pxref{Invoking guix hash}).
3dc1970d 2223
f9cc8971
LC
2224@cindex patches
2225When needed, the @code{origin} form can also have a @code{patches} field
2226listing patches to be applied, and a @code{snippet} field giving a
2227Scheme expression to modify the source code.
2228
3dc1970d
LC
2229@item
2230@cindex GNU Build System
7458bd0a
LC
2231The @code{build-system} field specifies the procedure to build the
2232package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2233represents the familiar GNU Build System, where packages may be
2234configured, built, and installed with the usual @code{./configure &&
2235make && make check && make install} command sequence.
2236
2237@item
2238The @code{arguments} field specifies options for the build system
2239(@pxref{Build Systems}). Here it is interpreted by
2240@var{gnu-build-system} as a request run @file{configure} with the
2241@code{--enable-silent-rules} flag.
3dc1970d
LC
2242
2243@item
2244The @code{inputs} field specifies inputs to the build process---i.e.,
2245build-time or run-time dependencies of the package. Here, we define an
2246input called @code{"gawk"} whose value is that of the @var{gawk}
2247variable; @var{gawk} is itself bound to a @code{<package>} object.
2248
2249Note that GCC, Coreutils, Bash, and other essential tools do not need to
2250be specified as inputs here. Instead, @var{gnu-build-system} takes care
7458bd0a 2251of ensuring that they are present (@pxref{Build Systems}).
3dc1970d
LC
2252
2253However, any other dependencies need to be specified in the
2254@code{inputs} field. Any dependency not specified here will simply be
2255unavailable to the build process, possibly leading to a build failure.
2256@end itemize
2257
87eafdbd
TUBK
2258@xref{package Reference}, for a full description of possible fields.
2259
2f7d2d91 2260Once a package definition is in place, the
e49951eb 2261package may actually be built using the @code{guix build} command-line
39bee8a2
LC
2262tool (@pxref{Invoking guix build}). You can easily jump back to the
2263package definition using the @command{guix edit} command
2264(@pxref{Invoking guix edit}).
2265@xref{Packaging Guidelines}, for
b4f5e0e8
CR
2266more information on how to test package definitions, and
2267@ref{Invoking guix lint}, for information on how to check a definition
2268for style conformance.
2269
7458bd0a
LC
2270Eventually, updating the package definition to a new upstream version
2271can be partly automated by the @command{guix refresh} command
2272(@pxref{Invoking guix refresh}).
3dc1970d
LC
2273
2274Behind the scenes, a derivation corresponding to the @code{<package>}
2275object is first computed by the @code{package-derivation} procedure.
834129e0 2276That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 2277The build actions it prescribes may then be realized by using the
3dc1970d
LC
2278@code{build-derivations} procedure (@pxref{The Store}).
2279
2280@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
2281Return the @code{<derivation>} object of @var{package} for @var{system}
2282(@pxref{Derivations}).
3dc1970d
LC
2283
2284@var{package} must be a valid @code{<package>} object, and @var{system}
2285must be a string denoting the target system type---e.g.,
2286@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2287must be a connection to the daemon, which operates on the store
2288(@pxref{The Store}).
2289@end deffn
568717fd 2290
9c1edabd
LC
2291@noindent
2292@cindex cross-compilation
2293Similarly, it is possible to compute a derivation that cross-builds a
2294package for some other system:
2295
2296@deffn {Scheme Procedure} package-cross-derivation @var{store} @
2297 @var{package} @var{target} [@var{system}]
59688fc4
LC
2298Return the @code{<derivation>} object of @var{package} cross-built from
2299@var{system} to @var{target}.
9c1edabd
LC
2300
2301@var{target} must be a valid GNU triplet denoting the target hardware
2302and operating system, such as @code{"mips64el-linux-gnu"}
2303(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2304Configure and Build System}).
2305@end deffn
2306
87eafdbd
TUBK
2307@menu
2308* package Reference :: The package data type.
2309* origin Reference:: The origin data type.
2310@end menu
2311
2312
2313@node package Reference
2314@subsection @code{package} Reference
2315
2316This section summarizes all the options available in @code{package}
2317declarations (@pxref{Defining Packages}).
2318
2319@deftp {Data Type} package
2320This is the data type representing a package recipe.
2321
2322@table @asis
2323@item @code{name}
2324The name of the package, as a string.
2325
2326@item @code{version}
2327The version of the package, as a string.
2328
2329@item @code{source}
2330An origin object telling how the source code for the package should be
2331acquired (@pxref{origin Reference}).
2332
2333@item @code{build-system}
2334The build system that should be used to build the package (@pxref{Build
2335Systems}).
2336
2337@item @code{arguments} (default: @code{'()})
2338The arguments that should be passed to the build system. This is a
2339list, typically containing sequential keyword-value pairs.
2340
2341@item @code{inputs} (default: @code{'()})
70650c68
LC
2342@itemx @code{native-inputs} (default: @code{'()})
2343@itemx @code{propagated-inputs} (default: @code{'()})
2344@cindex inputs, of packages
2345These fields list dependencies of the package. Each one is a list of
2346tuples, where each tuple has a label for the input (a string) as its
2347first element, a package, origin, or derivation as its second element,
2348and optionally the name of the output thereof that should be used, which
2349defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
2350more on package outputs). For example, the list below specifies 3
2351inputs:
87eafdbd 2352
70650c68
LC
2353@example
2354`(("libffi" ,libffi)
2355 ("libunistring" ,libunistring)
2356 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
2357@end example
2358
2359@cindex cross compilation, package dependencies
2360The distinction between @code{native-inputs} and @code{inputs} is
2361necessary when considering cross-compilation. When cross-compiling,
2362dependencies listed in @code{inputs} are built for the @emph{target}
2363architecture; conversely, dependencies listed in @code{native-inputs}
2364are built for the architecture of the @emph{build} machine.
2365
2366@code{native-inputs} is typically where you would list tools needed at
2367build time but not at run time, such as Autoconf, Automake, pkg-config,
2368Gettext, or Bison. @command{guix lint} can report likely mistakes in
2369this area (@pxref{Invoking guix lint}).
2370
2371@anchor{package-propagated-inputs}
2372Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
2373specified packages will be force-installed alongside the package they
2374belong to (@pxref{package-cmd-propagated-inputs, @command{guix
2375package}}, for information on how @command{guix package} deals with
2376propagated inputs.)
21461f27 2377
e0508b6b
LC
2378For example this is necessary when a C/C++ library needs headers of
2379another library to compile, or when a pkg-config file refers to another
2380one @i{via} its @code{Requires} field.
2381
2382Another example where @code{propagated-inputs} is useful is for
2383languages that lack a facility to record the run-time search path akin
2384to ELF's @code{RUNPATH}; this includes Guile, Python, Perl, GHC, and
2385more. To ensure that libraries written in those languages can find
2386library code they depend on at run time, run-time dependencies must be
2387listed in @code{propagated-inputs} rather than @code{inputs}.
87eafdbd 2388
87eafdbd
TUBK
2389@item @code{self-native-input?} (default: @code{#f})
2390This is a Boolean field telling whether the package should use itself as
2391a native input when cross-compiling.
2392
2393@item @code{outputs} (default: @code{'("out")})
2394The list of output names of the package. @xref{Packages with Multiple
2395Outputs}, for typical uses of additional outputs.
2396
2397@item @code{native-search-paths} (default: @code{'()})
2398@itemx @code{search-paths} (default: @code{'()})
2399A list of @code{search-path-specification} objects describing
2400search-path environment variables honored by the package.
2401
2402@item @code{replacement} (default: @code{#f})
2403This must either @code{#f} or a package object that will be used as a
2404@dfn{replacement} for this package. @xref{Security Updates, grafts},
2405for details.
2406
2407@item @code{synopsis}
2408A one-line description of the package.
2409
2410@item @code{description}
2411A more elaborate description of the package.
2412
2413@item @code{license}
2414The license of the package; a value from @code{(guix licenses)}.
2415
2416@item @code{home-page}
2417The URL to the home-page of the package, as a string.
2418
2419@item @code{supported-systems} (default: @var{%supported-systems})
2420The list of systems supported by the package, as strings of the form
2421@code{architecture-kernel}, for example @code{"x86_64-linux"}.
2422
2423@item @code{maintainers} (default: @code{'()})
2424The list of maintainers of the package, as @code{maintainer} objects.
2425
2426@item @code{location} (default: source location of the @code{package} form)
2427The source location of the package. It's useful to override this when
2428inheriting from another package, in which case this field is not
2429automatically corrected.
2430@end table
2431@end deftp
2432
2433
2434@node origin Reference
2435@subsection @code{origin} Reference
2436
2437This section summarizes all the options available in @code{origin}
2438declarations (@pxref{Defining Packages}).
2439
2440@deftp {Data Type} origin
2441This is the data type representing a source code origin.
2442
2443@table @asis
2444@item @code{uri}
2445An object containing the URI of the source. The object type depends on
2446the @code{method} (see below). For example, when using the
2447@var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2448values are: a URL represented as a string, or a list thereof.
2449
2450@item @code{method}
2451A procedure that will handle the URI.
2452
2453Examples include:
2454
2455@table @asis
2456@item @var{url-fetch} from @code{(guix download)}
2457download a file the HTTP, HTTPS, or FTP URL specified in the
2458@code{uri} field;
2459
2460@item @var{git-fetch} from @code{(guix git-download)}
2461clone the Git version control repository, and check out the revision
2462specified in the @code{uri} field as a @code{git-reference} object; a
2463@code{git-reference} looks like this:
2464
2465@example
2466(git-reference
2467 (url "git://git.debian.org/git/pkg-shadow/shadow")
2468 (commit "v4.1.5.1"))
2469@end example
2470@end table
2471
2472@item @code{sha256}
2473A bytevector containing the SHA-256 hash of the source. Typically the
2474@code{base32} form is used here to generate the bytevector from a
2475base-32 string.
2476
2477@item @code{file-name} (default: @code{#f})
2478The file name under which the source code should be saved. When this is
2479@code{#f}, a sensible default value will be used in most cases. In case
2480the source is fetched from a URL, the file name from the URL will be
2481used. For version control checkouts, it's recommended to provide the
2482file name explicitly because the default is not very descriptive.
2483
2484@item @code{patches} (default: @code{'()})
2485A list of file names containing patches to be applied to the source.
2486
2487@item @code{snippet} (default: @code{#f})
2488A quoted piece of code that will be run in the source directory to make
2489any modifications, which is sometimes more convenient than a patch.
2490
2491@item @code{patch-flags} (default: @code{'("-p1")})
2492A list of command-line flags that should be passed to the @code{patch}
2493command.
2494
2495@item @code{patch-inputs} (default: @code{#f})
2496Input packages or derivations to the patching process. When this is
2497@code{#f}, the usual set of inputs necessary for patching are provided,
2498such as GNU@tie{}Patch.
2499
2500@item @code{modules} (default: @code{'()})
2501A list of Guile modules that should be loaded during the patching
2502process and while running the code in the @code{snippet} field.
2503
2504@item @code{imported-modules} (default: @code{'()})
2505The list of Guile modules to import in the patch derivation, for use by
2506the @code{snippet}.
2507
2508@item @code{patch-guile} (default: @code{#f})
2509The Guile package that should be used in the patching process. When
2510this is @code{#f}, a sensible default is used.
2511@end table
2512@end deftp
2513
9c1edabd 2514
7458bd0a
LC
2515@node Build Systems
2516@section Build Systems
2517
2518@cindex build system
2519Each package definition specifies a @dfn{build system} and arguments for
2520that build system (@pxref{Defining Packages}). This @code{build-system}
2521field represents the build procedure of the package, as well implicit
2522dependencies of that build procedure.
2523
2524Build systems are @code{<build-system>} objects. The interface to
2525create and manipulate them is provided by the @code{(guix build-system)}
2526module, and actual build systems are exported by specific modules.
2527
f5fd4fd2 2528@cindex bag (low-level package representation)
0d5a559f
LC
2529Under the hood, build systems first compile package objects to
2530@dfn{bags}. A @dfn{bag} is like a package, but with less
2531ornamentation---in other words, a bag is a lower-level representation of
2532a package, which includes all the inputs of that package, including some
2533that were implicitly added by the build system. This intermediate
2534representation is then compiled to a derivation (@pxref{Derivations}).
2535
7458bd0a
LC
2536Build systems accept an optional list of @dfn{arguments}. In package
2537definitions, these are passed @i{via} the @code{arguments} field
2538(@pxref{Defining Packages}). They are typically keyword arguments
2539(@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
2540Guile Reference Manual}). The value of these arguments is usually
2541evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
2542by the daemon (@pxref{Derivations}).
2543
2544The main build system is @var{gnu-build-system}, which implements the
2545standard build procedure for GNU packages and many other packages. It
2546is provided by the @code{(guix build-system gnu)} module.
2547
2548@defvr {Scheme Variable} gnu-build-system
2549@var{gnu-build-system} represents the GNU Build System, and variants
2550thereof (@pxref{Configuration, configuration and makefile conventions,,
2551standards, GNU Coding Standards}).
2552
2553@cindex build phases
2554In a nutshell, packages using it configured, built, and installed with
2555the usual @code{./configure && make && make check && make install}
2556command sequence. In practice, a few additional steps are often needed.
2557All these steps are split up in separate @dfn{phases},
2558notably@footnote{Please see the @code{(guix build gnu-build-system)}
2559modules for more details about the build phases.}:
2560
2561@table @code
2562@item unpack
2563Unpack the source tarball, and change the current directory to the
2564extracted source tree. If the source is actually a directory, copy it
2565to the build tree, and enter that directory.
2566
2567@item patch-source-shebangs
2568Patch shebangs encountered in source files so they refer to the right
2569store file names. For instance, this changes @code{#!/bin/sh} to
2570@code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
2571
2572@item configure
2573Run the @file{configure} script with a number of default options, such
2574as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
2575by the @code{#:configure-flags} argument.
2576
2577@item build
2578Run @code{make} with the list of flags specified with
0917e80e 2579@code{#:make-flags}. If the @code{#:parallel-build?} argument is true
7458bd0a
LC
2580(the default), build with @code{make -j}.
2581
2582@item check
2583Run @code{make check}, or some other target specified with
2584@code{#:test-target}, unless @code{#:tests? #f} is passed. If the
2585@code{#:parallel-tests?} argument is true (the default), run @code{make
2586check -j}.
2587
2588@item install
2589Run @code{make install} with the flags listed in @code{#:make-flags}.
2590
2591@item patch-shebangs
2592Patch shebangs on the installed executable files.
2593
2594@item strip
2595Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
2596is false), copying them to the @code{debug} output when available
2597(@pxref{Installing Debugging Files}).
2598@end table
2599
2600@vindex %standard-phases
2601The build-side module @code{(guix build gnu-build-system)} defines
2602@var{%standard-phases} as the default list of build phases.
2603@var{%standard-phases} is a list of symbol/procedure pairs, where the
2604procedure implements the actual phase.
2605
2606The list of phases used for a particular package can be changed with the
2607@code{#:phases} parameter. For instance, passing:
2608
2609@example
2610#:phases (alist-delete 'configure %standard-phases)
2611@end example
2612
9bf404e9 2613means that all the phases described above will be used, except the
7458bd0a
LC
2614@code{configure} phase.
2615
2616In addition, this build system ensures that the ``standard'' environment
2617for GNU packages is available. This includes tools such as GCC, libc,
2618Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
2619build-system gnu)} module for a complete list.) We call these the
2620@dfn{implicit inputs} of a package, because package definitions don't
2621have to mention them.
2622@end defvr
2623
2624Other @code{<build-system>} objects are defined to support other
2625conventions and tools used by free software packages. They inherit most
2626of @var{gnu-build-system}, and differ mainly in the set of inputs
2627implicitly added to the build process, and in the list of phases
2628executed. Some of these build systems are listed below.
2629
2630@defvr {Scheme Variable} cmake-build-system
2631This variable is exported by @code{(guix build-system cmake)}. It
2632implements the build procedure for packages using the
2633@url{http://www.cmake.org, CMake build tool}.
2634
2635It automatically adds the @code{cmake} package to the set of inputs.
2636Which package is used can be specified with the @code{#:cmake}
2637parameter.
9849cfc1
LC
2638
2639The @code{#:configure-flags} parameter is taken as a list of flags
2640passed to the @command{cmake} command. The @code{#:build-type}
2641parameter specifies in abstract terms the flags passed to the compiler;
2642it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
2643debugging information''), which roughly means that code is compiled with
2644@code{-O2 -g}, as is the case for Autoconf-based packages by default.
7458bd0a
LC
2645@end defvr
2646
3afcf52b
FB
2647@defvr {Scheme Variable} glib-or-gtk-build-system
2648This variable is exported by @code{(guix build-system glib-or-gtk)}. It
2649is intended for use with packages making use of GLib or GTK+.
2650
2651This build system adds the following two phases to the ones defined by
2652@var{gnu-build-system}:
2653
2654@table @code
2655@item glib-or-gtk-wrap
2656The phase @code{glib-or-gtk-wrap} ensures that programs found under
2657@file{bin/} are able to find GLib's ``schemas'' and
2658@uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
2659modules}. This is achieved by wrapping the programs in launch scripts
2660that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
2661environment variables.
2662
73aa8ddb
LC
2663It is possible to exclude specific package outputs from that wrapping
2664process by listing their names in the
2665@code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
2666when an output is known not to contain any GLib or GTK+ binaries, and
2667where wrapping would gratuitously add a dependency of that output on
2668GLib and GTK+.
2669
3afcf52b
FB
2670@item glib-or-gtk-compile-schemas
2671The phase @code{glib-or-gtk-compile-schemas} makes sure that all GLib's
2672@uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
2673GSettings schemas} are compiled. Compilation is performed by the
2674@command{glib-compile-schemas} program. It is provided by the package
2675@code{glib:bin} which is automatically imported by the build system.
2676The @code{glib} package providing @command{glib-compile-schemas} can be
2677specified with the @code{#:glib} parameter.
2678@end table
2679
2680Both phases are executed after the @code{install} phase.
2681@end defvr
2682
7458bd0a
LC
2683@defvr {Scheme Variable} python-build-system
2684This variable is exported by @code{(guix build-system python)}. It
2685implements the more or less standard build procedure used by Python
2686packages, which consists in running @code{python setup.py build} and
2687then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
2688
2689For packages that install stand-alone Python programs under @code{bin/},
2690it takes care of wrapping these programs so their @code{PYTHONPATH}
2691environment variable points to all the Python libraries they depend on.
2692
2693Which Python package is used can be specified with the @code{#:python}
2694parameter.
2695@end defvr
2696
2697@defvr {Scheme Variable} perl-build-system
2698This variable is exported by @code{(guix build-system perl)}. It
2d2a53fc
EB
2699implements the standard build procedure for Perl packages, which either
2700consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
2701followed by @code{Build} and @code{Build install}; or in running
2702@code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
2703@code{make} and @code{make install}; depending on which of
2704@code{Build.PL} or @code{Makefile.PL} is present in the package
2705distribution. Preference is given to the former if both @code{Build.PL}
2706and @code{Makefile.PL} exist in the package distribution. This
2707preference can be reversed by specifying @code{#t} for the
2708@code{#:make-maker?} parameter.
2709
2710The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
2711passes flags specified by the @code{#:make-maker-flags} or
2712@code{#:module-build-flags} parameter, respectively.
7458bd0a
LC
2713
2714Which Perl package is used can be specified with @code{#:perl}.
2715@end defvr
2716
f8f3bef6
RW
2717@defvr {Scheme Variable} r-build-system
2718This variable is exported by @code{(guix build-system r)}. It
2719implements the build procedure used by @uref{http://r-project.org, R}
2720packages, which essentially is little more than running @code{R CMD
2721INSTALL --library=/gnu/store/@dots{}} in an environment where
2722@code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
2723are run after installation using the R function
2724@code{tools::testInstalledPackage}.
2725@end defvr
2726
c08f9818
DT
2727@defvr {Scheme Variable} ruby-build-system
2728This variable is exported by @code{(guix build-system ruby)}. It
2729implements the RubyGems build procedure used by Ruby packages, which
2730involves running @code{gem build} followed by @code{gem install}.
2731
5dc87623
DT
2732The @code{source} field of a package that uses this build system
2733typically references a gem archive, since this is the format that Ruby
2734developers use when releasing their software. The build system unpacks
2735the gem archive, potentially patches the source, runs the test suite,
2736repackages the gem, and installs it. Additionally, directories and
2737tarballs may be referenced to allow building unreleased gems from Git or
2738a traditional source release tarball.
e83c6d00 2739
c08f9818 2740Which Ruby package is used can be specified with the @code{#:ruby}
6e9f2913
PP
2741parameter. A list of additional flags to be passed to the @command{gem}
2742command can be specified with the @code{#:gem-flags} parameter.
c08f9818 2743@end defvr
7458bd0a 2744
a677c726
RW
2745@defvr {Scheme Variable} waf-build-system
2746This variable is exported by @code{(guix build-system waf)}. It
2747implements a build procedure around the @code{waf} script. The common
2748phases---@code{configure}, @code{build}, and @code{install}---are
2749implemented by passing their names as arguments to the @code{waf}
2750script.
2751
2752The @code{waf} script is executed by the Python interpreter. Which
2753Python package is used to run the script can be specified with the
2754@code{#:python} parameter.
2755@end defvr
2756
14dfdf2e
FB
2757@defvr {Scheme Variable} haskell-build-system
2758This variable is exported by @code{(guix build-system haskell)}. It
2759implements the Cabal build procedure used by Haskell packages, which
2760involves running @code{runhaskell Setup.hs configure
2761--prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
2762Instead of installing the package by running @code{runhaskell Setup.hs
2763install}, to avoid trying to register libraries in the read-only
2764compiler store directory, the build system uses @code{runhaskell
2765Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
2766addition, the build system generates the package documentation by
2767running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
2768is passed. Optional Haddock parameters can be passed with the help of
2769the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
2770not found, the build system looks for @code{Setup.lhs} instead.
2771
2772Which Haskell compiler is used can be specified with the @code{#:haskell}
a54bd6d7 2773parameter which defaults to @code{ghc}.
14dfdf2e
FB
2774@end defvr
2775
e9137a53
FB
2776@defvr {Scheme Variable} emacs-build-system
2777This variable is exported by @code{(guix build-system emacs)}. It
2778implements an installation procedure similar to the one of Emacs' own
2779packaging system (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
2780
2781It first creates the @code{@var{package}-autoloads.el} file, then it
2782byte compiles all Emacs Lisp files. Differently from the Emacs
2783packaging system, the Info documentation files are moved to the standard
2784documentation directory and the @file{dir} file is deleted. Each
2785package is installed in its own directory under
2786@file{share/emacs/site-lisp/guix.d}.
2787@end defvr
2788
7458bd0a
LC
2789Lastly, for packages that do not need anything as sophisticated, a
2790``trivial'' build system is provided. It is trivial in the sense that
2791it provides basically no support: it does not pull any implicit inputs,
2792and does not have a notion of build phases.
2793
2794@defvr {Scheme Variable} trivial-build-system
2795This variable is exported by @code{(guix build-system trivial)}.
2796
2797This build system requires a @code{#:builder} argument. This argument
2798must be a Scheme expression that builds the package's output(s)---as
2799with @code{build-expression->derivation} (@pxref{Derivations,
2800@code{build-expression->derivation}}).
2801@end defvr
2802
568717fd
LC
2803@node The Store
2804@section The Store
2805
e531ac2a
LC
2806@cindex store
2807@cindex store paths
2808
2809Conceptually, the @dfn{store} is where derivations that have been
834129e0 2810successfully built are stored---by default, under @file{/gnu/store}.
e531ac2a 2811Sub-directories in the store are referred to as @dfn{store paths}. The
4988dd40 2812store has an associated database that contains information such as the
e531ac2a
LC
2813store paths referred to by each store path, and the list of @emph{valid}
2814store paths---paths that result from a successful build.
2815
2816The store is always accessed by the daemon on behalf of its clients
2817(@pxref{Invoking guix-daemon}). To manipulate the store, clients
2818connect to the daemon over a Unix-domain socket, send it requests, and
2819read the result---these are remote procedure calls, or RPCs.
2820
2821The @code{(guix store)} module provides procedures to connect to the
2822daemon, and to perform RPCs. These are described below.
2823
2824@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
2825Connect to the daemon over the Unix-domain socket at @var{file}. When
2826@var{reserve-space?} is true, instruct it to reserve a little bit of
2827extra space on the file system so that the garbage collector can still
2828operate, should the disk become full. Return a server object.
2829
2830@var{file} defaults to @var{%default-socket-path}, which is the normal
2831location given the options that were passed to @command{configure}.
2832@end deffn
2833
2834@deffn {Scheme Procedure} close-connection @var{server}
2835Close the connection to @var{server}.
2836@end deffn
2837
2838@defvr {Scheme Variable} current-build-output-port
2839This variable is bound to a SRFI-39 parameter, which refers to the port
2840where build and error logs sent by the daemon should be written.
2841@end defvr
2842
2843Procedures that make RPCs all take a server object as their first
2844argument.
2845
2846@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
2847Return @code{#t} when @var{path} is a valid store path.
2848@end deffn
2849
cfbf9160 2850@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
2851Add @var{text} under file @var{name} in the store, and return its store
2852path. @var{references} is the list of store paths referred to by the
2853resulting store path.
2854@end deffn
2855
874e6874 2856@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
2857Build @var{derivations} (a list of @code{<derivation>} objects or
2858derivation paths), and return when the worker is done building them.
2859Return @code{#t} on success.
874e6874
LC
2860@end deffn
2861
b860f382
LC
2862Note that the @code{(guix monads)} module provides a monad as well as
2863monadic versions of the above procedures, with the goal of making it
2864more convenient to work with code that accesses the store (@pxref{The
2865Store Monad}).
2866
e531ac2a
LC
2867@c FIXME
2868@i{This section is currently incomplete.}
568717fd
LC
2869
2870@node Derivations
2871@section Derivations
2872
874e6874
LC
2873@cindex derivations
2874Low-level build actions and the environment in which they are performed
2875are represented by @dfn{derivations}. A derivation contain the
2876following pieces of information:
2877
2878@itemize
2879@item
2880The outputs of the derivation---derivations produce at least one file or
2881directory in the store, but may produce more.
2882
2883@item
2884The inputs of the derivations, which may be other derivations or plain
2885files in the store (patches, build scripts, etc.)
2886
2887@item
2888The system type targeted by the derivation---e.g., @code{x86_64-linux}.
2889
2890@item
2891The file name of a build script in the store, along with the arguments
2892to be passed.
2893
2894@item
2895A list of environment variables to be defined.
2896
2897@end itemize
2898
2899@cindex derivation path
2900Derivations allow clients of the daemon to communicate build actions to
2901the store. They exist in two forms: as an in-memory representation,
2902both on the client- and daemon-side, and as files in the store whose
2903name end in @code{.drv}---these files are referred to as @dfn{derivation
2904paths}. Derivations paths can be passed to the @code{build-derivations}
2905procedure to perform the build actions they prescribe (@pxref{The
2906Store}).
2907
2908The @code{(guix derivations)} module provides a representation of
2909derivations as Scheme objects, along with procedures to create and
2910otherwise manipulate derivations. The lowest-level primitive to create
2911a derivation is the @code{derivation} procedure:
2912
1909431c
LC
2913@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
2914 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 2915 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c 2916 [#:system (%current-system)] [#:references-graphs #f] @
4a6aeb67
LC
2917 [#:allowed-references #f] [#:leaked-env-vars #f] [#:local-build? #f] @
2918 [#:substitutable? #t]
59688fc4
LC
2919Build a derivation with the given arguments, and return the resulting
2920@code{<derivation>} object.
874e6874 2921
2096ef47 2922When @var{hash} and @var{hash-algo} are given, a
874e6874 2923@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
2924known in advance, such as a file download. If, in addition,
2925@var{recursive?} is true, then that fixed output may be an executable
2926file or a directory and @var{hash} must be the hash of an archive
2927containing this output.
5b0c9d16 2928
858e9282 2929When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
2930name/store path pairs. In that case, the reference graph of each store
2931path is exported in the build environment in the corresponding file, in
2932a simple text format.
1909431c 2933
b53be755
LC
2934When @var{allowed-references} is true, it must be a list of store items
2935or outputs that the derivation's output may refer to.
2936
c0468155
LC
2937When @var{leaked-env-vars} is true, it must be a list of strings
2938denoting environment variables that are allowed to ``leak'' from the
2939daemon's environment to the build environment. This is only applicable
2940to fixed-output derivations---i.e., when @var{hash} is true. The main
2941use is to allow variables such as @code{http_proxy} to be passed to
2942derivations that download files.
2943
1909431c
LC
2944When @var{local-build?} is true, declare that the derivation is not a
2945good candidate for offloading and should rather be built locally
2946(@pxref{Daemon Offload Setup}). This is the case for small derivations
2947where the costs of data transfers would outweigh the benefits.
4a6aeb67
LC
2948
2949When @var{substitutable?} is false, declare that substitutes of the
2950derivation's output should not be used (@pxref{Substitutes}). This is
2951useful, for instance, when building packages that capture details of the
2952host CPU instruction set.
874e6874
LC
2953@end deffn
2954
2955@noindent
2956Here's an example with a shell script as its builder, assuming
2957@var{store} is an open connection to the daemon, and @var{bash} points
2958to a Bash executable in the store:
2959
2960@lisp
2961(use-modules (guix utils)
2962 (guix store)
2963 (guix derivations))
2964
59688fc4
LC
2965(let ((builder ; add the Bash script to the store
2966 (add-text-to-store store "my-builder.sh"
2967 "echo hello world > $out\n" '())))
2968 (derivation store "foo"
2969 bash `("-e" ,builder)
21b679f6 2970 #:inputs `((,bash) (,builder))
59688fc4 2971 #:env-vars '(("HOME" . "/homeless"))))
834129e0 2972@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
2973@end lisp
2974
21b679f6
LC
2975As can be guessed, this primitive is cumbersome to use directly. A
2976better approach is to write build scripts in Scheme, of course! The
2977best course of action for that is to write the build code as a
2978``G-expression'', and to pass it to @code{gexp->derivation}. For more
6621cdb6 2979information, @pxref{G-Expressions}.
21b679f6
LC
2980
2981Once upon a time, @code{gexp->derivation} did not exist and constructing
2982derivations with build code written in Scheme was achieved with
2983@code{build-expression->derivation}, documented below. This procedure
2984is now deprecated in favor of the much nicer @code{gexp->derivation}.
874e6874 2985
dd1a5a15
LC
2986@deffn {Scheme Procedure} build-expression->derivation @var{store} @
2987 @var{name} @var{exp} @
2988 [#:system (%current-system)] [#:inputs '()] @
2989 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
36bbbbd1 2990 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
63a42824 2991 [#:references-graphs #f] [#:allowed-references #f] @
4a6aeb67 2992 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
874e6874
LC
2993Return a derivation that executes Scheme expression @var{exp} as a
2994builder for derivation @var{name}. @var{inputs} must be a list of
2995@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
2996@code{"out"} is assumed. @var{modules} is a list of names of Guile
2997modules from the current search path to be copied in the store,
2998compiled, and made available in the load path during the execution of
2999@var{exp}---e.g., @code{((guix build utils) (guix build
3000gnu-build-system))}.
3001
3002@var{exp} is evaluated in an environment where @code{%outputs} is bound
3003to a list of output/path pairs, and where @code{%build-inputs} is bound
3004to a list of string/output-path pairs made from @var{inputs}.
3005Optionally, @var{env-vars} is a list of string pairs specifying the name
3006and value of environment variables visible to the builder. The builder
3007terminates by passing the result of @var{exp} to @code{exit}; thus, when
3008@var{exp} returns @code{#f}, the build is considered to have failed.
3009
3010@var{exp} is built using @var{guile-for-build} (a derivation). When
3011@var{guile-for-build} is omitted or is @code{#f}, the value of the
3012@code{%guile-for-build} fluid is used instead.
9c629a27 3013
63a42824 3014See the @code{derivation} procedure for the meaning of
4a6aeb67
LC
3015@var{references-graphs}, @var{allowed-references}, @var{local-build?},
3016and @var{substitutable?}.
874e6874
LC
3017@end deffn
3018
3019@noindent
3020Here's an example of a single-output derivation that creates a directory
3021containing one file:
3022
3023@lisp
3024(let ((builder '(let ((out (assoc-ref %outputs "out")))
834129e0 3025 (mkdir out) ; create /gnu/store/@dots{}-goo
874e6874
LC
3026 (call-with-output-file (string-append out "/test")
3027 (lambda (p)
3028 (display '(hello guix) p))))))
dd1a5a15 3029 (build-expression->derivation store "goo" builder))
874e6874 3030
834129e0 3031@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
874e6874
LC
3032@end lisp
3033
568717fd 3034
b860f382
LC
3035@node The Store Monad
3036@section The Store Monad
3037
3038@cindex monad
3039
3040The procedures that operate on the store described in the previous
3041sections all take an open connection to the build daemon as their first
3042argument. Although the underlying model is functional, they either have
3043side effects or depend on the current state of the store.
3044
3045The former is inconvenient: the connection to the build daemon has to be
3046carried around in all those functions, making it impossible to compose
3047functions that do not take that parameter with functions that do. The
3048latter can be problematic: since store operations have side effects
3049and/or depend on external state, they have to be properly sequenced.
3050
3051@cindex monadic values
3052@cindex monadic functions
3053This is where the @code{(guix monads)} module comes in. This module
3054provides a framework for working with @dfn{monads}, and a particularly
3055useful monad for our uses, the @dfn{store monad}. Monads are a
3056construct that allows two things: associating ``context'' with values
3057(in our case, the context is the store), and building sequences of
561fb6c3 3058computations (here computations include accesses to the store.) Values
b860f382
LC
3059in a monad---values that carry this additional context---are called
3060@dfn{monadic values}; procedures that return such values are called
3061@dfn{monadic procedures}.
3062
3063Consider this ``normal'' procedure:
3064
3065@example
45adbd62
LC
3066(define (sh-symlink store)
3067 ;; Return a derivation that symlinks the 'bash' executable.
3068 (let* ((drv (package-derivation store bash))
3069 (out (derivation->output-path drv))
3070 (sh (string-append out "/bin/bash")))
3071 (build-expression->derivation store "sh"
3072 `(symlink ,sh %output))))
b860f382
LC
3073@end example
3074
c6f30b81
LC
3075Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3076as a monadic function:
b860f382
LC
3077
3078@example
45adbd62 3079(define (sh-symlink)
b860f382 3080 ;; Same, but return a monadic value.
c6f30b81
LC
3081 (mlet %store-monad ((drv (package->derivation bash)))
3082 (gexp->derivation "sh"
3083 #~(symlink (string-append #$drv "/bin/bash")
3084 #$output))))
b860f382
LC
3085@end example
3086
c6f30b81
LC
3087There several things to note in the second version: the @code{store}
3088parameter is now implicit and is ``threaded'' in the calls to the
3089@code{package->derivation} and @code{gexp->derivation} monadic
3090procedures, and the monadic value returned by @code{package->derivation}
3091is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3092
3093As it turns out, the call to @code{package->derivation} can even be
3094omitted since it will take place implicitly, as we will see later
3095(@pxref{G-Expressions}):
3096
3097@example
3098(define (sh-symlink)
3099 (gexp->derivation "sh"
3100 #~(symlink (string-append #$bash "/bin/bash")
3101 #$output)))
3102@end example
b860f382 3103
7ce21611
LC
3104@c See
3105@c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
3106@c for the funny quote.
3107Calling the monadic @code{sh-symlink} has no effect. As someone once
3108said, ``you exit a monad like you exit a building on fire: by running''.
3109So, to exit the monad and get the desired effect, one must use
3110@code{run-with-store}:
b860f382
LC
3111
3112@example
8e9aa37f
CAW
3113(run-with-store (open-connection) (sh-symlink))
3114@result{} /gnu/store/...-sh-symlink
b860f382
LC
3115@end example
3116
b9b86078
LC
3117Note that the @code{(guix monad-repl)} module extends Guile's REPL with
3118new ``meta-commands'' to make it easier to deal with monadic procedures:
3119@code{run-in-store}, and @code{enter-store-monad}. The former, is used
3120to ``run'' a single monadic value through the store:
3121
3122@example
3123scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3124$1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3125@end example
3126
3127The latter enters a recursive REPL, where all the return values are
3128automatically run through the store:
3129
3130@example
3131scheme@@(guile-user)> ,enter-store-monad
3132store-monad@@(guile-user) [1]> (package->derivation hello)
3133$2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3134store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3135$3 = "/gnu/store/@dots{}-foo"
3136store-monad@@(guile-user) [1]> ,q
3137scheme@@(guile-user)>
3138@end example
3139
3140@noindent
3141Note that non-monadic values cannot be returned in the
3142@code{store-monad} REPL.
3143
e87f0591
LC
3144The main syntactic forms to deal with monads in general are provided by
3145the @code{(guix monads)} module and are described below.
b860f382
LC
3146
3147@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3148Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3149in @var{monad}.
3150@end deffn
3151
3152@deffn {Scheme Syntax} return @var{val}
3153Return a monadic value that encapsulates @var{val}.
3154@end deffn
3155
751630c9 3156@deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
b860f382 3157@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
751630c9
LC
3158procedures @var{mproc}@dots{}@footnote{This operation is commonly
3159referred to as ``bind'', but that name denotes an unrelated procedure in
3160Guile. Thus we use this somewhat cryptic symbol inherited from the
3161Haskell language.}. There can be one @var{mproc} or several of them, as
3162in this example:
3163
3164@example
3165(run-with-state
3166 (with-monad %state-monad
3167 (>>= (return 1)
3168 (lambda (x) (return (+ 1 x)))
3169 (lambda (x) (return (* 2 x)))))
3170 'some-state)
3171
3172@result{} 4
3173@result{} some-state
3174@end example
b860f382
LC
3175@end deffn
3176
3177@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3178 @var{body} ...
3179@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3180 @var{body} ...
3181Bind the variables @var{var} to the monadic values @var{mval} in
3182@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3183``normal'' value @var{val}, as per @code{let}.
3184
3185@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3186(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3187@end deffn
3188
405a9d4e
LC
3189@deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3190Bind @var{mexp} and the following monadic expressions in sequence,
3191returning the result of the last expression.
3192
3193This is akin to @code{mlet}, except that the return values of the
3194monadic expressions are ignored. In that sense, it is analogous to
3195@code{begin}, but applied to monadic expressions.
3196@end deffn
3197
561fb6c3
LC
3198@cindex state monad
3199The @code{(guix monads)} module provides the @dfn{state monad}, which
3200allows an additional value---the state---to be @emph{threaded} through
3201monadic procedure calls.
3202
3203@defvr {Scheme Variable} %state-monad
3204The state monad. Procedures in the state monad can access and change
3205the state that is threaded.
3206
3207Consider the example below. The @code{square} procedure returns a value
3208in the state monad. It returns the square of its argument, but also
3209increments the current state value:
3210
3211@example
3212(define (square x)
3213 (mlet %state-monad ((count (current-state)))
3214 (mbegin %state-monad
3215 (set-current-state (+ 1 count))
3216 (return (* x x)))))
3217
3218(run-with-state (sequence %state-monad (map square (iota 3))) 0)
3219@result{} (0 1 4)
3220@result{} 3
3221@end example
3222
3223When ``run'' through @var{%state-monad}, we obtain that additional state
3224value, which is the number of @code{square} calls.
3225@end defvr
3226
3227@deffn {Monadic Procedure} current-state
3228Return the current state as a monadic value.
3229@end deffn
3230
3231@deffn {Monadic Procedure} set-current-state @var{value}
3232Set the current state to @var{value} and return the previous state as a
3233monadic value.
3234@end deffn
3235
3236@deffn {Monadic Procedure} state-push @var{value}
3237Push @var{value} to the current state, which is assumed to be a list,
3238and return the previous state as a monadic value.
3239@end deffn
3240
3241@deffn {Monadic Procedure} state-pop
3242Pop a value from the current state and return it as a monadic value.
3243The state is assumed to be a list.
3244@end deffn
3245
3246@deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3247Run monadic value @var{mval} starting with @var{state} as the initial
3248state. Return two values: the resulting value, and the resulting state.
3249@end deffn
3250
e87f0591
LC
3251The main interface to the store monad, provided by the @code{(guix
3252store)} module, is as follows.
b860f382
LC
3253
3254@defvr {Scheme Variable} %store-monad
561fb6c3
LC
3255The store monad---an alias for @var{%state-monad}.
3256
3257Values in the store monad encapsulate accesses to the store. When its
3258effect is needed, a value of the store monad must be ``evaluated'' by
3259passing it to the @code{run-with-store} procedure (see below.)
b860f382
LC
3260@end defvr
3261
3262@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3263Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3264open store connection.
3265@end deffn
3266
ad372953 3267@deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
b860f382 3268Return as a monadic value the absolute file name in the store of the file
ad372953
LC
3269containing @var{text}, a string. @var{references} is a list of store items that the
3270resulting text file refers to; it defaults to the empty list.
45adbd62
LC
3271@end deffn
3272
0a90af15
LC
3273@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
3274 [#:recursive? #t]
3275Return the name of @var{file} once interned in the store. Use
3276@var{name} as its store name, or the basename of @var{file} if
3277@var{name} is omitted.
3278
3279When @var{recursive?} is true, the contents of @var{file} are added
3280recursively; if @var{file} designates a flat file and @var{recursive?}
3281is true, its contents are added, and its permission bits are kept.
3282
3283The example below adds a file to the store, under two different names:
3284
3285@example
3286(run-with-store (open-connection)
3287 (mlet %store-monad ((a (interned-file "README"))
3288 (b (interned-file "README" "LEGU-MIN")))
3289 (return (list a b))))
3290
3291@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3292@end example
3293
3294@end deffn
3295
e87f0591
LC
3296The @code{(guix packages)} module exports the following package-related
3297monadic procedures:
3298
b860f382 3299@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4231f05b
LC
3300 [#:system (%current-system)] [#:target #f] @
3301 [#:output "out"] Return as a monadic
b860f382
LC
3302value in the absolute file name of @var{file} within the @var{output}
3303directory of @var{package}. When @var{file} is omitted, return the name
4231f05b
LC
3304of the @var{output} directory of @var{package}. When @var{target} is
3305true, use it as a cross-compilation target triplet.
b860f382
LC
3306@end deffn
3307
b860f382 3308@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4231f05b
LC
3309@deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3310 @var{target} [@var{system}]
3311Monadic version of @code{package-derivation} and
3312@code{package-cross-derivation} (@pxref{Defining Packages}).
b860f382
LC
3313@end deffn
3314
3315
21b679f6
LC
3316@node G-Expressions
3317@section G-Expressions
3318
3319@cindex G-expression
3320@cindex build code quoting
3321So we have ``derivations'', which represent a sequence of build actions
3322to be performed to produce an item in the store (@pxref{Derivations}).
3323Those build actions are performed when asking the daemon to actually
3324build the derivations; they are run by the daemon in a container
3325(@pxref{Invoking guix-daemon}).
3326
3327@cindex strata of code
3328It should come as no surprise that we like to write those build actions
3329in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3330code@footnote{The term @dfn{stratum} in this context was coined by
ef4ab0a4
LC
3331Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3332Kiselyov, who has written insightful
3333@url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3334on this topic}, refers to this kind of code generation as
3335@dfn{staging}.}: the ``host code''---code that defines packages, talks
3336to the daemon, etc.---and the ``build code''---code that actually
3337performs build actions, such as making directories, invoking
3338@command{make}, etc.
21b679f6
LC
3339
3340To describe a derivation and its build actions, one typically needs to
3341embed build code inside host code. It boils down to manipulating build
3342code as data, and Scheme's homoiconicity---code has a direct
3343representation as data---comes in handy for that. But we need more than
3344Scheme's normal @code{quasiquote} mechanism to construct build
3345expressions.
3346
3347The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3348S-expressions adapted to build expressions. G-expressions, or
3349@dfn{gexps}, consist essentially in three syntactic forms: @code{gexp},
3350@code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
3351@code{#$}, and @code{#$@@}), which are comparable respectively to
3352@code{quasiquote}, @code{unquote}, and @code{unquote-splicing}
3353(@pxref{Expression Syntax, @code{quasiquote},, guile, GNU Guile
3354Reference Manual}). However, there are major differences:
3355
3356@itemize
3357@item
3358Gexps are meant to be written to a file and run or manipulated by other
3359processes.
3360
3361@item
b39fc6f7
LC
3362When a high-level object such as a package or derivation is unquoted
3363inside a gexp, the result is as if its output file name had been
3364introduced.
ff40e9b7 3365
21b679f6
LC
3366@item
3367Gexps carry information about the packages or derivations they refer to,
3368and these dependencies are automatically added as inputs to the build
3369processes that use them.
3370@end itemize
3371
c2b84676 3372@cindex lowering, of high-level objects in gexps
343eacbe
LC
3373This mechanism is not limited to package and derivation
3374objects: @dfn{compilers} able to ``lower'' other high-level objects to
c2b84676
LC
3375derivations or files in the store can be defined,
3376such that these objects can also be inserted
343eacbe
LC
3377into gexps. For example, a useful type of high-level object that can be
3378inserted in a gexp is ``file-like objects'', which make it easy to
3379add files to the store and refer to them in
558e8b11
LC
3380derivations and such (see @code{local-file} and @code{plain-file}
3381below.)
b39fc6f7 3382
21b679f6
LC
3383To illustrate the idea, here is an example of a gexp:
3384
3385@example
3386(define build-exp
3387 #~(begin
3388 (mkdir #$output)
3389 (chdir #$output)
aff8ce7c 3390 (symlink (string-append #$coreutils "/bin/ls")
21b679f6
LC
3391 "list-files")))
3392@end example
3393
3394This gexp can be passed to @code{gexp->derivation}; we obtain a
3395derivation that builds a directory containing exactly one symlink to
3396@file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3397
3398@example
3399(gexp->derivation "the-thing" build-exp)
3400@end example
3401
e20fd1bf 3402As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
21b679f6
LC
3403substituted to the reference to the @var{coreutils} package in the
3404actual build code, and @var{coreutils} is automatically made an input to
3405the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
3406output)}) is replaced by a string containing the derivation's output
667b2508
LC
3407directory name.
3408
3409@cindex cross compilation
3410In a cross-compilation context, it is useful to distinguish between
3411references to the @emph{native} build of a package---that can run on the
3412host---versus references to cross builds of a package. To that end, the
3413@code{#+} plays the same role as @code{#$}, but is a reference to a
3414native package build:
3415
3416@example
3417(gexp->derivation "vi"
3418 #~(begin
3419 (mkdir #$output)
3420 (system* (string-append #+coreutils "/bin/ln")
3421 "-s"
3422 (string-append #$emacs "/bin/emacs")
3423 (string-append #$output "/bin/vi")))
3424 #:target "mips64el-linux")
3425@end example
3426
3427@noindent
3428In the example above, the native build of @var{coreutils} is used, so
3429that @command{ln} can actually run on the host; but then the
3430cross-compiled build of @var{emacs} is referenced.
3431
3432The syntactic form to construct gexps is summarized below.
21b679f6
LC
3433
3434@deffn {Scheme Syntax} #~@var{exp}
3435@deffnx {Scheme Syntax} (gexp @var{exp})
3436Return a G-expression containing @var{exp}. @var{exp} may contain one
3437or more of the following forms:
3438
3439@table @code
3440@item #$@var{obj}
3441@itemx (ungexp @var{obj})
b39fc6f7
LC
3442Introduce a reference to @var{obj}. @var{obj} may have one of the
3443supported types, for example a package or a
21b679f6
LC
3444derivation, in which case the @code{ungexp} form is replaced by its
3445output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
3446
b39fc6f7
LC
3447If @var{obj} is a list, it is traversed and references to supported
3448objects are substituted similarly.
21b679f6
LC
3449
3450If @var{obj} is another gexp, its contents are inserted and its
3451dependencies are added to those of the containing gexp.
3452
3453If @var{obj} is another kind of object, it is inserted as is.
3454
b39fc6f7
LC
3455@item #$@var{obj}:@var{output}
3456@itemx (ungexp @var{obj} @var{output})
21b679f6 3457This is like the form above, but referring explicitly to the
b39fc6f7
LC
3458@var{output} of @var{obj}---this is useful when @var{obj} produces
3459multiple outputs (@pxref{Packages with Multiple Outputs}).
21b679f6 3460
667b2508
LC
3461@item #+@var{obj}
3462@itemx #+@var{obj}:output
3463@itemx (ungexp-native @var{obj})
3464@itemx (ungexp-native @var{obj} @var{output})
3465Same as @code{ungexp}, but produces a reference to the @emph{native}
3466build of @var{obj} when used in a cross compilation context.
3467
21b679f6
LC
3468@item #$output[:@var{output}]
3469@itemx (ungexp output [@var{output}])
3470Insert a reference to derivation output @var{output}, or to the main
3471output when @var{output} is omitted.
3472
3473This only makes sense for gexps passed to @code{gexp->derivation}.
3474
3475@item #$@@@var{lst}
3476@itemx (ungexp-splicing @var{lst})
3477Like the above, but splices the contents of @var{lst} inside the
3478containing list.
3479
667b2508
LC
3480@item #+@@@var{lst}
3481@itemx (ungexp-native-splicing @var{lst})
3482Like the above, but refers to native builds of the objects listed in
3483@var{lst}.
3484
21b679f6
LC
3485@end table
3486
3487G-expressions created by @code{gexp} or @code{#~} are run-time objects
3488of the @code{gexp?} type (see below.)
3489@end deffn
3490
3491@deffn {Scheme Procedure} gexp? @var{obj}
3492Return @code{#t} if @var{obj} is a G-expression.
3493@end deffn
3494
3495G-expressions are meant to be written to disk, either as code building
3496some derivation, or as plain files in the store. The monadic procedures
3497below allow you to do that (@pxref{The Store Monad}, for more
3498information about monads.)
3499
3500@deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
ce45eb4c 3501 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
21b679f6
LC
3502 [#:hash #f] [#:hash-algo #f] @
3503 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4684f301 3504 [#:module-path @var{%load-path}] @
c8351d9a 3505 [#:references-graphs #f] [#:allowed-references #f] @
c0468155 3506 [#:leaked-env-vars #f] @
0309e1b0 3507 [#:script-name (string-append @var{name} "-builder")] @
4a6aeb67 3508 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
21b679f6 3509Return a derivation @var{name} that runs @var{exp} (a gexp) with
0309e1b0
LC
3510@var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
3511stored in a file called @var{script-name}. When @var{target} is true,
3512it is used as the cross-compilation target triplet for packages referred
3513to by @var{exp}.
21b679f6 3514
ce45eb4c
LC
3515Make @var{modules} available in the evaluation context of @var{exp};
3516@var{modules} is a list of names of Guile modules searched in
3517@var{module-path} to be copied in the store, compiled, and made available in
21b679f6
LC
3518the load path during the execution of @var{exp}---e.g., @code{((guix
3519build utils) (guix build gnu-build-system))}.
3520
ce45eb4c
LC
3521@var{graft?} determines whether packages referred to by @var{exp} should be grafted when
3522applicable.
3523
b53833b2
LC
3524When @var{references-graphs} is true, it must be a list of tuples of one of the
3525following forms:
3526
3527@example
3528(@var{file-name} @var{package})
3529(@var{file-name} @var{package} @var{output})
3530(@var{file-name} @var{derivation})
3531(@var{file-name} @var{derivation} @var{output})
3532(@var{file-name} @var{store-item})
3533@end example
3534
3535The right-hand-side of each element of @var{references-graphs} is automatically made
3536an input of the build process of @var{exp}. In the build environment, each
3537@var{file-name} contains the reference graph of the corresponding item, in a simple
3538text format.
3539
c8351d9a
LC
3540@var{allowed-references} must be either @code{#f} or a list of output names and packages.
3541In the latter case, the list denotes store items that the result is allowed to
3542refer to. Any reference to another store item will lead to a build error.
3543
e20fd1bf 3544The other arguments are as for @code{derivation} (@pxref{Derivations}).
21b679f6
LC
3545@end deffn
3546
343eacbe 3547@cindex file-like objects
e1c153e0
LC
3548The @code{local-file}, @code{plain-file}, @code{computed-file},
3549@code{program-file}, and @code{scheme-file} procedures below return
3550@dfn{file-like objects}. That is, when unquoted in a G-expression,
3551these objects lead to a file in the store. Consider this G-expression:
343eacbe
LC
3552
3553@example
3554#~(system* (string-append #$glibc "/sbin/nscd") "-f"
3555 #$(local-file "/tmp/my-nscd.conf"))
3556@end example
3557
3558The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
3559to the store. Once expanded, for instance @i{via}
3560@code{gexp->derivation}, the G-expression refers to that copy under
3561@file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
3562does not have any effect on what the G-expression does.
3563@code{plain-file} can be used similarly; it differs in that the file
3564content is directly passed as a string.
3565
d9ae938f
LC
3566@deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
3567 [#:recursive? #t]
3568Return an object representing local file @var{file} to add to the store; this
9d3994f7
LC
3569object can be used in a gexp. If @var{file} is a relative file name, it is looked
3570up relative to the source file where this form appears. @var{file} will be added to
3571the store under @var{name}--by default the base name of @var{file}.
d9ae938f
LC
3572
3573When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
3574designates a flat file and @var{recursive?} is true, its contents are added, and its
3575permission bits are kept.
3576
3577This is the declarative counterpart of the @code{interned-file} monadic
3578procedure (@pxref{The Store Monad, @code{interned-file}}).
3579@end deffn
3580
558e8b11
LC
3581@deffn {Scheme Procedure} plain-file @var{name} @var{content}
3582Return an object representing a text file called @var{name} with the given
3583@var{content} (a string) to be added to the store.
3584
3585This is the declarative counterpart of @code{text-file}.
3586@end deffn
3587
91937029
LC
3588@deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
3589 [#:modules '()] [#:options '(#:local-build? #t)]
3590Return an object representing the store item @var{name}, a file or
3591directory computed by @var{gexp}. @var{modules} specifies the set of
3592modules visible in the execution context of @var{gexp}. @var{options}
3593is a list of additional arguments to pass to @code{gexp->derivation}.
3594
3595This is the declarative counterpart of @code{gexp->derivation}.
3596@end deffn
3597
21b679f6
LC
3598@deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
3599Return an executable script @var{name} that runs @var{exp} using
3600@var{guile} with @var{modules} in its search path.
3601
3602The example below builds a script that simply invokes the @command{ls}
3603command:
3604
3605@example
3606(use-modules (guix gexp) (gnu packages base))
3607
3608(gexp->script "list-files"
3609 #~(execl (string-append #$coreutils "/bin/ls")
3610 "ls"))
3611@end example
3612
3613When ``running'' it through the store (@pxref{The Store Monad,
e20fd1bf 3614@code{run-with-store}}), we obtain a derivation that produces an
21b679f6
LC
3615executable file @file{/gnu/store/@dots{}-list-files} along these lines:
3616
3617@example
3618#!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
3619!#
3620(execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls")
3621 "ls")
3622@end example
3623@end deffn
3624
15a01c72
LC
3625@deffn {Scheme Procedure} program-file @var{name} @var{exp} @
3626 [#:modules '()] [#:guile #f]
3627Return an object representing the executable store item @var{name} that
3628runs @var{gexp}. @var{guile} is the Guile package used to execute that
3629script, and @var{modules} is the list of modules visible to that script.
3630
3631This is the declarative counterpart of @code{gexp->script}.
3632@end deffn
3633
21b679f6
LC
3634@deffn {Monadic Procedure} gexp->file @var{name} @var{exp}
3635Return a derivation that builds a file @var{name} containing @var{exp}.
3636
3637The resulting file holds references to all the dependencies of @var{exp}
3638or a subset thereof.
3639@end deffn
1ed19464 3640
e1c153e0
LC
3641@deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
3642Return an object representing the Scheme file @var{name} that contains
3643@var{exp}.
3644
3645This is the declarative counterpart of @code{gexp->file}.
3646@end deffn
3647
1ed19464
LC
3648@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
3649Return as a monadic value a derivation that builds a text file
3650containing all of @var{text}. @var{text} may list, in addition to
d9ae938f
LC
3651strings, objects of any type that can be used in a gexp: packages,
3652derivations, local file objects, etc. The resulting store file holds
3653references to all these.
1ed19464
LC
3654
3655This variant should be preferred over @code{text-file} anytime the file
3656to create will reference items from the store. This is typically the
3657case when building a configuration file that embeds store file names,
3658like this:
3659
3660@example
3661(define (profile.sh)
3662 ;; Return the name of a shell script in the store that
3663 ;; initializes the 'PATH' environment variable.
3664 (text-file* "profile.sh"
3665 "export PATH=" coreutils "/bin:"
3666 grep "/bin:" sed "/bin\n"))
3667@end example
3668
3669In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
3670will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
3671preventing them from being garbage-collected during its lifetime.
3672@end deffn
21b679f6 3673
b751cde3
LC
3674@deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
3675Return an object representing store file @var{name} containing
3676@var{text}. @var{text} is a sequence of strings and file-like objects,
3677as in:
3678
3679@example
3680(mixed-text-file "profile"
3681 "export PATH=" coreutils "/bin:" grep "/bin")
3682@end example
3683
3684This is the declarative counterpart of @code{text-file*}.
3685@end deffn
3686
21b679f6
LC
3687Of course, in addition to gexps embedded in ``host'' code, there are
3688also modules containing build tools. To make it clear that they are
3689meant to be used in the build stratum, these modules are kept in the
3690@code{(guix build @dots{})} name space.
3691
c2b84676
LC
3692@cindex lowering, of high-level objects in gexps
3693Internally, high-level objects are @dfn{lowered}, using their compiler,
3694to either derivations or store items. For instance, lowering a package
3695yields a derivation, and lowering a @code{plain-file} yields a store
3696item. This is achieved using the @code{lower-object} monadic procedure.
3697
3698@deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
3699 [#:target #f]
3700Return as a value in @var{%store-monad} the derivation or store item
3701corresponding to @var{obj} for @var{system}, cross-compiling for
3702@var{target} if @var{target} is true. @var{obj} must be an object that
3703has an associated gexp compiler, such as a @code{<package>}.
3704@end deffn
3705
21b679f6 3706
568717fd
LC
3707@c *********************************************************************
3708@node Utilities
3709@chapter Utilities
3710
210cc920
LC
3711This section describes tools primarily targeted at developers and users
3712who write new package definitions. They complement the Scheme
3713programming interface of Guix in a convenient way.
3714
568717fd 3715@menu
37166310 3716* Invoking guix build:: Building packages from the command line.
39bee8a2 3717* Invoking guix edit:: Editing package definitions.
210cc920 3718* Invoking guix download:: Downloading a file and printing its hash.
37166310 3719* Invoking guix hash:: Computing the cryptographic hash of a file.
2f7d2d91 3720* Invoking guix import:: Importing package definitions.
37166310 3721* Invoking guix refresh:: Updating package definitions.
b4f5e0e8 3722* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 3723* Invoking guix size:: Profiling disk usage.
88856916 3724* Invoking guix graph:: Visualizing the graph of packages.
372c4bbc 3725* Invoking guix environment:: Setting up development environments.
aff8ce7c 3726* Invoking guix publish:: Sharing substitutes.
d23c20f1 3727* Invoking guix challenge:: Challenging substitute servers.
32efa254 3728* Invoking guix container:: Process isolation.
568717fd
LC
3729@end menu
3730
e49951eb
MW
3731@node Invoking guix build
3732@section Invoking @command{guix build}
568717fd 3733
e49951eb 3734The @command{guix build} command builds packages or derivations and
6798a8e4
LC
3735their dependencies, and prints the resulting store paths. Note that it
3736does not modify the user's profile---this is the job of the
e49951eb 3737@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
3738it is mainly useful for distribution developers.
3739
3740The general syntax is:
c78bd12b
LC
3741
3742@example
e49951eb 3743guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
3744@end example
3745
3746@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
3747the software distribution such as @code{coreutils} or
3748@code{coreutils-8.20}, or a derivation such as
834129e0 3749@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
3750package with the corresponding name (and optionally version) is searched
3751for among the GNU distribution modules (@pxref{Package Modules}).
3752
3753Alternatively, the @code{--expression} option may be used to specify a
3754Scheme expression that evaluates to a package; this is useful when
3755disambiguation among several same-named packages or package variants is
3756needed.
c78bd12b
LC
3757
3758The @var{options} may be zero or more of the following:
3759
3760@table @code
3761
34a1783f
DT
3762@item --file=@var{file}
3763@itemx -f @var{file}
3764
3765Build the package or derivation that the code within @var{file}
3766evaluates to.
3767
3768As an example, @var{file} might contain a package definition like this
3769(@pxref{Defining Packages}):
3770
3771@example
3772@verbatiminclude package-hello.scm
3773@end example
3774
c78bd12b
LC
3775@item --expression=@var{expr}
3776@itemx -e @var{expr}
ac5de156 3777Build the package or derivation @var{expr} evaluates to.
c78bd12b 3778
5401dd75 3779For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
3780guile-1.8)}, which unambiguously designates this specific variant of
3781version 1.8 of Guile.
3782
56b82106
LC
3783Alternately, @var{expr} may be a G-expression, in which case it is used
3784as a build program passed to @code{gexp->derivation}
3785(@pxref{G-Expressions}).
3786
3787Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
3788(@pxref{The Store Monad}). The procedure must return a derivation as a
3789monadic value, which is then passed through @code{run-with-store}.
3790
c78bd12b
LC
3791@item --source
3792@itemx -S
3793Build the packages' source derivations, rather than the packages
3794themselves.
3795
e49951eb 3796For instance, @code{guix build -S gcc} returns something like
834129e0 3797@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
c78bd12b 3798
f9cc8971
LC
3799The returned source tarball is the result of applying any patches and
3800code snippets specified in the package's @code{origin} (@pxref{Defining
3801Packages}).
3802
2cdfe13d
EB
3803@item --sources
3804Fetch and return the source of @var{package-or-derivation} and all their
3805dependencies, recursively. This is a handy way to obtain a local copy
3806of all the source code needed to build @var{packages}, allowing you to
3807eventually build them even without network access. It is an extension
3808of the @code{--source} option and can accept one of the following
3809optional argument values:
3810
3811@table @code
3812@item package
3813This value causes the @code{--sources} option to behave in the same way
3814as the @code{--source} option.
3815
3816@item all
3817Build all packages' source derivations, including any source that might
3818be listed as @code{inputs}. This is the default value.
3819
3820@example
3821$ guix build --sources tzdata
3822The following derivations will be built:
3823 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
3824 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
3825@end example
3826
3827@item transitive
3828Build all packages' source derivations, as well as all source
3829derivations for packages' transitive inputs. This can be used e.g. to
3830prefetch package source for later offline building.
3831
3832@example
3833$ guix build --sources=transitive tzdata
3834The following derivations will be built:
3835 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
3836 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
3837 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
3838 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
3839 /gnu/store/@dots{}-make-4.1.tar.xz.drv
3840 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
3841@dots{}
3842@end example
3843
3844@end table
3845
c78bd12b
LC
3846@item --system=@var{system}
3847@itemx -s @var{system}
3848Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
3849the host's system type.
3850
3851An example use of this is on Linux-based systems, which can emulate
3852different personalities. For instance, passing
3853@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
3854to build packages in a complete 32-bit environment.
3855
e55ec43d
LC
3856@item --target=@var{triplet}
3857@cindex cross-compilation
3858Cross-build for @var{triplet}, which must be a valid GNU triplet, such
3859as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
3860configuration triplets,, configure, GNU Configure and Build System}).
3861
7f3673f2
LC
3862@item --with-source=@var{source}
3863Use @var{source} as the source of the corresponding package.
3864@var{source} must be a file name or a URL, as for @command{guix
3865download} (@pxref{Invoking guix download}).
3866
3867The ``corresponding package'' is taken to be one specified on the
3868command line whose name matches the base of @var{source}---e.g., if
3869@var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
3870package is @code{guile}. Likewise, the version string is inferred from
3871@var{source}; in the previous example, it's @code{2.0.10}.
3872
3873This option allows users to try out versions of packages other than the
3874one provided by the distribution. The example below downloads
3875@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
3876the @code{ed} package:
3877
3878@example
3879guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
3880@end example
3881
3882As a developer, @code{--with-source} makes it easy to test release
3883candidates:
3884
3885@example
3886guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
3887@end example
3888
a43b55f1
LC
3889@dots{} or to build from a checkout in a pristine environment:
3890
3891@example
3892$ git clone git://git.sv.gnu.org/guix.git
3893$ guix build guix --with-source=./guix
3894@end example
3895
a8d65643
LC
3896@anchor{build-check}
3897@item --check
3898@cindex determinism, checking
3899@cindex reproducibility, checking
3900Rebuild @var{package-or-derivation}, which are already available in the
3901store, and raise an error if the build results are not bit-for-bit
3902identical.
3903
3904This mechanism allows you to check whether previously-installed
3905substitutes are genuine (@pxref{Substitutes}), or whether a package's
3906build result is deterministic. @xref{Invoking guix challenge}, for more
3907background information and tools.
3908
05962f29
LC
3909@item --no-grafts
3910Do not ``graft'' packages. In practice, this means that package updates
3911available as grafts are not applied. @xref{Security Updates}, for more
3912information on grafts.
7f3673f2 3913
c78bd12b
LC
3914@item --derivations
3915@itemx -d
3916Return the derivation paths, not the output paths, of the given
3917packages.
3918
70ee5642
LC
3919@item --root=@var{file}
3920@itemx -r @var{file}
3921Make @var{file} a symlink to the result, and register it as a garbage
3922collector root.
3923
3924@item --log-file
3f208ad7 3925Return the build log file names or URLs for the given
70ee5642
LC
3926@var{package-or-derivation}s, or raise an error if build logs are
3927missing.
3928
3929This works regardless of how packages or derivations are specified. For
3930instance, the following invocations are equivalent:
3931
3932@example
3933guix build --log-file `guix build -d guile`
3934guix build --log-file `guix build guile`
3935guix build --log-file guile
3936guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
3937@end example
3938
3f208ad7
LC
3939If a log is unavailable locally, and unless @code{--no-substitutes} is
3940passed, the command looks for a corresponding log on one of the
3941substitute servers (as specified with @code{--substitute-urls}.)
70ee5642 3942
3f208ad7
LC
3943So for instance, let's say you want to see the build log of GDB on MIPS
3944but you're actually on an @code{x86_64} machine:
3945
3946@example
3947$ guix build --log-file gdb -s mips64el-linux
3948http://hydra.gnu.org/log/@dots{}-gdb-7.10
3949@end example
3950
3951You can freely access a huge library of build logs!
70ee5642
LC
3952@end table
3953
3954@cindex common build options
3955In addition, a number of options that control the build process are
3956common to @command{guix build} and other commands that can spawn builds,
3957such as @command{guix package} or @command{guix archive}. These are the
3958following:
3959
3960@table @code
3961
300868ba
LC
3962@item --load-path=@var{directory}
3963@itemx -L @var{directory}
3964Add @var{directory} to the front of the package module search path
3965(@pxref{Package Modules}).
3966
3967This allows users to define their own packages and make them visible to
3968the command-line tools.
3969
c78bd12b
LC
3970@item --keep-failed
3971@itemx -K
3972Keep the build tree of failed builds. Thus, if a build fail, its build
3973tree is kept under @file{/tmp}, in a directory whose name is shown at
3974the end of the build log. This is useful when debugging build issues.
3975
f4953019
LC
3976@item --keep-going
3977@itemx -k
3978Keep going when some of the derivations fail to build; return only once
3979all the builds have either completed or failed.
3980
3981The default behavior is to stop as soon as one of the specified
3982derivations has failed.
3983
c78bd12b
LC
3984@item --dry-run
3985@itemx -n
3986Do not build the derivations.
3987
56b1f4b7
LC
3988@item --fallback
3989When substituting a pre-built binary fails, fall back to building
3990packages locally.
3991
f8a8e0fe
LC
3992@item --substitute-urls=@var{urls}
3993@anchor{client-substitute-urls}
3994Consider @var{urls} the whitespace-separated list of substitute source
3995URLs, overriding the default list of URLs of @command{guix-daemon}
3996(@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
3997
3998This means that substitutes may be downloaded from @var{urls}, provided
3999they are signed by a key authorized by the system administrator
4000(@pxref{Substitutes}).
4001
c78bd12b 4002@item --no-substitutes
b5385b52 4003Do not use substitutes for build products. That is, always build things
c4202d60
LC
4004locally instead of allowing downloads of pre-built binaries
4005(@pxref{Substitutes}).
c78bd12b 4006
5b74fe06
LC
4007@item --rounds=@var{n}
4008Build each derivation @var{n} times in a row, and raise an error if
4009consecutive build results are not bit-for-bit identical.
4010
4011This is a useful way to detect non-deterministic builds processes.
4012Non-deterministic build processes are a problem because they make it
4013practically impossible for users to @emph{verify} whether third-party
4014binaries are genuine. @xref{Invoking guix challenge}, for more.
4015
4016Note that, currently, the differing build results are not kept around,
4017so you will have to manually investigate in case of an error---e.g., by
4018stashing one of the build results with @code{guix archive --export},
4019then rebuilding, and finally comparing the two results.
4020
425b0bfc 4021@item --no-build-hook
4ec2e92d
LC
4022Do not attempt to offload builds @i{via} the daemon's ``build hook''
4023(@pxref{Daemon Offload Setup}). That is, always build things locally
4024instead of offloading builds to remote machines.
425b0bfc 4025
969e678e
LC
4026@item --max-silent-time=@var{seconds}
4027When the build or substitution process remains silent for more than
4028@var{seconds}, terminate it and report a build failure.
4029
002622b6
LC
4030@item --timeout=@var{seconds}
4031Likewise, when the build or substitution process lasts for more than
4032@var{seconds}, terminate it and report a build failure.
4033
4034By default there is no timeout. This behavior can be restored with
4035@code{--timeout=0}.
4036
07ab4bf1
LC
4037@item --verbosity=@var{level}
4038Use the given verbosity level. @var{level} must be an integer between 0
4039and 5; higher means more verbose output. Setting a level of 4 or more
4040may be helpful when debugging setup issues with the build daemon.
4041
70ee5642
LC
4042@item --cores=@var{n}
4043@itemx -c @var{n}
4044Allow the use of up to @var{n} CPU cores for the build. The special
4045value @code{0} means to use as many CPU cores as available.
bf421152 4046
f6526eb3
LC
4047@item --max-jobs=@var{n}
4048@itemx -M @var{n}
4049Allow at most @var{n} build jobs in parallel. @xref{Invoking
4050guix-daemon, @code{--max-jobs}}, for details about this option and the
4051equivalent @command{guix-daemon} option.
4052
c78bd12b
LC
4053@end table
4054
e49951eb 4055Behind the scenes, @command{guix build} is essentially an interface to
c78bd12b
LC
4056the @code{package-derivation} procedure of the @code{(guix packages)}
4057module, and to the @code{build-derivations} procedure of the @code{(guix
01d8ac64 4058derivations)} module.
c78bd12b 4059
16eb115e
DP
4060In addition to options explicitly passed on the command line,
4061@command{guix build} and other @command{guix} commands that support
4062building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
4063
4064@defvr {Environment Variable} GUIX_BUILD_OPTIONS
4065Users can define this variable to a list of command line options that
4066will automatically be used by @command{guix build} and other
4067@command{guix} commands that can perform builds, as in the example
4068below:
4069
4070@example
4071$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
4072@end example
4073
847391fe
DP
4074These options are parsed independently, and the result is appended to
4075the parsed command-line options.
16eb115e
DP
4076@end defvr
4077
4078
39bee8a2
LC
4079@node Invoking guix edit
4080@section Invoking @command{guix edit}
4081
4082@cindex package definition, editing
4083So many packages, so many source files! The @command{guix edit} command
4084facilitates the life of packagers by pointing their editor at the source
4085file containing the definition of the specified packages. For instance:
4086
4087@example
4088guix edit gcc-4.8 vim
4089@end example
4090
4091@noindent
6237b9fa
LC
4092launches the program specified in the @code{VISUAL} or in the
4093@code{EDITOR} environment variable to edit the recipe of GCC@tie{}4.8.4
4094and that of Vim.
39bee8a2
LC
4095
4096If you are using Emacs, note that the Emacs user interface provides
6248e326
AK
4097similar functionality in the ``package info'' and ``package list''
4098buffers created by @kbd{M-x guix-search-by-name} and similar commands
4099(@pxref{Emacs Commands}).
39bee8a2
LC
4100
4101
210cc920
LC
4102@node Invoking guix download
4103@section Invoking @command{guix download}
4104
4105When writing a package definition, developers typically need to download
4106the package's source tarball, compute its SHA256 hash, and write that
4107hash in the package definition (@pxref{Defining Packages}). The
4108@command{guix download} tool helps with this task: it downloads a file
4109from the given URI, adds it to the store, and prints both its file name
4110in the store and its SHA256 hash.
4111
4112The fact that the downloaded file is added to the store saves bandwidth:
4113when the developer eventually tries to build the newly defined package
4114with @command{guix build}, the source tarball will not have to be
4115downloaded again because it is already in the store. It is also a
4116convenient way to temporarily stash files, which may be deleted
4117eventually (@pxref{Invoking guix gc}).
4118
4119The @command{guix download} command supports the same URIs as used in
4120package definitions. In particular, it supports @code{mirror://} URIs.
4121@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
4122Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
4123they are not available, an error is raised. @xref{Guile Preparations,
4124how to install the GnuTLS bindings for Guile,, gnutls-guile,
4125GnuTLS-Guile}, for more information.
210cc920
LC
4126
4127The following option is available:
4128
4129@table @code
4130@item --format=@var{fmt}
4131@itemx -f @var{fmt}
4132Write the hash in the format specified by @var{fmt}. For more
081145cf 4133information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
210cc920
LC
4134@end table
4135
6c365eca
NK
4136@node Invoking guix hash
4137@section Invoking @command{guix hash}
4138
210cc920 4139The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
4140It is primarily a convenience tool for anyone contributing to the
4141distribution: it computes the cryptographic hash of a file, which can be
4142used in the definition of a package (@pxref{Defining Packages}).
4143
4144The general syntax is:
4145
4146@example
4147guix hash @var{option} @var{file}
4148@end example
4149
4150@command{guix hash} has the following option:
4151
4152@table @code
4153
4154@item --format=@var{fmt}
4155@itemx -f @var{fmt}
210cc920 4156Write the hash in the format specified by @var{fmt}.
6c365eca
NK
4157
4158Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4159(@code{hex} and @code{hexadecimal} can be used as well).
4160
4161If the @option{--format} option is not specified, @command{guix hash}
4162will output the hash in @code{nix-base32}. This representation is used
4163in the definitions of packages.
4164
3140f2df
LC
4165@item --recursive
4166@itemx -r
4167Compute the hash on @var{file} recursively.
4168
4169In this case, the hash is computed on an archive containing @var{file},
4170including its children if it is a directory. Some of @var{file}'s
4171meta-data is part of the archive; for instance, when @var{file} is a
4172regular file, the hash is different depending on whether @var{file} is
4173executable or not. Meta-data such as time stamps has no impact on the
4174hash (@pxref{Invoking guix archive}).
4175@c FIXME: Replace xref above with xref to an ``Archive'' section when
4176@c it exists.
4177
6c365eca
NK
4178@end table
4179
2f7d2d91
LC
4180@node Invoking guix import
4181@section Invoking @command{guix import}
4182
4183@cindex importing packages
4184@cindex package import
4185@cindex package conversion
4186The @command{guix import} command is useful for people willing to add a
4187package to the distribution but who'd rather do as little work as
4188possible to get there---a legitimate demand. The command knows of a few
4189repositories from which it can ``import'' package meta-data. The result
4190is a package definition, or a template thereof, in the format we know
4191(@pxref{Defining Packages}).
4192
4193The general syntax is:
4194
4195@example
4196guix import @var{importer} @var{options}@dots{}
4197@end example
4198
4199@var{importer} specifies the source from which to import package
4200meta-data, and @var{options} specifies a package identifier and other
4201options specific to @var{importer}. Currently, the available
4202``importers'' are:
4203
4204@table @code
4205@item gnu
4206Import meta-data for the given GNU package. This provides a template
4207for the latest version of that GNU package, including the hash of its
4208source tarball, and its canonical synopsis and description.
4209
4210Additional information such as the package's dependencies and its
4211license needs to be figured out manually.
4212
4213For example, the following command returns a package definition for
4214GNU@tie{}Hello:
4215
4216@example
4217guix import gnu hello
4218@end example
4219
4220Specific command-line options are:
4221
4222@table @code
4223@item --key-download=@var{policy}
4224As for @code{guix refresh}, specify the policy to handle missing OpenPGP
4225keys when verifying the package's signature. @xref{Invoking guix
4226refresh, @code{--key-download}}.
4227@end table
4228
4229@item pypi
4230@cindex pypi
4231Import meta-data from the @uref{https://pypi.python.org/, Python Package
4232Index}@footnote{This functionality requires Guile-JSON to be installed.
4233@xref{Requirements}.}. Information is taken from the JSON-formatted
4234description available at @code{pypi.python.org} and usually includes all
4235the relevant information, including package dependencies.
4236
4237The command below imports meta-data for the @code{itsdangerous} Python
4238package:
4239
4240@example
4241guix import pypi itsdangerous
4242@end example
4243
3aae8145
DT
4244@item gem
4245@cindex gem
4246Import meta-data from @uref{https://rubygems.org/,
4247RubyGems}@footnote{This functionality requires Guile-JSON to be
4248installed. @xref{Requirements}.}. Information is taken from the
4249JSON-formatted description available at @code{rubygems.org} and includes
4250most relevant information, including runtime dependencies. There are
4251some caveats, however. The meta-data doesn't distinguish between
4252synopses and descriptions, so the same string is used for both fields.
4253Additionally, the details of non-Ruby dependencies required to build
4254native extensions is unavailable and left as an exercise to the
4255packager.
4256
4257The command below imports meta-data for the @code{rails} Ruby package:
4258
4259@example
4260guix import gem rails
4261@end example
4262
d45dc6da
EB
4263@item cpan
4264@cindex CPAN
4265Import meta-data from @uref{https://www.metacpan.org/, MetaCPAN}.
4266Information is taken from the JSON-formatted meta-data provided through
4267@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
4268relevant information, such as module dependencies. License information
4269should be checked closely. If Perl is available in the store, then the
4270@code{corelist} utility will be used to filter core modules out of the
4271list of dependencies.
d45dc6da
EB
4272
4273The command command below imports meta-data for the @code{Acme::Boolean}
4274Perl module:
4275
4276@example
4277guix import cpan Acme::Boolean
4278@end example
4279
e1248602
RW
4280@item cran
4281@cindex CRAN
d0bd632f 4282@cindex Bioconductor
e1248602
RW
4283Import meta-data from @uref{http://cran.r-project.org/, CRAN}, the
4284central repository for the @uref{http://r-project.org, GNU@tie{}R
4285statistical and graphical environment}.
4286
d0bd632f 4287Information is extracted from the package's @code{DESCRIPTION} file.
e1248602
RW
4288
4289The command command below imports meta-data for the @code{Cairo}
4290R package:
4291
4292@example
4293guix import cran Cairo
4294@end example
4295
d0bd632f
RW
4296When @code{--archive=bioconductor} is added, meta-data is imported from
4297@uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
4298packages for for the analysis and comprehension of high-throughput
4299genomic data in bioinformatics.
4300
4301Information is extracted from a package's @code{DESCRIPTION} file
4302published on the web interface of the Bioconductor SVN repository.
4303
4304The command command below imports meta-data for the @code{GenomicRanges}
4305R package:
4306
4307@example
4308guix import cran --archive=bioconductor GenomicRanges
4309@end example
4310
2f7d2d91
LC
4311@item nix
4312Import meta-data from a local copy of the source of the
4313@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
4314relies on the @command{nix-instantiate} command of
4315@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
4316typically written in a mixture of Nix-language and Bash code. This
4317command only imports the high-level package structure that is written in
4318the Nix language. It normally includes all the basic fields of a
4319package definition.
4320
4321When importing a GNU package, the synopsis and descriptions are replaced
4322by their canonical upstream variant.
4323
961d0d2d
LC
4324Usually, you will first need to do:
4325
4326@example
4327export NIX_REMOTE=daemon
4328@end example
4329
4330@noindent
4331so that @command{nix-instantiate} does not try to open the Nix database.
4332
2f7d2d91
LC
4333As an example, the command below imports the package definition of
4334LibreOffice (more precisely, it imports the definition of the package
4335bound to the @code{libreoffice} top-level attribute):
4336
4337@example
4338guix import nix ~/path/to/nixpkgs libreoffice
4339@end example
863af4e1
FB
4340
4341@item hackage
4342@cindex hackage
4343Import meta-data from Haskell community's central package archive
4344@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4345Cabal files and includes all the relevant information, including package
4346dependencies.
4347
4348Specific command-line options are:
4349
4350@table @code
a4154748
FB
4351@item --stdin
4352@itemx -s
4353Read a Cabal file from the standard input.
863af4e1
FB
4354@item --no-test-dependencies
4355@itemx -t
a4154748
FB
4356Do not include dependencies required by the test suites only.
4357@item --cabal-environment=@var{alist}
4358@itemx -e @var{alist}
4359@var{alist} is a Scheme alist defining the environment in which the
4360Cabal conditionals are evaluated. The accepted keys are: @code{os},
4361@code{arch}, @code{impl} and a string representing the name of a flag.
4362The value associated with a flag has to be either the symbol
4363@code{true} or @code{false}. The value associated with other keys
4364has to conform to the Cabal file format definition. The default value
4365associated with the keys @code{os}, @code{arch} and @code{impl} is
4366@samp{linux}, @samp{x86_64} and @samp{ghc} respectively.
863af4e1
FB
4367@end table
4368
4369The command below imports meta-data for the latest version of the
a4154748
FB
4370@code{HTTP} Haskell package without including test dependencies and
4371specifying the value of the flag @samp{network-uri} as @code{false}:
863af4e1
FB
4372
4373@example
a4154748 4374guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
863af4e1
FB
4375@end example
4376
4377A specific package version may optionally be specified by following the
4378package name by a hyphen and a version number as in the following example:
4379
4380@example
4381guix import hackage mtl-2.1.3.1
4382@end example
7f74a931
FB
4383
4384@item elpa
4385@cindex elpa
4386Import meta-data from an Emacs Lisp Package Archive (ELPA) package
4387repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4388
4389Specific command-line options are:
4390
4391@table @code
4392@item --archive=@var{repo}
4393@itemx -a @var{repo}
4394@var{repo} identifies the archive repository from which to retrieve the
4395information. Currently the supported repositories and their identifiers
4396are:
4397@itemize -
4398@item
840bd1d3 4399@uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7f74a931
FB
4400identifier. This is the default.
4401
4402@item
840bd1d3 4403@uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7f74a931
FB
4404@code{melpa-stable} identifier.
4405
4406@item
840bd1d3 4407@uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7f74a931
FB
4408identifier.
4409@end itemize
4410@end table
2f7d2d91
LC
4411@end table
4412
4413The structure of the @command{guix import} code is modular. It would be
4414useful to have more importers for other package formats, and your help
4415is welcome here (@pxref{Contributing}).
4416
37166310
LC
4417@node Invoking guix refresh
4418@section Invoking @command{guix refresh}
4419
4420The primary audience of the @command{guix refresh} command is developers
4421of the GNU software distribution. By default, it reports any packages
4422provided by the distribution that are outdated compared to the latest
4423upstream version, like this:
4424
4425@example
4426$ guix refresh
4427gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
4428gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
4429@end example
4430
4431It does so by browsing each package's FTP directory and determining the
bcb571cb
LC
4432highest version number of the source tarballs therein. The command
4433knows how to update specific types of packages: GNU packages, ELPA
4434packages, etc.---see the documentation for @option{--type} below. The
4435are many packages, though, for which it lacks a method to determine
4436whether a new upstream release is available. However, the mechanism is
4437extensible, so feel free to get in touch with us to add a new method!
37166310
LC
4438
4439When passed @code{--update}, it modifies distribution source files to
4440update the version numbers and source tarball hashes of those packages'
4441recipes (@pxref{Defining Packages}). This is achieved by downloading
4442each package's latest source tarball and its associated OpenPGP
4443signature, authenticating the downloaded tarball against its signature
4444using @command{gpg}, and finally computing its hash. When the public
4445key used to sign the tarball is missing from the user's keyring, an
4446attempt is made to automatically retrieve it from a public key server;
4447when it's successful, the key is added to the user's keyring; otherwise,
4448@command{guix refresh} reports an error.
4449
4450The following options are supported:
4451
4452@table @code
4453
2d7fc7da
LC
4454@item --expression=@var{expr}
4455@itemx -e @var{expr}
4456Consider the package @var{expr} evaluates to.
4457
4458This is useful to precisely refer to a package, as in this example:
4459
4460@example
4461guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
4462@end example
4463
4464This command lists the dependents of the ``final'' libc (essentially all
4465the packages.)
4466
37166310
LC
4467@item --update
4468@itemx -u
38e16b49
LC
4469Update distribution source files (package recipes) in place. This is
4470usually run from a checkout of the Guix source tree (@pxref{Running
4471Guix Before It Is Installed}):
4472
4473@example
4474$ ./pre-inst-env guix refresh -s non-core
4475@end example
4476
081145cf 4477@xref{Defining Packages}, for more information on package definitions.
37166310
LC
4478
4479@item --select=[@var{subset}]
4480@itemx -s @var{subset}
4481Select all the packages in @var{subset}, one of @code{core} or
4482@code{non-core}.
4483
4484The @code{core} subset refers to all the packages at the core of the
4485distribution---i.e., packages that are used to build ``everything
4486else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
4487changing one of these packages in the distribution entails a rebuild of
4488all the others. Thus, such updates are an inconvenience to users in
4489terms of build time or bandwidth used to achieve the upgrade.
4490
4491The @code{non-core} subset refers to the remaining packages. It is
4492typically useful in cases where an update of the core packages would be
4493inconvenient.
4494
bcb571cb
LC
4495@item --type=@var{updater}
4496@itemx -t @var{updater}
7191adc5
AK
4497Select only packages handled by @var{updater} (may be a comma-separated
4498list of updaters). Currently, @var{updater} may be one of:
bcb571cb
LC
4499
4500@table @code
4501@item gnu
4502the updater for GNU packages;
e80c0f85
LC
4503@item gnome
4504the updater for GNOME packages;
bcb571cb 4505@item elpa
d882c235
LC
4506the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
4507@item cran
b9d044ef 4508the updater for @uref{http://cran.r-project.org/, CRAN} packages;
d0bd632f
RW
4509@item bioconductor
4510the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
bab020d7 4511@item pypi
b9d044ef 4512the updater for @uref{https://pypi.python.org, PyPI} packages.
bcb571cb
LC
4513@end table
4514
4515For instance, the following commands only checks for updates of Emacs
d882c235 4516packages hosted at @code{elpa.gnu.org} and updates of CRAN packages:
bcb571cb
LC
4517
4518@example
7191adc5 4519$ guix refresh --type=elpa,cran
d882c235 4520gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
bcb571cb
LC
4521gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
4522@end example
4523
37166310
LC
4524@end table
4525
4526In addition, @command{guix refresh} can be passed one or more package
4527names, as in this example:
4528
4529@example
38e16b49 4530$ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
37166310
LC
4531@end example
4532
4533@noindent
4534The command above specifically updates the @code{emacs} and
4535@code{idutils} packages. The @code{--select} option would have no
4536effect in this case.
4537
7d193ec3
EB
4538When considering whether to upgrade a package, it is sometimes
4539convenient to know which packages would be affected by the upgrade and
4540should be checked for compatibility. For this the following option may
4541be used when passing @command{guix refresh} one or more package names:
4542
4543@table @code
4544
6ffa706b
AK
4545@item --list-updaters
4546@itemx -L
4547List available updaters and exit (see @option{--type} above.)
4548
7d193ec3
EB
4549@item --list-dependent
4550@itemx -l
4551List top-level dependent packages that would need to be rebuilt as a
4552result of upgrading one or more packages.
4553
4554@end table
4555
4556Be aware that the @code{--list-dependent} option only
4557@emph{approximates} the rebuilds that would be required as a result of
4558an upgrade. More rebuilds might be required under some circumstances.
4559
4560@example
7779ab61
LC
4561$ guix refresh --list-dependent flex
4562Building the following 120 packages would ensure 213 dependent packages are rebuilt:
4563hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
4564@end example
4565
4566The command above lists a set of packages that could be built to check
4567for compatibility with an upgraded @code{flex} package.
4568
f9230085
LC
4569The following options can be used to customize GnuPG operation:
4570
4571@table @code
4572
f9230085
LC
4573@item --gpg=@var{command}
4574Use @var{command} as the GnuPG 2.x command. @var{command} is searched
4575for in @code{$PATH}.
4576
2bc53ba9
LC
4577@item --key-download=@var{policy}
4578Handle missing OpenPGP keys according to @var{policy}, which may be one
4579of:
4580
4581@table @code
4582@item always
4583Always download missing OpenPGP keys from the key server, and add them
4584to the user's GnuPG keyring.
4585
4586@item never
4587Never try to download missing OpenPGP keys. Instead just bail out.
4588
4589@item interactive
4590When a package signed with an unknown OpenPGP key is encountered, ask
4591the user whether to download it or not. This is the default behavior.
4592@end table
4593
4594@item --key-server=@var{host}
4595Use @var{host} as the OpenPGP key server when importing a public key.
4596
f9230085
LC
4597@end table
4598
b4f5e0e8
CR
4599@node Invoking guix lint
4600@section Invoking @command{guix lint}
4601The @command{guix lint} is meant to help package developers avoid common
873c4085
LC
4602errors and use a consistent style. It runs a number of checks on a
4603given set of packages in order to find common mistakes in their
4604definitions. Available @dfn{checkers} include (see
4605@code{--list-checkers} for a complete list):
4606
4607@table @code
4608@item synopsis
4609@itemx description
4610Validate certain typographical and stylistic rules about package
4611descriptions and synopses.
4612
4613@item inputs-should-be-native
4614Identify inputs that should most likely be native inputs.
4615
4616@item source
4617@itemx home-page
50f5c46d 4618@itemx source-file-name
873c4085 4619Probe @code{home-page} and @code{source} URLs and report those that are
50f5c46d
EB
4620invalid. Check that the source file name is meaningful, e.g. is not
4621just a version number or ``git-checkout'', and should not have a
4622@code{file-name} declared (@pxref{origin Reference}).
40a7d4e5 4623
5432734b
LC
4624@item cve
4625Report known vulnerabilities found in the Common Vulnerabilities and
4626Exposures (CVE) database
4627@uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
4628NIST}.
4629
40a7d4e5
LC
4630@item formatting
4631Warn about obvious source code formatting issues: trailing white space,
4632use of tabulations, etc.
873c4085 4633@end table
b4f5e0e8
CR
4634
4635The general syntax is:
4636
4637@example
4638guix lint @var{options} @var{package}@dots{}
4639@end example
4640
4641If no package is given on the command line, then all packages are checked.
4642The @var{options} may be zero or more of the following:
4643
4644@table @code
4645
dd7c013d
CR
4646@item --checkers
4647@itemx -c
4648Only enable the checkers specified in a comma-separated list using the
4649names returned by @code{--list-checkers}.
4650
b4f5e0e8
CR
4651@item --list-checkers
4652@itemx -l
4653List and describe all the available checkers that will be run on packages
4654and exit.
4655
4656@end table
37166310 4657
fcc58db6
LC
4658@node Invoking guix size
4659@section Invoking @command{guix size}
4660
4661The @command{guix size} command helps package developers profile the
4662disk usage of packages. It is easy to overlook the impact of an
4663additional dependency added to a package, or the impact of using a
4664single output for a package that could easily be split (@pxref{Packages
4665with Multiple Outputs}). These are the typical issues that
4666@command{guix size} can highlight.
4667
4668The command can be passed a package specification such as @code{gcc-4.8}
4669or @code{guile:debug}, or a file name in the store. Consider this
4670example:
4671
4672@example
4673$ guix size coreutils
4674store item total self
4675/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
4676/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
4677/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
4678/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
4679/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
4680/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
4681@end example
4682
4683@cindex closure
4684The store items listed here constitute the @dfn{transitive closure} of
4685Coreutils---i.e., Coreutils and all its dependencies, recursively---as
4686would be returned by:
4687
4688@example
4689$ guix gc -R /gnu/store/@dots{}-coreutils-8.23
4690@end example
4691
4692Here the output shows 3 columns next to store items. The first column,
4693labeled ``total'', shows the size in mebibytes (MiB) of the closure of
4694the store item---that is, its own size plus the size of all its
4695dependencies. The next column, labeled ``self'', shows the size of the
4696item itself. The last column shows the ratio of the item's size to the
4697space occupied by all the items listed here.
4698
4699In this example, we see that the closure of Coreutils weighs in at
470070@tie{}MiB, half of which is taken by libc. (That libc represents a
4701large fraction of the closure is not a problem @i{per se} because it is
4702always available on the system anyway.)
4703
4704When the package passed to @command{guix size} is available in the
4705store, @command{guix size} queries the daemon to determine its
4706dependencies, and measures its size in the store, similar to @command{du
4707-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
4708Coreutils}).
4709
4710When the given package is @emph{not} in the store, @command{guix size}
4711reports information based on information about the available substitutes
4712(@pxref{Substitutes}). This allows it to profile disk usage of store
4713items that are not even on disk, only available remotely.
4714
a8f996c6 4715The available options are:
fcc58db6
LC
4716
4717@table @option
4718
d490d06e
LC
4719@item --substitute-urls=@var{urls}
4720Use substitute information from @var{urls}.
4721@xref{client-substitute-urls, the same option for @code{guix build}}.
4722
a8f996c6
LC
4723@item --map-file=@var{file}
4724Write to @var{file} a graphical map of disk usage as a PNG file.
4725
4726For the example above, the map looks like this:
4727
4728@image{images/coreutils-size-map,5in,, map of Coreutils disk usage
4729produced by @command{guix size}}
4730
4731This option requires that
4732@uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
4733installed and visible in Guile's module search path. When that is not
4734the case, @command{guix size} fails as it tries to load it.
4735
fcc58db6
LC
4736@item --system=@var{system}
4737@itemx -s @var{system}
4738Consider packages for @var{system}---e.g., @code{x86_64-linux}.
4739
4740@end table
4741
88856916
LC
4742@node Invoking guix graph
4743@section Invoking @command{guix graph}
4744
4745@cindex DAG
4746Packages and their dependencies form a @dfn{graph}, specifically a
4747directed acyclic graph (DAG). It can quickly become difficult to have a
4748mental model of the package DAG, so the @command{guix graph} command is
4749here to provide a visual representation of the DAG. @command{guix
4750graph} emits a DAG representation in the input format of
4751@uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
4752directly to Graphviz's @command{dot} command, for instance. The general
4753syntax is:
4754
4755@example
4756guix graph @var{options} @var{package}@dots{}
4757@end example
4758
4759For example, the following command generates a PDF file representing the
4760package DAG for the GNU@tie{}Core Utilities, showing its build-time
4761dependencies:
4762
4763@example
4764guix graph coreutils | dot -Tpdf > dag.pdf
4765@end example
4766
4767The output looks like this:
4768
4769@image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
4770
4771Nice little graph, no?
4772
4773But there's more than one graph! The one above is concise: it's the
4774graph of package objects, omitting implicit inputs such as GCC, libc,
4775grep, etc. It's often useful to have such a concise graph, but
4776sometimes you want to see more details. @command{guix graph} supports
4777several types of graphs, allowing you to choose the level of details:
4778
4779@table @code
4780@item package
4781This is the default type, the one we used above. It shows the DAG of
4782package objects, excluding implicit dependencies. It is concise, but
4783filters out many details.
4784
4785@item bag-emerged
4786This is the package DAG, @emph{including} implicit inputs.
4787
4788For instance, the following command:
4789
4790@example
4791guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
4792@end example
4793
4794... yields this bigger graph:
4795
4796@image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
4797
4798At the bottom of the graph, we see all the implicit inputs of
4799@var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
4800
4801Now, note that the dependencies of those implicit inputs---that is, the
4802@dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
4803here, for conciseness.
4804
4805@item bag
4806Similar to @code{bag-emerged}, but this time including all the bootstrap
4807dependencies.
4808
38b92daa
LC
4809@item bag-with-origins
4810Similar to @code{bag}, but also showing origins and their dependencies.
4811
88856916
LC
4812@item derivations
4813This is the most detailed representation: It shows the DAG of
4814derivations (@pxref{Derivations}) and plain store items. Compared to
4815the above representation, many additional nodes are visible, including
4816builds scripts, patches, Guile modules, etc.
4817
4818@end table
4819
4820All the above types correspond to @emph{build-time dependencies}. The
4821following graph type represents the @emph{run-time dependencies}:
4822
4823@table @code
4824@item references
4825This is the graph of @dfn{references} of a package output, as returned
4826by @command{guix gc --references} (@pxref{Invoking guix gc}).
4827
4828If the given package output is not available in the store, @command{guix
4829graph} attempts to obtain dependency information from substitutes.
4830@end table
4831
4832The available options are the following:
4833
4834@table @option
4835@item --type=@var{type}
4836@itemx -t @var{type}
4837Produce a graph output of @var{type}, where @var{type} must be one of
4838the values listed above.
4839
4840@item --list-types
4841List the supported graph types.
4c8f997a
LC
4842
4843@item --expression=@var{expr}
4844@itemx -e @var{expr}
4845Consider the package @var{expr} evaluates to.
4846
4847This is useful to precisely refer to a package, as in this example:
4848
4849@example
4850guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
4851@end example
88856916
LC
4852@end table
4853
4854
372c4bbc
DT
4855@node Invoking guix environment
4856@section Invoking @command{guix environment}
4857
f5fd4fd2 4858@cindex reproducible build environments
fe36d84e 4859@cindex development environments
372c4bbc
DT
4860The purpose of @command{guix environment} is to assist hackers in
4861creating reproducible development environments without polluting their
4862package profile. The @command{guix environment} tool takes one or more
4863packages, builds all of the necessary inputs, and creates a shell
4864environment to use them.
4865
4866The general syntax is:
4867
4868@example
4869guix environment @var{options} @var{package}@dots{}
4870@end example
4871
fe36d84e
LC
4872The following example spawns a new shell set up for the development of
4873GNU@tie{}Guile:
372c4bbc
DT
4874
4875@example
4876guix environment guile
4877@end example
4878
4879If the specified packages are not built yet, @command{guix environment}
4880automatically builds them. The new shell's environment is an augmented
4881version of the environment that @command{guix environment} was run in.
4882It contains the necessary search paths for building the given package
4883added to the existing environment variables. To create a ``pure''
4884environment in which the original environment variables have been unset,
50500f7c
LC
4885use the @code{--pure} option@footnote{Users sometimes wrongfully augment
4886environment variables such as @code{PATH} in their @file{~/.bashrc}
4887file. As a consequence, when @code{guix environment} launches it, Bash
4888may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
4889environment variables. It is an error to define such environment
4890variables in @file{.bashrc}; instead, they should be defined in
4891@file{.bash_profile}, which is sourced only by log-in shells.
4892@xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
4893details on Bash start-up files.}.
372c4bbc 4894
28de8d25
LC
4895@vindex GUIX_ENVIRONMENT
4896@command{guix environment} defines the @code{GUIX_ENVIRONMENT}
4897variable in the shell it spaws. This allows users to, say, define a
4898specific prompt for development environments in their @file{.bashrc}
4899(@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
4900
4901@example
4902if [ -n "$GUIX_ENVIRONMENT" ]
4903then
4904 export PS1="\u@@\h \w [dev]\$ "
4905fi
4906@end example
4907
372c4bbc
DT
4908Additionally, more than one package may be specified, in which case the
4909union of the inputs for the given packages are used. For example, the
4910command below spawns a shell where all of the dependencies of both Guile
4911and Emacs are available:
4912
4913@example
4914guix environment guile emacs
4915@end example
4916
1de2fe95
DT
4917Sometimes an interactive shell session is not desired. An arbitrary
4918command may be invoked by placing the @code{--} token to separate the
4919command from the rest of the arguments:
372c4bbc
DT
4920
4921@example
1de2fe95 4922guix environment guile -- make -j4
372c4bbc
DT
4923@end example
4924
fe36d84e
LC
4925In other situations, it is more convenient to specify the list of
4926packages needed in the environment. For example, the following command
4927runs @command{python} from an environment containing Python@tie{}2.7 and
4928NumPy:
4929
4930@example
1de2fe95 4931guix environment --ad-hoc python2-numpy python-2.7 -- python
fe36d84e
LC
4932@end example
4933
cc90fbbf
DT
4934Furthermore, one might want the dependencies of a package and also some
4935additional packages that are not build-time or runtime dependencies, but
4936are useful when developing nonetheless. Because of this, the
4937@code{--ad-hoc} flag is positional. Packages appearing before
4938@code{--ad-hoc} are interpreted as packages whose dependencies will be
4939added to the environment. Packages appearing after are interpreted as
4940packages that will be added to the environment directly. For example,
4941the following command creates a Guix development environment that
4942additionally includes Git and strace:
4943
4944@example
4945guix environment guix --ad-hoc git strace
4946@end example
4947
f535dcbe
DT
4948Sometimes it is desirable to isolate the environment as much as
4949possible, for maximal purity and reproducibility. In particular, when
4950using Guix on a host distro that is not GuixSD, it is desirable to
4951prevent access to @file{/usr/bin} and other system-wide resources from
4952the development environment. For example, the following command spawns
4953a Guile REPL in a ``container'' where only the store and the current
4954working directory are mounted:
4955
4956@example
4957guix environment --ad-hoc --container guile -- guile
4958@end example
4959
0f252e26 4960@quotation Note
cfd35b4e 4961The @code{--container} option requires Linux-libre 3.19 or newer.
0f252e26
DT
4962@end quotation
4963
fe36d84e 4964The available options are summarized below.
372c4bbc
DT
4965
4966@table @code
4967@item --expression=@var{expr}
4968@itemx -e @var{expr}
c9c282ce
DT
4969Create an environment for the package or list of packages that
4970@var{expr} evaluates to.
372c4bbc 4971
fe36d84e
LC
4972For example, running:
4973
4974@example
4975guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
4976@end example
4977
4978starts a shell with the environment for this specific variant of the
4979PETSc package.
4980
c9c282ce
DT
4981Running:
4982
4983@example
5c2b2f00 4984guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
c9c282ce
DT
4985@end example
4986
4987starts a shell with all the GuixSD base packages available.
4988
372c4bbc
DT
4989@item --load=@var{file}
4990@itemx -l @var{file}
c9c282ce
DT
4991Create an environment for the package or list of packages that the code
4992within @var{file} evaluates to.
372c4bbc 4993
fe36d84e
LC
4994As an example, @var{file} might contain a definition like this
4995(@pxref{Defining Packages}):
4996
4997@example
4998@verbatiminclude environment-gdb.scm
4999@end example
5000
a54bd6d7
DT
5001@item --ad-hoc
5002Include all specified packages in the resulting environment, as if an
5003@i{ad hoc} package were defined with them as inputs. This option is
5004useful for quickly creating an environment without having to write a
5005package expression to contain the desired inputs.
5006
5007For instance, the command:
5008
5009@example
1de2fe95 5010guix environment --ad-hoc guile guile-sdl -- guile
a54bd6d7
DT
5011@end example
5012
5013runs @command{guile} in an environment where Guile and Guile-SDL are
5014available.
5015
417c39f1
LC
5016Note that this example implicitly asks for the default output of
5017@code{guile} and @code{guile-sdl} but it is possible to ask for a
5018specific output---e.g., @code{glib:bin} asks for the @code{bin} output
5019of @code{glib} (@pxref{Packages with Multiple Outputs}).
5020
cc90fbbf
DT
5021This option may be composed with the default behavior of @command{guix
5022environment}. Packages appearing before @code{--ad-hoc} are interpreted
5023as packages whose dependencies will be added to the environment, the
5024default behavior. Packages appearing after are interpreted as packages
5025that will be added to the environment directly.
5026
372c4bbc
DT
5027@item --pure
5028Unset existing environment variables when building the new environment.
5029This has the effect of creating an environment in which search paths
5030only contain package inputs.
5031
5032@item --search-paths
5033Display the environment variable definitions that make up the
5034environment.
ce367ef3
LC
5035
5036@item --system=@var{system}
5037@itemx -s @var{system}
5038Attempt to build for @var{system}---e.g., @code{i686-linux}.
f535dcbe
DT
5039
5040@item --container
5041@itemx -C
5042@cindex container
5043Run @var{command} within an isolated container. The current working
56b6befb 5044directory outside the container is mapped inside the
f535dcbe
DT
5045container. Additionally, the spawned process runs as the current user
5046outside the container, but has root privileges in the context of the
5047container.
5048
5049@item --network
5050@itemx -N
5051For containers, share the network namespace with the host system.
5052Containers created without this flag only have access to the loopback
5053device.
5054
5055@item --expose=@var{source}[=@var{target}]
5056For containers, expose the file system @var{source} from the host system
5057as the read-only file system @var{target} within the container. If
5058@var{target} is not specified, @var{source} is used as the target mount
5059point in the container.
5060
5061The example below spawns a Guile REPL in a container in which the user's
5062home directory is accessible read-only via the @file{/exchange}
5063directory:
5064
5065@example
5066guix environment --container --expose=$HOME=/exchange guile -- guile
5067@end example
5068
5c2b2f00 5069@item --share=@var{source}[=@var{target}]
f535dcbe
DT
5070For containers, share the file system @var{source} from the host system
5071as the writable file system @var{target} within the container. If
5072@var{target} is not specified, @var{source} is used as the target mount
5073point in the container.
5074
5075The example below spawns a Guile REPL in a container in which the user's
5076home directory is accessible for both reading and writing via the
5077@file{/exchange} directory:
5078
5079@example
5080guix environment --container --share=$HOME=/exchange guile -- guile
5081@end example
372c4bbc
DT
5082@end table
5083
5084It also supports all of the common build options that @command{guix
5085build} supports (@pxref{Invoking guix build, common build options}).
5086
aff8ce7c
DT
5087@node Invoking guix publish
5088@section Invoking @command{guix publish}
5089
5090The purpose of @command{guix publish} is to enable users to easily share
8ce229fc
LC
5091their store with others, which can then use it as a substitute server
5092(@pxref{Substitutes}).
5093
5094When @command{guix publish} runs, it spawns an HTTP server which allows
5095anyone with network access to obtain substitutes from it. This means
5096that any machine running Guix can also act as if it were a build farm,
5097since the HTTP interface is compatible with Hydra, the software behind
5098the @code{hydra.gnu.org} build farm.
aff8ce7c
DT
5099
5100For security, each substitute is signed, allowing recipients to check
5101their authenticity and integrity (@pxref{Substitutes}). Because
5102@command{guix publish} uses the system's signing key, which is only
5463fe51
LC
5103readable by the system administrator, it must be started as root; the
5104@code{--user} option makes it drop root privileges early on.
aff8ce7c 5105
b18812b6
LC
5106The signing key pair must be generated before @command{guix publish} is
5107launched, using @command{guix archive --generate-key} (@pxref{Invoking
5108guix archive}).
5109
aff8ce7c
DT
5110The general syntax is:
5111
5112@example
5113guix publish @var{options}@dots{}
5114@end example
5115
5116Running @command{guix publish} without any additional arguments will
5117spawn an HTTP server on port 8080:
5118
5119@example
5120guix publish
5121@end example
5122
5123Once a publishing server has been authorized (@pxref{Invoking guix
5124archive}), the daemon may download substitutes from it:
5125
5126@example
5127guix-daemon --substitute-urls=http://example.org:8080
5128@end example
5129
5130The following options are available:
5131
5132@table @code
5133@item --port=@var{port}
5134@itemx -p @var{port}
5135Listen for HTTP requests on @var{port}.
5136
9e2292ef
LC
5137@item --listen=@var{host}
5138Listen on the network interface for @var{host}. The default is to
5139accept connections from any interface.
5140
5463fe51
LC
5141@item --user=@var{user}
5142@itemx -u @var{user}
5143Change privileges to @var{user} as soon as possible---i.e., once the
5144server socket is open and the signing key has been read.
5145
aff8ce7c
DT
5146@item --repl[=@var{port}]
5147@itemx -r [@var{port}]
5148Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8ce229fc
LC
5149Reference Manual}) on @var{port} (37146 by default). This is used
5150primarily for debugging a running @command{guix publish} server.
aff8ce7c
DT
5151@end table
5152
1c52181f
LC
5153Enabling @command{guix publish} on a GuixSD system is a one-liner: just
5154add a call to @code{guix-publish-service} in the @code{services} field
5155of the @code{operating-system} declaration (@pxref{guix-publish-service,
5156@code{guix-publish-service}}).
5157
d23c20f1
LC
5158
5159@node Invoking guix challenge
5160@section Invoking @command{guix challenge}
5161
5162@cindex reproducible builds
5163@cindex verifiable builds
5164
5165Do the binaries provided by this server really correspond to the source
5166code it claims to build? Is this package's build process deterministic?
5167These are the questions the @command{guix challenge} command attempts to
5168answer.
5169
5170The former is obviously an important question: Before using a substitute
5171server (@pxref{Substitutes}), you'd rather @emph{verify} that it
5172provides the right binaries, and thus @emph{challenge} it. The latter
5173is what enables the former: If package builds are deterministic, then
5174independent builds of the package should yield the exact same result,
5175bit for bit; if a server provides a binary different from the one
5176obtained locally, it may be either corrupt or malicious.
5177
5178We know that the hash that shows up in @file{/gnu/store} file names is
5179the hash of all the inputs of the process that built the file or
5180directory---compilers, libraries, build scripts,
5181etc. (@pxref{Introduction}). Assuming deterministic build processes,
5182one store file name should map to exactly one build output.
5183@command{guix challenge} checks whether there is, indeed, a single
5184mapping by comparing the build outputs of several independent builds of
5185any given store item.
5186
5187The command's output looks like this:
5188
5189@smallexample
5190$ guix challenge --substitute-urls="http://hydra.gnu.org http://guix.example.org"
5191updating list of substitutes from 'http://hydra.gnu.org'... 100.0%
5192updating list of substitutes from 'http://guix.example.org'... 100.0%
5193/gnu/store/@dots{}-openssl-1.0.2d contents differ:
5194 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5195 http://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5196 http://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
5197/gnu/store/@dots{}-git-2.5.0 contents differ:
5198 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
5199 http://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
5200 http://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
5201/gnu/store/@dots{}-pius-2.1.1 contents differ:
5202 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5203 http://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5204 http://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
5205@end smallexample
5206
5207@noindent
5208In this example, @command{guix challenge} first scans the store to
5209determine the set of locally-built derivations---as opposed to store
5210items that were downloaded from a substitute server---and then queries
5211all the substitute servers. It then reports those store items for which
5212the servers obtained a result different from the local build.
5213
5214@cindex non-determinism, in package builds
5215As an example, @code{guix.example.org} always gets a different answer.
5216Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
5217case of Git. This might indicate that the build process of Git is
5218non-deterministic, meaning that its output varies as a function of
5219various things that Guix does not fully control, in spite of building
5220packages in isolated environments (@pxref{Features}). Most common
5221sources of non-determinism include the addition of timestamps in build
5222results, the inclusion of random numbers, and directory listings sorted
5223by inode number. See @uref{http://reproducible.debian.net/howto/}, for
5224more information.
5225
5226To find out what's wrong with this Git binary, we can do something along
5227these lines (@pxref{Invoking guix archive}):
5228
5229@example
5230$ wget -q -O - http://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
5231 | guix archive -x /tmp/git
043f4698 5232$ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
d23c20f1
LC
5233@end example
5234
5235This command shows the difference between the files resulting from the
5236local build, and the files resulting from the build on
5237@code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
5238diffutils, Comparing and Merging Files}). The @command{diff} command
5239works great for text files. When binary files differ, a better option
5240is @uref{http://diffoscope.org/, Diffoscope}, a tool that helps
5241visualize differences for all kinds of files.
5242
5243Once you've done that work, you can tell whether the differences are due
5244to a non-deterministic build process or to a malicious server. We try
5245hard to remove sources of non-determinism in packages to make it easier
5246to verify substitutes, but of course, this is a process, one that
5247involves not just Guix but a large part of the free software community.
5248In the meantime, @command{guix challenge} is one tool to help address
5249the problem.
5250
5251If you are writing packages for Guix, you are encouraged to check
5252whether @code{hydra.gnu.org} and other substitute servers obtain the
5253same build result as you did with:
5254
5255@example
5256$ guix challenge @var{package}
5257@end example
5258
5259@noindent
5260... where @var{package} is a package specification such as
5261@code{guile-2.0} or @code{glibc:debug}.
5262
5263The general syntax is:
5264
5265@example
5266guix challenge @var{options} [@var{packages}@dots{}]
5267@end example
5268
5269The one option that matters is:
5270
5271@table @code
5272
5273@item --substitute-urls=@var{urls}
5274Consider @var{urls} the whitespace-separated list of substitute source
5275URLs to compare to.
5276
5277@end table
5278
5279
32efa254
DT
5280@node Invoking guix container
5281@section Invoking @command{guix container}
5282@cindex container
5283
5284@quotation Note
5285As of version @value{VERSION}, this tool is experimental. The interface
5286is subject to radical change in the future.
5287@end quotation
5288
5289The purpose of @command{guix container} is to manipulate processes
5290running within an isolated environment, commonly known as a
46c36586 5291``container'', typically created by the @command{guix environment}
32efa254
DT
5292(@pxref{Invoking guix environment}) and @command{guix system container}
5293(@pxref{Invoking guix system}) commands.
5294
5295The general syntax is:
5296
5297@example
5298guix container @var{action} @var{options}@dots{}
5299@end example
5300
5301@var{action} specifies the operation to perform with a container, and
5302@var{options} specifies the context-specific arguments for the action.
5303
5304The following actions are available:
5305
5306@table @code
5307@item exec
5308Execute a command within the context of a running container.
5309
5310The syntax is:
5311
5312@example
5313guix container exec @var{pid} @var{program} @var{arguments}@dots{}
5314@end example
5315
5316@var{pid} specifies the process ID of the running container.
5317@var{program} specifies an executable file name within the container's
5318root file system. @var{arguments} are the additional options that will
5319be passed to @var{program}.
5320
5321The following command launches an interactive login shell inside a
5322GuixSD container, started by @command{guix system container}, and whose
5323process ID is 9001:
5324
5325@example
5326guix container exec 9001 /run/current-system/profile/bin/bash --login
5327@end example
5328
5329Note that the @var{pid} cannot be the parent process of a container. It
5330must be the container's PID 1 or one of its child processes.
5331
5332@end table
5333
a1ba8475
LC
5334@c *********************************************************************
5335@node GNU Distribution
5336@chapter GNU Distribution
5337
3ca2731c 5338@cindex Guix System Distribution
4705641f 5339@cindex GuixSD
3ca2731c
LC
5340Guix comes with a distribution of the GNU system consisting entirely of
5341free software@footnote{The term ``free'' here refers to the
a1ba8475 5342@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 5343users of that software}.}. The
35ed9306
LC
5344distribution can be installed on its own (@pxref{System Installation}),
5345but it is also possible to install Guix as a package manager on top of
5346an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c 5347between the two, we refer to the standalone distribution as the Guix
4705641f 5348System Distribution, or GuixSD.
35ed9306
LC
5349
5350The distribution provides core GNU packages such as GNU libc, GCC, and
5351Binutils, as well as many GNU and non-GNU applications. The complete
5352list of available packages can be browsed
093ae1be 5353@url{http://www.gnu.org/software/guix/packages,on-line} or by
d03bb653 5354running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
5355
5356@example
e49951eb 5357guix package --list-available
a1ba8475
LC
5358@end example
5359
35ed9306 5360Our goal has been to provide a practical 100% free software distribution of
401c53c4
LC
5361Linux-based and other variants of GNU, with a focus on the promotion and
5362tight integration of GNU components, and an emphasis on programs and
5363tools that help users exert that freedom.
5364
3ca2731c 5365Packages are currently available on the following platforms:
c320011d
LC
5366
5367@table @code
5368
5369@item x86_64-linux
5370Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
5371
5372@item i686-linux
5373Intel 32-bit architecture (IA32), Linux-Libre kernel;
5374
aa1e1947 5375@item armhf-linux
aa725117 5376ARMv7-A architecture with hard float, Thumb-2 and NEON,
aa1e1947
MW
5377using the EABI hard-float ABI, and Linux-Libre kernel.
5378
c320011d
LC
5379@item mips64el-linux
5380little-endian 64-bit MIPS processors, specifically the Loongson series,
5381n32 application binary interface (ABI), and Linux-Libre kernel.
5382
5383@end table
5384
4705641f 5385GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
3ca2731c 5386
c320011d
LC
5387@noindent
5388For information on porting to other architectures or kernels,
5389@xref{Porting}.
5390
401c53c4 5391@menu
5af6de3e 5392* System Installation:: Installing the whole operating system.
35ed9306 5393* System Configuration:: Configuring the operating system.
91ef73d4 5394* Installing Debugging Files:: Feeding the debugger.
05962f29 5395* Security Updates:: Deploying security fixes quickly.
401c53c4 5396* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 5397* Packaging Guidelines:: Growing the distribution.
401c53c4 5398* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 5399* Porting:: Targeting another platform or kernel.
401c53c4
LC
5400@end menu
5401
5402Building this distribution is a cooperative effort, and you are invited
081145cf 5403to join! @xref{Contributing}, for information about how you can help.
401c53c4 5404
5af6de3e
LC
5405@node System Installation
5406@section System Installation
5407
3ca2731c
LC
5408@cindex Guix System Distribution
5409This section explains how to install the Guix System Distribution
5410on a machine. The Guix package manager can
35ed9306
LC
5411also be installed on top of a running GNU/Linux system,
5412@pxref{Installation}.
5af6de3e
LC
5413
5414@ifinfo
5415@c This paragraph is for people reading this from tty2 of the
5416@c installation image.
5417You're reading this documentation with an Info reader. For details on
5418how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
6621cdb6 5419link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit
5af6de3e
LC
5420@kbd{l} afterwards to come back here.
5421@end ifinfo
5422
8aaaae38
LC
5423@subsection Limitations
5424
4705641f 5425As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
3ca2731c 5426not production-ready. It may contain bugs and lack important
8aaaae38
LC
5427features. Thus, if you are looking for a stable production system that
5428respects your freedom as a computer user, a good solution at this point
5429is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
5430more established GNU/Linux distributions}. We hope you can soon switch
4705641f 5431to the GuixSD without fear, of course. In the meantime, you can
8aaaae38
LC
5432also keep using your distribution and try out the package manager on top
5433of it (@pxref{Installation}).
5434
5435Before you proceed with the installation, be aware of the following
5436noteworthy limitations applicable to version @value{VERSION}:
5437
5438@itemize
5439@item
5440The installation process does not include a graphical user interface and
5441requires familiarity with GNU/Linux (see the following subsections to
5442get a feel of what that means.)
5443
5444@item
093ae1be
LC
5445The system does not yet provide full GNOME and KDE desktops. Xfce and
5446Enlightenment are available though, if graphical desktop environments
5447are your thing, as well as a number of X11 window managers.
8aaaae38
LC
5448
5449@item
dbcb0ab1 5450Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
5451
5452@item
5453Few system services are currently supported out-of-the-box
5454(@pxref{Services}).
5455
5456@item
093ae1be 5457More than 2,000 packages are available, but you may
8aaaae38
LC
5458occasionally find that a useful package is missing.
5459@end itemize
5460
5461You've been warned. But more than a disclaimer, this is an invitation
5462to report issues (and success stories!), and join us in improving it.
5463@xref{Contributing}, for more info.
5af6de3e
LC
5464
5465@subsection USB Stick Installation
5466
5467An installation image for USB sticks can be downloaded from
4705641f 5468@indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
5469where @var{system} is one of:
5470
5471@table @code
5472@item x86_64-linux
5473for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
5474
5475@item i686-linux
5476for a 32-bit GNU/Linux system on Intel-compatible CPUs.
5477@end table
5478
5479This image contains a single partition with the tools necessary for an
5480installation. It is meant to be copied @emph{as is} to a large-enough
5481USB stick.
5482
5483To copy the image to a USB stick, follow these steps:
5484
5485@enumerate
5486@item
5487Decompress the image using the @command{xz} command:
5488
5489@example
4705641f 5490xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
5491@end example
5492
5493@item
5494Insert a USB stick of 1@tie{}GiB or more in your machine, and determine
5495its device name. Assuming that USB stick is known as @file{/dev/sdX},
5496copy the image with:
5497
5498@example
4705641f 5499dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
5500@end example
5501
5502Access to @file{/dev/sdX} usually requires root privileges.
5503@end enumerate
5504
5505Once this is done, you should be able to reboot the system and boot from
5506the USB stick. The latter usually requires you to get in the BIOS' boot
5507menu, where you can choose to boot from the USB stick.
5508
5509@subsection Preparing for Installation
5510
5511Once you have successfully booted the image on the USB stick, you should
5512end up with a root prompt. Several console TTYs are configured and can
5513be used to run commands as root. TTY2 shows this documentation,
5514browsable using the Info reader commands (@pxref{Help,,, info, Info: An
ae7ffa9e
LC
5515Introduction}). The installation system runs the GPM mouse daemon,
5516which allows you to select text with the left mouse button and to paste
5517it with the middle button.
5af6de3e
LC
5518
5519To install the system, you would:
5520
5521@enumerate
5522
5523@item
235cba85
LC
5524Configure the network, by running:
5525
5526@example
5527ifconfig eno1 up && dhclient eno1
5528@end example
5529
5530to get an automatically assigned IP address from the wired
152dd61c 5531network interface controller@footnote{
95c559c1
LC
5532@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
5533The name @code{eno1} is for the first on-board Ethernet controller. The
5534interface name for an Ethernet controller that is in the first slot of
5535the first PCI bus, for instance, would be @code{enp1s0}. Use
235cba85 5536@command{ifconfig -a} to list all the available network interfaces.},
95c559c1 5537or using the @command{ifconfig} command.
5af6de3e
LC
5538
5539The system automatically loads drivers for your network interface
5540controllers.
5541
5542Setting up network access is almost always a requirement because the
5543image does not contain all the software and tools that may be needed.
5544
5545@item
316d65be
LC
5546Unless this has already been done, you must partition, and then format
5547the target partition.
5af6de3e 5548
7ab44369
LC
5549Preferably, assign partitions a label so that you can easily and
5550reliably refer to them in @code{file-system} declarations (@pxref{File
5551Systems}). This is typically done using the @code{-L} option of
5552@command{mkfs.ext4} and related commands.
5553
dd816355
LF
5554Be sure that your partition labels match the value of their respective
5555@code{device} fields in your @code{file-system} configuration, if your
5556@code{file-system} configuration sets the value of @code{title} to
5557@code{'label}, as do the example configurations found on the USB
5558installation image under @file{/etc/configuration} (@pxref{Using the
5559Configuration System}).
5560
316d65be
LC
5561@c FIXME: Uncomment this once GRUB fully supports encrypted roots.
5562@c A typical command sequence may be:
5563@c
5564@c @example
5565@c # fdisk /dev/sdX
5566@c @dots{} Create partitions etc.@dots{}
5567@c # cryptsetup luksFormat /dev/sdX1
5568@c # cryptsetup open --type luks /dev/sdX1 my-partition
5569@c # mkfs.ext4 -L my-root /dev/mapper/my-partition
5570@c @end example
6d6e6281 5571
5af6de3e 5572The installation image includes Parted (@pxref{Overview,,, parted, GNU
b419c7f5
LC
5573Parted User Manual}), @command{fdisk}, Cryptsetup/LUKS for disk
5574encryption, and e2fsprogs, the suite of tools to manipulate
5575ext2/ext3/ext4 file systems.
5af6de3e 5576
83a17b62
LC
5577@item
5578Once that is done, mount the target root partition under @file{/mnt}.
5579
5580@item
5581Lastly, run @code{deco start cow-store /mnt}.
5582
5583This will make @file{/gnu/store} copy-on-write, such that packages added
5584to it during the installation phase will be written to the target disk
5585rather than kept in memory.
5586
5af6de3e
LC
5587@end enumerate
5588
5af6de3e
LC
5589
5590@subsection Proceeding with the Installation
5591
5592With the target partitions ready, you now have to edit a file and
5593provide the declaration of the operating system to be installed. To
5594that end, the installation system comes with two text editors: GNU nano
5595(@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
5596It is better to store that file on the target root file system, say, as
5597@file{/mnt/etc/config.scm}.
5598
dd51caac
LC
5599@xref{Using the Configuration System}, for examples of operating system
5600configurations. These examples are available under
5601@file{/etc/configuration} in the installation image, so you can copy
5602them and use them as a starting point for your own configuration.
5af6de3e 5603
dd51caac
LC
5604Once you are done preparing the configuration file, the new system must
5605be initialized (remember that the target root file system is mounted
5606under @file{/mnt}):
5af6de3e
LC
5607
5608@example
5609guix system init /mnt/etc/config.scm /mnt
5610@end example
5611
5612@noindent
5613This will copy all the necessary files, and install GRUB on
5614@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 5615more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
5616downloads or builds of missing packages, which can take some time.
5617
1bd4e6db
LC
5618Once that command has completed---and hopefully succeeded!---you can run
5619@command{reboot} and boot into the new system. The @code{root} password
5620in the new system is initially empty; other users' passwords need to be
5621initialized by running the @command{passwd} command as @code{root},
5622unless your configuration specifies otherwise
5623(@pxref{user-account-password, user account passwords}).
5624
5625Join us on @code{#guix} on the Freenode IRC network or on
5af6de3e
LC
5626@file{guix-devel@@gnu.org} to share your experience---good or not so
5627good.
5628
5629@subsection Building the Installation Image
5630
5631The installation image described above was built using the @command{guix
5632system} command, specifically:
5633
5634@example
8a225c66 5635guix system disk-image --image-size=850MiB gnu/system/install.scm
5af6de3e
LC
5636@end example
5637
5638@xref{Invoking guix system}, for more information. See
5639@file{gnu/system/install.scm} in the source tree for more information
5640about the installation image.
5641
cf4a9129
LC
5642@node System Configuration
5643@section System Configuration
b208a005 5644
cf4a9129 5645@cindex system configuration
3ca2731c 5646The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
5647mechanism. By that we mean that all aspects of the global system
5648configuration---such as the available system services, timezone and
5649locale settings, user accounts---are declared in a single place. Such
5650a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 5651
cf4a9129
LC
5652One of the advantages of putting all the system configuration under the
5653control of Guix is that it supports transactional system upgrades, and
5654makes it possible to roll-back to a previous system instantiation,
5655should something go wrong with the new one (@pxref{Features}). Another
5656one is that it makes it easy to replicate the exact same configuration
5657across different machines, or at different points in time, without
5658having to resort to additional administration tools layered on top of
5659the system's own tools.
5660@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 5661
cf4a9129
LC
5662This section describes this mechanism. First we focus on the system
5663administrator's viewpoint---explaining how the system is configured and
5664instantiated. Then we show how this mechanism can be extended, for
5665instance to support new system services.
91ef73d4 5666
cf4a9129
LC
5667@menu
5668* Using the Configuration System:: Customizing your GNU system.
7313a52e 5669* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 5670* File Systems:: Configuring file system mounts.
510f9d86 5671* Mapped Devices:: Block device extra processing.
cf4a9129 5672* User Accounts:: Specifying user accounts.
598e19dc 5673* Locales:: Language and cultural convention settings.
cf4a9129 5674* Services:: Specifying system services.
0ae8c15a 5675* Setuid Programs:: Programs running with root privileges.
efb5e833 5676* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 5677* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 5678* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 5679* GRUB Configuration:: Configuring the boot loader.
cf4a9129
LC
5680* Invoking guix system:: Instantiating a system configuration.
5681* Defining Services:: Adding new service definitions.
5682@end menu
91ef73d4 5683
cf4a9129
LC
5684@node Using the Configuration System
5685@subsection Using the Configuration System
64d76fa6 5686
cf4a9129
LC
5687The operating system is configured by providing an
5688@code{operating-system} declaration in a file that can then be passed to
5689the @command{guix system} command (@pxref{Invoking guix system}). A
5690simple setup, with the default system services, the default Linux-Libre
5691kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 5692
cf4a9129
LC
5693@findex operating-system
5694@lisp
dd51caac 5695@include os-config-bare-bones.texi
cf4a9129 5696@end lisp
401c53c4 5697
cf4a9129
LC
5698This example should be self-describing. Some of the fields defined
5699above, such as @code{host-name} and @code{bootloader}, are mandatory.
5700Others, such as @code{packages} and @code{services}, can be omitted, in
5701which case they get a default value.
e7f34eb0 5702
cf4a9129
LC
5703@vindex %base-packages
5704The @code{packages} field lists
5705packages that will be globally visible on the system, for all user
5706accounts---i.e., in every user's @code{PATH} environment variable---in
5707addition to the per-user profiles (@pxref{Invoking guix package}). The
5708@var{%base-packages} variable provides all the tools one would expect
5709for basic user and administrator tasks---including the GNU Core
5710Utilities, the GNU Networking Utilities, the GNU Zile lightweight text
5711editor, @command{find}, @command{grep}, etc. The example above adds
2e437e29 5712tcpdump to those, taken from the @code{(gnu packages admin)} module
cf4a9129 5713(@pxref{Package Modules}).
e7f34eb0 5714
f6c9fb1b
LC
5715@findex specification->package
5716Referring to packages by variable name, like @var{tcpdump} above, has
5717the advantage of being unambiguous; it also allows typos and such to be
5718diagnosed right away as ``unbound variables''. The downside is that one
5719needs to know which module defines which package, and to augment the
5720@code{use-package-modules} line accordingly. To avoid that, one can use
5721the @code{specification->package} procedure of the @code{(gnu packages)}
5722module, which returns the best package for a given name or name and
5723version:
5724
5725@lisp
5726(use-modules (gnu packages))
5727
5728(operating-system
5729 ;; ...
5730 (packages (append (map specification->package
5731 '("tcpdump" "htop" "gnupg-2.0"))
5732 %base-packages)))
5733@end lisp
5734
cf4a9129
LC
5735@vindex %base-services
5736The @code{services} field lists @dfn{system services} to be made
5737available when the system starts (@pxref{Services}).
5738The @code{operating-system} declaration above specifies that, in
5739addition to the basic services, we want the @command{lshd} secure shell
cd6f6c22
LC
5740daemon listening on port 2222 (@pxref{Networking Services,
5741@code{lsh-service}}). Under the hood,
cf4a9129
LC
5742@code{lsh-service} arranges so that @code{lshd} is started with the
5743right command-line options, possibly with supporting configuration files
cd6f6c22
LC
5744generated as needed (@pxref{Defining Services}).
5745
5746@cindex customization, of services
5747@findex modify-services
5748Occasionally, instead of using the base services as is, you will want to
5749customize them. For instance, to change the configuration of
5750@code{guix-daemon} and Mingetty (the console log-in), you may write the
5751following instead of @var{%base-services}:
5752
5753@lisp
5754(modify-services %base-services
5755 (guix-service-type config =>
5756 (guix-configuration
5757 (inherit config)
5758 (use-substitutes? #f)
5759 (extra-options '("--gc-keep-outputs"))))
5760 (mingetty-service-type config =>
5761 (mingetty-configuration
5762 (inherit config)
5763 (motd (plain-file "motd" "Hi there!")))))
5764@end lisp
5765
5766@noindent
5767The effect here is to change the options passed to @command{guix-daemon}
5768when it is started, as well as the ``message of the day'' that appears
5769when logging in at the console. @xref{Service Reference,
5770@code{modify-services}}, for more on that.
a1ba8475 5771
dd51caac 5772The configuration for a typical ``desktop'' usage, with the X11 display
cd6f6c22 5773server, a desktop environment, network management, power management, and
dd51caac
LC
5774more, would look like this:
5775
5776@lisp
5777@include os-config-desktop.texi
5778@end lisp
5779
5780@xref{Desktop Services}, for the exact list of services provided by
efb5e833
LC
5781@var{%desktop-services}. @xref{X.509 Certificates}, for background
5782information about the @code{nss-certs} package that is used here.
cd6f6c22
LC
5783@xref{operating-system Reference}, for details about all the available
5784@code{operating-system} fields.
dd51caac 5785
cf4a9129
LC
5786Assuming the above snippet is stored in the @file{my-system-config.scm}
5787file, the @command{guix system reconfigure my-system-config.scm} command
5788instantiates that configuration, and makes it the default GRUB boot
65797bff
LC
5789entry (@pxref{Invoking guix system}).
5790
5791The normal way to change the system's configuration is by updating this
5792file and re-running @command{guix system reconfigure}. One should never
5793have to touch files in @command{/etc} or to run commands that modify the
5794system state such as @command{useradd} or @command{grub-install}. In
5795fact, you must avoid that since that would not only void your warranty
5796but also prevent you from rolling back to previous versions of your
5797system, should you ever need to.
5798
5799@cindex roll-back, of the operating system
5800Speaking of roll-back, each time you run @command{guix system
5801reconfigure}, a new @dfn{generation} of the system is created---without
5802modifying or deleting previous generations. Old system generations get
5803an entry in the GRUB boot menu, allowing you to boot them in case
5804something went wrong with the latest generation. Reassuring, no? The
5805@command{guix system list-generations} command lists the system
5806generations available on disk.
b81e1947 5807
cf4a9129
LC
5808At the Scheme level, the bulk of an @code{operating-system} declaration
5809is instantiated with the following monadic procedure (@pxref{The Store
5810Monad}):
b81e1947 5811
cf4a9129
LC
5812@deffn {Monadic Procedure} operating-system-derivation os
5813Return a derivation that builds @var{os}, an @code{operating-system}
5814object (@pxref{Derivations}).
b81e1947 5815
cf4a9129
LC
5816The output of the derivation is a single directory that refers to all
5817the packages, configuration files, and other supporting files needed to
5818instantiate @var{os}.
5819@end deffn
b81e1947 5820
7313a52e
LC
5821@node operating-system Reference
5822@subsection @code{operating-system} Reference
5823
5824This section summarizes all the options available in
5825@code{operating-system} declarations (@pxref{Using the Configuration
5826System}).
5827
5828@deftp {Data Type} operating-system
5829This is the data type representing an operating system configuration.
5830By that, we mean all the global system configuration, not per-user
5831configuration (@pxref{Using the Configuration System}).
5832
5833@table @asis
5834@item @code{kernel} (default: @var{linux-libre})
fbb25e56 5835The package object of the operating system kernel to use@footnote{Currently
7313a52e
LC
5836only the Linux-libre kernel is supported. In the future, it will be
5837possible to use the GNU@tie{}Hurd.}.
5838
ee2a6304
LC
5839@item @code{kernel-arguments} (default: @code{'()})
5840List of strings or gexps representing additional arguments to pass on
5841the kernel's command-line---e.g., @code{("console=ttyS0")}.
5842
7313a52e 5843@item @code{bootloader}
88faf933 5844The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
5845
5846@item @code{initrd} (default: @code{base-initrd})
5847A two-argument monadic procedure that returns an initial RAM disk for
5848the Linux kernel. @xref{Initial RAM Disk}.
5849
f34c56be
LC
5850@item @code{firmware} (default: @var{%base-firmware})
5851@cindex firmware
5852List of firmware packages loadable by the operating system kernel.
5853
5854The default includes firmware needed for Atheros-based WiFi devices
5855(Linux-libre module @code{ath9k}.)
5856
7313a52e
LC
5857@item @code{host-name}
5858The host name.
5859
5860@item @code{hosts-file}
5861@cindex hosts file
24e02c28 5862A file-like object (@pxref{G-Expressions, file-like objects}) for use as
7313a52e 5863@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
24e02c28 5864Reference Manual}). The default is a file with entries for
7313a52e
LC
5865@code{localhost} and @var{host-name}.
5866
5867@item @code{mapped-devices} (default: @code{'()})
5868A list of mapped devices. @xref{Mapped Devices}.
5869
5870@item @code{file-systems}
5871A list of file systems. @xref{File Systems}.
5872
5873@item @code{swap-devices} (default: @code{'()})
5874@cindex swap devices
5875A list of strings identifying devices to be used for ``swap space''
5876(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
5877For example, @code{'("/dev/sda3")}.
5878
bf87f38a 5879@item @code{users} (default: @code{%base-user-accounts})
7313a52e
LC
5880@itemx @code{groups} (default: @var{%base-groups})
5881List of user accounts and groups. @xref{User Accounts}.
5882
5883@item @code{skeletons} (default: @code{(default-skeletons)})
5884A monadic list of pairs of target file name and files. These are the
5885files that will be used as skeletons as new accounts are created.
5886
5887For instance, a valid value may look like this:
5888
5889@example
5890(mlet %store-monad ((bashrc (text-file "bashrc" "\
5891 export PATH=$HOME/.guix-profile/bin")))
5892 (return `((".bashrc" ,bashrc))))
5893@end example
5894
5895@item @code{issue} (default: @var{%default-issue})
5896A string denoting the contents of the @file{/etc/issue} file, which is
5897what displayed when users log in on a text console.
5898
5899@item @code{packages} (default: @var{%base-packages})
5900The set of packages installed in the global profile, which is accessible
5901at @file{/run/current-system/profile}.
5902
5903The default set includes core utilities, but it is good practice to
5904install non-core utilities in user profiles (@pxref{Invoking guix
5905package}).
5906
5907@item @code{timezone}
5908A timezone identifying string---e.g., @code{"Europe/Paris"}.
5909
598e19dc
LC
5910@item @code{locale} (default: @code{"en_US.utf8"})
5911The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
5912Library Reference Manual}). @xref{Locales}, for more information.
5913
5914@item @code{locale-definitions} (default: @var{%default-locale-definitions})
5915The list of locale definitions to be compiled and that may be used at
5916run time. @xref{Locales}.
7313a52e 5917
34760ae7
LC
5918@item @code{locale-libcs} (default: @code{(list @var{glibc})})
5919The list of GNU@tie{}libc packages whose locale data and tools are used
5920to build the locale definitions. @xref{Locales}, for compatibility
5921considerations that justify this option.
5922
996ed739
LC
5923@item @code{name-service-switch} (default: @var{%default-nss})
5924Configuration of libc's name service switch (NSS)---a
5925@code{<name-service-switch>} object. @xref{Name Service Switch}, for
5926details.
5927
7313a52e 5928@item @code{services} (default: @var{%base-services})
28d939af 5929A list of service objects denoting system services. @xref{Services}.
7313a52e
LC
5930
5931@item @code{pam-services} (default: @code{(base-pam-services)})
5932@cindex PAM
5933@cindex pluggable authentication modules
5934Linux @dfn{pluggable authentication module} (PAM) services.
5935@c FIXME: Add xref to PAM services section.
5936
5937@item @code{setuid-programs} (default: @var{%setuid-programs})
5938List of string-valued G-expressions denoting setuid programs.
5939@xref{Setuid Programs}.
5940
f5a9ffa0
AK
5941@item @code{sudoers-file} (default: @var{%sudoers-specification})
5942@cindex sudoers file
84765839
LC
5943The contents of the @file{/etc/sudoers} file as a file-like object
5944(@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7313a52e
LC
5945
5946This file specifies which users can use the @command{sudo} command, what
5947they are allowed to do, and what privileges they may gain. The default
5948is that only @code{root} and members of the @code{wheel} group may use
5949@code{sudo}.
5950
5951@end table
5952@end deftp
5953
cf4a9129
LC
5954@node File Systems
5955@subsection File Systems
b81e1947 5956
cf4a9129
LC
5957The list of file systems to be mounted is specified in the
5958@code{file-systems} field of the operating system's declaration
5959(@pxref{Using the Configuration System}). Each file system is declared
5960using the @code{file-system} form, like this:
b81e1947
LC
5961
5962@example
cf4a9129
LC
5963(file-system
5964 (mount-point "/home")
5965 (device "/dev/sda3")
5966 (type "ext4"))
b81e1947
LC
5967@end example
5968
cf4a9129
LC
5969As usual, some of the fields are mandatory---those shown in the example
5970above---while others can be omitted. These are described below.
b81e1947 5971
cf4a9129
LC
5972@deftp {Data Type} file-system
5973Objects of this type represent file systems to be mounted. They
5974contain the following members:
5ff3c4b8 5975
cf4a9129
LC
5976@table @asis
5977@item @code{type}
5978This is a string specifying the type of the file system---e.g.,
5979@code{"ext4"}.
5ff3c4b8 5980
cf4a9129
LC
5981@item @code{mount-point}
5982This designates the place where the file system is to be mounted.
b81e1947 5983
cf4a9129
LC
5984@item @code{device}
5985This names the ``source'' of the file system. By default it is the name
5986of a node under @file{/dev}, but its meaning depends on the @code{title}
5987field described below.
401c53c4 5988
cf4a9129
LC
5989@item @code{title} (default: @code{'device})
5990This is a symbol that specifies how the @code{device} field is to be
5991interpreted.
401c53c4 5992
cf4a9129
LC
5993When it is the symbol @code{device}, then the @code{device} field is
5994interpreted as a file name; when it is @code{label}, then @code{device}
5995is interpreted as a partition label name; when it is @code{uuid},
5996@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 5997
661a1d79
LC
5998UUIDs may be converted from their string representation (as shown by the
5999@command{tune2fs -l} command) using the @code{uuid} form, like this:
6000
6001@example
6002(file-system
6003 (mount-point "/home")
6004 (type "ext4")
6005 (title 'uuid)
6006 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
6007@end example
6008
cf4a9129 6009The @code{label} and @code{uuid} options offer a way to refer to disk
661a1d79
LC
6010partitions without having to hard-code their actual device
6011name@footnote{Note that, while it is tempting to use
6012@file{/dev/disk/by-uuid} and similar device names to achieve the same
6013result, this is not recommended: These special device nodes are created
6014by the udev daemon and may be unavailable at the time the device is
6015mounted.}.
da7cabd4 6016
5f86a66e
LC
6017However, when a file system's source is a mapped device (@pxref{Mapped
6018Devices}), its @code{device} field @emph{must} refer to the mapped
6019device name---e.g., @file{/dev/mapper/root-partition}---and consequently
6020@code{title} must be set to @code{'device}. This is required so that
6021the system knows that mounting the file system depends on having the
6022corresponding device mapping established.
6023
cf4a9129
LC
6024@item @code{flags} (default: @code{'()})
6025This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
6026include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
6027access to special files), @code{no-suid} (ignore setuid and setgid
6028bits), and @code{no-exec} (disallow program execution.)
da7cabd4 6029
cf4a9129
LC
6030@item @code{options} (default: @code{#f})
6031This is either @code{#f}, or a string denoting mount options.
da7cabd4 6032
be21979d
LC
6033@item @code{mount?} (default: @code{#t})
6034This value indicates whether to automatically mount the file system when
6035the system is brought up. When set to @code{#f}, the file system gets
6036an entry in @file{/etc/fstab} (read by the @command{mount} command) but
6037is not automatically mounted.
6038
cf4a9129
LC
6039@item @code{needed-for-boot?} (default: @code{#f})
6040This Boolean value indicates whether the file system is needed when
6041booting. If that is true, then the file system is mounted when the
6042initial RAM disk (initrd) is loaded. This is always the case, for
6043instance, for the root file system.
da7cabd4 6044
cf4a9129
LC
6045@item @code{check?} (default: @code{#t})
6046This Boolean indicates whether the file system needs to be checked for
6047errors before being mounted.
f9cc8971 6048
4e469051
LC
6049@item @code{create-mount-point?} (default: @code{#f})
6050When true, the mount point is created if it does not exist yet.
6051
e51710d1
LC
6052@item @code{dependencies} (default: @code{'()})
6053This is a list of @code{<file-system>} objects representing file systems
6054that must be mounted before (and unmounted after) this one.
6055
6056As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
6057a dependency of @file{/sys/fs/cgroup/cpu} and
6058@file{/sys/fs/cgroup/memory}.
6059
cf4a9129
LC
6060@end table
6061@end deftp
da7cabd4 6062
a69576ea
LC
6063The @code{(gnu system file-systems)} exports the following useful
6064variables.
6065
6066@defvr {Scheme Variable} %base-file-systems
6067These are essential file systems that are required on normal systems,
cc0e575a 6068such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
3392ce5d
LC
6069below.) Operating system declarations should always contain at least
6070these.
a69576ea
LC
6071@end defvr
6072
7f239fd3
LC
6073@defvr {Scheme Variable} %pseudo-terminal-file-system
6074This is the file system to be mounted as @file{/dev/pts}. It supports
6075@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
6076functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
6077Manual}). Pseudo-terminals are used by terminal emulators such as
6078@command{xterm}.
6079@end defvr
6080
db17ae5c
LC
6081@defvr {Scheme Variable} %shared-memory-file-system
6082This file system is mounted as @file{/dev/shm} and is used to support
6083memory sharing across processes (@pxref{Memory-mapped I/O,
6084@code{shm_open},, libc, The GNU C Library Reference Manual}).
6085@end defvr
6086
3392ce5d
LC
6087@defvr {Scheme Variable} %immutable-store
6088This file system performs a read-only ``bind mount'' of
6089@file{/gnu/store}, making it read-only for all the users including
6090@code{root}. This prevents against accidental modification by software
6091running as @code{root} or by system administrators.
6092
6093The daemon itself is still able to write to the store: it remounts it
6094read-write in its own ``name space.''
6095@end defvr
6096
a69576ea
LC
6097@defvr {Scheme Variable} %binary-format-file-system
6098The @code{binfmt_misc} file system, which allows handling of arbitrary
6099executable file types to be delegated to user space. This requires the
6100@code{binfmt.ko} kernel module to be loaded.
6101@end defvr
6102
6103@defvr {Scheme Variable} %fuse-control-file-system
6104The @code{fusectl} file system, which allows unprivileged users to mount
6105and unmount user-space FUSE file systems. This requires the
6106@code{fuse.ko} kernel module to be loaded.
6107@end defvr
6108
510f9d86
LC
6109@node Mapped Devices
6110@subsection Mapped Devices
6111
6112@cindex device mapping
6113@cindex mapped devices
6114The Linux kernel has a notion of @dfn{device mapping}: a block device,
6115such as a hard disk partition, can be @dfn{mapped} into another device,
6116with additional processing over the data that flows through
6117it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
6118concept of a ``mapped device'' and that of a file system: both boil down
6119to @emph{translating} input/output operations made on a file to
6120operations on its backing store. Thus, the Hurd implements mapped
6121devices, like file systems, using the generic @dfn{translator} mechanism
6122(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
6123typical example is encryption device mapping: all writes to the mapped
6124device are encrypted, and all reads are deciphered, transparently.
6125
6126Mapped devices are declared using the @code{mapped-device} form:
6127
6128@example
6129(mapped-device
6130 (source "/dev/sda3")
6131 (target "home")
6132 (type luks-device-mapping))
6133@end example
6134
6135@noindent
6136@cindex disk encryption
6137@cindex LUKS
6138This example specifies a mapping from @file{/dev/sda3} to
6139@file{/dev/mapper/home} using LUKS---the
6140@url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
6141standard mechanism for disk encryption. The @file{/dev/mapper/home}
6142device can then be used as the @code{device} of a @code{file-system}
6143declaration (@pxref{File Systems}). The @code{mapped-device} form is
6144detailed below.
6145
6146@deftp {Data Type} mapped-device
6147Objects of this type represent device mappings that will be made when
6148the system boots up.
6149
9cb426b8
LC
6150@table @code
6151@item source
510f9d86
LC
6152This string specifies the name of the block device to be mapped, such as
6153@code{"/dev/sda3"}.
6154
9cb426b8 6155@item target
510f9d86
LC
6156This string specifies the name of the mapping to be established. For
6157example, specifying @code{"my-partition"} will lead to the creation of
6158the @code{"/dev/mapper/my-partition"} device.
6159
9cb426b8 6160@item type
510f9d86
LC
6161This must be a @code{mapped-device-kind} object, which specifies how
6162@var{source} is mapped to @var{target}.
6163@end table
6164@end deftp
6165
6166@defvr {Scheme Variable} luks-device-mapping
6167This defines LUKS block device encryption using the @command{cryptsetup}
6168command, from the same-named package. This relies on the
6169@code{dm-crypt} Linux kernel module.
6170@end defvr
6171
cf4a9129
LC
6172@node User Accounts
6173@subsection User Accounts
ee85f3db 6174
9bea87a5
LC
6175User accounts and groups are entirely managed through the
6176@code{operating-system} declaration. They are specified with the
6177@code{user-account} and @code{user-group} forms:
ee85f3db 6178
cf4a9129
LC
6179@example
6180(user-account
6181 (name "alice")
6182 (group "users")
24e752c0
LC
6183 (supplementary-groups '("wheel" ;allow use of sudo, etc.
6184 "audio" ;sound card
6185 "video" ;video devices such as webcams
6186 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
6187 (comment "Bob's sister")
6188 (home-directory "/home/alice"))
6189@end example
25083588 6190
9bea87a5
LC
6191When booting or upon completion of @command{guix system reconfigure},
6192the system ensures that only the user accounts and groups specified in
6193the @code{operating-system} declaration exist, and with the specified
6194properties. Thus, account or group creations or modifications made by
6195directly invoking commands such as @command{useradd} are lost upon
6196reconfiguration or reboot. This ensures that the system remains exactly
6197as declared.
6198
cf4a9129
LC
6199@deftp {Data Type} user-account
6200Objects of this type represent user accounts. The following members may
6201be specified:
ee85f3db 6202
cf4a9129
LC
6203@table @asis
6204@item @code{name}
6205The name of the user account.
ee85f3db 6206
cf4a9129
LC
6207@item @code{group}
6208This is the name (a string) or identifier (a number) of the user group
6209this account belongs to.
ee85f3db 6210
cf4a9129
LC
6211@item @code{supplementary-groups} (default: @code{'()})
6212Optionally, this can be defined as a list of group names that this
6213account belongs to.
ee85f3db 6214
cf4a9129
LC
6215@item @code{uid} (default: @code{#f})
6216This is the user ID for this account (a number), or @code{#f}. In the
6217latter case, a number is automatically chosen by the system when the
6218account is created.
ee85f3db 6219
cf4a9129
LC
6220@item @code{comment} (default: @code{""})
6221A comment about the account, such as the account's owner full name.
c8c871d1 6222
cf4a9129
LC
6223@item @code{home-directory}
6224This is the name of the home directory for the account.
ee85f3db 6225
cf4a9129
LC
6226@item @code{shell} (default: Bash)
6227This is a G-expression denoting the file name of a program to be used as
6228the shell (@pxref{G-Expressions}).
ee85f3db 6229
cf4a9129
LC
6230@item @code{system?} (default: @code{#f})
6231This Boolean value indicates whether the account is a ``system''
6232account. System accounts are sometimes treated specially; for instance,
6233graphical login managers do not list them.
ee85f3db 6234
1bd4e6db 6235@anchor{user-account-password}
cf4a9129 6236@item @code{password} (default: @code{#f})
eb59595c
LC
6237You would normally leave this field to @code{#f}, initialize user
6238passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
6239users change it with @command{passwd}. Passwords set with
6240@command{passwd} are of course preserved across reboot and
6241reconfiguration.
eb59595c
LC
6242
6243If you @emph{do} want to have a preset password for an account, then
6244this field must contain the encrypted password, as a string.
5d1f1177
LC
6245@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
6246on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 6247Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 6248
cf4a9129
LC
6249@end table
6250@end deftp
ee85f3db 6251
cf4a9129 6252User group declarations are even simpler:
ee85f3db 6253
cf4a9129
LC
6254@example
6255(user-group (name "students"))
6256@end example
ee85f3db 6257
cf4a9129
LC
6258@deftp {Data Type} user-group
6259This type is for, well, user groups. There are just a few fields:
af8a56b8 6260
cf4a9129
LC
6261@table @asis
6262@item @code{name}
6263The group's name.
ee85f3db 6264
cf4a9129
LC
6265@item @code{id} (default: @code{#f})
6266The group identifier (a number). If @code{#f}, a new number is
6267automatically allocated when the group is created.
ee85f3db 6268
c8fa3426
LC
6269@item @code{system?} (default: @code{#f})
6270This Boolean value indicates whether the group is a ``system'' group.
6271System groups have low numerical IDs.
6272
cf4a9129
LC
6273@item @code{password} (default: @code{#f})
6274What, user groups can have a password? Well, apparently yes. Unless
6275@code{#f}, this field specifies the group's password.
ee85f3db 6276
cf4a9129
LC
6277@end table
6278@end deftp
401c53c4 6279
cf4a9129
LC
6280For convenience, a variable lists all the basic user groups one may
6281expect:
401c53c4 6282
cf4a9129
LC
6283@defvr {Scheme Variable} %base-groups
6284This is the list of basic user groups that users and/or packages expect
6285to be present on the system. This includes groups such as ``root'',
6286``wheel'', and ``users'', as well as groups used to control access to
6287specific devices such as ``audio'', ``disk'', and ``cdrom''.
6288@end defvr
401c53c4 6289
bf87f38a
LC
6290@defvr {Scheme Variable} %base-user-accounts
6291This is the list of basic system accounts that programs may expect to
6292find on a GNU/Linux system, such as the ``nobody'' account.
6293
6294Note that the ``root'' account is not included here. It is a
6295special-case and is automatically added whether or not it is specified.
6296@end defvr
6297
598e19dc
LC
6298@node Locales
6299@subsection Locales
6300
6301@cindex locale
6302A @dfn{locale} defines cultural conventions for a particular language
6303and region of the world (@pxref{Locales,,, libc, The GNU C Library
6304Reference Manual}). Each locale has a name that typically has the form
b2636518 6305@code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
598e19dc
LC
6306@code{fr_LU.utf8} designates the locale for the French language, with
6307cultural conventions from Luxembourg, and using the UTF-8 encoding.
6308
6309@cindex locale definition
6310Usually, you will want to specify the default locale for the machine
6311using the @code{locale} field of the @code{operating-system} declaration
6312(@pxref{operating-system Reference, @code{locale}}).
6313
6314That locale must be among the @dfn{locale definitions} that are known to
6315the system---and these are specified in the @code{locale-definitions}
6316slot of @code{operating-system}. The default value includes locale
6317definition for some widely used locales, but not for all the available
6318locales, in order to save space.
6319
6320If the locale specified in the @code{locale} field is not among the
6321definitions listed in @code{locale-definitions}, @command{guix system}
6322raises an error. In that case, you should add the locale definition to
6323the @code{locale-definitions} field. For instance, to add the North
6324Frisian locale for Germany, the value of that field may be:
6325
6326@example
6327(cons (locale-definition
6328 (name "fy_DE.utf8") (source "fy_DE"))
6329 %default-locale-definitions)
6330@end example
6331
6332Likewise, to save space, one might want @code{locale-definitions} to
6333list only the locales that are actually used, as in:
6334
6335@example
6336(list (locale-definition
6337 (name "ja_JP.eucjp") (source "ja_JP")
6338 (charset "EUC-JP")))
6339@end example
6340
5c3c1427
LC
6341@vindex LOCPATH
6342The compiled locale definitions are available at
46bd6edd
LC
6343@file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
6344version, which is the default location where the GNU@tie{}libc provided
6345by Guix looks for locale data. This can be overridden using the
6346@code{LOCPATH} environment variable (@pxref{locales-and-locpath,
5c3c1427
LC
6347@code{LOCPATH} and locale packages}).
6348
598e19dc
LC
6349The @code{locale-definition} form is provided by the @code{(gnu system
6350locale)} module. Details are given below.
6351
6352@deftp {Data Type} locale-definition
6353This is the data type of a locale definition.
6354
6355@table @asis
6356
6357@item @code{name}
6358The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
6359Reference Manual}, for more information on locale names.
6360
6361@item @code{source}
6362The name of the source for that locale. This is typically the
6363@code{@var{language}_@var{territory}} part of the locale name.
6364
6365@item @code{charset} (default: @code{"UTF-8"})
6366The ``character set'' or ``code set'' for that locale,
6367@uref{http://www.iana.org/assignments/character-sets, as defined by
6368IANA}.
6369
6370@end table
6371@end deftp
6372
6373@defvr {Scheme Variable} %default-locale-definitions
b2636518
LC
6374An arbitrary list of commonly used UTF-8 locales, used as the default
6375value of the @code{locale-definitions} field of @code{operating-system}
598e19dc 6376declarations.
b2636518
LC
6377
6378@cindex locale name
6379@cindex normalized codeset in locale names
6380These locale definitions use the @dfn{normalized codeset} for the part
6381that follows the dot in the name (@pxref{Using gettextized software,
6382normalized codeset,, libc, The GNU C Library Reference Manual}). So for
6383instance it has @code{uk_UA.utf8} but @emph{not}, say,
6384@code{uk_UA.UTF-8}.
598e19dc 6385@end defvr
401c53c4 6386
34760ae7
LC
6387@subsubsection Locale Data Compatibility Considerations
6388
6389@cindex incompatibility, of locale data
6390@code{operating-system} declarations provide a @code{locale-libcs} field
6391to specify the GNU@tie{}libc packages that are used to compile locale
6392declarations (@pxref{operating-system Reference}). ``Why would I
6393care?'', you may ask. Well, it turns out that the binary format of
6394locale data is occasionally incompatible from one libc version to
6395another.
6396
6397@c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
6398@c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
6399For instance, a program linked against libc version 2.21 is unable to
6400read locale data produced with libc 2.22; worse, that program
6401@emph{aborts} instead of simply ignoring the incompatible locale
6402data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
6403the incompatible locale data, which is already an improvement.}.
6404Similarly, a program linked against libc 2.22 can read most, but not
6405all, the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
6406data is incompatible); thus calls to @code{setlocale} may fail, but
6407programs will not abort.
6408
6409The ``problem'' in GuixSD is that users have a lot of freedom: They can
6410choose whether and when to upgrade software in their profiles, and might
6411be using a libc version different from the one the system administrator
6412used to build the system-wide locale data.
6413
6414Fortunately, unprivileged users can also install their own locale data
6415and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
6416@code{GUIX_LOCPATH} and locale packages}).
6417
6418Still, it is best if the system-wide locale data at
6419@file{/run/current-system/locale} is built for all the libc versions
6420actually in use on the system, so that all the programs can access
6421it---this is especially crucial on a multi-user system. To do that, the
6422administrator can specify several libc packages in the
6423@code{locale-libcs} field of @code{operating-system}:
6424
6425@example
6426(use-package-modules base)
6427
6428(operating-system
6429 ;; @dots{}
6430 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
6431@end example
6432
6433This example would lead to a system containing locale definitions for
6434both libc 2.21 and the current version of libc in
6435@file{/run/current-system/locale}.
6436
6437
cf4a9129
LC
6438@node Services
6439@subsection Services
401c53c4 6440
cf4a9129
LC
6441@cindex system services
6442An important part of preparing an @code{operating-system} declaration is
6443listing @dfn{system services} and their configuration (@pxref{Using the
6444Configuration System}). System services are typically daemons launched
6445when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
6446configuring network access.
6447
6448Services are managed by GNU@tie{}dmd (@pxref{Introduction,,, dmd, GNU
6449dmd Manual}). On a running system, the @command{deco} command allows
6450you to list the available services, show their status, start and stop
6451them, or do other specific operations (@pxref{Jump Start,,, dmd, GNU dmd
6452Manual}). For example:
6453
6454@example
6455# deco status dmd
6456@end example
6457
6458The above command, run as @code{root}, lists the currently defined
6459services. The @command{deco doc} command shows a synopsis of the given
6460service:
6461
6462@example
6463# deco doc nscd
6464Run libc's name service cache daemon (nscd).
6465@end example
6466
6467The @command{start}, @command{stop}, and @command{restart} sub-commands
6468have the effect you would expect. For instance, the commands below stop
6469the nscd service and restart the Xorg display server:
6470
6471@example
6472# deco stop nscd
6473Service nscd has been stopped.
6474# deco restart xorg-server
6475Service xorg-server has been stopped.
6476Service xorg-server has been started.
6477@end example
401c53c4 6478
cf4a9129 6479The following sections document the available services, starting with
d8b94dbd
LC
6480the core services, that may be used in an @code{operating-system}
6481declaration.
401c53c4 6482
cf4a9129
LC
6483@menu
6484* Base Services:: Essential system services.
6485* Networking Services:: Network setup, SSH daemon, etc.
6486* X Window:: Graphical display.
fe1a39d3 6487* Desktop Services:: D-Bus and desktop services.
105369a4 6488* Database Services:: SQL databases.
d8c18af8 6489* Mail Services:: IMAP, POP3, SMTP, and all that.
58724c48 6490* Web Services:: Web servers.
aa4ed923 6491* Various Services:: Other services.
cf4a9129 6492@end menu
401c53c4 6493
cf4a9129
LC
6494@node Base Services
6495@subsubsection Base Services
a1ba8475 6496
cf4a9129
LC
6497The @code{(gnu services base)} module provides definitions for the basic
6498services that one expects from the system. The services exported by
6499this module are listed below.
401c53c4 6500
cf4a9129 6501@defvr {Scheme Variable} %base-services
31771497
LC
6502This variable contains a list of basic services (@pxref{Service Types
6503and Services}, for more information on service objects) one would
cf4a9129
LC
6504expect from the system: a login service (mingetty) on each tty, syslogd,
6505libc's name service cache daemon (nscd), the udev device manager, and
6506more.
401c53c4 6507
cf4a9129
LC
6508This is the default value of the @code{services} field of
6509@code{operating-system} declarations. Usually, when customizing a
6510system, you will want to append services to @var{%base-services}, like
6511this:
401c53c4 6512
cf4a9129 6513@example
fa1e31b8 6514(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
6515@end example
6516@end defvr
401c53c4 6517
be1c2c54 6518@deffn {Scheme Procedure} host-name-service @var{name}
cf4a9129
LC
6519Return a service that sets the host name to @var{name}.
6520@end deffn
401c53c4 6521
66e4f01c
LC
6522@deffn {Scheme Procedure} mingetty-service @var{config}
6523Return a service to run mingetty according to @var{config}, a
6524@code{<mingetty-configuration>} object, which specifies the tty to run, among
6525other things.
cf4a9129 6526@end deffn
401c53c4 6527
66e4f01c
LC
6528@deftp {Data Type} mingetty-configuration
6529This is the data type representing the configuration of Mingetty, which
6530implements console log-in.
6531
6532@table @asis
6533
6534@item @code{tty}
6535The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
6536
6537@item @code{motd}
6538A file-like object containing the ``message of the day''.
6539
6540@item @code{auto-login} (default: @code{#f})
6541When true, this field must be a string denoting the user name under
f9b9a033 6542which the system automatically logs in. When it is @code{#f}, a
66e4f01c
LC
6543user name and password must be entered to log in.
6544
6545@item @code{login-program} (default: @code{#f})
6546This must be either @code{#f}, in which case the default log-in program
6547is used (@command{login} from the Shadow tool suite), or a gexp denoting
6548the name of the log-in program.
6549
6550@item @code{login-pause?} (default: @code{#f})
6551When set to @code{#t} in conjunction with @var{auto-login}, the user
6552will have to press a key before the log-in shell is launched.
6553
6554@item @code{mingetty} (default: @var{mingetty})
6555The Mingetty package to use.
6556
6557@end table
6558@end deftp
6559
6454b333
LC
6560@cindex name service cache daemon
6561@cindex nscd
be1c2c54 6562@deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
4aee6e60 6563 [#:name-services '()]
b893f1ae
LC
6564Return a service that runs libc's name service cache daemon (nscd) with the
6565given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
6566Service Switch}, for an example.
cf4a9129 6567@end deffn
401c53c4 6568
6454b333
LC
6569@defvr {Scheme Variable} %nscd-default-configuration
6570This is the default @code{<nscd-configuration>} value (see below) used
6571by @code{nscd-service}. This uses the caches defined by
6572@var{%nscd-default-caches}; see below.
6573@end defvr
6574
6575@deftp {Data Type} nscd-configuration
6576This is the type representing the name service cache daemon (nscd)
6577configuration.
6578
6579@table @asis
6580
b893f1ae
LC
6581@item @code{name-services} (default: @code{'()})
6582List of packages denoting @dfn{name services} that must be visible to
6583the nscd---e.g., @code{(list @var{nss-mdns})}.
6584
6585@item @code{glibc} (default: @var{glibc})
6586Package object denoting the GNU C Library providing the @command{nscd}
6587command.
6588
6454b333
LC
6589@item @code{log-file} (default: @code{"/var/log/nscd.log"})
6590Name of nscd's log file. This is where debugging output goes when
6591@code{debug-level} is strictly positive.
6592
6593@item @code{debug-level} (default: @code{0})
6594Integer denoting the debugging levels. Higher numbers mean more
6595debugging output is logged.
6596
6597@item @code{caches} (default: @var{%nscd-default-caches})
6598List of @code{<nscd-cache>} objects denoting things to be cached; see
6599below.
6600
6601@end table
6602@end deftp
6603
6604@deftp {Data Type} nscd-cache
6605Data type representing a cache database of nscd and its parameters.
6606
6607@table @asis
6608
6609@item @code{database}
6610This is a symbol representing the name of the database to be cached.
6611Valid values are @code{passwd}, @code{group}, @code{hosts}, and
6612@code{services}, which designate the corresponding NSS database
6613(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
6614
6615@item @code{positive-time-to-live}
6616@itemx @code{negative-time-to-live} (default: @code{20})
6617A number representing the number of seconds during which a positive or
6618negative lookup result remains in cache.
6619
6620@item @code{check-files?} (default: @code{#t})
6621Whether to check for updates of the files corresponding to
6622@var{database}.
6623
6624For instance, when @var{database} is @code{hosts}, setting this flag
6625instructs nscd to check for updates in @file{/etc/hosts} and to take
6626them into account.
6627
6628@item @code{persistent?} (default: @code{#t})
6629Whether the cache should be stored persistently on disk.
6630
6631@item @code{shared?} (default: @code{#t})
6632Whether the cache should be shared among users.
6633
6634@item @code{max-database-size} (default: 32@tie{}MiB)
6635Maximum size in bytes of the database cache.
6636
6637@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
6638@c settings, so leave them out.
6639
6640@end table
6641@end deftp
6642
6643@defvr {Scheme Variable} %nscd-default-caches
6644List of @code{<nscd-cache>} objects used by default by
6645@code{nscd-configuration} (see above.)
6646
6647It enables persistent and aggressive caching of service and host name
6648lookups. The latter provides better host name lookup performance,
6649resilience in the face of unreliable name servers, and also better
6650privacy---often the result of host name lookups is in local cache, so
6651external name servers do not even need to be queried.
6652@end defvr
6653
6654
be1c2c54 6655@deffn {Scheme Procedure} syslog-service [#:config-file #f]
1bb76f75
AK
6656Return a service that runs @code{syslogd}. If configuration file name
6657@var{config-file} is not specified, use some reasonable default
cf4a9129
LC
6658settings.
6659@end deffn
401c53c4 6660
0adfe95a
LC
6661@anchor{guix-configuration-type}
6662@deftp {Data Type} guix-configuration
6663This data type represents the configuration of the Guix build daemon.
6664@xref{Invoking guix-daemon}, for more information.
6665
6666@table @asis
6667@item @code{guix} (default: @var{guix})
6668The Guix package to use.
401c53c4 6669
0adfe95a
LC
6670@item @code{build-group} (default: @code{"guixbuild"})
6671Name of the group for build user accounts.
401c53c4 6672
0adfe95a
LC
6673@item @code{build-accounts} (default: @code{10})
6674Number of build user accounts to create.
401c53c4 6675
0adfe95a
LC
6676@item @code{authorize-key?} (default: @code{#t})
6677Whether to authorize the substitute key for @code{hydra.gnu.org}
6678(@pxref{Substitutes}).
6679
6680@item @code{use-substitutes?} (default: @code{#t})
6681Whether to use substitutes.
6682
b0b9f6e0
LC
6683@item @code{substitute-urls} (default: @var{%default-substitute-urls})
6684The list of URLs where to look for substitutes by default.
6685
0adfe95a
LC
6686@item @code{extra-options} (default: @code{'()})
6687List of extra command-line options for @command{guix-daemon}.
6688
6689@item @code{lsof} (default: @var{lsof})
6690@itemx @code{lsh} (default: @var{lsh})
6691The lsof and lsh packages to use.
6692
6693@end table
6694@end deftp
6695
6696@deffn {Scheme Procedure} guix-service @var{config}
6697Return a service that runs the Guix build daemon according to
6698@var{config}.
cf4a9129 6699@end deffn
a1ba8475 6700
be1c2c54 6701@deffn {Scheme Procedure} udev-service [#:udev udev]
cf4a9129
LC
6702Run @var{udev}, which populates the @file{/dev} directory dynamically.
6703@end deffn
401c53c4 6704
be1c2c54 6705@deffn {Scheme Procedure} console-keymap-service @var{file}
5eca9459
AK
6706Return a service to load console keymap from @var{file} using
6707@command{loadkeys} command.
6708@end deffn
6709
8664cc88
LC
6710@deffn {Scheme Procedure} gpm-service-type [#:gpm @var{gpm}] @
6711 [#:options]
6712Run @var{gpm}, the general-purpose mouse daemon, with the given
6713command-line @var{options}. GPM allows users to use the mouse in the console,
6714notably to select, copy, and paste text. The default value of @var{options}
6715uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
6716
6717This service is not part of @var{%base-services}.
6718@end deffn
6719
1c52181f
LC
6720@anchor{guix-publish-service}
6721@deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
6722 [#:port 80] [#:host "localhost"]
6723Return a service that runs @command{guix publish} listening on @var{host}
6724and @var{port} (@pxref{Invoking guix publish}).
6725
6726This assumes that @file{/etc/guix} already contains a signing key pair as
6727created by @command{guix archive --generate-key} (@pxref{Invoking guix
6728archive}). If that is not the case, the service will fail to start.
6729@end deffn
6730
a69576ea 6731
cf4a9129
LC
6732@node Networking Services
6733@subsubsection Networking Services
401c53c4 6734
fa1e31b8 6735The @code{(gnu services networking)} module provides services to configure
cf4a9129 6736the network interface.
a1ba8475 6737
a023cca8 6738@cindex DHCP, networking service
be1c2c54 6739@deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
a023cca8
LC
6740Return a service that runs @var{dhcp}, a Dynamic Host Configuration
6741Protocol (DHCP) client, on all the non-loopback network interfaces.
6742@end deffn
6743
be1c2c54 6744@deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
cf4a9129
LC
6745 [#:gateway #f] [#:name-services @code{'()}]
6746Return a service that starts @var{interface} with address @var{ip}. If
6747@var{gateway} is true, it must be a string specifying the default network
6748gateway.
6749@end deffn
8b315a6d 6750
b7d0c494 6751@cindex wicd
87f40011 6752@cindex network management
be1c2c54 6753@deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
87f40011
LC
6754Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
6755management daemon that aims to simplify wired and wireless networking.
6756
6757This service adds the @var{wicd} package to the global profile, providing
6758several commands to interact with the daemon and configure networking:
6759@command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
6760and @command{wicd-curses} user interfaces.
b7d0c494
MW
6761@end deffn
6762
c0a9589d
SB
6763@cindex NetworkManager
6764@deffn {Scheme Procedure} network-manager-service @
6765 [#:network-manager @var{network-manager}]
6766Return a service that runs NetworkManager, a network connection manager
6767that attempting to keep active network connectivity when available.
6768@end deffn
6769
be1c2c54 6770@deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
63854bcb
LC
6771 [#:name-service @var{%ntp-servers}]
6772Return a service that runs the daemon from @var{ntp}, the
6773@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
6774keep the system clock synchronized with that of @var{servers}.
6775@end deffn
6776
6777@defvr {Scheme Variable} %ntp-servers
6778List of host names used as the default NTP servers.
6779@end defvr
6780
375c6108
LC
6781@deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
6782Return a service to run the @uref{https://torproject.org, Tor} anonymous
6783networking daemon.
8b315a6d 6784
375c6108 6785The daemon runs as the @code{tor} unprivileged user. It is passed
6331bde7
LC
6786@var{config-file}, a file-like object, with an additional @code{User tor} line
6787and lines for hidden services added via @code{tor-hidden-service}. Run
6788@command{man tor} for information about the configuration file.
6789@end deffn
6790
6791@deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
6792Define a new Tor @dfn{hidden service} called @var{name} and implementing
6793@var{mapping}. @var{mapping} is a list of port/host tuples, such as:
6794
6795@example
6796 '((22 \"127.0.0.1:22\")
6797 (80 \"127.0.0.1:8080\"))
6798@end example
6799
6800In this example, port 22 of the hidden service is mapped to local port 22, and
6801port 80 is mapped to local port 8080.
6802
6629099a
LC
6803This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
6804the @file{hostname} file contains the @code{.onion} host name for the hidden
6331bde7
LC
6805service.
6806
6807See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
6808project's documentation} for more information.
cf4a9129 6809@end deffn
8b315a6d 6810
be1c2c54 6811@deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
4627a464
LC
6812 [#:interface "127.0.0.1"] [#:port 6667] @
6813 [#:extra-settings ""]
6814Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
6815acts as a gateway between IRC and chat networks.
6816
6817The daemon will listen to the interface corresponding to the IP address
6818specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
6819local clients can connect, whereas @code{0.0.0.0} means that connections can
6820come from any networking interface.
6821
6822In addition, @var{extra-settings} specifies a string to append to the
6823configuration file.
6824@end deffn
6825
f4391bec 6826Furthermore, @code{(gnu services ssh)} provides the following service.
8b315a6d 6827
be1c2c54 6828@deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 6829 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
6830 [#:allow-empty-passwords? #f] [#:root-login? #f] @
6831 [#:syslog-output? #t] [#:x11-forwarding? #t] @
6832 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 6833 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
6834Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
6835@var{host-key} must designate a file containing the host key, and readable
6836only by root.
72e25e35 6837
5833bf33
DP
6838When @var{daemonic?} is true, @command{lshd} will detach from the
6839controlling terminal and log its output to syslogd, unless one sets
6840@var{syslog-output?} to false. Obviously, it also makes lsh-service
6841depend on existence of syslogd service. When @var{pid-file?} is true,
6842@command{lshd} writes its PID to the file called @var{pid-file}.
6843
cf4a9129
LC
6844When @var{initialize?} is true, automatically create the seed and host key
6845upon service activation if they do not exist yet. This may take long and
6846require interaction.
8b315a6d 6847
20dd519c
LC
6848When @var{initialize?} is false, it is up to the user to initialize the
6849randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
6850a key pair with the private key stored in file @var{host-key} (@pxref{lshd
6851basics,,, lsh, LSH Manual}).
6852
cf4a9129
LC
6853When @var{interfaces} is empty, lshd listens for connections on all the
6854network interfaces; otherwise, @var{interfaces} must be a list of host names
6855or addresses.
9bf3c1a7 6856
20dd519c
LC
6857@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
6858passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 6859root.
4af2447e 6860
cf4a9129
LC
6861The other options should be self-descriptive.
6862@end deffn
4af2447e 6863
fa0c1d61
LC
6864@defvr {Scheme Variable} %facebook-host-aliases
6865This variable contains a string for use in @file{/etc/hosts}
6866(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
6867line contains a entry that maps a known server name of the Facebook
6868on-line service---e.g., @code{www.facebook.com}---to the local
6869host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
6870
6871This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
6872@code{operating-system} declaration (@pxref{operating-system Reference,
6873@file{/etc/hosts}}):
fa0c1d61
LC
6874
6875@example
6876(use-modules (gnu) (guix))
6877
6878(operating-system
6879 (host-name "mymachine")
6880 ;; ...
6881 (hosts-file
6882 ;; Create a /etc/hosts file with aliases for "localhost"
6883 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
6884 (plain-file "hosts"
6885 (string-append (local-host-aliases host-name)
6886 %facebook-host-aliases))))
fa0c1d61
LC
6887@end example
6888
6889This mechanism can prevent programs running locally, such as Web
6890browsers, from accessing Facebook.
6891@end defvr
6892
965a7332
LC
6893The @code{(gnu services avahi)} provides the following definition.
6894
be1c2c54 6895@deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
965a7332
LC
6896 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
6897 [#:ipv6? #t] [#:wide-area? #f] @
6898 [#:domains-to-browse '()]
6899Return a service that runs @command{avahi-daemon}, a system-wide
6900mDNS/DNS-SD responder that allows for service discovery and
cc9c1f39
LC
6901"zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
6902extends the name service cache daemon (nscd) so that it can resolve
6903@code{.local} host names using
1065bed9
LC
6904@uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
6905add the @var{avahi} package to the system profile so that commands such as
6906@command{avahi-browse} are directly usable.
965a7332
LC
6907
6908If @var{host-name} is different from @code{#f}, use that as the host name to
6909publish for this machine; otherwise, use the machine's actual host name.
6910
6911When @var{publish?} is true, publishing of host names and services is allowed;
6912in particular, avahi-daemon will publish the machine's host name and IP
6913address via mDNS on the local network.
6914
6915When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
6916
6917Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
6918sockets.
6919@end deffn
6920
6921
cf4a9129
LC
6922@node X Window
6923@subsubsection X Window
68ad877c 6924
cf4a9129
LC
6925Support for the X Window graphical display system---specifically
6926Xorg---is provided by the @code{(gnu services xorg)} module. Note that
6927there is no @code{xorg-service} procedure. Instead, the X server is
6928started by the @dfn{login manager}, currently SLiM.
4af2447e 6929
be1c2c54 6930@deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
6931 [#:auto-login? #f] [#:default-user ""] [#:startx] @
6932 [#:theme @var{%default-slim-theme}] @
4bd43bbe 6933 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
6934Return a service that spawns the SLiM graphical login manager, which in
6935turn starts the X display server with @var{startx}, a command as returned by
6936@code{xorg-start-command}.
4af2447e 6937
04e4e6ab
LC
6938@cindex X session
6939
6940SLiM automatically looks for session types described by the @file{.desktop}
6941files in @file{/run/current-system/profile/share/xsessions} and allows users
6942to choose a session from the log-in screen using @kbd{F1}. Packages such as
6943@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
6944adding them to the system-wide set of packages automatically makes them
6945available at the log-in screen.
6946
6947In addition, @file{~/.xsession} files are honored. When available,
6948@file{~/.xsession} must be an executable that starts a window manager
6949and/or other X clients.
6950
cf4a9129
LC
6951When @var{allow-empty-passwords?} is true, allow logins with an empty
6952password. When @var{auto-login?} is true, log in automatically as
6953@var{default-user}.
0ecc3bf3
LC
6954
6955If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
6956@var{theme} must be a gexp denoting the name of a directory containing the
6957theme to use. In that case, @var{theme-name} specifies the name of the
6958theme.
cf4a9129 6959@end deffn
4af2447e 6960
0ecc3bf3
LC
6961@defvr {Scheme Variable} %default-theme
6962@defvrx {Scheme Variable} %default-theme-name
6963The G-Expression denoting the default SLiM theme and its name.
6964@end defvr
6965
be1c2c54 6966@deffn {Scheme Procedure} xorg-start-command [#:guile] @
d1cdd7ba 6967 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 6968Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
6969from @var{xorg-server}. @var{configuration-file} is the server configuration
6970file or a derivation that builds it; when omitted, the result of
6971@code{xorg-configuration-file} is used.
6972
6973Usually the X server is started by a login manager.
6974@end deffn
6975
be1c2c54 6976@deffn {Scheme Procedure} xorg-configuration-file @
12422c9d 6977 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
6978Return a configuration file for the Xorg server containing search paths for
6979all the common drivers.
f703413e
LC
6980
6981@var{drivers} must be either the empty list, in which case Xorg chooses a
6982graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 6983this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
6984
6985Likewise, when @var{resolutions} is the empty list, Xorg chooses an
6986appropriate screen resolution; otherwise, it must be a list of
6987resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
6988
6989Last, @var{extra-config} is a list of strings or objects appended to the
6990@code{text-file*} argument list. It is used to pass extra text to be added
6991verbatim to the configuration file.
f703413e 6992@end deffn
4af2447e 6993
6726282b
LC
6994@deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
6995Add @var{package}, a package for a screen-locker or screen-saver whose
6996command is @var{program}, to the set of setuid programs and add a PAM entry
6997for it. For example:
6998
6999@lisp
7000(screen-locker-service xlockmore "xlock")
7001@end lisp
7002
7003makes the good ol' XlockMore usable.
7004@end deffn
7005
7006
fe1a39d3
LC
7007@node Desktop Services
7008@subsubsection Desktop Services
aa4ed923 7009
fe1a39d3
LC
7010The @code{(gnu services desktop)} module provides services that are
7011usually useful in the context of a ``desktop'' setup---that is, on a
7012machine running a graphical display server, possibly with graphical user
7013interfaces, etc.
aa4ed923 7014
4467be21
LC
7015To simplify things, the module defines a variable containing the set of
7016services that users typically expect on a machine with a graphical
7017environment and networking:
7018
7019@defvr {Scheme Variable} %desktop-services
7020This is a list of services that builds upon @var{%base-services} and
7021adds or adjust services for a typical ``desktop'' setup.
7022
7023In particular, it adds a graphical login manager (@pxref{X Window,
6726282b
LC
7024@code{slim-service}}), screen lockers,
7025a network management tool (@pxref{Networking
4467be21 7026Services, @code{wicd-service}}), energy and color management services,
4650a77e 7027the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
7028the GeoClue location service, an NTP client (@pxref{Networking
7029Services}), the Avahi daemon, and has the name service switch service
7030configured to be able to use @code{nss-mdns} (@pxref{Name Service
7031Switch, mDNS}).
4467be21
LC
7032@end defvr
7033
7034The @var{%desktop-services} variable can be used as the @code{services}
7035field of an @code{operating-system} declaration (@pxref{operating-system
7036Reference, @code{services}}).
7037
0adfe95a
LC
7038The actual service definitions provided by @code{(gnu services dbus)}
7039and @code{(gnu services desktop)} are described below.
4467be21 7040
0adfe95a 7041@deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
fe1a39d3
LC
7042Return a service that runs the ``system bus'', using @var{dbus}, with
7043support for @var{services}.
aa4ed923 7044
fe1a39d3
LC
7045@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
7046facility. Its system bus is used to allow system services to communicate
7047and be notified of system-wide events.
aa4ed923 7048
fe1a39d3
LC
7049@var{services} must be a list of packages that provide an
7050@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
7051and policy files. For example, to allow avahi-daemon to use the system bus,
7052@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
7053@end deffn
7054
0adfe95a 7055@deffn {Scheme Procedure} elogind-service [#:config @var{config}]
4650a77e
AW
7056Return a service that runs the @code{elogind} login and
7057seat management daemon. @uref{https://github.com/andywingo/elogind,
7058Elogind} exposes a D-Bus interface that can be used to know which users
7059are logged in, know what kind of sessions they have open, suspend the
7060system, inhibit system suspend, reboot the system, and other tasks.
7061
7062Elogind handles most system-level power events for a computer, for
7063example suspending the system when a lid is closed, or shutting it down
7064when the power button is pressed.
7065
7066The @var{config} keyword argument specifies the configuration for
7067elogind, and should be the result of a @code{(elogind-configuration
7068(@var{parameter} @var{value})...)} invocation. Available parameters and
7069their default values are:
7070
7071@table @code
7072@item kill-user-processes?
7073@code{#f}
7074@item kill-only-users
7075@code{()}
7076@item kill-exclude-users
7077@code{("root")}
7078@item inhibit-delay-max-seconds
7079@code{5}
7080@item handle-power-key
7081@code{poweroff}
7082@item handle-suspend-key
7083@code{suspend}
7084@item handle-hibernate-key
7085@code{hibernate}
7086@item handle-lid-switch
7087@code{suspend}
7088@item handle-lid-switch-docked
7089@code{ignore}
7090@item power-key-ignore-inhibited?
7091@code{#f}
7092@item suspend-key-ignore-inhibited?
7093@code{#f}
7094@item hibernate-key-ignore-inhibited?
7095@code{#f}
7096@item lid-switch-ignore-inhibited?
7097@code{#t}
7098@item holdoff-timeout-seconds
7099@code{30}
7100@item idle-action
7101@code{ignore}
7102@item idle-action-seconds
7103@code{(* 30 60)}
7104@item runtime-directory-size-percent
7105@code{10}
7106@item runtime-directory-size
7107@code{#f}
7108@item remove-ipc?
7109@code{#t}
7110@item suspend-state
7111@code{("mem" "standby" "freeze")}
7112@item suspend-mode
7113@code{()}
7114@item hibernate-state
7115@code{("disk")}
7116@item hibernate-mode
7117@code{("platform" "shutdown")}
7118@item hybrid-sleep-state
7119@code{("disk")}
7120@item hybrid-sleep-mode
7121@code{("suspend" "platform" "shutdown")}
7122@end table
7123@end deffn
7124
be1c2c54 7125@deffn {Scheme Procedure} polkit-service @
4650a77e 7126 [#:polkit @var{polkit}]
222e3319
LC
7127Return a service that runs the
7128@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
7129management service}, which allows system administrators to grant access to
7130privileged operations in a structured way. By querying the Polkit service, a
7131privileged system component can know when it should grant additional
7132capabilities to ordinary users. For example, an ordinary user can be granted
7133the capability to suspend the system if the user is logged in locally.
4650a77e
AW
7134@end deffn
7135
be1c2c54 7136@deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
be234128
AW
7137 [#:watts-up-pro? #f] @
7138 [#:poll-batteries? #t] @
7139 [#:ignore-lid? #f] @
7140 [#:use-percentage-for-policy? #f] @
7141 [#:percentage-low 10] @
7142 [#:percentage-critical 3] @
7143 [#:percentage-action 2] @
7144 [#:time-low 1200] @
7145 [#:time-critical 300] @
7146 [#:time-action 120] @
7147 [#:critical-power-action 'hybrid-sleep]
7148Return a service that runs @uref{http://upower.freedesktop.org/,
7149@command{upowerd}}, a system-wide monitor for power consumption and battery
7150levels, with the given configuration settings. It implements the
7151@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
7152GNOME.
7153@end deffn
7154
2b9e0a94
LC
7155@deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
7156Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
7157UDisks}, a @dfn{disk management} daemon that provides user interfaces with
7158notifications and ways to mount/unmount disks. Programs that talk to UDisks
7159include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
7160@end deffn
7161
be1c2c54 7162@deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7ce597ff
AW
7163Return a service that runs @command{colord}, a system service with a D-Bus
7164interface to manage the color profiles of input and output devices such as
7165screens and scanners. It is notably used by the GNOME Color Manager graphical
7166tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
7167site} for more information.
7168@end deffn
7169
cee32ee4
AW
7170@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
7171Return an configuration allowing an application to access GeoClue
7172location data. @var{name} is the Desktop ID of the application, without
7173the @code{.desktop} part. If @var{allowed?} is true, the application
7174will have access to location information by default. The boolean
7175@var{system?} value indicates that an application is a system component
7176or not. Finally @var{users} is a list of UIDs of all users for which
7177this application is allowed location info access. An empty users list
7178means that all users are allowed.
7179@end deffn
7180
7181@defvr {Scheme Variable} %standard-geoclue-applications
7182The standard list of well-known GeoClue application configurations,
7183granting authority to GNOME's date-and-time utility to ask for the
7184current location in order to set the time zone, and allowing the Firefox
7185(IceCat) and Epiphany web browsers to request location information.
7186Firefox and Epiphany both query the user before allowing a web page to
7187know the user's location.
7188@end defvr
7189
be1c2c54 7190@deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
cee32ee4
AW
7191 [#:whitelist '()] @
7192 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
7193 [#:submit-data? #f]
7194 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
7195 [#:submission-nick "geoclue"] @
7196 [#:applications %standard-geoclue-applications]
7197Return a service that runs the GeoClue location service. This service
7198provides a D-Bus interface to allow applications to request access to a
7199user's physical location, and optionally to add information to online
7200location databases. See
7201@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
7202web site} for more information.
7203@end deffn
7204
105369a4
DT
7205@node Database Services
7206@subsubsection Database Services
7207
7208The @code{(gnu services databases)} module provides the following service.
7209
be1c2c54 7210@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
105369a4
DT
7211 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
7212Return a service that runs @var{postgresql}, the PostgreSQL database
7213server.
7214
7215The PostgreSQL daemon loads its runtime configuration from
7216@var{config-file} and stores the database cluster in
7217@var{data-directory}.
7218@end deffn
fe1a39d3 7219
d8c18af8
AW
7220@node Mail Services
7221@subsubsection Mail Services
7222
7223The @code{(gnu services mail)} module provides Guix service definitions
7224for mail services. Currently the only implemented service is Dovecot,
7225an IMAP, POP3, and LMTP server.
7226
7227Guix does not yet have a mail transfer agent (MTA), although for some
7228lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
7229is needed to properly integrate a full MTA, such as Postfix. Patches
7230welcome!
7231
7232To add an IMAP/POP3 server to a GuixSD system, add a
7233@code{dovecot-service} to the operating system definition:
7234
7235@deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
7236Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
7237@end deffn
7238
7239By default, Dovecot doesn't need much configuration; the default
7240configuration object created by @code{(dovecot-configuration)} will
7241suffice if your mail is delivered to @code{~/Maildir}. A self-signed
7242certificate will be generated for TLS-protected connections, though
7243Dovecot will also listen on cleartext ports by default. There are a
7244number of options though which mail administrators might need to change,
7245and as is the case with other services, Guix allows the system
7246administrator to specify these parameters via a uniform Scheme interface.
7247
7248For example, to specify that mail is located at @code{maildir~/.mail},
7249one would instantiate the Dovecot service like this:
7250
7251@example
7252(dovecot-service #:config
7253 (dovecot-configuration
7254 (mail-location "maildir:~/.mail")))
7255@end example
7256
7257The available configuration parameters follow. Each parameter
7258definition is preceded by its type; for example, @samp{string-list foo}
7259indicates that the @code{foo} parameter should be specified as a list of
7260strings. There is also a way to specify the configuration as a string,
7261if you have an old @code{dovecot.conf} file that you want to port over
7262from some other system; see the end for more details.
7263
7264@c The following documentation was initially generated by
7265@c (generate-documentation) in (gnu services mail). Manually maintained
7266@c documentation is better, so we shouldn't hesitate to edit below as
7267@c needed. However if the change you want to make to this documentation
7268@c can be done in an automated way, it's probably easier to change
7269@c (generate-documentation) than to make it below and have to deal with
7270@c the churn as dovecot updates.
7271
7272Available @code{dovecot-configuration} fields are:
7273
7274@deftypevr {@code{dovecot-configuration} parameter} package dovecot
7275The dovecot package.
7276@end deftypevr
7277
7278@deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
7279A list of IPs or hosts where to listen in for connections. @samp{*}
7280listens in all IPv4 interfaces, @samp{::} listens in all IPv6
7281interfaces. If you want to specify non-default ports or anything more
7282complex, customize the address and port fields of the
7283@samp{inet-listener} of the specific services you are interested in.
7284@end deftypevr
7285
7286@deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
7287List of protocols we want to serve. Available protocols include
7288@samp{imap}, @samp{pop3}, and @samp{lmtp}.
7289
7290Available @code{protocol-configuration} fields are:
7291
7292@deftypevr {@code{protocol-configuration} parameter} string name
7293The name of the protocol.
7294@end deftypevr
7295
7296@deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
7297UNIX socket path to master authentication server to find users.
7298This is used by imap (for shared users) and lda.
7299Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
7300@end deftypevr
7301
7302@deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
7303Space separated list of plugins to load.
7304@end deftypevr
7305
7306@deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
7307Maximum number of IMAP connections allowed for a user from each IP
7308address. NOTE: The username is compared case-sensitively.
7309Defaults to @samp{10}.
7310@end deftypevr
7311
7312@end deftypevr
7313
7314@deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
7315List of services to enable. Available services include @samp{imap},
7316@samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
7317@samp{lmtp}.
7318
7319Available @code{service-configuration} fields are:
7320
7321@deftypevr {@code{service-configuration} parameter} string kind
7322The service kind. Valid values include @code{director},
7323@code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
7324@code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
7325@code{tcpwrap}, @code{quota-warning}, or anything else.
7326@end deftypevr
7327
7328@deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
7329Listeners for the service. A listener is either an
7330@code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
7331an @code{inet-listener-configuration}.
7332Defaults to @samp{()}.
7333
7334Available @code{unix-listener-configuration} fields are:
7335
7336@deftypevr {@code{unix-listener-configuration} parameter} file-name path
7337The file name on which to listen.
7338@end deftypevr
7339
7340@deftypevr {@code{unix-listener-configuration} parameter} string mode
7341The access mode for the socket.
7342Defaults to @samp{"0600"}.
7343@end deftypevr
7344
7345@deftypevr {@code{unix-listener-configuration} parameter} string user
f9b9a033 7346The user to own the socket.
d8c18af8
AW
7347Defaults to @samp{""}.
7348@end deftypevr
7349
7350@deftypevr {@code{unix-listener-configuration} parameter} string group
7351The group to own the socket.
7352Defaults to @samp{""}.
7353@end deftypevr
7354
7355
7356Available @code{fifo-listener-configuration} fields are:
7357
7358@deftypevr {@code{fifo-listener-configuration} parameter} file-name path
7359The file name on which to listen.
7360@end deftypevr
7361
7362@deftypevr {@code{fifo-listener-configuration} parameter} string mode
7363The access mode for the socket.
7364Defaults to @samp{"0600"}.
7365@end deftypevr
7366
7367@deftypevr {@code{fifo-listener-configuration} parameter} string user
f9b9a033 7368The user to own the socket.
d8c18af8
AW
7369Defaults to @samp{""}.
7370@end deftypevr
7371
7372@deftypevr {@code{fifo-listener-configuration} parameter} string group
7373The group to own the socket.
7374Defaults to @samp{""}.
7375@end deftypevr
7376
7377
7378Available @code{inet-listener-configuration} fields are:
7379
7380@deftypevr {@code{inet-listener-configuration} parameter} string protocol
7381The protocol to listen for.
7382@end deftypevr
7383
7384@deftypevr {@code{inet-listener-configuration} parameter} string address
7385The address on which to listen, or empty for all addresses.
7386Defaults to @samp{""}.
7387@end deftypevr
7388
7389@deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
7390The port on which to listen.
7391@end deftypevr
7392
7393@deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
7394Whether to use SSL for this service; @samp{yes}, @samp{no}, or
7395@samp{required}.
7396Defaults to @samp{#t}.
7397@end deftypevr
7398
7399@end deftypevr
7400
7401@deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
7402Number of connections to handle before starting a new process.
7403Typically the only useful values are 0 (unlimited) or 1. 1 is more
7404secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
7405Defaults to @samp{1}.
7406@end deftypevr
7407
7408@deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
7409Number of processes to always keep waiting for more connections.
7410Defaults to @samp{0}.
7411@end deftypevr
7412
7413@deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
7414If you set @samp{service-count 0}, you probably need to grow
7415this.
7416Defaults to @samp{256000000}.
7417@end deftypevr
7418
7419@end deftypevr
7420
7421@deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
7422Dict configuration, as created by the @code{dict-configuration}
7423constructor.
7424
7425Available @code{dict-configuration} fields are:
7426
7427@deftypevr {@code{dict-configuration} parameter} free-form-fields entries
7428A list of key-value pairs that this dict should hold.
7429Defaults to @samp{()}.
7430@end deftypevr
7431
7432@end deftypevr
7433
7434@deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
7435List of passdb configurations, each one created by the
7436@code{passdb-configuration} constructor.
7437
7438Available @code{passdb-configuration} fields are:
7439
7440@deftypevr {@code{passdb-configuration} parameter} string driver
7441The driver that the passdb should use. Valid values include
7442@samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
7443@samp{static}.
7444Defaults to @samp{"pam"}.
7445@end deftypevr
7446
7447@deftypevr {@code{passdb-configuration} parameter} free-form-args args
7448A list of key-value args to the passdb driver.
7449Defaults to @samp{()}.
7450@end deftypevr
7451
7452@end deftypevr
7453
7454@deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
7455List of userdb configurations, each one created by the
7456@code{userdb-configuration} constructor.
7457
7458Available @code{userdb-configuration} fields are:
7459
7460@deftypevr {@code{userdb-configuration} parameter} string driver
7461The driver that the userdb should use. Valid values include
7462@samp{passwd} and @samp{static}.
7463Defaults to @samp{"passwd"}.
7464@end deftypevr
7465
7466@deftypevr {@code{userdb-configuration} parameter} free-form-args args
7467A list of key-value args to the userdb driver.
7468Defaults to @samp{()}.
7469@end deftypevr
7470
7471@deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
7472Override fields from passwd.
7473Defaults to @samp{()}.
7474@end deftypevr
7475
7476@end deftypevr
7477
7478@deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
7479Plug-in configuration, created by the @code{plugin-configuration}
7480constructor.
7481@end deftypevr
7482
7483@deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
7484List of namespaces. Each item in the list is created by the
7485@code{namespace-configuration} constructor.
7486
7487Available @code{namespace-configuration} fields are:
7488
7489@deftypevr {@code{namespace-configuration} parameter} string name
7490Name for this namespace.
7491@end deftypevr
7492
7493@deftypevr {@code{namespace-configuration} parameter} string type
7494Namespace type: @samp{private}, @samp{shared} or @samp{public}.
7495Defaults to @samp{"private"}.
7496@end deftypevr
7497
7498@deftypevr {@code{namespace-configuration} parameter} string separator
7499Hierarchy separator to use. You should use the same separator for
7500all namespaces or some clients get confused. @samp{/} is usually a good
7501one. The default however depends on the underlying mail storage
7502format.
7503Defaults to @samp{""}.
7504@end deftypevr
7505
7506@deftypevr {@code{namespace-configuration} parameter} string prefix
7507Prefix required to access this namespace. This needs to be
7508different for all namespaces. For example @samp{Public/}.
7509Defaults to @samp{""}.
7510@end deftypevr
7511
7512@deftypevr {@code{namespace-configuration} parameter} string location
7513Physical location of the mailbox. This is in same format as
7514mail_location, which is also the default for it.
7515Defaults to @samp{""}.
7516@end deftypevr
7517
7518@deftypevr {@code{namespace-configuration} parameter} boolean inbox?
7519There can be only one INBOX, and this setting defines which
7520namespace has it.
7521Defaults to @samp{#f}.
7522@end deftypevr
7523
7524@deftypevr {@code{namespace-configuration} parameter} boolean hidden?
7525If namespace is hidden, it's not advertised to clients via NAMESPACE
7526extension. You'll most likely also want to set @samp{list? #f}. This is mostly
7527useful when converting from another server with different namespaces
7528which you want to deprecate but still keep working. For example you can
7529create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
7530and @samp{mail/}.
7531Defaults to @samp{#f}.
7532@end deftypevr
7533
7534@deftypevr {@code{namespace-configuration} parameter} boolean list?
7535Show the mailboxes under this namespace with LIST command. This
7536makes the namespace visible for clients that don't support NAMESPACE
7537extension. The special @code{children} value lists child mailboxes, but
7538hides the namespace prefix.
7539Defaults to @samp{#t}.
7540@end deftypevr
7541
7542@deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
7543Namespace handles its own subscriptions. If set to @code{#f}, the
7544parent namespace handles them. The empty prefix should always have this
7545as @code{#t}.)
7546Defaults to @samp{#t}.
7547@end deftypevr
7548
7549@deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
7550List of predefined mailboxes in this namespace.
7551Defaults to @samp{()}.
7552
7553Available @code{mailbox-configuration} fields are:
7554
7555@deftypevr {@code{mailbox-configuration} parameter} string name
7556Name for this mailbox.
7557@end deftypevr
7558
7559@deftypevr {@code{mailbox-configuration} parameter} string auto
7560@samp{create} will automatically create this mailbox.
7561@samp{subscribe} will both create and subscribe to the mailbox.
7562Defaults to @samp{"no"}.
7563@end deftypevr
7564
7565@deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
7566List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
7567Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
7568@code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
7569Defaults to @samp{()}.
7570@end deftypevr
7571
7572@end deftypevr
7573
7574@end deftypevr
7575
7576@deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
7577Base directory where to store runtime data.
7578Defaults to @samp{"/var/run/dovecot/"}.
7579@end deftypevr
7580
7581@deftypevr {@code{dovecot-configuration} parameter} string login-greeting
7582Greeting message for clients.
7583Defaults to @samp{"Dovecot ready."}.
7584@end deftypevr
7585
7586@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
7587List of trusted network ranges. Connections from these IPs are
7588allowed to override their IP addresses and ports (for logging and for
7589authentication checks). @samp{disable-plaintext-auth} is also ignored
7590for these networks. Typically you'd specify your IMAP proxy servers
7591here.
7592Defaults to @samp{()}.
7593@end deftypevr
7594
7595@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
7596List of login access check sockets (e.g. tcpwrap).
7597Defaults to @samp{()}.
7598@end deftypevr
7599
7600@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
7601Show more verbose process titles (in ps). Currently shows user name
7602and IP address. Useful for seeing who are actually using the IMAP
7603processes (e.g. shared mailboxes or if same uid is used for multiple
7604accounts).
7605Defaults to @samp{#f}.
7606@end deftypevr
7607
7608@deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
7609Should all processes be killed when Dovecot master process shuts down.
7610Setting this to @code{#f} means that Dovecot can be upgraded without
7611forcing existing client connections to close (although that could also
7612be a problem if the upgrade is e.g. because of a security fix).
7613Defaults to @samp{#t}.
7614@end deftypevr
7615
7616@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
7617If non-zero, run mail commands via this many connections to doveadm
7618server, instead of running them directly in the same process.
7619Defaults to @samp{0}.
7620@end deftypevr
7621
7622@deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
7623UNIX socket or host:port used for connecting to doveadm server.
7624Defaults to @samp{"doveadm-server"}.
7625@end deftypevr
7626
7627@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
7628List of environment variables that are preserved on Dovecot startup
7629and passed down to all of its child processes. You can also give
7630key=value pairs to always set specific settings.
7631@end deftypevr
7632
7633@deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
7634Disable LOGIN command and all other plaintext authentications unless
7635SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
7636matches the local IP (i.e. you're connecting from the same computer),
7637the connection is considered secure and plaintext authentication is
7638allowed. See also ssl=required setting.
7639Defaults to @samp{#t}.
7640@end deftypevr
7641
7642@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
7643Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
7644Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
7645for caching to be used.
7646Defaults to @samp{0}.
7647@end deftypevr
7648
7649@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
7650Time to live for cached data. After TTL expires the cached record
7651is no longer used, *except* if the main database lookup returns internal
7652failure. We also try to handle password changes automatically: If
7653user's previous authentication was successful, but this one wasn't, the
7654cache isn't used. For now this works only with plaintext
7655authentication.
7656Defaults to @samp{"1 hour"}.
7657@end deftypevr
7658
7659@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
7660TTL for negative hits (user not found, password mismatch).
76610 disables caching them completely.
7662Defaults to @samp{"1 hour"}.
7663@end deftypevr
7664
7665@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
7666List of realms for SASL authentication mechanisms that need them.
7667You can leave it empty if you don't want to support multiple realms.
7668Many clients simply use the first one listed here, so keep the default
7669realm first.
7670Defaults to @samp{()}.
7671@end deftypevr
7672
7673@deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
7674Default realm/domain to use if none was specified. This is used for
7675both SASL realms and appending @@domain to username in plaintext
7676logins.
7677Defaults to @samp{""}.
7678@end deftypevr
7679
7680@deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
7681List of allowed characters in username. If the user-given username
7682contains a character not listed in here, the login automatically fails.
7683This is just an extra check to make sure user can't exploit any
7684potential quote escaping vulnerabilities with SQL/LDAP databases. If
7685you want to allow all characters, set this value to empty.
7686Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
7687@end deftypevr
7688
7689@deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
7690Username character translations before it's looked up from
7691databases. The value contains series of from -> to characters. For
7692example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
7693translated to @samp{@@}.
7694Defaults to @samp{""}.
7695@end deftypevr
7696
7697@deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
7698Username formatting before it's looked up from databases. You can
7699use the standard variables here, e.g. %Lu would lowercase the username,
7700%n would drop away the domain if it was given, or @samp{%n-AT-%d} would
7701change the @samp{@@} into @samp{-AT-}. This translation is done after
7702@samp{auth-username-translation} changes.
7703Defaults to @samp{"%Lu"}.
7704@end deftypevr
7705
7706@deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
7707If you want to allow master users to log in by specifying the master
7708username within the normal username string (i.e. not using SASL
7709mechanism's support for it), you can specify the separator character
7710here. The format is then <username><separator><master username>.
7711UW-IMAP uses @samp{*} as the separator, so that could be a good
7712choice.
7713Defaults to @samp{""}.
7714@end deftypevr
7715
7716@deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
7717Username to use for users logging in with ANONYMOUS SASL
7718mechanism.
7719Defaults to @samp{"anonymous"}.
7720@end deftypevr
7721
7722@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
7723Maximum number of dovecot-auth worker processes. They're used to
7724execute blocking passdb and userdb queries (e.g. MySQL and PAM).
7725They're automatically created and destroyed as needed.
7726Defaults to @samp{30}.
7727@end deftypevr
7728
7729@deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
7730Host name to use in GSSAPI principal names. The default is to use
7731the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
7732allow all keytab entries.
7733Defaults to @samp{""}.
7734@end deftypevr
7735
7736@deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
7737Kerberos keytab to use for the GSSAPI mechanism. Will use the
7738system default (usually /etc/krb5.keytab) if not specified. You may
7739need to change the auth service to run as root to be able to read this
7740file.
7741Defaults to @samp{""}.
7742@end deftypevr
7743
7744@deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
7745Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
7746and @samp{ntlm-auth} helper.
7747<doc/wiki/Authentication/Mechanisms/Winbind.txt>.
7748Defaults to @samp{#f}.
7749@end deftypevr
7750
7751@deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
7752Path for Samba's @samp{ntlm-auth} helper binary.
7753Defaults to @samp{"/usr/bin/ntlm_auth"}.
7754@end deftypevr
7755
7756@deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
7757Time to delay before replying to failed authentications.
7758Defaults to @samp{"2 secs"}.
7759@end deftypevr
7760
7761@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
7762Require a valid SSL client certificate or the authentication
7763fails.
7764Defaults to @samp{#f}.
7765@end deftypevr
7766
7767@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
7768Take the username from client's SSL certificate, using
7769@code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
7770CommonName.
7771Defaults to @samp{#f}.
7772@end deftypevr
7773
7774@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
7775List of wanted authentication mechanisms. Supported mechanisms are:
7776@samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
7777@samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
7778@samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
7779@samp{disable-plaintext-auth} setting.
7780@end deftypevr
7781
7782@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
7783List of IPs or hostnames to all director servers, including ourself.
7784Ports can be specified as ip:port. The default port is the same as what
7785director service's @samp{inet-listener} is using.
7786Defaults to @samp{()}.
7787@end deftypevr
7788
7789@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
7790List of IPs or hostnames to all backend mail servers. Ranges are
7791allowed too, like 10.0.0.10-10.0.0.30.
7792Defaults to @samp{()}.
7793@end deftypevr
7794
7795@deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
7796How long to redirect users to a specific server after it no longer
7797has any connections.
7798Defaults to @samp{"15 min"}.
7799@end deftypevr
7800
7801@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
7802TCP/IP port that accepts doveadm connections (instead of director
7803connections) If you enable this, you'll also need to add
7804@samp{inet-listener} for the port.
7805Defaults to @samp{0}.
7806@end deftypevr
7807
7808@deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
7809How the username is translated before being hashed. Useful values
7810include %Ln if user can log in with or without @@domain, %Ld if mailboxes
7811are shared within domain.
7812Defaults to @samp{"%Lu"}.
7813@end deftypevr
7814
7815@deftypevr {@code{dovecot-configuration} parameter} string log-path
7816Log file to use for error messages. @samp{syslog} logs to syslog,
7817@samp{/dev/stderr} logs to stderr.
7818Defaults to @samp{"syslog"}.
7819@end deftypevr
7820
7821@deftypevr {@code{dovecot-configuration} parameter} string info-log-path
7822Log file to use for informational messages. Defaults to
7823@samp{log-path}.
7824Defaults to @samp{""}.
7825@end deftypevr
7826
7827@deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
7828Log file to use for debug messages. Defaults to
7829@samp{info-log-path}.
7830Defaults to @samp{""}.
7831@end deftypevr
7832
7833@deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
7834Syslog facility to use if you're logging to syslog. Usually if you
7835don't want to use @samp{mail}, you'll use local0..local7. Also other
7836standard facilities are supported.
7837Defaults to @samp{"mail"}.
7838@end deftypevr
7839
7840@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
7841Log unsuccessful authentication attempts and the reasons why they
7842failed.
7843Defaults to @samp{#f}.
7844@end deftypevr
7845
7846@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
7847In case of password mismatches, log the attempted password. Valid
7848values are no, plain and sha1. sha1 can be useful for detecting brute
7849force password attempts vs. user simply trying the same password over
7850and over again. You can also truncate the value to n chars by appending
7851":n" (e.g. sha1:6).
7852Defaults to @samp{#f}.
7853@end deftypevr
7854
7855@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
7856Even more verbose logging for debugging purposes. Shows for example
7857SQL queries.
7858Defaults to @samp{#f}.
7859@end deftypevr
7860
7861@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
7862In case of password mismatches, log the passwords and used scheme so
7863the problem can be debugged. Enabling this also enables
7864@samp{auth-debug}.
7865Defaults to @samp{#f}.
7866@end deftypevr
7867
7868@deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
7869Enable mail process debugging. This can help you figure out why
7870Dovecot isn't finding your mails.
7871Defaults to @samp{#f}.
7872@end deftypevr
7873
7874@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
7875Show protocol level SSL errors.
7876Defaults to @samp{#f}.
7877@end deftypevr
7878
7879@deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
7880Prefix for each line written to log file. % codes are in
7881strftime(3) format.
7882Defaults to @samp{"\"%b %d %H:%M:%S \""}.
7883@end deftypevr
7884
7885@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
7886List of elements we want to log. The elements which have a
7887non-empty variable value are joined together to form a comma-separated
7888string.
7889@end deftypevr
7890
7891@deftypevr {@code{dovecot-configuration} parameter} string login-log-format
7892Login log format. %s contains @samp{login-log-format-elements}
7893string, %$ contains the data we want to log.
7894Defaults to @samp{"%$: %s"}.
7895@end deftypevr
7896
7897@deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
7898Log prefix for mail processes. See doc/wiki/Variables.txt for list
7899of possible variables you can use.
7900Defaults to @samp{"\"%s(%u): \""}.
7901@end deftypevr
7902
7903@deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
7904Format to use for logging mail deliveries. You can use variables:
7905@table @code
7906@item %$
7907Delivery status message (e.g. @samp{saved to INBOX})
7908@item %m
7909Message-ID
7910@item %s
7911Subject
7912@item %f
7913From address
7914@item %p
7915Physical size
7916@item %w
7917Virtual size.
7918@end table
7919Defaults to @samp{"msgid=%m: %$"}.
7920@end deftypevr
7921
7922@deftypevr {@code{dovecot-configuration} parameter} string mail-location
7923Location for users' mailboxes. The default is empty, which means
7924that Dovecot tries to find the mailboxes automatically. This won't work
7925if the user doesn't yet have any mail, so you should explicitly tell
7926Dovecot the full location.
7927
7928If you're using mbox, giving a path to the INBOX
7929file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
7930where the other mailboxes are kept. This is called the "root mail
7931directory", and it must be the first path given in the
7932@samp{mail-location} setting.
7933
7934There are a few special variables you can use, eg.:
7935
7936@table @samp
7937@item %u
7938username
7939@item %n
7940user part in user@@domain, same as %u if there's no domain
7941@item %d
7942domain part in user@@domain, empty if there's no domain
7943@item %h
7944home director
7945@end table
7946
7947See doc/wiki/Variables.txt for full list. Some examples:
7948@table @samp
7949@item maildir:~/Maildir
7950@item mbox:~/mail:INBOX=/var/mail/%u
7951@item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
7952@end table
7953Defaults to @samp{""}.
7954@end deftypevr
7955
7956@deftypevr {@code{dovecot-configuration} parameter} string mail-uid
7957System user and group used to access mails. If you use multiple,
7958userdb can override these by returning uid or gid fields. You can use
7959either numbers or names. <doc/wiki/UserIds.txt>.
7960Defaults to @samp{""}.
7961@end deftypevr
7962
7963@deftypevr {@code{dovecot-configuration} parameter} string mail-gid
7964
7965Defaults to @samp{""}.
7966@end deftypevr
7967
7968@deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
7969Group to enable temporarily for privileged operations. Currently
7970this is used only with INBOX when either its initial creation or
7971dotlocking fails. Typically this is set to "mail" to give access to
7972/var/mail.
7973Defaults to @samp{""}.
7974@end deftypevr
7975
7976@deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
7977Grant access to these supplementary groups for mail processes.
7978Typically these are used to set up access to shared mailboxes. Note
7979that it may be dangerous to set these if users can create
7980symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
7981could allow a user to delete others' mailboxes, or ln -s
7982/secret/shared/box ~/mail/mybox would allow reading it).
7983Defaults to @samp{""}.
7984@end deftypevr
7985
7986@deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
7987Allow full filesystem access to clients. There's no access checks
7988other than what the operating system does for the active UID/GID. It
7989works with both maildir and mboxes, allowing you to prefix mailboxes
7990names with e.g. /path/ or ~user/.
7991Defaults to @samp{#f}.
7992@end deftypevr
7993
7994@deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
7995Don't use mmap() at all. This is required if you store indexes to
7996shared filesystems (NFS or clustered filesystem).
7997Defaults to @samp{#f}.
7998@end deftypevr
7999
8000@deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
8001Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
8002supports @samp{O_EXCL} since version 3, so this should be safe to use
8003nowadays by default.
8004Defaults to @samp{#t}.
8005@end deftypevr
8006
8007@deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
8008When to use fsync() or fdatasync() calls:
8009@table @code
8010@item optimized
8011Whenever necessary to avoid losing important data
8012@item always
8013Useful with e.g. NFS when write()s are delayed
8014@item never
8015Never use it (best performance, but crashes can lose data).
8016@end table
8017Defaults to @samp{"optimized"}.
8018@end deftypevr
8019
8020@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
8021Mail storage exists in NFS. Set this to yes to make Dovecot flush
8022NFS caches whenever needed. If you're using only a single mail server
8023this isn't needed.
8024Defaults to @samp{#f}.
8025@end deftypevr
8026
8027@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
8028Mail index files also exist in NFS. Setting this to yes requires
8029@samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
8030Defaults to @samp{#f}.
8031@end deftypevr
8032
8033@deftypevr {@code{dovecot-configuration} parameter} string lock-method
8034Locking method for index files. Alternatives are fcntl, flock and
8035dotlock. Dotlocking uses some tricks which may create more disk I/O
8036than other locking methods. NFS users: flock doesn't work, remember to
8037change @samp{mmap-disable}.
8038Defaults to @samp{"fcntl"}.
8039@end deftypevr
8040
8041@deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
8042Directory in which LDA/LMTP temporarily stores incoming mails >128
8043kB.
8044Defaults to @samp{"/tmp"}.
8045@end deftypevr
8046
8047@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
8048Valid UID range for users. This is mostly to make sure that users can't
8049log in as daemons or other system users. Note that denying root logins is
8050hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
8051is set to 0.
8052Defaults to @samp{500}.
8053@end deftypevr
8054
8055@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
8056
8057Defaults to @samp{0}.
8058@end deftypevr
8059
8060@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
8061Valid GID range for users. Users having non-valid GID as primary group ID
8062aren't allowed to log in. If user belongs to supplementary groups with
8063non-valid GIDs, those groups are not set.
8064Defaults to @samp{1}.
8065@end deftypevr
8066
8067@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
8068
8069Defaults to @samp{0}.
8070@end deftypevr
8071
8072@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
8073Maximum allowed length for mail keyword name. It's only forced when
8074trying to create new keywords.
8075Defaults to @samp{50}.
8076@end deftypevr
8077
8078@deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
8079List of directories under which chrooting is allowed for mail
8080processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
8081too). This setting doesn't affect @samp{login-chroot}
8082@samp{mail-chroot} or auth chroot settings. If this setting is empty,
8083"/./" in home dirs are ignored. WARNING: Never add directories here
8084which local users can modify, that may lead to root exploit. Usually
8085this should be done only if you don't allow shell access for users.
8086<doc/wiki/Chrooting.txt>.
8087Defaults to @samp{()}.
8088@end deftypevr
8089
8090@deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
8091Default chroot directory for mail processes. This can be overridden
8092for specific users in user database by giving /./ in user's home
8093directory (e.g. /home/./user chroots into /home). Note that usually
8094there is no real need to do chrooting, Dovecot doesn't allow users to
8095access files outside their mail directory anyway. If your home
8096directories are prefixed with the chroot directory, append "/." to
8097@samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
8098Defaults to @samp{""}.
8099@end deftypevr
8100
8101@deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
8102UNIX socket path to master authentication server to find users.
8103This is used by imap (for shared users) and lda.
8104Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
8105@end deftypevr
8106
8107@deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
8108Directory where to look up mail plugins.
8109Defaults to @samp{"/usr/lib/dovecot"}.
8110@end deftypevr
8111
8112@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
8113List of plugins to load for all services. Plugins specific to IMAP,
8114LDA, etc. are added to this list in their own .conf files.
8115Defaults to @samp{()}.
8116@end deftypevr
8117
8118@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
8119The minimum number of mails in a mailbox before updates are done to
8120cache file. This allows optimizing Dovecot's behavior to do less disk
8121writes at the cost of more disk reads.
8122Defaults to @samp{0}.
8123@end deftypevr
8124
8125@deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
8126When IDLE command is running, mailbox is checked once in a while to
8127see if there are any new mails or other changes. This setting defines
8128the minimum time to wait between those checks. Dovecot can also use
8129dnotify, inotify and kqueue to find out immediately when changes
8130occur.
8131Defaults to @samp{"30 secs"}.
8132@end deftypevr
8133
8134@deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
8135Save mails with CR+LF instead of plain LF. This makes sending those
8136mails take less CPU, especially with sendfile() syscall with Linux and
8137FreeBSD. But it also creates a bit more disk I/O which may just make it
8138slower. Also note that if other software reads the mboxes/maildirs,
8139they may handle the extra CRs wrong and cause problems.
8140Defaults to @samp{#f}.
8141@end deftypevr
8142
8143@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
8144By default LIST command returns all entries in maildir beginning
8145with a dot. Enabling this option makes Dovecot return only entries
8146which are directories. This is done by stat()ing each entry, so it
8147causes more disk I/O.
8148 (For systems setting struct @samp{dirent->d_type} this check is free
8149and it's done always regardless of this setting).
8150Defaults to @samp{#f}.
8151@end deftypevr
8152
8153@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
8154When copying a message, do it with hard links whenever possible.
8155This makes the performance much better, and it's unlikely to have any
8156side effects.
8157Defaults to @samp{#t}.
8158@end deftypevr
8159
8160@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
8161Assume Dovecot is the only MUA accessing Maildir: Scan cur/
8162directory only when its mtime changes unexpectedly or when we can't find
8163the mail otherwise.
8164Defaults to @samp{#f}.
8165@end deftypevr
8166
8167@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
8168Which locking methods to use for locking mbox. There are four
8169available:
8170
8171@table @code
8172@item dotlock
8173Create <mailbox>.lock file. This is the oldest and most NFS-safe
8174solution. If you want to use /var/mail/ like directory, the users will
8175need write access to that directory.
8176@item dotlock-try
8177Same as dotlock, but if it fails because of permissions or because there
8178isn't enough disk space, just skip it.
8179@item fcntl
8180Use this if possible. Works with NFS too if lockd is used.
8181@item flock
8182May not exist in all systems. Doesn't work with NFS.
8183@item lockf
8184May not exist in all systems. Doesn't work with NFS.
8185@end table
8186
8187You can use multiple locking methods; if you do the order they're declared
8188in is important to avoid deadlocks if other MTAs/MUAs are using multiple
8189locking methods as well. Some operating systems don't allow using some of
8190them simultaneously.
8191@end deftypevr
8192
8193@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
8194
8195@end deftypevr
8196
8197@deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
8198Maximum time to wait for lock (all of them) before aborting.
8199Defaults to @samp{"5 mins"}.
8200@end deftypevr
8201
8202@deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
8203If dotlock exists but the mailbox isn't modified in any way,
8204override the lock file after this much time.
8205Defaults to @samp{"2 mins"}.
8206@end deftypevr
8207
8208@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
8209When mbox changes unexpectedly we have to fully read it to find out
8210what changed. If the mbox is large this can take a long time. Since
8211the change is usually just a newly appended mail, it'd be faster to
8212simply read the new mails. If this setting is enabled, Dovecot does
8213this but still safely fallbacks to re-reading the whole mbox file
8214whenever something in mbox isn't how it's expected to be. The only real
8215downside to this setting is that if some other MUA changes message
8216flags, Dovecot doesn't notice it immediately. Note that a full sync is
8217done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
8218Defaults to @samp{#t}.
8219@end deftypevr
8220
8221@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
8222Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
8223EXAMINE, EXPUNGE or CHECK commands. If this is set,
8224@samp{mbox-dirty-syncs} is ignored.
8225Defaults to @samp{#f}.
8226@end deftypevr
8227
8228@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
8229Delay writing mbox headers until doing a full write sync (EXPUNGE
8230and CHECK commands and when closing the mailbox). This is especially
8231useful for POP3 where clients often delete all mails. The downside is
8232that our changes aren't immediately visible to other MUAs.
8233Defaults to @samp{#t}.
8234@end deftypevr
8235
8236@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
8237If mbox size is smaller than this (e.g. 100k), don't write index
8238files. If an index file already exists it's still read, just not
8239updated.
8240Defaults to @samp{0}.
8241@end deftypevr
8242
8243@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
8244Maximum dbox file size until it's rotated.
8245Defaults to @samp{2000000}.
8246@end deftypevr
8247
8248@deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
8249Maximum dbox file age until it's rotated. Typically in days. Day
8250begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
8251disabled.
8252Defaults to @samp{"1d"}.
8253@end deftypevr
8254
8255@deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
8256When creating new mdbox files, immediately preallocate their size to
8257@samp{mdbox-rotate-size}. This setting currently works only in Linux
8258with some filesystems (ext4, xfs).
8259Defaults to @samp{#f}.
8260@end deftypevr
8261
8262@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
8263sdbox and mdbox support saving mail attachments to external files,
8264which also allows single instance storage for them. Other backends
8265don't support this for now.
8266
8267WARNING: This feature hasn't been tested much yet. Use at your own risk.
8268
8269Directory root where to store mail attachments. Disabled, if empty.
8270Defaults to @samp{""}.
8271@end deftypevr
8272
8273@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
8274Attachments smaller than this aren't saved externally. It's also
8275possible to write a plugin to disable saving specific attachments
8276externally.
8277Defaults to @samp{128000}.
8278@end deftypevr
8279
8280@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
8281Filesystem backend to use for saving attachments:
8282@table @code
8283@item posix
8284No SiS done by Dovecot (but this might help FS's own deduplication)
8285@item sis posix
8286SiS with immediate byte-by-byte comparison during saving
8287@item sis-queue posix
8288SiS with delayed comparison and deduplication.
8289@end table
8290Defaults to @samp{"sis posix"}.
8291@end deftypevr
8292
8293@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
8294Hash format to use in attachment filenames. You can add any text and
8295variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
8296@code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
8297truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
8298Defaults to @samp{"%@{sha1@}"}.
8299@end deftypevr
8300
8301@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
8302
8303Defaults to @samp{100}.
8304@end deftypevr
8305
8306@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
8307
8308Defaults to @samp{1000}.
8309@end deftypevr
8310
8311@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
8312Default VSZ (virtual memory size) limit for service processes.
8313This is mainly intended to catch and kill processes that leak memory
8314before they eat up everything.
8315Defaults to @samp{256000000}.
8316@end deftypevr
8317
8318@deftypevr {@code{dovecot-configuration} parameter} string default-login-user
8319Login user is internally used by login processes. This is the most
8320untrusted user in Dovecot system. It shouldn't have access to anything
8321at all.
8322Defaults to @samp{"dovenull"}.
8323@end deftypevr
8324
8325@deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
8326Internal user is used by unprivileged processes. It should be
8327separate from login user, so that login processes can't disturb other
8328processes.
8329Defaults to @samp{"dovecot"}.
8330@end deftypevr
8331
8332@deftypevr {@code{dovecot-configuration} parameter} string ssl?
8333SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
8334Defaults to @samp{"required"}.
8335@end deftypevr
8336
8337@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
8338PEM encoded X.509 SSL/TLS certificate (public key).
8339Defaults to @samp{"</etc/dovecot/default.pem"}.
8340@end deftypevr
8341
8342@deftypevr {@code{dovecot-configuration} parameter} string ssl-key
8343PEM encoded SSL/TLS private key. The key is opened before
8344dropping root privileges, so keep the key file unreadable by anyone but
8345root.
8346Defaults to @samp{"</etc/dovecot/private/default.pem"}.
8347@end deftypevr
8348
8349@deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
8350If key file is password protected, give the password here.
8351Alternatively give it when starting dovecot with -p parameter. Since
8352this file is often world-readable, you may want to place this setting
8353instead to a different.
8354Defaults to @samp{""}.
8355@end deftypevr
8356
8357@deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
8358PEM encoded trusted certificate authority. Set this only if you
8359intend to use @samp{ssl-verify-client-cert? #t}. The file should
8360contain the CA certificate(s) followed by the matching
8361CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
8362Defaults to @samp{""}.
8363@end deftypevr
8364
8365@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
8366Require that CRL check succeeds for client certificates.
8367Defaults to @samp{#t}.
8368@end deftypevr
8369
8370@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
8371Request client to send a certificate. If you also want to require
8372it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
8373Defaults to @samp{#f}.
8374@end deftypevr
8375
8376@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
8377Which field from certificate to use for username. commonName and
8378x500UniqueIdentifier are the usual choices. You'll also need to set
8379@samp{auth-ssl-username-from-cert? #t}.
8380Defaults to @samp{"commonName"}.
8381@end deftypevr
8382
8383@deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
8384How often to regenerate the SSL parameters file. Generation is
8385quite CPU intensive operation. The value is in hours, 0 disables
8386regeneration entirely.
8387Defaults to @samp{168}.
8388@end deftypevr
8389
8390@deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
8391SSL protocols to use.
8392Defaults to @samp{"!SSLv2"}.
8393@end deftypevr
8394
8395@deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
8396SSL ciphers to use.
8397Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
8398@end deftypevr
8399
8400@deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
8401SSL crypto device to use, for valid values run "openssl engine".
8402Defaults to @samp{""}.
8403@end deftypevr
8404
8405@deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
8406Address to use when sending rejection mails.
8407Default is postmaster@@<your domain>. %d expands to recipient domain.
8408Defaults to @samp{""}.
8409@end deftypevr
8410
8411@deftypevr {@code{dovecot-configuration} parameter} string hostname
8412Hostname to use in various parts of sent mails (e.g. in Message-Id)
8413and in LMTP replies. Default is the system's real hostname@@domain.
8414Defaults to @samp{""}.
8415@end deftypevr
8416
8417@deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
8418If user is over quota, return with temporary failure instead of
8419bouncing the mail.
8420Defaults to @samp{#f}.
8421@end deftypevr
8422
8423@deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
8424Binary to use for sending mails.
8425Defaults to @samp{"/usr/sbin/sendmail"}.
8426@end deftypevr
8427
8428@deftypevr {@code{dovecot-configuration} parameter} string submission-host
8429If non-empty, send mails via this SMTP host[:port] instead of
8430sendmail.
8431Defaults to @samp{""}.
8432@end deftypevr
8433
8434@deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
8435Subject: header to use for rejection mails. You can use the same
8436variables as for @samp{rejection-reason} below.
8437Defaults to @samp{"Rejected: %s"}.
8438@end deftypevr
8439
8440@deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
8441Human readable error message for rejection mails. You can use
8442variables:
8443
8444@table @code
8445@item %n
8446CRLF
8447@item %r
8448reason
8449@item %s
8450original subject
8451@item %t
8452recipient
8453@end table
8454Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
8455@end deftypevr
8456
8457@deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
8458Delimiter character between local-part and detail in email
8459address.
8460Defaults to @samp{"+"}.
8461@end deftypevr
8462
8463@deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
8464Header where the original recipient address (SMTP's RCPT TO:
8465address) is taken from if not available elsewhere. With dovecot-lda -a
8466parameter overrides this. A commonly used header for this is
8467X-Original-To.
8468Defaults to @samp{""}.
8469@end deftypevr
8470
8471@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
8472Should saving a mail to a nonexistent mailbox automatically create
8473it?.
8474Defaults to @samp{#f}.
8475@end deftypevr
8476
8477@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
8478Should automatically created mailboxes be also automatically
8479subscribed?.
8480Defaults to @samp{#f}.
8481@end deftypevr
8482
8483@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
8484Maximum IMAP command line length. Some clients generate very long
8485command lines with huge mailboxes, so you may need to raise this if you
8486get "Too long argument" or "IMAP command line too large" errors
8487often.
8488Defaults to @samp{64000}.
8489@end deftypevr
8490
8491@deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
8492IMAP logout format string:
8493@table @code
8494@item %i
8495total number of bytes read from client
8496@item %o
8497total number of bytes sent to client.
8498@end table
8499Defaults to @samp{"in=%i out=%o"}.
8500@end deftypevr
8501
8502@deftypevr {@code{dovecot-configuration} parameter} string imap-capability
8503Override the IMAP CAPABILITY response. If the value begins with '+',
8504add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
8505Defaults to @samp{""}.
8506@end deftypevr
8507
8508@deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
8509How long to wait between "OK Still here" notifications when client
8510is IDLEing.
8511Defaults to @samp{"2 mins"}.
8512@end deftypevr
8513
8514@deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
8515ID field names and values to send to clients. Using * as the value
8516makes Dovecot use the default value. The following fields have default
8517values currently: name, version, os, os-version, support-url,
8518support-email.
8519Defaults to @samp{""}.
8520@end deftypevr
8521
8522@deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
8523ID fields sent by client to log. * means everything.
8524Defaults to @samp{""}.
8525@end deftypevr
8526
8527@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
8528Workarounds for various client bugs:
8529
8530@table @code
8531@item delay-newmail
8532Send EXISTS/RECENT new mail notifications only when replying to NOOP and
8533CHECK commands. Some clients ignore them otherwise, for example OSX
8534Mail (<v2.1). Outlook Express breaks more badly though, without this it
8535may show user "Message no longer in server" errors. Note that OE6
8536still breaks even with this workaround if synchronization is set to
8537"Headers Only".
8538
8539@item tb-extra-mailbox-sep
8540Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
8541adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
8542ignore the extra @samp{/} instead of treating it as invalid mailbox name.
8543
8544@item tb-lsub-flags
8545Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
8546This makes Thunderbird realize they aren't selectable and show them
8547greyed out, instead of only later giving "not selectable" popup error.
8548@end table
8549Defaults to @samp{()}.
8550@end deftypevr
8551
8552@deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
8553Host allowed in URLAUTH URLs sent by client. "*" allows all.
8554Defaults to @samp{""}.
8555@end deftypevr
8556
8557
8558Whew! Lots of configuration options. The nice thing about it though is
8559that GuixSD has a complete interface to Dovecot's configuration
8560language. This allows not only a nice way to declare configurations,
8561but also offers reflective capabilities as well: users can write code to
8562inspect and transform configurations from within Scheme.
8563
8564However, it could be that you just want to get a @code{dovecot.conf} up
8565and running. In that case, you can pass an
8566@code{opaque-dovecot-configuration} as the @code{#:config} paramter to
8567@code{dovecot-service}. As its name indicates, an opaque configuration
8568does not have easy reflective capabilities.
8569
8570Available @code{opaque-dovecot-configuration} fields are:
8571
8572@deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
8573The dovecot package.
8574@end deftypevr
8575
8576@deftypevr {@code{opaque-dovecot-configuration} parameter} string string
8577The contents of the @code{dovecot.conf}, as a string.
8578@end deftypevr
8579
8580For example, if your @code{dovecot.conf} is just the empty string, you
8581could instantiate a dovecot service like this:
8582
8583@example
8584(dovecot-service #:config
8585 (opaque-dovecot-configuration
8586 (string "")))
8587@end example
8588
58724c48
DT
8589@node Web Services
8590@subsubsection Web Services
8591
8592The @code{(gnu services web)} module provides the following service:
8593
be1c2c54 8594@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
58724c48
DT
8595 [#:log-directory ``/var/log/nginx''] @
8596 [#:run-directory ``/var/run/nginx''] @
8597 [#:config-file]
8598
8599Return a service that runs @var{nginx}, the nginx web server.
8600
8601The nginx daemon loads its runtime configuration from @var{config-file}.
8602Log files are written to @var{log-directory} and temporary runtime data
8603files are written to @var{run-directory}. For proper operation, these
8604arguments should match what is in @var{config-file} to ensure that the
8605directories are created when the service is activated.
8606
8607@end deffn
8608
fe1a39d3
LC
8609@node Various Services
8610@subsubsection Various Services
8611
8612The @code{(gnu services lirc)} module provides the following service.
8613
be1c2c54 8614@deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
fe1a39d3
LC
8615 [#:device #f] [#:driver #f] [#:config-file #f] @
8616 [#:extra-options '()]
8617Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
8618decodes infrared signals from remote controls.
8619
8620Optionally, @var{device}, @var{driver} and @var{config-file}
8621(configuration file name) may be specified. See @command{lircd} manual
8622for details.
8623
8624Finally, @var{extra-options} is a list of additional command-line options
8625passed to @command{lircd}.
8626@end deffn
8627
8628
0ae8c15a
LC
8629@node Setuid Programs
8630@subsection Setuid Programs
8631
8632@cindex setuid programs
8633Some programs need to run with ``root'' privileges, even when they are
8634launched by unprivileged users. A notorious example is the
4d40227c
LC
8635@command{passwd} program, which users can run to change their
8636password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
8637@file{/etc/shadow} files---something normally restricted to root, for
8638obvious security reasons. To address that, these executables are
8639@dfn{setuid-root}, meaning that they always run with root privileges
8640(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
f7e4ae7f 8641for more info about the setuid mechanism.)
0ae8c15a
LC
8642
8643The store itself @emph{cannot} contain setuid programs: that would be a
8644security issue since any user on the system can write derivations that
8645populate the store (@pxref{The Store}). Thus, a different mechanism is
8646used: instead of changing the setuid bit directly on files that are in
8647the store, we let the system administrator @emph{declare} which programs
8648should be setuid root.
8649
8650The @code{setuid-programs} field of an @code{operating-system}
8651declaration contains a list of G-expressions denoting the names of
8652programs to be setuid-root (@pxref{Using the Configuration System}).
8653For instance, the @command{passwd} program, which is part of the Shadow
8654package, can be designated by this G-expression (@pxref{G-Expressions}):
8655
8656@example
8657#~(string-append #$shadow "/bin/passwd")
8658@end example
8659
8660A default set of setuid programs is defined by the
8661@code{%setuid-programs} variable of the @code{(gnu system)} module.
8662
8663@defvr {Scheme Variable} %setuid-programs
8664A list of G-expressions denoting common programs that are setuid-root.
8665
8666The list includes commands such as @command{passwd}, @command{ping},
8667@command{su}, and @command{sudo}.
8668@end defvr
8669
8670Under the hood, the actual setuid programs are created in the
8671@file{/run/setuid-programs} directory at system activation time. The
8672files in this directory refer to the ``real'' binaries, which are in the
8673store.
8674
efb5e833
LC
8675@node X.509 Certificates
8676@subsection X.509 Certificates
8677
8678@cindex HTTPS, certificates
8679@cindex X.509 certificates
8680@cindex TLS
8681Web servers available over HTTPS (that is, HTTP over the transport-layer
8682security mechanism, TLS) send client programs an @dfn{X.509 certificate}
8683that the client can then use to @emph{authenticate} the server. To do
8684that, clients verify that the server's certificate is signed by a
8685so-called @dfn{certificate authority} (CA). But to verify the CA's
8686signature, clients must have first acquired the CA's certificate.
8687
8688Web browsers such as GNU@tie{}IceCat include their own set of CA
8689certificates, such that they are able to verify CA signatures
8690out-of-the-box.
8691
8692However, most other programs that can talk HTTPS---@command{wget},
8693@command{git}, @command{w3m}, etc.---need to be told where CA
8694certificates can be found.
8695
8696@cindex @code{nss-certs}
8697In GuixSD, this is done by adding a package that provides certificates
8698to the @code{packages} field of the @code{operating-system} declaration
8699(@pxref{operating-system Reference}). GuixSD includes one such package,
8700@code{nss-certs}, which is a set of CA certificates provided as part of
8701Mozilla's Network Security Services.
8702
8703Note that it is @emph{not} part of @var{%base-packages}, so you need to
8704explicitly add it. The @file{/etc/ssl/certs} directory, which is where
8705most applications and libraries look for certificates by default, points
8706to the certificates installed globally.
8707
8708Unprivileged users can also install their own certificate package in
8709their profile. A number of environment variables need to be defined so
8710that applications and libraries know where to find them. Namely, the
8711OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
8712variables. Some applications add their own environment variables; for
8713instance, the Git version control system honors the certificate bundle
8714pointed to by the @code{GIT_SSL_CAINFO} environment variable.
8715
8716
996ed739
LC
8717@node Name Service Switch
8718@subsection Name Service Switch
8719
8720@cindex name service switch
8721@cindex NSS
8722The @code{(gnu system nss)} module provides bindings to the
8723configuration file of libc's @dfn{name service switch} or @dfn{NSS}
8724(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
8725Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
8726extended with new ``name'' lookup methods for system databases, which
8727includes host names, service names, user accounts, and more (@pxref{Name
8728Service Switch, System Databases and Name Service Switch,, libc, The GNU
8729C Library Reference Manual}).
8730
8731The NSS configuration specifies, for each system database, which lookup
8732method is to be used, and how the various methods are chained
8733together---for instance, under which circumstances NSS should try the
8734next method in the list. The NSS configuration is given in the
8735@code{name-service-switch} field of @code{operating-system} declarations
8736(@pxref{operating-system Reference, @code{name-service-switch}}).
8737
4c9050c6
LC
8738@cindex nss-mdns
8739@cindex .local, host name lookup
996ed739 8740As an example, the declaration below configures the NSS to use the
4c9050c6
LC
8741@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
8742back-end}, which supports host name lookups over multicast DNS (mDNS)
8743for host names ending in @code{.local}:
996ed739
LC
8744
8745@example
8746(name-service-switch
8747 (hosts (list %files ;first, check /etc/hosts
8748
8749 ;; If the above did not succeed, try
8750 ;; with 'mdns_minimal'.
8751 (name-service
8752 (name "mdns_minimal")
8753
8754 ;; 'mdns_minimal' is authoritative for
8755 ;; '.local'. When it returns "not found",
8756 ;; no need to try the next methods.
8757 (reaction (lookup-specification
8758 (not-found => return))))
8759
8760 ;; Then fall back to DNS.
8761 (name-service
8762 (name "dns"))
8763
8764 ;; Finally, try with the "full" 'mdns'.
8765 (name-service
8766 (name "mdns")))))
8767@end example
8768
15137a29
LC
8769Don't worry: the @code{%mdns-host-lookup-nss} variable (see below)
8770contains this configuration, so you won't have to type it if all you
8771want is to have @code{.local} host lookup working.
8772
4c9050c6
LC
8773Note that, in this case, in addition to setting the
8774@code{name-service-switch} of the @code{operating-system} declaration,
cc9c1f39
LC
8775you also need to use @code{avahi-service} (@pxref{Networking Services,
8776@code{avahi-service}}), or @var{%desktop-services}, which includes it
8777(@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
8778to the name service cache daemon (@pxref{Base Services,
8779@code{nscd-service}}).
15137a29
LC
8780
8781For convenience, the following variables provide typical NSS
8782configurations.
8783
8784@defvr {Scheme Variable} %default-nss
8785This is the default name service switch configuration, a
8786@code{name-service-switch} object.
8787@end defvr
8788
8789@defvr {Scheme Variable} %mdns-host-lookup-nss
8790This is the name service switch configuration with support for host name
8791lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
8792@end defvr
4c9050c6 8793
996ed739
LC
8794The reference for name service switch configuration is given below. It
8795is a direct mapping of the C library's configuration file format, so
8796please refer to the C library manual for more information (@pxref{NSS
8797Configuration File,,, libc, The GNU C Library Reference Manual}).
8798Compared to libc's NSS configuration file format, it has the advantage
8799not only of adding this warm parenthetic feel that we like, but also
8800static checks: you'll know about syntax errors and typos as soon as you
8801run @command{guix system}.
8802
996ed739
LC
8803@deftp {Data Type} name-service-switch
8804
8805This is the data type representation the configuration of libc's name
8806service switch (NSS). Each field below represents one of the supported
8807system databases.
8808
8809@table @code
8810@item aliases
8811@itemx ethers
8812@itemx group
8813@itemx gshadow
8814@itemx hosts
8815@itemx initgroups
8816@itemx netgroup
8817@itemx networks
8818@itemx password
8819@itemx public-key
8820@itemx rpc
8821@itemx services
8822@itemx shadow
8823The system databases handled by the NSS. Each of these fields must be a
8824list of @code{<name-service>} objects (see below.)
8825@end table
8826@end deftp
8827
8828@deftp {Data Type} name-service
8829
8830This is the data type representing an actual name service and the
8831associated lookup action.
8832
8833@table @code
8834@item name
8835A string denoting the name service (@pxref{Services in the NSS
8836configuration,,, libc, The GNU C Library Reference Manual}).
8837
4aee6e60
LC
8838Note that name services listed here must be visible to nscd. This is
8839achieved by passing the @code{#:name-services} argument to
8840@code{nscd-service} the list of packages providing the needed name
8841services (@pxref{Base Services, @code{nscd-service}}).
8842
996ed739
LC
8843@item reaction
8844An action specified using the @code{lookup-specification} macro
8845(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
8846Reference Manual}). For example:
8847
8848@example
8849(lookup-specification (unavailable => continue)
8850 (success => return))
8851@end example
8852@end table
8853@end deftp
0ae8c15a 8854
fd1b1fa2
LC
8855@node Initial RAM Disk
8856@subsection Initial RAM Disk
8857
8858@cindex initial RAM disk (initrd)
8859@cindex initrd (initial RAM disk)
8860For bootstrapping purposes, the Linux-Libre kernel is passed an
8861@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
8862root file system, as well as an initialization script. The latter is
8863responsible for mounting the real root file system, and for loading any
8864kernel modules that may be needed to achieve that.
8865
8866The @code{initrd} field of an @code{operating-system} declaration allows
8867you to specify which initrd you would like to use. The @code{(gnu
8868system linux-initrd)} module provides two ways to build an initrd: the
8869high-level @code{base-initrd} procedure, and the low-level
8870@code{expression->initrd} procedure.
8871
8872The @code{base-initrd} procedure is intended to cover most common uses.
8873For example, if you want to add a bunch of kernel modules to be loaded
8874at boot time, you can define the @code{initrd} field of the operating
8875system declaration like this:
8876
8877@example
52ac153e 8878(initrd (lambda (file-systems . rest)
027981d6
LC
8879 ;; Create a standard initrd that has modules "foo.ko"
8880 ;; and "bar.ko", as well as their dependencies, in
8881 ;; addition to the modules available by default.
52ac153e 8882 (apply base-initrd file-systems
027981d6 8883 #:extra-modules '("foo" "bar")
52ac153e 8884 rest)))
fd1b1fa2
LC
8885@end example
8886
52ac153e
LC
8887The @code{base-initrd} procedure also handles common use cases that
8888involves using the system as a QEMU guest, or as a ``live'' system whose
8889root file system is volatile.
fd1b1fa2 8890
e90cf6c1
LC
8891The initial RAM disk produced by @code{base-initrd} honors several
8892options passed on the Linux kernel command line (that is, arguments
8893passed @i{via} GRUB's @code{linux} command, or with QEMU's
8894@code{-append} option), notably:
8895
8896@table @code
8897@item --load=@var{boot}
8898Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
8899program, once it has mounted the root file system.
8900
8901GuixSD uses this option to yield control to a boot program that runs the
8902service activation programs and then spawns GNU@tie{}dmd, the
8903initialization system.
8904
8905@item --root=@var{root}
8906Mount @var{root} as the root file system. @var{root} can be a device
8907device name like @code{/dev/sda1}, a partition label, or a partition
8908UUID.
8909
8910@item --system=@var{system}
8911Have @file{/run/booted-system} and @file{/run/current-system} point to
8912@var{system}.
8913
8914@item modprobe.blacklist=@var{modules}@dots{}
8915@cindex module, black-listing
8916@cindex black list, of kernel modules
8917Instruct the initial RAM disk as well as the @command{modprobe} command
8918(from the kmod package) to refuse to load @var{modules}. @var{modules}
8919must be a comma-separated list of module names---e.g.,
8920@code{usbkbd,9pnet}.
8921
8922@item --repl
8923Start a read-eval-print loop (REPL) from the initial RAM disk before it
8924tries to load kernel modules and to mount the root file system. Our
8925marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
8926love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
8927Manual}, for more information on Guile's REPL.
8928
8929@end table
8930
8931Now that you know all the features that initial RAM disks produced by
8932@code{base-initrd} provide, here is how to use it and customize it
8933further.
8934
fd1b1fa2
LC
8935@deffn {Monadic Procedure} base-initrd @var{file-systems} @
8936 [#:qemu-networking? #f] [#:virtio? #f] [#:volatile-root? #f] @
52ac153e 8937 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2
LC
8938Return a monadic derivation that builds a generic initrd. @var{file-systems} is
8939a list of file-systems to be mounted by the initrd, possibly in addition to
8940the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
8941@var{mapped-devices} is a list of device mappings to realize before
8942@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
8943
8944When @var{qemu-networking?} is true, set up networking with the standard QEMU
8945parameters. When @var{virtio?} is true, load additional modules so the initrd can
8946be used as a QEMU guest with para-virtualized I/O drivers.
8947
8948When @var{volatile-root?} is true, the root file system is writable but any changes
8949to it are lost.
8950
8951The initrd is automatically populated with all the kernel modules necessary
8952for @var{file-systems} and for the given options. However, additional kernel
8953modules can be listed in @var{extra-modules}. They will be added to the initrd, and
8954loaded at boot time in the order in which they appear.
8955@end deffn
8956
8957Needless to say, the initrds we produce and use embed a
8958statically-linked Guile, and the initialization program is a Guile
8959program. That gives a lot of flexibility. The
8960@code{expression->initrd} procedure builds such an initrd, given the
8961program to run in that initrd.
8962
8963@deffn {Monadic Procedure} expression->initrd @var{exp} @
8964 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
42d10464 8965 [#:modules '()]
fd1b1fa2
LC
8966Return a derivation that builds a Linux initrd (a gzipped cpio archive)
8967containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
8968upon booting. All the derivations referenced by @var{exp} are
8969automatically copied to the initrd.
fd1b1fa2 8970
42d10464
LC
8971@var{modules} is a list of Guile module names to be embedded in the
8972initrd.
fd1b1fa2
LC
8973@end deffn
8974
88faf933
LC
8975@node GRUB Configuration
8976@subsection GRUB Configuration
8977
8978@cindex GRUB
8979@cindex boot loader
8980
8981The operating system uses GNU@tie{}GRUB as its boot loader
8982(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
8983configured using @code{grub-configuration} declarations. This data type
8984is exported by the @code{(gnu system grub)} module, and described below.
8985
8986@deftp {Data Type} grub-configuration
8987The type of a GRUB configuration declaration.
8988
8989@table @asis
8990
8991@item @code{device}
8992This is a string denoting the boot device. It must be a device name
8993understood by the @command{grub-install} command, such as
8994@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
8995GNU GRUB Manual}).
8996
8997@item @code{menu-entries} (default: @code{()})
8998A possibly empty list of @code{menu-entry} objects (see below), denoting
8999entries to appear in the GRUB boot menu, in addition to the current
9000system entry and the entry pointing to previous system generations.
9001
9002@item @code{default-entry} (default: @code{0})
9003The index of the default boot menu entry. Index 0 is for the current
9004system's entry.
9005
9006@item @code{timeout} (default: @code{5})
9007The number of seconds to wait for keyboard input before booting. Set to
90080 to boot immediately, and to -1 to wait indefinitely.
9009
9010@item @code{theme} (default: @var{%default-theme})
9011The @code{grub-theme} object describing the theme to use.
9012@end table
9013
9014@end deftp
9015
9016Should you want to list additional boot menu entries @i{via} the
9017@code{menu-entries} field above, you will need to create them with the
9018@code{menu-entry} form:
9019
9020@deftp {Data Type} menu-entry
9021The type of an entry in the GRUB boot menu.
9022
9023@table @asis
9024
9025@item @code{label}
35ed9306 9026The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
9027
9028@item @code{linux}
9029The Linux kernel to boot.
9030
9031@item @code{linux-arguments} (default: @code{()})
9032The list of extra Linux kernel command-line arguments---e.g.,
9033@code{("console=ttyS0")}.
9034
9035@item @code{initrd}
9036A G-Expression or string denoting the file name of the initial RAM disk
9037to use (@pxref{G-Expressions}).
9038
9039@end table
9040@end deftp
9041
9042@c FIXME: Write documentation once it's stable.
9043Themes are created using the @code{grub-theme} form, which is not
9044documented yet.
9045
9046@defvr {Scheme Variable} %default-theme
9047This is the default GRUB theme used by the operating system, with a
9048fancy background image displaying the GNU and Guix logos.
9049@end defvr
9050
9051
cf4a9129
LC
9052@node Invoking guix system
9053@subsection Invoking @code{guix system}
0918e64a 9054
cf4a9129
LC
9055Once you have written an operating system declaration, as seen in the
9056previous section, it can be @dfn{instantiated} using the @command{guix
9057system} command. The synopsis is:
4af2447e 9058
cf4a9129
LC
9059@example
9060guix system @var{options}@dots{} @var{action} @var{file}
9061@end example
4af2447e 9062
cf4a9129
LC
9063@var{file} must be the name of a file containing an
9064@code{operating-system} declaration. @var{action} specifies how the
9065operating system is instantiate. Currently the following values are
9066supported:
4af2447e 9067
cf4a9129
LC
9068@table @code
9069@item reconfigure
9070Build the operating system described in @var{file}, activate it, and
9071switch to it@footnote{This action is usable only on systems already
65797bff 9072running GuixSD.}.
4af2447e 9073
cf4a9129
LC
9074This effects all the configuration specified in @var{file}: user
9075accounts, system services, global package list, setuid programs, etc.
4af2447e 9076
cf4a9129
LC
9077It also adds a GRUB menu entry for the new OS configuration, and moves
9078entries for older configurations to a submenu---unless
9079@option{--no-grub} is passed.
4af2447e 9080
bf2479c7
LC
9081@c The paragraph below refers to the problem discussed at
9082@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
9083It is highly recommended to run @command{guix pull} once before you run
9084@command{guix system reconfigure} for the first time (@pxref{Invoking
9085guix pull}). Failing to do that you would see an older version of Guix
9086once @command{reconfigure} has completed.
9087
cf4a9129
LC
9088@item build
9089Build the operating system's derivation, which includes all the
9090configuration files and programs needed to boot and run the system.
9091This action does not actually install anything.
113daf62 9092
cf4a9129
LC
9093@item init
9094Populate the given directory with all the files necessary to run the
9095operating system specified in @var{file}. This is useful for first-time
4705641f 9096installations of GuixSD. For instance:
113daf62
LC
9097
9098@example
cf4a9129 9099guix system init my-os-config.scm /mnt
113daf62
LC
9100@end example
9101
cf4a9129
LC
9102copies to @file{/mnt} all the store items required by the configuration
9103specified in @file{my-os-config.scm}. This includes configuration
9104files, packages, and so on. It also creates other essential files
9105needed for the system to operate correctly---e.g., the @file{/etc},
9106@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 9107
cf4a9129
LC
9108This command also installs GRUB on the device specified in
9109@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 9110
cf4a9129
LC
9111@item vm
9112@cindex virtual machine
0276f697 9113@cindex VM
f535dcbe 9114@anchor{guix system vm}
cf4a9129
LC
9115Build a virtual machine that contain the operating system declared in
9116@var{file}, and return a script to run that virtual machine (VM).
810568b3 9117Arguments given to the script are passed as is to QEMU.
113daf62 9118
cf4a9129 9119The VM shares its store with the host system.
113daf62 9120
0276f697
LC
9121Additional file systems can be shared between the host and the VM using
9122the @code{--share} and @code{--expose} command-line options: the former
9123specifies a directory to be shared with write access, while the latter
9124provides read-only access to the shared directory.
9125
9126The example below creates a VM in which the user's home directory is
9127accessible read-only, and where the @file{/exchange} directory is a
9128read-write mapping of the host's @file{$HOME/tmp}:
9129
9130@example
9131guix system vm my-config.scm \
9132 --expose=$HOME --share=$HOME/tmp=/exchange
9133@end example
9134
6aa260af
LC
9135On GNU/Linux, the default is to boot directly to the kernel; this has
9136the advantage of requiring only a very tiny root disk image since the
9137host's store can then be mounted.
9138
9139The @code{--full-boot} option forces a complete boot sequence, starting
9140with the bootloader. This requires more disk space since a root image
9141containing at least the kernel, initrd, and bootloader data files must
9142be created. The @code{--image-size} option can be used to specify the
9143image's size.
ab11f0be 9144
cf4a9129
LC
9145@item vm-image
9146@itemx disk-image
9147Return a virtual machine or disk image of the operating system declared
9148in @var{file} that stands alone. Use the @option{--image-size} option
9149to specify the size of the image.
113daf62 9150
cf4a9129
LC
9151When using @code{vm-image}, the returned image is in qcow2 format, which
9152the QEMU emulator can efficiently use.
113daf62 9153
cf4a9129
LC
9154When using @code{disk-image}, a raw disk image is produced; it can be
9155copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
9156the device corresponding to a USB stick, one can copy the image on it
9157using the following command:
113daf62 9158
cf4a9129
LC
9159@example
9160# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
9161@end example
113daf62 9162
1c8a81b1
DT
9163@item container
9164Return a script to run the operating system declared in @var{file}
9165within a container. Containers are a set of lightweight isolation
9166mechanisms provided by the kernel Linux-libre. Containers are
9167substantially less resource-demanding than full virtual machines since
9168the kernel, shared objects, and other resources can be shared with the
9169host system; this also means they provide thinner isolation.
9170
9171Currently, the script must be run as root in order to support more than
9172a single user and group. The container shares its store with the host
9173system.
9174
9175As with the @code{vm} action (@pxref{guix system vm}), additional file
9176systems to be shared between the host and container can be specified
9177using the @option{--share} and @option{--expose} options:
9178
9179@example
9180guix system container my-config.scm \
9181 --expose=$HOME --share=$HOME/tmp=/exchange
9182@end example
9183
0f252e26 9184@quotation Note
cfd35b4e 9185This option requires Linux-libre 3.19 or newer.
0f252e26
DT
9186@end quotation
9187
cf4a9129 9188@end table
113daf62 9189
cf4a9129
LC
9190@var{options} can contain any of the common build options provided by
9191@command{guix build} (@pxref{Invoking guix build}). In addition,
9192@var{options} can contain one of the following:
113daf62 9193
cf4a9129
LC
9194@table @option
9195@item --system=@var{system}
9196@itemx -s @var{system}
9197Attempt to build for @var{system} instead of the host's system type.
9198This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 9199
f3f427c2
LC
9200@item --derivation
9201@itemx -d
9202Return the derivation file name of the given operating system without
9203building anything.
9204
cf4a9129
LC
9205@item --image-size=@var{size}
9206For the @code{vm-image} and @code{disk-image} actions, create an image
9207of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
9208include a unit as a suffix (@pxref{Block size, size specifications,,
9209coreutils, GNU Coreutils}).
db030303
LC
9210
9211@item --on-error=@var{strategy}
9212Apply @var{strategy} when an error occurs when reading @var{file}.
9213@var{strategy} may be one of the following:
9214
9215@table @code
9216@item nothing-special
9217Report the error concisely and exit. This is the default strategy.
9218
9219@item backtrace
9220Likewise, but also display a backtrace.
9221
9222@item debug
9223Report the error and enter Guile's debugger. From there, you can run
9224commands such as @code{,bt} to get a backtrace, @code{,locals} to
9225display local variable values, and more generally inspect the program's
9226state. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
9227a list of available debugging commands.
9228@end table
113daf62 9229@end table
113daf62 9230
cf4a9129
LC
9231Note that all the actions above, except @code{build} and @code{init},
9232rely on KVM support in the Linux-Libre kernel. Specifically, the
9233machine should have hardware virtualization support, the corresponding
9234KVM kernel module should be loaded, and the @file{/dev/kvm} device node
9235must exist and be readable and writable by the user and by the daemon's
9236build users.
8451a568 9237
65797bff
LC
9238Once you have built, configured, re-configured, and re-re-configured
9239your GuixSD installation, you may find it useful to list the operating
9240system generations available on disk---and that you can choose from the
9241GRUB boot menu:
9242
9243@table @code
9244
9245@item list-generations
9246List a summary of each generation of the operating system available on
9247disk, in a human-readable way. This is similar to the
9248@option{--list-generations} option of @command{guix package}
9249(@pxref{Invoking guix package}).
9250
9251Optionally, one can specify a pattern, with the same syntax that is used
9252in @command{guix package --list-generations}, to restrict the list of
9253generations displayed. For instance, the following command displays
9254generations up to 10-day old:
9255
9256@example
9257$ guix system list-generations 10d
9258@end example
9259
9260@end table
9261
d6c3267a
LC
9262The @command{guix system} command has even more to offer! The following
9263sub-commands allow you to visualize how your system services relate to
9264each other:
9265
9266@anchor{system-extension-graph}
9267@table @code
9268
9269@item extension-graph
9270Emit in Dot/Graphviz format to standard output the @dfn{service
9271extension graph} of the operating system defined in @var{file}
9272(@pxref{Service Composition}, for more information on service
9273extensions.)
9274
9275The command:
9276
9277@example
9278$ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
9279@end example
9280
9281produces a PDF file showing the extension relations among services.
9282
6f305ea5
LC
9283@anchor{system-dmd-graph}
9284@item dmd-graph
9285Emit in Dot/Graphviz format to standard output the @dfn{dependency
9286graph} of dmd services of the operating system defined in @var{file}.
9287@xref{dmd Services}, for more information and for an example graph.
9288
d6c3267a
LC
9289@end table
9290
9291
cf4a9129
LC
9292@node Defining Services
9293@subsection Defining Services
8451a568 9294
eb524192 9295The previous sections show the available services and how one can combine
0adfe95a
LC
9296them in an @code{operating-system} declaration. But how do we define
9297them in the first place? And what is a service anyway?
8451a568 9298
0adfe95a
LC
9299@menu
9300* Service Composition:: The model for composing services.
9301* Service Types and Services:: Types and services.
9302* Service Reference:: API reference.
9303* dmd Services:: A particular type of service.
9304@end menu
9305
9306@node Service Composition
9307@subsubsection Service Composition
9308
9309@cindex services
9310@cindex daemons
9311Here we define a @dfn{service} as, broadly, something that extends the
9312operating system's functionality. Often a service is a process---a
9313@dfn{daemon}---started when the system boots: a secure shell server, a
9314Web server, the Guix build daemon, etc. Sometimes a service is a daemon
9315whose execution can be triggered by another daemon---e.g., an FTP server
9316started by @command{inetd} or a D-Bus service activated by
9317@command{dbus-daemon}. Occasionally, a service does not map to a
9318daemon. For instance, the ``account'' service collects user accounts
9319and makes sure they exist when the system runs; the ``udev'' service
9320collects device management rules and makes them available to the eudev
9321daemon; the @file{/etc} service populates the system's @file{/etc}
9322directory.
9323
d6c3267a 9324@cindex service extensions
0adfe95a
LC
9325GuixSD services are connected by @dfn{extensions}. For instance, the
9326secure shell service @emph{extends} dmd---GuixSD's initialization system,
9327running as PID@tie{}1---by giving it the command lines to start and stop
9328the secure shell daemon (@pxref{Networking Services,
9329@code{lsh-service}}); the UPower service extends the D-Bus service by
9330passing it its @file{.service} specification, and extends the udev
9331service by passing it device management rules (@pxref{Desktop Services,
9332@code{upower-service}}); the Guix daemon service extends dmd by passing
9333it the command lines to start and stop the daemon, and extends the
9334account service by passing it a list of required build user accounts
9335(@pxref{Base Services}).
9336
9337All in all, services and their ``extends'' relations form a directed
9338acyclic graph (DAG). If we represent services as boxes and extensions
9339as arrows, a typical system might provide something like this:
9340
9341@image{images/service-graph,,5in,Typical service extension graph.}
9342
d62e201c
LC
9343@cindex system service
9344At the bottom, we see the @dfn{system service}, which produces the
9345directory containing everything to run and boot the system, as returned
9346by the @command{guix system build} command. @xref{Service Reference},
9347to learn about the other service types shown here.
d6c3267a
LC
9348@xref{system-extension-graph, the @command{guix system extension-graph}
9349command}, for information on how to generate this representation for a
9350particular operating system definition.
0adfe95a
LC
9351
9352@cindex service types
9353Technically, developers can define @dfn{service types} to express these
9354relations. There can be any number of services of a given type on the
9355system---for instance, a system running two instances of the GNU secure
9356shell server (lsh) has two instances of @var{lsh-service-type}, with
9357different parameters.
9358
9359The following section describes the programming interface for service
9360types and services.
9361
9362@node Service Types and Services
9363@subsubsection Service Types and Services
9364
9365A @dfn{service type} is a node in the DAG described above. Let us start
9366with a simple example, the service type for the Guix build daemon
9367(@pxref{Invoking guix-daemon}):
9368
9369@example
9370(define guix-service-type
9371 (service-type
9372 (name 'guix)
9373 (extensions
9374 (list (service-extension dmd-root-service-type guix-dmd-service)
9375 (service-extension account-service-type guix-accounts)
9376 (service-extension activation-service-type guix-activation)))))
9377@end example
8451a568 9378
cf4a9129 9379@noindent
0adfe95a
LC
9380It defines a two things:
9381
9382@enumerate
9383@item
9384A name, whose sole purpose is to make inspection and debugging easier.
9385
9386@item
9387A list of @dfn{service extensions}, where each extension designates the
9388target service type and a procedure that, given the service's
9389parameters, returns a list of object to extend the service of that type.
9390
9391Every service type has at least one service extension. The only
9392exception is the @dfn{boot service type}, which is the ultimate service.
9393@end enumerate
9394
9395In this example, @var{guix-service-type} extends three services:
9396
9397@table @var
9398@item dmd-root-service-type
9399The @var{guix-dmd-service} procedure defines how the dmd service is
9400extended. Namely, it returns a @code{<dmd-service>} object that defines
9401how @command{guix-daemon} is started and stopped (@pxref{dmd Services}).
9402
9403@item account-service-type
9404This extension for this service is computed by @var{guix-accounts},
9405which returns a list of @code{user-group} and @code{user-account}
9406objects representing the build user accounts (@pxref{Invoking
9407guix-daemon}).
9408
9409@item activation-service-type
9410Here @var{guix-activation} is a procedure that returns a gexp, which is
9411a code snippet to run at ``activation time''---e.g., when the service is
9412booted.
9413@end table
9414
9415A service of this type is instantiated like this:
9416
9417@example
9418(service guix-service-type
9419 (guix-configuration
9420 (build-accounts 5)
9421 (use-substitutes? #f)))
9422@end example
9423
9424The second argument to the @code{service} form is a value representing
9425the parameters of this specific service instance.
9426@xref{guix-configuration-type, @code{guix-configuration}}, for
9427information about the @code{guix-configuration} data type.
9428
9429@var{guix-service-type} is quite simple because it extends other
9430services but is not extensible itself.
9431
9432@c @subsubsubsection Extensible Service Types
9433
9434The service type for an @emph{extensible} service looks like this:
9435
9436@example
9437(define udev-service-type
9438 (service-type (name 'udev)
9439 (extensions
9440 (list (service-extension dmd-root-service-type
9441 udev-dmd-service)))
9442
9443 (compose concatenate) ;concatenate the list of rules
9444 (extend (lambda (config rules)
9445 (match config
9446 (($ <udev-configuration> udev initial-rules)
9447 (udev-configuration
9448 (udev udev) ;the udev package to use
9449 (rules (append initial-rules rules)))))))))
9450@end example
9451
9452This is the service type for the
9453@uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
9454management daemon}. Compared to the previous example, in addition to an
9455extension of @var{dmd-root-service-type}, we see two new fields:
9456
9457@table @code
9458@item compose
9459This is the procedure to @dfn{compose} the list of extensions to
9460services of this type.
9461
9462Services can extend the udev service by passing it lists of rules; we
9463compose those extensions simply by concatenating them.
9464
9465@item extend
9466This procedure defines how the service's value is @dfn{extended} with
9467the composition of the extensions.
9468
9469Udev extensions are composed into a list of rules, but the udev service
9470value is itself a @code{<udev-configuration>} record. So here, we
9471extend that record by appending the list of rules is contains to the
9472list of contributed rules.
9473@end table
9474
9475There can be only one instance of an extensible service type such as
9476@var{udev-service-type}. If there were more, the
9477@code{service-extension} specifications would be ambiguous.
9478
9479Still here? The next section provides a reference of the programming
9480interface for services.
9481
9482@node Service Reference
9483@subsubsection Service Reference
9484
9485We have seen an overview of service types (@pxref{Service Types and
9486Services}). This section provides a reference on how to manipulate
9487services and service types. This interface is provided by the
9488@code{(gnu services)} module.
9489
9490@deffn {Scheme Procedure} service @var{type} @var{value}
9491Return a new service of @var{type}, a @code{<service-type>} object (see
9492below.) @var{value} can be any object; it represents the parameters of
9493this particular service instance.
9494@end deffn
9495
9496@deffn {Scheme Procedure} service? @var{obj}
9497Return true if @var{obj} is a service.
9498@end deffn
8451a568 9499
0adfe95a
LC
9500@deffn {Scheme Procedure} service-kind @var{service}
9501Return the type of @var{service}---i.e., a @code{<service-type>} object.
9502@end deffn
9503
9504@deffn {Scheme Procedure} service-parameters @var{service}
9505Return the value associated with @var{service}. It represents its
9506parameters.
9507@end deffn
9508
9509Here is an example of how a service is created and manipulated:
9510
9511@example
9512(define s
9513 (service nginx-service-type
9514 (nginx-configuration
9515 (nginx nginx)
9516 (log-directory log-directory)
9517 (run-directory run-directory)
9518 (file config-file))))
9519
9520(service? s)
9521@result{} #t
9522
9523(eq? (service-kind s) nginx-service-type)
9524@result{} #t
9525@end example
9526
cd6f6c22
LC
9527The @code{modify-services} form provides a handy way to change the
9528parameters of some of the services of a list such as
9529@var{%base-services} (@pxref{Base Services, @code{%base-services}}). Of
9530course, you could always use standard list combinators such as
9531@code{map} and @code{fold} to do that (@pxref{SRFI-1, List Library,,
9532guile, GNU Guile Reference Manual}); @code{modify-services} simply
9533provides a more concise form for this common pattern.
9534
9535@deffn {Scheme Syntax} modify-services @var{services} @
9536 (@var{type} @var{variable} => @var{body}) @dots{}
9537
9538Modify the services listed in @var{services} according to the given
9539clauses. Each clause has the form:
9540
9541@example
9542(@var{type} @var{variable} => @var{body})
9543@end example
9544
9545where @var{type} is a service type, such as @var{guix-service-type}, and
9546@var{variable} is an identifier that is bound within @var{body} to the
9547value of the service of that @var{type}. @xref{Using the Configuration
9548System}, for an example.
9549
9550This is a shorthand for:
9551
9552@example
9553(map (lambda (service) @dots{}) @var{services})
9554@end example
9555@end deffn
9556
9557Next comes the programming interface for service types. This is
9558something you want to know when writing new service definitions, but not
9559necessarily when simply looking for ways to customize your
9560@code{operating-system} declaration.
9561
0adfe95a
LC
9562@deftp {Data Type} service-type
9563@cindex service type
9564This is the representation of a @dfn{service type} (@pxref{Service Types
9565and Services}).
9566
9567@table @asis
9568@item @code{name}
9569This is a symbol, used only to simplify inspection and debugging.
9570
9571@item @code{extensions}
9572A non-empty list of @code{<service-extension>} objects (see below.)
9573
9574@item @code{compose} (default: @code{#f})
9575If this is @code{#f}, then the service type denotes services that cannot
9576be extended---i.e., services that do not receive ``values'' from other
9577services.
9578
9579Otherwise, it must be a one-argument procedure. The procedure is called
9580by @code{fold-services} and is passed a list of values collected from
9581extensions. It must return a value that is a valid parameter value for
9582the service instance.
9583
9584@item @code{extend} (default: @code{#f})
9585If this is @code{#f}, services of this type cannot be extended.
9586
9587Otherwise, it must be a two-argument procedure: @code{fold-services}
9588calls it, passing it the service's initial value as the first argument
9589and the result of applying @code{compose} to the extension values as the
9590second argument.
9591@end table
9592
9593@xref{Service Types and Services}, for examples.
9594@end deftp
9595
9596@deffn {Scheme Procedure} service-extension @var{target-type} @
9597 @var{compute}
9598Return a new extension for services of type @var{target-type}.
9599@var{compute} must be a one-argument procedure: @code{fold-services}
9600calls it, passing it the value associated with the service that provides
9601the extension; it must return a valid value for the target service.
9602@end deffn
9603
9604@deffn {Scheme Procedure} service-extension? @var{obj}
9605Return true if @var{obj} is a service extension.
9606@end deffn
9607
9608At the core of the service abstraction lies the @code{fold-services}
9609procedure, which is responsible for ``compiling'' a list of services
d62e201c
LC
9610down to a single directory that contains everything needed to boot and
9611run the system---the directory shown by the @command{guix system build}
9612command (@pxref{Invoking guix system}). In essence, it propagates
9613service extensions down the service graph, updating each node parameters
9614on the way, until it reaches the root node.
0adfe95a
LC
9615
9616@deffn {Scheme Procedure} fold-services @var{services} @
d62e201c 9617 [#:target-type @var{system-service-type}]
0adfe95a
LC
9618Fold @var{services} by propagating their extensions down to the root of
9619type @var{target-type}; return the root service adjusted accordingly.
9620@end deffn
9621
9622Lastly, the @code{(gnu services)} module also defines several essential
9623service types, some of which are listed below.
9624
d62e201c
LC
9625@defvr {Scheme Variable} system-service-type
9626This is the root of the service graph. It produces the system directory
9627as returned by the @command{guix system build} command.
9628@end defvr
9629
0adfe95a 9630@defvr {Scheme Variable} boot-service-type
d62e201c
LC
9631The type of the ``boot service'', which produces the @dfn{boot script}.
9632The boot script is what the initial RAM disk runs when booting.
0adfe95a
LC
9633@end defvr
9634
9635@defvr {Scheme Variable} etc-service-type
9636The type of the @file{/etc} service. This service can be extended by
9637passing it name/file tuples such as:
9638
9639@example
9640(list `("issue" ,(plain-file "issue" "Welcome!\n")))
9641@end example
9642
9643In this example, the effect would be to add an @file{/etc/issue} file
9644pointing to the given file.
9645@end defvr
9646
9647@defvr {Scheme Variable} setuid-program-service-type
9648Type for the ``setuid-program service''. This service collects lists of
9649executable file names, passed as gexps, and adds them to the set of
9650setuid-root programs on the system (@pxref{Setuid Programs}).
9651@end defvr
9652
af4c3fd5
LC
9653@defvr {Scheme Variable} profile-service-type
9654Type of the service that populates the @dfn{system profile}---i.e., the
9655programs under @file{/run/current-system/profile}. Other services can
9656extend it by passing it lists of packages to add to the system profile.
9657@end defvr
9658
0adfe95a
LC
9659
9660@node dmd Services
9661@subsubsection dmd Services
9662
9663@cindex PID 1
9664@cindex init system
9665The @code{(gnu services dmd)} provides a way to define services managed
9666by GNU@tie{}dmd, which is GuixSD initialization system---the first
9667process that is started when the system boots, aka. PID@tie{}1
6f305ea5
LC
9668(@pxref{Introduction,,, dmd, GNU dmd Manual}).
9669
9670Services in dmd can depend on each other. For instance, the SSH daemon
9671may need to be started after the syslog daemon has been started, which
9672in turn can only happen once all the file systems have been mounted.
9673The simple operating system defined earlier (@pxref{Using the
9674Configuration System}) results in a service graph like this:
9675
9676@image{images/dmd-graph,,5in,Typical dmd service graph.}
9677
9678You can actually generate such a graph for any operating system
9679definition using the @command{guix system dmd-graph} command
9680(@pxref{system-dmd-graph, @command{guix system dmd-graph}}).
9681
9682The @var{%dmd-root-service} is a service object representing PID@tie{}1,
9683of type @var{dmd-root-service-type}; it can be extended by passing it
9684lists of @code{<dmd-service>} objects.
0adfe95a
LC
9685
9686@deftp {Data Type} dmd-service
9687The data type representing a service managed by dmd.
9688
9689@table @asis
9690@item @code{provision}
9691This is a list of symbols denoting what the service provides.
9692
9693These are the names that may be passed to @command{deco start},
9694@command{deco status}, and similar commands (@pxref{Invoking deco,,,
9695dmd, GNU dmd Manual}). @xref{Slots of services, the @code{provides}
9696slot,, dmd, GNU dmd Manual}, for details.
9697
9698@item @code{requirements} (default: @code{'()})
9699List of symbols denoting the dmd services this one depends on.
9700
9701@item @code{respawn?} (default: @code{#t})
9702Whether to restart the service when it stops, for instance when the
9703underlying process dies.
9704
9705@item @code{start}
9706@itemx @code{stop} (default: @code{#~(const #f)})
cf4a9129
LC
9707The @code{start} and @code{stop} fields refer to dmd's facilities to
9708start and stop processes (@pxref{Service De- and Constructors,,, dmd,
0adfe95a
LC
9709GNU dmd Manual}). They are given as G-expressions that get expanded in
9710the dmd configuration file (@pxref{G-Expressions}).
9711
9712@item @code{documentation}
9713A documentation string, as shown when running:
9714
9715@example
9716deco doc @var{service-name}
9717@end example
9718
9719where @var{service-name} is one of the symbols in @var{provision}
9720(@pxref{Invoking deco,,, dmd, GNU dmd Manual}).
fae685b9
LC
9721
9722@item @code{modules} (default: @var{%default-modules})
9723This is the list of modules that must be in scope when @code{start} and
9724@code{stop} are evaluated.
9725
9726@item @code{imported-modules} (default: @var{%default-imported-modules})
9727This is the list of modules to import in the execution environment of
9728dmd.
9729
0adfe95a
LC
9730@end table
9731@end deftp
9732
9733@defvr {Scheme Variable} dmd-root-service-type
9734The service type for the dmd ``root service''---i.e., PID@tie{}1.
9735
9736This is the service type that extensions target when they want to create
9737dmd services (@pxref{Service Types and Services}, for an example). Each
9738extension must pass a list of @code{<dmd-service>}.
9739@end defvr
9740
9741@defvr {Scheme Variable} %dmd-root-service
9742This service represents PID@tie{}1.
9743@end defvr
8451a568 9744
8451a568 9745
cf4a9129
LC
9746@node Installing Debugging Files
9747@section Installing Debugging Files
8451a568 9748
cf4a9129
LC
9749@cindex debugging files
9750Program binaries, as produced by the GCC compilers for instance, are
9751typically written in the ELF format, with a section containing
9752@dfn{debugging information}. Debugging information is what allows the
9753debugger, GDB, to map binary code to source code; it is required to
9754debug a compiled program in good conditions.
8451a568 9755
cf4a9129
LC
9756The problem with debugging information is that is takes up a fair amount
9757of disk space. For example, debugging information for the GNU C Library
9758weighs in at more than 60 MiB. Thus, as a user, keeping all the
9759debugging info of all the installed programs is usually not an option.
9760Yet, space savings should not come at the cost of an impediment to
9761debugging---especially in the GNU system, which should make it easier
9762for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 9763
cf4a9129
LC
9764Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
9765mechanism that allows users to get the best of both worlds: debugging
9766information can be stripped from the binaries and stored in separate
9767files. GDB is then able to load debugging information from those files,
9768when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
9769with GDB}).
8451a568 9770
cf4a9129
LC
9771The GNU distribution takes advantage of this by storing debugging
9772information in the @code{lib/debug} sub-directory of a separate package
9773output unimaginatively called @code{debug} (@pxref{Packages with
9774Multiple Outputs}). Users can choose to install the @code{debug} output
9775of a package when they need it. For instance, the following command
9776installs the debugging information for the GNU C Library and for GNU
9777Guile:
8451a568
LC
9778
9779@example
cf4a9129 9780guix package -i glibc:debug guile:debug
8451a568
LC
9781@end example
9782
cf4a9129
LC
9783GDB must then be told to look for debug files in the user's profile, by
9784setting the @code{debug-file-directory} variable (consider setting it
9785from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
9786GDB}):
8451a568 9787
cf4a9129
LC
9788@example
9789(gdb) set debug-file-directory ~/.guix-profile/lib/debug
9790@end example
8451a568 9791
cf4a9129
LC
9792From there on, GDB will pick up debugging information from the
9793@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 9794
cf4a9129
LC
9795In addition, you will most likely want GDB to be able to show the source
9796code being debugged. To do that, you will have to unpack the source
9797code of the package of interest (obtained with @code{guix build
9798--source}, @pxref{Invoking guix build}), and to point GDB to that source
9799directory using the @code{directory} command (@pxref{Source Path,
9800@code{directory},, gdb, Debugging with GDB}).
8451a568 9801
cf4a9129
LC
9802@c XXX: keep me up-to-date
9803The @code{debug} output mechanism in Guix is implemented by the
9804@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
9805opt-in---debugging information is available only for those packages
9806whose definition explicitly declares a @code{debug} output. This may be
9807changed to opt-out in the future, if our build farm servers can handle
9808the load. To check whether a package has a @code{debug} output, use
9809@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 9810
8451a568 9811
05962f29
LC
9812@node Security Updates
9813@section Security Updates
9814
843858b8
LC
9815@quotation Note
9816As of version @value{VERSION}, the feature described in this section is
9817experimental.
9818@end quotation
05962f29
LC
9819
9820@cindex security updates
9821Occasionally, important security vulnerabilities are discovered in core
9822software packages and must be patched. Guix follows a functional
9823package management discipline (@pxref{Introduction}), which implies
9824that, when a package is changed, @emph{every package that depends on it}
9825must be rebuilt. This can significantly slow down the deployment of
9826fixes in core packages such as libc or Bash, since basically the whole
9827distribution would need to be rebuilt. Using pre-built binaries helps
9828(@pxref{Substitutes}), but deployment may still take more time than
9829desired.
9830
9831@cindex grafts
9832To address that, Guix implements @dfn{grafts}, a mechanism that allows
9833for fast deployment of critical updates without the costs associated
9834with a whole-distribution rebuild. The idea is to rebuild only the
9835package that needs to be patched, and then to ``graft'' it onto packages
9836explicitly installed by the user and that were previously referring to
9837the original package. The cost of grafting is typically very low, and
9838order of magnitudes lower than a full rebuild of the dependency chain.
9839
9840@cindex replacements of packages, for grafts
9841For instance, suppose a security update needs to be applied to Bash.
9842Guix developers will provide a package definition for the ``fixed''
9843Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
9844Packages}). Then, the original package definition is augmented with a
9845@code{replacement} field pointing to the package containing the bug fix:
9846
9847@example
9848(define bash
9849 (package
9850 (name "bash")
9851 ;; @dots{}
9852 (replacement bash-fixed)))
9853@end example
9854
9855From there on, any package depending directly or indirectly on Bash that
9856is installed will automatically be ``rewritten'' to refer to
9857@var{bash-fixed} instead of @var{bash}. This grafting process takes
9858time proportional to the size of the package, but expect less than a
9859minute for an ``average'' package on a recent machine.
9860
9861Currently, the graft and the package it replaces (@var{bash-fixed} and
9862@var{bash} in the example above) must have the exact same @code{name}
9863and @code{version} fields. This restriction mostly comes from the fact
9864that grafting works by patching files, including binary files, directly.
9865Other restrictions may apply: for instance, when adding a graft to a
9866package providing a shared library, the original shared library and its
9867replacement must have the same @code{SONAME} and be binary-compatible.
9868
9869
cf4a9129
LC
9870@node Package Modules
9871@section Package Modules
8451a568 9872
cf4a9129
LC
9873From a programming viewpoint, the package definitions of the
9874GNU distribution are provided by Guile modules in the @code{(gnu packages
9875@dots{})} name space@footnote{Note that packages under the @code{(gnu
9876packages @dots{})} module name space are not necessarily ``GNU
9877packages''. This module naming scheme follows the usual Guile module
9878naming convention: @code{gnu} means that these modules are distributed
9879as part of the GNU system, and @code{packages} identifies modules that
9880define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
9881Reference Manual}). For instance, the @code{(gnu packages emacs)}
9882module exports a variable named @code{emacs}, which is bound to a
9883@code{<package>} object (@pxref{Defining Packages}).
113daf62 9884
300868ba 9885The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
9886automatically scanned for packages by the command-line tools. For
9887instance, when running @code{guix package -i emacs}, all the @code{(gnu
9888packages @dots{})} modules are scanned until one that exports a package
9889object whose name is @code{emacs} is found. This package search
9890facility is implemented in the @code{(gnu packages)} module.
113daf62 9891
300868ba 9892@cindex customization, of packages
8689901f 9893@cindex package module search path
cf4a9129 9894Users can store package definitions in modules with different
60142854 9895names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
9896name and module name must match. For instance, the @code{(my-packages
9897emacs)} module must be stored in a @file{my-packages/emacs.scm} file
9898relative to the load path specified with @option{--load-path} or
9899@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
9900guile, GNU Guile Reference Manual}, for details.}. These package definitions
300868ba
LC
9901will not be visible by default. Thus, users can invoke commands such as
9902@command{guix package} and @command{guix build} have to be used with the
c95ded7e
LC
9903@code{-e} option so that they know where to find the package. Better
9904yet, they can use the
300868ba 9905@code{-L} option of these commands to make those modules visible
8689901f
LC
9906(@pxref{Invoking guix build, @code{--load-path}}), or define the
9907@code{GUIX_PACKAGE_PATH} environment variable. This environment
9908variable makes it easy to extend or customize the distribution and is
9909honored by all the user interfaces.
9910
9911@defvr {Environment Variable} GUIX_PACKAGE_PATH
9912This is a colon-separated list of directories to search for package
9913modules. Directories listed in this variable take precedence over the
9914distribution's own modules.
9915@end defvr
ef5dd60a 9916
cf4a9129
LC
9917The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
9918each package is built based solely on other packages in the
9919distribution. The root of this dependency graph is a small set of
9920@dfn{bootstrap binaries}, provided by the @code{(gnu packages
9921bootstrap)} module. For more information on bootstrapping,
081145cf 9922@pxref{Bootstrapping}.
ef5dd60a 9923
cf4a9129
LC
9924@node Packaging Guidelines
9925@section Packaging Guidelines
ef5dd60a 9926
cf4a9129
LC
9927The GNU distribution is nascent and may well lack some of your favorite
9928packages. This section describes how you can help make the distribution
9929grow. @xref{Contributing}, for additional information on how you can
9930help.
ef5dd60a 9931
cf4a9129
LC
9932Free software packages are usually distributed in the form of
9933@dfn{source code tarballs}---typically @file{tar.gz} files that contain
9934all the source files. Adding a package to the distribution means
9935essentially two things: adding a @dfn{recipe} that describes how to
9936build the package, including a list of other packages required to build
9937it, and adding @dfn{package meta-data} along with that recipe, such as a
9938description and licensing information.
ef5dd60a 9939
cf4a9129
LC
9940In Guix all this information is embodied in @dfn{package definitions}.
9941Package definitions provide a high-level view of the package. They are
9942written using the syntax of the Scheme programming language; in fact,
9943for each package we define a variable bound to the package definition,
9944and export that variable from a module (@pxref{Package Modules}).
9945However, in-depth Scheme knowledge is @emph{not} a prerequisite for
9946creating packages. For more information on package definitions,
081145cf 9947@pxref{Defining Packages}.
ef5dd60a 9948
cf4a9129
LC
9949Once a package definition is in place, stored in a file in the Guix
9950source tree, it can be tested using the @command{guix build} command
9951(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
9952called @code{gnew}, you may run this command from the Guix build tree
9953(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
9954
9955@example
cf4a9129 9956./pre-inst-env guix build gnew --keep-failed
ef5dd60a 9957@end example
ef5dd60a 9958
cf4a9129
LC
9959Using @code{--keep-failed} makes it easier to debug build failures since
9960it provides access to the failed build tree. Another useful
9961command-line option when debugging is @code{--log-file}, to access the
9962build log.
ef5dd60a 9963
cf4a9129
LC
9964If the package is unknown to the @command{guix} command, it may be that
9965the source file contains a syntax error, or lacks a @code{define-public}
9966clause to export the package variable. To figure it out, you may load
9967the module from Guile to get more information about the actual error:
ef5dd60a 9968
cf4a9129
LC
9969@example
9970./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
9971@end example
ef5dd60a 9972
cf4a9129
LC
9973Once your package builds correctly, please send us a patch
9974(@pxref{Contributing}). Well, if you need help, we will be happy to
9975help you too. Once the patch is committed in the Guix repository, the
9976new package automatically gets built on the supported platforms by
2b1cee21 9977@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 9978system}.
ef5dd60a 9979
cf4a9129
LC
9980@cindex substituter
9981Users can obtain the new package definition simply by running
9982@command{guix pull} (@pxref{Invoking guix pull}). When
9983@code{hydra.gnu.org} is done building the package, installing the
9984package automatically downloads binaries from there
9985(@pxref{Substitutes}). The only place where human intervention is
9986needed is to review and apply the patch.
ef5dd60a 9987
ef5dd60a 9988
cf4a9129 9989@menu
ec0339cd
LC
9990* Software Freedom:: What may go into the distribution.
9991* Package Naming:: What's in a name?
9992* Version Numbers:: When the name is not enough.
cbd02397 9993* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
9994* Python Modules:: Taming the snake.
9995* Perl Modules:: Little pearls.
9996* Fonts:: Fond of fonts.
cf4a9129 9997@end menu
ef5dd60a 9998
cf4a9129
LC
9999@node Software Freedom
10000@subsection Software Freedom
ef5dd60a 10001
cf4a9129 10002@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
c11a6eb1 10003
cf4a9129
LC
10004The GNU operating system has been developed so that users can have
10005freedom in their computing. GNU is @dfn{free software}, meaning that
10006users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
10007essential freedoms}: to run the program, to study and change the program
10008in source code form, to redistribute exact copies, and to distribute
10009modified versions. Packages found in the GNU distribution provide only
10010software that conveys these four freedoms.
c11a6eb1 10011
cf4a9129
LC
10012In addition, the GNU distribution follow the
10013@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
10014software distribution guidelines}. Among other things, these guidelines
10015reject non-free firmware, recommendations of non-free software, and
10016discuss ways to deal with trademarks and patents.
ef5dd60a 10017
cf4a9129
LC
10018Some packages contain a small and optional subset that violates the
10019above guidelines, for instance because this subset is itself non-free
10020code. When that happens, the offending items are removed with
10021appropriate patches or code snippets in the package definition's
10022@code{origin} form (@pxref{Defining Packages}). That way, @code{guix
10023build --source} returns the ``freed'' source rather than the unmodified
10024upstream source.
ef5dd60a 10025
ef5dd60a 10026
cf4a9129
LC
10027@node Package Naming
10028@subsection Package Naming
ef5dd60a 10029
cf4a9129
LC
10030A package has actually two names associated with it:
10031First, there is the name of the @emph{Scheme variable}, the one following
10032@code{define-public}. By this name, the package can be made known in the
10033Scheme code, for instance as input to another package. Second, there is
10034the string in the @code{name} field of a package definition. This name
10035is used by package management commands such as
10036@command{guix package} and @command{guix build}.
ef5dd60a 10037
cf4a9129
LC
10038Both are usually the same and correspond to the lowercase conversion of
10039the project name chosen upstream, with underscores replaced with
10040hyphens. For instance, GNUnet is available as @code{gnunet}, and
10041SDL_net as @code{sdl-net}.
927097ef 10042
cf4a9129 10043We do not add @code{lib} prefixes for library packages, unless these are
081145cf 10044already part of the official project name. But @pxref{Python
cf4a9129
LC
10045Modules} and @ref{Perl Modules} for special rules concerning modules for
10046the Python and Perl languages.
927097ef 10047
1b366ee4 10048Font package names are handled differently, @pxref{Fonts}.
7fec52b7 10049
ef5dd60a 10050
cf4a9129
LC
10051@node Version Numbers
10052@subsection Version Numbers
ef5dd60a 10053
cf4a9129
LC
10054We usually package only the latest version of a given free software
10055project. But sometimes, for instance for incompatible library versions,
10056two (or more) versions of the same package are needed. These require
10057different Scheme variable names. We use the name as defined
10058in @ref{Package Naming}
10059for the most recent version; previous versions use the same name, suffixed
10060by @code{-} and the smallest prefix of the version number that may
10061distinguish the two versions.
ef5dd60a 10062
cf4a9129
LC
10063The name inside the package definition is the same for all versions of a
10064package and does not contain any version number.
ef5dd60a 10065
cf4a9129 10066For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 10067
cf4a9129
LC
10068@example
10069(define-public gtk+
10070 (package
17d8e33f
ML
10071 (name "gtk+")
10072 (version "3.9.12")
10073 ...))
cf4a9129
LC
10074(define-public gtk+-2
10075 (package
17d8e33f
ML
10076 (name "gtk+")
10077 (version "2.24.20")
10078 ...))
cf4a9129
LC
10079@end example
10080If we also wanted GTK+ 3.8.2, this would be packaged as
10081@example
10082(define-public gtk+-3.8
10083 (package
17d8e33f
ML
10084 (name "gtk+")
10085 (version "3.8.2")
10086 ...))
cf4a9129 10087@end example
ef5dd60a 10088
cbd02397
LC
10089@node Synopses and Descriptions
10090@subsection Synopses and Descriptions
10091
10092As we have seen before, each package in GNU@tie{}Guix includes a
10093synopsis and a description (@pxref{Defining Packages}). Synopses and
10094descriptions are important: They are what @command{guix package
10095--search} searches, and a crucial piece of information to help users
10096determine whether a given package suits their needs. Consequently,
10097packagers should pay attention to what goes into them.
10098
10099Synopses must start with a capital letter and must not end with a
10100period. They must not start with ``a'' or ``the'', which usually does
10101not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
10102tool that frobs files''. The synopsis should say what the package
10103is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
10104used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
10105matching a pattern''.
10106
10107Keep in mind that the synopsis must be meaningful for a very wide
10108audience. For example, ``Manipulate alignments in the SAM format''
10109might make sense for a seasoned bioinformatics researcher, but might be
10110fairly unhelpful or even misleading to a non-specialized audience. It
10111is a good idea to come up with a synopsis that gives an idea of the
10112application domain of the package. In this example, this might give
10113something like ``Manipulate nucleotide sequence alignments'', which
10114hopefully gives the user a better idea of whether this is what they are
10115looking for.
10116
10117@cindex Texinfo markup, in package descriptions
10118Descriptions should take between five and ten lines. Use full
10119sentences, and avoid using acronyms without first introducing them.
10120Descriptions can include Texinfo markup, which is useful to introduce
10121ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
10122hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
10123should be careful when using some characters for example @samp{@@} and
10124curly braces which are the basic special characters in Texinfo
10125(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
10126such as @command{guix package --show} take care of rendering it
10127appropriately.
cbd02397
LC
10128
10129Synopses and descriptions are translated by volunteers
10130@uref{http://translationproject.org/domain/guix-packages.html, at the
10131Translation Project} so that as many users as possible can read them in
10132their native language. User interfaces search them and display them in
10133the language specified by the current locale.
10134
10135Translation is a lot of work so, as a packager, please pay even more
10136attention to your synopses and descriptions as every change may entail
ba7d6c76 10137additional work for translators. In order to help them, it is possible
36743e71 10138to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
10139special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
10140Gettext}):
10141
10142@example
10143;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
10144(description "ARandR is designed to provide a simple visual front end
10145for the X11 resize-and-rotate (RandR) extension. @dots{}")
10146@end example
cbd02397 10147
ef5dd60a 10148
cf4a9129
LC
10149@node Python Modules
10150@subsection Python Modules
ef5dd60a 10151
cf4a9129
LC
10152We currently package Python 2 and Python 3, under the Scheme variable names
10153@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
10154To avoid confusion and naming clashes with other programming languages, it
10155seems desirable that the name of a package for a Python module contains
10156the word @code{python}.
ef5dd60a 10157
cf4a9129
LC
10158Some modules are compatible with only one version of Python, others with both.
10159If the package Foo compiles only with Python 3, we name it
10160@code{python-foo}; if it compiles only with Python 2, we name it
10161@code{python2-foo}. If it is compatible with both versions, we create two
10162packages with the corresponding names.
ef5dd60a 10163
cf4a9129
LC
10164If a project already contains the word @code{python}, we drop this;
10165for instance, the module python-dateutil is packaged under the names
10166@code{python-dateutil} and @code{python2-dateutil}.
113daf62 10167
523e4896 10168
cf4a9129
LC
10169@node Perl Modules
10170@subsection Perl Modules
523e4896 10171
cf4a9129
LC
10172Perl programs standing for themselves are named as any other package,
10173using the lowercase upstream name.
10174For Perl packages containing a single class, we use the lowercase class name,
10175replace all occurrences of @code{::} by dashes and prepend the prefix
10176@code{perl-}.
10177So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
10178Modules containing several classes keep their lowercase upstream name and
10179are also prepended by @code{perl-}. Such modules tend to have the word
10180@code{perl} somewhere in their name, which gets dropped in favor of the
10181prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 10182
523e4896 10183
7fec52b7
AE
10184@node Fonts
10185@subsection Fonts
10186
10187For fonts that are in general not installed by a user for typesetting
10188purposes, or that are distributed as part of a larger software package,
10189we rely on the general packaging rules for software; for instance, this
10190applies to the fonts delivered as part of the X.Org system or fonts that
10191are part of TeX Live.
10192
10193To make it easier for a user to search for fonts, names for other packages
10194containing only fonts are constructed as follows, independently of the
10195upstream package name.
10196
10197The name of a package containing only one font family starts with
10198@code{font-}; it is followed by the foundry name and a dash @code{-}
10199if the foundry is known, and the font family name, in which spaces are
10200replaced by dashes (and as usual, all upper case letters are transformed
10201to lower case).
10202For example, the Gentium font family by SIL is packaged under the name
10203@code{font-sil-gentium}.
10204
10205For a package containing several font families, the name of the collection
10206is used in the place of the font family name.
10207For instance, the Liberation fonts consist of three families,
10208Liberation Sans, Liberation Serif and Liberation Mono.
10209These could be packaged separately under the names
10210@code{font-liberation-sans} and so on; but as they are distributed together
10211under a common name, we prefer to package them together as
10212@code{font-liberation}.
10213
10214In the case where several formats of the same font family or font collection
10215are packaged separately, a short form of the format, prepended by a dash,
10216is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 10217@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
10218fonts.
10219
10220
b25937e3 10221
cf4a9129
LC
10222@node Bootstrapping
10223@section Bootstrapping
b25937e3 10224
cf4a9129 10225@c Adapted from the ELS 2013 paper.
b25937e3 10226
cf4a9129 10227@cindex bootstrapping
7889394e 10228
cf4a9129
LC
10229Bootstrapping in our context refers to how the distribution gets built
10230``from nothing''. Remember that the build environment of a derivation
10231contains nothing but its declared inputs (@pxref{Introduction}). So
10232there's an obvious chicken-and-egg problem: how does the first package
10233get built? How does the first compiler get compiled? Note that this is
10234a question of interest only to the curious hacker, not to the regular
10235user, so you can shamelessly skip this section if you consider yourself
10236a ``regular user''.
72b9d60d 10237
cf4a9129
LC
10238@cindex bootstrap binaries
10239The GNU system is primarily made of C code, with libc at its core. The
10240GNU build system itself assumes the availability of a Bourne shell and
10241command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
10242`grep'. Furthermore, build programs---programs that run
10243@code{./configure}, @code{make}, etc.---are written in Guile Scheme
10244(@pxref{Derivations}). Consequently, to be able to build anything at
10245all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
10246Binutils, libc, and the other packages mentioned above---the
10247@dfn{bootstrap binaries}.
72b9d60d 10248
cf4a9129
LC
10249These bootstrap binaries are ``taken for granted'', though we can also
10250re-create them if needed (more on that later).
72b9d60d 10251
cf4a9129 10252@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 10253
cf4a9129
LC
10254@c As of Emacs 24.3, Info-mode displays the image, but since it's a
10255@c large image, it's hard to scroll. Oh well.
10256@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 10257
cf4a9129
LC
10258The figure above shows the very beginning of the dependency graph of the
10259distribution, corresponding to the package definitions of the @code{(gnu
d33fa0c7
LC
10260packages bootstrap)} module. A similar figure can be generated with
10261@command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
10262
10263@example
10264guix graph -t derivation \
10265 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
10266 | dot -Tps > t.ps
10267@end example
10268
10269At this level of detail, things are
cf4a9129
LC
10270slightly complex. First, Guile itself consists of an ELF executable,
10271along with many source and compiled Scheme files that are dynamically
10272loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
10273tarball shown in this graph. This tarball is part of Guix's ``source''
10274distribution, and gets inserted into the store with @code{add-to-store}
10275(@pxref{The Store}).
2e7b5cea 10276
cf4a9129
LC
10277But how do we write a derivation that unpacks this tarball and adds it
10278to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
10279derivation---the first one that gets built---uses @code{bash} as its
10280builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
10281@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
10282@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
10283the Guix source distribution, whose sole purpose is to allow the Guile
10284tarball to be unpacked.
fb729425 10285
cf4a9129
LC
10286Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
10287Guile that can be used to run subsequent build programs. Its first task
10288is to download tarballs containing the other pre-built binaries---this
10289is what the @code{.tar.xz.drv} derivations do. Guix modules such as
10290@code{ftp-client.scm} are used for this purpose. The
10291@code{module-import.drv} derivations import those modules in a directory
10292in the store, using the original layout. The
10293@code{module-import-compiled.drv} derivations compile those modules, and
10294write them in an output directory with the right layout. This
10295corresponds to the @code{#:modules} argument of
10296@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 10297
cf4a9129
LC
10298Finally, the various tarballs are unpacked by the
10299derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
10300etc., at which point we have a working C tool chain.
fb729425 10301
fb729425 10302
cf4a9129 10303@unnumberedsubsec Building the Build Tools
523e4896 10304
cf4a9129
LC
10305Bootstrapping is complete when we have a full tool chain that does not
10306depend on the pre-built bootstrap tools discussed above. This
10307no-dependency requirement is verified by checking whether the files of
10308the final tool chain contain references to the @file{/gnu/store}
10309directories of the bootstrap inputs. The process that leads to this
10310``final'' tool chain is described by the package definitions found in
1f6f57df 10311the @code{(gnu packages commencement)} module.
df2ce343 10312
d33fa0c7
LC
10313The @command{guix graph} command allows us to ``zoom out'' compared to
10314the graph above, by looking at the level of package objects instead of
10315individual derivations---remember that a package may translate to
10316several derivations, typically one derivation to download its source,
10317one to build the Guile modules it needs, and one to actually build the
10318package from source. The command:
10319
10320@example
10321guix graph -t bag \
10322 -e '(@@@@ (gnu packages commencement)
10323 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
10324@end example
10325
10326@noindent
10327produces the dependency graph leading to the ``final'' C
10328library@footnote{You may notice the @code{glibc-intermediate} label,
10329suggesting that it is not @emph{quite} final, but as a good
10330approximation, we will consider it final.}, depicted below.
10331
10332@image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
10333
cf4a9129
LC
10334@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
10335The first tool that gets built with the bootstrap binaries is
d33fa0c7
LC
10336GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
10337for all the following packages. From there Findutils and Diffutils get
10338built.
523e4896 10339
cf4a9129
LC
10340Then come the first-stage Binutils and GCC, built as pseudo cross
10341tools---i.e., with @code{--target} equal to @code{--host}. They are
10342used to build libc. Thanks to this cross-build trick, this libc is
10343guaranteed not to hold any reference to the initial tool chain.
4af2447e 10344
d33fa0c7
LC
10345From there the final Binutils and GCC (not shown above) are built.
10346GCC uses @code{ld}
cf4a9129
LC
10347from the final Binutils, and links programs against the just-built libc.
10348This tool chain is used to build the other packages used by Guix and by
10349the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 10350
cf4a9129
LC
10351And voilà! At this point we have the complete set of build tools that
10352the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
10353variable of the @code{(gnu packages commencement)} module, and are
10354implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 10355(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 10356
4af2447e 10357
cf4a9129 10358@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 10359
cf4a9129
LC
10360Because the final tool chain does not depend on the bootstrap binaries,
10361those rarely need to be updated. Nevertheless, it is useful to have an
10362automated way to produce them, should an update occur, and this is what
10363the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 10364
cf4a9129
LC
10365The following command builds the tarballs containing the bootstrap
10366binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
10367of Coreutils and other basic command-line tools):
4b2615e1 10368
cf4a9129
LC
10369@example
10370guix build bootstrap-tarballs
10371@end example
10372
10373The generated tarballs are those that should be referred to in the
10374@code{(gnu packages bootstrap)} module mentioned at the beginning of
10375this section.
10376
10377Still here? Then perhaps by now you've started to wonder: when do we
10378reach a fixed point? That is an interesting question! The answer is
10379unknown, but if you would like to investigate further (and have
10380significant computational and storage resources to do so), then let us
10381know.
10382
10383@node Porting
10384@section Porting to a New Platform
10385
10386As discussed above, the GNU distribution is self-contained, and
10387self-containment is achieved by relying on pre-built ``bootstrap
10388binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
10389operating system kernel, CPU architecture, and application binary
10390interface (ABI). Thus, to port the distribution to a platform that is
10391not yet supported, one must build those bootstrap binaries, and update
10392the @code{(gnu packages bootstrap)} module to use them on that platform.
10393
10394Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
10395When everything goes well, and assuming the GNU tool chain supports the
10396target platform, this can be as simple as running a command like this
10397one:
10398
10399@example
10400guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
10401@end example
10402
1c0c417d
LC
10403For this to work, the @code{glibc-dynamic-linker} procedure in
10404@code{(gnu packages bootstrap)} must be augmented to return the right
10405file name for libc's dynamic linker on that platform; likewise,
10406@code{system->linux-architecture} in @code{(gnu packages linux)} must be
10407taught about the new platform.
10408
cf4a9129 10409Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
10410to be updated to refer to these binaries on the target platform. That
10411is, the hashes and URLs of the bootstrap tarballs for the new platform
10412must be added alongside those of the currently supported platforms. The
10413bootstrap Guile tarball is treated specially: it is expected to be
10414available locally, and @file{gnu-system.am} has rules do download it for
10415the supported architectures; a rule for the new platform must be added
10416as well.
cf4a9129
LC
10417
10418In practice, there may be some complications. First, it may be that the
10419extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
10420above) is not recognized by all the GNU tools. Typically, glibc
10421recognizes some of these, whereas GCC uses an extra @code{--with-abi}
10422configure flag (see @code{gcc.scm} for examples of how to handle this).
10423Second, some of the required packages could fail to build for that
10424platform. Lastly, the generated binaries could be broken for some
10425reason.
4af2447e 10426
9bf3c1a7 10427@c *********************************************************************
8c01b9d0 10428@include contributing.texi
c78bd12b 10429
568717fd
LC
10430@c *********************************************************************
10431@node Acknowledgments
10432@chapter Acknowledgments
10433
136787cb
LC
10434Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
10435which was designed and
4c7ac9aa
LC
10436implemented by Eelco Dolstra, with contributions from other people (see
10437the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
10438management, and promoted unprecedented features, such as transactional
10439package upgrades and rollbacks, per-user profiles, and referentially
10440transparent build processes. Without this work, Guix would not exist.
10441
10442The Nix-based software distributions, Nixpkgs and NixOS, have also been
10443an inspiration for Guix.
10444
4c7ac9aa
LC
10445GNU@tie{}Guix itself is a collective work with contributions from a
10446number of people. See the @file{AUTHORS} file in Guix for more
10447information on these fine people. The @file{THANKS} file lists people
10448who have helped by reporting bugs, taking care of the infrastructure,
10449providing artwork and themes, making suggestions, and more---thank you!
10450
10451
568717fd
LC
10452@c *********************************************************************
10453@node GNU Free Documentation License
10454@appendix GNU Free Documentation License
10455
10456@include fdl-1.3.texi
10457
10458@c *********************************************************************
10459@node Concept Index
10460@unnumbered Concept Index
10461@printindex cp
10462
a85b83d2
LC
10463@node Programming Index
10464@unnumbered Programming Index
10465@syncodeindex tp fn
10466@syncodeindex vr fn
568717fd
LC
10467@printindex fn
10468
10469@bye
10470
10471@c Local Variables:
10472@c ispell-local-dictionary: "american";
10473@c End: