doc: Clarify 'cow-store'.
[jackhill/guix/guix.git] / doc / guix.texi
CommitLineData
568717fd
LC
1\input texinfo
2@c -*-texinfo-*-
3
4@c %**start of header
5@setfilename guix.info
6@documentencoding UTF-8
f8348b91 7@settitle GNU Guix Reference Manual
568717fd
LC
8@c %**end of header
9
10@include version.texi
7df7a74e
NK
11
12@copying
db5a9444 13Copyright @copyright{} 2012, 2013, 2014, 2015, 2016 Ludovic Courtès@*
f97c9175 14Copyright @copyright{} 2013, 2014, 2016 Andreas Enge@*
87eafdbd 15Copyright @copyright{} 2013 Nikita Karetnikov@*
1b846da8 16Copyright @copyright{} 2015, 2016 Mathieu Lirzin@*
8c01b9d0 17Copyright @copyright{} 2014 Pierre-Antoine Rault@*
97d76250 18Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer@*
4d343a14
CM
19Copyright @copyright{} 2015, 2016 Leo Famulari@*
20Copyright @copyright{} 2016 Ben Woodcroft@*
21Copyright @copyright{} 2016 Chris Marusich
7df7a74e
NK
22
23Permission is granted to copy, distribute and/or modify this document
24under the terms of the GNU Free Documentation License, Version 1.3 or
25any later version published by the Free Software Foundation; with no
26Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
27copy of the license is included in the section entitled ``GNU Free
28Documentation License''.
29@end copying
568717fd 30
abd67856 31@dircategory System administration
568717fd 32@direntry
abd67856
LC
33* Guix: (guix). Manage installed software and system configuration.
34* guix package: (guix)Invoking guix package. Installing, removing, and upgrading packages.
35* guix build: (guix)Invoking guix build. Building packages.
36* guix gc: (guix)Invoking guix gc. Reclaiming unused disk space.
37* guix pull: (guix)Invoking guix pull. Update the list of available packages.
38* guix system: (guix)Invoking guix system. Manage the operating system configuration.
568717fd 39@end direntry
568717fd 40
372c4bbc
DT
41@dircategory Software development
42@direntry
abd67856 43* guix environment: (guix)Invoking guix environment. Building development environments with Guix.
372c4bbc
DT
44@end direntry
45
abd67856
LC
46@dircategory Emacs
47@direntry
48* Guix user interface: (guix)Emacs Interface. Package management from the comfort of Emacs.
49@end direntry
50
51
568717fd 52@titlepage
7730d112
LC
53@title GNU Guix Reference Manual
54@subtitle Using the GNU Guix Functional Package Manager
2cbed07e 55@author The GNU Guix Developers
568717fd
LC
56
57@page
58@vskip 0pt plus 1filll
59Edition @value{EDITION} @*
60@value{UPDATED} @*
61
7df7a74e 62@insertcopying
568717fd
LC
63@end titlepage
64
568717fd
LC
65@contents
66
67@c *********************************************************************
68@node Top
f8348b91 69@top GNU Guix
568717fd 70
f8348b91
LC
71This document describes GNU Guix version @value{VERSION}, a functional
72package management tool written for the GNU system.
568717fd
LC
73
74@menu
75* Introduction:: What is Guix about?
bd5e766b 76* Installation:: Installing Guix.
eeaf4427 77* Package Management:: Package installation, upgrade, etc.
c554de89 78* Emacs Interface:: Using Guix from Emacs.
568717fd
LC
79* Programming Interface:: Using Guix in Scheme.
80* Utilities:: Package management commands.
a1ba8475 81* GNU Distribution:: Software for your friendly GNU system.
9bf3c1a7 82* Contributing:: Your help needed!
568717fd
LC
83
84* Acknowledgments:: Thanks!
85* GNU Free Documentation License:: The license of this manual.
86* Concept Index:: Concepts.
a85b83d2 87* Programming Index:: Data types, functions, and variables.
aaa3eaa9
LC
88
89@detailmenu
90 --- The Detailed Node Listing ---
91
92Installation
93
1b2b8177 94* Binary Installation:: Getting Guix running in no time!
aaa3eaa9 95* Requirements:: Software needed to build and run Guix.
ec0339cd 96* Running the Test Suite:: Testing Guix.
aaa3eaa9
LC
97* Setting Up the Daemon:: Preparing the build daemon's environment.
98* Invoking guix-daemon:: Running the build daemon.
0e2d0213 99* Application Setup:: Application-specific setup.
aaa3eaa9
LC
100
101Setting Up the Daemon
102
103* Build Environment Setup:: Preparing the isolated build environment.
104* Daemon Offload Setup:: Offloading builds to remote machines.
105
106Package Management
107
108* Features:: How Guix will make your life brighter.
109* Invoking guix package:: Package installation, removal, etc.
aaa3eaa9
LC
110* Substitutes:: Downloading pre-built binaries.
111* Packages with Multiple Outputs:: Single source package, multiple outputs.
112* Invoking guix gc:: Running the garbage collector.
113* Invoking guix pull:: Fetching the latest Guix and distribution.
114* Invoking guix archive:: Exporting and importing store files.
115
c554de89
AK
116Emacs Interface
117
118* Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
119* Package Management: Emacs Package Management. Managing packages and generations.
687c9bc0 120* Licenses: Emacs Licenses. Interface for licenses of Guix packages.
9b0afb0d 121* Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
c554de89 122* Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
34850cd5 123* Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
187f80c6
AK
124* Completions: Emacs Completions. Completing @command{guix} shell command.
125* Development: Emacs Development. Tools for Guix developers.
32950fc8 126* Hydra: Emacs Hydra. Interface for Guix build farm.
c554de89 127
aaa3eaa9
LC
128Programming Interface
129
130* Defining Packages:: Defining new packages.
131* Build Systems:: Specifying how packages are built.
132* The Store:: Manipulating the package store.
133* Derivations:: Low-level interface to package derivations.
134* The Store Monad:: Purely functional interface to the store.
135* G-Expressions:: Manipulating build expressions.
136
92492b23
LC
137Defining Packages
138
139* package Reference:: The package data type.
140* origin Reference:: The origin data type.
141
aaa3eaa9
LC
142Utilities
143
144* Invoking guix build:: Building packages from the command line.
fcc58db6 145* Invoking guix edit:: Editing package definitions.
aaa3eaa9
LC
146* Invoking guix download:: Downloading a file and printing its hash.
147* Invoking guix hash:: Computing the cryptographic hash of a file.
148* Invoking guix import:: Importing package definitions.
149* Invoking guix refresh:: Updating package definitions.
150* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 151* Invoking guix size:: Profiling disk usage.
88856916 152* Invoking guix graph:: Visualizing the graph of packages.
aaa3eaa9 153* Invoking guix environment:: Setting up development environments.
aff8ce7c 154* Invoking guix publish:: Sharing substitutes.
d23c20f1 155* Invoking guix challenge:: Challenging substitute servers.
32efa254 156* Invoking guix container:: Process isolation.
aaa3eaa9 157
e3009f60
LC
158Invoking @command{guix build}
159
160* Common Build Options:: Build options for most commands.
161* Package Transformation Options:: Creating variants of packages.
162* Additional Build Options:: Options specific to 'guix build'.
163
aaa3eaa9
LC
164GNU Distribution
165
166* System Installation:: Installing the whole operating system.
35ed9306 167* System Configuration:: Configuring the operating system.
aaa3eaa9
LC
168* Installing Debugging Files:: Feeding the debugger.
169* Security Updates:: Deploying security fixes quickly.
170* Package Modules:: Packages from the programmer's viewpoint.
171* Packaging Guidelines:: Growing the distribution.
172* Bootstrapping:: GNU/Linux built from scratch.
173* Porting:: Targeting another platform or kernel.
174
e3009f60
LC
175System Installation
176
177* Limitations:: What you can expect.
178* Hardware Considerations:: Supported hardware.
179* USB Stick Installation:: Preparing the installation medium.
180* Preparing for Installation:: Networking, partitioning, etc.
181* Proceeding with the Installation:: The real thing.
182* Building the Installation Image:: How this comes to be.
183
aaa3eaa9
LC
184System Configuration
185
186* Using the Configuration System:: Customizing your GNU system.
187* operating-system Reference:: Detail of operating-system declarations.
188* File Systems:: Configuring file system mounts.
189* Mapped Devices:: Block device extra processing.
190* User Accounts:: Specifying user accounts.
598e19dc 191* Locales:: Language and cultural convention settings.
aaa3eaa9
LC
192* Services:: Specifying system services.
193* Setuid Programs:: Programs running with root privileges.
1b2b8177 194* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 195* Name Service Switch:: Configuring libc's name service switch.
aaa3eaa9
LC
196* Initial RAM Disk:: Linux-Libre bootstrapping.
197* GRUB Configuration:: Configuring the boot loader.
198* Invoking guix system:: Instantiating a system configuration.
97d76250 199* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
aaa3eaa9
LC
200* Defining Services:: Adding new service definitions.
201
202Services
203
204* Base Services:: Essential system services.
205* Networking Services:: Network setup, SSH daemon, etc.
206* X Window:: Graphical display.
1b2b8177
LC
207* Desktop Services:: D-Bus and desktop services.
208* Database Services:: SQL databases.
d8c18af8 209* Mail Services:: IMAP, POP3, SMTP, and all that.
cbd02397 210* Web Services:: Web servers.
aa4ed923 211* Various Services:: Other services.
aaa3eaa9 212
0adfe95a
LC
213Defining Services
214
215* Service Composition:: The model for composing services.
216* Service Types and Services:: Types and services.
217* Service Reference:: API reference.
dd17bc38 218* Shepherd Services:: A particular type of service.
0adfe95a 219
aaa3eaa9
LC
220Packaging Guidelines
221
ec0339cd
LC
222* Software Freedom:: What may go into the distribution.
223* Package Naming:: What's in a name?
224* Version Numbers:: When the name is not enough.
cbd02397 225* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
226* Python Modules:: Taming the snake.
227* Perl Modules:: Little pearls.
228* Fonts:: Fond of fonts.
aaa3eaa9 229
8c01b9d0
ML
230Contributing
231
232* Building from Git:: The latest and greatest.
233* Running Guix Before It Is Installed:: Hacker tricks.
234* The Perfect Setup:: The right tools.
235* Coding Style:: Hygiene of the contributor.
236* Submitting Patches:: Share your work.
237
238Coding Style
239
240* Programming Paradigm:: How to compose your elements.
241* Modules:: Where to store your code?
242* Data Types and Pattern Matching:: Implementing data structures.
243* Formatting Code:: Writing conventions.
244
aaa3eaa9 245@end detailmenu
568717fd
LC
246@end menu
247
248@c *********************************************************************
249@node Introduction
250@chapter Introduction
251
6f773606 252@cindex purpose
c80e7e55 253GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
6f773606
LC
254using the international phonetic alphabet (IPA).} is a package
255management tool for the GNU system. Guix makes it easy for unprivileged
256users to install, upgrade, or remove packages, to roll back to a
257previous package set, to build packages from source, and generally
258assists with the creation and maintenance of software environments.
259
260@cindex user interfaces
261Guix provides a command-line package management interface
262(@pxref{Invoking guix package}), a set of command-line utilities
263(@pxref{Utilities}), a visual user interface in Emacs (@pxref{Emacs
264Interface}), as well as Scheme programming interfaces
265(@pxref{Programming Interface}).
266@cindex build daemon
267Its @dfn{build daemon} is responsible for building packages on behalf of
268users (@pxref{Setting Up the Daemon}) and for downloading pre-built
269binaries from authorized sources (@pxref{Substitutes}).
270
271@cindex extensibility of the distribution
272@cindex customization of packages
273Guix includes package definitions for many GNU and non-GNU packages, all
274of which @uref{https://www.gnu.org/philosophy/free-sw.html, respect the
275user's computing freedom}. It is @emph{extensible}: users can write
276their own package definitions (@pxref{Defining Packages}) and make them
277available as independent package modules (@pxref{Package Modules}). It
278is also @emph{customizable}: users can @emph{derive} specialized package
279definitions from existing ones, including from the command line
280(@pxref{Package Transformation Options}).
281
282@cindex Guix System Distribution
283@cindex GuixSD
284You can install GNU@tie{}Guix on top of an existing GNU/Linux system
285where it complements the available tools without interference
286(@pxref{Installation}), or you can use it as part of the standalone
287@dfn{Guix System Distribution} or GuixSD (@pxref{GNU Distribution}).
288With GNU@tie{}GuixSD, you @emph{declare} all aspects of the operating
289system configuration and Guix takes care of instantiating the
290configuration in a transactional, reproducible, and stateless fashion
291(@pxref{System Configuration}).
568717fd
LC
292
293@cindex functional package management
6f773606 294Under the hood, Guix implements the @dfn{functional package management}
136787cb
LC
295discipline pioneered by Nix (@pxref{Acknowledgments}).
296In Guix, the package build and installation process is seen
6f773606 297as a @emph{function}, in the mathematical sense. That function takes inputs,
4bfc4ea3
NK
298such as build scripts, a compiler, and libraries, and
299returns an installed package. As a pure function, its result depends
568717fd
LC
300solely on its inputs---for instance, it cannot refer to software or
301scripts that were not explicitly passed as inputs. A build function
4bfc4ea3 302always produces the same result when passed a given set of inputs. It
f97c9175 303cannot alter the environment of the running system in
568717fd
LC
304any way; for instance, it cannot create, modify, or delete files outside
305of its build and installation directories. This is achieved by running
e900c503 306build processes in isolated environments (or @dfn{containers}), where only their
4bfc4ea3 307explicit inputs are visible.
568717fd 308
e531ac2a 309@cindex store
568717fd 310The result of package build functions is @dfn{cached} in the file
e531ac2a 311system, in a special directory called @dfn{the store} (@pxref{The
f97c9175 312Store}). Each package is installed in a directory of its own in the
834129e0 313store---by default under @file{/gnu/store}. The directory name contains
568717fd
LC
314a hash of all the inputs used to build that package; thus, changing an
315input yields a different directory name.
316
f97c9175
AE
317This approach is the foundation for the salient features of Guix: support
318for transactional package upgrade and rollback, per-user installation, and
eeaf4427 319garbage collection of packages (@pxref{Features}).
568717fd 320
a1ba8475 321
bd5e766b
LC
322@c *********************************************************************
323@node Installation
324@chapter Installation
325
48febeb8
LC
326GNU Guix is available for download from its website at
327@url{http://www.gnu.org/software/guix/}. This section describes the
328software requirements of Guix, as well as how to install it and get
329ready to use it.
bd5e766b 330
5af6de3e
LC
331Note that this section is concerned with the installation of the package
332manager, which can be done on top of a running GNU/Linux system. If,
333instead, you want to install the complete GNU operating system,
6621cdb6 334@pxref{System Installation}.
5af6de3e 335
bd5e766b 336@menu
09722b11 337* Binary Installation:: Getting Guix running in no time!
bd5e766b 338* Requirements:: Software needed to build and run Guix.
ec0339cd 339* Running the Test Suite:: Testing Guix.
bd5e766b
LC
340* Setting Up the Daemon:: Preparing the build daemon's environment.
341* Invoking guix-daemon:: Running the build daemon.
0e2d0213 342* Application Setup:: Application-specific setup.
bd5e766b
LC
343@end menu
344
09722b11
LC
345@node Binary Installation
346@section Binary Installation
347
348This section describes how to install Guix on an arbitrary system from a
349self-contained tarball providing binaries for Guix and for all its
350dependencies. This is often quicker than installing from source, which
351is described in the next sections. The only requirement is to have
352GNU@tie{}tar and Xz.
353
354Installing goes along these lines:
355
356@enumerate
357@item
358Download the binary tarball from
daa8922a
LC
359@indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz},
360where @var{system} is @code{x86_64-linux} for an @code{x86_64} machine
361already running the kernel Linux, and so on.
362
363Make sure to download the associated @file{.sig} file and to verify the
364authenticity of the tarball against it, along these lines:
365
366@example
367$ wget ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
368$ gpg --verify guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
369@end example
370
f97c9175 371If that command fails because you do not have the required public key,
daa8922a
LC
372then run this command to import it:
373
374@example
375$ gpg --keyserver keys.gnupg.net --recv-keys 3D9AEBB5
376@end example
377
378@noindent
379and rerun the @code{gpg --verify} command.
09722b11
LC
380
381@item
382As @code{root}, run:
383
384@example
5dc42964 385# cd /tmp
254b1c2e
LC
386# tar --warning=no-timestamp -xf \
387 guix-binary-@value{VERSION}.@var{system}.tar.xz
5dc42964 388# mv var/guix /var/ && mv gnu /
09722b11
LC
389@end example
390
7acd3439
LC
391This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
392The latter contains a ready-to-use profile for @code{root} (see next
393step.)
09722b11 394
5dc3ce5f
LC
395Do @emph{not} unpack the tarball on a working Guix system since that
396would overwrite its own essential files.
397
254b1c2e 398The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
e9ba6357
LC
399not emit warnings about ``implausibly old time stamps'' (such
400warnings were triggered by GNU@tie{}tar 1.26 and older; recent
401versions are fine.)
402They stem from the fact that all the
254b1c2e
LC
403files in the archive have their modification time set to zero (which
404means January 1st, 1970.) This is done on purpose to make sure the
405archive content is independent of its creation time, thus making it
406reproducible.
407
7acd3439
LC
408@item
409Make @code{root}'s profile available under @file{~/.guix-profile}:
410
411@example
412# ln -sf /var/guix/profiles/per-user/root/guix-profile \
413 ~root/.guix-profile
414@end example
415
43c33047
LC
416@item
417Create the group and user accounts for build users as explained below
418(@pxref{Build Environment Setup}).
419
09722b11 420@item
bf98aea9 421Run the daemon, and set it to automatically start on boot.
c8e26887 422
bf98aea9
LC
423If your host distro uses the systemd init system, this can be achieved
424with these commands:
c8e26887
GC
425
426@example
427# cp ~root/.guix-profile/lib/systemd/system/guix-daemon.service \
428 /etc/systemd/system/
429# systemctl start guix-daemon && systemctl enable guix-daemon
430@end example
431
432If your host distro uses the Upstart init system:
09722b11
LC
433
434@example
c8e26887 435# cp ~root/.guix-profile/lib/upstart/system/guix-daemon.conf /etc/init/
bf98aea9 436# start guix-daemon
09722b11
LC
437@end example
438
c8e26887
GC
439Otherwise, you can still start the daemon manually with:
440
441@example
442# ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
443@end example
d2825c96 444
09722b11
LC
445@item
446Make the @command{guix} command available to other users on the machine,
447for instance with:
448
449@example
450# mkdir -p /usr/local/bin
451# cd /usr/local/bin
d72d05f9 452# ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
09722b11 453@end example
39f8ed14 454
aca738f3
LC
455It is also a good idea to make the Info version of this manual available
456there:
457
458@example
459# mkdir -p /usr/local/share/info
460# cd /usr/local/share/info
461# for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
462 do ln -s $i ; done
463@end example
464
465That way, assuming @file{/usr/local/share/info} is in the search path,
466running @command{info guix} will open this manual (@pxref{Other Info
467Directories,,, texinfo, GNU Texinfo}, for more details on changing the
468Info search path.)
469
39f8ed14 470@item
df061d07
LC
471To use substitutes from @code{hydra.gnu.org} or one of its mirrors
472(@pxref{Substitutes}), authorize them:
39f8ed14
LC
473
474@example
7acd3439 475# guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
39f8ed14 476@end example
09722b11
LC
477@end enumerate
478
bf98aea9 479This completes root-level install of Guix. Each user will need to
c8e26887
GC
480perform additional steps to make their Guix envionment ready for use,
481@pxref{Application Setup}.
09722b11 482
c8e26887
GC
483You can confirm that Guix is working by installing a sample package into
484the root profile:
09722b11
LC
485
486@example
c8e26887 487# guix package -i hello
09722b11
LC
488@end example
489
c8e26887
GC
490The @code{guix} package must remain available in @code{root}'s profile,
491or it would become subject to garbage collection---in which case you
492would find yourself badly handicapped by the lack of the @command{guix}
bf98aea9
LC
493command. In other words, do not remove @code{guix} by running
494@code{guix package -r guix}.
495
496The binary installation tarball can be (re)produced and verified simply
497by running the following command in the Guix source tree:
498
499@example
500make guix-binary.@var{system}.tar.xz
501@end example
c8e26887 502
09722b11 503
bd5e766b
LC
504@node Requirements
505@section Requirements
506
09722b11
LC
507This section lists requirements when building Guix from source. The
508build procedure for Guix is the same as for other GNU software, and is
509not covered here. Please see the files @file{README} and @file{INSTALL}
510in the Guix source tree for additional details.
511
bd5e766b
LC
512GNU Guix depends on the following packages:
513
514@itemize
47c66da0 515@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
288dca55 516@item @url{http://gnupg.org/, GNU libgcrypt};
f0b98b84 517@item @url{http://www.gnu.org/software/make/, GNU Make}.
8a96bd4b
ID
518@end itemize
519
520The following dependencies are optional:
521
522@itemize
9b7bd1b1
LC
523@item
524Installing @uref{http://gnutls.org/, GnuTLS-Guile} will allow you to
525access @code{https} URLs for substitutes, which is highly recommended
526(@pxref{Substitutes}). It also allows you to access HTTPS URLs with the
527@command{guix download} command (@pxref{Invoking guix download}), the
528@command{guix import pypi} command, and the @command{guix import cpan}
529command. @xref{Guile Preparations, how to install the GnuTLS bindings
530for Guile,, gnutls-guile, GnuTLS-Guile}.
531
288dca55 532@item
8a96bd4b 533Installing
288dca55 534@url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
2f7d2d91
LC
535allow you to use the @command{guix import pypi} command (@pxref{Invoking
536guix import}). It is of
288dca55 537interest primarily for developers and not for casual users.
bd5e766b
LC
538@end itemize
539
540Unless @code{--disable-daemon} was passed to @command{configure}, the
541following packages are also needed:
542
543@itemize
368d08f7
LC
544@item @url{http://sqlite.org, SQLite 3};
545@item @url{http://www.bzip.org, libbz2};
546@item @url{http://gcc.gnu.org, GCC's g++}, with support for the
547C++11 standard.
bd5e766b
LC
548@end itemize
549
ef5f5c86
LC
550When configuring Guix on a system that already has a Guix installation,
551be sure to specify the same state directory as the existing installation
552using the @code{--localstatedir} option of the @command{configure}
553script (@pxref{Directory Variables, @code{localstatedir},, standards,
554GNU Coding Standards}). The @command{configure} script protects against
555unintended misconfiguration of @var{localstatedir} so you do not
556inadvertently corrupt your store (@pxref{The Store}).
557
4bfc4ea3
NK
558When a working installation of @url{http://nixos.org/nix/, the Nix package
559manager} is available, you
bd5e766b 560can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 561Nix replaces the three dependencies above.
bd5e766b 562
b22a12fd
LC
563Guix is compatible with Nix, so it is possible to share the same store
564between both. To do so, you must pass @command{configure} not only the
565same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
566@code{--localstatedir} value. The latter is essential because it
567specifies where the database that stores metadata about the store is
834129e0 568located, among other things. The default values for Nix are
b22a12fd 569@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
570Note that @code{--disable-daemon} is not required if
571your goal is to share the store with Nix.
b22a12fd 572
ec0339cd
LC
573@node Running the Test Suite
574@section Running the Test Suite
575
576After a successful @command{configure} and @code{make} run, it is a good
577idea to run the test suite. It can help catch issues with the setup or
578environment, or bugs in Guix itself---and really, reporting test
579failures is a good way to help improve the software. To run the test
580suite, type:
581
582@example
583make check
584@end example
585
586Test cases can run in parallel: you can use the @code{-j} option of
587GNU@tie{}make to speed things up. The first run may take a few minutes
588on a recent machine; subsequent runs will be faster because the store
589that is created for test purposes will already have various things in
590cache.
591
a887fd8d
LC
592It is also possible to run a subset of the tests by defining the
593@code{TESTS} makefile variable as in this example:
594
595@example
596make check TESTS="tests/store.scm tests/cpio.scm"
597@end example
598
ec0339cd
LC
599Upon failure, please email @email{bug-guix@@gnu.org} and attach the
600@file{test-suite.log} file. When @file{tests/@var{something}.scm}
601fails, please also attach the @file{@var{something}.log} file available
602in the top-level build directory. Please specify the Guix version being
603used as well as version numbers of the dependencies
604(@pxref{Requirements}) in your message.
605
bd5e766b
LC
606@node Setting Up the Daemon
607@section Setting Up the Daemon
608
609@cindex daemon
610Operations such as building a package or running the garbage collector
49e6291a 611are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
612behalf of clients. Only the daemon may access the store and its
613associated database. Thus, any operation that manipulates the store
614goes through the daemon. For instance, command-line tools such as
e49951eb 615@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
616daemon (@i{via} remote procedure calls) to instruct it what to do.
617
49e6291a 618The following sections explain how to prepare the build daemon's
f97c9175 619environment. See also @ref{Substitutes}, for information on how to allow
225dafde 620the daemon to download pre-built binaries.
49e6291a
LC
621
622@menu
623* Build Environment Setup:: Preparing the isolated build environment.
624* Daemon Offload Setup:: Offloading builds to remote machines.
625@end menu
626
627@node Build Environment Setup
628@subsection Build Environment Setup
629
bd5e766b
LC
630In a standard multi-user setup, Guix and its daemon---the
631@command{guix-daemon} program---are installed by the system
834129e0 632administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
633@command{guix-daemon} runs as @code{root}. Unprivileged users may use
634Guix tools to build packages or otherwise access the store, and the
635daemon will do it on their behalf, ensuring that the store is kept in a
636consistent state, and allowing built packages to be shared among users.
637
638@cindex build users
639When @command{guix-daemon} runs as @code{root}, you may not want package
640build processes themselves to run as @code{root} too, for obvious
641security reasons. To avoid that, a special pool of @dfn{build users}
642should be created for use by build processes started by the daemon.
643These build users need not have a shell and a home directory: they will
644just be used when the daemon drops @code{root} privileges in build
645processes. Having several such users allows the daemon to launch
646distinct build processes under separate UIDs, which guarantees that they
647do not interfere with each other---an essential feature since builds are
648regarded as pure functions (@pxref{Introduction}).
649
650On a GNU/Linux system, a build user pool may be created like this (using
651Bash syntax and the @code{shadow} commands):
652
091196b3
LC
653@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
654@c for why `-G' is needed.
bd5e766b 655@example
cfc149dc
LC
656# groupadd --system guixbuild
657# for i in `seq -w 1 10`;
bd5e766b 658 do
cfc149dc
LC
659 useradd -g guixbuild -G guixbuild \
660 -d /var/empty -s `which nologin` \
661 -c "Guix build user $i" --system \
662 guixbuilder$i;
bd5e766b
LC
663 done
664@end example
665
666@noindent
54eb03ab
LC
667The number of build users determines how many build jobs may run in
668parallel, as specified by the @option{--max-jobs} option
d2825c96
LC
669(@pxref{Invoking guix-daemon, @option{--max-jobs}}). The
670@code{guix-daemon} program may then be run as @code{root} with the
671following command@footnote{If your machine uses the systemd init system,
672dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
673file in @file{/etc/systemd/system} will ensure that
ad227484
MDRS
674@command{guix-daemon} is automatically started. Similarly, if your
675machine uses the Upstart init system, drop the
676@file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
677file in @file{/etc/init}.}:
bd5e766b
LC
678
679@example
cfc149dc 680# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
681@end example
682
e900c503 683@cindex chroot
b095792f
LC
684@noindent
685This way, the daemon starts build processes in a chroot, under one of
cfc149dc 686the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
687environment contains nothing but:
688
689@c Keep this list in sync with libstore/build.cc! -----------------------
690@itemize
691@item
4743a4da
LC
692a minimal @code{/dev} directory, created mostly independently from the
693host @code{/dev}@footnote{``Mostly'', because while the set of files
694that appear in the chroot's @code{/dev} is fixed, most of these files
695can only be created if the host has them.};
696
697@item
f97c9175 698the @code{/proc} directory; it only shows the processes of the container
4743a4da 699since a separate PID name space is used;
6dc99317
LC
700
701@item
702@file{/etc/passwd} with an entry for the current user and an entry for
703user @file{nobody};
704
705@item
706@file{/etc/group} with an entry for the user's group;
707
708@item
709@file{/etc/hosts} with an entry that maps @code{localhost} to
710@code{127.0.0.1};
711
712@item
713a writable @file{/tmp} directory.
714@end itemize
b095792f 715
cb960102
ED
716You can influence the directory where the daemon stores build trees
717@i{via} the @code{TMPDIR} environment variable. However, the build tree
f97c9175 718within the chroot is always called @file{/tmp/guix-build-@var{name}.drv-0},
cb960102
ED
719where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
720This way, the value of @code{TMPDIR} does not leak inside build
721environments, which avoids discrepancies in cases where build processes
722capture the name of their build tree.
723
e0c941fe
LC
724@vindex http_proxy
725The daemon also honors the @code{http_proxy} environment variable for
726HTTP downloads it performs, be it for fixed-output derivations
727(@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
728
1e2644bb
LC
729If you are installing Guix as an unprivileged user, it is still possible
730to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
731However, build processes will not be isolated from one another, and not
732from the rest of the system. Thus, build processes may interfere with
733each other, and may access programs, libraries, and other files
734available on the system---making it much harder to view them as
735@emph{pure} functions.
bd5e766b 736
49e6291a
LC
737
738@node Daemon Offload Setup
739@subsection Using the Offload Facility
740
741@cindex offloading
4ec2e92d
LC
742@cindex build hook
743When desired, the build daemon can @dfn{offload}
744derivation builds to other machines
49e6291a
LC
745running Guix, using the @code{offload} @dfn{build hook}. When that
746feature is enabled, a list of user-specified build machines is read from
f97c9175 747@file{/etc/guix/machines.scm}; every time a build is requested, for
49e6291a 748instance via @code{guix build}, the daemon attempts to offload it to one
f97c9175 749of the machines that satisfy the constraints of the derivation, in
49e6291a
LC
750particular its system type---e.g., @file{x86_64-linux}. Missing
751prerequisites for the build are copied over SSH to the target machine,
752which then proceeds with the build; upon success the output(s) of the
753build are copied back to the initial machine.
754
4ec2e92d 755The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
756
757@example
758(list (build-machine
759 (name "eightysix.example.org")
760 (system "x86_64-linux")
761 (user "bob")
762 (speed 2.)) ; incredibly fast!
763
764 (build-machine
765 (name "meeps.example.org")
766 (system "mips64el-linux")
767 (user "alice")
768 (private-key
769 (string-append (getenv "HOME")
c4fdfd6f 770 "/.lsh/identity-for-guix"))))
49e6291a
LC
771@end example
772
773@noindent
774In the example above we specify a list of two build machines, one for
775the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
776architecture.
777
778In fact, this file is---not surprisingly!---a Scheme file that is
779evaluated when the @code{offload} hook is started. Its return value
780must be a list of @code{build-machine} objects. While this example
781shows a fixed list of build machines, one could imagine, say, using
782DNS-SD to return a list of potential build machines discovered in the
783local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
c678a4ee
LC
784Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
785detailed below.
4ec2e92d 786
c678a4ee 787@deftp {Data Type} build-machine
f97c9175
AE
788This data type represents build machines to which the daemon may offload
789builds. The important fields are:
49e6291a
LC
790
791@table @code
792
793@item name
f97c9175 794The host name of the remote machine.
49e6291a
LC
795
796@item system
f97c9175 797The system type of the remote machine---e.g., @code{"x86_64-linux"}.
49e6291a
LC
798
799@item user
800The user account to use when connecting to the remote machine over SSH.
801Note that the SSH key pair must @emph{not} be passphrase-protected, to
802allow non-interactive logins.
803
804@end table
805
4ec2e92d 806A number of optional fields may be specified:
49e6291a
LC
807
808@table @code
809
cecd72d5 810@item port
f97c9175 811Port number of SSH server on the machine (default: 22).
cecd72d5 812
49e6291a
LC
813@item private-key
814The SSH private key file to use when connecting to the machine.
815
c4fdfd6f
LC
816Currently offloading uses GNU@tie{}lsh as its SSH client
817(@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must
818be an lsh key file. This may change in the future, though.
819
49e6291a
LC
820@item parallel-builds
821The number of builds that may run in parallel on the machine (1 by
822default.)
823
824@item speed
825A ``relative speed factor''. The offload scheduler will tend to prefer
826machines with a higher speed factor.
827
828@item features
829A list of strings denoting specific features supported by the machine.
830An example is @code{"kvm"} for machines that have the KVM Linux modules
831and corresponding hardware support. Derivations can request features by
832name, and they will be scheduled on matching build machines.
833
834@end table
c678a4ee 835@end deftp
49e6291a
LC
836
837The @code{guix} command must be in the search path on the build
838machines, since offloading works by invoking the @code{guix archive} and
c4fdfd6f
LC
839@code{guix build} commands. In addition, the Guix modules must be in
840@code{$GUILE_LOAD_PATH} on the build machine---you can check whether
841this is the case by running:
842
843@example
74273b6f 844lsh build-machine guile -c "'(use-modules (guix config))'"
c4fdfd6f 845@end example
49e6291a 846
f97c9175 847There is one last thing to do once @file{machines.scm} is in place. As
49e6291a 848explained above, when offloading, files are transferred back and forth
c4fdfd6f
LC
849between the machine stores. For this to work, you first need to
850generate a key pair on each machine to allow the daemon to export signed
851archives of files from the store (@pxref{Invoking guix archive}):
49e6291a
LC
852
853@example
854# guix archive --generate-key
855@end example
856
857@noindent
c4fdfd6f
LC
858Each build machine must authorize the key of the master machine so that
859it accepts store items it receives from the master:
860
861@example
862# guix archive --authorize < master-public-key.txt
863@end example
864
865@noindent
866Likewise, the master machine must authorize the key of each build machine.
867
868All the fuss with keys is here to express pairwise mutual trust
869relations between the master and the build machines. Concretely, when
870the master receives files from a build machine (and @i{vice versa}), its
871build daemon can make sure they are genuine, have not been tampered
872with, and that they are signed by an authorized key.
49e6291a
LC
873
874
bd5e766b
LC
875@node Invoking guix-daemon
876@section Invoking @command{guix-daemon}
877
878The @command{guix-daemon} program implements all the functionality to
879access the store. This includes launching build processes, running the
880garbage collector, querying the availability of a build result, etc. It
881is normally run as @code{root} like this:
882
883@example
cfc149dc 884# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
885@end example
886
887@noindent
081145cf 888For details on how to set it up, @pxref{Setting Up the Daemon}.
bd5e766b 889
e900c503
LC
890@cindex chroot
891@cindex container, build environment
892@cindex build environment
893@cindex reproducible builds
bd5e766b
LC
894By default, @command{guix-daemon} launches build processes under
895different UIDs, taken from the build group specified with
896@code{--build-users-group}. In addition, each build process is run in a
897chroot environment that only contains the subset of the store that the
898build process depends on, as specified by its derivation
899(@pxref{Programming Interface, derivation}), plus a set of specific
900system directories. By default, the latter contains @file{/dev} and
e900c503
LC
901@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
902@dfn{container}: in addition to having its own file system tree, it has
903a separate mount name space, its own PID name space, network name space,
904etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b 905
cbc538fe
LC
906When the daemon performs a build on behalf of the user, it creates a
907build directory under @file{/tmp} or under the directory specified by
908its @code{TMPDIR} environment variable; this directory is shared with
909the container for the duration of the build. Be aware that using a
910directory other than @file{/tmp} can affect build results---for example,
911with a longer directory name, a build process that uses Unix-domain
912sockets might hit the name length limitation for @code{sun_path}, which
913it would otherwise not hit.
914
915The build directory is automatically deleted upon completion, unless the
916build failed and the client specified @option{--keep-failed}
917(@pxref{Invoking guix build, @option{--keep-failed}}).
918
bd5e766b
LC
919The following command-line options are supported:
920
921@table @code
922@item --build-users-group=@var{group}
923Take users from @var{group} to run build processes (@pxref{Setting Up
924the Daemon, build users}).
925
6858f9d1 926@item --no-substitutes
b5385b52 927@cindex substitutes
6858f9d1 928Do not use substitutes for build products. That is, always build things
c4202d60
LC
929locally instead of allowing downloads of pre-built binaries
930(@pxref{Substitutes}).
6858f9d1 931
b5385b52
LC
932By default substitutes are used, unless the client---such as the
933@command{guix package} command---is explicitly invoked with
934@code{--no-substitutes}.
935
936When the daemon runs with @code{--no-substitutes}, clients can still
937explicitly enable substitution @i{via} the @code{set-build-options}
938remote procedure call (@pxref{The Store}).
939
9176607e 940@item --substitute-urls=@var{urls}
f8a8e0fe 941@anchor{daemon-substitute-urls}
9176607e 942Consider @var{urls} the default whitespace-separated list of substitute
df061d07
LC
943source URLs. When this option is omitted,
944@indicateurl{https://mirror.hydra.gnu.org https://hydra.gnu.org} is used
945(@code{mirror.hydra.gnu.org} is a mirror of @code{hydra.gnu.org}).
9176607e
LC
946
947This means that substitutes may be downloaded from @var{urls}, as long
948as they are signed by a trusted signature (@pxref{Substitutes}).
949
4ec2e92d
LC
950@cindex build hook
951@item --no-build-hook
952Do not use the @dfn{build hook}.
953
954The build hook is a helper program that the daemon can start and to
955which it submits build requests. This mechanism is used to offload
956builds to other machines (@pxref{Daemon Offload Setup}).
957
bd5e766b
LC
958@item --cache-failures
959Cache build failures. By default, only successful builds are cached.
960
30d9aa54
LC
961When this option is used, @command{guix gc --list-failures} can be used
962to query the set of store items marked as failed; @command{guix gc
963--clear-failures} removes store items from the set of cached failures.
964@xref{Invoking guix gc}.
965
bd5e766b
LC
966@item --cores=@var{n}
967@itemx -c @var{n}
968Use @var{n} CPU cores to build each derivation; @code{0} means as many
969as available.
970
6efc160e 971The default value is @code{0}, but it may be overridden by clients, such
e49951eb
MW
972as the @code{--cores} option of @command{guix build} (@pxref{Invoking
973guix build}).
bd5e766b
LC
974
975The effect is to define the @code{NIX_BUILD_CORES} environment variable
976in the build process, which can then use it to exploit internal
977parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
978
979@item --max-jobs=@var{n}
980@itemx -M @var{n}
981Allow at most @var{n} build jobs in parallel. The default value is
f6526eb3
LC
982@code{1}. Setting it to @code{0} means that no builds will be performed
983locally; instead, the daemon will offload builds (@pxref{Daemon Offload
984Setup}), or simply fail.
bd5e766b 985
ecf84b7c
LC
986@item --rounds=@var{N}
987Build each derivation @var{n} times in a row, and raise an error if
988consecutive build results are not bit-for-bit identical. Note that this
989setting can be overridden by clients such as @command{guix build}
990(@pxref{Invoking guix build}).
991
bd5e766b
LC
992@item --debug
993Produce debugging output.
994
995This is useful to debug daemon start-up issues, but then it may be
996overridden by clients, for example the @code{--verbosity} option of
e49951eb 997@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
998
999@item --chroot-directory=@var{dir}
1000Add @var{dir} to the build chroot.
1001
1002Doing this may change the result of build processes---for instance if
1003they use optional dependencies found in @var{dir} when it is available,
1004and not otherwise. For that reason, it is not recommended to do so.
1005Instead, make sure that each derivation declares all the inputs that it
1006needs.
1007
1008@item --disable-chroot
1009Disable chroot builds.
1010
1011Using this option is not recommended since, again, it would allow build
1e2644bb
LC
1012processes to gain access to undeclared dependencies. It is necessary,
1013though, when @command{guix-daemon} is running under an unprivileged user
1014account.
bd5e766b
LC
1015
1016@item --disable-log-compression
1017Disable compression of the build logs.
1018
1da983b9
LC
1019Unless @code{--lose-logs} is used, all the build logs are kept in the
1020@var{localstatedir}. To save space, the daemon automatically compresses
1021them with bzip2 by default. This option disables that.
1022
ab3893d7
LC
1023@item --disable-deduplication
1024@cindex deduplication
bd5e766b
LC
1025Disable automatic file ``deduplication'' in the store.
1026
1da983b9 1027By default, files added to the store are automatically ``deduplicated'':
ab3893d7
LC
1028if a newly added file is identical to another one found in the store,
1029the daemon makes the new file a hard link to the other file. This can
4988dd40 1030noticeably reduce disk usage, at the expense of slightly increased
ab3893d7
LC
1031input/output load at the end of a build process. This option disables
1032this optimization.
1da983b9 1033
6e37066e
LC
1034@item --gc-keep-outputs[=yes|no]
1035Tell whether the garbage collector (GC) must keep outputs of live
1036derivations.
1037
1038When set to ``yes'', the GC will keep the outputs of any live derivation
1039available in the store---the @code{.drv} files. The default is ``no'',
1040meaning that derivation outputs are kept only if they are GC roots.
1041
1042@item --gc-keep-derivations[=yes|no]
1043Tell whether the garbage collector (GC) must keep derivations
1044corresponding to live outputs.
1045
1046When set to ``yes'', as is the case by default, the GC keeps
1047derivations---i.e., @code{.drv} files---as long as at least one of their
1048outputs is live. This allows users to keep track of the origins of
1049items in their store. Setting it to ``no'' saves a bit of disk space.
1050
1051Note that when both @code{--gc-keep-derivations} and
1052@code{--gc-keep-outputs} are used, the effect is to keep all the build
1053prerequisites (the sources, compiler, libraries, and other build-time
1054tools) of live objects in the store, regardless of whether these
1055prerequisites are live. This is convenient for developers since it
1056saves rebuilds or downloads.
1057
bd5e766b
LC
1058@item --impersonate-linux-2.6
1059On Linux-based systems, impersonate Linux 2.6. This means that the
1060kernel's @code{uname} system call will report 2.6 as the release number.
1061
1062This might be helpful to build programs that (usually wrongfully) depend
1063on the kernel version number.
1064
1065@item --lose-logs
1066Do not keep build logs. By default they are kept under
ce33631f 1067@code{@var{localstatedir}/guix/log}.
bd5e766b
LC
1068
1069@item --system=@var{system}
1070Assume @var{system} as the current system type. By default it is the
1071architecture/kernel pair found at configure time, such as
1072@code{x86_64-linux}.
b8d2aa26
LC
1073
1074@item --listen=@var{socket}
1075Listen for connections on @var{socket}, the file name of a Unix-domain
1076socket. The default socket is
1077@file{@var{localstatedir}/daemon-socket/socket}. This option is only
1078useful in exceptional circumstances, such as if you need to run several
1079daemons on the same machine.
bd5e766b
LC
1080@end table
1081
1082
0e2d0213
LC
1083@node Application Setup
1084@section Application Setup
1085
85e57214
LC
1086When using Guix on top of GNU/Linux distribution other than GuixSD---a
1087so-called @dfn{foreign distro}---a few additional steps are needed to
1088get everything in place. Here are some of them.
0e2d0213
LC
1089
1090@subsection Locales
1091
5c3c1427 1092@anchor{locales-and-locpath}
0e2d0213 1093@cindex locales, when not on GuixSD
5c3c1427 1094@vindex LOCPATH
85e57214 1095@vindex GUIX_LOCPATH
f97c9175
AE
1096Packages installed @i{via} Guix will not use the locale data of the
1097host system. Instead, you must first install one of the locale packages
85e57214
LC
1098available with Guix and then define the @code{GUIX_LOCPATH} environment
1099variable:
0e2d0213
LC
1100
1101@example
1102$ guix package -i glibc-locales
85e57214 1103$ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
0e2d0213
LC
1104@end example
1105
1106Note that the @code{glibc-locales} package contains data for all the
1107locales supported by the GNU@tie{}libc and weighs in at around
f97c9175 1108110@tie{}MiB. Alternatively, the @code{glibc-utf8-locales} is smaller but
0e2d0213
LC
1109limited to a few UTF-8 locales.
1110
85e57214
LC
1111The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1112(@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1113Manual}). There are two important differences though:
1114
1115@enumerate
1116@item
f97c9175 1117@code{GUIX_LOCPATH} is honored only by the libc in Guix, and not by the libc
85e57214 1118provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
f97c9175 1119to make sure the programs of the foreign distro will not end up loading
85e57214
LC
1120incompatible locale data.
1121
1122@item
1123libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1124@code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1125should your Guix profile contain a mixture of programs linked against
1126different libc version, each libc version will only try to load locale
1127data in the right format.
1128@end enumerate
1129
1130This is important because the locale data format used by different libc
1131versions may be incompatible.
1132
0e2d0213
LC
1133@subsection X11 Fonts
1134
4988dd40 1135The majority of graphical applications use Fontconfig to locate and
f97c9175
AE
1136load fonts and perform X11-client-side rendering. The @code{fontconfig}
1137package in Guix looks for fonts in @file{$HOME/.guix-profile}
0e2d0213 1138by default. Thus, to allow graphical applications installed with Guix
f97c9175 1139to display fonts, you have to install fonts with Guix as well.
0e2d0213 1140Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
8fe5b1d1 1141@code{font-gnu-freefont-ttf}.
0e2d0213 1142
5c36edc8
LC
1143To display text written in Chinese languages, Japanese, or Korean in
1144graphical applications, consider installing
1145@code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1146has multiple outputs, one per language family (@pxref{Packages with
1147Multiple Outputs}). For instance, the following command installs fonts
1148for Chinese languages:
1149
1150@example
1151guix package -i font-adobe-source-han-sans:cn
1152@end example
1153
6d97319c
AK
1154@subsection Emacs Packages
1155
1156When you install Emacs packages with Guix, the elisp files may be placed
1157either in @file{$HOME/.guix-profile/share/emacs/site-lisp/} or in
1158sub-directories of
1159@file{$HOME/.guix-profile/share/emacs/site-lisp/guix.d/}. The latter
1160directory exists because potentially there may exist thousands of Emacs
1161packages and storing all their files in a single directory may be not
1162reliable (because of name conflicts). So we think using a separate
1163directory for each package is a good idea. It is very similar to how
1164the Emacs package system organizes the file structure (@pxref{Package
1165Files,,, emacs, The GNU Emacs Manual}).
1166
1167By default, Emacs (installed with Guix) ``knows'' where these packages
f97c9175 1168are placed, so you do not need to perform any configuration. If, for
6d97319c 1169some reason, you want to avoid auto-loading Emacs packages installed
f97c9175 1170with Guix, you can do so by running Emacs with @code{--no-site-file}
6d97319c
AK
1171option (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
1172
0e2d0213
LC
1173@c TODO What else?
1174
eeaf4427
LC
1175@c *********************************************************************
1176@node Package Management
1177@chapter Package Management
1178
f8348b91 1179The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427 1180remove software packages, without having to know about their build
f97c9175 1181procedures or dependencies. Guix also goes beyond this obvious set of
eeaf4427
LC
1182features.
1183
1184This chapter describes the main features of Guix, as well as the package
c1941588 1185management tools it provides. Two user interfaces are provided for
c554de89
AK
1186routine package management tasks: A command-line interface described below
1187(@pxref{Invoking guix package, @code{guix package}}), as well as a visual user
1188interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}).
eeaf4427
LC
1189
1190@menu
1191* Features:: How Guix will make your life brighter.
e49951eb 1192* Invoking guix package:: Package installation, removal, etc.
c4202d60 1193* Substitutes:: Downloading pre-built binaries.
760c60d6 1194* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 1195* Invoking guix gc:: Running the garbage collector.
f651b477 1196* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 1197* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
1198@end menu
1199
1200@node Features
1201@section Features
1202
1203When using Guix, each package ends up in the @dfn{package store}, in its
1204own directory---something that resembles
9a130e19
AK
1205@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
1206(note that Guix comes with an Emacs extension to shorten those file
081145cf 1207names, @pxref{Emacs Prettify}.)
eeaf4427
LC
1208
1209Instead of referring to these directories, users have their own
1210@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
1211use. These profiles are stored within each user's home directory, at
1212@code{$HOME/.guix-profile}.
eeaf4427 1213
821b0015 1214For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 1215@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 1216@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
1217@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1218simply continues to point to
834129e0 1219@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 1220coexist on the same system without any interference.
eeaf4427 1221
e49951eb 1222The @command{guix package} command is the central tool to manage
f97c9175 1223packages (@pxref{Invoking guix package}). It operates on the per-user
821b0015 1224profiles, and can be used @emph{with normal user privileges}.
eeaf4427
LC
1225
1226The command provides the obvious install, remove, and upgrade
1227operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 1228the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 1229@command{guix package} process is terminated during the transaction,
eeaf4427
LC
1230or if a power outage occurs during the transaction, then the user's
1231profile remains in its previous state, and remains usable.
1232
1233In addition, any package transaction may be @emph{rolled back}. So, if,
1234for example, an upgrade installs a new version of a package that turns
1235out to have a serious bug, users may roll back to the previous instance
4af2447e 1236of their profile, which was known to work well. Similarly, the global
6f773606
LC
1237system configuration on GuixSD is subject to
1238transactional upgrades and roll-back
4af2447e 1239(@pxref{Using the Configuration System}).
eeaf4427 1240
f97c9175
AE
1241All packages in the package store may be @emph{garbage-collected}.
1242Guix can determine which packages are still referenced by user
fe8ff028 1243profiles, and remove those that are provably no longer referenced
e49951eb 1244(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
1245generations of their profile so that the packages they refer to can be
1246collected.
eeaf4427 1247
e900c503
LC
1248@cindex reproducibility
1249@cindex reproducible builds
eeaf4427
LC
1250Finally, Guix takes a @dfn{purely functional} approach to package
1251management, as described in the introduction (@pxref{Introduction}).
834129e0 1252Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
1253inputs that were used to build that package---compiler, libraries, build
1254scripts, etc. This direct correspondence allows users to make sure a
1255given package installation matches the current state of their
e900c503
LC
1256distribution. It also helps maximize @dfn{build reproducibility}:
1257thanks to the isolated build environments that are used, a given build
1258is likely to yield bit-identical files when performed on different
1259machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 1260
c4202d60 1261@cindex substitutes
eeaf4427 1262This foundation allows Guix to support @dfn{transparent binary/source
c4202d60 1263deployment}. When a pre-built binary for a @file{/gnu/store} item is
18f2887b 1264available from an external source---a @dfn{substitute}, Guix just
c4202d60
LC
1265downloads it and unpacks it;
1266otherwise, it builds the package from source, locally
bf9eacd2
LC
1267(@pxref{Substitutes}). Because build results are usually bit-for-bit
1268reproducible, users do not have to trust servers that provide
1269substitutes: they can force a local build and @emph{challenge} providers
1270(@pxref{Invoking guix challenge}).
eeaf4427 1271
f5fd4fd2
LC
1272Control over the build environment is a feature that is also useful for
1273developers. The @command{guix environment} command allows developers of
1274a package to quickly set up the right development environment for their
f97c9175
AE
1275package, without having to manually install the dependencies of the
1276package into their profile (@pxref{Invoking guix environment}).
f5fd4fd2 1277
e49951eb
MW
1278@node Invoking guix package
1279@section Invoking @command{guix package}
eeaf4427 1280
e49951eb 1281The @command{guix package} command is the tool that allows users to
eeaf4427
LC
1282install, upgrade, and remove packages, as well as rolling back to
1283previous configurations. It operates only on the user's own profile,
1284and works with normal user privileges (@pxref{Features}). Its syntax
1285is:
1286
1287@example
e49951eb 1288guix package @var{options}
eeaf4427
LC
1289@end example
1290
ba55b1cb 1291Primarily, @var{options} specifies the operations to be performed during
eeaf4427 1292the transaction. Upon completion, a new profile is created, but
99bd74d5 1293previous @dfn{generations} of the profile remain available, should the user
eeaf4427
LC
1294want to roll back.
1295
6447738c
MW
1296For example, to remove @code{lua} and install @code{guile} and
1297@code{guile-cairo} in a single transaction:
1298
1299@example
1300guix package -r lua -i guile guile-cairo
1301@end example
1302
99bd74d5
LC
1303@command{guix package} also supports a @dfn{declarative approach}
1304whereby the user specifies the exact set of packages to be available and
1305passes it @i{via} the @option{--manifest} option
1306(@pxref{profile-manifest, @option{--manifest}}).
1307
b9e5c0a9 1308For each user, a symlink to the user's default profile is automatically
0ec1af59 1309created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
1310current generation of the user's default profile. Thus, users can add
1311@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1312variable, and so on.
d664f1b4
LC
1313@cindex search paths
1314If you are not using the Guix System Distribution, consider adding the
1315following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1316Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1317shells get all the right environment variable definitions:
1318
1319@example
1320GUIX_PROFILE="$HOME/.guix-profile" \
1321source "$HOME/.guix-profile/etc/profile"
1322@end example
b9e5c0a9 1323
4379c35b
LC
1324In a multi-user setup, user profiles are stored in a place registered as
1325a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1326to (@pxref{Invoking guix gc}). That directory is normally
0ec1af59
LC
1327@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1328@var{localstatedir} is the value passed to @code{configure} as
4379c35b
LC
1329@code{--localstatedir}, and @var{user} is the user name. The
1330@file{per-user} directory is created when @command{guix-daemon} is
1331started, and the @var{user} sub-directory is created by @command{guix
1332package}.
0ec1af59
LC
1333
1334The @var{options} can be among the following:
1335
eeaf4427
LC
1336@table @code
1337
6447738c
MW
1338@item --install=@var{package} @dots{}
1339@itemx -i @var{package} @dots{}
1340Install the specified @var{package}s.
eeaf4427 1341
6447738c 1342Each @var{package} may specify either a simple package name, such as
1b846da8
ML
1343@code{guile}, or a package name followed by an at-sign and version number,
1344such as @code{guile@@1.8.8} or simply @code{guile@@1.8} (in the latter
724311a2
LC
1345case, the newest version prefixed by @code{1.8} is selected.)
1346
1347If no version number is specified, the
dc5669cd
MW
1348newest available version will be selected. In addition, @var{package}
1349may contain a colon, followed by the name of one of the outputs of the
1b846da8 1350package, as in @code{gcc:doc} or @code{binutils@@2.22:lib}
e7f34eb0
LC
1351(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1352name (and optionally version) are searched for among the GNU
1353distribution modules (@pxref{Package Modules}).
eeaf4427 1354
461572cc
LC
1355@cindex propagated inputs
1356Sometimes packages have @dfn{propagated inputs}: these are dependencies
21461f27
LC
1357that automatically get installed along with the required package
1358(@pxref{package-propagated-inputs, @code{propagated-inputs} in
1359@code{package} objects}, for information about propagated inputs in
1360package definitions).
461572cc 1361
21461f27 1362@anchor{package-cmd-propagated-inputs}
461572cc
LC
1363An example is the GNU MPC library: its C header files refer to those of
1364the GNU MPFR library, which in turn refer to those of the GMP library.
1365Thus, when installing MPC, the MPFR and GMP libraries also get installed
1366in the profile; removing MPC also removes MPFR and GMP---unless they had
f97c9175 1367also been explicitly installed by the user.
461572cc 1368
ba7ea5ce 1369Besides, packages sometimes rely on the definition of environment
5924080d 1370variables for their search paths (see explanation of
ba7ea5ce 1371@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
1372environment variable definitions are reported here.
1373
ef010c0f 1374@c XXX: keep me up-to-date
5924080d 1375Finally, when installing a GNU package, the tool reports the
ef010c0f
LC
1376availability of a newer upstream version. In the future, it may provide
1377the option of installing directly from the upstream version, even if
1378that version is not yet in the distribution.
1379
5d4b411f
LC
1380@item --install-from-expression=@var{exp}
1381@itemx -e @var{exp}
1382Install the package @var{exp} evaluates to.
1383
1384@var{exp} must be a Scheme expression that evaluates to a
1385@code{<package>} object. This option is notably useful to disambiguate
1386between same-named variants of a package, with expressions such as
1387@code{(@@ (gnu packages base) guile-final)}.
1388
1389Note that this option installs the first output of the specified
1390package, which may be insufficient when needing a specific output of a
1391multiple-output package.
1392
0d279400
DT
1393@item --install-from-file=@var{file}
1394@itemx -f @var{file}
1395Install the package that the code within @var{file} evaluates to.
1396
1397As an example, @var{file} might contain a definition like this
1398(@pxref{Defining Packages}):
1399
1400@example
1401@verbatiminclude package-hello.scm
1402@end example
1403
baacf042 1404Developers may find it useful to include such a @file{guix.scm} file
f97c9175 1405in the root of their project source tree that can be used to test
0d279400
DT
1406development snapshots and create reproducible development environments
1407(@pxref{Invoking guix environment}).
1408
6447738c
MW
1409@item --remove=@var{package} @dots{}
1410@itemx -r @var{package} @dots{}
1411Remove the specified @var{package}s.
eeaf4427 1412
6447738c 1413As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
1414and/or output name in addition to the package name. For instance,
1415@code{-r glibc:debug} would remove the @code{debug} output of
1416@code{glibc}.
1417
6447738c
MW
1418@item --upgrade[=@var{regexp} @dots{}]
1419@itemx -u [@var{regexp} @dots{}]
1420Upgrade all the installed packages. If one or more @var{regexp}s are
1421specified, upgrade only installed packages whose name matches a
d5f01e48 1422@var{regexp}. Also see the @code{--do-not-upgrade} option below.
eeaf4427 1423
f651b477
LC
1424Note that this upgrades package to the latest version of packages found
1425in the distribution currently installed. To update your distribution,
1426you should regularly run @command{guix pull} (@pxref{Invoking guix
1427pull}).
1428
d5f01e48
MW
1429@item --do-not-upgrade[=@var{regexp} @dots{}]
1430When used together with the @code{--upgrade} option, do @emph{not}
1431upgrade any packages whose name matches a @var{regexp}. For example, to
1432upgrade all packages in the current profile except those containing the
1433substring ``emacs'':
1434
1435@example
1436$ guix package --upgrade . --do-not-upgrade emacs
1437@end example
1438
99bd74d5 1439@item @anchor{profile-manifest}--manifest=@var{file}
1b676447 1440@itemx -m @var{file}
99bd74d5
LC
1441@cindex profile declaration
1442@cindex profile manifest
1443Create a new generation of the profile from the manifest object
1b676447
DT
1444returned by the Scheme code in @var{file}.
1445
99bd74d5
LC
1446This allows you to @emph{declare} the profile's contents rather than
1447constructing it through a sequence of @code{--install} and similar
1448commands. The advantage is that @var{file} can be put under version
1449control, copied to different machines to reproduce the same profile, and
1450so on.
1451
1452@c FIXME: Add reference to (guix profile) documentation when available.
1453@var{file} must return a @dfn{manifest} object, which is roughly a list
1454of packages:
1b676447 1455
99bd74d5 1456@findex packages->manifest
1b676447 1457@example
99bd74d5 1458(use-package-modules guile emacs)
1b676447
DT
1459
1460(packages->manifest
99bd74d5
LC
1461 (list emacs
1462 guile-2.0
1b676447 1463 ;; Use a specific package output.
99bd74d5 1464 (list guile-2.0 "debug")))
1b676447
DT
1465@end example
1466
24e262f0
LC
1467@item --roll-back
1468Roll back to the previous @dfn{generation} of the profile---i.e., undo
1469the last transaction.
1470
1471When combined with options such as @code{--install}, roll back occurs
1472before any other actions.
1473
d9307267 1474When rolling back from the first generation that actually contains
4b2bc804 1475installed packages, the profile is made to point to the @dfn{zeroth
f97c9175 1476generation}, which contains no files apart from its own metadata.
d9307267 1477
f97c9175
AE
1478After having rolled back, installing, removing, or upgrading packages
1479overwrites previous future generations. Thus, the history of the
1480generations in a profile is always linear.
82fe08ed 1481
b3bb82f1
AK
1482@item --switch-generation=@var{pattern}
1483@itemx -S @var{pattern}
1484Switch to a particular generation defined by @var{pattern}.
1485
1486@var{pattern} may be either a generation number or a number prefixed
1487with ``+'' or ``-''. The latter means: move forward/backward by a
1488specified number of generations. For example, if you want to return to
1489the latest generation after @code{--roll-back}, use
1490@code{--switch-generation=+1}.
1491
1492The difference between @code{--roll-back} and
1493@code{--switch-generation=-1} is that @code{--switch-generation} will
1494not make a zeroth generation, so if a specified generation does not
1495exist, the current generation will not be changed.
1496
dbc31ab2 1497@item --search-paths[=@var{kind}]
5924080d
LC
1498@cindex search paths
1499Report environment variable definitions, in Bash syntax, that may be
1500needed in order to use the set of installed packages. These environment
1501variables are used to specify @dfn{search paths} for files used by some
1502of the installed packages.
1503
1504For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1505environment variables to be defined so it can look for headers and
1506libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1507Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1508library are installed in the profile, then @code{--search-paths} will
1509suggest setting these variables to @code{@var{profile}/include} and
1510@code{@var{profile}/lib}, respectively.
1511
dbc31ab2
LC
1512The typical use case is to define these environment variables in the
1513shell:
1514
1515@example
1516$ eval `guix package --search-paths`
1517@end example
1518
1519@var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1520meaning that the returned environment variable definitions will either
1521be exact settings, or prefixes or suffixes of the current value of these
1522variables. When omitted, @var{kind} defaults to @code{exact}.
1523
fc2d2339
LC
1524This option can also be used to compute the @emph{combined} search paths
1525of several profiles. Consider this example:
1526
1527@example
1528$ guix package -p foo -i guile
1529$ guix package -p bar -i guile-json
1530$ guix package -p foo -p bar --search-paths
1531@end example
1532
1533The last command above reports about the @code{GUILE_LOAD_PATH}
1534variable, even though, taken individually, neither @file{foo} nor
1535@file{bar} would lead to that recommendation.
1536
1537
eeaf4427
LC
1538@item --profile=@var{profile}
1539@itemx -p @var{profile}
1540Use @var{profile} instead of the user's default profile.
1541
70915c1a 1542@item --verbose
f97c9175
AE
1543Produce verbose output. In particular, emit the build log of the
1544environment on the standard error port.
70915c1a 1545
eeaf4427
LC
1546@item --bootstrap
1547Use the bootstrap Guile to build the profile. This option is only
1548useful to distribution developers.
1549
1550@end table
1551
f97c9175 1552In addition to these actions, @command{guix package} supports the
733b4130
LC
1553following options to query the current state of a profile, or the
1554availability of packages:
eeaf4427 1555
733b4130
LC
1556@table @option
1557
acc08466
NK
1558@item --search=@var{regexp}
1559@itemx -s @var{regexp}
b110869d 1560@cindex searching for packages
5763ad92 1561List the available packages whose name, synopsis, or description matches
f97c9175 1562@var{regexp}. Print all the metadata of matching packages in
299112d3
LC
1563@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1564GNU recutils manual}).
acc08466 1565
299112d3
LC
1566This allows specific fields to be extracted using the @command{recsel}
1567command, for instance:
1568
1569@example
e49951eb 1570$ guix package -s malloc | recsel -p name,version
299112d3
LC
1571name: glibc
1572version: 2.17
1573
1574name: libgc
1575version: 7.2alpha6
1576@end example
acc08466 1577
a12d92f5
LC
1578Similarly, to show the name of all the packages available under the
1579terms of the GNU@tie{}LGPL version 3:
1580
1581@example
1582$ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1583name: elfutils
1584
1585name: gmp
1586@dots{}
1587@end example
1588
db5a9444
LC
1589It is also possible to refine search results using several @code{-s}
1590flags. For example, the following command returns a list of board
1591games:
1592
1593@example
1594$ guix package -s '\<board\>' -s game | recsel -p name
1595name: gnubg
1596@dots{}
1597@end example
1598
1599If we were to omit @code{-s game}, we would also get software packages
1600that deal with printed circuit boards; removing the angle brackets
1601around @code{board} would further add packages that have to do with
1602keyboards.
1603
b110869d
LC
1604And now for a more elaborate example. The following command searches
1605for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1606libraries, and prints the name and synopsis of the matching packages:
1607
1608@example
1609$ guix package -s crypto -s library | \
1610 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1611@end example
1612
1613@noindent
1614@xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1615information on @dfn{selection expressions} for @code{recsel -e}.
1616
2aa6efb0
CR
1617@item --show=@var{package}
1618Show details about @var{package}, taken from the list of available packages, in
1619@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1620recutils manual}).
1621
1622@example
1623$ guix package --show=python | recsel -p name,version
1624name: python
1625version: 2.7.6
1626
1627name: python
1628version: 3.3.5
1629@end example
1630
1631You may also specify the full name of a package to only get details about a
1632specific version of it:
1633@example
1634$ guix package --show=python-3.3.5 | recsel -p name,version
1635name: python
1636version: 3.3.5
1637@end example
1638
1639
1640
733b4130
LC
1641@item --list-installed[=@var{regexp}]
1642@itemx -I [@var{regexp}]
bd9bde1c
LC
1643List the currently installed packages in the specified profile, with the
1644most recently installed packages shown last. When @var{regexp} is
1645specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
1646
1647For each installed package, print the following items, separated by
1648tabs: the package name, its version string, the part of the package that
1649is installed (for instance, @code{out} for the default output,
1650@code{include} for its headers, etc.), and the path of this package in
1651the store.
1652
64fc89b6
LC
1653@item --list-available[=@var{regexp}]
1654@itemx -A [@var{regexp}]
5763ad92 1655List packages currently available in the distribution for this system
a1ba8475
LC
1656(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1657installed packages whose name matches @var{regexp}.
64fc89b6
LC
1658
1659For each package, print the following items separated by tabs: its name,
6e721c4d
LC
1660its version string, the parts of the package (@pxref{Packages with
1661Multiple Outputs}), and the source location of its definition.
64fc89b6 1662
f566d765
LC
1663@item --list-generations[=@var{pattern}]
1664@itemx -l [@var{pattern}]
1665Return a list of generations along with their creation dates; for each
1666generation, show the installed packages, with the most recently
4b2bc804
NK
1667installed packages shown last. Note that the zeroth generation is never
1668shown.
f566d765
LC
1669
1670For each installed package, print the following items, separated by
1671tabs: the name of a package, its version string, the part of the package
1672that is installed (@pxref{Packages with Multiple Outputs}), and the
1673location of this package in the store.
1674
1675When @var{pattern} is used, the command returns only matching
1676generations. Valid patterns include:
1677
1678@itemize
1679@item @emph{Integers and comma-separated integers}. Both patterns denote
1680generation numbers. For instance, @code{--list-generations=1} returns
1681the first one.
1682
1683And @code{--list-generations=1,8,2} outputs three generations in the
1684specified order. Neither spaces nor trailing commas are allowed.
1685
1686@item @emph{Ranges}. @code{--list-generations=2..9} prints the
1687specified generations and everything in between. Note that the start of
f97c9175 1688a range must be smaller than its end.
f566d765
LC
1689
1690It is also possible to omit the endpoint. For example,
1691@code{--list-generations=2..}, returns all generations starting from the
1692second one.
1693
1694@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1695or months by passing an integer along with the first letter of the
d7ddb257
LC
1696duration. For example, @code{--list-generations=20d} lists generations
1697that are up to 20 days old.
f566d765
LC
1698@end itemize
1699
b7884ca3
NK
1700@item --delete-generations[=@var{pattern}]
1701@itemx -d [@var{pattern}]
d7ddb257
LC
1702When @var{pattern} is omitted, delete all generations except the current
1703one.
b7884ca3
NK
1704
1705This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
1706When @var{pattern} is specified, delete the matching generations. When
1707@var{pattern} specifies a duration, generations @emph{older} than the
1708specified duration match. For instance, @code{--delete-generations=1m}
1709deletes generations that are more than one month old.
1710
391bdd8f
LC
1711If the current generation matches, it is @emph{not} deleted. Also, the
1712zeroth generation is never deleted.
b7884ca3 1713
f97c9175 1714Note that deleting generations prevents rolling back to them.
1bb9900a
LC
1715Consequently, this command must be used with care.
1716
733b4130 1717@end table
eeaf4427 1718
70ee5642 1719Finally, since @command{guix package} may actually start build
ccd7158d 1720processes, it supports all the common build options (@pxref{Common Build
f97c9175 1721Options}). It also supports package transformation options, such as
b8638f03
LC
1722@option{--with-source} (@pxref{Package Transformation Options}).
1723However, note that package transformations are lost when upgrading; to
f97c9175 1724preserve transformations across upgrades, you should define your own
b8638f03
LC
1725package variant in a Guile module and add it to @code{GUIX_PACKAGE_PATH}
1726(@pxref{Defining Packages}).
1727
70ee5642 1728
c4202d60
LC
1729@node Substitutes
1730@section Substitutes
1731
1732@cindex substitutes
1733@cindex pre-built binaries
1734Guix supports transparent source/binary deployment, which means that it
1735can either build things locally, or download pre-built items from a
1736server. We call these pre-built items @dfn{substitutes}---they are
1737substitutes for local build results. In many cases, downloading a
1738substitute is much faster than building things locally.
1739
1740Substitutes can be anything resulting from a derivation build
1741(@pxref{Derivations}). Of course, in the common case, they are
1742pre-built package binaries, but source tarballs, for instance, which
1743also result from derivation builds, can be available as substitutes.
1744
1745The @code{hydra.gnu.org} server is a front-end to a build farm that
1746builds packages from the GNU distribution continuously for some
32950fc8
AK
1747architectures, and makes them available as substitutes (@pxref{Emacs
1748Hydra}, for information on how to query the continuous integration
1749server). This is the
f8a8e0fe
LC
1750default source of substitutes; it can be overridden by passing the
1751@option{--substitute-urls} option either to @command{guix-daemon}
1752(@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1753or to client tools such as @command{guix package}
1754(@pxref{client-substitute-urls,, client @option{--substitute-urls}
1755option}).
c4202d60 1756
9b7bd1b1
LC
1757Substitute URLs can be either HTTP or HTTPS@footnote{For HTTPS access,
1758the Guile bindings of GnuTLS must be installed. @xref{Requirements}.}
1759HTTPS is recommended because communications are encrypted; conversely,
1760using HTTP makes all communications visible to an eavesdropper, who
1761could use the information gathered to determine, for instance, whether
1762your system has unpatched security vulnerabilities.
1763
c4202d60
LC
1764@cindex security
1765@cindex digital signatures
df061d07
LC
1766To allow Guix to download substitutes from @code{hydra.gnu.org} or a
1767mirror thereof, you
c4202d60
LC
1768must add its public key to the access control list (ACL) of archive
1769imports, using the @command{guix archive} command (@pxref{Invoking guix
1770archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1771be compromised and to serve genuine substitutes.
1772
1773This public key is installed along with Guix, in
1774@code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1775the installation prefix of Guix. If you installed Guix from source,
1776make sure you checked the GPG signature of
1777@file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1778Then, you can run something like this:
1779
1780@example
1781# guix archive --authorize < hydra.gnu.org.pub
1782@end example
1783
1784Once this is in place, the output of a command like @code{guix build}
1785should change from something like:
1786
1787@example
1788$ guix build emacs --dry-run
1789The following derivations would be built:
1790 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1791 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1792 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1793 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1794@dots{}
1795@end example
1796
1797@noindent
1798to something like:
1799
1800@example
1801$ guix build emacs --dry-run
1802The following files would be downloaded:
1803 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1804 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1805 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1806 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1807@dots{}
1808@end example
1809
1810@noindent
1811This indicates that substitutes from @code{hydra.gnu.org} are usable and
1812will be downloaded, when possible, for future builds.
1813
1814Guix ignores substitutes that are not signed, or that are not signed by
ef27aa9c 1815one of the keys listed in the ACL. It also detects and raises an error
c4202d60
LC
1816when attempting to use a substitute that has been tampered with.
1817
e0c941fe 1818@vindex http_proxy
9b7bd1b1
LC
1819Substitutes are downloaded over HTTP or HTTPS.
1820The @code{http_proxy} environment
e0c941fe
LC
1821variable can be set in the environment of @command{guix-daemon} and is
1822honored for downloads of substitutes. Note that the value of
1823@code{http_proxy} in the environment where @command{guix build},
1824@command{guix package}, and other client commands are run has
1825@emph{absolutely no effect}.
1826
9b7bd1b1
LC
1827When using HTTPS, the server's X.509 certificate is @emph{not} validated
1828(in other words, the server is not authenticated), contrary to what
1829HTTPS clients such as Web browsers usually do. This is because Guix
1830authenticates substitute information itself, as explained above, which
1831is what we care about (whereas X.509 certificates are about
1832authenticating bindings between domain names and public keys.)
1833
c4202d60
LC
1834The substitute mechanism can be disabled globally by running
1835@code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1836guix-daemon}). It can also be disabled temporarily by passing the
1837@code{--no-substitutes} option to @command{guix package}, @command{guix
1838build}, and other command-line tools.
1839
1840
9b7bd1b1
LC
1841@unnumberedsubsec On Trusting Binaries
1842
c4202d60
LC
1843Today, each individual's control over their own computing is at the
1844mercy of institutions, corporations, and groups with enough power and
1845determination to subvert the computing infrastructure and exploit its
1846weaknesses. While using @code{hydra.gnu.org} substitutes can be
1847convenient, we encourage users to also build on their own, or even run
1848their own build farm, such that @code{hydra.gnu.org} is less of an
8ce229fc
LC
1849interesting target. One way to help is by publishing the software you
1850build using @command{guix publish} so that others have one more choice
1851of server to download substitutes from (@pxref{Invoking guix publish}).
c4202d60
LC
1852
1853Guix has the foundations to maximize build reproducibility
1854(@pxref{Features}). In most cases, independent builds of a given
1855package or derivation should yield bit-identical results. Thus, through
1856a diverse set of independent package builds, we can strengthen the
d23c20f1
LC
1857integrity of our systems. The @command{guix challenge} command aims to
1858help users assess substitute servers, and to assist developers in
1859finding out about non-deterministic package builds (@pxref{Invoking guix
a8d65643
LC
1860challenge}). Similarly, the @option{--check} option of @command{guix
1861build} allows users to check whether previously-installed substitutes
1862are genuine by rebuilding them locally (@pxref{build-check,
1863@command{guix build --check}}).
c4202d60
LC
1864
1865In the future, we want Guix to have support to publish and retrieve
1866binaries to/from other users, in a peer-to-peer fashion. If you would
1867like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1868
1869
6e721c4d
LC
1870@node Packages with Multiple Outputs
1871@section Packages with Multiple Outputs
1872
1873@cindex multiple-output packages
1874@cindex package outputs
1875
1876Often, packages defined in Guix have a single @dfn{output}---i.e., the
f97c9175 1877source package leads to exactly one directory in the store. When running
6e721c4d
LC
1878@command{guix package -i glibc}, one installs the default output of the
1879GNU libc package; the default output is called @code{out}, but its name
1880can be omitted as shown in this command. In this particular case, the
1881default output of @code{glibc} contains all the C header files, shared
1882libraries, static libraries, Info documentation, and other supporting
1883files.
1884
1885Sometimes it is more appropriate to separate the various types of files
1886produced from a single source package into separate outputs. For
1887instance, the GLib C library (used by GTK+ and related packages)
1888installs more than 20 MiB of reference documentation as HTML pages.
1889To save space for users who do not need it, the documentation goes to a
1890separate output, called @code{doc}. To install the main GLib output,
1891which contains everything but the documentation, one would run:
1892
1893@example
1894guix package -i glib
1895@end example
1896
1897The command to install its documentation is:
1898
1899@example
1900guix package -i glib:doc
1901@end example
1902
1903Some packages install programs with different ``dependency footprints''.
f97c9175 1904For instance, the WordNet package installs both command-line tools and
6e721c4d
LC
1905graphical user interfaces (GUIs). The former depend solely on the C
1906library, whereas the latter depend on Tcl/Tk and the underlying X
1907libraries. In this case, we leave the command-line tools in the default
1908output, whereas the GUIs are in a separate output. This allows users
fcc58db6
LC
1909who do not need the GUIs to save space. The @command{guix size} command
1910can help find out about such situations (@pxref{Invoking guix size}).
88856916 1911@command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
6e721c4d
LC
1912
1913There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
1914Other conventional output names include @code{lib} for libraries and
1915possibly header files, @code{bin} for stand-alone programs, and
1916@code{debug} for debugging information (@pxref{Installing Debugging
1917Files}). The outputs of a packages are listed in the third column of
1918the output of @command{guix package --list-available} (@pxref{Invoking
1919guix package}).
6e721c4d 1920
eeaf4427 1921
e49951eb
MW
1922@node Invoking guix gc
1923@section Invoking @command{guix gc}
fe8ff028
LC
1924
1925@cindex garbage collector
f97c9175 1926Packages that are installed, but not used, may be @dfn{garbage-collected}.
e49951eb 1927The @command{guix gc} command allows users to explicitly run the garbage
c22eb992
LC
1928collector to reclaim space from the @file{/gnu/store} directory. It is
1929the @emph{only} way to remove files from @file{/gnu/store}---removing
1930files or directories manually may break it beyond repair!
fe8ff028
LC
1931
1932The garbage collector has a set of known @dfn{roots}: any file under
834129e0 1933@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
1934cannot be deleted; any other file is considered @dfn{dead} and may be
1935deleted. The set of garbage collector roots includes default user
e49951eb
MW
1936profiles, and may be augmented with @command{guix build --root}, for
1937example (@pxref{Invoking guix build}).
fe8ff028 1938
1bb9900a
LC
1939Prior to running @code{guix gc --collect-garbage} to make space, it is
1940often useful to remove old generations from user profiles; that way, old
1941package builds referenced by those generations can be reclaimed. This
1942is achieved by running @code{guix package --delete-generations}
1943(@pxref{Invoking guix package}).
1944
e49951eb 1945The @command{guix gc} command has three modes of operation: it can be
fe8ff028 1946used to garbage-collect any dead files (the default), to delete specific
7770aafc
LC
1947files (the @code{--delete} option), to print garbage-collector
1948information, or for more advanced queries. The garbage collection
1949options are as follows:
fe8ff028
LC
1950
1951@table @code
1952@item --collect-garbage[=@var{min}]
1953@itemx -C [@var{min}]
834129e0 1954Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
1955sub-directories. This is the default operation when no option is
1956specified.
1957
1958When @var{min} is given, stop once @var{min} bytes have been collected.
1959@var{min} may be a number of bytes, or it may include a unit as a
4a44d7bb
LC
1960suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
1961(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
fe8ff028
LC
1962
1963When @var{min} is omitted, collect all the garbage.
1964
1965@item --delete
1966@itemx -d
1967Attempt to delete all the store files and directories specified as
1968arguments. This fails if some of the files are not in the store, or if
1969they are still live.
1970
30d9aa54
LC
1971@item --list-failures
1972List store items corresponding to cached build failures.
1973
1974This prints nothing unless the daemon was started with
1975@option{--cache-failures} (@pxref{Invoking guix-daemon,
1976@option{--cache-failures}}).
1977
1978@item --clear-failures
1979Remove the specified store items from the failed-build cache.
1980
1981Again, this option only makes sense when the daemon is started with
1982@option{--cache-failures}. Otherwise, it does nothing.
1983
fe8ff028
LC
1984@item --list-dead
1985Show the list of dead files and directories still present in the
1986store---i.e., files and directories no longer reachable from any root.
1987
1988@item --list-live
1989Show the list of live store files and directories.
ba8b732d
LC
1990
1991@end table
1992
1993In addition, the references among existing store files can be queried:
1994
1995@table @code
1996
1997@item --references
1998@itemx --referrers
1999List the references (respectively, the referrers) of store files given
2000as arguments.
2001
8e59fdd5
LC
2002@item --requisites
2003@itemx -R
fcc58db6 2004@cindex closure
8e59fdd5
LC
2005List the requisites of the store files passed as arguments. Requisites
2006include the store files themselves, their references, and the references
2007of these, recursively. In other words, the returned list is the
2008@dfn{transitive closure} of the store files.
2009
f97c9175
AE
2010@xref{Invoking guix size}, for a tool to profile the size of the closure
2011of an element. @xref{Invoking guix graph}, for a tool to visualize
88856916 2012the graph of references.
fcc58db6 2013
fe8ff028
LC
2014@end table
2015
7770aafc
LC
2016Lastly, the following options allow you to check the integrity of the
2017store and to control disk usage.
2018
2019@table @option
2020
2021@item --verify[=@var{options}]
2022@cindex integrity, of the store
2023@cindex integrity checking
2024Verify the integrity of the store.
2025
2026By default, make sure that all the store items marked as valid in the
f97c9175 2027database of the daemon actually exist in @file{/gnu/store}.
7770aafc 2028
f97c9175 2029When provided, @var{options} must be a comma-separated list containing one
7770aafc
LC
2030or more of @code{contents} and @code{repair}.
2031
f97c9175
AE
2032When passing @option{--verify=contents}, the daemon computse the
2033content hash of each store item and compares it against its hash in the
7770aafc
LC
2034database. Hash mismatches are reported as data corruptions. Because it
2035traverses @emph{all the files in the store}, this command can take a
2036long time, especially on systems with a slow disk drive.
2037
2038@cindex repairing the store
2039Using @option{--verify=repair} or @option{--verify=contents,repair}
2040causes the daemon to try to repair corrupt store items by fetching
2041substitutes for them (@pxref{Substitutes}). Because repairing is not
2042atomic, and thus potentially dangerous, it is available only to the
2043system administrator.
2044
2045@item --optimize
2046@cindex deduplication
2047Optimize the store by hard-linking identical files---this is
2048@dfn{deduplication}.
2049
2050The daemon performs deduplication after each successful build or archive
2051import, unless it was started with @code{--disable-deduplication}
2052(@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
2053this option is primarily useful when the daemon was running with
2054@code{--disable-deduplication}.
2055
2056@end table
eeaf4427 2057
f651b477
LC
2058@node Invoking guix pull
2059@section Invoking @command{guix pull}
2060
2061Packages are installed or upgraded to the latest version available in
2062the distribution currently available on your local machine. To update
2063that distribution, along with the Guix tools, you must run @command{guix
2064pull}: the command downloads the latest Guix source code and package
2065descriptions, and deploys it.
2066
2067On completion, @command{guix package} will use packages and package
2068versions from this just-retrieved copy of Guix. Not only that, but all
2069the Guix commands and Scheme modules will also be taken from that latest
2070version. New @command{guix} sub-commands added by the update also
cb05108a
LC
2071become available.
2072
2073Any user can update their Guix copy using @command{guix pull}, and the
2074effect is limited to the user who run @command{guix pull}. For
2075instance, when user @code{root} runs @command{guix pull}, this has no
2076effect on the version of Guix that user @code{alice} sees, and vice
2077versa@footnote{Under the hood, @command{guix pull} updates the
2078@file{~/.config/guix/latest} symbolic link to point to the latest Guix,
2079and the @command{guix} command loads code from there.}.
f651b477
LC
2080
2081The @command{guix pull} command is usually invoked with no arguments,
2082but it supports the following options:
2083
2084@table @code
2085@item --verbose
2086Produce verbose output, writing build logs to the standard error output.
2087
ab5d72ad
LC
2088@item --url=@var{url}
2089Download the source tarball of Guix from @var{url}.
2090
2091By default, the tarball is taken from its canonical address at
2092@code{gnu.org}, for the stable branch of Guix.
2093
f651b477
LC
2094@item --bootstrap
2095Use the bootstrap Guile to build the latest Guix. This option is only
2096useful to Guix developers.
2097@end table
2098
760c60d6
LC
2099
2100@node Invoking guix archive
2101@section Invoking @command{guix archive}
2102
2103The @command{guix archive} command allows users to @dfn{export} files
2104from the store into a single archive, and to later @dfn{import} them.
2105In particular, it allows store files to be transferred from one machine
4d4c4816
AE
2106to the store on another machine.
2107
2108To export store files as an archive to standard output, run:
2109
2110@example
2111guix archive --export @var{options} @var{specifications}...
2112@end example
2113
2114@var{specifications} may be either store file names or package
2115specifications, as for @command{guix package} (@pxref{Invoking guix
2116package}). For instance, the following command creates an archive
2117containing the @code{gui} output of the @code{git} package and the main
2118output of @code{emacs}:
2119
2120@example
2121guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
2122@end example
2123
2124If the specified packages are not built yet, @command{guix archive}
2125automatically builds them. The build process may be controlled with the
2126common build options (@pxref{Common Build Options}).
2127
2128To transfer the @code{emacs} package to a machine connected over SSH,
2129one would run:
760c60d6
LC
2130
2131@example
56607088 2132guix archive --export -r emacs | ssh the-machine guix archive --import
760c60d6
LC
2133@end example
2134
87236aed 2135@noindent
56607088
LC
2136Similarly, a complete user profile may be transferred from one machine
2137to another like this:
2138
2139@example
2140guix archive --export -r $(readlink -f ~/.guix-profile) | \
2141 ssh the-machine guix-archive --import
2142@end example
2143
2144@noindent
2145However, note that, in both examples, all of @code{emacs} and the
2146profile as well as all of their dependencies are transferred (due to
f97c9175
AE
2147@code{-r}), regardless of what is already available in the store on the
2148target machine. The @code{--missing} option can help figure out which
2149items are missing from the target store.
87236aed 2150
760c60d6 2151Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
0dbd88db
LC
2152comparable in spirit to `tar', but with a few noteworthy differences
2153that make it more appropriate for our purposes. First, rather than
f97c9175 2154recording all Unix metadata for each file, the Nar format only mentions
0dbd88db
LC
2155the file type (regular, directory, or symbolic link); Unix permissions
2156and owner/group are dismissed. Second, the order in which directory
2157entries are stored always follows the order of file names according to
2158the C locale collation order. This makes archive production fully
2159deterministic.
2160
2161When exporting, the daemon digitally signs the contents of the archive,
2162and that digital signature is appended. When importing, the daemon
2163verifies the signature and rejects the import in case of an invalid
2164signature or if the signing key is not authorized.
760c60d6
LC
2165@c FIXME: Add xref to daemon doc about signatures.
2166
2167The main options are:
2168
2169@table @code
2170@item --export
2171Export the specified store files or packages (see below.) Write the
2172resulting archive to the standard output.
2173
56607088
LC
2174Dependencies are @emph{not} included in the output, unless
2175@code{--recursive} is passed.
2176
2177@item -r
2178@itemx --recursive
2179When combined with @code{--export}, this instructs @command{guix
2180archive} to include dependencies of the given items in the archive.
2181Thus, the resulting archive is self-contained: it contains the closure
2182of the exported store items.
2183
760c60d6
LC
2184@item --import
2185Read an archive from the standard input, and import the files listed
2186therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
2187signature, or if it is signed by a public key not among the authorized
2188keys (see @code{--authorize} below.)
554f26ec 2189
87236aed
LC
2190@item --missing
2191Read a list of store file names from the standard input, one per line,
2192and write on the standard output the subset of these files missing from
2193the store.
2194
554f26ec 2195@item --generate-key[=@var{parameters}]
f82cc5fd 2196@cindex signing, archives
f97c9175 2197Generate a new key pair for the daemon. This is a prerequisite before
554f26ec
LC
2198archives can be exported with @code{--export}. Note that this operation
2199usually takes time, because it needs to gather enough entropy to
2200generate the key pair.
2201
2202The generated key pair is typically stored under @file{/etc/guix}, in
2203@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
867d8473
LC
2204key, which must be kept secret.) When @var{parameters} is omitted,
2205an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2206versions before 1.6.0, it is a 4096-bit RSA key.
f97c9175 2207Alternatively, @var{parameters} can specify
554f26ec
LC
2208@code{genkey} parameters suitable for Libgcrypt (@pxref{General
2209public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2210Libgcrypt Reference Manual}).
f82cc5fd
LC
2211
2212@item --authorize
2213@cindex authorizing, archives
2214Authorize imports signed by the public key passed on standard input.
2215The public key must be in ``s-expression advanced format''---i.e., the
2216same format as the @file{signing-key.pub} file.
2217
2218The list of authorized keys is kept in the human-editable file
2219@file{/etc/guix/acl}. The file contains
2220@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2221s-expressions''} and is structured as an access-control list in the
2222@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2223(SPKI)}.
c6f8e9dd
LC
2224
2225@item --extract=@var{directory}
2226@itemx -x @var{directory}
2227Read a single-item archive as served by substitute servers
2228(@pxref{Substitutes}) and extract it to @var{directory}. This is a
2229low-level operation needed in only very narrow use cases; see below.
2230
2231For example, the following command extracts the substitute for Emacs
2232served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2233
2234@example
2235$ wget -O - \
df061d07 2236 https://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
c6f8e9dd
LC
2237 | bunzip2 | guix archive -x /tmp/emacs
2238@end example
2239
2240Single-item archives are different from multiple-item archives produced
2241by @command{guix archive --export}; they contain a single store item,
2242and they do @emph{not} embed a signature. Thus this operation does
2243@emph{no} signature verification and its output should be considered
2244unsafe.
2245
2246The primary purpose of this operation is to facilitate inspection of
2247archive contents coming from possibly untrusted substitute servers.
2248
760c60d6
LC
2249@end table
2250
c554de89
AK
2251@c *********************************************************************
2252@include emacs.texi
760c60d6 2253
568717fd
LC
2254@c *********************************************************************
2255@node Programming Interface
2256@chapter Programming Interface
2257
3dc1970d
LC
2258GNU Guix provides several Scheme programming interfaces (APIs) to
2259define, build, and query packages. The first interface allows users to
2260write high-level package definitions. These definitions refer to
2261familiar packaging concepts, such as the name and version of a package,
2262its build system, and its dependencies. These definitions can then be
2263turned into concrete build actions.
2264
ba55b1cb 2265Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 2266standard setup, the daemon has write access to the store---the
834129e0 2267@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
2268setup also has the daemon perform builds in chroots, under a specific
2269build users, to minimize interference with the rest of the system.
2270
2271@cindex derivation
2272Lower-level APIs are available to interact with the daemon and the
2273store. To instruct the daemon to perform a build action, users actually
2274provide it with a @dfn{derivation}. A derivation is a low-level
2275representation of the build actions to be taken, and the environment in
2276which they should occur---derivations are to package definitions what
49ad317a
LC
2277assembly is to C programs. The term ``derivation'' comes from the fact
2278that build results @emph{derive} from them.
3dc1970d
LC
2279
2280This chapter describes all these APIs in turn, starting from high-level
2281package definitions.
2282
568717fd 2283@menu
b860f382 2284* Defining Packages:: Defining new packages.
7458bd0a 2285* Build Systems:: Specifying how packages are built.
b860f382
LC
2286* The Store:: Manipulating the package store.
2287* Derivations:: Low-level interface to package derivations.
2288* The Store Monad:: Purely functional interface to the store.
21b679f6 2289* G-Expressions:: Manipulating build expressions.
568717fd
LC
2290@end menu
2291
2292@node Defining Packages
2293@section Defining Packages
2294
3dc1970d
LC
2295The high-level interface to package definitions is implemented in the
2296@code{(guix packages)} and @code{(guix build-system)} modules. As an
2297example, the package definition, or @dfn{recipe}, for the GNU Hello
2298package looks like this:
2299
2300@example
e7f34eb0
LC
2301(define-module (gnu packages hello)
2302 #:use-module (guix packages)
2303 #:use-module (guix download)
2304 #:use-module (guix build-system gnu)
a6dcdcac
SB
2305 #:use-module (guix licenses)
2306 #:use-module (gnu packages gawk))
b22a12fd 2307
79f5dd59 2308(define-public hello
3dc1970d
LC
2309 (package
2310 (name "hello")
17d8e33f 2311 (version "2.10")
3dc1970d 2312 (source (origin
17d8e33f
ML
2313 (method url-fetch)
2314 (uri (string-append "mirror://gnu/hello/hello-" version
2315 ".tar.gz"))
2316 (sha256
2317 (base32
2318 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
3dc1970d 2319 (build-system gnu-build-system)
7458bd0a 2320 (arguments `(#:configure-flags '("--enable-silent-rules")))
3dc1970d 2321 (inputs `(("gawk" ,gawk)))
7458bd0a
LC
2322 (synopsis "Hello, GNU world: An example GNU package")
2323 (description "Guess what GNU Hello prints!")
3dc1970d 2324 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 2325 (license gpl3+)))
3dc1970d
LC
2326@end example
2327
2328@noindent
2329Without being a Scheme expert, the reader may have guessed the meaning
f97c9175
AE
2330of the various fields here. This expression binds the variable
2331@code{hello} to a @code{<package>} object, which is essentially a record
3dc1970d
LC
2332(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2333This package object can be inspected using procedures found in the
2334@code{(guix packages)} module; for instance, @code{(package-name hello)}
2335returns---surprise!---@code{"hello"}.
2336
2f7d2d91
LC
2337With luck, you may be able to import part or all of the definition of
2338the package you are interested in from another repository, using the
2339@code{guix import} command (@pxref{Invoking guix import}).
2340
f97c9175 2341In the example above, @var{hello} is defined in a module of its own,
e7f34eb0
LC
2342@code{(gnu packages hello)}. Technically, this is not strictly
2343necessary, but it is convenient to do so: all the packages defined in
2344modules under @code{(gnu packages @dots{})} are automatically known to
2345the command-line tools (@pxref{Package Modules}).
2346
3dc1970d
LC
2347There are a few points worth noting in the above package definition:
2348
2349@itemize
2350@item
a2bf4907
LC
2351The @code{source} field of the package is an @code{<origin>} object
2352(@pxref{origin Reference}, for the complete reference).
3dc1970d
LC
2353Here, the @code{url-fetch} method from @code{(guix download)} is used,
2354meaning that the source is a file to be downloaded over FTP or HTTP.
2355
2356The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2357the GNU mirrors defined in @code{(guix download)}.
2358
2359The @code{sha256} field specifies the expected SHA256 hash of the file
2360being downloaded. It is mandatory, and allows Guix to check the
2361integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 2362base32 representation of the hash. You can obtain this information with
210cc920
LC
2363@code{guix download} (@pxref{Invoking guix download}) and @code{guix
2364hash} (@pxref{Invoking guix hash}).
3dc1970d 2365
f9cc8971
LC
2366@cindex patches
2367When needed, the @code{origin} form can also have a @code{patches} field
2368listing patches to be applied, and a @code{snippet} field giving a
2369Scheme expression to modify the source code.
2370
3dc1970d
LC
2371@item
2372@cindex GNU Build System
7458bd0a
LC
2373The @code{build-system} field specifies the procedure to build the
2374package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2375represents the familiar GNU Build System, where packages may be
2376configured, built, and installed with the usual @code{./configure &&
2377make && make check && make install} command sequence.
2378
2379@item
2380The @code{arguments} field specifies options for the build system
2381(@pxref{Build Systems}). Here it is interpreted by
2382@var{gnu-build-system} as a request run @file{configure} with the
2383@code{--enable-silent-rules} flag.
3dc1970d
LC
2384
2385@item
2386The @code{inputs} field specifies inputs to the build process---i.e.,
2387build-time or run-time dependencies of the package. Here, we define an
2388input called @code{"gawk"} whose value is that of the @var{gawk}
2389variable; @var{gawk} is itself bound to a @code{<package>} object.
2390
2391Note that GCC, Coreutils, Bash, and other essential tools do not need to
2392be specified as inputs here. Instead, @var{gnu-build-system} takes care
7458bd0a 2393of ensuring that they are present (@pxref{Build Systems}).
3dc1970d
LC
2394
2395However, any other dependencies need to be specified in the
2396@code{inputs} field. Any dependency not specified here will simply be
2397unavailable to the build process, possibly leading to a build failure.
2398@end itemize
2399
87eafdbd
TUBK
2400@xref{package Reference}, for a full description of possible fields.
2401
2f7d2d91 2402Once a package definition is in place, the
e49951eb 2403package may actually be built using the @code{guix build} command-line
39bee8a2
LC
2404tool (@pxref{Invoking guix build}). You can easily jump back to the
2405package definition using the @command{guix edit} command
2406(@pxref{Invoking guix edit}).
2407@xref{Packaging Guidelines}, for
b4f5e0e8
CR
2408more information on how to test package definitions, and
2409@ref{Invoking guix lint}, for information on how to check a definition
2410for style conformance.
2411
f97c9175 2412Finally, updating the package definition to a new upstream version
7458bd0a
LC
2413can be partly automated by the @command{guix refresh} command
2414(@pxref{Invoking guix refresh}).
3dc1970d
LC
2415
2416Behind the scenes, a derivation corresponding to the @code{<package>}
2417object is first computed by the @code{package-derivation} procedure.
834129e0 2418That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 2419The build actions it prescribes may then be realized by using the
3dc1970d
LC
2420@code{build-derivations} procedure (@pxref{The Store}).
2421
2422@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
2423Return the @code{<derivation>} object of @var{package} for @var{system}
2424(@pxref{Derivations}).
3dc1970d
LC
2425
2426@var{package} must be a valid @code{<package>} object, and @var{system}
2427must be a string denoting the target system type---e.g.,
2428@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2429must be a connection to the daemon, which operates on the store
2430(@pxref{The Store}).
2431@end deffn
568717fd 2432
9c1edabd
LC
2433@noindent
2434@cindex cross-compilation
2435Similarly, it is possible to compute a derivation that cross-builds a
2436package for some other system:
2437
2438@deffn {Scheme Procedure} package-cross-derivation @var{store} @
2439 @var{package} @var{target} [@var{system}]
59688fc4
LC
2440Return the @code{<derivation>} object of @var{package} cross-built from
2441@var{system} to @var{target}.
9c1edabd
LC
2442
2443@var{target} must be a valid GNU triplet denoting the target hardware
2444and operating system, such as @code{"mips64el-linux-gnu"}
2445(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2446Configure and Build System}).
2447@end deffn
2448
87eafdbd
TUBK
2449@menu
2450* package Reference :: The package data type.
2451* origin Reference:: The origin data type.
2452@end menu
2453
2454
2455@node package Reference
2456@subsection @code{package} Reference
2457
2458This section summarizes all the options available in @code{package}
2459declarations (@pxref{Defining Packages}).
2460
2461@deftp {Data Type} package
2462This is the data type representing a package recipe.
2463
2464@table @asis
2465@item @code{name}
2466The name of the package, as a string.
2467
2468@item @code{version}
2469The version of the package, as a string.
2470
2471@item @code{source}
2472An origin object telling how the source code for the package should be
2473acquired (@pxref{origin Reference}).
2474
2475@item @code{build-system}
2476The build system that should be used to build the package (@pxref{Build
2477Systems}).
2478
2479@item @code{arguments} (default: @code{'()})
2480The arguments that should be passed to the build system. This is a
2481list, typically containing sequential keyword-value pairs.
2482
2483@item @code{inputs} (default: @code{'()})
70650c68
LC
2484@itemx @code{native-inputs} (default: @code{'()})
2485@itemx @code{propagated-inputs} (default: @code{'()})
2486@cindex inputs, of packages
2487These fields list dependencies of the package. Each one is a list of
2488tuples, where each tuple has a label for the input (a string) as its
2489first element, a package, origin, or derivation as its second element,
2490and optionally the name of the output thereof that should be used, which
2491defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
f97c9175 2492more on package outputs). For example, the list below specifies three
70650c68 2493inputs:
87eafdbd 2494
70650c68
LC
2495@example
2496`(("libffi" ,libffi)
2497 ("libunistring" ,libunistring)
2498 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
2499@end example
2500
2501@cindex cross compilation, package dependencies
2502The distinction between @code{native-inputs} and @code{inputs} is
2503necessary when considering cross-compilation. When cross-compiling,
2504dependencies listed in @code{inputs} are built for the @emph{target}
2505architecture; conversely, dependencies listed in @code{native-inputs}
2506are built for the architecture of the @emph{build} machine.
2507
f97c9175
AE
2508@code{native-inputs} is typically used to list tools needed at
2509build time, but not at run time, such as Autoconf, Automake, pkg-config,
70650c68
LC
2510Gettext, or Bison. @command{guix lint} can report likely mistakes in
2511this area (@pxref{Invoking guix lint}).
2512
2513@anchor{package-propagated-inputs}
2514Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
f97c9175
AE
2515specified packages will be automatically installed alongside the package
2516they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
70650c68
LC
2517package}}, for information on how @command{guix package} deals with
2518propagated inputs.)
21461f27 2519
e0508b6b
LC
2520For example this is necessary when a C/C++ library needs headers of
2521another library to compile, or when a pkg-config file refers to another
2522one @i{via} its @code{Requires} field.
2523
f97c9175
AE
2524Another example where @code{propagated-inputs} is useful is for languages
2525that lack a facility to record the run-time search path akin to the
2526@code{RUNPATH}of ELF files; this includes Guile, Python, Perl, GHC, and
e0508b6b
LC
2527more. To ensure that libraries written in those languages can find
2528library code they depend on at run time, run-time dependencies must be
2529listed in @code{propagated-inputs} rather than @code{inputs}.
87eafdbd 2530
87eafdbd
TUBK
2531@item @code{self-native-input?} (default: @code{#f})
2532This is a Boolean field telling whether the package should use itself as
2533a native input when cross-compiling.
2534
2535@item @code{outputs} (default: @code{'("out")})
2536The list of output names of the package. @xref{Packages with Multiple
2537Outputs}, for typical uses of additional outputs.
2538
2539@item @code{native-search-paths} (default: @code{'()})
2540@itemx @code{search-paths} (default: @code{'()})
2541A list of @code{search-path-specification} objects describing
2542search-path environment variables honored by the package.
2543
2544@item @code{replacement} (default: @code{#f})
f97c9175 2545This must be either @code{#f} or a package object that will be used as a
87eafdbd
TUBK
2546@dfn{replacement} for this package. @xref{Security Updates, grafts},
2547for details.
2548
2549@item @code{synopsis}
2550A one-line description of the package.
2551
2552@item @code{description}
2553A more elaborate description of the package.
2554
2555@item @code{license}
f97c9175
AE
2556The license of the package; a value from @code{(guix licenses)},
2557or a list of such values.
87eafdbd
TUBK
2558
2559@item @code{home-page}
2560The URL to the home-page of the package, as a string.
2561
2562@item @code{supported-systems} (default: @var{%supported-systems})
2563The list of systems supported by the package, as strings of the form
2564@code{architecture-kernel}, for example @code{"x86_64-linux"}.
2565
2566@item @code{maintainers} (default: @code{'()})
2567The list of maintainers of the package, as @code{maintainer} objects.
2568
2569@item @code{location} (default: source location of the @code{package} form)
f97c9175 2570The source location of the package. It is useful to override this when
87eafdbd
TUBK
2571inheriting from another package, in which case this field is not
2572automatically corrected.
2573@end table
2574@end deftp
2575
2576
2577@node origin Reference
2578@subsection @code{origin} Reference
2579
2580This section summarizes all the options available in @code{origin}
2581declarations (@pxref{Defining Packages}).
2582
2583@deftp {Data Type} origin
2584This is the data type representing a source code origin.
2585
2586@table @asis
2587@item @code{uri}
2588An object containing the URI of the source. The object type depends on
2589the @code{method} (see below). For example, when using the
2590@var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2591values are: a URL represented as a string, or a list thereof.
2592
2593@item @code{method}
f97c9175 2594A procedure that handles the URI.
87eafdbd
TUBK
2595
2596Examples include:
2597
2598@table @asis
2599@item @var{url-fetch} from @code{(guix download)}
f97c9175 2600download a file from the HTTP, HTTPS, or FTP URL specified in the
87eafdbd
TUBK
2601@code{uri} field;
2602
2603@item @var{git-fetch} from @code{(guix git-download)}
2604clone the Git version control repository, and check out the revision
2605specified in the @code{uri} field as a @code{git-reference} object; a
2606@code{git-reference} looks like this:
2607
2608@example
2609(git-reference
2610 (url "git://git.debian.org/git/pkg-shadow/shadow")
2611 (commit "v4.1.5.1"))
2612@end example
2613@end table
2614
2615@item @code{sha256}
2616A bytevector containing the SHA-256 hash of the source. Typically the
2617@code{base32} form is used here to generate the bytevector from a
2618base-32 string.
2619
2620@item @code{file-name} (default: @code{#f})
2621The file name under which the source code should be saved. When this is
2622@code{#f}, a sensible default value will be used in most cases. In case
2623the source is fetched from a URL, the file name from the URL will be
f97c9175 2624used. For version control checkouts, it is recommended to provide the
87eafdbd
TUBK
2625file name explicitly because the default is not very descriptive.
2626
2627@item @code{patches} (default: @code{'()})
2628A list of file names containing patches to be applied to the source.
2629
2630@item @code{snippet} (default: @code{#f})
2631A quoted piece of code that will be run in the source directory to make
2632any modifications, which is sometimes more convenient than a patch.
2633
2634@item @code{patch-flags} (default: @code{'("-p1")})
2635A list of command-line flags that should be passed to the @code{patch}
2636command.
2637
2638@item @code{patch-inputs} (default: @code{#f})
2639Input packages or derivations to the patching process. When this is
2640@code{#f}, the usual set of inputs necessary for patching are provided,
2641such as GNU@tie{}Patch.
2642
2643@item @code{modules} (default: @code{'()})
2644A list of Guile modules that should be loaded during the patching
2645process and while running the code in the @code{snippet} field.
2646
2647@item @code{imported-modules} (default: @code{'()})
2648The list of Guile modules to import in the patch derivation, for use by
2649the @code{snippet}.
2650
2651@item @code{patch-guile} (default: @code{#f})
2652The Guile package that should be used in the patching process. When
2653this is @code{#f}, a sensible default is used.
2654@end table
2655@end deftp
2656
9c1edabd 2657
7458bd0a
LC
2658@node Build Systems
2659@section Build Systems
2660
2661@cindex build system
2662Each package definition specifies a @dfn{build system} and arguments for
2663that build system (@pxref{Defining Packages}). This @code{build-system}
f97c9175 2664field represents the build procedure of the package, as well as implicit
7458bd0a
LC
2665dependencies of that build procedure.
2666
2667Build systems are @code{<build-system>} objects. The interface to
2668create and manipulate them is provided by the @code{(guix build-system)}
2669module, and actual build systems are exported by specific modules.
2670
f5fd4fd2 2671@cindex bag (low-level package representation)
0d5a559f
LC
2672Under the hood, build systems first compile package objects to
2673@dfn{bags}. A @dfn{bag} is like a package, but with less
2674ornamentation---in other words, a bag is a lower-level representation of
2675a package, which includes all the inputs of that package, including some
2676that were implicitly added by the build system. This intermediate
2677representation is then compiled to a derivation (@pxref{Derivations}).
2678
7458bd0a
LC
2679Build systems accept an optional list of @dfn{arguments}. In package
2680definitions, these are passed @i{via} the @code{arguments} field
2681(@pxref{Defining Packages}). They are typically keyword arguments
2682(@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
2683Guile Reference Manual}). The value of these arguments is usually
2684evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
2685by the daemon (@pxref{Derivations}).
2686
2687The main build system is @var{gnu-build-system}, which implements the
f97c9175 2688standard build procedure for GNU and many other packages. It
7458bd0a
LC
2689is provided by the @code{(guix build-system gnu)} module.
2690
2691@defvr {Scheme Variable} gnu-build-system
2692@var{gnu-build-system} represents the GNU Build System, and variants
2693thereof (@pxref{Configuration, configuration and makefile conventions,,
2694standards, GNU Coding Standards}).
2695
2696@cindex build phases
f97c9175 2697In a nutshell, packages using it are configured, built, and installed with
7458bd0a
LC
2698the usual @code{./configure && make && make check && make install}
2699command sequence. In practice, a few additional steps are often needed.
2700All these steps are split up in separate @dfn{phases},
2701notably@footnote{Please see the @code{(guix build gnu-build-system)}
2702modules for more details about the build phases.}:
2703
2704@table @code
2705@item unpack
2706Unpack the source tarball, and change the current directory to the
2707extracted source tree. If the source is actually a directory, copy it
2708to the build tree, and enter that directory.
2709
2710@item patch-source-shebangs
2711Patch shebangs encountered in source files so they refer to the right
2712store file names. For instance, this changes @code{#!/bin/sh} to
2713@code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
2714
2715@item configure
2716Run the @file{configure} script with a number of default options, such
2717as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
2718by the @code{#:configure-flags} argument.
2719
2720@item build
2721Run @code{make} with the list of flags specified with
0917e80e 2722@code{#:make-flags}. If the @code{#:parallel-build?} argument is true
7458bd0a
LC
2723(the default), build with @code{make -j}.
2724
2725@item check
2726Run @code{make check}, or some other target specified with
2727@code{#:test-target}, unless @code{#:tests? #f} is passed. If the
2728@code{#:parallel-tests?} argument is true (the default), run @code{make
2729check -j}.
2730
2731@item install
2732Run @code{make install} with the flags listed in @code{#:make-flags}.
2733
2734@item patch-shebangs
2735Patch shebangs on the installed executable files.
2736
2737@item strip
2738Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
2739is false), copying them to the @code{debug} output when available
2740(@pxref{Installing Debugging Files}).
2741@end table
2742
2743@vindex %standard-phases
2744The build-side module @code{(guix build gnu-build-system)} defines
2745@var{%standard-phases} as the default list of build phases.
2746@var{%standard-phases} is a list of symbol/procedure pairs, where the
2747procedure implements the actual phase.
2748
2749The list of phases used for a particular package can be changed with the
2750@code{#:phases} parameter. For instance, passing:
2751
2752@example
c2c5dc79 2753#:phases (modify-phases %standard-phases (delete 'configure))
7458bd0a
LC
2754@end example
2755
9bf404e9 2756means that all the phases described above will be used, except the
7458bd0a
LC
2757@code{configure} phase.
2758
2759In addition, this build system ensures that the ``standard'' environment
2760for GNU packages is available. This includes tools such as GCC, libc,
2761Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
f97c9175
AE
2762build-system gnu)} module for a complete list). We call these the
2763@dfn{implicit inputs} of a package, because package definitions do not
7458bd0a
LC
2764have to mention them.
2765@end defvr
2766
2767Other @code{<build-system>} objects are defined to support other
2768conventions and tools used by free software packages. They inherit most
2769of @var{gnu-build-system}, and differ mainly in the set of inputs
2770implicitly added to the build process, and in the list of phases
2771executed. Some of these build systems are listed below.
2772
5f7a1a4d
RW
2773@defvr {Scheme Variable} ant-build-system
2774This variable is exported by @code{(guix build-system ant)}. It
2775implements the build procedure for Java packages that can be built with
2776@url{http://ant.apache.org/, Ant build tool}.
2777
2778It adds both @code{ant} and the @dfn{Java Development Kit} (JDK) as
2779provided by the @code{icedtea} package to the set of inputs. Different
2780packages can be specified with the @code{#:ant} and @code{#:jdk}
2781parameters, respectively.
2782
2783When the original package does not provide a suitable Ant build file,
2784the parameter @code{#:jar-name} can be used to generate a minimal Ant
2785build file @file{build.xml} with tasks to build the specified jar
2786archive.
2787
2788The parameter @code{#:build-target} can be used to specify the Ant task
2789that should be run during the @code{build} phase. By default the
2790``jar'' task will be run.
2791
2792@end defvr
2793
7458bd0a
LC
2794@defvr {Scheme Variable} cmake-build-system
2795This variable is exported by @code{(guix build-system cmake)}. It
2796implements the build procedure for packages using the
2797@url{http://www.cmake.org, CMake build tool}.
2798
2799It automatically adds the @code{cmake} package to the set of inputs.
2800Which package is used can be specified with the @code{#:cmake}
2801parameter.
9849cfc1
LC
2802
2803The @code{#:configure-flags} parameter is taken as a list of flags
2804passed to the @command{cmake} command. The @code{#:build-type}
2805parameter specifies in abstract terms the flags passed to the compiler;
2806it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
2807debugging information''), which roughly means that code is compiled with
2808@code{-O2 -g}, as is the case for Autoconf-based packages by default.
7458bd0a
LC
2809@end defvr
2810
3afcf52b
FB
2811@defvr {Scheme Variable} glib-or-gtk-build-system
2812This variable is exported by @code{(guix build-system glib-or-gtk)}. It
2813is intended for use with packages making use of GLib or GTK+.
2814
2815This build system adds the following two phases to the ones defined by
2816@var{gnu-build-system}:
2817
2818@table @code
2819@item glib-or-gtk-wrap
f97c9175
AE
2820The phase @code{glib-or-gtk-wrap} ensures that programs in
2821@file{bin/} are able to find GLib ``schemas'' and
3afcf52b
FB
2822@uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
2823modules}. This is achieved by wrapping the programs in launch scripts
2824that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
2825environment variables.
2826
73aa8ddb
LC
2827It is possible to exclude specific package outputs from that wrapping
2828process by listing their names in the
2829@code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
2830when an output is known not to contain any GLib or GTK+ binaries, and
2831where wrapping would gratuitously add a dependency of that output on
2832GLib and GTK+.
2833
3afcf52b 2834@item glib-or-gtk-compile-schemas
f97c9175 2835The phase @code{glib-or-gtk-compile-schemas} makes sure that all
3afcf52b 2836@uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
f97c9175 2837GSettings schemas} of GLib are compiled. Compilation is performed by the
3afcf52b
FB
2838@command{glib-compile-schemas} program. It is provided by the package
2839@code{glib:bin} which is automatically imported by the build system.
2840The @code{glib} package providing @command{glib-compile-schemas} can be
2841specified with the @code{#:glib} parameter.
2842@end table
2843
2844Both phases are executed after the @code{install} phase.
2845@end defvr
2846
7458bd0a
LC
2847@defvr {Scheme Variable} python-build-system
2848This variable is exported by @code{(guix build-system python)}. It
2849implements the more or less standard build procedure used by Python
2850packages, which consists in running @code{python setup.py build} and
2851then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
2852
2853For packages that install stand-alone Python programs under @code{bin/},
f97c9175 2854it takes care of wrapping these programs so that their @code{PYTHONPATH}
7458bd0a
LC
2855environment variable points to all the Python libraries they depend on.
2856
2857Which Python package is used can be specified with the @code{#:python}
2858parameter.
2859@end defvr
2860
2861@defvr {Scheme Variable} perl-build-system
2862This variable is exported by @code{(guix build-system perl)}. It
2d2a53fc
EB
2863implements the standard build procedure for Perl packages, which either
2864consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
2865followed by @code{Build} and @code{Build install}; or in running
2866@code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
f97c9175 2867@code{make} and @code{make install}, depending on which of
2d2a53fc
EB
2868@code{Build.PL} or @code{Makefile.PL} is present in the package
2869distribution. Preference is given to the former if both @code{Build.PL}
2870and @code{Makefile.PL} exist in the package distribution. This
2871preference can be reversed by specifying @code{#t} for the
2872@code{#:make-maker?} parameter.
2873
2874The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
2875passes flags specified by the @code{#:make-maker-flags} or
2876@code{#:module-build-flags} parameter, respectively.
7458bd0a
LC
2877
2878Which Perl package is used can be specified with @code{#:perl}.
2879@end defvr
2880
f8f3bef6
RW
2881@defvr {Scheme Variable} r-build-system
2882This variable is exported by @code{(guix build-system r)}. It
2883implements the build procedure used by @uref{http://r-project.org, R}
2884packages, which essentially is little more than running @code{R CMD
2885INSTALL --library=/gnu/store/@dots{}} in an environment where
2886@code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
2887are run after installation using the R function
2888@code{tools::testInstalledPackage}.
2889@end defvr
2890
c08f9818
DT
2891@defvr {Scheme Variable} ruby-build-system
2892This variable is exported by @code{(guix build-system ruby)}. It
2893implements the RubyGems build procedure used by Ruby packages, which
2894involves running @code{gem build} followed by @code{gem install}.
2895
5dc87623
DT
2896The @code{source} field of a package that uses this build system
2897typically references a gem archive, since this is the format that Ruby
2898developers use when releasing their software. The build system unpacks
2899the gem archive, potentially patches the source, runs the test suite,
2900repackages the gem, and installs it. Additionally, directories and
2901tarballs may be referenced to allow building unreleased gems from Git or
2902a traditional source release tarball.
e83c6d00 2903
c08f9818 2904Which Ruby package is used can be specified with the @code{#:ruby}
6e9f2913
PP
2905parameter. A list of additional flags to be passed to the @command{gem}
2906command can be specified with the @code{#:gem-flags} parameter.
c08f9818 2907@end defvr
7458bd0a 2908
a677c726
RW
2909@defvr {Scheme Variable} waf-build-system
2910This variable is exported by @code{(guix build-system waf)}. It
2911implements a build procedure around the @code{waf} script. The common
2912phases---@code{configure}, @code{build}, and @code{install}---are
2913implemented by passing their names as arguments to the @code{waf}
2914script.
2915
2916The @code{waf} script is executed by the Python interpreter. Which
2917Python package is used to run the script can be specified with the
2918@code{#:python} parameter.
2919@end defvr
2920
14dfdf2e
FB
2921@defvr {Scheme Variable} haskell-build-system
2922This variable is exported by @code{(guix build-system haskell)}. It
2923implements the Cabal build procedure used by Haskell packages, which
2924involves running @code{runhaskell Setup.hs configure
2925--prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
2926Instead of installing the package by running @code{runhaskell Setup.hs
2927install}, to avoid trying to register libraries in the read-only
2928compiler store directory, the build system uses @code{runhaskell
2929Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
2930addition, the build system generates the package documentation by
2931running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
2932is passed. Optional Haddock parameters can be passed with the help of
2933the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
2934not found, the build system looks for @code{Setup.lhs} instead.
2935
2936Which Haskell compiler is used can be specified with the @code{#:haskell}
a54bd6d7 2937parameter which defaults to @code{ghc}.
14dfdf2e
FB
2938@end defvr
2939
e9137a53
FB
2940@defvr {Scheme Variable} emacs-build-system
2941This variable is exported by @code{(guix build-system emacs)}. It
f97c9175
AE
2942implements an installation procedure similar to the packaging system
2943of Emacs itself (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
e9137a53
FB
2944
2945It first creates the @code{@var{package}-autoloads.el} file, then it
2946byte compiles all Emacs Lisp files. Differently from the Emacs
2947packaging system, the Info documentation files are moved to the standard
2948documentation directory and the @file{dir} file is deleted. Each
2949package is installed in its own directory under
2950@file{share/emacs/site-lisp/guix.d}.
2951@end defvr
2952
7458bd0a
LC
2953Lastly, for packages that do not need anything as sophisticated, a
2954``trivial'' build system is provided. It is trivial in the sense that
2955it provides basically no support: it does not pull any implicit inputs,
2956and does not have a notion of build phases.
2957
2958@defvr {Scheme Variable} trivial-build-system
2959This variable is exported by @code{(guix build-system trivial)}.
2960
2961This build system requires a @code{#:builder} argument. This argument
f97c9175 2962must be a Scheme expression that builds the package output(s)---as
7458bd0a
LC
2963with @code{build-expression->derivation} (@pxref{Derivations,
2964@code{build-expression->derivation}}).
2965@end defvr
2966
568717fd
LC
2967@node The Store
2968@section The Store
2969
e531ac2a 2970@cindex store
1ddee424 2971@cindex store items
e531ac2a
LC
2972@cindex store paths
2973
f97c9175
AE
2974Conceptually, the @dfn{store} is the place where derivations that have
2975been built successfully are stored---by default, @file{/gnu/store}.
1ddee424
LC
2976Sub-directories in the store are referred to as @dfn{store items} or
2977sometimes @dfn{store paths}. The store has an associated database that
2978contains information such as the store paths referred to by each store
2979path, and the list of @emph{valid} store items---results of successful
ef5f5c86
LC
2980builds. This database resides in @file{@var{localstatedir}/guix/db},
2981where @var{localstatedir} is the state directory specified @i{via}
2982@option{--localstatedir} at configure time, usually @file{/var}.
1ddee424
LC
2983
2984The store is @emph{always} accessed by the daemon on behalf of its clients
e531ac2a 2985(@pxref{Invoking guix-daemon}). To manipulate the store, clients
f97c9175
AE
2986connect to the daemon over a Unix-domain socket, send requests to it,
2987and read the result---these are remote procedure calls, or RPCs.
e531ac2a 2988
1ddee424
LC
2989@quotation Note
2990Users must @emph{never} modify files under @file{/gnu/store} directly.
2991This would lead to inconsistencies and break the immutability
2992assumptions of Guix's functional model (@pxref{Introduction}).
2993
2994@xref{Invoking guix gc, @command{guix gc --verify}}, for information on
2995how to check the integrity of the store and attempt recovery from
2996accidental modifications.
2997@end quotation
2998
e531ac2a
LC
2999The @code{(guix store)} module provides procedures to connect to the
3000daemon, and to perform RPCs. These are described below.
3001
3002@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
3003Connect to the daemon over the Unix-domain socket at @var{file}. When
3004@var{reserve-space?} is true, instruct it to reserve a little bit of
3005extra space on the file system so that the garbage collector can still
f97c9175 3006operate should the disk become full. Return a server object.
e531ac2a
LC
3007
3008@var{file} defaults to @var{%default-socket-path}, which is the normal
3009location given the options that were passed to @command{configure}.
3010@end deffn
3011
3012@deffn {Scheme Procedure} close-connection @var{server}
3013Close the connection to @var{server}.
3014@end deffn
3015
3016@defvr {Scheme Variable} current-build-output-port
3017This variable is bound to a SRFI-39 parameter, which refers to the port
3018where build and error logs sent by the daemon should be written.
3019@end defvr
3020
3021Procedures that make RPCs all take a server object as their first
3022argument.
3023
3024@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
06b76acc
LC
3025@cindex invalid store items
3026Return @code{#t} when @var{path} designates a valid store item and
3027@code{#f} otherwise (an invalid item may exist on disk but still be
3028invalid, for instance because it is the result of an aborted or failed
3029build.)
3030
3031A @code{&nix-protocol-error} condition is raised if @var{path} is not
3032prefixed by the store directory (@file{/gnu/store}).
e531ac2a
LC
3033@end deffn
3034
cfbf9160 3035@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
3036Add @var{text} under file @var{name} in the store, and return its store
3037path. @var{references} is the list of store paths referred to by the
3038resulting store path.
3039@end deffn
3040
874e6874 3041@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
3042Build @var{derivations} (a list of @code{<derivation>} objects or
3043derivation paths), and return when the worker is done building them.
3044Return @code{#t} on success.
874e6874
LC
3045@end deffn
3046
b860f382
LC
3047Note that the @code{(guix monads)} module provides a monad as well as
3048monadic versions of the above procedures, with the goal of making it
3049more convenient to work with code that accesses the store (@pxref{The
3050Store Monad}).
3051
e531ac2a
LC
3052@c FIXME
3053@i{This section is currently incomplete.}
568717fd
LC
3054
3055@node Derivations
3056@section Derivations
3057
874e6874
LC
3058@cindex derivations
3059Low-level build actions and the environment in which they are performed
3060are represented by @dfn{derivations}. A derivation contain the
3061following pieces of information:
3062
3063@itemize
3064@item
3065The outputs of the derivation---derivations produce at least one file or
3066directory in the store, but may produce more.
3067
3068@item
3069The inputs of the derivations, which may be other derivations or plain
3070files in the store (patches, build scripts, etc.)
3071
3072@item
3073The system type targeted by the derivation---e.g., @code{x86_64-linux}.
3074
3075@item
3076The file name of a build script in the store, along with the arguments
3077to be passed.
3078
3079@item
3080A list of environment variables to be defined.
3081
3082@end itemize
3083
3084@cindex derivation path
3085Derivations allow clients of the daemon to communicate build actions to
3086the store. They exist in two forms: as an in-memory representation,
3087both on the client- and daemon-side, and as files in the store whose
3088name end in @code{.drv}---these files are referred to as @dfn{derivation
3089paths}. Derivations paths can be passed to the @code{build-derivations}
3090procedure to perform the build actions they prescribe (@pxref{The
3091Store}).
3092
3093The @code{(guix derivations)} module provides a representation of
3094derivations as Scheme objects, along with procedures to create and
3095otherwise manipulate derivations. The lowest-level primitive to create
3096a derivation is the @code{derivation} procedure:
3097
1909431c
LC
3098@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
3099 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 3100 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c 3101 [#:system (%current-system)] [#:references-graphs #f] @
35b5ca78
LC
3102 [#:allowed-references #f] [#:disallowed-references #f] @
3103 [#:leaked-env-vars #f] [#:local-build? #f] @
4a6aeb67 3104 [#:substitutable? #t]
59688fc4
LC
3105Build a derivation with the given arguments, and return the resulting
3106@code{<derivation>} object.
874e6874 3107
2096ef47 3108When @var{hash} and @var{hash-algo} are given, a
874e6874 3109@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
3110known in advance, such as a file download. If, in addition,
3111@var{recursive?} is true, then that fixed output may be an executable
3112file or a directory and @var{hash} must be the hash of an archive
3113containing this output.
5b0c9d16 3114
858e9282 3115When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
3116name/store path pairs. In that case, the reference graph of each store
3117path is exported in the build environment in the corresponding file, in
3118a simple text format.
1909431c 3119
b53be755 3120When @var{allowed-references} is true, it must be a list of store items
35b5ca78
LC
3121or outputs that the derivation's output may refer to. Likewise,
3122@var{disallowed-references}, if true, must be a list of things the
3123outputs may @emph{not} refer to.
b53be755 3124
c0468155
LC
3125When @var{leaked-env-vars} is true, it must be a list of strings
3126denoting environment variables that are allowed to ``leak'' from the
3127daemon's environment to the build environment. This is only applicable
3128to fixed-output derivations---i.e., when @var{hash} is true. The main
3129use is to allow variables such as @code{http_proxy} to be passed to
3130derivations that download files.
3131
1909431c
LC
3132When @var{local-build?} is true, declare that the derivation is not a
3133good candidate for offloading and should rather be built locally
3134(@pxref{Daemon Offload Setup}). This is the case for small derivations
3135where the costs of data transfers would outweigh the benefits.
4a6aeb67
LC
3136
3137When @var{substitutable?} is false, declare that substitutes of the
3138derivation's output should not be used (@pxref{Substitutes}). This is
3139useful, for instance, when building packages that capture details of the
3140host CPU instruction set.
874e6874
LC
3141@end deffn
3142
3143@noindent
3144Here's an example with a shell script as its builder, assuming
3145@var{store} is an open connection to the daemon, and @var{bash} points
3146to a Bash executable in the store:
3147
3148@lisp
3149(use-modules (guix utils)
3150 (guix store)
3151 (guix derivations))
3152
59688fc4
LC
3153(let ((builder ; add the Bash script to the store
3154 (add-text-to-store store "my-builder.sh"
3155 "echo hello world > $out\n" '())))
3156 (derivation store "foo"
3157 bash `("-e" ,builder)
21b679f6 3158 #:inputs `((,bash) (,builder))
59688fc4 3159 #:env-vars '(("HOME" . "/homeless"))))
834129e0 3160@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
3161@end lisp
3162
21b679f6
LC
3163As can be guessed, this primitive is cumbersome to use directly. A
3164better approach is to write build scripts in Scheme, of course! The
3165best course of action for that is to write the build code as a
3166``G-expression'', and to pass it to @code{gexp->derivation}. For more
6621cdb6 3167information, @pxref{G-Expressions}.
21b679f6 3168
f2fadbc1
AE
3169Once upon a time, @code{gexp->derivation} did not exist and constructing
3170derivations with build code written in Scheme was achieved with
3171@code{build-expression->derivation}, documented below. This procedure
3172is now deprecated in favor of the much nicer @code{gexp->derivation}.
3173
3174@deffn {Scheme Procedure} build-expression->derivation @var{store} @
3175 @var{name} @var{exp} @
3176 [#:system (%current-system)] [#:inputs '()] @
3177 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3178 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3179 [#:references-graphs #f] [#:allowed-references #f] @
35b5ca78 3180 [#:disallowed-references #f] @
f2fadbc1
AE
3181 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3182Return a derivation that executes Scheme expression @var{exp} as a
3183builder for derivation @var{name}. @var{inputs} must be a list of
3184@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
3185@code{"out"} is assumed. @var{modules} is a list of names of Guile
3186modules from the current search path to be copied in the store,
3187compiled, and made available in the load path during the execution of
3188@var{exp}---e.g., @code{((guix build utils) (guix build
3189gnu-build-system))}.
3190
3191@var{exp} is evaluated in an environment where @code{%outputs} is bound
3192to a list of output/path pairs, and where @code{%build-inputs} is bound
3193to a list of string/output-path pairs made from @var{inputs}.
3194Optionally, @var{env-vars} is a list of string pairs specifying the name
3195and value of environment variables visible to the builder. The builder
3196terminates by passing the result of @var{exp} to @code{exit}; thus, when
3197@var{exp} returns @code{#f}, the build is considered to have failed.
3198
3199@var{exp} is built using @var{guile-for-build} (a derivation). When
3200@var{guile-for-build} is omitted or is @code{#f}, the value of the
3201@code{%guile-for-build} fluid is used instead.
3202
3203See the @code{derivation} procedure for the meaning of
35b5ca78
LC
3204@var{references-graphs}, @var{allowed-references},
3205@var{disallowed-references}, @var{local-build?}, and
3206@var{substitutable?}.
f2fadbc1
AE
3207@end deffn
3208
3209@noindent
3210Here's an example of a single-output derivation that creates a directory
3211containing one file:
3212
3213@lisp
3214(let ((builder '(let ((out (assoc-ref %outputs "out")))
3215 (mkdir out) ; create /gnu/store/@dots{}-goo
3216 (call-with-output-file (string-append out "/test")
3217 (lambda (p)
3218 (display '(hello guix) p))))))
3219 (build-expression->derivation store "goo" builder))
3220
3221@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
3222@end lisp
3223
568717fd 3224
b860f382
LC
3225@node The Store Monad
3226@section The Store Monad
3227
3228@cindex monad
3229
3230The procedures that operate on the store described in the previous
3231sections all take an open connection to the build daemon as their first
3232argument. Although the underlying model is functional, they either have
3233side effects or depend on the current state of the store.
3234
3235The former is inconvenient: the connection to the build daemon has to be
3236carried around in all those functions, making it impossible to compose
3237functions that do not take that parameter with functions that do. The
3238latter can be problematic: since store operations have side effects
3239and/or depend on external state, they have to be properly sequenced.
3240
3241@cindex monadic values
3242@cindex monadic functions
3243This is where the @code{(guix monads)} module comes in. This module
3244provides a framework for working with @dfn{monads}, and a particularly
3245useful monad for our uses, the @dfn{store monad}. Monads are a
3246construct that allows two things: associating ``context'' with values
3247(in our case, the context is the store), and building sequences of
561fb6c3 3248computations (here computations include accesses to the store.) Values
b860f382
LC
3249in a monad---values that carry this additional context---are called
3250@dfn{monadic values}; procedures that return such values are called
3251@dfn{monadic procedures}.
3252
3253Consider this ``normal'' procedure:
3254
3255@example
45adbd62
LC
3256(define (sh-symlink store)
3257 ;; Return a derivation that symlinks the 'bash' executable.
3258 (let* ((drv (package-derivation store bash))
3259 (out (derivation->output-path drv))
3260 (sh (string-append out "/bin/bash")))
3261 (build-expression->derivation store "sh"
3262 `(symlink ,sh %output))))
b860f382
LC
3263@end example
3264
c6f30b81
LC
3265Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3266as a monadic function:
b860f382
LC
3267
3268@example
45adbd62 3269(define (sh-symlink)
b860f382 3270 ;; Same, but return a monadic value.
c6f30b81
LC
3271 (mlet %store-monad ((drv (package->derivation bash)))
3272 (gexp->derivation "sh"
3273 #~(symlink (string-append #$drv "/bin/bash")
3274 #$output))))
b860f382
LC
3275@end example
3276
c6f30b81
LC
3277There several things to note in the second version: the @code{store}
3278parameter is now implicit and is ``threaded'' in the calls to the
3279@code{package->derivation} and @code{gexp->derivation} monadic
3280procedures, and the monadic value returned by @code{package->derivation}
3281is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3282
3283As it turns out, the call to @code{package->derivation} can even be
3284omitted since it will take place implicitly, as we will see later
3285(@pxref{G-Expressions}):
3286
3287@example
3288(define (sh-symlink)
3289 (gexp->derivation "sh"
3290 #~(symlink (string-append #$bash "/bin/bash")
3291 #$output)))
3292@end example
b860f382 3293
7ce21611 3294@c See
a01ad638 3295@c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
7ce21611
LC
3296@c for the funny quote.
3297Calling the monadic @code{sh-symlink} has no effect. As someone once
3298said, ``you exit a monad like you exit a building on fire: by running''.
3299So, to exit the monad and get the desired effect, one must use
3300@code{run-with-store}:
b860f382
LC
3301
3302@example
8e9aa37f
CAW
3303(run-with-store (open-connection) (sh-symlink))
3304@result{} /gnu/store/...-sh-symlink
b860f382
LC
3305@end example
3306
f97c9175 3307Note that the @code{(guix monad-repl)} module extends the Guile REPL with
b9b86078 3308new ``meta-commands'' to make it easier to deal with monadic procedures:
f97c9175 3309@code{run-in-store}, and @code{enter-store-monad}. The former is used
b9b86078
LC
3310to ``run'' a single monadic value through the store:
3311
3312@example
3313scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3314$1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3315@end example
3316
3317The latter enters a recursive REPL, where all the return values are
3318automatically run through the store:
3319
3320@example
3321scheme@@(guile-user)> ,enter-store-monad
3322store-monad@@(guile-user) [1]> (package->derivation hello)
3323$2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3324store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3325$3 = "/gnu/store/@dots{}-foo"
3326store-monad@@(guile-user) [1]> ,q
3327scheme@@(guile-user)>
3328@end example
3329
3330@noindent
3331Note that non-monadic values cannot be returned in the
3332@code{store-monad} REPL.
3333
e87f0591
LC
3334The main syntactic forms to deal with monads in general are provided by
3335the @code{(guix monads)} module and are described below.
b860f382
LC
3336
3337@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3338Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3339in @var{monad}.
3340@end deffn
3341
3342@deffn {Scheme Syntax} return @var{val}
3343Return a monadic value that encapsulates @var{val}.
3344@end deffn
3345
751630c9 3346@deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
b860f382 3347@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
751630c9
LC
3348procedures @var{mproc}@dots{}@footnote{This operation is commonly
3349referred to as ``bind'', but that name denotes an unrelated procedure in
3350Guile. Thus we use this somewhat cryptic symbol inherited from the
3351Haskell language.}. There can be one @var{mproc} or several of them, as
3352in this example:
3353
3354@example
3355(run-with-state
3356 (with-monad %state-monad
3357 (>>= (return 1)
3358 (lambda (x) (return (+ 1 x)))
3359 (lambda (x) (return (* 2 x)))))
3360 'some-state)
3361
3362@result{} 4
3363@result{} some-state
3364@end example
b860f382
LC
3365@end deffn
3366
3367@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3368 @var{body} ...
3369@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3370 @var{body} ...
3371Bind the variables @var{var} to the monadic values @var{mval} in
3372@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3373``normal'' value @var{val}, as per @code{let}.
3374
3375@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3376(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3377@end deffn
3378
405a9d4e
LC
3379@deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3380Bind @var{mexp} and the following monadic expressions in sequence,
3381returning the result of the last expression.
3382
3383This is akin to @code{mlet}, except that the return values of the
3384monadic expressions are ignored. In that sense, it is analogous to
3385@code{begin}, but applied to monadic expressions.
3386@end deffn
3387
561fb6c3
LC
3388@cindex state monad
3389The @code{(guix monads)} module provides the @dfn{state monad}, which
3390allows an additional value---the state---to be @emph{threaded} through
3391monadic procedure calls.
3392
3393@defvr {Scheme Variable} %state-monad
3394The state monad. Procedures in the state monad can access and change
3395the state that is threaded.
3396
3397Consider the example below. The @code{square} procedure returns a value
3398in the state monad. It returns the square of its argument, but also
3399increments the current state value:
3400
3401@example
3402(define (square x)
3403 (mlet %state-monad ((count (current-state)))
3404 (mbegin %state-monad
3405 (set-current-state (+ 1 count))
3406 (return (* x x)))))
3407
3408(run-with-state (sequence %state-monad (map square (iota 3))) 0)
3409@result{} (0 1 4)
3410@result{} 3
3411@end example
3412
3413When ``run'' through @var{%state-monad}, we obtain that additional state
3414value, which is the number of @code{square} calls.
3415@end defvr
3416
3417@deffn {Monadic Procedure} current-state
3418Return the current state as a monadic value.
3419@end deffn
3420
3421@deffn {Monadic Procedure} set-current-state @var{value}
3422Set the current state to @var{value} and return the previous state as a
3423monadic value.
3424@end deffn
3425
3426@deffn {Monadic Procedure} state-push @var{value}
3427Push @var{value} to the current state, which is assumed to be a list,
3428and return the previous state as a monadic value.
3429@end deffn
3430
3431@deffn {Monadic Procedure} state-pop
3432Pop a value from the current state and return it as a monadic value.
3433The state is assumed to be a list.
3434@end deffn
3435
3436@deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3437Run monadic value @var{mval} starting with @var{state} as the initial
3438state. Return two values: the resulting value, and the resulting state.
3439@end deffn
3440
e87f0591
LC
3441The main interface to the store monad, provided by the @code{(guix
3442store)} module, is as follows.
b860f382
LC
3443
3444@defvr {Scheme Variable} %store-monad
561fb6c3
LC
3445The store monad---an alias for @var{%state-monad}.
3446
3447Values in the store monad encapsulate accesses to the store. When its
3448effect is needed, a value of the store monad must be ``evaluated'' by
3449passing it to the @code{run-with-store} procedure (see below.)
b860f382
LC
3450@end defvr
3451
3452@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3453Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3454open store connection.
3455@end deffn
3456
ad372953 3457@deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
b860f382 3458Return as a monadic value the absolute file name in the store of the file
ad372953
LC
3459containing @var{text}, a string. @var{references} is a list of store items that the
3460resulting text file refers to; it defaults to the empty list.
45adbd62
LC
3461@end deffn
3462
0a90af15
LC
3463@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
3464 [#:recursive? #t]
3465Return the name of @var{file} once interned in the store. Use
3466@var{name} as its store name, or the basename of @var{file} if
3467@var{name} is omitted.
3468
3469When @var{recursive?} is true, the contents of @var{file} are added
3470recursively; if @var{file} designates a flat file and @var{recursive?}
3471is true, its contents are added, and its permission bits are kept.
3472
3473The example below adds a file to the store, under two different names:
3474
3475@example
3476(run-with-store (open-connection)
3477 (mlet %store-monad ((a (interned-file "README"))
3478 (b (interned-file "README" "LEGU-MIN")))
3479 (return (list a b))))
3480
3481@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3482@end example
3483
3484@end deffn
3485
e87f0591
LC
3486The @code{(guix packages)} module exports the following package-related
3487monadic procedures:
3488
b860f382 3489@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4231f05b 3490 [#:system (%current-system)] [#:target #f] @
f97c9175
AE
3491 [#:output "out"]
3492Return as a monadic
b860f382
LC
3493value in the absolute file name of @var{file} within the @var{output}
3494directory of @var{package}. When @var{file} is omitted, return the name
4231f05b
LC
3495of the @var{output} directory of @var{package}. When @var{target} is
3496true, use it as a cross-compilation target triplet.
b860f382
LC
3497@end deffn
3498
b860f382 3499@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4231f05b
LC
3500@deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3501 @var{target} [@var{system}]
3502Monadic version of @code{package-derivation} and
3503@code{package-cross-derivation} (@pxref{Defining Packages}).
b860f382
LC
3504@end deffn
3505
3506
21b679f6
LC
3507@node G-Expressions
3508@section G-Expressions
3509
3510@cindex G-expression
3511@cindex build code quoting
3512So we have ``derivations'', which represent a sequence of build actions
3513to be performed to produce an item in the store (@pxref{Derivations}).
f97c9175 3514These build actions are performed when asking the daemon to actually
21b679f6
LC
3515build the derivations; they are run by the daemon in a container
3516(@pxref{Invoking guix-daemon}).
3517
3518@cindex strata of code
f97c9175 3519It should come as no surprise that we like to write these build actions
21b679f6
LC
3520in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3521code@footnote{The term @dfn{stratum} in this context was coined by
ef4ab0a4
LC
3522Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3523Kiselyov, who has written insightful
3524@url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3525on this topic}, refers to this kind of code generation as
3526@dfn{staging}.}: the ``host code''---code that defines packages, talks
3527to the daemon, etc.---and the ``build code''---code that actually
3528performs build actions, such as making directories, invoking
3529@command{make}, etc.
21b679f6
LC
3530
3531To describe a derivation and its build actions, one typically needs to
3532embed build code inside host code. It boils down to manipulating build
f97c9175 3533code as data, and the homoiconicity of Scheme---code has a direct
21b679f6 3534representation as data---comes in handy for that. But we need more than
f97c9175 3535the normal @code{quasiquote} mechanism in Scheme to construct build
21b679f6
LC
3536expressions.
3537
3538The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3539S-expressions adapted to build expressions. G-expressions, or
f97c9175 3540@dfn{gexps}, consist essentially of three syntactic forms: @code{gexp},
21b679f6 3541@code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
f97c9175
AE
3542@code{#$}, and @code{#$@@}), which are comparable to
3543@code{quasiquote}, @code{unquote}, and @code{unquote-splicing},
3544respectivel (@pxref{Expression Syntax, @code{quasiquote},, guile,
3545GNU Guile Reference Manual}). However, there are major differences:
21b679f6
LC
3546
3547@itemize
3548@item
3549Gexps are meant to be written to a file and run or manipulated by other
3550processes.
3551
3552@item
b39fc6f7
LC
3553When a high-level object such as a package or derivation is unquoted
3554inside a gexp, the result is as if its output file name had been
3555introduced.
ff40e9b7 3556
21b679f6
LC
3557@item
3558Gexps carry information about the packages or derivations they refer to,
3559and these dependencies are automatically added as inputs to the build
3560processes that use them.
3561@end itemize
3562
c2b84676 3563@cindex lowering, of high-level objects in gexps
343eacbe
LC
3564This mechanism is not limited to package and derivation
3565objects: @dfn{compilers} able to ``lower'' other high-level objects to
c2b84676
LC
3566derivations or files in the store can be defined,
3567such that these objects can also be inserted
f97c9175 3568into gexps. For example, a useful type of high-level objects that can be
343eacbe 3569inserted in a gexp is ``file-like objects'', which make it easy to
f97c9175 3570add files to the store and to refer to them in
558e8b11
LC
3571derivations and such (see @code{local-file} and @code{plain-file}
3572below.)
b39fc6f7 3573
21b679f6
LC
3574To illustrate the idea, here is an example of a gexp:
3575
3576@example
3577(define build-exp
3578 #~(begin
3579 (mkdir #$output)
3580 (chdir #$output)
aff8ce7c 3581 (symlink (string-append #$coreutils "/bin/ls")
21b679f6
LC
3582 "list-files")))
3583@end example
3584
3585This gexp can be passed to @code{gexp->derivation}; we obtain a
3586derivation that builds a directory containing exactly one symlink to
3587@file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3588
3589@example
3590(gexp->derivation "the-thing" build-exp)
3591@end example
3592
e20fd1bf 3593As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
21b679f6
LC
3594substituted to the reference to the @var{coreutils} package in the
3595actual build code, and @var{coreutils} is automatically made an input to
3596the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
f97c9175
AE
3597output)}) is replaced by a string containing the directory name of the
3598output of the derivation.
667b2508
LC
3599
3600@cindex cross compilation
3601In a cross-compilation context, it is useful to distinguish between
3602references to the @emph{native} build of a package---that can run on the
3603host---versus references to cross builds of a package. To that end, the
3604@code{#+} plays the same role as @code{#$}, but is a reference to a
3605native package build:
3606
3607@example
3608(gexp->derivation "vi"
3609 #~(begin
3610 (mkdir #$output)
3611 (system* (string-append #+coreutils "/bin/ln")
3612 "-s"
3613 (string-append #$emacs "/bin/emacs")
3614 (string-append #$output "/bin/vi")))
3615 #:target "mips64el-linux")
3616@end example
3617
3618@noindent
3619In the example above, the native build of @var{coreutils} is used, so
3620that @command{ln} can actually run on the host; but then the
3621cross-compiled build of @var{emacs} is referenced.
3622
3623The syntactic form to construct gexps is summarized below.
21b679f6
LC
3624
3625@deffn {Scheme Syntax} #~@var{exp}
3626@deffnx {Scheme Syntax} (gexp @var{exp})
3627Return a G-expression containing @var{exp}. @var{exp} may contain one
3628or more of the following forms:
3629
3630@table @code
3631@item #$@var{obj}
3632@itemx (ungexp @var{obj})
b39fc6f7
LC
3633Introduce a reference to @var{obj}. @var{obj} may have one of the
3634supported types, for example a package or a
21b679f6
LC
3635derivation, in which case the @code{ungexp} form is replaced by its
3636output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
3637
b39fc6f7
LC
3638If @var{obj} is a list, it is traversed and references to supported
3639objects are substituted similarly.
21b679f6
LC
3640
3641If @var{obj} is another gexp, its contents are inserted and its
3642dependencies are added to those of the containing gexp.
3643
3644If @var{obj} is another kind of object, it is inserted as is.
3645
b39fc6f7
LC
3646@item #$@var{obj}:@var{output}
3647@itemx (ungexp @var{obj} @var{output})
21b679f6 3648This is like the form above, but referring explicitly to the
b39fc6f7
LC
3649@var{output} of @var{obj}---this is useful when @var{obj} produces
3650multiple outputs (@pxref{Packages with Multiple Outputs}).
21b679f6 3651
667b2508
LC
3652@item #+@var{obj}
3653@itemx #+@var{obj}:output
3654@itemx (ungexp-native @var{obj})
3655@itemx (ungexp-native @var{obj} @var{output})
3656Same as @code{ungexp}, but produces a reference to the @emph{native}
3657build of @var{obj} when used in a cross compilation context.
3658
21b679f6
LC
3659@item #$output[:@var{output}]
3660@itemx (ungexp output [@var{output}])
3661Insert a reference to derivation output @var{output}, or to the main
3662output when @var{output} is omitted.
3663
3664This only makes sense for gexps passed to @code{gexp->derivation}.
3665
3666@item #$@@@var{lst}
3667@itemx (ungexp-splicing @var{lst})
3668Like the above, but splices the contents of @var{lst} inside the
3669containing list.
3670
667b2508
LC
3671@item #+@@@var{lst}
3672@itemx (ungexp-native-splicing @var{lst})
3673Like the above, but refers to native builds of the objects listed in
3674@var{lst}.
3675
21b679f6
LC
3676@end table
3677
3678G-expressions created by @code{gexp} or @code{#~} are run-time objects
3679of the @code{gexp?} type (see below.)
3680@end deffn
3681
3682@deffn {Scheme Procedure} gexp? @var{obj}
3683Return @code{#t} if @var{obj} is a G-expression.
3684@end deffn
3685
3686G-expressions are meant to be written to disk, either as code building
3687some derivation, or as plain files in the store. The monadic procedures
3688below allow you to do that (@pxref{The Store Monad}, for more
3689information about monads.)
3690
3691@deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
ce45eb4c 3692 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
21b679f6
LC
3693 [#:hash #f] [#:hash-algo #f] @
3694 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4684f301 3695 [#:module-path @var{%load-path}] @
c8351d9a 3696 [#:references-graphs #f] [#:allowed-references #f] @
3f4ecf32 3697 [#:disallowed-references #f] @
c0468155 3698 [#:leaked-env-vars #f] @
0309e1b0 3699 [#:script-name (string-append @var{name} "-builder")] @
4a6aeb67 3700 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
21b679f6 3701Return a derivation @var{name} that runs @var{exp} (a gexp) with
0309e1b0
LC
3702@var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
3703stored in a file called @var{script-name}. When @var{target} is true,
3704it is used as the cross-compilation target triplet for packages referred
3705to by @var{exp}.
21b679f6 3706
ce45eb4c
LC
3707Make @var{modules} available in the evaluation context of @var{exp};
3708@var{modules} is a list of names of Guile modules searched in
3709@var{module-path} to be copied in the store, compiled, and made available in
21b679f6
LC
3710the load path during the execution of @var{exp}---e.g., @code{((guix
3711build utils) (guix build gnu-build-system))}.
3712
ce45eb4c
LC
3713@var{graft?} determines whether packages referred to by @var{exp} should be grafted when
3714applicable.
3715
b53833b2
LC
3716When @var{references-graphs} is true, it must be a list of tuples of one of the
3717following forms:
3718
3719@example
3720(@var{file-name} @var{package})
3721(@var{file-name} @var{package} @var{output})
3722(@var{file-name} @var{derivation})
3723(@var{file-name} @var{derivation} @var{output})
3724(@var{file-name} @var{store-item})
3725@end example
3726
3727The right-hand-side of each element of @var{references-graphs} is automatically made
3728an input of the build process of @var{exp}. In the build environment, each
3729@var{file-name} contains the reference graph of the corresponding item, in a simple
3730text format.
3731
c8351d9a
LC
3732@var{allowed-references} must be either @code{#f} or a list of output names and packages.
3733In the latter case, the list denotes store items that the result is allowed to
3734refer to. Any reference to another store item will lead to a build error.
3f4ecf32
LC
3735Similarly for @var{disallowed-references}, which can list items that must not be
3736referenced by the outputs.
c8351d9a 3737
e20fd1bf 3738The other arguments are as for @code{derivation} (@pxref{Derivations}).
21b679f6
LC
3739@end deffn
3740
343eacbe 3741@cindex file-like objects
e1c153e0
LC
3742The @code{local-file}, @code{plain-file}, @code{computed-file},
3743@code{program-file}, and @code{scheme-file} procedures below return
3744@dfn{file-like objects}. That is, when unquoted in a G-expression,
3745these objects lead to a file in the store. Consider this G-expression:
343eacbe
LC
3746
3747@example
3748#~(system* (string-append #$glibc "/sbin/nscd") "-f"
3749 #$(local-file "/tmp/my-nscd.conf"))
3750@end example
3751
3752The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
3753to the store. Once expanded, for instance @i{via}
3754@code{gexp->derivation}, the G-expression refers to that copy under
3755@file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
3756does not have any effect on what the G-expression does.
3757@code{plain-file} can be used similarly; it differs in that the file
3758content is directly passed as a string.
3759
d9ae938f
LC
3760@deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
3761 [#:recursive? #t]
3762Return an object representing local file @var{file} to add to the store; this
9d3994f7
LC
3763object can be used in a gexp. If @var{file} is a relative file name, it is looked
3764up relative to the source file where this form appears. @var{file} will be added to
3765the store under @var{name}--by default the base name of @var{file}.
d9ae938f
LC
3766
3767When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
3768designates a flat file and @var{recursive?} is true, its contents are added, and its
3769permission bits are kept.
3770
3771This is the declarative counterpart of the @code{interned-file} monadic
3772procedure (@pxref{The Store Monad, @code{interned-file}}).
3773@end deffn
3774
558e8b11
LC
3775@deffn {Scheme Procedure} plain-file @var{name} @var{content}
3776Return an object representing a text file called @var{name} with the given
3777@var{content} (a string) to be added to the store.
3778
3779This is the declarative counterpart of @code{text-file}.
3780@end deffn
3781
91937029
LC
3782@deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
3783 [#:modules '()] [#:options '(#:local-build? #t)]
3784Return an object representing the store item @var{name}, a file or
3785directory computed by @var{gexp}. @var{modules} specifies the set of
3786modules visible in the execution context of @var{gexp}. @var{options}
3787is a list of additional arguments to pass to @code{gexp->derivation}.
3788
3789This is the declarative counterpart of @code{gexp->derivation}.
3790@end deffn
3791
21b679f6
LC
3792@deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
3793Return an executable script @var{name} that runs @var{exp} using
3794@var{guile} with @var{modules} in its search path.
3795
3796The example below builds a script that simply invokes the @command{ls}
3797command:
3798
3799@example
3800(use-modules (guix gexp) (gnu packages base))
3801
3802(gexp->script "list-files"
3803 #~(execl (string-append #$coreutils "/bin/ls")
3804 "ls"))
3805@end example
3806
3807When ``running'' it through the store (@pxref{The Store Monad,
e20fd1bf 3808@code{run-with-store}}), we obtain a derivation that produces an
21b679f6
LC
3809executable file @file{/gnu/store/@dots{}-list-files} along these lines:
3810
3811@example
3812#!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
3813!#
3814(execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls")
3815 "ls")
3816@end example
3817@end deffn
3818
15a01c72
LC
3819@deffn {Scheme Procedure} program-file @var{name} @var{exp} @
3820 [#:modules '()] [#:guile #f]
3821Return an object representing the executable store item @var{name} that
3822runs @var{gexp}. @var{guile} is the Guile package used to execute that
3823script, and @var{modules} is the list of modules visible to that script.
3824
3825This is the declarative counterpart of @code{gexp->script}.
3826@end deffn
3827
21b679f6
LC
3828@deffn {Monadic Procedure} gexp->file @var{name} @var{exp}
3829Return a derivation that builds a file @var{name} containing @var{exp}.
3830
3831The resulting file holds references to all the dependencies of @var{exp}
3832or a subset thereof.
3833@end deffn
1ed19464 3834
e1c153e0
LC
3835@deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
3836Return an object representing the Scheme file @var{name} that contains
3837@var{exp}.
3838
3839This is the declarative counterpart of @code{gexp->file}.
3840@end deffn
3841
1ed19464
LC
3842@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
3843Return as a monadic value a derivation that builds a text file
3844containing all of @var{text}. @var{text} may list, in addition to
d9ae938f
LC
3845strings, objects of any type that can be used in a gexp: packages,
3846derivations, local file objects, etc. The resulting store file holds
3847references to all these.
1ed19464
LC
3848
3849This variant should be preferred over @code{text-file} anytime the file
3850to create will reference items from the store. This is typically the
3851case when building a configuration file that embeds store file names,
3852like this:
3853
3854@example
3855(define (profile.sh)
3856 ;; Return the name of a shell script in the store that
3857 ;; initializes the 'PATH' environment variable.
3858 (text-file* "profile.sh"
3859 "export PATH=" coreutils "/bin:"
3860 grep "/bin:" sed "/bin\n"))
3861@end example
3862
3863In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
3864will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
3865preventing them from being garbage-collected during its lifetime.
3866@end deffn
21b679f6 3867
b751cde3
LC
3868@deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
3869Return an object representing store file @var{name} containing
3870@var{text}. @var{text} is a sequence of strings and file-like objects,
3871as in:
3872
3873@example
3874(mixed-text-file "profile"
3875 "export PATH=" coreutils "/bin:" grep "/bin")
3876@end example
3877
3878This is the declarative counterpart of @code{text-file*}.
3879@end deffn
3880
21b679f6
LC
3881Of course, in addition to gexps embedded in ``host'' code, there are
3882also modules containing build tools. To make it clear that they are
3883meant to be used in the build stratum, these modules are kept in the
3884@code{(guix build @dots{})} name space.
3885
c2b84676
LC
3886@cindex lowering, of high-level objects in gexps
3887Internally, high-level objects are @dfn{lowered}, using their compiler,
3888to either derivations or store items. For instance, lowering a package
3889yields a derivation, and lowering a @code{plain-file} yields a store
3890item. This is achieved using the @code{lower-object} monadic procedure.
3891
3892@deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
3893 [#:target #f]
3894Return as a value in @var{%store-monad} the derivation or store item
3895corresponding to @var{obj} for @var{system}, cross-compiling for
3896@var{target} if @var{target} is true. @var{obj} must be an object that
3897has an associated gexp compiler, such as a @code{<package>}.
3898@end deffn
3899
21b679f6 3900
568717fd
LC
3901@c *********************************************************************
3902@node Utilities
3903@chapter Utilities
3904
6f773606
LC
3905This section describes Guix command-line utilities. Some of them are
3906primarily targeted at developers and users who write new package
3907definitions, while others are more generally useful. They complement
3908the Scheme programming interface of Guix in a convenient way.
210cc920 3909
568717fd 3910@menu
37166310 3911* Invoking guix build:: Building packages from the command line.
39bee8a2 3912* Invoking guix edit:: Editing package definitions.
210cc920 3913* Invoking guix download:: Downloading a file and printing its hash.
37166310 3914* Invoking guix hash:: Computing the cryptographic hash of a file.
2f7d2d91 3915* Invoking guix import:: Importing package definitions.
37166310 3916* Invoking guix refresh:: Updating package definitions.
b4f5e0e8 3917* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 3918* Invoking guix size:: Profiling disk usage.
88856916 3919* Invoking guix graph:: Visualizing the graph of packages.
372c4bbc 3920* Invoking guix environment:: Setting up development environments.
aff8ce7c 3921* Invoking guix publish:: Sharing substitutes.
d23c20f1 3922* Invoking guix challenge:: Challenging substitute servers.
32efa254 3923* Invoking guix container:: Process isolation.
568717fd
LC
3924@end menu
3925
e49951eb
MW
3926@node Invoking guix build
3927@section Invoking @command{guix build}
568717fd 3928
e49951eb 3929The @command{guix build} command builds packages or derivations and
6798a8e4
LC
3930their dependencies, and prints the resulting store paths. Note that it
3931does not modify the user's profile---this is the job of the
e49951eb 3932@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
3933it is mainly useful for distribution developers.
3934
3935The general syntax is:
c78bd12b
LC
3936
3937@example
e49951eb 3938guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
3939@end example
3940
f97c9175 3941As an example, the following command builds the latest versions of Emacs
ccd7158d
LC
3942and of Guile, displays their build logs, and finally displays the
3943resulting directories:
3944
3945@example
3946guix build emacs guile
3947@end example
3948
3949Similarly, the following command builds all the available packages:
3950
3951@example
5284339d 3952guix build --quiet --keep-going \
ccd7158d
LC
3953 `guix package -A | cut -f1,2 --output-delimiter=@@`
3954@end example
3955
c78bd12b 3956@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
3957the software distribution such as @code{coreutils} or
3958@code{coreutils-8.20}, or a derivation such as
834129e0 3959@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
3960package with the corresponding name (and optionally version) is searched
3961for among the GNU distribution modules (@pxref{Package Modules}).
3962
3963Alternatively, the @code{--expression} option may be used to specify a
3964Scheme expression that evaluates to a package; this is useful when
3965disambiguation among several same-named packages or package variants is
3966needed.
c78bd12b 3967
ccd7158d
LC
3968There may be zero or more @var{options}. The available options are
3969described in the subsections below.
3970
3971@menu
3972* Common Build Options:: Build options for most commands.
88ad6ded 3973* Package Transformation Options:: Creating variants of packages.
ccd7158d
LC
3974* Additional Build Options:: Options specific to 'guix build'.
3975@end menu
3976
3977@node Common Build Options
3978@subsection Common Build Options
3979
3980A number of options that control the build process are common to
3981@command{guix build} and other commands that can spawn builds, such as
3982@command{guix package} or @command{guix archive}. These are the
3983following:
3984
3985@table @code
3986
3987@item --load-path=@var{directory}
3988@itemx -L @var{directory}
3989Add @var{directory} to the front of the package module search path
3990(@pxref{Package Modules}).
3991
3992This allows users to define their own packages and make them visible to
3993the command-line tools.
3994
3995@item --keep-failed
3996@itemx -K
3997Keep the build tree of failed builds. Thus, if a build fail, its build
3998tree is kept under @file{/tmp}, in a directory whose name is shown at
3999the end of the build log. This is useful when debugging build issues.
4000
4001@item --keep-going
4002@itemx -k
4003Keep going when some of the derivations fail to build; return only once
4004all the builds have either completed or failed.
4005
4006The default behavior is to stop as soon as one of the specified
4007derivations has failed.
4008
4009@item --dry-run
4010@itemx -n
4011Do not build the derivations.
4012
4013@item --fallback
4014When substituting a pre-built binary fails, fall back to building
4015packages locally.
4016
4017@item --substitute-urls=@var{urls}
4018@anchor{client-substitute-urls}
4019Consider @var{urls} the whitespace-separated list of substitute source
4020URLs, overriding the default list of URLs of @command{guix-daemon}
4021(@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
4022
4023This means that substitutes may be downloaded from @var{urls}, provided
4024they are signed by a key authorized by the system administrator
4025(@pxref{Substitutes}).
4026
71e2065a
LC
4027When @var{urls} is the empty string, substitutes are effectively
4028disabled.
4029
ccd7158d
LC
4030@item --no-substitutes
4031Do not use substitutes for build products. That is, always build things
4032locally instead of allowing downloads of pre-built binaries
4033(@pxref{Substitutes}).
4034
7573d30f
LC
4035@item --no-grafts
4036Do not ``graft'' packages. In practice, this means that package updates
4037available as grafts are not applied. @xref{Security Updates}, for more
4038information on grafts.
4039
ccd7158d
LC
4040@item --rounds=@var{n}
4041Build each derivation @var{n} times in a row, and raise an error if
4042consecutive build results are not bit-for-bit identical.
4043
4044This is a useful way to detect non-deterministic builds processes.
4045Non-deterministic build processes are a problem because they make it
4046practically impossible for users to @emph{verify} whether third-party
4047binaries are genuine. @xref{Invoking guix challenge}, for more.
4048
4049Note that, currently, the differing build results are not kept around,
4050so you will have to manually investigate in case of an error---e.g., by
4051stashing one of the build results with @code{guix archive --export},
4052then rebuilding, and finally comparing the two results.
4053
4054@item --no-build-hook
f97c9175 4055Do not attempt to offload builds @i{via} the ``build hook'' of the daemon
ccd7158d
LC
4056(@pxref{Daemon Offload Setup}). That is, always build things locally
4057instead of offloading builds to remote machines.
4058
4059@item --max-silent-time=@var{seconds}
4060When the build or substitution process remains silent for more than
4061@var{seconds}, terminate it and report a build failure.
4062
4063@item --timeout=@var{seconds}
4064Likewise, when the build or substitution process lasts for more than
4065@var{seconds}, terminate it and report a build failure.
4066
4067By default there is no timeout. This behavior can be restored with
4068@code{--timeout=0}.
4069
4070@item --verbosity=@var{level}
4071Use the given verbosity level. @var{level} must be an integer between 0
4072and 5; higher means more verbose output. Setting a level of 4 or more
4073may be helpful when debugging setup issues with the build daemon.
4074
4075@item --cores=@var{n}
4076@itemx -c @var{n}
4077Allow the use of up to @var{n} CPU cores for the build. The special
4078value @code{0} means to use as many CPU cores as available.
4079
4080@item --max-jobs=@var{n}
4081@itemx -M @var{n}
4082Allow at most @var{n} build jobs in parallel. @xref{Invoking
4083guix-daemon, @code{--max-jobs}}, for details about this option and the
4084equivalent @command{guix-daemon} option.
4085
4086@end table
4087
4088Behind the scenes, @command{guix build} is essentially an interface to
4089the @code{package-derivation} procedure of the @code{(guix packages)}
4090module, and to the @code{build-derivations} procedure of the @code{(guix
4091derivations)} module.
4092
4093In addition to options explicitly passed on the command line,
4094@command{guix build} and other @command{guix} commands that support
4095building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
4096
4097@defvr {Environment Variable} GUIX_BUILD_OPTIONS
4098Users can define this variable to a list of command line options that
4099will automatically be used by @command{guix build} and other
4100@command{guix} commands that can perform builds, as in the example
4101below:
4102
4103@example
4104$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
4105@end example
4106
4107These options are parsed independently, and the result is appended to
4108the parsed command-line options.
4109@end defvr
4110
88ad6ded
LC
4111
4112@node Package Transformation Options
4113@subsection Package Transformation Options
4114
4115@cindex package variants
4116Another set of command-line options supported by @command{guix build}
b8638f03 4117and also @command{guix package} are @dfn{package transformation
f97c9175 4118options}. These are options that make it possible to define @dfn{package
b8638f03
LC
4119variants}---for instance, packages built from different source code.
4120This is a convenient way to create customized packages on the fly
4121without having to type in the definitions of package variants
4122(@pxref{Defining Packages}).
88ad6ded
LC
4123
4124@table @code
4125
4126@item --with-source=@var{source}
4127Use @var{source} as the source of the corresponding package.
4128@var{source} must be a file name or a URL, as for @command{guix
4129download} (@pxref{Invoking guix download}).
4130
f97c9175
AE
4131The ``corresponding package'' is taken to be the one specified on the
4132command line the name of which matches the base of @var{source}---e.g.,
4133if @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
88ad6ded 4134package is @code{guile}. Likewise, the version string is inferred from
f97c9175 4135@var{source}; in the previous example, it is @code{2.0.10}.
88ad6ded
LC
4136
4137This option allows users to try out versions of packages other than the
4138one provided by the distribution. The example below downloads
4139@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
4140the @code{ed} package:
4141
4142@example
4143guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
4144@end example
4145
4146As a developer, @code{--with-source} makes it easy to test release
4147candidates:
4148
4149@example
4150guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
4151@end example
4152
4153@dots{} or to build from a checkout in a pristine environment:
4154
4155@example
4156$ git clone git://git.sv.gnu.org/guix.git
4157$ guix build guix --with-source=./guix
4158@end example
4159
47c0f92c
LC
4160@item --with-input=@var{package}=@var{replacement}
4161Replace dependency on @var{package} by a dependency on
4162@var{replacement}. @var{package} must be a package name, and
4163@var{replacement} must be a package specification such as @code{guile}
4164or @code{guile@@1.8}.
4165
f97c9175 4166For instance, the following command builds Guix, but replaces its
47c0f92c
LC
4167dependency on the current stable version of Guile with a dependency on
4168the development version of Guile, @code{guile-next}:
4169
4170@example
4171guix build --with-input=guile=guile-next guix
4172@end example
4173
4174This is a recursive, deep replacement. So in this example, both
4175@code{guix} and its dependency @code{guile-json} (which also depends on
4176@code{guile}) get rebuilt against @code{guile-next}.
4177
4178However, implicit inputs are left unchanged.
88ad6ded
LC
4179@end table
4180
ccd7158d
LC
4181@node Additional Build Options
4182@subsection Additional Build Options
4183
4184The command-line options presented below are specific to @command{guix
4185build}.
c78bd12b
LC
4186
4187@table @code
4188
5284339d
LC
4189@item --quiet
4190@itemx -q
4191Build quietly, without displaying the build log. Upon completion, the
4192build log is kept in @file{/var} (or similar) and can always be
4193retrieved using the @option{--log-file} option.
4194
34a1783f
DT
4195@item --file=@var{file}
4196@itemx -f @var{file}
4197
4198Build the package or derivation that the code within @var{file}
4199evaluates to.
4200
4201As an example, @var{file} might contain a package definition like this
4202(@pxref{Defining Packages}):
4203
4204@example
4205@verbatiminclude package-hello.scm
4206@end example
4207
c78bd12b
LC
4208@item --expression=@var{expr}
4209@itemx -e @var{expr}
ac5de156 4210Build the package or derivation @var{expr} evaluates to.
c78bd12b 4211
5401dd75 4212For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
4213guile-1.8)}, which unambiguously designates this specific variant of
4214version 1.8 of Guile.
4215
f97c9175 4216Alternatively, @var{expr} may be a G-expression, in which case it is used
56b82106
LC
4217as a build program passed to @code{gexp->derivation}
4218(@pxref{G-Expressions}).
4219
4220Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
4221(@pxref{The Store Monad}). The procedure must return a derivation as a
4222monadic value, which is then passed through @code{run-with-store}.
4223
c78bd12b
LC
4224@item --source
4225@itemx -S
f97c9175 4226Build the source derivations of the packages, rather than the packages
c78bd12b
LC
4227themselves.
4228
e49951eb 4229For instance, @code{guix build -S gcc} returns something like
f97c9175
AE
4230@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
4231source tarball.
c78bd12b 4232
f9cc8971 4233The returned source tarball is the result of applying any patches and
f97c9175 4234code snippets specified in the package @code{origin} (@pxref{Defining
f9cc8971
LC
4235Packages}).
4236
2cdfe13d
EB
4237@item --sources
4238Fetch and return the source of @var{package-or-derivation} and all their
4239dependencies, recursively. This is a handy way to obtain a local copy
4240of all the source code needed to build @var{packages}, allowing you to
4241eventually build them even without network access. It is an extension
4242of the @code{--source} option and can accept one of the following
4243optional argument values:
4244
4245@table @code
4246@item package
4247This value causes the @code{--sources} option to behave in the same way
4248as the @code{--source} option.
4249
4250@item all
f97c9175
AE
4251Build the source derivations of all packages, including any source that
4252might be listed as @code{inputs}. This is the default value.
2cdfe13d
EB
4253
4254@example
4255$ guix build --sources tzdata
4256The following derivations will be built:
4257 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
4258 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4259@end example
4260
4261@item transitive
f97c9175
AE
4262Build the source derivations of all packages, as well of all transitive
4263inputs to the packages. This can be used e.g. to
2cdfe13d
EB
4264prefetch package source for later offline building.
4265
4266@example
4267$ guix build --sources=transitive tzdata
4268The following derivations will be built:
4269 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4270 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
4271 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
4272 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
4273 /gnu/store/@dots{}-make-4.1.tar.xz.drv
4274 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
4275@dots{}
4276@end example
4277
4278@end table
4279
c78bd12b
LC
4280@item --system=@var{system}
4281@itemx -s @var{system}
4282Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
f97c9175 4283the system type of the build host.
c78bd12b
LC
4284
4285An example use of this is on Linux-based systems, which can emulate
4286different personalities. For instance, passing
4287@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
4288to build packages in a complete 32-bit environment.
4289
e55ec43d
LC
4290@item --target=@var{triplet}
4291@cindex cross-compilation
4292Cross-build for @var{triplet}, which must be a valid GNU triplet, such
4293as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
4294configuration triplets,, configure, GNU Configure and Build System}).
4295
a8d65643
LC
4296@anchor{build-check}
4297@item --check
4298@cindex determinism, checking
4299@cindex reproducibility, checking
4300Rebuild @var{package-or-derivation}, which are already available in the
4301store, and raise an error if the build results are not bit-for-bit
4302identical.
4303
f97c9175
AE
4304This mechanism allows you to check whether previously installed
4305substitutes are genuine (@pxref{Substitutes}), or whether the build result
4306of a package is deterministic. @xref{Invoking guix challenge}, for more
a8d65643
LC
4307background information and tools.
4308
c78bd12b
LC
4309@item --derivations
4310@itemx -d
4311Return the derivation paths, not the output paths, of the given
4312packages.
4313
70ee5642
LC
4314@item --root=@var{file}
4315@itemx -r @var{file}
4316Make @var{file} a symlink to the result, and register it as a garbage
4317collector root.
4318
4319@item --log-file
3f208ad7 4320Return the build log file names or URLs for the given
f97c9175 4321@var{package-or-derivation}, or raise an error if build logs are
70ee5642
LC
4322missing.
4323
4324This works regardless of how packages or derivations are specified. For
4325instance, the following invocations are equivalent:
4326
4327@example
4328guix build --log-file `guix build -d guile`
4329guix build --log-file `guix build guile`
4330guix build --log-file guile
4331guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
4332@end example
4333
3f208ad7
LC
4334If a log is unavailable locally, and unless @code{--no-substitutes} is
4335passed, the command looks for a corresponding log on one of the
4336substitute servers (as specified with @code{--substitute-urls}.)
70ee5642 4337
f97c9175
AE
4338So for instance, imagine you want to see the build log of GDB on MIPS,
4339but you are actually on an @code{x86_64} machine:
3f208ad7
LC
4340
4341@example
a01ad638 4342$ guix build --log-file gdb -s mips64el-linux
df061d07 4343https://hydra.gnu.org/log/@dots{}-gdb-7.10
3f208ad7
LC
4344@end example
4345
4346You can freely access a huge library of build logs!
70ee5642
LC
4347@end table
4348
16eb115e 4349
39bee8a2
LC
4350@node Invoking guix edit
4351@section Invoking @command{guix edit}
4352
4353@cindex package definition, editing
4354So many packages, so many source files! The @command{guix edit} command
4355facilitates the life of packagers by pointing their editor at the source
4356file containing the definition of the specified packages. For instance:
4357
4358@example
4359guix edit gcc-4.8 vim
4360@end example
4361
4362@noindent
6237b9fa
LC
4363launches the program specified in the @code{VISUAL} or in the
4364@code{EDITOR} environment variable to edit the recipe of GCC@tie{}4.8.4
4365and that of Vim.
39bee8a2 4366
f97c9175 4367If you are using Emacs, note that the Emacs user interface provides the
7c1b1ae2 4368@kbd{M-x guix-edit} command and a similar functionality in the ``package
f97c9175 4369info'' and ``package list'' buffers created by the @kbd{M-x
7c1b1ae2 4370guix-search-by-name} and similar commands (@pxref{Emacs Commands}).
39bee8a2
LC
4371
4372
210cc920
LC
4373@node Invoking guix download
4374@section Invoking @command{guix download}
4375
4376When writing a package definition, developers typically need to download
f97c9175 4377a source tarball, compute its SHA256 hash, and write that
210cc920
LC
4378hash in the package definition (@pxref{Defining Packages}). The
4379@command{guix download} tool helps with this task: it downloads a file
4380from the given URI, adds it to the store, and prints both its file name
4381in the store and its SHA256 hash.
4382
4383The fact that the downloaded file is added to the store saves bandwidth:
4384when the developer eventually tries to build the newly defined package
4385with @command{guix build}, the source tarball will not have to be
4386downloaded again because it is already in the store. It is also a
4387convenient way to temporarily stash files, which may be deleted
4388eventually (@pxref{Invoking guix gc}).
4389
4390The @command{guix download} command supports the same URIs as used in
4391package definitions. In particular, it supports @code{mirror://} URIs.
4392@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
4393Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
4394they are not available, an error is raised. @xref{Guile Preparations,
4395how to install the GnuTLS bindings for Guile,, gnutls-guile,
4396GnuTLS-Guile}, for more information.
210cc920
LC
4397
4398The following option is available:
4399
4400@table @code
4401@item --format=@var{fmt}
4402@itemx -f @var{fmt}
4403Write the hash in the format specified by @var{fmt}. For more
081145cf 4404information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
210cc920
LC
4405@end table
4406
6c365eca
NK
4407@node Invoking guix hash
4408@section Invoking @command{guix hash}
4409
210cc920 4410The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
4411It is primarily a convenience tool for anyone contributing to the
4412distribution: it computes the cryptographic hash of a file, which can be
4413used in the definition of a package (@pxref{Defining Packages}).
4414
4415The general syntax is:
4416
4417@example
4418guix hash @var{option} @var{file}
4419@end example
4420
4421@command{guix hash} has the following option:
4422
4423@table @code
4424
4425@item --format=@var{fmt}
4426@itemx -f @var{fmt}
210cc920 4427Write the hash in the format specified by @var{fmt}.
6c365eca
NK
4428
4429Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4430(@code{hex} and @code{hexadecimal} can be used as well).
4431
4432If the @option{--format} option is not specified, @command{guix hash}
4433will output the hash in @code{nix-base32}. This representation is used
4434in the definitions of packages.
4435
3140f2df
LC
4436@item --recursive
4437@itemx -r
4438Compute the hash on @var{file} recursively.
4439
4440In this case, the hash is computed on an archive containing @var{file},
f97c9175
AE
4441including its children if it is a directory. Some of the metadata of
4442@var{file} is part of the archive; for instance, when @var{file} is a
3140f2df 4443regular file, the hash is different depending on whether @var{file} is
f97c9175 4444executable or not. Metadata such as time stamps has no impact on the
3140f2df
LC
4445hash (@pxref{Invoking guix archive}).
4446@c FIXME: Replace xref above with xref to an ``Archive'' section when
4447@c it exists.
4448
6c365eca
NK
4449@end table
4450
2f7d2d91
LC
4451@node Invoking guix import
4452@section Invoking @command{guix import}
4453
4454@cindex importing packages
4455@cindex package import
4456@cindex package conversion
f97c9175
AE
4457The @command{guix import} command is useful for people who would like to
4458add a package to the distribution with as little work as
4459possible---a legitimate demand. The command knows of a few
4460repositories from which it can ``import'' package metadata. The result
2f7d2d91
LC
4461is a package definition, or a template thereof, in the format we know
4462(@pxref{Defining Packages}).
4463
4464The general syntax is:
4465
4466@example
4467guix import @var{importer} @var{options}@dots{}
4468@end example
4469
4470@var{importer} specifies the source from which to import package
f97c9175 4471metadata, and @var{options} specifies a package identifier and other
2f7d2d91
LC
4472options specific to @var{importer}. Currently, the available
4473``importers'' are:
4474
4475@table @code
4476@item gnu
f97c9175 4477Import metadata for the given GNU package. This provides a template
2f7d2d91
LC
4478for the latest version of that GNU package, including the hash of its
4479source tarball, and its canonical synopsis and description.
4480
f97c9175 4481Additional information such as the package dependencies and its
2f7d2d91
LC
4482license needs to be figured out manually.
4483
4484For example, the following command returns a package definition for
4485GNU@tie{}Hello:
4486
4487@example
4488guix import gnu hello
4489@end example
4490
4491Specific command-line options are:
4492
4493@table @code
4494@item --key-download=@var{policy}
4495As for @code{guix refresh}, specify the policy to handle missing OpenPGP
f97c9175 4496keys when verifying the package signature. @xref{Invoking guix
2f7d2d91
LC
4497refresh, @code{--key-download}}.
4498@end table
4499
4500@item pypi
4501@cindex pypi
f97c9175 4502Import metadata from the @uref{https://pypi.python.org/, Python Package
2f7d2d91
LC
4503Index}@footnote{This functionality requires Guile-JSON to be installed.
4504@xref{Requirements}.}. Information is taken from the JSON-formatted
4505description available at @code{pypi.python.org} and usually includes all
4506the relevant information, including package dependencies.
4507
f97c9175 4508The command below imports metadata for the @code{itsdangerous} Python
2f7d2d91
LC
4509package:
4510
4511@example
4512guix import pypi itsdangerous
4513@end example
4514
3aae8145
DT
4515@item gem
4516@cindex gem
f97c9175 4517Import metadata from @uref{https://rubygems.org/,
3aae8145
DT
4518RubyGems}@footnote{This functionality requires Guile-JSON to be
4519installed. @xref{Requirements}.}. Information is taken from the
4520JSON-formatted description available at @code{rubygems.org} and includes
4521most relevant information, including runtime dependencies. There are
f97c9175 4522some caveats, however. The metadata doesn't distinguish between
3aae8145
DT
4523synopses and descriptions, so the same string is used for both fields.
4524Additionally, the details of non-Ruby dependencies required to build
4525native extensions is unavailable and left as an exercise to the
4526packager.
4527
f97c9175 4528The command below imports metadata for the @code{rails} Ruby package:
3aae8145
DT
4529
4530@example
4531guix import gem rails
4532@end example
4533
d45dc6da
EB
4534@item cpan
4535@cindex CPAN
3c192e4e
AE
4536Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}@footnote{This
4537functionality requires Guile-JSON to be installed.
4538@xref{Requirements}.}.
f97c9175 4539Information is taken from the JSON-formatted metadata provided through
d45dc6da 4540@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
4541relevant information, such as module dependencies. License information
4542should be checked closely. If Perl is available in the store, then the
4543@code{corelist} utility will be used to filter core modules out of the
4544list of dependencies.
d45dc6da 4545
f97c9175 4546The command command below imports metadata for the @code{Acme::Boolean}
d45dc6da
EB
4547Perl module:
4548
4549@example
4550guix import cpan Acme::Boolean
4551@end example
4552
e1248602
RW
4553@item cran
4554@cindex CRAN
d0bd632f 4555@cindex Bioconductor
f97c9175 4556Import metadata from @uref{http://cran.r-project.org/, CRAN}, the
e1248602
RW
4557central repository for the @uref{http://r-project.org, GNU@tie{}R
4558statistical and graphical environment}.
4559
f97c9175 4560Information is extracted from the @code{DESCRIPTION} file of the package.
e1248602 4561
f97c9175 4562The command command below imports metadata for the @code{Cairo}
e1248602
RW
4563R package:
4564
4565@example
4566guix import cran Cairo
4567@end example
4568
f97c9175 4569When @code{--archive=bioconductor} is added, metadata is imported from
d0bd632f
RW
4570@uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
4571packages for for the analysis and comprehension of high-throughput
4572genomic data in bioinformatics.
4573
f97c9175 4574Information is extracted from the @code{DESCRIPTION} file of a package
d0bd632f
RW
4575published on the web interface of the Bioconductor SVN repository.
4576
f97c9175 4577The command below imports metadata for the @code{GenomicRanges}
d0bd632f
RW
4578R package:
4579
4580@example
4581guix import cran --archive=bioconductor GenomicRanges
4582@end example
4583
2f7d2d91 4584@item nix
f97c9175 4585Import metadata from a local copy of the source of the
2f7d2d91
LC
4586@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
4587relies on the @command{nix-instantiate} command of
4588@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
4589typically written in a mixture of Nix-language and Bash code. This
4590command only imports the high-level package structure that is written in
4591the Nix language. It normally includes all the basic fields of a
4592package definition.
4593
4594When importing a GNU package, the synopsis and descriptions are replaced
4595by their canonical upstream variant.
4596
961d0d2d
LC
4597Usually, you will first need to do:
4598
4599@example
4600export NIX_REMOTE=daemon
4601@end example
4602
4603@noindent
4604so that @command{nix-instantiate} does not try to open the Nix database.
4605
2f7d2d91
LC
4606As an example, the command below imports the package definition of
4607LibreOffice (more precisely, it imports the definition of the package
4608bound to the @code{libreoffice} top-level attribute):
4609
4610@example
4611guix import nix ~/path/to/nixpkgs libreoffice
4612@end example
863af4e1
FB
4613
4614@item hackage
4615@cindex hackage
f97c9175 4616Import metadata from the Haskell community's central package archive
863af4e1
FB
4617@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4618Cabal files and includes all the relevant information, including package
4619dependencies.
4620
4621Specific command-line options are:
4622
4623@table @code
a4154748
FB
4624@item --stdin
4625@itemx -s
f97c9175 4626Read a Cabal file from standard input.
863af4e1
FB
4627@item --no-test-dependencies
4628@itemx -t
f97c9175 4629Do not include dependencies required only by the test suites.
a4154748
FB
4630@item --cabal-environment=@var{alist}
4631@itemx -e @var{alist}
4632@var{alist} is a Scheme alist defining the environment in which the
4633Cabal conditionals are evaluated. The accepted keys are: @code{os},
4634@code{arch}, @code{impl} and a string representing the name of a flag.
4635The value associated with a flag has to be either the symbol
4636@code{true} or @code{false}. The value associated with other keys
4637has to conform to the Cabal file format definition. The default value
4638associated with the keys @code{os}, @code{arch} and @code{impl} is
f97c9175 4639@samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
863af4e1
FB
4640@end table
4641
f97c9175 4642The command below imports metadata for the latest version of the
a4154748
FB
4643@code{HTTP} Haskell package without including test dependencies and
4644specifying the value of the flag @samp{network-uri} as @code{false}:
863af4e1
FB
4645
4646@example
a4154748 4647guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
863af4e1
FB
4648@end example
4649
4650A specific package version may optionally be specified by following the
1b846da8 4651package name by an at-sign and a version number as in the following example:
863af4e1
FB
4652
4653@example
1b846da8 4654guix import hackage mtl@@2.1.3.1
863af4e1 4655@end example
7f74a931
FB
4656
4657@item elpa
4658@cindex elpa
f97c9175 4659Import metadata from an Emacs Lisp Package Archive (ELPA) package
7f74a931
FB
4660repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4661
4662Specific command-line options are:
4663
4664@table @code
4665@item --archive=@var{repo}
4666@itemx -a @var{repo}
4667@var{repo} identifies the archive repository from which to retrieve the
4668information. Currently the supported repositories and their identifiers
4669are:
4670@itemize -
4671@item
840bd1d3 4672@uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7f74a931
FB
4673identifier. This is the default.
4674
4675@item
840bd1d3 4676@uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7f74a931
FB
4677@code{melpa-stable} identifier.
4678
4679@item
840bd1d3 4680@uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7f74a931
FB
4681identifier.
4682@end itemize
4683@end table
2f7d2d91
LC
4684@end table
4685
4686The structure of the @command{guix import} code is modular. It would be
4687useful to have more importers for other package formats, and your help
4688is welcome here (@pxref{Contributing}).
4689
37166310
LC
4690@node Invoking guix refresh
4691@section Invoking @command{guix refresh}
4692
4693The primary audience of the @command{guix refresh} command is developers
4694of the GNU software distribution. By default, it reports any packages
4695provided by the distribution that are outdated compared to the latest
4696upstream version, like this:
4697
4698@example
4699$ guix refresh
4700gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
4701gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
4702@end example
4703
f97c9175
AE
4704It does so by browsing the FTP directory of each package and determining
4705the highest version number of the source tarballs therein. The command
bcb571cb
LC
4706knows how to update specific types of packages: GNU packages, ELPA
4707packages, etc.---see the documentation for @option{--type} below. The
4708are many packages, though, for which it lacks a method to determine
4709whether a new upstream release is available. However, the mechanism is
4710extensible, so feel free to get in touch with us to add a new method!
37166310
LC
4711
4712When passed @code{--update}, it modifies distribution source files to
f97c9175 4713update the version numbers and source tarball hashes of those package
37166310
LC
4714recipes (@pxref{Defining Packages}). This is achieved by downloading
4715each package's latest source tarball and its associated OpenPGP
4716signature, authenticating the downloaded tarball against its signature
4717using @command{gpg}, and finally computing its hash. When the public
4718key used to sign the tarball is missing from the user's keyring, an
4719attempt is made to automatically retrieve it from a public key server;
f97c9175 4720when this is successful, the key is added to the user's keyring; otherwise,
37166310
LC
4721@command{guix refresh} reports an error.
4722
4723The following options are supported:
4724
4725@table @code
4726
2d7fc7da
LC
4727@item --expression=@var{expr}
4728@itemx -e @var{expr}
4729Consider the package @var{expr} evaluates to.
4730
4731This is useful to precisely refer to a package, as in this example:
4732
4733@example
4734guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
4735@end example
4736
4737This command lists the dependents of the ``final'' libc (essentially all
4738the packages.)
4739
37166310
LC
4740@item --update
4741@itemx -u
38e16b49
LC
4742Update distribution source files (package recipes) in place. This is
4743usually run from a checkout of the Guix source tree (@pxref{Running
4744Guix Before It Is Installed}):
4745
4746@example
4747$ ./pre-inst-env guix refresh -s non-core
4748@end example
4749
081145cf 4750@xref{Defining Packages}, for more information on package definitions.
37166310
LC
4751
4752@item --select=[@var{subset}]
4753@itemx -s @var{subset}
4754Select all the packages in @var{subset}, one of @code{core} or
4755@code{non-core}.
4756
4757The @code{core} subset refers to all the packages at the core of the
4758distribution---i.e., packages that are used to build ``everything
4759else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
4760changing one of these packages in the distribution entails a rebuild of
4761all the others. Thus, such updates are an inconvenience to users in
4762terms of build time or bandwidth used to achieve the upgrade.
4763
4764The @code{non-core} subset refers to the remaining packages. It is
4765typically useful in cases where an update of the core packages would be
4766inconvenient.
4767
bcb571cb
LC
4768@item --type=@var{updater}
4769@itemx -t @var{updater}
7191adc5
AK
4770Select only packages handled by @var{updater} (may be a comma-separated
4771list of updaters). Currently, @var{updater} may be one of:
bcb571cb
LC
4772
4773@table @code
4774@item gnu
4775the updater for GNU packages;
e80c0f85
LC
4776@item gnome
4777the updater for GNOME packages;
62061d6b
AW
4778@item xorg
4779the updater for X.org packages;
bcb571cb 4780@item elpa
d882c235
LC
4781the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
4782@item cran
b9d044ef 4783the updater for @uref{http://cran.r-project.org/, CRAN} packages;
d0bd632f
RW
4784@item bioconductor
4785the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
bab020d7 4786@item pypi
b9d044ef 4787the updater for @uref{https://pypi.python.org, PyPI} packages.
fbc5b815
BW
4788@item gem
4789the updater for @uref{https://rubygems.org, RubyGems} packages.
917a2a58
BW
4790@item github
4791the updater for @uref{https://github.com, GitHub} packages.
bcb571cb
LC
4792@end table
4793
f97c9175
AE
4794For instance, the following command only checks for updates of Emacs
4795packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
bcb571cb
LC
4796
4797@example
7191adc5 4798$ guix refresh --type=elpa,cran
d882c235 4799gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
bcb571cb
LC
4800gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
4801@end example
4802
37166310
LC
4803@end table
4804
4805In addition, @command{guix refresh} can be passed one or more package
4806names, as in this example:
4807
4808@example
38e16b49 4809$ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
37166310
LC
4810@end example
4811
4812@noindent
4813The command above specifically updates the @code{emacs} and
4814@code{idutils} packages. The @code{--select} option would have no
4815effect in this case.
4816
7d193ec3
EB
4817When considering whether to upgrade a package, it is sometimes
4818convenient to know which packages would be affected by the upgrade and
4819should be checked for compatibility. For this the following option may
4820be used when passing @command{guix refresh} one or more package names:
4821
4822@table @code
4823
6ffa706b
AK
4824@item --list-updaters
4825@itemx -L
4826List available updaters and exit (see @option{--type} above.)
4827
7d193ec3
EB
4828@item --list-dependent
4829@itemx -l
4830List top-level dependent packages that would need to be rebuilt as a
4831result of upgrading one or more packages.
4832
4833@end table
4834
4835Be aware that the @code{--list-dependent} option only
4836@emph{approximates} the rebuilds that would be required as a result of
4837an upgrade. More rebuilds might be required under some circumstances.
4838
4839@example
7779ab61
LC
4840$ guix refresh --list-dependent flex
4841Building the following 120 packages would ensure 213 dependent packages are rebuilt:
4842hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
4843@end example
4844
4845The command above lists a set of packages that could be built to check
4846for compatibility with an upgraded @code{flex} package.
4847
f9230085
LC
4848The following options can be used to customize GnuPG operation:
4849
4850@table @code
4851
f9230085
LC
4852@item --gpg=@var{command}
4853Use @var{command} as the GnuPG 2.x command. @var{command} is searched
4854for in @code{$PATH}.
4855
2bc53ba9
LC
4856@item --key-download=@var{policy}
4857Handle missing OpenPGP keys according to @var{policy}, which may be one
4858of:
4859
4860@table @code
4861@item always
4862Always download missing OpenPGP keys from the key server, and add them
4863to the user's GnuPG keyring.
4864
4865@item never
4866Never try to download missing OpenPGP keys. Instead just bail out.
4867
4868@item interactive
4869When a package signed with an unknown OpenPGP key is encountered, ask
4870the user whether to download it or not. This is the default behavior.
4871@end table
4872
4873@item --key-server=@var{host}
4874Use @var{host} as the OpenPGP key server when importing a public key.
4875
f9230085
LC
4876@end table
4877
917a2a58
BW
4878The @code{github} updater uses the
4879@uref{https://developer.github.com/v3/, GitHub API} to query for new
4880releases. When used repeatedly e.g. when refreshing all packages,
4881GitHub will eventually refuse to answer any further API requests. By
4882default 60 API requests per hour are allowed, and a full refresh on all
4883GitHub packages in Guix requires more than this. Authentication with
4884GitHub through the use of an API token alleviates these limits. To use
4885an API token, set the environment variable @code{GUIX_GITHUB_TOKEN} to a
4886token procured from @uref{https://github.com/settings/tokens} or
4887otherwise.
4888
4889
b4f5e0e8
CR
4890@node Invoking guix lint
4891@section Invoking @command{guix lint}
f97c9175
AE
4892The @command{guix lint} command is meant to help package developers avoid
4893common errors and use a consistent style. It runs a number of checks on
4894a given set of packages in order to find common mistakes in their
873c4085
LC
4895definitions. Available @dfn{checkers} include (see
4896@code{--list-checkers} for a complete list):
4897
4898@table @code
4899@item synopsis
4900@itemx description
4901Validate certain typographical and stylistic rules about package
4902descriptions and synopses.
4903
4904@item inputs-should-be-native
4905Identify inputs that should most likely be native inputs.
4906
4907@item source
4908@itemx home-page
50f5c46d 4909@itemx source-file-name
873c4085 4910Probe @code{home-page} and @code{source} URLs and report those that are
50f5c46d 4911invalid. Check that the source file name is meaningful, e.g. is not
f97c9175
AE
4912just a version number or ``git-checkout'', without a declared
4913@code{file-name} (@pxref{origin Reference}).
40a7d4e5 4914
5432734b 4915@item cve
09866b39
LC
4916@cindex security vulnerabilities
4917@cindex CVE, Common Vulnerabilities and Exposures
5432734b 4918Report known vulnerabilities found in the Common Vulnerabilities and
09866b39 4919Exposures (CVE) databases of the current and past year
5432734b
LC
4920@uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
4921NIST}.
4922
09866b39
LC
4923To view information about a particular vulnerability, visit pages such as:
4924
4925@itemize
4926@item
4927@indicateurl{https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-YYYY-ABCD}
4928@item
4929@indicateurl{https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-YYYY-ABCD}
4930@end itemize
4931
4932@noindent
4933where @code{CVE-YYYY-ABCD} is the CVE identifier---e.g.,
4934@code{CVE-2015-7554}.
4935
40a7d4e5
LC
4936@item formatting
4937Warn about obvious source code formatting issues: trailing white space,
4938use of tabulations, etc.
873c4085 4939@end table
b4f5e0e8
CR
4940
4941The general syntax is:
4942
4943@example
4944guix lint @var{options} @var{package}@dots{}
4945@end example
4946
4947If no package is given on the command line, then all packages are checked.
4948The @var{options} may be zero or more of the following:
4949
4950@table @code
f97c9175
AE
4951@item --list-checkers
4952@itemx -l
4953List and describe all the available checkers that will be run on packages
4954and exit.
b4f5e0e8 4955
dd7c013d
CR
4956@item --checkers
4957@itemx -c
4958Only enable the checkers specified in a comma-separated list using the
4959names returned by @code{--list-checkers}.
4960
b4f5e0e8 4961@end table
37166310 4962
fcc58db6
LC
4963@node Invoking guix size
4964@section Invoking @command{guix size}
4965
4966The @command{guix size} command helps package developers profile the
4967disk usage of packages. It is easy to overlook the impact of an
4968additional dependency added to a package, or the impact of using a
4969single output for a package that could easily be split (@pxref{Packages
f97c9175 4970with Multiple Outputs}). Such are the typical issues that
fcc58db6
LC
4971@command{guix size} can highlight.
4972
4973The command can be passed a package specification such as @code{gcc-4.8}
4974or @code{guile:debug}, or a file name in the store. Consider this
4975example:
4976
4977@example
4978$ guix size coreutils
4979store item total self
4980/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
4981/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
4982/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
4983/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
4984/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
4985/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
4986@end example
4987
4988@cindex closure
4989The store items listed here constitute the @dfn{transitive closure} of
4990Coreutils---i.e., Coreutils and all its dependencies, recursively---as
4991would be returned by:
4992
4993@example
4994$ guix gc -R /gnu/store/@dots{}-coreutils-8.23
4995@end example
4996
f97c9175 4997Here the output shows three columns next to store items. The first column,
fcc58db6
LC
4998labeled ``total'', shows the size in mebibytes (MiB) of the closure of
4999the store item---that is, its own size plus the size of all its
5000dependencies. The next column, labeled ``self'', shows the size of the
f97c9175
AE
5001item itself. The last column shows the ratio of the size of the item
5002itself to the space occupied by all the items listed here.
fcc58db6
LC
5003
5004In this example, we see that the closure of Coreutils weighs in at
500570@tie{}MiB, half of which is taken by libc. (That libc represents a
5006large fraction of the closure is not a problem @i{per se} because it is
5007always available on the system anyway.)
5008
5009When the package passed to @command{guix size} is available in the
5010store, @command{guix size} queries the daemon to determine its
5011dependencies, and measures its size in the store, similar to @command{du
5012-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
5013Coreutils}).
5014
5015When the given package is @emph{not} in the store, @command{guix size}
f97c9175
AE
5016reports information based on the available substitutes
5017(@pxref{Substitutes}). This makes it possible it to profile disk usage of
5018store items that are not even on disk, only available remotely.
fcc58db6 5019
a8f996c6 5020The available options are:
fcc58db6
LC
5021
5022@table @option
5023
d490d06e
LC
5024@item --substitute-urls=@var{urls}
5025Use substitute information from @var{urls}.
5026@xref{client-substitute-urls, the same option for @code{guix build}}.
5027
a8f996c6 5028@item --map-file=@var{file}
f97c9175 5029Write a graphical map of disk usage in PNG format to @var{file}.
a8f996c6
LC
5030
5031For the example above, the map looks like this:
5032
5033@image{images/coreutils-size-map,5in,, map of Coreutils disk usage
5034produced by @command{guix size}}
5035
5036This option requires that
5037@uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
5038installed and visible in Guile's module search path. When that is not
5039the case, @command{guix size} fails as it tries to load it.
5040
fcc58db6
LC
5041@item --system=@var{system}
5042@itemx -s @var{system}
5043Consider packages for @var{system}---e.g., @code{x86_64-linux}.
5044
5045@end table
5046
88856916
LC
5047@node Invoking guix graph
5048@section Invoking @command{guix graph}
5049
5050@cindex DAG
5051Packages and their dependencies form a @dfn{graph}, specifically a
5052directed acyclic graph (DAG). It can quickly become difficult to have a
f97c9175
AE
5053mental model of the package DAG, so the @command{guix graph} command
5054provides a visual representation of the DAG. @command{guix graph}
5055emits a DAG representation in the input format of
88856916 5056@uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
f97c9175 5057directly to the @command{dot} command of Graphviz. The general
88856916
LC
5058syntax is:
5059
5060@example
5061guix graph @var{options} @var{package}@dots{}
5062@end example
5063
5064For example, the following command generates a PDF file representing the
5065package DAG for the GNU@tie{}Core Utilities, showing its build-time
5066dependencies:
5067
5068@example
5069guix graph coreutils | dot -Tpdf > dag.pdf
5070@end example
5071
5072The output looks like this:
5073
5074@image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
5075
5076Nice little graph, no?
5077
f97c9175 5078But there is more than one graph! The one above is concise: it is the
88856916 5079graph of package objects, omitting implicit inputs such as GCC, libc,
f97c9175
AE
5080grep, etc. It is often useful to have such a concise graph, but
5081sometimes one may want to see more details. @command{guix graph} supports
5082several types of graphs, allowing you to choose the level of detail:
88856916
LC
5083
5084@table @code
5085@item package
f97c9175 5086This is the default type used in the example above. It shows the DAG of
88856916
LC
5087package objects, excluding implicit dependencies. It is concise, but
5088filters out many details.
5089
5090@item bag-emerged
5091This is the package DAG, @emph{including} implicit inputs.
5092
5093For instance, the following command:
5094
5095@example
5096guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
5097@end example
5098
5099... yields this bigger graph:
5100
5101@image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
5102
5103At the bottom of the graph, we see all the implicit inputs of
5104@var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
5105
f97c9175 5106Now, note that the dependencies of these implicit inputs---that is, the
88856916
LC
5107@dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
5108here, for conciseness.
5109
5110@item bag
5111Similar to @code{bag-emerged}, but this time including all the bootstrap
5112dependencies.
5113
38b92daa
LC
5114@item bag-with-origins
5115Similar to @code{bag}, but also showing origins and their dependencies.
5116
88856916
LC
5117@item derivations
5118This is the most detailed representation: It shows the DAG of
5119derivations (@pxref{Derivations}) and plain store items. Compared to
5120the above representation, many additional nodes are visible, including
f97c9175 5121build scripts, patches, Guile modules, etc.
88856916
LC
5122
5123@end table
5124
f97c9175 5125All the types above correspond to @emph{build-time dependencies}. The
88856916
LC
5126following graph type represents the @emph{run-time dependencies}:
5127
5128@table @code
5129@item references
5130This is the graph of @dfn{references} of a package output, as returned
5131by @command{guix gc --references} (@pxref{Invoking guix gc}).
5132
5133If the given package output is not available in the store, @command{guix
5134graph} attempts to obtain dependency information from substitutes.
5135@end table
5136
5137The available options are the following:
5138
5139@table @option
5140@item --type=@var{type}
5141@itemx -t @var{type}
5142Produce a graph output of @var{type}, where @var{type} must be one of
5143the values listed above.
5144
5145@item --list-types
5146List the supported graph types.
4c8f997a
LC
5147
5148@item --expression=@var{expr}
5149@itemx -e @var{expr}
5150Consider the package @var{expr} evaluates to.
5151
5152This is useful to precisely refer to a package, as in this example:
5153
5154@example
5155guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
5156@end example
88856916
LC
5157@end table
5158
5159
372c4bbc
DT
5160@node Invoking guix environment
5161@section Invoking @command{guix environment}
5162
f5fd4fd2 5163@cindex reproducible build environments
fe36d84e 5164@cindex development environments
372c4bbc
DT
5165The purpose of @command{guix environment} is to assist hackers in
5166creating reproducible development environments without polluting their
5167package profile. The @command{guix environment} tool takes one or more
f97c9175 5168packages, builds all of their inputs, and creates a shell
372c4bbc
DT
5169environment to use them.
5170
5171The general syntax is:
5172
5173@example
5174guix environment @var{options} @var{package}@dots{}
5175@end example
5176
fe36d84e
LC
5177The following example spawns a new shell set up for the development of
5178GNU@tie{}Guile:
372c4bbc
DT
5179
5180@example
5181guix environment guile
5182@end example
5183
f97c9175
AE
5184If the needed dependencies are not built yet, @command{guix environment}
5185automatically builds them. The environment of the new shell is an augmented
372c4bbc
DT
5186version of the environment that @command{guix environment} was run in.
5187It contains the necessary search paths for building the given package
5188added to the existing environment variables. To create a ``pure''
f97c9175 5189environment, in which the original environment variables have been unset,
50500f7c
LC
5190use the @code{--pure} option@footnote{Users sometimes wrongfully augment
5191environment variables such as @code{PATH} in their @file{~/.bashrc}
5192file. As a consequence, when @code{guix environment} launches it, Bash
5193may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
5194environment variables. It is an error to define such environment
5195variables in @file{.bashrc}; instead, they should be defined in
5196@file{.bash_profile}, which is sourced only by log-in shells.
5197@xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
5198details on Bash start-up files.}.
372c4bbc 5199
28de8d25
LC
5200@vindex GUIX_ENVIRONMENT
5201@command{guix environment} defines the @code{GUIX_ENVIRONMENT}
f97c9175 5202variable in the shell it spawns. This allows users to, say, define a
28de8d25
LC
5203specific prompt for development environments in their @file{.bashrc}
5204(@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
5205
5206@example
5207if [ -n "$GUIX_ENVIRONMENT" ]
5208then
5209 export PS1="\u@@\h \w [dev]\$ "
5210fi
5211@end example
5212
372c4bbc
DT
5213Additionally, more than one package may be specified, in which case the
5214union of the inputs for the given packages are used. For example, the
5215command below spawns a shell where all of the dependencies of both Guile
5216and Emacs are available:
5217
5218@example
5219guix environment guile emacs
5220@end example
5221
1de2fe95
DT
5222Sometimes an interactive shell session is not desired. An arbitrary
5223command may be invoked by placing the @code{--} token to separate the
5224command from the rest of the arguments:
372c4bbc
DT
5225
5226@example
1de2fe95 5227guix environment guile -- make -j4
372c4bbc
DT
5228@end example
5229
fe36d84e
LC
5230In other situations, it is more convenient to specify the list of
5231packages needed in the environment. For example, the following command
5232runs @command{python} from an environment containing Python@tie{}2.7 and
5233NumPy:
5234
5235@example
1de2fe95 5236guix environment --ad-hoc python2-numpy python-2.7 -- python
fe36d84e
LC
5237@end example
5238
cc90fbbf
DT
5239Furthermore, one might want the dependencies of a package and also some
5240additional packages that are not build-time or runtime dependencies, but
5241are useful when developing nonetheless. Because of this, the
5242@code{--ad-hoc} flag is positional. Packages appearing before
5243@code{--ad-hoc} are interpreted as packages whose dependencies will be
5244added to the environment. Packages appearing after are interpreted as
5245packages that will be added to the environment directly. For example,
5246the following command creates a Guix development environment that
5247additionally includes Git and strace:
5248
5249@example
5250guix environment guix --ad-hoc git strace
5251@end example
5252
f535dcbe
DT
5253Sometimes it is desirable to isolate the environment as much as
5254possible, for maximal purity and reproducibility. In particular, when
5255using Guix on a host distro that is not GuixSD, it is desirable to
5256prevent access to @file{/usr/bin} and other system-wide resources from
5257the development environment. For example, the following command spawns
5258a Guile REPL in a ``container'' where only the store and the current
5259working directory are mounted:
5260
5261@example
5262guix environment --ad-hoc --container guile -- guile
5263@end example
5264
0f252e26 5265@quotation Note
cfd35b4e 5266The @code{--container} option requires Linux-libre 3.19 or newer.
0f252e26
DT
5267@end quotation
5268
fe36d84e 5269The available options are summarized below.
372c4bbc
DT
5270
5271@table @code
5272@item --expression=@var{expr}
5273@itemx -e @var{expr}
c9c282ce
DT
5274Create an environment for the package or list of packages that
5275@var{expr} evaluates to.
372c4bbc 5276
fe36d84e
LC
5277For example, running:
5278
5279@example
5280guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
5281@end example
5282
5283starts a shell with the environment for this specific variant of the
5284PETSc package.
5285
c9c282ce
DT
5286Running:
5287
5288@example
5c2b2f00 5289guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
c9c282ce
DT
5290@end example
5291
5292starts a shell with all the GuixSD base packages available.
5293
779aa003
DT
5294The above commands only the use default output of the given packages.
5295To select other outputs, two element tuples can be specified:
5296
5297@example
5298guix environment --ad-hoc -e '(list (@ (gnu packages bash) bash) "include")'
5299@end example
5300
372c4bbc
DT
5301@item --load=@var{file}
5302@itemx -l @var{file}
c9c282ce
DT
5303Create an environment for the package or list of packages that the code
5304within @var{file} evaluates to.
372c4bbc 5305
fe36d84e
LC
5306As an example, @var{file} might contain a definition like this
5307(@pxref{Defining Packages}):
5308
5309@example
5310@verbatiminclude environment-gdb.scm
5311@end example
5312
a54bd6d7
DT
5313@item --ad-hoc
5314Include all specified packages in the resulting environment, as if an
5315@i{ad hoc} package were defined with them as inputs. This option is
5316useful for quickly creating an environment without having to write a
5317package expression to contain the desired inputs.
5318
5319For instance, the command:
5320
5321@example
1de2fe95 5322guix environment --ad-hoc guile guile-sdl -- guile
a54bd6d7
DT
5323@end example
5324
5325runs @command{guile} in an environment where Guile and Guile-SDL are
5326available.
5327
417c39f1 5328Note that this example implicitly asks for the default output of
f97c9175 5329@code{guile} and @code{guile-sdl}, but it is possible to ask for a
417c39f1
LC
5330specific output---e.g., @code{glib:bin} asks for the @code{bin} output
5331of @code{glib} (@pxref{Packages with Multiple Outputs}).
5332
cc90fbbf
DT
5333This option may be composed with the default behavior of @command{guix
5334environment}. Packages appearing before @code{--ad-hoc} are interpreted
5335as packages whose dependencies will be added to the environment, the
5336default behavior. Packages appearing after are interpreted as packages
5337that will be added to the environment directly.
5338
372c4bbc
DT
5339@item --pure
5340Unset existing environment variables when building the new environment.
5341This has the effect of creating an environment in which search paths
5342only contain package inputs.
5343
5344@item --search-paths
5345Display the environment variable definitions that make up the
5346environment.
ce367ef3
LC
5347
5348@item --system=@var{system}
5349@itemx -s @var{system}
5350Attempt to build for @var{system}---e.g., @code{i686-linux}.
f535dcbe
DT
5351
5352@item --container
5353@itemx -C
5354@cindex container
5355Run @var{command} within an isolated container. The current working
a01ad638
DT
5356directory outside the container is mapped inside the container.
5357Additionally, a dummy home directory is created that matches the current
5358user's home directory, and @file{/etc/passwd} is configured accordingly.
5359The spawned process runs as the current user outside the container, but
5360has root privileges in the context of the container.
f535dcbe
DT
5361
5362@item --network
5363@itemx -N
5364For containers, share the network namespace with the host system.
5365Containers created without this flag only have access to the loopback
5366device.
5367
5368@item --expose=@var{source}[=@var{target}]
5369For containers, expose the file system @var{source} from the host system
5370as the read-only file system @var{target} within the container. If
5371@var{target} is not specified, @var{source} is used as the target mount
5372point in the container.
5373
5374The example below spawns a Guile REPL in a container in which the user's
5375home directory is accessible read-only via the @file{/exchange}
5376directory:
5377
5378@example
5379guix environment --container --expose=$HOME=/exchange guile -- guile
5380@end example
5381
5c2b2f00 5382@item --share=@var{source}[=@var{target}]
f535dcbe
DT
5383For containers, share the file system @var{source} from the host system
5384as the writable file system @var{target} within the container. If
5385@var{target} is not specified, @var{source} is used as the target mount
5386point in the container.
5387
5388The example below spawns a Guile REPL in a container in which the user's
5389home directory is accessible for both reading and writing via the
5390@file{/exchange} directory:
5391
5392@example
5393guix environment --container --share=$HOME=/exchange guile -- guile
5394@end example
372c4bbc
DT
5395@end table
5396
5397It also supports all of the common build options that @command{guix
ccd7158d 5398build} supports (@pxref{Common Build Options}).
372c4bbc 5399
aff8ce7c
DT
5400@node Invoking guix publish
5401@section Invoking @command{guix publish}
5402
5403The purpose of @command{guix publish} is to enable users to easily share
f97c9175 5404their store with others, who can then use it as a substitute server
8ce229fc
LC
5405(@pxref{Substitutes}).
5406
5407When @command{guix publish} runs, it spawns an HTTP server which allows
5408anyone with network access to obtain substitutes from it. This means
5409that any machine running Guix can also act as if it were a build farm,
5410since the HTTP interface is compatible with Hydra, the software behind
5411the @code{hydra.gnu.org} build farm.
aff8ce7c
DT
5412
5413For security, each substitute is signed, allowing recipients to check
5414their authenticity and integrity (@pxref{Substitutes}). Because
f97c9175 5415@command{guix publish} uses the signing key of the system, which is only
5463fe51
LC
5416readable by the system administrator, it must be started as root; the
5417@code{--user} option makes it drop root privileges early on.
aff8ce7c 5418
b18812b6
LC
5419The signing key pair must be generated before @command{guix publish} is
5420launched, using @command{guix archive --generate-key} (@pxref{Invoking
5421guix archive}).
5422
aff8ce7c
DT
5423The general syntax is:
5424
5425@example
5426guix publish @var{options}@dots{}
5427@end example
5428
5429Running @command{guix publish} without any additional arguments will
5430spawn an HTTP server on port 8080:
5431
5432@example
5433guix publish
5434@end example
5435
5436Once a publishing server has been authorized (@pxref{Invoking guix
5437archive}), the daemon may download substitutes from it:
5438
5439@example
5440guix-daemon --substitute-urls=http://example.org:8080
5441@end example
5442
5443The following options are available:
5444
5445@table @code
5446@item --port=@var{port}
5447@itemx -p @var{port}
5448Listen for HTTP requests on @var{port}.
5449
9e2292ef
LC
5450@item --listen=@var{host}
5451Listen on the network interface for @var{host}. The default is to
5452accept connections from any interface.
5453
5463fe51
LC
5454@item --user=@var{user}
5455@itemx -u @var{user}
5456Change privileges to @var{user} as soon as possible---i.e., once the
5457server socket is open and the signing key has been read.
5458
aff8ce7c
DT
5459@item --repl[=@var{port}]
5460@itemx -r [@var{port}]
5461Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8ce229fc
LC
5462Reference Manual}) on @var{port} (37146 by default). This is used
5463primarily for debugging a running @command{guix publish} server.
aff8ce7c
DT
5464@end table
5465
1c52181f
LC
5466Enabling @command{guix publish} on a GuixSD system is a one-liner: just
5467add a call to @code{guix-publish-service} in the @code{services} field
5468of the @code{operating-system} declaration (@pxref{guix-publish-service,
5469@code{guix-publish-service}}).
5470
d23c20f1
LC
5471
5472@node Invoking guix challenge
5473@section Invoking @command{guix challenge}
5474
5475@cindex reproducible builds
5476@cindex verifiable builds
5477
5478Do the binaries provided by this server really correspond to the source
f97c9175 5479code it claims to build? Is a package build process deterministic?
d23c20f1
LC
5480These are the questions the @command{guix challenge} command attempts to
5481answer.
5482
5483The former is obviously an important question: Before using a substitute
f97c9175 5484server (@pxref{Substitutes}), one had better @emph{verify} that it
d23c20f1
LC
5485provides the right binaries, and thus @emph{challenge} it. The latter
5486is what enables the former: If package builds are deterministic, then
5487independent builds of the package should yield the exact same result,
5488bit for bit; if a server provides a binary different from the one
5489obtained locally, it may be either corrupt or malicious.
5490
5491We know that the hash that shows up in @file{/gnu/store} file names is
5492the hash of all the inputs of the process that built the file or
5493directory---compilers, libraries, build scripts,
5494etc. (@pxref{Introduction}). Assuming deterministic build processes,
5495one store file name should map to exactly one build output.
5496@command{guix challenge} checks whether there is, indeed, a single
5497mapping by comparing the build outputs of several independent builds of
5498any given store item.
5499
f97c9175 5500The command output looks like this:
d23c20f1
LC
5501
5502@smallexample
5503$ guix challenge --substitute-urls="http://hydra.gnu.org http://guix.example.org"
5504updating list of substitutes from 'http://hydra.gnu.org'... 100.0%
5505updating list of substitutes from 'http://guix.example.org'... 100.0%
5506/gnu/store/@dots{}-openssl-1.0.2d contents differ:
5507 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5508 http://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5509 http://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
5510/gnu/store/@dots{}-git-2.5.0 contents differ:
5511 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
5512 http://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
5513 http://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
5514/gnu/store/@dots{}-pius-2.1.1 contents differ:
5515 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5516 http://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5517 http://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
5518@end smallexample
5519
5520@noindent
5521In this example, @command{guix challenge} first scans the store to
5522determine the set of locally-built derivations---as opposed to store
5523items that were downloaded from a substitute server---and then queries
5524all the substitute servers. It then reports those store items for which
5525the servers obtained a result different from the local build.
5526
5527@cindex non-determinism, in package builds
5528As an example, @code{guix.example.org} always gets a different answer.
5529Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
5530case of Git. This might indicate that the build process of Git is
5531non-deterministic, meaning that its output varies as a function of
5532various things that Guix does not fully control, in spite of building
5533packages in isolated environments (@pxref{Features}). Most common
5534sources of non-determinism include the addition of timestamps in build
5535results, the inclusion of random numbers, and directory listings sorted
5536by inode number. See @uref{http://reproducible.debian.net/howto/}, for
5537more information.
5538
f97c9175 5539To find out what is wrong with this Git binary, we can do something along
d23c20f1
LC
5540these lines (@pxref{Invoking guix archive}):
5541
5542@example
5543$ wget -q -O - http://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
5544 | guix archive -x /tmp/git
043f4698 5545$ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
d23c20f1
LC
5546@end example
5547
5548This command shows the difference between the files resulting from the
5549local build, and the files resulting from the build on
5550@code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
5551diffutils, Comparing and Merging Files}). The @command{diff} command
5552works great for text files. When binary files differ, a better option
5553is @uref{http://diffoscope.org/, Diffoscope}, a tool that helps
5554visualize differences for all kinds of files.
5555
f97c9175 5556Once you have done that work, you can tell whether the differences are due
d23c20f1
LC
5557to a non-deterministic build process or to a malicious server. We try
5558hard to remove sources of non-determinism in packages to make it easier
f97c9175
AE
5559to verify substitutes, but of course, this is a process that
5560involves not just Guix, but a large part of the free software community.
d23c20f1
LC
5561In the meantime, @command{guix challenge} is one tool to help address
5562the problem.
5563
5564If you are writing packages for Guix, you are encouraged to check
5565whether @code{hydra.gnu.org} and other substitute servers obtain the
5566same build result as you did with:
5567
5568@example
5569$ guix challenge @var{package}
5570@end example
5571
5572@noindent
f97c9175 5573where @var{package} is a package specification such as
d23c20f1
LC
5574@code{guile-2.0} or @code{glibc:debug}.
5575
5576The general syntax is:
5577
5578@example
5579guix challenge @var{options} [@var{packages}@dots{}]
5580@end example
5581
5582The one option that matters is:
5583
5584@table @code
5585
5586@item --substitute-urls=@var{urls}
5587Consider @var{urls} the whitespace-separated list of substitute source
5588URLs to compare to.
5589
5590@end table
5591
5592
32efa254
DT
5593@node Invoking guix container
5594@section Invoking @command{guix container}
5595@cindex container
5596
5597@quotation Note
5598As of version @value{VERSION}, this tool is experimental. The interface
5599is subject to radical change in the future.
5600@end quotation
5601
5602The purpose of @command{guix container} is to manipulate processes
5603running within an isolated environment, commonly known as a
46c36586 5604``container'', typically created by the @command{guix environment}
32efa254
DT
5605(@pxref{Invoking guix environment}) and @command{guix system container}
5606(@pxref{Invoking guix system}) commands.
5607
5608The general syntax is:
5609
5610@example
5611guix container @var{action} @var{options}@dots{}
5612@end example
5613
5614@var{action} specifies the operation to perform with a container, and
5615@var{options} specifies the context-specific arguments for the action.
5616
5617The following actions are available:
5618
5619@table @code
5620@item exec
5621Execute a command within the context of a running container.
5622
5623The syntax is:
5624
5625@example
5626guix container exec @var{pid} @var{program} @var{arguments}@dots{}
5627@end example
5628
5629@var{pid} specifies the process ID of the running container.
f97c9175
AE
5630@var{program} specifies an executable file name within the root file
5631system of the container. @var{arguments} are the additional options that
5632will be passed to @var{program}.
32efa254
DT
5633
5634The following command launches an interactive login shell inside a
5635GuixSD container, started by @command{guix system container}, and whose
5636process ID is 9001:
5637
5638@example
5639guix container exec 9001 /run/current-system/profile/bin/bash --login
5640@end example
5641
5642Note that the @var{pid} cannot be the parent process of a container. It
f97c9175 5643must be PID 1 of the container or one of its child processes.
32efa254
DT
5644
5645@end table
5646
a1ba8475
LC
5647@c *********************************************************************
5648@node GNU Distribution
5649@chapter GNU Distribution
5650
3ca2731c 5651@cindex Guix System Distribution
4705641f 5652@cindex GuixSD
3ca2731c
LC
5653Guix comes with a distribution of the GNU system consisting entirely of
5654free software@footnote{The term ``free'' here refers to the
a1ba8475 5655@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 5656users of that software}.}. The
35ed9306
LC
5657distribution can be installed on its own (@pxref{System Installation}),
5658but it is also possible to install Guix as a package manager on top of
5659an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c 5660between the two, we refer to the standalone distribution as the Guix
4705641f 5661System Distribution, or GuixSD.
35ed9306
LC
5662
5663The distribution provides core GNU packages such as GNU libc, GCC, and
5664Binutils, as well as many GNU and non-GNU applications. The complete
5665list of available packages can be browsed
093ae1be 5666@url{http://www.gnu.org/software/guix/packages,on-line} or by
d03bb653 5667running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
5668
5669@example
e49951eb 5670guix package --list-available
a1ba8475
LC
5671@end example
5672
f97c9175 5673Our goal is to provide a practical 100% free software distribution of
401c53c4
LC
5674Linux-based and other variants of GNU, with a focus on the promotion and
5675tight integration of GNU components, and an emphasis on programs and
5676tools that help users exert that freedom.
5677
3ca2731c 5678Packages are currently available on the following platforms:
c320011d
LC
5679
5680@table @code
5681
5682@item x86_64-linux
5683Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
5684
5685@item i686-linux
5686Intel 32-bit architecture (IA32), Linux-Libre kernel;
5687
aa1e1947 5688@item armhf-linux
aa725117 5689ARMv7-A architecture with hard float, Thumb-2 and NEON,
f97c9175
AE
5690using the EABI hard-float application binary interface (ABI),
5691and Linux-Libre kernel.
aa1e1947 5692
c320011d
LC
5693@item mips64el-linux
5694little-endian 64-bit MIPS processors, specifically the Loongson series,
f97c9175 5695n32 ABI, and Linux-Libre kernel.
c320011d
LC
5696
5697@end table
5698
4705641f 5699GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
3ca2731c 5700
c320011d
LC
5701@noindent
5702For information on porting to other architectures or kernels,
f97c9175 5703@pxref{Porting}.
c320011d 5704
401c53c4 5705@menu
5af6de3e 5706* System Installation:: Installing the whole operating system.
35ed9306 5707* System Configuration:: Configuring the operating system.
91ef73d4 5708* Installing Debugging Files:: Feeding the debugger.
05962f29 5709* Security Updates:: Deploying security fixes quickly.
401c53c4 5710* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 5711* Packaging Guidelines:: Growing the distribution.
401c53c4 5712* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 5713* Porting:: Targeting another platform or kernel.
401c53c4
LC
5714@end menu
5715
5716Building this distribution is a cooperative effort, and you are invited
081145cf 5717to join! @xref{Contributing}, for information about how you can help.
401c53c4 5718
5af6de3e
LC
5719@node System Installation
5720@section System Installation
5721
3ca2731c
LC
5722@cindex Guix System Distribution
5723This section explains how to install the Guix System Distribution
5724on a machine. The Guix package manager can
35ed9306
LC
5725also be installed on top of a running GNU/Linux system,
5726@pxref{Installation}.
5af6de3e
LC
5727
5728@ifinfo
5729@c This paragraph is for people reading this from tty2 of the
5730@c installation image.
1068f26b 5731You are reading this documentation with an Info reader. For details on
5af6de3e 5732how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
de341e7c
LC
5733link that follows: @pxref{Top, Info reader,, info-stnd, Stand-alone GNU
5734Info}. Hit @kbd{l} afterwards to come back here.
5af6de3e
LC
5735@end ifinfo
5736
dedb8d5e 5737@menu
e3009f60
LC
5738* Limitations:: What you can expect.
5739* Hardware Considerations:: Supported hardware.
5740* USB Stick Installation:: Preparing the installation medium.
5741* Preparing for Installation:: Networking, partitioning, etc.
5742* Proceeding with the Installation:: The real thing.
5743* Building the Installation Image:: How this comes to be.
dedb8d5e
LC
5744@end menu
5745
5746@node Limitations
8aaaae38
LC
5747@subsection Limitations
5748
4705641f 5749As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
3ca2731c 5750not production-ready. It may contain bugs and lack important
8aaaae38
LC
5751features. Thus, if you are looking for a stable production system that
5752respects your freedom as a computer user, a good solution at this point
5753is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
f97c9175 5754the more established GNU/Linux distributions}. We hope you can soon switch
4705641f 5755to the GuixSD without fear, of course. In the meantime, you can
8aaaae38
LC
5756also keep using your distribution and try out the package manager on top
5757of it (@pxref{Installation}).
5758
5759Before you proceed with the installation, be aware of the following
5760noteworthy limitations applicable to version @value{VERSION}:
5761
5762@itemize
5763@item
5764The installation process does not include a graphical user interface and
5765requires familiarity with GNU/Linux (see the following subsections to
5766get a feel of what that means.)
5767
8aaaae38 5768@item
dbcb0ab1 5769Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
5770
5771@item
5772Few system services are currently supported out-of-the-box
5773(@pxref{Services}).
5774
5775@item
dedb8d5e 5776More than 3,000 packages are available, but you may
8aaaae38 5777occasionally find that a useful package is missing.
5fe01c2d
LC
5778
5779@item
5780GNOME, Xfce, and Enlightenment are available (@pxref{Desktop Services}),
5781as well as a number of X11 window managers. However, some graphical
5782applications may be missing, as well as KDE.
8aaaae38
LC
5783@end itemize
5784
f97c9175
AE
5785You have been warned! But more than a disclaimer, this is an invitation
5786to report issues (and success stories!), and to join us in improving it.
8aaaae38 5787@xref{Contributing}, for more info.
5af6de3e 5788
e3009f60
LC
5789
5790@node Hardware Considerations
5791@subsection Hardware Considerations
5792
5793@cindex hardware support on GuixSD
5794GNU@tie{}GuixSD focuses on respecting the user's computing freedom. It
5795builds around the kernel Linux-libre, which means that only hardware for
5796which free software drivers and firmware exists is supported. Nowadays,
5797a wide range of off-the-shelf hardware is supported on
5798GNU/Linux-libre---from keyboards to graphics cards to scanners and
5799Ethernet controllers. Unfortunately, there are still areas where
5800hardware vendors deny users control over their own computing, and such
5801hardware is not supported on GuixSD.
5802
5803@cindex WiFi, hardware support
5804One of the main areas where free drivers or firmware is lacking is WiFi
5805devices. WiFi devices known to work include those using Atheros chips
5806(AR9271 and AR7010), which corresponds to the @code{ath9k} Linux-libre
5807driver, and for which free firmware exists and is available
5808out-of-the-box on GuixSD, as part of @var{%base-firmware}
5809(@pxref{operating-system Reference, @code{firmware}}).
5810
5811@cindex RYF, Respects Your Freedom
5812The @uref{https://www.fsf.org/, Free Software Foundation} runs
5813@uref{https://www.fsf.org/ryf, @dfn{Respect Your Freedom}} (RYF), a
5814certification program for hardware products that respect your freedom
5815and your privacy and ensure that you have control over your device. We
5816encourage you to check the list of RYF-certified hardware.
5817
5818Another useful resource is the @uref{https://www.h-node.org/, H-Node}
5819web site. It contains a catalog of hardware devices with information
5820about their support in GNU/Linux.
5821
5822
dedb8d5e 5823@node USB Stick Installation
5af6de3e
LC
5824@subsection USB Stick Installation
5825
5826An installation image for USB sticks can be downloaded from
4705641f 5827@indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
5828where @var{system} is one of:
5829
5830@table @code
5831@item x86_64-linux
5832for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
5833
5834@item i686-linux
5835for a 32-bit GNU/Linux system on Intel-compatible CPUs.
5836@end table
5837
5838This image contains a single partition with the tools necessary for an
5839installation. It is meant to be copied @emph{as is} to a large-enough
5840USB stick.
5841
5842To copy the image to a USB stick, follow these steps:
5843
5844@enumerate
5845@item
5846Decompress the image using the @command{xz} command:
5847
5848@example
4705641f 5849xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
5850@end example
5851
5852@item
f97c9175
AE
5853Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
5854its device name. Assuming that the USB stick is known as @file{/dev/sdX},
5af6de3e
LC
5855copy the image with:
5856
5857@example
4705641f 5858dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
5859@end example
5860
5861Access to @file{/dev/sdX} usually requires root privileges.
5862@end enumerate
5863
5864Once this is done, you should be able to reboot the system and boot from
5865the USB stick. The latter usually requires you to get in the BIOS' boot
5866menu, where you can choose to boot from the USB stick.
5867
dedb8d5e 5868@node Preparing for Installation
5af6de3e
LC
5869@subsection Preparing for Installation
5870
5871Once you have successfully booted the image on the USB stick, you should
5872end up with a root prompt. Several console TTYs are configured and can
5873be used to run commands as root. TTY2 shows this documentation,
de341e7c
LC
5874browsable using the Info reader commands (@pxref{Top,,, info-stnd,
5875Stand-alone GNU Info}). The installation system runs the GPM mouse
5876daemon, which allows you to select text with the left mouse button and
5877to paste it with the middle button.
5af6de3e 5878
ff925d37
LC
5879@quotation Note
5880Installation requires access to the Internet so that any missing
5881dependencies of your system configuration can be downloaded. See the
5882``Networking'' section below.
5883@end quotation
5884
dedb8d5e 5885@subsubsection Keyboard Layout
5af6de3e 5886
dedb8d5e
LC
5887@cindex keyboard layout
5888The installation image uses the US qwerty keyboard layout. If you want
5889to change it, you can use the @command{loadkeys} command. For example,
5890the following command selects the Dvorak keyboard layout:
5af6de3e 5891
dedb8d5e
LC
5892@example
5893loadkeys dvorak
5894@end example
5895
5896See the files under @file{/run/current-system/profile/share/keymaps} for
5897a list of available keyboard layouts. Run @command{man loadkeys} for
5898more information.
5899
5900@subsubsection Networking
5901
5902Run the following command see what your network interfaces are called:
235cba85
LC
5903
5904@example
dedb8d5e 5905ifconfig -a
235cba85
LC
5906@end example
5907
95c559c1 5908@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
dedb8d5e
LC
5909Wired interfaces have a name starting with @samp{e}; for example, the
5910interface corresponding to the first on-board Ethernet controller is
5911called @samp{eno1}. Wireless interfaces have a name starting with
5912@samp{w}, like @samp{w1p2s0}.
5913
5914@table @asis
5915@item Wired connection
5916To configure a wired network run the following command, substituting
5917@var{interface} with the name of the wired interface you want to use.
5918
5919@example
5920ifconfig @var{interface} up
5921@end example
5922
5923@item Wireless connection
5924To configure wireless networking, you can create a configuration file
5925for the @command{wpa_supplicant} configuration tool (its location is not
5926important) using one of the available text editors such as
5927@command{zile}:
5928
5929@example
5930zile wpa_supplicant.conf
5931@end example
5932
5933As an example, the following stanza can go to this file and will work
5934for many wireless networks, provided you give the actual SSID and
5935passphrase for the network you are connecting to:
5936
5937@example
5938network=@{
5939 ssid=@var{my-ssid}
5940 key_mgmt=WPA-PSK
5941 psk="the network's secret passphrase"
5942@}
5943@end example
5944
5945Start the wireless service and run it in the background with the
5946following command (substitute @var{interface} with the name of the
5947network interface you want to use):
5948
5949@example
5950wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
5951@end example
5952
641d0518 5953Run @command{man wpa_supplicant} for more information.
dedb8d5e
LC
5954@end table
5955
5956At this point, you need to acquire an IP address. On a network where IP
5957addresses are automatically assigned @i{via} DHCP, you can run:
5958
5959@example
5960dhclient @var{interface}
5961@end example
5af6de3e 5962
dedb8d5e
LC
5963Try to ping a server to see if networking is up and running:
5964
5965@example
5966ping -c 3 gnu.org
5967@end example
5af6de3e
LC
5968
5969Setting up network access is almost always a requirement because the
5970image does not contain all the software and tools that may be needed.
5971
dedb8d5e
LC
5972@subsubsection Disk Partitioning
5973
5974Unless this has already been done, the next step is to partition, and
5975then format the target partition(s).
5976
5977The installation image includes several partitioning tools, including
5978Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
5979@command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
5980the partition layout you want:
5981
5982@example
5983cfdisk
5984@end example
5985
5986Once you are done partitioning the target hard disk drive, you have to
5987create a file system on the relevant partition(s)@footnote{Currently
5988GuixSD pretty much assumes an ext4 file system. In particular, code
5989that reads partition UUIDs and labels only works with ext4. This will
5990be fixed in the future.}.
5af6de3e 5991
7ab44369
LC
5992Preferably, assign partitions a label so that you can easily and
5993reliably refer to them in @code{file-system} declarations (@pxref{File
5994Systems}). This is typically done using the @code{-L} option of
dedb8d5e
LC
5995@command{mkfs.ext4} and related commands. So, assuming the target root
5996partition lives at @file{/dev/sda1}, a file system with the label
5997@code{my-root} can be created with:
7ab44369 5998
dedb8d5e
LC
5999@example
6000mkfs.ext4 -L my-root /dev/sda1
6001@end example
dd816355 6002
316d65be
LC
6003@c FIXME: Uncomment this once GRUB fully supports encrypted roots.
6004@c A typical command sequence may be:
6005@c
6006@c @example
6007@c # fdisk /dev/sdX
6008@c @dots{} Create partitions etc.@dots{}
6009@c # cryptsetup luksFormat /dev/sdX1
6010@c # cryptsetup open --type luks /dev/sdX1 my-partition
6011@c # mkfs.ext4 -L my-root /dev/mapper/my-partition
6012@c @end example
6d6e6281 6013
dedb8d5e
LC
6014In addition to e2fsprogs, the suite of tools to manipulate
6015ext2/ext3/ext4 file systems, the installation image includes
6016Cryptsetup/LUKS for disk encryption.
5af6de3e 6017
dedb8d5e
LC
6018Once that is done, mount the target root partition under @file{/mnt}
6019with a command like (again, assuming @file{/dev/sda1} is the root
6020partition):
83a17b62 6021
dedb8d5e
LC
6022@example
6023mount /dev/sda1 /mnt
6024@end example
83a17b62 6025
dedb8d5e
LC
6026@node Proceeding with the Installation
6027@subsection Proceeding with the Installation
83a17b62 6028
dedb8d5e
LC
6029With the target partitions ready and the target root mounted on
6030@file{/mnt}, we're ready to go. First, run:
5af6de3e 6031
dedb8d5e
LC
6032@example
6033herd start cow-store /mnt
6034@end example
5af6de3e 6035
b397c0d5
LC
6036This makes @file{/gnu/store} copy-on-write, such that packages added to it
6037during the installation phase are written to the target disk on @file{/mnt}
6038rather than kept in memory. This is necessary because the first phase of
6039the @command{guix system init} command (see below) entails downloads or
6040builds to @file{/gnu/store} which, initially, is an in-memory file system.
5af6de3e 6041
dedb8d5e 6042Next, you have to edit a file and
5af6de3e
LC
6043provide the declaration of the operating system to be installed. To
6044that end, the installation system comes with two text editors: GNU nano
6045(@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
6046It is better to store that file on the target root file system, say, as
6047@file{/mnt/etc/config.scm}.
6048
dedb8d5e
LC
6049@xref{Using the Configuration System}, for an overview of the
6050configuration file. The example configurations discussed in that
6051section are available under @file{/etc/configuration} in the
6052installation image. Thus, to get started with a system configuration
6053providing a graphical display server (a ``desktop'' system), you can run
6054something along these lines:
6055
6056@example
6057# mkdir /mnt/etc
6058# cp /etc/configuration/desktop.scm /mnt/etc/config.scm
6059# zile /mnt/etc/config.scm
6060@end example
6061
6062You should pay attention to what your configuration file contains, and
6063in particular:
6064
6065@itemize
6066@item
6067Make sure the @code{grub-configuration} form refers to the device you
6068want to install GRUB on.
6069
6070@item
6071Be sure that your partition labels match the value of their respective
6072@code{device} fields in your @code{file-system} configuration, assuming
6073your @code{file-system} configuration sets the value of @code{title} to
6074@code{'label}.
6075@end itemize
5af6de3e 6076
dd51caac
LC
6077Once you are done preparing the configuration file, the new system must
6078be initialized (remember that the target root file system is mounted
6079under @file{/mnt}):
5af6de3e
LC
6080
6081@example
6082guix system init /mnt/etc/config.scm /mnt
6083@end example
6084
6085@noindent
dedb8d5e 6086This copies all the necessary files and installs GRUB on
5af6de3e 6087@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 6088more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
6089downloads or builds of missing packages, which can take some time.
6090
1bd4e6db
LC
6091Once that command has completed---and hopefully succeeded!---you can run
6092@command{reboot} and boot into the new system. The @code{root} password
6093in the new system is initially empty; other users' passwords need to be
6094initialized by running the @command{passwd} command as @code{root},
6095unless your configuration specifies otherwise
6096(@pxref{user-account-password, user account passwords}).
6097
6098Join us on @code{#guix} on the Freenode IRC network or on
5af6de3e
LC
6099@file{guix-devel@@gnu.org} to share your experience---good or not so
6100good.
6101
dedb8d5e 6102@node Building the Installation Image
5af6de3e
LC
6103@subsection Building the Installation Image
6104
6105The installation image described above was built using the @command{guix
6106system} command, specifically:
6107
622b2304 6108@c FIXME: 1G is too much; see <http://bugs.gnu.org/23077>.
5af6de3e 6109@example
622b2304 6110guix system disk-image --image-size=1G gnu/system/install.scm
5af6de3e
LC
6111@end example
6112
6e6a0401
AE
6113Have a look at @file{gnu/system/install.scm} in the source tree,
6114and see also @ref{Invoking guix system} for more information
5af6de3e
LC
6115about the installation image.
6116
cf4a9129
LC
6117@node System Configuration
6118@section System Configuration
b208a005 6119
cf4a9129 6120@cindex system configuration
3ca2731c 6121The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
6122mechanism. By that we mean that all aspects of the global system
6123configuration---such as the available system services, timezone and
6124locale settings, user accounts---are declared in a single place. Such
6125a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 6126
cf4a9129
LC
6127One of the advantages of putting all the system configuration under the
6128control of Guix is that it supports transactional system upgrades, and
1068f26b 6129makes it possible to roll back to a previous system instantiation,
cf4a9129 6130should something go wrong with the new one (@pxref{Features}). Another
1068f26b 6131advantage is that it makes it easy to replicate the exact same configuration
cf4a9129
LC
6132across different machines, or at different points in time, without
6133having to resort to additional administration tools layered on top of
1068f26b 6134the own tools of the system.
cf4a9129 6135@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 6136
cf4a9129
LC
6137This section describes this mechanism. First we focus on the system
6138administrator's viewpoint---explaining how the system is configured and
6139instantiated. Then we show how this mechanism can be extended, for
6140instance to support new system services.
91ef73d4 6141
cf4a9129
LC
6142@menu
6143* Using the Configuration System:: Customizing your GNU system.
7313a52e 6144* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 6145* File Systems:: Configuring file system mounts.
510f9d86 6146* Mapped Devices:: Block device extra processing.
cf4a9129 6147* User Accounts:: Specifying user accounts.
598e19dc 6148* Locales:: Language and cultural convention settings.
cf4a9129 6149* Services:: Specifying system services.
0ae8c15a 6150* Setuid Programs:: Programs running with root privileges.
efb5e833 6151* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 6152* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 6153* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 6154* GRUB Configuration:: Configuring the boot loader.
cf4a9129 6155* Invoking guix system:: Instantiating a system configuration.
97d76250 6156* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
cf4a9129
LC
6157* Defining Services:: Adding new service definitions.
6158@end menu
91ef73d4 6159
cf4a9129
LC
6160@node Using the Configuration System
6161@subsection Using the Configuration System
64d76fa6 6162
cf4a9129
LC
6163The operating system is configured by providing an
6164@code{operating-system} declaration in a file that can then be passed to
6165the @command{guix system} command (@pxref{Invoking guix system}). A
6166simple setup, with the default system services, the default Linux-Libre
6167kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 6168
cf4a9129
LC
6169@findex operating-system
6170@lisp
dd51caac 6171@include os-config-bare-bones.texi
cf4a9129 6172@end lisp
401c53c4 6173
cf4a9129
LC
6174This example should be self-describing. Some of the fields defined
6175above, such as @code{host-name} and @code{bootloader}, are mandatory.
6176Others, such as @code{packages} and @code{services}, can be omitted, in
6177which case they get a default value.
e7f34eb0 6178
5d94ac51
LC
6179Below we discuss the effect of some of the most important fields
6180(@pxref{operating-system Reference}, for details about all the available
6181fields), and how to @dfn{instantiate} the operating system using
6182@command{guix system}.
6183
6184@unnumberedsubsubsec Globally-Visible Packages
6185
cf4a9129 6186@vindex %base-packages
5d94ac51
LC
6187The @code{packages} field lists packages that will be globally visible
6188on the system, for all user accounts---i.e., in every user's @code{PATH}
6189environment variable---in addition to the per-user profiles
6190(@pxref{Invoking guix package}). The @var{%base-packages} variable
6191provides all the tools one would expect for basic user and administrator
6192tasks---including the GNU Core Utilities, the GNU Networking Utilities,
6193the GNU Zile lightweight text editor, @command{find}, @command{grep},
6194etc. The example above adds tcpdump to those, taken from the @code{(gnu
6195packages admin)} module (@pxref{Package Modules}).
e7f34eb0 6196
f6c9fb1b
LC
6197@findex specification->package
6198Referring to packages by variable name, like @var{tcpdump} above, has
6199the advantage of being unambiguous; it also allows typos and such to be
6200diagnosed right away as ``unbound variables''. The downside is that one
6201needs to know which module defines which package, and to augment the
6202@code{use-package-modules} line accordingly. To avoid that, one can use
6203the @code{specification->package} procedure of the @code{(gnu packages)}
6204module, which returns the best package for a given name or name and
6205version:
6206
6207@lisp
6208(use-modules (gnu packages))
6209
6210(operating-system
6211 ;; ...
6212 (packages (append (map specification->package
6213 '("tcpdump" "htop" "gnupg-2.0"))
6214 %base-packages)))
6215@end lisp
6216
5d94ac51
LC
6217@unnumberedsubsubsec System Services
6218
cf4a9129
LC
6219@vindex %base-services
6220The @code{services} field lists @dfn{system services} to be made
6221available when the system starts (@pxref{Services}).
6222The @code{operating-system} declaration above specifies that, in
6223addition to the basic services, we want the @command{lshd} secure shell
cd6f6c22
LC
6224daemon listening on port 2222 (@pxref{Networking Services,
6225@code{lsh-service}}). Under the hood,
cf4a9129
LC
6226@code{lsh-service} arranges so that @code{lshd} is started with the
6227right command-line options, possibly with supporting configuration files
cd6f6c22
LC
6228generated as needed (@pxref{Defining Services}).
6229
6230@cindex customization, of services
6231@findex modify-services
6232Occasionally, instead of using the base services as is, you will want to
4d343a14
CM
6233customize them. To do this, use @code{modify-services} (@pxref{Service
6234Reference, @code{modify-services}}) to modify the list.
6235
6236For example, suppose you want to modify @code{guix-daemon} and Mingetty
6237(the console log-in) in the @var{%base-services} list (@pxref{Base
6238Services, @code{%base-services}}). To do that, you can write the
6239following in your operating system declaration:
cd6f6c22
LC
6240
6241@lisp
4d343a14
CM
6242(define %my-services
6243 ;; My very own list of services.
6244 (modify-services %base-services
6245 (guix-service-type config =>
6246 (guix-configuration
6247 (inherit config)
6248 (use-substitutes? #f)
6249 (extra-options '("--gc-keep-derivations"))))
6250 (mingetty-service-type config =>
6251 (mingetty-configuration
6252 (inherit config)
6253 (motd (plain-file "motd" "Howdy!"))))))
6254
6255(operating-system
6256 ;; @dots{}
6257 (services %my-services))
cd6f6c22
LC
6258@end lisp
6259
4d343a14
CM
6260This changes the configuration---i.e., the service parameters---of the
6261@code{guix-service-type} instance, and that of all the
6262@code{mingetty-service-type} instances in the @var{%base-services} list.
6263Observe how this is accomplished: first, we arrange for the original
6264configuration to be bound to the identifier @code{config} in the
6265@var{body}, and then we write the @var{body} so that it evaluates to the
6266desired configuration. In particular, notice how we use @code{inherit}
6267to create a new configuration which has the same values as the old
6268configuration, but with a few modifications.
a1ba8475 6269
dd51caac 6270The configuration for a typical ``desktop'' usage, with the X11 display
d038b674
LC
6271server, GNOME and Xfce (users can choose which of these desktop
6272environments to use at the log-in screen by pressing @kbd{F1}), network
6273management, power management, and more, would look like this:
dd51caac
LC
6274
6275@lisp
6276@include os-config-desktop.texi
6277@end lisp
6278
d038b674
LC
6279A graphical environment with a choice of lightweight window managers
6280instead of full-blown desktop environments would look like this:
6281
6282@lisp
6283@include os-config-lightweight-desktop.texi
6284@end lisp
6285
dd51caac 6286@xref{Desktop Services}, for the exact list of services provided by
efb5e833
LC
6287@var{%desktop-services}. @xref{X.509 Certificates}, for background
6288information about the @code{nss-certs} package that is used here.
dd51caac 6289
5d94ac51
LC
6290Again, @var{%desktop-services} is just a list of service objects. If
6291you want to remove services from there, you can do so using the
6292procedures for list filtering (@pxref{SRFI-1 Filtering and
6293Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
6294following expression returns a list that contains all the services in
6295@var{%desktop-services} minus the Avahi service:
6296
6297@example
6298(remove (lambda (service)
6299 (eq? (service-kind service) avahi-service-type))
6300 %desktop-services)
6301@end example
6302
6303@unnumberedsubsubsec Instantiating the System
6304
6305Assuming the @code{operating-system} declaration
6306is stored in the @file{my-system-config.scm}
cf4a9129
LC
6307file, the @command{guix system reconfigure my-system-config.scm} command
6308instantiates that configuration, and makes it the default GRUB boot
65797bff
LC
6309entry (@pxref{Invoking guix system}).
6310
1068f26b 6311The normal way to change the system configuration is by updating this
65797bff
LC
6312file and re-running @command{guix system reconfigure}. One should never
6313have to touch files in @command{/etc} or to run commands that modify the
6314system state such as @command{useradd} or @command{grub-install}. In
6315fact, you must avoid that since that would not only void your warranty
6316but also prevent you from rolling back to previous versions of your
6317system, should you ever need to.
6318
6319@cindex roll-back, of the operating system
6320Speaking of roll-back, each time you run @command{guix system
6321reconfigure}, a new @dfn{generation} of the system is created---without
6322modifying or deleting previous generations. Old system generations get
6323an entry in the GRUB boot menu, allowing you to boot them in case
6324something went wrong with the latest generation. Reassuring, no? The
6325@command{guix system list-generations} command lists the system
6326generations available on disk.
b81e1947 6327
5d94ac51
LC
6328@unnumberedsubsubsec The Programming Interface
6329
cf4a9129
LC
6330At the Scheme level, the bulk of an @code{operating-system} declaration
6331is instantiated with the following monadic procedure (@pxref{The Store
6332Monad}):
b81e1947 6333
cf4a9129
LC
6334@deffn {Monadic Procedure} operating-system-derivation os
6335Return a derivation that builds @var{os}, an @code{operating-system}
6336object (@pxref{Derivations}).
b81e1947 6337
cf4a9129
LC
6338The output of the derivation is a single directory that refers to all
6339the packages, configuration files, and other supporting files needed to
6340instantiate @var{os}.
6341@end deffn
b81e1947 6342
5d94ac51
LC
6343This procedure is provided by the @code{(gnu system)} module. Along
6344with @code{(gnu services)} (@pxref{Services}), this module contains the
6345guts of GuixSD. Make sure to visit it!
6346
6347
7313a52e
LC
6348@node operating-system Reference
6349@subsection @code{operating-system} Reference
6350
6351This section summarizes all the options available in
6352@code{operating-system} declarations (@pxref{Using the Configuration
6353System}).
6354
6355@deftp {Data Type} operating-system
6356This is the data type representing an operating system configuration.
6357By that, we mean all the global system configuration, not per-user
6358configuration (@pxref{Using the Configuration System}).
6359
6360@table @asis
6361@item @code{kernel} (default: @var{linux-libre})
fbb25e56 6362The package object of the operating system kernel to use@footnote{Currently
7313a52e
LC
6363only the Linux-libre kernel is supported. In the future, it will be
6364possible to use the GNU@tie{}Hurd.}.
6365
ee2a6304
LC
6366@item @code{kernel-arguments} (default: @code{'()})
6367List of strings or gexps representing additional arguments to pass on
1068f26b 6368the command-line of the kernel---e.g., @code{("console=ttyS0")}.
ee2a6304 6369
7313a52e 6370@item @code{bootloader}
88faf933 6371The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
6372
6373@item @code{initrd} (default: @code{base-initrd})
6374A two-argument monadic procedure that returns an initial RAM disk for
6375the Linux kernel. @xref{Initial RAM Disk}.
6376
f34c56be
LC
6377@item @code{firmware} (default: @var{%base-firmware})
6378@cindex firmware
6379List of firmware packages loadable by the operating system kernel.
6380
6381The default includes firmware needed for Atheros-based WiFi devices
e3009f60
LC
6382(Linux-libre module @code{ath9k}). @xref{Hardware Considerations}, for
6383more info on supported hardware.
f34c56be 6384
7313a52e
LC
6385@item @code{host-name}
6386The host name.
6387
6388@item @code{hosts-file}
6389@cindex hosts file
24e02c28 6390A file-like object (@pxref{G-Expressions, file-like objects}) for use as
7313a52e 6391@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
24e02c28 6392Reference Manual}). The default is a file with entries for
7313a52e
LC
6393@code{localhost} and @var{host-name}.
6394
6395@item @code{mapped-devices} (default: @code{'()})
6396A list of mapped devices. @xref{Mapped Devices}.
6397
6398@item @code{file-systems}
6399A list of file systems. @xref{File Systems}.
6400
6401@item @code{swap-devices} (default: @code{'()})
6402@cindex swap devices
6403A list of strings identifying devices to be used for ``swap space''
6404(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
6405For example, @code{'("/dev/sda3")}.
6406
bf87f38a 6407@item @code{users} (default: @code{%base-user-accounts})
7313a52e
LC
6408@itemx @code{groups} (default: @var{%base-groups})
6409List of user accounts and groups. @xref{User Accounts}.
6410
6411@item @code{skeletons} (default: @code{(default-skeletons)})
6412A monadic list of pairs of target file name and files. These are the
6413files that will be used as skeletons as new accounts are created.
6414
6415For instance, a valid value may look like this:
6416
6417@example
6418(mlet %store-monad ((bashrc (text-file "bashrc" "\
6419 export PATH=$HOME/.guix-profile/bin")))
6420 (return `((".bashrc" ,bashrc))))
6421@end example
6422
6423@item @code{issue} (default: @var{%default-issue})
6424A string denoting the contents of the @file{/etc/issue} file, which is
1068f26b 6425displayed when users log in on a text console.
7313a52e
LC
6426
6427@item @code{packages} (default: @var{%base-packages})
6428The set of packages installed in the global profile, which is accessible
6429at @file{/run/current-system/profile}.
6430
1068f26b 6431The default set includes core utilities and it is good practice to
7313a52e
LC
6432install non-core utilities in user profiles (@pxref{Invoking guix
6433package}).
6434
6435@item @code{timezone}
6436A timezone identifying string---e.g., @code{"Europe/Paris"}.
6437
17c20385
LC
6438You can run the @command{tzselect} command to find out which timezone
6439string corresponds to your region. Choosing an invalid timezone name
6440causes @command{guix system} to fail.
6441
598e19dc
LC
6442@item @code{locale} (default: @code{"en_US.utf8"})
6443The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
6444Library Reference Manual}). @xref{Locales}, for more information.
6445
6446@item @code{locale-definitions} (default: @var{%default-locale-definitions})
6447The list of locale definitions to be compiled and that may be used at
6448run time. @xref{Locales}.
7313a52e 6449
34760ae7
LC
6450@item @code{locale-libcs} (default: @code{(list @var{glibc})})
6451The list of GNU@tie{}libc packages whose locale data and tools are used
6452to build the locale definitions. @xref{Locales}, for compatibility
6453considerations that justify this option.
6454
996ed739 6455@item @code{name-service-switch} (default: @var{%default-nss})
1068f26b 6456Configuration of the libc name service switch (NSS)---a
996ed739
LC
6457@code{<name-service-switch>} object. @xref{Name Service Switch}, for
6458details.
6459
7313a52e 6460@item @code{services} (default: @var{%base-services})
28d939af 6461A list of service objects denoting system services. @xref{Services}.
7313a52e
LC
6462
6463@item @code{pam-services} (default: @code{(base-pam-services)})
6464@cindex PAM
6465@cindex pluggable authentication modules
6466Linux @dfn{pluggable authentication module} (PAM) services.
6467@c FIXME: Add xref to PAM services section.
6468
6469@item @code{setuid-programs} (default: @var{%setuid-programs})
6470List of string-valued G-expressions denoting setuid programs.
6471@xref{Setuid Programs}.
6472
f5a9ffa0
AK
6473@item @code{sudoers-file} (default: @var{%sudoers-specification})
6474@cindex sudoers file
84765839
LC
6475The contents of the @file{/etc/sudoers} file as a file-like object
6476(@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7313a52e
LC
6477
6478This file specifies which users can use the @command{sudo} command, what
6479they are allowed to do, and what privileges they may gain. The default
6480is that only @code{root} and members of the @code{wheel} group may use
6481@code{sudo}.
6482
6483@end table
6484@end deftp
6485
cf4a9129
LC
6486@node File Systems
6487@subsection File Systems
b81e1947 6488
cf4a9129 6489The list of file systems to be mounted is specified in the
1068f26b 6490@code{file-systems} field of the operating system declaration
cf4a9129
LC
6491(@pxref{Using the Configuration System}). Each file system is declared
6492using the @code{file-system} form, like this:
b81e1947
LC
6493
6494@example
cf4a9129
LC
6495(file-system
6496 (mount-point "/home")
6497 (device "/dev/sda3")
6498 (type "ext4"))
b81e1947
LC
6499@end example
6500
cf4a9129
LC
6501As usual, some of the fields are mandatory---those shown in the example
6502above---while others can be omitted. These are described below.
b81e1947 6503
cf4a9129
LC
6504@deftp {Data Type} file-system
6505Objects of this type represent file systems to be mounted. They
6506contain the following members:
5ff3c4b8 6507
cf4a9129
LC
6508@table @asis
6509@item @code{type}
6510This is a string specifying the type of the file system---e.g.,
6511@code{"ext4"}.
5ff3c4b8 6512
cf4a9129
LC
6513@item @code{mount-point}
6514This designates the place where the file system is to be mounted.
b81e1947 6515
cf4a9129
LC
6516@item @code{device}
6517This names the ``source'' of the file system. By default it is the name
6518of a node under @file{/dev}, but its meaning depends on the @code{title}
6519field described below.
401c53c4 6520
cf4a9129
LC
6521@item @code{title} (default: @code{'device})
6522This is a symbol that specifies how the @code{device} field is to be
6523interpreted.
401c53c4 6524
cf4a9129
LC
6525When it is the symbol @code{device}, then the @code{device} field is
6526interpreted as a file name; when it is @code{label}, then @code{device}
6527is interpreted as a partition label name; when it is @code{uuid},
6528@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 6529
661a1d79 6530UUIDs may be converted from their string representation (as shown by the
0767f6a6
LC
6531@command{tune2fs -l} command) using the @code{uuid} form@footnote{The
6532@code{uuid} form expects 16-byte UUIDs as defined in
6533@uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
6534form of UUID used by the ext2 family of file systems and others, but it
6535is different from ``UUIDs'' found in FAT file systems, for instance.},
6536like this:
661a1d79
LC
6537
6538@example
6539(file-system
6540 (mount-point "/home")
6541 (type "ext4")
6542 (title 'uuid)
6543 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
6544@end example
6545
cf4a9129 6546The @code{label} and @code{uuid} options offer a way to refer to disk
661a1d79
LC
6547partitions without having to hard-code their actual device
6548name@footnote{Note that, while it is tempting to use
6549@file{/dev/disk/by-uuid} and similar device names to achieve the same
6550result, this is not recommended: These special device nodes are created
6551by the udev daemon and may be unavailable at the time the device is
6552mounted.}.
da7cabd4 6553
1068f26b 6554However, when the source of a file system is a mapped device (@pxref{Mapped
5f86a66e
LC
6555Devices}), its @code{device} field @emph{must} refer to the mapped
6556device name---e.g., @file{/dev/mapper/root-partition}---and consequently
6557@code{title} must be set to @code{'device}. This is required so that
6558the system knows that mounting the file system depends on having the
6559corresponding device mapping established.
6560
cf4a9129
LC
6561@item @code{flags} (default: @code{'()})
6562This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
6563include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
6564access to special files), @code{no-suid} (ignore setuid and setgid
6565bits), and @code{no-exec} (disallow program execution.)
da7cabd4 6566
cf4a9129
LC
6567@item @code{options} (default: @code{#f})
6568This is either @code{#f}, or a string denoting mount options.
da7cabd4 6569
be21979d
LC
6570@item @code{mount?} (default: @code{#t})
6571This value indicates whether to automatically mount the file system when
6572the system is brought up. When set to @code{#f}, the file system gets
6573an entry in @file{/etc/fstab} (read by the @command{mount} command) but
6574is not automatically mounted.
6575
cf4a9129
LC
6576@item @code{needed-for-boot?} (default: @code{#f})
6577This Boolean value indicates whether the file system is needed when
6578booting. If that is true, then the file system is mounted when the
6579initial RAM disk (initrd) is loaded. This is always the case, for
6580instance, for the root file system.
da7cabd4 6581
cf4a9129
LC
6582@item @code{check?} (default: @code{#t})
6583This Boolean indicates whether the file system needs to be checked for
6584errors before being mounted.
f9cc8971 6585
4e469051
LC
6586@item @code{create-mount-point?} (default: @code{#f})
6587When true, the mount point is created if it does not exist yet.
6588
e51710d1
LC
6589@item @code{dependencies} (default: @code{'()})
6590This is a list of @code{<file-system>} objects representing file systems
6591that must be mounted before (and unmounted after) this one.
6592
6593As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
6594a dependency of @file{/sys/fs/cgroup/cpu} and
6595@file{/sys/fs/cgroup/memory}.
6596
cf4a9129
LC
6597@end table
6598@end deftp
da7cabd4 6599
a69576ea
LC
6600The @code{(gnu system file-systems)} exports the following useful
6601variables.
6602
6603@defvr {Scheme Variable} %base-file-systems
6604These are essential file systems that are required on normal systems,
cc0e575a 6605such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
3392ce5d
LC
6606below.) Operating system declarations should always contain at least
6607these.
a69576ea
LC
6608@end defvr
6609
7f239fd3
LC
6610@defvr {Scheme Variable} %pseudo-terminal-file-system
6611This is the file system to be mounted as @file{/dev/pts}. It supports
6612@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
6613functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
6614Manual}). Pseudo-terminals are used by terminal emulators such as
6615@command{xterm}.
6616@end defvr
6617
db17ae5c
LC
6618@defvr {Scheme Variable} %shared-memory-file-system
6619This file system is mounted as @file{/dev/shm} and is used to support
6620memory sharing across processes (@pxref{Memory-mapped I/O,
6621@code{shm_open},, libc, The GNU C Library Reference Manual}).
6622@end defvr
6623
3392ce5d
LC
6624@defvr {Scheme Variable} %immutable-store
6625This file system performs a read-only ``bind mount'' of
6626@file{/gnu/store}, making it read-only for all the users including
6627@code{root}. This prevents against accidental modification by software
6628running as @code{root} or by system administrators.
6629
6630The daemon itself is still able to write to the store: it remounts it
6631read-write in its own ``name space.''
6632@end defvr
6633
a69576ea
LC
6634@defvr {Scheme Variable} %binary-format-file-system
6635The @code{binfmt_misc} file system, which allows handling of arbitrary
6636executable file types to be delegated to user space. This requires the
6637@code{binfmt.ko} kernel module to be loaded.
6638@end defvr
6639
6640@defvr {Scheme Variable} %fuse-control-file-system
6641The @code{fusectl} file system, which allows unprivileged users to mount
6642and unmount user-space FUSE file systems. This requires the
6643@code{fuse.ko} kernel module to be loaded.
6644@end defvr
6645
510f9d86
LC
6646@node Mapped Devices
6647@subsection Mapped Devices
6648
6649@cindex device mapping
6650@cindex mapped devices
6651The Linux kernel has a notion of @dfn{device mapping}: a block device,
6652such as a hard disk partition, can be @dfn{mapped} into another device,
6653with additional processing over the data that flows through
6654it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
6655concept of a ``mapped device'' and that of a file system: both boil down
6656to @emph{translating} input/output operations made on a file to
6657operations on its backing store. Thus, the Hurd implements mapped
6658devices, like file systems, using the generic @dfn{translator} mechanism
6659(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
6660typical example is encryption device mapping: all writes to the mapped
6661device are encrypted, and all reads are deciphered, transparently.
6662
6663Mapped devices are declared using the @code{mapped-device} form:
6664
6665@example
6666(mapped-device
6667 (source "/dev/sda3")
6668 (target "home")
6669 (type luks-device-mapping))
6670@end example
6671
6672@noindent
6673@cindex disk encryption
6674@cindex LUKS
6675This example specifies a mapping from @file{/dev/sda3} to
6676@file{/dev/mapper/home} using LUKS---the
6677@url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
6678standard mechanism for disk encryption. The @file{/dev/mapper/home}
6679device can then be used as the @code{device} of a @code{file-system}
6680declaration (@pxref{File Systems}). The @code{mapped-device} form is
6681detailed below.
6682
6683@deftp {Data Type} mapped-device
6684Objects of this type represent device mappings that will be made when
6685the system boots up.
6686
9cb426b8
LC
6687@table @code
6688@item source
510f9d86
LC
6689This string specifies the name of the block device to be mapped, such as
6690@code{"/dev/sda3"}.
6691
9cb426b8 6692@item target
510f9d86
LC
6693This string specifies the name of the mapping to be established. For
6694example, specifying @code{"my-partition"} will lead to the creation of
6695the @code{"/dev/mapper/my-partition"} device.
6696
9cb426b8 6697@item type
510f9d86
LC
6698This must be a @code{mapped-device-kind} object, which specifies how
6699@var{source} is mapped to @var{target}.
6700@end table
6701@end deftp
6702
6703@defvr {Scheme Variable} luks-device-mapping
6704This defines LUKS block device encryption using the @command{cryptsetup}
1068f26b 6705command from the package with the same name. It relies on the
510f9d86
LC
6706@code{dm-crypt} Linux kernel module.
6707@end defvr
6708
cf4a9129
LC
6709@node User Accounts
6710@subsection User Accounts
ee85f3db 6711
9bea87a5
LC
6712User accounts and groups are entirely managed through the
6713@code{operating-system} declaration. They are specified with the
6714@code{user-account} and @code{user-group} forms:
ee85f3db 6715
cf4a9129
LC
6716@example
6717(user-account
6718 (name "alice")
6719 (group "users")
24e752c0
LC
6720 (supplementary-groups '("wheel" ;allow use of sudo, etc.
6721 "audio" ;sound card
6722 "video" ;video devices such as webcams
6723 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
6724 (comment "Bob's sister")
6725 (home-directory "/home/alice"))
6726@end example
25083588 6727
9bea87a5
LC
6728When booting or upon completion of @command{guix system reconfigure},
6729the system ensures that only the user accounts and groups specified in
6730the @code{operating-system} declaration exist, and with the specified
6731properties. Thus, account or group creations or modifications made by
6732directly invoking commands such as @command{useradd} are lost upon
6733reconfiguration or reboot. This ensures that the system remains exactly
6734as declared.
6735
cf4a9129
LC
6736@deftp {Data Type} user-account
6737Objects of this type represent user accounts. The following members may
6738be specified:
ee85f3db 6739
cf4a9129
LC
6740@table @asis
6741@item @code{name}
6742The name of the user account.
ee85f3db 6743
cf4a9129
LC
6744@item @code{group}
6745This is the name (a string) or identifier (a number) of the user group
6746this account belongs to.
ee85f3db 6747
cf4a9129
LC
6748@item @code{supplementary-groups} (default: @code{'()})
6749Optionally, this can be defined as a list of group names that this
6750account belongs to.
ee85f3db 6751
cf4a9129
LC
6752@item @code{uid} (default: @code{#f})
6753This is the user ID for this account (a number), or @code{#f}. In the
6754latter case, a number is automatically chosen by the system when the
6755account is created.
ee85f3db 6756
cf4a9129 6757@item @code{comment} (default: @code{""})
1068f26b 6758A comment about the account, such as the account owner's full name.
c8c871d1 6759
cf4a9129
LC
6760@item @code{home-directory}
6761This is the name of the home directory for the account.
ee85f3db 6762
cf4a9129
LC
6763@item @code{shell} (default: Bash)
6764This is a G-expression denoting the file name of a program to be used as
6765the shell (@pxref{G-Expressions}).
ee85f3db 6766
cf4a9129
LC
6767@item @code{system?} (default: @code{#f})
6768This Boolean value indicates whether the account is a ``system''
6769account. System accounts are sometimes treated specially; for instance,
6770graphical login managers do not list them.
ee85f3db 6771
1bd4e6db 6772@anchor{user-account-password}
cf4a9129 6773@item @code{password} (default: @code{#f})
eb59595c
LC
6774You would normally leave this field to @code{#f}, initialize user
6775passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
6776users change it with @command{passwd}. Passwords set with
6777@command{passwd} are of course preserved across reboot and
6778reconfiguration.
eb59595c
LC
6779
6780If you @emph{do} want to have a preset password for an account, then
6781this field must contain the encrypted password, as a string.
5d1f1177
LC
6782@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
6783on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 6784Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 6785
cf4a9129
LC
6786@end table
6787@end deftp
ee85f3db 6788
cf4a9129 6789User group declarations are even simpler:
ee85f3db 6790
cf4a9129
LC
6791@example
6792(user-group (name "students"))
6793@end example
ee85f3db 6794
cf4a9129
LC
6795@deftp {Data Type} user-group
6796This type is for, well, user groups. There are just a few fields:
af8a56b8 6797
cf4a9129
LC
6798@table @asis
6799@item @code{name}
1068f26b 6800The name of the group.
ee85f3db 6801
cf4a9129
LC
6802@item @code{id} (default: @code{#f})
6803The group identifier (a number). If @code{#f}, a new number is
6804automatically allocated when the group is created.
ee85f3db 6805
c8fa3426
LC
6806@item @code{system?} (default: @code{#f})
6807This Boolean value indicates whether the group is a ``system'' group.
6808System groups have low numerical IDs.
6809
cf4a9129
LC
6810@item @code{password} (default: @code{#f})
6811What, user groups can have a password? Well, apparently yes. Unless
1068f26b 6812@code{#f}, this field specifies the password of the group.
ee85f3db 6813
cf4a9129
LC
6814@end table
6815@end deftp
401c53c4 6816
cf4a9129
LC
6817For convenience, a variable lists all the basic user groups one may
6818expect:
401c53c4 6819
cf4a9129
LC
6820@defvr {Scheme Variable} %base-groups
6821This is the list of basic user groups that users and/or packages expect
6822to be present on the system. This includes groups such as ``root'',
6823``wheel'', and ``users'', as well as groups used to control access to
6824specific devices such as ``audio'', ``disk'', and ``cdrom''.
6825@end defvr
401c53c4 6826
bf87f38a
LC
6827@defvr {Scheme Variable} %base-user-accounts
6828This is the list of basic system accounts that programs may expect to
6829find on a GNU/Linux system, such as the ``nobody'' account.
6830
6831Note that the ``root'' account is not included here. It is a
6832special-case and is automatically added whether or not it is specified.
6833@end defvr
6834
598e19dc
LC
6835@node Locales
6836@subsection Locales
6837
6838@cindex locale
6839A @dfn{locale} defines cultural conventions for a particular language
6840and region of the world (@pxref{Locales,,, libc, The GNU C Library
6841Reference Manual}). Each locale has a name that typically has the form
b2636518 6842@code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
598e19dc
LC
6843@code{fr_LU.utf8} designates the locale for the French language, with
6844cultural conventions from Luxembourg, and using the UTF-8 encoding.
6845
6846@cindex locale definition
6847Usually, you will want to specify the default locale for the machine
6848using the @code{locale} field of the @code{operating-system} declaration
6849(@pxref{operating-system Reference, @code{locale}}).
6850
f5582b2c
LC
6851The selected locale is automatically added to the @dfn{locale
6852definitions} known to the system if needed, with its codeset inferred
6853from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
6854@code{UTF-8} codeset. Additional locale definitions can be specified in
6855the @code{locale-definitions} slot of @code{operating-system}---this is
6856useful, for instance, if the codeset could not be inferred from the
6857locale name. The default set of locale definitions includes some widely
6858used locales, but not all the available locales, in order to save space.
6859
6860For instance, to add the North Frisian locale for Germany, the value of
6861that field may be:
598e19dc
LC
6862
6863@example
6864(cons (locale-definition
6865 (name "fy_DE.utf8") (source "fy_DE"))
6866 %default-locale-definitions)
6867@end example
6868
6869Likewise, to save space, one might want @code{locale-definitions} to
6870list only the locales that are actually used, as in:
6871
6872@example
6873(list (locale-definition
6874 (name "ja_JP.eucjp") (source "ja_JP")
6875 (charset "EUC-JP")))
6876@end example
6877
5c3c1427
LC
6878@vindex LOCPATH
6879The compiled locale definitions are available at
46bd6edd
LC
6880@file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
6881version, which is the default location where the GNU@tie{}libc provided
6882by Guix looks for locale data. This can be overridden using the
6883@code{LOCPATH} environment variable (@pxref{locales-and-locpath,
5c3c1427
LC
6884@code{LOCPATH} and locale packages}).
6885
598e19dc
LC
6886The @code{locale-definition} form is provided by the @code{(gnu system
6887locale)} module. Details are given below.
6888
6889@deftp {Data Type} locale-definition
6890This is the data type of a locale definition.
6891
6892@table @asis
6893
6894@item @code{name}
6895The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
6896Reference Manual}, for more information on locale names.
6897
6898@item @code{source}
6899The name of the source for that locale. This is typically the
6900@code{@var{language}_@var{territory}} part of the locale name.
6901
6902@item @code{charset} (default: @code{"UTF-8"})
6903The ``character set'' or ``code set'' for that locale,
6904@uref{http://www.iana.org/assignments/character-sets, as defined by
6905IANA}.
6906
6907@end table
6908@end deftp
6909
6910@defvr {Scheme Variable} %default-locale-definitions
1068f26b 6911A list of commonly used UTF-8 locales, used as the default
b2636518 6912value of the @code{locale-definitions} field of @code{operating-system}
598e19dc 6913declarations.
b2636518
LC
6914
6915@cindex locale name
6916@cindex normalized codeset in locale names
6917These locale definitions use the @dfn{normalized codeset} for the part
6918that follows the dot in the name (@pxref{Using gettextized software,
6919normalized codeset,, libc, The GNU C Library Reference Manual}). So for
6920instance it has @code{uk_UA.utf8} but @emph{not}, say,
6921@code{uk_UA.UTF-8}.
598e19dc 6922@end defvr
401c53c4 6923
34760ae7
LC
6924@subsubsection Locale Data Compatibility Considerations
6925
6926@cindex incompatibility, of locale data
6927@code{operating-system} declarations provide a @code{locale-libcs} field
6928to specify the GNU@tie{}libc packages that are used to compile locale
6929declarations (@pxref{operating-system Reference}). ``Why would I
6930care?'', you may ask. Well, it turns out that the binary format of
6931locale data is occasionally incompatible from one libc version to
6932another.
6933
6934@c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
6935@c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
6936For instance, a program linked against libc version 2.21 is unable to
6937read locale data produced with libc 2.22; worse, that program
6938@emph{aborts} instead of simply ignoring the incompatible locale
6939data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
6940the incompatible locale data, which is already an improvement.}.
6941Similarly, a program linked against libc 2.22 can read most, but not
6942all, the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
6943data is incompatible); thus calls to @code{setlocale} may fail, but
6944programs will not abort.
6945
6946The ``problem'' in GuixSD is that users have a lot of freedom: They can
6947choose whether and when to upgrade software in their profiles, and might
6948be using a libc version different from the one the system administrator
6949used to build the system-wide locale data.
6950
6951Fortunately, unprivileged users can also install their own locale data
6952and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
6953@code{GUIX_LOCPATH} and locale packages}).
6954
6955Still, it is best if the system-wide locale data at
6956@file{/run/current-system/locale} is built for all the libc versions
6957actually in use on the system, so that all the programs can access
6958it---this is especially crucial on a multi-user system. To do that, the
6959administrator can specify several libc packages in the
6960@code{locale-libcs} field of @code{operating-system}:
6961
6962@example
6963(use-package-modules base)
6964
6965(operating-system
6966 ;; @dots{}
6967 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
6968@end example
6969
6970This example would lead to a system containing locale definitions for
6971both libc 2.21 and the current version of libc in
6972@file{/run/current-system/locale}.
6973
6974
cf4a9129
LC
6975@node Services
6976@subsection Services
401c53c4 6977
cf4a9129
LC
6978@cindex system services
6979An important part of preparing an @code{operating-system} declaration is
6980listing @dfn{system services} and their configuration (@pxref{Using the
6981Configuration System}). System services are typically daemons launched
6982when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
6983configuring network access.
6984
dd17bc38
AK
6985Services are managed by the GNU@tie{}Shepherd (@pxref{Introduction,,,
6986shepherd, The GNU Shepherd Manual}). On a running system, the
6987@command{herd} command allows you to list the available services, show
6988their status, start and stop them, or do other specific operations
6989(@pxref{Jump Start,,, shepherd, The GNU Shepherd Manual}). For example:
d8b94dbd
LC
6990
6991@example
dd17bc38 6992# herd status
d8b94dbd
LC
6993@end example
6994
6995The above command, run as @code{root}, lists the currently defined
dd17bc38 6996services. The @command{herd doc} command shows a synopsis of the given
d8b94dbd
LC
6997service:
6998
6999@example
dd17bc38 7000# herd doc nscd
d8b94dbd
LC
7001Run libc's name service cache daemon (nscd).
7002@end example
7003
7004The @command{start}, @command{stop}, and @command{restart} sub-commands
7005have the effect you would expect. For instance, the commands below stop
7006the nscd service and restart the Xorg display server:
7007
7008@example
dd17bc38 7009# herd stop nscd
d8b94dbd 7010Service nscd has been stopped.
dd17bc38 7011# herd restart xorg-server
d8b94dbd
LC
7012Service xorg-server has been stopped.
7013Service xorg-server has been started.
7014@end example
401c53c4 7015
cf4a9129 7016The following sections document the available services, starting with
d8b94dbd
LC
7017the core services, that may be used in an @code{operating-system}
7018declaration.
401c53c4 7019
cf4a9129
LC
7020@menu
7021* Base Services:: Essential system services.
7022* Networking Services:: Network setup, SSH daemon, etc.
7023* X Window:: Graphical display.
fe1a39d3 7024* Desktop Services:: D-Bus and desktop services.
105369a4 7025* Database Services:: SQL databases.
d8c18af8 7026* Mail Services:: IMAP, POP3, SMTP, and all that.
58724c48 7027* Web Services:: Web servers.
aa4ed923 7028* Various Services:: Other services.
cf4a9129 7029@end menu
401c53c4 7030
cf4a9129
LC
7031@node Base Services
7032@subsubsection Base Services
a1ba8475 7033
cf4a9129
LC
7034The @code{(gnu services base)} module provides definitions for the basic
7035services that one expects from the system. The services exported by
7036this module are listed below.
401c53c4 7037
cf4a9129 7038@defvr {Scheme Variable} %base-services
31771497
LC
7039This variable contains a list of basic services (@pxref{Service Types
7040and Services}, for more information on service objects) one would
cf4a9129 7041expect from the system: a login service (mingetty) on each tty, syslogd,
1068f26b 7042the libc name service cache daemon (nscd), the udev device manager, and
cf4a9129 7043more.
401c53c4 7044
cf4a9129
LC
7045This is the default value of the @code{services} field of
7046@code{operating-system} declarations. Usually, when customizing a
7047system, you will want to append services to @var{%base-services}, like
7048this:
401c53c4 7049
cf4a9129 7050@example
fa1e31b8 7051(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
7052@end example
7053@end defvr
401c53c4 7054
be1c2c54 7055@deffn {Scheme Procedure} host-name-service @var{name}
cf4a9129
LC
7056Return a service that sets the host name to @var{name}.
7057@end deffn
401c53c4 7058
66e4f01c
LC
7059@deffn {Scheme Procedure} mingetty-service @var{config}
7060Return a service to run mingetty according to @var{config}, a
7061@code{<mingetty-configuration>} object, which specifies the tty to run, among
7062other things.
cf4a9129 7063@end deffn
401c53c4 7064
66e4f01c
LC
7065@deftp {Data Type} mingetty-configuration
7066This is the data type representing the configuration of Mingetty, which
7067implements console log-in.
7068
7069@table @asis
7070
7071@item @code{tty}
7072The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
7073
7074@item @code{motd}
7075A file-like object containing the ``message of the day''.
7076
7077@item @code{auto-login} (default: @code{#f})
7078When true, this field must be a string denoting the user name under
f9b9a033 7079which the system automatically logs in. When it is @code{#f}, a
66e4f01c
LC
7080user name and password must be entered to log in.
7081
7082@item @code{login-program} (default: @code{#f})
7083This must be either @code{#f}, in which case the default log-in program
7084is used (@command{login} from the Shadow tool suite), or a gexp denoting
7085the name of the log-in program.
7086
7087@item @code{login-pause?} (default: @code{#f})
7088When set to @code{#t} in conjunction with @var{auto-login}, the user
7089will have to press a key before the log-in shell is launched.
7090
7091@item @code{mingetty} (default: @var{mingetty})
7092The Mingetty package to use.
7093
7094@end table
7095@end deftp
7096
6454b333
LC
7097@cindex name service cache daemon
7098@cindex nscd
be1c2c54 7099@deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
4aee6e60 7100 [#:name-services '()]
1068f26b 7101Return a service that runs the libc name service cache daemon (nscd) with the
b893f1ae
LC
7102given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
7103Service Switch}, for an example.
cf4a9129 7104@end deffn
401c53c4 7105
6454b333
LC
7106@defvr {Scheme Variable} %nscd-default-configuration
7107This is the default @code{<nscd-configuration>} value (see below) used
1068f26b 7108by @code{nscd-service}. It uses the caches defined by
6454b333
LC
7109@var{%nscd-default-caches}; see below.
7110@end defvr
7111
7112@deftp {Data Type} nscd-configuration
1068f26b 7113This is the data type representing the name service cache daemon (nscd)
6454b333
LC
7114configuration.
7115
7116@table @asis
7117
b893f1ae
LC
7118@item @code{name-services} (default: @code{'()})
7119List of packages denoting @dfn{name services} that must be visible to
7120the nscd---e.g., @code{(list @var{nss-mdns})}.
7121
7122@item @code{glibc} (default: @var{glibc})
7123Package object denoting the GNU C Library providing the @command{nscd}
7124command.
7125
6454b333 7126@item @code{log-file} (default: @code{"/var/log/nscd.log"})
1068f26b 7127Name of the nscd log file. This is where debugging output goes when
6454b333
LC
7128@code{debug-level} is strictly positive.
7129
7130@item @code{debug-level} (default: @code{0})
1068f26b 7131Integer denoting the debugging levels. Higher numbers mean that more
6454b333
LC
7132debugging output is logged.
7133
7134@item @code{caches} (default: @var{%nscd-default-caches})
7135List of @code{<nscd-cache>} objects denoting things to be cached; see
7136below.
7137
7138@end table
7139@end deftp
7140
7141@deftp {Data Type} nscd-cache
7142Data type representing a cache database of nscd and its parameters.
7143
7144@table @asis
7145
7146@item @code{database}
7147This is a symbol representing the name of the database to be cached.
7148Valid values are @code{passwd}, @code{group}, @code{hosts}, and
7149@code{services}, which designate the corresponding NSS database
7150(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
7151
7152@item @code{positive-time-to-live}
7153@itemx @code{negative-time-to-live} (default: @code{20})
7154A number representing the number of seconds during which a positive or
7155negative lookup result remains in cache.
7156
7157@item @code{check-files?} (default: @code{#t})
7158Whether to check for updates of the files corresponding to
7159@var{database}.
7160
7161For instance, when @var{database} is @code{hosts}, setting this flag
7162instructs nscd to check for updates in @file{/etc/hosts} and to take
7163them into account.
7164
7165@item @code{persistent?} (default: @code{#t})
7166Whether the cache should be stored persistently on disk.
7167
7168@item @code{shared?} (default: @code{#t})
7169Whether the cache should be shared among users.
7170
7171@item @code{max-database-size} (default: 32@tie{}MiB)
7172Maximum size in bytes of the database cache.
7173
7174@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
7175@c settings, so leave them out.
7176
7177@end table
7178@end deftp
7179
7180@defvr {Scheme Variable} %nscd-default-caches
7181List of @code{<nscd-cache>} objects used by default by
1068f26b 7182@code{nscd-configuration} (see above).
6454b333
LC
7183
7184It enables persistent and aggressive caching of service and host name
7185lookups. The latter provides better host name lookup performance,
7186resilience in the face of unreliable name servers, and also better
7187privacy---often the result of host name lookups is in local cache, so
7188external name servers do not even need to be queried.
7189@end defvr
7190
7191
44abcb28
LC
7192@deffn {Scheme Procedure} syslog-service @
7193 [#:config-file @var{%default-syslog.conf}]
1068f26b 7194Return a service that runs @command{syslogd}. If the configuration file
44abcb28 7195name @var{config-file} is not specified, use some reasonable default
cf4a9129 7196settings.
44abcb28
LC
7197
7198@xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
7199information on the configuration file syntax.
cf4a9129 7200@end deffn
401c53c4 7201
0adfe95a
LC
7202@anchor{guix-configuration-type}
7203@deftp {Data Type} guix-configuration
7204This data type represents the configuration of the Guix build daemon.
7205@xref{Invoking guix-daemon}, for more information.
7206
7207@table @asis
7208@item @code{guix} (default: @var{guix})
7209The Guix package to use.
401c53c4 7210
0adfe95a
LC
7211@item @code{build-group} (default: @code{"guixbuild"})
7212Name of the group for build user accounts.
401c53c4 7213
0adfe95a
LC
7214@item @code{build-accounts} (default: @code{10})
7215Number of build user accounts to create.
401c53c4 7216
0adfe95a
LC
7217@item @code{authorize-key?} (default: @code{#t})
7218Whether to authorize the substitute key for @code{hydra.gnu.org}
7219(@pxref{Substitutes}).
7220
7221@item @code{use-substitutes?} (default: @code{#t})
7222Whether to use substitutes.
7223
b0b9f6e0
LC
7224@item @code{substitute-urls} (default: @var{%default-substitute-urls})
7225The list of URLs where to look for substitutes by default.
7226
0adfe95a
LC
7227@item @code{extra-options} (default: @code{'()})
7228List of extra command-line options for @command{guix-daemon}.
7229
7230@item @code{lsof} (default: @var{lsof})
7231@itemx @code{lsh} (default: @var{lsh})
7232The lsof and lsh packages to use.
7233
7234@end table
7235@end deftp
7236
7237@deffn {Scheme Procedure} guix-service @var{config}
7238Return a service that runs the Guix build daemon according to
7239@var{config}.
cf4a9129 7240@end deffn
a1ba8475 7241
be1c2c54 7242@deffn {Scheme Procedure} udev-service [#:udev udev]
cf4a9129
LC
7243Run @var{udev}, which populates the @file{/dev} directory dynamically.
7244@end deffn
401c53c4 7245
be1c2c54 7246@deffn {Scheme Procedure} console-keymap-service @var{file}
dedb8d5e 7247@cindex keyboard layout
5eca9459
AK
7248Return a service to load console keymap from @var{file} using
7249@command{loadkeys} command.
7250@end deffn
7251
8664cc88
LC
7252@deffn {Scheme Procedure} gpm-service-type [#:gpm @var{gpm}] @
7253 [#:options]
7254Run @var{gpm}, the general-purpose mouse daemon, with the given
7255command-line @var{options}. GPM allows users to use the mouse in the console,
7256notably to select, copy, and paste text. The default value of @var{options}
7257uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
7258
7259This service is not part of @var{%base-services}.
7260@end deffn
7261
1c52181f
LC
7262@anchor{guix-publish-service}
7263@deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
7264 [#:port 80] [#:host "localhost"]
7265Return a service that runs @command{guix publish} listening on @var{host}
7266and @var{port} (@pxref{Invoking guix publish}).
7267
7268This assumes that @file{/etc/guix} already contains a signing key pair as
7269created by @command{guix archive --generate-key} (@pxref{Invoking guix
7270archive}). If that is not the case, the service will fail to start.
7271@end deffn
7272
a69576ea 7273
cf4a9129
LC
7274@node Networking Services
7275@subsubsection Networking Services
401c53c4 7276
fa1e31b8 7277The @code{(gnu services networking)} module provides services to configure
cf4a9129 7278the network interface.
a1ba8475 7279
a023cca8 7280@cindex DHCP, networking service
be1c2c54 7281@deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
a023cca8
LC
7282Return a service that runs @var{dhcp}, a Dynamic Host Configuration
7283Protocol (DHCP) client, on all the non-loopback network interfaces.
7284@end deffn
7285
be1c2c54 7286@deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
cf4a9129
LC
7287 [#:gateway #f] [#:name-services @code{'()}]
7288Return a service that starts @var{interface} with address @var{ip}. If
7289@var{gateway} is true, it must be a string specifying the default network
7290gateway.
7291@end deffn
8b315a6d 7292
b7d0c494 7293@cindex wicd
87f40011 7294@cindex network management
be1c2c54 7295@deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
87f40011
LC
7296Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
7297management daemon that aims to simplify wired and wireless networking.
7298
7299This service adds the @var{wicd} package to the global profile, providing
7300several commands to interact with the daemon and configure networking:
7301@command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
7302and @command{wicd-curses} user interfaces.
b7d0c494
MW
7303@end deffn
7304
c0a9589d
SB
7305@cindex NetworkManager
7306@deffn {Scheme Procedure} network-manager-service @
7307 [#:network-manager @var{network-manager}]
7308Return a service that runs NetworkManager, a network connection manager
1068f26b 7309attempting to keep network connectivity active when available.
c0a9589d
SB
7310@end deffn
7311
be1c2c54 7312@deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
63854bcb
LC
7313 [#:name-service @var{%ntp-servers}]
7314Return a service that runs the daemon from @var{ntp}, the
7315@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
7316keep the system clock synchronized with that of @var{servers}.
7317@end deffn
7318
7319@defvr {Scheme Variable} %ntp-servers
7320List of host names used as the default NTP servers.
7321@end defvr
7322
375c6108
LC
7323@deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
7324Return a service to run the @uref{https://torproject.org, Tor} anonymous
7325networking daemon.
8b315a6d 7326
375c6108 7327The daemon runs as the @code{tor} unprivileged user. It is passed
6331bde7
LC
7328@var{config-file}, a file-like object, with an additional @code{User tor} line
7329and lines for hidden services added via @code{tor-hidden-service}. Run
7330@command{man tor} for information about the configuration file.
7331@end deffn
7332
24a8ef3b 7333@cindex hidden service
6331bde7
LC
7334@deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
7335Define a new Tor @dfn{hidden service} called @var{name} and implementing
7336@var{mapping}. @var{mapping} is a list of port/host tuples, such as:
7337
7338@example
24a8ef3b
LC
7339 '((22 "127.0.0.1:22")
7340 (80 "127.0.0.1:8080"))
6331bde7
LC
7341@end example
7342
7343In this example, port 22 of the hidden service is mapped to local port 22, and
7344port 80 is mapped to local port 8080.
7345
6629099a
LC
7346This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
7347the @file{hostname} file contains the @code{.onion} host name for the hidden
6331bde7
LC
7348service.
7349
7350See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
7351project's documentation} for more information.
cf4a9129 7352@end deffn
8b315a6d 7353
be1c2c54 7354@deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
4627a464
LC
7355 [#:interface "127.0.0.1"] [#:port 6667] @
7356 [#:extra-settings ""]
7357Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
7358acts as a gateway between IRC and chat networks.
7359
7360The daemon will listen to the interface corresponding to the IP address
7361specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
7362local clients can connect, whereas @code{0.0.0.0} means that connections can
7363come from any networking interface.
7364
7365In addition, @var{extra-settings} specifies a string to append to the
7366configuration file.
7367@end deffn
7368
f4391bec 7369Furthermore, @code{(gnu services ssh)} provides the following service.
8b315a6d 7370
be1c2c54 7371@deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 7372 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
7373 [#:allow-empty-passwords? #f] [#:root-login? #f] @
7374 [#:syslog-output? #t] [#:x11-forwarding? #t] @
7375 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 7376 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
7377Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
7378@var{host-key} must designate a file containing the host key, and readable
7379only by root.
72e25e35 7380
5833bf33
DP
7381When @var{daemonic?} is true, @command{lshd} will detach from the
7382controlling terminal and log its output to syslogd, unless one sets
7383@var{syslog-output?} to false. Obviously, it also makes lsh-service
7384depend on existence of syslogd service. When @var{pid-file?} is true,
7385@command{lshd} writes its PID to the file called @var{pid-file}.
7386
cf4a9129
LC
7387When @var{initialize?} is true, automatically create the seed and host key
7388upon service activation if they do not exist yet. This may take long and
7389require interaction.
8b315a6d 7390
20dd519c
LC
7391When @var{initialize?} is false, it is up to the user to initialize the
7392randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
7393a key pair with the private key stored in file @var{host-key} (@pxref{lshd
7394basics,,, lsh, LSH Manual}).
7395
cf4a9129
LC
7396When @var{interfaces} is empty, lshd listens for connections on all the
7397network interfaces; otherwise, @var{interfaces} must be a list of host names
7398or addresses.
9bf3c1a7 7399
20dd519c
LC
7400@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
7401passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 7402root.
4af2447e 7403
cf4a9129
LC
7404The other options should be self-descriptive.
7405@end deffn
4af2447e 7406
fa0c1d61
LC
7407@defvr {Scheme Variable} %facebook-host-aliases
7408This variable contains a string for use in @file{/etc/hosts}
7409(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
7410line contains a entry that maps a known server name of the Facebook
7411on-line service---e.g., @code{www.facebook.com}---to the local
7412host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
7413
7414This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
7415@code{operating-system} declaration (@pxref{operating-system Reference,
7416@file{/etc/hosts}}):
fa0c1d61
LC
7417
7418@example
7419(use-modules (gnu) (guix))
7420
7421(operating-system
7422 (host-name "mymachine")
7423 ;; ...
7424 (hosts-file
7425 ;; Create a /etc/hosts file with aliases for "localhost"
7426 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
7427 (plain-file "hosts"
7428 (string-append (local-host-aliases host-name)
7429 %facebook-host-aliases))))
fa0c1d61
LC
7430@end example
7431
7432This mechanism can prevent programs running locally, such as Web
7433browsers, from accessing Facebook.
7434@end defvr
7435
965a7332
LC
7436The @code{(gnu services avahi)} provides the following definition.
7437
be1c2c54 7438@deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
965a7332
LC
7439 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
7440 [#:ipv6? #t] [#:wide-area? #f] @
7441 [#:domains-to-browse '()]
7442Return a service that runs @command{avahi-daemon}, a system-wide
7443mDNS/DNS-SD responder that allows for service discovery and
cc9c1f39
LC
7444"zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
7445extends the name service cache daemon (nscd) so that it can resolve
7446@code{.local} host names using
1065bed9
LC
7447@uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
7448add the @var{avahi} package to the system profile so that commands such as
7449@command{avahi-browse} are directly usable.
965a7332
LC
7450
7451If @var{host-name} is different from @code{#f}, use that as the host name to
7452publish for this machine; otherwise, use the machine's actual host name.
7453
7454When @var{publish?} is true, publishing of host names and services is allowed;
7455in particular, avahi-daemon will publish the machine's host name and IP
7456address via mDNS on the local network.
7457
7458When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
7459
7460Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
7461sockets.
7462@end deffn
7463
7464
cf4a9129
LC
7465@node X Window
7466@subsubsection X Window
68ad877c 7467
cf4a9129
LC
7468Support for the X Window graphical display system---specifically
7469Xorg---is provided by the @code{(gnu services xorg)} module. Note that
7470there is no @code{xorg-service} procedure. Instead, the X server is
7471started by the @dfn{login manager}, currently SLiM.
4af2447e 7472
be1c2c54 7473@deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
7474 [#:auto-login? #f] [#:default-user ""] [#:startx] @
7475 [#:theme @var{%default-slim-theme}] @
4bd43bbe 7476 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
7477Return a service that spawns the SLiM graphical login manager, which in
7478turn starts the X display server with @var{startx}, a command as returned by
7479@code{xorg-start-command}.
4af2447e 7480
04e4e6ab
LC
7481@cindex X session
7482
7483SLiM automatically looks for session types described by the @file{.desktop}
7484files in @file{/run/current-system/profile/share/xsessions} and allows users
7485to choose a session from the log-in screen using @kbd{F1}. Packages such as
7486@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
7487adding them to the system-wide set of packages automatically makes them
7488available at the log-in screen.
7489
7490In addition, @file{~/.xsession} files are honored. When available,
7491@file{~/.xsession} must be an executable that starts a window manager
7492and/or other X clients.
7493
cf4a9129
LC
7494When @var{allow-empty-passwords?} is true, allow logins with an empty
7495password. When @var{auto-login?} is true, log in automatically as
7496@var{default-user}.
0ecc3bf3 7497
1068f26b 7498If @var{theme} is @code{#f}, use the default log-in theme; otherwise
0ecc3bf3
LC
7499@var{theme} must be a gexp denoting the name of a directory containing the
7500theme to use. In that case, @var{theme-name} specifies the name of the
7501theme.
cf4a9129 7502@end deffn
4af2447e 7503
0ecc3bf3
LC
7504@defvr {Scheme Variable} %default-theme
7505@defvrx {Scheme Variable} %default-theme-name
7506The G-Expression denoting the default SLiM theme and its name.
7507@end defvr
7508
be1c2c54 7509@deffn {Scheme Procedure} xorg-start-command [#:guile] @
d1cdd7ba 7510 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 7511Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
7512from @var{xorg-server}. @var{configuration-file} is the server configuration
7513file or a derivation that builds it; when omitted, the result of
7514@code{xorg-configuration-file} is used.
7515
7516Usually the X server is started by a login manager.
7517@end deffn
7518
be1c2c54 7519@deffn {Scheme Procedure} xorg-configuration-file @
12422c9d 7520 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
7521Return a configuration file for the Xorg server containing search paths for
7522all the common drivers.
f703413e
LC
7523
7524@var{drivers} must be either the empty list, in which case Xorg chooses a
7525graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 7526this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
7527
7528Likewise, when @var{resolutions} is the empty list, Xorg chooses an
7529appropriate screen resolution; otherwise, it must be a list of
7530resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
7531
7532Last, @var{extra-config} is a list of strings or objects appended to the
7533@code{text-file*} argument list. It is used to pass extra text to be added
7534verbatim to the configuration file.
f703413e 7535@end deffn
4af2447e 7536
6726282b
LC
7537@deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
7538Add @var{package}, a package for a screen-locker or screen-saver whose
7539command is @var{program}, to the set of setuid programs and add a PAM entry
7540for it. For example:
7541
7542@lisp
7543(screen-locker-service xlockmore "xlock")
7544@end lisp
7545
7546makes the good ol' XlockMore usable.
7547@end deffn
7548
7549
fe1a39d3
LC
7550@node Desktop Services
7551@subsubsection Desktop Services
aa4ed923 7552
fe1a39d3
LC
7553The @code{(gnu services desktop)} module provides services that are
7554usually useful in the context of a ``desktop'' setup---that is, on a
7555machine running a graphical display server, possibly with graphical user
7a2413e4
AW
7556interfaces, etc. It also defines services that provide specific desktop
7557environments like GNOME and XFCE.
aa4ed923 7558
4467be21
LC
7559To simplify things, the module defines a variable containing the set of
7560services that users typically expect on a machine with a graphical
7561environment and networking:
7562
7563@defvr {Scheme Variable} %desktop-services
7564This is a list of services that builds upon @var{%base-services} and
1068f26b 7565adds or adjusts services for a typical ``desktop'' setup.
4467be21
LC
7566
7567In particular, it adds a graphical login manager (@pxref{X Window,
6726282b
LC
7568@code{slim-service}}), screen lockers,
7569a network management tool (@pxref{Networking
4467be21 7570Services, @code{wicd-service}}), energy and color management services,
4650a77e 7571the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
7572the GeoClue location service, an NTP client (@pxref{Networking
7573Services}), the Avahi daemon, and has the name service switch service
7574configured to be able to use @code{nss-mdns} (@pxref{Name Service
7575Switch, mDNS}).
4467be21
LC
7576@end defvr
7577
7578The @var{%desktop-services} variable can be used as the @code{services}
7579field of an @code{operating-system} declaration (@pxref{operating-system
7580Reference, @code{services}}).
7581
7a2413e4
AW
7582Additionally, the @code{gnome-desktop-service} and
7583@code{xfce-desktop-service} procedures can add GNOME and/or XFCE to a
7584system. To ``add GNOME'' means that system-level services like the
7585backlight adjustment helpers and the power management utilities are
7586added to the system, extending @code{polkit} and @code{dbus}
7587appropriately, allowing GNOME to operate with elevated privileges on a
7588limited number of special-purpose system interfaces. Additionally,
7589adding a service made by @code{gnome-desktop-service} adds the GNOME
7590metapackage to the system profile. Likewise, adding the XFCE service
7591not only adds the @code{xfce} metapackage to the system profile, but it
7592also gives the Thunar file manager the ability to open a ``root-mode''
7593file management window, if the user authenticates using the
7594administrator's password via the standard polkit graphical interface.
7595
7596@deffn {Scheme Procedure} gnome-desktop-service
7597Return a service that adds the @code{gnome} package to the system
7598profile, and extends polkit with the actions from
7599@code{gnome-settings-daemon}.
7600@end deffn
7601
7602@deffn {Scheme Procedure} xfce-desktop-service
7603Return a service that adds the @code{xfce} package to the system profile,
7604and extends polkit with the abilit for @code{thunar} to manipulate the
7605file system as root from within a user session, after the user has
7606authenticated with the administrator's password.
7607@end deffn
7608
7609Because the GNOME and XFCE desktop services pull in so many packages,
7610the default @code{%desktop-services} variable doesn't include either of
7611them by default. To add GNOME or XFCE, just @code{cons} them onto
7612@code{%desktop-services} in the @code{services} field of your
7613@code{operating-system}:
7614
7615@example
7616(use-modules (gnu))
7617(use-service-modules desktop)
7618(operating-system
7619 ...
7620 ;; cons* adds items to the list given as its last argument.
7621 (services (cons* (gnome-desktop-service)
7622 (xfce-desktop-service)
7623 %desktop-services))
7624 ...)
7625@end example
7626
7627These desktop environments will then be available as options in the
7628graphical login window.
7629
7630The actual service definitions included in @code{%desktop-services} and
7631provided by @code{(gnu services dbus)} and @code{(gnu services desktop)}
7632are described below.
4467be21 7633
0adfe95a 7634@deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
fe1a39d3
LC
7635Return a service that runs the ``system bus'', using @var{dbus}, with
7636support for @var{services}.
aa4ed923 7637
fe1a39d3
LC
7638@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
7639facility. Its system bus is used to allow system services to communicate
1068f26b 7640and to be notified of system-wide events.
aa4ed923 7641
fe1a39d3
LC
7642@var{services} must be a list of packages that provide an
7643@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
7644and policy files. For example, to allow avahi-daemon to use the system bus,
7645@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
7646@end deffn
7647
0adfe95a 7648@deffn {Scheme Procedure} elogind-service [#:config @var{config}]
4650a77e
AW
7649Return a service that runs the @code{elogind} login and
7650seat management daemon. @uref{https://github.com/andywingo/elogind,
7651Elogind} exposes a D-Bus interface that can be used to know which users
7652are logged in, know what kind of sessions they have open, suspend the
7653system, inhibit system suspend, reboot the system, and other tasks.
7654
7655Elogind handles most system-level power events for a computer, for
7656example suspending the system when a lid is closed, or shutting it down
7657when the power button is pressed.
7658
7659The @var{config} keyword argument specifies the configuration for
1068f26b 7660elogind, and should be the result of an @code{(elogind-configuration
4650a77e
AW
7661(@var{parameter} @var{value})...)} invocation. Available parameters and
7662their default values are:
7663
7664@table @code
7665@item kill-user-processes?
7666@code{#f}
7667@item kill-only-users
7668@code{()}
7669@item kill-exclude-users
7670@code{("root")}
7671@item inhibit-delay-max-seconds
7672@code{5}
7673@item handle-power-key
7674@code{poweroff}
7675@item handle-suspend-key
7676@code{suspend}
7677@item handle-hibernate-key
7678@code{hibernate}
7679@item handle-lid-switch
7680@code{suspend}
7681@item handle-lid-switch-docked
7682@code{ignore}
7683@item power-key-ignore-inhibited?
7684@code{#f}
7685@item suspend-key-ignore-inhibited?
7686@code{#f}
7687@item hibernate-key-ignore-inhibited?
7688@code{#f}
7689@item lid-switch-ignore-inhibited?
7690@code{#t}
7691@item holdoff-timeout-seconds
7692@code{30}
7693@item idle-action
7694@code{ignore}
7695@item idle-action-seconds
7696@code{(* 30 60)}
7697@item runtime-directory-size-percent
7698@code{10}
7699@item runtime-directory-size
7700@code{#f}
7701@item remove-ipc?
7702@code{#t}
7703@item suspend-state
7704@code{("mem" "standby" "freeze")}
7705@item suspend-mode
7706@code{()}
7707@item hibernate-state
7708@code{("disk")}
7709@item hibernate-mode
7710@code{("platform" "shutdown")}
7711@item hybrid-sleep-state
7712@code{("disk")}
7713@item hybrid-sleep-mode
7714@code{("suspend" "platform" "shutdown")}
7715@end table
7716@end deffn
7717
be1c2c54 7718@deffn {Scheme Procedure} polkit-service @
4650a77e 7719 [#:polkit @var{polkit}]
222e3319
LC
7720Return a service that runs the
7721@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
7722management service}, which allows system administrators to grant access to
7723privileged operations in a structured way. By querying the Polkit service, a
7724privileged system component can know when it should grant additional
7725capabilities to ordinary users. For example, an ordinary user can be granted
7726the capability to suspend the system if the user is logged in locally.
4650a77e
AW
7727@end deffn
7728
be1c2c54 7729@deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
be234128
AW
7730 [#:watts-up-pro? #f] @
7731 [#:poll-batteries? #t] @
7732 [#:ignore-lid? #f] @
7733 [#:use-percentage-for-policy? #f] @
7734 [#:percentage-low 10] @
7735 [#:percentage-critical 3] @
7736 [#:percentage-action 2] @
7737 [#:time-low 1200] @
7738 [#:time-critical 300] @
7739 [#:time-action 120] @
7740 [#:critical-power-action 'hybrid-sleep]
7741Return a service that runs @uref{http://upower.freedesktop.org/,
7742@command{upowerd}}, a system-wide monitor for power consumption and battery
7743levels, with the given configuration settings. It implements the
7744@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
7745GNOME.
7746@end deffn
7747
2b9e0a94
LC
7748@deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
7749Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
7750UDisks}, a @dfn{disk management} daemon that provides user interfaces with
7751notifications and ways to mount/unmount disks. Programs that talk to UDisks
7752include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
7753@end deffn
7754
be1c2c54 7755@deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7ce597ff
AW
7756Return a service that runs @command{colord}, a system service with a D-Bus
7757interface to manage the color profiles of input and output devices such as
7758screens and scanners. It is notably used by the GNOME Color Manager graphical
7759tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
7760site} for more information.
7761@end deffn
7762
cee32ee4 7763@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
1068f26b 7764Return a configuration allowing an application to access GeoClue
cee32ee4
AW
7765location data. @var{name} is the Desktop ID of the application, without
7766the @code{.desktop} part. If @var{allowed?} is true, the application
7767will have access to location information by default. The boolean
1068f26b 7768@var{system?} value indicates whether an application is a system component
cee32ee4
AW
7769or not. Finally @var{users} is a list of UIDs of all users for which
7770this application is allowed location info access. An empty users list
7771means that all users are allowed.
7772@end deffn
7773
7774@defvr {Scheme Variable} %standard-geoclue-applications
7775The standard list of well-known GeoClue application configurations,
1068f26b
AE
7776granting authority to the GNOME date-and-time utility to ask for the
7777current location in order to set the time zone, and allowing the
7778IceCat and Epiphany web browsers to request location information.
7779IceCat and Epiphany both query the user before allowing a web page to
cee32ee4
AW
7780know the user's location.
7781@end defvr
7782
be1c2c54 7783@deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
cee32ee4
AW
7784 [#:whitelist '()] @
7785 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
7786 [#:submit-data? #f]
7787 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
7788 [#:submission-nick "geoclue"] @
7789 [#:applications %standard-geoclue-applications]
7790Return a service that runs the GeoClue location service. This service
7791provides a D-Bus interface to allow applications to request access to a
7792user's physical location, and optionally to add information to online
7793location databases. See
7794@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
7795web site} for more information.
7796@end deffn
7797
105369a4
DT
7798@node Database Services
7799@subsubsection Database Services
7800
7801The @code{(gnu services databases)} module provides the following service.
7802
be1c2c54 7803@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
105369a4
DT
7804 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
7805Return a service that runs @var{postgresql}, the PostgreSQL database
7806server.
7807
7808The PostgreSQL daemon loads its runtime configuration from
7809@var{config-file} and stores the database cluster in
7810@var{data-directory}.
7811@end deffn
fe1a39d3 7812
d8c18af8
AW
7813@node Mail Services
7814@subsubsection Mail Services
7815
7816The @code{(gnu services mail)} module provides Guix service definitions
7817for mail services. Currently the only implemented service is Dovecot,
7818an IMAP, POP3, and LMTP server.
7819
7820Guix does not yet have a mail transfer agent (MTA), although for some
7821lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
7822is needed to properly integrate a full MTA, such as Postfix. Patches
7823welcome!
7824
7825To add an IMAP/POP3 server to a GuixSD system, add a
7826@code{dovecot-service} to the operating system definition:
7827
7828@deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
7829Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
7830@end deffn
7831
1068f26b 7832By default, Dovecot does not need much configuration; the default
d8c18af8
AW
7833configuration object created by @code{(dovecot-configuration)} will
7834suffice if your mail is delivered to @code{~/Maildir}. A self-signed
7835certificate will be generated for TLS-protected connections, though
7836Dovecot will also listen on cleartext ports by default. There are a
1068f26b 7837number of options, though, which mail administrators might need to change,
d8c18af8
AW
7838and as is the case with other services, Guix allows the system
7839administrator to specify these parameters via a uniform Scheme interface.
7840
7841For example, to specify that mail is located at @code{maildir~/.mail},
7842one would instantiate the Dovecot service like this:
7843
7844@example
7845(dovecot-service #:config
7846 (dovecot-configuration
7847 (mail-location "maildir:~/.mail")))
7848@end example
7849
7850The available configuration parameters follow. Each parameter
7851definition is preceded by its type; for example, @samp{string-list foo}
7852indicates that the @code{foo} parameter should be specified as a list of
7853strings. There is also a way to specify the configuration as a string,
7854if you have an old @code{dovecot.conf} file that you want to port over
7855from some other system; see the end for more details.
7856
7857@c The following documentation was initially generated by
7858@c (generate-documentation) in (gnu services mail). Manually maintained
7859@c documentation is better, so we shouldn't hesitate to edit below as
7860@c needed. However if the change you want to make to this documentation
7861@c can be done in an automated way, it's probably easier to change
7862@c (generate-documentation) than to make it below and have to deal with
7863@c the churn as dovecot updates.
7864
7865Available @code{dovecot-configuration} fields are:
7866
7867@deftypevr {@code{dovecot-configuration} parameter} package dovecot
7868The dovecot package.
7869@end deftypevr
7870
7871@deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
1068f26b
AE
7872A list of IPs or hosts where to listen for connections. @samp{*}
7873listens on all IPv4 interfaces, @samp{::} listens on all IPv6
d8c18af8
AW
7874interfaces. If you want to specify non-default ports or anything more
7875complex, customize the address and port fields of the
7876@samp{inet-listener} of the specific services you are interested in.
7877@end deftypevr
7878
7879@deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
7880List of protocols we want to serve. Available protocols include
7881@samp{imap}, @samp{pop3}, and @samp{lmtp}.
7882
7883Available @code{protocol-configuration} fields are:
7884
7885@deftypevr {@code{protocol-configuration} parameter} string name
7886The name of the protocol.
7887@end deftypevr
7888
7889@deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
1068f26b 7890UNIX socket path to the master authentication server to find users.
d8c18af8 7891This is used by imap (for shared users) and lda.
1068f26b 7892It defaults to @samp{"/var/run/dovecot/auth-userdb"}.
d8c18af8
AW
7893@end deftypevr
7894
7895@deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
7896Space separated list of plugins to load.
7897@end deftypevr
7898
7899@deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
7900Maximum number of IMAP connections allowed for a user from each IP
7901address. NOTE: The username is compared case-sensitively.
7902Defaults to @samp{10}.
7903@end deftypevr
7904
7905@end deftypevr
7906
7907@deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
7908List of services to enable. Available services include @samp{imap},
7909@samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
7910@samp{lmtp}.
7911
7912Available @code{service-configuration} fields are:
7913
7914@deftypevr {@code{service-configuration} parameter} string kind
7915The service kind. Valid values include @code{director},
7916@code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
7917@code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
7918@code{tcpwrap}, @code{quota-warning}, or anything else.
7919@end deftypevr
7920
7921@deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
1068f26b 7922Listeners for the service. A listener is either a
d8c18af8
AW
7923@code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
7924an @code{inet-listener-configuration}.
7925Defaults to @samp{()}.
7926
7927Available @code{unix-listener-configuration} fields are:
7928
7929@deftypevr {@code{unix-listener-configuration} parameter} file-name path
7930The file name on which to listen.
7931@end deftypevr
7932
7933@deftypevr {@code{unix-listener-configuration} parameter} string mode
7934The access mode for the socket.
7935Defaults to @samp{"0600"}.
7936@end deftypevr
7937
7938@deftypevr {@code{unix-listener-configuration} parameter} string user
f9b9a033 7939The user to own the socket.
d8c18af8
AW
7940Defaults to @samp{""}.
7941@end deftypevr
7942
7943@deftypevr {@code{unix-listener-configuration} parameter} string group
7944The group to own the socket.
7945Defaults to @samp{""}.
7946@end deftypevr
7947
7948
7949Available @code{fifo-listener-configuration} fields are:
7950
7951@deftypevr {@code{fifo-listener-configuration} parameter} file-name path
7952The file name on which to listen.
7953@end deftypevr
7954
7955@deftypevr {@code{fifo-listener-configuration} parameter} string mode
7956The access mode for the socket.
7957Defaults to @samp{"0600"}.
7958@end deftypevr
7959
7960@deftypevr {@code{fifo-listener-configuration} parameter} string user
f9b9a033 7961The user to own the socket.
d8c18af8
AW
7962Defaults to @samp{""}.
7963@end deftypevr
7964
7965@deftypevr {@code{fifo-listener-configuration} parameter} string group
7966The group to own the socket.
7967Defaults to @samp{""}.
7968@end deftypevr
7969
7970
7971Available @code{inet-listener-configuration} fields are:
7972
7973@deftypevr {@code{inet-listener-configuration} parameter} string protocol
7974The protocol to listen for.
7975@end deftypevr
7976
7977@deftypevr {@code{inet-listener-configuration} parameter} string address
7978The address on which to listen, or empty for all addresses.
7979Defaults to @samp{""}.
7980@end deftypevr
7981
7982@deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
7983The port on which to listen.
7984@end deftypevr
7985
7986@deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
7987Whether to use SSL for this service; @samp{yes}, @samp{no}, or
7988@samp{required}.
7989Defaults to @samp{#t}.
7990@end deftypevr
7991
7992@end deftypevr
7993
7994@deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
7995Number of connections to handle before starting a new process.
7996Typically the only useful values are 0 (unlimited) or 1. 1 is more
7997secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
7998Defaults to @samp{1}.
7999@end deftypevr
8000
8001@deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
8002Number of processes to always keep waiting for more connections.
8003Defaults to @samp{0}.
8004@end deftypevr
8005
8006@deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
8007If you set @samp{service-count 0}, you probably need to grow
8008this.
8009Defaults to @samp{256000000}.
8010@end deftypevr
8011
8012@end deftypevr
8013
8014@deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
8015Dict configuration, as created by the @code{dict-configuration}
8016constructor.
8017
8018Available @code{dict-configuration} fields are:
8019
8020@deftypevr {@code{dict-configuration} parameter} free-form-fields entries
8021A list of key-value pairs that this dict should hold.
8022Defaults to @samp{()}.
8023@end deftypevr
8024
8025@end deftypevr
8026
8027@deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
1068f26b 8028A list of passdb configurations, each one created by the
d8c18af8
AW
8029@code{passdb-configuration} constructor.
8030
8031Available @code{passdb-configuration} fields are:
8032
8033@deftypevr {@code{passdb-configuration} parameter} string driver
8034The driver that the passdb should use. Valid values include
8035@samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
8036@samp{static}.
8037Defaults to @samp{"pam"}.
8038@end deftypevr
8039
8040@deftypevr {@code{passdb-configuration} parameter} free-form-args args
8041A list of key-value args to the passdb driver.
8042Defaults to @samp{()}.
8043@end deftypevr
8044
8045@end deftypevr
8046
8047@deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
8048List of userdb configurations, each one created by the
8049@code{userdb-configuration} constructor.
8050
8051Available @code{userdb-configuration} fields are:
8052
8053@deftypevr {@code{userdb-configuration} parameter} string driver
8054The driver that the userdb should use. Valid values include
8055@samp{passwd} and @samp{static}.
8056Defaults to @samp{"passwd"}.
8057@end deftypevr
8058
8059@deftypevr {@code{userdb-configuration} parameter} free-form-args args
8060A list of key-value args to the userdb driver.
8061Defaults to @samp{()}.
8062@end deftypevr
8063
8064@deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
8065Override fields from passwd.
8066Defaults to @samp{()}.
8067@end deftypevr
8068
8069@end deftypevr
8070
8071@deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
8072Plug-in configuration, created by the @code{plugin-configuration}
8073constructor.
8074@end deftypevr
8075
8076@deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
8077List of namespaces. Each item in the list is created by the
8078@code{namespace-configuration} constructor.
8079
8080Available @code{namespace-configuration} fields are:
8081
8082@deftypevr {@code{namespace-configuration} parameter} string name
8083Name for this namespace.
8084@end deftypevr
8085
8086@deftypevr {@code{namespace-configuration} parameter} string type
8087Namespace type: @samp{private}, @samp{shared} or @samp{public}.
8088Defaults to @samp{"private"}.
8089@end deftypevr
8090
8091@deftypevr {@code{namespace-configuration} parameter} string separator
8092Hierarchy separator to use. You should use the same separator for
8093all namespaces or some clients get confused. @samp{/} is usually a good
8094one. The default however depends on the underlying mail storage
8095format.
8096Defaults to @samp{""}.
8097@end deftypevr
8098
8099@deftypevr {@code{namespace-configuration} parameter} string prefix
8100Prefix required to access this namespace. This needs to be
8101different for all namespaces. For example @samp{Public/}.
8102Defaults to @samp{""}.
8103@end deftypevr
8104
8105@deftypevr {@code{namespace-configuration} parameter} string location
1068f26b 8106Physical location of the mailbox. This is in the same format as
d8c18af8
AW
8107mail_location, which is also the default for it.
8108Defaults to @samp{""}.
8109@end deftypevr
8110
8111@deftypevr {@code{namespace-configuration} parameter} boolean inbox?
8112There can be only one INBOX, and this setting defines which
8113namespace has it.
8114Defaults to @samp{#f}.
8115@end deftypevr
8116
8117@deftypevr {@code{namespace-configuration} parameter} boolean hidden?
8118If namespace is hidden, it's not advertised to clients via NAMESPACE
8119extension. You'll most likely also want to set @samp{list? #f}. This is mostly
8120useful when converting from another server with different namespaces
8121which you want to deprecate but still keep working. For example you can
8122create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
8123and @samp{mail/}.
8124Defaults to @samp{#f}.
8125@end deftypevr
8126
8127@deftypevr {@code{namespace-configuration} parameter} boolean list?
1068f26b
AE
8128Show the mailboxes under this namespace with the LIST command. This
8129makes the namespace visible for clients that do not support the NAMESPACE
d8c18af8
AW
8130extension. The special @code{children} value lists child mailboxes, but
8131hides the namespace prefix.
8132Defaults to @samp{#t}.
8133@end deftypevr
8134
8135@deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
8136Namespace handles its own subscriptions. If set to @code{#f}, the
8137parent namespace handles them. The empty prefix should always have this
1068f26b 8138as @code{#t}).
d8c18af8
AW
8139Defaults to @samp{#t}.
8140@end deftypevr
8141
8142@deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
8143List of predefined mailboxes in this namespace.
8144Defaults to @samp{()}.
8145
8146Available @code{mailbox-configuration} fields are:
8147
8148@deftypevr {@code{mailbox-configuration} parameter} string name
8149Name for this mailbox.
8150@end deftypevr
8151
8152@deftypevr {@code{mailbox-configuration} parameter} string auto
8153@samp{create} will automatically create this mailbox.
8154@samp{subscribe} will both create and subscribe to the mailbox.
8155Defaults to @samp{"no"}.
8156@end deftypevr
8157
8158@deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
8159List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
8160Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
8161@code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
8162Defaults to @samp{()}.
8163@end deftypevr
8164
8165@end deftypevr
8166
8167@end deftypevr
8168
8169@deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
8170Base directory where to store runtime data.
8171Defaults to @samp{"/var/run/dovecot/"}.
8172@end deftypevr
8173
8174@deftypevr {@code{dovecot-configuration} parameter} string login-greeting
8175Greeting message for clients.
8176Defaults to @samp{"Dovecot ready."}.
8177@end deftypevr
8178
8179@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
8180List of trusted network ranges. Connections from these IPs are
8181allowed to override their IP addresses and ports (for logging and for
8182authentication checks). @samp{disable-plaintext-auth} is also ignored
1068f26b 8183for these networks. Typically you would specify your IMAP proxy servers
d8c18af8
AW
8184here.
8185Defaults to @samp{()}.
8186@end deftypevr
8187
8188@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
8189List of login access check sockets (e.g. tcpwrap).
8190Defaults to @samp{()}.
8191@end deftypevr
8192
8193@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
8194Show more verbose process titles (in ps). Currently shows user name
1068f26b
AE
8195and IP address. Useful for seeing who is actually using the IMAP
8196processes (e.g. shared mailboxes or if the same uid is used for multiple
d8c18af8
AW
8197accounts).
8198Defaults to @samp{#f}.
8199@end deftypevr
8200
8201@deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
8202Should all processes be killed when Dovecot master process shuts down.
8203Setting this to @code{#f} means that Dovecot can be upgraded without
8204forcing existing client connections to close (although that could also
1068f26b 8205be a problem if the upgrade is e.g. due to a security fix).
d8c18af8
AW
8206Defaults to @samp{#t}.
8207@end deftypevr
8208
8209@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
8210If non-zero, run mail commands via this many connections to doveadm
8211server, instead of running them directly in the same process.
8212Defaults to @samp{0}.
8213@end deftypevr
8214
8215@deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
8216UNIX socket or host:port used for connecting to doveadm server.
8217Defaults to @samp{"doveadm-server"}.
8218@end deftypevr
8219
8220@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
8221List of environment variables that are preserved on Dovecot startup
8222and passed down to all of its child processes. You can also give
8223key=value pairs to always set specific settings.
8224@end deftypevr
8225
8226@deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
8227Disable LOGIN command and all other plaintext authentications unless
8228SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
8229matches the local IP (i.e. you're connecting from the same computer),
8230the connection is considered secure and plaintext authentication is
8231allowed. See also ssl=required setting.
8232Defaults to @samp{#t}.
8233@end deftypevr
8234
8235@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
8236Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
8237Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
8238for caching to be used.
8239Defaults to @samp{0}.
8240@end deftypevr
8241
8242@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
8243Time to live for cached data. After TTL expires the cached record
8244is no longer used, *except* if the main database lookup returns internal
8245failure. We also try to handle password changes automatically: If
8246user's previous authentication was successful, but this one wasn't, the
8247cache isn't used. For now this works only with plaintext
8248authentication.
8249Defaults to @samp{"1 hour"}.
8250@end deftypevr
8251
8252@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
8253TTL for negative hits (user not found, password mismatch).
82540 disables caching them completely.
8255Defaults to @samp{"1 hour"}.
8256@end deftypevr
8257
8258@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
8259List of realms for SASL authentication mechanisms that need them.
8260You can leave it empty if you don't want to support multiple realms.
8261Many clients simply use the first one listed here, so keep the default
8262realm first.
8263Defaults to @samp{()}.
8264@end deftypevr
8265
8266@deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
8267Default realm/domain to use if none was specified. This is used for
8268both SASL realms and appending @@domain to username in plaintext
8269logins.
8270Defaults to @samp{""}.
8271@end deftypevr
8272
8273@deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
8274List of allowed characters in username. If the user-given username
8275contains a character not listed in here, the login automatically fails.
8276This is just an extra check to make sure user can't exploit any
8277potential quote escaping vulnerabilities with SQL/LDAP databases. If
8278you want to allow all characters, set this value to empty.
8279Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
8280@end deftypevr
8281
8282@deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
8283Username character translations before it's looked up from
8284databases. The value contains series of from -> to characters. For
8285example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
8286translated to @samp{@@}.
8287Defaults to @samp{""}.
8288@end deftypevr
8289
8290@deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
8291Username formatting before it's looked up from databases. You can
8292use the standard variables here, e.g. %Lu would lowercase the username,
8293%n would drop away the domain if it was given, or @samp{%n-AT-%d} would
8294change the @samp{@@} into @samp{-AT-}. This translation is done after
8295@samp{auth-username-translation} changes.
8296Defaults to @samp{"%Lu"}.
8297@end deftypevr
8298
8299@deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
8300If you want to allow master users to log in by specifying the master
8301username within the normal username string (i.e. not using SASL
8302mechanism's support for it), you can specify the separator character
8303here. The format is then <username><separator><master username>.
8304UW-IMAP uses @samp{*} as the separator, so that could be a good
8305choice.
8306Defaults to @samp{""}.
8307@end deftypevr
8308
8309@deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
8310Username to use for users logging in with ANONYMOUS SASL
8311mechanism.
8312Defaults to @samp{"anonymous"}.
8313@end deftypevr
8314
8315@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
8316Maximum number of dovecot-auth worker processes. They're used to
8317execute blocking passdb and userdb queries (e.g. MySQL and PAM).
8318They're automatically created and destroyed as needed.
8319Defaults to @samp{30}.
8320@end deftypevr
8321
8322@deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
8323Host name to use in GSSAPI principal names. The default is to use
8324the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
8325allow all keytab entries.
8326Defaults to @samp{""}.
8327@end deftypevr
8328
8329@deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
8330Kerberos keytab to use for the GSSAPI mechanism. Will use the
8331system default (usually /etc/krb5.keytab) if not specified. You may
8332need to change the auth service to run as root to be able to read this
8333file.
8334Defaults to @samp{""}.
8335@end deftypevr
8336
8337@deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
8338Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
8339and @samp{ntlm-auth} helper.
8340<doc/wiki/Authentication/Mechanisms/Winbind.txt>.
8341Defaults to @samp{#f}.
8342@end deftypevr
8343
8344@deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
8345Path for Samba's @samp{ntlm-auth} helper binary.
8346Defaults to @samp{"/usr/bin/ntlm_auth"}.
8347@end deftypevr
8348
8349@deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
8350Time to delay before replying to failed authentications.
8351Defaults to @samp{"2 secs"}.
8352@end deftypevr
8353
8354@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
8355Require a valid SSL client certificate or the authentication
8356fails.
8357Defaults to @samp{#f}.
8358@end deftypevr
8359
8360@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
8361Take the username from client's SSL certificate, using
8362@code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
8363CommonName.
8364Defaults to @samp{#f}.
8365@end deftypevr
8366
8367@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
8368List of wanted authentication mechanisms. Supported mechanisms are:
8369@samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
8370@samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
8371@samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
8372@samp{disable-plaintext-auth} setting.
8373@end deftypevr
8374
8375@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
8376List of IPs or hostnames to all director servers, including ourself.
8377Ports can be specified as ip:port. The default port is the same as what
8378director service's @samp{inet-listener} is using.
8379Defaults to @samp{()}.
8380@end deftypevr
8381
8382@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
8383List of IPs or hostnames to all backend mail servers. Ranges are
8384allowed too, like 10.0.0.10-10.0.0.30.
8385Defaults to @samp{()}.
8386@end deftypevr
8387
8388@deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
8389How long to redirect users to a specific server after it no longer
8390has any connections.
8391Defaults to @samp{"15 min"}.
8392@end deftypevr
8393
8394@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
8395TCP/IP port that accepts doveadm connections (instead of director
8396connections) If you enable this, you'll also need to add
8397@samp{inet-listener} for the port.
8398Defaults to @samp{0}.
8399@end deftypevr
8400
8401@deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
8402How the username is translated before being hashed. Useful values
8403include %Ln if user can log in with or without @@domain, %Ld if mailboxes
8404are shared within domain.
8405Defaults to @samp{"%Lu"}.
8406@end deftypevr
8407
8408@deftypevr {@code{dovecot-configuration} parameter} string log-path
8409Log file to use for error messages. @samp{syslog} logs to syslog,
8410@samp{/dev/stderr} logs to stderr.
8411Defaults to @samp{"syslog"}.
8412@end deftypevr
8413
8414@deftypevr {@code{dovecot-configuration} parameter} string info-log-path
8415Log file to use for informational messages. Defaults to
8416@samp{log-path}.
8417Defaults to @samp{""}.
8418@end deftypevr
8419
8420@deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
8421Log file to use for debug messages. Defaults to
8422@samp{info-log-path}.
8423Defaults to @samp{""}.
8424@end deftypevr
8425
8426@deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
8427Syslog facility to use if you're logging to syslog. Usually if you
8428don't want to use @samp{mail}, you'll use local0..local7. Also other
8429standard facilities are supported.
8430Defaults to @samp{"mail"}.
8431@end deftypevr
8432
8433@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
8434Log unsuccessful authentication attempts and the reasons why they
8435failed.
8436Defaults to @samp{#f}.
8437@end deftypevr
8438
8439@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
8440In case of password mismatches, log the attempted password. Valid
8441values are no, plain and sha1. sha1 can be useful for detecting brute
8442force password attempts vs. user simply trying the same password over
8443and over again. You can also truncate the value to n chars by appending
8444":n" (e.g. sha1:6).
8445Defaults to @samp{#f}.
8446@end deftypevr
8447
8448@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
8449Even more verbose logging for debugging purposes. Shows for example
8450SQL queries.
8451Defaults to @samp{#f}.
8452@end deftypevr
8453
8454@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
8455In case of password mismatches, log the passwords and used scheme so
8456the problem can be debugged. Enabling this also enables
8457@samp{auth-debug}.
8458Defaults to @samp{#f}.
8459@end deftypevr
8460
8461@deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
8462Enable mail process debugging. This can help you figure out why
8463Dovecot isn't finding your mails.
8464Defaults to @samp{#f}.
8465@end deftypevr
8466
8467@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
8468Show protocol level SSL errors.
8469Defaults to @samp{#f}.
8470@end deftypevr
8471
8472@deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
8473Prefix for each line written to log file. % codes are in
8474strftime(3) format.
8475Defaults to @samp{"\"%b %d %H:%M:%S \""}.
8476@end deftypevr
8477
8478@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
8479List of elements we want to log. The elements which have a
8480non-empty variable value are joined together to form a comma-separated
8481string.
8482@end deftypevr
8483
8484@deftypevr {@code{dovecot-configuration} parameter} string login-log-format
8485Login log format. %s contains @samp{login-log-format-elements}
8486string, %$ contains the data we want to log.
8487Defaults to @samp{"%$: %s"}.
8488@end deftypevr
8489
8490@deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
8491Log prefix for mail processes. See doc/wiki/Variables.txt for list
8492of possible variables you can use.
8493Defaults to @samp{"\"%s(%u): \""}.
8494@end deftypevr
8495
8496@deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
8497Format to use for logging mail deliveries. You can use variables:
8498@table @code
8499@item %$
8500Delivery status message (e.g. @samp{saved to INBOX})
8501@item %m
8502Message-ID
8503@item %s
8504Subject
8505@item %f
8506From address
8507@item %p
8508Physical size
8509@item %w
8510Virtual size.
8511@end table
8512Defaults to @samp{"msgid=%m: %$"}.
8513@end deftypevr
8514
8515@deftypevr {@code{dovecot-configuration} parameter} string mail-location
8516Location for users' mailboxes. The default is empty, which means
8517that Dovecot tries to find the mailboxes automatically. This won't work
8518if the user doesn't yet have any mail, so you should explicitly tell
8519Dovecot the full location.
8520
8521If you're using mbox, giving a path to the INBOX
8522file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
8523where the other mailboxes are kept. This is called the "root mail
8524directory", and it must be the first path given in the
8525@samp{mail-location} setting.
8526
8527There are a few special variables you can use, eg.:
8528
8529@table @samp
8530@item %u
8531username
8532@item %n
8533user part in user@@domain, same as %u if there's no domain
8534@item %d
8535domain part in user@@domain, empty if there's no domain
8536@item %h
8537home director
8538@end table
8539
8540See doc/wiki/Variables.txt for full list. Some examples:
8541@table @samp
8542@item maildir:~/Maildir
8543@item mbox:~/mail:INBOX=/var/mail/%u
8544@item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
8545@end table
8546Defaults to @samp{""}.
8547@end deftypevr
8548
8549@deftypevr {@code{dovecot-configuration} parameter} string mail-uid
8550System user and group used to access mails. If you use multiple,
8551userdb can override these by returning uid or gid fields. You can use
8552either numbers or names. <doc/wiki/UserIds.txt>.
8553Defaults to @samp{""}.
8554@end deftypevr
8555
8556@deftypevr {@code{dovecot-configuration} parameter} string mail-gid
8557
8558Defaults to @samp{""}.
8559@end deftypevr
8560
8561@deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
8562Group to enable temporarily for privileged operations. Currently
8563this is used only with INBOX when either its initial creation or
8564dotlocking fails. Typically this is set to "mail" to give access to
8565/var/mail.
8566Defaults to @samp{""}.
8567@end deftypevr
8568
8569@deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
8570Grant access to these supplementary groups for mail processes.
8571Typically these are used to set up access to shared mailboxes. Note
8572that it may be dangerous to set these if users can create
8573symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
8574could allow a user to delete others' mailboxes, or ln -s
8575/secret/shared/box ~/mail/mybox would allow reading it).
8576Defaults to @samp{""}.
8577@end deftypevr
8578
8579@deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
8580Allow full filesystem access to clients. There's no access checks
8581other than what the operating system does for the active UID/GID. It
8582works with both maildir and mboxes, allowing you to prefix mailboxes
8583names with e.g. /path/ or ~user/.
8584Defaults to @samp{#f}.
8585@end deftypevr
8586
8587@deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
8588Don't use mmap() at all. This is required if you store indexes to
8589shared filesystems (NFS or clustered filesystem).
8590Defaults to @samp{#f}.
8591@end deftypevr
8592
8593@deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
8594Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
8595supports @samp{O_EXCL} since version 3, so this should be safe to use
8596nowadays by default.
8597Defaults to @samp{#t}.
8598@end deftypevr
8599
8600@deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
8601When to use fsync() or fdatasync() calls:
8602@table @code
8603@item optimized
8604Whenever necessary to avoid losing important data
8605@item always
8606Useful with e.g. NFS when write()s are delayed
8607@item never
8608Never use it (best performance, but crashes can lose data).
8609@end table
8610Defaults to @samp{"optimized"}.
8611@end deftypevr
8612
8613@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
8614Mail storage exists in NFS. Set this to yes to make Dovecot flush
8615NFS caches whenever needed. If you're using only a single mail server
8616this isn't needed.
8617Defaults to @samp{#f}.
8618@end deftypevr
8619
8620@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
8621Mail index files also exist in NFS. Setting this to yes requires
8622@samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
8623Defaults to @samp{#f}.
8624@end deftypevr
8625
8626@deftypevr {@code{dovecot-configuration} parameter} string lock-method
8627Locking method for index files. Alternatives are fcntl, flock and
8628dotlock. Dotlocking uses some tricks which may create more disk I/O
8629than other locking methods. NFS users: flock doesn't work, remember to
8630change @samp{mmap-disable}.
8631Defaults to @samp{"fcntl"}.
8632@end deftypevr
8633
8634@deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
8635Directory in which LDA/LMTP temporarily stores incoming mails >128
8636kB.
8637Defaults to @samp{"/tmp"}.
8638@end deftypevr
8639
8640@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
8641Valid UID range for users. This is mostly to make sure that users can't
8642log in as daemons or other system users. Note that denying root logins is
8643hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
8644is set to 0.
8645Defaults to @samp{500}.
8646@end deftypevr
8647
8648@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
8649
8650Defaults to @samp{0}.
8651@end deftypevr
8652
8653@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
8654Valid GID range for users. Users having non-valid GID as primary group ID
8655aren't allowed to log in. If user belongs to supplementary groups with
8656non-valid GIDs, those groups are not set.
8657Defaults to @samp{1}.
8658@end deftypevr
8659
8660@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
8661
8662Defaults to @samp{0}.
8663@end deftypevr
8664
8665@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
8666Maximum allowed length for mail keyword name. It's only forced when
8667trying to create new keywords.
8668Defaults to @samp{50}.
8669@end deftypevr
8670
8671@deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
8672List of directories under which chrooting is allowed for mail
8673processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
8674too). This setting doesn't affect @samp{login-chroot}
8675@samp{mail-chroot} or auth chroot settings. If this setting is empty,
8676"/./" in home dirs are ignored. WARNING: Never add directories here
8677which local users can modify, that may lead to root exploit. Usually
8678this should be done only if you don't allow shell access for users.
8679<doc/wiki/Chrooting.txt>.
8680Defaults to @samp{()}.
8681@end deftypevr
8682
8683@deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
8684Default chroot directory for mail processes. This can be overridden
8685for specific users in user database by giving /./ in user's home
8686directory (e.g. /home/./user chroots into /home). Note that usually
8687there is no real need to do chrooting, Dovecot doesn't allow users to
8688access files outside their mail directory anyway. If your home
8689directories are prefixed with the chroot directory, append "/." to
8690@samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
8691Defaults to @samp{""}.
8692@end deftypevr
8693
8694@deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
8695UNIX socket path to master authentication server to find users.
8696This is used by imap (for shared users) and lda.
8697Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
8698@end deftypevr
8699
8700@deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
8701Directory where to look up mail plugins.
8702Defaults to @samp{"/usr/lib/dovecot"}.
8703@end deftypevr
8704
8705@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
8706List of plugins to load for all services. Plugins specific to IMAP,
8707LDA, etc. are added to this list in their own .conf files.
8708Defaults to @samp{()}.
8709@end deftypevr
8710
8711@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
8712The minimum number of mails in a mailbox before updates are done to
8713cache file. This allows optimizing Dovecot's behavior to do less disk
8714writes at the cost of more disk reads.
8715Defaults to @samp{0}.
8716@end deftypevr
8717
8718@deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
8719When IDLE command is running, mailbox is checked once in a while to
8720see if there are any new mails or other changes. This setting defines
8721the minimum time to wait between those checks. Dovecot can also use
8722dnotify, inotify and kqueue to find out immediately when changes
8723occur.
8724Defaults to @samp{"30 secs"}.
8725@end deftypevr
8726
8727@deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
8728Save mails with CR+LF instead of plain LF. This makes sending those
8729mails take less CPU, especially with sendfile() syscall with Linux and
8730FreeBSD. But it also creates a bit more disk I/O which may just make it
8731slower. Also note that if other software reads the mboxes/maildirs,
8732they may handle the extra CRs wrong and cause problems.
8733Defaults to @samp{#f}.
8734@end deftypevr
8735
8736@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
8737By default LIST command returns all entries in maildir beginning
8738with a dot. Enabling this option makes Dovecot return only entries
8739which are directories. This is done by stat()ing each entry, so it
8740causes more disk I/O.
8741 (For systems setting struct @samp{dirent->d_type} this check is free
8742and it's done always regardless of this setting).
8743Defaults to @samp{#f}.
8744@end deftypevr
8745
8746@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
8747When copying a message, do it with hard links whenever possible.
8748This makes the performance much better, and it's unlikely to have any
8749side effects.
8750Defaults to @samp{#t}.
8751@end deftypevr
8752
8753@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
8754Assume Dovecot is the only MUA accessing Maildir: Scan cur/
8755directory only when its mtime changes unexpectedly or when we can't find
8756the mail otherwise.
8757Defaults to @samp{#f}.
8758@end deftypevr
8759
8760@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
8761Which locking methods to use for locking mbox. There are four
8762available:
8763
8764@table @code
8765@item dotlock
8766Create <mailbox>.lock file. This is the oldest and most NFS-safe
8767solution. If you want to use /var/mail/ like directory, the users will
8768need write access to that directory.
8769@item dotlock-try
8770Same as dotlock, but if it fails because of permissions or because there
8771isn't enough disk space, just skip it.
8772@item fcntl
8773Use this if possible. Works with NFS too if lockd is used.
8774@item flock
a01ad638 8775May not exist in all systems. Doesn't work with NFS.
d8c18af8
AW
8776@item lockf
8777May not exist in all systems. Doesn't work with NFS.
8778@end table
8779
8780You can use multiple locking methods; if you do the order they're declared
8781in is important to avoid deadlocks if other MTAs/MUAs are using multiple
8782locking methods as well. Some operating systems don't allow using some of
8783them simultaneously.
8784@end deftypevr
8785
8786@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
8787
8788@end deftypevr
8789
8790@deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
8791Maximum time to wait for lock (all of them) before aborting.
8792Defaults to @samp{"5 mins"}.
8793@end deftypevr
8794
8795@deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
8796If dotlock exists but the mailbox isn't modified in any way,
8797override the lock file after this much time.
8798Defaults to @samp{"2 mins"}.
8799@end deftypevr
8800
8801@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
8802When mbox changes unexpectedly we have to fully read it to find out
8803what changed. If the mbox is large this can take a long time. Since
8804the change is usually just a newly appended mail, it'd be faster to
8805simply read the new mails. If this setting is enabled, Dovecot does
8806this but still safely fallbacks to re-reading the whole mbox file
8807whenever something in mbox isn't how it's expected to be. The only real
8808downside to this setting is that if some other MUA changes message
8809flags, Dovecot doesn't notice it immediately. Note that a full sync is
8810done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
8811Defaults to @samp{#t}.
8812@end deftypevr
8813
8814@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
8815Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
8816EXAMINE, EXPUNGE or CHECK commands. If this is set,
8817@samp{mbox-dirty-syncs} is ignored.
8818Defaults to @samp{#f}.
8819@end deftypevr
8820
8821@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
8822Delay writing mbox headers until doing a full write sync (EXPUNGE
8823and CHECK commands and when closing the mailbox). This is especially
8824useful for POP3 where clients often delete all mails. The downside is
8825that our changes aren't immediately visible to other MUAs.
8826Defaults to @samp{#t}.
8827@end deftypevr
8828
8829@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
8830If mbox size is smaller than this (e.g. 100k), don't write index
8831files. If an index file already exists it's still read, just not
8832updated.
8833Defaults to @samp{0}.
8834@end deftypevr
8835
8836@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
8837Maximum dbox file size until it's rotated.
8838Defaults to @samp{2000000}.
8839@end deftypevr
8840
8841@deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
8842Maximum dbox file age until it's rotated. Typically in days. Day
8843begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
8844disabled.
8845Defaults to @samp{"1d"}.
8846@end deftypevr
8847
8848@deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
8849When creating new mdbox files, immediately preallocate their size to
8850@samp{mdbox-rotate-size}. This setting currently works only in Linux
8851with some filesystems (ext4, xfs).
8852Defaults to @samp{#f}.
8853@end deftypevr
8854
8855@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
8856sdbox and mdbox support saving mail attachments to external files,
8857which also allows single instance storage for them. Other backends
8858don't support this for now.
8859
8860WARNING: This feature hasn't been tested much yet. Use at your own risk.
8861
8862Directory root where to store mail attachments. Disabled, if empty.
8863Defaults to @samp{""}.
8864@end deftypevr
8865
8866@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
8867Attachments smaller than this aren't saved externally. It's also
8868possible to write a plugin to disable saving specific attachments
8869externally.
8870Defaults to @samp{128000}.
8871@end deftypevr
8872
8873@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
8874Filesystem backend to use for saving attachments:
8875@table @code
8876@item posix
8877No SiS done by Dovecot (but this might help FS's own deduplication)
8878@item sis posix
8879SiS with immediate byte-by-byte comparison during saving
8880@item sis-queue posix
8881SiS with delayed comparison and deduplication.
8882@end table
8883Defaults to @samp{"sis posix"}.
8884@end deftypevr
8885
8886@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
8887Hash format to use in attachment filenames. You can add any text and
8888variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
8889@code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
8890truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
8891Defaults to @samp{"%@{sha1@}"}.
8892@end deftypevr
8893
8894@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
8895
8896Defaults to @samp{100}.
8897@end deftypevr
8898
8899@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
8900
8901Defaults to @samp{1000}.
8902@end deftypevr
8903
8904@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
8905Default VSZ (virtual memory size) limit for service processes.
8906This is mainly intended to catch and kill processes that leak memory
8907before they eat up everything.
8908Defaults to @samp{256000000}.
8909@end deftypevr
8910
8911@deftypevr {@code{dovecot-configuration} parameter} string default-login-user
8912Login user is internally used by login processes. This is the most
8913untrusted user in Dovecot system. It shouldn't have access to anything
8914at all.
8915Defaults to @samp{"dovenull"}.
8916@end deftypevr
8917
8918@deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
8919Internal user is used by unprivileged processes. It should be
8920separate from login user, so that login processes can't disturb other
8921processes.
8922Defaults to @samp{"dovecot"}.
8923@end deftypevr
8924
8925@deftypevr {@code{dovecot-configuration} parameter} string ssl?
8926SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
8927Defaults to @samp{"required"}.
8928@end deftypevr
8929
8930@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
8931PEM encoded X.509 SSL/TLS certificate (public key).
8932Defaults to @samp{"</etc/dovecot/default.pem"}.
8933@end deftypevr
8934
8935@deftypevr {@code{dovecot-configuration} parameter} string ssl-key
8936PEM encoded SSL/TLS private key. The key is opened before
8937dropping root privileges, so keep the key file unreadable by anyone but
8938root.
8939Defaults to @samp{"</etc/dovecot/private/default.pem"}.
8940@end deftypevr
8941
8942@deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
8943If key file is password protected, give the password here.
8944Alternatively give it when starting dovecot with -p parameter. Since
8945this file is often world-readable, you may want to place this setting
8946instead to a different.
8947Defaults to @samp{""}.
8948@end deftypevr
8949
8950@deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
8951PEM encoded trusted certificate authority. Set this only if you
8952intend to use @samp{ssl-verify-client-cert? #t}. The file should
8953contain the CA certificate(s) followed by the matching
8954CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
8955Defaults to @samp{""}.
8956@end deftypevr
8957
8958@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
8959Require that CRL check succeeds for client certificates.
8960Defaults to @samp{#t}.
8961@end deftypevr
8962
8963@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
8964Request client to send a certificate. If you also want to require
8965it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
8966Defaults to @samp{#f}.
8967@end deftypevr
8968
8969@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
8970Which field from certificate to use for username. commonName and
8971x500UniqueIdentifier are the usual choices. You'll also need to set
8972@samp{auth-ssl-username-from-cert? #t}.
8973Defaults to @samp{"commonName"}.
8974@end deftypevr
8975
8976@deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
8977How often to regenerate the SSL parameters file. Generation is
8978quite CPU intensive operation. The value is in hours, 0 disables
8979regeneration entirely.
8980Defaults to @samp{168}.
8981@end deftypevr
8982
8983@deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
8984SSL protocols to use.
8985Defaults to @samp{"!SSLv2"}.
8986@end deftypevr
8987
8988@deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
8989SSL ciphers to use.
8990Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
8991@end deftypevr
8992
8993@deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
8994SSL crypto device to use, for valid values run "openssl engine".
8995Defaults to @samp{""}.
8996@end deftypevr
8997
8998@deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
8999Address to use when sending rejection mails.
9000Default is postmaster@@<your domain>. %d expands to recipient domain.
9001Defaults to @samp{""}.
9002@end deftypevr
9003
9004@deftypevr {@code{dovecot-configuration} parameter} string hostname
9005Hostname to use in various parts of sent mails (e.g. in Message-Id)
9006and in LMTP replies. Default is the system's real hostname@@domain.
9007Defaults to @samp{""}.
9008@end deftypevr
9009
9010@deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
9011If user is over quota, return with temporary failure instead of
9012bouncing the mail.
9013Defaults to @samp{#f}.
9014@end deftypevr
9015
9016@deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
9017Binary to use for sending mails.
9018Defaults to @samp{"/usr/sbin/sendmail"}.
9019@end deftypevr
9020
9021@deftypevr {@code{dovecot-configuration} parameter} string submission-host
9022If non-empty, send mails via this SMTP host[:port] instead of
9023sendmail.
9024Defaults to @samp{""}.
9025@end deftypevr
9026
9027@deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
9028Subject: header to use for rejection mails. You can use the same
9029variables as for @samp{rejection-reason} below.
9030Defaults to @samp{"Rejected: %s"}.
9031@end deftypevr
9032
9033@deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
9034Human readable error message for rejection mails. You can use
9035variables:
9036
9037@table @code
9038@item %n
9039CRLF
9040@item %r
9041reason
9042@item %s
9043original subject
9044@item %t
9045recipient
9046@end table
9047Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
9048@end deftypevr
9049
9050@deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
9051Delimiter character between local-part and detail in email
9052address.
9053Defaults to @samp{"+"}.
9054@end deftypevr
9055
9056@deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
9057Header where the original recipient address (SMTP's RCPT TO:
9058address) is taken from if not available elsewhere. With dovecot-lda -a
9059parameter overrides this. A commonly used header for this is
9060X-Original-To.
9061Defaults to @samp{""}.
9062@end deftypevr
9063
9064@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
9065Should saving a mail to a nonexistent mailbox automatically create
9066it?.
9067Defaults to @samp{#f}.
9068@end deftypevr
9069
9070@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
9071Should automatically created mailboxes be also automatically
9072subscribed?.
9073Defaults to @samp{#f}.
9074@end deftypevr
9075
9076@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
9077Maximum IMAP command line length. Some clients generate very long
9078command lines with huge mailboxes, so you may need to raise this if you
9079get "Too long argument" or "IMAP command line too large" errors
9080often.
9081Defaults to @samp{64000}.
9082@end deftypevr
9083
9084@deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
9085IMAP logout format string:
9086@table @code
9087@item %i
9088total number of bytes read from client
9089@item %o
9090total number of bytes sent to client.
9091@end table
9092Defaults to @samp{"in=%i out=%o"}.
9093@end deftypevr
9094
9095@deftypevr {@code{dovecot-configuration} parameter} string imap-capability
9096Override the IMAP CAPABILITY response. If the value begins with '+',
9097add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
9098Defaults to @samp{""}.
9099@end deftypevr
9100
9101@deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
9102How long to wait between "OK Still here" notifications when client
9103is IDLEing.
9104Defaults to @samp{"2 mins"}.
9105@end deftypevr
9106
9107@deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
9108ID field names and values to send to clients. Using * as the value
9109makes Dovecot use the default value. The following fields have default
9110values currently: name, version, os, os-version, support-url,
9111support-email.
9112Defaults to @samp{""}.
9113@end deftypevr
9114
9115@deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
9116ID fields sent by client to log. * means everything.
9117Defaults to @samp{""}.
9118@end deftypevr
9119
9120@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
9121Workarounds for various client bugs:
9122
9123@table @code
9124@item delay-newmail
9125Send EXISTS/RECENT new mail notifications only when replying to NOOP and
9126CHECK commands. Some clients ignore them otherwise, for example OSX
9127Mail (<v2.1). Outlook Express breaks more badly though, without this it
9128may show user "Message no longer in server" errors. Note that OE6
9129still breaks even with this workaround if synchronization is set to
9130"Headers Only".
9131
9132@item tb-extra-mailbox-sep
9133Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
9134adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
9135ignore the extra @samp{/} instead of treating it as invalid mailbox name.
9136
9137@item tb-lsub-flags
9138Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
9139This makes Thunderbird realize they aren't selectable and show them
9140greyed out, instead of only later giving "not selectable" popup error.
9141@end table
9142Defaults to @samp{()}.
9143@end deftypevr
9144
9145@deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
9146Host allowed in URLAUTH URLs sent by client. "*" allows all.
9147Defaults to @samp{""}.
9148@end deftypevr
9149
9150
9151Whew! Lots of configuration options. The nice thing about it though is
9152that GuixSD has a complete interface to Dovecot's configuration
9153language. This allows not only a nice way to declare configurations,
9154but also offers reflective capabilities as well: users can write code to
9155inspect and transform configurations from within Scheme.
9156
9157However, it could be that you just want to get a @code{dovecot.conf} up
9158and running. In that case, you can pass an
9159@code{opaque-dovecot-configuration} as the @code{#:config} paramter to
9160@code{dovecot-service}. As its name indicates, an opaque configuration
9161does not have easy reflective capabilities.
9162
9163Available @code{opaque-dovecot-configuration} fields are:
9164
9165@deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
9166The dovecot package.
9167@end deftypevr
9168
9169@deftypevr {@code{opaque-dovecot-configuration} parameter} string string
9170The contents of the @code{dovecot.conf}, as a string.
9171@end deftypevr
9172
9173For example, if your @code{dovecot.conf} is just the empty string, you
9174could instantiate a dovecot service like this:
9175
9176@example
9177(dovecot-service #:config
9178 (opaque-dovecot-configuration
9179 (string "")))
9180@end example
9181
58724c48
DT
9182@node Web Services
9183@subsubsection Web Services
9184
9185The @code{(gnu services web)} module provides the following service:
9186
be1c2c54 9187@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
58724c48
DT
9188 [#:log-directory ``/var/log/nginx''] @
9189 [#:run-directory ``/var/run/nginx''] @
9190 [#:config-file]
9191
9192Return a service that runs @var{nginx}, the nginx web server.
9193
9194The nginx daemon loads its runtime configuration from @var{config-file}.
9195Log files are written to @var{log-directory} and temporary runtime data
9196files are written to @var{run-directory}. For proper operation, these
9197arguments should match what is in @var{config-file} to ensure that the
9198directories are created when the service is activated.
9199
9200@end deffn
9201
fe1a39d3
LC
9202@node Various Services
9203@subsubsection Various Services
9204
9205The @code{(gnu services lirc)} module provides the following service.
9206
be1c2c54 9207@deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
fe1a39d3
LC
9208 [#:device #f] [#:driver #f] [#:config-file #f] @
9209 [#:extra-options '()]
9210Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
9211decodes infrared signals from remote controls.
9212
9213Optionally, @var{device}, @var{driver} and @var{config-file}
9214(configuration file name) may be specified. See @command{lircd} manual
9215for details.
9216
9217Finally, @var{extra-options} is a list of additional command-line options
9218passed to @command{lircd}.
9219@end deffn
9220
9221
0ae8c15a
LC
9222@node Setuid Programs
9223@subsection Setuid Programs
9224
9225@cindex setuid programs
9226Some programs need to run with ``root'' privileges, even when they are
9227launched by unprivileged users. A notorious example is the
4d40227c
LC
9228@command{passwd} program, which users can run to change their
9229password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
9230@file{/etc/shadow} files---something normally restricted to root, for
9231obvious security reasons. To address that, these executables are
9232@dfn{setuid-root}, meaning that they always run with root privileges
9233(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
f7e4ae7f 9234for more info about the setuid mechanism.)
0ae8c15a
LC
9235
9236The store itself @emph{cannot} contain setuid programs: that would be a
9237security issue since any user on the system can write derivations that
9238populate the store (@pxref{The Store}). Thus, a different mechanism is
9239used: instead of changing the setuid bit directly on files that are in
9240the store, we let the system administrator @emph{declare} which programs
9241should be setuid root.
9242
9243The @code{setuid-programs} field of an @code{operating-system}
9244declaration contains a list of G-expressions denoting the names of
9245programs to be setuid-root (@pxref{Using the Configuration System}).
9246For instance, the @command{passwd} program, which is part of the Shadow
9247package, can be designated by this G-expression (@pxref{G-Expressions}):
9248
9249@example
9250#~(string-append #$shadow "/bin/passwd")
9251@end example
9252
9253A default set of setuid programs is defined by the
9254@code{%setuid-programs} variable of the @code{(gnu system)} module.
9255
9256@defvr {Scheme Variable} %setuid-programs
9257A list of G-expressions denoting common programs that are setuid-root.
9258
9259The list includes commands such as @command{passwd}, @command{ping},
9260@command{su}, and @command{sudo}.
9261@end defvr
9262
9263Under the hood, the actual setuid programs are created in the
9264@file{/run/setuid-programs} directory at system activation time. The
9265files in this directory refer to the ``real'' binaries, which are in the
9266store.
9267
efb5e833
LC
9268@node X.509 Certificates
9269@subsection X.509 Certificates
9270
9271@cindex HTTPS, certificates
9272@cindex X.509 certificates
9273@cindex TLS
9274Web servers available over HTTPS (that is, HTTP over the transport-layer
9275security mechanism, TLS) send client programs an @dfn{X.509 certificate}
9276that the client can then use to @emph{authenticate} the server. To do
9277that, clients verify that the server's certificate is signed by a
9278so-called @dfn{certificate authority} (CA). But to verify the CA's
9279signature, clients must have first acquired the CA's certificate.
9280
9281Web browsers such as GNU@tie{}IceCat include their own set of CA
9282certificates, such that they are able to verify CA signatures
9283out-of-the-box.
9284
9285However, most other programs that can talk HTTPS---@command{wget},
9286@command{git}, @command{w3m}, etc.---need to be told where CA
9287certificates can be found.
9288
9289@cindex @code{nss-certs}
9290In GuixSD, this is done by adding a package that provides certificates
9291to the @code{packages} field of the @code{operating-system} declaration
9292(@pxref{operating-system Reference}). GuixSD includes one such package,
9293@code{nss-certs}, which is a set of CA certificates provided as part of
9294Mozilla's Network Security Services.
9295
9296Note that it is @emph{not} part of @var{%base-packages}, so you need to
9297explicitly add it. The @file{/etc/ssl/certs} directory, which is where
9298most applications and libraries look for certificates by default, points
9299to the certificates installed globally.
9300
9301Unprivileged users can also install their own certificate package in
9302their profile. A number of environment variables need to be defined so
9303that applications and libraries know where to find them. Namely, the
9304OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
9305variables. Some applications add their own environment variables; for
9306instance, the Git version control system honors the certificate bundle
9307pointed to by the @code{GIT_SSL_CAINFO} environment variable.
9308
9309
996ed739
LC
9310@node Name Service Switch
9311@subsection Name Service Switch
9312
9313@cindex name service switch
9314@cindex NSS
9315The @code{(gnu system nss)} module provides bindings to the
1068f26b 9316configuration file of the libc @dfn{name service switch} or @dfn{NSS}
996ed739
LC
9317(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
9318Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
9319extended with new ``name'' lookup methods for system databases, which
9320includes host names, service names, user accounts, and more (@pxref{Name
9321Service Switch, System Databases and Name Service Switch,, libc, The GNU
9322C Library Reference Manual}).
9323
9324The NSS configuration specifies, for each system database, which lookup
9325method is to be used, and how the various methods are chained
9326together---for instance, under which circumstances NSS should try the
9327next method in the list. The NSS configuration is given in the
9328@code{name-service-switch} field of @code{operating-system} declarations
9329(@pxref{operating-system Reference, @code{name-service-switch}}).
9330
4c9050c6
LC
9331@cindex nss-mdns
9332@cindex .local, host name lookup
996ed739 9333As an example, the declaration below configures the NSS to use the
4c9050c6
LC
9334@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
9335back-end}, which supports host name lookups over multicast DNS (mDNS)
9336for host names ending in @code{.local}:
996ed739
LC
9337
9338@example
9339(name-service-switch
9340 (hosts (list %files ;first, check /etc/hosts
9341
9342 ;; If the above did not succeed, try
9343 ;; with 'mdns_minimal'.
9344 (name-service
9345 (name "mdns_minimal")
9346
9347 ;; 'mdns_minimal' is authoritative for
9348 ;; '.local'. When it returns "not found",
9349 ;; no need to try the next methods.
9350 (reaction (lookup-specification
9351 (not-found => return))))
9352
9353 ;; Then fall back to DNS.
9354 (name-service
9355 (name "dns"))
9356
9357 ;; Finally, try with the "full" 'mdns'.
9358 (name-service
9359 (name "mdns")))))
9360@end example
9361
1068f26b
AE
9362Do not worry: the @code{%mdns-host-lookup-nss} variable (see below)
9363contains this configuration, so you will not have to type it if all you
15137a29
LC
9364want is to have @code{.local} host lookup working.
9365
4c9050c6
LC
9366Note that, in this case, in addition to setting the
9367@code{name-service-switch} of the @code{operating-system} declaration,
cc9c1f39
LC
9368you also need to use @code{avahi-service} (@pxref{Networking Services,
9369@code{avahi-service}}), or @var{%desktop-services}, which includes it
9370(@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
9371to the name service cache daemon (@pxref{Base Services,
9372@code{nscd-service}}).
15137a29
LC
9373
9374For convenience, the following variables provide typical NSS
9375configurations.
9376
9377@defvr {Scheme Variable} %default-nss
9378This is the default name service switch configuration, a
9379@code{name-service-switch} object.
9380@end defvr
9381
9382@defvr {Scheme Variable} %mdns-host-lookup-nss
9383This is the name service switch configuration with support for host name
9384lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
9385@end defvr
4c9050c6 9386
996ed739 9387The reference for name service switch configuration is given below. It
1068f26b 9388is a direct mapping of the configuration file format of the C library , so
996ed739
LC
9389please refer to the C library manual for more information (@pxref{NSS
9390Configuration File,,, libc, The GNU C Library Reference Manual}).
1068f26b 9391Compared to the configuration file format of libc NSS, it has the advantage
996ed739 9392not only of adding this warm parenthetic feel that we like, but also
1068f26b 9393static checks: you will know about syntax errors and typos as soon as you
996ed739
LC
9394run @command{guix system}.
9395
996ed739
LC
9396@deftp {Data Type} name-service-switch
9397
9398This is the data type representation the configuration of libc's name
9399service switch (NSS). Each field below represents one of the supported
9400system databases.
9401
9402@table @code
9403@item aliases
9404@itemx ethers
9405@itemx group
9406@itemx gshadow
9407@itemx hosts
9408@itemx initgroups
9409@itemx netgroup
9410@itemx networks
9411@itemx password
9412@itemx public-key
9413@itemx rpc
9414@itemx services
9415@itemx shadow
9416The system databases handled by the NSS. Each of these fields must be a
1068f26b 9417list of @code{<name-service>} objects (see below).
996ed739
LC
9418@end table
9419@end deftp
9420
9421@deftp {Data Type} name-service
9422
9423This is the data type representing an actual name service and the
9424associated lookup action.
9425
9426@table @code
9427@item name
9428A string denoting the name service (@pxref{Services in the NSS
9429configuration,,, libc, The GNU C Library Reference Manual}).
9430
4aee6e60
LC
9431Note that name services listed here must be visible to nscd. This is
9432achieved by passing the @code{#:name-services} argument to
9433@code{nscd-service} the list of packages providing the needed name
9434services (@pxref{Base Services, @code{nscd-service}}).
9435
996ed739
LC
9436@item reaction
9437An action specified using the @code{lookup-specification} macro
9438(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
9439Reference Manual}). For example:
9440
9441@example
9442(lookup-specification (unavailable => continue)
9443 (success => return))
9444@end example
9445@end table
9446@end deftp
0ae8c15a 9447
fd1b1fa2
LC
9448@node Initial RAM Disk
9449@subsection Initial RAM Disk
9450
9451@cindex initial RAM disk (initrd)
9452@cindex initrd (initial RAM disk)
9453For bootstrapping purposes, the Linux-Libre kernel is passed an
9454@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
1068f26b 9455root file system as well as an initialization script. The latter is
fd1b1fa2
LC
9456responsible for mounting the real root file system, and for loading any
9457kernel modules that may be needed to achieve that.
9458
9459The @code{initrd} field of an @code{operating-system} declaration allows
9460you to specify which initrd you would like to use. The @code{(gnu
9461system linux-initrd)} module provides two ways to build an initrd: the
9462high-level @code{base-initrd} procedure, and the low-level
9463@code{expression->initrd} procedure.
9464
9465The @code{base-initrd} procedure is intended to cover most common uses.
9466For example, if you want to add a bunch of kernel modules to be loaded
9467at boot time, you can define the @code{initrd} field of the operating
9468system declaration like this:
9469
9470@example
52ac153e 9471(initrd (lambda (file-systems . rest)
027981d6
LC
9472 ;; Create a standard initrd that has modules "foo.ko"
9473 ;; and "bar.ko", as well as their dependencies, in
9474 ;; addition to the modules available by default.
52ac153e 9475 (apply base-initrd file-systems
027981d6 9476 #:extra-modules '("foo" "bar")
52ac153e 9477 rest)))
fd1b1fa2
LC
9478@end example
9479
52ac153e 9480The @code{base-initrd} procedure also handles common use cases that
1068f26b
AE
9481involves using the system as a QEMU guest, or as a ``live'' system with
9482volatile root file system.
fd1b1fa2 9483
e90cf6c1
LC
9484The initial RAM disk produced by @code{base-initrd} honors several
9485options passed on the Linux kernel command line (that is, arguments
1068f26b
AE
9486passed @i{via} the @code{linux} command of GRUB, or the
9487@code{-append} option) of QEMU, notably:
e90cf6c1
LC
9488
9489@table @code
9490@item --load=@var{boot}
9491Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
9492program, once it has mounted the root file system.
9493
9494GuixSD uses this option to yield control to a boot program that runs the
dd17bc38 9495service activation programs and then spawns the GNU@tie{}Shepherd, the
e90cf6c1
LC
9496initialization system.
9497
9498@item --root=@var{root}
1068f26b 9499Mount @var{root} as the root file system. @var{root} can be a
e90cf6c1
LC
9500device name like @code{/dev/sda1}, a partition label, or a partition
9501UUID.
9502
9503@item --system=@var{system}
9504Have @file{/run/booted-system} and @file{/run/current-system} point to
9505@var{system}.
9506
9507@item modprobe.blacklist=@var{modules}@dots{}
9508@cindex module, black-listing
9509@cindex black list, of kernel modules
9510Instruct the initial RAM disk as well as the @command{modprobe} command
9511(from the kmod package) to refuse to load @var{modules}. @var{modules}
9512must be a comma-separated list of module names---e.g.,
9513@code{usbkbd,9pnet}.
9514
9515@item --repl
9516Start a read-eval-print loop (REPL) from the initial RAM disk before it
9517tries to load kernel modules and to mount the root file system. Our
9518marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
9519love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
9520Manual}, for more information on Guile's REPL.
9521
9522@end table
9523
9524Now that you know all the features that initial RAM disks produced by
9525@code{base-initrd} provide, here is how to use it and customize it
9526further.
9527
fd1b1fa2 9528@deffn {Monadic Procedure} base-initrd @var{file-systems} @
9059b97d 9529 [#:qemu-networking? #f] [#:virtio? #t] [#:volatile-root? #f] @
52ac153e 9530 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2 9531Return a monadic derivation that builds a generic initrd. @var{file-systems} is
1068f26b 9532a list of file systems to be mounted by the initrd, possibly in addition to
fd1b1fa2 9533the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
9534@var{mapped-devices} is a list of device mappings to realize before
9535@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
9536
9537When @var{qemu-networking?} is true, set up networking with the standard QEMU
1068f26b
AE
9538parameters. When @var{virtio?} is true, load additional modules so that the
9539initrd can be used as a QEMU guest with para-virtualized I/O drivers.
fd1b1fa2
LC
9540
9541When @var{volatile-root?} is true, the root file system is writable but any changes
9542to it are lost.
9543
9544The initrd is automatically populated with all the kernel modules necessary
9545for @var{file-systems} and for the given options. However, additional kernel
9546modules can be listed in @var{extra-modules}. They will be added to the initrd, and
9547loaded at boot time in the order in which they appear.
9548@end deffn
9549
9550Needless to say, the initrds we produce and use embed a
9551statically-linked Guile, and the initialization program is a Guile
9552program. That gives a lot of flexibility. The
9553@code{expression->initrd} procedure builds such an initrd, given the
9554program to run in that initrd.
9555
9556@deffn {Monadic Procedure} expression->initrd @var{exp} @
9557 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
42d10464 9558 [#:modules '()]
fd1b1fa2
LC
9559Return a derivation that builds a Linux initrd (a gzipped cpio archive)
9560containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
9561upon booting. All the derivations referenced by @var{exp} are
9562automatically copied to the initrd.
fd1b1fa2 9563
42d10464
LC
9564@var{modules} is a list of Guile module names to be embedded in the
9565initrd.
fd1b1fa2
LC
9566@end deffn
9567
88faf933
LC
9568@node GRUB Configuration
9569@subsection GRUB Configuration
9570
9571@cindex GRUB
9572@cindex boot loader
9573
9574The operating system uses GNU@tie{}GRUB as its boot loader
9575(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
1068f26b
AE
9576configured using a @code{grub-configuration} declaration. This data type
9577is exported by the @code{(gnu system grub)} module and described below.
88faf933
LC
9578
9579@deftp {Data Type} grub-configuration
9580The type of a GRUB configuration declaration.
9581
9582@table @asis
9583
9584@item @code{device}
9585This is a string denoting the boot device. It must be a device name
9586understood by the @command{grub-install} command, such as
9587@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
9588GNU GRUB Manual}).
9589
9590@item @code{menu-entries} (default: @code{()})
9591A possibly empty list of @code{menu-entry} objects (see below), denoting
9592entries to appear in the GRUB boot menu, in addition to the current
9593system entry and the entry pointing to previous system generations.
9594
9595@item @code{default-entry} (default: @code{0})
1068f26b
AE
9596The index of the default boot menu entry. Index 0 is for the entry of the
9597current system.
88faf933
LC
9598
9599@item @code{timeout} (default: @code{5})
9600The number of seconds to wait for keyboard input before booting. Set to
96010 to boot immediately, and to -1 to wait indefinitely.
9602
9603@item @code{theme} (default: @var{%default-theme})
9604The @code{grub-theme} object describing the theme to use.
9605@end table
9606
9607@end deftp
9608
9609Should you want to list additional boot menu entries @i{via} the
9610@code{menu-entries} field above, you will need to create them with the
9611@code{menu-entry} form:
9612
9613@deftp {Data Type} menu-entry
9614The type of an entry in the GRUB boot menu.
9615
9616@table @asis
9617
9618@item @code{label}
35ed9306 9619The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
9620
9621@item @code{linux}
9622The Linux kernel to boot.
9623
9624@item @code{linux-arguments} (default: @code{()})
9625The list of extra Linux kernel command-line arguments---e.g.,
9626@code{("console=ttyS0")}.
9627
9628@item @code{initrd}
9629A G-Expression or string denoting the file name of the initial RAM disk
9630to use (@pxref{G-Expressions}).
9631
9632@end table
9633@end deftp
9634
9635@c FIXME: Write documentation once it's stable.
9636Themes are created using the @code{grub-theme} form, which is not
9637documented yet.
9638
9639@defvr {Scheme Variable} %default-theme
9640This is the default GRUB theme used by the operating system, with a
9641fancy background image displaying the GNU and Guix logos.
9642@end defvr
9643
9644
cf4a9129
LC
9645@node Invoking guix system
9646@subsection Invoking @code{guix system}
0918e64a 9647
1068f26b 9648Once you have written an operating system declaration as seen in the
cf4a9129
LC
9649previous section, it can be @dfn{instantiated} using the @command{guix
9650system} command. The synopsis is:
4af2447e 9651
cf4a9129
LC
9652@example
9653guix system @var{options}@dots{} @var{action} @var{file}
9654@end example
4af2447e 9655
cf4a9129
LC
9656@var{file} must be the name of a file containing an
9657@code{operating-system} declaration. @var{action} specifies how the
a40424bd 9658operating system is instantiated. Currently the following values are
cf4a9129 9659supported:
4af2447e 9660
cf4a9129
LC
9661@table @code
9662@item reconfigure
9663Build the operating system described in @var{file}, activate it, and
9664switch to it@footnote{This action is usable only on systems already
65797bff 9665running GuixSD.}.
4af2447e 9666
cf4a9129
LC
9667This effects all the configuration specified in @var{file}: user
9668accounts, system services, global package list, setuid programs, etc.
240b57f0
LC
9669The command starts system services specified in @var{file} that are not
9670currently running; if a service is currently running, it does not
1068f26b 9671attempt to upgrade it since this would not be possible without stopping it
240b57f0 9672first.
4af2447e 9673
cf4a9129
LC
9674It also adds a GRUB menu entry for the new OS configuration, and moves
9675entries for older configurations to a submenu---unless
9676@option{--no-grub} is passed.
4af2447e 9677
240b57f0 9678@quotation Note
bf2479c7
LC
9679@c The paragraph below refers to the problem discussed at
9680@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
9681It is highly recommended to run @command{guix pull} once before you run
9682@command{guix system reconfigure} for the first time (@pxref{Invoking
9683guix pull}). Failing to do that you would see an older version of Guix
9684once @command{reconfigure} has completed.
240b57f0 9685@end quotation
bf2479c7 9686
cf4a9129 9687@item build
1068f26b 9688Build the derivation of the operating system, which includes all the
cf4a9129
LC
9689configuration files and programs needed to boot and run the system.
9690This action does not actually install anything.
113daf62 9691
cf4a9129
LC
9692@item init
9693Populate the given directory with all the files necessary to run the
9694operating system specified in @var{file}. This is useful for first-time
4705641f 9695installations of GuixSD. For instance:
113daf62
LC
9696
9697@example
cf4a9129 9698guix system init my-os-config.scm /mnt
113daf62
LC
9699@end example
9700
cf4a9129
LC
9701copies to @file{/mnt} all the store items required by the configuration
9702specified in @file{my-os-config.scm}. This includes configuration
9703files, packages, and so on. It also creates other essential files
9704needed for the system to operate correctly---e.g., the @file{/etc},
9705@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 9706
cf4a9129
LC
9707This command also installs GRUB on the device specified in
9708@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 9709
cf4a9129
LC
9710@item vm
9711@cindex virtual machine
0276f697 9712@cindex VM
f535dcbe 9713@anchor{guix system vm}
1068f26b 9714Build a virtual machine that contains the operating system declared in
cf4a9129 9715@var{file}, and return a script to run that virtual machine (VM).
1068f26b 9716Arguments given to the script are passed to QEMU.
113daf62 9717
cf4a9129 9718The VM shares its store with the host system.
113daf62 9719
0276f697
LC
9720Additional file systems can be shared between the host and the VM using
9721the @code{--share} and @code{--expose} command-line options: the former
9722specifies a directory to be shared with write access, while the latter
9723provides read-only access to the shared directory.
9724
9725The example below creates a VM in which the user's home directory is
9726accessible read-only, and where the @file{/exchange} directory is a
1068f26b 9727read-write mapping of @file{$HOME/tmp} on the host:
0276f697
LC
9728
9729@example
9730guix system vm my-config.scm \
9731 --expose=$HOME --share=$HOME/tmp=/exchange
9732@end example
9733
6aa260af
LC
9734On GNU/Linux, the default is to boot directly to the kernel; this has
9735the advantage of requiring only a very tiny root disk image since the
1068f26b 9736store of the host can then be mounted.
6aa260af
LC
9737
9738The @code{--full-boot} option forces a complete boot sequence, starting
9739with the bootloader. This requires more disk space since a root image
9740containing at least the kernel, initrd, and bootloader data files must
9741be created. The @code{--image-size} option can be used to specify the
1068f26b 9742size of the image.
ab11f0be 9743
cf4a9129
LC
9744@item vm-image
9745@itemx disk-image
9746Return a virtual machine or disk image of the operating system declared
9747in @var{file} that stands alone. Use the @option{--image-size} option
9748to specify the size of the image.
113daf62 9749
cf4a9129 9750When using @code{vm-image}, the returned image is in qcow2 format, which
97d76250
LF
9751the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
9752for more information on how to run the image in a virtual machine.
113daf62 9753
cf4a9129
LC
9754When using @code{disk-image}, a raw disk image is produced; it can be
9755copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
1068f26b 9756the device corresponding to a USB stick, one can copy the image to it
cf4a9129 9757using the following command:
113daf62 9758
cf4a9129
LC
9759@example
9760# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
9761@end example
113daf62 9762
1c8a81b1
DT
9763@item container
9764Return a script to run the operating system declared in @var{file}
9765within a container. Containers are a set of lightweight isolation
9766mechanisms provided by the kernel Linux-libre. Containers are
9767substantially less resource-demanding than full virtual machines since
9768the kernel, shared objects, and other resources can be shared with the
9769host system; this also means they provide thinner isolation.
9770
9771Currently, the script must be run as root in order to support more than
9772a single user and group. The container shares its store with the host
9773system.
9774
9775As with the @code{vm} action (@pxref{guix system vm}), additional file
9776systems to be shared between the host and container can be specified
9777using the @option{--share} and @option{--expose} options:
9778
9779@example
9780guix system container my-config.scm \
9781 --expose=$HOME --share=$HOME/tmp=/exchange
9782@end example
9783
0f252e26 9784@quotation Note
cfd35b4e 9785This option requires Linux-libre 3.19 or newer.
0f252e26
DT
9786@end quotation
9787
cf4a9129 9788@end table
113daf62 9789
ccd7158d
LC
9790@var{options} can contain any of the common build options (@pxref{Common
9791Build Options}). In addition, @var{options} can contain one of the
9792following:
113daf62 9793
cf4a9129
LC
9794@table @option
9795@item --system=@var{system}
9796@itemx -s @var{system}
1068f26b 9797Attempt to build for @var{system} instead of the host system type.
cf4a9129 9798This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 9799
f3f427c2
LC
9800@item --derivation
9801@itemx -d
9802Return the derivation file name of the given operating system without
9803building anything.
9804
cf4a9129
LC
9805@item --image-size=@var{size}
9806For the @code{vm-image} and @code{disk-image} actions, create an image
9807of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
9808include a unit as a suffix (@pxref{Block size, size specifications,,
9809coreutils, GNU Coreutils}).
db030303
LC
9810
9811@item --on-error=@var{strategy}
9812Apply @var{strategy} when an error occurs when reading @var{file}.
9813@var{strategy} may be one of the following:
9814
9815@table @code
9816@item nothing-special
9817Report the error concisely and exit. This is the default strategy.
9818
9819@item backtrace
9820Likewise, but also display a backtrace.
9821
9822@item debug
9823Report the error and enter Guile's debugger. From there, you can run
9824commands such as @code{,bt} to get a backtrace, @code{,locals} to
1068f26b
AE
9825display local variable values, and more generally inspect the state of the
9826program. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
db030303
LC
9827a list of available debugging commands.
9828@end table
113daf62 9829@end table
113daf62 9830
cf4a9129
LC
9831Note that all the actions above, except @code{build} and @code{init},
9832rely on KVM support in the Linux-Libre kernel. Specifically, the
9833machine should have hardware virtualization support, the corresponding
9834KVM kernel module should be loaded, and the @file{/dev/kvm} device node
1068f26b
AE
9835must exist and be readable and writable by the user and by the
9836build users of the daemon.
8451a568 9837
65797bff
LC
9838Once you have built, configured, re-configured, and re-re-configured
9839your GuixSD installation, you may find it useful to list the operating
9840system generations available on disk---and that you can choose from the
9841GRUB boot menu:
9842
9843@table @code
9844
9845@item list-generations
9846List a summary of each generation of the operating system available on
9847disk, in a human-readable way. This is similar to the
9848@option{--list-generations} option of @command{guix package}
9849(@pxref{Invoking guix package}).
9850
9851Optionally, one can specify a pattern, with the same syntax that is used
9852in @command{guix package --list-generations}, to restrict the list of
9853generations displayed. For instance, the following command displays
1068f26b 9854generations that are up to 10 days old:
65797bff
LC
9855
9856@example
9857$ guix system list-generations 10d
9858@end example
9859
9860@end table
9861
d6c3267a
LC
9862The @command{guix system} command has even more to offer! The following
9863sub-commands allow you to visualize how your system services relate to
9864each other:
9865
9866@anchor{system-extension-graph}
9867@table @code
9868
9869@item extension-graph
9870Emit in Dot/Graphviz format to standard output the @dfn{service
9871extension graph} of the operating system defined in @var{file}
9872(@pxref{Service Composition}, for more information on service
9873extensions.)
9874
9875The command:
9876
9877@example
9878$ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
9879@end example
9880
9881produces a PDF file showing the extension relations among services.
9882
710fa231
AK
9883@anchor{system-shepherd-graph}
9884@item shepherd-graph
6f305ea5 9885Emit in Dot/Graphviz format to standard output the @dfn{dependency
dd17bc38
AK
9886graph} of shepherd services of the operating system defined in
9887@var{file}. @xref{Shepherd Services}, for more information and for an
9888example graph.
6f305ea5 9889
d6c3267a
LC
9890@end table
9891
97d76250 9892@node Running GuixSD in a VM
70ac09a5 9893@subsection Running GuixSD in a Virtual Machine
97d76250
LF
9894
9895One way to run GuixSD in a virtual machine (VM) is to build a GuixSD
9896virtual machine image using @command{guix system vm-image}
9897(@pxref{Invoking guix system}). The returned image is in qcow2 format,
9898which the @uref{http://qemu.org/, QEMU emulator} can efficiently use.
9899
9900To run the image in QEMU, copy it out of the store (@pxref{The Store})
9901and give yourself permission to write to the copy. When invoking QEMU,
9902you must choose a system emulator that is suitable for your hardware
9903platform. Here is a minimal QEMU invocation that will boot the result
9904of @command{guix system vm-image} on x86_64 hardware:
9905
9906@example
9907$ qemu-system-x86_64 \
9908 -net user -net nic,model=virtio \
9909 -enable-kvm -m 256 /tmp/qemu-image
9910@end example
9911
9912Here is what each of these options means:
9913
9914@table @code
9915@item qemu-system-x86_64
9916This specifies the hardware platform to emulate. This should match the
9917host.
9918
9919@item -net user
9920Enable the unprivileged user-mode network stack. The guest OS can
9921access the host but not vice versa. This is the simplest way to get the
1068f26b 9922guest OS online. If you do not choose a network stack, the boot will
97d76250
LF
9923fail.
9924
9925@item -net nic,model=virtio
1068f26b 9926You must create a network interface of a given model. If you do not
97d76250
LF
9927create a NIC, the boot will fail. Assuming your hardware platform is
9928x86_64, you can get a list of available NIC models by running
9929@command{qemu-system-x86_64 -net nic,model=help}.
9930
9931@item -enable-kvm
9932If your system has hardware virtualization extensions, enabling the
1068f26b 9933virtual machine support (KVM) of the Linux kernel will make things run
97d76250
LF
9934faster.
9935
9936@item -m 256
9937RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
9938which may be insufficent for some operations.
9939
9940@item /tmp/qemu-image
9941The file name of the qcow2 image.
9942@end table
d6c3267a 9943
cf4a9129
LC
9944@node Defining Services
9945@subsection Defining Services
8451a568 9946
eb524192 9947The previous sections show the available services and how one can combine
0adfe95a
LC
9948them in an @code{operating-system} declaration. But how do we define
9949them in the first place? And what is a service anyway?
8451a568 9950
0adfe95a
LC
9951@menu
9952* Service Composition:: The model for composing services.
9953* Service Types and Services:: Types and services.
9954* Service Reference:: API reference.
dd17bc38 9955* Shepherd Services:: A particular type of service.
0adfe95a
LC
9956@end menu
9957
9958@node Service Composition
9959@subsubsection Service Composition
9960
9961@cindex services
9962@cindex daemons
9963Here we define a @dfn{service} as, broadly, something that extends the
1068f26b 9964functionality of the operating system. Often a service is a process---a
0adfe95a
LC
9965@dfn{daemon}---started when the system boots: a secure shell server, a
9966Web server, the Guix build daemon, etc. Sometimes a service is a daemon
9967whose execution can be triggered by another daemon---e.g., an FTP server
9968started by @command{inetd} or a D-Bus service activated by
9969@command{dbus-daemon}. Occasionally, a service does not map to a
9970daemon. For instance, the ``account'' service collects user accounts
9971and makes sure they exist when the system runs; the ``udev'' service
9972collects device management rules and makes them available to the eudev
1068f26b
AE
9973daemon; the @file{/etc} service populates the @file{/etc} directory
9974of the system.
0adfe95a 9975
d6c3267a 9976@cindex service extensions
0adfe95a 9977GuixSD services are connected by @dfn{extensions}. For instance, the
1068f26b 9978secure shell service @emph{extends} the Shepherd---the GuixSD
dd17bc38
AK
9979initialization system, running as PID@tie{}1---by giving it the command
9980lines to start and stop the secure shell daemon (@pxref{Networking
9981Services, @code{lsh-service}}); the UPower service extends the D-Bus
9982service by passing it its @file{.service} specification, and extends the
9983udev service by passing it device management rules (@pxref{Desktop
9984Services, @code{upower-service}}); the Guix daemon service extends the
9985Shepherd by passing it the command lines to start and stop the daemon,
9986and extends the account service by passing it a list of required build
9987user accounts (@pxref{Base Services}).
0adfe95a
LC
9988
9989All in all, services and their ``extends'' relations form a directed
9990acyclic graph (DAG). If we represent services as boxes and extensions
9991as arrows, a typical system might provide something like this:
9992
9993@image{images/service-graph,,5in,Typical service extension graph.}
9994
d62e201c
LC
9995@cindex system service
9996At the bottom, we see the @dfn{system service}, which produces the
9997directory containing everything to run and boot the system, as returned
9998by the @command{guix system build} command. @xref{Service Reference},
9999to learn about the other service types shown here.
d6c3267a
LC
10000@xref{system-extension-graph, the @command{guix system extension-graph}
10001command}, for information on how to generate this representation for a
10002particular operating system definition.
0adfe95a
LC
10003
10004@cindex service types
10005Technically, developers can define @dfn{service types} to express these
10006relations. There can be any number of services of a given type on the
10007system---for instance, a system running two instances of the GNU secure
10008shell server (lsh) has two instances of @var{lsh-service-type}, with
10009different parameters.
10010
10011The following section describes the programming interface for service
10012types and services.
10013
10014@node Service Types and Services
10015@subsubsection Service Types and Services
10016
10017A @dfn{service type} is a node in the DAG described above. Let us start
10018with a simple example, the service type for the Guix build daemon
10019(@pxref{Invoking guix-daemon}):
10020
10021@example
10022(define guix-service-type
10023 (service-type
10024 (name 'guix)
10025 (extensions
d4053c71 10026 (list (service-extension shepherd-root-service-type guix-shepherd-service)
0adfe95a
LC
10027 (service-extension account-service-type guix-accounts)
10028 (service-extension activation-service-type guix-activation)))))
10029@end example
8451a568 10030
cf4a9129 10031@noindent
1068f26b 10032It defines two things:
0adfe95a
LC
10033
10034@enumerate
10035@item
10036A name, whose sole purpose is to make inspection and debugging easier.
10037
10038@item
10039A list of @dfn{service extensions}, where each extension designates the
1068f26b
AE
10040target service type and a procedure that, given the parameters of the
10041service, returns a list of objects to extend the service of that type.
0adfe95a
LC
10042
10043Every service type has at least one service extension. The only
10044exception is the @dfn{boot service type}, which is the ultimate service.
10045@end enumerate
10046
10047In this example, @var{guix-service-type} extends three services:
10048
10049@table @var
d4053c71
AK
10050@item shepherd-root-service-type
10051The @var{guix-shepherd-service} procedure defines how the Shepherd
10052service is extended. Namely, it returns a @code{<shepherd-service>}
10053object that defines how @command{guix-daemon} is started and stopped
10054(@pxref{Shepherd Services}).
0adfe95a
LC
10055
10056@item account-service-type
10057This extension for this service is computed by @var{guix-accounts},
10058which returns a list of @code{user-group} and @code{user-account}
10059objects representing the build user accounts (@pxref{Invoking
10060guix-daemon}).
10061
10062@item activation-service-type
10063Here @var{guix-activation} is a procedure that returns a gexp, which is
10064a code snippet to run at ``activation time''---e.g., when the service is
10065booted.
10066@end table
10067
10068A service of this type is instantiated like this:
10069
10070@example
10071(service guix-service-type
10072 (guix-configuration
10073 (build-accounts 5)
10074 (use-substitutes? #f)))
10075@end example
10076
10077The second argument to the @code{service} form is a value representing
10078the parameters of this specific service instance.
10079@xref{guix-configuration-type, @code{guix-configuration}}, for
10080information about the @code{guix-configuration} data type.
10081
10082@var{guix-service-type} is quite simple because it extends other
10083services but is not extensible itself.
10084
10085@c @subsubsubsection Extensible Service Types
10086
10087The service type for an @emph{extensible} service looks like this:
10088
10089@example
10090(define udev-service-type
10091 (service-type (name 'udev)
10092 (extensions
d4053c71
AK
10093 (list (service-extension shepherd-root-service-type
10094 udev-shepherd-service)))
0adfe95a
LC
10095
10096 (compose concatenate) ;concatenate the list of rules
10097 (extend (lambda (config rules)
10098 (match config
10099 (($ <udev-configuration> udev initial-rules)
10100 (udev-configuration
10101 (udev udev) ;the udev package to use
10102 (rules (append initial-rules rules)))))))))
10103@end example
10104
10105This is the service type for the
10106@uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
10107management daemon}. Compared to the previous example, in addition to an
d4053c71 10108extension of @var{shepherd-root-service-type}, we see two new fields:
0adfe95a
LC
10109
10110@table @code
10111@item compose
10112This is the procedure to @dfn{compose} the list of extensions to
10113services of this type.
10114
10115Services can extend the udev service by passing it lists of rules; we
10116compose those extensions simply by concatenating them.
10117
10118@item extend
1068f26b 10119This procedure defines how the value of the service is @dfn{extended} with
0adfe95a
LC
10120the composition of the extensions.
10121
10122Udev extensions are composed into a list of rules, but the udev service
10123value is itself a @code{<udev-configuration>} record. So here, we
a40424bd 10124extend that record by appending the list of rules it contains to the
0adfe95a
LC
10125list of contributed rules.
10126@end table
10127
10128There can be only one instance of an extensible service type such as
10129@var{udev-service-type}. If there were more, the
10130@code{service-extension} specifications would be ambiguous.
10131
10132Still here? The next section provides a reference of the programming
10133interface for services.
10134
10135@node Service Reference
10136@subsubsection Service Reference
10137
10138We have seen an overview of service types (@pxref{Service Types and
10139Services}). This section provides a reference on how to manipulate
10140services and service types. This interface is provided by the
10141@code{(gnu services)} module.
10142
10143@deffn {Scheme Procedure} service @var{type} @var{value}
10144Return a new service of @var{type}, a @code{<service-type>} object (see
10145below.) @var{value} can be any object; it represents the parameters of
10146this particular service instance.
10147@end deffn
10148
10149@deffn {Scheme Procedure} service? @var{obj}
10150Return true if @var{obj} is a service.
10151@end deffn
8451a568 10152
0adfe95a
LC
10153@deffn {Scheme Procedure} service-kind @var{service}
10154Return the type of @var{service}---i.e., a @code{<service-type>} object.
10155@end deffn
10156
10157@deffn {Scheme Procedure} service-parameters @var{service}
10158Return the value associated with @var{service}. It represents its
10159parameters.
10160@end deffn
10161
10162Here is an example of how a service is created and manipulated:
10163
10164@example
10165(define s
10166 (service nginx-service-type
10167 (nginx-configuration
10168 (nginx nginx)
10169 (log-directory log-directory)
10170 (run-directory run-directory)
10171 (file config-file))))
10172
10173(service? s)
10174@result{} #t
10175
10176(eq? (service-kind s) nginx-service-type)
10177@result{} #t
10178@end example
10179
cd6f6c22
LC
10180The @code{modify-services} form provides a handy way to change the
10181parameters of some of the services of a list such as
4d343a14
CM
10182@var{%base-services} (@pxref{Base Services, @code{%base-services}}). It
10183evalutes to a list of services. Of course, you could always use
10184standard list combinators such as @code{map} and @code{fold} to do that
10185(@pxref{SRFI-1, List Library,, guile, GNU Guile Reference Manual});
10186@code{modify-services} simply provides a more concise form for this
10187common pattern.
cd6f6c22
LC
10188
10189@deffn {Scheme Syntax} modify-services @var{services} @
10190 (@var{type} @var{variable} => @var{body}) @dots{}
10191
10192Modify the services listed in @var{services} according to the given
10193clauses. Each clause has the form:
10194
10195@example
10196(@var{type} @var{variable} => @var{body})
10197@end example
10198
4d343a14
CM
10199where @var{type} is a service type---e.g.,
10200@code{guix-service-type}---and @var{variable} is an identifier that is
10201bound within the @var{body} to the service parameters---e.g., a
10202@code{guix-configuration} instance---of the original service of that
10203@var{type}.
cd6f6c22 10204
4d343a14
CM
10205The @var{body} should evaluate to the new service parameters, which will
10206be used to configure the new service. This new service will replace the
10207original in the resulting list. Because a service's service parameters
10208are created using @code{define-record-type*}, you can write a succint
10209@var{body} that evaluates to the new service parameters by using the
10210@code{inherit} feature that @code{define-record-type*} provides.
10211
b53daad0 10212@xref{Using the Configuration System}, for example usage.
cd6f6c22 10213
cd6f6c22
LC
10214@end deffn
10215
10216Next comes the programming interface for service types. This is
10217something you want to know when writing new service definitions, but not
10218necessarily when simply looking for ways to customize your
10219@code{operating-system} declaration.
10220
0adfe95a
LC
10221@deftp {Data Type} service-type
10222@cindex service type
10223This is the representation of a @dfn{service type} (@pxref{Service Types
10224and Services}).
10225
10226@table @asis
10227@item @code{name}
10228This is a symbol, used only to simplify inspection and debugging.
10229
10230@item @code{extensions}
1068f26b 10231A non-empty list of @code{<service-extension>} objects (see below).
0adfe95a
LC
10232
10233@item @code{compose} (default: @code{#f})
10234If this is @code{#f}, then the service type denotes services that cannot
10235be extended---i.e., services that do not receive ``values'' from other
10236services.
10237
10238Otherwise, it must be a one-argument procedure. The procedure is called
10239by @code{fold-services} and is passed a list of values collected from
10240extensions. It must return a value that is a valid parameter value for
10241the service instance.
10242
10243@item @code{extend} (default: @code{#f})
10244If this is @code{#f}, services of this type cannot be extended.
10245
10246Otherwise, it must be a two-argument procedure: @code{fold-services}
1068f26b 10247calls it, passing it the initial value of the service as the first argument
0adfe95a
LC
10248and the result of applying @code{compose} to the extension values as the
10249second argument.
10250@end table
10251
10252@xref{Service Types and Services}, for examples.
10253@end deftp
10254
10255@deffn {Scheme Procedure} service-extension @var{target-type} @
10256 @var{compute}
10257Return a new extension for services of type @var{target-type}.
10258@var{compute} must be a one-argument procedure: @code{fold-services}
10259calls it, passing it the value associated with the service that provides
10260the extension; it must return a valid value for the target service.
10261@end deffn
10262
10263@deffn {Scheme Procedure} service-extension? @var{obj}
10264Return true if @var{obj} is a service extension.
10265@end deffn
10266
10267At the core of the service abstraction lies the @code{fold-services}
10268procedure, which is responsible for ``compiling'' a list of services
d62e201c
LC
10269down to a single directory that contains everything needed to boot and
10270run the system---the directory shown by the @command{guix system build}
10271command (@pxref{Invoking guix system}). In essence, it propagates
10272service extensions down the service graph, updating each node parameters
10273on the way, until it reaches the root node.
0adfe95a
LC
10274
10275@deffn {Scheme Procedure} fold-services @var{services} @
d62e201c 10276 [#:target-type @var{system-service-type}]
0adfe95a
LC
10277Fold @var{services} by propagating their extensions down to the root of
10278type @var{target-type}; return the root service adjusted accordingly.
10279@end deffn
10280
10281Lastly, the @code{(gnu services)} module also defines several essential
10282service types, some of which are listed below.
10283
d62e201c
LC
10284@defvr {Scheme Variable} system-service-type
10285This is the root of the service graph. It produces the system directory
10286as returned by the @command{guix system build} command.
10287@end defvr
10288
0adfe95a 10289@defvr {Scheme Variable} boot-service-type
d62e201c
LC
10290The type of the ``boot service'', which produces the @dfn{boot script}.
10291The boot script is what the initial RAM disk runs when booting.
0adfe95a
LC
10292@end defvr
10293
10294@defvr {Scheme Variable} etc-service-type
10295The type of the @file{/etc} service. This service can be extended by
10296passing it name/file tuples such as:
10297
10298@example
10299(list `("issue" ,(plain-file "issue" "Welcome!\n")))
10300@end example
10301
10302In this example, the effect would be to add an @file{/etc/issue} file
10303pointing to the given file.
10304@end defvr
10305
10306@defvr {Scheme Variable} setuid-program-service-type
10307Type for the ``setuid-program service''. This service collects lists of
10308executable file names, passed as gexps, and adds them to the set of
10309setuid-root programs on the system (@pxref{Setuid Programs}).
10310@end defvr
10311
af4c3fd5
LC
10312@defvr {Scheme Variable} profile-service-type
10313Type of the service that populates the @dfn{system profile}---i.e., the
10314programs under @file{/run/current-system/profile}. Other services can
10315extend it by passing it lists of packages to add to the system profile.
10316@end defvr
10317
0adfe95a 10318
dd17bc38
AK
10319@node Shepherd Services
10320@subsubsection Shepherd Services
0adfe95a
LC
10321
10322@cindex PID 1
10323@cindex init system
a40424bd
CM
10324The @code{(gnu services shepherd)} module provides a way to define
10325services managed by the GNU@tie{}Shepherd, which is the GuixSD
10326initialization system---the first process that is started when the
1068f26b
AE
10327system boots, also known as PID@tie{}1
10328(@pxref{Introduction,,, shepherd, The GNU Shepherd Manual}).
6f305ea5 10329
dd17bc38
AK
10330Services in the Shepherd can depend on each other. For instance, the
10331SSH daemon may need to be started after the syslog daemon has been
10332started, which in turn can only happen once all the file systems have
10333been mounted. The simple operating system defined earlier (@pxref{Using
10334the Configuration System}) results in a service graph like this:
6f305ea5 10335
710fa231 10336@image{images/shepherd-graph,,5in,Typical shepherd service graph.}
6f305ea5
LC
10337
10338You can actually generate such a graph for any operating system
710fa231
AK
10339definition using the @command{guix system shepherd-graph} command
10340(@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
6f305ea5 10341
d4053c71
AK
10342The @var{%shepherd-root-service} is a service object representing
10343PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
10344by passing it lists of @code{<shepherd-service>} objects.
0adfe95a 10345
d4053c71 10346@deftp {Data Type} shepherd-service
dd17bc38 10347The data type representing a service managed by the Shepherd.
0adfe95a
LC
10348
10349@table @asis
10350@item @code{provision}
10351This is a list of symbols denoting what the service provides.
10352
dd17bc38
AK
10353These are the names that may be passed to @command{herd start},
10354@command{herd status}, and similar commands (@pxref{Invoking herd,,,
10355shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
10356@code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
0adfe95a
LC
10357
10358@item @code{requirements} (default: @code{'()})
dd17bc38 10359List of symbols denoting the Shepherd services this one depends on.
0adfe95a
LC
10360
10361@item @code{respawn?} (default: @code{#t})
10362Whether to restart the service when it stops, for instance when the
10363underlying process dies.
10364
10365@item @code{start}
10366@itemx @code{stop} (default: @code{#~(const #f)})
dd17bc38
AK
10367The @code{start} and @code{stop} fields refer to the Shepherd's
10368facilities to start and stop processes (@pxref{Service De- and
10369Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
10370G-expressions that get expanded in the Shepherd configuration file
10371(@pxref{G-Expressions}).
0adfe95a
LC
10372
10373@item @code{documentation}
10374A documentation string, as shown when running:
10375
10376@example
dd17bc38 10377herd doc @var{service-name}
0adfe95a
LC
10378@end example
10379
10380where @var{service-name} is one of the symbols in @var{provision}
dd17bc38 10381(@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
fae685b9
LC
10382
10383@item @code{modules} (default: @var{%default-modules})
10384This is the list of modules that must be in scope when @code{start} and
10385@code{stop} are evaluated.
10386
10387@item @code{imported-modules} (default: @var{%default-imported-modules})
10388This is the list of modules to import in the execution environment of
dd17bc38 10389the Shepherd.
fae685b9 10390
0adfe95a
LC
10391@end table
10392@end deftp
10393
d4053c71 10394@defvr {Scheme Variable} shepherd-root-service-type
dd17bc38 10395The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
0adfe95a
LC
10396
10397This is the service type that extensions target when they want to create
dd17bc38 10398shepherd services (@pxref{Service Types and Services}, for an example).
d4053c71 10399Each extension must pass a list of @code{<shepherd-service>}.
0adfe95a
LC
10400@end defvr
10401
d4053c71 10402@defvr {Scheme Variable} %shepherd-root-service
0adfe95a
LC
10403This service represents PID@tie{}1.
10404@end defvr
8451a568 10405
8451a568 10406
cf4a9129
LC
10407@node Installing Debugging Files
10408@section Installing Debugging Files
8451a568 10409
cf4a9129
LC
10410@cindex debugging files
10411Program binaries, as produced by the GCC compilers for instance, are
10412typically written in the ELF format, with a section containing
10413@dfn{debugging information}. Debugging information is what allows the
10414debugger, GDB, to map binary code to source code; it is required to
10415debug a compiled program in good conditions.
8451a568 10416
cf4a9129
LC
10417The problem with debugging information is that is takes up a fair amount
10418of disk space. For example, debugging information for the GNU C Library
10419weighs in at more than 60 MiB. Thus, as a user, keeping all the
10420debugging info of all the installed programs is usually not an option.
10421Yet, space savings should not come at the cost of an impediment to
10422debugging---especially in the GNU system, which should make it easier
10423for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 10424
cf4a9129
LC
10425Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
10426mechanism that allows users to get the best of both worlds: debugging
10427information can be stripped from the binaries and stored in separate
10428files. GDB is then able to load debugging information from those files,
10429when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
10430with GDB}).
8451a568 10431
cf4a9129
LC
10432The GNU distribution takes advantage of this by storing debugging
10433information in the @code{lib/debug} sub-directory of a separate package
10434output unimaginatively called @code{debug} (@pxref{Packages with
10435Multiple Outputs}). Users can choose to install the @code{debug} output
10436of a package when they need it. For instance, the following command
10437installs the debugging information for the GNU C Library and for GNU
10438Guile:
8451a568
LC
10439
10440@example
cf4a9129 10441guix package -i glibc:debug guile:debug
8451a568
LC
10442@end example
10443
cf4a9129
LC
10444GDB must then be told to look for debug files in the user's profile, by
10445setting the @code{debug-file-directory} variable (consider setting it
10446from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
10447GDB}):
8451a568 10448
cf4a9129
LC
10449@example
10450(gdb) set debug-file-directory ~/.guix-profile/lib/debug
10451@end example
8451a568 10452
cf4a9129
LC
10453From there on, GDB will pick up debugging information from the
10454@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 10455
cf4a9129
LC
10456In addition, you will most likely want GDB to be able to show the source
10457code being debugged. To do that, you will have to unpack the source
10458code of the package of interest (obtained with @code{guix build
10459--source}, @pxref{Invoking guix build}), and to point GDB to that source
10460directory using the @code{directory} command (@pxref{Source Path,
10461@code{directory},, gdb, Debugging with GDB}).
8451a568 10462
cf4a9129
LC
10463@c XXX: keep me up-to-date
10464The @code{debug} output mechanism in Guix is implemented by the
10465@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
1068f26b
AE
10466opt-in---debugging information is available only for the packages
10467with definitions explicitly declaring a @code{debug} output. This may be
10468changed to opt-out in the future if our build farm servers can handle
cf4a9129
LC
10469the load. To check whether a package has a @code{debug} output, use
10470@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 10471
8451a568 10472
05962f29
LC
10473@node Security Updates
10474@section Security Updates
10475
09866b39
LC
10476@cindex security updates
10477@cindex security vulnerabilities
10478Occasionally, important security vulnerabilities are discovered in software
10479packages and must be patched. Guix developers try hard to keep track of
10480known vulnerabilities and to apply fixes as soon as possible in the
10481@code{master} branch of Guix (we do not yet provide a ``stable'' branch
10482containing only security updates.) The @command{guix lint} tool helps
10483developers find out about vulnerable versions of software packages in the
10484distribution:
10485
10486@smallexample
10487$ guix lint -c cve
10488gnu/packages/base.scm:652:2: glibc-2.21: probably vulnerable to CVE-2015-1781, CVE-2015-7547
10489gnu/packages/gcc.scm:334:2: gcc-4.9.3: probably vulnerable to CVE-2015-5276
10490gnu/packages/image.scm:312:2: openjpeg-2.1.0: probably vulnerable to CVE-2016-1923, CVE-2016-1924
10491@dots{}
10492@end smallexample
10493
10494@xref{Invoking guix lint}, for more information.
10495
843858b8 10496@quotation Note
09866b39
LC
10497As of version @value{VERSION}, the feature described below is considered
10498``beta''.
843858b8 10499@end quotation
05962f29 10500
09866b39 10501Guix follows a functional
05962f29
LC
10502package management discipline (@pxref{Introduction}), which implies
10503that, when a package is changed, @emph{every package that depends on it}
10504must be rebuilt. This can significantly slow down the deployment of
10505fixes in core packages such as libc or Bash, since basically the whole
10506distribution would need to be rebuilt. Using pre-built binaries helps
10507(@pxref{Substitutes}), but deployment may still take more time than
10508desired.
10509
10510@cindex grafts
1068f26b 10511To address this, Guix implements @dfn{grafts}, a mechanism that allows
05962f29
LC
10512for fast deployment of critical updates without the costs associated
10513with a whole-distribution rebuild. The idea is to rebuild only the
10514package that needs to be patched, and then to ``graft'' it onto packages
10515explicitly installed by the user and that were previously referring to
10516the original package. The cost of grafting is typically very low, and
10517order of magnitudes lower than a full rebuild of the dependency chain.
10518
10519@cindex replacements of packages, for grafts
10520For instance, suppose a security update needs to be applied to Bash.
10521Guix developers will provide a package definition for the ``fixed''
10522Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
10523Packages}). Then, the original package definition is augmented with a
10524@code{replacement} field pointing to the package containing the bug fix:
10525
10526@example
10527(define bash
10528 (package
10529 (name "bash")
10530 ;; @dots{}
10531 (replacement bash-fixed)))
10532@end example
10533
c22a1324
LC
10534From there on, any package depending directly or indirectly on Bash---as
10535reported by @command{guix gc --requisites} (@pxref{Invoking guix
10536gc})---that is installed is automatically ``rewritten'' to refer to
05962f29 10537@var{bash-fixed} instead of @var{bash}. This grafting process takes
1068f26b 10538time proportional to the size of the package, usually less than a
c22a1324
LC
10539minute for an ``average'' package on a recent machine. Grafting is
10540recursive: when an indirect dependency requires grafting, then grafting
10541``propagates'' up to the package that the user is installing.
05962f29
LC
10542
10543Currently, the graft and the package it replaces (@var{bash-fixed} and
10544@var{bash} in the example above) must have the exact same @code{name}
10545and @code{version} fields. This restriction mostly comes from the fact
10546that grafting works by patching files, including binary files, directly.
10547Other restrictions may apply: for instance, when adding a graft to a
10548package providing a shared library, the original shared library and its
10549replacement must have the same @code{SONAME} and be binary-compatible.
10550
59a4dd50
LC
10551The @option{--no-grafts} command-line option allows you to forcefully
10552avoid grafting (@pxref{Common Build Options, @option{--no-grafts}}).
10553Thus, the command:
10554
10555@example
10556guix build bash --no-grafts
10557@end example
10558
10559@noindent
10560returns the store file name of the original Bash, whereas:
10561
10562@example
10563guix build bash
10564@end example
10565
10566@noindent
10567returns the store file name of the ``fixed'', replacement Bash. This
10568allows you to distinguish between the two variants of Bash.
10569
10570To verify which Bash your whole profile refers to, you can run
10571(@pxref{Invoking guix gc}):
10572
10573@example
10574guix gc -R `readlink -f ~/.guix-profile` | grep bash
10575@end example
10576
10577@noindent
10578@dots{} and compare the store file names that you get with those above.
10579Likewise for a complete GuixSD system generation:
10580
10581@example
10582guix gc -R `guix system build my-config.scm` | grep bash
10583@end example
10584
10585Lastly, to check which Bash running processes are using, you can use the
10586@command{lsof} command:
10587
10588@example
10589lsof | grep /gnu/store/.*bash
10590@end example
10591
05962f29 10592
cf4a9129
LC
10593@node Package Modules
10594@section Package Modules
8451a568 10595
cf4a9129
LC
10596From a programming viewpoint, the package definitions of the
10597GNU distribution are provided by Guile modules in the @code{(gnu packages
10598@dots{})} name space@footnote{Note that packages under the @code{(gnu
10599packages @dots{})} module name space are not necessarily ``GNU
10600packages''. This module naming scheme follows the usual Guile module
10601naming convention: @code{gnu} means that these modules are distributed
10602as part of the GNU system, and @code{packages} identifies modules that
10603define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
10604Reference Manual}). For instance, the @code{(gnu packages emacs)}
10605module exports a variable named @code{emacs}, which is bound to a
10606@code{<package>} object (@pxref{Defining Packages}).
113daf62 10607
300868ba 10608The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
10609automatically scanned for packages by the command-line tools. For
10610instance, when running @code{guix package -i emacs}, all the @code{(gnu
10611packages @dots{})} modules are scanned until one that exports a package
10612object whose name is @code{emacs} is found. This package search
10613facility is implemented in the @code{(gnu packages)} module.
113daf62 10614
300868ba 10615@cindex customization, of packages
8689901f 10616@cindex package module search path
cf4a9129 10617Users can store package definitions in modules with different
60142854 10618names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
10619name and module name must match. For instance, the @code{(my-packages
10620emacs)} module must be stored in a @file{my-packages/emacs.scm} file
10621relative to the load path specified with @option{--load-path} or
10622@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
10623guile, GNU Guile Reference Manual}, for details.}. These package definitions
1068f26b
AE
10624will not be visible by default. Users can invoke commands such as
10625@command{guix package} and @command{guix build} with the
c95ded7e
LC
10626@code{-e} option so that they know where to find the package. Better
10627yet, they can use the
300868ba 10628@code{-L} option of these commands to make those modules visible
8689901f
LC
10629(@pxref{Invoking guix build, @code{--load-path}}), or define the
10630@code{GUIX_PACKAGE_PATH} environment variable. This environment
10631variable makes it easy to extend or customize the distribution and is
10632honored by all the user interfaces.
10633
10634@defvr {Environment Variable} GUIX_PACKAGE_PATH
1068f26b
AE
10635This is a colon-separated list of directories to search for additional
10636package modules. Directories listed in this variable take precedence
10637over the own modules of the distribution.
8689901f 10638@end defvr
ef5dd60a 10639
cf4a9129
LC
10640The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
10641each package is built based solely on other packages in the
10642distribution. The root of this dependency graph is a small set of
10643@dfn{bootstrap binaries}, provided by the @code{(gnu packages
10644bootstrap)} module. For more information on bootstrapping,
081145cf 10645@pxref{Bootstrapping}.
ef5dd60a 10646
cf4a9129
LC
10647@node Packaging Guidelines
10648@section Packaging Guidelines
ef5dd60a 10649
cf4a9129
LC
10650The GNU distribution is nascent and may well lack some of your favorite
10651packages. This section describes how you can help make the distribution
10652grow. @xref{Contributing}, for additional information on how you can
10653help.
ef5dd60a 10654
cf4a9129
LC
10655Free software packages are usually distributed in the form of
10656@dfn{source code tarballs}---typically @file{tar.gz} files that contain
10657all the source files. Adding a package to the distribution means
10658essentially two things: adding a @dfn{recipe} that describes how to
10659build the package, including a list of other packages required to build
f97c9175 10660it, and adding @dfn{package metadata} along with that recipe, such as a
cf4a9129 10661description and licensing information.
ef5dd60a 10662
cf4a9129
LC
10663In Guix all this information is embodied in @dfn{package definitions}.
10664Package definitions provide a high-level view of the package. They are
10665written using the syntax of the Scheme programming language; in fact,
10666for each package we define a variable bound to the package definition,
10667and export that variable from a module (@pxref{Package Modules}).
10668However, in-depth Scheme knowledge is @emph{not} a prerequisite for
10669creating packages. For more information on package definitions,
081145cf 10670@pxref{Defining Packages}.
ef5dd60a 10671
cf4a9129
LC
10672Once a package definition is in place, stored in a file in the Guix
10673source tree, it can be tested using the @command{guix build} command
10674(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
10675called @code{gnew}, you may run this command from the Guix build tree
10676(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
10677
10678@example
cf4a9129 10679./pre-inst-env guix build gnew --keep-failed
ef5dd60a 10680@end example
ef5dd60a 10681
cf4a9129
LC
10682Using @code{--keep-failed} makes it easier to debug build failures since
10683it provides access to the failed build tree. Another useful
10684command-line option when debugging is @code{--log-file}, to access the
10685build log.
ef5dd60a 10686
cf4a9129
LC
10687If the package is unknown to the @command{guix} command, it may be that
10688the source file contains a syntax error, or lacks a @code{define-public}
10689clause to export the package variable. To figure it out, you may load
10690the module from Guile to get more information about the actual error:
ef5dd60a 10691
cf4a9129
LC
10692@example
10693./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
10694@end example
ef5dd60a 10695
cf4a9129
LC
10696Once your package builds correctly, please send us a patch
10697(@pxref{Contributing}). Well, if you need help, we will be happy to
10698help you too. Once the patch is committed in the Guix repository, the
10699new package automatically gets built on the supported platforms by
2b1cee21 10700@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 10701system}.
ef5dd60a 10702
cf4a9129
LC
10703@cindex substituter
10704Users can obtain the new package definition simply by running
10705@command{guix pull} (@pxref{Invoking guix pull}). When
10706@code{hydra.gnu.org} is done building the package, installing the
10707package automatically downloads binaries from there
10708(@pxref{Substitutes}). The only place where human intervention is
10709needed is to review and apply the patch.
ef5dd60a 10710
ef5dd60a 10711
cf4a9129 10712@menu
ec0339cd
LC
10713* Software Freedom:: What may go into the distribution.
10714* Package Naming:: What's in a name?
10715* Version Numbers:: When the name is not enough.
cbd02397 10716* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
10717* Python Modules:: Taming the snake.
10718* Perl Modules:: Little pearls.
10719* Fonts:: Fond of fonts.
cf4a9129 10720@end menu
ef5dd60a 10721
cf4a9129
LC
10722@node Software Freedom
10723@subsection Software Freedom
ef5dd60a 10724
cf4a9129 10725@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
c11a6eb1 10726
cf4a9129
LC
10727The GNU operating system has been developed so that users can have
10728freedom in their computing. GNU is @dfn{free software}, meaning that
10729users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
10730essential freedoms}: to run the program, to study and change the program
10731in source code form, to redistribute exact copies, and to distribute
10732modified versions. Packages found in the GNU distribution provide only
10733software that conveys these four freedoms.
c11a6eb1 10734
cf4a9129
LC
10735In addition, the GNU distribution follow the
10736@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
10737software distribution guidelines}. Among other things, these guidelines
10738reject non-free firmware, recommendations of non-free software, and
10739discuss ways to deal with trademarks and patents.
ef5dd60a 10740
1068f26b
AE
10741Some otherwise free upstream package sources contain a small and optional
10742subset that violates the above guidelines, for instance because this subset
10743is itself non-free code. When that happens, the offending items are removed
10744with appropriate patches or code snippets in the @code{origin} form of the
10745package (@pxref{Defining Packages}). This way, @code{guix
cf4a9129
LC
10746build --source} returns the ``freed'' source rather than the unmodified
10747upstream source.
ef5dd60a 10748
ef5dd60a 10749
cf4a9129
LC
10750@node Package Naming
10751@subsection Package Naming
ef5dd60a 10752
cf4a9129
LC
10753A package has actually two names associated with it:
10754First, there is the name of the @emph{Scheme variable}, the one following
10755@code{define-public}. By this name, the package can be made known in the
10756Scheme code, for instance as input to another package. Second, there is
10757the string in the @code{name} field of a package definition. This name
10758is used by package management commands such as
10759@command{guix package} and @command{guix build}.
ef5dd60a 10760
cf4a9129
LC
10761Both are usually the same and correspond to the lowercase conversion of
10762the project name chosen upstream, with underscores replaced with
10763hyphens. For instance, GNUnet is available as @code{gnunet}, and
10764SDL_net as @code{sdl-net}.
927097ef 10765
cf4a9129 10766We do not add @code{lib} prefixes for library packages, unless these are
081145cf 10767already part of the official project name. But @pxref{Python
cf4a9129
LC
10768Modules} and @ref{Perl Modules} for special rules concerning modules for
10769the Python and Perl languages.
927097ef 10770
1b366ee4 10771Font package names are handled differently, @pxref{Fonts}.
7fec52b7 10772
ef5dd60a 10773
cf4a9129
LC
10774@node Version Numbers
10775@subsection Version Numbers
ef5dd60a 10776
cf4a9129
LC
10777We usually package only the latest version of a given free software
10778project. But sometimes, for instance for incompatible library versions,
10779two (or more) versions of the same package are needed. These require
10780different Scheme variable names. We use the name as defined
10781in @ref{Package Naming}
10782for the most recent version; previous versions use the same name, suffixed
10783by @code{-} and the smallest prefix of the version number that may
10784distinguish the two versions.
ef5dd60a 10785
cf4a9129
LC
10786The name inside the package definition is the same for all versions of a
10787package and does not contain any version number.
ef5dd60a 10788
cf4a9129 10789For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 10790
cf4a9129
LC
10791@example
10792(define-public gtk+
10793 (package
17d8e33f
ML
10794 (name "gtk+")
10795 (version "3.9.12")
10796 ...))
cf4a9129
LC
10797(define-public gtk+-2
10798 (package
17d8e33f
ML
10799 (name "gtk+")
10800 (version "2.24.20")
10801 ...))
cf4a9129
LC
10802@end example
10803If we also wanted GTK+ 3.8.2, this would be packaged as
10804@example
10805(define-public gtk+-3.8
10806 (package
17d8e33f
ML
10807 (name "gtk+")
10808 (version "3.8.2")
10809 ...))
cf4a9129 10810@end example
ef5dd60a 10811
880d647d
LC
10812@c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
10813@c for a discussion of what follows.
10814@cindex version number, for VCS snapshots
10815Occasionally, we package snapshots of upstream's version control system
10816(VCS) instead of formal releases. This should remain exceptional,
10817because it is up to upstream developers to clarify what the stable
10818release is. Yet, it is sometimes necessary. So, what should we put in
10819the @code{version} field?
10820
10821Clearly, we need to make the commit identifier of the VCS snapshot
10822visible in the version string, but we also need to make sure that the
10823version string is monotonically increasing so that @command{guix package
10824--upgrade} can determine which version is newer. Since commit
10825identifiers, notably with Git, are not monotonically increasing, we add
10826a revision number that we increase each time we upgrade to a newer
10827snapshot. The resulting version string looks like this:
10828
10829@example
108302.0.11-3.cabba9e
10831 ^ ^ ^
10832 | | `-- upstream commit ID
10833 | |
10834 | `--- Guix package revision
10835 |
10836latest upstream version
10837@end example
10838
10839It is a good idea to strip commit identifiers in the @code{version}
10840field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
10841aesthetics have a role to play here) as well as problems related to OS
10842limits such as the maximum shebang length (127 bytes for the Linux
10843kernel.) It is best to use the full commit identifiers in
561360a5
LC
10844@code{origin}s, though, to avoid ambiguities. A typical package
10845definition may look like this:
10846
10847@example
10848(define my-package
10849 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7"))
10850 (package
10851 (version (string-append "0.9-1."
10852 (string-take commit 7)))
10853 (source (origin
10854 (method git-fetch)
10855 (uri (git-reference
10856 (url "git://example.org/my-package.git")
10857 (commit commit)))
10858 (sha256 (base32 "1mbikn@dots{}"))
10859 (file-name (string-append "my-package-" version
10860 "-checkout"))))
10861 ;; @dots{}
10862 )))
10863@end example
880d647d 10864
cbd02397
LC
10865@node Synopses and Descriptions
10866@subsection Synopses and Descriptions
10867
10868As we have seen before, each package in GNU@tie{}Guix includes a
10869synopsis and a description (@pxref{Defining Packages}). Synopses and
10870descriptions are important: They are what @command{guix package
10871--search} searches, and a crucial piece of information to help users
10872determine whether a given package suits their needs. Consequently,
10873packagers should pay attention to what goes into them.
10874
10875Synopses must start with a capital letter and must not end with a
10876period. They must not start with ``a'' or ``the'', which usually does
10877not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
10878tool that frobs files''. The synopsis should say what the package
10879is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
10880used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
10881matching a pattern''.
10882
10883Keep in mind that the synopsis must be meaningful for a very wide
10884audience. For example, ``Manipulate alignments in the SAM format''
10885might make sense for a seasoned bioinformatics researcher, but might be
10886fairly unhelpful or even misleading to a non-specialized audience. It
10887is a good idea to come up with a synopsis that gives an idea of the
10888application domain of the package. In this example, this might give
10889something like ``Manipulate nucleotide sequence alignments'', which
10890hopefully gives the user a better idea of whether this is what they are
10891looking for.
10892
10893@cindex Texinfo markup, in package descriptions
10894Descriptions should take between five and ten lines. Use full
10895sentences, and avoid using acronyms without first introducing them.
10896Descriptions can include Texinfo markup, which is useful to introduce
10897ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
10898hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
10899should be careful when using some characters for example @samp{@@} and
10900curly braces which are the basic special characters in Texinfo
10901(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
10902such as @command{guix package --show} take care of rendering it
10903appropriately.
cbd02397
LC
10904
10905Synopses and descriptions are translated by volunteers
10906@uref{http://translationproject.org/domain/guix-packages.html, at the
10907Translation Project} so that as many users as possible can read them in
10908their native language. User interfaces search them and display them in
10909the language specified by the current locale.
10910
10911Translation is a lot of work so, as a packager, please pay even more
10912attention to your synopses and descriptions as every change may entail
ba7d6c76 10913additional work for translators. In order to help them, it is possible
36743e71 10914to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
10915special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
10916Gettext}):
10917
10918@example
10919;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
10920(description "ARandR is designed to provide a simple visual front end
10921for the X11 resize-and-rotate (RandR) extension. @dots{}")
10922@end example
cbd02397 10923
ef5dd60a 10924
cf4a9129
LC
10925@node Python Modules
10926@subsection Python Modules
ef5dd60a 10927
cf4a9129
LC
10928We currently package Python 2 and Python 3, under the Scheme variable names
10929@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
10930To avoid confusion and naming clashes with other programming languages, it
10931seems desirable that the name of a package for a Python module contains
10932the word @code{python}.
ef5dd60a 10933
cf4a9129
LC
10934Some modules are compatible with only one version of Python, others with both.
10935If the package Foo compiles only with Python 3, we name it
10936@code{python-foo}; if it compiles only with Python 2, we name it
10937@code{python2-foo}. If it is compatible with both versions, we create two
10938packages with the corresponding names.
ef5dd60a 10939
cf4a9129
LC
10940If a project already contains the word @code{python}, we drop this;
10941for instance, the module python-dateutil is packaged under the names
10942@code{python-dateutil} and @code{python2-dateutil}.
113daf62 10943
523e4896 10944
cf4a9129
LC
10945@node Perl Modules
10946@subsection Perl Modules
523e4896 10947
cf4a9129
LC
10948Perl programs standing for themselves are named as any other package,
10949using the lowercase upstream name.
10950For Perl packages containing a single class, we use the lowercase class name,
10951replace all occurrences of @code{::} by dashes and prepend the prefix
10952@code{perl-}.
10953So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
10954Modules containing several classes keep their lowercase upstream name and
10955are also prepended by @code{perl-}. Such modules tend to have the word
10956@code{perl} somewhere in their name, which gets dropped in favor of the
10957prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 10958
523e4896 10959
7fec52b7
AE
10960@node Fonts
10961@subsection Fonts
10962
10963For fonts that are in general not installed by a user for typesetting
10964purposes, or that are distributed as part of a larger software package,
10965we rely on the general packaging rules for software; for instance, this
10966applies to the fonts delivered as part of the X.Org system or fonts that
10967are part of TeX Live.
10968
10969To make it easier for a user to search for fonts, names for other packages
10970containing only fonts are constructed as follows, independently of the
10971upstream package name.
10972
10973The name of a package containing only one font family starts with
10974@code{font-}; it is followed by the foundry name and a dash @code{-}
10975if the foundry is known, and the font family name, in which spaces are
10976replaced by dashes (and as usual, all upper case letters are transformed
10977to lower case).
10978For example, the Gentium font family by SIL is packaged under the name
10979@code{font-sil-gentium}.
10980
10981For a package containing several font families, the name of the collection
10982is used in the place of the font family name.
10983For instance, the Liberation fonts consist of three families,
10984Liberation Sans, Liberation Serif and Liberation Mono.
10985These could be packaged separately under the names
10986@code{font-liberation-sans} and so on; but as they are distributed together
10987under a common name, we prefer to package them together as
10988@code{font-liberation}.
10989
10990In the case where several formats of the same font family or font collection
10991are packaged separately, a short form of the format, prepended by a dash,
10992is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 10993@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
10994fonts.
10995
10996
b25937e3 10997
cf4a9129
LC
10998@node Bootstrapping
10999@section Bootstrapping
b25937e3 11000
cf4a9129 11001@c Adapted from the ELS 2013 paper.
b25937e3 11002
cf4a9129 11003@cindex bootstrapping
7889394e 11004
cf4a9129
LC
11005Bootstrapping in our context refers to how the distribution gets built
11006``from nothing''. Remember that the build environment of a derivation
11007contains nothing but its declared inputs (@pxref{Introduction}). So
11008there's an obvious chicken-and-egg problem: how does the first package
11009get built? How does the first compiler get compiled? Note that this is
11010a question of interest only to the curious hacker, not to the regular
11011user, so you can shamelessly skip this section if you consider yourself
11012a ``regular user''.
72b9d60d 11013
cf4a9129
LC
11014@cindex bootstrap binaries
11015The GNU system is primarily made of C code, with libc at its core. The
11016GNU build system itself assumes the availability of a Bourne shell and
11017command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
11018`grep'. Furthermore, build programs---programs that run
11019@code{./configure}, @code{make}, etc.---are written in Guile Scheme
11020(@pxref{Derivations}). Consequently, to be able to build anything at
11021all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
11022Binutils, libc, and the other packages mentioned above---the
11023@dfn{bootstrap binaries}.
72b9d60d 11024
cf4a9129
LC
11025These bootstrap binaries are ``taken for granted'', though we can also
11026re-create them if needed (more on that later).
72b9d60d 11027
cf4a9129 11028@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 11029
cf4a9129
LC
11030@c As of Emacs 24.3, Info-mode displays the image, but since it's a
11031@c large image, it's hard to scroll. Oh well.
11032@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 11033
cf4a9129
LC
11034The figure above shows the very beginning of the dependency graph of the
11035distribution, corresponding to the package definitions of the @code{(gnu
d33fa0c7
LC
11036packages bootstrap)} module. A similar figure can be generated with
11037@command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
11038
11039@example
11040guix graph -t derivation \
11041 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
11042 | dot -Tps > t.ps
11043@end example
11044
11045At this level of detail, things are
cf4a9129
LC
11046slightly complex. First, Guile itself consists of an ELF executable,
11047along with many source and compiled Scheme files that are dynamically
11048loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
11049tarball shown in this graph. This tarball is part of Guix's ``source''
11050distribution, and gets inserted into the store with @code{add-to-store}
11051(@pxref{The Store}).
2e7b5cea 11052
cf4a9129
LC
11053But how do we write a derivation that unpacks this tarball and adds it
11054to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
11055derivation---the first one that gets built---uses @code{bash} as its
11056builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
11057@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
11058@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
11059the Guix source distribution, whose sole purpose is to allow the Guile
11060tarball to be unpacked.
fb729425 11061
cf4a9129
LC
11062Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
11063Guile that can be used to run subsequent build programs. Its first task
11064is to download tarballs containing the other pre-built binaries---this
11065is what the @code{.tar.xz.drv} derivations do. Guix modules such as
11066@code{ftp-client.scm} are used for this purpose. The
11067@code{module-import.drv} derivations import those modules in a directory
11068in the store, using the original layout. The
11069@code{module-import-compiled.drv} derivations compile those modules, and
11070write them in an output directory with the right layout. This
11071corresponds to the @code{#:modules} argument of
11072@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 11073
cf4a9129
LC
11074Finally, the various tarballs are unpacked by the
11075derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
11076etc., at which point we have a working C tool chain.
fb729425 11077
fb729425 11078
cf4a9129 11079@unnumberedsubsec Building the Build Tools
523e4896 11080
cf4a9129
LC
11081Bootstrapping is complete when we have a full tool chain that does not
11082depend on the pre-built bootstrap tools discussed above. This
11083no-dependency requirement is verified by checking whether the files of
11084the final tool chain contain references to the @file{/gnu/store}
11085directories of the bootstrap inputs. The process that leads to this
11086``final'' tool chain is described by the package definitions found in
1f6f57df 11087the @code{(gnu packages commencement)} module.
df2ce343 11088
d33fa0c7
LC
11089The @command{guix graph} command allows us to ``zoom out'' compared to
11090the graph above, by looking at the level of package objects instead of
11091individual derivations---remember that a package may translate to
11092several derivations, typically one derivation to download its source,
11093one to build the Guile modules it needs, and one to actually build the
11094package from source. The command:
11095
11096@example
11097guix graph -t bag \
11098 -e '(@@@@ (gnu packages commencement)
11099 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
11100@end example
11101
11102@noindent
11103produces the dependency graph leading to the ``final'' C
11104library@footnote{You may notice the @code{glibc-intermediate} label,
11105suggesting that it is not @emph{quite} final, but as a good
11106approximation, we will consider it final.}, depicted below.
11107
11108@image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
11109
cf4a9129
LC
11110@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
11111The first tool that gets built with the bootstrap binaries is
d33fa0c7
LC
11112GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
11113for all the following packages. From there Findutils and Diffutils get
11114built.
523e4896 11115
cf4a9129
LC
11116Then come the first-stage Binutils and GCC, built as pseudo cross
11117tools---i.e., with @code{--target} equal to @code{--host}. They are
11118used to build libc. Thanks to this cross-build trick, this libc is
11119guaranteed not to hold any reference to the initial tool chain.
4af2447e 11120
d33fa0c7
LC
11121From there the final Binutils and GCC (not shown above) are built.
11122GCC uses @code{ld}
cf4a9129
LC
11123from the final Binutils, and links programs against the just-built libc.
11124This tool chain is used to build the other packages used by Guix and by
11125the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 11126
cf4a9129
LC
11127And voilà! At this point we have the complete set of build tools that
11128the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
11129variable of the @code{(gnu packages commencement)} module, and are
11130implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 11131(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 11132
4af2447e 11133
cf4a9129 11134@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 11135
cf4a9129
LC
11136Because the final tool chain does not depend on the bootstrap binaries,
11137those rarely need to be updated. Nevertheless, it is useful to have an
11138automated way to produce them, should an update occur, and this is what
11139the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 11140
cf4a9129
LC
11141The following command builds the tarballs containing the bootstrap
11142binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
11143of Coreutils and other basic command-line tools):
4b2615e1 11144
cf4a9129
LC
11145@example
11146guix build bootstrap-tarballs
11147@end example
11148
11149The generated tarballs are those that should be referred to in the
11150@code{(gnu packages bootstrap)} module mentioned at the beginning of
11151this section.
11152
11153Still here? Then perhaps by now you've started to wonder: when do we
11154reach a fixed point? That is an interesting question! The answer is
11155unknown, but if you would like to investigate further (and have
11156significant computational and storage resources to do so), then let us
11157know.
11158
11159@node Porting
11160@section Porting to a New Platform
11161
11162As discussed above, the GNU distribution is self-contained, and
11163self-containment is achieved by relying on pre-built ``bootstrap
11164binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
11165operating system kernel, CPU architecture, and application binary
11166interface (ABI). Thus, to port the distribution to a platform that is
11167not yet supported, one must build those bootstrap binaries, and update
11168the @code{(gnu packages bootstrap)} module to use them on that platform.
11169
11170Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
11171When everything goes well, and assuming the GNU tool chain supports the
11172target platform, this can be as simple as running a command like this
11173one:
11174
11175@example
11176guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
11177@end example
11178
1c0c417d
LC
11179For this to work, the @code{glibc-dynamic-linker} procedure in
11180@code{(gnu packages bootstrap)} must be augmented to return the right
11181file name for libc's dynamic linker on that platform; likewise,
11182@code{system->linux-architecture} in @code{(gnu packages linux)} must be
11183taught about the new platform.
11184
cf4a9129 11185Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
11186to be updated to refer to these binaries on the target platform. That
11187is, the hashes and URLs of the bootstrap tarballs for the new platform
11188must be added alongside those of the currently supported platforms. The
11189bootstrap Guile tarball is treated specially: it is expected to be
11190available locally, and @file{gnu-system.am} has rules do download it for
11191the supported architectures; a rule for the new platform must be added
11192as well.
cf4a9129
LC
11193
11194In practice, there may be some complications. First, it may be that the
11195extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
11196above) is not recognized by all the GNU tools. Typically, glibc
11197recognizes some of these, whereas GCC uses an extra @code{--with-abi}
11198configure flag (see @code{gcc.scm} for examples of how to handle this).
11199Second, some of the required packages could fail to build for that
11200platform. Lastly, the generated binaries could be broken for some
11201reason.
4af2447e 11202
9bf3c1a7 11203@c *********************************************************************
8c01b9d0 11204@include contributing.texi
c78bd12b 11205
568717fd
LC
11206@c *********************************************************************
11207@node Acknowledgments
11208@chapter Acknowledgments
11209
136787cb
LC
11210Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
11211which was designed and
4c7ac9aa
LC
11212implemented by Eelco Dolstra, with contributions from other people (see
11213the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
11214management, and promoted unprecedented features, such as transactional
11215package upgrades and rollbacks, per-user profiles, and referentially
11216transparent build processes. Without this work, Guix would not exist.
11217
11218The Nix-based software distributions, Nixpkgs and NixOS, have also been
11219an inspiration for Guix.
11220
4c7ac9aa
LC
11221GNU@tie{}Guix itself is a collective work with contributions from a
11222number of people. See the @file{AUTHORS} file in Guix for more
11223information on these fine people. The @file{THANKS} file lists people
11224who have helped by reporting bugs, taking care of the infrastructure,
11225providing artwork and themes, making suggestions, and more---thank you!
11226
11227
568717fd
LC
11228@c *********************************************************************
11229@node GNU Free Documentation License
11230@appendix GNU Free Documentation License
11231
11232@include fdl-1.3.texi
11233
11234@c *********************************************************************
11235@node Concept Index
11236@unnumbered Concept Index
11237@printindex cp
11238
a85b83d2
LC
11239@node Programming Index
11240@unnumbered Programming Index
11241@syncodeindex tp fn
11242@syncodeindex vr fn
568717fd
LC
11243@printindex fn
11244
11245@bye
11246
11247@c Local Variables:
11248@c ispell-local-dictionary: "american";
11249@c End: