gnu: Add xaos.
[jackhill/guix/guix.git] / doc / guix.texi
CommitLineData
568717fd
LC
1\input texinfo
2@c -*-texinfo-*-
3
4@c %**start of header
5@setfilename guix.info
6@documentencoding UTF-8
f8348b91 7@settitle GNU Guix Reference Manual
568717fd
LC
8@c %**end of header
9
10@include version.texi
7df7a74e
NK
11
12@copying
4379c35b 13Copyright @copyright{} 2012, 2013, 2014, 2015 Ludovic Courtès@*
af8a56b8 14Copyright @copyright{} 2013, 2014 Andreas Enge@*
87eafdbd 15Copyright @copyright{} 2013 Nikita Karetnikov@*
8c01b9d0
ML
16Copyright @copyright{} 2015 Mathieu Lirzin@*
17Copyright @copyright{} 2014 Pierre-Antoine Rault@*
87eafdbd 18Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer
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.
c554de89 119
aaa3eaa9
LC
120Programming Interface
121
122* Defining Packages:: Defining new packages.
123* Build Systems:: Specifying how packages are built.
124* The Store:: Manipulating the package store.
125* Derivations:: Low-level interface to package derivations.
126* The Store Monad:: Purely functional interface to the store.
127* G-Expressions:: Manipulating build expressions.
128
92492b23
LC
129Defining Packages
130
131* package Reference:: The package data type.
132* origin Reference:: The origin data type.
133
aaa3eaa9
LC
134Utilities
135
136* Invoking guix build:: Building packages from the command line.
fcc58db6 137* Invoking guix edit:: Editing package definitions.
aaa3eaa9
LC
138* Invoking guix download:: Downloading a file and printing its hash.
139* Invoking guix hash:: Computing the cryptographic hash of a file.
140* Invoking guix import:: Importing package definitions.
141* Invoking guix refresh:: Updating package definitions.
142* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 143* Invoking guix size:: Profiling disk usage.
88856916 144* Invoking guix graph:: Visualizing the graph of packages.
aaa3eaa9 145* Invoking guix environment:: Setting up development environments.
aff8ce7c 146* Invoking guix publish:: Sharing substitutes.
d23c20f1 147* Invoking guix challenge:: Challenging substitute servers.
32efa254 148* Invoking guix container:: Process isolation.
aaa3eaa9
LC
149
150GNU Distribution
151
152* System Installation:: Installing the whole operating system.
35ed9306 153* System Configuration:: Configuring the operating system.
aaa3eaa9
LC
154* Installing Debugging Files:: Feeding the debugger.
155* Security Updates:: Deploying security fixes quickly.
156* Package Modules:: Packages from the programmer's viewpoint.
157* Packaging Guidelines:: Growing the distribution.
158* Bootstrapping:: GNU/Linux built from scratch.
159* Porting:: Targeting another platform or kernel.
160
161System Configuration
162
163* Using the Configuration System:: Customizing your GNU system.
164* operating-system Reference:: Detail of operating-system declarations.
165* File Systems:: Configuring file system mounts.
166* Mapped Devices:: Block device extra processing.
167* User Accounts:: Specifying user accounts.
598e19dc 168* Locales:: Language and cultural convention settings.
aaa3eaa9
LC
169* Services:: Specifying system services.
170* Setuid Programs:: Programs running with root privileges.
1b2b8177 171* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 172* Name Service Switch:: Configuring libc's name service switch.
aaa3eaa9
LC
173* Initial RAM Disk:: Linux-Libre bootstrapping.
174* GRUB Configuration:: Configuring the boot loader.
175* Invoking guix system:: Instantiating a system configuration.
176* Defining Services:: Adding new service definitions.
177
178Services
179
180* Base Services:: Essential system services.
181* Networking Services:: Network setup, SSH daemon, etc.
182* X Window:: Graphical display.
1b2b8177
LC
183* Desktop Services:: D-Bus and desktop services.
184* Database Services:: SQL databases.
d8c18af8 185* Mail Services:: IMAP, POP3, SMTP, and all that.
cbd02397 186* Web Services:: Web servers.
aa4ed923 187* Various Services:: Other services.
aaa3eaa9 188
0adfe95a
LC
189Defining Services
190
191* Service Composition:: The model for composing services.
192* Service Types and Services:: Types and services.
193* Service Reference:: API reference.
194* dmd Services:: A particular type of service.
195
aaa3eaa9
LC
196Packaging Guidelines
197
ec0339cd
LC
198* Software Freedom:: What may go into the distribution.
199* Package Naming:: What's in a name?
200* Version Numbers:: When the name is not enough.
cbd02397 201* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
202* Python Modules:: Taming the snake.
203* Perl Modules:: Little pearls.
204* Fonts:: Fond of fonts.
aaa3eaa9 205
8c01b9d0
ML
206Contributing
207
208* Building from Git:: The latest and greatest.
209* Running Guix Before It Is Installed:: Hacker tricks.
210* The Perfect Setup:: The right tools.
211* Coding Style:: Hygiene of the contributor.
212* Submitting Patches:: Share your work.
213
214Coding Style
215
216* Programming Paradigm:: How to compose your elements.
217* Modules:: Where to store your code?
218* Data Types and Pattern Matching:: Implementing data structures.
219* Formatting Code:: Writing conventions.
220
aaa3eaa9 221@end detailmenu
568717fd
LC
222@end menu
223
224@c *********************************************************************
225@node Introduction
226@chapter Introduction
227
c80e7e55
LC
228GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
229using the international phonetic alphabet (IPA).} is a functional
230package management tool for the GNU system. Package management consists
4bfc4ea3
NK
231of all activities that relate to building packages from sources,
232honoring their build-time and run-time dependencies,
c80e7e55
LC
233installing packages in user environments, upgrading installed packages
234to new versions or rolling back to a previous set, removing unused
235software packages, etc.
568717fd
LC
236
237@cindex functional package management
238The term @dfn{functional} refers to a specific package management
136787cb
LC
239discipline pioneered by Nix (@pxref{Acknowledgments}).
240In Guix, the package build and installation process is seen
4bfc4ea3
NK
241as a function, in the mathematical sense. That function takes inputs,
242such as build scripts, a compiler, and libraries, and
243returns an installed package. As a pure function, its result depends
568717fd
LC
244solely on its inputs---for instance, it cannot refer to software or
245scripts that were not explicitly passed as inputs. A build function
4bfc4ea3
NK
246always produces the same result when passed a given set of inputs. It
247cannot alter the system's environment in
568717fd
LC
248any way; for instance, it cannot create, modify, or delete files outside
249of its build and installation directories. This is achieved by running
e900c503 250build processes in isolated environments (or @dfn{containers}), where only their
4bfc4ea3 251explicit inputs are visible.
568717fd 252
e531ac2a 253@cindex store
568717fd 254The result of package build functions is @dfn{cached} in the file
e531ac2a
LC
255system, in a special directory called @dfn{the store} (@pxref{The
256Store}). Each package is installed in a directory of its own, in the
834129e0 257store---by default under @file{/gnu/store}. The directory name contains
568717fd
LC
258a hash of all the inputs used to build that package; thus, changing an
259input yields a different directory name.
260
261This approach is the foundation of Guix's salient features: support for
4bfc4ea3 262transactional package upgrade and rollback, per-user installation, and
eeaf4427 263garbage collection of packages (@pxref{Features}).
568717fd 264
4bfc4ea3 265Guix has a command-line interface, which allows users to build, install,
568717fd 266upgrade, and remove packages, as well as a Scheme programming interface.
568717fd 267
3ca2731c 268@cindex Guix System Distribution
4705641f 269@cindex GuixSD
a1ba8475 270Last but not least, Guix is used to build a distribution of the GNU
3ca2731c 271system, with many GNU and non-GNU free software packages. The Guix
4705641f
LC
272System Distribution, or GNU@tie{}GuixSD, takes advantage of the core
273properties of Guix at the system level. With GuixSD, users
3ca2731c
LC
274@emph{declare} all aspects of the operating system configuration, and
275Guix takes care of instantiating that configuration in a reproducible,
276stateless fashion. @xref{GNU Distribution}.
a1ba8475 277
bd5e766b
LC
278@c *********************************************************************
279@node Installation
280@chapter Installation
281
48febeb8
LC
282GNU Guix is available for download from its website at
283@url{http://www.gnu.org/software/guix/}. This section describes the
284software requirements of Guix, as well as how to install it and get
285ready to use it.
bd5e766b 286
5af6de3e
LC
287Note that this section is concerned with the installation of the package
288manager, which can be done on top of a running GNU/Linux system. If,
289instead, you want to install the complete GNU operating system,
6621cdb6 290@pxref{System Installation}.
5af6de3e 291
bd5e766b 292@menu
09722b11 293* Binary Installation:: Getting Guix running in no time!
bd5e766b 294* Requirements:: Software needed to build and run Guix.
ec0339cd 295* Running the Test Suite:: Testing Guix.
bd5e766b
LC
296* Setting Up the Daemon:: Preparing the build daemon's environment.
297* Invoking guix-daemon:: Running the build daemon.
0e2d0213 298* Application Setup:: Application-specific setup.
bd5e766b
LC
299@end menu
300
09722b11
LC
301@node Binary Installation
302@section Binary Installation
303
304This section describes how to install Guix on an arbitrary system from a
305self-contained tarball providing binaries for Guix and for all its
306dependencies. This is often quicker than installing from source, which
307is described in the next sections. The only requirement is to have
308GNU@tie{}tar and Xz.
309
310Installing goes along these lines:
311
312@enumerate
313@item
314Download the binary tarball from
ae806096 315@indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz}@footnote{As
09722b11
LC
316usual, make sure to download the associated @file{.sig} file and to
317verify the authenticity of the tarball against it!}, where @var{system}
318is @code{x86_64-linux} for an @code{x86_64} machine already running the
319kernel Linux, and so on.
320
321@item
322As @code{root}, run:
323
324@example
5dc42964 325# cd /tmp
254b1c2e
LC
326# tar --warning=no-timestamp -xf \
327 guix-binary-@value{VERSION}.@var{system}.tar.xz
5dc42964 328# mv var/guix /var/ && mv gnu /
09722b11
LC
329@end example
330
7acd3439
LC
331This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
332The latter contains a ready-to-use profile for @code{root} (see next
333step.)
09722b11 334
5dc3ce5f
LC
335Do @emph{not} unpack the tarball on a working Guix system since that
336would overwrite its own essential files.
337
254b1c2e 338The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
e9ba6357
LC
339not emit warnings about ``implausibly old time stamps'' (such
340warnings were triggered by GNU@tie{}tar 1.26 and older; recent
341versions are fine.)
342They stem from the fact that all the
254b1c2e
LC
343files in the archive have their modification time set to zero (which
344means January 1st, 1970.) This is done on purpose to make sure the
345archive content is independent of its creation time, thus making it
346reproducible.
347
7acd3439
LC
348@item
349Make @code{root}'s profile available under @file{~/.guix-profile}:
350
351@example
352# ln -sf /var/guix/profiles/per-user/root/guix-profile \
353 ~root/.guix-profile
354@end example
355
43c33047
LC
356@item
357Create the group and user accounts for build users as explained below
358(@pxref{Build Environment Setup}).
359
09722b11 360@item
175ced41 361Run the daemon:
09722b11
LC
362
363@example
7acd3439 364# ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
09722b11
LC
365@end example
366
d2825c96
LC
367On hosts using the systemd init system, drop
368@file{~root/.guix-profile/lib/systemd/system/guix-daemon.service} in
369@file{/etc/systemd/system}.
370
ad227484
MDRS
371Likewise, on hosts using the Upstart init system, drop
372@file{~root/.guix-profile/lib/upstart/system/guix-daemon.conf} in
373@file{/etc/init}.
374
09722b11
LC
375@item
376Make the @command{guix} command available to other users on the machine,
377for instance with:
378
379@example
380# mkdir -p /usr/local/bin
381# cd /usr/local/bin
d72d05f9 382# ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
09722b11 383@end example
39f8ed14
LC
384
385@item
386To use substitutes from @code{hydra.gnu.org} (@pxref{Substitutes}),
387authorize them:
388
389@example
7acd3439 390# guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
39f8ed14 391@end example
09722b11
LC
392@end enumerate
393
53de532f
LC
394And that's it! For additional tips and tricks, @pxref{Application
395Setup}.
09722b11 396
5dc3ce5f 397The @code{guix} package must remain available in @code{root}'s
09722b11
LC
398profile, or it would become subject to garbage collection---in which
399case you would find yourself badly handicapped by the lack of the
400@command{guix} command.
401
39f8ed14
LC
402The tarball in question can be (re)produced and verified simply by
403running the following command in the Guix source tree:
09722b11
LC
404
405@example
406make guix-binary.@var{system}.tar.xz
407@end example
408
409
bd5e766b
LC
410@node Requirements
411@section Requirements
412
09722b11
LC
413This section lists requirements when building Guix from source. The
414build procedure for Guix is the same as for other GNU software, and is
415not covered here. Please see the files @file{README} and @file{INSTALL}
416in the Guix source tree for additional details.
417
bd5e766b
LC
418GNU Guix depends on the following packages:
419
420@itemize
47c66da0 421@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
288dca55 422@item @url{http://gnupg.org/, GNU libgcrypt};
f0b98b84 423@item @url{http://www.gnu.org/software/make/, GNU Make}.
8a96bd4b
ID
424@end itemize
425
426The following dependencies are optional:
427
428@itemize
288dca55 429@item
8a96bd4b 430Installing
288dca55 431@url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
2f7d2d91
LC
432allow you to use the @command{guix import pypi} command (@pxref{Invoking
433guix import}). It is of
288dca55 434interest primarily for developers and not for casual users.
8a96bd4b
ID
435@item
436Installing @uref{http://gnutls.org/, GnuTLS-Guile} will
437allow you to access @code{https} URLs with the @command{guix download}
d45dc6da
EB
438command (@pxref{Invoking guix download}), the @command{guix import pypi}
439command, and the @command{guix import cpan} command. This is primarily
440of interest to developers. @xref{Guile Preparations, how to install the
441GnuTLS bindings for Guile,, gnutls-guile, GnuTLS-Guile}.
bd5e766b
LC
442@end itemize
443
444Unless @code{--disable-daemon} was passed to @command{configure}, the
445following packages are also needed:
446
447@itemize
368d08f7
LC
448@item @url{http://sqlite.org, SQLite 3};
449@item @url{http://www.bzip.org, libbz2};
450@item @url{http://gcc.gnu.org, GCC's g++}, with support for the
451C++11 standard.
bd5e766b
LC
452@end itemize
453
4bfc4ea3
NK
454When a working installation of @url{http://nixos.org/nix/, the Nix package
455manager} is available, you
bd5e766b 456can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 457Nix replaces the three dependencies above.
bd5e766b 458
b22a12fd
LC
459Guix is compatible with Nix, so it is possible to share the same store
460between both. To do so, you must pass @command{configure} not only the
461same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
462@code{--localstatedir} value. The latter is essential because it
463specifies where the database that stores metadata about the store is
834129e0 464located, among other things. The default values for Nix are
b22a12fd 465@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
466Note that @code{--disable-daemon} is not required if
467your goal is to share the store with Nix.
b22a12fd 468
ec0339cd
LC
469@node Running the Test Suite
470@section Running the Test Suite
471
472After a successful @command{configure} and @code{make} run, it is a good
473idea to run the test suite. It can help catch issues with the setup or
474environment, or bugs in Guix itself---and really, reporting test
475failures is a good way to help improve the software. To run the test
476suite, type:
477
478@example
479make check
480@end example
481
482Test cases can run in parallel: you can use the @code{-j} option of
483GNU@tie{}make to speed things up. The first run may take a few minutes
484on a recent machine; subsequent runs will be faster because the store
485that is created for test purposes will already have various things in
486cache.
487
488Upon failure, please email @email{bug-guix@@gnu.org} and attach the
489@file{test-suite.log} file. When @file{tests/@var{something}.scm}
490fails, please also attach the @file{@var{something}.log} file available
491in the top-level build directory. Please specify the Guix version being
492used as well as version numbers of the dependencies
493(@pxref{Requirements}) in your message.
494
bd5e766b
LC
495@node Setting Up the Daemon
496@section Setting Up the Daemon
497
498@cindex daemon
499Operations such as building a package or running the garbage collector
49e6291a 500are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
501behalf of clients. Only the daemon may access the store and its
502associated database. Thus, any operation that manipulates the store
503goes through the daemon. For instance, command-line tools such as
e49951eb 504@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
505daemon (@i{via} remote procedure calls) to instruct it what to do.
506
49e6291a 507The following sections explain how to prepare the build daemon's
225dafde
LC
508environment. Also @ref{Substitutes}, for information on how to allow
509the daemon to download pre-built binaries.
49e6291a
LC
510
511@menu
512* Build Environment Setup:: Preparing the isolated build environment.
513* Daemon Offload Setup:: Offloading builds to remote machines.
514@end menu
515
516@node Build Environment Setup
517@subsection Build Environment Setup
518
bd5e766b
LC
519In a standard multi-user setup, Guix and its daemon---the
520@command{guix-daemon} program---are installed by the system
834129e0 521administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
522@command{guix-daemon} runs as @code{root}. Unprivileged users may use
523Guix tools to build packages or otherwise access the store, and the
524daemon will do it on their behalf, ensuring that the store is kept in a
525consistent state, and allowing built packages to be shared among users.
526
527@cindex build users
528When @command{guix-daemon} runs as @code{root}, you may not want package
529build processes themselves to run as @code{root} too, for obvious
530security reasons. To avoid that, a special pool of @dfn{build users}
531should be created for use by build processes started by the daemon.
532These build users need not have a shell and a home directory: they will
533just be used when the daemon drops @code{root} privileges in build
534processes. Having several such users allows the daemon to launch
535distinct build processes under separate UIDs, which guarantees that they
536do not interfere with each other---an essential feature since builds are
537regarded as pure functions (@pxref{Introduction}).
538
539On a GNU/Linux system, a build user pool may be created like this (using
540Bash syntax and the @code{shadow} commands):
541
091196b3
LC
542@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
543@c for why `-G' is needed.
bd5e766b 544@example
cfc149dc
LC
545# groupadd --system guixbuild
546# for i in `seq -w 1 10`;
bd5e766b 547 do
cfc149dc
LC
548 useradd -g guixbuild -G guixbuild \
549 -d /var/empty -s `which nologin` \
550 -c "Guix build user $i" --system \
551 guixbuilder$i;
bd5e766b
LC
552 done
553@end example
554
555@noindent
54eb03ab
LC
556The number of build users determines how many build jobs may run in
557parallel, as specified by the @option{--max-jobs} option
d2825c96
LC
558(@pxref{Invoking guix-daemon, @option{--max-jobs}}). The
559@code{guix-daemon} program may then be run as @code{root} with the
560following command@footnote{If your machine uses the systemd init system,
561dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
562file in @file{/etc/systemd/system} will ensure that
ad227484
MDRS
563@command{guix-daemon} is automatically started. Similarly, if your
564machine uses the Upstart init system, drop the
565@file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
566file in @file{/etc/init}.}:
bd5e766b
LC
567
568@example
cfc149dc 569# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
570@end example
571
e900c503 572@cindex chroot
b095792f
LC
573@noindent
574This way, the daemon starts build processes in a chroot, under one of
cfc149dc 575the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
576environment contains nothing but:
577
578@c Keep this list in sync with libstore/build.cc! -----------------------
579@itemize
580@item
4743a4da
LC
581a minimal @code{/dev} directory, created mostly independently from the
582host @code{/dev}@footnote{``Mostly'', because while the set of files
583that appear in the chroot's @code{/dev} is fixed, most of these files
584can only be created if the host has them.};
585
586@item
587the @code{/proc} directory; it only shows the container's processes
588since a separate PID name space is used;
6dc99317
LC
589
590@item
591@file{/etc/passwd} with an entry for the current user and an entry for
592user @file{nobody};
593
594@item
595@file{/etc/group} with an entry for the user's group;
596
597@item
598@file{/etc/hosts} with an entry that maps @code{localhost} to
599@code{127.0.0.1};
600
601@item
602a writable @file{/tmp} directory.
603@end itemize
b095792f 604
cb960102
ED
605You can influence the directory where the daemon stores build trees
606@i{via} the @code{TMPDIR} environment variable. However, the build tree
7a57c96a 607within the chroot is always @file{/tmp/guix-build-@var{name}.drv-0},
cb960102
ED
608where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
609This way, the value of @code{TMPDIR} does not leak inside build
610environments, which avoids discrepancies in cases where build processes
611capture the name of their build tree.
612
1e2644bb
LC
613If you are installing Guix as an unprivileged user, it is still possible
614to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
615However, build processes will not be isolated from one another, and not
616from the rest of the system. Thus, build processes may interfere with
617each other, and may access programs, libraries, and other files
618available on the system---making it much harder to view them as
619@emph{pure} functions.
bd5e766b 620
49e6291a
LC
621
622@node Daemon Offload Setup
623@subsection Using the Offload Facility
624
625@cindex offloading
4ec2e92d
LC
626@cindex build hook
627When desired, the build daemon can @dfn{offload}
628derivation builds to other machines
49e6291a
LC
629running Guix, using the @code{offload} @dfn{build hook}. When that
630feature is enabled, a list of user-specified build machines is read from
631@file{/etc/guix/machines.scm}; anytime a build is requested, for
632instance via @code{guix build}, the daemon attempts to offload it to one
633of the machines that satisfies the derivation's constraints, in
634particular its system type---e.g., @file{x86_64-linux}. Missing
635prerequisites for the build are copied over SSH to the target machine,
636which then proceeds with the build; upon success the output(s) of the
637build are copied back to the initial machine.
638
4ec2e92d 639The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
640
641@example
642(list (build-machine
643 (name "eightysix.example.org")
644 (system "x86_64-linux")
645 (user "bob")
646 (speed 2.)) ; incredibly fast!
647
648 (build-machine
649 (name "meeps.example.org")
650 (system "mips64el-linux")
651 (user "alice")
652 (private-key
653 (string-append (getenv "HOME")
c4fdfd6f 654 "/.lsh/identity-for-guix"))))
49e6291a
LC
655@end example
656
657@noindent
658In the example above we specify a list of two build machines, one for
659the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
660architecture.
661
662In fact, this file is---not surprisingly!---a Scheme file that is
663evaluated when the @code{offload} hook is started. Its return value
664must be a list of @code{build-machine} objects. While this example
665shows a fixed list of build machines, one could imagine, say, using
666DNS-SD to return a list of potential build machines discovered in the
667local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
c678a4ee
LC
668Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
669detailed below.
4ec2e92d 670
c678a4ee
LC
671@deftp {Data Type} build-machine
672This data type represents build machines the daemon may offload builds
673to. The important fields are:
49e6291a
LC
674
675@table @code
676
677@item name
678The remote machine's host name.
679
680@item system
c678a4ee 681The remote machine's system type---e.g., @code{"x86_64-linux"}.
49e6291a
LC
682
683@item user
684The user account to use when connecting to the remote machine over SSH.
685Note that the SSH key pair must @emph{not} be passphrase-protected, to
686allow non-interactive logins.
687
688@end table
689
4ec2e92d 690A number of optional fields may be specified:
49e6291a
LC
691
692@table @code
693
cecd72d5
LC
694@item port
695Port number of the machine's SSH server (default: 22).
696
49e6291a
LC
697@item private-key
698The SSH private key file to use when connecting to the machine.
699
c4fdfd6f
LC
700Currently offloading uses GNU@tie{}lsh as its SSH client
701(@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must
702be an lsh key file. This may change in the future, though.
703
49e6291a
LC
704@item parallel-builds
705The number of builds that may run in parallel on the machine (1 by
706default.)
707
708@item speed
709A ``relative speed factor''. The offload scheduler will tend to prefer
710machines with a higher speed factor.
711
712@item features
713A list of strings denoting specific features supported by the machine.
714An example is @code{"kvm"} for machines that have the KVM Linux modules
715and corresponding hardware support. Derivations can request features by
716name, and they will be scheduled on matching build machines.
717
718@end table
c678a4ee 719@end deftp
49e6291a
LC
720
721The @code{guix} command must be in the search path on the build
722machines, since offloading works by invoking the @code{guix archive} and
c4fdfd6f
LC
723@code{guix build} commands. In addition, the Guix modules must be in
724@code{$GUILE_LOAD_PATH} on the build machine---you can check whether
725this is the case by running:
726
727@example
728lsh build-machine guile -c '(use-modules (guix config))'
729@end example
49e6291a
LC
730
731There's one last thing to do once @file{machines.scm} is in place. As
732explained above, when offloading, files are transferred back and forth
c4fdfd6f
LC
733between the machine stores. For this to work, you first need to
734generate a key pair on each machine to allow the daemon to export signed
735archives of files from the store (@pxref{Invoking guix archive}):
49e6291a
LC
736
737@example
738# guix archive --generate-key
739@end example
740
741@noindent
c4fdfd6f
LC
742Each build machine must authorize the key of the master machine so that
743it accepts store items it receives from the master:
744
745@example
746# guix archive --authorize < master-public-key.txt
747@end example
748
749@noindent
750Likewise, the master machine must authorize the key of each build machine.
751
752All the fuss with keys is here to express pairwise mutual trust
753relations between the master and the build machines. Concretely, when
754the master receives files from a build machine (and @i{vice versa}), its
755build daemon can make sure they are genuine, have not been tampered
756with, and that they are signed by an authorized key.
49e6291a
LC
757
758
bd5e766b
LC
759@node Invoking guix-daemon
760@section Invoking @command{guix-daemon}
761
762The @command{guix-daemon} program implements all the functionality to
763access the store. This includes launching build processes, running the
764garbage collector, querying the availability of a build result, etc. It
765is normally run as @code{root} like this:
766
767@example
cfc149dc 768# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
769@end example
770
771@noindent
081145cf 772For details on how to set it up, @pxref{Setting Up the Daemon}.
bd5e766b 773
e900c503
LC
774@cindex chroot
775@cindex container, build environment
776@cindex build environment
777@cindex reproducible builds
bd5e766b
LC
778By default, @command{guix-daemon} launches build processes under
779different UIDs, taken from the build group specified with
780@code{--build-users-group}. In addition, each build process is run in a
781chroot environment that only contains the subset of the store that the
782build process depends on, as specified by its derivation
783(@pxref{Programming Interface, derivation}), plus a set of specific
784system directories. By default, the latter contains @file{/dev} and
e900c503
LC
785@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
786@dfn{container}: in addition to having its own file system tree, it has
787a separate mount name space, its own PID name space, network name space,
788etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b 789
cbc538fe
LC
790When the daemon performs a build on behalf of the user, it creates a
791build directory under @file{/tmp} or under the directory specified by
792its @code{TMPDIR} environment variable; this directory is shared with
793the container for the duration of the build. Be aware that using a
794directory other than @file{/tmp} can affect build results---for example,
795with a longer directory name, a build process that uses Unix-domain
796sockets might hit the name length limitation for @code{sun_path}, which
797it would otherwise not hit.
798
799The build directory is automatically deleted upon completion, unless the
800build failed and the client specified @option{--keep-failed}
801(@pxref{Invoking guix build, @option{--keep-failed}}).
802
bd5e766b
LC
803The following command-line options are supported:
804
805@table @code
806@item --build-users-group=@var{group}
807Take users from @var{group} to run build processes (@pxref{Setting Up
808the Daemon, build users}).
809
6858f9d1 810@item --no-substitutes
b5385b52 811@cindex substitutes
6858f9d1 812Do not use substitutes for build products. That is, always build things
c4202d60
LC
813locally instead of allowing downloads of pre-built binaries
814(@pxref{Substitutes}).
6858f9d1 815
b5385b52
LC
816By default substitutes are used, unless the client---such as the
817@command{guix package} command---is explicitly invoked with
818@code{--no-substitutes}.
819
820When the daemon runs with @code{--no-substitutes}, clients can still
821explicitly enable substitution @i{via} the @code{set-build-options}
822remote procedure call (@pxref{The Store}).
823
9176607e 824@item --substitute-urls=@var{urls}
f8a8e0fe 825@anchor{daemon-substitute-urls}
9176607e 826Consider @var{urls} the default whitespace-separated list of substitute
ae806096 827source URLs. When this option is omitted, @indicateurl{http://hydra.gnu.org}
9176607e
LC
828is used.
829
830This means that substitutes may be downloaded from @var{urls}, as long
831as they are signed by a trusted signature (@pxref{Substitutes}).
832
4ec2e92d
LC
833@cindex build hook
834@item --no-build-hook
835Do not use the @dfn{build hook}.
836
837The build hook is a helper program that the daemon can start and to
838which it submits build requests. This mechanism is used to offload
839builds to other machines (@pxref{Daemon Offload Setup}).
840
bd5e766b
LC
841@item --cache-failures
842Cache build failures. By default, only successful builds are cached.
843
30d9aa54
LC
844When this option is used, @command{guix gc --list-failures} can be used
845to query the set of store items marked as failed; @command{guix gc
846--clear-failures} removes store items from the set of cached failures.
847@xref{Invoking guix gc}.
848
bd5e766b
LC
849@item --cores=@var{n}
850@itemx -c @var{n}
851Use @var{n} CPU cores to build each derivation; @code{0} means as many
852as available.
853
6efc160e 854The default value is @code{0}, but it may be overridden by clients, such
e49951eb
MW
855as the @code{--cores} option of @command{guix build} (@pxref{Invoking
856guix build}).
bd5e766b
LC
857
858The effect is to define the @code{NIX_BUILD_CORES} environment variable
859in the build process, which can then use it to exploit internal
860parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
861
862@item --max-jobs=@var{n}
863@itemx -M @var{n}
864Allow at most @var{n} build jobs in parallel. The default value is
f6526eb3
LC
865@code{1}. Setting it to @code{0} means that no builds will be performed
866locally; instead, the daemon will offload builds (@pxref{Daemon Offload
867Setup}), or simply fail.
bd5e766b 868
ecf84b7c
LC
869@item --rounds=@var{N}
870Build each derivation @var{n} times in a row, and raise an error if
871consecutive build results are not bit-for-bit identical. Note that this
872setting can be overridden by clients such as @command{guix build}
873(@pxref{Invoking guix build}).
874
bd5e766b
LC
875@item --debug
876Produce debugging output.
877
878This is useful to debug daemon start-up issues, but then it may be
879overridden by clients, for example the @code{--verbosity} option of
e49951eb 880@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
881
882@item --chroot-directory=@var{dir}
883Add @var{dir} to the build chroot.
884
885Doing this may change the result of build processes---for instance if
886they use optional dependencies found in @var{dir} when it is available,
887and not otherwise. For that reason, it is not recommended to do so.
888Instead, make sure that each derivation declares all the inputs that it
889needs.
890
891@item --disable-chroot
892Disable chroot builds.
893
894Using this option is not recommended since, again, it would allow build
1e2644bb
LC
895processes to gain access to undeclared dependencies. It is necessary,
896though, when @command{guix-daemon} is running under an unprivileged user
897account.
bd5e766b
LC
898
899@item --disable-log-compression
900Disable compression of the build logs.
901
1da983b9
LC
902Unless @code{--lose-logs} is used, all the build logs are kept in the
903@var{localstatedir}. To save space, the daemon automatically compresses
904them with bzip2 by default. This option disables that.
905
ab3893d7
LC
906@item --disable-deduplication
907@cindex deduplication
bd5e766b
LC
908Disable automatic file ``deduplication'' in the store.
909
1da983b9 910By default, files added to the store are automatically ``deduplicated'':
ab3893d7
LC
911if a newly added file is identical to another one found in the store,
912the daemon makes the new file a hard link to the other file. This can
4988dd40 913noticeably reduce disk usage, at the expense of slightly increased
ab3893d7
LC
914input/output load at the end of a build process. This option disables
915this optimization.
1da983b9 916
6e37066e
LC
917@item --gc-keep-outputs[=yes|no]
918Tell whether the garbage collector (GC) must keep outputs of live
919derivations.
920
921When set to ``yes'', the GC will keep the outputs of any live derivation
922available in the store---the @code{.drv} files. The default is ``no'',
923meaning that derivation outputs are kept only if they are GC roots.
924
925@item --gc-keep-derivations[=yes|no]
926Tell whether the garbage collector (GC) must keep derivations
927corresponding to live outputs.
928
929When set to ``yes'', as is the case by default, the GC keeps
930derivations---i.e., @code{.drv} files---as long as at least one of their
931outputs is live. This allows users to keep track of the origins of
932items in their store. Setting it to ``no'' saves a bit of disk space.
933
934Note that when both @code{--gc-keep-derivations} and
935@code{--gc-keep-outputs} are used, the effect is to keep all the build
936prerequisites (the sources, compiler, libraries, and other build-time
937tools) of live objects in the store, regardless of whether these
938prerequisites are live. This is convenient for developers since it
939saves rebuilds or downloads.
940
bd5e766b
LC
941@item --impersonate-linux-2.6
942On Linux-based systems, impersonate Linux 2.6. This means that the
943kernel's @code{uname} system call will report 2.6 as the release number.
944
945This might be helpful to build programs that (usually wrongfully) depend
946on the kernel version number.
947
948@item --lose-logs
949Do not keep build logs. By default they are kept under
ce33631f 950@code{@var{localstatedir}/guix/log}.
bd5e766b
LC
951
952@item --system=@var{system}
953Assume @var{system} as the current system type. By default it is the
954architecture/kernel pair found at configure time, such as
955@code{x86_64-linux}.
b8d2aa26
LC
956
957@item --listen=@var{socket}
958Listen for connections on @var{socket}, the file name of a Unix-domain
959socket. The default socket is
960@file{@var{localstatedir}/daemon-socket/socket}. This option is only
961useful in exceptional circumstances, such as if you need to run several
962daemons on the same machine.
bd5e766b
LC
963@end table
964
965
0e2d0213
LC
966@node Application Setup
967@section Application Setup
968
85e57214
LC
969When using Guix on top of GNU/Linux distribution other than GuixSD---a
970so-called @dfn{foreign distro}---a few additional steps are needed to
971get everything in place. Here are some of them.
0e2d0213
LC
972
973@subsection Locales
974
5c3c1427 975@anchor{locales-and-locpath}
0e2d0213 976@cindex locales, when not on GuixSD
5c3c1427 977@vindex LOCPATH
85e57214 978@vindex GUIX_LOCPATH
0e2d0213
LC
979Packages installed @i{via} Guix will not use the host system's locale
980data. Instead, you must first install one of the locale packages
85e57214
LC
981available with Guix and then define the @code{GUIX_LOCPATH} environment
982variable:
0e2d0213
LC
983
984@example
985$ guix package -i glibc-locales
85e57214 986$ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
0e2d0213
LC
987@end example
988
989Note that the @code{glibc-locales} package contains data for all the
990locales supported by the GNU@tie{}libc and weighs in at around
991110@tie{}MiB. Alternately, the @code{glibc-utf8-locales} is smaller but
992limited to a few UTF-8 locales.
993
85e57214
LC
994The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
995(@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
996Manual}). There are two important differences though:
997
998@enumerate
999@item
1000@code{GUIX_LOCPATH} is honored only by Guix's libc, and not by the libc
1001provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
1002to make sure the the foreign distro's programs will not end up loading
1003incompatible locale data.
1004
1005@item
1006libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1007@code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1008should your Guix profile contain a mixture of programs linked against
1009different libc version, each libc version will only try to load locale
1010data in the right format.
1011@end enumerate
1012
1013This is important because the locale data format used by different libc
1014versions may be incompatible.
1015
0e2d0213
LC
1016@subsection X11 Fonts
1017
4988dd40 1018The majority of graphical applications use Fontconfig to locate and
0e2d0213
LC
1019load fonts and perform X11-client-side rendering. Guix's
1020@code{fontconfig} package looks for fonts in @file{$HOME/.guix-profile}
1021by default. Thus, to allow graphical applications installed with Guix
1022to display fonts, you will have to install fonts with Guix as well.
1023Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
8fe5b1d1 1024@code{font-gnu-freefont-ttf}.
0e2d0213 1025
5c36edc8
LC
1026To display text written in Chinese languages, Japanese, or Korean in
1027graphical applications, consider installing
1028@code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1029has multiple outputs, one per language family (@pxref{Packages with
1030Multiple Outputs}). For instance, the following command installs fonts
1031for Chinese languages:
1032
1033@example
1034guix package -i font-adobe-source-han-sans:cn
1035@end example
1036
0e2d0213
LC
1037@c TODO What else?
1038
eeaf4427
LC
1039@c *********************************************************************
1040@node Package Management
1041@chapter Package Management
1042
f8348b91 1043The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427
LC
1044remove software packages, without having to know about their build
1045procedure or dependencies. Guix also goes beyond this obvious set of
1046features.
1047
1048This chapter describes the main features of Guix, as well as the package
c1941588 1049management tools it provides. Two user interfaces are provided for
c554de89
AK
1050routine package management tasks: A command-line interface described below
1051(@pxref{Invoking guix package, @code{guix package}}), as well as a visual user
1052interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}).
eeaf4427
LC
1053
1054@menu
1055* Features:: How Guix will make your life brighter.
e49951eb 1056* Invoking guix package:: Package installation, removal, etc.
c4202d60 1057* Substitutes:: Downloading pre-built binaries.
760c60d6 1058* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 1059* Invoking guix gc:: Running the garbage collector.
f651b477 1060* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 1061* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
1062@end menu
1063
1064@node Features
1065@section Features
1066
1067When using Guix, each package ends up in the @dfn{package store}, in its
1068own directory---something that resembles
9a130e19
AK
1069@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
1070(note that Guix comes with an Emacs extension to shorten those file
081145cf 1071names, @pxref{Emacs Prettify}.)
eeaf4427
LC
1072
1073Instead of referring to these directories, users have their own
1074@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
1075use. These profiles are stored within each user's home directory, at
1076@code{$HOME/.guix-profile}.
eeaf4427 1077
821b0015 1078For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 1079@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 1080@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
1081@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1082simply continues to point to
834129e0 1083@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 1084coexist on the same system without any interference.
eeaf4427 1085
e49951eb
MW
1086The @command{guix package} command is the central tool to manage
1087packages (@pxref{Invoking guix package}). It operates on those per-user
821b0015 1088profiles, and can be used @emph{with normal user privileges}.
eeaf4427
LC
1089
1090The command provides the obvious install, remove, and upgrade
1091operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 1092the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 1093@command{guix package} process is terminated during the transaction,
eeaf4427
LC
1094or if a power outage occurs during the transaction, then the user's
1095profile remains in its previous state, and remains usable.
1096
1097In addition, any package transaction may be @emph{rolled back}. So, if,
1098for example, an upgrade installs a new version of a package that turns
1099out to have a serious bug, users may roll back to the previous instance
4af2447e
LC
1100of their profile, which was known to work well. Similarly, the global
1101system configuration is subject to transactional upgrades and roll-back
1102(@pxref{Using the Configuration System}).
eeaf4427
LC
1103
1104All those packages in the package store may be @emph{garbage-collected}.
1105Guix can determine which packages are still referenced by the user
fe8ff028 1106profiles, and remove those that are provably no longer referenced
e49951eb 1107(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
1108generations of their profile so that the packages they refer to can be
1109collected.
eeaf4427 1110
e900c503
LC
1111@cindex reproducibility
1112@cindex reproducible builds
eeaf4427
LC
1113Finally, Guix takes a @dfn{purely functional} approach to package
1114management, as described in the introduction (@pxref{Introduction}).
834129e0 1115Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
1116inputs that were used to build that package---compiler, libraries, build
1117scripts, etc. This direct correspondence allows users to make sure a
1118given package installation matches the current state of their
e900c503
LC
1119distribution. It also helps maximize @dfn{build reproducibility}:
1120thanks to the isolated build environments that are used, a given build
1121is likely to yield bit-identical files when performed on different
1122machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 1123
c4202d60 1124@cindex substitutes
eeaf4427 1125This foundation allows Guix to support @dfn{transparent binary/source
c4202d60 1126deployment}. When a pre-built binary for a @file{/gnu/store} item is
18f2887b 1127available from an external source---a @dfn{substitute}, Guix just
c4202d60
LC
1128downloads it and unpacks it;
1129otherwise, it builds the package from source, locally
1130(@pxref{Substitutes}).
eeaf4427 1131
f5fd4fd2
LC
1132Control over the build environment is a feature that is also useful for
1133developers. The @command{guix environment} command allows developers of
1134a package to quickly set up the right development environment for their
1135package, without having to manually install the package's dependencies
1136in their profile (@pxref{Invoking guix environment}).
1137
e49951eb
MW
1138@node Invoking guix package
1139@section Invoking @command{guix package}
eeaf4427 1140
e49951eb 1141The @command{guix package} command is the tool that allows users to
eeaf4427
LC
1142install, upgrade, and remove packages, as well as rolling back to
1143previous configurations. It operates only on the user's own profile,
1144and works with normal user privileges (@pxref{Features}). Its syntax
1145is:
1146
1147@example
e49951eb 1148guix package @var{options}
eeaf4427
LC
1149@end example
1150
ba55b1cb 1151Primarily, @var{options} specifies the operations to be performed during
eeaf4427 1152the transaction. Upon completion, a new profile is created, but
99bd74d5 1153previous @dfn{generations} of the profile remain available, should the user
eeaf4427
LC
1154want to roll back.
1155
6447738c
MW
1156For example, to remove @code{lua} and install @code{guile} and
1157@code{guile-cairo} in a single transaction:
1158
1159@example
1160guix package -r lua -i guile guile-cairo
1161@end example
1162
99bd74d5
LC
1163@command{guix package} also supports a @dfn{declarative approach}
1164whereby the user specifies the exact set of packages to be available and
1165passes it @i{via} the @option{--manifest} option
1166(@pxref{profile-manifest, @option{--manifest}}).
1167
b9e5c0a9 1168For each user, a symlink to the user's default profile is automatically
0ec1af59 1169created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
1170current generation of the user's default profile. Thus, users can add
1171@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1172variable, and so on.
d664f1b4
LC
1173@cindex search paths
1174If you are not using the Guix System Distribution, consider adding the
1175following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1176Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1177shells get all the right environment variable definitions:
1178
1179@example
1180GUIX_PROFILE="$HOME/.guix-profile" \
1181source "$HOME/.guix-profile/etc/profile"
1182@end example
b9e5c0a9 1183
4379c35b
LC
1184In a multi-user setup, user profiles are stored in a place registered as
1185a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1186to (@pxref{Invoking guix gc}). That directory is normally
0ec1af59
LC
1187@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1188@var{localstatedir} is the value passed to @code{configure} as
4379c35b
LC
1189@code{--localstatedir}, and @var{user} is the user name. The
1190@file{per-user} directory is created when @command{guix-daemon} is
1191started, and the @var{user} sub-directory is created by @command{guix
1192package}.
0ec1af59
LC
1193
1194The @var{options} can be among the following:
1195
eeaf4427
LC
1196@table @code
1197
6447738c
MW
1198@item --install=@var{package} @dots{}
1199@itemx -i @var{package} @dots{}
1200Install the specified @var{package}s.
eeaf4427 1201
6447738c 1202Each @var{package} may specify either a simple package name, such as
eeaf4427 1203@code{guile}, or a package name followed by a hyphen and version number,
724311a2
LC
1204such as @code{guile-1.8.8} or simply @code{guile-1.8} (in the latter
1205case, the newest version prefixed by @code{1.8} is selected.)
1206
1207If no version number is specified, the
dc5669cd
MW
1208newest available version will be selected. In addition, @var{package}
1209may contain a colon, followed by the name of one of the outputs of the
6e721c4d 1210package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
e7f34eb0
LC
1211(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1212name (and optionally version) are searched for among the GNU
1213distribution modules (@pxref{Package Modules}).
eeaf4427 1214
461572cc
LC
1215@cindex propagated inputs
1216Sometimes packages have @dfn{propagated inputs}: these are dependencies
21461f27
LC
1217that automatically get installed along with the required package
1218(@pxref{package-propagated-inputs, @code{propagated-inputs} in
1219@code{package} objects}, for information about propagated inputs in
1220package definitions).
461572cc 1221
21461f27 1222@anchor{package-cmd-propagated-inputs}
461572cc
LC
1223An example is the GNU MPC library: its C header files refer to those of
1224the GNU MPFR library, which in turn refer to those of the GMP library.
1225Thus, when installing MPC, the MPFR and GMP libraries also get installed
1226in the profile; removing MPC also removes MPFR and GMP---unless they had
1227also been explicitly installed independently.
1228
ba7ea5ce 1229Besides, packages sometimes rely on the definition of environment
5924080d 1230variables for their search paths (see explanation of
ba7ea5ce 1231@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
1232environment variable definitions are reported here.
1233
ef010c0f 1234@c XXX: keep me up-to-date
5924080d 1235Finally, when installing a GNU package, the tool reports the
ef010c0f
LC
1236availability of a newer upstream version. In the future, it may provide
1237the option of installing directly from the upstream version, even if
1238that version is not yet in the distribution.
1239
5d4b411f
LC
1240@item --install-from-expression=@var{exp}
1241@itemx -e @var{exp}
1242Install the package @var{exp} evaluates to.
1243
1244@var{exp} must be a Scheme expression that evaluates to a
1245@code{<package>} object. This option is notably useful to disambiguate
1246between same-named variants of a package, with expressions such as
1247@code{(@@ (gnu packages base) guile-final)}.
1248
1249Note that this option installs the first output of the specified
1250package, which may be insufficient when needing a specific output of a
1251multiple-output package.
1252
0d279400
DT
1253@item --install-from-file=@var{file}
1254@itemx -f @var{file}
1255Install the package that the code within @var{file} evaluates to.
1256
1257As an example, @var{file} might contain a definition like this
1258(@pxref{Defining Packages}):
1259
1260@example
1261@verbatiminclude package-hello.scm
1262@end example
1263
1264Developers may find it useful to include such a @file{package.scm} file
1265in the root of their project's source tree that can be used to test
1266development snapshots and create reproducible development environments
1267(@pxref{Invoking guix environment}).
1268
6447738c
MW
1269@item --remove=@var{package} @dots{}
1270@itemx -r @var{package} @dots{}
1271Remove the specified @var{package}s.
eeaf4427 1272
6447738c 1273As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
1274and/or output name in addition to the package name. For instance,
1275@code{-r glibc:debug} would remove the @code{debug} output of
1276@code{glibc}.
1277
6447738c
MW
1278@item --upgrade[=@var{regexp} @dots{}]
1279@itemx -u [@var{regexp} @dots{}]
1280Upgrade all the installed packages. If one or more @var{regexp}s are
1281specified, upgrade only installed packages whose name matches a
d5f01e48 1282@var{regexp}. Also see the @code{--do-not-upgrade} option below.
eeaf4427 1283
f651b477
LC
1284Note that this upgrades package to the latest version of packages found
1285in the distribution currently installed. To update your distribution,
1286you should regularly run @command{guix pull} (@pxref{Invoking guix
1287pull}).
1288
d5f01e48
MW
1289@item --do-not-upgrade[=@var{regexp} @dots{}]
1290When used together with the @code{--upgrade} option, do @emph{not}
1291upgrade any packages whose name matches a @var{regexp}. For example, to
1292upgrade all packages in the current profile except those containing the
1293substring ``emacs'':
1294
1295@example
1296$ guix package --upgrade . --do-not-upgrade emacs
1297@end example
1298
99bd74d5 1299@item @anchor{profile-manifest}--manifest=@var{file}
1b676447 1300@itemx -m @var{file}
99bd74d5
LC
1301@cindex profile declaration
1302@cindex profile manifest
1303Create a new generation of the profile from the manifest object
1b676447
DT
1304returned by the Scheme code in @var{file}.
1305
99bd74d5
LC
1306This allows you to @emph{declare} the profile's contents rather than
1307constructing it through a sequence of @code{--install} and similar
1308commands. The advantage is that @var{file} can be put under version
1309control, copied to different machines to reproduce the same profile, and
1310so on.
1311
1312@c FIXME: Add reference to (guix profile) documentation when available.
1313@var{file} must return a @dfn{manifest} object, which is roughly a list
1314of packages:
1b676447 1315
99bd74d5 1316@findex packages->manifest
1b676447 1317@example
99bd74d5 1318(use-package-modules guile emacs)
1b676447
DT
1319
1320(packages->manifest
99bd74d5
LC
1321 (list emacs
1322 guile-2.0
1b676447 1323 ;; Use a specific package output.
99bd74d5 1324 (list guile-2.0 "debug")))
1b676447
DT
1325@end example
1326
24e262f0
LC
1327@item --roll-back
1328Roll back to the previous @dfn{generation} of the profile---i.e., undo
1329the last transaction.
1330
1331When combined with options such as @code{--install}, roll back occurs
1332before any other actions.
1333
d9307267 1334When rolling back from the first generation that actually contains
4b2bc804
NK
1335installed packages, the profile is made to point to the @dfn{zeroth
1336generation}, which contains no files apart from its own meta-data.
d9307267 1337
82fe08ed
LC
1338Installing, removing, or upgrading packages from a generation that has
1339been rolled back to overwrites previous future generations. Thus, the
1340history of a profile's generations is always linear.
1341
b3bb82f1
AK
1342@item --switch-generation=@var{pattern}
1343@itemx -S @var{pattern}
1344Switch to a particular generation defined by @var{pattern}.
1345
1346@var{pattern} may be either a generation number or a number prefixed
1347with ``+'' or ``-''. The latter means: move forward/backward by a
1348specified number of generations. For example, if you want to return to
1349the latest generation after @code{--roll-back}, use
1350@code{--switch-generation=+1}.
1351
1352The difference between @code{--roll-back} and
1353@code{--switch-generation=-1} is that @code{--switch-generation} will
1354not make a zeroth generation, so if a specified generation does not
1355exist, the current generation will not be changed.
1356
dbc31ab2 1357@item --search-paths[=@var{kind}]
5924080d
LC
1358@cindex search paths
1359Report environment variable definitions, in Bash syntax, that may be
1360needed in order to use the set of installed packages. These environment
1361variables are used to specify @dfn{search paths} for files used by some
1362of the installed packages.
1363
1364For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1365environment variables to be defined so it can look for headers and
1366libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1367Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1368library are installed in the profile, then @code{--search-paths} will
1369suggest setting these variables to @code{@var{profile}/include} and
1370@code{@var{profile}/lib}, respectively.
1371
dbc31ab2
LC
1372The typical use case is to define these environment variables in the
1373shell:
1374
1375@example
1376$ eval `guix package --search-paths`
1377@end example
1378
1379@var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1380meaning that the returned environment variable definitions will either
1381be exact settings, or prefixes or suffixes of the current value of these
1382variables. When omitted, @var{kind} defaults to @code{exact}.
1383
fc2d2339
LC
1384This option can also be used to compute the @emph{combined} search paths
1385of several profiles. Consider this example:
1386
1387@example
1388$ guix package -p foo -i guile
1389$ guix package -p bar -i guile-json
1390$ guix package -p foo -p bar --search-paths
1391@end example
1392
1393The last command above reports about the @code{GUILE_LOAD_PATH}
1394variable, even though, taken individually, neither @file{foo} nor
1395@file{bar} would lead to that recommendation.
1396
1397
eeaf4427
LC
1398@item --profile=@var{profile}
1399@itemx -p @var{profile}
1400Use @var{profile} instead of the user's default profile.
1401
70915c1a
LC
1402@item --verbose
1403Produce verbose output. In particular, emit the environment's build log
1404on the standard error port.
1405
eeaf4427
LC
1406@item --bootstrap
1407Use the bootstrap Guile to build the profile. This option is only
1408useful to distribution developers.
1409
1410@end table
1411
e49951eb 1412In addition to these actions @command{guix package} supports the
733b4130
LC
1413following options to query the current state of a profile, or the
1414availability of packages:
eeaf4427 1415
733b4130
LC
1416@table @option
1417
acc08466
NK
1418@item --search=@var{regexp}
1419@itemx -s @var{regexp}
5763ad92 1420List the available packages whose name, synopsis, or description matches
299112d3
LC
1421@var{regexp}. Print all the meta-data of matching packages in
1422@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1423GNU recutils manual}).
acc08466 1424
299112d3
LC
1425This allows specific fields to be extracted using the @command{recsel}
1426command, for instance:
1427
1428@example
e49951eb 1429$ guix package -s malloc | recsel -p name,version
299112d3
LC
1430name: glibc
1431version: 2.17
1432
1433name: libgc
1434version: 7.2alpha6
1435@end example
acc08466 1436
a12d92f5
LC
1437Similarly, to show the name of all the packages available under the
1438terms of the GNU@tie{}LGPL version 3:
1439
1440@example
1441$ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1442name: elfutils
1443
1444name: gmp
1445@dots{}
1446@end example
1447
2aa6efb0
CR
1448@item --show=@var{package}
1449Show details about @var{package}, taken from the list of available packages, in
1450@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1451recutils manual}).
1452
1453@example
1454$ guix package --show=python | recsel -p name,version
1455name: python
1456version: 2.7.6
1457
1458name: python
1459version: 3.3.5
1460@end example
1461
1462You may also specify the full name of a package to only get details about a
1463specific version of it:
1464@example
1465$ guix package --show=python-3.3.5 | recsel -p name,version
1466name: python
1467version: 3.3.5
1468@end example
1469
1470
1471
733b4130
LC
1472@item --list-installed[=@var{regexp}]
1473@itemx -I [@var{regexp}]
bd9bde1c
LC
1474List the currently installed packages in the specified profile, with the
1475most recently installed packages shown last. When @var{regexp} is
1476specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
1477
1478For each installed package, print the following items, separated by
1479tabs: the package name, its version string, the part of the package that
1480is installed (for instance, @code{out} for the default output,
1481@code{include} for its headers, etc.), and the path of this package in
1482the store.
1483
64fc89b6
LC
1484@item --list-available[=@var{regexp}]
1485@itemx -A [@var{regexp}]
5763ad92 1486List packages currently available in the distribution for this system
a1ba8475
LC
1487(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1488installed packages whose name matches @var{regexp}.
64fc89b6
LC
1489
1490For each package, print the following items separated by tabs: its name,
6e721c4d
LC
1491its version string, the parts of the package (@pxref{Packages with
1492Multiple Outputs}), and the source location of its definition.
64fc89b6 1493
f566d765
LC
1494@item --list-generations[=@var{pattern}]
1495@itemx -l [@var{pattern}]
1496Return a list of generations along with their creation dates; for each
1497generation, show the installed packages, with the most recently
4b2bc804
NK
1498installed packages shown last. Note that the zeroth generation is never
1499shown.
f566d765
LC
1500
1501For each installed package, print the following items, separated by
1502tabs: the name of a package, its version string, the part of the package
1503that is installed (@pxref{Packages with Multiple Outputs}), and the
1504location of this package in the store.
1505
1506When @var{pattern} is used, the command returns only matching
1507generations. Valid patterns include:
1508
1509@itemize
1510@item @emph{Integers and comma-separated integers}. Both patterns denote
1511generation numbers. For instance, @code{--list-generations=1} returns
1512the first one.
1513
1514And @code{--list-generations=1,8,2} outputs three generations in the
1515specified order. Neither spaces nor trailing commas are allowed.
1516
1517@item @emph{Ranges}. @code{--list-generations=2..9} prints the
1518specified generations and everything in between. Note that the start of
1519a range must be lesser than its end.
1520
1521It is also possible to omit the endpoint. For example,
1522@code{--list-generations=2..}, returns all generations starting from the
1523second one.
1524
1525@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1526or months by passing an integer along with the first letter of the
d7ddb257
LC
1527duration. For example, @code{--list-generations=20d} lists generations
1528that are up to 20 days old.
f566d765
LC
1529@end itemize
1530
b7884ca3
NK
1531@item --delete-generations[=@var{pattern}]
1532@itemx -d [@var{pattern}]
d7ddb257
LC
1533When @var{pattern} is omitted, delete all generations except the current
1534one.
b7884ca3
NK
1535
1536This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
1537When @var{pattern} is specified, delete the matching generations. When
1538@var{pattern} specifies a duration, generations @emph{older} than the
1539specified duration match. For instance, @code{--delete-generations=1m}
1540deletes generations that are more than one month old.
1541
391bdd8f
LC
1542If the current generation matches, it is @emph{not} deleted. Also, the
1543zeroth generation is never deleted.
b7884ca3 1544
1bb9900a
LC
1545Note that deleting generations prevents roll-back to them.
1546Consequently, this command must be used with care.
1547
733b4130 1548@end table
eeaf4427 1549
70ee5642
LC
1550Finally, since @command{guix package} may actually start build
1551processes, it supports all the common build options that @command{guix
1552build} supports (@pxref{Invoking guix build, common build options}).
1553
c4202d60
LC
1554@node Substitutes
1555@section Substitutes
1556
1557@cindex substitutes
1558@cindex pre-built binaries
1559Guix supports transparent source/binary deployment, which means that it
1560can either build things locally, or download pre-built items from a
1561server. We call these pre-built items @dfn{substitutes}---they are
1562substitutes for local build results. In many cases, downloading a
1563substitute is much faster than building things locally.
1564
1565Substitutes can be anything resulting from a derivation build
1566(@pxref{Derivations}). Of course, in the common case, they are
1567pre-built package binaries, but source tarballs, for instance, which
1568also result from derivation builds, can be available as substitutes.
1569
1570The @code{hydra.gnu.org} server is a front-end to a build farm that
1571builds packages from the GNU distribution continuously for some
9176607e 1572architectures, and makes them available as substitutes. This is the
f8a8e0fe
LC
1573default source of substitutes; it can be overridden by passing the
1574@option{--substitute-urls} option either to @command{guix-daemon}
1575(@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1576or to client tools such as @command{guix package}
1577(@pxref{client-substitute-urls,, client @option{--substitute-urls}
1578option}).
c4202d60
LC
1579
1580@cindex security
1581@cindex digital signatures
1582To allow Guix to download substitutes from @code{hydra.gnu.org}, you
1583must add its public key to the access control list (ACL) of archive
1584imports, using the @command{guix archive} command (@pxref{Invoking guix
1585archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1586be compromised and to serve genuine substitutes.
1587
1588This public key is installed along with Guix, in
1589@code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1590the installation prefix of Guix. If you installed Guix from source,
1591make sure you checked the GPG signature of
1592@file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1593Then, you can run something like this:
1594
1595@example
1596# guix archive --authorize < hydra.gnu.org.pub
1597@end example
1598
1599Once this is in place, the output of a command like @code{guix build}
1600should change from something like:
1601
1602@example
1603$ guix build emacs --dry-run
1604The following derivations would be built:
1605 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1606 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1607 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1608 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1609@dots{}
1610@end example
1611
1612@noindent
1613to something like:
1614
1615@example
1616$ guix build emacs --dry-run
1617The following files would be downloaded:
1618 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1619 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1620 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1621 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1622@dots{}
1623@end example
1624
1625@noindent
1626This indicates that substitutes from @code{hydra.gnu.org} are usable and
1627will be downloaded, when possible, for future builds.
1628
1629Guix ignores substitutes that are not signed, or that are not signed by
ef27aa9c 1630one of the keys listed in the ACL. It also detects and raises an error
c4202d60
LC
1631when attempting to use a substitute that has been tampered with.
1632
1633The substitute mechanism can be disabled globally by running
1634@code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1635guix-daemon}). It can also be disabled temporarily by passing the
1636@code{--no-substitutes} option to @command{guix package}, @command{guix
1637build}, and other command-line tools.
1638
1639
1640Today, each individual's control over their own computing is at the
1641mercy of institutions, corporations, and groups with enough power and
1642determination to subvert the computing infrastructure and exploit its
1643weaknesses. While using @code{hydra.gnu.org} substitutes can be
1644convenient, we encourage users to also build on their own, or even run
1645their own build farm, such that @code{hydra.gnu.org} is less of an
8ce229fc
LC
1646interesting target. One way to help is by publishing the software you
1647build using @command{guix publish} so that others have one more choice
1648of server to download substitutes from (@pxref{Invoking guix publish}).
c4202d60
LC
1649
1650Guix has the foundations to maximize build reproducibility
1651(@pxref{Features}). In most cases, independent builds of a given
1652package or derivation should yield bit-identical results. Thus, through
1653a diverse set of independent package builds, we can strengthen the
d23c20f1
LC
1654integrity of our systems. The @command{guix challenge} command aims to
1655help users assess substitute servers, and to assist developers in
1656finding out about non-deterministic package builds (@pxref{Invoking guix
a8d65643
LC
1657challenge}). Similarly, the @option{--check} option of @command{guix
1658build} allows users to check whether previously-installed substitutes
1659are genuine by rebuilding them locally (@pxref{build-check,
1660@command{guix build --check}}).
c4202d60
LC
1661
1662In the future, we want Guix to have support to publish and retrieve
1663binaries to/from other users, in a peer-to-peer fashion. If you would
1664like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1665
1666
6e721c4d
LC
1667@node Packages with Multiple Outputs
1668@section Packages with Multiple Outputs
1669
1670@cindex multiple-output packages
1671@cindex package outputs
1672
1673Often, packages defined in Guix have a single @dfn{output}---i.e., the
1674source package leads exactly one directory in the store. When running
1675@command{guix package -i glibc}, one installs the default output of the
1676GNU libc package; the default output is called @code{out}, but its name
1677can be omitted as shown in this command. In this particular case, the
1678default output of @code{glibc} contains all the C header files, shared
1679libraries, static libraries, Info documentation, and other supporting
1680files.
1681
1682Sometimes it is more appropriate to separate the various types of files
1683produced from a single source package into separate outputs. For
1684instance, the GLib C library (used by GTK+ and related packages)
1685installs more than 20 MiB of reference documentation as HTML pages.
1686To save space for users who do not need it, the documentation goes to a
1687separate output, called @code{doc}. To install the main GLib output,
1688which contains everything but the documentation, one would run:
1689
1690@example
1691guix package -i glib
1692@end example
1693
1694The command to install its documentation is:
1695
1696@example
1697guix package -i glib:doc
1698@end example
1699
1700Some packages install programs with different ``dependency footprints''.
1701For instance, the WordNet package install both command-line tools and
1702graphical user interfaces (GUIs). The former depend solely on the C
1703library, whereas the latter depend on Tcl/Tk and the underlying X
1704libraries. In this case, we leave the command-line tools in the default
1705output, whereas the GUIs are in a separate output. This allows users
fcc58db6
LC
1706who do not need the GUIs to save space. The @command{guix size} command
1707can help find out about such situations (@pxref{Invoking guix size}).
88856916 1708@command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
6e721c4d
LC
1709
1710There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
1711Other conventional output names include @code{lib} for libraries and
1712possibly header files, @code{bin} for stand-alone programs, and
1713@code{debug} for debugging information (@pxref{Installing Debugging
1714Files}). The outputs of a packages are listed in the third column of
1715the output of @command{guix package --list-available} (@pxref{Invoking
1716guix package}).
6e721c4d 1717
eeaf4427 1718
e49951eb
MW
1719@node Invoking guix gc
1720@section Invoking @command{guix gc}
fe8ff028
LC
1721
1722@cindex garbage collector
1723Packages that are installed but not used may be @dfn{garbage-collected}.
e49951eb 1724The @command{guix gc} command allows users to explicitly run the garbage
c22eb992
LC
1725collector to reclaim space from the @file{/gnu/store} directory. It is
1726the @emph{only} way to remove files from @file{/gnu/store}---removing
1727files or directories manually may break it beyond repair!
fe8ff028
LC
1728
1729The garbage collector has a set of known @dfn{roots}: any file under
834129e0 1730@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
1731cannot be deleted; any other file is considered @dfn{dead} and may be
1732deleted. The set of garbage collector roots includes default user
e49951eb
MW
1733profiles, and may be augmented with @command{guix build --root}, for
1734example (@pxref{Invoking guix build}).
fe8ff028 1735
1bb9900a
LC
1736Prior to running @code{guix gc --collect-garbage} to make space, it is
1737often useful to remove old generations from user profiles; that way, old
1738package builds referenced by those generations can be reclaimed. This
1739is achieved by running @code{guix package --delete-generations}
1740(@pxref{Invoking guix package}).
1741
e49951eb 1742The @command{guix gc} command has three modes of operation: it can be
fe8ff028 1743used to garbage-collect any dead files (the default), to delete specific
7770aafc
LC
1744files (the @code{--delete} option), to print garbage-collector
1745information, or for more advanced queries. The garbage collection
1746options are as follows:
fe8ff028
LC
1747
1748@table @code
1749@item --collect-garbage[=@var{min}]
1750@itemx -C [@var{min}]
834129e0 1751Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
1752sub-directories. This is the default operation when no option is
1753specified.
1754
1755When @var{min} is given, stop once @var{min} bytes have been collected.
1756@var{min} may be a number of bytes, or it may include a unit as a
4a44d7bb
LC
1757suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
1758(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
fe8ff028
LC
1759
1760When @var{min} is omitted, collect all the garbage.
1761
1762@item --delete
1763@itemx -d
1764Attempt to delete all the store files and directories specified as
1765arguments. This fails if some of the files are not in the store, or if
1766they are still live.
1767
30d9aa54
LC
1768@item --list-failures
1769List store items corresponding to cached build failures.
1770
1771This prints nothing unless the daemon was started with
1772@option{--cache-failures} (@pxref{Invoking guix-daemon,
1773@option{--cache-failures}}).
1774
1775@item --clear-failures
1776Remove the specified store items from the failed-build cache.
1777
1778Again, this option only makes sense when the daemon is started with
1779@option{--cache-failures}. Otherwise, it does nothing.
1780
fe8ff028
LC
1781@item --list-dead
1782Show the list of dead files and directories still present in the
1783store---i.e., files and directories no longer reachable from any root.
1784
1785@item --list-live
1786Show the list of live store files and directories.
ba8b732d
LC
1787
1788@end table
1789
1790In addition, the references among existing store files can be queried:
1791
1792@table @code
1793
1794@item --references
1795@itemx --referrers
1796List the references (respectively, the referrers) of store files given
1797as arguments.
1798
8e59fdd5
LC
1799@item --requisites
1800@itemx -R
fcc58db6 1801@cindex closure
8e59fdd5
LC
1802List the requisites of the store files passed as arguments. Requisites
1803include the store files themselves, their references, and the references
1804of these, recursively. In other words, the returned list is the
1805@dfn{transitive closure} of the store files.
1806
fcc58db6 1807@xref{Invoking guix size}, for a tool to profile the size of an
88856916
LC
1808element's closure. @xref{Invoking guix graph}, for a tool to visualize
1809the graph of references.
fcc58db6 1810
fe8ff028
LC
1811@end table
1812
7770aafc
LC
1813Lastly, the following options allow you to check the integrity of the
1814store and to control disk usage.
1815
1816@table @option
1817
1818@item --verify[=@var{options}]
1819@cindex integrity, of the store
1820@cindex integrity checking
1821Verify the integrity of the store.
1822
1823By default, make sure that all the store items marked as valid in the
1824daemon's database actually exist in @file{/gnu/store}.
1825
1826When provided, @var{options} must a comma-separated list containing one
1827or more of @code{contents} and @code{repair}.
1828
1829When passing @option{--verify=contents}, the daemon will compute the
1830content hash of each store item and compare it against its hash in the
1831database. Hash mismatches are reported as data corruptions. Because it
1832traverses @emph{all the files in the store}, this command can take a
1833long time, especially on systems with a slow disk drive.
1834
1835@cindex repairing the store
1836Using @option{--verify=repair} or @option{--verify=contents,repair}
1837causes the daemon to try to repair corrupt store items by fetching
1838substitutes for them (@pxref{Substitutes}). Because repairing is not
1839atomic, and thus potentially dangerous, it is available only to the
1840system administrator.
1841
1842@item --optimize
1843@cindex deduplication
1844Optimize the store by hard-linking identical files---this is
1845@dfn{deduplication}.
1846
1847The daemon performs deduplication after each successful build or archive
1848import, unless it was started with @code{--disable-deduplication}
1849(@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
1850this option is primarily useful when the daemon was running with
1851@code{--disable-deduplication}.
1852
1853@end table
eeaf4427 1854
f651b477
LC
1855@node Invoking guix pull
1856@section Invoking @command{guix pull}
1857
1858Packages are installed or upgraded to the latest version available in
1859the distribution currently available on your local machine. To update
1860that distribution, along with the Guix tools, you must run @command{guix
1861pull}: the command downloads the latest Guix source code and package
1862descriptions, and deploys it.
1863
1864On completion, @command{guix package} will use packages and package
1865versions from this just-retrieved copy of Guix. Not only that, but all
1866the Guix commands and Scheme modules will also be taken from that latest
1867version. New @command{guix} sub-commands added by the update also
ef54b61d
AV
1868become available@footnote{Under the hood, @command{guix pull} updates
1869the @file{~/.config/guix/latest} symbolic link to point to the latest
1870Guix, and the @command{guix} command loads code from there.}.
f651b477
LC
1871
1872The @command{guix pull} command is usually invoked with no arguments,
1873but it supports the following options:
1874
1875@table @code
1876@item --verbose
1877Produce verbose output, writing build logs to the standard error output.
1878
ab5d72ad
LC
1879@item --url=@var{url}
1880Download the source tarball of Guix from @var{url}.
1881
1882By default, the tarball is taken from its canonical address at
1883@code{gnu.org}, for the stable branch of Guix.
1884
f651b477
LC
1885@item --bootstrap
1886Use the bootstrap Guile to build the latest Guix. This option is only
1887useful to Guix developers.
1888@end table
1889
760c60d6
LC
1890
1891@node Invoking guix archive
1892@section Invoking @command{guix archive}
1893
1894The @command{guix archive} command allows users to @dfn{export} files
1895from the store into a single archive, and to later @dfn{import} them.
1896In particular, it allows store files to be transferred from one machine
1897to another machine's store. For example, to transfer the @code{emacs}
1898package to a machine connected over SSH, one would run:
1899
1900@example
56607088 1901guix archive --export -r emacs | ssh the-machine guix archive --import
760c60d6
LC
1902@end example
1903
87236aed 1904@noindent
56607088
LC
1905Similarly, a complete user profile may be transferred from one machine
1906to another like this:
1907
1908@example
1909guix archive --export -r $(readlink -f ~/.guix-profile) | \
1910 ssh the-machine guix-archive --import
1911@end example
1912
1913@noindent
1914However, note that, in both examples, all of @code{emacs} and the
1915profile as well as all of their dependencies are transferred (due to
1916@code{-r}), regardless of what is already available in the target
1917machine's store. The @code{--missing} option can help figure out which
1918items are missing from the target's store.
87236aed 1919
760c60d6 1920Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
0dbd88db
LC
1921comparable in spirit to `tar', but with a few noteworthy differences
1922that make it more appropriate for our purposes. First, rather than
1923recording all Unix meta-data for each file, the Nar format only mentions
1924the file type (regular, directory, or symbolic link); Unix permissions
1925and owner/group are dismissed. Second, the order in which directory
1926entries are stored always follows the order of file names according to
1927the C locale collation order. This makes archive production fully
1928deterministic.
1929
1930When exporting, the daemon digitally signs the contents of the archive,
1931and that digital signature is appended. When importing, the daemon
1932verifies the signature and rejects the import in case of an invalid
1933signature or if the signing key is not authorized.
760c60d6
LC
1934@c FIXME: Add xref to daemon doc about signatures.
1935
1936The main options are:
1937
1938@table @code
1939@item --export
1940Export the specified store files or packages (see below.) Write the
1941resulting archive to the standard output.
1942
56607088
LC
1943Dependencies are @emph{not} included in the output, unless
1944@code{--recursive} is passed.
1945
1946@item -r
1947@itemx --recursive
1948When combined with @code{--export}, this instructs @command{guix
1949archive} to include dependencies of the given items in the archive.
1950Thus, the resulting archive is self-contained: it contains the closure
1951of the exported store items.
1952
760c60d6
LC
1953@item --import
1954Read an archive from the standard input, and import the files listed
1955therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
1956signature, or if it is signed by a public key not among the authorized
1957keys (see @code{--authorize} below.)
554f26ec 1958
87236aed
LC
1959@item --missing
1960Read a list of store file names from the standard input, one per line,
1961and write on the standard output the subset of these files missing from
1962the store.
1963
554f26ec 1964@item --generate-key[=@var{parameters}]
f82cc5fd 1965@cindex signing, archives
554f26ec
LC
1966Generate a new key pair for the daemons. This is a prerequisite before
1967archives can be exported with @code{--export}. Note that this operation
1968usually takes time, because it needs to gather enough entropy to
1969generate the key pair.
1970
1971The generated key pair is typically stored under @file{/etc/guix}, in
1972@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
867d8473
LC
1973key, which must be kept secret.) When @var{parameters} is omitted,
1974an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
1975versions before 1.6.0, it is a 4096-bit RSA key.
1976Alternately, @var{parameters} can specify
554f26ec
LC
1977@code{genkey} parameters suitable for Libgcrypt (@pxref{General
1978public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
1979Libgcrypt Reference Manual}).
f82cc5fd
LC
1980
1981@item --authorize
1982@cindex authorizing, archives
1983Authorize imports signed by the public key passed on standard input.
1984The public key must be in ``s-expression advanced format''---i.e., the
1985same format as the @file{signing-key.pub} file.
1986
1987The list of authorized keys is kept in the human-editable file
1988@file{/etc/guix/acl}. The file contains
1989@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
1990s-expressions''} and is structured as an access-control list in the
1991@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
1992(SPKI)}.
c6f8e9dd
LC
1993
1994@item --extract=@var{directory}
1995@itemx -x @var{directory}
1996Read a single-item archive as served by substitute servers
1997(@pxref{Substitutes}) and extract it to @var{directory}. This is a
1998low-level operation needed in only very narrow use cases; see below.
1999
2000For example, the following command extracts the substitute for Emacs
2001served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2002
2003@example
2004$ wget -O - \
2005 http://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
2006 | bunzip2 | guix archive -x /tmp/emacs
2007@end example
2008
2009Single-item archives are different from multiple-item archives produced
2010by @command{guix archive --export}; they contain a single store item,
2011and they do @emph{not} embed a signature. Thus this operation does
2012@emph{no} signature verification and its output should be considered
2013unsafe.
2014
2015The primary purpose of this operation is to facilitate inspection of
2016archive contents coming from possibly untrusted substitute servers.
2017
760c60d6
LC
2018@end table
2019
2020To export store files as an archive to the standard output, run:
2021
2022@example
2023guix archive --export @var{options} @var{specifications}...
2024@end example
2025
2026@var{specifications} may be either store file names or package
2027specifications, as for @command{guix package} (@pxref{Invoking guix
2028package}). For instance, the following command creates an archive
2029containing the @code{gui} output of the @code{git} package and the main
2030output of @code{emacs}:
2031
2032@example
834129e0 2033guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
760c60d6
LC
2034@end example
2035
2036If the specified packages are not built yet, @command{guix archive}
2037automatically builds them. The build process may be controlled with the
2038same options that can be passed to the @command{guix build} command
70ee5642 2039(@pxref{Invoking guix build, common build options}).
760c60d6 2040
c554de89
AK
2041@c *********************************************************************
2042@include emacs.texi
760c60d6 2043
568717fd
LC
2044@c *********************************************************************
2045@node Programming Interface
2046@chapter Programming Interface
2047
3dc1970d
LC
2048GNU Guix provides several Scheme programming interfaces (APIs) to
2049define, build, and query packages. The first interface allows users to
2050write high-level package definitions. These definitions refer to
2051familiar packaging concepts, such as the name and version of a package,
2052its build system, and its dependencies. These definitions can then be
2053turned into concrete build actions.
2054
ba55b1cb 2055Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 2056standard setup, the daemon has write access to the store---the
834129e0 2057@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
2058setup also has the daemon perform builds in chroots, under a specific
2059build users, to minimize interference with the rest of the system.
2060
2061@cindex derivation
2062Lower-level APIs are available to interact with the daemon and the
2063store. To instruct the daemon to perform a build action, users actually
2064provide it with a @dfn{derivation}. A derivation is a low-level
2065representation of the build actions to be taken, and the environment in
2066which they should occur---derivations are to package definitions what
49ad317a
LC
2067assembly is to C programs. The term ``derivation'' comes from the fact
2068that build results @emph{derive} from them.
3dc1970d
LC
2069
2070This chapter describes all these APIs in turn, starting from high-level
2071package definitions.
2072
568717fd 2073@menu
b860f382 2074* Defining Packages:: Defining new packages.
7458bd0a 2075* Build Systems:: Specifying how packages are built.
b860f382
LC
2076* The Store:: Manipulating the package store.
2077* Derivations:: Low-level interface to package derivations.
2078* The Store Monad:: Purely functional interface to the store.
21b679f6 2079* G-Expressions:: Manipulating build expressions.
568717fd
LC
2080@end menu
2081
2082@node Defining Packages
2083@section Defining Packages
2084
3dc1970d
LC
2085The high-level interface to package definitions is implemented in the
2086@code{(guix packages)} and @code{(guix build-system)} modules. As an
2087example, the package definition, or @dfn{recipe}, for the GNU Hello
2088package looks like this:
2089
2090@example
e7f34eb0
LC
2091(define-module (gnu packages hello)
2092 #:use-module (guix packages)
2093 #:use-module (guix download)
2094 #:use-module (guix build-system gnu)
a6dcdcac
SB
2095 #:use-module (guix licenses)
2096 #:use-module (gnu packages gawk))
b22a12fd 2097
79f5dd59 2098(define-public hello
3dc1970d
LC
2099 (package
2100 (name "hello")
17d8e33f 2101 (version "2.10")
3dc1970d 2102 (source (origin
17d8e33f
ML
2103 (method url-fetch)
2104 (uri (string-append "mirror://gnu/hello/hello-" version
2105 ".tar.gz"))
2106 (sha256
2107 (base32
2108 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
3dc1970d 2109 (build-system gnu-build-system)
7458bd0a 2110 (arguments `(#:configure-flags '("--enable-silent-rules")))
3dc1970d 2111 (inputs `(("gawk" ,gawk)))
7458bd0a
LC
2112 (synopsis "Hello, GNU world: An example GNU package")
2113 (description "Guess what GNU Hello prints!")
3dc1970d 2114 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 2115 (license gpl3+)))
3dc1970d
LC
2116@end example
2117
2118@noindent
2119Without being a Scheme expert, the reader may have guessed the meaning
e7f34eb0 2120of the various fields here. This expression binds variable @code{hello}
3dc1970d
LC
2121to a @code{<package>} object, which is essentially a record
2122(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2123This package object can be inspected using procedures found in the
2124@code{(guix packages)} module; for instance, @code{(package-name hello)}
2125returns---surprise!---@code{"hello"}.
2126
2f7d2d91
LC
2127With luck, you may be able to import part or all of the definition of
2128the package you are interested in from another repository, using the
2129@code{guix import} command (@pxref{Invoking guix import}).
2130
e7f34eb0
LC
2131In the example above, @var{hello} is defined into a module of its own,
2132@code{(gnu packages hello)}. Technically, this is not strictly
2133necessary, but it is convenient to do so: all the packages defined in
2134modules under @code{(gnu packages @dots{})} are automatically known to
2135the command-line tools (@pxref{Package Modules}).
2136
3dc1970d
LC
2137There are a few points worth noting in the above package definition:
2138
2139@itemize
2140@item
a2bf4907
LC
2141The @code{source} field of the package is an @code{<origin>} object
2142(@pxref{origin Reference}, for the complete reference).
3dc1970d
LC
2143Here, the @code{url-fetch} method from @code{(guix download)} is used,
2144meaning that the source is a file to be downloaded over FTP or HTTP.
2145
2146The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2147the GNU mirrors defined in @code{(guix download)}.
2148
2149The @code{sha256} field specifies the expected SHA256 hash of the file
2150being downloaded. It is mandatory, and allows Guix to check the
2151integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 2152base32 representation of the hash. You can obtain this information with
210cc920
LC
2153@code{guix download} (@pxref{Invoking guix download}) and @code{guix
2154hash} (@pxref{Invoking guix hash}).
3dc1970d 2155
f9cc8971
LC
2156@cindex patches
2157When needed, the @code{origin} form can also have a @code{patches} field
2158listing patches to be applied, and a @code{snippet} field giving a
2159Scheme expression to modify the source code.
2160
3dc1970d
LC
2161@item
2162@cindex GNU Build System
7458bd0a
LC
2163The @code{build-system} field specifies the procedure to build the
2164package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2165represents the familiar GNU Build System, where packages may be
2166configured, built, and installed with the usual @code{./configure &&
2167make && make check && make install} command sequence.
2168
2169@item
2170The @code{arguments} field specifies options for the build system
2171(@pxref{Build Systems}). Here it is interpreted by
2172@var{gnu-build-system} as a request run @file{configure} with the
2173@code{--enable-silent-rules} flag.
3dc1970d
LC
2174
2175@item
2176The @code{inputs} field specifies inputs to the build process---i.e.,
2177build-time or run-time dependencies of the package. Here, we define an
2178input called @code{"gawk"} whose value is that of the @var{gawk}
2179variable; @var{gawk} is itself bound to a @code{<package>} object.
2180
2181Note that GCC, Coreutils, Bash, and other essential tools do not need to
2182be specified as inputs here. Instead, @var{gnu-build-system} takes care
7458bd0a 2183of ensuring that they are present (@pxref{Build Systems}).
3dc1970d
LC
2184
2185However, any other dependencies need to be specified in the
2186@code{inputs} field. Any dependency not specified here will simply be
2187unavailable to the build process, possibly leading to a build failure.
2188@end itemize
2189
87eafdbd
TUBK
2190@xref{package Reference}, for a full description of possible fields.
2191
2f7d2d91 2192Once a package definition is in place, the
e49951eb 2193package may actually be built using the @code{guix build} command-line
39bee8a2
LC
2194tool (@pxref{Invoking guix build}). You can easily jump back to the
2195package definition using the @command{guix edit} command
2196(@pxref{Invoking guix edit}).
2197@xref{Packaging Guidelines}, for
b4f5e0e8
CR
2198more information on how to test package definitions, and
2199@ref{Invoking guix lint}, for information on how to check a definition
2200for style conformance.
2201
7458bd0a
LC
2202Eventually, updating the package definition to a new upstream version
2203can be partly automated by the @command{guix refresh} command
2204(@pxref{Invoking guix refresh}).
3dc1970d
LC
2205
2206Behind the scenes, a derivation corresponding to the @code{<package>}
2207object is first computed by the @code{package-derivation} procedure.
834129e0 2208That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 2209The build actions it prescribes may then be realized by using the
3dc1970d
LC
2210@code{build-derivations} procedure (@pxref{The Store}).
2211
2212@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
2213Return the @code{<derivation>} object of @var{package} for @var{system}
2214(@pxref{Derivations}).
3dc1970d
LC
2215
2216@var{package} must be a valid @code{<package>} object, and @var{system}
2217must be a string denoting the target system type---e.g.,
2218@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2219must be a connection to the daemon, which operates on the store
2220(@pxref{The Store}).
2221@end deffn
568717fd 2222
9c1edabd
LC
2223@noindent
2224@cindex cross-compilation
2225Similarly, it is possible to compute a derivation that cross-builds a
2226package for some other system:
2227
2228@deffn {Scheme Procedure} package-cross-derivation @var{store} @
2229 @var{package} @var{target} [@var{system}]
59688fc4
LC
2230Return the @code{<derivation>} object of @var{package} cross-built from
2231@var{system} to @var{target}.
9c1edabd
LC
2232
2233@var{target} must be a valid GNU triplet denoting the target hardware
2234and operating system, such as @code{"mips64el-linux-gnu"}
2235(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2236Configure and Build System}).
2237@end deffn
2238
87eafdbd
TUBK
2239@menu
2240* package Reference :: The package data type.
2241* origin Reference:: The origin data type.
2242@end menu
2243
2244
2245@node package Reference
2246@subsection @code{package} Reference
2247
2248This section summarizes all the options available in @code{package}
2249declarations (@pxref{Defining Packages}).
2250
2251@deftp {Data Type} package
2252This is the data type representing a package recipe.
2253
2254@table @asis
2255@item @code{name}
2256The name of the package, as a string.
2257
2258@item @code{version}
2259The version of the package, as a string.
2260
2261@item @code{source}
2262An origin object telling how the source code for the package should be
2263acquired (@pxref{origin Reference}).
2264
2265@item @code{build-system}
2266The build system that should be used to build the package (@pxref{Build
2267Systems}).
2268
2269@item @code{arguments} (default: @code{'()})
2270The arguments that should be passed to the build system. This is a
2271list, typically containing sequential keyword-value pairs.
2272
2273@item @code{inputs} (default: @code{'()})
70650c68
LC
2274@itemx @code{native-inputs} (default: @code{'()})
2275@itemx @code{propagated-inputs} (default: @code{'()})
2276@cindex inputs, of packages
2277These fields list dependencies of the package. Each one is a list of
2278tuples, where each tuple has a label for the input (a string) as its
2279first element, a package, origin, or derivation as its second element,
2280and optionally the name of the output thereof that should be used, which
2281defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
2282more on package outputs). For example, the list below specifies 3
2283inputs:
87eafdbd 2284
70650c68
LC
2285@example
2286`(("libffi" ,libffi)
2287 ("libunistring" ,libunistring)
2288 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
2289@end example
2290
2291@cindex cross compilation, package dependencies
2292The distinction between @code{native-inputs} and @code{inputs} is
2293necessary when considering cross-compilation. When cross-compiling,
2294dependencies listed in @code{inputs} are built for the @emph{target}
2295architecture; conversely, dependencies listed in @code{native-inputs}
2296are built for the architecture of the @emph{build} machine.
2297
2298@code{native-inputs} is typically where you would list tools needed at
2299build time but not at run time, such as Autoconf, Automake, pkg-config,
2300Gettext, or Bison. @command{guix lint} can report likely mistakes in
2301this area (@pxref{Invoking guix lint}).
2302
2303@anchor{package-propagated-inputs}
2304Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
2305specified packages will be force-installed alongside the package they
2306belong to (@pxref{package-cmd-propagated-inputs, @command{guix
2307package}}, for information on how @command{guix package} deals with
2308propagated inputs.)
21461f27 2309
e0508b6b
LC
2310For example this is necessary when a C/C++ library needs headers of
2311another library to compile, or when a pkg-config file refers to another
2312one @i{via} its @code{Requires} field.
2313
2314Another example where @code{propagated-inputs} is useful is for
2315languages that lack a facility to record the run-time search path akin
2316to ELF's @code{RUNPATH}; this includes Guile, Python, Perl, GHC, and
2317more. To ensure that libraries written in those languages can find
2318library code they depend on at run time, run-time dependencies must be
2319listed in @code{propagated-inputs} rather than @code{inputs}.
87eafdbd 2320
87eafdbd
TUBK
2321@item @code{self-native-input?} (default: @code{#f})
2322This is a Boolean field telling whether the package should use itself as
2323a native input when cross-compiling.
2324
2325@item @code{outputs} (default: @code{'("out")})
2326The list of output names of the package. @xref{Packages with Multiple
2327Outputs}, for typical uses of additional outputs.
2328
2329@item @code{native-search-paths} (default: @code{'()})
2330@itemx @code{search-paths} (default: @code{'()})
2331A list of @code{search-path-specification} objects describing
2332search-path environment variables honored by the package.
2333
2334@item @code{replacement} (default: @code{#f})
2335This must either @code{#f} or a package object that will be used as a
2336@dfn{replacement} for this package. @xref{Security Updates, grafts},
2337for details.
2338
2339@item @code{synopsis}
2340A one-line description of the package.
2341
2342@item @code{description}
2343A more elaborate description of the package.
2344
2345@item @code{license}
2346The license of the package; a value from @code{(guix licenses)}.
2347
2348@item @code{home-page}
2349The URL to the home-page of the package, as a string.
2350
2351@item @code{supported-systems} (default: @var{%supported-systems})
2352The list of systems supported by the package, as strings of the form
2353@code{architecture-kernel}, for example @code{"x86_64-linux"}.
2354
2355@item @code{maintainers} (default: @code{'()})
2356The list of maintainers of the package, as @code{maintainer} objects.
2357
2358@item @code{location} (default: source location of the @code{package} form)
2359The source location of the package. It's useful to override this when
2360inheriting from another package, in which case this field is not
2361automatically corrected.
2362@end table
2363@end deftp
2364
2365
2366@node origin Reference
2367@subsection @code{origin} Reference
2368
2369This section summarizes all the options available in @code{origin}
2370declarations (@pxref{Defining Packages}).
2371
2372@deftp {Data Type} origin
2373This is the data type representing a source code origin.
2374
2375@table @asis
2376@item @code{uri}
2377An object containing the URI of the source. The object type depends on
2378the @code{method} (see below). For example, when using the
2379@var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2380values are: a URL represented as a string, or a list thereof.
2381
2382@item @code{method}
2383A procedure that will handle the URI.
2384
2385Examples include:
2386
2387@table @asis
2388@item @var{url-fetch} from @code{(guix download)}
2389download a file the HTTP, HTTPS, or FTP URL specified in the
2390@code{uri} field;
2391
2392@item @var{git-fetch} from @code{(guix git-download)}
2393clone the Git version control repository, and check out the revision
2394specified in the @code{uri} field as a @code{git-reference} object; a
2395@code{git-reference} looks like this:
2396
2397@example
2398(git-reference
2399 (url "git://git.debian.org/git/pkg-shadow/shadow")
2400 (commit "v4.1.5.1"))
2401@end example
2402@end table
2403
2404@item @code{sha256}
2405A bytevector containing the SHA-256 hash of the source. Typically the
2406@code{base32} form is used here to generate the bytevector from a
2407base-32 string.
2408
2409@item @code{file-name} (default: @code{#f})
2410The file name under which the source code should be saved. When this is
2411@code{#f}, a sensible default value will be used in most cases. In case
2412the source is fetched from a URL, the file name from the URL will be
2413used. For version control checkouts, it's recommended to provide the
2414file name explicitly because the default is not very descriptive.
2415
2416@item @code{patches} (default: @code{'()})
2417A list of file names containing patches to be applied to the source.
2418
2419@item @code{snippet} (default: @code{#f})
2420A quoted piece of code that will be run in the source directory to make
2421any modifications, which is sometimes more convenient than a patch.
2422
2423@item @code{patch-flags} (default: @code{'("-p1")})
2424A list of command-line flags that should be passed to the @code{patch}
2425command.
2426
2427@item @code{patch-inputs} (default: @code{#f})
2428Input packages or derivations to the patching process. When this is
2429@code{#f}, the usual set of inputs necessary for patching are provided,
2430such as GNU@tie{}Patch.
2431
2432@item @code{modules} (default: @code{'()})
2433A list of Guile modules that should be loaded during the patching
2434process and while running the code in the @code{snippet} field.
2435
2436@item @code{imported-modules} (default: @code{'()})
2437The list of Guile modules to import in the patch derivation, for use by
2438the @code{snippet}.
2439
2440@item @code{patch-guile} (default: @code{#f})
2441The Guile package that should be used in the patching process. When
2442this is @code{#f}, a sensible default is used.
2443@end table
2444@end deftp
2445
9c1edabd 2446
7458bd0a
LC
2447@node Build Systems
2448@section Build Systems
2449
2450@cindex build system
2451Each package definition specifies a @dfn{build system} and arguments for
2452that build system (@pxref{Defining Packages}). This @code{build-system}
2453field represents the build procedure of the package, as well implicit
2454dependencies of that build procedure.
2455
2456Build systems are @code{<build-system>} objects. The interface to
2457create and manipulate them is provided by the @code{(guix build-system)}
2458module, and actual build systems are exported by specific modules.
2459
f5fd4fd2 2460@cindex bag (low-level package representation)
0d5a559f
LC
2461Under the hood, build systems first compile package objects to
2462@dfn{bags}. A @dfn{bag} is like a package, but with less
2463ornamentation---in other words, a bag is a lower-level representation of
2464a package, which includes all the inputs of that package, including some
2465that were implicitly added by the build system. This intermediate
2466representation is then compiled to a derivation (@pxref{Derivations}).
2467
7458bd0a
LC
2468Build systems accept an optional list of @dfn{arguments}. In package
2469definitions, these are passed @i{via} the @code{arguments} field
2470(@pxref{Defining Packages}). They are typically keyword arguments
2471(@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
2472Guile Reference Manual}). The value of these arguments is usually
2473evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
2474by the daemon (@pxref{Derivations}).
2475
2476The main build system is @var{gnu-build-system}, which implements the
2477standard build procedure for GNU packages and many other packages. It
2478is provided by the @code{(guix build-system gnu)} module.
2479
2480@defvr {Scheme Variable} gnu-build-system
2481@var{gnu-build-system} represents the GNU Build System, and variants
2482thereof (@pxref{Configuration, configuration and makefile conventions,,
2483standards, GNU Coding Standards}).
2484
2485@cindex build phases
2486In a nutshell, packages using it configured, built, and installed with
2487the usual @code{./configure && make && make check && make install}
2488command sequence. In practice, a few additional steps are often needed.
2489All these steps are split up in separate @dfn{phases},
2490notably@footnote{Please see the @code{(guix build gnu-build-system)}
2491modules for more details about the build phases.}:
2492
2493@table @code
2494@item unpack
2495Unpack the source tarball, and change the current directory to the
2496extracted source tree. If the source is actually a directory, copy it
2497to the build tree, and enter that directory.
2498
2499@item patch-source-shebangs
2500Patch shebangs encountered in source files so they refer to the right
2501store file names. For instance, this changes @code{#!/bin/sh} to
2502@code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
2503
2504@item configure
2505Run the @file{configure} script with a number of default options, such
2506as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
2507by the @code{#:configure-flags} argument.
2508
2509@item build
2510Run @code{make} with the list of flags specified with
2511@code{#:make-flags}. If the @code{#:parallel-builds?} argument is true
2512(the default), build with @code{make -j}.
2513
2514@item check
2515Run @code{make check}, or some other target specified with
2516@code{#:test-target}, unless @code{#:tests? #f} is passed. If the
2517@code{#:parallel-tests?} argument is true (the default), run @code{make
2518check -j}.
2519
2520@item install
2521Run @code{make install} with the flags listed in @code{#:make-flags}.
2522
2523@item patch-shebangs
2524Patch shebangs on the installed executable files.
2525
2526@item strip
2527Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
2528is false), copying them to the @code{debug} output when available
2529(@pxref{Installing Debugging Files}).
2530@end table
2531
2532@vindex %standard-phases
2533The build-side module @code{(guix build gnu-build-system)} defines
2534@var{%standard-phases} as the default list of build phases.
2535@var{%standard-phases} is a list of symbol/procedure pairs, where the
2536procedure implements the actual phase.
2537
2538The list of phases used for a particular package can be changed with the
2539@code{#:phases} parameter. For instance, passing:
2540
2541@example
2542#:phases (alist-delete 'configure %standard-phases)
2543@end example
2544
9bf404e9 2545means that all the phases described above will be used, except the
7458bd0a
LC
2546@code{configure} phase.
2547
2548In addition, this build system ensures that the ``standard'' environment
2549for GNU packages is available. This includes tools such as GCC, libc,
2550Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
2551build-system gnu)} module for a complete list.) We call these the
2552@dfn{implicit inputs} of a package, because package definitions don't
2553have to mention them.
2554@end defvr
2555
2556Other @code{<build-system>} objects are defined to support other
2557conventions and tools used by free software packages. They inherit most
2558of @var{gnu-build-system}, and differ mainly in the set of inputs
2559implicitly added to the build process, and in the list of phases
2560executed. Some of these build systems are listed below.
2561
2562@defvr {Scheme Variable} cmake-build-system
2563This variable is exported by @code{(guix build-system cmake)}. It
2564implements the build procedure for packages using the
2565@url{http://www.cmake.org, CMake build tool}.
2566
2567It automatically adds the @code{cmake} package to the set of inputs.
2568Which package is used can be specified with the @code{#:cmake}
2569parameter.
9849cfc1
LC
2570
2571The @code{#:configure-flags} parameter is taken as a list of flags
2572passed to the @command{cmake} command. The @code{#:build-type}
2573parameter specifies in abstract terms the flags passed to the compiler;
2574it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
2575debugging information''), which roughly means that code is compiled with
2576@code{-O2 -g}, as is the case for Autoconf-based packages by default.
7458bd0a
LC
2577@end defvr
2578
3afcf52b
FB
2579@defvr {Scheme Variable} glib-or-gtk-build-system
2580This variable is exported by @code{(guix build-system glib-or-gtk)}. It
2581is intended for use with packages making use of GLib or GTK+.
2582
2583This build system adds the following two phases to the ones defined by
2584@var{gnu-build-system}:
2585
2586@table @code
2587@item glib-or-gtk-wrap
2588The phase @code{glib-or-gtk-wrap} ensures that programs found under
2589@file{bin/} are able to find GLib's ``schemas'' and
2590@uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
2591modules}. This is achieved by wrapping the programs in launch scripts
2592that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
2593environment variables.
2594
73aa8ddb
LC
2595It is possible to exclude specific package outputs from that wrapping
2596process by listing their names in the
2597@code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
2598when an output is known not to contain any GLib or GTK+ binaries, and
2599where wrapping would gratuitously add a dependency of that output on
2600GLib and GTK+.
2601
3afcf52b
FB
2602@item glib-or-gtk-compile-schemas
2603The phase @code{glib-or-gtk-compile-schemas} makes sure that all GLib's
2604@uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
2605GSettings schemas} are compiled. Compilation is performed by the
2606@command{glib-compile-schemas} program. It is provided by the package
2607@code{glib:bin} which is automatically imported by the build system.
2608The @code{glib} package providing @command{glib-compile-schemas} can be
2609specified with the @code{#:glib} parameter.
2610@end table
2611
2612Both phases are executed after the @code{install} phase.
2613@end defvr
2614
7458bd0a
LC
2615@defvr {Scheme Variable} python-build-system
2616This variable is exported by @code{(guix build-system python)}. It
2617implements the more or less standard build procedure used by Python
2618packages, which consists in running @code{python setup.py build} and
2619then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
2620
2621For packages that install stand-alone Python programs under @code{bin/},
2622it takes care of wrapping these programs so their @code{PYTHONPATH}
2623environment variable points to all the Python libraries they depend on.
2624
2625Which Python package is used can be specified with the @code{#:python}
2626parameter.
2627@end defvr
2628
2629@defvr {Scheme Variable} perl-build-system
2630This variable is exported by @code{(guix build-system perl)}. It
2d2a53fc
EB
2631implements the standard build procedure for Perl packages, which either
2632consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
2633followed by @code{Build} and @code{Build install}; or in running
2634@code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
2635@code{make} and @code{make install}; depending on which of
2636@code{Build.PL} or @code{Makefile.PL} is present in the package
2637distribution. Preference is given to the former if both @code{Build.PL}
2638and @code{Makefile.PL} exist in the package distribution. This
2639preference can be reversed by specifying @code{#t} for the
2640@code{#:make-maker?} parameter.
2641
2642The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
2643passes flags specified by the @code{#:make-maker-flags} or
2644@code{#:module-build-flags} parameter, respectively.
7458bd0a
LC
2645
2646Which Perl package is used can be specified with @code{#:perl}.
2647@end defvr
2648
f8f3bef6
RW
2649@defvr {Scheme Variable} r-build-system
2650This variable is exported by @code{(guix build-system r)}. It
2651implements the build procedure used by @uref{http://r-project.org, R}
2652packages, which essentially is little more than running @code{R CMD
2653INSTALL --library=/gnu/store/@dots{}} in an environment where
2654@code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
2655are run after installation using the R function
2656@code{tools::testInstalledPackage}.
2657@end defvr
2658
c08f9818
DT
2659@defvr {Scheme Variable} ruby-build-system
2660This variable is exported by @code{(guix build-system ruby)}. It
2661implements the RubyGems build procedure used by Ruby packages, which
2662involves running @code{gem build} followed by @code{gem install}.
2663
5dc87623
DT
2664The @code{source} field of a package that uses this build system
2665typically references a gem archive, since this is the format that Ruby
2666developers use when releasing their software. The build system unpacks
2667the gem archive, potentially patches the source, runs the test suite,
2668repackages the gem, and installs it. Additionally, directories and
2669tarballs may be referenced to allow building unreleased gems from Git or
2670a traditional source release tarball.
e83c6d00 2671
c08f9818 2672Which Ruby package is used can be specified with the @code{#:ruby}
6e9f2913
PP
2673parameter. A list of additional flags to be passed to the @command{gem}
2674command can be specified with the @code{#:gem-flags} parameter.
c08f9818 2675@end defvr
7458bd0a 2676
a677c726
RW
2677@defvr {Scheme Variable} waf-build-system
2678This variable is exported by @code{(guix build-system waf)}. It
2679implements a build procedure around the @code{waf} script. The common
2680phases---@code{configure}, @code{build}, and @code{install}---are
2681implemented by passing their names as arguments to the @code{waf}
2682script.
2683
2684The @code{waf} script is executed by the Python interpreter. Which
2685Python package is used to run the script can be specified with the
2686@code{#:python} parameter.
2687@end defvr
2688
14dfdf2e
FB
2689@defvr {Scheme Variable} haskell-build-system
2690This variable is exported by @code{(guix build-system haskell)}. It
2691implements the Cabal build procedure used by Haskell packages, which
2692involves running @code{runhaskell Setup.hs configure
2693--prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
2694Instead of installing the package by running @code{runhaskell Setup.hs
2695install}, to avoid trying to register libraries in the read-only
2696compiler store directory, the build system uses @code{runhaskell
2697Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
2698addition, the build system generates the package documentation by
2699running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
2700is passed. Optional Haddock parameters can be passed with the help of
2701the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
2702not found, the build system looks for @code{Setup.lhs} instead.
2703
2704Which Haskell compiler is used can be specified with the @code{#:haskell}
a54bd6d7 2705parameter which defaults to @code{ghc}.
14dfdf2e
FB
2706@end defvr
2707
e9137a53
FB
2708@defvr {Scheme Variable} emacs-build-system
2709This variable is exported by @code{(guix build-system emacs)}. It
2710implements an installation procedure similar to the one of Emacs' own
2711packaging system (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
2712
2713It first creates the @code{@var{package}-autoloads.el} file, then it
2714byte compiles all Emacs Lisp files. Differently from the Emacs
2715packaging system, the Info documentation files are moved to the standard
2716documentation directory and the @file{dir} file is deleted. Each
2717package is installed in its own directory under
2718@file{share/emacs/site-lisp/guix.d}.
2719@end defvr
2720
7458bd0a
LC
2721Lastly, for packages that do not need anything as sophisticated, a
2722``trivial'' build system is provided. It is trivial in the sense that
2723it provides basically no support: it does not pull any implicit inputs,
2724and does not have a notion of build phases.
2725
2726@defvr {Scheme Variable} trivial-build-system
2727This variable is exported by @code{(guix build-system trivial)}.
2728
2729This build system requires a @code{#:builder} argument. This argument
2730must be a Scheme expression that builds the package's output(s)---as
2731with @code{build-expression->derivation} (@pxref{Derivations,
2732@code{build-expression->derivation}}).
2733@end defvr
2734
568717fd
LC
2735@node The Store
2736@section The Store
2737
e531ac2a
LC
2738@cindex store
2739@cindex store paths
2740
2741Conceptually, the @dfn{store} is where derivations that have been
834129e0 2742successfully built are stored---by default, under @file{/gnu/store}.
e531ac2a 2743Sub-directories in the store are referred to as @dfn{store paths}. The
4988dd40 2744store has an associated database that contains information such as the
e531ac2a
LC
2745store paths referred to by each store path, and the list of @emph{valid}
2746store paths---paths that result from a successful build.
2747
2748The store is always accessed by the daemon on behalf of its clients
2749(@pxref{Invoking guix-daemon}). To manipulate the store, clients
2750connect to the daemon over a Unix-domain socket, send it requests, and
2751read the result---these are remote procedure calls, or RPCs.
2752
2753The @code{(guix store)} module provides procedures to connect to the
2754daemon, and to perform RPCs. These are described below.
2755
2756@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
2757Connect to the daemon over the Unix-domain socket at @var{file}. When
2758@var{reserve-space?} is true, instruct it to reserve a little bit of
2759extra space on the file system so that the garbage collector can still
2760operate, should the disk become full. Return a server object.
2761
2762@var{file} defaults to @var{%default-socket-path}, which is the normal
2763location given the options that were passed to @command{configure}.
2764@end deffn
2765
2766@deffn {Scheme Procedure} close-connection @var{server}
2767Close the connection to @var{server}.
2768@end deffn
2769
2770@defvr {Scheme Variable} current-build-output-port
2771This variable is bound to a SRFI-39 parameter, which refers to the port
2772where build and error logs sent by the daemon should be written.
2773@end defvr
2774
2775Procedures that make RPCs all take a server object as their first
2776argument.
2777
2778@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
2779Return @code{#t} when @var{path} is a valid store path.
2780@end deffn
2781
cfbf9160 2782@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
2783Add @var{text} under file @var{name} in the store, and return its store
2784path. @var{references} is the list of store paths referred to by the
2785resulting store path.
2786@end deffn
2787
874e6874 2788@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
2789Build @var{derivations} (a list of @code{<derivation>} objects or
2790derivation paths), and return when the worker is done building them.
2791Return @code{#t} on success.
874e6874
LC
2792@end deffn
2793
b860f382
LC
2794Note that the @code{(guix monads)} module provides a monad as well as
2795monadic versions of the above procedures, with the goal of making it
2796more convenient to work with code that accesses the store (@pxref{The
2797Store Monad}).
2798
e531ac2a
LC
2799@c FIXME
2800@i{This section is currently incomplete.}
568717fd
LC
2801
2802@node Derivations
2803@section Derivations
2804
874e6874
LC
2805@cindex derivations
2806Low-level build actions and the environment in which they are performed
2807are represented by @dfn{derivations}. A derivation contain the
2808following pieces of information:
2809
2810@itemize
2811@item
2812The outputs of the derivation---derivations produce at least one file or
2813directory in the store, but may produce more.
2814
2815@item
2816The inputs of the derivations, which may be other derivations or plain
2817files in the store (patches, build scripts, etc.)
2818
2819@item
2820The system type targeted by the derivation---e.g., @code{x86_64-linux}.
2821
2822@item
2823The file name of a build script in the store, along with the arguments
2824to be passed.
2825
2826@item
2827A list of environment variables to be defined.
2828
2829@end itemize
2830
2831@cindex derivation path
2832Derivations allow clients of the daemon to communicate build actions to
2833the store. They exist in two forms: as an in-memory representation,
2834both on the client- and daemon-side, and as files in the store whose
2835name end in @code{.drv}---these files are referred to as @dfn{derivation
2836paths}. Derivations paths can be passed to the @code{build-derivations}
2837procedure to perform the build actions they prescribe (@pxref{The
2838Store}).
2839
2840The @code{(guix derivations)} module provides a representation of
2841derivations as Scheme objects, along with procedures to create and
2842otherwise manipulate derivations. The lowest-level primitive to create
2843a derivation is the @code{derivation} procedure:
2844
1909431c
LC
2845@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
2846 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 2847 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c 2848 [#:system (%current-system)] [#:references-graphs #f] @
4a6aeb67
LC
2849 [#:allowed-references #f] [#:leaked-env-vars #f] [#:local-build? #f] @
2850 [#:substitutable? #t]
59688fc4
LC
2851Build a derivation with the given arguments, and return the resulting
2852@code{<derivation>} object.
874e6874 2853
2096ef47 2854When @var{hash} and @var{hash-algo} are given, a
874e6874 2855@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
2856known in advance, such as a file download. If, in addition,
2857@var{recursive?} is true, then that fixed output may be an executable
2858file or a directory and @var{hash} must be the hash of an archive
2859containing this output.
5b0c9d16 2860
858e9282 2861When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
2862name/store path pairs. In that case, the reference graph of each store
2863path is exported in the build environment in the corresponding file, in
2864a simple text format.
1909431c 2865
b53be755
LC
2866When @var{allowed-references} is true, it must be a list of store items
2867or outputs that the derivation's output may refer to.
2868
c0468155
LC
2869When @var{leaked-env-vars} is true, it must be a list of strings
2870denoting environment variables that are allowed to ``leak'' from the
2871daemon's environment to the build environment. This is only applicable
2872to fixed-output derivations---i.e., when @var{hash} is true. The main
2873use is to allow variables such as @code{http_proxy} to be passed to
2874derivations that download files.
2875
1909431c
LC
2876When @var{local-build?} is true, declare that the derivation is not a
2877good candidate for offloading and should rather be built locally
2878(@pxref{Daemon Offload Setup}). This is the case for small derivations
2879where the costs of data transfers would outweigh the benefits.
4a6aeb67
LC
2880
2881When @var{substitutable?} is false, declare that substitutes of the
2882derivation's output should not be used (@pxref{Substitutes}). This is
2883useful, for instance, when building packages that capture details of the
2884host CPU instruction set.
874e6874
LC
2885@end deffn
2886
2887@noindent
2888Here's an example with a shell script as its builder, assuming
2889@var{store} is an open connection to the daemon, and @var{bash} points
2890to a Bash executable in the store:
2891
2892@lisp
2893(use-modules (guix utils)
2894 (guix store)
2895 (guix derivations))
2896
59688fc4
LC
2897(let ((builder ; add the Bash script to the store
2898 (add-text-to-store store "my-builder.sh"
2899 "echo hello world > $out\n" '())))
2900 (derivation store "foo"
2901 bash `("-e" ,builder)
21b679f6 2902 #:inputs `((,bash) (,builder))
59688fc4 2903 #:env-vars '(("HOME" . "/homeless"))))
834129e0 2904@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
2905@end lisp
2906
21b679f6
LC
2907As can be guessed, this primitive is cumbersome to use directly. A
2908better approach is to write build scripts in Scheme, of course! The
2909best course of action for that is to write the build code as a
2910``G-expression'', and to pass it to @code{gexp->derivation}. For more
6621cdb6 2911information, @pxref{G-Expressions}.
21b679f6
LC
2912
2913Once upon a time, @code{gexp->derivation} did not exist and constructing
2914derivations with build code written in Scheme was achieved with
2915@code{build-expression->derivation}, documented below. This procedure
2916is now deprecated in favor of the much nicer @code{gexp->derivation}.
874e6874 2917
dd1a5a15
LC
2918@deffn {Scheme Procedure} build-expression->derivation @var{store} @
2919 @var{name} @var{exp} @
2920 [#:system (%current-system)] [#:inputs '()] @
2921 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
36bbbbd1 2922 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
63a42824 2923 [#:references-graphs #f] [#:allowed-references #f] @
4a6aeb67 2924 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
874e6874
LC
2925Return a derivation that executes Scheme expression @var{exp} as a
2926builder for derivation @var{name}. @var{inputs} must be a list of
2927@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
2928@code{"out"} is assumed. @var{modules} is a list of names of Guile
2929modules from the current search path to be copied in the store,
2930compiled, and made available in the load path during the execution of
2931@var{exp}---e.g., @code{((guix build utils) (guix build
2932gnu-build-system))}.
2933
2934@var{exp} is evaluated in an environment where @code{%outputs} is bound
2935to a list of output/path pairs, and where @code{%build-inputs} is bound
2936to a list of string/output-path pairs made from @var{inputs}.
2937Optionally, @var{env-vars} is a list of string pairs specifying the name
2938and value of environment variables visible to the builder. The builder
2939terminates by passing the result of @var{exp} to @code{exit}; thus, when
2940@var{exp} returns @code{#f}, the build is considered to have failed.
2941
2942@var{exp} is built using @var{guile-for-build} (a derivation). When
2943@var{guile-for-build} is omitted or is @code{#f}, the value of the
2944@code{%guile-for-build} fluid is used instead.
9c629a27 2945
63a42824 2946See the @code{derivation} procedure for the meaning of
4a6aeb67
LC
2947@var{references-graphs}, @var{allowed-references}, @var{local-build?},
2948and @var{substitutable?}.
874e6874
LC
2949@end deffn
2950
2951@noindent
2952Here's an example of a single-output derivation that creates a directory
2953containing one file:
2954
2955@lisp
2956(let ((builder '(let ((out (assoc-ref %outputs "out")))
834129e0 2957 (mkdir out) ; create /gnu/store/@dots{}-goo
874e6874
LC
2958 (call-with-output-file (string-append out "/test")
2959 (lambda (p)
2960 (display '(hello guix) p))))))
dd1a5a15 2961 (build-expression->derivation store "goo" builder))
874e6874 2962
834129e0 2963@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
874e6874
LC
2964@end lisp
2965
568717fd 2966
b860f382
LC
2967@node The Store Monad
2968@section The Store Monad
2969
2970@cindex monad
2971
2972The procedures that operate on the store described in the previous
2973sections all take an open connection to the build daemon as their first
2974argument. Although the underlying model is functional, they either have
2975side effects or depend on the current state of the store.
2976
2977The former is inconvenient: the connection to the build daemon has to be
2978carried around in all those functions, making it impossible to compose
2979functions that do not take that parameter with functions that do. The
2980latter can be problematic: since store operations have side effects
2981and/or depend on external state, they have to be properly sequenced.
2982
2983@cindex monadic values
2984@cindex monadic functions
2985This is where the @code{(guix monads)} module comes in. This module
2986provides a framework for working with @dfn{monads}, and a particularly
2987useful monad for our uses, the @dfn{store monad}. Monads are a
2988construct that allows two things: associating ``context'' with values
2989(in our case, the context is the store), and building sequences of
561fb6c3 2990computations (here computations include accesses to the store.) Values
b860f382
LC
2991in a monad---values that carry this additional context---are called
2992@dfn{monadic values}; procedures that return such values are called
2993@dfn{monadic procedures}.
2994
2995Consider this ``normal'' procedure:
2996
2997@example
45adbd62
LC
2998(define (sh-symlink store)
2999 ;; Return a derivation that symlinks the 'bash' executable.
3000 (let* ((drv (package-derivation store bash))
3001 (out (derivation->output-path drv))
3002 (sh (string-append out "/bin/bash")))
3003 (build-expression->derivation store "sh"
3004 `(symlink ,sh %output))))
b860f382
LC
3005@end example
3006
c6f30b81
LC
3007Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3008as a monadic function:
b860f382
LC
3009
3010@example
45adbd62 3011(define (sh-symlink)
b860f382 3012 ;; Same, but return a monadic value.
c6f30b81
LC
3013 (mlet %store-monad ((drv (package->derivation bash)))
3014 (gexp->derivation "sh"
3015 #~(symlink (string-append #$drv "/bin/bash")
3016 #$output))))
b860f382
LC
3017@end example
3018
c6f30b81
LC
3019There several things to note in the second version: the @code{store}
3020parameter is now implicit and is ``threaded'' in the calls to the
3021@code{package->derivation} and @code{gexp->derivation} monadic
3022procedures, and the monadic value returned by @code{package->derivation}
3023is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3024
3025As it turns out, the call to @code{package->derivation} can even be
3026omitted since it will take place implicitly, as we will see later
3027(@pxref{G-Expressions}):
3028
3029@example
3030(define (sh-symlink)
3031 (gexp->derivation "sh"
3032 #~(symlink (string-append #$bash "/bin/bash")
3033 #$output)))
3034@end example
b860f382 3035
7ce21611
LC
3036@c See
3037@c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
3038@c for the funny quote.
3039Calling the monadic @code{sh-symlink} has no effect. As someone once
3040said, ``you exit a monad like you exit a building on fire: by running''.
3041So, to exit the monad and get the desired effect, one must use
3042@code{run-with-store}:
b860f382
LC
3043
3044@example
8e9aa37f
CAW
3045(run-with-store (open-connection) (sh-symlink))
3046@result{} /gnu/store/...-sh-symlink
b860f382
LC
3047@end example
3048
b9b86078
LC
3049Note that the @code{(guix monad-repl)} module extends Guile's REPL with
3050new ``meta-commands'' to make it easier to deal with monadic procedures:
3051@code{run-in-store}, and @code{enter-store-monad}. The former, is used
3052to ``run'' a single monadic value through the store:
3053
3054@example
3055scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3056$1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3057@end example
3058
3059The latter enters a recursive REPL, where all the return values are
3060automatically run through the store:
3061
3062@example
3063scheme@@(guile-user)> ,enter-store-monad
3064store-monad@@(guile-user) [1]> (package->derivation hello)
3065$2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3066store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3067$3 = "/gnu/store/@dots{}-foo"
3068store-monad@@(guile-user) [1]> ,q
3069scheme@@(guile-user)>
3070@end example
3071
3072@noindent
3073Note that non-monadic values cannot be returned in the
3074@code{store-monad} REPL.
3075
e87f0591
LC
3076The main syntactic forms to deal with monads in general are provided by
3077the @code{(guix monads)} module and are described below.
b860f382
LC
3078
3079@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3080Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3081in @var{monad}.
3082@end deffn
3083
3084@deffn {Scheme Syntax} return @var{val}
3085Return a monadic value that encapsulates @var{val}.
3086@end deffn
3087
751630c9 3088@deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
b860f382 3089@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
751630c9
LC
3090procedures @var{mproc}@dots{}@footnote{This operation is commonly
3091referred to as ``bind'', but that name denotes an unrelated procedure in
3092Guile. Thus we use this somewhat cryptic symbol inherited from the
3093Haskell language.}. There can be one @var{mproc} or several of them, as
3094in this example:
3095
3096@example
3097(run-with-state
3098 (with-monad %state-monad
3099 (>>= (return 1)
3100 (lambda (x) (return (+ 1 x)))
3101 (lambda (x) (return (* 2 x)))))
3102 'some-state)
3103
3104@result{} 4
3105@result{} some-state
3106@end example
b860f382
LC
3107@end deffn
3108
3109@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3110 @var{body} ...
3111@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3112 @var{body} ...
3113Bind the variables @var{var} to the monadic values @var{mval} in
3114@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3115``normal'' value @var{val}, as per @code{let}.
3116
3117@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3118(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3119@end deffn
3120
405a9d4e
LC
3121@deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3122Bind @var{mexp} and the following monadic expressions in sequence,
3123returning the result of the last expression.
3124
3125This is akin to @code{mlet}, except that the return values of the
3126monadic expressions are ignored. In that sense, it is analogous to
3127@code{begin}, but applied to monadic expressions.
3128@end deffn
3129
561fb6c3
LC
3130@cindex state monad
3131The @code{(guix monads)} module provides the @dfn{state monad}, which
3132allows an additional value---the state---to be @emph{threaded} through
3133monadic procedure calls.
3134
3135@defvr {Scheme Variable} %state-monad
3136The state monad. Procedures in the state monad can access and change
3137the state that is threaded.
3138
3139Consider the example below. The @code{square} procedure returns a value
3140in the state monad. It returns the square of its argument, but also
3141increments the current state value:
3142
3143@example
3144(define (square x)
3145 (mlet %state-monad ((count (current-state)))
3146 (mbegin %state-monad
3147 (set-current-state (+ 1 count))
3148 (return (* x x)))))
3149
3150(run-with-state (sequence %state-monad (map square (iota 3))) 0)
3151@result{} (0 1 4)
3152@result{} 3
3153@end example
3154
3155When ``run'' through @var{%state-monad}, we obtain that additional state
3156value, which is the number of @code{square} calls.
3157@end defvr
3158
3159@deffn {Monadic Procedure} current-state
3160Return the current state as a monadic value.
3161@end deffn
3162
3163@deffn {Monadic Procedure} set-current-state @var{value}
3164Set the current state to @var{value} and return the previous state as a
3165monadic value.
3166@end deffn
3167
3168@deffn {Monadic Procedure} state-push @var{value}
3169Push @var{value} to the current state, which is assumed to be a list,
3170and return the previous state as a monadic value.
3171@end deffn
3172
3173@deffn {Monadic Procedure} state-pop
3174Pop a value from the current state and return it as a monadic value.
3175The state is assumed to be a list.
3176@end deffn
3177
3178@deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3179Run monadic value @var{mval} starting with @var{state} as the initial
3180state. Return two values: the resulting value, and the resulting state.
3181@end deffn
3182
e87f0591
LC
3183The main interface to the store monad, provided by the @code{(guix
3184store)} module, is as follows.
b860f382
LC
3185
3186@defvr {Scheme Variable} %store-monad
561fb6c3
LC
3187The store monad---an alias for @var{%state-monad}.
3188
3189Values in the store monad encapsulate accesses to the store. When its
3190effect is needed, a value of the store monad must be ``evaluated'' by
3191passing it to the @code{run-with-store} procedure (see below.)
b860f382
LC
3192@end defvr
3193
3194@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3195Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3196open store connection.
3197@end deffn
3198
ad372953 3199@deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
b860f382 3200Return as a monadic value the absolute file name in the store of the file
ad372953
LC
3201containing @var{text}, a string. @var{references} is a list of store items that the
3202resulting text file refers to; it defaults to the empty list.
45adbd62
LC
3203@end deffn
3204
0a90af15
LC
3205@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
3206 [#:recursive? #t]
3207Return the name of @var{file} once interned in the store. Use
3208@var{name} as its store name, or the basename of @var{file} if
3209@var{name} is omitted.
3210
3211When @var{recursive?} is true, the contents of @var{file} are added
3212recursively; if @var{file} designates a flat file and @var{recursive?}
3213is true, its contents are added, and its permission bits are kept.
3214
3215The example below adds a file to the store, under two different names:
3216
3217@example
3218(run-with-store (open-connection)
3219 (mlet %store-monad ((a (interned-file "README"))
3220 (b (interned-file "README" "LEGU-MIN")))
3221 (return (list a b))))
3222
3223@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3224@end example
3225
3226@end deffn
3227
e87f0591
LC
3228The @code{(guix packages)} module exports the following package-related
3229monadic procedures:
3230
b860f382 3231@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4231f05b
LC
3232 [#:system (%current-system)] [#:target #f] @
3233 [#:output "out"] Return as a monadic
b860f382
LC
3234value in the absolute file name of @var{file} within the @var{output}
3235directory of @var{package}. When @var{file} is omitted, return the name
4231f05b
LC
3236of the @var{output} directory of @var{package}. When @var{target} is
3237true, use it as a cross-compilation target triplet.
b860f382
LC
3238@end deffn
3239
b860f382 3240@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4231f05b
LC
3241@deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3242 @var{target} [@var{system}]
3243Monadic version of @code{package-derivation} and
3244@code{package-cross-derivation} (@pxref{Defining Packages}).
b860f382
LC
3245@end deffn
3246
3247
21b679f6
LC
3248@node G-Expressions
3249@section G-Expressions
3250
3251@cindex G-expression
3252@cindex build code quoting
3253So we have ``derivations'', which represent a sequence of build actions
3254to be performed to produce an item in the store (@pxref{Derivations}).
3255Those build actions are performed when asking the daemon to actually
3256build the derivations; they are run by the daemon in a container
3257(@pxref{Invoking guix-daemon}).
3258
3259@cindex strata of code
3260It should come as no surprise that we like to write those build actions
3261in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3262code@footnote{The term @dfn{stratum} in this context was coined by
ef4ab0a4
LC
3263Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3264Kiselyov, who has written insightful
3265@url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3266on this topic}, refers to this kind of code generation as
3267@dfn{staging}.}: the ``host code''---code that defines packages, talks
3268to the daemon, etc.---and the ``build code''---code that actually
3269performs build actions, such as making directories, invoking
3270@command{make}, etc.
21b679f6
LC
3271
3272To describe a derivation and its build actions, one typically needs to
3273embed build code inside host code. It boils down to manipulating build
3274code as data, and Scheme's homoiconicity---code has a direct
3275representation as data---comes in handy for that. But we need more than
3276Scheme's normal @code{quasiquote} mechanism to construct build
3277expressions.
3278
3279The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3280S-expressions adapted to build expressions. G-expressions, or
3281@dfn{gexps}, consist essentially in three syntactic forms: @code{gexp},
3282@code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
3283@code{#$}, and @code{#$@@}), which are comparable respectively to
3284@code{quasiquote}, @code{unquote}, and @code{unquote-splicing}
3285(@pxref{Expression Syntax, @code{quasiquote},, guile, GNU Guile
3286Reference Manual}). However, there are major differences:
3287
3288@itemize
3289@item
3290Gexps are meant to be written to a file and run or manipulated by other
3291processes.
3292
3293@item
b39fc6f7
LC
3294When a high-level object such as a package or derivation is unquoted
3295inside a gexp, the result is as if its output file name had been
3296introduced.
ff40e9b7 3297
21b679f6
LC
3298@item
3299Gexps carry information about the packages or derivations they refer to,
3300and these dependencies are automatically added as inputs to the build
3301processes that use them.
3302@end itemize
3303
c2b84676 3304@cindex lowering, of high-level objects in gexps
343eacbe
LC
3305This mechanism is not limited to package and derivation
3306objects: @dfn{compilers} able to ``lower'' other high-level objects to
c2b84676
LC
3307derivations or files in the store can be defined,
3308such that these objects can also be inserted
343eacbe
LC
3309into gexps. For example, a useful type of high-level object that can be
3310inserted in a gexp is ``file-like objects'', which make it easy to
3311add files to the store and refer to them in
558e8b11
LC
3312derivations and such (see @code{local-file} and @code{plain-file}
3313below.)
b39fc6f7 3314
21b679f6
LC
3315To illustrate the idea, here is an example of a gexp:
3316
3317@example
3318(define build-exp
3319 #~(begin
3320 (mkdir #$output)
3321 (chdir #$output)
aff8ce7c 3322 (symlink (string-append #$coreutils "/bin/ls")
21b679f6
LC
3323 "list-files")))
3324@end example
3325
3326This gexp can be passed to @code{gexp->derivation}; we obtain a
3327derivation that builds a directory containing exactly one symlink to
3328@file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3329
3330@example
3331(gexp->derivation "the-thing" build-exp)
3332@end example
3333
e20fd1bf 3334As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
21b679f6
LC
3335substituted to the reference to the @var{coreutils} package in the
3336actual build code, and @var{coreutils} is automatically made an input to
3337the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
3338output)}) is replaced by a string containing the derivation's output
667b2508
LC
3339directory name.
3340
3341@cindex cross compilation
3342In a cross-compilation context, it is useful to distinguish between
3343references to the @emph{native} build of a package---that can run on the
3344host---versus references to cross builds of a package. To that end, the
3345@code{#+} plays the same role as @code{#$}, but is a reference to a
3346native package build:
3347
3348@example
3349(gexp->derivation "vi"
3350 #~(begin
3351 (mkdir #$output)
3352 (system* (string-append #+coreutils "/bin/ln")
3353 "-s"
3354 (string-append #$emacs "/bin/emacs")
3355 (string-append #$output "/bin/vi")))
3356 #:target "mips64el-linux")
3357@end example
3358
3359@noindent
3360In the example above, the native build of @var{coreutils} is used, so
3361that @command{ln} can actually run on the host; but then the
3362cross-compiled build of @var{emacs} is referenced.
3363
3364The syntactic form to construct gexps is summarized below.
21b679f6
LC
3365
3366@deffn {Scheme Syntax} #~@var{exp}
3367@deffnx {Scheme Syntax} (gexp @var{exp})
3368Return a G-expression containing @var{exp}. @var{exp} may contain one
3369or more of the following forms:
3370
3371@table @code
3372@item #$@var{obj}
3373@itemx (ungexp @var{obj})
b39fc6f7
LC
3374Introduce a reference to @var{obj}. @var{obj} may have one of the
3375supported types, for example a package or a
21b679f6
LC
3376derivation, in which case the @code{ungexp} form is replaced by its
3377output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
3378
b39fc6f7
LC
3379If @var{obj} is a list, it is traversed and references to supported
3380objects are substituted similarly.
21b679f6
LC
3381
3382If @var{obj} is another gexp, its contents are inserted and its
3383dependencies are added to those of the containing gexp.
3384
3385If @var{obj} is another kind of object, it is inserted as is.
3386
b39fc6f7
LC
3387@item #$@var{obj}:@var{output}
3388@itemx (ungexp @var{obj} @var{output})
21b679f6 3389This is like the form above, but referring explicitly to the
b39fc6f7
LC
3390@var{output} of @var{obj}---this is useful when @var{obj} produces
3391multiple outputs (@pxref{Packages with Multiple Outputs}).
21b679f6 3392
667b2508
LC
3393@item #+@var{obj}
3394@itemx #+@var{obj}:output
3395@itemx (ungexp-native @var{obj})
3396@itemx (ungexp-native @var{obj} @var{output})
3397Same as @code{ungexp}, but produces a reference to the @emph{native}
3398build of @var{obj} when used in a cross compilation context.
3399
21b679f6
LC
3400@item #$output[:@var{output}]
3401@itemx (ungexp output [@var{output}])
3402Insert a reference to derivation output @var{output}, or to the main
3403output when @var{output} is omitted.
3404
3405This only makes sense for gexps passed to @code{gexp->derivation}.
3406
3407@item #$@@@var{lst}
3408@itemx (ungexp-splicing @var{lst})
3409Like the above, but splices the contents of @var{lst} inside the
3410containing list.
3411
667b2508
LC
3412@item #+@@@var{lst}
3413@itemx (ungexp-native-splicing @var{lst})
3414Like the above, but refers to native builds of the objects listed in
3415@var{lst}.
3416
21b679f6
LC
3417@end table
3418
3419G-expressions created by @code{gexp} or @code{#~} are run-time objects
3420of the @code{gexp?} type (see below.)
3421@end deffn
3422
3423@deffn {Scheme Procedure} gexp? @var{obj}
3424Return @code{#t} if @var{obj} is a G-expression.
3425@end deffn
3426
3427G-expressions are meant to be written to disk, either as code building
3428some derivation, or as plain files in the store. The monadic procedures
3429below allow you to do that (@pxref{The Store Monad}, for more
3430information about monads.)
3431
3432@deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
ce45eb4c 3433 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
21b679f6
LC
3434 [#:hash #f] [#:hash-algo #f] @
3435 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4684f301 3436 [#:module-path @var{%load-path}] @
c8351d9a 3437 [#:references-graphs #f] [#:allowed-references #f] @
c0468155 3438 [#:leaked-env-vars #f] @
0309e1b0 3439 [#:script-name (string-append @var{name} "-builder")] @
4a6aeb67 3440 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
21b679f6 3441Return a derivation @var{name} that runs @var{exp} (a gexp) with
0309e1b0
LC
3442@var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
3443stored in a file called @var{script-name}. When @var{target} is true,
3444it is used as the cross-compilation target triplet for packages referred
3445to by @var{exp}.
21b679f6 3446
ce45eb4c
LC
3447Make @var{modules} available in the evaluation context of @var{exp};
3448@var{modules} is a list of names of Guile modules searched in
3449@var{module-path} to be copied in the store, compiled, and made available in
21b679f6
LC
3450the load path during the execution of @var{exp}---e.g., @code{((guix
3451build utils) (guix build gnu-build-system))}.
3452
ce45eb4c
LC
3453@var{graft?} determines whether packages referred to by @var{exp} should be grafted when
3454applicable.
3455
b53833b2
LC
3456When @var{references-graphs} is true, it must be a list of tuples of one of the
3457following forms:
3458
3459@example
3460(@var{file-name} @var{package})
3461(@var{file-name} @var{package} @var{output})
3462(@var{file-name} @var{derivation})
3463(@var{file-name} @var{derivation} @var{output})
3464(@var{file-name} @var{store-item})
3465@end example
3466
3467The right-hand-side of each element of @var{references-graphs} is automatically made
3468an input of the build process of @var{exp}. In the build environment, each
3469@var{file-name} contains the reference graph of the corresponding item, in a simple
3470text format.
3471
c8351d9a
LC
3472@var{allowed-references} must be either @code{#f} or a list of output names and packages.
3473In the latter case, the list denotes store items that the result is allowed to
3474refer to. Any reference to another store item will lead to a build error.
3475
e20fd1bf 3476The other arguments are as for @code{derivation} (@pxref{Derivations}).
21b679f6
LC
3477@end deffn
3478
343eacbe 3479@cindex file-like objects
e1c153e0
LC
3480The @code{local-file}, @code{plain-file}, @code{computed-file},
3481@code{program-file}, and @code{scheme-file} procedures below return
3482@dfn{file-like objects}. That is, when unquoted in a G-expression,
3483these objects lead to a file in the store. Consider this G-expression:
343eacbe
LC
3484
3485@example
3486#~(system* (string-append #$glibc "/sbin/nscd") "-f"
3487 #$(local-file "/tmp/my-nscd.conf"))
3488@end example
3489
3490The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
3491to the store. Once expanded, for instance @i{via}
3492@code{gexp->derivation}, the G-expression refers to that copy under
3493@file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
3494does not have any effect on what the G-expression does.
3495@code{plain-file} can be used similarly; it differs in that the file
3496content is directly passed as a string.
3497
d9ae938f
LC
3498@deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
3499 [#:recursive? #t]
3500Return an object representing local file @var{file} to add to the store; this
9d3994f7
LC
3501object can be used in a gexp. If @var{file} is a relative file name, it is looked
3502up relative to the source file where this form appears. @var{file} will be added to
3503the store under @var{name}--by default the base name of @var{file}.
d9ae938f
LC
3504
3505When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
3506designates a flat file and @var{recursive?} is true, its contents are added, and its
3507permission bits are kept.
3508
3509This is the declarative counterpart of the @code{interned-file} monadic
3510procedure (@pxref{The Store Monad, @code{interned-file}}).
3511@end deffn
3512
558e8b11
LC
3513@deffn {Scheme Procedure} plain-file @var{name} @var{content}
3514Return an object representing a text file called @var{name} with the given
3515@var{content} (a string) to be added to the store.
3516
3517This is the declarative counterpart of @code{text-file}.
3518@end deffn
3519
91937029
LC
3520@deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
3521 [#:modules '()] [#:options '(#:local-build? #t)]
3522Return an object representing the store item @var{name}, a file or
3523directory computed by @var{gexp}. @var{modules} specifies the set of
3524modules visible in the execution context of @var{gexp}. @var{options}
3525is a list of additional arguments to pass to @code{gexp->derivation}.
3526
3527This is the declarative counterpart of @code{gexp->derivation}.
3528@end deffn
3529
21b679f6
LC
3530@deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
3531Return an executable script @var{name} that runs @var{exp} using
3532@var{guile} with @var{modules} in its search path.
3533
3534The example below builds a script that simply invokes the @command{ls}
3535command:
3536
3537@example
3538(use-modules (guix gexp) (gnu packages base))
3539
3540(gexp->script "list-files"
3541 #~(execl (string-append #$coreutils "/bin/ls")
3542 "ls"))
3543@end example
3544
3545When ``running'' it through the store (@pxref{The Store Monad,
e20fd1bf 3546@code{run-with-store}}), we obtain a derivation that produces an
21b679f6
LC
3547executable file @file{/gnu/store/@dots{}-list-files} along these lines:
3548
3549@example
3550#!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
3551!#
3552(execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls")
3553 "ls")
3554@end example
3555@end deffn
3556
15a01c72
LC
3557@deffn {Scheme Procedure} program-file @var{name} @var{exp} @
3558 [#:modules '()] [#:guile #f]
3559Return an object representing the executable store item @var{name} that
3560runs @var{gexp}. @var{guile} is the Guile package used to execute that
3561script, and @var{modules} is the list of modules visible to that script.
3562
3563This is the declarative counterpart of @code{gexp->script}.
3564@end deffn
3565
21b679f6
LC
3566@deffn {Monadic Procedure} gexp->file @var{name} @var{exp}
3567Return a derivation that builds a file @var{name} containing @var{exp}.
3568
3569The resulting file holds references to all the dependencies of @var{exp}
3570or a subset thereof.
3571@end deffn
1ed19464 3572
e1c153e0
LC
3573@deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
3574Return an object representing the Scheme file @var{name} that contains
3575@var{exp}.
3576
3577This is the declarative counterpart of @code{gexp->file}.
3578@end deffn
3579
1ed19464
LC
3580@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
3581Return as a monadic value a derivation that builds a text file
3582containing all of @var{text}. @var{text} may list, in addition to
d9ae938f
LC
3583strings, objects of any type that can be used in a gexp: packages,
3584derivations, local file objects, etc. The resulting store file holds
3585references to all these.
1ed19464
LC
3586
3587This variant should be preferred over @code{text-file} anytime the file
3588to create will reference items from the store. This is typically the
3589case when building a configuration file that embeds store file names,
3590like this:
3591
3592@example
3593(define (profile.sh)
3594 ;; Return the name of a shell script in the store that
3595 ;; initializes the 'PATH' environment variable.
3596 (text-file* "profile.sh"
3597 "export PATH=" coreutils "/bin:"
3598 grep "/bin:" sed "/bin\n"))
3599@end example
3600
3601In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
3602will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
3603preventing them from being garbage-collected during its lifetime.
3604@end deffn
21b679f6 3605
b751cde3
LC
3606@deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
3607Return an object representing store file @var{name} containing
3608@var{text}. @var{text} is a sequence of strings and file-like objects,
3609as in:
3610
3611@example
3612(mixed-text-file "profile"
3613 "export PATH=" coreutils "/bin:" grep "/bin")
3614@end example
3615
3616This is the declarative counterpart of @code{text-file*}.
3617@end deffn
3618
21b679f6
LC
3619Of course, in addition to gexps embedded in ``host'' code, there are
3620also modules containing build tools. To make it clear that they are
3621meant to be used in the build stratum, these modules are kept in the
3622@code{(guix build @dots{})} name space.
3623
c2b84676
LC
3624@cindex lowering, of high-level objects in gexps
3625Internally, high-level objects are @dfn{lowered}, using their compiler,
3626to either derivations or store items. For instance, lowering a package
3627yields a derivation, and lowering a @code{plain-file} yields a store
3628item. This is achieved using the @code{lower-object} monadic procedure.
3629
3630@deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
3631 [#:target #f]
3632Return as a value in @var{%store-monad} the derivation or store item
3633corresponding to @var{obj} for @var{system}, cross-compiling for
3634@var{target} if @var{target} is true. @var{obj} must be an object that
3635has an associated gexp compiler, such as a @code{<package>}.
3636@end deffn
3637
21b679f6 3638
568717fd
LC
3639@c *********************************************************************
3640@node Utilities
3641@chapter Utilities
3642
210cc920
LC
3643This section describes tools primarily targeted at developers and users
3644who write new package definitions. They complement the Scheme
3645programming interface of Guix in a convenient way.
3646
568717fd 3647@menu
37166310 3648* Invoking guix build:: Building packages from the command line.
39bee8a2 3649* Invoking guix edit:: Editing package definitions.
210cc920 3650* Invoking guix download:: Downloading a file and printing its hash.
37166310 3651* Invoking guix hash:: Computing the cryptographic hash of a file.
2f7d2d91 3652* Invoking guix import:: Importing package definitions.
37166310 3653* Invoking guix refresh:: Updating package definitions.
b4f5e0e8 3654* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 3655* Invoking guix size:: Profiling disk usage.
88856916 3656* Invoking guix graph:: Visualizing the graph of packages.
372c4bbc 3657* Invoking guix environment:: Setting up development environments.
aff8ce7c 3658* Invoking guix publish:: Sharing substitutes.
d23c20f1 3659* Invoking guix challenge:: Challenging substitute servers.
32efa254 3660* Invoking guix container:: Process isolation.
568717fd
LC
3661@end menu
3662
e49951eb
MW
3663@node Invoking guix build
3664@section Invoking @command{guix build}
568717fd 3665
e49951eb 3666The @command{guix build} command builds packages or derivations and
6798a8e4
LC
3667their dependencies, and prints the resulting store paths. Note that it
3668does not modify the user's profile---this is the job of the
e49951eb 3669@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
3670it is mainly useful for distribution developers.
3671
3672The general syntax is:
c78bd12b
LC
3673
3674@example
e49951eb 3675guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
3676@end example
3677
3678@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
3679the software distribution such as @code{coreutils} or
3680@code{coreutils-8.20}, or a derivation such as
834129e0 3681@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
3682package with the corresponding name (and optionally version) is searched
3683for among the GNU distribution modules (@pxref{Package Modules}).
3684
3685Alternatively, the @code{--expression} option may be used to specify a
3686Scheme expression that evaluates to a package; this is useful when
3687disambiguation among several same-named packages or package variants is
3688needed.
c78bd12b
LC
3689
3690The @var{options} may be zero or more of the following:
3691
3692@table @code
3693
34a1783f
DT
3694@item --file=@var{file}
3695@itemx -f @var{file}
3696
3697Build the package or derivation that the code within @var{file}
3698evaluates to.
3699
3700As an example, @var{file} might contain a package definition like this
3701(@pxref{Defining Packages}):
3702
3703@example
3704@verbatiminclude package-hello.scm
3705@end example
3706
c78bd12b
LC
3707@item --expression=@var{expr}
3708@itemx -e @var{expr}
ac5de156 3709Build the package or derivation @var{expr} evaluates to.
c78bd12b 3710
5401dd75 3711For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
3712guile-1.8)}, which unambiguously designates this specific variant of
3713version 1.8 of Guile.
3714
56b82106
LC
3715Alternately, @var{expr} may be a G-expression, in which case it is used
3716as a build program passed to @code{gexp->derivation}
3717(@pxref{G-Expressions}).
3718
3719Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
3720(@pxref{The Store Monad}). The procedure must return a derivation as a
3721monadic value, which is then passed through @code{run-with-store}.
3722
c78bd12b
LC
3723@item --source
3724@itemx -S
3725Build the packages' source derivations, rather than the packages
3726themselves.
3727
e49951eb 3728For instance, @code{guix build -S gcc} returns something like
834129e0 3729@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
c78bd12b 3730
f9cc8971
LC
3731The returned source tarball is the result of applying any patches and
3732code snippets specified in the package's @code{origin} (@pxref{Defining
3733Packages}).
3734
2cdfe13d
EB
3735@item --sources
3736Fetch and return the source of @var{package-or-derivation} and all their
3737dependencies, recursively. This is a handy way to obtain a local copy
3738of all the source code needed to build @var{packages}, allowing you to
3739eventually build them even without network access. It is an extension
3740of the @code{--source} option and can accept one of the following
3741optional argument values:
3742
3743@table @code
3744@item package
3745This value causes the @code{--sources} option to behave in the same way
3746as the @code{--source} option.
3747
3748@item all
3749Build all packages' source derivations, including any source that might
3750be listed as @code{inputs}. This is the default value.
3751
3752@example
3753$ guix build --sources tzdata
3754The following derivations will be built:
3755 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
3756 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
3757@end example
3758
3759@item transitive
3760Build all packages' source derivations, as well as all source
3761derivations for packages' transitive inputs. This can be used e.g. to
3762prefetch package source for later offline building.
3763
3764@example
3765$ guix build --sources=transitive tzdata
3766The following derivations will be built:
3767 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
3768 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
3769 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
3770 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
3771 /gnu/store/@dots{}-make-4.1.tar.xz.drv
3772 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
3773@dots{}
3774@end example
3775
3776@end table
3777
c78bd12b
LC
3778@item --system=@var{system}
3779@itemx -s @var{system}
3780Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
3781the host's system type.
3782
3783An example use of this is on Linux-based systems, which can emulate
3784different personalities. For instance, passing
3785@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
3786to build packages in a complete 32-bit environment.
3787
e55ec43d
LC
3788@item --target=@var{triplet}
3789@cindex cross-compilation
3790Cross-build for @var{triplet}, which must be a valid GNU triplet, such
3791as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
3792configuration triplets,, configure, GNU Configure and Build System}).
3793
7f3673f2
LC
3794@item --with-source=@var{source}
3795Use @var{source} as the source of the corresponding package.
3796@var{source} must be a file name or a URL, as for @command{guix
3797download} (@pxref{Invoking guix download}).
3798
3799The ``corresponding package'' is taken to be one specified on the
3800command line whose name matches the base of @var{source}---e.g., if
3801@var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
3802package is @code{guile}. Likewise, the version string is inferred from
3803@var{source}; in the previous example, it's @code{2.0.10}.
3804
3805This option allows users to try out versions of packages other than the
3806one provided by the distribution. The example below downloads
3807@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
3808the @code{ed} package:
3809
3810@example
3811guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
3812@end example
3813
3814As a developer, @code{--with-source} makes it easy to test release
3815candidates:
3816
3817@example
3818guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
3819@end example
3820
a43b55f1
LC
3821@dots{} or to build from a checkout in a pristine environment:
3822
3823@example
3824$ git clone git://git.sv.gnu.org/guix.git
3825$ guix build guix --with-source=./guix
3826@end example
3827
a8d65643
LC
3828@anchor{build-check}
3829@item --check
3830@cindex determinism, checking
3831@cindex reproducibility, checking
3832Rebuild @var{package-or-derivation}, which are already available in the
3833store, and raise an error if the build results are not bit-for-bit
3834identical.
3835
3836This mechanism allows you to check whether previously-installed
3837substitutes are genuine (@pxref{Substitutes}), or whether a package's
3838build result is deterministic. @xref{Invoking guix challenge}, for more
3839background information and tools.
3840
05962f29
LC
3841@item --no-grafts
3842Do not ``graft'' packages. In practice, this means that package updates
3843available as grafts are not applied. @xref{Security Updates}, for more
3844information on grafts.
7f3673f2 3845
c78bd12b
LC
3846@item --derivations
3847@itemx -d
3848Return the derivation paths, not the output paths, of the given
3849packages.
3850
70ee5642
LC
3851@item --root=@var{file}
3852@itemx -r @var{file}
3853Make @var{file} a symlink to the result, and register it as a garbage
3854collector root.
3855
3856@item --log-file
3f208ad7 3857Return the build log file names or URLs for the given
70ee5642
LC
3858@var{package-or-derivation}s, or raise an error if build logs are
3859missing.
3860
3861This works regardless of how packages or derivations are specified. For
3862instance, the following invocations are equivalent:
3863
3864@example
3865guix build --log-file `guix build -d guile`
3866guix build --log-file `guix build guile`
3867guix build --log-file guile
3868guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
3869@end example
3870
3f208ad7
LC
3871If a log is unavailable locally, and unless @code{--no-substitutes} is
3872passed, the command looks for a corresponding log on one of the
3873substitute servers (as specified with @code{--substitute-urls}.)
70ee5642 3874
3f208ad7
LC
3875So for instance, let's say you want to see the build log of GDB on MIPS
3876but you're actually on an @code{x86_64} machine:
3877
3878@example
3879$ guix build --log-file gdb -s mips64el-linux
3880http://hydra.gnu.org/log/@dots{}-gdb-7.10
3881@end example
3882
3883You can freely access a huge library of build logs!
70ee5642
LC
3884@end table
3885
3886@cindex common build options
3887In addition, a number of options that control the build process are
3888common to @command{guix build} and other commands that can spawn builds,
3889such as @command{guix package} or @command{guix archive}. These are the
3890following:
3891
3892@table @code
3893
300868ba
LC
3894@item --load-path=@var{directory}
3895@itemx -L @var{directory}
3896Add @var{directory} to the front of the package module search path
3897(@pxref{Package Modules}).
3898
3899This allows users to define their own packages and make them visible to
3900the command-line tools.
3901
c78bd12b
LC
3902@item --keep-failed
3903@itemx -K
3904Keep the build tree of failed builds. Thus, if a build fail, its build
3905tree is kept under @file{/tmp}, in a directory whose name is shown at
3906the end of the build log. This is useful when debugging build issues.
3907
3908@item --dry-run
3909@itemx -n
3910Do not build the derivations.
3911
56b1f4b7
LC
3912@item --fallback
3913When substituting a pre-built binary fails, fall back to building
3914packages locally.
3915
f8a8e0fe
LC
3916@item --substitute-urls=@var{urls}
3917@anchor{client-substitute-urls}
3918Consider @var{urls} the whitespace-separated list of substitute source
3919URLs, overriding the default list of URLs of @command{guix-daemon}
3920(@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
3921
3922This means that substitutes may be downloaded from @var{urls}, provided
3923they are signed by a key authorized by the system administrator
3924(@pxref{Substitutes}).
3925
c78bd12b 3926@item --no-substitutes
b5385b52 3927Do not use substitutes for build products. That is, always build things
c4202d60
LC
3928locally instead of allowing downloads of pre-built binaries
3929(@pxref{Substitutes}).
c78bd12b 3930
5b74fe06
LC
3931@item --rounds=@var{n}
3932Build each derivation @var{n} times in a row, and raise an error if
3933consecutive build results are not bit-for-bit identical.
3934
3935This is a useful way to detect non-deterministic builds processes.
3936Non-deterministic build processes are a problem because they make it
3937practically impossible for users to @emph{verify} whether third-party
3938binaries are genuine. @xref{Invoking guix challenge}, for more.
3939
3940Note that, currently, the differing build results are not kept around,
3941so you will have to manually investigate in case of an error---e.g., by
3942stashing one of the build results with @code{guix archive --export},
3943then rebuilding, and finally comparing the two results.
3944
425b0bfc 3945@item --no-build-hook
4ec2e92d
LC
3946Do not attempt to offload builds @i{via} the daemon's ``build hook''
3947(@pxref{Daemon Offload Setup}). That is, always build things locally
3948instead of offloading builds to remote machines.
425b0bfc 3949
969e678e
LC
3950@item --max-silent-time=@var{seconds}
3951When the build or substitution process remains silent for more than
3952@var{seconds}, terminate it and report a build failure.
3953
002622b6
LC
3954@item --timeout=@var{seconds}
3955Likewise, when the build or substitution process lasts for more than
3956@var{seconds}, terminate it and report a build failure.
3957
3958By default there is no timeout. This behavior can be restored with
3959@code{--timeout=0}.
3960
07ab4bf1
LC
3961@item --verbosity=@var{level}
3962Use the given verbosity level. @var{level} must be an integer between 0
3963and 5; higher means more verbose output. Setting a level of 4 or more
3964may be helpful when debugging setup issues with the build daemon.
3965
70ee5642
LC
3966@item --cores=@var{n}
3967@itemx -c @var{n}
3968Allow the use of up to @var{n} CPU cores for the build. The special
3969value @code{0} means to use as many CPU cores as available.
bf421152 3970
f6526eb3
LC
3971@item --max-jobs=@var{n}
3972@itemx -M @var{n}
3973Allow at most @var{n} build jobs in parallel. @xref{Invoking
3974guix-daemon, @code{--max-jobs}}, for details about this option and the
3975equivalent @command{guix-daemon} option.
3976
c78bd12b
LC
3977@end table
3978
e49951eb 3979Behind the scenes, @command{guix build} is essentially an interface to
c78bd12b
LC
3980the @code{package-derivation} procedure of the @code{(guix packages)}
3981module, and to the @code{build-derivations} procedure of the @code{(guix
01d8ac64 3982derivations)} module.
c78bd12b 3983
16eb115e
DP
3984In addition to options explicitly passed on the command line,
3985@command{guix build} and other @command{guix} commands that support
3986building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
3987
3988@defvr {Environment Variable} GUIX_BUILD_OPTIONS
3989Users can define this variable to a list of command line options that
3990will automatically be used by @command{guix build} and other
3991@command{guix} commands that can perform builds, as in the example
3992below:
3993
3994@example
3995$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
3996@end example
3997
847391fe
DP
3998These options are parsed independently, and the result is appended to
3999the parsed command-line options.
16eb115e
DP
4000@end defvr
4001
4002
39bee8a2
LC
4003@node Invoking guix edit
4004@section Invoking @command{guix edit}
4005
4006@cindex package definition, editing
4007So many packages, so many source files! The @command{guix edit} command
4008facilitates the life of packagers by pointing their editor at the source
4009file containing the definition of the specified packages. For instance:
4010
4011@example
4012guix edit gcc-4.8 vim
4013@end example
4014
4015@noindent
6237b9fa
LC
4016launches the program specified in the @code{VISUAL} or in the
4017@code{EDITOR} environment variable to edit the recipe of GCC@tie{}4.8.4
4018and that of Vim.
39bee8a2
LC
4019
4020If you are using Emacs, note that the Emacs user interface provides
6248e326
AK
4021similar functionality in the ``package info'' and ``package list''
4022buffers created by @kbd{M-x guix-search-by-name} and similar commands
4023(@pxref{Emacs Commands}).
39bee8a2
LC
4024
4025
210cc920
LC
4026@node Invoking guix download
4027@section Invoking @command{guix download}
4028
4029When writing a package definition, developers typically need to download
4030the package's source tarball, compute its SHA256 hash, and write that
4031hash in the package definition (@pxref{Defining Packages}). The
4032@command{guix download} tool helps with this task: it downloads a file
4033from the given URI, adds it to the store, and prints both its file name
4034in the store and its SHA256 hash.
4035
4036The fact that the downloaded file is added to the store saves bandwidth:
4037when the developer eventually tries to build the newly defined package
4038with @command{guix build}, the source tarball will not have to be
4039downloaded again because it is already in the store. It is also a
4040convenient way to temporarily stash files, which may be deleted
4041eventually (@pxref{Invoking guix gc}).
4042
4043The @command{guix download} command supports the same URIs as used in
4044package definitions. In particular, it supports @code{mirror://} URIs.
4045@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
4046Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
4047they are not available, an error is raised. @xref{Guile Preparations,
4048how to install the GnuTLS bindings for Guile,, gnutls-guile,
4049GnuTLS-Guile}, for more information.
210cc920
LC
4050
4051The following option is available:
4052
4053@table @code
4054@item --format=@var{fmt}
4055@itemx -f @var{fmt}
4056Write the hash in the format specified by @var{fmt}. For more
081145cf 4057information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
210cc920
LC
4058@end table
4059
6c365eca
NK
4060@node Invoking guix hash
4061@section Invoking @command{guix hash}
4062
210cc920 4063The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
4064It is primarily a convenience tool for anyone contributing to the
4065distribution: it computes the cryptographic hash of a file, which can be
4066used in the definition of a package (@pxref{Defining Packages}).
4067
4068The general syntax is:
4069
4070@example
4071guix hash @var{option} @var{file}
4072@end example
4073
4074@command{guix hash} has the following option:
4075
4076@table @code
4077
4078@item --format=@var{fmt}
4079@itemx -f @var{fmt}
210cc920 4080Write the hash in the format specified by @var{fmt}.
6c365eca
NK
4081
4082Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4083(@code{hex} and @code{hexadecimal} can be used as well).
4084
4085If the @option{--format} option is not specified, @command{guix hash}
4086will output the hash in @code{nix-base32}. This representation is used
4087in the definitions of packages.
4088
3140f2df
LC
4089@item --recursive
4090@itemx -r
4091Compute the hash on @var{file} recursively.
4092
4093In this case, the hash is computed on an archive containing @var{file},
4094including its children if it is a directory. Some of @var{file}'s
4095meta-data is part of the archive; for instance, when @var{file} is a
4096regular file, the hash is different depending on whether @var{file} is
4097executable or not. Meta-data such as time stamps has no impact on the
4098hash (@pxref{Invoking guix archive}).
4099@c FIXME: Replace xref above with xref to an ``Archive'' section when
4100@c it exists.
4101
6c365eca
NK
4102@end table
4103
2f7d2d91
LC
4104@node Invoking guix import
4105@section Invoking @command{guix import}
4106
4107@cindex importing packages
4108@cindex package import
4109@cindex package conversion
4110The @command{guix import} command is useful for people willing to add a
4111package to the distribution but who'd rather do as little work as
4112possible to get there---a legitimate demand. The command knows of a few
4113repositories from which it can ``import'' package meta-data. The result
4114is a package definition, or a template thereof, in the format we know
4115(@pxref{Defining Packages}).
4116
4117The general syntax is:
4118
4119@example
4120guix import @var{importer} @var{options}@dots{}
4121@end example
4122
4123@var{importer} specifies the source from which to import package
4124meta-data, and @var{options} specifies a package identifier and other
4125options specific to @var{importer}. Currently, the available
4126``importers'' are:
4127
4128@table @code
4129@item gnu
4130Import meta-data for the given GNU package. This provides a template
4131for the latest version of that GNU package, including the hash of its
4132source tarball, and its canonical synopsis and description.
4133
4134Additional information such as the package's dependencies and its
4135license needs to be figured out manually.
4136
4137For example, the following command returns a package definition for
4138GNU@tie{}Hello:
4139
4140@example
4141guix import gnu hello
4142@end example
4143
4144Specific command-line options are:
4145
4146@table @code
4147@item --key-download=@var{policy}
4148As for @code{guix refresh}, specify the policy to handle missing OpenPGP
4149keys when verifying the package's signature. @xref{Invoking guix
4150refresh, @code{--key-download}}.
4151@end table
4152
4153@item pypi
4154@cindex pypi
4155Import meta-data from the @uref{https://pypi.python.org/, Python Package
4156Index}@footnote{This functionality requires Guile-JSON to be installed.
4157@xref{Requirements}.}. Information is taken from the JSON-formatted
4158description available at @code{pypi.python.org} and usually includes all
4159the relevant information, including package dependencies.
4160
4161The command below imports meta-data for the @code{itsdangerous} Python
4162package:
4163
4164@example
4165guix import pypi itsdangerous
4166@end example
4167
3aae8145
DT
4168@item gem
4169@cindex gem
4170Import meta-data from @uref{https://rubygems.org/,
4171RubyGems}@footnote{This functionality requires Guile-JSON to be
4172installed. @xref{Requirements}.}. Information is taken from the
4173JSON-formatted description available at @code{rubygems.org} and includes
4174most relevant information, including runtime dependencies. There are
4175some caveats, however. The meta-data doesn't distinguish between
4176synopses and descriptions, so the same string is used for both fields.
4177Additionally, the details of non-Ruby dependencies required to build
4178native extensions is unavailable and left as an exercise to the
4179packager.
4180
4181The command below imports meta-data for the @code{rails} Ruby package:
4182
4183@example
4184guix import gem rails
4185@end example
4186
d45dc6da
EB
4187@item cpan
4188@cindex CPAN
4189Import meta-data from @uref{https://www.metacpan.org/, MetaCPAN}.
4190Information is taken from the JSON-formatted meta-data provided through
4191@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
4192relevant information, such as module dependencies. License information
4193should be checked closely. If Perl is available in the store, then the
4194@code{corelist} utility will be used to filter core modules out of the
4195list of dependencies.
d45dc6da
EB
4196
4197The command command below imports meta-data for the @code{Acme::Boolean}
4198Perl module:
4199
4200@example
4201guix import cpan Acme::Boolean
4202@end example
4203
e1248602
RW
4204@item cran
4205@cindex CRAN
4206Import meta-data from @uref{http://cran.r-project.org/, CRAN}, the
4207central repository for the @uref{http://r-project.org, GNU@tie{}R
4208statistical and graphical environment}.
4209
b1186502 4210Information is extracted from the package's DESCRIPTION file.
e1248602
RW
4211
4212The command command below imports meta-data for the @code{Cairo}
4213R package:
4214
4215@example
4216guix import cran Cairo
4217@end example
4218
2f7d2d91
LC
4219@item nix
4220Import meta-data from a local copy of the source of the
4221@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
4222relies on the @command{nix-instantiate} command of
4223@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
4224typically written in a mixture of Nix-language and Bash code. This
4225command only imports the high-level package structure that is written in
4226the Nix language. It normally includes all the basic fields of a
4227package definition.
4228
4229When importing a GNU package, the synopsis and descriptions are replaced
4230by their canonical upstream variant.
4231
961d0d2d
LC
4232Usually, you will first need to do:
4233
4234@example
4235export NIX_REMOTE=daemon
4236@end example
4237
4238@noindent
4239so that @command{nix-instantiate} does not try to open the Nix database.
4240
2f7d2d91
LC
4241As an example, the command below imports the package definition of
4242LibreOffice (more precisely, it imports the definition of the package
4243bound to the @code{libreoffice} top-level attribute):
4244
4245@example
4246guix import nix ~/path/to/nixpkgs libreoffice
4247@end example
863af4e1
FB
4248
4249@item hackage
4250@cindex hackage
4251Import meta-data from Haskell community's central package archive
4252@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4253Cabal files and includes all the relevant information, including package
4254dependencies.
4255
4256Specific command-line options are:
4257
4258@table @code
a4154748
FB
4259@item --stdin
4260@itemx -s
4261Read a Cabal file from the standard input.
863af4e1
FB
4262@item --no-test-dependencies
4263@itemx -t
a4154748
FB
4264Do not include dependencies required by the test suites only.
4265@item --cabal-environment=@var{alist}
4266@itemx -e @var{alist}
4267@var{alist} is a Scheme alist defining the environment in which the
4268Cabal conditionals are evaluated. The accepted keys are: @code{os},
4269@code{arch}, @code{impl} and a string representing the name of a flag.
4270The value associated with a flag has to be either the symbol
4271@code{true} or @code{false}. The value associated with other keys
4272has to conform to the Cabal file format definition. The default value
4273associated with the keys @code{os}, @code{arch} and @code{impl} is
4274@samp{linux}, @samp{x86_64} and @samp{ghc} respectively.
863af4e1
FB
4275@end table
4276
4277The command below imports meta-data for the latest version of the
a4154748
FB
4278@code{HTTP} Haskell package without including test dependencies and
4279specifying the value of the flag @samp{network-uri} as @code{false}:
863af4e1
FB
4280
4281@example
a4154748 4282guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
863af4e1
FB
4283@end example
4284
4285A specific package version may optionally be specified by following the
4286package name by a hyphen and a version number as in the following example:
4287
4288@example
4289guix import hackage mtl-2.1.3.1
4290@end example
7f74a931
FB
4291
4292@item elpa
4293@cindex elpa
4294Import meta-data from an Emacs Lisp Package Archive (ELPA) package
4295repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4296
4297Specific command-line options are:
4298
4299@table @code
4300@item --archive=@var{repo}
4301@itemx -a @var{repo}
4302@var{repo} identifies the archive repository from which to retrieve the
4303information. Currently the supported repositories and their identifiers
4304are:
4305@itemize -
4306@item
840bd1d3 4307@uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7f74a931
FB
4308identifier. This is the default.
4309
4310@item
840bd1d3 4311@uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7f74a931
FB
4312@code{melpa-stable} identifier.
4313
4314@item
840bd1d3 4315@uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7f74a931
FB
4316identifier.
4317@end itemize
4318@end table
2f7d2d91
LC
4319@end table
4320
4321The structure of the @command{guix import} code is modular. It would be
4322useful to have more importers for other package formats, and your help
4323is welcome here (@pxref{Contributing}).
4324
37166310
LC
4325@node Invoking guix refresh
4326@section Invoking @command{guix refresh}
4327
4328The primary audience of the @command{guix refresh} command is developers
4329of the GNU software distribution. By default, it reports any packages
4330provided by the distribution that are outdated compared to the latest
4331upstream version, like this:
4332
4333@example
4334$ guix refresh
4335gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
4336gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
4337@end example
4338
4339It does so by browsing each package's FTP directory and determining the
bcb571cb
LC
4340highest version number of the source tarballs therein. The command
4341knows how to update specific types of packages: GNU packages, ELPA
4342packages, etc.---see the documentation for @option{--type} below. The
4343are many packages, though, for which it lacks a method to determine
4344whether a new upstream release is available. However, the mechanism is
4345extensible, so feel free to get in touch with us to add a new method!
37166310
LC
4346
4347When passed @code{--update}, it modifies distribution source files to
4348update the version numbers and source tarball hashes of those packages'
4349recipes (@pxref{Defining Packages}). This is achieved by downloading
4350each package's latest source tarball and its associated OpenPGP
4351signature, authenticating the downloaded tarball against its signature
4352using @command{gpg}, and finally computing its hash. When the public
4353key used to sign the tarball is missing from the user's keyring, an
4354attempt is made to automatically retrieve it from a public key server;
4355when it's successful, the key is added to the user's keyring; otherwise,
4356@command{guix refresh} reports an error.
4357
4358The following options are supported:
4359
4360@table @code
4361
2d7fc7da
LC
4362@item --expression=@var{expr}
4363@itemx -e @var{expr}
4364Consider the package @var{expr} evaluates to.
4365
4366This is useful to precisely refer to a package, as in this example:
4367
4368@example
4369guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
4370@end example
4371
4372This command lists the dependents of the ``final'' libc (essentially all
4373the packages.)
4374
37166310
LC
4375@item --update
4376@itemx -u
38e16b49
LC
4377Update distribution source files (package recipes) in place. This is
4378usually run from a checkout of the Guix source tree (@pxref{Running
4379Guix Before It Is Installed}):
4380
4381@example
4382$ ./pre-inst-env guix refresh -s non-core
4383@end example
4384
081145cf 4385@xref{Defining Packages}, for more information on package definitions.
37166310
LC
4386
4387@item --select=[@var{subset}]
4388@itemx -s @var{subset}
4389Select all the packages in @var{subset}, one of @code{core} or
4390@code{non-core}.
4391
4392The @code{core} subset refers to all the packages at the core of the
4393distribution---i.e., packages that are used to build ``everything
4394else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
4395changing one of these packages in the distribution entails a rebuild of
4396all the others. Thus, such updates are an inconvenience to users in
4397terms of build time or bandwidth used to achieve the upgrade.
4398
4399The @code{non-core} subset refers to the remaining packages. It is
4400typically useful in cases where an update of the core packages would be
4401inconvenient.
4402
bcb571cb
LC
4403@item --type=@var{updater}
4404@itemx -t @var{updater}
7191adc5
AK
4405Select only packages handled by @var{updater} (may be a comma-separated
4406list of updaters). Currently, @var{updater} may be one of:
bcb571cb
LC
4407
4408@table @code
4409@item gnu
4410the updater for GNU packages;
e80c0f85
LC
4411@item gnome
4412the updater for GNOME packages;
bcb571cb 4413@item elpa
d882c235
LC
4414the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
4415@item cran
b9d044ef 4416the updater for @uref{http://cran.r-project.org/, CRAN} packages;
bab020d7 4417@item pypi
b9d044ef 4418the updater for @uref{https://pypi.python.org, PyPI} packages.
bcb571cb
LC
4419@end table
4420
4421For instance, the following commands only checks for updates of Emacs
d882c235 4422packages hosted at @code{elpa.gnu.org} and updates of CRAN packages:
bcb571cb
LC
4423
4424@example
7191adc5 4425$ guix refresh --type=elpa,cran
d882c235 4426gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
bcb571cb
LC
4427gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
4428@end example
4429
37166310
LC
4430@end table
4431
4432In addition, @command{guix refresh} can be passed one or more package
4433names, as in this example:
4434
4435@example
38e16b49 4436$ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
37166310
LC
4437@end example
4438
4439@noindent
4440The command above specifically updates the @code{emacs} and
4441@code{idutils} packages. The @code{--select} option would have no
4442effect in this case.
4443
7d193ec3
EB
4444When considering whether to upgrade a package, it is sometimes
4445convenient to know which packages would be affected by the upgrade and
4446should be checked for compatibility. For this the following option may
4447be used when passing @command{guix refresh} one or more package names:
4448
4449@table @code
4450
6ffa706b
AK
4451@item --list-updaters
4452@itemx -L
4453List available updaters and exit (see @option{--type} above.)
4454
7d193ec3
EB
4455@item --list-dependent
4456@itemx -l
4457List top-level dependent packages that would need to be rebuilt as a
4458result of upgrading one or more packages.
4459
4460@end table
4461
4462Be aware that the @code{--list-dependent} option only
4463@emph{approximates} the rebuilds that would be required as a result of
4464an upgrade. More rebuilds might be required under some circumstances.
4465
4466@example
7779ab61
LC
4467$ guix refresh --list-dependent flex
4468Building the following 120 packages would ensure 213 dependent packages are rebuilt:
4469hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
4470@end example
4471
4472The command above lists a set of packages that could be built to check
4473for compatibility with an upgraded @code{flex} package.
4474
f9230085
LC
4475The following options can be used to customize GnuPG operation:
4476
4477@table @code
4478
f9230085
LC
4479@item --gpg=@var{command}
4480Use @var{command} as the GnuPG 2.x command. @var{command} is searched
4481for in @code{$PATH}.
4482
2bc53ba9
LC
4483@item --key-download=@var{policy}
4484Handle missing OpenPGP keys according to @var{policy}, which may be one
4485of:
4486
4487@table @code
4488@item always
4489Always download missing OpenPGP keys from the key server, and add them
4490to the user's GnuPG keyring.
4491
4492@item never
4493Never try to download missing OpenPGP keys. Instead just bail out.
4494
4495@item interactive
4496When a package signed with an unknown OpenPGP key is encountered, ask
4497the user whether to download it or not. This is the default behavior.
4498@end table
4499
4500@item --key-server=@var{host}
4501Use @var{host} as the OpenPGP key server when importing a public key.
4502
f9230085
LC
4503@end table
4504
b4f5e0e8
CR
4505@node Invoking guix lint
4506@section Invoking @command{guix lint}
4507The @command{guix lint} is meant to help package developers avoid common
873c4085
LC
4508errors and use a consistent style. It runs a number of checks on a
4509given set of packages in order to find common mistakes in their
4510definitions. Available @dfn{checkers} include (see
4511@code{--list-checkers} for a complete list):
4512
4513@table @code
4514@item synopsis
4515@itemx description
4516Validate certain typographical and stylistic rules about package
4517descriptions and synopses.
4518
4519@item inputs-should-be-native
4520Identify inputs that should most likely be native inputs.
4521
4522@item source
4523@itemx home-page
50f5c46d 4524@itemx source-file-name
873c4085 4525Probe @code{home-page} and @code{source} URLs and report those that are
50f5c46d
EB
4526invalid. Check that the source file name is meaningful, e.g. is not
4527just a version number or ``git-checkout'', and should not have a
4528@code{file-name} declared (@pxref{origin Reference}).
40a7d4e5 4529
5432734b
LC
4530@item cve
4531Report known vulnerabilities found in the Common Vulnerabilities and
4532Exposures (CVE) database
4533@uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
4534NIST}.
4535
40a7d4e5
LC
4536@item formatting
4537Warn about obvious source code formatting issues: trailing white space,
4538use of tabulations, etc.
873c4085 4539@end table
b4f5e0e8
CR
4540
4541The general syntax is:
4542
4543@example
4544guix lint @var{options} @var{package}@dots{}
4545@end example
4546
4547If no package is given on the command line, then all packages are checked.
4548The @var{options} may be zero or more of the following:
4549
4550@table @code
4551
dd7c013d
CR
4552@item --checkers
4553@itemx -c
4554Only enable the checkers specified in a comma-separated list using the
4555names returned by @code{--list-checkers}.
4556
b4f5e0e8
CR
4557@item --list-checkers
4558@itemx -l
4559List and describe all the available checkers that will be run on packages
4560and exit.
4561
4562@end table
37166310 4563
fcc58db6
LC
4564@node Invoking guix size
4565@section Invoking @command{guix size}
4566
4567The @command{guix size} command helps package developers profile the
4568disk usage of packages. It is easy to overlook the impact of an
4569additional dependency added to a package, or the impact of using a
4570single output for a package that could easily be split (@pxref{Packages
4571with Multiple Outputs}). These are the typical issues that
4572@command{guix size} can highlight.
4573
4574The command can be passed a package specification such as @code{gcc-4.8}
4575or @code{guile:debug}, or a file name in the store. Consider this
4576example:
4577
4578@example
4579$ guix size coreutils
4580store item total self
4581/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
4582/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
4583/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
4584/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
4585/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
4586/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
4587@end example
4588
4589@cindex closure
4590The store items listed here constitute the @dfn{transitive closure} of
4591Coreutils---i.e., Coreutils and all its dependencies, recursively---as
4592would be returned by:
4593
4594@example
4595$ guix gc -R /gnu/store/@dots{}-coreutils-8.23
4596@end example
4597
4598Here the output shows 3 columns next to store items. The first column,
4599labeled ``total'', shows the size in mebibytes (MiB) of the closure of
4600the store item---that is, its own size plus the size of all its
4601dependencies. The next column, labeled ``self'', shows the size of the
4602item itself. The last column shows the ratio of the item's size to the
4603space occupied by all the items listed here.
4604
4605In this example, we see that the closure of Coreutils weighs in at
460670@tie{}MiB, half of which is taken by libc. (That libc represents a
4607large fraction of the closure is not a problem @i{per se} because it is
4608always available on the system anyway.)
4609
4610When the package passed to @command{guix size} is available in the
4611store, @command{guix size} queries the daemon to determine its
4612dependencies, and measures its size in the store, similar to @command{du
4613-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
4614Coreutils}).
4615
4616When the given package is @emph{not} in the store, @command{guix size}
4617reports information based on information about the available substitutes
4618(@pxref{Substitutes}). This allows it to profile disk usage of store
4619items that are not even on disk, only available remotely.
4620
a8f996c6 4621The available options are:
fcc58db6
LC
4622
4623@table @option
4624
d490d06e
LC
4625@item --substitute-urls=@var{urls}
4626Use substitute information from @var{urls}.
4627@xref{client-substitute-urls, the same option for @code{guix build}}.
4628
a8f996c6
LC
4629@item --map-file=@var{file}
4630Write to @var{file} a graphical map of disk usage as a PNG file.
4631
4632For the example above, the map looks like this:
4633
4634@image{images/coreutils-size-map,5in,, map of Coreutils disk usage
4635produced by @command{guix size}}
4636
4637This option requires that
4638@uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
4639installed and visible in Guile's module search path. When that is not
4640the case, @command{guix size} fails as it tries to load it.
4641
fcc58db6
LC
4642@item --system=@var{system}
4643@itemx -s @var{system}
4644Consider packages for @var{system}---e.g., @code{x86_64-linux}.
4645
4646@end table
4647
88856916
LC
4648@node Invoking guix graph
4649@section Invoking @command{guix graph}
4650
4651@cindex DAG
4652Packages and their dependencies form a @dfn{graph}, specifically a
4653directed acyclic graph (DAG). It can quickly become difficult to have a
4654mental model of the package DAG, so the @command{guix graph} command is
4655here to provide a visual representation of the DAG. @command{guix
4656graph} emits a DAG representation in the input format of
4657@uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
4658directly to Graphviz's @command{dot} command, for instance. The general
4659syntax is:
4660
4661@example
4662guix graph @var{options} @var{package}@dots{}
4663@end example
4664
4665For example, the following command generates a PDF file representing the
4666package DAG for the GNU@tie{}Core Utilities, showing its build-time
4667dependencies:
4668
4669@example
4670guix graph coreutils | dot -Tpdf > dag.pdf
4671@end example
4672
4673The output looks like this:
4674
4675@image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
4676
4677Nice little graph, no?
4678
4679But there's more than one graph! The one above is concise: it's the
4680graph of package objects, omitting implicit inputs such as GCC, libc,
4681grep, etc. It's often useful to have such a concise graph, but
4682sometimes you want to see more details. @command{guix graph} supports
4683several types of graphs, allowing you to choose the level of details:
4684
4685@table @code
4686@item package
4687This is the default type, the one we used above. It shows the DAG of
4688package objects, excluding implicit dependencies. It is concise, but
4689filters out many details.
4690
4691@item bag-emerged
4692This is the package DAG, @emph{including} implicit inputs.
4693
4694For instance, the following command:
4695
4696@example
4697guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
4698@end example
4699
4700... yields this bigger graph:
4701
4702@image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
4703
4704At the bottom of the graph, we see all the implicit inputs of
4705@var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
4706
4707Now, note that the dependencies of those implicit inputs---that is, the
4708@dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
4709here, for conciseness.
4710
4711@item bag
4712Similar to @code{bag-emerged}, but this time including all the bootstrap
4713dependencies.
4714
38b92daa
LC
4715@item bag-with-origins
4716Similar to @code{bag}, but also showing origins and their dependencies.
4717
88856916
LC
4718@item derivations
4719This is the most detailed representation: It shows the DAG of
4720derivations (@pxref{Derivations}) and plain store items. Compared to
4721the above representation, many additional nodes are visible, including
4722builds scripts, patches, Guile modules, etc.
4723
4724@end table
4725
4726All the above types correspond to @emph{build-time dependencies}. The
4727following graph type represents the @emph{run-time dependencies}:
4728
4729@table @code
4730@item references
4731This is the graph of @dfn{references} of a package output, as returned
4732by @command{guix gc --references} (@pxref{Invoking guix gc}).
4733
4734If the given package output is not available in the store, @command{guix
4735graph} attempts to obtain dependency information from substitutes.
4736@end table
4737
4738The available options are the following:
4739
4740@table @option
4741@item --type=@var{type}
4742@itemx -t @var{type}
4743Produce a graph output of @var{type}, where @var{type} must be one of
4744the values listed above.
4745
4746@item --list-types
4747List the supported graph types.
4c8f997a
LC
4748
4749@item --expression=@var{expr}
4750@itemx -e @var{expr}
4751Consider the package @var{expr} evaluates to.
4752
4753This is useful to precisely refer to a package, as in this example:
4754
4755@example
4756guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
4757@end example
88856916
LC
4758@end table
4759
4760
372c4bbc
DT
4761@node Invoking guix environment
4762@section Invoking @command{guix environment}
4763
f5fd4fd2 4764@cindex reproducible build environments
fe36d84e 4765@cindex development environments
372c4bbc
DT
4766The purpose of @command{guix environment} is to assist hackers in
4767creating reproducible development environments without polluting their
4768package profile. The @command{guix environment} tool takes one or more
4769packages, builds all of the necessary inputs, and creates a shell
4770environment to use them.
4771
4772The general syntax is:
4773
4774@example
4775guix environment @var{options} @var{package}@dots{}
4776@end example
4777
fe36d84e
LC
4778The following example spawns a new shell set up for the development of
4779GNU@tie{}Guile:
372c4bbc
DT
4780
4781@example
4782guix environment guile
4783@end example
4784
4785If the specified packages are not built yet, @command{guix environment}
4786automatically builds them. The new shell's environment is an augmented
4787version of the environment that @command{guix environment} was run in.
4788It contains the necessary search paths for building the given package
4789added to the existing environment variables. To create a ``pure''
4790environment in which the original environment variables have been unset,
50500f7c
LC
4791use the @code{--pure} option@footnote{Users sometimes wrongfully augment
4792environment variables such as @code{PATH} in their @file{~/.bashrc}
4793file. As a consequence, when @code{guix environment} launches it, Bash
4794may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
4795environment variables. It is an error to define such environment
4796variables in @file{.bashrc}; instead, they should be defined in
4797@file{.bash_profile}, which is sourced only by log-in shells.
4798@xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
4799details on Bash start-up files.}.
372c4bbc 4800
28de8d25
LC
4801@vindex GUIX_ENVIRONMENT
4802@command{guix environment} defines the @code{GUIX_ENVIRONMENT}
4803variable in the shell it spaws. This allows users to, say, define a
4804specific prompt for development environments in their @file{.bashrc}
4805(@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
4806
4807@example
4808if [ -n "$GUIX_ENVIRONMENT" ]
4809then
4810 export PS1="\u@@\h \w [dev]\$ "
4811fi
4812@end example
4813
372c4bbc
DT
4814Additionally, more than one package may be specified, in which case the
4815union of the inputs for the given packages are used. For example, the
4816command below spawns a shell where all of the dependencies of both Guile
4817and Emacs are available:
4818
4819@example
4820guix environment guile emacs
4821@end example
4822
1de2fe95
DT
4823Sometimes an interactive shell session is not desired. An arbitrary
4824command may be invoked by placing the @code{--} token to separate the
4825command from the rest of the arguments:
372c4bbc
DT
4826
4827@example
1de2fe95 4828guix environment guile -- make -j4
372c4bbc
DT
4829@end example
4830
fe36d84e
LC
4831In other situations, it is more convenient to specify the list of
4832packages needed in the environment. For example, the following command
4833runs @command{python} from an environment containing Python@tie{}2.7 and
4834NumPy:
4835
4836@example
1de2fe95 4837guix environment --ad-hoc python2-numpy python-2.7 -- python
fe36d84e
LC
4838@end example
4839
cc90fbbf
DT
4840Furthermore, one might want the dependencies of a package and also some
4841additional packages that are not build-time or runtime dependencies, but
4842are useful when developing nonetheless. Because of this, the
4843@code{--ad-hoc} flag is positional. Packages appearing before
4844@code{--ad-hoc} are interpreted as packages whose dependencies will be
4845added to the environment. Packages appearing after are interpreted as
4846packages that will be added to the environment directly. For example,
4847the following command creates a Guix development environment that
4848additionally includes Git and strace:
4849
4850@example
4851guix environment guix --ad-hoc git strace
4852@end example
4853
f535dcbe
DT
4854Sometimes it is desirable to isolate the environment as much as
4855possible, for maximal purity and reproducibility. In particular, when
4856using Guix on a host distro that is not GuixSD, it is desirable to
4857prevent access to @file{/usr/bin} and other system-wide resources from
4858the development environment. For example, the following command spawns
4859a Guile REPL in a ``container'' where only the store and the current
4860working directory are mounted:
4861
4862@example
4863guix environment --ad-hoc --container guile -- guile
4864@end example
4865
0f252e26 4866@quotation Note
cfd35b4e 4867The @code{--container} option requires Linux-libre 3.19 or newer.
0f252e26
DT
4868@end quotation
4869
fe36d84e 4870The available options are summarized below.
372c4bbc
DT
4871
4872@table @code
4873@item --expression=@var{expr}
4874@itemx -e @var{expr}
c9c282ce
DT
4875Create an environment for the package or list of packages that
4876@var{expr} evaluates to.
372c4bbc 4877
fe36d84e
LC
4878For example, running:
4879
4880@example
4881guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
4882@end example
4883
4884starts a shell with the environment for this specific variant of the
4885PETSc package.
4886
c9c282ce
DT
4887Running:
4888
4889@example
5c2b2f00 4890guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
c9c282ce
DT
4891@end example
4892
4893starts a shell with all the GuixSD base packages available.
4894
372c4bbc
DT
4895@item --load=@var{file}
4896@itemx -l @var{file}
c9c282ce
DT
4897Create an environment for the package or list of packages that the code
4898within @var{file} evaluates to.
372c4bbc 4899
fe36d84e
LC
4900As an example, @var{file} might contain a definition like this
4901(@pxref{Defining Packages}):
4902
4903@example
4904@verbatiminclude environment-gdb.scm
4905@end example
4906
a54bd6d7
DT
4907@item --ad-hoc
4908Include all specified packages in the resulting environment, as if an
4909@i{ad hoc} package were defined with them as inputs. This option is
4910useful for quickly creating an environment without having to write a
4911package expression to contain the desired inputs.
4912
4913For instance, the command:
4914
4915@example
1de2fe95 4916guix environment --ad-hoc guile guile-sdl -- guile
a54bd6d7
DT
4917@end example
4918
4919runs @command{guile} in an environment where Guile and Guile-SDL are
4920available.
4921
417c39f1
LC
4922Note that this example implicitly asks for the default output of
4923@code{guile} and @code{guile-sdl} but it is possible to ask for a
4924specific output---e.g., @code{glib:bin} asks for the @code{bin} output
4925of @code{glib} (@pxref{Packages with Multiple Outputs}).
4926
cc90fbbf
DT
4927This option may be composed with the default behavior of @command{guix
4928environment}. Packages appearing before @code{--ad-hoc} are interpreted
4929as packages whose dependencies will be added to the environment, the
4930default behavior. Packages appearing after are interpreted as packages
4931that will be added to the environment directly.
4932
372c4bbc
DT
4933@item --pure
4934Unset existing environment variables when building the new environment.
4935This has the effect of creating an environment in which search paths
4936only contain package inputs.
4937
4938@item --search-paths
4939Display the environment variable definitions that make up the
4940environment.
ce367ef3
LC
4941
4942@item --system=@var{system}
4943@itemx -s @var{system}
4944Attempt to build for @var{system}---e.g., @code{i686-linux}.
f535dcbe
DT
4945
4946@item --container
4947@itemx -C
4948@cindex container
4949Run @var{command} within an isolated container. The current working
56b6befb 4950directory outside the container is mapped inside the
f535dcbe
DT
4951container. Additionally, the spawned process runs as the current user
4952outside the container, but has root privileges in the context of the
4953container.
4954
4955@item --network
4956@itemx -N
4957For containers, share the network namespace with the host system.
4958Containers created without this flag only have access to the loopback
4959device.
4960
4961@item --expose=@var{source}[=@var{target}]
4962For containers, expose the file system @var{source} from the host system
4963as the read-only file system @var{target} within the container. If
4964@var{target} is not specified, @var{source} is used as the target mount
4965point in the container.
4966
4967The example below spawns a Guile REPL in a container in which the user's
4968home directory is accessible read-only via the @file{/exchange}
4969directory:
4970
4971@example
4972guix environment --container --expose=$HOME=/exchange guile -- guile
4973@end example
4974
5c2b2f00 4975@item --share=@var{source}[=@var{target}]
f535dcbe
DT
4976For containers, share the file system @var{source} from the host system
4977as the writable file system @var{target} within the container. If
4978@var{target} is not specified, @var{source} is used as the target mount
4979point in the container.
4980
4981The example below spawns a Guile REPL in a container in which the user's
4982home directory is accessible for both reading and writing via the
4983@file{/exchange} directory:
4984
4985@example
4986guix environment --container --share=$HOME=/exchange guile -- guile
4987@end example
372c4bbc
DT
4988@end table
4989
4990It also supports all of the common build options that @command{guix
4991build} supports (@pxref{Invoking guix build, common build options}).
4992
aff8ce7c
DT
4993@node Invoking guix publish
4994@section Invoking @command{guix publish}
4995
4996The purpose of @command{guix publish} is to enable users to easily share
8ce229fc
LC
4997their store with others, which can then use it as a substitute server
4998(@pxref{Substitutes}).
4999
5000When @command{guix publish} runs, it spawns an HTTP server which allows
5001anyone with network access to obtain substitutes from it. This means
5002that any machine running Guix can also act as if it were a build farm,
5003since the HTTP interface is compatible with Hydra, the software behind
5004the @code{hydra.gnu.org} build farm.
aff8ce7c
DT
5005
5006For security, each substitute is signed, allowing recipients to check
5007their authenticity and integrity (@pxref{Substitutes}). Because
5008@command{guix publish} uses the system's signing key, which is only
5463fe51
LC
5009readable by the system administrator, it must be started as root; the
5010@code{--user} option makes it drop root privileges early on.
aff8ce7c 5011
b18812b6
LC
5012The signing key pair must be generated before @command{guix publish} is
5013launched, using @command{guix archive --generate-key} (@pxref{Invoking
5014guix archive}).
5015
aff8ce7c
DT
5016The general syntax is:
5017
5018@example
5019guix publish @var{options}@dots{}
5020@end example
5021
5022Running @command{guix publish} without any additional arguments will
5023spawn an HTTP server on port 8080:
5024
5025@example
5026guix publish
5027@end example
5028
5029Once a publishing server has been authorized (@pxref{Invoking guix
5030archive}), the daemon may download substitutes from it:
5031
5032@example
5033guix-daemon --substitute-urls=http://example.org:8080
5034@end example
5035
5036The following options are available:
5037
5038@table @code
5039@item --port=@var{port}
5040@itemx -p @var{port}
5041Listen for HTTP requests on @var{port}.
5042
9e2292ef
LC
5043@item --listen=@var{host}
5044Listen on the network interface for @var{host}. The default is to
5045accept connections from any interface.
5046
5463fe51
LC
5047@item --user=@var{user}
5048@itemx -u @var{user}
5049Change privileges to @var{user} as soon as possible---i.e., once the
5050server socket is open and the signing key has been read.
5051
aff8ce7c
DT
5052@item --repl[=@var{port}]
5053@itemx -r [@var{port}]
5054Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8ce229fc
LC
5055Reference Manual}) on @var{port} (37146 by default). This is used
5056primarily for debugging a running @command{guix publish} server.
aff8ce7c
DT
5057@end table
5058
1c52181f
LC
5059Enabling @command{guix publish} on a GuixSD system is a one-liner: just
5060add a call to @code{guix-publish-service} in the @code{services} field
5061of the @code{operating-system} declaration (@pxref{guix-publish-service,
5062@code{guix-publish-service}}).
5063
d23c20f1
LC
5064
5065@node Invoking guix challenge
5066@section Invoking @command{guix challenge}
5067
5068@cindex reproducible builds
5069@cindex verifiable builds
5070
5071Do the binaries provided by this server really correspond to the source
5072code it claims to build? Is this package's build process deterministic?
5073These are the questions the @command{guix challenge} command attempts to
5074answer.
5075
5076The former is obviously an important question: Before using a substitute
5077server (@pxref{Substitutes}), you'd rather @emph{verify} that it
5078provides the right binaries, and thus @emph{challenge} it. The latter
5079is what enables the former: If package builds are deterministic, then
5080independent builds of the package should yield the exact same result,
5081bit for bit; if a server provides a binary different from the one
5082obtained locally, it may be either corrupt or malicious.
5083
5084We know that the hash that shows up in @file{/gnu/store} file names is
5085the hash of all the inputs of the process that built the file or
5086directory---compilers, libraries, build scripts,
5087etc. (@pxref{Introduction}). Assuming deterministic build processes,
5088one store file name should map to exactly one build output.
5089@command{guix challenge} checks whether there is, indeed, a single
5090mapping by comparing the build outputs of several independent builds of
5091any given store item.
5092
5093The command's output looks like this:
5094
5095@smallexample
5096$ guix challenge --substitute-urls="http://hydra.gnu.org http://guix.example.org"
5097updating list of substitutes from 'http://hydra.gnu.org'... 100.0%
5098updating list of substitutes from 'http://guix.example.org'... 100.0%
5099/gnu/store/@dots{}-openssl-1.0.2d contents differ:
5100 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5101 http://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5102 http://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
5103/gnu/store/@dots{}-git-2.5.0 contents differ:
5104 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
5105 http://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
5106 http://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
5107/gnu/store/@dots{}-pius-2.1.1 contents differ:
5108 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5109 http://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5110 http://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
5111@end smallexample
5112
5113@noindent
5114In this example, @command{guix challenge} first scans the store to
5115determine the set of locally-built derivations---as opposed to store
5116items that were downloaded from a substitute server---and then queries
5117all the substitute servers. It then reports those store items for which
5118the servers obtained a result different from the local build.
5119
5120@cindex non-determinism, in package builds
5121As an example, @code{guix.example.org} always gets a different answer.
5122Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
5123case of Git. This might indicate that the build process of Git is
5124non-deterministic, meaning that its output varies as a function of
5125various things that Guix does not fully control, in spite of building
5126packages in isolated environments (@pxref{Features}). Most common
5127sources of non-determinism include the addition of timestamps in build
5128results, the inclusion of random numbers, and directory listings sorted
5129by inode number. See @uref{http://reproducible.debian.net/howto/}, for
5130more information.
5131
5132To find out what's wrong with this Git binary, we can do something along
5133these lines (@pxref{Invoking guix archive}):
5134
5135@example
5136$ wget -q -O - http://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
5137 | guix archive -x /tmp/git
043f4698 5138$ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
d23c20f1
LC
5139@end example
5140
5141This command shows the difference between the files resulting from the
5142local build, and the files resulting from the build on
5143@code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
5144diffutils, Comparing and Merging Files}). The @command{diff} command
5145works great for text files. When binary files differ, a better option
5146is @uref{http://diffoscope.org/, Diffoscope}, a tool that helps
5147visualize differences for all kinds of files.
5148
5149Once you've done that work, you can tell whether the differences are due
5150to a non-deterministic build process or to a malicious server. We try
5151hard to remove sources of non-determinism in packages to make it easier
5152to verify substitutes, but of course, this is a process, one that
5153involves not just Guix but a large part of the free software community.
5154In the meantime, @command{guix challenge} is one tool to help address
5155the problem.
5156
5157If you are writing packages for Guix, you are encouraged to check
5158whether @code{hydra.gnu.org} and other substitute servers obtain the
5159same build result as you did with:
5160
5161@example
5162$ guix challenge @var{package}
5163@end example
5164
5165@noindent
5166... where @var{package} is a package specification such as
5167@code{guile-2.0} or @code{glibc:debug}.
5168
5169The general syntax is:
5170
5171@example
5172guix challenge @var{options} [@var{packages}@dots{}]
5173@end example
5174
5175The one option that matters is:
5176
5177@table @code
5178
5179@item --substitute-urls=@var{urls}
5180Consider @var{urls} the whitespace-separated list of substitute source
5181URLs to compare to.
5182
5183@end table
5184
5185
32efa254
DT
5186@node Invoking guix container
5187@section Invoking @command{guix container}
5188@cindex container
5189
5190@quotation Note
5191As of version @value{VERSION}, this tool is experimental. The interface
5192is subject to radical change in the future.
5193@end quotation
5194
5195The purpose of @command{guix container} is to manipulate processes
5196running within an isolated environment, commonly known as a
46c36586 5197``container'', typically created by the @command{guix environment}
32efa254
DT
5198(@pxref{Invoking guix environment}) and @command{guix system container}
5199(@pxref{Invoking guix system}) commands.
5200
5201The general syntax is:
5202
5203@example
5204guix container @var{action} @var{options}@dots{}
5205@end example
5206
5207@var{action} specifies the operation to perform with a container, and
5208@var{options} specifies the context-specific arguments for the action.
5209
5210The following actions are available:
5211
5212@table @code
5213@item exec
5214Execute a command within the context of a running container.
5215
5216The syntax is:
5217
5218@example
5219guix container exec @var{pid} @var{program} @var{arguments}@dots{}
5220@end example
5221
5222@var{pid} specifies the process ID of the running container.
5223@var{program} specifies an executable file name within the container's
5224root file system. @var{arguments} are the additional options that will
5225be passed to @var{program}.
5226
5227The following command launches an interactive login shell inside a
5228GuixSD container, started by @command{guix system container}, and whose
5229process ID is 9001:
5230
5231@example
5232guix container exec 9001 /run/current-system/profile/bin/bash --login
5233@end example
5234
5235Note that the @var{pid} cannot be the parent process of a container. It
5236must be the container's PID 1 or one of its child processes.
5237
5238@end table
5239
a1ba8475
LC
5240@c *********************************************************************
5241@node GNU Distribution
5242@chapter GNU Distribution
5243
3ca2731c 5244@cindex Guix System Distribution
4705641f 5245@cindex GuixSD
3ca2731c
LC
5246Guix comes with a distribution of the GNU system consisting entirely of
5247free software@footnote{The term ``free'' here refers to the
a1ba8475 5248@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 5249users of that software}.}. The
35ed9306
LC
5250distribution can be installed on its own (@pxref{System Installation}),
5251but it is also possible to install Guix as a package manager on top of
5252an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c 5253between the two, we refer to the standalone distribution as the Guix
4705641f 5254System Distribution, or GuixSD.
35ed9306
LC
5255
5256The distribution provides core GNU packages such as GNU libc, GCC, and
5257Binutils, as well as many GNU and non-GNU applications. The complete
5258list of available packages can be browsed
093ae1be 5259@url{http://www.gnu.org/software/guix/packages,on-line} or by
d03bb653 5260running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
5261
5262@example
e49951eb 5263guix package --list-available
a1ba8475
LC
5264@end example
5265
35ed9306 5266Our goal has been to provide a practical 100% free software distribution of
401c53c4
LC
5267Linux-based and other variants of GNU, with a focus on the promotion and
5268tight integration of GNU components, and an emphasis on programs and
5269tools that help users exert that freedom.
5270
3ca2731c 5271Packages are currently available on the following platforms:
c320011d
LC
5272
5273@table @code
5274
5275@item x86_64-linux
5276Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
5277
5278@item i686-linux
5279Intel 32-bit architecture (IA32), Linux-Libre kernel;
5280
aa1e1947 5281@item armhf-linux
aa725117 5282ARMv7-A architecture with hard float, Thumb-2 and NEON,
aa1e1947
MW
5283using the EABI hard-float ABI, and Linux-Libre kernel.
5284
c320011d
LC
5285@item mips64el-linux
5286little-endian 64-bit MIPS processors, specifically the Loongson series,
5287n32 application binary interface (ABI), and Linux-Libre kernel.
5288
5289@end table
5290
4705641f 5291GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
3ca2731c 5292
c320011d
LC
5293@noindent
5294For information on porting to other architectures or kernels,
5295@xref{Porting}.
5296
401c53c4 5297@menu
5af6de3e 5298* System Installation:: Installing the whole operating system.
35ed9306 5299* System Configuration:: Configuring the operating system.
91ef73d4 5300* Installing Debugging Files:: Feeding the debugger.
05962f29 5301* Security Updates:: Deploying security fixes quickly.
401c53c4 5302* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 5303* Packaging Guidelines:: Growing the distribution.
401c53c4 5304* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 5305* Porting:: Targeting another platform or kernel.
401c53c4
LC
5306@end menu
5307
5308Building this distribution is a cooperative effort, and you are invited
081145cf 5309to join! @xref{Contributing}, for information about how you can help.
401c53c4 5310
5af6de3e
LC
5311@node System Installation
5312@section System Installation
5313
3ca2731c
LC
5314@cindex Guix System Distribution
5315This section explains how to install the Guix System Distribution
5316on a machine. The Guix package manager can
35ed9306
LC
5317also be installed on top of a running GNU/Linux system,
5318@pxref{Installation}.
5af6de3e
LC
5319
5320@ifinfo
5321@c This paragraph is for people reading this from tty2 of the
5322@c installation image.
5323You're reading this documentation with an Info reader. For details on
5324how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
6621cdb6 5325link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit
5af6de3e
LC
5326@kbd{l} afterwards to come back here.
5327@end ifinfo
5328
8aaaae38
LC
5329@subsection Limitations
5330
4705641f 5331As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
3ca2731c 5332not production-ready. It may contain bugs and lack important
8aaaae38
LC
5333features. Thus, if you are looking for a stable production system that
5334respects your freedom as a computer user, a good solution at this point
5335is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
5336more established GNU/Linux distributions}. We hope you can soon switch
4705641f 5337to the GuixSD without fear, of course. In the meantime, you can
8aaaae38
LC
5338also keep using your distribution and try out the package manager on top
5339of it (@pxref{Installation}).
5340
5341Before you proceed with the installation, be aware of the following
5342noteworthy limitations applicable to version @value{VERSION}:
5343
5344@itemize
5345@item
5346The installation process does not include a graphical user interface and
5347requires familiarity with GNU/Linux (see the following subsections to
5348get a feel of what that means.)
5349
5350@item
093ae1be
LC
5351The system does not yet provide full GNOME and KDE desktops. Xfce and
5352Enlightenment are available though, if graphical desktop environments
5353are your thing, as well as a number of X11 window managers.
8aaaae38
LC
5354
5355@item
dbcb0ab1 5356Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
5357
5358@item
5359Few system services are currently supported out-of-the-box
5360(@pxref{Services}).
5361
5362@item
093ae1be 5363More than 2,000 packages are available, but you may
8aaaae38
LC
5364occasionally find that a useful package is missing.
5365@end itemize
5366
5367You've been warned. But more than a disclaimer, this is an invitation
5368to report issues (and success stories!), and join us in improving it.
5369@xref{Contributing}, for more info.
5af6de3e
LC
5370
5371@subsection USB Stick Installation
5372
5373An installation image for USB sticks can be downloaded from
4705641f 5374@indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
5375where @var{system} is one of:
5376
5377@table @code
5378@item x86_64-linux
5379for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
5380
5381@item i686-linux
5382for a 32-bit GNU/Linux system on Intel-compatible CPUs.
5383@end table
5384
5385This image contains a single partition with the tools necessary for an
5386installation. It is meant to be copied @emph{as is} to a large-enough
5387USB stick.
5388
5389To copy the image to a USB stick, follow these steps:
5390
5391@enumerate
5392@item
5393Decompress the image using the @command{xz} command:
5394
5395@example
4705641f 5396xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
5397@end example
5398
5399@item
5400Insert a USB stick of 1@tie{}GiB or more in your machine, and determine
5401its device name. Assuming that USB stick is known as @file{/dev/sdX},
5402copy the image with:
5403
5404@example
4705641f 5405dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
5406@end example
5407
5408Access to @file{/dev/sdX} usually requires root privileges.
5409@end enumerate
5410
5411Once this is done, you should be able to reboot the system and boot from
5412the USB stick. The latter usually requires you to get in the BIOS' boot
5413menu, where you can choose to boot from the USB stick.
5414
5415@subsection Preparing for Installation
5416
5417Once you have successfully booted the image on the USB stick, you should
5418end up with a root prompt. Several console TTYs are configured and can
5419be used to run commands as root. TTY2 shows this documentation,
5420browsable using the Info reader commands (@pxref{Help,,, info, Info: An
ae7ffa9e
LC
5421Introduction}). The installation system runs the GPM mouse daemon,
5422which allows you to select text with the left mouse button and to paste
5423it with the middle button.
5af6de3e
LC
5424
5425To install the system, you would:
5426
5427@enumerate
5428
5429@item
235cba85
LC
5430Configure the network, by running:
5431
5432@example
5433ifconfig eno1 up && dhclient eno1
5434@end example
5435
5436to get an automatically assigned IP address from the wired
152dd61c 5437network interface controller@footnote{
95c559c1
LC
5438@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
5439The name @code{eno1} is for the first on-board Ethernet controller. The
5440interface name for an Ethernet controller that is in the first slot of
5441the first PCI bus, for instance, would be @code{enp1s0}. Use
235cba85 5442@command{ifconfig -a} to list all the available network interfaces.},
95c559c1 5443or using the @command{ifconfig} command.
5af6de3e
LC
5444
5445The system automatically loads drivers for your network interface
5446controllers.
5447
5448Setting up network access is almost always a requirement because the
5449image does not contain all the software and tools that may be needed.
5450
5451@item
316d65be
LC
5452Unless this has already been done, you must partition, and then format
5453the target partition.
5af6de3e 5454
7ab44369
LC
5455Preferably, assign partitions a label so that you can easily and
5456reliably refer to them in @code{file-system} declarations (@pxref{File
5457Systems}). This is typically done using the @code{-L} option of
5458@command{mkfs.ext4} and related commands.
5459
dd816355
LF
5460Be sure that your partition labels match the value of their respective
5461@code{device} fields in your @code{file-system} configuration, if your
5462@code{file-system} configuration sets the value of @code{title} to
5463@code{'label}, as do the example configurations found on the USB
5464installation image under @file{/etc/configuration} (@pxref{Using the
5465Configuration System}).
5466
316d65be
LC
5467@c FIXME: Uncomment this once GRUB fully supports encrypted roots.
5468@c A typical command sequence may be:
5469@c
5470@c @example
5471@c # fdisk /dev/sdX
5472@c @dots{} Create partitions etc.@dots{}
5473@c # cryptsetup luksFormat /dev/sdX1
5474@c # cryptsetup open --type luks /dev/sdX1 my-partition
5475@c # mkfs.ext4 -L my-root /dev/mapper/my-partition
5476@c @end example
6d6e6281 5477
5af6de3e 5478The installation image includes Parted (@pxref{Overview,,, parted, GNU
b419c7f5
LC
5479Parted User Manual}), @command{fdisk}, Cryptsetup/LUKS for disk
5480encryption, and e2fsprogs, the suite of tools to manipulate
5481ext2/ext3/ext4 file systems.
5af6de3e 5482
83a17b62
LC
5483@item
5484Once that is done, mount the target root partition under @file{/mnt}.
5485
5486@item
5487Lastly, run @code{deco start cow-store /mnt}.
5488
5489This will make @file{/gnu/store} copy-on-write, such that packages added
5490to it during the installation phase will be written to the target disk
5491rather than kept in memory.
5492
5af6de3e
LC
5493@end enumerate
5494
5af6de3e
LC
5495
5496@subsection Proceeding with the Installation
5497
5498With the target partitions ready, you now have to edit a file and
5499provide the declaration of the operating system to be installed. To
5500that end, the installation system comes with two text editors: GNU nano
5501(@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
5502It is better to store that file on the target root file system, say, as
5503@file{/mnt/etc/config.scm}.
5504
dd51caac
LC
5505@xref{Using the Configuration System}, for examples of operating system
5506configurations. These examples are available under
5507@file{/etc/configuration} in the installation image, so you can copy
5508them and use them as a starting point for your own configuration.
5af6de3e 5509
dd51caac
LC
5510Once you are done preparing the configuration file, the new system must
5511be initialized (remember that the target root file system is mounted
5512under @file{/mnt}):
5af6de3e
LC
5513
5514@example
5515guix system init /mnt/etc/config.scm /mnt
5516@end example
5517
5518@noindent
5519This will copy all the necessary files, and install GRUB on
5520@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 5521more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
5522downloads or builds of missing packages, which can take some time.
5523
1bd4e6db
LC
5524Once that command has completed---and hopefully succeeded!---you can run
5525@command{reboot} and boot into the new system. The @code{root} password
5526in the new system is initially empty; other users' passwords need to be
5527initialized by running the @command{passwd} command as @code{root},
5528unless your configuration specifies otherwise
5529(@pxref{user-account-password, user account passwords}).
5530
5531Join us on @code{#guix} on the Freenode IRC network or on
5af6de3e
LC
5532@file{guix-devel@@gnu.org} to share your experience---good or not so
5533good.
5534
5535@subsection Building the Installation Image
5536
5537The installation image described above was built using the @command{guix
5538system} command, specifically:
5539
5540@example
8a225c66 5541guix system disk-image --image-size=850MiB gnu/system/install.scm
5af6de3e
LC
5542@end example
5543
5544@xref{Invoking guix system}, for more information. See
5545@file{gnu/system/install.scm} in the source tree for more information
5546about the installation image.
5547
cf4a9129
LC
5548@node System Configuration
5549@section System Configuration
b208a005 5550
cf4a9129 5551@cindex system configuration
3ca2731c 5552The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
5553mechanism. By that we mean that all aspects of the global system
5554configuration---such as the available system services, timezone and
5555locale settings, user accounts---are declared in a single place. Such
5556a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 5557
cf4a9129
LC
5558One of the advantages of putting all the system configuration under the
5559control of Guix is that it supports transactional system upgrades, and
5560makes it possible to roll-back to a previous system instantiation,
5561should something go wrong with the new one (@pxref{Features}). Another
5562one is that it makes it easy to replicate the exact same configuration
5563across different machines, or at different points in time, without
5564having to resort to additional administration tools layered on top of
5565the system's own tools.
5566@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 5567
cf4a9129
LC
5568This section describes this mechanism. First we focus on the system
5569administrator's viewpoint---explaining how the system is configured and
5570instantiated. Then we show how this mechanism can be extended, for
5571instance to support new system services.
91ef73d4 5572
cf4a9129
LC
5573@menu
5574* Using the Configuration System:: Customizing your GNU system.
7313a52e 5575* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 5576* File Systems:: Configuring file system mounts.
510f9d86 5577* Mapped Devices:: Block device extra processing.
cf4a9129 5578* User Accounts:: Specifying user accounts.
598e19dc 5579* Locales:: Language and cultural convention settings.
cf4a9129 5580* Services:: Specifying system services.
0ae8c15a 5581* Setuid Programs:: Programs running with root privileges.
efb5e833 5582* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 5583* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 5584* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 5585* GRUB Configuration:: Configuring the boot loader.
cf4a9129
LC
5586* Invoking guix system:: Instantiating a system configuration.
5587* Defining Services:: Adding new service definitions.
5588@end menu
91ef73d4 5589
cf4a9129
LC
5590@node Using the Configuration System
5591@subsection Using the Configuration System
64d76fa6 5592
cf4a9129
LC
5593The operating system is configured by providing an
5594@code{operating-system} declaration in a file that can then be passed to
5595the @command{guix system} command (@pxref{Invoking guix system}). A
5596simple setup, with the default system services, the default Linux-Libre
5597kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 5598
cf4a9129
LC
5599@findex operating-system
5600@lisp
dd51caac 5601@include os-config-bare-bones.texi
cf4a9129 5602@end lisp
401c53c4 5603
cf4a9129
LC
5604This example should be self-describing. Some of the fields defined
5605above, such as @code{host-name} and @code{bootloader}, are mandatory.
5606Others, such as @code{packages} and @code{services}, can be omitted, in
5607which case they get a default value.
e7f34eb0 5608
cf4a9129
LC
5609@vindex %base-packages
5610The @code{packages} field lists
5611packages that will be globally visible on the system, for all user
5612accounts---i.e., in every user's @code{PATH} environment variable---in
5613addition to the per-user profiles (@pxref{Invoking guix package}). The
5614@var{%base-packages} variable provides all the tools one would expect
5615for basic user and administrator tasks---including the GNU Core
5616Utilities, the GNU Networking Utilities, the GNU Zile lightweight text
5617editor, @command{find}, @command{grep}, etc. The example above adds
2e437e29 5618tcpdump to those, taken from the @code{(gnu packages admin)} module
cf4a9129 5619(@pxref{Package Modules}).
e7f34eb0 5620
f6c9fb1b
LC
5621@findex specification->package
5622Referring to packages by variable name, like @var{tcpdump} above, has
5623the advantage of being unambiguous; it also allows typos and such to be
5624diagnosed right away as ``unbound variables''. The downside is that one
5625needs to know which module defines which package, and to augment the
5626@code{use-package-modules} line accordingly. To avoid that, one can use
5627the @code{specification->package} procedure of the @code{(gnu packages)}
5628module, which returns the best package for a given name or name and
5629version:
5630
5631@lisp
5632(use-modules (gnu packages))
5633
5634(operating-system
5635 ;; ...
5636 (packages (append (map specification->package
5637 '("tcpdump" "htop" "gnupg-2.0"))
5638 %base-packages)))
5639@end lisp
5640
cf4a9129
LC
5641@vindex %base-services
5642The @code{services} field lists @dfn{system services} to be made
5643available when the system starts (@pxref{Services}).
5644The @code{operating-system} declaration above specifies that, in
5645addition to the basic services, we want the @command{lshd} secure shell
cd6f6c22
LC
5646daemon listening on port 2222 (@pxref{Networking Services,
5647@code{lsh-service}}). Under the hood,
cf4a9129
LC
5648@code{lsh-service} arranges so that @code{lshd} is started with the
5649right command-line options, possibly with supporting configuration files
cd6f6c22
LC
5650generated as needed (@pxref{Defining Services}).
5651
5652@cindex customization, of services
5653@findex modify-services
5654Occasionally, instead of using the base services as is, you will want to
5655customize them. For instance, to change the configuration of
5656@code{guix-daemon} and Mingetty (the console log-in), you may write the
5657following instead of @var{%base-services}:
5658
5659@lisp
5660(modify-services %base-services
5661 (guix-service-type config =>
5662 (guix-configuration
5663 (inherit config)
5664 (use-substitutes? #f)
5665 (extra-options '("--gc-keep-outputs"))))
5666 (mingetty-service-type config =>
5667 (mingetty-configuration
5668 (inherit config)
5669 (motd (plain-file "motd" "Hi there!")))))
5670@end lisp
5671
5672@noindent
5673The effect here is to change the options passed to @command{guix-daemon}
5674when it is started, as well as the ``message of the day'' that appears
5675when logging in at the console. @xref{Service Reference,
5676@code{modify-services}}, for more on that.
a1ba8475 5677
dd51caac 5678The configuration for a typical ``desktop'' usage, with the X11 display
cd6f6c22 5679server, a desktop environment, network management, power management, and
dd51caac
LC
5680more, would look like this:
5681
5682@lisp
5683@include os-config-desktop.texi
5684@end lisp
5685
5686@xref{Desktop Services}, for the exact list of services provided by
efb5e833
LC
5687@var{%desktop-services}. @xref{X.509 Certificates}, for background
5688information about the @code{nss-certs} package that is used here.
cd6f6c22
LC
5689@xref{operating-system Reference}, for details about all the available
5690@code{operating-system} fields.
dd51caac 5691
cf4a9129
LC
5692Assuming the above snippet is stored in the @file{my-system-config.scm}
5693file, the @command{guix system reconfigure my-system-config.scm} command
5694instantiates that configuration, and makes it the default GRUB boot
65797bff
LC
5695entry (@pxref{Invoking guix system}).
5696
5697The normal way to change the system's configuration is by updating this
5698file and re-running @command{guix system reconfigure}. One should never
5699have to touch files in @command{/etc} or to run commands that modify the
5700system state such as @command{useradd} or @command{grub-install}. In
5701fact, you must avoid that since that would not only void your warranty
5702but also prevent you from rolling back to previous versions of your
5703system, should you ever need to.
5704
5705@cindex roll-back, of the operating system
5706Speaking of roll-back, each time you run @command{guix system
5707reconfigure}, a new @dfn{generation} of the system is created---without
5708modifying or deleting previous generations. Old system generations get
5709an entry in the GRUB boot menu, allowing you to boot them in case
5710something went wrong with the latest generation. Reassuring, no? The
5711@command{guix system list-generations} command lists the system
5712generations available on disk.
b81e1947 5713
cf4a9129
LC
5714At the Scheme level, the bulk of an @code{operating-system} declaration
5715is instantiated with the following monadic procedure (@pxref{The Store
5716Monad}):
b81e1947 5717
cf4a9129
LC
5718@deffn {Monadic Procedure} operating-system-derivation os
5719Return a derivation that builds @var{os}, an @code{operating-system}
5720object (@pxref{Derivations}).
b81e1947 5721
cf4a9129
LC
5722The output of the derivation is a single directory that refers to all
5723the packages, configuration files, and other supporting files needed to
5724instantiate @var{os}.
5725@end deffn
b81e1947 5726
7313a52e
LC
5727@node operating-system Reference
5728@subsection @code{operating-system} Reference
5729
5730This section summarizes all the options available in
5731@code{operating-system} declarations (@pxref{Using the Configuration
5732System}).
5733
5734@deftp {Data Type} operating-system
5735This is the data type representing an operating system configuration.
5736By that, we mean all the global system configuration, not per-user
5737configuration (@pxref{Using the Configuration System}).
5738
5739@table @asis
5740@item @code{kernel} (default: @var{linux-libre})
fbb25e56 5741The package object of the operating system kernel to use@footnote{Currently
7313a52e
LC
5742only the Linux-libre kernel is supported. In the future, it will be
5743possible to use the GNU@tie{}Hurd.}.
5744
ee2a6304
LC
5745@item @code{kernel-arguments} (default: @code{'()})
5746List of strings or gexps representing additional arguments to pass on
5747the kernel's command-line---e.g., @code{("console=ttyS0")}.
5748
7313a52e 5749@item @code{bootloader}
88faf933 5750The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
5751
5752@item @code{initrd} (default: @code{base-initrd})
5753A two-argument monadic procedure that returns an initial RAM disk for
5754the Linux kernel. @xref{Initial RAM Disk}.
5755
f34c56be
LC
5756@item @code{firmware} (default: @var{%base-firmware})
5757@cindex firmware
5758List of firmware packages loadable by the operating system kernel.
5759
5760The default includes firmware needed for Atheros-based WiFi devices
5761(Linux-libre module @code{ath9k}.)
5762
7313a52e
LC
5763@item @code{host-name}
5764The host name.
5765
5766@item @code{hosts-file}
5767@cindex hosts file
24e02c28 5768A file-like object (@pxref{G-Expressions, file-like objects}) for use as
7313a52e 5769@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
24e02c28 5770Reference Manual}). The default is a file with entries for
7313a52e
LC
5771@code{localhost} and @var{host-name}.
5772
5773@item @code{mapped-devices} (default: @code{'()})
5774A list of mapped devices. @xref{Mapped Devices}.
5775
5776@item @code{file-systems}
5777A list of file systems. @xref{File Systems}.
5778
5779@item @code{swap-devices} (default: @code{'()})
5780@cindex swap devices
5781A list of strings identifying devices to be used for ``swap space''
5782(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
5783For example, @code{'("/dev/sda3")}.
5784
bf87f38a 5785@item @code{users} (default: @code{%base-user-accounts})
7313a52e
LC
5786@itemx @code{groups} (default: @var{%base-groups})
5787List of user accounts and groups. @xref{User Accounts}.
5788
5789@item @code{skeletons} (default: @code{(default-skeletons)})
5790A monadic list of pairs of target file name and files. These are the
5791files that will be used as skeletons as new accounts are created.
5792
5793For instance, a valid value may look like this:
5794
5795@example
5796(mlet %store-monad ((bashrc (text-file "bashrc" "\
5797 export PATH=$HOME/.guix-profile/bin")))
5798 (return `((".bashrc" ,bashrc))))
5799@end example
5800
5801@item @code{issue} (default: @var{%default-issue})
5802A string denoting the contents of the @file{/etc/issue} file, which is
5803what displayed when users log in on a text console.
5804
5805@item @code{packages} (default: @var{%base-packages})
5806The set of packages installed in the global profile, which is accessible
5807at @file{/run/current-system/profile}.
5808
5809The default set includes core utilities, but it is good practice to
5810install non-core utilities in user profiles (@pxref{Invoking guix
5811package}).
5812
5813@item @code{timezone}
5814A timezone identifying string---e.g., @code{"Europe/Paris"}.
5815
598e19dc
LC
5816@item @code{locale} (default: @code{"en_US.utf8"})
5817The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
5818Library Reference Manual}). @xref{Locales}, for more information.
5819
5820@item @code{locale-definitions} (default: @var{%default-locale-definitions})
5821The list of locale definitions to be compiled and that may be used at
5822run time. @xref{Locales}.
7313a52e 5823
34760ae7
LC
5824@item @code{locale-libcs} (default: @code{(list @var{glibc})})
5825The list of GNU@tie{}libc packages whose locale data and tools are used
5826to build the locale definitions. @xref{Locales}, for compatibility
5827considerations that justify this option.
5828
996ed739
LC
5829@item @code{name-service-switch} (default: @var{%default-nss})
5830Configuration of libc's name service switch (NSS)---a
5831@code{<name-service-switch>} object. @xref{Name Service Switch}, for
5832details.
5833
7313a52e 5834@item @code{services} (default: @var{%base-services})
28d939af 5835A list of service objects denoting system services. @xref{Services}.
7313a52e
LC
5836
5837@item @code{pam-services} (default: @code{(base-pam-services)})
5838@cindex PAM
5839@cindex pluggable authentication modules
5840Linux @dfn{pluggable authentication module} (PAM) services.
5841@c FIXME: Add xref to PAM services section.
5842
5843@item @code{setuid-programs} (default: @var{%setuid-programs})
5844List of string-valued G-expressions denoting setuid programs.
5845@xref{Setuid Programs}.
5846
f5a9ffa0
AK
5847@item @code{sudoers-file} (default: @var{%sudoers-specification})
5848@cindex sudoers file
84765839
LC
5849The contents of the @file{/etc/sudoers} file as a file-like object
5850(@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7313a52e
LC
5851
5852This file specifies which users can use the @command{sudo} command, what
5853they are allowed to do, and what privileges they may gain. The default
5854is that only @code{root} and members of the @code{wheel} group may use
5855@code{sudo}.
5856
5857@end table
5858@end deftp
5859
cf4a9129
LC
5860@node File Systems
5861@subsection File Systems
b81e1947 5862
cf4a9129
LC
5863The list of file systems to be mounted is specified in the
5864@code{file-systems} field of the operating system's declaration
5865(@pxref{Using the Configuration System}). Each file system is declared
5866using the @code{file-system} form, like this:
b81e1947
LC
5867
5868@example
cf4a9129
LC
5869(file-system
5870 (mount-point "/home")
5871 (device "/dev/sda3")
5872 (type "ext4"))
b81e1947
LC
5873@end example
5874
cf4a9129
LC
5875As usual, some of the fields are mandatory---those shown in the example
5876above---while others can be omitted. These are described below.
b81e1947 5877
cf4a9129
LC
5878@deftp {Data Type} file-system
5879Objects of this type represent file systems to be mounted. They
5880contain the following members:
5ff3c4b8 5881
cf4a9129
LC
5882@table @asis
5883@item @code{type}
5884This is a string specifying the type of the file system---e.g.,
5885@code{"ext4"}.
5ff3c4b8 5886
cf4a9129
LC
5887@item @code{mount-point}
5888This designates the place where the file system is to be mounted.
b81e1947 5889
cf4a9129
LC
5890@item @code{device}
5891This names the ``source'' of the file system. By default it is the name
5892of a node under @file{/dev}, but its meaning depends on the @code{title}
5893field described below.
401c53c4 5894
cf4a9129
LC
5895@item @code{title} (default: @code{'device})
5896This is a symbol that specifies how the @code{device} field is to be
5897interpreted.
401c53c4 5898
cf4a9129
LC
5899When it is the symbol @code{device}, then the @code{device} field is
5900interpreted as a file name; when it is @code{label}, then @code{device}
5901is interpreted as a partition label name; when it is @code{uuid},
5902@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 5903
661a1d79
LC
5904UUIDs may be converted from their string representation (as shown by the
5905@command{tune2fs -l} command) using the @code{uuid} form, like this:
5906
5907@example
5908(file-system
5909 (mount-point "/home")
5910 (type "ext4")
5911 (title 'uuid)
5912 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
5913@end example
5914
cf4a9129 5915The @code{label} and @code{uuid} options offer a way to refer to disk
661a1d79
LC
5916partitions without having to hard-code their actual device
5917name@footnote{Note that, while it is tempting to use
5918@file{/dev/disk/by-uuid} and similar device names to achieve the same
5919result, this is not recommended: These special device nodes are created
5920by the udev daemon and may be unavailable at the time the device is
5921mounted.}.
da7cabd4 5922
5f86a66e
LC
5923However, when a file system's source is a mapped device (@pxref{Mapped
5924Devices}), its @code{device} field @emph{must} refer to the mapped
5925device name---e.g., @file{/dev/mapper/root-partition}---and consequently
5926@code{title} must be set to @code{'device}. This is required so that
5927the system knows that mounting the file system depends on having the
5928corresponding device mapping established.
5929
cf4a9129
LC
5930@item @code{flags} (default: @code{'()})
5931This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
5932include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
5933access to special files), @code{no-suid} (ignore setuid and setgid
5934bits), and @code{no-exec} (disallow program execution.)
da7cabd4 5935
cf4a9129
LC
5936@item @code{options} (default: @code{#f})
5937This is either @code{#f}, or a string denoting mount options.
da7cabd4 5938
be21979d
LC
5939@item @code{mount?} (default: @code{#t})
5940This value indicates whether to automatically mount the file system when
5941the system is brought up. When set to @code{#f}, the file system gets
5942an entry in @file{/etc/fstab} (read by the @command{mount} command) but
5943is not automatically mounted.
5944
cf4a9129
LC
5945@item @code{needed-for-boot?} (default: @code{#f})
5946This Boolean value indicates whether the file system is needed when
5947booting. If that is true, then the file system is mounted when the
5948initial RAM disk (initrd) is loaded. This is always the case, for
5949instance, for the root file system.
da7cabd4 5950
cf4a9129
LC
5951@item @code{check?} (default: @code{#t})
5952This Boolean indicates whether the file system needs to be checked for
5953errors before being mounted.
f9cc8971 5954
4e469051
LC
5955@item @code{create-mount-point?} (default: @code{#f})
5956When true, the mount point is created if it does not exist yet.
5957
e51710d1
LC
5958@item @code{dependencies} (default: @code{'()})
5959This is a list of @code{<file-system>} objects representing file systems
5960that must be mounted before (and unmounted after) this one.
5961
5962As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
5963a dependency of @file{/sys/fs/cgroup/cpu} and
5964@file{/sys/fs/cgroup/memory}.
5965
cf4a9129
LC
5966@end table
5967@end deftp
da7cabd4 5968
a69576ea
LC
5969The @code{(gnu system file-systems)} exports the following useful
5970variables.
5971
5972@defvr {Scheme Variable} %base-file-systems
5973These are essential file systems that are required on normal systems,
cc0e575a 5974such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
3392ce5d
LC
5975below.) Operating system declarations should always contain at least
5976these.
a69576ea
LC
5977@end defvr
5978
7f239fd3
LC
5979@defvr {Scheme Variable} %pseudo-terminal-file-system
5980This is the file system to be mounted as @file{/dev/pts}. It supports
5981@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
5982functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
5983Manual}). Pseudo-terminals are used by terminal emulators such as
5984@command{xterm}.
5985@end defvr
5986
db17ae5c
LC
5987@defvr {Scheme Variable} %shared-memory-file-system
5988This file system is mounted as @file{/dev/shm} and is used to support
5989memory sharing across processes (@pxref{Memory-mapped I/O,
5990@code{shm_open},, libc, The GNU C Library Reference Manual}).
5991@end defvr
5992
3392ce5d
LC
5993@defvr {Scheme Variable} %immutable-store
5994This file system performs a read-only ``bind mount'' of
5995@file{/gnu/store}, making it read-only for all the users including
5996@code{root}. This prevents against accidental modification by software
5997running as @code{root} or by system administrators.
5998
5999The daemon itself is still able to write to the store: it remounts it
6000read-write in its own ``name space.''
6001@end defvr
6002
a69576ea
LC
6003@defvr {Scheme Variable} %binary-format-file-system
6004The @code{binfmt_misc} file system, which allows handling of arbitrary
6005executable file types to be delegated to user space. This requires the
6006@code{binfmt.ko} kernel module to be loaded.
6007@end defvr
6008
6009@defvr {Scheme Variable} %fuse-control-file-system
6010The @code{fusectl} file system, which allows unprivileged users to mount
6011and unmount user-space FUSE file systems. This requires the
6012@code{fuse.ko} kernel module to be loaded.
6013@end defvr
6014
510f9d86
LC
6015@node Mapped Devices
6016@subsection Mapped Devices
6017
6018@cindex device mapping
6019@cindex mapped devices
6020The Linux kernel has a notion of @dfn{device mapping}: a block device,
6021such as a hard disk partition, can be @dfn{mapped} into another device,
6022with additional processing over the data that flows through
6023it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
6024concept of a ``mapped device'' and that of a file system: both boil down
6025to @emph{translating} input/output operations made on a file to
6026operations on its backing store. Thus, the Hurd implements mapped
6027devices, like file systems, using the generic @dfn{translator} mechanism
6028(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
6029typical example is encryption device mapping: all writes to the mapped
6030device are encrypted, and all reads are deciphered, transparently.
6031
6032Mapped devices are declared using the @code{mapped-device} form:
6033
6034@example
6035(mapped-device
6036 (source "/dev/sda3")
6037 (target "home")
6038 (type luks-device-mapping))
6039@end example
6040
6041@noindent
6042@cindex disk encryption
6043@cindex LUKS
6044This example specifies a mapping from @file{/dev/sda3} to
6045@file{/dev/mapper/home} using LUKS---the
6046@url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
6047standard mechanism for disk encryption. The @file{/dev/mapper/home}
6048device can then be used as the @code{device} of a @code{file-system}
6049declaration (@pxref{File Systems}). The @code{mapped-device} form is
6050detailed below.
6051
6052@deftp {Data Type} mapped-device
6053Objects of this type represent device mappings that will be made when
6054the system boots up.
6055
9cb426b8
LC
6056@table @code
6057@item source
510f9d86
LC
6058This string specifies the name of the block device to be mapped, such as
6059@code{"/dev/sda3"}.
6060
9cb426b8 6061@item target
510f9d86
LC
6062This string specifies the name of the mapping to be established. For
6063example, specifying @code{"my-partition"} will lead to the creation of
6064the @code{"/dev/mapper/my-partition"} device.
6065
9cb426b8 6066@item type
510f9d86
LC
6067This must be a @code{mapped-device-kind} object, which specifies how
6068@var{source} is mapped to @var{target}.
6069@end table
6070@end deftp
6071
6072@defvr {Scheme Variable} luks-device-mapping
6073This defines LUKS block device encryption using the @command{cryptsetup}
6074command, from the same-named package. This relies on the
6075@code{dm-crypt} Linux kernel module.
6076@end defvr
6077
cf4a9129
LC
6078@node User Accounts
6079@subsection User Accounts
ee85f3db 6080
9bea87a5
LC
6081User accounts and groups are entirely managed through the
6082@code{operating-system} declaration. They are specified with the
6083@code{user-account} and @code{user-group} forms:
ee85f3db 6084
cf4a9129
LC
6085@example
6086(user-account
6087 (name "alice")
6088 (group "users")
24e752c0
LC
6089 (supplementary-groups '("wheel" ;allow use of sudo, etc.
6090 "audio" ;sound card
6091 "video" ;video devices such as webcams
6092 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
6093 (comment "Bob's sister")
6094 (home-directory "/home/alice"))
6095@end example
25083588 6096
9bea87a5
LC
6097When booting or upon completion of @command{guix system reconfigure},
6098the system ensures that only the user accounts and groups specified in
6099the @code{operating-system} declaration exist, and with the specified
6100properties. Thus, account or group creations or modifications made by
6101directly invoking commands such as @command{useradd} are lost upon
6102reconfiguration or reboot. This ensures that the system remains exactly
6103as declared.
6104
cf4a9129
LC
6105@deftp {Data Type} user-account
6106Objects of this type represent user accounts. The following members may
6107be specified:
ee85f3db 6108
cf4a9129
LC
6109@table @asis
6110@item @code{name}
6111The name of the user account.
ee85f3db 6112
cf4a9129
LC
6113@item @code{group}
6114This is the name (a string) or identifier (a number) of the user group
6115this account belongs to.
ee85f3db 6116
cf4a9129
LC
6117@item @code{supplementary-groups} (default: @code{'()})
6118Optionally, this can be defined as a list of group names that this
6119account belongs to.
ee85f3db 6120
cf4a9129
LC
6121@item @code{uid} (default: @code{#f})
6122This is the user ID for this account (a number), or @code{#f}. In the
6123latter case, a number is automatically chosen by the system when the
6124account is created.
ee85f3db 6125
cf4a9129
LC
6126@item @code{comment} (default: @code{""})
6127A comment about the account, such as the account's owner full name.
c8c871d1 6128
cf4a9129
LC
6129@item @code{home-directory}
6130This is the name of the home directory for the account.
ee85f3db 6131
cf4a9129
LC
6132@item @code{shell} (default: Bash)
6133This is a G-expression denoting the file name of a program to be used as
6134the shell (@pxref{G-Expressions}).
ee85f3db 6135
cf4a9129
LC
6136@item @code{system?} (default: @code{#f})
6137This Boolean value indicates whether the account is a ``system''
6138account. System accounts are sometimes treated specially; for instance,
6139graphical login managers do not list them.
ee85f3db 6140
1bd4e6db 6141@anchor{user-account-password}
cf4a9129 6142@item @code{password} (default: @code{#f})
eb59595c
LC
6143You would normally leave this field to @code{#f}, initialize user
6144passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
6145users change it with @command{passwd}. Passwords set with
6146@command{passwd} are of course preserved across reboot and
6147reconfiguration.
eb59595c
LC
6148
6149If you @emph{do} want to have a preset password for an account, then
6150this field must contain the encrypted password, as a string.
5d1f1177
LC
6151@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
6152on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 6153Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 6154
cf4a9129
LC
6155@end table
6156@end deftp
ee85f3db 6157
cf4a9129 6158User group declarations are even simpler:
ee85f3db 6159
cf4a9129
LC
6160@example
6161(user-group (name "students"))
6162@end example
ee85f3db 6163
cf4a9129
LC
6164@deftp {Data Type} user-group
6165This type is for, well, user groups. There are just a few fields:
af8a56b8 6166
cf4a9129
LC
6167@table @asis
6168@item @code{name}
6169The group's name.
ee85f3db 6170
cf4a9129
LC
6171@item @code{id} (default: @code{#f})
6172The group identifier (a number). If @code{#f}, a new number is
6173automatically allocated when the group is created.
ee85f3db 6174
c8fa3426
LC
6175@item @code{system?} (default: @code{#f})
6176This Boolean value indicates whether the group is a ``system'' group.
6177System groups have low numerical IDs.
6178
cf4a9129
LC
6179@item @code{password} (default: @code{#f})
6180What, user groups can have a password? Well, apparently yes. Unless
6181@code{#f}, this field specifies the group's password.
ee85f3db 6182
cf4a9129
LC
6183@end table
6184@end deftp
401c53c4 6185
cf4a9129
LC
6186For convenience, a variable lists all the basic user groups one may
6187expect:
401c53c4 6188
cf4a9129
LC
6189@defvr {Scheme Variable} %base-groups
6190This is the list of basic user groups that users and/or packages expect
6191to be present on the system. This includes groups such as ``root'',
6192``wheel'', and ``users'', as well as groups used to control access to
6193specific devices such as ``audio'', ``disk'', and ``cdrom''.
6194@end defvr
401c53c4 6195
bf87f38a
LC
6196@defvr {Scheme Variable} %base-user-accounts
6197This is the list of basic system accounts that programs may expect to
6198find on a GNU/Linux system, such as the ``nobody'' account.
6199
6200Note that the ``root'' account is not included here. It is a
6201special-case and is automatically added whether or not it is specified.
6202@end defvr
6203
598e19dc
LC
6204@node Locales
6205@subsection Locales
6206
6207@cindex locale
6208A @dfn{locale} defines cultural conventions for a particular language
6209and region of the world (@pxref{Locales,,, libc, The GNU C Library
6210Reference Manual}). Each locale has a name that typically has the form
b2636518 6211@code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
598e19dc
LC
6212@code{fr_LU.utf8} designates the locale for the French language, with
6213cultural conventions from Luxembourg, and using the UTF-8 encoding.
6214
6215@cindex locale definition
6216Usually, you will want to specify the default locale for the machine
6217using the @code{locale} field of the @code{operating-system} declaration
6218(@pxref{operating-system Reference, @code{locale}}).
6219
6220That locale must be among the @dfn{locale definitions} that are known to
6221the system---and these are specified in the @code{locale-definitions}
6222slot of @code{operating-system}. The default value includes locale
6223definition for some widely used locales, but not for all the available
6224locales, in order to save space.
6225
6226If the locale specified in the @code{locale} field is not among the
6227definitions listed in @code{locale-definitions}, @command{guix system}
6228raises an error. In that case, you should add the locale definition to
6229the @code{locale-definitions} field. For instance, to add the North
6230Frisian locale for Germany, the value of that field may be:
6231
6232@example
6233(cons (locale-definition
6234 (name "fy_DE.utf8") (source "fy_DE"))
6235 %default-locale-definitions)
6236@end example
6237
6238Likewise, to save space, one might want @code{locale-definitions} to
6239list only the locales that are actually used, as in:
6240
6241@example
6242(list (locale-definition
6243 (name "ja_JP.eucjp") (source "ja_JP")
6244 (charset "EUC-JP")))
6245@end example
6246
5c3c1427
LC
6247@vindex LOCPATH
6248The compiled locale definitions are available at
46bd6edd
LC
6249@file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
6250version, which is the default location where the GNU@tie{}libc provided
6251by Guix looks for locale data. This can be overridden using the
6252@code{LOCPATH} environment variable (@pxref{locales-and-locpath,
5c3c1427
LC
6253@code{LOCPATH} and locale packages}).
6254
598e19dc
LC
6255The @code{locale-definition} form is provided by the @code{(gnu system
6256locale)} module. Details are given below.
6257
6258@deftp {Data Type} locale-definition
6259This is the data type of a locale definition.
6260
6261@table @asis
6262
6263@item @code{name}
6264The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
6265Reference Manual}, for more information on locale names.
6266
6267@item @code{source}
6268The name of the source for that locale. This is typically the
6269@code{@var{language}_@var{territory}} part of the locale name.
6270
6271@item @code{charset} (default: @code{"UTF-8"})
6272The ``character set'' or ``code set'' for that locale,
6273@uref{http://www.iana.org/assignments/character-sets, as defined by
6274IANA}.
6275
6276@end table
6277@end deftp
6278
6279@defvr {Scheme Variable} %default-locale-definitions
b2636518
LC
6280An arbitrary list of commonly used UTF-8 locales, used as the default
6281value of the @code{locale-definitions} field of @code{operating-system}
598e19dc 6282declarations.
b2636518
LC
6283
6284@cindex locale name
6285@cindex normalized codeset in locale names
6286These locale definitions use the @dfn{normalized codeset} for the part
6287that follows the dot in the name (@pxref{Using gettextized software,
6288normalized codeset,, libc, The GNU C Library Reference Manual}). So for
6289instance it has @code{uk_UA.utf8} but @emph{not}, say,
6290@code{uk_UA.UTF-8}.
598e19dc 6291@end defvr
401c53c4 6292
34760ae7
LC
6293@subsubsection Locale Data Compatibility Considerations
6294
6295@cindex incompatibility, of locale data
6296@code{operating-system} declarations provide a @code{locale-libcs} field
6297to specify the GNU@tie{}libc packages that are used to compile locale
6298declarations (@pxref{operating-system Reference}). ``Why would I
6299care?'', you may ask. Well, it turns out that the binary format of
6300locale data is occasionally incompatible from one libc version to
6301another.
6302
6303@c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
6304@c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
6305For instance, a program linked against libc version 2.21 is unable to
6306read locale data produced with libc 2.22; worse, that program
6307@emph{aborts} instead of simply ignoring the incompatible locale
6308data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
6309the incompatible locale data, which is already an improvement.}.
6310Similarly, a program linked against libc 2.22 can read most, but not
6311all, the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
6312data is incompatible); thus calls to @code{setlocale} may fail, but
6313programs will not abort.
6314
6315The ``problem'' in GuixSD is that users have a lot of freedom: They can
6316choose whether and when to upgrade software in their profiles, and might
6317be using a libc version different from the one the system administrator
6318used to build the system-wide locale data.
6319
6320Fortunately, unprivileged users can also install their own locale data
6321and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
6322@code{GUIX_LOCPATH} and locale packages}).
6323
6324Still, it is best if the system-wide locale data at
6325@file{/run/current-system/locale} is built for all the libc versions
6326actually in use on the system, so that all the programs can access
6327it---this is especially crucial on a multi-user system. To do that, the
6328administrator can specify several libc packages in the
6329@code{locale-libcs} field of @code{operating-system}:
6330
6331@example
6332(use-package-modules base)
6333
6334(operating-system
6335 ;; @dots{}
6336 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
6337@end example
6338
6339This example would lead to a system containing locale definitions for
6340both libc 2.21 and the current version of libc in
6341@file{/run/current-system/locale}.
6342
6343
cf4a9129
LC
6344@node Services
6345@subsection Services
401c53c4 6346
cf4a9129
LC
6347@cindex system services
6348An important part of preparing an @code{operating-system} declaration is
6349listing @dfn{system services} and their configuration (@pxref{Using the
6350Configuration System}). System services are typically daemons launched
6351when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
6352configuring network access.
6353
6354Services are managed by GNU@tie{}dmd (@pxref{Introduction,,, dmd, GNU
6355dmd Manual}). On a running system, the @command{deco} command allows
6356you to list the available services, show their status, start and stop
6357them, or do other specific operations (@pxref{Jump Start,,, dmd, GNU dmd
6358Manual}). For example:
6359
6360@example
6361# deco status dmd
6362@end example
6363
6364The above command, run as @code{root}, lists the currently defined
6365services. The @command{deco doc} command shows a synopsis of the given
6366service:
6367
6368@example
6369# deco doc nscd
6370Run libc's name service cache daemon (nscd).
6371@end example
6372
6373The @command{start}, @command{stop}, and @command{restart} sub-commands
6374have the effect you would expect. For instance, the commands below stop
6375the nscd service and restart the Xorg display server:
6376
6377@example
6378# deco stop nscd
6379Service nscd has been stopped.
6380# deco restart xorg-server
6381Service xorg-server has been stopped.
6382Service xorg-server has been started.
6383@end example
401c53c4 6384
cf4a9129 6385The following sections document the available services, starting with
d8b94dbd
LC
6386the core services, that may be used in an @code{operating-system}
6387declaration.
401c53c4 6388
cf4a9129
LC
6389@menu
6390* Base Services:: Essential system services.
6391* Networking Services:: Network setup, SSH daemon, etc.
6392* X Window:: Graphical display.
fe1a39d3 6393* Desktop Services:: D-Bus and desktop services.
105369a4 6394* Database Services:: SQL databases.
d8c18af8 6395* Mail Services:: IMAP, POP3, SMTP, and all that.
58724c48 6396* Web Services:: Web servers.
aa4ed923 6397* Various Services:: Other services.
cf4a9129 6398@end menu
401c53c4 6399
cf4a9129
LC
6400@node Base Services
6401@subsubsection Base Services
a1ba8475 6402
cf4a9129
LC
6403The @code{(gnu services base)} module provides definitions for the basic
6404services that one expects from the system. The services exported by
6405this module are listed below.
401c53c4 6406
cf4a9129 6407@defvr {Scheme Variable} %base-services
31771497
LC
6408This variable contains a list of basic services (@pxref{Service Types
6409and Services}, for more information on service objects) one would
cf4a9129
LC
6410expect from the system: a login service (mingetty) on each tty, syslogd,
6411libc's name service cache daemon (nscd), the udev device manager, and
6412more.
401c53c4 6413
cf4a9129
LC
6414This is the default value of the @code{services} field of
6415@code{operating-system} declarations. Usually, when customizing a
6416system, you will want to append services to @var{%base-services}, like
6417this:
401c53c4 6418
cf4a9129 6419@example
fa1e31b8 6420(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
6421@end example
6422@end defvr
401c53c4 6423
be1c2c54 6424@deffn {Scheme Procedure} host-name-service @var{name}
cf4a9129
LC
6425Return a service that sets the host name to @var{name}.
6426@end deffn
401c53c4 6427
66e4f01c
LC
6428@deffn {Scheme Procedure} mingetty-service @var{config}
6429Return a service to run mingetty according to @var{config}, a
6430@code{<mingetty-configuration>} object, which specifies the tty to run, among
6431other things.
cf4a9129 6432@end deffn
401c53c4 6433
66e4f01c
LC
6434@deftp {Data Type} mingetty-configuration
6435This is the data type representing the configuration of Mingetty, which
6436implements console log-in.
6437
6438@table @asis
6439
6440@item @code{tty}
6441The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
6442
6443@item @code{motd}
6444A file-like object containing the ``message of the day''.
6445
6446@item @code{auto-login} (default: @code{#f})
6447When true, this field must be a string denoting the user name under
6448which the the system automatically logs in. When it is @code{#f}, a
6449user name and password must be entered to log in.
6450
6451@item @code{login-program} (default: @code{#f})
6452This must be either @code{#f}, in which case the default log-in program
6453is used (@command{login} from the Shadow tool suite), or a gexp denoting
6454the name of the log-in program.
6455
6456@item @code{login-pause?} (default: @code{#f})
6457When set to @code{#t} in conjunction with @var{auto-login}, the user
6458will have to press a key before the log-in shell is launched.
6459
6460@item @code{mingetty} (default: @var{mingetty})
6461The Mingetty package to use.
6462
6463@end table
6464@end deftp
6465
6454b333
LC
6466@cindex name service cache daemon
6467@cindex nscd
be1c2c54 6468@deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
4aee6e60 6469 [#:name-services '()]
b893f1ae
LC
6470Return a service that runs libc's name service cache daemon (nscd) with the
6471given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
6472Service Switch}, for an example.
cf4a9129 6473@end deffn
401c53c4 6474
6454b333
LC
6475@defvr {Scheme Variable} %nscd-default-configuration
6476This is the default @code{<nscd-configuration>} value (see below) used
6477by @code{nscd-service}. This uses the caches defined by
6478@var{%nscd-default-caches}; see below.
6479@end defvr
6480
6481@deftp {Data Type} nscd-configuration
6482This is the type representing the name service cache daemon (nscd)
6483configuration.
6484
6485@table @asis
6486
b893f1ae
LC
6487@item @code{name-services} (default: @code{'()})
6488List of packages denoting @dfn{name services} that must be visible to
6489the nscd---e.g., @code{(list @var{nss-mdns})}.
6490
6491@item @code{glibc} (default: @var{glibc})
6492Package object denoting the GNU C Library providing the @command{nscd}
6493command.
6494
6454b333
LC
6495@item @code{log-file} (default: @code{"/var/log/nscd.log"})
6496Name of nscd's log file. This is where debugging output goes when
6497@code{debug-level} is strictly positive.
6498
6499@item @code{debug-level} (default: @code{0})
6500Integer denoting the debugging levels. Higher numbers mean more
6501debugging output is logged.
6502
6503@item @code{caches} (default: @var{%nscd-default-caches})
6504List of @code{<nscd-cache>} objects denoting things to be cached; see
6505below.
6506
6507@end table
6508@end deftp
6509
6510@deftp {Data Type} nscd-cache
6511Data type representing a cache database of nscd and its parameters.
6512
6513@table @asis
6514
6515@item @code{database}
6516This is a symbol representing the name of the database to be cached.
6517Valid values are @code{passwd}, @code{group}, @code{hosts}, and
6518@code{services}, which designate the corresponding NSS database
6519(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
6520
6521@item @code{positive-time-to-live}
6522@itemx @code{negative-time-to-live} (default: @code{20})
6523A number representing the number of seconds during which a positive or
6524negative lookup result remains in cache.
6525
6526@item @code{check-files?} (default: @code{#t})
6527Whether to check for updates of the files corresponding to
6528@var{database}.
6529
6530For instance, when @var{database} is @code{hosts}, setting this flag
6531instructs nscd to check for updates in @file{/etc/hosts} and to take
6532them into account.
6533
6534@item @code{persistent?} (default: @code{#t})
6535Whether the cache should be stored persistently on disk.
6536
6537@item @code{shared?} (default: @code{#t})
6538Whether the cache should be shared among users.
6539
6540@item @code{max-database-size} (default: 32@tie{}MiB)
6541Maximum size in bytes of the database cache.
6542
6543@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
6544@c settings, so leave them out.
6545
6546@end table
6547@end deftp
6548
6549@defvr {Scheme Variable} %nscd-default-caches
6550List of @code{<nscd-cache>} objects used by default by
6551@code{nscd-configuration} (see above.)
6552
6553It enables persistent and aggressive caching of service and host name
6554lookups. The latter provides better host name lookup performance,
6555resilience in the face of unreliable name servers, and also better
6556privacy---often the result of host name lookups is in local cache, so
6557external name servers do not even need to be queried.
6558@end defvr
6559
6560
be1c2c54 6561@deffn {Scheme Procedure} syslog-service [#:config-file #f]
1bb76f75
AK
6562Return a service that runs @code{syslogd}. If configuration file name
6563@var{config-file} is not specified, use some reasonable default
cf4a9129
LC
6564settings.
6565@end deffn
401c53c4 6566
0adfe95a
LC
6567@anchor{guix-configuration-type}
6568@deftp {Data Type} guix-configuration
6569This data type represents the configuration of the Guix build daemon.
6570@xref{Invoking guix-daemon}, for more information.
6571
6572@table @asis
6573@item @code{guix} (default: @var{guix})
6574The Guix package to use.
401c53c4 6575
0adfe95a
LC
6576@item @code{build-group} (default: @code{"guixbuild"})
6577Name of the group for build user accounts.
401c53c4 6578
0adfe95a
LC
6579@item @code{build-accounts} (default: @code{10})
6580Number of build user accounts to create.
401c53c4 6581
0adfe95a
LC
6582@item @code{authorize-key?} (default: @code{#t})
6583Whether to authorize the substitute key for @code{hydra.gnu.org}
6584(@pxref{Substitutes}).
6585
6586@item @code{use-substitutes?} (default: @code{#t})
6587Whether to use substitutes.
6588
b0b9f6e0
LC
6589@item @code{substitute-urls} (default: @var{%default-substitute-urls})
6590The list of URLs where to look for substitutes by default.
6591
0adfe95a
LC
6592@item @code{extra-options} (default: @code{'()})
6593List of extra command-line options for @command{guix-daemon}.
6594
6595@item @code{lsof} (default: @var{lsof})
6596@itemx @code{lsh} (default: @var{lsh})
6597The lsof and lsh packages to use.
6598
6599@end table
6600@end deftp
6601
6602@deffn {Scheme Procedure} guix-service @var{config}
6603Return a service that runs the Guix build daemon according to
6604@var{config}.
cf4a9129 6605@end deffn
a1ba8475 6606
be1c2c54 6607@deffn {Scheme Procedure} udev-service [#:udev udev]
cf4a9129
LC
6608Run @var{udev}, which populates the @file{/dev} directory dynamically.
6609@end deffn
401c53c4 6610
be1c2c54 6611@deffn {Scheme Procedure} console-keymap-service @var{file}
5eca9459
AK
6612Return a service to load console keymap from @var{file} using
6613@command{loadkeys} command.
6614@end deffn
6615
8664cc88
LC
6616@deffn {Scheme Procedure} gpm-service-type [#:gpm @var{gpm}] @
6617 [#:options]
6618Run @var{gpm}, the general-purpose mouse daemon, with the given
6619command-line @var{options}. GPM allows users to use the mouse in the console,
6620notably to select, copy, and paste text. The default value of @var{options}
6621uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
6622
6623This service is not part of @var{%base-services}.
6624@end deffn
6625
1c52181f
LC
6626@anchor{guix-publish-service}
6627@deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
6628 [#:port 80] [#:host "localhost"]
6629Return a service that runs @command{guix publish} listening on @var{host}
6630and @var{port} (@pxref{Invoking guix publish}).
6631
6632This assumes that @file{/etc/guix} already contains a signing key pair as
6633created by @command{guix archive --generate-key} (@pxref{Invoking guix
6634archive}). If that is not the case, the service will fail to start.
6635@end deffn
6636
a69576ea 6637
cf4a9129
LC
6638@node Networking Services
6639@subsubsection Networking Services
401c53c4 6640
fa1e31b8 6641The @code{(gnu services networking)} module provides services to configure
cf4a9129 6642the network interface.
a1ba8475 6643
a023cca8 6644@cindex DHCP, networking service
be1c2c54 6645@deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
a023cca8
LC
6646Return a service that runs @var{dhcp}, a Dynamic Host Configuration
6647Protocol (DHCP) client, on all the non-loopback network interfaces.
6648@end deffn
6649
be1c2c54 6650@deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
cf4a9129
LC
6651 [#:gateway #f] [#:name-services @code{'()}]
6652Return a service that starts @var{interface} with address @var{ip}. If
6653@var{gateway} is true, it must be a string specifying the default network
6654gateway.
6655@end deffn
8b315a6d 6656
b7d0c494 6657@cindex wicd
87f40011 6658@cindex network management
be1c2c54 6659@deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
87f40011
LC
6660Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
6661management daemon that aims to simplify wired and wireless networking.
6662
6663This service adds the @var{wicd} package to the global profile, providing
6664several commands to interact with the daemon and configure networking:
6665@command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
6666and @command{wicd-curses} user interfaces.
b7d0c494
MW
6667@end deffn
6668
be1c2c54 6669@deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
63854bcb
LC
6670 [#:name-service @var{%ntp-servers}]
6671Return a service that runs the daemon from @var{ntp}, the
6672@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
6673keep the system clock synchronized with that of @var{servers}.
6674@end deffn
6675
6676@defvr {Scheme Variable} %ntp-servers
6677List of host names used as the default NTP servers.
6678@end defvr
6679
375c6108
LC
6680@deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
6681Return a service to run the @uref{https://torproject.org, Tor} anonymous
6682networking daemon.
8b315a6d 6683
375c6108 6684The daemon runs as the @code{tor} unprivileged user. It is passed
6331bde7
LC
6685@var{config-file}, a file-like object, with an additional @code{User tor} line
6686and lines for hidden services added via @code{tor-hidden-service}. Run
6687@command{man tor} for information about the configuration file.
6688@end deffn
6689
6690@deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
6691Define a new Tor @dfn{hidden service} called @var{name} and implementing
6692@var{mapping}. @var{mapping} is a list of port/host tuples, such as:
6693
6694@example
6695 '((22 \"127.0.0.1:22\")
6696 (80 \"127.0.0.1:8080\"))
6697@end example
6698
6699In this example, port 22 of the hidden service is mapped to local port 22, and
6700port 80 is mapped to local port 8080.
6701
6629099a
LC
6702This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
6703the @file{hostname} file contains the @code{.onion} host name for the hidden
6331bde7
LC
6704service.
6705
6706See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
6707project's documentation} for more information.
cf4a9129 6708@end deffn
8b315a6d 6709
be1c2c54 6710@deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
4627a464
LC
6711 [#:interface "127.0.0.1"] [#:port 6667] @
6712 [#:extra-settings ""]
6713Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
6714acts as a gateway between IRC and chat networks.
6715
6716The daemon will listen to the interface corresponding to the IP address
6717specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
6718local clients can connect, whereas @code{0.0.0.0} means that connections can
6719come from any networking interface.
6720
6721In addition, @var{extra-settings} specifies a string to append to the
6722configuration file.
6723@end deffn
6724
f4391bec 6725Furthermore, @code{(gnu services ssh)} provides the following service.
8b315a6d 6726
be1c2c54 6727@deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 6728 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
6729 [#:allow-empty-passwords? #f] [#:root-login? #f] @
6730 [#:syslog-output? #t] [#:x11-forwarding? #t] @
6731 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 6732 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
6733Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
6734@var{host-key} must designate a file containing the host key, and readable
6735only by root.
72e25e35 6736
5833bf33
DP
6737When @var{daemonic?} is true, @command{lshd} will detach from the
6738controlling terminal and log its output to syslogd, unless one sets
6739@var{syslog-output?} to false. Obviously, it also makes lsh-service
6740depend on existence of syslogd service. When @var{pid-file?} is true,
6741@command{lshd} writes its PID to the file called @var{pid-file}.
6742
cf4a9129
LC
6743When @var{initialize?} is true, automatically create the seed and host key
6744upon service activation if they do not exist yet. This may take long and
6745require interaction.
8b315a6d 6746
20dd519c
LC
6747When @var{initialize?} is false, it is up to the user to initialize the
6748randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
6749a key pair with the private key stored in file @var{host-key} (@pxref{lshd
6750basics,,, lsh, LSH Manual}).
6751
cf4a9129
LC
6752When @var{interfaces} is empty, lshd listens for connections on all the
6753network interfaces; otherwise, @var{interfaces} must be a list of host names
6754or addresses.
9bf3c1a7 6755
20dd519c
LC
6756@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
6757passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 6758root.
4af2447e 6759
cf4a9129
LC
6760The other options should be self-descriptive.
6761@end deffn
4af2447e 6762
fa0c1d61
LC
6763@defvr {Scheme Variable} %facebook-host-aliases
6764This variable contains a string for use in @file{/etc/hosts}
6765(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
6766line contains a entry that maps a known server name of the Facebook
6767on-line service---e.g., @code{www.facebook.com}---to the local
6768host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
6769
6770This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
6771@code{operating-system} declaration (@pxref{operating-system Reference,
6772@file{/etc/hosts}}):
fa0c1d61
LC
6773
6774@example
6775(use-modules (gnu) (guix))
6776
6777(operating-system
6778 (host-name "mymachine")
6779 ;; ...
6780 (hosts-file
6781 ;; Create a /etc/hosts file with aliases for "localhost"
6782 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
6783 (plain-file "hosts"
6784 (string-append (local-host-aliases host-name)
6785 %facebook-host-aliases))))
fa0c1d61
LC
6786@end example
6787
6788This mechanism can prevent programs running locally, such as Web
6789browsers, from accessing Facebook.
6790@end defvr
6791
965a7332
LC
6792The @code{(gnu services avahi)} provides the following definition.
6793
be1c2c54 6794@deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
965a7332
LC
6795 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
6796 [#:ipv6? #t] [#:wide-area? #f] @
6797 [#:domains-to-browse '()]
6798Return a service that runs @command{avahi-daemon}, a system-wide
6799mDNS/DNS-SD responder that allows for service discovery and
cc9c1f39
LC
6800"zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
6801extends the name service cache daemon (nscd) so that it can resolve
6802@code{.local} host names using
1065bed9
LC
6803@uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
6804add the @var{avahi} package to the system profile so that commands such as
6805@command{avahi-browse} are directly usable.
965a7332
LC
6806
6807If @var{host-name} is different from @code{#f}, use that as the host name to
6808publish for this machine; otherwise, use the machine's actual host name.
6809
6810When @var{publish?} is true, publishing of host names and services is allowed;
6811in particular, avahi-daemon will publish the machine's host name and IP
6812address via mDNS on the local network.
6813
6814When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
6815
6816Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
6817sockets.
6818@end deffn
6819
6820
cf4a9129
LC
6821@node X Window
6822@subsubsection X Window
68ad877c 6823
cf4a9129
LC
6824Support for the X Window graphical display system---specifically
6825Xorg---is provided by the @code{(gnu services xorg)} module. Note that
6826there is no @code{xorg-service} procedure. Instead, the X server is
6827started by the @dfn{login manager}, currently SLiM.
4af2447e 6828
be1c2c54 6829@deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
6830 [#:auto-login? #f] [#:default-user ""] [#:startx] @
6831 [#:theme @var{%default-slim-theme}] @
4bd43bbe 6832 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
6833Return a service that spawns the SLiM graphical login manager, which in
6834turn starts the X display server with @var{startx}, a command as returned by
6835@code{xorg-start-command}.
4af2447e 6836
04e4e6ab
LC
6837@cindex X session
6838
6839SLiM automatically looks for session types described by the @file{.desktop}
6840files in @file{/run/current-system/profile/share/xsessions} and allows users
6841to choose a session from the log-in screen using @kbd{F1}. Packages such as
6842@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
6843adding them to the system-wide set of packages automatically makes them
6844available at the log-in screen.
6845
6846In addition, @file{~/.xsession} files are honored. When available,
6847@file{~/.xsession} must be an executable that starts a window manager
6848and/or other X clients.
6849
cf4a9129
LC
6850When @var{allow-empty-passwords?} is true, allow logins with an empty
6851password. When @var{auto-login?} is true, log in automatically as
6852@var{default-user}.
0ecc3bf3
LC
6853
6854If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
6855@var{theme} must be a gexp denoting the name of a directory containing the
6856theme to use. In that case, @var{theme-name} specifies the name of the
6857theme.
cf4a9129 6858@end deffn
4af2447e 6859
0ecc3bf3
LC
6860@defvr {Scheme Variable} %default-theme
6861@defvrx {Scheme Variable} %default-theme-name
6862The G-Expression denoting the default SLiM theme and its name.
6863@end defvr
6864
be1c2c54 6865@deffn {Scheme Procedure} xorg-start-command [#:guile] @
d1cdd7ba 6866 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 6867Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
6868from @var{xorg-server}. @var{configuration-file} is the server configuration
6869file or a derivation that builds it; when omitted, the result of
6870@code{xorg-configuration-file} is used.
6871
6872Usually the X server is started by a login manager.
6873@end deffn
6874
be1c2c54 6875@deffn {Scheme Procedure} xorg-configuration-file @
12422c9d 6876 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
6877Return a configuration file for the Xorg server containing search paths for
6878all the common drivers.
f703413e
LC
6879
6880@var{drivers} must be either the empty list, in which case Xorg chooses a
6881graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 6882this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
6883
6884Likewise, when @var{resolutions} is the empty list, Xorg chooses an
6885appropriate screen resolution; otherwise, it must be a list of
6886resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
6887
6888Last, @var{extra-config} is a list of strings or objects appended to the
6889@code{text-file*} argument list. It is used to pass extra text to be added
6890verbatim to the configuration file.
f703413e 6891@end deffn
4af2447e 6892
6726282b
LC
6893@deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
6894Add @var{package}, a package for a screen-locker or screen-saver whose
6895command is @var{program}, to the set of setuid programs and add a PAM entry
6896for it. For example:
6897
6898@lisp
6899(screen-locker-service xlockmore "xlock")
6900@end lisp
6901
6902makes the good ol' XlockMore usable.
6903@end deffn
6904
6905
fe1a39d3
LC
6906@node Desktop Services
6907@subsubsection Desktop Services
aa4ed923 6908
fe1a39d3
LC
6909The @code{(gnu services desktop)} module provides services that are
6910usually useful in the context of a ``desktop'' setup---that is, on a
6911machine running a graphical display server, possibly with graphical user
6912interfaces, etc.
aa4ed923 6913
4467be21
LC
6914To simplify things, the module defines a variable containing the set of
6915services that users typically expect on a machine with a graphical
6916environment and networking:
6917
6918@defvr {Scheme Variable} %desktop-services
6919This is a list of services that builds upon @var{%base-services} and
6920adds or adjust services for a typical ``desktop'' setup.
6921
6922In particular, it adds a graphical login manager (@pxref{X Window,
6726282b
LC
6923@code{slim-service}}), screen lockers,
6924a network management tool (@pxref{Networking
4467be21 6925Services, @code{wicd-service}}), energy and color management services,
4650a77e 6926the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
6927the GeoClue location service, an NTP client (@pxref{Networking
6928Services}), the Avahi daemon, and has the name service switch service
6929configured to be able to use @code{nss-mdns} (@pxref{Name Service
6930Switch, mDNS}).
4467be21
LC
6931@end defvr
6932
6933The @var{%desktop-services} variable can be used as the @code{services}
6934field of an @code{operating-system} declaration (@pxref{operating-system
6935Reference, @code{services}}).
6936
0adfe95a
LC
6937The actual service definitions provided by @code{(gnu services dbus)}
6938and @code{(gnu services desktop)} are described below.
4467be21 6939
0adfe95a 6940@deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
fe1a39d3
LC
6941Return a service that runs the ``system bus'', using @var{dbus}, with
6942support for @var{services}.
aa4ed923 6943
fe1a39d3
LC
6944@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
6945facility. Its system bus is used to allow system services to communicate
6946and be notified of system-wide events.
aa4ed923 6947
fe1a39d3
LC
6948@var{services} must be a list of packages that provide an
6949@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
6950and policy files. For example, to allow avahi-daemon to use the system bus,
6951@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
6952@end deffn
6953
0adfe95a 6954@deffn {Scheme Procedure} elogind-service [#:config @var{config}]
4650a77e
AW
6955Return a service that runs the @code{elogind} login and
6956seat management daemon. @uref{https://github.com/andywingo/elogind,
6957Elogind} exposes a D-Bus interface that can be used to know which users
6958are logged in, know what kind of sessions they have open, suspend the
6959system, inhibit system suspend, reboot the system, and other tasks.
6960
6961Elogind handles most system-level power events for a computer, for
6962example suspending the system when a lid is closed, or shutting it down
6963when the power button is pressed.
6964
6965The @var{config} keyword argument specifies the configuration for
6966elogind, and should be the result of a @code{(elogind-configuration
6967(@var{parameter} @var{value})...)} invocation. Available parameters and
6968their default values are:
6969
6970@table @code
6971@item kill-user-processes?
6972@code{#f}
6973@item kill-only-users
6974@code{()}
6975@item kill-exclude-users
6976@code{("root")}
6977@item inhibit-delay-max-seconds
6978@code{5}
6979@item handle-power-key
6980@code{poweroff}
6981@item handle-suspend-key
6982@code{suspend}
6983@item handle-hibernate-key
6984@code{hibernate}
6985@item handle-lid-switch
6986@code{suspend}
6987@item handle-lid-switch-docked
6988@code{ignore}
6989@item power-key-ignore-inhibited?
6990@code{#f}
6991@item suspend-key-ignore-inhibited?
6992@code{#f}
6993@item hibernate-key-ignore-inhibited?
6994@code{#f}
6995@item lid-switch-ignore-inhibited?
6996@code{#t}
6997@item holdoff-timeout-seconds
6998@code{30}
6999@item idle-action
7000@code{ignore}
7001@item idle-action-seconds
7002@code{(* 30 60)}
7003@item runtime-directory-size-percent
7004@code{10}
7005@item runtime-directory-size
7006@code{#f}
7007@item remove-ipc?
7008@code{#t}
7009@item suspend-state
7010@code{("mem" "standby" "freeze")}
7011@item suspend-mode
7012@code{()}
7013@item hibernate-state
7014@code{("disk")}
7015@item hibernate-mode
7016@code{("platform" "shutdown")}
7017@item hybrid-sleep-state
7018@code{("disk")}
7019@item hybrid-sleep-mode
7020@code{("suspend" "platform" "shutdown")}
7021@end table
7022@end deffn
7023
be1c2c54 7024@deffn {Scheme Procedure} polkit-service @
4650a77e 7025 [#:polkit @var{polkit}]
222e3319
LC
7026Return a service that runs the
7027@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
7028management service}, which allows system administrators to grant access to
7029privileged operations in a structured way. By querying the Polkit service, a
7030privileged system component can know when it should grant additional
7031capabilities to ordinary users. For example, an ordinary user can be granted
7032the capability to suspend the system if the user is logged in locally.
4650a77e
AW
7033@end deffn
7034
be1c2c54 7035@deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
be234128
AW
7036 [#:watts-up-pro? #f] @
7037 [#:poll-batteries? #t] @
7038 [#:ignore-lid? #f] @
7039 [#:use-percentage-for-policy? #f] @
7040 [#:percentage-low 10] @
7041 [#:percentage-critical 3] @
7042 [#:percentage-action 2] @
7043 [#:time-low 1200] @
7044 [#:time-critical 300] @
7045 [#:time-action 120] @
7046 [#:critical-power-action 'hybrid-sleep]
7047Return a service that runs @uref{http://upower.freedesktop.org/,
7048@command{upowerd}}, a system-wide monitor for power consumption and battery
7049levels, with the given configuration settings. It implements the
7050@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
7051GNOME.
7052@end deffn
7053
2b9e0a94
LC
7054@deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
7055Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
7056UDisks}, a @dfn{disk management} daemon that provides user interfaces with
7057notifications and ways to mount/unmount disks. Programs that talk to UDisks
7058include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
7059@end deffn
7060
be1c2c54 7061@deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7ce597ff
AW
7062Return a service that runs @command{colord}, a system service with a D-Bus
7063interface to manage the color profiles of input and output devices such as
7064screens and scanners. It is notably used by the GNOME Color Manager graphical
7065tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
7066site} for more information.
7067@end deffn
7068
cee32ee4
AW
7069@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
7070Return an configuration allowing an application to access GeoClue
7071location data. @var{name} is the Desktop ID of the application, without
7072the @code{.desktop} part. If @var{allowed?} is true, the application
7073will have access to location information by default. The boolean
7074@var{system?} value indicates that an application is a system component
7075or not. Finally @var{users} is a list of UIDs of all users for which
7076this application is allowed location info access. An empty users list
7077means that all users are allowed.
7078@end deffn
7079
7080@defvr {Scheme Variable} %standard-geoclue-applications
7081The standard list of well-known GeoClue application configurations,
7082granting authority to GNOME's date-and-time utility to ask for the
7083current location in order to set the time zone, and allowing the Firefox
7084(IceCat) and Epiphany web browsers to request location information.
7085Firefox and Epiphany both query the user before allowing a web page to
7086know the user's location.
7087@end defvr
7088
be1c2c54 7089@deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
cee32ee4
AW
7090 [#:whitelist '()] @
7091 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
7092 [#:submit-data? #f]
7093 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
7094 [#:submission-nick "geoclue"] @
7095 [#:applications %standard-geoclue-applications]
7096Return a service that runs the GeoClue location service. This service
7097provides a D-Bus interface to allow applications to request access to a
7098user's physical location, and optionally to add information to online
7099location databases. See
7100@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
7101web site} for more information.
7102@end deffn
7103
105369a4
DT
7104@node Database Services
7105@subsubsection Database Services
7106
7107The @code{(gnu services databases)} module provides the following service.
7108
be1c2c54 7109@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
105369a4
DT
7110 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
7111Return a service that runs @var{postgresql}, the PostgreSQL database
7112server.
7113
7114The PostgreSQL daemon loads its runtime configuration from
7115@var{config-file} and stores the database cluster in
7116@var{data-directory}.
7117@end deffn
fe1a39d3 7118
d8c18af8
AW
7119@node Mail Services
7120@subsubsection Mail Services
7121
7122The @code{(gnu services mail)} module provides Guix service definitions
7123for mail services. Currently the only implemented service is Dovecot,
7124an IMAP, POP3, and LMTP server.
7125
7126Guix does not yet have a mail transfer agent (MTA), although for some
7127lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
7128is needed to properly integrate a full MTA, such as Postfix. Patches
7129welcome!
7130
7131To add an IMAP/POP3 server to a GuixSD system, add a
7132@code{dovecot-service} to the operating system definition:
7133
7134@deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
7135Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
7136@end deffn
7137
7138By default, Dovecot doesn't need much configuration; the default
7139configuration object created by @code{(dovecot-configuration)} will
7140suffice if your mail is delivered to @code{~/Maildir}. A self-signed
7141certificate will be generated for TLS-protected connections, though
7142Dovecot will also listen on cleartext ports by default. There are a
7143number of options though which mail administrators might need to change,
7144and as is the case with other services, Guix allows the system
7145administrator to specify these parameters via a uniform Scheme interface.
7146
7147For example, to specify that mail is located at @code{maildir~/.mail},
7148one would instantiate the Dovecot service like this:
7149
7150@example
7151(dovecot-service #:config
7152 (dovecot-configuration
7153 (mail-location "maildir:~/.mail")))
7154@end example
7155
7156The available configuration parameters follow. Each parameter
7157definition is preceded by its type; for example, @samp{string-list foo}
7158indicates that the @code{foo} parameter should be specified as a list of
7159strings. There is also a way to specify the configuration as a string,
7160if you have an old @code{dovecot.conf} file that you want to port over
7161from some other system; see the end for more details.
7162
7163@c The following documentation was initially generated by
7164@c (generate-documentation) in (gnu services mail). Manually maintained
7165@c documentation is better, so we shouldn't hesitate to edit below as
7166@c needed. However if the change you want to make to this documentation
7167@c can be done in an automated way, it's probably easier to change
7168@c (generate-documentation) than to make it below and have to deal with
7169@c the churn as dovecot updates.
7170
7171Available @code{dovecot-configuration} fields are:
7172
7173@deftypevr {@code{dovecot-configuration} parameter} package dovecot
7174The dovecot package.
7175@end deftypevr
7176
7177@deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
7178A list of IPs or hosts where to listen in for connections. @samp{*}
7179listens in all IPv4 interfaces, @samp{::} listens in all IPv6
7180interfaces. If you want to specify non-default ports or anything more
7181complex, customize the address and port fields of the
7182@samp{inet-listener} of the specific services you are interested in.
7183@end deftypevr
7184
7185@deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
7186List of protocols we want to serve. Available protocols include
7187@samp{imap}, @samp{pop3}, and @samp{lmtp}.
7188
7189Available @code{protocol-configuration} fields are:
7190
7191@deftypevr {@code{protocol-configuration} parameter} string name
7192The name of the protocol.
7193@end deftypevr
7194
7195@deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
7196UNIX socket path to master authentication server to find users.
7197This is used by imap (for shared users) and lda.
7198Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
7199@end deftypevr
7200
7201@deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
7202Space separated list of plugins to load.
7203@end deftypevr
7204
7205@deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
7206Maximum number of IMAP connections allowed for a user from each IP
7207address. NOTE: The username is compared case-sensitively.
7208Defaults to @samp{10}.
7209@end deftypevr
7210
7211@end deftypevr
7212
7213@deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
7214List of services to enable. Available services include @samp{imap},
7215@samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
7216@samp{lmtp}.
7217
7218Available @code{service-configuration} fields are:
7219
7220@deftypevr {@code{service-configuration} parameter} string kind
7221The service kind. Valid values include @code{director},
7222@code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
7223@code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
7224@code{tcpwrap}, @code{quota-warning}, or anything else.
7225@end deftypevr
7226
7227@deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
7228Listeners for the service. A listener is either an
7229@code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
7230an @code{inet-listener-configuration}.
7231Defaults to @samp{()}.
7232
7233Available @code{unix-listener-configuration} fields are:
7234
7235@deftypevr {@code{unix-listener-configuration} parameter} file-name path
7236The file name on which to listen.
7237@end deftypevr
7238
7239@deftypevr {@code{unix-listener-configuration} parameter} string mode
7240The access mode for the socket.
7241Defaults to @samp{"0600"}.
7242@end deftypevr
7243
7244@deftypevr {@code{unix-listener-configuration} parameter} string user
7245The user to own the the socket.
7246Defaults to @samp{""}.
7247@end deftypevr
7248
7249@deftypevr {@code{unix-listener-configuration} parameter} string group
7250The group to own the socket.
7251Defaults to @samp{""}.
7252@end deftypevr
7253
7254
7255Available @code{fifo-listener-configuration} fields are:
7256
7257@deftypevr {@code{fifo-listener-configuration} parameter} file-name path
7258The file name on which to listen.
7259@end deftypevr
7260
7261@deftypevr {@code{fifo-listener-configuration} parameter} string mode
7262The access mode for the socket.
7263Defaults to @samp{"0600"}.
7264@end deftypevr
7265
7266@deftypevr {@code{fifo-listener-configuration} parameter} string user
7267The user to own the the socket.
7268Defaults to @samp{""}.
7269@end deftypevr
7270
7271@deftypevr {@code{fifo-listener-configuration} parameter} string group
7272The group to own the socket.
7273Defaults to @samp{""}.
7274@end deftypevr
7275
7276
7277Available @code{inet-listener-configuration} fields are:
7278
7279@deftypevr {@code{inet-listener-configuration} parameter} string protocol
7280The protocol to listen for.
7281@end deftypevr
7282
7283@deftypevr {@code{inet-listener-configuration} parameter} string address
7284The address on which to listen, or empty for all addresses.
7285Defaults to @samp{""}.
7286@end deftypevr
7287
7288@deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
7289The port on which to listen.
7290@end deftypevr
7291
7292@deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
7293Whether to use SSL for this service; @samp{yes}, @samp{no}, or
7294@samp{required}.
7295Defaults to @samp{#t}.
7296@end deftypevr
7297
7298@end deftypevr
7299
7300@deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
7301Number of connections to handle before starting a new process.
7302Typically the only useful values are 0 (unlimited) or 1. 1 is more
7303secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
7304Defaults to @samp{1}.
7305@end deftypevr
7306
7307@deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
7308Number of processes to always keep waiting for more connections.
7309Defaults to @samp{0}.
7310@end deftypevr
7311
7312@deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
7313If you set @samp{service-count 0}, you probably need to grow
7314this.
7315Defaults to @samp{256000000}.
7316@end deftypevr
7317
7318@end deftypevr
7319
7320@deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
7321Dict configuration, as created by the @code{dict-configuration}
7322constructor.
7323
7324Available @code{dict-configuration} fields are:
7325
7326@deftypevr {@code{dict-configuration} parameter} free-form-fields entries
7327A list of key-value pairs that this dict should hold.
7328Defaults to @samp{()}.
7329@end deftypevr
7330
7331@end deftypevr
7332
7333@deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
7334List of passdb configurations, each one created by the
7335@code{passdb-configuration} constructor.
7336
7337Available @code{passdb-configuration} fields are:
7338
7339@deftypevr {@code{passdb-configuration} parameter} string driver
7340The driver that the passdb should use. Valid values include
7341@samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
7342@samp{static}.
7343Defaults to @samp{"pam"}.
7344@end deftypevr
7345
7346@deftypevr {@code{passdb-configuration} parameter} free-form-args args
7347A list of key-value args to the passdb driver.
7348Defaults to @samp{()}.
7349@end deftypevr
7350
7351@end deftypevr
7352
7353@deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
7354List of userdb configurations, each one created by the
7355@code{userdb-configuration} constructor.
7356
7357Available @code{userdb-configuration} fields are:
7358
7359@deftypevr {@code{userdb-configuration} parameter} string driver
7360The driver that the userdb should use. Valid values include
7361@samp{passwd} and @samp{static}.
7362Defaults to @samp{"passwd"}.
7363@end deftypevr
7364
7365@deftypevr {@code{userdb-configuration} parameter} free-form-args args
7366A list of key-value args to the userdb driver.
7367Defaults to @samp{()}.
7368@end deftypevr
7369
7370@deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
7371Override fields from passwd.
7372Defaults to @samp{()}.
7373@end deftypevr
7374
7375@end deftypevr
7376
7377@deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
7378Plug-in configuration, created by the @code{plugin-configuration}
7379constructor.
7380@end deftypevr
7381
7382@deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
7383List of namespaces. Each item in the list is created by the
7384@code{namespace-configuration} constructor.
7385
7386Available @code{namespace-configuration} fields are:
7387
7388@deftypevr {@code{namespace-configuration} parameter} string name
7389Name for this namespace.
7390@end deftypevr
7391
7392@deftypevr {@code{namespace-configuration} parameter} string type
7393Namespace type: @samp{private}, @samp{shared} or @samp{public}.
7394Defaults to @samp{"private"}.
7395@end deftypevr
7396
7397@deftypevr {@code{namespace-configuration} parameter} string separator
7398Hierarchy separator to use. You should use the same separator for
7399all namespaces or some clients get confused. @samp{/} is usually a good
7400one. The default however depends on the underlying mail storage
7401format.
7402Defaults to @samp{""}.
7403@end deftypevr
7404
7405@deftypevr {@code{namespace-configuration} parameter} string prefix
7406Prefix required to access this namespace. This needs to be
7407different for all namespaces. For example @samp{Public/}.
7408Defaults to @samp{""}.
7409@end deftypevr
7410
7411@deftypevr {@code{namespace-configuration} parameter} string location
7412Physical location of the mailbox. This is in same format as
7413mail_location, which is also the default for it.
7414Defaults to @samp{""}.
7415@end deftypevr
7416
7417@deftypevr {@code{namespace-configuration} parameter} boolean inbox?
7418There can be only one INBOX, and this setting defines which
7419namespace has it.
7420Defaults to @samp{#f}.
7421@end deftypevr
7422
7423@deftypevr {@code{namespace-configuration} parameter} boolean hidden?
7424If namespace is hidden, it's not advertised to clients via NAMESPACE
7425extension. You'll most likely also want to set @samp{list? #f}. This is mostly
7426useful when converting from another server with different namespaces
7427which you want to deprecate but still keep working. For example you can
7428create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
7429and @samp{mail/}.
7430Defaults to @samp{#f}.
7431@end deftypevr
7432
7433@deftypevr {@code{namespace-configuration} parameter} boolean list?
7434Show the mailboxes under this namespace with LIST command. This
7435makes the namespace visible for clients that don't support NAMESPACE
7436extension. The special @code{children} value lists child mailboxes, but
7437hides the namespace prefix.
7438Defaults to @samp{#t}.
7439@end deftypevr
7440
7441@deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
7442Namespace handles its own subscriptions. If set to @code{#f}, the
7443parent namespace handles them. The empty prefix should always have this
7444as @code{#t}.)
7445Defaults to @samp{#t}.
7446@end deftypevr
7447
7448@deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
7449List of predefined mailboxes in this namespace.
7450Defaults to @samp{()}.
7451
7452Available @code{mailbox-configuration} fields are:
7453
7454@deftypevr {@code{mailbox-configuration} parameter} string name
7455Name for this mailbox.
7456@end deftypevr
7457
7458@deftypevr {@code{mailbox-configuration} parameter} string auto
7459@samp{create} will automatically create this mailbox.
7460@samp{subscribe} will both create and subscribe to the mailbox.
7461Defaults to @samp{"no"}.
7462@end deftypevr
7463
7464@deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
7465List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
7466Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
7467@code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
7468Defaults to @samp{()}.
7469@end deftypevr
7470
7471@end deftypevr
7472
7473@end deftypevr
7474
7475@deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
7476Base directory where to store runtime data.
7477Defaults to @samp{"/var/run/dovecot/"}.
7478@end deftypevr
7479
7480@deftypevr {@code{dovecot-configuration} parameter} string login-greeting
7481Greeting message for clients.
7482Defaults to @samp{"Dovecot ready."}.
7483@end deftypevr
7484
7485@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
7486List of trusted network ranges. Connections from these IPs are
7487allowed to override their IP addresses and ports (for logging and for
7488authentication checks). @samp{disable-plaintext-auth} is also ignored
7489for these networks. Typically you'd specify your IMAP proxy servers
7490here.
7491Defaults to @samp{()}.
7492@end deftypevr
7493
7494@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
7495List of login access check sockets (e.g. tcpwrap).
7496Defaults to @samp{()}.
7497@end deftypevr
7498
7499@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
7500Show more verbose process titles (in ps). Currently shows user name
7501and IP address. Useful for seeing who are actually using the IMAP
7502processes (e.g. shared mailboxes or if same uid is used for multiple
7503accounts).
7504Defaults to @samp{#f}.
7505@end deftypevr
7506
7507@deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
7508Should all processes be killed when Dovecot master process shuts down.
7509Setting this to @code{#f} means that Dovecot can be upgraded without
7510forcing existing client connections to close (although that could also
7511be a problem if the upgrade is e.g. because of a security fix).
7512Defaults to @samp{#t}.
7513@end deftypevr
7514
7515@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
7516If non-zero, run mail commands via this many connections to doveadm
7517server, instead of running them directly in the same process.
7518Defaults to @samp{0}.
7519@end deftypevr
7520
7521@deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
7522UNIX socket or host:port used for connecting to doveadm server.
7523Defaults to @samp{"doveadm-server"}.
7524@end deftypevr
7525
7526@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
7527List of environment variables that are preserved on Dovecot startup
7528and passed down to all of its child processes. You can also give
7529key=value pairs to always set specific settings.
7530@end deftypevr
7531
7532@deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
7533Disable LOGIN command and all other plaintext authentications unless
7534SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
7535matches the local IP (i.e. you're connecting from the same computer),
7536the connection is considered secure and plaintext authentication is
7537allowed. See also ssl=required setting.
7538Defaults to @samp{#t}.
7539@end deftypevr
7540
7541@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
7542Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
7543Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
7544for caching to be used.
7545Defaults to @samp{0}.
7546@end deftypevr
7547
7548@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
7549Time to live for cached data. After TTL expires the cached record
7550is no longer used, *except* if the main database lookup returns internal
7551failure. We also try to handle password changes automatically: If
7552user's previous authentication was successful, but this one wasn't, the
7553cache isn't used. For now this works only with plaintext
7554authentication.
7555Defaults to @samp{"1 hour"}.
7556@end deftypevr
7557
7558@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
7559TTL for negative hits (user not found, password mismatch).
75600 disables caching them completely.
7561Defaults to @samp{"1 hour"}.
7562@end deftypevr
7563
7564@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
7565List of realms for SASL authentication mechanisms that need them.
7566You can leave it empty if you don't want to support multiple realms.
7567Many clients simply use the first one listed here, so keep the default
7568realm first.
7569Defaults to @samp{()}.
7570@end deftypevr
7571
7572@deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
7573Default realm/domain to use if none was specified. This is used for
7574both SASL realms and appending @@domain to username in plaintext
7575logins.
7576Defaults to @samp{""}.
7577@end deftypevr
7578
7579@deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
7580List of allowed characters in username. If the user-given username
7581contains a character not listed in here, the login automatically fails.
7582This is just an extra check to make sure user can't exploit any
7583potential quote escaping vulnerabilities with SQL/LDAP databases. If
7584you want to allow all characters, set this value to empty.
7585Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
7586@end deftypevr
7587
7588@deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
7589Username character translations before it's looked up from
7590databases. The value contains series of from -> to characters. For
7591example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
7592translated to @samp{@@}.
7593Defaults to @samp{""}.
7594@end deftypevr
7595
7596@deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
7597Username formatting before it's looked up from databases. You can
7598use the standard variables here, e.g. %Lu would lowercase the username,
7599%n would drop away the domain if it was given, or @samp{%n-AT-%d} would
7600change the @samp{@@} into @samp{-AT-}. This translation is done after
7601@samp{auth-username-translation} changes.
7602Defaults to @samp{"%Lu"}.
7603@end deftypevr
7604
7605@deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
7606If you want to allow master users to log in by specifying the master
7607username within the normal username string (i.e. not using SASL
7608mechanism's support for it), you can specify the separator character
7609here. The format is then <username><separator><master username>.
7610UW-IMAP uses @samp{*} as the separator, so that could be a good
7611choice.
7612Defaults to @samp{""}.
7613@end deftypevr
7614
7615@deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
7616Username to use for users logging in with ANONYMOUS SASL
7617mechanism.
7618Defaults to @samp{"anonymous"}.
7619@end deftypevr
7620
7621@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
7622Maximum number of dovecot-auth worker processes. They're used to
7623execute blocking passdb and userdb queries (e.g. MySQL and PAM).
7624They're automatically created and destroyed as needed.
7625Defaults to @samp{30}.
7626@end deftypevr
7627
7628@deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
7629Host name to use in GSSAPI principal names. The default is to use
7630the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
7631allow all keytab entries.
7632Defaults to @samp{""}.
7633@end deftypevr
7634
7635@deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
7636Kerberos keytab to use for the GSSAPI mechanism. Will use the
7637system default (usually /etc/krb5.keytab) if not specified. You may
7638need to change the auth service to run as root to be able to read this
7639file.
7640Defaults to @samp{""}.
7641@end deftypevr
7642
7643@deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
7644Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
7645and @samp{ntlm-auth} helper.
7646<doc/wiki/Authentication/Mechanisms/Winbind.txt>.
7647Defaults to @samp{#f}.
7648@end deftypevr
7649
7650@deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
7651Path for Samba's @samp{ntlm-auth} helper binary.
7652Defaults to @samp{"/usr/bin/ntlm_auth"}.
7653@end deftypevr
7654
7655@deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
7656Time to delay before replying to failed authentications.
7657Defaults to @samp{"2 secs"}.
7658@end deftypevr
7659
7660@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
7661Require a valid SSL client certificate or the authentication
7662fails.
7663Defaults to @samp{#f}.
7664@end deftypevr
7665
7666@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
7667Take the username from client's SSL certificate, using
7668@code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
7669CommonName.
7670Defaults to @samp{#f}.
7671@end deftypevr
7672
7673@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
7674List of wanted authentication mechanisms. Supported mechanisms are:
7675@samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
7676@samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
7677@samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
7678@samp{disable-plaintext-auth} setting.
7679@end deftypevr
7680
7681@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
7682List of IPs or hostnames to all director servers, including ourself.
7683Ports can be specified as ip:port. The default port is the same as what
7684director service's @samp{inet-listener} is using.
7685Defaults to @samp{()}.
7686@end deftypevr
7687
7688@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
7689List of IPs or hostnames to all backend mail servers. Ranges are
7690allowed too, like 10.0.0.10-10.0.0.30.
7691Defaults to @samp{()}.
7692@end deftypevr
7693
7694@deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
7695How long to redirect users to a specific server after it no longer
7696has any connections.
7697Defaults to @samp{"15 min"}.
7698@end deftypevr
7699
7700@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
7701TCP/IP port that accepts doveadm connections (instead of director
7702connections) If you enable this, you'll also need to add
7703@samp{inet-listener} for the port.
7704Defaults to @samp{0}.
7705@end deftypevr
7706
7707@deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
7708How the username is translated before being hashed. Useful values
7709include %Ln if user can log in with or without @@domain, %Ld if mailboxes
7710are shared within domain.
7711Defaults to @samp{"%Lu"}.
7712@end deftypevr
7713
7714@deftypevr {@code{dovecot-configuration} parameter} string log-path
7715Log file to use for error messages. @samp{syslog} logs to syslog,
7716@samp{/dev/stderr} logs to stderr.
7717Defaults to @samp{"syslog"}.
7718@end deftypevr
7719
7720@deftypevr {@code{dovecot-configuration} parameter} string info-log-path
7721Log file to use for informational messages. Defaults to
7722@samp{log-path}.
7723Defaults to @samp{""}.
7724@end deftypevr
7725
7726@deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
7727Log file to use for debug messages. Defaults to
7728@samp{info-log-path}.
7729Defaults to @samp{""}.
7730@end deftypevr
7731
7732@deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
7733Syslog facility to use if you're logging to syslog. Usually if you
7734don't want to use @samp{mail}, you'll use local0..local7. Also other
7735standard facilities are supported.
7736Defaults to @samp{"mail"}.
7737@end deftypevr
7738
7739@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
7740Log unsuccessful authentication attempts and the reasons why they
7741failed.
7742Defaults to @samp{#f}.
7743@end deftypevr
7744
7745@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
7746In case of password mismatches, log the attempted password. Valid
7747values are no, plain and sha1. sha1 can be useful for detecting brute
7748force password attempts vs. user simply trying the same password over
7749and over again. You can also truncate the value to n chars by appending
7750":n" (e.g. sha1:6).
7751Defaults to @samp{#f}.
7752@end deftypevr
7753
7754@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
7755Even more verbose logging for debugging purposes. Shows for example
7756SQL queries.
7757Defaults to @samp{#f}.
7758@end deftypevr
7759
7760@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
7761In case of password mismatches, log the passwords and used scheme so
7762the problem can be debugged. Enabling this also enables
7763@samp{auth-debug}.
7764Defaults to @samp{#f}.
7765@end deftypevr
7766
7767@deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
7768Enable mail process debugging. This can help you figure out why
7769Dovecot isn't finding your mails.
7770Defaults to @samp{#f}.
7771@end deftypevr
7772
7773@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
7774Show protocol level SSL errors.
7775Defaults to @samp{#f}.
7776@end deftypevr
7777
7778@deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
7779Prefix for each line written to log file. % codes are in
7780strftime(3) format.
7781Defaults to @samp{"\"%b %d %H:%M:%S \""}.
7782@end deftypevr
7783
7784@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
7785List of elements we want to log. The elements which have a
7786non-empty variable value are joined together to form a comma-separated
7787string.
7788@end deftypevr
7789
7790@deftypevr {@code{dovecot-configuration} parameter} string login-log-format
7791Login log format. %s contains @samp{login-log-format-elements}
7792string, %$ contains the data we want to log.
7793Defaults to @samp{"%$: %s"}.
7794@end deftypevr
7795
7796@deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
7797Log prefix for mail processes. See doc/wiki/Variables.txt for list
7798of possible variables you can use.
7799Defaults to @samp{"\"%s(%u): \""}.
7800@end deftypevr
7801
7802@deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
7803Format to use for logging mail deliveries. You can use variables:
7804@table @code
7805@item %$
7806Delivery status message (e.g. @samp{saved to INBOX})
7807@item %m
7808Message-ID
7809@item %s
7810Subject
7811@item %f
7812From address
7813@item %p
7814Physical size
7815@item %w
7816Virtual size.
7817@end table
7818Defaults to @samp{"msgid=%m: %$"}.
7819@end deftypevr
7820
7821@deftypevr {@code{dovecot-configuration} parameter} string mail-location
7822Location for users' mailboxes. The default is empty, which means
7823that Dovecot tries to find the mailboxes automatically. This won't work
7824if the user doesn't yet have any mail, so you should explicitly tell
7825Dovecot the full location.
7826
7827If you're using mbox, giving a path to the INBOX
7828file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
7829where the other mailboxes are kept. This is called the "root mail
7830directory", and it must be the first path given in the
7831@samp{mail-location} setting.
7832
7833There are a few special variables you can use, eg.:
7834
7835@table @samp
7836@item %u
7837username
7838@item %n
7839user part in user@@domain, same as %u if there's no domain
7840@item %d
7841domain part in user@@domain, empty if there's no domain
7842@item %h
7843home director
7844@end table
7845
7846See doc/wiki/Variables.txt for full list. Some examples:
7847@table @samp
7848@item maildir:~/Maildir
7849@item mbox:~/mail:INBOX=/var/mail/%u
7850@item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
7851@end table
7852Defaults to @samp{""}.
7853@end deftypevr
7854
7855@deftypevr {@code{dovecot-configuration} parameter} string mail-uid
7856System user and group used to access mails. If you use multiple,
7857userdb can override these by returning uid or gid fields. You can use
7858either numbers or names. <doc/wiki/UserIds.txt>.
7859Defaults to @samp{""}.
7860@end deftypevr
7861
7862@deftypevr {@code{dovecot-configuration} parameter} string mail-gid
7863
7864Defaults to @samp{""}.
7865@end deftypevr
7866
7867@deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
7868Group to enable temporarily for privileged operations. Currently
7869this is used only with INBOX when either its initial creation or
7870dotlocking fails. Typically this is set to "mail" to give access to
7871/var/mail.
7872Defaults to @samp{""}.
7873@end deftypevr
7874
7875@deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
7876Grant access to these supplementary groups for mail processes.
7877Typically these are used to set up access to shared mailboxes. Note
7878that it may be dangerous to set these if users can create
7879symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
7880could allow a user to delete others' mailboxes, or ln -s
7881/secret/shared/box ~/mail/mybox would allow reading it).
7882Defaults to @samp{""}.
7883@end deftypevr
7884
7885@deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
7886Allow full filesystem access to clients. There's no access checks
7887other than what the operating system does for the active UID/GID. It
7888works with both maildir and mboxes, allowing you to prefix mailboxes
7889names with e.g. /path/ or ~user/.
7890Defaults to @samp{#f}.
7891@end deftypevr
7892
7893@deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
7894Don't use mmap() at all. This is required if you store indexes to
7895shared filesystems (NFS or clustered filesystem).
7896Defaults to @samp{#f}.
7897@end deftypevr
7898
7899@deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
7900Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
7901supports @samp{O_EXCL} since version 3, so this should be safe to use
7902nowadays by default.
7903Defaults to @samp{#t}.
7904@end deftypevr
7905
7906@deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
7907When to use fsync() or fdatasync() calls:
7908@table @code
7909@item optimized
7910Whenever necessary to avoid losing important data
7911@item always
7912Useful with e.g. NFS when write()s are delayed
7913@item never
7914Never use it (best performance, but crashes can lose data).
7915@end table
7916Defaults to @samp{"optimized"}.
7917@end deftypevr
7918
7919@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
7920Mail storage exists in NFS. Set this to yes to make Dovecot flush
7921NFS caches whenever needed. If you're using only a single mail server
7922this isn't needed.
7923Defaults to @samp{#f}.
7924@end deftypevr
7925
7926@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
7927Mail index files also exist in NFS. Setting this to yes requires
7928@samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
7929Defaults to @samp{#f}.
7930@end deftypevr
7931
7932@deftypevr {@code{dovecot-configuration} parameter} string lock-method
7933Locking method for index files. Alternatives are fcntl, flock and
7934dotlock. Dotlocking uses some tricks which may create more disk I/O
7935than other locking methods. NFS users: flock doesn't work, remember to
7936change @samp{mmap-disable}.
7937Defaults to @samp{"fcntl"}.
7938@end deftypevr
7939
7940@deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
7941Directory in which LDA/LMTP temporarily stores incoming mails >128
7942kB.
7943Defaults to @samp{"/tmp"}.
7944@end deftypevr
7945
7946@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
7947Valid UID range for users. This is mostly to make sure that users can't
7948log in as daemons or other system users. Note that denying root logins is
7949hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
7950is set to 0.
7951Defaults to @samp{500}.
7952@end deftypevr
7953
7954@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
7955
7956Defaults to @samp{0}.
7957@end deftypevr
7958
7959@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
7960Valid GID range for users. Users having non-valid GID as primary group ID
7961aren't allowed to log in. If user belongs to supplementary groups with
7962non-valid GIDs, those groups are not set.
7963Defaults to @samp{1}.
7964@end deftypevr
7965
7966@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
7967
7968Defaults to @samp{0}.
7969@end deftypevr
7970
7971@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
7972Maximum allowed length for mail keyword name. It's only forced when
7973trying to create new keywords.
7974Defaults to @samp{50}.
7975@end deftypevr
7976
7977@deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
7978List of directories under which chrooting is allowed for mail
7979processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
7980too). This setting doesn't affect @samp{login-chroot}
7981@samp{mail-chroot} or auth chroot settings. If this setting is empty,
7982"/./" in home dirs are ignored. WARNING: Never add directories here
7983which local users can modify, that may lead to root exploit. Usually
7984this should be done only if you don't allow shell access for users.
7985<doc/wiki/Chrooting.txt>.
7986Defaults to @samp{()}.
7987@end deftypevr
7988
7989@deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
7990Default chroot directory for mail processes. This can be overridden
7991for specific users in user database by giving /./ in user's home
7992directory (e.g. /home/./user chroots into /home). Note that usually
7993there is no real need to do chrooting, Dovecot doesn't allow users to
7994access files outside their mail directory anyway. If your home
7995directories are prefixed with the chroot directory, append "/." to
7996@samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
7997Defaults to @samp{""}.
7998@end deftypevr
7999
8000@deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
8001UNIX socket path to master authentication server to find users.
8002This is used by imap (for shared users) and lda.
8003Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
8004@end deftypevr
8005
8006@deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
8007Directory where to look up mail plugins.
8008Defaults to @samp{"/usr/lib/dovecot"}.
8009@end deftypevr
8010
8011@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
8012List of plugins to load for all services. Plugins specific to IMAP,
8013LDA, etc. are added to this list in their own .conf files.
8014Defaults to @samp{()}.
8015@end deftypevr
8016
8017@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
8018The minimum number of mails in a mailbox before updates are done to
8019cache file. This allows optimizing Dovecot's behavior to do less disk
8020writes at the cost of more disk reads.
8021Defaults to @samp{0}.
8022@end deftypevr
8023
8024@deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
8025When IDLE command is running, mailbox is checked once in a while to
8026see if there are any new mails or other changes. This setting defines
8027the minimum time to wait between those checks. Dovecot can also use
8028dnotify, inotify and kqueue to find out immediately when changes
8029occur.
8030Defaults to @samp{"30 secs"}.
8031@end deftypevr
8032
8033@deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
8034Save mails with CR+LF instead of plain LF. This makes sending those
8035mails take less CPU, especially with sendfile() syscall with Linux and
8036FreeBSD. But it also creates a bit more disk I/O which may just make it
8037slower. Also note that if other software reads the mboxes/maildirs,
8038they may handle the extra CRs wrong and cause problems.
8039Defaults to @samp{#f}.
8040@end deftypevr
8041
8042@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
8043By default LIST command returns all entries in maildir beginning
8044with a dot. Enabling this option makes Dovecot return only entries
8045which are directories. This is done by stat()ing each entry, so it
8046causes more disk I/O.
8047 (For systems setting struct @samp{dirent->d_type} this check is free
8048and it's done always regardless of this setting).
8049Defaults to @samp{#f}.
8050@end deftypevr
8051
8052@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
8053When copying a message, do it with hard links whenever possible.
8054This makes the performance much better, and it's unlikely to have any
8055side effects.
8056Defaults to @samp{#t}.
8057@end deftypevr
8058
8059@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
8060Assume Dovecot is the only MUA accessing Maildir: Scan cur/
8061directory only when its mtime changes unexpectedly or when we can't find
8062the mail otherwise.
8063Defaults to @samp{#f}.
8064@end deftypevr
8065
8066@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
8067Which locking methods to use for locking mbox. There are four
8068available:
8069
8070@table @code
8071@item dotlock
8072Create <mailbox>.lock file. This is the oldest and most NFS-safe
8073solution. If you want to use /var/mail/ like directory, the users will
8074need write access to that directory.
8075@item dotlock-try
8076Same as dotlock, but if it fails because of permissions or because there
8077isn't enough disk space, just skip it.
8078@item fcntl
8079Use this if possible. Works with NFS too if lockd is used.
8080@item flock
8081May not exist in all systems. Doesn't work with NFS.
8082@item lockf
8083May not exist in all systems. Doesn't work with NFS.
8084@end table
8085
8086You can use multiple locking methods; if you do the order they're declared
8087in is important to avoid deadlocks if other MTAs/MUAs are using multiple
8088locking methods as well. Some operating systems don't allow using some of
8089them simultaneously.
8090@end deftypevr
8091
8092@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
8093
8094@end deftypevr
8095
8096@deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
8097Maximum time to wait for lock (all of them) before aborting.
8098Defaults to @samp{"5 mins"}.
8099@end deftypevr
8100
8101@deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
8102If dotlock exists but the mailbox isn't modified in any way,
8103override the lock file after this much time.
8104Defaults to @samp{"2 mins"}.
8105@end deftypevr
8106
8107@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
8108When mbox changes unexpectedly we have to fully read it to find out
8109what changed. If the mbox is large this can take a long time. Since
8110the change is usually just a newly appended mail, it'd be faster to
8111simply read the new mails. If this setting is enabled, Dovecot does
8112this but still safely fallbacks to re-reading the whole mbox file
8113whenever something in mbox isn't how it's expected to be. The only real
8114downside to this setting is that if some other MUA changes message
8115flags, Dovecot doesn't notice it immediately. Note that a full sync is
8116done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
8117Defaults to @samp{#t}.
8118@end deftypevr
8119
8120@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
8121Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
8122EXAMINE, EXPUNGE or CHECK commands. If this is set,
8123@samp{mbox-dirty-syncs} is ignored.
8124Defaults to @samp{#f}.
8125@end deftypevr
8126
8127@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
8128Delay writing mbox headers until doing a full write sync (EXPUNGE
8129and CHECK commands and when closing the mailbox). This is especially
8130useful for POP3 where clients often delete all mails. The downside is
8131that our changes aren't immediately visible to other MUAs.
8132Defaults to @samp{#t}.
8133@end deftypevr
8134
8135@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
8136If mbox size is smaller than this (e.g. 100k), don't write index
8137files. If an index file already exists it's still read, just not
8138updated.
8139Defaults to @samp{0}.
8140@end deftypevr
8141
8142@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
8143Maximum dbox file size until it's rotated.
8144Defaults to @samp{2000000}.
8145@end deftypevr
8146
8147@deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
8148Maximum dbox file age until it's rotated. Typically in days. Day
8149begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
8150disabled.
8151Defaults to @samp{"1d"}.
8152@end deftypevr
8153
8154@deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
8155When creating new mdbox files, immediately preallocate their size to
8156@samp{mdbox-rotate-size}. This setting currently works only in Linux
8157with some filesystems (ext4, xfs).
8158Defaults to @samp{#f}.
8159@end deftypevr
8160
8161@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
8162sdbox and mdbox support saving mail attachments to external files,
8163which also allows single instance storage for them. Other backends
8164don't support this for now.
8165
8166WARNING: This feature hasn't been tested much yet. Use at your own risk.
8167
8168Directory root where to store mail attachments. Disabled, if empty.
8169Defaults to @samp{""}.
8170@end deftypevr
8171
8172@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
8173Attachments smaller than this aren't saved externally. It's also
8174possible to write a plugin to disable saving specific attachments
8175externally.
8176Defaults to @samp{128000}.
8177@end deftypevr
8178
8179@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
8180Filesystem backend to use for saving attachments:
8181@table @code
8182@item posix
8183No SiS done by Dovecot (but this might help FS's own deduplication)
8184@item sis posix
8185SiS with immediate byte-by-byte comparison during saving
8186@item sis-queue posix
8187SiS with delayed comparison and deduplication.
8188@end table
8189Defaults to @samp{"sis posix"}.
8190@end deftypevr
8191
8192@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
8193Hash format to use in attachment filenames. You can add any text and
8194variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
8195@code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
8196truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
8197Defaults to @samp{"%@{sha1@}"}.
8198@end deftypevr
8199
8200@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
8201
8202Defaults to @samp{100}.
8203@end deftypevr
8204
8205@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
8206
8207Defaults to @samp{1000}.
8208@end deftypevr
8209
8210@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
8211Default VSZ (virtual memory size) limit for service processes.
8212This is mainly intended to catch and kill processes that leak memory
8213before they eat up everything.
8214Defaults to @samp{256000000}.
8215@end deftypevr
8216
8217@deftypevr {@code{dovecot-configuration} parameter} string default-login-user
8218Login user is internally used by login processes. This is the most
8219untrusted user in Dovecot system. It shouldn't have access to anything
8220at all.
8221Defaults to @samp{"dovenull"}.
8222@end deftypevr
8223
8224@deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
8225Internal user is used by unprivileged processes. It should be
8226separate from login user, so that login processes can't disturb other
8227processes.
8228Defaults to @samp{"dovecot"}.
8229@end deftypevr
8230
8231@deftypevr {@code{dovecot-configuration} parameter} string ssl?
8232SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
8233Defaults to @samp{"required"}.
8234@end deftypevr
8235
8236@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
8237PEM encoded X.509 SSL/TLS certificate (public key).
8238Defaults to @samp{"</etc/dovecot/default.pem"}.
8239@end deftypevr
8240
8241@deftypevr {@code{dovecot-configuration} parameter} string ssl-key
8242PEM encoded SSL/TLS private key. The key is opened before
8243dropping root privileges, so keep the key file unreadable by anyone but
8244root.
8245Defaults to @samp{"</etc/dovecot/private/default.pem"}.
8246@end deftypevr
8247
8248@deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
8249If key file is password protected, give the password here.
8250Alternatively give it when starting dovecot with -p parameter. Since
8251this file is often world-readable, you may want to place this setting
8252instead to a different.
8253Defaults to @samp{""}.
8254@end deftypevr
8255
8256@deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
8257PEM encoded trusted certificate authority. Set this only if you
8258intend to use @samp{ssl-verify-client-cert? #t}. The file should
8259contain the CA certificate(s) followed by the matching
8260CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
8261Defaults to @samp{""}.
8262@end deftypevr
8263
8264@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
8265Require that CRL check succeeds for client certificates.
8266Defaults to @samp{#t}.
8267@end deftypevr
8268
8269@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
8270Request client to send a certificate. If you also want to require
8271it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
8272Defaults to @samp{#f}.
8273@end deftypevr
8274
8275@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
8276Which field from certificate to use for username. commonName and
8277x500UniqueIdentifier are the usual choices. You'll also need to set
8278@samp{auth-ssl-username-from-cert? #t}.
8279Defaults to @samp{"commonName"}.
8280@end deftypevr
8281
8282@deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
8283How often to regenerate the SSL parameters file. Generation is
8284quite CPU intensive operation. The value is in hours, 0 disables
8285regeneration entirely.
8286Defaults to @samp{168}.
8287@end deftypevr
8288
8289@deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
8290SSL protocols to use.
8291Defaults to @samp{"!SSLv2"}.
8292@end deftypevr
8293
8294@deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
8295SSL ciphers to use.
8296Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
8297@end deftypevr
8298
8299@deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
8300SSL crypto device to use, for valid values run "openssl engine".
8301Defaults to @samp{""}.
8302@end deftypevr
8303
8304@deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
8305Address to use when sending rejection mails.
8306Default is postmaster@@<your domain>. %d expands to recipient domain.
8307Defaults to @samp{""}.
8308@end deftypevr
8309
8310@deftypevr {@code{dovecot-configuration} parameter} string hostname
8311Hostname to use in various parts of sent mails (e.g. in Message-Id)
8312and in LMTP replies. Default is the system's real hostname@@domain.
8313Defaults to @samp{""}.
8314@end deftypevr
8315
8316@deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
8317If user is over quota, return with temporary failure instead of
8318bouncing the mail.
8319Defaults to @samp{#f}.
8320@end deftypevr
8321
8322@deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
8323Binary to use for sending mails.
8324Defaults to @samp{"/usr/sbin/sendmail"}.
8325@end deftypevr
8326
8327@deftypevr {@code{dovecot-configuration} parameter} string submission-host
8328If non-empty, send mails via this SMTP host[:port] instead of
8329sendmail.
8330Defaults to @samp{""}.
8331@end deftypevr
8332
8333@deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
8334Subject: header to use for rejection mails. You can use the same
8335variables as for @samp{rejection-reason} below.
8336Defaults to @samp{"Rejected: %s"}.
8337@end deftypevr
8338
8339@deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
8340Human readable error message for rejection mails. You can use
8341variables:
8342
8343@table @code
8344@item %n
8345CRLF
8346@item %r
8347reason
8348@item %s
8349original subject
8350@item %t
8351recipient
8352@end table
8353Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
8354@end deftypevr
8355
8356@deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
8357Delimiter character between local-part and detail in email
8358address.
8359Defaults to @samp{"+"}.
8360@end deftypevr
8361
8362@deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
8363Header where the original recipient address (SMTP's RCPT TO:
8364address) is taken from if not available elsewhere. With dovecot-lda -a
8365parameter overrides this. A commonly used header for this is
8366X-Original-To.
8367Defaults to @samp{""}.
8368@end deftypevr
8369
8370@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
8371Should saving a mail to a nonexistent mailbox automatically create
8372it?.
8373Defaults to @samp{#f}.
8374@end deftypevr
8375
8376@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
8377Should automatically created mailboxes be also automatically
8378subscribed?.
8379Defaults to @samp{#f}.
8380@end deftypevr
8381
8382@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
8383Maximum IMAP command line length. Some clients generate very long
8384command lines with huge mailboxes, so you may need to raise this if you
8385get "Too long argument" or "IMAP command line too large" errors
8386often.
8387Defaults to @samp{64000}.
8388@end deftypevr
8389
8390@deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
8391IMAP logout format string:
8392@table @code
8393@item %i
8394total number of bytes read from client
8395@item %o
8396total number of bytes sent to client.
8397@end table
8398Defaults to @samp{"in=%i out=%o"}.
8399@end deftypevr
8400
8401@deftypevr {@code{dovecot-configuration} parameter} string imap-capability
8402Override the IMAP CAPABILITY response. If the value begins with '+',
8403add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
8404Defaults to @samp{""}.
8405@end deftypevr
8406
8407@deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
8408How long to wait between "OK Still here" notifications when client
8409is IDLEing.
8410Defaults to @samp{"2 mins"}.
8411@end deftypevr
8412
8413@deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
8414ID field names and values to send to clients. Using * as the value
8415makes Dovecot use the default value. The following fields have default
8416values currently: name, version, os, os-version, support-url,
8417support-email.
8418Defaults to @samp{""}.
8419@end deftypevr
8420
8421@deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
8422ID fields sent by client to log. * means everything.
8423Defaults to @samp{""}.
8424@end deftypevr
8425
8426@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
8427Workarounds for various client bugs:
8428
8429@table @code
8430@item delay-newmail
8431Send EXISTS/RECENT new mail notifications only when replying to NOOP and
8432CHECK commands. Some clients ignore them otherwise, for example OSX
8433Mail (<v2.1). Outlook Express breaks more badly though, without this it
8434may show user "Message no longer in server" errors. Note that OE6
8435still breaks even with this workaround if synchronization is set to
8436"Headers Only".
8437
8438@item tb-extra-mailbox-sep
8439Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
8440adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
8441ignore the extra @samp{/} instead of treating it as invalid mailbox name.
8442
8443@item tb-lsub-flags
8444Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
8445This makes Thunderbird realize they aren't selectable and show them
8446greyed out, instead of only later giving "not selectable" popup error.
8447@end table
8448Defaults to @samp{()}.
8449@end deftypevr
8450
8451@deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
8452Host allowed in URLAUTH URLs sent by client. "*" allows all.
8453Defaults to @samp{""}.
8454@end deftypevr
8455
8456
8457Whew! Lots of configuration options. The nice thing about it though is
8458that GuixSD has a complete interface to Dovecot's configuration
8459language. This allows not only a nice way to declare configurations,
8460but also offers reflective capabilities as well: users can write code to
8461inspect and transform configurations from within Scheme.
8462
8463However, it could be that you just want to get a @code{dovecot.conf} up
8464and running. In that case, you can pass an
8465@code{opaque-dovecot-configuration} as the @code{#:config} paramter to
8466@code{dovecot-service}. As its name indicates, an opaque configuration
8467does not have easy reflective capabilities.
8468
8469Available @code{opaque-dovecot-configuration} fields are:
8470
8471@deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
8472The dovecot package.
8473@end deftypevr
8474
8475@deftypevr {@code{opaque-dovecot-configuration} parameter} string string
8476The contents of the @code{dovecot.conf}, as a string.
8477@end deftypevr
8478
8479For example, if your @code{dovecot.conf} is just the empty string, you
8480could instantiate a dovecot service like this:
8481
8482@example
8483(dovecot-service #:config
8484 (opaque-dovecot-configuration
8485 (string "")))
8486@end example
8487
58724c48
DT
8488@node Web Services
8489@subsubsection Web Services
8490
8491The @code{(gnu services web)} module provides the following service:
8492
be1c2c54 8493@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
58724c48
DT
8494 [#:log-directory ``/var/log/nginx''] @
8495 [#:run-directory ``/var/run/nginx''] @
8496 [#:config-file]
8497
8498Return a service that runs @var{nginx}, the nginx web server.
8499
8500The nginx daemon loads its runtime configuration from @var{config-file}.
8501Log files are written to @var{log-directory} and temporary runtime data
8502files are written to @var{run-directory}. For proper operation, these
8503arguments should match what is in @var{config-file} to ensure that the
8504directories are created when the service is activated.
8505
8506@end deffn
8507
fe1a39d3
LC
8508@node Various Services
8509@subsubsection Various Services
8510
8511The @code{(gnu services lirc)} module provides the following service.
8512
be1c2c54 8513@deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
fe1a39d3
LC
8514 [#:device #f] [#:driver #f] [#:config-file #f] @
8515 [#:extra-options '()]
8516Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
8517decodes infrared signals from remote controls.
8518
8519Optionally, @var{device}, @var{driver} and @var{config-file}
8520(configuration file name) may be specified. See @command{lircd} manual
8521for details.
8522
8523Finally, @var{extra-options} is a list of additional command-line options
8524passed to @command{lircd}.
8525@end deffn
8526
8527
0ae8c15a
LC
8528@node Setuid Programs
8529@subsection Setuid Programs
8530
8531@cindex setuid programs
8532Some programs need to run with ``root'' privileges, even when they are
8533launched by unprivileged users. A notorious example is the
4d40227c
LC
8534@command{passwd} program, which users can run to change their
8535password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
8536@file{/etc/shadow} files---something normally restricted to root, for
8537obvious security reasons. To address that, these executables are
8538@dfn{setuid-root}, meaning that they always run with root privileges
8539(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
f7e4ae7f 8540for more info about the setuid mechanism.)
0ae8c15a
LC
8541
8542The store itself @emph{cannot} contain setuid programs: that would be a
8543security issue since any user on the system can write derivations that
8544populate the store (@pxref{The Store}). Thus, a different mechanism is
8545used: instead of changing the setuid bit directly on files that are in
8546the store, we let the system administrator @emph{declare} which programs
8547should be setuid root.
8548
8549The @code{setuid-programs} field of an @code{operating-system}
8550declaration contains a list of G-expressions denoting the names of
8551programs to be setuid-root (@pxref{Using the Configuration System}).
8552For instance, the @command{passwd} program, which is part of the Shadow
8553package, can be designated by this G-expression (@pxref{G-Expressions}):
8554
8555@example
8556#~(string-append #$shadow "/bin/passwd")
8557@end example
8558
8559A default set of setuid programs is defined by the
8560@code{%setuid-programs} variable of the @code{(gnu system)} module.
8561
8562@defvr {Scheme Variable} %setuid-programs
8563A list of G-expressions denoting common programs that are setuid-root.
8564
8565The list includes commands such as @command{passwd}, @command{ping},
8566@command{su}, and @command{sudo}.
8567@end defvr
8568
8569Under the hood, the actual setuid programs are created in the
8570@file{/run/setuid-programs} directory at system activation time. The
8571files in this directory refer to the ``real'' binaries, which are in the
8572store.
8573
efb5e833
LC
8574@node X.509 Certificates
8575@subsection X.509 Certificates
8576
8577@cindex HTTPS, certificates
8578@cindex X.509 certificates
8579@cindex TLS
8580Web servers available over HTTPS (that is, HTTP over the transport-layer
8581security mechanism, TLS) send client programs an @dfn{X.509 certificate}
8582that the client can then use to @emph{authenticate} the server. To do
8583that, clients verify that the server's certificate is signed by a
8584so-called @dfn{certificate authority} (CA). But to verify the CA's
8585signature, clients must have first acquired the CA's certificate.
8586
8587Web browsers such as GNU@tie{}IceCat include their own set of CA
8588certificates, such that they are able to verify CA signatures
8589out-of-the-box.
8590
8591However, most other programs that can talk HTTPS---@command{wget},
8592@command{git}, @command{w3m}, etc.---need to be told where CA
8593certificates can be found.
8594
8595@cindex @code{nss-certs}
8596In GuixSD, this is done by adding a package that provides certificates
8597to the @code{packages} field of the @code{operating-system} declaration
8598(@pxref{operating-system Reference}). GuixSD includes one such package,
8599@code{nss-certs}, which is a set of CA certificates provided as part of
8600Mozilla's Network Security Services.
8601
8602Note that it is @emph{not} part of @var{%base-packages}, so you need to
8603explicitly add it. The @file{/etc/ssl/certs} directory, which is where
8604most applications and libraries look for certificates by default, points
8605to the certificates installed globally.
8606
8607Unprivileged users can also install their own certificate package in
8608their profile. A number of environment variables need to be defined so
8609that applications and libraries know where to find them. Namely, the
8610OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
8611variables. Some applications add their own environment variables; for
8612instance, the Git version control system honors the certificate bundle
8613pointed to by the @code{GIT_SSL_CAINFO} environment variable.
8614
8615
996ed739
LC
8616@node Name Service Switch
8617@subsection Name Service Switch
8618
8619@cindex name service switch
8620@cindex NSS
8621The @code{(gnu system nss)} module provides bindings to the
8622configuration file of libc's @dfn{name service switch} or @dfn{NSS}
8623(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
8624Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
8625extended with new ``name'' lookup methods for system databases, which
8626includes host names, service names, user accounts, and more (@pxref{Name
8627Service Switch, System Databases and Name Service Switch,, libc, The GNU
8628C Library Reference Manual}).
8629
8630The NSS configuration specifies, for each system database, which lookup
8631method is to be used, and how the various methods are chained
8632together---for instance, under which circumstances NSS should try the
8633next method in the list. The NSS configuration is given in the
8634@code{name-service-switch} field of @code{operating-system} declarations
8635(@pxref{operating-system Reference, @code{name-service-switch}}).
8636
4c9050c6
LC
8637@cindex nss-mdns
8638@cindex .local, host name lookup
996ed739 8639As an example, the declaration below configures the NSS to use the
4c9050c6
LC
8640@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
8641back-end}, which supports host name lookups over multicast DNS (mDNS)
8642for host names ending in @code{.local}:
996ed739
LC
8643
8644@example
8645(name-service-switch
8646 (hosts (list %files ;first, check /etc/hosts
8647
8648 ;; If the above did not succeed, try
8649 ;; with 'mdns_minimal'.
8650 (name-service
8651 (name "mdns_minimal")
8652
8653 ;; 'mdns_minimal' is authoritative for
8654 ;; '.local'. When it returns "not found",
8655 ;; no need to try the next methods.
8656 (reaction (lookup-specification
8657 (not-found => return))))
8658
8659 ;; Then fall back to DNS.
8660 (name-service
8661 (name "dns"))
8662
8663 ;; Finally, try with the "full" 'mdns'.
8664 (name-service
8665 (name "mdns")))))
8666@end example
8667
15137a29
LC
8668Don't worry: the @code{%mdns-host-lookup-nss} variable (see below)
8669contains this configuration, so you won't have to type it if all you
8670want is to have @code{.local} host lookup working.
8671
4c9050c6
LC
8672Note that, in this case, in addition to setting the
8673@code{name-service-switch} of the @code{operating-system} declaration,
cc9c1f39
LC
8674you also need to use @code{avahi-service} (@pxref{Networking Services,
8675@code{avahi-service}}), or @var{%desktop-services}, which includes it
8676(@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
8677to the name service cache daemon (@pxref{Base Services,
8678@code{nscd-service}}).
15137a29
LC
8679
8680For convenience, the following variables provide typical NSS
8681configurations.
8682
8683@defvr {Scheme Variable} %default-nss
8684This is the default name service switch configuration, a
8685@code{name-service-switch} object.
8686@end defvr
8687
8688@defvr {Scheme Variable} %mdns-host-lookup-nss
8689This is the name service switch configuration with support for host name
8690lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
8691@end defvr
4c9050c6 8692
996ed739
LC
8693The reference for name service switch configuration is given below. It
8694is a direct mapping of the C library's configuration file format, so
8695please refer to the C library manual for more information (@pxref{NSS
8696Configuration File,,, libc, The GNU C Library Reference Manual}).
8697Compared to libc's NSS configuration file format, it has the advantage
8698not only of adding this warm parenthetic feel that we like, but also
8699static checks: you'll know about syntax errors and typos as soon as you
8700run @command{guix system}.
8701
996ed739
LC
8702@deftp {Data Type} name-service-switch
8703
8704This is the data type representation the configuration of libc's name
8705service switch (NSS). Each field below represents one of the supported
8706system databases.
8707
8708@table @code
8709@item aliases
8710@itemx ethers
8711@itemx group
8712@itemx gshadow
8713@itemx hosts
8714@itemx initgroups
8715@itemx netgroup
8716@itemx networks
8717@itemx password
8718@itemx public-key
8719@itemx rpc
8720@itemx services
8721@itemx shadow
8722The system databases handled by the NSS. Each of these fields must be a
8723list of @code{<name-service>} objects (see below.)
8724@end table
8725@end deftp
8726
8727@deftp {Data Type} name-service
8728
8729This is the data type representing an actual name service and the
8730associated lookup action.
8731
8732@table @code
8733@item name
8734A string denoting the name service (@pxref{Services in the NSS
8735configuration,,, libc, The GNU C Library Reference Manual}).
8736
4aee6e60
LC
8737Note that name services listed here must be visible to nscd. This is
8738achieved by passing the @code{#:name-services} argument to
8739@code{nscd-service} the list of packages providing the needed name
8740services (@pxref{Base Services, @code{nscd-service}}).
8741
996ed739
LC
8742@item reaction
8743An action specified using the @code{lookup-specification} macro
8744(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
8745Reference Manual}). For example:
8746
8747@example
8748(lookup-specification (unavailable => continue)
8749 (success => return))
8750@end example
8751@end table
8752@end deftp
0ae8c15a 8753
fd1b1fa2
LC
8754@node Initial RAM Disk
8755@subsection Initial RAM Disk
8756
8757@cindex initial RAM disk (initrd)
8758@cindex initrd (initial RAM disk)
8759For bootstrapping purposes, the Linux-Libre kernel is passed an
8760@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
8761root file system, as well as an initialization script. The latter is
8762responsible for mounting the real root file system, and for loading any
8763kernel modules that may be needed to achieve that.
8764
8765The @code{initrd} field of an @code{operating-system} declaration allows
8766you to specify which initrd you would like to use. The @code{(gnu
8767system linux-initrd)} module provides two ways to build an initrd: the
8768high-level @code{base-initrd} procedure, and the low-level
8769@code{expression->initrd} procedure.
8770
8771The @code{base-initrd} procedure is intended to cover most common uses.
8772For example, if you want to add a bunch of kernel modules to be loaded
8773at boot time, you can define the @code{initrd} field of the operating
8774system declaration like this:
8775
8776@example
52ac153e 8777(initrd (lambda (file-systems . rest)
027981d6
LC
8778 ;; Create a standard initrd that has modules "foo.ko"
8779 ;; and "bar.ko", as well as their dependencies, in
8780 ;; addition to the modules available by default.
52ac153e 8781 (apply base-initrd file-systems
027981d6 8782 #:extra-modules '("foo" "bar")
52ac153e 8783 rest)))
fd1b1fa2
LC
8784@end example
8785
52ac153e
LC
8786The @code{base-initrd} procedure also handles common use cases that
8787involves using the system as a QEMU guest, or as a ``live'' system whose
8788root file system is volatile.
fd1b1fa2
LC
8789
8790@deffn {Monadic Procedure} base-initrd @var{file-systems} @
8791 [#:qemu-networking? #f] [#:virtio? #f] [#:volatile-root? #f] @
52ac153e 8792 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2
LC
8793Return a monadic derivation that builds a generic initrd. @var{file-systems} is
8794a list of file-systems to be mounted by the initrd, possibly in addition to
8795the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
8796@var{mapped-devices} is a list of device mappings to realize before
8797@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
8798
8799When @var{qemu-networking?} is true, set up networking with the standard QEMU
8800parameters. When @var{virtio?} is true, load additional modules so the initrd can
8801be used as a QEMU guest with para-virtualized I/O drivers.
8802
8803When @var{volatile-root?} is true, the root file system is writable but any changes
8804to it are lost.
8805
8806The initrd is automatically populated with all the kernel modules necessary
8807for @var{file-systems} and for the given options. However, additional kernel
8808modules can be listed in @var{extra-modules}. They will be added to the initrd, and
8809loaded at boot time in the order in which they appear.
8810@end deffn
8811
8812Needless to say, the initrds we produce and use embed a
8813statically-linked Guile, and the initialization program is a Guile
8814program. That gives a lot of flexibility. The
8815@code{expression->initrd} procedure builds such an initrd, given the
8816program to run in that initrd.
8817
8818@deffn {Monadic Procedure} expression->initrd @var{exp} @
8819 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
42d10464 8820 [#:modules '()]
fd1b1fa2
LC
8821Return a derivation that builds a Linux initrd (a gzipped cpio archive)
8822containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
8823upon booting. All the derivations referenced by @var{exp} are
8824automatically copied to the initrd.
fd1b1fa2 8825
42d10464
LC
8826@var{modules} is a list of Guile module names to be embedded in the
8827initrd.
fd1b1fa2
LC
8828@end deffn
8829
88faf933
LC
8830@node GRUB Configuration
8831@subsection GRUB Configuration
8832
8833@cindex GRUB
8834@cindex boot loader
8835
8836The operating system uses GNU@tie{}GRUB as its boot loader
8837(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
8838configured using @code{grub-configuration} declarations. This data type
8839is exported by the @code{(gnu system grub)} module, and described below.
8840
8841@deftp {Data Type} grub-configuration
8842The type of a GRUB configuration declaration.
8843
8844@table @asis
8845
8846@item @code{device}
8847This is a string denoting the boot device. It must be a device name
8848understood by the @command{grub-install} command, such as
8849@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
8850GNU GRUB Manual}).
8851
8852@item @code{menu-entries} (default: @code{()})
8853A possibly empty list of @code{menu-entry} objects (see below), denoting
8854entries to appear in the GRUB boot menu, in addition to the current
8855system entry and the entry pointing to previous system generations.
8856
8857@item @code{default-entry} (default: @code{0})
8858The index of the default boot menu entry. Index 0 is for the current
8859system's entry.
8860
8861@item @code{timeout} (default: @code{5})
8862The number of seconds to wait for keyboard input before booting. Set to
88630 to boot immediately, and to -1 to wait indefinitely.
8864
8865@item @code{theme} (default: @var{%default-theme})
8866The @code{grub-theme} object describing the theme to use.
8867@end table
8868
8869@end deftp
8870
8871Should you want to list additional boot menu entries @i{via} the
8872@code{menu-entries} field above, you will need to create them with the
8873@code{menu-entry} form:
8874
8875@deftp {Data Type} menu-entry
8876The type of an entry in the GRUB boot menu.
8877
8878@table @asis
8879
8880@item @code{label}
35ed9306 8881The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
8882
8883@item @code{linux}
8884The Linux kernel to boot.
8885
8886@item @code{linux-arguments} (default: @code{()})
8887The list of extra Linux kernel command-line arguments---e.g.,
8888@code{("console=ttyS0")}.
8889
8890@item @code{initrd}
8891A G-Expression or string denoting the file name of the initial RAM disk
8892to use (@pxref{G-Expressions}).
8893
8894@end table
8895@end deftp
8896
8897@c FIXME: Write documentation once it's stable.
8898Themes are created using the @code{grub-theme} form, which is not
8899documented yet.
8900
8901@defvr {Scheme Variable} %default-theme
8902This is the default GRUB theme used by the operating system, with a
8903fancy background image displaying the GNU and Guix logos.
8904@end defvr
8905
8906
cf4a9129
LC
8907@node Invoking guix system
8908@subsection Invoking @code{guix system}
0918e64a 8909
cf4a9129
LC
8910Once you have written an operating system declaration, as seen in the
8911previous section, it can be @dfn{instantiated} using the @command{guix
8912system} command. The synopsis is:
4af2447e 8913
cf4a9129
LC
8914@example
8915guix system @var{options}@dots{} @var{action} @var{file}
8916@end example
4af2447e 8917
cf4a9129
LC
8918@var{file} must be the name of a file containing an
8919@code{operating-system} declaration. @var{action} specifies how the
8920operating system is instantiate. Currently the following values are
8921supported:
4af2447e 8922
cf4a9129
LC
8923@table @code
8924@item reconfigure
8925Build the operating system described in @var{file}, activate it, and
8926switch to it@footnote{This action is usable only on systems already
65797bff 8927running GuixSD.}.
4af2447e 8928
cf4a9129
LC
8929This effects all the configuration specified in @var{file}: user
8930accounts, system services, global package list, setuid programs, etc.
4af2447e 8931
cf4a9129
LC
8932It also adds a GRUB menu entry for the new OS configuration, and moves
8933entries for older configurations to a submenu---unless
8934@option{--no-grub} is passed.
4af2447e 8935
bf2479c7
LC
8936@c The paragraph below refers to the problem discussed at
8937@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
8938It is highly recommended to run @command{guix pull} once before you run
8939@command{guix system reconfigure} for the first time (@pxref{Invoking
8940guix pull}). Failing to do that you would see an older version of Guix
8941once @command{reconfigure} has completed.
8942
cf4a9129
LC
8943@item build
8944Build the operating system's derivation, which includes all the
8945configuration files and programs needed to boot and run the system.
8946This action does not actually install anything.
113daf62 8947
cf4a9129
LC
8948@item init
8949Populate the given directory with all the files necessary to run the
8950operating system specified in @var{file}. This is useful for first-time
4705641f 8951installations of GuixSD. For instance:
113daf62
LC
8952
8953@example
cf4a9129 8954guix system init my-os-config.scm /mnt
113daf62
LC
8955@end example
8956
cf4a9129
LC
8957copies to @file{/mnt} all the store items required by the configuration
8958specified in @file{my-os-config.scm}. This includes configuration
8959files, packages, and so on. It also creates other essential files
8960needed for the system to operate correctly---e.g., the @file{/etc},
8961@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 8962
cf4a9129
LC
8963This command also installs GRUB on the device specified in
8964@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 8965
cf4a9129
LC
8966@item vm
8967@cindex virtual machine
0276f697 8968@cindex VM
f535dcbe 8969@anchor{guix system vm}
cf4a9129
LC
8970Build a virtual machine that contain the operating system declared in
8971@var{file}, and return a script to run that virtual machine (VM).
810568b3 8972Arguments given to the script are passed as is to QEMU.
113daf62 8973
cf4a9129 8974The VM shares its store with the host system.
113daf62 8975
0276f697
LC
8976Additional file systems can be shared between the host and the VM using
8977the @code{--share} and @code{--expose} command-line options: the former
8978specifies a directory to be shared with write access, while the latter
8979provides read-only access to the shared directory.
8980
8981The example below creates a VM in which the user's home directory is
8982accessible read-only, and where the @file{/exchange} directory is a
8983read-write mapping of the host's @file{$HOME/tmp}:
8984
8985@example
8986guix system vm my-config.scm \
8987 --expose=$HOME --share=$HOME/tmp=/exchange
8988@end example
8989
6aa260af
LC
8990On GNU/Linux, the default is to boot directly to the kernel; this has
8991the advantage of requiring only a very tiny root disk image since the
8992host's store can then be mounted.
8993
8994The @code{--full-boot} option forces a complete boot sequence, starting
8995with the bootloader. This requires more disk space since a root image
8996containing at least the kernel, initrd, and bootloader data files must
8997be created. The @code{--image-size} option can be used to specify the
8998image's size.
ab11f0be 8999
cf4a9129
LC
9000@item vm-image
9001@itemx disk-image
9002Return a virtual machine or disk image of the operating system declared
9003in @var{file} that stands alone. Use the @option{--image-size} option
9004to specify the size of the image.
113daf62 9005
cf4a9129
LC
9006When using @code{vm-image}, the returned image is in qcow2 format, which
9007the QEMU emulator can efficiently use.
113daf62 9008
cf4a9129
LC
9009When using @code{disk-image}, a raw disk image is produced; it can be
9010copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
9011the device corresponding to a USB stick, one can copy the image on it
9012using the following command:
113daf62 9013
cf4a9129
LC
9014@example
9015# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
9016@end example
113daf62 9017
1c8a81b1
DT
9018@item container
9019Return a script to run the operating system declared in @var{file}
9020within a container. Containers are a set of lightweight isolation
9021mechanisms provided by the kernel Linux-libre. Containers are
9022substantially less resource-demanding than full virtual machines since
9023the kernel, shared objects, and other resources can be shared with the
9024host system; this also means they provide thinner isolation.
9025
9026Currently, the script must be run as root in order to support more than
9027a single user and group. The container shares its store with the host
9028system.
9029
9030As with the @code{vm} action (@pxref{guix system vm}), additional file
9031systems to be shared between the host and container can be specified
9032using the @option{--share} and @option{--expose} options:
9033
9034@example
9035guix system container my-config.scm \
9036 --expose=$HOME --share=$HOME/tmp=/exchange
9037@end example
9038
0f252e26 9039@quotation Note
cfd35b4e 9040This option requires Linux-libre 3.19 or newer.
0f252e26
DT
9041@end quotation
9042
cf4a9129 9043@end table
113daf62 9044
cf4a9129
LC
9045@var{options} can contain any of the common build options provided by
9046@command{guix build} (@pxref{Invoking guix build}). In addition,
9047@var{options} can contain one of the following:
113daf62 9048
cf4a9129
LC
9049@table @option
9050@item --system=@var{system}
9051@itemx -s @var{system}
9052Attempt to build for @var{system} instead of the host's system type.
9053This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 9054
f3f427c2
LC
9055@item --derivation
9056@itemx -d
9057Return the derivation file name of the given operating system without
9058building anything.
9059
cf4a9129
LC
9060@item --image-size=@var{size}
9061For the @code{vm-image} and @code{disk-image} actions, create an image
9062of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
9063include a unit as a suffix (@pxref{Block size, size specifications,,
9064coreutils, GNU Coreutils}).
db030303
LC
9065
9066@item --on-error=@var{strategy}
9067Apply @var{strategy} when an error occurs when reading @var{file}.
9068@var{strategy} may be one of the following:
9069
9070@table @code
9071@item nothing-special
9072Report the error concisely and exit. This is the default strategy.
9073
9074@item backtrace
9075Likewise, but also display a backtrace.
9076
9077@item debug
9078Report the error and enter Guile's debugger. From there, you can run
9079commands such as @code{,bt} to get a backtrace, @code{,locals} to
9080display local variable values, and more generally inspect the program's
9081state. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
9082a list of available debugging commands.
9083@end table
113daf62 9084@end table
113daf62 9085
cf4a9129
LC
9086Note that all the actions above, except @code{build} and @code{init},
9087rely on KVM support in the Linux-Libre kernel. Specifically, the
9088machine should have hardware virtualization support, the corresponding
9089KVM kernel module should be loaded, and the @file{/dev/kvm} device node
9090must exist and be readable and writable by the user and by the daemon's
9091build users.
8451a568 9092
65797bff
LC
9093Once you have built, configured, re-configured, and re-re-configured
9094your GuixSD installation, you may find it useful to list the operating
9095system generations available on disk---and that you can choose from the
9096GRUB boot menu:
9097
9098@table @code
9099
9100@item list-generations
9101List a summary of each generation of the operating system available on
9102disk, in a human-readable way. This is similar to the
9103@option{--list-generations} option of @command{guix package}
9104(@pxref{Invoking guix package}).
9105
9106Optionally, one can specify a pattern, with the same syntax that is used
9107in @command{guix package --list-generations}, to restrict the list of
9108generations displayed. For instance, the following command displays
9109generations up to 10-day old:
9110
9111@example
9112$ guix system list-generations 10d
9113@end example
9114
9115@end table
9116
d6c3267a
LC
9117The @command{guix system} command has even more to offer! The following
9118sub-commands allow you to visualize how your system services relate to
9119each other:
9120
9121@anchor{system-extension-graph}
9122@table @code
9123
9124@item extension-graph
9125Emit in Dot/Graphviz format to standard output the @dfn{service
9126extension graph} of the operating system defined in @var{file}
9127(@pxref{Service Composition}, for more information on service
9128extensions.)
9129
9130The command:
9131
9132@example
9133$ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
9134@end example
9135
9136produces a PDF file showing the extension relations among services.
9137
6f305ea5
LC
9138@anchor{system-dmd-graph}
9139@item dmd-graph
9140Emit in Dot/Graphviz format to standard output the @dfn{dependency
9141graph} of dmd services of the operating system defined in @var{file}.
9142@xref{dmd Services}, for more information and for an example graph.
9143
d6c3267a
LC
9144@end table
9145
9146
cf4a9129
LC
9147@node Defining Services
9148@subsection Defining Services
8451a568 9149
eb524192 9150The previous sections show the available services and how one can combine
0adfe95a
LC
9151them in an @code{operating-system} declaration. But how do we define
9152them in the first place? And what is a service anyway?
8451a568 9153
0adfe95a
LC
9154@menu
9155* Service Composition:: The model for composing services.
9156* Service Types and Services:: Types and services.
9157* Service Reference:: API reference.
9158* dmd Services:: A particular type of service.
9159@end menu
9160
9161@node Service Composition
9162@subsubsection Service Composition
9163
9164@cindex services
9165@cindex daemons
9166Here we define a @dfn{service} as, broadly, something that extends the
9167operating system's functionality. Often a service is a process---a
9168@dfn{daemon}---started when the system boots: a secure shell server, a
9169Web server, the Guix build daemon, etc. Sometimes a service is a daemon
9170whose execution can be triggered by another daemon---e.g., an FTP server
9171started by @command{inetd} or a D-Bus service activated by
9172@command{dbus-daemon}. Occasionally, a service does not map to a
9173daemon. For instance, the ``account'' service collects user accounts
9174and makes sure they exist when the system runs; the ``udev'' service
9175collects device management rules and makes them available to the eudev
9176daemon; the @file{/etc} service populates the system's @file{/etc}
9177directory.
9178
d6c3267a 9179@cindex service extensions
0adfe95a
LC
9180GuixSD services are connected by @dfn{extensions}. For instance, the
9181secure shell service @emph{extends} dmd---GuixSD's initialization system,
9182running as PID@tie{}1---by giving it the command lines to start and stop
9183the secure shell daemon (@pxref{Networking Services,
9184@code{lsh-service}}); the UPower service extends the D-Bus service by
9185passing it its @file{.service} specification, and extends the udev
9186service by passing it device management rules (@pxref{Desktop Services,
9187@code{upower-service}}); the Guix daemon service extends dmd by passing
9188it the command lines to start and stop the daemon, and extends the
9189account service by passing it a list of required build user accounts
9190(@pxref{Base Services}).
9191
9192All in all, services and their ``extends'' relations form a directed
9193acyclic graph (DAG). If we represent services as boxes and extensions
9194as arrows, a typical system might provide something like this:
9195
9196@image{images/service-graph,,5in,Typical service extension graph.}
9197
d62e201c
LC
9198@cindex system service
9199At the bottom, we see the @dfn{system service}, which produces the
9200directory containing everything to run and boot the system, as returned
9201by the @command{guix system build} command. @xref{Service Reference},
9202to learn about the other service types shown here.
d6c3267a
LC
9203@xref{system-extension-graph, the @command{guix system extension-graph}
9204command}, for information on how to generate this representation for a
9205particular operating system definition.
0adfe95a
LC
9206
9207@cindex service types
9208Technically, developers can define @dfn{service types} to express these
9209relations. There can be any number of services of a given type on the
9210system---for instance, a system running two instances of the GNU secure
9211shell server (lsh) has two instances of @var{lsh-service-type}, with
9212different parameters.
9213
9214The following section describes the programming interface for service
9215types and services.
9216
9217@node Service Types and Services
9218@subsubsection Service Types and Services
9219
9220A @dfn{service type} is a node in the DAG described above. Let us start
9221with a simple example, the service type for the Guix build daemon
9222(@pxref{Invoking guix-daemon}):
9223
9224@example
9225(define guix-service-type
9226 (service-type
9227 (name 'guix)
9228 (extensions
9229 (list (service-extension dmd-root-service-type guix-dmd-service)
9230 (service-extension account-service-type guix-accounts)
9231 (service-extension activation-service-type guix-activation)))))
9232@end example
8451a568 9233
cf4a9129 9234@noindent
0adfe95a
LC
9235It defines a two things:
9236
9237@enumerate
9238@item
9239A name, whose sole purpose is to make inspection and debugging easier.
9240
9241@item
9242A list of @dfn{service extensions}, where each extension designates the
9243target service type and a procedure that, given the service's
9244parameters, returns a list of object to extend the service of that type.
9245
9246Every service type has at least one service extension. The only
9247exception is the @dfn{boot service type}, which is the ultimate service.
9248@end enumerate
9249
9250In this example, @var{guix-service-type} extends three services:
9251
9252@table @var
9253@item dmd-root-service-type
9254The @var{guix-dmd-service} procedure defines how the dmd service is
9255extended. Namely, it returns a @code{<dmd-service>} object that defines
9256how @command{guix-daemon} is started and stopped (@pxref{dmd Services}).
9257
9258@item account-service-type
9259This extension for this service is computed by @var{guix-accounts},
9260which returns a list of @code{user-group} and @code{user-account}
9261objects representing the build user accounts (@pxref{Invoking
9262guix-daemon}).
9263
9264@item activation-service-type
9265Here @var{guix-activation} is a procedure that returns a gexp, which is
9266a code snippet to run at ``activation time''---e.g., when the service is
9267booted.
9268@end table
9269
9270A service of this type is instantiated like this:
9271
9272@example
9273(service guix-service-type
9274 (guix-configuration
9275 (build-accounts 5)
9276 (use-substitutes? #f)))
9277@end example
9278
9279The second argument to the @code{service} form is a value representing
9280the parameters of this specific service instance.
9281@xref{guix-configuration-type, @code{guix-configuration}}, for
9282information about the @code{guix-configuration} data type.
9283
9284@var{guix-service-type} is quite simple because it extends other
9285services but is not extensible itself.
9286
9287@c @subsubsubsection Extensible Service Types
9288
9289The service type for an @emph{extensible} service looks like this:
9290
9291@example
9292(define udev-service-type
9293 (service-type (name 'udev)
9294 (extensions
9295 (list (service-extension dmd-root-service-type
9296 udev-dmd-service)))
9297
9298 (compose concatenate) ;concatenate the list of rules
9299 (extend (lambda (config rules)
9300 (match config
9301 (($ <udev-configuration> udev initial-rules)
9302 (udev-configuration
9303 (udev udev) ;the udev package to use
9304 (rules (append initial-rules rules)))))))))
9305@end example
9306
9307This is the service type for the
9308@uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
9309management daemon}. Compared to the previous example, in addition to an
9310extension of @var{dmd-root-service-type}, we see two new fields:
9311
9312@table @code
9313@item compose
9314This is the procedure to @dfn{compose} the list of extensions to
9315services of this type.
9316
9317Services can extend the udev service by passing it lists of rules; we
9318compose those extensions simply by concatenating them.
9319
9320@item extend
9321This procedure defines how the service's value is @dfn{extended} with
9322the composition of the extensions.
9323
9324Udev extensions are composed into a list of rules, but the udev service
9325value is itself a @code{<udev-configuration>} record. So here, we
9326extend that record by appending the list of rules is contains to the
9327list of contributed rules.
9328@end table
9329
9330There can be only one instance of an extensible service type such as
9331@var{udev-service-type}. If there were more, the
9332@code{service-extension} specifications would be ambiguous.
9333
9334Still here? The next section provides a reference of the programming
9335interface for services.
9336
9337@node Service Reference
9338@subsubsection Service Reference
9339
9340We have seen an overview of service types (@pxref{Service Types and
9341Services}). This section provides a reference on how to manipulate
9342services and service types. This interface is provided by the
9343@code{(gnu services)} module.
9344
9345@deffn {Scheme Procedure} service @var{type} @var{value}
9346Return a new service of @var{type}, a @code{<service-type>} object (see
9347below.) @var{value} can be any object; it represents the parameters of
9348this particular service instance.
9349@end deffn
9350
9351@deffn {Scheme Procedure} service? @var{obj}
9352Return true if @var{obj} is a service.
9353@end deffn
8451a568 9354
0adfe95a
LC
9355@deffn {Scheme Procedure} service-kind @var{service}
9356Return the type of @var{service}---i.e., a @code{<service-type>} object.
9357@end deffn
9358
9359@deffn {Scheme Procedure} service-parameters @var{service}
9360Return the value associated with @var{service}. It represents its
9361parameters.
9362@end deffn
9363
9364Here is an example of how a service is created and manipulated:
9365
9366@example
9367(define s
9368 (service nginx-service-type
9369 (nginx-configuration
9370 (nginx nginx)
9371 (log-directory log-directory)
9372 (run-directory run-directory)
9373 (file config-file))))
9374
9375(service? s)
9376@result{} #t
9377
9378(eq? (service-kind s) nginx-service-type)
9379@result{} #t
9380@end example
9381
cd6f6c22
LC
9382The @code{modify-services} form provides a handy way to change the
9383parameters of some of the services of a list such as
9384@var{%base-services} (@pxref{Base Services, @code{%base-services}}). Of
9385course, you could always use standard list combinators such as
9386@code{map} and @code{fold} to do that (@pxref{SRFI-1, List Library,,
9387guile, GNU Guile Reference Manual}); @code{modify-services} simply
9388provides a more concise form for this common pattern.
9389
9390@deffn {Scheme Syntax} modify-services @var{services} @
9391 (@var{type} @var{variable} => @var{body}) @dots{}
9392
9393Modify the services listed in @var{services} according to the given
9394clauses. Each clause has the form:
9395
9396@example
9397(@var{type} @var{variable} => @var{body})
9398@end example
9399
9400where @var{type} is a service type, such as @var{guix-service-type}, and
9401@var{variable} is an identifier that is bound within @var{body} to the
9402value of the service of that @var{type}. @xref{Using the Configuration
9403System}, for an example.
9404
9405This is a shorthand for:
9406
9407@example
9408(map (lambda (service) @dots{}) @var{services})
9409@end example
9410@end deffn
9411
9412Next comes the programming interface for service types. This is
9413something you want to know when writing new service definitions, but not
9414necessarily when simply looking for ways to customize your
9415@code{operating-system} declaration.
9416
0adfe95a
LC
9417@deftp {Data Type} service-type
9418@cindex service type
9419This is the representation of a @dfn{service type} (@pxref{Service Types
9420and Services}).
9421
9422@table @asis
9423@item @code{name}
9424This is a symbol, used only to simplify inspection and debugging.
9425
9426@item @code{extensions}
9427A non-empty list of @code{<service-extension>} objects (see below.)
9428
9429@item @code{compose} (default: @code{#f})
9430If this is @code{#f}, then the service type denotes services that cannot
9431be extended---i.e., services that do not receive ``values'' from other
9432services.
9433
9434Otherwise, it must be a one-argument procedure. The procedure is called
9435by @code{fold-services} and is passed a list of values collected from
9436extensions. It must return a value that is a valid parameter value for
9437the service instance.
9438
9439@item @code{extend} (default: @code{#f})
9440If this is @code{#f}, services of this type cannot be extended.
9441
9442Otherwise, it must be a two-argument procedure: @code{fold-services}
9443calls it, passing it the service's initial value as the first argument
9444and the result of applying @code{compose} to the extension values as the
9445second argument.
9446@end table
9447
9448@xref{Service Types and Services}, for examples.
9449@end deftp
9450
9451@deffn {Scheme Procedure} service-extension @var{target-type} @
9452 @var{compute}
9453Return a new extension for services of type @var{target-type}.
9454@var{compute} must be a one-argument procedure: @code{fold-services}
9455calls it, passing it the value associated with the service that provides
9456the extension; it must return a valid value for the target service.
9457@end deffn
9458
9459@deffn {Scheme Procedure} service-extension? @var{obj}
9460Return true if @var{obj} is a service extension.
9461@end deffn
9462
9463At the core of the service abstraction lies the @code{fold-services}
9464procedure, which is responsible for ``compiling'' a list of services
d62e201c
LC
9465down to a single directory that contains everything needed to boot and
9466run the system---the directory shown by the @command{guix system build}
9467command (@pxref{Invoking guix system}). In essence, it propagates
9468service extensions down the service graph, updating each node parameters
9469on the way, until it reaches the root node.
0adfe95a
LC
9470
9471@deffn {Scheme Procedure} fold-services @var{services} @
d62e201c 9472 [#:target-type @var{system-service-type}]
0adfe95a
LC
9473Fold @var{services} by propagating their extensions down to the root of
9474type @var{target-type}; return the root service adjusted accordingly.
9475@end deffn
9476
9477Lastly, the @code{(gnu services)} module also defines several essential
9478service types, some of which are listed below.
9479
d62e201c
LC
9480@defvr {Scheme Variable} system-service-type
9481This is the root of the service graph. It produces the system directory
9482as returned by the @command{guix system build} command.
9483@end defvr
9484
0adfe95a 9485@defvr {Scheme Variable} boot-service-type
d62e201c
LC
9486The type of the ``boot service'', which produces the @dfn{boot script}.
9487The boot script is what the initial RAM disk runs when booting.
0adfe95a
LC
9488@end defvr
9489
9490@defvr {Scheme Variable} etc-service-type
9491The type of the @file{/etc} service. This service can be extended by
9492passing it name/file tuples such as:
9493
9494@example
9495(list `("issue" ,(plain-file "issue" "Welcome!\n")))
9496@end example
9497
9498In this example, the effect would be to add an @file{/etc/issue} file
9499pointing to the given file.
9500@end defvr
9501
9502@defvr {Scheme Variable} setuid-program-service-type
9503Type for the ``setuid-program service''. This service collects lists of
9504executable file names, passed as gexps, and adds them to the set of
9505setuid-root programs on the system (@pxref{Setuid Programs}).
9506@end defvr
9507
af4c3fd5
LC
9508@defvr {Scheme Variable} profile-service-type
9509Type of the service that populates the @dfn{system profile}---i.e., the
9510programs under @file{/run/current-system/profile}. Other services can
9511extend it by passing it lists of packages to add to the system profile.
9512@end defvr
9513
0adfe95a
LC
9514
9515@node dmd Services
9516@subsubsection dmd Services
9517
9518@cindex PID 1
9519@cindex init system
9520The @code{(gnu services dmd)} provides a way to define services managed
9521by GNU@tie{}dmd, which is GuixSD initialization system---the first
9522process that is started when the system boots, aka. PID@tie{}1
6f305ea5
LC
9523(@pxref{Introduction,,, dmd, GNU dmd Manual}).
9524
9525Services in dmd can depend on each other. For instance, the SSH daemon
9526may need to be started after the syslog daemon has been started, which
9527in turn can only happen once all the file systems have been mounted.
9528The simple operating system defined earlier (@pxref{Using the
9529Configuration System}) results in a service graph like this:
9530
9531@image{images/dmd-graph,,5in,Typical dmd service graph.}
9532
9533You can actually generate such a graph for any operating system
9534definition using the @command{guix system dmd-graph} command
9535(@pxref{system-dmd-graph, @command{guix system dmd-graph}}).
9536
9537The @var{%dmd-root-service} is a service object representing PID@tie{}1,
9538of type @var{dmd-root-service-type}; it can be extended by passing it
9539lists of @code{<dmd-service>} objects.
0adfe95a
LC
9540
9541@deftp {Data Type} dmd-service
9542The data type representing a service managed by dmd.
9543
9544@table @asis
9545@item @code{provision}
9546This is a list of symbols denoting what the service provides.
9547
9548These are the names that may be passed to @command{deco start},
9549@command{deco status}, and similar commands (@pxref{Invoking deco,,,
9550dmd, GNU dmd Manual}). @xref{Slots of services, the @code{provides}
9551slot,, dmd, GNU dmd Manual}, for details.
9552
9553@item @code{requirements} (default: @code{'()})
9554List of symbols denoting the dmd services this one depends on.
9555
9556@item @code{respawn?} (default: @code{#t})
9557Whether to restart the service when it stops, for instance when the
9558underlying process dies.
9559
9560@item @code{start}
9561@itemx @code{stop} (default: @code{#~(const #f)})
cf4a9129
LC
9562The @code{start} and @code{stop} fields refer to dmd's facilities to
9563start and stop processes (@pxref{Service De- and Constructors,,, dmd,
0adfe95a
LC
9564GNU dmd Manual}). They are given as G-expressions that get expanded in
9565the dmd configuration file (@pxref{G-Expressions}).
9566
9567@item @code{documentation}
9568A documentation string, as shown when running:
9569
9570@example
9571deco doc @var{service-name}
9572@end example
9573
9574where @var{service-name} is one of the symbols in @var{provision}
9575(@pxref{Invoking deco,,, dmd, GNU dmd Manual}).
fae685b9
LC
9576
9577@item @code{modules} (default: @var{%default-modules})
9578This is the list of modules that must be in scope when @code{start} and
9579@code{stop} are evaluated.
9580
9581@item @code{imported-modules} (default: @var{%default-imported-modules})
9582This is the list of modules to import in the execution environment of
9583dmd.
9584
0adfe95a
LC
9585@end table
9586@end deftp
9587
9588@defvr {Scheme Variable} dmd-root-service-type
9589The service type for the dmd ``root service''---i.e., PID@tie{}1.
9590
9591This is the service type that extensions target when they want to create
9592dmd services (@pxref{Service Types and Services}, for an example). Each
9593extension must pass a list of @code{<dmd-service>}.
9594@end defvr
9595
9596@defvr {Scheme Variable} %dmd-root-service
9597This service represents PID@tie{}1.
9598@end defvr
8451a568 9599
8451a568 9600
cf4a9129
LC
9601@node Installing Debugging Files
9602@section Installing Debugging Files
8451a568 9603
cf4a9129
LC
9604@cindex debugging files
9605Program binaries, as produced by the GCC compilers for instance, are
9606typically written in the ELF format, with a section containing
9607@dfn{debugging information}. Debugging information is what allows the
9608debugger, GDB, to map binary code to source code; it is required to
9609debug a compiled program in good conditions.
8451a568 9610
cf4a9129
LC
9611The problem with debugging information is that is takes up a fair amount
9612of disk space. For example, debugging information for the GNU C Library
9613weighs in at more than 60 MiB. Thus, as a user, keeping all the
9614debugging info of all the installed programs is usually not an option.
9615Yet, space savings should not come at the cost of an impediment to
9616debugging---especially in the GNU system, which should make it easier
9617for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 9618
cf4a9129
LC
9619Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
9620mechanism that allows users to get the best of both worlds: debugging
9621information can be stripped from the binaries and stored in separate
9622files. GDB is then able to load debugging information from those files,
9623when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
9624with GDB}).
8451a568 9625
cf4a9129
LC
9626The GNU distribution takes advantage of this by storing debugging
9627information in the @code{lib/debug} sub-directory of a separate package
9628output unimaginatively called @code{debug} (@pxref{Packages with
9629Multiple Outputs}). Users can choose to install the @code{debug} output
9630of a package when they need it. For instance, the following command
9631installs the debugging information for the GNU C Library and for GNU
9632Guile:
8451a568
LC
9633
9634@example
cf4a9129 9635guix package -i glibc:debug guile:debug
8451a568
LC
9636@end example
9637
cf4a9129
LC
9638GDB must then be told to look for debug files in the user's profile, by
9639setting the @code{debug-file-directory} variable (consider setting it
9640from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
9641GDB}):
8451a568 9642
cf4a9129
LC
9643@example
9644(gdb) set debug-file-directory ~/.guix-profile/lib/debug
9645@end example
8451a568 9646
cf4a9129
LC
9647From there on, GDB will pick up debugging information from the
9648@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 9649
cf4a9129
LC
9650In addition, you will most likely want GDB to be able to show the source
9651code being debugged. To do that, you will have to unpack the source
9652code of the package of interest (obtained with @code{guix build
9653--source}, @pxref{Invoking guix build}), and to point GDB to that source
9654directory using the @code{directory} command (@pxref{Source Path,
9655@code{directory},, gdb, Debugging with GDB}).
8451a568 9656
cf4a9129
LC
9657@c XXX: keep me up-to-date
9658The @code{debug} output mechanism in Guix is implemented by the
9659@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
9660opt-in---debugging information is available only for those packages
9661whose definition explicitly declares a @code{debug} output. This may be
9662changed to opt-out in the future, if our build farm servers can handle
9663the load. To check whether a package has a @code{debug} output, use
9664@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 9665
8451a568 9666
05962f29
LC
9667@node Security Updates
9668@section Security Updates
9669
843858b8
LC
9670@quotation Note
9671As of version @value{VERSION}, the feature described in this section is
9672experimental.
9673@end quotation
05962f29
LC
9674
9675@cindex security updates
9676Occasionally, important security vulnerabilities are discovered in core
9677software packages and must be patched. Guix follows a functional
9678package management discipline (@pxref{Introduction}), which implies
9679that, when a package is changed, @emph{every package that depends on it}
9680must be rebuilt. This can significantly slow down the deployment of
9681fixes in core packages such as libc or Bash, since basically the whole
9682distribution would need to be rebuilt. Using pre-built binaries helps
9683(@pxref{Substitutes}), but deployment may still take more time than
9684desired.
9685
9686@cindex grafts
9687To address that, Guix implements @dfn{grafts}, a mechanism that allows
9688for fast deployment of critical updates without the costs associated
9689with a whole-distribution rebuild. The idea is to rebuild only the
9690package that needs to be patched, and then to ``graft'' it onto packages
9691explicitly installed by the user and that were previously referring to
9692the original package. The cost of grafting is typically very low, and
9693order of magnitudes lower than a full rebuild of the dependency chain.
9694
9695@cindex replacements of packages, for grafts
9696For instance, suppose a security update needs to be applied to Bash.
9697Guix developers will provide a package definition for the ``fixed''
9698Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
9699Packages}). Then, the original package definition is augmented with a
9700@code{replacement} field pointing to the package containing the bug fix:
9701
9702@example
9703(define bash
9704 (package
9705 (name "bash")
9706 ;; @dots{}
9707 (replacement bash-fixed)))
9708@end example
9709
9710From there on, any package depending directly or indirectly on Bash that
9711is installed will automatically be ``rewritten'' to refer to
9712@var{bash-fixed} instead of @var{bash}. This grafting process takes
9713time proportional to the size of the package, but expect less than a
9714minute for an ``average'' package on a recent machine.
9715
9716Currently, the graft and the package it replaces (@var{bash-fixed} and
9717@var{bash} in the example above) must have the exact same @code{name}
9718and @code{version} fields. This restriction mostly comes from the fact
9719that grafting works by patching files, including binary files, directly.
9720Other restrictions may apply: for instance, when adding a graft to a
9721package providing a shared library, the original shared library and its
9722replacement must have the same @code{SONAME} and be binary-compatible.
9723
9724
cf4a9129
LC
9725@node Package Modules
9726@section Package Modules
8451a568 9727
cf4a9129
LC
9728From a programming viewpoint, the package definitions of the
9729GNU distribution are provided by Guile modules in the @code{(gnu packages
9730@dots{})} name space@footnote{Note that packages under the @code{(gnu
9731packages @dots{})} module name space are not necessarily ``GNU
9732packages''. This module naming scheme follows the usual Guile module
9733naming convention: @code{gnu} means that these modules are distributed
9734as part of the GNU system, and @code{packages} identifies modules that
9735define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
9736Reference Manual}). For instance, the @code{(gnu packages emacs)}
9737module exports a variable named @code{emacs}, which is bound to a
9738@code{<package>} object (@pxref{Defining Packages}).
113daf62 9739
300868ba 9740The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
9741automatically scanned for packages by the command-line tools. For
9742instance, when running @code{guix package -i emacs}, all the @code{(gnu
9743packages @dots{})} modules are scanned until one that exports a package
9744object whose name is @code{emacs} is found. This package search
9745facility is implemented in the @code{(gnu packages)} module.
113daf62 9746
300868ba 9747@cindex customization, of packages
8689901f 9748@cindex package module search path
cf4a9129 9749Users can store package definitions in modules with different
60142854 9750names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
9751name and module name must match. For instance, the @code{(my-packages
9752emacs)} module must be stored in a @file{my-packages/emacs.scm} file
9753relative to the load path specified with @option{--load-path} or
9754@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
9755guile, GNU Guile Reference Manual}, for details.}. These package definitions
300868ba
LC
9756will not be visible by default. Thus, users can invoke commands such as
9757@command{guix package} and @command{guix build} have to be used with the
c95ded7e
LC
9758@code{-e} option so that they know where to find the package. Better
9759yet, they can use the
300868ba 9760@code{-L} option of these commands to make those modules visible
8689901f
LC
9761(@pxref{Invoking guix build, @code{--load-path}}), or define the
9762@code{GUIX_PACKAGE_PATH} environment variable. This environment
9763variable makes it easy to extend or customize the distribution and is
9764honored by all the user interfaces.
9765
9766@defvr {Environment Variable} GUIX_PACKAGE_PATH
9767This is a colon-separated list of directories to search for package
9768modules. Directories listed in this variable take precedence over the
9769distribution's own modules.
9770@end defvr
ef5dd60a 9771
cf4a9129
LC
9772The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
9773each package is built based solely on other packages in the
9774distribution. The root of this dependency graph is a small set of
9775@dfn{bootstrap binaries}, provided by the @code{(gnu packages
9776bootstrap)} module. For more information on bootstrapping,
081145cf 9777@pxref{Bootstrapping}.
ef5dd60a 9778
cf4a9129
LC
9779@node Packaging Guidelines
9780@section Packaging Guidelines
ef5dd60a 9781
cf4a9129
LC
9782The GNU distribution is nascent and may well lack some of your favorite
9783packages. This section describes how you can help make the distribution
9784grow. @xref{Contributing}, for additional information on how you can
9785help.
ef5dd60a 9786
cf4a9129
LC
9787Free software packages are usually distributed in the form of
9788@dfn{source code tarballs}---typically @file{tar.gz} files that contain
9789all the source files. Adding a package to the distribution means
9790essentially two things: adding a @dfn{recipe} that describes how to
9791build the package, including a list of other packages required to build
9792it, and adding @dfn{package meta-data} along with that recipe, such as a
9793description and licensing information.
ef5dd60a 9794
cf4a9129
LC
9795In Guix all this information is embodied in @dfn{package definitions}.
9796Package definitions provide a high-level view of the package. They are
9797written using the syntax of the Scheme programming language; in fact,
9798for each package we define a variable bound to the package definition,
9799and export that variable from a module (@pxref{Package Modules}).
9800However, in-depth Scheme knowledge is @emph{not} a prerequisite for
9801creating packages. For more information on package definitions,
081145cf 9802@pxref{Defining Packages}.
ef5dd60a 9803
cf4a9129
LC
9804Once a package definition is in place, stored in a file in the Guix
9805source tree, it can be tested using the @command{guix build} command
9806(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
9807called @code{gnew}, you may run this command from the Guix build tree
9808(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
9809
9810@example
cf4a9129 9811./pre-inst-env guix build gnew --keep-failed
ef5dd60a 9812@end example
ef5dd60a 9813
cf4a9129
LC
9814Using @code{--keep-failed} makes it easier to debug build failures since
9815it provides access to the failed build tree. Another useful
9816command-line option when debugging is @code{--log-file}, to access the
9817build log.
ef5dd60a 9818
cf4a9129
LC
9819If the package is unknown to the @command{guix} command, it may be that
9820the source file contains a syntax error, or lacks a @code{define-public}
9821clause to export the package variable. To figure it out, you may load
9822the module from Guile to get more information about the actual error:
ef5dd60a 9823
cf4a9129
LC
9824@example
9825./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
9826@end example
ef5dd60a 9827
cf4a9129
LC
9828Once your package builds correctly, please send us a patch
9829(@pxref{Contributing}). Well, if you need help, we will be happy to
9830help you too. Once the patch is committed in the Guix repository, the
9831new package automatically gets built on the supported platforms by
2b1cee21 9832@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 9833system}.
ef5dd60a 9834
cf4a9129
LC
9835@cindex substituter
9836Users can obtain the new package definition simply by running
9837@command{guix pull} (@pxref{Invoking guix pull}). When
9838@code{hydra.gnu.org} is done building the package, installing the
9839package automatically downloads binaries from there
9840(@pxref{Substitutes}). The only place where human intervention is
9841needed is to review and apply the patch.
ef5dd60a 9842
ef5dd60a 9843
cf4a9129 9844@menu
ec0339cd
LC
9845* Software Freedom:: What may go into the distribution.
9846* Package Naming:: What's in a name?
9847* Version Numbers:: When the name is not enough.
cbd02397 9848* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
9849* Python Modules:: Taming the snake.
9850* Perl Modules:: Little pearls.
9851* Fonts:: Fond of fonts.
cf4a9129 9852@end menu
ef5dd60a 9853
cf4a9129
LC
9854@node Software Freedom
9855@subsection Software Freedom
ef5dd60a 9856
cf4a9129 9857@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
c11a6eb1 9858
cf4a9129
LC
9859The GNU operating system has been developed so that users can have
9860freedom in their computing. GNU is @dfn{free software}, meaning that
9861users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
9862essential freedoms}: to run the program, to study and change the program
9863in source code form, to redistribute exact copies, and to distribute
9864modified versions. Packages found in the GNU distribution provide only
9865software that conveys these four freedoms.
c11a6eb1 9866
cf4a9129
LC
9867In addition, the GNU distribution follow the
9868@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
9869software distribution guidelines}. Among other things, these guidelines
9870reject non-free firmware, recommendations of non-free software, and
9871discuss ways to deal with trademarks and patents.
ef5dd60a 9872
cf4a9129
LC
9873Some packages contain a small and optional subset that violates the
9874above guidelines, for instance because this subset is itself non-free
9875code. When that happens, the offending items are removed with
9876appropriate patches or code snippets in the package definition's
9877@code{origin} form (@pxref{Defining Packages}). That way, @code{guix
9878build --source} returns the ``freed'' source rather than the unmodified
9879upstream source.
ef5dd60a 9880
ef5dd60a 9881
cf4a9129
LC
9882@node Package Naming
9883@subsection Package Naming
ef5dd60a 9884
cf4a9129
LC
9885A package has actually two names associated with it:
9886First, there is the name of the @emph{Scheme variable}, the one following
9887@code{define-public}. By this name, the package can be made known in the
9888Scheme code, for instance as input to another package. Second, there is
9889the string in the @code{name} field of a package definition. This name
9890is used by package management commands such as
9891@command{guix package} and @command{guix build}.
ef5dd60a 9892
cf4a9129
LC
9893Both are usually the same and correspond to the lowercase conversion of
9894the project name chosen upstream, with underscores replaced with
9895hyphens. For instance, GNUnet is available as @code{gnunet}, and
9896SDL_net as @code{sdl-net}.
927097ef 9897
cf4a9129 9898We do not add @code{lib} prefixes for library packages, unless these are
081145cf 9899already part of the official project name. But @pxref{Python
cf4a9129
LC
9900Modules} and @ref{Perl Modules} for special rules concerning modules for
9901the Python and Perl languages.
927097ef 9902
1b366ee4 9903Font package names are handled differently, @pxref{Fonts}.
7fec52b7 9904
ef5dd60a 9905
cf4a9129
LC
9906@node Version Numbers
9907@subsection Version Numbers
ef5dd60a 9908
cf4a9129
LC
9909We usually package only the latest version of a given free software
9910project. But sometimes, for instance for incompatible library versions,
9911two (or more) versions of the same package are needed. These require
9912different Scheme variable names. We use the name as defined
9913in @ref{Package Naming}
9914for the most recent version; previous versions use the same name, suffixed
9915by @code{-} and the smallest prefix of the version number that may
9916distinguish the two versions.
ef5dd60a 9917
cf4a9129
LC
9918The name inside the package definition is the same for all versions of a
9919package and does not contain any version number.
ef5dd60a 9920
cf4a9129 9921For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 9922
cf4a9129
LC
9923@example
9924(define-public gtk+
9925 (package
17d8e33f
ML
9926 (name "gtk+")
9927 (version "3.9.12")
9928 ...))
cf4a9129
LC
9929(define-public gtk+-2
9930 (package
17d8e33f
ML
9931 (name "gtk+")
9932 (version "2.24.20")
9933 ...))
cf4a9129
LC
9934@end example
9935If we also wanted GTK+ 3.8.2, this would be packaged as
9936@example
9937(define-public gtk+-3.8
9938 (package
17d8e33f
ML
9939 (name "gtk+")
9940 (version "3.8.2")
9941 ...))
cf4a9129 9942@end example
ef5dd60a 9943
cbd02397
LC
9944@node Synopses and Descriptions
9945@subsection Synopses and Descriptions
9946
9947As we have seen before, each package in GNU@tie{}Guix includes a
9948synopsis and a description (@pxref{Defining Packages}). Synopses and
9949descriptions are important: They are what @command{guix package
9950--search} searches, and a crucial piece of information to help users
9951determine whether a given package suits their needs. Consequently,
9952packagers should pay attention to what goes into them.
9953
9954Synopses must start with a capital letter and must not end with a
9955period. They must not start with ``a'' or ``the'', which usually does
9956not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
9957tool that frobs files''. The synopsis should say what the package
9958is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
9959used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
9960matching a pattern''.
9961
9962Keep in mind that the synopsis must be meaningful for a very wide
9963audience. For example, ``Manipulate alignments in the SAM format''
9964might make sense for a seasoned bioinformatics researcher, but might be
9965fairly unhelpful or even misleading to a non-specialized audience. It
9966is a good idea to come up with a synopsis that gives an idea of the
9967application domain of the package. In this example, this might give
9968something like ``Manipulate nucleotide sequence alignments'', which
9969hopefully gives the user a better idea of whether this is what they are
9970looking for.
9971
9972@cindex Texinfo markup, in package descriptions
9973Descriptions should take between five and ten lines. Use full
9974sentences, and avoid using acronyms without first introducing them.
9975Descriptions can include Texinfo markup, which is useful to introduce
9976ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
9977hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
9978should be careful when using some characters for example @samp{@@} and
9979curly braces which are the basic special characters in Texinfo
9980(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
9981such as @command{guix package --show} take care of rendering it
9982appropriately.
cbd02397
LC
9983
9984Synopses and descriptions are translated by volunteers
9985@uref{http://translationproject.org/domain/guix-packages.html, at the
9986Translation Project} so that as many users as possible can read them in
9987their native language. User interfaces search them and display them in
9988the language specified by the current locale.
9989
9990Translation is a lot of work so, as a packager, please pay even more
9991attention to your synopses and descriptions as every change may entail
ba7d6c76 9992additional work for translators. In order to help them, it is possible
36743e71 9993to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
9994special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
9995Gettext}):
9996
9997@example
9998;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
9999(description "ARandR is designed to provide a simple visual front end
10000for the X11 resize-and-rotate (RandR) extension. @dots{}")
10001@end example
cbd02397 10002
ef5dd60a 10003
cf4a9129
LC
10004@node Python Modules
10005@subsection Python Modules
ef5dd60a 10006
cf4a9129
LC
10007We currently package Python 2 and Python 3, under the Scheme variable names
10008@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
10009To avoid confusion and naming clashes with other programming languages, it
10010seems desirable that the name of a package for a Python module contains
10011the word @code{python}.
ef5dd60a 10012
cf4a9129
LC
10013Some modules are compatible with only one version of Python, others with both.
10014If the package Foo compiles only with Python 3, we name it
10015@code{python-foo}; if it compiles only with Python 2, we name it
10016@code{python2-foo}. If it is compatible with both versions, we create two
10017packages with the corresponding names.
ef5dd60a 10018
cf4a9129
LC
10019If a project already contains the word @code{python}, we drop this;
10020for instance, the module python-dateutil is packaged under the names
10021@code{python-dateutil} and @code{python2-dateutil}.
113daf62 10022
523e4896 10023
cf4a9129
LC
10024@node Perl Modules
10025@subsection Perl Modules
523e4896 10026
cf4a9129
LC
10027Perl programs standing for themselves are named as any other package,
10028using the lowercase upstream name.
10029For Perl packages containing a single class, we use the lowercase class name,
10030replace all occurrences of @code{::} by dashes and prepend the prefix
10031@code{perl-}.
10032So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
10033Modules containing several classes keep their lowercase upstream name and
10034are also prepended by @code{perl-}. Such modules tend to have the word
10035@code{perl} somewhere in their name, which gets dropped in favor of the
10036prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 10037
523e4896 10038
7fec52b7
AE
10039@node Fonts
10040@subsection Fonts
10041
10042For fonts that are in general not installed by a user for typesetting
10043purposes, or that are distributed as part of a larger software package,
10044we rely on the general packaging rules for software; for instance, this
10045applies to the fonts delivered as part of the X.Org system or fonts that
10046are part of TeX Live.
10047
10048To make it easier for a user to search for fonts, names for other packages
10049containing only fonts are constructed as follows, independently of the
10050upstream package name.
10051
10052The name of a package containing only one font family starts with
10053@code{font-}; it is followed by the foundry name and a dash @code{-}
10054if the foundry is known, and the font family name, in which spaces are
10055replaced by dashes (and as usual, all upper case letters are transformed
10056to lower case).
10057For example, the Gentium font family by SIL is packaged under the name
10058@code{font-sil-gentium}.
10059
10060For a package containing several font families, the name of the collection
10061is used in the place of the font family name.
10062For instance, the Liberation fonts consist of three families,
10063Liberation Sans, Liberation Serif and Liberation Mono.
10064These could be packaged separately under the names
10065@code{font-liberation-sans} and so on; but as they are distributed together
10066under a common name, we prefer to package them together as
10067@code{font-liberation}.
10068
10069In the case where several formats of the same font family or font collection
10070are packaged separately, a short form of the format, prepended by a dash,
10071is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 10072@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
10073fonts.
10074
10075
b25937e3 10076
cf4a9129
LC
10077@node Bootstrapping
10078@section Bootstrapping
b25937e3 10079
cf4a9129 10080@c Adapted from the ELS 2013 paper.
b25937e3 10081
cf4a9129 10082@cindex bootstrapping
7889394e 10083
cf4a9129
LC
10084Bootstrapping in our context refers to how the distribution gets built
10085``from nothing''. Remember that the build environment of a derivation
10086contains nothing but its declared inputs (@pxref{Introduction}). So
10087there's an obvious chicken-and-egg problem: how does the first package
10088get built? How does the first compiler get compiled? Note that this is
10089a question of interest only to the curious hacker, not to the regular
10090user, so you can shamelessly skip this section if you consider yourself
10091a ``regular user''.
72b9d60d 10092
cf4a9129
LC
10093@cindex bootstrap binaries
10094The GNU system is primarily made of C code, with libc at its core. The
10095GNU build system itself assumes the availability of a Bourne shell and
10096command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
10097`grep'. Furthermore, build programs---programs that run
10098@code{./configure}, @code{make}, etc.---are written in Guile Scheme
10099(@pxref{Derivations}). Consequently, to be able to build anything at
10100all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
10101Binutils, libc, and the other packages mentioned above---the
10102@dfn{bootstrap binaries}.
72b9d60d 10103
cf4a9129
LC
10104These bootstrap binaries are ``taken for granted'', though we can also
10105re-create them if needed (more on that later).
72b9d60d 10106
cf4a9129 10107@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 10108
cf4a9129
LC
10109@c As of Emacs 24.3, Info-mode displays the image, but since it's a
10110@c large image, it's hard to scroll. Oh well.
10111@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 10112
cf4a9129
LC
10113The figure above shows the very beginning of the dependency graph of the
10114distribution, corresponding to the package definitions of the @code{(gnu
10115packages bootstrap)} module. At this level of detail, things are
10116slightly complex. First, Guile itself consists of an ELF executable,
10117along with many source and compiled Scheme files that are dynamically
10118loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
10119tarball shown in this graph. This tarball is part of Guix's ``source''
10120distribution, and gets inserted into the store with @code{add-to-store}
10121(@pxref{The Store}).
2e7b5cea 10122
cf4a9129
LC
10123But how do we write a derivation that unpacks this tarball and adds it
10124to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
10125derivation---the first one that gets built---uses @code{bash} as its
10126builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
10127@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
10128@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
10129the Guix source distribution, whose sole purpose is to allow the Guile
10130tarball to be unpacked.
fb729425 10131
cf4a9129
LC
10132Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
10133Guile that can be used to run subsequent build programs. Its first task
10134is to download tarballs containing the other pre-built binaries---this
10135is what the @code{.tar.xz.drv} derivations do. Guix modules such as
10136@code{ftp-client.scm} are used for this purpose. The
10137@code{module-import.drv} derivations import those modules in a directory
10138in the store, using the original layout. The
10139@code{module-import-compiled.drv} derivations compile those modules, and
10140write them in an output directory with the right layout. This
10141corresponds to the @code{#:modules} argument of
10142@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 10143
cf4a9129
LC
10144Finally, the various tarballs are unpacked by the
10145derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
10146etc., at which point we have a working C tool chain.
fb729425 10147
fb729425 10148
cf4a9129 10149@unnumberedsubsec Building the Build Tools
523e4896 10150
cf4a9129
LC
10151@c TODO: Add a package-level dependency graph generated from (gnu
10152@c packages base).
df2ce343 10153
cf4a9129
LC
10154Bootstrapping is complete when we have a full tool chain that does not
10155depend on the pre-built bootstrap tools discussed above. This
10156no-dependency requirement is verified by checking whether the files of
10157the final tool chain contain references to the @file{/gnu/store}
10158directories of the bootstrap inputs. The process that leads to this
10159``final'' tool chain is described by the package definitions found in
1f6f57df 10160the @code{(gnu packages commencement)} module.
df2ce343 10161
cf4a9129
LC
10162@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
10163The first tool that gets built with the bootstrap binaries is
10164GNU Make, which is a prerequisite for all the following packages.
10165From there Findutils and Diffutils get built.
523e4896 10166
cf4a9129
LC
10167Then come the first-stage Binutils and GCC, built as pseudo cross
10168tools---i.e., with @code{--target} equal to @code{--host}. They are
10169used to build libc. Thanks to this cross-build trick, this libc is
10170guaranteed not to hold any reference to the initial tool chain.
4af2447e 10171
cf4a9129
LC
10172From there the final Binutils and GCC are built. GCC uses @code{ld}
10173from the final Binutils, and links programs against the just-built libc.
10174This tool chain is used to build the other packages used by Guix and by
10175the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 10176
cf4a9129
LC
10177And voilà! At this point we have the complete set of build tools that
10178the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
10179variable of the @code{(gnu packages commencement)} module, and are
10180implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 10181(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 10182
4af2447e 10183
cf4a9129 10184@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 10185
cf4a9129
LC
10186Because the final tool chain does not depend on the bootstrap binaries,
10187those rarely need to be updated. Nevertheless, it is useful to have an
10188automated way to produce them, should an update occur, and this is what
10189the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 10190
cf4a9129
LC
10191The following command builds the tarballs containing the bootstrap
10192binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
10193of Coreutils and other basic command-line tools):
4b2615e1 10194
cf4a9129
LC
10195@example
10196guix build bootstrap-tarballs
10197@end example
10198
10199The generated tarballs are those that should be referred to in the
10200@code{(gnu packages bootstrap)} module mentioned at the beginning of
10201this section.
10202
10203Still here? Then perhaps by now you've started to wonder: when do we
10204reach a fixed point? That is an interesting question! The answer is
10205unknown, but if you would like to investigate further (and have
10206significant computational and storage resources to do so), then let us
10207know.
10208
10209@node Porting
10210@section Porting to a New Platform
10211
10212As discussed above, the GNU distribution is self-contained, and
10213self-containment is achieved by relying on pre-built ``bootstrap
10214binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
10215operating system kernel, CPU architecture, and application binary
10216interface (ABI). Thus, to port the distribution to a platform that is
10217not yet supported, one must build those bootstrap binaries, and update
10218the @code{(gnu packages bootstrap)} module to use them on that platform.
10219
10220Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
10221When everything goes well, and assuming the GNU tool chain supports the
10222target platform, this can be as simple as running a command like this
10223one:
10224
10225@example
10226guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
10227@end example
10228
1c0c417d
LC
10229For this to work, the @code{glibc-dynamic-linker} procedure in
10230@code{(gnu packages bootstrap)} must be augmented to return the right
10231file name for libc's dynamic linker on that platform; likewise,
10232@code{system->linux-architecture} in @code{(gnu packages linux)} must be
10233taught about the new platform.
10234
cf4a9129 10235Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
10236to be updated to refer to these binaries on the target platform. That
10237is, the hashes and URLs of the bootstrap tarballs for the new platform
10238must be added alongside those of the currently supported platforms. The
10239bootstrap Guile tarball is treated specially: it is expected to be
10240available locally, and @file{gnu-system.am} has rules do download it for
10241the supported architectures; a rule for the new platform must be added
10242as well.
cf4a9129
LC
10243
10244In practice, there may be some complications. First, it may be that the
10245extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
10246above) is not recognized by all the GNU tools. Typically, glibc
10247recognizes some of these, whereas GCC uses an extra @code{--with-abi}
10248configure flag (see @code{gcc.scm} for examples of how to handle this).
10249Second, some of the required packages could fail to build for that
10250platform. Lastly, the generated binaries could be broken for some
10251reason.
4af2447e 10252
9bf3c1a7 10253@c *********************************************************************
8c01b9d0 10254@include contributing.texi
c78bd12b 10255
568717fd
LC
10256@c *********************************************************************
10257@node Acknowledgments
10258@chapter Acknowledgments
10259
136787cb
LC
10260Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
10261which was designed and
4c7ac9aa
LC
10262implemented by Eelco Dolstra, with contributions from other people (see
10263the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
10264management, and promoted unprecedented features, such as transactional
10265package upgrades and rollbacks, per-user profiles, and referentially
10266transparent build processes. Without this work, Guix would not exist.
10267
10268The Nix-based software distributions, Nixpkgs and NixOS, have also been
10269an inspiration for Guix.
10270
4c7ac9aa
LC
10271GNU@tie{}Guix itself is a collective work with contributions from a
10272number of people. See the @file{AUTHORS} file in Guix for more
10273information on these fine people. The @file{THANKS} file lists people
10274who have helped by reporting bugs, taking care of the infrastructure,
10275providing artwork and themes, making suggestions, and more---thank you!
10276
10277
568717fd
LC
10278@c *********************************************************************
10279@node GNU Free Documentation License
10280@appendix GNU Free Documentation License
10281
10282@include fdl-1.3.texi
10283
10284@c *********************************************************************
10285@node Concept Index
10286@unnumbered Concept Index
10287@printindex cp
10288
a85b83d2
LC
10289@node Programming Index
10290@unnumbered Programming Index
10291@syncodeindex tp fn
10292@syncodeindex vr fn
568717fd
LC
10293@printindex fn
10294
10295@bye
10296
10297@c Local Variables:
10298@c ispell-local-dictionary: "american";
10299@c End: