gnu: tcsh: Use modify-phases.
[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 11
debc6360 12@c Identifier of the OpenPGP key used to sign tarballs and such.
cccbc639 13@set OPENPGP-SIGNING-KEY-ID BCA689B636553801C3C62150197A5888235FACAC
debc6360 14
7df7a74e 15@copying
8de938d5 16Copyright @copyright{} 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès@*
f97c9175 17Copyright @copyright{} 2013, 2014, 2016 Andreas Enge@*
87eafdbd 18Copyright @copyright{} 2013 Nikita Karetnikov@*
1a3e6b15 19Copyright @copyright{} 2014, 2015, 2016 Alex Kost@*
1b846da8 20Copyright @copyright{} 2015, 2016 Mathieu Lirzin@*
8c01b9d0 21Copyright @copyright{} 2014 Pierre-Antoine Rault@*
97d76250 22Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer@*
8a9cffb2 23Copyright @copyright{} 2015, 2016, 2017 Leo Famulari@*
909147e4 24Copyright @copyright{} 2015, 2016 Ricardo Wurmus@*
4d343a14 25Copyright @copyright{} 2016 Ben Woodcroft@*
76192896 26Copyright @copyright{} 2016 Chris Marusich@*
3b88f376 27Copyright @copyright{} 2016, 2017 Efraim Flashner@*
d6a07ee6 28Copyright @copyright{} 2016 John Darrington@*
92c03a87 29Copyright @copyright{} 2016 ng0@*
8c00b838 30Copyright @copyright{} 2016 Jan Nieuwenhuizen@*
9747d189 31Copyright @copyright{} 2016 Julien Lepiller@*
78cef99b 32Copyright @copyright{} 2016 Alex ter Weele@*
11b7717d 33Copyright @copyright{} 2017 Clément Lassieur@*
bc5844d1
FB
34Copyright @copyright{} 2017 Mathieu Othacehe@*
35Copyright @copyright{} 2017 Federico Beffa
7df7a74e
NK
36
37Permission is granted to copy, distribute and/or modify this document
38under the terms of the GNU Free Documentation License, Version 1.3 or
39any later version published by the Free Software Foundation; with no
40Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
41copy of the license is included in the section entitled ``GNU Free
42Documentation License''.
43@end copying
568717fd 44
abd67856 45@dircategory System administration
568717fd 46@direntry
abd67856
LC
47* Guix: (guix). Manage installed software and system configuration.
48* guix package: (guix)Invoking guix package. Installing, removing, and upgrading packages.
49* guix build: (guix)Invoking guix build. Building packages.
50* guix gc: (guix)Invoking guix gc. Reclaiming unused disk space.
51* guix pull: (guix)Invoking guix pull. Update the list of available packages.
52* guix system: (guix)Invoking guix system. Manage the operating system configuration.
568717fd 53@end direntry
568717fd 54
372c4bbc
DT
55@dircategory Software development
56@direntry
abd67856 57* guix environment: (guix)Invoking guix environment. Building development environments with Guix.
372c4bbc
DT
58@end direntry
59
568717fd 60@titlepage
7730d112
LC
61@title GNU Guix Reference Manual
62@subtitle Using the GNU Guix Functional Package Manager
2cbed07e 63@author The GNU Guix Developers
568717fd
LC
64
65@page
66@vskip 0pt plus 1filll
67Edition @value{EDITION} @*
68@value{UPDATED} @*
69
7df7a74e 70@insertcopying
568717fd
LC
71@end titlepage
72
568717fd
LC
73@contents
74
75@c *********************************************************************
76@node Top
f8348b91 77@top GNU Guix
568717fd 78
f8348b91
LC
79This document describes GNU Guix version @value{VERSION}, a functional
80package management tool written for the GNU system.
568717fd
LC
81
82@menu
83* Introduction:: What is Guix about?
bd5e766b 84* Installation:: Installing Guix.
eeaf4427 85* Package Management:: Package installation, upgrade, etc.
568717fd
LC
86* Programming Interface:: Using Guix in Scheme.
87* Utilities:: Package management commands.
a1ba8475 88* GNU Distribution:: Software for your friendly GNU system.
9bf3c1a7 89* Contributing:: Your help needed!
568717fd
LC
90
91* Acknowledgments:: Thanks!
92* GNU Free Documentation License:: The license of this manual.
93* Concept Index:: Concepts.
a85b83d2 94* Programming Index:: Data types, functions, and variables.
aaa3eaa9
LC
95
96@detailmenu
97 --- The Detailed Node Listing ---
98
99Installation
100
1b2b8177 101* Binary Installation:: Getting Guix running in no time!
aaa3eaa9 102* Requirements:: Software needed to build and run Guix.
ec0339cd 103* Running the Test Suite:: Testing Guix.
aaa3eaa9
LC
104* Setting Up the Daemon:: Preparing the build daemon's environment.
105* Invoking guix-daemon:: Running the build daemon.
0e2d0213 106* Application Setup:: Application-specific setup.
aaa3eaa9
LC
107
108Setting Up the Daemon
109
110* Build Environment Setup:: Preparing the isolated build environment.
111* Daemon Offload Setup:: Offloading builds to remote machines.
112
113Package Management
114
115* Features:: How Guix will make your life brighter.
116* Invoking guix package:: Package installation, removal, etc.
aaa3eaa9
LC
117* Substitutes:: Downloading pre-built binaries.
118* Packages with Multiple Outputs:: Single source package, multiple outputs.
119* Invoking guix gc:: Running the garbage collector.
120* Invoking guix pull:: Fetching the latest Guix and distribution.
121* Invoking guix archive:: Exporting and importing store files.
122
123Programming Interface
124
125* Defining Packages:: Defining new packages.
126* Build Systems:: Specifying how packages are built.
127* The Store:: Manipulating the package store.
128* Derivations:: Low-level interface to package derivations.
129* The Store Monad:: Purely functional interface to the store.
130* G-Expressions:: Manipulating build expressions.
131
92492b23
LC
132Defining Packages
133
134* package Reference:: The package data type.
135* origin Reference:: The origin data type.
136
aaa3eaa9
LC
137Utilities
138
139* Invoking guix build:: Building packages from the command line.
fcc58db6 140* Invoking guix edit:: Editing package definitions.
aaa3eaa9
LC
141* Invoking guix download:: Downloading a file and printing its hash.
142* Invoking guix hash:: Computing the cryptographic hash of a file.
143* Invoking guix import:: Importing package definitions.
144* Invoking guix refresh:: Updating package definitions.
145* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 146* Invoking guix size:: Profiling disk usage.
88856916 147* Invoking guix graph:: Visualizing the graph of packages.
aaa3eaa9 148* Invoking guix environment:: Setting up development environments.
aff8ce7c 149* Invoking guix publish:: Sharing substitutes.
d23c20f1 150* Invoking guix challenge:: Challenging substitute servers.
f11c444d 151* Invoking guix copy:: Copying to and from a remote store.
32efa254 152* Invoking guix container:: Process isolation.
aaa3eaa9 153
e3009f60
LC
154Invoking @command{guix build}
155
156* Common Build Options:: Build options for most commands.
f11c444d 157* Package Transformation Options:: Creating variants of packages.
e3009f60
LC
158* Additional Build Options:: Options specific to 'guix build'.
159
aaa3eaa9
LC
160GNU Distribution
161
162* System Installation:: Installing the whole operating system.
35ed9306 163* System Configuration:: Configuring the operating system.
aaa3eaa9
LC
164* Installing Debugging Files:: Feeding the debugger.
165* Security Updates:: Deploying security fixes quickly.
166* Package Modules:: Packages from the programmer's viewpoint.
167* Packaging Guidelines:: Growing the distribution.
168* Bootstrapping:: GNU/Linux built from scratch.
169* Porting:: Targeting another platform or kernel.
170
e3009f60
LC
171System Installation
172
173* Limitations:: What you can expect.
174* Hardware Considerations:: Supported hardware.
175* USB Stick Installation:: Preparing the installation medium.
176* Preparing for Installation:: Networking, partitioning, etc.
177* Proceeding with the Installation:: The real thing.
c8b54374 178* Installing GuixSD in a VM:: GuixSD playground.
e3009f60
LC
179* Building the Installation Image:: How this comes to be.
180
aaa3eaa9
LC
181System Configuration
182
183* Using the Configuration System:: Customizing your GNU system.
184* operating-system Reference:: Detail of operating-system declarations.
185* File Systems:: Configuring file system mounts.
186* Mapped Devices:: Block device extra processing.
187* User Accounts:: Specifying user accounts.
598e19dc 188* Locales:: Language and cultural convention settings.
aaa3eaa9
LC
189* Services:: Specifying system services.
190* Setuid Programs:: Programs running with root privileges.
1b2b8177 191* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 192* Name Service Switch:: Configuring libc's name service switch.
aaa3eaa9
LC
193* Initial RAM Disk:: Linux-Libre bootstrapping.
194* GRUB Configuration:: Configuring the boot loader.
195* Invoking guix system:: Instantiating a system configuration.
97d76250 196* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
aaa3eaa9
LC
197* Defining Services:: Adding new service definitions.
198
199Services
200
201* Base Services:: Essential system services.
c311089b 202* Scheduled Job Execution:: The mcron service.
92c03a87 203* Log Rotation:: The rottlog service.
aaa3eaa9
LC
204* Networking Services:: Network setup, SSH daemon, etc.
205* X Window:: Graphical display.
f11c444d 206* Printing Services:: Local and remote printer support.
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.
78cef99b 210* Messaging Services:: Messaging services.
859e367d 211* Kerberos Services:: Kerberos services.
cbd02397 212* Web Services:: Web servers.
2be1b471 213* VPN Services:: VPN daemons.
eb419bc9 214* Network File System:: NFS related services.
f11c444d 215* Continuous Integration:: The Cuirass service.
dbc6d370 216* Miscellaneous Services:: Other services.
aaa3eaa9 217
0adfe95a
LC
218Defining Services
219
220* Service Composition:: The model for composing services.
221* Service Types and Services:: Types and services.
222* Service Reference:: API reference.
dd17bc38 223* Shepherd Services:: A particular type of service.
0adfe95a 224
aaa3eaa9
LC
225Packaging Guidelines
226
ec0339cd
LC
227* Software Freedom:: What may go into the distribution.
228* Package Naming:: What's in a name?
229* Version Numbers:: When the name is not enough.
cbd02397 230* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
231* Python Modules:: Taming the snake.
232* Perl Modules:: Little pearls.
e1c963bf 233* Java Packages:: Coffee break.
ec0339cd 234* Fonts:: Fond of fonts.
aaa3eaa9 235
8c01b9d0
ML
236Contributing
237
238* Building from Git:: The latest and greatest.
239* Running Guix Before It Is Installed:: Hacker tricks.
240* The Perfect Setup:: The right tools.
241* Coding Style:: Hygiene of the contributor.
242* Submitting Patches:: Share your work.
243
244Coding Style
245
246* Programming Paradigm:: How to compose your elements.
247* Modules:: Where to store your code?
248* Data Types and Pattern Matching:: Implementing data structures.
249* Formatting Code:: Writing conventions.
250
aaa3eaa9 251@end detailmenu
568717fd
LC
252@end menu
253
254@c *********************************************************************
255@node Introduction
256@chapter Introduction
257
6f773606 258@cindex purpose
c80e7e55 259GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
6f773606
LC
260using the international phonetic alphabet (IPA).} is a package
261management tool for the GNU system. Guix makes it easy for unprivileged
262users to install, upgrade, or remove packages, to roll back to a
263previous package set, to build packages from source, and generally
264assists with the creation and maintenance of software environments.
265
266@cindex user interfaces
267Guix provides a command-line package management interface
268(@pxref{Invoking guix package}), a set of command-line utilities
deb6276d 269(@pxref{Utilities}), as well as Scheme programming interfaces
6f773606
LC
270(@pxref{Programming Interface}).
271@cindex build daemon
272Its @dfn{build daemon} is responsible for building packages on behalf of
273users (@pxref{Setting Up the Daemon}) and for downloading pre-built
274binaries from authorized sources (@pxref{Substitutes}).
275
276@cindex extensibility of the distribution
e32171ee 277@cindex customization, of packages
6f773606
LC
278Guix includes package definitions for many GNU and non-GNU packages, all
279of which @uref{https://www.gnu.org/philosophy/free-sw.html, respect the
280user's computing freedom}. It is @emph{extensible}: users can write
281their own package definitions (@pxref{Defining Packages}) and make them
282available as independent package modules (@pxref{Package Modules}). It
283is also @emph{customizable}: users can @emph{derive} specialized package
284definitions from existing ones, including from the command line
285(@pxref{Package Transformation Options}).
286
287@cindex Guix System Distribution
288@cindex GuixSD
289You can install GNU@tie{}Guix on top of an existing GNU/Linux system
290where it complements the available tools without interference
291(@pxref{Installation}), or you can use it as part of the standalone
292@dfn{Guix System Distribution} or GuixSD (@pxref{GNU Distribution}).
293With GNU@tie{}GuixSD, you @emph{declare} all aspects of the operating
294system configuration and Guix takes care of instantiating the
295configuration in a transactional, reproducible, and stateless fashion
296(@pxref{System Configuration}).
568717fd
LC
297
298@cindex functional package management
6f773606 299Under the hood, Guix implements the @dfn{functional package management}
136787cb
LC
300discipline pioneered by Nix (@pxref{Acknowledgments}).
301In Guix, the package build and installation process is seen
6f773606 302as a @emph{function}, in the mathematical sense. That function takes inputs,
4bfc4ea3
NK
303such as build scripts, a compiler, and libraries, and
304returns an installed package. As a pure function, its result depends
568717fd
LC
305solely on its inputs---for instance, it cannot refer to software or
306scripts that were not explicitly passed as inputs. A build function
4bfc4ea3 307always produces the same result when passed a given set of inputs. It
f97c9175 308cannot alter the environment of the running system in
568717fd
LC
309any way; for instance, it cannot create, modify, or delete files outside
310of its build and installation directories. This is achieved by running
e900c503 311build processes in isolated environments (or @dfn{containers}), where only their
4bfc4ea3 312explicit inputs are visible.
568717fd 313
e531ac2a 314@cindex store
568717fd 315The result of package build functions is @dfn{cached} in the file
e531ac2a 316system, in a special directory called @dfn{the store} (@pxref{The
f97c9175 317Store}). Each package is installed in a directory of its own in the
834129e0 318store---by default under @file{/gnu/store}. The directory name contains
568717fd
LC
319a hash of all the inputs used to build that package; thus, changing an
320input yields a different directory name.
321
f97c9175
AE
322This approach is the foundation for the salient features of Guix: support
323for transactional package upgrade and rollback, per-user installation, and
eeaf4427 324garbage collection of packages (@pxref{Features}).
568717fd 325
a1ba8475 326
bd5e766b
LC
327@c *********************************************************************
328@node Installation
329@chapter Installation
330
e32171ee 331@cindex installing Guix
48febeb8
LC
332GNU Guix is available for download from its website at
333@url{http://www.gnu.org/software/guix/}. This section describes the
334software requirements of Guix, as well as how to install it and get
335ready to use it.
bd5e766b 336
5af6de3e
LC
337Note that this section is concerned with the installation of the package
338manager, which can be done on top of a running GNU/Linux system. If,
339instead, you want to install the complete GNU operating system,
6621cdb6 340@pxref{System Installation}.
5af6de3e 341
d23ef788
LC
342@cindex foreign distro
343When installed on a running GNU/Linux system---thereafter called a
344@dfn{foreign distro}---GNU@tie{}Guix complements the available tools
345without interference. Its data lives exclusively in two directories,
346usually @file{/gnu/store} and @file{/var/guix}; other files on your
347system, such as @file{/etc}, are left untouched.
348
7fcf2a0b
LC
349Once installed, Guix can be updated by running @command{guix pull}
350(@pxref{Invoking guix pull}).
351
bd5e766b 352@menu
09722b11 353* Binary Installation:: Getting Guix running in no time!
bd5e766b 354* Requirements:: Software needed to build and run Guix.
ec0339cd 355* Running the Test Suite:: Testing Guix.
bd5e766b
LC
356* Setting Up the Daemon:: Preparing the build daemon's environment.
357* Invoking guix-daemon:: Running the build daemon.
0e2d0213 358* Application Setup:: Application-specific setup.
bd5e766b
LC
359@end menu
360
09722b11
LC
361@node Binary Installation
362@section Binary Installation
363
e32171ee 364@cindex installing Guix from binaries
09722b11
LC
365This section describes how to install Guix on an arbitrary system from a
366self-contained tarball providing binaries for Guix and for all its
367dependencies. This is often quicker than installing from source, which
368is described in the next sections. The only requirement is to have
369GNU@tie{}tar and Xz.
370
371Installing goes along these lines:
372
373@enumerate
374@item
e32171ee 375@cindex downloading Guix binary
09722b11 376Download the binary tarball from
daa8922a
LC
377@indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz},
378where @var{system} is @code{x86_64-linux} for an @code{x86_64} machine
379already running the kernel Linux, and so on.
380
debc6360 381@c The following is somewhat duplicated in ``System Installation''.
daa8922a
LC
382Make sure to download the associated @file{.sig} file and to verify the
383authenticity of the tarball against it, along these lines:
384
385@example
386$ wget ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
387$ gpg --verify guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
388@end example
389
f97c9175 390If that command fails because you do not have the required public key,
daa8922a
LC
391then run this command to import it:
392
393@example
debc6360 394$ gpg --keyserver pgp.mit.edu --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
daa8922a
LC
395@end example
396
397@noindent
398and rerun the @code{gpg --verify} command.
debc6360 399@c end authentication part
09722b11
LC
400
401@item
402As @code{root}, run:
403
404@example
5dc42964 405# cd /tmp
254b1c2e
LC
406# tar --warning=no-timestamp -xf \
407 guix-binary-@value{VERSION}.@var{system}.tar.xz
5dc42964 408# mv var/guix /var/ && mv gnu /
09722b11
LC
409@end example
410
7acd3439
LC
411This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
412The latter contains a ready-to-use profile for @code{root} (see next
413step.)
09722b11 414
5dc3ce5f
LC
415Do @emph{not} unpack the tarball on a working Guix system since that
416would overwrite its own essential files.
417
254b1c2e 418The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
e9ba6357
LC
419not emit warnings about ``implausibly old time stamps'' (such
420warnings were triggered by GNU@tie{}tar 1.26 and older; recent
421versions are fine.)
422They stem from the fact that all the
254b1c2e
LC
423files in the archive have their modification time set to zero (which
424means January 1st, 1970.) This is done on purpose to make sure the
425archive content is independent of its creation time, thus making it
426reproducible.
427
7acd3439
LC
428@item
429Make @code{root}'s profile available under @file{~/.guix-profile}:
430
431@example
432# ln -sf /var/guix/profiles/per-user/root/guix-profile \
433 ~root/.guix-profile
434@end example
435
43c33047
LC
436@item
437Create the group and user accounts for build users as explained below
438(@pxref{Build Environment Setup}).
439
09722b11 440@item
bf98aea9 441Run the daemon, and set it to automatically start on boot.
c8e26887 442
bf98aea9
LC
443If your host distro uses the systemd init system, this can be achieved
444with these commands:
c8e26887
GC
445
446@example
b7230de5 447# ln -s ~root/.guix-profile/lib/systemd/system/guix-daemon.service \
c8e26887
GC
448 /etc/systemd/system/
449# systemctl start guix-daemon && systemctl enable guix-daemon
450@end example
451
452If your host distro uses the Upstart init system:
09722b11
LC
453
454@example
b7230de5 455# ln -s ~root/.guix-profile/lib/upstart/system/guix-daemon.conf /etc/init/
4a780bdf 456# initctl reload-configuration
bf98aea9 457# start guix-daemon
09722b11
LC
458@end example
459
c8e26887
GC
460Otherwise, you can still start the daemon manually with:
461
462@example
463# ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
464@end example
d2825c96 465
09722b11
LC
466@item
467Make the @command{guix} command available to other users on the machine,
468for instance with:
469
470@example
471# mkdir -p /usr/local/bin
472# cd /usr/local/bin
d72d05f9 473# ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
09722b11 474@end example
39f8ed14 475
aca738f3
LC
476It is also a good idea to make the Info version of this manual available
477there:
478
479@example
480# mkdir -p /usr/local/share/info
481# cd /usr/local/share/info
482# for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
483 do ln -s $i ; done
484@end example
485
486That way, assuming @file{/usr/local/share/info} is in the search path,
487running @command{info guix} will open this manual (@pxref{Other Info
488Directories,,, texinfo, GNU Texinfo}, for more details on changing the
489Info search path.)
490
39f8ed14 491@item
e32171ee 492@cindex substitutes, authorization thereof
df061d07
LC
493To use substitutes from @code{hydra.gnu.org} or one of its mirrors
494(@pxref{Substitutes}), authorize them:
39f8ed14
LC
495
496@example
7acd3439 497# guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
39f8ed14 498@end example
09722b11
LC
499@end enumerate
500
bf98aea9 501This completes root-level install of Guix. Each user will need to
7414de0a 502perform additional steps to make their Guix environment ready for use,
c8e26887 503@pxref{Application Setup}.
09722b11 504
c8e26887
GC
505You can confirm that Guix is working by installing a sample package into
506the root profile:
09722b11
LC
507
508@example
c8e26887 509# guix package -i hello
09722b11
LC
510@end example
511
c8e26887
GC
512The @code{guix} package must remain available in @code{root}'s profile,
513or it would become subject to garbage collection---in which case you
514would find yourself badly handicapped by the lack of the @command{guix}
bf98aea9
LC
515command. In other words, do not remove @code{guix} by running
516@code{guix package -r guix}.
517
518The binary installation tarball can be (re)produced and verified simply
519by running the following command in the Guix source tree:
520
521@example
522make guix-binary.@var{system}.tar.xz
523@end example
c8e26887 524
09722b11 525
bd5e766b
LC
526@node Requirements
527@section Requirements
528
09722b11
LC
529This section lists requirements when building Guix from source. The
530build procedure for Guix is the same as for other GNU software, and is
531not covered here. Please see the files @file{README} and @file{INSTALL}
532in the Guix source tree for additional details.
533
bd5e766b
LC
534GNU Guix depends on the following packages:
535
536@itemize
47c66da0 537@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
288dca55 538@item @url{http://gnupg.org/, GNU libgcrypt};
f0b98b84 539@item @url{http://www.gnu.org/software/make/, GNU Make}.
8a96bd4b
ID
540@end itemize
541
542The following dependencies are optional:
543
544@itemize
9b7bd1b1
LC
545@item
546Installing @uref{http://gnutls.org/, GnuTLS-Guile} will allow you to
547access @code{https} URLs for substitutes, which is highly recommended
548(@pxref{Substitutes}). It also allows you to access HTTPS URLs with the
549@command{guix download} command (@pxref{Invoking guix download}), the
550@command{guix import pypi} command, and the @command{guix import cpan}
551command. @xref{Guile Preparations, how to install the GnuTLS bindings
552for Guile,, gnutls-guile, GnuTLS-Guile}.
553
288dca55 554@item
8a96bd4b 555Installing
288dca55 556@url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
2f7d2d91
LC
557allow you to use the @command{guix import pypi} command (@pxref{Invoking
558guix import}). It is of
288dca55 559interest primarily for developers and not for casual users.
4591c02e 560
21531add
LC
561@item
562@c Note: We need at least 0.10.2 for 'channel-send-eof'.
f11c444d
LC
563Support for build offloading (@pxref{Daemon Offload Setup}) and
564@command{guix copy} (@pxref{Invoking guix copy}) depends on
21531add
LC
565@uref{https://github.com/artyom-poptsov/guile-ssh, Guile-SSH},
566version 0.10.2 or later.
567
4591c02e
LC
568@item
569When @url{http://zlib.net, zlib} is available, @command{guix publish}
570can compress build byproducts (@pxref{Invoking guix publish}).
bd5e766b
LC
571@end itemize
572
573Unless @code{--disable-daemon} was passed to @command{configure}, the
574following packages are also needed:
575
576@itemize
368d08f7
LC
577@item @url{http://sqlite.org, SQLite 3};
578@item @url{http://www.bzip.org, libbz2};
579@item @url{http://gcc.gnu.org, GCC's g++}, with support for the
580C++11 standard.
bd5e766b
LC
581@end itemize
582
e32171ee 583@cindex state directory
ef5f5c86
LC
584When configuring Guix on a system that already has a Guix installation,
585be sure to specify the same state directory as the existing installation
586using the @code{--localstatedir} option of the @command{configure}
587script (@pxref{Directory Variables, @code{localstatedir},, standards,
588GNU Coding Standards}). The @command{configure} script protects against
589unintended misconfiguration of @var{localstatedir} so you do not
590inadvertently corrupt your store (@pxref{The Store}).
591
e32171ee 592@cindex Nix, compatibility
4bfc4ea3
NK
593When a working installation of @url{http://nixos.org/nix/, the Nix package
594manager} is available, you
bd5e766b 595can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 596Nix replaces the three dependencies above.
bd5e766b 597
b22a12fd
LC
598Guix is compatible with Nix, so it is possible to share the same store
599between both. To do so, you must pass @command{configure} not only the
600same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
601@code{--localstatedir} value. The latter is essential because it
602specifies where the database that stores metadata about the store is
834129e0 603located, among other things. The default values for Nix are
b22a12fd 604@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
605Note that @code{--disable-daemon} is not required if
606your goal is to share the store with Nix.
b22a12fd 607
ec0339cd
LC
608@node Running the Test Suite
609@section Running the Test Suite
610
e32171ee 611@cindex test suite
ec0339cd
LC
612After a successful @command{configure} and @code{make} run, it is a good
613idea to run the test suite. It can help catch issues with the setup or
614environment, or bugs in Guix itself---and really, reporting test
615failures is a good way to help improve the software. To run the test
616suite, type:
617
618@example
619make check
620@end example
621
622Test cases can run in parallel: you can use the @code{-j} option of
623GNU@tie{}make to speed things up. The first run may take a few minutes
624on a recent machine; subsequent runs will be faster because the store
625that is created for test purposes will already have various things in
626cache.
627
a887fd8d
LC
628It is also possible to run a subset of the tests by defining the
629@code{TESTS} makefile variable as in this example:
630
631@example
632make check TESTS="tests/store.scm tests/cpio.scm"
633@end example
634
a9edb211
ML
635By default, tests results are displayed at a file level. In order to
636see the details of every individual test cases, it is possible to define
637the @code{SCM_LOG_DRIVER_FLAGS} makefile variable as in this example:
638
639@example
640make check TESTS="tests/base64.scm" SCM_LOG_DRIVER_FLAGS="--brief=no"
641@end example
642
ec0339cd 643Upon failure, please email @email{bug-guix@@gnu.org} and attach the
a9edb211
ML
644@file{test-suite.log} file. Please specify the Guix version being used
645as well as version numbers of the dependencies (@pxref{Requirements}) in
646your message.
ec0339cd 647
0a2f2848
LC
648Guix also comes with a whole-system test suite that tests complete
649GuixSD operating system instances. It can only run on systems where
650Guix is already installed, using:
651
652@example
653make check-system
654@end example
655
656@noindent
657or, again, by defining @code{TESTS} to select a subset of tests to run:
658
659@example
660make check-system TESTS="basic mcron"
661@end example
662
663These system tests are defined in the @code{(gnu tests @dots{})}
664modules. They work by running the operating systems under test with
665lightweight instrumentation in a virtual machine (VM). They can be
666computationally intensive or rather cheap, depending on whether
667substitutes are available for their dependencies (@pxref{Substitutes}).
668Some of them require a lot of storage space to hold VM images.
669
670Again in case of test failures, please send @email{bug-guix@@gnu.org}
671all the details.
672
bd5e766b
LC
673@node Setting Up the Daemon
674@section Setting Up the Daemon
675
676@cindex daemon
677Operations such as building a package or running the garbage collector
49e6291a 678are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
679behalf of clients. Only the daemon may access the store and its
680associated database. Thus, any operation that manipulates the store
681goes through the daemon. For instance, command-line tools such as
e49951eb 682@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
683daemon (@i{via} remote procedure calls) to instruct it what to do.
684
49e6291a 685The following sections explain how to prepare the build daemon's
f97c9175 686environment. See also @ref{Substitutes}, for information on how to allow
225dafde 687the daemon to download pre-built binaries.
49e6291a
LC
688
689@menu
690* Build Environment Setup:: Preparing the isolated build environment.
691* Daemon Offload Setup:: Offloading builds to remote machines.
692@end menu
693
694@node Build Environment Setup
695@subsection Build Environment Setup
696
e32171ee 697@cindex build environment
bd5e766b
LC
698In a standard multi-user setup, Guix and its daemon---the
699@command{guix-daemon} program---are installed by the system
834129e0 700administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
701@command{guix-daemon} runs as @code{root}. Unprivileged users may use
702Guix tools to build packages or otherwise access the store, and the
703daemon will do it on their behalf, ensuring that the store is kept in a
704consistent state, and allowing built packages to be shared among users.
705
706@cindex build users
707When @command{guix-daemon} runs as @code{root}, you may not want package
708build processes themselves to run as @code{root} too, for obvious
709security reasons. To avoid that, a special pool of @dfn{build users}
710should be created for use by build processes started by the daemon.
711These build users need not have a shell and a home directory: they will
712just be used when the daemon drops @code{root} privileges in build
713processes. Having several such users allows the daemon to launch
714distinct build processes under separate UIDs, which guarantees that they
715do not interfere with each other---an essential feature since builds are
716regarded as pure functions (@pxref{Introduction}).
717
718On a GNU/Linux system, a build user pool may be created like this (using
719Bash syntax and the @code{shadow} commands):
720
091196b3
LC
721@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
722@c for why `-G' is needed.
bd5e766b 723@example
cfc149dc
LC
724# groupadd --system guixbuild
725# for i in `seq -w 1 10`;
bd5e766b 726 do
cfc149dc
LC
727 useradd -g guixbuild -G guixbuild \
728 -d /var/empty -s `which nologin` \
729 -c "Guix build user $i" --system \
730 guixbuilder$i;
bd5e766b
LC
731 done
732@end example
733
734@noindent
54eb03ab
LC
735The number of build users determines how many build jobs may run in
736parallel, as specified by the @option{--max-jobs} option
eca69fc0
LC
737(@pxref{Invoking guix-daemon, @option{--max-jobs}}). To use
738@command{guix system vm} and related commands, you may need to add the
739build users to the @code{kvm} group so they can access @file{/dev/kvm},
740using @code{-G guixbuild,kvm} instead of @code{-G guixbuild}
741(@pxref{Invoking guix system}).
742
743The @code{guix-daemon} program may then be run as @code{root} with the
d2825c96
LC
744following command@footnote{If your machine uses the systemd init system,
745dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
746file in @file{/etc/systemd/system} will ensure that
ad227484
MDRS
747@command{guix-daemon} is automatically started. Similarly, if your
748machine uses the Upstart init system, drop the
749@file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
750file in @file{/etc/init}.}:
bd5e766b
LC
751
752@example
cfc149dc 753# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
754@end example
755
e900c503 756@cindex chroot
b095792f
LC
757@noindent
758This way, the daemon starts build processes in a chroot, under one of
cfc149dc 759the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
760environment contains nothing but:
761
762@c Keep this list in sync with libstore/build.cc! -----------------------
763@itemize
764@item
4743a4da
LC
765a minimal @code{/dev} directory, created mostly independently from the
766host @code{/dev}@footnote{``Mostly'', because while the set of files
767that appear in the chroot's @code{/dev} is fixed, most of these files
768can only be created if the host has them.};
769
770@item
f97c9175 771the @code{/proc} directory; it only shows the processes of the container
4743a4da 772since a separate PID name space is used;
6dc99317
LC
773
774@item
775@file{/etc/passwd} with an entry for the current user and an entry for
776user @file{nobody};
777
778@item
779@file{/etc/group} with an entry for the user's group;
780
781@item
782@file{/etc/hosts} with an entry that maps @code{localhost} to
783@code{127.0.0.1};
784
785@item
786a writable @file{/tmp} directory.
787@end itemize
b095792f 788
cb960102
ED
789You can influence the directory where the daemon stores build trees
790@i{via} the @code{TMPDIR} environment variable. However, the build tree
f97c9175 791within the chroot is always called @file{/tmp/guix-build-@var{name}.drv-0},
cb960102
ED
792where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
793This way, the value of @code{TMPDIR} does not leak inside build
794environments, which avoids discrepancies in cases where build processes
795capture the name of their build tree.
796
e0c941fe
LC
797@vindex http_proxy
798The daemon also honors the @code{http_proxy} environment variable for
799HTTP downloads it performs, be it for fixed-output derivations
800(@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
801
1e2644bb
LC
802If you are installing Guix as an unprivileged user, it is still possible
803to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
804However, build processes will not be isolated from one another, and not
805from the rest of the system. Thus, build processes may interfere with
806each other, and may access programs, libraries, and other files
807available on the system---making it much harder to view them as
808@emph{pure} functions.
bd5e766b 809
49e6291a
LC
810
811@node Daemon Offload Setup
812@subsection Using the Offload Facility
813
814@cindex offloading
4ec2e92d 815@cindex build hook
21531add
LC
816When desired, the build daemon can @dfn{offload} derivation builds to
817other machines running Guix, using the @code{offload} @dfn{build
818hook}@footnote{This feature is available only when
819@uref{https://github.com/artyom-poptsov/guile-ssh, Guile-SSH} is
820present.}. When that
49e6291a 821feature is enabled, a list of user-specified build machines is read from
f97c9175 822@file{/etc/guix/machines.scm}; every time a build is requested, for
49e6291a 823instance via @code{guix build}, the daemon attempts to offload it to one
f97c9175 824of the machines that satisfy the constraints of the derivation, in
49e6291a
LC
825particular its system type---e.g., @file{x86_64-linux}. Missing
826prerequisites for the build are copied over SSH to the target machine,
827which then proceeds with the build; upon success the output(s) of the
828build are copied back to the initial machine.
829
4ec2e92d 830The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
831
832@example
833(list (build-machine
834 (name "eightysix.example.org")
835 (system "x86_64-linux")
21531add 836 (host-key "ssh-ed25519 AAAAC3Nza@dots{}")
49e6291a 837 (user "bob")
21531add 838 (speed 2.)) ;incredibly fast!
49e6291a
LC
839
840 (build-machine
841 (name "meeps.example.org")
842 (system "mips64el-linux")
21531add 843 (host-key "ssh-rsa AAAAB3Nza@dots{}")
49e6291a
LC
844 (user "alice")
845 (private-key
846 (string-append (getenv "HOME")
21531add 847 "/.ssh/identity-for-guix"))))
49e6291a
LC
848@end example
849
850@noindent
851In the example above we specify a list of two build machines, one for
852the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
853architecture.
854
855In fact, this file is---not surprisingly!---a Scheme file that is
856evaluated when the @code{offload} hook is started. Its return value
857must be a list of @code{build-machine} objects. While this example
858shows a fixed list of build machines, one could imagine, say, using
859DNS-SD to return a list of potential build machines discovered in the
860local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
c678a4ee
LC
861Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
862detailed below.
4ec2e92d 863
c678a4ee 864@deftp {Data Type} build-machine
f97c9175
AE
865This data type represents build machines to which the daemon may offload
866builds. The important fields are:
49e6291a
LC
867
868@table @code
869
870@item name
f97c9175 871The host name of the remote machine.
49e6291a
LC
872
873@item system
f97c9175 874The system type of the remote machine---e.g., @code{"x86_64-linux"}.
49e6291a
LC
875
876@item user
877The user account to use when connecting to the remote machine over SSH.
878Note that the SSH key pair must @emph{not} be passphrase-protected, to
879allow non-interactive logins.
880
21531add
LC
881@item host-key
882This must be the machine's SSH @dfn{public host key} in OpenSSH format.
883This is used to authenticate the machine when we connect to it. It is a
884long string that looks like this:
885
886@example
887ssh-ed25519 AAAAC3NzaC@dots{}mde+UhL hint@@example.org
888@end example
889
890If the machine is running the OpenSSH daemon, @command{sshd}, the host
891key can be found in a file such as
892@file{/etc/ssh/ssh_host_ed25519_key.pub}.
893
894If the machine is running the SSH daemon of GNU@tie{}lsh,
895@command{lshd}, the host key is in @file{/etc/lsh/host-key.pub} or a
896similar file. It can be converted to the OpenSSH format using
897@command{lsh-export-key} (@pxref{Converting keys,,, lsh, LSH Manual}):
898
899@example
900$ lsh-export-key --openssh < /etc/lsh/host-key.pub
901ssh-rsa AAAAB3NzaC1yc2EAAAAEOp8FoQAAAQEAs1eB46LV@dots{}
902@end example
903
49e6291a
LC
904@end table
905
4ec2e92d 906A number of optional fields may be specified:
49e6291a 907
21531add 908@table @asis
49e6291a 909
21531add
LC
910@item @code{port} (default: @code{22})
911Port number of SSH server on the machine.
cecd72d5 912
21531add
LC
913@item @code{private-key} (default: @file{~/.ssh/id_rsa})
914The SSH private key file to use when connecting to the machine, in
915OpenSSH format.
49e6291a 916
1d48cf94
LC
917@item @code{compression} (default: @code{"zlib@@openssh.com,zlib"})
918@itemx @code{compression-level} (default: @code{3})
919The SSH-level compression methods and compression level requested.
920
921Note that offloading relies on SSH compression to reduce bandwidth usage
922when transferring files to and from build machines.
923
cf283dd9
LC
924@item @code{daemon-socket} (default: @code{"/var/guix/daemon-socket/socket"})
925File name of the Unix-domain socket @command{guix-daemon} is listening
926to on that machine.
c4fdfd6f 927
21531add
LC
928@item @code{parallel-builds} (default: @code{1})
929The number of builds that may run in parallel on the machine.
49e6291a 930
21531add 931@item @code{speed} (default: @code{1.0})
49e6291a
LC
932A ``relative speed factor''. The offload scheduler will tend to prefer
933machines with a higher speed factor.
934
21531add 935@item @code{features} (default: @code{'()})
49e6291a
LC
936A list of strings denoting specific features supported by the machine.
937An example is @code{"kvm"} for machines that have the KVM Linux modules
938and corresponding hardware support. Derivations can request features by
939name, and they will be scheduled on matching build machines.
940
941@end table
c678a4ee 942@end deftp
49e6291a 943
aebaee95
LC
944The @code{guile} command must be in the search path on the build
945machines. In addition, the Guix modules must be in
c4fdfd6f
LC
946@code{$GUILE_LOAD_PATH} on the build machine---you can check whether
947this is the case by running:
948
949@example
21531add 950ssh build-machine guile -c "'(use-modules (guix config))'"
c4fdfd6f 951@end example
49e6291a 952
f97c9175 953There is one last thing to do once @file{machines.scm} is in place. As
49e6291a 954explained above, when offloading, files are transferred back and forth
c4fdfd6f
LC
955between the machine stores. For this to work, you first need to
956generate a key pair on each machine to allow the daemon to export signed
957archives of files from the store (@pxref{Invoking guix archive}):
49e6291a
LC
958
959@example
960# guix archive --generate-key
961@end example
962
963@noindent
c4fdfd6f
LC
964Each build machine must authorize the key of the master machine so that
965it accepts store items it receives from the master:
966
967@example
968# guix archive --authorize < master-public-key.txt
969@end example
970
971@noindent
972Likewise, the master machine must authorize the key of each build machine.
973
974All the fuss with keys is here to express pairwise mutual trust
975relations between the master and the build machines. Concretely, when
976the master receives files from a build machine (and @i{vice versa}), its
977build daemon can make sure they are genuine, have not been tampered
978with, and that they are signed by an authorized key.
49e6291a 979
aebaee95
LC
980@cindex offload test
981To test whether your setup is operational, run this command on the
982master node:
983
984@example
985# guix offload test
986@end example
987
988This will attempt to connect to each of the build machines specified in
989@file{/etc/guix/machines.scm}, make sure Guile and the Guix modules are
990available on each machine, attempt to export to the machine and import
991from it, and report any error in the process.
992
993If you want to test a different machine file, just specify it on the
994command line:
995
996@example
997# guix offload test machines-qualif.scm
998@end example
999
27991c97
LC
1000Last, you can test the subset of the machines whose name matches a
1001regular expression like this:
1002
1003@example
1004# guix offload test machines.scm '\.gnu\.org$'
1005@end example
49e6291a 1006
bd5e766b
LC
1007@node Invoking guix-daemon
1008@section Invoking @command{guix-daemon}
1009
1010The @command{guix-daemon} program implements all the functionality to
1011access the store. This includes launching build processes, running the
1012garbage collector, querying the availability of a build result, etc. It
1013is normally run as @code{root} like this:
1014
1015@example
cfc149dc 1016# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
1017@end example
1018
1019@noindent
081145cf 1020For details on how to set it up, @pxref{Setting Up the Daemon}.
bd5e766b 1021
e900c503
LC
1022@cindex chroot
1023@cindex container, build environment
1024@cindex build environment
1025@cindex reproducible builds
bd5e766b
LC
1026By default, @command{guix-daemon} launches build processes under
1027different UIDs, taken from the build group specified with
1028@code{--build-users-group}. In addition, each build process is run in a
1029chroot environment that only contains the subset of the store that the
1030build process depends on, as specified by its derivation
1031(@pxref{Programming Interface, derivation}), plus a set of specific
1032system directories. By default, the latter contains @file{/dev} and
e900c503
LC
1033@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
1034@dfn{container}: in addition to having its own file system tree, it has
1035a separate mount name space, its own PID name space, network name space,
1036etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b 1037
cbc538fe
LC
1038When the daemon performs a build on behalf of the user, it creates a
1039build directory under @file{/tmp} or under the directory specified by
1040its @code{TMPDIR} environment variable; this directory is shared with
1041the container for the duration of the build. Be aware that using a
1042directory other than @file{/tmp} can affect build results---for example,
1043with a longer directory name, a build process that uses Unix-domain
1044sockets might hit the name length limitation for @code{sun_path}, which
1045it would otherwise not hit.
1046
1047The build directory is automatically deleted upon completion, unless the
1048build failed and the client specified @option{--keep-failed}
1049(@pxref{Invoking guix build, @option{--keep-failed}}).
1050
bd5e766b
LC
1051The following command-line options are supported:
1052
1053@table @code
1054@item --build-users-group=@var{group}
1055Take users from @var{group} to run build processes (@pxref{Setting Up
1056the Daemon, build users}).
1057
6858f9d1 1058@item --no-substitutes
b5385b52 1059@cindex substitutes
6858f9d1 1060Do not use substitutes for build products. That is, always build things
c4202d60
LC
1061locally instead of allowing downloads of pre-built binaries
1062(@pxref{Substitutes}).
6858f9d1 1063
b5385b52
LC
1064By default substitutes are used, unless the client---such as the
1065@command{guix package} command---is explicitly invoked with
1066@code{--no-substitutes}.
1067
1068When the daemon runs with @code{--no-substitutes}, clients can still
1069explicitly enable substitution @i{via} the @code{set-build-options}
1070remote procedure call (@pxref{The Store}).
1071
9176607e 1072@item --substitute-urls=@var{urls}
f8a8e0fe 1073@anchor{daemon-substitute-urls}
9176607e 1074Consider @var{urls} the default whitespace-separated list of substitute
df061d07
LC
1075source URLs. When this option is omitted,
1076@indicateurl{https://mirror.hydra.gnu.org https://hydra.gnu.org} is used
1077(@code{mirror.hydra.gnu.org} is a mirror of @code{hydra.gnu.org}).
9176607e
LC
1078
1079This means that substitutes may be downloaded from @var{urls}, as long
1080as they are signed by a trusted signature (@pxref{Substitutes}).
1081
4ec2e92d
LC
1082@cindex build hook
1083@item --no-build-hook
1084Do not use the @dfn{build hook}.
1085
1086The build hook is a helper program that the daemon can start and to
1087which it submits build requests. This mechanism is used to offload
1088builds to other machines (@pxref{Daemon Offload Setup}).
1089
bd5e766b
LC
1090@item --cache-failures
1091Cache build failures. By default, only successful builds are cached.
1092
30d9aa54
LC
1093When this option is used, @command{guix gc --list-failures} can be used
1094to query the set of store items marked as failed; @command{guix gc
1095--clear-failures} removes store items from the set of cached failures.
1096@xref{Invoking guix gc}.
1097
bd5e766b
LC
1098@item --cores=@var{n}
1099@itemx -c @var{n}
1100Use @var{n} CPU cores to build each derivation; @code{0} means as many
1101as available.
1102
6efc160e 1103The default value is @code{0}, but it may be overridden by clients, such
e49951eb
MW
1104as the @code{--cores} option of @command{guix build} (@pxref{Invoking
1105guix build}).
bd5e766b
LC
1106
1107The effect is to define the @code{NIX_BUILD_CORES} environment variable
1108in the build process, which can then use it to exploit internal
1109parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
1110
1111@item --max-jobs=@var{n}
1112@itemx -M @var{n}
1113Allow at most @var{n} build jobs in parallel. The default value is
f6526eb3
LC
1114@code{1}. Setting it to @code{0} means that no builds will be performed
1115locally; instead, the daemon will offload builds (@pxref{Daemon Offload
1116Setup}), or simply fail.
bd5e766b 1117
ecf84b7c
LC
1118@item --rounds=@var{N}
1119Build each derivation @var{n} times in a row, and raise an error if
1120consecutive build results are not bit-for-bit identical. Note that this
1121setting can be overridden by clients such as @command{guix build}
1122(@pxref{Invoking guix build}).
1123
b4528110
ED
1124When used in conjunction with @option{--keep-failed}, the differing
1125output is kept in the store, under @file{/gnu/store/@dots{}-check}.
1126This makes it easy to look for differences between the two results.
1127
bd5e766b
LC
1128@item --debug
1129Produce debugging output.
1130
1131This is useful to debug daemon start-up issues, but then it may be
1132overridden by clients, for example the @code{--verbosity} option of
e49951eb 1133@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
1134
1135@item --chroot-directory=@var{dir}
1136Add @var{dir} to the build chroot.
1137
1138Doing this may change the result of build processes---for instance if
1139they use optional dependencies found in @var{dir} when it is available,
1140and not otherwise. For that reason, it is not recommended to do so.
1141Instead, make sure that each derivation declares all the inputs that it
1142needs.
1143
1144@item --disable-chroot
1145Disable chroot builds.
1146
1147Using this option is not recommended since, again, it would allow build
1e2644bb
LC
1148processes to gain access to undeclared dependencies. It is necessary,
1149though, when @command{guix-daemon} is running under an unprivileged user
1150account.
bd5e766b
LC
1151
1152@item --disable-log-compression
1153Disable compression of the build logs.
1154
1da983b9
LC
1155Unless @code{--lose-logs} is used, all the build logs are kept in the
1156@var{localstatedir}. To save space, the daemon automatically compresses
1157them with bzip2 by default. This option disables that.
1158
ab3893d7
LC
1159@item --disable-deduplication
1160@cindex deduplication
bd5e766b
LC
1161Disable automatic file ``deduplication'' in the store.
1162
1da983b9 1163By default, files added to the store are automatically ``deduplicated'':
ab3893d7
LC
1164if a newly added file is identical to another one found in the store,
1165the daemon makes the new file a hard link to the other file. This can
4988dd40 1166noticeably reduce disk usage, at the expense of slightly increased
ab3893d7
LC
1167input/output load at the end of a build process. This option disables
1168this optimization.
1da983b9 1169
6e37066e
LC
1170@item --gc-keep-outputs[=yes|no]
1171Tell whether the garbage collector (GC) must keep outputs of live
1172derivations.
1173
1174When set to ``yes'', the GC will keep the outputs of any live derivation
1175available in the store---the @code{.drv} files. The default is ``no'',
1176meaning that derivation outputs are kept only if they are GC roots.
1177
1178@item --gc-keep-derivations[=yes|no]
1179Tell whether the garbage collector (GC) must keep derivations
1180corresponding to live outputs.
1181
1182When set to ``yes'', as is the case by default, the GC keeps
1183derivations---i.e., @code{.drv} files---as long as at least one of their
1184outputs is live. This allows users to keep track of the origins of
1185items in their store. Setting it to ``no'' saves a bit of disk space.
1186
1187Note that when both @code{--gc-keep-derivations} and
1188@code{--gc-keep-outputs} are used, the effect is to keep all the build
1189prerequisites (the sources, compiler, libraries, and other build-time
1190tools) of live objects in the store, regardless of whether these
1191prerequisites are live. This is convenient for developers since it
1192saves rebuilds or downloads.
1193
bd5e766b
LC
1194@item --impersonate-linux-2.6
1195On Linux-based systems, impersonate Linux 2.6. This means that the
1196kernel's @code{uname} system call will report 2.6 as the release number.
1197
1198This might be helpful to build programs that (usually wrongfully) depend
1199on the kernel version number.
1200
1201@item --lose-logs
1202Do not keep build logs. By default they are kept under
ce33631f 1203@code{@var{localstatedir}/guix/log}.
bd5e766b
LC
1204
1205@item --system=@var{system}
1206Assume @var{system} as the current system type. By default it is the
1207architecture/kernel pair found at configure time, such as
1208@code{x86_64-linux}.
b8d2aa26
LC
1209
1210@item --listen=@var{socket}
1211Listen for connections on @var{socket}, the file name of a Unix-domain
1212socket. The default socket is
1213@file{@var{localstatedir}/daemon-socket/socket}. This option is only
1214useful in exceptional circumstances, such as if you need to run several
1215daemons on the same machine.
bd5e766b
LC
1216@end table
1217
1218
0e2d0213
LC
1219@node Application Setup
1220@section Application Setup
1221
d23ef788 1222@cindex foreign distro
85e57214
LC
1223When using Guix on top of GNU/Linux distribution other than GuixSD---a
1224so-called @dfn{foreign distro}---a few additional steps are needed to
1225get everything in place. Here are some of them.
0e2d0213
LC
1226
1227@subsection Locales
1228
5c3c1427 1229@anchor{locales-and-locpath}
0e2d0213 1230@cindex locales, when not on GuixSD
5c3c1427 1231@vindex LOCPATH
85e57214 1232@vindex GUIX_LOCPATH
f97c9175
AE
1233Packages installed @i{via} Guix will not use the locale data of the
1234host system. Instead, you must first install one of the locale packages
85e57214
LC
1235available with Guix and then define the @code{GUIX_LOCPATH} environment
1236variable:
0e2d0213
LC
1237
1238@example
1239$ guix package -i glibc-locales
85e57214 1240$ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
0e2d0213
LC
1241@end example
1242
1243Note that the @code{glibc-locales} package contains data for all the
1244locales supported by the GNU@tie{}libc and weighs in at around
f97c9175 1245110@tie{}MiB. Alternatively, the @code{glibc-utf8-locales} is smaller but
0e2d0213
LC
1246limited to a few UTF-8 locales.
1247
85e57214
LC
1248The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1249(@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1250Manual}). There are two important differences though:
1251
1252@enumerate
1253@item
f97c9175 1254@code{GUIX_LOCPATH} is honored only by the libc in Guix, and not by the libc
85e57214 1255provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
f97c9175 1256to make sure the programs of the foreign distro will not end up loading
85e57214
LC
1257incompatible locale data.
1258
1259@item
1260libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1261@code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1262should your Guix profile contain a mixture of programs linked against
1263different libc version, each libc version will only try to load locale
1264data in the right format.
1265@end enumerate
1266
1267This is important because the locale data format used by different libc
1268versions may be incompatible.
1269
9a5187b6
LC
1270@subsection Name Service Switch
1271
1272@cindex name service switch, glibc
1273@cindex NSS (name service switch), glibc
1274@cindex nscd (name service caching daemon)
1275@cindex name service caching daemon (nscd)
1276When using Guix on a foreign distro, we @emph{strongly recommend} that
1277the system run the GNU C library's @dfn{name service cache daemon},
1278@command{nscd}, which should be listening on the
1279@file{/var/run/nscd/socket} socket. Failing to do that, applications
1280installed with Guix may fail to look up host names or user accounts, or
1281may even crash. The next paragraphs explain why.
1282
1283@cindex @file{nsswitch.conf}
1284The GNU C library implements a @dfn{name service switch} (NSS), which is
1285an extensible mechanism for ``name lookups'' in general: host name
1286resolution, user accounts, and more (@pxref{Name Service Switch,,, libc,
1287The GNU C Library Reference Manual}).
1288
1289@cindex Network information service (NIS)
1290@cindex NIS (Network information service)
1291Being extensible, the NSS supports @dfn{plugins}, which provide new name
1292lookup implementations: for example, the @code{nss-mdns} plugin allow
1293resolution of @code{.local} host names, the @code{nis} plugin allows
1294user account lookup using the Network information service (NIS), and so
1295on. These extra ``lookup services'' are configured system-wide in
1296@file{/etc/nsswitch.conf}, and all the programs running on the system
1297honor those settings (@pxref{NSS Configuration File,,, libc, The GNU C
1298Reference Manual}).
1299
1300When they perform a name lookup---for instance by calling the
1301@code{getaddrinfo} function in C---applications first try to connect to
1302the nscd; on success, nscd performs name lookups on their behalf. If
1303the nscd is not running, then they perform the name lookup by
1304themselves, by loading the name lookup services into their own address
1305space and running it. These name lookup services---the
1306@file{libnss_*.so} files---are @code{dlopen}'d, but they may come from
1307the host system's C library, rather than from the C library the
1308application is linked against (the C library coming from Guix).
1309
1310And this is where the problem is: if your application is linked against
1311Guix's C library (say, glibc 2.24) and tries to load NSS plugins from
1312another C library (say, @code{libnss_mdns.so} for glibc 2.22), it will
1313likely crash or have its name lookups fail unexpectedly.
1314
1315Running @command{nscd} on the system, among other advantages, eliminates
1316this binary incompatibility problem because those @code{libnss_*.so}
1317files are loaded in the @command{nscd} process, not in applications
1318themselves.
1319
0e2d0213
LC
1320@subsection X11 Fonts
1321
e32171ee 1322@cindex fonts
4988dd40 1323The majority of graphical applications use Fontconfig to locate and
f97c9175
AE
1324load fonts and perform X11-client-side rendering. The @code{fontconfig}
1325package in Guix looks for fonts in @file{$HOME/.guix-profile}
0e2d0213 1326by default. Thus, to allow graphical applications installed with Guix
f97c9175 1327to display fonts, you have to install fonts with Guix as well.
0e2d0213 1328Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
8fe5b1d1 1329@code{font-gnu-freefont-ttf}.
0e2d0213 1330
5c36edc8
LC
1331To display text written in Chinese languages, Japanese, or Korean in
1332graphical applications, consider installing
1333@code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1334has multiple outputs, one per language family (@pxref{Packages with
1335Multiple Outputs}). For instance, the following command installs fonts
1336for Chinese languages:
1337
1338@example
1339guix package -i font-adobe-source-han-sans:cn
1340@end example
1341
e32171ee 1342@cindex @code{xterm}
1a3e6b15
AK
1343Older programs such as @command{xterm} do not use Fontconfig and instead
1344rely on server-side font rendering. Such programs require to specify a
1345full name of a font using XLFD (X Logical Font Description), like this:
1346
1347@example
1348-*-dejavu sans-medium-r-normal-*-*-100-*-*-*-*-*-1
1349@end example
1350
1351To be able to use such full names for the TrueType fonts installed in
1352your Guix profile, you need to extend the font path of the X server:
1353
1354@example
1355xset +fp ~/.guix-profile/share/fonts/truetype
1356@end example
1357
e32171ee 1358@cindex @code{xlsfonts}
1a3e6b15
AK
1359After that, you can run @code{xlsfonts} (from @code{xlsfonts} package)
1360to make sure your TrueType fonts are listed there.
1361
b3129f2b
LC
1362@subsection X.509 Certificates
1363
e32171ee 1364@cindex @code{nss-certs}
b3129f2b
LC
1365The @code{nss-certs} package provides X.509 certificates, which allow
1366programs to authenticate Web servers accessed over HTTPS.
1367
1368When using Guix on a foreign distro, you can install this package and
1369define the relevant environment variables so that packages know where to
80d944b7 1370look for certificates. @xref{X.509 Certificates}, for detailed
b3129f2b
LC
1371information.
1372
6d97319c
AK
1373@subsection Emacs Packages
1374
e32171ee 1375@cindex @code{emacs}
6d97319c
AK
1376When you install Emacs packages with Guix, the elisp files may be placed
1377either in @file{$HOME/.guix-profile/share/emacs/site-lisp/} or in
1378sub-directories of
1379@file{$HOME/.guix-profile/share/emacs/site-lisp/guix.d/}. The latter
1380directory exists because potentially there may exist thousands of Emacs
1381packages and storing all their files in a single directory may be not
1382reliable (because of name conflicts). So we think using a separate
1383directory for each package is a good idea. It is very similar to how
1384the Emacs package system organizes the file structure (@pxref{Package
1385Files,,, emacs, The GNU Emacs Manual}).
1386
1387By default, Emacs (installed with Guix) ``knows'' where these packages
f97c9175 1388are placed, so you do not need to perform any configuration. If, for
6d97319c 1389some reason, you want to avoid auto-loading Emacs packages installed
f97c9175 1390with Guix, you can do so by running Emacs with @code{--no-site-file}
6d97319c
AK
1391option (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
1392
0e2d0213
LC
1393@c TODO What else?
1394
eeaf4427
LC
1395@c *********************************************************************
1396@node Package Management
1397@chapter Package Management
1398
e32171ee 1399@cindex packages
f8348b91 1400The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427 1401remove software packages, without having to know about their build
f97c9175 1402procedures or dependencies. Guix also goes beyond this obvious set of
eeaf4427
LC
1403features.
1404
1405This chapter describes the main features of Guix, as well as the package
deb6276d
AK
1406management tools it provides. Along with the command-line interface
1407described below (@pxref{Invoking guix package, @code{guix package}}),
1408you may also use Emacs Interface, after installing @code{emacs-guix}
1409package (run @kbd{M-x guix-help} command to start with it):
1410
1411@example
1412guix package -i emacs-guix
1413@end example
eeaf4427
LC
1414
1415@menu
1416* Features:: How Guix will make your life brighter.
e49951eb 1417* Invoking guix package:: Package installation, removal, etc.
c4202d60 1418* Substitutes:: Downloading pre-built binaries.
760c60d6 1419* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 1420* Invoking guix gc:: Running the garbage collector.
f651b477 1421* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 1422* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
1423@end menu
1424
1425@node Features
1426@section Features
1427
1428When using Guix, each package ends up in the @dfn{package store}, in its
1429own directory---something that resembles
deb6276d 1430@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string.
eeaf4427
LC
1431
1432Instead of referring to these directories, users have their own
1433@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
1434use. These profiles are stored within each user's home directory, at
1435@code{$HOME/.guix-profile}.
eeaf4427 1436
821b0015 1437For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 1438@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 1439@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
1440@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1441simply continues to point to
834129e0 1442@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 1443coexist on the same system without any interference.
eeaf4427 1444
e49951eb 1445The @command{guix package} command is the central tool to manage
f97c9175 1446packages (@pxref{Invoking guix package}). It operates on the per-user
821b0015 1447profiles, and can be used @emph{with normal user privileges}.
eeaf4427 1448
e32171ee 1449@cindex transactions
eeaf4427
LC
1450The command provides the obvious install, remove, and upgrade
1451operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 1452the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 1453@command{guix package} process is terminated during the transaction,
eeaf4427
LC
1454or if a power outage occurs during the transaction, then the user's
1455profile remains in its previous state, and remains usable.
1456
1457In addition, any package transaction may be @emph{rolled back}. So, if,
1458for example, an upgrade installs a new version of a package that turns
1459out to have a serious bug, users may roll back to the previous instance
4af2447e 1460of their profile, which was known to work well. Similarly, the global
6f773606
LC
1461system configuration on GuixSD is subject to
1462transactional upgrades and roll-back
4af2447e 1463(@pxref{Using the Configuration System}).
eeaf4427 1464
f97c9175
AE
1465All packages in the package store may be @emph{garbage-collected}.
1466Guix can determine which packages are still referenced by user
fe8ff028 1467profiles, and remove those that are provably no longer referenced
e49951eb 1468(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
1469generations of their profile so that the packages they refer to can be
1470collected.
eeaf4427 1471
e900c503
LC
1472@cindex reproducibility
1473@cindex reproducible builds
eeaf4427
LC
1474Finally, Guix takes a @dfn{purely functional} approach to package
1475management, as described in the introduction (@pxref{Introduction}).
834129e0 1476Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
1477inputs that were used to build that package---compiler, libraries, build
1478scripts, etc. This direct correspondence allows users to make sure a
1479given package installation matches the current state of their
e900c503
LC
1480distribution. It also helps maximize @dfn{build reproducibility}:
1481thanks to the isolated build environments that are used, a given build
1482is likely to yield bit-identical files when performed on different
1483machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 1484
c4202d60 1485@cindex substitutes
eeaf4427 1486This foundation allows Guix to support @dfn{transparent binary/source
c4202d60 1487deployment}. When a pre-built binary for a @file{/gnu/store} item is
18f2887b 1488available from an external source---a @dfn{substitute}, Guix just
c4202d60
LC
1489downloads it and unpacks it;
1490otherwise, it builds the package from source, locally
bf9eacd2
LC
1491(@pxref{Substitutes}). Because build results are usually bit-for-bit
1492reproducible, users do not have to trust servers that provide
1493substitutes: they can force a local build and @emph{challenge} providers
1494(@pxref{Invoking guix challenge}).
eeaf4427 1495
f5fd4fd2
LC
1496Control over the build environment is a feature that is also useful for
1497developers. The @command{guix environment} command allows developers of
1498a package to quickly set up the right development environment for their
f97c9175
AE
1499package, without having to manually install the dependencies of the
1500package into their profile (@pxref{Invoking guix environment}).
f5fd4fd2 1501
e49951eb
MW
1502@node Invoking guix package
1503@section Invoking @command{guix package}
eeaf4427 1504
e32171ee
JD
1505@cindex installing packages
1506@cindex removing packages
1507@cindex package installation
1508@cindex package removal
e49951eb 1509The @command{guix package} command is the tool that allows users to
eeaf4427
LC
1510install, upgrade, and remove packages, as well as rolling back to
1511previous configurations. It operates only on the user's own profile,
1512and works with normal user privileges (@pxref{Features}). Its syntax
1513is:
1514
1515@example
e49951eb 1516guix package @var{options}
eeaf4427 1517@end example
e32171ee 1518@cindex transactions
ba55b1cb 1519Primarily, @var{options} specifies the operations to be performed during
eeaf4427 1520the transaction. Upon completion, a new profile is created, but
99bd74d5 1521previous @dfn{generations} of the profile remain available, should the user
eeaf4427
LC
1522want to roll back.
1523
6447738c
MW
1524For example, to remove @code{lua} and install @code{guile} and
1525@code{guile-cairo} in a single transaction:
1526
1527@example
1528guix package -r lua -i guile guile-cairo
1529@end example
1530
99bd74d5
LC
1531@command{guix package} also supports a @dfn{declarative approach}
1532whereby the user specifies the exact set of packages to be available and
1533passes it @i{via} the @option{--manifest} option
1534(@pxref{profile-manifest, @option{--manifest}}).
1535
e32171ee 1536@cindex profile
b9e5c0a9 1537For each user, a symlink to the user's default profile is automatically
0ec1af59 1538created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
1539current generation of the user's default profile. Thus, users can add
1540@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1541variable, and so on.
d664f1b4
LC
1542@cindex search paths
1543If you are not using the Guix System Distribution, consider adding the
1544following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1545Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1546shells get all the right environment variable definitions:
1547
1548@example
1549GUIX_PROFILE="$HOME/.guix-profile" \
1550source "$HOME/.guix-profile/etc/profile"
1551@end example
b9e5c0a9 1552
4379c35b
LC
1553In a multi-user setup, user profiles are stored in a place registered as
1554a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1555to (@pxref{Invoking guix gc}). That directory is normally
0ec1af59
LC
1556@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1557@var{localstatedir} is the value passed to @code{configure} as
4379c35b
LC
1558@code{--localstatedir}, and @var{user} is the user name. The
1559@file{per-user} directory is created when @command{guix-daemon} is
1560started, and the @var{user} sub-directory is created by @command{guix
1561package}.
0ec1af59
LC
1562
1563The @var{options} can be among the following:
1564
eeaf4427
LC
1565@table @code
1566
6447738c
MW
1567@item --install=@var{package} @dots{}
1568@itemx -i @var{package} @dots{}
1569Install the specified @var{package}s.
eeaf4427 1570
6447738c 1571Each @var{package} may specify either a simple package name, such as
1b846da8
ML
1572@code{guile}, or a package name followed by an at-sign and version number,
1573such as @code{guile@@1.8.8} or simply @code{guile@@1.8} (in the latter
724311a2
LC
1574case, the newest version prefixed by @code{1.8} is selected.)
1575
1576If no version number is specified, the
dc5669cd
MW
1577newest available version will be selected. In addition, @var{package}
1578may contain a colon, followed by the name of one of the outputs of the
1b846da8 1579package, as in @code{gcc:doc} or @code{binutils@@2.22:lib}
e7f34eb0
LC
1580(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1581name (and optionally version) are searched for among the GNU
1582distribution modules (@pxref{Package Modules}).
eeaf4427 1583
461572cc
LC
1584@cindex propagated inputs
1585Sometimes packages have @dfn{propagated inputs}: these are dependencies
21461f27
LC
1586that automatically get installed along with the required package
1587(@pxref{package-propagated-inputs, @code{propagated-inputs} in
1588@code{package} objects}, for information about propagated inputs in
1589package definitions).
461572cc 1590
21461f27 1591@anchor{package-cmd-propagated-inputs}
461572cc
LC
1592An example is the GNU MPC library: its C header files refer to those of
1593the GNU MPFR library, which in turn refer to those of the GMP library.
1594Thus, when installing MPC, the MPFR and GMP libraries also get installed
1595in the profile; removing MPC also removes MPFR and GMP---unless they had
f97c9175 1596also been explicitly installed by the user.
461572cc 1597
ba7ea5ce 1598Besides, packages sometimes rely on the definition of environment
5924080d 1599variables for their search paths (see explanation of
ba7ea5ce 1600@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
1601environment variable definitions are reported here.
1602
5d4b411f
LC
1603@item --install-from-expression=@var{exp}
1604@itemx -e @var{exp}
1605Install the package @var{exp} evaluates to.
1606
1607@var{exp} must be a Scheme expression that evaluates to a
1608@code{<package>} object. This option is notably useful to disambiguate
1609between same-named variants of a package, with expressions such as
1610@code{(@@ (gnu packages base) guile-final)}.
1611
1612Note that this option installs the first output of the specified
1613package, which may be insufficient when needing a specific output of a
1614multiple-output package.
1615
0d279400
DT
1616@item --install-from-file=@var{file}
1617@itemx -f @var{file}
1618Install the package that the code within @var{file} evaluates to.
1619
1620As an example, @var{file} might contain a definition like this
1621(@pxref{Defining Packages}):
1622
1623@example
1624@verbatiminclude package-hello.scm
1625@end example
1626
baacf042 1627Developers may find it useful to include such a @file{guix.scm} file
f97c9175 1628in the root of their project source tree that can be used to test
0d279400
DT
1629development snapshots and create reproducible development environments
1630(@pxref{Invoking guix environment}).
1631
6447738c
MW
1632@item --remove=@var{package} @dots{}
1633@itemx -r @var{package} @dots{}
1634Remove the specified @var{package}s.
eeaf4427 1635
6447738c 1636As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
1637and/or output name in addition to the package name. For instance,
1638@code{-r glibc:debug} would remove the @code{debug} output of
1639@code{glibc}.
1640
6447738c
MW
1641@item --upgrade[=@var{regexp} @dots{}]
1642@itemx -u [@var{regexp} @dots{}]
e32171ee 1643@cindex upgrading packages
6447738c
MW
1644Upgrade all the installed packages. If one or more @var{regexp}s are
1645specified, upgrade only installed packages whose name matches a
d5f01e48 1646@var{regexp}. Also see the @code{--do-not-upgrade} option below.
eeaf4427 1647
f651b477
LC
1648Note that this upgrades package to the latest version of packages found
1649in the distribution currently installed. To update your distribution,
1650you should regularly run @command{guix pull} (@pxref{Invoking guix
1651pull}).
1652
d5f01e48
MW
1653@item --do-not-upgrade[=@var{regexp} @dots{}]
1654When used together with the @code{--upgrade} option, do @emph{not}
1655upgrade any packages whose name matches a @var{regexp}. For example, to
1656upgrade all packages in the current profile except those containing the
1657substring ``emacs'':
1658
1659@example
1660$ guix package --upgrade . --do-not-upgrade emacs
1661@end example
1662
99bd74d5 1663@item @anchor{profile-manifest}--manifest=@var{file}
1b676447 1664@itemx -m @var{file}
99bd74d5
LC
1665@cindex profile declaration
1666@cindex profile manifest
1667Create a new generation of the profile from the manifest object
1b676447
DT
1668returned by the Scheme code in @var{file}.
1669
99bd74d5
LC
1670This allows you to @emph{declare} the profile's contents rather than
1671constructing it through a sequence of @code{--install} and similar
1672commands. The advantage is that @var{file} can be put under version
1673control, copied to different machines to reproduce the same profile, and
1674so on.
1675
1676@c FIXME: Add reference to (guix profile) documentation when available.
1677@var{file} must return a @dfn{manifest} object, which is roughly a list
1678of packages:
1b676447 1679
99bd74d5 1680@findex packages->manifest
1b676447 1681@example
99bd74d5 1682(use-package-modules guile emacs)
1b676447
DT
1683
1684(packages->manifest
99bd74d5
LC
1685 (list emacs
1686 guile-2.0
1b676447 1687 ;; Use a specific package output.
99bd74d5 1688 (list guile-2.0 "debug")))
1b676447
DT
1689@end example
1690
6cd10593
LC
1691@findex specification->package+output
1692In this example we have to know which modules define the @code{emacs}
1693and @code{guile-2.0} variables to provide the right
1694@code{use-package-modules} line, which can be cumbersome. We can
1695instead provide regular package specifications and let
1696@code{specification->package-output} look up the corresponding package
1697objects, like this:
1698
1699@example
1700(packages->manifest
1701 (map (compose list specification->package+output)
1702 '("emacs" "guile@@2.0" "guile@@2.0:debug")))
1703@end example
1704
24e262f0 1705@item --roll-back
e32171ee
JD
1706@cindex rolling back
1707@cindex undoing transactions
1708@cindex transactions, undoing
24e262f0
LC
1709Roll back to the previous @dfn{generation} of the profile---i.e., undo
1710the last transaction.
1711
1712When combined with options such as @code{--install}, roll back occurs
1713before any other actions.
1714
d9307267 1715When rolling back from the first generation that actually contains
4b2bc804 1716installed packages, the profile is made to point to the @dfn{zeroth
f97c9175 1717generation}, which contains no files apart from its own metadata.
d9307267 1718
f97c9175
AE
1719After having rolled back, installing, removing, or upgrading packages
1720overwrites previous future generations. Thus, the history of the
1721generations in a profile is always linear.
82fe08ed 1722
b3bb82f1
AK
1723@item --switch-generation=@var{pattern}
1724@itemx -S @var{pattern}
e32171ee 1725@cindex generations
b3bb82f1
AK
1726Switch to a particular generation defined by @var{pattern}.
1727
1728@var{pattern} may be either a generation number or a number prefixed
1729with ``+'' or ``-''. The latter means: move forward/backward by a
1730specified number of generations. For example, if you want to return to
1731the latest generation after @code{--roll-back}, use
1732@code{--switch-generation=+1}.
1733
1734The difference between @code{--roll-back} and
1735@code{--switch-generation=-1} is that @code{--switch-generation} will
1736not make a zeroth generation, so if a specified generation does not
1737exist, the current generation will not be changed.
1738
dbc31ab2 1739@item --search-paths[=@var{kind}]
5924080d
LC
1740@cindex search paths
1741Report environment variable definitions, in Bash syntax, that may be
1742needed in order to use the set of installed packages. These environment
1743variables are used to specify @dfn{search paths} for files used by some
1744of the installed packages.
1745
1746For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1747environment variables to be defined so it can look for headers and
1748libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1749Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1750library are installed in the profile, then @code{--search-paths} will
1751suggest setting these variables to @code{@var{profile}/include} and
1752@code{@var{profile}/lib}, respectively.
1753
dbc31ab2
LC
1754The typical use case is to define these environment variables in the
1755shell:
1756
1757@example
1758$ eval `guix package --search-paths`
1759@end example
1760
1761@var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1762meaning that the returned environment variable definitions will either
1763be exact settings, or prefixes or suffixes of the current value of these
1764variables. When omitted, @var{kind} defaults to @code{exact}.
1765
fc2d2339
LC
1766This option can also be used to compute the @emph{combined} search paths
1767of several profiles. Consider this example:
1768
1769@example
1770$ guix package -p foo -i guile
1771$ guix package -p bar -i guile-json
1772$ guix package -p foo -p bar --search-paths
1773@end example
1774
1775The last command above reports about the @code{GUILE_LOAD_PATH}
1776variable, even though, taken individually, neither @file{foo} nor
1777@file{bar} would lead to that recommendation.
1778
1779
eeaf4427
LC
1780@item --profile=@var{profile}
1781@itemx -p @var{profile}
1782Use @var{profile} instead of the user's default profile.
1783
70915c1a 1784@item --verbose
f97c9175
AE
1785Produce verbose output. In particular, emit the build log of the
1786environment on the standard error port.
70915c1a 1787
eeaf4427
LC
1788@item --bootstrap
1789Use the bootstrap Guile to build the profile. This option is only
1790useful to distribution developers.
1791
1792@end table
1793
f97c9175 1794In addition to these actions, @command{guix package} supports the
733b4130
LC
1795following options to query the current state of a profile, or the
1796availability of packages:
eeaf4427 1797
733b4130
LC
1798@table @option
1799
acc08466
NK
1800@item --search=@var{regexp}
1801@itemx -s @var{regexp}
b110869d 1802@cindex searching for packages
5763ad92 1803List the available packages whose name, synopsis, or description matches
f97c9175 1804@var{regexp}. Print all the metadata of matching packages in
299112d3
LC
1805@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1806GNU recutils manual}).
acc08466 1807
299112d3
LC
1808This allows specific fields to be extracted using the @command{recsel}
1809command, for instance:
1810
1811@example
e49951eb 1812$ guix package -s malloc | recsel -p name,version
299112d3
LC
1813name: glibc
1814version: 2.17
1815
1816name: libgc
1817version: 7.2alpha6
1818@end example
acc08466 1819
a12d92f5
LC
1820Similarly, to show the name of all the packages available under the
1821terms of the GNU@tie{}LGPL version 3:
1822
1823@example
1824$ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1825name: elfutils
1826
1827name: gmp
1828@dots{}
1829@end example
1830
db5a9444
LC
1831It is also possible to refine search results using several @code{-s}
1832flags. For example, the following command returns a list of board
1833games:
1834
1835@example
1836$ guix package -s '\<board\>' -s game | recsel -p name
1837name: gnubg
1838@dots{}
1839@end example
1840
1841If we were to omit @code{-s game}, we would also get software packages
1842that deal with printed circuit boards; removing the angle brackets
1843around @code{board} would further add packages that have to do with
1844keyboards.
1845
b110869d
LC
1846And now for a more elaborate example. The following command searches
1847for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1848libraries, and prints the name and synopsis of the matching packages:
1849
1850@example
1851$ guix package -s crypto -s library | \
1852 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1853@end example
1854
1855@noindent
1856@xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1857information on @dfn{selection expressions} for @code{recsel -e}.
1858
2aa6efb0
CR
1859@item --show=@var{package}
1860Show details about @var{package}, taken from the list of available packages, in
1861@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1862recutils manual}).
1863
1864@example
1865$ guix package --show=python | recsel -p name,version
1866name: python
1867version: 2.7.6
1868
1869name: python
1870version: 3.3.5
1871@end example
1872
1873You may also specify the full name of a package to only get details about a
1874specific version of it:
1875@example
ea206df4 1876$ guix package --show=python@@3.4 | recsel -p name,version
2aa6efb0 1877name: python
ea206df4 1878version: 3.4.3
2aa6efb0
CR
1879@end example
1880
1881
1882
733b4130
LC
1883@item --list-installed[=@var{regexp}]
1884@itemx -I [@var{regexp}]
bd9bde1c
LC
1885List the currently installed packages in the specified profile, with the
1886most recently installed packages shown last. When @var{regexp} is
1887specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
1888
1889For each installed package, print the following items, separated by
1890tabs: the package name, its version string, the part of the package that
1891is installed (for instance, @code{out} for the default output,
1892@code{include} for its headers, etc.), and the path of this package in
1893the store.
1894
64fc89b6
LC
1895@item --list-available[=@var{regexp}]
1896@itemx -A [@var{regexp}]
5763ad92 1897List packages currently available in the distribution for this system
a1ba8475
LC
1898(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1899installed packages whose name matches @var{regexp}.
64fc89b6
LC
1900
1901For each package, print the following items separated by tabs: its name,
6e721c4d
LC
1902its version string, the parts of the package (@pxref{Packages with
1903Multiple Outputs}), and the source location of its definition.
64fc89b6 1904
f566d765
LC
1905@item --list-generations[=@var{pattern}]
1906@itemx -l [@var{pattern}]
e32171ee 1907@cindex generations
f566d765
LC
1908Return a list of generations along with their creation dates; for each
1909generation, show the installed packages, with the most recently
4b2bc804
NK
1910installed packages shown last. Note that the zeroth generation is never
1911shown.
f566d765
LC
1912
1913For each installed package, print the following items, separated by
1914tabs: the name of a package, its version string, the part of the package
1915that is installed (@pxref{Packages with Multiple Outputs}), and the
1916location of this package in the store.
1917
1918When @var{pattern} is used, the command returns only matching
1919generations. Valid patterns include:
1920
1921@itemize
1922@item @emph{Integers and comma-separated integers}. Both patterns denote
1923generation numbers. For instance, @code{--list-generations=1} returns
1924the first one.
1925
1926And @code{--list-generations=1,8,2} outputs three generations in the
1927specified order. Neither spaces nor trailing commas are allowed.
1928
1929@item @emph{Ranges}. @code{--list-generations=2..9} prints the
1930specified generations and everything in between. Note that the start of
f97c9175 1931a range must be smaller than its end.
f566d765
LC
1932
1933It is also possible to omit the endpoint. For example,
1934@code{--list-generations=2..}, returns all generations starting from the
1935second one.
1936
1937@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1938or months by passing an integer along with the first letter of the
d7ddb257
LC
1939duration. For example, @code{--list-generations=20d} lists generations
1940that are up to 20 days old.
f566d765
LC
1941@end itemize
1942
b7884ca3
NK
1943@item --delete-generations[=@var{pattern}]
1944@itemx -d [@var{pattern}]
d7ddb257
LC
1945When @var{pattern} is omitted, delete all generations except the current
1946one.
b7884ca3
NK
1947
1948This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
1949When @var{pattern} is specified, delete the matching generations. When
1950@var{pattern} specifies a duration, generations @emph{older} than the
1951specified duration match. For instance, @code{--delete-generations=1m}
1952deletes generations that are more than one month old.
1953
391bdd8f
LC
1954If the current generation matches, it is @emph{not} deleted. Also, the
1955zeroth generation is never deleted.
b7884ca3 1956
f97c9175 1957Note that deleting generations prevents rolling back to them.
1bb9900a
LC
1958Consequently, this command must be used with care.
1959
733b4130 1960@end table
eeaf4427 1961
70ee5642 1962Finally, since @command{guix package} may actually start build
ccd7158d 1963processes, it supports all the common build options (@pxref{Common Build
f97c9175 1964Options}). It also supports package transformation options, such as
b8638f03
LC
1965@option{--with-source} (@pxref{Package Transformation Options}).
1966However, note that package transformations are lost when upgrading; to
f97c9175 1967preserve transformations across upgrades, you should define your own
b8638f03
LC
1968package variant in a Guile module and add it to @code{GUIX_PACKAGE_PATH}
1969(@pxref{Defining Packages}).
1970
70ee5642 1971
c4202d60
LC
1972@node Substitutes
1973@section Substitutes
1974
1975@cindex substitutes
1976@cindex pre-built binaries
1977Guix supports transparent source/binary deployment, which means that it
1978can either build things locally, or download pre-built items from a
1979server. We call these pre-built items @dfn{substitutes}---they are
1980substitutes for local build results. In many cases, downloading a
1981substitute is much faster than building things locally.
1982
1983Substitutes can be anything resulting from a derivation build
1984(@pxref{Derivations}). Of course, in the common case, they are
1985pre-built package binaries, but source tarballs, for instance, which
1986also result from derivation builds, can be available as substitutes.
1987
1988The @code{hydra.gnu.org} server is a front-end to a build farm that
1989builds packages from the GNU distribution continuously for some
deb6276d 1990architectures, and makes them available as substitutes. This is the
f8a8e0fe
LC
1991default source of substitutes; it can be overridden by passing the
1992@option{--substitute-urls} option either to @command{guix-daemon}
1993(@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1994or to client tools such as @command{guix package}
1995(@pxref{client-substitute-urls,, client @option{--substitute-urls}
1996option}).
c4202d60 1997
9b7bd1b1
LC
1998Substitute URLs can be either HTTP or HTTPS@footnote{For HTTPS access,
1999the Guile bindings of GnuTLS must be installed. @xref{Requirements}.}
2000HTTPS is recommended because communications are encrypted; conversely,
2001using HTTP makes all communications visible to an eavesdropper, who
2002could use the information gathered to determine, for instance, whether
2003your system has unpatched security vulnerabilities.
2004
c4202d60
LC
2005@cindex security
2006@cindex digital signatures
e32171ee 2007@cindex substitutes, authorization thereof
df061d07
LC
2008To allow Guix to download substitutes from @code{hydra.gnu.org} or a
2009mirror thereof, you
c4202d60
LC
2010must add its public key to the access control list (ACL) of archive
2011imports, using the @command{guix archive} command (@pxref{Invoking guix
2012archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
2013be compromised and to serve genuine substitutes.
2014
2015This public key is installed along with Guix, in
2016@code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
2017the installation prefix of Guix. If you installed Guix from source,
2018make sure you checked the GPG signature of
2019@file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
2020Then, you can run something like this:
2021
2022@example
2023# guix archive --authorize < hydra.gnu.org.pub
2024@end example
2025
2026Once this is in place, the output of a command like @code{guix build}
2027should change from something like:
2028
2029@example
2030$ guix build emacs --dry-run
2031The following derivations would be built:
2032 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
2033 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
2034 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
2035 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
2036@dots{}
2037@end example
2038
2039@noindent
2040to something like:
2041
2042@example
2043$ guix build emacs --dry-run
2044The following files would be downloaded:
2045 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
2046 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
2047 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
2048 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
2049@dots{}
2050@end example
2051
2052@noindent
2053This indicates that substitutes from @code{hydra.gnu.org} are usable and
2054will be downloaded, when possible, for future builds.
2055
2056Guix ignores substitutes that are not signed, or that are not signed by
ef27aa9c 2057one of the keys listed in the ACL. It also detects and raises an error
c4202d60
LC
2058when attempting to use a substitute that has been tampered with.
2059
e0c941fe 2060@vindex http_proxy
9b7bd1b1
LC
2061Substitutes are downloaded over HTTP or HTTPS.
2062The @code{http_proxy} environment
e0c941fe
LC
2063variable can be set in the environment of @command{guix-daemon} and is
2064honored for downloads of substitutes. Note that the value of
2065@code{http_proxy} in the environment where @command{guix build},
2066@command{guix package}, and other client commands are run has
2067@emph{absolutely no effect}.
2068
9b7bd1b1
LC
2069When using HTTPS, the server's X.509 certificate is @emph{not} validated
2070(in other words, the server is not authenticated), contrary to what
2071HTTPS clients such as Web browsers usually do. This is because Guix
2072authenticates substitute information itself, as explained above, which
2073is what we care about (whereas X.509 certificates are about
2074authenticating bindings between domain names and public keys.)
2075
c4202d60
LC
2076The substitute mechanism can be disabled globally by running
2077@code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
2078guix-daemon}). It can also be disabled temporarily by passing the
2079@code{--no-substitutes} option to @command{guix package}, @command{guix
2080build}, and other command-line tools.
2081
2082
9b7bd1b1
LC
2083@unnumberedsubsec On Trusting Binaries
2084
c4202d60
LC
2085Today, each individual's control over their own computing is at the
2086mercy of institutions, corporations, and groups with enough power and
2087determination to subvert the computing infrastructure and exploit its
2088weaknesses. While using @code{hydra.gnu.org} substitutes can be
2089convenient, we encourage users to also build on their own, or even run
2090their own build farm, such that @code{hydra.gnu.org} is less of an
8ce229fc
LC
2091interesting target. One way to help is by publishing the software you
2092build using @command{guix publish} so that others have one more choice
2093of server to download substitutes from (@pxref{Invoking guix publish}).
c4202d60
LC
2094
2095Guix has the foundations to maximize build reproducibility
2096(@pxref{Features}). In most cases, independent builds of a given
2097package or derivation should yield bit-identical results. Thus, through
2098a diverse set of independent package builds, we can strengthen the
d23c20f1
LC
2099integrity of our systems. The @command{guix challenge} command aims to
2100help users assess substitute servers, and to assist developers in
2101finding out about non-deterministic package builds (@pxref{Invoking guix
a8d65643
LC
2102challenge}). Similarly, the @option{--check} option of @command{guix
2103build} allows users to check whether previously-installed substitutes
2104are genuine by rebuilding them locally (@pxref{build-check,
2105@command{guix build --check}}).
c4202d60
LC
2106
2107In the future, we want Guix to have support to publish and retrieve
2108binaries to/from other users, in a peer-to-peer fashion. If you would
2109like to discuss this project, join us on @email{guix-devel@@gnu.org}.
2110
2111
6e721c4d
LC
2112@node Packages with Multiple Outputs
2113@section Packages with Multiple Outputs
2114
2115@cindex multiple-output packages
2116@cindex package outputs
e32171ee 2117@cindex outputs
6e721c4d
LC
2118
2119Often, packages defined in Guix have a single @dfn{output}---i.e., the
f97c9175 2120source package leads to exactly one directory in the store. When running
6e721c4d
LC
2121@command{guix package -i glibc}, one installs the default output of the
2122GNU libc package; the default output is called @code{out}, but its name
2123can be omitted as shown in this command. In this particular case, the
2124default output of @code{glibc} contains all the C header files, shared
2125libraries, static libraries, Info documentation, and other supporting
2126files.
2127
2128Sometimes it is more appropriate to separate the various types of files
2129produced from a single source package into separate outputs. For
2130instance, the GLib C library (used by GTK+ and related packages)
2131installs more than 20 MiB of reference documentation as HTML pages.
2132To save space for users who do not need it, the documentation goes to a
2133separate output, called @code{doc}. To install the main GLib output,
2134which contains everything but the documentation, one would run:
2135
2136@example
2137guix package -i glib
2138@end example
2139
e32171ee 2140@cindex documentation
6e721c4d
LC
2141The command to install its documentation is:
2142
2143@example
2144guix package -i glib:doc
2145@end example
2146
2147Some packages install programs with different ``dependency footprints''.
f97c9175 2148For instance, the WordNet package installs both command-line tools and
6e721c4d
LC
2149graphical user interfaces (GUIs). The former depend solely on the C
2150library, whereas the latter depend on Tcl/Tk and the underlying X
2151libraries. In this case, we leave the command-line tools in the default
2152output, whereas the GUIs are in a separate output. This allows users
fcc58db6
LC
2153who do not need the GUIs to save space. The @command{guix size} command
2154can help find out about such situations (@pxref{Invoking guix size}).
88856916 2155@command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
6e721c4d
LC
2156
2157There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
2158Other conventional output names include @code{lib} for libraries and
2159possibly header files, @code{bin} for stand-alone programs, and
2160@code{debug} for debugging information (@pxref{Installing Debugging
2161Files}). The outputs of a packages are listed in the third column of
2162the output of @command{guix package --list-available} (@pxref{Invoking
2163guix package}).
6e721c4d 2164
eeaf4427 2165
e49951eb
MW
2166@node Invoking guix gc
2167@section Invoking @command{guix gc}
fe8ff028
LC
2168
2169@cindex garbage collector
e32171ee 2170@cindex disk space
f97c9175 2171Packages that are installed, but not used, may be @dfn{garbage-collected}.
e49951eb 2172The @command{guix gc} command allows users to explicitly run the garbage
c22eb992
LC
2173collector to reclaim space from the @file{/gnu/store} directory. It is
2174the @emph{only} way to remove files from @file{/gnu/store}---removing
2175files or directories manually may break it beyond repair!
fe8ff028
LC
2176
2177The garbage collector has a set of known @dfn{roots}: any file under
834129e0 2178@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
2179cannot be deleted; any other file is considered @dfn{dead} and may be
2180deleted. The set of garbage collector roots includes default user
e49951eb
MW
2181profiles, and may be augmented with @command{guix build --root}, for
2182example (@pxref{Invoking guix build}).
fe8ff028 2183
1bb9900a
LC
2184Prior to running @code{guix gc --collect-garbage} to make space, it is
2185often useful to remove old generations from user profiles; that way, old
2186package builds referenced by those generations can be reclaimed. This
2187is achieved by running @code{guix package --delete-generations}
2188(@pxref{Invoking guix package}).
2189
e49951eb 2190The @command{guix gc} command has three modes of operation: it can be
fe8ff028 2191used to garbage-collect any dead files (the default), to delete specific
7770aafc
LC
2192files (the @code{--delete} option), to print garbage-collector
2193information, or for more advanced queries. The garbage collection
2194options are as follows:
fe8ff028
LC
2195
2196@table @code
2197@item --collect-garbage[=@var{min}]
2198@itemx -C [@var{min}]
834129e0 2199Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
2200sub-directories. This is the default operation when no option is
2201specified.
2202
2203When @var{min} is given, stop once @var{min} bytes have been collected.
2204@var{min} may be a number of bytes, or it may include a unit as a
4a44d7bb
LC
2205suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
2206(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
fe8ff028
LC
2207
2208When @var{min} is omitted, collect all the garbage.
2209
0054e470
LC
2210@item --free-space=@var{free}
2211@itemx -F @var{free}
2212Collect garbage until @var{free} space is available under
2213@file{/gnu/store}, if possible; @var{free} denotes storage space, such
2214as @code{500MiB}, as described above.
2215
2216When @var{free} or more is already available in @file{/gnu/store}, do
2217nothing and exit immediately.
2218
fe8ff028
LC
2219@item --delete
2220@itemx -d
2221Attempt to delete all the store files and directories specified as
2222arguments. This fails if some of the files are not in the store, or if
2223they are still live.
2224
30d9aa54
LC
2225@item --list-failures
2226List store items corresponding to cached build failures.
2227
2228This prints nothing unless the daemon was started with
2229@option{--cache-failures} (@pxref{Invoking guix-daemon,
2230@option{--cache-failures}}).
2231
2232@item --clear-failures
2233Remove the specified store items from the failed-build cache.
2234
2235Again, this option only makes sense when the daemon is started with
2236@option{--cache-failures}. Otherwise, it does nothing.
2237
fe8ff028
LC
2238@item --list-dead
2239Show the list of dead files and directories still present in the
2240store---i.e., files and directories no longer reachable from any root.
2241
2242@item --list-live
2243Show the list of live store files and directories.
ba8b732d
LC
2244
2245@end table
2246
2247In addition, the references among existing store files can be queried:
2248
2249@table @code
2250
2251@item --references
2252@itemx --referrers
e32171ee 2253@cindex package dependencies
ba8b732d
LC
2254List the references (respectively, the referrers) of store files given
2255as arguments.
2256
8e59fdd5
LC
2257@item --requisites
2258@itemx -R
fcc58db6 2259@cindex closure
8e59fdd5
LC
2260List the requisites of the store files passed as arguments. Requisites
2261include the store files themselves, their references, and the references
2262of these, recursively. In other words, the returned list is the
2263@dfn{transitive closure} of the store files.
2264
f97c9175
AE
2265@xref{Invoking guix size}, for a tool to profile the size of the closure
2266of an element. @xref{Invoking guix graph}, for a tool to visualize
88856916 2267the graph of references.
fcc58db6 2268
fe8ff028
LC
2269@end table
2270
7770aafc
LC
2271Lastly, the following options allow you to check the integrity of the
2272store and to control disk usage.
2273
2274@table @option
2275
2276@item --verify[=@var{options}]
2277@cindex integrity, of the store
2278@cindex integrity checking
2279Verify the integrity of the store.
2280
2281By default, make sure that all the store items marked as valid in the
f97c9175 2282database of the daemon actually exist in @file{/gnu/store}.
7770aafc 2283
f97c9175 2284When provided, @var{options} must be a comma-separated list containing one
7770aafc
LC
2285or more of @code{contents} and @code{repair}.
2286
7414de0a 2287When passing @option{--verify=contents}, the daemon computes the
f97c9175 2288content hash of each store item and compares it against its hash in the
7770aafc
LC
2289database. Hash mismatches are reported as data corruptions. Because it
2290traverses @emph{all the files in the store}, this command can take a
2291long time, especially on systems with a slow disk drive.
2292
2293@cindex repairing the store
6da5bb7b 2294@cindex corruption, recovering from
7770aafc
LC
2295Using @option{--verify=repair} or @option{--verify=contents,repair}
2296causes the daemon to try to repair corrupt store items by fetching
2297substitutes for them (@pxref{Substitutes}). Because repairing is not
2298atomic, and thus potentially dangerous, it is available only to the
6da5bb7b
LC
2299system administrator. A lightweight alternative, when you know exactly
2300which items in the store are corrupt, is @command{guix build --repair}
2301(@pxref{Invoking guix build}).
7770aafc
LC
2302
2303@item --optimize
2304@cindex deduplication
2305Optimize the store by hard-linking identical files---this is
2306@dfn{deduplication}.
2307
2308The daemon performs deduplication after each successful build or archive
2309import, unless it was started with @code{--disable-deduplication}
2310(@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
2311this option is primarily useful when the daemon was running with
2312@code{--disable-deduplication}.
2313
2314@end table
eeaf4427 2315
f651b477
LC
2316@node Invoking guix pull
2317@section Invoking @command{guix pull}
2318
e32171ee 2319@cindex upgrading Guix
7fcf2a0b 2320@cindex updating Guix
e32171ee
JD
2321@cindex @command{guix pull}
2322@cindex pull
f651b477
LC
2323Packages are installed or upgraded to the latest version available in
2324the distribution currently available on your local machine. To update
2325that distribution, along with the Guix tools, you must run @command{guix
2326pull}: the command downloads the latest Guix source code and package
2327descriptions, and deploys it.
2328
2329On completion, @command{guix package} will use packages and package
2330versions from this just-retrieved copy of Guix. Not only that, but all
2331the Guix commands and Scheme modules will also be taken from that latest
2332version. New @command{guix} sub-commands added by the update also
cb05108a
LC
2333become available.
2334
2335Any user can update their Guix copy using @command{guix pull}, and the
2336effect is limited to the user who run @command{guix pull}. For
2337instance, when user @code{root} runs @command{guix pull}, this has no
2338effect on the version of Guix that user @code{alice} sees, and vice
2339versa@footnote{Under the hood, @command{guix pull} updates the
2340@file{~/.config/guix/latest} symbolic link to point to the latest Guix,
5e2017ed
CM
2341and the @command{guix} command loads code from there. Currently, the
2342only way to roll back an invocation of @command{guix pull} is to
2343manually update this symlink to point to the previous Guix.}.
f651b477
LC
2344
2345The @command{guix pull} command is usually invoked with no arguments,
2346but it supports the following options:
2347
2348@table @code
2349@item --verbose
2350Produce verbose output, writing build logs to the standard error output.
2351
ab5d72ad
LC
2352@item --url=@var{url}
2353Download the source tarball of Guix from @var{url}.
2354
2355By default, the tarball is taken from its canonical address at
2356@code{gnu.org}, for the stable branch of Guix.
2357
8a9cffb2
LF
2358With some Git servers, this can be used to deploy any version of Guix.
2359For example, to download and deploy version 0.12.0 of Guix from the
2360canonical Git repo:
2361
2362@example
2363guix pull --url=http://git.savannah.gnu.org/cgit/guix.git/snapshot/v0.12.0.tar.gz
2364@end example
2365
2366It can also be used to deploy arbitrary Git revisions:
2367
2368@example
2369guix pull --url=http://git.savannah.gnu.org/cgit/guix.git/snapshot/74d862e8a.tar.gz
2370@end example
2371
f651b477
LC
2372@item --bootstrap
2373Use the bootstrap Guile to build the latest Guix. This option is only
2374useful to Guix developers.
2375@end table
2376
760c60d6
LC
2377
2378@node Invoking guix archive
2379@section Invoking @command{guix archive}
2380
e32171ee
JD
2381@cindex @command{guix archive}
2382@cindex archive
760c60d6
LC
2383The @command{guix archive} command allows users to @dfn{export} files
2384from the store into a single archive, and to later @dfn{import} them.
2385In particular, it allows store files to be transferred from one machine
4d4c4816
AE
2386to the store on another machine.
2387
e32171ee 2388@cindex exporting store items
4d4c4816
AE
2389To export store files as an archive to standard output, run:
2390
2391@example
2392guix archive --export @var{options} @var{specifications}...
2393@end example
2394
2395@var{specifications} may be either store file names or package
2396specifications, as for @command{guix package} (@pxref{Invoking guix
2397package}). For instance, the following command creates an archive
2398containing the @code{gui} output of the @code{git} package and the main
2399output of @code{emacs}:
2400
2401@example
2402guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
2403@end example
2404
2405If the specified packages are not built yet, @command{guix archive}
2406automatically builds them. The build process may be controlled with the
2407common build options (@pxref{Common Build Options}).
2408
2409To transfer the @code{emacs} package to a machine connected over SSH,
2410one would run:
760c60d6
LC
2411
2412@example
56607088 2413guix archive --export -r emacs | ssh the-machine guix archive --import
760c60d6
LC
2414@end example
2415
87236aed 2416@noindent
56607088
LC
2417Similarly, a complete user profile may be transferred from one machine
2418to another like this:
2419
2420@example
2421guix archive --export -r $(readlink -f ~/.guix-profile) | \
2422 ssh the-machine guix-archive --import
2423@end example
2424
2425@noindent
2426However, note that, in both examples, all of @code{emacs} and the
2427profile as well as all of their dependencies are transferred (due to
f97c9175
AE
2428@code{-r}), regardless of what is already available in the store on the
2429target machine. The @code{--missing} option can help figure out which
f11c444d
LC
2430items are missing from the target store. The @command{guix copy}
2431command simplifies and optimizes this whole process, so this is probably
2432what you should use in this case (@pxref{Invoking guix copy}).
87236aed 2433
5597b3ae
LC
2434@cindex nar, archive format
2435@cindex normalized archive (nar)
03476a23 2436By default archives are stored in the ``normalized archive'' or ``nar'' format, which is
5597b3ae 2437comparable in spirit to `tar', but with differences
0dbd88db 2438that make it more appropriate for our purposes. First, rather than
5597b3ae 2439recording all Unix metadata for each file, the nar format only mentions
0dbd88db
LC
2440the file type (regular, directory, or symbolic link); Unix permissions
2441and owner/group are dismissed. Second, the order in which directory
2442entries are stored always follows the order of file names according to
2443the C locale collation order. This makes archive production fully
2444deterministic.
2445
2446When exporting, the daemon digitally signs the contents of the archive,
2447and that digital signature is appended. When importing, the daemon
2448verifies the signature and rejects the import in case of an invalid
2449signature or if the signing key is not authorized.
760c60d6
LC
2450@c FIXME: Add xref to daemon doc about signatures.
2451
03476a23
RW
2452Optionally, archives can be exported as a Docker image in the tar
2453archive format using @code{--format=docker}.
2454
760c60d6
LC
2455The main options are:
2456
2457@table @code
2458@item --export
2459Export the specified store files or packages (see below.) Write the
2460resulting archive to the standard output.
2461
56607088
LC
2462Dependencies are @emph{not} included in the output, unless
2463@code{--recursive} is passed.
2464
2465@item -r
2466@itemx --recursive
2467When combined with @code{--export}, this instructs @command{guix
2468archive} to include dependencies of the given items in the archive.
2469Thus, the resulting archive is self-contained: it contains the closure
2470of the exported store items.
2471
760c60d6
LC
2472@item --import
2473Read an archive from the standard input, and import the files listed
2474therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
2475signature, or if it is signed by a public key not among the authorized
2476keys (see @code{--authorize} below.)
554f26ec 2477
87236aed
LC
2478@item --missing
2479Read a list of store file names from the standard input, one per line,
2480and write on the standard output the subset of these files missing from
2481the store.
2482
03476a23
RW
2483@item -f
2484@item --format=@var{FMT}
2485@cindex docker, export
2486@cindex export format
2487Specify the export format. Acceptable arguments are @code{nar} and
2488@code{docker}. The default is the nar format. When the format is
2489@code{docker}, recursively export the specified store directory as a
2490Docker image in tar archive format, as specified in
2491@uref{https://github.com/docker/docker/blob/master/image/spec/v1.2.md,
2492version 1.2.0 of the Docker Image Specification}. Using
2493@code{--format=docker} implies @code{--recursive}. The generated
2494archive can be loaded by Docker using @command{docker load}.
2495
554f26ec 2496@item --generate-key[=@var{parameters}]
f82cc5fd 2497@cindex signing, archives
f97c9175 2498Generate a new key pair for the daemon. This is a prerequisite before
554f26ec
LC
2499archives can be exported with @code{--export}. Note that this operation
2500usually takes time, because it needs to gather enough entropy to
2501generate the key pair.
2502
2503The generated key pair is typically stored under @file{/etc/guix}, in
2504@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
867d8473
LC
2505key, which must be kept secret.) When @var{parameters} is omitted,
2506an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2507versions before 1.6.0, it is a 4096-bit RSA key.
f97c9175 2508Alternatively, @var{parameters} can specify
554f26ec
LC
2509@code{genkey} parameters suitable for Libgcrypt (@pxref{General
2510public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2511Libgcrypt Reference Manual}).
f82cc5fd
LC
2512
2513@item --authorize
2514@cindex authorizing, archives
2515Authorize imports signed by the public key passed on standard input.
2516The public key must be in ``s-expression advanced format''---i.e., the
2517same format as the @file{signing-key.pub} file.
2518
2519The list of authorized keys is kept in the human-editable file
2520@file{/etc/guix/acl}. The file contains
2521@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2522s-expressions''} and is structured as an access-control list in the
2523@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2524(SPKI)}.
c6f8e9dd
LC
2525
2526@item --extract=@var{directory}
2527@itemx -x @var{directory}
2528Read a single-item archive as served by substitute servers
2529(@pxref{Substitutes}) and extract it to @var{directory}. This is a
2530low-level operation needed in only very narrow use cases; see below.
2531
2532For example, the following command extracts the substitute for Emacs
2533served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2534
2535@example
2536$ wget -O - \
df061d07 2537 https://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
c6f8e9dd
LC
2538 | bunzip2 | guix archive -x /tmp/emacs
2539@end example
2540
2541Single-item archives are different from multiple-item archives produced
2542by @command{guix archive --export}; they contain a single store item,
2543and they do @emph{not} embed a signature. Thus this operation does
2544@emph{no} signature verification and its output should be considered
2545unsafe.
2546
2547The primary purpose of this operation is to facilitate inspection of
2548archive contents coming from possibly untrusted substitute servers.
2549
760c60d6
LC
2550@end table
2551
568717fd
LC
2552@c *********************************************************************
2553@node Programming Interface
2554@chapter Programming Interface
2555
3dc1970d
LC
2556GNU Guix provides several Scheme programming interfaces (APIs) to
2557define, build, and query packages. The first interface allows users to
2558write high-level package definitions. These definitions refer to
2559familiar packaging concepts, such as the name and version of a package,
2560its build system, and its dependencies. These definitions can then be
2561turned into concrete build actions.
2562
ba55b1cb 2563Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 2564standard setup, the daemon has write access to the store---the
834129e0 2565@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
2566setup also has the daemon perform builds in chroots, under a specific
2567build users, to minimize interference with the rest of the system.
2568
2569@cindex derivation
2570Lower-level APIs are available to interact with the daemon and the
2571store. To instruct the daemon to perform a build action, users actually
2572provide it with a @dfn{derivation}. A derivation is a low-level
2573representation of the build actions to be taken, and the environment in
2574which they should occur---derivations are to package definitions what
49ad317a
LC
2575assembly is to C programs. The term ``derivation'' comes from the fact
2576that build results @emph{derive} from them.
3dc1970d
LC
2577
2578This chapter describes all these APIs in turn, starting from high-level
2579package definitions.
2580
568717fd 2581@menu
b860f382 2582* Defining Packages:: Defining new packages.
7458bd0a 2583* Build Systems:: Specifying how packages are built.
b860f382
LC
2584* The Store:: Manipulating the package store.
2585* Derivations:: Low-level interface to package derivations.
2586* The Store Monad:: Purely functional interface to the store.
21b679f6 2587* G-Expressions:: Manipulating build expressions.
568717fd
LC
2588@end menu
2589
2590@node Defining Packages
2591@section Defining Packages
2592
3dc1970d
LC
2593The high-level interface to package definitions is implemented in the
2594@code{(guix packages)} and @code{(guix build-system)} modules. As an
2595example, the package definition, or @dfn{recipe}, for the GNU Hello
2596package looks like this:
2597
2598@example
e7f34eb0
LC
2599(define-module (gnu packages hello)
2600 #:use-module (guix packages)
2601 #:use-module (guix download)
2602 #:use-module (guix build-system gnu)
a6dcdcac
SB
2603 #:use-module (guix licenses)
2604 #:use-module (gnu packages gawk))
b22a12fd 2605
79f5dd59 2606(define-public hello
3dc1970d
LC
2607 (package
2608 (name "hello")
17d8e33f 2609 (version "2.10")
3dc1970d 2610 (source (origin
17d8e33f
ML
2611 (method url-fetch)
2612 (uri (string-append "mirror://gnu/hello/hello-" version
2613 ".tar.gz"))
2614 (sha256
2615 (base32
2616 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
3dc1970d 2617 (build-system gnu-build-system)
654c0d97 2618 (arguments '(#:configure-flags '("--enable-silent-rules")))
3dc1970d 2619 (inputs `(("gawk" ,gawk)))
7458bd0a
LC
2620 (synopsis "Hello, GNU world: An example GNU package")
2621 (description "Guess what GNU Hello prints!")
3dc1970d 2622 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 2623 (license gpl3+)))
3dc1970d
LC
2624@end example
2625
2626@noindent
2627Without being a Scheme expert, the reader may have guessed the meaning
f97c9175
AE
2628of the various fields here. This expression binds the variable
2629@code{hello} to a @code{<package>} object, which is essentially a record
3dc1970d
LC
2630(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2631This package object can be inspected using procedures found in the
2632@code{(guix packages)} module; for instance, @code{(package-name hello)}
2633returns---surprise!---@code{"hello"}.
2634
2f7d2d91
LC
2635With luck, you may be able to import part or all of the definition of
2636the package you are interested in from another repository, using the
2637@code{guix import} command (@pxref{Invoking guix import}).
2638
f97c9175 2639In the example above, @var{hello} is defined in a module of its own,
e7f34eb0
LC
2640@code{(gnu packages hello)}. Technically, this is not strictly
2641necessary, but it is convenient to do so: all the packages defined in
2642modules under @code{(gnu packages @dots{})} are automatically known to
2643the command-line tools (@pxref{Package Modules}).
2644
3dc1970d
LC
2645There are a few points worth noting in the above package definition:
2646
2647@itemize
2648@item
a2bf4907
LC
2649The @code{source} field of the package is an @code{<origin>} object
2650(@pxref{origin Reference}, for the complete reference).
3dc1970d
LC
2651Here, the @code{url-fetch} method from @code{(guix download)} is used,
2652meaning that the source is a file to be downloaded over FTP or HTTP.
2653
2654The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2655the GNU mirrors defined in @code{(guix download)}.
2656
2657The @code{sha256} field specifies the expected SHA256 hash of the file
2658being downloaded. It is mandatory, and allows Guix to check the
2659integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 2660base32 representation of the hash. You can obtain this information with
210cc920
LC
2661@code{guix download} (@pxref{Invoking guix download}) and @code{guix
2662hash} (@pxref{Invoking guix hash}).
3dc1970d 2663
f9cc8971
LC
2664@cindex patches
2665When needed, the @code{origin} form can also have a @code{patches} field
2666listing patches to be applied, and a @code{snippet} field giving a
2667Scheme expression to modify the source code.
2668
3dc1970d
LC
2669@item
2670@cindex GNU Build System
7458bd0a
LC
2671The @code{build-system} field specifies the procedure to build the
2672package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2673represents the familiar GNU Build System, where packages may be
2674configured, built, and installed with the usual @code{./configure &&
2675make && make check && make install} command sequence.
2676
2677@item
2678The @code{arguments} field specifies options for the build system
2679(@pxref{Build Systems}). Here it is interpreted by
2680@var{gnu-build-system} as a request run @file{configure} with the
2681@code{--enable-silent-rules} flag.
3dc1970d 2682
654c0d97
LC
2683@cindex quote
2684@cindex quoting
2685@findex '
2686@findex quote
2687What about these quote (@code{'}) characters? They are Scheme syntax to
2688introduce a literal list; @code{'} is synonymous with @code{quote}.
2689@xref{Expression Syntax, quoting,, guile, GNU Guile Reference Manual},
2690for details. Here the value of the @code{arguments} field is a list of
2691arguments passed to the build system down the road, as with @code{apply}
2692(@pxref{Fly Evaluation, @code{apply},, guile, GNU Guile Reference
2693Manual}).
2694
2695The hash-colon (@code{#:}) sequence defines a Scheme @dfn{keyword}
2696(@pxref{Keywords,,, guile, GNU Guile Reference Manual}), and
2697@code{#:configure-flags} is a keyword used to pass a keyword argument
2698to the build system (@pxref{Coding With Keywords,,, guile, GNU Guile
2699Reference Manual}).
2700
3dc1970d
LC
2701@item
2702The @code{inputs} field specifies inputs to the build process---i.e.,
2703build-time or run-time dependencies of the package. Here, we define an
2704input called @code{"gawk"} whose value is that of the @var{gawk}
2705variable; @var{gawk} is itself bound to a @code{<package>} object.
2706
654c0d97
LC
2707@cindex backquote (quasiquote)
2708@findex `
2709@findex quasiquote
2710@cindex comma (unquote)
2711@findex ,
2712@findex unquote
2713@findex ,@@
2714@findex unquote-splicing
2715Again, @code{`} (a backquote, synonymous with @code{quasiquote}) allows
2716us to introduce a literal list in the @code{inputs} field, while
2717@code{,} (a comma, synonymous with @code{unquote}) allows us to insert a
2718value in that list (@pxref{Expression Syntax, unquote,, guile, GNU Guile
2719Reference Manual}).
2720
3dc1970d
LC
2721Note that GCC, Coreutils, Bash, and other essential tools do not need to
2722be specified as inputs here. Instead, @var{gnu-build-system} takes care
7458bd0a 2723of ensuring that they are present (@pxref{Build Systems}).
3dc1970d
LC
2724
2725However, any other dependencies need to be specified in the
2726@code{inputs} field. Any dependency not specified here will simply be
2727unavailable to the build process, possibly leading to a build failure.
2728@end itemize
2729
87eafdbd
TUBK
2730@xref{package Reference}, for a full description of possible fields.
2731
2f7d2d91 2732Once a package definition is in place, the
e49951eb 2733package may actually be built using the @code{guix build} command-line
39bee8a2
LC
2734tool (@pxref{Invoking guix build}). You can easily jump back to the
2735package definition using the @command{guix edit} command
2736(@pxref{Invoking guix edit}).
2737@xref{Packaging Guidelines}, for
b4f5e0e8
CR
2738more information on how to test package definitions, and
2739@ref{Invoking guix lint}, for information on how to check a definition
2740for style conformance.
2741
f97c9175 2742Finally, updating the package definition to a new upstream version
7458bd0a
LC
2743can be partly automated by the @command{guix refresh} command
2744(@pxref{Invoking guix refresh}).
3dc1970d
LC
2745
2746Behind the scenes, a derivation corresponding to the @code{<package>}
2747object is first computed by the @code{package-derivation} procedure.
834129e0 2748That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 2749The build actions it prescribes may then be realized by using the
3dc1970d
LC
2750@code{build-derivations} procedure (@pxref{The Store}).
2751
2752@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
2753Return the @code{<derivation>} object of @var{package} for @var{system}
2754(@pxref{Derivations}).
3dc1970d
LC
2755
2756@var{package} must be a valid @code{<package>} object, and @var{system}
2757must be a string denoting the target system type---e.g.,
2758@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2759must be a connection to the daemon, which operates on the store
2760(@pxref{The Store}).
2761@end deffn
568717fd 2762
9c1edabd
LC
2763@noindent
2764@cindex cross-compilation
2765Similarly, it is possible to compute a derivation that cross-builds a
2766package for some other system:
2767
2768@deffn {Scheme Procedure} package-cross-derivation @var{store} @
2769 @var{package} @var{target} [@var{system}]
59688fc4
LC
2770Return the @code{<derivation>} object of @var{package} cross-built from
2771@var{system} to @var{target}.
9c1edabd
LC
2772
2773@var{target} must be a valid GNU triplet denoting the target hardware
2774and operating system, such as @code{"mips64el-linux-gnu"}
2775(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2776Configure and Build System}).
2777@end deffn
2778
2a75b0b6
LC
2779@cindex package transformations
2780@cindex input rewriting
2781@cindex dependency tree rewriting
2782Packages can be manipulated in arbitrary ways. An example of a useful
2783transformation is @dfn{input rewriting}, whereby the dependency tree of
2784a package is rewritten by replacing specific inputs by others:
2785
2786@deffn {Scheme Procedure} package-input-rewriting @var{replacements} @
2787 [@var{rewrite-name}]
2788Return a procedure that, when passed a package, replaces its direct and
2789indirect dependencies (but not its implicit inputs) according to
2790@var{replacements}. @var{replacements} is a list of package pairs; the
2791first element of each pair is the package to replace, and the second one
2792is the replacement.
2793
2794Optionally, @var{rewrite-name} is a one-argument procedure that takes
2795the name of a package and returns its new name after rewrite.
2796@end deffn
2797
2798@noindent
2799Consider this example:
2800
2801@example
2802(define libressl-instead-of-openssl
2803 ;; This is a procedure to replace OPENSSL by LIBRESSL,
2804 ;; recursively.
2805 (package-input-rewriting `((,openssl . ,libressl))))
2806
2807(define git-with-libressl
2808 (libressl-instead-of-openssl git))
2809@end example
2810
2811@noindent
2812Here we first define a rewriting procedure that replaces @var{openssl}
2813with @var{libressl}. Then we use it to define a @dfn{variant} of the
2814@var{git} package that uses @var{libressl} instead of @var{openssl}.
2815This is exactly what the @option{--with-input} command-line option does
2816(@pxref{Package Transformation Options, @option{--with-input}}).
2817
87eafdbd
TUBK
2818@menu
2819* package Reference :: The package data type.
2820* origin Reference:: The origin data type.
2821@end menu
2822
2823
2824@node package Reference
2825@subsection @code{package} Reference
2826
2827This section summarizes all the options available in @code{package}
2828declarations (@pxref{Defining Packages}).
2829
2830@deftp {Data Type} package
2831This is the data type representing a package recipe.
2832
2833@table @asis
2834@item @code{name}
2835The name of the package, as a string.
2836
2837@item @code{version}
2838The version of the package, as a string.
2839
2840@item @code{source}
da675305
LC
2841An object telling how the source code for the package should be
2842acquired. Most of the time, this is an @code{origin} object, which
2843denotes a file fetched from the Internet (@pxref{origin Reference}). It
2844can also be any other ``file-like'' object such as a @code{local-file},
2845which denotes a file from the local file system (@pxref{G-Expressions,
2846@code{local-file}}).
87eafdbd
TUBK
2847
2848@item @code{build-system}
2849The build system that should be used to build the package (@pxref{Build
2850Systems}).
2851
2852@item @code{arguments} (default: @code{'()})
2853The arguments that should be passed to the build system. This is a
2854list, typically containing sequential keyword-value pairs.
2855
2856@item @code{inputs} (default: @code{'()})
70650c68
LC
2857@itemx @code{native-inputs} (default: @code{'()})
2858@itemx @code{propagated-inputs} (default: @code{'()})
2859@cindex inputs, of packages
2860These fields list dependencies of the package. Each one is a list of
2861tuples, where each tuple has a label for the input (a string) as its
2862first element, a package, origin, or derivation as its second element,
2863and optionally the name of the output thereof that should be used, which
2864defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
f97c9175 2865more on package outputs). For example, the list below specifies three
70650c68 2866inputs:
87eafdbd 2867
70650c68
LC
2868@example
2869`(("libffi" ,libffi)
2870 ("libunistring" ,libunistring)
2871 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
2872@end example
2873
2874@cindex cross compilation, package dependencies
2875The distinction between @code{native-inputs} and @code{inputs} is
2876necessary when considering cross-compilation. When cross-compiling,
2877dependencies listed in @code{inputs} are built for the @emph{target}
2878architecture; conversely, dependencies listed in @code{native-inputs}
2879are built for the architecture of the @emph{build} machine.
2880
f97c9175
AE
2881@code{native-inputs} is typically used to list tools needed at
2882build time, but not at run time, such as Autoconf, Automake, pkg-config,
70650c68
LC
2883Gettext, or Bison. @command{guix lint} can report likely mistakes in
2884this area (@pxref{Invoking guix lint}).
2885
2886@anchor{package-propagated-inputs}
2887Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
f97c9175
AE
2888specified packages will be automatically installed alongside the package
2889they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
70650c68
LC
2890package}}, for information on how @command{guix package} deals with
2891propagated inputs.)
21461f27 2892
e0508b6b
LC
2893For example this is necessary when a C/C++ library needs headers of
2894another library to compile, or when a pkg-config file refers to another
2895one @i{via} its @code{Requires} field.
2896
f97c9175
AE
2897Another example where @code{propagated-inputs} is useful is for languages
2898that lack a facility to record the run-time search path akin to the
c8ebb4c4 2899@code{RUNPATH} of ELF files; this includes Guile, Python, Perl, and
e0508b6b
LC
2900more. To ensure that libraries written in those languages can find
2901library code they depend on at run time, run-time dependencies must be
2902listed in @code{propagated-inputs} rather than @code{inputs}.
87eafdbd 2903
87eafdbd
TUBK
2904@item @code{self-native-input?} (default: @code{#f})
2905This is a Boolean field telling whether the package should use itself as
2906a native input when cross-compiling.
2907
2908@item @code{outputs} (default: @code{'("out")})
2909The list of output names of the package. @xref{Packages with Multiple
2910Outputs}, for typical uses of additional outputs.
2911
2912@item @code{native-search-paths} (default: @code{'()})
2913@itemx @code{search-paths} (default: @code{'()})
2914A list of @code{search-path-specification} objects describing
2915search-path environment variables honored by the package.
2916
2917@item @code{replacement} (default: @code{#f})
f97c9175 2918This must be either @code{#f} or a package object that will be used as a
87eafdbd
TUBK
2919@dfn{replacement} for this package. @xref{Security Updates, grafts},
2920for details.
2921
2922@item @code{synopsis}
2923A one-line description of the package.
2924
2925@item @code{description}
2926A more elaborate description of the package.
2927
2928@item @code{license}
e32171ee 2929@cindex license, of packages
f97c9175
AE
2930The license of the package; a value from @code{(guix licenses)},
2931or a list of such values.
87eafdbd
TUBK
2932
2933@item @code{home-page}
2934The URL to the home-page of the package, as a string.
2935
2936@item @code{supported-systems} (default: @var{%supported-systems})
2937The list of systems supported by the package, as strings of the form
2938@code{architecture-kernel}, for example @code{"x86_64-linux"}.
2939
2940@item @code{maintainers} (default: @code{'()})
2941The list of maintainers of the package, as @code{maintainer} objects.
2942
2943@item @code{location} (default: source location of the @code{package} form)
f97c9175 2944The source location of the package. It is useful to override this when
87eafdbd
TUBK
2945inheriting from another package, in which case this field is not
2946automatically corrected.
2947@end table
2948@end deftp
2949
2950
2951@node origin Reference
2952@subsection @code{origin} Reference
2953
2954This section summarizes all the options available in @code{origin}
2955declarations (@pxref{Defining Packages}).
2956
2957@deftp {Data Type} origin
2958This is the data type representing a source code origin.
2959
2960@table @asis
2961@item @code{uri}
2962An object containing the URI of the source. The object type depends on
2963the @code{method} (see below). For example, when using the
2964@var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2965values are: a URL represented as a string, or a list thereof.
2966
2967@item @code{method}
f97c9175 2968A procedure that handles the URI.
87eafdbd
TUBK
2969
2970Examples include:
2971
2972@table @asis
2973@item @var{url-fetch} from @code{(guix download)}
f97c9175 2974download a file from the HTTP, HTTPS, or FTP URL specified in the
87eafdbd
TUBK
2975@code{uri} field;
2976
db97a03a 2977@vindex git-fetch
87eafdbd
TUBK
2978@item @var{git-fetch} from @code{(guix git-download)}
2979clone the Git version control repository, and check out the revision
2980specified in the @code{uri} field as a @code{git-reference} object; a
2981@code{git-reference} looks like this:
2982
2983@example
2984(git-reference
2985 (url "git://git.debian.org/git/pkg-shadow/shadow")
2986 (commit "v4.1.5.1"))
2987@end example
2988@end table
2989
2990@item @code{sha256}
2991A bytevector containing the SHA-256 hash of the source. Typically the
2992@code{base32} form is used here to generate the bytevector from a
2993base-32 string.
2994
db97a03a
LC
2995You can obtain this information using @code{guix download}
2996(@pxref{Invoking guix download}) or @code{guix hash} (@pxref{Invoking
2997guix hash}).
2998
87eafdbd
TUBK
2999@item @code{file-name} (default: @code{#f})
3000The file name under which the source code should be saved. When this is
3001@code{#f}, a sensible default value will be used in most cases. In case
3002the source is fetched from a URL, the file name from the URL will be
f97c9175 3003used. For version control checkouts, it is recommended to provide the
87eafdbd
TUBK
3004file name explicitly because the default is not very descriptive.
3005
3006@item @code{patches} (default: @code{'()})
3007A list of file names containing patches to be applied to the source.
3008
0dfebdaa
LC
3009This list of patches must be unconditional. In particular, it cannot
3010depend on the value of @code{%current-system} or
3011@code{%current-target-system}.
3012
87eafdbd 3013@item @code{snippet} (default: @code{#f})
1929fdba
LC
3014A G-expression (@pxref{G-Expressions}) or S-expression that will be run
3015in the source directory. This is a convenient way to modify the source,
3016sometimes more convenient than a patch.
87eafdbd
TUBK
3017
3018@item @code{patch-flags} (default: @code{'("-p1")})
3019A list of command-line flags that should be passed to the @code{patch}
3020command.
3021
3022@item @code{patch-inputs} (default: @code{#f})
3023Input packages or derivations to the patching process. When this is
3024@code{#f}, the usual set of inputs necessary for patching are provided,
3025such as GNU@tie{}Patch.
3026
3027@item @code{modules} (default: @code{'()})
3028A list of Guile modules that should be loaded during the patching
3029process and while running the code in the @code{snippet} field.
3030
87eafdbd
TUBK
3031@item @code{patch-guile} (default: @code{#f})
3032The Guile package that should be used in the patching process. When
3033this is @code{#f}, a sensible default is used.
3034@end table
3035@end deftp
3036
9c1edabd 3037
7458bd0a
LC
3038@node Build Systems
3039@section Build Systems
3040
3041@cindex build system
3042Each package definition specifies a @dfn{build system} and arguments for
3043that build system (@pxref{Defining Packages}). This @code{build-system}
f97c9175 3044field represents the build procedure of the package, as well as implicit
7458bd0a
LC
3045dependencies of that build procedure.
3046
3047Build systems are @code{<build-system>} objects. The interface to
3048create and manipulate them is provided by the @code{(guix build-system)}
3049module, and actual build systems are exported by specific modules.
3050
f5fd4fd2 3051@cindex bag (low-level package representation)
0d5a559f
LC
3052Under the hood, build systems first compile package objects to
3053@dfn{bags}. A @dfn{bag} is like a package, but with less
3054ornamentation---in other words, a bag is a lower-level representation of
3055a package, which includes all the inputs of that package, including some
3056that were implicitly added by the build system. This intermediate
3057representation is then compiled to a derivation (@pxref{Derivations}).
3058
7458bd0a
LC
3059Build systems accept an optional list of @dfn{arguments}. In package
3060definitions, these are passed @i{via} the @code{arguments} field
3061(@pxref{Defining Packages}). They are typically keyword arguments
3062(@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
3063Guile Reference Manual}). The value of these arguments is usually
3064evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
3065by the daemon (@pxref{Derivations}).
3066
3067The main build system is @var{gnu-build-system}, which implements the
f97c9175 3068standard build procedure for GNU and many other packages. It
7458bd0a
LC
3069is provided by the @code{(guix build-system gnu)} module.
3070
3071@defvr {Scheme Variable} gnu-build-system
3072@var{gnu-build-system} represents the GNU Build System, and variants
3073thereof (@pxref{Configuration, configuration and makefile conventions,,
3074standards, GNU Coding Standards}).
3075
3076@cindex build phases
f97c9175 3077In a nutshell, packages using it are configured, built, and installed with
7458bd0a
LC
3078the usual @code{./configure && make && make check && make install}
3079command sequence. In practice, a few additional steps are often needed.
3080All these steps are split up in separate @dfn{phases},
3081notably@footnote{Please see the @code{(guix build gnu-build-system)}
3082modules for more details about the build phases.}:
3083
3084@table @code
3085@item unpack
3086Unpack the source tarball, and change the current directory to the
3087extracted source tree. If the source is actually a directory, copy it
3088to the build tree, and enter that directory.
3089
3090@item patch-source-shebangs
3091Patch shebangs encountered in source files so they refer to the right
3092store file names. For instance, this changes @code{#!/bin/sh} to
3093@code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
3094
3095@item configure
3096Run the @file{configure} script with a number of default options, such
3097as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
3098by the @code{#:configure-flags} argument.
3099
3100@item build
3101Run @code{make} with the list of flags specified with
0917e80e 3102@code{#:make-flags}. If the @code{#:parallel-build?} argument is true
7458bd0a
LC
3103(the default), build with @code{make -j}.
3104
3105@item check
3106Run @code{make check}, or some other target specified with
3107@code{#:test-target}, unless @code{#:tests? #f} is passed. If the
3108@code{#:parallel-tests?} argument is true (the default), run @code{make
3109check -j}.
3110
3111@item install
3112Run @code{make install} with the flags listed in @code{#:make-flags}.
3113
3114@item patch-shebangs
3115Patch shebangs on the installed executable files.
3116
3117@item strip
3118Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
3119is false), copying them to the @code{debug} output when available
3120(@pxref{Installing Debugging Files}).
3121@end table
3122
3123@vindex %standard-phases
3124The build-side module @code{(guix build gnu-build-system)} defines
3125@var{%standard-phases} as the default list of build phases.
3126@var{%standard-phases} is a list of symbol/procedure pairs, where the
3127procedure implements the actual phase.
3128
3129The list of phases used for a particular package can be changed with the
3130@code{#:phases} parameter. For instance, passing:
3131
3132@example
c2c5dc79 3133#:phases (modify-phases %standard-phases (delete 'configure))
7458bd0a
LC
3134@end example
3135
9bf404e9 3136means that all the phases described above will be used, except the
7458bd0a
LC
3137@code{configure} phase.
3138
3139In addition, this build system ensures that the ``standard'' environment
3140for GNU packages is available. This includes tools such as GCC, libc,
3141Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
f97c9175
AE
3142build-system gnu)} module for a complete list). We call these the
3143@dfn{implicit inputs} of a package, because package definitions do not
7458bd0a
LC
3144have to mention them.
3145@end defvr
3146
3147Other @code{<build-system>} objects are defined to support other
3148conventions and tools used by free software packages. They inherit most
3149of @var{gnu-build-system}, and differ mainly in the set of inputs
3150implicitly added to the build process, and in the list of phases
3151executed. Some of these build systems are listed below.
3152
5f7a1a4d
RW
3153@defvr {Scheme Variable} ant-build-system
3154This variable is exported by @code{(guix build-system ant)}. It
3155implements the build procedure for Java packages that can be built with
3156@url{http://ant.apache.org/, Ant build tool}.
3157
3158It adds both @code{ant} and the @dfn{Java Development Kit} (JDK) as
3159provided by the @code{icedtea} package to the set of inputs. Different
3160packages can be specified with the @code{#:ant} and @code{#:jdk}
3161parameters, respectively.
3162
3163When the original package does not provide a suitable Ant build file,
3164the parameter @code{#:jar-name} can be used to generate a minimal Ant
3165build file @file{build.xml} with tasks to build the specified jar
3166archive.
3167
3168The parameter @code{#:build-target} can be used to specify the Ant task
3169that should be run during the @code{build} phase. By default the
3170``jar'' task will be run.
3171
3172@end defvr
3173
a1b30f99
AP
3174@defvr {Scheme Variable} asdf-build-system/source
3175@defvrx {Scheme Variable} asdf-build-system/sbcl
3176@defvrx {Scheme Variable} asdf-build-system/ecl
3177
3178These variables, exported by @code{(guix build-system asdf)}, implement
3179build procedures for Common Lisp packages using
3180@url{https://common-lisp.net/project/asdf/, ``ASDF''}. ASDF is a system
3181definition facility for Common Lisp programs and libraries.
3182
3183The @code{asdf-build-system/source} system installs the packages in
3184source form, and can be loaded using any common lisp implementation, via
3185ASDF. The others, such as @code{asdf-build-system/sbcl}, install binary
3186systems in the format which a particular implementation understands.
3187These build systems can also be used to produce executable programs, or
3188lisp images which contain a set of packages pre-loaded.
3189
3190The build system uses naming conventions. For binary packages, the
3191package itself as well as its run-time dependencies should begin their
3192name with the lisp implementation, such as @code{sbcl-} for
3193@code{asdf-build-system/sbcl}. Beginning the input name with this
3194prefix will allow the build system to encode its location into the
3195resulting library, so that the input can be found at run-time.
3196
3197If dependencies are used only for tests, it is convenient to use a
3198different prefix in order to avoid having a run-time dependency on such
3199systems. For example,
3200
3201@example
3202(define-public sbcl-bordeaux-threads
3203 (package
3204 ...
3205 (native-inputs `(("tests:cl-fiveam" ,sbcl-fiveam)))
3206 ...))
3207@end example
3208
3209Additionally, the corresponding source package should be labeled using
3210the same convention as python packages (see @ref{Python Modules}), using
3211the @code{cl-} prefix.
3212
3213For binary packages, each system should be defined as a Guix package.
3214If one package @code{origin} contains several systems, package variants
3215can be created in order to build all the systems. Source packages,
3216which use @code{asdf-build-system/source}, may contain several systems.
3217
3218In order to create executable programs and images, the build-side
3219procedures @code{build-program} and @code{build-image} can be used.
3220They should be called in a build phase after the @code{create-symlinks}
3221phase, so that the system which was just built can be used within the
3222resulting image. @code{build-program} requires a list of Common Lisp
3223expressions to be passed as the @code{#:entry-program} argument.
3224
3225If the system is not defined within its own @code{.asd} file of the same
3226name, then the @code{#:asd-file} parameter should be used to specify
3227which file the system is defined in.
3228
3229@end defvr
3230
1ec34dd7
LC
3231@defvr {Scheme Variable} cargo-build-system
3232@cindex Rust programming language
3233@cindex Cargo (Rust build system)
3234This variable is exported by @code{(guix build-system cargo)}. It
3235supports builds of packages using Cargo, the build tool of the
3236@uref{https://www.rust-lang.org, Rust programming language}.
3237
3238In its @code{configure} phase, this build system replaces dependencies
3239specified in the @file{Carto.toml} file with inputs to the Guix package.
3240The @code{install} phase installs the binaries, and it also installs the
3241source code and @file{Cargo.toml} file.
3242@end defvr
3243
7458bd0a
LC
3244@defvr {Scheme Variable} cmake-build-system
3245This variable is exported by @code{(guix build-system cmake)}. It
3246implements the build procedure for packages using the
3247@url{http://www.cmake.org, CMake build tool}.
3248
3249It automatically adds the @code{cmake} package to the set of inputs.
3250Which package is used can be specified with the @code{#:cmake}
3251parameter.
9849cfc1
LC
3252
3253The @code{#:configure-flags} parameter is taken as a list of flags
3254passed to the @command{cmake} command. The @code{#:build-type}
3255parameter specifies in abstract terms the flags passed to the compiler;
3256it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
3257debugging information''), which roughly means that code is compiled with
3258@code{-O2 -g}, as is the case for Autoconf-based packages by default.
7458bd0a
LC
3259@end defvr
3260
3afcf52b
FB
3261@defvr {Scheme Variable} glib-or-gtk-build-system
3262This variable is exported by @code{(guix build-system glib-or-gtk)}. It
3263is intended for use with packages making use of GLib or GTK+.
3264
3265This build system adds the following two phases to the ones defined by
3266@var{gnu-build-system}:
3267
3268@table @code
3269@item glib-or-gtk-wrap
f97c9175
AE
3270The phase @code{glib-or-gtk-wrap} ensures that programs in
3271@file{bin/} are able to find GLib ``schemas'' and
3afcf52b
FB
3272@uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
3273modules}. This is achieved by wrapping the programs in launch scripts
3274that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
3275environment variables.
3276
73aa8ddb
LC
3277It is possible to exclude specific package outputs from that wrapping
3278process by listing their names in the
3279@code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
3280when an output is known not to contain any GLib or GTK+ binaries, and
3281where wrapping would gratuitously add a dependency of that output on
3282GLib and GTK+.
3283
3afcf52b 3284@item glib-or-gtk-compile-schemas
f97c9175 3285The phase @code{glib-or-gtk-compile-schemas} makes sure that all
3afcf52b 3286@uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
f97c9175 3287GSettings schemas} of GLib are compiled. Compilation is performed by the
3afcf52b
FB
3288@command{glib-compile-schemas} program. It is provided by the package
3289@code{glib:bin} which is automatically imported by the build system.
3290The @code{glib} package providing @command{glib-compile-schemas} can be
3291specified with the @code{#:glib} parameter.
3292@end table
3293
3294Both phases are executed after the @code{install} phase.
3295@end defvr
3296
3184f14a
JL
3297@defvr {Scheme Variable} ocaml-build-system
3298This variable is exported by @code{(guix build-sytem ocaml)}. It implements
3299a build procedure for @uref{https://ocaml.org, OCaml} packages, which consists
3300of choosing the correct set of commands to run for each package. OCaml
3301packages can expect many different commands to be run. This build system will
3302try some of them.
3303
3304When the package has a @file{setup.ml} file present at the top-level, it will
3305run @code{ocaml setup.ml -configure}, @code{ocaml setup.ml -build} and
3306@code{ocaml setup.ml -install}. The build system will assume that this file
3307was generated by @uref{http://oasis.forge.ocamlcore.org/, OASIS} and will take
3308care of setting the prefix and enabling tests if they are not disabled. You
3309can pass configure and build flags with the @code{#:configure-flags} and
3310@code{#:build-flags}. The @code{#:test-flags} key can be passed to change the
3311set of flags used to enable tests. The @code{#:use-make?} key can be used to
3312bypass this system in the build and install phases.
3313
3314When the package has a @file{configure} file, it is assumed that it is a
3315hand-made configure script that requires a different argument format than
3316in the @code{gnu-build-system}. You can add more flags with the
3317@code{#:configure-flags} key.
3318
3319When the package has a @file{Makefile} file (or @code{#:use-make?} is
3320@code{#t}), it will be used and more flags can be passed to the build and
3321install phases with the @code{#:make-flags} key.
3322
3323Finally, some packages do not have these files and use a somewhat standard
3324location for its build system. In that case, the build system will run
3325@code{ocaml pkg/pkg.ml} or @code{ocaml pkg/build.ml} and take care of
3326providing the path to the required findlib module. Additional flags can
3327be passed via the @code{#:build-flags} key. Install is taken care of by
3328@command{opam-installer}. In this case, the @code{opam} package must
3329be added to the @code{native-inputs} field of the package definition.
3330
3331Note that most OCaml packages assume they will be installed in the same
88ba7852 3332directory as OCaml, which is not what we want in guix. In particular, they
3184f14a 3333will install @file{.so} files in their module's directory, which is usually
88ba7852 3334fine because it is in the OCaml compiler directory. In guix though, these
3184f14a
JL
3335libraries cannot be found and we use @code{CAML_LD_LIBRARY_PATH}. This
3336variable points to @file{lib/ocaml/site-lib/stubslibs} and this is where
3337@file{.so} libraries should be installed.
3338@end defvr
3339
7458bd0a
LC
3340@defvr {Scheme Variable} python-build-system
3341This variable is exported by @code{(guix build-system python)}. It
3342implements the more or less standard build procedure used by Python
3343packages, which consists in running @code{python setup.py build} and
3344then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
3345
3346For packages that install stand-alone Python programs under @code{bin/},
f97c9175 3347it takes care of wrapping these programs so that their @code{PYTHONPATH}
7458bd0a
LC
3348environment variable points to all the Python libraries they depend on.
3349
8a46205b
CM
3350Which Python package is used to perform the build can be specified with
3351the @code{#:python} parameter. This is a useful way to force a package
3352to be built for a specific version of the Python interpreter, which
3353might be necessary if the package is only compatible with a single
3354interpreter version.
5f7565d1
HG
3355
3356By default guix calls @code{setup.py} under control of
3357@code{setuptools}, much like @command{pip} does. Some packages are not
3358compatible with setuptools (and pip), thus you can disable this by
3359setting the @code{#:use-setuptools} parameter to @code{#f}.
7458bd0a
LC
3360@end defvr
3361
3362@defvr {Scheme Variable} perl-build-system
3363This variable is exported by @code{(guix build-system perl)}. It
2d2a53fc
EB
3364implements the standard build procedure for Perl packages, which either
3365consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
3366followed by @code{Build} and @code{Build install}; or in running
3367@code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
f97c9175 3368@code{make} and @code{make install}, depending on which of
2d2a53fc
EB
3369@code{Build.PL} or @code{Makefile.PL} is present in the package
3370distribution. Preference is given to the former if both @code{Build.PL}
3371and @code{Makefile.PL} exist in the package distribution. This
3372preference can be reversed by specifying @code{#t} for the
3373@code{#:make-maker?} parameter.
3374
3375The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
3376passes flags specified by the @code{#:make-maker-flags} or
3377@code{#:module-build-flags} parameter, respectively.
7458bd0a
LC
3378
3379Which Perl package is used can be specified with @code{#:perl}.
3380@end defvr
3381
f8f3bef6
RW
3382@defvr {Scheme Variable} r-build-system
3383This variable is exported by @code{(guix build-system r)}. It
3384implements the build procedure used by @uref{http://r-project.org, R}
3385packages, which essentially is little more than running @code{R CMD
3386INSTALL --library=/gnu/store/@dots{}} in an environment where
3387@code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
3388are run after installation using the R function
3389@code{tools::testInstalledPackage}.
3390@end defvr
3391
c08f9818
DT
3392@defvr {Scheme Variable} ruby-build-system
3393This variable is exported by @code{(guix build-system ruby)}. It
3394implements the RubyGems build procedure used by Ruby packages, which
3395involves running @code{gem build} followed by @code{gem install}.
3396
5dc87623
DT
3397The @code{source} field of a package that uses this build system
3398typically references a gem archive, since this is the format that Ruby
3399developers use when releasing their software. The build system unpacks
3400the gem archive, potentially patches the source, runs the test suite,
3401repackages the gem, and installs it. Additionally, directories and
3402tarballs may be referenced to allow building unreleased gems from Git or
3403a traditional source release tarball.
e83c6d00 3404
c08f9818 3405Which Ruby package is used can be specified with the @code{#:ruby}
6e9f2913
PP
3406parameter. A list of additional flags to be passed to the @command{gem}
3407command can be specified with the @code{#:gem-flags} parameter.
c08f9818 3408@end defvr
7458bd0a 3409
a677c726
RW
3410@defvr {Scheme Variable} waf-build-system
3411This variable is exported by @code{(guix build-system waf)}. It
3412implements a build procedure around the @code{waf} script. The common
3413phases---@code{configure}, @code{build}, and @code{install}---are
3414implemented by passing their names as arguments to the @code{waf}
3415script.
3416
3417The @code{waf} script is executed by the Python interpreter. Which
3418Python package is used to run the script can be specified with the
3419@code{#:python} parameter.
3420@end defvr
3421
14dfdf2e
FB
3422@defvr {Scheme Variable} haskell-build-system
3423This variable is exported by @code{(guix build-system haskell)}. It
3424implements the Cabal build procedure used by Haskell packages, which
3425involves running @code{runhaskell Setup.hs configure
3426--prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
3427Instead of installing the package by running @code{runhaskell Setup.hs
3428install}, to avoid trying to register libraries in the read-only
3429compiler store directory, the build system uses @code{runhaskell
3430Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
3431addition, the build system generates the package documentation by
3432running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
3433is passed. Optional Haddock parameters can be passed with the help of
3434the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
3435not found, the build system looks for @code{Setup.lhs} instead.
3436
3437Which Haskell compiler is used can be specified with the @code{#:haskell}
a54bd6d7 3438parameter which defaults to @code{ghc}.
14dfdf2e
FB
3439@end defvr
3440
65e862d1
DM
3441@defvr {Scheme Variable} dub-build-system
3442This variable is exported by @code{(guix build-system dub)}. It
3443implements the Dub build procedure used by D packages, which
3444involves running @code{dub build} and @code{dub run}.
3445Installation is done by copying the files manually.
3446
3447Which D compiler is used can be specified with the @code{#:ldc}
3448parameter which defaults to @code{ldc}.
3449@end defvr
3450
e9137a53
FB
3451@defvr {Scheme Variable} emacs-build-system
3452This variable is exported by @code{(guix build-system emacs)}. It
f97c9175
AE
3453implements an installation procedure similar to the packaging system
3454of Emacs itself (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
e9137a53
FB
3455
3456It first creates the @code{@var{package}-autoloads.el} file, then it
3457byte compiles all Emacs Lisp files. Differently from the Emacs
3458packaging system, the Info documentation files are moved to the standard
3459documentation directory and the @file{dir} file is deleted. Each
3460package is installed in its own directory under
3461@file{share/emacs/site-lisp/guix.d}.
3462@end defvr
3463
7458bd0a
LC
3464Lastly, for packages that do not need anything as sophisticated, a
3465``trivial'' build system is provided. It is trivial in the sense that
3466it provides basically no support: it does not pull any implicit inputs,
3467and does not have a notion of build phases.
3468
3469@defvr {Scheme Variable} trivial-build-system
3470This variable is exported by @code{(guix build-system trivial)}.
3471
3472This build system requires a @code{#:builder} argument. This argument
f97c9175 3473must be a Scheme expression that builds the package output(s)---as
7458bd0a
LC
3474with @code{build-expression->derivation} (@pxref{Derivations,
3475@code{build-expression->derivation}}).
3476@end defvr
3477
568717fd
LC
3478@node The Store
3479@section The Store
3480
e531ac2a 3481@cindex store
1ddee424 3482@cindex store items
e531ac2a
LC
3483@cindex store paths
3484
f97c9175
AE
3485Conceptually, the @dfn{store} is the place where derivations that have
3486been built successfully are stored---by default, @file{/gnu/store}.
1ddee424
LC
3487Sub-directories in the store are referred to as @dfn{store items} or
3488sometimes @dfn{store paths}. The store has an associated database that
3489contains information such as the store paths referred to by each store
3490path, and the list of @emph{valid} store items---results of successful
ef5f5c86
LC
3491builds. This database resides in @file{@var{localstatedir}/guix/db},
3492where @var{localstatedir} is the state directory specified @i{via}
3493@option{--localstatedir} at configure time, usually @file{/var}.
1ddee424
LC
3494
3495The store is @emph{always} accessed by the daemon on behalf of its clients
e531ac2a 3496(@pxref{Invoking guix-daemon}). To manipulate the store, clients
f97c9175
AE
3497connect to the daemon over a Unix-domain socket, send requests to it,
3498and read the result---these are remote procedure calls, or RPCs.
e531ac2a 3499
1ddee424
LC
3500@quotation Note
3501Users must @emph{never} modify files under @file{/gnu/store} directly.
3502This would lead to inconsistencies and break the immutability
3503assumptions of Guix's functional model (@pxref{Introduction}).
3504
3505@xref{Invoking guix gc, @command{guix gc --verify}}, for information on
3506how to check the integrity of the store and attempt recovery from
3507accidental modifications.
3508@end quotation
3509
e531ac2a
LC
3510The @code{(guix store)} module provides procedures to connect to the
3511daemon, and to perform RPCs. These are described below.
3512
3513@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
3514Connect to the daemon over the Unix-domain socket at @var{file}. When
3515@var{reserve-space?} is true, instruct it to reserve a little bit of
3516extra space on the file system so that the garbage collector can still
f97c9175 3517operate should the disk become full. Return a server object.
e531ac2a
LC
3518
3519@var{file} defaults to @var{%default-socket-path}, which is the normal
3520location given the options that were passed to @command{configure}.
3521@end deffn
3522
3523@deffn {Scheme Procedure} close-connection @var{server}
3524Close the connection to @var{server}.
3525@end deffn
3526
3527@defvr {Scheme Variable} current-build-output-port
3528This variable is bound to a SRFI-39 parameter, which refers to the port
3529where build and error logs sent by the daemon should be written.
3530@end defvr
3531
3532Procedures that make RPCs all take a server object as their first
3533argument.
3534
3535@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
06b76acc
LC
3536@cindex invalid store items
3537Return @code{#t} when @var{path} designates a valid store item and
3538@code{#f} otherwise (an invalid item may exist on disk but still be
3539invalid, for instance because it is the result of an aborted or failed
3540build.)
3541
3542A @code{&nix-protocol-error} condition is raised if @var{path} is not
3543prefixed by the store directory (@file{/gnu/store}).
e531ac2a
LC
3544@end deffn
3545
cfbf9160 3546@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
3547Add @var{text} under file @var{name} in the store, and return its store
3548path. @var{references} is the list of store paths referred to by the
3549resulting store path.
3550@end deffn
3551
874e6874 3552@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
3553Build @var{derivations} (a list of @code{<derivation>} objects or
3554derivation paths), and return when the worker is done building them.
3555Return @code{#t} on success.
874e6874
LC
3556@end deffn
3557
b860f382
LC
3558Note that the @code{(guix monads)} module provides a monad as well as
3559monadic versions of the above procedures, with the goal of making it
3560more convenient to work with code that accesses the store (@pxref{The
3561Store Monad}).
3562
e531ac2a
LC
3563@c FIXME
3564@i{This section is currently incomplete.}
568717fd
LC
3565
3566@node Derivations
3567@section Derivations
3568
874e6874
LC
3569@cindex derivations
3570Low-level build actions and the environment in which they are performed
70458ed5 3571are represented by @dfn{derivations}. A derivation contains the
874e6874
LC
3572following pieces of information:
3573
3574@itemize
3575@item
3576The outputs of the derivation---derivations produce at least one file or
3577directory in the store, but may produce more.
3578
3579@item
3580The inputs of the derivations, which may be other derivations or plain
3581files in the store (patches, build scripts, etc.)
3582
3583@item
3584The system type targeted by the derivation---e.g., @code{x86_64-linux}.
3585
3586@item
3587The file name of a build script in the store, along with the arguments
3588to be passed.
3589
3590@item
3591A list of environment variables to be defined.
3592
3593@end itemize
3594
3595@cindex derivation path
3596Derivations allow clients of the daemon to communicate build actions to
3597the store. They exist in two forms: as an in-memory representation,
3598both on the client- and daemon-side, and as files in the store whose
3599name end in @code{.drv}---these files are referred to as @dfn{derivation
3600paths}. Derivations paths can be passed to the @code{build-derivations}
3601procedure to perform the build actions they prescribe (@pxref{The
3602Store}).
3603
3604The @code{(guix derivations)} module provides a representation of
3605derivations as Scheme objects, along with procedures to create and
3606otherwise manipulate derivations. The lowest-level primitive to create
3607a derivation is the @code{derivation} procedure:
3608
1909431c
LC
3609@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
3610 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 3611 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c 3612 [#:system (%current-system)] [#:references-graphs #f] @
35b5ca78
LC
3613 [#:allowed-references #f] [#:disallowed-references #f] @
3614 [#:leaked-env-vars #f] [#:local-build? #f] @
4a6aeb67 3615 [#:substitutable? #t]
59688fc4
LC
3616Build a derivation with the given arguments, and return the resulting
3617@code{<derivation>} object.
874e6874 3618
2096ef47 3619When @var{hash} and @var{hash-algo} are given, a
874e6874 3620@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
3621known in advance, such as a file download. If, in addition,
3622@var{recursive?} is true, then that fixed output may be an executable
3623file or a directory and @var{hash} must be the hash of an archive
3624containing this output.
5b0c9d16 3625
858e9282 3626When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
3627name/store path pairs. In that case, the reference graph of each store
3628path is exported in the build environment in the corresponding file, in
3629a simple text format.
1909431c 3630
b53be755 3631When @var{allowed-references} is true, it must be a list of store items
35b5ca78
LC
3632or outputs that the derivation's output may refer to. Likewise,
3633@var{disallowed-references}, if true, must be a list of things the
3634outputs may @emph{not} refer to.
b53be755 3635
c0468155
LC
3636When @var{leaked-env-vars} is true, it must be a list of strings
3637denoting environment variables that are allowed to ``leak'' from the
3638daemon's environment to the build environment. This is only applicable
3639to fixed-output derivations---i.e., when @var{hash} is true. The main
3640use is to allow variables such as @code{http_proxy} to be passed to
3641derivations that download files.
3642
1909431c
LC
3643When @var{local-build?} is true, declare that the derivation is not a
3644good candidate for offloading and should rather be built locally
3645(@pxref{Daemon Offload Setup}). This is the case for small derivations
3646where the costs of data transfers would outweigh the benefits.
4a6aeb67
LC
3647
3648When @var{substitutable?} is false, declare that substitutes of the
3649derivation's output should not be used (@pxref{Substitutes}). This is
3650useful, for instance, when building packages that capture details of the
3651host CPU instruction set.
874e6874
LC
3652@end deffn
3653
3654@noindent
3655Here's an example with a shell script as its builder, assuming
3656@var{store} is an open connection to the daemon, and @var{bash} points
3657to a Bash executable in the store:
3658
3659@lisp
3660(use-modules (guix utils)
3661 (guix store)
3662 (guix derivations))
3663
59688fc4
LC
3664(let ((builder ; add the Bash script to the store
3665 (add-text-to-store store "my-builder.sh"
3666 "echo hello world > $out\n" '())))
3667 (derivation store "foo"
3668 bash `("-e" ,builder)
21b679f6 3669 #:inputs `((,bash) (,builder))
59688fc4 3670 #:env-vars '(("HOME" . "/homeless"))))
834129e0 3671@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
3672@end lisp
3673
21b679f6
LC
3674As can be guessed, this primitive is cumbersome to use directly. A
3675better approach is to write build scripts in Scheme, of course! The
3676best course of action for that is to write the build code as a
3677``G-expression'', and to pass it to @code{gexp->derivation}. For more
6621cdb6 3678information, @pxref{G-Expressions}.
21b679f6 3679
f2fadbc1
AE
3680Once upon a time, @code{gexp->derivation} did not exist and constructing
3681derivations with build code written in Scheme was achieved with
3682@code{build-expression->derivation}, documented below. This procedure
3683is now deprecated in favor of the much nicer @code{gexp->derivation}.
3684
3685@deffn {Scheme Procedure} build-expression->derivation @var{store} @
3686 @var{name} @var{exp} @
3687 [#:system (%current-system)] [#:inputs '()] @
3688 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3689 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3690 [#:references-graphs #f] [#:allowed-references #f] @
35b5ca78 3691 [#:disallowed-references #f] @
f2fadbc1
AE
3692 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3693Return a derivation that executes Scheme expression @var{exp} as a
3694builder for derivation @var{name}. @var{inputs} must be a list of
3695@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
3696@code{"out"} is assumed. @var{modules} is a list of names of Guile
3697modules from the current search path to be copied in the store,
3698compiled, and made available in the load path during the execution of
3699@var{exp}---e.g., @code{((guix build utils) (guix build
3700gnu-build-system))}.
3701
3702@var{exp} is evaluated in an environment where @code{%outputs} is bound
3703to a list of output/path pairs, and where @code{%build-inputs} is bound
3704to a list of string/output-path pairs made from @var{inputs}.
3705Optionally, @var{env-vars} is a list of string pairs specifying the name
3706and value of environment variables visible to the builder. The builder
3707terminates by passing the result of @var{exp} to @code{exit}; thus, when
3708@var{exp} returns @code{#f}, the build is considered to have failed.
3709
3710@var{exp} is built using @var{guile-for-build} (a derivation). When
3711@var{guile-for-build} is omitted or is @code{#f}, the value of the
3712@code{%guile-for-build} fluid is used instead.
3713
3714See the @code{derivation} procedure for the meaning of
35b5ca78
LC
3715@var{references-graphs}, @var{allowed-references},
3716@var{disallowed-references}, @var{local-build?}, and
3717@var{substitutable?}.
f2fadbc1
AE
3718@end deffn
3719
3720@noindent
3721Here's an example of a single-output derivation that creates a directory
3722containing one file:
3723
3724@lisp
3725(let ((builder '(let ((out (assoc-ref %outputs "out")))
3726 (mkdir out) ; create /gnu/store/@dots{}-goo
3727 (call-with-output-file (string-append out "/test")
3728 (lambda (p)
3729 (display '(hello guix) p))))))
3730 (build-expression->derivation store "goo" builder))
3731
3732@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
3733@end lisp
3734
568717fd 3735
b860f382
LC
3736@node The Store Monad
3737@section The Store Monad
3738
3739@cindex monad
3740
3741The procedures that operate on the store described in the previous
3742sections all take an open connection to the build daemon as their first
3743argument. Although the underlying model is functional, they either have
3744side effects or depend on the current state of the store.
3745
3746The former is inconvenient: the connection to the build daemon has to be
3747carried around in all those functions, making it impossible to compose
3748functions that do not take that parameter with functions that do. The
3749latter can be problematic: since store operations have side effects
3750and/or depend on external state, they have to be properly sequenced.
3751
3752@cindex monadic values
3753@cindex monadic functions
3754This is where the @code{(guix monads)} module comes in. This module
3755provides a framework for working with @dfn{monads}, and a particularly
3756useful monad for our uses, the @dfn{store monad}. Monads are a
3757construct that allows two things: associating ``context'' with values
3758(in our case, the context is the store), and building sequences of
4827b36d 3759computations (here computations include accesses to the store). Values
b860f382
LC
3760in a monad---values that carry this additional context---are called
3761@dfn{monadic values}; procedures that return such values are called
3762@dfn{monadic procedures}.
3763
3764Consider this ``normal'' procedure:
3765
3766@example
45adbd62
LC
3767(define (sh-symlink store)
3768 ;; Return a derivation that symlinks the 'bash' executable.
3769 (let* ((drv (package-derivation store bash))
3770 (out (derivation->output-path drv))
3771 (sh (string-append out "/bin/bash")))
3772 (build-expression->derivation store "sh"
3773 `(symlink ,sh %output))))
b860f382
LC
3774@end example
3775
c6f30b81
LC
3776Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3777as a monadic function:
b860f382
LC
3778
3779@example
45adbd62 3780(define (sh-symlink)
b860f382 3781 ;; Same, but return a monadic value.
c6f30b81
LC
3782 (mlet %store-monad ((drv (package->derivation bash)))
3783 (gexp->derivation "sh"
3784 #~(symlink (string-append #$drv "/bin/bash")
3785 #$output))))
b860f382
LC
3786@end example
3787
4827b36d 3788There are several things to note in the second version: the @code{store}
c6f30b81
LC
3789parameter is now implicit and is ``threaded'' in the calls to the
3790@code{package->derivation} and @code{gexp->derivation} monadic
3791procedures, and the monadic value returned by @code{package->derivation}
3792is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3793
3794As it turns out, the call to @code{package->derivation} can even be
3795omitted since it will take place implicitly, as we will see later
3796(@pxref{G-Expressions}):
3797
3798@example
3799(define (sh-symlink)
3800 (gexp->derivation "sh"
3801 #~(symlink (string-append #$bash "/bin/bash")
3802 #$output)))
3803@end example
b860f382 3804
7ce21611 3805@c See
a01ad638 3806@c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
7ce21611
LC
3807@c for the funny quote.
3808Calling the monadic @code{sh-symlink} has no effect. As someone once
3809said, ``you exit a monad like you exit a building on fire: by running''.
3810So, to exit the monad and get the desired effect, one must use
3811@code{run-with-store}:
b860f382
LC
3812
3813@example
8e9aa37f
CAW
3814(run-with-store (open-connection) (sh-symlink))
3815@result{} /gnu/store/...-sh-symlink
b860f382
LC
3816@end example
3817
f97c9175 3818Note that the @code{(guix monad-repl)} module extends the Guile REPL with
b9b86078 3819new ``meta-commands'' to make it easier to deal with monadic procedures:
f97c9175 3820@code{run-in-store}, and @code{enter-store-monad}. The former is used
b9b86078
LC
3821to ``run'' a single monadic value through the store:
3822
3823@example
3824scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3825$1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3826@end example
3827
3828The latter enters a recursive REPL, where all the return values are
3829automatically run through the store:
3830
3831@example
3832scheme@@(guile-user)> ,enter-store-monad
3833store-monad@@(guile-user) [1]> (package->derivation hello)
3834$2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3835store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3836$3 = "/gnu/store/@dots{}-foo"
3837store-monad@@(guile-user) [1]> ,q
3838scheme@@(guile-user)>
3839@end example
3840
3841@noindent
3842Note that non-monadic values cannot be returned in the
3843@code{store-monad} REPL.
3844
e87f0591
LC
3845The main syntactic forms to deal with monads in general are provided by
3846the @code{(guix monads)} module and are described below.
b860f382
LC
3847
3848@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3849Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3850in @var{monad}.
3851@end deffn
3852
3853@deffn {Scheme Syntax} return @var{val}
3854Return a monadic value that encapsulates @var{val}.
3855@end deffn
3856
751630c9 3857@deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
b860f382 3858@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
751630c9
LC
3859procedures @var{mproc}@dots{}@footnote{This operation is commonly
3860referred to as ``bind'', but that name denotes an unrelated procedure in
3861Guile. Thus we use this somewhat cryptic symbol inherited from the
3862Haskell language.}. There can be one @var{mproc} or several of them, as
3863in this example:
3864
3865@example
3866(run-with-state
3867 (with-monad %state-monad
3868 (>>= (return 1)
3869 (lambda (x) (return (+ 1 x)))
3870 (lambda (x) (return (* 2 x)))))
3871 'some-state)
3872
3873@result{} 4
3874@result{} some-state
3875@end example
b860f382
LC
3876@end deffn
3877
3878@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3879 @var{body} ...
3880@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3881 @var{body} ...
3882Bind the variables @var{var} to the monadic values @var{mval} in
3883@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3884``normal'' value @var{val}, as per @code{let}.
3885
3886@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3887(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3888@end deffn
3889
405a9d4e
LC
3890@deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3891Bind @var{mexp} and the following monadic expressions in sequence,
3892returning the result of the last expression.
3893
3894This is akin to @code{mlet}, except that the return values of the
3895monadic expressions are ignored. In that sense, it is analogous to
3896@code{begin}, but applied to monadic expressions.
3897@end deffn
3898
561fb6c3
LC
3899@cindex state monad
3900The @code{(guix monads)} module provides the @dfn{state monad}, which
3901allows an additional value---the state---to be @emph{threaded} through
3902monadic procedure calls.
3903
3904@defvr {Scheme Variable} %state-monad
3905The state monad. Procedures in the state monad can access and change
3906the state that is threaded.
3907
3908Consider the example below. The @code{square} procedure returns a value
3909in the state monad. It returns the square of its argument, but also
3910increments the current state value:
3911
3912@example
3913(define (square x)
3914 (mlet %state-monad ((count (current-state)))
3915 (mbegin %state-monad
3916 (set-current-state (+ 1 count))
3917 (return (* x x)))))
3918
3919(run-with-state (sequence %state-monad (map square (iota 3))) 0)
3920@result{} (0 1 4)
3921@result{} 3
3922@end example
3923
3924When ``run'' through @var{%state-monad}, we obtain that additional state
3925value, which is the number of @code{square} calls.
3926@end defvr
3927
3928@deffn {Monadic Procedure} current-state
3929Return the current state as a monadic value.
3930@end deffn
3931
3932@deffn {Monadic Procedure} set-current-state @var{value}
3933Set the current state to @var{value} and return the previous state as a
3934monadic value.
3935@end deffn
3936
3937@deffn {Monadic Procedure} state-push @var{value}
3938Push @var{value} to the current state, which is assumed to be a list,
3939and return the previous state as a monadic value.
3940@end deffn
3941
3942@deffn {Monadic Procedure} state-pop
3943Pop a value from the current state and return it as a monadic value.
3944The state is assumed to be a list.
3945@end deffn
3946
3947@deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3948Run monadic value @var{mval} starting with @var{state} as the initial
3949state. Return two values: the resulting value, and the resulting state.
3950@end deffn
3951
e87f0591
LC
3952The main interface to the store monad, provided by the @code{(guix
3953store)} module, is as follows.
b860f382
LC
3954
3955@defvr {Scheme Variable} %store-monad
561fb6c3
LC
3956The store monad---an alias for @var{%state-monad}.
3957
3958Values in the store monad encapsulate accesses to the store. When its
3959effect is needed, a value of the store monad must be ``evaluated'' by
3960passing it to the @code{run-with-store} procedure (see below.)
b860f382
LC
3961@end defvr
3962
3963@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3964Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3965open store connection.
3966@end deffn
3967
ad372953 3968@deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
b860f382 3969Return as a monadic value the absolute file name in the store of the file
ad372953
LC
3970containing @var{text}, a string. @var{references} is a list of store items that the
3971resulting text file refers to; it defaults to the empty list.
45adbd62
LC
3972@end deffn
3973
0a90af15 3974@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
1ec32f4a 3975 [#:recursive? #t] [#:select? (const #t)]
0a90af15
LC
3976Return the name of @var{file} once interned in the store. Use
3977@var{name} as its store name, or the basename of @var{file} if
3978@var{name} is omitted.
3979
3980When @var{recursive?} is true, the contents of @var{file} are added
3981recursively; if @var{file} designates a flat file and @var{recursive?}
3982is true, its contents are added, and its permission bits are kept.
3983
1ec32f4a
LC
3984When @var{recursive?} is true, call @code{(@var{select?} @var{file}
3985@var{stat})} for each directory entry, where @var{file} is the entry's
3986absolute file name and @var{stat} is the result of @code{lstat}; exclude
3987entries for which @var{select?} does not return true.
3988
0a90af15
LC
3989The example below adds a file to the store, under two different names:
3990
3991@example
3992(run-with-store (open-connection)
3993 (mlet %store-monad ((a (interned-file "README"))
3994 (b (interned-file "README" "LEGU-MIN")))
3995 (return (list a b))))
3996
3997@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3998@end example
3999
4000@end deffn
4001
e87f0591
LC
4002The @code{(guix packages)} module exports the following package-related
4003monadic procedures:
4004
b860f382 4005@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4231f05b 4006 [#:system (%current-system)] [#:target #f] @
f97c9175
AE
4007 [#:output "out"]
4008Return as a monadic
b860f382
LC
4009value in the absolute file name of @var{file} within the @var{output}
4010directory of @var{package}. When @var{file} is omitted, return the name
4231f05b
LC
4011of the @var{output} directory of @var{package}. When @var{target} is
4012true, use it as a cross-compilation target triplet.
b860f382
LC
4013@end deffn
4014
b860f382 4015@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4231f05b
LC
4016@deffnx {Monadic Procedure} package->cross-derivation @var{package} @
4017 @var{target} [@var{system}]
4018Monadic version of @code{package-derivation} and
4019@code{package-cross-derivation} (@pxref{Defining Packages}).
b860f382
LC
4020@end deffn
4021
4022
21b679f6
LC
4023@node G-Expressions
4024@section G-Expressions
4025
4026@cindex G-expression
4027@cindex build code quoting
4028So we have ``derivations'', which represent a sequence of build actions
4029to be performed to produce an item in the store (@pxref{Derivations}).
f97c9175 4030These build actions are performed when asking the daemon to actually
21b679f6
LC
4031build the derivations; they are run by the daemon in a container
4032(@pxref{Invoking guix-daemon}).
4033
4034@cindex strata of code
f97c9175 4035It should come as no surprise that we like to write these build actions
21b679f6
LC
4036in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
4037code@footnote{The term @dfn{stratum} in this context was coined by
ef4ab0a4
LC
4038Manuel Serrano et al.@: in the context of their work on Hop. Oleg
4039Kiselyov, who has written insightful
4040@url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
4041on this topic}, refers to this kind of code generation as
4042@dfn{staging}.}: the ``host code''---code that defines packages, talks
4043to the daemon, etc.---and the ``build code''---code that actually
4044performs build actions, such as making directories, invoking
4045@command{make}, etc.
21b679f6
LC
4046
4047To describe a derivation and its build actions, one typically needs to
4048embed build code inside host code. It boils down to manipulating build
f97c9175 4049code as data, and the homoiconicity of Scheme---code has a direct
21b679f6 4050representation as data---comes in handy for that. But we need more than
f97c9175 4051the normal @code{quasiquote} mechanism in Scheme to construct build
21b679f6
LC
4052expressions.
4053
4054The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
4055S-expressions adapted to build expressions. G-expressions, or
f97c9175 4056@dfn{gexps}, consist essentially of three syntactic forms: @code{gexp},
21b679f6 4057@code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
f97c9175
AE
4058@code{#$}, and @code{#$@@}), which are comparable to
4059@code{quasiquote}, @code{unquote}, and @code{unquote-splicing},
4827b36d 4060respectively (@pxref{Expression Syntax, @code{quasiquote},, guile,
f97c9175 4061GNU Guile Reference Manual}). However, there are major differences:
21b679f6
LC
4062
4063@itemize
4064@item
4065Gexps are meant to be written to a file and run or manipulated by other
4066processes.
4067
4068@item
b39fc6f7
LC
4069When a high-level object such as a package or derivation is unquoted
4070inside a gexp, the result is as if its output file name had been
4071introduced.
ff40e9b7 4072
21b679f6
LC
4073@item
4074Gexps carry information about the packages or derivations they refer to,
4075and these dependencies are automatically added as inputs to the build
4076processes that use them.
4077@end itemize
4078
c2b84676 4079@cindex lowering, of high-level objects in gexps
343eacbe
LC
4080This mechanism is not limited to package and derivation
4081objects: @dfn{compilers} able to ``lower'' other high-level objects to
c2b84676
LC
4082derivations or files in the store can be defined,
4083such that these objects can also be inserted
f97c9175 4084into gexps. For example, a useful type of high-level objects that can be
343eacbe 4085inserted in a gexp is ``file-like objects'', which make it easy to
f97c9175 4086add files to the store and to refer to them in
558e8b11
LC
4087derivations and such (see @code{local-file} and @code{plain-file}
4088below.)
b39fc6f7 4089
21b679f6
LC
4090To illustrate the idea, here is an example of a gexp:
4091
4092@example
4093(define build-exp
4094 #~(begin
4095 (mkdir #$output)
4096 (chdir #$output)
aff8ce7c 4097 (symlink (string-append #$coreutils "/bin/ls")
21b679f6
LC
4098 "list-files")))
4099@end example
4100
4101This gexp can be passed to @code{gexp->derivation}; we obtain a
4102derivation that builds a directory containing exactly one symlink to
4103@file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
4104
4105@example
4106(gexp->derivation "the-thing" build-exp)
4107@end example
4108
e20fd1bf 4109As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
21b679f6
LC
4110substituted to the reference to the @var{coreutils} package in the
4111actual build code, and @var{coreutils} is automatically made an input to
4112the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
f97c9175
AE
4113output)}) is replaced by a string containing the directory name of the
4114output of the derivation.
667b2508
LC
4115
4116@cindex cross compilation
4117In a cross-compilation context, it is useful to distinguish between
4118references to the @emph{native} build of a package---that can run on the
4119host---versus references to cross builds of a package. To that end, the
4120@code{#+} plays the same role as @code{#$}, but is a reference to a
4121native package build:
4122
4123@example
4124(gexp->derivation "vi"
4125 #~(begin
4126 (mkdir #$output)
4127 (system* (string-append #+coreutils "/bin/ln")
4128 "-s"
4129 (string-append #$emacs "/bin/emacs")
4130 (string-append #$output "/bin/vi")))
4a3b6aa5 4131 #:target "mips64el-linux-gnu")
667b2508
LC
4132@end example
4133
4134@noindent
4135In the example above, the native build of @var{coreutils} is used, so
4136that @command{ln} can actually run on the host; but then the
4137cross-compiled build of @var{emacs} is referenced.
4138
0bb9929e
LC
4139@cindex imported modules, for gexps
4140@findex with-imported-modules
4141Another gexp feature is @dfn{imported modules}: sometimes you want to be
4142able to use certain Guile modules from the ``host environment'' in the
4143gexp, so those modules should be imported in the ``build environment''.
4144The @code{with-imported-modules} form allows you to express that:
4145
4146@example
4147(let ((build (with-imported-modules '((guix build utils))
4148 #~(begin
4149 (use-modules (guix build utils))
4150 (mkdir-p (string-append #$output "/bin"))))))
4151 (gexp->derivation "empty-dir"
4152 #~(begin
4153 #$build
4154 (display "success!\n")
4155 #t)))
4156@end example
4157
4158@noindent
4159In this example, the @code{(guix build utils)} module is automatically
4160pulled into the isolated build environment of our gexp, such that
4161@code{(use-modules (guix build utils))} works as expected.
4162
7ca87354
LC
4163@cindex module closure
4164@findex source-module-closure
4165Usually you want the @emph{closure} of the module to be imported---i.e.,
4166the module itself and all the modules it depends on---rather than just
4167the module; failing to do that, attempts to use the module will fail
4168because of missing dependent modules. The @code{source-module-closure}
4169procedure computes the closure of a module by looking at its source file
4170headers, which comes in handy in this case:
4171
4172@example
4173(use-modules (guix modules)) ;for 'source-module-closure'
4174
4175(with-imported-modules (source-module-closure
4176 '((guix build utils)
4177 (gnu build vm)))
4178 (gexp->derivation "something-with-vms"
4179 #~(begin
4180 (use-modules (guix build utils)
4181 (gnu build vm))
4182 @dots{})))
4183@end example
4184
667b2508 4185The syntactic form to construct gexps is summarized below.
21b679f6
LC
4186
4187@deffn {Scheme Syntax} #~@var{exp}
4188@deffnx {Scheme Syntax} (gexp @var{exp})
4189Return a G-expression containing @var{exp}. @var{exp} may contain one
4190or more of the following forms:
4191
4192@table @code
4193@item #$@var{obj}
4194@itemx (ungexp @var{obj})
b39fc6f7
LC
4195Introduce a reference to @var{obj}. @var{obj} may have one of the
4196supported types, for example a package or a
21b679f6
LC
4197derivation, in which case the @code{ungexp} form is replaced by its
4198output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
4199
b39fc6f7
LC
4200If @var{obj} is a list, it is traversed and references to supported
4201objects are substituted similarly.
21b679f6
LC
4202
4203If @var{obj} is another gexp, its contents are inserted and its
4204dependencies are added to those of the containing gexp.
4205
4206If @var{obj} is another kind of object, it is inserted as is.
4207
b39fc6f7
LC
4208@item #$@var{obj}:@var{output}
4209@itemx (ungexp @var{obj} @var{output})
21b679f6 4210This is like the form above, but referring explicitly to the
b39fc6f7
LC
4211@var{output} of @var{obj}---this is useful when @var{obj} produces
4212multiple outputs (@pxref{Packages with Multiple Outputs}).
21b679f6 4213
667b2508
LC
4214@item #+@var{obj}
4215@itemx #+@var{obj}:output
4216@itemx (ungexp-native @var{obj})
4217@itemx (ungexp-native @var{obj} @var{output})
4218Same as @code{ungexp}, but produces a reference to the @emph{native}
4219build of @var{obj} when used in a cross compilation context.
4220
21b679f6
LC
4221@item #$output[:@var{output}]
4222@itemx (ungexp output [@var{output}])
4223Insert a reference to derivation output @var{output}, or to the main
4224output when @var{output} is omitted.
4225
4226This only makes sense for gexps passed to @code{gexp->derivation}.
4227
4228@item #$@@@var{lst}
4229@itemx (ungexp-splicing @var{lst})
4230Like the above, but splices the contents of @var{lst} inside the
4231containing list.
4232
667b2508
LC
4233@item #+@@@var{lst}
4234@itemx (ungexp-native-splicing @var{lst})
4235Like the above, but refers to native builds of the objects listed in
4236@var{lst}.
4237
21b679f6
LC
4238@end table
4239
4240G-expressions created by @code{gexp} or @code{#~} are run-time objects
4241of the @code{gexp?} type (see below.)
4242@end deffn
4243
0bb9929e
LC
4244@deffn {Scheme Syntax} with-imported-modules @var{modules} @var{body}@dots{}
4245Mark the gexps defined in @var{body}@dots{} as requiring @var{modules}
4246in their execution environment. @var{modules} must be a list of Guile
4247module names, such as @code{'((guix build utils) (guix build gremlin))}.
4248
4249This form has @emph{lexical} scope: it has an effect on the gexps
4250directly defined in @var{body}@dots{}, but not on those defined, say, in
4251procedures called from @var{body}@dots{}.
4252@end deffn
4253
21b679f6
LC
4254@deffn {Scheme Procedure} gexp? @var{obj}
4255Return @code{#t} if @var{obj} is a G-expression.
4256@end deffn
4257
4258G-expressions are meant to be written to disk, either as code building
4259some derivation, or as plain files in the store. The monadic procedures
4260below allow you to do that (@pxref{The Store Monad}, for more
4261information about monads.)
4262
4263@deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
ce45eb4c 4264 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
21b679f6
LC
4265 [#:hash #f] [#:hash-algo #f] @
4266 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4684f301 4267 [#:module-path @var{%load-path}] @
c8351d9a 4268 [#:references-graphs #f] [#:allowed-references #f] @
3f4ecf32 4269 [#:disallowed-references #f] @
c0468155 4270 [#:leaked-env-vars #f] @
0309e1b0 4271 [#:script-name (string-append @var{name} "-builder")] @
4a6aeb67 4272 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
21b679f6 4273Return a derivation @var{name} that runs @var{exp} (a gexp) with
0309e1b0
LC
4274@var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
4275stored in a file called @var{script-name}. When @var{target} is true,
4276it is used as the cross-compilation target triplet for packages referred
4277to by @var{exp}.
21b679f6 4278
0bb9929e
LC
4279@var{modules} is deprecated in favor of @code{with-imported-modules}.
4280Its meaning is to
4281make @var{modules} available in the evaluation context of @var{exp};
ce45eb4c
LC
4282@var{modules} is a list of names of Guile modules searched in
4283@var{module-path} to be copied in the store, compiled, and made available in
21b679f6
LC
4284the load path during the execution of @var{exp}---e.g., @code{((guix
4285build utils) (guix build gnu-build-system))}.
4286
ce45eb4c
LC
4287@var{graft?} determines whether packages referred to by @var{exp} should be grafted when
4288applicable.
4289
b53833b2
LC
4290When @var{references-graphs} is true, it must be a list of tuples of one of the
4291following forms:
4292
4293@example
4294(@var{file-name} @var{package})
4295(@var{file-name} @var{package} @var{output})
4296(@var{file-name} @var{derivation})
4297(@var{file-name} @var{derivation} @var{output})
4298(@var{file-name} @var{store-item})
4299@end example
4300
4301The right-hand-side of each element of @var{references-graphs} is automatically made
4302an input of the build process of @var{exp}. In the build environment, each
4303@var{file-name} contains the reference graph of the corresponding item, in a simple
4304text format.
4305
c8351d9a
LC
4306@var{allowed-references} must be either @code{#f} or a list of output names and packages.
4307In the latter case, the list denotes store items that the result is allowed to
4308refer to. Any reference to another store item will lead to a build error.
3f4ecf32
LC
4309Similarly for @var{disallowed-references}, which can list items that must not be
4310referenced by the outputs.
c8351d9a 4311
e20fd1bf 4312The other arguments are as for @code{derivation} (@pxref{Derivations}).
21b679f6
LC
4313@end deffn
4314
343eacbe 4315@cindex file-like objects
e1c153e0
LC
4316The @code{local-file}, @code{plain-file}, @code{computed-file},
4317@code{program-file}, and @code{scheme-file} procedures below return
4318@dfn{file-like objects}. That is, when unquoted in a G-expression,
4319these objects lead to a file in the store. Consider this G-expression:
343eacbe
LC
4320
4321@example
a9e5e92f 4322#~(system* #$(file-append glibc "/sbin/nscd") "-f"
343eacbe
LC
4323 #$(local-file "/tmp/my-nscd.conf"))
4324@end example
4325
4326The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
4327to the store. Once expanded, for instance @i{via}
4328@code{gexp->derivation}, the G-expression refers to that copy under
4329@file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
4330does not have any effect on what the G-expression does.
4331@code{plain-file} can be used similarly; it differs in that the file
4332content is directly passed as a string.
4333
d9ae938f 4334@deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
0687fc9c 4335 [#:recursive? #f] [#:select? (const #t)]
d9ae938f 4336Return an object representing local file @var{file} to add to the store; this
9d3994f7
LC
4337object can be used in a gexp. If @var{file} is a relative file name, it is looked
4338up relative to the source file where this form appears. @var{file} will be added to
4339the store under @var{name}--by default the base name of @var{file}.
d9ae938f
LC
4340
4341When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
4342designates a flat file and @var{recursive?} is true, its contents are added, and its
4343permission bits are kept.
4344
0687fc9c
LC
4345When @var{recursive?} is true, call @code{(@var{select?} @var{file}
4346@var{stat})} for each directory entry, where @var{file} is the entry's
4347absolute file name and @var{stat} is the result of @code{lstat}; exclude
4348entries for which @var{select?} does not return true.
4349
d9ae938f
LC
4350This is the declarative counterpart of the @code{interned-file} monadic
4351procedure (@pxref{The Store Monad, @code{interned-file}}).
4352@end deffn
4353
558e8b11
LC
4354@deffn {Scheme Procedure} plain-file @var{name} @var{content}
4355Return an object representing a text file called @var{name} with the given
4356@var{content} (a string) to be added to the store.
4357
4358This is the declarative counterpart of @code{text-file}.
4359@end deffn
4360
91937029 4361@deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
a769bffb 4362 [#:options '(#:local-build? #t)]
91937029 4363Return an object representing the store item @var{name}, a file or
a769bffb 4364directory computed by @var{gexp}. @var{options}
91937029
LC
4365is a list of additional arguments to pass to @code{gexp->derivation}.
4366
4367This is the declarative counterpart of @code{gexp->derivation}.
4368@end deffn
4369
21b679f6
LC
4370@deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
4371Return an executable script @var{name} that runs @var{exp} using
9c14a487 4372@var{guile}, with @var{exp}'s imported modules in its search path.
21b679f6
LC
4373
4374The example below builds a script that simply invokes the @command{ls}
4375command:
4376
4377@example
4378(use-modules (guix gexp) (gnu packages base))
4379
4380(gexp->script "list-files"
a9e5e92f 4381 #~(execl #$(file-append coreutils "/bin/ls")
21b679f6
LC
4382 "ls"))
4383@end example
4384
4385When ``running'' it through the store (@pxref{The Store Monad,
e20fd1bf 4386@code{run-with-store}}), we obtain a derivation that produces an
21b679f6
LC
4387executable file @file{/gnu/store/@dots{}-list-files} along these lines:
4388
4389@example
4390#!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
4391!#
a9e5e92f 4392(execl "/gnu/store/@dots{}-coreutils-8.22"/bin/ls" "ls")
21b679f6
LC
4393@end example
4394@end deffn
4395
15a01c72 4396@deffn {Scheme Procedure} program-file @var{name} @var{exp} @
9c14a487 4397 [#:guile #f]
15a01c72
LC
4398Return an object representing the executable store item @var{name} that
4399runs @var{gexp}. @var{guile} is the Guile package used to execute that
9c14a487 4400script.
15a01c72
LC
4401
4402This is the declarative counterpart of @code{gexp->script}.
4403@end deffn
4404
2b418579
LC
4405@deffn {Monadic Procedure} gexp->file @var{name} @var{exp} @
4406 [#:set-load-path? #t]
21b679f6 4407Return a derivation that builds a file @var{name} containing @var{exp}.
2b418579
LC
4408When @var{set-load-path?} is true, emit code in the resulting file to
4409set @code{%load-path} and @code{%load-compiled-path} to honor
4410@var{exp}'s imported modules.
21b679f6
LC
4411
4412The resulting file holds references to all the dependencies of @var{exp}
4413or a subset thereof.
4414@end deffn
1ed19464 4415
e1c153e0
LC
4416@deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
4417Return an object representing the Scheme file @var{name} that contains
4418@var{exp}.
4419
4420This is the declarative counterpart of @code{gexp->file}.
4421@end deffn
4422
1ed19464
LC
4423@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
4424Return as a monadic value a derivation that builds a text file
4425containing all of @var{text}. @var{text} may list, in addition to
d9ae938f
LC
4426strings, objects of any type that can be used in a gexp: packages,
4427derivations, local file objects, etc. The resulting store file holds
4428references to all these.
1ed19464
LC
4429
4430This variant should be preferred over @code{text-file} anytime the file
4431to create will reference items from the store. This is typically the
4432case when building a configuration file that embeds store file names,
4433like this:
4434
4435@example
4436(define (profile.sh)
4437 ;; Return the name of a shell script in the store that
4438 ;; initializes the 'PATH' environment variable.
4439 (text-file* "profile.sh"
4440 "export PATH=" coreutils "/bin:"
4441 grep "/bin:" sed "/bin\n"))
4442@end example
4443
4444In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
b7899749 4445will reference @var{coreutils}, @var{grep}, and @var{sed}, thereby
1ed19464
LC
4446preventing them from being garbage-collected during its lifetime.
4447@end deffn
21b679f6 4448
b751cde3
LC
4449@deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
4450Return an object representing store file @var{name} containing
4451@var{text}. @var{text} is a sequence of strings and file-like objects,
4452as in:
4453
4454@example
4455(mixed-text-file "profile"
4456 "export PATH=" coreutils "/bin:" grep "/bin")
4457@end example
4458
4459This is the declarative counterpart of @code{text-file*}.
4460@end deffn
4461
a9e5e92f
LC
4462@deffn {Scheme Procedure} file-append @var{obj} @var{suffix} @dots{}
4463Return a file-like object that expands to the concatenation of @var{obj}
4464and @var{suffix}, where @var{obj} is a lowerable object and each
4465@var{suffix} is a string.
4466
4467As an example, consider this gexp:
4468
4469@example
4470(gexp->script "run-uname"
4471 #~(system* #$(file-append coreutils
4472 "/bin/uname")))
4473@end example
4474
4475The same effect could be achieved with:
4476
4477@example
4478(gexp->script "run-uname"
4479 #~(system* (string-append #$coreutils
4480 "/bin/uname")))
4481@end example
4482
4483There is one difference though: in the @code{file-append} case, the
4484resulting script contains the absolute file name as a string, whereas in
4485the second case, the resulting script contains a @code{(string-append
4486@dots{})} expression to construct the file name @emph{at run time}.
4487@end deffn
4488
4489
21b679f6
LC
4490Of course, in addition to gexps embedded in ``host'' code, there are
4491also modules containing build tools. To make it clear that they are
4492meant to be used in the build stratum, these modules are kept in the
4493@code{(guix build @dots{})} name space.
4494
c2b84676
LC
4495@cindex lowering, of high-level objects in gexps
4496Internally, high-level objects are @dfn{lowered}, using their compiler,
4497to either derivations or store items. For instance, lowering a package
4498yields a derivation, and lowering a @code{plain-file} yields a store
4499item. This is achieved using the @code{lower-object} monadic procedure.
4500
4501@deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
4502 [#:target #f]
4503Return as a value in @var{%store-monad} the derivation or store item
4504corresponding to @var{obj} for @var{system}, cross-compiling for
4505@var{target} if @var{target} is true. @var{obj} must be an object that
4506has an associated gexp compiler, such as a @code{<package>}.
4507@end deffn
4508
21b679f6 4509
568717fd
LC
4510@c *********************************************************************
4511@node Utilities
4512@chapter Utilities
4513
6f773606
LC
4514This section describes Guix command-line utilities. Some of them are
4515primarily targeted at developers and users who write new package
4516definitions, while others are more generally useful. They complement
4517the Scheme programming interface of Guix in a convenient way.
210cc920 4518
568717fd 4519@menu
37166310 4520* Invoking guix build:: Building packages from the command line.
39bee8a2 4521* Invoking guix edit:: Editing package definitions.
210cc920 4522* Invoking guix download:: Downloading a file and printing its hash.
37166310 4523* Invoking guix hash:: Computing the cryptographic hash of a file.
2f7d2d91 4524* Invoking guix import:: Importing package definitions.
37166310 4525* Invoking guix refresh:: Updating package definitions.
b4f5e0e8 4526* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 4527* Invoking guix size:: Profiling disk usage.
88856916 4528* Invoking guix graph:: Visualizing the graph of packages.
372c4bbc 4529* Invoking guix environment:: Setting up development environments.
aff8ce7c 4530* Invoking guix publish:: Sharing substitutes.
d23c20f1 4531* Invoking guix challenge:: Challenging substitute servers.
f11c444d 4532* Invoking guix copy:: Copying to and from a remote store.
32efa254 4533* Invoking guix container:: Process isolation.
568717fd
LC
4534@end menu
4535
e49951eb
MW
4536@node Invoking guix build
4537@section Invoking @command{guix build}
568717fd 4538
e32171ee
JD
4539@cindex package building
4540@cindex @command{guix build}
e49951eb 4541The @command{guix build} command builds packages or derivations and
6798a8e4
LC
4542their dependencies, and prints the resulting store paths. Note that it
4543does not modify the user's profile---this is the job of the
e49951eb 4544@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
4545it is mainly useful for distribution developers.
4546
4547The general syntax is:
c78bd12b
LC
4548
4549@example
e49951eb 4550guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
4551@end example
4552
f97c9175 4553As an example, the following command builds the latest versions of Emacs
ccd7158d
LC
4554and of Guile, displays their build logs, and finally displays the
4555resulting directories:
4556
4557@example
4558guix build emacs guile
4559@end example
4560
4561Similarly, the following command builds all the available packages:
4562
4563@example
5284339d 4564guix build --quiet --keep-going \
ccd7158d
LC
4565 `guix package -A | cut -f1,2 --output-delimiter=@@`
4566@end example
4567
c78bd12b 4568@var{package-or-derivation} may be either the name of a package found in
5401dd75 4569the software distribution such as @code{coreutils} or
e1a65ae5 4570@code{coreutils@@8.20}, or a derivation such as
834129e0 4571@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
4572package with the corresponding name (and optionally version) is searched
4573for among the GNU distribution modules (@pxref{Package Modules}).
4574
4575Alternatively, the @code{--expression} option may be used to specify a
4576Scheme expression that evaluates to a package; this is useful when
b7899749 4577disambiguating among several same-named packages or package variants is
e7f34eb0 4578needed.
c78bd12b 4579
ccd7158d
LC
4580There may be zero or more @var{options}. The available options are
4581described in the subsections below.
4582
4583@menu
4584* Common Build Options:: Build options for most commands.
f11c444d 4585* Package Transformation Options:: Creating variants of packages.
ccd7158d
LC
4586* Additional Build Options:: Options specific to 'guix build'.
4587@end menu
4588
4589@node Common Build Options
4590@subsection Common Build Options
4591
4592A number of options that control the build process are common to
4593@command{guix build} and other commands that can spawn builds, such as
4594@command{guix package} or @command{guix archive}. These are the
4595following:
4596
4597@table @code
4598
4599@item --load-path=@var{directory}
4600@itemx -L @var{directory}
4601Add @var{directory} to the front of the package module search path
4602(@pxref{Package Modules}).
4603
4604This allows users to define their own packages and make them visible to
4605the command-line tools.
4606
4607@item --keep-failed
4608@itemx -K
b7899749 4609Keep the build tree of failed builds. Thus, if a build fails, its build
ccd7158d
LC
4610tree is kept under @file{/tmp}, in a directory whose name is shown at
4611the end of the build log. This is useful when debugging build issues.
4612
4613@item --keep-going
4614@itemx -k
4615Keep going when some of the derivations fail to build; return only once
4616all the builds have either completed or failed.
4617
4618The default behavior is to stop as soon as one of the specified
4619derivations has failed.
4620
4621@item --dry-run
4622@itemx -n
4623Do not build the derivations.
4624
4625@item --fallback
4626When substituting a pre-built binary fails, fall back to building
4627packages locally.
4628
4629@item --substitute-urls=@var{urls}
4630@anchor{client-substitute-urls}
4631Consider @var{urls} the whitespace-separated list of substitute source
4632URLs, overriding the default list of URLs of @command{guix-daemon}
4633(@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
4634
4635This means that substitutes may be downloaded from @var{urls}, provided
4636they are signed by a key authorized by the system administrator
4637(@pxref{Substitutes}).
4638
71e2065a
LC
4639When @var{urls} is the empty string, substitutes are effectively
4640disabled.
4641
ccd7158d
LC
4642@item --no-substitutes
4643Do not use substitutes for build products. That is, always build things
4644locally instead of allowing downloads of pre-built binaries
4645(@pxref{Substitutes}).
4646
7573d30f
LC
4647@item --no-grafts
4648Do not ``graft'' packages. In practice, this means that package updates
4649available as grafts are not applied. @xref{Security Updates}, for more
4650information on grafts.
4651
ccd7158d
LC
4652@item --rounds=@var{n}
4653Build each derivation @var{n} times in a row, and raise an error if
4654consecutive build results are not bit-for-bit identical.
4655
4656This is a useful way to detect non-deterministic builds processes.
4657Non-deterministic build processes are a problem because they make it
4658practically impossible for users to @emph{verify} whether third-party
4659binaries are genuine. @xref{Invoking guix challenge}, for more.
4660
4661Note that, currently, the differing build results are not kept around,
4662so you will have to manually investigate in case of an error---e.g., by
e66d1f59
ML
4663stashing one of the build results with @code{guix archive --export}
4664(@pxref{Invoking guix archive}), then rebuilding, and finally comparing
4665the two results.
ccd7158d
LC
4666
4667@item --no-build-hook
f97c9175 4668Do not attempt to offload builds @i{via} the ``build hook'' of the daemon
ccd7158d
LC
4669(@pxref{Daemon Offload Setup}). That is, always build things locally
4670instead of offloading builds to remote machines.
4671
4672@item --max-silent-time=@var{seconds}
4673When the build or substitution process remains silent for more than
4674@var{seconds}, terminate it and report a build failure.
4675
4676@item --timeout=@var{seconds}
4677Likewise, when the build or substitution process lasts for more than
4678@var{seconds}, terminate it and report a build failure.
4679
4680By default there is no timeout. This behavior can be restored with
4681@code{--timeout=0}.
4682
4683@item --verbosity=@var{level}
4684Use the given verbosity level. @var{level} must be an integer between 0
4685and 5; higher means more verbose output. Setting a level of 4 or more
4686may be helpful when debugging setup issues with the build daemon.
4687
4688@item --cores=@var{n}
4689@itemx -c @var{n}
4690Allow the use of up to @var{n} CPU cores for the build. The special
4691value @code{0} means to use as many CPU cores as available.
4692
4693@item --max-jobs=@var{n}
4694@itemx -M @var{n}
4695Allow at most @var{n} build jobs in parallel. @xref{Invoking
4696guix-daemon, @code{--max-jobs}}, for details about this option and the
4697equivalent @command{guix-daemon} option.
4698
4699@end table
4700
4701Behind the scenes, @command{guix build} is essentially an interface to
4702the @code{package-derivation} procedure of the @code{(guix packages)}
4703module, and to the @code{build-derivations} procedure of the @code{(guix
4704derivations)} module.
4705
4706In addition to options explicitly passed on the command line,
4707@command{guix build} and other @command{guix} commands that support
4708building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
4709
4710@defvr {Environment Variable} GUIX_BUILD_OPTIONS
4711Users can define this variable to a list of command line options that
4712will automatically be used by @command{guix build} and other
4713@command{guix} commands that can perform builds, as in the example
4714below:
4715
4716@example
4717$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
4718@end example
4719
4720These options are parsed independently, and the result is appended to
4721the parsed command-line options.
4722@end defvr
4723
88ad6ded
LC
4724
4725@node Package Transformation Options
4726@subsection Package Transformation Options
4727
4728@cindex package variants
4729Another set of command-line options supported by @command{guix build}
b8638f03 4730and also @command{guix package} are @dfn{package transformation
f97c9175 4731options}. These are options that make it possible to define @dfn{package
b8638f03
LC
4732variants}---for instance, packages built from different source code.
4733This is a convenient way to create customized packages on the fly
4734without having to type in the definitions of package variants
4735(@pxref{Defining Packages}).
88ad6ded
LC
4736
4737@table @code
4738
4739@item --with-source=@var{source}
4740Use @var{source} as the source of the corresponding package.
4741@var{source} must be a file name or a URL, as for @command{guix
4742download} (@pxref{Invoking guix download}).
4743
f97c9175
AE
4744The ``corresponding package'' is taken to be the one specified on the
4745command line the name of which matches the base of @var{source}---e.g.,
4746if @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
88ad6ded 4747package is @code{guile}. Likewise, the version string is inferred from
f97c9175 4748@var{source}; in the previous example, it is @code{2.0.10}.
88ad6ded
LC
4749
4750This option allows users to try out versions of packages other than the
4751one provided by the distribution. The example below downloads
4752@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
4753the @code{ed} package:
4754
4755@example
4756guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
4757@end example
4758
4759As a developer, @code{--with-source} makes it easy to test release
4760candidates:
4761
4762@example
4763guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
4764@end example
4765
4766@dots{} or to build from a checkout in a pristine environment:
4767
4768@example
4769$ git clone git://git.sv.gnu.org/guix.git
4770$ guix build guix --with-source=./guix
4771@end example
4772
47c0f92c
LC
4773@item --with-input=@var{package}=@var{replacement}
4774Replace dependency on @var{package} by a dependency on
4775@var{replacement}. @var{package} must be a package name, and
4776@var{replacement} must be a package specification such as @code{guile}
4777or @code{guile@@1.8}.
4778
f97c9175 4779For instance, the following command builds Guix, but replaces its
47c0f92c
LC
4780dependency on the current stable version of Guile with a dependency on
4781the development version of Guile, @code{guile-next}:
4782
4783@example
4784guix build --with-input=guile=guile-next guix
4785@end example
4786
4787This is a recursive, deep replacement. So in this example, both
4788@code{guix} and its dependency @code{guile-json} (which also depends on
4789@code{guile}) get rebuilt against @code{guile-next}.
4790
2a75b0b6
LC
4791This is implemented using the @code{package-input-rewriting} Scheme
4792procedure (@pxref{Defining Packages, @code{package-input-rewriting}}).
645b9df8
LC
4793
4794@item --with-graft=@var{package}=@var{replacement}
4795This is similar to @code{--with-input} but with an important difference:
9b4ec573 4796instead of rebuilding the whole dependency chain, @var{replacement} is
645b9df8
LC
4797built and then @dfn{grafted} onto the binaries that were initially
4798referring to @var{package}. @xref{Security Updates}, for more
4799information on grafts.
4800
4801For example, the command below grafts version 3.5.4 of GnuTLS onto Wget
4802and all its dependencies, replacing references to the version of GnuTLS
4803they currently refer to:
4804
4805@example
4806guix build --with-graft=gnutls=gnutls@@3.5.4 wget
4807@end example
4808
4809This has the advantage of being much faster than rebuilding everything.
4810But there is a caveat: it works if and only if @var{package} and
4811@var{replacement} are strictly compatible---for example, if they provide
4812a library, the application binary interface (ABI) of those libraries
4813must be compatible. If @var{replacement} is somehow incompatible with
4814@var{package}, then the resulting package may be unusable. Use with
4815care!
4816
88ad6ded
LC
4817@end table
4818
ccd7158d
LC
4819@node Additional Build Options
4820@subsection Additional Build Options
4821
4822The command-line options presented below are specific to @command{guix
4823build}.
c78bd12b
LC
4824
4825@table @code
4826
5284339d
LC
4827@item --quiet
4828@itemx -q
4829Build quietly, without displaying the build log. Upon completion, the
4830build log is kept in @file{/var} (or similar) and can always be
4831retrieved using the @option{--log-file} option.
4832
34a1783f
DT
4833@item --file=@var{file}
4834@itemx -f @var{file}
4835
4836Build the package or derivation that the code within @var{file}
4837evaluates to.
4838
4839As an example, @var{file} might contain a package definition like this
4840(@pxref{Defining Packages}):
4841
4842@example
4843@verbatiminclude package-hello.scm
4844@end example
4845
c78bd12b
LC
4846@item --expression=@var{expr}
4847@itemx -e @var{expr}
ac5de156 4848Build the package or derivation @var{expr} evaluates to.
c78bd12b 4849
5401dd75 4850For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
4851guile-1.8)}, which unambiguously designates this specific variant of
4852version 1.8 of Guile.
4853
f97c9175 4854Alternatively, @var{expr} may be a G-expression, in which case it is used
56b82106
LC
4855as a build program passed to @code{gexp->derivation}
4856(@pxref{G-Expressions}).
4857
4858Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
4859(@pxref{The Store Monad}). The procedure must return a derivation as a
4860monadic value, which is then passed through @code{run-with-store}.
4861
c78bd12b
LC
4862@item --source
4863@itemx -S
f97c9175 4864Build the source derivations of the packages, rather than the packages
c78bd12b
LC
4865themselves.
4866
e49951eb 4867For instance, @code{guix build -S gcc} returns something like
f97c9175
AE
4868@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
4869source tarball.
c78bd12b 4870
f9cc8971 4871The returned source tarball is the result of applying any patches and
f97c9175 4872code snippets specified in the package @code{origin} (@pxref{Defining
f9cc8971
LC
4873Packages}).
4874
2cdfe13d
EB
4875@item --sources
4876Fetch and return the source of @var{package-or-derivation} and all their
4877dependencies, recursively. This is a handy way to obtain a local copy
4878of all the source code needed to build @var{packages}, allowing you to
4879eventually build them even without network access. It is an extension
4880of the @code{--source} option and can accept one of the following
4881optional argument values:
4882
4883@table @code
4884@item package
4885This value causes the @code{--sources} option to behave in the same way
4886as the @code{--source} option.
4887
4888@item all
f97c9175
AE
4889Build the source derivations of all packages, including any source that
4890might be listed as @code{inputs}. This is the default value.
2cdfe13d
EB
4891
4892@example
4893$ guix build --sources tzdata
4894The following derivations will be built:
4895 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
4896 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4897@end example
4898
4899@item transitive
f97c9175
AE
4900Build the source derivations of all packages, as well of all transitive
4901inputs to the packages. This can be used e.g. to
2cdfe13d
EB
4902prefetch package source for later offline building.
4903
4904@example
4905$ guix build --sources=transitive tzdata
4906The following derivations will be built:
4907 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4908 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
4909 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
4910 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
4911 /gnu/store/@dots{}-make-4.1.tar.xz.drv
4912 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
4913@dots{}
4914@end example
4915
4916@end table
4917
c78bd12b
LC
4918@item --system=@var{system}
4919@itemx -s @var{system}
4920Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
f97c9175 4921the system type of the build host.
c78bd12b
LC
4922
4923An example use of this is on Linux-based systems, which can emulate
4924different personalities. For instance, passing
4925@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
4926to build packages in a complete 32-bit environment.
4927
e55ec43d
LC
4928@item --target=@var{triplet}
4929@cindex cross-compilation
4930Cross-build for @var{triplet}, which must be a valid GNU triplet, such
4931as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
4932configuration triplets,, configure, GNU Configure and Build System}).
4933
a8d65643
LC
4934@anchor{build-check}
4935@item --check
4936@cindex determinism, checking
4937@cindex reproducibility, checking
4938Rebuild @var{package-or-derivation}, which are already available in the
4939store, and raise an error if the build results are not bit-for-bit
4940identical.
4941
f97c9175
AE
4942This mechanism allows you to check whether previously installed
4943substitutes are genuine (@pxref{Substitutes}), or whether the build result
4944of a package is deterministic. @xref{Invoking guix challenge}, for more
a8d65643
LC
4945background information and tools.
4946
7f3b2510
ED
4947When used in conjunction with @option{--keep-failed}, the differing
4948output is kept in the store, under @file{/gnu/store/@dots{}-check}.
4949This makes it easy to look for differences between the two results.
4950
6da5bb7b
LC
4951@item --repair
4952@cindex repairing store items
4953@cindex corruption, recovering from
4954Attempt to repair the specified store items, if they are corrupt, by
4955re-downloading or rebuilding them.
4956
4957This operation is not atomic and thus restricted to @code{root}.
4958
c78bd12b
LC
4959@item --derivations
4960@itemx -d
4961Return the derivation paths, not the output paths, of the given
4962packages.
4963
70ee5642
LC
4964@item --root=@var{file}
4965@itemx -r @var{file}
4966Make @var{file} a symlink to the result, and register it as a garbage
4967collector root.
4968
4969@item --log-file
3f208ad7 4970Return the build log file names or URLs for the given
f97c9175 4971@var{package-or-derivation}, or raise an error if build logs are
70ee5642
LC
4972missing.
4973
4974This works regardless of how packages or derivations are specified. For
4975instance, the following invocations are equivalent:
4976
4977@example
4978guix build --log-file `guix build -d guile`
4979guix build --log-file `guix build guile`
4980guix build --log-file guile
4981guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
4982@end example
4983
3f208ad7
LC
4984If a log is unavailable locally, and unless @code{--no-substitutes} is
4985passed, the command looks for a corresponding log on one of the
4986substitute servers (as specified with @code{--substitute-urls}.)
70ee5642 4987
f97c9175
AE
4988So for instance, imagine you want to see the build log of GDB on MIPS,
4989but you are actually on an @code{x86_64} machine:
3f208ad7
LC
4990
4991@example
a01ad638 4992$ guix build --log-file gdb -s mips64el-linux
df061d07 4993https://hydra.gnu.org/log/@dots{}-gdb-7.10
3f208ad7
LC
4994@end example
4995
4996You can freely access a huge library of build logs!
70ee5642
LC
4997@end table
4998
16eb115e 4999
39bee8a2
LC
5000@node Invoking guix edit
5001@section Invoking @command{guix edit}
5002
e32171ee 5003@cindex @command{guix edit}
39bee8a2
LC
5004@cindex package definition, editing
5005So many packages, so many source files! The @command{guix edit} command
424a323e
GC
5006facilitates the life of users and packagers by pointing their editor at
5007the source file containing the definition of the specified packages.
5008For instance:
39bee8a2
LC
5009
5010@example
7b9a66e5 5011guix edit gcc@@4.9 vim
39bee8a2
LC
5012@end example
5013
5014@noindent
6237b9fa 5015launches the program specified in the @code{VISUAL} or in the
424a323e 5016@code{EDITOR} environment variable to view the recipe of GCC@tie{}4.9.3
6237b9fa 5017and that of Vim.
39bee8a2 5018
424a323e
GC
5019If you are using a Guix Git checkout (@pxref{Building from Git}), or
5020have created your own packages on @code{GUIX_PACKAGE_PATH}
5021(@pxref{Defining Packages}), you will be able to edit the package
5022recipes. Otherwise, you will be able to examine the read-only recipes
5023for packages currently in the store.
5024
39bee8a2 5025
210cc920
LC
5026@node Invoking guix download
5027@section Invoking @command{guix download}
5028
e32171ee
JD
5029@cindex @command{guix download}
5030@cindex downloading package sources
210cc920 5031When writing a package definition, developers typically need to download
f97c9175 5032a source tarball, compute its SHA256 hash, and write that
210cc920
LC
5033hash in the package definition (@pxref{Defining Packages}). The
5034@command{guix download} tool helps with this task: it downloads a file
5035from the given URI, adds it to the store, and prints both its file name
5036in the store and its SHA256 hash.
5037
5038The fact that the downloaded file is added to the store saves bandwidth:
5039when the developer eventually tries to build the newly defined package
5040with @command{guix build}, the source tarball will not have to be
5041downloaded again because it is already in the store. It is also a
5042convenient way to temporarily stash files, which may be deleted
5043eventually (@pxref{Invoking guix gc}).
5044
5045The @command{guix download} command supports the same URIs as used in
5046package definitions. In particular, it supports @code{mirror://} URIs.
5047@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
5048Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
5049they are not available, an error is raised. @xref{Guile Preparations,
5050how to install the GnuTLS bindings for Guile,, gnutls-guile,
5051GnuTLS-Guile}, for more information.
210cc920 5052
bc3c41ce
LC
5053@command{guix download} verifies HTTPS server certificates by loading
5054the certificates of X.509 authorities from the directory pointed to by
5055the @code{SSL_CERT_DIR} environment variable (@pxref{X.509
64b8695c 5056Certificates}), unless @option{--no-check-certificate} is used.
bc3c41ce 5057
64b8695c 5058The following options are available:
210cc920
LC
5059
5060@table @code
5061@item --format=@var{fmt}
5062@itemx -f @var{fmt}
5063Write the hash in the format specified by @var{fmt}. For more
081145cf 5064information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
64b8695c
LC
5065
5066@item --no-check-certificate
5067Do not validate the X.509 certificates of HTTPS servers.
5068
5069When using this option, you have @emph{absolutely no guarantee} that you
5070are communicating with the authentic server responsible for the given
5071URL, which makes you vulnerable to ``man-in-the-middle'' attacks.
5072
1bcc87bb
LC
5073@item --output=@var{file}
5074@itemx -o @var{file}
5075Save the downloaded file to @var{file} instead of adding it to the
5076store.
210cc920
LC
5077@end table
5078
6c365eca
NK
5079@node Invoking guix hash
5080@section Invoking @command{guix hash}
5081
e32171ee 5082@cindex @command{guix hash}
210cc920 5083The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
5084It is primarily a convenience tool for anyone contributing to the
5085distribution: it computes the cryptographic hash of a file, which can be
5086used in the definition of a package (@pxref{Defining Packages}).
5087
5088The general syntax is:
5089
5090@example
5091guix hash @var{option} @var{file}
5092@end example
5093
343dc117
LC
5094When @var{file} is @code{-} (a hyphen), @command{guix hash} computes the
5095hash of data read from standard input. @command{guix hash} has the
5096following options:
6c365eca
NK
5097
5098@table @code
5099
5100@item --format=@var{fmt}
5101@itemx -f @var{fmt}
210cc920 5102Write the hash in the format specified by @var{fmt}.
6c365eca
NK
5103
5104Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
5105(@code{hex} and @code{hexadecimal} can be used as well).
5106
5107If the @option{--format} option is not specified, @command{guix hash}
5108will output the hash in @code{nix-base32}. This representation is used
5109in the definitions of packages.
5110
3140f2df
LC
5111@item --recursive
5112@itemx -r
5113Compute the hash on @var{file} recursively.
5114
5115In this case, the hash is computed on an archive containing @var{file},
f97c9175
AE
5116including its children if it is a directory. Some of the metadata of
5117@var{file} is part of the archive; for instance, when @var{file} is a
3140f2df 5118regular file, the hash is different depending on whether @var{file} is
f97c9175 5119executable or not. Metadata such as time stamps has no impact on the
3140f2df
LC
5120hash (@pxref{Invoking guix archive}).
5121@c FIXME: Replace xref above with xref to an ``Archive'' section when
5122@c it exists.
5123
392a4e12
JN
5124@item --exclude-vcs
5125@itemx -x
5126When combined with @option{--recursive}, exclude version control system
5127directories (@file{.bzr}, @file{.git}, @file{.hg}, etc.)
5128
db97a03a
LC
5129@vindex git-fetch
5130As an example, here is how you would compute the hash of a Git checkout,
5131which is useful when using the @code{git-fetch} method (@pxref{origin
5132Reference}):
5133
5134@example
5135$ git clone http://example.org/foo.git
5136$ cd foo
392a4e12 5137$ guix hash -rx .
db97a03a 5138@end example
6c365eca
NK
5139@end table
5140
2f7d2d91
LC
5141@node Invoking guix import
5142@section Invoking @command{guix import}
5143
5144@cindex importing packages
5145@cindex package import
5146@cindex package conversion
e32171ee 5147@cindex Invoking @command{guix import}
f97c9175
AE
5148The @command{guix import} command is useful for people who would like to
5149add a package to the distribution with as little work as
5150possible---a legitimate demand. The command knows of a few
5151repositories from which it can ``import'' package metadata. The result
2f7d2d91
LC
5152is a package definition, or a template thereof, in the format we know
5153(@pxref{Defining Packages}).
5154
5155The general syntax is:
5156
5157@example
5158guix import @var{importer} @var{options}@dots{}
5159@end example
5160
5161@var{importer} specifies the source from which to import package
f97c9175 5162metadata, and @var{options} specifies a package identifier and other
2f7d2d91
LC
5163options specific to @var{importer}. Currently, the available
5164``importers'' are:
5165
5166@table @code
5167@item gnu
f97c9175 5168Import metadata for the given GNU package. This provides a template
2f7d2d91
LC
5169for the latest version of that GNU package, including the hash of its
5170source tarball, and its canonical synopsis and description.
5171
f97c9175 5172Additional information such as the package dependencies and its
2f7d2d91
LC
5173license needs to be figured out manually.
5174
5175For example, the following command returns a package definition for
5176GNU@tie{}Hello:
5177
5178@example
5179guix import gnu hello
5180@end example
5181
5182Specific command-line options are:
5183
5184@table @code
5185@item --key-download=@var{policy}
5186As for @code{guix refresh}, specify the policy to handle missing OpenPGP
f97c9175 5187keys when verifying the package signature. @xref{Invoking guix
2f7d2d91
LC
5188refresh, @code{--key-download}}.
5189@end table
5190
5191@item pypi
5192@cindex pypi
f97c9175 5193Import metadata from the @uref{https://pypi.python.org/, Python Package
2f7d2d91
LC
5194Index}@footnote{This functionality requires Guile-JSON to be installed.
5195@xref{Requirements}.}. Information is taken from the JSON-formatted
5196description available at @code{pypi.python.org} and usually includes all
266785d2
CR
5197the relevant information, including package dependencies. For maximum
5198efficiency, it is recommended to install the @command{unzip} utility, so
5199that the importer can unzip Python wheels and gather data from them.
2f7d2d91 5200
f97c9175 5201The command below imports metadata for the @code{itsdangerous} Python
2f7d2d91
LC
5202package:
5203
5204@example
5205guix import pypi itsdangerous
5206@end example
5207
3aae8145
DT
5208@item gem
5209@cindex gem
f97c9175 5210Import metadata from @uref{https://rubygems.org/,
3aae8145
DT
5211RubyGems}@footnote{This functionality requires Guile-JSON to be
5212installed. @xref{Requirements}.}. Information is taken from the
5213JSON-formatted description available at @code{rubygems.org} and includes
5214most relevant information, including runtime dependencies. There are
f97c9175 5215some caveats, however. The metadata doesn't distinguish between
3aae8145
DT
5216synopses and descriptions, so the same string is used for both fields.
5217Additionally, the details of non-Ruby dependencies required to build
5218native extensions is unavailable and left as an exercise to the
5219packager.
5220
f97c9175 5221The command below imports metadata for the @code{rails} Ruby package:
3aae8145
DT
5222
5223@example
5224guix import gem rails
5225@end example
5226
d45dc6da
EB
5227@item cpan
5228@cindex CPAN
3c192e4e
AE
5229Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}@footnote{This
5230functionality requires Guile-JSON to be installed.
5231@xref{Requirements}.}.
f97c9175 5232Information is taken from the JSON-formatted metadata provided through
d45dc6da 5233@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
5234relevant information, such as module dependencies. License information
5235should be checked closely. If Perl is available in the store, then the
5236@code{corelist} utility will be used to filter core modules out of the
5237list of dependencies.
d45dc6da 5238
f97c9175 5239The command command below imports metadata for the @code{Acme::Boolean}
d45dc6da
EB
5240Perl module:
5241
5242@example
5243guix import cpan Acme::Boolean
5244@end example
5245
e1248602
RW
5246@item cran
5247@cindex CRAN
d0bd632f 5248@cindex Bioconductor
f97c9175 5249Import metadata from @uref{http://cran.r-project.org/, CRAN}, the
e1248602
RW
5250central repository for the @uref{http://r-project.org, GNU@tie{}R
5251statistical and graphical environment}.
5252
f97c9175 5253Information is extracted from the @code{DESCRIPTION} file of the package.
e1248602 5254
f97c9175 5255The command command below imports metadata for the @code{Cairo}
e1248602
RW
5256R package:
5257
5258@example
5259guix import cran Cairo
5260@end example
5261
64ce53eb
RW
5262When @code{--recursive} is added, the importer will traverse the
5263dependency graph of the given upstream package recursively and generate
5264package expressions for all those packages that are not yet in Guix.
5265
f97c9175 5266When @code{--archive=bioconductor} is added, metadata is imported from
d0bd632f
RW
5267@uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
5268packages for for the analysis and comprehension of high-throughput
5269genomic data in bioinformatics.
5270
f97c9175 5271Information is extracted from the @code{DESCRIPTION} file of a package
d0bd632f
RW
5272published on the web interface of the Bioconductor SVN repository.
5273
f97c9175 5274The command below imports metadata for the @code{GenomicRanges}
d0bd632f
RW
5275R package:
5276
5277@example
5278guix import cran --archive=bioconductor GenomicRanges
5279@end example
5280
2f7d2d91 5281@item nix
f97c9175 5282Import metadata from a local copy of the source of the
2f7d2d91
LC
5283@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
5284relies on the @command{nix-instantiate} command of
5285@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
5286typically written in a mixture of Nix-language and Bash code. This
5287command only imports the high-level package structure that is written in
5288the Nix language. It normally includes all the basic fields of a
5289package definition.
5290
5291When importing a GNU package, the synopsis and descriptions are replaced
5292by their canonical upstream variant.
5293
961d0d2d
LC
5294Usually, you will first need to do:
5295
5296@example
5297export NIX_REMOTE=daemon
5298@end example
5299
5300@noindent
5301so that @command{nix-instantiate} does not try to open the Nix database.
5302
2f7d2d91
LC
5303As an example, the command below imports the package definition of
5304LibreOffice (more precisely, it imports the definition of the package
5305bound to the @code{libreoffice} top-level attribute):
5306
5307@example
5308guix import nix ~/path/to/nixpkgs libreoffice
5309@end example
863af4e1
FB
5310
5311@item hackage
5312@cindex hackage
f97c9175 5313Import metadata from the Haskell community's central package archive
863af4e1
FB
5314@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
5315Cabal files and includes all the relevant information, including package
5316dependencies.
5317
5318Specific command-line options are:
5319
5320@table @code
a4154748
FB
5321@item --stdin
5322@itemx -s
f97c9175 5323Read a Cabal file from standard input.
863af4e1
FB
5324@item --no-test-dependencies
5325@itemx -t
f97c9175 5326Do not include dependencies required only by the test suites.
a4154748
FB
5327@item --cabal-environment=@var{alist}
5328@itemx -e @var{alist}
5329@var{alist} is a Scheme alist defining the environment in which the
5330Cabal conditionals are evaluated. The accepted keys are: @code{os},
5331@code{arch}, @code{impl} and a string representing the name of a flag.
5332The value associated with a flag has to be either the symbol
5333@code{true} or @code{false}. The value associated with other keys
5334has to conform to the Cabal file format definition. The default value
5335associated with the keys @code{os}, @code{arch} and @code{impl} is
f97c9175 5336@samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
863af4e1
FB
5337@end table
5338
f97c9175 5339The command below imports metadata for the latest version of the
a4154748
FB
5340@code{HTTP} Haskell package without including test dependencies and
5341specifying the value of the flag @samp{network-uri} as @code{false}:
863af4e1
FB
5342
5343@example
a4154748 5344guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
863af4e1
FB
5345@end example
5346
5347A specific package version may optionally be specified by following the
1b846da8 5348package name by an at-sign and a version number as in the following example:
863af4e1
FB
5349
5350@example
1b846da8 5351guix import hackage mtl@@2.1.3.1
863af4e1 5352@end example
7f74a931 5353
bc5844d1
FB
5354@item stackage
5355@cindex stackage
5356The @code{stackage} importer is a wrapper around the @code{hackage} one.
5357It takes a package name, looks up the package version included in a
5358long-term support (LTS) @uref{https://www.stackage.org, Stackage}
5359release and uses the @code{hackage} importer to retrieve its metadata.
5360Note that it is up to you to select an LTS release compatible with the
5361GHC compiler used by Guix.
5362
5363Specific command-line options are:
5364
5365@table @code
5366@item --no-test-dependencies
5367@itemx -t
5368Do not include dependencies required only by the test suites.
5369@item --lts-version=@var{version}
5370@itemx -r @var{version}
5371@var{version} is the desired LTS release version. If omitted the latest
5372release is used.
5373@end table
5374
5375The command below imports metadata for the @code{HTTP} Haskell package
5376included in the LTS Stackage release version 7.18:
5377
5378@example
5379guix import stackage --lts-version=7.18 HTTP
5380@end example
5381
7f74a931
FB
5382@item elpa
5383@cindex elpa
f97c9175 5384Import metadata from an Emacs Lisp Package Archive (ELPA) package
7f74a931
FB
5385repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
5386
5387Specific command-line options are:
5388
5389@table @code
5390@item --archive=@var{repo}
5391@itemx -a @var{repo}
5392@var{repo} identifies the archive repository from which to retrieve the
5393information. Currently the supported repositories and their identifiers
5394are:
5395@itemize -
5396@item
840bd1d3 5397@uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7f74a931
FB
5398identifier. This is the default.
5399
624144e0
LC
5400Packages from @code{elpa.gnu.org} are signed with one of the keys
5401contained in the GnuPG keyring at
5402@file{share/emacs/25.1/etc/package-keyring.gpg} (or similar) in the
5403@code{emacs} package (@pxref{Package Installation, ELPA package
5404signatures,, emacs, The GNU Emacs Manual}).
5405
7f74a931 5406@item
840bd1d3 5407@uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7f74a931
FB
5408@code{melpa-stable} identifier.
5409
5410@item
840bd1d3 5411@uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7f74a931
FB
5412identifier.
5413@end itemize
5414@end table
3e0c0365
DC
5415
5416@item crate
5417@cindex crate
5418Import metadata from the crates.io Rust package repository
5419@uref{https://crates.io, crates.io}.
2f7d2d91
LC
5420@end table
5421
5422The structure of the @command{guix import} code is modular. It would be
5423useful to have more importers for other package formats, and your help
5424is welcome here (@pxref{Contributing}).
5425
37166310
LC
5426@node Invoking guix refresh
5427@section Invoking @command{guix refresh}
5428
e32171ee 5429@cindex @command {guix refresh}
37166310
LC
5430The primary audience of the @command{guix refresh} command is developers
5431of the GNU software distribution. By default, it reports any packages
5432provided by the distribution that are outdated compared to the latest
5433upstream version, like this:
5434
5435@example
5436$ guix refresh
5437gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
5438gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
5439@end example
5440
e9c72306
LC
5441Alternately, one can specify packages to consider, in which case a
5442warning is emitted for packages that lack an updater:
5443
5444@example
5445$ guix refresh coreutils guile guile-ssh
5446gnu/packages/ssh.scm:205:2: warning: no updater for guile-ssh
5447gnu/packages/guile.scm:136:12: guile would be upgraded from 2.0.12 to 2.0.13
5448@end example
5449
5450@command{guix refresh} browses the upstream repository of each package and determines
5451the highest version number of the releases therein. The command
bcb571cb 5452knows how to update specific types of packages: GNU packages, ELPA
e9c72306 5453packages, etc.---see the documentation for @option{--type} below. There
bcb571cb
LC
5454are many packages, though, for which it lacks a method to determine
5455whether a new upstream release is available. However, the mechanism is
5456extensible, so feel free to get in touch with us to add a new method!
37166310
LC
5457
5458When passed @code{--update}, it modifies distribution source files to
f97c9175 5459update the version numbers and source tarball hashes of those package
37166310
LC
5460recipes (@pxref{Defining Packages}). This is achieved by downloading
5461each package's latest source tarball and its associated OpenPGP
5462signature, authenticating the downloaded tarball against its signature
5463using @command{gpg}, and finally computing its hash. When the public
5464key used to sign the tarball is missing from the user's keyring, an
5465attempt is made to automatically retrieve it from a public key server;
f97c9175 5466when this is successful, the key is added to the user's keyring; otherwise,
37166310
LC
5467@command{guix refresh} reports an error.
5468
5469The following options are supported:
5470
5471@table @code
5472
2d7fc7da
LC
5473@item --expression=@var{expr}
5474@itemx -e @var{expr}
5475Consider the package @var{expr} evaluates to.
5476
5477This is useful to precisely refer to a package, as in this example:
5478
5479@example
5480guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
5481@end example
5482
5483This command lists the dependents of the ``final'' libc (essentially all
5484the packages.)
5485
37166310
LC
5486@item --update
5487@itemx -u
38e16b49
LC
5488Update distribution source files (package recipes) in place. This is
5489usually run from a checkout of the Guix source tree (@pxref{Running
5490Guix Before It Is Installed}):
5491
5492@example
e9c72306 5493$ ./pre-inst-env guix refresh -s non-core -u
38e16b49
LC
5494@end example
5495
081145cf 5496@xref{Defining Packages}, for more information on package definitions.
37166310
LC
5497
5498@item --select=[@var{subset}]
5499@itemx -s @var{subset}
5500Select all the packages in @var{subset}, one of @code{core} or
5501@code{non-core}.
5502
5503The @code{core} subset refers to all the packages at the core of the
5504distribution---i.e., packages that are used to build ``everything
5505else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
5506changing one of these packages in the distribution entails a rebuild of
5507all the others. Thus, such updates are an inconvenience to users in
5508terms of build time or bandwidth used to achieve the upgrade.
5509
5510The @code{non-core} subset refers to the remaining packages. It is
5511typically useful in cases where an update of the core packages would be
5512inconvenient.
5513
bcb571cb
LC
5514@item --type=@var{updater}
5515@itemx -t @var{updater}
7191adc5
AK
5516Select only packages handled by @var{updater} (may be a comma-separated
5517list of updaters). Currently, @var{updater} may be one of:
bcb571cb
LC
5518
5519@table @code
5520@item gnu
5521the updater for GNU packages;
e80c0f85
LC
5522@item gnome
5523the updater for GNOME packages;
9c97afe8
DC
5524@item kde
5525the updater for KDE packages;
62061d6b
AW
5526@item xorg
5527the updater for X.org packages;
2fd370e8
LC
5528@item kernel.org
5529the updater for packages hosted on kernel.org;
bcb571cb 5530@item elpa
d882c235
LC
5531the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
5532@item cran
b9d044ef 5533the updater for @uref{http://cran.r-project.org/, CRAN} packages;
d0bd632f
RW
5534@item bioconductor
5535the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
200cdf81
EB
5536@item cpan
5537the updater for @uref{http://www.cpan.org/, CPAN} packages;
bab020d7 5538@item pypi
b9d044ef 5539the updater for @uref{https://pypi.python.org, PyPI} packages.
fbc5b815
BW
5540@item gem
5541the updater for @uref{https://rubygems.org, RubyGems} packages.
917a2a58
BW
5542@item github
5543the updater for @uref{https://github.com, GitHub} packages.
42efe27a
EB
5544@item hackage
5545the updater for @uref{https://hackage.haskell.org, Hackage} packages.
bc5844d1
FB
5546@item stackage
5547the updater for @uref{https://www.stackage.org, Stackage} packages.
8ac52987
DC
5548@item crate
5549the updater for @uref{https://crates.io, Crates} packages.
bcb571cb
LC
5550@end table
5551
f97c9175
AE
5552For instance, the following command only checks for updates of Emacs
5553packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
bcb571cb
LC
5554
5555@example
7191adc5 5556$ guix refresh --type=elpa,cran
d882c235 5557gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
bcb571cb
LC
5558gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
5559@end example
5560
37166310
LC
5561@end table
5562
5563In addition, @command{guix refresh} can be passed one or more package
5564names, as in this example:
5565
5566@example
e9c72306 5567$ ./pre-inst-env guix refresh -u emacs idutils gcc@@4.8
37166310
LC
5568@end example
5569
5570@noindent
5571The command above specifically updates the @code{emacs} and
5572@code{idutils} packages. The @code{--select} option would have no
5573effect in this case.
5574
7d193ec3
EB
5575When considering whether to upgrade a package, it is sometimes
5576convenient to know which packages would be affected by the upgrade and
5577should be checked for compatibility. For this the following option may
5578be used when passing @command{guix refresh} one or more package names:
5579
5580@table @code
5581
6ffa706b
AK
5582@item --list-updaters
5583@itemx -L
5584List available updaters and exit (see @option{--type} above.)
5585
3676f892
LC
5586For each updater, display the fraction of packages it covers; at the
5587end, display the fraction of packages covered by all these updaters.
5588
7d193ec3
EB
5589@item --list-dependent
5590@itemx -l
5591List top-level dependent packages that would need to be rebuilt as a
5592result of upgrading one or more packages.
5593
b96a0640
LC
5594@xref{Invoking guix graph, the @code{reverse-package} type of
5595@command{guix graph}}, for information on how to visualize the list of
5596dependents of a package.
5597
7d193ec3
EB
5598@end table
5599
5600Be aware that the @code{--list-dependent} option only
5601@emph{approximates} the rebuilds that would be required as a result of
5602an upgrade. More rebuilds might be required under some circumstances.
5603
5604@example
7779ab61
LC
5605$ guix refresh --list-dependent flex
5606Building the following 120 packages would ensure 213 dependent packages are rebuilt:
5607hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
5608@end example
5609
5610The command above lists a set of packages that could be built to check
5611for compatibility with an upgraded @code{flex} package.
5612
f9230085
LC
5613The following options can be used to customize GnuPG operation:
5614
5615@table @code
5616
f9230085
LC
5617@item --gpg=@var{command}
5618Use @var{command} as the GnuPG 2.x command. @var{command} is searched
5619for in @code{$PATH}.
5620
2bc53ba9
LC
5621@item --key-download=@var{policy}
5622Handle missing OpenPGP keys according to @var{policy}, which may be one
5623of:
5624
5625@table @code
5626@item always
5627Always download missing OpenPGP keys from the key server, and add them
5628to the user's GnuPG keyring.
5629
5630@item never
5631Never try to download missing OpenPGP keys. Instead just bail out.
5632
5633@item interactive
5634When a package signed with an unknown OpenPGP key is encountered, ask
5635the user whether to download it or not. This is the default behavior.
5636@end table
5637
5638@item --key-server=@var{host}
5639Use @var{host} as the OpenPGP key server when importing a public key.
5640
f9230085
LC
5641@end table
5642
917a2a58
BW
5643The @code{github} updater uses the
5644@uref{https://developer.github.com/v3/, GitHub API} to query for new
5645releases. When used repeatedly e.g. when refreshing all packages,
5646GitHub will eventually refuse to answer any further API requests. By
5647default 60 API requests per hour are allowed, and a full refresh on all
5648GitHub packages in Guix requires more than this. Authentication with
5649GitHub through the use of an API token alleviates these limits. To use
5650an API token, set the environment variable @code{GUIX_GITHUB_TOKEN} to a
5651token procured from @uref{https://github.com/settings/tokens} or
5652otherwise.
5653
5654
b4f5e0e8
CR
5655@node Invoking guix lint
5656@section Invoking @command{guix lint}
e32171ee
JD
5657
5658@cindex @command{guix lint}
5659@cindex package, checking for errors
f97c9175
AE
5660The @command{guix lint} command is meant to help package developers avoid
5661common errors and use a consistent style. It runs a number of checks on
5662a given set of packages in order to find common mistakes in their
873c4085
LC
5663definitions. Available @dfn{checkers} include (see
5664@code{--list-checkers} for a complete list):
5665
5666@table @code
5667@item synopsis
5668@itemx description
5669Validate certain typographical and stylistic rules about package
5670descriptions and synopses.
5671
5672@item inputs-should-be-native
5673Identify inputs that should most likely be native inputs.
5674
5675@item source
5676@itemx home-page
fac46e3f 5677@itemx mirror-url
50f5c46d 5678@itemx source-file-name
873c4085 5679Probe @code{home-page} and @code{source} URLs and report those that are
fac46e3f
LC
5680invalid. Suggest a @code{mirror://} URL when applicable. Check that
5681the source file name is meaningful, e.g. is not
f97c9175
AE
5682just a version number or ``git-checkout'', without a declared
5683@code{file-name} (@pxref{origin Reference}).
40a7d4e5 5684
5432734b 5685@item cve
09866b39
LC
5686@cindex security vulnerabilities
5687@cindex CVE, Common Vulnerabilities and Exposures
5432734b 5688Report known vulnerabilities found in the Common Vulnerabilities and
09866b39 5689Exposures (CVE) databases of the current and past year
5432734b
LC
5690@uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
5691NIST}.
5692
09866b39
LC
5693To view information about a particular vulnerability, visit pages such as:
5694
5695@itemize
5696@item
5697@indicateurl{https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-YYYY-ABCD}
5698@item
5699@indicateurl{https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-YYYY-ABCD}
5700@end itemize
5701
5702@noindent
5703where @code{CVE-YYYY-ABCD} is the CVE identifier---e.g.,
5704@code{CVE-2015-7554}.
5705
99effc8f
LC
5706Package developers can specify in package recipes the
5707@uref{https://nvd.nist.gov/cpe.cfm,Common Platform Enumeration (CPE)}
5708name and version of the package when they differ from the name that Guix
5709uses, as in this example:
5710
5711@example
5712(package
5713 (name "grub")
5714 ;; @dots{}
5715 ;; CPE calls this package "grub2".
5716 (properties '((cpe-name . "grub2"))))
5717@end example
5718
40a7d4e5
LC
5719@item formatting
5720Warn about obvious source code formatting issues: trailing white space,
5721use of tabulations, etc.
873c4085 5722@end table
b4f5e0e8
CR
5723
5724The general syntax is:
5725
5726@example
5727guix lint @var{options} @var{package}@dots{}
5728@end example
5729
5730If no package is given on the command line, then all packages are checked.
5731The @var{options} may be zero or more of the following:
5732
5733@table @code
f97c9175
AE
5734@item --list-checkers
5735@itemx -l
5736List and describe all the available checkers that will be run on packages
5737and exit.
b4f5e0e8 5738
dd7c013d
CR
5739@item --checkers
5740@itemx -c
5741Only enable the checkers specified in a comma-separated list using the
5742names returned by @code{--list-checkers}.
5743
b4f5e0e8 5744@end table
37166310 5745
fcc58db6
LC
5746@node Invoking guix size
5747@section Invoking @command{guix size}
5748
e32171ee
JD
5749@cindex size
5750@cindex package size
5751@cindex closure
5752@cindex @command{guix size}
fcc58db6
LC
5753The @command{guix size} command helps package developers profile the
5754disk usage of packages. It is easy to overlook the impact of an
5755additional dependency added to a package, or the impact of using a
5756single output for a package that could easily be split (@pxref{Packages
f97c9175 5757with Multiple Outputs}). Such are the typical issues that
fcc58db6
LC
5758@command{guix size} can highlight.
5759
e1a65ae5 5760The command can be passed a package specification such as @code{gcc@@4.8}
fcc58db6
LC
5761or @code{guile:debug}, or a file name in the store. Consider this
5762example:
5763
5764@example
5765$ guix size coreutils
5766store item total self
5767/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
5768/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
5769/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
5770/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
5771/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
5772/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
5773@end example
5774
5775@cindex closure
5776The store items listed here constitute the @dfn{transitive closure} of
5777Coreutils---i.e., Coreutils and all its dependencies, recursively---as
5778would be returned by:
5779
5780@example
5781$ guix gc -R /gnu/store/@dots{}-coreutils-8.23
5782@end example
5783
f97c9175 5784Here the output shows three columns next to store items. The first column,
fcc58db6
LC
5785labeled ``total'', shows the size in mebibytes (MiB) of the closure of
5786the store item---that is, its own size plus the size of all its
5787dependencies. The next column, labeled ``self'', shows the size of the
f97c9175
AE
5788item itself. The last column shows the ratio of the size of the item
5789itself to the space occupied by all the items listed here.
fcc58db6
LC
5790
5791In this example, we see that the closure of Coreutils weighs in at
579270@tie{}MiB, half of which is taken by libc. (That libc represents a
5793large fraction of the closure is not a problem @i{per se} because it is
5794always available on the system anyway.)
5795
5796When the package passed to @command{guix size} is available in the
5797store, @command{guix size} queries the daemon to determine its
5798dependencies, and measures its size in the store, similar to @command{du
5799-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
5800Coreutils}).
5801
5802When the given package is @emph{not} in the store, @command{guix size}
f97c9175
AE
5803reports information based on the available substitutes
5804(@pxref{Substitutes}). This makes it possible it to profile disk usage of
5805store items that are not even on disk, only available remotely.
fcc58db6 5806
db761534
LC
5807You can also specify several package names:
5808
5809@example
5810$ guix size coreutils grep sed bash
5811store item total self
5812/gnu/store/@dots{}-coreutils-8.24 77.8 13.8 13.4%
5813/gnu/store/@dots{}-grep-2.22 73.1 0.8 0.8%
5814/gnu/store/@dots{}-bash-4.3.42 72.3 4.7 4.6%
5815/gnu/store/@dots{}-readline-6.3 67.6 1.2 1.2%
5816@dots{}
5817total: 102.3 MiB
5818@end example
5819
5820@noindent
5821In this example we see that the combination of the four packages takes
5822102.3@tie{}MiB in total, which is much less than the sum of each closure
5823since they have a lot of dependencies in common.
5824
a8f996c6 5825The available options are:
fcc58db6
LC
5826
5827@table @option
5828
d490d06e
LC
5829@item --substitute-urls=@var{urls}
5830Use substitute information from @var{urls}.
5831@xref{client-substitute-urls, the same option for @code{guix build}}.
5832
a8f996c6 5833@item --map-file=@var{file}
f97c9175 5834Write a graphical map of disk usage in PNG format to @var{file}.
a8f996c6
LC
5835
5836For the example above, the map looks like this:
5837
5838@image{images/coreutils-size-map,5in,, map of Coreutils disk usage
5839produced by @command{guix size}}
5840
5841This option requires that
5842@uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
5843installed and visible in Guile's module search path. When that is not
5844the case, @command{guix size} fails as it tries to load it.
5845
fcc58db6
LC
5846@item --system=@var{system}
5847@itemx -s @var{system}
5848Consider packages for @var{system}---e.g., @code{x86_64-linux}.
5849
5850@end table
5851
88856916
LC
5852@node Invoking guix graph
5853@section Invoking @command{guix graph}
5854
5855@cindex DAG
e32171ee
JD
5856@cindex @command{guix graph}
5857@cindex package dependencies
88856916
LC
5858Packages and their dependencies form a @dfn{graph}, specifically a
5859directed acyclic graph (DAG). It can quickly become difficult to have a
f97c9175 5860mental model of the package DAG, so the @command{guix graph} command
9ea36197
LC
5861provides a visual representation of the DAG. By default,
5862@command{guix graph} emits a DAG representation in the input format of
88856916 5863@uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
9ea36197
LC
5864directly to the @command{dot} command of Graphviz. It can also emit an
5865HTML page with embedded JavaScript code to display a ``chord diagram''
5866in a Web browser, using the @uref{https://d3js.org/, d3.js} library.
5867The general syntax is:
88856916
LC
5868
5869@example
5870guix graph @var{options} @var{package}@dots{}
5871@end example
5872
5873For example, the following command generates a PDF file representing the
5874package DAG for the GNU@tie{}Core Utilities, showing its build-time
5875dependencies:
5876
5877@example
5878guix graph coreutils | dot -Tpdf > dag.pdf
5879@end example
5880
5881The output looks like this:
5882
5883@image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
5884
5885Nice little graph, no?
5886
f97c9175 5887But there is more than one graph! The one above is concise: it is the
88856916 5888graph of package objects, omitting implicit inputs such as GCC, libc,
f97c9175
AE
5889grep, etc. It is often useful to have such a concise graph, but
5890sometimes one may want to see more details. @command{guix graph} supports
5891several types of graphs, allowing you to choose the level of detail:
88856916
LC
5892
5893@table @code
5894@item package
f97c9175 5895This is the default type used in the example above. It shows the DAG of
88856916
LC
5896package objects, excluding implicit dependencies. It is concise, but
5897filters out many details.
5898
b96a0640
LC
5899@item reverse-package
5900This shows the @emph{reverse} DAG of packages. For example:
5901
5902@example
5903guix graph --type=reverse-package ocaml
5904@end example
5905
5906... yields the graph of packages that depend on OCaml.
5907
5908Note that for core packages this can yield huge graphs. If all you want
5909is to know the number of packages that depend on a given package, use
5910@command{guix refresh --list-dependent} (@pxref{Invoking guix refresh,
5911@option{--list-dependent}}).
5912
88856916
LC
5913@item bag-emerged
5914This is the package DAG, @emph{including} implicit inputs.
5915
5916For instance, the following command:
5917
5918@example
5919guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
5920@end example
5921
5922... yields this bigger graph:
5923
5924@image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
5925
5926At the bottom of the graph, we see all the implicit inputs of
5927@var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
5928
f97c9175 5929Now, note that the dependencies of these implicit inputs---that is, the
88856916
LC
5930@dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
5931here, for conciseness.
5932
5933@item bag
5934Similar to @code{bag-emerged}, but this time including all the bootstrap
5935dependencies.
5936
38b92daa
LC
5937@item bag-with-origins
5938Similar to @code{bag}, but also showing origins and their dependencies.
5939
88856916
LC
5940@item derivations
5941This is the most detailed representation: It shows the DAG of
5942derivations (@pxref{Derivations}) and plain store items. Compared to
5943the above representation, many additional nodes are visible, including
f97c9175 5944build scripts, patches, Guile modules, etc.
88856916 5945
a773c314
LC
5946For this type of graph, it is also possible to pass a @file{.drv} file
5947name instead of a package name, as in:
5948
5949@example
5950guix graph -t derivation `guix system build -d my-config.scm`
5951@end example
88856916
LC
5952@end table
5953
f97c9175 5954All the types above correspond to @emph{build-time dependencies}. The
88856916
LC
5955following graph type represents the @emph{run-time dependencies}:
5956
5957@table @code
5958@item references
5959This is the graph of @dfn{references} of a package output, as returned
5960by @command{guix gc --references} (@pxref{Invoking guix gc}).
5961
5962If the given package output is not available in the store, @command{guix
5963graph} attempts to obtain dependency information from substitutes.
a773c314
LC
5964
5965Here you can also pass a store file name instead of a package name. For
5966example, the command below produces the reference graph of your profile
5967(which can be big!):
5968
5969@example
5970guix graph -t references `readlink -f ~/.guix-profile`
5971@end example
7f8fec0f
LC
5972
5973@item referrers
5974This is the graph of the @dfn{referrers} of a store item, as returned by
5975@command{guix gc --referrers} (@pxref{Invoking guix gc}).
5976
5977This relies exclusively on local information from your store. For
5978instance, let us suppose that the current Inkscape is available in 10
5979profiles on your machine; @command{guix graph -t referrers inkscape}
5980will show a graph rooted at Inkscape and with those 10 profiles linked
5981to it.
5982
5983It can help determine what is preventing a store item from being garbage
5984collected.
5985
88856916
LC
5986@end table
5987
5988The available options are the following:
5989
5990@table @option
5991@item --type=@var{type}
5992@itemx -t @var{type}
5993Produce a graph output of @var{type}, where @var{type} must be one of
5994the values listed above.
5995
5996@item --list-types
5997List the supported graph types.
4c8f997a 5998
642339dc
RW
5999@item --backend=@var{backend}
6000@itemx -b @var{backend}
6001Produce a graph using the selected @var{backend}.
6002
6003@item --list-backends
6004List the supported graph backends.
6005
9ea36197
LC
6006Currently, the available backends are Graphviz and d3.js.
6007
4c8f997a
LC
6008@item --expression=@var{expr}
6009@itemx -e @var{expr}
6010Consider the package @var{expr} evaluates to.
6011
6012This is useful to precisely refer to a package, as in this example:
6013
6014@example
6015guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
6016@end example
88856916
LC
6017@end table
6018
6019
372c4bbc
DT
6020@node Invoking guix environment
6021@section Invoking @command{guix environment}
6022
f5fd4fd2 6023@cindex reproducible build environments
fe36d84e 6024@cindex development environments
e32171ee
JD
6025@cindex @command{guix environment}
6026@cindex environment, package build environment
372c4bbc
DT
6027The purpose of @command{guix environment} is to assist hackers in
6028creating reproducible development environments without polluting their
6029package profile. The @command{guix environment} tool takes one or more
f97c9175 6030packages, builds all of their inputs, and creates a shell
372c4bbc
DT
6031environment to use them.
6032
6033The general syntax is:
6034
6035@example
6036guix environment @var{options} @var{package}@dots{}
6037@end example
6038
fe36d84e
LC
6039The following example spawns a new shell set up for the development of
6040GNU@tie{}Guile:
372c4bbc
DT
6041
6042@example
6043guix environment guile
6044@end example
6045
f97c9175
AE
6046If the needed dependencies are not built yet, @command{guix environment}
6047automatically builds them. The environment of the new shell is an augmented
372c4bbc
DT
6048version of the environment that @command{guix environment} was run in.
6049It contains the necessary search paths for building the given package
6050added to the existing environment variables. To create a ``pure''
f97c9175 6051environment, in which the original environment variables have been unset,
50500f7c
LC
6052use the @code{--pure} option@footnote{Users sometimes wrongfully augment
6053environment variables such as @code{PATH} in their @file{~/.bashrc}
6054file. As a consequence, when @code{guix environment} launches it, Bash
6055may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
6056environment variables. It is an error to define such environment
6057variables in @file{.bashrc}; instead, they should be defined in
6058@file{.bash_profile}, which is sourced only by log-in shells.
6059@xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
6060details on Bash start-up files.}.
372c4bbc 6061
28de8d25
LC
6062@vindex GUIX_ENVIRONMENT
6063@command{guix environment} defines the @code{GUIX_ENVIRONMENT}
20185522
LC
6064variable in the shell it spawns; its value is the file name of the
6065profile of this environment. This allows users to, say, define a
28de8d25
LC
6066specific prompt for development environments in their @file{.bashrc}
6067(@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
6068
6069@example
6070if [ -n "$GUIX_ENVIRONMENT" ]
6071then
6072 export PS1="\u@@\h \w [dev]\$ "
6073fi
6074@end example
6075
20185522
LC
6076@noindent
6077... or to browse the profile:
6078
6079@example
6080$ ls "$GUIX_ENVIRONMENT/bin"
6081@end example
6082
372c4bbc
DT
6083Additionally, more than one package may be specified, in which case the
6084union of the inputs for the given packages are used. For example, the
6085command below spawns a shell where all of the dependencies of both Guile
6086and Emacs are available:
6087
6088@example
6089guix environment guile emacs
6090@end example
6091
1de2fe95
DT
6092Sometimes an interactive shell session is not desired. An arbitrary
6093command may be invoked by placing the @code{--} token to separate the
6094command from the rest of the arguments:
372c4bbc
DT
6095
6096@example
1de2fe95 6097guix environment guile -- make -j4
372c4bbc
DT
6098@end example
6099
fe36d84e
LC
6100In other situations, it is more convenient to specify the list of
6101packages needed in the environment. For example, the following command
6102runs @command{python} from an environment containing Python@tie{}2.7 and
6103NumPy:
6104
6105@example
1de2fe95 6106guix environment --ad-hoc python2-numpy python-2.7 -- python
fe36d84e
LC
6107@end example
6108
cc90fbbf
DT
6109Furthermore, one might want the dependencies of a package and also some
6110additional packages that are not build-time or runtime dependencies, but
6111are useful when developing nonetheless. Because of this, the
6112@code{--ad-hoc} flag is positional. Packages appearing before
6113@code{--ad-hoc} are interpreted as packages whose dependencies will be
6114added to the environment. Packages appearing after are interpreted as
6115packages that will be added to the environment directly. For example,
6116the following command creates a Guix development environment that
6117additionally includes Git and strace:
6118
6119@example
6120guix environment guix --ad-hoc git strace
6121@end example
6122
f535dcbe
DT
6123Sometimes it is desirable to isolate the environment as much as
6124possible, for maximal purity and reproducibility. In particular, when
6125using Guix on a host distro that is not GuixSD, it is desirable to
6126prevent access to @file{/usr/bin} and other system-wide resources from
6127the development environment. For example, the following command spawns
6128a Guile REPL in a ``container'' where only the store and the current
6129working directory are mounted:
6130
6131@example
6132guix environment --ad-hoc --container guile -- guile
6133@end example
6134
0f252e26 6135@quotation Note
cfd35b4e 6136The @code{--container} option requires Linux-libre 3.19 or newer.
0f252e26
DT
6137@end quotation
6138
fe36d84e 6139The available options are summarized below.
372c4bbc
DT
6140
6141@table @code
f943c317
LC
6142@item --root=@var{file}
6143@itemx -r @var{file}
6144@cindex persistent environment
6145@cindex garbage collector root, for environments
6146Make @var{file} a symlink to the profile for this environment, and
6147register it as a garbage collector root.
6148
6149This is useful if you want to protect your environment from garbage
6150collection, to make it ``persistent''.
6151
6152When this option is omitted, the environment is protected from garbage
6153collection only for the duration of the @command{guix environment}
6154session. This means that next time you recreate the same environment,
6155you could have to rebuild or re-download packages.
6156
372c4bbc
DT
6157@item --expression=@var{expr}
6158@itemx -e @var{expr}
c9c282ce
DT
6159Create an environment for the package or list of packages that
6160@var{expr} evaluates to.
372c4bbc 6161
fe36d84e
LC
6162For example, running:
6163
6164@example
6165guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
6166@end example
6167
6168starts a shell with the environment for this specific variant of the
6169PETSc package.
6170
c9c282ce
DT
6171Running:
6172
6173@example
5c2b2f00 6174guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
c9c282ce
DT
6175@end example
6176
6177starts a shell with all the GuixSD base packages available.
6178
fa445d64 6179The above commands only use the default output of the given packages.
779aa003
DT
6180To select other outputs, two element tuples can be specified:
6181
6182@example
6183guix environment --ad-hoc -e '(list (@ (gnu packages bash) bash) "include")'
6184@end example
6185
372c4bbc
DT
6186@item --load=@var{file}
6187@itemx -l @var{file}
c9c282ce
DT
6188Create an environment for the package or list of packages that the code
6189within @var{file} evaluates to.
372c4bbc 6190
fe36d84e
LC
6191As an example, @var{file} might contain a definition like this
6192(@pxref{Defining Packages}):
6193
6194@example
6195@verbatiminclude environment-gdb.scm
6196@end example
6197
a54bd6d7
DT
6198@item --ad-hoc
6199Include all specified packages in the resulting environment, as if an
6200@i{ad hoc} package were defined with them as inputs. This option is
6201useful for quickly creating an environment without having to write a
6202package expression to contain the desired inputs.
6203
6204For instance, the command:
6205
6206@example
1de2fe95 6207guix environment --ad-hoc guile guile-sdl -- guile
a54bd6d7
DT
6208@end example
6209
6210runs @command{guile} in an environment where Guile and Guile-SDL are
6211available.
6212
417c39f1 6213Note that this example implicitly asks for the default output of
f97c9175 6214@code{guile} and @code{guile-sdl}, but it is possible to ask for a
417c39f1
LC
6215specific output---e.g., @code{glib:bin} asks for the @code{bin} output
6216of @code{glib} (@pxref{Packages with Multiple Outputs}).
6217
cc90fbbf
DT
6218This option may be composed with the default behavior of @command{guix
6219environment}. Packages appearing before @code{--ad-hoc} are interpreted
6220as packages whose dependencies will be added to the environment, the
6221default behavior. Packages appearing after are interpreted as packages
6222that will be added to the environment directly.
6223
372c4bbc
DT
6224@item --pure
6225Unset existing environment variables when building the new environment.
6226This has the effect of creating an environment in which search paths
6227only contain package inputs.
6228
6229@item --search-paths
6230Display the environment variable definitions that make up the
6231environment.
ce367ef3
LC
6232
6233@item --system=@var{system}
6234@itemx -s @var{system}
6235Attempt to build for @var{system}---e.g., @code{i686-linux}.
f535dcbe
DT
6236
6237@item --container
6238@itemx -C
6239@cindex container
6240Run @var{command} within an isolated container. The current working
a01ad638
DT
6241directory outside the container is mapped inside the container.
6242Additionally, a dummy home directory is created that matches the current
6243user's home directory, and @file{/etc/passwd} is configured accordingly.
6244The spawned process runs as the current user outside the container, but
6245has root privileges in the context of the container.
f535dcbe
DT
6246
6247@item --network
6248@itemx -N
6249For containers, share the network namespace with the host system.
6250Containers created without this flag only have access to the loopback
6251device.
6252
6253@item --expose=@var{source}[=@var{target}]
6254For containers, expose the file system @var{source} from the host system
6255as the read-only file system @var{target} within the container. If
6256@var{target} is not specified, @var{source} is used as the target mount
6257point in the container.
6258
6259The example below spawns a Guile REPL in a container in which the user's
6260home directory is accessible read-only via the @file{/exchange}
6261directory:
6262
6263@example
6264guix environment --container --expose=$HOME=/exchange guile -- guile
6265@end example
6266
5c2b2f00 6267@item --share=@var{source}[=@var{target}]
f535dcbe
DT
6268For containers, share the file system @var{source} from the host system
6269as the writable file system @var{target} within the container. If
6270@var{target} is not specified, @var{source} is used as the target mount
6271point in the container.
6272
6273The example below spawns a Guile REPL in a container in which the user's
6274home directory is accessible for both reading and writing via the
6275@file{/exchange} directory:
6276
6277@example
6278guix environment --container --share=$HOME=/exchange guile -- guile
6279@end example
372c4bbc
DT
6280@end table
6281
6282It also supports all of the common build options that @command{guix
ccd7158d 6283build} supports (@pxref{Common Build Options}).
372c4bbc 6284
aff8ce7c
DT
6285@node Invoking guix publish
6286@section Invoking @command{guix publish}
6287
e32171ee 6288@cindex @command{guix publish}
aff8ce7c 6289The purpose of @command{guix publish} is to enable users to easily share
f97c9175 6290their store with others, who can then use it as a substitute server
8ce229fc
LC
6291(@pxref{Substitutes}).
6292
6293When @command{guix publish} runs, it spawns an HTTP server which allows
6294anyone with network access to obtain substitutes from it. This means
6295that any machine running Guix can also act as if it were a build farm,
6296since the HTTP interface is compatible with Hydra, the software behind
6297the @code{hydra.gnu.org} build farm.
aff8ce7c
DT
6298
6299For security, each substitute is signed, allowing recipients to check
6300their authenticity and integrity (@pxref{Substitutes}). Because
f97c9175 6301@command{guix publish} uses the signing key of the system, which is only
5463fe51
LC
6302readable by the system administrator, it must be started as root; the
6303@code{--user} option makes it drop root privileges early on.
aff8ce7c 6304
b18812b6
LC
6305The signing key pair must be generated before @command{guix publish} is
6306launched, using @command{guix archive --generate-key} (@pxref{Invoking
6307guix archive}).
6308
aff8ce7c
DT
6309The general syntax is:
6310
6311@example
6312guix publish @var{options}@dots{}
6313@end example
6314
6315Running @command{guix publish} without any additional arguments will
6316spawn an HTTP server on port 8080:
6317
6318@example
6319guix publish
6320@end example
6321
6322Once a publishing server has been authorized (@pxref{Invoking guix
6323archive}), the daemon may download substitutes from it:
6324
6325@example
6326guix-daemon --substitute-urls=http://example.org:8080
6327@end example
6328
ff6638d1
LC
6329As a bonus, @command{guix publish} also serves as a content-addressed
6330mirror for source files referenced in @code{origin} records
6331(@pxref{origin Reference}). For instance, assuming @command{guix
6332publish} is running on @code{example.org}, the following URL returns the
6333raw @file{hello-2.10.tar.gz} file with the given SHA256 hash
6334(represented in @code{nix-base32} format, @pxref{Invoking guix hash}):
6335
6336@example
6337http://example.org/file/hello-2.10.tar.gz/sha256/0ssi1@dots{}ndq1i
6338@end example
6339
6340Obviously, these URLs only work for files that are in the store; in
6341other cases, they return 404 (``Not Found'').
6342
aff8ce7c
DT
6343The following options are available:
6344
6345@table @code
6346@item --port=@var{port}
6347@itemx -p @var{port}
6348Listen for HTTP requests on @var{port}.
6349
9e2292ef
LC
6350@item --listen=@var{host}
6351Listen on the network interface for @var{host}. The default is to
6352accept connections from any interface.
6353
5463fe51
LC
6354@item --user=@var{user}
6355@itemx -u @var{user}
6356Change privileges to @var{user} as soon as possible---i.e., once the
6357server socket is open and the signing key has been read.
6358
4a1fc562
LC
6359@item --compression[=@var{level}]
6360@itemx -C [@var{level}]
6361Compress data using the given @var{level}. When @var{level} is zero,
6362disable compression. The range 1 to 9 corresponds to different gzip
6363compression levels: 1 is the fastest, and 9 is the best (CPU-intensive).
6364The default is 3.
6365
4591c02e 6366Compression occurs on the fly and the compressed streams are not
4a1fc562
LC
6367cached. Thus, to reduce load on the machine that runs @command{guix
6368publish}, it may be a good idea to choose a low compression level, or to
6369run @command{guix publish} behind a caching proxy.
6370
e4c7a5f7
LC
6371@item --ttl=@var{ttl}
6372Produce @code{Cache-Control} HTTP headers that advertise a time-to-live
6373(TTL) of @var{ttl}. @var{ttl} must denote a duration: @code{5d} means 5
6374days, @code{1m} means 1 month, and so on.
6375
6376This allows the user's Guix to keep substitute information in cache for
6377@var{ttl}. However, note that @code{guix publish} does not itself
6378guarantee that the store items it provides will indeed remain available
6379for as long as @var{ttl}.
6380
aff8ce7c
DT
6381@item --repl[=@var{port}]
6382@itemx -r [@var{port}]
6383Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8ce229fc
LC
6384Reference Manual}) on @var{port} (37146 by default). This is used
6385primarily for debugging a running @command{guix publish} server.
aff8ce7c
DT
6386@end table
6387
1c52181f
LC
6388Enabling @command{guix publish} on a GuixSD system is a one-liner: just
6389add a call to @code{guix-publish-service} in the @code{services} field
6390of the @code{operating-system} declaration (@pxref{guix-publish-service,
6391@code{guix-publish-service}}).
6392
332d7903
HG
6393If you are instead running Guix on a ``foreign distro'', follow these
6394instructions:”
6395
6396@itemize
6397@item
6398If your host distro uses the systemd init system:
6399
6400@example
6401# ln -s ~root/.guix-profile/lib/systemd/system/guix-publish.service \
6402 /etc/systemd/system/
6403# systemctl start guix-publish && systemctl enable guix-publish
6404@end example
6405
6406@item
6407If your host distro uses the Upstart init system:
6408
6409@example
6410# ln -s ~root/.guix-profile/lib/upstart/system/guix-publish.conf /etc/init/
6411# start guix-publish
6412@end example
6413
6414@item
6415Otherwise, proceed similarly with your distro's init system.
6416@end itemize
d23c20f1
LC
6417
6418@node Invoking guix challenge
6419@section Invoking @command{guix challenge}
6420
6421@cindex reproducible builds
6422@cindex verifiable builds
e32171ee
JD
6423@cindex @command{guix challenge}
6424@cindex challenge
d23c20f1 6425Do the binaries provided by this server really correspond to the source
f97c9175 6426code it claims to build? Is a package build process deterministic?
d23c20f1
LC
6427These are the questions the @command{guix challenge} command attempts to
6428answer.
6429
6430The former is obviously an important question: Before using a substitute
f97c9175 6431server (@pxref{Substitutes}), one had better @emph{verify} that it
d23c20f1
LC
6432provides the right binaries, and thus @emph{challenge} it. The latter
6433is what enables the former: If package builds are deterministic, then
6434independent builds of the package should yield the exact same result,
6435bit for bit; if a server provides a binary different from the one
6436obtained locally, it may be either corrupt or malicious.
6437
6438We know that the hash that shows up in @file{/gnu/store} file names is
6439the hash of all the inputs of the process that built the file or
6440directory---compilers, libraries, build scripts,
6441etc. (@pxref{Introduction}). Assuming deterministic build processes,
6442one store file name should map to exactly one build output.
6443@command{guix challenge} checks whether there is, indeed, a single
6444mapping by comparing the build outputs of several independent builds of
6445any given store item.
6446
f97c9175 6447The command output looks like this:
d23c20f1
LC
6448
6449@smallexample
ddbc7f7d
LC
6450$ guix challenge --substitute-urls="https://hydra.gnu.org https://guix.example.org"
6451updating list of substitutes from 'https://hydra.gnu.org'... 100.0%
6452updating list of substitutes from 'https://guix.example.org'... 100.0%
d23c20f1
LC
6453/gnu/store/@dots{}-openssl-1.0.2d contents differ:
6454 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
ddbc7f7d
LC
6455 https://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
6456 https://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
d23c20f1
LC
6457/gnu/store/@dots{}-git-2.5.0 contents differ:
6458 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
ddbc7f7d
LC
6459 https://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
6460 https://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
d23c20f1
LC
6461/gnu/store/@dots{}-pius-2.1.1 contents differ:
6462 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
ddbc7f7d
LC
6463 https://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
6464 https://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
d23c20f1
LC
6465@end smallexample
6466
6467@noindent
6468In this example, @command{guix challenge} first scans the store to
6469determine the set of locally-built derivations---as opposed to store
6470items that were downloaded from a substitute server---and then queries
6471all the substitute servers. It then reports those store items for which
6472the servers obtained a result different from the local build.
6473
6474@cindex non-determinism, in package builds
6475As an example, @code{guix.example.org} always gets a different answer.
6476Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
6477case of Git. This might indicate that the build process of Git is
6478non-deterministic, meaning that its output varies as a function of
6479various things that Guix does not fully control, in spite of building
6480packages in isolated environments (@pxref{Features}). Most common
6481sources of non-determinism include the addition of timestamps in build
6482results, the inclusion of random numbers, and directory listings sorted
a70a5004 6483by inode number. See @uref{https://reproducible-builds.org/docs/}, for
d23c20f1
LC
6484more information.
6485
f97c9175 6486To find out what is wrong with this Git binary, we can do something along
d23c20f1
LC
6487these lines (@pxref{Invoking guix archive}):
6488
6489@example
ddbc7f7d 6490$ wget -q -O - https://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
d23c20f1 6491 | guix archive -x /tmp/git
043f4698 6492$ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
d23c20f1
LC
6493@end example
6494
6495This command shows the difference between the files resulting from the
6496local build, and the files resulting from the build on
6497@code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
6498diffutils, Comparing and Merging Files}). The @command{diff} command
6499works great for text files. When binary files differ, a better option
ddbc7f7d 6500is @uref{https://diffoscope.org/, Diffoscope}, a tool that helps
d23c20f1
LC
6501visualize differences for all kinds of files.
6502
f97c9175 6503Once you have done that work, you can tell whether the differences are due
d23c20f1
LC
6504to a non-deterministic build process or to a malicious server. We try
6505hard to remove sources of non-determinism in packages to make it easier
f97c9175
AE
6506to verify substitutes, but of course, this is a process that
6507involves not just Guix, but a large part of the free software community.
d23c20f1
LC
6508In the meantime, @command{guix challenge} is one tool to help address
6509the problem.
6510
6511If you are writing packages for Guix, you are encouraged to check
6512whether @code{hydra.gnu.org} and other substitute servers obtain the
6513same build result as you did with:
6514
6515@example
6516$ guix challenge @var{package}
6517@end example
6518
6519@noindent
f97c9175 6520where @var{package} is a package specification such as
7cffaeb6 6521@code{guile@@2.0} or @code{glibc:debug}.
d23c20f1
LC
6522
6523The general syntax is:
6524
6525@example
6526guix challenge @var{options} [@var{packages}@dots{}]
6527@end example
6528
7cffaeb6
LC
6529When a difference is found between the hash of a locally-built item and
6530that of a server-provided substitute, or among substitutes provided by
6531different servers, the command displays it as in the example above and
a17417a8
LC
6532its exit code is 2 (other non-zero exit codes denote other kinds of
6533errors.)
7cffaeb6 6534
d23c20f1
LC
6535The one option that matters is:
6536
6537@table @code
6538
6539@item --substitute-urls=@var{urls}
6540Consider @var{urls} the whitespace-separated list of substitute source
6541URLs to compare to.
6542
153b6295
LC
6543@item --verbose
6544@itemx -v
6545Show details about matches (identical contents) in addition to
6546information about mismatches.
6547
d23c20f1
LC
6548@end table
6549
f11c444d
LC
6550@node Invoking guix copy
6551@section Invoking @command{guix copy}
6552
6553@cindex copy, of store items, over SSH
6554@cindex SSH, copy of store items
6555@cindex sharing store items across machines
6556@cindex transferring store items across machines
6557The @command{guix copy} command copies items from the store of one
6558machine to that of another machine over a secure shell (SSH)
6559connection@footnote{This command is available only when Guile-SSH was
6560found. @xref{Requirements}, for details.}. For example, the following
6561command copies the @code{coreutils} package, the user's profile, and all
6562their dependencies over to @var{host}, logged in as @var{user}:
6563
6564@example
6565guix copy --to=@var{user}@@@var{host} \
6566 coreutils `readlink -f ~/.guix-profile`
6567@end example
6568
6569If some of the items to be copied are already present on @var{host},
6570they are not actually sent.
6571
6572The command below retrieves @code{libreoffice} and @code{gimp} from
6573@var{host}, assuming they are available there:
6574
6575@example
6576guix copy --from=@var{host} libreoffice gimp
6577@end example
6578
6579The SSH connection is established using the Guile-SSH client, which is
6580compatible with OpenSSH: it honors @file{~/.ssh/known_hosts} and
6581@file{~/.ssh/config}, and uses the SSH agent for authentication.
6582
6583The key used to sign items that are sent must be accepted by the remote
6584machine. Likewise, the key used by the remote machine to sign items you
6585are retrieving must be in @file{/etc/guix/acl} so it is accepted by your
6586own daemon. @xref{Invoking guix archive}, for more information about
6587store item authentication.
6588
6589The general syntax is:
6590
6591@example
6592guix copy [--to=@var{spec}|--from=@var{spec}] @var{items}@dots{}
6593@end example
6594
6595You must always specify one of the following options:
6596
6597@table @code
6598@item --to=@var{spec}
6599@itemx --from=@var{spec}
6600Specify the host to send to or receive from. @var{spec} must be an SSH
6601spec such as @code{example.org}, @code{charlie@@example.org}, or
6602@code{charlie@@example.org:2222}.
6603@end table
6604
6605The @var{items} can be either package names, such as @code{gimp}, or
6606store items, such as @file{/gnu/store/@dots{}-idutils-4.6}.
6607
6608When specifying the name of a package to send, it is first built if
6609needed, unless @option{--dry-run} was specified. Common build options
6610are supported (@pxref{Common Build Options}).
6611
d23c20f1 6612
32efa254
DT
6613@node Invoking guix container
6614@section Invoking @command{guix container}
6615@cindex container
e32171ee 6616@cindex @command{guix container}
32efa254
DT
6617@quotation Note
6618As of version @value{VERSION}, this tool is experimental. The interface
6619is subject to radical change in the future.
6620@end quotation
6621
6622The purpose of @command{guix container} is to manipulate processes
6623running within an isolated environment, commonly known as a
46c36586 6624``container'', typically created by the @command{guix environment}
32efa254
DT
6625(@pxref{Invoking guix environment}) and @command{guix system container}
6626(@pxref{Invoking guix system}) commands.
6627
6628The general syntax is:
6629
6630@example
6631guix container @var{action} @var{options}@dots{}
6632@end example
6633
6634@var{action} specifies the operation to perform with a container, and
6635@var{options} specifies the context-specific arguments for the action.
6636
6637The following actions are available:
6638
6639@table @code
6640@item exec
6641Execute a command within the context of a running container.
6642
6643The syntax is:
6644
6645@example
6646guix container exec @var{pid} @var{program} @var{arguments}@dots{}
6647@end example
6648
6649@var{pid} specifies the process ID of the running container.
f97c9175
AE
6650@var{program} specifies an executable file name within the root file
6651system of the container. @var{arguments} are the additional options that
6652will be passed to @var{program}.
32efa254
DT
6653
6654The following command launches an interactive login shell inside a
6655GuixSD container, started by @command{guix system container}, and whose
6656process ID is 9001:
6657
6658@example
6659guix container exec 9001 /run/current-system/profile/bin/bash --login
6660@end example
6661
6662Note that the @var{pid} cannot be the parent process of a container. It
f97c9175 6663must be PID 1 of the container or one of its child processes.
32efa254
DT
6664
6665@end table
6666
a1ba8475
LC
6667@c *********************************************************************
6668@node GNU Distribution
6669@chapter GNU Distribution
6670
3ca2731c 6671@cindex Guix System Distribution
4705641f 6672@cindex GuixSD
3ca2731c
LC
6673Guix comes with a distribution of the GNU system consisting entirely of
6674free software@footnote{The term ``free'' here refers to the
a1ba8475 6675@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 6676users of that software}.}. The
35ed9306
LC
6677distribution can be installed on its own (@pxref{System Installation}),
6678but it is also possible to install Guix as a package manager on top of
6679an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c 6680between the two, we refer to the standalone distribution as the Guix
4705641f 6681System Distribution, or GuixSD.
35ed9306
LC
6682
6683The distribution provides core GNU packages such as GNU libc, GCC, and
6684Binutils, as well as many GNU and non-GNU applications. The complete
6685list of available packages can be browsed
093ae1be 6686@url{http://www.gnu.org/software/guix/packages,on-line} or by
d03bb653 6687running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
6688
6689@example
e49951eb 6690guix package --list-available
a1ba8475
LC
6691@end example
6692
f97c9175 6693Our goal is to provide a practical 100% free software distribution of
401c53c4
LC
6694Linux-based and other variants of GNU, with a focus on the promotion and
6695tight integration of GNU components, and an emphasis on programs and
6696tools that help users exert that freedom.
6697
3ca2731c 6698Packages are currently available on the following platforms:
c320011d
LC
6699
6700@table @code
6701
6702@item x86_64-linux
6703Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
6704
6705@item i686-linux
6706Intel 32-bit architecture (IA32), Linux-Libre kernel;
6707
aa1e1947 6708@item armhf-linux
aa725117 6709ARMv7-A architecture with hard float, Thumb-2 and NEON,
f97c9175
AE
6710using the EABI hard-float application binary interface (ABI),
6711and Linux-Libre kernel.
aa1e1947 6712
3b88f376
EF
6713@item aarch64-linux
6714little-endian 64-bit ARMv8-A processors, Linux-Libre kernel. This is
6715currently in an experimental stage, with limited support. See
6716@xref{Contributing}, for how to help!
6717
c320011d
LC
6718@item mips64el-linux
6719little-endian 64-bit MIPS processors, specifically the Loongson series,
f97c9175 6720n32 ABI, and Linux-Libre kernel.
c320011d
LC
6721
6722@end table
6723
4705641f 6724GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
3ca2731c 6725
c320011d
LC
6726@noindent
6727For information on porting to other architectures or kernels,
f97c9175 6728@pxref{Porting}.
c320011d 6729
401c53c4 6730@menu
5af6de3e 6731* System Installation:: Installing the whole operating system.
35ed9306 6732* System Configuration:: Configuring the operating system.
91ef73d4 6733* Installing Debugging Files:: Feeding the debugger.
05962f29 6734* Security Updates:: Deploying security fixes quickly.
401c53c4 6735* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 6736* Packaging Guidelines:: Growing the distribution.
401c53c4 6737* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 6738* Porting:: Targeting another platform or kernel.
401c53c4
LC
6739@end menu
6740
6741Building this distribution is a cooperative effort, and you are invited
081145cf 6742to join! @xref{Contributing}, for information about how you can help.
401c53c4 6743
5af6de3e
LC
6744@node System Installation
6745@section System Installation
6746
e32171ee 6747@cindex installing GuixSD
3ca2731c 6748@cindex Guix System Distribution
c8b54374 6749This section explains how to install the Guix System Distribution (GuixSD)
3ca2731c 6750on a machine. The Guix package manager can
35ed9306
LC
6751also be installed on top of a running GNU/Linux system,
6752@pxref{Installation}.
5af6de3e
LC
6753
6754@ifinfo
9c18cf9b 6755@quotation Note
5af6de3e
LC
6756@c This paragraph is for people reading this from tty2 of the
6757@c installation image.
1068f26b 6758You are reading this documentation with an Info reader. For details on
5af6de3e 6759how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
de341e7c
LC
6760link that follows: @pxref{Top, Info reader,, info-stnd, Stand-alone GNU
6761Info}. Hit @kbd{l} afterwards to come back here.
9c18cf9b
LC
6762
6763Alternately, run @command{info info} in another tty to keep the manual
6764available.
6765@end quotation
5af6de3e
LC
6766@end ifinfo
6767
dedb8d5e 6768@menu
e3009f60
LC
6769* Limitations:: What you can expect.
6770* Hardware Considerations:: Supported hardware.
6771* USB Stick Installation:: Preparing the installation medium.
6772* Preparing for Installation:: Networking, partitioning, etc.
6773* Proceeding with the Installation:: The real thing.
c8b54374 6774* Installing GuixSD in a VM:: GuixSD playground.
e3009f60 6775* Building the Installation Image:: How this comes to be.
dedb8d5e
LC
6776@end menu
6777
6778@node Limitations
8aaaae38
LC
6779@subsection Limitations
6780
4705641f 6781As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
3ca2731c 6782not production-ready. It may contain bugs and lack important
8aaaae38
LC
6783features. Thus, if you are looking for a stable production system that
6784respects your freedom as a computer user, a good solution at this point
6785is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
f97c9175 6786the more established GNU/Linux distributions}. We hope you can soon switch
4705641f 6787to the GuixSD without fear, of course. In the meantime, you can
8aaaae38
LC
6788also keep using your distribution and try out the package manager on top
6789of it (@pxref{Installation}).
6790
6791Before you proceed with the installation, be aware of the following
6792noteworthy limitations applicable to version @value{VERSION}:
6793
6794@itemize
6795@item
6796The installation process does not include a graphical user interface and
6797requires familiarity with GNU/Linux (see the following subsections to
6798get a feel of what that means.)
6799
8aaaae38 6800@item
dbcb0ab1 6801Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
6802
6803@item
6804Few system services are currently supported out-of-the-box
6805(@pxref{Services}).
6806
6807@item
29e53b95 6808More than 4,000 packages are available, but you may
8aaaae38 6809occasionally find that a useful package is missing.
5fe01c2d
LC
6810
6811@item
6812GNOME, Xfce, and Enlightenment are available (@pxref{Desktop Services}),
6813as well as a number of X11 window managers. However, some graphical
6814applications may be missing, as well as KDE.
8aaaae38
LC
6815@end itemize
6816
f97c9175
AE
6817You have been warned! But more than a disclaimer, this is an invitation
6818to report issues (and success stories!), and to join us in improving it.
8aaaae38 6819@xref{Contributing}, for more info.
5af6de3e 6820
e3009f60
LC
6821
6822@node Hardware Considerations
6823@subsection Hardware Considerations
6824
6825@cindex hardware support on GuixSD
6826GNU@tie{}GuixSD focuses on respecting the user's computing freedom. It
6827builds around the kernel Linux-libre, which means that only hardware for
e0b3f97e 6828which free software drivers and firmware exist is supported. Nowadays,
e3009f60
LC
6829a wide range of off-the-shelf hardware is supported on
6830GNU/Linux-libre---from keyboards to graphics cards to scanners and
6831Ethernet controllers. Unfortunately, there are still areas where
6832hardware vendors deny users control over their own computing, and such
6833hardware is not supported on GuixSD.
6834
6835@cindex WiFi, hardware support
e0b3f97e 6836One of the main areas where free drivers or firmware are lacking is WiFi
e3009f60
LC
6837devices. WiFi devices known to work include those using Atheros chips
6838(AR9271 and AR7010), which corresponds to the @code{ath9k} Linux-libre
52db41af
EB
6839driver, and those using Broadcom/AirForce chips (BCM43xx with
6840Wireless-Core Revision 5), which corresponds to the @code{b43-open}
6841Linux-libre driver. Free firmware exists for both and is available
e3009f60
LC
6842out-of-the-box on GuixSD, as part of @var{%base-firmware}
6843(@pxref{operating-system Reference, @code{firmware}}).
6844
6845@cindex RYF, Respects Your Freedom
6846The @uref{https://www.fsf.org/, Free Software Foundation} runs
e0b3f97e 6847@uref{https://www.fsf.org/ryf, @dfn{Respects Your Freedom}} (RYF), a
e3009f60
LC
6848certification program for hardware products that respect your freedom
6849and your privacy and ensure that you have control over your device. We
e0b3f97e 6850encourage you to check the list of RYF-certified devices.
e3009f60
LC
6851
6852Another useful resource is the @uref{https://www.h-node.org/, H-Node}
6853web site. It contains a catalog of hardware devices with information
6854about their support in GNU/Linux.
6855
6856
dedb8d5e 6857@node USB Stick Installation
5af6de3e
LC
6858@subsection USB Stick Installation
6859
6860An installation image for USB sticks can be downloaded from
4705641f 6861@indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
6862where @var{system} is one of:
6863
6864@table @code
6865@item x86_64-linux
6866for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
6867
6868@item i686-linux
6869for a 32-bit GNU/Linux system on Intel-compatible CPUs.
6870@end table
6871
debc6360
LC
6872@c start duplication of authentication part from ``Binary Installation''
6873Make sure to download the associated @file{.sig} file and to verify the
6874authenticity of the image against it, along these lines:
6875
6876@example
6877$ wget ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz.sig
6878$ gpg --verify guixsd-usb-install-@value{VERSION}.@var{system}.xz.sig
6879@end example
6880
6881If that command fails because you do not have the required public key,
6882then run this command to import it:
6883
6884@example
6885$ gpg --keyserver pgp.mit.edu --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
6886@end example
6887
6888@noindent
6889and rerun the @code{gpg --verify} command.
6890@c end duplication
6891
5af6de3e
LC
6892This image contains a single partition with the tools necessary for an
6893installation. It is meant to be copied @emph{as is} to a large-enough
6894USB stick.
6895
6896To copy the image to a USB stick, follow these steps:
6897
6898@enumerate
6899@item
6900Decompress the image using the @command{xz} command:
6901
6902@example
4705641f 6903xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
6904@end example
6905
6906@item
f97c9175
AE
6907Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
6908its device name. Assuming that the USB stick is known as @file{/dev/sdX},
5af6de3e
LC
6909copy the image with:
6910
6911@example
4705641f 6912dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
6913@end example
6914
6915Access to @file{/dev/sdX} usually requires root privileges.
6916@end enumerate
6917
6918Once this is done, you should be able to reboot the system and boot from
6919the USB stick. The latter usually requires you to get in the BIOS' boot
6920menu, where you can choose to boot from the USB stick.
6921
c8b54374
VL
6922@xref{Installing GuixSD in a VM}, if, instead, you would like to install
6923GuixSD in a virtual machine (VM).
6924
dedb8d5e 6925@node Preparing for Installation
5af6de3e
LC
6926@subsection Preparing for Installation
6927
6928Once you have successfully booted the image on the USB stick, you should
6929end up with a root prompt. Several console TTYs are configured and can
6930be used to run commands as root. TTY2 shows this documentation,
de341e7c
LC
6931browsable using the Info reader commands (@pxref{Top,,, info-stnd,
6932Stand-alone GNU Info}). The installation system runs the GPM mouse
6933daemon, which allows you to select text with the left mouse button and
6934to paste it with the middle button.
5af6de3e 6935
ff925d37
LC
6936@quotation Note
6937Installation requires access to the Internet so that any missing
6938dependencies of your system configuration can be downloaded. See the
6939``Networking'' section below.
6940@end quotation
6941
0e69cf67
LC
6942The installation system includes many common tools needed for this task.
6943But it is also a full-blown GuixSD system, which means that you can
6944install additional packages, should you need it, using @command{guix
6945package} (@pxref{Invoking guix package}).
6946
dedb8d5e 6947@subsubsection Keyboard Layout
5af6de3e 6948
dedb8d5e
LC
6949@cindex keyboard layout
6950The installation image uses the US qwerty keyboard layout. If you want
6951to change it, you can use the @command{loadkeys} command. For example,
6952the following command selects the Dvorak keyboard layout:
5af6de3e 6953
dedb8d5e
LC
6954@example
6955loadkeys dvorak
6956@end example
6957
6958See the files under @file{/run/current-system/profile/share/keymaps} for
6959a list of available keyboard layouts. Run @command{man loadkeys} for
6960more information.
6961
6962@subsubsection Networking
6963
6964Run the following command see what your network interfaces are called:
235cba85
LC
6965
6966@example
dedb8d5e 6967ifconfig -a
235cba85
LC
6968@end example
6969
1713c37f
LC
6970@noindent
6971@dots{} or, using the GNU/Linux-specific @command{ip} command:
6972
6973@example
6974ip a
6975@end example
6976
95c559c1 6977@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
dedb8d5e
LC
6978Wired interfaces have a name starting with @samp{e}; for example, the
6979interface corresponding to the first on-board Ethernet controller is
6980called @samp{eno1}. Wireless interfaces have a name starting with
6981@samp{w}, like @samp{w1p2s0}.
6982
6983@table @asis
6984@item Wired connection
6985To configure a wired network run the following command, substituting
6986@var{interface} with the name of the wired interface you want to use.
6987
6988@example
6989ifconfig @var{interface} up
6990@end example
6991
6992@item Wireless connection
e32171ee
JD
6993@cindex wireless
6994@cindex WiFi
dedb8d5e
LC
6995To configure wireless networking, you can create a configuration file
6996for the @command{wpa_supplicant} configuration tool (its location is not
6997important) using one of the available text editors such as
6998@command{zile}:
6999
7000@example
7001zile wpa_supplicant.conf
7002@end example
7003
7004As an example, the following stanza can go to this file and will work
7005for many wireless networks, provided you give the actual SSID and
7006passphrase for the network you are connecting to:
7007
7008@example
7009network=@{
ae768308 7010 ssid="@var{my-ssid}"
dedb8d5e
LC
7011 key_mgmt=WPA-PSK
7012 psk="the network's secret passphrase"
7013@}
7014@end example
7015
7016Start the wireless service and run it in the background with the
7017following command (substitute @var{interface} with the name of the
7018network interface you want to use):
7019
7020@example
7021wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
7022@end example
7023
641d0518 7024Run @command{man wpa_supplicant} for more information.
dedb8d5e
LC
7025@end table
7026
e32171ee 7027@cindex DHCP
dedb8d5e
LC
7028At this point, you need to acquire an IP address. On a network where IP
7029addresses are automatically assigned @i{via} DHCP, you can run:
7030
7031@example
15650ac2 7032dhclient -v @var{interface}
dedb8d5e 7033@end example
5af6de3e 7034
dedb8d5e
LC
7035Try to ping a server to see if networking is up and running:
7036
7037@example
7038ping -c 3 gnu.org
7039@end example
5af6de3e
LC
7040
7041Setting up network access is almost always a requirement because the
7042image does not contain all the software and tools that may be needed.
7043
dedb8d5e
LC
7044@subsubsection Disk Partitioning
7045
7046Unless this has already been done, the next step is to partition, and
7047then format the target partition(s).
7048
7049The installation image includes several partitioning tools, including
7050Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
7051@command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
7052the partition layout you want:
7053
7054@example
7055cfdisk
7056@end example
7057
d918d79f
SB
7058If your disk uses the GUID Partition Table (GPT) format and you plan to
7059install BIOS-based GRUB (which is the default), make sure a BIOS Boot
7060Partition is available (@pxref{BIOS installation,,, grub, GNU GRUB
7061manual}).
7062
dedb8d5e
LC
7063Once you are done partitioning the target hard disk drive, you have to
7064create a file system on the relevant partition(s)@footnote{Currently
b1a505ba
DC
7065GuixSD only supports ext4 and btrfs file systems. In particular, code
7066that reads partition UUIDs and labels only works for these file system
7067types.}.
5af6de3e 7068
7ab44369
LC
7069Preferably, assign partitions a label so that you can easily and
7070reliably refer to them in @code{file-system} declarations (@pxref{File
7071Systems}). This is typically done using the @code{-L} option of
dedb8d5e
LC
7072@command{mkfs.ext4} and related commands. So, assuming the target root
7073partition lives at @file{/dev/sda1}, a file system with the label
7074@code{my-root} can be created with:
7ab44369 7075
dedb8d5e
LC
7076@example
7077mkfs.ext4 -L my-root /dev/sda1
7078@end example
dd816355 7079
13fb1bd9
LC
7080@cindex encrypted disk
7081If you are instead planning to encrypt the root partition, you can use
7082the Cryptsetup/LUKS utilities to do that (see @inlinefmtifelse{html,
7083@uref{https://linux.die.net/man/8/cryptsetup, @code{man cryptsetup}},
7084@code{man cryptsetup}} for more information.) Assuming you want to
7085store the root partition on @file{/dev/sda1}, the command sequence would
7086be along these lines:
6d6e6281 7087
13fb1bd9
LC
7088@example
7089cryptsetup luksFormat /dev/sda1
7090cryptsetup open --type luks /dev/sda1 my-partition
7091mkfs.ext4 -L my-root /dev/mapper/my-partition
7092@end example
5af6de3e 7093
dedb8d5e 7094Once that is done, mount the target root partition under @file{/mnt}
13fb1bd9
LC
7095with a command like (again, assuming @code{my-root} is the label of the
7096root partition):
83a17b62 7097
dedb8d5e 7098@example
13fb1bd9 7099mount LABEL=my-root /mnt
dedb8d5e 7100@end example
83a17b62 7101
31b6cdf8
LC
7102Finally, if you plan to use one or more swap partitions (@pxref{Memory
7103Concepts, swap space,, libc, The GNU C Library Reference Manual}), make
7104sure to initialize them with @command{mkswap}. Assuming you have one
7105swap partition on @file{/dev/sda2}, you would run:
7106
7107@example
7108mkswap /dev/sda2
b2ff76a0 7109swapon /dev/sda2
31b6cdf8
LC
7110@end example
7111
a4ca4362
CM
7112Alternatively, you may use a swap file. For example, assuming that in
7113the new system you want to use the file @file{/swapfile} as a swap file,
7114you would run@footnote{This example will work for many types of file
7115systems (e.g., ext4). However, for copy-on-write file systems (e.g.,
7116btrfs), the required steps may be different. For details, see the
7117manual pages for @command{mkswap} and @command{swapon}.}:
7118
7119@example
7120# This is 10 GiB of swap space. Adjust "count" to change the size.
7121dd if=/dev/zero of=/mnt/swapfile bs=1MiB count=10240
7122# For security, make the file readable and writable only by root.
7123chmod 600 /mnt/swapfile
7124mkswap /mnt/swapfile
7125swapon /mnt/swapfile
7126@end example
7127
7128Note that if you have encrypted the root partition and created a swap
7129file in its file system as described above, then the encryption also
7130protects the swap file, just like any other file in that file system.
7131
dedb8d5e
LC
7132@node Proceeding with the Installation
7133@subsection Proceeding with the Installation
83a17b62 7134
dedb8d5e
LC
7135With the target partitions ready and the target root mounted on
7136@file{/mnt}, we're ready to go. First, run:
5af6de3e 7137
dedb8d5e
LC
7138@example
7139herd start cow-store /mnt
7140@end example
5af6de3e 7141
b397c0d5
LC
7142This makes @file{/gnu/store} copy-on-write, such that packages added to it
7143during the installation phase are written to the target disk on @file{/mnt}
7144rather than kept in memory. This is necessary because the first phase of
7145the @command{guix system init} command (see below) entails downloads or
7146builds to @file{/gnu/store} which, initially, is an in-memory file system.
5af6de3e 7147
dedb8d5e 7148Next, you have to edit a file and
5af6de3e 7149provide the declaration of the operating system to be installed. To
a8cb87ab
LC
7150that end, the installation system comes with three text editors: GNU nano
7151(@pxref{Top,,, nano, GNU nano Manual}), GNU Zile (an Emacs clone), and
7152nvi (a clone of the original BSD @command{vi} editor).
efa77c6c
LC
7153We strongly recommend storing that file on the target root file system, say,
7154as @file{/mnt/etc/config.scm}. Failing to do that, you will have lost your
7155configuration file once you have rebooted into the newly-installed system.
5af6de3e 7156
dedb8d5e
LC
7157@xref{Using the Configuration System}, for an overview of the
7158configuration file. The example configurations discussed in that
7159section are available under @file{/etc/configuration} in the
7160installation image. Thus, to get started with a system configuration
7161providing a graphical display server (a ``desktop'' system), you can run
7162something along these lines:
7163
7164@example
7165# mkdir /mnt/etc
7166# cp /etc/configuration/desktop.scm /mnt/etc/config.scm
7167# zile /mnt/etc/config.scm
7168@end example
7169
7170You should pay attention to what your configuration file contains, and
7171in particular:
7172
7173@itemize
7174@item
7175Make sure the @code{grub-configuration} form refers to the device you
7176want to install GRUB on.
7177
7178@item
7179Be sure that your partition labels match the value of their respective
7180@code{device} fields in your @code{file-system} configuration, assuming
7181your @code{file-system} configuration sets the value of @code{title} to
7182@code{'label}.
13fb1bd9
LC
7183
7184@item
7185If there are encrypted or RAID partitions, make sure to add a
7186@code{mapped-devices} field to describe them (@pxref{Mapped Devices}).
dedb8d5e 7187@end itemize
5af6de3e 7188
dd51caac
LC
7189Once you are done preparing the configuration file, the new system must
7190be initialized (remember that the target root file system is mounted
7191under @file{/mnt}):
5af6de3e
LC
7192
7193@example
7194guix system init /mnt/etc/config.scm /mnt
7195@end example
7196
7197@noindent
dedb8d5e 7198This copies all the necessary files and installs GRUB on
5af6de3e 7199@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 7200more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
7201downloads or builds of missing packages, which can take some time.
7202
1bd4e6db
LC
7203Once that command has completed---and hopefully succeeded!---you can run
7204@command{reboot} and boot into the new system. The @code{root} password
7205in the new system is initially empty; other users' passwords need to be
7206initialized by running the @command{passwd} command as @code{root},
7207unless your configuration specifies otherwise
7208(@pxref{user-account-password, user account passwords}).
7209
7fcf2a0b
LC
7210@cindex upgrading GuixSD
7211From then on, you can update GuixSD whenever you want by running
7212@command{guix pull} as @code{root} (@pxref{Invoking guix pull}), and
7213then running @command{guix system reconfigure} to build a new system
7214generation with the latest packages and services (@pxref{Invoking guix
7215system}). We recommend doing that regularly so that your system
7216includes the latest security updates (@pxref{Security Updates}).
7217
1bd4e6db 7218Join us on @code{#guix} on the Freenode IRC network or on
5af6de3e
LC
7219@file{guix-devel@@gnu.org} to share your experience---good or not so
7220good.
7221
c8b54374
VL
7222@node Installing GuixSD in a VM
7223@subsection Installing GuixSD in a Virtual Machine
7224
7225@cindex virtual machine, GuixSD installation
7226If you'd like to install GuixSD in a virtual machine (VM) rather than on
7227your beloved machine, this section is for you.
7228
7229To boot a @uref{http://qemu.org/,QEMU} VM for installing GuixSD in a
7230disk image, follow these steps:
7231
7232@enumerate
7233@item
a0885414
LF
7234First, retrieve and decompress the GuixSD installation image as
7235described previously (@pxref{USB Stick Installation}).
c8b54374
VL
7236
7237@item
7238Create a disk image that will hold the installed system. To make a
7239qcow2-formatted disk image, use the @command{qemu-img} command:
7240
7241@example
7242qemu-img create -f qcow2 guixsd.img 5G
7243@end example
7244
7245This will create a 5GB file.
7246
7247@item
7248Boot the USB installation image in an VM:
7249
7250@example
7251qemu-system-x86_64 -m 1024 -smp 1 \
d36b8457 7252 -net user -net nic,model=virtio -boot menu=on \
c8b54374
VL
7253 -drive file=guixsd.img \
7254 -drive file=guixsd-usb-install-@value{VERSION}.@var{system}
7255@end example
7256
7257In the VM console, quickly press the @kbd{F12} key to enter the boot
7258menu. Then press the @kbd{2} key and the @kbd{RET} key to validate your
7259selection.
7260
7261@item
7262You're now root in the VM, proceed with the installation process.
7263@xref{Preparing for Installation}, and follow the instructions.
7264@end enumerate
7265
7266Once installation is complete, you can boot the system that's on your
7267@file{guixsd.img} image. @xref{Running GuixSD in a VM}, for how to do
7268that.
7269
dedb8d5e 7270@node Building the Installation Image
5af6de3e
LC
7271@subsection Building the Installation Image
7272
e32171ee 7273@cindex installation image
5af6de3e
LC
7274The installation image described above was built using the @command{guix
7275system} command, specifically:
7276
622b2304 7277@c FIXME: 1G is too much; see <http://bugs.gnu.org/23077>.
5af6de3e 7278@example
622b2304 7279guix system disk-image --image-size=1G gnu/system/install.scm
5af6de3e
LC
7280@end example
7281
6e6a0401
AE
7282Have a look at @file{gnu/system/install.scm} in the source tree,
7283and see also @ref{Invoking guix system} for more information
5af6de3e
LC
7284about the installation image.
7285
cf4a9129
LC
7286@node System Configuration
7287@section System Configuration
b208a005 7288
cf4a9129 7289@cindex system configuration
3ca2731c 7290The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
7291mechanism. By that we mean that all aspects of the global system
7292configuration---such as the available system services, timezone and
7293locale settings, user accounts---are declared in a single place. Such
7294a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 7295
cf4a9129
LC
7296One of the advantages of putting all the system configuration under the
7297control of Guix is that it supports transactional system upgrades, and
1068f26b 7298makes it possible to roll back to a previous system instantiation,
cf4a9129 7299should something go wrong with the new one (@pxref{Features}). Another
1068f26b 7300advantage is that it makes it easy to replicate the exact same configuration
cf4a9129
LC
7301across different machines, or at different points in time, without
7302having to resort to additional administration tools layered on top of
1068f26b 7303the own tools of the system.
cf4a9129 7304@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 7305
cf4a9129
LC
7306This section describes this mechanism. First we focus on the system
7307administrator's viewpoint---explaining how the system is configured and
7308instantiated. Then we show how this mechanism can be extended, for
7309instance to support new system services.
91ef73d4 7310
cf4a9129
LC
7311@menu
7312* Using the Configuration System:: Customizing your GNU system.
7313a52e 7313* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 7314* File Systems:: Configuring file system mounts.
510f9d86 7315* Mapped Devices:: Block device extra processing.
cf4a9129 7316* User Accounts:: Specifying user accounts.
598e19dc 7317* Locales:: Language and cultural convention settings.
cf4a9129 7318* Services:: Specifying system services.
0ae8c15a 7319* Setuid Programs:: Programs running with root privileges.
efb5e833 7320* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 7321* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 7322* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 7323* GRUB Configuration:: Configuring the boot loader.
cf4a9129 7324* Invoking guix system:: Instantiating a system configuration.
97d76250 7325* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
cf4a9129
LC
7326* Defining Services:: Adding new service definitions.
7327@end menu
91ef73d4 7328
cf4a9129
LC
7329@node Using the Configuration System
7330@subsection Using the Configuration System
64d76fa6 7331
cf4a9129
LC
7332The operating system is configured by providing an
7333@code{operating-system} declaration in a file that can then be passed to
7334the @command{guix system} command (@pxref{Invoking guix system}). A
7335simple setup, with the default system services, the default Linux-Libre
7336kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 7337
cf4a9129
LC
7338@findex operating-system
7339@lisp
dd51caac 7340@include os-config-bare-bones.texi
cf4a9129 7341@end lisp
401c53c4 7342
cf4a9129
LC
7343This example should be self-describing. Some of the fields defined
7344above, such as @code{host-name} and @code{bootloader}, are mandatory.
7345Others, such as @code{packages} and @code{services}, can be omitted, in
7346which case they get a default value.
e7f34eb0 7347
5d94ac51
LC
7348Below we discuss the effect of some of the most important fields
7349(@pxref{operating-system Reference}, for details about all the available
7350fields), and how to @dfn{instantiate} the operating system using
7351@command{guix system}.
7352
7353@unnumberedsubsubsec Globally-Visible Packages
7354
cf4a9129 7355@vindex %base-packages
5d94ac51
LC
7356The @code{packages} field lists packages that will be globally visible
7357on the system, for all user accounts---i.e., in every user's @code{PATH}
7358environment variable---in addition to the per-user profiles
7359(@pxref{Invoking guix package}). The @var{%base-packages} variable
7360provides all the tools one would expect for basic user and administrator
7361tasks---including the GNU Core Utilities, the GNU Networking Utilities,
7362the GNU Zile lightweight text editor, @command{find}, @command{grep},
7363etc. The example above adds tcpdump to those, taken from the @code{(gnu
7364packages admin)} module (@pxref{Package Modules}).
e7f34eb0 7365
f6c9fb1b
LC
7366@findex specification->package
7367Referring to packages by variable name, like @var{tcpdump} above, has
7368the advantage of being unambiguous; it also allows typos and such to be
7369diagnosed right away as ``unbound variables''. The downside is that one
7370needs to know which module defines which package, and to augment the
7371@code{use-package-modules} line accordingly. To avoid that, one can use
7372the @code{specification->package} procedure of the @code{(gnu packages)}
7373module, which returns the best package for a given name or name and
7374version:
7375
7376@lisp
7377(use-modules (gnu packages))
7378
7379(operating-system
7380 ;; ...
7381 (packages (append (map specification->package
d5e59248 7382 '("tcpdump" "htop" "gnupg@@2.0"))
f6c9fb1b
LC
7383 %base-packages)))
7384@end lisp
7385
5d94ac51
LC
7386@unnumberedsubsubsec System Services
7387
e32171ee 7388@cindex services
cf4a9129
LC
7389@vindex %base-services
7390The @code{services} field lists @dfn{system services} to be made
7391available when the system starts (@pxref{Services}).
7392The @code{operating-system} declaration above specifies that, in
7393addition to the basic services, we want the @command{lshd} secure shell
cd6f6c22
LC
7394daemon listening on port 2222 (@pxref{Networking Services,
7395@code{lsh-service}}). Under the hood,
cf4a9129
LC
7396@code{lsh-service} arranges so that @code{lshd} is started with the
7397right command-line options, possibly with supporting configuration files
cd6f6c22
LC
7398generated as needed (@pxref{Defining Services}).
7399
7400@cindex customization, of services
7401@findex modify-services
7402Occasionally, instead of using the base services as is, you will want to
4d343a14
CM
7403customize them. To do this, use @code{modify-services} (@pxref{Service
7404Reference, @code{modify-services}}) to modify the list.
7405
7406For example, suppose you want to modify @code{guix-daemon} and Mingetty
7407(the console log-in) in the @var{%base-services} list (@pxref{Base
7408Services, @code{%base-services}}). To do that, you can write the
7409following in your operating system declaration:
cd6f6c22
LC
7410
7411@lisp
4d343a14
CM
7412(define %my-services
7413 ;; My very own list of services.
7414 (modify-services %base-services
7415 (guix-service-type config =>
7416 (guix-configuration
7417 (inherit config)
7418 (use-substitutes? #f)
7419 (extra-options '("--gc-keep-derivations"))))
7420 (mingetty-service-type config =>
7421 (mingetty-configuration
317d3b47 7422 (inherit config)))))
4d343a14
CM
7423
7424(operating-system
7425 ;; @dots{}
7426 (services %my-services))
cd6f6c22
LC
7427@end lisp
7428
4d343a14
CM
7429This changes the configuration---i.e., the service parameters---of the
7430@code{guix-service-type} instance, and that of all the
7431@code{mingetty-service-type} instances in the @var{%base-services} list.
7432Observe how this is accomplished: first, we arrange for the original
7433configuration to be bound to the identifier @code{config} in the
7434@var{body}, and then we write the @var{body} so that it evaluates to the
7435desired configuration. In particular, notice how we use @code{inherit}
7436to create a new configuration which has the same values as the old
7437configuration, but with a few modifications.
a1ba8475 7438
13fb1bd9
LC
7439@cindex encrypted disk
7440The configuration for a typical ``desktop'' usage, with an encrypted
7441root partition, the X11 display
d038b674
LC
7442server, GNOME and Xfce (users can choose which of these desktop
7443environments to use at the log-in screen by pressing @kbd{F1}), network
7444management, power management, and more, would look like this:
dd51caac
LC
7445
7446@lisp
7447@include os-config-desktop.texi
7448@end lisp
7449
d038b674
LC
7450A graphical environment with a choice of lightweight window managers
7451instead of full-blown desktop environments would look like this:
7452
7453@lisp
7454@include os-config-lightweight-desktop.texi
7455@end lisp
7456
dd51caac 7457@xref{Desktop Services}, for the exact list of services provided by
efb5e833
LC
7458@var{%desktop-services}. @xref{X.509 Certificates}, for background
7459information about the @code{nss-certs} package that is used here.
dd51caac 7460
5d94ac51
LC
7461Again, @var{%desktop-services} is just a list of service objects. If
7462you want to remove services from there, you can do so using the
7463procedures for list filtering (@pxref{SRFI-1 Filtering and
7464Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
7465following expression returns a list that contains all the services in
7466@var{%desktop-services} minus the Avahi service:
7467
7468@example
7469(remove (lambda (service)
7470 (eq? (service-kind service) avahi-service-type))
7471 %desktop-services)
7472@end example
7473
7474@unnumberedsubsubsec Instantiating the System
7475
7476Assuming the @code{operating-system} declaration
7477is stored in the @file{my-system-config.scm}
cf4a9129
LC
7478file, the @command{guix system reconfigure my-system-config.scm} command
7479instantiates that configuration, and makes it the default GRUB boot
65797bff
LC
7480entry (@pxref{Invoking guix system}).
7481
1068f26b 7482The normal way to change the system configuration is by updating this
65797bff 7483file and re-running @command{guix system reconfigure}. One should never
8b499030 7484have to touch files in @file{/etc} or to run commands that modify the
65797bff
LC
7485system state such as @command{useradd} or @command{grub-install}. In
7486fact, you must avoid that since that would not only void your warranty
7487but also prevent you from rolling back to previous versions of your
7488system, should you ever need to.
7489
7490@cindex roll-back, of the operating system
7491Speaking of roll-back, each time you run @command{guix system
7492reconfigure}, a new @dfn{generation} of the system is created---without
7493modifying or deleting previous generations. Old system generations get
7494an entry in the GRUB boot menu, allowing you to boot them in case
7495something went wrong with the latest generation. Reassuring, no? The
7496@command{guix system list-generations} command lists the system
067a2e2d
CM
7497generations available on disk. It is also possible to roll back the
7498system via the commands @command{guix system roll-back} and
7499@command{guix system switch-generation}.
7500
7501Although the command @command{guix system reconfigure} will not modify
7502previous generations, must take care when the current generation is not
7503the latest (e.g., after invoking @command{guix system roll-back}), since
7504the operation might overwrite a later generation (@pxref{Invoking guix
7505system}).
b81e1947 7506
5d94ac51
LC
7507@unnumberedsubsubsec The Programming Interface
7508
cf4a9129
LC
7509At the Scheme level, the bulk of an @code{operating-system} declaration
7510is instantiated with the following monadic procedure (@pxref{The Store
7511Monad}):
b81e1947 7512
cf4a9129
LC
7513@deffn {Monadic Procedure} operating-system-derivation os
7514Return a derivation that builds @var{os}, an @code{operating-system}
7515object (@pxref{Derivations}).
b81e1947 7516
cf4a9129
LC
7517The output of the derivation is a single directory that refers to all
7518the packages, configuration files, and other supporting files needed to
7519instantiate @var{os}.
7520@end deffn
b81e1947 7521
5d94ac51
LC
7522This procedure is provided by the @code{(gnu system)} module. Along
7523with @code{(gnu services)} (@pxref{Services}), this module contains the
7524guts of GuixSD. Make sure to visit it!
7525
7526
7313a52e
LC
7527@node operating-system Reference
7528@subsection @code{operating-system} Reference
7529
7530This section summarizes all the options available in
7531@code{operating-system} declarations (@pxref{Using the Configuration
7532System}).
7533
7534@deftp {Data Type} operating-system
7535This is the data type representing an operating system configuration.
7536By that, we mean all the global system configuration, not per-user
7537configuration (@pxref{Using the Configuration System}).
7538
7539@table @asis
7540@item @code{kernel} (default: @var{linux-libre})
fbb25e56 7541The package object of the operating system kernel to use@footnote{Currently
7313a52e
LC
7542only the Linux-libre kernel is supported. In the future, it will be
7543possible to use the GNU@tie{}Hurd.}.
7544
ee2a6304
LC
7545@item @code{kernel-arguments} (default: @code{'()})
7546List of strings or gexps representing additional arguments to pass on
1068f26b 7547the command-line of the kernel---e.g., @code{("console=ttyS0")}.
ee2a6304 7548
7313a52e 7549@item @code{bootloader}
88faf933 7550The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
7551
7552@item @code{initrd} (default: @code{base-initrd})
e32171ee
JD
7553@cindex initrd
7554@cindex initial RAM disk
7313a52e
LC
7555A two-argument monadic procedure that returns an initial RAM disk for
7556the Linux kernel. @xref{Initial RAM Disk}.
7557
f34c56be
LC
7558@item @code{firmware} (default: @var{%base-firmware})
7559@cindex firmware
7560List of firmware packages loadable by the operating system kernel.
7561
52db41af
EB
7562The default includes firmware needed for Atheros- and Broadcom-based
7563WiFi devices (Linux-libre modules @code{ath9k} and @code{b43-open},
7564respectively). @xref{Hardware Considerations}, for more info on
7565supported hardware.
f34c56be 7566
7313a52e
LC
7567@item @code{host-name}
7568The host name.
7569
7570@item @code{hosts-file}
7571@cindex hosts file
24e02c28 7572A file-like object (@pxref{G-Expressions, file-like objects}) for use as
7313a52e 7573@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
24e02c28 7574Reference Manual}). The default is a file with entries for
7313a52e
LC
7575@code{localhost} and @var{host-name}.
7576
7577@item @code{mapped-devices} (default: @code{'()})
7578A list of mapped devices. @xref{Mapped Devices}.
7579
7580@item @code{file-systems}
7581A list of file systems. @xref{File Systems}.
7582
7583@item @code{swap-devices} (default: @code{'()})
7584@cindex swap devices
a4ca4362
CM
7585A list of strings identifying devices or files to be used for ``swap
7586space'' (@pxref{Memory Concepts,,, libc, The GNU C Library Reference
7587Manual}). For example, @code{'("/dev/sda3")} or @code{'("/swapfile")}.
7588It is possible to specify a swap file in a file system on a mapped
7589device, provided that the necessary device mapping and file system are
7590also specified. @xref{Mapped Devices} and @ref{File Systems}.
7313a52e 7591
bf87f38a 7592@item @code{users} (default: @code{%base-user-accounts})
7313a52e
LC
7593@itemx @code{groups} (default: @var{%base-groups})
7594List of user accounts and groups. @xref{User Accounts}.
7595
7596@item @code{skeletons} (default: @code{(default-skeletons)})
e9dffec1
LC
7597A list target file name/file-like object tuples (@pxref{G-Expressions,
7598file-like objects}). These are the skeleton files that will be added to
7599the home directory of newly-created user accounts.
7313a52e
LC
7600
7601For instance, a valid value may look like this:
7602
7603@example
e9dffec1
LC
7604`((".bashrc" ,(plain-file "bashrc" "echo Hello\n"))
7605 (".guile" ,(plain-file "guile"
7606 "(use-modules (ice-9 readline))
7607 (activate-readline)")))
7313a52e
LC
7608@end example
7609
7610@item @code{issue} (default: @var{%default-issue})
7611A string denoting the contents of the @file{/etc/issue} file, which is
1068f26b 7612displayed when users log in on a text console.
7313a52e
LC
7613
7614@item @code{packages} (default: @var{%base-packages})
7615The set of packages installed in the global profile, which is accessible
7616at @file{/run/current-system/profile}.
7617
1068f26b 7618The default set includes core utilities and it is good practice to
7313a52e
LC
7619install non-core utilities in user profiles (@pxref{Invoking guix
7620package}).
7621
7622@item @code{timezone}
7623A timezone identifying string---e.g., @code{"Europe/Paris"}.
7624
17c20385
LC
7625You can run the @command{tzselect} command to find out which timezone
7626string corresponds to your region. Choosing an invalid timezone name
7627causes @command{guix system} to fail.
7628
598e19dc
LC
7629@item @code{locale} (default: @code{"en_US.utf8"})
7630The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
7631Library Reference Manual}). @xref{Locales}, for more information.
7632
7633@item @code{locale-definitions} (default: @var{%default-locale-definitions})
7634The list of locale definitions to be compiled and that may be used at
7635run time. @xref{Locales}.
7313a52e 7636
34760ae7
LC
7637@item @code{locale-libcs} (default: @code{(list @var{glibc})})
7638The list of GNU@tie{}libc packages whose locale data and tools are used
7639to build the locale definitions. @xref{Locales}, for compatibility
7640considerations that justify this option.
7641
996ed739 7642@item @code{name-service-switch} (default: @var{%default-nss})
1068f26b 7643Configuration of the libc name service switch (NSS)---a
996ed739
LC
7644@code{<name-service-switch>} object. @xref{Name Service Switch}, for
7645details.
7646
7313a52e 7647@item @code{services} (default: @var{%base-services})
28d939af 7648A list of service objects denoting system services. @xref{Services}.
7313a52e
LC
7649
7650@item @code{pam-services} (default: @code{(base-pam-services)})
7651@cindex PAM
7652@cindex pluggable authentication modules
7653Linux @dfn{pluggable authentication module} (PAM) services.
7654@c FIXME: Add xref to PAM services section.
7655
7656@item @code{setuid-programs} (default: @var{%setuid-programs})
7657List of string-valued G-expressions denoting setuid programs.
7658@xref{Setuid Programs}.
7659
f5a9ffa0
AK
7660@item @code{sudoers-file} (default: @var{%sudoers-specification})
7661@cindex sudoers file
84765839
LC
7662The contents of the @file{/etc/sudoers} file as a file-like object
7663(@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7313a52e
LC
7664
7665This file specifies which users can use the @command{sudo} command, what
7666they are allowed to do, and what privileges they may gain. The default
7667is that only @code{root} and members of the @code{wheel} group may use
7668@code{sudo}.
7669
7670@end table
7671@end deftp
7672
cf4a9129
LC
7673@node File Systems
7674@subsection File Systems
b81e1947 7675
cf4a9129 7676The list of file systems to be mounted is specified in the
1068f26b 7677@code{file-systems} field of the operating system declaration
cf4a9129
LC
7678(@pxref{Using the Configuration System}). Each file system is declared
7679using the @code{file-system} form, like this:
b81e1947
LC
7680
7681@example
cf4a9129
LC
7682(file-system
7683 (mount-point "/home")
7684 (device "/dev/sda3")
7685 (type "ext4"))
b81e1947
LC
7686@end example
7687
cf4a9129
LC
7688As usual, some of the fields are mandatory---those shown in the example
7689above---while others can be omitted. These are described below.
b81e1947 7690
cf4a9129
LC
7691@deftp {Data Type} file-system
7692Objects of this type represent file systems to be mounted. They
7693contain the following members:
5ff3c4b8 7694
cf4a9129
LC
7695@table @asis
7696@item @code{type}
7697This is a string specifying the type of the file system---e.g.,
7698@code{"ext4"}.
5ff3c4b8 7699
cf4a9129
LC
7700@item @code{mount-point}
7701This designates the place where the file system is to be mounted.
b81e1947 7702
cf4a9129
LC
7703@item @code{device}
7704This names the ``source'' of the file system. By default it is the name
7705of a node under @file{/dev}, but its meaning depends on the @code{title}
7706field described below.
401c53c4 7707
cf4a9129
LC
7708@item @code{title} (default: @code{'device})
7709This is a symbol that specifies how the @code{device} field is to be
7710interpreted.
401c53c4 7711
cf4a9129
LC
7712When it is the symbol @code{device}, then the @code{device} field is
7713interpreted as a file name; when it is @code{label}, then @code{device}
7714is interpreted as a partition label name; when it is @code{uuid},
7715@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 7716
661a1d79 7717UUIDs may be converted from their string representation (as shown by the
0767f6a6
LC
7718@command{tune2fs -l} command) using the @code{uuid} form@footnote{The
7719@code{uuid} form expects 16-byte UUIDs as defined in
7720@uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
7721form of UUID used by the ext2 family of file systems and others, but it
7722is different from ``UUIDs'' found in FAT file systems, for instance.},
7723like this:
661a1d79
LC
7724
7725@example
7726(file-system
7727 (mount-point "/home")
7728 (type "ext4")
7729 (title 'uuid)
7730 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
7731@end example
7732
cf4a9129 7733The @code{label} and @code{uuid} options offer a way to refer to disk
661a1d79
LC
7734partitions without having to hard-code their actual device
7735name@footnote{Note that, while it is tempting to use
7736@file{/dev/disk/by-uuid} and similar device names to achieve the same
7737result, this is not recommended: These special device nodes are created
7738by the udev daemon and may be unavailable at the time the device is
7739mounted.}.
da7cabd4 7740
1068f26b 7741However, when the source of a file system is a mapped device (@pxref{Mapped
5f86a66e
LC
7742Devices}), its @code{device} field @emph{must} refer to the mapped
7743device name---e.g., @file{/dev/mapper/root-partition}---and consequently
7744@code{title} must be set to @code{'device}. This is required so that
7745the system knows that mounting the file system depends on having the
7746corresponding device mapping established.
7747
cf4a9129
LC
7748@item @code{flags} (default: @code{'()})
7749This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
7750include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
7751access to special files), @code{no-suid} (ignore setuid and setgid
7752bits), and @code{no-exec} (disallow program execution.)
da7cabd4 7753
cf4a9129
LC
7754@item @code{options} (default: @code{#f})
7755This is either @code{#f}, or a string denoting mount options.
da7cabd4 7756
be21979d
LC
7757@item @code{mount?} (default: @code{#t})
7758This value indicates whether to automatically mount the file system when
7759the system is brought up. When set to @code{#f}, the file system gets
7760an entry in @file{/etc/fstab} (read by the @command{mount} command) but
7761is not automatically mounted.
7762
cf4a9129
LC
7763@item @code{needed-for-boot?} (default: @code{#f})
7764This Boolean value indicates whether the file system is needed when
7765booting. If that is true, then the file system is mounted when the
7766initial RAM disk (initrd) is loaded. This is always the case, for
7767instance, for the root file system.
da7cabd4 7768
cf4a9129
LC
7769@item @code{check?} (default: @code{#t})
7770This Boolean indicates whether the file system needs to be checked for
7771errors before being mounted.
f9cc8971 7772
4e469051
LC
7773@item @code{create-mount-point?} (default: @code{#f})
7774When true, the mount point is created if it does not exist yet.
7775
e51710d1 7776@item @code{dependencies} (default: @code{'()})
13fb1bd9
LC
7777This is a list of @code{<file-system>} or @code{<mapped-device>} objects
7778representing file systems that must be mounted or mapped devices that
7779must be opened before (and unmounted or closed after) this one.
e51710d1
LC
7780
7781As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
7782a dependency of @file{/sys/fs/cgroup/cpu} and
7783@file{/sys/fs/cgroup/memory}.
7784
13fb1bd9
LC
7785Another example is a file system that depends on a mapped device, for
7786example for an encrypted partition (@pxref{Mapped Devices}).
cf4a9129
LC
7787@end table
7788@end deftp
da7cabd4 7789
a69576ea
LC
7790The @code{(gnu system file-systems)} exports the following useful
7791variables.
7792
7793@defvr {Scheme Variable} %base-file-systems
7794These are essential file systems that are required on normal systems,
cc0e575a 7795such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
3392ce5d
LC
7796below.) Operating system declarations should always contain at least
7797these.
a69576ea
LC
7798@end defvr
7799
7f239fd3
LC
7800@defvr {Scheme Variable} %pseudo-terminal-file-system
7801This is the file system to be mounted as @file{/dev/pts}. It supports
7802@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
7803functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
7804Manual}). Pseudo-terminals are used by terminal emulators such as
7805@command{xterm}.
7806@end defvr
7807
db17ae5c
LC
7808@defvr {Scheme Variable} %shared-memory-file-system
7809This file system is mounted as @file{/dev/shm} and is used to support
7810memory sharing across processes (@pxref{Memory-mapped I/O,
7811@code{shm_open},, libc, The GNU C Library Reference Manual}).
7812@end defvr
7813
3392ce5d
LC
7814@defvr {Scheme Variable} %immutable-store
7815This file system performs a read-only ``bind mount'' of
7816@file{/gnu/store}, making it read-only for all the users including
7817@code{root}. This prevents against accidental modification by software
7818running as @code{root} or by system administrators.
7819
7820The daemon itself is still able to write to the store: it remounts it
7821read-write in its own ``name space.''
7822@end defvr
7823
a69576ea
LC
7824@defvr {Scheme Variable} %binary-format-file-system
7825The @code{binfmt_misc} file system, which allows handling of arbitrary
7826executable file types to be delegated to user space. This requires the
7827@code{binfmt.ko} kernel module to be loaded.
7828@end defvr
7829
7830@defvr {Scheme Variable} %fuse-control-file-system
7831The @code{fusectl} file system, which allows unprivileged users to mount
7832and unmount user-space FUSE file systems. This requires the
7833@code{fuse.ko} kernel module to be loaded.
7834@end defvr
7835
510f9d86
LC
7836@node Mapped Devices
7837@subsection Mapped Devices
7838
7839@cindex device mapping
7840@cindex mapped devices
7841The Linux kernel has a notion of @dfn{device mapping}: a block device,
7842such as a hard disk partition, can be @dfn{mapped} into another device,
97c8aef1 7843usually in @code{/dev/mapper/},
510f9d86
LC
7844with additional processing over the data that flows through
7845it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
7846concept of a ``mapped device'' and that of a file system: both boil down
7847to @emph{translating} input/output operations made on a file to
7848operations on its backing store. Thus, the Hurd implements mapped
7849devices, like file systems, using the generic @dfn{translator} mechanism
7850(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
7851typical example is encryption device mapping: all writes to the mapped
7852device are encrypted, and all reads are deciphered, transparently.
97c8aef1
AE
7853Guix extends this notion by considering any device or set of devices that
7854are @dfn{transformed} in some way to create a new device; for instance,
7855RAID devices are obtained by @dfn{assembling} several other devices, such
7856as hard disks or partitions, into a new one that behaves as one partition.
7857Other examples, not yet implemented, are LVM logical volumes.
510f9d86 7858
97c8aef1
AE
7859Mapped devices are declared using the @code{mapped-device} form,
7860defined as follows; for examples, see below.
510f9d86
LC
7861
7862@deftp {Data Type} mapped-device
7863Objects of this type represent device mappings that will be made when
7864the system boots up.
7865
9cb426b8
LC
7866@table @code
7867@item source
97c8aef1
AE
7868This is either a string specifying the name of the block device to be mapped,
7869such as @code{"/dev/sda3"}, or a list of such strings when several devices
7870need to be assembled for creating a new one.
510f9d86 7871
9cb426b8 7872@item target
97c8aef1
AE
7873This string specifies the name of the resulting mapped device. For
7874kernel mappers such as encrypted devices of type @code{luks-device-mapping},
7875specifying @code{"my-partition"} leads to the creation of
510f9d86 7876the @code{"/dev/mapper/my-partition"} device.
97c8aef1
AE
7877For RAID devices of type @code{raid-device-mapping}, the full device name
7878such as @code{"/dev/md0"} needs to be given.
510f9d86 7879
9cb426b8 7880@item type
510f9d86
LC
7881This must be a @code{mapped-device-kind} object, which specifies how
7882@var{source} is mapped to @var{target}.
7883@end table
7884@end deftp
7885
7886@defvr {Scheme Variable} luks-device-mapping
7887This defines LUKS block device encryption using the @command{cryptsetup}
1068f26b 7888command from the package with the same name. It relies on the
510f9d86
LC
7889@code{dm-crypt} Linux kernel module.
7890@end defvr
7891
97c8aef1
AE
7892@defvr {Scheme Variable} raid-device-mapping
7893This defines a RAID device, which is assembled using the @code{mdadm}
7894command from the package with the same name. It requires a Linux kernel
7895module for the appropriate RAID level to be loaded, such as @code{raid456}
7896for RAID-4, RAID-5 or RAID-6, or @code{raid10} for RAID-10.
7897@end defvr
7898
7899@cindex disk encryption
7900@cindex LUKS
7901The following example specifies a mapping from @file{/dev/sda3} to
7902@file{/dev/mapper/home} using LUKS---the
ddf1cd51 7903@url{https://gitlab.com/cryptsetup/cryptsetup,Linux Unified Key Setup}, a
97c8aef1
AE
7904standard mechanism for disk encryption.
7905The @file{/dev/mapper/home}
7906device can then be used as the @code{device} of a @code{file-system}
7907declaration (@pxref{File Systems}).
7908
7909@example
7910(mapped-device
7911 (source "/dev/sda3")
7912 (target "home")
7913 (type luks-device-mapping))
7914@end example
7915
7916Alternatively, to become independent of device numbering, one may obtain
7917the LUKS UUID (@dfn{unique identifier}) of the source device by a
7918command like:
7919
7920@example
7921cryptsetup luksUUID /dev/sda3
7922@end example
7923
7924and use it as follows:
7925
7926@example
7927(mapped-device
7928 (source (uuid "cb67fc72-0d54-4c88-9d4b-b225f30b0f44"))
7929 (target "home")
7930 (type luks-device-mapping))
7931@end example
7932
a4ca4362
CM
7933@cindex swap encryption
7934It is also desirable to encrypt swap space, since swap space may contain
7935sensitive data. One way to accomplish that is to use a swap file in a
7936file system on a device mapped via LUKS encryption. In this way, the
7937swap file is encrypted because the entire device is encrypted.
7938@xref{Preparing for Installation,,Disk Partitioning}, for an example.
7939
97c8aef1
AE
7940A RAID device formed of the partitions @file{/dev/sda1} and @file{/dev/sdb1}
7941may be declared as follows:
7942
7943@example
7944(mapped-device
7945 (source (list "/dev/sda1" "/dev/sdb1"))
7946 (target "/dev/md0")
7947 (type raid-device-mapping))
7948@end example
7949
7950The @file{/dev/md0} device can then be used as the @code{device} of a
7951@code{file-system} declaration (@pxref{File Systems}).
7952Note that the RAID level need not be given; it is chosen during the
7953initial creation and formatting of the RAID device and is determined
7954automatically later.
7955
7956
cf4a9129
LC
7957@node User Accounts
7958@subsection User Accounts
ee85f3db 7959
e32171ee
JD
7960@cindex users
7961@cindex accounts
7962@cindex user accounts
9bea87a5
LC
7963User accounts and groups are entirely managed through the
7964@code{operating-system} declaration. They are specified with the
7965@code{user-account} and @code{user-group} forms:
ee85f3db 7966
cf4a9129
LC
7967@example
7968(user-account
7969 (name "alice")
7970 (group "users")
24e752c0
LC
7971 (supplementary-groups '("wheel" ;allow use of sudo, etc.
7972 "audio" ;sound card
7973 "video" ;video devices such as webcams
7974 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
7975 (comment "Bob's sister")
7976 (home-directory "/home/alice"))
7977@end example
25083588 7978
9bea87a5
LC
7979When booting or upon completion of @command{guix system reconfigure},
7980the system ensures that only the user accounts and groups specified in
7981the @code{operating-system} declaration exist, and with the specified
7982properties. Thus, account or group creations or modifications made by
7983directly invoking commands such as @command{useradd} are lost upon
7984reconfiguration or reboot. This ensures that the system remains exactly
7985as declared.
7986
cf4a9129
LC
7987@deftp {Data Type} user-account
7988Objects of this type represent user accounts. The following members may
7989be specified:
ee85f3db 7990
cf4a9129
LC
7991@table @asis
7992@item @code{name}
7993The name of the user account.
ee85f3db 7994
cf4a9129 7995@item @code{group}
e32171ee 7996@cindex groups
cf4a9129
LC
7997This is the name (a string) or identifier (a number) of the user group
7998this account belongs to.
ee85f3db 7999
cf4a9129
LC
8000@item @code{supplementary-groups} (default: @code{'()})
8001Optionally, this can be defined as a list of group names that this
8002account belongs to.
ee85f3db 8003
cf4a9129
LC
8004@item @code{uid} (default: @code{#f})
8005This is the user ID for this account (a number), or @code{#f}. In the
8006latter case, a number is automatically chosen by the system when the
8007account is created.
ee85f3db 8008
cf4a9129 8009@item @code{comment} (default: @code{""})
1068f26b 8010A comment about the account, such as the account owner's full name.
c8c871d1 8011
cf4a9129
LC
8012@item @code{home-directory}
8013This is the name of the home directory for the account.
ee85f3db 8014
eb56ee02
LC
8015@item @code{create-home-directory?} (default: @code{#t})
8016Indicates whether the home directory of this account should be created
8017if it does not exist yet.
8018
cf4a9129
LC
8019@item @code{shell} (default: Bash)
8020This is a G-expression denoting the file name of a program to be used as
8021the shell (@pxref{G-Expressions}).
ee85f3db 8022
cf4a9129
LC
8023@item @code{system?} (default: @code{#f})
8024This Boolean value indicates whether the account is a ``system''
8025account. System accounts are sometimes treated specially; for instance,
8026graphical login managers do not list them.
ee85f3db 8027
1bd4e6db 8028@anchor{user-account-password}
cf4a9129 8029@item @code{password} (default: @code{#f})
eb59595c
LC
8030You would normally leave this field to @code{#f}, initialize user
8031passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
8032users change it with @command{passwd}. Passwords set with
8033@command{passwd} are of course preserved across reboot and
8034reconfiguration.
eb59595c
LC
8035
8036If you @emph{do} want to have a preset password for an account, then
8037this field must contain the encrypted password, as a string.
5d1f1177
LC
8038@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
8039on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 8040Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 8041
cf4a9129
LC
8042@end table
8043@end deftp
ee85f3db 8044
e32171ee 8045@cindex groups
cf4a9129 8046User group declarations are even simpler:
ee85f3db 8047
cf4a9129
LC
8048@example
8049(user-group (name "students"))
8050@end example
ee85f3db 8051
cf4a9129
LC
8052@deftp {Data Type} user-group
8053This type is for, well, user groups. There are just a few fields:
af8a56b8 8054
cf4a9129
LC
8055@table @asis
8056@item @code{name}
1068f26b 8057The name of the group.
ee85f3db 8058
cf4a9129
LC
8059@item @code{id} (default: @code{#f})
8060The group identifier (a number). If @code{#f}, a new number is
8061automatically allocated when the group is created.
ee85f3db 8062
c8fa3426
LC
8063@item @code{system?} (default: @code{#f})
8064This Boolean value indicates whether the group is a ``system'' group.
8065System groups have low numerical IDs.
8066
cf4a9129
LC
8067@item @code{password} (default: @code{#f})
8068What, user groups can have a password? Well, apparently yes. Unless
1068f26b 8069@code{#f}, this field specifies the password of the group.
ee85f3db 8070
cf4a9129
LC
8071@end table
8072@end deftp
401c53c4 8073
cf4a9129
LC
8074For convenience, a variable lists all the basic user groups one may
8075expect:
401c53c4 8076
cf4a9129
LC
8077@defvr {Scheme Variable} %base-groups
8078This is the list of basic user groups that users and/or packages expect
8079to be present on the system. This includes groups such as ``root'',
8080``wheel'', and ``users'', as well as groups used to control access to
8081specific devices such as ``audio'', ``disk'', and ``cdrom''.
8082@end defvr
401c53c4 8083
bf87f38a
LC
8084@defvr {Scheme Variable} %base-user-accounts
8085This is the list of basic system accounts that programs may expect to
8086find on a GNU/Linux system, such as the ``nobody'' account.
8087
8088Note that the ``root'' account is not included here. It is a
8089special-case and is automatically added whether or not it is specified.
8090@end defvr
8091
598e19dc
LC
8092@node Locales
8093@subsection Locales
8094
8095@cindex locale
8096A @dfn{locale} defines cultural conventions for a particular language
8097and region of the world (@pxref{Locales,,, libc, The GNU C Library
8098Reference Manual}). Each locale has a name that typically has the form
b2636518 8099@code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
598e19dc
LC
8100@code{fr_LU.utf8} designates the locale for the French language, with
8101cultural conventions from Luxembourg, and using the UTF-8 encoding.
8102
8103@cindex locale definition
8104Usually, you will want to specify the default locale for the machine
8105using the @code{locale} field of the @code{operating-system} declaration
8106(@pxref{operating-system Reference, @code{locale}}).
8107
f5582b2c
LC
8108The selected locale is automatically added to the @dfn{locale
8109definitions} known to the system if needed, with its codeset inferred
8110from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
8111@code{UTF-8} codeset. Additional locale definitions can be specified in
8112the @code{locale-definitions} slot of @code{operating-system}---this is
8113useful, for instance, if the codeset could not be inferred from the
8114locale name. The default set of locale definitions includes some widely
8115used locales, but not all the available locales, in order to save space.
8116
8117For instance, to add the North Frisian locale for Germany, the value of
8118that field may be:
598e19dc
LC
8119
8120@example
8121(cons (locale-definition
8122 (name "fy_DE.utf8") (source "fy_DE"))
8123 %default-locale-definitions)
8124@end example
8125
8126Likewise, to save space, one might want @code{locale-definitions} to
8127list only the locales that are actually used, as in:
8128
8129@example
8130(list (locale-definition
8131 (name "ja_JP.eucjp") (source "ja_JP")
8132 (charset "EUC-JP")))
8133@end example
8134
5c3c1427
LC
8135@vindex LOCPATH
8136The compiled locale definitions are available at
46bd6edd
LC
8137@file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
8138version, which is the default location where the GNU@tie{}libc provided
8139by Guix looks for locale data. This can be overridden using the
8140@code{LOCPATH} environment variable (@pxref{locales-and-locpath,
5c3c1427
LC
8141@code{LOCPATH} and locale packages}).
8142
598e19dc
LC
8143The @code{locale-definition} form is provided by the @code{(gnu system
8144locale)} module. Details are given below.
8145
8146@deftp {Data Type} locale-definition
8147This is the data type of a locale definition.
8148
8149@table @asis
8150
8151@item @code{name}
8152The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
8153Reference Manual}, for more information on locale names.
8154
8155@item @code{source}
8156The name of the source for that locale. This is typically the
8157@code{@var{language}_@var{territory}} part of the locale name.
8158
8159@item @code{charset} (default: @code{"UTF-8"})
8160The ``character set'' or ``code set'' for that locale,
8161@uref{http://www.iana.org/assignments/character-sets, as defined by
8162IANA}.
8163
8164@end table
8165@end deftp
8166
8167@defvr {Scheme Variable} %default-locale-definitions
1068f26b 8168A list of commonly used UTF-8 locales, used as the default
b2636518 8169value of the @code{locale-definitions} field of @code{operating-system}
598e19dc 8170declarations.
b2636518
LC
8171
8172@cindex locale name
8173@cindex normalized codeset in locale names
8174These locale definitions use the @dfn{normalized codeset} for the part
8175that follows the dot in the name (@pxref{Using gettextized software,
8176normalized codeset,, libc, The GNU C Library Reference Manual}). So for
8177instance it has @code{uk_UA.utf8} but @emph{not}, say,
8178@code{uk_UA.UTF-8}.
598e19dc 8179@end defvr
401c53c4 8180
34760ae7
LC
8181@subsubsection Locale Data Compatibility Considerations
8182
8183@cindex incompatibility, of locale data
8184@code{operating-system} declarations provide a @code{locale-libcs} field
8185to specify the GNU@tie{}libc packages that are used to compile locale
8186declarations (@pxref{operating-system Reference}). ``Why would I
8187care?'', you may ask. Well, it turns out that the binary format of
8188locale data is occasionally incompatible from one libc version to
8189another.
8190
8191@c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
8192@c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
8193For instance, a program linked against libc version 2.21 is unable to
8194read locale data produced with libc 2.22; worse, that program
8195@emph{aborts} instead of simply ignoring the incompatible locale
8196data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
8197the incompatible locale data, which is already an improvement.}.
8198Similarly, a program linked against libc 2.22 can read most, but not
201fff9e 8199all, of the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
34760ae7
LC
8200data is incompatible); thus calls to @code{setlocale} may fail, but
8201programs will not abort.
8202
8203The ``problem'' in GuixSD is that users have a lot of freedom: They can
8204choose whether and when to upgrade software in their profiles, and might
8205be using a libc version different from the one the system administrator
8206used to build the system-wide locale data.
8207
8208Fortunately, unprivileged users can also install their own locale data
8209and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
8210@code{GUIX_LOCPATH} and locale packages}).
8211
8212Still, it is best if the system-wide locale data at
8213@file{/run/current-system/locale} is built for all the libc versions
8214actually in use on the system, so that all the programs can access
8215it---this is especially crucial on a multi-user system. To do that, the
8216administrator can specify several libc packages in the
8217@code{locale-libcs} field of @code{operating-system}:
8218
8219@example
8220(use-package-modules base)
8221
8222(operating-system
8223 ;; @dots{}
8224 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
8225@end example
8226
8227This example would lead to a system containing locale definitions for
8228both libc 2.21 and the current version of libc in
8229@file{/run/current-system/locale}.
8230
8231
cf4a9129
LC
8232@node Services
8233@subsection Services
401c53c4 8234
cf4a9129
LC
8235@cindex system services
8236An important part of preparing an @code{operating-system} declaration is
8237listing @dfn{system services} and their configuration (@pxref{Using the
8238Configuration System}). System services are typically daemons launched
8239when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
8240configuring network access.
8241
e8b652d4
LC
8242GuixSD has a broad definition of ``service'' (@pxref{Service
8243Composition}), but many services are managed by the GNU@tie{}Shepherd
8244(@pxref{Shepherd Services}). On a running system, the @command{herd}
8245command allows you to list the available services, show their status,
8246start and stop them, or do other specific operations (@pxref{Jump
8247Start,,, shepherd, The GNU Shepherd Manual}). For example:
d8b94dbd
LC
8248
8249@example
dd17bc38 8250# herd status
d8b94dbd
LC
8251@end example
8252
8253The above command, run as @code{root}, lists the currently defined
dd17bc38 8254services. The @command{herd doc} command shows a synopsis of the given
d8b94dbd
LC
8255service:
8256
8257@example
dd17bc38 8258# herd doc nscd
d8b94dbd
LC
8259Run libc's name service cache daemon (nscd).
8260@end example
8261
8262The @command{start}, @command{stop}, and @command{restart} sub-commands
8263have the effect you would expect. For instance, the commands below stop
8264the nscd service and restart the Xorg display server:
8265
8266@example
dd17bc38 8267# herd stop nscd
d8b94dbd 8268Service nscd has been stopped.
dd17bc38 8269# herd restart xorg-server
d8b94dbd
LC
8270Service xorg-server has been stopped.
8271Service xorg-server has been started.
8272@end example
401c53c4 8273
cf4a9129 8274The following sections document the available services, starting with
d8b94dbd
LC
8275the core services, that may be used in an @code{operating-system}
8276declaration.
401c53c4 8277
cf4a9129
LC
8278@menu
8279* Base Services:: Essential system services.
c311089b 8280* Scheduled Job Execution:: The mcron service.
92c03a87 8281* Log Rotation:: The rottlog service.
cf4a9129
LC
8282* Networking Services:: Network setup, SSH daemon, etc.
8283* X Window:: Graphical display.
f2ec23d1 8284* Printing Services:: Local and remote printer support.
fe1a39d3 8285* Desktop Services:: D-Bus and desktop services.
105369a4 8286* Database Services:: SQL databases.
d8c18af8 8287* Mail Services:: IMAP, POP3, SMTP, and all that.
78cef99b 8288* Messaging Services:: Messaging services.
859e367d 8289* Kerberos Services:: Kerberos services.
58724c48 8290* Web Services:: Web servers.
2be1b471 8291* VPN Services:: VPN daemons.
eb419bc9 8292* Network File System:: NFS related services.
a7cf4eb6 8293* Continuous Integration:: The Cuirass service.
dbc6d370 8294* Miscellaneous Services:: Other services.
cf4a9129 8295@end menu
401c53c4 8296
cf4a9129
LC
8297@node Base Services
8298@subsubsection Base Services
a1ba8475 8299
cf4a9129
LC
8300The @code{(gnu services base)} module provides definitions for the basic
8301services that one expects from the system. The services exported by
8302this module are listed below.
401c53c4 8303
cf4a9129 8304@defvr {Scheme Variable} %base-services
31771497
LC
8305This variable contains a list of basic services (@pxref{Service Types
8306and Services}, for more information on service objects) one would
cf4a9129 8307expect from the system: a login service (mingetty) on each tty, syslogd,
1068f26b 8308the libc name service cache daemon (nscd), the udev device manager, and
cf4a9129 8309more.
401c53c4 8310
cf4a9129
LC
8311This is the default value of the @code{services} field of
8312@code{operating-system} declarations. Usually, when customizing a
8313system, you will want to append services to @var{%base-services}, like
8314this:
401c53c4 8315
cf4a9129 8316@example
fa1e31b8 8317(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
8318@end example
8319@end defvr
401c53c4 8320
387e1754
LC
8321@defvr {Scheme Variable} special-files-service-type
8322This is the service that sets up ``special files'' such as
8323@file{/bin/sh}; an instance of it is part of @code{%base-services}.
8324
8325The value associated with @code{special-files-service-type} services
8326must be a list of tuples where the first element is the ``special file''
8327and the second element is its target. By default it is:
8328
8329@cindex @file{/bin/sh}
8330@cindex @file{sh}, in @file{/bin}
8331@example
8332`(("/bin/sh" ,(file-append @var{bash} "/bin/sh")))
8333@end example
8334
8335@cindex @file{/usr/bin/env}
8336@cindex @file{env}, in @file{/usr/bin}
8337If you want to add, say, @code{/usr/bin/env} to your system, you can
8338change it to:
8339
8340@example
8341`(("/bin/sh" ,(file-append @var{bash} "/bin/sh"))
8342 ("/usr/bin/env" ,(file-append @var{coreutils} "/bin/env")))
8343@end example
8344
8345Since this is part of @code{%base-services}, you can use
8346@code{modify-services} to customize the set of special files
8347(@pxref{Service Reference, @code{modify-services}}). But the simple way
8348to add a special file is @i{via} the @code{extra-special-file} procedure
8349(see below.)
8350@end defvr
8351
8352@deffn {Scheme Procedure} extra-special-file @var{file} @var{target}
8353Use @var{target} as the ``special file'' @var{file}.
8354
8355For example, adding the following lines to the @code{services} field of
8356your operating system declaration leads to a @file{/usr/bin/env}
8357symlink:
8358
8359@example
8360(extra-special-file "/usr/bin/env"
8361 (file-append coreutils "/bin/env"))
8362@end example
8363@end deffn
8364
be1c2c54 8365@deffn {Scheme Procedure} host-name-service @var{name}
cf4a9129
LC
8366Return a service that sets the host name to @var{name}.
8367@end deffn
401c53c4 8368
317d3b47
DC
8369@deffn {Scheme Procedure} login-service @var{config}
8370Return a service to run login according to @var{config}, a
8371@code{<login-configuration>} object, which specifies the message of the day,
8372among other things.
8373@end deffn
8374
8375@deftp {Data Type} login-configuration
8376This is the data type representing the configuration of login.
8377
8378@table @asis
8379
8380@item @code{motd}
e32171ee 8381@cindex message of the day
317d3b47
DC
8382A file-like object containing the ``message of the day''.
8383
8384@item @code{allow-empty-passwords?} (default: @code{#t})
8385Allow empty passwords by default so that first-time users can log in when
8386the 'root' account has just been created.
8387
8388@end table
8389@end deftp
8390
66e4f01c
LC
8391@deffn {Scheme Procedure} mingetty-service @var{config}
8392Return a service to run mingetty according to @var{config}, a
8393@code{<mingetty-configuration>} object, which specifies the tty to run, among
8394other things.
cf4a9129 8395@end deffn
401c53c4 8396
66e4f01c
LC
8397@deftp {Data Type} mingetty-configuration
8398This is the data type representing the configuration of Mingetty, which
8399implements console log-in.
8400
8401@table @asis
8402
8403@item @code{tty}
8404The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
8405
66e4f01c
LC
8406@item @code{auto-login} (default: @code{#f})
8407When true, this field must be a string denoting the user name under
f9b9a033 8408which the system automatically logs in. When it is @code{#f}, a
66e4f01c
LC
8409user name and password must be entered to log in.
8410
8411@item @code{login-program} (default: @code{#f})
8412This must be either @code{#f}, in which case the default log-in program
8413is used (@command{login} from the Shadow tool suite), or a gexp denoting
8414the name of the log-in program.
8415
8416@item @code{login-pause?} (default: @code{#f})
8417When set to @code{#t} in conjunction with @var{auto-login}, the user
8418will have to press a key before the log-in shell is launched.
8419
8420@item @code{mingetty} (default: @var{mingetty})
8421The Mingetty package to use.
8422
8423@end table
8424@end deftp
8425
46ec2707
DC
8426@deffn {Scheme Procedure} kmscon-service-type @var{config}
8427Return a service to run @uref{https://www.freedesktop.org/wiki/Software/kmscon,kmscon}
8428according to @var{config}, a @code{<kmscon-configuration>} object, which
8429specifies the tty to run, among other things.
8430@end deffn
8431
8432@deftp {Data Type} kmscon-configuration
8433This is the data type representing the configuration of Kmscon, which
8434implements console log-in.
8435
8436@table @asis
8437
8438@item @code{virtual-terminal}
8439The name of the console this Kmscon runs on---e.g., @code{"tty1"}.
8440
8441@item @code{login-program} (default: @code{#~(string-append #$shadow "/bin/login")})
8442A gexp denoting the name of the log-in program. The default log-in program is
8443@command{login} from the Shadow tool suite.
8444
8445@item @code{login-arguments} (default: @code{'("-p")})
8446A list of arguments to pass to @command{login}.
8447
8448@item @code{hardware-acceleration?} (default: #f)
8449Whether to use hardware acceleration.
8450
8451@item @code{kmscon} (default: @var{kmscon})
8452The Kmscon package to use.
8453
8454@end table
8455@end deftp
8456
6454b333
LC
8457@cindex name service cache daemon
8458@cindex nscd
be1c2c54 8459@deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
4aee6e60 8460 [#:name-services '()]
1068f26b 8461Return a service that runs the libc name service cache daemon (nscd) with the
b893f1ae
LC
8462given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
8463Service Switch}, for an example.
cf4a9129 8464@end deffn
401c53c4 8465
6454b333
LC
8466@defvr {Scheme Variable} %nscd-default-configuration
8467This is the default @code{<nscd-configuration>} value (see below) used
1068f26b 8468by @code{nscd-service}. It uses the caches defined by
6454b333
LC
8469@var{%nscd-default-caches}; see below.
8470@end defvr
8471
8472@deftp {Data Type} nscd-configuration
1068f26b 8473This is the data type representing the name service cache daemon (nscd)
6454b333
LC
8474configuration.
8475
8476@table @asis
8477
b893f1ae
LC
8478@item @code{name-services} (default: @code{'()})
8479List of packages denoting @dfn{name services} that must be visible to
8480the nscd---e.g., @code{(list @var{nss-mdns})}.
8481
8482@item @code{glibc} (default: @var{glibc})
8483Package object denoting the GNU C Library providing the @command{nscd}
8484command.
8485
6454b333 8486@item @code{log-file} (default: @code{"/var/log/nscd.log"})
1068f26b 8487Name of the nscd log file. This is where debugging output goes when
6454b333
LC
8488@code{debug-level} is strictly positive.
8489
8490@item @code{debug-level} (default: @code{0})
1068f26b 8491Integer denoting the debugging levels. Higher numbers mean that more
6454b333
LC
8492debugging output is logged.
8493
8494@item @code{caches} (default: @var{%nscd-default-caches})
8495List of @code{<nscd-cache>} objects denoting things to be cached; see
8496below.
8497
8498@end table
8499@end deftp
8500
8501@deftp {Data Type} nscd-cache
8502Data type representing a cache database of nscd and its parameters.
8503
8504@table @asis
8505
8506@item @code{database}
8507This is a symbol representing the name of the database to be cached.
8508Valid values are @code{passwd}, @code{group}, @code{hosts}, and
8509@code{services}, which designate the corresponding NSS database
8510(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
8511
8512@item @code{positive-time-to-live}
8513@itemx @code{negative-time-to-live} (default: @code{20})
8514A number representing the number of seconds during which a positive or
8515negative lookup result remains in cache.
8516
8517@item @code{check-files?} (default: @code{#t})
8518Whether to check for updates of the files corresponding to
8519@var{database}.
8520
8521For instance, when @var{database} is @code{hosts}, setting this flag
8522instructs nscd to check for updates in @file{/etc/hosts} and to take
8523them into account.
8524
8525@item @code{persistent?} (default: @code{#t})
8526Whether the cache should be stored persistently on disk.
8527
8528@item @code{shared?} (default: @code{#t})
8529Whether the cache should be shared among users.
8530
8531@item @code{max-database-size} (default: 32@tie{}MiB)
8532Maximum size in bytes of the database cache.
8533
8534@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
8535@c settings, so leave them out.
8536
8537@end table
8538@end deftp
8539
8540@defvr {Scheme Variable} %nscd-default-caches
8541List of @code{<nscd-cache>} objects used by default by
1068f26b 8542@code{nscd-configuration} (see above).
6454b333
LC
8543
8544It enables persistent and aggressive caching of service and host name
8545lookups. The latter provides better host name lookup performance,
8546resilience in the face of unreliable name servers, and also better
8547privacy---often the result of host name lookups is in local cache, so
8548external name servers do not even need to be queried.
8549@end defvr
8550
ec2e2f6c 8551@anchor{syslog-configuration-type}
e32171ee
JD
8552@cindex syslog
8553@cindex logging
ec2e2f6c
DC
8554@deftp {Data Type} syslog-configuration
8555This data type represents the configuration of the syslog daemon.
6454b333 8556
ec2e2f6c
DC
8557@table @asis
8558@item @code{syslogd} (default: @code{#~(string-append #$inetutils "/libexec/syslogd")})
8559The syslog daemon to use.
8560
8561@item @code{config-file} (default: @code{%default-syslog.conf})
8562The syslog configuration file to use.
8563
8564@end table
8565@end deftp
8566
8567@anchor{syslog-service}
e32171ee 8568@cindex syslog
ec2e2f6c
DC
8569@deffn {Scheme Procedure} syslog-service @var{config}
8570Return a service that runs a syslog daemon according to @var{config}.
44abcb28
LC
8571
8572@xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
8573information on the configuration file syntax.
cf4a9129 8574@end deffn
401c53c4 8575
0adfe95a
LC
8576@anchor{guix-configuration-type}
8577@deftp {Data Type} guix-configuration
8578This data type represents the configuration of the Guix build daemon.
8579@xref{Invoking guix-daemon}, for more information.
8580
8581@table @asis
8582@item @code{guix} (default: @var{guix})
8583The Guix package to use.
401c53c4 8584
0adfe95a
LC
8585@item @code{build-group} (default: @code{"guixbuild"})
8586Name of the group for build user accounts.
401c53c4 8587
0adfe95a
LC
8588@item @code{build-accounts} (default: @code{10})
8589Number of build user accounts to create.
401c53c4 8590
0adfe95a 8591@item @code{authorize-key?} (default: @code{#t})
e32171ee 8592@cindex substitutes, authorization thereof
5b58c28b
LC
8593Whether to authorize the substitute keys listed in
8594@code{authorized-keys}---by default that of @code{hydra.gnu.org}
0adfe95a
LC
8595(@pxref{Substitutes}).
8596
5b58c28b
LC
8597@vindex %default-authorized-guix-keys
8598@item @code{authorized-keys} (default: @var{%default-authorized-guix-keys})
8599The list of authorized key files for archive imports, as a list of
8600string-valued gexps (@pxref{Invoking guix archive}). By default, it
8601contains that of @code{hydra.gnu.org} (@pxref{Substitutes}).
8602
0adfe95a
LC
8603@item @code{use-substitutes?} (default: @code{#t})
8604Whether to use substitutes.
8605
b0b9f6e0
LC
8606@item @code{substitute-urls} (default: @var{%default-substitute-urls})
8607The list of URLs where to look for substitutes by default.
8608
0adfe95a
LC
8609@item @code{extra-options} (default: @code{'()})
8610List of extra command-line options for @command{guix-daemon}.
8611
dc0ef095
LC
8612@item @code{log-file} (default: @code{"/var/log/guix-daemon.log"})
8613File where @command{guix-daemon}'s standard output and standard error
8614are written.
8615
0adfe95a 8616@item @code{lsof} (default: @var{lsof})
f78903f3 8617The lsof package to use.
0adfe95a
LC
8618
8619@end table
8620@end deftp
8621
8622@deffn {Scheme Procedure} guix-service @var{config}
8623Return a service that runs the Guix build daemon according to
8624@var{config}.
cf4a9129 8625@end deffn
a1ba8475 8626
be1c2c54 8627@deffn {Scheme Procedure} udev-service [#:udev udev]
cf4a9129
LC
8628Run @var{udev}, which populates the @file{/dev} directory dynamically.
8629@end deffn
401c53c4 8630
a535e122
LF
8631@deffn {Scheme Procedure} urandom-seed-service @var{#f}
8632Save some entropy in @var{%random-seed-file} to seed @file{/dev/urandom}
8633when rebooting.
8634@end deffn
8635
8636@defvr {Scheme Variable} %random-seed-file
8637This is the name of the file where some random bytes are saved by
8638@var{urandom-seed-service} to seed @file{/dev/urandom} when rebooting.
8639It defaults to @file{/var/lib/random-seed}.
8640@end defvr
8641
e32171ee
JD
8642@cindex keymap
8643@cindex keyboard
b3d05f48 8644@deffn {Scheme Procedure} console-keymap-service @var{files} ...
dedb8d5e 8645@cindex keyboard layout
b3d05f48
AK
8646Return a service to load console keymaps from @var{files} using
8647@command{loadkeys} command. Most likely, you want to load some default
8648keymap, which can be done like this:
8649
8650@example
8651(console-keymap-service "dvorak")
8652@end example
8653
8654Or, for example, for a Swedish keyboard, you may need to combine
8655the following keymaps:
8656@example
8657(console-keymap-service "se-lat6" "se-fi-lat6")
8658@end example
8659
8660Also you can specify a full file name (or file names) of your keymap(s).
8661See @code{man loadkeys} for details.
8662
5eca9459
AK
8663@end deffn
8664
e32171ee
JD
8665@cindex mouse
8666@cindex gpm
1aaf116d 8667@deffn {Scheme Procedure} gpm-service [#:gpm @var{gpm}] @
8664cc88
LC
8668 [#:options]
8669Run @var{gpm}, the general-purpose mouse daemon, with the given
8670command-line @var{options}. GPM allows users to use the mouse in the console,
8671notably to select, copy, and paste text. The default value of @var{options}
8672uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
8673
8674This service is not part of @var{%base-services}.
8675@end deffn
8676
1c52181f
LC
8677@anchor{guix-publish-service}
8678@deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
8679 [#:port 80] [#:host "localhost"]
8680Return a service that runs @command{guix publish} listening on @var{host}
8681and @var{port} (@pxref{Invoking guix publish}).
8682
8683This assumes that @file{/etc/guix} already contains a signing key pair as
8684created by @command{guix archive --generate-key} (@pxref{Invoking guix
8685archive}). If that is not the case, the service will fail to start.
8686@end deffn
8687
b58cbf9a
DC
8688@anchor{rngd-service}
8689@deffn {Scheme Procedure} rngd-service [#:rng-tools @var{rng-tools}] @
8690 [#:device "/dev/hwrng"]
8691Return a service that runs the @command{rngd} program from @var{rng-tools}
8692to add @var{device} to the kernel's entropy pool. The service will fail if
8693@var{device} does not exist.
8694@end deffn
a69576ea 8695
909147e4
RW
8696@anchor{pam-limits-service}
8697@cindex session limits
8698@cindex ulimit
8699@cindex priority
8700@deffn {Scheme Procedure} pam-limits-service [#:limits @var{limits}]
8701
8702Return a service that installs a configuration file for the
8703@uref{http://linux-pam.org/Linux-PAM-html/sag-pam_limits.html,
8704@code{pam_limits} module}. The procedure optionally takes a list of
8705@code{pam-limits-entry} values, which can be used to specify
8706@code{ulimit} limits and nice priority limits to user sessions.
8707
8708The following limits definition sets two hard and soft limits for all
8709login sessions of users in the @code{realtime} group:
8710
8711@example
8712(pam-limits-service
8713 (list
8714 (pam-limits-entry "@@realtime" 'both 'rtprio 99)
8715 (pam-limits-entry "@@realtime" 'both 'memlock 'unlimited)))
8716@end example
8717
8718The first entry increases the maximum realtime priority for
8719non-privileged processes; the second entry lifts any restriction of the
8720maximum address space that can be locked in memory. These settings are
8721commonly used for real-time audio systems.
8722@end deffn
8723
c311089b
LC
8724@node Scheduled Job Execution
8725@subsubsection Scheduled Job Execution
8726
8727@cindex cron
e32171ee 8728@cindex mcron
c311089b
LC
8729@cindex scheduling jobs
8730The @code{(gnu services mcron)} module provides an interface to
8731GNU@tie{}mcron, a daemon to run jobs at scheduled times (@pxref{Top,,,
8732mcron, GNU@tie{}mcron}). GNU@tie{}mcron is similar to the traditional
8733Unix @command{cron} daemon; the main difference is that it is
8734implemented in Guile Scheme, which provides a lot of flexibility when
8735specifying the scheduling of jobs and their actions.
8736
8ac6282c 8737The example below defines an operating system that runs the
c311089b 8738@command{updatedb} (@pxref{Invoking updatedb,,, find, Finding Files})
8ac6282c
LC
8739and the @command{guix gc} commands (@pxref{Invoking guix gc}) daily, as
8740well as the @command{mkid} command on behalf of an unprivileged user
8741(@pxref{mkid invocation,,, idutils, ID Database Utilities}). It uses
8742gexps to introduce job definitions that are passed to mcron
8743(@pxref{G-Expressions}).
c311089b
LC
8744
8745@lisp
8746(use-modules (guix) (gnu) (gnu services mcron))
8ac6282c 8747(use-package-modules base idutils)
c311089b
LC
8748
8749(define updatedb-job
8ac6282c
LC
8750 ;; Run 'updatedb' at 3AM every day. Here we write the
8751 ;; job's action as a Scheme procedure.
c311089b 8752 #~(job '(next-hour '(3))
8ac6282c
LC
8753 (lambda ()
8754 (execl (string-append #$findutils "/bin/updatedb")
8755 "updatedb"
8756 "--prunepaths=/tmp /var/tmp /gnu/store"))))
c311089b
LC
8757
8758(define garbage-collector-job
8759 ;; Collect garbage 5 minutes after midnight every day.
8ac6282c 8760 ;; The job's action is a shell command.
c311089b
LC
8761 #~(job "5 0 * * *" ;Vixie cron syntax
8762 "guix gc -F 1G"))
8763
80d944b7 8764(define idutils-job
8ac6282c
LC
8765 ;; Update the index database as user "charlie" at 12:15PM
8766 ;; and 19:15PM. This runs from the user's home directory.
8767 #~(job '(next-minute-from (next-hour '(12 19)) '(15))
8768 (string-append #$idutils "/bin/mkid src")
8769 #:user "charlie"))
8770
c311089b
LC
8771(operating-system
8772 ;; @dots{}
8773 (services (cons (mcron-service (list garbage-collector-job
8ac6282c
LC
8774 updatedb-job
8775 idutils-job))
c311089b
LC
8776 %base-services)))
8777@end lisp
8778
8779@xref{Guile Syntax, mcron job specifications,, mcron, GNU@tie{}mcron},
8780for more information on mcron job specifications. Below is the
8781reference of the mcron service.
8782
8783@deffn {Scheme Procedure} mcron-service @var{jobs} [#:mcron @var{mcron2}]
8784Return an mcron service running @var{mcron} that schedules @var{jobs}, a
8785list of gexps denoting mcron job specifications.
8786
8787This is a shorthand for:
8788@example
80d944b7
LC
8789(service mcron-service-type
8790 (mcron-configuration (mcron mcron) (jobs jobs)))
c311089b
LC
8791@end example
8792@end deffn
8793
8794@defvr {Scheme Variable} mcron-service-type
8795This is the type of the @code{mcron} service, whose value is an
8796@code{mcron-configuration} object.
8797
8798This service type can be the target of a service extension that provides
8799it additional job specifications (@pxref{Service Composition}). In
80d944b7 8800other words, it is possible to define services that provide additional
c311089b
LC
8801mcron jobs to run.
8802@end defvr
8803
8804@deftp {Data Type} mcron-configuration
8805Data type representing the configuration of mcron.
8806
8807@table @asis
8808@item @code{mcron} (default: @var{mcron2})
8809The mcron package to use.
8810
8811@item @code{jobs}
8812This is a list of gexps (@pxref{G-Expressions}), where each gexp
8813corresponds to an mcron job specification (@pxref{Syntax, mcron job
8814specifications,, mcron, GNU@tie{}mcron}).
8815@end table
8816@end deftp
8817
8818
92c03a87
JN
8819@node Log Rotation
8820@subsubsection Log Rotation
8821
8822@cindex rottlog
8823@cindex log rotation
e32171ee 8824@cindex logging
92c03a87
JN
8825Log files such as those found in @file{/var/log} tend to grow endlessly,
8826so it's a good idea to @dfn{rotate} them once in a while---i.e., archive
8827their contents in separate files, possibly compressed. The @code{(gnu
8828services admin)} module provides an interface to GNU@tie{}Rot[t]log, a
8829log rotation tool (@pxref{Top,,, rottlog, GNU Rot[t]log Manual}).
8830
8831The example below defines an operating system that provides log rotation
8832with the default settings.
8833
8834@lisp
8835(use-modules (guix) (gnu))
8836(use-service-modules admin mcron)
8837(use-package-modules base idutils)
8838
8839(operating-system
8840 ;; @dots{}
8841 (services (cons* (mcron-service)
8842 (service rottlog-service-type (rottlog-configuration))
8843 %base-services)))
8844@end lisp
8845
8846@defvr {Scheme Variable} rottlog-service-type
8847This is the type of the Rottlog service, whose value is a
8848@code{rottlog-configuration} object.
8849
8850This service type can define mcron jobs (@pxref{Scheduled Job
8851Execution}) to run the rottlog service.
8852@end defvr
8853
8854@deftp {Data Type} rottlog-configuration
8855Data type representing the configuration of rottlog.
8856
8857@table @asis
8858@item @code{rottlog} (default: @code{rottlog})
8859The Rottlog package to use.
8860
8861@item @code{rc-file} (default: @code{(file-append rottlog "/etc/rc")})
8862The Rottlog configuration file to use (@pxref{Mandatory RC Variables,,,
8863rottlog, GNU Rot[t]log Manual}).
8864
8865@item @code{periodic-rotations} (default: @code{`(("weekly" %default-rotatations))})
8866A list of Rottlog period-name/period-config tuples.
8867
8868For example, taking an example from the Rottlog manual (@pxref{Period
8869Related File Examples,,, rottlog, GNU Rot[t]log Manual}), a valid tuple
8870might be:
8871
8872@example
8873("daily" ,(plain-file "daily"
8874 "\
8875 /var/log/apache/* @{
8876 storedir apache-archives
8877 rotate 6
8878 notifempty
8879 nocompress
8880 @}"))
8881@end example
8882
8883@item @code{jobs}
8884This is a list of gexps where each gexp corresponds to an mcron job
8885specification (@pxref{Scheduled Job Execution}).
8886@end table
8887@end deftp
8888
8889@defvr {Scheme Variable} %default-rotations
8890Specifies weekly rotation of @var{%rotated-files} and
8891@code{"/var/log/shepherd.log"}.
8892@end defvr
8893
8894@defvr {Scheme Variable} %rotated-files
8895The list of syslog-controlled files to be rotated. By default it is:
8896@code{'("/var/log/messages" "/var/log/secure")}.
8897@end defvr
8898
cf4a9129
LC
8899@node Networking Services
8900@subsubsection Networking Services
401c53c4 8901
fa1e31b8 8902The @code{(gnu services networking)} module provides services to configure
cf4a9129 8903the network interface.
a1ba8475 8904
a023cca8 8905@cindex DHCP, networking service
be1c2c54 8906@deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
a023cca8
LC
8907Return a service that runs @var{dhcp}, a Dynamic Host Configuration
8908Protocol (DHCP) client, on all the non-loopback network interfaces.
8909@end deffn
8910
8de3e4b3
LC
8911@defvr {Scheme Variable} static-networking-service-type
8912This is the type for statically-configured network interfaces.
8913@c TODO Document <static-networking> data structures.
8914@end defvr
8915
be1c2c54 8916@deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
1f9803c2 8917 [#:netmask #f] [#:gateway #f] [#:name-servers @code{'()}]
cf4a9129 8918Return a service that starts @var{interface} with address @var{ip}. If
1f9803c2
LC
8919@var{netmask} is true, use it as the network mask. If @var{gateway} is true,
8920it must be a string specifying the default network gateway.
8de3e4b3
LC
8921
8922This procedure can be called several times, one for each network
8923interface of interest. Behind the scenes what it does is extend
8924@code{static-networking-service-type} with additional network interfaces
8925to handle.
cf4a9129 8926@end deffn
8b315a6d 8927
b7d0c494 8928@cindex wicd
e32171ee
JD
8929@cindex wireless
8930@cindex WiFi
87f40011 8931@cindex network management
be1c2c54 8932@deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
87f40011
LC
8933Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
8934management daemon that aims to simplify wired and wireless networking.
8935
8936This service adds the @var{wicd} package to the global profile, providing
8937several commands to interact with the daemon and configure networking:
8938@command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
8939and @command{wicd-curses} user interfaces.
b7d0c494
MW
8940@end deffn
8941
c0a9589d 8942@cindex NetworkManager
b726096b
CB
8943
8944@defvr {Scheme Variable} network-manager-service-type
8945This is the service type for the
8946@uref{https://wiki.gnome.org/Projects/NetworkManager, NetworkManager}
8947service. The value for this service type is a
8948@code{network-manager-configuration} record.
8949@end defvr
8950
8951@deftp {Data Type} network-manager-configuration
8952Data type representing the configuration of NetworkManager.
8953
8954@table @asis
8955@item @code{network-manager} (default: @code{network-manager})
8956The NetworkManager package to use.
8957
8958@item @code{dns} (default: @code{"default"})
8959Processing mode for DNS, which affects how NetworkManager uses the
8960@code{resolv.conf} configuration file.
8961
8962@table @samp
8963@item default
8964NetworkManager will update @code{resolv.conf} to reflect the nameservers
8965provided by currently active connections.
8966
8967@item dnsmasq
8968NetworkManager will run @code{dnsmasq} as a local caching nameserver,
8969using a "split DNS" configuration if you are connected to a VPN, and
8970then update @code{resolv.conf} to point to the local nameserver.
8971
8972@item none
8973NetworkManager will not modify @code{resolv.conf}.
8974@end table
8975
8976@end table
8977@end deftp
c0a9589d 8978
76192896
EF
8979@cindex Connman
8980@deffn {Scheme Procedure} connman-service @
8981 [#:connman @var{connman}]
8982Return a service that runs @url{https://01.org/connman,Connman}, a network
8983connection manager.
8984
8985This service adds the @var{connman} package to the global profile, providing
8986several the @command{connmanctl} command to interact with the daemon and
8987configure networking."
8988@end deffn
8989
2cccbc2a 8990@cindex WPA Supplicant
cbf1024e
LC
8991@defvr {Scheme Variable} wpa-supplicant-service-type
8992This is the service type to run @url{https://w1.fi/wpa_supplicant/,WPA
2cccbc2a 8993supplicant}, an authentication daemon required to authenticate against
cbf1024e 8994encrypted WiFi or ethernet networks. It is configured to listen for
2cccbc2a 8995requests on D-Bus.
cbf1024e
LC
8996
8997The value of this service is the @code{wpa-supplicant} package to use.
8998Thus, it can be instantiated like this:
8999
9000@lisp
9001(use-modules (gnu services networking)
9002 (gnu packages admin))
9003
9747d189 9004(service wpa-supplicant-service-type wpa-supplicant)
cbf1024e
LC
9005@end lisp
9006@end defvr
2cccbc2a 9007
e32171ee
JD
9008@cindex NTP
9009@cindex real time clock
be1c2c54 9010@deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
dc0322b5
LC
9011 [#:servers @var{%ntp-servers}] @
9012 [#:allow-large-adjustment? #f]
63854bcb
LC
9013Return a service that runs the daemon from @var{ntp}, the
9014@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
9015keep the system clock synchronized with that of @var{servers}.
dc0322b5
LC
9016@var{allow-large-adjustment?} determines whether @command{ntpd} is allowed to
9017make an initial adjustment of more than 1,000 seconds.
63854bcb
LC
9018@end deffn
9019
9020@defvr {Scheme Variable} %ntp-servers
9021List of host names used as the default NTP servers.
9022@end defvr
9023
e32171ee 9024@cindex Tor
375c6108
LC
9025@deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
9026Return a service to run the @uref{https://torproject.org, Tor} anonymous
9027networking daemon.
8b315a6d 9028
375c6108 9029The daemon runs as the @code{tor} unprivileged user. It is passed
6331bde7
LC
9030@var{config-file}, a file-like object, with an additional @code{User tor} line
9031and lines for hidden services added via @code{tor-hidden-service}. Run
9032@command{man tor} for information about the configuration file.
9033@end deffn
9034
24a8ef3b 9035@cindex hidden service
6331bde7
LC
9036@deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
9037Define a new Tor @dfn{hidden service} called @var{name} and implementing
9038@var{mapping}. @var{mapping} is a list of port/host tuples, such as:
9039
9040@example
24a8ef3b
LC
9041 '((22 "127.0.0.1:22")
9042 (80 "127.0.0.1:8080"))
6331bde7
LC
9043@end example
9044
9045In this example, port 22 of the hidden service is mapped to local port 22, and
9046port 80 is mapped to local port 8080.
9047
6629099a
LC
9048This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
9049the @file{hostname} file contains the @code{.onion} host name for the hidden
6331bde7
LC
9050service.
9051
9052See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
9053project's documentation} for more information.
cf4a9129 9054@end deffn
8b315a6d 9055
be1c2c54 9056@deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
4627a464
LC
9057 [#:interface "127.0.0.1"] [#:port 6667] @
9058 [#:extra-settings ""]
9059Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
9060acts as a gateway between IRC and chat networks.
9061
9062The daemon will listen to the interface corresponding to the IP address
9063specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
9064local clients can connect, whereas @code{0.0.0.0} means that connections can
9065come from any networking interface.
9066
9067In addition, @var{extra-settings} specifies a string to append to the
9068configuration file.
9069@end deffn
9070
71b0601a 9071Furthermore, @code{(gnu services ssh)} provides the following services.
e32171ee
JD
9072@cindex SSH
9073@cindex SSH server
8b315a6d 9074
be1c2c54 9075@deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 9076 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
9077 [#:allow-empty-passwords? #f] [#:root-login? #f] @
9078 [#:syslog-output? #t] [#:x11-forwarding? #t] @
9079 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 9080 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
9081Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
9082@var{host-key} must designate a file containing the host key, and readable
9083only by root.
72e25e35 9084
5833bf33
DP
9085When @var{daemonic?} is true, @command{lshd} will detach from the
9086controlling terminal and log its output to syslogd, unless one sets
9087@var{syslog-output?} to false. Obviously, it also makes lsh-service
9088depend on existence of syslogd service. When @var{pid-file?} is true,
9089@command{lshd} writes its PID to the file called @var{pid-file}.
9090
cf4a9129
LC
9091When @var{initialize?} is true, automatically create the seed and host key
9092upon service activation if they do not exist yet. This may take long and
9093require interaction.
8b315a6d 9094
20dd519c
LC
9095When @var{initialize?} is false, it is up to the user to initialize the
9096randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
9097a key pair with the private key stored in file @var{host-key} (@pxref{lshd
9098basics,,, lsh, LSH Manual}).
9099
cf4a9129
LC
9100When @var{interfaces} is empty, lshd listens for connections on all the
9101network interfaces; otherwise, @var{interfaces} must be a list of host names
9102or addresses.
9bf3c1a7 9103
20dd519c
LC
9104@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
9105passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 9106root.
4af2447e 9107
cf4a9129
LC
9108The other options should be self-descriptive.
9109@end deffn
4af2447e 9110
e32171ee
JD
9111@cindex SSH
9112@cindex SSH server
d8f31281
LC
9113@deffn {Scheme Variable} openssh-service-type
9114This is the type for the @uref{http://www.openssh.org, OpenSSH} secure
9115shell daemon, @command{sshd}. Its value must be an
9116@code{openssh-configuration} record as in this example:
9117
9118@example
9119(service openssh-service-type
9120 (openssh-configuration
9121 (x11-forwarding? #t)
9122 (permit-root-login 'without-password)))
9123@end example
9124
9125See below for details about @code{openssh-configuration}.
86d8f6d3
JL
9126@end deffn
9127
d8f31281
LC
9128@deftp {Data Type} openssh-configuration
9129This is the configuration record for OpenSSH's @command{sshd}.
9130
9131@table @asis
9132@item @code{pid-file} (default: @code{"/var/run/sshd.pid"})
9133Name of the file where @command{sshd} writes its PID.
9134
9135@item @code{port-number} (default: @code{22})
9136TCP port on which @command{sshd} listens for incoming connections.
9137
9138@item @code{permit-root-login} (default: @code{#f})
9139This field determines whether and when to allow logins as root. If
9140@code{#f}, root logins are disallowed; if @code{#t}, they are allowed.
9141If it's the symbol @code{'without-password}, then root logins are
9142permitted but not with password-based authentication.
9143
9144@item @code{allow-empty-passwords?} (default: @code{#f})
9145When true, users with empty passwords may log in. When false, they may
9146not.
9147
9148@item @code{password-authentication?} (default: @code{#t})
9149When true, users may log in with their password. When false, they have
9150other authentication methods.
9151
9152@item @code{public-key-authentication?} (default: @code{#t})
9153When true, users may log in using public key authentication. When
9154false, users have to use other authentication method.
9155
9156Authorized public keys are stored in @file{~/.ssh/authorized_keys}.
9157This is used only by protocol version 2.
9158
9159@item @code{rsa-authentication?} (default: @code{#t})
9160When true, users may log in using pure RSA authentication. When false,
9161users have to use other means of authentication. This is used only by
9162protocol 1.
9163
9164@item @code{x11-forwarding?} (default: @code{#f})
9165When true, forwarding of X11 graphical client connections is
9166enabled---in other words, @command{ssh} options @option{-X} and
9167@option{-Y} will work.
9168
9169@item @code{protocol-number} (default: @code{2})
9170The SSH protocol number to use.
9171@end table
9172@end deftp
9173
71b0601a
DC
9174@deffn {Scheme Procedure} dropbear-service [@var{config}]
9175Run the @uref{https://matt.ucc.asn.au/dropbear/dropbear.html,Dropbear SSH
9176daemon} with the given @var{config}, a @code{<dropbear-configuration>}
9177object.
9178
9179For example, to specify a Dropbear service listening on port 1234, add
9180this call to the operating system's @code{services} field:
9181
9182@example
9183(dropbear-service (dropbear-configuration
9184 (port-number 1234)))
9185@end example
9186@end deffn
9187
9188@deftp {Data Type} dropbear-configuration
9189This data type represents the configuration of a Dropbear SSH daemon.
9190
9191@table @asis
9192@item @code{dropbear} (default: @var{dropbear})
9193The Dropbear package to use.
9194
9195@item @code{port-number} (default: 22)
9196The TCP port where the daemon waits for incoming connections.
9197
9198@item @code{syslog-output?} (default: @code{#t})
9199Whether to enable syslog output.
9200
9201@item @code{pid-file} (default: @code{"/var/run/dropbear.pid"})
9202File name of the daemon's PID file.
9203
9204@item @code{root-login?} (default: @code{#f})
9205Whether to allow @code{root} logins.
9206
9207@item @code{allow-empty-passwords?} (default: @code{#f})
9208Whether to allow empty passwords.
9209
9210@item @code{password-authentication?} (default: @code{#t})
9211Whether to enable password-based authentication.
9212@end table
9213@end deftp
9214
fa0c1d61
LC
9215@defvr {Scheme Variable} %facebook-host-aliases
9216This variable contains a string for use in @file{/etc/hosts}
9217(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
9218line contains a entry that maps a known server name of the Facebook
9219on-line service---e.g., @code{www.facebook.com}---to the local
9220host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
9221
9222This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
9223@code{operating-system} declaration (@pxref{operating-system Reference,
9224@file{/etc/hosts}}):
fa0c1d61
LC
9225
9226@example
9227(use-modules (gnu) (guix))
9228
9229(operating-system
9230 (host-name "mymachine")
9231 ;; ...
9232 (hosts-file
9233 ;; Create a /etc/hosts file with aliases for "localhost"
9234 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
9235 (plain-file "hosts"
9236 (string-append (local-host-aliases host-name)
9237 %facebook-host-aliases))))
fa0c1d61
LC
9238@end example
9239
9240This mechanism can prevent programs running locally, such as Web
9241browsers, from accessing Facebook.
9242@end defvr
9243
965a7332
LC
9244The @code{(gnu services avahi)} provides the following definition.
9245
be1c2c54 9246@deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
965a7332
LC
9247 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
9248 [#:ipv6? #t] [#:wide-area? #f] @
c8695f32 9249 [#:domains-to-browse '()] [#:debug? #f]
965a7332
LC
9250Return a service that runs @command{avahi-daemon}, a system-wide
9251mDNS/DNS-SD responder that allows for service discovery and
cc9c1f39
LC
9252"zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
9253extends the name service cache daemon (nscd) so that it can resolve
9254@code{.local} host names using
1065bed9
LC
9255@uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
9256add the @var{avahi} package to the system profile so that commands such as
9257@command{avahi-browse} are directly usable.
965a7332
LC
9258
9259If @var{host-name} is different from @code{#f}, use that as the host name to
9260publish for this machine; otherwise, use the machine's actual host name.
9261
9262When @var{publish?} is true, publishing of host names and services is allowed;
9263in particular, avahi-daemon will publish the machine's host name and IP
9264address via mDNS on the local network.
9265
9266When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
9267
9268Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
9269sockets.
9270@end deffn
9271
c32d02fe
SB
9272@deffn {Scheme Variable} openvswitch-service-type
9273This is the type of the @uref{http://www.openvswitch.org, Open vSwitch}
9274service, whose value should be an @code{openvswitch-configuration}
9275object.
9276@end deffn
9277
9278@deftp {Data Type} openvswitch-configuration
9279Data type representing the configuration of Open vSwitch, a multilayer
9280virtual switch which is designed to enable massive network automation
9281through programmatic extension.
9282
9283@table @asis
9284@item @code{package} (default: @var{openvswitch})
9285Package object of the Open vSwitch.
9286
9287@end table
9288@end deftp
965a7332 9289
cf4a9129
LC
9290@node X Window
9291@subsubsection X Window
68ad877c 9292
e32171ee
JD
9293@cindex X11
9294@cindex X Window System
cf4a9129
LC
9295Support for the X Window graphical display system---specifically
9296Xorg---is provided by the @code{(gnu services xorg)} module. Note that
9297there is no @code{xorg-service} procedure. Instead, the X server is
9298started by the @dfn{login manager}, currently SLiM.
4af2447e 9299
935644c0
DC
9300@deftp {Data Type} sddm-configuration
9301This is the data type representing the sddm service configuration.
9302
9303@table @asis
9304@item @code{display-server} (default: "x11")
9305Select display server to use for the greeter. Valid values are "x11"
9306or "wayland".
9307
9308@item @code{numlock} (default: "on")
9309Valid values are "on", "off" or "none".
9310
9311@item @code{halt-command} (default @code{#~(string-apppend #$shepherd "/sbin/halt")})
9312Command to run when halting.
9313
9314@item @code{reboot-command} (default @code{#~(string-append #$shepherd "/sbin/reboot")})
9315Command to run when rebooting.
9316
9317@item @code{theme} (default "maldives")
9318Theme to use. Default themes provided by SDDM are "elarun" or "maldives".
9319
9320@item @code{themes-directory} (default "/run/current-system/profile/share/sddm/themes")
9321Directory to look for themes.
9322
9323@item @code{faces-directory} (default "/run/current-system/profile/share/sddm/faces")
9324Directory to look for faces.
9325
9326@item @code{default-path} (default "/run/current-system/profile/bin")
9327Default PATH to use.
9328
9329@item @code{minimum-uid} (default 1000)
9330Minimum UID to display in SDDM.
9331
9332@item @code{maximum-uid} (default 2000)
9333Maximum UID to display in SDDM
9334
9335@item @code{remember-last-user?} (default #t)
9336Remember last user.
9337
9338@item @code{remember-last-session?} (default #t)
9339Remember last session.
9340
9341@item @code{hide-users} (default "")
9342Usernames to hide from SDDM greeter.
9343
9344@item @code{hide-shells} (default @code{#~(string-append #$shadow "/sbin/nologin")})
9345Users with shells listed will be hidden from the SDDM greeter.
9346
9347@item @code{session-command} (default @code{#~(string-append #$sddm "/share/sddm/scripts/wayland-session")})
9348Script to run before starting a wayland session.
9349
9350@item @code{sessions-directory} (default "/run/current-system/profile/share/wayland-sessions")
9351Directory to look for desktop files starting wayland sessions.
9352
9353@item @code{xorg-server-path} (default @code{xorg-start-command})
9354Path to xorg-server.
9355
9356@item @code{xauth-path} (default @code{#~(string-append #$xauth "/bin/xauth")})
9357Path to xauth.
9358
9359@item @code{xephyr-path} (default @code{#~(string-append #$xorg-server "/bin/Xephyr")})
9360Path to Xephyr.
9361
9362@item @code{xdisplay-start} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xsetup")})
9363Script to run after starting xorg-server.
9364
9365@item @code{xdisplay-stop} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xstop")})
9366Script to run before stopping xorg-server.
9367
9368@item @code{xsession-command} (default: @code{xinitr })
9369Script to run before starting a X session.
9370
9371@item @code{xsessions-directory} (default: "/run/current-system/profile/share/xsessions")
9372Directory to look for desktop files starting X sessions.
9373
9374@item @code{minimum-vt} (default: 7)
9375Minimum VT to use.
9376
9377@item @code{xserver-arguments} (default "-nolisten tcp")
9378Arguments to pass to xorg-server.
9379
9380@item @code{auto-login-user} (default "")
9381User to use for auto-login.
9382
9383@item @code{auto-login-session} (default "")
9384Desktop file to use for auto-login.
9385
9386@item @code{relogin?} (default #f)
9387Relogin after logout.
9388
9389@end table
9390@end deftp
9391
e32171ee 9392@cindex login manager
935644c0
DC
9393@deffn {Scheme Procedure} sddm-service config
9394Return a service that spawns the SDDM graphical login manager for config of
9395type @code{<sddm-configuration>}.
9396
9397@example
9398 (sddm-service (sddm-configuration
9399 (auto-login-user "Alice")
9400 (auto-login-session "xfce.desktop")))
9401@end example
9402@end deffn
9403
be1c2c54 9404@deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
9405 [#:auto-login? #f] [#:default-user ""] [#:startx] @
9406 [#:theme @var{%default-slim-theme}] @
4bd43bbe 9407 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
9408Return a service that spawns the SLiM graphical login manager, which in
9409turn starts the X display server with @var{startx}, a command as returned by
9410@code{xorg-start-command}.
4af2447e 9411
04e4e6ab
LC
9412@cindex X session
9413
9414SLiM automatically looks for session types described by the @file{.desktop}
9415files in @file{/run/current-system/profile/share/xsessions} and allows users
9416to choose a session from the log-in screen using @kbd{F1}. Packages such as
9417@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
9418adding them to the system-wide set of packages automatically makes them
9419available at the log-in screen.
9420
9421In addition, @file{~/.xsession} files are honored. When available,
9422@file{~/.xsession} must be an executable that starts a window manager
9423and/or other X clients.
9424
cf4a9129
LC
9425When @var{allow-empty-passwords?} is true, allow logins with an empty
9426password. When @var{auto-login?} is true, log in automatically as
9427@var{default-user}.
0ecc3bf3 9428
1068f26b 9429If @var{theme} is @code{#f}, use the default log-in theme; otherwise
0ecc3bf3
LC
9430@var{theme} must be a gexp denoting the name of a directory containing the
9431theme to use. In that case, @var{theme-name} specifies the name of the
9432theme.
cf4a9129 9433@end deffn
4af2447e 9434
0ecc3bf3
LC
9435@defvr {Scheme Variable} %default-theme
9436@defvrx {Scheme Variable} %default-theme-name
9437The G-Expression denoting the default SLiM theme and its name.
9438@end defvr
9439
be1c2c54 9440@deffn {Scheme Procedure} xorg-start-command [#:guile] @
d1cdd7ba 9441 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 9442Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
9443from @var{xorg-server}. @var{configuration-file} is the server configuration
9444file or a derivation that builds it; when omitted, the result of
9445@code{xorg-configuration-file} is used.
9446
9447Usually the X server is started by a login manager.
9448@end deffn
9449
be1c2c54 9450@deffn {Scheme Procedure} xorg-configuration-file @
12422c9d 9451 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
9452Return a configuration file for the Xorg server containing search paths for
9453all the common drivers.
f703413e
LC
9454
9455@var{drivers} must be either the empty list, in which case Xorg chooses a
9456graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 9457this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
9458
9459Likewise, when @var{resolutions} is the empty list, Xorg chooses an
9460appropriate screen resolution; otherwise, it must be a list of
9461resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
9462
9463Last, @var{extra-config} is a list of strings or objects appended to the
9464@code{text-file*} argument list. It is used to pass extra text to be added
9465verbatim to the configuration file.
f703413e 9466@end deffn
4af2447e 9467
6726282b
LC
9468@deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
9469Add @var{package}, a package for a screen-locker or screen-saver whose
9470command is @var{program}, to the set of setuid programs and add a PAM entry
9471for it. For example:
9472
9473@lisp
9474(screen-locker-service xlockmore "xlock")
9475@end lisp
9476
9477makes the good ol' XlockMore usable.
9478@end deffn
9479
9480
f2ec23d1
AW
9481@node Printing Services
9482@subsubsection Printing Services
9483
de322a5d 9484@cindex printer support with CUPS
f2ec23d1
AW
9485The @code{(gnu services cups)} module provides a Guix service definition
9486for the CUPS printing service. To add printer support to a GuixSD
9487system, add a @code{cups-service} to the operating system definition:
9488
9489@deffn {Scheme Variable} cups-service-type
9490The service type for the CUPS print server. Its value should be a valid
9491CUPS configuration (see below). For example:
9492@example
9493(service cups-service-type (cups-configuration))
9494@end example
9495@end deffn
9496
9497The CUPS configuration controls the basic things about your CUPS
9498installation: what interfaces it listens on, what to do if a print job
9499fails, how much logging to do, and so on. To actually add a printer,
9500you have to visit the @url{http://localhost:631} URL, or use a tool such
9501as GNOME's printer configuration services. By default, configuring a
9502CUPS service will generate a self-signed certificate if needed, for
9503secure connections to the print server.
9504
de322a5d
LC
9505Suppose you want to enable the Web interface of CUPS and also add
9506support for HP printers @i{via} the @code{hplip} package. You can do
9507that directly, like this (you need to use the @code{(gnu packages cups)}
9508module):
f2ec23d1
AW
9509
9510@example
9511(service cups-service-type
9512 (cups-configuration
de322a5d
LC
9513 (web-interface? #t)
9514 (extensions
9515 (list cups-filters hplip))))
f2ec23d1
AW
9516@end example
9517
9518The available configuration parameters follow. Each parameter
9519definition is preceded by its type; for example, @samp{string-list foo}
9520indicates that the @code{foo} parameter should be specified as a list of
9521strings. There is also a way to specify the configuration as a string,
9522if you have an old @code{cupsd.conf} file that you want to port over
9523from some other system; see the end for more details.
9524
9525@c The following documentation was initially generated by
9526@c (generate-documentation) in (gnu services cups). Manually maintained
9527@c documentation is better, so we shouldn't hesitate to edit below as
9528@c needed. However if the change you want to make to this documentation
9529@c can be done in an automated way, it's probably easier to change
9530@c (generate-documentation) than to make it below and have to deal with
9531@c the churn as CUPS updates.
9532
9533
9534Available @code{cups-configuration} fields are:
9535
9536@deftypevr {@code{cups-configuration} parameter} package cups
9537The CUPS package.
9538@end deftypevr
9539
9540@deftypevr {@code{cups-configuration} parameter} package-list extensions
9541Drivers and other extensions to the CUPS package.
9542@end deftypevr
9543
9544@deftypevr {@code{cups-configuration} parameter} files-configuration files-configuration
9545Configuration of where to write logs, what directories to use for print
9546spools, and related privileged configuration parameters.
9547
9548Available @code{files-configuration} fields are:
9549
9550@deftypevr {@code{files-configuration} parameter} log-location access-log
9551Defines the access log filename. Specifying a blank filename disables
9552access log generation. The value @code{stderr} causes log entries to be
9553sent to the standard error file when the scheduler is running in the
9554foreground, or to the system log daemon when run in the background. The
9555value @code{syslog} causes log entries to be sent to the system log
9556daemon. The server name may be included in filenames using the string
9557@code{%s}, as in @code{/var/log/cups/%s-access_log}.
9558
9559Defaults to @samp{"/var/log/cups/access_log"}.
9560@end deftypevr
9561
9562@deftypevr {@code{files-configuration} parameter} file-name cache-dir
9563Where CUPS should cache data.
9564
9565Defaults to @samp{"/var/cache/cups"}.
9566@end deftypevr
9567
9568@deftypevr {@code{files-configuration} parameter} string config-file-perm
9569Specifies the permissions for all configuration files that the scheduler
9570writes.
9571
9572Note that the permissions for the printers.conf file are currently
9573masked to only allow access from the scheduler user (typically root).
9574This is done because printer device URIs sometimes contain sensitive
9575authentication information that should not be generally known on the
9576system. There is no way to disable this security feature.
9577
9578Defaults to @samp{"0640"}.
9579@end deftypevr
9580
9581@deftypevr {@code{files-configuration} parameter} log-location error-log
9582Defines the error log filename. Specifying a blank filename disables
9583access log generation. The value @code{stderr} causes log entries to be
9584sent to the standard error file when the scheduler is running in the
9585foreground, or to the system log daemon when run in the background. The
9586value @code{syslog} causes log entries to be sent to the system log
9587daemon. The server name may be included in filenames using the string
9588@code{%s}, as in @code{/var/log/cups/%s-error_log}.
9589
9590Defaults to @samp{"/var/log/cups/error_log"}.
9591@end deftypevr
9592
9593@deftypevr {@code{files-configuration} parameter} string fatal-errors
9594Specifies which errors are fatal, causing the scheduler to exit. The
9595kind strings are:
9596
9597@table @code
9598@item none
9599No errors are fatal.
9600
9601@item all
9602All of the errors below are fatal.
9603
9604@item browse
9605Browsing initialization errors are fatal, for example failed connections
9606to the DNS-SD daemon.
9607
9608@item config
9609Configuration file syntax errors are fatal.
9610
9611@item listen
9612Listen or Port errors are fatal, except for IPv6 failures on the
9613loopback or @code{any} addresses.
9614
9615@item log
9616Log file creation or write errors are fatal.
9617
9618@item permissions
9619Bad startup file permissions are fatal, for example shared TLS
9620certificate and key files with world-read permissions.
9621@end table
9622
9623Defaults to @samp{"all -browse"}.
9624@end deftypevr
9625
9626@deftypevr {@code{files-configuration} parameter} boolean file-device?
9627Specifies whether the file pseudo-device can be used for new printer
9628queues. The URI @uref{file:///dev/null} is always allowed.
9629
9630Defaults to @samp{#f}.
9631@end deftypevr
9632
9633@deftypevr {@code{files-configuration} parameter} string group
9634Specifies the group name or ID that will be used when executing external
9635programs.
9636
9637Defaults to @samp{"lp"}.
9638@end deftypevr
9639
9640@deftypevr {@code{files-configuration} parameter} string log-file-perm
9641Specifies the permissions for all log files that the scheduler writes.
9642
9643Defaults to @samp{"0644"}.
9644@end deftypevr
9645
9646@deftypevr {@code{files-configuration} parameter} log-location page-log
9647Defines the page log filename. Specifying a blank filename disables
9648access log generation. The value @code{stderr} causes log entries to be
9649sent to the standard error file when the scheduler is running in the
9650foreground, or to the system log daemon when run in the background. The
9651value @code{syslog} causes log entries to be sent to the system log
9652daemon. The server name may be included in filenames using the string
9653@code{%s}, as in @code{/var/log/cups/%s-page_log}.
9654
9655Defaults to @samp{"/var/log/cups/page_log"}.
9656@end deftypevr
9657
9658@deftypevr {@code{files-configuration} parameter} string remote-root
9659Specifies the username that is associated with unauthenticated accesses
9660by clients claiming to be the root user. The default is @code{remroot}.
9661
9662Defaults to @samp{"remroot"}.
9663@end deftypevr
9664
9665@deftypevr {@code{files-configuration} parameter} file-name request-root
9666Specifies the directory that contains print jobs and other HTTP request
9667data.
9668
9669Defaults to @samp{"/var/spool/cups"}.
9670@end deftypevr
9671
9672@deftypevr {@code{files-configuration} parameter} sandboxing sandboxing
9673Specifies the level of security sandboxing that is applied to print
9674filters, backends, and other child processes of the scheduler; either
9675@code{relaxed} or @code{strict}. This directive is currently only
9676used/supported on macOS.
9677
9678Defaults to @samp{strict}.
9679@end deftypevr
9680
9681@deftypevr {@code{files-configuration} parameter} file-name server-keychain
9682Specifies the location of TLS certificates and private keys. CUPS will
9683look for public and private keys in this directory: a @code{.crt} files
9684for PEM-encoded certificates and corresponding @code{.key} files for
9685PEM-encoded private keys.
9686
9687Defaults to @samp{"/etc/cups/ssl"}.
9688@end deftypevr
9689
9690@deftypevr {@code{files-configuration} parameter} file-name server-root
9691Specifies the directory containing the server configuration files.
9692
9693Defaults to @samp{"/etc/cups"}.
9694@end deftypevr
9695
9696@deftypevr {@code{files-configuration} parameter} boolean sync-on-close?
9697Specifies whether the scheduler calls fsync(2) after writing
9698configuration or state files.
9699
9700Defaults to @samp{#f}.
9701@end deftypevr
9702
9703@deftypevr {@code{files-configuration} parameter} space-separated-string-list system-group
9704Specifies the group(s) to use for @code{@@SYSTEM} group authentication.
9705@end deftypevr
9706
9707@deftypevr {@code{files-configuration} parameter} file-name temp-dir
9708Specifies the directory where temporary files are stored.
9709
9710Defaults to @samp{"/var/spool/cups/tmp"}.
9711@end deftypevr
9712
9713@deftypevr {@code{files-configuration} parameter} string user
9714Specifies the user name or ID that is used when running external
9715programs.
9716
9717Defaults to @samp{"lp"}.
9718@end deftypevr
9719@end deftypevr
9720
9721@deftypevr {@code{cups-configuration} parameter} access-log-level access-log-level
9722Specifies the logging level for the AccessLog file. The @code{config}
9723level logs when printers and classes are added, deleted, or modified and
9724when configuration files are accessed or updated. The @code{actions}
9725level logs when print jobs are submitted, held, released, modified, or
9726canceled, and any of the conditions for @code{config}. The @code{all}
9727level logs all requests.
9728
9729Defaults to @samp{actions}.
9730@end deftypevr
9731
9732@deftypevr {@code{cups-configuration} parameter} boolean auto-purge-jobs?
9733Specifies whether to purge job history data automatically when it is no
9734longer required for quotas.
9735
9736Defaults to @samp{#f}.
9737@end deftypevr
9738
9739@deftypevr {@code{cups-configuration} parameter} browse-local-protocols browse-local-protocols
9740Specifies which protocols to use for local printer sharing.
9741
9742Defaults to @samp{dnssd}.
9743@end deftypevr
9744
9745@deftypevr {@code{cups-configuration} parameter} boolean browse-web-if?
9746Specifies whether the CUPS web interface is advertised.
9747
9748Defaults to @samp{#f}.
9749@end deftypevr
9750
9751@deftypevr {@code{cups-configuration} parameter} boolean browsing?
9752Specifies whether shared printers are advertised.
9753
9754Defaults to @samp{#f}.
9755@end deftypevr
9756
9757@deftypevr {@code{cups-configuration} parameter} string classification
9758Specifies the security classification of the server. Any valid banner
9759name can be used, including "classified", "confidential", "secret",
9760"topsecret", and "unclassified", or the banner can be omitted to disable
9761secure printing functions.
9762
9763Defaults to @samp{""}.
9764@end deftypevr
9765
9766@deftypevr {@code{cups-configuration} parameter} boolean classify-override?
9767Specifies whether users may override the classification (cover page) of
9768individual print jobs using the @code{job-sheets} option.
9769
9770Defaults to @samp{#f}.
9771@end deftypevr
9772
9773@deftypevr {@code{cups-configuration} parameter} default-auth-type default-auth-type
9774Specifies the default type of authentication to use.
9775
9776Defaults to @samp{Basic}.
9777@end deftypevr
9778
9779@deftypevr {@code{cups-configuration} parameter} default-encryption default-encryption
9780Specifies whether encryption will be used for authenticated requests.
9781
9782Defaults to @samp{Required}.
9783@end deftypevr
9784
9785@deftypevr {@code{cups-configuration} parameter} string default-language
9786Specifies the default language to use for text and web content.
9787
9788Defaults to @samp{"en"}.
9789@end deftypevr
9790
9791@deftypevr {@code{cups-configuration} parameter} string default-paper-size
9792Specifies the default paper size for new print queues. @samp{"Auto"}
9793uses a locale-specific default, while @samp{"None"} specifies there is
9794no default paper size. Specific size names are typically
9795@samp{"Letter"} or @samp{"A4"}.
9796
9797Defaults to @samp{"Auto"}.
9798@end deftypevr
9799
9800@deftypevr {@code{cups-configuration} parameter} string default-policy
9801Specifies the default access policy to use.
9802
9803Defaults to @samp{"default"}.
9804@end deftypevr
9805
9806@deftypevr {@code{cups-configuration} parameter} boolean default-shared?
9807Specifies whether local printers are shared by default.
9808
9809Defaults to @samp{#t}.
9810@end deftypevr
9811
9812@deftypevr {@code{cups-configuration} parameter} non-negative-integer dirty-clean-interval
9813Specifies the delay for updating of configuration and state files, in
9814seconds. A value of 0 causes the update to happen as soon as possible,
9815typically within a few milliseconds.
9816
9817Defaults to @samp{30}.
9818@end deftypevr
9819
9820@deftypevr {@code{cups-configuration} parameter} error-policy error-policy
9821Specifies what to do when an error occurs. Possible values are
9822@code{abort-job}, which will discard the failed print job;
9823@code{retry-job}, which will retry the job at a later time;
9824@code{retry-this-job}, which retries the failed job immediately; and
9825@code{stop-printer}, which stops the printer.
9826
9827Defaults to @samp{stop-printer}.
9828@end deftypevr
9829
9830@deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-limit
9831Specifies the maximum cost of filters that are run concurrently, which
9832can be used to minimize disk, memory, and CPU resource problems. A
9833limit of 0 disables filter limiting. An average print to a
9834non-PostScript printer needs a filter limit of about 200. A PostScript
9835printer needs about half that (100). Setting the limit below these
9836thresholds will effectively limit the scheduler to printing a single job
9837at any time.
9838
9839Defaults to @samp{0}.
9840@end deftypevr
9841
9842@deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-nice
9843Specifies the scheduling priority of filters that are run to print a
9844job. The nice value ranges from 0, the highest priority, to 19, the
9845lowest priority.
9846
9847Defaults to @samp{0}.
9848@end deftypevr
9849
9850@deftypevr {@code{cups-configuration} parameter} host-name-lookups host-name-lookups
9851Specifies whether to do reverse lookups on connecting clients. The
9852@code{double} setting causes @code{cupsd} to verify that the hostname
9853resolved from the address matches one of the addresses returned for that
9854hostname. Double lookups also prevent clients with unregistered
9855addresses from connecting to your server. Only set this option to
9856@code{#t} or @code{double} if absolutely required.
9857
9858Defaults to @samp{#f}.
9859@end deftypevr
9860
9861@deftypevr {@code{cups-configuration} parameter} non-negative-integer job-kill-delay
9862Specifies the number of seconds to wait before killing the filters and
9863backend associated with a canceled or held job.
9864
9865Defaults to @samp{30}.
9866@end deftypevr
9867
9868@deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-interval
9869Specifies the interval between retries of jobs in seconds. This is
9870typically used for fax queues but can also be used with normal print
9871queues whose error policy is @code{retry-job} or
9872@code{retry-current-job}.
9873
9874Defaults to @samp{30}.
9875@end deftypevr
9876
9877@deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-limit
9878Specifies the number of retries that are done for jobs. This is
9879typically used for fax queues but can also be used with normal print
9880queues whose error policy is @code{retry-job} or
9881@code{retry-current-job}.
9882
9883Defaults to @samp{5}.
9884@end deftypevr
9885
9886@deftypevr {@code{cups-configuration} parameter} boolean keep-alive?
9887Specifies whether to support HTTP keep-alive connections.
9888
9889Defaults to @samp{#t}.
9890@end deftypevr
9891
9892@deftypevr {@code{cups-configuration} parameter} non-negative-integer keep-alive-timeout
9893Specifies how long an idle client connection remains open, in seconds.
9894
9895Defaults to @samp{30}.
9896@end deftypevr
9897
9898@deftypevr {@code{cups-configuration} parameter} non-negative-integer limit-request-body
9899Specifies the maximum size of print files, IPP requests, and HTML form
9900data. A limit of 0 disables the limit check.
9901
9902Defaults to @samp{0}.
9903@end deftypevr
9904
9905@deftypevr {@code{cups-configuration} parameter} multiline-string-list listen
9906Listens on the specified interfaces for connections. Valid values are
9907of the form @var{address}:@var{port}, where @var{address} is either an
9908IPv6 address enclosed in brackets, an IPv4 address, or @code{*} to
9909indicate all addresses. Values can also be file names of local UNIX
9910domain sockets. The Listen directive is similar to the Port directive
9911but allows you to restrict access to specific interfaces or networks.
9912@end deftypevr
9913
9914@deftypevr {@code{cups-configuration} parameter} non-negative-integer listen-back-log
9915Specifies the number of pending connections that will be allowed. This
9916normally only affects very busy servers that have reached the MaxClients
9917limit, but can also be triggered by large numbers of simultaneous
9918connections. When the limit is reached, the operating system will
9919refuse additional connections until the scheduler can accept the pending
9920ones.
9921
9922Defaults to @samp{128}.
9923@end deftypevr
9924
9925@deftypevr {@code{cups-configuration} parameter} location-access-control-list location-access-controls
9926Specifies a set of additional access controls.
9927
9928Available @code{location-access-controls} fields are:
9929
9930@deftypevr {@code{location-access-controls} parameter} file-name path
9931Specifies the URI path to which the access control applies.
9932@end deftypevr
9933
9934@deftypevr {@code{location-access-controls} parameter} access-control-list access-controls
9935Access controls for all access to this path, in the same format as the
9936@code{access-controls} of @code{operation-access-control}.
9937
9938Defaults to @samp{()}.
9939@end deftypevr
9940
9941@deftypevr {@code{location-access-controls} parameter} method-access-control-list method-access-controls
9942Access controls for method-specific access to this path.
9943
9944Defaults to @samp{()}.
9945
9946Available @code{method-access-controls} fields are:
9947
9948@deftypevr {@code{method-access-controls} parameter} boolean reverse?
9949If @code{#t}, apply access controls to all methods except the listed
9950methods. Otherwise apply to only the listed methods.
9951
9952Defaults to @samp{#f}.
9953@end deftypevr
9954
9955@deftypevr {@code{method-access-controls} parameter} method-list methods
9956Methods to which this access control applies.
9957
9958Defaults to @samp{()}.
9959@end deftypevr
9960
9961@deftypevr {@code{method-access-controls} parameter} access-control-list access-controls
9962Access control directives, as a list of strings. Each string should be
9963one directive, such as "Order allow,deny".
9964
9965Defaults to @samp{()}.
9966@end deftypevr
9967@end deftypevr
9968@end deftypevr
9969
9970@deftypevr {@code{cups-configuration} parameter} non-negative-integer log-debug-history
9971Specifies the number of debugging messages that are retained for logging
9972if an error occurs in a print job. Debug messages are logged regardless
9973of the LogLevel setting.
9974
9975Defaults to @samp{100}.
9976@end deftypevr
9977
9978@deftypevr {@code{cups-configuration} parameter} log-level log-level
9979Specifies the level of logging for the ErrorLog file. The value
9980@code{none} stops all logging while @code{debug2} logs everything.
9981
9982Defaults to @samp{info}.
9983@end deftypevr
9984
9985@deftypevr {@code{cups-configuration} parameter} log-time-format log-time-format
9986Specifies the format of the date and time in the log files. The value
9987@code{standard} logs whole seconds while @code{usecs} logs microseconds.
9988
9989Defaults to @samp{standard}.
9990@end deftypevr
9991
9992@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients
9993Specifies the maximum number of simultaneous clients that are allowed by
9994the scheduler.
9995
9996Defaults to @samp{100}.
9997@end deftypevr
9998
9999@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients-per-host
10000Specifies the maximum number of simultaneous clients that are allowed
10001from a single address.
10002
10003Defaults to @samp{100}.
10004@end deftypevr
10005
10006@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-copies
10007Specifies the maximum number of copies that a user can print of each
10008job.
10009
10010Defaults to @samp{9999}.
10011@end deftypevr
10012
10013@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-hold-time
10014Specifies the maximum time a job may remain in the @code{indefinite}
10015hold state before it is canceled. A value of 0 disables cancellation of
10016held jobs.
10017
10018Defaults to @samp{0}.
10019@end deftypevr
10020
10021@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs
10022Specifies the maximum number of simultaneous jobs that are allowed. Set
10023to 0 to allow an unlimited number of jobs.
10024
10025Defaults to @samp{500}.
10026@end deftypevr
10027
10028@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-printer
10029Specifies the maximum number of simultaneous jobs that are allowed per
10030printer. A value of 0 allows up to MaxJobs jobs per printer.
10031
10032Defaults to @samp{0}.
10033@end deftypevr
10034
10035@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-user
10036Specifies the maximum number of simultaneous jobs that are allowed per
10037user. A value of 0 allows up to MaxJobs jobs per user.
10038
10039Defaults to @samp{0}.
10040@end deftypevr
10041
10042@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-job-time
10043Specifies the maximum time a job may take to print before it is
10044canceled, in seconds. Set to 0 to disable cancellation of "stuck" jobs.
10045
10046Defaults to @samp{10800}.
10047@end deftypevr
10048
10049@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-log-size
10050Specifies the maximum size of the log files before they are rotated, in
10051bytes. The value 0 disables log rotation.
10052
10053Defaults to @samp{1048576}.
10054@end deftypevr
10055
10056@deftypevr {@code{cups-configuration} parameter} non-negative-integer multiple-operation-timeout
10057Specifies the maximum amount of time to allow between files in a
10058multiple file print job, in seconds.
10059
10060Defaults to @samp{300}.
10061@end deftypevr
10062
10063@deftypevr {@code{cups-configuration} parameter} string page-log-format
10064Specifies the format of PageLog lines. Sequences beginning with percent
10065(@samp{%}) characters are replaced with the corresponding information,
10066while all other characters are copied literally. The following percent
10067sequences are recognized:
10068
10069@table @samp
10070@item %%
10071insert a single percent character
10072
10073@item %@{name@}
10074insert the value of the specified IPP attribute
10075
10076@item %C
10077insert the number of copies for the current page
10078
10079@item %P
10080insert the current page number
10081
10082@item %T
10083insert the current date and time in common log format
10084
10085@item %j
10086insert the job ID
10087
10088@item %p
10089insert the printer name
10090
10091@item %u
10092insert the username
10093@end table
10094
10095A value of the empty string disables page logging. The string @code{%p
10096%u %j %T %P %C %@{job-billing@} %@{job-originating-host-name@}
10097%@{job-name@} %@{media@} %@{sides@}} creates a page log with the
10098standard items.
10099
10100Defaults to @samp{""}.
10101@end deftypevr
10102
10103@deftypevr {@code{cups-configuration} parameter} environment-variables environment-variables
10104Passes the specified environment variable(s) to child processes; a list
10105of strings.
10106
10107Defaults to @samp{()}.
10108@end deftypevr
10109
10110@deftypevr {@code{cups-configuration} parameter} policy-configuration-list policies
10111Specifies named access control policies.
10112
10113Available @code{policy-configuration} fields are:
10114
10115@deftypevr {@code{policy-configuration} parameter} string name
10116Name of the policy.
10117@end deftypevr
10118
10119@deftypevr {@code{policy-configuration} parameter} string job-private-access
10120Specifies an access list for a job's private values. @code{@@ACL} maps
10121to the printer's requesting-user-name-allowed or
10122requesting-user-name-denied values. @code{@@OWNER} maps to the job's
10123owner. @code{@@SYSTEM} maps to the groups listed for the
10124@code{system-group} field of the @code{files-config} configuration,
10125which is reified into the @code{cups-files.conf(5)} file. Other
10126possible elements of the access list include specific user names, and
10127@code{@@@var{group}} to indicate members of a specific group. The
10128access list may also be simply @code{all} or @code{default}.
10129
10130Defaults to @samp{"@@OWNER @@SYSTEM"}.
10131@end deftypevr
10132
10133@deftypevr {@code{policy-configuration} parameter} string job-private-values
10134Specifies the list of job values to make private, or @code{all},
10135@code{default}, or @code{none}.
10136
10137Defaults to @samp{"job-name job-originating-host-name
10138job-originating-user-name phone"}.
10139@end deftypevr
10140
10141@deftypevr {@code{policy-configuration} parameter} string subscription-private-access
10142Specifies an access list for a subscription's private values.
10143@code{@@ACL} maps to the printer's requesting-user-name-allowed or
10144requesting-user-name-denied values. @code{@@OWNER} maps to the job's
10145owner. @code{@@SYSTEM} maps to the groups listed for the
10146@code{system-group} field of the @code{files-config} configuration,
10147which is reified into the @code{cups-files.conf(5)} file. Other
10148possible elements of the access list include specific user names, and
10149@code{@@@var{group}} to indicate members of a specific group. The
10150access list may also be simply @code{all} or @code{default}.
10151
10152Defaults to @samp{"@@OWNER @@SYSTEM"}.
10153@end deftypevr
10154
10155@deftypevr {@code{policy-configuration} parameter} string subscription-private-values
10156Specifies the list of job values to make private, or @code{all},
10157@code{default}, or @code{none}.
10158
10159Defaults to @samp{"notify-events notify-pull-method notify-recipient-uri
10160notify-subscriber-user-name notify-user-data"}.
10161@end deftypevr
10162
10163@deftypevr {@code{policy-configuration} parameter} operation-access-control-list access-controls
10164Access control by IPP operation.
10165
10166Defaults to @samp{()}.
10167@end deftypevr
10168@end deftypevr
10169
10170@deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-files
10171Specifies whether job files (documents) are preserved after a job is
10172printed. If a numeric value is specified, job files are preserved for
10173the indicated number of seconds after printing. Otherwise a boolean
10174value applies indefinitely.
10175
10176Defaults to @samp{86400}.
10177@end deftypevr
10178
10179@deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-history
10180Specifies whether the job history is preserved after a job is printed.
10181If a numeric value is specified, the job history is preserved for the
10182indicated number of seconds after printing. If @code{#t}, the job
10183history is preserved until the MaxJobs limit is reached.
10184
10185Defaults to @samp{#t}.
10186@end deftypevr
10187
10188@deftypevr {@code{cups-configuration} parameter} non-negative-integer reload-timeout
10189Specifies the amount of time to wait for job completion before
10190restarting the scheduler.
10191
10192Defaults to @samp{30}.
10193@end deftypevr
10194
10195@deftypevr {@code{cups-configuration} parameter} string rip-cache
10196Specifies the maximum amount of memory to use when converting documents
10197into bitmaps for a printer.
10198
10199Defaults to @samp{"128m"}.
10200@end deftypevr
10201
10202@deftypevr {@code{cups-configuration} parameter} string server-admin
10203Specifies the email address of the server administrator.
10204
10205Defaults to @samp{"root@@localhost.localdomain"}.
10206@end deftypevr
10207
10208@deftypevr {@code{cups-configuration} parameter} host-name-list-or-* server-alias
10209The ServerAlias directive is used for HTTP Host header validation when
10210clients connect to the scheduler from external interfaces. Using the
10211special name @code{*} can expose your system to known browser-based DNS
10212rebinding attacks, even when accessing sites through a firewall. If the
10213auto-discovery of alternate names does not work, we recommend listing
10214each alternate name with a ServerAlias directive instead of using
10215@code{*}.
10216
10217Defaults to @samp{*}.
10218@end deftypevr
10219
10220@deftypevr {@code{cups-configuration} parameter} string server-name
10221Specifies the fully-qualified host name of the server.
10222
10223Defaults to @samp{"localhost"}.
10224@end deftypevr
10225
10226@deftypevr {@code{cups-configuration} parameter} server-tokens server-tokens
10227Specifies what information is included in the Server header of HTTP
10228responses. @code{None} disables the Server header. @code{ProductOnly}
10229reports @code{CUPS}. @code{Major} reports @code{CUPS 2}. @code{Minor}
10230reports @code{CUPS 2.0}. @code{Minimal} reports @code{CUPS 2.0.0}.
10231@code{OS} reports @code{CUPS 2.0.0 (@var{uname})} where @var{uname} is
10232the output of the @code{uname} command. @code{Full} reports @code{CUPS
102332.0.0 (@var{uname}) IPP/2.0}.
10234
10235Defaults to @samp{Minimal}.
10236@end deftypevr
10237
10238@deftypevr {@code{cups-configuration} parameter} string set-env
10239Set the specified environment variable to be passed to child processes.
10240
10241Defaults to @samp{"variable value"}.
10242@end deftypevr
10243
10244@deftypevr {@code{cups-configuration} parameter} multiline-string-list ssl-listen
10245Listens on the specified interfaces for encrypted connections. Valid
10246values are of the form @var{address}:@var{port}, where @var{address} is
10247either an IPv6 address enclosed in brackets, an IPv4 address, or
10248@code{*} to indicate all addresses.
10249
10250Defaults to @samp{()}.
10251@end deftypevr
10252
10253@deftypevr {@code{cups-configuration} parameter} ssl-options ssl-options
10254Sets encryption options. By default, CUPS only supports encryption
10255using TLS v1.0 or higher using known secure cipher suites. The
10256@code{AllowRC4} option enables the 128-bit RC4 cipher suites, which are
10257required for some older clients that do not implement newer ones. The
10258@code{AllowSSL3} option enables SSL v3.0, which is required for some
10259older clients that do not support TLS v1.0.
10260
10261Defaults to @samp{()}.
10262@end deftypevr
10263
10264@deftypevr {@code{cups-configuration} parameter} boolean strict-conformance?
10265Specifies whether the scheduler requires clients to strictly adhere to
10266the IPP specifications.
10267
10268Defaults to @samp{#f}.
10269@end deftypevr
10270
10271@deftypevr {@code{cups-configuration} parameter} non-negative-integer timeout
10272Specifies the HTTP request timeout, in seconds.
10273
10274Defaults to @samp{300}.
10275
10276@end deftypevr
10277
10278@deftypevr {@code{cups-configuration} parameter} boolean web-interface?
10279Specifies whether the web interface is enabled.
10280
10281Defaults to @samp{#f}.
10282@end deftypevr
10283
10284At this point you're probably thinking ``oh dear, Guix manual, I like
10285you but you can stop already with the configuration options''. Indeed.
10286However, one more point: it could be that you have an existing
10287@code{cupsd.conf} that you want to use. In that case, you can pass an
10288@code{opaque-cups-configuration} as the configuration of a
10289@code{cups-service-type}.
10290
10291Available @code{opaque-cups-configuration} fields are:
10292
10293@deftypevr {@code{opaque-cups-configuration} parameter} package cups
10294The CUPS package.
10295@end deftypevr
10296
10297@deftypevr {@code{opaque-cups-configuration} parameter} string cupsd.conf
10298The contents of the @code{cupsd.conf}, as a string.
10299@end deftypevr
10300
10301@deftypevr {@code{opaque-cups-configuration} parameter} string cups-files.conf
10302The contents of the @code{cups-files.conf} file, as a string.
10303@end deftypevr
10304
10305For example, if your @code{cupsd.conf} and @code{cups-files.conf} are in
10306strings of the same name, you could instantiate a CUPS service like
10307this:
10308
10309@example
10310(service cups-service-type
10311 (opaque-cups-configuration
10312 (cupsd.conf cupsd.conf)
10313 (cups-files.conf cups-files.conf)))
10314@end example
10315
10316
fe1a39d3
LC
10317@node Desktop Services
10318@subsubsection Desktop Services
aa4ed923 10319
fe1a39d3
LC
10320The @code{(gnu services desktop)} module provides services that are
10321usually useful in the context of a ``desktop'' setup---that is, on a
10322machine running a graphical display server, possibly with graphical user
7a2413e4
AW
10323interfaces, etc. It also defines services that provide specific desktop
10324environments like GNOME and XFCE.
aa4ed923 10325
4467be21
LC
10326To simplify things, the module defines a variable containing the set of
10327services that users typically expect on a machine with a graphical
10328environment and networking:
10329
10330@defvr {Scheme Variable} %desktop-services
10331This is a list of services that builds upon @var{%base-services} and
1068f26b 10332adds or adjusts services for a typical ``desktop'' setup.
4467be21
LC
10333
10334In particular, it adds a graphical login manager (@pxref{X Window,
6726282b
LC
10335@code{slim-service}}), screen lockers,
10336a network management tool (@pxref{Networking
4467be21 10337Services, @code{wicd-service}}), energy and color management services,
4650a77e 10338the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
10339the GeoClue location service, an NTP client (@pxref{Networking
10340Services}), the Avahi daemon, and has the name service switch service
10341configured to be able to use @code{nss-mdns} (@pxref{Name Service
10342Switch, mDNS}).
4467be21
LC
10343@end defvr
10344
10345The @var{%desktop-services} variable can be used as the @code{services}
10346field of an @code{operating-system} declaration (@pxref{operating-system
10347Reference, @code{services}}).
10348
7a2413e4
AW
10349Additionally, the @code{gnome-desktop-service} and
10350@code{xfce-desktop-service} procedures can add GNOME and/or XFCE to a
10351system. To ``add GNOME'' means that system-level services like the
10352backlight adjustment helpers and the power management utilities are
10353added to the system, extending @code{polkit} and @code{dbus}
10354appropriately, allowing GNOME to operate with elevated privileges on a
10355limited number of special-purpose system interfaces. Additionally,
10356adding a service made by @code{gnome-desktop-service} adds the GNOME
10357metapackage to the system profile. Likewise, adding the XFCE service
10358not only adds the @code{xfce} metapackage to the system profile, but it
10359also gives the Thunar file manager the ability to open a ``root-mode''
10360file management window, if the user authenticates using the
10361administrator's password via the standard polkit graphical interface.
10362
10363@deffn {Scheme Procedure} gnome-desktop-service
10364Return a service that adds the @code{gnome} package to the system
10365profile, and extends polkit with the actions from
10366@code{gnome-settings-daemon}.
10367@end deffn
10368
10369@deffn {Scheme Procedure} xfce-desktop-service
10370Return a service that adds the @code{xfce} package to the system profile,
5741e3e5 10371and extends polkit with the ability for @code{thunar} to manipulate the
7a2413e4
AW
10372file system as root from within a user session, after the user has
10373authenticated with the administrator's password.
10374@end deffn
10375
10376Because the GNOME and XFCE desktop services pull in so many packages,
10377the default @code{%desktop-services} variable doesn't include either of
10378them by default. To add GNOME or XFCE, just @code{cons} them onto
10379@code{%desktop-services} in the @code{services} field of your
10380@code{operating-system}:
10381
10382@example
10383(use-modules (gnu))
10384(use-service-modules desktop)
10385(operating-system
10386 ...
10387 ;; cons* adds items to the list given as its last argument.
10388 (services (cons* (gnome-desktop-service)
10389 (xfce-desktop-service)
10390 %desktop-services))
10391 ...)
10392@end example
10393
10394These desktop environments will then be available as options in the
10395graphical login window.
10396
10397The actual service definitions included in @code{%desktop-services} and
10398provided by @code{(gnu services dbus)} and @code{(gnu services desktop)}
10399are described below.
4467be21 10400
0adfe95a 10401@deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
fe1a39d3
LC
10402Return a service that runs the ``system bus'', using @var{dbus}, with
10403support for @var{services}.
aa4ed923 10404
fe1a39d3
LC
10405@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
10406facility. Its system bus is used to allow system services to communicate
1068f26b 10407and to be notified of system-wide events.
aa4ed923 10408
fe1a39d3
LC
10409@var{services} must be a list of packages that provide an
10410@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
10411and policy files. For example, to allow avahi-daemon to use the system bus,
10412@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
10413@end deffn
10414
0adfe95a 10415@deffn {Scheme Procedure} elogind-service [#:config @var{config}]
4650a77e
AW
10416Return a service that runs the @code{elogind} login and
10417seat management daemon. @uref{https://github.com/andywingo/elogind,
10418Elogind} exposes a D-Bus interface that can be used to know which users
10419are logged in, know what kind of sessions they have open, suspend the
10420system, inhibit system suspend, reboot the system, and other tasks.
10421
10422Elogind handles most system-level power events for a computer, for
10423example suspending the system when a lid is closed, or shutting it down
10424when the power button is pressed.
10425
10426The @var{config} keyword argument specifies the configuration for
1068f26b 10427elogind, and should be the result of an @code{(elogind-configuration
4650a77e
AW
10428(@var{parameter} @var{value})...)} invocation. Available parameters and
10429their default values are:
10430
10431@table @code
10432@item kill-user-processes?
10433@code{#f}
10434@item kill-only-users
10435@code{()}
10436@item kill-exclude-users
10437@code{("root")}
10438@item inhibit-delay-max-seconds
10439@code{5}
10440@item handle-power-key
10441@code{poweroff}
10442@item handle-suspend-key
10443@code{suspend}
10444@item handle-hibernate-key
10445@code{hibernate}
10446@item handle-lid-switch
10447@code{suspend}
10448@item handle-lid-switch-docked
10449@code{ignore}
10450@item power-key-ignore-inhibited?
10451@code{#f}
10452@item suspend-key-ignore-inhibited?
10453@code{#f}
10454@item hibernate-key-ignore-inhibited?
10455@code{#f}
10456@item lid-switch-ignore-inhibited?
10457@code{#t}
10458@item holdoff-timeout-seconds
10459@code{30}
10460@item idle-action
10461@code{ignore}
10462@item idle-action-seconds
10463@code{(* 30 60)}
10464@item runtime-directory-size-percent
10465@code{10}
10466@item runtime-directory-size
10467@code{#f}
10468@item remove-ipc?
10469@code{#t}
10470@item suspend-state
10471@code{("mem" "standby" "freeze")}
10472@item suspend-mode
10473@code{()}
10474@item hibernate-state
10475@code{("disk")}
10476@item hibernate-mode
10477@code{("platform" "shutdown")}
10478@item hybrid-sleep-state
10479@code{("disk")}
10480@item hybrid-sleep-mode
10481@code{("suspend" "platform" "shutdown")}
10482@end table
10483@end deffn
10484
be1c2c54 10485@deffn {Scheme Procedure} polkit-service @
4650a77e 10486 [#:polkit @var{polkit}]
222e3319
LC
10487Return a service that runs the
10488@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
10489management service}, which allows system administrators to grant access to
10490privileged operations in a structured way. By querying the Polkit service, a
10491privileged system component can know when it should grant additional
10492capabilities to ordinary users. For example, an ordinary user can be granted
10493the capability to suspend the system if the user is logged in locally.
4650a77e
AW
10494@end deffn
10495
be1c2c54 10496@deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
be234128
AW
10497 [#:watts-up-pro? #f] @
10498 [#:poll-batteries? #t] @
10499 [#:ignore-lid? #f] @
10500 [#:use-percentage-for-policy? #f] @
10501 [#:percentage-low 10] @
10502 [#:percentage-critical 3] @
10503 [#:percentage-action 2] @
10504 [#:time-low 1200] @
10505 [#:time-critical 300] @
10506 [#:time-action 120] @
10507 [#:critical-power-action 'hybrid-sleep]
10508Return a service that runs @uref{http://upower.freedesktop.org/,
10509@command{upowerd}}, a system-wide monitor for power consumption and battery
10510levels, with the given configuration settings. It implements the
10511@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
10512GNOME.
10513@end deffn
10514
2b9e0a94
LC
10515@deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
10516Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
10517UDisks}, a @dfn{disk management} daemon that provides user interfaces with
10518notifications and ways to mount/unmount disks. Programs that talk to UDisks
10519include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
10520@end deffn
10521
be1c2c54 10522@deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7ce597ff
AW
10523Return a service that runs @command{colord}, a system service with a D-Bus
10524interface to manage the color profiles of input and output devices such as
10525screens and scanners. It is notably used by the GNOME Color Manager graphical
10526tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
10527site} for more information.
10528@end deffn
10529
cee32ee4 10530@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
1068f26b 10531Return a configuration allowing an application to access GeoClue
cee32ee4
AW
10532location data. @var{name} is the Desktop ID of the application, without
10533the @code{.desktop} part. If @var{allowed?} is true, the application
10534will have access to location information by default. The boolean
1068f26b 10535@var{system?} value indicates whether an application is a system component
cee32ee4
AW
10536or not. Finally @var{users} is a list of UIDs of all users for which
10537this application is allowed location info access. An empty users list
10538means that all users are allowed.
10539@end deffn
10540
10541@defvr {Scheme Variable} %standard-geoclue-applications
10542The standard list of well-known GeoClue application configurations,
1068f26b
AE
10543granting authority to the GNOME date-and-time utility to ask for the
10544current location in order to set the time zone, and allowing the
10545IceCat and Epiphany web browsers to request location information.
10546IceCat and Epiphany both query the user before allowing a web page to
cee32ee4
AW
10547know the user's location.
10548@end defvr
10549
be1c2c54 10550@deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
cee32ee4
AW
10551 [#:whitelist '()] @
10552 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
10553 [#:submit-data? #f]
10554 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
10555 [#:submission-nick "geoclue"] @
10556 [#:applications %standard-geoclue-applications]
10557Return a service that runs the GeoClue location service. This service
10558provides a D-Bus interface to allow applications to request access to a
10559user's physical location, and optionally to add information to online
10560location databases. See
10561@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
10562web site} for more information.
10563@end deffn
10564
922e21f4
SB
10565@deffn {Scheme Procedure} bluetooth-service [#:bluez @var{bluez}]
10566Return a service that runs the @command{bluetoothd} daemon, which manages
10567all the Bluetooth devices and provides a number of D-Bus interfaces.
10568
10569Users need to be in the @code{lp} group to access the D-Bus service.
10570@end deffn
10571
105369a4
DT
10572@node Database Services
10573@subsubsection Database Services
10574
e32171ee
JD
10575@cindex database
10576@cindex SQL
6575183b 10577The @code{(gnu services databases)} module provides the following services.
105369a4 10578
be1c2c54 10579@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
2d3d5cc5 10580 [#:config-file] [#:data-directory ``/var/lib/postgresql/data''] @
e05b780a 10581 [#:port 5432] [#:locale ``en_US.utf8'']
105369a4
DT
10582Return a service that runs @var{postgresql}, the PostgreSQL database
10583server.
10584
e05b780a
CB
10585The PostgreSQL daemon loads its runtime configuration from @var{config-file},
10586creates a database cluster with @var{locale} as the default
10587locale, stored in @var{data-directory}. It then listens on @var{port}.
105369a4 10588@end deffn
fe1a39d3 10589
6575183b
SB
10590@deffn {Scheme Procedure} mysql-service [#:config (mysql-configuration)]
10591Return a service that runs @command{mysqld}, the MySQL or MariaDB
10592database server.
10593
10594The optional @var{config} argument specifies the configuration for
c940b8e6 10595@command{mysqld}, which should be a @code{<mysql-configuration>} object.
6575183b
SB
10596@end deffn
10597
10598@deftp {Data Type} mysql-configuration
10599Data type representing the configuration of @var{mysql-service}.
10600
10601@table @asis
10602@item @code{mysql} (default: @var{mariadb})
10603Package object of the MySQL database server, can be either @var{mariadb}
10604or @var{mysql}.
10605
7414de0a 10606For MySQL, a temporary root password will be displayed at activation time.
6575183b 10607For MariaDB, the root password is empty.
4b41febf
CB
10608
10609@item @code{port} (default: @code{3306})
10610TCP port on which the database server listens for incoming connections.
6575183b
SB
10611@end table
10612@end deftp
10613
67cadaca
CB
10614@defvr {Scheme Variable} redis-service-type
10615This is the service type for the @uref{https://redis.io/, Redis}
10616key/value store, whose value is a @code{redis-configuration} object.
10617@end defvr
10618
10619@deftp {Data Type} redis-configuration
10620Data type representing the configuration of redis.
10621
10622@table @asis
10623@item @code{redis} (default: @code{redis})
10624The Redis package to use.
10625
10626@item @code{bind} (default: @code{"127.0.0.1"})
10627Network interface on which to listen.
10628
10629@item @code{port} (default: @code{6379})
10630Port on which to accept connections on, a value of 0 will disable
10631listining on a TCP socket.
10632
10633@item @code{working-directory} (default: @code{"/var/lib/redis"})
10634Directory in which to store the database and related files.
10635@end table
10636@end deftp
10637
d8c18af8
AW
10638@node Mail Services
10639@subsubsection Mail Services
10640
e32171ee
JD
10641@cindex mail
10642@cindex email
d8c18af8 10643The @code{(gnu services mail)} module provides Guix service definitions
f88371e8
SB
10644for email services: IMAP, POP3, and LMTP servers, as well as mail
10645transport agents (MTAs). Lots of acronyms! These services are detailed
10646in the subsections below.
d8c18af8 10647
f88371e8 10648@subsubheading Dovecot Service
d8c18af8
AW
10649
10650@deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
10651Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
10652@end deffn
10653
1068f26b 10654By default, Dovecot does not need much configuration; the default
d8c18af8
AW
10655configuration object created by @code{(dovecot-configuration)} will
10656suffice if your mail is delivered to @code{~/Maildir}. A self-signed
10657certificate will be generated for TLS-protected connections, though
10658Dovecot will also listen on cleartext ports by default. There are a
1068f26b 10659number of options, though, which mail administrators might need to change,
d8c18af8
AW
10660and as is the case with other services, Guix allows the system
10661administrator to specify these parameters via a uniform Scheme interface.
10662
10663For example, to specify that mail is located at @code{maildir~/.mail},
10664one would instantiate the Dovecot service like this:
10665
10666@example
10667(dovecot-service #:config
10668 (dovecot-configuration
10669 (mail-location "maildir:~/.mail")))
10670@end example
10671
10672The available configuration parameters follow. Each parameter
10673definition is preceded by its type; for example, @samp{string-list foo}
10674indicates that the @code{foo} parameter should be specified as a list of
10675strings. There is also a way to specify the configuration as a string,
10676if you have an old @code{dovecot.conf} file that you want to port over
10677from some other system; see the end for more details.
10678
10679@c The following documentation was initially generated by
10680@c (generate-documentation) in (gnu services mail). Manually maintained
10681@c documentation is better, so we shouldn't hesitate to edit below as
10682@c needed. However if the change you want to make to this documentation
10683@c can be done in an automated way, it's probably easier to change
10684@c (generate-documentation) than to make it below and have to deal with
10685@c the churn as dovecot updates.
10686
10687Available @code{dovecot-configuration} fields are:
10688
10689@deftypevr {@code{dovecot-configuration} parameter} package dovecot
10690The dovecot package.
10691@end deftypevr
10692
10693@deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
1068f26b
AE
10694A list of IPs or hosts where to listen for connections. @samp{*}
10695listens on all IPv4 interfaces, @samp{::} listens on all IPv6
d8c18af8
AW
10696interfaces. If you want to specify non-default ports or anything more
10697complex, customize the address and port fields of the
10698@samp{inet-listener} of the specific services you are interested in.
10699@end deftypevr
10700
10701@deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
10702List of protocols we want to serve. Available protocols include
10703@samp{imap}, @samp{pop3}, and @samp{lmtp}.
10704
10705Available @code{protocol-configuration} fields are:
10706
10707@deftypevr {@code{protocol-configuration} parameter} string name
10708The name of the protocol.
10709@end deftypevr
10710
10711@deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
1068f26b 10712UNIX socket path to the master authentication server to find users.
d8c18af8 10713This is used by imap (for shared users) and lda.
1068f26b 10714It defaults to @samp{"/var/run/dovecot/auth-userdb"}.
d8c18af8
AW
10715@end deftypevr
10716
10717@deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
10718Space separated list of plugins to load.
10719@end deftypevr
10720
10721@deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
10722Maximum number of IMAP connections allowed for a user from each IP
10723address. NOTE: The username is compared case-sensitively.
10724Defaults to @samp{10}.
10725@end deftypevr
10726
10727@end deftypevr
10728
10729@deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
10730List of services to enable. Available services include @samp{imap},
10731@samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
10732@samp{lmtp}.
10733
10734Available @code{service-configuration} fields are:
10735
10736@deftypevr {@code{service-configuration} parameter} string kind
10737The service kind. Valid values include @code{director},
10738@code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
10739@code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
10740@code{tcpwrap}, @code{quota-warning}, or anything else.
10741@end deftypevr
10742
10743@deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
1068f26b 10744Listeners for the service. A listener is either a
d8c18af8
AW
10745@code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
10746an @code{inet-listener-configuration}.
10747Defaults to @samp{()}.
10748
10749Available @code{unix-listener-configuration} fields are:
10750
10751@deftypevr {@code{unix-listener-configuration} parameter} file-name path
10752The file name on which to listen.
10753@end deftypevr
10754
10755@deftypevr {@code{unix-listener-configuration} parameter} string mode
10756The access mode for the socket.
10757Defaults to @samp{"0600"}.
10758@end deftypevr
10759
10760@deftypevr {@code{unix-listener-configuration} parameter} string user
f9b9a033 10761The user to own the socket.
d8c18af8
AW
10762Defaults to @samp{""}.
10763@end deftypevr
10764
10765@deftypevr {@code{unix-listener-configuration} parameter} string group
10766The group to own the socket.
10767Defaults to @samp{""}.
10768@end deftypevr
10769
10770
10771Available @code{fifo-listener-configuration} fields are:
10772
10773@deftypevr {@code{fifo-listener-configuration} parameter} file-name path
10774The file name on which to listen.
10775@end deftypevr
10776
10777@deftypevr {@code{fifo-listener-configuration} parameter} string mode
10778The access mode for the socket.
10779Defaults to @samp{"0600"}.
10780@end deftypevr
10781
10782@deftypevr {@code{fifo-listener-configuration} parameter} string user
f9b9a033 10783The user to own the socket.
d8c18af8
AW
10784Defaults to @samp{""}.
10785@end deftypevr
10786
10787@deftypevr {@code{fifo-listener-configuration} parameter} string group
10788The group to own the socket.
10789Defaults to @samp{""}.
10790@end deftypevr
10791
10792
10793Available @code{inet-listener-configuration} fields are:
10794
10795@deftypevr {@code{inet-listener-configuration} parameter} string protocol
10796The protocol to listen for.
10797@end deftypevr
10798
10799@deftypevr {@code{inet-listener-configuration} parameter} string address
10800The address on which to listen, or empty for all addresses.
10801Defaults to @samp{""}.
10802@end deftypevr
10803
10804@deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
10805The port on which to listen.
10806@end deftypevr
10807
10808@deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
10809Whether to use SSL for this service; @samp{yes}, @samp{no}, or
10810@samp{required}.
10811Defaults to @samp{#t}.
10812@end deftypevr
10813
10814@end deftypevr
10815
10816@deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
10817Number of connections to handle before starting a new process.
10818Typically the only useful values are 0 (unlimited) or 1. 1 is more
10819secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
10820Defaults to @samp{1}.
10821@end deftypevr
10822
10823@deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
10824Number of processes to always keep waiting for more connections.
10825Defaults to @samp{0}.
10826@end deftypevr
10827
10828@deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
10829If you set @samp{service-count 0}, you probably need to grow
10830this.
10831Defaults to @samp{256000000}.
10832@end deftypevr
10833
10834@end deftypevr
10835
10836@deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
10837Dict configuration, as created by the @code{dict-configuration}
10838constructor.
10839
10840Available @code{dict-configuration} fields are:
10841
10842@deftypevr {@code{dict-configuration} parameter} free-form-fields entries
10843A list of key-value pairs that this dict should hold.
10844Defaults to @samp{()}.
10845@end deftypevr
10846
10847@end deftypevr
10848
10849@deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
1068f26b 10850A list of passdb configurations, each one created by the
d8c18af8
AW
10851@code{passdb-configuration} constructor.
10852
10853Available @code{passdb-configuration} fields are:
10854
10855@deftypevr {@code{passdb-configuration} parameter} string driver
10856The driver that the passdb should use. Valid values include
10857@samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
10858@samp{static}.
10859Defaults to @samp{"pam"}.
10860@end deftypevr
10861
10862@deftypevr {@code{passdb-configuration} parameter} free-form-args args
10863A list of key-value args to the passdb driver.
10864Defaults to @samp{()}.
10865@end deftypevr
10866
10867@end deftypevr
10868
10869@deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
10870List of userdb configurations, each one created by the
10871@code{userdb-configuration} constructor.
10872
10873Available @code{userdb-configuration} fields are:
10874
10875@deftypevr {@code{userdb-configuration} parameter} string driver
10876The driver that the userdb should use. Valid values include
10877@samp{passwd} and @samp{static}.
10878Defaults to @samp{"passwd"}.
10879@end deftypevr
10880
10881@deftypevr {@code{userdb-configuration} parameter} free-form-args args
10882A list of key-value args to the userdb driver.
10883Defaults to @samp{()}.
10884@end deftypevr
10885
10886@deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
10887Override fields from passwd.
10888Defaults to @samp{()}.
10889@end deftypevr
10890
10891@end deftypevr
10892
10893@deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
10894Plug-in configuration, created by the @code{plugin-configuration}
10895constructor.
10896@end deftypevr
10897
10898@deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
10899List of namespaces. Each item in the list is created by the
10900@code{namespace-configuration} constructor.
10901
10902Available @code{namespace-configuration} fields are:
10903
10904@deftypevr {@code{namespace-configuration} parameter} string name
10905Name for this namespace.
10906@end deftypevr
10907
10908@deftypevr {@code{namespace-configuration} parameter} string type
10909Namespace type: @samp{private}, @samp{shared} or @samp{public}.
10910Defaults to @samp{"private"}.
10911@end deftypevr
10912
10913@deftypevr {@code{namespace-configuration} parameter} string separator
10914Hierarchy separator to use. You should use the same separator for
10915all namespaces or some clients get confused. @samp{/} is usually a good
10916one. The default however depends on the underlying mail storage
10917format.
10918Defaults to @samp{""}.
10919@end deftypevr
10920
10921@deftypevr {@code{namespace-configuration} parameter} string prefix
10922Prefix required to access this namespace. This needs to be
10923different for all namespaces. For example @samp{Public/}.
10924Defaults to @samp{""}.
10925@end deftypevr
10926
10927@deftypevr {@code{namespace-configuration} parameter} string location
1068f26b 10928Physical location of the mailbox. This is in the same format as
d8c18af8
AW
10929mail_location, which is also the default for it.
10930Defaults to @samp{""}.
10931@end deftypevr
10932
10933@deftypevr {@code{namespace-configuration} parameter} boolean inbox?
10934There can be only one INBOX, and this setting defines which
10935namespace has it.
10936Defaults to @samp{#f}.
10937@end deftypevr
10938
10939@deftypevr {@code{namespace-configuration} parameter} boolean hidden?
10940If namespace is hidden, it's not advertised to clients via NAMESPACE
10941extension. You'll most likely also want to set @samp{list? #f}. This is mostly
10942useful when converting from another server with different namespaces
10943which you want to deprecate but still keep working. For example you can
10944create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
10945and @samp{mail/}.
10946Defaults to @samp{#f}.
10947@end deftypevr
10948
10949@deftypevr {@code{namespace-configuration} parameter} boolean list?
1068f26b
AE
10950Show the mailboxes under this namespace with the LIST command. This
10951makes the namespace visible for clients that do not support the NAMESPACE
d8c18af8
AW
10952extension. The special @code{children} value lists child mailboxes, but
10953hides the namespace prefix.
10954Defaults to @samp{#t}.
10955@end deftypevr
10956
10957@deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
10958Namespace handles its own subscriptions. If set to @code{#f}, the
10959parent namespace handles them. The empty prefix should always have this
1068f26b 10960as @code{#t}).
d8c18af8
AW
10961Defaults to @samp{#t}.
10962@end deftypevr
10963
10964@deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
10965List of predefined mailboxes in this namespace.
10966Defaults to @samp{()}.
10967
10968Available @code{mailbox-configuration} fields are:
10969
10970@deftypevr {@code{mailbox-configuration} parameter} string name
10971Name for this mailbox.
10972@end deftypevr
10973
10974@deftypevr {@code{mailbox-configuration} parameter} string auto
10975@samp{create} will automatically create this mailbox.
10976@samp{subscribe} will both create and subscribe to the mailbox.
10977Defaults to @samp{"no"}.
10978@end deftypevr
10979
10980@deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
10981List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
10982Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
10983@code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
10984Defaults to @samp{()}.
10985@end deftypevr
10986
10987@end deftypevr
10988
10989@end deftypevr
10990
10991@deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
10992Base directory where to store runtime data.
10993Defaults to @samp{"/var/run/dovecot/"}.
10994@end deftypevr
10995
10996@deftypevr {@code{dovecot-configuration} parameter} string login-greeting
10997Greeting message for clients.
10998Defaults to @samp{"Dovecot ready."}.
10999@end deftypevr
11000
11001@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
11002List of trusted network ranges. Connections from these IPs are
11003allowed to override their IP addresses and ports (for logging and for
11004authentication checks). @samp{disable-plaintext-auth} is also ignored
1068f26b 11005for these networks. Typically you would specify your IMAP proxy servers
d8c18af8
AW
11006here.
11007Defaults to @samp{()}.
11008@end deftypevr
11009
11010@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
11011List of login access check sockets (e.g. tcpwrap).
11012Defaults to @samp{()}.
11013@end deftypevr
11014
11015@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
11016Show more verbose process titles (in ps). Currently shows user name
1068f26b
AE
11017and IP address. Useful for seeing who is actually using the IMAP
11018processes (e.g. shared mailboxes or if the same uid is used for multiple
d8c18af8
AW
11019accounts).
11020Defaults to @samp{#f}.
11021@end deftypevr
11022
11023@deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
11024Should all processes be killed when Dovecot master process shuts down.
11025Setting this to @code{#f} means that Dovecot can be upgraded without
11026forcing existing client connections to close (although that could also
1068f26b 11027be a problem if the upgrade is e.g. due to a security fix).
d8c18af8
AW
11028Defaults to @samp{#t}.
11029@end deftypevr
11030
11031@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
11032If non-zero, run mail commands via this many connections to doveadm
11033server, instead of running them directly in the same process.
11034Defaults to @samp{0}.
11035@end deftypevr
11036
11037@deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
11038UNIX socket or host:port used for connecting to doveadm server.
11039Defaults to @samp{"doveadm-server"}.
11040@end deftypevr
11041
11042@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
11043List of environment variables that are preserved on Dovecot startup
11044and passed down to all of its child processes. You can also give
11045key=value pairs to always set specific settings.
11046@end deftypevr
11047
11048@deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
11049Disable LOGIN command and all other plaintext authentications unless
11050SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
11051matches the local IP (i.e. you're connecting from the same computer),
11052the connection is considered secure and plaintext authentication is
11053allowed. See also ssl=required setting.
11054Defaults to @samp{#t}.
11055@end deftypevr
11056
11057@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
11058Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
11059Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
11060for caching to be used.
11061Defaults to @samp{0}.
11062@end deftypevr
11063
11064@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
11065Time to live for cached data. After TTL expires the cached record
11066is no longer used, *except* if the main database lookup returns internal
11067failure. We also try to handle password changes automatically: If
11068user's previous authentication was successful, but this one wasn't, the
11069cache isn't used. For now this works only with plaintext
11070authentication.
11071Defaults to @samp{"1 hour"}.
11072@end deftypevr
11073
11074@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
11075TTL for negative hits (user not found, password mismatch).
110760 disables caching them completely.
11077Defaults to @samp{"1 hour"}.
11078@end deftypevr
11079
11080@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
11081List of realms for SASL authentication mechanisms that need them.
11082You can leave it empty if you don't want to support multiple realms.
11083Many clients simply use the first one listed here, so keep the default
11084realm first.
11085Defaults to @samp{()}.
11086@end deftypevr
11087
11088@deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
11089Default realm/domain to use if none was specified. This is used for
11090both SASL realms and appending @@domain to username in plaintext
11091logins.
11092Defaults to @samp{""}.
11093@end deftypevr
11094
11095@deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
11096List of allowed characters in username. If the user-given username
11097contains a character not listed in here, the login automatically fails.
11098This is just an extra check to make sure user can't exploit any
11099potential quote escaping vulnerabilities with SQL/LDAP databases. If
11100you want to allow all characters, set this value to empty.
11101Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
11102@end deftypevr
11103
11104@deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
11105Username character translations before it's looked up from
11106databases. The value contains series of from -> to characters. For
11107example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
11108translated to @samp{@@}.
11109Defaults to @samp{""}.
11110@end deftypevr
11111
11112@deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
11113Username formatting before it's looked up from databases. You can
11114use the standard variables here, e.g. %Lu would lowercase the username,
11115%n would drop away the domain if it was given, or @samp{%n-AT-%d} would
11116change the @samp{@@} into @samp{-AT-}. This translation is done after
11117@samp{auth-username-translation} changes.
11118Defaults to @samp{"%Lu"}.
11119@end deftypevr
11120
11121@deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
11122If you want to allow master users to log in by specifying the master
11123username within the normal username string (i.e. not using SASL
11124mechanism's support for it), you can specify the separator character
11125here. The format is then <username><separator><master username>.
11126UW-IMAP uses @samp{*} as the separator, so that could be a good
11127choice.
11128Defaults to @samp{""}.
11129@end deftypevr
11130
11131@deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
11132Username to use for users logging in with ANONYMOUS SASL
11133mechanism.
11134Defaults to @samp{"anonymous"}.
11135@end deftypevr
11136
11137@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
11138Maximum number of dovecot-auth worker processes. They're used to
11139execute blocking passdb and userdb queries (e.g. MySQL and PAM).
11140They're automatically created and destroyed as needed.
11141Defaults to @samp{30}.
11142@end deftypevr
11143
11144@deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
11145Host name to use in GSSAPI principal names. The default is to use
11146the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
11147allow all keytab entries.
11148Defaults to @samp{""}.
11149@end deftypevr
11150
11151@deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
11152Kerberos keytab to use for the GSSAPI mechanism. Will use the
8b499030 11153system default (usually @file{/etc/krb5.keytab}) if not specified. You may
d8c18af8
AW
11154need to change the auth service to run as root to be able to read this
11155file.
11156Defaults to @samp{""}.
11157@end deftypevr
11158
11159@deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
11160Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
11161and @samp{ntlm-auth} helper.
11162<doc/wiki/Authentication/Mechanisms/Winbind.txt>.
11163Defaults to @samp{#f}.
11164@end deftypevr
11165
11166@deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
11167Path for Samba's @samp{ntlm-auth} helper binary.
11168Defaults to @samp{"/usr/bin/ntlm_auth"}.
11169@end deftypevr
11170
11171@deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
11172Time to delay before replying to failed authentications.
11173Defaults to @samp{"2 secs"}.
11174@end deftypevr
11175
11176@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
11177Require a valid SSL client certificate or the authentication
11178fails.
11179Defaults to @samp{#f}.
11180@end deftypevr
11181
11182@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
11183Take the username from client's SSL certificate, using
11184@code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
11185CommonName.
11186Defaults to @samp{#f}.
11187@end deftypevr
11188
11189@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
11190List of wanted authentication mechanisms. Supported mechanisms are:
11191@samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
11192@samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
11193@samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
11194@samp{disable-plaintext-auth} setting.
11195@end deftypevr
11196
11197@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
11198List of IPs or hostnames to all director servers, including ourself.
11199Ports can be specified as ip:port. The default port is the same as what
11200director service's @samp{inet-listener} is using.
11201Defaults to @samp{()}.
11202@end deftypevr
11203
11204@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
11205List of IPs or hostnames to all backend mail servers. Ranges are
11206allowed too, like 10.0.0.10-10.0.0.30.
11207Defaults to @samp{()}.
11208@end deftypevr
11209
11210@deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
11211How long to redirect users to a specific server after it no longer
11212has any connections.
11213Defaults to @samp{"15 min"}.
11214@end deftypevr
11215
11216@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
11217TCP/IP port that accepts doveadm connections (instead of director
11218connections) If you enable this, you'll also need to add
11219@samp{inet-listener} for the port.
11220Defaults to @samp{0}.
11221@end deftypevr
11222
11223@deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
11224How the username is translated before being hashed. Useful values
11225include %Ln if user can log in with or without @@domain, %Ld if mailboxes
11226are shared within domain.
11227Defaults to @samp{"%Lu"}.
11228@end deftypevr
11229
11230@deftypevr {@code{dovecot-configuration} parameter} string log-path
11231Log file to use for error messages. @samp{syslog} logs to syslog,
11232@samp{/dev/stderr} logs to stderr.
11233Defaults to @samp{"syslog"}.
11234@end deftypevr
11235
11236@deftypevr {@code{dovecot-configuration} parameter} string info-log-path
11237Log file to use for informational messages. Defaults to
11238@samp{log-path}.
11239Defaults to @samp{""}.
11240@end deftypevr
11241
11242@deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
11243Log file to use for debug messages. Defaults to
11244@samp{info-log-path}.
11245Defaults to @samp{""}.
11246@end deftypevr
11247
11248@deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
11249Syslog facility to use if you're logging to syslog. Usually if you
11250don't want to use @samp{mail}, you'll use local0..local7. Also other
11251standard facilities are supported.
11252Defaults to @samp{"mail"}.
11253@end deftypevr
11254
11255@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
11256Log unsuccessful authentication attempts and the reasons why they
11257failed.
11258Defaults to @samp{#f}.
11259@end deftypevr
11260
11261@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
11262In case of password mismatches, log the attempted password. Valid
11263values are no, plain and sha1. sha1 can be useful for detecting brute
11264force password attempts vs. user simply trying the same password over
11265and over again. You can also truncate the value to n chars by appending
11266":n" (e.g. sha1:6).
11267Defaults to @samp{#f}.
11268@end deftypevr
11269
11270@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
11271Even more verbose logging for debugging purposes. Shows for example
11272SQL queries.
11273Defaults to @samp{#f}.
11274@end deftypevr
11275
11276@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
11277In case of password mismatches, log the passwords and used scheme so
11278the problem can be debugged. Enabling this also enables
11279@samp{auth-debug}.
11280Defaults to @samp{#f}.
11281@end deftypevr
11282
11283@deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
11284Enable mail process debugging. This can help you figure out why
11285Dovecot isn't finding your mails.
11286Defaults to @samp{#f}.
11287@end deftypevr
11288
11289@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
11290Show protocol level SSL errors.
11291Defaults to @samp{#f}.
11292@end deftypevr
11293
11294@deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
11295Prefix for each line written to log file. % codes are in
11296strftime(3) format.
11297Defaults to @samp{"\"%b %d %H:%M:%S \""}.
11298@end deftypevr
11299
11300@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
11301List of elements we want to log. The elements which have a
11302non-empty variable value are joined together to form a comma-separated
11303string.
11304@end deftypevr
11305
11306@deftypevr {@code{dovecot-configuration} parameter} string login-log-format
11307Login log format. %s contains @samp{login-log-format-elements}
11308string, %$ contains the data we want to log.
11309Defaults to @samp{"%$: %s"}.
11310@end deftypevr
11311
11312@deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
11313Log prefix for mail processes. See doc/wiki/Variables.txt for list
11314of possible variables you can use.
11315Defaults to @samp{"\"%s(%u): \""}.
11316@end deftypevr
11317
11318@deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
11319Format to use for logging mail deliveries. You can use variables:
11320@table @code
11321@item %$
11322Delivery status message (e.g. @samp{saved to INBOX})
11323@item %m
11324Message-ID
11325@item %s
11326Subject
11327@item %f
11328From address
11329@item %p
11330Physical size
11331@item %w
11332Virtual size.
11333@end table
11334Defaults to @samp{"msgid=%m: %$"}.
11335@end deftypevr
11336
11337@deftypevr {@code{dovecot-configuration} parameter} string mail-location
11338Location for users' mailboxes. The default is empty, which means
11339that Dovecot tries to find the mailboxes automatically. This won't work
11340if the user doesn't yet have any mail, so you should explicitly tell
11341Dovecot the full location.
11342
11343If you're using mbox, giving a path to the INBOX
11344file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
11345where the other mailboxes are kept. This is called the "root mail
11346directory", and it must be the first path given in the
11347@samp{mail-location} setting.
11348
11349There are a few special variables you can use, eg.:
11350
11351@table @samp
11352@item %u
11353username
11354@item %n
11355user part in user@@domain, same as %u if there's no domain
11356@item %d
11357domain part in user@@domain, empty if there's no domain
11358@item %h
11359home director
11360@end table
11361
11362See doc/wiki/Variables.txt for full list. Some examples:
11363@table @samp
11364@item maildir:~/Maildir
11365@item mbox:~/mail:INBOX=/var/mail/%u
11366@item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
11367@end table
11368Defaults to @samp{""}.
11369@end deftypevr
11370
11371@deftypevr {@code{dovecot-configuration} parameter} string mail-uid
11372System user and group used to access mails. If you use multiple,
11373userdb can override these by returning uid or gid fields. You can use
11374either numbers or names. <doc/wiki/UserIds.txt>.
11375Defaults to @samp{""}.
11376@end deftypevr
11377
11378@deftypevr {@code{dovecot-configuration} parameter} string mail-gid
11379
11380Defaults to @samp{""}.
11381@end deftypevr
11382
11383@deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
11384Group to enable temporarily for privileged operations. Currently
11385this is used only with INBOX when either its initial creation or
11386dotlocking fails. Typically this is set to "mail" to give access to
11387/var/mail.
11388Defaults to @samp{""}.
11389@end deftypevr
11390
11391@deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
11392Grant access to these supplementary groups for mail processes.
11393Typically these are used to set up access to shared mailboxes. Note
11394that it may be dangerous to set these if users can create
11395symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
11396could allow a user to delete others' mailboxes, or ln -s
11397/secret/shared/box ~/mail/mybox would allow reading it).
11398Defaults to @samp{""}.
11399@end deftypevr
11400
11401@deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
8f65585b 11402Allow full file system access to clients. There's no access checks
d8c18af8
AW
11403other than what the operating system does for the active UID/GID. It
11404works with both maildir and mboxes, allowing you to prefix mailboxes
11405names with e.g. /path/ or ~user/.
11406Defaults to @samp{#f}.
11407@end deftypevr
11408
11409@deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
11410Don't use mmap() at all. This is required if you store indexes to
8f65585b 11411shared file systems (NFS or clustered file system).
d8c18af8
AW
11412Defaults to @samp{#f}.
11413@end deftypevr
11414
11415@deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
11416Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
11417supports @samp{O_EXCL} since version 3, so this should be safe to use
11418nowadays by default.
11419Defaults to @samp{#t}.
11420@end deftypevr
11421
11422@deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
11423When to use fsync() or fdatasync() calls:
11424@table @code
11425@item optimized
11426Whenever necessary to avoid losing important data
11427@item always
11428Useful with e.g. NFS when write()s are delayed
11429@item never
11430Never use it (best performance, but crashes can lose data).
11431@end table
11432Defaults to @samp{"optimized"}.
11433@end deftypevr
11434
11435@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
11436Mail storage exists in NFS. Set this to yes to make Dovecot flush
11437NFS caches whenever needed. If you're using only a single mail server
11438this isn't needed.
11439Defaults to @samp{#f}.
11440@end deftypevr
11441
11442@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
11443Mail index files also exist in NFS. Setting this to yes requires
11444@samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
11445Defaults to @samp{#f}.
11446@end deftypevr
11447
11448@deftypevr {@code{dovecot-configuration} parameter} string lock-method
11449Locking method for index files. Alternatives are fcntl, flock and
11450dotlock. Dotlocking uses some tricks which may create more disk I/O
11451than other locking methods. NFS users: flock doesn't work, remember to
11452change @samp{mmap-disable}.
11453Defaults to @samp{"fcntl"}.
11454@end deftypevr
11455
11456@deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
11457Directory in which LDA/LMTP temporarily stores incoming mails >128
11458kB.
11459Defaults to @samp{"/tmp"}.
11460@end deftypevr
11461
11462@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
11463Valid UID range for users. This is mostly to make sure that users can't
11464log in as daemons or other system users. Note that denying root logins is
11465hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
11466is set to 0.
11467Defaults to @samp{500}.
11468@end deftypevr
11469
11470@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
11471
11472Defaults to @samp{0}.
11473@end deftypevr
11474
11475@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
11476Valid GID range for users. Users having non-valid GID as primary group ID
11477aren't allowed to log in. If user belongs to supplementary groups with
11478non-valid GIDs, those groups are not set.
11479Defaults to @samp{1}.
11480@end deftypevr
11481
11482@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
11483
11484Defaults to @samp{0}.
11485@end deftypevr
11486
11487@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
11488Maximum allowed length for mail keyword name. It's only forced when
11489trying to create new keywords.
11490Defaults to @samp{50}.
11491@end deftypevr
11492
11493@deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
11494List of directories under which chrooting is allowed for mail
11495processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
11496too). This setting doesn't affect @samp{login-chroot}
11497@samp{mail-chroot} or auth chroot settings. If this setting is empty,
11498"/./" in home dirs are ignored. WARNING: Never add directories here
11499which local users can modify, that may lead to root exploit. Usually
11500this should be done only if you don't allow shell access for users.
11501<doc/wiki/Chrooting.txt>.
11502Defaults to @samp{()}.
11503@end deftypevr
11504
11505@deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
11506Default chroot directory for mail processes. This can be overridden
11507for specific users in user database by giving /./ in user's home
11508directory (e.g. /home/./user chroots into /home). Note that usually
11509there is no real need to do chrooting, Dovecot doesn't allow users to
11510access files outside their mail directory anyway. If your home
11511directories are prefixed with the chroot directory, append "/." to
11512@samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
11513Defaults to @samp{""}.
11514@end deftypevr
11515
11516@deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
11517UNIX socket path to master authentication server to find users.
11518This is used by imap (for shared users) and lda.
11519Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
11520@end deftypevr
11521
11522@deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
11523Directory where to look up mail plugins.
11524Defaults to @samp{"/usr/lib/dovecot"}.
11525@end deftypevr
11526
11527@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
11528List of plugins to load for all services. Plugins specific to IMAP,
11529LDA, etc. are added to this list in their own .conf files.
11530Defaults to @samp{()}.
11531@end deftypevr
11532
11533@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
11534The minimum number of mails in a mailbox before updates are done to
11535cache file. This allows optimizing Dovecot's behavior to do less disk
11536writes at the cost of more disk reads.
11537Defaults to @samp{0}.
11538@end deftypevr
11539
11540@deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
11541When IDLE command is running, mailbox is checked once in a while to
11542see if there are any new mails or other changes. This setting defines
11543the minimum time to wait between those checks. Dovecot can also use
11544dnotify, inotify and kqueue to find out immediately when changes
11545occur.
11546Defaults to @samp{"30 secs"}.
11547@end deftypevr
11548
11549@deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
11550Save mails with CR+LF instead of plain LF. This makes sending those
11551mails take less CPU, especially with sendfile() syscall with Linux and
11552FreeBSD. But it also creates a bit more disk I/O which may just make it
11553slower. Also note that if other software reads the mboxes/maildirs,
11554they may handle the extra CRs wrong and cause problems.
11555Defaults to @samp{#f}.
11556@end deftypevr
11557
11558@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
11559By default LIST command returns all entries in maildir beginning
11560with a dot. Enabling this option makes Dovecot return only entries
11561which are directories. This is done by stat()ing each entry, so it
11562causes more disk I/O.
11563 (For systems setting struct @samp{dirent->d_type} this check is free
11564and it's done always regardless of this setting).
11565Defaults to @samp{#f}.
11566@end deftypevr
11567
11568@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
11569When copying a message, do it with hard links whenever possible.
11570This makes the performance much better, and it's unlikely to have any
11571side effects.
11572Defaults to @samp{#t}.
11573@end deftypevr
11574
11575@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
11576Assume Dovecot is the only MUA accessing Maildir: Scan cur/
11577directory only when its mtime changes unexpectedly or when we can't find
11578the mail otherwise.
11579Defaults to @samp{#f}.
11580@end deftypevr
11581
11582@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
11583Which locking methods to use for locking mbox. There are four
11584available:
11585
11586@table @code
11587@item dotlock
11588Create <mailbox>.lock file. This is the oldest and most NFS-safe
11589solution. If you want to use /var/mail/ like directory, the users will
11590need write access to that directory.
11591@item dotlock-try
11592Same as dotlock, but if it fails because of permissions or because there
11593isn't enough disk space, just skip it.
11594@item fcntl
11595Use this if possible. Works with NFS too if lockd is used.
11596@item flock
a01ad638 11597May not exist in all systems. Doesn't work with NFS.
d8c18af8
AW
11598@item lockf
11599May not exist in all systems. Doesn't work with NFS.
11600@end table
11601
11602You can use multiple locking methods; if you do the order they're declared
11603in is important to avoid deadlocks if other MTAs/MUAs are using multiple
11604locking methods as well. Some operating systems don't allow using some of
11605them simultaneously.
11606@end deftypevr
11607
11608@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
11609
11610@end deftypevr
11611
11612@deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
11613Maximum time to wait for lock (all of them) before aborting.
11614Defaults to @samp{"5 mins"}.
11615@end deftypevr
11616
11617@deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
11618If dotlock exists but the mailbox isn't modified in any way,
11619override the lock file after this much time.
11620Defaults to @samp{"2 mins"}.
11621@end deftypevr
11622
11623@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
11624When mbox changes unexpectedly we have to fully read it to find out
11625what changed. If the mbox is large this can take a long time. Since
11626the change is usually just a newly appended mail, it'd be faster to
11627simply read the new mails. If this setting is enabled, Dovecot does
11628this but still safely fallbacks to re-reading the whole mbox file
11629whenever something in mbox isn't how it's expected to be. The only real
11630downside to this setting is that if some other MUA changes message
11631flags, Dovecot doesn't notice it immediately. Note that a full sync is
11632done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
11633Defaults to @samp{#t}.
11634@end deftypevr
11635
11636@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
11637Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
11638EXAMINE, EXPUNGE or CHECK commands. If this is set,
11639@samp{mbox-dirty-syncs} is ignored.
11640Defaults to @samp{#f}.
11641@end deftypevr
11642
11643@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
11644Delay writing mbox headers until doing a full write sync (EXPUNGE
11645and CHECK commands and when closing the mailbox). This is especially
11646useful for POP3 where clients often delete all mails. The downside is
11647that our changes aren't immediately visible to other MUAs.
11648Defaults to @samp{#t}.
11649@end deftypevr
11650
11651@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
11652If mbox size is smaller than this (e.g. 100k), don't write index
11653files. If an index file already exists it's still read, just not
11654updated.
11655Defaults to @samp{0}.
11656@end deftypevr
11657
11658@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
11659Maximum dbox file size until it's rotated.
11660Defaults to @samp{2000000}.
11661@end deftypevr
11662
11663@deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
11664Maximum dbox file age until it's rotated. Typically in days. Day
11665begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
11666disabled.
11667Defaults to @samp{"1d"}.
11668@end deftypevr
11669
11670@deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
11671When creating new mdbox files, immediately preallocate their size to
11672@samp{mdbox-rotate-size}. This setting currently works only in Linux
8f65585b 11673with some file systems (ext4, xfs).
d8c18af8
AW
11674Defaults to @samp{#f}.
11675@end deftypevr
11676
11677@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
11678sdbox and mdbox support saving mail attachments to external files,
11679which also allows single instance storage for them. Other backends
11680don't support this for now.
11681
11682WARNING: This feature hasn't been tested much yet. Use at your own risk.
11683
11684Directory root where to store mail attachments. Disabled, if empty.
11685Defaults to @samp{""}.
11686@end deftypevr
11687
11688@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
11689Attachments smaller than this aren't saved externally. It's also
11690possible to write a plugin to disable saving specific attachments
11691externally.
11692Defaults to @samp{128000}.
11693@end deftypevr
11694
11695@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
8f65585b 11696File system backend to use for saving attachments:
d8c18af8
AW
11697@table @code
11698@item posix
11699No SiS done by Dovecot (but this might help FS's own deduplication)
11700@item sis posix
11701SiS with immediate byte-by-byte comparison during saving
11702@item sis-queue posix
11703SiS with delayed comparison and deduplication.
11704@end table
11705Defaults to @samp{"sis posix"}.
11706@end deftypevr
11707
11708@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
11709Hash format to use in attachment filenames. You can add any text and
11710variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
11711@code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
11712truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
11713Defaults to @samp{"%@{sha1@}"}.
11714@end deftypevr
11715
11716@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
11717
11718Defaults to @samp{100}.
11719@end deftypevr
11720
11721@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
11722
11723Defaults to @samp{1000}.
11724@end deftypevr
11725
11726@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
11727Default VSZ (virtual memory size) limit for service processes.
11728This is mainly intended to catch and kill processes that leak memory
11729before they eat up everything.
11730Defaults to @samp{256000000}.
11731@end deftypevr
11732
11733@deftypevr {@code{dovecot-configuration} parameter} string default-login-user
11734Login user is internally used by login processes. This is the most
11735untrusted user in Dovecot system. It shouldn't have access to anything
11736at all.
11737Defaults to @samp{"dovenull"}.
11738@end deftypevr
11739
11740@deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
11741Internal user is used by unprivileged processes. It should be
11742separate from login user, so that login processes can't disturb other
11743processes.
11744Defaults to @samp{"dovecot"}.
11745@end deftypevr
11746
11747@deftypevr {@code{dovecot-configuration} parameter} string ssl?
11748SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
11749Defaults to @samp{"required"}.
11750@end deftypevr
11751
11752@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
11753PEM encoded X.509 SSL/TLS certificate (public key).
11754Defaults to @samp{"</etc/dovecot/default.pem"}.
11755@end deftypevr
11756
11757@deftypevr {@code{dovecot-configuration} parameter} string ssl-key
11758PEM encoded SSL/TLS private key. The key is opened before
11759dropping root privileges, so keep the key file unreadable by anyone but
11760root.
11761Defaults to @samp{"</etc/dovecot/private/default.pem"}.
11762@end deftypevr
11763
11764@deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
11765If key file is password protected, give the password here.
11766Alternatively give it when starting dovecot with -p parameter. Since
11767this file is often world-readable, you may want to place this setting
11768instead to a different.
11769Defaults to @samp{""}.
11770@end deftypevr
11771
11772@deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
11773PEM encoded trusted certificate authority. Set this only if you
11774intend to use @samp{ssl-verify-client-cert? #t}. The file should
11775contain the CA certificate(s) followed by the matching
11776CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
11777Defaults to @samp{""}.
11778@end deftypevr
11779
11780@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
11781Require that CRL check succeeds for client certificates.
11782Defaults to @samp{#t}.
11783@end deftypevr
11784
11785@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
11786Request client to send a certificate. If you also want to require
11787it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
11788Defaults to @samp{#f}.
11789@end deftypevr
11790
11791@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
11792Which field from certificate to use for username. commonName and
11793x500UniqueIdentifier are the usual choices. You'll also need to set
11794@samp{auth-ssl-username-from-cert? #t}.
11795Defaults to @samp{"commonName"}.
11796@end deftypevr
11797
11798@deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
11799How often to regenerate the SSL parameters file. Generation is
11800quite CPU intensive operation. The value is in hours, 0 disables
11801regeneration entirely.
11802Defaults to @samp{168}.
11803@end deftypevr
11804
11805@deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
11806SSL protocols to use.
11807Defaults to @samp{"!SSLv2"}.
11808@end deftypevr
11809
11810@deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
11811SSL ciphers to use.
11812Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
11813@end deftypevr
11814
11815@deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
11816SSL crypto device to use, for valid values run "openssl engine".
11817Defaults to @samp{""}.
11818@end deftypevr
11819
11820@deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
11821Address to use when sending rejection mails.
66329c23
AW
11822%d expands to recipient domain.
11823Defaults to @samp{"postmaster@@%d"}.
d8c18af8
AW
11824@end deftypevr
11825
11826@deftypevr {@code{dovecot-configuration} parameter} string hostname
11827Hostname to use in various parts of sent mails (e.g. in Message-Id)
11828and in LMTP replies. Default is the system's real hostname@@domain.
11829Defaults to @samp{""}.
11830@end deftypevr
11831
11832@deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
11833If user is over quota, return with temporary failure instead of
11834bouncing the mail.
11835Defaults to @samp{#f}.
11836@end deftypevr
11837
11838@deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
11839Binary to use for sending mails.
11840Defaults to @samp{"/usr/sbin/sendmail"}.
11841@end deftypevr
11842
11843@deftypevr {@code{dovecot-configuration} parameter} string submission-host
11844If non-empty, send mails via this SMTP host[:port] instead of
11845sendmail.
11846Defaults to @samp{""}.
11847@end deftypevr
11848
11849@deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
11850Subject: header to use for rejection mails. You can use the same
11851variables as for @samp{rejection-reason} below.
11852Defaults to @samp{"Rejected: %s"}.
11853@end deftypevr
11854
11855@deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
11856Human readable error message for rejection mails. You can use
11857variables:
11858
11859@table @code
11860@item %n
11861CRLF
11862@item %r
11863reason
11864@item %s
11865original subject
11866@item %t
11867recipient
11868@end table
11869Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
11870@end deftypevr
11871
11872@deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
11873Delimiter character between local-part and detail in email
11874address.
11875Defaults to @samp{"+"}.
11876@end deftypevr
11877
11878@deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
11879Header where the original recipient address (SMTP's RCPT TO:
11880address) is taken from if not available elsewhere. With dovecot-lda -a
11881parameter overrides this. A commonly used header for this is
11882X-Original-To.
11883Defaults to @samp{""}.
11884@end deftypevr
11885
11886@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
11887Should saving a mail to a nonexistent mailbox automatically create
11888it?.
11889Defaults to @samp{#f}.
11890@end deftypevr
11891
11892@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
11893Should automatically created mailboxes be also automatically
11894subscribed?.
11895Defaults to @samp{#f}.
11896@end deftypevr
11897
11898@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
11899Maximum IMAP command line length. Some clients generate very long
11900command lines with huge mailboxes, so you may need to raise this if you
11901get "Too long argument" or "IMAP command line too large" errors
11902often.
11903Defaults to @samp{64000}.
11904@end deftypevr
11905
11906@deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
11907IMAP logout format string:
11908@table @code
11909@item %i
11910total number of bytes read from client
11911@item %o
11912total number of bytes sent to client.
11913@end table
11914Defaults to @samp{"in=%i out=%o"}.
11915@end deftypevr
11916
11917@deftypevr {@code{dovecot-configuration} parameter} string imap-capability
11918Override the IMAP CAPABILITY response. If the value begins with '+',
11919add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
11920Defaults to @samp{""}.
11921@end deftypevr
11922
11923@deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
11924How long to wait between "OK Still here" notifications when client
11925is IDLEing.
11926Defaults to @samp{"2 mins"}.
11927@end deftypevr
11928
11929@deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
11930ID field names and values to send to clients. Using * as the value
11931makes Dovecot use the default value. The following fields have default
11932values currently: name, version, os, os-version, support-url,
11933support-email.
11934Defaults to @samp{""}.
11935@end deftypevr
11936
11937@deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
11938ID fields sent by client to log. * means everything.
11939Defaults to @samp{""}.
11940@end deftypevr
11941
11942@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
11943Workarounds for various client bugs:
11944
11945@table @code
11946@item delay-newmail
11947Send EXISTS/RECENT new mail notifications only when replying to NOOP and
11948CHECK commands. Some clients ignore them otherwise, for example OSX
11949Mail (<v2.1). Outlook Express breaks more badly though, without this it
11950may show user "Message no longer in server" errors. Note that OE6
11951still breaks even with this workaround if synchronization is set to
11952"Headers Only".
11953
11954@item tb-extra-mailbox-sep
11955Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
11956adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
11957ignore the extra @samp{/} instead of treating it as invalid mailbox name.
11958
11959@item tb-lsub-flags
11960Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
11961This makes Thunderbird realize they aren't selectable and show them
11962greyed out, instead of only later giving "not selectable" popup error.
11963@end table
11964Defaults to @samp{()}.
11965@end deftypevr
11966
11967@deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
11968Host allowed in URLAUTH URLs sent by client. "*" allows all.
11969Defaults to @samp{""}.
11970@end deftypevr
11971
11972
11973Whew! Lots of configuration options. The nice thing about it though is
11974that GuixSD has a complete interface to Dovecot's configuration
11975language. This allows not only a nice way to declare configurations,
11976but also offers reflective capabilities as well: users can write code to
11977inspect and transform configurations from within Scheme.
11978
11979However, it could be that you just want to get a @code{dovecot.conf} up
11980and running. In that case, you can pass an
7414de0a 11981@code{opaque-dovecot-configuration} as the @code{#:config} parameter to
d8c18af8
AW
11982@code{dovecot-service}. As its name indicates, an opaque configuration
11983does not have easy reflective capabilities.
11984
11985Available @code{opaque-dovecot-configuration} fields are:
11986
11987@deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
11988The dovecot package.
11989@end deftypevr
11990
11991@deftypevr {@code{opaque-dovecot-configuration} parameter} string string
11992The contents of the @code{dovecot.conf}, as a string.
11993@end deftypevr
11994
11995For example, if your @code{dovecot.conf} is just the empty string, you
11996could instantiate a dovecot service like this:
11997
11998@example
11999(dovecot-service #:config
12000 (opaque-dovecot-configuration
12001 (string "")))
12002@end example
12003
f88371e8
SB
12004@subsubheading OpenSMTPD Service
12005
12006@deffn {Scheme Variable} opensmtpd-service-type
12007This is the type of the @uref{https://www.opensmtpd.org, OpenSMTPD}
12008service, whose value should be an @code{opensmtpd-configuration} object
12009as in this example:
12010
12011@example
12012(service opensmtpd-service-type
12013 (opensmtpd-configuration
12014 (config-file (local-file "./my-smtpd.conf"))))
12015@end example
12016@end deffn
12017
12018@deftp {Data Type} opensmtpd-configuration
12019Data type regresenting the configuration of opensmtpd.
12020
12021@table @asis
12022@item @code{package} (default: @var{opensmtpd})
12023Package object of the OpenSMTPD SMTP server.
12024
12025@item @code{config-file} (default: @var{%default-opensmtpd-file})
12026File-like object of the OpenSMTPD configuration file to use. By default
12027it listens on the loopback network interface, and allows for mail from
12028users and daemons on the local machine, as well as permitting email to
12029remote servers. Run @command{man smtpd.conf} for more information.
12030
12031@end table
12032@end deftp
859e367d 12033
78cef99b
CL
12034@node Messaging Services
12035@subsubsection Messaging Services
12036
12037@cindex messaging
12038@cindex jabber
12039@cindex XMPP
12040The @code{(gnu services messaging)} module provides Guix service
12041definitions for messaging services: currently only Prosody is supported.
12042
12043@subsubheading Prosody Service
12044
12045@deffn {Scheme Variable} prosody-service-type
12046This is the type for the @uref{http://prosody.im, Prosody XMPP
12047communication server}. Its value must be a @code{prosody-configuration}
12048record as in this example:
12049
12050@example
12051(service prosody-service-type
12052 (prosody-configuration
12053 (modules-enabled (cons "groups" %default-modules-enabled))
12054 (int-components
12055 (list
12056 (int-component-configuration
12057 (hostname "conference.example.net")
12058 (plugin "muc")
12059 (mod-muc (mod-muc-configuration)))))
12060 (virtualhosts
12061 (list
12062 (virtualhost-configuration
12063 (domain "example.net"))))))
12064@end example
12065
12066See below for details about @code{prosody-configuration}.
12067
12068@end deffn
12069
12070By default, Prosody does not need much configuration. Only one
12071@code{virtualhosts} field is needed: it specifies the domain you wish
12072Prosody to serve.
12073
12074Prosodyctl will help you generate X.509 certificates and keys:
12075
12076@example
12077prosodyctl cert request example.net
12078@end example
12079
12080The available configuration parameters follow. Each parameter
12081definition is preceded by its type; for example, @samp{string-list foo}
12082indicates that the @code{foo} parameter should be specified as a list of
12083strings. Types starting with @code{maybe-} denote parameters that won't
12084show up in @code{prosody.cfg.lua} when their value is @code{'disabled}.
12085
12086There is also a way to specify the configuration as a string, if you
12087have an old @code{prosody.cfg.lua} file that you want to port over from
12088some other system; see the end for more details.
12089
12090@c The following documentation was initially generated by
12091@c (generate-documentation) in (gnu services messaging). Manually maintained
12092@c documentation is better, so we shouldn't hesitate to edit below as
12093@c needed. However if the change you want to make to this documentation
12094@c can be done in an automated way, it's probably easier to change
12095@c (generate-documentation) than to make it below and have to deal with
12096@c the churn as Prosody updates.
12097
12098Available @code{prosody-configuration} fields are:
12099
12100@deftypevr {@code{prosody-configuration} parameter} package prosody
12101The Prosody package.
12102@end deftypevr
12103
12104@deftypevr {@code{prosody-configuration} parameter} file-name data-path
12105Location of the Prosody data storage directory. See
12106@url{http://prosody.im/doc/configure}.
12107Defaults to @samp{"/var/lib/prosody"}.
12108@end deftypevr
12109
12110@deftypevr {@code{prosody-configuration} parameter} file-name-list plugin-paths
12111Additional plugin directories. They are searched in all the specified
12112paths in order. See @url{http://prosody.im/doc/plugins_directory}.
12113Defaults to @samp{()}.
12114@end deftypevr
12115
12116@deftypevr {@code{prosody-configuration} parameter} string-list admins
12117This is a list of accounts that are admins for the server. Note that you
12118must create the accounts separately. See @url{http://prosody.im/doc/admins} and
12119@url{http://prosody.im/doc/creating_accounts}.
12120Example: @code{(admins '("user1@@example.com" "user2@@example.net"))}
12121Defaults to @samp{()}.
12122@end deftypevr
12123
12124@deftypevr {@code{prosody-configuration} parameter} boolean use-libevent?
12125Enable use of libevent for better performance under high load. See
12126@url{http://prosody.im/doc/libevent}.
12127Defaults to @samp{#f}.
12128@end deftypevr
12129
12130@deftypevr {@code{prosody-configuration} parameter} module-list modules-enabled
12131This is the list of modules Prosody will load on startup. It looks for
12132@code{mod_modulename.lua} in the plugins folder, so make sure that exists too.
12133Documentation on modules can be found at: @url{http://prosody.im/doc/modules}.
12134Defaults to @samp{%default-modules-enabled}.
12135@end deftypevr
12136
12137@deftypevr {@code{prosody-configuration} parameter} string-list modules-disabled
12138@samp{"offline"}, @samp{"c2s"} and @samp{"s2s"} are auto-loaded, but
12139should you want to disable them then add them to this list.
12140Defaults to @samp{()}.
12141@end deftypevr
12142
12143@deftypevr {@code{prosody-configuration} parameter} file-name groups-file
12144Path to a text file where the shared groups are defined. If this path is
12145empty then @samp{mod_groups} does nothing. See
12146@url{http://prosody.im/doc/modules/mod_groups}.
12147Defaults to @samp{"/var/lib/prosody/sharedgroups.txt"}.
12148@end deftypevr
12149
12150@deftypevr {@code{prosody-configuration} parameter} boolean allow-registration?
12151Disable account creation by default, for security. See
12152@url{http://prosody.im/doc/creating_accounts}.
12153Defaults to @samp{#f}.
12154@end deftypevr
12155
12156@deftypevr {@code{prosody-configuration} parameter} maybe-ssl-configuration ssl
12157These are the SSL/TLS-related settings. Most of them are disabled so to
12158use Prosody's defaults. If you do not completely understand these options, do
12159not add them to your config, it is easy to lower the security of your server
12160using them. See @url{http://prosody.im/doc/advanced_ssl_config}.
12161
12162Available @code{ssl-configuration} fields are:
12163
12164@deftypevr {@code{ssl-configuration} parameter} maybe-string protocol
12165This determines what handshake to use.
12166@end deftypevr
12167
12168@deftypevr {@code{ssl-configuration} parameter} file-name key
12169Path to your private key file, relative to @code{/etc/prosody}.
12170Defaults to @samp{"/etc/prosody/certs/key.pem"}.
12171@end deftypevr
12172
12173@deftypevr {@code{ssl-configuration} parameter} file-name certificate
12174Path to your certificate file, relative to @code{/etc/prosody}.
12175Defaults to @samp{"/etc/prosody/certs/cert.pem"}.
12176@end deftypevr
12177
12178@deftypevr {@code{ssl-configuration} parameter} file-name capath
12179Path to directory containing root certificates that you wish Prosody to
12180trust when verifying the certificates of remote servers.
12181Defaults to @samp{"/etc/ssl/certs"}.
12182@end deftypevr
12183
12184@deftypevr {@code{ssl-configuration} parameter} maybe-file-name cafile
12185Path to a file containing root certificates that you wish Prosody to trust.
12186Similar to @code{capath} but with all certificates concatenated together.
12187@end deftypevr
12188
12189@deftypevr {@code{ssl-configuration} parameter} maybe-string-list verify
12190A list of verification options (these mostly map to OpenSSL's
12191@code{set_verify()} flags).
12192@end deftypevr
12193
12194@deftypevr {@code{ssl-configuration} parameter} maybe-string-list options
12195A list of general options relating to SSL/TLS. These map to OpenSSL's
12196@code{set_options()}. For a full list of options available in LuaSec, see the
12197LuaSec source.
12198@end deftypevr
12199
12200@deftypevr {@code{ssl-configuration} parameter} maybe-non-negative-integer depth
12201How long a chain of certificate authorities to check when looking for a
12202trusted root certificate.
12203@end deftypevr
12204
12205@deftypevr {@code{ssl-configuration} parameter} maybe-string ciphers
12206An OpenSSL cipher string. This selects what ciphers Prosody will offer to
12207clients, and in what order.
12208@end deftypevr
12209
12210@deftypevr {@code{ssl-configuration} parameter} maybe-file-name dhparam
12211A path to a file containing parameters for Diffie-Hellman key exchange. You
12212can create such a file with:
12213@code{openssl dhparam -out /etc/prosody/certs/dh-2048.pem 2048}
12214@end deftypevr
12215
12216@deftypevr {@code{ssl-configuration} parameter} maybe-string curve
12217Curve for Elliptic curve Diffie-Hellman. Prosody's default is
12218@samp{"secp384r1"}.
12219@end deftypevr
12220
12221@deftypevr {@code{ssl-configuration} parameter} maybe-string-list verifyext
12222A list of "extra" verification options.
12223@end deftypevr
12224
12225@deftypevr {@code{ssl-configuration} parameter} maybe-string password
12226Password for encrypted private keys.
12227@end deftypevr
12228
12229@end deftypevr
12230
12231@deftypevr {@code{prosody-configuration} parameter} boolean c2s-require-encryption?
12232Whether to force all client-to-server connections to be encrypted or not.
12233See @url{http://prosody.im/doc/modules/mod_tls}.
12234Defaults to @samp{#f}.
12235@end deftypevr
12236
12237@deftypevr {@code{prosody-configuration} parameter} boolean s2s-require-encryption?
12238Whether to force all server-to-server connections to be encrypted or not.
12239See @url{http://prosody.im/doc/modules/mod_tls}.
12240Defaults to @samp{#f}.
12241@end deftypevr
12242
12243@deftypevr {@code{prosody-configuration} parameter} boolean s2s-secure-auth?
12244Whether to require encryption and certificate authentication. This
12245provides ideal security, but requires servers you communicate with to support
12246encryption AND present valid, trusted certificates. See
12247@url{http://prosody.im/doc/s2s#security}.
12248Defaults to @samp{#f}.
12249@end deftypevr
12250
12251@deftypevr {@code{prosody-configuration} parameter} string-list s2s-insecure-domains
12252Many servers don't support encryption or have invalid or self-signed
12253certificates. You can list domains here that will not be required to
12254authenticate using certificates. They will be authenticated using DNS. See
12255@url{http://prosody.im/doc/s2s#security}.
12256Defaults to @samp{()}.
12257@end deftypevr
12258
12259@deftypevr {@code{prosody-configuration} parameter} string-list s2s-secure-domains
12260Even if you leave @code{s2s-secure-auth?} disabled, you can still require
12261valid certificates for some domains by specifying a list here. See
12262@url{http://prosody.im/doc/s2s#security}.
12263Defaults to @samp{()}.
12264@end deftypevr
12265
12266@deftypevr {@code{prosody-configuration} parameter} string authentication
12267Select the authentication backend to use. The default provider stores
12268passwords in plaintext and uses Prosody's configured data storage to store the
12269authentication data. If you do not trust your server please see
12270@url{http://prosody.im/doc/modules/mod_auth_internal_hashed} for information
12271about using the hashed backend. See also
12272@url{http://prosody.im/doc/authentication}
12273Defaults to @samp{"internal_plain"}.
12274@end deftypevr
12275
12276@deftypevr {@code{prosody-configuration} parameter} maybe-string log
12277Set logging options. Advanced logging configuration is not yet supported
12278by the GuixSD Prosody Service. See @url{http://prosody.im/doc/logging}.
12279Defaults to @samp{"*syslog"}.
12280@end deftypevr
12281
12282@deftypevr {@code{prosody-configuration} parameter} file-name pidfile
12283File to write pid in. See @url{http://prosody.im/doc/modules/mod_posix}.
12284Defaults to @samp{"/var/run/prosody/prosody.pid"}.
12285@end deftypevr
12286
12287@deftypevr {@code{prosody-configuration} parameter} virtualhost-configuration-list virtualhosts
12288A host in Prosody is a domain on which user accounts can be created. For
12289example if you want your users to have addresses like
12290@samp{"john.smith@@example.com"} then you need to add a host
12291@samp{"example.com"}. All options in this list will apply only to this host.
12292
12293Note: the name "virtual" host is used in configuration to avoid confusion with
12294the actual physical host that Prosody is installed on. A single Prosody
12295instance can serve many domains, each one defined as a VirtualHost entry in
12296Prosody's configuration. Conversely a server that hosts a single domain would
12297have just one VirtualHost entry.
12298
12299See @url{http://prosody.im/doc/configure#virtual_host_settings}.
12300
12301Available @code{virtualhost-configuration} fields are:
12302
12303all these @code{prosody-configuration} fields: @code{admins}, @code{use-libevent?}, @code{modules-enabled}, @code{modules-disabled}, @code{groups-file}, @code{allow-registration?}, @code{ssl}, @code{c2s-require-encryption?}, @code{s2s-require-encryption?}, @code{s2s-secure-auth?}, @code{s2s-insecure-domains}, @code{s2s-secure-domains}, @code{authentication}, @code{log}, plus:
12304@deftypevr {@code{virtualhost-configuration} parameter} string domain
12305Domain you wish Prosody to serve.
12306@end deftypevr
12307
12308@end deftypevr
12309
12310@deftypevr {@code{prosody-configuration} parameter} int-component-configuration-list int-components
12311Components are extra services on a server which are available to clients,
12312usually on a subdomain of the main server (such as
12313@samp{"mycomponent.example.com"}). Example components might be chatroom
12314servers, user directories, or gateways to other protocols.
12315
12316Internal components are implemented with Prosody-specific plugins. To add an
12317internal component, you simply fill the hostname field, and the plugin you wish
12318to use for the component.
12319
12320See @url{http://prosody.im/doc/components}.
12321Defaults to @samp{()}.
12322
12323Available @code{int-component-configuration} fields are:
12324
12325all these @code{prosody-configuration} fields: @code{admins}, @code{use-libevent?}, @code{modules-enabled}, @code{modules-disabled}, @code{groups-file}, @code{allow-registration?}, @code{ssl}, @code{c2s-require-encryption?}, @code{s2s-require-encryption?}, @code{s2s-secure-auth?}, @code{s2s-insecure-domains}, @code{s2s-secure-domains}, @code{authentication}, @code{log}, plus:
12326@deftypevr {@code{int-component-configuration} parameter} string hostname
12327Hostname of the component.
12328@end deftypevr
12329
12330@deftypevr {@code{int-component-configuration} parameter} string plugin
12331Plugin you wish to use for the component.
12332@end deftypevr
12333
12334@deftypevr {@code{int-component-configuration} parameter} maybe-mod-muc-configuration mod-muc
12335Multi-user chat (MUC) is Prosody's module for allowing you to create
12336hosted chatrooms/conferences for XMPP users.
12337
12338General information on setting up and using multi-user chatrooms can be found
12339in the "Chatrooms" documentation (@url{http://prosody.im/doc/chatrooms}),
12340which you should read if you are new to XMPP chatrooms.
12341
12342See also @url{http://prosody.im/doc/modules/mod_muc}.
12343
12344Available @code{mod-muc-configuration} fields are:
12345
12346@deftypevr {@code{mod-muc-configuration} parameter} string name
12347The name to return in service discovery responses.
12348Defaults to @samp{"Prosody Chatrooms"}.
12349@end deftypevr
12350
12351@deftypevr {@code{mod-muc-configuration} parameter} string-or-boolean restrict-room-creation
12352If @samp{#t}, this will only allow admins to create new chatrooms.
12353Otherwise anyone can create a room. The value @samp{"local"} restricts room
12354creation to users on the service's parent domain. E.g. @samp{user@@example.com}
12355can create rooms on @samp{rooms.example.com}. The value @samp{"admin"}
12356restricts to service administrators only.
12357Defaults to @samp{#f}.
12358@end deftypevr
12359
12360@deftypevr {@code{mod-muc-configuration} parameter} non-negative-integer max-history-messages
12361Maximum number of history messages that will be sent to the member that has
12362just joined the room.
12363Defaults to @samp{20}.
12364@end deftypevr
12365
12366@end deftypevr
12367
12368@end deftypevr
12369
12370@deftypevr {@code{prosody-configuration} parameter} ext-component-configuration-list ext-components
12371External components use XEP-0114, which most standalone components
12372support. To add an external component, you simply fill the hostname field. See
12373@url{http://prosody.im/doc/components}.
12374Defaults to @samp{()}.
12375
12376Available @code{ext-component-configuration} fields are:
12377
12378all these @code{prosody-configuration} fields: @code{admins}, @code{use-libevent?}, @code{modules-enabled}, @code{modules-disabled}, @code{groups-file}, @code{allow-registration?}, @code{ssl}, @code{c2s-require-encryption?}, @code{s2s-require-encryption?}, @code{s2s-secure-auth?}, @code{s2s-insecure-domains}, @code{s2s-secure-domains}, @code{authentication}, @code{log}, plus:
12379@deftypevr {@code{ext-component-configuration} parameter} string component-secret
12380Password which the component will use to log in.
12381@end deftypevr
12382
12383@deftypevr {@code{ext-component-configuration} parameter} string hostname
12384Hostname of the component.
12385@end deftypevr
12386
12387@end deftypevr
12388
12389@deftypevr {@code{prosody-configuration} parameter} non-negative-integer-list component-ports
12390Port(s) Prosody listens on for component connections.
12391@end deftypevr
12392
12393@deftypevr {@code{prosody-configuration} parameter} string component-interface
12394Interface Prosody listens on for component connections.
12395Defaults to @samp{"127.0.0.1"}.
12396@end deftypevr
12397
12398It could be that you just want to get a @code{prosody.cfg.lua}
12399up and running. In that case, you can pass an
12400@code{opaque-prosody-configuration} record as the value of
12401@code{prosody-service-type}. As its name indicates, an opaque configuration
12402does not have easy reflective capabilities.
12403Available @code{opaque-prosody-configuration} fields are:
12404
12405@deftypevr {@code{opaque-prosody-configuration} parameter} package prosody
12406The prosody package.
12407@end deftypevr
12408
12409@deftypevr {@code{opaque-prosody-configuration} parameter} string prosody.cfg.lua
12410The contents of the @code{prosody.cfg.lua} to use.
12411@end deftypevr
12412
12413For example, if your @code{prosody.cfg.lua} is just the empty
12414string, you could instantiate a prosody service like this:
12415
12416@example
12417(service prosody-service-type
12418 (opaque-prosody-configuration
12419 (prosody.cfg.lua "")))
12420@end example
12421
859e367d
JD
12422@node Kerberos Services
12423@subsubsection Kerberos Services
12424@cindex Kerberos
12425
df31e36a 12426The @code{(gnu services kerberos)} module provides services relating to
859e367d
JD
12427the authentication protocol @dfn{Kerberos}.
12428
8e3f813f
JD
12429@subsubheading Krb5 Service
12430
12431Programs using a Kerberos client library normally
12432expect a configuration file in @file{/etc/krb5.conf}.
12433This service generates such a file from a definition provided in the
12434operating system declaration.
12435It does not cause any daemon to be started.
12436
12437No ``keytab'' files are provided by this service---you must explicitly create them.
12438This service is known to work with the MIT client library, @code{mit-krb5}.
12439Other implementations have not been tested.
12440
12441@defvr {Scheme Variable} krb5-service-type
12442A service type for Kerberos 5 clients.
12443@end defvr
12444
12445@noindent
12446Here is an example of its use:
12447@lisp
12448(service krb5-service-type
12449 (krb5-configuration
12450 (default-realm "EXAMPLE.COM")
12451 (allow-weak-crypto? #t)
12452 (realms (list
12453 (krb5-realm
12454 (name "EXAMPLE.COM")
12455 (admin-server "groucho.example.com")
12456 (kdc "karl.example.com"))
12457 (krb5-realm
12458 (name "ARGRX.EDU")
12459 (admin-server "kerb-admin.argrx.edu")
12460 (kdc "keys.argrx.edu"))))))
12461@end lisp
12462
12463@noindent
12464This example provides a Kerberos@tie{}5 client configuration which:
12465@itemize
12466@item Recognizes two realms, @i{viz:} ``EXAMPLE.COM'' and ``ARGRX.EDU'', both
12467of which have distinct administration servers and key distribution centers;
12468@item Will default to the realm ``EXAMPLE.COM'' if the realm is not explicitly
12469specified by clients;
12470@item Accepts services which only support encryption types known to be weak.
12471@end itemize
12472
12473The @code{krb5-realm} and @code{krb5-configuration} types have many fields.
12474Only the most commonly used ones are described here.
12475For a full list, and more detailed explanation of each, see the MIT
12476@uref{http://web.mit.edu/kerberos/krb5-devel/doc/admin/conf_files/krb5_conf.html,,krb5.conf}
12477documentation.
12478
12479
12480@deftp {Data Type} krb5-realm
12481@cindex realm, kerberos
12482@table @asis
12483@item @code{name}
12484This field is a string identifying the name of the realm.
12485A common convention is to use the fully qualified DNS name of your organization,
12486converted to upper case.
12487
12488@item @code{admin-server}
12489This field is a string identifying the host where the administration server is
12490running.
12491
12492@item @code{kdc}
12493This field is a string identifying the key distribution center
12494for the realm.
12495@end table
12496@end deftp
12497
12498@deftp {Data Type} krb5-configuration
12499
12500@table @asis
12501@item @code{allow-weak-crypto?} (default: @code{#f})
12502If this flag is @code{#t} then services which only offer encryption algorithms
12503known to be weak will be accepted.
12504
12505@item @code{default-realm} (default: @code{#f})
12506This field should be a string identifying the default Kerberos
12507realm for the client.
12508You should set this field to the name of your Kerberos realm.
12509If this value is @code{#f}
12510then a realm must be specified with every Kerberos principal when invoking programs
12511such as @command{kinit}.
12512
12513@item @code{realms}
12514This should be a non-empty list of @code{krb5-realm} objects, which clients may
12515access.
12516Normally, one of them will have a @code{name} field matching the @code{default-realm}
12517field.
12518@end table
12519@end deftp
12520
12521
859e367d
JD
12522@subsubheading PAM krb5 Service
12523@cindex pam-krb5
12524
df31e36a 12525The @code{pam-krb5} service allows for login authentication and password
859e367d
JD
12526management via Kerberos.
12527You will need this service if you want PAM enabled applications to authenticate
12528users using Kerberos.
12529
12530@defvr {Scheme Variable} pam-krb5-service-type
12531A service type for the Kerberos 5 PAM module.
12532@end defvr
12533
12534@deftp {Data Type} pam-krb5-configuration
12535Data type representing the configuration of the Kerberos 5 PAM module
12536This type has the following parameters:
12537@table @asis
12538@item @code{pam-krb5} (default: @code{pam-krb5})
12539The pam-krb5 package to use.
12540
12541@item @code{minimum-uid} (default: @code{1000})
12542The smallest user ID for which Kerberos authentications should be attempted.
12543Local accounts with lower values will silently fail to authenticate.
12544@end table
12545@end deftp
12546
12547
58724c48
DT
12548@node Web Services
12549@subsubsection Web Services
12550
e32171ee
JD
12551@cindex web
12552@cindex www
12553@cindex HTTP
58724c48
DT
12554The @code{(gnu services web)} module provides the following service:
12555
be1c2c54 12556@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
58724c48
DT
12557 [#:log-directory ``/var/log/nginx''] @
12558 [#:run-directory ``/var/run/nginx''] @
d338237d 12559 [#:server-list '()] @
cb341293 12560 [#:upstream-list '()] @
d338237d 12561 [#:config-file @code{#f}]
58724c48
DT
12562
12563Return a service that runs @var{nginx}, the nginx web server.
12564
12565The nginx daemon loads its runtime configuration from @var{config-file}.
12566Log files are written to @var{log-directory} and temporary runtime data
12567files are written to @var{run-directory}. For proper operation, these
12568arguments should match what is in @var{config-file} to ensure that the
12569directories are created when the service is activated.
12570
3b9b12ef 12571As an alternative to using a @var{config-file}, @var{server-list} can be
cb341293
CB
12572used to specify the list of @dfn{server blocks} required on the host and
12573@var{upstream-list} can be used to specify a list of @dfn{upstream
12574blocks} to configure. For this to work, use the default value for
12575@var{config-file}.
8c00b838 12576
58724c48
DT
12577@end deffn
12578
d338237d
JL
12579@deffn {Scheme Variable} nginx-service-type
12580This is type for the nginx web server.
12581
12582This service can be extended to add server blocks in addition to the
12583default one, as in this example:
12584
12585@example
12586(simple-service 'my-extra-server nginx-service-type
12587 (list (nginx-server-configuration
12588 (https-port #f)
12589 (root "/srv/http/extra-website"))))
12590@end example
12591@end deffn
12592
3b9b12ef
JL
12593@deftp {Data Type} nginx-server-configuration
12594Data type representing the configuration of an nginx server block.
8c00b838
JL
12595This type has the following parameters:
12596
12597@table @asis
12598@item @code{http-port} (default: @code{80})
12599Nginx will listen for HTTP connection on this port. Set it at @code{#f} if
12600nginx should not listen for HTTP (non secure) connection for this
3b9b12ef 12601@dfn{server block}.
8c00b838
JL
12602
12603@item @code{https-port} (default: @code{443})
12604Nginx will listen for HTTPS connection on this port. Set it at @code{#f} if
3b9b12ef 12605nginx should not listen for HTTPS (secure) connection for this @dfn{server block}.
8c00b838
JL
12606
12607Note that nginx can listen for HTTP and HTTPS connections in the same
3b9b12ef 12608@dfn{server block}.
8c00b838
JL
12609
12610@item @code{server-name} (default: @code{(list 'default)})
3b9b12ef
JL
12611A list of server names this server represents. @code{'default} represents the
12612default server for connections matching no other server.
8c00b838
JL
12613
12614@item @code{root} (default: @code{"/srv/http"})
12615Root of the website nginx will serve.
12616
9c557a69
CB
12617@item @code{locations} (default: @code{'()})
12618A list of @dfn{nginx-location-configuration} or
12619@dfn{nginx-named-location-configuration} records to use within this
12620server block.
12621
8c00b838
JL
12622@item @code{index} (default: @code{(list "index.html")})
12623Index files to look for when clients ask for a directory. If it cannot be found,
12624Nginx will send the list of files in the directory.
12625
12626@item @code{ssl-certificate} (default: @code{"/etc/nginx/cert.pem"})
12627Where to find the certificate for secure connections. Set it to @code{#f} if
12628you don't have a certificate or you don't want to use HTTPS.
12629
12630@item @code{ssl-certificate-key} (default: @code{"/etc/nginx/key.pem"})
12631Where to find the private key for secure connections. Set it to @code{#f} if
12632you don't have a key or you don't want to use HTTPS.
12633
12634@item @code{server-tokens?} (default: @code{#f})
12635Whether the server should add its configuration to response.
12636
12637@end table
12638@end deftp
12639
2be1b471
JL
12640@node VPN Services
12641@subsubsection VPN Services
12642@cindex VPN (virtual private network)
12643@cindex virtual private network (VPN)
12644
12645The @code{(gnu services vpn)} module provides services related to
12646@dfn{virtual private networks} (VPNs). It provides a @emph{client} service for
12647your machine to connect to a VPN, and a @emph{servire} service for your machine
12648to host a VPN. Both services use @uref{https://openvpn.net/, OpenVPN}.
12649
12650@deffn {Scheme Procedure} openvpn-client-service @
12651 [#:config (openvpn-client-configuration)]
12652
12653Return a service that runs @command{openvpn}, a VPN daemon, as a client.
12654@end deffn
12655
12656@deffn {Scheme Procedure} openvpn-server-service @
12657 [#:config (openvpn-server-configuration)]
12658
12659Return a service that runs @command{openvpn}, a VPN daemon, as a server.
12660
12661Both can be run simultaneously.
12662@end deffn
12663
12664@c %automatically generated documentation
12665
12666Available @code{openvpn-client-configuration} fields are:
12667
12668@deftypevr @code{openvpn-client-configuration} parameter package openvpn
12669The OpenVPN package.
12670
12671@end deftypevr
12672
12673@deftypevr @code{openvpn-client-configuration} parameter string pid-file
12674The OpenVPN pid file.
12675
12676Defaults to @samp{"/var/run/openvpn/openvpn.pid"}.
12677
12678@end deftypevr
12679
12680@deftypevr @code{openvpn-client-configuration} parameter proto proto
12681The protocol (UDP or TCP) used to open a channel between clients and
12682servers.
12683
12684Defaults to @samp{udp}.
12685
12686@end deftypevr
12687
12688@deftypevr @code{openvpn-client-configuration} parameter dev dev
12689The device type used to represent the VPN connection.
12690
12691Defaults to @samp{tun}.
12692
12693@end deftypevr
12694
12695@deftypevr @code{openvpn-client-configuration} parameter string ca
12696The certificate authority to check connections against.
12697
12698Defaults to @samp{"/etc/openvpn/ca.crt"}.
12699
12700@end deftypevr
12701
12702@deftypevr @code{openvpn-client-configuration} parameter string cert
12703The certificate of the machine the daemon is running on. It should be
12704signed by the authority given in @code{ca}.
12705
12706Defaults to @samp{"/etc/openvpn/client.crt"}.
12707
12708@end deftypevr
12709
12710@deftypevr @code{openvpn-client-configuration} parameter string key
12711The key of the machine the daemon is running on. It must be the key whose
12712certificate is @code{cert}.
12713
12714Defaults to @samp{"/etc/openvpn/client.key"}.
12715
12716@end deftypevr
12717
12718@deftypevr @code{openvpn-client-configuration} parameter boolean comp-lzo?
12719Whether to use the lzo compression algorithm.
12720
12721Defaults to @samp{#t}.
12722
12723@end deftypevr
12724
12725@deftypevr @code{openvpn-client-configuration} parameter boolean persist-key?
12726Don't re-read key files across SIGUSR1 or --ping-restart.
12727
12728Defaults to @samp{#t}.
12729
12730@end deftypevr
12731
12732@deftypevr @code{openvpn-client-configuration} parameter boolean persist-tun?
12733Don't close and reopen TUN/TAP device or run up/down scripts across
12734SIGUSR1 or --ping-restart restarts.
12735
12736Defaults to @samp{#t}.
12737
12738@end deftypevr
12739
12740@deftypevr @code{openvpn-client-configuration} parameter number verbosity
12741Verbosity level.
12742
12743Defaults to @samp{3}.
12744
12745@end deftypevr
12746
12747@deftypevr @code{openvpn-client-configuration} parameter tls-auth-client tls-auth
12748Add an additional layer of HMAC authentication on top of the TLS control
12749channel to protect against DoS attacks.
12750
12751Defaults to @samp{#f}.
12752
12753@end deftypevr
12754
12755@deftypevr @code{openvpn-client-configuration} parameter key-usage verify-key-usage?
12756Whether to check the server certificate has server usage extension.
12757
12758Defaults to @samp{#t}.
12759
12760@end deftypevr
12761
12762@deftypevr @code{openvpn-client-configuration} parameter bind bind?
12763Bind to a specific local port number.
12764
12765Defaults to @samp{#f}.
12766
12767@end deftypevr
12768
12769@deftypevr @code{openvpn-client-configuration} parameter resolv-retry resolv-retry?
12770Retry resolving server address.
12771
12772Defaults to @samp{#t}.
12773
12774@end deftypevr
12775
12776@deftypevr @code{openvpn-client-configuration} parameter openvpn-remote-list remote
12777A list of remote servers to connect to.
12778
12779Defaults to @samp{()}.
12780
12781Available @code{openvpn-remote-configuration} fields are:
12782
12783@deftypevr @code{openvpn-remote-configuration} parameter string name
12784Server name.
12785
12786Defaults to @samp{"my-server"}.
12787
12788@end deftypevr
12789
12790@deftypevr @code{openvpn-remote-configuration} parameter number port
12791Port number the server listens to.
12792
12793Defaults to @samp{1194}.
12794
12795@end deftypevr
12796
12797@end deftypevr
12798@c %end of automatic openvpn-client documentation
12799
12800@c %automatically generated documentation
12801
12802Available @code{openvpn-server-configuration} fields are:
12803
12804@deftypevr @code{openvpn-server-configuration} parameter package openvpn
12805The OpenVPN package.
12806
12807@end deftypevr
12808
12809@deftypevr @code{openvpn-server-configuration} parameter string pid-file
12810The OpenVPN pid file.
12811
12812Defaults to @samp{"/var/run/openvpn/openvpn.pid"}.
12813
12814@end deftypevr
12815
12816@deftypevr @code{openvpn-server-configuration} parameter proto proto
12817The protocol (UDP or TCP) used to open a channel between clients and
12818servers.
12819
12820Defaults to @samp{udp}.
12821
12822@end deftypevr
12823
12824@deftypevr @code{openvpn-server-configuration} parameter dev dev
12825The device type used to represent the VPN connection.
12826
12827Defaults to @samp{tun}.
12828
12829@end deftypevr
12830
12831@deftypevr @code{openvpn-server-configuration} parameter string ca
12832The certificate authority to check connections against.
12833
12834Defaults to @samp{"/etc/openvpn/ca.crt"}.
12835
12836@end deftypevr
12837
12838@deftypevr @code{openvpn-server-configuration} parameter string cert
12839The certificate of the machine the daemon is running on. It should be
12840signed by the authority given in @code{ca}.
12841
12842Defaults to @samp{"/etc/openvpn/client.crt"}.
12843
12844@end deftypevr
12845
12846@deftypevr @code{openvpn-server-configuration} parameter string key
12847The key of the machine the daemon is running on. It must be the key whose
12848certificate is @code{cert}.
12849
12850Defaults to @samp{"/etc/openvpn/client.key"}.
12851
12852@end deftypevr
12853
12854@deftypevr @code{openvpn-server-configuration} parameter boolean comp-lzo?
12855Whether to use the lzo compression algorithm.
12856
12857Defaults to @samp{#t}.
12858
12859@end deftypevr
12860
12861@deftypevr @code{openvpn-server-configuration} parameter boolean persist-key?
12862Don't re-read key files across SIGUSR1 or --ping-restart.
12863
12864Defaults to @samp{#t}.
12865
12866@end deftypevr
12867
12868@deftypevr @code{openvpn-server-configuration} parameter boolean persist-tun?
12869Don't close and reopen TUN/TAP device or run up/down scripts across
12870SIGUSR1 or --ping-restart restarts.
12871
12872Defaults to @samp{#t}.
12873
12874@end deftypevr
12875
12876@deftypevr @code{openvpn-server-configuration} parameter number verbosity
12877Verbosity level.
12878
12879Defaults to @samp{3}.
12880
12881@end deftypevr
12882
12883@deftypevr @code{openvpn-server-configuration} parameter tls-auth-server tls-auth
12884Add an additional layer of HMAC authentication on top of the TLS control
12885channel to protect against DoS attacks.
12886
12887Defaults to @samp{#f}.
12888
12889@end deftypevr
12890
12891@deftypevr @code{openvpn-server-configuration} parameter number port
12892Specifies the port number on which the server listens.
12893
12894Defaults to @samp{1194}.
12895
12896@end deftypevr
12897
12898@deftypevr @code{openvpn-server-configuration} parameter ip-mask server
12899An ip and mask specifying the subnet inside the virtual network.
12900
12901Defaults to @samp{"10.8.0.0 255.255.255.0"}.
12902
12903@end deftypevr
12904
12905@deftypevr @code{openvpn-server-configuration} parameter cidr6 server-ipv6
12906A CIDR notation specifying the IPv6 subnet inside the virtual network.
12907
12908Defaults to @samp{#f}.
12909
12910@end deftypevr
12911
12912@deftypevr @code{openvpn-server-configuration} parameter string dh
12913The Diffie-Hellman parameters file.
12914
12915Defaults to @samp{"/etc/openvpn/dh2048.pem"}.
12916
12917@end deftypevr
12918
12919@deftypevr @code{openvpn-server-configuration} parameter string ifconfig-pool-persist
12920The file that records client IPs.
12921
12922Defaults to @samp{"/etc/openvpn/ipp.txt"}.
12923
12924@end deftypevr
12925
12926@deftypevr @code{openvpn-server-configuration} parameter gateway redirect-gateway?
12927When true, the server will act as a gateway for its clients.
12928
12929Defaults to @samp{#f}.
12930
12931@end deftypevr
12932
12933@deftypevr @code{openvpn-server-configuration} parameter boolean client-to-client?
12934When true, clients are alowed to talk to each other inside the VPN.
12935
12936Defaults to @samp{#f}.
12937
12938@end deftypevr
12939
12940@deftypevr @code{openvpn-server-configuration} parameter keepalive keepalive
12941Causes ping-like messages to be sent back and forth over the link so
12942that each side knows when the other side has gone down. @code{keepalive}
12943requires a pair. The first element is the period of the ping sending,
12944and the second element is the timeout before considering the other side
12945down.
12946
12947@end deftypevr
12948
12949@deftypevr @code{openvpn-server-configuration} parameter number max-clients
12950The maximum number of clients.
12951
12952Defaults to @samp{100}.
12953
12954@end deftypevr
12955
12956@deftypevr @code{openvpn-server-configuration} parameter string status
12957The status file. This file shows a small report on current connection.
12958It is trunkated and rewritten every minute.
12959
12960Defaults to @samp{"/var/run/openvpn/status"}.
12961
12962@end deftypevr
12963
12964@deftypevr @code{openvpn-server-configuration} parameter openvpn-ccd-list client-config-dir
12965The list of configuration for some clients.
12966
12967Defaults to @samp{()}.
12968
12969Available @code{openvpn-ccd-configuration} fields are:
12970
12971@deftypevr @code{openvpn-ccd-configuration} parameter string name
12972Client name.
12973
12974Defaults to @samp{"client"}.
12975
12976@end deftypevr
12977
12978@deftypevr @code{openvpn-ccd-configuration} parameter ip-mask iroute
12979Client own network
12980
12981Defaults to @samp{#f}.
12982
12983@end deftypevr
12984
12985@deftypevr @code{openvpn-ccd-configuration} parameter ip-mask ifconfig-push
12986Client VPN IP.
12987
12988Defaults to @samp{#f}.
12989
12990@end deftypevr
12991
12992@end deftypevr
12993
12994
12995@c %end of automatic openvpn-server documentation
12996
12997
cb341293
CB
12998@deftp {Data Type} nginx-upstream-configuration
12999Data type representing the configuration of an nginx @code{upstream}
13000block. This type has the following parameters:
13001
13002@table @asis
13003@item @code{name}
13004Name for this group of servers.
13005
13006@item @code{servers}
13007Specify the addresses of the servers in the group. The address can be
13008specified as a IP address (e.g. @samp{127.0.0.1}), domain name
13009(e.g. @samp{backend1.example.com}) or a path to a UNIX socket using the
13010prefix @samp{unix:}. For addresses using an IP address or domain name,
13011the default port is 80, and a different port can be specified
13012explicitly.
13013
13014@end table
13015@end deftp
13016
9c557a69
CB
13017@deftp {Data Type} nginx-location-configuration
13018Data type representing the configuration of an nginx @code{location}
13019block. This type has the following parameters:
13020
13021@table @asis
13022@item @code{uri}
13023URI which this location block matches.
13024
13025@anchor{nginx-location-configuration body}
13026@item @code{body}
13027Body of the location block, specified as a string. This can contain many
13028configuration directives. For example, to pass requests to a upstream
13029server group defined using an @code{nginx-upstream-configuration} block,
13030the following directive would be specified in the body @samp{proxy_pass
13031http://upstream-name;}.
13032
13033@end table
13034@end deftp
13035
13036@deftp {Data Type} nginx-named-location-configuration
13037Data type representing the configuration of an nginx named location
13038block. Named location blocks are used for request redirection, and not
13039used for regular request processing. This type has the following
13040parameters:
13041
13042@table @asis
13043@item @code{name}
13044Name to identify this location block.
13045
13046@item @code{body}
13047@xref{nginx-location-configuration body}, as the body for named location
13048blocks can be used in a similar way to the
13049@code{nginx-location-configuration body}. One restriction is that the
13050body of a named location block cannot contain location blocks.
13051
13052@end table
13053@end deftp
13054
eb419bc9
JD
13055@node Network File System
13056@subsubsection Network File System
13057@cindex NFS
fe1a39d3 13058
eb419bc9
JD
13059The @code{(gnu services nfs)} module provides the following services,
13060which are most commonly used in relation to mounting or exporting
13061directory trees as @dfn{network file systems} (NFS).
d6a07ee6
JD
13062
13063@subsubheading RPC Bind Service
13064@cindex rpcbind
13065
eb419bc9
JD
13066The RPC Bind service provides a facility to map program numbers into
13067universal addresses.
13068Many NFS related services use this facility. Hence it is automatically
13069started when a dependent service starts.
d6a07ee6
JD
13070
13071@defvr {Scheme Variable} rpcbind-service-type
13072A service type for the RPC portmapper daemon.
13073@end defvr
13074
13075
13076@deftp {Data Type} rpcbind-configuration
13077Data type representing the configuration of the RPC Bind Service.
13078This type has the following parameters:
13079@table @asis
13080@item @code{rpcbind} (default: @code{rpcbind})
13081The rpcbind package to use.
13082
13083@item @code{warm-start?} (default: @code{#t})
13084If this parameter is @code{#t}, then the daemon will read a
13085state file on startup thus reloading state information saved by a previous
13086instance.
13087@end table
13088@end deftp
13089
eb419bc9
JD
13090
13091@subsubheading Pipefs Pseudo File System
13092@cindex pipefs
13093@cindex rpc_pipefs
13094
13095The pipefs file system is used to transfer NFS related data
13096between the kernel and user space programs.
13097
13098@defvr {Scheme Variable} pipefs-service-type
13099A service type for the pipefs pseudo file system.
13100@end defvr
13101
13102@deftp {Data Type} pipefs-configuration
13103Data type representing the configuration of the pipefs pseudo file system service.
13104This type has the following parameters:
13105@table @asis
13106@item @code{mount-point} (default: @code{"/var/lib/nfs/rpc_pipefs"})
13107The directory to which the file system is to be attached.
13108@end table
13109@end deftp
13110
13111
13112@subsubheading GSS Daemon Service
13113@cindex GSSD
13114@cindex GSS
13115@cindex global security system
13116
13117The @dfn{global security system} (GSS) daemon provides strong security for RPC
13118based protocols.
13119Before exchanging RPC requests an RPC client must establish a security
13120context. Typically this is done using the Kerberos command @command{kinit}
859e367d 13121or automatically at login time using PAM services (@pxref{Kerberos Services}).
eb419bc9
JD
13122
13123@defvr {Scheme Variable} gss-service-type
13124A service type for the Global Security System (GSS) daemon.
13125@end defvr
13126
13127@deftp {Data Type} gss-configuration
13128Data type representing the configuration of the GSS daemon service.
13129This type has the following parameters:
13130@table @asis
13131@item @code{nfs-utils} (default: @code{nfs-utils})
13132The package in which the @command{rpc.gssd} command is to be found.
13133
13134@item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
13135The directory where the pipefs file system is mounted.
13136
13137@end table
13138@end deftp
13139
13140
13141@subsubheading IDMAP Daemon Service
13142@cindex idmapd
13143@cindex name mapper
13144
13145The idmap daemon service provides mapping between user IDs and user names.
13146Typically it is required in order to access file systems mounted via NFSv4.
13147
13148@defvr {Scheme Variable} idmap-service-type
13149A service type for the Identity Mapper (IDMAP) daemon.
13150@end defvr
13151
13152@deftp {Data Type} idmap-configuration
13153Data type representing the configuration of the IDMAP daemon service.
13154This type has the following parameters:
13155@table @asis
13156@item @code{nfs-utils} (default: @code{nfs-utils})
13157The package in which the @command{rpc.idmapd} command is to be found.
13158
13159@item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
13160The directory where the pipefs file system is mounted.
13161
13162@item @code{domain} (default: @code{#f})
13163The local NFSv4 domain name.
13164This must be a string or @code{#f}.
13165If it is @code{#f} then the daemon will use the host's fully qualified domain name.
13166
13167@end table
13168@end deftp
13169
a7cf4eb6
ML
13170@node Continuous Integration
13171@subsubsection Continuous Integration
13172
13173@cindex continuous integration
13174@uref{https://notabug.org/mthl/cuirass, Cuirass} is a continuous
13175integration tool for Guix. It can be used both for development and for
13176providing substitutes to others (@pxref{Substitutes}).
13177
13178The @code{(gnu services cuirass)} module provides the following service.
13179
231eddc8
LC
13180@defvr {Scheme Procedure} cuirass-service-type
13181The type of the Cuirass service. Its value must be a
13182@code{cuirass-configuration} object, as described below.
13183@end defvr
a7cf4eb6 13184
231eddc8
LC
13185To add build jobs, you have to set the @code{specifications} field of
13186the configuration. Here is an example of a service defining a build job
13187based on a specification that can be found in Cuirass source tree. This
13188service polls the Guix repository and builds a subset of the Guix
13189packages, as prescribed in the @file{gnu-system.scm} example spec:
a7cf4eb6
ML
13190
13191@example
8de938d5
LC
13192(let ((spec #~((#:name . "guix")
13193 (#:url . "git://git.savannah.gnu.org/guix.git")
13194 (#:load-path . ".")
13195
13196 ;; Here we must provide an absolute file name.
13197 ;; We take jobs from one of the examples provided
13198 ;; by Cuirass.
13199 (#:file . #$(file-append
13200 cuirass
13201 "/tests/gnu-system.scm"))
13202
13203 (#:proc . hydra-jobs)
13204 (#:arguments (subset . "hello"))
13205 (#:branch . "master"))))
231eddc8
LC
13206 (service cuirass-service-type
13207 (cuirass-configuration
13208 (specifications #~(list #$spec)))))
a7cf4eb6
ML
13209@end example
13210
231eddc8 13211While information related to build jobs is located directly in the
a7cf4eb6
ML
13212specifications, global settings for the @command{cuirass} process are
13213accessible in other @code{cuirass-configuration} fields.
13214
13215@deftp {Data Type} cuirass-configuration
13216Data type representing the configuration of Cuirass.
13217
13218@table @asis
b17e326f
LC
13219@item @code{log-file} (default: @code{"/var/log/cuirass.log"})
13220Location of the log file.
13221
463995da 13222@item @code{cache-directory} (default: @code{"/var/cache/cuirass"})
a7cf4eb6
ML
13223Location of the repository cache.
13224
13225@item @code{user} (default: @code{"cuirass"})
13226Owner of the @code{cuirass} process.
13227
13228@item @code{group} (default: @code{"cuirass"})
13229Owner's group of the @code{cuirass} process.
13230
13231@item @code{interval} (default: @code{60})
13232Number of seconds between the poll of the repositories followed by the
13233Cuirass jobs.
13234
13235@item @code{database} (default: @code{"/var/run/cuirass/cuirass.db"})
13236Location of sqlite database which contains the build results and previously
13237added specifications.
13238
11b7717d
MO
13239@item @code{port} (default: @code{8080})
13240Port number used by the HTTP server.
13241
8de938d5
LC
13242@item @code{specifications} (default: @code{#~'()})
13243A gexp (@pxref{G-Expressions}) that evaluates to a list of specifications,
13244where a specification is an association list
a7cf4eb6
ML
13245(@pxref{Associations Lists,,, guile, GNU Guile Reference Manual}) whose
13246keys are keywords (@code{#:keyword-example}) as shown in the example
13247above.
13248
13249@item @code{use-substitutes?} (default: @code{#f})
13250This allows using substitutes to avoid building every dependencies of a job
13251from source.
13252
13253@item @code{one-shot?} (default: @code{#f})
13254Only evaluate specifications and build derivations once.
379b6ba5 13255
eb122280
MO
13256@item @code{load-path} (default: @code{'()})
13257This allows users to define their own packages and make them visible to
13258cuirass as in @command{guix build} command.
13259
379b6ba5
LC
13260@item @code{cuirass} (default: @code{cuirass})
13261The Cuirass package to use.
a7cf4eb6
ML
13262@end table
13263@end deftp
eb419bc9
JD
13264
13265@node Miscellaneous Services
13266@subsubsection Miscellaneous Services
13267
13268
8ff4dcbe
DC
13269@cindex lirc
13270@subsubheading Lirc Service
13271
fe1a39d3
LC
13272The @code{(gnu services lirc)} module provides the following service.
13273
be1c2c54 13274@deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
fe1a39d3
LC
13275 [#:device #f] [#:driver #f] [#:config-file #f] @
13276 [#:extra-options '()]
13277Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
13278decodes infrared signals from remote controls.
13279
13280Optionally, @var{device}, @var{driver} and @var{config-file}
13281(configuration file name) may be specified. See @command{lircd} manual
13282for details.
13283
13284Finally, @var{extra-options} is a list of additional command-line options
13285passed to @command{lircd}.
13286@end deffn
13287
00f46905
DC
13288@cindex spice
13289@subsubheading Spice Service
13290
13291The @code{(gnu services spice)} module provides the following service.
13292
13293@deffn {Scheme Procedure} spice-vdagent-service [#:spice-vdagent]
13294Returns a service that runs @url{http://www.spice-space.org,VDAGENT}, a daemon
13295that enables sharing the clipboard with a vm and setting the guest display
13296resolution when the graphical console window resizes.
13297@end deffn
13298
c3d38b2b 13299@subsubsection Dictionary Services
e32171ee 13300@cindex dictionary
c3d38b2b
SB
13301The @code{(gnu services dict)} module provides the following service:
13302
13303@deffn {Scheme Procedure} dicod-service [#:config (dicod-configuration)]
13304Return a service that runs the @command{dicod} daemon, an implementation
13305of DICT server (@pxref{Dicod,,, dico, GNU Dico Manual}).
13306
13307The optional @var{config} argument specifies the configuration for
13308@command{dicod}, which should be a @code{<dicod-configuration>} object, by
13309default it serves the GNU Collaborative International Dictonary of English.
13310
13311You can add @command{open localhost} to your @file{~/.dico} file to make
13312@code{localhost} the default server for @command{dico} client
13313(@pxref{Initialization File,,, dico, GNU Dico Manual}).
13314@end deffn
13315
13316@deftp {Data Type} dicod-configuration
13317Data type representing the configuration of dicod.
13318
13319@table @asis
13320@item @code{dico} (default: @var{dico})
13321Package object of the GNU Dico dictionary server.
13322
a1b48465
LC
13323@item @code{interfaces} (default: @var{'("localhost")})
13324This is the list of IP addresses and ports and possibly socket file
13325names to listen to (@pxref{Server Settings, @code{listen} directive,,
13326dico, GNU Dico Manual}).
13327
c3d38b2b
SB
13328@item @code{databases} (default: @var{(list %dicod-database:gcide)})
13329List of @code{<dicod-database>} objects denoting dictionaries to be served.
13330@end table
13331@end deftp
13332
13333@deftp {Data Type} dicod-database
13334Data type representing a dictionary database.
13335
13336@table @asis
13337@item @code{name}
13338Name of the database, will be used in DICT commands.
13339
13340@item @code{module}
13341Name of the dicod module used by this database
13342(@pxref{Modules,,, dico, GNU Dico Manual}).
13343
13344@item @code{options}
13345List of strings or gexps representing the arguments for the module handler
13346(@pxref{Handlers,,, dico, GNU Dico Manual}).
13347@end table
13348@end deftp
13349
13350@defvr {Scheme Variable} %dicod-database:gcide
13351A @code{<dicod-database>} object serving the GNU Collaborative International
13352Dictonary of English using the @code{gcide} package.
13353@end defvr
fe1a39d3 13354
e01e2c6c 13355@subsubsection Version Control
13356
13357The @code{(gnu services version-control)} module provides the following services:
13358
13359@subsubheading Git daemon service
13360
13361@deffn {Scheme Procedure} git-daemon-service [#:config (git-daemon-configuration)]
13362
13363Return a service that runs @command{git daemon}, a simple TCP server to
13364expose repositiories over the Git protocol for annoymous access.
13365
13366The optional @var{config} argument should be a
13367@code{<git-daemon-configuration>} object, by default it allows read-only
13368access to exported@footnote{By creating the magic file
13369"git-daemon-export-ok" in the repository directory.} repositories under
13370@file{/srv/git}.
13371
13372@end deffn
13373
13374@deftp {Data Type} git-daemon-configuration
13375Data type representing the configuration for @code{git-daemon-service}.
13376
13377@table @asis
13378@item @code{package} (default: @var{git})
13379Package object of the Git distributed version control system.
13380
13381@item @code{export-all?} (default: @var{#f})
13382Whether to allow access for all Git repositories, even if they do not
13383have the @file{git-daemon-export-ok} file.
13384
13385@item @code{base-path} (default: @file{/srv/git})
13386Whether to remap all the path requests as relative to the given path.
13387If you run git daemon with @var{(base-path "/srv/git")} on example.com,
13388then if you later try to pull @code{git://example.com/hello.git}, git
13389daemon will interpret the path as @code{/srv/git/hello.git}.
13390
13391@item @code{user-path} (default: @var{#f})
13392Whether to allow @code{~user} notation to be used in requests. When
13393specified with empty string, requests to @code{git://host/~alice/foo} is
13394taken as a request to access @code{foo} repository in the home directory
13395of user @code{alice}. If @var{(user-path "path")} is specified, the
13396same request is taken as a request to access @code{path/foo} repository
13397in the home directory of user @code{alice}.
13398
13399@item @code{listen} (default: @var{'()})
13400Whether to listen on specific IP addresses or hostnames, defaults to
13401all.
13402
13403@item @code{port} (default: @var{#f})
13404Whether to listen on an alternative port, which defaults to 9418.
13405
13406@item @code{whitelist} (default: @var{'()})
13407If not empty, only allow access to this list of directories.
13408
13409@item @code{extra-options} (default: @var{'()})
13410Extra options will be passed to @code{git daemon}, please run
13411@command{man git-daemon} for more information.
13412
13413@end table
13414@end deftp
13415
0ae8c15a
LC
13416@node Setuid Programs
13417@subsection Setuid Programs
13418
13419@cindex setuid programs
13420Some programs need to run with ``root'' privileges, even when they are
13421launched by unprivileged users. A notorious example is the
4d40227c
LC
13422@command{passwd} program, which users can run to change their
13423password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
13424@file{/etc/shadow} files---something normally restricted to root, for
13425obvious security reasons. To address that, these executables are
13426@dfn{setuid-root}, meaning that they always run with root privileges
13427(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
f7e4ae7f 13428for more info about the setuid mechanism.)
0ae8c15a
LC
13429
13430The store itself @emph{cannot} contain setuid programs: that would be a
13431security issue since any user on the system can write derivations that
13432populate the store (@pxref{The Store}). Thus, a different mechanism is
13433used: instead of changing the setuid bit directly on files that are in
13434the store, we let the system administrator @emph{declare} which programs
13435should be setuid root.
13436
13437The @code{setuid-programs} field of an @code{operating-system}
13438declaration contains a list of G-expressions denoting the names of
13439programs to be setuid-root (@pxref{Using the Configuration System}).
13440For instance, the @command{passwd} program, which is part of the Shadow
13441package, can be designated by this G-expression (@pxref{G-Expressions}):
13442
13443@example
13444#~(string-append #$shadow "/bin/passwd")
13445@end example
13446
13447A default set of setuid programs is defined by the
13448@code{%setuid-programs} variable of the @code{(gnu system)} module.
13449
13450@defvr {Scheme Variable} %setuid-programs
13451A list of G-expressions denoting common programs that are setuid-root.
13452
13453The list includes commands such as @command{passwd}, @command{ping},
13454@command{su}, and @command{sudo}.
13455@end defvr
13456
13457Under the hood, the actual setuid programs are created in the
13458@file{/run/setuid-programs} directory at system activation time. The
13459files in this directory refer to the ``real'' binaries, which are in the
13460store.
13461
efb5e833
LC
13462@node X.509 Certificates
13463@subsection X.509 Certificates
13464
13465@cindex HTTPS, certificates
13466@cindex X.509 certificates
13467@cindex TLS
13468Web servers available over HTTPS (that is, HTTP over the transport-layer
13469security mechanism, TLS) send client programs an @dfn{X.509 certificate}
13470that the client can then use to @emph{authenticate} the server. To do
13471that, clients verify that the server's certificate is signed by a
13472so-called @dfn{certificate authority} (CA). But to verify the CA's
13473signature, clients must have first acquired the CA's certificate.
13474
13475Web browsers such as GNU@tie{}IceCat include their own set of CA
13476certificates, such that they are able to verify CA signatures
13477out-of-the-box.
13478
13479However, most other programs that can talk HTTPS---@command{wget},
13480@command{git}, @command{w3m}, etc.---need to be told where CA
13481certificates can be found.
13482
13483@cindex @code{nss-certs}
13484In GuixSD, this is done by adding a package that provides certificates
13485to the @code{packages} field of the @code{operating-system} declaration
13486(@pxref{operating-system Reference}). GuixSD includes one such package,
13487@code{nss-certs}, which is a set of CA certificates provided as part of
13488Mozilla's Network Security Services.
13489
13490Note that it is @emph{not} part of @var{%base-packages}, so you need to
13491explicitly add it. The @file{/etc/ssl/certs} directory, which is where
13492most applications and libraries look for certificates by default, points
13493to the certificates installed globally.
13494
b3129f2b
LC
13495Unprivileged users, including users of Guix on a foreign distro,
13496can also install their own certificate package in
efb5e833
LC
13497their profile. A number of environment variables need to be defined so
13498that applications and libraries know where to find them. Namely, the
13499OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
13500variables. Some applications add their own environment variables; for
13501instance, the Git version control system honors the certificate bundle
b3129f2b
LC
13502pointed to by the @code{GIT_SSL_CAINFO} environment variable. Thus, you
13503would typically run something like:
efb5e833 13504
b3129f2b
LC
13505@example
13506$ guix package -i nss-certs
13507$ export SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs"
13508$ export SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt"
13509$ export GIT_SSL_CAINFO="$SSL_CERT_FILE"
13510@end example
efb5e833 13511
996ed739
LC
13512@node Name Service Switch
13513@subsection Name Service Switch
13514
13515@cindex name service switch
13516@cindex NSS
13517The @code{(gnu system nss)} module provides bindings to the
1068f26b 13518configuration file of the libc @dfn{name service switch} or @dfn{NSS}
996ed739
LC
13519(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
13520Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
13521extended with new ``name'' lookup methods for system databases, which
13522includes host names, service names, user accounts, and more (@pxref{Name
13523Service Switch, System Databases and Name Service Switch,, libc, The GNU
13524C Library Reference Manual}).
13525
13526The NSS configuration specifies, for each system database, which lookup
13527method is to be used, and how the various methods are chained
13528together---for instance, under which circumstances NSS should try the
13529next method in the list. The NSS configuration is given in the
13530@code{name-service-switch} field of @code{operating-system} declarations
13531(@pxref{operating-system Reference, @code{name-service-switch}}).
13532
4c9050c6
LC
13533@cindex nss-mdns
13534@cindex .local, host name lookup
996ed739 13535As an example, the declaration below configures the NSS to use the
4c9050c6
LC
13536@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
13537back-end}, which supports host name lookups over multicast DNS (mDNS)
13538for host names ending in @code{.local}:
996ed739
LC
13539
13540@example
13541(name-service-switch
13542 (hosts (list %files ;first, check /etc/hosts
13543
13544 ;; If the above did not succeed, try
13545 ;; with 'mdns_minimal'.
13546 (name-service
13547 (name "mdns_minimal")
13548
13549 ;; 'mdns_minimal' is authoritative for
13550 ;; '.local'. When it returns "not found",
13551 ;; no need to try the next methods.
13552 (reaction (lookup-specification
13553 (not-found => return))))
13554
13555 ;; Then fall back to DNS.
13556 (name-service
13557 (name "dns"))
13558
13559 ;; Finally, try with the "full" 'mdns'.
13560 (name-service
13561 (name "mdns")))))
13562@end example
13563
1068f26b
AE
13564Do not worry: the @code{%mdns-host-lookup-nss} variable (see below)
13565contains this configuration, so you will not have to type it if all you
15137a29
LC
13566want is to have @code{.local} host lookup working.
13567
4c9050c6
LC
13568Note that, in this case, in addition to setting the
13569@code{name-service-switch} of the @code{operating-system} declaration,
cc9c1f39
LC
13570you also need to use @code{avahi-service} (@pxref{Networking Services,
13571@code{avahi-service}}), or @var{%desktop-services}, which includes it
13572(@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
13573to the name service cache daemon (@pxref{Base Services,
13574@code{nscd-service}}).
15137a29
LC
13575
13576For convenience, the following variables provide typical NSS
13577configurations.
13578
13579@defvr {Scheme Variable} %default-nss
13580This is the default name service switch configuration, a
13581@code{name-service-switch} object.
13582@end defvr
13583
13584@defvr {Scheme Variable} %mdns-host-lookup-nss
13585This is the name service switch configuration with support for host name
13586lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
13587@end defvr
4c9050c6 13588
996ed739 13589The reference for name service switch configuration is given below. It
1068f26b 13590is a direct mapping of the configuration file format of the C library , so
996ed739
LC
13591please refer to the C library manual for more information (@pxref{NSS
13592Configuration File,,, libc, The GNU C Library Reference Manual}).
1068f26b 13593Compared to the configuration file format of libc NSS, it has the advantage
996ed739 13594not only of adding this warm parenthetic feel that we like, but also
1068f26b 13595static checks: you will know about syntax errors and typos as soon as you
996ed739
LC
13596run @command{guix system}.
13597
996ed739
LC
13598@deftp {Data Type} name-service-switch
13599
13600This is the data type representation the configuration of libc's name
13601service switch (NSS). Each field below represents one of the supported
13602system databases.
13603
13604@table @code
13605@item aliases
13606@itemx ethers
13607@itemx group
13608@itemx gshadow
13609@itemx hosts
13610@itemx initgroups
13611@itemx netgroup
13612@itemx networks
13613@itemx password
13614@itemx public-key
13615@itemx rpc
13616@itemx services
13617@itemx shadow
13618The system databases handled by the NSS. Each of these fields must be a
1068f26b 13619list of @code{<name-service>} objects (see below).
996ed739
LC
13620@end table
13621@end deftp
13622
13623@deftp {Data Type} name-service
13624
13625This is the data type representing an actual name service and the
13626associated lookup action.
13627
13628@table @code
13629@item name
13630A string denoting the name service (@pxref{Services in the NSS
13631configuration,,, libc, The GNU C Library Reference Manual}).
13632
4aee6e60
LC
13633Note that name services listed here must be visible to nscd. This is
13634achieved by passing the @code{#:name-services} argument to
13635@code{nscd-service} the list of packages providing the needed name
13636services (@pxref{Base Services, @code{nscd-service}}).
13637
996ed739
LC
13638@item reaction
13639An action specified using the @code{lookup-specification} macro
13640(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
13641Reference Manual}). For example:
13642
13643@example
13644(lookup-specification (unavailable => continue)
13645 (success => return))
13646@end example
13647@end table
13648@end deftp
0ae8c15a 13649
fd1b1fa2
LC
13650@node Initial RAM Disk
13651@subsection Initial RAM Disk
13652
e32171ee
JD
13653@cindex initrd
13654@cindex initial RAM disk
fd1b1fa2
LC
13655For bootstrapping purposes, the Linux-Libre kernel is passed an
13656@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
1068f26b 13657root file system as well as an initialization script. The latter is
fd1b1fa2
LC
13658responsible for mounting the real root file system, and for loading any
13659kernel modules that may be needed to achieve that.
13660
13661The @code{initrd} field of an @code{operating-system} declaration allows
13662you to specify which initrd you would like to use. The @code{(gnu
13663system linux-initrd)} module provides two ways to build an initrd: the
13664high-level @code{base-initrd} procedure, and the low-level
13665@code{expression->initrd} procedure.
13666
13667The @code{base-initrd} procedure is intended to cover most common uses.
13668For example, if you want to add a bunch of kernel modules to be loaded
13669at boot time, you can define the @code{initrd} field of the operating
13670system declaration like this:
13671
13672@example
52ac153e 13673(initrd (lambda (file-systems . rest)
027981d6
LC
13674 ;; Create a standard initrd that has modules "foo.ko"
13675 ;; and "bar.ko", as well as their dependencies, in
13676 ;; addition to the modules available by default.
52ac153e 13677 (apply base-initrd file-systems
027981d6 13678 #:extra-modules '("foo" "bar")
52ac153e 13679 rest)))
fd1b1fa2
LC
13680@end example
13681
52ac153e 13682The @code{base-initrd} procedure also handles common use cases that
1068f26b
AE
13683involves using the system as a QEMU guest, or as a ``live'' system with
13684volatile root file system.
fd1b1fa2 13685
e90cf6c1
LC
13686The initial RAM disk produced by @code{base-initrd} honors several
13687options passed on the Linux kernel command line (that is, arguments
1068f26b 13688passed @i{via} the @code{linux} command of GRUB, or the
4af2fafd 13689@code{-append} option of QEMU), notably:
e90cf6c1
LC
13690
13691@table @code
13692@item --load=@var{boot}
13693Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
13694program, once it has mounted the root file system.
13695
13696GuixSD uses this option to yield control to a boot program that runs the
dd17bc38 13697service activation programs and then spawns the GNU@tie{}Shepherd, the
e90cf6c1
LC
13698initialization system.
13699
13700@item --root=@var{root}
1068f26b 13701Mount @var{root} as the root file system. @var{root} can be a
e90cf6c1
LC
13702device name like @code{/dev/sda1}, a partition label, or a partition
13703UUID.
13704
13705@item --system=@var{system}
13706Have @file{/run/booted-system} and @file{/run/current-system} point to
13707@var{system}.
13708
13709@item modprobe.blacklist=@var{modules}@dots{}
13710@cindex module, black-listing
13711@cindex black list, of kernel modules
13712Instruct the initial RAM disk as well as the @command{modprobe} command
13713(from the kmod package) to refuse to load @var{modules}. @var{modules}
13714must be a comma-separated list of module names---e.g.,
13715@code{usbkbd,9pnet}.
13716
13717@item --repl
13718Start a read-eval-print loop (REPL) from the initial RAM disk before it
13719tries to load kernel modules and to mount the root file system. Our
13720marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
13721love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
13722Manual}, for more information on Guile's REPL.
13723
13724@end table
13725
13726Now that you know all the features that initial RAM disks produced by
13727@code{base-initrd} provide, here is how to use it and customize it
13728further.
13729
e32171ee
JD
13730@cindex initrd
13731@cindex initial RAM disk
fd1b1fa2 13732@deffn {Monadic Procedure} base-initrd @var{file-systems} @
9059b97d 13733 [#:qemu-networking? #f] [#:virtio? #t] [#:volatile-root? #f] @
52ac153e 13734 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2 13735Return a monadic derivation that builds a generic initrd. @var{file-systems} is
1068f26b 13736a list of file systems to be mounted by the initrd, possibly in addition to
fd1b1fa2 13737the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
13738@var{mapped-devices} is a list of device mappings to realize before
13739@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
13740
13741When @var{qemu-networking?} is true, set up networking with the standard QEMU
1068f26b
AE
13742parameters. When @var{virtio?} is true, load additional modules so that the
13743initrd can be used as a QEMU guest with para-virtualized I/O drivers.
fd1b1fa2
LC
13744
13745When @var{volatile-root?} is true, the root file system is writable but any changes
13746to it are lost.
13747
13748The initrd is automatically populated with all the kernel modules necessary
13749for @var{file-systems} and for the given options. However, additional kernel
13750modules can be listed in @var{extra-modules}. They will be added to the initrd, and
13751loaded at boot time in the order in which they appear.
13752@end deffn
13753
13754Needless to say, the initrds we produce and use embed a
13755statically-linked Guile, and the initialization program is a Guile
13756program. That gives a lot of flexibility. The
13757@code{expression->initrd} procedure builds such an initrd, given the
13758program to run in that initrd.
13759
13760@deffn {Monadic Procedure} expression->initrd @var{exp} @
4ee96a79 13761 [#:guile %guile-static-stripped] [#:name "guile-initrd"]
fd1b1fa2
LC
13762Return a derivation that builds a Linux initrd (a gzipped cpio archive)
13763containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
13764upon booting. All the derivations referenced by @var{exp} are
13765automatically copied to the initrd.
fd1b1fa2
LC
13766@end deffn
13767
88faf933
LC
13768@node GRUB Configuration
13769@subsection GRUB Configuration
13770
13771@cindex GRUB
13772@cindex boot loader
13773
13774The operating system uses GNU@tie{}GRUB as its boot loader
13775(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
1068f26b
AE
13776configured using a @code{grub-configuration} declaration. This data type
13777is exported by the @code{(gnu system grub)} module and described below.
88faf933
LC
13778
13779@deftp {Data Type} grub-configuration
13780The type of a GRUB configuration declaration.
13781
13782@table @asis
13783
13784@item @code{device}
13785This is a string denoting the boot device. It must be a device name
13786understood by the @command{grub-install} command, such as
13787@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
13788GNU GRUB Manual}).
13789
13790@item @code{menu-entries} (default: @code{()})
13791A possibly empty list of @code{menu-entry} objects (see below), denoting
13792entries to appear in the GRUB boot menu, in addition to the current
13793system entry and the entry pointing to previous system generations.
13794
13795@item @code{default-entry} (default: @code{0})
1068f26b
AE
13796The index of the default boot menu entry. Index 0 is for the entry of the
13797current system.
88faf933
LC
13798
13799@item @code{timeout} (default: @code{5})
13800The number of seconds to wait for keyboard input before booting. Set to
138010 to boot immediately, and to -1 to wait indefinitely.
13802
13803@item @code{theme} (default: @var{%default-theme})
13804The @code{grub-theme} object describing the theme to use.
9b06f503
LC
13805
13806@item @code{grub} (default: @code{grub})
13807The GRUB package to use.
88faf933
LC
13808@end table
13809
13810@end deftp
13811
44d5f54e
LC
13812@cindex dual boot
13813@cindex boot menu
88faf933
LC
13814Should you want to list additional boot menu entries @i{via} the
13815@code{menu-entries} field above, you will need to create them with the
44d5f54e
LC
13816@code{menu-entry} form. For example, imagine you want to be able to
13817boot another distro (hard to imagine!), you can define a menu entry
13818along these lines:
13819
13820@example
13821(menu-entry
13822 (label "The Other Distro")
13823 (linux "/boot/old/vmlinux-2.6.32")
13824 (linux-arguments '("root=/dev/sda2"))
13825 (initrd "/boot/old/initrd"))
13826@end example
13827
13828Details below.
88faf933
LC
13829
13830@deftp {Data Type} menu-entry
13831The type of an entry in the GRUB boot menu.
13832
13833@table @asis
13834
13835@item @code{label}
35ed9306 13836The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
13837
13838@item @code{linux}
44d5f54e
LC
13839The Linux kernel image to boot, for example:
13840
13841@example
13842(file-append linux-libre "/bzImage")
13843@end example
88faf933 13844
1ef8b72a
CM
13845It is also possible to specify a device explicitly in the file path
13846using GRUB's device naming convention (@pxref{Naming convention,,, grub,
13847GNU GRUB manual}), for example:
13848
13849@example
13850"(hd0,msdos1)/boot/vmlinuz"
13851@end example
13852
13853If the device is specified explicitly as above, then the @code{device}
13854field is ignored entirely.
13855
88faf933
LC
13856@item @code{linux-arguments} (default: @code{()})
13857The list of extra Linux kernel command-line arguments---e.g.,
13858@code{("console=ttyS0")}.
13859
13860@item @code{initrd}
13861A G-Expression or string denoting the file name of the initial RAM disk
13862to use (@pxref{G-Expressions}).
13863
1ef8b72a
CM
13864@item @code{device} (default: @code{#f})
13865The device where the kernel and initrd are to be found---i.e., the GRUB
13866@dfn{root} for this menu entry (@pxref{root,,, grub, GNU GRUB manual}).
13867
13868This may be a file system label (a string), a file system UUID (a
13869bytevector, @pxref{File Systems}), or @code{#f}, in which case GRUB will
13870search the device containing the file specified by the @code{linux}
13871field (@pxref{search,,, grub, GNU GRUB manual}). It must @emph{not} be
13872an OS device name such as @file{/dev/sda1}.
13873
13874@item @code{device-mount-point} (default: @code{"/"})
13875The mount point of the above device on the system. You probably do not
13876need to change the default value. GuixSD uses it to strip the prefix of
13877store file names for systems where @file{/gnu} or @file{/gnu/store} is
13878on a separate partition.
13879
88faf933
LC
13880@end table
13881@end deftp
13882
13883@c FIXME: Write documentation once it's stable.
13884Themes are created using the @code{grub-theme} form, which is not
13885documented yet.
13886
13887@defvr {Scheme Variable} %default-theme
13888This is the default GRUB theme used by the operating system, with a
13889fancy background image displaying the GNU and Guix logos.
13890@end defvr
13891
13892
cf4a9129
LC
13893@node Invoking guix system
13894@subsection Invoking @code{guix system}
0918e64a 13895
1068f26b 13896Once you have written an operating system declaration as seen in the
cf4a9129
LC
13897previous section, it can be @dfn{instantiated} using the @command{guix
13898system} command. The synopsis is:
4af2447e 13899
cf4a9129
LC
13900@example
13901guix system @var{options}@dots{} @var{action} @var{file}
13902@end example
4af2447e 13903
cf4a9129
LC
13904@var{file} must be the name of a file containing an
13905@code{operating-system} declaration. @var{action} specifies how the
a40424bd 13906operating system is instantiated. Currently the following values are
cf4a9129 13907supported:
4af2447e 13908
cf4a9129
LC
13909@table @code
13910@item reconfigure
13911Build the operating system described in @var{file}, activate it, and
8074b330
CM
13912switch to it@footnote{This action (and the related actions
13913@code{switch-generation} and @code{roll-back}) are usable only on
13914systems already running GuixSD.}.
4af2447e 13915
cf4a9129
LC
13916This effects all the configuration specified in @var{file}: user
13917accounts, system services, global package list, setuid programs, etc.
240b57f0
LC
13918The command starts system services specified in @var{file} that are not
13919currently running; if a service is currently running, it does not
1068f26b 13920attempt to upgrade it since this would not be possible without stopping it
240b57f0 13921first.
4af2447e 13922
067a2e2d
CM
13923This command creates a new generation whose number is one greater than
13924the current generation (as reported by @command{guix system
13925list-generations}). If that generation already exists, it will be
13926overwritten. This behavior mirrors that of @command{guix package}
13927(@pxref{Invoking guix package}).
13928
cf4a9129
LC
13929It also adds a GRUB menu entry for the new OS configuration, and moves
13930entries for older configurations to a submenu---unless
13931@option{--no-grub} is passed.
4af2447e 13932
240b57f0 13933@quotation Note
bf2479c7
LC
13934@c The paragraph below refers to the problem discussed at
13935@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
13936It is highly recommended to run @command{guix pull} once before you run
13937@command{guix system reconfigure} for the first time (@pxref{Invoking
13938guix pull}). Failing to do that you would see an older version of Guix
13939once @command{reconfigure} has completed.
240b57f0 13940@end quotation
bf2479c7 13941
8074b330 13942@item switch-generation
e32171ee 13943@cindex generations
8074b330
CM
13944Switch to an existing system generation. This action atomically
13945switches the system profile to the specified system generation. It also
13946rearranges the system's existing GRUB menu entries. It makes the menu
13947entry for the specified system generation the default, and it moves the
13948entries for the other generations to a submenu. The next time the
13949system boots, it will use the specified system generation.
13950
13951The target generation can be specified explicitly by its generation
13952number. For example, the following invocation would switch to system
13953generation 7:
13954
13955@example
13956guix system switch-generation 7
13957@end example
13958
13959The target generation can also be specified relative to the current
13960generation with the form @code{+N} or @code{-N}, where @code{+3} means
13961``3 generations ahead of the current generation,'' and @code{-1} means
13962``1 generation prior to the current generation.'' When specifying a
13963negative value such as @code{-1}, you must precede it with @code{--} to
13964prevent it from being parsed as an option. For example:
13965
13966@example
13967guix system switch-generation -- -1
13968@end example
13969
13970Currently, the effect of invoking this action is @emph{only} to switch
13971the system profile to an existing generation and rearrange the GRUB menu
13972entries. To actually start using the target system generation, you must
13973reboot after running this action. In the future, it will be updated to
13974do the same things as @command{reconfigure}, like activating and
13975deactivating services.
13976
13977This action will fail if the specified generation does not exist.
13978
13979@item roll-back
e32171ee 13980@cindex rolling back
8074b330
CM
13981Switch to the preceding system generation. The next time the system
13982boots, it will use the preceding system generation. This is the inverse
13983of @command{reconfigure}, and it is exactly the same as invoking
13984@command{switch-generation} with an argument of @code{-1}.
13985
13986Currently, as with @command{switch-generation}, you must reboot after
13987running this action to actually start using the preceding system
13988generation.
13989
cf4a9129 13990@item build
1068f26b 13991Build the derivation of the operating system, which includes all the
cf4a9129
LC
13992configuration files and programs needed to boot and run the system.
13993This action does not actually install anything.
113daf62 13994
cf4a9129
LC
13995@item init
13996Populate the given directory with all the files necessary to run the
13997operating system specified in @var{file}. This is useful for first-time
4705641f 13998installations of GuixSD. For instance:
113daf62
LC
13999
14000@example
cf4a9129 14001guix system init my-os-config.scm /mnt
113daf62
LC
14002@end example
14003
cf4a9129
LC
14004copies to @file{/mnt} all the store items required by the configuration
14005specified in @file{my-os-config.scm}. This includes configuration
14006files, packages, and so on. It also creates other essential files
14007needed for the system to operate correctly---e.g., the @file{/etc},
14008@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 14009
cf4a9129
LC
14010This command also installs GRUB on the device specified in
14011@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 14012
cf4a9129
LC
14013@item vm
14014@cindex virtual machine
0276f697 14015@cindex VM
f535dcbe 14016@anchor{guix system vm}
1068f26b 14017Build a virtual machine that contains the operating system declared in
cf4a9129 14018@var{file}, and return a script to run that virtual machine (VM).
1068f26b 14019Arguments given to the script are passed to QEMU.
113daf62 14020
cf4a9129 14021The VM shares its store with the host system.
113daf62 14022
0276f697
LC
14023Additional file systems can be shared between the host and the VM using
14024the @code{--share} and @code{--expose} command-line options: the former
14025specifies a directory to be shared with write access, while the latter
14026provides read-only access to the shared directory.
14027
14028The example below creates a VM in which the user's home directory is
14029accessible read-only, and where the @file{/exchange} directory is a
1068f26b 14030read-write mapping of @file{$HOME/tmp} on the host:
0276f697
LC
14031
14032@example
14033guix system vm my-config.scm \
14034 --expose=$HOME --share=$HOME/tmp=/exchange
14035@end example
14036
6aa260af
LC
14037On GNU/Linux, the default is to boot directly to the kernel; this has
14038the advantage of requiring only a very tiny root disk image since the
1068f26b 14039store of the host can then be mounted.
6aa260af
LC
14040
14041The @code{--full-boot} option forces a complete boot sequence, starting
14042with the bootloader. This requires more disk space since a root image
14043containing at least the kernel, initrd, and bootloader data files must
14044be created. The @code{--image-size} option can be used to specify the
1068f26b 14045size of the image.
ab11f0be 14046
cf4a9129
LC
14047@item vm-image
14048@itemx disk-image
14049Return a virtual machine or disk image of the operating system declared
14050in @var{file} that stands alone. Use the @option{--image-size} option
14051to specify the size of the image.
113daf62 14052
cf4a9129 14053When using @code{vm-image}, the returned image is in qcow2 format, which
97d76250
LF
14054the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
14055for more information on how to run the image in a virtual machine.
113daf62 14056
cf4a9129
LC
14057When using @code{disk-image}, a raw disk image is produced; it can be
14058copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
1068f26b 14059the device corresponding to a USB stick, one can copy the image to it
cf4a9129 14060using the following command:
113daf62 14061
cf4a9129
LC
14062@example
14063# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
14064@end example
113daf62 14065
1c8a81b1
DT
14066@item container
14067Return a script to run the operating system declared in @var{file}
14068within a container. Containers are a set of lightweight isolation
14069mechanisms provided by the kernel Linux-libre. Containers are
14070substantially less resource-demanding than full virtual machines since
14071the kernel, shared objects, and other resources can be shared with the
14072host system; this also means they provide thinner isolation.
14073
14074Currently, the script must be run as root in order to support more than
14075a single user and group. The container shares its store with the host
14076system.
14077
14078As with the @code{vm} action (@pxref{guix system vm}), additional file
14079systems to be shared between the host and container can be specified
14080using the @option{--share} and @option{--expose} options:
14081
14082@example
14083guix system container my-config.scm \
14084 --expose=$HOME --share=$HOME/tmp=/exchange
14085@end example
14086
0f252e26 14087@quotation Note
cfd35b4e 14088This option requires Linux-libre 3.19 or newer.
0f252e26
DT
14089@end quotation
14090
cf4a9129 14091@end table
113daf62 14092
ccd7158d
LC
14093@var{options} can contain any of the common build options (@pxref{Common
14094Build Options}). In addition, @var{options} can contain one of the
14095following:
113daf62 14096
cf4a9129
LC
14097@table @option
14098@item --system=@var{system}
14099@itemx -s @var{system}
1068f26b 14100Attempt to build for @var{system} instead of the host system type.
cf4a9129 14101This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 14102
f3f427c2
LC
14103@item --derivation
14104@itemx -d
14105Return the derivation file name of the given operating system without
14106building anything.
14107
cf4a9129
LC
14108@item --image-size=@var{size}
14109For the @code{vm-image} and @code{disk-image} actions, create an image
14110of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
14111include a unit as a suffix (@pxref{Block size, size specifications,,
14112coreutils, GNU Coreutils}).
db030303
LC
14113
14114@item --on-error=@var{strategy}
14115Apply @var{strategy} when an error occurs when reading @var{file}.
14116@var{strategy} may be one of the following:
14117
14118@table @code
14119@item nothing-special
14120Report the error concisely and exit. This is the default strategy.
14121
14122@item backtrace
14123Likewise, but also display a backtrace.
14124
14125@item debug
14126Report the error and enter Guile's debugger. From there, you can run
14127commands such as @code{,bt} to get a backtrace, @code{,locals} to
1068f26b
AE
14128display local variable values, and more generally inspect the state of the
14129program. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
db030303
LC
14130a list of available debugging commands.
14131@end table
113daf62 14132@end table
113daf62 14133
eca69fc0
LC
14134@quotation Note
14135All the actions above, except @code{build} and @code{init},
14136can use KVM support in the Linux-libre kernel. Specifically, if the
14137machine has hardware virtualization support, the corresponding
cf4a9129 14138KVM kernel module should be loaded, and the @file{/dev/kvm} device node
1068f26b 14139must exist and be readable and writable by the user and by the
eca69fc0
LC
14140build users of the daemon (@pxref{Build Environment Setup}).
14141@end quotation
8451a568 14142
65797bff
LC
14143Once you have built, configured, re-configured, and re-re-configured
14144your GuixSD installation, you may find it useful to list the operating
14145system generations available on disk---and that you can choose from the
14146GRUB boot menu:
14147
14148@table @code
14149
14150@item list-generations
14151List a summary of each generation of the operating system available on
14152disk, in a human-readable way. This is similar to the
14153@option{--list-generations} option of @command{guix package}
14154(@pxref{Invoking guix package}).
14155
14156Optionally, one can specify a pattern, with the same syntax that is used
14157in @command{guix package --list-generations}, to restrict the list of
14158generations displayed. For instance, the following command displays
1068f26b 14159generations that are up to 10 days old:
65797bff
LC
14160
14161@example
14162$ guix system list-generations 10d
14163@end example
14164
14165@end table
14166
d6c3267a
LC
14167The @command{guix system} command has even more to offer! The following
14168sub-commands allow you to visualize how your system services relate to
14169each other:
14170
14171@anchor{system-extension-graph}
14172@table @code
14173
14174@item extension-graph
14175Emit in Dot/Graphviz format to standard output the @dfn{service
14176extension graph} of the operating system defined in @var{file}
14177(@pxref{Service Composition}, for more information on service
14178extensions.)
14179
14180The command:
14181
14182@example
14183$ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
14184@end example
14185
14186produces a PDF file showing the extension relations among services.
14187
710fa231
AK
14188@anchor{system-shepherd-graph}
14189@item shepherd-graph
6f305ea5 14190Emit in Dot/Graphviz format to standard output the @dfn{dependency
dd17bc38
AK
14191graph} of shepherd services of the operating system defined in
14192@var{file}. @xref{Shepherd Services}, for more information and for an
14193example graph.
6f305ea5 14194
d6c3267a
LC
14195@end table
14196
97d76250 14197@node Running GuixSD in a VM
70ac09a5 14198@subsection Running GuixSD in a Virtual Machine
97d76250 14199
e32171ee 14200@cindex virtual machine
97d76250
LF
14201One way to run GuixSD in a virtual machine (VM) is to build a GuixSD
14202virtual machine image using @command{guix system vm-image}
14203(@pxref{Invoking guix system}). The returned image is in qcow2 format,
14204which the @uref{http://qemu.org/, QEMU emulator} can efficiently use.
14205
e32171ee 14206@cindex QEMU
97d76250
LF
14207To run the image in QEMU, copy it out of the store (@pxref{The Store})
14208and give yourself permission to write to the copy. When invoking QEMU,
14209you must choose a system emulator that is suitable for your hardware
14210platform. Here is a minimal QEMU invocation that will boot the result
14211of @command{guix system vm-image} on x86_64 hardware:
14212
14213@example
14214$ qemu-system-x86_64 \
14215 -net user -net nic,model=virtio \
14216 -enable-kvm -m 256 /tmp/qemu-image
14217@end example
14218
14219Here is what each of these options means:
14220
14221@table @code
14222@item qemu-system-x86_64
14223This specifies the hardware platform to emulate. This should match the
14224host.
14225
14226@item -net user
14227Enable the unprivileged user-mode network stack. The guest OS can
14228access the host but not vice versa. This is the simplest way to get the
58806e6f 14229guest OS online.
97d76250
LF
14230
14231@item -net nic,model=virtio
1068f26b 14232You must create a network interface of a given model. If you do not
97d76250
LF
14233create a NIC, the boot will fail. Assuming your hardware platform is
14234x86_64, you can get a list of available NIC models by running
14235@command{qemu-system-x86_64 -net nic,model=help}.
14236
14237@item -enable-kvm
14238If your system has hardware virtualization extensions, enabling the
1068f26b 14239virtual machine support (KVM) of the Linux kernel will make things run
97d76250
LF
14240faster.
14241
14242@item -m 256
14243RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
7414de0a 14244which may be insufficient for some operations.
97d76250
LF
14245
14246@item /tmp/qemu-image
14247The file name of the qcow2 image.
14248@end table
d6c3267a 14249
3ddc50db
DC
14250The default @command{run-vm.sh} script that is returned by an invokation of
14251@command{guix system vm} does not add a @command{-net user} flag by default.
14252To get network access from within the vm add the @code{(dhcp-client-service)}
14253to your system definition and start the VM using
14254@command{`guix system vm config.scm` -net user}. An important caveat of using
14255@command{-net user} for networking is that @command{ping} will not work, because
14256it uses the ICMP protocol. You'll have to use a different command to check for
14257network connectivity, like for example @command{curl}.
14258
14259@subsubsection Connecting Through SSH
14260
e32171ee
JD
14261@cindex SSH
14262@cindex SSH server
3ddc50db
DC
14263To enable SSH inside a VM you need to add a SSH server like @code{(dropbear-service)}
14264or @code{(lsh-service)} to your VM. The @code{(lsh-service}) doesn't currently
14265boot unsupervised. It requires you to type some characters to initialize the
14266randomness generator. In addition you need to forward the SSH port, 22 by
14267default, to the host. You can do this with
14268
14269@example
14270`guix system vm config.scm` -net user,hostfwd=tcp::10022-:22
14271@end example
14272
14273To connect to the VM you can run
14274
14275@example
14276ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022
14277@end example
14278
14279The @command{-p} tells @command{ssh} the port you want to connect to.
14280@command{-o UserKnownHostsFile=/dev/null} prevents @command{ssh} from complaining
14281every time you modify your @command{config.scm} file and the
14282@command{-o StrictHostKeyChecking=no} prevents you from having to allow a
14283connection to an unknown host every time you connect.
14284
14285@subsubsection Using @command{virt-viewer} with Spice
14286
14287As an alternative to the default @command{qemu} graphical client you can
14288use the @command{remote-viewer} from the @command{virt-viewer} package. To
14289connect pass the @command{-spice port=5930,disable-ticketing} flag to
14290@command{qemu}. See previous section for further information on how to do this.
14291
14292Spice also allows you to do some nice stuff like share your clipboard with your
14293VM. To enable that you'll also have to pass the following flags to @command{qemu}:
14294
14295@example
14296-device virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0,addr=0x5
14297-chardev spicevmc,name=vdagent,id=vdagent
14298-device virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,
14299name=com.redhat.spice.0
14300@end example
14301
14302You'll also need to add the @pxref{Miscellaneous Services, Spice service}.
14303
cf4a9129
LC
14304@node Defining Services
14305@subsection Defining Services
8451a568 14306
eb524192 14307The previous sections show the available services and how one can combine
0adfe95a
LC
14308them in an @code{operating-system} declaration. But how do we define
14309them in the first place? And what is a service anyway?
8451a568 14310
0adfe95a
LC
14311@menu
14312* Service Composition:: The model for composing services.
14313* Service Types and Services:: Types and services.
14314* Service Reference:: API reference.
dd17bc38 14315* Shepherd Services:: A particular type of service.
0adfe95a
LC
14316@end menu
14317
14318@node Service Composition
14319@subsubsection Service Composition
14320
14321@cindex services
14322@cindex daemons
14323Here we define a @dfn{service} as, broadly, something that extends the
1068f26b 14324functionality of the operating system. Often a service is a process---a
0adfe95a
LC
14325@dfn{daemon}---started when the system boots: a secure shell server, a
14326Web server, the Guix build daemon, etc. Sometimes a service is a daemon
14327whose execution can be triggered by another daemon---e.g., an FTP server
14328started by @command{inetd} or a D-Bus service activated by
14329@command{dbus-daemon}. Occasionally, a service does not map to a
14330daemon. For instance, the ``account'' service collects user accounts
14331and makes sure they exist when the system runs; the ``udev'' service
14332collects device management rules and makes them available to the eudev
1068f26b
AE
14333daemon; the @file{/etc} service populates the @file{/etc} directory
14334of the system.
0adfe95a 14335
d6c3267a 14336@cindex service extensions
0adfe95a 14337GuixSD services are connected by @dfn{extensions}. For instance, the
1068f26b 14338secure shell service @emph{extends} the Shepherd---the GuixSD
dd17bc38
AK
14339initialization system, running as PID@tie{}1---by giving it the command
14340lines to start and stop the secure shell daemon (@pxref{Networking
14341Services, @code{lsh-service}}); the UPower service extends the D-Bus
14342service by passing it its @file{.service} specification, and extends the
14343udev service by passing it device management rules (@pxref{Desktop
14344Services, @code{upower-service}}); the Guix daemon service extends the
14345Shepherd by passing it the command lines to start and stop the daemon,
14346and extends the account service by passing it a list of required build
14347user accounts (@pxref{Base Services}).
0adfe95a
LC
14348
14349All in all, services and their ``extends'' relations form a directed
14350acyclic graph (DAG). If we represent services as boxes and extensions
14351as arrows, a typical system might provide something like this:
14352
14353@image{images/service-graph,,5in,Typical service extension graph.}
14354
d62e201c
LC
14355@cindex system service
14356At the bottom, we see the @dfn{system service}, which produces the
14357directory containing everything to run and boot the system, as returned
14358by the @command{guix system build} command. @xref{Service Reference},
14359to learn about the other service types shown here.
d6c3267a
LC
14360@xref{system-extension-graph, the @command{guix system extension-graph}
14361command}, for information on how to generate this representation for a
14362particular operating system definition.
0adfe95a
LC
14363
14364@cindex service types
14365Technically, developers can define @dfn{service types} to express these
14366relations. There can be any number of services of a given type on the
14367system---for instance, a system running two instances of the GNU secure
14368shell server (lsh) has two instances of @var{lsh-service-type}, with
14369different parameters.
14370
14371The following section describes the programming interface for service
14372types and services.
14373
14374@node Service Types and Services
14375@subsubsection Service Types and Services
14376
14377A @dfn{service type} is a node in the DAG described above. Let us start
14378with a simple example, the service type for the Guix build daemon
14379(@pxref{Invoking guix-daemon}):
14380
14381@example
14382(define guix-service-type
14383 (service-type
14384 (name 'guix)
14385 (extensions
d4053c71 14386 (list (service-extension shepherd-root-service-type guix-shepherd-service)
0adfe95a
LC
14387 (service-extension account-service-type guix-accounts)
14388 (service-extension activation-service-type guix-activation)))))
14389@end example
8451a568 14390
cf4a9129 14391@noindent
1068f26b 14392It defines two things:
0adfe95a
LC
14393
14394@enumerate
14395@item
14396A name, whose sole purpose is to make inspection and debugging easier.
14397
14398@item
14399A list of @dfn{service extensions}, where each extension designates the
1068f26b
AE
14400target service type and a procedure that, given the parameters of the
14401service, returns a list of objects to extend the service of that type.
0adfe95a
LC
14402
14403Every service type has at least one service extension. The only
14404exception is the @dfn{boot service type}, which is the ultimate service.
14405@end enumerate
14406
14407In this example, @var{guix-service-type} extends three services:
14408
14409@table @var
d4053c71
AK
14410@item shepherd-root-service-type
14411The @var{guix-shepherd-service} procedure defines how the Shepherd
14412service is extended. Namely, it returns a @code{<shepherd-service>}
14413object that defines how @command{guix-daemon} is started and stopped
14414(@pxref{Shepherd Services}).
0adfe95a
LC
14415
14416@item account-service-type
14417This extension for this service is computed by @var{guix-accounts},
14418which returns a list of @code{user-group} and @code{user-account}
14419objects representing the build user accounts (@pxref{Invoking
14420guix-daemon}).
14421
14422@item activation-service-type
14423Here @var{guix-activation} is a procedure that returns a gexp, which is
14424a code snippet to run at ``activation time''---e.g., when the service is
14425booted.
14426@end table
14427
14428A service of this type is instantiated like this:
14429
14430@example
14431(service guix-service-type
14432 (guix-configuration
14433 (build-accounts 5)
14434 (use-substitutes? #f)))
14435@end example
14436
14437The second argument to the @code{service} form is a value representing
14438the parameters of this specific service instance.
14439@xref{guix-configuration-type, @code{guix-configuration}}, for
14440information about the @code{guix-configuration} data type.
14441
14442@var{guix-service-type} is quite simple because it extends other
14443services but is not extensible itself.
14444
14445@c @subsubsubsection Extensible Service Types
14446
14447The service type for an @emph{extensible} service looks like this:
14448
14449@example
14450(define udev-service-type
14451 (service-type (name 'udev)
14452 (extensions
d4053c71
AK
14453 (list (service-extension shepherd-root-service-type
14454 udev-shepherd-service)))
0adfe95a
LC
14455
14456 (compose concatenate) ;concatenate the list of rules
14457 (extend (lambda (config rules)
14458 (match config
14459 (($ <udev-configuration> udev initial-rules)
14460 (udev-configuration
14461 (udev udev) ;the udev package to use
14462 (rules (append initial-rules rules)))))))))
14463@end example
14464
14465This is the service type for the
14466@uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
14467management daemon}. Compared to the previous example, in addition to an
d4053c71 14468extension of @var{shepherd-root-service-type}, we see two new fields:
0adfe95a
LC
14469
14470@table @code
14471@item compose
14472This is the procedure to @dfn{compose} the list of extensions to
14473services of this type.
14474
14475Services can extend the udev service by passing it lists of rules; we
14476compose those extensions simply by concatenating them.
14477
14478@item extend
1068f26b 14479This procedure defines how the value of the service is @dfn{extended} with
0adfe95a
LC
14480the composition of the extensions.
14481
14482Udev extensions are composed into a list of rules, but the udev service
14483value is itself a @code{<udev-configuration>} record. So here, we
a40424bd 14484extend that record by appending the list of rules it contains to the
0adfe95a
LC
14485list of contributed rules.
14486@end table
14487
14488There can be only one instance of an extensible service type such as
14489@var{udev-service-type}. If there were more, the
14490@code{service-extension} specifications would be ambiguous.
14491
14492Still here? The next section provides a reference of the programming
14493interface for services.
14494
14495@node Service Reference
14496@subsubsection Service Reference
14497
14498We have seen an overview of service types (@pxref{Service Types and
14499Services}). This section provides a reference on how to manipulate
14500services and service types. This interface is provided by the
14501@code{(gnu services)} module.
14502
14503@deffn {Scheme Procedure} service @var{type} @var{value}
14504Return a new service of @var{type}, a @code{<service-type>} object (see
14505below.) @var{value} can be any object; it represents the parameters of
14506this particular service instance.
14507@end deffn
14508
14509@deffn {Scheme Procedure} service? @var{obj}
14510Return true if @var{obj} is a service.
14511@end deffn
8451a568 14512
0adfe95a
LC
14513@deffn {Scheme Procedure} service-kind @var{service}
14514Return the type of @var{service}---i.e., a @code{<service-type>} object.
14515@end deffn
14516
14517@deffn {Scheme Procedure} service-parameters @var{service}
14518Return the value associated with @var{service}. It represents its
14519parameters.
14520@end deffn
14521
14522Here is an example of how a service is created and manipulated:
14523
14524@example
14525(define s
14526 (service nginx-service-type
14527 (nginx-configuration
14528 (nginx nginx)
14529 (log-directory log-directory)
14530 (run-directory run-directory)
14531 (file config-file))))
14532
14533(service? s)
14534@result{} #t
14535
14536(eq? (service-kind s) nginx-service-type)
14537@result{} #t
14538@end example
14539
cd6f6c22
LC
14540The @code{modify-services} form provides a handy way to change the
14541parameters of some of the services of a list such as
4d343a14 14542@var{%base-services} (@pxref{Base Services, @code{%base-services}}). It
7414de0a 14543evaluates to a list of services. Of course, you could always use
4d343a14
CM
14544standard list combinators such as @code{map} and @code{fold} to do that
14545(@pxref{SRFI-1, List Library,, guile, GNU Guile Reference Manual});
14546@code{modify-services} simply provides a more concise form for this
14547common pattern.
cd6f6c22
LC
14548
14549@deffn {Scheme Syntax} modify-services @var{services} @
14550 (@var{type} @var{variable} => @var{body}) @dots{}
14551
14552Modify the services listed in @var{services} according to the given
14553clauses. Each clause has the form:
14554
14555@example
14556(@var{type} @var{variable} => @var{body})
14557@end example
14558
4d343a14
CM
14559where @var{type} is a service type---e.g.,
14560@code{guix-service-type}---and @var{variable} is an identifier that is
14561bound within the @var{body} to the service parameters---e.g., a
14562@code{guix-configuration} instance---of the original service of that
14563@var{type}.
cd6f6c22 14564
4d343a14
CM
14565The @var{body} should evaluate to the new service parameters, which will
14566be used to configure the new service. This new service will replace the
14567original in the resulting list. Because a service's service parameters
7414de0a 14568are created using @code{define-record-type*}, you can write a succinct
4d343a14
CM
14569@var{body} that evaluates to the new service parameters by using the
14570@code{inherit} feature that @code{define-record-type*} provides.
14571
b53daad0 14572@xref{Using the Configuration System}, for example usage.
cd6f6c22 14573
cd6f6c22
LC
14574@end deffn
14575
14576Next comes the programming interface for service types. This is
14577something you want to know when writing new service definitions, but not
14578necessarily when simply looking for ways to customize your
14579@code{operating-system} declaration.
14580
0adfe95a
LC
14581@deftp {Data Type} service-type
14582@cindex service type
14583This is the representation of a @dfn{service type} (@pxref{Service Types
14584and Services}).
14585
14586@table @asis
14587@item @code{name}
14588This is a symbol, used only to simplify inspection and debugging.
14589
14590@item @code{extensions}
1068f26b 14591A non-empty list of @code{<service-extension>} objects (see below).
0adfe95a
LC
14592
14593@item @code{compose} (default: @code{#f})
14594If this is @code{#f}, then the service type denotes services that cannot
14595be extended---i.e., services that do not receive ``values'' from other
14596services.
14597
14598Otherwise, it must be a one-argument procedure. The procedure is called
14599by @code{fold-services} and is passed a list of values collected from
14600extensions. It must return a value that is a valid parameter value for
14601the service instance.
14602
14603@item @code{extend} (default: @code{#f})
14604If this is @code{#f}, services of this type cannot be extended.
14605
14606Otherwise, it must be a two-argument procedure: @code{fold-services}
1068f26b 14607calls it, passing it the initial value of the service as the first argument
0adfe95a
LC
14608and the result of applying @code{compose} to the extension values as the
14609second argument.
14610@end table
14611
14612@xref{Service Types and Services}, for examples.
14613@end deftp
14614
14615@deffn {Scheme Procedure} service-extension @var{target-type} @
14616 @var{compute}
14617Return a new extension for services of type @var{target-type}.
14618@var{compute} must be a one-argument procedure: @code{fold-services}
14619calls it, passing it the value associated with the service that provides
14620the extension; it must return a valid value for the target service.
14621@end deffn
14622
14623@deffn {Scheme Procedure} service-extension? @var{obj}
14624Return true if @var{obj} is a service extension.
14625@end deffn
14626
71654dfd
LC
14627Occasionally, you might want to simply extend an existing service. This
14628involves creating a new service type and specifying the extension of
14629interest, which can be verbose; the @code{simple-service} procedure
14630provides a shorthand for this.
14631
14632@deffn {Scheme Procedure} simple-service @var{name} @var{target} @var{value}
14633Return a service that extends @var{target} with @var{value}. This works
14634by creating a singleton service type @var{name}, of which the returned
14635service is an instance.
14636
14637For example, this extends mcron (@pxref{Scheduled Job Execution}) with
14638an additional job:
14639
14640@example
14641(simple-service 'my-mcron-job mcron-service-type
14642 #~(job '(next-hour (3)) "guix gc -F 2G"))
14643@end example
14644@end deffn
14645
0adfe95a
LC
14646At the core of the service abstraction lies the @code{fold-services}
14647procedure, which is responsible for ``compiling'' a list of services
d62e201c
LC
14648down to a single directory that contains everything needed to boot and
14649run the system---the directory shown by the @command{guix system build}
14650command (@pxref{Invoking guix system}). In essence, it propagates
14651service extensions down the service graph, updating each node parameters
14652on the way, until it reaches the root node.
0adfe95a
LC
14653
14654@deffn {Scheme Procedure} fold-services @var{services} @
d62e201c 14655 [#:target-type @var{system-service-type}]
0adfe95a
LC
14656Fold @var{services} by propagating their extensions down to the root of
14657type @var{target-type}; return the root service adjusted accordingly.
14658@end deffn
14659
14660Lastly, the @code{(gnu services)} module also defines several essential
14661service types, some of which are listed below.
14662
d62e201c
LC
14663@defvr {Scheme Variable} system-service-type
14664This is the root of the service graph. It produces the system directory
14665as returned by the @command{guix system build} command.
14666@end defvr
14667
0adfe95a 14668@defvr {Scheme Variable} boot-service-type
d62e201c
LC
14669The type of the ``boot service'', which produces the @dfn{boot script}.
14670The boot script is what the initial RAM disk runs when booting.
0adfe95a
LC
14671@end defvr
14672
14673@defvr {Scheme Variable} etc-service-type
14674The type of the @file{/etc} service. This service can be extended by
14675passing it name/file tuples such as:
14676
14677@example
14678(list `("issue" ,(plain-file "issue" "Welcome!\n")))
14679@end example
14680
14681In this example, the effect would be to add an @file{/etc/issue} file
14682pointing to the given file.
14683@end defvr
14684
14685@defvr {Scheme Variable} setuid-program-service-type
14686Type for the ``setuid-program service''. This service collects lists of
14687executable file names, passed as gexps, and adds them to the set of
14688setuid-root programs on the system (@pxref{Setuid Programs}).
14689@end defvr
14690
af4c3fd5
LC
14691@defvr {Scheme Variable} profile-service-type
14692Type of the service that populates the @dfn{system profile}---i.e., the
14693programs under @file{/run/current-system/profile}. Other services can
14694extend it by passing it lists of packages to add to the system profile.
14695@end defvr
14696
0adfe95a 14697
dd17bc38
AK
14698@node Shepherd Services
14699@subsubsection Shepherd Services
0adfe95a 14700
e32171ee 14701@cindex shepherd services
0adfe95a
LC
14702@cindex PID 1
14703@cindex init system
a40424bd
CM
14704The @code{(gnu services shepherd)} module provides a way to define
14705services managed by the GNU@tie{}Shepherd, which is the GuixSD
14706initialization system---the first process that is started when the
1068f26b
AE
14707system boots, also known as PID@tie{}1
14708(@pxref{Introduction,,, shepherd, The GNU Shepherd Manual}).
6f305ea5 14709
dd17bc38
AK
14710Services in the Shepherd can depend on each other. For instance, the
14711SSH daemon may need to be started after the syslog daemon has been
14712started, which in turn can only happen once all the file systems have
14713been mounted. The simple operating system defined earlier (@pxref{Using
14714the Configuration System}) results in a service graph like this:
6f305ea5 14715
710fa231 14716@image{images/shepherd-graph,,5in,Typical shepherd service graph.}
6f305ea5
LC
14717
14718You can actually generate such a graph for any operating system
710fa231
AK
14719definition using the @command{guix system shepherd-graph} command
14720(@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
6f305ea5 14721
d4053c71
AK
14722The @var{%shepherd-root-service} is a service object representing
14723PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
14724by passing it lists of @code{<shepherd-service>} objects.
0adfe95a 14725
d4053c71 14726@deftp {Data Type} shepherd-service
dd17bc38 14727The data type representing a service managed by the Shepherd.
0adfe95a
LC
14728
14729@table @asis
14730@item @code{provision}
14731This is a list of symbols denoting what the service provides.
14732
dd17bc38
AK
14733These are the names that may be passed to @command{herd start},
14734@command{herd status}, and similar commands (@pxref{Invoking herd,,,
14735shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
14736@code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
0adfe95a
LC
14737
14738@item @code{requirements} (default: @code{'()})
dd17bc38 14739List of symbols denoting the Shepherd services this one depends on.
0adfe95a
LC
14740
14741@item @code{respawn?} (default: @code{#t})
14742Whether to restart the service when it stops, for instance when the
14743underlying process dies.
14744
14745@item @code{start}
14746@itemx @code{stop} (default: @code{#~(const #f)})
dd17bc38
AK
14747The @code{start} and @code{stop} fields refer to the Shepherd's
14748facilities to start and stop processes (@pxref{Service De- and
14749Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
14750G-expressions that get expanded in the Shepherd configuration file
14751(@pxref{G-Expressions}).
0adfe95a
LC
14752
14753@item @code{documentation}
14754A documentation string, as shown when running:
14755
14756@example
dd17bc38 14757herd doc @var{service-name}
0adfe95a
LC
14758@end example
14759
14760where @var{service-name} is one of the symbols in @var{provision}
dd17bc38 14761(@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
fae685b9
LC
14762
14763@item @code{modules} (default: @var{%default-modules})
14764This is the list of modules that must be in scope when @code{start} and
14765@code{stop} are evaluated.
14766
0adfe95a
LC
14767@end table
14768@end deftp
14769
d4053c71 14770@defvr {Scheme Variable} shepherd-root-service-type
dd17bc38 14771The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
0adfe95a
LC
14772
14773This is the service type that extensions target when they want to create
dd17bc38 14774shepherd services (@pxref{Service Types and Services}, for an example).
d4053c71 14775Each extension must pass a list of @code{<shepherd-service>}.
0adfe95a
LC
14776@end defvr
14777
d4053c71 14778@defvr {Scheme Variable} %shepherd-root-service
0adfe95a
LC
14779This service represents PID@tie{}1.
14780@end defvr
8451a568 14781
8451a568 14782
cf4a9129
LC
14783@node Installing Debugging Files
14784@section Installing Debugging Files
8451a568 14785
cf4a9129
LC
14786@cindex debugging files
14787Program binaries, as produced by the GCC compilers for instance, are
14788typically written in the ELF format, with a section containing
14789@dfn{debugging information}. Debugging information is what allows the
14790debugger, GDB, to map binary code to source code; it is required to
14791debug a compiled program in good conditions.
8451a568 14792
cf4a9129
LC
14793The problem with debugging information is that is takes up a fair amount
14794of disk space. For example, debugging information for the GNU C Library
14795weighs in at more than 60 MiB. Thus, as a user, keeping all the
14796debugging info of all the installed programs is usually not an option.
14797Yet, space savings should not come at the cost of an impediment to
14798debugging---especially in the GNU system, which should make it easier
14799for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 14800
cf4a9129
LC
14801Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
14802mechanism that allows users to get the best of both worlds: debugging
14803information can be stripped from the binaries and stored in separate
14804files. GDB is then able to load debugging information from those files,
14805when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
14806with GDB}).
8451a568 14807
cf4a9129
LC
14808The GNU distribution takes advantage of this by storing debugging
14809information in the @code{lib/debug} sub-directory of a separate package
14810output unimaginatively called @code{debug} (@pxref{Packages with
14811Multiple Outputs}). Users can choose to install the @code{debug} output
14812of a package when they need it. For instance, the following command
14813installs the debugging information for the GNU C Library and for GNU
14814Guile:
8451a568
LC
14815
14816@example
cf4a9129 14817guix package -i glibc:debug guile:debug
8451a568
LC
14818@end example
14819
cf4a9129
LC
14820GDB must then be told to look for debug files in the user's profile, by
14821setting the @code{debug-file-directory} variable (consider setting it
14822from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
14823GDB}):
8451a568 14824
cf4a9129
LC
14825@example
14826(gdb) set debug-file-directory ~/.guix-profile/lib/debug
14827@end example
8451a568 14828
cf4a9129
LC
14829From there on, GDB will pick up debugging information from the
14830@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 14831
cf4a9129
LC
14832In addition, you will most likely want GDB to be able to show the source
14833code being debugged. To do that, you will have to unpack the source
14834code of the package of interest (obtained with @code{guix build
14835--source}, @pxref{Invoking guix build}), and to point GDB to that source
14836directory using the @code{directory} command (@pxref{Source Path,
14837@code{directory},, gdb, Debugging with GDB}).
8451a568 14838
cf4a9129
LC
14839@c XXX: keep me up-to-date
14840The @code{debug} output mechanism in Guix is implemented by the
14841@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
1068f26b
AE
14842opt-in---debugging information is available only for the packages
14843with definitions explicitly declaring a @code{debug} output. This may be
14844changed to opt-out in the future if our build farm servers can handle
cf4a9129
LC
14845the load. To check whether a package has a @code{debug} output, use
14846@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 14847
8451a568 14848
05962f29
LC
14849@node Security Updates
14850@section Security Updates
14851
09866b39
LC
14852@cindex security updates
14853@cindex security vulnerabilities
14854Occasionally, important security vulnerabilities are discovered in software
14855packages and must be patched. Guix developers try hard to keep track of
14856known vulnerabilities and to apply fixes as soon as possible in the
14857@code{master} branch of Guix (we do not yet provide a ``stable'' branch
14858containing only security updates.) The @command{guix lint} tool helps
14859developers find out about vulnerable versions of software packages in the
14860distribution:
14861
14862@smallexample
14863$ guix lint -c cve
14864gnu/packages/base.scm:652:2: glibc-2.21: probably vulnerable to CVE-2015-1781, CVE-2015-7547
14865gnu/packages/gcc.scm:334:2: gcc-4.9.3: probably vulnerable to CVE-2015-5276
14866gnu/packages/image.scm:312:2: openjpeg-2.1.0: probably vulnerable to CVE-2016-1923, CVE-2016-1924
14867@dots{}
14868@end smallexample
14869
14870@xref{Invoking guix lint}, for more information.
14871
843858b8 14872@quotation Note
09866b39
LC
14873As of version @value{VERSION}, the feature described below is considered
14874``beta''.
843858b8 14875@end quotation
05962f29 14876
09866b39 14877Guix follows a functional
05962f29
LC
14878package management discipline (@pxref{Introduction}), which implies
14879that, when a package is changed, @emph{every package that depends on it}
14880must be rebuilt. This can significantly slow down the deployment of
14881fixes in core packages such as libc or Bash, since basically the whole
14882distribution would need to be rebuilt. Using pre-built binaries helps
14883(@pxref{Substitutes}), but deployment may still take more time than
14884desired.
14885
14886@cindex grafts
1068f26b 14887To address this, Guix implements @dfn{grafts}, a mechanism that allows
05962f29
LC
14888for fast deployment of critical updates without the costs associated
14889with a whole-distribution rebuild. The idea is to rebuild only the
14890package that needs to be patched, and then to ``graft'' it onto packages
14891explicitly installed by the user and that were previously referring to
14892the original package. The cost of grafting is typically very low, and
14893order of magnitudes lower than a full rebuild of the dependency chain.
14894
14895@cindex replacements of packages, for grafts
14896For instance, suppose a security update needs to be applied to Bash.
14897Guix developers will provide a package definition for the ``fixed''
14898Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
14899Packages}). Then, the original package definition is augmented with a
14900@code{replacement} field pointing to the package containing the bug fix:
14901
14902@example
14903(define bash
14904 (package
14905 (name "bash")
14906 ;; @dots{}
14907 (replacement bash-fixed)))
14908@end example
14909
c22a1324
LC
14910From there on, any package depending directly or indirectly on Bash---as
14911reported by @command{guix gc --requisites} (@pxref{Invoking guix
14912gc})---that is installed is automatically ``rewritten'' to refer to
05962f29 14913@var{bash-fixed} instead of @var{bash}. This grafting process takes
1068f26b 14914time proportional to the size of the package, usually less than a
c22a1324
LC
14915minute for an ``average'' package on a recent machine. Grafting is
14916recursive: when an indirect dependency requires grafting, then grafting
14917``propagates'' up to the package that the user is installing.
05962f29 14918
57bdd79e
LC
14919Currently, the length of the name and version of the graft and that of
14920the package it replaces (@var{bash-fixed} and @var{bash} in the example
14921above) must be equal. This restriction mostly comes from the fact that
14922grafting works by patching files, including binary files, directly.
05962f29
LC
14923Other restrictions may apply: for instance, when adding a graft to a
14924package providing a shared library, the original shared library and its
14925replacement must have the same @code{SONAME} and be binary-compatible.
14926
59a4dd50
LC
14927The @option{--no-grafts} command-line option allows you to forcefully
14928avoid grafting (@pxref{Common Build Options, @option{--no-grafts}}).
14929Thus, the command:
14930
14931@example
14932guix build bash --no-grafts
14933@end example
14934
14935@noindent
14936returns the store file name of the original Bash, whereas:
14937
14938@example
14939guix build bash
14940@end example
14941
14942@noindent
14943returns the store file name of the ``fixed'', replacement Bash. This
14944allows you to distinguish between the two variants of Bash.
14945
14946To verify which Bash your whole profile refers to, you can run
14947(@pxref{Invoking guix gc}):
14948
14949@example
14950guix gc -R `readlink -f ~/.guix-profile` | grep bash
14951@end example
14952
14953@noindent
14954@dots{} and compare the store file names that you get with those above.
14955Likewise for a complete GuixSD system generation:
14956
14957@example
14958guix gc -R `guix system build my-config.scm` | grep bash
14959@end example
14960
14961Lastly, to check which Bash running processes are using, you can use the
14962@command{lsof} command:
14963
14964@example
14965lsof | grep /gnu/store/.*bash
14966@end example
14967
05962f29 14968
cf4a9129
LC
14969@node Package Modules
14970@section Package Modules
8451a568 14971
cf4a9129
LC
14972From a programming viewpoint, the package definitions of the
14973GNU distribution are provided by Guile modules in the @code{(gnu packages
14974@dots{})} name space@footnote{Note that packages under the @code{(gnu
14975packages @dots{})} module name space are not necessarily ``GNU
14976packages''. This module naming scheme follows the usual Guile module
14977naming convention: @code{gnu} means that these modules are distributed
14978as part of the GNU system, and @code{packages} identifies modules that
14979define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
14980Reference Manual}). For instance, the @code{(gnu packages emacs)}
14981module exports a variable named @code{emacs}, which is bound to a
14982@code{<package>} object (@pxref{Defining Packages}).
113daf62 14983
300868ba 14984The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
14985automatically scanned for packages by the command-line tools. For
14986instance, when running @code{guix package -i emacs}, all the @code{(gnu
14987packages @dots{})} modules are scanned until one that exports a package
14988object whose name is @code{emacs} is found. This package search
14989facility is implemented in the @code{(gnu packages)} module.
113daf62 14990
300868ba 14991@cindex customization, of packages
8689901f 14992@cindex package module search path
cf4a9129 14993Users can store package definitions in modules with different
60142854 14994names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
14995name and module name must match. For instance, the @code{(my-packages
14996emacs)} module must be stored in a @file{my-packages/emacs.scm} file
14997relative to the load path specified with @option{--load-path} or
14998@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
14999guile, GNU Guile Reference Manual}, for details.}. These package definitions
1068f26b
AE
15000will not be visible by default. Users can invoke commands such as
15001@command{guix package} and @command{guix build} with the
c95ded7e
LC
15002@code{-e} option so that they know where to find the package. Better
15003yet, they can use the
300868ba 15004@code{-L} option of these commands to make those modules visible
8689901f
LC
15005(@pxref{Invoking guix build, @code{--load-path}}), or define the
15006@code{GUIX_PACKAGE_PATH} environment variable. This environment
15007variable makes it easy to extend or customize the distribution and is
15008honored by all the user interfaces.
15009
15010@defvr {Environment Variable} GUIX_PACKAGE_PATH
1068f26b
AE
15011This is a colon-separated list of directories to search for additional
15012package modules. Directories listed in this variable take precedence
15013over the own modules of the distribution.
8689901f 15014@end defvr
ef5dd60a 15015
cf4a9129
LC
15016The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
15017each package is built based solely on other packages in the
15018distribution. The root of this dependency graph is a small set of
15019@dfn{bootstrap binaries}, provided by the @code{(gnu packages
15020bootstrap)} module. For more information on bootstrapping,
081145cf 15021@pxref{Bootstrapping}.
ef5dd60a 15022
cf4a9129
LC
15023@node Packaging Guidelines
15024@section Packaging Guidelines
ef5dd60a 15025
e32171ee 15026@cindex packages, creating
cf4a9129
LC
15027The GNU distribution is nascent and may well lack some of your favorite
15028packages. This section describes how you can help make the distribution
15029grow. @xref{Contributing}, for additional information on how you can
15030help.
ef5dd60a 15031
cf4a9129
LC
15032Free software packages are usually distributed in the form of
15033@dfn{source code tarballs}---typically @file{tar.gz} files that contain
15034all the source files. Adding a package to the distribution means
15035essentially two things: adding a @dfn{recipe} that describes how to
15036build the package, including a list of other packages required to build
f97c9175 15037it, and adding @dfn{package metadata} along with that recipe, such as a
cf4a9129 15038description and licensing information.
ef5dd60a 15039
cf4a9129
LC
15040In Guix all this information is embodied in @dfn{package definitions}.
15041Package definitions provide a high-level view of the package. They are
15042written using the syntax of the Scheme programming language; in fact,
15043for each package we define a variable bound to the package definition,
15044and export that variable from a module (@pxref{Package Modules}).
15045However, in-depth Scheme knowledge is @emph{not} a prerequisite for
15046creating packages. For more information on package definitions,
081145cf 15047@pxref{Defining Packages}.
ef5dd60a 15048
cf4a9129
LC
15049Once a package definition is in place, stored in a file in the Guix
15050source tree, it can be tested using the @command{guix build} command
15051(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
15052called @code{gnew}, you may run this command from the Guix build tree
15053(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
15054
15055@example
cf4a9129 15056./pre-inst-env guix build gnew --keep-failed
ef5dd60a 15057@end example
ef5dd60a 15058
cf4a9129
LC
15059Using @code{--keep-failed} makes it easier to debug build failures since
15060it provides access to the failed build tree. Another useful
15061command-line option when debugging is @code{--log-file}, to access the
15062build log.
ef5dd60a 15063
cf4a9129
LC
15064If the package is unknown to the @command{guix} command, it may be that
15065the source file contains a syntax error, or lacks a @code{define-public}
15066clause to export the package variable. To figure it out, you may load
15067the module from Guile to get more information about the actual error:
ef5dd60a 15068
cf4a9129
LC
15069@example
15070./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
15071@end example
ef5dd60a 15072
cf4a9129
LC
15073Once your package builds correctly, please send us a patch
15074(@pxref{Contributing}). Well, if you need help, we will be happy to
15075help you too. Once the patch is committed in the Guix repository, the
15076new package automatically gets built on the supported platforms by
2b1cee21 15077@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 15078system}.
ef5dd60a 15079
cf4a9129
LC
15080@cindex substituter
15081Users can obtain the new package definition simply by running
15082@command{guix pull} (@pxref{Invoking guix pull}). When
15083@code{hydra.gnu.org} is done building the package, installing the
15084package automatically downloads binaries from there
15085(@pxref{Substitutes}). The only place where human intervention is
15086needed is to review and apply the patch.
ef5dd60a 15087
ef5dd60a 15088
cf4a9129 15089@menu
ec0339cd
LC
15090* Software Freedom:: What may go into the distribution.
15091* Package Naming:: What's in a name?
15092* Version Numbers:: When the name is not enough.
cbd02397 15093* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
15094* Python Modules:: Taming the snake.
15095* Perl Modules:: Little pearls.
e1c963bf 15096* Java Packages:: Coffee break.
ec0339cd 15097* Fonts:: Fond of fonts.
cf4a9129 15098@end menu
ef5dd60a 15099
cf4a9129
LC
15100@node Software Freedom
15101@subsection Software Freedom
ef5dd60a 15102
cf4a9129 15103@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
e32171ee 15104@cindex free software
cf4a9129
LC
15105The GNU operating system has been developed so that users can have
15106freedom in their computing. GNU is @dfn{free software}, meaning that
15107users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
15108essential freedoms}: to run the program, to study and change the program
15109in source code form, to redistribute exact copies, and to distribute
15110modified versions. Packages found in the GNU distribution provide only
15111software that conveys these four freedoms.
c11a6eb1 15112
cf4a9129
LC
15113In addition, the GNU distribution follow the
15114@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
15115software distribution guidelines}. Among other things, these guidelines
15116reject non-free firmware, recommendations of non-free software, and
15117discuss ways to deal with trademarks and patents.
ef5dd60a 15118
1068f26b
AE
15119Some otherwise free upstream package sources contain a small and optional
15120subset that violates the above guidelines, for instance because this subset
15121is itself non-free code. When that happens, the offending items are removed
15122with appropriate patches or code snippets in the @code{origin} form of the
15123package (@pxref{Defining Packages}). This way, @code{guix
cf4a9129
LC
15124build --source} returns the ``freed'' source rather than the unmodified
15125upstream source.
ef5dd60a 15126
ef5dd60a 15127
cf4a9129
LC
15128@node Package Naming
15129@subsection Package Naming
ef5dd60a 15130
e32171ee 15131@cindex package name
cf4a9129
LC
15132A package has actually two names associated with it:
15133First, there is the name of the @emph{Scheme variable}, the one following
15134@code{define-public}. By this name, the package can be made known in the
15135Scheme code, for instance as input to another package. Second, there is
15136the string in the @code{name} field of a package definition. This name
15137is used by package management commands such as
15138@command{guix package} and @command{guix build}.
ef5dd60a 15139
cf4a9129
LC
15140Both are usually the same and correspond to the lowercase conversion of
15141the project name chosen upstream, with underscores replaced with
15142hyphens. For instance, GNUnet is available as @code{gnunet}, and
15143SDL_net as @code{sdl-net}.
927097ef 15144
cf4a9129 15145We do not add @code{lib} prefixes for library packages, unless these are
081145cf 15146already part of the official project name. But @pxref{Python
cf4a9129
LC
15147Modules} and @ref{Perl Modules} for special rules concerning modules for
15148the Python and Perl languages.
927097ef 15149
1b366ee4 15150Font package names are handled differently, @pxref{Fonts}.
7fec52b7 15151
ef5dd60a 15152
cf4a9129
LC
15153@node Version Numbers
15154@subsection Version Numbers
ef5dd60a 15155
e32171ee 15156@cindex package version
cf4a9129
LC
15157We usually package only the latest version of a given free software
15158project. But sometimes, for instance for incompatible library versions,
15159two (or more) versions of the same package are needed. These require
15160different Scheme variable names. We use the name as defined
15161in @ref{Package Naming}
15162for the most recent version; previous versions use the same name, suffixed
15163by @code{-} and the smallest prefix of the version number that may
15164distinguish the two versions.
ef5dd60a 15165
cf4a9129
LC
15166The name inside the package definition is the same for all versions of a
15167package and does not contain any version number.
ef5dd60a 15168
cf4a9129 15169For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 15170
cf4a9129
LC
15171@example
15172(define-public gtk+
15173 (package
17d8e33f
ML
15174 (name "gtk+")
15175 (version "3.9.12")
15176 ...))
cf4a9129
LC
15177(define-public gtk+-2
15178 (package
17d8e33f
ML
15179 (name "gtk+")
15180 (version "2.24.20")
15181 ...))
cf4a9129
LC
15182@end example
15183If we also wanted GTK+ 3.8.2, this would be packaged as
15184@example
15185(define-public gtk+-3.8
15186 (package
17d8e33f
ML
15187 (name "gtk+")
15188 (version "3.8.2")
15189 ...))
cf4a9129 15190@end example
ef5dd60a 15191
880d647d
LC
15192@c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
15193@c for a discussion of what follows.
15194@cindex version number, for VCS snapshots
15195Occasionally, we package snapshots of upstream's version control system
15196(VCS) instead of formal releases. This should remain exceptional,
15197because it is up to upstream developers to clarify what the stable
15198release is. Yet, it is sometimes necessary. So, what should we put in
15199the @code{version} field?
15200
15201Clearly, we need to make the commit identifier of the VCS snapshot
15202visible in the version string, but we also need to make sure that the
15203version string is monotonically increasing so that @command{guix package
15204--upgrade} can determine which version is newer. Since commit
15205identifiers, notably with Git, are not monotonically increasing, we add
15206a revision number that we increase each time we upgrade to a newer
15207snapshot. The resulting version string looks like this:
15208
15209@example
152102.0.11-3.cabba9e
15211 ^ ^ ^
15212 | | `-- upstream commit ID
15213 | |
15214 | `--- Guix package revision
15215 |
15216latest upstream version
15217@end example
15218
15219It is a good idea to strip commit identifiers in the @code{version}
15220field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
15221aesthetics have a role to play here) as well as problems related to OS
15222limits such as the maximum shebang length (127 bytes for the Linux
15223kernel.) It is best to use the full commit identifiers in
561360a5
LC
15224@code{origin}s, though, to avoid ambiguities. A typical package
15225definition may look like this:
15226
15227@example
15228(define my-package
6e42660b 15229 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7")
15230 (revision "1")) ;Guix package revision
561360a5 15231 (package
6e42660b 15232 (version (string-append "0.9-" revision "."
561360a5
LC
15233 (string-take commit 7)))
15234 (source (origin
15235 (method git-fetch)
15236 (uri (git-reference
15237 (url "git://example.org/my-package.git")
15238 (commit commit)))
15239 (sha256 (base32 "1mbikn@dots{}"))
15240 (file-name (string-append "my-package-" version
15241 "-checkout"))))
15242 ;; @dots{}
15243 )))
15244@end example
880d647d 15245
cbd02397
LC
15246@node Synopses and Descriptions
15247@subsection Synopses and Descriptions
15248
e32171ee
JD
15249@cindex package description
15250@cindex package synopsis
cbd02397
LC
15251As we have seen before, each package in GNU@tie{}Guix includes a
15252synopsis and a description (@pxref{Defining Packages}). Synopses and
15253descriptions are important: They are what @command{guix package
15254--search} searches, and a crucial piece of information to help users
15255determine whether a given package suits their needs. Consequently,
15256packagers should pay attention to what goes into them.
15257
15258Synopses must start with a capital letter and must not end with a
15259period. They must not start with ``a'' or ``the'', which usually does
15260not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
15261tool that frobs files''. The synopsis should say what the package
15262is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
15263used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
15264matching a pattern''.
15265
15266Keep in mind that the synopsis must be meaningful for a very wide
15267audience. For example, ``Manipulate alignments in the SAM format''
15268might make sense for a seasoned bioinformatics researcher, but might be
15269fairly unhelpful or even misleading to a non-specialized audience. It
15270is a good idea to come up with a synopsis that gives an idea of the
15271application domain of the package. In this example, this might give
15272something like ``Manipulate nucleotide sequence alignments'', which
15273hopefully gives the user a better idea of whether this is what they are
15274looking for.
15275
cbd02397
LC
15276Descriptions should take between five and ten lines. Use full
15277sentences, and avoid using acronyms without first introducing them.
762e54b7
LC
15278Please avoid marketing phrases such as ``world-leading'',
15279``industrial-strength'', and ``next-generation'', and avoid superlatives
15280like ``the most advanced''---they are not helpful to users looking for a
15281package and may even sound suspicious. Instead, try to be factual,
15282mentioning use cases and features.
15283
15284@cindex Texinfo markup, in package descriptions
cbd02397
LC
15285Descriptions can include Texinfo markup, which is useful to introduce
15286ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
15287hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
15288should be careful when using some characters for example @samp{@@} and
15289curly braces which are the basic special characters in Texinfo
15290(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
15291such as @command{guix package --show} take care of rendering it
15292appropriately.
cbd02397
LC
15293
15294Synopses and descriptions are translated by volunteers
15295@uref{http://translationproject.org/domain/guix-packages.html, at the
15296Translation Project} so that as many users as possible can read them in
15297their native language. User interfaces search them and display them in
15298the language specified by the current locale.
15299
15300Translation is a lot of work so, as a packager, please pay even more
15301attention to your synopses and descriptions as every change may entail
ba7d6c76 15302additional work for translators. In order to help them, it is possible
36743e71 15303to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
15304special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
15305Gettext}):
15306
15307@example
15308;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
15309(description "ARandR is designed to provide a simple visual front end
15310for the X11 resize-and-rotate (RandR) extension. @dots{}")
15311@end example
cbd02397 15312
ef5dd60a 15313
cf4a9129
LC
15314@node Python Modules
15315@subsection Python Modules
ef5dd60a 15316
e32171ee 15317@cindex python
cf4a9129
LC
15318We currently package Python 2 and Python 3, under the Scheme variable names
15319@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
15320To avoid confusion and naming clashes with other programming languages, it
15321seems desirable that the name of a package for a Python module contains
15322the word @code{python}.
ef5dd60a 15323
cf4a9129
LC
15324Some modules are compatible with only one version of Python, others with both.
15325If the package Foo compiles only with Python 3, we name it
15326@code{python-foo}; if it compiles only with Python 2, we name it
15327@code{python2-foo}. If it is compatible with both versions, we create two
15328packages with the corresponding names.
ef5dd60a 15329
cf4a9129
LC
15330If a project already contains the word @code{python}, we drop this;
15331for instance, the module python-dateutil is packaged under the names
99c866a0
HG
15332@code{python-dateutil} and @code{python2-dateutil}. If the project name
15333starts with @code{py} (e.g. @code{pytz}), we keep it and prefix it as
15334described above.
113daf62 15335
e940a271
HG
15336@subsubsection Specifying Dependencies
15337@cindex inputs, for Python packages
15338
15339Dependency information for Python packages is usually available in the
15340package source tree, with varying degrees of accuracy: in the
15341@file{setup.py} file, in @file{requirements.txt}, or in @file{tox.ini}.
15342
15343Your mission, when writing a recipe for a Python package, is to map
15344these dependencies to the appropriate type of ``input'' (@pxref{package
15345Reference, inputs}). Although the @code{pypi} importer normally does a
15346good job (@pxref{Invoking guix import}), you may want to check the
15347following check list to determine which dependency goes where.
15348
15349@itemize
15350
aaf75c89
HG
15351@item
15352We currently package Python 2 with @code{setuptools} and @code{pip}
15353installed like Python 3.4 has per default. Thus you don't need to
891a843d
HG
15354specify either of these as an input. @command{guix lint} will warn you
15355if you do.
aaf75c89 15356
e940a271
HG
15357@item
15358Python dependencies required at run time go into
15359@code{propagated-inputs}. They are typically defined with the
15360@code{install_requires} keyword in @file{setup.py}, or in the
15361@file{requirements.txt} file.
15362
15363@item
15364Python packages required only at build time---e.g., those listed with
15365the @code{setup_requires} keyword in @file{setup.py}---or only for
15366testing---e.g., those in @code{tests_require}---go into
15367@code{native-inputs}. The rationale is that (1) they do not need to be
15368propagated because they are not needed at run time, and (2) in a
15369cross-compilation context, it's the ``native'' input that we'd want.
15370
aaf75c89 15371Examples are the @code{pytest}, @code{mock}, and @code{nose} test
e940a271
HG
15372frameworks. Of course if any of these packages is also required at
15373run-time, it needs to go to @code{propagated-inputs}.
15374
15375@item
15376Anything that does not fall in the previous categories goes to
15377@code{inputs}, for example programs or C libraries required for building
15378Python packages containing C extensions.
15379
15380@item
15381If a Python package has optional dependencies (@code{extras_require}),
15382it is up to you to decide whether to add them or not, based on their
15383usefulness/overhead ratio (@pxref{Submitting Patches, @command{guix
15384size}}).
15385
15386@end itemize
15387
15388
cf4a9129
LC
15389@node Perl Modules
15390@subsection Perl Modules
523e4896 15391
e32171ee 15392@cindex perl
cf4a9129
LC
15393Perl programs standing for themselves are named as any other package,
15394using the lowercase upstream name.
15395For Perl packages containing a single class, we use the lowercase class name,
15396replace all occurrences of @code{::} by dashes and prepend the prefix
15397@code{perl-}.
15398So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
15399Modules containing several classes keep their lowercase upstream name and
15400are also prepended by @code{perl-}. Such modules tend to have the word
15401@code{perl} somewhere in their name, which gets dropped in favor of the
15402prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 15403
523e4896 15404
e1c963bf
HG
15405@node Java Packages
15406@subsection Java Packages
15407
e32171ee 15408@cindex java
e1c963bf
HG
15409Java programs standing for themselves are named as any other package,
15410using the lowercase upstream name.
15411
15412To avoid confusion and naming clashes with other programming languages,
15413it is desirable that the name of a package for a Java package is
15414prefixed with @code{java-}. If a project already contains the word
15415@code{java}, we drop this; for instance, the package @code{ngsjava} is
15416packaged under the name @code{java-ngs}.
15417
15418For Java packages containing a single class or a small class hierarchy,
15419we use the lowercase class name, replace all occurrences of @code{.} by
15420dashes and prepend the prefix @code{java-}. So the class
15421@code{apache.commons.cli} becomes package
15422@code{java-apache-commons-cli}.
15423
15424
7fec52b7
AE
15425@node Fonts
15426@subsection Fonts
15427
e32171ee 15428@cindex fonts
7fec52b7
AE
15429For fonts that are in general not installed by a user for typesetting
15430purposes, or that are distributed as part of a larger software package,
15431we rely on the general packaging rules for software; for instance, this
15432applies to the fonts delivered as part of the X.Org system or fonts that
15433are part of TeX Live.
15434
15435To make it easier for a user to search for fonts, names for other packages
15436containing only fonts are constructed as follows, independently of the
15437upstream package name.
15438
15439The name of a package containing only one font family starts with
15440@code{font-}; it is followed by the foundry name and a dash @code{-}
15441if the foundry is known, and the font family name, in which spaces are
15442replaced by dashes (and as usual, all upper case letters are transformed
15443to lower case).
15444For example, the Gentium font family by SIL is packaged under the name
15445@code{font-sil-gentium}.
15446
15447For a package containing several font families, the name of the collection
15448is used in the place of the font family name.
15449For instance, the Liberation fonts consist of three families,
15450Liberation Sans, Liberation Serif and Liberation Mono.
15451These could be packaged separately under the names
15452@code{font-liberation-sans} and so on; but as they are distributed together
15453under a common name, we prefer to package them together as
15454@code{font-liberation}.
15455
15456In the case where several formats of the same font family or font collection
15457are packaged separately, a short form of the format, prepended by a dash,
15458is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 15459@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
15460fonts.
15461
15462
b25937e3 15463
cf4a9129
LC
15464@node Bootstrapping
15465@section Bootstrapping
b25937e3 15466
cf4a9129 15467@c Adapted from the ELS 2013 paper.
b25937e3 15468
cf4a9129 15469@cindex bootstrapping
7889394e 15470
cf4a9129
LC
15471Bootstrapping in our context refers to how the distribution gets built
15472``from nothing''. Remember that the build environment of a derivation
15473contains nothing but its declared inputs (@pxref{Introduction}). So
15474there's an obvious chicken-and-egg problem: how does the first package
15475get built? How does the first compiler get compiled? Note that this is
15476a question of interest only to the curious hacker, not to the regular
15477user, so you can shamelessly skip this section if you consider yourself
15478a ``regular user''.
72b9d60d 15479
cf4a9129
LC
15480@cindex bootstrap binaries
15481The GNU system is primarily made of C code, with libc at its core. The
15482GNU build system itself assumes the availability of a Bourne shell and
15483command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
15484`grep'. Furthermore, build programs---programs that run
15485@code{./configure}, @code{make}, etc.---are written in Guile Scheme
15486(@pxref{Derivations}). Consequently, to be able to build anything at
15487all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
15488Binutils, libc, and the other packages mentioned above---the
15489@dfn{bootstrap binaries}.
72b9d60d 15490
cf4a9129
LC
15491These bootstrap binaries are ``taken for granted'', though we can also
15492re-create them if needed (more on that later).
72b9d60d 15493
cf4a9129 15494@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 15495
cf4a9129
LC
15496@c As of Emacs 24.3, Info-mode displays the image, but since it's a
15497@c large image, it's hard to scroll. Oh well.
15498@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 15499
cf4a9129
LC
15500The figure above shows the very beginning of the dependency graph of the
15501distribution, corresponding to the package definitions of the @code{(gnu
d33fa0c7
LC
15502packages bootstrap)} module. A similar figure can be generated with
15503@command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
15504
15505@example
15506guix graph -t derivation \
15507 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
15508 | dot -Tps > t.ps
15509@end example
15510
15511At this level of detail, things are
cf4a9129
LC
15512slightly complex. First, Guile itself consists of an ELF executable,
15513along with many source and compiled Scheme files that are dynamically
15514loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
15515tarball shown in this graph. This tarball is part of Guix's ``source''
15516distribution, and gets inserted into the store with @code{add-to-store}
15517(@pxref{The Store}).
2e7b5cea 15518
cf4a9129
LC
15519But how do we write a derivation that unpacks this tarball and adds it
15520to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
15521derivation---the first one that gets built---uses @code{bash} as its
15522builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
15523@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
15524@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
15525the Guix source distribution, whose sole purpose is to allow the Guile
15526tarball to be unpacked.
fb729425 15527
cf4a9129
LC
15528Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
15529Guile that can be used to run subsequent build programs. Its first task
15530is to download tarballs containing the other pre-built binaries---this
15531is what the @code{.tar.xz.drv} derivations do. Guix modules such as
15532@code{ftp-client.scm} are used for this purpose. The
15533@code{module-import.drv} derivations import those modules in a directory
15534in the store, using the original layout. The
15535@code{module-import-compiled.drv} derivations compile those modules, and
15536write them in an output directory with the right layout. This
15537corresponds to the @code{#:modules} argument of
15538@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 15539
cf4a9129
LC
15540Finally, the various tarballs are unpacked by the
15541derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
15542etc., at which point we have a working C tool chain.
fb729425 15543
fb729425 15544
cf4a9129 15545@unnumberedsubsec Building the Build Tools
523e4896 15546
cf4a9129
LC
15547Bootstrapping is complete when we have a full tool chain that does not
15548depend on the pre-built bootstrap tools discussed above. This
15549no-dependency requirement is verified by checking whether the files of
15550the final tool chain contain references to the @file{/gnu/store}
15551directories of the bootstrap inputs. The process that leads to this
15552``final'' tool chain is described by the package definitions found in
1f6f57df 15553the @code{(gnu packages commencement)} module.
df2ce343 15554
d33fa0c7
LC
15555The @command{guix graph} command allows us to ``zoom out'' compared to
15556the graph above, by looking at the level of package objects instead of
15557individual derivations---remember that a package may translate to
15558several derivations, typically one derivation to download its source,
15559one to build the Guile modules it needs, and one to actually build the
15560package from source. The command:
15561
15562@example
15563guix graph -t bag \
15564 -e '(@@@@ (gnu packages commencement)
15565 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
15566@end example
15567
15568@noindent
15569produces the dependency graph leading to the ``final'' C
15570library@footnote{You may notice the @code{glibc-intermediate} label,
15571suggesting that it is not @emph{quite} final, but as a good
15572approximation, we will consider it final.}, depicted below.
15573
15574@image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
15575
cf4a9129
LC
15576@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
15577The first tool that gets built with the bootstrap binaries is
d33fa0c7
LC
15578GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
15579for all the following packages. From there Findutils and Diffutils get
15580built.
523e4896 15581
cf4a9129
LC
15582Then come the first-stage Binutils and GCC, built as pseudo cross
15583tools---i.e., with @code{--target} equal to @code{--host}. They are
15584used to build libc. Thanks to this cross-build trick, this libc is
15585guaranteed not to hold any reference to the initial tool chain.
4af2447e 15586
d33fa0c7
LC
15587From there the final Binutils and GCC (not shown above) are built.
15588GCC uses @code{ld}
cf4a9129
LC
15589from the final Binutils, and links programs against the just-built libc.
15590This tool chain is used to build the other packages used by Guix and by
15591the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 15592
cf4a9129
LC
15593And voilà! At this point we have the complete set of build tools that
15594the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
15595variable of the @code{(gnu packages commencement)} module, and are
15596implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 15597(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 15598
4af2447e 15599
cf4a9129 15600@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 15601
e32171ee 15602@cindex bootstrap binaries
cf4a9129
LC
15603Because the final tool chain does not depend on the bootstrap binaries,
15604those rarely need to be updated. Nevertheless, it is useful to have an
15605automated way to produce them, should an update occur, and this is what
15606the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 15607
cf4a9129
LC
15608The following command builds the tarballs containing the bootstrap
15609binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
15610of Coreutils and other basic command-line tools):
4b2615e1 15611
cf4a9129
LC
15612@example
15613guix build bootstrap-tarballs
15614@end example
15615
15616The generated tarballs are those that should be referred to in the
15617@code{(gnu packages bootstrap)} module mentioned at the beginning of
15618this section.
15619
15620Still here? Then perhaps by now you've started to wonder: when do we
15621reach a fixed point? That is an interesting question! The answer is
15622unknown, but if you would like to investigate further (and have
15623significant computational and storage resources to do so), then let us
15624know.
15625
15626@node Porting
15627@section Porting to a New Platform
15628
15629As discussed above, the GNU distribution is self-contained, and
15630self-containment is achieved by relying on pre-built ``bootstrap
15631binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
15632operating system kernel, CPU architecture, and application binary
15633interface (ABI). Thus, to port the distribution to a platform that is
15634not yet supported, one must build those bootstrap binaries, and update
15635the @code{(gnu packages bootstrap)} module to use them on that platform.
15636
15637Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
15638When everything goes well, and assuming the GNU tool chain supports the
15639target platform, this can be as simple as running a command like this
15640one:
15641
15642@example
15643guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
15644@end example
15645
1c0c417d
LC
15646For this to work, the @code{glibc-dynamic-linker} procedure in
15647@code{(gnu packages bootstrap)} must be augmented to return the right
15648file name for libc's dynamic linker on that platform; likewise,
15649@code{system->linux-architecture} in @code{(gnu packages linux)} must be
15650taught about the new platform.
15651
cf4a9129 15652Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
15653to be updated to refer to these binaries on the target platform. That
15654is, the hashes and URLs of the bootstrap tarballs for the new platform
15655must be added alongside those of the currently supported platforms. The
15656bootstrap Guile tarball is treated specially: it is expected to be
03d0e2d2 15657available locally, and @file{gnu/local.mk} has rules do download it for
1c0c417d
LC
15658the supported architectures; a rule for the new platform must be added
15659as well.
cf4a9129
LC
15660
15661In practice, there may be some complications. First, it may be that the
15662extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
15663above) is not recognized by all the GNU tools. Typically, glibc
15664recognizes some of these, whereas GCC uses an extra @code{--with-abi}
15665configure flag (see @code{gcc.scm} for examples of how to handle this).
15666Second, some of the required packages could fail to build for that
15667platform. Lastly, the generated binaries could be broken for some
15668reason.
4af2447e 15669
9bf3c1a7 15670@c *********************************************************************
8c01b9d0 15671@include contributing.texi
c78bd12b 15672
568717fd
LC
15673@c *********************************************************************
15674@node Acknowledgments
15675@chapter Acknowledgments
15676
136787cb
LC
15677Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
15678which was designed and
4c7ac9aa
LC
15679implemented by Eelco Dolstra, with contributions from other people (see
15680the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
15681management, and promoted unprecedented features, such as transactional
15682package upgrades and rollbacks, per-user profiles, and referentially
15683transparent build processes. Without this work, Guix would not exist.
15684
15685The Nix-based software distributions, Nixpkgs and NixOS, have also been
15686an inspiration for Guix.
15687
4c7ac9aa
LC
15688GNU@tie{}Guix itself is a collective work with contributions from a
15689number of people. See the @file{AUTHORS} file in Guix for more
15690information on these fine people. The @file{THANKS} file lists people
15691who have helped by reporting bugs, taking care of the infrastructure,
15692providing artwork and themes, making suggestions, and more---thank you!
15693
15694
568717fd
LC
15695@c *********************************************************************
15696@node GNU Free Documentation License
15697@appendix GNU Free Documentation License
e32171ee 15698@cindex license, GNU Free Documentation License
568717fd
LC
15699@include fdl-1.3.texi
15700
15701@c *********************************************************************
15702@node Concept Index
15703@unnumbered Concept Index
15704@printindex cp
15705
a85b83d2
LC
15706@node Programming Index
15707@unnumbered Programming Index
15708@syncodeindex tp fn
15709@syncodeindex vr fn
568717fd
LC
15710@printindex fn
15711
15712@bye
15713
15714@c Local Variables:
15715@c ispell-local-dictionary: "american";
15716@c End: