packages: Add 'package-mapping' and base 'package-input-rewriting' on it.
[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 34Copyright @copyright{} 2017 Mathieu Othacehe@*
82ccc499 35Copyright @copyright{} 2017 Federico Beffa@*
9260b9d1
TD
36Copyright @copyright{} 2017 Carlo Zancanaro@*
37Copyright @copyright{} 2017 Thomas Danckaert
7df7a74e
NK
38
39Permission is granted to copy, distribute and/or modify this document
40under the terms of the GNU Free Documentation License, Version 1.3 or
41any later version published by the Free Software Foundation; with no
42Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
43copy of the license is included in the section entitled ``GNU Free
44Documentation License''.
45@end copying
568717fd 46
abd67856 47@dircategory System administration
568717fd 48@direntry
abd67856
LC
49* Guix: (guix). Manage installed software and system configuration.
50* guix package: (guix)Invoking guix package. Installing, removing, and upgrading packages.
abd67856
LC
51* guix gc: (guix)Invoking guix gc. Reclaiming unused disk space.
52* guix pull: (guix)Invoking guix pull. Update the list of available packages.
53* guix system: (guix)Invoking guix system. Manage the operating system configuration.
568717fd 54@end direntry
568717fd 55
372c4bbc
DT
56@dircategory Software development
57@direntry
abd67856 58* guix environment: (guix)Invoking guix environment. Building development environments with Guix.
ad172c4a
LC
59* guix build: (guix)Invoking guix build. Building packages.
60* guix pack: (guix)Invoking guix pack. Creating binary bundles.
372c4bbc
DT
61@end direntry
62
568717fd 63@titlepage
7730d112
LC
64@title GNU Guix Reference Manual
65@subtitle Using the GNU Guix Functional Package Manager
2cbed07e 66@author The GNU Guix Developers
568717fd
LC
67
68@page
69@vskip 0pt plus 1filll
70Edition @value{EDITION} @*
71@value{UPDATED} @*
72
7df7a74e 73@insertcopying
568717fd
LC
74@end titlepage
75
568717fd
LC
76@contents
77
78@c *********************************************************************
79@node Top
f8348b91 80@top GNU Guix
568717fd 81
f8348b91
LC
82This document describes GNU Guix version @value{VERSION}, a functional
83package management tool written for the GNU system.
568717fd
LC
84
85@menu
86* Introduction:: What is Guix about?
bd5e766b 87* Installation:: Installing Guix.
eeaf4427 88* Package Management:: Package installation, upgrade, etc.
568717fd
LC
89* Programming Interface:: Using Guix in Scheme.
90* Utilities:: Package management commands.
a1ba8475 91* GNU Distribution:: Software for your friendly GNU system.
9bf3c1a7 92* Contributing:: Your help needed!
568717fd
LC
93
94* Acknowledgments:: Thanks!
95* GNU Free Documentation License:: The license of this manual.
96* Concept Index:: Concepts.
a85b83d2 97* Programming Index:: Data types, functions, and variables.
aaa3eaa9
LC
98
99@detailmenu
100 --- The Detailed Node Listing ---
101
102Installation
103
1b2b8177 104* Binary Installation:: Getting Guix running in no time!
aaa3eaa9 105* Requirements:: Software needed to build and run Guix.
ec0339cd 106* Running the Test Suite:: Testing Guix.
aaa3eaa9
LC
107* Setting Up the Daemon:: Preparing the build daemon's environment.
108* Invoking guix-daemon:: Running the build daemon.
0e2d0213 109* Application Setup:: Application-specific setup.
aaa3eaa9
LC
110
111Setting Up the Daemon
112
113* Build Environment Setup:: Preparing the isolated build environment.
114* Daemon Offload Setup:: Offloading builds to remote machines.
115
116Package Management
117
118* Features:: How Guix will make your life brighter.
119* Invoking guix package:: Package installation, removal, etc.
aaa3eaa9
LC
120* Substitutes:: Downloading pre-built binaries.
121* Packages with Multiple Outputs:: Single source package, multiple outputs.
122* Invoking guix gc:: Running the garbage collector.
123* Invoking guix pull:: Fetching the latest Guix and distribution.
239c2266 124* Invoking guix pack:: Creating software bundles.
aaa3eaa9
LC
125* Invoking guix archive:: Exporting and importing store files.
126
127Programming Interface
128
129* Defining Packages:: Defining new packages.
130* Build Systems:: Specifying how packages are built.
131* The Store:: Manipulating the package store.
132* Derivations:: Low-level interface to package derivations.
133* The Store Monad:: Purely functional interface to the store.
134* G-Expressions:: Manipulating build expressions.
135
92492b23
LC
136Defining Packages
137
138* package Reference:: The package data type.
139* origin Reference:: The origin data type.
140
aaa3eaa9
LC
141Utilities
142
143* Invoking guix build:: Building packages from the command line.
fcc58db6 144* Invoking guix edit:: Editing package definitions.
aaa3eaa9
LC
145* Invoking guix download:: Downloading a file and printing its hash.
146* Invoking guix hash:: Computing the cryptographic hash of a file.
147* Invoking guix import:: Importing package definitions.
148* Invoking guix refresh:: Updating package definitions.
149* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 150* Invoking guix size:: Profiling disk usage.
88856916 151* Invoking guix graph:: Visualizing the graph of packages.
aaa3eaa9 152* Invoking guix environment:: Setting up development environments.
aff8ce7c 153* Invoking guix publish:: Sharing substitutes.
d23c20f1 154* Invoking guix challenge:: Challenging substitute servers.
f11c444d 155* Invoking guix copy:: Copying to and from a remote store.
32efa254 156* Invoking guix container:: Process isolation.
aaa3eaa9 157
e3009f60
LC
158Invoking @command{guix build}
159
160* Common Build Options:: Build options for most commands.
f11c444d 161* Package Transformation Options:: Creating variants of packages.
e3009f60
LC
162* Additional Build Options:: Options specific to 'guix build'.
163
aaa3eaa9
LC
164GNU Distribution
165
166* System Installation:: Installing the whole operating system.
35ed9306 167* System Configuration:: Configuring the operating system.
aaa3eaa9
LC
168* Installing Debugging Files:: Feeding the debugger.
169* Security Updates:: Deploying security fixes quickly.
170* Package Modules:: Packages from the programmer's viewpoint.
171* Packaging Guidelines:: Growing the distribution.
172* Bootstrapping:: GNU/Linux built from scratch.
173* Porting:: Targeting another platform or kernel.
174
e3009f60
LC
175System Installation
176
177* Limitations:: What you can expect.
178* Hardware Considerations:: Supported hardware.
179* USB Stick Installation:: Preparing the installation medium.
180* Preparing for Installation:: Networking, partitioning, etc.
181* Proceeding with the Installation:: The real thing.
c8b54374 182* Installing GuixSD in a VM:: GuixSD playground.
e3009f60
LC
183* Building the Installation Image:: How this comes to be.
184
aaa3eaa9
LC
185System Configuration
186
187* Using the Configuration System:: Customizing your GNU system.
188* operating-system Reference:: Detail of operating-system declarations.
189* File Systems:: Configuring file system mounts.
190* Mapped Devices:: Block device extra processing.
191* User Accounts:: Specifying user accounts.
598e19dc 192* Locales:: Language and cultural convention settings.
aaa3eaa9
LC
193* Services:: Specifying system services.
194* Setuid Programs:: Programs running with root privileges.
1b2b8177 195* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 196* Name Service Switch:: Configuring libc's name service switch.
aaa3eaa9
LC
197* Initial RAM Disk:: Linux-Libre bootstrapping.
198* GRUB Configuration:: Configuring the boot loader.
199* Invoking guix system:: Instantiating a system configuration.
97d76250 200* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
aaa3eaa9
LC
201* Defining Services:: Adding new service definitions.
202
203Services
204
205* Base Services:: Essential system services.
c311089b 206* Scheduled Job Execution:: The mcron service.
92c03a87 207* Log Rotation:: The rottlog service.
aaa3eaa9
LC
208* Networking Services:: Network setup, SSH daemon, etc.
209* X Window:: Graphical display.
f11c444d 210* Printing Services:: Local and remote printer support.
1b2b8177
LC
211* Desktop Services:: D-Bus and desktop services.
212* Database Services:: SQL databases.
d8c18af8 213* Mail Services:: IMAP, POP3, SMTP, and all that.
78cef99b 214* Messaging Services:: Messaging services.
859e367d 215* Kerberos Services:: Kerberos services.
cbd02397 216* Web Services:: Web servers.
2be1b471 217* VPN Services:: VPN daemons.
eb419bc9 218* Network File System:: NFS related services.
f11c444d 219* Continuous Integration:: The Cuirass service.
bfbf6e1e 220* Power management Services:: The TLP tool.
dbc6d370 221* Miscellaneous Services:: Other services.
aaa3eaa9 222
0adfe95a
LC
223Defining Services
224
225* Service Composition:: The model for composing services.
226* Service Types and Services:: Types and services.
227* Service Reference:: API reference.
dd17bc38 228* Shepherd Services:: A particular type of service.
0adfe95a 229
aaa3eaa9
LC
230Packaging Guidelines
231
ec0339cd
LC
232* Software Freedom:: What may go into the distribution.
233* Package Naming:: What's in a name?
234* Version Numbers:: When the name is not enough.
cbd02397 235* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
236* Python Modules:: Taming the snake.
237* Perl Modules:: Little pearls.
e1c963bf 238* Java Packages:: Coffee break.
ec0339cd 239* Fonts:: Fond of fonts.
aaa3eaa9 240
8c01b9d0
ML
241Contributing
242
243* Building from Git:: The latest and greatest.
244* Running Guix Before It Is Installed:: Hacker tricks.
245* The Perfect Setup:: The right tools.
246* Coding Style:: Hygiene of the contributor.
247* Submitting Patches:: Share your work.
248
249Coding Style
250
251* Programming Paradigm:: How to compose your elements.
252* Modules:: Where to store your code?
253* Data Types and Pattern Matching:: Implementing data structures.
254* Formatting Code:: Writing conventions.
255
aaa3eaa9 256@end detailmenu
568717fd
LC
257@end menu
258
259@c *********************************************************************
260@node Introduction
261@chapter Introduction
262
6f773606 263@cindex purpose
c80e7e55 264GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
6f773606
LC
265using the international phonetic alphabet (IPA).} is a package
266management tool for the GNU system. Guix makes it easy for unprivileged
267users to install, upgrade, or remove packages, to roll back to a
268previous package set, to build packages from source, and generally
269assists with the creation and maintenance of software environments.
270
271@cindex user interfaces
272Guix provides a command-line package management interface
273(@pxref{Invoking guix package}), a set of command-line utilities
deb6276d 274(@pxref{Utilities}), as well as Scheme programming interfaces
6f773606
LC
275(@pxref{Programming Interface}).
276@cindex build daemon
277Its @dfn{build daemon} is responsible for building packages on behalf of
278users (@pxref{Setting Up the Daemon}) and for downloading pre-built
279binaries from authorized sources (@pxref{Substitutes}).
280
281@cindex extensibility of the distribution
e32171ee 282@cindex customization, of packages
6f773606
LC
283Guix includes package definitions for many GNU and non-GNU packages, all
284of which @uref{https://www.gnu.org/philosophy/free-sw.html, respect the
285user's computing freedom}. It is @emph{extensible}: users can write
286their own package definitions (@pxref{Defining Packages}) and make them
287available as independent package modules (@pxref{Package Modules}). It
288is also @emph{customizable}: users can @emph{derive} specialized package
289definitions from existing ones, including from the command line
290(@pxref{Package Transformation Options}).
291
292@cindex Guix System Distribution
293@cindex GuixSD
294You can install GNU@tie{}Guix on top of an existing GNU/Linux system
295where it complements the available tools without interference
296(@pxref{Installation}), or you can use it as part of the standalone
297@dfn{Guix System Distribution} or GuixSD (@pxref{GNU Distribution}).
298With GNU@tie{}GuixSD, you @emph{declare} all aspects of the operating
299system configuration and Guix takes care of instantiating the
300configuration in a transactional, reproducible, and stateless fashion
301(@pxref{System Configuration}).
568717fd
LC
302
303@cindex functional package management
6f773606 304Under the hood, Guix implements the @dfn{functional package management}
136787cb
LC
305discipline pioneered by Nix (@pxref{Acknowledgments}).
306In Guix, the package build and installation process is seen
6f773606 307as a @emph{function}, in the mathematical sense. That function takes inputs,
4bfc4ea3
NK
308such as build scripts, a compiler, and libraries, and
309returns an installed package. As a pure function, its result depends
568717fd
LC
310solely on its inputs---for instance, it cannot refer to software or
311scripts that were not explicitly passed as inputs. A build function
4bfc4ea3 312always produces the same result when passed a given set of inputs. It
f97c9175 313cannot alter the environment of the running system in
568717fd
LC
314any way; for instance, it cannot create, modify, or delete files outside
315of its build and installation directories. This is achieved by running
e900c503 316build processes in isolated environments (or @dfn{containers}), where only their
4bfc4ea3 317explicit inputs are visible.
568717fd 318
e531ac2a 319@cindex store
568717fd 320The result of package build functions is @dfn{cached} in the file
e531ac2a 321system, in a special directory called @dfn{the store} (@pxref{The
f97c9175 322Store}). Each package is installed in a directory of its own in the
834129e0 323store---by default under @file{/gnu/store}. The directory name contains
568717fd
LC
324a hash of all the inputs used to build that package; thus, changing an
325input yields a different directory name.
326
f97c9175
AE
327This approach is the foundation for the salient features of Guix: support
328for transactional package upgrade and rollback, per-user installation, and
eeaf4427 329garbage collection of packages (@pxref{Features}).
568717fd 330
a1ba8475 331
bd5e766b
LC
332@c *********************************************************************
333@node Installation
334@chapter Installation
335
e32171ee 336@cindex installing Guix
48febeb8
LC
337GNU Guix is available for download from its website at
338@url{http://www.gnu.org/software/guix/}. This section describes the
339software requirements of Guix, as well as how to install it and get
340ready to use it.
bd5e766b 341
5af6de3e
LC
342Note that this section is concerned with the installation of the package
343manager, which can be done on top of a running GNU/Linux system. If,
344instead, you want to install the complete GNU operating system,
6621cdb6 345@pxref{System Installation}.
5af6de3e 346
d23ef788
LC
347@cindex foreign distro
348When installed on a running GNU/Linux system---thereafter called a
349@dfn{foreign distro}---GNU@tie{}Guix complements the available tools
350without interference. Its data lives exclusively in two directories,
351usually @file{/gnu/store} and @file{/var/guix}; other files on your
352system, such as @file{/etc}, are left untouched.
353
7fcf2a0b
LC
354Once installed, Guix can be updated by running @command{guix pull}
355(@pxref{Invoking guix pull}).
356
bd5e766b 357@menu
09722b11 358* Binary Installation:: Getting Guix running in no time!
bd5e766b 359* Requirements:: Software needed to build and run Guix.
ec0339cd 360* Running the Test Suite:: Testing Guix.
bd5e766b
LC
361* Setting Up the Daemon:: Preparing the build daemon's environment.
362* Invoking guix-daemon:: Running the build daemon.
0e2d0213 363* Application Setup:: Application-specific setup.
bd5e766b
LC
364@end menu
365
09722b11
LC
366@node Binary Installation
367@section Binary Installation
368
e32171ee 369@cindex installing Guix from binaries
09722b11
LC
370This section describes how to install Guix on an arbitrary system from a
371self-contained tarball providing binaries for Guix and for all its
372dependencies. This is often quicker than installing from source, which
373is described in the next sections. The only requirement is to have
374GNU@tie{}tar and Xz.
375
376Installing goes along these lines:
377
378@enumerate
379@item
e32171ee 380@cindex downloading Guix binary
09722b11 381Download the binary tarball from
daa8922a
LC
382@indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz},
383where @var{system} is @code{x86_64-linux} for an @code{x86_64} machine
384already running the kernel Linux, and so on.
385
debc6360 386@c The following is somewhat duplicated in ``System Installation''.
daa8922a
LC
387Make sure to download the associated @file{.sig} file and to verify the
388authenticity of the tarball against it, along these lines:
389
390@example
391$ wget ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
392$ gpg --verify guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
393@end example
394
f97c9175 395If that command fails because you do not have the required public key,
daa8922a
LC
396then run this command to import it:
397
398@example
debc6360 399$ gpg --keyserver pgp.mit.edu --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
daa8922a
LC
400@end example
401
402@noindent
403and rerun the @code{gpg --verify} command.
debc6360 404@c end authentication part
09722b11
LC
405
406@item
407As @code{root}, run:
408
409@example
5dc42964 410# cd /tmp
254b1c2e
LC
411# tar --warning=no-timestamp -xf \
412 guix-binary-@value{VERSION}.@var{system}.tar.xz
5dc42964 413# mv var/guix /var/ && mv gnu /
09722b11
LC
414@end example
415
7acd3439
LC
416This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
417The latter contains a ready-to-use profile for @code{root} (see next
418step.)
09722b11 419
5dc3ce5f
LC
420Do @emph{not} unpack the tarball on a working Guix system since that
421would overwrite its own essential files.
422
254b1c2e 423The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
e9ba6357
LC
424not emit warnings about ``implausibly old time stamps'' (such
425warnings were triggered by GNU@tie{}tar 1.26 and older; recent
426versions are fine.)
427They stem from the fact that all the
254b1c2e
LC
428files in the archive have their modification time set to zero (which
429means January 1st, 1970.) This is done on purpose to make sure the
430archive content is independent of its creation time, thus making it
431reproducible.
432
7acd3439
LC
433@item
434Make @code{root}'s profile available under @file{~/.guix-profile}:
435
436@example
437# ln -sf /var/guix/profiles/per-user/root/guix-profile \
438 ~root/.guix-profile
439@end example
440
43c33047
LC
441@item
442Create the group and user accounts for build users as explained below
443(@pxref{Build Environment Setup}).
444
09722b11 445@item
bf98aea9 446Run the daemon, and set it to automatically start on boot.
c8e26887 447
bf98aea9
LC
448If your host distro uses the systemd init system, this can be achieved
449with these commands:
c8e26887 450
b812da70
LF
451@c Versions of systemd that supported symlinked service files are not
452@c yet widely deployed, so we should suggest that users copy the service
453@c files into place.
454@c
455@c See this thread for more information:
456@c http://lists.gnu.org/archive/html/guix-devel/2017-01/msg01199.html
457
c8e26887 458@example
b812da70 459# cp ~root/.guix-profile/lib/systemd/system/guix-daemon.service \
c8e26887
GC
460 /etc/systemd/system/
461# systemctl start guix-daemon && systemctl enable guix-daemon
462@end example
463
464If your host distro uses the Upstart init system:
09722b11
LC
465
466@example
4a780bdf 467# initctl reload-configuration
b812da70 468# cp ~root/.guix-profile/lib/upstart/system/guix-daemon.conf /etc/init/
bf98aea9 469# start guix-daemon
09722b11
LC
470@end example
471
c8e26887
GC
472Otherwise, you can still start the daemon manually with:
473
474@example
475# ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
476@end example
d2825c96 477
09722b11
LC
478@item
479Make the @command{guix} command available to other users on the machine,
480for instance with:
481
482@example
483# mkdir -p /usr/local/bin
484# cd /usr/local/bin
d72d05f9 485# ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
09722b11 486@end example
39f8ed14 487
aca738f3
LC
488It is also a good idea to make the Info version of this manual available
489there:
490
491@example
492# mkdir -p /usr/local/share/info
493# cd /usr/local/share/info
494# for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
495 do ln -s $i ; done
496@end example
497
498That way, assuming @file{/usr/local/share/info} is in the search path,
499running @command{info guix} will open this manual (@pxref{Other Info
500Directories,,, texinfo, GNU Texinfo}, for more details on changing the
501Info search path.)
502
39f8ed14 503@item
e32171ee 504@cindex substitutes, authorization thereof
df061d07
LC
505To use substitutes from @code{hydra.gnu.org} or one of its mirrors
506(@pxref{Substitutes}), authorize them:
39f8ed14
LC
507
508@example
7acd3439 509# guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
39f8ed14 510@end example
7f608a9b
LC
511
512@item
513Each user may need to perform a few additional steps to make their Guix
514environment ready for use, @pxref{Application Setup}.
09722b11
LC
515@end enumerate
516
7f608a9b 517Voilà, the installation is complete!
09722b11 518
c8e26887
GC
519You can confirm that Guix is working by installing a sample package into
520the root profile:
09722b11
LC
521
522@example
c8e26887 523# guix package -i hello
09722b11
LC
524@end example
525
c8e26887
GC
526The @code{guix} package must remain available in @code{root}'s profile,
527or it would become subject to garbage collection---in which case you
528would find yourself badly handicapped by the lack of the @command{guix}
bf98aea9
LC
529command. In other words, do not remove @code{guix} by running
530@code{guix package -r guix}.
531
532The binary installation tarball can be (re)produced and verified simply
533by running the following command in the Guix source tree:
534
535@example
536make guix-binary.@var{system}.tar.xz
537@end example
c8e26887 538
239c2266
LC
539@noindent
540... which, in turn, runs:
541
542@example
6b63c43e 543guix pack -s @var{system} --localstatedir guix
239c2266
LC
544@end example
545
546@xref{Invoking guix pack}, for more info on this handy tool.
09722b11 547
bd5e766b
LC
548@node Requirements
549@section Requirements
550
09722b11
LC
551This section lists requirements when building Guix from source. The
552build procedure for Guix is the same as for other GNU software, and is
553not covered here. Please see the files @file{README} and @file{INSTALL}
554in the Guix source tree for additional details.
555
bd5e766b
LC
556GNU Guix depends on the following packages:
557
558@itemize
36626c55 559@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.9 or
608e42e7 560later, including 2.2.x;
288dca55 561@item @url{http://gnupg.org/, GNU libgcrypt};
1dbe3a8d
LC
562@item
563@uref{http://gnutls.org/, GnuTLS}, specifically its Guile bindings
564(@pxref{Guile Preparations, how to install the GnuTLS bindings for
565Guile,, gnutls-guile, GnuTLS-Guile});
f0b98b84 566@item @url{http://www.gnu.org/software/make/, GNU Make}.
8a96bd4b
ID
567@end itemize
568
569The following dependencies are optional:
570
571@itemize
288dca55 572@item
8a96bd4b 573Installing
288dca55 574@url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
2f7d2d91
LC
575allow you to use the @command{guix import pypi} command (@pxref{Invoking
576guix import}). It is of
288dca55 577interest primarily for developers and not for casual users.
4591c02e 578
21531add
LC
579@item
580@c Note: We need at least 0.10.2 for 'channel-send-eof'.
f11c444d
LC
581Support for build offloading (@pxref{Daemon Offload Setup}) and
582@command{guix copy} (@pxref{Invoking guix copy}) depends on
21531add
LC
583@uref{https://github.com/artyom-poptsov/guile-ssh, Guile-SSH},
584version 0.10.2 or later.
585
4591c02e
LC
586@item
587When @url{http://zlib.net, zlib} is available, @command{guix publish}
588can compress build byproducts (@pxref{Invoking guix publish}).
bd5e766b
LC
589@end itemize
590
591Unless @code{--disable-daemon} was passed to @command{configure}, the
592following packages are also needed:
593
594@itemize
368d08f7
LC
595@item @url{http://sqlite.org, SQLite 3};
596@item @url{http://www.bzip.org, libbz2};
597@item @url{http://gcc.gnu.org, GCC's g++}, with support for the
598C++11 standard.
bd5e766b
LC
599@end itemize
600
e32171ee 601@cindex state directory
ef5f5c86
LC
602When configuring Guix on a system that already has a Guix installation,
603be sure to specify the same state directory as the existing installation
604using the @code{--localstatedir} option of the @command{configure}
605script (@pxref{Directory Variables, @code{localstatedir},, standards,
606GNU Coding Standards}). The @command{configure} script protects against
607unintended misconfiguration of @var{localstatedir} so you do not
608inadvertently corrupt your store (@pxref{The Store}).
609
e32171ee 610@cindex Nix, compatibility
4bfc4ea3
NK
611When a working installation of @url{http://nixos.org/nix/, the Nix package
612manager} is available, you
bd5e766b 613can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 614Nix replaces the three dependencies above.
bd5e766b 615
b22a12fd
LC
616Guix is compatible with Nix, so it is possible to share the same store
617between both. To do so, you must pass @command{configure} not only the
618same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
619@code{--localstatedir} value. The latter is essential because it
620specifies where the database that stores metadata about the store is
834129e0 621located, among other things. The default values for Nix are
b22a12fd 622@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
623Note that @code{--disable-daemon} is not required if
624your goal is to share the store with Nix.
b22a12fd 625
ec0339cd
LC
626@node Running the Test Suite
627@section Running the Test Suite
628
e32171ee 629@cindex test suite
ec0339cd
LC
630After a successful @command{configure} and @code{make} run, it is a good
631idea to run the test suite. It can help catch issues with the setup or
632environment, or bugs in Guix itself---and really, reporting test
633failures is a good way to help improve the software. To run the test
634suite, type:
635
636@example
637make check
638@end example
639
640Test cases can run in parallel: you can use the @code{-j} option of
641GNU@tie{}make to speed things up. The first run may take a few minutes
642on a recent machine; subsequent runs will be faster because the store
643that is created for test purposes will already have various things in
644cache.
645
a887fd8d
LC
646It is also possible to run a subset of the tests by defining the
647@code{TESTS} makefile variable as in this example:
648
649@example
650make check TESTS="tests/store.scm tests/cpio.scm"
651@end example
652
a9edb211
ML
653By default, tests results are displayed at a file level. In order to
654see the details of every individual test cases, it is possible to define
655the @code{SCM_LOG_DRIVER_FLAGS} makefile variable as in this example:
656
657@example
658make check TESTS="tests/base64.scm" SCM_LOG_DRIVER_FLAGS="--brief=no"
659@end example
660
ec0339cd 661Upon failure, please email @email{bug-guix@@gnu.org} and attach the
a9edb211
ML
662@file{test-suite.log} file. Please specify the Guix version being used
663as well as version numbers of the dependencies (@pxref{Requirements}) in
664your message.
ec0339cd 665
0a2f2848
LC
666Guix also comes with a whole-system test suite that tests complete
667GuixSD operating system instances. It can only run on systems where
668Guix is already installed, using:
669
670@example
671make check-system
672@end example
673
674@noindent
675or, again, by defining @code{TESTS} to select a subset of tests to run:
676
677@example
678make check-system TESTS="basic mcron"
679@end example
680
681These system tests are defined in the @code{(gnu tests @dots{})}
682modules. They work by running the operating systems under test with
683lightweight instrumentation in a virtual machine (VM). They can be
684computationally intensive or rather cheap, depending on whether
685substitutes are available for their dependencies (@pxref{Substitutes}).
686Some of them require a lot of storage space to hold VM images.
687
688Again in case of test failures, please send @email{bug-guix@@gnu.org}
689all the details.
690
bd5e766b
LC
691@node Setting Up the Daemon
692@section Setting Up the Daemon
693
694@cindex daemon
695Operations such as building a package or running the garbage collector
49e6291a 696are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
697behalf of clients. Only the daemon may access the store and its
698associated database. Thus, any operation that manipulates the store
699goes through the daemon. For instance, command-line tools such as
e49951eb 700@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
701daemon (@i{via} remote procedure calls) to instruct it what to do.
702
49e6291a 703The following sections explain how to prepare the build daemon's
f97c9175 704environment. See also @ref{Substitutes}, for information on how to allow
225dafde 705the daemon to download pre-built binaries.
49e6291a
LC
706
707@menu
708* Build Environment Setup:: Preparing the isolated build environment.
709* Daemon Offload Setup:: Offloading builds to remote machines.
710@end menu
711
712@node Build Environment Setup
713@subsection Build Environment Setup
714
e32171ee 715@cindex build environment
bd5e766b
LC
716In a standard multi-user setup, Guix and its daemon---the
717@command{guix-daemon} program---are installed by the system
834129e0 718administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
719@command{guix-daemon} runs as @code{root}. Unprivileged users may use
720Guix tools to build packages or otherwise access the store, and the
721daemon will do it on their behalf, ensuring that the store is kept in a
722consistent state, and allowing built packages to be shared among users.
723
724@cindex build users
725When @command{guix-daemon} runs as @code{root}, you may not want package
726build processes themselves to run as @code{root} too, for obvious
727security reasons. To avoid that, a special pool of @dfn{build users}
728should be created for use by build processes started by the daemon.
729These build users need not have a shell and a home directory: they will
730just be used when the daemon drops @code{root} privileges in build
731processes. Having several such users allows the daemon to launch
732distinct build processes under separate UIDs, which guarantees that they
733do not interfere with each other---an essential feature since builds are
734regarded as pure functions (@pxref{Introduction}).
735
736On a GNU/Linux system, a build user pool may be created like this (using
737Bash syntax and the @code{shadow} commands):
738
091196b3
LC
739@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
740@c for why `-G' is needed.
bd5e766b 741@example
cfc149dc
LC
742# groupadd --system guixbuild
743# for i in `seq -w 1 10`;
bd5e766b 744 do
cfc149dc
LC
745 useradd -g guixbuild -G guixbuild \
746 -d /var/empty -s `which nologin` \
747 -c "Guix build user $i" --system \
748 guixbuilder$i;
bd5e766b
LC
749 done
750@end example
751
752@noindent
54eb03ab
LC
753The number of build users determines how many build jobs may run in
754parallel, as specified by the @option{--max-jobs} option
eca69fc0
LC
755(@pxref{Invoking guix-daemon, @option{--max-jobs}}). To use
756@command{guix system vm} and related commands, you may need to add the
757build users to the @code{kvm} group so they can access @file{/dev/kvm},
758using @code{-G guixbuild,kvm} instead of @code{-G guixbuild}
759(@pxref{Invoking guix system}).
760
761The @code{guix-daemon} program may then be run as @code{root} with the
d2825c96
LC
762following command@footnote{If your machine uses the systemd init system,
763dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
764file in @file{/etc/systemd/system} will ensure that
ad227484
MDRS
765@command{guix-daemon} is automatically started. Similarly, if your
766machine uses the Upstart init system, drop the
767@file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
768file in @file{/etc/init}.}:
bd5e766b
LC
769
770@example
cfc149dc 771# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
772@end example
773
e900c503 774@cindex chroot
b095792f
LC
775@noindent
776This way, the daemon starts build processes in a chroot, under one of
cfc149dc 777the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
778environment contains nothing but:
779
780@c Keep this list in sync with libstore/build.cc! -----------------------
781@itemize
782@item
4743a4da
LC
783a minimal @code{/dev} directory, created mostly independently from the
784host @code{/dev}@footnote{``Mostly'', because while the set of files
785that appear in the chroot's @code{/dev} is fixed, most of these files
786can only be created if the host has them.};
787
788@item
f97c9175 789the @code{/proc} directory; it only shows the processes of the container
4743a4da 790since a separate PID name space is used;
6dc99317
LC
791
792@item
793@file{/etc/passwd} with an entry for the current user and an entry for
794user @file{nobody};
795
796@item
797@file{/etc/group} with an entry for the user's group;
798
799@item
800@file{/etc/hosts} with an entry that maps @code{localhost} to
801@code{127.0.0.1};
802
803@item
804a writable @file{/tmp} directory.
805@end itemize
b095792f 806
cb960102
ED
807You can influence the directory where the daemon stores build trees
808@i{via} the @code{TMPDIR} environment variable. However, the build tree
f97c9175 809within the chroot is always called @file{/tmp/guix-build-@var{name}.drv-0},
cb960102
ED
810where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
811This way, the value of @code{TMPDIR} does not leak inside build
812environments, which avoids discrepancies in cases where build processes
813capture the name of their build tree.
814
e0c941fe
LC
815@vindex http_proxy
816The daemon also honors the @code{http_proxy} environment variable for
817HTTP downloads it performs, be it for fixed-output derivations
818(@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
819
1e2644bb
LC
820If you are installing Guix as an unprivileged user, it is still possible
821to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
822However, build processes will not be isolated from one another, and not
823from the rest of the system. Thus, build processes may interfere with
824each other, and may access programs, libraries, and other files
825available on the system---making it much harder to view them as
826@emph{pure} functions.
bd5e766b 827
49e6291a
LC
828
829@node Daemon Offload Setup
830@subsection Using the Offload Facility
831
832@cindex offloading
4ec2e92d 833@cindex build hook
21531add
LC
834When desired, the build daemon can @dfn{offload} derivation builds to
835other machines running Guix, using the @code{offload} @dfn{build
836hook}@footnote{This feature is available only when
837@uref{https://github.com/artyom-poptsov/guile-ssh, Guile-SSH} is
838present.}. When that
49e6291a 839feature is enabled, a list of user-specified build machines is read from
f97c9175 840@file{/etc/guix/machines.scm}; every time a build is requested, for
49e6291a 841instance via @code{guix build}, the daemon attempts to offload it to one
f97c9175 842of the machines that satisfy the constraints of the derivation, in
49e6291a
LC
843particular its system type---e.g., @file{x86_64-linux}. Missing
844prerequisites for the build are copied over SSH to the target machine,
845which then proceeds with the build; upon success the output(s) of the
846build are copied back to the initial machine.
847
4ec2e92d 848The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
849
850@example
851(list (build-machine
852 (name "eightysix.example.org")
853 (system "x86_64-linux")
21531add 854 (host-key "ssh-ed25519 AAAAC3Nza@dots{}")
49e6291a 855 (user "bob")
21531add 856 (speed 2.)) ;incredibly fast!
49e6291a
LC
857
858 (build-machine
859 (name "meeps.example.org")
860 (system "mips64el-linux")
21531add 861 (host-key "ssh-rsa AAAAB3Nza@dots{}")
49e6291a
LC
862 (user "alice")
863 (private-key
864 (string-append (getenv "HOME")
21531add 865 "/.ssh/identity-for-guix"))))
49e6291a
LC
866@end example
867
868@noindent
869In the example above we specify a list of two build machines, one for
870the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
871architecture.
872
873In fact, this file is---not surprisingly!---a Scheme file that is
874evaluated when the @code{offload} hook is started. Its return value
875must be a list of @code{build-machine} objects. While this example
876shows a fixed list of build machines, one could imagine, say, using
877DNS-SD to return a list of potential build machines discovered in the
878local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
c678a4ee
LC
879Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
880detailed below.
4ec2e92d 881
c678a4ee 882@deftp {Data Type} build-machine
f97c9175
AE
883This data type represents build machines to which the daemon may offload
884builds. The important fields are:
49e6291a
LC
885
886@table @code
887
888@item name
f97c9175 889The host name of the remote machine.
49e6291a
LC
890
891@item system
f97c9175 892The system type of the remote machine---e.g., @code{"x86_64-linux"}.
49e6291a
LC
893
894@item user
895The user account to use when connecting to the remote machine over SSH.
896Note that the SSH key pair must @emph{not} be passphrase-protected, to
897allow non-interactive logins.
898
21531add
LC
899@item host-key
900This must be the machine's SSH @dfn{public host key} in OpenSSH format.
901This is used to authenticate the machine when we connect to it. It is a
902long string that looks like this:
903
904@example
905ssh-ed25519 AAAAC3NzaC@dots{}mde+UhL hint@@example.org
906@end example
907
908If the machine is running the OpenSSH daemon, @command{sshd}, the host
909key can be found in a file such as
910@file{/etc/ssh/ssh_host_ed25519_key.pub}.
911
912If the machine is running the SSH daemon of GNU@tie{}lsh,
913@command{lshd}, the host key is in @file{/etc/lsh/host-key.pub} or a
914similar file. It can be converted to the OpenSSH format using
915@command{lsh-export-key} (@pxref{Converting keys,,, lsh, LSH Manual}):
916
917@example
918$ lsh-export-key --openssh < /etc/lsh/host-key.pub
919ssh-rsa AAAAB3NzaC1yc2EAAAAEOp8FoQAAAQEAs1eB46LV@dots{}
920@end example
921
49e6291a
LC
922@end table
923
4ec2e92d 924A number of optional fields may be specified:
49e6291a 925
21531add 926@table @asis
49e6291a 927
21531add
LC
928@item @code{port} (default: @code{22})
929Port number of SSH server on the machine.
cecd72d5 930
21531add
LC
931@item @code{private-key} (default: @file{~/.ssh/id_rsa})
932The SSH private key file to use when connecting to the machine, in
933OpenSSH format.
49e6291a 934
1d48cf94
LC
935@item @code{compression} (default: @code{"zlib@@openssh.com,zlib"})
936@itemx @code{compression-level} (default: @code{3})
937The SSH-level compression methods and compression level requested.
938
939Note that offloading relies on SSH compression to reduce bandwidth usage
940when transferring files to and from build machines.
941
cf283dd9
LC
942@item @code{daemon-socket} (default: @code{"/var/guix/daemon-socket/socket"})
943File name of the Unix-domain socket @command{guix-daemon} is listening
944to on that machine.
c4fdfd6f 945
21531add
LC
946@item @code{parallel-builds} (default: @code{1})
947The number of builds that may run in parallel on the machine.
49e6291a 948
21531add 949@item @code{speed} (default: @code{1.0})
49e6291a
LC
950A ``relative speed factor''. The offload scheduler will tend to prefer
951machines with a higher speed factor.
952
21531add 953@item @code{features} (default: @code{'()})
49e6291a
LC
954A list of strings denoting specific features supported by the machine.
955An example is @code{"kvm"} for machines that have the KVM Linux modules
956and corresponding hardware support. Derivations can request features by
957name, and they will be scheduled on matching build machines.
958
959@end table
c678a4ee 960@end deftp
49e6291a 961
aebaee95
LC
962The @code{guile} command must be in the search path on the build
963machines. In addition, the Guix modules must be in
c4fdfd6f
LC
964@code{$GUILE_LOAD_PATH} on the build machine---you can check whether
965this is the case by running:
966
967@example
21531add 968ssh build-machine guile -c "'(use-modules (guix config))'"
c4fdfd6f 969@end example
49e6291a 970
f97c9175 971There is one last thing to do once @file{machines.scm} is in place. As
49e6291a 972explained above, when offloading, files are transferred back and forth
c4fdfd6f
LC
973between the machine stores. For this to work, you first need to
974generate a key pair on each machine to allow the daemon to export signed
975archives of files from the store (@pxref{Invoking guix archive}):
49e6291a
LC
976
977@example
978# guix archive --generate-key
979@end example
980
981@noindent
c4fdfd6f
LC
982Each build machine must authorize the key of the master machine so that
983it accepts store items it receives from the master:
984
985@example
986# guix archive --authorize < master-public-key.txt
987@end example
988
989@noindent
990Likewise, the master machine must authorize the key of each build machine.
991
992All the fuss with keys is here to express pairwise mutual trust
993relations between the master and the build machines. Concretely, when
994the master receives files from a build machine (and @i{vice versa}), its
995build daemon can make sure they are genuine, have not been tampered
996with, and that they are signed by an authorized key.
49e6291a 997
aebaee95
LC
998@cindex offload test
999To test whether your setup is operational, run this command on the
1000master node:
1001
1002@example
1003# guix offload test
1004@end example
1005
1006This will attempt to connect to each of the build machines specified in
1007@file{/etc/guix/machines.scm}, make sure Guile and the Guix modules are
1008available on each machine, attempt to export to the machine and import
1009from it, and report any error in the process.
1010
1011If you want to test a different machine file, just specify it on the
1012command line:
1013
1014@example
1015# guix offload test machines-qualif.scm
1016@end example
1017
27991c97
LC
1018Last, you can test the subset of the machines whose name matches a
1019regular expression like this:
1020
1021@example
1022# guix offload test machines.scm '\.gnu\.org$'
1023@end example
49e6291a 1024
bd5e766b
LC
1025@node Invoking guix-daemon
1026@section Invoking @command{guix-daemon}
1027
1028The @command{guix-daemon} program implements all the functionality to
1029access the store. This includes launching build processes, running the
1030garbage collector, querying the availability of a build result, etc. It
1031is normally run as @code{root} like this:
1032
1033@example
cfc149dc 1034# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
1035@end example
1036
1037@noindent
081145cf 1038For details on how to set it up, @pxref{Setting Up the Daemon}.
bd5e766b 1039
e900c503
LC
1040@cindex chroot
1041@cindex container, build environment
1042@cindex build environment
1043@cindex reproducible builds
bd5e766b
LC
1044By default, @command{guix-daemon} launches build processes under
1045different UIDs, taken from the build group specified with
1046@code{--build-users-group}. In addition, each build process is run in a
1047chroot environment that only contains the subset of the store that the
1048build process depends on, as specified by its derivation
1049(@pxref{Programming Interface, derivation}), plus a set of specific
1050system directories. By default, the latter contains @file{/dev} and
e900c503
LC
1051@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
1052@dfn{container}: in addition to having its own file system tree, it has
1053a separate mount name space, its own PID name space, network name space,
1054etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b 1055
cbc538fe
LC
1056When the daemon performs a build on behalf of the user, it creates a
1057build directory under @file{/tmp} or under the directory specified by
1058its @code{TMPDIR} environment variable; this directory is shared with
1059the container for the duration of the build. Be aware that using a
1060directory other than @file{/tmp} can affect build results---for example,
1061with a longer directory name, a build process that uses Unix-domain
1062sockets might hit the name length limitation for @code{sun_path}, which
1063it would otherwise not hit.
1064
1065The build directory is automatically deleted upon completion, unless the
1066build failed and the client specified @option{--keep-failed}
1067(@pxref{Invoking guix build, @option{--keep-failed}}).
1068
bd5e766b
LC
1069The following command-line options are supported:
1070
1071@table @code
1072@item --build-users-group=@var{group}
1073Take users from @var{group} to run build processes (@pxref{Setting Up
1074the Daemon, build users}).
1075
6858f9d1 1076@item --no-substitutes
b5385b52 1077@cindex substitutes
6858f9d1 1078Do not use substitutes for build products. That is, always build things
c4202d60
LC
1079locally instead of allowing downloads of pre-built binaries
1080(@pxref{Substitutes}).
6858f9d1 1081
b5385b52
LC
1082By default substitutes are used, unless the client---such as the
1083@command{guix package} command---is explicitly invoked with
1084@code{--no-substitutes}.
1085
1086When the daemon runs with @code{--no-substitutes}, clients can still
1087explicitly enable substitution @i{via} the @code{set-build-options}
1088remote procedure call (@pxref{The Store}).
1089
9176607e 1090@item --substitute-urls=@var{urls}
f8a8e0fe 1091@anchor{daemon-substitute-urls}
9176607e 1092Consider @var{urls} the default whitespace-separated list of substitute
df061d07
LC
1093source URLs. When this option is omitted,
1094@indicateurl{https://mirror.hydra.gnu.org https://hydra.gnu.org} is used
1095(@code{mirror.hydra.gnu.org} is a mirror of @code{hydra.gnu.org}).
9176607e
LC
1096
1097This means that substitutes may be downloaded from @var{urls}, as long
1098as they are signed by a trusted signature (@pxref{Substitutes}).
1099
4ec2e92d
LC
1100@cindex build hook
1101@item --no-build-hook
1102Do not use the @dfn{build hook}.
1103
1104The build hook is a helper program that the daemon can start and to
1105which it submits build requests. This mechanism is used to offload
1106builds to other machines (@pxref{Daemon Offload Setup}).
1107
bd5e766b
LC
1108@item --cache-failures
1109Cache build failures. By default, only successful builds are cached.
1110
30d9aa54
LC
1111When this option is used, @command{guix gc --list-failures} can be used
1112to query the set of store items marked as failed; @command{guix gc
1113--clear-failures} removes store items from the set of cached failures.
1114@xref{Invoking guix gc}.
1115
bd5e766b
LC
1116@item --cores=@var{n}
1117@itemx -c @var{n}
1118Use @var{n} CPU cores to build each derivation; @code{0} means as many
1119as available.
1120
6efc160e 1121The default value is @code{0}, but it may be overridden by clients, such
e49951eb
MW
1122as the @code{--cores} option of @command{guix build} (@pxref{Invoking
1123guix build}).
bd5e766b
LC
1124
1125The effect is to define the @code{NIX_BUILD_CORES} environment variable
1126in the build process, which can then use it to exploit internal
1127parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
1128
1129@item --max-jobs=@var{n}
1130@itemx -M @var{n}
1131Allow at most @var{n} build jobs in parallel. The default value is
f6526eb3
LC
1132@code{1}. Setting it to @code{0} means that no builds will be performed
1133locally; instead, the daemon will offload builds (@pxref{Daemon Offload
1134Setup}), or simply fail.
bd5e766b 1135
ecf84b7c
LC
1136@item --rounds=@var{N}
1137Build each derivation @var{n} times in a row, and raise an error if
1138consecutive build results are not bit-for-bit identical. Note that this
1139setting can be overridden by clients such as @command{guix build}
1140(@pxref{Invoking guix build}).
1141
b4528110
ED
1142When used in conjunction with @option{--keep-failed}, the differing
1143output is kept in the store, under @file{/gnu/store/@dots{}-check}.
1144This makes it easy to look for differences between the two results.
1145
bd5e766b
LC
1146@item --debug
1147Produce debugging output.
1148
1149This is useful to debug daemon start-up issues, but then it may be
1150overridden by clients, for example the @code{--verbosity} option of
e49951eb 1151@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
1152
1153@item --chroot-directory=@var{dir}
1154Add @var{dir} to the build chroot.
1155
1156Doing this may change the result of build processes---for instance if
1157they use optional dependencies found in @var{dir} when it is available,
1158and not otherwise. For that reason, it is not recommended to do so.
1159Instead, make sure that each derivation declares all the inputs that it
1160needs.
1161
1162@item --disable-chroot
1163Disable chroot builds.
1164
1165Using this option is not recommended since, again, it would allow build
1e2644bb
LC
1166processes to gain access to undeclared dependencies. It is necessary,
1167though, when @command{guix-daemon} is running under an unprivileged user
1168account.
bd5e766b
LC
1169
1170@item --disable-log-compression
1171Disable compression of the build logs.
1172
1da983b9
LC
1173Unless @code{--lose-logs} is used, all the build logs are kept in the
1174@var{localstatedir}. To save space, the daemon automatically compresses
1175them with bzip2 by default. This option disables that.
1176
ab3893d7
LC
1177@item --disable-deduplication
1178@cindex deduplication
bd5e766b
LC
1179Disable automatic file ``deduplication'' in the store.
1180
1da983b9 1181By default, files added to the store are automatically ``deduplicated'':
ab3893d7
LC
1182if a newly added file is identical to another one found in the store,
1183the daemon makes the new file a hard link to the other file. This can
4988dd40 1184noticeably reduce disk usage, at the expense of slightly increased
ab3893d7
LC
1185input/output load at the end of a build process. This option disables
1186this optimization.
1da983b9 1187
6e37066e
LC
1188@item --gc-keep-outputs[=yes|no]
1189Tell whether the garbage collector (GC) must keep outputs of live
1190derivations.
1191
1192When set to ``yes'', the GC will keep the outputs of any live derivation
1193available in the store---the @code{.drv} files. The default is ``no'',
1194meaning that derivation outputs are kept only if they are GC roots.
1195
1196@item --gc-keep-derivations[=yes|no]
1197Tell whether the garbage collector (GC) must keep derivations
1198corresponding to live outputs.
1199
1200When set to ``yes'', as is the case by default, the GC keeps
1201derivations---i.e., @code{.drv} files---as long as at least one of their
1202outputs is live. This allows users to keep track of the origins of
1203items in their store. Setting it to ``no'' saves a bit of disk space.
1204
1205Note that when both @code{--gc-keep-derivations} and
1206@code{--gc-keep-outputs} are used, the effect is to keep all the build
1207prerequisites (the sources, compiler, libraries, and other build-time
1208tools) of live objects in the store, regardless of whether these
1209prerequisites are live. This is convenient for developers since it
1210saves rebuilds or downloads.
1211
bd5e766b
LC
1212@item --impersonate-linux-2.6
1213On Linux-based systems, impersonate Linux 2.6. This means that the
1214kernel's @code{uname} system call will report 2.6 as the release number.
1215
1216This might be helpful to build programs that (usually wrongfully) depend
1217on the kernel version number.
1218
1219@item --lose-logs
1220Do not keep build logs. By default they are kept under
ce33631f 1221@code{@var{localstatedir}/guix/log}.
bd5e766b
LC
1222
1223@item --system=@var{system}
1224Assume @var{system} as the current system type. By default it is the
1225architecture/kernel pair found at configure time, such as
1226@code{x86_64-linux}.
b8d2aa26
LC
1227
1228@item --listen=@var{socket}
1229Listen for connections on @var{socket}, the file name of a Unix-domain
1230socket. The default socket is
1231@file{@var{localstatedir}/daemon-socket/socket}. This option is only
1232useful in exceptional circumstances, such as if you need to run several
1233daemons on the same machine.
bd5e766b
LC
1234@end table
1235
1236
0e2d0213
LC
1237@node Application Setup
1238@section Application Setup
1239
d23ef788 1240@cindex foreign distro
85e57214
LC
1241When using Guix on top of GNU/Linux distribution other than GuixSD---a
1242so-called @dfn{foreign distro}---a few additional steps are needed to
1243get everything in place. Here are some of them.
0e2d0213
LC
1244
1245@subsection Locales
1246
5c3c1427 1247@anchor{locales-and-locpath}
0e2d0213 1248@cindex locales, when not on GuixSD
5c3c1427 1249@vindex LOCPATH
85e57214 1250@vindex GUIX_LOCPATH
f97c9175
AE
1251Packages installed @i{via} Guix will not use the locale data of the
1252host system. Instead, you must first install one of the locale packages
85e57214
LC
1253available with Guix and then define the @code{GUIX_LOCPATH} environment
1254variable:
0e2d0213
LC
1255
1256@example
1257$ guix package -i glibc-locales
85e57214 1258$ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
0e2d0213
LC
1259@end example
1260
1261Note that the @code{glibc-locales} package contains data for all the
1262locales supported by the GNU@tie{}libc and weighs in at around
f97c9175 1263110@tie{}MiB. Alternatively, the @code{glibc-utf8-locales} is smaller but
0e2d0213
LC
1264limited to a few UTF-8 locales.
1265
85e57214
LC
1266The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1267(@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1268Manual}). There are two important differences though:
1269
1270@enumerate
1271@item
f97c9175 1272@code{GUIX_LOCPATH} is honored only by the libc in Guix, and not by the libc
85e57214 1273provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
f97c9175 1274to make sure the programs of the foreign distro will not end up loading
85e57214
LC
1275incompatible locale data.
1276
1277@item
1278libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1279@code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1280should your Guix profile contain a mixture of programs linked against
1281different libc version, each libc version will only try to load locale
1282data in the right format.
1283@end enumerate
1284
1285This is important because the locale data format used by different libc
1286versions may be incompatible.
1287
9a5187b6
LC
1288@subsection Name Service Switch
1289
1290@cindex name service switch, glibc
1291@cindex NSS (name service switch), glibc
1292@cindex nscd (name service caching daemon)
1293@cindex name service caching daemon (nscd)
1294When using Guix on a foreign distro, we @emph{strongly recommend} that
1295the system run the GNU C library's @dfn{name service cache daemon},
1296@command{nscd}, which should be listening on the
1297@file{/var/run/nscd/socket} socket. Failing to do that, applications
1298installed with Guix may fail to look up host names or user accounts, or
1299may even crash. The next paragraphs explain why.
1300
1301@cindex @file{nsswitch.conf}
1302The GNU C library implements a @dfn{name service switch} (NSS), which is
1303an extensible mechanism for ``name lookups'' in general: host name
1304resolution, user accounts, and more (@pxref{Name Service Switch,,, libc,
1305The GNU C Library Reference Manual}).
1306
1307@cindex Network information service (NIS)
1308@cindex NIS (Network information service)
1309Being extensible, the NSS supports @dfn{plugins}, which provide new name
1310lookup implementations: for example, the @code{nss-mdns} plugin allow
1311resolution of @code{.local} host names, the @code{nis} plugin allows
1312user account lookup using the Network information service (NIS), and so
1313on. These extra ``lookup services'' are configured system-wide in
1314@file{/etc/nsswitch.conf}, and all the programs running on the system
1315honor those settings (@pxref{NSS Configuration File,,, libc, The GNU C
1316Reference Manual}).
1317
1318When they perform a name lookup---for instance by calling the
1319@code{getaddrinfo} function in C---applications first try to connect to
1320the nscd; on success, nscd performs name lookups on their behalf. If
1321the nscd is not running, then they perform the name lookup by
1322themselves, by loading the name lookup services into their own address
1323space and running it. These name lookup services---the
1324@file{libnss_*.so} files---are @code{dlopen}'d, but they may come from
1325the host system's C library, rather than from the C library the
1326application is linked against (the C library coming from Guix).
1327
1328And this is where the problem is: if your application is linked against
1329Guix's C library (say, glibc 2.24) and tries to load NSS plugins from
1330another C library (say, @code{libnss_mdns.so} for glibc 2.22), it will
1331likely crash or have its name lookups fail unexpectedly.
1332
1333Running @command{nscd} on the system, among other advantages, eliminates
1334this binary incompatibility problem because those @code{libnss_*.so}
1335files are loaded in the @command{nscd} process, not in applications
1336themselves.
1337
0e2d0213
LC
1338@subsection X11 Fonts
1339
e32171ee 1340@cindex fonts
4988dd40 1341The majority of graphical applications use Fontconfig to locate and
f97c9175
AE
1342load fonts and perform X11-client-side rendering. The @code{fontconfig}
1343package in Guix looks for fonts in @file{$HOME/.guix-profile}
0e2d0213 1344by default. Thus, to allow graphical applications installed with Guix
f97c9175 1345to display fonts, you have to install fonts with Guix as well.
0e2d0213 1346Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
8fe5b1d1 1347@code{font-gnu-freefont-ttf}.
0e2d0213 1348
5c36edc8
LC
1349To display text written in Chinese languages, Japanese, or Korean in
1350graphical applications, consider installing
1351@code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1352has multiple outputs, one per language family (@pxref{Packages with
1353Multiple Outputs}). For instance, the following command installs fonts
1354for Chinese languages:
1355
1356@example
1357guix package -i font-adobe-source-han-sans:cn
1358@end example
1359
e32171ee 1360@cindex @code{xterm}
1a3e6b15
AK
1361Older programs such as @command{xterm} do not use Fontconfig and instead
1362rely on server-side font rendering. Such programs require to specify a
1363full name of a font using XLFD (X Logical Font Description), like this:
1364
1365@example
1366-*-dejavu sans-medium-r-normal-*-*-100-*-*-*-*-*-1
1367@end example
1368
1369To be able to use such full names for the TrueType fonts installed in
1370your Guix profile, you need to extend the font path of the X server:
1371
1372@example
1373xset +fp ~/.guix-profile/share/fonts/truetype
1374@end example
1375
e32171ee 1376@cindex @code{xlsfonts}
1a3e6b15
AK
1377After that, you can run @code{xlsfonts} (from @code{xlsfonts} package)
1378to make sure your TrueType fonts are listed there.
1379
b3129f2b
LC
1380@subsection X.509 Certificates
1381
e32171ee 1382@cindex @code{nss-certs}
b3129f2b
LC
1383The @code{nss-certs} package provides X.509 certificates, which allow
1384programs to authenticate Web servers accessed over HTTPS.
1385
1386When using Guix on a foreign distro, you can install this package and
1387define the relevant environment variables so that packages know where to
80d944b7 1388look for certificates. @xref{X.509 Certificates}, for detailed
b3129f2b
LC
1389information.
1390
6d97319c
AK
1391@subsection Emacs Packages
1392
e32171ee 1393@cindex @code{emacs}
6d97319c
AK
1394When you install Emacs packages with Guix, the elisp files may be placed
1395either in @file{$HOME/.guix-profile/share/emacs/site-lisp/} or in
1396sub-directories of
1397@file{$HOME/.guix-profile/share/emacs/site-lisp/guix.d/}. The latter
1398directory exists because potentially there may exist thousands of Emacs
1399packages and storing all their files in a single directory may be not
1400reliable (because of name conflicts). So we think using a separate
1401directory for each package is a good idea. It is very similar to how
1402the Emacs package system organizes the file structure (@pxref{Package
1403Files,,, emacs, The GNU Emacs Manual}).
1404
1405By default, Emacs (installed with Guix) ``knows'' where these packages
f97c9175 1406are placed, so you do not need to perform any configuration. If, for
6d97319c 1407some reason, you want to avoid auto-loading Emacs packages installed
f97c9175 1408with Guix, you can do so by running Emacs with @code{--no-site-file}
6d97319c
AK
1409option (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
1410
0e2d0213
LC
1411@c TODO What else?
1412
eeaf4427
LC
1413@c *********************************************************************
1414@node Package Management
1415@chapter Package Management
1416
e32171ee 1417@cindex packages
f8348b91 1418The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427 1419remove software packages, without having to know about their build
f97c9175 1420procedures or dependencies. Guix also goes beyond this obvious set of
eeaf4427
LC
1421features.
1422
1423This chapter describes the main features of Guix, as well as the package
deb6276d
AK
1424management tools it provides. Along with the command-line interface
1425described below (@pxref{Invoking guix package, @code{guix package}}),
1426you may also use Emacs Interface, after installing @code{emacs-guix}
1427package (run @kbd{M-x guix-help} command to start with it):
1428
1429@example
1430guix package -i emacs-guix
1431@end example
eeaf4427
LC
1432
1433@menu
1434* Features:: How Guix will make your life brighter.
e49951eb 1435* Invoking guix package:: Package installation, removal, etc.
c4202d60 1436* Substitutes:: Downloading pre-built binaries.
760c60d6 1437* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 1438* Invoking guix gc:: Running the garbage collector.
f651b477 1439* Invoking guix pull:: Fetching the latest Guix and distribution.
239c2266 1440* Invoking guix pack:: Creating software bundles.
760c60d6 1441* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
1442@end menu
1443
1444@node Features
1445@section Features
1446
1447When using Guix, each package ends up in the @dfn{package store}, in its
1448own directory---something that resembles
deb6276d 1449@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string.
eeaf4427
LC
1450
1451Instead of referring to these directories, users have their own
1452@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
1453use. These profiles are stored within each user's home directory, at
1454@code{$HOME/.guix-profile}.
eeaf4427 1455
821b0015 1456For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 1457@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 1458@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
1459@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1460simply continues to point to
834129e0 1461@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 1462coexist on the same system without any interference.
eeaf4427 1463
e49951eb 1464The @command{guix package} command is the central tool to manage
f97c9175 1465packages (@pxref{Invoking guix package}). It operates on the per-user
821b0015 1466profiles, and can be used @emph{with normal user privileges}.
eeaf4427 1467
e32171ee 1468@cindex transactions
eeaf4427
LC
1469The command provides the obvious install, remove, and upgrade
1470operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 1471the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 1472@command{guix package} process is terminated during the transaction,
eeaf4427
LC
1473or if a power outage occurs during the transaction, then the user's
1474profile remains in its previous state, and remains usable.
1475
1476In addition, any package transaction may be @emph{rolled back}. So, if,
1477for example, an upgrade installs a new version of a package that turns
1478out to have a serious bug, users may roll back to the previous instance
4af2447e 1479of their profile, which was known to work well. Similarly, the global
6f773606
LC
1480system configuration on GuixSD is subject to
1481transactional upgrades and roll-back
4af2447e 1482(@pxref{Using the Configuration System}).
eeaf4427 1483
f97c9175
AE
1484All packages in the package store may be @emph{garbage-collected}.
1485Guix can determine which packages are still referenced by user
fe8ff028 1486profiles, and remove those that are provably no longer referenced
e49951eb 1487(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
1488generations of their profile so that the packages they refer to can be
1489collected.
eeaf4427 1490
e900c503
LC
1491@cindex reproducibility
1492@cindex reproducible builds
eeaf4427
LC
1493Finally, Guix takes a @dfn{purely functional} approach to package
1494management, as described in the introduction (@pxref{Introduction}).
834129e0 1495Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
1496inputs that were used to build that package---compiler, libraries, build
1497scripts, etc. This direct correspondence allows users to make sure a
1498given package installation matches the current state of their
e900c503
LC
1499distribution. It also helps maximize @dfn{build reproducibility}:
1500thanks to the isolated build environments that are used, a given build
1501is likely to yield bit-identical files when performed on different
1502machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 1503
c4202d60 1504@cindex substitutes
eeaf4427 1505This foundation allows Guix to support @dfn{transparent binary/source
c4202d60 1506deployment}. When a pre-built binary for a @file{/gnu/store} item is
18f2887b 1507available from an external source---a @dfn{substitute}, Guix just
c4202d60
LC
1508downloads it and unpacks it;
1509otherwise, it builds the package from source, locally
bf9eacd2
LC
1510(@pxref{Substitutes}). Because build results are usually bit-for-bit
1511reproducible, users do not have to trust servers that provide
1512substitutes: they can force a local build and @emph{challenge} providers
1513(@pxref{Invoking guix challenge}).
eeaf4427 1514
f5fd4fd2
LC
1515Control over the build environment is a feature that is also useful for
1516developers. The @command{guix environment} command allows developers of
1517a package to quickly set up the right development environment for their
f97c9175
AE
1518package, without having to manually install the dependencies of the
1519package into their profile (@pxref{Invoking guix environment}).
f5fd4fd2 1520
e49951eb
MW
1521@node Invoking guix package
1522@section Invoking @command{guix package}
eeaf4427 1523
e32171ee
JD
1524@cindex installing packages
1525@cindex removing packages
1526@cindex package installation
1527@cindex package removal
e49951eb 1528The @command{guix package} command is the tool that allows users to
eeaf4427
LC
1529install, upgrade, and remove packages, as well as rolling back to
1530previous configurations. It operates only on the user's own profile,
1531and works with normal user privileges (@pxref{Features}). Its syntax
1532is:
1533
1534@example
e49951eb 1535guix package @var{options}
eeaf4427 1536@end example
e32171ee 1537@cindex transactions
ba55b1cb 1538Primarily, @var{options} specifies the operations to be performed during
eeaf4427 1539the transaction. Upon completion, a new profile is created, but
99bd74d5 1540previous @dfn{generations} of the profile remain available, should the user
eeaf4427
LC
1541want to roll back.
1542
6447738c
MW
1543For example, to remove @code{lua} and install @code{guile} and
1544@code{guile-cairo} in a single transaction:
1545
1546@example
1547guix package -r lua -i guile guile-cairo
1548@end example
1549
99bd74d5
LC
1550@command{guix package} also supports a @dfn{declarative approach}
1551whereby the user specifies the exact set of packages to be available and
1552passes it @i{via} the @option{--manifest} option
1553(@pxref{profile-manifest, @option{--manifest}}).
1554
e32171ee 1555@cindex profile
b9e5c0a9 1556For each user, a symlink to the user's default profile is automatically
0ec1af59 1557created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
1558current generation of the user's default profile. Thus, users can add
1559@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1560variable, and so on.
d664f1b4
LC
1561@cindex search paths
1562If you are not using the Guix System Distribution, consider adding the
1563following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1564Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1565shells get all the right environment variable definitions:
1566
1567@example
1568GUIX_PROFILE="$HOME/.guix-profile" \
1569source "$HOME/.guix-profile/etc/profile"
1570@end example
b9e5c0a9 1571
4379c35b
LC
1572In a multi-user setup, user profiles are stored in a place registered as
1573a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1574to (@pxref{Invoking guix gc}). That directory is normally
0ec1af59
LC
1575@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1576@var{localstatedir} is the value passed to @code{configure} as
4379c35b
LC
1577@code{--localstatedir}, and @var{user} is the user name. The
1578@file{per-user} directory is created when @command{guix-daemon} is
1579started, and the @var{user} sub-directory is created by @command{guix
1580package}.
0ec1af59
LC
1581
1582The @var{options} can be among the following:
1583
eeaf4427
LC
1584@table @code
1585
6447738c
MW
1586@item --install=@var{package} @dots{}
1587@itemx -i @var{package} @dots{}
1588Install the specified @var{package}s.
eeaf4427 1589
6447738c 1590Each @var{package} may specify either a simple package name, such as
1b846da8
ML
1591@code{guile}, or a package name followed by an at-sign and version number,
1592such as @code{guile@@1.8.8} or simply @code{guile@@1.8} (in the latter
724311a2
LC
1593case, the newest version prefixed by @code{1.8} is selected.)
1594
1595If no version number is specified, the
dc5669cd
MW
1596newest available version will be selected. In addition, @var{package}
1597may contain a colon, followed by the name of one of the outputs of the
1b846da8 1598package, as in @code{gcc:doc} or @code{binutils@@2.22:lib}
e7f34eb0
LC
1599(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1600name (and optionally version) are searched for among the GNU
1601distribution modules (@pxref{Package Modules}).
eeaf4427 1602
461572cc
LC
1603@cindex propagated inputs
1604Sometimes packages have @dfn{propagated inputs}: these are dependencies
21461f27
LC
1605that automatically get installed along with the required package
1606(@pxref{package-propagated-inputs, @code{propagated-inputs} in
1607@code{package} objects}, for information about propagated inputs in
1608package definitions).
461572cc 1609
21461f27 1610@anchor{package-cmd-propagated-inputs}
461572cc
LC
1611An example is the GNU MPC library: its C header files refer to those of
1612the GNU MPFR library, which in turn refer to those of the GMP library.
1613Thus, when installing MPC, the MPFR and GMP libraries also get installed
1614in the profile; removing MPC also removes MPFR and GMP---unless they had
f97c9175 1615also been explicitly installed by the user.
461572cc 1616
ba7ea5ce 1617Besides, packages sometimes rely on the definition of environment
5924080d 1618variables for their search paths (see explanation of
ba7ea5ce 1619@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
1620environment variable definitions are reported here.
1621
5d4b411f
LC
1622@item --install-from-expression=@var{exp}
1623@itemx -e @var{exp}
1624Install the package @var{exp} evaluates to.
1625
1626@var{exp} must be a Scheme expression that evaluates to a
1627@code{<package>} object. This option is notably useful to disambiguate
1628between same-named variants of a package, with expressions such as
1629@code{(@@ (gnu packages base) guile-final)}.
1630
1631Note that this option installs the first output of the specified
1632package, which may be insufficient when needing a specific output of a
1633multiple-output package.
1634
0d279400
DT
1635@item --install-from-file=@var{file}
1636@itemx -f @var{file}
1637Install the package that the code within @var{file} evaluates to.
1638
1639As an example, @var{file} might contain a definition like this
1640(@pxref{Defining Packages}):
1641
1642@example
1643@verbatiminclude package-hello.scm
1644@end example
1645
baacf042 1646Developers may find it useful to include such a @file{guix.scm} file
f97c9175 1647in the root of their project source tree that can be used to test
0d279400
DT
1648development snapshots and create reproducible development environments
1649(@pxref{Invoking guix environment}).
1650
6447738c
MW
1651@item --remove=@var{package} @dots{}
1652@itemx -r @var{package} @dots{}
1653Remove the specified @var{package}s.
eeaf4427 1654
6447738c 1655As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
1656and/or output name in addition to the package name. For instance,
1657@code{-r glibc:debug} would remove the @code{debug} output of
1658@code{glibc}.
1659
6447738c
MW
1660@item --upgrade[=@var{regexp} @dots{}]
1661@itemx -u [@var{regexp} @dots{}]
e32171ee 1662@cindex upgrading packages
6447738c
MW
1663Upgrade all the installed packages. If one or more @var{regexp}s are
1664specified, upgrade only installed packages whose name matches a
d5f01e48 1665@var{regexp}. Also see the @code{--do-not-upgrade} option below.
eeaf4427 1666
f651b477
LC
1667Note that this upgrades package to the latest version of packages found
1668in the distribution currently installed. To update your distribution,
1669you should regularly run @command{guix pull} (@pxref{Invoking guix
1670pull}).
1671
d5f01e48
MW
1672@item --do-not-upgrade[=@var{regexp} @dots{}]
1673When used together with the @code{--upgrade} option, do @emph{not}
1674upgrade any packages whose name matches a @var{regexp}. For example, to
1675upgrade all packages in the current profile except those containing the
1676substring ``emacs'':
1677
1678@example
1679$ guix package --upgrade . --do-not-upgrade emacs
1680@end example
1681
99bd74d5 1682@item @anchor{profile-manifest}--manifest=@var{file}
1b676447 1683@itemx -m @var{file}
99bd74d5
LC
1684@cindex profile declaration
1685@cindex profile manifest
1686Create a new generation of the profile from the manifest object
1b676447
DT
1687returned by the Scheme code in @var{file}.
1688
99bd74d5
LC
1689This allows you to @emph{declare} the profile's contents rather than
1690constructing it through a sequence of @code{--install} and similar
1691commands. The advantage is that @var{file} can be put under version
1692control, copied to different machines to reproduce the same profile, and
1693so on.
1694
1695@c FIXME: Add reference to (guix profile) documentation when available.
1696@var{file} must return a @dfn{manifest} object, which is roughly a list
1697of packages:
1b676447 1698
99bd74d5 1699@findex packages->manifest
1b676447 1700@example
99bd74d5 1701(use-package-modules guile emacs)
1b676447
DT
1702
1703(packages->manifest
99bd74d5
LC
1704 (list emacs
1705 guile-2.0
1b676447 1706 ;; Use a specific package output.
99bd74d5 1707 (list guile-2.0 "debug")))
1b676447
DT
1708@end example
1709
6cd10593
LC
1710@findex specification->package+output
1711In this example we have to know which modules define the @code{emacs}
1712and @code{guile-2.0} variables to provide the right
1713@code{use-package-modules} line, which can be cumbersome. We can
1714instead provide regular package specifications and let
1715@code{specification->package-output} look up the corresponding package
1716objects, like this:
1717
1718@example
1719(packages->manifest
1720 (map (compose list specification->package+output)
1721 '("emacs" "guile@@2.0" "guile@@2.0:debug")))
1722@end example
1723
24e262f0 1724@item --roll-back
e32171ee
JD
1725@cindex rolling back
1726@cindex undoing transactions
1727@cindex transactions, undoing
24e262f0
LC
1728Roll back to the previous @dfn{generation} of the profile---i.e., undo
1729the last transaction.
1730
1731When combined with options such as @code{--install}, roll back occurs
1732before any other actions.
1733
d9307267 1734When rolling back from the first generation that actually contains
4b2bc804 1735installed packages, the profile is made to point to the @dfn{zeroth
f97c9175 1736generation}, which contains no files apart from its own metadata.
d9307267 1737
f97c9175
AE
1738After having rolled back, installing, removing, or upgrading packages
1739overwrites previous future generations. Thus, the history of the
1740generations in a profile is always linear.
82fe08ed 1741
b3bb82f1
AK
1742@item --switch-generation=@var{pattern}
1743@itemx -S @var{pattern}
e32171ee 1744@cindex generations
b3bb82f1
AK
1745Switch to a particular generation defined by @var{pattern}.
1746
1747@var{pattern} may be either a generation number or a number prefixed
1748with ``+'' or ``-''. The latter means: move forward/backward by a
1749specified number of generations. For example, if you want to return to
1750the latest generation after @code{--roll-back}, use
1751@code{--switch-generation=+1}.
1752
1753The difference between @code{--roll-back} and
1754@code{--switch-generation=-1} is that @code{--switch-generation} will
1755not make a zeroth generation, so if a specified generation does not
1756exist, the current generation will not be changed.
1757
dbc31ab2 1758@item --search-paths[=@var{kind}]
5924080d
LC
1759@cindex search paths
1760Report environment variable definitions, in Bash syntax, that may be
1761needed in order to use the set of installed packages. These environment
1762variables are used to specify @dfn{search paths} for files used by some
1763of the installed packages.
1764
1765For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1766environment variables to be defined so it can look for headers and
1767libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1768Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1769library are installed in the profile, then @code{--search-paths} will
1770suggest setting these variables to @code{@var{profile}/include} and
1771@code{@var{profile}/lib}, respectively.
1772
dbc31ab2
LC
1773The typical use case is to define these environment variables in the
1774shell:
1775
1776@example
1777$ eval `guix package --search-paths`
1778@end example
1779
1780@var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1781meaning that the returned environment variable definitions will either
1782be exact settings, or prefixes or suffixes of the current value of these
1783variables. When omitted, @var{kind} defaults to @code{exact}.
1784
fc2d2339
LC
1785This option can also be used to compute the @emph{combined} search paths
1786of several profiles. Consider this example:
1787
1788@example
1789$ guix package -p foo -i guile
1790$ guix package -p bar -i guile-json
1791$ guix package -p foo -p bar --search-paths
1792@end example
1793
1794The last command above reports about the @code{GUILE_LOAD_PATH}
1795variable, even though, taken individually, neither @file{foo} nor
1796@file{bar} would lead to that recommendation.
1797
1798
eeaf4427
LC
1799@item --profile=@var{profile}
1800@itemx -p @var{profile}
1801Use @var{profile} instead of the user's default profile.
1802
70915c1a 1803@item --verbose
f97c9175
AE
1804Produce verbose output. In particular, emit the build log of the
1805environment on the standard error port.
70915c1a 1806
eeaf4427
LC
1807@item --bootstrap
1808Use the bootstrap Guile to build the profile. This option is only
1809useful to distribution developers.
1810
1811@end table
1812
f97c9175 1813In addition to these actions, @command{guix package} supports the
733b4130
LC
1814following options to query the current state of a profile, or the
1815availability of packages:
eeaf4427 1816
733b4130
LC
1817@table @option
1818
acc08466
NK
1819@item --search=@var{regexp}
1820@itemx -s @var{regexp}
b110869d 1821@cindex searching for packages
5763ad92 1822List the available packages whose name, synopsis, or description matches
f97c9175 1823@var{regexp}. Print all the metadata of matching packages in
299112d3
LC
1824@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1825GNU recutils manual}).
acc08466 1826
299112d3
LC
1827This allows specific fields to be extracted using the @command{recsel}
1828command, for instance:
1829
1830@example
e49951eb 1831$ guix package -s malloc | recsel -p name,version
299112d3
LC
1832name: glibc
1833version: 2.17
1834
1835name: libgc
1836version: 7.2alpha6
1837@end example
acc08466 1838
a12d92f5
LC
1839Similarly, to show the name of all the packages available under the
1840terms of the GNU@tie{}LGPL version 3:
1841
1842@example
1843$ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1844name: elfutils
1845
1846name: gmp
1847@dots{}
1848@end example
1849
db5a9444
LC
1850It is also possible to refine search results using several @code{-s}
1851flags. For example, the following command returns a list of board
1852games:
1853
1854@example
1855$ guix package -s '\<board\>' -s game | recsel -p name
1856name: gnubg
1857@dots{}
1858@end example
1859
1860If we were to omit @code{-s game}, we would also get software packages
1861that deal with printed circuit boards; removing the angle brackets
1862around @code{board} would further add packages that have to do with
1863keyboards.
1864
b110869d
LC
1865And now for a more elaborate example. The following command searches
1866for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1867libraries, and prints the name and synopsis of the matching packages:
1868
1869@example
1870$ guix package -s crypto -s library | \
1871 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1872@end example
1873
1874@noindent
1875@xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1876information on @dfn{selection expressions} for @code{recsel -e}.
1877
2aa6efb0
CR
1878@item --show=@var{package}
1879Show details about @var{package}, taken from the list of available packages, in
1880@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1881recutils manual}).
1882
1883@example
1884$ guix package --show=python | recsel -p name,version
1885name: python
1886version: 2.7.6
1887
1888name: python
1889version: 3.3.5
1890@end example
1891
1892You may also specify the full name of a package to only get details about a
1893specific version of it:
1894@example
ea206df4 1895$ guix package --show=python@@3.4 | recsel -p name,version
2aa6efb0 1896name: python
ea206df4 1897version: 3.4.3
2aa6efb0
CR
1898@end example
1899
1900
1901
733b4130
LC
1902@item --list-installed[=@var{regexp}]
1903@itemx -I [@var{regexp}]
bd9bde1c
LC
1904List the currently installed packages in the specified profile, with the
1905most recently installed packages shown last. When @var{regexp} is
1906specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
1907
1908For each installed package, print the following items, separated by
1909tabs: the package name, its version string, the part of the package that
1910is installed (for instance, @code{out} for the default output,
1911@code{include} for its headers, etc.), and the path of this package in
1912the store.
1913
64fc89b6
LC
1914@item --list-available[=@var{regexp}]
1915@itemx -A [@var{regexp}]
5763ad92 1916List packages currently available in the distribution for this system
a1ba8475
LC
1917(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1918installed packages whose name matches @var{regexp}.
64fc89b6
LC
1919
1920For each package, print the following items separated by tabs: its name,
6e721c4d
LC
1921its version string, the parts of the package (@pxref{Packages with
1922Multiple Outputs}), and the source location of its definition.
64fc89b6 1923
f566d765
LC
1924@item --list-generations[=@var{pattern}]
1925@itemx -l [@var{pattern}]
e32171ee 1926@cindex generations
f566d765
LC
1927Return a list of generations along with their creation dates; for each
1928generation, show the installed packages, with the most recently
4b2bc804
NK
1929installed packages shown last. Note that the zeroth generation is never
1930shown.
f566d765
LC
1931
1932For each installed package, print the following items, separated by
1933tabs: the name of a package, its version string, the part of the package
1934that is installed (@pxref{Packages with Multiple Outputs}), and the
1935location of this package in the store.
1936
1937When @var{pattern} is used, the command returns only matching
1938generations. Valid patterns include:
1939
1940@itemize
1941@item @emph{Integers and comma-separated integers}. Both patterns denote
1942generation numbers. For instance, @code{--list-generations=1} returns
1943the first one.
1944
1945And @code{--list-generations=1,8,2} outputs three generations in the
1946specified order. Neither spaces nor trailing commas are allowed.
1947
1948@item @emph{Ranges}. @code{--list-generations=2..9} prints the
1949specified generations and everything in between. Note that the start of
f97c9175 1950a range must be smaller than its end.
f566d765
LC
1951
1952It is also possible to omit the endpoint. For example,
1953@code{--list-generations=2..}, returns all generations starting from the
1954second one.
1955
1956@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1957or months by passing an integer along with the first letter of the
d7ddb257
LC
1958duration. For example, @code{--list-generations=20d} lists generations
1959that are up to 20 days old.
f566d765
LC
1960@end itemize
1961
b7884ca3
NK
1962@item --delete-generations[=@var{pattern}]
1963@itemx -d [@var{pattern}]
d7ddb257
LC
1964When @var{pattern} is omitted, delete all generations except the current
1965one.
b7884ca3
NK
1966
1967This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
1968When @var{pattern} is specified, delete the matching generations. When
1969@var{pattern} specifies a duration, generations @emph{older} than the
1970specified duration match. For instance, @code{--delete-generations=1m}
1971deletes generations that are more than one month old.
1972
391bdd8f
LC
1973If the current generation matches, it is @emph{not} deleted. Also, the
1974zeroth generation is never deleted.
b7884ca3 1975
f97c9175 1976Note that deleting generations prevents rolling back to them.
1bb9900a
LC
1977Consequently, this command must be used with care.
1978
733b4130 1979@end table
eeaf4427 1980
70ee5642 1981Finally, since @command{guix package} may actually start build
ccd7158d 1982processes, it supports all the common build options (@pxref{Common Build
f97c9175 1983Options}). It also supports package transformation options, such as
b8638f03
LC
1984@option{--with-source} (@pxref{Package Transformation Options}).
1985However, note that package transformations are lost when upgrading; to
f97c9175 1986preserve transformations across upgrades, you should define your own
b8638f03
LC
1987package variant in a Guile module and add it to @code{GUIX_PACKAGE_PATH}
1988(@pxref{Defining Packages}).
1989
70ee5642 1990
c4202d60
LC
1991@node Substitutes
1992@section Substitutes
1993
1994@cindex substitutes
1995@cindex pre-built binaries
1996Guix supports transparent source/binary deployment, which means that it
1997can either build things locally, or download pre-built items from a
1998server. We call these pre-built items @dfn{substitutes}---they are
1999substitutes for local build results. In many cases, downloading a
2000substitute is much faster than building things locally.
2001
2002Substitutes can be anything resulting from a derivation build
2003(@pxref{Derivations}). Of course, in the common case, they are
2004pre-built package binaries, but source tarballs, for instance, which
2005also result from derivation builds, can be available as substitutes.
2006
2007The @code{hydra.gnu.org} server is a front-end to a build farm that
2008builds packages from the GNU distribution continuously for some
deb6276d 2009architectures, and makes them available as substitutes. This is the
f8a8e0fe
LC
2010default source of substitutes; it can be overridden by passing the
2011@option{--substitute-urls} option either to @command{guix-daemon}
2012(@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
2013or to client tools such as @command{guix package}
2014(@pxref{client-substitute-urls,, client @option{--substitute-urls}
2015option}).
c4202d60 2016
1dbe3a8d 2017Substitute URLs can be either HTTP or HTTPS.
9b7bd1b1
LC
2018HTTPS is recommended because communications are encrypted; conversely,
2019using HTTP makes all communications visible to an eavesdropper, who
2020could use the information gathered to determine, for instance, whether
2021your system has unpatched security vulnerabilities.
2022
c4202d60
LC
2023@cindex security
2024@cindex digital signatures
e32171ee 2025@cindex substitutes, authorization thereof
df061d07
LC
2026To allow Guix to download substitutes from @code{hydra.gnu.org} or a
2027mirror thereof, you
c4202d60
LC
2028must add its public key to the access control list (ACL) of archive
2029imports, using the @command{guix archive} command (@pxref{Invoking guix
2030archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
2031be compromised and to serve genuine substitutes.
2032
2033This public key is installed along with Guix, in
2034@code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
2035the installation prefix of Guix. If you installed Guix from source,
2036make sure you checked the GPG signature of
2037@file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
2038Then, you can run something like this:
2039
2040@example
2041# guix archive --authorize < hydra.gnu.org.pub
2042@end example
2043
2044Once this is in place, the output of a command like @code{guix build}
2045should change from something like:
2046
2047@example
2048$ guix build emacs --dry-run
2049The following derivations would be built:
2050 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
2051 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
2052 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
2053 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
2054@dots{}
2055@end example
2056
2057@noindent
2058to something like:
2059
2060@example
2061$ guix build emacs --dry-run
2062The following files would be downloaded:
2063 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
2064 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
2065 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
2066 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
2067@dots{}
2068@end example
2069
2070@noindent
2071This indicates that substitutes from @code{hydra.gnu.org} are usable and
2072will be downloaded, when possible, for future builds.
2073
2074Guix ignores substitutes that are not signed, or that are not signed by
ef27aa9c 2075one of the keys listed in the ACL. It also detects and raises an error
c4202d60
LC
2076when attempting to use a substitute that has been tampered with.
2077
e0c941fe 2078@vindex http_proxy
9b7bd1b1
LC
2079Substitutes are downloaded over HTTP or HTTPS.
2080The @code{http_proxy} environment
e0c941fe
LC
2081variable can be set in the environment of @command{guix-daemon} and is
2082honored for downloads of substitutes. Note that the value of
2083@code{http_proxy} in the environment where @command{guix build},
2084@command{guix package}, and other client commands are run has
2085@emph{absolutely no effect}.
2086
9b7bd1b1
LC
2087When using HTTPS, the server's X.509 certificate is @emph{not} validated
2088(in other words, the server is not authenticated), contrary to what
2089HTTPS clients such as Web browsers usually do. This is because Guix
2090authenticates substitute information itself, as explained above, which
2091is what we care about (whereas X.509 certificates are about
2092authenticating bindings between domain names and public keys.)
2093
c4202d60
LC
2094The substitute mechanism can be disabled globally by running
2095@code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
2096guix-daemon}). It can also be disabled temporarily by passing the
2097@code{--no-substitutes} option to @command{guix package}, @command{guix
2098build}, and other command-line tools.
2099
2100
9b7bd1b1
LC
2101@unnumberedsubsec On Trusting Binaries
2102
c4202d60
LC
2103Today, each individual's control over their own computing is at the
2104mercy of institutions, corporations, and groups with enough power and
2105determination to subvert the computing infrastructure and exploit its
2106weaknesses. While using @code{hydra.gnu.org} substitutes can be
2107convenient, we encourage users to also build on their own, or even run
2108their own build farm, such that @code{hydra.gnu.org} is less of an
8ce229fc
LC
2109interesting target. One way to help is by publishing the software you
2110build using @command{guix publish} so that others have one more choice
2111of server to download substitutes from (@pxref{Invoking guix publish}).
c4202d60
LC
2112
2113Guix has the foundations to maximize build reproducibility
2114(@pxref{Features}). In most cases, independent builds of a given
2115package or derivation should yield bit-identical results. Thus, through
2116a diverse set of independent package builds, we can strengthen the
d23c20f1
LC
2117integrity of our systems. The @command{guix challenge} command aims to
2118help users assess substitute servers, and to assist developers in
2119finding out about non-deterministic package builds (@pxref{Invoking guix
a8d65643
LC
2120challenge}). Similarly, the @option{--check} option of @command{guix
2121build} allows users to check whether previously-installed substitutes
2122are genuine by rebuilding them locally (@pxref{build-check,
2123@command{guix build --check}}).
c4202d60
LC
2124
2125In the future, we want Guix to have support to publish and retrieve
2126binaries to/from other users, in a peer-to-peer fashion. If you would
2127like to discuss this project, join us on @email{guix-devel@@gnu.org}.
2128
2129
6e721c4d
LC
2130@node Packages with Multiple Outputs
2131@section Packages with Multiple Outputs
2132
2133@cindex multiple-output packages
2134@cindex package outputs
e32171ee 2135@cindex outputs
6e721c4d
LC
2136
2137Often, packages defined in Guix have a single @dfn{output}---i.e., the
f97c9175 2138source package leads to exactly one directory in the store. When running
6e721c4d
LC
2139@command{guix package -i glibc}, one installs the default output of the
2140GNU libc package; the default output is called @code{out}, but its name
2141can be omitted as shown in this command. In this particular case, the
2142default output of @code{glibc} contains all the C header files, shared
2143libraries, static libraries, Info documentation, and other supporting
2144files.
2145
2146Sometimes it is more appropriate to separate the various types of files
2147produced from a single source package into separate outputs. For
2148instance, the GLib C library (used by GTK+ and related packages)
2149installs more than 20 MiB of reference documentation as HTML pages.
2150To save space for users who do not need it, the documentation goes to a
2151separate output, called @code{doc}. To install the main GLib output,
2152which contains everything but the documentation, one would run:
2153
2154@example
2155guix package -i glib
2156@end example
2157
e32171ee 2158@cindex documentation
6e721c4d
LC
2159The command to install its documentation is:
2160
2161@example
2162guix package -i glib:doc
2163@end example
2164
2165Some packages install programs with different ``dependency footprints''.
f97c9175 2166For instance, the WordNet package installs both command-line tools and
6e721c4d
LC
2167graphical user interfaces (GUIs). The former depend solely on the C
2168library, whereas the latter depend on Tcl/Tk and the underlying X
2169libraries. In this case, we leave the command-line tools in the default
2170output, whereas the GUIs are in a separate output. This allows users
fcc58db6
LC
2171who do not need the GUIs to save space. The @command{guix size} command
2172can help find out about such situations (@pxref{Invoking guix size}).
88856916 2173@command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
6e721c4d
LC
2174
2175There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
2176Other conventional output names include @code{lib} for libraries and
2177possibly header files, @code{bin} for stand-alone programs, and
2178@code{debug} for debugging information (@pxref{Installing Debugging
2179Files}). The outputs of a packages are listed in the third column of
2180the output of @command{guix package --list-available} (@pxref{Invoking
2181guix package}).
6e721c4d 2182
eeaf4427 2183
e49951eb
MW
2184@node Invoking guix gc
2185@section Invoking @command{guix gc}
fe8ff028
LC
2186
2187@cindex garbage collector
e32171ee 2188@cindex disk space
f97c9175 2189Packages that are installed, but not used, may be @dfn{garbage-collected}.
e49951eb 2190The @command{guix gc} command allows users to explicitly run the garbage
c22eb992
LC
2191collector to reclaim space from the @file{/gnu/store} directory. It is
2192the @emph{only} way to remove files from @file{/gnu/store}---removing
2193files or directories manually may break it beyond repair!
fe8ff028
LC
2194
2195The garbage collector has a set of known @dfn{roots}: any file under
834129e0 2196@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
2197cannot be deleted; any other file is considered @dfn{dead} and may be
2198deleted. The set of garbage collector roots includes default user
e49951eb
MW
2199profiles, and may be augmented with @command{guix build --root}, for
2200example (@pxref{Invoking guix build}).
fe8ff028 2201
1bb9900a
LC
2202Prior to running @code{guix gc --collect-garbage} to make space, it is
2203often useful to remove old generations from user profiles; that way, old
2204package builds referenced by those generations can be reclaimed. This
2205is achieved by running @code{guix package --delete-generations}
2206(@pxref{Invoking guix package}).
2207
e49951eb 2208The @command{guix gc} command has three modes of operation: it can be
fe8ff028 2209used to garbage-collect any dead files (the default), to delete specific
7770aafc
LC
2210files (the @code{--delete} option), to print garbage-collector
2211information, or for more advanced queries. The garbage collection
2212options are as follows:
fe8ff028
LC
2213
2214@table @code
2215@item --collect-garbage[=@var{min}]
2216@itemx -C [@var{min}]
834129e0 2217Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
2218sub-directories. This is the default operation when no option is
2219specified.
2220
2221When @var{min} is given, stop once @var{min} bytes have been collected.
2222@var{min} may be a number of bytes, or it may include a unit as a
4a44d7bb
LC
2223suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
2224(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
fe8ff028
LC
2225
2226When @var{min} is omitted, collect all the garbage.
2227
0054e470
LC
2228@item --free-space=@var{free}
2229@itemx -F @var{free}
2230Collect garbage until @var{free} space is available under
2231@file{/gnu/store}, if possible; @var{free} denotes storage space, such
2232as @code{500MiB}, as described above.
2233
2234When @var{free} or more is already available in @file{/gnu/store}, do
2235nothing and exit immediately.
2236
fe8ff028
LC
2237@item --delete
2238@itemx -d
2239Attempt to delete all the store files and directories specified as
2240arguments. This fails if some of the files are not in the store, or if
2241they are still live.
2242
30d9aa54
LC
2243@item --list-failures
2244List store items corresponding to cached build failures.
2245
2246This prints nothing unless the daemon was started with
2247@option{--cache-failures} (@pxref{Invoking guix-daemon,
2248@option{--cache-failures}}).
2249
2250@item --clear-failures
2251Remove the specified store items from the failed-build cache.
2252
2253Again, this option only makes sense when the daemon is started with
2254@option{--cache-failures}. Otherwise, it does nothing.
2255
fe8ff028
LC
2256@item --list-dead
2257Show the list of dead files and directories still present in the
2258store---i.e., files and directories no longer reachable from any root.
2259
2260@item --list-live
2261Show the list of live store files and directories.
ba8b732d
LC
2262
2263@end table
2264
2265In addition, the references among existing store files can be queried:
2266
2267@table @code
2268
2269@item --references
2270@itemx --referrers
e32171ee 2271@cindex package dependencies
ba8b732d
LC
2272List the references (respectively, the referrers) of store files given
2273as arguments.
2274
8e59fdd5
LC
2275@item --requisites
2276@itemx -R
fcc58db6 2277@cindex closure
8e59fdd5
LC
2278List the requisites of the store files passed as arguments. Requisites
2279include the store files themselves, their references, and the references
2280of these, recursively. In other words, the returned list is the
2281@dfn{transitive closure} of the store files.
2282
f97c9175
AE
2283@xref{Invoking guix size}, for a tool to profile the size of the closure
2284of an element. @xref{Invoking guix graph}, for a tool to visualize
88856916 2285the graph of references.
fcc58db6 2286
fe8ff028
LC
2287@end table
2288
7770aafc
LC
2289Lastly, the following options allow you to check the integrity of the
2290store and to control disk usage.
2291
2292@table @option
2293
2294@item --verify[=@var{options}]
2295@cindex integrity, of the store
2296@cindex integrity checking
2297Verify the integrity of the store.
2298
2299By default, make sure that all the store items marked as valid in the
f97c9175 2300database of the daemon actually exist in @file{/gnu/store}.
7770aafc 2301
f97c9175 2302When provided, @var{options} must be a comma-separated list containing one
7770aafc
LC
2303or more of @code{contents} and @code{repair}.
2304
7414de0a 2305When passing @option{--verify=contents}, the daemon computes the
f97c9175 2306content hash of each store item and compares it against its hash in the
7770aafc
LC
2307database. Hash mismatches are reported as data corruptions. Because it
2308traverses @emph{all the files in the store}, this command can take a
2309long time, especially on systems with a slow disk drive.
2310
2311@cindex repairing the store
6da5bb7b 2312@cindex corruption, recovering from
7770aafc
LC
2313Using @option{--verify=repair} or @option{--verify=contents,repair}
2314causes the daemon to try to repair corrupt store items by fetching
2315substitutes for them (@pxref{Substitutes}). Because repairing is not
2316atomic, and thus potentially dangerous, it is available only to the
6da5bb7b
LC
2317system administrator. A lightweight alternative, when you know exactly
2318which items in the store are corrupt, is @command{guix build --repair}
2319(@pxref{Invoking guix build}).
7770aafc
LC
2320
2321@item --optimize
2322@cindex deduplication
2323Optimize the store by hard-linking identical files---this is
2324@dfn{deduplication}.
2325
2326The daemon performs deduplication after each successful build or archive
2327import, unless it was started with @code{--disable-deduplication}
2328(@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
2329this option is primarily useful when the daemon was running with
2330@code{--disable-deduplication}.
2331
2332@end table
eeaf4427 2333
f651b477
LC
2334@node Invoking guix pull
2335@section Invoking @command{guix pull}
2336
e32171ee 2337@cindex upgrading Guix
7fcf2a0b 2338@cindex updating Guix
e32171ee
JD
2339@cindex @command{guix pull}
2340@cindex pull
f651b477
LC
2341Packages are installed or upgraded to the latest version available in
2342the distribution currently available on your local machine. To update
2343that distribution, along with the Guix tools, you must run @command{guix
2344pull}: the command downloads the latest Guix source code and package
2345descriptions, and deploys it.
2346
2347On completion, @command{guix package} will use packages and package
2348versions from this just-retrieved copy of Guix. Not only that, but all
2349the Guix commands and Scheme modules will also be taken from that latest
2350version. New @command{guix} sub-commands added by the update also
cb05108a
LC
2351become available.
2352
2353Any user can update their Guix copy using @command{guix pull}, and the
2354effect is limited to the user who run @command{guix pull}. For
2355instance, when user @code{root} runs @command{guix pull}, this has no
2356effect on the version of Guix that user @code{alice} sees, and vice
2357versa@footnote{Under the hood, @command{guix pull} updates the
2358@file{~/.config/guix/latest} symbolic link to point to the latest Guix,
5e2017ed
CM
2359and the @command{guix} command loads code from there. Currently, the
2360only way to roll back an invocation of @command{guix pull} is to
2361manually update this symlink to point to the previous Guix.}.
f651b477
LC
2362
2363The @command{guix pull} command is usually invoked with no arguments,
2364but it supports the following options:
2365
2366@table @code
2367@item --verbose
2368Produce verbose output, writing build logs to the standard error output.
2369
ab5d72ad
LC
2370@item --url=@var{url}
2371Download the source tarball of Guix from @var{url}.
2372
2373By default, the tarball is taken from its canonical address at
2374@code{gnu.org}, for the stable branch of Guix.
2375
8a9cffb2
LF
2376With some Git servers, this can be used to deploy any version of Guix.
2377For example, to download and deploy version 0.12.0 of Guix from the
2378canonical Git repo:
2379
2380@example
2381guix pull --url=http://git.savannah.gnu.org/cgit/guix.git/snapshot/v0.12.0.tar.gz
2382@end example
2383
2384It can also be used to deploy arbitrary Git revisions:
2385
2386@example
2387guix pull --url=http://git.savannah.gnu.org/cgit/guix.git/snapshot/74d862e8a.tar.gz
2388@end example
2389
f651b477
LC
2390@item --bootstrap
2391Use the bootstrap Guile to build the latest Guix. This option is only
2392useful to Guix developers.
2393@end table
2394
760c60d6 2395
239c2266
LC
2396@node Invoking guix pack
2397@section Invoking @command{guix pack}
2398
2399Occasionally you want to pass software to people who are not (yet!)
2400lucky enough to be using Guix. You'd tell them to run @command{guix
2401package -i @var{something}}, but that's not possible in this case. This
2402is where @command{guix pack} comes in.
2403
2404@cindex pack
2405@cindex bundle
2406@cindex application bundle
2407@cindex software bundle
2408The @command{guix pack} command creates a shrink-wrapped @dfn{pack} or
2409@dfn{software bundle}: it creates a tarball or some other archive
2410containing the binaries of the software you're interested in, and all
2411its dependencies. The resulting archive can be used on any machine that
2412does not have Guix, and people can run the exact same binaries as those
107b8da6
LC
2413you have with Guix. The pack itself is created in a bit-reproducible
2414fashion, so anyone can verify that it really contains the build results
2415that you pretend to be shipping.
239c2266
LC
2416
2417For example, to create a bundle containing Guile, Emacs, Geiser, and all
2418their dependencies, you can run:
2419
2420@example
2421$ guix pack guile emacs geiser
2422@dots{}
2423/gnu/store/@dots{}-pack.tar.gz
2424@end example
2425
2426The result here is a tarball containing a @file{/gnu/store} directory
2427with all the relevant packages. The resulting tarball contains a
2428@dfn{profile} with the three packages of interest; the profile is the
2429same as would be created by @command{guix package -i}. It is this
2430mechanism that is used to create Guix's own standalone binary tarball
2431(@pxref{Binary Installation}).
2432
5895ec8a
LC
2433Users of this pack would have to run
2434@file{/gnu/store/@dots{}-profile/bin/guile} to run Guile, which you may
2435find inconvenient. To work around it, you can create, say, a
2436@file{/opt/gnu/bin} symlink to the profile:
2437
2438@example
2439guix pack -S /opt/gnu/bin=bin guile emacs geiser
2440@end example
2441
2442@noindent
2443That way, users can happily type @file{/opt/gnu/bin/guile} and enjoy.
2444
708b54a9
LC
2445Alternatively, you can produce a pack in the Docker image format using
2446the following command:
b1edfbc3
LC
2447
2448@example
2449guix pack -f docker guile emacs geiser
2450@end example
2451
2452@noindent
2453The result is a tarball that can be passed to the @command{docker load}
2454command. See the
2455@uref{https://docs.docker.com/engine/reference/commandline/load/, Docker
2456documentation} for more information.
2457
239c2266
LC
2458Several command-line options allow you to customize your pack:
2459
2460@table @code
708b54a9
LC
2461@item --format=@var{format}
2462@itemx -f @var{format}
2463Produce a pack in the given @var{format}.
2464
2465The available formats are:
2466
2467@table @code
2468@item tarball
2469This is the default format. It produces a tarball containing all the
2470specifies binaries and symlinks.
2471
2472@item docker
2473This produces a tarball that follows the
2474@uref{https://github.com/docker/docker/blob/master/image/spec/v1.2.md,
2475Docker Image Specification}.
2476@end table
2477
239c2266
LC
2478@item --system=@var{system}
2479@itemx -s @var{system}
2480Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
2481the system type of the build host.
2482
5461115e
LC
2483@item --target=@var{triplet}
2484@cindex cross-compilation
2485Cross-build for @var{triplet}, which must be a valid GNU triplet, such
2486as @code{"mips64el-linux-gnu"} (@pxref{Specifying target triplets, GNU
2487configuration triplets,, autoconf, Autoconf}).
2488
239c2266
LC
2489@item --compression=@var{tool}
2490@itemx -C @var{tool}
2491Compress the resulting tarball using @var{tool}---one of @code{gzip},
2492@code{bzip2}, @code{xz}, or @code{lzip}.
6b63c43e 2493
5895ec8a
LC
2494@item --symlink=@var{spec}
2495@itemx -S @var{spec}
2496Add the symlinks specified by @var{spec} to the pack. This option can
2497appear several times.
2498
2499@var{spec} has the form @code{@var{source}=@var{target}}, where
2500@var{source} is the symlink that will be created and @var{target} is the
2501symlink target.
2502
2503For instance, @code{-S /opt/gnu/bin=bin} creates a @file{/opt/gnu/bin}
2504symlink pointing to the @file{bin} sub-directory of the profile.
2505
6b63c43e
LC
2506@item --localstatedir
2507Include the ``local state directory'', @file{/var/guix}, in the
2508resulting pack.
2509
2510@file{/var/guix} contains the store database (@pxref{The Store}) as well
2511as garbage-collector roots (@pxref{Invoking guix gc}). Providing it in
2512the pack means that the store is ``complete'' and manageable by Guix;
2513not providing it pack means that the store is ``dead'': items cannot be
2514added to it or removed from it after extraction of the pack.
2515
2516One use case for this is the Guix self-contained binary tarball
2517(@pxref{Binary Installation}).
239c2266
LC
2518@end table
2519
2520In addition, @command{guix pack} supports all the common build options
2521(@pxref{Common Build Options}) and all the package transformation
2522options (@pxref{Package Transformation Options}).
2523
2524
760c60d6
LC
2525@node Invoking guix archive
2526@section Invoking @command{guix archive}
2527
e32171ee
JD
2528@cindex @command{guix archive}
2529@cindex archive
760c60d6
LC
2530The @command{guix archive} command allows users to @dfn{export} files
2531from the store into a single archive, and to later @dfn{import} them.
2532In particular, it allows store files to be transferred from one machine
4d4c4816
AE
2533to the store on another machine.
2534
e32171ee 2535@cindex exporting store items
4d4c4816
AE
2536To export store files as an archive to standard output, run:
2537
2538@example
2539guix archive --export @var{options} @var{specifications}...
2540@end example
2541
2542@var{specifications} may be either store file names or package
2543specifications, as for @command{guix package} (@pxref{Invoking guix
2544package}). For instance, the following command creates an archive
2545containing the @code{gui} output of the @code{git} package and the main
2546output of @code{emacs}:
2547
2548@example
2549guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
2550@end example
2551
2552If the specified packages are not built yet, @command{guix archive}
2553automatically builds them. The build process may be controlled with the
2554common build options (@pxref{Common Build Options}).
2555
2556To transfer the @code{emacs} package to a machine connected over SSH,
2557one would run:
760c60d6
LC
2558
2559@example
56607088 2560guix archive --export -r emacs | ssh the-machine guix archive --import
760c60d6
LC
2561@end example
2562
87236aed 2563@noindent
56607088
LC
2564Similarly, a complete user profile may be transferred from one machine
2565to another like this:
2566
2567@example
2568guix archive --export -r $(readlink -f ~/.guix-profile) | \
2569 ssh the-machine guix-archive --import
2570@end example
2571
2572@noindent
2573However, note that, in both examples, all of @code{emacs} and the
2574profile as well as all of their dependencies are transferred (due to
f97c9175
AE
2575@code{-r}), regardless of what is already available in the store on the
2576target machine. The @code{--missing} option can help figure out which
f11c444d
LC
2577items are missing from the target store. The @command{guix copy}
2578command simplifies and optimizes this whole process, so this is probably
2579what you should use in this case (@pxref{Invoking guix copy}).
87236aed 2580
5597b3ae
LC
2581@cindex nar, archive format
2582@cindex normalized archive (nar)
b1edfbc3 2583Archives are stored in the ``normalized archive'' or ``nar'' format, which is
5597b3ae 2584comparable in spirit to `tar', but with differences
0dbd88db 2585that make it more appropriate for our purposes. First, rather than
5597b3ae 2586recording all Unix metadata for each file, the nar format only mentions
0dbd88db
LC
2587the file type (regular, directory, or symbolic link); Unix permissions
2588and owner/group are dismissed. Second, the order in which directory
2589entries are stored always follows the order of file names according to
2590the C locale collation order. This makes archive production fully
2591deterministic.
2592
2593When exporting, the daemon digitally signs the contents of the archive,
2594and that digital signature is appended. When importing, the daemon
2595verifies the signature and rejects the import in case of an invalid
2596signature or if the signing key is not authorized.
760c60d6
LC
2597@c FIXME: Add xref to daemon doc about signatures.
2598
2599The main options are:
2600
2601@table @code
2602@item --export
2603Export the specified store files or packages (see below.) Write the
2604resulting archive to the standard output.
2605
56607088
LC
2606Dependencies are @emph{not} included in the output, unless
2607@code{--recursive} is passed.
2608
2609@item -r
2610@itemx --recursive
2611When combined with @code{--export}, this instructs @command{guix
2612archive} to include dependencies of the given items in the archive.
2613Thus, the resulting archive is self-contained: it contains the closure
2614of the exported store items.
2615
760c60d6
LC
2616@item --import
2617Read an archive from the standard input, and import the files listed
2618therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
2619signature, or if it is signed by a public key not among the authorized
2620keys (see @code{--authorize} below.)
554f26ec 2621
87236aed
LC
2622@item --missing
2623Read a list of store file names from the standard input, one per line,
2624and write on the standard output the subset of these files missing from
2625the store.
2626
554f26ec 2627@item --generate-key[=@var{parameters}]
f82cc5fd 2628@cindex signing, archives
f97c9175 2629Generate a new key pair for the daemon. This is a prerequisite before
554f26ec
LC
2630archives can be exported with @code{--export}. Note that this operation
2631usually takes time, because it needs to gather enough entropy to
2632generate the key pair.
2633
2634The generated key pair is typically stored under @file{/etc/guix}, in
2635@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
867d8473
LC
2636key, which must be kept secret.) When @var{parameters} is omitted,
2637an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2638versions before 1.6.0, it is a 4096-bit RSA key.
f97c9175 2639Alternatively, @var{parameters} can specify
554f26ec
LC
2640@code{genkey} parameters suitable for Libgcrypt (@pxref{General
2641public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2642Libgcrypt Reference Manual}).
f82cc5fd
LC
2643
2644@item --authorize
2645@cindex authorizing, archives
2646Authorize imports signed by the public key passed on standard input.
2647The public key must be in ``s-expression advanced format''---i.e., the
2648same format as the @file{signing-key.pub} file.
2649
2650The list of authorized keys is kept in the human-editable file
2651@file{/etc/guix/acl}. The file contains
2652@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2653s-expressions''} and is structured as an access-control list in the
2654@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2655(SPKI)}.
c6f8e9dd
LC
2656
2657@item --extract=@var{directory}
2658@itemx -x @var{directory}
2659Read a single-item archive as served by substitute servers
2660(@pxref{Substitutes}) and extract it to @var{directory}. This is a
2661low-level operation needed in only very narrow use cases; see below.
2662
2663For example, the following command extracts the substitute for Emacs
2664served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2665
2666@example
2667$ wget -O - \
df061d07 2668 https://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
c6f8e9dd
LC
2669 | bunzip2 | guix archive -x /tmp/emacs
2670@end example
2671
2672Single-item archives are different from multiple-item archives produced
2673by @command{guix archive --export}; they contain a single store item,
2674and they do @emph{not} embed a signature. Thus this operation does
2675@emph{no} signature verification and its output should be considered
2676unsafe.
2677
2678The primary purpose of this operation is to facilitate inspection of
2679archive contents coming from possibly untrusted substitute servers.
2680
760c60d6
LC
2681@end table
2682
568717fd
LC
2683@c *********************************************************************
2684@node Programming Interface
2685@chapter Programming Interface
2686
3dc1970d
LC
2687GNU Guix provides several Scheme programming interfaces (APIs) to
2688define, build, and query packages. The first interface allows users to
2689write high-level package definitions. These definitions refer to
2690familiar packaging concepts, such as the name and version of a package,
2691its build system, and its dependencies. These definitions can then be
2692turned into concrete build actions.
2693
ba55b1cb 2694Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 2695standard setup, the daemon has write access to the store---the
834129e0 2696@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
2697setup also has the daemon perform builds in chroots, under a specific
2698build users, to minimize interference with the rest of the system.
2699
2700@cindex derivation
2701Lower-level APIs are available to interact with the daemon and the
2702store. To instruct the daemon to perform a build action, users actually
2703provide it with a @dfn{derivation}. A derivation is a low-level
2704representation of the build actions to be taken, and the environment in
2705which they should occur---derivations are to package definitions what
49ad317a
LC
2706assembly is to C programs. The term ``derivation'' comes from the fact
2707that build results @emph{derive} from them.
3dc1970d
LC
2708
2709This chapter describes all these APIs in turn, starting from high-level
2710package definitions.
2711
568717fd 2712@menu
b860f382 2713* Defining Packages:: Defining new packages.
7458bd0a 2714* Build Systems:: Specifying how packages are built.
b860f382
LC
2715* The Store:: Manipulating the package store.
2716* Derivations:: Low-level interface to package derivations.
2717* The Store Monad:: Purely functional interface to the store.
21b679f6 2718* G-Expressions:: Manipulating build expressions.
568717fd
LC
2719@end menu
2720
2721@node Defining Packages
2722@section Defining Packages
2723
3dc1970d
LC
2724The high-level interface to package definitions is implemented in the
2725@code{(guix packages)} and @code{(guix build-system)} modules. As an
2726example, the package definition, or @dfn{recipe}, for the GNU Hello
2727package looks like this:
2728
2729@example
e7f34eb0
LC
2730(define-module (gnu packages hello)
2731 #:use-module (guix packages)
2732 #:use-module (guix download)
2733 #:use-module (guix build-system gnu)
a6dcdcac
SB
2734 #:use-module (guix licenses)
2735 #:use-module (gnu packages gawk))
b22a12fd 2736
79f5dd59 2737(define-public hello
3dc1970d
LC
2738 (package
2739 (name "hello")
17d8e33f 2740 (version "2.10")
3dc1970d 2741 (source (origin
17d8e33f
ML
2742 (method url-fetch)
2743 (uri (string-append "mirror://gnu/hello/hello-" version
2744 ".tar.gz"))
2745 (sha256
2746 (base32
2747 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
3dc1970d 2748 (build-system gnu-build-system)
654c0d97 2749 (arguments '(#:configure-flags '("--enable-silent-rules")))
3dc1970d 2750 (inputs `(("gawk" ,gawk)))
7458bd0a
LC
2751 (synopsis "Hello, GNU world: An example GNU package")
2752 (description "Guess what GNU Hello prints!")
3dc1970d 2753 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 2754 (license gpl3+)))
3dc1970d
LC
2755@end example
2756
2757@noindent
2758Without being a Scheme expert, the reader may have guessed the meaning
f97c9175
AE
2759of the various fields here. This expression binds the variable
2760@code{hello} to a @code{<package>} object, which is essentially a record
3dc1970d
LC
2761(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2762This package object can be inspected using procedures found in the
2763@code{(guix packages)} module; for instance, @code{(package-name hello)}
2764returns---surprise!---@code{"hello"}.
2765
2f7d2d91
LC
2766With luck, you may be able to import part or all of the definition of
2767the package you are interested in from another repository, using the
2768@code{guix import} command (@pxref{Invoking guix import}).
2769
f97c9175 2770In the example above, @var{hello} is defined in a module of its own,
e7f34eb0
LC
2771@code{(gnu packages hello)}. Technically, this is not strictly
2772necessary, but it is convenient to do so: all the packages defined in
2773modules under @code{(gnu packages @dots{})} are automatically known to
2774the command-line tools (@pxref{Package Modules}).
2775
3dc1970d
LC
2776There are a few points worth noting in the above package definition:
2777
2778@itemize
2779@item
a2bf4907
LC
2780The @code{source} field of the package is an @code{<origin>} object
2781(@pxref{origin Reference}, for the complete reference).
3dc1970d
LC
2782Here, the @code{url-fetch} method from @code{(guix download)} is used,
2783meaning that the source is a file to be downloaded over FTP or HTTP.
2784
2785The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2786the GNU mirrors defined in @code{(guix download)}.
2787
2788The @code{sha256} field specifies the expected SHA256 hash of the file
2789being downloaded. It is mandatory, and allows Guix to check the
2790integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 2791base32 representation of the hash. You can obtain this information with
210cc920
LC
2792@code{guix download} (@pxref{Invoking guix download}) and @code{guix
2793hash} (@pxref{Invoking guix hash}).
3dc1970d 2794
f9cc8971
LC
2795@cindex patches
2796When needed, the @code{origin} form can also have a @code{patches} field
2797listing patches to be applied, and a @code{snippet} field giving a
2798Scheme expression to modify the source code.
2799
3dc1970d
LC
2800@item
2801@cindex GNU Build System
7458bd0a
LC
2802The @code{build-system} field specifies the procedure to build the
2803package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2804represents the familiar GNU Build System, where packages may be
2805configured, built, and installed with the usual @code{./configure &&
2806make && make check && make install} command sequence.
2807
2808@item
2809The @code{arguments} field specifies options for the build system
2810(@pxref{Build Systems}). Here it is interpreted by
2811@var{gnu-build-system} as a request run @file{configure} with the
2812@code{--enable-silent-rules} flag.
3dc1970d 2813
654c0d97
LC
2814@cindex quote
2815@cindex quoting
2816@findex '
2817@findex quote
2818What about these quote (@code{'}) characters? They are Scheme syntax to
2819introduce a literal list; @code{'} is synonymous with @code{quote}.
2820@xref{Expression Syntax, quoting,, guile, GNU Guile Reference Manual},
2821for details. Here the value of the @code{arguments} field is a list of
2822arguments passed to the build system down the road, as with @code{apply}
2823(@pxref{Fly Evaluation, @code{apply},, guile, GNU Guile Reference
2824Manual}).
2825
2826The hash-colon (@code{#:}) sequence defines a Scheme @dfn{keyword}
2827(@pxref{Keywords,,, guile, GNU Guile Reference Manual}), and
2828@code{#:configure-flags} is a keyword used to pass a keyword argument
2829to the build system (@pxref{Coding With Keywords,,, guile, GNU Guile
2830Reference Manual}).
2831
3dc1970d
LC
2832@item
2833The @code{inputs} field specifies inputs to the build process---i.e.,
2834build-time or run-time dependencies of the package. Here, we define an
2835input called @code{"gawk"} whose value is that of the @var{gawk}
2836variable; @var{gawk} is itself bound to a @code{<package>} object.
2837
654c0d97
LC
2838@cindex backquote (quasiquote)
2839@findex `
2840@findex quasiquote
2841@cindex comma (unquote)
2842@findex ,
2843@findex unquote
2844@findex ,@@
2845@findex unquote-splicing
2846Again, @code{`} (a backquote, synonymous with @code{quasiquote}) allows
2847us to introduce a literal list in the @code{inputs} field, while
2848@code{,} (a comma, synonymous with @code{unquote}) allows us to insert a
2849value in that list (@pxref{Expression Syntax, unquote,, guile, GNU Guile
2850Reference Manual}).
2851
3dc1970d
LC
2852Note that GCC, Coreutils, Bash, and other essential tools do not need to
2853be specified as inputs here. Instead, @var{gnu-build-system} takes care
7458bd0a 2854of ensuring that they are present (@pxref{Build Systems}).
3dc1970d
LC
2855
2856However, any other dependencies need to be specified in the
2857@code{inputs} field. Any dependency not specified here will simply be
2858unavailable to the build process, possibly leading to a build failure.
2859@end itemize
2860
87eafdbd
TUBK
2861@xref{package Reference}, for a full description of possible fields.
2862
2f7d2d91 2863Once a package definition is in place, the
e49951eb 2864package may actually be built using the @code{guix build} command-line
39bee8a2
LC
2865tool (@pxref{Invoking guix build}). You can easily jump back to the
2866package definition using the @command{guix edit} command
2867(@pxref{Invoking guix edit}).
2868@xref{Packaging Guidelines}, for
b4f5e0e8
CR
2869more information on how to test package definitions, and
2870@ref{Invoking guix lint}, for information on how to check a definition
2871for style conformance.
2872
f97c9175 2873Finally, updating the package definition to a new upstream version
7458bd0a
LC
2874can be partly automated by the @command{guix refresh} command
2875(@pxref{Invoking guix refresh}).
3dc1970d
LC
2876
2877Behind the scenes, a derivation corresponding to the @code{<package>}
2878object is first computed by the @code{package-derivation} procedure.
834129e0 2879That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 2880The build actions it prescribes may then be realized by using the
3dc1970d
LC
2881@code{build-derivations} procedure (@pxref{The Store}).
2882
2883@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
2884Return the @code{<derivation>} object of @var{package} for @var{system}
2885(@pxref{Derivations}).
3dc1970d
LC
2886
2887@var{package} must be a valid @code{<package>} object, and @var{system}
2888must be a string denoting the target system type---e.g.,
2889@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2890must be a connection to the daemon, which operates on the store
2891(@pxref{The Store}).
2892@end deffn
568717fd 2893
9c1edabd
LC
2894@noindent
2895@cindex cross-compilation
2896Similarly, it is possible to compute a derivation that cross-builds a
2897package for some other system:
2898
2899@deffn {Scheme Procedure} package-cross-derivation @var{store} @
2900 @var{package} @var{target} [@var{system}]
59688fc4
LC
2901Return the @code{<derivation>} object of @var{package} cross-built from
2902@var{system} to @var{target}.
9c1edabd
LC
2903
2904@var{target} must be a valid GNU triplet denoting the target hardware
2905and operating system, such as @code{"mips64el-linux-gnu"}
2906(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2907Configure and Build System}).
2908@end deffn
2909
2a75b0b6
LC
2910@cindex package transformations
2911@cindex input rewriting
2912@cindex dependency tree rewriting
2913Packages can be manipulated in arbitrary ways. An example of a useful
2914transformation is @dfn{input rewriting}, whereby the dependency tree of
2915a package is rewritten by replacing specific inputs by others:
2916
2917@deffn {Scheme Procedure} package-input-rewriting @var{replacements} @
2918 [@var{rewrite-name}]
2919Return a procedure that, when passed a package, replaces its direct and
2920indirect dependencies (but not its implicit inputs) according to
2921@var{replacements}. @var{replacements} is a list of package pairs; the
2922first element of each pair is the package to replace, and the second one
2923is the replacement.
2924
2925Optionally, @var{rewrite-name} is a one-argument procedure that takes
2926the name of a package and returns its new name after rewrite.
2927@end deffn
2928
2929@noindent
2930Consider this example:
2931
2932@example
2933(define libressl-instead-of-openssl
2934 ;; This is a procedure to replace OPENSSL by LIBRESSL,
2935 ;; recursively.
2936 (package-input-rewriting `((,openssl . ,libressl))))
2937
2938(define git-with-libressl
2939 (libressl-instead-of-openssl git))
2940@end example
2941
2942@noindent
2943Here we first define a rewriting procedure that replaces @var{openssl}
2944with @var{libressl}. Then we use it to define a @dfn{variant} of the
2945@var{git} package that uses @var{libressl} instead of @var{openssl}.
2946This is exactly what the @option{--with-input} command-line option does
2947(@pxref{Package Transformation Options, @option{--with-input}}).
2948
f37f2b83
LC
2949A more generic procedure to rewrite a package dependency graph is
2950@code{package-mapping}: it supports arbitrary changes to nodes in the
2951graph.
2952
2953@deffn {Scheme Procedure} package-mapping @var{proc} [@var{cut?}]
2954Return a procedure that, given a package, applies @var{proc} to all the packages
2955depended on and returns the resulting package. The procedure stops recursion
2956when @var{cut?} returns true for a given package.
2957@end deffn
2958
87eafdbd
TUBK
2959@menu
2960* package Reference :: The package data type.
2961* origin Reference:: The origin data type.
2962@end menu
2963
2964
2965@node package Reference
2966@subsection @code{package} Reference
2967
2968This section summarizes all the options available in @code{package}
2969declarations (@pxref{Defining Packages}).
2970
2971@deftp {Data Type} package
2972This is the data type representing a package recipe.
2973
2974@table @asis
2975@item @code{name}
2976The name of the package, as a string.
2977
2978@item @code{version}
2979The version of the package, as a string.
2980
2981@item @code{source}
da675305
LC
2982An object telling how the source code for the package should be
2983acquired. Most of the time, this is an @code{origin} object, which
2984denotes a file fetched from the Internet (@pxref{origin Reference}). It
2985can also be any other ``file-like'' object such as a @code{local-file},
2986which denotes a file from the local file system (@pxref{G-Expressions,
2987@code{local-file}}).
87eafdbd
TUBK
2988
2989@item @code{build-system}
2990The build system that should be used to build the package (@pxref{Build
2991Systems}).
2992
2993@item @code{arguments} (default: @code{'()})
2994The arguments that should be passed to the build system. This is a
2995list, typically containing sequential keyword-value pairs.
2996
2997@item @code{inputs} (default: @code{'()})
70650c68
LC
2998@itemx @code{native-inputs} (default: @code{'()})
2999@itemx @code{propagated-inputs} (default: @code{'()})
3000@cindex inputs, of packages
3001These fields list dependencies of the package. Each one is a list of
3002tuples, where each tuple has a label for the input (a string) as its
3003first element, a package, origin, or derivation as its second element,
3004and optionally the name of the output thereof that should be used, which
3005defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
f97c9175 3006more on package outputs). For example, the list below specifies three
70650c68 3007inputs:
87eafdbd 3008
70650c68
LC
3009@example
3010`(("libffi" ,libffi)
3011 ("libunistring" ,libunistring)
3012 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
3013@end example
3014
3015@cindex cross compilation, package dependencies
3016The distinction between @code{native-inputs} and @code{inputs} is
3017necessary when considering cross-compilation. When cross-compiling,
3018dependencies listed in @code{inputs} are built for the @emph{target}
3019architecture; conversely, dependencies listed in @code{native-inputs}
3020are built for the architecture of the @emph{build} machine.
3021
f97c9175
AE
3022@code{native-inputs} is typically used to list tools needed at
3023build time, but not at run time, such as Autoconf, Automake, pkg-config,
70650c68
LC
3024Gettext, or Bison. @command{guix lint} can report likely mistakes in
3025this area (@pxref{Invoking guix lint}).
3026
3027@anchor{package-propagated-inputs}
3028Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
f97c9175
AE
3029specified packages will be automatically installed alongside the package
3030they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
70650c68
LC
3031package}}, for information on how @command{guix package} deals with
3032propagated inputs.)
21461f27 3033
e0508b6b
LC
3034For example this is necessary when a C/C++ library needs headers of
3035another library to compile, or when a pkg-config file refers to another
3036one @i{via} its @code{Requires} field.
3037
f97c9175
AE
3038Another example where @code{propagated-inputs} is useful is for languages
3039that lack a facility to record the run-time search path akin to the
c8ebb4c4 3040@code{RUNPATH} of ELF files; this includes Guile, Python, Perl, and
e0508b6b
LC
3041more. To ensure that libraries written in those languages can find
3042library code they depend on at run time, run-time dependencies must be
3043listed in @code{propagated-inputs} rather than @code{inputs}.
87eafdbd 3044
87eafdbd
TUBK
3045@item @code{self-native-input?} (default: @code{#f})
3046This is a Boolean field telling whether the package should use itself as
3047a native input when cross-compiling.
3048
3049@item @code{outputs} (default: @code{'("out")})
3050The list of output names of the package. @xref{Packages with Multiple
3051Outputs}, for typical uses of additional outputs.
3052
3053@item @code{native-search-paths} (default: @code{'()})
3054@itemx @code{search-paths} (default: @code{'()})
3055A list of @code{search-path-specification} objects describing
3056search-path environment variables honored by the package.
3057
3058@item @code{replacement} (default: @code{#f})
f97c9175 3059This must be either @code{#f} or a package object that will be used as a
87eafdbd
TUBK
3060@dfn{replacement} for this package. @xref{Security Updates, grafts},
3061for details.
3062
3063@item @code{synopsis}
3064A one-line description of the package.
3065
3066@item @code{description}
3067A more elaborate description of the package.
3068
3069@item @code{license}
e32171ee 3070@cindex license, of packages
f97c9175
AE
3071The license of the package; a value from @code{(guix licenses)},
3072or a list of such values.
87eafdbd
TUBK
3073
3074@item @code{home-page}
3075The URL to the home-page of the package, as a string.
3076
3077@item @code{supported-systems} (default: @var{%supported-systems})
3078The list of systems supported by the package, as strings of the form
3079@code{architecture-kernel}, for example @code{"x86_64-linux"}.
3080
3081@item @code{maintainers} (default: @code{'()})
3082The list of maintainers of the package, as @code{maintainer} objects.
3083
3084@item @code{location} (default: source location of the @code{package} form)
f97c9175 3085The source location of the package. It is useful to override this when
87eafdbd
TUBK
3086inheriting from another package, in which case this field is not
3087automatically corrected.
3088@end table
3089@end deftp
3090
3091
3092@node origin Reference
3093@subsection @code{origin} Reference
3094
3095This section summarizes all the options available in @code{origin}
3096declarations (@pxref{Defining Packages}).
3097
3098@deftp {Data Type} origin
3099This is the data type representing a source code origin.
3100
3101@table @asis
3102@item @code{uri}
3103An object containing the URI of the source. The object type depends on
3104the @code{method} (see below). For example, when using the
3105@var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
3106values are: a URL represented as a string, or a list thereof.
3107
3108@item @code{method}
f97c9175 3109A procedure that handles the URI.
87eafdbd
TUBK
3110
3111Examples include:
3112
3113@table @asis
3114@item @var{url-fetch} from @code{(guix download)}
f97c9175 3115download a file from the HTTP, HTTPS, or FTP URL specified in the
87eafdbd
TUBK
3116@code{uri} field;
3117
db97a03a 3118@vindex git-fetch
87eafdbd
TUBK
3119@item @var{git-fetch} from @code{(guix git-download)}
3120clone the Git version control repository, and check out the revision
3121specified in the @code{uri} field as a @code{git-reference} object; a
3122@code{git-reference} looks like this:
3123
3124@example
3125(git-reference
3126 (url "git://git.debian.org/git/pkg-shadow/shadow")
3127 (commit "v4.1.5.1"))
3128@end example
3129@end table
3130
3131@item @code{sha256}
3132A bytevector containing the SHA-256 hash of the source. Typically the
3133@code{base32} form is used here to generate the bytevector from a
3134base-32 string.
3135
db97a03a
LC
3136You can obtain this information using @code{guix download}
3137(@pxref{Invoking guix download}) or @code{guix hash} (@pxref{Invoking
3138guix hash}).
3139
87eafdbd
TUBK
3140@item @code{file-name} (default: @code{#f})
3141The file name under which the source code should be saved. When this is
3142@code{#f}, a sensible default value will be used in most cases. In case
3143the source is fetched from a URL, the file name from the URL will be
f97c9175 3144used. For version control checkouts, it is recommended to provide the
87eafdbd
TUBK
3145file name explicitly because the default is not very descriptive.
3146
3147@item @code{patches} (default: @code{'()})
3148A list of file names containing patches to be applied to the source.
3149
0dfebdaa
LC
3150This list of patches must be unconditional. In particular, it cannot
3151depend on the value of @code{%current-system} or
3152@code{%current-target-system}.
3153
87eafdbd 3154@item @code{snippet} (default: @code{#f})
1929fdba
LC
3155A G-expression (@pxref{G-Expressions}) or S-expression that will be run
3156in the source directory. This is a convenient way to modify the source,
3157sometimes more convenient than a patch.
87eafdbd
TUBK
3158
3159@item @code{patch-flags} (default: @code{'("-p1")})
3160A list of command-line flags that should be passed to the @code{patch}
3161command.
3162
3163@item @code{patch-inputs} (default: @code{#f})
3164Input packages or derivations to the patching process. When this is
3165@code{#f}, the usual set of inputs necessary for patching are provided,
3166such as GNU@tie{}Patch.
3167
3168@item @code{modules} (default: @code{'()})
3169A list of Guile modules that should be loaded during the patching
3170process and while running the code in the @code{snippet} field.
3171
87eafdbd
TUBK
3172@item @code{patch-guile} (default: @code{#f})
3173The Guile package that should be used in the patching process. When
3174this is @code{#f}, a sensible default is used.
3175@end table
3176@end deftp
3177
9c1edabd 3178
7458bd0a
LC
3179@node Build Systems
3180@section Build Systems
3181
3182@cindex build system
3183Each package definition specifies a @dfn{build system} and arguments for
3184that build system (@pxref{Defining Packages}). This @code{build-system}
f97c9175 3185field represents the build procedure of the package, as well as implicit
7458bd0a
LC
3186dependencies of that build procedure.
3187
3188Build systems are @code{<build-system>} objects. The interface to
3189create and manipulate them is provided by the @code{(guix build-system)}
3190module, and actual build systems are exported by specific modules.
3191
f5fd4fd2 3192@cindex bag (low-level package representation)
0d5a559f
LC
3193Under the hood, build systems first compile package objects to
3194@dfn{bags}. A @dfn{bag} is like a package, but with less
3195ornamentation---in other words, a bag is a lower-level representation of
3196a package, which includes all the inputs of that package, including some
3197that were implicitly added by the build system. This intermediate
3198representation is then compiled to a derivation (@pxref{Derivations}).
3199
7458bd0a
LC
3200Build systems accept an optional list of @dfn{arguments}. In package
3201definitions, these are passed @i{via} the @code{arguments} field
3202(@pxref{Defining Packages}). They are typically keyword arguments
3203(@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
3204Guile Reference Manual}). The value of these arguments is usually
3205evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
3206by the daemon (@pxref{Derivations}).
3207
3208The main build system is @var{gnu-build-system}, which implements the
f97c9175 3209standard build procedure for GNU and many other packages. It
7458bd0a
LC
3210is provided by the @code{(guix build-system gnu)} module.
3211
3212@defvr {Scheme Variable} gnu-build-system
3213@var{gnu-build-system} represents the GNU Build System, and variants
3214thereof (@pxref{Configuration, configuration and makefile conventions,,
3215standards, GNU Coding Standards}).
3216
3217@cindex build phases
f97c9175 3218In a nutshell, packages using it are configured, built, and installed with
7458bd0a
LC
3219the usual @code{./configure && make && make check && make install}
3220command sequence. In practice, a few additional steps are often needed.
3221All these steps are split up in separate @dfn{phases},
3222notably@footnote{Please see the @code{(guix build gnu-build-system)}
3223modules for more details about the build phases.}:
3224
3225@table @code
3226@item unpack
3227Unpack the source tarball, and change the current directory to the
3228extracted source tree. If the source is actually a directory, copy it
3229to the build tree, and enter that directory.
3230
3231@item patch-source-shebangs
3232Patch shebangs encountered in source files so they refer to the right
3233store file names. For instance, this changes @code{#!/bin/sh} to
3234@code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
3235
3236@item configure
3237Run the @file{configure} script with a number of default options, such
3238as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
3239by the @code{#:configure-flags} argument.
3240
3241@item build
3242Run @code{make} with the list of flags specified with
0917e80e 3243@code{#:make-flags}. If the @code{#:parallel-build?} argument is true
7458bd0a
LC
3244(the default), build with @code{make -j}.
3245
3246@item check
3247Run @code{make check}, or some other target specified with
3248@code{#:test-target}, unless @code{#:tests? #f} is passed. If the
3249@code{#:parallel-tests?} argument is true (the default), run @code{make
3250check -j}.
3251
3252@item install
3253Run @code{make install} with the flags listed in @code{#:make-flags}.
3254
3255@item patch-shebangs
3256Patch shebangs on the installed executable files.
3257
3258@item strip
3259Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
3260is false), copying them to the @code{debug} output when available
3261(@pxref{Installing Debugging Files}).
3262@end table
3263
3264@vindex %standard-phases
3265The build-side module @code{(guix build gnu-build-system)} defines
3266@var{%standard-phases} as the default list of build phases.
3267@var{%standard-phases} is a list of symbol/procedure pairs, where the
3268procedure implements the actual phase.
3269
3270The list of phases used for a particular package can be changed with the
3271@code{#:phases} parameter. For instance, passing:
3272
3273@example
c2c5dc79 3274#:phases (modify-phases %standard-phases (delete 'configure))
7458bd0a
LC
3275@end example
3276
9bf404e9 3277means that all the phases described above will be used, except the
7458bd0a
LC
3278@code{configure} phase.
3279
3280In addition, this build system ensures that the ``standard'' environment
3281for GNU packages is available. This includes tools such as GCC, libc,
3282Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
f97c9175
AE
3283build-system gnu)} module for a complete list). We call these the
3284@dfn{implicit inputs} of a package, because package definitions do not
7458bd0a
LC
3285have to mention them.
3286@end defvr
3287
3288Other @code{<build-system>} objects are defined to support other
3289conventions and tools used by free software packages. They inherit most
3290of @var{gnu-build-system}, and differ mainly in the set of inputs
3291implicitly added to the build process, and in the list of phases
3292executed. Some of these build systems are listed below.
3293
5f7a1a4d
RW
3294@defvr {Scheme Variable} ant-build-system
3295This variable is exported by @code{(guix build-system ant)}. It
3296implements the build procedure for Java packages that can be built with
3297@url{http://ant.apache.org/, Ant build tool}.
3298
3299It adds both @code{ant} and the @dfn{Java Development Kit} (JDK) as
3300provided by the @code{icedtea} package to the set of inputs. Different
3301packages can be specified with the @code{#:ant} and @code{#:jdk}
3302parameters, respectively.
3303
3304When the original package does not provide a suitable Ant build file,
3305the parameter @code{#:jar-name} can be used to generate a minimal Ant
3306build file @file{build.xml} with tasks to build the specified jar
3307archive.
3308
3309The parameter @code{#:build-target} can be used to specify the Ant task
3310that should be run during the @code{build} phase. By default the
3311``jar'' task will be run.
3312
3313@end defvr
3314
a1b30f99
AP
3315@defvr {Scheme Variable} asdf-build-system/source
3316@defvrx {Scheme Variable} asdf-build-system/sbcl
3317@defvrx {Scheme Variable} asdf-build-system/ecl
3318
3319These variables, exported by @code{(guix build-system asdf)}, implement
3320build procedures for Common Lisp packages using
3321@url{https://common-lisp.net/project/asdf/, ``ASDF''}. ASDF is a system
3322definition facility for Common Lisp programs and libraries.
3323
3324The @code{asdf-build-system/source} system installs the packages in
3325source form, and can be loaded using any common lisp implementation, via
3326ASDF. The others, such as @code{asdf-build-system/sbcl}, install binary
3327systems in the format which a particular implementation understands.
3328These build systems can also be used to produce executable programs, or
3329lisp images which contain a set of packages pre-loaded.
3330
3331The build system uses naming conventions. For binary packages, the
3332package itself as well as its run-time dependencies should begin their
3333name with the lisp implementation, such as @code{sbcl-} for
3334@code{asdf-build-system/sbcl}. Beginning the input name with this
3335prefix will allow the build system to encode its location into the
3336resulting library, so that the input can be found at run-time.
3337
3338If dependencies are used only for tests, it is convenient to use a
3339different prefix in order to avoid having a run-time dependency on such
3340systems. For example,
3341
3342@example
3343(define-public sbcl-bordeaux-threads
3344 (package
3345 ...
3346 (native-inputs `(("tests:cl-fiveam" ,sbcl-fiveam)))
3347 ...))
3348@end example
3349
3350Additionally, the corresponding source package should be labeled using
3351the same convention as python packages (see @ref{Python Modules}), using
3352the @code{cl-} prefix.
3353
3354For binary packages, each system should be defined as a Guix package.
3355If one package @code{origin} contains several systems, package variants
3356can be created in order to build all the systems. Source packages,
3357which use @code{asdf-build-system/source}, may contain several systems.
3358
3359In order to create executable programs and images, the build-side
3360procedures @code{build-program} and @code{build-image} can be used.
3361They should be called in a build phase after the @code{create-symlinks}
3362phase, so that the system which was just built can be used within the
3363resulting image. @code{build-program} requires a list of Common Lisp
3364expressions to be passed as the @code{#:entry-program} argument.
3365
3366If the system is not defined within its own @code{.asd} file of the same
3367name, then the @code{#:asd-file} parameter should be used to specify
3368which file the system is defined in.
3369
3370@end defvr
3371
1ec34dd7
LC
3372@defvr {Scheme Variable} cargo-build-system
3373@cindex Rust programming language
3374@cindex Cargo (Rust build system)
3375This variable is exported by @code{(guix build-system cargo)}. It
3376supports builds of packages using Cargo, the build tool of the
3377@uref{https://www.rust-lang.org, Rust programming language}.
3378
3379In its @code{configure} phase, this build system replaces dependencies
3380specified in the @file{Carto.toml} file with inputs to the Guix package.
3381The @code{install} phase installs the binaries, and it also installs the
3382source code and @file{Cargo.toml} file.
3383@end defvr
3384
7458bd0a
LC
3385@defvr {Scheme Variable} cmake-build-system
3386This variable is exported by @code{(guix build-system cmake)}. It
3387implements the build procedure for packages using the
3388@url{http://www.cmake.org, CMake build tool}.
3389
3390It automatically adds the @code{cmake} package to the set of inputs.
3391Which package is used can be specified with the @code{#:cmake}
3392parameter.
9849cfc1
LC
3393
3394The @code{#:configure-flags} parameter is taken as a list of flags
3395passed to the @command{cmake} command. The @code{#:build-type}
3396parameter specifies in abstract terms the flags passed to the compiler;
3397it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
3398debugging information''), which roughly means that code is compiled with
3399@code{-O2 -g}, as is the case for Autoconf-based packages by default.
7458bd0a
LC
3400@end defvr
3401
3afcf52b
FB
3402@defvr {Scheme Variable} glib-or-gtk-build-system
3403This variable is exported by @code{(guix build-system glib-or-gtk)}. It
3404is intended for use with packages making use of GLib or GTK+.
3405
3406This build system adds the following two phases to the ones defined by
3407@var{gnu-build-system}:
3408
3409@table @code
3410@item glib-or-gtk-wrap
f97c9175
AE
3411The phase @code{glib-or-gtk-wrap} ensures that programs in
3412@file{bin/} are able to find GLib ``schemas'' and
3afcf52b
FB
3413@uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
3414modules}. This is achieved by wrapping the programs in launch scripts
3415that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
3416environment variables.
3417
73aa8ddb
LC
3418It is possible to exclude specific package outputs from that wrapping
3419process by listing their names in the
3420@code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
3421when an output is known not to contain any GLib or GTK+ binaries, and
3422where wrapping would gratuitously add a dependency of that output on
3423GLib and GTK+.
3424
3afcf52b 3425@item glib-or-gtk-compile-schemas
f97c9175 3426The phase @code{glib-or-gtk-compile-schemas} makes sure that all
3afcf52b 3427@uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
f97c9175 3428GSettings schemas} of GLib are compiled. Compilation is performed by the
3afcf52b
FB
3429@command{glib-compile-schemas} program. It is provided by the package
3430@code{glib:bin} which is automatically imported by the build system.
3431The @code{glib} package providing @command{glib-compile-schemas} can be
3432specified with the @code{#:glib} parameter.
3433@end table
3434
3435Both phases are executed after the @code{install} phase.
3436@end defvr
3437
3184f14a 3438@defvr {Scheme Variable} ocaml-build-system
9fc221b5 3439This variable is exported by @code{(guix build-system ocaml)}. It implements
3184f14a
JL
3440a build procedure for @uref{https://ocaml.org, OCaml} packages, which consists
3441of choosing the correct set of commands to run for each package. OCaml
3442packages can expect many different commands to be run. This build system will
3443try some of them.
3444
3445When the package has a @file{setup.ml} file present at the top-level, it will
3446run @code{ocaml setup.ml -configure}, @code{ocaml setup.ml -build} and
3447@code{ocaml setup.ml -install}. The build system will assume that this file
3448was generated by @uref{http://oasis.forge.ocamlcore.org/, OASIS} and will take
3449care of setting the prefix and enabling tests if they are not disabled. You
3450can pass configure and build flags with the @code{#:configure-flags} and
3451@code{#:build-flags}. The @code{#:test-flags} key can be passed to change the
3452set of flags used to enable tests. The @code{#:use-make?} key can be used to
3453bypass this system in the build and install phases.
3454
3455When the package has a @file{configure} file, it is assumed that it is a
3456hand-made configure script that requires a different argument format than
3457in the @code{gnu-build-system}. You can add more flags with the
3458@code{#:configure-flags} key.
3459
3460When the package has a @file{Makefile} file (or @code{#:use-make?} is
3461@code{#t}), it will be used and more flags can be passed to the build and
3462install phases with the @code{#:make-flags} key.
3463
3464Finally, some packages do not have these files and use a somewhat standard
3465location for its build system. In that case, the build system will run
3466@code{ocaml pkg/pkg.ml} or @code{ocaml pkg/build.ml} and take care of
3467providing the path to the required findlib module. Additional flags can
3468be passed via the @code{#:build-flags} key. Install is taken care of by
3469@command{opam-installer}. In this case, the @code{opam} package must
3470be added to the @code{native-inputs} field of the package definition.
3471
3472Note that most OCaml packages assume they will be installed in the same
88ba7852 3473directory as OCaml, which is not what we want in guix. In particular, they
3184f14a 3474will install @file{.so} files in their module's directory, which is usually
88ba7852 3475fine because it is in the OCaml compiler directory. In guix though, these
3184f14a
JL
3476libraries cannot be found and we use @code{CAML_LD_LIBRARY_PATH}. This
3477variable points to @file{lib/ocaml/site-lib/stubslibs} and this is where
3478@file{.so} libraries should be installed.
3479@end defvr
3480
7458bd0a
LC
3481@defvr {Scheme Variable} python-build-system
3482This variable is exported by @code{(guix build-system python)}. It
3483implements the more or less standard build procedure used by Python
3484packages, which consists in running @code{python setup.py build} and
3485then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
3486
3487For packages that install stand-alone Python programs under @code{bin/},
f97c9175 3488it takes care of wrapping these programs so that their @code{PYTHONPATH}
7458bd0a
LC
3489environment variable points to all the Python libraries they depend on.
3490
8a46205b
CM
3491Which Python package is used to perform the build can be specified with
3492the @code{#:python} parameter. This is a useful way to force a package
3493to be built for a specific version of the Python interpreter, which
3494might be necessary if the package is only compatible with a single
3495interpreter version.
5f7565d1
HG
3496
3497By default guix calls @code{setup.py} under control of
3498@code{setuptools}, much like @command{pip} does. Some packages are not
3499compatible with setuptools (and pip), thus you can disable this by
3500setting the @code{#:use-setuptools} parameter to @code{#f}.
7458bd0a
LC
3501@end defvr
3502
3503@defvr {Scheme Variable} perl-build-system
3504This variable is exported by @code{(guix build-system perl)}. It
2d2a53fc
EB
3505implements the standard build procedure for Perl packages, which either
3506consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
3507followed by @code{Build} and @code{Build install}; or in running
3508@code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
f97c9175 3509@code{make} and @code{make install}, depending on which of
2d2a53fc
EB
3510@code{Build.PL} or @code{Makefile.PL} is present in the package
3511distribution. Preference is given to the former if both @code{Build.PL}
3512and @code{Makefile.PL} exist in the package distribution. This
3513preference can be reversed by specifying @code{#t} for the
3514@code{#:make-maker?} parameter.
3515
3516The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
3517passes flags specified by the @code{#:make-maker-flags} or
3518@code{#:module-build-flags} parameter, respectively.
7458bd0a
LC
3519
3520Which Perl package is used can be specified with @code{#:perl}.
3521@end defvr
3522
f8f3bef6
RW
3523@defvr {Scheme Variable} r-build-system
3524This variable is exported by @code{(guix build-system r)}. It
3525implements the build procedure used by @uref{http://r-project.org, R}
3526packages, which essentially is little more than running @code{R CMD
3527INSTALL --library=/gnu/store/@dots{}} in an environment where
3528@code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
3529are run after installation using the R function
3530@code{tools::testInstalledPackage}.
3531@end defvr
3532
c08f9818
DT
3533@defvr {Scheme Variable} ruby-build-system
3534This variable is exported by @code{(guix build-system ruby)}. It
3535implements the RubyGems build procedure used by Ruby packages, which
3536involves running @code{gem build} followed by @code{gem install}.
3537
5dc87623
DT
3538The @code{source} field of a package that uses this build system
3539typically references a gem archive, since this is the format that Ruby
3540developers use when releasing their software. The build system unpacks
3541the gem archive, potentially patches the source, runs the test suite,
3542repackages the gem, and installs it. Additionally, directories and
3543tarballs may be referenced to allow building unreleased gems from Git or
3544a traditional source release tarball.
e83c6d00 3545
c08f9818 3546Which Ruby package is used can be specified with the @code{#:ruby}
6e9f2913
PP
3547parameter. A list of additional flags to be passed to the @command{gem}
3548command can be specified with the @code{#:gem-flags} parameter.
c08f9818 3549@end defvr
7458bd0a 3550
a677c726
RW
3551@defvr {Scheme Variable} waf-build-system
3552This variable is exported by @code{(guix build-system waf)}. It
3553implements a build procedure around the @code{waf} script. The common
3554phases---@code{configure}, @code{build}, and @code{install}---are
3555implemented by passing their names as arguments to the @code{waf}
3556script.
3557
3558The @code{waf} script is executed by the Python interpreter. Which
3559Python package is used to run the script can be specified with the
3560@code{#:python} parameter.
3561@end defvr
3562
14dfdf2e
FB
3563@defvr {Scheme Variable} haskell-build-system
3564This variable is exported by @code{(guix build-system haskell)}. It
3565implements the Cabal build procedure used by Haskell packages, which
3566involves running @code{runhaskell Setup.hs configure
3567--prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
3568Instead of installing the package by running @code{runhaskell Setup.hs
3569install}, to avoid trying to register libraries in the read-only
3570compiler store directory, the build system uses @code{runhaskell
3571Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
3572addition, the build system generates the package documentation by
3573running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
3574is passed. Optional Haddock parameters can be passed with the help of
3575the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
3576not found, the build system looks for @code{Setup.lhs} instead.
3577
3578Which Haskell compiler is used can be specified with the @code{#:haskell}
a54bd6d7 3579parameter which defaults to @code{ghc}.
14dfdf2e
FB
3580@end defvr
3581
65e862d1
DM
3582@defvr {Scheme Variable} dub-build-system
3583This variable is exported by @code{(guix build-system dub)}. It
3584implements the Dub build procedure used by D packages, which
3585involves running @code{dub build} and @code{dub run}.
3586Installation is done by copying the files manually.
3587
3588Which D compiler is used can be specified with the @code{#:ldc}
3589parameter which defaults to @code{ldc}.
3590@end defvr
3591
e9137a53
FB
3592@defvr {Scheme Variable} emacs-build-system
3593This variable is exported by @code{(guix build-system emacs)}. It
f97c9175
AE
3594implements an installation procedure similar to the packaging system
3595of Emacs itself (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
e9137a53
FB
3596
3597It first creates the @code{@var{package}-autoloads.el} file, then it
3598byte compiles all Emacs Lisp files. Differently from the Emacs
3599packaging system, the Info documentation files are moved to the standard
3600documentation directory and the @file{dir} file is deleted. Each
3601package is installed in its own directory under
3602@file{share/emacs/site-lisp/guix.d}.
3603@end defvr
3604
7458bd0a
LC
3605Lastly, for packages that do not need anything as sophisticated, a
3606``trivial'' build system is provided. It is trivial in the sense that
3607it provides basically no support: it does not pull any implicit inputs,
3608and does not have a notion of build phases.
3609
3610@defvr {Scheme Variable} trivial-build-system
3611This variable is exported by @code{(guix build-system trivial)}.
3612
3613This build system requires a @code{#:builder} argument. This argument
f97c9175 3614must be a Scheme expression that builds the package output(s)---as
7458bd0a
LC
3615with @code{build-expression->derivation} (@pxref{Derivations,
3616@code{build-expression->derivation}}).
3617@end defvr
3618
568717fd
LC
3619@node The Store
3620@section The Store
3621
e531ac2a 3622@cindex store
1ddee424 3623@cindex store items
e531ac2a
LC
3624@cindex store paths
3625
f97c9175
AE
3626Conceptually, the @dfn{store} is the place where derivations that have
3627been built successfully are stored---by default, @file{/gnu/store}.
1ddee424
LC
3628Sub-directories in the store are referred to as @dfn{store items} or
3629sometimes @dfn{store paths}. The store has an associated database that
3630contains information such as the store paths referred to by each store
3631path, and the list of @emph{valid} store items---results of successful
ef5f5c86
LC
3632builds. This database resides in @file{@var{localstatedir}/guix/db},
3633where @var{localstatedir} is the state directory specified @i{via}
3634@option{--localstatedir} at configure time, usually @file{/var}.
1ddee424
LC
3635
3636The store is @emph{always} accessed by the daemon on behalf of its clients
e531ac2a 3637(@pxref{Invoking guix-daemon}). To manipulate the store, clients
f97c9175
AE
3638connect to the daemon over a Unix-domain socket, send requests to it,
3639and read the result---these are remote procedure calls, or RPCs.
e531ac2a 3640
1ddee424
LC
3641@quotation Note
3642Users must @emph{never} modify files under @file{/gnu/store} directly.
3643This would lead to inconsistencies and break the immutability
3644assumptions of Guix's functional model (@pxref{Introduction}).
3645
3646@xref{Invoking guix gc, @command{guix gc --verify}}, for information on
3647how to check the integrity of the store and attempt recovery from
3648accidental modifications.
3649@end quotation
3650
e531ac2a
LC
3651The @code{(guix store)} module provides procedures to connect to the
3652daemon, and to perform RPCs. These are described below.
3653
3654@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
3655Connect to the daemon over the Unix-domain socket at @var{file}. When
3656@var{reserve-space?} is true, instruct it to reserve a little bit of
3657extra space on the file system so that the garbage collector can still
f97c9175 3658operate should the disk become full. Return a server object.
e531ac2a
LC
3659
3660@var{file} defaults to @var{%default-socket-path}, which is the normal
3661location given the options that were passed to @command{configure}.
3662@end deffn
3663
3664@deffn {Scheme Procedure} close-connection @var{server}
3665Close the connection to @var{server}.
3666@end deffn
3667
3668@defvr {Scheme Variable} current-build-output-port
3669This variable is bound to a SRFI-39 parameter, which refers to the port
3670where build and error logs sent by the daemon should be written.
3671@end defvr
3672
3673Procedures that make RPCs all take a server object as their first
3674argument.
3675
3676@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
06b76acc
LC
3677@cindex invalid store items
3678Return @code{#t} when @var{path} designates a valid store item and
3679@code{#f} otherwise (an invalid item may exist on disk but still be
3680invalid, for instance because it is the result of an aborted or failed
3681build.)
3682
3683A @code{&nix-protocol-error} condition is raised if @var{path} is not
3684prefixed by the store directory (@file{/gnu/store}).
e531ac2a
LC
3685@end deffn
3686
cfbf9160 3687@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
3688Add @var{text} under file @var{name} in the store, and return its store
3689path. @var{references} is the list of store paths referred to by the
3690resulting store path.
3691@end deffn
3692
874e6874 3693@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
3694Build @var{derivations} (a list of @code{<derivation>} objects or
3695derivation paths), and return when the worker is done building them.
3696Return @code{#t} on success.
874e6874
LC
3697@end deffn
3698
b860f382
LC
3699Note that the @code{(guix monads)} module provides a monad as well as
3700monadic versions of the above procedures, with the goal of making it
3701more convenient to work with code that accesses the store (@pxref{The
3702Store Monad}).
3703
e531ac2a
LC
3704@c FIXME
3705@i{This section is currently incomplete.}
568717fd
LC
3706
3707@node Derivations
3708@section Derivations
3709
874e6874
LC
3710@cindex derivations
3711Low-level build actions and the environment in which they are performed
70458ed5 3712are represented by @dfn{derivations}. A derivation contains the
874e6874
LC
3713following pieces of information:
3714
3715@itemize
3716@item
3717The outputs of the derivation---derivations produce at least one file or
3718directory in the store, but may produce more.
3719
3720@item
3721The inputs of the derivations, which may be other derivations or plain
3722files in the store (patches, build scripts, etc.)
3723
3724@item
3725The system type targeted by the derivation---e.g., @code{x86_64-linux}.
3726
3727@item
3728The file name of a build script in the store, along with the arguments
3729to be passed.
3730
3731@item
3732A list of environment variables to be defined.
3733
3734@end itemize
3735
3736@cindex derivation path
3737Derivations allow clients of the daemon to communicate build actions to
3738the store. They exist in two forms: as an in-memory representation,
3739both on the client- and daemon-side, and as files in the store whose
3740name end in @code{.drv}---these files are referred to as @dfn{derivation
3741paths}. Derivations paths can be passed to the @code{build-derivations}
3742procedure to perform the build actions they prescribe (@pxref{The
3743Store}).
3744
3745The @code{(guix derivations)} module provides a representation of
3746derivations as Scheme objects, along with procedures to create and
3747otherwise manipulate derivations. The lowest-level primitive to create
3748a derivation is the @code{derivation} procedure:
3749
1909431c
LC
3750@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
3751 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 3752 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c 3753 [#:system (%current-system)] [#:references-graphs #f] @
35b5ca78
LC
3754 [#:allowed-references #f] [#:disallowed-references #f] @
3755 [#:leaked-env-vars #f] [#:local-build? #f] @
4a6aeb67 3756 [#:substitutable? #t]
59688fc4
LC
3757Build a derivation with the given arguments, and return the resulting
3758@code{<derivation>} object.
874e6874 3759
2096ef47 3760When @var{hash} and @var{hash-algo} are given, a
874e6874 3761@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
3762known in advance, such as a file download. If, in addition,
3763@var{recursive?} is true, then that fixed output may be an executable
3764file or a directory and @var{hash} must be the hash of an archive
3765containing this output.
5b0c9d16 3766
858e9282 3767When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
3768name/store path pairs. In that case, the reference graph of each store
3769path is exported in the build environment in the corresponding file, in
3770a simple text format.
1909431c 3771
b53be755 3772When @var{allowed-references} is true, it must be a list of store items
35b5ca78
LC
3773or outputs that the derivation's output may refer to. Likewise,
3774@var{disallowed-references}, if true, must be a list of things the
3775outputs may @emph{not} refer to.
b53be755 3776
c0468155
LC
3777When @var{leaked-env-vars} is true, it must be a list of strings
3778denoting environment variables that are allowed to ``leak'' from the
3779daemon's environment to the build environment. This is only applicable
3780to fixed-output derivations---i.e., when @var{hash} is true. The main
3781use is to allow variables such as @code{http_proxy} to be passed to
3782derivations that download files.
3783
1909431c
LC
3784When @var{local-build?} is true, declare that the derivation is not a
3785good candidate for offloading and should rather be built locally
3786(@pxref{Daemon Offload Setup}). This is the case for small derivations
3787where the costs of data transfers would outweigh the benefits.
4a6aeb67
LC
3788
3789When @var{substitutable?} is false, declare that substitutes of the
3790derivation's output should not be used (@pxref{Substitutes}). This is
3791useful, for instance, when building packages that capture details of the
3792host CPU instruction set.
874e6874
LC
3793@end deffn
3794
3795@noindent
3796Here's an example with a shell script as its builder, assuming
3797@var{store} is an open connection to the daemon, and @var{bash} points
3798to a Bash executable in the store:
3799
3800@lisp
3801(use-modules (guix utils)
3802 (guix store)
3803 (guix derivations))
3804
59688fc4
LC
3805(let ((builder ; add the Bash script to the store
3806 (add-text-to-store store "my-builder.sh"
3807 "echo hello world > $out\n" '())))
3808 (derivation store "foo"
3809 bash `("-e" ,builder)
21b679f6 3810 #:inputs `((,bash) (,builder))
59688fc4 3811 #:env-vars '(("HOME" . "/homeless"))))
834129e0 3812@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
3813@end lisp
3814
21b679f6
LC
3815As can be guessed, this primitive is cumbersome to use directly. A
3816better approach is to write build scripts in Scheme, of course! The
3817best course of action for that is to write the build code as a
3818``G-expression'', and to pass it to @code{gexp->derivation}. For more
6621cdb6 3819information, @pxref{G-Expressions}.
21b679f6 3820
f2fadbc1
AE
3821Once upon a time, @code{gexp->derivation} did not exist and constructing
3822derivations with build code written in Scheme was achieved with
3823@code{build-expression->derivation}, documented below. This procedure
3824is now deprecated in favor of the much nicer @code{gexp->derivation}.
3825
3826@deffn {Scheme Procedure} build-expression->derivation @var{store} @
3827 @var{name} @var{exp} @
3828 [#:system (%current-system)] [#:inputs '()] @
3829 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3830 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3831 [#:references-graphs #f] [#:allowed-references #f] @
35b5ca78 3832 [#:disallowed-references #f] @
f2fadbc1
AE
3833 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3834Return a derivation that executes Scheme expression @var{exp} as a
3835builder for derivation @var{name}. @var{inputs} must be a list of
3836@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
3837@code{"out"} is assumed. @var{modules} is a list of names of Guile
3838modules from the current search path to be copied in the store,
3839compiled, and made available in the load path during the execution of
3840@var{exp}---e.g., @code{((guix build utils) (guix build
3841gnu-build-system))}.
3842
3843@var{exp} is evaluated in an environment where @code{%outputs} is bound
3844to a list of output/path pairs, and where @code{%build-inputs} is bound
3845to a list of string/output-path pairs made from @var{inputs}.
3846Optionally, @var{env-vars} is a list of string pairs specifying the name
3847and value of environment variables visible to the builder. The builder
3848terminates by passing the result of @var{exp} to @code{exit}; thus, when
3849@var{exp} returns @code{#f}, the build is considered to have failed.
3850
3851@var{exp} is built using @var{guile-for-build} (a derivation). When
3852@var{guile-for-build} is omitted or is @code{#f}, the value of the
3853@code{%guile-for-build} fluid is used instead.
3854
3855See the @code{derivation} procedure for the meaning of
35b5ca78
LC
3856@var{references-graphs}, @var{allowed-references},
3857@var{disallowed-references}, @var{local-build?}, and
3858@var{substitutable?}.
f2fadbc1
AE
3859@end deffn
3860
3861@noindent
3862Here's an example of a single-output derivation that creates a directory
3863containing one file:
3864
3865@lisp
3866(let ((builder '(let ((out (assoc-ref %outputs "out")))
3867 (mkdir out) ; create /gnu/store/@dots{}-goo
3868 (call-with-output-file (string-append out "/test")
3869 (lambda (p)
3870 (display '(hello guix) p))))))
3871 (build-expression->derivation store "goo" builder))
3872
3873@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
3874@end lisp
3875
568717fd 3876
b860f382
LC
3877@node The Store Monad
3878@section The Store Monad
3879
3880@cindex monad
3881
3882The procedures that operate on the store described in the previous
3883sections all take an open connection to the build daemon as their first
3884argument. Although the underlying model is functional, they either have
3885side effects or depend on the current state of the store.
3886
3887The former is inconvenient: the connection to the build daemon has to be
3888carried around in all those functions, making it impossible to compose
3889functions that do not take that parameter with functions that do. The
3890latter can be problematic: since store operations have side effects
3891and/or depend on external state, they have to be properly sequenced.
3892
3893@cindex monadic values
3894@cindex monadic functions
3895This is where the @code{(guix monads)} module comes in. This module
3896provides a framework for working with @dfn{monads}, and a particularly
3897useful monad for our uses, the @dfn{store monad}. Monads are a
3898construct that allows two things: associating ``context'' with values
3899(in our case, the context is the store), and building sequences of
4827b36d 3900computations (here computations include accesses to the store). Values
b860f382
LC
3901in a monad---values that carry this additional context---are called
3902@dfn{monadic values}; procedures that return such values are called
3903@dfn{monadic procedures}.
3904
3905Consider this ``normal'' procedure:
3906
3907@example
45adbd62
LC
3908(define (sh-symlink store)
3909 ;; Return a derivation that symlinks the 'bash' executable.
3910 (let* ((drv (package-derivation store bash))
3911 (out (derivation->output-path drv))
3912 (sh (string-append out "/bin/bash")))
3913 (build-expression->derivation store "sh"
3914 `(symlink ,sh %output))))
b860f382
LC
3915@end example
3916
c6f30b81
LC
3917Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3918as a monadic function:
b860f382
LC
3919
3920@example
45adbd62 3921(define (sh-symlink)
b860f382 3922 ;; Same, but return a monadic value.
c6f30b81
LC
3923 (mlet %store-monad ((drv (package->derivation bash)))
3924 (gexp->derivation "sh"
3925 #~(symlink (string-append #$drv "/bin/bash")
3926 #$output))))
b860f382
LC
3927@end example
3928
4827b36d 3929There are several things to note in the second version: the @code{store}
c6f30b81
LC
3930parameter is now implicit and is ``threaded'' in the calls to the
3931@code{package->derivation} and @code{gexp->derivation} monadic
3932procedures, and the monadic value returned by @code{package->derivation}
3933is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3934
3935As it turns out, the call to @code{package->derivation} can even be
3936omitted since it will take place implicitly, as we will see later
3937(@pxref{G-Expressions}):
3938
3939@example
3940(define (sh-symlink)
3941 (gexp->derivation "sh"
3942 #~(symlink (string-append #$bash "/bin/bash")
3943 #$output)))
3944@end example
b860f382 3945
7ce21611 3946@c See
a01ad638 3947@c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
7ce21611
LC
3948@c for the funny quote.
3949Calling the monadic @code{sh-symlink} has no effect. As someone once
3950said, ``you exit a monad like you exit a building on fire: by running''.
3951So, to exit the monad and get the desired effect, one must use
3952@code{run-with-store}:
b860f382
LC
3953
3954@example
8e9aa37f
CAW
3955(run-with-store (open-connection) (sh-symlink))
3956@result{} /gnu/store/...-sh-symlink
b860f382
LC
3957@end example
3958
f97c9175 3959Note that the @code{(guix monad-repl)} module extends the Guile REPL with
b9b86078 3960new ``meta-commands'' to make it easier to deal with monadic procedures:
f97c9175 3961@code{run-in-store}, and @code{enter-store-monad}. The former is used
b9b86078
LC
3962to ``run'' a single monadic value through the store:
3963
3964@example
3965scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3966$1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3967@end example
3968
3969The latter enters a recursive REPL, where all the return values are
3970automatically run through the store:
3971
3972@example
3973scheme@@(guile-user)> ,enter-store-monad
3974store-monad@@(guile-user) [1]> (package->derivation hello)
3975$2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3976store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3977$3 = "/gnu/store/@dots{}-foo"
3978store-monad@@(guile-user) [1]> ,q
3979scheme@@(guile-user)>
3980@end example
3981
3982@noindent
3983Note that non-monadic values cannot be returned in the
3984@code{store-monad} REPL.
3985
e87f0591
LC
3986The main syntactic forms to deal with monads in general are provided by
3987the @code{(guix monads)} module and are described below.
b860f382
LC
3988
3989@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3990Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3991in @var{monad}.
3992@end deffn
3993
3994@deffn {Scheme Syntax} return @var{val}
3995Return a monadic value that encapsulates @var{val}.
3996@end deffn
3997
751630c9 3998@deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
b860f382 3999@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
751630c9
LC
4000procedures @var{mproc}@dots{}@footnote{This operation is commonly
4001referred to as ``bind'', but that name denotes an unrelated procedure in
4002Guile. Thus we use this somewhat cryptic symbol inherited from the
4003Haskell language.}. There can be one @var{mproc} or several of them, as
4004in this example:
4005
4006@example
4007(run-with-state
4008 (with-monad %state-monad
4009 (>>= (return 1)
4010 (lambda (x) (return (+ 1 x)))
4011 (lambda (x) (return (* 2 x)))))
4012 'some-state)
4013
4014@result{} 4
4015@result{} some-state
4016@end example
b860f382
LC
4017@end deffn
4018
4019@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
4020 @var{body} ...
4021@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
4022 @var{body} ...
4023Bind the variables @var{var} to the monadic values @var{mval} in
4024@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
4025``normal'' value @var{val}, as per @code{let}.
4026
4027@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
4028(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
4029@end deffn
4030
405a9d4e
LC
4031@deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
4032Bind @var{mexp} and the following monadic expressions in sequence,
4033returning the result of the last expression.
4034
4035This is akin to @code{mlet}, except that the return values of the
4036monadic expressions are ignored. In that sense, it is analogous to
4037@code{begin}, but applied to monadic expressions.
4038@end deffn
4039
561fb6c3
LC
4040@cindex state monad
4041The @code{(guix monads)} module provides the @dfn{state monad}, which
4042allows an additional value---the state---to be @emph{threaded} through
4043monadic procedure calls.
4044
4045@defvr {Scheme Variable} %state-monad
4046The state monad. Procedures in the state monad can access and change
4047the state that is threaded.
4048
4049Consider the example below. The @code{square} procedure returns a value
4050in the state monad. It returns the square of its argument, but also
4051increments the current state value:
4052
4053@example
4054(define (square x)
4055 (mlet %state-monad ((count (current-state)))
4056 (mbegin %state-monad
4057 (set-current-state (+ 1 count))
4058 (return (* x x)))))
4059
4060(run-with-state (sequence %state-monad (map square (iota 3))) 0)
4061@result{} (0 1 4)
4062@result{} 3
4063@end example
4064
4065When ``run'' through @var{%state-monad}, we obtain that additional state
4066value, which is the number of @code{square} calls.
4067@end defvr
4068
4069@deffn {Monadic Procedure} current-state
4070Return the current state as a monadic value.
4071@end deffn
4072
4073@deffn {Monadic Procedure} set-current-state @var{value}
4074Set the current state to @var{value} and return the previous state as a
4075monadic value.
4076@end deffn
4077
4078@deffn {Monadic Procedure} state-push @var{value}
4079Push @var{value} to the current state, which is assumed to be a list,
4080and return the previous state as a monadic value.
4081@end deffn
4082
4083@deffn {Monadic Procedure} state-pop
4084Pop a value from the current state and return it as a monadic value.
4085The state is assumed to be a list.
4086@end deffn
4087
4088@deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
4089Run monadic value @var{mval} starting with @var{state} as the initial
4090state. Return two values: the resulting value, and the resulting state.
4091@end deffn
4092
e87f0591
LC
4093The main interface to the store monad, provided by the @code{(guix
4094store)} module, is as follows.
b860f382
LC
4095
4096@defvr {Scheme Variable} %store-monad
561fb6c3
LC
4097The store monad---an alias for @var{%state-monad}.
4098
4099Values in the store monad encapsulate accesses to the store. When its
4100effect is needed, a value of the store monad must be ``evaluated'' by
4101passing it to the @code{run-with-store} procedure (see below.)
b860f382
LC
4102@end defvr
4103
4104@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
4105Run @var{mval}, a monadic value in the store monad, in @var{store}, an
4106open store connection.
4107@end deffn
4108
ad372953 4109@deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
b860f382 4110Return as a monadic value the absolute file name in the store of the file
ad372953
LC
4111containing @var{text}, a string. @var{references} is a list of store items that the
4112resulting text file refers to; it defaults to the empty list.
45adbd62
LC
4113@end deffn
4114
0a90af15 4115@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
1ec32f4a 4116 [#:recursive? #t] [#:select? (const #t)]
0a90af15
LC
4117Return the name of @var{file} once interned in the store. Use
4118@var{name} as its store name, or the basename of @var{file} if
4119@var{name} is omitted.
4120
4121When @var{recursive?} is true, the contents of @var{file} are added
4122recursively; if @var{file} designates a flat file and @var{recursive?}
4123is true, its contents are added, and its permission bits are kept.
4124
1ec32f4a
LC
4125When @var{recursive?} is true, call @code{(@var{select?} @var{file}
4126@var{stat})} for each directory entry, where @var{file} is the entry's
4127absolute file name and @var{stat} is the result of @code{lstat}; exclude
4128entries for which @var{select?} does not return true.
4129
0a90af15
LC
4130The example below adds a file to the store, under two different names:
4131
4132@example
4133(run-with-store (open-connection)
4134 (mlet %store-monad ((a (interned-file "README"))
4135 (b (interned-file "README" "LEGU-MIN")))
4136 (return (list a b))))
4137
4138@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
4139@end example
4140
4141@end deffn
4142
e87f0591
LC
4143The @code{(guix packages)} module exports the following package-related
4144monadic procedures:
4145
b860f382 4146@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4231f05b 4147 [#:system (%current-system)] [#:target #f] @
f97c9175
AE
4148 [#:output "out"]
4149Return as a monadic
b860f382
LC
4150value in the absolute file name of @var{file} within the @var{output}
4151directory of @var{package}. When @var{file} is omitted, return the name
4231f05b
LC
4152of the @var{output} directory of @var{package}. When @var{target} is
4153true, use it as a cross-compilation target triplet.
b860f382
LC
4154@end deffn
4155
b860f382 4156@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4231f05b
LC
4157@deffnx {Monadic Procedure} package->cross-derivation @var{package} @
4158 @var{target} [@var{system}]
4159Monadic version of @code{package-derivation} and
4160@code{package-cross-derivation} (@pxref{Defining Packages}).
b860f382
LC
4161@end deffn
4162
4163
21b679f6
LC
4164@node G-Expressions
4165@section G-Expressions
4166
4167@cindex G-expression
4168@cindex build code quoting
4169So we have ``derivations'', which represent a sequence of build actions
4170to be performed to produce an item in the store (@pxref{Derivations}).
f97c9175 4171These build actions are performed when asking the daemon to actually
21b679f6
LC
4172build the derivations; they are run by the daemon in a container
4173(@pxref{Invoking guix-daemon}).
4174
4175@cindex strata of code
f97c9175 4176It should come as no surprise that we like to write these build actions
21b679f6
LC
4177in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
4178code@footnote{The term @dfn{stratum} in this context was coined by
ef4ab0a4
LC
4179Manuel Serrano et al.@: in the context of their work on Hop. Oleg
4180Kiselyov, who has written insightful
4181@url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
4182on this topic}, refers to this kind of code generation as
4183@dfn{staging}.}: the ``host code''---code that defines packages, talks
4184to the daemon, etc.---and the ``build code''---code that actually
4185performs build actions, such as making directories, invoking
4186@command{make}, etc.
21b679f6
LC
4187
4188To describe a derivation and its build actions, one typically needs to
4189embed build code inside host code. It boils down to manipulating build
f97c9175 4190code as data, and the homoiconicity of Scheme---code has a direct
21b679f6 4191representation as data---comes in handy for that. But we need more than
f97c9175 4192the normal @code{quasiquote} mechanism in Scheme to construct build
21b679f6
LC
4193expressions.
4194
4195The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
4196S-expressions adapted to build expressions. G-expressions, or
f97c9175 4197@dfn{gexps}, consist essentially of three syntactic forms: @code{gexp},
21b679f6 4198@code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
f97c9175
AE
4199@code{#$}, and @code{#$@@}), which are comparable to
4200@code{quasiquote}, @code{unquote}, and @code{unquote-splicing},
4827b36d 4201respectively (@pxref{Expression Syntax, @code{quasiquote},, guile,
f97c9175 4202GNU Guile Reference Manual}). However, there are major differences:
21b679f6
LC
4203
4204@itemize
4205@item
4206Gexps are meant to be written to a file and run or manipulated by other
4207processes.
4208
4209@item
b39fc6f7
LC
4210When a high-level object such as a package or derivation is unquoted
4211inside a gexp, the result is as if its output file name had been
4212introduced.
ff40e9b7 4213
21b679f6
LC
4214@item
4215Gexps carry information about the packages or derivations they refer to,
4216and these dependencies are automatically added as inputs to the build
4217processes that use them.
4218@end itemize
4219
c2b84676 4220@cindex lowering, of high-level objects in gexps
343eacbe
LC
4221This mechanism is not limited to package and derivation
4222objects: @dfn{compilers} able to ``lower'' other high-level objects to
c2b84676
LC
4223derivations or files in the store can be defined,
4224such that these objects can also be inserted
f97c9175 4225into gexps. For example, a useful type of high-level objects that can be
343eacbe 4226inserted in a gexp is ``file-like objects'', which make it easy to
f97c9175 4227add files to the store and to refer to them in
558e8b11
LC
4228derivations and such (see @code{local-file} and @code{plain-file}
4229below.)
b39fc6f7 4230
21b679f6
LC
4231To illustrate the idea, here is an example of a gexp:
4232
4233@example
4234(define build-exp
4235 #~(begin
4236 (mkdir #$output)
4237 (chdir #$output)
aff8ce7c 4238 (symlink (string-append #$coreutils "/bin/ls")
21b679f6
LC
4239 "list-files")))
4240@end example
4241
4242This gexp can be passed to @code{gexp->derivation}; we obtain a
4243derivation that builds a directory containing exactly one symlink to
4244@file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
4245
4246@example
4247(gexp->derivation "the-thing" build-exp)
4248@end example
4249
e20fd1bf 4250As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
21b679f6
LC
4251substituted to the reference to the @var{coreutils} package in the
4252actual build code, and @var{coreutils} is automatically made an input to
4253the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
f97c9175
AE
4254output)}) is replaced by a string containing the directory name of the
4255output of the derivation.
667b2508
LC
4256
4257@cindex cross compilation
4258In a cross-compilation context, it is useful to distinguish between
4259references to the @emph{native} build of a package---that can run on the
4260host---versus references to cross builds of a package. To that end, the
4261@code{#+} plays the same role as @code{#$}, but is a reference to a
4262native package build:
4263
4264@example
4265(gexp->derivation "vi"
4266 #~(begin
4267 (mkdir #$output)
4268 (system* (string-append #+coreutils "/bin/ln")
4269 "-s"
4270 (string-append #$emacs "/bin/emacs")
4271 (string-append #$output "/bin/vi")))
4a3b6aa5 4272 #:target "mips64el-linux-gnu")
667b2508
LC
4273@end example
4274
4275@noindent
4276In the example above, the native build of @var{coreutils} is used, so
4277that @command{ln} can actually run on the host; but then the
4278cross-compiled build of @var{emacs} is referenced.
4279
0bb9929e
LC
4280@cindex imported modules, for gexps
4281@findex with-imported-modules
4282Another gexp feature is @dfn{imported modules}: sometimes you want to be
4283able to use certain Guile modules from the ``host environment'' in the
4284gexp, so those modules should be imported in the ``build environment''.
4285The @code{with-imported-modules} form allows you to express that:
4286
4287@example
4288(let ((build (with-imported-modules '((guix build utils))
4289 #~(begin
4290 (use-modules (guix build utils))
4291 (mkdir-p (string-append #$output "/bin"))))))
4292 (gexp->derivation "empty-dir"
4293 #~(begin
4294 #$build
4295 (display "success!\n")
4296 #t)))
4297@end example
4298
4299@noindent
4300In this example, the @code{(guix build utils)} module is automatically
4301pulled into the isolated build environment of our gexp, such that
4302@code{(use-modules (guix build utils))} works as expected.
4303
7ca87354
LC
4304@cindex module closure
4305@findex source-module-closure
4306Usually you want the @emph{closure} of the module to be imported---i.e.,
4307the module itself and all the modules it depends on---rather than just
4308the module; failing to do that, attempts to use the module will fail
4309because of missing dependent modules. The @code{source-module-closure}
4310procedure computes the closure of a module by looking at its source file
4311headers, which comes in handy in this case:
4312
4313@example
4314(use-modules (guix modules)) ;for 'source-module-closure'
4315
4316(with-imported-modules (source-module-closure
4317 '((guix build utils)
4318 (gnu build vm)))
4319 (gexp->derivation "something-with-vms"
4320 #~(begin
4321 (use-modules (guix build utils)
4322 (gnu build vm))
4323 @dots{})))
4324@end example
4325
667b2508 4326The syntactic form to construct gexps is summarized below.
21b679f6
LC
4327
4328@deffn {Scheme Syntax} #~@var{exp}
4329@deffnx {Scheme Syntax} (gexp @var{exp})
4330Return a G-expression containing @var{exp}. @var{exp} may contain one
4331or more of the following forms:
4332
4333@table @code
4334@item #$@var{obj}
4335@itemx (ungexp @var{obj})
b39fc6f7
LC
4336Introduce a reference to @var{obj}. @var{obj} may have one of the
4337supported types, for example a package or a
21b679f6
LC
4338derivation, in which case the @code{ungexp} form is replaced by its
4339output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
4340
b39fc6f7
LC
4341If @var{obj} is a list, it is traversed and references to supported
4342objects are substituted similarly.
21b679f6
LC
4343
4344If @var{obj} is another gexp, its contents are inserted and its
4345dependencies are added to those of the containing gexp.
4346
4347If @var{obj} is another kind of object, it is inserted as is.
4348
b39fc6f7
LC
4349@item #$@var{obj}:@var{output}
4350@itemx (ungexp @var{obj} @var{output})
21b679f6 4351This is like the form above, but referring explicitly to the
b39fc6f7
LC
4352@var{output} of @var{obj}---this is useful when @var{obj} produces
4353multiple outputs (@pxref{Packages with Multiple Outputs}).
21b679f6 4354
667b2508
LC
4355@item #+@var{obj}
4356@itemx #+@var{obj}:output
4357@itemx (ungexp-native @var{obj})
4358@itemx (ungexp-native @var{obj} @var{output})
4359Same as @code{ungexp}, but produces a reference to the @emph{native}
4360build of @var{obj} when used in a cross compilation context.
4361
21b679f6
LC
4362@item #$output[:@var{output}]
4363@itemx (ungexp output [@var{output}])
4364Insert a reference to derivation output @var{output}, or to the main
4365output when @var{output} is omitted.
4366
4367This only makes sense for gexps passed to @code{gexp->derivation}.
4368
4369@item #$@@@var{lst}
4370@itemx (ungexp-splicing @var{lst})
4371Like the above, but splices the contents of @var{lst} inside the
4372containing list.
4373
667b2508
LC
4374@item #+@@@var{lst}
4375@itemx (ungexp-native-splicing @var{lst})
4376Like the above, but refers to native builds of the objects listed in
4377@var{lst}.
4378
21b679f6
LC
4379@end table
4380
4381G-expressions created by @code{gexp} or @code{#~} are run-time objects
4382of the @code{gexp?} type (see below.)
4383@end deffn
4384
0bb9929e
LC
4385@deffn {Scheme Syntax} with-imported-modules @var{modules} @var{body}@dots{}
4386Mark the gexps defined in @var{body}@dots{} as requiring @var{modules}
d938a58b
LC
4387in their execution environment.
4388
4389Each item in @var{modules} can be the name of a module, such as
4390@code{(guix build utils)}, or it can be a module name, followed by an
4391arrow, followed by a file-like object:
4392
4393@example
4394`((guix build utils)
4395 (guix gcrypt)
4396 ((guix config) => ,(scheme-file "config.scm"
4397 #~(define-module @dots{}))))
4398@end example
4399
4400@noindent
4401In the example above, the first two modules are taken from the search
4402path, and the last one is created from the given file-like object.
0bb9929e
LC
4403
4404This form has @emph{lexical} scope: it has an effect on the gexps
4405directly defined in @var{body}@dots{}, but not on those defined, say, in
4406procedures called from @var{body}@dots{}.
4407@end deffn
4408
21b679f6
LC
4409@deffn {Scheme Procedure} gexp? @var{obj}
4410Return @code{#t} if @var{obj} is a G-expression.
4411@end deffn
4412
4413G-expressions are meant to be written to disk, either as code building
4414some derivation, or as plain files in the store. The monadic procedures
4415below allow you to do that (@pxref{The Store Monad}, for more
4416information about monads.)
4417
4418@deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
ce45eb4c 4419 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
21b679f6
LC
4420 [#:hash #f] [#:hash-algo #f] @
4421 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4684f301 4422 [#:module-path @var{%load-path}] @
c8351d9a 4423 [#:references-graphs #f] [#:allowed-references #f] @
3f4ecf32 4424 [#:disallowed-references #f] @
c0468155 4425 [#:leaked-env-vars #f] @
0309e1b0 4426 [#:script-name (string-append @var{name} "-builder")] @
4a6aeb67 4427 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
21b679f6 4428Return a derivation @var{name} that runs @var{exp} (a gexp) with
0309e1b0
LC
4429@var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
4430stored in a file called @var{script-name}. When @var{target} is true,
4431it is used as the cross-compilation target triplet for packages referred
4432to by @var{exp}.
21b679f6 4433
0bb9929e
LC
4434@var{modules} is deprecated in favor of @code{with-imported-modules}.
4435Its meaning is to
4436make @var{modules} available in the evaluation context of @var{exp};
ce45eb4c
LC
4437@var{modules} is a list of names of Guile modules searched in
4438@var{module-path} to be copied in the store, compiled, and made available in
21b679f6
LC
4439the load path during the execution of @var{exp}---e.g., @code{((guix
4440build utils) (guix build gnu-build-system))}.
4441
ce45eb4c
LC
4442@var{graft?} determines whether packages referred to by @var{exp} should be grafted when
4443applicable.
4444
b53833b2
LC
4445When @var{references-graphs} is true, it must be a list of tuples of one of the
4446following forms:
4447
4448@example
4449(@var{file-name} @var{package})
4450(@var{file-name} @var{package} @var{output})
4451(@var{file-name} @var{derivation})
4452(@var{file-name} @var{derivation} @var{output})
4453(@var{file-name} @var{store-item})
4454@end example
4455
4456The right-hand-side of each element of @var{references-graphs} is automatically made
4457an input of the build process of @var{exp}. In the build environment, each
4458@var{file-name} contains the reference graph of the corresponding item, in a simple
4459text format.
4460
c8351d9a
LC
4461@var{allowed-references} must be either @code{#f} or a list of output names and packages.
4462In the latter case, the list denotes store items that the result is allowed to
4463refer to. Any reference to another store item will lead to a build error.
3f4ecf32
LC
4464Similarly for @var{disallowed-references}, which can list items that must not be
4465referenced by the outputs.
c8351d9a 4466
e20fd1bf 4467The other arguments are as for @code{derivation} (@pxref{Derivations}).
21b679f6
LC
4468@end deffn
4469
343eacbe 4470@cindex file-like objects
e1c153e0
LC
4471The @code{local-file}, @code{plain-file}, @code{computed-file},
4472@code{program-file}, and @code{scheme-file} procedures below return
4473@dfn{file-like objects}. That is, when unquoted in a G-expression,
4474these objects lead to a file in the store. Consider this G-expression:
343eacbe
LC
4475
4476@example
a9e5e92f 4477#~(system* #$(file-append glibc "/sbin/nscd") "-f"
343eacbe
LC
4478 #$(local-file "/tmp/my-nscd.conf"))
4479@end example
4480
4481The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
4482to the store. Once expanded, for instance @i{via}
4483@code{gexp->derivation}, the G-expression refers to that copy under
4484@file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
4485does not have any effect on what the G-expression does.
4486@code{plain-file} can be used similarly; it differs in that the file
4487content is directly passed as a string.
4488
d9ae938f 4489@deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
0687fc9c 4490 [#:recursive? #f] [#:select? (const #t)]
d9ae938f 4491Return an object representing local file @var{file} to add to the store; this
9d3994f7
LC
4492object can be used in a gexp. If @var{file} is a relative file name, it is looked
4493up relative to the source file where this form appears. @var{file} will be added to
4494the store under @var{name}--by default the base name of @var{file}.
d9ae938f
LC
4495
4496When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
4497designates a flat file and @var{recursive?} is true, its contents are added, and its
4498permission bits are kept.
4499
0687fc9c
LC
4500When @var{recursive?} is true, call @code{(@var{select?} @var{file}
4501@var{stat})} for each directory entry, where @var{file} is the entry's
4502absolute file name and @var{stat} is the result of @code{lstat}; exclude
4503entries for which @var{select?} does not return true.
4504
d9ae938f
LC
4505This is the declarative counterpart of the @code{interned-file} monadic
4506procedure (@pxref{The Store Monad, @code{interned-file}}).
4507@end deffn
4508
558e8b11
LC
4509@deffn {Scheme Procedure} plain-file @var{name} @var{content}
4510Return an object representing a text file called @var{name} with the given
4511@var{content} (a string) to be added to the store.
4512
4513This is the declarative counterpart of @code{text-file}.
4514@end deffn
4515
91937029 4516@deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
a769bffb 4517 [#:options '(#:local-build? #t)]
91937029 4518Return an object representing the store item @var{name}, a file or
a769bffb 4519directory computed by @var{gexp}. @var{options}
91937029
LC
4520is a list of additional arguments to pass to @code{gexp->derivation}.
4521
4522This is the declarative counterpart of @code{gexp->derivation}.
4523@end deffn
4524
21b679f6
LC
4525@deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
4526Return an executable script @var{name} that runs @var{exp} using
9c14a487 4527@var{guile}, with @var{exp}'s imported modules in its search path.
21b679f6
LC
4528
4529The example below builds a script that simply invokes the @command{ls}
4530command:
4531
4532@example
4533(use-modules (guix gexp) (gnu packages base))
4534
4535(gexp->script "list-files"
a9e5e92f 4536 #~(execl #$(file-append coreutils "/bin/ls")
21b679f6
LC
4537 "ls"))
4538@end example
4539
4540When ``running'' it through the store (@pxref{The Store Monad,
e20fd1bf 4541@code{run-with-store}}), we obtain a derivation that produces an
21b679f6
LC
4542executable file @file{/gnu/store/@dots{}-list-files} along these lines:
4543
4544@example
4545#!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
4546!#
a9e5e92f 4547(execl "/gnu/store/@dots{}-coreutils-8.22"/bin/ls" "ls")
21b679f6
LC
4548@end example
4549@end deffn
4550
15a01c72 4551@deffn {Scheme Procedure} program-file @var{name} @var{exp} @
9c14a487 4552 [#:guile #f]
15a01c72
LC
4553Return an object representing the executable store item @var{name} that
4554runs @var{gexp}. @var{guile} is the Guile package used to execute that
9c14a487 4555script.
15a01c72
LC
4556
4557This is the declarative counterpart of @code{gexp->script}.
4558@end deffn
4559
2b418579
LC
4560@deffn {Monadic Procedure} gexp->file @var{name} @var{exp} @
4561 [#:set-load-path? #t]
21b679f6 4562Return a derivation that builds a file @var{name} containing @var{exp}.
2b418579
LC
4563When @var{set-load-path?} is true, emit code in the resulting file to
4564set @code{%load-path} and @code{%load-compiled-path} to honor
4565@var{exp}'s imported modules.
21b679f6
LC
4566
4567The resulting file holds references to all the dependencies of @var{exp}
4568or a subset thereof.
4569@end deffn
1ed19464 4570
e1c153e0
LC
4571@deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
4572Return an object representing the Scheme file @var{name} that contains
4573@var{exp}.
4574
4575This is the declarative counterpart of @code{gexp->file}.
4576@end deffn
4577
1ed19464
LC
4578@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
4579Return as a monadic value a derivation that builds a text file
4580containing all of @var{text}. @var{text} may list, in addition to
d9ae938f
LC
4581strings, objects of any type that can be used in a gexp: packages,
4582derivations, local file objects, etc. The resulting store file holds
4583references to all these.
1ed19464
LC
4584
4585This variant should be preferred over @code{text-file} anytime the file
4586to create will reference items from the store. This is typically the
4587case when building a configuration file that embeds store file names,
4588like this:
4589
4590@example
4591(define (profile.sh)
4592 ;; Return the name of a shell script in the store that
4593 ;; initializes the 'PATH' environment variable.
4594 (text-file* "profile.sh"
4595 "export PATH=" coreutils "/bin:"
4596 grep "/bin:" sed "/bin\n"))
4597@end example
4598
4599In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
b7899749 4600will reference @var{coreutils}, @var{grep}, and @var{sed}, thereby
1ed19464
LC
4601preventing them from being garbage-collected during its lifetime.
4602@end deffn
21b679f6 4603
b751cde3
LC
4604@deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
4605Return an object representing store file @var{name} containing
4606@var{text}. @var{text} is a sequence of strings and file-like objects,
4607as in:
4608
4609@example
4610(mixed-text-file "profile"
4611 "export PATH=" coreutils "/bin:" grep "/bin")
4612@end example
4613
4614This is the declarative counterpart of @code{text-file*}.
4615@end deffn
4616
a9e5e92f
LC
4617@deffn {Scheme Procedure} file-append @var{obj} @var{suffix} @dots{}
4618Return a file-like object that expands to the concatenation of @var{obj}
4619and @var{suffix}, where @var{obj} is a lowerable object and each
4620@var{suffix} is a string.
4621
4622As an example, consider this gexp:
4623
4624@example
4625(gexp->script "run-uname"
4626 #~(system* #$(file-append coreutils
4627 "/bin/uname")))
4628@end example
4629
4630The same effect could be achieved with:
4631
4632@example
4633(gexp->script "run-uname"
4634 #~(system* (string-append #$coreutils
4635 "/bin/uname")))
4636@end example
4637
4638There is one difference though: in the @code{file-append} case, the
4639resulting script contains the absolute file name as a string, whereas in
4640the second case, the resulting script contains a @code{(string-append
4641@dots{})} expression to construct the file name @emph{at run time}.
4642@end deffn
4643
4644
21b679f6
LC
4645Of course, in addition to gexps embedded in ``host'' code, there are
4646also modules containing build tools. To make it clear that they are
4647meant to be used in the build stratum, these modules are kept in the
4648@code{(guix build @dots{})} name space.
4649
c2b84676
LC
4650@cindex lowering, of high-level objects in gexps
4651Internally, high-level objects are @dfn{lowered}, using their compiler,
4652to either derivations or store items. For instance, lowering a package
4653yields a derivation, and lowering a @code{plain-file} yields a store
4654item. This is achieved using the @code{lower-object} monadic procedure.
4655
4656@deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
4657 [#:target #f]
4658Return as a value in @var{%store-monad} the derivation or store item
4659corresponding to @var{obj} for @var{system}, cross-compiling for
4660@var{target} if @var{target} is true. @var{obj} must be an object that
4661has an associated gexp compiler, such as a @code{<package>}.
4662@end deffn
4663
21b679f6 4664
568717fd
LC
4665@c *********************************************************************
4666@node Utilities
4667@chapter Utilities
4668
6f773606
LC
4669This section describes Guix command-line utilities. Some of them are
4670primarily targeted at developers and users who write new package
4671definitions, while others are more generally useful. They complement
4672the Scheme programming interface of Guix in a convenient way.
210cc920 4673
568717fd 4674@menu
37166310 4675* Invoking guix build:: Building packages from the command line.
39bee8a2 4676* Invoking guix edit:: Editing package definitions.
210cc920 4677* Invoking guix download:: Downloading a file and printing its hash.
37166310 4678* Invoking guix hash:: Computing the cryptographic hash of a file.
2f7d2d91 4679* Invoking guix import:: Importing package definitions.
37166310 4680* Invoking guix refresh:: Updating package definitions.
b4f5e0e8 4681* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 4682* Invoking guix size:: Profiling disk usage.
88856916 4683* Invoking guix graph:: Visualizing the graph of packages.
372c4bbc 4684* Invoking guix environment:: Setting up development environments.
aff8ce7c 4685* Invoking guix publish:: Sharing substitutes.
d23c20f1 4686* Invoking guix challenge:: Challenging substitute servers.
f11c444d 4687* Invoking guix copy:: Copying to and from a remote store.
32efa254 4688* Invoking guix container:: Process isolation.
568717fd
LC
4689@end menu
4690
e49951eb
MW
4691@node Invoking guix build
4692@section Invoking @command{guix build}
568717fd 4693
e32171ee
JD
4694@cindex package building
4695@cindex @command{guix build}
e49951eb 4696The @command{guix build} command builds packages or derivations and
6798a8e4
LC
4697their dependencies, and prints the resulting store paths. Note that it
4698does not modify the user's profile---this is the job of the
e49951eb 4699@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
4700it is mainly useful for distribution developers.
4701
4702The general syntax is:
c78bd12b
LC
4703
4704@example
e49951eb 4705guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
4706@end example
4707
f97c9175 4708As an example, the following command builds the latest versions of Emacs
ccd7158d
LC
4709and of Guile, displays their build logs, and finally displays the
4710resulting directories:
4711
4712@example
4713guix build emacs guile
4714@end example
4715
4716Similarly, the following command builds all the available packages:
4717
4718@example
5284339d 4719guix build --quiet --keep-going \
ccd7158d
LC
4720 `guix package -A | cut -f1,2 --output-delimiter=@@`
4721@end example
4722
c78bd12b 4723@var{package-or-derivation} may be either the name of a package found in
5401dd75 4724the software distribution such as @code{coreutils} or
e1a65ae5 4725@code{coreutils@@8.20}, or a derivation such as
834129e0 4726@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
4727package with the corresponding name (and optionally version) is searched
4728for among the GNU distribution modules (@pxref{Package Modules}).
4729
4730Alternatively, the @code{--expression} option may be used to specify a
4731Scheme expression that evaluates to a package; this is useful when
b7899749 4732disambiguating among several same-named packages or package variants is
e7f34eb0 4733needed.
c78bd12b 4734
ccd7158d
LC
4735There may be zero or more @var{options}. The available options are
4736described in the subsections below.
4737
4738@menu
4739* Common Build Options:: Build options for most commands.
f11c444d 4740* Package Transformation Options:: Creating variants of packages.
ccd7158d
LC
4741* Additional Build Options:: Options specific to 'guix build'.
4742@end menu
4743
4744@node Common Build Options
4745@subsection Common Build Options
4746
4747A number of options that control the build process are common to
4748@command{guix build} and other commands that can spawn builds, such as
4749@command{guix package} or @command{guix archive}. These are the
4750following:
4751
4752@table @code
4753
4754@item --load-path=@var{directory}
4755@itemx -L @var{directory}
4756Add @var{directory} to the front of the package module search path
4757(@pxref{Package Modules}).
4758
4759This allows users to define their own packages and make them visible to
4760the command-line tools.
4761
4762@item --keep-failed
4763@itemx -K
b7899749 4764Keep the build tree of failed builds. Thus, if a build fails, its build
ccd7158d
LC
4765tree is kept under @file{/tmp}, in a directory whose name is shown at
4766the end of the build log. This is useful when debugging build issues.
4767
4768@item --keep-going
4769@itemx -k
4770Keep going when some of the derivations fail to build; return only once
4771all the builds have either completed or failed.
4772
4773The default behavior is to stop as soon as one of the specified
4774derivations has failed.
4775
4776@item --dry-run
4777@itemx -n
4778Do not build the derivations.
4779
4780@item --fallback
4781When substituting a pre-built binary fails, fall back to building
4782packages locally.
4783
4784@item --substitute-urls=@var{urls}
4785@anchor{client-substitute-urls}
4786Consider @var{urls} the whitespace-separated list of substitute source
4787URLs, overriding the default list of URLs of @command{guix-daemon}
4788(@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
4789
4790This means that substitutes may be downloaded from @var{urls}, provided
4791they are signed by a key authorized by the system administrator
4792(@pxref{Substitutes}).
4793
71e2065a
LC
4794When @var{urls} is the empty string, substitutes are effectively
4795disabled.
4796
ccd7158d
LC
4797@item --no-substitutes
4798Do not use substitutes for build products. That is, always build things
4799locally instead of allowing downloads of pre-built binaries
4800(@pxref{Substitutes}).
4801
7573d30f
LC
4802@item --no-grafts
4803Do not ``graft'' packages. In practice, this means that package updates
4804available as grafts are not applied. @xref{Security Updates}, for more
4805information on grafts.
4806
ccd7158d
LC
4807@item --rounds=@var{n}
4808Build each derivation @var{n} times in a row, and raise an error if
4809consecutive build results are not bit-for-bit identical.
4810
4811This is a useful way to detect non-deterministic builds processes.
4812Non-deterministic build processes are a problem because they make it
4813practically impossible for users to @emph{verify} whether third-party
4814binaries are genuine. @xref{Invoking guix challenge}, for more.
4815
4816Note that, currently, the differing build results are not kept around,
4817so you will have to manually investigate in case of an error---e.g., by
e66d1f59
ML
4818stashing one of the build results with @code{guix archive --export}
4819(@pxref{Invoking guix archive}), then rebuilding, and finally comparing
4820the two results.
ccd7158d
LC
4821
4822@item --no-build-hook
f97c9175 4823Do not attempt to offload builds @i{via} the ``build hook'' of the daemon
ccd7158d
LC
4824(@pxref{Daemon Offload Setup}). That is, always build things locally
4825instead of offloading builds to remote machines.
4826
4827@item --max-silent-time=@var{seconds}
4828When the build or substitution process remains silent for more than
4829@var{seconds}, terminate it and report a build failure.
4830
4831@item --timeout=@var{seconds}
4832Likewise, when the build or substitution process lasts for more than
4833@var{seconds}, terminate it and report a build failure.
4834
4835By default there is no timeout. This behavior can be restored with
4836@code{--timeout=0}.
4837
4838@item --verbosity=@var{level}
4839Use the given verbosity level. @var{level} must be an integer between 0
4840and 5; higher means more verbose output. Setting a level of 4 or more
4841may be helpful when debugging setup issues with the build daemon.
4842
4843@item --cores=@var{n}
4844@itemx -c @var{n}
4845Allow the use of up to @var{n} CPU cores for the build. The special
4846value @code{0} means to use as many CPU cores as available.
4847
4848@item --max-jobs=@var{n}
4849@itemx -M @var{n}
4850Allow at most @var{n} build jobs in parallel. @xref{Invoking
4851guix-daemon, @code{--max-jobs}}, for details about this option and the
4852equivalent @command{guix-daemon} option.
4853
4854@end table
4855
4856Behind the scenes, @command{guix build} is essentially an interface to
4857the @code{package-derivation} procedure of the @code{(guix packages)}
4858module, and to the @code{build-derivations} procedure of the @code{(guix
4859derivations)} module.
4860
4861In addition to options explicitly passed on the command line,
4862@command{guix build} and other @command{guix} commands that support
4863building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
4864
4865@defvr {Environment Variable} GUIX_BUILD_OPTIONS
4866Users can define this variable to a list of command line options that
4867will automatically be used by @command{guix build} and other
4868@command{guix} commands that can perform builds, as in the example
4869below:
4870
4871@example
4872$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
4873@end example
4874
4875These options are parsed independently, and the result is appended to
4876the parsed command-line options.
4877@end defvr
4878
88ad6ded
LC
4879
4880@node Package Transformation Options
4881@subsection Package Transformation Options
4882
4883@cindex package variants
4884Another set of command-line options supported by @command{guix build}
b8638f03 4885and also @command{guix package} are @dfn{package transformation
f97c9175 4886options}. These are options that make it possible to define @dfn{package
b8638f03
LC
4887variants}---for instance, packages built from different source code.
4888This is a convenient way to create customized packages on the fly
4889without having to type in the definitions of package variants
4890(@pxref{Defining Packages}).
88ad6ded
LC
4891
4892@table @code
4893
4894@item --with-source=@var{source}
4895Use @var{source} as the source of the corresponding package.
4896@var{source} must be a file name or a URL, as for @command{guix
4897download} (@pxref{Invoking guix download}).
4898
f97c9175
AE
4899The ``corresponding package'' is taken to be the one specified on the
4900command line the name of which matches the base of @var{source}---e.g.,
4901if @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
88ad6ded 4902package is @code{guile}. Likewise, the version string is inferred from
f97c9175 4903@var{source}; in the previous example, it is @code{2.0.10}.
88ad6ded
LC
4904
4905This option allows users to try out versions of packages other than the
4906one provided by the distribution. The example below downloads
4907@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
4908the @code{ed} package:
4909
4910@example
4911guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
4912@end example
4913
4914As a developer, @code{--with-source} makes it easy to test release
4915candidates:
4916
4917@example
4918guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
4919@end example
4920
4921@dots{} or to build from a checkout in a pristine environment:
4922
4923@example
4924$ git clone git://git.sv.gnu.org/guix.git
4925$ guix build guix --with-source=./guix
4926@end example
4927
47c0f92c
LC
4928@item --with-input=@var{package}=@var{replacement}
4929Replace dependency on @var{package} by a dependency on
4930@var{replacement}. @var{package} must be a package name, and
4931@var{replacement} must be a package specification such as @code{guile}
4932or @code{guile@@1.8}.
4933
f97c9175 4934For instance, the following command builds Guix, but replaces its
47c0f92c 4935dependency on the current stable version of Guile with a dependency on
f6396d86 4936the legacy version of Guile, @code{guile@@2.0}:
47c0f92c
LC
4937
4938@example
f6396d86 4939guix build --with-input=guile=guile@@2.0 guix
47c0f92c
LC
4940@end example
4941
4942This is a recursive, deep replacement. So in this example, both
4943@code{guix} and its dependency @code{guile-json} (which also depends on
f6396d86 4944@code{guile}) get rebuilt against @code{guile@@2.0}.
47c0f92c 4945
2a75b0b6
LC
4946This is implemented using the @code{package-input-rewriting} Scheme
4947procedure (@pxref{Defining Packages, @code{package-input-rewriting}}).
645b9df8
LC
4948
4949@item --with-graft=@var{package}=@var{replacement}
4950This is similar to @code{--with-input} but with an important difference:
9b4ec573 4951instead of rebuilding the whole dependency chain, @var{replacement} is
645b9df8
LC
4952built and then @dfn{grafted} onto the binaries that were initially
4953referring to @var{package}. @xref{Security Updates}, for more
4954information on grafts.
4955
4956For example, the command below grafts version 3.5.4 of GnuTLS onto Wget
4957and all its dependencies, replacing references to the version of GnuTLS
4958they currently refer to:
4959
4960@example
4961guix build --with-graft=gnutls=gnutls@@3.5.4 wget
4962@end example
4963
4964This has the advantage of being much faster than rebuilding everything.
4965But there is a caveat: it works if and only if @var{package} and
4966@var{replacement} are strictly compatible---for example, if they provide
4967a library, the application binary interface (ABI) of those libraries
4968must be compatible. If @var{replacement} is somehow incompatible with
4969@var{package}, then the resulting package may be unusable. Use with
4970care!
4971
88ad6ded
LC
4972@end table
4973
ccd7158d
LC
4974@node Additional Build Options
4975@subsection Additional Build Options
4976
4977The command-line options presented below are specific to @command{guix
4978build}.
c78bd12b
LC
4979
4980@table @code
4981
5284339d
LC
4982@item --quiet
4983@itemx -q
4984Build quietly, without displaying the build log. Upon completion, the
4985build log is kept in @file{/var} (or similar) and can always be
4986retrieved using the @option{--log-file} option.
4987
34a1783f
DT
4988@item --file=@var{file}
4989@itemx -f @var{file}
4990
4991Build the package or derivation that the code within @var{file}
4992evaluates to.
4993
4994As an example, @var{file} might contain a package definition like this
4995(@pxref{Defining Packages}):
4996
4997@example
4998@verbatiminclude package-hello.scm
4999@end example
5000
c78bd12b
LC
5001@item --expression=@var{expr}
5002@itemx -e @var{expr}
ac5de156 5003Build the package or derivation @var{expr} evaluates to.
c78bd12b 5004
5401dd75 5005For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
5006guile-1.8)}, which unambiguously designates this specific variant of
5007version 1.8 of Guile.
5008
f97c9175 5009Alternatively, @var{expr} may be a G-expression, in which case it is used
56b82106
LC
5010as a build program passed to @code{gexp->derivation}
5011(@pxref{G-Expressions}).
5012
5013Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
5014(@pxref{The Store Monad}). The procedure must return a derivation as a
5015monadic value, which is then passed through @code{run-with-store}.
5016
c78bd12b
LC
5017@item --source
5018@itemx -S
f97c9175 5019Build the source derivations of the packages, rather than the packages
c78bd12b
LC
5020themselves.
5021
e49951eb 5022For instance, @code{guix build -S gcc} returns something like
f97c9175
AE
5023@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
5024source tarball.
c78bd12b 5025
f9cc8971 5026The returned source tarball is the result of applying any patches and
f97c9175 5027code snippets specified in the package @code{origin} (@pxref{Defining
f9cc8971
LC
5028Packages}).
5029
2cdfe13d
EB
5030@item --sources
5031Fetch and return the source of @var{package-or-derivation} and all their
5032dependencies, recursively. This is a handy way to obtain a local copy
5033of all the source code needed to build @var{packages}, allowing you to
5034eventually build them even without network access. It is an extension
5035of the @code{--source} option and can accept one of the following
5036optional argument values:
5037
5038@table @code
5039@item package
5040This value causes the @code{--sources} option to behave in the same way
5041as the @code{--source} option.
5042
5043@item all
f97c9175
AE
5044Build the source derivations of all packages, including any source that
5045might be listed as @code{inputs}. This is the default value.
2cdfe13d
EB
5046
5047@example
5048$ guix build --sources tzdata
5049The following derivations will be built:
5050 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
5051 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
5052@end example
5053
5054@item transitive
f97c9175
AE
5055Build the source derivations of all packages, as well of all transitive
5056inputs to the packages. This can be used e.g. to
2cdfe13d
EB
5057prefetch package source for later offline building.
5058
5059@example
5060$ guix build --sources=transitive tzdata
5061The following derivations will be built:
5062 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
5063 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
5064 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
5065 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
5066 /gnu/store/@dots{}-make-4.1.tar.xz.drv
5067 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
5068@dots{}
5069@end example
5070
5071@end table
5072
c78bd12b
LC
5073@item --system=@var{system}
5074@itemx -s @var{system}
5075Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
f97c9175 5076the system type of the build host.
c78bd12b
LC
5077
5078An example use of this is on Linux-based systems, which can emulate
5079different personalities. For instance, passing
5080@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
5081to build packages in a complete 32-bit environment.
5082
e55ec43d
LC
5083@item --target=@var{triplet}
5084@cindex cross-compilation
5085Cross-build for @var{triplet}, which must be a valid GNU triplet, such
5461115e
LC
5086as @code{"mips64el-linux-gnu"} (@pxref{Specifying target triplets, GNU
5087configuration triplets,, autoconf, Autoconf}).
e55ec43d 5088
a8d65643
LC
5089@anchor{build-check}
5090@item --check
5091@cindex determinism, checking
5092@cindex reproducibility, checking
5093Rebuild @var{package-or-derivation}, which are already available in the
5094store, and raise an error if the build results are not bit-for-bit
5095identical.
5096
f97c9175
AE
5097This mechanism allows you to check whether previously installed
5098substitutes are genuine (@pxref{Substitutes}), or whether the build result
5099of a package is deterministic. @xref{Invoking guix challenge}, for more
a8d65643
LC
5100background information and tools.
5101
7f3b2510
ED
5102When used in conjunction with @option{--keep-failed}, the differing
5103output is kept in the store, under @file{/gnu/store/@dots{}-check}.
5104This makes it easy to look for differences between the two results.
5105
6da5bb7b
LC
5106@item --repair
5107@cindex repairing store items
5108@cindex corruption, recovering from
5109Attempt to repair the specified store items, if they are corrupt, by
5110re-downloading or rebuilding them.
5111
5112This operation is not atomic and thus restricted to @code{root}.
5113
c78bd12b
LC
5114@item --derivations
5115@itemx -d
5116Return the derivation paths, not the output paths, of the given
5117packages.
5118
70ee5642
LC
5119@item --root=@var{file}
5120@itemx -r @var{file}
5121Make @var{file} a symlink to the result, and register it as a garbage
5122collector root.
5123
5124@item --log-file
3f208ad7 5125Return the build log file names or URLs for the given
f97c9175 5126@var{package-or-derivation}, or raise an error if build logs are
70ee5642
LC
5127missing.
5128
5129This works regardless of how packages or derivations are specified. For
5130instance, the following invocations are equivalent:
5131
5132@example
5133guix build --log-file `guix build -d guile`
5134guix build --log-file `guix build guile`
5135guix build --log-file guile
5136guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
5137@end example
5138
3f208ad7
LC
5139If a log is unavailable locally, and unless @code{--no-substitutes} is
5140passed, the command looks for a corresponding log on one of the
5141substitute servers (as specified with @code{--substitute-urls}.)
70ee5642 5142
f97c9175
AE
5143So for instance, imagine you want to see the build log of GDB on MIPS,
5144but you are actually on an @code{x86_64} machine:
3f208ad7
LC
5145
5146@example
a01ad638 5147$ guix build --log-file gdb -s mips64el-linux
df061d07 5148https://hydra.gnu.org/log/@dots{}-gdb-7.10
3f208ad7
LC
5149@end example
5150
5151You can freely access a huge library of build logs!
70ee5642
LC
5152@end table
5153
16eb115e 5154
39bee8a2
LC
5155@node Invoking guix edit
5156@section Invoking @command{guix edit}
5157
e32171ee 5158@cindex @command{guix edit}
39bee8a2
LC
5159@cindex package definition, editing
5160So many packages, so many source files! The @command{guix edit} command
424a323e
GC
5161facilitates the life of users and packagers by pointing their editor at
5162the source file containing the definition of the specified packages.
5163For instance:
39bee8a2
LC
5164
5165@example
7b9a66e5 5166guix edit gcc@@4.9 vim
39bee8a2
LC
5167@end example
5168
5169@noindent
6237b9fa 5170launches the program specified in the @code{VISUAL} or in the
424a323e 5171@code{EDITOR} environment variable to view the recipe of GCC@tie{}4.9.3
6237b9fa 5172and that of Vim.
39bee8a2 5173
424a323e
GC
5174If you are using a Guix Git checkout (@pxref{Building from Git}), or
5175have created your own packages on @code{GUIX_PACKAGE_PATH}
5176(@pxref{Defining Packages}), you will be able to edit the package
5177recipes. Otherwise, you will be able to examine the read-only recipes
5178for packages currently in the store.
5179
39bee8a2 5180
210cc920
LC
5181@node Invoking guix download
5182@section Invoking @command{guix download}
5183
e32171ee
JD
5184@cindex @command{guix download}
5185@cindex downloading package sources
210cc920 5186When writing a package definition, developers typically need to download
f97c9175 5187a source tarball, compute its SHA256 hash, and write that
210cc920
LC
5188hash in the package definition (@pxref{Defining Packages}). The
5189@command{guix download} tool helps with this task: it downloads a file
5190from the given URI, adds it to the store, and prints both its file name
5191in the store and its SHA256 hash.
5192
5193The fact that the downloaded file is added to the store saves bandwidth:
5194when the developer eventually tries to build the newly defined package
5195with @command{guix build}, the source tarball will not have to be
5196downloaded again because it is already in the store. It is also a
5197convenient way to temporarily stash files, which may be deleted
5198eventually (@pxref{Invoking guix gc}).
5199
5200The @command{guix download} command supports the same URIs as used in
5201package definitions. In particular, it supports @code{mirror://} URIs.
5202@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
5203Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
5204they are not available, an error is raised. @xref{Guile Preparations,
5205how to install the GnuTLS bindings for Guile,, gnutls-guile,
5206GnuTLS-Guile}, for more information.
210cc920 5207
bc3c41ce
LC
5208@command{guix download} verifies HTTPS server certificates by loading
5209the certificates of X.509 authorities from the directory pointed to by
5210the @code{SSL_CERT_DIR} environment variable (@pxref{X.509
64b8695c 5211Certificates}), unless @option{--no-check-certificate} is used.
bc3c41ce 5212
64b8695c 5213The following options are available:
210cc920
LC
5214
5215@table @code
5216@item --format=@var{fmt}
5217@itemx -f @var{fmt}
5218Write the hash in the format specified by @var{fmt}. For more
081145cf 5219information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
64b8695c
LC
5220
5221@item --no-check-certificate
5222Do not validate the X.509 certificates of HTTPS servers.
5223
5224When using this option, you have @emph{absolutely no guarantee} that you
5225are communicating with the authentic server responsible for the given
5226URL, which makes you vulnerable to ``man-in-the-middle'' attacks.
5227
1bcc87bb
LC
5228@item --output=@var{file}
5229@itemx -o @var{file}
5230Save the downloaded file to @var{file} instead of adding it to the
5231store.
210cc920
LC
5232@end table
5233
6c365eca
NK
5234@node Invoking guix hash
5235@section Invoking @command{guix hash}
5236
e32171ee 5237@cindex @command{guix hash}
210cc920 5238The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
5239It is primarily a convenience tool for anyone contributing to the
5240distribution: it computes the cryptographic hash of a file, which can be
5241used in the definition of a package (@pxref{Defining Packages}).
5242
5243The general syntax is:
5244
5245@example
5246guix hash @var{option} @var{file}
5247@end example
5248
343dc117
LC
5249When @var{file} is @code{-} (a hyphen), @command{guix hash} computes the
5250hash of data read from standard input. @command{guix hash} has the
5251following options:
6c365eca
NK
5252
5253@table @code
5254
5255@item --format=@var{fmt}
5256@itemx -f @var{fmt}
210cc920 5257Write the hash in the format specified by @var{fmt}.
6c365eca
NK
5258
5259Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
5260(@code{hex} and @code{hexadecimal} can be used as well).
5261
5262If the @option{--format} option is not specified, @command{guix hash}
5263will output the hash in @code{nix-base32}. This representation is used
5264in the definitions of packages.
5265
3140f2df
LC
5266@item --recursive
5267@itemx -r
5268Compute the hash on @var{file} recursively.
5269
5270In this case, the hash is computed on an archive containing @var{file},
f97c9175
AE
5271including its children if it is a directory. Some of the metadata of
5272@var{file} is part of the archive; for instance, when @var{file} is a
3140f2df 5273regular file, the hash is different depending on whether @var{file} is
f97c9175 5274executable or not. Metadata such as time stamps has no impact on the
3140f2df
LC
5275hash (@pxref{Invoking guix archive}).
5276@c FIXME: Replace xref above with xref to an ``Archive'' section when
5277@c it exists.
5278
392a4e12
JN
5279@item --exclude-vcs
5280@itemx -x
5281When combined with @option{--recursive}, exclude version control system
5282directories (@file{.bzr}, @file{.git}, @file{.hg}, etc.)
5283
db97a03a
LC
5284@vindex git-fetch
5285As an example, here is how you would compute the hash of a Git checkout,
5286which is useful when using the @code{git-fetch} method (@pxref{origin
5287Reference}):
5288
5289@example
5290$ git clone http://example.org/foo.git
5291$ cd foo
392a4e12 5292$ guix hash -rx .
db97a03a 5293@end example
6c365eca
NK
5294@end table
5295
2f7d2d91
LC
5296@node Invoking guix import
5297@section Invoking @command{guix import}
5298
5299@cindex importing packages
5300@cindex package import
5301@cindex package conversion
e32171ee 5302@cindex Invoking @command{guix import}
f97c9175
AE
5303The @command{guix import} command is useful for people who would like to
5304add a package to the distribution with as little work as
5305possible---a legitimate demand. The command knows of a few
5306repositories from which it can ``import'' package metadata. The result
2f7d2d91
LC
5307is a package definition, or a template thereof, in the format we know
5308(@pxref{Defining Packages}).
5309
5310The general syntax is:
5311
5312@example
5313guix import @var{importer} @var{options}@dots{}
5314@end example
5315
5316@var{importer} specifies the source from which to import package
f97c9175 5317metadata, and @var{options} specifies a package identifier and other
2f7d2d91
LC
5318options specific to @var{importer}. Currently, the available
5319``importers'' are:
5320
5321@table @code
5322@item gnu
f97c9175 5323Import metadata for the given GNU package. This provides a template
2f7d2d91
LC
5324for the latest version of that GNU package, including the hash of its
5325source tarball, and its canonical synopsis and description.
5326
f97c9175 5327Additional information such as the package dependencies and its
2f7d2d91
LC
5328license needs to be figured out manually.
5329
5330For example, the following command returns a package definition for
5331GNU@tie{}Hello:
5332
5333@example
5334guix import gnu hello
5335@end example
5336
5337Specific command-line options are:
5338
5339@table @code
5340@item --key-download=@var{policy}
5341As for @code{guix refresh}, specify the policy to handle missing OpenPGP
f97c9175 5342keys when verifying the package signature. @xref{Invoking guix
2f7d2d91
LC
5343refresh, @code{--key-download}}.
5344@end table
5345
5346@item pypi
5347@cindex pypi
f97c9175 5348Import metadata from the @uref{https://pypi.python.org/, Python Package
2f7d2d91
LC
5349Index}@footnote{This functionality requires Guile-JSON to be installed.
5350@xref{Requirements}.}. Information is taken from the JSON-formatted
5351description available at @code{pypi.python.org} and usually includes all
266785d2
CR
5352the relevant information, including package dependencies. For maximum
5353efficiency, it is recommended to install the @command{unzip} utility, so
5354that the importer can unzip Python wheels and gather data from them.
2f7d2d91 5355
f97c9175 5356The command below imports metadata for the @code{itsdangerous} Python
2f7d2d91
LC
5357package:
5358
5359@example
5360guix import pypi itsdangerous
5361@end example
5362
3aae8145
DT
5363@item gem
5364@cindex gem
f97c9175 5365Import metadata from @uref{https://rubygems.org/,
3aae8145
DT
5366RubyGems}@footnote{This functionality requires Guile-JSON to be
5367installed. @xref{Requirements}.}. Information is taken from the
5368JSON-formatted description available at @code{rubygems.org} and includes
5369most relevant information, including runtime dependencies. There are
f97c9175 5370some caveats, however. The metadata doesn't distinguish between
3aae8145
DT
5371synopses and descriptions, so the same string is used for both fields.
5372Additionally, the details of non-Ruby dependencies required to build
5373native extensions is unavailable and left as an exercise to the
5374packager.
5375
f97c9175 5376The command below imports metadata for the @code{rails} Ruby package:
3aae8145
DT
5377
5378@example
5379guix import gem rails
5380@end example
5381
d45dc6da
EB
5382@item cpan
5383@cindex CPAN
3c192e4e
AE
5384Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}@footnote{This
5385functionality requires Guile-JSON to be installed.
5386@xref{Requirements}.}.
f97c9175 5387Information is taken from the JSON-formatted metadata provided through
d45dc6da 5388@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
5389relevant information, such as module dependencies. License information
5390should be checked closely. If Perl is available in the store, then the
5391@code{corelist} utility will be used to filter core modules out of the
5392list of dependencies.
d45dc6da 5393
f97c9175 5394The command command below imports metadata for the @code{Acme::Boolean}
d45dc6da
EB
5395Perl module:
5396
5397@example
5398guix import cpan Acme::Boolean
5399@end example
5400
e1248602
RW
5401@item cran
5402@cindex CRAN
d0bd632f 5403@cindex Bioconductor
f97c9175 5404Import metadata from @uref{http://cran.r-project.org/, CRAN}, the
e1248602
RW
5405central repository for the @uref{http://r-project.org, GNU@tie{}R
5406statistical and graphical environment}.
5407
f97c9175 5408Information is extracted from the @code{DESCRIPTION} file of the package.
e1248602 5409
f97c9175 5410The command command below imports metadata for the @code{Cairo}
e1248602
RW
5411R package:
5412
5413@example
5414guix import cran Cairo
5415@end example
5416
64ce53eb
RW
5417When @code{--recursive} is added, the importer will traverse the
5418dependency graph of the given upstream package recursively and generate
5419package expressions for all those packages that are not yet in Guix.
5420
f97c9175 5421When @code{--archive=bioconductor} is added, metadata is imported from
d0bd632f
RW
5422@uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
5423packages for for the analysis and comprehension of high-throughput
5424genomic data in bioinformatics.
5425
f97c9175 5426Information is extracted from the @code{DESCRIPTION} file of a package
d0bd632f
RW
5427published on the web interface of the Bioconductor SVN repository.
5428
f97c9175 5429The command below imports metadata for the @code{GenomicRanges}
d0bd632f
RW
5430R package:
5431
5432@example
5433guix import cran --archive=bioconductor GenomicRanges
5434@end example
5435
2f7d2d91 5436@item nix
f97c9175 5437Import metadata from a local copy of the source of the
2f7d2d91
LC
5438@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
5439relies on the @command{nix-instantiate} command of
5440@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
5441typically written in a mixture of Nix-language and Bash code. This
5442command only imports the high-level package structure that is written in
5443the Nix language. It normally includes all the basic fields of a
5444package definition.
5445
5446When importing a GNU package, the synopsis and descriptions are replaced
5447by their canonical upstream variant.
5448
961d0d2d
LC
5449Usually, you will first need to do:
5450
5451@example
5452export NIX_REMOTE=daemon
5453@end example
5454
5455@noindent
5456so that @command{nix-instantiate} does not try to open the Nix database.
5457
2f7d2d91
LC
5458As an example, the command below imports the package definition of
5459LibreOffice (more precisely, it imports the definition of the package
5460bound to the @code{libreoffice} top-level attribute):
5461
5462@example
5463guix import nix ~/path/to/nixpkgs libreoffice
5464@end example
863af4e1
FB
5465
5466@item hackage
5467@cindex hackage
f97c9175 5468Import metadata from the Haskell community's central package archive
863af4e1
FB
5469@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
5470Cabal files and includes all the relevant information, including package
5471dependencies.
5472
5473Specific command-line options are:
5474
5475@table @code
a4154748
FB
5476@item --stdin
5477@itemx -s
f97c9175 5478Read a Cabal file from standard input.
863af4e1
FB
5479@item --no-test-dependencies
5480@itemx -t
f97c9175 5481Do not include dependencies required only by the test suites.
a4154748
FB
5482@item --cabal-environment=@var{alist}
5483@itemx -e @var{alist}
5484@var{alist} is a Scheme alist defining the environment in which the
5485Cabal conditionals are evaluated. The accepted keys are: @code{os},
5486@code{arch}, @code{impl} and a string representing the name of a flag.
5487The value associated with a flag has to be either the symbol
5488@code{true} or @code{false}. The value associated with other keys
5489has to conform to the Cabal file format definition. The default value
5490associated with the keys @code{os}, @code{arch} and @code{impl} is
f97c9175 5491@samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
863af4e1
FB
5492@end table
5493
f97c9175 5494The command below imports metadata for the latest version of the
a4154748
FB
5495@code{HTTP} Haskell package without including test dependencies and
5496specifying the value of the flag @samp{network-uri} as @code{false}:
863af4e1
FB
5497
5498@example
a4154748 5499guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
863af4e1
FB
5500@end example
5501
5502A specific package version may optionally be specified by following the
1b846da8 5503package name by an at-sign and a version number as in the following example:
863af4e1
FB
5504
5505@example
1b846da8 5506guix import hackage mtl@@2.1.3.1
863af4e1 5507@end example
7f74a931 5508
bc5844d1
FB
5509@item stackage
5510@cindex stackage
5511The @code{stackage} importer is a wrapper around the @code{hackage} one.
5512It takes a package name, looks up the package version included in a
5513long-term support (LTS) @uref{https://www.stackage.org, Stackage}
5514release and uses the @code{hackage} importer to retrieve its metadata.
5515Note that it is up to you to select an LTS release compatible with the
5516GHC compiler used by Guix.
5517
5518Specific command-line options are:
5519
5520@table @code
5521@item --no-test-dependencies
5522@itemx -t
5523Do not include dependencies required only by the test suites.
5524@item --lts-version=@var{version}
5525@itemx -r @var{version}
5526@var{version} is the desired LTS release version. If omitted the latest
5527release is used.
5528@end table
5529
5530The command below imports metadata for the @code{HTTP} Haskell package
5531included in the LTS Stackage release version 7.18:
5532
5533@example
5534guix import stackage --lts-version=7.18 HTTP
5535@end example
5536
7f74a931
FB
5537@item elpa
5538@cindex elpa
f97c9175 5539Import metadata from an Emacs Lisp Package Archive (ELPA) package
7f74a931
FB
5540repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
5541
5542Specific command-line options are:
5543
5544@table @code
5545@item --archive=@var{repo}
5546@itemx -a @var{repo}
5547@var{repo} identifies the archive repository from which to retrieve the
5548information. Currently the supported repositories and their identifiers
5549are:
5550@itemize -
5551@item
840bd1d3 5552@uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7f74a931
FB
5553identifier. This is the default.
5554
624144e0
LC
5555Packages from @code{elpa.gnu.org} are signed with one of the keys
5556contained in the GnuPG keyring at
5557@file{share/emacs/25.1/etc/package-keyring.gpg} (or similar) in the
5558@code{emacs} package (@pxref{Package Installation, ELPA package
5559signatures,, emacs, The GNU Emacs Manual}).
5560
7f74a931 5561@item
840bd1d3 5562@uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7f74a931
FB
5563@code{melpa-stable} identifier.
5564
5565@item
840bd1d3 5566@uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7f74a931
FB
5567identifier.
5568@end itemize
5569@end table
3e0c0365
DC
5570
5571@item crate
5572@cindex crate
5573Import metadata from the crates.io Rust package repository
5574@uref{https://crates.io, crates.io}.
2f7d2d91
LC
5575@end table
5576
5577The structure of the @command{guix import} code is modular. It would be
5578useful to have more importers for other package formats, and your help
5579is welcome here (@pxref{Contributing}).
5580
37166310
LC
5581@node Invoking guix refresh
5582@section Invoking @command{guix refresh}
5583
e32171ee 5584@cindex @command {guix refresh}
37166310
LC
5585The primary audience of the @command{guix refresh} command is developers
5586of the GNU software distribution. By default, it reports any packages
5587provided by the distribution that are outdated compared to the latest
5588upstream version, like this:
5589
5590@example
5591$ guix refresh
5592gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
5593gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
5594@end example
5595
e9c72306
LC
5596Alternately, one can specify packages to consider, in which case a
5597warning is emitted for packages that lack an updater:
5598
5599@example
5600$ guix refresh coreutils guile guile-ssh
5601gnu/packages/ssh.scm:205:2: warning: no updater for guile-ssh
5602gnu/packages/guile.scm:136:12: guile would be upgraded from 2.0.12 to 2.0.13
5603@end example
5604
5605@command{guix refresh} browses the upstream repository of each package and determines
5606the highest version number of the releases therein. The command
bcb571cb 5607knows how to update specific types of packages: GNU packages, ELPA
e9c72306 5608packages, etc.---see the documentation for @option{--type} below. There
bcb571cb
LC
5609are many packages, though, for which it lacks a method to determine
5610whether a new upstream release is available. However, the mechanism is
5611extensible, so feel free to get in touch with us to add a new method!
37166310
LC
5612
5613When passed @code{--update}, it modifies distribution source files to
f97c9175 5614update the version numbers and source tarball hashes of those package
37166310
LC
5615recipes (@pxref{Defining Packages}). This is achieved by downloading
5616each package's latest source tarball and its associated OpenPGP
5617signature, authenticating the downloaded tarball against its signature
5618using @command{gpg}, and finally computing its hash. When the public
5619key used to sign the tarball is missing from the user's keyring, an
5620attempt is made to automatically retrieve it from a public key server;
f97c9175 5621when this is successful, the key is added to the user's keyring; otherwise,
37166310
LC
5622@command{guix refresh} reports an error.
5623
5624The following options are supported:
5625
5626@table @code
5627
2d7fc7da
LC
5628@item --expression=@var{expr}
5629@itemx -e @var{expr}
5630Consider the package @var{expr} evaluates to.
5631
5632This is useful to precisely refer to a package, as in this example:
5633
5634@example
5635guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
5636@end example
5637
5638This command lists the dependents of the ``final'' libc (essentially all
5639the packages.)
5640
37166310
LC
5641@item --update
5642@itemx -u
38e16b49
LC
5643Update distribution source files (package recipes) in place. This is
5644usually run from a checkout of the Guix source tree (@pxref{Running
5645Guix Before It Is Installed}):
5646
5647@example
e9c72306 5648$ ./pre-inst-env guix refresh -s non-core -u
38e16b49
LC
5649@end example
5650
081145cf 5651@xref{Defining Packages}, for more information on package definitions.
37166310
LC
5652
5653@item --select=[@var{subset}]
5654@itemx -s @var{subset}
5655Select all the packages in @var{subset}, one of @code{core} or
5656@code{non-core}.
5657
5658The @code{core} subset refers to all the packages at the core of the
5659distribution---i.e., packages that are used to build ``everything
5660else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
5661changing one of these packages in the distribution entails a rebuild of
5662all the others. Thus, such updates are an inconvenience to users in
5663terms of build time or bandwidth used to achieve the upgrade.
5664
5665The @code{non-core} subset refers to the remaining packages. It is
5666typically useful in cases where an update of the core packages would be
5667inconvenient.
5668
bcb571cb
LC
5669@item --type=@var{updater}
5670@itemx -t @var{updater}
7191adc5
AK
5671Select only packages handled by @var{updater} (may be a comma-separated
5672list of updaters). Currently, @var{updater} may be one of:
bcb571cb
LC
5673
5674@table @code
5675@item gnu
5676the updater for GNU packages;
e80c0f85
LC
5677@item gnome
5678the updater for GNOME packages;
9c97afe8
DC
5679@item kde
5680the updater for KDE packages;
62061d6b
AW
5681@item xorg
5682the updater for X.org packages;
2fd370e8
LC
5683@item kernel.org
5684the updater for packages hosted on kernel.org;
bcb571cb 5685@item elpa
d882c235
LC
5686the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
5687@item cran
b9d044ef 5688the updater for @uref{http://cran.r-project.org/, CRAN} packages;
d0bd632f
RW
5689@item bioconductor
5690the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
200cdf81
EB
5691@item cpan
5692the updater for @uref{http://www.cpan.org/, CPAN} packages;
bab020d7 5693@item pypi
b9d044ef 5694the updater for @uref{https://pypi.python.org, PyPI} packages.
fbc5b815
BW
5695@item gem
5696the updater for @uref{https://rubygems.org, RubyGems} packages.
917a2a58
BW
5697@item github
5698the updater for @uref{https://github.com, GitHub} packages.
42efe27a
EB
5699@item hackage
5700the updater for @uref{https://hackage.haskell.org, Hackage} packages.
bc5844d1
FB
5701@item stackage
5702the updater for @uref{https://www.stackage.org, Stackage} packages.
8ac52987
DC
5703@item crate
5704the updater for @uref{https://crates.io, Crates} packages.
bcb571cb
LC
5705@end table
5706
f97c9175
AE
5707For instance, the following command only checks for updates of Emacs
5708packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
bcb571cb
LC
5709
5710@example
7191adc5 5711$ guix refresh --type=elpa,cran
d882c235 5712gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
bcb571cb
LC
5713gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
5714@end example
5715
37166310
LC
5716@end table
5717
5718In addition, @command{guix refresh} can be passed one or more package
5719names, as in this example:
5720
5721@example
e9c72306 5722$ ./pre-inst-env guix refresh -u emacs idutils gcc@@4.8
37166310
LC
5723@end example
5724
5725@noindent
5726The command above specifically updates the @code{emacs} and
5727@code{idutils} packages. The @code{--select} option would have no
5728effect in this case.
5729
7d193ec3
EB
5730When considering whether to upgrade a package, it is sometimes
5731convenient to know which packages would be affected by the upgrade and
5732should be checked for compatibility. For this the following option may
5733be used when passing @command{guix refresh} one or more package names:
5734
5735@table @code
5736
6ffa706b
AK
5737@item --list-updaters
5738@itemx -L
5739List available updaters and exit (see @option{--type} above.)
5740
3676f892
LC
5741For each updater, display the fraction of packages it covers; at the
5742end, display the fraction of packages covered by all these updaters.
5743
7d193ec3
EB
5744@item --list-dependent
5745@itemx -l
5746List top-level dependent packages that would need to be rebuilt as a
5747result of upgrading one or more packages.
5748
b96a0640
LC
5749@xref{Invoking guix graph, the @code{reverse-package} type of
5750@command{guix graph}}, for information on how to visualize the list of
5751dependents of a package.
5752
7d193ec3
EB
5753@end table
5754
5755Be aware that the @code{--list-dependent} option only
5756@emph{approximates} the rebuilds that would be required as a result of
5757an upgrade. More rebuilds might be required under some circumstances.
5758
5759@example
7779ab61
LC
5760$ guix refresh --list-dependent flex
5761Building the following 120 packages would ensure 213 dependent packages are rebuilt:
5762hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
5763@end example
5764
5765The command above lists a set of packages that could be built to check
5766for compatibility with an upgraded @code{flex} package.
5767
f9230085
LC
5768The following options can be used to customize GnuPG operation:
5769
5770@table @code
5771
f9230085
LC
5772@item --gpg=@var{command}
5773Use @var{command} as the GnuPG 2.x command. @var{command} is searched
5774for in @code{$PATH}.
5775
2bc53ba9
LC
5776@item --key-download=@var{policy}
5777Handle missing OpenPGP keys according to @var{policy}, which may be one
5778of:
5779
5780@table @code
5781@item always
5782Always download missing OpenPGP keys from the key server, and add them
5783to the user's GnuPG keyring.
5784
5785@item never
5786Never try to download missing OpenPGP keys. Instead just bail out.
5787
5788@item interactive
5789When a package signed with an unknown OpenPGP key is encountered, ask
5790the user whether to download it or not. This is the default behavior.
5791@end table
5792
5793@item --key-server=@var{host}
5794Use @var{host} as the OpenPGP key server when importing a public key.
5795
f9230085
LC
5796@end table
5797
917a2a58
BW
5798The @code{github} updater uses the
5799@uref{https://developer.github.com/v3/, GitHub API} to query for new
5800releases. When used repeatedly e.g. when refreshing all packages,
5801GitHub will eventually refuse to answer any further API requests. By
5802default 60 API requests per hour are allowed, and a full refresh on all
5803GitHub packages in Guix requires more than this. Authentication with
5804GitHub through the use of an API token alleviates these limits. To use
5805an API token, set the environment variable @code{GUIX_GITHUB_TOKEN} to a
5806token procured from @uref{https://github.com/settings/tokens} or
5807otherwise.
5808
5809
b4f5e0e8
CR
5810@node Invoking guix lint
5811@section Invoking @command{guix lint}
e32171ee
JD
5812
5813@cindex @command{guix lint}
5814@cindex package, checking for errors
f97c9175
AE
5815The @command{guix lint} command is meant to help package developers avoid
5816common errors and use a consistent style. It runs a number of checks on
5817a given set of packages in order to find common mistakes in their
873c4085
LC
5818definitions. Available @dfn{checkers} include (see
5819@code{--list-checkers} for a complete list):
5820
5821@table @code
5822@item synopsis
5823@itemx description
5824Validate certain typographical and stylistic rules about package
5825descriptions and synopses.
5826
5827@item inputs-should-be-native
5828Identify inputs that should most likely be native inputs.
5829
5830@item source
5831@itemx home-page
fac46e3f 5832@itemx mirror-url
50f5c46d 5833@itemx source-file-name
873c4085 5834Probe @code{home-page} and @code{source} URLs and report those that are
fac46e3f
LC
5835invalid. Suggest a @code{mirror://} URL when applicable. Check that
5836the source file name is meaningful, e.g. is not
f97c9175
AE
5837just a version number or ``git-checkout'', without a declared
5838@code{file-name} (@pxref{origin Reference}).
40a7d4e5 5839
5432734b 5840@item cve
09866b39
LC
5841@cindex security vulnerabilities
5842@cindex CVE, Common Vulnerabilities and Exposures
5432734b 5843Report known vulnerabilities found in the Common Vulnerabilities and
09866b39 5844Exposures (CVE) databases of the current and past year
5432734b
LC
5845@uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
5846NIST}.
5847
09866b39
LC
5848To view information about a particular vulnerability, visit pages such as:
5849
5850@itemize
5851@item
5852@indicateurl{https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-YYYY-ABCD}
5853@item
5854@indicateurl{https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-YYYY-ABCD}
5855@end itemize
5856
5857@noindent
5858where @code{CVE-YYYY-ABCD} is the CVE identifier---e.g.,
5859@code{CVE-2015-7554}.
5860
99effc8f
LC
5861Package developers can specify in package recipes the
5862@uref{https://nvd.nist.gov/cpe.cfm,Common Platform Enumeration (CPE)}
5863name and version of the package when they differ from the name that Guix
5864uses, as in this example:
5865
5866@example
5867(package
5868 (name "grub")
5869 ;; @dots{}
5870 ;; CPE calls this package "grub2".
5871 (properties '((cpe-name . "grub2"))))
5872@end example
5873
40a7d4e5
LC
5874@item formatting
5875Warn about obvious source code formatting issues: trailing white space,
5876use of tabulations, etc.
873c4085 5877@end table
b4f5e0e8
CR
5878
5879The general syntax is:
5880
5881@example
5882guix lint @var{options} @var{package}@dots{}
5883@end example
5884
5885If no package is given on the command line, then all packages are checked.
5886The @var{options} may be zero or more of the following:
5887
5888@table @code
f97c9175
AE
5889@item --list-checkers
5890@itemx -l
5891List and describe all the available checkers that will be run on packages
5892and exit.
b4f5e0e8 5893
dd7c013d
CR
5894@item --checkers
5895@itemx -c
5896Only enable the checkers specified in a comma-separated list using the
5897names returned by @code{--list-checkers}.
5898
b4f5e0e8 5899@end table
37166310 5900
fcc58db6
LC
5901@node Invoking guix size
5902@section Invoking @command{guix size}
5903
e32171ee
JD
5904@cindex size
5905@cindex package size
5906@cindex closure
5907@cindex @command{guix size}
fcc58db6
LC
5908The @command{guix size} command helps package developers profile the
5909disk usage of packages. It is easy to overlook the impact of an
5910additional dependency added to a package, or the impact of using a
5911single output for a package that could easily be split (@pxref{Packages
f97c9175 5912with Multiple Outputs}). Such are the typical issues that
fcc58db6
LC
5913@command{guix size} can highlight.
5914
e1a65ae5 5915The command can be passed a package specification such as @code{gcc@@4.8}
fcc58db6
LC
5916or @code{guile:debug}, or a file name in the store. Consider this
5917example:
5918
5919@example
5920$ guix size coreutils
5921store item total self
5922/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
5923/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
5924/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
5925/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
5926/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
5927/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
5928@end example
5929
5930@cindex closure
5931The store items listed here constitute the @dfn{transitive closure} of
5932Coreutils---i.e., Coreutils and all its dependencies, recursively---as
5933would be returned by:
5934
5935@example
5936$ guix gc -R /gnu/store/@dots{}-coreutils-8.23
5937@end example
5938
f97c9175 5939Here the output shows three columns next to store items. The first column,
fcc58db6
LC
5940labeled ``total'', shows the size in mebibytes (MiB) of the closure of
5941the store item---that is, its own size plus the size of all its
5942dependencies. The next column, labeled ``self'', shows the size of the
f97c9175
AE
5943item itself. The last column shows the ratio of the size of the item
5944itself to the space occupied by all the items listed here.
fcc58db6
LC
5945
5946In this example, we see that the closure of Coreutils weighs in at
594770@tie{}MiB, half of which is taken by libc. (That libc represents a
5948large fraction of the closure is not a problem @i{per se} because it is
5949always available on the system anyway.)
5950
5951When the package passed to @command{guix size} is available in the
5952store, @command{guix size} queries the daemon to determine its
5953dependencies, and measures its size in the store, similar to @command{du
5954-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
5955Coreutils}).
5956
5957When the given package is @emph{not} in the store, @command{guix size}
f97c9175
AE
5958reports information based on the available substitutes
5959(@pxref{Substitutes}). This makes it possible it to profile disk usage of
5960store items that are not even on disk, only available remotely.
fcc58db6 5961
db761534
LC
5962You can also specify several package names:
5963
5964@example
5965$ guix size coreutils grep sed bash
5966store item total self
5967/gnu/store/@dots{}-coreutils-8.24 77.8 13.8 13.4%
5968/gnu/store/@dots{}-grep-2.22 73.1 0.8 0.8%
5969/gnu/store/@dots{}-bash-4.3.42 72.3 4.7 4.6%
5970/gnu/store/@dots{}-readline-6.3 67.6 1.2 1.2%
5971@dots{}
5972total: 102.3 MiB
5973@end example
5974
5975@noindent
5976In this example we see that the combination of the four packages takes
5977102.3@tie{}MiB in total, which is much less than the sum of each closure
5978since they have a lot of dependencies in common.
5979
a8f996c6 5980The available options are:
fcc58db6
LC
5981
5982@table @option
5983
d490d06e
LC
5984@item --substitute-urls=@var{urls}
5985Use substitute information from @var{urls}.
5986@xref{client-substitute-urls, the same option for @code{guix build}}.
5987
a8f996c6 5988@item --map-file=@var{file}
f97c9175 5989Write a graphical map of disk usage in PNG format to @var{file}.
a8f996c6
LC
5990
5991For the example above, the map looks like this:
5992
5993@image{images/coreutils-size-map,5in,, map of Coreutils disk usage
5994produced by @command{guix size}}
5995
5996This option requires that
5997@uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
5998installed and visible in Guile's module search path. When that is not
5999the case, @command{guix size} fails as it tries to load it.
6000
fcc58db6
LC
6001@item --system=@var{system}
6002@itemx -s @var{system}
6003Consider packages for @var{system}---e.g., @code{x86_64-linux}.
6004
6005@end table
6006
88856916
LC
6007@node Invoking guix graph
6008@section Invoking @command{guix graph}
6009
6010@cindex DAG
e32171ee
JD
6011@cindex @command{guix graph}
6012@cindex package dependencies
88856916
LC
6013Packages and their dependencies form a @dfn{graph}, specifically a
6014directed acyclic graph (DAG). It can quickly become difficult to have a
f97c9175 6015mental model of the package DAG, so the @command{guix graph} command
9ea36197
LC
6016provides a visual representation of the DAG. By default,
6017@command{guix graph} emits a DAG representation in the input format of
88856916 6018@uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
9ea36197
LC
6019directly to the @command{dot} command of Graphviz. It can also emit an
6020HTML page with embedded JavaScript code to display a ``chord diagram''
6021in a Web browser, using the @uref{https://d3js.org/, d3.js} library.
6022The general syntax is:
88856916
LC
6023
6024@example
6025guix graph @var{options} @var{package}@dots{}
6026@end example
6027
6028For example, the following command generates a PDF file representing the
6029package DAG for the GNU@tie{}Core Utilities, showing its build-time
6030dependencies:
6031
6032@example
6033guix graph coreutils | dot -Tpdf > dag.pdf
6034@end example
6035
6036The output looks like this:
6037
6038@image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
6039
6040Nice little graph, no?
6041
f97c9175 6042But there is more than one graph! The one above is concise: it is the
88856916 6043graph of package objects, omitting implicit inputs such as GCC, libc,
f97c9175
AE
6044grep, etc. It is often useful to have such a concise graph, but
6045sometimes one may want to see more details. @command{guix graph} supports
6046several types of graphs, allowing you to choose the level of detail:
88856916
LC
6047
6048@table @code
6049@item package
f97c9175 6050This is the default type used in the example above. It shows the DAG of
88856916
LC
6051package objects, excluding implicit dependencies. It is concise, but
6052filters out many details.
6053
b96a0640
LC
6054@item reverse-package
6055This shows the @emph{reverse} DAG of packages. For example:
6056
6057@example
6058guix graph --type=reverse-package ocaml
6059@end example
6060
6061... yields the graph of packages that depend on OCaml.
6062
6063Note that for core packages this can yield huge graphs. If all you want
6064is to know the number of packages that depend on a given package, use
6065@command{guix refresh --list-dependent} (@pxref{Invoking guix refresh,
6066@option{--list-dependent}}).
6067
88856916
LC
6068@item bag-emerged
6069This is the package DAG, @emph{including} implicit inputs.
6070
6071For instance, the following command:
6072
6073@example
6074guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
6075@end example
6076
6077... yields this bigger graph:
6078
6079@image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
6080
6081At the bottom of the graph, we see all the implicit inputs of
6082@var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
6083
f97c9175 6084Now, note that the dependencies of these implicit inputs---that is, the
88856916
LC
6085@dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
6086here, for conciseness.
6087
6088@item bag
6089Similar to @code{bag-emerged}, but this time including all the bootstrap
6090dependencies.
6091
38b92daa
LC
6092@item bag-with-origins
6093Similar to @code{bag}, but also showing origins and their dependencies.
6094
88856916
LC
6095@item derivations
6096This is the most detailed representation: It shows the DAG of
6097derivations (@pxref{Derivations}) and plain store items. Compared to
6098the above representation, many additional nodes are visible, including
f97c9175 6099build scripts, patches, Guile modules, etc.
88856916 6100
a773c314
LC
6101For this type of graph, it is also possible to pass a @file{.drv} file
6102name instead of a package name, as in:
6103
6104@example
6105guix graph -t derivation `guix system build -d my-config.scm`
6106@end example
88856916
LC
6107@end table
6108
f97c9175 6109All the types above correspond to @emph{build-time dependencies}. The
88856916
LC
6110following graph type represents the @emph{run-time dependencies}:
6111
6112@table @code
6113@item references
6114This is the graph of @dfn{references} of a package output, as returned
6115by @command{guix gc --references} (@pxref{Invoking guix gc}).
6116
6117If the given package output is not available in the store, @command{guix
6118graph} attempts to obtain dependency information from substitutes.
a773c314
LC
6119
6120Here you can also pass a store file name instead of a package name. For
6121example, the command below produces the reference graph of your profile
6122(which can be big!):
6123
6124@example
6125guix graph -t references `readlink -f ~/.guix-profile`
6126@end example
7f8fec0f
LC
6127
6128@item referrers
6129This is the graph of the @dfn{referrers} of a store item, as returned by
6130@command{guix gc --referrers} (@pxref{Invoking guix gc}).
6131
6132This relies exclusively on local information from your store. For
6133instance, let us suppose that the current Inkscape is available in 10
6134profiles on your machine; @command{guix graph -t referrers inkscape}
6135will show a graph rooted at Inkscape and with those 10 profiles linked
6136to it.
6137
6138It can help determine what is preventing a store item from being garbage
6139collected.
6140
88856916
LC
6141@end table
6142
6143The available options are the following:
6144
6145@table @option
6146@item --type=@var{type}
6147@itemx -t @var{type}
6148Produce a graph output of @var{type}, where @var{type} must be one of
6149the values listed above.
6150
6151@item --list-types
6152List the supported graph types.
4c8f997a 6153
642339dc
RW
6154@item --backend=@var{backend}
6155@itemx -b @var{backend}
6156Produce a graph using the selected @var{backend}.
6157
6158@item --list-backends
6159List the supported graph backends.
6160
9ea36197
LC
6161Currently, the available backends are Graphviz and d3.js.
6162
4c8f997a
LC
6163@item --expression=@var{expr}
6164@itemx -e @var{expr}
6165Consider the package @var{expr} evaluates to.
6166
6167This is useful to precisely refer to a package, as in this example:
6168
6169@example
6170guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
6171@end example
88856916
LC
6172@end table
6173
6174
372c4bbc
DT
6175@node Invoking guix environment
6176@section Invoking @command{guix environment}
6177
f5fd4fd2 6178@cindex reproducible build environments
fe36d84e 6179@cindex development environments
e32171ee
JD
6180@cindex @command{guix environment}
6181@cindex environment, package build environment
372c4bbc
DT
6182The purpose of @command{guix environment} is to assist hackers in
6183creating reproducible development environments without polluting their
6184package profile. The @command{guix environment} tool takes one or more
f97c9175 6185packages, builds all of their inputs, and creates a shell
372c4bbc
DT
6186environment to use them.
6187
6188The general syntax is:
6189
6190@example
6191guix environment @var{options} @var{package}@dots{}
6192@end example
6193
fe36d84e
LC
6194The following example spawns a new shell set up for the development of
6195GNU@tie{}Guile:
372c4bbc
DT
6196
6197@example
6198guix environment guile
6199@end example
6200
f97c9175
AE
6201If the needed dependencies are not built yet, @command{guix environment}
6202automatically builds them. The environment of the new shell is an augmented
372c4bbc
DT
6203version of the environment that @command{guix environment} was run in.
6204It contains the necessary search paths for building the given package
6205added to the existing environment variables. To create a ``pure''
f97c9175 6206environment, in which the original environment variables have been unset,
50500f7c
LC
6207use the @code{--pure} option@footnote{Users sometimes wrongfully augment
6208environment variables such as @code{PATH} in their @file{~/.bashrc}
6209file. As a consequence, when @code{guix environment} launches it, Bash
6210may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
6211environment variables. It is an error to define such environment
6212variables in @file{.bashrc}; instead, they should be defined in
6213@file{.bash_profile}, which is sourced only by log-in shells.
6214@xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
6215details on Bash start-up files.}.
372c4bbc 6216
28de8d25
LC
6217@vindex GUIX_ENVIRONMENT
6218@command{guix environment} defines the @code{GUIX_ENVIRONMENT}
20185522
LC
6219variable in the shell it spawns; its value is the file name of the
6220profile of this environment. This allows users to, say, define a
28de8d25
LC
6221specific prompt for development environments in their @file{.bashrc}
6222(@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
6223
6224@example
6225if [ -n "$GUIX_ENVIRONMENT" ]
6226then
6227 export PS1="\u@@\h \w [dev]\$ "
6228fi
6229@end example
6230
20185522
LC
6231@noindent
6232... or to browse the profile:
6233
6234@example
6235$ ls "$GUIX_ENVIRONMENT/bin"
6236@end example
6237
372c4bbc
DT
6238Additionally, more than one package may be specified, in which case the
6239union of the inputs for the given packages are used. For example, the
6240command below spawns a shell where all of the dependencies of both Guile
6241and Emacs are available:
6242
6243@example
6244guix environment guile emacs
6245@end example
6246
1de2fe95
DT
6247Sometimes an interactive shell session is not desired. An arbitrary
6248command may be invoked by placing the @code{--} token to separate the
6249command from the rest of the arguments:
372c4bbc
DT
6250
6251@example
1de2fe95 6252guix environment guile -- make -j4
372c4bbc
DT
6253@end example
6254
fe36d84e
LC
6255In other situations, it is more convenient to specify the list of
6256packages needed in the environment. For example, the following command
6257runs @command{python} from an environment containing Python@tie{}2.7 and
6258NumPy:
6259
6260@example
1de2fe95 6261guix environment --ad-hoc python2-numpy python-2.7 -- python
fe36d84e
LC
6262@end example
6263
cc90fbbf
DT
6264Furthermore, one might want the dependencies of a package and also some
6265additional packages that are not build-time or runtime dependencies, but
6266are useful when developing nonetheless. Because of this, the
6267@code{--ad-hoc} flag is positional. Packages appearing before
6268@code{--ad-hoc} are interpreted as packages whose dependencies will be
6269added to the environment. Packages appearing after are interpreted as
6270packages that will be added to the environment directly. For example,
6271the following command creates a Guix development environment that
6272additionally includes Git and strace:
6273
6274@example
6275guix environment guix --ad-hoc git strace
6276@end example
6277
f535dcbe
DT
6278Sometimes it is desirable to isolate the environment as much as
6279possible, for maximal purity and reproducibility. In particular, when
6280using Guix on a host distro that is not GuixSD, it is desirable to
6281prevent access to @file{/usr/bin} and other system-wide resources from
6282the development environment. For example, the following command spawns
6283a Guile REPL in a ``container'' where only the store and the current
6284working directory are mounted:
6285
6286@example
6287guix environment --ad-hoc --container guile -- guile
6288@end example
6289
0f252e26 6290@quotation Note
cfd35b4e 6291The @code{--container} option requires Linux-libre 3.19 or newer.
0f252e26
DT
6292@end quotation
6293
fe36d84e 6294The available options are summarized below.
372c4bbc
DT
6295
6296@table @code
f943c317
LC
6297@item --root=@var{file}
6298@itemx -r @var{file}
6299@cindex persistent environment
6300@cindex garbage collector root, for environments
6301Make @var{file} a symlink to the profile for this environment, and
6302register it as a garbage collector root.
6303
6304This is useful if you want to protect your environment from garbage
6305collection, to make it ``persistent''.
6306
6307When this option is omitted, the environment is protected from garbage
6308collection only for the duration of the @command{guix environment}
6309session. This means that next time you recreate the same environment,
6310you could have to rebuild or re-download packages.
6311
372c4bbc
DT
6312@item --expression=@var{expr}
6313@itemx -e @var{expr}
c9c282ce
DT
6314Create an environment for the package or list of packages that
6315@var{expr} evaluates to.
372c4bbc 6316
fe36d84e
LC
6317For example, running:
6318
6319@example
6320guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
6321@end example
6322
6323starts a shell with the environment for this specific variant of the
6324PETSc package.
6325
c9c282ce
DT
6326Running:
6327
6328@example
5c2b2f00 6329guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
c9c282ce
DT
6330@end example
6331
6332starts a shell with all the GuixSD base packages available.
6333
fa445d64 6334The above commands only use the default output of the given packages.
779aa003
DT
6335To select other outputs, two element tuples can be specified:
6336
6337@example
6338guix environment --ad-hoc -e '(list (@ (gnu packages bash) bash) "include")'
6339@end example
6340
372c4bbc
DT
6341@item --load=@var{file}
6342@itemx -l @var{file}
c9c282ce
DT
6343Create an environment for the package or list of packages that the code
6344within @var{file} evaluates to.
372c4bbc 6345
fe36d84e
LC
6346As an example, @var{file} might contain a definition like this
6347(@pxref{Defining Packages}):
6348
6349@example
6350@verbatiminclude environment-gdb.scm
6351@end example
6352
a54bd6d7
DT
6353@item --ad-hoc
6354Include all specified packages in the resulting environment, as if an
6355@i{ad hoc} package were defined with them as inputs. This option is
6356useful for quickly creating an environment without having to write a
6357package expression to contain the desired inputs.
6358
6359For instance, the command:
6360
6361@example
1de2fe95 6362guix environment --ad-hoc guile guile-sdl -- guile
a54bd6d7
DT
6363@end example
6364
6365runs @command{guile} in an environment where Guile and Guile-SDL are
6366available.
6367
417c39f1 6368Note that this example implicitly asks for the default output of
f97c9175 6369@code{guile} and @code{guile-sdl}, but it is possible to ask for a
417c39f1
LC
6370specific output---e.g., @code{glib:bin} asks for the @code{bin} output
6371of @code{glib} (@pxref{Packages with Multiple Outputs}).
6372
cc90fbbf
DT
6373This option may be composed with the default behavior of @command{guix
6374environment}. Packages appearing before @code{--ad-hoc} are interpreted
6375as packages whose dependencies will be added to the environment, the
6376default behavior. Packages appearing after are interpreted as packages
6377that will be added to the environment directly.
6378
372c4bbc
DT
6379@item --pure
6380Unset existing environment variables when building the new environment.
6381This has the effect of creating an environment in which search paths
6382only contain package inputs.
6383
6384@item --search-paths
6385Display the environment variable definitions that make up the
6386environment.
ce367ef3
LC
6387
6388@item --system=@var{system}
6389@itemx -s @var{system}
6390Attempt to build for @var{system}---e.g., @code{i686-linux}.
f535dcbe
DT
6391
6392@item --container
6393@itemx -C
6394@cindex container
6395Run @var{command} within an isolated container. The current working
a01ad638
DT
6396directory outside the container is mapped inside the container.
6397Additionally, a dummy home directory is created that matches the current
6398user's home directory, and @file{/etc/passwd} is configured accordingly.
6399The spawned process runs as the current user outside the container, but
6400has root privileges in the context of the container.
f535dcbe
DT
6401
6402@item --network
6403@itemx -N
6404For containers, share the network namespace with the host system.
6405Containers created without this flag only have access to the loopback
6406device.
6407
6408@item --expose=@var{source}[=@var{target}]
6409For containers, expose the file system @var{source} from the host system
6410as the read-only file system @var{target} within the container. If
6411@var{target} is not specified, @var{source} is used as the target mount
6412point in the container.
6413
6414The example below spawns a Guile REPL in a container in which the user's
6415home directory is accessible read-only via the @file{/exchange}
6416directory:
6417
6418@example
da31b9c7 6419guix environment --container --expose=$HOME=/exchange --ad-hoc guile -- guile
f535dcbe
DT
6420@end example
6421
5c2b2f00 6422@item --share=@var{source}[=@var{target}]
f535dcbe
DT
6423For containers, share the file system @var{source} from the host system
6424as the writable file system @var{target} within the container. If
6425@var{target} is not specified, @var{source} is used as the target mount
6426point in the container.
6427
6428The example below spawns a Guile REPL in a container in which the user's
6429home directory is accessible for both reading and writing via the
6430@file{/exchange} directory:
6431
6432@example
da31b9c7 6433guix environment --container --share=$HOME=/exchange --ad-hoc guile -- guile
f535dcbe 6434@end example
372c4bbc
DT
6435@end table
6436
fdcb04af
HG
6437@command{guix environment}
6438also supports all of the common build options that @command{guix
ccd7158d 6439build} supports (@pxref{Common Build Options}).
372c4bbc 6440
fdcb04af 6441
aff8ce7c
DT
6442@node Invoking guix publish
6443@section Invoking @command{guix publish}
6444
e32171ee 6445@cindex @command{guix publish}
aff8ce7c 6446The purpose of @command{guix publish} is to enable users to easily share
f97c9175 6447their store with others, who can then use it as a substitute server
8ce229fc
LC
6448(@pxref{Substitutes}).
6449
6450When @command{guix publish} runs, it spawns an HTTP server which allows
6451anyone with network access to obtain substitutes from it. This means
6452that any machine running Guix can also act as if it were a build farm,
6453since the HTTP interface is compatible with Hydra, the software behind
6454the @code{hydra.gnu.org} build farm.
aff8ce7c
DT
6455
6456For security, each substitute is signed, allowing recipients to check
6457their authenticity and integrity (@pxref{Substitutes}). Because
f97c9175 6458@command{guix publish} uses the signing key of the system, which is only
5463fe51
LC
6459readable by the system administrator, it must be started as root; the
6460@code{--user} option makes it drop root privileges early on.
aff8ce7c 6461
b18812b6
LC
6462The signing key pair must be generated before @command{guix publish} is
6463launched, using @command{guix archive --generate-key} (@pxref{Invoking
6464guix archive}).
6465
aff8ce7c
DT
6466The general syntax is:
6467
6468@example
6469guix publish @var{options}@dots{}
6470@end example
6471
6472Running @command{guix publish} without any additional arguments will
6473spawn an HTTP server on port 8080:
6474
6475@example
6476guix publish
6477@end example
6478
6479Once a publishing server has been authorized (@pxref{Invoking guix
6480archive}), the daemon may download substitutes from it:
6481
6482@example
6483guix-daemon --substitute-urls=http://example.org:8080
6484@end example
6485
ff6638d1
LC
6486As a bonus, @command{guix publish} also serves as a content-addressed
6487mirror for source files referenced in @code{origin} records
6488(@pxref{origin Reference}). For instance, assuming @command{guix
6489publish} is running on @code{example.org}, the following URL returns the
6490raw @file{hello-2.10.tar.gz} file with the given SHA256 hash
6491(represented in @code{nix-base32} format, @pxref{Invoking guix hash}):
6492
6493@example
6494http://example.org/file/hello-2.10.tar.gz/sha256/0ssi1@dots{}ndq1i
6495@end example
6496
6497Obviously, these URLs only work for files that are in the store; in
6498other cases, they return 404 (``Not Found'').
6499
aff8ce7c
DT
6500The following options are available:
6501
6502@table @code
6503@item --port=@var{port}
6504@itemx -p @var{port}
6505Listen for HTTP requests on @var{port}.
6506
9e2292ef
LC
6507@item --listen=@var{host}
6508Listen on the network interface for @var{host}. The default is to
6509accept connections from any interface.
6510
5463fe51
LC
6511@item --user=@var{user}
6512@itemx -u @var{user}
6513Change privileges to @var{user} as soon as possible---i.e., once the
6514server socket is open and the signing key has been read.
6515
4a1fc562
LC
6516@item --compression[=@var{level}]
6517@itemx -C [@var{level}]
6518Compress data using the given @var{level}. When @var{level} is zero,
6519disable compression. The range 1 to 9 corresponds to different gzip
6520compression levels: 1 is the fastest, and 9 is the best (CPU-intensive).
6521The default is 3.
6522
4591c02e 6523Compression occurs on the fly and the compressed streams are not
4a1fc562
LC
6524cached. Thus, to reduce load on the machine that runs @command{guix
6525publish}, it may be a good idea to choose a low compression level, or to
6526run @command{guix publish} behind a caching proxy.
6527
e4c7a5f7
LC
6528@item --ttl=@var{ttl}
6529Produce @code{Cache-Control} HTTP headers that advertise a time-to-live
6530(TTL) of @var{ttl}. @var{ttl} must denote a duration: @code{5d} means 5
6531days, @code{1m} means 1 month, and so on.
6532
6533This allows the user's Guix to keep substitute information in cache for
6534@var{ttl}. However, note that @code{guix publish} does not itself
6535guarantee that the store items it provides will indeed remain available
6536for as long as @var{ttl}.
6537
4bb5e0ae
LC
6538@item --nar-path=@var{path}
6539Use @var{path} as the prefix for the URLs of ``nar'' files
6540(@pxref{Invoking guix archive, normalized archives}).
6541
6542By default, nars are served at a URL such as
6543@code{/nar/gzip/@dots{}-coreutils-8.25}. This option allows you to
6544change the @code{/nar} part to @var{path}.
6545
46f58390
LC
6546@item --public-key=@var{file}
6547@itemx --private-key=@var{file}
6548Use the specific @var{file}s as the public/private key pair used to sign
6549the store items being published.
6550
6551The files must correspond to the same key pair (the private key is used
6552for signing and the public key is merely advertised in the signature
6553metadata). They must contain keys in the canonical s-expression format
6554as produced by @command{guix archive --generate-key} (@pxref{Invoking
6555guix archive}). By default, @file{/etc/guix/signing-key.pub} and
6556@file{/etc/guix/signing-key.sec} are used.
6557
aff8ce7c
DT
6558@item --repl[=@var{port}]
6559@itemx -r [@var{port}]
6560Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8ce229fc
LC
6561Reference Manual}) on @var{port} (37146 by default). This is used
6562primarily for debugging a running @command{guix publish} server.
aff8ce7c
DT
6563@end table
6564
1c52181f 6565Enabling @command{guix publish} on a GuixSD system is a one-liner: just
f1e900a3
LC
6566instantiate a @code{guix-publish-service-type} service in the @code{services} field
6567of the @code{operating-system} declaration (@pxref{guix-publish-service-type,
6568@code{guix-publish-service-type}}).
1c52181f 6569
332d7903
HG
6570If you are instead running Guix on a ``foreign distro'', follow these
6571instructions:”
6572
6573@itemize
6574@item
6575If your host distro uses the systemd init system:
6576
6577@example
6578# ln -s ~root/.guix-profile/lib/systemd/system/guix-publish.service \
6579 /etc/systemd/system/
6580# systemctl start guix-publish && systemctl enable guix-publish
6581@end example
6582
6583@item
6584If your host distro uses the Upstart init system:
6585
6586@example
6587# ln -s ~root/.guix-profile/lib/upstart/system/guix-publish.conf /etc/init/
6588# start guix-publish
6589@end example
6590
6591@item
6592Otherwise, proceed similarly with your distro's init system.
6593@end itemize
d23c20f1
LC
6594
6595@node Invoking guix challenge
6596@section Invoking @command{guix challenge}
6597
6598@cindex reproducible builds
6599@cindex verifiable builds
e32171ee
JD
6600@cindex @command{guix challenge}
6601@cindex challenge
d23c20f1 6602Do the binaries provided by this server really correspond to the source
f97c9175 6603code it claims to build? Is a package build process deterministic?
d23c20f1
LC
6604These are the questions the @command{guix challenge} command attempts to
6605answer.
6606
6607The former is obviously an important question: Before using a substitute
f97c9175 6608server (@pxref{Substitutes}), one had better @emph{verify} that it
d23c20f1
LC
6609provides the right binaries, and thus @emph{challenge} it. The latter
6610is what enables the former: If package builds are deterministic, then
6611independent builds of the package should yield the exact same result,
6612bit for bit; if a server provides a binary different from the one
6613obtained locally, it may be either corrupt or malicious.
6614
6615We know that the hash that shows up in @file{/gnu/store} file names is
6616the hash of all the inputs of the process that built the file or
6617directory---compilers, libraries, build scripts,
6618etc. (@pxref{Introduction}). Assuming deterministic build processes,
6619one store file name should map to exactly one build output.
6620@command{guix challenge} checks whether there is, indeed, a single
6621mapping by comparing the build outputs of several independent builds of
6622any given store item.
6623
f97c9175 6624The command output looks like this:
d23c20f1
LC
6625
6626@smallexample
ddbc7f7d
LC
6627$ guix challenge --substitute-urls="https://hydra.gnu.org https://guix.example.org"
6628updating list of substitutes from 'https://hydra.gnu.org'... 100.0%
6629updating list of substitutes from 'https://guix.example.org'... 100.0%
d23c20f1
LC
6630/gnu/store/@dots{}-openssl-1.0.2d contents differ:
6631 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
ddbc7f7d
LC
6632 https://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
6633 https://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
d23c20f1
LC
6634/gnu/store/@dots{}-git-2.5.0 contents differ:
6635 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
ddbc7f7d
LC
6636 https://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
6637 https://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
d23c20f1
LC
6638/gnu/store/@dots{}-pius-2.1.1 contents differ:
6639 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
ddbc7f7d
LC
6640 https://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
6641 https://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
d23c20f1
LC
6642@end smallexample
6643
6644@noindent
6645In this example, @command{guix challenge} first scans the store to
6646determine the set of locally-built derivations---as opposed to store
6647items that were downloaded from a substitute server---and then queries
6648all the substitute servers. It then reports those store items for which
6649the servers obtained a result different from the local build.
6650
6651@cindex non-determinism, in package builds
6652As an example, @code{guix.example.org} always gets a different answer.
6653Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
6654case of Git. This might indicate that the build process of Git is
6655non-deterministic, meaning that its output varies as a function of
6656various things that Guix does not fully control, in spite of building
6657packages in isolated environments (@pxref{Features}). Most common
6658sources of non-determinism include the addition of timestamps in build
6659results, the inclusion of random numbers, and directory listings sorted
a70a5004 6660by inode number. See @uref{https://reproducible-builds.org/docs/}, for
d23c20f1
LC
6661more information.
6662
f97c9175 6663To find out what is wrong with this Git binary, we can do something along
d23c20f1
LC
6664these lines (@pxref{Invoking guix archive}):
6665
6666@example
ddbc7f7d 6667$ wget -q -O - https://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
d23c20f1 6668 | guix archive -x /tmp/git
043f4698 6669$ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
d23c20f1
LC
6670@end example
6671
6672This command shows the difference between the files resulting from the
6673local build, and the files resulting from the build on
6674@code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
6675diffutils, Comparing and Merging Files}). The @command{diff} command
6676works great for text files. When binary files differ, a better option
ddbc7f7d 6677is @uref{https://diffoscope.org/, Diffoscope}, a tool that helps
d23c20f1
LC
6678visualize differences for all kinds of files.
6679
f97c9175 6680Once you have done that work, you can tell whether the differences are due
d23c20f1
LC
6681to a non-deterministic build process or to a malicious server. We try
6682hard to remove sources of non-determinism in packages to make it easier
f97c9175
AE
6683to verify substitutes, but of course, this is a process that
6684involves not just Guix, but a large part of the free software community.
d23c20f1
LC
6685In the meantime, @command{guix challenge} is one tool to help address
6686the problem.
6687
6688If you are writing packages for Guix, you are encouraged to check
6689whether @code{hydra.gnu.org} and other substitute servers obtain the
6690same build result as you did with:
6691
6692@example
6693$ guix challenge @var{package}
6694@end example
6695
6696@noindent
f97c9175 6697where @var{package} is a package specification such as
7cffaeb6 6698@code{guile@@2.0} or @code{glibc:debug}.
d23c20f1
LC
6699
6700The general syntax is:
6701
6702@example
6703guix challenge @var{options} [@var{packages}@dots{}]
6704@end example
6705
7cffaeb6
LC
6706When a difference is found between the hash of a locally-built item and
6707that of a server-provided substitute, or among substitutes provided by
6708different servers, the command displays it as in the example above and
a17417a8
LC
6709its exit code is 2 (other non-zero exit codes denote other kinds of
6710errors.)
7cffaeb6 6711
d23c20f1
LC
6712The one option that matters is:
6713
6714@table @code
6715
6716@item --substitute-urls=@var{urls}
6717Consider @var{urls} the whitespace-separated list of substitute source
6718URLs to compare to.
6719
153b6295
LC
6720@item --verbose
6721@itemx -v
6722Show details about matches (identical contents) in addition to
6723information about mismatches.
6724
d23c20f1
LC
6725@end table
6726
f11c444d
LC
6727@node Invoking guix copy
6728@section Invoking @command{guix copy}
6729
6730@cindex copy, of store items, over SSH
6731@cindex SSH, copy of store items
6732@cindex sharing store items across machines
6733@cindex transferring store items across machines
6734The @command{guix copy} command copies items from the store of one
6735machine to that of another machine over a secure shell (SSH)
6736connection@footnote{This command is available only when Guile-SSH was
6737found. @xref{Requirements}, for details.}. For example, the following
6738command copies the @code{coreutils} package, the user's profile, and all
6739their dependencies over to @var{host}, logged in as @var{user}:
6740
6741@example
6742guix copy --to=@var{user}@@@var{host} \
6743 coreutils `readlink -f ~/.guix-profile`
6744@end example
6745
6746If some of the items to be copied are already present on @var{host},
6747they are not actually sent.
6748
6749The command below retrieves @code{libreoffice} and @code{gimp} from
6750@var{host}, assuming they are available there:
6751
6752@example
6753guix copy --from=@var{host} libreoffice gimp
6754@end example
6755
6756The SSH connection is established using the Guile-SSH client, which is
6757compatible with OpenSSH: it honors @file{~/.ssh/known_hosts} and
6758@file{~/.ssh/config}, and uses the SSH agent for authentication.
6759
6760The key used to sign items that are sent must be accepted by the remote
6761machine. Likewise, the key used by the remote machine to sign items you
6762are retrieving must be in @file{/etc/guix/acl} so it is accepted by your
6763own daemon. @xref{Invoking guix archive}, for more information about
6764store item authentication.
6765
6766The general syntax is:
6767
6768@example
6769guix copy [--to=@var{spec}|--from=@var{spec}] @var{items}@dots{}
6770@end example
6771
6772You must always specify one of the following options:
6773
6774@table @code
6775@item --to=@var{spec}
6776@itemx --from=@var{spec}
6777Specify the host to send to or receive from. @var{spec} must be an SSH
6778spec such as @code{example.org}, @code{charlie@@example.org}, or
6779@code{charlie@@example.org:2222}.
6780@end table
6781
6782The @var{items} can be either package names, such as @code{gimp}, or
6783store items, such as @file{/gnu/store/@dots{}-idutils-4.6}.
6784
6785When specifying the name of a package to send, it is first built if
6786needed, unless @option{--dry-run} was specified. Common build options
6787are supported (@pxref{Common Build Options}).
6788
d23c20f1 6789
32efa254
DT
6790@node Invoking guix container
6791@section Invoking @command{guix container}
6792@cindex container
e32171ee 6793@cindex @command{guix container}
32efa254
DT
6794@quotation Note
6795As of version @value{VERSION}, this tool is experimental. The interface
6796is subject to radical change in the future.
6797@end quotation
6798
6799The purpose of @command{guix container} is to manipulate processes
6800running within an isolated environment, commonly known as a
46c36586 6801``container'', typically created by the @command{guix environment}
32efa254
DT
6802(@pxref{Invoking guix environment}) and @command{guix system container}
6803(@pxref{Invoking guix system}) commands.
6804
6805The general syntax is:
6806
6807@example
6808guix container @var{action} @var{options}@dots{}
6809@end example
6810
6811@var{action} specifies the operation to perform with a container, and
6812@var{options} specifies the context-specific arguments for the action.
6813
6814The following actions are available:
6815
6816@table @code
6817@item exec
6818Execute a command within the context of a running container.
6819
6820The syntax is:
6821
6822@example
6823guix container exec @var{pid} @var{program} @var{arguments}@dots{}
6824@end example
6825
6826@var{pid} specifies the process ID of the running container.
f97c9175
AE
6827@var{program} specifies an executable file name within the root file
6828system of the container. @var{arguments} are the additional options that
6829will be passed to @var{program}.
32efa254
DT
6830
6831The following command launches an interactive login shell inside a
6832GuixSD container, started by @command{guix system container}, and whose
6833process ID is 9001:
6834
6835@example
6836guix container exec 9001 /run/current-system/profile/bin/bash --login
6837@end example
6838
6839Note that the @var{pid} cannot be the parent process of a container. It
f97c9175 6840must be PID 1 of the container or one of its child processes.
32efa254
DT
6841
6842@end table
6843
a1ba8475
LC
6844@c *********************************************************************
6845@node GNU Distribution
6846@chapter GNU Distribution
6847
3ca2731c 6848@cindex Guix System Distribution
4705641f 6849@cindex GuixSD
3ca2731c
LC
6850Guix comes with a distribution of the GNU system consisting entirely of
6851free software@footnote{The term ``free'' here refers to the
a1ba8475 6852@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 6853users of that software}.}. The
35ed9306
LC
6854distribution can be installed on its own (@pxref{System Installation}),
6855but it is also possible to install Guix as a package manager on top of
6856an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c 6857between the two, we refer to the standalone distribution as the Guix
4705641f 6858System Distribution, or GuixSD.
35ed9306
LC
6859
6860The distribution provides core GNU packages such as GNU libc, GCC, and
6861Binutils, as well as many GNU and non-GNU applications. The complete
6862list of available packages can be browsed
093ae1be 6863@url{http://www.gnu.org/software/guix/packages,on-line} or by
d03bb653 6864running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
6865
6866@example
e49951eb 6867guix package --list-available
a1ba8475
LC
6868@end example
6869
f97c9175 6870Our goal is to provide a practical 100% free software distribution of
401c53c4
LC
6871Linux-based and other variants of GNU, with a focus on the promotion and
6872tight integration of GNU components, and an emphasis on programs and
6873tools that help users exert that freedom.
6874
3ca2731c 6875Packages are currently available on the following platforms:
c320011d
LC
6876
6877@table @code
6878
6879@item x86_64-linux
6880Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
6881
6882@item i686-linux
6883Intel 32-bit architecture (IA32), Linux-Libre kernel;
6884
aa1e1947 6885@item armhf-linux
aa725117 6886ARMv7-A architecture with hard float, Thumb-2 and NEON,
f97c9175
AE
6887using the EABI hard-float application binary interface (ABI),
6888and Linux-Libre kernel.
aa1e1947 6889
3b88f376
EF
6890@item aarch64-linux
6891little-endian 64-bit ARMv8-A processors, Linux-Libre kernel. This is
be2ba697 6892currently in an experimental stage, with limited support.
3b88f376
EF
6893@xref{Contributing}, for how to help!
6894
c320011d
LC
6895@item mips64el-linux
6896little-endian 64-bit MIPS processors, specifically the Loongson series,
f97c9175 6897n32 ABI, and Linux-Libre kernel.
c320011d
LC
6898
6899@end table
6900
4705641f 6901GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
3ca2731c 6902
c320011d
LC
6903@noindent
6904For information on porting to other architectures or kernels,
f97c9175 6905@pxref{Porting}.
c320011d 6906
401c53c4 6907@menu
5af6de3e 6908* System Installation:: Installing the whole operating system.
35ed9306 6909* System Configuration:: Configuring the operating system.
91ef73d4 6910* Installing Debugging Files:: Feeding the debugger.
05962f29 6911* Security Updates:: Deploying security fixes quickly.
401c53c4 6912* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 6913* Packaging Guidelines:: Growing the distribution.
401c53c4 6914* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 6915* Porting:: Targeting another platform or kernel.
401c53c4
LC
6916@end menu
6917
6918Building this distribution is a cooperative effort, and you are invited
081145cf 6919to join! @xref{Contributing}, for information about how you can help.
401c53c4 6920
5af6de3e
LC
6921@node System Installation
6922@section System Installation
6923
e32171ee 6924@cindex installing GuixSD
3ca2731c 6925@cindex Guix System Distribution
c8b54374 6926This section explains how to install the Guix System Distribution (GuixSD)
3ca2731c 6927on a machine. The Guix package manager can
35ed9306
LC
6928also be installed on top of a running GNU/Linux system,
6929@pxref{Installation}.
5af6de3e
LC
6930
6931@ifinfo
9c18cf9b 6932@quotation Note
5af6de3e
LC
6933@c This paragraph is for people reading this from tty2 of the
6934@c installation image.
1068f26b 6935You are reading this documentation with an Info reader. For details on
5af6de3e 6936how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
de341e7c
LC
6937link that follows: @pxref{Top, Info reader,, info-stnd, Stand-alone GNU
6938Info}. Hit @kbd{l} afterwards to come back here.
9c18cf9b
LC
6939
6940Alternately, run @command{info info} in another tty to keep the manual
6941available.
6942@end quotation
5af6de3e
LC
6943@end ifinfo
6944
dedb8d5e 6945@menu
e3009f60
LC
6946* Limitations:: What you can expect.
6947* Hardware Considerations:: Supported hardware.
6948* USB Stick Installation:: Preparing the installation medium.
6949* Preparing for Installation:: Networking, partitioning, etc.
6950* Proceeding with the Installation:: The real thing.
c8b54374 6951* Installing GuixSD in a VM:: GuixSD playground.
e3009f60 6952* Building the Installation Image:: How this comes to be.
dedb8d5e
LC
6953@end menu
6954
6955@node Limitations
8aaaae38
LC
6956@subsection Limitations
6957
4705641f 6958As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
3ca2731c 6959not production-ready. It may contain bugs and lack important
8aaaae38
LC
6960features. Thus, if you are looking for a stable production system that
6961respects your freedom as a computer user, a good solution at this point
6962is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
f97c9175 6963the more established GNU/Linux distributions}. We hope you can soon switch
4705641f 6964to the GuixSD without fear, of course. In the meantime, you can
8aaaae38
LC
6965also keep using your distribution and try out the package manager on top
6966of it (@pxref{Installation}).
6967
6968Before you proceed with the installation, be aware of the following
6969noteworthy limitations applicable to version @value{VERSION}:
6970
6971@itemize
6972@item
6973The installation process does not include a graphical user interface and
6974requires familiarity with GNU/Linux (see the following subsections to
6975get a feel of what that means.)
6976
8aaaae38 6977@item
dbcb0ab1 6978Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
6979
6980@item
6981Few system services are currently supported out-of-the-box
6982(@pxref{Services}).
6983
6984@item
4018745a 6985More than 5,000 packages are available, but you may
8aaaae38 6986occasionally find that a useful package is missing.
5fe01c2d
LC
6987
6988@item
6989GNOME, Xfce, and Enlightenment are available (@pxref{Desktop Services}),
6990as well as a number of X11 window managers. However, some graphical
6991applications may be missing, as well as KDE.
8aaaae38
LC
6992@end itemize
6993
f97c9175
AE
6994You have been warned! But more than a disclaimer, this is an invitation
6995to report issues (and success stories!), and to join us in improving it.
8aaaae38 6996@xref{Contributing}, for more info.
5af6de3e 6997
e3009f60
LC
6998
6999@node Hardware Considerations
7000@subsection Hardware Considerations
7001
7002@cindex hardware support on GuixSD
7003GNU@tie{}GuixSD focuses on respecting the user's computing freedom. It
7004builds around the kernel Linux-libre, which means that only hardware for
e0b3f97e 7005which free software drivers and firmware exist is supported. Nowadays,
e3009f60
LC
7006a wide range of off-the-shelf hardware is supported on
7007GNU/Linux-libre---from keyboards to graphics cards to scanners and
7008Ethernet controllers. Unfortunately, there are still areas where
7009hardware vendors deny users control over their own computing, and such
7010hardware is not supported on GuixSD.
7011
7012@cindex WiFi, hardware support
e0b3f97e 7013One of the main areas where free drivers or firmware are lacking is WiFi
e3009f60
LC
7014devices. WiFi devices known to work include those using Atheros chips
7015(AR9271 and AR7010), which corresponds to the @code{ath9k} Linux-libre
52db41af
EB
7016driver, and those using Broadcom/AirForce chips (BCM43xx with
7017Wireless-Core Revision 5), which corresponds to the @code{b43-open}
7018Linux-libre driver. Free firmware exists for both and is available
e3009f60
LC
7019out-of-the-box on GuixSD, as part of @var{%base-firmware}
7020(@pxref{operating-system Reference, @code{firmware}}).
7021
7022@cindex RYF, Respects Your Freedom
7023The @uref{https://www.fsf.org/, Free Software Foundation} runs
e0b3f97e 7024@uref{https://www.fsf.org/ryf, @dfn{Respects Your Freedom}} (RYF), a
e3009f60
LC
7025certification program for hardware products that respect your freedom
7026and your privacy and ensure that you have control over your device. We
e0b3f97e 7027encourage you to check the list of RYF-certified devices.
e3009f60
LC
7028
7029Another useful resource is the @uref{https://www.h-node.org/, H-Node}
7030web site. It contains a catalog of hardware devices with information
7031about their support in GNU/Linux.
7032
7033
dedb8d5e 7034@node USB Stick Installation
5af6de3e
LC
7035@subsection USB Stick Installation
7036
7037An installation image for USB sticks can be downloaded from
4705641f 7038@indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
7039where @var{system} is one of:
7040
7041@table @code
7042@item x86_64-linux
7043for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
7044
7045@item i686-linux
7046for a 32-bit GNU/Linux system on Intel-compatible CPUs.
7047@end table
7048
debc6360
LC
7049@c start duplication of authentication part from ``Binary Installation''
7050Make sure to download the associated @file{.sig} file and to verify the
7051authenticity of the image against it, along these lines:
7052
7053@example
7054$ wget ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz.sig
7055$ gpg --verify guixsd-usb-install-@value{VERSION}.@var{system}.xz.sig
7056@end example
7057
7058If that command fails because you do not have the required public key,
7059then run this command to import it:
7060
7061@example
7062$ gpg --keyserver pgp.mit.edu --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
7063@end example
7064
7065@noindent
7066and rerun the @code{gpg --verify} command.
7067@c end duplication
7068
5af6de3e
LC
7069This image contains a single partition with the tools necessary for an
7070installation. It is meant to be copied @emph{as is} to a large-enough
7071USB stick.
7072
7073To copy the image to a USB stick, follow these steps:
7074
7075@enumerate
7076@item
7077Decompress the image using the @command{xz} command:
7078
7079@example
4705641f 7080xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
7081@end example
7082
7083@item
f97c9175
AE
7084Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
7085its device name. Assuming that the USB stick is known as @file{/dev/sdX},
5af6de3e
LC
7086copy the image with:
7087
7088@example
4705641f 7089dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
7090@end example
7091
7092Access to @file{/dev/sdX} usually requires root privileges.
7093@end enumerate
7094
7095Once this is done, you should be able to reboot the system and boot from
7096the USB stick. The latter usually requires you to get in the BIOS' boot
7097menu, where you can choose to boot from the USB stick.
7098
c8b54374
VL
7099@xref{Installing GuixSD in a VM}, if, instead, you would like to install
7100GuixSD in a virtual machine (VM).
7101
dedb8d5e 7102@node Preparing for Installation
5af6de3e
LC
7103@subsection Preparing for Installation
7104
7105Once you have successfully booted the image on the USB stick, you should
7106end up with a root prompt. Several console TTYs are configured and can
7107be used to run commands as root. TTY2 shows this documentation,
de341e7c
LC
7108browsable using the Info reader commands (@pxref{Top,,, info-stnd,
7109Stand-alone GNU Info}). The installation system runs the GPM mouse
7110daemon, which allows you to select text with the left mouse button and
7111to paste it with the middle button.
5af6de3e 7112
ff925d37
LC
7113@quotation Note
7114Installation requires access to the Internet so that any missing
7115dependencies of your system configuration can be downloaded. See the
7116``Networking'' section below.
7117@end quotation
7118
0e69cf67
LC
7119The installation system includes many common tools needed for this task.
7120But it is also a full-blown GuixSD system, which means that you can
7121install additional packages, should you need it, using @command{guix
7122package} (@pxref{Invoking guix package}).
7123
dedb8d5e 7124@subsubsection Keyboard Layout
5af6de3e 7125
dedb8d5e
LC
7126@cindex keyboard layout
7127The installation image uses the US qwerty keyboard layout. If you want
7128to change it, you can use the @command{loadkeys} command. For example,
7129the following command selects the Dvorak keyboard layout:
5af6de3e 7130
dedb8d5e
LC
7131@example
7132loadkeys dvorak
7133@end example
7134
7135See the files under @file{/run/current-system/profile/share/keymaps} for
7136a list of available keyboard layouts. Run @command{man loadkeys} for
7137more information.
7138
7139@subsubsection Networking
7140
7141Run the following command see what your network interfaces are called:
235cba85
LC
7142
7143@example
dedb8d5e 7144ifconfig -a
235cba85
LC
7145@end example
7146
1713c37f
LC
7147@noindent
7148@dots{} or, using the GNU/Linux-specific @command{ip} command:
7149
7150@example
7151ip a
7152@end example
7153
95c559c1 7154@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
dedb8d5e
LC
7155Wired interfaces have a name starting with @samp{e}; for example, the
7156interface corresponding to the first on-board Ethernet controller is
7157called @samp{eno1}. Wireless interfaces have a name starting with
7158@samp{w}, like @samp{w1p2s0}.
7159
7160@table @asis
7161@item Wired connection
7162To configure a wired network run the following command, substituting
7163@var{interface} with the name of the wired interface you want to use.
7164
7165@example
7166ifconfig @var{interface} up
7167@end example
7168
7169@item Wireless connection
e32171ee
JD
7170@cindex wireless
7171@cindex WiFi
dedb8d5e
LC
7172To configure wireless networking, you can create a configuration file
7173for the @command{wpa_supplicant} configuration tool (its location is not
7174important) using one of the available text editors such as
7175@command{zile}:
7176
7177@example
7178zile wpa_supplicant.conf
7179@end example
7180
7181As an example, the following stanza can go to this file and will work
7182for many wireless networks, provided you give the actual SSID and
7183passphrase for the network you are connecting to:
7184
7185@example
7186network=@{
ae768308 7187 ssid="@var{my-ssid}"
dedb8d5e
LC
7188 key_mgmt=WPA-PSK
7189 psk="the network's secret passphrase"
7190@}
7191@end example
7192
7193Start the wireless service and run it in the background with the
7194following command (substitute @var{interface} with the name of the
7195network interface you want to use):
7196
7197@example
7198wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
7199@end example
7200
641d0518 7201Run @command{man wpa_supplicant} for more information.
dedb8d5e
LC
7202@end table
7203
e32171ee 7204@cindex DHCP
dedb8d5e
LC
7205At this point, you need to acquire an IP address. On a network where IP
7206addresses are automatically assigned @i{via} DHCP, you can run:
7207
7208@example
15650ac2 7209dhclient -v @var{interface}
dedb8d5e 7210@end example
5af6de3e 7211
dedb8d5e
LC
7212Try to ping a server to see if networking is up and running:
7213
7214@example
7215ping -c 3 gnu.org
7216@end example
5af6de3e
LC
7217
7218Setting up network access is almost always a requirement because the
7219image does not contain all the software and tools that may be needed.
7220
dedb8d5e
LC
7221@subsubsection Disk Partitioning
7222
7223Unless this has already been done, the next step is to partition, and
7224then format the target partition(s).
7225
7226The installation image includes several partitioning tools, including
7227Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
7228@command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
7229the partition layout you want:
7230
7231@example
7232cfdisk
7233@end example
7234
d918d79f
SB
7235If your disk uses the GUID Partition Table (GPT) format and you plan to
7236install BIOS-based GRUB (which is the default), make sure a BIOS Boot
7237Partition is available (@pxref{BIOS installation,,, grub, GNU GRUB
7238manual}).
7239
dedb8d5e
LC
7240Once you are done partitioning the target hard disk drive, you have to
7241create a file system on the relevant partition(s)@footnote{Currently
b1a505ba
DC
7242GuixSD only supports ext4 and btrfs file systems. In particular, code
7243that reads partition UUIDs and labels only works for these file system
7244types.}.
5af6de3e 7245
7ab44369
LC
7246Preferably, assign partitions a label so that you can easily and
7247reliably refer to them in @code{file-system} declarations (@pxref{File
7248Systems}). This is typically done using the @code{-L} option of
dedb8d5e
LC
7249@command{mkfs.ext4} and related commands. So, assuming the target root
7250partition lives at @file{/dev/sda1}, a file system with the label
7251@code{my-root} can be created with:
7ab44369 7252
dedb8d5e
LC
7253@example
7254mkfs.ext4 -L my-root /dev/sda1
7255@end example
dd816355 7256
13fb1bd9
LC
7257@cindex encrypted disk
7258If you are instead planning to encrypt the root partition, you can use
7259the Cryptsetup/LUKS utilities to do that (see @inlinefmtifelse{html,
7260@uref{https://linux.die.net/man/8/cryptsetup, @code{man cryptsetup}},
7261@code{man cryptsetup}} for more information.) Assuming you want to
7262store the root partition on @file{/dev/sda1}, the command sequence would
7263be along these lines:
6d6e6281 7264
13fb1bd9
LC
7265@example
7266cryptsetup luksFormat /dev/sda1
7267cryptsetup open --type luks /dev/sda1 my-partition
7268mkfs.ext4 -L my-root /dev/mapper/my-partition
7269@end example
5af6de3e 7270
dedb8d5e 7271Once that is done, mount the target root partition under @file{/mnt}
13fb1bd9
LC
7272with a command like (again, assuming @code{my-root} is the label of the
7273root partition):
83a17b62 7274
dedb8d5e 7275@example
13fb1bd9 7276mount LABEL=my-root /mnt
dedb8d5e 7277@end example
83a17b62 7278
31b6cdf8
LC
7279Finally, if you plan to use one or more swap partitions (@pxref{Memory
7280Concepts, swap space,, libc, The GNU C Library Reference Manual}), make
7281sure to initialize them with @command{mkswap}. Assuming you have one
7282swap partition on @file{/dev/sda2}, you would run:
7283
7284@example
7285mkswap /dev/sda2
b2ff76a0 7286swapon /dev/sda2
31b6cdf8
LC
7287@end example
7288
a4ca4362
CM
7289Alternatively, you may use a swap file. For example, assuming that in
7290the new system you want to use the file @file{/swapfile} as a swap file,
7291you would run@footnote{This example will work for many types of file
7292systems (e.g., ext4). However, for copy-on-write file systems (e.g.,
7293btrfs), the required steps may be different. For details, see the
7294manual pages for @command{mkswap} and @command{swapon}.}:
7295
7296@example
7297# This is 10 GiB of swap space. Adjust "count" to change the size.
7298dd if=/dev/zero of=/mnt/swapfile bs=1MiB count=10240
7299# For security, make the file readable and writable only by root.
7300chmod 600 /mnt/swapfile
7301mkswap /mnt/swapfile
7302swapon /mnt/swapfile
7303@end example
7304
7305Note that if you have encrypted the root partition and created a swap
7306file in its file system as described above, then the encryption also
7307protects the swap file, just like any other file in that file system.
7308
dedb8d5e
LC
7309@node Proceeding with the Installation
7310@subsection Proceeding with the Installation
83a17b62 7311
dedb8d5e
LC
7312With the target partitions ready and the target root mounted on
7313@file{/mnt}, we're ready to go. First, run:
5af6de3e 7314
dedb8d5e
LC
7315@example
7316herd start cow-store /mnt
7317@end example
5af6de3e 7318
b397c0d5
LC
7319This makes @file{/gnu/store} copy-on-write, such that packages added to it
7320during the installation phase are written to the target disk on @file{/mnt}
7321rather than kept in memory. This is necessary because the first phase of
7322the @command{guix system init} command (see below) entails downloads or
7323builds to @file{/gnu/store} which, initially, is an in-memory file system.
5af6de3e 7324
dedb8d5e 7325Next, you have to edit a file and
5af6de3e 7326provide the declaration of the operating system to be installed. To
a8cb87ab
LC
7327that end, the installation system comes with three text editors: GNU nano
7328(@pxref{Top,,, nano, GNU nano Manual}), GNU Zile (an Emacs clone), and
7329nvi (a clone of the original BSD @command{vi} editor).
efa77c6c
LC
7330We strongly recommend storing that file on the target root file system, say,
7331as @file{/mnt/etc/config.scm}. Failing to do that, you will have lost your
7332configuration file once you have rebooted into the newly-installed system.
5af6de3e 7333
dedb8d5e
LC
7334@xref{Using the Configuration System}, for an overview of the
7335configuration file. The example configurations discussed in that
7336section are available under @file{/etc/configuration} in the
7337installation image. Thus, to get started with a system configuration
7338providing a graphical display server (a ``desktop'' system), you can run
7339something along these lines:
7340
7341@example
7342# mkdir /mnt/etc
7343# cp /etc/configuration/desktop.scm /mnt/etc/config.scm
7344# zile /mnt/etc/config.scm
7345@end example
7346
7347You should pay attention to what your configuration file contains, and
7348in particular:
7349
7350@itemize
7351@item
7352Make sure the @code{grub-configuration} form refers to the device you
7353want to install GRUB on.
7354
7355@item
7356Be sure that your partition labels match the value of their respective
7357@code{device} fields in your @code{file-system} configuration, assuming
7358your @code{file-system} configuration sets the value of @code{title} to
7359@code{'label}.
13fb1bd9
LC
7360
7361@item
7362If there are encrypted or RAID partitions, make sure to add a
7363@code{mapped-devices} field to describe them (@pxref{Mapped Devices}).
dedb8d5e 7364@end itemize
5af6de3e 7365
dd51caac
LC
7366Once you are done preparing the configuration file, the new system must
7367be initialized (remember that the target root file system is mounted
7368under @file{/mnt}):
5af6de3e
LC
7369
7370@example
7371guix system init /mnt/etc/config.scm /mnt
7372@end example
7373
7374@noindent
dedb8d5e 7375This copies all the necessary files and installs GRUB on
5af6de3e 7376@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 7377more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
7378downloads or builds of missing packages, which can take some time.
7379
1bd4e6db
LC
7380Once that command has completed---and hopefully succeeded!---you can run
7381@command{reboot} and boot into the new system. The @code{root} password
7382in the new system is initially empty; other users' passwords need to be
7383initialized by running the @command{passwd} command as @code{root},
7384unless your configuration specifies otherwise
7385(@pxref{user-account-password, user account passwords}).
7386
7fcf2a0b
LC
7387@cindex upgrading GuixSD
7388From then on, you can update GuixSD whenever you want by running
7389@command{guix pull} as @code{root} (@pxref{Invoking guix pull}), and
7390then running @command{guix system reconfigure} to build a new system
7391generation with the latest packages and services (@pxref{Invoking guix
7392system}). We recommend doing that regularly so that your system
7393includes the latest security updates (@pxref{Security Updates}).
7394
1bd4e6db 7395Join us on @code{#guix} on the Freenode IRC network or on
5af6de3e
LC
7396@file{guix-devel@@gnu.org} to share your experience---good or not so
7397good.
7398
c8b54374
VL
7399@node Installing GuixSD in a VM
7400@subsection Installing GuixSD in a Virtual Machine
7401
7402@cindex virtual machine, GuixSD installation
7403If you'd like to install GuixSD in a virtual machine (VM) rather than on
7404your beloved machine, this section is for you.
7405
7406To boot a @uref{http://qemu.org/,QEMU} VM for installing GuixSD in a
7407disk image, follow these steps:
7408
7409@enumerate
7410@item
a0885414
LF
7411First, retrieve and decompress the GuixSD installation image as
7412described previously (@pxref{USB Stick Installation}).
c8b54374
VL
7413
7414@item
7415Create a disk image that will hold the installed system. To make a
7416qcow2-formatted disk image, use the @command{qemu-img} command:
7417
7418@example
7419qemu-img create -f qcow2 guixsd.img 5G
7420@end example
7421
7422This will create a 5GB file.
7423
7424@item
7425Boot the USB installation image in an VM:
7426
7427@example
7428qemu-system-x86_64 -m 1024 -smp 1 \
d36b8457 7429 -net user -net nic,model=virtio -boot menu=on \
c8b54374
VL
7430 -drive file=guixsd.img \
7431 -drive file=guixsd-usb-install-@value{VERSION}.@var{system}
7432@end example
7433
7434In the VM console, quickly press the @kbd{F12} key to enter the boot
7435menu. Then press the @kbd{2} key and the @kbd{RET} key to validate your
7436selection.
7437
7438@item
7439You're now root in the VM, proceed with the installation process.
7440@xref{Preparing for Installation}, and follow the instructions.
7441@end enumerate
7442
7443Once installation is complete, you can boot the system that's on your
7444@file{guixsd.img} image. @xref{Running GuixSD in a VM}, for how to do
7445that.
7446
dedb8d5e 7447@node Building the Installation Image
5af6de3e
LC
7448@subsection Building the Installation Image
7449
e32171ee 7450@cindex installation image
5af6de3e
LC
7451The installation image described above was built using the @command{guix
7452system} command, specifically:
7453
622b2304 7454@c FIXME: 1G is too much; see <http://bugs.gnu.org/23077>.
5af6de3e 7455@example
622b2304 7456guix system disk-image --image-size=1G gnu/system/install.scm
5af6de3e
LC
7457@end example
7458
6e6a0401
AE
7459Have a look at @file{gnu/system/install.scm} in the source tree,
7460and see also @ref{Invoking guix system} for more information
5af6de3e
LC
7461about the installation image.
7462
cf4a9129
LC
7463@node System Configuration
7464@section System Configuration
b208a005 7465
cf4a9129 7466@cindex system configuration
3ca2731c 7467The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
7468mechanism. By that we mean that all aspects of the global system
7469configuration---such as the available system services, timezone and
7470locale settings, user accounts---are declared in a single place. Such
7471a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 7472
cf4a9129
LC
7473One of the advantages of putting all the system configuration under the
7474control of Guix is that it supports transactional system upgrades, and
1068f26b 7475makes it possible to roll back to a previous system instantiation,
cf4a9129 7476should something go wrong with the new one (@pxref{Features}). Another
1068f26b 7477advantage is that it makes it easy to replicate the exact same configuration
cf4a9129
LC
7478across different machines, or at different points in time, without
7479having to resort to additional administration tools layered on top of
1068f26b 7480the own tools of the system.
cf4a9129 7481@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 7482
cf4a9129
LC
7483This section describes this mechanism. First we focus on the system
7484administrator's viewpoint---explaining how the system is configured and
7485instantiated. Then we show how this mechanism can be extended, for
7486instance to support new system services.
91ef73d4 7487
cf4a9129
LC
7488@menu
7489* Using the Configuration System:: Customizing your GNU system.
7313a52e 7490* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 7491* File Systems:: Configuring file system mounts.
510f9d86 7492* Mapped Devices:: Block device extra processing.
cf4a9129 7493* User Accounts:: Specifying user accounts.
598e19dc 7494* Locales:: Language and cultural convention settings.
cf4a9129 7495* Services:: Specifying system services.
0ae8c15a 7496* Setuid Programs:: Programs running with root privileges.
efb5e833 7497* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 7498* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 7499* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 7500* GRUB Configuration:: Configuring the boot loader.
cf4a9129 7501* Invoking guix system:: Instantiating a system configuration.
97d76250 7502* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
cf4a9129
LC
7503* Defining Services:: Adding new service definitions.
7504@end menu
91ef73d4 7505
cf4a9129
LC
7506@node Using the Configuration System
7507@subsection Using the Configuration System
64d76fa6 7508
cf4a9129
LC
7509The operating system is configured by providing an
7510@code{operating-system} declaration in a file that can then be passed to
7511the @command{guix system} command (@pxref{Invoking guix system}). A
7512simple setup, with the default system services, the default Linux-Libre
7513kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 7514
cf4a9129
LC
7515@findex operating-system
7516@lisp
dd51caac 7517@include os-config-bare-bones.texi
cf4a9129 7518@end lisp
401c53c4 7519
cf4a9129
LC
7520This example should be self-describing. Some of the fields defined
7521above, such as @code{host-name} and @code{bootloader}, are mandatory.
7522Others, such as @code{packages} and @code{services}, can be omitted, in
7523which case they get a default value.
e7f34eb0 7524
5d94ac51
LC
7525Below we discuss the effect of some of the most important fields
7526(@pxref{operating-system Reference}, for details about all the available
7527fields), and how to @dfn{instantiate} the operating system using
7528@command{guix system}.
7529
7530@unnumberedsubsubsec Globally-Visible Packages
7531
cf4a9129 7532@vindex %base-packages
5d94ac51
LC
7533The @code{packages} field lists packages that will be globally visible
7534on the system, for all user accounts---i.e., in every user's @code{PATH}
7535environment variable---in addition to the per-user profiles
7536(@pxref{Invoking guix package}). The @var{%base-packages} variable
7537provides all the tools one would expect for basic user and administrator
7538tasks---including the GNU Core Utilities, the GNU Networking Utilities,
7539the GNU Zile lightweight text editor, @command{find}, @command{grep},
7540etc. The example above adds tcpdump to those, taken from the @code{(gnu
7541packages admin)} module (@pxref{Package Modules}).
e7f34eb0 7542
f6c9fb1b
LC
7543@findex specification->package
7544Referring to packages by variable name, like @var{tcpdump} above, has
7545the advantage of being unambiguous; it also allows typos and such to be
7546diagnosed right away as ``unbound variables''. The downside is that one
7547needs to know which module defines which package, and to augment the
7548@code{use-package-modules} line accordingly. To avoid that, one can use
7549the @code{specification->package} procedure of the @code{(gnu packages)}
7550module, which returns the best package for a given name or name and
7551version:
7552
7553@lisp
7554(use-modules (gnu packages))
7555
7556(operating-system
7557 ;; ...
7558 (packages (append (map specification->package
d5e59248 7559 '("tcpdump" "htop" "gnupg@@2.0"))
f6c9fb1b
LC
7560 %base-packages)))
7561@end lisp
7562
5d94ac51
LC
7563@unnumberedsubsubsec System Services
7564
e32171ee 7565@cindex services
cf4a9129
LC
7566@vindex %base-services
7567The @code{services} field lists @dfn{system services} to be made
7568available when the system starts (@pxref{Services}).
7569The @code{operating-system} declaration above specifies that, in
7570addition to the basic services, we want the @command{lshd} secure shell
cd6f6c22
LC
7571daemon listening on port 2222 (@pxref{Networking Services,
7572@code{lsh-service}}). Under the hood,
cf4a9129
LC
7573@code{lsh-service} arranges so that @code{lshd} is started with the
7574right command-line options, possibly with supporting configuration files
cd6f6c22
LC
7575generated as needed (@pxref{Defining Services}).
7576
7577@cindex customization, of services
7578@findex modify-services
7579Occasionally, instead of using the base services as is, you will want to
4d343a14
CM
7580customize them. To do this, use @code{modify-services} (@pxref{Service
7581Reference, @code{modify-services}}) to modify the list.
7582
7583For example, suppose you want to modify @code{guix-daemon} and Mingetty
7584(the console log-in) in the @var{%base-services} list (@pxref{Base
7585Services, @code{%base-services}}). To do that, you can write the
7586following in your operating system declaration:
cd6f6c22
LC
7587
7588@lisp
4d343a14
CM
7589(define %my-services
7590 ;; My very own list of services.
7591 (modify-services %base-services
7592 (guix-service-type config =>
7593 (guix-configuration
7594 (inherit config)
7595 (use-substitutes? #f)
7596 (extra-options '("--gc-keep-derivations"))))
7597 (mingetty-service-type config =>
7598 (mingetty-configuration
317d3b47 7599 (inherit config)))))
4d343a14
CM
7600
7601(operating-system
7602 ;; @dots{}
7603 (services %my-services))
cd6f6c22
LC
7604@end lisp
7605
4d343a14
CM
7606This changes the configuration---i.e., the service parameters---of the
7607@code{guix-service-type} instance, and that of all the
7608@code{mingetty-service-type} instances in the @var{%base-services} list.
7609Observe how this is accomplished: first, we arrange for the original
7610configuration to be bound to the identifier @code{config} in the
7611@var{body}, and then we write the @var{body} so that it evaluates to the
7612desired configuration. In particular, notice how we use @code{inherit}
7613to create a new configuration which has the same values as the old
7614configuration, but with a few modifications.
a1ba8475 7615
13fb1bd9
LC
7616@cindex encrypted disk
7617The configuration for a typical ``desktop'' usage, with an encrypted
7618root partition, the X11 display
d038b674
LC
7619server, GNOME and Xfce (users can choose which of these desktop
7620environments to use at the log-in screen by pressing @kbd{F1}), network
7621management, power management, and more, would look like this:
dd51caac
LC
7622
7623@lisp
7624@include os-config-desktop.texi
7625@end lisp
7626
d038b674
LC
7627A graphical environment with a choice of lightweight window managers
7628instead of full-blown desktop environments would look like this:
7629
7630@lisp
7631@include os-config-lightweight-desktop.texi
7632@end lisp
7633
dd51caac 7634@xref{Desktop Services}, for the exact list of services provided by
efb5e833
LC
7635@var{%desktop-services}. @xref{X.509 Certificates}, for background
7636information about the @code{nss-certs} package that is used here.
dd51caac 7637
5d94ac51
LC
7638Again, @var{%desktop-services} is just a list of service objects. If
7639you want to remove services from there, you can do so using the
7640procedures for list filtering (@pxref{SRFI-1 Filtering and
7641Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
7642following expression returns a list that contains all the services in
7643@var{%desktop-services} minus the Avahi service:
7644
7645@example
7646(remove (lambda (service)
7647 (eq? (service-kind service) avahi-service-type))
7648 %desktop-services)
7649@end example
7650
7651@unnumberedsubsubsec Instantiating the System
7652
7653Assuming the @code{operating-system} declaration
7654is stored in the @file{my-system-config.scm}
cf4a9129
LC
7655file, the @command{guix system reconfigure my-system-config.scm} command
7656instantiates that configuration, and makes it the default GRUB boot
65797bff
LC
7657entry (@pxref{Invoking guix system}).
7658
1068f26b 7659The normal way to change the system configuration is by updating this
65797bff 7660file and re-running @command{guix system reconfigure}. One should never
8b499030 7661have to touch files in @file{/etc} or to run commands that modify the
65797bff
LC
7662system state such as @command{useradd} or @command{grub-install}. In
7663fact, you must avoid that since that would not only void your warranty
7664but also prevent you from rolling back to previous versions of your
7665system, should you ever need to.
7666
7667@cindex roll-back, of the operating system
7668Speaking of roll-back, each time you run @command{guix system
7669reconfigure}, a new @dfn{generation} of the system is created---without
7670modifying or deleting previous generations. Old system generations get
7671an entry in the GRUB boot menu, allowing you to boot them in case
7672something went wrong with the latest generation. Reassuring, no? The
7673@command{guix system list-generations} command lists the system
067a2e2d
CM
7674generations available on disk. It is also possible to roll back the
7675system via the commands @command{guix system roll-back} and
7676@command{guix system switch-generation}.
7677
7678Although the command @command{guix system reconfigure} will not modify
7679previous generations, must take care when the current generation is not
7680the latest (e.g., after invoking @command{guix system roll-back}), since
7681the operation might overwrite a later generation (@pxref{Invoking guix
7682system}).
b81e1947 7683
5d94ac51
LC
7684@unnumberedsubsubsec The Programming Interface
7685
cf4a9129
LC
7686At the Scheme level, the bulk of an @code{operating-system} declaration
7687is instantiated with the following monadic procedure (@pxref{The Store
7688Monad}):
b81e1947 7689
cf4a9129
LC
7690@deffn {Monadic Procedure} operating-system-derivation os
7691Return a derivation that builds @var{os}, an @code{operating-system}
7692object (@pxref{Derivations}).
b81e1947 7693
cf4a9129
LC
7694The output of the derivation is a single directory that refers to all
7695the packages, configuration files, and other supporting files needed to
7696instantiate @var{os}.
7697@end deffn
b81e1947 7698
5d94ac51
LC
7699This procedure is provided by the @code{(gnu system)} module. Along
7700with @code{(gnu services)} (@pxref{Services}), this module contains the
7701guts of GuixSD. Make sure to visit it!
7702
7703
7313a52e
LC
7704@node operating-system Reference
7705@subsection @code{operating-system} Reference
7706
7707This section summarizes all the options available in
7708@code{operating-system} declarations (@pxref{Using the Configuration
7709System}).
7710
7711@deftp {Data Type} operating-system
7712This is the data type representing an operating system configuration.
7713By that, we mean all the global system configuration, not per-user
7714configuration (@pxref{Using the Configuration System}).
7715
7716@table @asis
7717@item @code{kernel} (default: @var{linux-libre})
fbb25e56 7718The package object of the operating system kernel to use@footnote{Currently
7313a52e
LC
7719only the Linux-libre kernel is supported. In the future, it will be
7720possible to use the GNU@tie{}Hurd.}.
7721
ee2a6304
LC
7722@item @code{kernel-arguments} (default: @code{'()})
7723List of strings or gexps representing additional arguments to pass on
1068f26b 7724the command-line of the kernel---e.g., @code{("console=ttyS0")}.
ee2a6304 7725
7313a52e 7726@item @code{bootloader}
88faf933 7727The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
7728
7729@item @code{initrd} (default: @code{base-initrd})
e32171ee
JD
7730@cindex initrd
7731@cindex initial RAM disk
7313a52e
LC
7732A two-argument monadic procedure that returns an initial RAM disk for
7733the Linux kernel. @xref{Initial RAM Disk}.
7734
f34c56be
LC
7735@item @code{firmware} (default: @var{%base-firmware})
7736@cindex firmware
7737List of firmware packages loadable by the operating system kernel.
7738
52db41af
EB
7739The default includes firmware needed for Atheros- and Broadcom-based
7740WiFi devices (Linux-libre modules @code{ath9k} and @code{b43-open},
7741respectively). @xref{Hardware Considerations}, for more info on
7742supported hardware.
f34c56be 7743
7313a52e
LC
7744@item @code{host-name}
7745The host name.
7746
7747@item @code{hosts-file}
7748@cindex hosts file
24e02c28 7749A file-like object (@pxref{G-Expressions, file-like objects}) for use as
7313a52e 7750@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
24e02c28 7751Reference Manual}). The default is a file with entries for
7313a52e
LC
7752@code{localhost} and @var{host-name}.
7753
7754@item @code{mapped-devices} (default: @code{'()})
7755A list of mapped devices. @xref{Mapped Devices}.
7756
7757@item @code{file-systems}
7758A list of file systems. @xref{File Systems}.
7759
7760@item @code{swap-devices} (default: @code{'()})
7761@cindex swap devices
a4ca4362
CM
7762A list of strings identifying devices or files to be used for ``swap
7763space'' (@pxref{Memory Concepts,,, libc, The GNU C Library Reference
7764Manual}). For example, @code{'("/dev/sda3")} or @code{'("/swapfile")}.
7765It is possible to specify a swap file in a file system on a mapped
7766device, provided that the necessary device mapping and file system are
7767also specified. @xref{Mapped Devices} and @ref{File Systems}.
7313a52e 7768
bf87f38a 7769@item @code{users} (default: @code{%base-user-accounts})
7313a52e
LC
7770@itemx @code{groups} (default: @var{%base-groups})
7771List of user accounts and groups. @xref{User Accounts}.
7772
7773@item @code{skeletons} (default: @code{(default-skeletons)})
e9dffec1
LC
7774A list target file name/file-like object tuples (@pxref{G-Expressions,
7775file-like objects}). These are the skeleton files that will be added to
7776the home directory of newly-created user accounts.
7313a52e
LC
7777
7778For instance, a valid value may look like this:
7779
7780@example
e9dffec1
LC
7781`((".bashrc" ,(plain-file "bashrc" "echo Hello\n"))
7782 (".guile" ,(plain-file "guile"
7783 "(use-modules (ice-9 readline))
7784 (activate-readline)")))
7313a52e
LC
7785@end example
7786
7787@item @code{issue} (default: @var{%default-issue})
7788A string denoting the contents of the @file{/etc/issue} file, which is
1068f26b 7789displayed when users log in on a text console.
7313a52e
LC
7790
7791@item @code{packages} (default: @var{%base-packages})
7792The set of packages installed in the global profile, which is accessible
7793at @file{/run/current-system/profile}.
7794
1068f26b 7795The default set includes core utilities and it is good practice to
7313a52e
LC
7796install non-core utilities in user profiles (@pxref{Invoking guix
7797package}).
7798
7799@item @code{timezone}
7800A timezone identifying string---e.g., @code{"Europe/Paris"}.
7801
17c20385
LC
7802You can run the @command{tzselect} command to find out which timezone
7803string corresponds to your region. Choosing an invalid timezone name
7804causes @command{guix system} to fail.
7805
598e19dc
LC
7806@item @code{locale} (default: @code{"en_US.utf8"})
7807The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
7808Library Reference Manual}). @xref{Locales}, for more information.
7809
7810@item @code{locale-definitions} (default: @var{%default-locale-definitions})
7811The list of locale definitions to be compiled and that may be used at
7812run time. @xref{Locales}.
7313a52e 7813
34760ae7
LC
7814@item @code{locale-libcs} (default: @code{(list @var{glibc})})
7815The list of GNU@tie{}libc packages whose locale data and tools are used
7816to build the locale definitions. @xref{Locales}, for compatibility
7817considerations that justify this option.
7818
996ed739 7819@item @code{name-service-switch} (default: @var{%default-nss})
1068f26b 7820Configuration of the libc name service switch (NSS)---a
996ed739
LC
7821@code{<name-service-switch>} object. @xref{Name Service Switch}, for
7822details.
7823
7313a52e 7824@item @code{services} (default: @var{%base-services})
28d939af 7825A list of service objects denoting system services. @xref{Services}.
7313a52e
LC
7826
7827@item @code{pam-services} (default: @code{(base-pam-services)})
7828@cindex PAM
7829@cindex pluggable authentication modules
7830Linux @dfn{pluggable authentication module} (PAM) services.
7831@c FIXME: Add xref to PAM services section.
7832
7833@item @code{setuid-programs} (default: @var{%setuid-programs})
7834List of string-valued G-expressions denoting setuid programs.
7835@xref{Setuid Programs}.
7836
f5a9ffa0
AK
7837@item @code{sudoers-file} (default: @var{%sudoers-specification})
7838@cindex sudoers file
84765839
LC
7839The contents of the @file{/etc/sudoers} file as a file-like object
7840(@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7313a52e
LC
7841
7842This file specifies which users can use the @command{sudo} command, what
7843they are allowed to do, and what privileges they may gain. The default
7844is that only @code{root} and members of the @code{wheel} group may use
7845@code{sudo}.
7846
7847@end table
7848@end deftp
7849
cf4a9129
LC
7850@node File Systems
7851@subsection File Systems
b81e1947 7852
cf4a9129 7853The list of file systems to be mounted is specified in the
1068f26b 7854@code{file-systems} field of the operating system declaration
cf4a9129
LC
7855(@pxref{Using the Configuration System}). Each file system is declared
7856using the @code{file-system} form, like this:
b81e1947
LC
7857
7858@example
cf4a9129
LC
7859(file-system
7860 (mount-point "/home")
7861 (device "/dev/sda3")
7862 (type "ext4"))
b81e1947
LC
7863@end example
7864
cf4a9129
LC
7865As usual, some of the fields are mandatory---those shown in the example
7866above---while others can be omitted. These are described below.
b81e1947 7867
cf4a9129
LC
7868@deftp {Data Type} file-system
7869Objects of this type represent file systems to be mounted. They
7870contain the following members:
5ff3c4b8 7871
cf4a9129
LC
7872@table @asis
7873@item @code{type}
7874This is a string specifying the type of the file system---e.g.,
7875@code{"ext4"}.
5ff3c4b8 7876
cf4a9129
LC
7877@item @code{mount-point}
7878This designates the place where the file system is to be mounted.
b81e1947 7879
cf4a9129
LC
7880@item @code{device}
7881This names the ``source'' of the file system. By default it is the name
7882of a node under @file{/dev}, but its meaning depends on the @code{title}
7883field described below.
401c53c4 7884
cf4a9129
LC
7885@item @code{title} (default: @code{'device})
7886This is a symbol that specifies how the @code{device} field is to be
7887interpreted.
401c53c4 7888
cf4a9129
LC
7889When it is the symbol @code{device}, then the @code{device} field is
7890interpreted as a file name; when it is @code{label}, then @code{device}
7891is interpreted as a partition label name; when it is @code{uuid},
7892@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 7893
661a1d79 7894UUIDs may be converted from their string representation (as shown by the
0767f6a6
LC
7895@command{tune2fs -l} command) using the @code{uuid} form@footnote{The
7896@code{uuid} form expects 16-byte UUIDs as defined in
7897@uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
7898form of UUID used by the ext2 family of file systems and others, but it
7899is different from ``UUIDs'' found in FAT file systems, for instance.},
7900like this:
661a1d79
LC
7901
7902@example
7903(file-system
7904 (mount-point "/home")
7905 (type "ext4")
7906 (title 'uuid)
7907 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
7908@end example
7909
cf4a9129 7910The @code{label} and @code{uuid} options offer a way to refer to disk
661a1d79
LC
7911partitions without having to hard-code their actual device
7912name@footnote{Note that, while it is tempting to use
7913@file{/dev/disk/by-uuid} and similar device names to achieve the same
7914result, this is not recommended: These special device nodes are created
7915by the udev daemon and may be unavailable at the time the device is
7916mounted.}.
da7cabd4 7917
1068f26b 7918However, when the source of a file system is a mapped device (@pxref{Mapped
5f86a66e
LC
7919Devices}), its @code{device} field @emph{must} refer to the mapped
7920device name---e.g., @file{/dev/mapper/root-partition}---and consequently
7921@code{title} must be set to @code{'device}. This is required so that
7922the system knows that mounting the file system depends on having the
7923corresponding device mapping established.
7924
cf4a9129
LC
7925@item @code{flags} (default: @code{'()})
7926This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
7927include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
7928access to special files), @code{no-suid} (ignore setuid and setgid
7929bits), and @code{no-exec} (disallow program execution.)
da7cabd4 7930
cf4a9129
LC
7931@item @code{options} (default: @code{#f})
7932This is either @code{#f}, or a string denoting mount options.
da7cabd4 7933
be21979d
LC
7934@item @code{mount?} (default: @code{#t})
7935This value indicates whether to automatically mount the file system when
7936the system is brought up. When set to @code{#f}, the file system gets
7937an entry in @file{/etc/fstab} (read by the @command{mount} command) but
7938is not automatically mounted.
7939
cf4a9129
LC
7940@item @code{needed-for-boot?} (default: @code{#f})
7941This Boolean value indicates whether the file system is needed when
7942booting. If that is true, then the file system is mounted when the
7943initial RAM disk (initrd) is loaded. This is always the case, for
7944instance, for the root file system.
da7cabd4 7945
cf4a9129
LC
7946@item @code{check?} (default: @code{#t})
7947This Boolean indicates whether the file system needs to be checked for
7948errors before being mounted.
f9cc8971 7949
4e469051
LC
7950@item @code{create-mount-point?} (default: @code{#f})
7951When true, the mount point is created if it does not exist yet.
7952
e51710d1 7953@item @code{dependencies} (default: @code{'()})
13fb1bd9
LC
7954This is a list of @code{<file-system>} or @code{<mapped-device>} objects
7955representing file systems that must be mounted or mapped devices that
7956must be opened before (and unmounted or closed after) this one.
e51710d1
LC
7957
7958As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
7959a dependency of @file{/sys/fs/cgroup/cpu} and
7960@file{/sys/fs/cgroup/memory}.
7961
13fb1bd9
LC
7962Another example is a file system that depends on a mapped device, for
7963example for an encrypted partition (@pxref{Mapped Devices}).
cf4a9129
LC
7964@end table
7965@end deftp
da7cabd4 7966
a69576ea
LC
7967The @code{(gnu system file-systems)} exports the following useful
7968variables.
7969
7970@defvr {Scheme Variable} %base-file-systems
7971These are essential file systems that are required on normal systems,
cc0e575a 7972such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
3392ce5d
LC
7973below.) Operating system declarations should always contain at least
7974these.
a69576ea
LC
7975@end defvr
7976
7f239fd3
LC
7977@defvr {Scheme Variable} %pseudo-terminal-file-system
7978This is the file system to be mounted as @file{/dev/pts}. It supports
7979@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
7980functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
7981Manual}). Pseudo-terminals are used by terminal emulators such as
7982@command{xterm}.
7983@end defvr
7984
db17ae5c
LC
7985@defvr {Scheme Variable} %shared-memory-file-system
7986This file system is mounted as @file{/dev/shm} and is used to support
7987memory sharing across processes (@pxref{Memory-mapped I/O,
7988@code{shm_open},, libc, The GNU C Library Reference Manual}).
7989@end defvr
7990
3392ce5d
LC
7991@defvr {Scheme Variable} %immutable-store
7992This file system performs a read-only ``bind mount'' of
7993@file{/gnu/store}, making it read-only for all the users including
7994@code{root}. This prevents against accidental modification by software
7995running as @code{root} or by system administrators.
7996
7997The daemon itself is still able to write to the store: it remounts it
7998read-write in its own ``name space.''
7999@end defvr
8000
a69576ea
LC
8001@defvr {Scheme Variable} %binary-format-file-system
8002The @code{binfmt_misc} file system, which allows handling of arbitrary
8003executable file types to be delegated to user space. This requires the
8004@code{binfmt.ko} kernel module to be loaded.
8005@end defvr
8006
8007@defvr {Scheme Variable} %fuse-control-file-system
8008The @code{fusectl} file system, which allows unprivileged users to mount
8009and unmount user-space FUSE file systems. This requires the
8010@code{fuse.ko} kernel module to be loaded.
8011@end defvr
8012
510f9d86
LC
8013@node Mapped Devices
8014@subsection Mapped Devices
8015
8016@cindex device mapping
8017@cindex mapped devices
8018The Linux kernel has a notion of @dfn{device mapping}: a block device,
8019such as a hard disk partition, can be @dfn{mapped} into another device,
97c8aef1 8020usually in @code{/dev/mapper/},
510f9d86
LC
8021with additional processing over the data that flows through
8022it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
8023concept of a ``mapped device'' and that of a file system: both boil down
8024to @emph{translating} input/output operations made on a file to
8025operations on its backing store. Thus, the Hurd implements mapped
8026devices, like file systems, using the generic @dfn{translator} mechanism
8027(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
8028typical example is encryption device mapping: all writes to the mapped
8029device are encrypted, and all reads are deciphered, transparently.
97c8aef1
AE
8030Guix extends this notion by considering any device or set of devices that
8031are @dfn{transformed} in some way to create a new device; for instance,
8032RAID devices are obtained by @dfn{assembling} several other devices, such
8033as hard disks or partitions, into a new one that behaves as one partition.
8034Other examples, not yet implemented, are LVM logical volumes.
510f9d86 8035
97c8aef1
AE
8036Mapped devices are declared using the @code{mapped-device} form,
8037defined as follows; for examples, see below.
510f9d86
LC
8038
8039@deftp {Data Type} mapped-device
8040Objects of this type represent device mappings that will be made when
8041the system boots up.
8042
9cb426b8
LC
8043@table @code
8044@item source
97c8aef1
AE
8045This is either a string specifying the name of the block device to be mapped,
8046such as @code{"/dev/sda3"}, or a list of such strings when several devices
8047need to be assembled for creating a new one.
510f9d86 8048
9cb426b8 8049@item target
97c8aef1
AE
8050This string specifies the name of the resulting mapped device. For
8051kernel mappers such as encrypted devices of type @code{luks-device-mapping},
8052specifying @code{"my-partition"} leads to the creation of
510f9d86 8053the @code{"/dev/mapper/my-partition"} device.
97c8aef1
AE
8054For RAID devices of type @code{raid-device-mapping}, the full device name
8055such as @code{"/dev/md0"} needs to be given.
510f9d86 8056
9cb426b8 8057@item type
510f9d86
LC
8058This must be a @code{mapped-device-kind} object, which specifies how
8059@var{source} is mapped to @var{target}.
8060@end table
8061@end deftp
8062
8063@defvr {Scheme Variable} luks-device-mapping
8064This defines LUKS block device encryption using the @command{cryptsetup}
1068f26b 8065command from the package with the same name. It relies on the
510f9d86
LC
8066@code{dm-crypt} Linux kernel module.
8067@end defvr
8068
97c8aef1
AE
8069@defvr {Scheme Variable} raid-device-mapping
8070This defines a RAID device, which is assembled using the @code{mdadm}
8071command from the package with the same name. It requires a Linux kernel
8072module for the appropriate RAID level to be loaded, such as @code{raid456}
8073for RAID-4, RAID-5 or RAID-6, or @code{raid10} for RAID-10.
8074@end defvr
8075
8076@cindex disk encryption
8077@cindex LUKS
8078The following example specifies a mapping from @file{/dev/sda3} to
8079@file{/dev/mapper/home} using LUKS---the
ddf1cd51 8080@url{https://gitlab.com/cryptsetup/cryptsetup,Linux Unified Key Setup}, a
97c8aef1
AE
8081standard mechanism for disk encryption.
8082The @file{/dev/mapper/home}
8083device can then be used as the @code{device} of a @code{file-system}
8084declaration (@pxref{File Systems}).
8085
8086@example
8087(mapped-device
8088 (source "/dev/sda3")
8089 (target "home")
8090 (type luks-device-mapping))
8091@end example
8092
8093Alternatively, to become independent of device numbering, one may obtain
8094the LUKS UUID (@dfn{unique identifier}) of the source device by a
8095command like:
8096
8097@example
8098cryptsetup luksUUID /dev/sda3
8099@end example
8100
8101and use it as follows:
8102
8103@example
8104(mapped-device
8105 (source (uuid "cb67fc72-0d54-4c88-9d4b-b225f30b0f44"))
8106 (target "home")
8107 (type luks-device-mapping))
8108@end example
8109
a4ca4362
CM
8110@cindex swap encryption
8111It is also desirable to encrypt swap space, since swap space may contain
8112sensitive data. One way to accomplish that is to use a swap file in a
8113file system on a device mapped via LUKS encryption. In this way, the
8114swap file is encrypted because the entire device is encrypted.
8115@xref{Preparing for Installation,,Disk Partitioning}, for an example.
8116
97c8aef1
AE
8117A RAID device formed of the partitions @file{/dev/sda1} and @file{/dev/sdb1}
8118may be declared as follows:
8119
8120@example
8121(mapped-device
8122 (source (list "/dev/sda1" "/dev/sdb1"))
8123 (target "/dev/md0")
8124 (type raid-device-mapping))
8125@end example
8126
8127The @file{/dev/md0} device can then be used as the @code{device} of a
8128@code{file-system} declaration (@pxref{File Systems}).
8129Note that the RAID level need not be given; it is chosen during the
8130initial creation and formatting of the RAID device and is determined
8131automatically later.
8132
8133
cf4a9129
LC
8134@node User Accounts
8135@subsection User Accounts
ee85f3db 8136
e32171ee
JD
8137@cindex users
8138@cindex accounts
8139@cindex user accounts
9bea87a5
LC
8140User accounts and groups are entirely managed through the
8141@code{operating-system} declaration. They are specified with the
8142@code{user-account} and @code{user-group} forms:
ee85f3db 8143
cf4a9129
LC
8144@example
8145(user-account
8146 (name "alice")
8147 (group "users")
24e752c0
LC
8148 (supplementary-groups '("wheel" ;allow use of sudo, etc.
8149 "audio" ;sound card
8150 "video" ;video devices such as webcams
8151 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
8152 (comment "Bob's sister")
8153 (home-directory "/home/alice"))
8154@end example
25083588 8155
9bea87a5
LC
8156When booting or upon completion of @command{guix system reconfigure},
8157the system ensures that only the user accounts and groups specified in
8158the @code{operating-system} declaration exist, and with the specified
8159properties. Thus, account or group creations or modifications made by
8160directly invoking commands such as @command{useradd} are lost upon
8161reconfiguration or reboot. This ensures that the system remains exactly
8162as declared.
8163
cf4a9129
LC
8164@deftp {Data Type} user-account
8165Objects of this type represent user accounts. The following members may
8166be specified:
ee85f3db 8167
cf4a9129
LC
8168@table @asis
8169@item @code{name}
8170The name of the user account.
ee85f3db 8171
cf4a9129 8172@item @code{group}
e32171ee 8173@cindex groups
cf4a9129
LC
8174This is the name (a string) or identifier (a number) of the user group
8175this account belongs to.
ee85f3db 8176
cf4a9129
LC
8177@item @code{supplementary-groups} (default: @code{'()})
8178Optionally, this can be defined as a list of group names that this
8179account belongs to.
ee85f3db 8180
cf4a9129
LC
8181@item @code{uid} (default: @code{#f})
8182This is the user ID for this account (a number), or @code{#f}. In the
8183latter case, a number is automatically chosen by the system when the
8184account is created.
ee85f3db 8185
cf4a9129 8186@item @code{comment} (default: @code{""})
1068f26b 8187A comment about the account, such as the account owner's full name.
c8c871d1 8188
cf4a9129
LC
8189@item @code{home-directory}
8190This is the name of the home directory for the account.
ee85f3db 8191
eb56ee02
LC
8192@item @code{create-home-directory?} (default: @code{#t})
8193Indicates whether the home directory of this account should be created
8194if it does not exist yet.
8195
cf4a9129
LC
8196@item @code{shell} (default: Bash)
8197This is a G-expression denoting the file name of a program to be used as
8198the shell (@pxref{G-Expressions}).
ee85f3db 8199
cf4a9129
LC
8200@item @code{system?} (default: @code{#f})
8201This Boolean value indicates whether the account is a ``system''
8202account. System accounts are sometimes treated specially; for instance,
8203graphical login managers do not list them.
ee85f3db 8204
1bd4e6db 8205@anchor{user-account-password}
cf4a9129 8206@item @code{password} (default: @code{#f})
eb59595c
LC
8207You would normally leave this field to @code{#f}, initialize user
8208passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
8209users change it with @command{passwd}. Passwords set with
8210@command{passwd} are of course preserved across reboot and
8211reconfiguration.
eb59595c
LC
8212
8213If you @emph{do} want to have a preset password for an account, then
8214this field must contain the encrypted password, as a string.
5d1f1177
LC
8215@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
8216on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 8217Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 8218
cf4a9129
LC
8219@end table
8220@end deftp
ee85f3db 8221
e32171ee 8222@cindex groups
cf4a9129 8223User group declarations are even simpler:
ee85f3db 8224
cf4a9129
LC
8225@example
8226(user-group (name "students"))
8227@end example
ee85f3db 8228
cf4a9129
LC
8229@deftp {Data Type} user-group
8230This type is for, well, user groups. There are just a few fields:
af8a56b8 8231
cf4a9129
LC
8232@table @asis
8233@item @code{name}
1068f26b 8234The name of the group.
ee85f3db 8235
cf4a9129
LC
8236@item @code{id} (default: @code{#f})
8237The group identifier (a number). If @code{#f}, a new number is
8238automatically allocated when the group is created.
ee85f3db 8239
c8fa3426
LC
8240@item @code{system?} (default: @code{#f})
8241This Boolean value indicates whether the group is a ``system'' group.
8242System groups have low numerical IDs.
8243
cf4a9129
LC
8244@item @code{password} (default: @code{#f})
8245What, user groups can have a password? Well, apparently yes. Unless
1068f26b 8246@code{#f}, this field specifies the password of the group.
ee85f3db 8247
cf4a9129
LC
8248@end table
8249@end deftp
401c53c4 8250
cf4a9129
LC
8251For convenience, a variable lists all the basic user groups one may
8252expect:
401c53c4 8253
cf4a9129
LC
8254@defvr {Scheme Variable} %base-groups
8255This is the list of basic user groups that users and/or packages expect
8256to be present on the system. This includes groups such as ``root'',
8257``wheel'', and ``users'', as well as groups used to control access to
8258specific devices such as ``audio'', ``disk'', and ``cdrom''.
8259@end defvr
401c53c4 8260
bf87f38a
LC
8261@defvr {Scheme Variable} %base-user-accounts
8262This is the list of basic system accounts that programs may expect to
8263find on a GNU/Linux system, such as the ``nobody'' account.
8264
8265Note that the ``root'' account is not included here. It is a
8266special-case and is automatically added whether or not it is specified.
8267@end defvr
8268
598e19dc
LC
8269@node Locales
8270@subsection Locales
8271
8272@cindex locale
8273A @dfn{locale} defines cultural conventions for a particular language
8274and region of the world (@pxref{Locales,,, libc, The GNU C Library
8275Reference Manual}). Each locale has a name that typically has the form
b2636518 8276@code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
598e19dc
LC
8277@code{fr_LU.utf8} designates the locale for the French language, with
8278cultural conventions from Luxembourg, and using the UTF-8 encoding.
8279
8280@cindex locale definition
8281Usually, you will want to specify the default locale for the machine
8282using the @code{locale} field of the @code{operating-system} declaration
8283(@pxref{operating-system Reference, @code{locale}}).
8284
f5582b2c
LC
8285The selected locale is automatically added to the @dfn{locale
8286definitions} known to the system if needed, with its codeset inferred
8287from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
8288@code{UTF-8} codeset. Additional locale definitions can be specified in
8289the @code{locale-definitions} slot of @code{operating-system}---this is
8290useful, for instance, if the codeset could not be inferred from the
8291locale name. The default set of locale definitions includes some widely
8292used locales, but not all the available locales, in order to save space.
8293
8294For instance, to add the North Frisian locale for Germany, the value of
8295that field may be:
598e19dc
LC
8296
8297@example
8298(cons (locale-definition
8299 (name "fy_DE.utf8") (source "fy_DE"))
8300 %default-locale-definitions)
8301@end example
8302
8303Likewise, to save space, one might want @code{locale-definitions} to
8304list only the locales that are actually used, as in:
8305
8306@example
8307(list (locale-definition
8308 (name "ja_JP.eucjp") (source "ja_JP")
8309 (charset "EUC-JP")))
8310@end example
8311
5c3c1427
LC
8312@vindex LOCPATH
8313The compiled locale definitions are available at
46bd6edd
LC
8314@file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
8315version, which is the default location where the GNU@tie{}libc provided
8316by Guix looks for locale data. This can be overridden using the
8317@code{LOCPATH} environment variable (@pxref{locales-and-locpath,
5c3c1427
LC
8318@code{LOCPATH} and locale packages}).
8319
598e19dc
LC
8320The @code{locale-definition} form is provided by the @code{(gnu system
8321locale)} module. Details are given below.
8322
8323@deftp {Data Type} locale-definition
8324This is the data type of a locale definition.
8325
8326@table @asis
8327
8328@item @code{name}
8329The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
8330Reference Manual}, for more information on locale names.
8331
8332@item @code{source}
8333The name of the source for that locale. This is typically the
8334@code{@var{language}_@var{territory}} part of the locale name.
8335
8336@item @code{charset} (default: @code{"UTF-8"})
8337The ``character set'' or ``code set'' for that locale,
8338@uref{http://www.iana.org/assignments/character-sets, as defined by
8339IANA}.
8340
8341@end table
8342@end deftp
8343
8344@defvr {Scheme Variable} %default-locale-definitions
1068f26b 8345A list of commonly used UTF-8 locales, used as the default
b2636518 8346value of the @code{locale-definitions} field of @code{operating-system}
598e19dc 8347declarations.
b2636518
LC
8348
8349@cindex locale name
8350@cindex normalized codeset in locale names
8351These locale definitions use the @dfn{normalized codeset} for the part
8352that follows the dot in the name (@pxref{Using gettextized software,
8353normalized codeset,, libc, The GNU C Library Reference Manual}). So for
8354instance it has @code{uk_UA.utf8} but @emph{not}, say,
8355@code{uk_UA.UTF-8}.
598e19dc 8356@end defvr
401c53c4 8357
34760ae7
LC
8358@subsubsection Locale Data Compatibility Considerations
8359
8360@cindex incompatibility, of locale data
8361@code{operating-system} declarations provide a @code{locale-libcs} field
8362to specify the GNU@tie{}libc packages that are used to compile locale
8363declarations (@pxref{operating-system Reference}). ``Why would I
8364care?'', you may ask. Well, it turns out that the binary format of
8365locale data is occasionally incompatible from one libc version to
8366another.
8367
8368@c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
8369@c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
8370For instance, a program linked against libc version 2.21 is unable to
8371read locale data produced with libc 2.22; worse, that program
8372@emph{aborts} instead of simply ignoring the incompatible locale
8373data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
8374the incompatible locale data, which is already an improvement.}.
8375Similarly, a program linked against libc 2.22 can read most, but not
201fff9e 8376all, of the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
34760ae7
LC
8377data is incompatible); thus calls to @code{setlocale} may fail, but
8378programs will not abort.
8379
8380The ``problem'' in GuixSD is that users have a lot of freedom: They can
8381choose whether and when to upgrade software in their profiles, and might
8382be using a libc version different from the one the system administrator
8383used to build the system-wide locale data.
8384
8385Fortunately, unprivileged users can also install their own locale data
8386and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
8387@code{GUIX_LOCPATH} and locale packages}).
8388
8389Still, it is best if the system-wide locale data at
8390@file{/run/current-system/locale} is built for all the libc versions
8391actually in use on the system, so that all the programs can access
8392it---this is especially crucial on a multi-user system. To do that, the
8393administrator can specify several libc packages in the
8394@code{locale-libcs} field of @code{operating-system}:
8395
8396@example
8397(use-package-modules base)
8398
8399(operating-system
8400 ;; @dots{}
8401 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
8402@end example
8403
8404This example would lead to a system containing locale definitions for
8405both libc 2.21 and the current version of libc in
8406@file{/run/current-system/locale}.
8407
8408
cf4a9129
LC
8409@node Services
8410@subsection Services
401c53c4 8411
cf4a9129
LC
8412@cindex system services
8413An important part of preparing an @code{operating-system} declaration is
8414listing @dfn{system services} and their configuration (@pxref{Using the
8415Configuration System}). System services are typically daemons launched
8416when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
8417configuring network access.
8418
e8b652d4
LC
8419GuixSD has a broad definition of ``service'' (@pxref{Service
8420Composition}), but many services are managed by the GNU@tie{}Shepherd
8421(@pxref{Shepherd Services}). On a running system, the @command{herd}
8422command allows you to list the available services, show their status,
8423start and stop them, or do other specific operations (@pxref{Jump
8424Start,,, shepherd, The GNU Shepherd Manual}). For example:
d8b94dbd
LC
8425
8426@example
dd17bc38 8427# herd status
d8b94dbd
LC
8428@end example
8429
8430The above command, run as @code{root}, lists the currently defined
dd17bc38 8431services. The @command{herd doc} command shows a synopsis of the given
d8b94dbd
LC
8432service:
8433
8434@example
dd17bc38 8435# herd doc nscd
d8b94dbd
LC
8436Run libc's name service cache daemon (nscd).
8437@end example
8438
8439The @command{start}, @command{stop}, and @command{restart} sub-commands
8440have the effect you would expect. For instance, the commands below stop
8441the nscd service and restart the Xorg display server:
8442
8443@example
dd17bc38 8444# herd stop nscd
d8b94dbd 8445Service nscd has been stopped.
dd17bc38 8446# herd restart xorg-server
d8b94dbd
LC
8447Service xorg-server has been stopped.
8448Service xorg-server has been started.
8449@end example
401c53c4 8450
cf4a9129 8451The following sections document the available services, starting with
d8b94dbd
LC
8452the core services, that may be used in an @code{operating-system}
8453declaration.
401c53c4 8454
cf4a9129
LC
8455@menu
8456* Base Services:: Essential system services.
c311089b 8457* Scheduled Job Execution:: The mcron service.
92c03a87 8458* Log Rotation:: The rottlog service.
cf4a9129
LC
8459* Networking Services:: Network setup, SSH daemon, etc.
8460* X Window:: Graphical display.
f2ec23d1 8461* Printing Services:: Local and remote printer support.
fe1a39d3 8462* Desktop Services:: D-Bus and desktop services.
105369a4 8463* Database Services:: SQL databases.
d8c18af8 8464* Mail Services:: IMAP, POP3, SMTP, and all that.
78cef99b 8465* Messaging Services:: Messaging services.
859e367d 8466* Kerberos Services:: Kerberos services.
58724c48 8467* Web Services:: Web servers.
2be1b471 8468* VPN Services:: VPN daemons.
eb419bc9 8469* Network File System:: NFS related services.
a7cf4eb6 8470* Continuous Integration:: The Cuirass service.
bfbf6e1e 8471* Power management Services:: The TLP tool.
dbc6d370 8472* Miscellaneous Services:: Other services.
cf4a9129 8473@end menu
401c53c4 8474
cf4a9129
LC
8475@node Base Services
8476@subsubsection Base Services
a1ba8475 8477
cf4a9129
LC
8478The @code{(gnu services base)} module provides definitions for the basic
8479services that one expects from the system. The services exported by
8480this module are listed below.
401c53c4 8481
cf4a9129 8482@defvr {Scheme Variable} %base-services
31771497
LC
8483This variable contains a list of basic services (@pxref{Service Types
8484and Services}, for more information on service objects) one would
cf4a9129 8485expect from the system: a login service (mingetty) on each tty, syslogd,
1068f26b 8486the libc name service cache daemon (nscd), the udev device manager, and
cf4a9129 8487more.
401c53c4 8488
cf4a9129
LC
8489This is the default value of the @code{services} field of
8490@code{operating-system} declarations. Usually, when customizing a
8491system, you will want to append services to @var{%base-services}, like
8492this:
401c53c4 8493
cf4a9129 8494@example
fa1e31b8 8495(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
8496@end example
8497@end defvr
401c53c4 8498
387e1754
LC
8499@defvr {Scheme Variable} special-files-service-type
8500This is the service that sets up ``special files'' such as
8501@file{/bin/sh}; an instance of it is part of @code{%base-services}.
8502
8503The value associated with @code{special-files-service-type} services
8504must be a list of tuples where the first element is the ``special file''
8505and the second element is its target. By default it is:
8506
8507@cindex @file{/bin/sh}
8508@cindex @file{sh}, in @file{/bin}
8509@example
8510`(("/bin/sh" ,(file-append @var{bash} "/bin/sh")))
8511@end example
8512
8513@cindex @file{/usr/bin/env}
8514@cindex @file{env}, in @file{/usr/bin}
8515If you want to add, say, @code{/usr/bin/env} to your system, you can
8516change it to:
8517
8518@example
8519`(("/bin/sh" ,(file-append @var{bash} "/bin/sh"))
8520 ("/usr/bin/env" ,(file-append @var{coreutils} "/bin/env")))
8521@end example
8522
8523Since this is part of @code{%base-services}, you can use
8524@code{modify-services} to customize the set of special files
8525(@pxref{Service Reference, @code{modify-services}}). But the simple way
8526to add a special file is @i{via} the @code{extra-special-file} procedure
8527(see below.)
8528@end defvr
8529
8530@deffn {Scheme Procedure} extra-special-file @var{file} @var{target}
8531Use @var{target} as the ``special file'' @var{file}.
8532
8533For example, adding the following lines to the @code{services} field of
8534your operating system declaration leads to a @file{/usr/bin/env}
8535symlink:
8536
8537@example
8538(extra-special-file "/usr/bin/env"
8539 (file-append coreutils "/bin/env"))
8540@end example
8541@end deffn
8542
be1c2c54 8543@deffn {Scheme Procedure} host-name-service @var{name}
cf4a9129
LC
8544Return a service that sets the host name to @var{name}.
8545@end deffn
401c53c4 8546
317d3b47
DC
8547@deffn {Scheme Procedure} login-service @var{config}
8548Return a service to run login according to @var{config}, a
8549@code{<login-configuration>} object, which specifies the message of the day,
8550among other things.
8551@end deffn
8552
8553@deftp {Data Type} login-configuration
8554This is the data type representing the configuration of login.
8555
8556@table @asis
8557
8558@item @code{motd}
e32171ee 8559@cindex message of the day
317d3b47
DC
8560A file-like object containing the ``message of the day''.
8561
8562@item @code{allow-empty-passwords?} (default: @code{#t})
8563Allow empty passwords by default so that first-time users can log in when
8564the 'root' account has just been created.
8565
8566@end table
8567@end deftp
8568
66e4f01c
LC
8569@deffn {Scheme Procedure} mingetty-service @var{config}
8570Return a service to run mingetty according to @var{config}, a
8571@code{<mingetty-configuration>} object, which specifies the tty to run, among
8572other things.
cf4a9129 8573@end deffn
401c53c4 8574
66e4f01c
LC
8575@deftp {Data Type} mingetty-configuration
8576This is the data type representing the configuration of Mingetty, which
9ee4c9ab 8577provides the default implementation of virtual console log-in.
66e4f01c
LC
8578
8579@table @asis
8580
8581@item @code{tty}
8582The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
8583
66e4f01c
LC
8584@item @code{auto-login} (default: @code{#f})
8585When true, this field must be a string denoting the user name under
f9b9a033 8586which the system automatically logs in. When it is @code{#f}, a
66e4f01c
LC
8587user name and password must be entered to log in.
8588
8589@item @code{login-program} (default: @code{#f})
8590This must be either @code{#f}, in which case the default log-in program
8591is used (@command{login} from the Shadow tool suite), or a gexp denoting
8592the name of the log-in program.
8593
8594@item @code{login-pause?} (default: @code{#f})
8595When set to @code{#t} in conjunction with @var{auto-login}, the user
8596will have to press a key before the log-in shell is launched.
8597
8598@item @code{mingetty} (default: @var{mingetty})
8599The Mingetty package to use.
8600
8601@end table
8602@end deftp
8603
9ee4c9ab
LF
8604@deffn {Scheme Procedure} agetty-service @var{config}
8605Return a service to run agetty according to @var{config}, an
8606@code{<agetty-configuration>} object, which specifies the tty to run,
8607among other things.
8608@end deffn
8609
8610@deftp {Data Type} agetty-configuration
8611This is the data type representing the configuration of agetty, which
8612implements virtual and serial console log-in. See the @code{agetty(8)}
8613man page for more information.
8614
8615@table @asis
8616
8617@item @code{tty}
8618The name of the console this agetty runs on, as a string---e.g.,
8619@code{"ttyS0"}. This argument is mandatory.
8620
8621@item @code{baud-rate} (default: @code{#f})
8622A string containing a comma-separated list of one or more baud rates, in
8623descending order.
8624
8625@item @code{term} (default: @code{#f})
8626A string containing the value used for the @code{TERM} environment
8627variable.
8628
8629@item @code{eight-bits?} (default: @code{#f})
8630When @code{#t}, the tty is assumed to be 8-bit clean, and parity detection is
8631disabled.
8632
8633@item @code{auto-login} (default: @code{#f})
8634When passed a login name, as a string, the specified user will be logged
8635in automatically without prompting for their login name or password.
8636
8637@item @code{no-reset?} (default: @code{#f})
8638When @code{#t}, don't reset terminal cflags (control modes).
8639
8640@item @code{host} (default: @code{#f})
8641This accepts a string containing the "login_host", which will be written
8642into the @file{/var/run/utmpx} file.
8643
8644@item @code{remote?} (default: @code{#f})
8645When set to @code{#t} in conjunction with @var{host}, this will add an
8646@code{-r} fakehost option to the command line of the login program
8647specified in @var{login-program}.
8648
8649@item @code{flow-control?} (default: @code{#f})
8650When set to @code{#t}, enable hardware (RTS/CTS) flow control.
8651
8652@item @code{no-issue?} (default: @code{#f})
8653When set to @code{#t}, the contents of the @file{/etc/issue} file will
8654not be displayed before presenting the login prompt.
8655
8656@item @code{init-string} (default: @code{#f})
8657This accepts a string that will be sent to the tty or modem before
8658sending anything else. It can be used to initialize a modem.
8659
8660@item @code{no-clear?} (default: @code{#f})
8661When set to @code{#t}, agetty will not clear the screen before showing
8662the login prompt.
8663
8664@item @code{login-program} (default: (file-append shadow "/bin/login"))
8665This must be either a gexp denoting the name of a log-in program, or
8666unset, in which case the default value is the @command{login} from the
8667Shadow tool suite.
8668
8669@item @code{local-line} (default: @code{#f})
8670Control the CLOCAL line flag. This accepts one of three symbols as
8671arguments, @code{'auto}, @code{'always}, or @code{'never}. If @code{#f},
8672the default value chosen by agetty is @code{'auto}.
8673
8674@item @code{extract-baud?} (default: @code{#f})
8675When set to @code{#t}, instruct agetty to try to extract the baud rate
8676from the status messages produced by certain types of modems.
8677
8678@item @code{skip-login?} (default: @code{#f})
8679When set to @code{#t}, do not prompt the user for a login name. This
8680can be used with @var{login-program} field to use non-standard login
8681systems.
8682
8683@item @code{no-newline?} (default: @code{#f})
8684When set to @code{#t}, do not print a newline before printing the
8685@file{/etc/issue} file.
8686
8687@c Is this dangerous only when used with login-program, or always?
8688@item @code{login-options} (default: @code{#f})
8689This option accepts a string containing options that are passed to the
8690login program. When used with the @var{login-program}, be aware that a
8691malicious user could try to enter a login name containing embedded
8692options that could be parsed by the login program.
8693
8694@item @code{login-pause} (default: @code{#f})
8695When set to @code{#t}, wait for any key before showing the login prompt.
8696This can be used in conjunction with @var{auto-login} to save memory by
8697lazily spawning shells.
8698
8699@item @code{chroot} (default: @code{#f})
8700Change root to the specified directory. This option accepts a directory
8701path as a string.
8702
8703@item @code{hangup?} (default: @code{#f})
8704Use the Linux system call @code{vhangup} to do a virtual hangup of the
8705specified terminal.
8706
8707@item @code{keep-baud?} (default: @code{#f})
8708When set to @code{#t}, try to keep the existing baud rate. The baud
8709rates from @var{baud-rate} are used when agetty receives a @key{BREAK}
8710character.
8711
8712@item @code{timeout} (default: @code{#f})
8713When set to an integer value, terminate if no user name could be read
8714within @var{timeout} seconds.
8715
8716@item @code{detect-case?} (default: @code{#f})
8717When set to @code{#t}, turn on support for detecting an uppercase-only
8718terminal. This setting will detect a login name containing only
8719uppercase letters as indicating an uppercase-only terminal and turn on
8720some upper-to-lower case conversions. Note that this will not support
8721Unicode characters.
8722
8723@item @code{wait-cr?} (default: @code{#f})
8724When set to @code{#t}, wait for the user or modem to send a
8725carriage-return or linefeed character before displaying
8726@file{/etc/issue} or login prompt. This is typically used with the
8727@var{init-string} option.
8728
8729@item @code{no-hints?} (default: @code{#f})
8730When set to @code{#t}, do not print hints about Num, Caps, and Scroll
8731locks.
8732
8733@item @code{no-hostname?} (default: @code{#f})
8734By default, the hostname is printed. When this option is set to
8735@code{#t}, no hostname will be shown at all.
8736
8737@item @code{long-hostname?} (default: @code{#f})
8738By default, the hostname is only printed until the first dot. When this
8739option is set to @code{#t}, the fully qualified hostname by
8740@code{gethostname} or @code{getaddrinfo} is shown.
8741
8742@item @code{erase-characters} (default: @code{#f})
8743This option accepts a string of additional characters that should be
8744interpreted as backspace when the user types their login name.
8745
8746@item @code{kill-characters} (default: @code{#f})
8747This option accepts a string that should be interpreted to mean "ignore
8748all previous characters" (also called a "kill" character) when the types
8749their login name.
8750
8751@item @code{chdir} (default: @code{#f})
8752This option accepts, as a string, a directory path that will be changed
8753to before login.
8754
8755@item @code{delay} (default: @code{#f})
8756This options accepts, as an integer, the number of seconds to sleep
8757before opening the tty and displaying the login prompt.
8758
8759@item @code{nice} (default: @code{#f})
8760This option accepts, as an integer, the nice value with which to run the
8761@command{login} program.
8762
8763@item @code{extra-options} (default: @code{'()})
8764This option provides an "escape hatch" for the user to provide arbitrary
8765command-line arguments to @command{agetty} as a list of strings.
8766
8767@end table
8768@end deftp
8769
46ec2707
DC
8770@deffn {Scheme Procedure} kmscon-service-type @var{config}
8771Return a service to run @uref{https://www.freedesktop.org/wiki/Software/kmscon,kmscon}
8772according to @var{config}, a @code{<kmscon-configuration>} object, which
8773specifies the tty to run, among other things.
8774@end deffn
8775
8776@deftp {Data Type} kmscon-configuration
8777This is the data type representing the configuration of Kmscon, which
9ee4c9ab 8778implements virtual console log-in.
46ec2707
DC
8779
8780@table @asis
8781
8782@item @code{virtual-terminal}
8783The name of the console this Kmscon runs on---e.g., @code{"tty1"}.
8784
8785@item @code{login-program} (default: @code{#~(string-append #$shadow "/bin/login")})
8786A gexp denoting the name of the log-in program. The default log-in program is
8787@command{login} from the Shadow tool suite.
8788
8789@item @code{login-arguments} (default: @code{'("-p")})
8790A list of arguments to pass to @command{login}.
8791
8792@item @code{hardware-acceleration?} (default: #f)
8793Whether to use hardware acceleration.
8794
8795@item @code{kmscon} (default: @var{kmscon})
8796The Kmscon package to use.
8797
8798@end table
8799@end deftp
8800
6454b333
LC
8801@cindex name service cache daemon
8802@cindex nscd
be1c2c54 8803@deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
4aee6e60 8804 [#:name-services '()]
1068f26b 8805Return a service that runs the libc name service cache daemon (nscd) with the
b893f1ae
LC
8806given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
8807Service Switch}, for an example.
cf4a9129 8808@end deffn
401c53c4 8809
6454b333
LC
8810@defvr {Scheme Variable} %nscd-default-configuration
8811This is the default @code{<nscd-configuration>} value (see below) used
1068f26b 8812by @code{nscd-service}. It uses the caches defined by
6454b333
LC
8813@var{%nscd-default-caches}; see below.
8814@end defvr
8815
8816@deftp {Data Type} nscd-configuration
1068f26b 8817This is the data type representing the name service cache daemon (nscd)
6454b333
LC
8818configuration.
8819
8820@table @asis
8821
b893f1ae
LC
8822@item @code{name-services} (default: @code{'()})
8823List of packages denoting @dfn{name services} that must be visible to
8824the nscd---e.g., @code{(list @var{nss-mdns})}.
8825
8826@item @code{glibc} (default: @var{glibc})
8827Package object denoting the GNU C Library providing the @command{nscd}
8828command.
8829
6454b333 8830@item @code{log-file} (default: @code{"/var/log/nscd.log"})
1068f26b 8831Name of the nscd log file. This is where debugging output goes when
6454b333
LC
8832@code{debug-level} is strictly positive.
8833
8834@item @code{debug-level} (default: @code{0})
1068f26b 8835Integer denoting the debugging levels. Higher numbers mean that more
6454b333
LC
8836debugging output is logged.
8837
8838@item @code{caches} (default: @var{%nscd-default-caches})
8839List of @code{<nscd-cache>} objects denoting things to be cached; see
8840below.
8841
8842@end table
8843@end deftp
8844
8845@deftp {Data Type} nscd-cache
8846Data type representing a cache database of nscd and its parameters.
8847
8848@table @asis
8849
8850@item @code{database}
8851This is a symbol representing the name of the database to be cached.
8852Valid values are @code{passwd}, @code{group}, @code{hosts}, and
8853@code{services}, which designate the corresponding NSS database
8854(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
8855
8856@item @code{positive-time-to-live}
8857@itemx @code{negative-time-to-live} (default: @code{20})
8858A number representing the number of seconds during which a positive or
8859negative lookup result remains in cache.
8860
8861@item @code{check-files?} (default: @code{#t})
8862Whether to check for updates of the files corresponding to
8863@var{database}.
8864
8865For instance, when @var{database} is @code{hosts}, setting this flag
8866instructs nscd to check for updates in @file{/etc/hosts} and to take
8867them into account.
8868
8869@item @code{persistent?} (default: @code{#t})
8870Whether the cache should be stored persistently on disk.
8871
8872@item @code{shared?} (default: @code{#t})
8873Whether the cache should be shared among users.
8874
8875@item @code{max-database-size} (default: 32@tie{}MiB)
8876Maximum size in bytes of the database cache.
8877
8878@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
8879@c settings, so leave them out.
8880
8881@end table
8882@end deftp
8883
8884@defvr {Scheme Variable} %nscd-default-caches
8885List of @code{<nscd-cache>} objects used by default by
1068f26b 8886@code{nscd-configuration} (see above).
6454b333
LC
8887
8888It enables persistent and aggressive caching of service and host name
8889lookups. The latter provides better host name lookup performance,
8890resilience in the face of unreliable name servers, and also better
8891privacy---often the result of host name lookups is in local cache, so
8892external name servers do not even need to be queried.
8893@end defvr
8894
ec2e2f6c 8895@anchor{syslog-configuration-type}
e32171ee
JD
8896@cindex syslog
8897@cindex logging
ec2e2f6c
DC
8898@deftp {Data Type} syslog-configuration
8899This data type represents the configuration of the syslog daemon.
6454b333 8900
ec2e2f6c
DC
8901@table @asis
8902@item @code{syslogd} (default: @code{#~(string-append #$inetutils "/libexec/syslogd")})
8903The syslog daemon to use.
8904
8905@item @code{config-file} (default: @code{%default-syslog.conf})
8906The syslog configuration file to use.
8907
8908@end table
8909@end deftp
8910
8911@anchor{syslog-service}
e32171ee 8912@cindex syslog
ec2e2f6c
DC
8913@deffn {Scheme Procedure} syslog-service @var{config}
8914Return a service that runs a syslog daemon according to @var{config}.
44abcb28
LC
8915
8916@xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
8917information on the configuration file syntax.
cf4a9129 8918@end deffn
401c53c4 8919
0adfe95a
LC
8920@anchor{guix-configuration-type}
8921@deftp {Data Type} guix-configuration
8922This data type represents the configuration of the Guix build daemon.
8923@xref{Invoking guix-daemon}, for more information.
8924
8925@table @asis
8926@item @code{guix} (default: @var{guix})
8927The Guix package to use.
401c53c4 8928
0adfe95a
LC
8929@item @code{build-group} (default: @code{"guixbuild"})
8930Name of the group for build user accounts.
401c53c4 8931
0adfe95a
LC
8932@item @code{build-accounts} (default: @code{10})
8933Number of build user accounts to create.
401c53c4 8934
0adfe95a 8935@item @code{authorize-key?} (default: @code{#t})
e32171ee 8936@cindex substitutes, authorization thereof
5b58c28b
LC
8937Whether to authorize the substitute keys listed in
8938@code{authorized-keys}---by default that of @code{hydra.gnu.org}
0adfe95a
LC
8939(@pxref{Substitutes}).
8940
5b58c28b
LC
8941@vindex %default-authorized-guix-keys
8942@item @code{authorized-keys} (default: @var{%default-authorized-guix-keys})
8943The list of authorized key files for archive imports, as a list of
8944string-valued gexps (@pxref{Invoking guix archive}). By default, it
8945contains that of @code{hydra.gnu.org} (@pxref{Substitutes}).
8946
0adfe95a
LC
8947@item @code{use-substitutes?} (default: @code{#t})
8948Whether to use substitutes.
8949
b0b9f6e0
LC
8950@item @code{substitute-urls} (default: @var{%default-substitute-urls})
8951The list of URLs where to look for substitutes by default.
8952
0adfe95a
LC
8953@item @code{extra-options} (default: @code{'()})
8954List of extra command-line options for @command{guix-daemon}.
8955
dc0ef095
LC
8956@item @code{log-file} (default: @code{"/var/log/guix-daemon.log"})
8957File where @command{guix-daemon}'s standard output and standard error
8958are written.
8959
0adfe95a 8960@item @code{lsof} (default: @var{lsof})
f78903f3 8961The lsof package to use.
0adfe95a 8962
93d32da9
LF
8963@item @code{http-proxy} (default: @code{#f})
8964The HTTP proxy used for downloading fixed-output derivations and
8965substitutes.
8966
b191f0a6
LF
8967@item @code{tmpdir} (default: @code{#f})
8968A directory path where the @command{guix-daemon} will perform builds.
8969
0adfe95a
LC
8970@end table
8971@end deftp
8972
8973@deffn {Scheme Procedure} guix-service @var{config}
8974Return a service that runs the Guix build daemon according to
8975@var{config}.
cf4a9129 8976@end deffn
a1ba8475 8977
be1c2c54 8978@deffn {Scheme Procedure} udev-service [#:udev udev]
cf4a9129
LC
8979Run @var{udev}, which populates the @file{/dev} directory dynamically.
8980@end deffn
401c53c4 8981
a535e122
LF
8982@deffn {Scheme Procedure} urandom-seed-service @var{#f}
8983Save some entropy in @var{%random-seed-file} to seed @file{/dev/urandom}
8984when rebooting.
8985@end deffn
8986
8987@defvr {Scheme Variable} %random-seed-file
8988This is the name of the file where some random bytes are saved by
8989@var{urandom-seed-service} to seed @file{/dev/urandom} when rebooting.
8990It defaults to @file{/var/lib/random-seed}.
8991@end defvr
8992
e32171ee
JD
8993@cindex keymap
8994@cindex keyboard
b3d05f48 8995@deffn {Scheme Procedure} console-keymap-service @var{files} ...
dedb8d5e 8996@cindex keyboard layout
b3d05f48
AK
8997Return a service to load console keymaps from @var{files} using
8998@command{loadkeys} command. Most likely, you want to load some default
8999keymap, which can be done like this:
9000
9001@example
9002(console-keymap-service "dvorak")
9003@end example
9004
9005Or, for example, for a Swedish keyboard, you may need to combine
9006the following keymaps:
9007@example
9008(console-keymap-service "se-lat6" "se-fi-lat6")
9009@end example
9010
9011Also you can specify a full file name (or file names) of your keymap(s).
9012See @code{man loadkeys} for details.
9013
5eca9459
AK
9014@end deffn
9015
e32171ee
JD
9016@cindex mouse
9017@cindex gpm
1aaf116d 9018@deffn {Scheme Procedure} gpm-service [#:gpm @var{gpm}] @
8664cc88
LC
9019 [#:options]
9020Run @var{gpm}, the general-purpose mouse daemon, with the given
9021command-line @var{options}. GPM allows users to use the mouse in the console,
9022notably to select, copy, and paste text. The default value of @var{options}
9023uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
9024
9025This service is not part of @var{%base-services}.
9026@end deffn
9027
f1e900a3
LC
9028@anchor{guix-publish-service-type}
9029@deffn {Scheme Variable} guix-publish-service-type @var{config}
9030This is the service type for @command{guix publish} (@pxref{Invoking
9031guix publish}). @var{config} must be a @code{guix-configuration}
9032object, as described below.
1c52181f
LC
9033
9034This assumes that @file{/etc/guix} already contains a signing key pair as
9035created by @command{guix archive --generate-key} (@pxref{Invoking guix
9036archive}). If that is not the case, the service will fail to start.
9037@end deffn
9038
f1e900a3
LC
9039@deftp {Data Type} guix-publish-configuration
9040Data type representing the configuration of the @code{guix publish}
9041service.
9042
9043@table @asis
9044@item @code{guix} (default: @code{guix})
9045The Guix package to use.
9046
9047@item @code{port} (default: @code{80})
9048The TCP port to listen for connections.
9049
9050@item @code{host} (default: @code{"localhost"})
9051The host (and thus, network interface) to listen to. Use
9052@code{"0.0.0.0"} to listen on all the network interfaces.
697ddb88
LC
9053
9054@item @code{compression-level} (default: @code{3})
9055The gzip compression level at which substitutes are compressed. Use
9056@code{0} to disable compression altogether, and @code{9} to get the best
9057compression ratio at the expense of increased CPU usage.
9058
9059@item @code{nar-path} (default: @code{"nar"})
9060The URL path at which ``nars'' can be fetched. @xref{Invoking guix
9061publish, @code{--nar-path}}, for details.
f1e900a3
LC
9062@end table
9063@end deftp
9064
b58cbf9a
DC
9065@anchor{rngd-service}
9066@deffn {Scheme Procedure} rngd-service [#:rng-tools @var{rng-tools}] @
9067 [#:device "/dev/hwrng"]
9068Return a service that runs the @command{rngd} program from @var{rng-tools}
9069to add @var{device} to the kernel's entropy pool. The service will fail if
9070@var{device} does not exist.
9071@end deffn
a69576ea 9072
909147e4
RW
9073@anchor{pam-limits-service}
9074@cindex session limits
9075@cindex ulimit
9076@cindex priority
9077@deffn {Scheme Procedure} pam-limits-service [#:limits @var{limits}]
9078
9079Return a service that installs a configuration file for the
9080@uref{http://linux-pam.org/Linux-PAM-html/sag-pam_limits.html,
9081@code{pam_limits} module}. The procedure optionally takes a list of
9082@code{pam-limits-entry} values, which can be used to specify
9083@code{ulimit} limits and nice priority limits to user sessions.
9084
9085The following limits definition sets two hard and soft limits for all
9086login sessions of users in the @code{realtime} group:
9087
9088@example
9089(pam-limits-service
9090 (list
9091 (pam-limits-entry "@@realtime" 'both 'rtprio 99)
9092 (pam-limits-entry "@@realtime" 'both 'memlock 'unlimited)))
9093@end example
9094
9095The first entry increases the maximum realtime priority for
9096non-privileged processes; the second entry lifts any restriction of the
9097maximum address space that can be locked in memory. These settings are
9098commonly used for real-time audio systems.
9099@end deffn
9100
c311089b
LC
9101@node Scheduled Job Execution
9102@subsubsection Scheduled Job Execution
9103
9104@cindex cron
e32171ee 9105@cindex mcron
c311089b
LC
9106@cindex scheduling jobs
9107The @code{(gnu services mcron)} module provides an interface to
9108GNU@tie{}mcron, a daemon to run jobs at scheduled times (@pxref{Top,,,
9109mcron, GNU@tie{}mcron}). GNU@tie{}mcron is similar to the traditional
9110Unix @command{cron} daemon; the main difference is that it is
9111implemented in Guile Scheme, which provides a lot of flexibility when
9112specifying the scheduling of jobs and their actions.
9113
8ac6282c 9114The example below defines an operating system that runs the
c311089b 9115@command{updatedb} (@pxref{Invoking updatedb,,, find, Finding Files})
8ac6282c
LC
9116and the @command{guix gc} commands (@pxref{Invoking guix gc}) daily, as
9117well as the @command{mkid} command on behalf of an unprivileged user
9118(@pxref{mkid invocation,,, idutils, ID Database Utilities}). It uses
9119gexps to introduce job definitions that are passed to mcron
9120(@pxref{G-Expressions}).
c311089b
LC
9121
9122@lisp
9123(use-modules (guix) (gnu) (gnu services mcron))
8ac6282c 9124(use-package-modules base idutils)
c311089b
LC
9125
9126(define updatedb-job
8ac6282c
LC
9127 ;; Run 'updatedb' at 3AM every day. Here we write the
9128 ;; job's action as a Scheme procedure.
c311089b 9129 #~(job '(next-hour '(3))
8ac6282c
LC
9130 (lambda ()
9131 (execl (string-append #$findutils "/bin/updatedb")
9132 "updatedb"
9133 "--prunepaths=/tmp /var/tmp /gnu/store"))))
c311089b
LC
9134
9135(define garbage-collector-job
9136 ;; Collect garbage 5 minutes after midnight every day.
8ac6282c 9137 ;; The job's action is a shell command.
c311089b
LC
9138 #~(job "5 0 * * *" ;Vixie cron syntax
9139 "guix gc -F 1G"))
9140
80d944b7 9141(define idutils-job
8ac6282c
LC
9142 ;; Update the index database as user "charlie" at 12:15PM
9143 ;; and 19:15PM. This runs from the user's home directory.
9144 #~(job '(next-minute-from (next-hour '(12 19)) '(15))
9145 (string-append #$idutils "/bin/mkid src")
9146 #:user "charlie"))
9147
c311089b
LC
9148(operating-system
9149 ;; @dots{}
9150 (services (cons (mcron-service (list garbage-collector-job
8ac6282c
LC
9151 updatedb-job
9152 idutils-job))
c311089b
LC
9153 %base-services)))
9154@end lisp
9155
9156@xref{Guile Syntax, mcron job specifications,, mcron, GNU@tie{}mcron},
9157for more information on mcron job specifications. Below is the
9158reference of the mcron service.
9159
9160@deffn {Scheme Procedure} mcron-service @var{jobs} [#:mcron @var{mcron2}]
9161Return an mcron service running @var{mcron} that schedules @var{jobs}, a
9162list of gexps denoting mcron job specifications.
9163
9164This is a shorthand for:
9165@example
80d944b7
LC
9166(service mcron-service-type
9167 (mcron-configuration (mcron mcron) (jobs jobs)))
c311089b
LC
9168@end example
9169@end deffn
9170
9171@defvr {Scheme Variable} mcron-service-type
9172This is the type of the @code{mcron} service, whose value is an
9173@code{mcron-configuration} object.
9174
9175This service type can be the target of a service extension that provides
9176it additional job specifications (@pxref{Service Composition}). In
80d944b7 9177other words, it is possible to define services that provide additional
c311089b
LC
9178mcron jobs to run.
9179@end defvr
9180
9181@deftp {Data Type} mcron-configuration
9182Data type representing the configuration of mcron.
9183
9184@table @asis
9185@item @code{mcron} (default: @var{mcron2})
9186The mcron package to use.
9187
9188@item @code{jobs}
9189This is a list of gexps (@pxref{G-Expressions}), where each gexp
9190corresponds to an mcron job specification (@pxref{Syntax, mcron job
9191specifications,, mcron, GNU@tie{}mcron}).
9192@end table
9193@end deftp
9194
9195
92c03a87
JN
9196@node Log Rotation
9197@subsubsection Log Rotation
9198
9199@cindex rottlog
9200@cindex log rotation
e32171ee 9201@cindex logging
92c03a87
JN
9202Log files such as those found in @file{/var/log} tend to grow endlessly,
9203so it's a good idea to @dfn{rotate} them once in a while---i.e., archive
9204their contents in separate files, possibly compressed. The @code{(gnu
9205services admin)} module provides an interface to GNU@tie{}Rot[t]log, a
9206log rotation tool (@pxref{Top,,, rottlog, GNU Rot[t]log Manual}).
9207
9208The example below defines an operating system that provides log rotation
9209with the default settings.
9210
9211@lisp
9212(use-modules (guix) (gnu))
9213(use-service-modules admin mcron)
9214(use-package-modules base idutils)
9215
9216(operating-system
9217 ;; @dots{}
9218 (services (cons* (mcron-service)
9219 (service rottlog-service-type (rottlog-configuration))
9220 %base-services)))
9221@end lisp
9222
9223@defvr {Scheme Variable} rottlog-service-type
9224This is the type of the Rottlog service, whose value is a
9225@code{rottlog-configuration} object.
9226
9227This service type can define mcron jobs (@pxref{Scheduled Job
9228Execution}) to run the rottlog service.
9229@end defvr
9230
9231@deftp {Data Type} rottlog-configuration
9232Data type representing the configuration of rottlog.
9233
9234@table @asis
9235@item @code{rottlog} (default: @code{rottlog})
9236The Rottlog package to use.
9237
9238@item @code{rc-file} (default: @code{(file-append rottlog "/etc/rc")})
9239The Rottlog configuration file to use (@pxref{Mandatory RC Variables,,,
9240rottlog, GNU Rot[t]log Manual}).
9241
9fc221b5 9242@item @code{periodic-rotations} (default: @code{`(("weekly" %default-rotations))})
92c03a87
JN
9243A list of Rottlog period-name/period-config tuples.
9244
9245For example, taking an example from the Rottlog manual (@pxref{Period
9246Related File Examples,,, rottlog, GNU Rot[t]log Manual}), a valid tuple
9247might be:
9248
9249@example
9250("daily" ,(plain-file "daily"
9251 "\
9252 /var/log/apache/* @{
9253 storedir apache-archives
9254 rotate 6
9255 notifempty
9256 nocompress
9257 @}"))
9258@end example
9259
9260@item @code{jobs}
9261This is a list of gexps where each gexp corresponds to an mcron job
9262specification (@pxref{Scheduled Job Execution}).
9263@end table
9264@end deftp
9265
9266@defvr {Scheme Variable} %default-rotations
9267Specifies weekly rotation of @var{%rotated-files} and
9268@code{"/var/log/shepherd.log"}.
9269@end defvr
9270
9271@defvr {Scheme Variable} %rotated-files
9272The list of syslog-controlled files to be rotated. By default it is:
9273@code{'("/var/log/messages" "/var/log/secure")}.
9274@end defvr
9275
cf4a9129
LC
9276@node Networking Services
9277@subsubsection Networking Services
401c53c4 9278
fa1e31b8 9279The @code{(gnu services networking)} module provides services to configure
cf4a9129 9280the network interface.
a1ba8475 9281
a023cca8 9282@cindex DHCP, networking service
be1c2c54 9283@deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
a023cca8
LC
9284Return a service that runs @var{dhcp}, a Dynamic Host Configuration
9285Protocol (DHCP) client, on all the non-loopback network interfaces.
9286@end deffn
9287
8de3e4b3
LC
9288@defvr {Scheme Variable} static-networking-service-type
9289This is the type for statically-configured network interfaces.
9290@c TODO Document <static-networking> data structures.
9291@end defvr
9292
be1c2c54 9293@deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
1f9803c2 9294 [#:netmask #f] [#:gateway #f] [#:name-servers @code{'()}]
cf4a9129 9295Return a service that starts @var{interface} with address @var{ip}. If
1f9803c2
LC
9296@var{netmask} is true, use it as the network mask. If @var{gateway} is true,
9297it must be a string specifying the default network gateway.
8de3e4b3
LC
9298
9299This procedure can be called several times, one for each network
9300interface of interest. Behind the scenes what it does is extend
9301@code{static-networking-service-type} with additional network interfaces
9302to handle.
cf4a9129 9303@end deffn
8b315a6d 9304
b7d0c494 9305@cindex wicd
e32171ee
JD
9306@cindex wireless
9307@cindex WiFi
87f40011 9308@cindex network management
be1c2c54 9309@deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
87f40011
LC
9310Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
9311management daemon that aims to simplify wired and wireless networking.
9312
9313This service adds the @var{wicd} package to the global profile, providing
9314several commands to interact with the daemon and configure networking:
9315@command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
9316and @command{wicd-curses} user interfaces.
b7d0c494
MW
9317@end deffn
9318
c0a9589d 9319@cindex NetworkManager
b726096b
CB
9320
9321@defvr {Scheme Variable} network-manager-service-type
9322This is the service type for the
9323@uref{https://wiki.gnome.org/Projects/NetworkManager, NetworkManager}
9324service. The value for this service type is a
9325@code{network-manager-configuration} record.
9326@end defvr
9327
9328@deftp {Data Type} network-manager-configuration
9329Data type representing the configuration of NetworkManager.
9330
9331@table @asis
9332@item @code{network-manager} (default: @code{network-manager})
9333The NetworkManager package to use.
9334
9335@item @code{dns} (default: @code{"default"})
9336Processing mode for DNS, which affects how NetworkManager uses the
9337@code{resolv.conf} configuration file.
9338
9339@table @samp
9340@item default
9341NetworkManager will update @code{resolv.conf} to reflect the nameservers
9342provided by currently active connections.
9343
9344@item dnsmasq
9345NetworkManager will run @code{dnsmasq} as a local caching nameserver,
9346using a "split DNS" configuration if you are connected to a VPN, and
9347then update @code{resolv.conf} to point to the local nameserver.
9348
9349@item none
9350NetworkManager will not modify @code{resolv.conf}.
9351@end table
9352
9353@end table
9354@end deftp
c0a9589d 9355
76192896 9356@cindex Connman
34d60c49
MO
9357@deffn {Scheme Variable} connman-service-type
9358This is the service type to run @url{https://01.org/connman,Connman},
9359a network connection manager.
9360
9361Its value must be an
9362@code{connman-configuration} record as in this example:
9363
9364@example
9365(service connman-service-type
9366 (connman-configuration
9367 (disable-vpn? #t)))
9368@end example
9369
9370See below for details about @code{connman-configuration}.
76192896
EF
9371@end deffn
9372
34d60c49
MO
9373@deftp {Data Type} connman-configuration
9374Data Type representing the configuration of connman.
9375
9376@table @asis
9377@item @code{connman} (default: @var{connman})
9378The connman package to use.
9379
9380@item @code{disable-vpn?} (default: @code{#f})
9381When true, enable connman's vpn plugin.
9382@end table
9383@end deftp
9384
2cccbc2a 9385@cindex WPA Supplicant
cbf1024e
LC
9386@defvr {Scheme Variable} wpa-supplicant-service-type
9387This is the service type to run @url{https://w1.fi/wpa_supplicant/,WPA
2cccbc2a 9388supplicant}, an authentication daemon required to authenticate against
cbf1024e 9389encrypted WiFi or ethernet networks. It is configured to listen for
2cccbc2a 9390requests on D-Bus.
cbf1024e
LC
9391
9392The value of this service is the @code{wpa-supplicant} package to use.
9393Thus, it can be instantiated like this:
9394
9395@lisp
9396(use-modules (gnu services networking)
9397 (gnu packages admin))
9398
9747d189 9399(service wpa-supplicant-service-type wpa-supplicant)
cbf1024e
LC
9400@end lisp
9401@end defvr
2cccbc2a 9402
e32171ee
JD
9403@cindex NTP
9404@cindex real time clock
be1c2c54 9405@deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
dc0322b5
LC
9406 [#:servers @var{%ntp-servers}] @
9407 [#:allow-large-adjustment? #f]
63854bcb
LC
9408Return a service that runs the daemon from @var{ntp}, the
9409@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
9410keep the system clock synchronized with that of @var{servers}.
dc0322b5
LC
9411@var{allow-large-adjustment?} determines whether @command{ntpd} is allowed to
9412make an initial adjustment of more than 1,000 seconds.
63854bcb
LC
9413@end deffn
9414
9415@defvr {Scheme Variable} %ntp-servers
9416List of host names used as the default NTP servers.
9417@end defvr
9418
9260b9d1
TD
9419@cindex inetd
9420@deffn {Scheme variable} inetd-service-type
9421This service runs the @command{inetd} (@pxref{inetd invocation,,,
9422inetutils, GNU Inetutils}) daemon. @command{inetd} listens for
9423connections on internet sockets, and lazily starts the specified server
9424program when a connection is made on one of these sockets.
9425
9426The value of this service is an @code{inetd-configuration} object. The
9427following example configures the @command{inetd} daemon to provide the
9428built-in @command{echo} service, as well as an smtp service which
9429forwards smtp traffic over ssh to a server @code{smtp-server} behind a
9430gateway @code{hostname}:
9431
9432@example
9433(service
9434 inetd-service-type
9435 (inetd-configuration
9436 (entries (list
9437 (inetd-entry
9438 (name "echo")
9439 (socket-type 'stream)
9440 (protocol "tcp")
9441 (wait? #f)
9442 (user "root"))
9443 (inetd-entry
9444 (node "127.0.0.1")
9445 (name "smtp")
9446 (socket-type 'stream)
9447 (protocol "tcp")
9448 (wait? #f)
9449 (user "root")
9450 (program (file-append openssh "/bin/ssh"))
9451 (arguments
9452 '("ssh" "-qT" "-i" "/path/to/ssh_key"
9453 "-W" "smtp-server:25" "user@@hostname")))))
9454@end example
9455
9456See below for more details about @code{inetd-configuration}.
9457@end deffn
9458
9459@deftp {Data Type} inetd-configuration
9460Data type representing the configuration of @command{inetd}.
9461
9462@table @asis
9463@item @code{program} (default: @code{(file-append inetutils "/libexec/inetd")})
9464The @command{inetd} executable to use.
9465
9466@item @code{entries} (default: @code{'()})
9467A list of @command{inetd} service entries. Each entry should be created
9468by the @code{inetd-entry} constructor.
9469@end table
9470@end deftp
9471
9472@deftp {Data Type} inetd-entry
9473Data type representing an entry in the @command{inetd} configuration.
9474Each entry corresponds to a socket where @command{inetd} will listen for
9475requests.
9476
9477@table @asis
9478@item @code{node} (default: @code{#f})
9479Optional string, a comma-separated list of local addresses
9480@command{inetd} should use when listening for this service.
9481@xref{Configuration file,,, inetutils, GNU Inetutils} for a complete
9482description of all options.
9483@item @code{name}
9484A string, the name must correspond to an entry in @code{/etc/services}.
9485@item @code{socket-type}
9486One of @code{'stream}, @code{'dgram}, @code{'raw}, @code{'rdm} or
9487@code{'seqpacket}.
9488@item @code{protocol}
9489A string, must correspond to an entry in @code{/etc/protocols}.
9490@item @code{wait?} (default: @code{#t})
9491Whether @command{inetd} should wait for the server to exit before
9492listening to new service requests.
9493@item @code{user}
9494A string containing the user (and, optionally, group) name of the user
9495as whom the server should run. The group name can be specified in a
9496suffix, separated by a colon or period, i.e. @code{"user"},
9497@code{"user:group"} or @code{"user.group"}.
9498@item @code{program} (default: @code{"internal"})
9499The server program which will serve the requests, or @code{"internal"}
9500if @command{inetd} should use a built-in service.
9501@item @code{arguments} (default: @code{'()})
9502A list strings or file-like objects, which are the server program's
9503arguments, starting with the zeroth argument, i.e. the name of the
9504program itself. For @command{inetd}'s internal services, this entry
9505must be @code{'()} or @code{'("internal")}.
9506@end table
9507
9508@xref{Configuration file,,, inetutils, GNU Inetutils} for a more
9509detailed discussion of each configuration field.
9510@end deftp
9511
e32171ee 9512@cindex Tor
375c6108
LC
9513@deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
9514Return a service to run the @uref{https://torproject.org, Tor} anonymous
9515networking daemon.
8b315a6d 9516
375c6108 9517The daemon runs as the @code{tor} unprivileged user. It is passed
6331bde7
LC
9518@var{config-file}, a file-like object, with an additional @code{User tor} line
9519and lines for hidden services added via @code{tor-hidden-service}. Run
9520@command{man tor} for information about the configuration file.
9521@end deffn
9522
24a8ef3b 9523@cindex hidden service
6331bde7
LC
9524@deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
9525Define a new Tor @dfn{hidden service} called @var{name} and implementing
9526@var{mapping}. @var{mapping} is a list of port/host tuples, such as:
9527
9528@example
24a8ef3b
LC
9529 '((22 "127.0.0.1:22")
9530 (80 "127.0.0.1:8080"))
6331bde7
LC
9531@end example
9532
9533In this example, port 22 of the hidden service is mapped to local port 22, and
9534port 80 is mapped to local port 8080.
9535
6629099a
LC
9536This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
9537the @file{hostname} file contains the @code{.onion} host name for the hidden
6331bde7
LC
9538service.
9539
9540See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
9541project's documentation} for more information.
cf4a9129 9542@end deffn
8b315a6d 9543
be1c2c54 9544@deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
4627a464
LC
9545 [#:interface "127.0.0.1"] [#:port 6667] @
9546 [#:extra-settings ""]
9547Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
9548acts as a gateway between IRC and chat networks.
9549
9550The daemon will listen to the interface corresponding to the IP address
9551specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
9552local clients can connect, whereas @code{0.0.0.0} means that connections can
9553come from any networking interface.
9554
9555In addition, @var{extra-settings} specifies a string to append to the
9556configuration file.
9557@end deffn
9558
71b0601a 9559Furthermore, @code{(gnu services ssh)} provides the following services.
e32171ee
JD
9560@cindex SSH
9561@cindex SSH server
8b315a6d 9562
be1c2c54 9563@deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 9564 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
9565 [#:allow-empty-passwords? #f] [#:root-login? #f] @
9566 [#:syslog-output? #t] [#:x11-forwarding? #t] @
9567 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 9568 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
9569Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
9570@var{host-key} must designate a file containing the host key, and readable
9571only by root.
72e25e35 9572
5833bf33
DP
9573When @var{daemonic?} is true, @command{lshd} will detach from the
9574controlling terminal and log its output to syslogd, unless one sets
9575@var{syslog-output?} to false. Obviously, it also makes lsh-service
9576depend on existence of syslogd service. When @var{pid-file?} is true,
9577@command{lshd} writes its PID to the file called @var{pid-file}.
9578
cf4a9129
LC
9579When @var{initialize?} is true, automatically create the seed and host key
9580upon service activation if they do not exist yet. This may take long and
9581require interaction.
8b315a6d 9582
20dd519c
LC
9583When @var{initialize?} is false, it is up to the user to initialize the
9584randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
9585a key pair with the private key stored in file @var{host-key} (@pxref{lshd
9586basics,,, lsh, LSH Manual}).
9587
cf4a9129
LC
9588When @var{interfaces} is empty, lshd listens for connections on all the
9589network interfaces; otherwise, @var{interfaces} must be a list of host names
9590or addresses.
9bf3c1a7 9591
20dd519c
LC
9592@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
9593passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 9594root.
4af2447e 9595
cf4a9129
LC
9596The other options should be self-descriptive.
9597@end deffn
4af2447e 9598
e32171ee
JD
9599@cindex SSH
9600@cindex SSH server
d8f31281
LC
9601@deffn {Scheme Variable} openssh-service-type
9602This is the type for the @uref{http://www.openssh.org, OpenSSH} secure
9603shell daemon, @command{sshd}. Its value must be an
9604@code{openssh-configuration} record as in this example:
9605
9606@example
9607(service openssh-service-type
9608 (openssh-configuration
9609 (x11-forwarding? #t)
9610 (permit-root-login 'without-password)))
9611@end example
9612
9613See below for details about @code{openssh-configuration}.
86d8f6d3
JL
9614@end deffn
9615
d8f31281
LC
9616@deftp {Data Type} openssh-configuration
9617This is the configuration record for OpenSSH's @command{sshd}.
9618
9619@table @asis
9620@item @code{pid-file} (default: @code{"/var/run/sshd.pid"})
9621Name of the file where @command{sshd} writes its PID.
9622
9623@item @code{port-number} (default: @code{22})
9624TCP port on which @command{sshd} listens for incoming connections.
9625
9626@item @code{permit-root-login} (default: @code{#f})
9627This field determines whether and when to allow logins as root. If
9628@code{#f}, root logins are disallowed; if @code{#t}, they are allowed.
9629If it's the symbol @code{'without-password}, then root logins are
9630permitted but not with password-based authentication.
9631
9632@item @code{allow-empty-passwords?} (default: @code{#f})
9633When true, users with empty passwords may log in. When false, they may
9634not.
9635
9636@item @code{password-authentication?} (default: @code{#t})
9637When true, users may log in with their password. When false, they have
9638other authentication methods.
9639
9640@item @code{public-key-authentication?} (default: @code{#t})
9641When true, users may log in using public key authentication. When
9642false, users have to use other authentication method.
9643
9644Authorized public keys are stored in @file{~/.ssh/authorized_keys}.
9645This is used only by protocol version 2.
9646
d8f31281
LC
9647@item @code{x11-forwarding?} (default: @code{#f})
9648When true, forwarding of X11 graphical client connections is
9649enabled---in other words, @command{ssh} options @option{-X} and
9650@option{-Y} will work.
9651
563c5d42
CL
9652@item @code{challenge-response-authentication?} (default: @code{#f})
9653Specifies whether challenge response authentication is allowed (e.g. via
9654PAM).
9655
9656@item @code{use-pam?} (default: @code{#t})
9657Enables the Pluggable Authentication Module interface. If set to
9658@code{#t}, this will enable PAM authentication using
9659@code{challenge-response-authentication?} and
9660@code{password-authentication?}, in addition to PAM account and session
9661module processing for all authentication types.
9662
9663Because PAM challenge response authentication usually serves an
9664equivalent role to password authentication, you should disable either
9665@code{challenge-response-authentication?} or
9666@code{password-authentication?}.
f895dce4
CL
9667
9668@item @code{print-last-log?} (default: @code{#t})
9669Specifies whether @command{sshd} should print the date and time of the
9670last user login when a user logs in interactively.
12723370
CL
9671
9672@item @code{subsystems} (default: @code{'(("sftp" "internal-sftp"))})
9673Configures external subsystems (e.g. file transfer daemon).
9674
9675This is a list of two-element lists, each of which containing the
9676subsystem name and a command (with optional arguments) to execute upon
9677subsystem request.
9678
9679The command @command{internal-sftp} implements an in-process SFTP
9680server. Alternately, one can specify the @command{sftp-server} command:
9681@example
9682(service openssh-service-type
9683 (openssh-configuration
9684 (subsystems
9685 '(("sftp" ,(file-append openssh "/libexec/sftp-server"))))))
9686@end example
d8f31281
LC
9687@end table
9688@end deftp
9689
71b0601a
DC
9690@deffn {Scheme Procedure} dropbear-service [@var{config}]
9691Run the @uref{https://matt.ucc.asn.au/dropbear/dropbear.html,Dropbear SSH
9692daemon} with the given @var{config}, a @code{<dropbear-configuration>}
9693object.
9694
9695For example, to specify a Dropbear service listening on port 1234, add
9696this call to the operating system's @code{services} field:
9697
9698@example
9699(dropbear-service (dropbear-configuration
9700 (port-number 1234)))
9701@end example
9702@end deffn
9703
9704@deftp {Data Type} dropbear-configuration
9705This data type represents the configuration of a Dropbear SSH daemon.
9706
9707@table @asis
9708@item @code{dropbear} (default: @var{dropbear})
9709The Dropbear package to use.
9710
9711@item @code{port-number} (default: 22)
9712The TCP port where the daemon waits for incoming connections.
9713
9714@item @code{syslog-output?} (default: @code{#t})
9715Whether to enable syslog output.
9716
9717@item @code{pid-file} (default: @code{"/var/run/dropbear.pid"})
9718File name of the daemon's PID file.
9719
9720@item @code{root-login?} (default: @code{#f})
9721Whether to allow @code{root} logins.
9722
9723@item @code{allow-empty-passwords?} (default: @code{#f})
9724Whether to allow empty passwords.
9725
9726@item @code{password-authentication?} (default: @code{#t})
9727Whether to enable password-based authentication.
9728@end table
9729@end deftp
9730
fa0c1d61
LC
9731@defvr {Scheme Variable} %facebook-host-aliases
9732This variable contains a string for use in @file{/etc/hosts}
9733(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
9734line contains a entry that maps a known server name of the Facebook
9735on-line service---e.g., @code{www.facebook.com}---to the local
9736host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
9737
9738This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
9739@code{operating-system} declaration (@pxref{operating-system Reference,
9740@file{/etc/hosts}}):
fa0c1d61
LC
9741
9742@example
9743(use-modules (gnu) (guix))
9744
9745(operating-system
9746 (host-name "mymachine")
9747 ;; ...
9748 (hosts-file
9749 ;; Create a /etc/hosts file with aliases for "localhost"
9750 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
9751 (plain-file "hosts"
9752 (string-append (local-host-aliases host-name)
9753 %facebook-host-aliases))))
fa0c1d61
LC
9754@end example
9755
9756This mechanism can prevent programs running locally, such as Web
9757browsers, from accessing Facebook.
9758@end defvr
9759
965a7332
LC
9760The @code{(gnu services avahi)} provides the following definition.
9761
be1c2c54 9762@deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
965a7332
LC
9763 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
9764 [#:ipv6? #t] [#:wide-area? #f] @
c8695f32 9765 [#:domains-to-browse '()] [#:debug? #f]
965a7332
LC
9766Return a service that runs @command{avahi-daemon}, a system-wide
9767mDNS/DNS-SD responder that allows for service discovery and
cc9c1f39
LC
9768"zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
9769extends the name service cache daemon (nscd) so that it can resolve
9770@code{.local} host names using
1065bed9
LC
9771@uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
9772add the @var{avahi} package to the system profile so that commands such as
9773@command{avahi-browse} are directly usable.
965a7332
LC
9774
9775If @var{host-name} is different from @code{#f}, use that as the host name to
9776publish for this machine; otherwise, use the machine's actual host name.
9777
9778When @var{publish?} is true, publishing of host names and services is allowed;
9779in particular, avahi-daemon will publish the machine's host name and IP
9780address via mDNS on the local network.
9781
9782When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
9783
9784Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
9785sockets.
9786@end deffn
9787
c32d02fe
SB
9788@deffn {Scheme Variable} openvswitch-service-type
9789This is the type of the @uref{http://www.openvswitch.org, Open vSwitch}
9790service, whose value should be an @code{openvswitch-configuration}
9791object.
9792@end deffn
9793
9794@deftp {Data Type} openvswitch-configuration
9795Data type representing the configuration of Open vSwitch, a multilayer
9796virtual switch which is designed to enable massive network automation
9797through programmatic extension.
9798
9799@table @asis
9800@item @code{package} (default: @var{openvswitch})
9801Package object of the Open vSwitch.
9802
9803@end table
9804@end deftp
965a7332 9805
cf4a9129
LC
9806@node X Window
9807@subsubsection X Window
68ad877c 9808
e32171ee
JD
9809@cindex X11
9810@cindex X Window System
cf4a9129
LC
9811Support for the X Window graphical display system---specifically
9812Xorg---is provided by the @code{(gnu services xorg)} module. Note that
9813there is no @code{xorg-service} procedure. Instead, the X server is
9814started by the @dfn{login manager}, currently SLiM.
4af2447e 9815
935644c0
DC
9816@deftp {Data Type} sddm-configuration
9817This is the data type representing the sddm service configuration.
9818
9819@table @asis
9820@item @code{display-server} (default: "x11")
9821Select display server to use for the greeter. Valid values are "x11"
9822or "wayland".
9823
9824@item @code{numlock} (default: "on")
9825Valid values are "on", "off" or "none".
9826
9827@item @code{halt-command} (default @code{#~(string-apppend #$shepherd "/sbin/halt")})
9828Command to run when halting.
9829
9830@item @code{reboot-command} (default @code{#~(string-append #$shepherd "/sbin/reboot")})
9831Command to run when rebooting.
9832
9833@item @code{theme} (default "maldives")
9834Theme to use. Default themes provided by SDDM are "elarun" or "maldives".
9835
9836@item @code{themes-directory} (default "/run/current-system/profile/share/sddm/themes")
9837Directory to look for themes.
9838
9839@item @code{faces-directory} (default "/run/current-system/profile/share/sddm/faces")
9840Directory to look for faces.
9841
9842@item @code{default-path} (default "/run/current-system/profile/bin")
9843Default PATH to use.
9844
9845@item @code{minimum-uid} (default 1000)
9846Minimum UID to display in SDDM.
9847
9848@item @code{maximum-uid} (default 2000)
9849Maximum UID to display in SDDM
9850
9851@item @code{remember-last-user?} (default #t)
9852Remember last user.
9853
9854@item @code{remember-last-session?} (default #t)
9855Remember last session.
9856
9857@item @code{hide-users} (default "")
9858Usernames to hide from SDDM greeter.
9859
9860@item @code{hide-shells} (default @code{#~(string-append #$shadow "/sbin/nologin")})
9861Users with shells listed will be hidden from the SDDM greeter.
9862
9863@item @code{session-command} (default @code{#~(string-append #$sddm "/share/sddm/scripts/wayland-session")})
9864Script to run before starting a wayland session.
9865
9866@item @code{sessions-directory} (default "/run/current-system/profile/share/wayland-sessions")
9867Directory to look for desktop files starting wayland sessions.
9868
9869@item @code{xorg-server-path} (default @code{xorg-start-command})
9870Path to xorg-server.
9871
9872@item @code{xauth-path} (default @code{#~(string-append #$xauth "/bin/xauth")})
9873Path to xauth.
9874
9875@item @code{xephyr-path} (default @code{#~(string-append #$xorg-server "/bin/Xephyr")})
9876Path to Xephyr.
9877
9878@item @code{xdisplay-start} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xsetup")})
9879Script to run after starting xorg-server.
9880
9881@item @code{xdisplay-stop} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xstop")})
9882Script to run before stopping xorg-server.
9883
9884@item @code{xsession-command} (default: @code{xinitr })
9885Script to run before starting a X session.
9886
9887@item @code{xsessions-directory} (default: "/run/current-system/profile/share/xsessions")
9888Directory to look for desktop files starting X sessions.
9889
9890@item @code{minimum-vt} (default: 7)
9891Minimum VT to use.
9892
9893@item @code{xserver-arguments} (default "-nolisten tcp")
9894Arguments to pass to xorg-server.
9895
9896@item @code{auto-login-user} (default "")
9897User to use for auto-login.
9898
9899@item @code{auto-login-session} (default "")
9900Desktop file to use for auto-login.
9901
9902@item @code{relogin?} (default #f)
9903Relogin after logout.
9904
9905@end table
9906@end deftp
9907
e32171ee 9908@cindex login manager
935644c0
DC
9909@deffn {Scheme Procedure} sddm-service config
9910Return a service that spawns the SDDM graphical login manager for config of
9911type @code{<sddm-configuration>}.
9912
9913@example
9914 (sddm-service (sddm-configuration
9915 (auto-login-user "Alice")
9916 (auto-login-session "xfce.desktop")))
9917@end example
9918@end deffn
9919
be1c2c54 9920@deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
9921 [#:auto-login? #f] [#:default-user ""] [#:startx] @
9922 [#:theme @var{%default-slim-theme}] @
4bd43bbe 9923 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
9924Return a service that spawns the SLiM graphical login manager, which in
9925turn starts the X display server with @var{startx}, a command as returned by
9926@code{xorg-start-command}.
4af2447e 9927
04e4e6ab
LC
9928@cindex X session
9929
9930SLiM automatically looks for session types described by the @file{.desktop}
9931files in @file{/run/current-system/profile/share/xsessions} and allows users
9932to choose a session from the log-in screen using @kbd{F1}. Packages such as
9933@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
9934adding them to the system-wide set of packages automatically makes them
9935available at the log-in screen.
9936
9937In addition, @file{~/.xsession} files are honored. When available,
9938@file{~/.xsession} must be an executable that starts a window manager
9939and/or other X clients.
9940
cf4a9129
LC
9941When @var{allow-empty-passwords?} is true, allow logins with an empty
9942password. When @var{auto-login?} is true, log in automatically as
9943@var{default-user}.
0ecc3bf3 9944
1068f26b 9945If @var{theme} is @code{#f}, use the default log-in theme; otherwise
0ecc3bf3
LC
9946@var{theme} must be a gexp denoting the name of a directory containing the
9947theme to use. In that case, @var{theme-name} specifies the name of the
9948theme.
cf4a9129 9949@end deffn
4af2447e 9950
0ecc3bf3
LC
9951@defvr {Scheme Variable} %default-theme
9952@defvrx {Scheme Variable} %default-theme-name
9953The G-Expression denoting the default SLiM theme and its name.
9954@end defvr
9955
be1c2c54 9956@deffn {Scheme Procedure} xorg-start-command [#:guile] @
d1cdd7ba 9957 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 9958Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
9959from @var{xorg-server}. @var{configuration-file} is the server configuration
9960file or a derivation that builds it; when omitted, the result of
9961@code{xorg-configuration-file} is used.
9962
9963Usually the X server is started by a login manager.
9964@end deffn
9965
be1c2c54 9966@deffn {Scheme Procedure} xorg-configuration-file @
12422c9d 9967 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
9968Return a configuration file for the Xorg server containing search paths for
9969all the common drivers.
f703413e
LC
9970
9971@var{drivers} must be either the empty list, in which case Xorg chooses a
9972graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 9973this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
9974
9975Likewise, when @var{resolutions} is the empty list, Xorg chooses an
9976appropriate screen resolution; otherwise, it must be a list of
9977resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
9978
9979Last, @var{extra-config} is a list of strings or objects appended to the
9980@code{text-file*} argument list. It is used to pass extra text to be added
9981verbatim to the configuration file.
f703413e 9982@end deffn
4af2447e 9983
6726282b
LC
9984@deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
9985Add @var{package}, a package for a screen-locker or screen-saver whose
9986command is @var{program}, to the set of setuid programs and add a PAM entry
9987for it. For example:
9988
9989@lisp
9990(screen-locker-service xlockmore "xlock")
9991@end lisp
9992
9993makes the good ol' XlockMore usable.
9994@end deffn
9995
9996
f2ec23d1
AW
9997@node Printing Services
9998@subsubsection Printing Services
9999
de322a5d 10000@cindex printer support with CUPS
f2ec23d1
AW
10001The @code{(gnu services cups)} module provides a Guix service definition
10002for the CUPS printing service. To add printer support to a GuixSD
10003system, add a @code{cups-service} to the operating system definition:
10004
10005@deffn {Scheme Variable} cups-service-type
10006The service type for the CUPS print server. Its value should be a valid
10007CUPS configuration (see below). For example:
10008@example
10009(service cups-service-type (cups-configuration))
10010@end example
10011@end deffn
10012
10013The CUPS configuration controls the basic things about your CUPS
10014installation: what interfaces it listens on, what to do if a print job
10015fails, how much logging to do, and so on. To actually add a printer,
10016you have to visit the @url{http://localhost:631} URL, or use a tool such
10017as GNOME's printer configuration services. By default, configuring a
10018CUPS service will generate a self-signed certificate if needed, for
10019secure connections to the print server.
10020
de322a5d
LC
10021Suppose you want to enable the Web interface of CUPS and also add
10022support for HP printers @i{via} the @code{hplip} package. You can do
10023that directly, like this (you need to use the @code{(gnu packages cups)}
10024module):
f2ec23d1
AW
10025
10026@example
10027(service cups-service-type
10028 (cups-configuration
de322a5d
LC
10029 (web-interface? #t)
10030 (extensions
10031 (list cups-filters hplip))))
f2ec23d1
AW
10032@end example
10033
10034The available configuration parameters follow. Each parameter
10035definition is preceded by its type; for example, @samp{string-list foo}
10036indicates that the @code{foo} parameter should be specified as a list of
10037strings. There is also a way to specify the configuration as a string,
10038if you have an old @code{cupsd.conf} file that you want to port over
10039from some other system; see the end for more details.
10040
10041@c The following documentation was initially generated by
10042@c (generate-documentation) in (gnu services cups). Manually maintained
10043@c documentation is better, so we shouldn't hesitate to edit below as
10044@c needed. However if the change you want to make to this documentation
10045@c can be done in an automated way, it's probably easier to change
10046@c (generate-documentation) than to make it below and have to deal with
10047@c the churn as CUPS updates.
10048
10049
10050Available @code{cups-configuration} fields are:
10051
10052@deftypevr {@code{cups-configuration} parameter} package cups
10053The CUPS package.
10054@end deftypevr
10055
10056@deftypevr {@code{cups-configuration} parameter} package-list extensions
10057Drivers and other extensions to the CUPS package.
10058@end deftypevr
10059
10060@deftypevr {@code{cups-configuration} parameter} files-configuration files-configuration
10061Configuration of where to write logs, what directories to use for print
10062spools, and related privileged configuration parameters.
10063
10064Available @code{files-configuration} fields are:
10065
10066@deftypevr {@code{files-configuration} parameter} log-location access-log
10067Defines the access log filename. Specifying a blank filename disables
10068access log generation. The value @code{stderr} causes log entries to be
10069sent to the standard error file when the scheduler is running in the
10070foreground, or to the system log daemon when run in the background. The
10071value @code{syslog} causes log entries to be sent to the system log
10072daemon. The server name may be included in filenames using the string
10073@code{%s}, as in @code{/var/log/cups/%s-access_log}.
10074
10075Defaults to @samp{"/var/log/cups/access_log"}.
10076@end deftypevr
10077
10078@deftypevr {@code{files-configuration} parameter} file-name cache-dir
10079Where CUPS should cache data.
10080
10081Defaults to @samp{"/var/cache/cups"}.
10082@end deftypevr
10083
10084@deftypevr {@code{files-configuration} parameter} string config-file-perm
10085Specifies the permissions for all configuration files that the scheduler
10086writes.
10087
10088Note that the permissions for the printers.conf file are currently
10089masked to only allow access from the scheduler user (typically root).
10090This is done because printer device URIs sometimes contain sensitive
10091authentication information that should not be generally known on the
10092system. There is no way to disable this security feature.
10093
10094Defaults to @samp{"0640"}.
10095@end deftypevr
10096
10097@deftypevr {@code{files-configuration} parameter} log-location error-log
10098Defines the error log filename. Specifying a blank filename disables
10099access log generation. The value @code{stderr} causes log entries to be
10100sent to the standard error file when the scheduler is running in the
10101foreground, or to the system log daemon when run in the background. The
10102value @code{syslog} causes log entries to be sent to the system log
10103daemon. The server name may be included in filenames using the string
10104@code{%s}, as in @code{/var/log/cups/%s-error_log}.
10105
10106Defaults to @samp{"/var/log/cups/error_log"}.
10107@end deftypevr
10108
10109@deftypevr {@code{files-configuration} parameter} string fatal-errors
10110Specifies which errors are fatal, causing the scheduler to exit. The
10111kind strings are:
10112
10113@table @code
10114@item none
10115No errors are fatal.
10116
10117@item all
10118All of the errors below are fatal.
10119
10120@item browse
10121Browsing initialization errors are fatal, for example failed connections
10122to the DNS-SD daemon.
10123
10124@item config
10125Configuration file syntax errors are fatal.
10126
10127@item listen
10128Listen or Port errors are fatal, except for IPv6 failures on the
10129loopback or @code{any} addresses.
10130
10131@item log
10132Log file creation or write errors are fatal.
10133
10134@item permissions
10135Bad startup file permissions are fatal, for example shared TLS
10136certificate and key files with world-read permissions.
10137@end table
10138
10139Defaults to @samp{"all -browse"}.
10140@end deftypevr
10141
10142@deftypevr {@code{files-configuration} parameter} boolean file-device?
10143Specifies whether the file pseudo-device can be used for new printer
10144queues. The URI @uref{file:///dev/null} is always allowed.
10145
10146Defaults to @samp{#f}.
10147@end deftypevr
10148
10149@deftypevr {@code{files-configuration} parameter} string group
10150Specifies the group name or ID that will be used when executing external
10151programs.
10152
10153Defaults to @samp{"lp"}.
10154@end deftypevr
10155
10156@deftypevr {@code{files-configuration} parameter} string log-file-perm
10157Specifies the permissions for all log files that the scheduler writes.
10158
10159Defaults to @samp{"0644"}.
10160@end deftypevr
10161
10162@deftypevr {@code{files-configuration} parameter} log-location page-log
10163Defines the page log filename. Specifying a blank filename disables
10164access log generation. The value @code{stderr} causes log entries to be
10165sent to the standard error file when the scheduler is running in the
10166foreground, or to the system log daemon when run in the background. The
10167value @code{syslog} causes log entries to be sent to the system log
10168daemon. The server name may be included in filenames using the string
10169@code{%s}, as in @code{/var/log/cups/%s-page_log}.
10170
10171Defaults to @samp{"/var/log/cups/page_log"}.
10172@end deftypevr
10173
10174@deftypevr {@code{files-configuration} parameter} string remote-root
10175Specifies the username that is associated with unauthenticated accesses
10176by clients claiming to be the root user. The default is @code{remroot}.
10177
10178Defaults to @samp{"remroot"}.
10179@end deftypevr
10180
10181@deftypevr {@code{files-configuration} parameter} file-name request-root
10182Specifies the directory that contains print jobs and other HTTP request
10183data.
10184
10185Defaults to @samp{"/var/spool/cups"}.
10186@end deftypevr
10187
10188@deftypevr {@code{files-configuration} parameter} sandboxing sandboxing
10189Specifies the level of security sandboxing that is applied to print
10190filters, backends, and other child processes of the scheduler; either
10191@code{relaxed} or @code{strict}. This directive is currently only
10192used/supported on macOS.
10193
10194Defaults to @samp{strict}.
10195@end deftypevr
10196
10197@deftypevr {@code{files-configuration} parameter} file-name server-keychain
10198Specifies the location of TLS certificates and private keys. CUPS will
10199look for public and private keys in this directory: a @code{.crt} files
10200for PEM-encoded certificates and corresponding @code{.key} files for
10201PEM-encoded private keys.
10202
10203Defaults to @samp{"/etc/cups/ssl"}.
10204@end deftypevr
10205
10206@deftypevr {@code{files-configuration} parameter} file-name server-root
10207Specifies the directory containing the server configuration files.
10208
10209Defaults to @samp{"/etc/cups"}.
10210@end deftypevr
10211
10212@deftypevr {@code{files-configuration} parameter} boolean sync-on-close?
10213Specifies whether the scheduler calls fsync(2) after writing
10214configuration or state files.
10215
10216Defaults to @samp{#f}.
10217@end deftypevr
10218
10219@deftypevr {@code{files-configuration} parameter} space-separated-string-list system-group
10220Specifies the group(s) to use for @code{@@SYSTEM} group authentication.
10221@end deftypevr
10222
10223@deftypevr {@code{files-configuration} parameter} file-name temp-dir
10224Specifies the directory where temporary files are stored.
10225
10226Defaults to @samp{"/var/spool/cups/tmp"}.
10227@end deftypevr
10228
10229@deftypevr {@code{files-configuration} parameter} string user
10230Specifies the user name or ID that is used when running external
10231programs.
10232
10233Defaults to @samp{"lp"}.
10234@end deftypevr
10235@end deftypevr
10236
10237@deftypevr {@code{cups-configuration} parameter} access-log-level access-log-level
10238Specifies the logging level for the AccessLog file. The @code{config}
10239level logs when printers and classes are added, deleted, or modified and
10240when configuration files are accessed or updated. The @code{actions}
10241level logs when print jobs are submitted, held, released, modified, or
10242canceled, and any of the conditions for @code{config}. The @code{all}
10243level logs all requests.
10244
10245Defaults to @samp{actions}.
10246@end deftypevr
10247
10248@deftypevr {@code{cups-configuration} parameter} boolean auto-purge-jobs?
10249Specifies whether to purge job history data automatically when it is no
10250longer required for quotas.
10251
10252Defaults to @samp{#f}.
10253@end deftypevr
10254
10255@deftypevr {@code{cups-configuration} parameter} browse-local-protocols browse-local-protocols
10256Specifies which protocols to use for local printer sharing.
10257
10258Defaults to @samp{dnssd}.
10259@end deftypevr
10260
10261@deftypevr {@code{cups-configuration} parameter} boolean browse-web-if?
10262Specifies whether the CUPS web interface is advertised.
10263
10264Defaults to @samp{#f}.
10265@end deftypevr
10266
10267@deftypevr {@code{cups-configuration} parameter} boolean browsing?
10268Specifies whether shared printers are advertised.
10269
10270Defaults to @samp{#f}.
10271@end deftypevr
10272
10273@deftypevr {@code{cups-configuration} parameter} string classification
10274Specifies the security classification of the server. Any valid banner
10275name can be used, including "classified", "confidential", "secret",
10276"topsecret", and "unclassified", or the banner can be omitted to disable
10277secure printing functions.
10278
10279Defaults to @samp{""}.
10280@end deftypevr
10281
10282@deftypevr {@code{cups-configuration} parameter} boolean classify-override?
10283Specifies whether users may override the classification (cover page) of
10284individual print jobs using the @code{job-sheets} option.
10285
10286Defaults to @samp{#f}.
10287@end deftypevr
10288
10289@deftypevr {@code{cups-configuration} parameter} default-auth-type default-auth-type
10290Specifies the default type of authentication to use.
10291
10292Defaults to @samp{Basic}.
10293@end deftypevr
10294
10295@deftypevr {@code{cups-configuration} parameter} default-encryption default-encryption
10296Specifies whether encryption will be used for authenticated requests.
10297
10298Defaults to @samp{Required}.
10299@end deftypevr
10300
10301@deftypevr {@code{cups-configuration} parameter} string default-language
10302Specifies the default language to use for text and web content.
10303
10304Defaults to @samp{"en"}.
10305@end deftypevr
10306
10307@deftypevr {@code{cups-configuration} parameter} string default-paper-size
10308Specifies the default paper size for new print queues. @samp{"Auto"}
10309uses a locale-specific default, while @samp{"None"} specifies there is
10310no default paper size. Specific size names are typically
10311@samp{"Letter"} or @samp{"A4"}.
10312
10313Defaults to @samp{"Auto"}.
10314@end deftypevr
10315
10316@deftypevr {@code{cups-configuration} parameter} string default-policy
10317Specifies the default access policy to use.
10318
10319Defaults to @samp{"default"}.
10320@end deftypevr
10321
10322@deftypevr {@code{cups-configuration} parameter} boolean default-shared?
10323Specifies whether local printers are shared by default.
10324
10325Defaults to @samp{#t}.
10326@end deftypevr
10327
10328@deftypevr {@code{cups-configuration} parameter} non-negative-integer dirty-clean-interval
10329Specifies the delay for updating of configuration and state files, in
10330seconds. A value of 0 causes the update to happen as soon as possible,
10331typically within a few milliseconds.
10332
10333Defaults to @samp{30}.
10334@end deftypevr
10335
10336@deftypevr {@code{cups-configuration} parameter} error-policy error-policy
10337Specifies what to do when an error occurs. Possible values are
10338@code{abort-job}, which will discard the failed print job;
10339@code{retry-job}, which will retry the job at a later time;
10340@code{retry-this-job}, which retries the failed job immediately; and
10341@code{stop-printer}, which stops the printer.
10342
10343Defaults to @samp{stop-printer}.
10344@end deftypevr
10345
10346@deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-limit
10347Specifies the maximum cost of filters that are run concurrently, which
10348can be used to minimize disk, memory, and CPU resource problems. A
10349limit of 0 disables filter limiting. An average print to a
10350non-PostScript printer needs a filter limit of about 200. A PostScript
10351printer needs about half that (100). Setting the limit below these
10352thresholds will effectively limit the scheduler to printing a single job
10353at any time.
10354
10355Defaults to @samp{0}.
10356@end deftypevr
10357
10358@deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-nice
10359Specifies the scheduling priority of filters that are run to print a
10360job. The nice value ranges from 0, the highest priority, to 19, the
10361lowest priority.
10362
10363Defaults to @samp{0}.
10364@end deftypevr
10365
10366@deftypevr {@code{cups-configuration} parameter} host-name-lookups host-name-lookups
10367Specifies whether to do reverse lookups on connecting clients. The
10368@code{double} setting causes @code{cupsd} to verify that the hostname
10369resolved from the address matches one of the addresses returned for that
10370hostname. Double lookups also prevent clients with unregistered
10371addresses from connecting to your server. Only set this option to
10372@code{#t} or @code{double} if absolutely required.
10373
10374Defaults to @samp{#f}.
10375@end deftypevr
10376
10377@deftypevr {@code{cups-configuration} parameter} non-negative-integer job-kill-delay
10378Specifies the number of seconds to wait before killing the filters and
10379backend associated with a canceled or held job.
10380
10381Defaults to @samp{30}.
10382@end deftypevr
10383
10384@deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-interval
10385Specifies the interval between retries of jobs in seconds. This is
10386typically used for fax queues but can also be used with normal print
10387queues whose error policy is @code{retry-job} or
10388@code{retry-current-job}.
10389
10390Defaults to @samp{30}.
10391@end deftypevr
10392
10393@deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-limit
10394Specifies the number of retries that are done for jobs. This is
10395typically used for fax queues but can also be used with normal print
10396queues whose error policy is @code{retry-job} or
10397@code{retry-current-job}.
10398
10399Defaults to @samp{5}.
10400@end deftypevr
10401
10402@deftypevr {@code{cups-configuration} parameter} boolean keep-alive?
10403Specifies whether to support HTTP keep-alive connections.
10404
10405Defaults to @samp{#t}.
10406@end deftypevr
10407
10408@deftypevr {@code{cups-configuration} parameter} non-negative-integer keep-alive-timeout
10409Specifies how long an idle client connection remains open, in seconds.
10410
10411Defaults to @samp{30}.
10412@end deftypevr
10413
10414@deftypevr {@code{cups-configuration} parameter} non-negative-integer limit-request-body
10415Specifies the maximum size of print files, IPP requests, and HTML form
10416data. A limit of 0 disables the limit check.
10417
10418Defaults to @samp{0}.
10419@end deftypevr
10420
10421@deftypevr {@code{cups-configuration} parameter} multiline-string-list listen
10422Listens on the specified interfaces for connections. Valid values are
10423of the form @var{address}:@var{port}, where @var{address} is either an
10424IPv6 address enclosed in brackets, an IPv4 address, or @code{*} to
10425indicate all addresses. Values can also be file names of local UNIX
10426domain sockets. The Listen directive is similar to the Port directive
10427but allows you to restrict access to specific interfaces or networks.
10428@end deftypevr
10429
10430@deftypevr {@code{cups-configuration} parameter} non-negative-integer listen-back-log
10431Specifies the number of pending connections that will be allowed. This
10432normally only affects very busy servers that have reached the MaxClients
10433limit, but can also be triggered by large numbers of simultaneous
10434connections. When the limit is reached, the operating system will
10435refuse additional connections until the scheduler can accept the pending
10436ones.
10437
10438Defaults to @samp{128}.
10439@end deftypevr
10440
10441@deftypevr {@code{cups-configuration} parameter} location-access-control-list location-access-controls
10442Specifies a set of additional access controls.
10443
10444Available @code{location-access-controls} fields are:
10445
10446@deftypevr {@code{location-access-controls} parameter} file-name path
10447Specifies the URI path to which the access control applies.
10448@end deftypevr
10449
10450@deftypevr {@code{location-access-controls} parameter} access-control-list access-controls
10451Access controls for all access to this path, in the same format as the
10452@code{access-controls} of @code{operation-access-control}.
10453
10454Defaults to @samp{()}.
10455@end deftypevr
10456
10457@deftypevr {@code{location-access-controls} parameter} method-access-control-list method-access-controls
10458Access controls for method-specific access to this path.
10459
10460Defaults to @samp{()}.
10461
10462Available @code{method-access-controls} fields are:
10463
10464@deftypevr {@code{method-access-controls} parameter} boolean reverse?
10465If @code{#t}, apply access controls to all methods except the listed
10466methods. Otherwise apply to only the listed methods.
10467
10468Defaults to @samp{#f}.
10469@end deftypevr
10470
10471@deftypevr {@code{method-access-controls} parameter} method-list methods
10472Methods to which this access control applies.
10473
10474Defaults to @samp{()}.
10475@end deftypevr
10476
10477@deftypevr {@code{method-access-controls} parameter} access-control-list access-controls
10478Access control directives, as a list of strings. Each string should be
10479one directive, such as "Order allow,deny".
10480
10481Defaults to @samp{()}.
10482@end deftypevr
10483@end deftypevr
10484@end deftypevr
10485
10486@deftypevr {@code{cups-configuration} parameter} non-negative-integer log-debug-history
10487Specifies the number of debugging messages that are retained for logging
10488if an error occurs in a print job. Debug messages are logged regardless
10489of the LogLevel setting.
10490
10491Defaults to @samp{100}.
10492@end deftypevr
10493
10494@deftypevr {@code{cups-configuration} parameter} log-level log-level
10495Specifies the level of logging for the ErrorLog file. The value
10496@code{none} stops all logging while @code{debug2} logs everything.
10497
10498Defaults to @samp{info}.
10499@end deftypevr
10500
10501@deftypevr {@code{cups-configuration} parameter} log-time-format log-time-format
10502Specifies the format of the date and time in the log files. The value
10503@code{standard} logs whole seconds while @code{usecs} logs microseconds.
10504
10505Defaults to @samp{standard}.
10506@end deftypevr
10507
10508@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients
10509Specifies the maximum number of simultaneous clients that are allowed by
10510the scheduler.
10511
10512Defaults to @samp{100}.
10513@end deftypevr
10514
10515@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients-per-host
10516Specifies the maximum number of simultaneous clients that are allowed
10517from a single address.
10518
10519Defaults to @samp{100}.
10520@end deftypevr
10521
10522@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-copies
10523Specifies the maximum number of copies that a user can print of each
10524job.
10525
10526Defaults to @samp{9999}.
10527@end deftypevr
10528
10529@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-hold-time
10530Specifies the maximum time a job may remain in the @code{indefinite}
10531hold state before it is canceled. A value of 0 disables cancellation of
10532held jobs.
10533
10534Defaults to @samp{0}.
10535@end deftypevr
10536
10537@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs
10538Specifies the maximum number of simultaneous jobs that are allowed. Set
10539to 0 to allow an unlimited number of jobs.
10540
10541Defaults to @samp{500}.
10542@end deftypevr
10543
10544@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-printer
10545Specifies the maximum number of simultaneous jobs that are allowed per
10546printer. A value of 0 allows up to MaxJobs jobs per printer.
10547
10548Defaults to @samp{0}.
10549@end deftypevr
10550
10551@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-user
10552Specifies the maximum number of simultaneous jobs that are allowed per
10553user. A value of 0 allows up to MaxJobs jobs per user.
10554
10555Defaults to @samp{0}.
10556@end deftypevr
10557
10558@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-job-time
10559Specifies the maximum time a job may take to print before it is
10560canceled, in seconds. Set to 0 to disable cancellation of "stuck" jobs.
10561
10562Defaults to @samp{10800}.
10563@end deftypevr
10564
10565@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-log-size
10566Specifies the maximum size of the log files before they are rotated, in
10567bytes. The value 0 disables log rotation.
10568
10569Defaults to @samp{1048576}.
10570@end deftypevr
10571
10572@deftypevr {@code{cups-configuration} parameter} non-negative-integer multiple-operation-timeout
10573Specifies the maximum amount of time to allow between files in a
10574multiple file print job, in seconds.
10575
10576Defaults to @samp{300}.
10577@end deftypevr
10578
10579@deftypevr {@code{cups-configuration} parameter} string page-log-format
10580Specifies the format of PageLog lines. Sequences beginning with percent
10581(@samp{%}) characters are replaced with the corresponding information,
10582while all other characters are copied literally. The following percent
10583sequences are recognized:
10584
10585@table @samp
10586@item %%
10587insert a single percent character
10588
10589@item %@{name@}
10590insert the value of the specified IPP attribute
10591
10592@item %C
10593insert the number of copies for the current page
10594
10595@item %P
10596insert the current page number
10597
10598@item %T
10599insert the current date and time in common log format
10600
10601@item %j
10602insert the job ID
10603
10604@item %p
10605insert the printer name
10606
10607@item %u
10608insert the username
10609@end table
10610
10611A value of the empty string disables page logging. The string @code{%p
10612%u %j %T %P %C %@{job-billing@} %@{job-originating-host-name@}
10613%@{job-name@} %@{media@} %@{sides@}} creates a page log with the
10614standard items.
10615
10616Defaults to @samp{""}.
10617@end deftypevr
10618
10619@deftypevr {@code{cups-configuration} parameter} environment-variables environment-variables
10620Passes the specified environment variable(s) to child processes; a list
10621of strings.
10622
10623Defaults to @samp{()}.
10624@end deftypevr
10625
10626@deftypevr {@code{cups-configuration} parameter} policy-configuration-list policies
10627Specifies named access control policies.
10628
10629Available @code{policy-configuration} fields are:
10630
10631@deftypevr {@code{policy-configuration} parameter} string name
10632Name of the policy.
10633@end deftypevr
10634
10635@deftypevr {@code{policy-configuration} parameter} string job-private-access
10636Specifies an access list for a job's private values. @code{@@ACL} maps
10637to the printer's requesting-user-name-allowed or
10638requesting-user-name-denied values. @code{@@OWNER} maps to the job's
10639owner. @code{@@SYSTEM} maps to the groups listed for the
10640@code{system-group} field of the @code{files-config} configuration,
10641which is reified into the @code{cups-files.conf(5)} file. Other
10642possible elements of the access list include specific user names, and
10643@code{@@@var{group}} to indicate members of a specific group. The
10644access list may also be simply @code{all} or @code{default}.
10645
10646Defaults to @samp{"@@OWNER @@SYSTEM"}.
10647@end deftypevr
10648
10649@deftypevr {@code{policy-configuration} parameter} string job-private-values
10650Specifies the list of job values to make private, or @code{all},
10651@code{default}, or @code{none}.
10652
10653Defaults to @samp{"job-name job-originating-host-name
10654job-originating-user-name phone"}.
10655@end deftypevr
10656
10657@deftypevr {@code{policy-configuration} parameter} string subscription-private-access
10658Specifies an access list for a subscription's private values.
10659@code{@@ACL} maps to the printer's requesting-user-name-allowed or
10660requesting-user-name-denied values. @code{@@OWNER} maps to the job's
10661owner. @code{@@SYSTEM} maps to the groups listed for the
10662@code{system-group} field of the @code{files-config} configuration,
10663which is reified into the @code{cups-files.conf(5)} file. Other
10664possible elements of the access list include specific user names, and
10665@code{@@@var{group}} to indicate members of a specific group. The
10666access list may also be simply @code{all} or @code{default}.
10667
10668Defaults to @samp{"@@OWNER @@SYSTEM"}.
10669@end deftypevr
10670
10671@deftypevr {@code{policy-configuration} parameter} string subscription-private-values
10672Specifies the list of job values to make private, or @code{all},
10673@code{default}, or @code{none}.
10674
10675Defaults to @samp{"notify-events notify-pull-method notify-recipient-uri
10676notify-subscriber-user-name notify-user-data"}.
10677@end deftypevr
10678
10679@deftypevr {@code{policy-configuration} parameter} operation-access-control-list access-controls
10680Access control by IPP operation.
10681
10682Defaults to @samp{()}.
10683@end deftypevr
10684@end deftypevr
10685
10686@deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-files
10687Specifies whether job files (documents) are preserved after a job is
10688printed. If a numeric value is specified, job files are preserved for
10689the indicated number of seconds after printing. Otherwise a boolean
10690value applies indefinitely.
10691
10692Defaults to @samp{86400}.
10693@end deftypevr
10694
10695@deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-history
10696Specifies whether the job history is preserved after a job is printed.
10697If a numeric value is specified, the job history is preserved for the
10698indicated number of seconds after printing. If @code{#t}, the job
10699history is preserved until the MaxJobs limit is reached.
10700
10701Defaults to @samp{#t}.
10702@end deftypevr
10703
10704@deftypevr {@code{cups-configuration} parameter} non-negative-integer reload-timeout
10705Specifies the amount of time to wait for job completion before
10706restarting the scheduler.
10707
10708Defaults to @samp{30}.
10709@end deftypevr
10710
10711@deftypevr {@code{cups-configuration} parameter} string rip-cache
10712Specifies the maximum amount of memory to use when converting documents
10713into bitmaps for a printer.
10714
10715Defaults to @samp{"128m"}.
10716@end deftypevr
10717
10718@deftypevr {@code{cups-configuration} parameter} string server-admin
10719Specifies the email address of the server administrator.
10720
10721Defaults to @samp{"root@@localhost.localdomain"}.
10722@end deftypevr
10723
10724@deftypevr {@code{cups-configuration} parameter} host-name-list-or-* server-alias
10725The ServerAlias directive is used for HTTP Host header validation when
10726clients connect to the scheduler from external interfaces. Using the
10727special name @code{*} can expose your system to known browser-based DNS
10728rebinding attacks, even when accessing sites through a firewall. If the
10729auto-discovery of alternate names does not work, we recommend listing
10730each alternate name with a ServerAlias directive instead of using
10731@code{*}.
10732
10733Defaults to @samp{*}.
10734@end deftypevr
10735
10736@deftypevr {@code{cups-configuration} parameter} string server-name
10737Specifies the fully-qualified host name of the server.
10738
10739Defaults to @samp{"localhost"}.
10740@end deftypevr
10741
10742@deftypevr {@code{cups-configuration} parameter} server-tokens server-tokens
10743Specifies what information is included in the Server header of HTTP
10744responses. @code{None} disables the Server header. @code{ProductOnly}
10745reports @code{CUPS}. @code{Major} reports @code{CUPS 2}. @code{Minor}
10746reports @code{CUPS 2.0}. @code{Minimal} reports @code{CUPS 2.0.0}.
10747@code{OS} reports @code{CUPS 2.0.0 (@var{uname})} where @var{uname} is
10748the output of the @code{uname} command. @code{Full} reports @code{CUPS
107492.0.0 (@var{uname}) IPP/2.0}.
10750
10751Defaults to @samp{Minimal}.
10752@end deftypevr
10753
10754@deftypevr {@code{cups-configuration} parameter} string set-env
10755Set the specified environment variable to be passed to child processes.
10756
10757Defaults to @samp{"variable value"}.
10758@end deftypevr
10759
10760@deftypevr {@code{cups-configuration} parameter} multiline-string-list ssl-listen
10761Listens on the specified interfaces for encrypted connections. Valid
10762values are of the form @var{address}:@var{port}, where @var{address} is
10763either an IPv6 address enclosed in brackets, an IPv4 address, or
10764@code{*} to indicate all addresses.
10765
10766Defaults to @samp{()}.
10767@end deftypevr
10768
10769@deftypevr {@code{cups-configuration} parameter} ssl-options ssl-options
10770Sets encryption options. By default, CUPS only supports encryption
10771using TLS v1.0 or higher using known secure cipher suites. The
10772@code{AllowRC4} option enables the 128-bit RC4 cipher suites, which are
10773required for some older clients that do not implement newer ones. The
10774@code{AllowSSL3} option enables SSL v3.0, which is required for some
10775older clients that do not support TLS v1.0.
10776
10777Defaults to @samp{()}.
10778@end deftypevr
10779
10780@deftypevr {@code{cups-configuration} parameter} boolean strict-conformance?
10781Specifies whether the scheduler requires clients to strictly adhere to
10782the IPP specifications.
10783
10784Defaults to @samp{#f}.
10785@end deftypevr
10786
10787@deftypevr {@code{cups-configuration} parameter} non-negative-integer timeout
10788Specifies the HTTP request timeout, in seconds.
10789
10790Defaults to @samp{300}.
10791
10792@end deftypevr
10793
10794@deftypevr {@code{cups-configuration} parameter} boolean web-interface?
10795Specifies whether the web interface is enabled.
10796
10797Defaults to @samp{#f}.
10798@end deftypevr
10799
10800At this point you're probably thinking ``oh dear, Guix manual, I like
10801you but you can stop already with the configuration options''. Indeed.
10802However, one more point: it could be that you have an existing
10803@code{cupsd.conf} that you want to use. In that case, you can pass an
10804@code{opaque-cups-configuration} as the configuration of a
10805@code{cups-service-type}.
10806
10807Available @code{opaque-cups-configuration} fields are:
10808
10809@deftypevr {@code{opaque-cups-configuration} parameter} package cups
10810The CUPS package.
10811@end deftypevr
10812
10813@deftypevr {@code{opaque-cups-configuration} parameter} string cupsd.conf
10814The contents of the @code{cupsd.conf}, as a string.
10815@end deftypevr
10816
10817@deftypevr {@code{opaque-cups-configuration} parameter} string cups-files.conf
10818The contents of the @code{cups-files.conf} file, as a string.
10819@end deftypevr
10820
10821For example, if your @code{cupsd.conf} and @code{cups-files.conf} are in
10822strings of the same name, you could instantiate a CUPS service like
10823this:
10824
10825@example
10826(service cups-service-type
10827 (opaque-cups-configuration
10828 (cupsd.conf cupsd.conf)
10829 (cups-files.conf cups-files.conf)))
10830@end example
10831
10832
fe1a39d3
LC
10833@node Desktop Services
10834@subsubsection Desktop Services
aa4ed923 10835
fe1a39d3
LC
10836The @code{(gnu services desktop)} module provides services that are
10837usually useful in the context of a ``desktop'' setup---that is, on a
10838machine running a graphical display server, possibly with graphical user
7a2413e4
AW
10839interfaces, etc. It also defines services that provide specific desktop
10840environments like GNOME and XFCE.
aa4ed923 10841
4467be21
LC
10842To simplify things, the module defines a variable containing the set of
10843services that users typically expect on a machine with a graphical
10844environment and networking:
10845
10846@defvr {Scheme Variable} %desktop-services
10847This is a list of services that builds upon @var{%base-services} and
1068f26b 10848adds or adjusts services for a typical ``desktop'' setup.
4467be21
LC
10849
10850In particular, it adds a graphical login manager (@pxref{X Window,
6726282b
LC
10851@code{slim-service}}), screen lockers,
10852a network management tool (@pxref{Networking
4467be21 10853Services, @code{wicd-service}}), energy and color management services,
4650a77e 10854the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
10855the GeoClue location service, an NTP client (@pxref{Networking
10856Services}), the Avahi daemon, and has the name service switch service
10857configured to be able to use @code{nss-mdns} (@pxref{Name Service
10858Switch, mDNS}).
4467be21
LC
10859@end defvr
10860
10861The @var{%desktop-services} variable can be used as the @code{services}
10862field of an @code{operating-system} declaration (@pxref{operating-system
10863Reference, @code{services}}).
10864
7a2413e4
AW
10865Additionally, the @code{gnome-desktop-service} and
10866@code{xfce-desktop-service} procedures can add GNOME and/or XFCE to a
10867system. To ``add GNOME'' means that system-level services like the
10868backlight adjustment helpers and the power management utilities are
10869added to the system, extending @code{polkit} and @code{dbus}
10870appropriately, allowing GNOME to operate with elevated privileges on a
10871limited number of special-purpose system interfaces. Additionally,
10872adding a service made by @code{gnome-desktop-service} adds the GNOME
10873metapackage to the system profile. Likewise, adding the XFCE service
10874not only adds the @code{xfce} metapackage to the system profile, but it
10875also gives the Thunar file manager the ability to open a ``root-mode''
10876file management window, if the user authenticates using the
10877administrator's password via the standard polkit graphical interface.
10878
10879@deffn {Scheme Procedure} gnome-desktop-service
10880Return a service that adds the @code{gnome} package to the system
10881profile, and extends polkit with the actions from
10882@code{gnome-settings-daemon}.
10883@end deffn
10884
10885@deffn {Scheme Procedure} xfce-desktop-service
10886Return a service that adds the @code{xfce} package to the system profile,
5741e3e5 10887and extends polkit with the ability for @code{thunar} to manipulate the
7a2413e4
AW
10888file system as root from within a user session, after the user has
10889authenticated with the administrator's password.
10890@end deffn
10891
10892Because the GNOME and XFCE desktop services pull in so many packages,
10893the default @code{%desktop-services} variable doesn't include either of
10894them by default. To add GNOME or XFCE, just @code{cons} them onto
10895@code{%desktop-services} in the @code{services} field of your
10896@code{operating-system}:
10897
10898@example
10899(use-modules (gnu))
10900(use-service-modules desktop)
10901(operating-system
10902 ...
10903 ;; cons* adds items to the list given as its last argument.
10904 (services (cons* (gnome-desktop-service)
10905 (xfce-desktop-service)
10906 %desktop-services))
10907 ...)
10908@end example
10909
10910These desktop environments will then be available as options in the
10911graphical login window.
10912
10913The actual service definitions included in @code{%desktop-services} and
10914provided by @code{(gnu services dbus)} and @code{(gnu services desktop)}
10915are described below.
4467be21 10916
0adfe95a 10917@deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
fe1a39d3
LC
10918Return a service that runs the ``system bus'', using @var{dbus}, with
10919support for @var{services}.
aa4ed923 10920
fe1a39d3
LC
10921@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
10922facility. Its system bus is used to allow system services to communicate
1068f26b 10923and to be notified of system-wide events.
aa4ed923 10924
fe1a39d3
LC
10925@var{services} must be a list of packages that provide an
10926@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
10927and policy files. For example, to allow avahi-daemon to use the system bus,
10928@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
10929@end deffn
10930
0adfe95a 10931@deffn {Scheme Procedure} elogind-service [#:config @var{config}]
4650a77e
AW
10932Return a service that runs the @code{elogind} login and
10933seat management daemon. @uref{https://github.com/andywingo/elogind,
10934Elogind} exposes a D-Bus interface that can be used to know which users
10935are logged in, know what kind of sessions they have open, suspend the
10936system, inhibit system suspend, reboot the system, and other tasks.
10937
10938Elogind handles most system-level power events for a computer, for
10939example suspending the system when a lid is closed, or shutting it down
10940when the power button is pressed.
10941
10942The @var{config} keyword argument specifies the configuration for
1068f26b 10943elogind, and should be the result of an @code{(elogind-configuration
4650a77e
AW
10944(@var{parameter} @var{value})...)} invocation. Available parameters and
10945their default values are:
10946
10947@table @code
10948@item kill-user-processes?
10949@code{#f}
10950@item kill-only-users
10951@code{()}
10952@item kill-exclude-users
10953@code{("root")}
10954@item inhibit-delay-max-seconds
10955@code{5}
10956@item handle-power-key
10957@code{poweroff}
10958@item handle-suspend-key
10959@code{suspend}
10960@item handle-hibernate-key
10961@code{hibernate}
10962@item handle-lid-switch
10963@code{suspend}
10964@item handle-lid-switch-docked
10965@code{ignore}
10966@item power-key-ignore-inhibited?
10967@code{#f}
10968@item suspend-key-ignore-inhibited?
10969@code{#f}
10970@item hibernate-key-ignore-inhibited?
10971@code{#f}
10972@item lid-switch-ignore-inhibited?
10973@code{#t}
10974@item holdoff-timeout-seconds
10975@code{30}
10976@item idle-action
10977@code{ignore}
10978@item idle-action-seconds
10979@code{(* 30 60)}
10980@item runtime-directory-size-percent
10981@code{10}
10982@item runtime-directory-size
10983@code{#f}
10984@item remove-ipc?
10985@code{#t}
10986@item suspend-state
10987@code{("mem" "standby" "freeze")}
10988@item suspend-mode
10989@code{()}
10990@item hibernate-state
10991@code{("disk")}
10992@item hibernate-mode
10993@code{("platform" "shutdown")}
10994@item hybrid-sleep-state
10995@code{("disk")}
10996@item hybrid-sleep-mode
10997@code{("suspend" "platform" "shutdown")}
10998@end table
10999@end deffn
11000
be1c2c54 11001@deffn {Scheme Procedure} polkit-service @
4650a77e 11002 [#:polkit @var{polkit}]
222e3319
LC
11003Return a service that runs the
11004@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
11005management service}, which allows system administrators to grant access to
11006privileged operations in a structured way. By querying the Polkit service, a
11007privileged system component can know when it should grant additional
11008capabilities to ordinary users. For example, an ordinary user can be granted
11009the capability to suspend the system if the user is logged in locally.
4650a77e
AW
11010@end deffn
11011
be1c2c54 11012@deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
be234128
AW
11013 [#:watts-up-pro? #f] @
11014 [#:poll-batteries? #t] @
11015 [#:ignore-lid? #f] @
11016 [#:use-percentage-for-policy? #f] @
11017 [#:percentage-low 10] @
11018 [#:percentage-critical 3] @
11019 [#:percentage-action 2] @
11020 [#:time-low 1200] @
11021 [#:time-critical 300] @
11022 [#:time-action 120] @
11023 [#:critical-power-action 'hybrid-sleep]
11024Return a service that runs @uref{http://upower.freedesktop.org/,
11025@command{upowerd}}, a system-wide monitor for power consumption and battery
11026levels, with the given configuration settings. It implements the
11027@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
11028GNOME.
11029@end deffn
11030
2b9e0a94
LC
11031@deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
11032Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
11033UDisks}, a @dfn{disk management} daemon that provides user interfaces with
11034notifications and ways to mount/unmount disks. Programs that talk to UDisks
11035include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
11036@end deffn
11037
be1c2c54 11038@deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7ce597ff
AW
11039Return a service that runs @command{colord}, a system service with a D-Bus
11040interface to manage the color profiles of input and output devices such as
11041screens and scanners. It is notably used by the GNOME Color Manager graphical
11042tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
11043site} for more information.
11044@end deffn
11045
cee32ee4 11046@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
1068f26b 11047Return a configuration allowing an application to access GeoClue
cee32ee4
AW
11048location data. @var{name} is the Desktop ID of the application, without
11049the @code{.desktop} part. If @var{allowed?} is true, the application
11050will have access to location information by default. The boolean
1068f26b 11051@var{system?} value indicates whether an application is a system component
cee32ee4
AW
11052or not. Finally @var{users} is a list of UIDs of all users for which
11053this application is allowed location info access. An empty users list
11054means that all users are allowed.
11055@end deffn
11056
11057@defvr {Scheme Variable} %standard-geoclue-applications
11058The standard list of well-known GeoClue application configurations,
1068f26b
AE
11059granting authority to the GNOME date-and-time utility to ask for the
11060current location in order to set the time zone, and allowing the
11061IceCat and Epiphany web browsers to request location information.
11062IceCat and Epiphany both query the user before allowing a web page to
cee32ee4
AW
11063know the user's location.
11064@end defvr
11065
be1c2c54 11066@deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
cee32ee4
AW
11067 [#:whitelist '()] @
11068 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
11069 [#:submit-data? #f]
11070 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
11071 [#:submission-nick "geoclue"] @
11072 [#:applications %standard-geoclue-applications]
11073Return a service that runs the GeoClue location service. This service
11074provides a D-Bus interface to allow applications to request access to a
11075user's physical location, and optionally to add information to online
11076location databases. See
11077@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
11078web site} for more information.
11079@end deffn
11080
922e21f4
SB
11081@deffn {Scheme Procedure} bluetooth-service [#:bluez @var{bluez}]
11082Return a service that runs the @command{bluetoothd} daemon, which manages
11083all the Bluetooth devices and provides a number of D-Bus interfaces.
11084
11085Users need to be in the @code{lp} group to access the D-Bus service.
11086@end deffn
11087
105369a4
DT
11088@node Database Services
11089@subsubsection Database Services
11090
e32171ee
JD
11091@cindex database
11092@cindex SQL
6575183b 11093The @code{(gnu services databases)} module provides the following services.
105369a4 11094
be1c2c54 11095@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
2d3d5cc5 11096 [#:config-file] [#:data-directory ``/var/lib/postgresql/data''] @
e05b780a 11097 [#:port 5432] [#:locale ``en_US.utf8'']
105369a4
DT
11098Return a service that runs @var{postgresql}, the PostgreSQL database
11099server.
11100
e05b780a
CB
11101The PostgreSQL daemon loads its runtime configuration from @var{config-file},
11102creates a database cluster with @var{locale} as the default
11103locale, stored in @var{data-directory}. It then listens on @var{port}.
105369a4 11104@end deffn
fe1a39d3 11105
6575183b
SB
11106@deffn {Scheme Procedure} mysql-service [#:config (mysql-configuration)]
11107Return a service that runs @command{mysqld}, the MySQL or MariaDB
11108database server.
11109
11110The optional @var{config} argument specifies the configuration for
c940b8e6 11111@command{mysqld}, which should be a @code{<mysql-configuration>} object.
6575183b
SB
11112@end deffn
11113
11114@deftp {Data Type} mysql-configuration
11115Data type representing the configuration of @var{mysql-service}.
11116
11117@table @asis
11118@item @code{mysql} (default: @var{mariadb})
11119Package object of the MySQL database server, can be either @var{mariadb}
11120or @var{mysql}.
11121
7414de0a 11122For MySQL, a temporary root password will be displayed at activation time.
6575183b 11123For MariaDB, the root password is empty.
4b41febf
CB
11124
11125@item @code{port} (default: @code{3306})
11126TCP port on which the database server listens for incoming connections.
6575183b
SB
11127@end table
11128@end deftp
11129
67cadaca
CB
11130@defvr {Scheme Variable} redis-service-type
11131This is the service type for the @uref{https://redis.io/, Redis}
11132key/value store, whose value is a @code{redis-configuration} object.
11133@end defvr
11134
11135@deftp {Data Type} redis-configuration
11136Data type representing the configuration of redis.
11137
11138@table @asis
11139@item @code{redis} (default: @code{redis})
11140The Redis package to use.
11141
11142@item @code{bind} (default: @code{"127.0.0.1"})
11143Network interface on which to listen.
11144
11145@item @code{port} (default: @code{6379})
11146Port on which to accept connections on, a value of 0 will disable
9fc221b5 11147listening on a TCP socket.
67cadaca
CB
11148
11149@item @code{working-directory} (default: @code{"/var/lib/redis"})
11150Directory in which to store the database and related files.
11151@end table
11152@end deftp
11153
d8c18af8
AW
11154@node Mail Services
11155@subsubsection Mail Services
11156
e32171ee
JD
11157@cindex mail
11158@cindex email
d8c18af8 11159The @code{(gnu services mail)} module provides Guix service definitions
f88371e8
SB
11160for email services: IMAP, POP3, and LMTP servers, as well as mail
11161transport agents (MTAs). Lots of acronyms! These services are detailed
11162in the subsections below.
d8c18af8 11163
f88371e8 11164@subsubheading Dovecot Service
d8c18af8
AW
11165
11166@deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
11167Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
11168@end deffn
11169
1068f26b 11170By default, Dovecot does not need much configuration; the default
d8c18af8
AW
11171configuration object created by @code{(dovecot-configuration)} will
11172suffice if your mail is delivered to @code{~/Maildir}. A self-signed
11173certificate will be generated for TLS-protected connections, though
11174Dovecot will also listen on cleartext ports by default. There are a
1068f26b 11175number of options, though, which mail administrators might need to change,
d8c18af8
AW
11176and as is the case with other services, Guix allows the system
11177administrator to specify these parameters via a uniform Scheme interface.
11178
11179For example, to specify that mail is located at @code{maildir~/.mail},
11180one would instantiate the Dovecot service like this:
11181
11182@example
11183(dovecot-service #:config
11184 (dovecot-configuration
11185 (mail-location "maildir:~/.mail")))
11186@end example
11187
11188The available configuration parameters follow. Each parameter
11189definition is preceded by its type; for example, @samp{string-list foo}
11190indicates that the @code{foo} parameter should be specified as a list of
11191strings. There is also a way to specify the configuration as a string,
11192if you have an old @code{dovecot.conf} file that you want to port over
11193from some other system; see the end for more details.
11194
11195@c The following documentation was initially generated by
11196@c (generate-documentation) in (gnu services mail). Manually maintained
11197@c documentation is better, so we shouldn't hesitate to edit below as
11198@c needed. However if the change you want to make to this documentation
11199@c can be done in an automated way, it's probably easier to change
11200@c (generate-documentation) than to make it below and have to deal with
11201@c the churn as dovecot updates.
11202
11203Available @code{dovecot-configuration} fields are:
11204
11205@deftypevr {@code{dovecot-configuration} parameter} package dovecot
11206The dovecot package.
11207@end deftypevr
11208
11209@deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
1068f26b
AE
11210A list of IPs or hosts where to listen for connections. @samp{*}
11211listens on all IPv4 interfaces, @samp{::} listens on all IPv6
d8c18af8
AW
11212interfaces. If you want to specify non-default ports or anything more
11213complex, customize the address and port fields of the
11214@samp{inet-listener} of the specific services you are interested in.
11215@end deftypevr
11216
11217@deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
11218List of protocols we want to serve. Available protocols include
11219@samp{imap}, @samp{pop3}, and @samp{lmtp}.
11220
11221Available @code{protocol-configuration} fields are:
11222
11223@deftypevr {@code{protocol-configuration} parameter} string name
11224The name of the protocol.
11225@end deftypevr
11226
11227@deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
1068f26b 11228UNIX socket path to the master authentication server to find users.
d8c18af8 11229This is used by imap (for shared users) and lda.
1068f26b 11230It defaults to @samp{"/var/run/dovecot/auth-userdb"}.
d8c18af8
AW
11231@end deftypevr
11232
11233@deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
11234Space separated list of plugins to load.
11235@end deftypevr
11236
11237@deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
11238Maximum number of IMAP connections allowed for a user from each IP
11239address. NOTE: The username is compared case-sensitively.
11240Defaults to @samp{10}.
11241@end deftypevr
11242
11243@end deftypevr
11244
11245@deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
11246List of services to enable. Available services include @samp{imap},
11247@samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
11248@samp{lmtp}.
11249
11250Available @code{service-configuration} fields are:
11251
11252@deftypevr {@code{service-configuration} parameter} string kind
11253The service kind. Valid values include @code{director},
11254@code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
11255@code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
11256@code{tcpwrap}, @code{quota-warning}, or anything else.
11257@end deftypevr
11258
11259@deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
1068f26b 11260Listeners for the service. A listener is either a
d8c18af8
AW
11261@code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
11262an @code{inet-listener-configuration}.
11263Defaults to @samp{()}.
11264
11265Available @code{unix-listener-configuration} fields are:
11266
eba56076
CL
11267@deftypevr {@code{unix-listener-configuration} parameter} string path
11268Path to the file, relative to @code{base-dir} field. This is also used as
11269the section name.
d8c18af8
AW
11270@end deftypevr
11271
11272@deftypevr {@code{unix-listener-configuration} parameter} string mode
11273The access mode for the socket.
11274Defaults to @samp{"0600"}.
11275@end deftypevr
11276
11277@deftypevr {@code{unix-listener-configuration} parameter} string user
f9b9a033 11278The user to own the socket.
d8c18af8
AW
11279Defaults to @samp{""}.
11280@end deftypevr
11281
11282@deftypevr {@code{unix-listener-configuration} parameter} string group
11283The group to own the socket.
11284Defaults to @samp{""}.
11285@end deftypevr
11286
11287
11288Available @code{fifo-listener-configuration} fields are:
11289
eba56076
CL
11290@deftypevr {@code{fifo-listener-configuration} parameter} string path
11291Path to the file, relative to @code{base-dir} field. This is also used as
11292the section name.
d8c18af8
AW
11293@end deftypevr
11294
11295@deftypevr {@code{fifo-listener-configuration} parameter} string mode
11296The access mode for the socket.
11297Defaults to @samp{"0600"}.
11298@end deftypevr
11299
11300@deftypevr {@code{fifo-listener-configuration} parameter} string user
f9b9a033 11301The user to own the socket.
d8c18af8
AW
11302Defaults to @samp{""}.
11303@end deftypevr
11304
11305@deftypevr {@code{fifo-listener-configuration} parameter} string group
11306The group to own the socket.
11307Defaults to @samp{""}.
11308@end deftypevr
11309
11310
11311Available @code{inet-listener-configuration} fields are:
11312
11313@deftypevr {@code{inet-listener-configuration} parameter} string protocol
11314The protocol to listen for.
11315@end deftypevr
11316
11317@deftypevr {@code{inet-listener-configuration} parameter} string address
11318The address on which to listen, or empty for all addresses.
11319Defaults to @samp{""}.
11320@end deftypevr
11321
11322@deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
11323The port on which to listen.
11324@end deftypevr
11325
11326@deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
11327Whether to use SSL for this service; @samp{yes}, @samp{no}, or
11328@samp{required}.
11329Defaults to @samp{#t}.
11330@end deftypevr
11331
11332@end deftypevr
11333
11334@deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
11335Number of connections to handle before starting a new process.
11336Typically the only useful values are 0 (unlimited) or 1. 1 is more
11337secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
11338Defaults to @samp{1}.
11339@end deftypevr
11340
11341@deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
11342Number of processes to always keep waiting for more connections.
11343Defaults to @samp{0}.
11344@end deftypevr
11345
11346@deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
11347If you set @samp{service-count 0}, you probably need to grow
11348this.
11349Defaults to @samp{256000000}.
11350@end deftypevr
11351
11352@end deftypevr
11353
11354@deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
11355Dict configuration, as created by the @code{dict-configuration}
11356constructor.
11357
11358Available @code{dict-configuration} fields are:
11359
11360@deftypevr {@code{dict-configuration} parameter} free-form-fields entries
11361A list of key-value pairs that this dict should hold.
11362Defaults to @samp{()}.
11363@end deftypevr
11364
11365@end deftypevr
11366
11367@deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
1068f26b 11368A list of passdb configurations, each one created by the
d8c18af8
AW
11369@code{passdb-configuration} constructor.
11370
11371Available @code{passdb-configuration} fields are:
11372
11373@deftypevr {@code{passdb-configuration} parameter} string driver
11374The driver that the passdb should use. Valid values include
11375@samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
11376@samp{static}.
11377Defaults to @samp{"pam"}.
11378@end deftypevr
11379
deb36188
CL
11380@deftypevr {@code{passdb-configuration} parameter} space-separated-string-list args
11381Space separated list of arguments to the passdb driver.
11382Defaults to @samp{""}.
d8c18af8
AW
11383@end deftypevr
11384
11385@end deftypevr
11386
11387@deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
11388List of userdb configurations, each one created by the
11389@code{userdb-configuration} constructor.
11390
11391Available @code{userdb-configuration} fields are:
11392
11393@deftypevr {@code{userdb-configuration} parameter} string driver
11394The driver that the userdb should use. Valid values include
11395@samp{passwd} and @samp{static}.
11396Defaults to @samp{"passwd"}.
11397@end deftypevr
11398
deb36188
CL
11399@deftypevr {@code{userdb-configuration} parameter} space-separated-string-list args
11400Space separated list of arguments to the userdb driver.
11401Defaults to @samp{""}.
d8c18af8
AW
11402@end deftypevr
11403
11404@deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
11405Override fields from passwd.
11406Defaults to @samp{()}.
11407@end deftypevr
11408
11409@end deftypevr
11410
11411@deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
11412Plug-in configuration, created by the @code{plugin-configuration}
11413constructor.
11414@end deftypevr
11415
11416@deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
11417List of namespaces. Each item in the list is created by the
11418@code{namespace-configuration} constructor.
11419
11420Available @code{namespace-configuration} fields are:
11421
11422@deftypevr {@code{namespace-configuration} parameter} string name
11423Name for this namespace.
11424@end deftypevr
11425
11426@deftypevr {@code{namespace-configuration} parameter} string type
11427Namespace type: @samp{private}, @samp{shared} or @samp{public}.
11428Defaults to @samp{"private"}.
11429@end deftypevr
11430
11431@deftypevr {@code{namespace-configuration} parameter} string separator
11432Hierarchy separator to use. You should use the same separator for
11433all namespaces or some clients get confused. @samp{/} is usually a good
11434one. The default however depends on the underlying mail storage
11435format.
11436Defaults to @samp{""}.
11437@end deftypevr
11438
11439@deftypevr {@code{namespace-configuration} parameter} string prefix
11440Prefix required to access this namespace. This needs to be
11441different for all namespaces. For example @samp{Public/}.
11442Defaults to @samp{""}.
11443@end deftypevr
11444
11445@deftypevr {@code{namespace-configuration} parameter} string location
1068f26b 11446Physical location of the mailbox. This is in the same format as
d8c18af8
AW
11447mail_location, which is also the default for it.
11448Defaults to @samp{""}.
11449@end deftypevr
11450
11451@deftypevr {@code{namespace-configuration} parameter} boolean inbox?
11452There can be only one INBOX, and this setting defines which
11453namespace has it.
11454Defaults to @samp{#f}.
11455@end deftypevr
11456
11457@deftypevr {@code{namespace-configuration} parameter} boolean hidden?
11458If namespace is hidden, it's not advertised to clients via NAMESPACE
11459extension. You'll most likely also want to set @samp{list? #f}. This is mostly
11460useful when converting from another server with different namespaces
11461which you want to deprecate but still keep working. For example you can
11462create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
11463and @samp{mail/}.
11464Defaults to @samp{#f}.
11465@end deftypevr
11466
11467@deftypevr {@code{namespace-configuration} parameter} boolean list?
1068f26b
AE
11468Show the mailboxes under this namespace with the LIST command. This
11469makes the namespace visible for clients that do not support the NAMESPACE
d8c18af8
AW
11470extension. The special @code{children} value lists child mailboxes, but
11471hides the namespace prefix.
11472Defaults to @samp{#t}.
11473@end deftypevr
11474
11475@deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
11476Namespace handles its own subscriptions. If set to @code{#f}, the
11477parent namespace handles them. The empty prefix should always have this
1068f26b 11478as @code{#t}).
d8c18af8
AW
11479Defaults to @samp{#t}.
11480@end deftypevr
11481
11482@deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
11483List of predefined mailboxes in this namespace.
11484Defaults to @samp{()}.
11485
11486Available @code{mailbox-configuration} fields are:
11487
11488@deftypevr {@code{mailbox-configuration} parameter} string name
11489Name for this mailbox.
11490@end deftypevr
11491
11492@deftypevr {@code{mailbox-configuration} parameter} string auto
11493@samp{create} will automatically create this mailbox.
11494@samp{subscribe} will both create and subscribe to the mailbox.
11495Defaults to @samp{"no"}.
11496@end deftypevr
11497
11498@deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
11499List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
11500Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
11501@code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
11502Defaults to @samp{()}.
11503@end deftypevr
11504
11505@end deftypevr
11506
11507@end deftypevr
11508
11509@deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
11510Base directory where to store runtime data.
11511Defaults to @samp{"/var/run/dovecot/"}.
11512@end deftypevr
11513
11514@deftypevr {@code{dovecot-configuration} parameter} string login-greeting
11515Greeting message for clients.
11516Defaults to @samp{"Dovecot ready."}.
11517@end deftypevr
11518
11519@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
11520List of trusted network ranges. Connections from these IPs are
11521allowed to override their IP addresses and ports (for logging and for
11522authentication checks). @samp{disable-plaintext-auth} is also ignored
1068f26b 11523for these networks. Typically you would specify your IMAP proxy servers
d8c18af8
AW
11524here.
11525Defaults to @samp{()}.
11526@end deftypevr
11527
11528@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
11529List of login access check sockets (e.g. tcpwrap).
11530Defaults to @samp{()}.
11531@end deftypevr
11532
11533@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
11534Show more verbose process titles (in ps). Currently shows user name
1068f26b
AE
11535and IP address. Useful for seeing who is actually using the IMAP
11536processes (e.g. shared mailboxes or if the same uid is used for multiple
d8c18af8
AW
11537accounts).
11538Defaults to @samp{#f}.
11539@end deftypevr
11540
11541@deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
11542Should all processes be killed when Dovecot master process shuts down.
11543Setting this to @code{#f} means that Dovecot can be upgraded without
11544forcing existing client connections to close (although that could also
1068f26b 11545be a problem if the upgrade is e.g. due to a security fix).
d8c18af8
AW
11546Defaults to @samp{#t}.
11547@end deftypevr
11548
11549@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
11550If non-zero, run mail commands via this many connections to doveadm
11551server, instead of running them directly in the same process.
11552Defaults to @samp{0}.
11553@end deftypevr
11554
11555@deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
11556UNIX socket or host:port used for connecting to doveadm server.
11557Defaults to @samp{"doveadm-server"}.
11558@end deftypevr
11559
11560@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
11561List of environment variables that are preserved on Dovecot startup
11562and passed down to all of its child processes. You can also give
11563key=value pairs to always set specific settings.
11564@end deftypevr
11565
11566@deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
11567Disable LOGIN command and all other plaintext authentications unless
11568SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
11569matches the local IP (i.e. you're connecting from the same computer),
11570the connection is considered secure and plaintext authentication is
11571allowed. See also ssl=required setting.
11572Defaults to @samp{#t}.
11573@end deftypevr
11574
11575@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
11576Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
11577Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
11578for caching to be used.
11579Defaults to @samp{0}.
11580@end deftypevr
11581
11582@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
11583Time to live for cached data. After TTL expires the cached record
11584is no longer used, *except* if the main database lookup returns internal
11585failure. We also try to handle password changes automatically: If
11586user's previous authentication was successful, but this one wasn't, the
11587cache isn't used. For now this works only with plaintext
11588authentication.
11589Defaults to @samp{"1 hour"}.
11590@end deftypevr
11591
11592@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
11593TTL for negative hits (user not found, password mismatch).
115940 disables caching them completely.
11595Defaults to @samp{"1 hour"}.
11596@end deftypevr
11597
11598@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
11599List of realms for SASL authentication mechanisms that need them.
11600You can leave it empty if you don't want to support multiple realms.
11601Many clients simply use the first one listed here, so keep the default
11602realm first.
11603Defaults to @samp{()}.
11604@end deftypevr
11605
11606@deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
11607Default realm/domain to use if none was specified. This is used for
11608both SASL realms and appending @@domain to username in plaintext
11609logins.
11610Defaults to @samp{""}.
11611@end deftypevr
11612
11613@deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
11614List of allowed characters in username. If the user-given username
11615contains a character not listed in here, the login automatically fails.
11616This is just an extra check to make sure user can't exploit any
11617potential quote escaping vulnerabilities with SQL/LDAP databases. If
11618you want to allow all characters, set this value to empty.
11619Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
11620@end deftypevr
11621
11622@deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
11623Username character translations before it's looked up from
11624databases. The value contains series of from -> to characters. For
11625example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
11626translated to @samp{@@}.
11627Defaults to @samp{""}.
11628@end deftypevr
11629
11630@deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
11631Username formatting before it's looked up from databases. You can
11632use the standard variables here, e.g. %Lu would lowercase the username,
11633%n would drop away the domain if it was given, or @samp{%n-AT-%d} would
11634change the @samp{@@} into @samp{-AT-}. This translation is done after
11635@samp{auth-username-translation} changes.
11636Defaults to @samp{"%Lu"}.
11637@end deftypevr
11638
11639@deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
11640If you want to allow master users to log in by specifying the master
11641username within the normal username string (i.e. not using SASL
11642mechanism's support for it), you can specify the separator character
11643here. The format is then <username><separator><master username>.
11644UW-IMAP uses @samp{*} as the separator, so that could be a good
11645choice.
11646Defaults to @samp{""}.
11647@end deftypevr
11648
11649@deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
11650Username to use for users logging in with ANONYMOUS SASL
11651mechanism.
11652Defaults to @samp{"anonymous"}.
11653@end deftypevr
11654
11655@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
11656Maximum number of dovecot-auth worker processes. They're used to
11657execute blocking passdb and userdb queries (e.g. MySQL and PAM).
11658They're automatically created and destroyed as needed.
11659Defaults to @samp{30}.
11660@end deftypevr
11661
11662@deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
11663Host name to use in GSSAPI principal names. The default is to use
11664the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
11665allow all keytab entries.
11666Defaults to @samp{""}.
11667@end deftypevr
11668
11669@deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
11670Kerberos keytab to use for the GSSAPI mechanism. Will use the
8b499030 11671system default (usually @file{/etc/krb5.keytab}) if not specified. You may
d8c18af8
AW
11672need to change the auth service to run as root to be able to read this
11673file.
11674Defaults to @samp{""}.
11675@end deftypevr
11676
11677@deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
11678Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
11679and @samp{ntlm-auth} helper.
11680<doc/wiki/Authentication/Mechanisms/Winbind.txt>.
11681Defaults to @samp{#f}.
11682@end deftypevr
11683
11684@deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
11685Path for Samba's @samp{ntlm-auth} helper binary.
11686Defaults to @samp{"/usr/bin/ntlm_auth"}.
11687@end deftypevr
11688
11689@deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
11690Time to delay before replying to failed authentications.
11691Defaults to @samp{"2 secs"}.
11692@end deftypevr
11693
11694@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
11695Require a valid SSL client certificate or the authentication
11696fails.
11697Defaults to @samp{#f}.
11698@end deftypevr
11699
11700@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
11701Take the username from client's SSL certificate, using
11702@code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
11703CommonName.
11704Defaults to @samp{#f}.
11705@end deftypevr
11706
11707@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
11708List of wanted authentication mechanisms. Supported mechanisms are:
11709@samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
11710@samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
11711@samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
11712@samp{disable-plaintext-auth} setting.
11713@end deftypevr
11714
11715@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
11716List of IPs or hostnames to all director servers, including ourself.
11717Ports can be specified as ip:port. The default port is the same as what
11718director service's @samp{inet-listener} is using.
11719Defaults to @samp{()}.
11720@end deftypevr
11721
11722@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
11723List of IPs or hostnames to all backend mail servers. Ranges are
11724allowed too, like 10.0.0.10-10.0.0.30.
11725Defaults to @samp{()}.
11726@end deftypevr
11727
11728@deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
11729How long to redirect users to a specific server after it no longer
11730has any connections.
11731Defaults to @samp{"15 min"}.
11732@end deftypevr
11733
11734@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
11735TCP/IP port that accepts doveadm connections (instead of director
11736connections) If you enable this, you'll also need to add
11737@samp{inet-listener} for the port.
11738Defaults to @samp{0}.
11739@end deftypevr
11740
11741@deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
11742How the username is translated before being hashed. Useful values
11743include %Ln if user can log in with or without @@domain, %Ld if mailboxes
11744are shared within domain.
11745Defaults to @samp{"%Lu"}.
11746@end deftypevr
11747
11748@deftypevr {@code{dovecot-configuration} parameter} string log-path
11749Log file to use for error messages. @samp{syslog} logs to syslog,
11750@samp{/dev/stderr} logs to stderr.
11751Defaults to @samp{"syslog"}.
11752@end deftypevr
11753
11754@deftypevr {@code{dovecot-configuration} parameter} string info-log-path
11755Log file to use for informational messages. Defaults to
11756@samp{log-path}.
11757Defaults to @samp{""}.
11758@end deftypevr
11759
11760@deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
11761Log file to use for debug messages. Defaults to
11762@samp{info-log-path}.
11763Defaults to @samp{""}.
11764@end deftypevr
11765
11766@deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
11767Syslog facility to use if you're logging to syslog. Usually if you
11768don't want to use @samp{mail}, you'll use local0..local7. Also other
11769standard facilities are supported.
11770Defaults to @samp{"mail"}.
11771@end deftypevr
11772
11773@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
11774Log unsuccessful authentication attempts and the reasons why they
11775failed.
11776Defaults to @samp{#f}.
11777@end deftypevr
11778
11779@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
11780In case of password mismatches, log the attempted password. Valid
11781values are no, plain and sha1. sha1 can be useful for detecting brute
11782force password attempts vs. user simply trying the same password over
11783and over again. You can also truncate the value to n chars by appending
11784":n" (e.g. sha1:6).
11785Defaults to @samp{#f}.
11786@end deftypevr
11787
11788@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
11789Even more verbose logging for debugging purposes. Shows for example
11790SQL queries.
11791Defaults to @samp{#f}.
11792@end deftypevr
11793
11794@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
11795In case of password mismatches, log the passwords and used scheme so
11796the problem can be debugged. Enabling this also enables
11797@samp{auth-debug}.
11798Defaults to @samp{#f}.
11799@end deftypevr
11800
11801@deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
11802Enable mail process debugging. This can help you figure out why
11803Dovecot isn't finding your mails.
11804Defaults to @samp{#f}.
11805@end deftypevr
11806
11807@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
11808Show protocol level SSL errors.
11809Defaults to @samp{#f}.
11810@end deftypevr
11811
11812@deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
11813Prefix for each line written to log file. % codes are in
11814strftime(3) format.
11815Defaults to @samp{"\"%b %d %H:%M:%S \""}.
11816@end deftypevr
11817
11818@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
11819List of elements we want to log. The elements which have a
11820non-empty variable value are joined together to form a comma-separated
11821string.
11822@end deftypevr
11823
11824@deftypevr {@code{dovecot-configuration} parameter} string login-log-format
11825Login log format. %s contains @samp{login-log-format-elements}
11826string, %$ contains the data we want to log.
11827Defaults to @samp{"%$: %s"}.
11828@end deftypevr
11829
11830@deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
11831Log prefix for mail processes. See doc/wiki/Variables.txt for list
11832of possible variables you can use.
11833Defaults to @samp{"\"%s(%u): \""}.
11834@end deftypevr
11835
11836@deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
11837Format to use for logging mail deliveries. You can use variables:
11838@table @code
11839@item %$
11840Delivery status message (e.g. @samp{saved to INBOX})
11841@item %m
11842Message-ID
11843@item %s
11844Subject
11845@item %f
11846From address
11847@item %p
11848Physical size
11849@item %w
11850Virtual size.
11851@end table
11852Defaults to @samp{"msgid=%m: %$"}.
11853@end deftypevr
11854
11855@deftypevr {@code{dovecot-configuration} parameter} string mail-location
11856Location for users' mailboxes. The default is empty, which means
11857that Dovecot tries to find the mailboxes automatically. This won't work
11858if the user doesn't yet have any mail, so you should explicitly tell
11859Dovecot the full location.
11860
11861If you're using mbox, giving a path to the INBOX
11862file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
11863where the other mailboxes are kept. This is called the "root mail
11864directory", and it must be the first path given in the
11865@samp{mail-location} setting.
11866
11867There are a few special variables you can use, eg.:
11868
11869@table @samp
11870@item %u
11871username
11872@item %n
11873user part in user@@domain, same as %u if there's no domain
11874@item %d
11875domain part in user@@domain, empty if there's no domain
11876@item %h
11877home director
11878@end table
11879
11880See doc/wiki/Variables.txt for full list. Some examples:
11881@table @samp
11882@item maildir:~/Maildir
11883@item mbox:~/mail:INBOX=/var/mail/%u
11884@item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
11885@end table
11886Defaults to @samp{""}.
11887@end deftypevr
11888
11889@deftypevr {@code{dovecot-configuration} parameter} string mail-uid
11890System user and group used to access mails. If you use multiple,
11891userdb can override these by returning uid or gid fields. You can use
11892either numbers or names. <doc/wiki/UserIds.txt>.
11893Defaults to @samp{""}.
11894@end deftypevr
11895
11896@deftypevr {@code{dovecot-configuration} parameter} string mail-gid
11897
11898Defaults to @samp{""}.
11899@end deftypevr
11900
11901@deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
11902Group to enable temporarily for privileged operations. Currently
11903this is used only with INBOX when either its initial creation or
11904dotlocking fails. Typically this is set to "mail" to give access to
11905/var/mail.
11906Defaults to @samp{""}.
11907@end deftypevr
11908
11909@deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
11910Grant access to these supplementary groups for mail processes.
11911Typically these are used to set up access to shared mailboxes. Note
11912that it may be dangerous to set these if users can create
11913symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
11914could allow a user to delete others' mailboxes, or ln -s
11915/secret/shared/box ~/mail/mybox would allow reading it).
11916Defaults to @samp{""}.
11917@end deftypevr
11918
11919@deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
8f65585b 11920Allow full file system access to clients. There's no access checks
d8c18af8
AW
11921other than what the operating system does for the active UID/GID. It
11922works with both maildir and mboxes, allowing you to prefix mailboxes
11923names with e.g. /path/ or ~user/.
11924Defaults to @samp{#f}.
11925@end deftypevr
11926
11927@deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
11928Don't use mmap() at all. This is required if you store indexes to
8f65585b 11929shared file systems (NFS or clustered file system).
d8c18af8
AW
11930Defaults to @samp{#f}.
11931@end deftypevr
11932
11933@deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
11934Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
11935supports @samp{O_EXCL} since version 3, so this should be safe to use
11936nowadays by default.
11937Defaults to @samp{#t}.
11938@end deftypevr
11939
11940@deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
11941When to use fsync() or fdatasync() calls:
11942@table @code
11943@item optimized
11944Whenever necessary to avoid losing important data
11945@item always
11946Useful with e.g. NFS when write()s are delayed
11947@item never
11948Never use it (best performance, but crashes can lose data).
11949@end table
11950Defaults to @samp{"optimized"}.
11951@end deftypevr
11952
11953@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
11954Mail storage exists in NFS. Set this to yes to make Dovecot flush
11955NFS caches whenever needed. If you're using only a single mail server
11956this isn't needed.
11957Defaults to @samp{#f}.
11958@end deftypevr
11959
11960@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
11961Mail index files also exist in NFS. Setting this to yes requires
11962@samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
11963Defaults to @samp{#f}.
11964@end deftypevr
11965
11966@deftypevr {@code{dovecot-configuration} parameter} string lock-method
11967Locking method for index files. Alternatives are fcntl, flock and
11968dotlock. Dotlocking uses some tricks which may create more disk I/O
11969than other locking methods. NFS users: flock doesn't work, remember to
11970change @samp{mmap-disable}.
11971Defaults to @samp{"fcntl"}.
11972@end deftypevr
11973
11974@deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
11975Directory in which LDA/LMTP temporarily stores incoming mails >128
11976kB.
11977Defaults to @samp{"/tmp"}.
11978@end deftypevr
11979
11980@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
11981Valid UID range for users. This is mostly to make sure that users can't
11982log in as daemons or other system users. Note that denying root logins is
11983hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
11984is set to 0.
11985Defaults to @samp{500}.
11986@end deftypevr
11987
11988@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
11989
11990Defaults to @samp{0}.
11991@end deftypevr
11992
11993@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
11994Valid GID range for users. Users having non-valid GID as primary group ID
11995aren't allowed to log in. If user belongs to supplementary groups with
11996non-valid GIDs, those groups are not set.
11997Defaults to @samp{1}.
11998@end deftypevr
11999
12000@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
12001
12002Defaults to @samp{0}.
12003@end deftypevr
12004
12005@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
12006Maximum allowed length for mail keyword name. It's only forced when
12007trying to create new keywords.
12008Defaults to @samp{50}.
12009@end deftypevr
12010
12011@deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
12012List of directories under which chrooting is allowed for mail
12013processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
12014too). This setting doesn't affect @samp{login-chroot}
12015@samp{mail-chroot} or auth chroot settings. If this setting is empty,
12016"/./" in home dirs are ignored. WARNING: Never add directories here
12017which local users can modify, that may lead to root exploit. Usually
12018this should be done only if you don't allow shell access for users.
12019<doc/wiki/Chrooting.txt>.
12020Defaults to @samp{()}.
12021@end deftypevr
12022
12023@deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
12024Default chroot directory for mail processes. This can be overridden
12025for specific users in user database by giving /./ in user's home
12026directory (e.g. /home/./user chroots into /home). Note that usually
12027there is no real need to do chrooting, Dovecot doesn't allow users to
12028access files outside their mail directory anyway. If your home
12029directories are prefixed with the chroot directory, append "/." to
12030@samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
12031Defaults to @samp{""}.
12032@end deftypevr
12033
12034@deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
12035UNIX socket path to master authentication server to find users.
12036This is used by imap (for shared users) and lda.
12037Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
12038@end deftypevr
12039
12040@deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
12041Directory where to look up mail plugins.
12042Defaults to @samp{"/usr/lib/dovecot"}.
12043@end deftypevr
12044
12045@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
12046List of plugins to load for all services. Plugins specific to IMAP,
12047LDA, etc. are added to this list in their own .conf files.
12048Defaults to @samp{()}.
12049@end deftypevr
12050
12051@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
12052The minimum number of mails in a mailbox before updates are done to
12053cache file. This allows optimizing Dovecot's behavior to do less disk
12054writes at the cost of more disk reads.
12055Defaults to @samp{0}.
12056@end deftypevr
12057
12058@deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
12059When IDLE command is running, mailbox is checked once in a while to
12060see if there are any new mails or other changes. This setting defines
12061the minimum time to wait between those checks. Dovecot can also use
12062dnotify, inotify and kqueue to find out immediately when changes
12063occur.
12064Defaults to @samp{"30 secs"}.
12065@end deftypevr
12066
12067@deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
12068Save mails with CR+LF instead of plain LF. This makes sending those
12069mails take less CPU, especially with sendfile() syscall with Linux and
12070FreeBSD. But it also creates a bit more disk I/O which may just make it
12071slower. Also note that if other software reads the mboxes/maildirs,
12072they may handle the extra CRs wrong and cause problems.
12073Defaults to @samp{#f}.
12074@end deftypevr
12075
12076@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
12077By default LIST command returns all entries in maildir beginning
12078with a dot. Enabling this option makes Dovecot return only entries
12079which are directories. This is done by stat()ing each entry, so it
12080causes more disk I/O.
12081 (For systems setting struct @samp{dirent->d_type} this check is free
12082and it's done always regardless of this setting).
12083Defaults to @samp{#f}.
12084@end deftypevr
12085
12086@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
12087When copying a message, do it with hard links whenever possible.
12088This makes the performance much better, and it's unlikely to have any
12089side effects.
12090Defaults to @samp{#t}.
12091@end deftypevr
12092
12093@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
12094Assume Dovecot is the only MUA accessing Maildir: Scan cur/
12095directory only when its mtime changes unexpectedly or when we can't find
12096the mail otherwise.
12097Defaults to @samp{#f}.
12098@end deftypevr
12099
12100@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
12101Which locking methods to use for locking mbox. There are four
12102available:
12103
12104@table @code
12105@item dotlock
12106Create <mailbox>.lock file. This is the oldest and most NFS-safe
12107solution. If you want to use /var/mail/ like directory, the users will
12108need write access to that directory.
12109@item dotlock-try
12110Same as dotlock, but if it fails because of permissions or because there
12111isn't enough disk space, just skip it.
12112@item fcntl
12113Use this if possible. Works with NFS too if lockd is used.
12114@item flock
a01ad638 12115May not exist in all systems. Doesn't work with NFS.
d8c18af8
AW
12116@item lockf
12117May not exist in all systems. Doesn't work with NFS.
12118@end table
12119
12120You can use multiple locking methods; if you do the order they're declared
12121in is important to avoid deadlocks if other MTAs/MUAs are using multiple
12122locking methods as well. Some operating systems don't allow using some of
12123them simultaneously.
12124@end deftypevr
12125
12126@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
12127
12128@end deftypevr
12129
12130@deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
12131Maximum time to wait for lock (all of them) before aborting.
12132Defaults to @samp{"5 mins"}.
12133@end deftypevr
12134
12135@deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
12136If dotlock exists but the mailbox isn't modified in any way,
12137override the lock file after this much time.
12138Defaults to @samp{"2 mins"}.
12139@end deftypevr
12140
12141@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
12142When mbox changes unexpectedly we have to fully read it to find out
12143what changed. If the mbox is large this can take a long time. Since
12144the change is usually just a newly appended mail, it'd be faster to
12145simply read the new mails. If this setting is enabled, Dovecot does
12146this but still safely fallbacks to re-reading the whole mbox file
12147whenever something in mbox isn't how it's expected to be. The only real
12148downside to this setting is that if some other MUA changes message
12149flags, Dovecot doesn't notice it immediately. Note that a full sync is
12150done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
12151Defaults to @samp{#t}.
12152@end deftypevr
12153
12154@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
12155Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
12156EXAMINE, EXPUNGE or CHECK commands. If this is set,
12157@samp{mbox-dirty-syncs} is ignored.
12158Defaults to @samp{#f}.
12159@end deftypevr
12160
12161@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
12162Delay writing mbox headers until doing a full write sync (EXPUNGE
12163and CHECK commands and when closing the mailbox). This is especially
12164useful for POP3 where clients often delete all mails. The downside is
12165that our changes aren't immediately visible to other MUAs.
12166Defaults to @samp{#t}.
12167@end deftypevr
12168
12169@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
12170If mbox size is smaller than this (e.g. 100k), don't write index
12171files. If an index file already exists it's still read, just not
12172updated.
12173Defaults to @samp{0}.
12174@end deftypevr
12175
12176@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
12177Maximum dbox file size until it's rotated.
12178Defaults to @samp{2000000}.
12179@end deftypevr
12180
12181@deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
12182Maximum dbox file age until it's rotated. Typically in days. Day
12183begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
12184disabled.
12185Defaults to @samp{"1d"}.
12186@end deftypevr
12187
12188@deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
12189When creating new mdbox files, immediately preallocate their size to
12190@samp{mdbox-rotate-size}. This setting currently works only in Linux
8f65585b 12191with some file systems (ext4, xfs).
d8c18af8
AW
12192Defaults to @samp{#f}.
12193@end deftypevr
12194
12195@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
12196sdbox and mdbox support saving mail attachments to external files,
12197which also allows single instance storage for them. Other backends
12198don't support this for now.
12199
12200WARNING: This feature hasn't been tested much yet. Use at your own risk.
12201
12202Directory root where to store mail attachments. Disabled, if empty.
12203Defaults to @samp{""}.
12204@end deftypevr
12205
12206@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
12207Attachments smaller than this aren't saved externally. It's also
12208possible to write a plugin to disable saving specific attachments
12209externally.
12210Defaults to @samp{128000}.
12211@end deftypevr
12212
12213@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
8f65585b 12214File system backend to use for saving attachments:
d8c18af8
AW
12215@table @code
12216@item posix
12217No SiS done by Dovecot (but this might help FS's own deduplication)
12218@item sis posix
12219SiS with immediate byte-by-byte comparison during saving
12220@item sis-queue posix
12221SiS with delayed comparison and deduplication.
12222@end table
12223Defaults to @samp{"sis posix"}.
12224@end deftypevr
12225
12226@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
12227Hash format to use in attachment filenames. You can add any text and
12228variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
12229@code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
12230truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
12231Defaults to @samp{"%@{sha1@}"}.
12232@end deftypevr
12233
12234@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
12235
12236Defaults to @samp{100}.
12237@end deftypevr
12238
12239@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
12240
12241Defaults to @samp{1000}.
12242@end deftypevr
12243
12244@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
12245Default VSZ (virtual memory size) limit for service processes.
12246This is mainly intended to catch and kill processes that leak memory
12247before they eat up everything.
12248Defaults to @samp{256000000}.
12249@end deftypevr
12250
12251@deftypevr {@code{dovecot-configuration} parameter} string default-login-user
12252Login user is internally used by login processes. This is the most
12253untrusted user in Dovecot system. It shouldn't have access to anything
12254at all.
12255Defaults to @samp{"dovenull"}.
12256@end deftypevr
12257
12258@deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
12259Internal user is used by unprivileged processes. It should be
12260separate from login user, so that login processes can't disturb other
12261processes.
12262Defaults to @samp{"dovecot"}.
12263@end deftypevr
12264
12265@deftypevr {@code{dovecot-configuration} parameter} string ssl?
12266SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
12267Defaults to @samp{"required"}.
12268@end deftypevr
12269
12270@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
12271PEM encoded X.509 SSL/TLS certificate (public key).
12272Defaults to @samp{"</etc/dovecot/default.pem"}.
12273@end deftypevr
12274
12275@deftypevr {@code{dovecot-configuration} parameter} string ssl-key
12276PEM encoded SSL/TLS private key. The key is opened before
12277dropping root privileges, so keep the key file unreadable by anyone but
12278root.
12279Defaults to @samp{"</etc/dovecot/private/default.pem"}.
12280@end deftypevr
12281
12282@deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
12283If key file is password protected, give the password here.
12284Alternatively give it when starting dovecot with -p parameter. Since
12285this file is often world-readable, you may want to place this setting
12286instead to a different.
12287Defaults to @samp{""}.
12288@end deftypevr
12289
12290@deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
12291PEM encoded trusted certificate authority. Set this only if you
12292intend to use @samp{ssl-verify-client-cert? #t}. The file should
12293contain the CA certificate(s) followed by the matching
12294CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
12295Defaults to @samp{""}.
12296@end deftypevr
12297
12298@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
12299Require that CRL check succeeds for client certificates.
12300Defaults to @samp{#t}.
12301@end deftypevr
12302
12303@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
12304Request client to send a certificate. If you also want to require
12305it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
12306Defaults to @samp{#f}.
12307@end deftypevr
12308
12309@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
12310Which field from certificate to use for username. commonName and
12311x500UniqueIdentifier are the usual choices. You'll also need to set
12312@samp{auth-ssl-username-from-cert? #t}.
12313Defaults to @samp{"commonName"}.
12314@end deftypevr
12315
12316@deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
12317How often to regenerate the SSL parameters file. Generation is
12318quite CPU intensive operation. The value is in hours, 0 disables
12319regeneration entirely.
12320Defaults to @samp{168}.
12321@end deftypevr
12322
12323@deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
12324SSL protocols to use.
12325Defaults to @samp{"!SSLv2"}.
12326@end deftypevr
12327
12328@deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
12329SSL ciphers to use.
12330Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
12331@end deftypevr
12332
12333@deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
12334SSL crypto device to use, for valid values run "openssl engine".
12335Defaults to @samp{""}.
12336@end deftypevr
12337
12338@deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
12339Address to use when sending rejection mails.
66329c23
AW
12340%d expands to recipient domain.
12341Defaults to @samp{"postmaster@@%d"}.
d8c18af8
AW
12342@end deftypevr
12343
12344@deftypevr {@code{dovecot-configuration} parameter} string hostname
12345Hostname to use in various parts of sent mails (e.g. in Message-Id)
12346and in LMTP replies. Default is the system's real hostname@@domain.
12347Defaults to @samp{""}.
12348@end deftypevr
12349
12350@deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
12351If user is over quota, return with temporary failure instead of
12352bouncing the mail.
12353Defaults to @samp{#f}.
12354@end deftypevr
12355
12356@deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
12357Binary to use for sending mails.
12358Defaults to @samp{"/usr/sbin/sendmail"}.
12359@end deftypevr
12360
12361@deftypevr {@code{dovecot-configuration} parameter} string submission-host
12362If non-empty, send mails via this SMTP host[:port] instead of
12363sendmail.
12364Defaults to @samp{""}.
12365@end deftypevr
12366
12367@deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
12368Subject: header to use for rejection mails. You can use the same
12369variables as for @samp{rejection-reason} below.
12370Defaults to @samp{"Rejected: %s"}.
12371@end deftypevr
12372
12373@deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
12374Human readable error message for rejection mails. You can use
12375variables:
12376
12377@table @code
12378@item %n
12379CRLF
12380@item %r
12381reason
12382@item %s
12383original subject
12384@item %t
12385recipient
12386@end table
12387Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
12388@end deftypevr
12389
12390@deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
12391Delimiter character between local-part and detail in email
12392address.
12393Defaults to @samp{"+"}.
12394@end deftypevr
12395
12396@deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
12397Header where the original recipient address (SMTP's RCPT TO:
12398address) is taken from if not available elsewhere. With dovecot-lda -a
12399parameter overrides this. A commonly used header for this is
12400X-Original-To.
12401Defaults to @samp{""}.
12402@end deftypevr
12403
12404@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
12405Should saving a mail to a nonexistent mailbox automatically create
12406it?.
12407Defaults to @samp{#f}.
12408@end deftypevr
12409
12410@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
12411Should automatically created mailboxes be also automatically
12412subscribed?.
12413Defaults to @samp{#f}.
12414@end deftypevr
12415
12416@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
12417Maximum IMAP command line length. Some clients generate very long
12418command lines with huge mailboxes, so you may need to raise this if you
12419get "Too long argument" or "IMAP command line too large" errors
12420often.
12421Defaults to @samp{64000}.
12422@end deftypevr
12423
12424@deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
12425IMAP logout format string:
12426@table @code
12427@item %i
12428total number of bytes read from client
12429@item %o
12430total number of bytes sent to client.
12431@end table
12432Defaults to @samp{"in=%i out=%o"}.
12433@end deftypevr
12434
12435@deftypevr {@code{dovecot-configuration} parameter} string imap-capability
12436Override the IMAP CAPABILITY response. If the value begins with '+',
12437add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
12438Defaults to @samp{""}.
12439@end deftypevr
12440
12441@deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
12442How long to wait between "OK Still here" notifications when client
12443is IDLEing.
12444Defaults to @samp{"2 mins"}.
12445@end deftypevr
12446
12447@deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
12448ID field names and values to send to clients. Using * as the value
12449makes Dovecot use the default value. The following fields have default
12450values currently: name, version, os, os-version, support-url,
12451support-email.
12452Defaults to @samp{""}.
12453@end deftypevr
12454
12455@deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
12456ID fields sent by client to log. * means everything.
12457Defaults to @samp{""}.
12458@end deftypevr
12459
12460@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
12461Workarounds for various client bugs:
12462
12463@table @code
12464@item delay-newmail
12465Send EXISTS/RECENT new mail notifications only when replying to NOOP and
12466CHECK commands. Some clients ignore them otherwise, for example OSX
12467Mail (<v2.1). Outlook Express breaks more badly though, without this it
12468may show user "Message no longer in server" errors. Note that OE6
12469still breaks even with this workaround if synchronization is set to
12470"Headers Only".
12471
12472@item tb-extra-mailbox-sep
12473Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
12474adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
12475ignore the extra @samp{/} instead of treating it as invalid mailbox name.
12476
12477@item tb-lsub-flags
12478Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
12479This makes Thunderbird realize they aren't selectable and show them
12480greyed out, instead of only later giving "not selectable" popup error.
12481@end table
12482Defaults to @samp{()}.
12483@end deftypevr
12484
12485@deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
12486Host allowed in URLAUTH URLs sent by client. "*" allows all.
12487Defaults to @samp{""}.
12488@end deftypevr
12489
12490
12491Whew! Lots of configuration options. The nice thing about it though is
12492that GuixSD has a complete interface to Dovecot's configuration
12493language. This allows not only a nice way to declare configurations,
12494but also offers reflective capabilities as well: users can write code to
12495inspect and transform configurations from within Scheme.
12496
12497However, it could be that you just want to get a @code{dovecot.conf} up
12498and running. In that case, you can pass an
7414de0a 12499@code{opaque-dovecot-configuration} as the @code{#:config} parameter to
d8c18af8
AW
12500@code{dovecot-service}. As its name indicates, an opaque configuration
12501does not have easy reflective capabilities.
12502
12503Available @code{opaque-dovecot-configuration} fields are:
12504
12505@deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
12506The dovecot package.
12507@end deftypevr
12508
12509@deftypevr {@code{opaque-dovecot-configuration} parameter} string string
12510The contents of the @code{dovecot.conf}, as a string.
12511@end deftypevr
12512
12513For example, if your @code{dovecot.conf} is just the empty string, you
12514could instantiate a dovecot service like this:
12515
12516@example
12517(dovecot-service #:config
12518 (opaque-dovecot-configuration
12519 (string "")))
12520@end example
12521
f88371e8
SB
12522@subsubheading OpenSMTPD Service
12523
12524@deffn {Scheme Variable} opensmtpd-service-type
12525This is the type of the @uref{https://www.opensmtpd.org, OpenSMTPD}
12526service, whose value should be an @code{opensmtpd-configuration} object
12527as in this example:
12528
12529@example
12530(service opensmtpd-service-type
12531 (opensmtpd-configuration
12532 (config-file (local-file "./my-smtpd.conf"))))
12533@end example
12534@end deffn
12535
12536@deftp {Data Type} opensmtpd-configuration
9fc221b5 12537Data type representing the configuration of opensmtpd.
f88371e8
SB
12538
12539@table @asis
12540@item @code{package} (default: @var{opensmtpd})
12541Package object of the OpenSMTPD SMTP server.
12542
12543@item @code{config-file} (default: @var{%default-opensmtpd-file})
12544File-like object of the OpenSMTPD configuration file to use. By default
12545it listens on the loopback network interface, and allows for mail from
12546users and daemons on the local machine, as well as permitting email to
12547remote servers. Run @command{man smtpd.conf} for more information.
12548
12549@end table
12550@end deftp
859e367d 12551
82ccc499
CZ
12552@subsubheading Exim Service
12553
12554@deffn {Scheme Variable} exim-service-type
12555This is the type of the @uref{https://exim.org, Exim} service, whose value
12556should be an @code{exim-configuration} object as in this example:
12557
12558@example
12559(service exim-service-type
12560 (exim-configuration
12561 (config-file (local-file "./my-exim.conf"))
12562 (aliases '(("postmaster" "bob")
12563 ("bob" "bob@@example.com" "bob@@example2.com")))))
12564@end example
12565@end deffn
12566
12567@deftp {Data Type} exim-configuration
12568Data type representing the configuration of exim.
12569
12570@table @asis
12571@item @code{package} (default: @var{exim})
12572Package object of the Exim server.
12573
12574@item @code{config-file} (default: @code{#f})
12575File-like object of the Exim configuration file to use. If its value is
12576@code{#f} then use the default configuration file from the package
12577provided in @code{package}. The resulting configuration file is loaded
12578after setting the @code{exim_user} and @code{exim_group} configuration
12579variables.
12580
12581@item @code{aliases} (default: @code{'()})
12582List of aliases to use when delivering mail on this system. The
12583@code{car} of each list is used to match incoming mail, with the
12584@code{cdr} of each list designating how to deliver it. There may be many
12585delivery methods provided, in which case the mail is delivered to them
12586all.
12587
12588@end table
12589@end deftp
12590
78cef99b
CL
12591@node Messaging Services
12592@subsubsection Messaging Services
12593
12594@cindex messaging
12595@cindex jabber
12596@cindex XMPP
12597The @code{(gnu services messaging)} module provides Guix service
12598definitions for messaging services: currently only Prosody is supported.
12599
12600@subsubheading Prosody Service
12601
12602@deffn {Scheme Variable} prosody-service-type
12603This is the type for the @uref{http://prosody.im, Prosody XMPP
12604communication server}. Its value must be a @code{prosody-configuration}
12605record as in this example:
12606
12607@example
12608(service prosody-service-type
12609 (prosody-configuration
12610 (modules-enabled (cons "groups" %default-modules-enabled))
12611 (int-components
12612 (list
12613 (int-component-configuration
12614 (hostname "conference.example.net")
12615 (plugin "muc")
12616 (mod-muc (mod-muc-configuration)))))
12617 (virtualhosts
12618 (list
12619 (virtualhost-configuration
12620 (domain "example.net"))))))
12621@end example
12622
12623See below for details about @code{prosody-configuration}.
12624
12625@end deffn
12626
12627By default, Prosody does not need much configuration. Only one
12628@code{virtualhosts} field is needed: it specifies the domain you wish
12629Prosody to serve.
12630
12631Prosodyctl will help you generate X.509 certificates and keys:
12632
12633@example
12634prosodyctl cert request example.net
12635@end example
12636
12637The available configuration parameters follow. Each parameter
12638definition is preceded by its type; for example, @samp{string-list foo}
12639indicates that the @code{foo} parameter should be specified as a list of
12640strings. Types starting with @code{maybe-} denote parameters that won't
12641show up in @code{prosody.cfg.lua} when their value is @code{'disabled}.
12642
12643There is also a way to specify the configuration as a string, if you
12644have an old @code{prosody.cfg.lua} file that you want to port over from
12645some other system; see the end for more details.
12646
12647@c The following documentation was initially generated by
12648@c (generate-documentation) in (gnu services messaging). Manually maintained
12649@c documentation is better, so we shouldn't hesitate to edit below as
12650@c needed. However if the change you want to make to this documentation
12651@c can be done in an automated way, it's probably easier to change
12652@c (generate-documentation) than to make it below and have to deal with
12653@c the churn as Prosody updates.
12654
12655Available @code{prosody-configuration} fields are:
12656
12657@deftypevr {@code{prosody-configuration} parameter} package prosody
12658The Prosody package.
12659@end deftypevr
12660
12661@deftypevr {@code{prosody-configuration} parameter} file-name data-path
12662Location of the Prosody data storage directory. See
12663@url{http://prosody.im/doc/configure}.
12664Defaults to @samp{"/var/lib/prosody"}.
12665@end deftypevr
12666
12667@deftypevr {@code{prosody-configuration} parameter} file-name-list plugin-paths
12668Additional plugin directories. They are searched in all the specified
12669paths in order. See @url{http://prosody.im/doc/plugins_directory}.
12670Defaults to @samp{()}.
12671@end deftypevr
12672
12673@deftypevr {@code{prosody-configuration} parameter} string-list admins
12674This is a list of accounts that are admins for the server. Note that you
12675must create the accounts separately. See @url{http://prosody.im/doc/admins} and
12676@url{http://prosody.im/doc/creating_accounts}.
12677Example: @code{(admins '("user1@@example.com" "user2@@example.net"))}
12678Defaults to @samp{()}.
12679@end deftypevr
12680
12681@deftypevr {@code{prosody-configuration} parameter} boolean use-libevent?
12682Enable use of libevent for better performance under high load. See
12683@url{http://prosody.im/doc/libevent}.
12684Defaults to @samp{#f}.
12685@end deftypevr
12686
12687@deftypevr {@code{prosody-configuration} parameter} module-list modules-enabled
12688This is the list of modules Prosody will load on startup. It looks for
12689@code{mod_modulename.lua} in the plugins folder, so make sure that exists too.
12690Documentation on modules can be found at: @url{http://prosody.im/doc/modules}.
12691Defaults to @samp{%default-modules-enabled}.
12692@end deftypevr
12693
12694@deftypevr {@code{prosody-configuration} parameter} string-list modules-disabled
12695@samp{"offline"}, @samp{"c2s"} and @samp{"s2s"} are auto-loaded, but
12696should you want to disable them then add them to this list.
12697Defaults to @samp{()}.
12698@end deftypevr
12699
12700@deftypevr {@code{prosody-configuration} parameter} file-name groups-file
12701Path to a text file where the shared groups are defined. If this path is
12702empty then @samp{mod_groups} does nothing. See
12703@url{http://prosody.im/doc/modules/mod_groups}.
12704Defaults to @samp{"/var/lib/prosody/sharedgroups.txt"}.
12705@end deftypevr
12706
12707@deftypevr {@code{prosody-configuration} parameter} boolean allow-registration?
12708Disable account creation by default, for security. See
12709@url{http://prosody.im/doc/creating_accounts}.
12710Defaults to @samp{#f}.
12711@end deftypevr
12712
12713@deftypevr {@code{prosody-configuration} parameter} maybe-ssl-configuration ssl
12714These are the SSL/TLS-related settings. Most of them are disabled so to
12715use Prosody's defaults. If you do not completely understand these options, do
12716not add them to your config, it is easy to lower the security of your server
12717using them. See @url{http://prosody.im/doc/advanced_ssl_config}.
12718
12719Available @code{ssl-configuration} fields are:
12720
12721@deftypevr {@code{ssl-configuration} parameter} maybe-string protocol
12722This determines what handshake to use.
12723@end deftypevr
12724
12725@deftypevr {@code{ssl-configuration} parameter} file-name key
12726Path to your private key file, relative to @code{/etc/prosody}.
12727Defaults to @samp{"/etc/prosody/certs/key.pem"}.
12728@end deftypevr
12729
12730@deftypevr {@code{ssl-configuration} parameter} file-name certificate
12731Path to your certificate file, relative to @code{/etc/prosody}.
12732Defaults to @samp{"/etc/prosody/certs/cert.pem"}.
12733@end deftypevr
12734
12735@deftypevr {@code{ssl-configuration} parameter} file-name capath
12736Path to directory containing root certificates that you wish Prosody to
12737trust when verifying the certificates of remote servers.
12738Defaults to @samp{"/etc/ssl/certs"}.
12739@end deftypevr
12740
12741@deftypevr {@code{ssl-configuration} parameter} maybe-file-name cafile
12742Path to a file containing root certificates that you wish Prosody to trust.
12743Similar to @code{capath} but with all certificates concatenated together.
12744@end deftypevr
12745
12746@deftypevr {@code{ssl-configuration} parameter} maybe-string-list verify
12747A list of verification options (these mostly map to OpenSSL's
12748@code{set_verify()} flags).
12749@end deftypevr
12750
12751@deftypevr {@code{ssl-configuration} parameter} maybe-string-list options
12752A list of general options relating to SSL/TLS. These map to OpenSSL's
12753@code{set_options()}. For a full list of options available in LuaSec, see the
12754LuaSec source.
12755@end deftypevr
12756
12757@deftypevr {@code{ssl-configuration} parameter} maybe-non-negative-integer depth
12758How long a chain of certificate authorities to check when looking for a
12759trusted root certificate.
12760@end deftypevr
12761
12762@deftypevr {@code{ssl-configuration} parameter} maybe-string ciphers
12763An OpenSSL cipher string. This selects what ciphers Prosody will offer to
12764clients, and in what order.
12765@end deftypevr
12766
12767@deftypevr {@code{ssl-configuration} parameter} maybe-file-name dhparam
12768A path to a file containing parameters for Diffie-Hellman key exchange. You
12769can create such a file with:
12770@code{openssl dhparam -out /etc/prosody/certs/dh-2048.pem 2048}
12771@end deftypevr
12772
12773@deftypevr {@code{ssl-configuration} parameter} maybe-string curve
12774Curve for Elliptic curve Diffie-Hellman. Prosody's default is
12775@samp{"secp384r1"}.
12776@end deftypevr
12777
12778@deftypevr {@code{ssl-configuration} parameter} maybe-string-list verifyext
12779A list of "extra" verification options.
12780@end deftypevr
12781
12782@deftypevr {@code{ssl-configuration} parameter} maybe-string password
12783Password for encrypted private keys.
12784@end deftypevr
12785
12786@end deftypevr
12787
12788@deftypevr {@code{prosody-configuration} parameter} boolean c2s-require-encryption?
12789Whether to force all client-to-server connections to be encrypted or not.
12790See @url{http://prosody.im/doc/modules/mod_tls}.
12791Defaults to @samp{#f}.
12792@end deftypevr
12793
12794@deftypevr {@code{prosody-configuration} parameter} boolean s2s-require-encryption?
12795Whether to force all server-to-server connections to be encrypted or not.
12796See @url{http://prosody.im/doc/modules/mod_tls}.
12797Defaults to @samp{#f}.
12798@end deftypevr
12799
12800@deftypevr {@code{prosody-configuration} parameter} boolean s2s-secure-auth?
12801Whether to require encryption and certificate authentication. This
12802provides ideal security, but requires servers you communicate with to support
12803encryption AND present valid, trusted certificates. See
12804@url{http://prosody.im/doc/s2s#security}.
12805Defaults to @samp{#f}.
12806@end deftypevr
12807
12808@deftypevr {@code{prosody-configuration} parameter} string-list s2s-insecure-domains
12809Many servers don't support encryption or have invalid or self-signed
12810certificates. You can list domains here that will not be required to
12811authenticate using certificates. They will be authenticated using DNS. See
12812@url{http://prosody.im/doc/s2s#security}.
12813Defaults to @samp{()}.
12814@end deftypevr
12815
12816@deftypevr {@code{prosody-configuration} parameter} string-list s2s-secure-domains
12817Even if you leave @code{s2s-secure-auth?} disabled, you can still require
12818valid certificates for some domains by specifying a list here. See
12819@url{http://prosody.im/doc/s2s#security}.
12820Defaults to @samp{()}.
12821@end deftypevr
12822
12823@deftypevr {@code{prosody-configuration} parameter} string authentication
12824Select the authentication backend to use. The default provider stores
12825passwords in plaintext and uses Prosody's configured data storage to store the
12826authentication data. If you do not trust your server please see
12827@url{http://prosody.im/doc/modules/mod_auth_internal_hashed} for information
12828about using the hashed backend. See also
12829@url{http://prosody.im/doc/authentication}
12830Defaults to @samp{"internal_plain"}.
12831@end deftypevr
12832
12833@deftypevr {@code{prosody-configuration} parameter} maybe-string log
12834Set logging options. Advanced logging configuration is not yet supported
12835by the GuixSD Prosody Service. See @url{http://prosody.im/doc/logging}.
12836Defaults to @samp{"*syslog"}.
12837@end deftypevr
12838
12839@deftypevr {@code{prosody-configuration} parameter} file-name pidfile
12840File to write pid in. See @url{http://prosody.im/doc/modules/mod_posix}.
12841Defaults to @samp{"/var/run/prosody/prosody.pid"}.
12842@end deftypevr
12843
12844@deftypevr {@code{prosody-configuration} parameter} virtualhost-configuration-list virtualhosts
12845A host in Prosody is a domain on which user accounts can be created. For
12846example if you want your users to have addresses like
12847@samp{"john.smith@@example.com"} then you need to add a host
12848@samp{"example.com"}. All options in this list will apply only to this host.
12849
12850Note: the name "virtual" host is used in configuration to avoid confusion with
12851the actual physical host that Prosody is installed on. A single Prosody
12852instance can serve many domains, each one defined as a VirtualHost entry in
12853Prosody's configuration. Conversely a server that hosts a single domain would
12854have just one VirtualHost entry.
12855
12856See @url{http://prosody.im/doc/configure#virtual_host_settings}.
12857
12858Available @code{virtualhost-configuration} fields are:
12859
12860all 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:
12861@deftypevr {@code{virtualhost-configuration} parameter} string domain
12862Domain you wish Prosody to serve.
12863@end deftypevr
12864
12865@end deftypevr
12866
12867@deftypevr {@code{prosody-configuration} parameter} int-component-configuration-list int-components
12868Components are extra services on a server which are available to clients,
12869usually on a subdomain of the main server (such as
12870@samp{"mycomponent.example.com"}). Example components might be chatroom
12871servers, user directories, or gateways to other protocols.
12872
12873Internal components are implemented with Prosody-specific plugins. To add an
12874internal component, you simply fill the hostname field, and the plugin you wish
12875to use for the component.
12876
12877See @url{http://prosody.im/doc/components}.
12878Defaults to @samp{()}.
12879
12880Available @code{int-component-configuration} fields are:
12881
12882all 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:
12883@deftypevr {@code{int-component-configuration} parameter} string hostname
12884Hostname of the component.
12885@end deftypevr
12886
12887@deftypevr {@code{int-component-configuration} parameter} string plugin
12888Plugin you wish to use for the component.
12889@end deftypevr
12890
12891@deftypevr {@code{int-component-configuration} parameter} maybe-mod-muc-configuration mod-muc
12892Multi-user chat (MUC) is Prosody's module for allowing you to create
12893hosted chatrooms/conferences for XMPP users.
12894
12895General information on setting up and using multi-user chatrooms can be found
12896in the "Chatrooms" documentation (@url{http://prosody.im/doc/chatrooms}),
12897which you should read if you are new to XMPP chatrooms.
12898
12899See also @url{http://prosody.im/doc/modules/mod_muc}.
12900
12901Available @code{mod-muc-configuration} fields are:
12902
12903@deftypevr {@code{mod-muc-configuration} parameter} string name
12904The name to return in service discovery responses.
12905Defaults to @samp{"Prosody Chatrooms"}.
12906@end deftypevr
12907
12908@deftypevr {@code{mod-muc-configuration} parameter} string-or-boolean restrict-room-creation
12909If @samp{#t}, this will only allow admins to create new chatrooms.
12910Otherwise anyone can create a room. The value @samp{"local"} restricts room
12911creation to users on the service's parent domain. E.g. @samp{user@@example.com}
12912can create rooms on @samp{rooms.example.com}. The value @samp{"admin"}
12913restricts to service administrators only.
12914Defaults to @samp{#f}.
12915@end deftypevr
12916
12917@deftypevr {@code{mod-muc-configuration} parameter} non-negative-integer max-history-messages
12918Maximum number of history messages that will be sent to the member that has
12919just joined the room.
12920Defaults to @samp{20}.
12921@end deftypevr
12922
12923@end deftypevr
12924
12925@end deftypevr
12926
12927@deftypevr {@code{prosody-configuration} parameter} ext-component-configuration-list ext-components
12928External components use XEP-0114, which most standalone components
12929support. To add an external component, you simply fill the hostname field. See
12930@url{http://prosody.im/doc/components}.
12931Defaults to @samp{()}.
12932
12933Available @code{ext-component-configuration} fields are:
12934
12935all 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:
12936@deftypevr {@code{ext-component-configuration} parameter} string component-secret
12937Password which the component will use to log in.
12938@end deftypevr
12939
12940@deftypevr {@code{ext-component-configuration} parameter} string hostname
12941Hostname of the component.
12942@end deftypevr
12943
12944@end deftypevr
12945
12946@deftypevr {@code{prosody-configuration} parameter} non-negative-integer-list component-ports
12947Port(s) Prosody listens on for component connections.
12948@end deftypevr
12949
12950@deftypevr {@code{prosody-configuration} parameter} string component-interface
12951Interface Prosody listens on for component connections.
12952Defaults to @samp{"127.0.0.1"}.
12953@end deftypevr
12954
12955It could be that you just want to get a @code{prosody.cfg.lua}
12956up and running. In that case, you can pass an
12957@code{opaque-prosody-configuration} record as the value of
12958@code{prosody-service-type}. As its name indicates, an opaque configuration
12959does not have easy reflective capabilities.
12960Available @code{opaque-prosody-configuration} fields are:
12961
12962@deftypevr {@code{opaque-prosody-configuration} parameter} package prosody
12963The prosody package.
12964@end deftypevr
12965
12966@deftypevr {@code{opaque-prosody-configuration} parameter} string prosody.cfg.lua
12967The contents of the @code{prosody.cfg.lua} to use.
12968@end deftypevr
12969
12970For example, if your @code{prosody.cfg.lua} is just the empty
12971string, you could instantiate a prosody service like this:
12972
12973@example
12974(service prosody-service-type
12975 (opaque-prosody-configuration
12976 (prosody.cfg.lua "")))
12977@end example
12978
859e367d
JD
12979@node Kerberos Services
12980@subsubsection Kerberos Services
12981@cindex Kerberos
12982
df31e36a 12983The @code{(gnu services kerberos)} module provides services relating to
859e367d
JD
12984the authentication protocol @dfn{Kerberos}.
12985
8e3f813f
JD
12986@subsubheading Krb5 Service
12987
12988Programs using a Kerberos client library normally
12989expect a configuration file in @file{/etc/krb5.conf}.
12990This service generates such a file from a definition provided in the
12991operating system declaration.
12992It does not cause any daemon to be started.
12993
12994No ``keytab'' files are provided by this service---you must explicitly create them.
12995This service is known to work with the MIT client library, @code{mit-krb5}.
12996Other implementations have not been tested.
12997
12998@defvr {Scheme Variable} krb5-service-type
12999A service type for Kerberos 5 clients.
13000@end defvr
13001
13002@noindent
13003Here is an example of its use:
13004@lisp
13005(service krb5-service-type
13006 (krb5-configuration
13007 (default-realm "EXAMPLE.COM")
13008 (allow-weak-crypto? #t)
13009 (realms (list
13010 (krb5-realm
13011 (name "EXAMPLE.COM")
13012 (admin-server "groucho.example.com")
13013 (kdc "karl.example.com"))
13014 (krb5-realm
13015 (name "ARGRX.EDU")
13016 (admin-server "kerb-admin.argrx.edu")
13017 (kdc "keys.argrx.edu"))))))
13018@end lisp
13019
13020@noindent
13021This example provides a Kerberos@tie{}5 client configuration which:
13022@itemize
13023@item Recognizes two realms, @i{viz:} ``EXAMPLE.COM'' and ``ARGRX.EDU'', both
13024of which have distinct administration servers and key distribution centers;
13025@item Will default to the realm ``EXAMPLE.COM'' if the realm is not explicitly
13026specified by clients;
13027@item Accepts services which only support encryption types known to be weak.
13028@end itemize
13029
13030The @code{krb5-realm} and @code{krb5-configuration} types have many fields.
13031Only the most commonly used ones are described here.
13032For a full list, and more detailed explanation of each, see the MIT
13033@uref{http://web.mit.edu/kerberos/krb5-devel/doc/admin/conf_files/krb5_conf.html,,krb5.conf}
13034documentation.
13035
13036
13037@deftp {Data Type} krb5-realm
13038@cindex realm, kerberos
13039@table @asis
13040@item @code{name}
13041This field is a string identifying the name of the realm.
13042A common convention is to use the fully qualified DNS name of your organization,
13043converted to upper case.
13044
13045@item @code{admin-server}
13046This field is a string identifying the host where the administration server is
13047running.
13048
13049@item @code{kdc}
13050This field is a string identifying the key distribution center
13051for the realm.
13052@end table
13053@end deftp
13054
13055@deftp {Data Type} krb5-configuration
13056
13057@table @asis
13058@item @code{allow-weak-crypto?} (default: @code{#f})
13059If this flag is @code{#t} then services which only offer encryption algorithms
13060known to be weak will be accepted.
13061
13062@item @code{default-realm} (default: @code{#f})
13063This field should be a string identifying the default Kerberos
13064realm for the client.
13065You should set this field to the name of your Kerberos realm.
13066If this value is @code{#f}
13067then a realm must be specified with every Kerberos principal when invoking programs
13068such as @command{kinit}.
13069
13070@item @code{realms}
13071This should be a non-empty list of @code{krb5-realm} objects, which clients may
13072access.
13073Normally, one of them will have a @code{name} field matching the @code{default-realm}
13074field.
13075@end table
13076@end deftp
13077
13078
859e367d
JD
13079@subsubheading PAM krb5 Service
13080@cindex pam-krb5
13081
df31e36a 13082The @code{pam-krb5} service allows for login authentication and password
859e367d
JD
13083management via Kerberos.
13084You will need this service if you want PAM enabled applications to authenticate
13085users using Kerberos.
13086
13087@defvr {Scheme Variable} pam-krb5-service-type
13088A service type for the Kerberos 5 PAM module.
13089@end defvr
13090
13091@deftp {Data Type} pam-krb5-configuration
13092Data type representing the configuration of the Kerberos 5 PAM module
13093This type has the following parameters:
13094@table @asis
13095@item @code{pam-krb5} (default: @code{pam-krb5})
13096The pam-krb5 package to use.
13097
13098@item @code{minimum-uid} (default: @code{1000})
13099The smallest user ID for which Kerberos authentications should be attempted.
13100Local accounts with lower values will silently fail to authenticate.
13101@end table
13102@end deftp
13103
13104
58724c48
DT
13105@node Web Services
13106@subsubsection Web Services
13107
e32171ee
JD
13108@cindex web
13109@cindex www
13110@cindex HTTP
58724c48
DT
13111The @code{(gnu services web)} module provides the following service:
13112
be1c2c54 13113@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
58724c48
DT
13114 [#:log-directory ``/var/log/nginx''] @
13115 [#:run-directory ``/var/run/nginx''] @
d338237d 13116 [#:server-list '()] @
cb341293 13117 [#:upstream-list '()] @
d338237d 13118 [#:config-file @code{#f}]
58724c48
DT
13119
13120Return a service that runs @var{nginx}, the nginx web server.
13121
13122The nginx daemon loads its runtime configuration from @var{config-file}.
13123Log files are written to @var{log-directory} and temporary runtime data
13124files are written to @var{run-directory}. For proper operation, these
13125arguments should match what is in @var{config-file} to ensure that the
13126directories are created when the service is activated.
13127
3b9b12ef 13128As an alternative to using a @var{config-file}, @var{server-list} can be
cb341293
CB
13129used to specify the list of @dfn{server blocks} required on the host and
13130@var{upstream-list} can be used to specify a list of @dfn{upstream
13131blocks} to configure. For this to work, use the default value for
13132@var{config-file}.
8c00b838 13133
58724c48
DT
13134@end deffn
13135
d338237d
JL
13136@deffn {Scheme Variable} nginx-service-type
13137This is type for the nginx web server.
13138
13139This service can be extended to add server blocks in addition to the
13140default one, as in this example:
13141
13142@example
13143(simple-service 'my-extra-server nginx-service-type
13144 (list (nginx-server-configuration
13145 (https-port #f)
13146 (root "/srv/http/extra-website"))))
13147@end example
13148@end deffn
13149
3b9b12ef
JL
13150@deftp {Data Type} nginx-server-configuration
13151Data type representing the configuration of an nginx server block.
8c00b838
JL
13152This type has the following parameters:
13153
13154@table @asis
13155@item @code{http-port} (default: @code{80})
13156Nginx will listen for HTTP connection on this port. Set it at @code{#f} if
13157nginx should not listen for HTTP (non secure) connection for this
3b9b12ef 13158@dfn{server block}.
8c00b838
JL
13159
13160@item @code{https-port} (default: @code{443})
13161Nginx will listen for HTTPS connection on this port. Set it at @code{#f} if
3b9b12ef 13162nginx should not listen for HTTPS (secure) connection for this @dfn{server block}.
8c00b838
JL
13163
13164Note that nginx can listen for HTTP and HTTPS connections in the same
3b9b12ef 13165@dfn{server block}.
8c00b838
JL
13166
13167@item @code{server-name} (default: @code{(list 'default)})
3b9b12ef
JL
13168A list of server names this server represents. @code{'default} represents the
13169default server for connections matching no other server.
8c00b838
JL
13170
13171@item @code{root} (default: @code{"/srv/http"})
13172Root of the website nginx will serve.
13173
9c557a69
CB
13174@item @code{locations} (default: @code{'()})
13175A list of @dfn{nginx-location-configuration} or
13176@dfn{nginx-named-location-configuration} records to use within this
13177server block.
13178
8c00b838
JL
13179@item @code{index} (default: @code{(list "index.html")})
13180Index files to look for when clients ask for a directory. If it cannot be found,
13181Nginx will send the list of files in the directory.
13182
13183@item @code{ssl-certificate} (default: @code{"/etc/nginx/cert.pem"})
13184Where to find the certificate for secure connections. Set it to @code{#f} if
13185you don't have a certificate or you don't want to use HTTPS.
13186
13187@item @code{ssl-certificate-key} (default: @code{"/etc/nginx/key.pem"})
13188Where to find the private key for secure connections. Set it to @code{#f} if
13189you don't have a key or you don't want to use HTTPS.
13190
13191@item @code{server-tokens?} (default: @code{#f})
13192Whether the server should add its configuration to response.
13193
13194@end table
13195@end deftp
13196
2be1b471
JL
13197@node VPN Services
13198@subsubsection VPN Services
13199@cindex VPN (virtual private network)
13200@cindex virtual private network (VPN)
13201
13202The @code{(gnu services vpn)} module provides services related to
13203@dfn{virtual private networks} (VPNs). It provides a @emph{client} service for
13204your machine to connect to a VPN, and a @emph{servire} service for your machine
13205to host a VPN. Both services use @uref{https://openvpn.net/, OpenVPN}.
13206
13207@deffn {Scheme Procedure} openvpn-client-service @
13208 [#:config (openvpn-client-configuration)]
13209
13210Return a service that runs @command{openvpn}, a VPN daemon, as a client.
13211@end deffn
13212
13213@deffn {Scheme Procedure} openvpn-server-service @
13214 [#:config (openvpn-server-configuration)]
13215
13216Return a service that runs @command{openvpn}, a VPN daemon, as a server.
13217
13218Both can be run simultaneously.
13219@end deffn
13220
13221@c %automatically generated documentation
13222
13223Available @code{openvpn-client-configuration} fields are:
13224
1c17a863 13225@deftypevr {@code{openvpn-client-configuration} parameter} package openvpn
2be1b471
JL
13226The OpenVPN package.
13227
13228@end deftypevr
13229
1c17a863 13230@deftypevr {@code{openvpn-client-configuration} parameter} string pid-file
2be1b471
JL
13231The OpenVPN pid file.
13232
13233Defaults to @samp{"/var/run/openvpn/openvpn.pid"}.
13234
13235@end deftypevr
13236
1c17a863 13237@deftypevr {@code{openvpn-client-configuration} parameter} proto proto
2be1b471
JL
13238The protocol (UDP or TCP) used to open a channel between clients and
13239servers.
13240
13241Defaults to @samp{udp}.
13242
13243@end deftypevr
13244
1c17a863 13245@deftypevr {@code{openvpn-client-configuration} parameter} dev dev
2be1b471
JL
13246The device type used to represent the VPN connection.
13247
13248Defaults to @samp{tun}.
13249
13250@end deftypevr
13251
1c17a863 13252@deftypevr {@code{openvpn-client-configuration} parameter} string ca
2be1b471
JL
13253The certificate authority to check connections against.
13254
13255Defaults to @samp{"/etc/openvpn/ca.crt"}.
13256
13257@end deftypevr
13258
1c17a863 13259@deftypevr {@code{openvpn-client-configuration} parameter} string cert
2be1b471
JL
13260The certificate of the machine the daemon is running on. It should be
13261signed by the authority given in @code{ca}.
13262
13263Defaults to @samp{"/etc/openvpn/client.crt"}.
13264
13265@end deftypevr
13266
1c17a863 13267@deftypevr {@code{openvpn-client-configuration} parameter} string key
2be1b471
JL
13268The key of the machine the daemon is running on. It must be the key whose
13269certificate is @code{cert}.
13270
13271Defaults to @samp{"/etc/openvpn/client.key"}.
13272
13273@end deftypevr
13274
1c17a863 13275@deftypevr {@code{openvpn-client-configuration} parameter} boolean comp-lzo?
2be1b471
JL
13276Whether to use the lzo compression algorithm.
13277
13278Defaults to @samp{#t}.
13279
13280@end deftypevr
13281
1c17a863 13282@deftypevr {@code{openvpn-client-configuration} parameter} boolean persist-key?
2be1b471
JL
13283Don't re-read key files across SIGUSR1 or --ping-restart.
13284
13285Defaults to @samp{#t}.
13286
13287@end deftypevr
13288
1c17a863 13289@deftypevr {@code{openvpn-client-configuration} parameter} boolean persist-tun?
2be1b471
JL
13290Don't close and reopen TUN/TAP device or run up/down scripts across
13291SIGUSR1 or --ping-restart restarts.
13292
13293Defaults to @samp{#t}.
13294
13295@end deftypevr
13296
1c17a863 13297@deftypevr {@code{openvpn-client-configuration} parameter} number verbosity
2be1b471
JL
13298Verbosity level.
13299
13300Defaults to @samp{3}.
13301
13302@end deftypevr
13303
1c17a863 13304@deftypevr {@code{openvpn-client-configuration} parameter} tls-auth-client tls-auth
2be1b471
JL
13305Add an additional layer of HMAC authentication on top of the TLS control
13306channel to protect against DoS attacks.
13307
13308Defaults to @samp{#f}.
13309
13310@end deftypevr
13311
1c17a863 13312@deftypevr {@code{openvpn-client-configuration} parameter} key-usage verify-key-usage?
2be1b471
JL
13313Whether to check the server certificate has server usage extension.
13314
13315Defaults to @samp{#t}.
13316
13317@end deftypevr
13318
1c17a863 13319@deftypevr {@code{openvpn-client-configuration} parameter} bind bind?
2be1b471
JL
13320Bind to a specific local port number.
13321
13322Defaults to @samp{#f}.
13323
13324@end deftypevr
13325
1c17a863 13326@deftypevr {@code{openvpn-client-configuration} parameter} resolv-retry resolv-retry?
2be1b471
JL
13327Retry resolving server address.
13328
13329Defaults to @samp{#t}.
13330
13331@end deftypevr
13332
1c17a863 13333@deftypevr {@code{openvpn-client-configuration} parameter} openvpn-remote-list remote
2be1b471
JL
13334A list of remote servers to connect to.
13335
13336Defaults to @samp{()}.
13337
13338Available @code{openvpn-remote-configuration} fields are:
13339
1c17a863 13340@deftypevr {@code{openvpn-remote-configuration} parameter} string name
2be1b471
JL
13341Server name.
13342
13343Defaults to @samp{"my-server"}.
13344
13345@end deftypevr
13346
1c17a863 13347@deftypevr {@code{openvpn-remote-configuration} parameter} number port
2be1b471
JL
13348Port number the server listens to.
13349
13350Defaults to @samp{1194}.
13351
13352@end deftypevr
13353
13354@end deftypevr
13355@c %end of automatic openvpn-client documentation
13356
13357@c %automatically generated documentation
13358
13359Available @code{openvpn-server-configuration} fields are:
13360
1c17a863 13361@deftypevr {@code{openvpn-server-configuration} parameter} package openvpn
2be1b471
JL
13362The OpenVPN package.
13363
13364@end deftypevr
13365
1c17a863 13366@deftypevr {@code{openvpn-server-configuration} parameter} string pid-file
2be1b471
JL
13367The OpenVPN pid file.
13368
13369Defaults to @samp{"/var/run/openvpn/openvpn.pid"}.
13370
13371@end deftypevr
13372
1c17a863 13373@deftypevr {@code{openvpn-server-configuration} parameter} proto proto
2be1b471
JL
13374The protocol (UDP or TCP) used to open a channel between clients and
13375servers.
13376
13377Defaults to @samp{udp}.
13378
13379@end deftypevr
13380
1c17a863 13381@deftypevr {@code{openvpn-server-configuration} parameter} dev dev
2be1b471
JL
13382The device type used to represent the VPN connection.
13383
13384Defaults to @samp{tun}.
13385
13386@end deftypevr
13387
1c17a863 13388@deftypevr {@code{openvpn-server-configuration} parameter} string ca
2be1b471
JL
13389The certificate authority to check connections against.
13390
13391Defaults to @samp{"/etc/openvpn/ca.crt"}.
13392
13393@end deftypevr
13394
1c17a863 13395@deftypevr {@code{openvpn-server-configuration} parameter} string cert
2be1b471
JL
13396The certificate of the machine the daemon is running on. It should be
13397signed by the authority given in @code{ca}.
13398
13399Defaults to @samp{"/etc/openvpn/client.crt"}.
13400
13401@end deftypevr
13402
1c17a863 13403@deftypevr {@code{openvpn-server-configuration} parameter} string key
2be1b471
JL
13404The key of the machine the daemon is running on. It must be the key whose
13405certificate is @code{cert}.
13406
13407Defaults to @samp{"/etc/openvpn/client.key"}.
13408
13409@end deftypevr
13410
1c17a863 13411@deftypevr {@code{openvpn-server-configuration} parameter} boolean comp-lzo?
2be1b471
JL
13412Whether to use the lzo compression algorithm.
13413
13414Defaults to @samp{#t}.
13415
13416@end deftypevr
13417
1c17a863 13418@deftypevr {@code{openvpn-server-configuration} parameter} boolean persist-key?
2be1b471
JL
13419Don't re-read key files across SIGUSR1 or --ping-restart.
13420
13421Defaults to @samp{#t}.
13422
13423@end deftypevr
13424
1c17a863 13425@deftypevr {@code{openvpn-server-configuration} parameter} boolean persist-tun?
2be1b471
JL
13426Don't close and reopen TUN/TAP device or run up/down scripts across
13427SIGUSR1 or --ping-restart restarts.
13428
13429Defaults to @samp{#t}.
13430
13431@end deftypevr
13432
1c17a863 13433@deftypevr {@code{openvpn-server-configuration} parameter} number verbosity
2be1b471
JL
13434Verbosity level.
13435
13436Defaults to @samp{3}.
13437
13438@end deftypevr
13439
1c17a863 13440@deftypevr {@code{openvpn-server-configuration} parameter} tls-auth-server tls-auth
2be1b471
JL
13441Add an additional layer of HMAC authentication on top of the TLS control
13442channel to protect against DoS attacks.
13443
13444Defaults to @samp{#f}.
13445
13446@end deftypevr
13447
1c17a863 13448@deftypevr {@code{openvpn-server-configuration} parameter} number port
2be1b471
JL
13449Specifies the port number on which the server listens.
13450
13451Defaults to @samp{1194}.
13452
13453@end deftypevr
13454
1c17a863 13455@deftypevr {@code{openvpn-server-configuration} parameter} ip-mask server
2be1b471
JL
13456An ip and mask specifying the subnet inside the virtual network.
13457
13458Defaults to @samp{"10.8.0.0 255.255.255.0"}.
13459
13460@end deftypevr
13461
1c17a863 13462@deftypevr {@code{openvpn-server-configuration} parameter} cidr6 server-ipv6
2be1b471
JL
13463A CIDR notation specifying the IPv6 subnet inside the virtual network.
13464
13465Defaults to @samp{#f}.
13466
13467@end deftypevr
13468
1c17a863 13469@deftypevr {@code{openvpn-server-configuration} parameter} string dh
2be1b471
JL
13470The Diffie-Hellman parameters file.
13471
13472Defaults to @samp{"/etc/openvpn/dh2048.pem"}.
13473
13474@end deftypevr
13475
1c17a863 13476@deftypevr {@code{openvpn-server-configuration} parameter} string ifconfig-pool-persist
2be1b471
JL
13477The file that records client IPs.
13478
13479Defaults to @samp{"/etc/openvpn/ipp.txt"}.
13480
13481@end deftypevr
13482
1c17a863 13483@deftypevr {@code{openvpn-server-configuration} parameter} gateway redirect-gateway?
2be1b471
JL
13484When true, the server will act as a gateway for its clients.
13485
13486Defaults to @samp{#f}.
13487
13488@end deftypevr
13489
1c17a863 13490@deftypevr {@code{openvpn-server-configuration} parameter} boolean client-to-client?
9fc221b5 13491When true, clients are allowed to talk to each other inside the VPN.
2be1b471
JL
13492
13493Defaults to @samp{#f}.
13494
13495@end deftypevr
13496
1c17a863 13497@deftypevr {@code{openvpn-server-configuration} parameter} keepalive keepalive
2be1b471
JL
13498Causes ping-like messages to be sent back and forth over the link so
13499that each side knows when the other side has gone down. @code{keepalive}
13500requires a pair. The first element is the period of the ping sending,
13501and the second element is the timeout before considering the other side
13502down.
13503
13504@end deftypevr
13505
1c17a863 13506@deftypevr {@code{openvpn-server-configuration} parameter} number max-clients
2be1b471
JL
13507The maximum number of clients.
13508
13509Defaults to @samp{100}.
13510
13511@end deftypevr
13512
1c17a863 13513@deftypevr {@code{openvpn-server-configuration} parameter} string status
2be1b471 13514The status file. This file shows a small report on current connection.
9fc221b5 13515It is truncated and rewritten every minute.
2be1b471
JL
13516
13517Defaults to @samp{"/var/run/openvpn/status"}.
13518
13519@end deftypevr
13520
1c17a863 13521@deftypevr {@code{openvpn-server-configuration} parameter} openvpn-ccd-list client-config-dir
2be1b471
JL
13522The list of configuration for some clients.
13523
13524Defaults to @samp{()}.
13525
13526Available @code{openvpn-ccd-configuration} fields are:
13527
1c17a863 13528@deftypevr {@code{openvpn-ccd-configuration} parameter} string name
2be1b471
JL
13529Client name.
13530
13531Defaults to @samp{"client"}.
13532
13533@end deftypevr
13534
1c17a863 13535@deftypevr {@code{openvpn-ccd-configuration} parameter} ip-mask iroute
2be1b471
JL
13536Client own network
13537
13538Defaults to @samp{#f}.
13539
13540@end deftypevr
13541
1c17a863 13542@deftypevr {@code{openvpn-ccd-configuration} parameter} ip-mask ifconfig-push
2be1b471
JL
13543Client VPN IP.
13544
13545Defaults to @samp{#f}.
13546
13547@end deftypevr
13548
13549@end deftypevr
13550
13551
13552@c %end of automatic openvpn-server documentation
13553
13554
cb341293
CB
13555@deftp {Data Type} nginx-upstream-configuration
13556Data type representing the configuration of an nginx @code{upstream}
13557block. This type has the following parameters:
13558
13559@table @asis
13560@item @code{name}
13561Name for this group of servers.
13562
13563@item @code{servers}
13564Specify the addresses of the servers in the group. The address can be
13565specified as a IP address (e.g. @samp{127.0.0.1}), domain name
13566(e.g. @samp{backend1.example.com}) or a path to a UNIX socket using the
13567prefix @samp{unix:}. For addresses using an IP address or domain name,
13568the default port is 80, and a different port can be specified
13569explicitly.
13570
13571@end table
13572@end deftp
13573
9c557a69
CB
13574@deftp {Data Type} nginx-location-configuration
13575Data type representing the configuration of an nginx @code{location}
13576block. This type has the following parameters:
13577
13578@table @asis
13579@item @code{uri}
13580URI which this location block matches.
13581
13582@anchor{nginx-location-configuration body}
13583@item @code{body}
13584Body of the location block, specified as a string. This can contain many
13585configuration directives. For example, to pass requests to a upstream
13586server group defined using an @code{nginx-upstream-configuration} block,
13587the following directive would be specified in the body @samp{proxy_pass
13588http://upstream-name;}.
13589
13590@end table
13591@end deftp
13592
13593@deftp {Data Type} nginx-named-location-configuration
13594Data type representing the configuration of an nginx named location
13595block. Named location blocks are used for request redirection, and not
13596used for regular request processing. This type has the following
13597parameters:
13598
13599@table @asis
13600@item @code{name}
13601Name to identify this location block.
13602
13603@item @code{body}
13604@xref{nginx-location-configuration body}, as the body for named location
13605blocks can be used in a similar way to the
13606@code{nginx-location-configuration body}. One restriction is that the
13607body of a named location block cannot contain location blocks.
13608
13609@end table
13610@end deftp
13611
eb419bc9
JD
13612@node Network File System
13613@subsubsection Network File System
13614@cindex NFS
fe1a39d3 13615
eb419bc9
JD
13616The @code{(gnu services nfs)} module provides the following services,
13617which are most commonly used in relation to mounting or exporting
13618directory trees as @dfn{network file systems} (NFS).
d6a07ee6
JD
13619
13620@subsubheading RPC Bind Service
13621@cindex rpcbind
13622
eb419bc9
JD
13623The RPC Bind service provides a facility to map program numbers into
13624universal addresses.
13625Many NFS related services use this facility. Hence it is automatically
13626started when a dependent service starts.
d6a07ee6
JD
13627
13628@defvr {Scheme Variable} rpcbind-service-type
13629A service type for the RPC portmapper daemon.
13630@end defvr
13631
13632
13633@deftp {Data Type} rpcbind-configuration
13634Data type representing the configuration of the RPC Bind Service.
13635This type has the following parameters:
13636@table @asis
13637@item @code{rpcbind} (default: @code{rpcbind})
13638The rpcbind package to use.
13639
13640@item @code{warm-start?} (default: @code{#t})
13641If this parameter is @code{#t}, then the daemon will read a
13642state file on startup thus reloading state information saved by a previous
13643instance.
13644@end table
13645@end deftp
13646
eb419bc9
JD
13647
13648@subsubheading Pipefs Pseudo File System
13649@cindex pipefs
13650@cindex rpc_pipefs
13651
13652The pipefs file system is used to transfer NFS related data
13653between the kernel and user space programs.
13654
13655@defvr {Scheme Variable} pipefs-service-type
13656A service type for the pipefs pseudo file system.
13657@end defvr
13658
13659@deftp {Data Type} pipefs-configuration
13660Data type representing the configuration of the pipefs pseudo file system service.
13661This type has the following parameters:
13662@table @asis
13663@item @code{mount-point} (default: @code{"/var/lib/nfs/rpc_pipefs"})
13664The directory to which the file system is to be attached.
13665@end table
13666@end deftp
13667
13668
13669@subsubheading GSS Daemon Service
13670@cindex GSSD
13671@cindex GSS
13672@cindex global security system
13673
13674The @dfn{global security system} (GSS) daemon provides strong security for RPC
13675based protocols.
13676Before exchanging RPC requests an RPC client must establish a security
13677context. Typically this is done using the Kerberos command @command{kinit}
859e367d 13678or automatically at login time using PAM services (@pxref{Kerberos Services}).
eb419bc9
JD
13679
13680@defvr {Scheme Variable} gss-service-type
13681A service type for the Global Security System (GSS) daemon.
13682@end defvr
13683
13684@deftp {Data Type} gss-configuration
13685Data type representing the configuration of the GSS daemon service.
13686This type has the following parameters:
13687@table @asis
13688@item @code{nfs-utils} (default: @code{nfs-utils})
13689The package in which the @command{rpc.gssd} command is to be found.
13690
13691@item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
13692The directory where the pipefs file system is mounted.
13693
13694@end table
13695@end deftp
13696
13697
13698@subsubheading IDMAP Daemon Service
13699@cindex idmapd
13700@cindex name mapper
13701
13702The idmap daemon service provides mapping between user IDs and user names.
13703Typically it is required in order to access file systems mounted via NFSv4.
13704
13705@defvr {Scheme Variable} idmap-service-type
13706A service type for the Identity Mapper (IDMAP) daemon.
13707@end defvr
13708
13709@deftp {Data Type} idmap-configuration
13710Data type representing the configuration of the IDMAP daemon service.
13711This type has the following parameters:
13712@table @asis
13713@item @code{nfs-utils} (default: @code{nfs-utils})
13714The package in which the @command{rpc.idmapd} command is to be found.
13715
13716@item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
13717The directory where the pipefs file system is mounted.
13718
13719@item @code{domain} (default: @code{#f})
13720The local NFSv4 domain name.
13721This must be a string or @code{#f}.
13722If it is @code{#f} then the daemon will use the host's fully qualified domain name.
13723
13724@end table
13725@end deftp
13726
a7cf4eb6
ML
13727@node Continuous Integration
13728@subsubsection Continuous Integration
13729
13730@cindex continuous integration
13731@uref{https://notabug.org/mthl/cuirass, Cuirass} is a continuous
13732integration tool for Guix. It can be used both for development and for
13733providing substitutes to others (@pxref{Substitutes}).
13734
13735The @code{(gnu services cuirass)} module provides the following service.
13736
231eddc8
LC
13737@defvr {Scheme Procedure} cuirass-service-type
13738The type of the Cuirass service. Its value must be a
13739@code{cuirass-configuration} object, as described below.
13740@end defvr
a7cf4eb6 13741
231eddc8
LC
13742To add build jobs, you have to set the @code{specifications} field of
13743the configuration. Here is an example of a service defining a build job
13744based on a specification that can be found in Cuirass source tree. This
13745service polls the Guix repository and builds a subset of the Guix
13746packages, as prescribed in the @file{gnu-system.scm} example spec:
a7cf4eb6
ML
13747
13748@example
8de938d5
LC
13749(let ((spec #~((#:name . "guix")
13750 (#:url . "git://git.savannah.gnu.org/guix.git")
13751 (#:load-path . ".")
13752
13753 ;; Here we must provide an absolute file name.
13754 ;; We take jobs from one of the examples provided
13755 ;; by Cuirass.
13756 (#:file . #$(file-append
13757 cuirass
13758 "/tests/gnu-system.scm"))
13759
13760 (#:proc . hydra-jobs)
13761 (#:arguments (subset . "hello"))
13762 (#:branch . "master"))))
231eddc8
LC
13763 (service cuirass-service-type
13764 (cuirass-configuration
13765 (specifications #~(list #$spec)))))
a7cf4eb6
ML
13766@end example
13767
231eddc8 13768While information related to build jobs is located directly in the
a7cf4eb6
ML
13769specifications, global settings for the @command{cuirass} process are
13770accessible in other @code{cuirass-configuration} fields.
13771
13772@deftp {Data Type} cuirass-configuration
13773Data type representing the configuration of Cuirass.
13774
13775@table @asis
b17e326f
LC
13776@item @code{log-file} (default: @code{"/var/log/cuirass.log"})
13777Location of the log file.
13778
463995da 13779@item @code{cache-directory} (default: @code{"/var/cache/cuirass"})
a7cf4eb6
ML
13780Location of the repository cache.
13781
13782@item @code{user} (default: @code{"cuirass"})
13783Owner of the @code{cuirass} process.
13784
13785@item @code{group} (default: @code{"cuirass"})
13786Owner's group of the @code{cuirass} process.
13787
13788@item @code{interval} (default: @code{60})
13789Number of seconds between the poll of the repositories followed by the
13790Cuirass jobs.
13791
13792@item @code{database} (default: @code{"/var/run/cuirass/cuirass.db"})
13793Location of sqlite database which contains the build results and previously
13794added specifications.
13795
11b7717d
MO
13796@item @code{port} (default: @code{8080})
13797Port number used by the HTTP server.
13798
8de938d5
LC
13799@item @code{specifications} (default: @code{#~'()})
13800A gexp (@pxref{G-Expressions}) that evaluates to a list of specifications,
13801where a specification is an association list
a7cf4eb6
ML
13802(@pxref{Associations Lists,,, guile, GNU Guile Reference Manual}) whose
13803keys are keywords (@code{#:keyword-example}) as shown in the example
13804above.
13805
13806@item @code{use-substitutes?} (default: @code{#f})
13807This allows using substitutes to avoid building every dependencies of a job
13808from source.
13809
13810@item @code{one-shot?} (default: @code{#f})
13811Only evaluate specifications and build derivations once.
379b6ba5 13812
eb122280
MO
13813@item @code{load-path} (default: @code{'()})
13814This allows users to define their own packages and make them visible to
13815cuirass as in @command{guix build} command.
13816
379b6ba5
LC
13817@item @code{cuirass} (default: @code{cuirass})
13818The Cuirass package to use.
a7cf4eb6
ML
13819@end table
13820@end deftp
eb419bc9 13821
bfbf6e1e
MO
13822@node Power management Services
13823@subsubsection Power management Services
13824
13825@cindex power management with TLP
13826The @code{(gnu services pm)} module provides a Guix service definition
13827for the Linux power management tool TLP.
13828
13829TLP enables various powersaving modes in userspace and kernel.
13830Contrary to @code{upower-service}, it is not a passive,
13831monitoring tool, as it will apply custom settings each time a new power
13832source is detected. More information can be found at
13833@uref{http://linrunner.de/en/tlp/tlp.html, TLP home page}.
13834
13835@deffn {Scheme Variable} tlp-service-type
13836The service type for the TLP tool. Its value should be a valid
13837TLP configuration (see below). For example:
13838@example
13839(service tlp-service-type (tlp-configuration))
13840@end example
13841@end deffn
13842
13843By default TLP does not need much configuration but most TLP parameters
13844can be tweaked using @code{tlp-configuration}.
13845
13846Each parameter definition is preceded by its type; for example,
13847@samp{boolean foo} indicates that the @code{foo} parameter
13848should be specified as a boolean. Types starting with
13849@code{maybe-} denote parameters that won't show up in TLP config file
13850when their value is @code{'disabled}.
13851
13852@c The following documentation was initially generated by
13853@c (generate-tlp-documentation) in (gnu services pm). Manually maintained
13854@c documentation is better, so we shouldn't hesitate to edit below as
13855@c needed. However if the change you want to make to this documentation
13856@c can be done in an automated way, it's probably easier to change
13857@c (generate-documentation) than to make it below and have to deal with
13858@c the churn as TLP updates.
13859
13860Available @code{tlp-configuration} fields are:
13861
13862@deftypevr {@code{tlp-configuration} parameter} package tlp
13863The TLP package.
13864
13865@end deftypevr
13866
13867@deftypevr {@code{tlp-configuration} parameter} boolean tlp-enable?
13868Set to true if you wish to enable TLP.
13869
13870Defaults to @samp{#t}.
13871
13872@end deftypevr
13873
13874@deftypevr {@code{tlp-configuration} parameter} string tlp-default-mode
13875Default mode when no power supply can be detected. Alternatives are AC
13876and BAT.
13877
13878Defaults to @samp{"AC"}.
13879
13880@end deftypevr
13881
13882@deftypevr {@code{tlp-configuration} parameter} non-negative-integer disk-idle-secs-on-ac
13883Number of seconds Linux kernel has to wait after the disk goes idle,
13884before syncing on AC.
13885
13886Defaults to @samp{0}.
13887
13888@end deftypevr
13889
13890@deftypevr {@code{tlp-configuration} parameter} non-negative-integer disk-idle-secs-on-bat
13891Same as @code{disk-idle-ac} but on BAT mode.
13892
13893Defaults to @samp{2}.
13894
13895@end deftypevr
13896
13897@deftypevr {@code{tlp-configuration} parameter} non-negative-integer max-lost-work-secs-on-ac
13898Dirty pages flushing periodicity, expressed in seconds.
13899
13900Defaults to @samp{15}.
13901
13902@end deftypevr
13903
13904@deftypevr {@code{tlp-configuration} parameter} non-negative-integer max-lost-work-secs-on-bat
13905Same as @code{max-lost-work-secs-on-ac} but on BAT mode.
13906
13907Defaults to @samp{60}.
13908
13909@end deftypevr
13910
13911@deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list cpu-scaling-governor-on-ac
13912CPU frequency scaling governor on AC mode. With intel_pstate driver,
13913alternatives are powersave and performance. With acpi-cpufreq driver,
13914alternatives are ondemand, powersave, performance and conservative.
13915
13916Defaults to @samp{disabled}.
13917
13918@end deftypevr
13919
13920@deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list cpu-scaling-governor-on-bat
13921Same as @code{cpu-scaling-governor-on-ac} but on BAT mode.
13922
13923Defaults to @samp{disabled}.
13924
13925@end deftypevr
13926
13927@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-min-freq-on-ac
13928Set the min available frequency for the scaling governor on AC.
13929
13930Defaults to @samp{disabled}.
13931
13932@end deftypevr
13933
13934@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-max-freq-on-ac
13935Set the max available frequency for the scaling governor on AC.
13936
13937Defaults to @samp{disabled}.
13938
13939@end deftypevr
13940
13941@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-min-freq-on-bat
13942Set the min available frequency for the scaling governor on BAT.
13943
13944Defaults to @samp{disabled}.
13945
13946@end deftypevr
13947
13948@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-max-freq-on-bat
13949Set the max available frequency for the scaling governor on BAT.
13950
13951Defaults to @samp{disabled}.
13952
13953@end deftypevr
13954
13955@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-min-perf-on-ac
13956Limit the min P-state to control the power dissipation of the CPU, in AC
13957mode. Values are stated as a percentage of the available performance.
13958
13959Defaults to @samp{disabled}.
13960
13961@end deftypevr
13962
13963@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-max-perf-on-ac
13964Limit the max P-state to control the power dissipation of the CPU, in AC
13965mode. Values are stated as a percentage of the available performance.
13966
13967Defaults to @samp{disabled}.
13968
13969@end deftypevr
13970
13971@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-min-perf-on-bat
13972Same as @code{cpu-min-perf-on-ac} on BAT mode.
13973
13974Defaults to @samp{disabled}.
13975
13976@end deftypevr
13977
13978@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-max-perf-on-bat
13979Same as @code{cpu-max-perf-on-ac} on BAT mode.
13980
13981Defaults to @samp{disabled}.
13982
13983@end deftypevr
13984
13985@deftypevr {@code{tlp-configuration} parameter} maybe-boolean cpu-boost-on-ac?
13986Enable CPU turbo boost feature on AC mode.
13987
13988Defaults to @samp{disabled}.
13989
13990@end deftypevr
13991
13992@deftypevr {@code{tlp-configuration} parameter} maybe-boolean cpu-boost-on-bat?
13993Same as @code{cpu-boost-on-ac?} on BAT mode.
13994
13995Defaults to @samp{disabled}.
13996
13997@end deftypevr
13998
13999@deftypevr {@code{tlp-configuration} parameter} boolean sched-powersave-on-ac?
14000Allow Linux kernel to minimize the number of CPU cores/hyper-threads
14001used under light load conditions.
14002
14003Defaults to @samp{#f}.
14004
14005@end deftypevr
14006
14007@deftypevr {@code{tlp-configuration} parameter} boolean sched-powersave-on-bat?
14008Same as @code{sched-powersave-on-ac?} but on BAT mode.
14009
14010Defaults to @samp{#t}.
14011
14012@end deftypevr
14013
14014@deftypevr {@code{tlp-configuration} parameter} boolean nmi-watchdog?
14015Enable Linux kernel NMI watchdog.
14016
14017Defaults to @samp{#f}.
14018
14019@end deftypevr
14020
14021@deftypevr {@code{tlp-configuration} parameter} maybe-string phc-controls
14022For Linux kernels with PHC patch applied, change CPU voltages. An
14023example value would be @samp{"F:V F:V F:V F:V"}.
14024
14025Defaults to @samp{disabled}.
14026
14027@end deftypevr
14028
14029@deftypevr {@code{tlp-configuration} parameter} string energy-perf-policy-on-ac
14030Set CPU performance versus energy saving policy on AC. Alternatives are
14031performance, normal, powersave.
14032
14033Defaults to @samp{"performance"}.
14034
14035@end deftypevr
14036
14037@deftypevr {@code{tlp-configuration} parameter} string energy-perf-policy-on-bat
14038Same as @code{energy-perf-policy-ac} but on BAT mode.
14039
14040Defaults to @samp{"powersave"}.
14041
14042@end deftypevr
14043
14044@deftypevr {@code{tlp-configuration} parameter} space-separated-string-list disks-devices
14045Hard disk devices.
14046
14047@end deftypevr
14048
14049@deftypevr {@code{tlp-configuration} parameter} space-separated-string-list disk-apm-level-on-ac
14050Hard disk advanced power management level.
14051
14052@end deftypevr
14053
14054@deftypevr {@code{tlp-configuration} parameter} space-separated-string-list disk-apm-level-on-bat
14055Same as @code{disk-apm-bat} but on BAT mode.
14056
14057@end deftypevr
14058
14059@deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list disk-spindown-timeout-on-ac
14060Hard disk spin down timeout. One value has to be specified for each
14061declared hard disk.
14062
14063Defaults to @samp{disabled}.
14064
14065@end deftypevr
14066
14067@deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list disk-spindown-timeout-on-bat
14068Same as @code{disk-spindown-timeout-on-ac} but on BAT mode.
14069
14070Defaults to @samp{disabled}.
14071
14072@end deftypevr
14073
14074@deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list disk-iosched
14075Select IO scheduler for disk devices. One value has to be specified for
14076each declared hard disk. Example alternatives are cfq, deadline and
14077noop.
14078
14079Defaults to @samp{disabled}.
14080
14081@end deftypevr
14082
14083@deftypevr {@code{tlp-configuration} parameter} string sata-linkpwr-on-ac
14084SATA aggressive link power management (ALPM) level. Alternatives are
14085min_power, medium_power, max_performance.
14086
14087Defaults to @samp{"max_performance"}.
14088
14089@end deftypevr
14090
14091@deftypevr {@code{tlp-configuration} parameter} string sata-linkpwr-on-bat
14092Same as @code{sata-linkpwr-ac} but on BAT mode.
14093
14094Defaults to @samp{"min_power"}.
14095
14096@end deftypevr
14097
14098@deftypevr {@code{tlp-configuration} parameter} maybe-string sata-linkpwr-blacklist
14099Exclude specified SATA host devices for link power management.
14100
14101Defaults to @samp{disabled}.
14102
14103@end deftypevr
14104
14105@deftypevr {@code{tlp-configuration} parameter} maybe-on-off-boolean ahci-runtime-pm-on-ac?
14106Enable Runtime Power Management for AHCI controller and disks on AC
14107mode.
14108
14109Defaults to @samp{disabled}.
14110
14111@end deftypevr
14112
14113@deftypevr {@code{tlp-configuration} parameter} maybe-on-off-boolean ahci-runtime-pm-on-bat?
14114Same as @code{ahci-runtime-pm-on-ac} on BAT mode.
14115
14116Defaults to @samp{disabled}.
14117
14118@end deftypevr
14119
14120@deftypevr {@code{tlp-configuration} parameter} non-negative-integer ahci-runtime-pm-timeout
14121Seconds of inactivity before disk is suspended.
14122
14123Defaults to @samp{15}.
14124
14125@end deftypevr
14126
14127@deftypevr {@code{tlp-configuration} parameter} string pcie-aspm-on-ac
14128PCI Express Active State Power Management level. Alternatives are
14129default, performance, powersave.
14130
14131Defaults to @samp{"performance"}.
14132
14133@end deftypevr
14134
14135@deftypevr {@code{tlp-configuration} parameter} string pcie-aspm-on-bat
14136Same as @code{pcie-aspm-ac} but on BAT mode.
14137
14138Defaults to @samp{"powersave"}.
14139
14140@end deftypevr
14141
14142@deftypevr {@code{tlp-configuration} parameter} string radeon-power-profile-on-ac
14143Radeon graphics clock speed level. Alternatives are low, mid, high,
14144auto, default.
14145
14146Defaults to @samp{"high"}.
14147
14148@end deftypevr
14149
14150@deftypevr {@code{tlp-configuration} parameter} string radeon-power-profile-on-bat
14151Same as @code{radeon-power-ac} but on BAT mode.
14152
14153Defaults to @samp{"low"}.
14154
14155@end deftypevr
14156
14157@deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-state-on-ac
14158Radeon dynamic power management method (DPM). Alternatives are battery,
14159performance.
14160
14161Defaults to @samp{"performance"}.
14162
14163@end deftypevr
14164
14165@deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-state-on-bat
14166Same as @code{radeon-dpm-state-ac} but on BAT mode.
14167
14168Defaults to @samp{"battery"}.
14169
14170@end deftypevr
14171
14172@deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-perf-level-on-ac
14173Radeon DPM performance level. Alternatives are auto, low, high.
14174
14175Defaults to @samp{"auto"}.
14176
14177@end deftypevr
14178
14179@deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-perf-level-on-bat
14180Same as @code{radeon-dpm-perf-ac} but on BAT mode.
14181
14182Defaults to @samp{"auto"}.
14183
14184@end deftypevr
14185
14186@deftypevr {@code{tlp-configuration} parameter} on-off-boolean wifi-pwr-on-ac?
14187Wifi power saving mode.
14188
14189Defaults to @samp{#f}.
14190
14191@end deftypevr
14192
14193@deftypevr {@code{tlp-configuration} parameter} on-off-boolean wifi-pwr-on-bat?
14194Same as @code{wifi-power-ac?} but on BAT mode.
14195
14196Defaults to @samp{#t}.
14197
14198@end deftypevr
14199
14200@deftypevr {@code{tlp-configuration} parameter} y-n-boolean wol-disable?
14201Disable wake on LAN.
14202
14203Defaults to @samp{#t}.
14204
14205@end deftypevr
14206
14207@deftypevr {@code{tlp-configuration} parameter} non-negative-integer sound-power-save-on-ac
14208Timeout duration in seconds before activating audio power saving on
14209Intel HDA and AC97 devices. A value of 0 disables power saving.
14210
14211Defaults to @samp{0}.
14212
14213@end deftypevr
14214
14215@deftypevr {@code{tlp-configuration} parameter} non-negative-integer sound-power-save-on-bat
14216Same as @code{sound-powersave-ac} but on BAT mode.
14217
14218Defaults to @samp{1}.
14219
14220@end deftypevr
14221
14222@deftypevr {@code{tlp-configuration} parameter} y-n-boolean sound-power-save-controller?
14223Disable controller in powersaving mode on Intel HDA devices.
14224
14225Defaults to @samp{#t}.
14226
14227@end deftypevr
14228
14229@deftypevr {@code{tlp-configuration} parameter} boolean bay-poweroff-on-bat?
14230Enable optical drive in UltraBay/MediaBay on BAT mode. Drive can be
14231powered on again by releasing (and reinserting) the eject lever or by
14232pressing the disc eject button on newer models.
14233
14234Defaults to @samp{#f}.
14235
14236@end deftypevr
14237
14238@deftypevr {@code{tlp-configuration} parameter} string bay-device
14239Name of the optical drive device to power off.
14240
14241Defaults to @samp{"sr0"}.
14242
14243@end deftypevr
14244
14245@deftypevr {@code{tlp-configuration} parameter} string runtime-pm-on-ac
14246Runtime Power Management for PCI(e) bus devices. Alternatives are on
14247and auto.
14248
14249Defaults to @samp{"on"}.
14250
14251@end deftypevr
14252
14253@deftypevr {@code{tlp-configuration} parameter} string runtime-pm-on-bat
14254Same as @code{runtime-pm-ac} but on BAT mode.
14255
14256Defaults to @samp{"auto"}.
14257
14258@end deftypevr
14259
14260@deftypevr {@code{tlp-configuration} parameter} boolean runtime-pm-all?
14261Runtime Power Management for all PCI(e) bus devices, except blacklisted
14262ones.
14263
14264Defaults to @samp{#t}.
14265
14266@end deftypevr
14267
14268@deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list runtime-pm-blacklist
9fc221b5 14269Exclude specified PCI(e) device addresses from Runtime Power Management.
bfbf6e1e
MO
14270
14271Defaults to @samp{disabled}.
14272
14273@end deftypevr
14274
14275@deftypevr {@code{tlp-configuration} parameter} space-separated-string-list runtime-pm-driver-blacklist
14276Exclude PCI(e) devices assigned to the specified drivers from Runtime
14277Power Management.
14278
14279@end deftypevr
14280
14281@deftypevr {@code{tlp-configuration} parameter} boolean usb-autosuspend?
14282Enable USB autosuspend feature.
14283
14284Defaults to @samp{#t}.
14285
14286@end deftypevr
14287
14288@deftypevr {@code{tlp-configuration} parameter} maybe-string usb-blacklist
14289Exclude specified devices from USB autosuspend.
14290
14291Defaults to @samp{disabled}.
14292
14293@end deftypevr
14294
14295@deftypevr {@code{tlp-configuration} parameter} boolean usb-blacklist-wwan?
14296Exclude WWAN devices from USB autosuspend.
14297
14298Defaults to @samp{#t}.
14299
14300@end deftypevr
14301
14302@deftypevr {@code{tlp-configuration} parameter} maybe-string usb-whitelist
14303Include specified devices into USB autosuspend, even if they are already
14304excluded by the driver or via @code{usb-blacklist-wwan?}.
14305
14306Defaults to @samp{disabled}.
14307
14308@end deftypevr
14309
14310@deftypevr {@code{tlp-configuration} parameter} maybe-boolean usb-autosuspend-disable-on-shutdown?
14311Enable USB autosuspend before shutdown.
14312
14313Defaults to @samp{disabled}.
14314
14315@end deftypevr
14316
14317@deftypevr {@code{tlp-configuration} parameter} boolean restore-device-state-on-startup?
14318Restore radio device state (bluetooth, wifi, wwan) from previous
14319shutdown on system startup.
14320
14321Defaults to @samp{#f}.
14322
14323@end deftypevr
14324
eb419bc9
JD
14325@node Miscellaneous Services
14326@subsubsection Miscellaneous Services
14327
14328
8ff4dcbe
DC
14329@cindex lirc
14330@subsubheading Lirc Service
14331
fe1a39d3
LC
14332The @code{(gnu services lirc)} module provides the following service.
14333
be1c2c54 14334@deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
fe1a39d3
LC
14335 [#:device #f] [#:driver #f] [#:config-file #f] @
14336 [#:extra-options '()]
14337Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
14338decodes infrared signals from remote controls.
14339
14340Optionally, @var{device}, @var{driver} and @var{config-file}
14341(configuration file name) may be specified. See @command{lircd} manual
14342for details.
14343
14344Finally, @var{extra-options} is a list of additional command-line options
14345passed to @command{lircd}.
14346@end deffn
14347
00f46905
DC
14348@cindex spice
14349@subsubheading Spice Service
14350
14351The @code{(gnu services spice)} module provides the following service.
14352
14353@deffn {Scheme Procedure} spice-vdagent-service [#:spice-vdagent]
14354Returns a service that runs @url{http://www.spice-space.org,VDAGENT}, a daemon
14355that enables sharing the clipboard with a vm and setting the guest display
14356resolution when the graphical console window resizes.
14357@end deffn
14358
c3d38b2b 14359@subsubsection Dictionary Services
e32171ee 14360@cindex dictionary
c3d38b2b
SB
14361The @code{(gnu services dict)} module provides the following service:
14362
14363@deffn {Scheme Procedure} dicod-service [#:config (dicod-configuration)]
14364Return a service that runs the @command{dicod} daemon, an implementation
14365of DICT server (@pxref{Dicod,,, dico, GNU Dico Manual}).
14366
14367The optional @var{config} argument specifies the configuration for
14368@command{dicod}, which should be a @code{<dicod-configuration>} object, by
14369default it serves the GNU Collaborative International Dictonary of English.
14370
14371You can add @command{open localhost} to your @file{~/.dico} file to make
14372@code{localhost} the default server for @command{dico} client
14373(@pxref{Initialization File,,, dico, GNU Dico Manual}).
14374@end deffn
14375
14376@deftp {Data Type} dicod-configuration
14377Data type representing the configuration of dicod.
14378
14379@table @asis
14380@item @code{dico} (default: @var{dico})
14381Package object of the GNU Dico dictionary server.
14382
a1b48465
LC
14383@item @code{interfaces} (default: @var{'("localhost")})
14384This is the list of IP addresses and ports and possibly socket file
14385names to listen to (@pxref{Server Settings, @code{listen} directive,,
14386dico, GNU Dico Manual}).
14387
9af7ecd9
HY
14388@item @code{handlers} (default: @var{'()})
14389List of @code{<dicod-handler>} objects denoting handlers (module instances).
14390
c3d38b2b
SB
14391@item @code{databases} (default: @var{(list %dicod-database:gcide)})
14392List of @code{<dicod-database>} objects denoting dictionaries to be served.
14393@end table
14394@end deftp
14395
9af7ecd9
HY
14396@deftp {Data Type} dicod-handler
14397Data type representing a dictionary handler (module instance).
c3d38b2b
SB
14398
14399@table @asis
14400@item @code{name}
9af7ecd9 14401Name of the handler (module instance).
c3d38b2b 14402
9af7ecd9
HY
14403@item @code{module} (default: @var{#f})
14404Name of the dicod module of the handler (instance). If it is @code{#f},
14405the module has the same name as the handler.
c3d38b2b
SB
14406(@pxref{Modules,,, dico, GNU Dico Manual}).
14407
14408@item @code{options}
14409List of strings or gexps representing the arguments for the module handler
9af7ecd9
HY
14410@end table
14411@end deftp
14412
14413@deftp {Data Type} dicod-database
14414Data type representing a dictionary database.
14415
14416@table @asis
14417@item @code{name}
14418Name of the database, will be used in DICT commands.
14419
14420@item @code{handler}
14421Name of the dicod handler (module instance) used by this database
c3d38b2b 14422(@pxref{Handlers,,, dico, GNU Dico Manual}).
9af7ecd9
HY
14423
14424@item @code{complex?} (default: @var{#f})
14425Whether the database configuration complex. The complex configuration
14426will need a corresponding @code{<dicod-handler>} object, otherwise not.
14427
14428@item @code{options}
14429List of strings or gexps representing the arguments for the database
14430(@pxref{Databases,,, dico, GNU Dico Manual}).
c3d38b2b
SB
14431@end table
14432@end deftp
14433
14434@defvr {Scheme Variable} %dicod-database:gcide
14435A @code{<dicod-database>} object serving the GNU Collaborative International
9fc221b5 14436Dictionary of English using the @code{gcide} package.
c3d38b2b 14437@end defvr
fe1a39d3 14438
9af7ecd9
HY
14439The following is an example @code{dicod-service} configuration.
14440
14441@example
14442(dicod-service #:config
14443 (dicod-configuration
14444 (handlers (list (dicod-handler
14445 (name "wordnet")
14446 (module "dictorg")
14447 (options
14448 (list #~(string-append "dbdir=" #$wordnet))))))
14449 (databases (list (dicod-database
14450 (name "wordnet")
14451 (complex? #t)
14452 (handler "wordnet")
14453 (options '("database=wn")))
14454 %dicod-database:gcide))))
14455@end example
14456
e01e2c6c 14457@subsubsection Version Control
14458
14459The @code{(gnu services version-control)} module provides the following services:
14460
14461@subsubheading Git daemon service
14462
14463@deffn {Scheme Procedure} git-daemon-service [#:config (git-daemon-configuration)]
14464
14465Return a service that runs @command{git daemon}, a simple TCP server to
9fc221b5 14466expose repositories over the Git protocol for anonymous access.
e01e2c6c 14467
14468The optional @var{config} argument should be a
14469@code{<git-daemon-configuration>} object, by default it allows read-only
14470access to exported@footnote{By creating the magic file
14471"git-daemon-export-ok" in the repository directory.} repositories under
14472@file{/srv/git}.
14473
14474@end deffn
14475
14476@deftp {Data Type} git-daemon-configuration
14477Data type representing the configuration for @code{git-daemon-service}.
14478
14479@table @asis
14480@item @code{package} (default: @var{git})
14481Package object of the Git distributed version control system.
14482
14483@item @code{export-all?} (default: @var{#f})
14484Whether to allow access for all Git repositories, even if they do not
14485have the @file{git-daemon-export-ok} file.
14486
14487@item @code{base-path} (default: @file{/srv/git})
14488Whether to remap all the path requests as relative to the given path.
14489If you run git daemon with @var{(base-path "/srv/git")} on example.com,
14490then if you later try to pull @code{git://example.com/hello.git}, git
14491daemon will interpret the path as @code{/srv/git/hello.git}.
14492
14493@item @code{user-path} (default: @var{#f})
14494Whether to allow @code{~user} notation to be used in requests. When
14495specified with empty string, requests to @code{git://host/~alice/foo} is
14496taken as a request to access @code{foo} repository in the home directory
14497of user @code{alice}. If @var{(user-path "path")} is specified, the
14498same request is taken as a request to access @code{path/foo} repository
14499in the home directory of user @code{alice}.
14500
14501@item @code{listen} (default: @var{'()})
14502Whether to listen on specific IP addresses or hostnames, defaults to
14503all.
14504
14505@item @code{port} (default: @var{#f})
14506Whether to listen on an alternative port, which defaults to 9418.
14507
14508@item @code{whitelist} (default: @var{'()})
14509If not empty, only allow access to this list of directories.
14510
14511@item @code{extra-options} (default: @var{'()})
14512Extra options will be passed to @code{git daemon}, please run
14513@command{man git-daemon} for more information.
14514
14515@end table
14516@end deftp
14517
0ae8c15a
LC
14518@node Setuid Programs
14519@subsection Setuid Programs
14520
14521@cindex setuid programs
14522Some programs need to run with ``root'' privileges, even when they are
14523launched by unprivileged users. A notorious example is the
4d40227c
LC
14524@command{passwd} program, which users can run to change their
14525password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
14526@file{/etc/shadow} files---something normally restricted to root, for
14527obvious security reasons. To address that, these executables are
14528@dfn{setuid-root}, meaning that they always run with root privileges
14529(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
f7e4ae7f 14530for more info about the setuid mechanism.)
0ae8c15a
LC
14531
14532The store itself @emph{cannot} contain setuid programs: that would be a
14533security issue since any user on the system can write derivations that
14534populate the store (@pxref{The Store}). Thus, a different mechanism is
14535used: instead of changing the setuid bit directly on files that are in
14536the store, we let the system administrator @emph{declare} which programs
14537should be setuid root.
14538
14539The @code{setuid-programs} field of an @code{operating-system}
14540declaration contains a list of G-expressions denoting the names of
14541programs to be setuid-root (@pxref{Using the Configuration System}).
14542For instance, the @command{passwd} program, which is part of the Shadow
14543package, can be designated by this G-expression (@pxref{G-Expressions}):
14544
14545@example
14546#~(string-append #$shadow "/bin/passwd")
14547@end example
14548
14549A default set of setuid programs is defined by the
14550@code{%setuid-programs} variable of the @code{(gnu system)} module.
14551
14552@defvr {Scheme Variable} %setuid-programs
14553A list of G-expressions denoting common programs that are setuid-root.
14554
14555The list includes commands such as @command{passwd}, @command{ping},
14556@command{su}, and @command{sudo}.
14557@end defvr
14558
14559Under the hood, the actual setuid programs are created in the
14560@file{/run/setuid-programs} directory at system activation time. The
14561files in this directory refer to the ``real'' binaries, which are in the
14562store.
14563
efb5e833
LC
14564@node X.509 Certificates
14565@subsection X.509 Certificates
14566
14567@cindex HTTPS, certificates
14568@cindex X.509 certificates
14569@cindex TLS
14570Web servers available over HTTPS (that is, HTTP over the transport-layer
14571security mechanism, TLS) send client programs an @dfn{X.509 certificate}
14572that the client can then use to @emph{authenticate} the server. To do
14573that, clients verify that the server's certificate is signed by a
14574so-called @dfn{certificate authority} (CA). But to verify the CA's
14575signature, clients must have first acquired the CA's certificate.
14576
14577Web browsers such as GNU@tie{}IceCat include their own set of CA
14578certificates, such that they are able to verify CA signatures
14579out-of-the-box.
14580
14581However, most other programs that can talk HTTPS---@command{wget},
14582@command{git}, @command{w3m}, etc.---need to be told where CA
14583certificates can be found.
14584
14585@cindex @code{nss-certs}
14586In GuixSD, this is done by adding a package that provides certificates
14587to the @code{packages} field of the @code{operating-system} declaration
14588(@pxref{operating-system Reference}). GuixSD includes one such package,
14589@code{nss-certs}, which is a set of CA certificates provided as part of
14590Mozilla's Network Security Services.
14591
14592Note that it is @emph{not} part of @var{%base-packages}, so you need to
14593explicitly add it. The @file{/etc/ssl/certs} directory, which is where
14594most applications and libraries look for certificates by default, points
14595to the certificates installed globally.
14596
b3129f2b
LC
14597Unprivileged users, including users of Guix on a foreign distro,
14598can also install their own certificate package in
efb5e833
LC
14599their profile. A number of environment variables need to be defined so
14600that applications and libraries know where to find them. Namely, the
14601OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
14602variables. Some applications add their own environment variables; for
14603instance, the Git version control system honors the certificate bundle
b3129f2b
LC
14604pointed to by the @code{GIT_SSL_CAINFO} environment variable. Thus, you
14605would typically run something like:
efb5e833 14606
b3129f2b
LC
14607@example
14608$ guix package -i nss-certs
14609$ export SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs"
14610$ export SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt"
14611$ export GIT_SSL_CAINFO="$SSL_CERT_FILE"
14612@end example
efb5e833 14613
996ed739
LC
14614@node Name Service Switch
14615@subsection Name Service Switch
14616
14617@cindex name service switch
14618@cindex NSS
14619The @code{(gnu system nss)} module provides bindings to the
1068f26b 14620configuration file of the libc @dfn{name service switch} or @dfn{NSS}
996ed739
LC
14621(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
14622Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
14623extended with new ``name'' lookup methods for system databases, which
14624includes host names, service names, user accounts, and more (@pxref{Name
14625Service Switch, System Databases and Name Service Switch,, libc, The GNU
14626C Library Reference Manual}).
14627
14628The NSS configuration specifies, for each system database, which lookup
14629method is to be used, and how the various methods are chained
14630together---for instance, under which circumstances NSS should try the
14631next method in the list. The NSS configuration is given in the
14632@code{name-service-switch} field of @code{operating-system} declarations
14633(@pxref{operating-system Reference, @code{name-service-switch}}).
14634
4c9050c6
LC
14635@cindex nss-mdns
14636@cindex .local, host name lookup
996ed739 14637As an example, the declaration below configures the NSS to use the
4c9050c6
LC
14638@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
14639back-end}, which supports host name lookups over multicast DNS (mDNS)
14640for host names ending in @code{.local}:
996ed739
LC
14641
14642@example
14643(name-service-switch
14644 (hosts (list %files ;first, check /etc/hosts
14645
14646 ;; If the above did not succeed, try
14647 ;; with 'mdns_minimal'.
14648 (name-service
14649 (name "mdns_minimal")
14650
14651 ;; 'mdns_minimal' is authoritative for
14652 ;; '.local'. When it returns "not found",
14653 ;; no need to try the next methods.
14654 (reaction (lookup-specification
14655 (not-found => return))))
14656
14657 ;; Then fall back to DNS.
14658 (name-service
14659 (name "dns"))
14660
14661 ;; Finally, try with the "full" 'mdns'.
14662 (name-service
14663 (name "mdns")))))
14664@end example
14665
1068f26b
AE
14666Do not worry: the @code{%mdns-host-lookup-nss} variable (see below)
14667contains this configuration, so you will not have to type it if all you
15137a29
LC
14668want is to have @code{.local} host lookup working.
14669
4c9050c6
LC
14670Note that, in this case, in addition to setting the
14671@code{name-service-switch} of the @code{operating-system} declaration,
cc9c1f39
LC
14672you also need to use @code{avahi-service} (@pxref{Networking Services,
14673@code{avahi-service}}), or @var{%desktop-services}, which includes it
14674(@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
14675to the name service cache daemon (@pxref{Base Services,
14676@code{nscd-service}}).
15137a29
LC
14677
14678For convenience, the following variables provide typical NSS
14679configurations.
14680
14681@defvr {Scheme Variable} %default-nss
14682This is the default name service switch configuration, a
14683@code{name-service-switch} object.
14684@end defvr
14685
14686@defvr {Scheme Variable} %mdns-host-lookup-nss
14687This is the name service switch configuration with support for host name
14688lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
14689@end defvr
4c9050c6 14690
996ed739 14691The reference for name service switch configuration is given below. It
1068f26b 14692is a direct mapping of the configuration file format of the C library , so
996ed739
LC
14693please refer to the C library manual for more information (@pxref{NSS
14694Configuration File,,, libc, The GNU C Library Reference Manual}).
1068f26b 14695Compared to the configuration file format of libc NSS, it has the advantage
996ed739 14696not only of adding this warm parenthetic feel that we like, but also
1068f26b 14697static checks: you will know about syntax errors and typos as soon as you
996ed739
LC
14698run @command{guix system}.
14699
996ed739
LC
14700@deftp {Data Type} name-service-switch
14701
14702This is the data type representation the configuration of libc's name
14703service switch (NSS). Each field below represents one of the supported
14704system databases.
14705
14706@table @code
14707@item aliases
14708@itemx ethers
14709@itemx group
14710@itemx gshadow
14711@itemx hosts
14712@itemx initgroups
14713@itemx netgroup
14714@itemx networks
14715@itemx password
14716@itemx public-key
14717@itemx rpc
14718@itemx services
14719@itemx shadow
14720The system databases handled by the NSS. Each of these fields must be a
1068f26b 14721list of @code{<name-service>} objects (see below).
996ed739
LC
14722@end table
14723@end deftp
14724
14725@deftp {Data Type} name-service
14726
14727This is the data type representing an actual name service and the
14728associated lookup action.
14729
14730@table @code
14731@item name
14732A string denoting the name service (@pxref{Services in the NSS
14733configuration,,, libc, The GNU C Library Reference Manual}).
14734
4aee6e60
LC
14735Note that name services listed here must be visible to nscd. This is
14736achieved by passing the @code{#:name-services} argument to
14737@code{nscd-service} the list of packages providing the needed name
14738services (@pxref{Base Services, @code{nscd-service}}).
14739
996ed739
LC
14740@item reaction
14741An action specified using the @code{lookup-specification} macro
14742(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
14743Reference Manual}). For example:
14744
14745@example
14746(lookup-specification (unavailable => continue)
14747 (success => return))
14748@end example
14749@end table
14750@end deftp
0ae8c15a 14751
fd1b1fa2
LC
14752@node Initial RAM Disk
14753@subsection Initial RAM Disk
14754
e32171ee
JD
14755@cindex initrd
14756@cindex initial RAM disk
fd1b1fa2
LC
14757For bootstrapping purposes, the Linux-Libre kernel is passed an
14758@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
1068f26b 14759root file system as well as an initialization script. The latter is
fd1b1fa2
LC
14760responsible for mounting the real root file system, and for loading any
14761kernel modules that may be needed to achieve that.
14762
14763The @code{initrd} field of an @code{operating-system} declaration allows
14764you to specify which initrd you would like to use. The @code{(gnu
47bdc5a1
MO
14765system linux-initrd)} module provides three ways to build an initrd: the
14766high-level @code{base-initrd} procedure and the low-level
14767@code{raw-initrd} and @code{expression->initrd} procedures.
fd1b1fa2
LC
14768
14769The @code{base-initrd} procedure is intended to cover most common uses.
14770For example, if you want to add a bunch of kernel modules to be loaded
14771at boot time, you can define the @code{initrd} field of the operating
14772system declaration like this:
14773
14774@example
52ac153e 14775(initrd (lambda (file-systems . rest)
027981d6
LC
14776 ;; Create a standard initrd that has modules "foo.ko"
14777 ;; and "bar.ko", as well as their dependencies, in
14778 ;; addition to the modules available by default.
52ac153e 14779 (apply base-initrd file-systems
027981d6 14780 #:extra-modules '("foo" "bar")
52ac153e 14781 rest)))
fd1b1fa2
LC
14782@end example
14783
52ac153e 14784The @code{base-initrd} procedure also handles common use cases that
1068f26b
AE
14785involves using the system as a QEMU guest, or as a ``live'' system with
14786volatile root file system.
fd1b1fa2 14787
47bdc5a1
MO
14788The @code{base-initrd} procedure is built from @code{raw-initrd} procedure.
14789Unlike @code{base-initrd}, @code{raw-initrd} doesn't do anything high-level,
14790such as trying to guess which kernel modules and packages should be included
14791to the initrd. An example use of @code{raw-initrd} is when a user has
14792a custom Linux kernel configuration and default kernel modules included by
14793@code{base-initrd} are not available.
14794
14795The initial RAM disk produced by @code{base-initrd} or @code{raw-initrd}
14796honors several options passed on the Linux kernel command line
14797(that is, arguments passed @i{via} the @code{linux} command of GRUB, or the
4af2fafd 14798@code{-append} option of QEMU), notably:
e90cf6c1
LC
14799
14800@table @code
14801@item --load=@var{boot}
14802Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
14803program, once it has mounted the root file system.
14804
14805GuixSD uses this option to yield control to a boot program that runs the
dd17bc38 14806service activation programs and then spawns the GNU@tie{}Shepherd, the
e90cf6c1
LC
14807initialization system.
14808
14809@item --root=@var{root}
1068f26b 14810Mount @var{root} as the root file system. @var{root} can be a
e90cf6c1
LC
14811device name like @code{/dev/sda1}, a partition label, or a partition
14812UUID.
14813
14814@item --system=@var{system}
14815Have @file{/run/booted-system} and @file{/run/current-system} point to
14816@var{system}.
14817
14818@item modprobe.blacklist=@var{modules}@dots{}
14819@cindex module, black-listing
14820@cindex black list, of kernel modules
14821Instruct the initial RAM disk as well as the @command{modprobe} command
14822(from the kmod package) to refuse to load @var{modules}. @var{modules}
14823must be a comma-separated list of module names---e.g.,
14824@code{usbkbd,9pnet}.
14825
14826@item --repl
14827Start a read-eval-print loop (REPL) from the initial RAM disk before it
14828tries to load kernel modules and to mount the root file system. Our
14829marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
14830love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
14831Manual}, for more information on Guile's REPL.
14832
14833@end table
14834
14835Now that you know all the features that initial RAM disks produced by
47bdc5a1
MO
14836@code{base-initrd} and @code{raw-initrd} provide,
14837here is how to use it and customize it further.
e90cf6c1 14838
e32171ee
JD
14839@cindex initrd
14840@cindex initial RAM disk
47bdc5a1
MO
14841@deffn {Monadic Procedure} raw-initrd @var{file-systems} @
14842 [#:linux-modules '()] [#:mapped-devices '()] @
14843 [#:helper-packages '()] [#:qemu-networking? #f] [#:volatile-root? #f]
14844Return a monadic derivation that builds a raw initrd. @var{file-systems} is
1068f26b 14845a list of file systems to be mounted by the initrd, possibly in addition to
fd1b1fa2 14846the root file system specified on the kernel command line via @code{--root}.
47bdc5a1 14847@var{linux-modules} is a list of kernel modules to be loaded at boot time.
52ac153e
LC
14848@var{mapped-devices} is a list of device mappings to realize before
14849@var{file-systems} are mounted (@pxref{Mapped Devices}).
47bdc5a1
MO
14850@var{helper-packages} is a list of packages to be copied in the initrd. It may
14851include @code{e2fsck/static} or other packages needed by the initrd to check
14852root partition.
fd1b1fa2
LC
14853
14854When @var{qemu-networking?} is true, set up networking with the standard QEMU
1068f26b
AE
14855parameters. When @var{virtio?} is true, load additional modules so that the
14856initrd can be used as a QEMU guest with para-virtualized I/O drivers.
fd1b1fa2
LC
14857
14858When @var{volatile-root?} is true, the root file system is writable but any changes
14859to it are lost.
47bdc5a1
MO
14860@end deffn
14861
14862@deffn {Monadic Procedure} base-initrd @var{file-systems} @
14863 [#:mapped-devices '()] [#:qemu-networking? #f] [#:volatile-root? #f]@
14864 [#:virtio? #t] [#:extra-modules '()]
14865Return a monadic derivation that builds a generic initrd. @var{file-systems} is
14866a list of file systems to be mounted by the initrd like for @code{raw-initrd}.
14867@var{mapped-devices}, @var{qemu-networking?} and @var{volatile-root?}
14868also behaves as in @code{raw-initrd}.
14869
14870When @var{virtio?} is true, load additional modules so that the
14871initrd can be used as a QEMU guest with para-virtualized I/O drivers.
fd1b1fa2
LC
14872
14873The initrd is automatically populated with all the kernel modules necessary
14874for @var{file-systems} and for the given options. However, additional kernel
14875modules can be listed in @var{extra-modules}. They will be added to the initrd, and
14876loaded at boot time in the order in which they appear.
14877@end deffn
14878
14879Needless to say, the initrds we produce and use embed a
14880statically-linked Guile, and the initialization program is a Guile
14881program. That gives a lot of flexibility. The
14882@code{expression->initrd} procedure builds such an initrd, given the
14883program to run in that initrd.
14884
14885@deffn {Monadic Procedure} expression->initrd @var{exp} @
4ee96a79 14886 [#:guile %guile-static-stripped] [#:name "guile-initrd"]
fd1b1fa2
LC
14887Return a derivation that builds a Linux initrd (a gzipped cpio archive)
14888containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
14889upon booting. All the derivations referenced by @var{exp} are
14890automatically copied to the initrd.
fd1b1fa2
LC
14891@end deffn
14892
88faf933
LC
14893@node GRUB Configuration
14894@subsection GRUB Configuration
14895
14896@cindex GRUB
14897@cindex boot loader
14898
14899The operating system uses GNU@tie{}GRUB as its boot loader
14900(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
1068f26b
AE
14901configured using a @code{grub-configuration} declaration. This data type
14902is exported by the @code{(gnu system grub)} module and described below.
88faf933
LC
14903
14904@deftp {Data Type} grub-configuration
14905The type of a GRUB configuration declaration.
14906
14907@table @asis
14908
14909@item @code{device}
14910This is a string denoting the boot device. It must be a device name
14911understood by the @command{grub-install} command, such as
14912@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
14913GNU GRUB Manual}).
14914
14915@item @code{menu-entries} (default: @code{()})
14916A possibly empty list of @code{menu-entry} objects (see below), denoting
14917entries to appear in the GRUB boot menu, in addition to the current
14918system entry and the entry pointing to previous system generations.
14919
14920@item @code{default-entry} (default: @code{0})
1068f26b
AE
14921The index of the default boot menu entry. Index 0 is for the entry of the
14922current system.
88faf933
LC
14923
14924@item @code{timeout} (default: @code{5})
14925The number of seconds to wait for keyboard input before booting. Set to
149260 to boot immediately, and to -1 to wait indefinitely.
14927
14928@item @code{theme} (default: @var{%default-theme})
14929The @code{grub-theme} object describing the theme to use.
9b06f503
LC
14930
14931@item @code{grub} (default: @code{grub})
14932The GRUB package to use.
88faf933
LC
14933@end table
14934
14935@end deftp
14936
44d5f54e
LC
14937@cindex dual boot
14938@cindex boot menu
88faf933
LC
14939Should you want to list additional boot menu entries @i{via} the
14940@code{menu-entries} field above, you will need to create them with the
44d5f54e
LC
14941@code{menu-entry} form. For example, imagine you want to be able to
14942boot another distro (hard to imagine!), you can define a menu entry
14943along these lines:
14944
14945@example
14946(menu-entry
14947 (label "The Other Distro")
14948 (linux "/boot/old/vmlinux-2.6.32")
14949 (linux-arguments '("root=/dev/sda2"))
14950 (initrd "/boot/old/initrd"))
14951@end example
14952
14953Details below.
88faf933
LC
14954
14955@deftp {Data Type} menu-entry
14956The type of an entry in the GRUB boot menu.
14957
14958@table @asis
14959
14960@item @code{label}
35ed9306 14961The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
14962
14963@item @code{linux}
44d5f54e
LC
14964The Linux kernel image to boot, for example:
14965
14966@example
14967(file-append linux-libre "/bzImage")
14968@end example
88faf933 14969
1ef8b72a
CM
14970It is also possible to specify a device explicitly in the file path
14971using GRUB's device naming convention (@pxref{Naming convention,,, grub,
14972GNU GRUB manual}), for example:
14973
14974@example
14975"(hd0,msdos1)/boot/vmlinuz"
14976@end example
14977
14978If the device is specified explicitly as above, then the @code{device}
14979field is ignored entirely.
14980
88faf933
LC
14981@item @code{linux-arguments} (default: @code{()})
14982The list of extra Linux kernel command-line arguments---e.g.,
14983@code{("console=ttyS0")}.
14984
14985@item @code{initrd}
14986A G-Expression or string denoting the file name of the initial RAM disk
14987to use (@pxref{G-Expressions}).
14988
1ef8b72a
CM
14989@item @code{device} (default: @code{#f})
14990The device where the kernel and initrd are to be found---i.e., the GRUB
14991@dfn{root} for this menu entry (@pxref{root,,, grub, GNU GRUB manual}).
14992
14993This may be a file system label (a string), a file system UUID (a
14994bytevector, @pxref{File Systems}), or @code{#f}, in which case GRUB will
14995search the device containing the file specified by the @code{linux}
14996field (@pxref{search,,, grub, GNU GRUB manual}). It must @emph{not} be
14997an OS device name such as @file{/dev/sda1}.
14998
14999@item @code{device-mount-point} (default: @code{"/"})
15000The mount point of the above device on the system. You probably do not
15001need to change the default value. GuixSD uses it to strip the prefix of
15002store file names for systems where @file{/gnu} or @file{/gnu/store} is
15003on a separate partition.
15004
88faf933
LC
15005@end table
15006@end deftp
15007
15008@c FIXME: Write documentation once it's stable.
15009Themes are created using the @code{grub-theme} form, which is not
15010documented yet.
15011
15012@defvr {Scheme Variable} %default-theme
15013This is the default GRUB theme used by the operating system, with a
15014fancy background image displaying the GNU and Guix logos.
15015@end defvr
15016
15017
cf4a9129
LC
15018@node Invoking guix system
15019@subsection Invoking @code{guix system}
0918e64a 15020
1068f26b 15021Once you have written an operating system declaration as seen in the
cf4a9129
LC
15022previous section, it can be @dfn{instantiated} using the @command{guix
15023system} command. The synopsis is:
4af2447e 15024
cf4a9129
LC
15025@example
15026guix system @var{options}@dots{} @var{action} @var{file}
15027@end example
4af2447e 15028
cf4a9129
LC
15029@var{file} must be the name of a file containing an
15030@code{operating-system} declaration. @var{action} specifies how the
a40424bd 15031operating system is instantiated. Currently the following values are
cf4a9129 15032supported:
4af2447e 15033
cf4a9129
LC
15034@table @code
15035@item reconfigure
15036Build the operating system described in @var{file}, activate it, and
8074b330
CM
15037switch to it@footnote{This action (and the related actions
15038@code{switch-generation} and @code{roll-back}) are usable only on
15039systems already running GuixSD.}.
4af2447e 15040
cf4a9129
LC
15041This effects all the configuration specified in @var{file}: user
15042accounts, system services, global package list, setuid programs, etc.
240b57f0
LC
15043The command starts system services specified in @var{file} that are not
15044currently running; if a service is currently running, it does not
1068f26b 15045attempt to upgrade it since this would not be possible without stopping it
240b57f0 15046first.
4af2447e 15047
067a2e2d
CM
15048This command creates a new generation whose number is one greater than
15049the current generation (as reported by @command{guix system
15050list-generations}). If that generation already exists, it will be
15051overwritten. This behavior mirrors that of @command{guix package}
15052(@pxref{Invoking guix package}).
15053
cf4a9129
LC
15054It also adds a GRUB menu entry for the new OS configuration, and moves
15055entries for older configurations to a submenu---unless
15056@option{--no-grub} is passed.
4af2447e 15057
240b57f0 15058@quotation Note
bf2479c7
LC
15059@c The paragraph below refers to the problem discussed at
15060@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
15061It is highly recommended to run @command{guix pull} once before you run
15062@command{guix system reconfigure} for the first time (@pxref{Invoking
15063guix pull}). Failing to do that you would see an older version of Guix
15064once @command{reconfigure} has completed.
240b57f0 15065@end quotation
bf2479c7 15066
8074b330 15067@item switch-generation
e32171ee 15068@cindex generations
8074b330
CM
15069Switch to an existing system generation. This action atomically
15070switches the system profile to the specified system generation. It also
15071rearranges the system's existing GRUB menu entries. It makes the menu
15072entry for the specified system generation the default, and it moves the
15073entries for the other generations to a submenu. The next time the
15074system boots, it will use the specified system generation.
15075
15076The target generation can be specified explicitly by its generation
15077number. For example, the following invocation would switch to system
15078generation 7:
15079
15080@example
15081guix system switch-generation 7
15082@end example
15083
15084The target generation can also be specified relative to the current
15085generation with the form @code{+N} or @code{-N}, where @code{+3} means
15086``3 generations ahead of the current generation,'' and @code{-1} means
15087``1 generation prior to the current generation.'' When specifying a
15088negative value such as @code{-1}, you must precede it with @code{--} to
15089prevent it from being parsed as an option. For example:
15090
15091@example
15092guix system switch-generation -- -1
15093@end example
15094
15095Currently, the effect of invoking this action is @emph{only} to switch
15096the system profile to an existing generation and rearrange the GRUB menu
15097entries. To actually start using the target system generation, you must
15098reboot after running this action. In the future, it will be updated to
15099do the same things as @command{reconfigure}, like activating and
15100deactivating services.
15101
15102This action will fail if the specified generation does not exist.
15103
15104@item roll-back
e32171ee 15105@cindex rolling back
8074b330
CM
15106Switch to the preceding system generation. The next time the system
15107boots, it will use the preceding system generation. This is the inverse
15108of @command{reconfigure}, and it is exactly the same as invoking
15109@command{switch-generation} with an argument of @code{-1}.
15110
15111Currently, as with @command{switch-generation}, you must reboot after
15112running this action to actually start using the preceding system
15113generation.
15114
cf4a9129 15115@item build
1068f26b 15116Build the derivation of the operating system, which includes all the
cf4a9129
LC
15117configuration files and programs needed to boot and run the system.
15118This action does not actually install anything.
113daf62 15119
cf4a9129
LC
15120@item init
15121Populate the given directory with all the files necessary to run the
15122operating system specified in @var{file}. This is useful for first-time
4705641f 15123installations of GuixSD. For instance:
113daf62
LC
15124
15125@example
cf4a9129 15126guix system init my-os-config.scm /mnt
113daf62
LC
15127@end example
15128
cf4a9129
LC
15129copies to @file{/mnt} all the store items required by the configuration
15130specified in @file{my-os-config.scm}. This includes configuration
15131files, packages, and so on. It also creates other essential files
15132needed for the system to operate correctly---e.g., the @file{/etc},
15133@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 15134
cf4a9129
LC
15135This command also installs GRUB on the device specified in
15136@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 15137
cf4a9129
LC
15138@item vm
15139@cindex virtual machine
0276f697 15140@cindex VM
f535dcbe 15141@anchor{guix system vm}
1068f26b 15142Build a virtual machine that contains the operating system declared in
cf4a9129 15143@var{file}, and return a script to run that virtual machine (VM).
1068f26b 15144Arguments given to the script are passed to QEMU.
113daf62 15145
cf4a9129 15146The VM shares its store with the host system.
113daf62 15147
0276f697
LC
15148Additional file systems can be shared between the host and the VM using
15149the @code{--share} and @code{--expose} command-line options: the former
15150specifies a directory to be shared with write access, while the latter
15151provides read-only access to the shared directory.
15152
15153The example below creates a VM in which the user's home directory is
15154accessible read-only, and where the @file{/exchange} directory is a
1068f26b 15155read-write mapping of @file{$HOME/tmp} on the host:
0276f697
LC
15156
15157@example
15158guix system vm my-config.scm \
15159 --expose=$HOME --share=$HOME/tmp=/exchange
15160@end example
15161
6aa260af
LC
15162On GNU/Linux, the default is to boot directly to the kernel; this has
15163the advantage of requiring only a very tiny root disk image since the
1068f26b 15164store of the host can then be mounted.
6aa260af
LC
15165
15166The @code{--full-boot} option forces a complete boot sequence, starting
15167with the bootloader. This requires more disk space since a root image
15168containing at least the kernel, initrd, and bootloader data files must
15169be created. The @code{--image-size} option can be used to specify the
1068f26b 15170size of the image.
ab11f0be 15171
cf4a9129
LC
15172@item vm-image
15173@itemx disk-image
15174Return a virtual machine or disk image of the operating system declared
15175in @var{file} that stands alone. Use the @option{--image-size} option
15176to specify the size of the image.
113daf62 15177
cf4a9129 15178When using @code{vm-image}, the returned image is in qcow2 format, which
97d76250
LF
15179the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
15180for more information on how to run the image in a virtual machine.
113daf62 15181
cf4a9129
LC
15182When using @code{disk-image}, a raw disk image is produced; it can be
15183copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
1068f26b 15184the device corresponding to a USB stick, one can copy the image to it
cf4a9129 15185using the following command:
113daf62 15186
cf4a9129
LC
15187@example
15188# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
15189@end example
113daf62 15190
1c8a81b1
DT
15191@item container
15192Return a script to run the operating system declared in @var{file}
15193within a container. Containers are a set of lightweight isolation
15194mechanisms provided by the kernel Linux-libre. Containers are
15195substantially less resource-demanding than full virtual machines since
15196the kernel, shared objects, and other resources can be shared with the
15197host system; this also means they provide thinner isolation.
15198
15199Currently, the script must be run as root in order to support more than
15200a single user and group. The container shares its store with the host
15201system.
15202
15203As with the @code{vm} action (@pxref{guix system vm}), additional file
15204systems to be shared between the host and container can be specified
15205using the @option{--share} and @option{--expose} options:
15206
15207@example
15208guix system container my-config.scm \
15209 --expose=$HOME --share=$HOME/tmp=/exchange
15210@end example
15211
0f252e26 15212@quotation Note
cfd35b4e 15213This option requires Linux-libre 3.19 or newer.
0f252e26
DT
15214@end quotation
15215
cf4a9129 15216@end table
113daf62 15217
ccd7158d
LC
15218@var{options} can contain any of the common build options (@pxref{Common
15219Build Options}). In addition, @var{options} can contain one of the
15220following:
113daf62 15221
cf4a9129
LC
15222@table @option
15223@item --system=@var{system}
15224@itemx -s @var{system}
1068f26b 15225Attempt to build for @var{system} instead of the host system type.
cf4a9129 15226This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 15227
f3f427c2
LC
15228@item --derivation
15229@itemx -d
15230Return the derivation file name of the given operating system without
15231building anything.
15232
cf4a9129
LC
15233@item --image-size=@var{size}
15234For the @code{vm-image} and @code{disk-image} actions, create an image
15235of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
15236include a unit as a suffix (@pxref{Block size, size specifications,,
15237coreutils, GNU Coreutils}).
db030303
LC
15238
15239@item --on-error=@var{strategy}
15240Apply @var{strategy} when an error occurs when reading @var{file}.
15241@var{strategy} may be one of the following:
15242
15243@table @code
15244@item nothing-special
15245Report the error concisely and exit. This is the default strategy.
15246
15247@item backtrace
15248Likewise, but also display a backtrace.
15249
15250@item debug
15251Report the error and enter Guile's debugger. From there, you can run
15252commands such as @code{,bt} to get a backtrace, @code{,locals} to
1068f26b
AE
15253display local variable values, and more generally inspect the state of the
15254program. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
db030303
LC
15255a list of available debugging commands.
15256@end table
113daf62 15257@end table
113daf62 15258
eca69fc0
LC
15259@quotation Note
15260All the actions above, except @code{build} and @code{init},
15261can use KVM support in the Linux-libre kernel. Specifically, if the
15262machine has hardware virtualization support, the corresponding
cf4a9129 15263KVM kernel module should be loaded, and the @file{/dev/kvm} device node
1068f26b 15264must exist and be readable and writable by the user and by the
eca69fc0
LC
15265build users of the daemon (@pxref{Build Environment Setup}).
15266@end quotation
8451a568 15267
65797bff
LC
15268Once you have built, configured, re-configured, and re-re-configured
15269your GuixSD installation, you may find it useful to list the operating
15270system generations available on disk---and that you can choose from the
15271GRUB boot menu:
15272
15273@table @code
15274
15275@item list-generations
15276List a summary of each generation of the operating system available on
15277disk, in a human-readable way. This is similar to the
15278@option{--list-generations} option of @command{guix package}
15279(@pxref{Invoking guix package}).
15280
15281Optionally, one can specify a pattern, with the same syntax that is used
15282in @command{guix package --list-generations}, to restrict the list of
15283generations displayed. For instance, the following command displays
1068f26b 15284generations that are up to 10 days old:
65797bff
LC
15285
15286@example
15287$ guix system list-generations 10d
15288@end example
15289
15290@end table
15291
d6c3267a
LC
15292The @command{guix system} command has even more to offer! The following
15293sub-commands allow you to visualize how your system services relate to
15294each other:
15295
15296@anchor{system-extension-graph}
15297@table @code
15298
15299@item extension-graph
15300Emit in Dot/Graphviz format to standard output the @dfn{service
15301extension graph} of the operating system defined in @var{file}
15302(@pxref{Service Composition}, for more information on service
15303extensions.)
15304
15305The command:
15306
15307@example
15308$ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
15309@end example
15310
15311produces a PDF file showing the extension relations among services.
15312
710fa231
AK
15313@anchor{system-shepherd-graph}
15314@item shepherd-graph
6f305ea5 15315Emit in Dot/Graphviz format to standard output the @dfn{dependency
dd17bc38
AK
15316graph} of shepherd services of the operating system defined in
15317@var{file}. @xref{Shepherd Services}, for more information and for an
15318example graph.
6f305ea5 15319
d6c3267a
LC
15320@end table
15321
97d76250 15322@node Running GuixSD in a VM
70ac09a5 15323@subsection Running GuixSD in a Virtual Machine
97d76250 15324
e32171ee 15325@cindex virtual machine
97d76250
LF
15326One way to run GuixSD in a virtual machine (VM) is to build a GuixSD
15327virtual machine image using @command{guix system vm-image}
15328(@pxref{Invoking guix system}). The returned image is in qcow2 format,
15329which the @uref{http://qemu.org/, QEMU emulator} can efficiently use.
15330
e32171ee 15331@cindex QEMU
97d76250
LF
15332To run the image in QEMU, copy it out of the store (@pxref{The Store})
15333and give yourself permission to write to the copy. When invoking QEMU,
15334you must choose a system emulator that is suitable for your hardware
15335platform. Here is a minimal QEMU invocation that will boot the result
15336of @command{guix system vm-image} on x86_64 hardware:
15337
15338@example
15339$ qemu-system-x86_64 \
15340 -net user -net nic,model=virtio \
15341 -enable-kvm -m 256 /tmp/qemu-image
15342@end example
15343
15344Here is what each of these options means:
15345
15346@table @code
15347@item qemu-system-x86_64
15348This specifies the hardware platform to emulate. This should match the
15349host.
15350
15351@item -net user
15352Enable the unprivileged user-mode network stack. The guest OS can
15353access the host but not vice versa. This is the simplest way to get the
58806e6f 15354guest OS online.
97d76250
LF
15355
15356@item -net nic,model=virtio
1068f26b 15357You must create a network interface of a given model. If you do not
97d76250
LF
15358create a NIC, the boot will fail. Assuming your hardware platform is
15359x86_64, you can get a list of available NIC models by running
15360@command{qemu-system-x86_64 -net nic,model=help}.
15361
15362@item -enable-kvm
15363If your system has hardware virtualization extensions, enabling the
1068f26b 15364virtual machine support (KVM) of the Linux kernel will make things run
97d76250
LF
15365faster.
15366
15367@item -m 256
15368RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
7414de0a 15369which may be insufficient for some operations.
97d76250
LF
15370
15371@item /tmp/qemu-image
15372The file name of the qcow2 image.
15373@end table
d6c3267a 15374
9fc221b5 15375The default @command{run-vm.sh} script that is returned by an invocation of
3ddc50db
DC
15376@command{guix system vm} does not add a @command{-net user} flag by default.
15377To get network access from within the vm add the @code{(dhcp-client-service)}
15378to your system definition and start the VM using
15379@command{`guix system vm config.scm` -net user}. An important caveat of using
15380@command{-net user} for networking is that @command{ping} will not work, because
15381it uses the ICMP protocol. You'll have to use a different command to check for
15382network connectivity, like for example @command{curl}.
15383
15384@subsubsection Connecting Through SSH
15385
e32171ee
JD
15386@cindex SSH
15387@cindex SSH server
3ddc50db
DC
15388To enable SSH inside a VM you need to add a SSH server like @code{(dropbear-service)}
15389or @code{(lsh-service)} to your VM. The @code{(lsh-service}) doesn't currently
15390boot unsupervised. It requires you to type some characters to initialize the
15391randomness generator. In addition you need to forward the SSH port, 22 by
15392default, to the host. You can do this with
15393
15394@example
15395`guix system vm config.scm` -net user,hostfwd=tcp::10022-:22
15396@end example
15397
15398To connect to the VM you can run
15399
15400@example
15401ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022
15402@end example
15403
15404The @command{-p} tells @command{ssh} the port you want to connect to.
15405@command{-o UserKnownHostsFile=/dev/null} prevents @command{ssh} from complaining
15406every time you modify your @command{config.scm} file and the
15407@command{-o StrictHostKeyChecking=no} prevents you from having to allow a
15408connection to an unknown host every time you connect.
15409
15410@subsubsection Using @command{virt-viewer} with Spice
15411
15412As an alternative to the default @command{qemu} graphical client you can
15413use the @command{remote-viewer} from the @command{virt-viewer} package. To
15414connect pass the @command{-spice port=5930,disable-ticketing} flag to
15415@command{qemu}. See previous section for further information on how to do this.
15416
15417Spice also allows you to do some nice stuff like share your clipboard with your
15418VM. To enable that you'll also have to pass the following flags to @command{qemu}:
15419
15420@example
15421-device virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0,addr=0x5
15422-chardev spicevmc,name=vdagent,id=vdagent
15423-device virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,
15424name=com.redhat.spice.0
15425@end example
15426
15427You'll also need to add the @pxref{Miscellaneous Services, Spice service}.
15428
cf4a9129
LC
15429@node Defining Services
15430@subsection Defining Services
8451a568 15431
eb524192 15432The previous sections show the available services and how one can combine
0adfe95a
LC
15433them in an @code{operating-system} declaration. But how do we define
15434them in the first place? And what is a service anyway?
8451a568 15435
0adfe95a
LC
15436@menu
15437* Service Composition:: The model for composing services.
15438* Service Types and Services:: Types and services.
15439* Service Reference:: API reference.
dd17bc38 15440* Shepherd Services:: A particular type of service.
0adfe95a
LC
15441@end menu
15442
15443@node Service Composition
15444@subsubsection Service Composition
15445
15446@cindex services
15447@cindex daemons
15448Here we define a @dfn{service} as, broadly, something that extends the
1068f26b 15449functionality of the operating system. Often a service is a process---a
0adfe95a
LC
15450@dfn{daemon}---started when the system boots: a secure shell server, a
15451Web server, the Guix build daemon, etc. Sometimes a service is a daemon
15452whose execution can be triggered by another daemon---e.g., an FTP server
15453started by @command{inetd} or a D-Bus service activated by
15454@command{dbus-daemon}. Occasionally, a service does not map to a
15455daemon. For instance, the ``account'' service collects user accounts
15456and makes sure they exist when the system runs; the ``udev'' service
15457collects device management rules and makes them available to the eudev
1068f26b
AE
15458daemon; the @file{/etc} service populates the @file{/etc} directory
15459of the system.
0adfe95a 15460
d6c3267a 15461@cindex service extensions
0adfe95a 15462GuixSD services are connected by @dfn{extensions}. For instance, the
1068f26b 15463secure shell service @emph{extends} the Shepherd---the GuixSD
dd17bc38
AK
15464initialization system, running as PID@tie{}1---by giving it the command
15465lines to start and stop the secure shell daemon (@pxref{Networking
15466Services, @code{lsh-service}}); the UPower service extends the D-Bus
15467service by passing it its @file{.service} specification, and extends the
15468udev service by passing it device management rules (@pxref{Desktop
15469Services, @code{upower-service}}); the Guix daemon service extends the
15470Shepherd by passing it the command lines to start and stop the daemon,
15471and extends the account service by passing it a list of required build
15472user accounts (@pxref{Base Services}).
0adfe95a
LC
15473
15474All in all, services and their ``extends'' relations form a directed
15475acyclic graph (DAG). If we represent services as boxes and extensions
15476as arrows, a typical system might provide something like this:
15477
15478@image{images/service-graph,,5in,Typical service extension graph.}
15479
d62e201c
LC
15480@cindex system service
15481At the bottom, we see the @dfn{system service}, which produces the
15482directory containing everything to run and boot the system, as returned
15483by the @command{guix system build} command. @xref{Service Reference},
15484to learn about the other service types shown here.
d6c3267a
LC
15485@xref{system-extension-graph, the @command{guix system extension-graph}
15486command}, for information on how to generate this representation for a
15487particular operating system definition.
0adfe95a
LC
15488
15489@cindex service types
15490Technically, developers can define @dfn{service types} to express these
15491relations. There can be any number of services of a given type on the
15492system---for instance, a system running two instances of the GNU secure
15493shell server (lsh) has two instances of @var{lsh-service-type}, with
15494different parameters.
15495
15496The following section describes the programming interface for service
15497types and services.
15498
15499@node Service Types and Services
15500@subsubsection Service Types and Services
15501
15502A @dfn{service type} is a node in the DAG described above. Let us start
15503with a simple example, the service type for the Guix build daemon
15504(@pxref{Invoking guix-daemon}):
15505
15506@example
15507(define guix-service-type
15508 (service-type
15509 (name 'guix)
15510 (extensions
d4053c71 15511 (list (service-extension shepherd-root-service-type guix-shepherd-service)
0adfe95a
LC
15512 (service-extension account-service-type guix-accounts)
15513 (service-extension activation-service-type guix-activation)))))
15514@end example
8451a568 15515
cf4a9129 15516@noindent
1068f26b 15517It defines two things:
0adfe95a
LC
15518
15519@enumerate
15520@item
15521A name, whose sole purpose is to make inspection and debugging easier.
15522
15523@item
15524A list of @dfn{service extensions}, where each extension designates the
1068f26b
AE
15525target service type and a procedure that, given the parameters of the
15526service, returns a list of objects to extend the service of that type.
0adfe95a
LC
15527
15528Every service type has at least one service extension. The only
15529exception is the @dfn{boot service type}, which is the ultimate service.
15530@end enumerate
15531
15532In this example, @var{guix-service-type} extends three services:
15533
15534@table @var
d4053c71
AK
15535@item shepherd-root-service-type
15536The @var{guix-shepherd-service} procedure defines how the Shepherd
15537service is extended. Namely, it returns a @code{<shepherd-service>}
15538object that defines how @command{guix-daemon} is started and stopped
15539(@pxref{Shepherd Services}).
0adfe95a
LC
15540
15541@item account-service-type
15542This extension for this service is computed by @var{guix-accounts},
15543which returns a list of @code{user-group} and @code{user-account}
15544objects representing the build user accounts (@pxref{Invoking
15545guix-daemon}).
15546
15547@item activation-service-type
15548Here @var{guix-activation} is a procedure that returns a gexp, which is
15549a code snippet to run at ``activation time''---e.g., when the service is
15550booted.
15551@end table
15552
15553A service of this type is instantiated like this:
15554
15555@example
15556(service guix-service-type
15557 (guix-configuration
15558 (build-accounts 5)
15559 (use-substitutes? #f)))
15560@end example
15561
15562The second argument to the @code{service} form is a value representing
15563the parameters of this specific service instance.
15564@xref{guix-configuration-type, @code{guix-configuration}}, for
15565information about the @code{guix-configuration} data type.
15566
15567@var{guix-service-type} is quite simple because it extends other
15568services but is not extensible itself.
15569
15570@c @subsubsubsection Extensible Service Types
15571
15572The service type for an @emph{extensible} service looks like this:
15573
15574@example
15575(define udev-service-type
15576 (service-type (name 'udev)
15577 (extensions
d4053c71
AK
15578 (list (service-extension shepherd-root-service-type
15579 udev-shepherd-service)))
0adfe95a
LC
15580
15581 (compose concatenate) ;concatenate the list of rules
15582 (extend (lambda (config rules)
15583 (match config
15584 (($ <udev-configuration> udev initial-rules)
15585 (udev-configuration
15586 (udev udev) ;the udev package to use
15587 (rules (append initial-rules rules)))))))))
15588@end example
15589
15590This is the service type for the
15591@uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
15592management daemon}. Compared to the previous example, in addition to an
d4053c71 15593extension of @var{shepherd-root-service-type}, we see two new fields:
0adfe95a
LC
15594
15595@table @code
15596@item compose
15597This is the procedure to @dfn{compose} the list of extensions to
15598services of this type.
15599
15600Services can extend the udev service by passing it lists of rules; we
15601compose those extensions simply by concatenating them.
15602
15603@item extend
1068f26b 15604This procedure defines how the value of the service is @dfn{extended} with
0adfe95a
LC
15605the composition of the extensions.
15606
15607Udev extensions are composed into a list of rules, but the udev service
15608value is itself a @code{<udev-configuration>} record. So here, we
a40424bd 15609extend that record by appending the list of rules it contains to the
0adfe95a
LC
15610list of contributed rules.
15611@end table
15612
15613There can be only one instance of an extensible service type such as
15614@var{udev-service-type}. If there were more, the
15615@code{service-extension} specifications would be ambiguous.
15616
15617Still here? The next section provides a reference of the programming
15618interface for services.
15619
15620@node Service Reference
15621@subsubsection Service Reference
15622
15623We have seen an overview of service types (@pxref{Service Types and
15624Services}). This section provides a reference on how to manipulate
15625services and service types. This interface is provided by the
15626@code{(gnu services)} module.
15627
15628@deffn {Scheme Procedure} service @var{type} @var{value}
15629Return a new service of @var{type}, a @code{<service-type>} object (see
15630below.) @var{value} can be any object; it represents the parameters of
15631this particular service instance.
15632@end deffn
15633
15634@deffn {Scheme Procedure} service? @var{obj}
15635Return true if @var{obj} is a service.
15636@end deffn
8451a568 15637
0adfe95a
LC
15638@deffn {Scheme Procedure} service-kind @var{service}
15639Return the type of @var{service}---i.e., a @code{<service-type>} object.
15640@end deffn
15641
15642@deffn {Scheme Procedure} service-parameters @var{service}
15643Return the value associated with @var{service}. It represents its
15644parameters.
15645@end deffn
15646
15647Here is an example of how a service is created and manipulated:
15648
15649@example
15650(define s
15651 (service nginx-service-type
15652 (nginx-configuration
15653 (nginx nginx)
15654 (log-directory log-directory)
15655 (run-directory run-directory)
15656 (file config-file))))
15657
15658(service? s)
15659@result{} #t
15660
15661(eq? (service-kind s) nginx-service-type)
15662@result{} #t
15663@end example
15664
cd6f6c22
LC
15665The @code{modify-services} form provides a handy way to change the
15666parameters of some of the services of a list such as
4d343a14 15667@var{%base-services} (@pxref{Base Services, @code{%base-services}}). It
7414de0a 15668evaluates to a list of services. Of course, you could always use
4d343a14
CM
15669standard list combinators such as @code{map} and @code{fold} to do that
15670(@pxref{SRFI-1, List Library,, guile, GNU Guile Reference Manual});
15671@code{modify-services} simply provides a more concise form for this
15672common pattern.
cd6f6c22
LC
15673
15674@deffn {Scheme Syntax} modify-services @var{services} @
15675 (@var{type} @var{variable} => @var{body}) @dots{}
15676
15677Modify the services listed in @var{services} according to the given
15678clauses. Each clause has the form:
15679
15680@example
15681(@var{type} @var{variable} => @var{body})
15682@end example
15683
4d343a14
CM
15684where @var{type} is a service type---e.g.,
15685@code{guix-service-type}---and @var{variable} is an identifier that is
15686bound within the @var{body} to the service parameters---e.g., a
15687@code{guix-configuration} instance---of the original service of that
15688@var{type}.
cd6f6c22 15689
4d343a14
CM
15690The @var{body} should evaluate to the new service parameters, which will
15691be used to configure the new service. This new service will replace the
15692original in the resulting list. Because a service's service parameters
7414de0a 15693are created using @code{define-record-type*}, you can write a succinct
4d343a14
CM
15694@var{body} that evaluates to the new service parameters by using the
15695@code{inherit} feature that @code{define-record-type*} provides.
15696
b53daad0 15697@xref{Using the Configuration System}, for example usage.
cd6f6c22 15698
cd6f6c22
LC
15699@end deffn
15700
15701Next comes the programming interface for service types. This is
15702something you want to know when writing new service definitions, but not
15703necessarily when simply looking for ways to customize your
15704@code{operating-system} declaration.
15705
0adfe95a
LC
15706@deftp {Data Type} service-type
15707@cindex service type
15708This is the representation of a @dfn{service type} (@pxref{Service Types
15709and Services}).
15710
15711@table @asis
15712@item @code{name}
15713This is a symbol, used only to simplify inspection and debugging.
15714
15715@item @code{extensions}
1068f26b 15716A non-empty list of @code{<service-extension>} objects (see below).
0adfe95a
LC
15717
15718@item @code{compose} (default: @code{#f})
15719If this is @code{#f}, then the service type denotes services that cannot
15720be extended---i.e., services that do not receive ``values'' from other
15721services.
15722
15723Otherwise, it must be a one-argument procedure. The procedure is called
15724by @code{fold-services} and is passed a list of values collected from
15725extensions. It must return a value that is a valid parameter value for
15726the service instance.
15727
15728@item @code{extend} (default: @code{#f})
15729If this is @code{#f}, services of this type cannot be extended.
15730
15731Otherwise, it must be a two-argument procedure: @code{fold-services}
1068f26b 15732calls it, passing it the initial value of the service as the first argument
0adfe95a
LC
15733and the result of applying @code{compose} to the extension values as the
15734second argument.
15735@end table
15736
15737@xref{Service Types and Services}, for examples.
15738@end deftp
15739
15740@deffn {Scheme Procedure} service-extension @var{target-type} @
15741 @var{compute}
15742Return a new extension for services of type @var{target-type}.
15743@var{compute} must be a one-argument procedure: @code{fold-services}
15744calls it, passing it the value associated with the service that provides
15745the extension; it must return a valid value for the target service.
15746@end deffn
15747
15748@deffn {Scheme Procedure} service-extension? @var{obj}
15749Return true if @var{obj} is a service extension.
15750@end deffn
15751
71654dfd
LC
15752Occasionally, you might want to simply extend an existing service. This
15753involves creating a new service type and specifying the extension of
15754interest, which can be verbose; the @code{simple-service} procedure
15755provides a shorthand for this.
15756
15757@deffn {Scheme Procedure} simple-service @var{name} @var{target} @var{value}
15758Return a service that extends @var{target} with @var{value}. This works
15759by creating a singleton service type @var{name}, of which the returned
15760service is an instance.
15761
15762For example, this extends mcron (@pxref{Scheduled Job Execution}) with
15763an additional job:
15764
15765@example
15766(simple-service 'my-mcron-job mcron-service-type
15767 #~(job '(next-hour (3)) "guix gc -F 2G"))
15768@end example
15769@end deffn
15770
0adfe95a
LC
15771At the core of the service abstraction lies the @code{fold-services}
15772procedure, which is responsible for ``compiling'' a list of services
d62e201c
LC
15773down to a single directory that contains everything needed to boot and
15774run the system---the directory shown by the @command{guix system build}
15775command (@pxref{Invoking guix system}). In essence, it propagates
15776service extensions down the service graph, updating each node parameters
15777on the way, until it reaches the root node.
0adfe95a
LC
15778
15779@deffn {Scheme Procedure} fold-services @var{services} @
d62e201c 15780 [#:target-type @var{system-service-type}]
0adfe95a
LC
15781Fold @var{services} by propagating their extensions down to the root of
15782type @var{target-type}; return the root service adjusted accordingly.
15783@end deffn
15784
15785Lastly, the @code{(gnu services)} module also defines several essential
15786service types, some of which are listed below.
15787
d62e201c
LC
15788@defvr {Scheme Variable} system-service-type
15789This is the root of the service graph. It produces the system directory
15790as returned by the @command{guix system build} command.
15791@end defvr
15792
0adfe95a 15793@defvr {Scheme Variable} boot-service-type
d62e201c
LC
15794The type of the ``boot service'', which produces the @dfn{boot script}.
15795The boot script is what the initial RAM disk runs when booting.
0adfe95a
LC
15796@end defvr
15797
15798@defvr {Scheme Variable} etc-service-type
15799The type of the @file{/etc} service. This service can be extended by
15800passing it name/file tuples such as:
15801
15802@example
15803(list `("issue" ,(plain-file "issue" "Welcome!\n")))
15804@end example
15805
15806In this example, the effect would be to add an @file{/etc/issue} file
15807pointing to the given file.
15808@end defvr
15809
15810@defvr {Scheme Variable} setuid-program-service-type
15811Type for the ``setuid-program service''. This service collects lists of
15812executable file names, passed as gexps, and adds them to the set of
15813setuid-root programs on the system (@pxref{Setuid Programs}).
15814@end defvr
15815
af4c3fd5
LC
15816@defvr {Scheme Variable} profile-service-type
15817Type of the service that populates the @dfn{system profile}---i.e., the
15818programs under @file{/run/current-system/profile}. Other services can
15819extend it by passing it lists of packages to add to the system profile.
15820@end defvr
15821
0adfe95a 15822
dd17bc38
AK
15823@node Shepherd Services
15824@subsubsection Shepherd Services
0adfe95a 15825
e32171ee 15826@cindex shepherd services
0adfe95a
LC
15827@cindex PID 1
15828@cindex init system
a40424bd
CM
15829The @code{(gnu services shepherd)} module provides a way to define
15830services managed by the GNU@tie{}Shepherd, which is the GuixSD
15831initialization system---the first process that is started when the
1068f26b
AE
15832system boots, also known as PID@tie{}1
15833(@pxref{Introduction,,, shepherd, The GNU Shepherd Manual}).
6f305ea5 15834
dd17bc38
AK
15835Services in the Shepherd can depend on each other. For instance, the
15836SSH daemon may need to be started after the syslog daemon has been
15837started, which in turn can only happen once all the file systems have
15838been mounted. The simple operating system defined earlier (@pxref{Using
15839the Configuration System}) results in a service graph like this:
6f305ea5 15840
710fa231 15841@image{images/shepherd-graph,,5in,Typical shepherd service graph.}
6f305ea5
LC
15842
15843You can actually generate such a graph for any operating system
710fa231
AK
15844definition using the @command{guix system shepherd-graph} command
15845(@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
6f305ea5 15846
d4053c71
AK
15847The @var{%shepherd-root-service} is a service object representing
15848PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
15849by passing it lists of @code{<shepherd-service>} objects.
0adfe95a 15850
d4053c71 15851@deftp {Data Type} shepherd-service
dd17bc38 15852The data type representing a service managed by the Shepherd.
0adfe95a
LC
15853
15854@table @asis
15855@item @code{provision}
15856This is a list of symbols denoting what the service provides.
15857
dd17bc38
AK
15858These are the names that may be passed to @command{herd start},
15859@command{herd status}, and similar commands (@pxref{Invoking herd,,,
15860shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
15861@code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
0adfe95a
LC
15862
15863@item @code{requirements} (default: @code{'()})
dd17bc38 15864List of symbols denoting the Shepherd services this one depends on.
0adfe95a
LC
15865
15866@item @code{respawn?} (default: @code{#t})
15867Whether to restart the service when it stops, for instance when the
15868underlying process dies.
15869
15870@item @code{start}
15871@itemx @code{stop} (default: @code{#~(const #f)})
dd17bc38
AK
15872The @code{start} and @code{stop} fields refer to the Shepherd's
15873facilities to start and stop processes (@pxref{Service De- and
15874Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
15875G-expressions that get expanded in the Shepherd configuration file
15876(@pxref{G-Expressions}).
0adfe95a
LC
15877
15878@item @code{documentation}
15879A documentation string, as shown when running:
15880
15881@example
dd17bc38 15882herd doc @var{service-name}
0adfe95a
LC
15883@end example
15884
15885where @var{service-name} is one of the symbols in @var{provision}
dd17bc38 15886(@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
fae685b9
LC
15887
15888@item @code{modules} (default: @var{%default-modules})
15889This is the list of modules that must be in scope when @code{start} and
15890@code{stop} are evaluated.
15891
0adfe95a
LC
15892@end table
15893@end deftp
15894
d4053c71 15895@defvr {Scheme Variable} shepherd-root-service-type
dd17bc38 15896The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
0adfe95a
LC
15897
15898This is the service type that extensions target when they want to create
dd17bc38 15899shepherd services (@pxref{Service Types and Services}, for an example).
d4053c71 15900Each extension must pass a list of @code{<shepherd-service>}.
0adfe95a
LC
15901@end defvr
15902
d4053c71 15903@defvr {Scheme Variable} %shepherd-root-service
0adfe95a
LC
15904This service represents PID@tie{}1.
15905@end defvr
8451a568 15906
8451a568 15907
cf4a9129
LC
15908@node Installing Debugging Files
15909@section Installing Debugging Files
8451a568 15910
cf4a9129
LC
15911@cindex debugging files
15912Program binaries, as produced by the GCC compilers for instance, are
15913typically written in the ELF format, with a section containing
15914@dfn{debugging information}. Debugging information is what allows the
15915debugger, GDB, to map binary code to source code; it is required to
15916debug a compiled program in good conditions.
8451a568 15917
cf4a9129
LC
15918The problem with debugging information is that is takes up a fair amount
15919of disk space. For example, debugging information for the GNU C Library
15920weighs in at more than 60 MiB. Thus, as a user, keeping all the
15921debugging info of all the installed programs is usually not an option.
15922Yet, space savings should not come at the cost of an impediment to
15923debugging---especially in the GNU system, which should make it easier
15924for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 15925
cf4a9129
LC
15926Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
15927mechanism that allows users to get the best of both worlds: debugging
15928information can be stripped from the binaries and stored in separate
15929files. GDB is then able to load debugging information from those files,
15930when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
15931with GDB}).
8451a568 15932
cf4a9129
LC
15933The GNU distribution takes advantage of this by storing debugging
15934information in the @code{lib/debug} sub-directory of a separate package
15935output unimaginatively called @code{debug} (@pxref{Packages with
15936Multiple Outputs}). Users can choose to install the @code{debug} output
15937of a package when they need it. For instance, the following command
15938installs the debugging information for the GNU C Library and for GNU
15939Guile:
8451a568
LC
15940
15941@example
cf4a9129 15942guix package -i glibc:debug guile:debug
8451a568
LC
15943@end example
15944
cf4a9129
LC
15945GDB must then be told to look for debug files in the user's profile, by
15946setting the @code{debug-file-directory} variable (consider setting it
15947from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
15948GDB}):
8451a568 15949
cf4a9129
LC
15950@example
15951(gdb) set debug-file-directory ~/.guix-profile/lib/debug
15952@end example
8451a568 15953
cf4a9129
LC
15954From there on, GDB will pick up debugging information from the
15955@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 15956
cf4a9129
LC
15957In addition, you will most likely want GDB to be able to show the source
15958code being debugged. To do that, you will have to unpack the source
15959code of the package of interest (obtained with @code{guix build
15960--source}, @pxref{Invoking guix build}), and to point GDB to that source
15961directory using the @code{directory} command (@pxref{Source Path,
15962@code{directory},, gdb, Debugging with GDB}).
8451a568 15963
cf4a9129
LC
15964@c XXX: keep me up-to-date
15965The @code{debug} output mechanism in Guix is implemented by the
15966@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
1068f26b
AE
15967opt-in---debugging information is available only for the packages
15968with definitions explicitly declaring a @code{debug} output. This may be
15969changed to opt-out in the future if our build farm servers can handle
cf4a9129
LC
15970the load. To check whether a package has a @code{debug} output, use
15971@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 15972
8451a568 15973
05962f29
LC
15974@node Security Updates
15975@section Security Updates
15976
09866b39
LC
15977@cindex security updates
15978@cindex security vulnerabilities
15979Occasionally, important security vulnerabilities are discovered in software
15980packages and must be patched. Guix developers try hard to keep track of
15981known vulnerabilities and to apply fixes as soon as possible in the
15982@code{master} branch of Guix (we do not yet provide a ``stable'' branch
15983containing only security updates.) The @command{guix lint} tool helps
15984developers find out about vulnerable versions of software packages in the
15985distribution:
15986
15987@smallexample
15988$ guix lint -c cve
15989gnu/packages/base.scm:652:2: glibc-2.21: probably vulnerable to CVE-2015-1781, CVE-2015-7547
15990gnu/packages/gcc.scm:334:2: gcc-4.9.3: probably vulnerable to CVE-2015-5276
15991gnu/packages/image.scm:312:2: openjpeg-2.1.0: probably vulnerable to CVE-2016-1923, CVE-2016-1924
15992@dots{}
15993@end smallexample
15994
15995@xref{Invoking guix lint}, for more information.
15996
843858b8 15997@quotation Note
09866b39
LC
15998As of version @value{VERSION}, the feature described below is considered
15999``beta''.
843858b8 16000@end quotation
05962f29 16001
09866b39 16002Guix follows a functional
05962f29
LC
16003package management discipline (@pxref{Introduction}), which implies
16004that, when a package is changed, @emph{every package that depends on it}
16005must be rebuilt. This can significantly slow down the deployment of
16006fixes in core packages such as libc or Bash, since basically the whole
16007distribution would need to be rebuilt. Using pre-built binaries helps
16008(@pxref{Substitutes}), but deployment may still take more time than
16009desired.
16010
16011@cindex grafts
1068f26b 16012To address this, Guix implements @dfn{grafts}, a mechanism that allows
05962f29
LC
16013for fast deployment of critical updates without the costs associated
16014with a whole-distribution rebuild. The idea is to rebuild only the
16015package that needs to be patched, and then to ``graft'' it onto packages
16016explicitly installed by the user and that were previously referring to
16017the original package. The cost of grafting is typically very low, and
16018order of magnitudes lower than a full rebuild of the dependency chain.
16019
16020@cindex replacements of packages, for grafts
16021For instance, suppose a security update needs to be applied to Bash.
16022Guix developers will provide a package definition for the ``fixed''
16023Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
16024Packages}). Then, the original package definition is augmented with a
16025@code{replacement} field pointing to the package containing the bug fix:
16026
16027@example
16028(define bash
16029 (package
16030 (name "bash")
16031 ;; @dots{}
16032 (replacement bash-fixed)))
16033@end example
16034
c22a1324
LC
16035From there on, any package depending directly or indirectly on Bash---as
16036reported by @command{guix gc --requisites} (@pxref{Invoking guix
16037gc})---that is installed is automatically ``rewritten'' to refer to
05962f29 16038@var{bash-fixed} instead of @var{bash}. This grafting process takes
1068f26b 16039time proportional to the size of the package, usually less than a
c22a1324
LC
16040minute for an ``average'' package on a recent machine. Grafting is
16041recursive: when an indirect dependency requires grafting, then grafting
16042``propagates'' up to the package that the user is installing.
05962f29 16043
57bdd79e
LC
16044Currently, the length of the name and version of the graft and that of
16045the package it replaces (@var{bash-fixed} and @var{bash} in the example
16046above) must be equal. This restriction mostly comes from the fact that
16047grafting works by patching files, including binary files, directly.
05962f29
LC
16048Other restrictions may apply: for instance, when adding a graft to a
16049package providing a shared library, the original shared library and its
16050replacement must have the same @code{SONAME} and be binary-compatible.
16051
59a4dd50
LC
16052The @option{--no-grafts} command-line option allows you to forcefully
16053avoid grafting (@pxref{Common Build Options, @option{--no-grafts}}).
16054Thus, the command:
16055
16056@example
16057guix build bash --no-grafts
16058@end example
16059
16060@noindent
16061returns the store file name of the original Bash, whereas:
16062
16063@example
16064guix build bash
16065@end example
16066
16067@noindent
16068returns the store file name of the ``fixed'', replacement Bash. This
16069allows you to distinguish between the two variants of Bash.
16070
16071To verify which Bash your whole profile refers to, you can run
16072(@pxref{Invoking guix gc}):
16073
16074@example
16075guix gc -R `readlink -f ~/.guix-profile` | grep bash
16076@end example
16077
16078@noindent
16079@dots{} and compare the store file names that you get with those above.
16080Likewise for a complete GuixSD system generation:
16081
16082@example
16083guix gc -R `guix system build my-config.scm` | grep bash
16084@end example
16085
16086Lastly, to check which Bash running processes are using, you can use the
16087@command{lsof} command:
16088
16089@example
16090lsof | grep /gnu/store/.*bash
16091@end example
16092
05962f29 16093
cf4a9129
LC
16094@node Package Modules
16095@section Package Modules
8451a568 16096
cf4a9129
LC
16097From a programming viewpoint, the package definitions of the
16098GNU distribution are provided by Guile modules in the @code{(gnu packages
16099@dots{})} name space@footnote{Note that packages under the @code{(gnu
16100packages @dots{})} module name space are not necessarily ``GNU
16101packages''. This module naming scheme follows the usual Guile module
16102naming convention: @code{gnu} means that these modules are distributed
16103as part of the GNU system, and @code{packages} identifies modules that
16104define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
16105Reference Manual}). For instance, the @code{(gnu packages emacs)}
16106module exports a variable named @code{emacs}, which is bound to a
16107@code{<package>} object (@pxref{Defining Packages}).
113daf62 16108
300868ba 16109The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
16110automatically scanned for packages by the command-line tools. For
16111instance, when running @code{guix package -i emacs}, all the @code{(gnu
16112packages @dots{})} modules are scanned until one that exports a package
16113object whose name is @code{emacs} is found. This package search
16114facility is implemented in the @code{(gnu packages)} module.
113daf62 16115
300868ba 16116@cindex customization, of packages
8689901f 16117@cindex package module search path
cf4a9129 16118Users can store package definitions in modules with different
60142854 16119names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
16120name and module name must match. For instance, the @code{(my-packages
16121emacs)} module must be stored in a @file{my-packages/emacs.scm} file
16122relative to the load path specified with @option{--load-path} or
16123@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
16124guile, GNU Guile Reference Manual}, for details.}. These package definitions
1068f26b
AE
16125will not be visible by default. Users can invoke commands such as
16126@command{guix package} and @command{guix build} with the
c95ded7e
LC
16127@code{-e} option so that they know where to find the package. Better
16128yet, they can use the
300868ba 16129@code{-L} option of these commands to make those modules visible
8689901f
LC
16130(@pxref{Invoking guix build, @code{--load-path}}), or define the
16131@code{GUIX_PACKAGE_PATH} environment variable. This environment
16132variable makes it easy to extend or customize the distribution and is
16133honored by all the user interfaces.
16134
16135@defvr {Environment Variable} GUIX_PACKAGE_PATH
1068f26b
AE
16136This is a colon-separated list of directories to search for additional
16137package modules. Directories listed in this variable take precedence
16138over the own modules of the distribution.
8689901f 16139@end defvr
ef5dd60a 16140
cf4a9129
LC
16141The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
16142each package is built based solely on other packages in the
16143distribution. The root of this dependency graph is a small set of
16144@dfn{bootstrap binaries}, provided by the @code{(gnu packages
16145bootstrap)} module. For more information on bootstrapping,
081145cf 16146@pxref{Bootstrapping}.
ef5dd60a 16147
cf4a9129
LC
16148@node Packaging Guidelines
16149@section Packaging Guidelines
ef5dd60a 16150
e32171ee 16151@cindex packages, creating
cf4a9129
LC
16152The GNU distribution is nascent and may well lack some of your favorite
16153packages. This section describes how you can help make the distribution
16154grow. @xref{Contributing}, for additional information on how you can
16155help.
ef5dd60a 16156
cf4a9129
LC
16157Free software packages are usually distributed in the form of
16158@dfn{source code tarballs}---typically @file{tar.gz} files that contain
16159all the source files. Adding a package to the distribution means
16160essentially two things: adding a @dfn{recipe} that describes how to
16161build the package, including a list of other packages required to build
f97c9175 16162it, and adding @dfn{package metadata} along with that recipe, such as a
cf4a9129 16163description and licensing information.
ef5dd60a 16164
cf4a9129
LC
16165In Guix all this information is embodied in @dfn{package definitions}.
16166Package definitions provide a high-level view of the package. They are
16167written using the syntax of the Scheme programming language; in fact,
16168for each package we define a variable bound to the package definition,
16169and export that variable from a module (@pxref{Package Modules}).
16170However, in-depth Scheme knowledge is @emph{not} a prerequisite for
16171creating packages. For more information on package definitions,
081145cf 16172@pxref{Defining Packages}.
ef5dd60a 16173
cf4a9129
LC
16174Once a package definition is in place, stored in a file in the Guix
16175source tree, it can be tested using the @command{guix build} command
16176(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
16177called @code{gnew}, you may run this command from the Guix build tree
16178(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
16179
16180@example
cf4a9129 16181./pre-inst-env guix build gnew --keep-failed
ef5dd60a 16182@end example
ef5dd60a 16183
cf4a9129
LC
16184Using @code{--keep-failed} makes it easier to debug build failures since
16185it provides access to the failed build tree. Another useful
16186command-line option when debugging is @code{--log-file}, to access the
16187build log.
ef5dd60a 16188
cf4a9129
LC
16189If the package is unknown to the @command{guix} command, it may be that
16190the source file contains a syntax error, or lacks a @code{define-public}
16191clause to export the package variable. To figure it out, you may load
16192the module from Guile to get more information about the actual error:
ef5dd60a 16193
cf4a9129
LC
16194@example
16195./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
16196@end example
ef5dd60a 16197
cf4a9129
LC
16198Once your package builds correctly, please send us a patch
16199(@pxref{Contributing}). Well, if you need help, we will be happy to
16200help you too. Once the patch is committed in the Guix repository, the
16201new package automatically gets built on the supported platforms by
2b1cee21 16202@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 16203system}.
ef5dd60a 16204
cf4a9129
LC
16205@cindex substituter
16206Users can obtain the new package definition simply by running
16207@command{guix pull} (@pxref{Invoking guix pull}). When
16208@code{hydra.gnu.org} is done building the package, installing the
16209package automatically downloads binaries from there
16210(@pxref{Substitutes}). The only place where human intervention is
16211needed is to review and apply the patch.
ef5dd60a 16212
ef5dd60a 16213
cf4a9129 16214@menu
ec0339cd
LC
16215* Software Freedom:: What may go into the distribution.
16216* Package Naming:: What's in a name?
16217* Version Numbers:: When the name is not enough.
cbd02397 16218* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
16219* Python Modules:: Taming the snake.
16220* Perl Modules:: Little pearls.
e1c963bf 16221* Java Packages:: Coffee break.
ec0339cd 16222* Fonts:: Fond of fonts.
cf4a9129 16223@end menu
ef5dd60a 16224
cf4a9129
LC
16225@node Software Freedom
16226@subsection Software Freedom
ef5dd60a 16227
cf4a9129 16228@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
e32171ee 16229@cindex free software
cf4a9129
LC
16230The GNU operating system has been developed so that users can have
16231freedom in their computing. GNU is @dfn{free software}, meaning that
16232users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
16233essential freedoms}: to run the program, to study and change the program
16234in source code form, to redistribute exact copies, and to distribute
16235modified versions. Packages found in the GNU distribution provide only
16236software that conveys these four freedoms.
c11a6eb1 16237
cf4a9129
LC
16238In addition, the GNU distribution follow the
16239@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
16240software distribution guidelines}. Among other things, these guidelines
16241reject non-free firmware, recommendations of non-free software, and
16242discuss ways to deal with trademarks and patents.
ef5dd60a 16243
1068f26b
AE
16244Some otherwise free upstream package sources contain a small and optional
16245subset that violates the above guidelines, for instance because this subset
16246is itself non-free code. When that happens, the offending items are removed
16247with appropriate patches or code snippets in the @code{origin} form of the
16248package (@pxref{Defining Packages}). This way, @code{guix
cf4a9129
LC
16249build --source} returns the ``freed'' source rather than the unmodified
16250upstream source.
ef5dd60a 16251
ef5dd60a 16252
cf4a9129
LC
16253@node Package Naming
16254@subsection Package Naming
ef5dd60a 16255
e32171ee 16256@cindex package name
cf4a9129
LC
16257A package has actually two names associated with it:
16258First, there is the name of the @emph{Scheme variable}, the one following
16259@code{define-public}. By this name, the package can be made known in the
16260Scheme code, for instance as input to another package. Second, there is
16261the string in the @code{name} field of a package definition. This name
16262is used by package management commands such as
16263@command{guix package} and @command{guix build}.
ef5dd60a 16264
cf4a9129
LC
16265Both are usually the same and correspond to the lowercase conversion of
16266the project name chosen upstream, with underscores replaced with
16267hyphens. For instance, GNUnet is available as @code{gnunet}, and
16268SDL_net as @code{sdl-net}.
927097ef 16269
cf4a9129 16270We do not add @code{lib} prefixes for library packages, unless these are
081145cf 16271already part of the official project name. But @pxref{Python
cf4a9129
LC
16272Modules} and @ref{Perl Modules} for special rules concerning modules for
16273the Python and Perl languages.
927097ef 16274
1b366ee4 16275Font package names are handled differently, @pxref{Fonts}.
7fec52b7 16276
ef5dd60a 16277
cf4a9129
LC
16278@node Version Numbers
16279@subsection Version Numbers
ef5dd60a 16280
e32171ee 16281@cindex package version
cf4a9129
LC
16282We usually package only the latest version of a given free software
16283project. But sometimes, for instance for incompatible library versions,
16284two (or more) versions of the same package are needed. These require
16285different Scheme variable names. We use the name as defined
16286in @ref{Package Naming}
16287for the most recent version; previous versions use the same name, suffixed
16288by @code{-} and the smallest prefix of the version number that may
16289distinguish the two versions.
ef5dd60a 16290
cf4a9129
LC
16291The name inside the package definition is the same for all versions of a
16292package and does not contain any version number.
ef5dd60a 16293
cf4a9129 16294For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 16295
cf4a9129
LC
16296@example
16297(define-public gtk+
16298 (package
17d8e33f
ML
16299 (name "gtk+")
16300 (version "3.9.12")
16301 ...))
cf4a9129
LC
16302(define-public gtk+-2
16303 (package
17d8e33f
ML
16304 (name "gtk+")
16305 (version "2.24.20")
16306 ...))
cf4a9129
LC
16307@end example
16308If we also wanted GTK+ 3.8.2, this would be packaged as
16309@example
16310(define-public gtk+-3.8
16311 (package
17d8e33f
ML
16312 (name "gtk+")
16313 (version "3.8.2")
16314 ...))
cf4a9129 16315@end example
ef5dd60a 16316
880d647d
LC
16317@c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
16318@c for a discussion of what follows.
16319@cindex version number, for VCS snapshots
16320Occasionally, we package snapshots of upstream's version control system
16321(VCS) instead of formal releases. This should remain exceptional,
16322because it is up to upstream developers to clarify what the stable
16323release is. Yet, it is sometimes necessary. So, what should we put in
16324the @code{version} field?
16325
16326Clearly, we need to make the commit identifier of the VCS snapshot
16327visible in the version string, but we also need to make sure that the
16328version string is monotonically increasing so that @command{guix package
16329--upgrade} can determine which version is newer. Since commit
16330identifiers, notably with Git, are not monotonically increasing, we add
16331a revision number that we increase each time we upgrade to a newer
16332snapshot. The resulting version string looks like this:
16333
16334@example
163352.0.11-3.cabba9e
16336 ^ ^ ^
16337 | | `-- upstream commit ID
16338 | |
16339 | `--- Guix package revision
16340 |
16341latest upstream version
16342@end example
16343
16344It is a good idea to strip commit identifiers in the @code{version}
16345field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
16346aesthetics have a role to play here) as well as problems related to OS
16347limits such as the maximum shebang length (127 bytes for the Linux
16348kernel.) It is best to use the full commit identifiers in
561360a5
LC
16349@code{origin}s, though, to avoid ambiguities. A typical package
16350definition may look like this:
16351
16352@example
16353(define my-package
6e42660b 16354 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7")
16355 (revision "1")) ;Guix package revision
561360a5 16356 (package
6e42660b 16357 (version (string-append "0.9-" revision "."
561360a5
LC
16358 (string-take commit 7)))
16359 (source (origin
16360 (method git-fetch)
16361 (uri (git-reference
16362 (url "git://example.org/my-package.git")
16363 (commit commit)))
16364 (sha256 (base32 "1mbikn@dots{}"))
16365 (file-name (string-append "my-package-" version
16366 "-checkout"))))
16367 ;; @dots{}
16368 )))
16369@end example
880d647d 16370
cbd02397
LC
16371@node Synopses and Descriptions
16372@subsection Synopses and Descriptions
16373
e32171ee
JD
16374@cindex package description
16375@cindex package synopsis
cbd02397
LC
16376As we have seen before, each package in GNU@tie{}Guix includes a
16377synopsis and a description (@pxref{Defining Packages}). Synopses and
16378descriptions are important: They are what @command{guix package
16379--search} searches, and a crucial piece of information to help users
16380determine whether a given package suits their needs. Consequently,
16381packagers should pay attention to what goes into them.
16382
16383Synopses must start with a capital letter and must not end with a
16384period. They must not start with ``a'' or ``the'', which usually does
16385not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
16386tool that frobs files''. The synopsis should say what the package
16387is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
16388used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
16389matching a pattern''.
16390
16391Keep in mind that the synopsis must be meaningful for a very wide
16392audience. For example, ``Manipulate alignments in the SAM format''
16393might make sense for a seasoned bioinformatics researcher, but might be
16394fairly unhelpful or even misleading to a non-specialized audience. It
16395is a good idea to come up with a synopsis that gives an idea of the
16396application domain of the package. In this example, this might give
16397something like ``Manipulate nucleotide sequence alignments'', which
16398hopefully gives the user a better idea of whether this is what they are
16399looking for.
16400
cbd02397
LC
16401Descriptions should take between five and ten lines. Use full
16402sentences, and avoid using acronyms without first introducing them.
762e54b7
LC
16403Please avoid marketing phrases such as ``world-leading'',
16404``industrial-strength'', and ``next-generation'', and avoid superlatives
16405like ``the most advanced''---they are not helpful to users looking for a
16406package and may even sound suspicious. Instead, try to be factual,
16407mentioning use cases and features.
16408
16409@cindex Texinfo markup, in package descriptions
cbd02397
LC
16410Descriptions can include Texinfo markup, which is useful to introduce
16411ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
16412hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
16413should be careful when using some characters for example @samp{@@} and
16414curly braces which are the basic special characters in Texinfo
16415(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
16416such as @command{guix package --show} take care of rendering it
16417appropriately.
cbd02397
LC
16418
16419Synopses and descriptions are translated by volunteers
16420@uref{http://translationproject.org/domain/guix-packages.html, at the
16421Translation Project} so that as many users as possible can read them in
16422their native language. User interfaces search them and display them in
16423the language specified by the current locale.
16424
16425Translation is a lot of work so, as a packager, please pay even more
16426attention to your synopses and descriptions as every change may entail
ba7d6c76 16427additional work for translators. In order to help them, it is possible
36743e71 16428to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
16429special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
16430Gettext}):
16431
16432@example
16433;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
16434(description "ARandR is designed to provide a simple visual front end
16435for the X11 resize-and-rotate (RandR) extension. @dots{}")
16436@end example
cbd02397 16437
ef5dd60a 16438
cf4a9129
LC
16439@node Python Modules
16440@subsection Python Modules
ef5dd60a 16441
e32171ee 16442@cindex python
cf4a9129
LC
16443We currently package Python 2 and Python 3, under the Scheme variable names
16444@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
16445To avoid confusion and naming clashes with other programming languages, it
16446seems desirable that the name of a package for a Python module contains
16447the word @code{python}.
ef5dd60a 16448
cf4a9129
LC
16449Some modules are compatible with only one version of Python, others with both.
16450If the package Foo compiles only with Python 3, we name it
16451@code{python-foo}; if it compiles only with Python 2, we name it
16452@code{python2-foo}. If it is compatible with both versions, we create two
16453packages with the corresponding names.
ef5dd60a 16454
cf4a9129
LC
16455If a project already contains the word @code{python}, we drop this;
16456for instance, the module python-dateutil is packaged under the names
99c866a0
HG
16457@code{python-dateutil} and @code{python2-dateutil}. If the project name
16458starts with @code{py} (e.g. @code{pytz}), we keep it and prefix it as
16459described above.
113daf62 16460
e940a271
HG
16461@subsubsection Specifying Dependencies
16462@cindex inputs, for Python packages
16463
16464Dependency information for Python packages is usually available in the
16465package source tree, with varying degrees of accuracy: in the
16466@file{setup.py} file, in @file{requirements.txt}, or in @file{tox.ini}.
16467
16468Your mission, when writing a recipe for a Python package, is to map
16469these dependencies to the appropriate type of ``input'' (@pxref{package
16470Reference, inputs}). Although the @code{pypi} importer normally does a
16471good job (@pxref{Invoking guix import}), you may want to check the
16472following check list to determine which dependency goes where.
16473
16474@itemize
16475
aaf75c89
HG
16476@item
16477We currently package Python 2 with @code{setuptools} and @code{pip}
16478installed like Python 3.4 has per default. Thus you don't need to
891a843d
HG
16479specify either of these as an input. @command{guix lint} will warn you
16480if you do.
aaf75c89 16481
e940a271
HG
16482@item
16483Python dependencies required at run time go into
16484@code{propagated-inputs}. They are typically defined with the
16485@code{install_requires} keyword in @file{setup.py}, or in the
16486@file{requirements.txt} file.
16487
16488@item
16489Python packages required only at build time---e.g., those listed with
16490the @code{setup_requires} keyword in @file{setup.py}---or only for
16491testing---e.g., those in @code{tests_require}---go into
16492@code{native-inputs}. The rationale is that (1) they do not need to be
16493propagated because they are not needed at run time, and (2) in a
16494cross-compilation context, it's the ``native'' input that we'd want.
16495
aaf75c89 16496Examples are the @code{pytest}, @code{mock}, and @code{nose} test
e940a271
HG
16497frameworks. Of course if any of these packages is also required at
16498run-time, it needs to go to @code{propagated-inputs}.
16499
16500@item
16501Anything that does not fall in the previous categories goes to
16502@code{inputs}, for example programs or C libraries required for building
16503Python packages containing C extensions.
16504
16505@item
16506If a Python package has optional dependencies (@code{extras_require}),
16507it is up to you to decide whether to add them or not, based on their
16508usefulness/overhead ratio (@pxref{Submitting Patches, @command{guix
16509size}}).
16510
16511@end itemize
16512
16513
cf4a9129
LC
16514@node Perl Modules
16515@subsection Perl Modules
523e4896 16516
e32171ee 16517@cindex perl
cf4a9129
LC
16518Perl programs standing for themselves are named as any other package,
16519using the lowercase upstream name.
16520For Perl packages containing a single class, we use the lowercase class name,
16521replace all occurrences of @code{::} by dashes and prepend the prefix
16522@code{perl-}.
16523So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
16524Modules containing several classes keep their lowercase upstream name and
16525are also prepended by @code{perl-}. Such modules tend to have the word
16526@code{perl} somewhere in their name, which gets dropped in favor of the
16527prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 16528
523e4896 16529
e1c963bf
HG
16530@node Java Packages
16531@subsection Java Packages
16532
e32171ee 16533@cindex java
e1c963bf
HG
16534Java programs standing for themselves are named as any other package,
16535using the lowercase upstream name.
16536
16537To avoid confusion and naming clashes with other programming languages,
16538it is desirable that the name of a package for a Java package is
16539prefixed with @code{java-}. If a project already contains the word
16540@code{java}, we drop this; for instance, the package @code{ngsjava} is
16541packaged under the name @code{java-ngs}.
16542
16543For Java packages containing a single class or a small class hierarchy,
16544we use the lowercase class name, replace all occurrences of @code{.} by
16545dashes and prepend the prefix @code{java-}. So the class
16546@code{apache.commons.cli} becomes package
16547@code{java-apache-commons-cli}.
16548
16549
7fec52b7
AE
16550@node Fonts
16551@subsection Fonts
16552
e32171ee 16553@cindex fonts
7fec52b7
AE
16554For fonts that are in general not installed by a user for typesetting
16555purposes, or that are distributed as part of a larger software package,
16556we rely on the general packaging rules for software; for instance, this
16557applies to the fonts delivered as part of the X.Org system or fonts that
16558are part of TeX Live.
16559
16560To make it easier for a user to search for fonts, names for other packages
16561containing only fonts are constructed as follows, independently of the
16562upstream package name.
16563
16564The name of a package containing only one font family starts with
16565@code{font-}; it is followed by the foundry name and a dash @code{-}
16566if the foundry is known, and the font family name, in which spaces are
16567replaced by dashes (and as usual, all upper case letters are transformed
16568to lower case).
16569For example, the Gentium font family by SIL is packaged under the name
16570@code{font-sil-gentium}.
16571
16572For a package containing several font families, the name of the collection
16573is used in the place of the font family name.
16574For instance, the Liberation fonts consist of three families,
16575Liberation Sans, Liberation Serif and Liberation Mono.
16576These could be packaged separately under the names
16577@code{font-liberation-sans} and so on; but as they are distributed together
16578under a common name, we prefer to package them together as
16579@code{font-liberation}.
16580
16581In the case where several formats of the same font family or font collection
16582are packaged separately, a short form of the format, prepended by a dash,
16583is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 16584@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
16585fonts.
16586
16587
b25937e3 16588
cf4a9129
LC
16589@node Bootstrapping
16590@section Bootstrapping
b25937e3 16591
cf4a9129 16592@c Adapted from the ELS 2013 paper.
b25937e3 16593
cf4a9129 16594@cindex bootstrapping
7889394e 16595
cf4a9129
LC
16596Bootstrapping in our context refers to how the distribution gets built
16597``from nothing''. Remember that the build environment of a derivation
16598contains nothing but its declared inputs (@pxref{Introduction}). So
16599there's an obvious chicken-and-egg problem: how does the first package
16600get built? How does the first compiler get compiled? Note that this is
16601a question of interest only to the curious hacker, not to the regular
16602user, so you can shamelessly skip this section if you consider yourself
16603a ``regular user''.
72b9d60d 16604
cf4a9129
LC
16605@cindex bootstrap binaries
16606The GNU system is primarily made of C code, with libc at its core. The
16607GNU build system itself assumes the availability of a Bourne shell and
16608command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
16609`grep'. Furthermore, build programs---programs that run
16610@code{./configure}, @code{make}, etc.---are written in Guile Scheme
16611(@pxref{Derivations}). Consequently, to be able to build anything at
16612all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
16613Binutils, libc, and the other packages mentioned above---the
16614@dfn{bootstrap binaries}.
72b9d60d 16615
cf4a9129
LC
16616These bootstrap binaries are ``taken for granted'', though we can also
16617re-create them if needed (more on that later).
72b9d60d 16618
cf4a9129 16619@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 16620
cf4a9129
LC
16621@c As of Emacs 24.3, Info-mode displays the image, but since it's a
16622@c large image, it's hard to scroll. Oh well.
16623@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 16624
cf4a9129
LC
16625The figure above shows the very beginning of the dependency graph of the
16626distribution, corresponding to the package definitions of the @code{(gnu
d33fa0c7
LC
16627packages bootstrap)} module. A similar figure can be generated with
16628@command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
16629
16630@example
16631guix graph -t derivation \
16632 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
16633 | dot -Tps > t.ps
16634@end example
16635
16636At this level of detail, things are
cf4a9129
LC
16637slightly complex. First, Guile itself consists of an ELF executable,
16638along with many source and compiled Scheme files that are dynamically
16639loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
16640tarball shown in this graph. This tarball is part of Guix's ``source''
16641distribution, and gets inserted into the store with @code{add-to-store}
16642(@pxref{The Store}).
2e7b5cea 16643
cf4a9129
LC
16644But how do we write a derivation that unpacks this tarball and adds it
16645to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
16646derivation---the first one that gets built---uses @code{bash} as its
16647builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
16648@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
16649@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
16650the Guix source distribution, whose sole purpose is to allow the Guile
16651tarball to be unpacked.
fb729425 16652
cf4a9129
LC
16653Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
16654Guile that can be used to run subsequent build programs. Its first task
16655is to download tarballs containing the other pre-built binaries---this
16656is what the @code{.tar.xz.drv} derivations do. Guix modules such as
16657@code{ftp-client.scm} are used for this purpose. The
16658@code{module-import.drv} derivations import those modules in a directory
16659in the store, using the original layout. The
16660@code{module-import-compiled.drv} derivations compile those modules, and
16661write them in an output directory with the right layout. This
16662corresponds to the @code{#:modules} argument of
16663@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 16664
cf4a9129
LC
16665Finally, the various tarballs are unpacked by the
16666derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
16667etc., at which point we have a working C tool chain.
fb729425 16668
fb729425 16669
cf4a9129 16670@unnumberedsubsec Building the Build Tools
523e4896 16671
cf4a9129
LC
16672Bootstrapping is complete when we have a full tool chain that does not
16673depend on the pre-built bootstrap tools discussed above. This
16674no-dependency requirement is verified by checking whether the files of
16675the final tool chain contain references to the @file{/gnu/store}
16676directories of the bootstrap inputs. The process that leads to this
16677``final'' tool chain is described by the package definitions found in
1f6f57df 16678the @code{(gnu packages commencement)} module.
df2ce343 16679
d33fa0c7
LC
16680The @command{guix graph} command allows us to ``zoom out'' compared to
16681the graph above, by looking at the level of package objects instead of
16682individual derivations---remember that a package may translate to
16683several derivations, typically one derivation to download its source,
16684one to build the Guile modules it needs, and one to actually build the
16685package from source. The command:
16686
16687@example
16688guix graph -t bag \
16689 -e '(@@@@ (gnu packages commencement)
16690 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
16691@end example
16692
16693@noindent
16694produces the dependency graph leading to the ``final'' C
16695library@footnote{You may notice the @code{glibc-intermediate} label,
16696suggesting that it is not @emph{quite} final, but as a good
16697approximation, we will consider it final.}, depicted below.
16698
16699@image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
16700
cf4a9129
LC
16701@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
16702The first tool that gets built with the bootstrap binaries is
d33fa0c7
LC
16703GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
16704for all the following packages. From there Findutils and Diffutils get
16705built.
523e4896 16706
cf4a9129
LC
16707Then come the first-stage Binutils and GCC, built as pseudo cross
16708tools---i.e., with @code{--target} equal to @code{--host}. They are
16709used to build libc. Thanks to this cross-build trick, this libc is
16710guaranteed not to hold any reference to the initial tool chain.
4af2447e 16711
d33fa0c7
LC
16712From there the final Binutils and GCC (not shown above) are built.
16713GCC uses @code{ld}
cf4a9129
LC
16714from the final Binutils, and links programs against the just-built libc.
16715This tool chain is used to build the other packages used by Guix and by
16716the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 16717
cf4a9129
LC
16718And voilà! At this point we have the complete set of build tools that
16719the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
16720variable of the @code{(gnu packages commencement)} module, and are
16721implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 16722(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 16723
4af2447e 16724
cf4a9129 16725@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 16726
e32171ee 16727@cindex bootstrap binaries
cf4a9129
LC
16728Because the final tool chain does not depend on the bootstrap binaries,
16729those rarely need to be updated. Nevertheless, it is useful to have an
16730automated way to produce them, should an update occur, and this is what
16731the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 16732
cf4a9129
LC
16733The following command builds the tarballs containing the bootstrap
16734binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
16735of Coreutils and other basic command-line tools):
4b2615e1 16736
cf4a9129
LC
16737@example
16738guix build bootstrap-tarballs
16739@end example
16740
16741The generated tarballs are those that should be referred to in the
16742@code{(gnu packages bootstrap)} module mentioned at the beginning of
16743this section.
16744
16745Still here? Then perhaps by now you've started to wonder: when do we
16746reach a fixed point? That is an interesting question! The answer is
16747unknown, but if you would like to investigate further (and have
16748significant computational and storage resources to do so), then let us
16749know.
16750
16751@node Porting
16752@section Porting to a New Platform
16753
16754As discussed above, the GNU distribution is self-contained, and
16755self-containment is achieved by relying on pre-built ``bootstrap
16756binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
16757operating system kernel, CPU architecture, and application binary
16758interface (ABI). Thus, to port the distribution to a platform that is
16759not yet supported, one must build those bootstrap binaries, and update
16760the @code{(gnu packages bootstrap)} module to use them on that platform.
16761
16762Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
16763When everything goes well, and assuming the GNU tool chain supports the
16764target platform, this can be as simple as running a command like this
16765one:
16766
16767@example
16768guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
16769@end example
16770
1c0c417d
LC
16771For this to work, the @code{glibc-dynamic-linker} procedure in
16772@code{(gnu packages bootstrap)} must be augmented to return the right
16773file name for libc's dynamic linker on that platform; likewise,
16774@code{system->linux-architecture} in @code{(gnu packages linux)} must be
16775taught about the new platform.
16776
cf4a9129 16777Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
16778to be updated to refer to these binaries on the target platform. That
16779is, the hashes and URLs of the bootstrap tarballs for the new platform
16780must be added alongside those of the currently supported platforms. The
16781bootstrap Guile tarball is treated specially: it is expected to be
03d0e2d2 16782available locally, and @file{gnu/local.mk} has rules do download it for
1c0c417d
LC
16783the supported architectures; a rule for the new platform must be added
16784as well.
cf4a9129
LC
16785
16786In practice, there may be some complications. First, it may be that the
16787extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
16788above) is not recognized by all the GNU tools. Typically, glibc
16789recognizes some of these, whereas GCC uses an extra @code{--with-abi}
16790configure flag (see @code{gcc.scm} for examples of how to handle this).
16791Second, some of the required packages could fail to build for that
16792platform. Lastly, the generated binaries could be broken for some
16793reason.
4af2447e 16794
9bf3c1a7 16795@c *********************************************************************
8c01b9d0 16796@include contributing.texi
c78bd12b 16797
568717fd
LC
16798@c *********************************************************************
16799@node Acknowledgments
16800@chapter Acknowledgments
16801
136787cb
LC
16802Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
16803which was designed and
4c7ac9aa
LC
16804implemented by Eelco Dolstra, with contributions from other people (see
16805the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
16806management, and promoted unprecedented features, such as transactional
16807package upgrades and rollbacks, per-user profiles, and referentially
16808transparent build processes. Without this work, Guix would not exist.
16809
16810The Nix-based software distributions, Nixpkgs and NixOS, have also been
16811an inspiration for Guix.
16812
4c7ac9aa
LC
16813GNU@tie{}Guix itself is a collective work with contributions from a
16814number of people. See the @file{AUTHORS} file in Guix for more
16815information on these fine people. The @file{THANKS} file lists people
16816who have helped by reporting bugs, taking care of the infrastructure,
16817providing artwork and themes, making suggestions, and more---thank you!
16818
16819
568717fd
LC
16820@c *********************************************************************
16821@node GNU Free Documentation License
16822@appendix GNU Free Documentation License
e32171ee 16823@cindex license, GNU Free Documentation License
568717fd
LC
16824@include fdl-1.3.texi
16825
16826@c *********************************************************************
16827@node Concept Index
16828@unnumbered Concept Index
16829@printindex cp
16830
a85b83d2
LC
16831@node Programming Index
16832@unnumbered Programming Index
16833@syncodeindex tp fn
16834@syncodeindex vr fn
568717fd
LC
16835@printindex fn
16836
16837@bye
16838
16839@c Local Variables:
16840@c ispell-local-dictionary: "american";
16841@c End: