Merge branch 'core-updates'
[jackhill/guix/guix.git] / doc / guix.texi
1 \input texinfo
2 @c -*-texinfo-*-
3
4 @c %**start of header
5 @setfilename guix.info
6 @documentencoding UTF-8
7 @settitle GNU Guix Reference Manual
8 @c %**end of header
9
10 @include version.texi
11
12 @c Identifier of the OpenPGP key used to sign tarballs and such.
13 @set OPENPGP-SIGNING-KEY-ID 3CE464558A84FDC69DB40CFB090B11993D9AEBB5
14
15 @copying
16 Copyright @copyright{} 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès@*
17 Copyright @copyright{} 2013, 2014, 2016 Andreas Enge@*
18 Copyright @copyright{} 2013 Nikita Karetnikov@*
19 Copyright @copyright{} 2014, 2015, 2016 Alex Kost@*
20 Copyright @copyright{} 2015, 2016 Mathieu Lirzin@*
21 Copyright @copyright{} 2014 Pierre-Antoine Rault@*
22 Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer@*
23 Copyright @copyright{} 2015, 2016, 2017 Leo Famulari@*
24 Copyright @copyright{} 2015, 2016, 2017 Ricardo Wurmus@*
25 Copyright @copyright{} 2016 Ben Woodcroft@*
26 Copyright @copyright{} 2016 Chris Marusich@*
27 Copyright @copyright{} 2016, 2017 Efraim Flashner@*
28 Copyright @copyright{} 2016 John Darrington@*
29 Copyright @copyright{} 2016 ng0@*
30 Copyright @copyright{} 2016 Jan Nieuwenhuizen@*
31 Copyright @copyright{} 2016 Julien Lepiller@*
32 Copyright @copyright{} 2016 Alex ter Weele@*
33 Copyright @copyright{} 2017 Clément Lassieur@*
34 Copyright @copyright{} 2017 Mathieu Othacehe@*
35 Copyright @copyright{} 2017 Federico Beffa@*
36 Copyright @copyright{} 2017 Carlo Zancanaro@*
37 Copyright @copyright{} 2017 Thomas Danckaert@*
38 Copyright @copyright{} 2017 humanitiesNerd@*
39 Copyright @copyright{} 2017 Christopher Allan Webber@*
40 Copyright @copyright{} 2017 Marius Bakke@*
41 Copyright @copyright{} 2017 Hartmut Goebel
42
43 Permission is granted to copy, distribute and/or modify this document
44 under the terms of the GNU Free Documentation License, Version 1.3 or
45 any later version published by the Free Software Foundation; with no
46 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
47 copy of the license is included in the section entitled ``GNU Free
48 Documentation License''.
49 @end copying
50
51 @dircategory System administration
52 @direntry
53 * Guix: (guix). Manage installed software and system configuration.
54 * guix package: (guix)Invoking guix package. Installing, removing, and upgrading packages.
55 * guix gc: (guix)Invoking guix gc. Reclaiming unused disk space.
56 * guix pull: (guix)Invoking guix pull. Update the list of available packages.
57 * guix system: (guix)Invoking guix system. Manage the operating system configuration.
58 @end direntry
59
60 @dircategory Software development
61 @direntry
62 * guix environment: (guix)Invoking guix environment. Building development environments with Guix.
63 * guix build: (guix)Invoking guix build. Building packages.
64 * guix pack: (guix)Invoking guix pack. Creating binary bundles.
65 @end direntry
66
67 @titlepage
68 @title GNU Guix Reference Manual
69 @subtitle Using the GNU Guix Functional Package Manager
70 @author The GNU Guix Developers
71
72 @page
73 @vskip 0pt plus 1filll
74 Edition @value{EDITION} @*
75 @value{UPDATED} @*
76
77 @insertcopying
78 @end titlepage
79
80 @contents
81
82 @c *********************************************************************
83 @node Top
84 @top GNU Guix
85
86 This document describes GNU Guix version @value{VERSION}, a functional
87 package management tool written for the GNU system.
88
89 @menu
90 * Introduction:: What is Guix about?
91 * Installation:: Installing Guix.
92 * Package Management:: Package installation, upgrade, etc.
93 * Programming Interface:: Using Guix in Scheme.
94 * Utilities:: Package management commands.
95 * GNU Distribution:: Software for your friendly GNU system.
96 * Contributing:: Your help needed!
97
98 * Acknowledgments:: Thanks!
99 * GNU Free Documentation License:: The license of this manual.
100 * Concept Index:: Concepts.
101 * Programming Index:: Data types, functions, and variables.
102
103 @detailmenu
104 --- The Detailed Node Listing ---
105
106 Installation
107
108 * Binary Installation:: Getting Guix running in no time!
109 * Requirements:: Software needed to build and run Guix.
110 * Running the Test Suite:: Testing Guix.
111 * Setting Up the Daemon:: Preparing the build daemon's environment.
112 * Invoking guix-daemon:: Running the build daemon.
113 * Application Setup:: Application-specific setup.
114
115 Setting Up the Daemon
116
117 * Build Environment Setup:: Preparing the isolated build environment.
118 * Daemon Offload Setup:: Offloading builds to remote machines.
119
120 Package Management
121
122 * Features:: How Guix will make your life brighter.
123 * Invoking guix package:: Package installation, removal, etc.
124 * Substitutes:: Downloading pre-built binaries.
125 * Packages with Multiple Outputs:: Single source package, multiple outputs.
126 * Invoking guix gc:: Running the garbage collector.
127 * Invoking guix pull:: Fetching the latest Guix and distribution.
128 * Invoking guix pack:: Creating software bundles.
129 * Invoking guix archive:: Exporting and importing store files.
130
131 Programming Interface
132
133 * Defining Packages:: Defining new packages.
134 * Build Systems:: Specifying how packages are built.
135 * The Store:: Manipulating the package store.
136 * Derivations:: Low-level interface to package derivations.
137 * The Store Monad:: Purely functional interface to the store.
138 * G-Expressions:: Manipulating build expressions.
139
140 Defining Packages
141
142 * package Reference :: The package data type.
143 * origin Reference:: The origin data type.
144
145 Utilities
146
147 * Invoking guix build:: Building packages from the command line.
148 * Invoking guix edit:: Editing package definitions.
149 * Invoking guix download:: Downloading a file and printing its hash.
150 * Invoking guix hash:: Computing the cryptographic hash of a file.
151 * Invoking guix import:: Importing package definitions.
152 * Invoking guix refresh:: Updating package definitions.
153 * Invoking guix lint:: Finding errors in package definitions.
154 * Invoking guix size:: Profiling disk usage.
155 * Invoking guix graph:: Visualizing the graph of packages.
156 * Invoking guix environment:: Setting up development environments.
157 * Invoking guix publish:: Sharing substitutes.
158 * Invoking guix challenge:: Challenging substitute servers.
159 * Invoking guix copy:: Copying to and from a remote store.
160 * Invoking guix container:: Process isolation.
161 * Invoking guix weather:: Assessing substitute availability.
162
163 Invoking @command{guix build}
164
165 * Common Build Options:: Build options for most commands.
166 * Package Transformation Options:: Creating variants of packages.
167 * Additional Build Options:: Options specific to 'guix build'.
168 * Debugging Build Failures:: Real life packaging experience.
169
170 GNU Distribution
171
172 * System Installation:: Installing the whole operating system.
173 * System Configuration:: Configuring the operating system.
174 * Documentation:: Browsing software user manuals.
175 * Installing Debugging Files:: Feeding the debugger.
176 * Security Updates:: Deploying security fixes quickly.
177 * Package Modules:: Packages from the programmer's viewpoint.
178 * Packaging Guidelines:: Growing the distribution.
179 * Bootstrapping:: GNU/Linux built from scratch.
180 * Porting:: Targeting another platform or kernel.
181
182 System Installation
183
184 * Limitations:: What you can expect.
185 * Hardware Considerations:: Supported hardware.
186 * USB Stick Installation:: Preparing the installation medium.
187 * Preparing for Installation:: Networking, partitioning, etc.
188 * Proceeding with the Installation:: The real thing.
189 * Installing GuixSD in a VM:: GuixSD playground.
190 * Building the Installation Image:: How this comes to be.
191
192 System Configuration
193
194 * Using the Configuration System:: Customizing your GNU system.
195 * operating-system Reference:: Detail of operating-system declarations.
196 * File Systems:: Configuring file system mounts.
197 * Mapped Devices:: Block device extra processing.
198 * User Accounts:: Specifying user accounts.
199 * Locales:: Language and cultural convention settings.
200 * Services:: Specifying system services.
201 * Setuid Programs:: Programs running with root privileges.
202 * X.509 Certificates:: Authenticating HTTPS servers.
203 * Name Service Switch:: Configuring libc's name service switch.
204 * Initial RAM Disk:: Linux-Libre bootstrapping.
205 * Bootloader Configuration:: Configuring the boot loader.
206 * Invoking guix system:: Instantiating a system configuration.
207 * Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
208 * Defining Services:: Adding new service definitions.
209
210 Services
211
212 * Base Services:: Essential system services.
213 * Scheduled Job Execution:: The mcron service.
214 * Log Rotation:: The rottlog service.
215 * Networking Services:: Network setup, SSH daemon, etc.
216 * X Window:: Graphical display.
217 * Printing Services:: Local and remote printer support.
218 * Desktop Services:: D-Bus and desktop services.
219 * Database Services:: SQL databases, key-value stores, etc.
220 * Mail Services:: IMAP, POP3, SMTP, and all that.
221 * Messaging Services:: Messaging services.
222 * Monitoring Services:: Monitoring services.
223 * Kerberos Services:: Kerberos services.
224 * Web Services:: Web servers.
225 * DNS Services:: DNS daemons.
226 * VPN Services:: VPN daemons.
227 * Network File System:: NFS related services.
228 * Continuous Integration:: The Cuirass service.
229 * Power management Services:: The TLP tool.
230 * Audio Services:: The MPD.
231 * Virtualization Services:: Virtualization services.
232 * Miscellaneous Services:: Other services.
233
234 Defining Services
235
236 * Service Composition:: The model for composing services.
237 * Service Types and Services:: Types and services.
238 * Service Reference:: API reference.
239 * Shepherd Services:: A particular type of service.
240
241 Packaging Guidelines
242
243 * Software Freedom:: What may go into the distribution.
244 * Package Naming:: What's in a name?
245 * Version Numbers:: When the name is not enough.
246 * Synopses and Descriptions:: Helping users find the right package.
247 * Python Modules:: A touch of British comedy.
248 * Perl Modules:: Little pearls.
249 * Java Packages:: Coffee break.
250 * Fonts:: Fond of fonts.
251
252 Contributing
253
254 * Building from Git:: The latest and greatest.
255 * Running Guix Before It Is Installed:: Hacker tricks.
256 * The Perfect Setup:: The right tools.
257 * Coding Style:: Hygiene of the contributor.
258 * Submitting Patches:: Share your work.
259
260 Coding Style
261
262 * Programming Paradigm:: How to compose your elements.
263 * Modules:: Where to store your code?
264 * Data Types and Pattern Matching:: Implementing data structures.
265 * Formatting Code:: Writing conventions.
266
267 @end detailmenu
268 @end menu
269
270 @c *********************************************************************
271 @node Introduction
272 @chapter Introduction
273
274 @cindex purpose
275 GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
276 using the international phonetic alphabet (IPA).} is a package
277 management tool for the GNU system. Guix makes it easy for unprivileged
278 users to install, upgrade, or remove packages, to roll back to a
279 previous package set, to build packages from source, and generally
280 assists with the creation and maintenance of software environments.
281
282 @cindex user interfaces
283 Guix provides a command-line package management interface
284 (@pxref{Invoking guix package}), a set of command-line utilities
285 (@pxref{Utilities}), as well as Scheme programming interfaces
286 (@pxref{Programming Interface}).
287 @cindex build daemon
288 Its @dfn{build daemon} is responsible for building packages on behalf of
289 users (@pxref{Setting Up the Daemon}) and for downloading pre-built
290 binaries from authorized sources (@pxref{Substitutes}).
291
292 @cindex extensibility of the distribution
293 @cindex customization, of packages
294 Guix includes package definitions for many GNU and non-GNU packages, all
295 of which @uref{https://www.gnu.org/philosophy/free-sw.html, respect the
296 user's computing freedom}. It is @emph{extensible}: users can write
297 their own package definitions (@pxref{Defining Packages}) and make them
298 available as independent package modules (@pxref{Package Modules}). It
299 is also @emph{customizable}: users can @emph{derive} specialized package
300 definitions from existing ones, including from the command line
301 (@pxref{Package Transformation Options}).
302
303 @cindex Guix System Distribution
304 @cindex GuixSD
305 You can install GNU@tie{}Guix on top of an existing GNU/Linux system
306 where it complements the available tools without interference
307 (@pxref{Installation}), or you can use it as part of the standalone
308 @dfn{Guix System Distribution} or GuixSD (@pxref{GNU Distribution}).
309 With GNU@tie{}GuixSD, you @emph{declare} all aspects of the operating
310 system configuration and Guix takes care of instantiating the
311 configuration in a transactional, reproducible, and stateless fashion
312 (@pxref{System Configuration}).
313
314 @cindex functional package management
315 Under the hood, Guix implements the @dfn{functional package management}
316 discipline pioneered by Nix (@pxref{Acknowledgments}).
317 In Guix, the package build and installation process is seen
318 as a @emph{function}, in the mathematical sense. That function takes inputs,
319 such as build scripts, a compiler, and libraries, and
320 returns an installed package. As a pure function, its result depends
321 solely on its inputs---for instance, it cannot refer to software or
322 scripts that were not explicitly passed as inputs. A build function
323 always produces the same result when passed a given set of inputs. It
324 cannot alter the environment of the running system in
325 any way; for instance, it cannot create, modify, or delete files outside
326 of its build and installation directories. This is achieved by running
327 build processes in isolated environments (or @dfn{containers}), where only their
328 explicit inputs are visible.
329
330 @cindex store
331 The result of package build functions is @dfn{cached} in the file
332 system, in a special directory called @dfn{the store} (@pxref{The
333 Store}). Each package is installed in a directory of its own in the
334 store---by default under @file{/gnu/store}. The directory name contains
335 a hash of all the inputs used to build that package; thus, changing an
336 input yields a different directory name.
337
338 This approach is the foundation for the salient features of Guix: support
339 for transactional package upgrade and rollback, per-user installation, and
340 garbage collection of packages (@pxref{Features}).
341
342
343 @c *********************************************************************
344 @node Installation
345 @chapter Installation
346
347 @cindex installing Guix
348 GNU Guix is available for download from its website at
349 @url{http://www.gnu.org/software/guix/}. This section describes the
350 software requirements of Guix, as well as how to install it and get
351 ready to use it.
352
353 Note that this section is concerned with the installation of the package
354 manager, which can be done on top of a running GNU/Linux system. If,
355 instead, you want to install the complete GNU operating system,
356 @pxref{System Installation}.
357
358 @cindex foreign distro
359 When installed on a running GNU/Linux system---thereafter called a
360 @dfn{foreign distro}---GNU@tie{}Guix complements the available tools
361 without interference. Its data lives exclusively in two directories,
362 usually @file{/gnu/store} and @file{/var/guix}; other files on your
363 system, such as @file{/etc}, are left untouched.
364
365 Once installed, Guix can be updated by running @command{guix pull}
366 (@pxref{Invoking guix pull}).
367
368 @menu
369 * Binary Installation:: Getting Guix running in no time!
370 * Requirements:: Software needed to build and run Guix.
371 * Running the Test Suite:: Testing Guix.
372 * Setting Up the Daemon:: Preparing the build daemon's environment.
373 * Invoking guix-daemon:: Running the build daemon.
374 * Application Setup:: Application-specific setup.
375 @end menu
376
377 @node Binary Installation
378 @section Binary Installation
379
380 @cindex installing Guix from binaries
381 This section describes how to install Guix on an arbitrary system from a
382 self-contained tarball providing binaries for Guix and for all its
383 dependencies. This is often quicker than installing from source, which
384 is described in the next sections. The only requirement is to have
385 GNU@tie{}tar and Xz.
386
387 Installing goes along these lines:
388
389 @enumerate
390 @item
391 @cindex downloading Guix binary
392 Download the binary tarball from
393 @indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz},
394 where @var{system} is @code{x86_64-linux} for an @code{x86_64} machine
395 already running the kernel Linux, and so on.
396
397 @c The following is somewhat duplicated in ``System Installation''.
398 Make sure to download the associated @file{.sig} file and to verify the
399 authenticity of the tarball against it, along these lines:
400
401 @example
402 $ wget ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
403 $ gpg --verify guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
404 @end example
405
406 If that command fails because you do not have the required public key,
407 then run this command to import it:
408
409 @example
410 $ gpg --keyserver pgp.mit.edu --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
411 @end example
412
413 @noindent
414 and rerun the @code{gpg --verify} command.
415 @c end authentication part
416
417 @item
418 As @code{root}, run:
419
420 @example
421 # cd /tmp
422 # tar --warning=no-timestamp -xf \
423 guix-binary-@value{VERSION}.@var{system}.tar.xz
424 # mv var/guix /var/ && mv gnu /
425 @end example
426
427 This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
428 The latter contains a ready-to-use profile for @code{root} (see next
429 step.)
430
431 Do @emph{not} unpack the tarball on a working Guix system since that
432 would overwrite its own essential files.
433
434 The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
435 not emit warnings about ``implausibly old time stamps'' (such
436 warnings were triggered by GNU@tie{}tar 1.26 and older; recent
437 versions are fine.)
438 They stem from the fact that all the
439 files in the archive have their modification time set to zero (which
440 means January 1st, 1970.) This is done on purpose to make sure the
441 archive content is independent of its creation time, thus making it
442 reproducible.
443
444 @item
445 Make @code{root}'s profile available under @file{~/.guix-profile}:
446
447 @example
448 # ln -sf /var/guix/profiles/per-user/root/guix-profile \
449 ~root/.guix-profile
450 @end example
451
452 Source @file{etc/profile} to augment @code{PATH} and other relevant
453 environment variables:
454
455 @example
456 # GUIX_PROFILE=$HOME/.guix-profile \
457 source $GUIX_PROFILE/etc/profile
458 @end example
459
460 @item
461 Create the group and user accounts for build users as explained below
462 (@pxref{Build Environment Setup}).
463
464 @item
465 Run the daemon, and set it to automatically start on boot.
466
467 If your host distro uses the systemd init system, this can be achieved
468 with these commands:
469
470 @c Versions of systemd that supported symlinked service files are not
471 @c yet widely deployed, so we should suggest that users copy the service
472 @c files into place.
473 @c
474 @c See this thread for more information:
475 @c http://lists.gnu.org/archive/html/guix-devel/2017-01/msg01199.html
476
477 @example
478 # cp ~root/.guix-profile/lib/systemd/system/guix-daemon.service \
479 /etc/systemd/system/
480 # systemctl start guix-daemon && systemctl enable guix-daemon
481 @end example
482
483 If your host distro uses the Upstart init system:
484
485 @example
486 # initctl reload-configuration
487 # cp ~root/.guix-profile/lib/upstart/system/guix-daemon.conf /etc/init/
488 # start guix-daemon
489 @end example
490
491 Otherwise, you can still start the daemon manually with:
492
493 @example
494 # ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
495 @end example
496
497 @item
498 Make the @command{guix} command available to other users on the machine,
499 for instance with:
500
501 @example
502 # mkdir -p /usr/local/bin
503 # cd /usr/local/bin
504 # ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
505 @end example
506
507 It is also a good idea to make the Info version of this manual available
508 there:
509
510 @example
511 # mkdir -p /usr/local/share/info
512 # cd /usr/local/share/info
513 # for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
514 do ln -s $i ; done
515 @end example
516
517 That way, assuming @file{/usr/local/share/info} is in the search path,
518 running @command{info guix} will open this manual (@pxref{Other Info
519 Directories,,, texinfo, GNU Texinfo}, for more details on changing the
520 Info search path.)
521
522 @item
523 @cindex substitutes, authorization thereof
524 To use substitutes from @code{hydra.gnu.org} or one of its mirrors
525 (@pxref{Substitutes}), authorize them:
526
527 @example
528 # guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
529 @end example
530
531 @item
532 Each user may need to perform a few additional steps to make their Guix
533 environment ready for use, @pxref{Application Setup}.
534 @end enumerate
535
536 Voilà, the installation is complete!
537
538 You can confirm that Guix is working by installing a sample package into
539 the root profile:
540
541 @example
542 # guix package -i hello
543 @end example
544
545 The @code{guix} package must remain available in @code{root}'s profile,
546 or it would become subject to garbage collection---in which case you
547 would find yourself badly handicapped by the lack of the @command{guix}
548 command. In other words, do not remove @code{guix} by running
549 @code{guix package -r guix}.
550
551 The binary installation tarball can be (re)produced and verified simply
552 by running the following command in the Guix source tree:
553
554 @example
555 make guix-binary.@var{system}.tar.xz
556 @end example
557
558 @noindent
559 ... which, in turn, runs:
560
561 @example
562 guix pack -s @var{system} --localstatedir guix
563 @end example
564
565 @xref{Invoking guix pack}, for more info on this handy tool.
566
567 @node Requirements
568 @section Requirements
569
570 This section lists requirements when building Guix from source. The
571 build procedure for Guix is the same as for other GNU software, and is
572 not covered here. Please see the files @file{README} and @file{INSTALL}
573 in the Guix source tree for additional details.
574
575 GNU Guix depends on the following packages:
576
577 @itemize
578 @item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.9 or
579 later, including 2.2.x;
580 @item @url{http://gnupg.org/, GNU libgcrypt};
581 @item
582 @uref{http://gnutls.org/, GnuTLS}, specifically its Guile bindings
583 (@pxref{Guile Preparations, how to install the GnuTLS bindings for
584 Guile,, gnutls-guile, GnuTLS-Guile});
585 @item
586 @c FIXME: Specify a version number once a release has been made.
587 @uref{https://gitlab.com/guile-git/guile-git, Guile-Git}, from August
588 2017 or later;
589 @item @url{http://www.gnu.org/software/make/, GNU Make}.
590 @end itemize
591
592 The following dependencies are optional:
593
594 @itemize
595 @item
596 Installing
597 @url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
598 allow you to use the @command{guix import pypi} command (@pxref{Invoking
599 guix import}). It is of
600 interest primarily for developers and not for casual users.
601
602 @item
603 @c Note: We need at least 0.10.2 for 'channel-send-eof'.
604 Support for build offloading (@pxref{Daemon Offload Setup}) and
605 @command{guix copy} (@pxref{Invoking guix copy}) depends on
606 @uref{https://github.com/artyom-poptsov/guile-ssh, Guile-SSH},
607 version 0.10.2 or later.
608
609 @item
610 When @url{http://zlib.net, zlib} is available, @command{guix publish}
611 can compress build byproducts (@pxref{Invoking guix publish}).
612 @end itemize
613
614 Unless @code{--disable-daemon} was passed to @command{configure}, the
615 following packages are also needed:
616
617 @itemize
618 @item @url{http://sqlite.org, SQLite 3};
619 @item @url{http://www.bzip.org, libbz2};
620 @item @url{http://gcc.gnu.org, GCC's g++}, with support for the
621 C++11 standard.
622 @end itemize
623
624 @cindex state directory
625 When configuring Guix on a system that already has a Guix installation,
626 be sure to specify the same state directory as the existing installation
627 using the @code{--localstatedir} option of the @command{configure}
628 script (@pxref{Directory Variables, @code{localstatedir},, standards,
629 GNU Coding Standards}). The @command{configure} script protects against
630 unintended misconfiguration of @var{localstatedir} so you do not
631 inadvertently corrupt your store (@pxref{The Store}).
632
633 @cindex Nix, compatibility
634 When a working installation of @url{http://nixos.org/nix/, the Nix package
635 manager} is available, you
636 can instead configure Guix with @code{--disable-daemon}. In that case,
637 Nix replaces the three dependencies above.
638
639 Guix is compatible with Nix, so it is possible to share the same store
640 between both. To do so, you must pass @command{configure} not only the
641 same @code{--with-store-dir} value, but also the same
642 @code{--localstatedir} value. The latter is essential because it
643 specifies where the database that stores metadata about the store is
644 located, among other things. The default values for Nix are
645 @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
646 Note that @code{--disable-daemon} is not required if
647 your goal is to share the store with Nix.
648
649 @node Running the Test Suite
650 @section Running the Test Suite
651
652 @cindex test suite
653 After a successful @command{configure} and @code{make} run, it is a good
654 idea to run the test suite. It can help catch issues with the setup or
655 environment, or bugs in Guix itself---and really, reporting test
656 failures is a good way to help improve the software. To run the test
657 suite, type:
658
659 @example
660 make check
661 @end example
662
663 Test cases can run in parallel: you can use the @code{-j} option of
664 GNU@tie{}make to speed things up. The first run may take a few minutes
665 on a recent machine; subsequent runs will be faster because the store
666 that is created for test purposes will already have various things in
667 cache.
668
669 It is also possible to run a subset of the tests by defining the
670 @code{TESTS} makefile variable as in this example:
671
672 @example
673 make check TESTS="tests/store.scm tests/cpio.scm"
674 @end example
675
676 By default, tests results are displayed at a file level. In order to
677 see the details of every individual test cases, it is possible to define
678 the @code{SCM_LOG_DRIVER_FLAGS} makefile variable as in this example:
679
680 @example
681 make check TESTS="tests/base64.scm" SCM_LOG_DRIVER_FLAGS="--brief=no"
682 @end example
683
684 Upon failure, please email @email{bug-guix@@gnu.org} and attach the
685 @file{test-suite.log} file. Please specify the Guix version being used
686 as well as version numbers of the dependencies (@pxref{Requirements}) in
687 your message.
688
689 Guix also comes with a whole-system test suite that tests complete
690 GuixSD operating system instances. It can only run on systems where
691 Guix is already installed, using:
692
693 @example
694 make check-system
695 @end example
696
697 @noindent
698 or, again, by defining @code{TESTS} to select a subset of tests to run:
699
700 @example
701 make check-system TESTS="basic mcron"
702 @end example
703
704 These system tests are defined in the @code{(gnu tests @dots{})}
705 modules. They work by running the operating systems under test with
706 lightweight instrumentation in a virtual machine (VM). They can be
707 computationally intensive or rather cheap, depending on whether
708 substitutes are available for their dependencies (@pxref{Substitutes}).
709 Some of them require a lot of storage space to hold VM images.
710
711 Again in case of test failures, please send @email{bug-guix@@gnu.org}
712 all the details.
713
714 @node Setting Up the Daemon
715 @section Setting Up the Daemon
716
717 @cindex daemon
718 Operations such as building a package or running the garbage collector
719 are all performed by a specialized process, the @dfn{build daemon}, on
720 behalf of clients. Only the daemon may access the store and its
721 associated database. Thus, any operation that manipulates the store
722 goes through the daemon. For instance, command-line tools such as
723 @command{guix package} and @command{guix build} communicate with the
724 daemon (@i{via} remote procedure calls) to instruct it what to do.
725
726 The following sections explain how to prepare the build daemon's
727 environment. See also @ref{Substitutes}, for information on how to allow
728 the daemon to download pre-built binaries.
729
730 @menu
731 * Build Environment Setup:: Preparing the isolated build environment.
732 * Daemon Offload Setup:: Offloading builds to remote machines.
733 @end menu
734
735 @node Build Environment Setup
736 @subsection Build Environment Setup
737
738 @cindex build environment
739 In a standard multi-user setup, Guix and its daemon---the
740 @command{guix-daemon} program---are installed by the system
741 administrator; @file{/gnu/store} is owned by @code{root} and
742 @command{guix-daemon} runs as @code{root}. Unprivileged users may use
743 Guix tools to build packages or otherwise access the store, and the
744 daemon will do it on their behalf, ensuring that the store is kept in a
745 consistent state, and allowing built packages to be shared among users.
746
747 @cindex build users
748 When @command{guix-daemon} runs as @code{root}, you may not want package
749 build processes themselves to run as @code{root} too, for obvious
750 security reasons. To avoid that, a special pool of @dfn{build users}
751 should be created for use by build processes started by the daemon.
752 These build users need not have a shell and a home directory: they will
753 just be used when the daemon drops @code{root} privileges in build
754 processes. Having several such users allows the daemon to launch
755 distinct build processes under separate UIDs, which guarantees that they
756 do not interfere with each other---an essential feature since builds are
757 regarded as pure functions (@pxref{Introduction}).
758
759 On a GNU/Linux system, a build user pool may be created like this (using
760 Bash syntax and the @code{shadow} commands):
761
762 @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
763 @c for why `-G' is needed.
764 @example
765 # groupadd --system guixbuild
766 # for i in `seq -w 1 10`;
767 do
768 useradd -g guixbuild -G guixbuild \
769 -d /var/empty -s `which nologin` \
770 -c "Guix build user $i" --system \
771 guixbuilder$i;
772 done
773 @end example
774
775 @noindent
776 The number of build users determines how many build jobs may run in
777 parallel, as specified by the @option{--max-jobs} option
778 (@pxref{Invoking guix-daemon, @option{--max-jobs}}). To use
779 @command{guix system vm} and related commands, you may need to add the
780 build users to the @code{kvm} group so they can access @file{/dev/kvm},
781 using @code{-G guixbuild,kvm} instead of @code{-G guixbuild}
782 (@pxref{Invoking guix system}).
783
784 The @code{guix-daemon} program may then be run as @code{root} with the
785 following command@footnote{If your machine uses the systemd init system,
786 dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
787 file in @file{/etc/systemd/system} will ensure that
788 @command{guix-daemon} is automatically started. Similarly, if your
789 machine uses the Upstart init system, drop the
790 @file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
791 file in @file{/etc/init}.}:
792
793 @example
794 # guix-daemon --build-users-group=guixbuild
795 @end example
796
797 @cindex chroot
798 @noindent
799 This way, the daemon starts build processes in a chroot, under one of
800 the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
801 environment contains nothing but:
802
803 @c Keep this list in sync with libstore/build.cc! -----------------------
804 @itemize
805 @item
806 a minimal @code{/dev} directory, created mostly independently from the
807 host @code{/dev}@footnote{``Mostly'', because while the set of files
808 that appear in the chroot's @code{/dev} is fixed, most of these files
809 can only be created if the host has them.};
810
811 @item
812 the @code{/proc} directory; it only shows the processes of the container
813 since a separate PID name space is used;
814
815 @item
816 @file{/etc/passwd} with an entry for the current user and an entry for
817 user @file{nobody};
818
819 @item
820 @file{/etc/group} with an entry for the user's group;
821
822 @item
823 @file{/etc/hosts} with an entry that maps @code{localhost} to
824 @code{127.0.0.1};
825
826 @item
827 a writable @file{/tmp} directory.
828 @end itemize
829
830 You can influence the directory where the daemon stores build trees
831 @i{via} the @code{TMPDIR} environment variable. However, the build tree
832 within the chroot is always called @file{/tmp/guix-build-@var{name}.drv-0},
833 where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
834 This way, the value of @code{TMPDIR} does not leak inside build
835 environments, which avoids discrepancies in cases where build processes
836 capture the name of their build tree.
837
838 @vindex http_proxy
839 The daemon also honors the @code{http_proxy} environment variable for
840 HTTP downloads it performs, be it for fixed-output derivations
841 (@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
842
843 If you are installing Guix as an unprivileged user, it is still possible
844 to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
845 However, build processes will not be isolated from one another, and not
846 from the rest of the system. Thus, build processes may interfere with
847 each other, and may access programs, libraries, and other files
848 available on the system---making it much harder to view them as
849 @emph{pure} functions.
850
851
852 @node Daemon Offload Setup
853 @subsection Using the Offload Facility
854
855 @cindex offloading
856 @cindex build hook
857 When desired, the build daemon can @dfn{offload} derivation builds to
858 other machines running Guix, using the @code{offload} @dfn{build
859 hook}@footnote{This feature is available only when
860 @uref{https://github.com/artyom-poptsov/guile-ssh, Guile-SSH} is
861 present.}. When that
862 feature is enabled, a list of user-specified build machines is read from
863 @file{/etc/guix/machines.scm}; every time a build is requested, for
864 instance via @code{guix build}, the daemon attempts to offload it to one
865 of the machines that satisfy the constraints of the derivation, in
866 particular its system type---e.g., @file{x86_64-linux}. Missing
867 prerequisites for the build are copied over SSH to the target machine,
868 which then proceeds with the build; upon success the output(s) of the
869 build are copied back to the initial machine.
870
871 The @file{/etc/guix/machines.scm} file typically looks like this:
872
873 @example
874 (list (build-machine
875 (name "eightysix.example.org")
876 (system "x86_64-linux")
877 (host-key "ssh-ed25519 AAAAC3Nza@dots{}")
878 (user "bob")
879 (speed 2.)) ;incredibly fast!
880
881 (build-machine
882 (name "meeps.example.org")
883 (system "mips64el-linux")
884 (host-key "ssh-rsa AAAAB3Nza@dots{}")
885 (user "alice")
886 (private-key
887 (string-append (getenv "HOME")
888 "/.ssh/identity-for-guix"))))
889 @end example
890
891 @noindent
892 In the example above we specify a list of two build machines, one for
893 the @code{x86_64} architecture and one for the @code{mips64el}
894 architecture.
895
896 In fact, this file is---not surprisingly!---a Scheme file that is
897 evaluated when the @code{offload} hook is started. Its return value
898 must be a list of @code{build-machine} objects. While this example
899 shows a fixed list of build machines, one could imagine, say, using
900 DNS-SD to return a list of potential build machines discovered in the
901 local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
902 Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
903 detailed below.
904
905 @deftp {Data Type} build-machine
906 This data type represents build machines to which the daemon may offload
907 builds. The important fields are:
908
909 @table @code
910
911 @item name
912 The host name of the remote machine.
913
914 @item system
915 The system type of the remote machine---e.g., @code{"x86_64-linux"}.
916
917 @item user
918 The user account to use when connecting to the remote machine over SSH.
919 Note that the SSH key pair must @emph{not} be passphrase-protected, to
920 allow non-interactive logins.
921
922 @item host-key
923 This must be the machine's SSH @dfn{public host key} in OpenSSH format.
924 This is used to authenticate the machine when we connect to it. It is a
925 long string that looks like this:
926
927 @example
928 ssh-ed25519 AAAAC3NzaC@dots{}mde+UhL hint@@example.org
929 @end example
930
931 If the machine is running the OpenSSH daemon, @command{sshd}, the host
932 key can be found in a file such as
933 @file{/etc/ssh/ssh_host_ed25519_key.pub}.
934
935 If the machine is running the SSH daemon of GNU@tie{}lsh,
936 @command{lshd}, the host key is in @file{/etc/lsh/host-key.pub} or a
937 similar file. It can be converted to the OpenSSH format using
938 @command{lsh-export-key} (@pxref{Converting keys,,, lsh, LSH Manual}):
939
940 @example
941 $ lsh-export-key --openssh < /etc/lsh/host-key.pub
942 ssh-rsa AAAAB3NzaC1yc2EAAAAEOp8FoQAAAQEAs1eB46LV@dots{}
943 @end example
944
945 @end table
946
947 A number of optional fields may be specified:
948
949 @table @asis
950
951 @item @code{port} (default: @code{22})
952 Port number of SSH server on the machine.
953
954 @item @code{private-key} (default: @file{~root/.ssh/id_rsa})
955 The SSH private key file to use when connecting to the machine, in
956 OpenSSH format.
957
958 Note that the default value is the private key @emph{of the root
959 account}. Make sure it exists if you use the default.
960
961 @item @code{compression} (default: @code{"zlib@@openssh.com,zlib"})
962 @itemx @code{compression-level} (default: @code{3})
963 The SSH-level compression methods and compression level requested.
964
965 Note that offloading relies on SSH compression to reduce bandwidth usage
966 when transferring files to and from build machines.
967
968 @item @code{daemon-socket} (default: @code{"/var/guix/daemon-socket/socket"})
969 File name of the Unix-domain socket @command{guix-daemon} is listening
970 to on that machine.
971
972 @item @code{parallel-builds} (default: @code{1})
973 The number of builds that may run in parallel on the machine.
974
975 @item @code{speed} (default: @code{1.0})
976 A ``relative speed factor''. The offload scheduler will tend to prefer
977 machines with a higher speed factor.
978
979 @item @code{features} (default: @code{'()})
980 A list of strings denoting specific features supported by the machine.
981 An example is @code{"kvm"} for machines that have the KVM Linux modules
982 and corresponding hardware support. Derivations can request features by
983 name, and they will be scheduled on matching build machines.
984
985 @end table
986 @end deftp
987
988 The @code{guile} command must be in the search path on the build
989 machines. In addition, the Guix modules must be in
990 @code{$GUILE_LOAD_PATH} on the build machine---you can check whether
991 this is the case by running:
992
993 @example
994 ssh build-machine guile -c "'(use-modules (guix config))'"
995 @end example
996
997 There is one last thing to do once @file{machines.scm} is in place. As
998 explained above, when offloading, files are transferred back and forth
999 between the machine stores. For this to work, you first need to
1000 generate a key pair on each machine to allow the daemon to export signed
1001 archives of files from the store (@pxref{Invoking guix archive}):
1002
1003 @example
1004 # guix archive --generate-key
1005 @end example
1006
1007 @noindent
1008 Each build machine must authorize the key of the master machine so that
1009 it accepts store items it receives from the master:
1010
1011 @example
1012 # guix archive --authorize < master-public-key.txt
1013 @end example
1014
1015 @noindent
1016 Likewise, the master machine must authorize the key of each build machine.
1017
1018 All the fuss with keys is here to express pairwise mutual trust
1019 relations between the master and the build machines. Concretely, when
1020 the master receives files from a build machine (and @i{vice versa}), its
1021 build daemon can make sure they are genuine, have not been tampered
1022 with, and that they are signed by an authorized key.
1023
1024 @cindex offload test
1025 To test whether your setup is operational, run this command on the
1026 master node:
1027
1028 @example
1029 # guix offload test
1030 @end example
1031
1032 This will attempt to connect to each of the build machines specified in
1033 @file{/etc/guix/machines.scm}, make sure Guile and the Guix modules are
1034 available on each machine, attempt to export to the machine and import
1035 from it, and report any error in the process.
1036
1037 If you want to test a different machine file, just specify it on the
1038 command line:
1039
1040 @example
1041 # guix offload test machines-qualif.scm
1042 @end example
1043
1044 Last, you can test the subset of the machines whose name matches a
1045 regular expression like this:
1046
1047 @example
1048 # guix offload test machines.scm '\.gnu\.org$'
1049 @end example
1050
1051 @node Invoking guix-daemon
1052 @section Invoking @command{guix-daemon}
1053
1054 The @command{guix-daemon} program implements all the functionality to
1055 access the store. This includes launching build processes, running the
1056 garbage collector, querying the availability of a build result, etc. It
1057 is normally run as @code{root} like this:
1058
1059 @example
1060 # guix-daemon --build-users-group=guixbuild
1061 @end example
1062
1063 @noindent
1064 For details on how to set it up, @pxref{Setting Up the Daemon}.
1065
1066 @cindex chroot
1067 @cindex container, build environment
1068 @cindex build environment
1069 @cindex reproducible builds
1070 By default, @command{guix-daemon} launches build processes under
1071 different UIDs, taken from the build group specified with
1072 @code{--build-users-group}. In addition, each build process is run in a
1073 chroot environment that only contains the subset of the store that the
1074 build process depends on, as specified by its derivation
1075 (@pxref{Programming Interface, derivation}), plus a set of specific
1076 system directories. By default, the latter contains @file{/dev} and
1077 @file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
1078 @dfn{container}: in addition to having its own file system tree, it has
1079 a separate mount name space, its own PID name space, network name space,
1080 etc. This helps achieve reproducible builds (@pxref{Features}).
1081
1082 When the daemon performs a build on behalf of the user, it creates a
1083 build directory under @file{/tmp} or under the directory specified by
1084 its @code{TMPDIR} environment variable; this directory is shared with
1085 the container for the duration of the build. Be aware that using a
1086 directory other than @file{/tmp} can affect build results---for example,
1087 with a longer directory name, a build process that uses Unix-domain
1088 sockets might hit the name length limitation for @code{sun_path}, which
1089 it would otherwise not hit.
1090
1091 The build directory is automatically deleted upon completion, unless the
1092 build failed and the client specified @option{--keep-failed}
1093 (@pxref{Invoking guix build, @option{--keep-failed}}).
1094
1095 The following command-line options are supported:
1096
1097 @table @code
1098 @item --build-users-group=@var{group}
1099 Take users from @var{group} to run build processes (@pxref{Setting Up
1100 the Daemon, build users}).
1101
1102 @item --no-substitutes
1103 @cindex substitutes
1104 Do not use substitutes for build products. That is, always build things
1105 locally instead of allowing downloads of pre-built binaries
1106 (@pxref{Substitutes}).
1107
1108 By default substitutes are used, unless the client---such as the
1109 @command{guix package} command---is explicitly invoked with
1110 @code{--no-substitutes}.
1111
1112 When the daemon runs with @code{--no-substitutes}, clients can still
1113 explicitly enable substitution @i{via} the @code{set-build-options}
1114 remote procedure call (@pxref{The Store}).
1115
1116 @item --substitute-urls=@var{urls}
1117 @anchor{daemon-substitute-urls}
1118 Consider @var{urls} the default whitespace-separated list of substitute
1119 source URLs. When this option is omitted,
1120 @indicateurl{https://mirror.hydra.gnu.org https://hydra.gnu.org} is used
1121 (@code{mirror.hydra.gnu.org} is a mirror of @code{hydra.gnu.org}).
1122
1123 This means that substitutes may be downloaded from @var{urls}, as long
1124 as they are signed by a trusted signature (@pxref{Substitutes}).
1125
1126 @cindex build hook
1127 @item --no-build-hook
1128 Do not use the @dfn{build hook}.
1129
1130 The build hook is a helper program that the daemon can start and to
1131 which it submits build requests. This mechanism is used to offload
1132 builds to other machines (@pxref{Daemon Offload Setup}).
1133
1134 @item --cache-failures
1135 Cache build failures. By default, only successful builds are cached.
1136
1137 When this option is used, @command{guix gc --list-failures} can be used
1138 to query the set of store items marked as failed; @command{guix gc
1139 --clear-failures} removes store items from the set of cached failures.
1140 @xref{Invoking guix gc}.
1141
1142 @item --cores=@var{n}
1143 @itemx -c @var{n}
1144 Use @var{n} CPU cores to build each derivation; @code{0} means as many
1145 as available.
1146
1147 The default value is @code{0}, but it may be overridden by clients, such
1148 as the @code{--cores} option of @command{guix build} (@pxref{Invoking
1149 guix build}).
1150
1151 The effect is to define the @code{NIX_BUILD_CORES} environment variable
1152 in the build process, which can then use it to exploit internal
1153 parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
1154
1155 @item --max-jobs=@var{n}
1156 @itemx -M @var{n}
1157 Allow at most @var{n} build jobs in parallel. The default value is
1158 @code{1}. Setting it to @code{0} means that no builds will be performed
1159 locally; instead, the daemon will offload builds (@pxref{Daemon Offload
1160 Setup}), or simply fail.
1161
1162 @item --max-silent-time=@var{seconds}
1163 When the build or substitution process remains silent for more than
1164 @var{seconds}, terminate it and report a build failure.
1165
1166 The default value is @code{0}, which disables the timeout.
1167
1168 The value specified here can be overridden by clients (@pxref{Common
1169 Build Options, @code{--max-silent-time}}).
1170
1171 @item --timeout=@var{seconds}
1172 Likewise, when the build or substitution process lasts for more than
1173 @var{seconds}, terminate it and report a build failure.
1174
1175 The default value is @code{0}, which disables the timeout.
1176
1177 The value specified here can be overridden by clients (@pxref{Common
1178 Build Options, @code{--timeout}}).
1179
1180 @item --rounds=@var{N}
1181 Build each derivation @var{n} times in a row, and raise an error if
1182 consecutive build results are not bit-for-bit identical. Note that this
1183 setting can be overridden by clients such as @command{guix build}
1184 (@pxref{Invoking guix build}).
1185
1186 When used in conjunction with @option{--keep-failed}, the differing
1187 output is kept in the store, under @file{/gnu/store/@dots{}-check}.
1188 This makes it easy to look for differences between the two results.
1189
1190 @item --debug
1191 Produce debugging output.
1192
1193 This is useful to debug daemon start-up issues, but then it may be
1194 overridden by clients, for example the @code{--verbosity} option of
1195 @command{guix build} (@pxref{Invoking guix build}).
1196
1197 @item --chroot-directory=@var{dir}
1198 Add @var{dir} to the build chroot.
1199
1200 Doing this may change the result of build processes---for instance if
1201 they use optional dependencies found in @var{dir} when it is available,
1202 and not otherwise. For that reason, it is not recommended to do so.
1203 Instead, make sure that each derivation declares all the inputs that it
1204 needs.
1205
1206 @item --disable-chroot
1207 Disable chroot builds.
1208
1209 Using this option is not recommended since, again, it would allow build
1210 processes to gain access to undeclared dependencies. It is necessary,
1211 though, when @command{guix-daemon} is running under an unprivileged user
1212 account.
1213
1214 @item --disable-log-compression
1215 Disable compression of the build logs.
1216
1217 Unless @code{--lose-logs} is used, all the build logs are kept in the
1218 @var{localstatedir}. To save space, the daemon automatically compresses
1219 them with bzip2 by default. This option disables that.
1220
1221 @item --disable-deduplication
1222 @cindex deduplication
1223 Disable automatic file ``deduplication'' in the store.
1224
1225 By default, files added to the store are automatically ``deduplicated'':
1226 if a newly added file is identical to another one found in the store,
1227 the daemon makes the new file a hard link to the other file. This can
1228 noticeably reduce disk usage, at the expense of slightly increased
1229 input/output load at the end of a build process. This option disables
1230 this optimization.
1231
1232 @item --gc-keep-outputs[=yes|no]
1233 Tell whether the garbage collector (GC) must keep outputs of live
1234 derivations.
1235
1236 When set to ``yes'', the GC will keep the outputs of any live derivation
1237 available in the store---the @code{.drv} files. The default is ``no'',
1238 meaning that derivation outputs are kept only if they are GC roots.
1239
1240 @item --gc-keep-derivations[=yes|no]
1241 Tell whether the garbage collector (GC) must keep derivations
1242 corresponding to live outputs.
1243
1244 When set to ``yes'', as is the case by default, the GC keeps
1245 derivations---i.e., @code{.drv} files---as long as at least one of their
1246 outputs is live. This allows users to keep track of the origins of
1247 items in their store. Setting it to ``no'' saves a bit of disk space.
1248
1249 Note that when both @code{--gc-keep-derivations} and
1250 @code{--gc-keep-outputs} are used, the effect is to keep all the build
1251 prerequisites (the sources, compiler, libraries, and other build-time
1252 tools) of live objects in the store, regardless of whether these
1253 prerequisites are live. This is convenient for developers since it
1254 saves rebuilds or downloads.
1255
1256 @item --impersonate-linux-2.6
1257 On Linux-based systems, impersonate Linux 2.6. This means that the
1258 kernel's @code{uname} system call will report 2.6 as the release number.
1259
1260 This might be helpful to build programs that (usually wrongfully) depend
1261 on the kernel version number.
1262
1263 @item --lose-logs
1264 Do not keep build logs. By default they are kept under
1265 @code{@var{localstatedir}/guix/log}.
1266
1267 @item --system=@var{system}
1268 Assume @var{system} as the current system type. By default it is the
1269 architecture/kernel pair found at configure time, such as
1270 @code{x86_64-linux}.
1271
1272 @item --listen=@var{endpoint}
1273 Listen for connections on @var{endpoint}. @var{endpoint} is interpreted
1274 as the file name of a Unix-domain socket if it starts with
1275 @code{/} (slash sign). Otherwise, @var{endpoint} is interpreted as a
1276 host name or host name and port to listen to. Here are a few examples:
1277
1278 @table @code
1279 @item --listen=/gnu/var/daemon
1280 Listen for connections on the @file{/gnu/var/daemon} Unix-domain socket,
1281 creating it if needed.
1282
1283 @item --listen=localhost
1284 @cindex daemon, remote access
1285 @cindex remote access to the daemon
1286 @cindex daemon, cluster setup
1287 @cindex clusters, daemon setup
1288 Listen for TCP connections on the network interface corresponding to
1289 @code{localhost}, on port 44146.
1290
1291 @item --listen=128.0.0.42:1234
1292 Listen for TCP connections on the network interface corresponding to
1293 @code{128.0.0.42}, on port 1234.
1294 @end table
1295
1296 This option can be repeated multiple times, in which case
1297 @command{guix-daemon} accepts connections on all the specified
1298 endpoints. Users can tell client commands what endpoint to connect to
1299 by setting the @code{GUIX_DAEMON_SOCKET} environment variable
1300 (@pxref{The Store, @code{GUIX_DAEMON_SOCKET}}).
1301
1302 @quotation Note
1303 The daemon protocol is @emph{unauthenticated and unencrypted}. Using
1304 @code{--listen=@var{host}} is suitable on local networks, such as
1305 clusters, where only trusted nodes may connect to the build daemon. In
1306 other cases where remote access to the daemon is needed, we recommend
1307 using Unix-domain sockets along with SSH.
1308 @end quotation
1309
1310 When @code{--listen} is omitted, @command{guix-daemon} listens for
1311 connections on the Unix-domain socket located at
1312 @file{@var{localstatedir}/daemon-socket/socket}.
1313 @end table
1314
1315
1316 @node Application Setup
1317 @section Application Setup
1318
1319 @cindex foreign distro
1320 When using Guix on top of GNU/Linux distribution other than GuixSD---a
1321 so-called @dfn{foreign distro}---a few additional steps are needed to
1322 get everything in place. Here are some of them.
1323
1324 @subsection Locales
1325
1326 @anchor{locales-and-locpath}
1327 @cindex locales, when not on GuixSD
1328 @vindex LOCPATH
1329 @vindex GUIX_LOCPATH
1330 Packages installed @i{via} Guix will not use the locale data of the
1331 host system. Instead, you must first install one of the locale packages
1332 available with Guix and then define the @code{GUIX_LOCPATH} environment
1333 variable:
1334
1335 @example
1336 $ guix package -i glibc-locales
1337 $ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
1338 @end example
1339
1340 Note that the @code{glibc-locales} package contains data for all the
1341 locales supported by the GNU@tie{}libc and weighs in at around
1342 110@tie{}MiB. Alternatively, the @code{glibc-utf8-locales} is smaller but
1343 limited to a few UTF-8 locales.
1344
1345 The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1346 (@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1347 Manual}). There are two important differences though:
1348
1349 @enumerate
1350 @item
1351 @code{GUIX_LOCPATH} is honored only by the libc in Guix, and not by the libc
1352 provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
1353 to make sure the programs of the foreign distro will not end up loading
1354 incompatible locale data.
1355
1356 @item
1357 libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1358 @code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1359 should your Guix profile contain a mixture of programs linked against
1360 different libc version, each libc version will only try to load locale
1361 data in the right format.
1362 @end enumerate
1363
1364 This is important because the locale data format used by different libc
1365 versions may be incompatible.
1366
1367 @subsection Name Service Switch
1368
1369 @cindex name service switch, glibc
1370 @cindex NSS (name service switch), glibc
1371 @cindex nscd (name service caching daemon)
1372 @cindex name service caching daemon (nscd)
1373 When using Guix on a foreign distro, we @emph{strongly recommend} that
1374 the system run the GNU C library's @dfn{name service cache daemon},
1375 @command{nscd}, which should be listening on the
1376 @file{/var/run/nscd/socket} socket. Failing to do that, applications
1377 installed with Guix may fail to look up host names or user accounts, or
1378 may even crash. The next paragraphs explain why.
1379
1380 @cindex @file{nsswitch.conf}
1381 The GNU C library implements a @dfn{name service switch} (NSS), which is
1382 an extensible mechanism for ``name lookups'' in general: host name
1383 resolution, user accounts, and more (@pxref{Name Service Switch,,, libc,
1384 The GNU C Library Reference Manual}).
1385
1386 @cindex Network information service (NIS)
1387 @cindex NIS (Network information service)
1388 Being extensible, the NSS supports @dfn{plugins}, which provide new name
1389 lookup implementations: for example, the @code{nss-mdns} plugin allow
1390 resolution of @code{.local} host names, the @code{nis} plugin allows
1391 user account lookup using the Network information service (NIS), and so
1392 on. These extra ``lookup services'' are configured system-wide in
1393 @file{/etc/nsswitch.conf}, and all the programs running on the system
1394 honor those settings (@pxref{NSS Configuration File,,, libc, The GNU C
1395 Reference Manual}).
1396
1397 When they perform a name lookup---for instance by calling the
1398 @code{getaddrinfo} function in C---applications first try to connect to
1399 the nscd; on success, nscd performs name lookups on their behalf. If
1400 the nscd is not running, then they perform the name lookup by
1401 themselves, by loading the name lookup services into their own address
1402 space and running it. These name lookup services---the
1403 @file{libnss_*.so} files---are @code{dlopen}'d, but they may come from
1404 the host system's C library, rather than from the C library the
1405 application is linked against (the C library coming from Guix).
1406
1407 And this is where the problem is: if your application is linked against
1408 Guix's C library (say, glibc 2.24) and tries to load NSS plugins from
1409 another C library (say, @code{libnss_mdns.so} for glibc 2.22), it will
1410 likely crash or have its name lookups fail unexpectedly.
1411
1412 Running @command{nscd} on the system, among other advantages, eliminates
1413 this binary incompatibility problem because those @code{libnss_*.so}
1414 files are loaded in the @command{nscd} process, not in applications
1415 themselves.
1416
1417 @subsection X11 Fonts
1418
1419 @cindex fonts
1420 The majority of graphical applications use Fontconfig to locate and
1421 load fonts and perform X11-client-side rendering. The @code{fontconfig}
1422 package in Guix looks for fonts in @file{$HOME/.guix-profile}
1423 by default. Thus, to allow graphical applications installed with Guix
1424 to display fonts, you have to install fonts with Guix as well.
1425 Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
1426 @code{font-gnu-freefont-ttf}.
1427
1428 To display text written in Chinese languages, Japanese, or Korean in
1429 graphical applications, consider installing
1430 @code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1431 has multiple outputs, one per language family (@pxref{Packages with
1432 Multiple Outputs}). For instance, the following command installs fonts
1433 for Chinese languages:
1434
1435 @example
1436 guix package -i font-adobe-source-han-sans:cn
1437 @end example
1438
1439 @cindex @code{xterm}
1440 Older programs such as @command{xterm} do not use Fontconfig and instead
1441 rely on server-side font rendering. Such programs require to specify a
1442 full name of a font using XLFD (X Logical Font Description), like this:
1443
1444 @example
1445 -*-dejavu sans-medium-r-normal-*-*-100-*-*-*-*-*-1
1446 @end example
1447
1448 To be able to use such full names for the TrueType fonts installed in
1449 your Guix profile, you need to extend the font path of the X server:
1450
1451 @example
1452 xset +fp ~/.guix-profile/share/fonts/truetype
1453 @end example
1454
1455 @cindex @code{xlsfonts}
1456 After that, you can run @code{xlsfonts} (from @code{xlsfonts} package)
1457 to make sure your TrueType fonts are listed there.
1458
1459 @cindex @code{fc-cache}
1460 @cindex font cache
1461 After installing fonts you may have to refresh the font cache to use
1462 them in applications. The same applies when applications installed via
1463 Guix do not seem to find fonts. To force rebuilding of the font cache
1464 run @code{fc-cache -f}. The @code{fc-cache} command is provided by the
1465 @code{fontconfig} package.
1466
1467 @subsection X.509 Certificates
1468
1469 @cindex @code{nss-certs}
1470 The @code{nss-certs} package provides X.509 certificates, which allow
1471 programs to authenticate Web servers accessed over HTTPS.
1472
1473 When using Guix on a foreign distro, you can install this package and
1474 define the relevant environment variables so that packages know where to
1475 look for certificates. @xref{X.509 Certificates}, for detailed
1476 information.
1477
1478 @subsection Emacs Packages
1479
1480 @cindex @code{emacs}
1481 When you install Emacs packages with Guix, the elisp files may be placed
1482 either in @file{$HOME/.guix-profile/share/emacs/site-lisp/} or in
1483 sub-directories of
1484 @file{$HOME/.guix-profile/share/emacs/site-lisp/guix.d/}. The latter
1485 directory exists because potentially there may exist thousands of Emacs
1486 packages and storing all their files in a single directory may be not
1487 reliable (because of name conflicts). So we think using a separate
1488 directory for each package is a good idea. It is very similar to how
1489 the Emacs package system organizes the file structure (@pxref{Package
1490 Files,,, emacs, The GNU Emacs Manual}).
1491
1492 By default, Emacs (installed with Guix) ``knows'' where these packages
1493 are placed, so you do not need to perform any configuration. If, for
1494 some reason, you want to avoid auto-loading Emacs packages installed
1495 with Guix, you can do so by running Emacs with @code{--no-site-file}
1496 option (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
1497
1498 @subsection The GCC toolchain
1499
1500 @cindex GCC
1501 @cindex ld-wrapper
1502
1503 Guix offers individual compiler packages such as @code{gcc} but if you
1504 are in need of a complete toolchain for compiling and linking source
1505 code what you really want is the @code{gcc-toolchain} package. This
1506 package provides a complete GCC toolchain for C/C++ development,
1507 including GCC itself, the GNU C Library (headers and binaries, plus
1508 debugging symbols in the @code{debug} output), Binutils, and a linker
1509 wrapper.
1510
1511 @cindex attempt to use impure library, error message
1512
1513 The wrapper's purpose is to inspect the @code{-L} and @code{-l} switches
1514 passed to the linker, add corresponding @code{-rpath} arguments, and
1515 invoke the actual linker with this new set of arguments. By default,
1516 the linker wrapper refuses to link to libraries outside the store to
1517 ensure ``purity''. This can be annoying when using the toolchain to
1518 link with local libraries. To allow references to libraries outside the
1519 store you need to define the environment variable
1520 @code{GUIX_LD_WRAPPER_ALLOW_IMPURITIES}.
1521
1522 @c TODO What else?
1523
1524 @c *********************************************************************
1525 @node Package Management
1526 @chapter Package Management
1527
1528 @cindex packages
1529 The purpose of GNU Guix is to allow users to easily install, upgrade, and
1530 remove software packages, without having to know about their build
1531 procedures or dependencies. Guix also goes beyond this obvious set of
1532 features.
1533
1534 This chapter describes the main features of Guix, as well as the
1535 package management tools it provides. Along with the command-line
1536 interface described below (@pxref{Invoking guix package, @code{guix
1537 package}}), you may also use Emacs Interface (@pxref{Top,,,
1538 emacs-guix, The Emacs-Guix Reference Manual}), after installing
1539 @code{emacs-guix} package (run @kbd{M-x guix-help} command to start
1540 with it):
1541
1542 @example
1543 guix package -i emacs-guix
1544 @end example
1545
1546 @menu
1547 * Features:: How Guix will make your life brighter.
1548 * Invoking guix package:: Package installation, removal, etc.
1549 * Substitutes:: Downloading pre-built binaries.
1550 * Packages with Multiple Outputs:: Single source package, multiple outputs.
1551 * Invoking guix gc:: Running the garbage collector.
1552 * Invoking guix pull:: Fetching the latest Guix and distribution.
1553 * Invoking guix pack:: Creating software bundles.
1554 * Invoking guix archive:: Exporting and importing store files.
1555 @end menu
1556
1557 @node Features
1558 @section Features
1559
1560 When using Guix, each package ends up in the @dfn{package store}, in its
1561 own directory---something that resembles
1562 @file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string.
1563
1564 Instead of referring to these directories, users have their own
1565 @dfn{profile}, which points to the packages that they actually want to
1566 use. These profiles are stored within each user's home directory, at
1567 @code{$HOME/.guix-profile}.
1568
1569 For example, @code{alice} installs GCC 4.7.2. As a result,
1570 @file{/home/alice/.guix-profile/bin/gcc} points to
1571 @file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
1572 @code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1573 simply continues to point to
1574 @file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
1575 coexist on the same system without any interference.
1576
1577 The @command{guix package} command is the central tool to manage
1578 packages (@pxref{Invoking guix package}). It operates on the per-user
1579 profiles, and can be used @emph{with normal user privileges}.
1580
1581 @cindex transactions
1582 The command provides the obvious install, remove, and upgrade
1583 operations. Each invocation is actually a @emph{transaction}: either
1584 the specified operation succeeds, or nothing happens. Thus, if the
1585 @command{guix package} process is terminated during the transaction,
1586 or if a power outage occurs during the transaction, then the user's
1587 profile remains in its previous state, and remains usable.
1588
1589 In addition, any package transaction may be @emph{rolled back}. So, if,
1590 for example, an upgrade installs a new version of a package that turns
1591 out to have a serious bug, users may roll back to the previous instance
1592 of their profile, which was known to work well. Similarly, the global
1593 system configuration on GuixSD is subject to
1594 transactional upgrades and roll-back
1595 (@pxref{Using the Configuration System}).
1596
1597 All packages in the package store may be @emph{garbage-collected}.
1598 Guix can determine which packages are still referenced by user
1599 profiles, and remove those that are provably no longer referenced
1600 (@pxref{Invoking guix gc}). Users may also explicitly remove old
1601 generations of their profile so that the packages they refer to can be
1602 collected.
1603
1604 @cindex reproducibility
1605 @cindex reproducible builds
1606 Finally, Guix takes a @dfn{purely functional} approach to package
1607 management, as described in the introduction (@pxref{Introduction}).
1608 Each @file{/gnu/store} package directory name contains a hash of all the
1609 inputs that were used to build that package---compiler, libraries, build
1610 scripts, etc. This direct correspondence allows users to make sure a
1611 given package installation matches the current state of their
1612 distribution. It also helps maximize @dfn{build reproducibility}:
1613 thanks to the isolated build environments that are used, a given build
1614 is likely to yield bit-identical files when performed on different
1615 machines (@pxref{Invoking guix-daemon, container}).
1616
1617 @cindex substitutes
1618 This foundation allows Guix to support @dfn{transparent binary/source
1619 deployment}. When a pre-built binary for a @file{/gnu/store} item is
1620 available from an external source---a @dfn{substitute}, Guix just
1621 downloads it and unpacks it;
1622 otherwise, it builds the package from source, locally
1623 (@pxref{Substitutes}). Because build results are usually bit-for-bit
1624 reproducible, users do not have to trust servers that provide
1625 substitutes: they can force a local build and @emph{challenge} providers
1626 (@pxref{Invoking guix challenge}).
1627
1628 Control over the build environment is a feature that is also useful for
1629 developers. The @command{guix environment} command allows developers of
1630 a package to quickly set up the right development environment for their
1631 package, without having to manually install the dependencies of the
1632 package into their profile (@pxref{Invoking guix environment}).
1633
1634 @node Invoking guix package
1635 @section Invoking @command{guix package}
1636
1637 @cindex installing packages
1638 @cindex removing packages
1639 @cindex package installation
1640 @cindex package removal
1641 The @command{guix package} command is the tool that allows users to
1642 install, upgrade, and remove packages, as well as rolling back to
1643 previous configurations. It operates only on the user's own profile,
1644 and works with normal user privileges (@pxref{Features}). Its syntax
1645 is:
1646
1647 @example
1648 guix package @var{options}
1649 @end example
1650 @cindex transactions
1651 Primarily, @var{options} specifies the operations to be performed during
1652 the transaction. Upon completion, a new profile is created, but
1653 previous @dfn{generations} of the profile remain available, should the user
1654 want to roll back.
1655
1656 For example, to remove @code{lua} and install @code{guile} and
1657 @code{guile-cairo} in a single transaction:
1658
1659 @example
1660 guix package -r lua -i guile guile-cairo
1661 @end example
1662
1663 @command{guix package} also supports a @dfn{declarative approach}
1664 whereby the user specifies the exact set of packages to be available and
1665 passes it @i{via} the @option{--manifest} option
1666 (@pxref{profile-manifest, @option{--manifest}}).
1667
1668 @cindex profile
1669 For each user, a symlink to the user's default profile is automatically
1670 created in @file{$HOME/.guix-profile}. This symlink always points to the
1671 current generation of the user's default profile. Thus, users can add
1672 @file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1673 variable, and so on.
1674 @cindex search paths
1675 If you are not using the Guix System Distribution, consider adding the
1676 following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1677 Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1678 shells get all the right environment variable definitions:
1679
1680 @example
1681 GUIX_PROFILE="$HOME/.guix-profile" \
1682 source "$HOME/.guix-profile/etc/profile"
1683 @end example
1684
1685 In a multi-user setup, user profiles are stored in a place registered as
1686 a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1687 to (@pxref{Invoking guix gc}). That directory is normally
1688 @code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1689 @var{localstatedir} is the value passed to @code{configure} as
1690 @code{--localstatedir}, and @var{user} is the user name. The
1691 @file{per-user} directory is created when @command{guix-daemon} is
1692 started, and the @var{user} sub-directory is created by @command{guix
1693 package}.
1694
1695 The @var{options} can be among the following:
1696
1697 @table @code
1698
1699 @item --install=@var{package} @dots{}
1700 @itemx -i @var{package} @dots{}
1701 Install the specified @var{package}s.
1702
1703 Each @var{package} may specify either a simple package name, such as
1704 @code{guile}, or a package name followed by an at-sign and version number,
1705 such as @code{guile@@1.8.8} or simply @code{guile@@1.8} (in the latter
1706 case, the newest version prefixed by @code{1.8} is selected.)
1707
1708 If no version number is specified, the
1709 newest available version will be selected. In addition, @var{package}
1710 may contain a colon, followed by the name of one of the outputs of the
1711 package, as in @code{gcc:doc} or @code{binutils@@2.22:lib}
1712 (@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1713 name (and optionally version) are searched for among the GNU
1714 distribution modules (@pxref{Package Modules}).
1715
1716 @cindex propagated inputs
1717 Sometimes packages have @dfn{propagated inputs}: these are dependencies
1718 that automatically get installed along with the required package
1719 (@pxref{package-propagated-inputs, @code{propagated-inputs} in
1720 @code{package} objects}, for information about propagated inputs in
1721 package definitions).
1722
1723 @anchor{package-cmd-propagated-inputs}
1724 An example is the GNU MPC library: its C header files refer to those of
1725 the GNU MPFR library, which in turn refer to those of the GMP library.
1726 Thus, when installing MPC, the MPFR and GMP libraries also get installed
1727 in the profile; removing MPC also removes MPFR and GMP---unless they had
1728 also been explicitly installed by the user.
1729
1730 Besides, packages sometimes rely on the definition of environment
1731 variables for their search paths (see explanation of
1732 @code{--search-paths} below). Any missing or possibly incorrect
1733 environment variable definitions are reported here.
1734
1735 @item --install-from-expression=@var{exp}
1736 @itemx -e @var{exp}
1737 Install the package @var{exp} evaluates to.
1738
1739 @var{exp} must be a Scheme expression that evaluates to a
1740 @code{<package>} object. This option is notably useful to disambiguate
1741 between same-named variants of a package, with expressions such as
1742 @code{(@@ (gnu packages base) guile-final)}.
1743
1744 Note that this option installs the first output of the specified
1745 package, which may be insufficient when needing a specific output of a
1746 multiple-output package.
1747
1748 @item --install-from-file=@var{file}
1749 @itemx -f @var{file}
1750 Install the package that the code within @var{file} evaluates to.
1751
1752 As an example, @var{file} might contain a definition like this
1753 (@pxref{Defining Packages}):
1754
1755 @example
1756 @verbatiminclude package-hello.scm
1757 @end example
1758
1759 Developers may find it useful to include such a @file{guix.scm} file
1760 in the root of their project source tree that can be used to test
1761 development snapshots and create reproducible development environments
1762 (@pxref{Invoking guix environment}).
1763
1764 @item --remove=@var{package} @dots{}
1765 @itemx -r @var{package} @dots{}
1766 Remove the specified @var{package}s.
1767
1768 As for @code{--install}, each @var{package} may specify a version number
1769 and/or output name in addition to the package name. For instance,
1770 @code{-r glibc:debug} would remove the @code{debug} output of
1771 @code{glibc}.
1772
1773 @item --upgrade[=@var{regexp} @dots{}]
1774 @itemx -u [@var{regexp} @dots{}]
1775 @cindex upgrading packages
1776 Upgrade all the installed packages. If one or more @var{regexp}s are
1777 specified, upgrade only installed packages whose name matches a
1778 @var{regexp}. Also see the @code{--do-not-upgrade} option below.
1779
1780 Note that this upgrades package to the latest version of packages found
1781 in the distribution currently installed. To update your distribution,
1782 you should regularly run @command{guix pull} (@pxref{Invoking guix
1783 pull}).
1784
1785 @item --do-not-upgrade[=@var{regexp} @dots{}]
1786 When used together with the @code{--upgrade} option, do @emph{not}
1787 upgrade any packages whose name matches a @var{regexp}. For example, to
1788 upgrade all packages in the current profile except those containing the
1789 substring ``emacs'':
1790
1791 @example
1792 $ guix package --upgrade . --do-not-upgrade emacs
1793 @end example
1794
1795 @item @anchor{profile-manifest}--manifest=@var{file}
1796 @itemx -m @var{file}
1797 @cindex profile declaration
1798 @cindex profile manifest
1799 Create a new generation of the profile from the manifest object
1800 returned by the Scheme code in @var{file}.
1801
1802 This allows you to @emph{declare} the profile's contents rather than
1803 constructing it through a sequence of @code{--install} and similar
1804 commands. The advantage is that @var{file} can be put under version
1805 control, copied to different machines to reproduce the same profile, and
1806 so on.
1807
1808 @c FIXME: Add reference to (guix profile) documentation when available.
1809 @var{file} must return a @dfn{manifest} object, which is roughly a list
1810 of packages:
1811
1812 @findex packages->manifest
1813 @example
1814 (use-package-modules guile emacs)
1815
1816 (packages->manifest
1817 (list emacs
1818 guile-2.0
1819 ;; Use a specific package output.
1820 (list guile-2.0 "debug")))
1821 @end example
1822
1823 @findex specifications->manifest
1824 In this example we have to know which modules define the @code{emacs}
1825 and @code{guile-2.0} variables to provide the right
1826 @code{use-package-modules} line, which can be cumbersome. We can
1827 instead provide regular package specifications and let
1828 @code{specifications->manifest} look up the corresponding package
1829 objects, like this:
1830
1831 @example
1832 (specifications->manifest
1833 '("emacs" "guile@@2.2" "guile@@2.2:debug"))
1834 @end example
1835
1836 @item --roll-back
1837 @cindex rolling back
1838 @cindex undoing transactions
1839 @cindex transactions, undoing
1840 Roll back to the previous @dfn{generation} of the profile---i.e., undo
1841 the last transaction.
1842
1843 When combined with options such as @code{--install}, roll back occurs
1844 before any other actions.
1845
1846 When rolling back from the first generation that actually contains
1847 installed packages, the profile is made to point to the @dfn{zeroth
1848 generation}, which contains no files apart from its own metadata.
1849
1850 After having rolled back, installing, removing, or upgrading packages
1851 overwrites previous future generations. Thus, the history of the
1852 generations in a profile is always linear.
1853
1854 @item --switch-generation=@var{pattern}
1855 @itemx -S @var{pattern}
1856 @cindex generations
1857 Switch to a particular generation defined by @var{pattern}.
1858
1859 @var{pattern} may be either a generation number or a number prefixed
1860 with ``+'' or ``-''. The latter means: move forward/backward by a
1861 specified number of generations. For example, if you want to return to
1862 the latest generation after @code{--roll-back}, use
1863 @code{--switch-generation=+1}.
1864
1865 The difference between @code{--roll-back} and
1866 @code{--switch-generation=-1} is that @code{--switch-generation} will
1867 not make a zeroth generation, so if a specified generation does not
1868 exist, the current generation will not be changed.
1869
1870 @item --search-paths[=@var{kind}]
1871 @cindex search paths
1872 Report environment variable definitions, in Bash syntax, that may be
1873 needed in order to use the set of installed packages. These environment
1874 variables are used to specify @dfn{search paths} for files used by some
1875 of the installed packages.
1876
1877 For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1878 environment variables to be defined so it can look for headers and
1879 libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1880 Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1881 library are installed in the profile, then @code{--search-paths} will
1882 suggest setting these variables to @code{@var{profile}/include} and
1883 @code{@var{profile}/lib}, respectively.
1884
1885 The typical use case is to define these environment variables in the
1886 shell:
1887
1888 @example
1889 $ eval `guix package --search-paths`
1890 @end example
1891
1892 @var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1893 meaning that the returned environment variable definitions will either
1894 be exact settings, or prefixes or suffixes of the current value of these
1895 variables. When omitted, @var{kind} defaults to @code{exact}.
1896
1897 This option can also be used to compute the @emph{combined} search paths
1898 of several profiles. Consider this example:
1899
1900 @example
1901 $ guix package -p foo -i guile
1902 $ guix package -p bar -i guile-json
1903 $ guix package -p foo -p bar --search-paths
1904 @end example
1905
1906 The last command above reports about the @code{GUILE_LOAD_PATH}
1907 variable, even though, taken individually, neither @file{foo} nor
1908 @file{bar} would lead to that recommendation.
1909
1910
1911 @item --profile=@var{profile}
1912 @itemx -p @var{profile}
1913 Use @var{profile} instead of the user's default profile.
1914
1915 @item --verbose
1916 Produce verbose output. In particular, emit the build log of the
1917 environment on the standard error port.
1918
1919 @item --bootstrap
1920 Use the bootstrap Guile to build the profile. This option is only
1921 useful to distribution developers.
1922
1923 @end table
1924
1925 In addition to these actions, @command{guix package} supports the
1926 following options to query the current state of a profile, or the
1927 availability of packages:
1928
1929 @table @option
1930
1931 @item --search=@var{regexp}
1932 @itemx -s @var{regexp}
1933 @cindex searching for packages
1934 List the available packages whose name, synopsis, or description matches
1935 @var{regexp}, sorted by relevance. Print all the metadata of matching packages in
1936 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1937 GNU recutils manual}).
1938
1939 This allows specific fields to be extracted using the @command{recsel}
1940 command, for instance:
1941
1942 @example
1943 $ guix package -s malloc | recsel -p name,version,relevance
1944 name: jemalloc
1945 version: 4.5.0
1946 relevance: 6
1947
1948 name: glibc
1949 version: 2.25
1950 relevance: 1
1951
1952 name: libgc
1953 version: 7.6.0
1954 relevance: 1
1955 @end example
1956
1957 Similarly, to show the name of all the packages available under the
1958 terms of the GNU@tie{}LGPL version 3:
1959
1960 @example
1961 $ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1962 name: elfutils
1963
1964 name: gmp
1965 @dots{}
1966 @end example
1967
1968 It is also possible to refine search results using several @code{-s}
1969 flags. For example, the following command returns a list of board
1970 games:
1971
1972 @example
1973 $ guix package -s '\<board\>' -s game | recsel -p name
1974 name: gnubg
1975 @dots{}
1976 @end example
1977
1978 If we were to omit @code{-s game}, we would also get software packages
1979 that deal with printed circuit boards; removing the angle brackets
1980 around @code{board} would further add packages that have to do with
1981 keyboards.
1982
1983 And now for a more elaborate example. The following command searches
1984 for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1985 libraries, and prints the name and synopsis of the matching packages:
1986
1987 @example
1988 $ guix package -s crypto -s library | \
1989 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1990 @end example
1991
1992 @noindent
1993 @xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1994 information on @dfn{selection expressions} for @code{recsel -e}.
1995
1996 @item --show=@var{package}
1997 Show details about @var{package}, taken from the list of available packages, in
1998 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1999 recutils manual}).
2000
2001 @example
2002 $ guix package --show=python | recsel -p name,version
2003 name: python
2004 version: 2.7.6
2005
2006 name: python
2007 version: 3.3.5
2008 @end example
2009
2010 You may also specify the full name of a package to only get details about a
2011 specific version of it:
2012 @example
2013 $ guix package --show=python@@3.4 | recsel -p name,version
2014 name: python
2015 version: 3.4.3
2016 @end example
2017
2018
2019
2020 @item --list-installed[=@var{regexp}]
2021 @itemx -I [@var{regexp}]
2022 List the currently installed packages in the specified profile, with the
2023 most recently installed packages shown last. When @var{regexp} is
2024 specified, list only installed packages whose name matches @var{regexp}.
2025
2026 For each installed package, print the following items, separated by
2027 tabs: the package name, its version string, the part of the package that
2028 is installed (for instance, @code{out} for the default output,
2029 @code{include} for its headers, etc.), and the path of this package in
2030 the store.
2031
2032 @item --list-available[=@var{regexp}]
2033 @itemx -A [@var{regexp}]
2034 List packages currently available in the distribution for this system
2035 (@pxref{GNU Distribution}). When @var{regexp} is specified, list only
2036 installed packages whose name matches @var{regexp}.
2037
2038 For each package, print the following items separated by tabs: its name,
2039 its version string, the parts of the package (@pxref{Packages with
2040 Multiple Outputs}), and the source location of its definition.
2041
2042 @item --list-generations[=@var{pattern}]
2043 @itemx -l [@var{pattern}]
2044 @cindex generations
2045 Return a list of generations along with their creation dates; for each
2046 generation, show the installed packages, with the most recently
2047 installed packages shown last. Note that the zeroth generation is never
2048 shown.
2049
2050 For each installed package, print the following items, separated by
2051 tabs: the name of a package, its version string, the part of the package
2052 that is installed (@pxref{Packages with Multiple Outputs}), and the
2053 location of this package in the store.
2054
2055 When @var{pattern} is used, the command returns only matching
2056 generations. Valid patterns include:
2057
2058 @itemize
2059 @item @emph{Integers and comma-separated integers}. Both patterns denote
2060 generation numbers. For instance, @code{--list-generations=1} returns
2061 the first one.
2062
2063 And @code{--list-generations=1,8,2} outputs three generations in the
2064 specified order. Neither spaces nor trailing commas are allowed.
2065
2066 @item @emph{Ranges}. @code{--list-generations=2..9} prints the
2067 specified generations and everything in between. Note that the start of
2068 a range must be smaller than its end.
2069
2070 It is also possible to omit the endpoint. For example,
2071 @code{--list-generations=2..}, returns all generations starting from the
2072 second one.
2073
2074 @item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
2075 or months by passing an integer along with the first letter of the
2076 duration. For example, @code{--list-generations=20d} lists generations
2077 that are up to 20 days old.
2078 @end itemize
2079
2080 @item --delete-generations[=@var{pattern}]
2081 @itemx -d [@var{pattern}]
2082 When @var{pattern} is omitted, delete all generations except the current
2083 one.
2084
2085 This command accepts the same patterns as @option{--list-generations}.
2086 When @var{pattern} is specified, delete the matching generations. When
2087 @var{pattern} specifies a duration, generations @emph{older} than the
2088 specified duration match. For instance, @code{--delete-generations=1m}
2089 deletes generations that are more than one month old.
2090
2091 If the current generation matches, it is @emph{not} deleted. Also, the
2092 zeroth generation is never deleted.
2093
2094 Note that deleting generations prevents rolling back to them.
2095 Consequently, this command must be used with care.
2096
2097 @end table
2098
2099 Finally, since @command{guix package} may actually start build
2100 processes, it supports all the common build options (@pxref{Common Build
2101 Options}). It also supports package transformation options, such as
2102 @option{--with-source} (@pxref{Package Transformation Options}).
2103 However, note that package transformations are lost when upgrading; to
2104 preserve transformations across upgrades, you should define your own
2105 package variant in a Guile module and add it to @code{GUIX_PACKAGE_PATH}
2106 (@pxref{Defining Packages}).
2107
2108
2109 @node Substitutes
2110 @section Substitutes
2111
2112 @cindex substitutes
2113 @cindex pre-built binaries
2114 Guix supports transparent source/binary deployment, which means that it
2115 can either build things locally, or download pre-built items from a
2116 server. We call these pre-built items @dfn{substitutes}---they are
2117 substitutes for local build results. In many cases, downloading a
2118 substitute is much faster than building things locally.
2119
2120 Substitutes can be anything resulting from a derivation build
2121 (@pxref{Derivations}). Of course, in the common case, they are
2122 pre-built package binaries, but source tarballs, for instance, which
2123 also result from derivation builds, can be available as substitutes.
2124
2125 The @code{hydra.gnu.org} server is a front-end to a build farm that
2126 builds packages from the GNU distribution continuously for some
2127 architectures, and makes them available as substitutes. This is the
2128 default source of substitutes; it can be overridden by passing the
2129 @option{--substitute-urls} option either to @command{guix-daemon}
2130 (@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
2131 or to client tools such as @command{guix package}
2132 (@pxref{client-substitute-urls,, client @option{--substitute-urls}
2133 option}).
2134
2135 Substitute URLs can be either HTTP or HTTPS.
2136 HTTPS is recommended because communications are encrypted; conversely,
2137 using HTTP makes all communications visible to an eavesdropper, who
2138 could use the information gathered to determine, for instance, whether
2139 your system has unpatched security vulnerabilities.
2140
2141 @cindex security
2142 @cindex digital signatures
2143 @cindex substitutes, authorization thereof
2144 To allow Guix to download substitutes from @code{hydra.gnu.org} or a
2145 mirror thereof, you
2146 must add its public key to the access control list (ACL) of archive
2147 imports, using the @command{guix archive} command (@pxref{Invoking guix
2148 archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
2149 be compromised and to serve genuine substitutes.
2150
2151 This public key is installed along with Guix, in
2152 @code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
2153 the installation prefix of Guix. If you installed Guix from source,
2154 make sure you checked the GPG signature of
2155 @file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
2156 Then, you can run something like this:
2157
2158 @example
2159 # guix archive --authorize < hydra.gnu.org.pub
2160 @end example
2161
2162 Once this is in place, the output of a command like @code{guix build}
2163 should change from something like:
2164
2165 @example
2166 $ guix build emacs --dry-run
2167 The following derivations would be built:
2168 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
2169 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
2170 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
2171 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
2172 @dots{}
2173 @end example
2174
2175 @noindent
2176 to something like:
2177
2178 @example
2179 $ guix build emacs --dry-run
2180 The following files would be downloaded:
2181 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
2182 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
2183 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
2184 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
2185 @dots{}
2186 @end example
2187
2188 @noindent
2189 This indicates that substitutes from @code{hydra.gnu.org} are usable and
2190 will be downloaded, when possible, for future builds.
2191
2192 Guix ignores substitutes that are not signed, or that are not signed by
2193 one of the keys listed in the ACL. It also detects and raises an error
2194 when attempting to use a substitute that has been tampered with.
2195
2196 @vindex http_proxy
2197 Substitutes are downloaded over HTTP or HTTPS.
2198 The @code{http_proxy} environment
2199 variable can be set in the environment of @command{guix-daemon} and is
2200 honored for downloads of substitutes. Note that the value of
2201 @code{http_proxy} in the environment where @command{guix build},
2202 @command{guix package}, and other client commands are run has
2203 @emph{absolutely no effect}.
2204
2205 When using HTTPS, the server's X.509 certificate is @emph{not} validated
2206 (in other words, the server is not authenticated), contrary to what
2207 HTTPS clients such as Web browsers usually do. This is because Guix
2208 authenticates substitute information itself, as explained above, which
2209 is what we care about (whereas X.509 certificates are about
2210 authenticating bindings between domain names and public keys.)
2211
2212 You can get statistics on the substitutes provided by a server using the
2213 @command{guix weather} command (@pxref{Invoking guix weather}).
2214
2215 The substitute mechanism can be disabled globally by running
2216 @code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
2217 guix-daemon}). It can also be disabled temporarily by passing the
2218 @code{--no-substitutes} option to @command{guix package}, @command{guix
2219 build}, and other command-line tools.
2220
2221
2222 @unnumberedsubsec On Trusting Binaries
2223
2224 Today, each individual's control over their own computing is at the
2225 mercy of institutions, corporations, and groups with enough power and
2226 determination to subvert the computing infrastructure and exploit its
2227 weaknesses. While using @code{hydra.gnu.org} substitutes can be
2228 convenient, we encourage users to also build on their own, or even run
2229 their own build farm, such that @code{hydra.gnu.org} is less of an
2230 interesting target. One way to help is by publishing the software you
2231 build using @command{guix publish} so that others have one more choice
2232 of server to download substitutes from (@pxref{Invoking guix publish}).
2233
2234 Guix has the foundations to maximize build reproducibility
2235 (@pxref{Features}). In most cases, independent builds of a given
2236 package or derivation should yield bit-identical results. Thus, through
2237 a diverse set of independent package builds, we can strengthen the
2238 integrity of our systems. The @command{guix challenge} command aims to
2239 help users assess substitute servers, and to assist developers in
2240 finding out about non-deterministic package builds (@pxref{Invoking guix
2241 challenge}). Similarly, the @option{--check} option of @command{guix
2242 build} allows users to check whether previously-installed substitutes
2243 are genuine by rebuilding them locally (@pxref{build-check,
2244 @command{guix build --check}}).
2245
2246 In the future, we want Guix to have support to publish and retrieve
2247 binaries to/from other users, in a peer-to-peer fashion. If you would
2248 like to discuss this project, join us on @email{guix-devel@@gnu.org}.
2249
2250
2251 @node Packages with Multiple Outputs
2252 @section Packages with Multiple Outputs
2253
2254 @cindex multiple-output packages
2255 @cindex package outputs
2256 @cindex outputs
2257
2258 Often, packages defined in Guix have a single @dfn{output}---i.e., the
2259 source package leads to exactly one directory in the store. When running
2260 @command{guix package -i glibc}, one installs the default output of the
2261 GNU libc package; the default output is called @code{out}, but its name
2262 can be omitted as shown in this command. In this particular case, the
2263 default output of @code{glibc} contains all the C header files, shared
2264 libraries, static libraries, Info documentation, and other supporting
2265 files.
2266
2267 Sometimes it is more appropriate to separate the various types of files
2268 produced from a single source package into separate outputs. For
2269 instance, the GLib C library (used by GTK+ and related packages)
2270 installs more than 20 MiB of reference documentation as HTML pages.
2271 To save space for users who do not need it, the documentation goes to a
2272 separate output, called @code{doc}. To install the main GLib output,
2273 which contains everything but the documentation, one would run:
2274
2275 @example
2276 guix package -i glib
2277 @end example
2278
2279 @cindex documentation
2280 The command to install its documentation is:
2281
2282 @example
2283 guix package -i glib:doc
2284 @end example
2285
2286 Some packages install programs with different ``dependency footprints''.
2287 For instance, the WordNet package installs both command-line tools and
2288 graphical user interfaces (GUIs). The former depend solely on the C
2289 library, whereas the latter depend on Tcl/Tk and the underlying X
2290 libraries. In this case, we leave the command-line tools in the default
2291 output, whereas the GUIs are in a separate output. This allows users
2292 who do not need the GUIs to save space. The @command{guix size} command
2293 can help find out about such situations (@pxref{Invoking guix size}).
2294 @command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
2295
2296 There are several such multiple-output packages in the GNU distribution.
2297 Other conventional output names include @code{lib} for libraries and
2298 possibly header files, @code{bin} for stand-alone programs, and
2299 @code{debug} for debugging information (@pxref{Installing Debugging
2300 Files}). The outputs of a packages are listed in the third column of
2301 the output of @command{guix package --list-available} (@pxref{Invoking
2302 guix package}).
2303
2304
2305 @node Invoking guix gc
2306 @section Invoking @command{guix gc}
2307
2308 @cindex garbage collector
2309 @cindex disk space
2310 Packages that are installed, but not used, may be @dfn{garbage-collected}.
2311 The @command{guix gc} command allows users to explicitly run the garbage
2312 collector to reclaim space from the @file{/gnu/store} directory. It is
2313 the @emph{only} way to remove files from @file{/gnu/store}---removing
2314 files or directories manually may break it beyond repair!
2315
2316 The garbage collector has a set of known @dfn{roots}: any file under
2317 @file{/gnu/store} reachable from a root is considered @dfn{live} and
2318 cannot be deleted; any other file is considered @dfn{dead} and may be
2319 deleted. The set of garbage collector roots includes default user
2320 profiles, and may be augmented with @command{guix build --root}, for
2321 example (@pxref{Invoking guix build}).
2322
2323 Prior to running @code{guix gc --collect-garbage} to make space, it is
2324 often useful to remove old generations from user profiles; that way, old
2325 package builds referenced by those generations can be reclaimed. This
2326 is achieved by running @code{guix package --delete-generations}
2327 (@pxref{Invoking guix package}).
2328
2329 Our recommendation is to run a garbage collection periodically, or when
2330 you are short on disk space. For instance, to guarantee that at least
2331 5@tie{}GB are available on your disk, simply run:
2332
2333 @example
2334 guix gc -F 5G
2335 @end example
2336
2337 It is perfectly safe to run as a non-interactive periodic job
2338 (@pxref{Scheduled Job Execution}, for how to set up such a job on
2339 GuixSD). Running @command{guix gc} with no arguments will collect as
2340 much garbage as it can, but that is often inconvenient: you may find
2341 yourself having to rebuild or re-download software that is ``dead'' from
2342 the GC viewpoint but that is necessary to build other pieces of
2343 software---e.g., the compiler tool chain.
2344
2345 The @command{guix gc} command has three modes of operation: it can be
2346 used to garbage-collect any dead files (the default), to delete specific
2347 files (the @code{--delete} option), to print garbage-collector
2348 information, or for more advanced queries. The garbage collection
2349 options are as follows:
2350
2351 @table @code
2352 @item --collect-garbage[=@var{min}]
2353 @itemx -C [@var{min}]
2354 Collect garbage---i.e., unreachable @file{/gnu/store} files and
2355 sub-directories. This is the default operation when no option is
2356 specified.
2357
2358 When @var{min} is given, stop once @var{min} bytes have been collected.
2359 @var{min} may be a number of bytes, or it may include a unit as a
2360 suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
2361 (@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
2362
2363 When @var{min} is omitted, collect all the garbage.
2364
2365 @item --free-space=@var{free}
2366 @itemx -F @var{free}
2367 Collect garbage until @var{free} space is available under
2368 @file{/gnu/store}, if possible; @var{free} denotes storage space, such
2369 as @code{500MiB}, as described above.
2370
2371 When @var{free} or more is already available in @file{/gnu/store}, do
2372 nothing and exit immediately.
2373
2374 @item --delete
2375 @itemx -d
2376 Attempt to delete all the store files and directories specified as
2377 arguments. This fails if some of the files are not in the store, or if
2378 they are still live.
2379
2380 @item --list-failures
2381 List store items corresponding to cached build failures.
2382
2383 This prints nothing unless the daemon was started with
2384 @option{--cache-failures} (@pxref{Invoking guix-daemon,
2385 @option{--cache-failures}}).
2386
2387 @item --clear-failures
2388 Remove the specified store items from the failed-build cache.
2389
2390 Again, this option only makes sense when the daemon is started with
2391 @option{--cache-failures}. Otherwise, it does nothing.
2392
2393 @item --list-dead
2394 Show the list of dead files and directories still present in the
2395 store---i.e., files and directories no longer reachable from any root.
2396
2397 @item --list-live
2398 Show the list of live store files and directories.
2399
2400 @end table
2401
2402 In addition, the references among existing store files can be queried:
2403
2404 @table @code
2405
2406 @item --references
2407 @itemx --referrers
2408 @cindex package dependencies
2409 List the references (respectively, the referrers) of store files given
2410 as arguments.
2411
2412 @item --requisites
2413 @itemx -R
2414 @cindex closure
2415 List the requisites of the store files passed as arguments. Requisites
2416 include the store files themselves, their references, and the references
2417 of these, recursively. In other words, the returned list is the
2418 @dfn{transitive closure} of the store files.
2419
2420 @xref{Invoking guix size}, for a tool to profile the size of the closure
2421 of an element. @xref{Invoking guix graph}, for a tool to visualize
2422 the graph of references.
2423
2424 @end table
2425
2426 Lastly, the following options allow you to check the integrity of the
2427 store and to control disk usage.
2428
2429 @table @option
2430
2431 @item --verify[=@var{options}]
2432 @cindex integrity, of the store
2433 @cindex integrity checking
2434 Verify the integrity of the store.
2435
2436 By default, make sure that all the store items marked as valid in the
2437 database of the daemon actually exist in @file{/gnu/store}.
2438
2439 When provided, @var{options} must be a comma-separated list containing one
2440 or more of @code{contents} and @code{repair}.
2441
2442 When passing @option{--verify=contents}, the daemon computes the
2443 content hash of each store item and compares it against its hash in the
2444 database. Hash mismatches are reported as data corruptions. Because it
2445 traverses @emph{all the files in the store}, this command can take a
2446 long time, especially on systems with a slow disk drive.
2447
2448 @cindex repairing the store
2449 @cindex corruption, recovering from
2450 Using @option{--verify=repair} or @option{--verify=contents,repair}
2451 causes the daemon to try to repair corrupt store items by fetching
2452 substitutes for them (@pxref{Substitutes}). Because repairing is not
2453 atomic, and thus potentially dangerous, it is available only to the
2454 system administrator. A lightweight alternative, when you know exactly
2455 which items in the store are corrupt, is @command{guix build --repair}
2456 (@pxref{Invoking guix build}).
2457
2458 @item --optimize
2459 @cindex deduplication
2460 Optimize the store by hard-linking identical files---this is
2461 @dfn{deduplication}.
2462
2463 The daemon performs deduplication after each successful build or archive
2464 import, unless it was started with @code{--disable-deduplication}
2465 (@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
2466 this option is primarily useful when the daemon was running with
2467 @code{--disable-deduplication}.
2468
2469 @end table
2470
2471 @node Invoking guix pull
2472 @section Invoking @command{guix pull}
2473
2474 @cindex upgrading Guix
2475 @cindex updating Guix
2476 @cindex @command{guix pull}
2477 @cindex pull
2478 Packages are installed or upgraded to the latest version available in
2479 the distribution currently available on your local machine. To update
2480 that distribution, along with the Guix tools, you must run @command{guix
2481 pull}: the command downloads the latest Guix source code and package
2482 descriptions, and deploys it. Source code is downloaded from a
2483 @uref{https://git-scm.com, Git} repository.
2484
2485 On completion, @command{guix package} will use packages and package
2486 versions from this just-retrieved copy of Guix. Not only that, but all
2487 the Guix commands and Scheme modules will also be taken from that latest
2488 version. New @command{guix} sub-commands added by the update also
2489 become available.
2490
2491 Any user can update their Guix copy using @command{guix pull}, and the
2492 effect is limited to the user who run @command{guix pull}. For
2493 instance, when user @code{root} runs @command{guix pull}, this has no
2494 effect on the version of Guix that user @code{alice} sees, and vice
2495 versa@footnote{Under the hood, @command{guix pull} updates the
2496 @file{~/.config/guix/latest} symbolic link to point to the latest Guix,
2497 and the @command{guix} command loads code from there. Currently, the
2498 only way to roll back an invocation of @command{guix pull} is to
2499 manually update this symlink to point to the previous Guix.}.
2500
2501 The @command{guix pull} command is usually invoked with no arguments,
2502 but it supports the following options:
2503
2504 @table @code
2505 @item --verbose
2506 Produce verbose output, writing build logs to the standard error output.
2507
2508 @item --url=@var{url}
2509 Download Guix from the Git repository at @var{url}.
2510
2511 By default, the source is taken from its canonical Git repository at
2512 @code{gnu.org}, for the stable branch of Guix.
2513
2514 @item --commit=@var{commit}
2515 Deploy @var{commit}, a valid Git commit ID represented as a hexadecimal
2516 string.
2517
2518 @item --branch=@var{branch}
2519 Deploy the tip of @var{branch}, the name of a Git branch available on
2520 the repository at @var{url}.
2521
2522 @item --bootstrap
2523 Use the bootstrap Guile to build the latest Guix. This option is only
2524 useful to Guix developers.
2525 @end table
2526
2527 In addition, @command{guix pull} supports all the common build options
2528 (@pxref{Common Build Options}).
2529
2530 @node Invoking guix pack
2531 @section Invoking @command{guix pack}
2532
2533 Occasionally you want to pass software to people who are not (yet!)
2534 lucky enough to be using Guix. You'd tell them to run @command{guix
2535 package -i @var{something}}, but that's not possible in this case. This
2536 is where @command{guix pack} comes in.
2537
2538 @cindex pack
2539 @cindex bundle
2540 @cindex application bundle
2541 @cindex software bundle
2542 The @command{guix pack} command creates a shrink-wrapped @dfn{pack} or
2543 @dfn{software bundle}: it creates a tarball or some other archive
2544 containing the binaries of the software you're interested in, and all
2545 its dependencies. The resulting archive can be used on any machine that
2546 does not have Guix, and people can run the exact same binaries as those
2547 you have with Guix. The pack itself is created in a bit-reproducible
2548 fashion, so anyone can verify that it really contains the build results
2549 that you pretend to be shipping.
2550
2551 For example, to create a bundle containing Guile, Emacs, Geiser, and all
2552 their dependencies, you can run:
2553
2554 @example
2555 $ guix pack guile emacs geiser
2556 @dots{}
2557 /gnu/store/@dots{}-pack.tar.gz
2558 @end example
2559
2560 The result here is a tarball containing a @file{/gnu/store} directory
2561 with all the relevant packages. The resulting tarball contains a
2562 @dfn{profile} with the three packages of interest; the profile is the
2563 same as would be created by @command{guix package -i}. It is this
2564 mechanism that is used to create Guix's own standalone binary tarball
2565 (@pxref{Binary Installation}).
2566
2567 Users of this pack would have to run
2568 @file{/gnu/store/@dots{}-profile/bin/guile} to run Guile, which you may
2569 find inconvenient. To work around it, you can create, say, a
2570 @file{/opt/gnu/bin} symlink to the profile:
2571
2572 @example
2573 guix pack -S /opt/gnu/bin=bin guile emacs geiser
2574 @end example
2575
2576 @noindent
2577 That way, users can happily type @file{/opt/gnu/bin/guile} and enjoy.
2578
2579 Alternatively, you can produce a pack in the Docker image format using
2580 the following command:
2581
2582 @example
2583 guix pack -f docker guile emacs geiser
2584 @end example
2585
2586 @noindent
2587 The result is a tarball that can be passed to the @command{docker load}
2588 command. See the
2589 @uref{https://docs.docker.com/engine/reference/commandline/load/, Docker
2590 documentation} for more information.
2591
2592 Several command-line options allow you to customize your pack:
2593
2594 @table @code
2595 @item --format=@var{format}
2596 @itemx -f @var{format}
2597 Produce a pack in the given @var{format}.
2598
2599 The available formats are:
2600
2601 @table @code
2602 @item tarball
2603 This is the default format. It produces a tarball containing all the
2604 specified binaries and symlinks.
2605
2606 @item docker
2607 This produces a tarball that follows the
2608 @uref{https://github.com/docker/docker/blob/master/image/spec/v1.2.md,
2609 Docker Image Specification}.
2610 @end table
2611
2612 @item --expression=@var{expr}
2613 @itemx -e @var{expr}
2614 Consider the package @var{expr} evaluates to.
2615
2616 This has the same purpose as the same-named option in @command{guix
2617 build} (@pxref{Additional Build Options, @code{--expression} in
2618 @command{guix build}}).
2619
2620 @item --system=@var{system}
2621 @itemx -s @var{system}
2622 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
2623 the system type of the build host.
2624
2625 @item --target=@var{triplet}
2626 @cindex cross-compilation
2627 Cross-build for @var{triplet}, which must be a valid GNU triplet, such
2628 as @code{"mips64el-linux-gnu"} (@pxref{Specifying target triplets, GNU
2629 configuration triplets,, autoconf, Autoconf}).
2630
2631 @item --compression=@var{tool}
2632 @itemx -C @var{tool}
2633 Compress the resulting tarball using @var{tool}---one of @code{gzip},
2634 @code{bzip2}, @code{xz}, @code{lzip}, or @code{none} for no compression.
2635
2636 @item --symlink=@var{spec}
2637 @itemx -S @var{spec}
2638 Add the symlinks specified by @var{spec} to the pack. This option can
2639 appear several times.
2640
2641 @var{spec} has the form @code{@var{source}=@var{target}}, where
2642 @var{source} is the symlink that will be created and @var{target} is the
2643 symlink target.
2644
2645 For instance, @code{-S /opt/gnu/bin=bin} creates a @file{/opt/gnu/bin}
2646 symlink pointing to the @file{bin} sub-directory of the profile.
2647
2648 @item --localstatedir
2649 Include the ``local state directory'', @file{/var/guix}, in the
2650 resulting pack.
2651
2652 @file{/var/guix} contains the store database (@pxref{The Store}) as well
2653 as garbage-collector roots (@pxref{Invoking guix gc}). Providing it in
2654 the pack means that the store is ``complete'' and manageable by Guix;
2655 not providing it pack means that the store is ``dead'': items cannot be
2656 added to it or removed from it after extraction of the pack.
2657
2658 One use case for this is the Guix self-contained binary tarball
2659 (@pxref{Binary Installation}).
2660 @end table
2661
2662 In addition, @command{guix pack} supports all the common build options
2663 (@pxref{Common Build Options}) and all the package transformation
2664 options (@pxref{Package Transformation Options}).
2665
2666
2667 @node Invoking guix archive
2668 @section Invoking @command{guix archive}
2669
2670 @cindex @command{guix archive}
2671 @cindex archive
2672 The @command{guix archive} command allows users to @dfn{export} files
2673 from the store into a single archive, and to later @dfn{import} them.
2674 In particular, it allows store files to be transferred from one machine
2675 to the store on another machine.
2676
2677 @cindex exporting store items
2678 To export store files as an archive to standard output, run:
2679
2680 @example
2681 guix archive --export @var{options} @var{specifications}...
2682 @end example
2683
2684 @var{specifications} may be either store file names or package
2685 specifications, as for @command{guix package} (@pxref{Invoking guix
2686 package}). For instance, the following command creates an archive
2687 containing the @code{gui} output of the @code{git} package and the main
2688 output of @code{emacs}:
2689
2690 @example
2691 guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
2692 @end example
2693
2694 If the specified packages are not built yet, @command{guix archive}
2695 automatically builds them. The build process may be controlled with the
2696 common build options (@pxref{Common Build Options}).
2697
2698 To transfer the @code{emacs} package to a machine connected over SSH,
2699 one would run:
2700
2701 @example
2702 guix archive --export -r emacs | ssh the-machine guix archive --import
2703 @end example
2704
2705 @noindent
2706 Similarly, a complete user profile may be transferred from one machine
2707 to another like this:
2708
2709 @example
2710 guix archive --export -r $(readlink -f ~/.guix-profile) | \
2711 ssh the-machine guix-archive --import
2712 @end example
2713
2714 @noindent
2715 However, note that, in both examples, all of @code{emacs} and the
2716 profile as well as all of their dependencies are transferred (due to
2717 @code{-r}), regardless of what is already available in the store on the
2718 target machine. The @code{--missing} option can help figure out which
2719 items are missing from the target store. The @command{guix copy}
2720 command simplifies and optimizes this whole process, so this is probably
2721 what you should use in this case (@pxref{Invoking guix copy}).
2722
2723 @cindex nar, archive format
2724 @cindex normalized archive (nar)
2725 Archives are stored in the ``normalized archive'' or ``nar'' format, which is
2726 comparable in spirit to `tar', but with differences
2727 that make it more appropriate for our purposes. First, rather than
2728 recording all Unix metadata for each file, the nar format only mentions
2729 the file type (regular, directory, or symbolic link); Unix permissions
2730 and owner/group are dismissed. Second, the order in which directory
2731 entries are stored always follows the order of file names according to
2732 the C locale collation order. This makes archive production fully
2733 deterministic.
2734
2735 When exporting, the daemon digitally signs the contents of the archive,
2736 and that digital signature is appended. When importing, the daemon
2737 verifies the signature and rejects the import in case of an invalid
2738 signature or if the signing key is not authorized.
2739 @c FIXME: Add xref to daemon doc about signatures.
2740
2741 The main options are:
2742
2743 @table @code
2744 @item --export
2745 Export the specified store files or packages (see below.) Write the
2746 resulting archive to the standard output.
2747
2748 Dependencies are @emph{not} included in the output, unless
2749 @code{--recursive} is passed.
2750
2751 @item -r
2752 @itemx --recursive
2753 When combined with @code{--export}, this instructs @command{guix
2754 archive} to include dependencies of the given items in the archive.
2755 Thus, the resulting archive is self-contained: it contains the closure
2756 of the exported store items.
2757
2758 @item --import
2759 Read an archive from the standard input, and import the files listed
2760 therein into the store. Abort if the archive has an invalid digital
2761 signature, or if it is signed by a public key not among the authorized
2762 keys (see @code{--authorize} below.)
2763
2764 @item --missing
2765 Read a list of store file names from the standard input, one per line,
2766 and write on the standard output the subset of these files missing from
2767 the store.
2768
2769 @item --generate-key[=@var{parameters}]
2770 @cindex signing, archives
2771 Generate a new key pair for the daemon. This is a prerequisite before
2772 archives can be exported with @code{--export}. Note that this operation
2773 usually takes time, because it needs to gather enough entropy to
2774 generate the key pair.
2775
2776 The generated key pair is typically stored under @file{/etc/guix}, in
2777 @file{signing-key.pub} (public key) and @file{signing-key.sec} (private
2778 key, which must be kept secret.) When @var{parameters} is omitted,
2779 an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2780 versions before 1.6.0, it is a 4096-bit RSA key.
2781 Alternatively, @var{parameters} can specify
2782 @code{genkey} parameters suitable for Libgcrypt (@pxref{General
2783 public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2784 Libgcrypt Reference Manual}).
2785
2786 @item --authorize
2787 @cindex authorizing, archives
2788 Authorize imports signed by the public key passed on standard input.
2789 The public key must be in ``s-expression advanced format''---i.e., the
2790 same format as the @file{signing-key.pub} file.
2791
2792 The list of authorized keys is kept in the human-editable file
2793 @file{/etc/guix/acl}. The file contains
2794 @url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2795 s-expressions''} and is structured as an access-control list in the
2796 @url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2797 (SPKI)}.
2798
2799 @item --extract=@var{directory}
2800 @itemx -x @var{directory}
2801 Read a single-item archive as served by substitute servers
2802 (@pxref{Substitutes}) and extract it to @var{directory}. This is a
2803 low-level operation needed in only very narrow use cases; see below.
2804
2805 For example, the following command extracts the substitute for Emacs
2806 served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2807
2808 @example
2809 $ wget -O - \
2810 https://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
2811 | bunzip2 | guix archive -x /tmp/emacs
2812 @end example
2813
2814 Single-item archives are different from multiple-item archives produced
2815 by @command{guix archive --export}; they contain a single store item,
2816 and they do @emph{not} embed a signature. Thus this operation does
2817 @emph{no} signature verification and its output should be considered
2818 unsafe.
2819
2820 The primary purpose of this operation is to facilitate inspection of
2821 archive contents coming from possibly untrusted substitute servers.
2822
2823 @end table
2824
2825 @c *********************************************************************
2826 @node Programming Interface
2827 @chapter Programming Interface
2828
2829 GNU Guix provides several Scheme programming interfaces (APIs) to
2830 define, build, and query packages. The first interface allows users to
2831 write high-level package definitions. These definitions refer to
2832 familiar packaging concepts, such as the name and version of a package,
2833 its build system, and its dependencies. These definitions can then be
2834 turned into concrete build actions.
2835
2836 Build actions are performed by the Guix daemon, on behalf of users. In a
2837 standard setup, the daemon has write access to the store---the
2838 @file{/gnu/store} directory---whereas users do not. The recommended
2839 setup also has the daemon perform builds in chroots, under a specific
2840 build users, to minimize interference with the rest of the system.
2841
2842 @cindex derivation
2843 Lower-level APIs are available to interact with the daemon and the
2844 store. To instruct the daemon to perform a build action, users actually
2845 provide it with a @dfn{derivation}. A derivation is a low-level
2846 representation of the build actions to be taken, and the environment in
2847 which they should occur---derivations are to package definitions what
2848 assembly is to C programs. The term ``derivation'' comes from the fact
2849 that build results @emph{derive} from them.
2850
2851 This chapter describes all these APIs in turn, starting from high-level
2852 package definitions.
2853
2854 @menu
2855 * Defining Packages:: Defining new packages.
2856 * Build Systems:: Specifying how packages are built.
2857 * The Store:: Manipulating the package store.
2858 * Derivations:: Low-level interface to package derivations.
2859 * The Store Monad:: Purely functional interface to the store.
2860 * G-Expressions:: Manipulating build expressions.
2861 @end menu
2862
2863 @node Defining Packages
2864 @section Defining Packages
2865
2866 The high-level interface to package definitions is implemented in the
2867 @code{(guix packages)} and @code{(guix build-system)} modules. As an
2868 example, the package definition, or @dfn{recipe}, for the GNU Hello
2869 package looks like this:
2870
2871 @example
2872 (define-module (gnu packages hello)
2873 #:use-module (guix packages)
2874 #:use-module (guix download)
2875 #:use-module (guix build-system gnu)
2876 #:use-module (guix licenses)
2877 #:use-module (gnu packages gawk))
2878
2879 (define-public hello
2880 (package
2881 (name "hello")
2882 (version "2.10")
2883 (source (origin
2884 (method url-fetch)
2885 (uri (string-append "mirror://gnu/hello/hello-" version
2886 ".tar.gz"))
2887 (sha256
2888 (base32
2889 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
2890 (build-system gnu-build-system)
2891 (arguments '(#:configure-flags '("--enable-silent-rules")))
2892 (inputs `(("gawk" ,gawk)))
2893 (synopsis "Hello, GNU world: An example GNU package")
2894 (description "Guess what GNU Hello prints!")
2895 (home-page "http://www.gnu.org/software/hello/")
2896 (license gpl3+)))
2897 @end example
2898
2899 @noindent
2900 Without being a Scheme expert, the reader may have guessed the meaning
2901 of the various fields here. This expression binds the variable
2902 @code{hello} to a @code{<package>} object, which is essentially a record
2903 (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2904 This package object can be inspected using procedures found in the
2905 @code{(guix packages)} module; for instance, @code{(package-name hello)}
2906 returns---surprise!---@code{"hello"}.
2907
2908 With luck, you may be able to import part or all of the definition of
2909 the package you are interested in from another repository, using the
2910 @code{guix import} command (@pxref{Invoking guix import}).
2911
2912 In the example above, @var{hello} is defined in a module of its own,
2913 @code{(gnu packages hello)}. Technically, this is not strictly
2914 necessary, but it is convenient to do so: all the packages defined in
2915 modules under @code{(gnu packages @dots{})} are automatically known to
2916 the command-line tools (@pxref{Package Modules}).
2917
2918 There are a few points worth noting in the above package definition:
2919
2920 @itemize
2921 @item
2922 The @code{source} field of the package is an @code{<origin>} object
2923 (@pxref{origin Reference}, for the complete reference).
2924 Here, the @code{url-fetch} method from @code{(guix download)} is used,
2925 meaning that the source is a file to be downloaded over FTP or HTTP.
2926
2927 The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2928 the GNU mirrors defined in @code{(guix download)}.
2929
2930 The @code{sha256} field specifies the expected SHA256 hash of the file
2931 being downloaded. It is mandatory, and allows Guix to check the
2932 integrity of the file. The @code{(base32 @dots{})} form introduces the
2933 base32 representation of the hash. You can obtain this information with
2934 @code{guix download} (@pxref{Invoking guix download}) and @code{guix
2935 hash} (@pxref{Invoking guix hash}).
2936
2937 @cindex patches
2938 When needed, the @code{origin} form can also have a @code{patches} field
2939 listing patches to be applied, and a @code{snippet} field giving a
2940 Scheme expression to modify the source code.
2941
2942 @item
2943 @cindex GNU Build System
2944 The @code{build-system} field specifies the procedure to build the
2945 package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2946 represents the familiar GNU Build System, where packages may be
2947 configured, built, and installed with the usual @code{./configure &&
2948 make && make check && make install} command sequence.
2949
2950 @item
2951 The @code{arguments} field specifies options for the build system
2952 (@pxref{Build Systems}). Here it is interpreted by
2953 @var{gnu-build-system} as a request run @file{configure} with the
2954 @code{--enable-silent-rules} flag.
2955
2956 @cindex quote
2957 @cindex quoting
2958 @findex '
2959 @findex quote
2960 What about these quote (@code{'}) characters? They are Scheme syntax to
2961 introduce a literal list; @code{'} is synonymous with @code{quote}.
2962 @xref{Expression Syntax, quoting,, guile, GNU Guile Reference Manual},
2963 for details. Here the value of the @code{arguments} field is a list of
2964 arguments passed to the build system down the road, as with @code{apply}
2965 (@pxref{Fly Evaluation, @code{apply},, guile, GNU Guile Reference
2966 Manual}).
2967
2968 The hash-colon (@code{#:}) sequence defines a Scheme @dfn{keyword}
2969 (@pxref{Keywords,,, guile, GNU Guile Reference Manual}), and
2970 @code{#:configure-flags} is a keyword used to pass a keyword argument
2971 to the build system (@pxref{Coding With Keywords,,, guile, GNU Guile
2972 Reference Manual}).
2973
2974 @item
2975 The @code{inputs} field specifies inputs to the build process---i.e.,
2976 build-time or run-time dependencies of the package. Here, we define an
2977 input called @code{"gawk"} whose value is that of the @var{gawk}
2978 variable; @var{gawk} is itself bound to a @code{<package>} object.
2979
2980 @cindex backquote (quasiquote)
2981 @findex `
2982 @findex quasiquote
2983 @cindex comma (unquote)
2984 @findex ,
2985 @findex unquote
2986 @findex ,@@
2987 @findex unquote-splicing
2988 Again, @code{`} (a backquote, synonymous with @code{quasiquote}) allows
2989 us to introduce a literal list in the @code{inputs} field, while
2990 @code{,} (a comma, synonymous with @code{unquote}) allows us to insert a
2991 value in that list (@pxref{Expression Syntax, unquote,, guile, GNU Guile
2992 Reference Manual}).
2993
2994 Note that GCC, Coreutils, Bash, and other essential tools do not need to
2995 be specified as inputs here. Instead, @var{gnu-build-system} takes care
2996 of ensuring that they are present (@pxref{Build Systems}).
2997
2998 However, any other dependencies need to be specified in the
2999 @code{inputs} field. Any dependency not specified here will simply be
3000 unavailable to the build process, possibly leading to a build failure.
3001 @end itemize
3002
3003 @xref{package Reference}, for a full description of possible fields.
3004
3005 Once a package definition is in place, the
3006 package may actually be built using the @code{guix build} command-line
3007 tool (@pxref{Invoking guix build}), troubleshooting any build failures
3008 you encounter (@pxref{Debugging Build Failures}). You can easily jump back to the
3009 package definition using the @command{guix edit} command
3010 (@pxref{Invoking guix edit}).
3011 @xref{Packaging Guidelines}, for
3012 more information on how to test package definitions, and
3013 @ref{Invoking guix lint}, for information on how to check a definition
3014 for style conformance.
3015 @vindex GUIX_PACKAGE_PATH
3016 Lastly, @pxref{Package Modules}, for information
3017 on how to extend the distribution by adding your own package definitions
3018 to @code{GUIX_PACKAGE_PATH}.
3019
3020 Finally, updating the package definition to a new upstream version
3021 can be partly automated by the @command{guix refresh} command
3022 (@pxref{Invoking guix refresh}).
3023
3024 Behind the scenes, a derivation corresponding to the @code{<package>}
3025 object is first computed by the @code{package-derivation} procedure.
3026 That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
3027 The build actions it prescribes may then be realized by using the
3028 @code{build-derivations} procedure (@pxref{The Store}).
3029
3030 @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
3031 Return the @code{<derivation>} object of @var{package} for @var{system}
3032 (@pxref{Derivations}).
3033
3034 @var{package} must be a valid @code{<package>} object, and @var{system}
3035 must be a string denoting the target system type---e.g.,
3036 @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
3037 must be a connection to the daemon, which operates on the store
3038 (@pxref{The Store}).
3039 @end deffn
3040
3041 @noindent
3042 @cindex cross-compilation
3043 Similarly, it is possible to compute a derivation that cross-builds a
3044 package for some other system:
3045
3046 @deffn {Scheme Procedure} package-cross-derivation @var{store} @
3047 @var{package} @var{target} [@var{system}]
3048 Return the @code{<derivation>} object of @var{package} cross-built from
3049 @var{system} to @var{target}.
3050
3051 @var{target} must be a valid GNU triplet denoting the target hardware
3052 and operating system, such as @code{"mips64el-linux-gnu"}
3053 (@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
3054 Configure and Build System}).
3055 @end deffn
3056
3057 @cindex package transformations
3058 @cindex input rewriting
3059 @cindex dependency tree rewriting
3060 Packages can be manipulated in arbitrary ways. An example of a useful
3061 transformation is @dfn{input rewriting}, whereby the dependency tree of
3062 a package is rewritten by replacing specific inputs by others:
3063
3064 @deffn {Scheme Procedure} package-input-rewriting @var{replacements} @
3065 [@var{rewrite-name}]
3066 Return a procedure that, when passed a package, replaces its direct and
3067 indirect dependencies (but not its implicit inputs) according to
3068 @var{replacements}. @var{replacements} is a list of package pairs; the
3069 first element of each pair is the package to replace, and the second one
3070 is the replacement.
3071
3072 Optionally, @var{rewrite-name} is a one-argument procedure that takes
3073 the name of a package and returns its new name after rewrite.
3074 @end deffn
3075
3076 @noindent
3077 Consider this example:
3078
3079 @example
3080 (define libressl-instead-of-openssl
3081 ;; This is a procedure to replace OPENSSL by LIBRESSL,
3082 ;; recursively.
3083 (package-input-rewriting `((,openssl . ,libressl))))
3084
3085 (define git-with-libressl
3086 (libressl-instead-of-openssl git))
3087 @end example
3088
3089 @noindent
3090 Here we first define a rewriting procedure that replaces @var{openssl}
3091 with @var{libressl}. Then we use it to define a @dfn{variant} of the
3092 @var{git} package that uses @var{libressl} instead of @var{openssl}.
3093 This is exactly what the @option{--with-input} command-line option does
3094 (@pxref{Package Transformation Options, @option{--with-input}}).
3095
3096 A more generic procedure to rewrite a package dependency graph is
3097 @code{package-mapping}: it supports arbitrary changes to nodes in the
3098 graph.
3099
3100 @deffn {Scheme Procedure} package-mapping @var{proc} [@var{cut?}]
3101 Return a procedure that, given a package, applies @var{proc} to all the packages
3102 depended on and returns the resulting package. The procedure stops recursion
3103 when @var{cut?} returns true for a given package.
3104 @end deffn
3105
3106 @menu
3107 * package Reference :: The package data type.
3108 * origin Reference:: The origin data type.
3109 @end menu
3110
3111
3112 @node package Reference
3113 @subsection @code{package} Reference
3114
3115 This section summarizes all the options available in @code{package}
3116 declarations (@pxref{Defining Packages}).
3117
3118 @deftp {Data Type} package
3119 This is the data type representing a package recipe.
3120
3121 @table @asis
3122 @item @code{name}
3123 The name of the package, as a string.
3124
3125 @item @code{version}
3126 The version of the package, as a string.
3127
3128 @item @code{source}
3129 An object telling how the source code for the package should be
3130 acquired. Most of the time, this is an @code{origin} object, which
3131 denotes a file fetched from the Internet (@pxref{origin Reference}). It
3132 can also be any other ``file-like'' object such as a @code{local-file},
3133 which denotes a file from the local file system (@pxref{G-Expressions,
3134 @code{local-file}}).
3135
3136 @item @code{build-system}
3137 The build system that should be used to build the package (@pxref{Build
3138 Systems}).
3139
3140 @item @code{arguments} (default: @code{'()})
3141 The arguments that should be passed to the build system. This is a
3142 list, typically containing sequential keyword-value pairs.
3143
3144 @item @code{inputs} (default: @code{'()})
3145 @itemx @code{native-inputs} (default: @code{'()})
3146 @itemx @code{propagated-inputs} (default: @code{'()})
3147 @cindex inputs, of packages
3148 These fields list dependencies of the package. Each one is a list of
3149 tuples, where each tuple has a label for the input (a string) as its
3150 first element, a package, origin, or derivation as its second element,
3151 and optionally the name of the output thereof that should be used, which
3152 defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
3153 more on package outputs). For example, the list below specifies three
3154 inputs:
3155
3156 @example
3157 `(("libffi" ,libffi)
3158 ("libunistring" ,libunistring)
3159 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
3160 @end example
3161
3162 @cindex cross compilation, package dependencies
3163 The distinction between @code{native-inputs} and @code{inputs} is
3164 necessary when considering cross-compilation. When cross-compiling,
3165 dependencies listed in @code{inputs} are built for the @emph{target}
3166 architecture; conversely, dependencies listed in @code{native-inputs}
3167 are built for the architecture of the @emph{build} machine.
3168
3169 @code{native-inputs} is typically used to list tools needed at
3170 build time, but not at run time, such as Autoconf, Automake, pkg-config,
3171 Gettext, or Bison. @command{guix lint} can report likely mistakes in
3172 this area (@pxref{Invoking guix lint}).
3173
3174 @anchor{package-propagated-inputs}
3175 Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
3176 specified packages will be automatically installed alongside the package
3177 they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
3178 package}}, for information on how @command{guix package} deals with
3179 propagated inputs.)
3180
3181 For example this is necessary when a C/C++ library needs headers of
3182 another library to compile, or when a pkg-config file refers to another
3183 one @i{via} its @code{Requires} field.
3184
3185 Another example where @code{propagated-inputs} is useful is for languages
3186 that lack a facility to record the run-time search path akin to the
3187 @code{RUNPATH} of ELF files; this includes Guile, Python, Perl, and
3188 more. To ensure that libraries written in those languages can find
3189 library code they depend on at run time, run-time dependencies must be
3190 listed in @code{propagated-inputs} rather than @code{inputs}.
3191
3192 @item @code{self-native-input?} (default: @code{#f})
3193 This is a Boolean field telling whether the package should use itself as
3194 a native input when cross-compiling.
3195
3196 @item @code{outputs} (default: @code{'("out")})
3197 The list of output names of the package. @xref{Packages with Multiple
3198 Outputs}, for typical uses of additional outputs.
3199
3200 @item @code{native-search-paths} (default: @code{'()})
3201 @itemx @code{search-paths} (default: @code{'()})
3202 A list of @code{search-path-specification} objects describing
3203 search-path environment variables honored by the package.
3204
3205 @item @code{replacement} (default: @code{#f})
3206 This must be either @code{#f} or a package object that will be used as a
3207 @dfn{replacement} for this package. @xref{Security Updates, grafts},
3208 for details.
3209
3210 @item @code{synopsis}
3211 A one-line description of the package.
3212
3213 @item @code{description}
3214 A more elaborate description of the package.
3215
3216 @item @code{license}
3217 @cindex license, of packages
3218 The license of the package; a value from @code{(guix licenses)},
3219 or a list of such values.
3220
3221 @item @code{home-page}
3222 The URL to the home-page of the package, as a string.
3223
3224 @item @code{supported-systems} (default: @var{%supported-systems})
3225 The list of systems supported by the package, as strings of the form
3226 @code{architecture-kernel}, for example @code{"x86_64-linux"}.
3227
3228 @item @code{maintainers} (default: @code{'()})
3229 The list of maintainers of the package, as @code{maintainer} objects.
3230
3231 @item @code{location} (default: source location of the @code{package} form)
3232 The source location of the package. It is useful to override this when
3233 inheriting from another package, in which case this field is not
3234 automatically corrected.
3235 @end table
3236 @end deftp
3237
3238
3239 @node origin Reference
3240 @subsection @code{origin} Reference
3241
3242 This section summarizes all the options available in @code{origin}
3243 declarations (@pxref{Defining Packages}).
3244
3245 @deftp {Data Type} origin
3246 This is the data type representing a source code origin.
3247
3248 @table @asis
3249 @item @code{uri}
3250 An object containing the URI of the source. The object type depends on
3251 the @code{method} (see below). For example, when using the
3252 @var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
3253 values are: a URL represented as a string, or a list thereof.
3254
3255 @item @code{method}
3256 A procedure that handles the URI.
3257
3258 Examples include:
3259
3260 @table @asis
3261 @item @var{url-fetch} from @code{(guix download)}
3262 download a file from the HTTP, HTTPS, or FTP URL specified in the
3263 @code{uri} field;
3264
3265 @vindex git-fetch
3266 @item @var{git-fetch} from @code{(guix git-download)}
3267 clone the Git version control repository, and check out the revision
3268 specified in the @code{uri} field as a @code{git-reference} object; a
3269 @code{git-reference} looks like this:
3270
3271 @example
3272 (git-reference
3273 (url "git://git.debian.org/git/pkg-shadow/shadow")
3274 (commit "v4.1.5.1"))
3275 @end example
3276 @end table
3277
3278 @item @code{sha256}
3279 A bytevector containing the SHA-256 hash of the source. Typically the
3280 @code{base32} form is used here to generate the bytevector from a
3281 base-32 string.
3282
3283 You can obtain this information using @code{guix download}
3284 (@pxref{Invoking guix download}) or @code{guix hash} (@pxref{Invoking
3285 guix hash}).
3286
3287 @item @code{file-name} (default: @code{#f})
3288 The file name under which the source code should be saved. When this is
3289 @code{#f}, a sensible default value will be used in most cases. In case
3290 the source is fetched from a URL, the file name from the URL will be
3291 used. For version control checkouts, it is recommended to provide the
3292 file name explicitly because the default is not very descriptive.
3293
3294 @item @code{patches} (default: @code{'()})
3295 A list of file names, origins, or file-like objects (@pxref{G-Expressions,
3296 file-like objects}) pointing to patches to be applied to the source.
3297
3298 This list of patches must be unconditional. In particular, it cannot
3299 depend on the value of @code{%current-system} or
3300 @code{%current-target-system}.
3301
3302 @item @code{snippet} (default: @code{#f})
3303 A G-expression (@pxref{G-Expressions}) or S-expression that will be run
3304 in the source directory. This is a convenient way to modify the source,
3305 sometimes more convenient than a patch.
3306
3307 @item @code{patch-flags} (default: @code{'("-p1")})
3308 A list of command-line flags that should be passed to the @code{patch}
3309 command.
3310
3311 @item @code{patch-inputs} (default: @code{#f})
3312 Input packages or derivations to the patching process. When this is
3313 @code{#f}, the usual set of inputs necessary for patching are provided,
3314 such as GNU@tie{}Patch.
3315
3316 @item @code{modules} (default: @code{'()})
3317 A list of Guile modules that should be loaded during the patching
3318 process and while running the code in the @code{snippet} field.
3319
3320 @item @code{patch-guile} (default: @code{#f})
3321 The Guile package that should be used in the patching process. When
3322 this is @code{#f}, a sensible default is used.
3323 @end table
3324 @end deftp
3325
3326
3327 @node Build Systems
3328 @section Build Systems
3329
3330 @cindex build system
3331 Each package definition specifies a @dfn{build system} and arguments for
3332 that build system (@pxref{Defining Packages}). This @code{build-system}
3333 field represents the build procedure of the package, as well as implicit
3334 dependencies of that build procedure.
3335
3336 Build systems are @code{<build-system>} objects. The interface to
3337 create and manipulate them is provided by the @code{(guix build-system)}
3338 module, and actual build systems are exported by specific modules.
3339
3340 @cindex bag (low-level package representation)
3341 Under the hood, build systems first compile package objects to
3342 @dfn{bags}. A @dfn{bag} is like a package, but with less
3343 ornamentation---in other words, a bag is a lower-level representation of
3344 a package, which includes all the inputs of that package, including some
3345 that were implicitly added by the build system. This intermediate
3346 representation is then compiled to a derivation (@pxref{Derivations}).
3347
3348 Build systems accept an optional list of @dfn{arguments}. In package
3349 definitions, these are passed @i{via} the @code{arguments} field
3350 (@pxref{Defining Packages}). They are typically keyword arguments
3351 (@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
3352 Guile Reference Manual}). The value of these arguments is usually
3353 evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
3354 by the daemon (@pxref{Derivations}).
3355
3356 The main build system is @var{gnu-build-system}, which implements the
3357 standard build procedure for GNU and many other packages. It
3358 is provided by the @code{(guix build-system gnu)} module.
3359
3360 @defvr {Scheme Variable} gnu-build-system
3361 @var{gnu-build-system} represents the GNU Build System, and variants
3362 thereof (@pxref{Configuration, configuration and makefile conventions,,
3363 standards, GNU Coding Standards}).
3364
3365 @cindex build phases
3366 In a nutshell, packages using it are configured, built, and installed with
3367 the usual @code{./configure && make && make check && make install}
3368 command sequence. In practice, a few additional steps are often needed.
3369 All these steps are split up in separate @dfn{phases},
3370 notably@footnote{Please see the @code{(guix build gnu-build-system)}
3371 modules for more details about the build phases.}:
3372
3373 @table @code
3374 @item unpack
3375 Unpack the source tarball, and change the current directory to the
3376 extracted source tree. If the source is actually a directory, copy it
3377 to the build tree, and enter that directory.
3378
3379 @item patch-source-shebangs
3380 Patch shebangs encountered in source files so they refer to the right
3381 store file names. For instance, this changes @code{#!/bin/sh} to
3382 @code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
3383
3384 @item configure
3385 Run the @file{configure} script with a number of default options, such
3386 as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
3387 by the @code{#:configure-flags} argument.
3388
3389 @item build
3390 Run @code{make} with the list of flags specified with
3391 @code{#:make-flags}. If the @code{#:parallel-build?} argument is true
3392 (the default), build with @code{make -j}.
3393
3394 @item check
3395 Run @code{make check}, or some other target specified with
3396 @code{#:test-target}, unless @code{#:tests? #f} is passed. If the
3397 @code{#:parallel-tests?} argument is true (the default), run @code{make
3398 check -j}.
3399
3400 @item install
3401 Run @code{make install} with the flags listed in @code{#:make-flags}.
3402
3403 @item patch-shebangs
3404 Patch shebangs on the installed executable files.
3405
3406 @item strip
3407 Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
3408 is false), copying them to the @code{debug} output when available
3409 (@pxref{Installing Debugging Files}).
3410 @end table
3411
3412 @vindex %standard-phases
3413 The build-side module @code{(guix build gnu-build-system)} defines
3414 @var{%standard-phases} as the default list of build phases.
3415 @var{%standard-phases} is a list of symbol/procedure pairs, where the
3416 procedure implements the actual phase.
3417
3418 The list of phases used for a particular package can be changed with the
3419 @code{#:phases} parameter. For instance, passing:
3420
3421 @example
3422 #:phases (modify-phases %standard-phases (delete 'configure))
3423 @end example
3424
3425 means that all the phases described above will be used, except the
3426 @code{configure} phase.
3427
3428 In addition, this build system ensures that the ``standard'' environment
3429 for GNU packages is available. This includes tools such as GCC, libc,
3430 Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
3431 build-system gnu)} module for a complete list). We call these the
3432 @dfn{implicit inputs} of a package, because package definitions do not
3433 have to mention them.
3434 @end defvr
3435
3436 Other @code{<build-system>} objects are defined to support other
3437 conventions and tools used by free software packages. They inherit most
3438 of @var{gnu-build-system}, and differ mainly in the set of inputs
3439 implicitly added to the build process, and in the list of phases
3440 executed. Some of these build systems are listed below.
3441
3442 @defvr {Scheme Variable} ant-build-system
3443 This variable is exported by @code{(guix build-system ant)}. It
3444 implements the build procedure for Java packages that can be built with
3445 @url{http://ant.apache.org/, Ant build tool}.
3446
3447 It adds both @code{ant} and the @dfn{Java Development Kit} (JDK) as
3448 provided by the @code{icedtea} package to the set of inputs. Different
3449 packages can be specified with the @code{#:ant} and @code{#:jdk}
3450 parameters, respectively.
3451
3452 When the original package does not provide a suitable Ant build file,
3453 the parameter @code{#:jar-name} can be used to generate a minimal Ant
3454 build file @file{build.xml} with tasks to build the specified jar
3455 archive. In this case the parameter @code{#:source-dir} can be used to
3456 specify the source sub-directory, defaulting to ``src''.
3457
3458 The parameter @code{#:build-target} can be used to specify the Ant task
3459 that should be run during the @code{build} phase. By default the
3460 ``jar'' task will be run.
3461
3462 @end defvr
3463
3464 @defvr {Scheme Variable} asdf-build-system/source
3465 @defvrx {Scheme Variable} asdf-build-system/sbcl
3466 @defvrx {Scheme Variable} asdf-build-system/ecl
3467
3468 These variables, exported by @code{(guix build-system asdf)}, implement
3469 build procedures for Common Lisp packages using
3470 @url{https://common-lisp.net/project/asdf/, ``ASDF''}. ASDF is a system
3471 definition facility for Common Lisp programs and libraries.
3472
3473 The @code{asdf-build-system/source} system installs the packages in
3474 source form, and can be loaded using any common lisp implementation, via
3475 ASDF. The others, such as @code{asdf-build-system/sbcl}, install binary
3476 systems in the format which a particular implementation understands.
3477 These build systems can also be used to produce executable programs, or
3478 lisp images which contain a set of packages pre-loaded.
3479
3480 The build system uses naming conventions. For binary packages, the
3481 package name should be prefixed with the lisp implementation, such as
3482 @code{sbcl-} for @code{asdf-build-system/sbcl}.
3483
3484 Additionally, the corresponding source package should be labeled using
3485 the same convention as python packages (see @ref{Python Modules}), using
3486 the @code{cl-} prefix.
3487
3488 For binary packages, each system should be defined as a Guix package.
3489 If one package @code{origin} contains several systems, package variants
3490 can be created in order to build all the systems. Source packages,
3491 which use @code{asdf-build-system/source}, may contain several systems.
3492
3493 In order to create executable programs and images, the build-side
3494 procedures @code{build-program} and @code{build-image} can be used.
3495 They should be called in a build phase after the @code{create-symlinks}
3496 phase, so that the system which was just built can be used within the
3497 resulting image. @code{build-program} requires a list of Common Lisp
3498 expressions to be passed as the @code{#:entry-program} argument.
3499
3500 If the system is not defined within its own @code{.asd} file of the same
3501 name, then the @code{#:asd-file} parameter should be used to specify
3502 which file the system is defined in. Furthermore, if the package
3503 defines a system for its tests in a separate file, it will be loaded
3504 before the tests are run if it is specified by the
3505 @code{#:test-asd-file} parameter. If it is not set, the files
3506 @code{<system>-tests.asd}, @code{<system>-test.asd}, @code{tests.asd},
3507 and @code{test.asd} will be tried if they exist.
3508
3509 If for some reason the package must be named in a different way than the
3510 naming conventions suggest, the @code{#:asd-system-name} parameter can
3511 be used to specify the name of the system.
3512
3513 @end defvr
3514
3515 @defvr {Scheme Variable} cargo-build-system
3516 @cindex Rust programming language
3517 @cindex Cargo (Rust build system)
3518 This variable is exported by @code{(guix build-system cargo)}. It
3519 supports builds of packages using Cargo, the build tool of the
3520 @uref{https://www.rust-lang.org, Rust programming language}.
3521
3522 In its @code{configure} phase, this build system replaces dependencies
3523 specified in the @file{Carto.toml} file with inputs to the Guix package.
3524 The @code{install} phase installs the binaries, and it also installs the
3525 source code and @file{Cargo.toml} file.
3526 @end defvr
3527
3528 @defvr {Scheme Variable} cmake-build-system
3529 This variable is exported by @code{(guix build-system cmake)}. It
3530 implements the build procedure for packages using the
3531 @url{http://www.cmake.org, CMake build tool}.
3532
3533 It automatically adds the @code{cmake} package to the set of inputs.
3534 Which package is used can be specified with the @code{#:cmake}
3535 parameter.
3536
3537 The @code{#:configure-flags} parameter is taken as a list of flags
3538 passed to the @command{cmake} command. The @code{#:build-type}
3539 parameter specifies in abstract terms the flags passed to the compiler;
3540 it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
3541 debugging information''), which roughly means that code is compiled with
3542 @code{-O2 -g}, as is the case for Autoconf-based packages by default.
3543 @end defvr
3544
3545 @defvr {Scheme Variable} glib-or-gtk-build-system
3546 This variable is exported by @code{(guix build-system glib-or-gtk)}. It
3547 is intended for use with packages making use of GLib or GTK+.
3548
3549 This build system adds the following two phases to the ones defined by
3550 @var{gnu-build-system}:
3551
3552 @table @code
3553 @item glib-or-gtk-wrap
3554 The phase @code{glib-or-gtk-wrap} ensures that programs in
3555 @file{bin/} are able to find GLib ``schemas'' and
3556 @uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
3557 modules}. This is achieved by wrapping the programs in launch scripts
3558 that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
3559 environment variables.
3560
3561 It is possible to exclude specific package outputs from that wrapping
3562 process by listing their names in the
3563 @code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
3564 when an output is known not to contain any GLib or GTK+ binaries, and
3565 where wrapping would gratuitously add a dependency of that output on
3566 GLib and GTK+.
3567
3568 @item glib-or-gtk-compile-schemas
3569 The phase @code{glib-or-gtk-compile-schemas} makes sure that all
3570 @uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
3571 GSettings schemas} of GLib are compiled. Compilation is performed by the
3572 @command{glib-compile-schemas} program. It is provided by the package
3573 @code{glib:bin} which is automatically imported by the build system.
3574 The @code{glib} package providing @command{glib-compile-schemas} can be
3575 specified with the @code{#:glib} parameter.
3576 @end table
3577
3578 Both phases are executed after the @code{install} phase.
3579 @end defvr
3580
3581 @defvr {Scheme Variable} minify-build-system
3582 This variable is exported by @code{(guix build-system minify)}. It
3583 implements a minification procedure for simple JavaScript packages.
3584
3585 It adds @code{uglify-js} to the set of inputs and uses it to compress
3586 all JavaScript files in the @file{src} directory. A different minifier
3587 package can be specified with the @code{#:uglify-js} parameter, but it
3588 is expected that the package writes the minified code to the standard
3589 output.
3590
3591 When the input JavaScript files are not all located in the @file{src}
3592 directory, the parameter @code{#:javascript-files} can be used to
3593 specify a list of file names to feed to the minifier.
3594 @end defvr
3595
3596 @defvr {Scheme Variable} ocaml-build-system
3597 This variable is exported by @code{(guix build-system ocaml)}. It implements
3598 a build procedure for @uref{https://ocaml.org, OCaml} packages, which consists
3599 of choosing the correct set of commands to run for each package. OCaml
3600 packages can expect many different commands to be run. This build system will
3601 try some of them.
3602
3603 When the package has a @file{setup.ml} file present at the top-level, it will
3604 run @code{ocaml setup.ml -configure}, @code{ocaml setup.ml -build} and
3605 @code{ocaml setup.ml -install}. The build system will assume that this file
3606 was generated by @uref{http://oasis.forge.ocamlcore.org/, OASIS} and will take
3607 care of setting the prefix and enabling tests if they are not disabled. You
3608 can pass configure and build flags with the @code{#:configure-flags} and
3609 @code{#:build-flags}. The @code{#:test-flags} key can be passed to change the
3610 set of flags used to enable tests. The @code{#:use-make?} key can be used to
3611 bypass this system in the build and install phases.
3612
3613 When the package has a @file{configure} file, it is assumed that it is a
3614 hand-made configure script that requires a different argument format than
3615 in the @code{gnu-build-system}. You can add more flags with the
3616 @code{#:configure-flags} key.
3617
3618 When the package has a @file{Makefile} file (or @code{#:use-make?} is
3619 @code{#t}), it will be used and more flags can be passed to the build and
3620 install phases with the @code{#:make-flags} key.
3621
3622 Finally, some packages do not have these files and use a somewhat standard
3623 location for its build system. In that case, the build system will run
3624 @code{ocaml pkg/pkg.ml} or @code{ocaml pkg/build.ml} and take care of
3625 providing the path to the required findlib module. Additional flags can
3626 be passed via the @code{#:build-flags} key. Install is taken care of by
3627 @command{opam-installer}. In this case, the @code{opam} package must
3628 be added to the @code{native-inputs} field of the package definition.
3629
3630 Note that most OCaml packages assume they will be installed in the same
3631 directory as OCaml, which is not what we want in guix. In particular, they
3632 will install @file{.so} files in their module's directory, which is usually
3633 fine because it is in the OCaml compiler directory. In guix though, these
3634 libraries cannot be found and we use @code{CAML_LD_LIBRARY_PATH}. This
3635 variable points to @file{lib/ocaml/site-lib/stubslibs} and this is where
3636 @file{.so} libraries should be installed.
3637 @end defvr
3638
3639 @defvr {Scheme Variable} python-build-system
3640 This variable is exported by @code{(guix build-system python)}. It
3641 implements the more or less standard build procedure used by Python
3642 packages, which consists in running @code{python setup.py build} and
3643 then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
3644
3645 For packages that install stand-alone Python programs under @code{bin/},
3646 it takes care of wrapping these programs so that their @code{PYTHONPATH}
3647 environment variable points to all the Python libraries they depend on.
3648
3649 Which Python package is used to perform the build can be specified with
3650 the @code{#:python} parameter. This is a useful way to force a package
3651 to be built for a specific version of the Python interpreter, which
3652 might be necessary if the package is only compatible with a single
3653 interpreter version.
3654
3655 By default guix calls @code{setup.py} under control of
3656 @code{setuptools}, much like @command{pip} does. Some packages are not
3657 compatible with setuptools (and pip), thus you can disable this by
3658 setting the @code{#:use-setuptools} parameter to @code{#f}.
3659 @end defvr
3660
3661 @defvr {Scheme Variable} perl-build-system
3662 This variable is exported by @code{(guix build-system perl)}. It
3663 implements the standard build procedure for Perl packages, which either
3664 consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
3665 followed by @code{Build} and @code{Build install}; or in running
3666 @code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
3667 @code{make} and @code{make install}, depending on which of
3668 @code{Build.PL} or @code{Makefile.PL} is present in the package
3669 distribution. Preference is given to the former if both @code{Build.PL}
3670 and @code{Makefile.PL} exist in the package distribution. This
3671 preference can be reversed by specifying @code{#t} for the
3672 @code{#:make-maker?} parameter.
3673
3674 The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
3675 passes flags specified by the @code{#:make-maker-flags} or
3676 @code{#:module-build-flags} parameter, respectively.
3677
3678 Which Perl package is used can be specified with @code{#:perl}.
3679 @end defvr
3680
3681 @defvr {Scheme Variable} r-build-system
3682 This variable is exported by @code{(guix build-system r)}. It
3683 implements the build procedure used by @uref{http://r-project.org, R}
3684 packages, which essentially is little more than running @code{R CMD
3685 INSTALL --library=/gnu/store/@dots{}} in an environment where
3686 @code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
3687 are run after installation using the R function
3688 @code{tools::testInstalledPackage}.
3689 @end defvr
3690
3691 @defvr {Scheme Variable} texlive-build-system
3692 This variable is exported by @code{(guix build-system texlive)}. It is
3693 used to build TeX packages in batch mode with a specified engine. The
3694 build system sets the @code{TEXINPUTS} variable to find all TeX source
3695 files in the inputs.
3696
3697 By default it runs @code{luatex} on all files ending on @code{ins}. A
3698 different engine and format can be specified with the
3699 @code{#:tex-format} argument. Different build targets can be specified
3700 with the @code{#:build-targets} argument, which expects a list of file
3701 names. The build system adds only @code{texlive-bin} and
3702 @code{texlive-latex-base} (both from @code{(gnu packages tex}) to the
3703 inputs. Both can be overridden with the arguments @code{#:texlive-bin}
3704 and @code{#:texlive-latex-base}, respectively.
3705
3706 The @code{#:tex-directory} parameter tells the build system where to
3707 install the built files under the texmf tree.
3708 @end defvr
3709
3710 @defvr {Scheme Variable} ruby-build-system
3711 This variable is exported by @code{(guix build-system ruby)}. It
3712 implements the RubyGems build procedure used by Ruby packages, which
3713 involves running @code{gem build} followed by @code{gem install}.
3714
3715 The @code{source} field of a package that uses this build system
3716 typically references a gem archive, since this is the format that Ruby
3717 developers use when releasing their software. The build system unpacks
3718 the gem archive, potentially patches the source, runs the test suite,
3719 repackages the gem, and installs it. Additionally, directories and
3720 tarballs may be referenced to allow building unreleased gems from Git or
3721 a traditional source release tarball.
3722
3723 Which Ruby package is used can be specified with the @code{#:ruby}
3724 parameter. A list of additional flags to be passed to the @command{gem}
3725 command can be specified with the @code{#:gem-flags} parameter.
3726 @end defvr
3727
3728 @defvr {Scheme Variable} waf-build-system
3729 This variable is exported by @code{(guix build-system waf)}. It
3730 implements a build procedure around the @code{waf} script. The common
3731 phases---@code{configure}, @code{build}, and @code{install}---are
3732 implemented by passing their names as arguments to the @code{waf}
3733 script.
3734
3735 The @code{waf} script is executed by the Python interpreter. Which
3736 Python package is used to run the script can be specified with the
3737 @code{#:python} parameter.
3738 @end defvr
3739
3740 @defvr {Scheme Variable} haskell-build-system
3741 This variable is exported by @code{(guix build-system haskell)}. It
3742 implements the Cabal build procedure used by Haskell packages, which
3743 involves running @code{runhaskell Setup.hs configure
3744 --prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
3745 Instead of installing the package by running @code{runhaskell Setup.hs
3746 install}, to avoid trying to register libraries in the read-only
3747 compiler store directory, the build system uses @code{runhaskell
3748 Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
3749 addition, the build system generates the package documentation by
3750 running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
3751 is passed. Optional Haddock parameters can be passed with the help of
3752 the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
3753 not found, the build system looks for @code{Setup.lhs} instead.
3754
3755 Which Haskell compiler is used can be specified with the @code{#:haskell}
3756 parameter which defaults to @code{ghc}.
3757 @end defvr
3758
3759 @defvr {Scheme Variable} dub-build-system
3760 This variable is exported by @code{(guix build-system dub)}. It
3761 implements the Dub build procedure used by D packages, which
3762 involves running @code{dub build} and @code{dub run}.
3763 Installation is done by copying the files manually.
3764
3765 Which D compiler is used can be specified with the @code{#:ldc}
3766 parameter which defaults to @code{ldc}.
3767 @end defvr
3768
3769 @defvr {Scheme Variable} emacs-build-system
3770 This variable is exported by @code{(guix build-system emacs)}. It
3771 implements an installation procedure similar to the packaging system
3772 of Emacs itself (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
3773
3774 It first creates the @code{@var{package}-autoloads.el} file, then it
3775 byte compiles all Emacs Lisp files. Differently from the Emacs
3776 packaging system, the Info documentation files are moved to the standard
3777 documentation directory and the @file{dir} file is deleted. Each
3778 package is installed in its own directory under
3779 @file{share/emacs/site-lisp/guix.d}.
3780 @end defvr
3781
3782 @defvr {Scheme Variable} font-build-system
3783 This variable is exported by @code{(guix build-system font)}. It
3784 implements an installation procedure for font packages where upstream
3785 provides pre-compiled TrueType, OpenType, etc. font files that merely
3786 need to be copied into place. It copies font files to standard
3787 locations in the output directory.
3788 @end defvr
3789
3790 Lastly, for packages that do not need anything as sophisticated, a
3791 ``trivial'' build system is provided. It is trivial in the sense that
3792 it provides basically no support: it does not pull any implicit inputs,
3793 and does not have a notion of build phases.
3794
3795 @defvr {Scheme Variable} trivial-build-system
3796 This variable is exported by @code{(guix build-system trivial)}.
3797
3798 This build system requires a @code{#:builder} argument. This argument
3799 must be a Scheme expression that builds the package output(s)---as
3800 with @code{build-expression->derivation} (@pxref{Derivations,
3801 @code{build-expression->derivation}}).
3802 @end defvr
3803
3804 @node The Store
3805 @section The Store
3806
3807 @cindex store
3808 @cindex store items
3809 @cindex store paths
3810
3811 Conceptually, the @dfn{store} is the place where derivations that have
3812 been built successfully are stored---by default, @file{/gnu/store}.
3813 Sub-directories in the store are referred to as @dfn{store items} or
3814 sometimes @dfn{store paths}. The store has an associated database that
3815 contains information such as the store paths referred to by each store
3816 path, and the list of @emph{valid} store items---results of successful
3817 builds. This database resides in @file{@var{localstatedir}/guix/db},
3818 where @var{localstatedir} is the state directory specified @i{via}
3819 @option{--localstatedir} at configure time, usually @file{/var}.
3820
3821 The store is @emph{always} accessed by the daemon on behalf of its clients
3822 (@pxref{Invoking guix-daemon}). To manipulate the store, clients
3823 connect to the daemon over a Unix-domain socket, send requests to it,
3824 and read the result---these are remote procedure calls, or RPCs.
3825
3826 @quotation Note
3827 Users must @emph{never} modify files under @file{/gnu/store} directly.
3828 This would lead to inconsistencies and break the immutability
3829 assumptions of Guix's functional model (@pxref{Introduction}).
3830
3831 @xref{Invoking guix gc, @command{guix gc --verify}}, for information on
3832 how to check the integrity of the store and attempt recovery from
3833 accidental modifications.
3834 @end quotation
3835
3836 The @code{(guix store)} module provides procedures to connect to the
3837 daemon, and to perform RPCs. These are described below. By default,
3838 @code{open-connection}, and thus all the @command{guix} commands,
3839 connect to the local daemon or to the URI specified by the
3840 @code{GUIX_DAEMON_SOCKET} environment variable.
3841
3842 @defvr {Environment Variable} GUIX_DAEMON_SOCKET
3843 When set, the value of this variable should be a file name or a URI
3844 designating the daemon endpoint. When it is a file name, it denotes a
3845 Unix-domain socket to connect to. In addition to file names, the
3846 supported URI schemes are:
3847
3848 @table @code
3849 @item file
3850 @itemx unix
3851 These are for Unix-domain sockets.
3852 @code{file:///var/guix/daemon-socket/socket} is equivalent to
3853 @file{/var/guix/daemon-socket/socket}.
3854
3855 @item guix
3856 @cindex daemon, remote access
3857 @cindex remote access to the daemon
3858 @cindex daemon, cluster setup
3859 @cindex clusters, daemon setup
3860 These URIs denote connections over TCP/IP, without encryption nor
3861 authentication of the remote host. The URI must specify the host name
3862 and optionally a port number (by default port 44146 is used):
3863
3864 @example
3865 guix://master.guix.example.org:1234
3866 @end example
3867
3868 This setup is suitable on local networks, such as clusters, where only
3869 trusted nodes may connect to the build daemon at
3870 @code{master.guix.example.org}.
3871
3872 The @code{--listen} option of @command{guix-daemon} can be used to
3873 instruct it to listen for TCP connections (@pxref{Invoking guix-daemon,
3874 @code{--listen}}).
3875
3876 @item ssh
3877 @cindex SSH access to build daemons
3878 These URIs allow you to connect to a remote daemon over
3879 SSH@footnote{This feature requires Guile-SSH (@pxref{Requirements}).}.
3880 A typical URL might look like this:
3881
3882 @example
3883 ssh://charlie@@guix.example.org:22
3884 @end example
3885
3886 As for @command{guix copy}, the usual OpenSSH client configuration files
3887 are honored (@pxref{Invoking guix copy}).
3888 @end table
3889
3890 Additional URI schemes may be supported in the future.
3891
3892 @c XXX: Remove this note when the protocol incurs fewer round trips
3893 @c and when (guix derivations) no longer relies on file system access.
3894 @quotation Note
3895 The ability to connect to remote build daemons is considered
3896 experimental as of @value{VERSION}. Please get in touch with us to
3897 share any problems or suggestions you may have (@pxref{Contributing}).
3898 @end quotation
3899 @end defvr
3900
3901 @deffn {Scheme Procedure} open-connection [@var{uri}] [#:reserve-space? #t]
3902 Connect to the daemon over the Unix-domain socket at @var{uri} (a string). When
3903 @var{reserve-space?} is true, instruct it to reserve a little bit of
3904 extra space on the file system so that the garbage collector can still
3905 operate should the disk become full. Return a server object.
3906
3907 @var{file} defaults to @var{%default-socket-path}, which is the normal
3908 location given the options that were passed to @command{configure}.
3909 @end deffn
3910
3911 @deffn {Scheme Procedure} close-connection @var{server}
3912 Close the connection to @var{server}.
3913 @end deffn
3914
3915 @defvr {Scheme Variable} current-build-output-port
3916 This variable is bound to a SRFI-39 parameter, which refers to the port
3917 where build and error logs sent by the daemon should be written.
3918 @end defvr
3919
3920 Procedures that make RPCs all take a server object as their first
3921 argument.
3922
3923 @deffn {Scheme Procedure} valid-path? @var{server} @var{path}
3924 @cindex invalid store items
3925 Return @code{#t} when @var{path} designates a valid store item and
3926 @code{#f} otherwise (an invalid item may exist on disk but still be
3927 invalid, for instance because it is the result of an aborted or failed
3928 build.)
3929
3930 A @code{&nix-protocol-error} condition is raised if @var{path} is not
3931 prefixed by the store directory (@file{/gnu/store}).
3932 @end deffn
3933
3934 @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
3935 Add @var{text} under file @var{name} in the store, and return its store
3936 path. @var{references} is the list of store paths referred to by the
3937 resulting store path.
3938 @end deffn
3939
3940 @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
3941 Build @var{derivations} (a list of @code{<derivation>} objects or
3942 derivation paths), and return when the worker is done building them.
3943 Return @code{#t} on success.
3944 @end deffn
3945
3946 Note that the @code{(guix monads)} module provides a monad as well as
3947 monadic versions of the above procedures, with the goal of making it
3948 more convenient to work with code that accesses the store (@pxref{The
3949 Store Monad}).
3950
3951 @c FIXME
3952 @i{This section is currently incomplete.}
3953
3954 @node Derivations
3955 @section Derivations
3956
3957 @cindex derivations
3958 Low-level build actions and the environment in which they are performed
3959 are represented by @dfn{derivations}. A derivation contains the
3960 following pieces of information:
3961
3962 @itemize
3963 @item
3964 The outputs of the derivation---derivations produce at least one file or
3965 directory in the store, but may produce more.
3966
3967 @item
3968 The inputs of the derivations, which may be other derivations or plain
3969 files in the store (patches, build scripts, etc.)
3970
3971 @item
3972 The system type targeted by the derivation---e.g., @code{x86_64-linux}.
3973
3974 @item
3975 The file name of a build script in the store, along with the arguments
3976 to be passed.
3977
3978 @item
3979 A list of environment variables to be defined.
3980
3981 @end itemize
3982
3983 @cindex derivation path
3984 Derivations allow clients of the daemon to communicate build actions to
3985 the store. They exist in two forms: as an in-memory representation,
3986 both on the client- and daemon-side, and as files in the store whose
3987 name end in @code{.drv}---these files are referred to as @dfn{derivation
3988 paths}. Derivations paths can be passed to the @code{build-derivations}
3989 procedure to perform the build actions they prescribe (@pxref{The
3990 Store}).
3991
3992 The @code{(guix derivations)} module provides a representation of
3993 derivations as Scheme objects, along with procedures to create and
3994 otherwise manipulate derivations. The lowest-level primitive to create
3995 a derivation is the @code{derivation} procedure:
3996
3997 @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
3998 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3999 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
4000 [#:system (%current-system)] [#:references-graphs #f] @
4001 [#:allowed-references #f] [#:disallowed-references #f] @
4002 [#:leaked-env-vars #f] [#:local-build? #f] @
4003 [#:substitutable? #t]
4004 Build a derivation with the given arguments, and return the resulting
4005 @code{<derivation>} object.
4006
4007 When @var{hash} and @var{hash-algo} are given, a
4008 @dfn{fixed-output derivation} is created---i.e., one whose result is
4009 known in advance, such as a file download. If, in addition,
4010 @var{recursive?} is true, then that fixed output may be an executable
4011 file or a directory and @var{hash} must be the hash of an archive
4012 containing this output.
4013
4014 When @var{references-graphs} is true, it must be a list of file
4015 name/store path pairs. In that case, the reference graph of each store
4016 path is exported in the build environment in the corresponding file, in
4017 a simple text format.
4018
4019 When @var{allowed-references} is true, it must be a list of store items
4020 or outputs that the derivation's output may refer to. Likewise,
4021 @var{disallowed-references}, if true, must be a list of things the
4022 outputs may @emph{not} refer to.
4023
4024 When @var{leaked-env-vars} is true, it must be a list of strings
4025 denoting environment variables that are allowed to ``leak'' from the
4026 daemon's environment to the build environment. This is only applicable
4027 to fixed-output derivations---i.e., when @var{hash} is true. The main
4028 use is to allow variables such as @code{http_proxy} to be passed to
4029 derivations that download files.
4030
4031 When @var{local-build?} is true, declare that the derivation is not a
4032 good candidate for offloading and should rather be built locally
4033 (@pxref{Daemon Offload Setup}). This is the case for small derivations
4034 where the costs of data transfers would outweigh the benefits.
4035
4036 When @var{substitutable?} is false, declare that substitutes of the
4037 derivation's output should not be used (@pxref{Substitutes}). This is
4038 useful, for instance, when building packages that capture details of the
4039 host CPU instruction set.
4040 @end deffn
4041
4042 @noindent
4043 Here's an example with a shell script as its builder, assuming
4044 @var{store} is an open connection to the daemon, and @var{bash} points
4045 to a Bash executable in the store:
4046
4047 @lisp
4048 (use-modules (guix utils)
4049 (guix store)
4050 (guix derivations))
4051
4052 (let ((builder ; add the Bash script to the store
4053 (add-text-to-store store "my-builder.sh"
4054 "echo hello world > $out\n" '())))
4055 (derivation store "foo"
4056 bash `("-e" ,builder)
4057 #:inputs `((,bash) (,builder))
4058 #:env-vars '(("HOME" . "/homeless"))))
4059 @result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
4060 @end lisp
4061
4062 As can be guessed, this primitive is cumbersome to use directly. A
4063 better approach is to write build scripts in Scheme, of course! The
4064 best course of action for that is to write the build code as a
4065 ``G-expression'', and to pass it to @code{gexp->derivation}. For more
4066 information, @pxref{G-Expressions}.
4067
4068 Once upon a time, @code{gexp->derivation} did not exist and constructing
4069 derivations with build code written in Scheme was achieved with
4070 @code{build-expression->derivation}, documented below. This procedure
4071 is now deprecated in favor of the much nicer @code{gexp->derivation}.
4072
4073 @deffn {Scheme Procedure} build-expression->derivation @var{store} @
4074 @var{name} @var{exp} @
4075 [#:system (%current-system)] [#:inputs '()] @
4076 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
4077 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4078 [#:references-graphs #f] [#:allowed-references #f] @
4079 [#:disallowed-references #f] @
4080 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
4081 Return a derivation that executes Scheme expression @var{exp} as a
4082 builder for derivation @var{name}. @var{inputs} must be a list of
4083 @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
4084 @code{"out"} is assumed. @var{modules} is a list of names of Guile
4085 modules from the current search path to be copied in the store,
4086 compiled, and made available in the load path during the execution of
4087 @var{exp}---e.g., @code{((guix build utils) (guix build
4088 gnu-build-system))}.
4089
4090 @var{exp} is evaluated in an environment where @code{%outputs} is bound
4091 to a list of output/path pairs, and where @code{%build-inputs} is bound
4092 to a list of string/output-path pairs made from @var{inputs}.
4093 Optionally, @var{env-vars} is a list of string pairs specifying the name
4094 and value of environment variables visible to the builder. The builder
4095 terminates by passing the result of @var{exp} to @code{exit}; thus, when
4096 @var{exp} returns @code{#f}, the build is considered to have failed.
4097
4098 @var{exp} is built using @var{guile-for-build} (a derivation). When
4099 @var{guile-for-build} is omitted or is @code{#f}, the value of the
4100 @code{%guile-for-build} fluid is used instead.
4101
4102 See the @code{derivation} procedure for the meaning of
4103 @var{references-graphs}, @var{allowed-references},
4104 @var{disallowed-references}, @var{local-build?}, and
4105 @var{substitutable?}.
4106 @end deffn
4107
4108 @noindent
4109 Here's an example of a single-output derivation that creates a directory
4110 containing one file:
4111
4112 @lisp
4113 (let ((builder '(let ((out (assoc-ref %outputs "out")))
4114 (mkdir out) ; create /gnu/store/@dots{}-goo
4115 (call-with-output-file (string-append out "/test")
4116 (lambda (p)
4117 (display '(hello guix) p))))))
4118 (build-expression->derivation store "goo" builder))
4119
4120 @result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
4121 @end lisp
4122
4123
4124 @node The Store Monad
4125 @section The Store Monad
4126
4127 @cindex monad
4128
4129 The procedures that operate on the store described in the previous
4130 sections all take an open connection to the build daemon as their first
4131 argument. Although the underlying model is functional, they either have
4132 side effects or depend on the current state of the store.
4133
4134 The former is inconvenient: the connection to the build daemon has to be
4135 carried around in all those functions, making it impossible to compose
4136 functions that do not take that parameter with functions that do. The
4137 latter can be problematic: since store operations have side effects
4138 and/or depend on external state, they have to be properly sequenced.
4139
4140 @cindex monadic values
4141 @cindex monadic functions
4142 This is where the @code{(guix monads)} module comes in. This module
4143 provides a framework for working with @dfn{monads}, and a particularly
4144 useful monad for our uses, the @dfn{store monad}. Monads are a
4145 construct that allows two things: associating ``context'' with values
4146 (in our case, the context is the store), and building sequences of
4147 computations (here computations include accesses to the store). Values
4148 in a monad---values that carry this additional context---are called
4149 @dfn{monadic values}; procedures that return such values are called
4150 @dfn{monadic procedures}.
4151
4152 Consider this ``normal'' procedure:
4153
4154 @example
4155 (define (sh-symlink store)
4156 ;; Return a derivation that symlinks the 'bash' executable.
4157 (let* ((drv (package-derivation store bash))
4158 (out (derivation->output-path drv))
4159 (sh (string-append out "/bin/bash")))
4160 (build-expression->derivation store "sh"
4161 `(symlink ,sh %output))))
4162 @end example
4163
4164 Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
4165 as a monadic function:
4166
4167 @example
4168 (define (sh-symlink)
4169 ;; Same, but return a monadic value.
4170 (mlet %store-monad ((drv (package->derivation bash)))
4171 (gexp->derivation "sh"
4172 #~(symlink (string-append #$drv "/bin/bash")
4173 #$output))))
4174 @end example
4175
4176 There are several things to note in the second version: the @code{store}
4177 parameter is now implicit and is ``threaded'' in the calls to the
4178 @code{package->derivation} and @code{gexp->derivation} monadic
4179 procedures, and the monadic value returned by @code{package->derivation}
4180 is @dfn{bound} using @code{mlet} instead of plain @code{let}.
4181
4182 As it turns out, the call to @code{package->derivation} can even be
4183 omitted since it will take place implicitly, as we will see later
4184 (@pxref{G-Expressions}):
4185
4186 @example
4187 (define (sh-symlink)
4188 (gexp->derivation "sh"
4189 #~(symlink (string-append #$bash "/bin/bash")
4190 #$output)))
4191 @end example
4192
4193 @c See
4194 @c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
4195 @c for the funny quote.
4196 Calling the monadic @code{sh-symlink} has no effect. As someone once
4197 said, ``you exit a monad like you exit a building on fire: by running''.
4198 So, to exit the monad and get the desired effect, one must use
4199 @code{run-with-store}:
4200
4201 @example
4202 (run-with-store (open-connection) (sh-symlink))
4203 @result{} /gnu/store/...-sh-symlink
4204 @end example
4205
4206 Note that the @code{(guix monad-repl)} module extends the Guile REPL with
4207 new ``meta-commands'' to make it easier to deal with monadic procedures:
4208 @code{run-in-store}, and @code{enter-store-monad}. The former is used
4209 to ``run'' a single monadic value through the store:
4210
4211 @example
4212 scheme@@(guile-user)> ,run-in-store (package->derivation hello)
4213 $1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
4214 @end example
4215
4216 The latter enters a recursive REPL, where all the return values are
4217 automatically run through the store:
4218
4219 @example
4220 scheme@@(guile-user)> ,enter-store-monad
4221 store-monad@@(guile-user) [1]> (package->derivation hello)
4222 $2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
4223 store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
4224 $3 = "/gnu/store/@dots{}-foo"
4225 store-monad@@(guile-user) [1]> ,q
4226 scheme@@(guile-user)>
4227 @end example
4228
4229 @noindent
4230 Note that non-monadic values cannot be returned in the
4231 @code{store-monad} REPL.
4232
4233 The main syntactic forms to deal with monads in general are provided by
4234 the @code{(guix monads)} module and are described below.
4235
4236 @deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
4237 Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
4238 in @var{monad}.
4239 @end deffn
4240
4241 @deffn {Scheme Syntax} return @var{val}
4242 Return a monadic value that encapsulates @var{val}.
4243 @end deffn
4244
4245 @deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
4246 @dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
4247 procedures @var{mproc}@dots{}@footnote{This operation is commonly
4248 referred to as ``bind'', but that name denotes an unrelated procedure in
4249 Guile. Thus we use this somewhat cryptic symbol inherited from the
4250 Haskell language.}. There can be one @var{mproc} or several of them, as
4251 in this example:
4252
4253 @example
4254 (run-with-state
4255 (with-monad %state-monad
4256 (>>= (return 1)
4257 (lambda (x) (return (+ 1 x)))
4258 (lambda (x) (return (* 2 x)))))
4259 'some-state)
4260
4261 @result{} 4
4262 @result{} some-state
4263 @end example
4264 @end deffn
4265
4266 @deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
4267 @var{body} ...
4268 @deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
4269 @var{body} ...
4270 Bind the variables @var{var} to the monadic values @var{mval} in
4271 @var{body}, which is a sequence of expressions. As with the bind
4272 operator, this can be thought of as ``unpacking'' the raw, non-monadic
4273 value ``contained'' in @var{mval} and making @var{var} refer to that
4274 raw, non-monadic value within the scope of the @var{body}. The form
4275 (@var{var} -> @var{val}) binds @var{var} to the ``normal'' value
4276 @var{val}, as per @code{let}. The binding operations occur in sequence
4277 from left to right. The last expression of @var{body} must be a monadic
4278 expression, and its result will become the result of the @code{mlet} or
4279 @code{mlet*} when run in the @var{monad}.
4280
4281 @code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
4282 (@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
4283 @end deffn
4284
4285 @deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
4286 Bind @var{mexp} and the following monadic expressions in sequence,
4287 returning the result of the last expression. Every expression in the
4288 sequence must be a monadic expression.
4289
4290 This is akin to @code{mlet}, except that the return values of the
4291 monadic expressions are ignored. In that sense, it is analogous to
4292 @code{begin}, but applied to monadic expressions.
4293 @end deffn
4294
4295 @deffn {Scheme System} mwhen @var{condition} @var{mexp0} @var{mexp*} ...
4296 When @var{condition} is true, evaluate the sequence of monadic
4297 expressions @var{mexp0}..@var{mexp*} as in an @code{mbegin}. When
4298 @var{condition} is false, return @code{*unspecified*} in the current
4299 monad. Every expression in the sequence must be a monadic expression.
4300 @end deffn
4301
4302 @deffn {Scheme System} munless @var{condition} @var{mexp0} @var{mexp*} ...
4303 When @var{condition} is false, evaluate the sequence of monadic
4304 expressions @var{mexp0}..@var{mexp*} as in an @code{mbegin}. When
4305 @var{condition} is true, return @code{*unspecified*} in the current
4306 monad. Every expression in the sequence must be a monadic expression.
4307 @end deffn
4308
4309 @cindex state monad
4310 The @code{(guix monads)} module provides the @dfn{state monad}, which
4311 allows an additional value---the state---to be @emph{threaded} through
4312 monadic procedure calls.
4313
4314 @defvr {Scheme Variable} %state-monad
4315 The state monad. Procedures in the state monad can access and change
4316 the state that is threaded.
4317
4318 Consider the example below. The @code{square} procedure returns a value
4319 in the state monad. It returns the square of its argument, but also
4320 increments the current state value:
4321
4322 @example
4323 (define (square x)
4324 (mlet %state-monad ((count (current-state)))
4325 (mbegin %state-monad
4326 (set-current-state (+ 1 count))
4327 (return (* x x)))))
4328
4329 (run-with-state (sequence %state-monad (map square (iota 3))) 0)
4330 @result{} (0 1 4)
4331 @result{} 3
4332 @end example
4333
4334 When ``run'' through @var{%state-monad}, we obtain that additional state
4335 value, which is the number of @code{square} calls.
4336 @end defvr
4337
4338 @deffn {Monadic Procedure} current-state
4339 Return the current state as a monadic value.
4340 @end deffn
4341
4342 @deffn {Monadic Procedure} set-current-state @var{value}
4343 Set the current state to @var{value} and return the previous state as a
4344 monadic value.
4345 @end deffn
4346
4347 @deffn {Monadic Procedure} state-push @var{value}
4348 Push @var{value} to the current state, which is assumed to be a list,
4349 and return the previous state as a monadic value.
4350 @end deffn
4351
4352 @deffn {Monadic Procedure} state-pop
4353 Pop a value from the current state and return it as a monadic value.
4354 The state is assumed to be a list.
4355 @end deffn
4356
4357 @deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
4358 Run monadic value @var{mval} starting with @var{state} as the initial
4359 state. Return two values: the resulting value, and the resulting state.
4360 @end deffn
4361
4362 The main interface to the store monad, provided by the @code{(guix
4363 store)} module, is as follows.
4364
4365 @defvr {Scheme Variable} %store-monad
4366 The store monad---an alias for @var{%state-monad}.
4367
4368 Values in the store monad encapsulate accesses to the store. When its
4369 effect is needed, a value of the store monad must be ``evaluated'' by
4370 passing it to the @code{run-with-store} procedure (see below.)
4371 @end defvr
4372
4373 @deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
4374 Run @var{mval}, a monadic value in the store monad, in @var{store}, an
4375 open store connection.
4376 @end deffn
4377
4378 @deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
4379 Return as a monadic value the absolute file name in the store of the file
4380 containing @var{text}, a string. @var{references} is a list of store items that the
4381 resulting text file refers to; it defaults to the empty list.
4382 @end deffn
4383
4384 @deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
4385 [#:recursive? #t] [#:select? (const #t)]
4386 Return the name of @var{file} once interned in the store. Use
4387 @var{name} as its store name, or the basename of @var{file} if
4388 @var{name} is omitted.
4389
4390 When @var{recursive?} is true, the contents of @var{file} are added
4391 recursively; if @var{file} designates a flat file and @var{recursive?}
4392 is true, its contents are added, and its permission bits are kept.
4393
4394 When @var{recursive?} is true, call @code{(@var{select?} @var{file}
4395 @var{stat})} for each directory entry, where @var{file} is the entry's
4396 absolute file name and @var{stat} is the result of @code{lstat}; exclude
4397 entries for which @var{select?} does not return true.
4398
4399 The example below adds a file to the store, under two different names:
4400
4401 @example
4402 (run-with-store (open-connection)
4403 (mlet %store-monad ((a (interned-file "README"))
4404 (b (interned-file "README" "LEGU-MIN")))
4405 (return (list a b))))
4406
4407 @result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
4408 @end example
4409
4410 @end deffn
4411
4412 The @code{(guix packages)} module exports the following package-related
4413 monadic procedures:
4414
4415 @deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4416 [#:system (%current-system)] [#:target #f] @
4417 [#:output "out"]
4418 Return as a monadic
4419 value in the absolute file name of @var{file} within the @var{output}
4420 directory of @var{package}. When @var{file} is omitted, return the name
4421 of the @var{output} directory of @var{package}. When @var{target} is
4422 true, use it as a cross-compilation target triplet.
4423 @end deffn
4424
4425 @deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4426 @deffnx {Monadic Procedure} package->cross-derivation @var{package} @
4427 @var{target} [@var{system}]
4428 Monadic version of @code{package-derivation} and
4429 @code{package-cross-derivation} (@pxref{Defining Packages}).
4430 @end deffn
4431
4432
4433 @node G-Expressions
4434 @section G-Expressions
4435
4436 @cindex G-expression
4437 @cindex build code quoting
4438 So we have ``derivations'', which represent a sequence of build actions
4439 to be performed to produce an item in the store (@pxref{Derivations}).
4440 These build actions are performed when asking the daemon to actually
4441 build the derivations; they are run by the daemon in a container
4442 (@pxref{Invoking guix-daemon}).
4443
4444 @cindex strata of code
4445 It should come as no surprise that we like to write these build actions
4446 in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
4447 code@footnote{The term @dfn{stratum} in this context was coined by
4448 Manuel Serrano et al.@: in the context of their work on Hop. Oleg
4449 Kiselyov, who has written insightful
4450 @url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
4451 on this topic}, refers to this kind of code generation as
4452 @dfn{staging}.}: the ``host code''---code that defines packages, talks
4453 to the daemon, etc.---and the ``build code''---code that actually
4454 performs build actions, such as making directories, invoking
4455 @command{make}, etc.
4456
4457 To describe a derivation and its build actions, one typically needs to
4458 embed build code inside host code. It boils down to manipulating build
4459 code as data, and the homoiconicity of Scheme---code has a direct
4460 representation as data---comes in handy for that. But we need more than
4461 the normal @code{quasiquote} mechanism in Scheme to construct build
4462 expressions.
4463
4464 The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
4465 S-expressions adapted to build expressions. G-expressions, or
4466 @dfn{gexps}, consist essentially of three syntactic forms: @code{gexp},
4467 @code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
4468 @code{#$}, and @code{#$@@}), which are comparable to
4469 @code{quasiquote}, @code{unquote}, and @code{unquote-splicing},
4470 respectively (@pxref{Expression Syntax, @code{quasiquote},, guile,
4471 GNU Guile Reference Manual}). However, there are major differences:
4472
4473 @itemize
4474 @item
4475 Gexps are meant to be written to a file and run or manipulated by other
4476 processes.
4477
4478 @item
4479 When a high-level object such as a package or derivation is unquoted
4480 inside a gexp, the result is as if its output file name had been
4481 introduced.
4482
4483 @item
4484 Gexps carry information about the packages or derivations they refer to,
4485 and these dependencies are automatically added as inputs to the build
4486 processes that use them.
4487 @end itemize
4488
4489 @cindex lowering, of high-level objects in gexps
4490 This mechanism is not limited to package and derivation
4491 objects: @dfn{compilers} able to ``lower'' other high-level objects to
4492 derivations or files in the store can be defined,
4493 such that these objects can also be inserted
4494 into gexps. For example, a useful type of high-level objects that can be
4495 inserted in a gexp is ``file-like objects'', which make it easy to
4496 add files to the store and to refer to them in
4497 derivations and such (see @code{local-file} and @code{plain-file}
4498 below.)
4499
4500 To illustrate the idea, here is an example of a gexp:
4501
4502 @example
4503 (define build-exp
4504 #~(begin
4505 (mkdir #$output)
4506 (chdir #$output)
4507 (symlink (string-append #$coreutils "/bin/ls")
4508 "list-files")))
4509 @end example
4510
4511 This gexp can be passed to @code{gexp->derivation}; we obtain a
4512 derivation that builds a directory containing exactly one symlink to
4513 @file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
4514
4515 @example
4516 (gexp->derivation "the-thing" build-exp)
4517 @end example
4518
4519 As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
4520 substituted to the reference to the @var{coreutils} package in the
4521 actual build code, and @var{coreutils} is automatically made an input to
4522 the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
4523 output)}) is replaced by a string containing the directory name of the
4524 output of the derivation.
4525
4526 @cindex cross compilation
4527 In a cross-compilation context, it is useful to distinguish between
4528 references to the @emph{native} build of a package---that can run on the
4529 host---versus references to cross builds of a package. To that end, the
4530 @code{#+} plays the same role as @code{#$}, but is a reference to a
4531 native package build:
4532
4533 @example
4534 (gexp->derivation "vi"
4535 #~(begin
4536 (mkdir #$output)
4537 (system* (string-append #+coreutils "/bin/ln")
4538 "-s"
4539 (string-append #$emacs "/bin/emacs")
4540 (string-append #$output "/bin/vi")))
4541 #:target "mips64el-linux-gnu")
4542 @end example
4543
4544 @noindent
4545 In the example above, the native build of @var{coreutils} is used, so
4546 that @command{ln} can actually run on the host; but then the
4547 cross-compiled build of @var{emacs} is referenced.
4548
4549 @cindex imported modules, for gexps
4550 @findex with-imported-modules
4551 Another gexp feature is @dfn{imported modules}: sometimes you want to be
4552 able to use certain Guile modules from the ``host environment'' in the
4553 gexp, so those modules should be imported in the ``build environment''.
4554 The @code{with-imported-modules} form allows you to express that:
4555
4556 @example
4557 (let ((build (with-imported-modules '((guix build utils))
4558 #~(begin
4559 (use-modules (guix build utils))
4560 (mkdir-p (string-append #$output "/bin"))))))
4561 (gexp->derivation "empty-dir"
4562 #~(begin
4563 #$build
4564 (display "success!\n")
4565 #t)))
4566 @end example
4567
4568 @noindent
4569 In this example, the @code{(guix build utils)} module is automatically
4570 pulled into the isolated build environment of our gexp, such that
4571 @code{(use-modules (guix build utils))} works as expected.
4572
4573 @cindex module closure
4574 @findex source-module-closure
4575 Usually you want the @emph{closure} of the module to be imported---i.e.,
4576 the module itself and all the modules it depends on---rather than just
4577 the module; failing to do that, attempts to use the module will fail
4578 because of missing dependent modules. The @code{source-module-closure}
4579 procedure computes the closure of a module by looking at its source file
4580 headers, which comes in handy in this case:
4581
4582 @example
4583 (use-modules (guix modules)) ;for 'source-module-closure'
4584
4585 (with-imported-modules (source-module-closure
4586 '((guix build utils)
4587 (gnu build vm)))
4588 (gexp->derivation "something-with-vms"
4589 #~(begin
4590 (use-modules (guix build utils)
4591 (gnu build vm))
4592 @dots{})))
4593 @end example
4594
4595 The syntactic form to construct gexps is summarized below.
4596
4597 @deffn {Scheme Syntax} #~@var{exp}
4598 @deffnx {Scheme Syntax} (gexp @var{exp})
4599 Return a G-expression containing @var{exp}. @var{exp} may contain one
4600 or more of the following forms:
4601
4602 @table @code
4603 @item #$@var{obj}
4604 @itemx (ungexp @var{obj})
4605 Introduce a reference to @var{obj}. @var{obj} may have one of the
4606 supported types, for example a package or a
4607 derivation, in which case the @code{ungexp} form is replaced by its
4608 output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
4609
4610 If @var{obj} is a list, it is traversed and references to supported
4611 objects are substituted similarly.
4612
4613 If @var{obj} is another gexp, its contents are inserted and its
4614 dependencies are added to those of the containing gexp.
4615
4616 If @var{obj} is another kind of object, it is inserted as is.
4617
4618 @item #$@var{obj}:@var{output}
4619 @itemx (ungexp @var{obj} @var{output})
4620 This is like the form above, but referring explicitly to the
4621 @var{output} of @var{obj}---this is useful when @var{obj} produces
4622 multiple outputs (@pxref{Packages with Multiple Outputs}).
4623
4624 @item #+@var{obj}
4625 @itemx #+@var{obj}:output
4626 @itemx (ungexp-native @var{obj})
4627 @itemx (ungexp-native @var{obj} @var{output})
4628 Same as @code{ungexp}, but produces a reference to the @emph{native}
4629 build of @var{obj} when used in a cross compilation context.
4630
4631 @item #$output[:@var{output}]
4632 @itemx (ungexp output [@var{output}])
4633 Insert a reference to derivation output @var{output}, or to the main
4634 output when @var{output} is omitted.
4635
4636 This only makes sense for gexps passed to @code{gexp->derivation}.
4637
4638 @item #$@@@var{lst}
4639 @itemx (ungexp-splicing @var{lst})
4640 Like the above, but splices the contents of @var{lst} inside the
4641 containing list.
4642
4643 @item #+@@@var{lst}
4644 @itemx (ungexp-native-splicing @var{lst})
4645 Like the above, but refers to native builds of the objects listed in
4646 @var{lst}.
4647
4648 @end table
4649
4650 G-expressions created by @code{gexp} or @code{#~} are run-time objects
4651 of the @code{gexp?} type (see below.)
4652 @end deffn
4653
4654 @deffn {Scheme Syntax} with-imported-modules @var{modules} @var{body}@dots{}
4655 Mark the gexps defined in @var{body}@dots{} as requiring @var{modules}
4656 in their execution environment.
4657
4658 Each item in @var{modules} can be the name of a module, such as
4659 @code{(guix build utils)}, or it can be a module name, followed by an
4660 arrow, followed by a file-like object:
4661
4662 @example
4663 `((guix build utils)
4664 (guix gcrypt)
4665 ((guix config) => ,(scheme-file "config.scm"
4666 #~(define-module @dots{}))))
4667 @end example
4668
4669 @noindent
4670 In the example above, the first two modules are taken from the search
4671 path, and the last one is created from the given file-like object.
4672
4673 This form has @emph{lexical} scope: it has an effect on the gexps
4674 directly defined in @var{body}@dots{}, but not on those defined, say, in
4675 procedures called from @var{body}@dots{}.
4676 @end deffn
4677
4678 @deffn {Scheme Procedure} gexp? @var{obj}
4679 Return @code{#t} if @var{obj} is a G-expression.
4680 @end deffn
4681
4682 G-expressions are meant to be written to disk, either as code building
4683 some derivation, or as plain files in the store. The monadic procedures
4684 below allow you to do that (@pxref{The Store Monad}, for more
4685 information about monads.)
4686
4687 @deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
4688 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
4689 [#:hash #f] [#:hash-algo #f] @
4690 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4691 [#:module-path @var{%load-path}] @
4692 [#:references-graphs #f] [#:allowed-references #f] @
4693 [#:disallowed-references #f] @
4694 [#:leaked-env-vars #f] @
4695 [#:script-name (string-append @var{name} "-builder")] @
4696 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
4697 Return a derivation @var{name} that runs @var{exp} (a gexp) with
4698 @var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
4699 stored in a file called @var{script-name}. When @var{target} is true,
4700 it is used as the cross-compilation target triplet for packages referred
4701 to by @var{exp}.
4702
4703 @var{modules} is deprecated in favor of @code{with-imported-modules}.
4704 Its meaning is to
4705 make @var{modules} available in the evaluation context of @var{exp};
4706 @var{modules} is a list of names of Guile modules searched in
4707 @var{module-path} to be copied in the store, compiled, and made available in
4708 the load path during the execution of @var{exp}---e.g., @code{((guix
4709 build utils) (guix build gnu-build-system))}.
4710
4711 @var{graft?} determines whether packages referred to by @var{exp} should be grafted when
4712 applicable.
4713
4714 When @var{references-graphs} is true, it must be a list of tuples of one of the
4715 following forms:
4716
4717 @example
4718 (@var{file-name} @var{package})
4719 (@var{file-name} @var{package} @var{output})
4720 (@var{file-name} @var{derivation})
4721 (@var{file-name} @var{derivation} @var{output})
4722 (@var{file-name} @var{store-item})
4723 @end example
4724
4725 The right-hand-side of each element of @var{references-graphs} is automatically made
4726 an input of the build process of @var{exp}. In the build environment, each
4727 @var{file-name} contains the reference graph of the corresponding item, in a simple
4728 text format.
4729
4730 @var{allowed-references} must be either @code{#f} or a list of output names and packages.
4731 In the latter case, the list denotes store items that the result is allowed to
4732 refer to. Any reference to another store item will lead to a build error.
4733 Similarly for @var{disallowed-references}, which can list items that must not be
4734 referenced by the outputs.
4735
4736 The other arguments are as for @code{derivation} (@pxref{Derivations}).
4737 @end deffn
4738
4739 @cindex file-like objects
4740 The @code{local-file}, @code{plain-file}, @code{computed-file},
4741 @code{program-file}, and @code{scheme-file} procedures below return
4742 @dfn{file-like objects}. That is, when unquoted in a G-expression,
4743 these objects lead to a file in the store. Consider this G-expression:
4744
4745 @example
4746 #~(system* #$(file-append glibc "/sbin/nscd") "-f"
4747 #$(local-file "/tmp/my-nscd.conf"))
4748 @end example
4749
4750 The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
4751 to the store. Once expanded, for instance @i{via}
4752 @code{gexp->derivation}, the G-expression refers to that copy under
4753 @file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
4754 does not have any effect on what the G-expression does.
4755 @code{plain-file} can be used similarly; it differs in that the file
4756 content is directly passed as a string.
4757
4758 @deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
4759 [#:recursive? #f] [#:select? (const #t)]
4760 Return an object representing local file @var{file} to add to the store; this
4761 object can be used in a gexp. If @var{file} is a relative file name, it is looked
4762 up relative to the source file where this form appears. @var{file} will be added to
4763 the store under @var{name}--by default the base name of @var{file}.
4764
4765 When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
4766 designates a flat file and @var{recursive?} is true, its contents are added, and its
4767 permission bits are kept.
4768
4769 When @var{recursive?} is true, call @code{(@var{select?} @var{file}
4770 @var{stat})} for each directory entry, where @var{file} is the entry's
4771 absolute file name and @var{stat} is the result of @code{lstat}; exclude
4772 entries for which @var{select?} does not return true.
4773
4774 This is the declarative counterpart of the @code{interned-file} monadic
4775 procedure (@pxref{The Store Monad, @code{interned-file}}).
4776 @end deffn
4777
4778 @deffn {Scheme Procedure} plain-file @var{name} @var{content}
4779 Return an object representing a text file called @var{name} with the given
4780 @var{content} (a string) to be added to the store.
4781
4782 This is the declarative counterpart of @code{text-file}.
4783 @end deffn
4784
4785 @deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
4786 [#:options '(#:local-build? #t)]
4787 Return an object representing the store item @var{name}, a file or
4788 directory computed by @var{gexp}. @var{options}
4789 is a list of additional arguments to pass to @code{gexp->derivation}.
4790
4791 This is the declarative counterpart of @code{gexp->derivation}.
4792 @end deffn
4793
4794 @deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
4795 Return an executable script @var{name} that runs @var{exp} using
4796 @var{guile}, with @var{exp}'s imported modules in its search path.
4797
4798 The example below builds a script that simply invokes the @command{ls}
4799 command:
4800
4801 @example
4802 (use-modules (guix gexp) (gnu packages base))
4803
4804 (gexp->script "list-files"
4805 #~(execl #$(file-append coreutils "/bin/ls")
4806 "ls"))
4807 @end example
4808
4809 When ``running'' it through the store (@pxref{The Store Monad,
4810 @code{run-with-store}}), we obtain a derivation that produces an
4811 executable file @file{/gnu/store/@dots{}-list-files} along these lines:
4812
4813 @example
4814 #!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
4815 !#
4816 (execl "/gnu/store/@dots{}-coreutils-8.22"/bin/ls" "ls")
4817 @end example
4818 @end deffn
4819
4820 @deffn {Scheme Procedure} program-file @var{name} @var{exp} @
4821 [#:guile #f]
4822 Return an object representing the executable store item @var{name} that
4823 runs @var{gexp}. @var{guile} is the Guile package used to execute that
4824 script.
4825
4826 This is the declarative counterpart of @code{gexp->script}.
4827 @end deffn
4828
4829 @deffn {Monadic Procedure} gexp->file @var{name} @var{exp} @
4830 [#:set-load-path? #t]
4831 Return a derivation that builds a file @var{name} containing @var{exp}.
4832 When @var{set-load-path?} is true, emit code in the resulting file to
4833 set @code{%load-path} and @code{%load-compiled-path} to honor
4834 @var{exp}'s imported modules.
4835
4836 The resulting file holds references to all the dependencies of @var{exp}
4837 or a subset thereof.
4838 @end deffn
4839
4840 @deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
4841 Return an object representing the Scheme file @var{name} that contains
4842 @var{exp}.
4843
4844 This is the declarative counterpart of @code{gexp->file}.
4845 @end deffn
4846
4847 @deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
4848 Return as a monadic value a derivation that builds a text file
4849 containing all of @var{text}. @var{text} may list, in addition to
4850 strings, objects of any type that can be used in a gexp: packages,
4851 derivations, local file objects, etc. The resulting store file holds
4852 references to all these.
4853
4854 This variant should be preferred over @code{text-file} anytime the file
4855 to create will reference items from the store. This is typically the
4856 case when building a configuration file that embeds store file names,
4857 like this:
4858
4859 @example
4860 (define (profile.sh)
4861 ;; Return the name of a shell script in the store that
4862 ;; initializes the 'PATH' environment variable.
4863 (text-file* "profile.sh"
4864 "export PATH=" coreutils "/bin:"
4865 grep "/bin:" sed "/bin\n"))
4866 @end example
4867
4868 In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
4869 will reference @var{coreutils}, @var{grep}, and @var{sed}, thereby
4870 preventing them from being garbage-collected during its lifetime.
4871 @end deffn
4872
4873 @deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
4874 Return an object representing store file @var{name} containing
4875 @var{text}. @var{text} is a sequence of strings and file-like objects,
4876 as in:
4877
4878 @example
4879 (mixed-text-file "profile"
4880 "export PATH=" coreutils "/bin:" grep "/bin")
4881 @end example
4882
4883 This is the declarative counterpart of @code{text-file*}.
4884 @end deffn
4885
4886 @deffn {Scheme Procedure} file-append @var{obj} @var{suffix} @dots{}
4887 Return a file-like object that expands to the concatenation of @var{obj}
4888 and @var{suffix}, where @var{obj} is a lowerable object and each
4889 @var{suffix} is a string.
4890
4891 As an example, consider this gexp:
4892
4893 @example
4894 (gexp->script "run-uname"
4895 #~(system* #$(file-append coreutils
4896 "/bin/uname")))
4897 @end example
4898
4899 The same effect could be achieved with:
4900
4901 @example
4902 (gexp->script "run-uname"
4903 #~(system* (string-append #$coreutils
4904 "/bin/uname")))
4905 @end example
4906
4907 There is one difference though: in the @code{file-append} case, the
4908 resulting script contains the absolute file name as a string, whereas in
4909 the second case, the resulting script contains a @code{(string-append
4910 @dots{})} expression to construct the file name @emph{at run time}.
4911 @end deffn
4912
4913
4914 Of course, in addition to gexps embedded in ``host'' code, there are
4915 also modules containing build tools. To make it clear that they are
4916 meant to be used in the build stratum, these modules are kept in the
4917 @code{(guix build @dots{})} name space.
4918
4919 @cindex lowering, of high-level objects in gexps
4920 Internally, high-level objects are @dfn{lowered}, using their compiler,
4921 to either derivations or store items. For instance, lowering a package
4922 yields a derivation, and lowering a @code{plain-file} yields a store
4923 item. This is achieved using the @code{lower-object} monadic procedure.
4924
4925 @deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
4926 [#:target #f]
4927 Return as a value in @var{%store-monad} the derivation or store item
4928 corresponding to @var{obj} for @var{system}, cross-compiling for
4929 @var{target} if @var{target} is true. @var{obj} must be an object that
4930 has an associated gexp compiler, such as a @code{<package>}.
4931 @end deffn
4932
4933
4934 @c *********************************************************************
4935 @node Utilities
4936 @chapter Utilities
4937
4938 This section describes Guix command-line utilities. Some of them are
4939 primarily targeted at developers and users who write new package
4940 definitions, while others are more generally useful. They complement
4941 the Scheme programming interface of Guix in a convenient way.
4942
4943 @menu
4944 * Invoking guix build:: Building packages from the command line.
4945 * Invoking guix edit:: Editing package definitions.
4946 * Invoking guix download:: Downloading a file and printing its hash.
4947 * Invoking guix hash:: Computing the cryptographic hash of a file.
4948 * Invoking guix import:: Importing package definitions.
4949 * Invoking guix refresh:: Updating package definitions.
4950 * Invoking guix lint:: Finding errors in package definitions.
4951 * Invoking guix size:: Profiling disk usage.
4952 * Invoking guix graph:: Visualizing the graph of packages.
4953 * Invoking guix environment:: Setting up development environments.
4954 * Invoking guix publish:: Sharing substitutes.
4955 * Invoking guix challenge:: Challenging substitute servers.
4956 * Invoking guix copy:: Copying to and from a remote store.
4957 * Invoking guix container:: Process isolation.
4958 * Invoking guix weather:: Assessing substitute availability.
4959 @end menu
4960
4961 @node Invoking guix build
4962 @section Invoking @command{guix build}
4963
4964 @cindex package building
4965 @cindex @command{guix build}
4966 The @command{guix build} command builds packages or derivations and
4967 their dependencies, and prints the resulting store paths. Note that it
4968 does not modify the user's profile---this is the job of the
4969 @command{guix package} command (@pxref{Invoking guix package}). Thus,
4970 it is mainly useful for distribution developers.
4971
4972 The general syntax is:
4973
4974 @example
4975 guix build @var{options} @var{package-or-derivation}@dots{}
4976 @end example
4977
4978 As an example, the following command builds the latest versions of Emacs
4979 and of Guile, displays their build logs, and finally displays the
4980 resulting directories:
4981
4982 @example
4983 guix build emacs guile
4984 @end example
4985
4986 Similarly, the following command builds all the available packages:
4987
4988 @example
4989 guix build --quiet --keep-going \
4990 `guix package -A | cut -f1,2 --output-delimiter=@@`
4991 @end example
4992
4993 @var{package-or-derivation} may be either the name of a package found in
4994 the software distribution such as @code{coreutils} or
4995 @code{coreutils@@8.20}, or a derivation such as
4996 @file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
4997 package with the corresponding name (and optionally version) is searched
4998 for among the GNU distribution modules (@pxref{Package Modules}).
4999
5000 Alternatively, the @code{--expression} option may be used to specify a
5001 Scheme expression that evaluates to a package; this is useful when
5002 disambiguating among several same-named packages or package variants is
5003 needed.
5004
5005 There may be zero or more @var{options}. The available options are
5006 described in the subsections below.
5007
5008 @menu
5009 * Common Build Options:: Build options for most commands.
5010 * Package Transformation Options:: Creating variants of packages.
5011 * Additional Build Options:: Options specific to 'guix build'.
5012 * Debugging Build Failures:: Real life packaging experience.
5013 @end menu
5014
5015 @node Common Build Options
5016 @subsection Common Build Options
5017
5018 A number of options that control the build process are common to
5019 @command{guix build} and other commands that can spawn builds, such as
5020 @command{guix package} or @command{guix archive}. These are the
5021 following:
5022
5023 @table @code
5024
5025 @item --load-path=@var{directory}
5026 @itemx -L @var{directory}
5027 Add @var{directory} to the front of the package module search path
5028 (@pxref{Package Modules}).
5029
5030 This allows users to define their own packages and make them visible to
5031 the command-line tools.
5032
5033 @item --keep-failed
5034 @itemx -K
5035 Keep the build tree of failed builds. Thus, if a build fails, its build
5036 tree is kept under @file{/tmp}, in a directory whose name is shown at
5037 the end of the build log. This is useful when debugging build issues.
5038 @xref{Debugging Build Failures}, for tips and tricks on how to debug
5039 build issues.
5040
5041 @item --keep-going
5042 @itemx -k
5043 Keep going when some of the derivations fail to build; return only once
5044 all the builds have either completed or failed.
5045
5046 The default behavior is to stop as soon as one of the specified
5047 derivations has failed.
5048
5049 @item --dry-run
5050 @itemx -n
5051 Do not build the derivations.
5052
5053 @item --fallback
5054 When substituting a pre-built binary fails, fall back to building
5055 packages locally.
5056
5057 @item --substitute-urls=@var{urls}
5058 @anchor{client-substitute-urls}
5059 Consider @var{urls} the whitespace-separated list of substitute source
5060 URLs, overriding the default list of URLs of @command{guix-daemon}
5061 (@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
5062
5063 This means that substitutes may be downloaded from @var{urls}, provided
5064 they are signed by a key authorized by the system administrator
5065 (@pxref{Substitutes}).
5066
5067 When @var{urls} is the empty string, substitutes are effectively
5068 disabled.
5069
5070 @item --no-substitutes
5071 Do not use substitutes for build products. That is, always build things
5072 locally instead of allowing downloads of pre-built binaries
5073 (@pxref{Substitutes}).
5074
5075 @item --no-grafts
5076 Do not ``graft'' packages. In practice, this means that package updates
5077 available as grafts are not applied. @xref{Security Updates}, for more
5078 information on grafts.
5079
5080 @item --rounds=@var{n}
5081 Build each derivation @var{n} times in a row, and raise an error if
5082 consecutive build results are not bit-for-bit identical.
5083
5084 This is a useful way to detect non-deterministic builds processes.
5085 Non-deterministic build processes are a problem because they make it
5086 practically impossible for users to @emph{verify} whether third-party
5087 binaries are genuine. @xref{Invoking guix challenge}, for more.
5088
5089 Note that, currently, the differing build results are not kept around,
5090 so you will have to manually investigate in case of an error---e.g., by
5091 stashing one of the build results with @code{guix archive --export}
5092 (@pxref{Invoking guix archive}), then rebuilding, and finally comparing
5093 the two results.
5094
5095 @item --no-build-hook
5096 Do not attempt to offload builds @i{via} the ``build hook'' of the daemon
5097 (@pxref{Daemon Offload Setup}). That is, always build things locally
5098 instead of offloading builds to remote machines.
5099
5100 @item --max-silent-time=@var{seconds}
5101 When the build or substitution process remains silent for more than
5102 @var{seconds}, terminate it and report a build failure.
5103
5104 By default, the daemon's setting is honored (@pxref{Invoking
5105 guix-daemon, @code{--max-silent-time}}).
5106
5107 @item --timeout=@var{seconds}
5108 Likewise, when the build or substitution process lasts for more than
5109 @var{seconds}, terminate it and report a build failure.
5110
5111 By default, the daemon's setting is honored (@pxref{Invoking
5112 guix-daemon, @code{--timeout}}).
5113
5114 @item --verbosity=@var{level}
5115 Use the given verbosity level. @var{level} must be an integer between 0
5116 and 5; higher means more verbose output. Setting a level of 4 or more
5117 may be helpful when debugging setup issues with the build daemon.
5118
5119 @item --cores=@var{n}
5120 @itemx -c @var{n}
5121 Allow the use of up to @var{n} CPU cores for the build. The special
5122 value @code{0} means to use as many CPU cores as available.
5123
5124 @item --max-jobs=@var{n}
5125 @itemx -M @var{n}
5126 Allow at most @var{n} build jobs in parallel. @xref{Invoking
5127 guix-daemon, @code{--max-jobs}}, for details about this option and the
5128 equivalent @command{guix-daemon} option.
5129
5130 @end table
5131
5132 Behind the scenes, @command{guix build} is essentially an interface to
5133 the @code{package-derivation} procedure of the @code{(guix packages)}
5134 module, and to the @code{build-derivations} procedure of the @code{(guix
5135 derivations)} module.
5136
5137 In addition to options explicitly passed on the command line,
5138 @command{guix build} and other @command{guix} commands that support
5139 building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
5140
5141 @defvr {Environment Variable} GUIX_BUILD_OPTIONS
5142 Users can define this variable to a list of command line options that
5143 will automatically be used by @command{guix build} and other
5144 @command{guix} commands that can perform builds, as in the example
5145 below:
5146
5147 @example
5148 $ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
5149 @end example
5150
5151 These options are parsed independently, and the result is appended to
5152 the parsed command-line options.
5153 @end defvr
5154
5155
5156 @node Package Transformation Options
5157 @subsection Package Transformation Options
5158
5159 @cindex package variants
5160 Another set of command-line options supported by @command{guix build}
5161 and also @command{guix package} are @dfn{package transformation
5162 options}. These are options that make it possible to define @dfn{package
5163 variants}---for instance, packages built from different source code.
5164 This is a convenient way to create customized packages on the fly
5165 without having to type in the definitions of package variants
5166 (@pxref{Defining Packages}).
5167
5168 @table @code
5169
5170 @item --with-source=@var{source}
5171 Use @var{source} as the source of the corresponding package.
5172 @var{source} must be a file name or a URL, as for @command{guix
5173 download} (@pxref{Invoking guix download}).
5174
5175 The ``corresponding package'' is taken to be the one specified on the
5176 command line the name of which matches the base of @var{source}---e.g.,
5177 if @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
5178 package is @code{guile}. Likewise, the version string is inferred from
5179 @var{source}; in the previous example, it is @code{2.0.10}.
5180
5181 This option allows users to try out versions of packages other than the
5182 one provided by the distribution. The example below downloads
5183 @file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
5184 the @code{ed} package:
5185
5186 @example
5187 guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
5188 @end example
5189
5190 As a developer, @code{--with-source} makes it easy to test release
5191 candidates:
5192
5193 @example
5194 guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
5195 @end example
5196
5197 @dots{} or to build from a checkout in a pristine environment:
5198
5199 @example
5200 $ git clone git://git.sv.gnu.org/guix.git
5201 $ guix build guix --with-source=./guix
5202 @end example
5203
5204 @item --with-input=@var{package}=@var{replacement}
5205 Replace dependency on @var{package} by a dependency on
5206 @var{replacement}. @var{package} must be a package name, and
5207 @var{replacement} must be a package specification such as @code{guile}
5208 or @code{guile@@1.8}.
5209
5210 For instance, the following command builds Guix, but replaces its
5211 dependency on the current stable version of Guile with a dependency on
5212 the legacy version of Guile, @code{guile@@2.0}:
5213
5214 @example
5215 guix build --with-input=guile=guile@@2.0 guix
5216 @end example
5217
5218 This is a recursive, deep replacement. So in this example, both
5219 @code{guix} and its dependency @code{guile-json} (which also depends on
5220 @code{guile}) get rebuilt against @code{guile@@2.0}.
5221
5222 This is implemented using the @code{package-input-rewriting} Scheme
5223 procedure (@pxref{Defining Packages, @code{package-input-rewriting}}).
5224
5225 @item --with-graft=@var{package}=@var{replacement}
5226 This is similar to @code{--with-input} but with an important difference:
5227 instead of rebuilding the whole dependency chain, @var{replacement} is
5228 built and then @dfn{grafted} onto the binaries that were initially
5229 referring to @var{package}. @xref{Security Updates}, for more
5230 information on grafts.
5231
5232 For example, the command below grafts version 3.5.4 of GnuTLS onto Wget
5233 and all its dependencies, replacing references to the version of GnuTLS
5234 they currently refer to:
5235
5236 @example
5237 guix build --with-graft=gnutls=gnutls@@3.5.4 wget
5238 @end example
5239
5240 This has the advantage of being much faster than rebuilding everything.
5241 But there is a caveat: it works if and only if @var{package} and
5242 @var{replacement} are strictly compatible---for example, if they provide
5243 a library, the application binary interface (ABI) of those libraries
5244 must be compatible. If @var{replacement} is somehow incompatible with
5245 @var{package}, then the resulting package may be unusable. Use with
5246 care!
5247
5248 @end table
5249
5250 @node Additional Build Options
5251 @subsection Additional Build Options
5252
5253 The command-line options presented below are specific to @command{guix
5254 build}.
5255
5256 @table @code
5257
5258 @item --quiet
5259 @itemx -q
5260 Build quietly, without displaying the build log. Upon completion, the
5261 build log is kept in @file{/var} (or similar) and can always be
5262 retrieved using the @option{--log-file} option.
5263
5264 @item --file=@var{file}
5265 @itemx -f @var{file}
5266
5267 Build the package or derivation that the code within @var{file}
5268 evaluates to.
5269
5270 As an example, @var{file} might contain a package definition like this
5271 (@pxref{Defining Packages}):
5272
5273 @example
5274 @verbatiminclude package-hello.scm
5275 @end example
5276
5277 @item --expression=@var{expr}
5278 @itemx -e @var{expr}
5279 Build the package or derivation @var{expr} evaluates to.
5280
5281 For example, @var{expr} may be @code{(@@ (gnu packages guile)
5282 guile-1.8)}, which unambiguously designates this specific variant of
5283 version 1.8 of Guile.
5284
5285 Alternatively, @var{expr} may be a G-expression, in which case it is used
5286 as a build program passed to @code{gexp->derivation}
5287 (@pxref{G-Expressions}).
5288
5289 Lastly, @var{expr} may refer to a zero-argument monadic procedure
5290 (@pxref{The Store Monad}). The procedure must return a derivation as a
5291 monadic value, which is then passed through @code{run-with-store}.
5292
5293 @item --source
5294 @itemx -S
5295 Build the source derivations of the packages, rather than the packages
5296 themselves.
5297
5298 For instance, @code{guix build -S gcc} returns something like
5299 @file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
5300 source tarball.
5301
5302 The returned source tarball is the result of applying any patches and
5303 code snippets specified in the package @code{origin} (@pxref{Defining
5304 Packages}).
5305
5306 @item --sources
5307 Fetch and return the source of @var{package-or-derivation} and all their
5308 dependencies, recursively. This is a handy way to obtain a local copy
5309 of all the source code needed to build @var{packages}, allowing you to
5310 eventually build them even without network access. It is an extension
5311 of the @code{--source} option and can accept one of the following
5312 optional argument values:
5313
5314 @table @code
5315 @item package
5316 This value causes the @code{--sources} option to behave in the same way
5317 as the @code{--source} option.
5318
5319 @item all
5320 Build the source derivations of all packages, including any source that
5321 might be listed as @code{inputs}. This is the default value.
5322
5323 @example
5324 $ guix build --sources tzdata
5325 The following derivations will be built:
5326 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
5327 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
5328 @end example
5329
5330 @item transitive
5331 Build the source derivations of all packages, as well of all transitive
5332 inputs to the packages. This can be used e.g. to
5333 prefetch package source for later offline building.
5334
5335 @example
5336 $ guix build --sources=transitive tzdata
5337 The following derivations will be built:
5338 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
5339 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
5340 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
5341 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
5342 /gnu/store/@dots{}-make-4.1.tar.xz.drv
5343 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
5344 @dots{}
5345 @end example
5346
5347 @end table
5348
5349 @item --system=@var{system}
5350 @itemx -s @var{system}
5351 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
5352 the system type of the build host.
5353
5354 An example use of this is on Linux-based systems, which can emulate
5355 different personalities. For instance, passing
5356 @code{--system=i686-linux} on an @code{x86_64-linux} system allows users
5357 to build packages in a complete 32-bit environment.
5358
5359 @item --target=@var{triplet}
5360 @cindex cross-compilation
5361 Cross-build for @var{triplet}, which must be a valid GNU triplet, such
5362 as @code{"mips64el-linux-gnu"} (@pxref{Specifying target triplets, GNU
5363 configuration triplets,, autoconf, Autoconf}).
5364
5365 @anchor{build-check}
5366 @item --check
5367 @cindex determinism, checking
5368 @cindex reproducibility, checking
5369 Rebuild @var{package-or-derivation}, which are already available in the
5370 store, and raise an error if the build results are not bit-for-bit
5371 identical.
5372
5373 This mechanism allows you to check whether previously installed
5374 substitutes are genuine (@pxref{Substitutes}), or whether the build result
5375 of a package is deterministic. @xref{Invoking guix challenge}, for more
5376 background information and tools.
5377
5378 When used in conjunction with @option{--keep-failed}, the differing
5379 output is kept in the store, under @file{/gnu/store/@dots{}-check}.
5380 This makes it easy to look for differences between the two results.
5381
5382 @item --repair
5383 @cindex repairing store items
5384 @cindex corruption, recovering from
5385 Attempt to repair the specified store items, if they are corrupt, by
5386 re-downloading or rebuilding them.
5387
5388 This operation is not atomic and thus restricted to @code{root}.
5389
5390 @item --derivations
5391 @itemx -d
5392 Return the derivation paths, not the output paths, of the given
5393 packages.
5394
5395 @item --root=@var{file}
5396 @itemx -r @var{file}
5397 Make @var{file} a symlink to the result, and register it as a garbage
5398 collector root.
5399
5400 @item --log-file
5401 Return the build log file names or URLs for the given
5402 @var{package-or-derivation}, or raise an error if build logs are
5403 missing.
5404
5405 This works regardless of how packages or derivations are specified. For
5406 instance, the following invocations are equivalent:
5407
5408 @example
5409 guix build --log-file `guix build -d guile`
5410 guix build --log-file `guix build guile`
5411 guix build --log-file guile
5412 guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
5413 @end example
5414
5415 If a log is unavailable locally, and unless @code{--no-substitutes} is
5416 passed, the command looks for a corresponding log on one of the
5417 substitute servers (as specified with @code{--substitute-urls}.)
5418
5419 So for instance, imagine you want to see the build log of GDB on MIPS,
5420 but you are actually on an @code{x86_64} machine:
5421
5422 @example
5423 $ guix build --log-file gdb -s mips64el-linux
5424 https://hydra.gnu.org/log/@dots{}-gdb-7.10
5425 @end example
5426
5427 You can freely access a huge library of build logs!
5428 @end table
5429
5430 @node Debugging Build Failures
5431 @subsection Debugging Build Failures
5432
5433 @cindex build failures, debugging
5434 When defining a new package (@pxref{Defining Packages}), you will
5435 probably find yourself spending some time debugging and tweaking the
5436 build until it succeeds. To do that, you need to operate the build
5437 commands yourself in an environment as close as possible to the one the
5438 build daemon uses.
5439
5440 To that end, the first thing to do is to use the @option{--keep-failed}
5441 or @option{-K} option of @command{guix build}, which will keep the
5442 failed build tree in @file{/tmp} or whatever directory you specified as
5443 @code{TMPDIR} (@pxref{Invoking guix build, @code{--keep-failed}}).
5444
5445 From there on, you can @command{cd} to the failed build tree and source
5446 the @file{environment-variables} file, which contains all the
5447 environment variable definitions that were in place when the build
5448 failed. So let's say you're debugging a build failure in package
5449 @code{foo}; a typical session would look like this:
5450
5451 @example
5452 $ guix build foo -K
5453 @dots{} @i{build fails}
5454 $ cd /tmp/guix-build-foo.drv-0
5455 $ source ./environment-variables
5456 $ cd foo-1.2
5457 @end example
5458
5459 Now, you can invoke commands as if you were the daemon (almost) and
5460 troubleshoot your build process.
5461
5462 Sometimes it happens that, for example, a package's tests pass when you
5463 run them manually but they fail when the daemon runs them. This can
5464 happen because the daemon runs builds in containers where, unlike in our
5465 environment above, network access is missing, @file{/bin/sh} does not
5466 exist, etc. (@pxref{Build Environment Setup}).
5467
5468 In such cases, you may need to run inspect the build process from within
5469 a container similar to the one the build daemon creates:
5470
5471 @example
5472 $ guix build -K foo
5473 @dots{}
5474 $ cd /tmp/guix-build-foo.drv-0
5475 $ guix environment --no-grafts -C foo --ad-hoc strace gdb
5476 [env]# source ./environment-variables
5477 [env]# cd foo-1.2
5478 @end example
5479
5480 Here, @command{guix environment -C} creates a container and spawns a new
5481 shell in it (@pxref{Invoking guix environment}). The @command{--ad-hoc
5482 strace gdb} part adds the @command{strace} and @command{gdb} commands to
5483 the container, which would may find handy while debugging. The
5484 @option{--no-grafts} option makes sure we get the exact same
5485 environment, with ungrafted packages (@pxref{Security Updates}, for more
5486 info on grafts).
5487
5488 To get closer to a container like that used by the build daemon, we can
5489 remove @file{/bin/sh}:
5490
5491 @example
5492 [env]# rm /bin/sh
5493 @end example
5494
5495 (Don't worry, this is harmless: this is all happening in the throw-away
5496 container created by @command{guix environment}.)
5497
5498 The @command{strace} command is probably not in the search path, but we
5499 can run:
5500
5501 @example
5502 [env]# $GUIX_ENVIRONMENT/bin/strace -f -o log make check
5503 @end example
5504
5505 In this way, not only you will have reproduced the environment variables
5506 the daemon uses, you will also be running the build process in a container
5507 similar to the one the daemon uses.
5508
5509
5510 @node Invoking guix edit
5511 @section Invoking @command{guix edit}
5512
5513 @cindex @command{guix edit}
5514 @cindex package definition, editing
5515 So many packages, so many source files! The @command{guix edit} command
5516 facilitates the life of users and packagers by pointing their editor at
5517 the source file containing the definition of the specified packages.
5518 For instance:
5519
5520 @example
5521 guix edit gcc@@4.9 vim
5522 @end example
5523
5524 @noindent
5525 launches the program specified in the @code{VISUAL} or in the
5526 @code{EDITOR} environment variable to view the recipe of GCC@tie{}4.9.3
5527 and that of Vim.
5528
5529 If you are using a Guix Git checkout (@pxref{Building from Git}), or
5530 have created your own packages on @code{GUIX_PACKAGE_PATH}
5531 (@pxref{Defining Packages}), you will be able to edit the package
5532 recipes. Otherwise, you will be able to examine the read-only recipes
5533 for packages currently in the store.
5534
5535
5536 @node Invoking guix download
5537 @section Invoking @command{guix download}
5538
5539 @cindex @command{guix download}
5540 @cindex downloading package sources
5541 When writing a package definition, developers typically need to download
5542 a source tarball, compute its SHA256 hash, and write that
5543 hash in the package definition (@pxref{Defining Packages}). The
5544 @command{guix download} tool helps with this task: it downloads a file
5545 from the given URI, adds it to the store, and prints both its file name
5546 in the store and its SHA256 hash.
5547
5548 The fact that the downloaded file is added to the store saves bandwidth:
5549 when the developer eventually tries to build the newly defined package
5550 with @command{guix build}, the source tarball will not have to be
5551 downloaded again because it is already in the store. It is also a
5552 convenient way to temporarily stash files, which may be deleted
5553 eventually (@pxref{Invoking guix gc}).
5554
5555 The @command{guix download} command supports the same URIs as used in
5556 package definitions. In particular, it supports @code{mirror://} URIs.
5557 @code{https} URIs (HTTP over TLS) are supported @emph{provided} the
5558 Guile bindings for GnuTLS are available in the user's environment; when
5559 they are not available, an error is raised. @xref{Guile Preparations,
5560 how to install the GnuTLS bindings for Guile,, gnutls-guile,
5561 GnuTLS-Guile}, for more information.
5562
5563 @command{guix download} verifies HTTPS server certificates by loading
5564 the certificates of X.509 authorities from the directory pointed to by
5565 the @code{SSL_CERT_DIR} environment variable (@pxref{X.509
5566 Certificates}), unless @option{--no-check-certificate} is used.
5567
5568 The following options are available:
5569
5570 @table @code
5571 @item --format=@var{fmt}
5572 @itemx -f @var{fmt}
5573 Write the hash in the format specified by @var{fmt}. For more
5574 information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
5575
5576 @item --no-check-certificate
5577 Do not validate the X.509 certificates of HTTPS servers.
5578
5579 When using this option, you have @emph{absolutely no guarantee} that you
5580 are communicating with the authentic server responsible for the given
5581 URL, which makes you vulnerable to ``man-in-the-middle'' attacks.
5582
5583 @item --output=@var{file}
5584 @itemx -o @var{file}
5585 Save the downloaded file to @var{file} instead of adding it to the
5586 store.
5587 @end table
5588
5589 @node Invoking guix hash
5590 @section Invoking @command{guix hash}
5591
5592 @cindex @command{guix hash}
5593 The @command{guix hash} command computes the SHA256 hash of a file.
5594 It is primarily a convenience tool for anyone contributing to the
5595 distribution: it computes the cryptographic hash of a file, which can be
5596 used in the definition of a package (@pxref{Defining Packages}).
5597
5598 The general syntax is:
5599
5600 @example
5601 guix hash @var{option} @var{file}
5602 @end example
5603
5604 When @var{file} is @code{-} (a hyphen), @command{guix hash} computes the
5605 hash of data read from standard input. @command{guix hash} has the
5606 following options:
5607
5608 @table @code
5609
5610 @item --format=@var{fmt}
5611 @itemx -f @var{fmt}
5612 Write the hash in the format specified by @var{fmt}.
5613
5614 Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
5615 (@code{hex} and @code{hexadecimal} can be used as well).
5616
5617 If the @option{--format} option is not specified, @command{guix hash}
5618 will output the hash in @code{nix-base32}. This representation is used
5619 in the definitions of packages.
5620
5621 @item --recursive
5622 @itemx -r
5623 Compute the hash on @var{file} recursively.
5624
5625 In this case, the hash is computed on an archive containing @var{file},
5626 including its children if it is a directory. Some of the metadata of
5627 @var{file} is part of the archive; for instance, when @var{file} is a
5628 regular file, the hash is different depending on whether @var{file} is
5629 executable or not. Metadata such as time stamps has no impact on the
5630 hash (@pxref{Invoking guix archive}).
5631 @c FIXME: Replace xref above with xref to an ``Archive'' section when
5632 @c it exists.
5633
5634 @item --exclude-vcs
5635 @itemx -x
5636 When combined with @option{--recursive}, exclude version control system
5637 directories (@file{.bzr}, @file{.git}, @file{.hg}, etc.)
5638
5639 @vindex git-fetch
5640 As an example, here is how you would compute the hash of a Git checkout,
5641 which is useful when using the @code{git-fetch} method (@pxref{origin
5642 Reference}):
5643
5644 @example
5645 $ git clone http://example.org/foo.git
5646 $ cd foo
5647 $ guix hash -rx .
5648 @end example
5649 @end table
5650
5651 @node Invoking guix import
5652 @section Invoking @command{guix import}
5653
5654 @cindex importing packages
5655 @cindex package import
5656 @cindex package conversion
5657 @cindex Invoking @command{guix import}
5658 The @command{guix import} command is useful for people who would like to
5659 add a package to the distribution with as little work as
5660 possible---a legitimate demand. The command knows of a few
5661 repositories from which it can ``import'' package metadata. The result
5662 is a package definition, or a template thereof, in the format we know
5663 (@pxref{Defining Packages}).
5664
5665 The general syntax is:
5666
5667 @example
5668 guix import @var{importer} @var{options}@dots{}
5669 @end example
5670
5671 @var{importer} specifies the source from which to import package
5672 metadata, and @var{options} specifies a package identifier and other
5673 options specific to @var{importer}. Currently, the available
5674 ``importers'' are:
5675
5676 @table @code
5677 @item gnu
5678 Import metadata for the given GNU package. This provides a template
5679 for the latest version of that GNU package, including the hash of its
5680 source tarball, and its canonical synopsis and description.
5681
5682 Additional information such as the package dependencies and its
5683 license needs to be figured out manually.
5684
5685 For example, the following command returns a package definition for
5686 GNU@tie{}Hello:
5687
5688 @example
5689 guix import gnu hello
5690 @end example
5691
5692 Specific command-line options are:
5693
5694 @table @code
5695 @item --key-download=@var{policy}
5696 As for @code{guix refresh}, specify the policy to handle missing OpenPGP
5697 keys when verifying the package signature. @xref{Invoking guix
5698 refresh, @code{--key-download}}.
5699 @end table
5700
5701 @item pypi
5702 @cindex pypi
5703 Import metadata from the @uref{https://pypi.python.org/, Python Package
5704 Index}@footnote{This functionality requires Guile-JSON to be installed.
5705 @xref{Requirements}.}. Information is taken from the JSON-formatted
5706 description available at @code{pypi.python.org} and usually includes all
5707 the relevant information, including package dependencies. For maximum
5708 efficiency, it is recommended to install the @command{unzip} utility, so
5709 that the importer can unzip Python wheels and gather data from them.
5710
5711 The command below imports metadata for the @code{itsdangerous} Python
5712 package:
5713
5714 @example
5715 guix import pypi itsdangerous
5716 @end example
5717
5718 @item gem
5719 @cindex gem
5720 Import metadata from @uref{https://rubygems.org/,
5721 RubyGems}@footnote{This functionality requires Guile-JSON to be
5722 installed. @xref{Requirements}.}. Information is taken from the
5723 JSON-formatted description available at @code{rubygems.org} and includes
5724 most relevant information, including runtime dependencies. There are
5725 some caveats, however. The metadata doesn't distinguish between
5726 synopses and descriptions, so the same string is used for both fields.
5727 Additionally, the details of non-Ruby dependencies required to build
5728 native extensions is unavailable and left as an exercise to the
5729 packager.
5730
5731 The command below imports metadata for the @code{rails} Ruby package:
5732
5733 @example
5734 guix import gem rails
5735 @end example
5736
5737 @item cpan
5738 @cindex CPAN
5739 Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}@footnote{This
5740 functionality requires Guile-JSON to be installed.
5741 @xref{Requirements}.}.
5742 Information is taken from the JSON-formatted metadata provided through
5743 @uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
5744 relevant information, such as module dependencies. License information
5745 should be checked closely. If Perl is available in the store, then the
5746 @code{corelist} utility will be used to filter core modules out of the
5747 list of dependencies.
5748
5749 The command command below imports metadata for the @code{Acme::Boolean}
5750 Perl module:
5751
5752 @example
5753 guix import cpan Acme::Boolean
5754 @end example
5755
5756 @item cran
5757 @cindex CRAN
5758 @cindex Bioconductor
5759 Import metadata from @uref{http://cran.r-project.org/, CRAN}, the
5760 central repository for the @uref{http://r-project.org, GNU@tie{}R
5761 statistical and graphical environment}.
5762
5763 Information is extracted from the @code{DESCRIPTION} file of the package.
5764
5765 The command command below imports metadata for the @code{Cairo}
5766 R package:
5767
5768 @example
5769 guix import cran Cairo
5770 @end example
5771
5772 When @code{--recursive} is added, the importer will traverse the
5773 dependency graph of the given upstream package recursively and generate
5774 package expressions for all those packages that are not yet in Guix.
5775
5776 When @code{--archive=bioconductor} is added, metadata is imported from
5777 @uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
5778 packages for for the analysis and comprehension of high-throughput
5779 genomic data in bioinformatics.
5780
5781 Information is extracted from the @code{DESCRIPTION} file of a package
5782 published on the web interface of the Bioconductor SVN repository.
5783
5784 The command below imports metadata for the @code{GenomicRanges}
5785 R package:
5786
5787 @example
5788 guix import cran --archive=bioconductor GenomicRanges
5789 @end example
5790
5791 @item texlive
5792 @cindex TeX Live
5793 @cindex CTAN
5794 Import metadata from @uref{http://www.ctan.org/, CTAN}, the
5795 comprehensive TeX archive network for TeX packages that are part of the
5796 @uref{https://www.tug.org/texlive/, TeX Live distribution}.
5797
5798 Information about the package is obtained through the XML API provided
5799 by CTAN, while the source code is downloaded from the SVN repository of
5800 the Tex Live project. This is done because the CTAN does not keep
5801 versioned archives.
5802
5803 The command command below imports metadata for the @code{fontspec}
5804 TeX package:
5805
5806 @example
5807 guix import texlive fontspec
5808 @end example
5809
5810 When @code{--archive=DIRECTORY} is added, the source code is downloaded
5811 not from the @file{latex} sub-directory of the @file{texmf-dist/source}
5812 tree in the TeX Live SVN repository, but from the specified sibling
5813 directory under the same root.
5814
5815 The command below imports metadata for the @code{ifxetex} package from
5816 CTAN while fetching the sources from the directory
5817 @file{texmf/source/generic}:
5818
5819 @example
5820 guix import texlive --archive=generic ifxetex
5821 @end example
5822
5823 @item nix
5824 Import metadata from a local copy of the source of the
5825 @uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
5826 relies on the @command{nix-instantiate} command of
5827 @uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
5828 typically written in a mixture of Nix-language and Bash code. This
5829 command only imports the high-level package structure that is written in
5830 the Nix language. It normally includes all the basic fields of a
5831 package definition.
5832
5833 When importing a GNU package, the synopsis and descriptions are replaced
5834 by their canonical upstream variant.
5835
5836 Usually, you will first need to do:
5837
5838 @example
5839 export NIX_REMOTE=daemon
5840 @end example
5841
5842 @noindent
5843 so that @command{nix-instantiate} does not try to open the Nix database.
5844
5845 As an example, the command below imports the package definition of
5846 LibreOffice (more precisely, it imports the definition of the package
5847 bound to the @code{libreoffice} top-level attribute):
5848
5849 @example
5850 guix import nix ~/path/to/nixpkgs libreoffice
5851 @end example
5852
5853 @item hackage
5854 @cindex hackage
5855 Import metadata from the Haskell community's central package archive
5856 @uref{https://hackage.haskell.org/, Hackage}. Information is taken from
5857 Cabal files and includes all the relevant information, including package
5858 dependencies.
5859
5860 Specific command-line options are:
5861
5862 @table @code
5863 @item --stdin
5864 @itemx -s
5865 Read a Cabal file from standard input.
5866 @item --no-test-dependencies
5867 @itemx -t
5868 Do not include dependencies required only by the test suites.
5869 @item --cabal-environment=@var{alist}
5870 @itemx -e @var{alist}
5871 @var{alist} is a Scheme alist defining the environment in which the
5872 Cabal conditionals are evaluated. The accepted keys are: @code{os},
5873 @code{arch}, @code{impl} and a string representing the name of a flag.
5874 The value associated with a flag has to be either the symbol
5875 @code{true} or @code{false}. The value associated with other keys
5876 has to conform to the Cabal file format definition. The default value
5877 associated with the keys @code{os}, @code{arch} and @code{impl} is
5878 @samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
5879 @end table
5880
5881 The command below imports metadata for the latest version of the
5882 @code{HTTP} Haskell package without including test dependencies and
5883 specifying the value of the flag @samp{network-uri} as @code{false}:
5884
5885 @example
5886 guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
5887 @end example
5888
5889 A specific package version may optionally be specified by following the
5890 package name by an at-sign and a version number as in the following example:
5891
5892 @example
5893 guix import hackage mtl@@2.1.3.1
5894 @end example
5895
5896 @item stackage
5897 @cindex stackage
5898 The @code{stackage} importer is a wrapper around the @code{hackage} one.
5899 It takes a package name, looks up the package version included in a
5900 long-term support (LTS) @uref{https://www.stackage.org, Stackage}
5901 release and uses the @code{hackage} importer to retrieve its metadata.
5902 Note that it is up to you to select an LTS release compatible with the
5903 GHC compiler used by Guix.
5904
5905 Specific command-line options are:
5906
5907 @table @code
5908 @item --no-test-dependencies
5909 @itemx -t
5910 Do not include dependencies required only by the test suites.
5911 @item --lts-version=@var{version}
5912 @itemx -r @var{version}
5913 @var{version} is the desired LTS release version. If omitted the latest
5914 release is used.
5915 @end table
5916
5917 The command below imports metadata for the @code{HTTP} Haskell package
5918 included in the LTS Stackage release version 7.18:
5919
5920 @example
5921 guix import stackage --lts-version=7.18 HTTP
5922 @end example
5923
5924 @item elpa
5925 @cindex elpa
5926 Import metadata from an Emacs Lisp Package Archive (ELPA) package
5927 repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
5928
5929 Specific command-line options are:
5930
5931 @table @code
5932 @item --archive=@var{repo}
5933 @itemx -a @var{repo}
5934 @var{repo} identifies the archive repository from which to retrieve the
5935 information. Currently the supported repositories and their identifiers
5936 are:
5937 @itemize -
5938 @item
5939 @uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
5940 identifier. This is the default.
5941
5942 Packages from @code{elpa.gnu.org} are signed with one of the keys
5943 contained in the GnuPG keyring at
5944 @file{share/emacs/25.1/etc/package-keyring.gpg} (or similar) in the
5945 @code{emacs} package (@pxref{Package Installation, ELPA package
5946 signatures,, emacs, The GNU Emacs Manual}).
5947
5948 @item
5949 @uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
5950 @code{melpa-stable} identifier.
5951
5952 @item
5953 @uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
5954 identifier.
5955 @end itemize
5956 @end table
5957
5958 @item crate
5959 @cindex crate
5960 Import metadata from the crates.io Rust package repository
5961 @uref{https://crates.io, crates.io}.
5962 @end table
5963
5964 The structure of the @command{guix import} code is modular. It would be
5965 useful to have more importers for other package formats, and your help
5966 is welcome here (@pxref{Contributing}).
5967
5968 @node Invoking guix refresh
5969 @section Invoking @command{guix refresh}
5970
5971 @cindex @command {guix refresh}
5972 The primary audience of the @command{guix refresh} command is developers
5973 of the GNU software distribution. By default, it reports any packages
5974 provided by the distribution that are outdated compared to the latest
5975 upstream version, like this:
5976
5977 @example
5978 $ guix refresh
5979 gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
5980 gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
5981 @end example
5982
5983 Alternately, one can specify packages to consider, in which case a
5984 warning is emitted for packages that lack an updater:
5985
5986 @example
5987 $ guix refresh coreutils guile guile-ssh
5988 gnu/packages/ssh.scm:205:2: warning: no updater for guile-ssh
5989 gnu/packages/guile.scm:136:12: guile would be upgraded from 2.0.12 to 2.0.13
5990 @end example
5991
5992 @command{guix refresh} browses the upstream repository of each package and determines
5993 the highest version number of the releases therein. The command
5994 knows how to update specific types of packages: GNU packages, ELPA
5995 packages, etc.---see the documentation for @option{--type} below. There
5996 are many packages, though, for which it lacks a method to determine
5997 whether a new upstream release is available. However, the mechanism is
5998 extensible, so feel free to get in touch with us to add a new method!
5999
6000 When passed @code{--update}, it modifies distribution source files to
6001 update the version numbers and source tarball hashes of those package
6002 recipes (@pxref{Defining Packages}). This is achieved by downloading
6003 each package's latest source tarball and its associated OpenPGP
6004 signature, authenticating the downloaded tarball against its signature
6005 using @command{gpg}, and finally computing its hash. When the public
6006 key used to sign the tarball is missing from the user's keyring, an
6007 attempt is made to automatically retrieve it from a public key server;
6008 when this is successful, the key is added to the user's keyring; otherwise,
6009 @command{guix refresh} reports an error.
6010
6011 The following options are supported:
6012
6013 @table @code
6014
6015 @item --expression=@var{expr}
6016 @itemx -e @var{expr}
6017 Consider the package @var{expr} evaluates to.
6018
6019 This is useful to precisely refer to a package, as in this example:
6020
6021 @example
6022 guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
6023 @end example
6024
6025 This command lists the dependents of the ``final'' libc (essentially all
6026 the packages.)
6027
6028 @item --update
6029 @itemx -u
6030 Update distribution source files (package recipes) in place. This is
6031 usually run from a checkout of the Guix source tree (@pxref{Running
6032 Guix Before It Is Installed}):
6033
6034 @example
6035 $ ./pre-inst-env guix refresh -s non-core -u
6036 @end example
6037
6038 @xref{Defining Packages}, for more information on package definitions.
6039
6040 @item --select=[@var{subset}]
6041 @itemx -s @var{subset}
6042 Select all the packages in @var{subset}, one of @code{core} or
6043 @code{non-core}.
6044
6045 The @code{core} subset refers to all the packages at the core of the
6046 distribution---i.e., packages that are used to build ``everything
6047 else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
6048 changing one of these packages in the distribution entails a rebuild of
6049 all the others. Thus, such updates are an inconvenience to users in
6050 terms of build time or bandwidth used to achieve the upgrade.
6051
6052 The @code{non-core} subset refers to the remaining packages. It is
6053 typically useful in cases where an update of the core packages would be
6054 inconvenient.
6055
6056 @item --manifest=@var{file}
6057 @itemx -m @var{file}
6058 Select all the packages from the manifest in @var{file}. This is useful to
6059 check if any packages of the user manifest can be updated.
6060
6061 @item --type=@var{updater}
6062 @itemx -t @var{updater}
6063 Select only packages handled by @var{updater} (may be a comma-separated
6064 list of updaters). Currently, @var{updater} may be one of:
6065
6066 @table @code
6067 @item gnu
6068 the updater for GNU packages;
6069 @item gnome
6070 the updater for GNOME packages;
6071 @item kde
6072 the updater for KDE packages;
6073 @item xorg
6074 the updater for X.org packages;
6075 @item kernel.org
6076 the updater for packages hosted on kernel.org;
6077 @item elpa
6078 the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
6079 @item cran
6080 the updater for @uref{http://cran.r-project.org/, CRAN} packages;
6081 @item bioconductor
6082 the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
6083 @item cpan
6084 the updater for @uref{http://www.cpan.org/, CPAN} packages;
6085 @item pypi
6086 the updater for @uref{https://pypi.python.org, PyPI} packages.
6087 @item gem
6088 the updater for @uref{https://rubygems.org, RubyGems} packages.
6089 @item github
6090 the updater for @uref{https://github.com, GitHub} packages.
6091 @item hackage
6092 the updater for @uref{https://hackage.haskell.org, Hackage} packages.
6093 @item stackage
6094 the updater for @uref{https://www.stackage.org, Stackage} packages.
6095 @item crate
6096 the updater for @uref{https://crates.io, Crates} packages.
6097 @end table
6098
6099 For instance, the following command only checks for updates of Emacs
6100 packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
6101
6102 @example
6103 $ guix refresh --type=elpa,cran
6104 gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
6105 gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
6106 @end example
6107
6108 @end table
6109
6110 In addition, @command{guix refresh} can be passed one or more package
6111 names, as in this example:
6112
6113 @example
6114 $ ./pre-inst-env guix refresh -u emacs idutils gcc@@4.8
6115 @end example
6116
6117 @noindent
6118 The command above specifically updates the @code{emacs} and
6119 @code{idutils} packages. The @code{--select} option would have no
6120 effect in this case.
6121
6122 When considering whether to upgrade a package, it is sometimes
6123 convenient to know which packages would be affected by the upgrade and
6124 should be checked for compatibility. For this the following option may
6125 be used when passing @command{guix refresh} one or more package names:
6126
6127 @table @code
6128
6129 @item --list-updaters
6130 @itemx -L
6131 List available updaters and exit (see @option{--type} above.)
6132
6133 For each updater, display the fraction of packages it covers; at the
6134 end, display the fraction of packages covered by all these updaters.
6135
6136 @item --list-dependent
6137 @itemx -l
6138 List top-level dependent packages that would need to be rebuilt as a
6139 result of upgrading one or more packages.
6140
6141 @xref{Invoking guix graph, the @code{reverse-package} type of
6142 @command{guix graph}}, for information on how to visualize the list of
6143 dependents of a package.
6144
6145 @end table
6146
6147 Be aware that the @code{--list-dependent} option only
6148 @emph{approximates} the rebuilds that would be required as a result of
6149 an upgrade. More rebuilds might be required under some circumstances.
6150
6151 @example
6152 $ guix refresh --list-dependent flex
6153 Building the following 120 packages would ensure 213 dependent packages are rebuilt:
6154 hop@@2.4.0 geiser@@0.4 notmuch@@0.18 mu@@0.9.9.5 cflow@@1.4 idutils@@4.6 @dots{}
6155 @end example
6156
6157 The command above lists a set of packages that could be built to check
6158 for compatibility with an upgraded @code{flex} package.
6159
6160 The following options can be used to customize GnuPG operation:
6161
6162 @table @code
6163
6164 @item --gpg=@var{command}
6165 Use @var{command} as the GnuPG 2.x command. @var{command} is searched
6166 for in @code{$PATH}.
6167
6168 @item --key-download=@var{policy}
6169 Handle missing OpenPGP keys according to @var{policy}, which may be one
6170 of:
6171
6172 @table @code
6173 @item always
6174 Always download missing OpenPGP keys from the key server, and add them
6175 to the user's GnuPG keyring.
6176
6177 @item never
6178 Never try to download missing OpenPGP keys. Instead just bail out.
6179
6180 @item interactive
6181 When a package signed with an unknown OpenPGP key is encountered, ask
6182 the user whether to download it or not. This is the default behavior.
6183 @end table
6184
6185 @item --key-server=@var{host}
6186 Use @var{host} as the OpenPGP key server when importing a public key.
6187
6188 @end table
6189
6190 The @code{github} updater uses the
6191 @uref{https://developer.github.com/v3/, GitHub API} to query for new
6192 releases. When used repeatedly e.g. when refreshing all packages,
6193 GitHub will eventually refuse to answer any further API requests. By
6194 default 60 API requests per hour are allowed, and a full refresh on all
6195 GitHub packages in Guix requires more than this. Authentication with
6196 GitHub through the use of an API token alleviates these limits. To use
6197 an API token, set the environment variable @code{GUIX_GITHUB_TOKEN} to a
6198 token procured from @uref{https://github.com/settings/tokens} or
6199 otherwise.
6200
6201
6202 @node Invoking guix lint
6203 @section Invoking @command{guix lint}
6204
6205 @cindex @command{guix lint}
6206 @cindex package, checking for errors
6207 The @command{guix lint} command is meant to help package developers avoid
6208 common errors and use a consistent style. It runs a number of checks on
6209 a given set of packages in order to find common mistakes in their
6210 definitions. Available @dfn{checkers} include (see
6211 @code{--list-checkers} for a complete list):
6212
6213 @table @code
6214 @item synopsis
6215 @itemx description
6216 Validate certain typographical and stylistic rules about package
6217 descriptions and synopses.
6218
6219 @item inputs-should-be-native
6220 Identify inputs that should most likely be native inputs.
6221
6222 @item source
6223 @itemx home-page
6224 @itemx mirror-url
6225 @itemx source-file-name
6226 Probe @code{home-page} and @code{source} URLs and report those that are
6227 invalid. Suggest a @code{mirror://} URL when applicable. Check that
6228 the source file name is meaningful, e.g. is not
6229 just a version number or ``git-checkout'', without a declared
6230 @code{file-name} (@pxref{origin Reference}).
6231
6232 @item cve
6233 @cindex security vulnerabilities
6234 @cindex CVE, Common Vulnerabilities and Exposures
6235 Report known vulnerabilities found in the Common Vulnerabilities and
6236 Exposures (CVE) databases of the current and past year
6237 @uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
6238 NIST}.
6239
6240 To view information about a particular vulnerability, visit pages such as:
6241
6242 @itemize
6243 @item
6244 @indicateurl{https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-YYYY-ABCD}
6245 @item
6246 @indicateurl{https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-YYYY-ABCD}
6247 @end itemize
6248
6249 @noindent
6250 where @code{CVE-YYYY-ABCD} is the CVE identifier---e.g.,
6251 @code{CVE-2015-7554}.
6252
6253 Package developers can specify in package recipes the
6254 @uref{https://nvd.nist.gov/cpe.cfm,Common Platform Enumeration (CPE)}
6255 name and version of the package when they differ from the name that Guix
6256 uses, as in this example:
6257
6258 @example
6259 (package
6260 (name "grub")
6261 ;; @dots{}
6262 ;; CPE calls this package "grub2".
6263 (properties '((cpe-name . "grub2"))))
6264 @end example
6265
6266 @item formatting
6267 Warn about obvious source code formatting issues: trailing white space,
6268 use of tabulations, etc.
6269 @end table
6270
6271 The general syntax is:
6272
6273 @example
6274 guix lint @var{options} @var{package}@dots{}
6275 @end example
6276
6277 If no package is given on the command line, then all packages are checked.
6278 The @var{options} may be zero or more of the following:
6279
6280 @table @code
6281 @item --list-checkers
6282 @itemx -l
6283 List and describe all the available checkers that will be run on packages
6284 and exit.
6285
6286 @item --checkers
6287 @itemx -c
6288 Only enable the checkers specified in a comma-separated list using the
6289 names returned by @code{--list-checkers}.
6290
6291 @end table
6292
6293 @node Invoking guix size
6294 @section Invoking @command{guix size}
6295
6296 @cindex size
6297 @cindex package size
6298 @cindex closure
6299 @cindex @command{guix size}
6300 The @command{guix size} command helps package developers profile the
6301 disk usage of packages. It is easy to overlook the impact of an
6302 additional dependency added to a package, or the impact of using a
6303 single output for a package that could easily be split (@pxref{Packages
6304 with Multiple Outputs}). Such are the typical issues that
6305 @command{guix size} can highlight.
6306
6307 The command can be passed a package specification such as @code{gcc@@4.8}
6308 or @code{guile:debug}, or a file name in the store. Consider this
6309 example:
6310
6311 @example
6312 $ guix size coreutils
6313 store item total self
6314 /gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
6315 /gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
6316 /gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
6317 /gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
6318 /gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
6319 /gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
6320 @end example
6321
6322 @cindex closure
6323 The store items listed here constitute the @dfn{transitive closure} of
6324 Coreutils---i.e., Coreutils and all its dependencies, recursively---as
6325 would be returned by:
6326
6327 @example
6328 $ guix gc -R /gnu/store/@dots{}-coreutils-8.23
6329 @end example
6330
6331 Here the output shows three columns next to store items. The first column,
6332 labeled ``total'', shows the size in mebibytes (MiB) of the closure of
6333 the store item---that is, its own size plus the size of all its
6334 dependencies. The next column, labeled ``self'', shows the size of the
6335 item itself. The last column shows the ratio of the size of the item
6336 itself to the space occupied by all the items listed here.
6337
6338 In this example, we see that the closure of Coreutils weighs in at
6339 70@tie{}MiB, half of which is taken by libc. (That libc represents a
6340 large fraction of the closure is not a problem @i{per se} because it is
6341 always available on the system anyway.)
6342
6343 When the package passed to @command{guix size} is available in the
6344 store, @command{guix size} queries the daemon to determine its
6345 dependencies, and measures its size in the store, similar to @command{du
6346 -ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
6347 Coreutils}).
6348
6349 When the given package is @emph{not} in the store, @command{guix size}
6350 reports information based on the available substitutes
6351 (@pxref{Substitutes}). This makes it possible it to profile disk usage of
6352 store items that are not even on disk, only available remotely.
6353
6354 You can also specify several package names:
6355
6356 @example
6357 $ guix size coreutils grep sed bash
6358 store item total self
6359 /gnu/store/@dots{}-coreutils-8.24 77.8 13.8 13.4%
6360 /gnu/store/@dots{}-grep-2.22 73.1 0.8 0.8%
6361 /gnu/store/@dots{}-bash-4.3.42 72.3 4.7 4.6%
6362 /gnu/store/@dots{}-readline-6.3 67.6 1.2 1.2%
6363 @dots{}
6364 total: 102.3 MiB
6365 @end example
6366
6367 @noindent
6368 In this example we see that the combination of the four packages takes
6369 102.3@tie{}MiB in total, which is much less than the sum of each closure
6370 since they have a lot of dependencies in common.
6371
6372 The available options are:
6373
6374 @table @option
6375
6376 @item --substitute-urls=@var{urls}
6377 Use substitute information from @var{urls}.
6378 @xref{client-substitute-urls, the same option for @code{guix build}}.
6379
6380 @item --sort=@var{key}
6381 Sort lines according to @var{key}, one of the following options:
6382
6383 @table @code
6384 @item closure
6385 the total size of the item's closure (the default);
6386 @item self
6387 the size of each item.
6388 @end table
6389
6390 @item --map-file=@var{file}
6391 Write a graphical map of disk usage in PNG format to @var{file}.
6392
6393 For the example above, the map looks like this:
6394
6395 @image{images/coreutils-size-map,5in,, map of Coreutils disk usage
6396 produced by @command{guix size}}
6397
6398 This option requires that
6399 @uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
6400 installed and visible in Guile's module search path. When that is not
6401 the case, @command{guix size} fails as it tries to load it.
6402
6403 @item --system=@var{system}
6404 @itemx -s @var{system}
6405 Consider packages for @var{system}---e.g., @code{x86_64-linux}.
6406
6407 @end table
6408
6409 @node Invoking guix graph
6410 @section Invoking @command{guix graph}
6411
6412 @cindex DAG
6413 @cindex @command{guix graph}
6414 @cindex package dependencies
6415 Packages and their dependencies form a @dfn{graph}, specifically a
6416 directed acyclic graph (DAG). It can quickly become difficult to have a
6417 mental model of the package DAG, so the @command{guix graph} command
6418 provides a visual representation of the DAG. By default,
6419 @command{guix graph} emits a DAG representation in the input format of
6420 @uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
6421 directly to the @command{dot} command of Graphviz. It can also emit an
6422 HTML page with embedded JavaScript code to display a ``chord diagram''
6423 in a Web browser, using the @uref{https://d3js.org/, d3.js} library, or
6424 emit Cypher queries to construct a graph in a graph database supporting
6425 the @uref{http://www.opencypher.org/, openCypher} query language.
6426 The general syntax is:
6427
6428 @example
6429 guix graph @var{options} @var{package}@dots{}
6430 @end example
6431
6432 For example, the following command generates a PDF file representing the
6433 package DAG for the GNU@tie{}Core Utilities, showing its build-time
6434 dependencies:
6435
6436 @example
6437 guix graph coreutils | dot -Tpdf > dag.pdf
6438 @end example
6439
6440 The output looks like this:
6441
6442 @image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
6443
6444 Nice little graph, no?
6445
6446 But there is more than one graph! The one above is concise: it is the
6447 graph of package objects, omitting implicit inputs such as GCC, libc,
6448 grep, etc. It is often useful to have such a concise graph, but
6449 sometimes one may want to see more details. @command{guix graph} supports
6450 several types of graphs, allowing you to choose the level of detail:
6451
6452 @table @code
6453 @item package
6454 This is the default type used in the example above. It shows the DAG of
6455 package objects, excluding implicit dependencies. It is concise, but
6456 filters out many details.
6457
6458 @item reverse-package
6459 This shows the @emph{reverse} DAG of packages. For example:
6460
6461 @example
6462 guix graph --type=reverse-package ocaml
6463 @end example
6464
6465 ... yields the graph of packages that depend on OCaml.
6466
6467 Note that for core packages this can yield huge graphs. If all you want
6468 is to know the number of packages that depend on a given package, use
6469 @command{guix refresh --list-dependent} (@pxref{Invoking guix refresh,
6470 @option{--list-dependent}}).
6471
6472 @item bag-emerged
6473 This is the package DAG, @emph{including} implicit inputs.
6474
6475 For instance, the following command:
6476
6477 @example
6478 guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
6479 @end example
6480
6481 ... yields this bigger graph:
6482
6483 @image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
6484
6485 At the bottom of the graph, we see all the implicit inputs of
6486 @var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
6487
6488 Now, note that the dependencies of these implicit inputs---that is, the
6489 @dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
6490 here, for conciseness.
6491
6492 @item bag
6493 Similar to @code{bag-emerged}, but this time including all the bootstrap
6494 dependencies.
6495
6496 @item bag-with-origins
6497 Similar to @code{bag}, but also showing origins and their dependencies.
6498
6499 @item derivations
6500 This is the most detailed representation: It shows the DAG of
6501 derivations (@pxref{Derivations}) and plain store items. Compared to
6502 the above representation, many additional nodes are visible, including
6503 build scripts, patches, Guile modules, etc.
6504
6505 For this type of graph, it is also possible to pass a @file{.drv} file
6506 name instead of a package name, as in:
6507
6508 @example
6509 guix graph -t derivation `guix system build -d my-config.scm`
6510 @end example
6511 @end table
6512
6513 All the types above correspond to @emph{build-time dependencies}. The
6514 following graph type represents the @emph{run-time dependencies}:
6515
6516 @table @code
6517 @item references
6518 This is the graph of @dfn{references} of a package output, as returned
6519 by @command{guix gc --references} (@pxref{Invoking guix gc}).
6520
6521 If the given package output is not available in the store, @command{guix
6522 graph} attempts to obtain dependency information from substitutes.
6523
6524 Here you can also pass a store file name instead of a package name. For
6525 example, the command below produces the reference graph of your profile
6526 (which can be big!):
6527
6528 @example
6529 guix graph -t references `readlink -f ~/.guix-profile`
6530 @end example
6531
6532 @item referrers
6533 This is the graph of the @dfn{referrers} of a store item, as returned by
6534 @command{guix gc --referrers} (@pxref{Invoking guix gc}).
6535
6536 This relies exclusively on local information from your store. For
6537 instance, let us suppose that the current Inkscape is available in 10
6538 profiles on your machine; @command{guix graph -t referrers inkscape}
6539 will show a graph rooted at Inkscape and with those 10 profiles linked
6540 to it.
6541
6542 It can help determine what is preventing a store item from being garbage
6543 collected.
6544
6545 @end table
6546
6547 The available options are the following:
6548
6549 @table @option
6550 @item --type=@var{type}
6551 @itemx -t @var{type}
6552 Produce a graph output of @var{type}, where @var{type} must be one of
6553 the values listed above.
6554
6555 @item --list-types
6556 List the supported graph types.
6557
6558 @item --backend=@var{backend}
6559 @itemx -b @var{backend}
6560 Produce a graph using the selected @var{backend}.
6561
6562 @item --list-backends
6563 List the supported graph backends.
6564
6565 Currently, the available backends are Graphviz and d3.js.
6566
6567 @item --expression=@var{expr}
6568 @itemx -e @var{expr}
6569 Consider the package @var{expr} evaluates to.
6570
6571 This is useful to precisely refer to a package, as in this example:
6572
6573 @example
6574 guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
6575 @end example
6576 @end table
6577
6578
6579 @node Invoking guix environment
6580 @section Invoking @command{guix environment}
6581
6582 @cindex reproducible build environments
6583 @cindex development environments
6584 @cindex @command{guix environment}
6585 @cindex environment, package build environment
6586 The purpose of @command{guix environment} is to assist hackers in
6587 creating reproducible development environments without polluting their
6588 package profile. The @command{guix environment} tool takes one or more
6589 packages, builds all of their inputs, and creates a shell
6590 environment to use them.
6591
6592 The general syntax is:
6593
6594 @example
6595 guix environment @var{options} @var{package}@dots{}
6596 @end example
6597
6598 The following example spawns a new shell set up for the development of
6599 GNU@tie{}Guile:
6600
6601 @example
6602 guix environment guile
6603 @end example
6604
6605 If the needed dependencies are not built yet, @command{guix environment}
6606 automatically builds them. The environment of the new shell is an augmented
6607 version of the environment that @command{guix environment} was run in.
6608 It contains the necessary search paths for building the given package
6609 added to the existing environment variables. To create a ``pure''
6610 environment, in which the original environment variables have been unset,
6611 use the @code{--pure} option@footnote{Users sometimes wrongfully augment
6612 environment variables such as @code{PATH} in their @file{~/.bashrc}
6613 file. As a consequence, when @code{guix environment} launches it, Bash
6614 may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
6615 environment variables. It is an error to define such environment
6616 variables in @file{.bashrc}; instead, they should be defined in
6617 @file{.bash_profile}, which is sourced only by log-in shells.
6618 @xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
6619 details on Bash start-up files.}.
6620
6621 @vindex GUIX_ENVIRONMENT
6622 @command{guix environment} defines the @code{GUIX_ENVIRONMENT}
6623 variable in the shell it spawns; its value is the file name of the
6624 profile of this environment. This allows users to, say, define a
6625 specific prompt for development environments in their @file{.bashrc}
6626 (@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
6627
6628 @example
6629 if [ -n "$GUIX_ENVIRONMENT" ]
6630 then
6631 export PS1="\u@@\h \w [dev]\$ "
6632 fi
6633 @end example
6634
6635 @noindent
6636 ... or to browse the profile:
6637
6638 @example
6639 $ ls "$GUIX_ENVIRONMENT/bin"
6640 @end example
6641
6642 Additionally, more than one package may be specified, in which case the
6643 union of the inputs for the given packages are used. For example, the
6644 command below spawns a shell where all of the dependencies of both Guile
6645 and Emacs are available:
6646
6647 @example
6648 guix environment guile emacs
6649 @end example
6650
6651 Sometimes an interactive shell session is not desired. An arbitrary
6652 command may be invoked by placing the @code{--} token to separate the
6653 command from the rest of the arguments:
6654
6655 @example
6656 guix environment guile -- make -j4
6657 @end example
6658
6659 In other situations, it is more convenient to specify the list of
6660 packages needed in the environment. For example, the following command
6661 runs @command{python} from an environment containing Python@tie{}2.7 and
6662 NumPy:
6663
6664 @example
6665 guix environment --ad-hoc python2-numpy python-2.7 -- python
6666 @end example
6667
6668 Furthermore, one might want the dependencies of a package and also some
6669 additional packages that are not build-time or runtime dependencies, but
6670 are useful when developing nonetheless. Because of this, the
6671 @code{--ad-hoc} flag is positional. Packages appearing before
6672 @code{--ad-hoc} are interpreted as packages whose dependencies will be
6673 added to the environment. Packages appearing after are interpreted as
6674 packages that will be added to the environment directly. For example,
6675 the following command creates a Guix development environment that
6676 additionally includes Git and strace:
6677
6678 @example
6679 guix environment guix --ad-hoc git strace
6680 @end example
6681
6682 Sometimes it is desirable to isolate the environment as much as
6683 possible, for maximal purity and reproducibility. In particular, when
6684 using Guix on a host distro that is not GuixSD, it is desirable to
6685 prevent access to @file{/usr/bin} and other system-wide resources from
6686 the development environment. For example, the following command spawns
6687 a Guile REPL in a ``container'' where only the store and the current
6688 working directory are mounted:
6689
6690 @example
6691 guix environment --ad-hoc --container guile -- guile
6692 @end example
6693
6694 @quotation Note
6695 The @code{--container} option requires Linux-libre 3.19 or newer.
6696 @end quotation
6697
6698 The available options are summarized below.
6699
6700 @table @code
6701 @item --root=@var{file}
6702 @itemx -r @var{file}
6703 @cindex persistent environment
6704 @cindex garbage collector root, for environments
6705 Make @var{file} a symlink to the profile for this environment, and
6706 register it as a garbage collector root.
6707
6708 This is useful if you want to protect your environment from garbage
6709 collection, to make it ``persistent''.
6710
6711 When this option is omitted, the environment is protected from garbage
6712 collection only for the duration of the @command{guix environment}
6713 session. This means that next time you recreate the same environment,
6714 you could have to rebuild or re-download packages.
6715
6716 @item --expression=@var{expr}
6717 @itemx -e @var{expr}
6718 Create an environment for the package or list of packages that
6719 @var{expr} evaluates to.
6720
6721 For example, running:
6722
6723 @example
6724 guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
6725 @end example
6726
6727 starts a shell with the environment for this specific variant of the
6728 PETSc package.
6729
6730 Running:
6731
6732 @example
6733 guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
6734 @end example
6735
6736 starts a shell with all the GuixSD base packages available.
6737
6738 The above commands only use the default output of the given packages.
6739 To select other outputs, two element tuples can be specified:
6740
6741 @example
6742 guix environment --ad-hoc -e '(list (@ (gnu packages bash) bash) "include")'
6743 @end example
6744
6745 @item --load=@var{file}
6746 @itemx -l @var{file}
6747 Create an environment for the package or list of packages that the code
6748 within @var{file} evaluates to.
6749
6750 As an example, @var{file} might contain a definition like this
6751 (@pxref{Defining Packages}):
6752
6753 @example
6754 @verbatiminclude environment-gdb.scm
6755 @end example
6756
6757 @item --ad-hoc
6758 Include all specified packages in the resulting environment, as if an
6759 @i{ad hoc} package were defined with them as inputs. This option is
6760 useful for quickly creating an environment without having to write a
6761 package expression to contain the desired inputs.
6762
6763 For instance, the command:
6764
6765 @example
6766 guix environment --ad-hoc guile guile-sdl -- guile
6767 @end example
6768
6769 runs @command{guile} in an environment where Guile and Guile-SDL are
6770 available.
6771
6772 Note that this example implicitly asks for the default output of
6773 @code{guile} and @code{guile-sdl}, but it is possible to ask for a
6774 specific output---e.g., @code{glib:bin} asks for the @code{bin} output
6775 of @code{glib} (@pxref{Packages with Multiple Outputs}).
6776
6777 This option may be composed with the default behavior of @command{guix
6778 environment}. Packages appearing before @code{--ad-hoc} are interpreted
6779 as packages whose dependencies will be added to the environment, the
6780 default behavior. Packages appearing after are interpreted as packages
6781 that will be added to the environment directly.
6782
6783 @item --pure
6784 Unset existing environment variables when building the new environment.
6785 This has the effect of creating an environment in which search paths
6786 only contain package inputs.
6787
6788 @item --search-paths
6789 Display the environment variable definitions that make up the
6790 environment.
6791
6792 @item --system=@var{system}
6793 @itemx -s @var{system}
6794 Attempt to build for @var{system}---e.g., @code{i686-linux}.
6795
6796 @item --container
6797 @itemx -C
6798 @cindex container
6799 Run @var{command} within an isolated container. The current working
6800 directory outside the container is mapped inside the container.
6801 Additionally, a dummy home directory is created that matches the current
6802 user's home directory, and @file{/etc/passwd} is configured accordingly.
6803 The spawned process runs as the current user outside the container, but
6804 has root privileges in the context of the container.
6805
6806 @item --network
6807 @itemx -N
6808 For containers, share the network namespace with the host system.
6809 Containers created without this flag only have access to the loopback
6810 device.
6811
6812 @item --expose=@var{source}[=@var{target}]
6813 For containers, expose the file system @var{source} from the host system
6814 as the read-only file system @var{target} within the container. If
6815 @var{target} is not specified, @var{source} is used as the target mount
6816 point in the container.
6817
6818 The example below spawns a Guile REPL in a container in which the user's
6819 home directory is accessible read-only via the @file{/exchange}
6820 directory:
6821
6822 @example
6823 guix environment --container --expose=$HOME=/exchange --ad-hoc guile -- guile
6824 @end example
6825
6826 @item --share=@var{source}[=@var{target}]
6827 For containers, share the file system @var{source} from the host system
6828 as the writable file system @var{target} within the container. If
6829 @var{target} is not specified, @var{source} is used as the target mount
6830 point in the container.
6831
6832 The example below spawns a Guile REPL in a container in which the user's
6833 home directory is accessible for both reading and writing via the
6834 @file{/exchange} directory:
6835
6836 @example
6837 guix environment --container --share=$HOME=/exchange --ad-hoc guile -- guile
6838 @end example
6839 @end table
6840
6841 @command{guix environment}
6842 also supports all of the common build options that @command{guix
6843 build} supports (@pxref{Common Build Options}).
6844
6845
6846 @node Invoking guix publish
6847 @section Invoking @command{guix publish}
6848
6849 @cindex @command{guix publish}
6850 The purpose of @command{guix publish} is to enable users to easily share
6851 their store with others, who can then use it as a substitute server
6852 (@pxref{Substitutes}).
6853
6854 When @command{guix publish} runs, it spawns an HTTP server which allows
6855 anyone with network access to obtain substitutes from it. This means
6856 that any machine running Guix can also act as if it were a build farm,
6857 since the HTTP interface is compatible with Hydra, the software behind
6858 the @code{hydra.gnu.org} build farm.
6859
6860 For security, each substitute is signed, allowing recipients to check
6861 their authenticity and integrity (@pxref{Substitutes}). Because
6862 @command{guix publish} uses the signing key of the system, which is only
6863 readable by the system administrator, it must be started as root; the
6864 @code{--user} option makes it drop root privileges early on.
6865
6866 The signing key pair must be generated before @command{guix publish} is
6867 launched, using @command{guix archive --generate-key} (@pxref{Invoking
6868 guix archive}).
6869
6870 The general syntax is:
6871
6872 @example
6873 guix publish @var{options}@dots{}
6874 @end example
6875
6876 Running @command{guix publish} without any additional arguments will
6877 spawn an HTTP server on port 8080:
6878
6879 @example
6880 guix publish
6881 @end example
6882
6883 Once a publishing server has been authorized (@pxref{Invoking guix
6884 archive}), the daemon may download substitutes from it:
6885
6886 @example
6887 guix-daemon --substitute-urls=http://example.org:8080
6888 @end example
6889
6890 By default, @command{guix publish} compresses archives on the fly as it
6891 serves them. This ``on-the-fly'' mode is convenient in that it requires
6892 no setup and is immediately available. However, when serving lots of
6893 clients, we recommend using the @option{--cache} option, which enables
6894 caching of the archives before they are sent to clients---see below for
6895 details. The @command{guix weather} command provides a handy way to
6896 check what a server provides (@pxref{Invoking guix weather}).
6897
6898 As a bonus, @command{guix publish} also serves as a content-addressed
6899 mirror for source files referenced in @code{origin} records
6900 (@pxref{origin Reference}). For instance, assuming @command{guix
6901 publish} is running on @code{example.org}, the following URL returns the
6902 raw @file{hello-2.10.tar.gz} file with the given SHA256 hash
6903 (represented in @code{nix-base32} format, @pxref{Invoking guix hash}):
6904
6905 @example
6906 http://example.org/file/hello-2.10.tar.gz/sha256/0ssi1@dots{}ndq1i
6907 @end example
6908
6909 Obviously, these URLs only work for files that are in the store; in
6910 other cases, they return 404 (``Not Found'').
6911
6912 The following options are available:
6913
6914 @table @code
6915 @item --port=@var{port}
6916 @itemx -p @var{port}
6917 Listen for HTTP requests on @var{port}.
6918
6919 @item --listen=@var{host}
6920 Listen on the network interface for @var{host}. The default is to
6921 accept connections from any interface.
6922
6923 @item --user=@var{user}
6924 @itemx -u @var{user}
6925 Change privileges to @var{user} as soon as possible---i.e., once the
6926 server socket is open and the signing key has been read.
6927
6928 @item --compression[=@var{level}]
6929 @itemx -C [@var{level}]
6930 Compress data using the given @var{level}. When @var{level} is zero,
6931 disable compression. The range 1 to 9 corresponds to different gzip
6932 compression levels: 1 is the fastest, and 9 is the best (CPU-intensive).
6933 The default is 3.
6934
6935 Unless @option{--cache} is used, compression occurs on the fly and
6936 the compressed streams are not
6937 cached. Thus, to reduce load on the machine that runs @command{guix
6938 publish}, it may be a good idea to choose a low compression level, to
6939 run @command{guix publish} behind a caching proxy, or to use
6940 @option{--cache}. Using @option{--cache} has the advantage that it
6941 allows @command{guix publish} to add @code{Content-Length} HTTP header
6942 to its responses.
6943
6944 @item --cache=@var{directory}
6945 @itemx -c @var{directory}
6946 Cache archives and meta-data (@code{.narinfo} URLs) to @var{directory}
6947 and only serve archives that are in cache.
6948
6949 When this option is omitted, archives and meta-data are created
6950 on-the-fly. This can reduce the available bandwidth, especially when
6951 compression is enabled, since this may become CPU-bound. Another
6952 drawback of the default mode is that the length of archives is not known
6953 in advance, so @command{guix publish} does not add a
6954 @code{Content-Length} HTTP header to its responses, which in turn
6955 prevents clients from knowing the amount of data being downloaded.
6956
6957 Conversely, when @option{--cache} is used, the first request for a store
6958 item (@i{via} a @code{.narinfo} URL) returns 404 and triggers a
6959 background process to @dfn{bake} the archive---computing its
6960 @code{.narinfo} and compressing the archive, if needed. Once the
6961 archive is cached in @var{directory}, subsequent requests succeed and
6962 are served directly from the cache, which guarantees that clients get
6963 the best possible bandwidth.
6964
6965 The ``baking'' process is performed by worker threads. By default, one
6966 thread per CPU core is created, but this can be customized. See
6967 @option{--workers} below.
6968
6969 When @option{--ttl} is used, cached entries are automatically deleted
6970 when they have expired.
6971
6972 @item --workers=@var{N}
6973 When @option{--cache} is used, request the allocation of @var{N} worker
6974 threads to ``bake'' archives.
6975
6976 @item --ttl=@var{ttl}
6977 Produce @code{Cache-Control} HTTP headers that advertise a time-to-live
6978 (TTL) of @var{ttl}. @var{ttl} must denote a duration: @code{5d} means 5
6979 days, @code{1m} means 1 month, and so on.
6980
6981 This allows the user's Guix to keep substitute information in cache for
6982 @var{ttl}. However, note that @code{guix publish} does not itself
6983 guarantee that the store items it provides will indeed remain available
6984 for as long as @var{ttl}.
6985
6986 Additionally, when @option{--cache} is used, cached entries that have
6987 not been accessed for @var{ttl} and that no longer have a corresponding
6988 item in the store, may be deleted.
6989
6990 @item --nar-path=@var{path}
6991 Use @var{path} as the prefix for the URLs of ``nar'' files
6992 (@pxref{Invoking guix archive, normalized archives}).
6993
6994 By default, nars are served at a URL such as
6995 @code{/nar/gzip/@dots{}-coreutils-8.25}. This option allows you to
6996 change the @code{/nar} part to @var{path}.
6997
6998 @item --public-key=@var{file}
6999 @itemx --private-key=@var{file}
7000 Use the specific @var{file}s as the public/private key pair used to sign
7001 the store items being published.
7002
7003 The files must correspond to the same key pair (the private key is used
7004 for signing and the public key is merely advertised in the signature
7005 metadata). They must contain keys in the canonical s-expression format
7006 as produced by @command{guix archive --generate-key} (@pxref{Invoking
7007 guix archive}). By default, @file{/etc/guix/signing-key.pub} and
7008 @file{/etc/guix/signing-key.sec} are used.
7009
7010 @item --repl[=@var{port}]
7011 @itemx -r [@var{port}]
7012 Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
7013 Reference Manual}) on @var{port} (37146 by default). This is used
7014 primarily for debugging a running @command{guix publish} server.
7015 @end table
7016
7017 Enabling @command{guix publish} on a GuixSD system is a one-liner: just
7018 instantiate a @code{guix-publish-service-type} service in the @code{services} field
7019 of the @code{operating-system} declaration (@pxref{guix-publish-service-type,
7020 @code{guix-publish-service-type}}).
7021
7022 If you are instead running Guix on a ``foreign distro'', follow these
7023 instructions:”
7024
7025 @itemize
7026 @item
7027 If your host distro uses the systemd init system:
7028
7029 @example
7030 # ln -s ~root/.guix-profile/lib/systemd/system/guix-publish.service \
7031 /etc/systemd/system/
7032 # systemctl start guix-publish && systemctl enable guix-publish
7033 @end example
7034
7035 @item
7036 If your host distro uses the Upstart init system:
7037
7038 @example
7039 # ln -s ~root/.guix-profile/lib/upstart/system/guix-publish.conf /etc/init/
7040 # start guix-publish
7041 @end example
7042
7043 @item
7044 Otherwise, proceed similarly with your distro's init system.
7045 @end itemize
7046
7047 @node Invoking guix challenge
7048 @section Invoking @command{guix challenge}
7049
7050 @cindex reproducible builds
7051 @cindex verifiable builds
7052 @cindex @command{guix challenge}
7053 @cindex challenge
7054 Do the binaries provided by this server really correspond to the source
7055 code it claims to build? Is a package build process deterministic?
7056 These are the questions the @command{guix challenge} command attempts to
7057 answer.
7058
7059 The former is obviously an important question: Before using a substitute
7060 server (@pxref{Substitutes}), one had better @emph{verify} that it
7061 provides the right binaries, and thus @emph{challenge} it. The latter
7062 is what enables the former: If package builds are deterministic, then
7063 independent builds of the package should yield the exact same result,
7064 bit for bit; if a server provides a binary different from the one
7065 obtained locally, it may be either corrupt or malicious.
7066
7067 We know that the hash that shows up in @file{/gnu/store} file names is
7068 the hash of all the inputs of the process that built the file or
7069 directory---compilers, libraries, build scripts,
7070 etc. (@pxref{Introduction}). Assuming deterministic build processes,
7071 one store file name should map to exactly one build output.
7072 @command{guix challenge} checks whether there is, indeed, a single
7073 mapping by comparing the build outputs of several independent builds of
7074 any given store item.
7075
7076 The command output looks like this:
7077
7078 @smallexample
7079 $ guix challenge --substitute-urls="https://hydra.gnu.org https://guix.example.org"
7080 updating list of substitutes from 'https://hydra.gnu.org'... 100.0%
7081 updating list of substitutes from 'https://guix.example.org'... 100.0%
7082 /gnu/store/@dots{}-openssl-1.0.2d contents differ:
7083 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
7084 https://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
7085 https://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
7086 /gnu/store/@dots{}-git-2.5.0 contents differ:
7087 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
7088 https://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
7089 https://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
7090 /gnu/store/@dots{}-pius-2.1.1 contents differ:
7091 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
7092 https://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
7093 https://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
7094 @end smallexample
7095
7096 @noindent
7097 In this example, @command{guix challenge} first scans the store to
7098 determine the set of locally-built derivations---as opposed to store
7099 items that were downloaded from a substitute server---and then queries
7100 all the substitute servers. It then reports those store items for which
7101 the servers obtained a result different from the local build.
7102
7103 @cindex non-determinism, in package builds
7104 As an example, @code{guix.example.org} always gets a different answer.
7105 Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
7106 case of Git. This might indicate that the build process of Git is
7107 non-deterministic, meaning that its output varies as a function of
7108 various things that Guix does not fully control, in spite of building
7109 packages in isolated environments (@pxref{Features}). Most common
7110 sources of non-determinism include the addition of timestamps in build
7111 results, the inclusion of random numbers, and directory listings sorted
7112 by inode number. See @uref{https://reproducible-builds.org/docs/}, for
7113 more information.
7114
7115 To find out what is wrong with this Git binary, we can do something along
7116 these lines (@pxref{Invoking guix archive}):
7117
7118 @example
7119 $ wget -q -O - https://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
7120 | guix archive -x /tmp/git
7121 $ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
7122 @end example
7123
7124 This command shows the difference between the files resulting from the
7125 local build, and the files resulting from the build on
7126 @code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
7127 diffutils, Comparing and Merging Files}). The @command{diff} command
7128 works great for text files. When binary files differ, a better option
7129 is @uref{https://diffoscope.org/, Diffoscope}, a tool that helps
7130 visualize differences for all kinds of files.
7131
7132 Once you have done that work, you can tell whether the differences are due
7133 to a non-deterministic build process or to a malicious server. We try
7134 hard to remove sources of non-determinism in packages to make it easier
7135 to verify substitutes, but of course, this is a process that
7136 involves not just Guix, but a large part of the free software community.
7137 In the meantime, @command{guix challenge} is one tool to help address
7138 the problem.
7139
7140 If you are writing packages for Guix, you are encouraged to check
7141 whether @code{hydra.gnu.org} and other substitute servers obtain the
7142 same build result as you did with:
7143
7144 @example
7145 $ guix challenge @var{package}
7146 @end example
7147
7148 @noindent
7149 where @var{package} is a package specification such as
7150 @code{guile@@2.0} or @code{glibc:debug}.
7151
7152 The general syntax is:
7153
7154 @example
7155 guix challenge @var{options} [@var{packages}@dots{}]
7156 @end example
7157
7158 When a difference is found between the hash of a locally-built item and
7159 that of a server-provided substitute, or among substitutes provided by
7160 different servers, the command displays it as in the example above and
7161 its exit code is 2 (other non-zero exit codes denote other kinds of
7162 errors.)
7163
7164 The one option that matters is:
7165
7166 @table @code
7167
7168 @item --substitute-urls=@var{urls}
7169 Consider @var{urls} the whitespace-separated list of substitute source
7170 URLs to compare to.
7171
7172 @item --verbose
7173 @itemx -v
7174 Show details about matches (identical contents) in addition to
7175 information about mismatches.
7176
7177 @end table
7178
7179 @node Invoking guix copy
7180 @section Invoking @command{guix copy}
7181
7182 @cindex copy, of store items, over SSH
7183 @cindex SSH, copy of store items
7184 @cindex sharing store items across machines
7185 @cindex transferring store items across machines
7186 The @command{guix copy} command copies items from the store of one
7187 machine to that of another machine over a secure shell (SSH)
7188 connection@footnote{This command is available only when Guile-SSH was
7189 found. @xref{Requirements}, for details.}. For example, the following
7190 command copies the @code{coreutils} package, the user's profile, and all
7191 their dependencies over to @var{host}, logged in as @var{user}:
7192
7193 @example
7194 guix copy --to=@var{user}@@@var{host} \
7195 coreutils `readlink -f ~/.guix-profile`
7196 @end example
7197
7198 If some of the items to be copied are already present on @var{host},
7199 they are not actually sent.
7200
7201 The command below retrieves @code{libreoffice} and @code{gimp} from
7202 @var{host}, assuming they are available there:
7203
7204 @example
7205 guix copy --from=@var{host} libreoffice gimp
7206 @end example
7207
7208 The SSH connection is established using the Guile-SSH client, which is
7209 compatible with OpenSSH: it honors @file{~/.ssh/known_hosts} and
7210 @file{~/.ssh/config}, and uses the SSH agent for authentication.
7211
7212 The key used to sign items that are sent must be accepted by the remote
7213 machine. Likewise, the key used by the remote machine to sign items you
7214 are retrieving must be in @file{/etc/guix/acl} so it is accepted by your
7215 own daemon. @xref{Invoking guix archive}, for more information about
7216 store item authentication.
7217
7218 The general syntax is:
7219
7220 @example
7221 guix copy [--to=@var{spec}|--from=@var{spec}] @var{items}@dots{}
7222 @end example
7223
7224 You must always specify one of the following options:
7225
7226 @table @code
7227 @item --to=@var{spec}
7228 @itemx --from=@var{spec}
7229 Specify the host to send to or receive from. @var{spec} must be an SSH
7230 spec such as @code{example.org}, @code{charlie@@example.org}, or
7231 @code{charlie@@example.org:2222}.
7232 @end table
7233
7234 The @var{items} can be either package names, such as @code{gimp}, or
7235 store items, such as @file{/gnu/store/@dots{}-idutils-4.6}.
7236
7237 When specifying the name of a package to send, it is first built if
7238 needed, unless @option{--dry-run} was specified. Common build options
7239 are supported (@pxref{Common Build Options}).
7240
7241
7242 @node Invoking guix container
7243 @section Invoking @command{guix container}
7244 @cindex container
7245 @cindex @command{guix container}
7246 @quotation Note
7247 As of version @value{VERSION}, this tool is experimental. The interface
7248 is subject to radical change in the future.
7249 @end quotation
7250
7251 The purpose of @command{guix container} is to manipulate processes
7252 running within an isolated environment, commonly known as a
7253 ``container'', typically created by the @command{guix environment}
7254 (@pxref{Invoking guix environment}) and @command{guix system container}
7255 (@pxref{Invoking guix system}) commands.
7256
7257 The general syntax is:
7258
7259 @example
7260 guix container @var{action} @var{options}@dots{}
7261 @end example
7262
7263 @var{action} specifies the operation to perform with a container, and
7264 @var{options} specifies the context-specific arguments for the action.
7265
7266 The following actions are available:
7267
7268 @table @code
7269 @item exec
7270 Execute a command within the context of a running container.
7271
7272 The syntax is:
7273
7274 @example
7275 guix container exec @var{pid} @var{program} @var{arguments}@dots{}
7276 @end example
7277
7278 @var{pid} specifies the process ID of the running container.
7279 @var{program} specifies an executable file name within the root file
7280 system of the container. @var{arguments} are the additional options that
7281 will be passed to @var{program}.
7282
7283 The following command launches an interactive login shell inside a
7284 GuixSD container, started by @command{guix system container}, and whose
7285 process ID is 9001:
7286
7287 @example
7288 guix container exec 9001 /run/current-system/profile/bin/bash --login
7289 @end example
7290
7291 Note that the @var{pid} cannot be the parent process of a container. It
7292 must be PID 1 of the container or one of its child processes.
7293
7294 @end table
7295
7296 @node Invoking guix weather
7297 @section Invoking @command{guix weather}
7298
7299 Occasionally you're grumpy because substitutes are lacking and you end
7300 up building packages by yourself (@pxref{Substitutes}). The
7301 @command{guix weather} command reports on substitute availability on the
7302 specified servers so you can have an idea of whether you'll be grumpy
7303 today. It can sometimes be useful info as a user, but it is primarily
7304 useful to people running @command{guix publish} (@pxref{Invoking guix
7305 publish}).
7306
7307 @cindex statistics, for substitutes
7308 @cindex availability of substitutes
7309 @cindex substitute availability
7310 @cindex weather, substitute availability
7311 Here's a sample run:
7312
7313 @example
7314 $ guix weather --substitute-urls=https://guix.example.org
7315 computing 5,872 package derivations for x86_64-linux...
7316 looking for 6,128 store items on https://guix.example.org..
7317 updating list of substitutes from 'https://guix.example.org'... 100.0%
7318 https://guix.example.org
7319 43.4% substitutes available (2,658 out of 6,128)
7320 7,032.5 MiB of nars (compressed)
7321 19,824.2 MiB on disk (uncompressed)
7322 0.030 seconds per request (182.9 seconds in total)
7323 33.5 requests per second
7324 @end example
7325
7326 As you can see, it reports the fraction of all the packages for which
7327 substitutes are available on the server---regardless of whether
7328 substitutes are enabled, and regardless of whether this server's signing
7329 key is authorized. It also reports the size of the compressed archives
7330 (``nars'') provided by the server, the size the corresponding store
7331 items occupy in the store (assuming deduplication is turned off), and
7332 the server's throughput.
7333
7334 To achieve that, @command{guix weather} queries over HTTP(S) meta-data
7335 (@dfn{narinfos}) for all the relevant store items. Like @command{guix
7336 challenge}, it ignores signatures on those substitutes, which is
7337 innocuous since the command only gathers statistics and cannot install
7338 those substitutes.
7339
7340 Among other things, it is possible to query specific system types and
7341 specific package sets. The available options are listed below.
7342
7343 @table @code
7344 @item --substitute-urls=@var{urls}
7345 @var{urls} is the space-separated list of substitute server URLs to
7346 query. When this option is omitted, the default set of substitute
7347 servers is queried.
7348
7349 @item --system=@var{system}
7350 @itemx -s @var{system}
7351 Query substitutes for @var{system}---e.g., @code{aarch64-linux}. This
7352 option can be repeated, in which case @command{guix weather} will query
7353 substitutes for several system types.
7354
7355 @item --manifest=@var{file}
7356 Instead of querying substitutes for all the packages, only ask for those
7357 specified in @var{file}. @var{file} must contain a @dfn{manifest}, as
7358 with the @code{-m} option of @command{guix package} (@pxref{Invoking
7359 guix package}).
7360 @end table
7361
7362
7363 @c *********************************************************************
7364 @node GNU Distribution
7365 @chapter GNU Distribution
7366
7367 @cindex Guix System Distribution
7368 @cindex GuixSD
7369 Guix comes with a distribution of the GNU system consisting entirely of
7370 free software@footnote{The term ``free'' here refers to the
7371 @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
7372 users of that software}.}. The
7373 distribution can be installed on its own (@pxref{System Installation}),
7374 but it is also possible to install Guix as a package manager on top of
7375 an installed GNU/Linux system (@pxref{Installation}). To distinguish
7376 between the two, we refer to the standalone distribution as the Guix
7377 System Distribution, or GuixSD.
7378
7379 The distribution provides core GNU packages such as GNU libc, GCC, and
7380 Binutils, as well as many GNU and non-GNU applications. The complete
7381 list of available packages can be browsed
7382 @url{http://www.gnu.org/software/guix/packages,on-line} or by
7383 running @command{guix package} (@pxref{Invoking guix package}):
7384
7385 @example
7386 guix package --list-available
7387 @end example
7388
7389 Our goal is to provide a practical 100% free software distribution of
7390 Linux-based and other variants of GNU, with a focus on the promotion and
7391 tight integration of GNU components, and an emphasis on programs and
7392 tools that help users exert that freedom.
7393
7394 Packages are currently available on the following platforms:
7395
7396 @table @code
7397
7398 @item x86_64-linux
7399 Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
7400
7401 @item i686-linux
7402 Intel 32-bit architecture (IA32), Linux-Libre kernel;
7403
7404 @item armhf-linux
7405 ARMv7-A architecture with hard float, Thumb-2 and NEON,
7406 using the EABI hard-float application binary interface (ABI),
7407 and Linux-Libre kernel.
7408
7409 @item aarch64-linux
7410 little-endian 64-bit ARMv8-A processors, Linux-Libre kernel. This is
7411 currently in an experimental stage, with limited support.
7412 @xref{Contributing}, for how to help!
7413
7414 @item mips64el-linux
7415 little-endian 64-bit MIPS processors, specifically the Loongson series,
7416 n32 ABI, and Linux-Libre kernel.
7417
7418 @end table
7419
7420 GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
7421
7422 @noindent
7423 For information on porting to other architectures or kernels,
7424 @pxref{Porting}.
7425
7426 @menu
7427 * System Installation:: Installing the whole operating system.
7428 * System Configuration:: Configuring the operating system.
7429 * Documentation:: Browsing software user manuals.
7430 * Installing Debugging Files:: Feeding the debugger.
7431 * Security Updates:: Deploying security fixes quickly.
7432 * Package Modules:: Packages from the programmer's viewpoint.
7433 * Packaging Guidelines:: Growing the distribution.
7434 * Bootstrapping:: GNU/Linux built from scratch.
7435 * Porting:: Targeting another platform or kernel.
7436 @end menu
7437
7438 Building this distribution is a cooperative effort, and you are invited
7439 to join! @xref{Contributing}, for information about how you can help.
7440
7441 @node System Installation
7442 @section System Installation
7443
7444 @cindex installing GuixSD
7445 @cindex Guix System Distribution
7446 This section explains how to install the Guix System Distribution (GuixSD)
7447 on a machine. The Guix package manager can
7448 also be installed on top of a running GNU/Linux system,
7449 @pxref{Installation}.
7450
7451 @ifinfo
7452 @quotation Note
7453 @c This paragraph is for people reading this from tty2 of the
7454 @c installation image.
7455 You are reading this documentation with an Info reader. For details on
7456 how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
7457 link that follows: @pxref{Top, Info reader,, info-stnd, Stand-alone GNU
7458 Info}. Hit @kbd{l} afterwards to come back here.
7459
7460 Alternately, run @command{info info} in another tty to keep the manual
7461 available.
7462 @end quotation
7463 @end ifinfo
7464
7465 @menu
7466 * Limitations:: What you can expect.
7467 * Hardware Considerations:: Supported hardware.
7468 * USB Stick Installation:: Preparing the installation medium.
7469 * DVD Installation:: Preparing the installation medium.
7470 * Preparing for Installation:: Networking, partitioning, etc.
7471 * Proceeding with the Installation:: The real thing.
7472 * Installing GuixSD in a VM:: GuixSD playground.
7473 * Building the Installation Image:: How this comes to be.
7474 @end menu
7475
7476 @node Limitations
7477 @subsection Limitations
7478
7479 As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
7480 not production-ready. It may contain bugs and lack important
7481 features. Thus, if you are looking for a stable production system that
7482 respects your freedom as a computer user, a good solution at this point
7483 is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
7484 the more established GNU/Linux distributions}. We hope you can soon switch
7485 to the GuixSD without fear, of course. In the meantime, you can
7486 also keep using your distribution and try out the package manager on top
7487 of it (@pxref{Installation}).
7488
7489 Before you proceed with the installation, be aware of the following
7490 noteworthy limitations applicable to version @value{VERSION}:
7491
7492 @itemize
7493 @item
7494 The installation process does not include a graphical user interface and
7495 requires familiarity with GNU/Linux (see the following subsections to
7496 get a feel of what that means.)
7497
7498 @item
7499 Support for the Logical Volume Manager (LVM) is missing.
7500
7501 @item
7502 More and more system services are provided (@pxref{Services}), but some
7503 may be missing.
7504
7505 @item
7506 More than 5,300 packages are available, but you may
7507 occasionally find that a useful package is missing.
7508
7509 @item
7510 GNOME, Xfce, LXDE, and Enlightenment are available (@pxref{Desktop Services}),
7511 as well as a number of X11 window managers. However, some graphical
7512 applications may be missing, as well as KDE.
7513 @end itemize
7514
7515 You have been warned! But more than a disclaimer, this is an invitation
7516 to report issues (and success stories!), and to join us in improving it.
7517 @xref{Contributing}, for more info.
7518
7519
7520 @node Hardware Considerations
7521 @subsection Hardware Considerations
7522
7523 @cindex hardware support on GuixSD
7524 GNU@tie{}GuixSD focuses on respecting the user's computing freedom. It
7525 builds around the kernel Linux-libre, which means that only hardware for
7526 which free software drivers and firmware exist is supported. Nowadays,
7527 a wide range of off-the-shelf hardware is supported on
7528 GNU/Linux-libre---from keyboards to graphics cards to scanners and
7529 Ethernet controllers. Unfortunately, there are still areas where
7530 hardware vendors deny users control over their own computing, and such
7531 hardware is not supported on GuixSD.
7532
7533 @cindex WiFi, hardware support
7534 One of the main areas where free drivers or firmware are lacking is WiFi
7535 devices. WiFi devices known to work include those using Atheros chips
7536 (AR9271 and AR7010), which corresponds to the @code{ath9k} Linux-libre
7537 driver, and those using Broadcom/AirForce chips (BCM43xx with
7538 Wireless-Core Revision 5), which corresponds to the @code{b43-open}
7539 Linux-libre driver. Free firmware exists for both and is available
7540 out-of-the-box on GuixSD, as part of @var{%base-firmware}
7541 (@pxref{operating-system Reference, @code{firmware}}).
7542
7543 @cindex RYF, Respects Your Freedom
7544 The @uref{https://www.fsf.org/, Free Software Foundation} runs
7545 @uref{https://www.fsf.org/ryf, @dfn{Respects Your Freedom}} (RYF), a
7546 certification program for hardware products that respect your freedom
7547 and your privacy and ensure that you have control over your device. We
7548 encourage you to check the list of RYF-certified devices.
7549
7550 Another useful resource is the @uref{https://www.h-node.org/, H-Node}
7551 web site. It contains a catalog of hardware devices with information
7552 about their support in GNU/Linux.
7553
7554
7555 @node USB Stick Installation
7556 @subsection USB Stick Installation
7557
7558 An installation image for USB sticks can be downloaded from
7559 @indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-install-@value{VERSION}.@var{system}.xz},
7560 where @var{system} is one of:
7561
7562 @table @code
7563 @item x86_64-linux
7564 for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
7565
7566 @item i686-linux
7567 for a 32-bit GNU/Linux system on Intel-compatible CPUs.
7568 @end table
7569
7570 @c start duplication of authentication part from ``Binary Installation''
7571 Make sure to download the associated @file{.sig} file and to verify the
7572 authenticity of the image against it, along these lines:
7573
7574 @example
7575 $ wget ftp://alpha.gnu.org/gnu/guix/guixsd-install-@value{VERSION}.@var{system}.xz.sig
7576 $ gpg --verify guixsd-install-@value{VERSION}.@var{system}.xz.sig
7577 @end example
7578
7579 If that command fails because you do not have the required public key,
7580 then run this command to import it:
7581
7582 @example
7583 $ gpg --keyserver pgp.mit.edu --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
7584 @end example
7585
7586 @noindent
7587 and rerun the @code{gpg --verify} command.
7588 @c end duplication
7589
7590 This image contains the tools necessary for an installation.
7591 It is meant to be copied @emph{as is} to a large-enough USB stick or DVD.
7592
7593 To copy the image to a USB stick, follow these steps:
7594
7595 @enumerate
7596 @item
7597 Decompress the image using the @command{xz} command:
7598
7599 @example
7600 xz -d guixsd-install-@value{VERSION}.@var{system}.xz
7601 @end example
7602
7603 @item
7604 Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
7605 its device name. Assuming that the USB stick is known as @file{/dev/sdX},
7606 copy the image with:
7607
7608 @example
7609 dd if=guixsd-install-@value{VERSION}.x86_64 of=/dev/sdX
7610 sync
7611 @end example
7612
7613 Access to @file{/dev/sdX} usually requires root privileges.
7614 @end enumerate
7615
7616 Once this is done, you should be able to reboot the system and boot from
7617 the USB stick. The latter usually requires you to get in the BIOS or
7618 UEFI boot menu, where you can choose to boot from the USB stick.
7619
7620 @xref{Installing GuixSD in a VM}, if, instead, you would like to install
7621 GuixSD in a virtual machine (VM).
7622
7623 @node DVD Installation
7624 @subsection DVD Installation
7625
7626 An installation image for DVDs can be downloaded from
7627 @indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-install-@value{VERSION}.@var{system}.xz},
7628 where @var{system} is one of:
7629
7630 @table @code
7631 @item x86_64-linux
7632 for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
7633
7634 @item i686-linux
7635 for a 32-bit GNU/Linux system on Intel-compatible CPUs.
7636 @end table
7637
7638 @c start duplication of authentication part from ``Binary Installation''
7639 Make sure to download the associated @file{.sig} file and to verify the
7640 authenticity of the image against it, along these lines:
7641
7642 @example
7643 $ wget ftp://alpha.gnu.org/gnu/guix/guixsd-install-@value{VERSION}.@var{system}.xz.sig
7644 $ gpg --verify guixsd-install-@value{VERSION}.@var{system}.xz.sig
7645 @end example
7646
7647 If that command fails because you do not have the required public key,
7648 then run this command to import it:
7649
7650 @example
7651 $ gpg --keyserver pgp.mit.edu --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
7652 @end example
7653
7654 @noindent
7655 and rerun the @code{gpg --verify} command.
7656 @c end duplication
7657
7658 This image contains the tools necessary for an installation.
7659 It is meant to be copied @emph{as is} to a large-enough USB stick or DVD.
7660
7661 To copy the image to a DVD, follow these steps:
7662
7663 @enumerate
7664 @item
7665 Decompress the image using the @command{xz} command:
7666
7667 @example
7668 xz -d guixsd-install-@value{VERSION}.@var{system}.xz
7669 @end example
7670
7671 @item
7672 Insert a blank DVD into your machine, and determine
7673 its device name. Assuming that the DVD drive is known as @file{/dev/srX},
7674 copy the image with:
7675
7676 @example
7677 growisofs -dvd-compat -Z /dev/srX=guixsd-install-@value{VERSION}.x86_64
7678 @end example
7679
7680 Access to @file{/dev/srX} usually requires root privileges.
7681 @end enumerate
7682
7683 Once this is done, you should be able to reboot the system and boot from
7684 the DVD. The latter usually requires you to get in the BIOS or
7685 UEFI boot menu, where you can choose to boot from the DVD.
7686
7687 @xref{Installing GuixSD in a VM}, if, instead, you would like to install
7688 GuixSD in a virtual machine (VM).
7689
7690 @node Preparing for Installation
7691 @subsection Preparing for Installation
7692
7693 Once you have successfully booted your computer using the installation medium,
7694 you should end up with a root prompt. Several console TTYs are configured
7695 and can be used to run commands as root. TTY2 shows this documentation,
7696 browsable using the Info reader commands (@pxref{Top,,, info-stnd,
7697 Stand-alone GNU Info}). The installation system runs the GPM mouse
7698 daemon, which allows you to select text with the left mouse button and
7699 to paste it with the middle button.
7700
7701 @quotation Note
7702 Installation requires access to the Internet so that any missing
7703 dependencies of your system configuration can be downloaded. See the
7704 ``Networking'' section below.
7705 @end quotation
7706
7707 The installation system includes many common tools needed for this task.
7708 But it is also a full-blown GuixSD system, which means that you can
7709 install additional packages, should you need it, using @command{guix
7710 package} (@pxref{Invoking guix package}).
7711
7712 @subsubsection Keyboard Layout
7713
7714 @cindex keyboard layout
7715 The installation image uses the US qwerty keyboard layout. If you want
7716 to change it, you can use the @command{loadkeys} command. For example,
7717 the following command selects the Dvorak keyboard layout:
7718
7719 @example
7720 loadkeys dvorak
7721 @end example
7722
7723 See the files under @file{/run/current-system/profile/share/keymaps} for
7724 a list of available keyboard layouts. Run @command{man loadkeys} for
7725 more information.
7726
7727 @subsubsection Networking
7728
7729 Run the following command see what your network interfaces are called:
7730
7731 @example
7732 ifconfig -a
7733 @end example
7734
7735 @noindent
7736 @dots{} or, using the GNU/Linux-specific @command{ip} command:
7737
7738 @example
7739 ip a
7740 @end example
7741
7742 @c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
7743 Wired interfaces have a name starting with @samp{e}; for example, the
7744 interface corresponding to the first on-board Ethernet controller is
7745 called @samp{eno1}. Wireless interfaces have a name starting with
7746 @samp{w}, like @samp{w1p2s0}.
7747
7748 @table @asis
7749 @item Wired connection
7750 To configure a wired network run the following command, substituting
7751 @var{interface} with the name of the wired interface you want to use.
7752
7753 @example
7754 ifconfig @var{interface} up
7755 @end example
7756
7757 @item Wireless connection
7758 @cindex wireless
7759 @cindex WiFi
7760 To configure wireless networking, you can create a configuration file
7761 for the @command{wpa_supplicant} configuration tool (its location is not
7762 important) using one of the available text editors such as
7763 @command{zile}:
7764
7765 @example
7766 zile wpa_supplicant.conf
7767 @end example
7768
7769 As an example, the following stanza can go to this file and will work
7770 for many wireless networks, provided you give the actual SSID and
7771 passphrase for the network you are connecting to:
7772
7773 @example
7774 network=@{
7775 ssid="@var{my-ssid}"
7776 key_mgmt=WPA-PSK
7777 psk="the network's secret passphrase"
7778 @}
7779 @end example
7780
7781 Start the wireless service and run it in the background with the
7782 following command (substitute @var{interface} with the name of the
7783 network interface you want to use):
7784
7785 @example
7786 wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
7787 @end example
7788
7789 Run @command{man wpa_supplicant} for more information.
7790 @end table
7791
7792 @cindex DHCP
7793 At this point, you need to acquire an IP address. On a network where IP
7794 addresses are automatically assigned @i{via} DHCP, you can run:
7795
7796 @example
7797 dhclient -v @var{interface}
7798 @end example
7799
7800 Try to ping a server to see if networking is up and running:
7801
7802 @example
7803 ping -c 3 gnu.org
7804 @end example
7805
7806 Setting up network access is almost always a requirement because the
7807 image does not contain all the software and tools that may be needed.
7808
7809 @cindex installing over SSH
7810 If you want to, you can continue the installation remotely by starting
7811 an SSH server:
7812
7813 @example
7814 herd start ssh-daemon
7815 @end example
7816
7817 Make sure to either set a password with @command{passwd}, or configure
7818 OpenSSH public key authentication before logging in.
7819
7820 @subsubsection Disk Partitioning
7821
7822 Unless this has already been done, the next step is to partition, and
7823 then format the target partition(s).
7824
7825 The installation image includes several partitioning tools, including
7826 Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
7827 @command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
7828 the partition layout you want:
7829
7830 @example
7831 cfdisk
7832 @end example
7833
7834 If your disk uses the GUID Partition Table (GPT) format and you plan to
7835 install BIOS-based GRUB (which is the default), make sure a BIOS Boot
7836 Partition is available (@pxref{BIOS installation,,, grub, GNU GRUB
7837 manual}).
7838
7839 @cindex EFI, installation
7840 @cindex UEFI, installation
7841 @cindex ESP, EFI system partition
7842 If you instead wish to use EFI-based GRUB, a FAT32 @dfn{EFI System Partition}
7843 (ESP) is required. This partition should be mounted at @file{/boot/efi} and
7844 must have the @code{esp} flag set. E.g., for @command{parted}:
7845
7846 @example
7847 parted /dev/sda set 1 esp on
7848 @end example
7849
7850 Once you are done partitioning the target hard disk drive, you have to
7851 create a file system on the relevant partition(s)@footnote{Currently
7852 GuixSD only supports ext4 and btrfs file systems. In particular, code
7853 that reads partition UUIDs and labels only works for these file system
7854 types.}.
7855
7856 Preferably, assign partitions a label so that you can easily and
7857 reliably refer to them in @code{file-system} declarations (@pxref{File
7858 Systems}). This is typically done using the @code{-L} option of
7859 @command{mkfs.ext4} and related commands. So, assuming the target root
7860 partition lives at @file{/dev/sda1}, a file system with the label
7861 @code{my-root} can be created with:
7862
7863 @example
7864 mkfs.ext4 -L my-root /dev/sda1
7865 @end example
7866
7867 @cindex encrypted disk
7868 If you are instead planning to encrypt the root partition, you can use
7869 the Cryptsetup/LUKS utilities to do that (see @inlinefmtifelse{html,
7870 @uref{https://linux.die.net/man/8/cryptsetup, @code{man cryptsetup}},
7871 @code{man cryptsetup}} for more information.) Assuming you want to
7872 store the root partition on @file{/dev/sda1}, the command sequence would
7873 be along these lines:
7874
7875 @example
7876 cryptsetup luksFormat /dev/sda1
7877 cryptsetup open --type luks /dev/sda1 my-partition
7878 mkfs.ext4 -L my-root /dev/mapper/my-partition
7879 @end example
7880
7881 Once that is done, mount the target root partition under @file{/mnt}
7882 with a command like (again, assuming @code{my-root} is the label of the
7883 root partition):
7884
7885 @example
7886 mount LABEL=my-root /mnt
7887 @end example
7888
7889 Also mount any other partitions you would like to use on the target
7890 system relative to this path. If you have @file{/boot} on a separate
7891 partition for example, mount it at @file{/mnt/boot} now so it is found
7892 by @code{guix system init} afterwards.
7893
7894 Finally, if you plan to use one or more swap partitions (@pxref{Memory
7895 Concepts, swap space,, libc, The GNU C Library Reference Manual}), make
7896 sure to initialize them with @command{mkswap}. Assuming you have one
7897 swap partition on @file{/dev/sda2}, you would run:
7898
7899 @example
7900 mkswap /dev/sda2
7901 swapon /dev/sda2
7902 @end example
7903
7904 Alternatively, you may use a swap file. For example, assuming that in
7905 the new system you want to use the file @file{/swapfile} as a swap file,
7906 you would run@footnote{This example will work for many types of file
7907 systems (e.g., ext4). However, for copy-on-write file systems (e.g.,
7908 btrfs), the required steps may be different. For details, see the
7909 manual pages for @command{mkswap} and @command{swapon}.}:
7910
7911 @example
7912 # This is 10 GiB of swap space. Adjust "count" to change the size.
7913 dd if=/dev/zero of=/mnt/swapfile bs=1MiB count=10240
7914 # For security, make the file readable and writable only by root.
7915 chmod 600 /mnt/swapfile
7916 mkswap /mnt/swapfile
7917 swapon /mnt/swapfile
7918 @end example
7919
7920 Note that if you have encrypted the root partition and created a swap
7921 file in its file system as described above, then the encryption also
7922 protects the swap file, just like any other file in that file system.
7923
7924 @node Proceeding with the Installation
7925 @subsection Proceeding with the Installation
7926
7927 With the target partitions ready and the target root mounted on
7928 @file{/mnt}, we're ready to go. First, run:
7929
7930 @example
7931 herd start cow-store /mnt
7932 @end example
7933
7934 This makes @file{/gnu/store} copy-on-write, such that packages added to it
7935 during the installation phase are written to the target disk on @file{/mnt}
7936 rather than kept in memory. This is necessary because the first phase of
7937 the @command{guix system init} command (see below) entails downloads or
7938 builds to @file{/gnu/store} which, initially, is an in-memory file system.
7939
7940 Next, you have to edit a file and
7941 provide the declaration of the operating system to be installed. To
7942 that end, the installation system comes with three text editors: GNU nano
7943 (@pxref{Top,,, nano, GNU nano Manual}), GNU Zile (an Emacs clone), and
7944 nvi (a clone of the original BSD @command{vi} editor).
7945 We strongly recommend storing that file on the target root file system, say,
7946 as @file{/mnt/etc/config.scm}. Failing to do that, you will have lost your
7947 configuration file once you have rebooted into the newly-installed system.
7948
7949 @xref{Using the Configuration System}, for an overview of the
7950 configuration file. The example configurations discussed in that
7951 section are available under @file{/etc/configuration} in the
7952 installation image. Thus, to get started with a system configuration
7953 providing a graphical display server (a ``desktop'' system), you can run
7954 something along these lines:
7955
7956 @example
7957 # mkdir /mnt/etc
7958 # cp /etc/configuration/desktop.scm /mnt/etc/config.scm
7959 # zile /mnt/etc/config.scm
7960 @end example
7961
7962 You should pay attention to what your configuration file contains, and
7963 in particular:
7964
7965 @itemize
7966 @item
7967 Make sure the @code{grub-configuration} form refers to the target you
7968 want to install GRUB on. It should mention @code{grub-bootloader} if
7969 you are installing GRUB in the legacy way, or @code{grub-efi-bootloader}
7970 for newer UEFI systems. For legacy systems, the @code{target} field
7971 names a device, like @code{/dev/sda}; for UEFI systems it names a path
7972 to a mounted EFI partition, like @code{/boot/efi}, and do make sure the
7973 path is actually mounted.
7974
7975 @item
7976 Be sure that your partition labels match the value of their respective
7977 @code{device} fields in your @code{file-system} configuration, assuming
7978 your @code{file-system} configuration sets the value of @code{title} to
7979 @code{'label}.
7980
7981 @item
7982 If there are encrypted or RAID partitions, make sure to add a
7983 @code{mapped-devices} field to describe them (@pxref{Mapped Devices}).
7984 @end itemize
7985
7986 Once you are done preparing the configuration file, the new system must
7987 be initialized (remember that the target root file system is mounted
7988 under @file{/mnt}):
7989
7990 @example
7991 guix system init /mnt/etc/config.scm /mnt
7992 @end example
7993
7994 @noindent
7995 This copies all the necessary files and installs GRUB on
7996 @file{/dev/sdX}, unless you pass the @option{--no-bootloader} option. For
7997 more information, @pxref{Invoking guix system}. This command may trigger
7998 downloads or builds of missing packages, which can take some time.
7999
8000 Once that command has completed---and hopefully succeeded!---you can run
8001 @command{reboot} and boot into the new system. The @code{root} password
8002 in the new system is initially empty; other users' passwords need to be
8003 initialized by running the @command{passwd} command as @code{root},
8004 unless your configuration specifies otherwise
8005 (@pxref{user-account-password, user account passwords}).
8006
8007 @cindex upgrading GuixSD
8008 From then on, you can update GuixSD whenever you want by running
8009 @command{guix pull} as @code{root} (@pxref{Invoking guix pull}), and
8010 then running @command{guix system reconfigure} to build a new system
8011 generation with the latest packages and services (@pxref{Invoking guix
8012 system}). We recommend doing that regularly so that your system
8013 includes the latest security updates (@pxref{Security Updates}).
8014
8015 Join us on @code{#guix} on the Freenode IRC network or on
8016 @file{guix-devel@@gnu.org} to share your experience---good or not so
8017 good.
8018
8019 @node Installing GuixSD in a VM
8020 @subsection Installing GuixSD in a Virtual Machine
8021
8022 @cindex virtual machine, GuixSD installation
8023 @cindex virtual private server (VPS)
8024 @cindex VPS (virtual private server)
8025 If you'd like to install GuixSD in a virtual machine (VM) or on a
8026 virtual private server (VPS) rather than on your beloved machine, this
8027 section is for you.
8028
8029 To boot a @uref{http://qemu.org/,QEMU} VM for installing GuixSD in a
8030 disk image, follow these steps:
8031
8032 @enumerate
8033 @item
8034 First, retrieve and decompress the GuixSD installation image as
8035 described previously (@pxref{USB Stick Installation}).
8036
8037 @item
8038 Create a disk image that will hold the installed system. To make a
8039 qcow2-formatted disk image, use the @command{qemu-img} command:
8040
8041 @example
8042 qemu-img create -f qcow2 guixsd.img 50G
8043 @end example
8044
8045 The resulting file will be much smaller than 50 GB (typically less than
8046 1 MB), but it will grow as the virtualized storage device is filled up.
8047
8048 @item
8049 Boot the USB installation image in an VM:
8050
8051 @example
8052 qemu-system-x86_64 -m 1024 -smp 1 \
8053 -net user -net nic,model=virtio -boot menu=on \
8054 -drive file=guixsd-install-@value{VERSION}.@var{system} \
8055 -drive file=guixsd.img
8056 @end example
8057
8058 The ordering of the drives matters.
8059
8060 In the VM console, quickly press the @kbd{F12} key to enter the boot
8061 menu. Then press the @kbd{2} key and the @kbd{RET} key to validate your
8062 selection.
8063
8064 @item
8065 You're now root in the VM, proceed with the installation process.
8066 @xref{Preparing for Installation}, and follow the instructions.
8067 @end enumerate
8068
8069 Once installation is complete, you can boot the system that's on your
8070 @file{guixsd.img} image. @xref{Running GuixSD in a VM}, for how to do
8071 that.
8072
8073 @node Building the Installation Image
8074 @subsection Building the Installation Image
8075
8076 @cindex installation image
8077 The installation image described above was built using the @command{guix
8078 system} command, specifically:
8079
8080 @example
8081 guix system disk-image gnu/system/install.scm
8082 @end example
8083
8084 Have a look at @file{gnu/system/install.scm} in the source tree,
8085 and see also @ref{Invoking guix system} for more information
8086 about the installation image.
8087
8088 @node System Configuration
8089 @section System Configuration
8090
8091 @cindex system configuration
8092 The Guix System Distribution supports a consistent whole-system configuration
8093 mechanism. By that we mean that all aspects of the global system
8094 configuration---such as the available system services, timezone and
8095 locale settings, user accounts---are declared in a single place. Such
8096 a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
8097
8098 One of the advantages of putting all the system configuration under the
8099 control of Guix is that it supports transactional system upgrades, and
8100 makes it possible to roll back to a previous system instantiation,
8101 should something go wrong with the new one (@pxref{Features}). Another
8102 advantage is that it makes it easy to replicate the exact same configuration
8103 across different machines, or at different points in time, without
8104 having to resort to additional administration tools layered on top of
8105 the own tools of the system.
8106 @c Yes, we're talking of Puppet, Chef, & co. here. ↑
8107
8108 This section describes this mechanism. First we focus on the system
8109 administrator's viewpoint---explaining how the system is configured and
8110 instantiated. Then we show how this mechanism can be extended, for
8111 instance to support new system services.
8112
8113 @menu
8114 * Using the Configuration System:: Customizing your GNU system.
8115 * operating-system Reference:: Detail of operating-system declarations.
8116 * File Systems:: Configuring file system mounts.
8117 * Mapped Devices:: Block device extra processing.
8118 * User Accounts:: Specifying user accounts.
8119 * Locales:: Language and cultural convention settings.
8120 * Services:: Specifying system services.
8121 * Setuid Programs:: Programs running with root privileges.
8122 * X.509 Certificates:: Authenticating HTTPS servers.
8123 * Name Service Switch:: Configuring libc's name service switch.
8124 * Initial RAM Disk:: Linux-Libre bootstrapping.
8125 * Bootloader Configuration:: Configuring the boot loader.
8126 * Invoking guix system:: Instantiating a system configuration.
8127 * Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
8128 * Defining Services:: Adding new service definitions.
8129 @end menu
8130
8131 @node Using the Configuration System
8132 @subsection Using the Configuration System
8133
8134 The operating system is configured by providing an
8135 @code{operating-system} declaration in a file that can then be passed to
8136 the @command{guix system} command (@pxref{Invoking guix system}). A
8137 simple setup, with the default system services, the default Linux-Libre
8138 kernel, initial RAM disk, and boot loader looks like this:
8139
8140 @findex operating-system
8141 @lisp
8142 @include os-config-bare-bones.texi
8143 @end lisp
8144
8145 This example should be self-describing. Some of the fields defined
8146 above, such as @code{host-name} and @code{bootloader}, are mandatory.
8147 Others, such as @code{packages} and @code{services}, can be omitted, in
8148 which case they get a default value.
8149
8150 Below we discuss the effect of some of the most important fields
8151 (@pxref{operating-system Reference}, for details about all the available
8152 fields), and how to @dfn{instantiate} the operating system using
8153 @command{guix system}.
8154
8155 @unnumberedsubsubsec Globally-Visible Packages
8156
8157 @vindex %base-packages
8158 The @code{packages} field lists packages that will be globally visible
8159 on the system, for all user accounts---i.e., in every user's @code{PATH}
8160 environment variable---in addition to the per-user profiles
8161 (@pxref{Invoking guix package}). The @var{%base-packages} variable
8162 provides all the tools one would expect for basic user and administrator
8163 tasks---including the GNU Core Utilities, the GNU Networking Utilities,
8164 the GNU Zile lightweight text editor, @command{find}, @command{grep},
8165 etc. The example above adds tcpdump to those, taken from the @code{(gnu
8166 packages admin)} module (@pxref{Package Modules}). The
8167 @code{(list package output)} syntax can be used to add a specific output
8168 of a package:
8169
8170 @lisp
8171 (use-modules (gnu packages))
8172 (use-modules (gnu packages dns))
8173
8174 (operating-system
8175 ;; ...
8176 (packages (cons (list bind "utils")
8177 %base-packages)))
8178 @end lisp
8179
8180 @findex specification->package
8181 Referring to packages by variable name, like @var{tcpdump} above, has
8182 the advantage of being unambiguous; it also allows typos and such to be
8183 diagnosed right away as ``unbound variables''. The downside is that one
8184 needs to know which module defines which package, and to augment the
8185 @code{use-package-modules} line accordingly. To avoid that, one can use
8186 the @code{specification->package} procedure of the @code{(gnu packages)}
8187 module, which returns the best package for a given name or name and
8188 version:
8189
8190 @lisp
8191 (use-modules (gnu packages))
8192
8193 (operating-system
8194 ;; ...
8195 (packages (append (map specification->package
8196 '("tcpdump" "htop" "gnupg@@2.0"))
8197 %base-packages)))
8198 @end lisp
8199
8200 @unnumberedsubsubsec System Services
8201
8202 @cindex services
8203 @vindex %base-services
8204 The @code{services} field lists @dfn{system services} to be made
8205 available when the system starts (@pxref{Services}).
8206 The @code{operating-system} declaration above specifies that, in
8207 addition to the basic services, we want the @command{lshd} secure shell
8208 daemon listening on port 2222 (@pxref{Networking Services,
8209 @code{lsh-service}}). Under the hood,
8210 @code{lsh-service} arranges so that @code{lshd} is started with the
8211 right command-line options, possibly with supporting configuration files
8212 generated as needed (@pxref{Defining Services}).
8213
8214 @cindex customization, of services
8215 @findex modify-services
8216 Occasionally, instead of using the base services as is, you will want to
8217 customize them. To do this, use @code{modify-services} (@pxref{Service
8218 Reference, @code{modify-services}}) to modify the list.
8219
8220 For example, suppose you want to modify @code{guix-daemon} and Mingetty
8221 (the console log-in) in the @var{%base-services} list (@pxref{Base
8222 Services, @code{%base-services}}). To do that, you can write the
8223 following in your operating system declaration:
8224
8225 @lisp
8226 (define %my-services
8227 ;; My very own list of services.
8228 (modify-services %base-services
8229 (guix-service-type config =>
8230 (guix-configuration
8231 (inherit config)
8232 (use-substitutes? #f)
8233 (extra-options '("--gc-keep-derivations"))))
8234 (mingetty-service-type config =>
8235 (mingetty-configuration
8236 (inherit config)))))
8237
8238 (operating-system
8239 ;; @dots{}
8240 (services %my-services))
8241 @end lisp
8242
8243 This changes the configuration---i.e., the service parameters---of the
8244 @code{guix-service-type} instance, and that of all the
8245 @code{mingetty-service-type} instances in the @var{%base-services} list.
8246 Observe how this is accomplished: first, we arrange for the original
8247 configuration to be bound to the identifier @code{config} in the
8248 @var{body}, and then we write the @var{body} so that it evaluates to the
8249 desired configuration. In particular, notice how we use @code{inherit}
8250 to create a new configuration which has the same values as the old
8251 configuration, but with a few modifications.
8252
8253 @cindex encrypted disk
8254 The configuration for a typical ``desktop'' usage, with an encrypted
8255 root partition, the X11 display
8256 server, GNOME and Xfce (users can choose which of these desktop
8257 environments to use at the log-in screen by pressing @kbd{F1}), network
8258 management, power management, and more, would look like this:
8259
8260 @lisp
8261 @include os-config-desktop.texi
8262 @end lisp
8263
8264 A graphical UEFI system with a choice of lightweight window managers
8265 instead of full-blown desktop environments would look like this:
8266
8267 @lisp
8268 @include os-config-lightweight-desktop.texi
8269 @end lisp
8270
8271 @xref{Desktop Services}, for the exact list of services provided by
8272 @var{%desktop-services}. @xref{X.509 Certificates}, for background
8273 information about the @code{nss-certs} package that is used here.
8274
8275 Again, @var{%desktop-services} is just a list of service objects. If
8276 you want to remove services from there, you can do so using the
8277 procedures for list filtering (@pxref{SRFI-1 Filtering and
8278 Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
8279 following expression returns a list that contains all the services in
8280 @var{%desktop-services} minus the Avahi service:
8281
8282 @example
8283 (remove (lambda (service)
8284 (eq? (service-kind service) avahi-service-type))
8285 %desktop-services)
8286 @end example
8287
8288 @unnumberedsubsubsec Instantiating the System
8289
8290 Assuming the @code{operating-system} declaration
8291 is stored in the @file{my-system-config.scm}
8292 file, the @command{guix system reconfigure my-system-config.scm} command
8293 instantiates that configuration, and makes it the default GRUB boot
8294 entry (@pxref{Invoking guix system}).
8295
8296 The normal way to change the system configuration is by updating this
8297 file and re-running @command{guix system reconfigure}. One should never
8298 have to touch files in @file{/etc} or to run commands that modify the
8299 system state such as @command{useradd} or @command{grub-install}. In
8300 fact, you must avoid that since that would not only void your warranty
8301 but also prevent you from rolling back to previous versions of your
8302 system, should you ever need to.
8303
8304 @cindex roll-back, of the operating system
8305 Speaking of roll-back, each time you run @command{guix system
8306 reconfigure}, a new @dfn{generation} of the system is created---without
8307 modifying or deleting previous generations. Old system generations get
8308 an entry in the bootloader boot menu, allowing you to boot them in case
8309 something went wrong with the latest generation. Reassuring, no? The
8310 @command{guix system list-generations} command lists the system
8311 generations available on disk. It is also possible to roll back the
8312 system via the commands @command{guix system roll-back} and
8313 @command{guix system switch-generation}.
8314
8315 Although the command @command{guix system reconfigure} will not modify
8316 previous generations, must take care when the current generation is not
8317 the latest (e.g., after invoking @command{guix system roll-back}), since
8318 the operation might overwrite a later generation (@pxref{Invoking guix
8319 system}).
8320
8321 @unnumberedsubsubsec The Programming Interface
8322
8323 At the Scheme level, the bulk of an @code{operating-system} declaration
8324 is instantiated with the following monadic procedure (@pxref{The Store
8325 Monad}):
8326
8327 @deffn {Monadic Procedure} operating-system-derivation os
8328 Return a derivation that builds @var{os}, an @code{operating-system}
8329 object (@pxref{Derivations}).
8330
8331 The output of the derivation is a single directory that refers to all
8332 the packages, configuration files, and other supporting files needed to
8333 instantiate @var{os}.
8334 @end deffn
8335
8336 This procedure is provided by the @code{(gnu system)} module. Along
8337 with @code{(gnu services)} (@pxref{Services}), this module contains the
8338 guts of GuixSD. Make sure to visit it!
8339
8340
8341 @node operating-system Reference
8342 @subsection @code{operating-system} Reference
8343
8344 This section summarizes all the options available in
8345 @code{operating-system} declarations (@pxref{Using the Configuration
8346 System}).
8347
8348 @deftp {Data Type} operating-system
8349 This is the data type representing an operating system configuration.
8350 By that, we mean all the global system configuration, not per-user
8351 configuration (@pxref{Using the Configuration System}).
8352
8353 @table @asis
8354 @item @code{kernel} (default: @var{linux-libre})
8355 The package object of the operating system kernel to use@footnote{Currently
8356 only the Linux-libre kernel is supported. In the future, it will be
8357 possible to use the GNU@tie{}Hurd.}.
8358
8359 @item @code{kernel-arguments} (default: @code{'()})
8360 List of strings or gexps representing additional arguments to pass on
8361 the command-line of the kernel---e.g., @code{("console=ttyS0")}.
8362
8363 @item @code{bootloader}
8364 The system bootloader configuration object. @xref{Bootloader Configuration}.
8365
8366 @item @code{initrd} (default: @code{base-initrd})
8367 @cindex initrd
8368 @cindex initial RAM disk
8369 A two-argument monadic procedure that returns an initial RAM disk for
8370 the Linux kernel. @xref{Initial RAM Disk}.
8371
8372 @item @code{firmware} (default: @var{%base-firmware})
8373 @cindex firmware
8374 List of firmware packages loadable by the operating system kernel.
8375
8376 The default includes firmware needed for Atheros- and Broadcom-based
8377 WiFi devices (Linux-libre modules @code{ath9k} and @code{b43-open},
8378 respectively). @xref{Hardware Considerations}, for more info on
8379 supported hardware.
8380
8381 @item @code{host-name}
8382 The host name.
8383
8384 @item @code{hosts-file}
8385 @cindex hosts file
8386 A file-like object (@pxref{G-Expressions, file-like objects}) for use as
8387 @file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
8388 Reference Manual}). The default is a file with entries for
8389 @code{localhost} and @var{host-name}.
8390
8391 @item @code{mapped-devices} (default: @code{'()})
8392 A list of mapped devices. @xref{Mapped Devices}.
8393
8394 @item @code{file-systems}
8395 A list of file systems. @xref{File Systems}.
8396
8397 @item @code{swap-devices} (default: @code{'()})
8398 @cindex swap devices
8399 A list of strings identifying devices or files to be used for ``swap
8400 space'' (@pxref{Memory Concepts,,, libc, The GNU C Library Reference
8401 Manual}). For example, @code{'("/dev/sda3")} or @code{'("/swapfile")}.
8402 It is possible to specify a swap file in a file system on a mapped
8403 device, provided that the necessary device mapping and file system are
8404 also specified. @xref{Mapped Devices} and @ref{File Systems}.
8405
8406 @item @code{users} (default: @code{%base-user-accounts})
8407 @itemx @code{groups} (default: @var{%base-groups})
8408 List of user accounts and groups. @xref{User Accounts}.
8409
8410 @item @code{skeletons} (default: @code{(default-skeletons)})
8411 A list target file name/file-like object tuples (@pxref{G-Expressions,
8412 file-like objects}). These are the skeleton files that will be added to
8413 the home directory of newly-created user accounts.
8414
8415 For instance, a valid value may look like this:
8416
8417 @example
8418 `((".bashrc" ,(plain-file "bashrc" "echo Hello\n"))
8419 (".guile" ,(plain-file "guile"
8420 "(use-modules (ice-9 readline))
8421 (activate-readline)")))
8422 @end example
8423
8424 @item @code{issue} (default: @var{%default-issue})
8425 A string denoting the contents of the @file{/etc/issue} file, which is
8426 displayed when users log in on a text console.
8427
8428 @item @code{packages} (default: @var{%base-packages})
8429 The set of packages installed in the global profile, which is accessible
8430 at @file{/run/current-system/profile}.
8431
8432 The default set includes core utilities and it is good practice to
8433 install non-core utilities in user profiles (@pxref{Invoking guix
8434 package}).
8435
8436 @item @code{timezone}
8437 A timezone identifying string---e.g., @code{"Europe/Paris"}.
8438
8439 You can run the @command{tzselect} command to find out which timezone
8440 string corresponds to your region. Choosing an invalid timezone name
8441 causes @command{guix system} to fail.
8442
8443 @item @code{locale} (default: @code{"en_US.utf8"})
8444 The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
8445 Library Reference Manual}). @xref{Locales}, for more information.
8446
8447 @item @code{locale-definitions} (default: @var{%default-locale-definitions})
8448 The list of locale definitions to be compiled and that may be used at
8449 run time. @xref{Locales}.
8450
8451 @item @code{locale-libcs} (default: @code{(list @var{glibc})})
8452 The list of GNU@tie{}libc packages whose locale data and tools are used
8453 to build the locale definitions. @xref{Locales}, for compatibility
8454 considerations that justify this option.
8455
8456 @item @code{name-service-switch} (default: @var{%default-nss})
8457 Configuration of the libc name service switch (NSS)---a
8458 @code{<name-service-switch>} object. @xref{Name Service Switch}, for
8459 details.
8460
8461 @item @code{services} (default: @var{%base-services})
8462 A list of service objects denoting system services. @xref{Services}.
8463
8464 @item @code{pam-services} (default: @code{(base-pam-services)})
8465 @cindex PAM
8466 @cindex pluggable authentication modules
8467 Linux @dfn{pluggable authentication module} (PAM) services.
8468 @c FIXME: Add xref to PAM services section.
8469
8470 @item @code{setuid-programs} (default: @var{%setuid-programs})
8471 List of string-valued G-expressions denoting setuid programs.
8472 @xref{Setuid Programs}.
8473
8474 @item @code{sudoers-file} (default: @var{%sudoers-specification})
8475 @cindex sudoers file
8476 The contents of the @file{/etc/sudoers} file as a file-like object
8477 (@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
8478
8479 This file specifies which users can use the @command{sudo} command, what
8480 they are allowed to do, and what privileges they may gain. The default
8481 is that only @code{root} and members of the @code{wheel} group may use
8482 @code{sudo}.
8483
8484 @end table
8485 @end deftp
8486
8487 @node File Systems
8488 @subsection File Systems
8489
8490 The list of file systems to be mounted is specified in the
8491 @code{file-systems} field of the operating system declaration
8492 (@pxref{Using the Configuration System}). Each file system is declared
8493 using the @code{file-system} form, like this:
8494
8495 @example
8496 (file-system
8497 (mount-point "/home")
8498 (device "/dev/sda3")
8499 (type "ext4"))
8500 @end example
8501
8502 As usual, some of the fields are mandatory---those shown in the example
8503 above---while others can be omitted. These are described below.
8504
8505 @deftp {Data Type} file-system
8506 Objects of this type represent file systems to be mounted. They
8507 contain the following members:
8508
8509 @table @asis
8510 @item @code{type}
8511 This is a string specifying the type of the file system---e.g.,
8512 @code{"ext4"}.
8513
8514 @item @code{mount-point}
8515 This designates the place where the file system is to be mounted.
8516
8517 @item @code{device}
8518 This names the ``source'' of the file system. By default it is the name
8519 of a node under @file{/dev}, but its meaning depends on the @code{title}
8520 field described below.
8521
8522 @item @code{title} (default: @code{'device})
8523 This is a symbol that specifies how the @code{device} field is to be
8524 interpreted.
8525
8526 When it is the symbol @code{device}, then the @code{device} field is
8527 interpreted as a file name; when it is @code{label}, then @code{device}
8528 is interpreted as a partition label name; when it is @code{uuid},
8529 @code{device} is interpreted as a partition unique identifier (UUID).
8530
8531 UUIDs may be converted from their string representation (as shown by the
8532 @command{tune2fs -l} command) using the @code{uuid} form@footnote{The
8533 @code{uuid} form expects 16-byte UUIDs as defined in
8534 @uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
8535 form of UUID used by the ext2 family of file systems and others, but it
8536 is different from ``UUIDs'' found in FAT file systems, for instance.},
8537 like this:
8538
8539 @example
8540 (file-system
8541 (mount-point "/home")
8542 (type "ext4")
8543 (title 'uuid)
8544 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
8545 @end example
8546
8547 The @code{label} and @code{uuid} options offer a way to refer to disk
8548 partitions without having to hard-code their actual device
8549 name@footnote{Note that, while it is tempting to use
8550 @file{/dev/disk/by-uuid} and similar device names to achieve the same
8551 result, this is not recommended: These special device nodes are created
8552 by the udev daemon and may be unavailable at the time the device is
8553 mounted.}.
8554
8555 However, when the source of a file system is a mapped device (@pxref{Mapped
8556 Devices}), its @code{device} field @emph{must} refer to the mapped
8557 device name---e.g., @file{/dev/mapper/root-partition}---and consequently
8558 @code{title} must be set to @code{'device}. This is required so that
8559 the system knows that mounting the file system depends on having the
8560 corresponding device mapping established.
8561
8562 @item @code{flags} (default: @code{'()})
8563 This is a list of symbols denoting mount flags. Recognized flags
8564 include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
8565 access to special files), @code{no-suid} (ignore setuid and setgid
8566 bits), and @code{no-exec} (disallow program execution.)
8567
8568 @item @code{options} (default: @code{#f})
8569 This is either @code{#f}, or a string denoting mount options.
8570
8571 @item @code{mount?} (default: @code{#t})
8572 This value indicates whether to automatically mount the file system when
8573 the system is brought up. When set to @code{#f}, the file system gets
8574 an entry in @file{/etc/fstab} (read by the @command{mount} command) but
8575 is not automatically mounted.
8576
8577 @item @code{needed-for-boot?} (default: @code{#f})
8578 This Boolean value indicates whether the file system is needed when
8579 booting. If that is true, then the file system is mounted when the
8580 initial RAM disk (initrd) is loaded. This is always the case, for
8581 instance, for the root file system.
8582
8583 @item @code{check?} (default: @code{#t})
8584 This Boolean indicates whether the file system needs to be checked for
8585 errors before being mounted.
8586
8587 @item @code{create-mount-point?} (default: @code{#f})
8588 When true, the mount point is created if it does not exist yet.
8589
8590 @item @code{dependencies} (default: @code{'()})
8591 This is a list of @code{<file-system>} or @code{<mapped-device>} objects
8592 representing file systems that must be mounted or mapped devices that
8593 must be opened before (and unmounted or closed after) this one.
8594
8595 As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
8596 a dependency of @file{/sys/fs/cgroup/cpu} and
8597 @file{/sys/fs/cgroup/memory}.
8598
8599 Another example is a file system that depends on a mapped device, for
8600 example for an encrypted partition (@pxref{Mapped Devices}).
8601 @end table
8602 @end deftp
8603
8604 The @code{(gnu system file-systems)} exports the following useful
8605 variables.
8606
8607 @defvr {Scheme Variable} %base-file-systems
8608 These are essential file systems that are required on normal systems,
8609 such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
8610 below.) Operating system declarations should always contain at least
8611 these.
8612 @end defvr
8613
8614 @defvr {Scheme Variable} %pseudo-terminal-file-system
8615 This is the file system to be mounted as @file{/dev/pts}. It supports
8616 @dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
8617 functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
8618 Manual}). Pseudo-terminals are used by terminal emulators such as
8619 @command{xterm}.
8620 @end defvr
8621
8622 @defvr {Scheme Variable} %shared-memory-file-system
8623 This file system is mounted as @file{/dev/shm} and is used to support
8624 memory sharing across processes (@pxref{Memory-mapped I/O,
8625 @code{shm_open},, libc, The GNU C Library Reference Manual}).
8626 @end defvr
8627
8628 @defvr {Scheme Variable} %immutable-store
8629 This file system performs a read-only ``bind mount'' of
8630 @file{/gnu/store}, making it read-only for all the users including
8631 @code{root}. This prevents against accidental modification by software
8632 running as @code{root} or by system administrators.
8633
8634 The daemon itself is still able to write to the store: it remounts it
8635 read-write in its own ``name space.''
8636 @end defvr
8637
8638 @defvr {Scheme Variable} %binary-format-file-system
8639 The @code{binfmt_misc} file system, which allows handling of arbitrary
8640 executable file types to be delegated to user space. This requires the
8641 @code{binfmt.ko} kernel module to be loaded.
8642 @end defvr
8643
8644 @defvr {Scheme Variable} %fuse-control-file-system
8645 The @code{fusectl} file system, which allows unprivileged users to mount
8646 and unmount user-space FUSE file systems. This requires the
8647 @code{fuse.ko} kernel module to be loaded.
8648 @end defvr
8649
8650 @node Mapped Devices
8651 @subsection Mapped Devices
8652
8653 @cindex device mapping
8654 @cindex mapped devices
8655 The Linux kernel has a notion of @dfn{device mapping}: a block device,
8656 such as a hard disk partition, can be @dfn{mapped} into another device,
8657 usually in @code{/dev/mapper/},
8658 with additional processing over the data that flows through
8659 it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
8660 concept of a ``mapped device'' and that of a file system: both boil down
8661 to @emph{translating} input/output operations made on a file to
8662 operations on its backing store. Thus, the Hurd implements mapped
8663 devices, like file systems, using the generic @dfn{translator} mechanism
8664 (@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
8665 typical example is encryption device mapping: all writes to the mapped
8666 device are encrypted, and all reads are deciphered, transparently.
8667 Guix extends this notion by considering any device or set of devices that
8668 are @dfn{transformed} in some way to create a new device; for instance,
8669 RAID devices are obtained by @dfn{assembling} several other devices, such
8670 as hard disks or partitions, into a new one that behaves as one partition.
8671 Other examples, not yet implemented, are LVM logical volumes.
8672
8673 Mapped devices are declared using the @code{mapped-device} form,
8674 defined as follows; for examples, see below.
8675
8676 @deftp {Data Type} mapped-device
8677 Objects of this type represent device mappings that will be made when
8678 the system boots up.
8679
8680 @table @code
8681 @item source
8682 This is either a string specifying the name of the block device to be mapped,
8683 such as @code{"/dev/sda3"}, or a list of such strings when several devices
8684 need to be assembled for creating a new one.
8685
8686 @item target
8687 This string specifies the name of the resulting mapped device. For
8688 kernel mappers such as encrypted devices of type @code{luks-device-mapping},
8689 specifying @code{"my-partition"} leads to the creation of
8690 the @code{"/dev/mapper/my-partition"} device.
8691 For RAID devices of type @code{raid-device-mapping}, the full device name
8692 such as @code{"/dev/md0"} needs to be given.
8693
8694 @item type
8695 This must be a @code{mapped-device-kind} object, which specifies how
8696 @var{source} is mapped to @var{target}.
8697 @end table
8698 @end deftp
8699
8700 @defvr {Scheme Variable} luks-device-mapping
8701 This defines LUKS block device encryption using the @command{cryptsetup}
8702 command from the package with the same name. It relies on the
8703 @code{dm-crypt} Linux kernel module.
8704 @end defvr
8705
8706 @defvr {Scheme Variable} raid-device-mapping
8707 This defines a RAID device, which is assembled using the @code{mdadm}
8708 command from the package with the same name. It requires a Linux kernel
8709 module for the appropriate RAID level to be loaded, such as @code{raid456}
8710 for RAID-4, RAID-5 or RAID-6, or @code{raid10} for RAID-10.
8711 @end defvr
8712
8713 @cindex disk encryption
8714 @cindex LUKS
8715 The following example specifies a mapping from @file{/dev/sda3} to
8716 @file{/dev/mapper/home} using LUKS---the
8717 @url{https://gitlab.com/cryptsetup/cryptsetup,Linux Unified Key Setup}, a
8718 standard mechanism for disk encryption.
8719 The @file{/dev/mapper/home}
8720 device can then be used as the @code{device} of a @code{file-system}
8721 declaration (@pxref{File Systems}).
8722
8723 @example
8724 (mapped-device
8725 (source "/dev/sda3")
8726 (target "home")
8727 (type luks-device-mapping))
8728 @end example
8729
8730 Alternatively, to become independent of device numbering, one may obtain
8731 the LUKS UUID (@dfn{unique identifier}) of the source device by a
8732 command like:
8733
8734 @example
8735 cryptsetup luksUUID /dev/sda3
8736 @end example
8737
8738 and use it as follows:
8739
8740 @example
8741 (mapped-device
8742 (source (uuid "cb67fc72-0d54-4c88-9d4b-b225f30b0f44"))
8743 (target "home")
8744 (type luks-device-mapping))
8745 @end example
8746
8747 @cindex swap encryption
8748 It is also desirable to encrypt swap space, since swap space may contain
8749 sensitive data. One way to accomplish that is to use a swap file in a
8750 file system on a device mapped via LUKS encryption. In this way, the
8751 swap file is encrypted because the entire device is encrypted.
8752 @xref{Preparing for Installation,,Disk Partitioning}, for an example.
8753
8754 A RAID device formed of the partitions @file{/dev/sda1} and @file{/dev/sdb1}
8755 may be declared as follows:
8756
8757 @example
8758 (mapped-device
8759 (source (list "/dev/sda1" "/dev/sdb1"))
8760 (target "/dev/md0")
8761 (type raid-device-mapping))
8762 @end example
8763
8764 The @file{/dev/md0} device can then be used as the @code{device} of a
8765 @code{file-system} declaration (@pxref{File Systems}).
8766 Note that the RAID level need not be given; it is chosen during the
8767 initial creation and formatting of the RAID device and is determined
8768 automatically later.
8769
8770
8771 @node User Accounts
8772 @subsection User Accounts
8773
8774 @cindex users
8775 @cindex accounts
8776 @cindex user accounts
8777 User accounts and groups are entirely managed through the
8778 @code{operating-system} declaration. They are specified with the
8779 @code{user-account} and @code{user-group} forms:
8780
8781 @example
8782 (user-account
8783 (name "alice")
8784 (group "users")
8785 (supplementary-groups '("wheel" ;allow use of sudo, etc.
8786 "audio" ;sound card
8787 "video" ;video devices such as webcams
8788 "cdrom")) ;the good ol' CD-ROM
8789 (comment "Bob's sister")
8790 (home-directory "/home/alice"))
8791 @end example
8792
8793 When booting or upon completion of @command{guix system reconfigure},
8794 the system ensures that only the user accounts and groups specified in
8795 the @code{operating-system} declaration exist, and with the specified
8796 properties. Thus, account or group creations or modifications made by
8797 directly invoking commands such as @command{useradd} are lost upon
8798 reconfiguration or reboot. This ensures that the system remains exactly
8799 as declared.
8800
8801 @deftp {Data Type} user-account
8802 Objects of this type represent user accounts. The following members may
8803 be specified:
8804
8805 @table @asis
8806 @item @code{name}
8807 The name of the user account.
8808
8809 @item @code{group}
8810 @cindex groups
8811 This is the name (a string) or identifier (a number) of the user group
8812 this account belongs to.
8813
8814 @item @code{supplementary-groups} (default: @code{'()})
8815 Optionally, this can be defined as a list of group names that this
8816 account belongs to.
8817
8818 @item @code{uid} (default: @code{#f})
8819 This is the user ID for this account (a number), or @code{#f}. In the
8820 latter case, a number is automatically chosen by the system when the
8821 account is created.
8822
8823 @item @code{comment} (default: @code{""})
8824 A comment about the account, such as the account owner's full name.
8825
8826 @item @code{home-directory}
8827 This is the name of the home directory for the account.
8828
8829 @item @code{create-home-directory?} (default: @code{#t})
8830 Indicates whether the home directory of this account should be created
8831 if it does not exist yet.
8832
8833 @item @code{shell} (default: Bash)
8834 This is a G-expression denoting the file name of a program to be used as
8835 the shell (@pxref{G-Expressions}).
8836
8837 @item @code{system?} (default: @code{#f})
8838 This Boolean value indicates whether the account is a ``system''
8839 account. System accounts are sometimes treated specially; for instance,
8840 graphical login managers do not list them.
8841
8842 @anchor{user-account-password}
8843 @item @code{password} (default: @code{#f})
8844 You would normally leave this field to @code{#f}, initialize user
8845 passwords as @code{root} with the @command{passwd} command, and then let
8846 users change it with @command{passwd}. Passwords set with
8847 @command{passwd} are of course preserved across reboot and
8848 reconfiguration.
8849
8850 If you @emph{do} want to have a preset password for an account, then
8851 this field must contain the encrypted password, as a string.
8852 @xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
8853 on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
8854 Manual}, for information on Guile's @code{crypt} procedure.
8855
8856 @end table
8857 @end deftp
8858
8859 @cindex groups
8860 User group declarations are even simpler:
8861
8862 @example
8863 (user-group (name "students"))
8864 @end example
8865
8866 @deftp {Data Type} user-group
8867 This type is for, well, user groups. There are just a few fields:
8868
8869 @table @asis
8870 @item @code{name}
8871 The name of the group.
8872
8873 @item @code{id} (default: @code{#f})
8874 The group identifier (a number). If @code{#f}, a new number is
8875 automatically allocated when the group is created.
8876
8877 @item @code{system?} (default: @code{#f})
8878 This Boolean value indicates whether the group is a ``system'' group.
8879 System groups have low numerical IDs.
8880
8881 @item @code{password} (default: @code{#f})
8882 What, user groups can have a password? Well, apparently yes. Unless
8883 @code{#f}, this field specifies the password of the group.
8884
8885 @end table
8886 @end deftp
8887
8888 For convenience, a variable lists all the basic user groups one may
8889 expect:
8890
8891 @defvr {Scheme Variable} %base-groups
8892 This is the list of basic user groups that users and/or packages expect
8893 to be present on the system. This includes groups such as ``root'',
8894 ``wheel'', and ``users'', as well as groups used to control access to
8895 specific devices such as ``audio'', ``disk'', and ``cdrom''.
8896 @end defvr
8897
8898 @defvr {Scheme Variable} %base-user-accounts
8899 This is the list of basic system accounts that programs may expect to
8900 find on a GNU/Linux system, such as the ``nobody'' account.
8901
8902 Note that the ``root'' account is not included here. It is a
8903 special-case and is automatically added whether or not it is specified.
8904 @end defvr
8905
8906 @node Locales
8907 @subsection Locales
8908
8909 @cindex locale
8910 A @dfn{locale} defines cultural conventions for a particular language
8911 and region of the world (@pxref{Locales,,, libc, The GNU C Library
8912 Reference Manual}). Each locale has a name that typically has the form
8913 @code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
8914 @code{fr_LU.utf8} designates the locale for the French language, with
8915 cultural conventions from Luxembourg, and using the UTF-8 encoding.
8916
8917 @cindex locale definition
8918 Usually, you will want to specify the default locale for the machine
8919 using the @code{locale} field of the @code{operating-system} declaration
8920 (@pxref{operating-system Reference, @code{locale}}).
8921
8922 The selected locale is automatically added to the @dfn{locale
8923 definitions} known to the system if needed, with its codeset inferred
8924 from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
8925 @code{UTF-8} codeset. Additional locale definitions can be specified in
8926 the @code{locale-definitions} slot of @code{operating-system}---this is
8927 useful, for instance, if the codeset could not be inferred from the
8928 locale name. The default set of locale definitions includes some widely
8929 used locales, but not all the available locales, in order to save space.
8930
8931 For instance, to add the North Frisian locale for Germany, the value of
8932 that field may be:
8933
8934 @example
8935 (cons (locale-definition
8936 (name "fy_DE.utf8") (source "fy_DE"))
8937 %default-locale-definitions)
8938 @end example
8939
8940 Likewise, to save space, one might want @code{locale-definitions} to
8941 list only the locales that are actually used, as in:
8942
8943 @example
8944 (list (locale-definition
8945 (name "ja_JP.eucjp") (source "ja_JP")
8946 (charset "EUC-JP")))
8947 @end example
8948
8949 @vindex LOCPATH
8950 The compiled locale definitions are available at
8951 @file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
8952 version, which is the default location where the GNU@tie{}libc provided
8953 by Guix looks for locale data. This can be overridden using the
8954 @code{LOCPATH} environment variable (@pxref{locales-and-locpath,
8955 @code{LOCPATH} and locale packages}).
8956
8957 The @code{locale-definition} form is provided by the @code{(gnu system
8958 locale)} module. Details are given below.
8959
8960 @deftp {Data Type} locale-definition
8961 This is the data type of a locale definition.
8962
8963 @table @asis
8964
8965 @item @code{name}
8966 The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
8967 Reference Manual}, for more information on locale names.
8968
8969 @item @code{source}
8970 The name of the source for that locale. This is typically the
8971 @code{@var{language}_@var{territory}} part of the locale name.
8972
8973 @item @code{charset} (default: @code{"UTF-8"})
8974 The ``character set'' or ``code set'' for that locale,
8975 @uref{http://www.iana.org/assignments/character-sets, as defined by
8976 IANA}.
8977
8978 @end table
8979 @end deftp
8980
8981 @defvr {Scheme Variable} %default-locale-definitions
8982 A list of commonly used UTF-8 locales, used as the default
8983 value of the @code{locale-definitions} field of @code{operating-system}
8984 declarations.
8985
8986 @cindex locale name
8987 @cindex normalized codeset in locale names
8988 These locale definitions use the @dfn{normalized codeset} for the part
8989 that follows the dot in the name (@pxref{Using gettextized software,
8990 normalized codeset,, libc, The GNU C Library Reference Manual}). So for
8991 instance it has @code{uk_UA.utf8} but @emph{not}, say,
8992 @code{uk_UA.UTF-8}.
8993 @end defvr
8994
8995 @subsubsection Locale Data Compatibility Considerations
8996
8997 @cindex incompatibility, of locale data
8998 @code{operating-system} declarations provide a @code{locale-libcs} field
8999 to specify the GNU@tie{}libc packages that are used to compile locale
9000 declarations (@pxref{operating-system Reference}). ``Why would I
9001 care?'', you may ask. Well, it turns out that the binary format of
9002 locale data is occasionally incompatible from one libc version to
9003 another.
9004
9005 @c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
9006 @c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
9007 For instance, a program linked against libc version 2.21 is unable to
9008 read locale data produced with libc 2.22; worse, that program
9009 @emph{aborts} instead of simply ignoring the incompatible locale
9010 data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
9011 the incompatible locale data, which is already an improvement.}.
9012 Similarly, a program linked against libc 2.22 can read most, but not
9013 all, of the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
9014 data is incompatible); thus calls to @code{setlocale} may fail, but
9015 programs will not abort.
9016
9017 The ``problem'' in GuixSD is that users have a lot of freedom: They can
9018 choose whether and when to upgrade software in their profiles, and might
9019 be using a libc version different from the one the system administrator
9020 used to build the system-wide locale data.
9021
9022 Fortunately, unprivileged users can also install their own locale data
9023 and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
9024 @code{GUIX_LOCPATH} and locale packages}).
9025
9026 Still, it is best if the system-wide locale data at
9027 @file{/run/current-system/locale} is built for all the libc versions
9028 actually in use on the system, so that all the programs can access
9029 it---this is especially crucial on a multi-user system. To do that, the
9030 administrator can specify several libc packages in the
9031 @code{locale-libcs} field of @code{operating-system}:
9032
9033 @example
9034 (use-package-modules base)
9035
9036 (operating-system
9037 ;; @dots{}
9038 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
9039 @end example
9040
9041 This example would lead to a system containing locale definitions for
9042 both libc 2.21 and the current version of libc in
9043 @file{/run/current-system/locale}.
9044
9045
9046 @node Services
9047 @subsection Services
9048
9049 @cindex system services
9050 An important part of preparing an @code{operating-system} declaration is
9051 listing @dfn{system services} and their configuration (@pxref{Using the
9052 Configuration System}). System services are typically daemons launched
9053 when the system boots, or other actions needed at that time---e.g.,
9054 configuring network access.
9055
9056 GuixSD has a broad definition of ``service'' (@pxref{Service
9057 Composition}), but many services are managed by the GNU@tie{}Shepherd
9058 (@pxref{Shepherd Services}). On a running system, the @command{herd}
9059 command allows you to list the available services, show their status,
9060 start and stop them, or do other specific operations (@pxref{Jump
9061 Start,,, shepherd, The GNU Shepherd Manual}). For example:
9062
9063 @example
9064 # herd status
9065 @end example
9066
9067 The above command, run as @code{root}, lists the currently defined
9068 services. The @command{herd doc} command shows a synopsis of the given
9069 service:
9070
9071 @example
9072 # herd doc nscd
9073 Run libc's name service cache daemon (nscd).
9074 @end example
9075
9076 The @command{start}, @command{stop}, and @command{restart} sub-commands
9077 have the effect you would expect. For instance, the commands below stop
9078 the nscd service and restart the Xorg display server:
9079
9080 @example
9081 # herd stop nscd
9082 Service nscd has been stopped.
9083 # herd restart xorg-server
9084 Service xorg-server has been stopped.
9085 Service xorg-server has been started.
9086 @end example
9087
9088 The following sections document the available services, starting with
9089 the core services, that may be used in an @code{operating-system}
9090 declaration.
9091
9092 @menu
9093 * Base Services:: Essential system services.
9094 * Scheduled Job Execution:: The mcron service.
9095 * Log Rotation:: The rottlog service.
9096 * Networking Services:: Network setup, SSH daemon, etc.
9097 * X Window:: Graphical display.
9098 * Printing Services:: Local and remote printer support.
9099 * Desktop Services:: D-Bus and desktop services.
9100 * Database Services:: SQL databases, key-value stores, etc.
9101 * Mail Services:: IMAP, POP3, SMTP, and all that.
9102 * Messaging Services:: Messaging services.
9103 * Monitoring Services:: Monitoring services.
9104 * Kerberos Services:: Kerberos services.
9105 * Web Services:: Web servers.
9106 * DNS Services:: DNS daemons.
9107 * VPN Services:: VPN daemons.
9108 * Network File System:: NFS related services.
9109 * Continuous Integration:: The Cuirass service.
9110 * Power management Services:: The TLP tool.
9111 * Audio Services:: The MPD.
9112 * Virtualization Services:: Virtualization services.
9113 * Miscellaneous Services:: Other services.
9114 @end menu
9115
9116 @node Base Services
9117 @subsubsection Base Services
9118
9119 The @code{(gnu services base)} module provides definitions for the basic
9120 services that one expects from the system. The services exported by
9121 this module are listed below.
9122
9123 @defvr {Scheme Variable} %base-services
9124 This variable contains a list of basic services (@pxref{Service Types
9125 and Services}, for more information on service objects) one would
9126 expect from the system: a login service (mingetty) on each tty, syslogd,
9127 the libc name service cache daemon (nscd), the udev device manager, and
9128 more.
9129
9130 This is the default value of the @code{services} field of
9131 @code{operating-system} declarations. Usually, when customizing a
9132 system, you will want to append services to @var{%base-services}, like
9133 this:
9134
9135 @example
9136 (cons* (avahi-service) (lsh-service) %base-services)
9137 @end example
9138 @end defvr
9139
9140 @defvr {Scheme Variable} special-files-service-type
9141 This is the service that sets up ``special files'' such as
9142 @file{/bin/sh}; an instance of it is part of @code{%base-services}.
9143
9144 The value associated with @code{special-files-service-type} services
9145 must be a list of tuples where the first element is the ``special file''
9146 and the second element is its target. By default it is:
9147
9148 @cindex @file{/bin/sh}
9149 @cindex @file{sh}, in @file{/bin}
9150 @example
9151 `(("/bin/sh" ,(file-append @var{bash} "/bin/sh")))
9152 @end example
9153
9154 @cindex @file{/usr/bin/env}
9155 @cindex @file{env}, in @file{/usr/bin}
9156 If you want to add, say, @code{/usr/bin/env} to your system, you can
9157 change it to:
9158
9159 @example
9160 `(("/bin/sh" ,(file-append @var{bash} "/bin/sh"))
9161 ("/usr/bin/env" ,(file-append @var{coreutils} "/bin/env")))
9162 @end example
9163
9164 Since this is part of @code{%base-services}, you can use
9165 @code{modify-services} to customize the set of special files
9166 (@pxref{Service Reference, @code{modify-services}}). But the simple way
9167 to add a special file is @i{via} the @code{extra-special-file} procedure
9168 (see below.)
9169 @end defvr
9170
9171 @deffn {Scheme Procedure} extra-special-file @var{file} @var{target}
9172 Use @var{target} as the ``special file'' @var{file}.
9173
9174 For example, adding the following lines to the @code{services} field of
9175 your operating system declaration leads to a @file{/usr/bin/env}
9176 symlink:
9177
9178 @example
9179 (extra-special-file "/usr/bin/env"
9180 (file-append coreutils "/bin/env"))
9181 @end example
9182 @end deffn
9183
9184 @deffn {Scheme Procedure} host-name-service @var{name}
9185 Return a service that sets the host name to @var{name}.
9186 @end deffn
9187
9188 @deffn {Scheme Procedure} login-service @var{config}
9189 Return a service to run login according to @var{config}, a
9190 @code{<login-configuration>} object, which specifies the message of the day,
9191 among other things.
9192 @end deffn
9193
9194 @deftp {Data Type} login-configuration
9195 This is the data type representing the configuration of login.
9196
9197 @table @asis
9198
9199 @item @code{motd}
9200 @cindex message of the day
9201 A file-like object containing the ``message of the day''.
9202
9203 @item @code{allow-empty-passwords?} (default: @code{#t})
9204 Allow empty passwords by default so that first-time users can log in when
9205 the 'root' account has just been created.
9206
9207 @end table
9208 @end deftp
9209
9210 @deffn {Scheme Procedure} mingetty-service @var{config}
9211 Return a service to run mingetty according to @var{config}, a
9212 @code{<mingetty-configuration>} object, which specifies the tty to run, among
9213 other things.
9214 @end deffn
9215
9216 @deftp {Data Type} mingetty-configuration
9217 This is the data type representing the configuration of Mingetty, which
9218 provides the default implementation of virtual console log-in.
9219
9220 @table @asis
9221
9222 @item @code{tty}
9223 The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
9224
9225 @item @code{auto-login} (default: @code{#f})
9226 When true, this field must be a string denoting the user name under
9227 which the system automatically logs in. When it is @code{#f}, a
9228 user name and password must be entered to log in.
9229
9230 @item @code{login-program} (default: @code{#f})
9231 This must be either @code{#f}, in which case the default log-in program
9232 is used (@command{login} from the Shadow tool suite), or a gexp denoting
9233 the name of the log-in program.
9234
9235 @item @code{login-pause?} (default: @code{#f})
9236 When set to @code{#t} in conjunction with @var{auto-login}, the user
9237 will have to press a key before the log-in shell is launched.
9238
9239 @item @code{mingetty} (default: @var{mingetty})
9240 The Mingetty package to use.
9241
9242 @end table
9243 @end deftp
9244
9245 @deffn {Scheme Procedure} agetty-service @var{config}
9246 Return a service to run agetty according to @var{config}, an
9247 @code{<agetty-configuration>} object, which specifies the tty to run,
9248 among other things.
9249 @end deffn
9250
9251 @deftp {Data Type} agetty-configuration
9252 This is the data type representing the configuration of agetty, which
9253 implements virtual and serial console log-in. See the @code{agetty(8)}
9254 man page for more information.
9255
9256 @table @asis
9257
9258 @item @code{tty}
9259 The name of the console this agetty runs on, as a string---e.g.,
9260 @code{"ttyS0"}. This argument is mandatory.
9261
9262 @item @code{baud-rate} (default: @code{#f})
9263 A string containing a comma-separated list of one or more baud rates, in
9264 descending order.
9265
9266 @item @code{term} (default: @code{#f})
9267 A string containing the value used for the @code{TERM} environment
9268 variable.
9269
9270 @item @code{eight-bits?} (default: @code{#f})
9271 When @code{#t}, the tty is assumed to be 8-bit clean, and parity detection is
9272 disabled.
9273
9274 @item @code{auto-login} (default: @code{#f})
9275 When passed a login name, as a string, the specified user will be logged
9276 in automatically without prompting for their login name or password.
9277
9278 @item @code{no-reset?} (default: @code{#f})
9279 When @code{#t}, don't reset terminal cflags (control modes).
9280
9281 @item @code{host} (default: @code{#f})
9282 This accepts a string containing the "login_host", which will be written
9283 into the @file{/var/run/utmpx} file.
9284
9285 @item @code{remote?} (default: @code{#f})
9286 When set to @code{#t} in conjunction with @var{host}, this will add an
9287 @code{-r} fakehost option to the command line of the login program
9288 specified in @var{login-program}.
9289
9290 @item @code{flow-control?} (default: @code{#f})
9291 When set to @code{#t}, enable hardware (RTS/CTS) flow control.
9292
9293 @item @code{no-issue?} (default: @code{#f})
9294 When set to @code{#t}, the contents of the @file{/etc/issue} file will
9295 not be displayed before presenting the login prompt.
9296
9297 @item @code{init-string} (default: @code{#f})
9298 This accepts a string that will be sent to the tty or modem before
9299 sending anything else. It can be used to initialize a modem.
9300
9301 @item @code{no-clear?} (default: @code{#f})
9302 When set to @code{#t}, agetty will not clear the screen before showing
9303 the login prompt.
9304
9305 @item @code{login-program} (default: (file-append shadow "/bin/login"))
9306 This must be either a gexp denoting the name of a log-in program, or
9307 unset, in which case the default value is the @command{login} from the
9308 Shadow tool suite.
9309
9310 @item @code{local-line} (default: @code{#f})
9311 Control the CLOCAL line flag. This accepts one of three symbols as
9312 arguments, @code{'auto}, @code{'always}, or @code{'never}. If @code{#f},
9313 the default value chosen by agetty is @code{'auto}.
9314
9315 @item @code{extract-baud?} (default: @code{#f})
9316 When set to @code{#t}, instruct agetty to try to extract the baud rate
9317 from the status messages produced by certain types of modems.
9318
9319 @item @code{skip-login?} (default: @code{#f})
9320 When set to @code{#t}, do not prompt the user for a login name. This
9321 can be used with @var{login-program} field to use non-standard login
9322 systems.
9323
9324 @item @code{no-newline?} (default: @code{#f})
9325 When set to @code{#t}, do not print a newline before printing the
9326 @file{/etc/issue} file.
9327
9328 @c Is this dangerous only when used with login-program, or always?
9329 @item @code{login-options} (default: @code{#f})
9330 This option accepts a string containing options that are passed to the
9331 login program. When used with the @var{login-program}, be aware that a
9332 malicious user could try to enter a login name containing embedded
9333 options that could be parsed by the login program.
9334
9335 @item @code{login-pause} (default: @code{#f})
9336 When set to @code{#t}, wait for any key before showing the login prompt.
9337 This can be used in conjunction with @var{auto-login} to save memory by
9338 lazily spawning shells.
9339
9340 @item @code{chroot} (default: @code{#f})
9341 Change root to the specified directory. This option accepts a directory
9342 path as a string.
9343
9344 @item @code{hangup?} (default: @code{#f})
9345 Use the Linux system call @code{vhangup} to do a virtual hangup of the
9346 specified terminal.
9347
9348 @item @code{keep-baud?} (default: @code{#f})
9349 When set to @code{#t}, try to keep the existing baud rate. The baud
9350 rates from @var{baud-rate} are used when agetty receives a @key{BREAK}
9351 character.
9352
9353 @item @code{timeout} (default: @code{#f})
9354 When set to an integer value, terminate if no user name could be read
9355 within @var{timeout} seconds.
9356
9357 @item @code{detect-case?} (default: @code{#f})
9358 When set to @code{#t}, turn on support for detecting an uppercase-only
9359 terminal. This setting will detect a login name containing only
9360 uppercase letters as indicating an uppercase-only terminal and turn on
9361 some upper-to-lower case conversions. Note that this will not support
9362 Unicode characters.
9363
9364 @item @code{wait-cr?} (default: @code{#f})
9365 When set to @code{#t}, wait for the user or modem to send a
9366 carriage-return or linefeed character before displaying
9367 @file{/etc/issue} or login prompt. This is typically used with the
9368 @var{init-string} option.
9369
9370 @item @code{no-hints?} (default: @code{#f})
9371 When set to @code{#t}, do not print hints about Num, Caps, and Scroll
9372 locks.
9373
9374 @item @code{no-hostname?} (default: @code{#f})
9375 By default, the hostname is printed. When this option is set to
9376 @code{#t}, no hostname will be shown at all.
9377
9378 @item @code{long-hostname?} (default: @code{#f})
9379 By default, the hostname is only printed until the first dot. When this
9380 option is set to @code{#t}, the fully qualified hostname by
9381 @code{gethostname} or @code{getaddrinfo} is shown.
9382
9383 @item @code{erase-characters} (default: @code{#f})
9384 This option accepts a string of additional characters that should be
9385 interpreted as backspace when the user types their login name.
9386
9387 @item @code{kill-characters} (default: @code{#f})
9388 This option accepts a string that should be interpreted to mean "ignore
9389 all previous characters" (also called a "kill" character) when the types
9390 their login name.
9391
9392 @item @code{chdir} (default: @code{#f})
9393 This option accepts, as a string, a directory path that will be changed
9394 to before login.
9395
9396 @item @code{delay} (default: @code{#f})
9397 This options accepts, as an integer, the number of seconds to sleep
9398 before opening the tty and displaying the login prompt.
9399
9400 @item @code{nice} (default: @code{#f})
9401 This option accepts, as an integer, the nice value with which to run the
9402 @command{login} program.
9403
9404 @item @code{extra-options} (default: @code{'()})
9405 This option provides an "escape hatch" for the user to provide arbitrary
9406 command-line arguments to @command{agetty} as a list of strings.
9407
9408 @end table
9409 @end deftp
9410
9411 @deffn {Scheme Procedure} kmscon-service-type @var{config}
9412 Return a service to run @uref{https://www.freedesktop.org/wiki/Software/kmscon,kmscon}
9413 according to @var{config}, a @code{<kmscon-configuration>} object, which
9414 specifies the tty to run, among other things.
9415 @end deffn
9416
9417 @deftp {Data Type} kmscon-configuration
9418 This is the data type representing the configuration of Kmscon, which
9419 implements virtual console log-in.
9420
9421 @table @asis
9422
9423 @item @code{virtual-terminal}
9424 The name of the console this Kmscon runs on---e.g., @code{"tty1"}.
9425
9426 @item @code{login-program} (default: @code{#~(string-append #$shadow "/bin/login")})
9427 A gexp denoting the name of the log-in program. The default log-in program is
9428 @command{login} from the Shadow tool suite.
9429
9430 @item @code{login-arguments} (default: @code{'("-p")})
9431 A list of arguments to pass to @command{login}.
9432
9433 @item @code{hardware-acceleration?} (default: #f)
9434 Whether to use hardware acceleration.
9435
9436 @item @code{kmscon} (default: @var{kmscon})
9437 The Kmscon package to use.
9438
9439 @end table
9440 @end deftp
9441
9442 @cindex name service cache daemon
9443 @cindex nscd
9444 @deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
9445 [#:name-services '()]
9446 Return a service that runs the libc name service cache daemon (nscd) with the
9447 given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
9448 Service Switch}, for an example.
9449 @end deffn
9450
9451 @defvr {Scheme Variable} %nscd-default-configuration
9452 This is the default @code{<nscd-configuration>} value (see below) used
9453 by @code{nscd-service}. It uses the caches defined by
9454 @var{%nscd-default-caches}; see below.
9455 @end defvr
9456
9457 @deftp {Data Type} nscd-configuration
9458 This is the data type representing the name service cache daemon (nscd)
9459 configuration.
9460
9461 @table @asis
9462
9463 @item @code{name-services} (default: @code{'()})
9464 List of packages denoting @dfn{name services} that must be visible to
9465 the nscd---e.g., @code{(list @var{nss-mdns})}.
9466
9467 @item @code{glibc} (default: @var{glibc})
9468 Package object denoting the GNU C Library providing the @command{nscd}
9469 command.
9470
9471 @item @code{log-file} (default: @code{"/var/log/nscd.log"})
9472 Name of the nscd log file. This is where debugging output goes when
9473 @code{debug-level} is strictly positive.
9474
9475 @item @code{debug-level} (default: @code{0})
9476 Integer denoting the debugging levels. Higher numbers mean that more
9477 debugging output is logged.
9478
9479 @item @code{caches} (default: @var{%nscd-default-caches})
9480 List of @code{<nscd-cache>} objects denoting things to be cached; see
9481 below.
9482
9483 @end table
9484 @end deftp
9485
9486 @deftp {Data Type} nscd-cache
9487 Data type representing a cache database of nscd and its parameters.
9488
9489 @table @asis
9490
9491 @item @code{database}
9492 This is a symbol representing the name of the database to be cached.
9493 Valid values are @code{passwd}, @code{group}, @code{hosts}, and
9494 @code{services}, which designate the corresponding NSS database
9495 (@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
9496
9497 @item @code{positive-time-to-live}
9498 @itemx @code{negative-time-to-live} (default: @code{20})
9499 A number representing the number of seconds during which a positive or
9500 negative lookup result remains in cache.
9501
9502 @item @code{check-files?} (default: @code{#t})
9503 Whether to check for updates of the files corresponding to
9504 @var{database}.
9505
9506 For instance, when @var{database} is @code{hosts}, setting this flag
9507 instructs nscd to check for updates in @file{/etc/hosts} and to take
9508 them into account.
9509
9510 @item @code{persistent?} (default: @code{#t})
9511 Whether the cache should be stored persistently on disk.
9512
9513 @item @code{shared?} (default: @code{#t})
9514 Whether the cache should be shared among users.
9515
9516 @item @code{max-database-size} (default: 32@tie{}MiB)
9517 Maximum size in bytes of the database cache.
9518
9519 @c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
9520 @c settings, so leave them out.
9521
9522 @end table
9523 @end deftp
9524
9525 @defvr {Scheme Variable} %nscd-default-caches
9526 List of @code{<nscd-cache>} objects used by default by
9527 @code{nscd-configuration} (see above).
9528
9529 It enables persistent and aggressive caching of service and host name
9530 lookups. The latter provides better host name lookup performance,
9531 resilience in the face of unreliable name servers, and also better
9532 privacy---often the result of host name lookups is in local cache, so
9533 external name servers do not even need to be queried.
9534 @end defvr
9535
9536 @anchor{syslog-configuration-type}
9537 @cindex syslog
9538 @cindex logging
9539 @deftp {Data Type} syslog-configuration
9540 This data type represents the configuration of the syslog daemon.
9541
9542 @table @asis
9543 @item @code{syslogd} (default: @code{#~(string-append #$inetutils "/libexec/syslogd")})
9544 The syslog daemon to use.
9545
9546 @item @code{config-file} (default: @code{%default-syslog.conf})
9547 The syslog configuration file to use.
9548
9549 @end table
9550 @end deftp
9551
9552 @anchor{syslog-service}
9553 @cindex syslog
9554 @deffn {Scheme Procedure} syslog-service @var{config}
9555 Return a service that runs a syslog daemon according to @var{config}.
9556
9557 @xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
9558 information on the configuration file syntax.
9559 @end deffn
9560
9561 @anchor{guix-configuration-type}
9562 @deftp {Data Type} guix-configuration
9563 This data type represents the configuration of the Guix build daemon.
9564 @xref{Invoking guix-daemon}, for more information.
9565
9566 @table @asis
9567 @item @code{guix} (default: @var{guix})
9568 The Guix package to use.
9569
9570 @item @code{build-group} (default: @code{"guixbuild"})
9571 Name of the group for build user accounts.
9572
9573 @item @code{build-accounts} (default: @code{10})
9574 Number of build user accounts to create.
9575
9576 @item @code{authorize-key?} (default: @code{#t})
9577 @cindex substitutes, authorization thereof
9578 Whether to authorize the substitute keys listed in
9579 @code{authorized-keys}---by default that of @code{hydra.gnu.org}
9580 (@pxref{Substitutes}).
9581
9582 @vindex %default-authorized-guix-keys
9583 @item @code{authorized-keys} (default: @var{%default-authorized-guix-keys})
9584 The list of authorized key files for archive imports, as a list of
9585 string-valued gexps (@pxref{Invoking guix archive}). By default, it
9586 contains that of @code{hydra.gnu.org} (@pxref{Substitutes}).
9587
9588 @item @code{use-substitutes?} (default: @code{#t})
9589 Whether to use substitutes.
9590
9591 @item @code{substitute-urls} (default: @var{%default-substitute-urls})
9592 The list of URLs where to look for substitutes by default.
9593
9594 @item @code{max-silent-time} (default: @code{0})
9595 @itemx @code{timeout} (default: @code{0})
9596 The number of seconds of silence and the number of seconds of activity,
9597 respectively, after which a build process times out. A value of zero
9598 disables the timeout.
9599
9600 @item @code{extra-options} (default: @code{'()})
9601 List of extra command-line options for @command{guix-daemon}.
9602
9603 @item @code{log-file} (default: @code{"/var/log/guix-daemon.log"})
9604 File where @command{guix-daemon}'s standard output and standard error
9605 are written.
9606
9607 @item @code{lsof} (default: @var{lsof})
9608 The lsof package to use.
9609
9610 @item @code{http-proxy} (default: @code{#f})
9611 The HTTP proxy used for downloading fixed-output derivations and
9612 substitutes.
9613
9614 @item @code{tmpdir} (default: @code{#f})
9615 A directory path where the @command{guix-daemon} will perform builds.
9616
9617 @end table
9618 @end deftp
9619
9620 @deffn {Scheme Procedure} guix-service @var{config}
9621 Return a service that runs the Guix build daemon according to
9622 @var{config}.
9623 @end deffn
9624
9625 @deffn {Scheme Procedure} udev-service [#:udev udev]
9626 Run @var{udev}, which populates the @file{/dev} directory dynamically.
9627 @end deffn
9628
9629 @deffn {Scheme Procedure} urandom-seed-service @var{#f}
9630 Save some entropy in @var{%random-seed-file} to seed @file{/dev/urandom}
9631 when rebooting.
9632 @end deffn
9633
9634 @defvr {Scheme Variable} %random-seed-file
9635 This is the name of the file where some random bytes are saved by
9636 @var{urandom-seed-service} to seed @file{/dev/urandom} when rebooting.
9637 It defaults to @file{/var/lib/random-seed}.
9638 @end defvr
9639
9640 @cindex keymap
9641 @cindex keyboard
9642 @deffn {Scheme Procedure} console-keymap-service @var{files} ...
9643 @cindex keyboard layout
9644 Return a service to load console keymaps from @var{files} using
9645 @command{loadkeys} command. Most likely, you want to load some default
9646 keymap, which can be done like this:
9647
9648 @example
9649 (console-keymap-service "dvorak")
9650 @end example
9651
9652 Or, for example, for a Swedish keyboard, you may need to combine
9653 the following keymaps:
9654 @example
9655 (console-keymap-service "se-lat6" "se-fi-lat6")
9656 @end example
9657
9658 Also you can specify a full file name (or file names) of your keymap(s).
9659 See @code{man loadkeys} for details.
9660
9661 @end deffn
9662
9663 @cindex mouse
9664 @cindex gpm
9665 @deffn {Scheme Procedure} gpm-service [#:gpm @var{gpm}] @
9666 [#:options]
9667 Run @var{gpm}, the general-purpose mouse daemon, with the given
9668 command-line @var{options}. GPM allows users to use the mouse in the console,
9669 notably to select, copy, and paste text. The default value of @var{options}
9670 uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
9671
9672 This service is not part of @var{%base-services}.
9673 @end deffn
9674
9675 @anchor{guix-publish-service-type}
9676 @deffn {Scheme Variable} guix-publish-service-type
9677 This is the service type for @command{guix publish} (@pxref{Invoking
9678 guix publish}). Its value must be a @code{guix-configuration}
9679 object, as described below.
9680
9681 This assumes that @file{/etc/guix} already contains a signing key pair as
9682 created by @command{guix archive --generate-key} (@pxref{Invoking guix
9683 archive}). If that is not the case, the service will fail to start.
9684 @end deffn
9685
9686 @deftp {Data Type} guix-publish-configuration
9687 Data type representing the configuration of the @code{guix publish}
9688 service.
9689
9690 @table @asis
9691 @item @code{guix} (default: @code{guix})
9692 The Guix package to use.
9693
9694 @item @code{port} (default: @code{80})
9695 The TCP port to listen for connections.
9696
9697 @item @code{host} (default: @code{"localhost"})
9698 The host (and thus, network interface) to listen to. Use
9699 @code{"0.0.0.0"} to listen on all the network interfaces.
9700
9701 @item @code{compression-level} (default: @code{3})
9702 The gzip compression level at which substitutes are compressed. Use
9703 @code{0} to disable compression altogether, and @code{9} to get the best
9704 compression ratio at the expense of increased CPU usage.
9705
9706 @item @code{nar-path} (default: @code{"nar"})
9707 The URL path at which ``nars'' can be fetched. @xref{Invoking guix
9708 publish, @code{--nar-path}}, for details.
9709
9710 @item @code{cache} (default: @code{#f})
9711 When it is @code{#f}, disable caching and instead generate archives on
9712 demand. Otherwise, this should be the name of a directory---e.g.,
9713 @code{"/var/cache/guix/publish"}---where @command{guix publish} caches
9714 archives and meta-data ready to be sent. @xref{Invoking guix publish,
9715 @option{--cache}}, for more information on the tradeoffs involved.
9716
9717 @item @code{workers} (default: @code{#f})
9718 When it is an integer, this is the number of worker threads used for
9719 caching; when @code{#f}, the number of processors is used.
9720 @xref{Invoking guix publish, @option{--workers}}, for more information.
9721
9722 @item @code{ttl} (default: @code{#f})
9723 When it is an integer, this denotes the @dfn{time-to-live} of the
9724 published archives. @xref{Invoking guix publish, @option{--ttl}}, for
9725 more information.
9726 @end table
9727 @end deftp
9728
9729 @anchor{rngd-service}
9730 @deffn {Scheme Procedure} rngd-service [#:rng-tools @var{rng-tools}] @
9731 [#:device "/dev/hwrng"]
9732 Return a service that runs the @command{rngd} program from @var{rng-tools}
9733 to add @var{device} to the kernel's entropy pool. The service will fail if
9734 @var{device} does not exist.
9735 @end deffn
9736
9737 @anchor{pam-limits-service}
9738 @cindex session limits
9739 @cindex ulimit
9740 @cindex priority
9741 @deffn {Scheme Procedure} pam-limits-service [#:limits @var{limits}]
9742
9743 Return a service that installs a configuration file for the
9744 @uref{http://linux-pam.org/Linux-PAM-html/sag-pam_limits.html,
9745 @code{pam_limits} module}. The procedure optionally takes a list of
9746 @code{pam-limits-entry} values, which can be used to specify
9747 @code{ulimit} limits and nice priority limits to user sessions.
9748
9749 The following limits definition sets two hard and soft limits for all
9750 login sessions of users in the @code{realtime} group:
9751
9752 @example
9753 (pam-limits-service
9754 (list
9755 (pam-limits-entry "@@realtime" 'both 'rtprio 99)
9756 (pam-limits-entry "@@realtime" 'both 'memlock 'unlimited)))
9757 @end example
9758
9759 The first entry increases the maximum realtime priority for
9760 non-privileged processes; the second entry lifts any restriction of the
9761 maximum address space that can be locked in memory. These settings are
9762 commonly used for real-time audio systems.
9763 @end deffn
9764
9765 @node Scheduled Job Execution
9766 @subsubsection Scheduled Job Execution
9767
9768 @cindex cron
9769 @cindex mcron
9770 @cindex scheduling jobs
9771 The @code{(gnu services mcron)} module provides an interface to
9772 GNU@tie{}mcron, a daemon to run jobs at scheduled times (@pxref{Top,,,
9773 mcron, GNU@tie{}mcron}). GNU@tie{}mcron is similar to the traditional
9774 Unix @command{cron} daemon; the main difference is that it is
9775 implemented in Guile Scheme, which provides a lot of flexibility when
9776 specifying the scheduling of jobs and their actions.
9777
9778 The example below defines an operating system that runs the
9779 @command{updatedb} (@pxref{Invoking updatedb,,, find, Finding Files})
9780 and the @command{guix gc} commands (@pxref{Invoking guix gc}) daily, as
9781 well as the @command{mkid} command on behalf of an unprivileged user
9782 (@pxref{mkid invocation,,, idutils, ID Database Utilities}). It uses
9783 gexps to introduce job definitions that are passed to mcron
9784 (@pxref{G-Expressions}).
9785
9786 @lisp
9787 (use-modules (guix) (gnu) (gnu services mcron))
9788 (use-package-modules base idutils)
9789
9790 (define updatedb-job
9791 ;; Run 'updatedb' at 3AM every day. Here we write the
9792 ;; job's action as a Scheme procedure.
9793 #~(job '(next-hour '(3))
9794 (lambda ()
9795 (execl (string-append #$findutils "/bin/updatedb")
9796 "updatedb"
9797 "--prunepaths=/tmp /var/tmp /gnu/store"))))
9798
9799 (define garbage-collector-job
9800 ;; Collect garbage 5 minutes after midnight every day.
9801 ;; The job's action is a shell command.
9802 #~(job "5 0 * * *" ;Vixie cron syntax
9803 "guix gc -F 1G"))
9804
9805 (define idutils-job
9806 ;; Update the index database as user "charlie" at 12:15PM
9807 ;; and 19:15PM. This runs from the user's home directory.
9808 #~(job '(next-minute-from (next-hour '(12 19)) '(15))
9809 (string-append #$idutils "/bin/mkid src")
9810 #:user "charlie"))
9811
9812 (operating-system
9813 ;; @dots{}
9814 (services (cons (mcron-service (list garbage-collector-job
9815 updatedb-job
9816 idutils-job))
9817 %base-services)))
9818 @end lisp
9819
9820 @xref{Guile Syntax, mcron job specifications,, mcron, GNU@tie{}mcron},
9821 for more information on mcron job specifications. Below is the
9822 reference of the mcron service.
9823
9824 @deffn {Scheme Procedure} mcron-service @var{jobs} [#:mcron @var{mcron2}]
9825 Return an mcron service running @var{mcron} that schedules @var{jobs}, a
9826 list of gexps denoting mcron job specifications.
9827
9828 This is a shorthand for:
9829 @example
9830 (service mcron-service-type
9831 (mcron-configuration (mcron mcron) (jobs jobs)))
9832 @end example
9833 @end deffn
9834
9835 @defvr {Scheme Variable} mcron-service-type
9836 This is the type of the @code{mcron} service, whose value is an
9837 @code{mcron-configuration} object.
9838
9839 This service type can be the target of a service extension that provides
9840 it additional job specifications (@pxref{Service Composition}). In
9841 other words, it is possible to define services that provide additional
9842 mcron jobs to run.
9843 @end defvr
9844
9845 @deftp {Data Type} mcron-configuration
9846 Data type representing the configuration of mcron.
9847
9848 @table @asis
9849 @item @code{mcron} (default: @var{mcron2})
9850 The mcron package to use.
9851
9852 @item @code{jobs}
9853 This is a list of gexps (@pxref{G-Expressions}), where each gexp
9854 corresponds to an mcron job specification (@pxref{Syntax, mcron job
9855 specifications,, mcron, GNU@tie{}mcron}).
9856 @end table
9857 @end deftp
9858
9859
9860 @node Log Rotation
9861 @subsubsection Log Rotation
9862
9863 @cindex rottlog
9864 @cindex log rotation
9865 @cindex logging
9866 Log files such as those found in @file{/var/log} tend to grow endlessly,
9867 so it's a good idea to @dfn{rotate} them once in a while---i.e., archive
9868 their contents in separate files, possibly compressed. The @code{(gnu
9869 services admin)} module provides an interface to GNU@tie{}Rot[t]log, a
9870 log rotation tool (@pxref{Top,,, rottlog, GNU Rot[t]log Manual}).
9871
9872 The example below defines an operating system that provides log rotation
9873 with the default settings, for commonly encountered log files.
9874
9875 @lisp
9876 (use-modules (guix) (gnu))
9877 (use-service-modules admin mcron)
9878 (use-package-modules base idutils)
9879
9880 (operating-system
9881 ;; @dots{}
9882 (services (cons* (mcron-service)
9883 (service rottlog-service-type)
9884 %base-services)))
9885 @end lisp
9886
9887 @defvr {Scheme Variable} rottlog-service-type
9888 This is the type of the Rottlog service, whose value is a
9889 @code{rottlog-configuration} object.
9890
9891 Other services can extend this one with new @code{log-rotation} objects
9892 (see below), thereby augmenting the set of files to be rotated.
9893
9894 This service type can define mcron jobs (@pxref{Scheduled Job
9895 Execution}) to run the rottlog service.
9896 @end defvr
9897
9898 @deftp {Data Type} rottlog-configuration
9899 Data type representing the configuration of rottlog.
9900
9901 @table @asis
9902 @item @code{rottlog} (default: @code{rottlog})
9903 The Rottlog package to use.
9904
9905 @item @code{rc-file} (default: @code{(file-append rottlog "/etc/rc")})
9906 The Rottlog configuration file to use (@pxref{Mandatory RC Variables,,,
9907 rottlog, GNU Rot[t]log Manual}).
9908
9909 @item @code{rotations} (default: @code{%default-rotations})
9910 A list of @code{log-rotation} objects as defined below.
9911
9912 @item @code{jobs}
9913 This is a list of gexps where each gexp corresponds to an mcron job
9914 specification (@pxref{Scheduled Job Execution}).
9915 @end table
9916 @end deftp
9917
9918 @deftp {Data Type} log-rotation
9919 Data type representing the rotation of a group of log files.
9920
9921 Taking an example from the Rottlog manual (@pxref{Period Related File
9922 Examples,,, rottlog, GNU Rot[t]log Manual}), a log rotation might be
9923 defined like this:
9924
9925 @example
9926 (log-rotation
9927 (frequency 'daily)
9928 (files '("/var/log/apache/*"))
9929 (options '("storedir apache-archives"
9930 "rotate 6"
9931 "notifempty"
9932 "nocompress")))
9933 @end example
9934
9935 The list of fields is as follows:
9936
9937 @table @asis
9938 @item @code{frequency} (default: @code{'weekly})
9939 The log rotation frequency, a symbol.
9940
9941 @item @code{files}
9942 The list of files or file glob patterns to rotate.
9943
9944 @item @code{options} (default: @code{'()})
9945 The list of rottlog options for this rotation (@pxref{Configuration
9946 parameters,,, rottlog, GNU Rot[t]lg Manual}).
9947
9948 @item @code{post-rotate} (default: @code{#f})
9949 Either @code{#f} or a gexp to execute once the rotation has completed.
9950 @end table
9951 @end deftp
9952
9953 @defvr {Scheme Variable} %default-rotations
9954 Specifies weekly rotation of @var{%rotated-files} and
9955 a couple of other files.
9956 @end defvr
9957
9958 @defvr {Scheme Variable} %rotated-files
9959 The list of syslog-controlled files to be rotated. By default it is:
9960 @code{'("/var/log/messages" "/var/log/secure")}.
9961 @end defvr
9962
9963 @node Networking Services
9964 @subsubsection Networking Services
9965
9966 The @code{(gnu services networking)} module provides services to configure
9967 the network interface.
9968
9969 @cindex DHCP, networking service
9970 @deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
9971 Return a service that runs @var{dhcp}, a Dynamic Host Configuration
9972 Protocol (DHCP) client, on all the non-loopback network interfaces.
9973 @end deffn
9974
9975 @defvr {Scheme Variable} static-networking-service-type
9976 This is the type for statically-configured network interfaces.
9977 @c TODO Document <static-networking> data structures.
9978 @end defvr
9979
9980 @deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
9981 [#:netmask #f] [#:gateway #f] [#:name-servers @code{'()}]
9982 Return a service that starts @var{interface} with address @var{ip}. If
9983 @var{netmask} is true, use it as the network mask. If @var{gateway} is true,
9984 it must be a string specifying the default network gateway.
9985
9986 This procedure can be called several times, one for each network
9987 interface of interest. Behind the scenes what it does is extend
9988 @code{static-networking-service-type} with additional network interfaces
9989 to handle.
9990 @end deffn
9991
9992 @cindex wicd
9993 @cindex wireless
9994 @cindex WiFi
9995 @cindex network management
9996 @deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
9997 Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
9998 management daemon that aims to simplify wired and wireless networking.
9999
10000 This service adds the @var{wicd} package to the global profile, providing
10001 several commands to interact with the daemon and configure networking:
10002 @command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
10003 and @command{wicd-curses} user interfaces.
10004 @end deffn
10005
10006 @cindex NetworkManager
10007
10008 @defvr {Scheme Variable} network-manager-service-type
10009 This is the service type for the
10010 @uref{https://wiki.gnome.org/Projects/NetworkManager, NetworkManager}
10011 service. The value for this service type is a
10012 @code{network-manager-configuration} record.
10013 @end defvr
10014
10015 @deftp {Data Type} network-manager-configuration
10016 Data type representing the configuration of NetworkManager.
10017
10018 @table @asis
10019 @item @code{network-manager} (default: @code{network-manager})
10020 The NetworkManager package to use.
10021
10022 @item @code{dns} (default: @code{"default"})
10023 Processing mode for DNS, which affects how NetworkManager uses the
10024 @code{resolv.conf} configuration file.
10025
10026 @table @samp
10027 @item default
10028 NetworkManager will update @code{resolv.conf} to reflect the nameservers
10029 provided by currently active connections.
10030
10031 @item dnsmasq
10032 NetworkManager will run @code{dnsmasq} as a local caching nameserver,
10033 using a "split DNS" configuration if you are connected to a VPN, and
10034 then update @code{resolv.conf} to point to the local nameserver.
10035
10036 @item none
10037 NetworkManager will not modify @code{resolv.conf}.
10038 @end table
10039
10040 @end table
10041 @end deftp
10042
10043 @cindex Connman
10044 @deffn {Scheme Variable} connman-service-type
10045 This is the service type to run @url{https://01.org/connman,Connman},
10046 a network connection manager.
10047
10048 Its value must be an
10049 @code{connman-configuration} record as in this example:
10050
10051 @example
10052 (service connman-service-type
10053 (connman-configuration
10054 (disable-vpn? #t)))
10055 @end example
10056
10057 See below for details about @code{connman-configuration}.
10058 @end deffn
10059
10060 @deftp {Data Type} connman-configuration
10061 Data Type representing the configuration of connman.
10062
10063 @table @asis
10064 @item @code{connman} (default: @var{connman})
10065 The connman package to use.
10066
10067 @item @code{disable-vpn?} (default: @code{#f})
10068 When true, enable connman's vpn plugin.
10069 @end table
10070 @end deftp
10071
10072 @cindex WPA Supplicant
10073 @defvr {Scheme Variable} wpa-supplicant-service-type
10074 This is the service type to run @url{https://w1.fi/wpa_supplicant/,WPA
10075 supplicant}, an authentication daemon required to authenticate against
10076 encrypted WiFi or ethernet networks. It is configured to listen for
10077 requests on D-Bus.
10078
10079 The value of this service is the @code{wpa-supplicant} package to use.
10080 Thus, it can be instantiated like this:
10081
10082 @lisp
10083 (use-modules (gnu services networking))
10084
10085 (service wpa-supplicant-service-type)
10086 @end lisp
10087 @end defvr
10088
10089 @cindex NTP
10090 @cindex real time clock
10091 @deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
10092 [#:servers @var{%ntp-servers}] @
10093 [#:allow-large-adjustment? #f]
10094 Return a service that runs the daemon from @var{ntp}, the
10095 @uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
10096 keep the system clock synchronized with that of @var{servers}.
10097 @var{allow-large-adjustment?} determines whether @command{ntpd} is allowed to
10098 make an initial adjustment of more than 1,000 seconds.
10099 @end deffn
10100
10101 @defvr {Scheme Variable} %ntp-servers
10102 List of host names used as the default NTP servers.
10103 @end defvr
10104
10105 @cindex inetd
10106 @deffn {Scheme variable} inetd-service-type
10107 This service runs the @command{inetd} (@pxref{inetd invocation,,,
10108 inetutils, GNU Inetutils}) daemon. @command{inetd} listens for
10109 connections on internet sockets, and lazily starts the specified server
10110 program when a connection is made on one of these sockets.
10111
10112 The value of this service is an @code{inetd-configuration} object. The
10113 following example configures the @command{inetd} daemon to provide the
10114 built-in @command{echo} service, as well as an smtp service which
10115 forwards smtp traffic over ssh to a server @code{smtp-server} behind a
10116 gateway @code{hostname}:
10117
10118 @example
10119 (service
10120 inetd-service-type
10121 (inetd-configuration
10122 (entries (list
10123 (inetd-entry
10124 (name "echo")
10125 (socket-type 'stream)
10126 (protocol "tcp")
10127 (wait? #f)
10128 (user "root"))
10129 (inetd-entry
10130 (node "127.0.0.1")
10131 (name "smtp")
10132 (socket-type 'stream)
10133 (protocol "tcp")
10134 (wait? #f)
10135 (user "root")
10136 (program (file-append openssh "/bin/ssh"))
10137 (arguments
10138 '("ssh" "-qT" "-i" "/path/to/ssh_key"
10139 "-W" "smtp-server:25" "user@@hostname")))))
10140 @end example
10141
10142 See below for more details about @code{inetd-configuration}.
10143 @end deffn
10144
10145 @deftp {Data Type} inetd-configuration
10146 Data type representing the configuration of @command{inetd}.
10147
10148 @table @asis
10149 @item @code{program} (default: @code{(file-append inetutils "/libexec/inetd")})
10150 The @command{inetd} executable to use.
10151
10152 @item @code{entries} (default: @code{'()})
10153 A list of @command{inetd} service entries. Each entry should be created
10154 by the @code{inetd-entry} constructor.
10155 @end table
10156 @end deftp
10157
10158 @deftp {Data Type} inetd-entry
10159 Data type representing an entry in the @command{inetd} configuration.
10160 Each entry corresponds to a socket where @command{inetd} will listen for
10161 requests.
10162
10163 @table @asis
10164 @item @code{node} (default: @code{#f})
10165 Optional string, a comma-separated list of local addresses
10166 @command{inetd} should use when listening for this service.
10167 @xref{Configuration file,,, inetutils, GNU Inetutils} for a complete
10168 description of all options.
10169 @item @code{name}
10170 A string, the name must correspond to an entry in @code{/etc/services}.
10171 @item @code{socket-type}
10172 One of @code{'stream}, @code{'dgram}, @code{'raw}, @code{'rdm} or
10173 @code{'seqpacket}.
10174 @item @code{protocol}
10175 A string, must correspond to an entry in @code{/etc/protocols}.
10176 @item @code{wait?} (default: @code{#t})
10177 Whether @command{inetd} should wait for the server to exit before
10178 listening to new service requests.
10179 @item @code{user}
10180 A string containing the user (and, optionally, group) name of the user
10181 as whom the server should run. The group name can be specified in a
10182 suffix, separated by a colon or period, i.e. @code{"user"},
10183 @code{"user:group"} or @code{"user.group"}.
10184 @item @code{program} (default: @code{"internal"})
10185 The server program which will serve the requests, or @code{"internal"}
10186 if @command{inetd} should use a built-in service.
10187 @item @code{arguments} (default: @code{'()})
10188 A list strings or file-like objects, which are the server program's
10189 arguments, starting with the zeroth argument, i.e. the name of the
10190 program itself. For @command{inetd}'s internal services, this entry
10191 must be @code{'()} or @code{'("internal")}.
10192 @end table
10193
10194 @xref{Configuration file,,, inetutils, GNU Inetutils} for a more
10195 detailed discussion of each configuration field.
10196 @end deftp
10197
10198 @cindex Tor
10199 @deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
10200 Return a service to run the @uref{https://torproject.org, Tor} anonymous
10201 networking daemon.
10202
10203 The daemon runs as the @code{tor} unprivileged user. It is passed
10204 @var{config-file}, a file-like object, with an additional @code{User tor} line
10205 and lines for hidden services added via @code{tor-hidden-service}. Run
10206 @command{man tor} for information about the configuration file.
10207 @end deffn
10208
10209 @cindex hidden service
10210 @deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
10211 Define a new Tor @dfn{hidden service} called @var{name} and implementing
10212 @var{mapping}. @var{mapping} is a list of port/host tuples, such as:
10213
10214 @example
10215 '((22 "127.0.0.1:22")
10216 (80 "127.0.0.1:8080"))
10217 @end example
10218
10219 In this example, port 22 of the hidden service is mapped to local port 22, and
10220 port 80 is mapped to local port 8080.
10221
10222 This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
10223 the @file{hostname} file contains the @code{.onion} host name for the hidden
10224 service.
10225
10226 See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
10227 project's documentation} for more information.
10228 @end deffn
10229
10230 @deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
10231 [#:interface "127.0.0.1"] [#:port 6667] @
10232 [#:extra-settings ""]
10233 Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
10234 acts as a gateway between IRC and chat networks.
10235
10236 The daemon will listen to the interface corresponding to the IP address
10237 specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
10238 local clients can connect, whereas @code{0.0.0.0} means that connections can
10239 come from any networking interface.
10240
10241 In addition, @var{extra-settings} specifies a string to append to the
10242 configuration file.
10243 @end deffn
10244
10245 Furthermore, @code{(gnu services ssh)} provides the following services.
10246 @cindex SSH
10247 @cindex SSH server
10248
10249 @deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
10250 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
10251 [#:allow-empty-passwords? #f] [#:root-login? #f] @
10252 [#:syslog-output? #t] [#:x11-forwarding? #t] @
10253 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
10254 [#:public-key-authentication? #t] [#:initialize? #t]
10255 Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
10256 @var{host-key} must designate a file containing the host key, and readable
10257 only by root.
10258
10259 When @var{daemonic?} is true, @command{lshd} will detach from the
10260 controlling terminal and log its output to syslogd, unless one sets
10261 @var{syslog-output?} to false. Obviously, it also makes lsh-service
10262 depend on existence of syslogd service. When @var{pid-file?} is true,
10263 @command{lshd} writes its PID to the file called @var{pid-file}.
10264
10265 When @var{initialize?} is true, automatically create the seed and host key
10266 upon service activation if they do not exist yet. This may take long and
10267 require interaction.
10268
10269 When @var{initialize?} is false, it is up to the user to initialize the
10270 randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
10271 a key pair with the private key stored in file @var{host-key} (@pxref{lshd
10272 basics,,, lsh, LSH Manual}).
10273
10274 When @var{interfaces} is empty, lshd listens for connections on all the
10275 network interfaces; otherwise, @var{interfaces} must be a list of host names
10276 or addresses.
10277
10278 @var{allow-empty-passwords?} specifies whether to accept log-ins with empty
10279 passwords, and @var{root-login?} specifies whether to accept log-ins as
10280 root.
10281
10282 The other options should be self-descriptive.
10283 @end deffn
10284
10285 @cindex SSH
10286 @cindex SSH server
10287 @deffn {Scheme Variable} openssh-service-type
10288 This is the type for the @uref{http://www.openssh.org, OpenSSH} secure
10289 shell daemon, @command{sshd}. Its value must be an
10290 @code{openssh-configuration} record as in this example:
10291
10292 @example
10293 (service openssh-service-type
10294 (openssh-configuration
10295 (x11-forwarding? #t)
10296 (permit-root-login 'without-password)
10297 (authorized-keys
10298 `(("alice" ,(local-file "alice.pub"))
10299 ("bob" ,(local-file "bob.pub"))))))
10300 @end example
10301
10302 See below for details about @code{openssh-configuration}.
10303
10304 This service can be extended with extra authorized keys, as in this
10305 example:
10306
10307 @example
10308 (service-extension openssh-service-type
10309 (const `(("charlie"
10310 ,(local-file "charlie.pub")))))
10311 @end example
10312 @end deffn
10313
10314 @deftp {Data Type} openssh-configuration
10315 This is the configuration record for OpenSSH's @command{sshd}.
10316
10317 @table @asis
10318 @item @code{pid-file} (default: @code{"/var/run/sshd.pid"})
10319 Name of the file where @command{sshd} writes its PID.
10320
10321 @item @code{port-number} (default: @code{22})
10322 TCP port on which @command{sshd} listens for incoming connections.
10323
10324 @item @code{permit-root-login} (default: @code{#f})
10325 This field determines whether and when to allow logins as root. If
10326 @code{#f}, root logins are disallowed; if @code{#t}, they are allowed.
10327 If it's the symbol @code{'without-password}, then root logins are
10328 permitted but not with password-based authentication.
10329
10330 @item @code{allow-empty-passwords?} (default: @code{#f})
10331 When true, users with empty passwords may log in. When false, they may
10332 not.
10333
10334 @item @code{password-authentication?} (default: @code{#t})
10335 When true, users may log in with their password. When false, they have
10336 other authentication methods.
10337
10338 @item @code{public-key-authentication?} (default: @code{#t})
10339 When true, users may log in using public key authentication. When
10340 false, users have to use other authentication method.
10341
10342 Authorized public keys are stored in @file{~/.ssh/authorized_keys}.
10343 This is used only by protocol version 2.
10344
10345 @item @code{x11-forwarding?} (default: @code{#f})
10346 When true, forwarding of X11 graphical client connections is
10347 enabled---in other words, @command{ssh} options @option{-X} and
10348 @option{-Y} will work.
10349
10350 @item @code{challenge-response-authentication?} (default: @code{#f})
10351 Specifies whether challenge response authentication is allowed (e.g. via
10352 PAM).
10353
10354 @item @code{use-pam?} (default: @code{#t})
10355 Enables the Pluggable Authentication Module interface. If set to
10356 @code{#t}, this will enable PAM authentication using
10357 @code{challenge-response-authentication?} and
10358 @code{password-authentication?}, in addition to PAM account and session
10359 module processing for all authentication types.
10360
10361 Because PAM challenge response authentication usually serves an
10362 equivalent role to password authentication, you should disable either
10363 @code{challenge-response-authentication?} or
10364 @code{password-authentication?}.
10365
10366 @item @code{print-last-log?} (default: @code{#t})
10367 Specifies whether @command{sshd} should print the date and time of the
10368 last user login when a user logs in interactively.
10369
10370 @item @code{subsystems} (default: @code{'(("sftp" "internal-sftp"))})
10371 Configures external subsystems (e.g. file transfer daemon).
10372
10373 This is a list of two-element lists, each of which containing the
10374 subsystem name and a command (with optional arguments) to execute upon
10375 subsystem request.
10376
10377 The command @command{internal-sftp} implements an in-process SFTP
10378 server. Alternately, one can specify the @command{sftp-server} command:
10379 @example
10380 (service openssh-service-type
10381 (openssh-configuration
10382 (subsystems
10383 `(("sftp" ,(file-append openssh "/libexec/sftp-server"))))))
10384 @end example
10385
10386 @item @code{authorized-keys} (default: @code{'()})
10387 @cindex authorized keys, SSH
10388 @cindex SSH authorized keys
10389 This is the list of authorized keys. Each element of the list is a user
10390 name followed by one or more file-like objects that represent SSH public
10391 keys. For example:
10392
10393 @example
10394 (openssh-configuration
10395 (authorized-keys
10396 `(("rekado" ,(local-file "rekado.pub"))
10397 ("chris" ,(local-file "chris.pub"))
10398 ("root" ,(local-file "rekado.pub") ,(local-file "chris.pub")))))
10399 @end example
10400
10401 @noindent
10402 registers the specified public keys for user accounts @code{rekado},
10403 @code{chris}, and @code{root}.
10404
10405 Additional authorized keys can be specified @i{via}
10406 @code{service-extension}.
10407
10408 Note that this does @emph{not} interfere with the use of
10409 @file{~/.ssh/authorized_keys}.
10410 @end table
10411 @end deftp
10412
10413 @deffn {Scheme Procedure} dropbear-service [@var{config}]
10414 Run the @uref{https://matt.ucc.asn.au/dropbear/dropbear.html,Dropbear SSH
10415 daemon} with the given @var{config}, a @code{<dropbear-configuration>}
10416 object.
10417
10418 For example, to specify a Dropbear service listening on port 1234, add
10419 this call to the operating system's @code{services} field:
10420
10421 @example
10422 (dropbear-service (dropbear-configuration
10423 (port-number 1234)))
10424 @end example
10425 @end deffn
10426
10427 @deftp {Data Type} dropbear-configuration
10428 This data type represents the configuration of a Dropbear SSH daemon.
10429
10430 @table @asis
10431 @item @code{dropbear} (default: @var{dropbear})
10432 The Dropbear package to use.
10433
10434 @item @code{port-number} (default: 22)
10435 The TCP port where the daemon waits for incoming connections.
10436
10437 @item @code{syslog-output?} (default: @code{#t})
10438 Whether to enable syslog output.
10439
10440 @item @code{pid-file} (default: @code{"/var/run/dropbear.pid"})
10441 File name of the daemon's PID file.
10442
10443 @item @code{root-login?} (default: @code{#f})
10444 Whether to allow @code{root} logins.
10445
10446 @item @code{allow-empty-passwords?} (default: @code{#f})
10447 Whether to allow empty passwords.
10448
10449 @item @code{password-authentication?} (default: @code{#t})
10450 Whether to enable password-based authentication.
10451 @end table
10452 @end deftp
10453
10454 @defvr {Scheme Variable} %facebook-host-aliases
10455 This variable contains a string for use in @file{/etc/hosts}
10456 (@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
10457 line contains a entry that maps a known server name of the Facebook
10458 on-line service---e.g., @code{www.facebook.com}---to the local
10459 host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
10460
10461 This variable is typically used in the @code{hosts-file} field of an
10462 @code{operating-system} declaration (@pxref{operating-system Reference,
10463 @file{/etc/hosts}}):
10464
10465 @example
10466 (use-modules (gnu) (guix))
10467
10468 (operating-system
10469 (host-name "mymachine")
10470 ;; ...
10471 (hosts-file
10472 ;; Create a /etc/hosts file with aliases for "localhost"
10473 ;; and "mymachine", as well as for Facebook servers.
10474 (plain-file "hosts"
10475 (string-append (local-host-aliases host-name)
10476 %facebook-host-aliases))))
10477 @end example
10478
10479 This mechanism can prevent programs running locally, such as Web
10480 browsers, from accessing Facebook.
10481 @end defvr
10482
10483 The @code{(gnu services avahi)} provides the following definition.
10484
10485 @deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
10486 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
10487 [#:ipv6? #t] [#:wide-area? #f] @
10488 [#:domains-to-browse '()] [#:debug? #f]
10489 Return a service that runs @command{avahi-daemon}, a system-wide
10490 mDNS/DNS-SD responder that allows for service discovery and
10491 "zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
10492 extends the name service cache daemon (nscd) so that it can resolve
10493 @code{.local} host names using
10494 @uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
10495 add the @var{avahi} package to the system profile so that commands such as
10496 @command{avahi-browse} are directly usable.
10497
10498 If @var{host-name} is different from @code{#f}, use that as the host name to
10499 publish for this machine; otherwise, use the machine's actual host name.
10500
10501 When @var{publish?} is true, publishing of host names and services is allowed;
10502 in particular, avahi-daemon will publish the machine's host name and IP
10503 address via mDNS on the local network.
10504
10505 When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
10506
10507 Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
10508 sockets.
10509 @end deffn
10510
10511 @deffn {Scheme Variable} openvswitch-service-type
10512 This is the type of the @uref{http://www.openvswitch.org, Open vSwitch}
10513 service, whose value should be an @code{openvswitch-configuration}
10514 object.
10515 @end deffn
10516
10517 @deftp {Data Type} openvswitch-configuration
10518 Data type representing the configuration of Open vSwitch, a multilayer
10519 virtual switch which is designed to enable massive network automation
10520 through programmatic extension.
10521
10522 @table @asis
10523 @item @code{package} (default: @var{openvswitch})
10524 Package object of the Open vSwitch.
10525
10526 @end table
10527 @end deftp
10528
10529 @node X Window
10530 @subsubsection X Window
10531
10532 @cindex X11
10533 @cindex X Window System
10534 Support for the X Window graphical display system---specifically
10535 Xorg---is provided by the @code{(gnu services xorg)} module. Note that
10536 there is no @code{xorg-service} procedure. Instead, the X server is
10537 started by the @dfn{login manager}, currently SLiM.
10538
10539 @deftp {Data Type} sddm-configuration
10540 This is the data type representing the sddm service configuration.
10541
10542 @table @asis
10543 @item @code{display-server} (default: "x11")
10544 Select display server to use for the greeter. Valid values are "x11"
10545 or "wayland".
10546
10547 @item @code{numlock} (default: "on")
10548 Valid values are "on", "off" or "none".
10549
10550 @item @code{halt-command} (default @code{#~(string-apppend #$shepherd "/sbin/halt")})
10551 Command to run when halting.
10552
10553 @item @code{reboot-command} (default @code{#~(string-append #$shepherd "/sbin/reboot")})
10554 Command to run when rebooting.
10555
10556 @item @code{theme} (default "maldives")
10557 Theme to use. Default themes provided by SDDM are "elarun" or "maldives".
10558
10559 @item @code{themes-directory} (default "/run/current-system/profile/share/sddm/themes")
10560 Directory to look for themes.
10561
10562 @item @code{faces-directory} (default "/run/current-system/profile/share/sddm/faces")
10563 Directory to look for faces.
10564
10565 @item @code{default-path} (default "/run/current-system/profile/bin")
10566 Default PATH to use.
10567
10568 @item @code{minimum-uid} (default 1000)
10569 Minimum UID to display in SDDM.
10570
10571 @item @code{maximum-uid} (default 2000)
10572 Maximum UID to display in SDDM
10573
10574 @item @code{remember-last-user?} (default #t)
10575 Remember last user.
10576
10577 @item @code{remember-last-session?} (default #t)
10578 Remember last session.
10579
10580 @item @code{hide-users} (default "")
10581 Usernames to hide from SDDM greeter.
10582
10583 @item @code{hide-shells} (default @code{#~(string-append #$shadow "/sbin/nologin")})
10584 Users with shells listed will be hidden from the SDDM greeter.
10585
10586 @item @code{session-command} (default @code{#~(string-append #$sddm "/share/sddm/scripts/wayland-session")})
10587 Script to run before starting a wayland session.
10588
10589 @item @code{sessions-directory} (default "/run/current-system/profile/share/wayland-sessions")
10590 Directory to look for desktop files starting wayland sessions.
10591
10592 @item @code{xorg-server-path} (default @code{xorg-start-command})
10593 Path to xorg-server.
10594
10595 @item @code{xauth-path} (default @code{#~(string-append #$xauth "/bin/xauth")})
10596 Path to xauth.
10597
10598 @item @code{xephyr-path} (default @code{#~(string-append #$xorg-server "/bin/Xephyr")})
10599 Path to Xephyr.
10600
10601 @item @code{xdisplay-start} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xsetup")})
10602 Script to run after starting xorg-server.
10603
10604 @item @code{xdisplay-stop} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xstop")})
10605 Script to run before stopping xorg-server.
10606
10607 @item @code{xsession-command} (default: @code{xinitr })
10608 Script to run before starting a X session.
10609
10610 @item @code{xsessions-directory} (default: "/run/current-system/profile/share/xsessions")
10611 Directory to look for desktop files starting X sessions.
10612
10613 @item @code{minimum-vt} (default: 7)
10614 Minimum VT to use.
10615
10616 @item @code{xserver-arguments} (default "-nolisten tcp")
10617 Arguments to pass to xorg-server.
10618
10619 @item @code{auto-login-user} (default "")
10620 User to use for auto-login.
10621
10622 @item @code{auto-login-session} (default "")
10623 Desktop file to use for auto-login.
10624
10625 @item @code{relogin?} (default #f)
10626 Relogin after logout.
10627
10628 @end table
10629 @end deftp
10630
10631 @cindex login manager
10632 @deffn {Scheme Procedure} sddm-service config
10633 Return a service that spawns the SDDM graphical login manager for config of
10634 type @code{<sddm-configuration>}.
10635
10636 @example
10637 (sddm-service (sddm-configuration
10638 (auto-login-user "Alice")
10639 (auto-login-session "xfce.desktop")))
10640 @end example
10641 @end deffn
10642
10643 @deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
10644 [#:auto-login? #f] [#:default-user ""] [#:startx] @
10645 [#:theme @var{%default-slim-theme}] @
10646 [#:theme-name @var{%default-slim-theme-name}]
10647 Return a service that spawns the SLiM graphical login manager, which in
10648 turn starts the X display server with @var{startx}, a command as returned by
10649 @code{xorg-start-command}.
10650
10651 @cindex X session
10652
10653 SLiM automatically looks for session types described by the @file{.desktop}
10654 files in @file{/run/current-system/profile/share/xsessions} and allows users
10655 to choose a session from the log-in screen using @kbd{F1}. Packages such as
10656 @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
10657 adding them to the system-wide set of packages automatically makes them
10658 available at the log-in screen.
10659
10660 In addition, @file{~/.xsession} files are honored. When available,
10661 @file{~/.xsession} must be an executable that starts a window manager
10662 and/or other X clients.
10663
10664 When @var{allow-empty-passwords?} is true, allow logins with an empty
10665 password. When @var{auto-login?} is true, log in automatically as
10666 @var{default-user}.
10667
10668 If @var{theme} is @code{#f}, use the default log-in theme; otherwise
10669 @var{theme} must be a gexp denoting the name of a directory containing the
10670 theme to use. In that case, @var{theme-name} specifies the name of the
10671 theme.
10672 @end deffn
10673
10674 @defvr {Scheme Variable} %default-theme
10675 @defvrx {Scheme Variable} %default-theme-name
10676 The G-Expression denoting the default SLiM theme and its name.
10677 @end defvr
10678
10679 @deffn {Scheme Procedure} xorg-start-command [#:guile] @
10680 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
10681 Return a derivation that builds a @var{guile} script to start the X server
10682 from @var{xorg-server}. @var{configuration-file} is the server configuration
10683 file or a derivation that builds it; when omitted, the result of
10684 @code{xorg-configuration-file} is used.
10685
10686 Usually the X server is started by a login manager.
10687 @end deffn
10688
10689 @deffn {Scheme Procedure} xorg-configuration-file @
10690 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
10691 Return a configuration file for the Xorg server containing search paths for
10692 all the common drivers.
10693
10694 @var{drivers} must be either the empty list, in which case Xorg chooses a
10695 graphics driver automatically, or a list of driver names that will be tried in
10696 this order---e.g., @code{(\"modesetting\" \"vesa\")}.
10697
10698 Likewise, when @var{resolutions} is the empty list, Xorg chooses an
10699 appropriate screen resolution; otherwise, it must be a list of
10700 resolutions---e.g., @code{((1024 768) (640 480))}.
10701
10702 Last, @var{extra-config} is a list of strings or objects appended to the
10703 @code{text-file*} argument list. It is used to pass extra text to be added
10704 verbatim to the configuration file.
10705 @end deffn
10706
10707 @deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
10708 Add @var{package}, a package for a screen-locker or screen-saver whose
10709 command is @var{program}, to the set of setuid programs and add a PAM entry
10710 for it. For example:
10711
10712 @lisp
10713 (screen-locker-service xlockmore "xlock")
10714 @end lisp
10715
10716 makes the good ol' XlockMore usable.
10717 @end deffn
10718
10719
10720 @node Printing Services
10721 @subsubsection Printing Services
10722
10723 @cindex printer support with CUPS
10724 The @code{(gnu services cups)} module provides a Guix service definition
10725 for the CUPS printing service. To add printer support to a GuixSD
10726 system, add a @code{cups-service} to the operating system definition:
10727
10728 @deffn {Scheme Variable} cups-service-type
10729 The service type for the CUPS print server. Its value should be a valid
10730 CUPS configuration (see below). To use the default settings, simply
10731 write:
10732 @example
10733 (service cups-service-type)
10734 @end example
10735 @end deffn
10736
10737 The CUPS configuration controls the basic things about your CUPS
10738 installation: what interfaces it listens on, what to do if a print job
10739 fails, how much logging to do, and so on. To actually add a printer,
10740 you have to visit the @url{http://localhost:631} URL, or use a tool such
10741 as GNOME's printer configuration services. By default, configuring a
10742 CUPS service will generate a self-signed certificate if needed, for
10743 secure connections to the print server.
10744
10745 Suppose you want to enable the Web interface of CUPS and also add
10746 support for HP printers @i{via} the @code{hplip} package. You can do
10747 that directly, like this (you need to use the @code{(gnu packages cups)}
10748 module):
10749
10750 @example
10751 (service cups-service-type
10752 (cups-configuration
10753 (web-interface? #t)
10754 (extensions
10755 (list cups-filters hplip))))
10756 @end example
10757
10758 The available configuration parameters follow. Each parameter
10759 definition is preceded by its type; for example, @samp{string-list foo}
10760 indicates that the @code{foo} parameter should be specified as a list of
10761 strings. There is also a way to specify the configuration as a string,
10762 if you have an old @code{cupsd.conf} file that you want to port over
10763 from some other system; see the end for more details.
10764
10765 @c The following documentation was initially generated by
10766 @c (generate-documentation) in (gnu services cups). Manually maintained
10767 @c documentation is better, so we shouldn't hesitate to edit below as
10768 @c needed. However if the change you want to make to this documentation
10769 @c can be done in an automated way, it's probably easier to change
10770 @c (generate-documentation) than to make it below and have to deal with
10771 @c the churn as CUPS updates.
10772
10773
10774 Available @code{cups-configuration} fields are:
10775
10776 @deftypevr {@code{cups-configuration} parameter} package cups
10777 The CUPS package.
10778 @end deftypevr
10779
10780 @deftypevr {@code{cups-configuration} parameter} package-list extensions
10781 Drivers and other extensions to the CUPS package.
10782 @end deftypevr
10783
10784 @deftypevr {@code{cups-configuration} parameter} files-configuration files-configuration
10785 Configuration of where to write logs, what directories to use for print
10786 spools, and related privileged configuration parameters.
10787
10788 Available @code{files-configuration} fields are:
10789
10790 @deftypevr {@code{files-configuration} parameter} log-location access-log
10791 Defines the access log filename. Specifying a blank filename disables
10792 access log generation. The value @code{stderr} causes log entries to be
10793 sent to the standard error file when the scheduler is running in the
10794 foreground, or to the system log daemon when run in the background. The
10795 value @code{syslog} causes log entries to be sent to the system log
10796 daemon. The server name may be included in filenames using the string
10797 @code{%s}, as in @code{/var/log/cups/%s-access_log}.
10798
10799 Defaults to @samp{"/var/log/cups/access_log"}.
10800 @end deftypevr
10801
10802 @deftypevr {@code{files-configuration} parameter} file-name cache-dir
10803 Where CUPS should cache data.
10804
10805 Defaults to @samp{"/var/cache/cups"}.
10806 @end deftypevr
10807
10808 @deftypevr {@code{files-configuration} parameter} string config-file-perm
10809 Specifies the permissions for all configuration files that the scheduler
10810 writes.
10811
10812 Note that the permissions for the printers.conf file are currently
10813 masked to only allow access from the scheduler user (typically root).
10814 This is done because printer device URIs sometimes contain sensitive
10815 authentication information that should not be generally known on the
10816 system. There is no way to disable this security feature.
10817
10818 Defaults to @samp{"0640"}.
10819 @end deftypevr
10820
10821 @deftypevr {@code{files-configuration} parameter} log-location error-log
10822 Defines the error log filename. Specifying a blank filename disables
10823 access log generation. The value @code{stderr} causes log entries to be
10824 sent to the standard error file when the scheduler is running in the
10825 foreground, or to the system log daemon when run in the background. The
10826 value @code{syslog} causes log entries to be sent to the system log
10827 daemon. The server name may be included in filenames using the string
10828 @code{%s}, as in @code{/var/log/cups/%s-error_log}.
10829
10830 Defaults to @samp{"/var/log/cups/error_log"}.
10831 @end deftypevr
10832
10833 @deftypevr {@code{files-configuration} parameter} string fatal-errors
10834 Specifies which errors are fatal, causing the scheduler to exit. The
10835 kind strings are:
10836
10837 @table @code
10838 @item none
10839 No errors are fatal.
10840
10841 @item all
10842 All of the errors below are fatal.
10843
10844 @item browse
10845 Browsing initialization errors are fatal, for example failed connections
10846 to the DNS-SD daemon.
10847
10848 @item config
10849 Configuration file syntax errors are fatal.
10850
10851 @item listen
10852 Listen or Port errors are fatal, except for IPv6 failures on the
10853 loopback or @code{any} addresses.
10854
10855 @item log
10856 Log file creation or write errors are fatal.
10857
10858 @item permissions
10859 Bad startup file permissions are fatal, for example shared TLS
10860 certificate and key files with world-read permissions.
10861 @end table
10862
10863 Defaults to @samp{"all -browse"}.
10864 @end deftypevr
10865
10866 @deftypevr {@code{files-configuration} parameter} boolean file-device?
10867 Specifies whether the file pseudo-device can be used for new printer
10868 queues. The URI @uref{file:///dev/null} is always allowed.
10869
10870 Defaults to @samp{#f}.
10871 @end deftypevr
10872
10873 @deftypevr {@code{files-configuration} parameter} string group
10874 Specifies the group name or ID that will be used when executing external
10875 programs.
10876
10877 Defaults to @samp{"lp"}.
10878 @end deftypevr
10879
10880 @deftypevr {@code{files-configuration} parameter} string log-file-perm
10881 Specifies the permissions for all log files that the scheduler writes.
10882
10883 Defaults to @samp{"0644"}.
10884 @end deftypevr
10885
10886 @deftypevr {@code{files-configuration} parameter} log-location page-log
10887 Defines the page log filename. Specifying a blank filename disables
10888 access log generation. The value @code{stderr} causes log entries to be
10889 sent to the standard error file when the scheduler is running in the
10890 foreground, or to the system log daemon when run in the background. The
10891 value @code{syslog} causes log entries to be sent to the system log
10892 daemon. The server name may be included in filenames using the string
10893 @code{%s}, as in @code{/var/log/cups/%s-page_log}.
10894
10895 Defaults to @samp{"/var/log/cups/page_log"}.
10896 @end deftypevr
10897
10898 @deftypevr {@code{files-configuration} parameter} string remote-root
10899 Specifies the username that is associated with unauthenticated accesses
10900 by clients claiming to be the root user. The default is @code{remroot}.
10901
10902 Defaults to @samp{"remroot"}.
10903 @end deftypevr
10904
10905 @deftypevr {@code{files-configuration} parameter} file-name request-root
10906 Specifies the directory that contains print jobs and other HTTP request
10907 data.
10908
10909 Defaults to @samp{"/var/spool/cups"}.
10910 @end deftypevr
10911
10912 @deftypevr {@code{files-configuration} parameter} sandboxing sandboxing
10913 Specifies the level of security sandboxing that is applied to print
10914 filters, backends, and other child processes of the scheduler; either
10915 @code{relaxed} or @code{strict}. This directive is currently only
10916 used/supported on macOS.
10917
10918 Defaults to @samp{strict}.
10919 @end deftypevr
10920
10921 @deftypevr {@code{files-configuration} parameter} file-name server-keychain
10922 Specifies the location of TLS certificates and private keys. CUPS will
10923 look for public and private keys in this directory: a @code{.crt} files
10924 for PEM-encoded certificates and corresponding @code{.key} files for
10925 PEM-encoded private keys.
10926
10927 Defaults to @samp{"/etc/cups/ssl"}.
10928 @end deftypevr
10929
10930 @deftypevr {@code{files-configuration} parameter} file-name server-root
10931 Specifies the directory containing the server configuration files.
10932
10933 Defaults to @samp{"/etc/cups"}.
10934 @end deftypevr
10935
10936 @deftypevr {@code{files-configuration} parameter} boolean sync-on-close?
10937 Specifies whether the scheduler calls fsync(2) after writing
10938 configuration or state files.
10939
10940 Defaults to @samp{#f}.
10941 @end deftypevr
10942
10943 @deftypevr {@code{files-configuration} parameter} space-separated-string-list system-group
10944 Specifies the group(s) to use for @code{@@SYSTEM} group authentication.
10945 @end deftypevr
10946
10947 @deftypevr {@code{files-configuration} parameter} file-name temp-dir
10948 Specifies the directory where temporary files are stored.
10949
10950 Defaults to @samp{"/var/spool/cups/tmp"}.
10951 @end deftypevr
10952
10953 @deftypevr {@code{files-configuration} parameter} string user
10954 Specifies the user name or ID that is used when running external
10955 programs.
10956
10957 Defaults to @samp{"lp"}.
10958 @end deftypevr
10959 @end deftypevr
10960
10961 @deftypevr {@code{cups-configuration} parameter} access-log-level access-log-level
10962 Specifies the logging level for the AccessLog file. The @code{config}
10963 level logs when printers and classes are added, deleted, or modified and
10964 when configuration files are accessed or updated. The @code{actions}
10965 level logs when print jobs are submitted, held, released, modified, or
10966 canceled, and any of the conditions for @code{config}. The @code{all}
10967 level logs all requests.
10968
10969 Defaults to @samp{actions}.
10970 @end deftypevr
10971
10972 @deftypevr {@code{cups-configuration} parameter} boolean auto-purge-jobs?
10973 Specifies whether to purge job history data automatically when it is no
10974 longer required for quotas.
10975
10976 Defaults to @samp{#f}.
10977 @end deftypevr
10978
10979 @deftypevr {@code{cups-configuration} parameter} browse-local-protocols browse-local-protocols
10980 Specifies which protocols to use for local printer sharing.
10981
10982 Defaults to @samp{dnssd}.
10983 @end deftypevr
10984
10985 @deftypevr {@code{cups-configuration} parameter} boolean browse-web-if?
10986 Specifies whether the CUPS web interface is advertised.
10987
10988 Defaults to @samp{#f}.
10989 @end deftypevr
10990
10991 @deftypevr {@code{cups-configuration} parameter} boolean browsing?
10992 Specifies whether shared printers are advertised.
10993
10994 Defaults to @samp{#f}.
10995 @end deftypevr
10996
10997 @deftypevr {@code{cups-configuration} parameter} string classification
10998 Specifies the security classification of the server. Any valid banner
10999 name can be used, including "classified", "confidential", "secret",
11000 "topsecret", and "unclassified", or the banner can be omitted to disable
11001 secure printing functions.
11002
11003 Defaults to @samp{""}.
11004 @end deftypevr
11005
11006 @deftypevr {@code{cups-configuration} parameter} boolean classify-override?
11007 Specifies whether users may override the classification (cover page) of
11008 individual print jobs using the @code{job-sheets} option.
11009
11010 Defaults to @samp{#f}.
11011 @end deftypevr
11012
11013 @deftypevr {@code{cups-configuration} parameter} default-auth-type default-auth-type
11014 Specifies the default type of authentication to use.
11015
11016 Defaults to @samp{Basic}.
11017 @end deftypevr
11018
11019 @deftypevr {@code{cups-configuration} parameter} default-encryption default-encryption
11020 Specifies whether encryption will be used for authenticated requests.
11021
11022 Defaults to @samp{Required}.
11023 @end deftypevr
11024
11025 @deftypevr {@code{cups-configuration} parameter} string default-language
11026 Specifies the default language to use for text and web content.
11027
11028 Defaults to @samp{"en"}.
11029 @end deftypevr
11030
11031 @deftypevr {@code{cups-configuration} parameter} string default-paper-size
11032 Specifies the default paper size for new print queues. @samp{"Auto"}
11033 uses a locale-specific default, while @samp{"None"} specifies there is
11034 no default paper size. Specific size names are typically
11035 @samp{"Letter"} or @samp{"A4"}.
11036
11037 Defaults to @samp{"Auto"}.
11038 @end deftypevr
11039
11040 @deftypevr {@code{cups-configuration} parameter} string default-policy
11041 Specifies the default access policy to use.
11042
11043 Defaults to @samp{"default"}.
11044 @end deftypevr
11045
11046 @deftypevr {@code{cups-configuration} parameter} boolean default-shared?
11047 Specifies whether local printers are shared by default.
11048
11049 Defaults to @samp{#t}.
11050 @end deftypevr
11051
11052 @deftypevr {@code{cups-configuration} parameter} non-negative-integer dirty-clean-interval
11053 Specifies the delay for updating of configuration and state files, in
11054 seconds. A value of 0 causes the update to happen as soon as possible,
11055 typically within a few milliseconds.
11056
11057 Defaults to @samp{30}.
11058 @end deftypevr
11059
11060 @deftypevr {@code{cups-configuration} parameter} error-policy error-policy
11061 Specifies what to do when an error occurs. Possible values are
11062 @code{abort-job}, which will discard the failed print job;
11063 @code{retry-job}, which will retry the job at a later time;
11064 @code{retry-this-job}, which retries the failed job immediately; and
11065 @code{stop-printer}, which stops the printer.
11066
11067 Defaults to @samp{stop-printer}.
11068 @end deftypevr
11069
11070 @deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-limit
11071 Specifies the maximum cost of filters that are run concurrently, which
11072 can be used to minimize disk, memory, and CPU resource problems. A
11073 limit of 0 disables filter limiting. An average print to a
11074 non-PostScript printer needs a filter limit of about 200. A PostScript
11075 printer needs about half that (100). Setting the limit below these
11076 thresholds will effectively limit the scheduler to printing a single job
11077 at any time.
11078
11079 Defaults to @samp{0}.
11080 @end deftypevr
11081
11082 @deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-nice
11083 Specifies the scheduling priority of filters that are run to print a
11084 job. The nice value ranges from 0, the highest priority, to 19, the
11085 lowest priority.
11086
11087 Defaults to @samp{0}.
11088 @end deftypevr
11089
11090 @deftypevr {@code{cups-configuration} parameter} host-name-lookups host-name-lookups
11091 Specifies whether to do reverse lookups on connecting clients. The
11092 @code{double} setting causes @code{cupsd} to verify that the hostname
11093 resolved from the address matches one of the addresses returned for that
11094 hostname. Double lookups also prevent clients with unregistered
11095 addresses from connecting to your server. Only set this option to
11096 @code{#t} or @code{double} if absolutely required.
11097
11098 Defaults to @samp{#f}.
11099 @end deftypevr
11100
11101 @deftypevr {@code{cups-configuration} parameter} non-negative-integer job-kill-delay
11102 Specifies the number of seconds to wait before killing the filters and
11103 backend associated with a canceled or held job.
11104
11105 Defaults to @samp{30}.
11106 @end deftypevr
11107
11108 @deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-interval
11109 Specifies the interval between retries of jobs in seconds. This is
11110 typically used for fax queues but can also be used with normal print
11111 queues whose error policy is @code{retry-job} or
11112 @code{retry-current-job}.
11113
11114 Defaults to @samp{30}.
11115 @end deftypevr
11116
11117 @deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-limit
11118 Specifies the number of retries that are done for jobs. This is
11119 typically used for fax queues but can also be used with normal print
11120 queues whose error policy is @code{retry-job} or
11121 @code{retry-current-job}.
11122
11123 Defaults to @samp{5}.
11124 @end deftypevr
11125
11126 @deftypevr {@code{cups-configuration} parameter} boolean keep-alive?
11127 Specifies whether to support HTTP keep-alive connections.
11128
11129 Defaults to @samp{#t}.
11130 @end deftypevr
11131
11132 @deftypevr {@code{cups-configuration} parameter} non-negative-integer keep-alive-timeout
11133 Specifies how long an idle client connection remains open, in seconds.
11134
11135 Defaults to @samp{30}.
11136 @end deftypevr
11137
11138 @deftypevr {@code{cups-configuration} parameter} non-negative-integer limit-request-body
11139 Specifies the maximum size of print files, IPP requests, and HTML form
11140 data. A limit of 0 disables the limit check.
11141
11142 Defaults to @samp{0}.
11143 @end deftypevr
11144
11145 @deftypevr {@code{cups-configuration} parameter} multiline-string-list listen
11146 Listens on the specified interfaces for connections. Valid values are
11147 of the form @var{address}:@var{port}, where @var{address} is either an
11148 IPv6 address enclosed in brackets, an IPv4 address, or @code{*} to
11149 indicate all addresses. Values can also be file names of local UNIX
11150 domain sockets. The Listen directive is similar to the Port directive
11151 but allows you to restrict access to specific interfaces or networks.
11152 @end deftypevr
11153
11154 @deftypevr {@code{cups-configuration} parameter} non-negative-integer listen-back-log
11155 Specifies the number of pending connections that will be allowed. This
11156 normally only affects very busy servers that have reached the MaxClients
11157 limit, but can also be triggered by large numbers of simultaneous
11158 connections. When the limit is reached, the operating system will
11159 refuse additional connections until the scheduler can accept the pending
11160 ones.
11161
11162 Defaults to @samp{128}.
11163 @end deftypevr
11164
11165 @deftypevr {@code{cups-configuration} parameter} location-access-control-list location-access-controls
11166 Specifies a set of additional access controls.
11167
11168 Available @code{location-access-controls} fields are:
11169
11170 @deftypevr {@code{location-access-controls} parameter} file-name path
11171 Specifies the URI path to which the access control applies.
11172 @end deftypevr
11173
11174 @deftypevr {@code{location-access-controls} parameter} access-control-list access-controls
11175 Access controls for all access to this path, in the same format as the
11176 @code{access-controls} of @code{operation-access-control}.
11177
11178 Defaults to @samp{()}.
11179 @end deftypevr
11180
11181 @deftypevr {@code{location-access-controls} parameter} method-access-control-list method-access-controls
11182 Access controls for method-specific access to this path.
11183
11184 Defaults to @samp{()}.
11185
11186 Available @code{method-access-controls} fields are:
11187
11188 @deftypevr {@code{method-access-controls} parameter} boolean reverse?
11189 If @code{#t}, apply access controls to all methods except the listed
11190 methods. Otherwise apply to only the listed methods.
11191
11192 Defaults to @samp{#f}.
11193 @end deftypevr
11194
11195 @deftypevr {@code{method-access-controls} parameter} method-list methods
11196 Methods to which this access control applies.
11197
11198 Defaults to @samp{()}.
11199 @end deftypevr
11200
11201 @deftypevr {@code{method-access-controls} parameter} access-control-list access-controls
11202 Access control directives, as a list of strings. Each string should be
11203 one directive, such as "Order allow,deny".
11204
11205 Defaults to @samp{()}.
11206 @end deftypevr
11207 @end deftypevr
11208 @end deftypevr
11209
11210 @deftypevr {@code{cups-configuration} parameter} non-negative-integer log-debug-history
11211 Specifies the number of debugging messages that are retained for logging
11212 if an error occurs in a print job. Debug messages are logged regardless
11213 of the LogLevel setting.
11214
11215 Defaults to @samp{100}.
11216 @end deftypevr
11217
11218 @deftypevr {@code{cups-configuration} parameter} log-level log-level
11219 Specifies the level of logging for the ErrorLog file. The value
11220 @code{none} stops all logging while @code{debug2} logs everything.
11221
11222 Defaults to @samp{info}.
11223 @end deftypevr
11224
11225 @deftypevr {@code{cups-configuration} parameter} log-time-format log-time-format
11226 Specifies the format of the date and time in the log files. The value
11227 @code{standard} logs whole seconds while @code{usecs} logs microseconds.
11228
11229 Defaults to @samp{standard}.
11230 @end deftypevr
11231
11232 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients
11233 Specifies the maximum number of simultaneous clients that are allowed by
11234 the scheduler.
11235
11236 Defaults to @samp{100}.
11237 @end deftypevr
11238
11239 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients-per-host
11240 Specifies the maximum number of simultaneous clients that are allowed
11241 from a single address.
11242
11243 Defaults to @samp{100}.
11244 @end deftypevr
11245
11246 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-copies
11247 Specifies the maximum number of copies that a user can print of each
11248 job.
11249
11250 Defaults to @samp{9999}.
11251 @end deftypevr
11252
11253 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-hold-time
11254 Specifies the maximum time a job may remain in the @code{indefinite}
11255 hold state before it is canceled. A value of 0 disables cancellation of
11256 held jobs.
11257
11258 Defaults to @samp{0}.
11259 @end deftypevr
11260
11261 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs
11262 Specifies the maximum number of simultaneous jobs that are allowed. Set
11263 to 0 to allow an unlimited number of jobs.
11264
11265 Defaults to @samp{500}.
11266 @end deftypevr
11267
11268 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-printer
11269 Specifies the maximum number of simultaneous jobs that are allowed per
11270 printer. A value of 0 allows up to MaxJobs jobs per printer.
11271
11272 Defaults to @samp{0}.
11273 @end deftypevr
11274
11275 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-user
11276 Specifies the maximum number of simultaneous jobs that are allowed per
11277 user. A value of 0 allows up to MaxJobs jobs per user.
11278
11279 Defaults to @samp{0}.
11280 @end deftypevr
11281
11282 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-job-time
11283 Specifies the maximum time a job may take to print before it is
11284 canceled, in seconds. Set to 0 to disable cancellation of "stuck" jobs.
11285
11286 Defaults to @samp{10800}.
11287 @end deftypevr
11288
11289 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-log-size
11290 Specifies the maximum size of the log files before they are rotated, in
11291 bytes. The value 0 disables log rotation.
11292
11293 Defaults to @samp{1048576}.
11294 @end deftypevr
11295
11296 @deftypevr {@code{cups-configuration} parameter} non-negative-integer multiple-operation-timeout
11297 Specifies the maximum amount of time to allow between files in a
11298 multiple file print job, in seconds.
11299
11300 Defaults to @samp{300}.
11301 @end deftypevr
11302
11303 @deftypevr {@code{cups-configuration} parameter} string page-log-format
11304 Specifies the format of PageLog lines. Sequences beginning with percent
11305 (@samp{%}) characters are replaced with the corresponding information,
11306 while all other characters are copied literally. The following percent
11307 sequences are recognized:
11308
11309 @table @samp
11310 @item %%
11311 insert a single percent character
11312
11313 @item %@{name@}
11314 insert the value of the specified IPP attribute
11315
11316 @item %C
11317 insert the number of copies for the current page
11318
11319 @item %P
11320 insert the current page number
11321
11322 @item %T
11323 insert the current date and time in common log format
11324
11325 @item %j
11326 insert the job ID
11327
11328 @item %p
11329 insert the printer name
11330
11331 @item %u
11332 insert the username
11333 @end table
11334
11335 A value of the empty string disables page logging. The string @code{%p
11336 %u %j %T %P %C %@{job-billing@} %@{job-originating-host-name@}
11337 %@{job-name@} %@{media@} %@{sides@}} creates a page log with the
11338 standard items.
11339
11340 Defaults to @samp{""}.
11341 @end deftypevr
11342
11343 @deftypevr {@code{cups-configuration} parameter} environment-variables environment-variables
11344 Passes the specified environment variable(s) to child processes; a list
11345 of strings.
11346
11347 Defaults to @samp{()}.
11348 @end deftypevr
11349
11350 @deftypevr {@code{cups-configuration} parameter} policy-configuration-list policies
11351 Specifies named access control policies.
11352
11353 Available @code{policy-configuration} fields are:
11354
11355 @deftypevr {@code{policy-configuration} parameter} string name
11356 Name of the policy.
11357 @end deftypevr
11358
11359 @deftypevr {@code{policy-configuration} parameter} string job-private-access
11360 Specifies an access list for a job's private values. @code{@@ACL} maps
11361 to the printer's requesting-user-name-allowed or
11362 requesting-user-name-denied values. @code{@@OWNER} maps to the job's
11363 owner. @code{@@SYSTEM} maps to the groups listed for the
11364 @code{system-group} field of the @code{files-config} configuration,
11365 which is reified into the @code{cups-files.conf(5)} file. Other
11366 possible elements of the access list include specific user names, and
11367 @code{@@@var{group}} to indicate members of a specific group. The
11368 access list may also be simply @code{all} or @code{default}.
11369
11370 Defaults to @samp{"@@OWNER @@SYSTEM"}.
11371 @end deftypevr
11372
11373 @deftypevr {@code{policy-configuration} parameter} string job-private-values
11374 Specifies the list of job values to make private, or @code{all},
11375 @code{default}, or @code{none}.
11376
11377 Defaults to @samp{"job-name job-originating-host-name
11378 job-originating-user-name phone"}.
11379 @end deftypevr
11380
11381 @deftypevr {@code{policy-configuration} parameter} string subscription-private-access
11382 Specifies an access list for a subscription's private values.
11383 @code{@@ACL} maps to the printer's requesting-user-name-allowed or
11384 requesting-user-name-denied values. @code{@@OWNER} maps to the job's
11385 owner. @code{@@SYSTEM} maps to the groups listed for the
11386 @code{system-group} field of the @code{files-config} configuration,
11387 which is reified into the @code{cups-files.conf(5)} file. Other
11388 possible elements of the access list include specific user names, and
11389 @code{@@@var{group}} to indicate members of a specific group. The
11390 access list may also be simply @code{all} or @code{default}.
11391
11392 Defaults to @samp{"@@OWNER @@SYSTEM"}.
11393 @end deftypevr
11394
11395 @deftypevr {@code{policy-configuration} parameter} string subscription-private-values
11396 Specifies the list of job values to make private, or @code{all},
11397 @code{default}, or @code{none}.
11398
11399 Defaults to @samp{"notify-events notify-pull-method notify-recipient-uri
11400 notify-subscriber-user-name notify-user-data"}.
11401 @end deftypevr
11402
11403 @deftypevr {@code{policy-configuration} parameter} operation-access-control-list access-controls
11404 Access control by IPP operation.
11405
11406 Defaults to @samp{()}.
11407 @end deftypevr
11408 @end deftypevr
11409
11410 @deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-files
11411 Specifies whether job files (documents) are preserved after a job is
11412 printed. If a numeric value is specified, job files are preserved for
11413 the indicated number of seconds after printing. Otherwise a boolean
11414 value applies indefinitely.
11415
11416 Defaults to @samp{86400}.
11417 @end deftypevr
11418
11419 @deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-history
11420 Specifies whether the job history is preserved after a job is printed.
11421 If a numeric value is specified, the job history is preserved for the
11422 indicated number of seconds after printing. If @code{#t}, the job
11423 history is preserved until the MaxJobs limit is reached.
11424
11425 Defaults to @samp{#t}.
11426 @end deftypevr
11427
11428 @deftypevr {@code{cups-configuration} parameter} non-negative-integer reload-timeout
11429 Specifies the amount of time to wait for job completion before
11430 restarting the scheduler.
11431
11432 Defaults to @samp{30}.
11433 @end deftypevr
11434
11435 @deftypevr {@code{cups-configuration} parameter} string rip-cache
11436 Specifies the maximum amount of memory to use when converting documents
11437 into bitmaps for a printer.
11438
11439 Defaults to @samp{"128m"}.
11440 @end deftypevr
11441
11442 @deftypevr {@code{cups-configuration} parameter} string server-admin
11443 Specifies the email address of the server administrator.
11444
11445 Defaults to @samp{"root@@localhost.localdomain"}.
11446 @end deftypevr
11447
11448 @deftypevr {@code{cups-configuration} parameter} host-name-list-or-* server-alias
11449 The ServerAlias directive is used for HTTP Host header validation when
11450 clients connect to the scheduler from external interfaces. Using the
11451 special name @code{*} can expose your system to known browser-based DNS
11452 rebinding attacks, even when accessing sites through a firewall. If the
11453 auto-discovery of alternate names does not work, we recommend listing
11454 each alternate name with a ServerAlias directive instead of using
11455 @code{*}.
11456
11457 Defaults to @samp{*}.
11458 @end deftypevr
11459
11460 @deftypevr {@code{cups-configuration} parameter} string server-name
11461 Specifies the fully-qualified host name of the server.
11462
11463 Defaults to @samp{"localhost"}.
11464 @end deftypevr
11465
11466 @deftypevr {@code{cups-configuration} parameter} server-tokens server-tokens
11467 Specifies what information is included in the Server header of HTTP
11468 responses. @code{None} disables the Server header. @code{ProductOnly}
11469 reports @code{CUPS}. @code{Major} reports @code{CUPS 2}. @code{Minor}
11470 reports @code{CUPS 2.0}. @code{Minimal} reports @code{CUPS 2.0.0}.
11471 @code{OS} reports @code{CUPS 2.0.0 (@var{uname})} where @var{uname} is
11472 the output of the @code{uname} command. @code{Full} reports @code{CUPS
11473 2.0.0 (@var{uname}) IPP/2.0}.
11474
11475 Defaults to @samp{Minimal}.
11476 @end deftypevr
11477
11478 @deftypevr {@code{cups-configuration} parameter} string set-env
11479 Set the specified environment variable to be passed to child processes.
11480
11481 Defaults to @samp{"variable value"}.
11482 @end deftypevr
11483
11484 @deftypevr {@code{cups-configuration} parameter} multiline-string-list ssl-listen
11485 Listens on the specified interfaces for encrypted connections. Valid
11486 values are of the form @var{address}:@var{port}, where @var{address} is
11487 either an IPv6 address enclosed in brackets, an IPv4 address, or
11488 @code{*} to indicate all addresses.
11489
11490 Defaults to @samp{()}.
11491 @end deftypevr
11492
11493 @deftypevr {@code{cups-configuration} parameter} ssl-options ssl-options
11494 Sets encryption options. By default, CUPS only supports encryption
11495 using TLS v1.0 or higher using known secure cipher suites. The
11496 @code{AllowRC4} option enables the 128-bit RC4 cipher suites, which are
11497 required for some older clients that do not implement newer ones. The
11498 @code{AllowSSL3} option enables SSL v3.0, which is required for some
11499 older clients that do not support TLS v1.0.
11500
11501 Defaults to @samp{()}.
11502 @end deftypevr
11503
11504 @deftypevr {@code{cups-configuration} parameter} boolean strict-conformance?
11505 Specifies whether the scheduler requires clients to strictly adhere to
11506 the IPP specifications.
11507
11508 Defaults to @samp{#f}.
11509 @end deftypevr
11510
11511 @deftypevr {@code{cups-configuration} parameter} non-negative-integer timeout
11512 Specifies the HTTP request timeout, in seconds.
11513
11514 Defaults to @samp{300}.
11515
11516 @end deftypevr
11517
11518 @deftypevr {@code{cups-configuration} parameter} boolean web-interface?
11519 Specifies whether the web interface is enabled.
11520
11521 Defaults to @samp{#f}.
11522 @end deftypevr
11523
11524 At this point you're probably thinking ``oh dear, Guix manual, I like
11525 you but you can stop already with the configuration options''. Indeed.
11526 However, one more point: it could be that you have an existing
11527 @code{cupsd.conf} that you want to use. In that case, you can pass an
11528 @code{opaque-cups-configuration} as the configuration of a
11529 @code{cups-service-type}.
11530
11531 Available @code{opaque-cups-configuration} fields are:
11532
11533 @deftypevr {@code{opaque-cups-configuration} parameter} package cups
11534 The CUPS package.
11535 @end deftypevr
11536
11537 @deftypevr {@code{opaque-cups-configuration} parameter} string cupsd.conf
11538 The contents of the @code{cupsd.conf}, as a string.
11539 @end deftypevr
11540
11541 @deftypevr {@code{opaque-cups-configuration} parameter} string cups-files.conf
11542 The contents of the @code{cups-files.conf} file, as a string.
11543 @end deftypevr
11544
11545 For example, if your @code{cupsd.conf} and @code{cups-files.conf} are in
11546 strings of the same name, you could instantiate a CUPS service like
11547 this:
11548
11549 @example
11550 (service cups-service-type
11551 (opaque-cups-configuration
11552 (cupsd.conf cupsd.conf)
11553 (cups-files.conf cups-files.conf)))
11554 @end example
11555
11556
11557 @node Desktop Services
11558 @subsubsection Desktop Services
11559
11560 The @code{(gnu services desktop)} module provides services that are
11561 usually useful in the context of a ``desktop'' setup---that is, on a
11562 machine running a graphical display server, possibly with graphical user
11563 interfaces, etc. It also defines services that provide specific desktop
11564 environments like GNOME and XFCE.
11565
11566 To simplify things, the module defines a variable containing the set of
11567 services that users typically expect on a machine with a graphical
11568 environment and networking:
11569
11570 @defvr {Scheme Variable} %desktop-services
11571 This is a list of services that builds upon @var{%base-services} and
11572 adds or adjusts services for a typical ``desktop'' setup.
11573
11574 In particular, it adds a graphical login manager (@pxref{X Window,
11575 @code{slim-service}}), screen lockers, a network management tool
11576 (@pxref{Networking Services, @code{wicd-service}}), energy and color
11577 management services, the @code{elogind} login and seat manager, the
11578 Polkit privilege service, the GeoClue location service, the
11579 AccountsService daemon that allows authorized users change system
11580 passwords, an NTP client (@pxref{Networking Services}), the Avahi
11581 daemon, and has the name service switch service configured to be able to
11582 use @code{nss-mdns} (@pxref{Name Service Switch, mDNS}).
11583 @end defvr
11584
11585 The @var{%desktop-services} variable can be used as the @code{services}
11586 field of an @code{operating-system} declaration (@pxref{operating-system
11587 Reference, @code{services}}).
11588
11589 Additionally, the @code{gnome-desktop-service} and
11590 @code{xfce-desktop-service} procedures can add GNOME and/or XFCE to a
11591 system. To ``add GNOME'' means that system-level services like the
11592 backlight adjustment helpers and the power management utilities are
11593 added to the system, extending @code{polkit} and @code{dbus}
11594 appropriately, allowing GNOME to operate with elevated privileges on a
11595 limited number of special-purpose system interfaces. Additionally,
11596 adding a service made by @code{gnome-desktop-service} adds the GNOME
11597 metapackage to the system profile. Likewise, adding the XFCE service
11598 not only adds the @code{xfce} metapackage to the system profile, but it
11599 also gives the Thunar file manager the ability to open a ``root-mode''
11600 file management window, if the user authenticates using the
11601 administrator's password via the standard polkit graphical interface.
11602
11603 @deffn {Scheme Procedure} gnome-desktop-service
11604 Return a service that adds the @code{gnome} package to the system
11605 profile, and extends polkit with the actions from
11606 @code{gnome-settings-daemon}.
11607 @end deffn
11608
11609 @deffn {Scheme Procedure} xfce-desktop-service
11610 Return a service that adds the @code{xfce} package to the system profile,
11611 and extends polkit with the ability for @code{thunar} to manipulate the
11612 file system as root from within a user session, after the user has
11613 authenticated with the administrator's password.
11614 @end deffn
11615
11616 Because the GNOME and XFCE desktop services pull in so many packages,
11617 the default @code{%desktop-services} variable doesn't include either of
11618 them by default. To add GNOME or XFCE, just @code{cons} them onto
11619 @code{%desktop-services} in the @code{services} field of your
11620 @code{operating-system}:
11621
11622 @example
11623 (use-modules (gnu))
11624 (use-service-modules desktop)
11625 (operating-system
11626 ...
11627 ;; cons* adds items to the list given as its last argument.
11628 (services (cons* (gnome-desktop-service)
11629 (xfce-desktop-service)
11630 %desktop-services))
11631 ...)
11632 @end example
11633
11634 These desktop environments will then be available as options in the
11635 graphical login window.
11636
11637 The actual service definitions included in @code{%desktop-services} and
11638 provided by @code{(gnu services dbus)} and @code{(gnu services desktop)}
11639 are described below.
11640
11641 @deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
11642 Return a service that runs the ``system bus'', using @var{dbus}, with
11643 support for @var{services}.
11644
11645 @uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
11646 facility. Its system bus is used to allow system services to communicate
11647 and to be notified of system-wide events.
11648
11649 @var{services} must be a list of packages that provide an
11650 @file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
11651 and policy files. For example, to allow avahi-daemon to use the system bus,
11652 @var{services} must be equal to @code{(list avahi)}.
11653 @end deffn
11654
11655 @deffn {Scheme Procedure} elogind-service [#:config @var{config}]
11656 Return a service that runs the @code{elogind} login and
11657 seat management daemon. @uref{https://github.com/andywingo/elogind,
11658 Elogind} exposes a D-Bus interface that can be used to know which users
11659 are logged in, know what kind of sessions they have open, suspend the
11660 system, inhibit system suspend, reboot the system, and other tasks.
11661
11662 Elogind handles most system-level power events for a computer, for
11663 example suspending the system when a lid is closed, or shutting it down
11664 when the power button is pressed.
11665
11666 The @var{config} keyword argument specifies the configuration for
11667 elogind, and should be the result of an @code{(elogind-configuration
11668 (@var{parameter} @var{value})...)} invocation. Available parameters and
11669 their default values are:
11670
11671 @table @code
11672 @item kill-user-processes?
11673 @code{#f}
11674 @item kill-only-users
11675 @code{()}
11676 @item kill-exclude-users
11677 @code{("root")}
11678 @item inhibit-delay-max-seconds
11679 @code{5}
11680 @item handle-power-key
11681 @code{poweroff}
11682 @item handle-suspend-key
11683 @code{suspend}
11684 @item handle-hibernate-key
11685 @code{hibernate}
11686 @item handle-lid-switch
11687 @code{suspend}
11688 @item handle-lid-switch-docked
11689 @code{ignore}
11690 @item power-key-ignore-inhibited?
11691 @code{#f}
11692 @item suspend-key-ignore-inhibited?
11693 @code{#f}
11694 @item hibernate-key-ignore-inhibited?
11695 @code{#f}
11696 @item lid-switch-ignore-inhibited?
11697 @code{#t}
11698 @item holdoff-timeout-seconds
11699 @code{30}
11700 @item idle-action
11701 @code{ignore}
11702 @item idle-action-seconds
11703 @code{(* 30 60)}
11704 @item runtime-directory-size-percent
11705 @code{10}
11706 @item runtime-directory-size
11707 @code{#f}
11708 @item remove-ipc?
11709 @code{#t}
11710 @item suspend-state
11711 @code{("mem" "standby" "freeze")}
11712 @item suspend-mode
11713 @code{()}
11714 @item hibernate-state
11715 @code{("disk")}
11716 @item hibernate-mode
11717 @code{("platform" "shutdown")}
11718 @item hybrid-sleep-state
11719 @code{("disk")}
11720 @item hybrid-sleep-mode
11721 @code{("suspend" "platform" "shutdown")}
11722 @end table
11723 @end deffn
11724
11725 @deffn {Scheme Procedure} accountsservice-service @
11726 [#:accountsservice @var{accountsservice}]
11727 Return a service that runs AccountsService, a system service that can
11728 list available accounts, change their passwords, and so on.
11729 AccountsService integrates with PolicyKit to enable unprivileged users
11730 to acquire the capability to modify their system configuration.
11731 @uref{https://www.freedesktop.org/wiki/Software/AccountsService/, the
11732 accountsservice web site} for more information.
11733
11734 The @var{accountsservice} keyword argument is the @code{accountsservice}
11735 package to expose as a service.
11736 @end deffn
11737
11738 @deffn {Scheme Procedure} polkit-service @
11739 [#:polkit @var{polkit}]
11740 Return a service that runs the
11741 @uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
11742 management service}, which allows system administrators to grant access to
11743 privileged operations in a structured way. By querying the Polkit service, a
11744 privileged system component can know when it should grant additional
11745 capabilities to ordinary users. For example, an ordinary user can be granted
11746 the capability to suspend the system if the user is logged in locally.
11747 @end deffn
11748
11749 @deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
11750 [#:watts-up-pro? #f] @
11751 [#:poll-batteries? #t] @
11752 [#:ignore-lid? #f] @
11753 [#:use-percentage-for-policy? #f] @
11754 [#:percentage-low 10] @
11755 [#:percentage-critical 3] @
11756 [#:percentage-action 2] @
11757 [#:time-low 1200] @
11758 [#:time-critical 300] @
11759 [#:time-action 120] @
11760 [#:critical-power-action 'hybrid-sleep]
11761 Return a service that runs @uref{http://upower.freedesktop.org/,
11762 @command{upowerd}}, a system-wide monitor for power consumption and battery
11763 levels, with the given configuration settings. It implements the
11764 @code{org.freedesktop.UPower} D-Bus interface, and is notably used by
11765 GNOME.
11766 @end deffn
11767
11768 @deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
11769 Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
11770 UDisks}, a @dfn{disk management} daemon that provides user interfaces with
11771 notifications and ways to mount/unmount disks. Programs that talk to UDisks
11772 include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
11773 @end deffn
11774
11775 @deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
11776 Return a service that runs @command{colord}, a system service with a D-Bus
11777 interface to manage the color profiles of input and output devices such as
11778 screens and scanners. It is notably used by the GNOME Color Manager graphical
11779 tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
11780 site} for more information.
11781 @end deffn
11782
11783 @deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
11784 Return a configuration allowing an application to access GeoClue
11785 location data. @var{name} is the Desktop ID of the application, without
11786 the @code{.desktop} part. If @var{allowed?} is true, the application
11787 will have access to location information by default. The boolean
11788 @var{system?} value indicates whether an application is a system component
11789 or not. Finally @var{users} is a list of UIDs of all users for which
11790 this application is allowed location info access. An empty users list
11791 means that all users are allowed.
11792 @end deffn
11793
11794 @defvr {Scheme Variable} %standard-geoclue-applications
11795 The standard list of well-known GeoClue application configurations,
11796 granting authority to the GNOME date-and-time utility to ask for the
11797 current location in order to set the time zone, and allowing the
11798 IceCat and Epiphany web browsers to request location information.
11799 IceCat and Epiphany both query the user before allowing a web page to
11800 know the user's location.
11801 @end defvr
11802
11803 @deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
11804 [#:whitelist '()] @
11805 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
11806 [#:submit-data? #f]
11807 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
11808 [#:submission-nick "geoclue"] @
11809 [#:applications %standard-geoclue-applications]
11810 Return a service that runs the GeoClue location service. This service
11811 provides a D-Bus interface to allow applications to request access to a
11812 user's physical location, and optionally to add information to online
11813 location databases. See
11814 @uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
11815 web site} for more information.
11816 @end deffn
11817
11818 @deffn {Scheme Procedure} bluetooth-service [#:bluez @var{bluez}]
11819 Return a service that runs the @command{bluetoothd} daemon, which manages
11820 all the Bluetooth devices and provides a number of D-Bus interfaces.
11821
11822 Users need to be in the @code{lp} group to access the D-Bus service.
11823 @end deffn
11824
11825 @node Database Services
11826 @subsubsection Database Services
11827
11828 @cindex database
11829 @cindex SQL
11830 The @code{(gnu services databases)} module provides the following services.
11831
11832 @deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
11833 [#:config-file] [#:data-directory ``/var/lib/postgresql/data''] @
11834 [#:port 5432] [#:locale ``en_US.utf8'']
11835 Return a service that runs @var{postgresql}, the PostgreSQL database
11836 server.
11837
11838 The PostgreSQL daemon loads its runtime configuration from @var{config-file},
11839 creates a database cluster with @var{locale} as the default
11840 locale, stored in @var{data-directory}. It then listens on @var{port}.
11841 @end deffn
11842
11843 @deffn {Scheme Procedure} mysql-service [#:config (mysql-configuration)]
11844 Return a service that runs @command{mysqld}, the MySQL or MariaDB
11845 database server.
11846
11847 The optional @var{config} argument specifies the configuration for
11848 @command{mysqld}, which should be a @code{<mysql-configuration>} object.
11849 @end deffn
11850
11851 @deftp {Data Type} mysql-configuration
11852 Data type representing the configuration of @var{mysql-service}.
11853
11854 @table @asis
11855 @item @code{mysql} (default: @var{mariadb})
11856 Package object of the MySQL database server, can be either @var{mariadb}
11857 or @var{mysql}.
11858
11859 For MySQL, a temporary root password will be displayed at activation time.
11860 For MariaDB, the root password is empty.
11861
11862 @item @code{port} (default: @code{3306})
11863 TCP port on which the database server listens for incoming connections.
11864 @end table
11865 @end deftp
11866
11867 @defvr {Scheme Variable} memcached-service-type
11868 This is the service type for the @uref{https://memcached.org/,
11869 Memcached} service, which provides a distributed in memory cache. The
11870 value for the service type is a @code{memcached-configuration} object.
11871 @end defvr
11872
11873 @example
11874 (service memcached-service-type)
11875 @end example
11876
11877 @deftp {Data Type} memcached-configuration
11878 Data type representing the configuration of memcached.
11879
11880 @table @asis
11881 @item @code{memcached} (default: @code{memcached})
11882 The Memcached package to use.
11883
11884 @item @code{interfaces} (default: @code{'("0.0.0.0")})
11885 Network interfaces on which to listen.
11886
11887 @item @code{tcp-port} (default: @code{11211})
11888 Port on which to accept connections on,
11889
11890 @item @code{udp-port} (default: @code{11211})
11891 Port on which to accept UDP connections on, a value of 0 will disable
11892 listening on a UDP socket.
11893
11894 @item @code{additional-options} (default: @code{'()})
11895 Additional command line options to pass to @code{memcached}.
11896 @end table
11897 @end deftp
11898
11899 @defvr {Scheme Variable} redis-service-type
11900 This is the service type for the @uref{https://redis.io/, Redis}
11901 key/value store, whose value is a @code{redis-configuration} object.
11902 @end defvr
11903
11904 @deftp {Data Type} redis-configuration
11905 Data type representing the configuration of redis.
11906
11907 @table @asis
11908 @item @code{redis} (default: @code{redis})
11909 The Redis package to use.
11910
11911 @item @code{bind} (default: @code{"127.0.0.1"})
11912 Network interface on which to listen.
11913
11914 @item @code{port} (default: @code{6379})
11915 Port on which to accept connections on, a value of 0 will disable
11916 listening on a TCP socket.
11917
11918 @item @code{working-directory} (default: @code{"/var/lib/redis"})
11919 Directory in which to store the database and related files.
11920 @end table
11921 @end deftp
11922
11923 @node Mail Services
11924 @subsubsection Mail Services
11925
11926 @cindex mail
11927 @cindex email
11928 The @code{(gnu services mail)} module provides Guix service definitions
11929 for email services: IMAP, POP3, and LMTP servers, as well as mail
11930 transport agents (MTAs). Lots of acronyms! These services are detailed
11931 in the subsections below.
11932
11933 @subsubheading Dovecot Service
11934
11935 @deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
11936 Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
11937 @end deffn
11938
11939 By default, Dovecot does not need much configuration; the default
11940 configuration object created by @code{(dovecot-configuration)} will
11941 suffice if your mail is delivered to @code{~/Maildir}. A self-signed
11942 certificate will be generated for TLS-protected connections, though
11943 Dovecot will also listen on cleartext ports by default. There are a
11944 number of options, though, which mail administrators might need to change,
11945 and as is the case with other services, Guix allows the system
11946 administrator to specify these parameters via a uniform Scheme interface.
11947
11948 For example, to specify that mail is located at @code{maildir~/.mail},
11949 one would instantiate the Dovecot service like this:
11950
11951 @example
11952 (dovecot-service #:config
11953 (dovecot-configuration
11954 (mail-location "maildir:~/.mail")))
11955 @end example
11956
11957 The available configuration parameters follow. Each parameter
11958 definition is preceded by its type; for example, @samp{string-list foo}
11959 indicates that the @code{foo} parameter should be specified as a list of
11960 strings. There is also a way to specify the configuration as a string,
11961 if you have an old @code{dovecot.conf} file that you want to port over
11962 from some other system; see the end for more details.
11963
11964 @c The following documentation was initially generated by
11965 @c (generate-documentation) in (gnu services mail). Manually maintained
11966 @c documentation is better, so we shouldn't hesitate to edit below as
11967 @c needed. However if the change you want to make to this documentation
11968 @c can be done in an automated way, it's probably easier to change
11969 @c (generate-documentation) than to make it below and have to deal with
11970 @c the churn as dovecot updates.
11971
11972 Available @code{dovecot-configuration} fields are:
11973
11974 @deftypevr {@code{dovecot-configuration} parameter} package dovecot
11975 The dovecot package.
11976 @end deftypevr
11977
11978 @deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
11979 A list of IPs or hosts where to listen for connections. @samp{*}
11980 listens on all IPv4 interfaces, @samp{::} listens on all IPv6
11981 interfaces. If you want to specify non-default ports or anything more
11982 complex, customize the address and port fields of the
11983 @samp{inet-listener} of the specific services you are interested in.
11984 @end deftypevr
11985
11986 @deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
11987 List of protocols we want to serve. Available protocols include
11988 @samp{imap}, @samp{pop3}, and @samp{lmtp}.
11989
11990 Available @code{protocol-configuration} fields are:
11991
11992 @deftypevr {@code{protocol-configuration} parameter} string name
11993 The name of the protocol.
11994 @end deftypevr
11995
11996 @deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
11997 UNIX socket path to the master authentication server to find users.
11998 This is used by imap (for shared users) and lda.
11999 It defaults to @samp{"/var/run/dovecot/auth-userdb"}.
12000 @end deftypevr
12001
12002 @deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
12003 Space separated list of plugins to load.
12004 @end deftypevr
12005
12006 @deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
12007 Maximum number of IMAP connections allowed for a user from each IP
12008 address. NOTE: The username is compared case-sensitively.
12009 Defaults to @samp{10}.
12010 @end deftypevr
12011
12012 @end deftypevr
12013
12014 @deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
12015 List of services to enable. Available services include @samp{imap},
12016 @samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
12017 @samp{lmtp}.
12018
12019 Available @code{service-configuration} fields are:
12020
12021 @deftypevr {@code{service-configuration} parameter} string kind
12022 The service kind. Valid values include @code{director},
12023 @code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
12024 @code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
12025 @code{tcpwrap}, @code{quota-warning}, or anything else.
12026 @end deftypevr
12027
12028 @deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
12029 Listeners for the service. A listener is either a
12030 @code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
12031 an @code{inet-listener-configuration}.
12032 Defaults to @samp{()}.
12033
12034 Available @code{unix-listener-configuration} fields are:
12035
12036 @deftypevr {@code{unix-listener-configuration} parameter} string path
12037 Path to the file, relative to @code{base-dir} field. This is also used as
12038 the section name.
12039 @end deftypevr
12040
12041 @deftypevr {@code{unix-listener-configuration} parameter} string mode
12042 The access mode for the socket.
12043 Defaults to @samp{"0600"}.
12044 @end deftypevr
12045
12046 @deftypevr {@code{unix-listener-configuration} parameter} string user
12047 The user to own the socket.
12048 Defaults to @samp{""}.
12049 @end deftypevr
12050
12051 @deftypevr {@code{unix-listener-configuration} parameter} string group
12052 The group to own the socket.
12053 Defaults to @samp{""}.
12054 @end deftypevr
12055
12056
12057 Available @code{fifo-listener-configuration} fields are:
12058
12059 @deftypevr {@code{fifo-listener-configuration} parameter} string path
12060 Path to the file, relative to @code{base-dir} field. This is also used as
12061 the section name.
12062 @end deftypevr
12063
12064 @deftypevr {@code{fifo-listener-configuration} parameter} string mode
12065 The access mode for the socket.
12066 Defaults to @samp{"0600"}.
12067 @end deftypevr
12068
12069 @deftypevr {@code{fifo-listener-configuration} parameter} string user
12070 The user to own the socket.
12071 Defaults to @samp{""}.
12072 @end deftypevr
12073
12074 @deftypevr {@code{fifo-listener-configuration} parameter} string group
12075 The group to own the socket.
12076 Defaults to @samp{""}.
12077 @end deftypevr
12078
12079
12080 Available @code{inet-listener-configuration} fields are:
12081
12082 @deftypevr {@code{inet-listener-configuration} parameter} string protocol
12083 The protocol to listen for.
12084 @end deftypevr
12085
12086 @deftypevr {@code{inet-listener-configuration} parameter} string address
12087 The address on which to listen, or empty for all addresses.
12088 Defaults to @samp{""}.
12089 @end deftypevr
12090
12091 @deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
12092 The port on which to listen.
12093 @end deftypevr
12094
12095 @deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
12096 Whether to use SSL for this service; @samp{yes}, @samp{no}, or
12097 @samp{required}.
12098 Defaults to @samp{#t}.
12099 @end deftypevr
12100
12101 @end deftypevr
12102
12103 @deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
12104 Number of connections to handle before starting a new process.
12105 Typically the only useful values are 0 (unlimited) or 1. 1 is more
12106 secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
12107 Defaults to @samp{1}.
12108 @end deftypevr
12109
12110 @deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
12111 Number of processes to always keep waiting for more connections.
12112 Defaults to @samp{0}.
12113 @end deftypevr
12114
12115 @deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
12116 If you set @samp{service-count 0}, you probably need to grow
12117 this.
12118 Defaults to @samp{256000000}.
12119 @end deftypevr
12120
12121 @end deftypevr
12122
12123 @deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
12124 Dict configuration, as created by the @code{dict-configuration}
12125 constructor.
12126
12127 Available @code{dict-configuration} fields are:
12128
12129 @deftypevr {@code{dict-configuration} parameter} free-form-fields entries
12130 A list of key-value pairs that this dict should hold.
12131 Defaults to @samp{()}.
12132 @end deftypevr
12133
12134 @end deftypevr
12135
12136 @deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
12137 A list of passdb configurations, each one created by the
12138 @code{passdb-configuration} constructor.
12139
12140 Available @code{passdb-configuration} fields are:
12141
12142 @deftypevr {@code{passdb-configuration} parameter} string driver
12143 The driver that the passdb should use. Valid values include
12144 @samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
12145 @samp{static}.
12146 Defaults to @samp{"pam"}.
12147 @end deftypevr
12148
12149 @deftypevr {@code{passdb-configuration} parameter} space-separated-string-list args
12150 Space separated list of arguments to the passdb driver.
12151 Defaults to @samp{""}.
12152 @end deftypevr
12153
12154 @end deftypevr
12155
12156 @deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
12157 List of userdb configurations, each one created by the
12158 @code{userdb-configuration} constructor.
12159
12160 Available @code{userdb-configuration} fields are:
12161
12162 @deftypevr {@code{userdb-configuration} parameter} string driver
12163 The driver that the userdb should use. Valid values include
12164 @samp{passwd} and @samp{static}.
12165 Defaults to @samp{"passwd"}.
12166 @end deftypevr
12167
12168 @deftypevr {@code{userdb-configuration} parameter} space-separated-string-list args
12169 Space separated list of arguments to the userdb driver.
12170 Defaults to @samp{""}.
12171 @end deftypevr
12172
12173 @deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
12174 Override fields from passwd.
12175 Defaults to @samp{()}.
12176 @end deftypevr
12177
12178 @end deftypevr
12179
12180 @deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
12181 Plug-in configuration, created by the @code{plugin-configuration}
12182 constructor.
12183 @end deftypevr
12184
12185 @deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
12186 List of namespaces. Each item in the list is created by the
12187 @code{namespace-configuration} constructor.
12188
12189 Available @code{namespace-configuration} fields are:
12190
12191 @deftypevr {@code{namespace-configuration} parameter} string name
12192 Name for this namespace.
12193 @end deftypevr
12194
12195 @deftypevr {@code{namespace-configuration} parameter} string type
12196 Namespace type: @samp{private}, @samp{shared} or @samp{public}.
12197 Defaults to @samp{"private"}.
12198 @end deftypevr
12199
12200 @deftypevr {@code{namespace-configuration} parameter} string separator
12201 Hierarchy separator to use. You should use the same separator for
12202 all namespaces or some clients get confused. @samp{/} is usually a good
12203 one. The default however depends on the underlying mail storage
12204 format.
12205 Defaults to @samp{""}.
12206 @end deftypevr
12207
12208 @deftypevr {@code{namespace-configuration} parameter} string prefix
12209 Prefix required to access this namespace. This needs to be
12210 different for all namespaces. For example @samp{Public/}.
12211 Defaults to @samp{""}.
12212 @end deftypevr
12213
12214 @deftypevr {@code{namespace-configuration} parameter} string location
12215 Physical location of the mailbox. This is in the same format as
12216 mail_location, which is also the default for it.
12217 Defaults to @samp{""}.
12218 @end deftypevr
12219
12220 @deftypevr {@code{namespace-configuration} parameter} boolean inbox?
12221 There can be only one INBOX, and this setting defines which
12222 namespace has it.
12223 Defaults to @samp{#f}.
12224 @end deftypevr
12225
12226 @deftypevr {@code{namespace-configuration} parameter} boolean hidden?
12227 If namespace is hidden, it's not advertised to clients via NAMESPACE
12228 extension. You'll most likely also want to set @samp{list? #f}. This is mostly
12229 useful when converting from another server with different namespaces
12230 which you want to deprecate but still keep working. For example you can
12231 create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
12232 and @samp{mail/}.
12233 Defaults to @samp{#f}.
12234 @end deftypevr
12235
12236 @deftypevr {@code{namespace-configuration} parameter} boolean list?
12237 Show the mailboxes under this namespace with the LIST command. This
12238 makes the namespace visible for clients that do not support the NAMESPACE
12239 extension. The special @code{children} value lists child mailboxes, but
12240 hides the namespace prefix.
12241 Defaults to @samp{#t}.
12242 @end deftypevr
12243
12244 @deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
12245 Namespace handles its own subscriptions. If set to @code{#f}, the
12246 parent namespace handles them. The empty prefix should always have this
12247 as @code{#t}).
12248 Defaults to @samp{#t}.
12249 @end deftypevr
12250
12251 @deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
12252 List of predefined mailboxes in this namespace.
12253 Defaults to @samp{()}.
12254
12255 Available @code{mailbox-configuration} fields are:
12256
12257 @deftypevr {@code{mailbox-configuration} parameter} string name
12258 Name for this mailbox.
12259 @end deftypevr
12260
12261 @deftypevr {@code{mailbox-configuration} parameter} string auto
12262 @samp{create} will automatically create this mailbox.
12263 @samp{subscribe} will both create and subscribe to the mailbox.
12264 Defaults to @samp{"no"}.
12265 @end deftypevr
12266
12267 @deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
12268 List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
12269 Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
12270 @code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
12271 Defaults to @samp{()}.
12272 @end deftypevr
12273
12274 @end deftypevr
12275
12276 @end deftypevr
12277
12278 @deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
12279 Base directory where to store runtime data.
12280 Defaults to @samp{"/var/run/dovecot/"}.
12281 @end deftypevr
12282
12283 @deftypevr {@code{dovecot-configuration} parameter} string login-greeting
12284 Greeting message for clients.
12285 Defaults to @samp{"Dovecot ready."}.
12286 @end deftypevr
12287
12288 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
12289 List of trusted network ranges. Connections from these IPs are
12290 allowed to override their IP addresses and ports (for logging and for
12291 authentication checks). @samp{disable-plaintext-auth} is also ignored
12292 for these networks. Typically you would specify your IMAP proxy servers
12293 here.
12294 Defaults to @samp{()}.
12295 @end deftypevr
12296
12297 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
12298 List of login access check sockets (e.g. tcpwrap).
12299 Defaults to @samp{()}.
12300 @end deftypevr
12301
12302 @deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
12303 Show more verbose process titles (in ps). Currently shows user name
12304 and IP address. Useful for seeing who is actually using the IMAP
12305 processes (e.g. shared mailboxes or if the same uid is used for multiple
12306 accounts).
12307 Defaults to @samp{#f}.
12308 @end deftypevr
12309
12310 @deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
12311 Should all processes be killed when Dovecot master process shuts down.
12312 Setting this to @code{#f} means that Dovecot can be upgraded without
12313 forcing existing client connections to close (although that could also
12314 be a problem if the upgrade is e.g. due to a security fix).
12315 Defaults to @samp{#t}.
12316 @end deftypevr
12317
12318 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
12319 If non-zero, run mail commands via this many connections to doveadm
12320 server, instead of running them directly in the same process.
12321 Defaults to @samp{0}.
12322 @end deftypevr
12323
12324 @deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
12325 UNIX socket or host:port used for connecting to doveadm server.
12326 Defaults to @samp{"doveadm-server"}.
12327 @end deftypevr
12328
12329 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
12330 List of environment variables that are preserved on Dovecot startup
12331 and passed down to all of its child processes. You can also give
12332 key=value pairs to always set specific settings.
12333 @end deftypevr
12334
12335 @deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
12336 Disable LOGIN command and all other plaintext authentications unless
12337 SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
12338 matches the local IP (i.e. you're connecting from the same computer),
12339 the connection is considered secure and plaintext authentication is
12340 allowed. See also ssl=required setting.
12341 Defaults to @samp{#t}.
12342 @end deftypevr
12343
12344 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
12345 Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
12346 Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
12347 for caching to be used.
12348 Defaults to @samp{0}.
12349 @end deftypevr
12350
12351 @deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
12352 Time to live for cached data. After TTL expires the cached record
12353 is no longer used, *except* if the main database lookup returns internal
12354 failure. We also try to handle password changes automatically: If
12355 user's previous authentication was successful, but this one wasn't, the
12356 cache isn't used. For now this works only with plaintext
12357 authentication.
12358 Defaults to @samp{"1 hour"}.
12359 @end deftypevr
12360
12361 @deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
12362 TTL for negative hits (user not found, password mismatch).
12363 0 disables caching them completely.
12364 Defaults to @samp{"1 hour"}.
12365 @end deftypevr
12366
12367 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
12368 List of realms for SASL authentication mechanisms that need them.
12369 You can leave it empty if you don't want to support multiple realms.
12370 Many clients simply use the first one listed here, so keep the default
12371 realm first.
12372 Defaults to @samp{()}.
12373 @end deftypevr
12374
12375 @deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
12376 Default realm/domain to use if none was specified. This is used for
12377 both SASL realms and appending @@domain to username in plaintext
12378 logins.
12379 Defaults to @samp{""}.
12380 @end deftypevr
12381
12382 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
12383 List of allowed characters in username. If the user-given username
12384 contains a character not listed in here, the login automatically fails.
12385 This is just an extra check to make sure user can't exploit any
12386 potential quote escaping vulnerabilities with SQL/LDAP databases. If
12387 you want to allow all characters, set this value to empty.
12388 Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
12389 @end deftypevr
12390
12391 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
12392 Username character translations before it's looked up from
12393 databases. The value contains series of from -> to characters. For
12394 example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
12395 translated to @samp{@@}.
12396 Defaults to @samp{""}.
12397 @end deftypevr
12398
12399 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
12400 Username formatting before it's looked up from databases. You can
12401 use the standard variables here, e.g. %Lu would lowercase the username,
12402 %n would drop away the domain if it was given, or @samp{%n-AT-%d} would
12403 change the @samp{@@} into @samp{-AT-}. This translation is done after
12404 @samp{auth-username-translation} changes.
12405 Defaults to @samp{"%Lu"}.
12406 @end deftypevr
12407
12408 @deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
12409 If you want to allow master users to log in by specifying the master
12410 username within the normal username string (i.e. not using SASL
12411 mechanism's support for it), you can specify the separator character
12412 here. The format is then <username><separator><master username>.
12413 UW-IMAP uses @samp{*} as the separator, so that could be a good
12414 choice.
12415 Defaults to @samp{""}.
12416 @end deftypevr
12417
12418 @deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
12419 Username to use for users logging in with ANONYMOUS SASL
12420 mechanism.
12421 Defaults to @samp{"anonymous"}.
12422 @end deftypevr
12423
12424 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
12425 Maximum number of dovecot-auth worker processes. They're used to
12426 execute blocking passdb and userdb queries (e.g. MySQL and PAM).
12427 They're automatically created and destroyed as needed.
12428 Defaults to @samp{30}.
12429 @end deftypevr
12430
12431 @deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
12432 Host name to use in GSSAPI principal names. The default is to use
12433 the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
12434 allow all keytab entries.
12435 Defaults to @samp{""}.
12436 @end deftypevr
12437
12438 @deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
12439 Kerberos keytab to use for the GSSAPI mechanism. Will use the
12440 system default (usually @file{/etc/krb5.keytab}) if not specified. You may
12441 need to change the auth service to run as root to be able to read this
12442 file.
12443 Defaults to @samp{""}.
12444 @end deftypevr
12445
12446 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
12447 Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
12448 and @samp{ntlm-auth} helper.
12449 <doc/wiki/Authentication/Mechanisms/Winbind.txt>.
12450 Defaults to @samp{#f}.
12451 @end deftypevr
12452
12453 @deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
12454 Path for Samba's @samp{ntlm-auth} helper binary.
12455 Defaults to @samp{"/usr/bin/ntlm_auth"}.
12456 @end deftypevr
12457
12458 @deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
12459 Time to delay before replying to failed authentications.
12460 Defaults to @samp{"2 secs"}.
12461 @end deftypevr
12462
12463 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
12464 Require a valid SSL client certificate or the authentication
12465 fails.
12466 Defaults to @samp{#f}.
12467 @end deftypevr
12468
12469 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
12470 Take the username from client's SSL certificate, using
12471 @code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
12472 CommonName.
12473 Defaults to @samp{#f}.
12474 @end deftypevr
12475
12476 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
12477 List of wanted authentication mechanisms. Supported mechanisms are:
12478 @samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
12479 @samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
12480 @samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
12481 @samp{disable-plaintext-auth} setting.
12482 @end deftypevr
12483
12484 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
12485 List of IPs or hostnames to all director servers, including ourself.
12486 Ports can be specified as ip:port. The default port is the same as what
12487 director service's @samp{inet-listener} is using.
12488 Defaults to @samp{()}.
12489 @end deftypevr
12490
12491 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
12492 List of IPs or hostnames to all backend mail servers. Ranges are
12493 allowed too, like 10.0.0.10-10.0.0.30.
12494 Defaults to @samp{()}.
12495 @end deftypevr
12496
12497 @deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
12498 How long to redirect users to a specific server after it no longer
12499 has any connections.
12500 Defaults to @samp{"15 min"}.
12501 @end deftypevr
12502
12503 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
12504 TCP/IP port that accepts doveadm connections (instead of director
12505 connections) If you enable this, you'll also need to add
12506 @samp{inet-listener} for the port.
12507 Defaults to @samp{0}.
12508 @end deftypevr
12509
12510 @deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
12511 How the username is translated before being hashed. Useful values
12512 include %Ln if user can log in with or without @@domain, %Ld if mailboxes
12513 are shared within domain.
12514 Defaults to @samp{"%Lu"}.
12515 @end deftypevr
12516
12517 @deftypevr {@code{dovecot-configuration} parameter} string log-path
12518 Log file to use for error messages. @samp{syslog} logs to syslog,
12519 @samp{/dev/stderr} logs to stderr.
12520 Defaults to @samp{"syslog"}.
12521 @end deftypevr
12522
12523 @deftypevr {@code{dovecot-configuration} parameter} string info-log-path
12524 Log file to use for informational messages. Defaults to
12525 @samp{log-path}.
12526 Defaults to @samp{""}.
12527 @end deftypevr
12528
12529 @deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
12530 Log file to use for debug messages. Defaults to
12531 @samp{info-log-path}.
12532 Defaults to @samp{""}.
12533 @end deftypevr
12534
12535 @deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
12536 Syslog facility to use if you're logging to syslog. Usually if you
12537 don't want to use @samp{mail}, you'll use local0..local7. Also other
12538 standard facilities are supported.
12539 Defaults to @samp{"mail"}.
12540 @end deftypevr
12541
12542 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
12543 Log unsuccessful authentication attempts and the reasons why they
12544 failed.
12545 Defaults to @samp{#f}.
12546 @end deftypevr
12547
12548 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
12549 In case of password mismatches, log the attempted password. Valid
12550 values are no, plain and sha1. sha1 can be useful for detecting brute
12551 force password attempts vs. user simply trying the same password over
12552 and over again. You can also truncate the value to n chars by appending
12553 ":n" (e.g. sha1:6).
12554 Defaults to @samp{#f}.
12555 @end deftypevr
12556
12557 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
12558 Even more verbose logging for debugging purposes. Shows for example
12559 SQL queries.
12560 Defaults to @samp{#f}.
12561 @end deftypevr
12562
12563 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
12564 In case of password mismatches, log the passwords and used scheme so
12565 the problem can be debugged. Enabling this also enables
12566 @samp{auth-debug}.
12567 Defaults to @samp{#f}.
12568 @end deftypevr
12569
12570 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
12571 Enable mail process debugging. This can help you figure out why
12572 Dovecot isn't finding your mails.
12573 Defaults to @samp{#f}.
12574 @end deftypevr
12575
12576 @deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
12577 Show protocol level SSL errors.
12578 Defaults to @samp{#f}.
12579 @end deftypevr
12580
12581 @deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
12582 Prefix for each line written to log file. % codes are in
12583 strftime(3) format.
12584 Defaults to @samp{"\"%b %d %H:%M:%S \""}.
12585 @end deftypevr
12586
12587 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
12588 List of elements we want to log. The elements which have a
12589 non-empty variable value are joined together to form a comma-separated
12590 string.
12591 @end deftypevr
12592
12593 @deftypevr {@code{dovecot-configuration} parameter} string login-log-format
12594 Login log format. %s contains @samp{login-log-format-elements}
12595 string, %$ contains the data we want to log.
12596 Defaults to @samp{"%$: %s"}.
12597 @end deftypevr
12598
12599 @deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
12600 Log prefix for mail processes. See doc/wiki/Variables.txt for list
12601 of possible variables you can use.
12602 Defaults to @samp{"\"%s(%u): \""}.
12603 @end deftypevr
12604
12605 @deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
12606 Format to use for logging mail deliveries. You can use variables:
12607 @table @code
12608 @item %$
12609 Delivery status message (e.g. @samp{saved to INBOX})
12610 @item %m
12611 Message-ID
12612 @item %s
12613 Subject
12614 @item %f
12615 From address
12616 @item %p
12617 Physical size
12618 @item %w
12619 Virtual size.
12620 @end table
12621 Defaults to @samp{"msgid=%m: %$"}.
12622 @end deftypevr
12623
12624 @deftypevr {@code{dovecot-configuration} parameter} string mail-location
12625 Location for users' mailboxes. The default is empty, which means
12626 that Dovecot tries to find the mailboxes automatically. This won't work
12627 if the user doesn't yet have any mail, so you should explicitly tell
12628 Dovecot the full location.
12629
12630 If you're using mbox, giving a path to the INBOX
12631 file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
12632 where the other mailboxes are kept. This is called the "root mail
12633 directory", and it must be the first path given in the
12634 @samp{mail-location} setting.
12635
12636 There are a few special variables you can use, eg.:
12637
12638 @table @samp
12639 @item %u
12640 username
12641 @item %n
12642 user part in user@@domain, same as %u if there's no domain
12643 @item %d
12644 domain part in user@@domain, empty if there's no domain
12645 @item %h
12646 home director
12647 @end table
12648
12649 See doc/wiki/Variables.txt for full list. Some examples:
12650 @table @samp
12651 @item maildir:~/Maildir
12652 @item mbox:~/mail:INBOX=/var/mail/%u
12653 @item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
12654 @end table
12655 Defaults to @samp{""}.
12656 @end deftypevr
12657
12658 @deftypevr {@code{dovecot-configuration} parameter} string mail-uid
12659 System user and group used to access mails. If you use multiple,
12660 userdb can override these by returning uid or gid fields. You can use
12661 either numbers or names. <doc/wiki/UserIds.txt>.
12662 Defaults to @samp{""}.
12663 @end deftypevr
12664
12665 @deftypevr {@code{dovecot-configuration} parameter} string mail-gid
12666
12667 Defaults to @samp{""}.
12668 @end deftypevr
12669
12670 @deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
12671 Group to enable temporarily for privileged operations. Currently
12672 this is used only with INBOX when either its initial creation or
12673 dotlocking fails. Typically this is set to "mail" to give access to
12674 /var/mail.
12675 Defaults to @samp{""}.
12676 @end deftypevr
12677
12678 @deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
12679 Grant access to these supplementary groups for mail processes.
12680 Typically these are used to set up access to shared mailboxes. Note
12681 that it may be dangerous to set these if users can create
12682 symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
12683 could allow a user to delete others' mailboxes, or ln -s
12684 /secret/shared/box ~/mail/mybox would allow reading it).
12685 Defaults to @samp{""}.
12686 @end deftypevr
12687
12688 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
12689 Allow full file system access to clients. There's no access checks
12690 other than what the operating system does for the active UID/GID. It
12691 works with both maildir and mboxes, allowing you to prefix mailboxes
12692 names with e.g. /path/ or ~user/.
12693 Defaults to @samp{#f}.
12694 @end deftypevr
12695
12696 @deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
12697 Don't use mmap() at all. This is required if you store indexes to
12698 shared file systems (NFS or clustered file system).
12699 Defaults to @samp{#f}.
12700 @end deftypevr
12701
12702 @deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
12703 Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
12704 supports @samp{O_EXCL} since version 3, so this should be safe to use
12705 nowadays by default.
12706 Defaults to @samp{#t}.
12707 @end deftypevr
12708
12709 @deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
12710 When to use fsync() or fdatasync() calls:
12711 @table @code
12712 @item optimized
12713 Whenever necessary to avoid losing important data
12714 @item always
12715 Useful with e.g. NFS when write()s are delayed
12716 @item never
12717 Never use it (best performance, but crashes can lose data).
12718 @end table
12719 Defaults to @samp{"optimized"}.
12720 @end deftypevr
12721
12722 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
12723 Mail storage exists in NFS. Set this to yes to make Dovecot flush
12724 NFS caches whenever needed. If you're using only a single mail server
12725 this isn't needed.
12726 Defaults to @samp{#f}.
12727 @end deftypevr
12728
12729 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
12730 Mail index files also exist in NFS. Setting this to yes requires
12731 @samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
12732 Defaults to @samp{#f}.
12733 @end deftypevr
12734
12735 @deftypevr {@code{dovecot-configuration} parameter} string lock-method
12736 Locking method for index files. Alternatives are fcntl, flock and
12737 dotlock. Dotlocking uses some tricks which may create more disk I/O
12738 than other locking methods. NFS users: flock doesn't work, remember to
12739 change @samp{mmap-disable}.
12740 Defaults to @samp{"fcntl"}.
12741 @end deftypevr
12742
12743 @deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
12744 Directory in which LDA/LMTP temporarily stores incoming mails >128
12745 kB.
12746 Defaults to @samp{"/tmp"}.
12747 @end deftypevr
12748
12749 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
12750 Valid UID range for users. This is mostly to make sure that users can't
12751 log in as daemons or other system users. Note that denying root logins is
12752 hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
12753 is set to 0.
12754 Defaults to @samp{500}.
12755 @end deftypevr
12756
12757 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
12758
12759 Defaults to @samp{0}.
12760 @end deftypevr
12761
12762 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
12763 Valid GID range for users. Users having non-valid GID as primary group ID
12764 aren't allowed to log in. If user belongs to supplementary groups with
12765 non-valid GIDs, those groups are not set.
12766 Defaults to @samp{1}.
12767 @end deftypevr
12768
12769 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
12770
12771 Defaults to @samp{0}.
12772 @end deftypevr
12773
12774 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
12775 Maximum allowed length for mail keyword name. It's only forced when
12776 trying to create new keywords.
12777 Defaults to @samp{50}.
12778 @end deftypevr
12779
12780 @deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
12781 List of directories under which chrooting is allowed for mail
12782 processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
12783 too). This setting doesn't affect @samp{login-chroot}
12784 @samp{mail-chroot} or auth chroot settings. If this setting is empty,
12785 "/./" in home dirs are ignored. WARNING: Never add directories here
12786 which local users can modify, that may lead to root exploit. Usually
12787 this should be done only if you don't allow shell access for users.
12788 <doc/wiki/Chrooting.txt>.
12789 Defaults to @samp{()}.
12790 @end deftypevr
12791
12792 @deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
12793 Default chroot directory for mail processes. This can be overridden
12794 for specific users in user database by giving /./ in user's home
12795 directory (e.g. /home/./user chroots into /home). Note that usually
12796 there is no real need to do chrooting, Dovecot doesn't allow users to
12797 access files outside their mail directory anyway. If your home
12798 directories are prefixed with the chroot directory, append "/." to
12799 @samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
12800 Defaults to @samp{""}.
12801 @end deftypevr
12802
12803 @deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
12804 UNIX socket path to master authentication server to find users.
12805 This is used by imap (for shared users) and lda.
12806 Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
12807 @end deftypevr
12808
12809 @deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
12810 Directory where to look up mail plugins.
12811 Defaults to @samp{"/usr/lib/dovecot"}.
12812 @end deftypevr
12813
12814 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
12815 List of plugins to load for all services. Plugins specific to IMAP,
12816 LDA, etc. are added to this list in their own .conf files.
12817 Defaults to @samp{()}.
12818 @end deftypevr
12819
12820 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
12821 The minimum number of mails in a mailbox before updates are done to
12822 cache file. This allows optimizing Dovecot's behavior to do less disk
12823 writes at the cost of more disk reads.
12824 Defaults to @samp{0}.
12825 @end deftypevr
12826
12827 @deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
12828 When IDLE command is running, mailbox is checked once in a while to
12829 see if there are any new mails or other changes. This setting defines
12830 the minimum time to wait between those checks. Dovecot can also use
12831 dnotify, inotify and kqueue to find out immediately when changes
12832 occur.
12833 Defaults to @samp{"30 secs"}.
12834 @end deftypevr
12835
12836 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
12837 Save mails with CR+LF instead of plain LF. This makes sending those
12838 mails take less CPU, especially with sendfile() syscall with Linux and
12839 FreeBSD. But it also creates a bit more disk I/O which may just make it
12840 slower. Also note that if other software reads the mboxes/maildirs,
12841 they may handle the extra CRs wrong and cause problems.
12842 Defaults to @samp{#f}.
12843 @end deftypevr
12844
12845 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
12846 By default LIST command returns all entries in maildir beginning
12847 with a dot. Enabling this option makes Dovecot return only entries
12848 which are directories. This is done by stat()ing each entry, so it
12849 causes more disk I/O.
12850 (For systems setting struct @samp{dirent->d_type} this check is free
12851 and it's done always regardless of this setting).
12852 Defaults to @samp{#f}.
12853 @end deftypevr
12854
12855 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
12856 When copying a message, do it with hard links whenever possible.
12857 This makes the performance much better, and it's unlikely to have any
12858 side effects.
12859 Defaults to @samp{#t}.
12860 @end deftypevr
12861
12862 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
12863 Assume Dovecot is the only MUA accessing Maildir: Scan cur/
12864 directory only when its mtime changes unexpectedly or when we can't find
12865 the mail otherwise.
12866 Defaults to @samp{#f}.
12867 @end deftypevr
12868
12869 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
12870 Which locking methods to use for locking mbox. There are four
12871 available:
12872
12873 @table @code
12874 @item dotlock
12875 Create <mailbox>.lock file. This is the oldest and most NFS-safe
12876 solution. If you want to use /var/mail/ like directory, the users will
12877 need write access to that directory.
12878 @item dotlock-try
12879 Same as dotlock, but if it fails because of permissions or because there
12880 isn't enough disk space, just skip it.
12881 @item fcntl
12882 Use this if possible. Works with NFS too if lockd is used.
12883 @item flock
12884 May not exist in all systems. Doesn't work with NFS.
12885 @item lockf
12886 May not exist in all systems. Doesn't work with NFS.
12887 @end table
12888
12889 You can use multiple locking methods; if you do the order they're declared
12890 in is important to avoid deadlocks if other MTAs/MUAs are using multiple
12891 locking methods as well. Some operating systems don't allow using some of
12892 them simultaneously.
12893 @end deftypevr
12894
12895 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
12896
12897 @end deftypevr
12898
12899 @deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
12900 Maximum time to wait for lock (all of them) before aborting.
12901 Defaults to @samp{"5 mins"}.
12902 @end deftypevr
12903
12904 @deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
12905 If dotlock exists but the mailbox isn't modified in any way,
12906 override the lock file after this much time.
12907 Defaults to @samp{"2 mins"}.
12908 @end deftypevr
12909
12910 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
12911 When mbox changes unexpectedly we have to fully read it to find out
12912 what changed. If the mbox is large this can take a long time. Since
12913 the change is usually just a newly appended mail, it'd be faster to
12914 simply read the new mails. If this setting is enabled, Dovecot does
12915 this but still safely fallbacks to re-reading the whole mbox file
12916 whenever something in mbox isn't how it's expected to be. The only real
12917 downside to this setting is that if some other MUA changes message
12918 flags, Dovecot doesn't notice it immediately. Note that a full sync is
12919 done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
12920 Defaults to @samp{#t}.
12921 @end deftypevr
12922
12923 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
12924 Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
12925 EXAMINE, EXPUNGE or CHECK commands. If this is set,
12926 @samp{mbox-dirty-syncs} is ignored.
12927 Defaults to @samp{#f}.
12928 @end deftypevr
12929
12930 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
12931 Delay writing mbox headers until doing a full write sync (EXPUNGE
12932 and CHECK commands and when closing the mailbox). This is especially
12933 useful for POP3 where clients often delete all mails. The downside is
12934 that our changes aren't immediately visible to other MUAs.
12935 Defaults to @samp{#t}.
12936 @end deftypevr
12937
12938 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
12939 If mbox size is smaller than this (e.g. 100k), don't write index
12940 files. If an index file already exists it's still read, just not
12941 updated.
12942 Defaults to @samp{0}.
12943 @end deftypevr
12944
12945 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
12946 Maximum dbox file size until it's rotated.
12947 Defaults to @samp{2000000}.
12948 @end deftypevr
12949
12950 @deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
12951 Maximum dbox file age until it's rotated. Typically in days. Day
12952 begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
12953 disabled.
12954 Defaults to @samp{"1d"}.
12955 @end deftypevr
12956
12957 @deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
12958 When creating new mdbox files, immediately preallocate their size to
12959 @samp{mdbox-rotate-size}. This setting currently works only in Linux
12960 with some file systems (ext4, xfs).
12961 Defaults to @samp{#f}.
12962 @end deftypevr
12963
12964 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
12965 sdbox and mdbox support saving mail attachments to external files,
12966 which also allows single instance storage for them. Other backends
12967 don't support this for now.
12968
12969 WARNING: This feature hasn't been tested much yet. Use at your own risk.
12970
12971 Directory root where to store mail attachments. Disabled, if empty.
12972 Defaults to @samp{""}.
12973 @end deftypevr
12974
12975 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
12976 Attachments smaller than this aren't saved externally. It's also
12977 possible to write a plugin to disable saving specific attachments
12978 externally.
12979 Defaults to @samp{128000}.
12980 @end deftypevr
12981
12982 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
12983 File system backend to use for saving attachments:
12984 @table @code
12985 @item posix
12986 No SiS done by Dovecot (but this might help FS's own deduplication)
12987 @item sis posix
12988 SiS with immediate byte-by-byte comparison during saving
12989 @item sis-queue posix
12990 SiS with delayed comparison and deduplication.
12991 @end table
12992 Defaults to @samp{"sis posix"}.
12993 @end deftypevr
12994
12995 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
12996 Hash format to use in attachment filenames. You can add any text and
12997 variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
12998 @code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
12999 truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
13000 Defaults to @samp{"%@{sha1@}"}.
13001 @end deftypevr
13002
13003 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
13004
13005 Defaults to @samp{100}.
13006 @end deftypevr
13007
13008 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
13009
13010 Defaults to @samp{1000}.
13011 @end deftypevr
13012
13013 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
13014 Default VSZ (virtual memory size) limit for service processes.
13015 This is mainly intended to catch and kill processes that leak memory
13016 before they eat up everything.
13017 Defaults to @samp{256000000}.
13018 @end deftypevr
13019
13020 @deftypevr {@code{dovecot-configuration} parameter} string default-login-user
13021 Login user is internally used by login processes. This is the most
13022 untrusted user in Dovecot system. It shouldn't have access to anything
13023 at all.
13024 Defaults to @samp{"dovenull"}.
13025 @end deftypevr
13026
13027 @deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
13028 Internal user is used by unprivileged processes. It should be
13029 separate from login user, so that login processes can't disturb other
13030 processes.
13031 Defaults to @samp{"dovecot"}.
13032 @end deftypevr
13033
13034 @deftypevr {@code{dovecot-configuration} parameter} string ssl?
13035 SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
13036 Defaults to @samp{"required"}.
13037 @end deftypevr
13038
13039 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
13040 PEM encoded X.509 SSL/TLS certificate (public key).
13041 Defaults to @samp{"</etc/dovecot/default.pem"}.
13042 @end deftypevr
13043
13044 @deftypevr {@code{dovecot-configuration} parameter} string ssl-key
13045 PEM encoded SSL/TLS private key. The key is opened before
13046 dropping root privileges, so keep the key file unreadable by anyone but
13047 root.
13048 Defaults to @samp{"</etc/dovecot/private/default.pem"}.
13049 @end deftypevr
13050
13051 @deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
13052 If key file is password protected, give the password here.
13053 Alternatively give it when starting dovecot with -p parameter. Since
13054 this file is often world-readable, you may want to place this setting
13055 instead to a different.
13056 Defaults to @samp{""}.
13057 @end deftypevr
13058
13059 @deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
13060 PEM encoded trusted certificate authority. Set this only if you
13061 intend to use @samp{ssl-verify-client-cert? #t}. The file should
13062 contain the CA certificate(s) followed by the matching
13063 CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
13064 Defaults to @samp{""}.
13065 @end deftypevr
13066
13067 @deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
13068 Require that CRL check succeeds for client certificates.
13069 Defaults to @samp{#t}.
13070 @end deftypevr
13071
13072 @deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
13073 Request client to send a certificate. If you also want to require
13074 it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
13075 Defaults to @samp{#f}.
13076 @end deftypevr
13077
13078 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
13079 Which field from certificate to use for username. commonName and
13080 x500UniqueIdentifier are the usual choices. You'll also need to set
13081 @samp{auth-ssl-username-from-cert? #t}.
13082 Defaults to @samp{"commonName"}.
13083 @end deftypevr
13084
13085 @deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
13086 How often to regenerate the SSL parameters file. Generation is
13087 quite CPU intensive operation. The value is in hours, 0 disables
13088 regeneration entirely.
13089 Defaults to @samp{168}.
13090 @end deftypevr
13091
13092 @deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
13093 SSL protocols to use.
13094 Defaults to @samp{"!SSLv2"}.
13095 @end deftypevr
13096
13097 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
13098 SSL ciphers to use.
13099 Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
13100 @end deftypevr
13101
13102 @deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
13103 SSL crypto device to use, for valid values run "openssl engine".
13104 Defaults to @samp{""}.
13105 @end deftypevr
13106
13107 @deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
13108 Address to use when sending rejection mails.
13109 %d expands to recipient domain.
13110 Defaults to @samp{"postmaster@@%d"}.
13111 @end deftypevr
13112
13113 @deftypevr {@code{dovecot-configuration} parameter} string hostname
13114 Hostname to use in various parts of sent mails (e.g. in Message-Id)
13115 and in LMTP replies. Default is the system's real hostname@@domain.
13116 Defaults to @samp{""}.
13117 @end deftypevr
13118
13119 @deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
13120 If user is over quota, return with temporary failure instead of
13121 bouncing the mail.
13122 Defaults to @samp{#f}.
13123 @end deftypevr
13124
13125 @deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
13126 Binary to use for sending mails.
13127 Defaults to @samp{"/usr/sbin/sendmail"}.
13128 @end deftypevr
13129
13130 @deftypevr {@code{dovecot-configuration} parameter} string submission-host
13131 If non-empty, send mails via this SMTP host[:port] instead of
13132 sendmail.
13133 Defaults to @samp{""}.
13134 @end deftypevr
13135
13136 @deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
13137 Subject: header to use for rejection mails. You can use the same
13138 variables as for @samp{rejection-reason} below.
13139 Defaults to @samp{"Rejected: %s"}.
13140 @end deftypevr
13141
13142 @deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
13143 Human readable error message for rejection mails. You can use
13144 variables:
13145
13146 @table @code
13147 @item %n
13148 CRLF
13149 @item %r
13150 reason
13151 @item %s
13152 original subject
13153 @item %t
13154 recipient
13155 @end table
13156 Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
13157 @end deftypevr
13158
13159 @deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
13160 Delimiter character between local-part and detail in email
13161 address.
13162 Defaults to @samp{"+"}.
13163 @end deftypevr
13164
13165 @deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
13166 Header where the original recipient address (SMTP's RCPT TO:
13167 address) is taken from if not available elsewhere. With dovecot-lda -a
13168 parameter overrides this. A commonly used header for this is
13169 X-Original-To.
13170 Defaults to @samp{""}.
13171 @end deftypevr
13172
13173 @deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
13174 Should saving a mail to a nonexistent mailbox automatically create
13175 it?.
13176 Defaults to @samp{#f}.
13177 @end deftypevr
13178
13179 @deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
13180 Should automatically created mailboxes be also automatically
13181 subscribed?.
13182 Defaults to @samp{#f}.
13183 @end deftypevr
13184
13185 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
13186 Maximum IMAP command line length. Some clients generate very long
13187 command lines with huge mailboxes, so you may need to raise this if you
13188 get "Too long argument" or "IMAP command line too large" errors
13189 often.
13190 Defaults to @samp{64000}.
13191 @end deftypevr
13192
13193 @deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
13194 IMAP logout format string:
13195 @table @code
13196 @item %i
13197 total number of bytes read from client
13198 @item %o
13199 total number of bytes sent to client.
13200 @end table
13201 Defaults to @samp{"in=%i out=%o"}.
13202 @end deftypevr
13203
13204 @deftypevr {@code{dovecot-configuration} parameter} string imap-capability
13205 Override the IMAP CAPABILITY response. If the value begins with '+',
13206 add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
13207 Defaults to @samp{""}.
13208 @end deftypevr
13209
13210 @deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
13211 How long to wait between "OK Still here" notifications when client
13212 is IDLEing.
13213 Defaults to @samp{"2 mins"}.
13214 @end deftypevr
13215
13216 @deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
13217 ID field names and values to send to clients. Using * as the value
13218 makes Dovecot use the default value. The following fields have default
13219 values currently: name, version, os, os-version, support-url,
13220 support-email.
13221 Defaults to @samp{""}.
13222 @end deftypevr
13223
13224 @deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
13225 ID fields sent by client to log. * means everything.
13226 Defaults to @samp{""}.
13227 @end deftypevr
13228
13229 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
13230 Workarounds for various client bugs:
13231
13232 @table @code
13233 @item delay-newmail
13234 Send EXISTS/RECENT new mail notifications only when replying to NOOP and
13235 CHECK commands. Some clients ignore them otherwise, for example OSX
13236 Mail (<v2.1). Outlook Express breaks more badly though, without this it
13237 may show user "Message no longer in server" errors. Note that OE6
13238 still breaks even with this workaround if synchronization is set to
13239 "Headers Only".
13240
13241 @item tb-extra-mailbox-sep
13242 Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
13243 adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
13244 ignore the extra @samp{/} instead of treating it as invalid mailbox name.
13245
13246 @item tb-lsub-flags
13247 Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
13248 This makes Thunderbird realize they aren't selectable and show them
13249 greyed out, instead of only later giving "not selectable" popup error.
13250 @end table
13251 Defaults to @samp{()}.
13252 @end deftypevr
13253
13254 @deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
13255 Host allowed in URLAUTH URLs sent by client. "*" allows all.
13256 Defaults to @samp{""}.
13257 @end deftypevr
13258
13259
13260 Whew! Lots of configuration options. The nice thing about it though is
13261 that GuixSD has a complete interface to Dovecot's configuration
13262 language. This allows not only a nice way to declare configurations,
13263 but also offers reflective capabilities as well: users can write code to
13264 inspect and transform configurations from within Scheme.
13265
13266 However, it could be that you just want to get a @code{dovecot.conf} up
13267 and running. In that case, you can pass an
13268 @code{opaque-dovecot-configuration} as the @code{#:config} parameter to
13269 @code{dovecot-service}. As its name indicates, an opaque configuration
13270 does not have easy reflective capabilities.
13271
13272 Available @code{opaque-dovecot-configuration} fields are:
13273
13274 @deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
13275 The dovecot package.
13276 @end deftypevr
13277
13278 @deftypevr {@code{opaque-dovecot-configuration} parameter} string string
13279 The contents of the @code{dovecot.conf}, as a string.
13280 @end deftypevr
13281
13282 For example, if your @code{dovecot.conf} is just the empty string, you
13283 could instantiate a dovecot service like this:
13284
13285 @example
13286 (dovecot-service #:config
13287 (opaque-dovecot-configuration
13288 (string "")))
13289 @end example
13290
13291 @subsubheading OpenSMTPD Service
13292
13293 @deffn {Scheme Variable} opensmtpd-service-type
13294 This is the type of the @uref{https://www.opensmtpd.org, OpenSMTPD}
13295 service, whose value should be an @code{opensmtpd-configuration} object
13296 as in this example:
13297
13298 @example
13299 (service opensmtpd-service-type
13300 (opensmtpd-configuration
13301 (config-file (local-file "./my-smtpd.conf"))))
13302 @end example
13303 @end deffn
13304
13305 @deftp {Data Type} opensmtpd-configuration
13306 Data type representing the configuration of opensmtpd.
13307
13308 @table @asis
13309 @item @code{package} (default: @var{opensmtpd})
13310 Package object of the OpenSMTPD SMTP server.
13311
13312 @item @code{config-file} (default: @var{%default-opensmtpd-file})
13313 File-like object of the OpenSMTPD configuration file to use. By default
13314 it listens on the loopback network interface, and allows for mail from
13315 users and daemons on the local machine, as well as permitting email to
13316 remote servers. Run @command{man smtpd.conf} for more information.
13317
13318 @end table
13319 @end deftp
13320
13321 @subsubheading Exim Service
13322
13323 @cindex mail transfer agent (MTA)
13324 @cindex MTA (mail transfer agent)
13325 @cindex SMTP
13326
13327 @deffn {Scheme Variable} exim-service-type
13328 This is the type of the @uref{https://exim.org, Exim} mail transfer
13329 agent (MTA), whose value should be an @code{exim-configuration} object
13330 as in this example:
13331
13332 @example
13333 (service exim-service-type
13334 (exim-configuration
13335 (config-file (local-file "./my-exim.conf"))))
13336 @end example
13337 @end deffn
13338
13339 In order to use an @code{exim-service-type} service you must also have a
13340 @code{mail-aliases-service-type} service present in your
13341 @code{operating-system} (even if it has no aliases).
13342
13343 @deftp {Data Type} exim-configuration
13344 Data type representing the configuration of exim.
13345
13346 @table @asis
13347 @item @code{package} (default: @var{exim})
13348 Package object of the Exim server.
13349
13350 @item @code{config-file} (default: @code{#f})
13351 File-like object of the Exim configuration file to use. If its value is
13352 @code{#f} then use the default configuration file from the package
13353 provided in @code{package}. The resulting configuration file is loaded
13354 after setting the @code{exim_user} and @code{exim_group} configuration
13355 variables.
13356
13357 @end table
13358 @end deftp
13359
13360 @subsubheading Mail Aliases Service
13361
13362 @cindex email aliases
13363 @cindex aliases, for email addresses
13364
13365 @deffn {Scheme Variable} mail-aliases-service-type
13366 This is the type of the service which provides @code{/etc/aliases},
13367 specifying how to deliver mail to users on this system.
13368
13369 @example
13370 (service mail-aliases-service-type
13371 '(("postmaster" "bob")
13372 ("bob" "bob@@example.com" "bob@@example2.com")))
13373 @end example
13374 @end deffn
13375
13376 The configuration for a @code{mail-aliases-service-type} service is an
13377 association list denoting how to deliver mail that comes to this
13378 system. Each entry is of the form @code{(alias addresses ...)}, with
13379 @code{alias} specifying the local alias and @code{addresses} specifying
13380 where to deliver this user's mail.
13381
13382 The aliases aren't required to exist as users on the local system. In
13383 the above example, there doesn't need to be a @code{postmaster} entry in
13384 the @code{operating-system}'s @code{user-accounts} in order to deliver
13385 the @code{postmaster} mail to @code{bob} (which subsequently would
13386 deliver mail to @code{bob@@example.com} and @code{bob@@example2.com}).
13387
13388 @node Messaging Services
13389 @subsubsection Messaging Services
13390
13391 @cindex messaging
13392 @cindex jabber
13393 @cindex XMPP
13394 The @code{(gnu services messaging)} module provides Guix service
13395 definitions for messaging services: currently only Prosody is supported.
13396
13397 @subsubheading Prosody Service
13398
13399 @deffn {Scheme Variable} prosody-service-type
13400 This is the type for the @uref{http://prosody.im, Prosody XMPP
13401 communication server}. Its value must be a @code{prosody-configuration}
13402 record as in this example:
13403
13404 @example
13405 (service prosody-service-type
13406 (prosody-configuration
13407 (modules-enabled (cons "groups" %default-modules-enabled))
13408 (int-components
13409 (list
13410 (int-component-configuration
13411 (hostname "conference.example.net")
13412 (plugin "muc")
13413 (mod-muc (mod-muc-configuration)))))
13414 (virtualhosts
13415 (list
13416 (virtualhost-configuration
13417 (domain "example.net"))))))
13418 @end example
13419
13420 See below for details about @code{prosody-configuration}.
13421
13422 @end deffn
13423
13424 By default, Prosody does not need much configuration. Only one
13425 @code{virtualhosts} field is needed: it specifies the domain you wish
13426 Prosody to serve.
13427
13428 Prosodyctl will help you generate X.509 certificates and keys:
13429
13430 @example
13431 prosodyctl cert request example.net
13432 @end example
13433
13434 The available configuration parameters follow. Each parameter
13435 definition is preceded by its type; for example, @samp{string-list foo}
13436 indicates that the @code{foo} parameter should be specified as a list of
13437 strings. Types starting with @code{maybe-} denote parameters that won't
13438 show up in @code{prosody.cfg.lua} when their value is @code{'disabled}.
13439
13440 There is also a way to specify the configuration as a string, if you
13441 have an old @code{prosody.cfg.lua} file that you want to port over from
13442 some other system; see the end for more details.
13443
13444 @c The following documentation was initially generated by
13445 @c (generate-documentation) in (gnu services messaging). Manually maintained
13446 @c documentation is better, so we shouldn't hesitate to edit below as
13447 @c needed. However if the change you want to make to this documentation
13448 @c can be done in an automated way, it's probably easier to change
13449 @c (generate-documentation) than to make it below and have to deal with
13450 @c the churn as Prosody updates.
13451
13452 Available @code{prosody-configuration} fields are:
13453
13454 @deftypevr {@code{prosody-configuration} parameter} package prosody
13455 The Prosody package.
13456 @end deftypevr
13457
13458 @deftypevr {@code{prosody-configuration} parameter} file-name data-path
13459 Location of the Prosody data storage directory. See
13460 @url{http://prosody.im/doc/configure}.
13461 Defaults to @samp{"/var/lib/prosody"}.
13462 @end deftypevr
13463
13464 @deftypevr {@code{prosody-configuration} parameter} file-name-list plugin-paths
13465 Additional plugin directories. They are searched in all the specified
13466 paths in order. See @url{http://prosody.im/doc/plugins_directory}.
13467 Defaults to @samp{()}.
13468 @end deftypevr
13469
13470 @deftypevr {@code{prosody-configuration} parameter} string-list admins
13471 This is a list of accounts that are admins for the server. Note that you
13472 must create the accounts separately. See @url{http://prosody.im/doc/admins} and
13473 @url{http://prosody.im/doc/creating_accounts}.
13474 Example: @code{(admins '("user1@@example.com" "user2@@example.net"))}
13475 Defaults to @samp{()}.
13476 @end deftypevr
13477
13478 @deftypevr {@code{prosody-configuration} parameter} boolean use-libevent?
13479 Enable use of libevent for better performance under high load. See
13480 @url{http://prosody.im/doc/libevent}.
13481 Defaults to @samp{#f}.
13482 @end deftypevr
13483
13484 @deftypevr {@code{prosody-configuration} parameter} module-list modules-enabled
13485 This is the list of modules Prosody will load on startup. It looks for
13486 @code{mod_modulename.lua} in the plugins folder, so make sure that exists too.
13487 Documentation on modules can be found at: @url{http://prosody.im/doc/modules}.
13488 Defaults to @samp{%default-modules-enabled}.
13489 @end deftypevr
13490
13491 @deftypevr {@code{prosody-configuration} parameter} string-list modules-disabled
13492 @samp{"offline"}, @samp{"c2s"} and @samp{"s2s"} are auto-loaded, but
13493 should you want to disable them then add them to this list.
13494 Defaults to @samp{()}.
13495 @end deftypevr
13496
13497 @deftypevr {@code{prosody-configuration} parameter} file-name groups-file
13498 Path to a text file where the shared groups are defined. If this path is
13499 empty then @samp{mod_groups} does nothing. See
13500 @url{http://prosody.im/doc/modules/mod_groups}.
13501 Defaults to @samp{"/var/lib/prosody/sharedgroups.txt"}.
13502 @end deftypevr
13503
13504 @deftypevr {@code{prosody-configuration} parameter} boolean allow-registration?
13505 Disable account creation by default, for security. See
13506 @url{http://prosody.im/doc/creating_accounts}.
13507 Defaults to @samp{#f}.
13508 @end deftypevr
13509
13510 @deftypevr {@code{prosody-configuration} parameter} maybe-ssl-configuration ssl
13511 These are the SSL/TLS-related settings. Most of them are disabled so to
13512 use Prosody's defaults. If you do not completely understand these options, do
13513 not add them to your config, it is easy to lower the security of your server
13514 using them. See @url{http://prosody.im/doc/advanced_ssl_config}.
13515
13516 Available @code{ssl-configuration} fields are:
13517
13518 @deftypevr {@code{ssl-configuration} parameter} maybe-string protocol
13519 This determines what handshake to use.
13520 @end deftypevr
13521
13522 @deftypevr {@code{ssl-configuration} parameter} file-name key
13523 Path to your private key file, relative to @code{/etc/prosody}.
13524 Defaults to @samp{"/etc/prosody/certs/key.pem"}.
13525 @end deftypevr
13526
13527 @deftypevr {@code{ssl-configuration} parameter} file-name certificate
13528 Path to your certificate file, relative to @code{/etc/prosody}.
13529 Defaults to @samp{"/etc/prosody/certs/cert.pem"}.
13530 @end deftypevr
13531
13532 @deftypevr {@code{ssl-configuration} parameter} file-name capath
13533 Path to directory containing root certificates that you wish Prosody to
13534 trust when verifying the certificates of remote servers.
13535 Defaults to @samp{"/etc/ssl/certs"}.
13536 @end deftypevr
13537
13538 @deftypevr {@code{ssl-configuration} parameter} maybe-file-name cafile
13539 Path to a file containing root certificates that you wish Prosody to trust.
13540 Similar to @code{capath} but with all certificates concatenated together.
13541 @end deftypevr
13542
13543 @deftypevr {@code{ssl-configuration} parameter} maybe-string-list verify
13544 A list of verification options (these mostly map to OpenSSL's
13545 @code{set_verify()} flags).
13546 @end deftypevr
13547
13548 @deftypevr {@code{ssl-configuration} parameter} maybe-string-list options
13549 A list of general options relating to SSL/TLS. These map to OpenSSL's
13550 @code{set_options()}. For a full list of options available in LuaSec, see the
13551 LuaSec source.
13552 @end deftypevr
13553
13554 @deftypevr {@code{ssl-configuration} parameter} maybe-non-negative-integer depth
13555 How long a chain of certificate authorities to check when looking for a
13556 trusted root certificate.
13557 @end deftypevr
13558
13559 @deftypevr {@code{ssl-configuration} parameter} maybe-string ciphers
13560 An OpenSSL cipher string. This selects what ciphers Prosody will offer to
13561 clients, and in what order.
13562 @end deftypevr
13563
13564 @deftypevr {@code{ssl-configuration} parameter} maybe-file-name dhparam
13565 A path to a file containing parameters for Diffie-Hellman key exchange. You
13566 can create such a file with:
13567 @code{openssl dhparam -out /etc/prosody/certs/dh-2048.pem 2048}
13568 @end deftypevr
13569
13570 @deftypevr {@code{ssl-configuration} parameter} maybe-string curve
13571 Curve for Elliptic curve Diffie-Hellman. Prosody's default is
13572 @samp{"secp384r1"}.
13573 @end deftypevr
13574
13575 @deftypevr {@code{ssl-configuration} parameter} maybe-string-list verifyext
13576 A list of "extra" verification options.
13577 @end deftypevr
13578
13579 @deftypevr {@code{ssl-configuration} parameter} maybe-string password
13580 Password for encrypted private keys.
13581 @end deftypevr
13582
13583 @end deftypevr
13584
13585 @deftypevr {@code{prosody-configuration} parameter} boolean c2s-require-encryption?
13586 Whether to force all client-to-server connections to be encrypted or not.
13587 See @url{http://prosody.im/doc/modules/mod_tls}.
13588 Defaults to @samp{#f}.
13589 @end deftypevr
13590
13591 @deftypevr {@code{prosody-configuration} parameter} boolean s2s-require-encryption?
13592 Whether to force all server-to-server connections to be encrypted or not.
13593 See @url{http://prosody.im/doc/modules/mod_tls}.
13594 Defaults to @samp{#f}.
13595 @end deftypevr
13596
13597 @deftypevr {@code{prosody-configuration} parameter} boolean s2s-secure-auth?
13598 Whether to require encryption and certificate authentication. This
13599 provides ideal security, but requires servers you communicate with to support
13600 encryption AND present valid, trusted certificates. See
13601 @url{http://prosody.im/doc/s2s#security}.
13602 Defaults to @samp{#f}.
13603 @end deftypevr
13604
13605 @deftypevr {@code{prosody-configuration} parameter} string-list s2s-insecure-domains
13606 Many servers don't support encryption or have invalid or self-signed
13607 certificates. You can list domains here that will not be required to
13608 authenticate using certificates. They will be authenticated using DNS. See
13609 @url{http://prosody.im/doc/s2s#security}.
13610 Defaults to @samp{()}.
13611 @end deftypevr
13612
13613 @deftypevr {@code{prosody-configuration} parameter} string-list s2s-secure-domains
13614 Even if you leave @code{s2s-secure-auth?} disabled, you can still require
13615 valid certificates for some domains by specifying a list here. See
13616 @url{http://prosody.im/doc/s2s#security}.
13617 Defaults to @samp{()}.
13618 @end deftypevr
13619
13620 @deftypevr {@code{prosody-configuration} parameter} string authentication
13621 Select the authentication backend to use. The default provider stores
13622 passwords in plaintext and uses Prosody's configured data storage to store the
13623 authentication data. If you do not trust your server please see
13624 @url{http://prosody.im/doc/modules/mod_auth_internal_hashed} for information
13625 about using the hashed backend. See also
13626 @url{http://prosody.im/doc/authentication}
13627 Defaults to @samp{"internal_plain"}.
13628 @end deftypevr
13629
13630 @deftypevr {@code{prosody-configuration} parameter} maybe-string log
13631 Set logging options. Advanced logging configuration is not yet supported
13632 by the GuixSD Prosody Service. See @url{http://prosody.im/doc/logging}.
13633 Defaults to @samp{"*syslog"}.
13634 @end deftypevr
13635
13636 @deftypevr {@code{prosody-configuration} parameter} file-name pidfile
13637 File to write pid in. See @url{http://prosody.im/doc/modules/mod_posix}.
13638 Defaults to @samp{"/var/run/prosody/prosody.pid"}.
13639 @end deftypevr
13640
13641 @deftypevr {@code{prosody-configuration} parameter} virtualhost-configuration-list virtualhosts
13642 A host in Prosody is a domain on which user accounts can be created. For
13643 example if you want your users to have addresses like
13644 @samp{"john.smith@@example.com"} then you need to add a host
13645 @samp{"example.com"}. All options in this list will apply only to this host.
13646
13647 Note: the name "virtual" host is used in configuration to avoid confusion with
13648 the actual physical host that Prosody is installed on. A single Prosody
13649 instance can serve many domains, each one defined as a VirtualHost entry in
13650 Prosody's configuration. Conversely a server that hosts a single domain would
13651 have just one VirtualHost entry.
13652
13653 See @url{http://prosody.im/doc/configure#virtual_host_settings}.
13654
13655 Available @code{virtualhost-configuration} fields are:
13656
13657 all 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:
13658 @deftypevr {@code{virtualhost-configuration} parameter} string domain
13659 Domain you wish Prosody to serve.
13660 @end deftypevr
13661
13662 @end deftypevr
13663
13664 @deftypevr {@code{prosody-configuration} parameter} int-component-configuration-list int-components
13665 Components are extra services on a server which are available to clients,
13666 usually on a subdomain of the main server (such as
13667 @samp{"mycomponent.example.com"}). Example components might be chatroom
13668 servers, user directories, or gateways to other protocols.
13669
13670 Internal components are implemented with Prosody-specific plugins. To add an
13671 internal component, you simply fill the hostname field, and the plugin you wish
13672 to use for the component.
13673
13674 See @url{http://prosody.im/doc/components}.
13675 Defaults to @samp{()}.
13676
13677 Available @code{int-component-configuration} fields are:
13678
13679 all 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:
13680 @deftypevr {@code{int-component-configuration} parameter} string hostname
13681 Hostname of the component.
13682 @end deftypevr
13683
13684 @deftypevr {@code{int-component-configuration} parameter} string plugin
13685 Plugin you wish to use for the component.
13686 @end deftypevr
13687
13688 @deftypevr {@code{int-component-configuration} parameter} maybe-mod-muc-configuration mod-muc
13689 Multi-user chat (MUC) is Prosody's module for allowing you to create
13690 hosted chatrooms/conferences for XMPP users.
13691
13692 General information on setting up and using multi-user chatrooms can be found
13693 in the "Chatrooms" documentation (@url{http://prosody.im/doc/chatrooms}),
13694 which you should read if you are new to XMPP chatrooms.
13695
13696 See also @url{http://prosody.im/doc/modules/mod_muc}.
13697
13698 Available @code{mod-muc-configuration} fields are:
13699
13700 @deftypevr {@code{mod-muc-configuration} parameter} string name
13701 The name to return in service discovery responses.
13702 Defaults to @samp{"Prosody Chatrooms"}.
13703 @end deftypevr
13704
13705 @deftypevr {@code{mod-muc-configuration} parameter} string-or-boolean restrict-room-creation
13706 If @samp{#t}, this will only allow admins to create new chatrooms.
13707 Otherwise anyone can create a room. The value @samp{"local"} restricts room
13708 creation to users on the service's parent domain. E.g. @samp{user@@example.com}
13709 can create rooms on @samp{rooms.example.com}. The value @samp{"admin"}
13710 restricts to service administrators only.
13711 Defaults to @samp{#f}.
13712 @end deftypevr
13713
13714 @deftypevr {@code{mod-muc-configuration} parameter} non-negative-integer max-history-messages
13715 Maximum number of history messages that will be sent to the member that has
13716 just joined the room.
13717 Defaults to @samp{20}.
13718 @end deftypevr
13719
13720 @end deftypevr
13721
13722 @end deftypevr
13723
13724 @deftypevr {@code{prosody-configuration} parameter} ext-component-configuration-list ext-components
13725 External components use XEP-0114, which most standalone components
13726 support. To add an external component, you simply fill the hostname field. See
13727 @url{http://prosody.im/doc/components}.
13728 Defaults to @samp{()}.
13729
13730 Available @code{ext-component-configuration} fields are:
13731
13732 all 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:
13733 @deftypevr {@code{ext-component-configuration} parameter} string component-secret
13734 Password which the component will use to log in.
13735 @end deftypevr
13736
13737 @deftypevr {@code{ext-component-configuration} parameter} string hostname
13738 Hostname of the component.
13739 @end deftypevr
13740
13741 @end deftypevr
13742
13743 @deftypevr {@code{prosody-configuration} parameter} non-negative-integer-list component-ports
13744 Port(s) Prosody listens on for component connections.
13745 @end deftypevr
13746
13747 @deftypevr {@code{prosody-configuration} parameter} string component-interface
13748 Interface Prosody listens on for component connections.
13749 Defaults to @samp{"127.0.0.1"}.
13750 @end deftypevr
13751
13752 It could be that you just want to get a @code{prosody.cfg.lua}
13753 up and running. In that case, you can pass an
13754 @code{opaque-prosody-configuration} record as the value of
13755 @code{prosody-service-type}. As its name indicates, an opaque configuration
13756 does not have easy reflective capabilities.
13757 Available @code{opaque-prosody-configuration} fields are:
13758
13759 @deftypevr {@code{opaque-prosody-configuration} parameter} package prosody
13760 The prosody package.
13761 @end deftypevr
13762
13763 @deftypevr {@code{opaque-prosody-configuration} parameter} string prosody.cfg.lua
13764 The contents of the @code{prosody.cfg.lua} to use.
13765 @end deftypevr
13766
13767 For example, if your @code{prosody.cfg.lua} is just the empty
13768 string, you could instantiate a prosody service like this:
13769
13770 @example
13771 (service prosody-service-type
13772 (opaque-prosody-configuration
13773 (prosody.cfg.lua "")))
13774 @end example
13775
13776 @node Monitoring Services
13777 @subsubsection Monitoring Services
13778
13779 @subsubheading Tailon Service
13780
13781 @uref{https://tailon.readthedocs.io/, Tailon} is a web application for
13782 viewing and searching log files.
13783
13784 The following example will configure the service with default values.
13785 By default, Tailon can be accessed on port 8080 (@code{http://localhost:8080}).
13786
13787 @example
13788 (service tailon-service-type)
13789 @end example
13790
13791 The following example customises more of the Tailon configuration,
13792 adding @command{sed} to the list of allowed commands.
13793
13794 @example
13795 (service tailon-service-type
13796 (tailon-configuration
13797 (config-file
13798 (tailon-configuration-file
13799 (allowed-commands '("tail" "grep" "awk" "sed"))))))
13800 @end example
13801
13802
13803 @deftp {Data Type} tailon-configuration
13804 Data type representing the configuration of Tailon.
13805 This type has the following parameters:
13806
13807 @table @asis
13808 @item @code{config-file} (default: @code{(tailon-configuration-file)})
13809 The configuration file to use for Tailon. This can be set to a
13810 @dfn{tailon-configuration-file} record value, or any gexp
13811 (@pxref{G-Expressions}).
13812
13813 For example, to instead use a local file, the @code{local-file} function
13814 can be used:
13815
13816 @example
13817 (service tailon-service-type
13818 (tailon-configuration
13819 (config-file (local-file "./my-tailon.conf"))))
13820 @end example
13821
13822 @item @code{package} (default: @code{tailon})
13823 The tailon package to use.
13824
13825 @end table
13826 @end deftp
13827
13828 @deftp {Data Type} tailon-configuration-file
13829 Data type representing the configuration options for Tailon.
13830 This type has the following parameters:
13831
13832 @table @asis
13833 @item @code{files} (default: @code{(list "/var/log")})
13834 List of files to display. The list can include strings for a single file
13835 or directory, or a list, where the first item is the name of a
13836 subsection, and the remaining items are the files or directories in that
13837 subsection.
13838
13839 @item @code{bind} (default: @code{"localhost:8080"})
13840 Address and port to which Tailon should bind on.
13841
13842 @item @code{relative-root} (default: @code{#f})
13843 URL path to use for Tailon, set to @code{#f} to not use a path.
13844
13845 @item @code{allow-transfers?} (default: @code{#t})
13846 Allow downloading the log files in the web interface.
13847
13848 @item @code{follow-names?} (default: @code{#t})
13849 Allow tailing of not-yet existent files.
13850
13851 @item @code{tail-lines} (default: @code{200})
13852 Number of lines to read initially from each file.
13853
13854 @item @code{allowed-commands} (default: @code{(list "tail" "grep" "awk")})
13855 Commands to allow running. By default, @code{sed} is disabled.
13856
13857 @item @code{debug?} (default: @code{#f})
13858 Set @code{debug?} to @code{#t} to show debug messages.
13859
13860 @item @code{wrap-lines} (default: @code{#t})
13861 Initial line wrapping state in the web interface. Set to @code{#t} to
13862 initially wrap lines (the default), or to @code{#f} to initially not
13863 wrap lines.
13864
13865 @item @code{http-auth} (default: @code{#f})
13866 HTTP authentication type to use. Set to @code{#f} to disable
13867 authentication (the default). Supported values are @code{"digest"} or
13868 @code{"basic"}.
13869
13870 @item @code{users} (default: @code{#f})
13871 If HTTP authentication is enabled (see @code{http-auth}), access will be
13872 restricted to the credentials provided here. To configure users, use a
13873 list of pairs, where the first element of the pair is the username, and
13874 the 2nd element of the pair is the password.
13875
13876 @example
13877 (tailon-configuration-file
13878 (http-auth "basic")
13879 (users '(("user1" . "password1")
13880 ("user2" . "password2"))))
13881 @end example
13882
13883 @end table
13884 @end deftp
13885
13886
13887 @node Kerberos Services
13888 @subsubsection Kerberos Services
13889 @cindex Kerberos
13890
13891 The @code{(gnu services kerberos)} module provides services relating to
13892 the authentication protocol @dfn{Kerberos}.
13893
13894 @subsubheading Krb5 Service
13895
13896 Programs using a Kerberos client library normally
13897 expect a configuration file in @file{/etc/krb5.conf}.
13898 This service generates such a file from a definition provided in the
13899 operating system declaration.
13900 It does not cause any daemon to be started.
13901
13902 No ``keytab'' files are provided by this service---you must explicitly create them.
13903 This service is known to work with the MIT client library, @code{mit-krb5}.
13904 Other implementations have not been tested.
13905
13906 @defvr {Scheme Variable} krb5-service-type
13907 A service type for Kerberos 5 clients.
13908 @end defvr
13909
13910 @noindent
13911 Here is an example of its use:
13912 @lisp
13913 (service krb5-service-type
13914 (krb5-configuration
13915 (default-realm "EXAMPLE.COM")
13916 (allow-weak-crypto? #t)
13917 (realms (list
13918 (krb5-realm
13919 (name "EXAMPLE.COM")
13920 (admin-server "groucho.example.com")
13921 (kdc "karl.example.com"))
13922 (krb5-realm
13923 (name "ARGRX.EDU")
13924 (admin-server "kerb-admin.argrx.edu")
13925 (kdc "keys.argrx.edu"))))))
13926 @end lisp
13927
13928 @noindent
13929 This example provides a Kerberos@tie{}5 client configuration which:
13930 @itemize
13931 @item Recognizes two realms, @i{viz:} ``EXAMPLE.COM'' and ``ARGRX.EDU'', both
13932 of which have distinct administration servers and key distribution centers;
13933 @item Will default to the realm ``EXAMPLE.COM'' if the realm is not explicitly
13934 specified by clients;
13935 @item Accepts services which only support encryption types known to be weak.
13936 @end itemize
13937
13938 The @code{krb5-realm} and @code{krb5-configuration} types have many fields.
13939 Only the most commonly used ones are described here.
13940 For a full list, and more detailed explanation of each, see the MIT
13941 @uref{http://web.mit.edu/kerberos/krb5-devel/doc/admin/conf_files/krb5_conf.html,,krb5.conf}
13942 documentation.
13943
13944
13945 @deftp {Data Type} krb5-realm
13946 @cindex realm, kerberos
13947 @table @asis
13948 @item @code{name}
13949 This field is a string identifying the name of the realm.
13950 A common convention is to use the fully qualified DNS name of your organization,
13951 converted to upper case.
13952
13953 @item @code{admin-server}
13954 This field is a string identifying the host where the administration server is
13955 running.
13956
13957 @item @code{kdc}
13958 This field is a string identifying the key distribution center
13959 for the realm.
13960 @end table
13961 @end deftp
13962
13963 @deftp {Data Type} krb5-configuration
13964
13965 @table @asis
13966 @item @code{allow-weak-crypto?} (default: @code{#f})
13967 If this flag is @code{#t} then services which only offer encryption algorithms
13968 known to be weak will be accepted.
13969
13970 @item @code{default-realm} (default: @code{#f})
13971 This field should be a string identifying the default Kerberos
13972 realm for the client.
13973 You should set this field to the name of your Kerberos realm.
13974 If this value is @code{#f}
13975 then a realm must be specified with every Kerberos principal when invoking programs
13976 such as @command{kinit}.
13977
13978 @item @code{realms}
13979 This should be a non-empty list of @code{krb5-realm} objects, which clients may
13980 access.
13981 Normally, one of them will have a @code{name} field matching the @code{default-realm}
13982 field.
13983 @end table
13984 @end deftp
13985
13986
13987 @subsubheading PAM krb5 Service
13988 @cindex pam-krb5
13989
13990 The @code{pam-krb5} service allows for login authentication and password
13991 management via Kerberos.
13992 You will need this service if you want PAM enabled applications to authenticate
13993 users using Kerberos.
13994
13995 @defvr {Scheme Variable} pam-krb5-service-type
13996 A service type for the Kerberos 5 PAM module.
13997 @end defvr
13998
13999 @deftp {Data Type} pam-krb5-configuration
14000 Data type representing the configuration of the Kerberos 5 PAM module
14001 This type has the following parameters:
14002 @table @asis
14003 @item @code{pam-krb5} (default: @code{pam-krb5})
14004 The pam-krb5 package to use.
14005
14006 @item @code{minimum-uid} (default: @code{1000})
14007 The smallest user ID for which Kerberos authentications should be attempted.
14008 Local accounts with lower values will silently fail to authenticate.
14009 @end table
14010 @end deftp
14011
14012
14013 @node Web Services
14014 @subsubsection Web Services
14015
14016 @cindex web
14017 @cindex www
14018 @cindex HTTP
14019 The @code{(gnu services web)} module provides the nginx web server and
14020 also a fastcgi wrapper daemon.
14021
14022 @deffn {Scheme Variable} nginx-service-type
14023 Service type for the @uref{https://nginx.org/,NGinx} web server. The
14024 value for this service type is a @code{<nginx-configuration>} record.
14025
14026 A simple example configuration is given below.
14027
14028 @example
14029 (service nginx-service-type
14030 (nginx-configuration
14031 (server-list
14032 (list (nginx-server-configuration
14033 (server-name '("www.example.com"))
14034 (root "/srv/http/www.example.com")
14035 (https-port #f)
14036 (ssl-certificate #f)
14037 (ssl-certificate-key #f))))))
14038 @end example
14039
14040 In addition to adding server blocks to the service configuration
14041 directly, this service can be extended by other services to add server
14042 blocks, as in this example:
14043
14044 @example
14045 (simple-service 'my-extra-server nginx-service-type
14046 (list (nginx-server-configuration
14047 (https-port #f)
14048 (ssl-certificate #f)
14049 (ssl-certificate-key #f)
14050 (root "/srv/http/extra-website"))))
14051 @end example
14052 @end deffn
14053
14054 At startup, @command{nginx} has not yet read its configuration file, so
14055 it uses a default file to log error messages. If it fails to load its
14056 configuration file, that is where error messages are logged. After the
14057 configuration file is loaded, the default error log file changes as per
14058 configuration. In our case, startup error messages can be found in
14059 @file{/var/run/nginx/logs/error.log}, and after configuration in
14060 @file{/var/log/nginx/error.log}. The second location can be changed
14061 with the @var{log-directory} configuration option.
14062
14063 @deffn {Data Type} nginx-configuration
14064 This data type represents the configuration for NGinx. Some
14065 configuration can be done through this and the other provided record
14066 types, or alternatively, a config file can be provided.
14067
14068 @table @asis
14069 @item @code{nginx} (default: @code{nginx})
14070 The nginx package to use.
14071
14072 @item @code{log-directory} (default: @code{"/var/log/nginx"})
14073 The directory to which NGinx will write log files.
14074
14075 @item @code{run-directory} (default: @code{"/var/run/nginx"})
14076 The directory in which NGinx will create a pid file, and write temporary
14077 files.
14078
14079 @item @code{server-list} (default: @code{'()})
14080 A list of @dfn{server blocks} to create in the generated configuration
14081 file, the elements should be of type
14082 @code{<nginx-server-configuration>}.
14083
14084 The following example would setup NGinx to serve @code{www.example.com}
14085 from the @code{/srv/http/www.example.com} directory, without using
14086 HTTPS.
14087 @example
14088 (service nginx-service-type
14089 (nginx-configuration
14090 (server-list
14091 (list (nginx-server-configuration
14092 (server-name '("www.example.com"))
14093 (root "/srv/http/www.example.com")
14094 (https-port #f)
14095 (ssl-certificate #f)
14096 (ssl-certificate-key #f))))))
14097 @end example
14098
14099 @item @code{upstream-list} (default: @code{'()})
14100 A list of @dfn{upstream blocks} to create in the generated configuration
14101 file, the elements should be of type
14102 @code{<nginx-upstream-configuration>}.
14103
14104 Configuring upstreams through the @code{upstream-list} can be useful
14105 when combined with @code{locations} in the
14106 @code{<nginx-server-configuration>} records. The following example
14107 creates a server configuration with one location configuration, that
14108 will proxy requests to a upstream configuration, which will handle
14109 requests with two servers.
14110
14111 @example
14112 (service
14113 nginx-service-type
14114 (nginx-configuration
14115 (server-list
14116 (list (nginx-server-configuration
14117 (server-name '("www.example.com"))
14118 (root "/srv/http/www.example.com")
14119 (https-port #f)
14120 (ssl-certificate #f)
14121 (ssl-certificate-key #f)
14122 (locations
14123 (list
14124 (nginx-location-configuration
14125 (uri "/path1")
14126 (body '("proxy_pass http://server-proxy;"))))))))
14127 (upstream-list
14128 (list (nginx-upstream-configuration
14129 (name "server-proxy")
14130 (servers (list "server1.example.com"
14131 "server2.example.com")))))))
14132 @end example
14133
14134 @item @code{config-file} (default: @code{#f})
14135 If the @var{config-file} is provided, this will be used, rather than
14136 generating a configuration file from the provided @code{log-directory},
14137 @code{run-directory}, @code{server-list} and @code{upstream-list}. For
14138 proper operation, these arguments should match what is in
14139 @var{config-file} to ensure that the directories are created when the
14140 service is activated.
14141
14142 This can be useful if you have an existing configuration file, or it's
14143 not possible to do what is required through the other parts of the
14144 nginx-configuration record.
14145
14146 @end table
14147 @end deffn
14148
14149 @deftp {Data Type} nginx-server-configuration
14150 Data type representing the configuration of an nginx server block.
14151 This type has the following parameters:
14152
14153 @table @asis
14154 @item @code{http-port} (default: @code{80})
14155 Nginx will listen for HTTP connection on this port. Set it at @code{#f} if
14156 nginx should not listen for HTTP (non secure) connection for this
14157 @dfn{server block}.
14158
14159 @item @code{https-port} (default: @code{443})
14160 Nginx will listen for HTTPS connection on this port. Set it at @code{#f} if
14161 nginx should not listen for HTTPS (secure) connection for this @dfn{server block}.
14162
14163 Note that nginx can listen for HTTP and HTTPS connections in the same
14164 @dfn{server block}.
14165
14166 @item @code{server-name} (default: @code{(list 'default)})
14167 A list of server names this server represents. @code{'default} represents the
14168 default server for connections matching no other server.
14169
14170 @item @code{root} (default: @code{"/srv/http"})
14171 Root of the website nginx will serve.
14172
14173 @item @code{locations} (default: @code{'()})
14174 A list of @dfn{nginx-location-configuration} or
14175 @dfn{nginx-named-location-configuration} records to use within this
14176 server block.
14177
14178 @item @code{index} (default: @code{(list "index.html")})
14179 Index files to look for when clients ask for a directory. If it cannot be found,
14180 Nginx will send the list of files in the directory.
14181
14182 @item @code{ssl-certificate} (default: @code{"/etc/nginx/cert.pem"})
14183 Where to find the certificate for secure connections. Set it to @code{#f} if
14184 you don't have a certificate or you don't want to use HTTPS.
14185
14186 @item @code{ssl-certificate-key} (default: @code{"/etc/nginx/key.pem"})
14187 Where to find the private key for secure connections. Set it to @code{#f} if
14188 you don't have a key or you don't want to use HTTPS.
14189
14190 @item @code{server-tokens?} (default: @code{#f})
14191 Whether the server should add its configuration to response.
14192
14193 @end table
14194 @end deftp
14195
14196 @deftp {Data Type} nginx-upstream-configuration
14197 Data type representing the configuration of an nginx @code{upstream}
14198 block. This type has the following parameters:
14199
14200 @table @asis
14201 @item @code{name}
14202 Name for this group of servers.
14203
14204 @item @code{servers}
14205 Specify the addresses of the servers in the group. The address can be
14206 specified as a IP address (e.g. @samp{127.0.0.1}), domain name
14207 (e.g. @samp{backend1.example.com}) or a path to a UNIX socket using the
14208 prefix @samp{unix:}. For addresses using an IP address or domain name,
14209 the default port is 80, and a different port can be specified
14210 explicitly.
14211
14212 @end table
14213 @end deftp
14214
14215 @deftp {Data Type} nginx-location-configuration
14216 Data type representing the configuration of an nginx @code{location}
14217 block. This type has the following parameters:
14218
14219 @table @asis
14220 @item @code{uri}
14221 URI which this location block matches.
14222
14223 @anchor{nginx-location-configuration body}
14224 @item @code{body}
14225 Body of the location block, specified as a string. This can contain many
14226 configuration directives. For example, to pass requests to a upstream
14227 server group defined using an @code{nginx-upstream-configuration} block,
14228 the following directive would be specified in the body @samp{proxy_pass
14229 http://upstream-name;}.
14230
14231 @end table
14232 @end deftp
14233
14234 @deftp {Data Type} nginx-named-location-configuration
14235 Data type representing the configuration of an nginx named location
14236 block. Named location blocks are used for request redirection, and not
14237 used for regular request processing. This type has the following
14238 parameters:
14239
14240 @table @asis
14241 @item @code{name}
14242 Name to identify this location block.
14243
14244 @item @code{body}
14245 @xref{nginx-location-configuration body}, as the body for named location
14246 blocks can be used in a similar way to the
14247 @code{nginx-location-configuration body}. One restriction is that the
14248 body of a named location block cannot contain location blocks.
14249
14250 @end table
14251 @end deftp
14252
14253 @cindex fastcgi
14254 @cindex fcgiwrap
14255 FastCGI is an interface between the front-end and the back-end of a web
14256 service. It is a somewhat legacy facility; new web services should
14257 generally just talk HTTP between the front-end and the back-end.
14258 However there are a number of back-end services such as PHP or the
14259 optimized HTTP Git repository access that use FastCGI, so we have
14260 support for it in Guix.
14261
14262 To use FastCGI, you configure the front-end web server (e.g., nginx) to
14263 dispatch some subset of its requests to the fastcgi backend, which
14264 listens on a local TCP or UNIX socket. There is an intermediary
14265 @code{fcgiwrap} program that sits between the actual backend process and
14266 the web server. The front-end indicates which backend program to run,
14267 passing that information to the @code{fcgiwrap} process.
14268
14269 @defvr {Scheme Variable} fcgiwrap-service-type
14270 A service type for the @code{fcgiwrap} FastCGI proxy.
14271 @end defvr
14272
14273 @deftp {Data Type} fcgiwrap-configuration
14274 Data type representing the configuration of the @code{fcgiwrap} serice.
14275 This type has the following parameters:
14276 @table @asis
14277 @item @code{package} (default: @code{fcgiwrap})
14278 The fcgiwrap package to use.
14279
14280 @item @code{socket} (default: @code{tcp:127.0.0.1:9000})
14281 The socket on which the @code{fcgiwrap} process should listen, as a
14282 string. Valid @var{socket} values include
14283 @code{unix:@var{/path/to/unix/socket}},
14284 @code{tcp:@var{dot.ted.qu.ad}:@var{port}} and
14285 @code{tcp6:[@var{ipv6_addr}]:port}.
14286
14287 @item @code{user} (default: @code{fcgiwrap})
14288 @itemx @code{group} (default: @code{fcgiwrap})
14289 The user and group names, as strings, under which to run the
14290 @code{fcgiwrap} process. The @code{fastcgi} service will ensure that if
14291 the user asks for the specific user or group names @code{fcgiwrap} that
14292 the corresponding user and/or group is present on the system.
14293
14294 It is possible to configure a FastCGI-backed web service to pass HTTP
14295 authentication information from the front-end to the back-end, and to
14296 allow @code{fcgiwrap} to run the back-end process as a corresponding
14297 local user. To enable this capability on the back-end., run
14298 @code{fcgiwrap} as the @code{root} user and group. Note that this
14299 capability also has to be configured on the front-end as well.
14300 @end table
14301 @end deftp
14302
14303
14304 @node DNS Services
14305 @subsubsection DNS Services
14306 @cindex DNS (domain name system)
14307 @cindex domain name system (DNS)
14308
14309 The @code{(gnu services dns)} module provides services related to the
14310 @dfn{domain name system} (DNS). It provides a server service for hosting
14311 an @emph{authoritative} DNS server for multiple zones, slave or master.
14312 This service uses @uref{https://www.knot-dns.cz/, Knot DNS}.
14313
14314 An example configuration of an authoritative server for two zones, one master
14315 and one slave, is:
14316
14317 @lisp
14318 (define-zone-entries example.org.zone
14319 ;; Name TTL Class Type Data
14320 ("@@" "" "IN" "A" "127.0.0.1")
14321 ("@@" "" "IN" "NS" "ns")
14322 ("ns" "" "IN" "A" "127.0.0.1"))
14323
14324 (define master-zone
14325 (knot-zone-configuration
14326 (domain "example.org")
14327 (zone (zone-file
14328 (origin "example.org")
14329 (entries example.org.zone)))))
14330
14331 (define slave-zone
14332 (knot-zone-configuration
14333 (domain "plop.org")
14334 (dnssec-policy "default")
14335 (master (list "plop-master"))))
14336
14337 (define plop-master
14338 (knot-remote-configuration
14339 (id "plop-master")
14340 (address (list "208.76.58.171"))))
14341
14342 (operating-system
14343 ;; ...
14344 (services (cons* (service knot-service-type
14345 (knot-confifguration
14346 (remotes (list plop-master))
14347 (zones (list master-zone slave-zone))))
14348 ;; ...
14349 %base-services)))
14350 @end lisp
14351
14352 @deffn {Scheme Variable} knot-service-type
14353 This is the type for the Knot DNS server.
14354
14355 Knot DNS is an authoritative DNS server, meaning that it can serve multiple
14356 zones, that is to say domain names you would buy from a registrar. This server
14357 is not a resolver, meaning that it can only resolve names for which it is
14358 authoritative. This server can be configured to serve zones as a master server
14359 or a slave server as a per-zone basis. Slave zones will get their data from
14360 masters, and will serve it as an authoritative server. From the point of view
14361 of a resolver, there is no difference between master and slave.
14362
14363 The following data types are used to configure the Knot DNS server:
14364 @end deffn
14365
14366 @deftp {Data Type} knot-key-configuration
14367 Data type representing a key.
14368 This type has the following parameters:
14369
14370 @table @asis
14371 @item @code{id} (default: @code{""})
14372 An identifier for other configuration fields to refer to this key. IDs must
14373 be unique and must not be empty.
14374
14375 @item @code{algorithm} (default: @code{#f})
14376 The algorithm to use. Choose between @code{#f}, @code{'hmac-md5},
14377 @code{'hmac-sha1}, @code{'hmac-sha224}, @code{'hmac-sha256}, @code{'hmac-sha384}
14378 and @code{'hmac-sha512}.
14379
14380 @item @code{secret} (default: @code{""})
14381 The secret key itself.
14382
14383 @end table
14384 @end deftp
14385
14386 @deftp {Data Type} knot-acl-configuration
14387 Data type representing an Access Control List (ACL) configuration.
14388 This type has the following parameters:
14389
14390 @table @asis
14391 @item @code{id} (default: @code{""})
14392 An identifier for ether configuration fields to refer to this key. IDs must be
14393 unique and must not be empty.
14394
14395 @item @code{address} (default: @code{'()})
14396 An ordered list of IP addresses, network subnets, or network ranges represented
14397 with strings. The query must match one of them. Empty value means that
14398 address match is not required.
14399
14400 @item @code{key} (default: @code{'()})
14401 An ordered list of references to keys represented with strings. The string
14402 must match a key ID defined in a @code{knot-key-configuration}. No key means
14403 that a key is not require to match that ACL.
14404
14405 @item @code{action} (default: @code{'()})
14406 An ordered list of actions that are permitted or forbidden by this ACL. Possible
14407 values are lists of zero or more elements from @code{'transfer}, @code{'notify}
14408 and @code{'update}.
14409
14410 @item @code{deny?} (default: @code{#f})
14411 When true, the ACL defines restrictions. Listed actions are forbidden. When
14412 false, listed actions are allowed.
14413
14414 @end table
14415 @end deftp
14416
14417 @deftp {Data Type} zone-entry
14418 Data type represnting a record entry in a zone file.
14419 This type has the following parameters:
14420
14421 @table @asis
14422 @item @code{name} (default: @code{"@@"})
14423 The name of the record. @code{"@@"} refers to the origin of the zone. Names
14424 are relative to the origin of the zone. For example, in the @code{example.org}
14425 zone, @code{"ns.example.org"} actually refers to @code{ns.example.org.example.org}.
14426 Names ending with a dot are absolute, which means that @code{"ns.example.org."}
14427 refers to @code{ns.example.org}.
14428
14429 @item @code{ttl} (default: @code{""})
14430 The Time-To-Live (TTL) of this record. If not set, the default TTL is used.
14431
14432 @item @code{class} (default: @code{"IN"})
14433 The class of the record. Knot currently supports only @code{"IN"} and
14434 partially @code{"CH"}.
14435
14436 @item @code{type} (default: @code{"A"})
14437 The type of the record. Common types include A (IPv4 address), AAAA (IPv6
14438 address), NS (Name Server) and MX (Mail eXchange). Many other types are
14439 defined.
14440
14441 @item @code{data} (default: @code{""})
14442 The data contained in the record. For instance an IP address associated with
14443 an A record, or a domain name associated with an NS record. Remember that
14444 domain names are relative to the origin unless they end with a dot.
14445
14446 @end table
14447 @end deftp
14448
14449 @deftp {Data Type} zone-file
14450 Data type representing the content of a zone file.
14451 This type has the following parameters:
14452
14453 @table @asis
14454 @item @code{entries} (default: @code{'()})
14455 The list of entries. The SOA record is taken care of, so you don't need to
14456 put it in the list of entries. This list should probably contain an entry
14457 for your primary authoritative DNS server. Other than using a list of entries
14458 directly, you can use @code{define-zone-entries} to define a object containing
14459 the list of entries more easily, that you can later pass to the @code{entries}
14460 field of the @code{zone-file}.
14461
14462 @item @code{origin} (default: @code{""})
14463 The name of your zone. This parameter cannot be empty.
14464
14465 @item @code{ns} (default: @code{"ns"})
14466 The domain of your primary authoritative DNS server. The name is relative to
14467 the origin, unless it ends with a dot. It is mandatory that this primary
14468 DNS server corresponds to an NS record in the zone and that it is associated
14469 to an IP address in the list of entries.
14470
14471 @item @code{mail} (default: @code{"hostmaster"})
14472 An email address people can contact you at, as the owner of the zone. This
14473 is translated as @code{<mail>@@<origin>}.
14474
14475 @item @code{serial} (default: @code{1})
14476 The serial number of the zone. As this is used to keep track of changes by
14477 both slaves and resolvers, it is mandatory that it @emph{never} decreases.
14478 Always increment it when you make a change in your zone.
14479
14480 @item @code{refresh} (default: @code{(* 2 24 3600)})
14481 The frequency at which slaves will do a zone transfer. This value is a number
14482 of seconds. It can be computed by multiplications or with
14483 @code{(string->duration)}.
14484
14485 @item @code{retry} (default: @code{(* 15 60)})
14486 The period after which a slave will retry to contact its master when it fails
14487 to do so a first time.
14488
14489 @item @code{expiry} (default: @code{(* 14 24 3600)})
14490 Default TTL of records. Existing records are considered correct for at most
14491 this amount of time. After this period, resolvers will invalidate their cache
14492 and check again that it still exists.
14493
14494 @item @code{nx} (default: @code{3600})
14495 Default TTL of inexistant records. This delay is usually short because you want
14496 your new domains to reach everyone quickly.
14497
14498 @end table
14499 @end deftp
14500
14501 @deftp {Data Type} knot-remote-configuration
14502 Data type representing a remote configuration.
14503 This type has the following parameters:
14504
14505 @table @asis
14506 @item @code{id} (default: @code{""})
14507 An identifier for other configuration fields to refer to this remote. IDs must
14508 be unique and must not be empty.
14509
14510 @item @code{address} (default: @code{'()})
14511 An ordered list of destination IP addresses. Addresses are tried in sequence.
14512 An optional port can be given with the @@ separator. For instance:
14513 @code{(list "1.2.3.4" "2.3.4.5@@53")}. Default port is 53.
14514
14515 @item @code{via} (default: @code{'()})
14516 An ordered list of source IP addresses. An empty list will have Knot choose
14517 an appropriate source IP. An optional port can be given with the @@ separator.
14518 The default is to choose at random.
14519
14520 @item @code{key} (default: @code{#f})
14521 A reference to a key, that is a string containing the identifier of a key
14522 defined in a @code{knot-key-configuration} field.
14523
14524 @end table
14525 @end deftp
14526
14527 @deftp {Data Type} knot-keystore-configuration
14528 Data type representing a keystore to hold dnssec keys.
14529 This type has the following parameters:
14530
14531 @table @asis
14532 @item @code{id} (default: @code{""})
14533 The id of the keystore. It must not be empty.
14534
14535 @item @code{backend} (default: @code{'pem})
14536 The backend to store the keys in. Can be @code{'pem} or @code{'pkcs11}.
14537
14538 @item @code{config} (default: @code{"/var/lib/knot/keys/keys"})
14539 The configuration string of the backend. An example for the PKCS#11 is:
14540 @code{"pkcs11:token=knot;pin-value=1234 /gnu/store/.../lib/pkcs11/libsofthsm2.so"}.
14541 For the pem backend, the string reprensents a path in the filesystem.
14542
14543 @end table
14544 @end deftp
14545
14546 @deftp {Data Type} knot-policy-configuration
14547 Data type representing a dnssec policy. Knot DNS is able to automatically
14548 sign your zones. It can either generate and manage your keys automatically or
14549 use keys that you generate.
14550
14551 Dnssec is usually implemented using two keys: a Key Signing Key (KSK) that is
14552 used to sign the second, and a Zone Signing Key (ZSK) that is used to sign the
14553 zone. In order to be trusted, the KSK needs to be present in the parent zone
14554 (usually a top-level domain). If your registrar supports dnssec, you will
14555 have to send them your KSK's hash so they can add a DS record in their zone.
14556 This is not automated and need to be done each time you change your KSK.
14557
14558 The policy also defines the lifetime of keys. Usually, ZSK can be changed
14559 easily and use weaker cryptographic functions (they use lower parameters) in
14560 order to sign records quickly, so they are changed often. The KSK however
14561 requires manual interaction with the registrar, so they are changed less often
14562 and use stronger parameters because they sign only one record.
14563
14564 This type has the following parameters:
14565
14566 @table @asis
14567 @item @code{id} (default: @code{""})
14568 The id of the policy. It must not be empty.
14569
14570 @item @code{keystore} (default: @code{"default"})
14571 A reference to a keystore, that is a string containing the identifier of a
14572 keystore defined in a @code{knot-keystore-configuration} field. The
14573 @code{"default"} identifier means the default keystore (a kasp database that
14574 was setup by this service).
14575
14576 @item @code{manual?} (default: @code{#f})
14577 Whether the key management is manual or automatic.
14578
14579 @item @code{single-type-signing?} (default: @code{#f})
14580 When @code{#t}, use the Single-Type Signing Scheme.
14581
14582 @item @code{algorithm} (default: @code{"ecdsap256sha256"})
14583 An algorithm of signing keys and issued signatures.
14584
14585 @item @code{ksk-size} (default: @code{256})
14586 The length of the KSK. Note that this value is correct for the default
14587 algorithm, but would be unsecure for other algorithms.
14588
14589 @item @code{zsk-size} (default: @code{256})
14590 The length of the ZSK. Note that this value is correct for the default
14591 algorithm, but would be unsecure for other algorithms.
14592
14593 @item @code{dnskey-ttl} (default: @code{'default})
14594 The TTL value for DNSKEY records added into zone apex. The special
14595 @code{'default} value means same as the zone SOA TTL.
14596
14597 @item @code{zsk-lifetime} (default: @code{(* 30 24 3600)})
14598 The period between ZSK publication and the next rollover initiation.
14599
14600 @item @code{propagation-delay} (default: @code{(* 24 3600)})
14601 An extra delay added for each key rollover step. This value should be high
14602 enough to cover propagation of data from the master server to all slaves.
14603
14604 @item @code{rrsig-lifetime} (default: @code{(* 14 24 3600)})
14605 A validity period of newly issued signatures.
14606
14607 @item @code{rrsig-refresh} (default: @code{(* 7 24 3600)})
14608 A period how long before a signature expiration the signature will be refreshed.
14609
14610 @item @code{nsec3?} (default: @code{#f})
14611 When @code{#t}, NSEC3 will be used instead of NSEC.
14612
14613 @item @code{nsec3-iterations} (default: @code{5})
14614 The number of additional times the hashing is performed.
14615
14616 @item @code{nsec3-salt-length} (default: @code{8})
14617 The length of a salt field in octets, which is appended to the original owner
14618 name before hashing.
14619
14620 @item @code{nsec3-salt-lifetime} (default: @code{(* 30 24 3600)})
14621 The validity period of newly issued salt field.
14622
14623 @end table
14624 @end deftp
14625
14626 @deftp {Data Type} knot-zone-configuration
14627 Data type representing a zone served by Knot.
14628 This type has the following parameters:
14629
14630 @table @asis
14631 @item @code{domain} (default: @code{""})
14632 The domain served by this configuration. It must not be empty.
14633
14634 @item @code{file} (default: @code{""})
14635 The file where this zone is saved. This parameter is ignored by master zones.
14636 Empty means default location that depends on the domain name.
14637
14638 @item @code{zone} (default: @code{(zone-file)})
14639 The content of the zone file. This parameter is ignored by slave zones. It
14640 must contain a zone-file record.
14641
14642 @item @code{master} (default: @code{'()})
14643 A list of master remotes. When empty, this zone is a master. When set, this
14644 zone is a slave. This is a list of remotes identifiers.
14645
14646 @item @code{ddns-master} (default: @code{#f})
14647 The main master. When empty, it defaults to the first master in the list of
14648 masters.
14649
14650 @item @code{notify} (default: @code{'()})
14651 A list of slave remote identifiers.
14652
14653 @item @code{acl} (default: @code{'()})
14654 A list of acl identifiers.
14655
14656 @item @code{semantic-checks?} (default: @code{#f})
14657 When set, this adds more semantic checks to the zone.
14658
14659 @item @code{disable-any?} (default: @code{#f})
14660 When set, this forbids queries of the ANY type.
14661
14662 @item @code{zonefile-sync} (default: @code{0})
14663 The delay between a modification in memory and on disk. 0 means immediate
14664 synchronization.
14665
14666 @item @code{serial-policy} (default: @code{'increment})
14667 A policy between @code{'increment} and @code{'unixtime}.
14668
14669 @end table
14670 @end deftp
14671
14672 @deftp {Data Type} knot-configuration
14673 Data type representing the Knot configuration.
14674 This type has the following parameters:
14675
14676 @table @asis
14677 @item @code{knot} (default: @code{knot})
14678 The Knot package.
14679
14680 @item @code{run-directory} (default: @code{"/var/run/knot"})
14681 The run directory. This directory will be used for pid file and sockets.
14682
14683 @item @code{listen-v4} (default: @code{"0.0.0.0"})
14684 An ip address on which to listen.
14685
14686 @item @code{listen-v6} (default: @code{"::"})
14687 An ip address on which to listen.
14688
14689 @item @code{listen-port} (default: @code{53})
14690 A port on which to listen.
14691
14692 @item @code{keys} (default: @code{'()})
14693 The list of knot-key-configuration used by this configuration.
14694
14695 @item @code{acls} (default: @code{'()})
14696 The list of knot-acl-configuration used by this configuration.
14697
14698 @item @code{remotes} (default: @code{'()})
14699 The list of knot-remote-configuration used by this configuration.
14700
14701 @item @code{zones} (default: @code{'()})
14702 The list of knot-zone-configuration used by this configuration.
14703
14704 @end table
14705 @end deftp
14706
14707 @node VPN Services
14708 @subsubsection VPN Services
14709 @cindex VPN (virtual private network)
14710 @cindex virtual private network (VPN)
14711
14712 The @code{(gnu services vpn)} module provides services related to
14713 @dfn{virtual private networks} (VPNs). It provides a @emph{client} service for
14714 your machine to connect to a VPN, and a @emph{servire} service for your machine
14715 to host a VPN. Both services use @uref{https://openvpn.net/, OpenVPN}.
14716
14717 @deffn {Scheme Procedure} openvpn-client-service @
14718 [#:config (openvpn-client-configuration)]
14719
14720 Return a service that runs @command{openvpn}, a VPN daemon, as a client.
14721 @end deffn
14722
14723 @deffn {Scheme Procedure} openvpn-server-service @
14724 [#:config (openvpn-server-configuration)]
14725
14726 Return a service that runs @command{openvpn}, a VPN daemon, as a server.
14727
14728 Both can be run simultaneously.
14729 @end deffn
14730
14731 @c %automatically generated documentation
14732
14733 Available @code{openvpn-client-configuration} fields are:
14734
14735 @deftypevr {@code{openvpn-client-configuration} parameter} package openvpn
14736 The OpenVPN package.
14737
14738 @end deftypevr
14739
14740 @deftypevr {@code{openvpn-client-configuration} parameter} string pid-file
14741 The OpenVPN pid file.
14742
14743 Defaults to @samp{"/var/run/openvpn/openvpn.pid"}.
14744
14745 @end deftypevr
14746
14747 @deftypevr {@code{openvpn-client-configuration} parameter} proto proto
14748 The protocol (UDP or TCP) used to open a channel between clients and
14749 servers.
14750
14751 Defaults to @samp{udp}.
14752
14753 @end deftypevr
14754
14755 @deftypevr {@code{openvpn-client-configuration} parameter} dev dev
14756 The device type used to represent the VPN connection.
14757
14758 Defaults to @samp{tun}.
14759
14760 @end deftypevr
14761
14762 @deftypevr {@code{openvpn-client-configuration} parameter} string ca
14763 The certificate authority to check connections against.
14764
14765 Defaults to @samp{"/etc/openvpn/ca.crt"}.
14766
14767 @end deftypevr
14768
14769 @deftypevr {@code{openvpn-client-configuration} parameter} string cert
14770 The certificate of the machine the daemon is running on. It should be
14771 signed by the authority given in @code{ca}.
14772
14773 Defaults to @samp{"/etc/openvpn/client.crt"}.
14774
14775 @end deftypevr
14776
14777 @deftypevr {@code{openvpn-client-configuration} parameter} string key
14778 The key of the machine the daemon is running on. It must be the key whose
14779 certificate is @code{cert}.
14780
14781 Defaults to @samp{"/etc/openvpn/client.key"}.
14782
14783 @end deftypevr
14784
14785 @deftypevr {@code{openvpn-client-configuration} parameter} boolean comp-lzo?
14786 Whether to use the lzo compression algorithm.
14787
14788 Defaults to @samp{#t}.
14789
14790 @end deftypevr
14791
14792 @deftypevr {@code{openvpn-client-configuration} parameter} boolean persist-key?
14793 Don't re-read key files across SIGUSR1 or --ping-restart.
14794
14795 Defaults to @samp{#t}.
14796
14797 @end deftypevr
14798
14799 @deftypevr {@code{openvpn-client-configuration} parameter} boolean persist-tun?
14800 Don't close and reopen TUN/TAP device or run up/down scripts across
14801 SIGUSR1 or --ping-restart restarts.
14802
14803 Defaults to @samp{#t}.
14804
14805 @end deftypevr
14806
14807 @deftypevr {@code{openvpn-client-configuration} parameter} number verbosity
14808 Verbosity level.
14809
14810 Defaults to @samp{3}.
14811
14812 @end deftypevr
14813
14814 @deftypevr {@code{openvpn-client-configuration} parameter} tls-auth-client tls-auth
14815 Add an additional layer of HMAC authentication on top of the TLS control
14816 channel to protect against DoS attacks.
14817
14818 Defaults to @samp{#f}.
14819
14820 @end deftypevr
14821
14822 @deftypevr {@code{openvpn-client-configuration} parameter} key-usage verify-key-usage?
14823 Whether to check the server certificate has server usage extension.
14824
14825 Defaults to @samp{#t}.
14826
14827 @end deftypevr
14828
14829 @deftypevr {@code{openvpn-client-configuration} parameter} bind bind?
14830 Bind to a specific local port number.
14831
14832 Defaults to @samp{#f}.
14833
14834 @end deftypevr
14835
14836 @deftypevr {@code{openvpn-client-configuration} parameter} resolv-retry resolv-retry?
14837 Retry resolving server address.
14838
14839 Defaults to @samp{#t}.
14840
14841 @end deftypevr
14842
14843 @deftypevr {@code{openvpn-client-configuration} parameter} openvpn-remote-list remote
14844 A list of remote servers to connect to.
14845
14846 Defaults to @samp{()}.
14847
14848 Available @code{openvpn-remote-configuration} fields are:
14849
14850 @deftypevr {@code{openvpn-remote-configuration} parameter} string name
14851 Server name.
14852
14853 Defaults to @samp{"my-server"}.
14854
14855 @end deftypevr
14856
14857 @deftypevr {@code{openvpn-remote-configuration} parameter} number port
14858 Port number the server listens to.
14859
14860 Defaults to @samp{1194}.
14861
14862 @end deftypevr
14863
14864 @end deftypevr
14865 @c %end of automatic openvpn-client documentation
14866
14867 @c %automatically generated documentation
14868
14869 Available @code{openvpn-server-configuration} fields are:
14870
14871 @deftypevr {@code{openvpn-server-configuration} parameter} package openvpn
14872 The OpenVPN package.
14873
14874 @end deftypevr
14875
14876 @deftypevr {@code{openvpn-server-configuration} parameter} string pid-file
14877 The OpenVPN pid file.
14878
14879 Defaults to @samp{"/var/run/openvpn/openvpn.pid"}.
14880
14881 @end deftypevr
14882
14883 @deftypevr {@code{openvpn-server-configuration} parameter} proto proto
14884 The protocol (UDP or TCP) used to open a channel between clients and
14885 servers.
14886
14887 Defaults to @samp{udp}.
14888
14889 @end deftypevr
14890
14891 @deftypevr {@code{openvpn-server-configuration} parameter} dev dev
14892 The device type used to represent the VPN connection.
14893
14894 Defaults to @samp{tun}.
14895
14896 @end deftypevr
14897
14898 @deftypevr {@code{openvpn-server-configuration} parameter} string ca
14899 The certificate authority to check connections against.
14900
14901 Defaults to @samp{"/etc/openvpn/ca.crt"}.
14902
14903 @end deftypevr
14904
14905 @deftypevr {@code{openvpn-server-configuration} parameter} string cert
14906 The certificate of the machine the daemon is running on. It should be
14907 signed by the authority given in @code{ca}.
14908
14909 Defaults to @samp{"/etc/openvpn/client.crt"}.
14910
14911 @end deftypevr
14912
14913 @deftypevr {@code{openvpn-server-configuration} parameter} string key
14914 The key of the machine the daemon is running on. It must be the key whose
14915 certificate is @code{cert}.
14916
14917 Defaults to @samp{"/etc/openvpn/client.key"}.
14918
14919 @end deftypevr
14920
14921 @deftypevr {@code{openvpn-server-configuration} parameter} boolean comp-lzo?
14922 Whether to use the lzo compression algorithm.
14923
14924 Defaults to @samp{#t}.
14925
14926 @end deftypevr
14927
14928 @deftypevr {@code{openvpn-server-configuration} parameter} boolean persist-key?
14929 Don't re-read key files across SIGUSR1 or --ping-restart.
14930
14931 Defaults to @samp{#t}.
14932
14933 @end deftypevr
14934
14935 @deftypevr {@code{openvpn-server-configuration} parameter} boolean persist-tun?
14936 Don't close and reopen TUN/TAP device or run up/down scripts across
14937 SIGUSR1 or --ping-restart restarts.
14938
14939 Defaults to @samp{#t}.
14940
14941 @end deftypevr
14942
14943 @deftypevr {@code{openvpn-server-configuration} parameter} number verbosity
14944 Verbosity level.
14945
14946 Defaults to @samp{3}.
14947
14948 @end deftypevr
14949
14950 @deftypevr {@code{openvpn-server-configuration} parameter} tls-auth-server tls-auth
14951 Add an additional layer of HMAC authentication on top of the TLS control
14952 channel to protect against DoS attacks.
14953
14954 Defaults to @samp{#f}.
14955
14956 @end deftypevr
14957
14958 @deftypevr {@code{openvpn-server-configuration} parameter} number port
14959 Specifies the port number on which the server listens.
14960
14961 Defaults to @samp{1194}.
14962
14963 @end deftypevr
14964
14965 @deftypevr {@code{openvpn-server-configuration} parameter} ip-mask server
14966 An ip and mask specifying the subnet inside the virtual network.
14967
14968 Defaults to @samp{"10.8.0.0 255.255.255.0"}.
14969
14970 @end deftypevr
14971
14972 @deftypevr {@code{openvpn-server-configuration} parameter} cidr6 server-ipv6
14973 A CIDR notation specifying the IPv6 subnet inside the virtual network.
14974
14975 Defaults to @samp{#f}.
14976
14977 @end deftypevr
14978
14979 @deftypevr {@code{openvpn-server-configuration} parameter} string dh
14980 The Diffie-Hellman parameters file.
14981
14982 Defaults to @samp{"/etc/openvpn/dh2048.pem"}.
14983
14984 @end deftypevr
14985
14986 @deftypevr {@code{openvpn-server-configuration} parameter} string ifconfig-pool-persist
14987 The file that records client IPs.
14988
14989 Defaults to @samp{"/etc/openvpn/ipp.txt"}.
14990
14991 @end deftypevr
14992
14993 @deftypevr {@code{openvpn-server-configuration} parameter} gateway redirect-gateway?
14994 When true, the server will act as a gateway for its clients.
14995
14996 Defaults to @samp{#f}.
14997
14998 @end deftypevr
14999
15000 @deftypevr {@code{openvpn-server-configuration} parameter} boolean client-to-client?
15001 When true, clients are allowed to talk to each other inside the VPN.
15002
15003 Defaults to @samp{#f}.
15004
15005 @end deftypevr
15006
15007 @deftypevr {@code{openvpn-server-configuration} parameter} keepalive keepalive
15008 Causes ping-like messages to be sent back and forth over the link so
15009 that each side knows when the other side has gone down. @code{keepalive}
15010 requires a pair. The first element is the period of the ping sending,
15011 and the second element is the timeout before considering the other side
15012 down.
15013
15014 @end deftypevr
15015
15016 @deftypevr {@code{openvpn-server-configuration} parameter} number max-clients
15017 The maximum number of clients.
15018
15019 Defaults to @samp{100}.
15020
15021 @end deftypevr
15022
15023 @deftypevr {@code{openvpn-server-configuration} parameter} string status
15024 The status file. This file shows a small report on current connection.
15025 It is truncated and rewritten every minute.
15026
15027 Defaults to @samp{"/var/run/openvpn/status"}.
15028
15029 @end deftypevr
15030
15031 @deftypevr {@code{openvpn-server-configuration} parameter} openvpn-ccd-list client-config-dir
15032 The list of configuration for some clients.
15033
15034 Defaults to @samp{()}.
15035
15036 Available @code{openvpn-ccd-configuration} fields are:
15037
15038 @deftypevr {@code{openvpn-ccd-configuration} parameter} string name
15039 Client name.
15040
15041 Defaults to @samp{"client"}.
15042
15043 @end deftypevr
15044
15045 @deftypevr {@code{openvpn-ccd-configuration} parameter} ip-mask iroute
15046 Client own network
15047
15048 Defaults to @samp{#f}.
15049
15050 @end deftypevr
15051
15052 @deftypevr {@code{openvpn-ccd-configuration} parameter} ip-mask ifconfig-push
15053 Client VPN IP.
15054
15055 Defaults to @samp{#f}.
15056
15057 @end deftypevr
15058
15059 @end deftypevr
15060
15061
15062 @c %end of automatic openvpn-server documentation
15063
15064
15065 @node Network File System
15066 @subsubsection Network File System
15067 @cindex NFS
15068
15069 The @code{(gnu services nfs)} module provides the following services,
15070 which are most commonly used in relation to mounting or exporting
15071 directory trees as @dfn{network file systems} (NFS).
15072
15073 @subsubheading RPC Bind Service
15074 @cindex rpcbind
15075
15076 The RPC Bind service provides a facility to map program numbers into
15077 universal addresses.
15078 Many NFS related services use this facility. Hence it is automatically
15079 started when a dependent service starts.
15080
15081 @defvr {Scheme Variable} rpcbind-service-type
15082 A service type for the RPC portmapper daemon.
15083 @end defvr
15084
15085
15086 @deftp {Data Type} rpcbind-configuration
15087 Data type representing the configuration of the RPC Bind Service.
15088 This type has the following parameters:
15089 @table @asis
15090 @item @code{rpcbind} (default: @code{rpcbind})
15091 The rpcbind package to use.
15092
15093 @item @code{warm-start?} (default: @code{#t})
15094 If this parameter is @code{#t}, then the daemon will read a
15095 state file on startup thus reloading state information saved by a previous
15096 instance.
15097 @end table
15098 @end deftp
15099
15100
15101 @subsubheading Pipefs Pseudo File System
15102 @cindex pipefs
15103 @cindex rpc_pipefs
15104
15105 The pipefs file system is used to transfer NFS related data
15106 between the kernel and user space programs.
15107
15108 @defvr {Scheme Variable} pipefs-service-type
15109 A service type for the pipefs pseudo file system.
15110 @end defvr
15111
15112 @deftp {Data Type} pipefs-configuration
15113 Data type representing the configuration of the pipefs pseudo file system service.
15114 This type has the following parameters:
15115 @table @asis
15116 @item @code{mount-point} (default: @code{"/var/lib/nfs/rpc_pipefs"})
15117 The directory to which the file system is to be attached.
15118 @end table
15119 @end deftp
15120
15121
15122 @subsubheading GSS Daemon Service
15123 @cindex GSSD
15124 @cindex GSS
15125 @cindex global security system
15126
15127 The @dfn{global security system} (GSS) daemon provides strong security for RPC
15128 based protocols.
15129 Before exchanging RPC requests an RPC client must establish a security
15130 context. Typically this is done using the Kerberos command @command{kinit}
15131 or automatically at login time using PAM services (@pxref{Kerberos Services}).
15132
15133 @defvr {Scheme Variable} gss-service-type
15134 A service type for the Global Security System (GSS) daemon.
15135 @end defvr
15136
15137 @deftp {Data Type} gss-configuration
15138 Data type representing the configuration of the GSS daemon service.
15139 This type has the following parameters:
15140 @table @asis
15141 @item @code{nfs-utils} (default: @code{nfs-utils})
15142 The package in which the @command{rpc.gssd} command is to be found.
15143
15144 @item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
15145 The directory where the pipefs file system is mounted.
15146
15147 @end table
15148 @end deftp
15149
15150
15151 @subsubheading IDMAP Daemon Service
15152 @cindex idmapd
15153 @cindex name mapper
15154
15155 The idmap daemon service provides mapping between user IDs and user names.
15156 Typically it is required in order to access file systems mounted via NFSv4.
15157
15158 @defvr {Scheme Variable} idmap-service-type
15159 A service type for the Identity Mapper (IDMAP) daemon.
15160 @end defvr
15161
15162 @deftp {Data Type} idmap-configuration
15163 Data type representing the configuration of the IDMAP daemon service.
15164 This type has the following parameters:
15165 @table @asis
15166 @item @code{nfs-utils} (default: @code{nfs-utils})
15167 The package in which the @command{rpc.idmapd} command is to be found.
15168
15169 @item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
15170 The directory where the pipefs file system is mounted.
15171
15172 @item @code{domain} (default: @code{#f})
15173 The local NFSv4 domain name.
15174 This must be a string or @code{#f}.
15175 If it is @code{#f} then the daemon will use the host's fully qualified domain name.
15176
15177 @end table
15178 @end deftp
15179
15180 @node Continuous Integration
15181 @subsubsection Continuous Integration
15182
15183 @cindex continuous integration
15184 @uref{https://notabug.org/mthl/cuirass, Cuirass} is a continuous
15185 integration tool for Guix. It can be used both for development and for
15186 providing substitutes to others (@pxref{Substitutes}).
15187
15188 The @code{(gnu services cuirass)} module provides the following service.
15189
15190 @defvr {Scheme Procedure} cuirass-service-type
15191 The type of the Cuirass service. Its value must be a
15192 @code{cuirass-configuration} object, as described below.
15193 @end defvr
15194
15195 To add build jobs, you have to set the @code{specifications} field of
15196 the configuration. Here is an example of a service defining a build job
15197 based on a specification that can be found in Cuirass source tree. This
15198 service polls the Guix repository and builds a subset of the Guix
15199 packages, as prescribed in the @file{gnu-system.scm} example spec:
15200
15201 @example
15202 (let ((spec #~((#:name . "guix")
15203 (#:url . "git://git.savannah.gnu.org/guix.git")
15204 (#:load-path . ".")
15205
15206 ;; Here we must provide an absolute file name.
15207 ;; We take jobs from one of the examples provided
15208 ;; by Cuirass.
15209 (#:file . #$(file-append
15210 cuirass
15211 "/tests/gnu-system.scm"))
15212
15213 (#:proc . hydra-jobs)
15214 (#:arguments (subset . "hello"))
15215 (#:branch . "master"))))
15216 (service cuirass-service-type
15217 (cuirass-configuration
15218 (specifications #~(list #$spec)))))
15219 @end example
15220
15221 While information related to build jobs is located directly in the
15222 specifications, global settings for the @command{cuirass} process are
15223 accessible in other @code{cuirass-configuration} fields.
15224
15225 @deftp {Data Type} cuirass-configuration
15226 Data type representing the configuration of Cuirass.
15227
15228 @table @asis
15229 @item @code{log-file} (default: @code{"/var/log/cuirass.log"})
15230 Location of the log file.
15231
15232 @item @code{cache-directory} (default: @code{"/var/cache/cuirass"})
15233 Location of the repository cache.
15234
15235 @item @code{user} (default: @code{"cuirass"})
15236 Owner of the @code{cuirass} process.
15237
15238 @item @code{group} (default: @code{"cuirass"})
15239 Owner's group of the @code{cuirass} process.
15240
15241 @item @code{interval} (default: @code{60})
15242 Number of seconds between the poll of the repositories followed by the
15243 Cuirass jobs.
15244
15245 @item @code{database} (default: @code{"/var/run/cuirass/cuirass.db"})
15246 Location of sqlite database which contains the build results and previously
15247 added specifications.
15248
15249 @item @code{port} (default: @code{8080})
15250 Port number used by the HTTP server.
15251
15252 @item @code{specifications} (default: @code{#~'()})
15253 A gexp (@pxref{G-Expressions}) that evaluates to a list of specifications,
15254 where a specification is an association list
15255 (@pxref{Associations Lists,,, guile, GNU Guile Reference Manual}) whose
15256 keys are keywords (@code{#:keyword-example}) as shown in the example
15257 above.
15258
15259 @item @code{use-substitutes?} (default: @code{#f})
15260 This allows using substitutes to avoid building every dependencies of a job
15261 from source.
15262
15263 @item @code{one-shot?} (default: @code{#f})
15264 Only evaluate specifications and build derivations once.
15265
15266 @item @code{fallback?} (default: @code{#f})
15267 When substituting a pre-built binary fails, fall back to building
15268 packages locally.
15269
15270 @item @code{load-path} (default: @code{'()})
15271 This allows users to define their own packages and make them visible to
15272 cuirass as in @command{guix build} command.
15273
15274 @item @code{cuirass} (default: @code{cuirass})
15275 The Cuirass package to use.
15276 @end table
15277 @end deftp
15278
15279 @node Power management Services
15280 @subsubsection Power management Services
15281
15282 @cindex power management with TLP
15283 The @code{(gnu services pm)} module provides a Guix service definition
15284 for the Linux power management tool TLP.
15285
15286 TLP enables various powersaving modes in userspace and kernel.
15287 Contrary to @code{upower-service}, it is not a passive,
15288 monitoring tool, as it will apply custom settings each time a new power
15289 source is detected. More information can be found at
15290 @uref{http://linrunner.de/en/tlp/tlp.html, TLP home page}.
15291
15292 @deffn {Scheme Variable} tlp-service-type
15293 The service type for the TLP tool. Its value should be a valid
15294 TLP configuration (see below). To use the default settings, simply
15295 write:
15296 @example
15297 (service tlp-service-type)
15298 @end example
15299 @end deffn
15300
15301 By default TLP does not need much configuration but most TLP parameters
15302 can be tweaked using @code{tlp-configuration}.
15303
15304 Each parameter definition is preceded by its type; for example,
15305 @samp{boolean foo} indicates that the @code{foo} parameter
15306 should be specified as a boolean. Types starting with
15307 @code{maybe-} denote parameters that won't show up in TLP config file
15308 when their value is @code{'disabled}.
15309
15310 @c The following documentation was initially generated by
15311 @c (generate-tlp-documentation) in (gnu services pm). Manually maintained
15312 @c documentation is better, so we shouldn't hesitate to edit below as
15313 @c needed. However if the change you want to make to this documentation
15314 @c can be done in an automated way, it's probably easier to change
15315 @c (generate-documentation) than to make it below and have to deal with
15316 @c the churn as TLP updates.
15317
15318 Available @code{tlp-configuration} fields are:
15319
15320 @deftypevr {@code{tlp-configuration} parameter} package tlp
15321 The TLP package.
15322
15323 @end deftypevr
15324
15325 @deftypevr {@code{tlp-configuration} parameter} boolean tlp-enable?
15326 Set to true if you wish to enable TLP.
15327
15328 Defaults to @samp{#t}.
15329
15330 @end deftypevr
15331
15332 @deftypevr {@code{tlp-configuration} parameter} string tlp-default-mode
15333 Default mode when no power supply can be detected. Alternatives are AC
15334 and BAT.
15335
15336 Defaults to @samp{"AC"}.
15337
15338 @end deftypevr
15339
15340 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer disk-idle-secs-on-ac
15341 Number of seconds Linux kernel has to wait after the disk goes idle,
15342 before syncing on AC.
15343
15344 Defaults to @samp{0}.
15345
15346 @end deftypevr
15347
15348 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer disk-idle-secs-on-bat
15349 Same as @code{disk-idle-ac} but on BAT mode.
15350
15351 Defaults to @samp{2}.
15352
15353 @end deftypevr
15354
15355 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer max-lost-work-secs-on-ac
15356 Dirty pages flushing periodicity, expressed in seconds.
15357
15358 Defaults to @samp{15}.
15359
15360 @end deftypevr
15361
15362 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer max-lost-work-secs-on-bat
15363 Same as @code{max-lost-work-secs-on-ac} but on BAT mode.
15364
15365 Defaults to @samp{60}.
15366
15367 @end deftypevr
15368
15369 @deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list cpu-scaling-governor-on-ac
15370 CPU frequency scaling governor on AC mode. With intel_pstate driver,
15371 alternatives are powersave and performance. With acpi-cpufreq driver,
15372 alternatives are ondemand, powersave, performance and conservative.
15373
15374 Defaults to @samp{disabled}.
15375
15376 @end deftypevr
15377
15378 @deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list cpu-scaling-governor-on-bat
15379 Same as @code{cpu-scaling-governor-on-ac} but on BAT mode.
15380
15381 Defaults to @samp{disabled}.
15382
15383 @end deftypevr
15384
15385 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-min-freq-on-ac
15386 Set the min available frequency for the scaling governor on AC.
15387
15388 Defaults to @samp{disabled}.
15389
15390 @end deftypevr
15391
15392 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-max-freq-on-ac
15393 Set the max available frequency for the scaling governor on AC.
15394
15395 Defaults to @samp{disabled}.
15396
15397 @end deftypevr
15398
15399 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-min-freq-on-bat
15400 Set the min available frequency for the scaling governor on BAT.
15401
15402 Defaults to @samp{disabled}.
15403
15404 @end deftypevr
15405
15406 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-max-freq-on-bat
15407 Set the max available frequency for the scaling governor on BAT.
15408
15409 Defaults to @samp{disabled}.
15410
15411 @end deftypevr
15412
15413 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-min-perf-on-ac
15414 Limit the min P-state to control the power dissipation of the CPU, in AC
15415 mode. Values are stated as a percentage of the available performance.
15416
15417 Defaults to @samp{disabled}.
15418
15419 @end deftypevr
15420
15421 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-max-perf-on-ac
15422 Limit the max P-state to control the power dissipation of the CPU, in AC
15423 mode. Values are stated as a percentage of the available performance.
15424
15425 Defaults to @samp{disabled}.
15426
15427 @end deftypevr
15428
15429 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-min-perf-on-bat
15430 Same as @code{cpu-min-perf-on-ac} on BAT mode.
15431
15432 Defaults to @samp{disabled}.
15433
15434 @end deftypevr
15435
15436 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-max-perf-on-bat
15437 Same as @code{cpu-max-perf-on-ac} on BAT mode.
15438
15439 Defaults to @samp{disabled}.
15440
15441 @end deftypevr
15442
15443 @deftypevr {@code{tlp-configuration} parameter} maybe-boolean cpu-boost-on-ac?
15444 Enable CPU turbo boost feature on AC mode.
15445
15446 Defaults to @samp{disabled}.
15447
15448 @end deftypevr
15449
15450 @deftypevr {@code{tlp-configuration} parameter} maybe-boolean cpu-boost-on-bat?
15451 Same as @code{cpu-boost-on-ac?} on BAT mode.
15452
15453 Defaults to @samp{disabled}.
15454
15455 @end deftypevr
15456
15457 @deftypevr {@code{tlp-configuration} parameter} boolean sched-powersave-on-ac?
15458 Allow Linux kernel to minimize the number of CPU cores/hyper-threads
15459 used under light load conditions.
15460
15461 Defaults to @samp{#f}.
15462
15463 @end deftypevr
15464
15465 @deftypevr {@code{tlp-configuration} parameter} boolean sched-powersave-on-bat?
15466 Same as @code{sched-powersave-on-ac?} but on BAT mode.
15467
15468 Defaults to @samp{#t}.
15469
15470 @end deftypevr
15471
15472 @deftypevr {@code{tlp-configuration} parameter} boolean nmi-watchdog?
15473 Enable Linux kernel NMI watchdog.
15474
15475 Defaults to @samp{#f}.
15476
15477 @end deftypevr
15478
15479 @deftypevr {@code{tlp-configuration} parameter} maybe-string phc-controls
15480 For Linux kernels with PHC patch applied, change CPU voltages. An
15481 example value would be @samp{"F:V F:V F:V F:V"}.
15482
15483 Defaults to @samp{disabled}.
15484
15485 @end deftypevr
15486
15487 @deftypevr {@code{tlp-configuration} parameter} string energy-perf-policy-on-ac
15488 Set CPU performance versus energy saving policy on AC. Alternatives are
15489 performance, normal, powersave.
15490
15491 Defaults to @samp{"performance"}.
15492
15493 @end deftypevr
15494
15495 @deftypevr {@code{tlp-configuration} parameter} string energy-perf-policy-on-bat
15496 Same as @code{energy-perf-policy-ac} but on BAT mode.
15497
15498 Defaults to @samp{"powersave"}.
15499
15500 @end deftypevr
15501
15502 @deftypevr {@code{tlp-configuration} parameter} space-separated-string-list disks-devices
15503 Hard disk devices.
15504
15505 @end deftypevr
15506
15507 @deftypevr {@code{tlp-configuration} parameter} space-separated-string-list disk-apm-level-on-ac
15508 Hard disk advanced power management level.
15509
15510 @end deftypevr
15511
15512 @deftypevr {@code{tlp-configuration} parameter} space-separated-string-list disk-apm-level-on-bat
15513 Same as @code{disk-apm-bat} but on BAT mode.
15514
15515 @end deftypevr
15516
15517 @deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list disk-spindown-timeout-on-ac
15518 Hard disk spin down timeout. One value has to be specified for each
15519 declared hard disk.
15520
15521 Defaults to @samp{disabled}.
15522
15523 @end deftypevr
15524
15525 @deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list disk-spindown-timeout-on-bat
15526 Same as @code{disk-spindown-timeout-on-ac} but on BAT mode.
15527
15528 Defaults to @samp{disabled}.
15529
15530 @end deftypevr
15531
15532 @deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list disk-iosched
15533 Select IO scheduler for disk devices. One value has to be specified for
15534 each declared hard disk. Example alternatives are cfq, deadline and
15535 noop.
15536
15537 Defaults to @samp{disabled}.
15538
15539 @end deftypevr
15540
15541 @deftypevr {@code{tlp-configuration} parameter} string sata-linkpwr-on-ac
15542 SATA aggressive link power management (ALPM) level. Alternatives are
15543 min_power, medium_power, max_performance.
15544
15545 Defaults to @samp{"max_performance"}.
15546
15547 @end deftypevr
15548
15549 @deftypevr {@code{tlp-configuration} parameter} string sata-linkpwr-on-bat
15550 Same as @code{sata-linkpwr-ac} but on BAT mode.
15551
15552 Defaults to @samp{"min_power"}.
15553
15554 @end deftypevr
15555
15556 @deftypevr {@code{tlp-configuration} parameter} maybe-string sata-linkpwr-blacklist
15557 Exclude specified SATA host devices for link power management.
15558
15559 Defaults to @samp{disabled}.
15560
15561 @end deftypevr
15562
15563 @deftypevr {@code{tlp-configuration} parameter} maybe-on-off-boolean ahci-runtime-pm-on-ac?
15564 Enable Runtime Power Management for AHCI controller and disks on AC
15565 mode.
15566
15567 Defaults to @samp{disabled}.
15568
15569 @end deftypevr
15570
15571 @deftypevr {@code{tlp-configuration} parameter} maybe-on-off-boolean ahci-runtime-pm-on-bat?
15572 Same as @code{ahci-runtime-pm-on-ac} on BAT mode.
15573
15574 Defaults to @samp{disabled}.
15575
15576 @end deftypevr
15577
15578 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer ahci-runtime-pm-timeout
15579 Seconds of inactivity before disk is suspended.
15580
15581 Defaults to @samp{15}.
15582
15583 @end deftypevr
15584
15585 @deftypevr {@code{tlp-configuration} parameter} string pcie-aspm-on-ac
15586 PCI Express Active State Power Management level. Alternatives are
15587 default, performance, powersave.
15588
15589 Defaults to @samp{"performance"}.
15590
15591 @end deftypevr
15592
15593 @deftypevr {@code{tlp-configuration} parameter} string pcie-aspm-on-bat
15594 Same as @code{pcie-aspm-ac} but on BAT mode.
15595
15596 Defaults to @samp{"powersave"}.
15597
15598 @end deftypevr
15599
15600 @deftypevr {@code{tlp-configuration} parameter} string radeon-power-profile-on-ac
15601 Radeon graphics clock speed level. Alternatives are low, mid, high,
15602 auto, default.
15603
15604 Defaults to @samp{"high"}.
15605
15606 @end deftypevr
15607
15608 @deftypevr {@code{tlp-configuration} parameter} string radeon-power-profile-on-bat
15609 Same as @code{radeon-power-ac} but on BAT mode.
15610
15611 Defaults to @samp{"low"}.
15612
15613 @end deftypevr
15614
15615 @deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-state-on-ac
15616 Radeon dynamic power management method (DPM). Alternatives are battery,
15617 performance.
15618
15619 Defaults to @samp{"performance"}.
15620
15621 @end deftypevr
15622
15623 @deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-state-on-bat
15624 Same as @code{radeon-dpm-state-ac} but on BAT mode.
15625
15626 Defaults to @samp{"battery"}.
15627
15628 @end deftypevr
15629
15630 @deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-perf-level-on-ac
15631 Radeon DPM performance level. Alternatives are auto, low, high.
15632
15633 Defaults to @samp{"auto"}.
15634
15635 @end deftypevr
15636
15637 @deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-perf-level-on-bat
15638 Same as @code{radeon-dpm-perf-ac} but on BAT mode.
15639
15640 Defaults to @samp{"auto"}.
15641
15642 @end deftypevr
15643
15644 @deftypevr {@code{tlp-configuration} parameter} on-off-boolean wifi-pwr-on-ac?
15645 Wifi power saving mode.
15646
15647 Defaults to @samp{#f}.
15648
15649 @end deftypevr
15650
15651 @deftypevr {@code{tlp-configuration} parameter} on-off-boolean wifi-pwr-on-bat?
15652 Same as @code{wifi-power-ac?} but on BAT mode.
15653
15654 Defaults to @samp{#t}.
15655
15656 @end deftypevr
15657
15658 @deftypevr {@code{tlp-configuration} parameter} y-n-boolean wol-disable?
15659 Disable wake on LAN.
15660
15661 Defaults to @samp{#t}.
15662
15663 @end deftypevr
15664
15665 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer sound-power-save-on-ac
15666 Timeout duration in seconds before activating audio power saving on
15667 Intel HDA and AC97 devices. A value of 0 disables power saving.
15668
15669 Defaults to @samp{0}.
15670
15671 @end deftypevr
15672
15673 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer sound-power-save-on-bat
15674 Same as @code{sound-powersave-ac} but on BAT mode.
15675
15676 Defaults to @samp{1}.
15677
15678 @end deftypevr
15679
15680 @deftypevr {@code{tlp-configuration} parameter} y-n-boolean sound-power-save-controller?
15681 Disable controller in powersaving mode on Intel HDA devices.
15682
15683 Defaults to @samp{#t}.
15684
15685 @end deftypevr
15686
15687 @deftypevr {@code{tlp-configuration} parameter} boolean bay-poweroff-on-bat?
15688 Enable optical drive in UltraBay/MediaBay on BAT mode. Drive can be
15689 powered on again by releasing (and reinserting) the eject lever or by
15690 pressing the disc eject button on newer models.
15691
15692 Defaults to @samp{#f}.
15693
15694 @end deftypevr
15695
15696 @deftypevr {@code{tlp-configuration} parameter} string bay-device
15697 Name of the optical drive device to power off.
15698
15699 Defaults to @samp{"sr0"}.
15700
15701 @end deftypevr
15702
15703 @deftypevr {@code{tlp-configuration} parameter} string runtime-pm-on-ac
15704 Runtime Power Management for PCI(e) bus devices. Alternatives are on
15705 and auto.
15706
15707 Defaults to @samp{"on"}.
15708
15709 @end deftypevr
15710
15711 @deftypevr {@code{tlp-configuration} parameter} string runtime-pm-on-bat
15712 Same as @code{runtime-pm-ac} but on BAT mode.
15713
15714 Defaults to @samp{"auto"}.
15715
15716 @end deftypevr
15717
15718 @deftypevr {@code{tlp-configuration} parameter} boolean runtime-pm-all?
15719 Runtime Power Management for all PCI(e) bus devices, except blacklisted
15720 ones.
15721
15722 Defaults to @samp{#t}.
15723
15724 @end deftypevr
15725
15726 @deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list runtime-pm-blacklist
15727 Exclude specified PCI(e) device addresses from Runtime Power Management.
15728
15729 Defaults to @samp{disabled}.
15730
15731 @end deftypevr
15732
15733 @deftypevr {@code{tlp-configuration} parameter} space-separated-string-list runtime-pm-driver-blacklist
15734 Exclude PCI(e) devices assigned to the specified drivers from Runtime
15735 Power Management.
15736
15737 @end deftypevr
15738
15739 @deftypevr {@code{tlp-configuration} parameter} boolean usb-autosuspend?
15740 Enable USB autosuspend feature.
15741
15742 Defaults to @samp{#t}.
15743
15744 @end deftypevr
15745
15746 @deftypevr {@code{tlp-configuration} parameter} maybe-string usb-blacklist
15747 Exclude specified devices from USB autosuspend.
15748
15749 Defaults to @samp{disabled}.
15750
15751 @end deftypevr
15752
15753 @deftypevr {@code{tlp-configuration} parameter} boolean usb-blacklist-wwan?
15754 Exclude WWAN devices from USB autosuspend.
15755
15756 Defaults to @samp{#t}.
15757
15758 @end deftypevr
15759
15760 @deftypevr {@code{tlp-configuration} parameter} maybe-string usb-whitelist
15761 Include specified devices into USB autosuspend, even if they are already
15762 excluded by the driver or via @code{usb-blacklist-wwan?}.
15763
15764 Defaults to @samp{disabled}.
15765
15766 @end deftypevr
15767
15768 @deftypevr {@code{tlp-configuration} parameter} maybe-boolean usb-autosuspend-disable-on-shutdown?
15769 Enable USB autosuspend before shutdown.
15770
15771 Defaults to @samp{disabled}.
15772
15773 @end deftypevr
15774
15775 @deftypevr {@code{tlp-configuration} parameter} boolean restore-device-state-on-startup?
15776 Restore radio device state (bluetooth, wifi, wwan) from previous
15777 shutdown on system startup.
15778
15779 Defaults to @samp{#f}.
15780
15781 @end deftypevr
15782
15783
15784 The @code{(gnu services pm)} module provides an interface to
15785 thermald, a CPU frequency scaling service which helps prevent overheating.
15786
15787 @defvr {Scheme Variable} thermald-service-type
15788 This is the service type for
15789 @uref{https://01.org/linux-thermal-daemon/, thermald}, the Linux
15790 Thermal Daemon, which is responsible for controlling the thermal state
15791 of processors and preventing overheating.
15792 @end defvr
15793
15794 @deftp {Data Type} thermald-configuration
15795 Data type representing the configuration of @code{thermald-service-type}.
15796
15797 @table @asis
15798 @item @code{ignore-cpuid-check?} (default: @code{#f})
15799 Ignore cpuid check for supported CPU models.
15800
15801 @item @code{thermald} (default: @var{thermald})
15802 Package object of thermald.
15803
15804 @end table
15805 @end deftp
15806
15807 @node Audio Services
15808 @subsubsection Audio Services
15809
15810 The @code{(gnu services audio)} module provides a service to start MPD
15811 (the Music Player Daemon).
15812
15813 @cindex mpd
15814 @subsubheading Music Player Daemon
15815
15816 The Music Player Daemon (MPD) is a service that can play music while
15817 being controlled from the local machine or over the network by a variety
15818 of clients.
15819
15820 The following example shows how one might run @code{mpd} as user
15821 @code{"bob"} on port @code{6666}. It uses pulseaudio for output.
15822
15823 @example
15824 (service mpd-service-type
15825 (mpd-configuration
15826 (user "bob")
15827 (port "6666")))
15828 @end example
15829
15830 @defvr {Scheme Variable} mpd-service-type
15831 The service type for @command{mpd}
15832 @end defvr
15833
15834 @deftp {Data Type} mpd-configuration
15835 Data type representing the configuration of @command{mpd}.
15836
15837 @table @asis
15838 @item @code{user} (default: @code{"mpd"})
15839 The user to run mpd as.
15840
15841 @item @code{music-dir} (default: @code{"~/Music"})
15842 The directory to scan for music files.
15843
15844 @item @code{playlist-dir} (default: @code{"~/.mpd/playlists"})
15845 The directory to store playlists.
15846
15847 @item @code{pid-file} (default: @code{"/var/run/mpd.pid"})
15848 The file mpd wil store its PID. This must be an absolute path.
15849
15850 @item @code{port} (default: @code{"6600"})
15851 The port to run mpd on.
15852
15853 @item @code{address} (default: @code{"any"})
15854 The address that mpd will bind to. To use a Unix domain socket,
15855 an absolute path can be specified here.
15856
15857 @end table
15858 @end deftp
15859
15860 @node Virtualization Services
15861 @subsubsection Virtualization services
15862 The @code{(gnu services virtualization)} module provides services for
15863 the libvirt and virtlog daemons.
15864
15865 @subsubheading Libvirt daemon
15866 @code{libvirtd} is the server side daemon component of the libvirt
15867 virtualization management system. This daemon runs on host servers
15868 and performs required management tasks for virtualized guests.
15869
15870 @deffn {Scheme Variable} libvirt-service-type
15871 This is the type of the @uref{https://libvirt.org, libvirt daemon}.
15872 Its value must be a @code{libvirt-configuration}.
15873
15874 @example
15875 (service libvirt-service-type
15876 (libvirt-configuration
15877 (unix-sock-group "libvirt")
15878 (tls-port "16555")))
15879 @end example
15880 @end deffn
15881
15882 @c Auto-generated with (generate-libvirt-documentation)
15883 Available @code{libvirt-configuration} fields are:
15884
15885 @deftypevr {@code{libvirt-configuration} parameter} package libvirt
15886 Libvirt package.
15887
15888 @end deftypevr
15889
15890 @deftypevr {@code{libvirt-configuration} parameter} boolean listen-tls?
15891 Flag listening for secure TLS connections on the public TCP/IP port.
15892 must set @code{listen} for this to have any effect.
15893
15894 It is necessary to setup a CA and issue server certificates before using
15895 this capability.
15896
15897 Defaults to @samp{#t}.
15898
15899 @end deftypevr
15900
15901 @deftypevr {@code{libvirt-configuration} parameter} boolean listen-tcp?
15902 Listen for unencrypted TCP connections on the public TCP/IP port. must
15903 set @code{listen} for this to have any effect.
15904
15905 Using the TCP socket requires SASL authentication by default. Only SASL
15906 mechanisms which support data encryption are allowed. This is
15907 DIGEST_MD5 and GSSAPI (Kerberos5)
15908
15909 Defaults to @samp{#f}.
15910
15911 @end deftypevr
15912
15913 @deftypevr {@code{libvirt-configuration} parameter} string tls-port
15914 Port for accepting secure TLS connections This can be a port number, or
15915 service name
15916
15917 Defaults to @samp{"16514"}.
15918
15919 @end deftypevr
15920
15921 @deftypevr {@code{libvirt-configuration} parameter} string tcp-port
15922 Port for accepting insecure TCP connections This can be a port number,
15923 or service name
15924
15925 Defaults to @samp{"16509"}.
15926
15927 @end deftypevr
15928
15929 @deftypevr {@code{libvirt-configuration} parameter} string listen-addr
15930 IP address or hostname used for client connections.
15931
15932 Defaults to @samp{"0.0.0.0"}.
15933
15934 @end deftypevr
15935
15936 @deftypevr {@code{libvirt-configuration} parameter} boolean mdns-adv?
15937 Flag toggling mDNS advertisement of the libvirt service.
15938
15939 Alternatively can disable for all services on a host by stopping the
15940 Avahi daemon.
15941
15942 Defaults to @samp{#f}.
15943
15944 @end deftypevr
15945
15946 @deftypevr {@code{libvirt-configuration} parameter} string mdns-name
15947 Default mDNS advertisement name. This must be unique on the immediate
15948 broadcast network.
15949
15950 Defaults to @samp{"Virtualization Host <hostname>"}.
15951
15952 @end deftypevr
15953
15954 @deftypevr {@code{libvirt-configuration} parameter} string unix-sock-group
15955 UNIX domain socket group ownership. This can be used to allow a
15956 'trusted' set of users access to management capabilities without
15957 becoming root.
15958
15959 Defaults to @samp{"root"}.
15960
15961 @end deftypevr
15962
15963 @deftypevr {@code{libvirt-configuration} parameter} string unix-sock-ro-perms
15964 UNIX socket permissions for the R/O socket. This is used for monitoring
15965 VM status only.
15966
15967 Defaults to @samp{"0777"}.
15968
15969 @end deftypevr
15970
15971 @deftypevr {@code{libvirt-configuration} parameter} string unix-sock-rw-perms
15972 UNIX socket permissions for the R/W socket. Default allows only root.
15973 If PolicyKit is enabled on the socket, the default will change to allow
15974 everyone (eg, 0777)
15975
15976 Defaults to @samp{"0770"}.
15977
15978 @end deftypevr
15979
15980 @deftypevr {@code{libvirt-configuration} parameter} string unix-sock-admin-perms
15981 UNIX socket permissions for the admin socket. Default allows only owner
15982 (root), do not change it unless you are sure to whom you are exposing
15983 the access to.
15984
15985 Defaults to @samp{"0777"}.
15986
15987 @end deftypevr
15988
15989 @deftypevr {@code{libvirt-configuration} parameter} string unix-sock-dir
15990 The directory in which sockets will be found/created.
15991
15992 Defaults to @samp{"/var/run/libvirt"}.
15993
15994 @end deftypevr
15995
15996 @deftypevr {@code{libvirt-configuration} parameter} string auth-unix-ro
15997 Authentication scheme for UNIX read-only sockets. By default socket
15998 permissions allow anyone to connect
15999
16000 Defaults to @samp{"polkit"}.
16001
16002 @end deftypevr
16003
16004 @deftypevr {@code{libvirt-configuration} parameter} string auth-unix-rw
16005 Authentication scheme for UNIX read-write sockets. By default socket
16006 permissions only allow root. If PolicyKit support was compiled into
16007 libvirt, the default will be to use 'polkit' auth.
16008
16009 Defaults to @samp{"polkit"}.
16010
16011 @end deftypevr
16012
16013 @deftypevr {@code{libvirt-configuration} parameter} string auth-tcp
16014 Authentication scheme for TCP sockets. If you don't enable SASL, then
16015 all TCP traffic is cleartext. Don't do this outside of a dev/test
16016 scenario.
16017
16018 Defaults to @samp{"sasl"}.
16019
16020 @end deftypevr
16021
16022 @deftypevr {@code{libvirt-configuration} parameter} string auth-tls
16023 Authentication scheme for TLS sockets. TLS sockets already have
16024 encryption provided by the TLS layer, and limited authentication is done
16025 by certificates.
16026
16027 It is possible to make use of any SASL authentication mechanism as well,
16028 by using 'sasl' for this option
16029
16030 Defaults to @samp{"none"}.
16031
16032 @end deftypevr
16033
16034 @deftypevr {@code{libvirt-configuration} parameter} optional-list access-drivers
16035 API access control scheme.
16036
16037 By default an authenticated user is allowed access to all APIs. Access
16038 drivers can place restrictions on this.
16039
16040 Defaults to @samp{()}.
16041
16042 @end deftypevr
16043
16044 @deftypevr {@code{libvirt-configuration} parameter} string key-file
16045 Server key file path. If set to an empty string, then no private key is
16046 loaded.
16047
16048 Defaults to @samp{""}.
16049
16050 @end deftypevr
16051
16052 @deftypevr {@code{libvirt-configuration} parameter} string cert-file
16053 Server key file path. If set to an empty string, then no certificate is
16054 loaded.
16055
16056 Defaults to @samp{""}.
16057
16058 @end deftypevr
16059
16060 @deftypevr {@code{libvirt-configuration} parameter} string ca-file
16061 Server key file path. If set to an empty string, then no CA certificate
16062 is loaded.
16063
16064 Defaults to @samp{""}.
16065
16066 @end deftypevr
16067
16068 @deftypevr {@code{libvirt-configuration} parameter} string crl-file
16069 Certificate revocation list path. If set to an empty string, then no
16070 CRL is loaded.
16071
16072 Defaults to @samp{""}.
16073
16074 @end deftypevr
16075
16076 @deftypevr {@code{libvirt-configuration} parameter} boolean tls-no-sanity-cert
16077 Disable verification of our own server certificates.
16078
16079 When libvirtd starts it performs some sanity checks against its own
16080 certificates.
16081
16082 Defaults to @samp{#f}.
16083
16084 @end deftypevr
16085
16086 @deftypevr {@code{libvirt-configuration} parameter} boolean tls-no-verify-cert
16087 Disable verification of client certificates.
16088
16089 Client certificate verification is the primary authentication mechanism.
16090 Any client which does not present a certificate signed by the CA will be
16091 rejected.
16092
16093 Defaults to @samp{#f}.
16094
16095 @end deftypevr
16096
16097 @deftypevr {@code{libvirt-configuration} parameter} optional-list tls-allowed-dn-list
16098 Whitelist of allowed x509 Distinguished Name.
16099
16100 Defaults to @samp{()}.
16101
16102 @end deftypevr
16103
16104 @deftypevr {@code{libvirt-configuration} parameter} optional-list sasl-allowed-usernames
16105 Whitelist of allowed SASL usernames. The format for username depends on
16106 the SASL authentication mechanism.
16107
16108 Defaults to @samp{()}.
16109
16110 @end deftypevr
16111
16112 @deftypevr {@code{libvirt-configuration} parameter} string tls-priority
16113 Override the compile time default TLS priority string. The default is
16114 usually "NORMAL" unless overridden at build time. Only set this is it
16115 is desired for libvirt to deviate from the global default settings.
16116
16117 Defaults to @samp{"NORMAL"}.
16118
16119 @end deftypevr
16120
16121 @deftypevr {@code{libvirt-configuration} parameter} integer max-clients
16122 Maximum number of concurrent client connections to allow over all
16123 sockets combined.
16124
16125 Defaults to @samp{5000}.
16126
16127 @end deftypevr
16128
16129 @deftypevr {@code{libvirt-configuration} parameter} integer max-queued-clients
16130 Maximum length of queue of connections waiting to be accepted by the
16131 daemon. Note, that some protocols supporting retransmission may obey
16132 this so that a later reattempt at connection succeeds.
16133
16134 Defaults to @samp{1000}.
16135
16136 @end deftypevr
16137
16138 @deftypevr {@code{libvirt-configuration} parameter} integer max-anonymous-clients
16139 Maximum length of queue of accepted but not yet authenticated clients.
16140 Set this to zero to turn this feature off
16141
16142 Defaults to @samp{20}.
16143
16144 @end deftypevr
16145
16146 @deftypevr {@code{libvirt-configuration} parameter} integer min-workers
16147 Number of workers to start up initially.
16148
16149 Defaults to @samp{5}.
16150
16151 @end deftypevr
16152
16153 @deftypevr {@code{libvirt-configuration} parameter} integer max-workers
16154 Maximum number of worker threads.
16155
16156 If the number of active clients exceeds @code{min-workers}, then more
16157 threads are spawned, up to max_workers limit. Typically you'd want
16158 max_workers to equal maximum number of clients allowed.
16159
16160 Defaults to @samp{20}.
16161
16162 @end deftypevr
16163
16164 @deftypevr {@code{libvirt-configuration} parameter} integer prio-workers
16165 Number of priority workers. If all workers from above pool are stuck,
16166 some calls marked as high priority (notably domainDestroy) can be
16167 executed in this pool.
16168
16169 Defaults to @samp{5}.
16170
16171 @end deftypevr
16172
16173 @deftypevr {@code{libvirt-configuration} parameter} integer max-requests
16174 Total global limit on concurrent RPC calls.
16175
16176 Defaults to @samp{20}.
16177
16178 @end deftypevr
16179
16180 @deftypevr {@code{libvirt-configuration} parameter} integer max-client-requests
16181 Limit on concurrent requests from a single client connection. To avoid
16182 one client monopolizing the server this should be a small fraction of
16183 the global max_requests and max_workers parameter.
16184
16185 Defaults to @samp{5}.
16186
16187 @end deftypevr
16188
16189 @deftypevr {@code{libvirt-configuration} parameter} integer admin-min-workers
16190 Same as @code{min-workers} but for the admin interface.
16191
16192 Defaults to @samp{1}.
16193
16194 @end deftypevr
16195
16196 @deftypevr {@code{libvirt-configuration} parameter} integer admin-max-workers
16197 Same as @code{max-workers} but for the admin interface.
16198
16199 Defaults to @samp{5}.
16200
16201 @end deftypevr
16202
16203 @deftypevr {@code{libvirt-configuration} parameter} integer admin-max-clients
16204 Same as @code{max-clients} but for the admin interface.
16205
16206 Defaults to @samp{5}.
16207
16208 @end deftypevr
16209
16210 @deftypevr {@code{libvirt-configuration} parameter} integer admin-max-queued-clients
16211 Same as @code{max-queued-clients} but for the admin interface.
16212
16213 Defaults to @samp{5}.
16214
16215 @end deftypevr
16216
16217 @deftypevr {@code{libvirt-configuration} parameter} integer admin-max-client-requests
16218 Same as @code{max-client-requests} but for the admin interface.
16219
16220 Defaults to @samp{5}.
16221
16222 @end deftypevr
16223
16224 @deftypevr {@code{libvirt-configuration} parameter} integer log-level
16225 Logging level. 4 errors, 3 warnings, 2 information, 1 debug.
16226
16227 Defaults to @samp{3}.
16228
16229 @end deftypevr
16230
16231 @deftypevr {@code{libvirt-configuration} parameter} string log-filters
16232 Logging filters.
16233
16234 A filter allows to select a different logging level for a given category
16235 of logs The format for a filter is one of:
16236
16237 @itemize @bullet
16238 @item
16239 x:name
16240
16241 @item
16242 x:+name
16243
16244 @end itemize
16245
16246 where @code{name} is a string which is matched against the category
16247 given in the @code{VIR_LOG_INIT()} at the top of each libvirt source
16248 file, e.g., "remote", "qemu", or "util.json" (the name in the filter can
16249 be a substring of the full category name, in order to match multiple
16250 similar categories), the optional "+" prefix tells libvirt to log stack
16251 trace for each message matching name, and @code{x} is the minimal level
16252 where matching messages should be logged:
16253
16254 @itemize @bullet
16255 @item
16256 1: DEBUG
16257
16258 @item
16259 2: INFO
16260
16261 @item
16262 3: WARNING
16263
16264 @item
16265 4: ERROR
16266
16267 @end itemize
16268
16269 Multiple filters can be defined in a single filters statement, they just
16270 need to be separated by spaces.
16271
16272 Defaults to @samp{"3:remote 4:event"}.
16273
16274 @end deftypevr
16275
16276 @deftypevr {@code{libvirt-configuration} parameter} string log-outputs
16277 Logging outputs.
16278
16279 An output is one of the places to save logging information The format
16280 for an output can be:
16281
16282 @table @code
16283 @item x:stderr
16284 output goes to stderr
16285
16286 @item x:syslog:name
16287 use syslog for the output and use the given name as the ident
16288
16289 @item x:file:file_path
16290 output to a file, with the given filepath
16291
16292 @item x:journald
16293 output to journald logging system
16294
16295 @end table
16296
16297 In all case the x prefix is the minimal level, acting as a filter
16298
16299 @itemize @bullet
16300 @item
16301 1: DEBUG
16302
16303 @item
16304 2: INFO
16305
16306 @item
16307 3: WARNING
16308
16309 @item
16310 4: ERROR
16311
16312 @end itemize
16313
16314 Multiple outputs can be defined, they just need to be separated by
16315 spaces.
16316
16317 Defaults to @samp{"3:stderr"}.
16318
16319 @end deftypevr
16320
16321 @deftypevr {@code{libvirt-configuration} parameter} integer audit-level
16322 Allows usage of the auditing subsystem to be altered
16323
16324 @itemize @bullet
16325 @item
16326 0: disable all auditing
16327
16328 @item
16329 1: enable auditing, only if enabled on host
16330
16331 @item
16332 2: enable auditing, and exit if disabled on host.
16333
16334 @end itemize
16335
16336 Defaults to @samp{1}.
16337
16338 @end deftypevr
16339
16340 @deftypevr {@code{libvirt-configuration} parameter} boolean audit-logging
16341 Send audit messages via libvirt logging infrastructure.
16342
16343 Defaults to @samp{#f}.
16344
16345 @end deftypevr
16346
16347 @deftypevr {@code{libvirt-configuration} parameter} optional-string host-uuid
16348 Host UUID. UUID must not have all digits be the same.
16349
16350 Defaults to @samp{""}.
16351
16352 @end deftypevr
16353
16354 @deftypevr {@code{libvirt-configuration} parameter} string host-uuid-source
16355 Source to read host UUID.
16356
16357 @itemize @bullet
16358 @item
16359 @code{smbios}: fetch the UUID from @code{dmidecode -s system-uuid}
16360
16361 @item
16362 @code{machine-id}: fetch the UUID from @code{/etc/machine-id}
16363
16364 @end itemize
16365
16366 If @code{dmidecode} does not provide a valid UUID a temporary UUID will
16367 be generated.
16368
16369 Defaults to @samp{"smbios"}.
16370
16371 @end deftypevr
16372
16373 @deftypevr {@code{libvirt-configuration} parameter} integer keepalive-interval
16374 A keepalive message is sent to a client after @code{keepalive_interval}
16375 seconds of inactivity to check if the client is still responding. If
16376 set to -1, libvirtd will never send keepalive requests; however clients
16377 can still send them and the daemon will send responses.
16378
16379 Defaults to @samp{5}.
16380
16381 @end deftypevr
16382
16383 @deftypevr {@code{libvirt-configuration} parameter} integer keepalive-count
16384 Maximum number of keepalive messages that are allowed to be sent to the
16385 client without getting any response before the connection is considered
16386 broken.
16387
16388 In other words, the connection is automatically closed approximately
16389 after @code{keepalive_interval * (keepalive_count + 1)} seconds since
16390 the last message received from the client. When @code{keepalive-count}
16391 is set to 0, connections will be automatically closed after
16392 @code{keepalive-interval} seconds of inactivity without sending any
16393 keepalive messages.
16394
16395 Defaults to @samp{5}.
16396
16397 @end deftypevr
16398
16399 @deftypevr {@code{libvirt-configuration} parameter} integer admin-keepalive-interval
16400 Same as above but for admin interface.
16401
16402 Defaults to @samp{5}.
16403
16404 @end deftypevr
16405
16406 @deftypevr {@code{libvirt-configuration} parameter} integer admin-keepalive-count
16407 Same as above but for admin interface.
16408
16409 Defaults to @samp{5}.
16410
16411 @end deftypevr
16412
16413 @deftypevr {@code{libvirt-configuration} parameter} integer ovs-timeout
16414 Timeout for Open vSwitch calls.
16415
16416 The @code{ovs-vsctl} utility is used for the configuration and its
16417 timeout option is set by default to 5 seconds to avoid potential
16418 infinite waits blocking libvirt.
16419
16420 Defaults to @samp{5}.
16421
16422 @end deftypevr
16423
16424 @c %end of autogenerated docs
16425
16426 @subsubheading Virtlog daemon
16427 The virtlogd service is a server side daemon component of libvirt that is
16428 used to manage logs from virtual machine consoles.
16429
16430 This daemon is not used directly by libvirt client applications, rather it
16431 is called on their behalf by @code{libvirtd}. By maintaining the logs in a
16432 standalone daemon, the main @code{libvirtd} daemon can be restarted without
16433 risk of losing logs. The @code{virtlogd} daemon has the ability to re-exec()
16434 itself upon receiving @code{SIGUSR1}, to allow live upgrades without downtime.
16435
16436 @deffn {Scheme Variable} virtlog-service-type
16437 This is the type of the virtlog daemon.
16438 Its value must be a @code{virtlog-configuration}.
16439
16440 @example
16441 (service virtlog-service-type
16442 (virtlog-configuration
16443 (max-clients 1000)))
16444 @end example
16445 @end deffn
16446
16447 @deftypevr {@code{virtlog-configuration} parameter} integer log-level
16448 Logging level. 4 errors, 3 warnings, 2 information, 1 debug.
16449
16450 Defaults to @samp{3}.
16451
16452 @end deftypevr
16453
16454 @deftypevr {@code{virtlog-configuration} parameter} string log-filters
16455 Logging filters.
16456
16457 A filter allows to select a different logging level for a given category
16458 of logs The format for a filter is one of:
16459
16460 @itemize @bullet
16461 @item
16462 x:name
16463
16464 @item
16465 x:+name
16466
16467 @end itemize
16468
16469 where @code{name} is a string which is matched against the category
16470 given in the @code{VIR_LOG_INIT()} at the top of each libvirt source
16471 file, e.g., "remote", "qemu", or "util.json" (the name in the filter can
16472 be a substring of the full category name, in order to match multiple
16473 similar categories), the optional "+" prefix tells libvirt to log stack
16474 trace for each message matching name, and @code{x} is the minimal level
16475 where matching messages should be logged:
16476
16477 @itemize @bullet
16478 @item
16479 1: DEBUG
16480
16481 @item
16482 2: INFO
16483
16484 @item
16485 3: WARNING
16486
16487 @item
16488 4: ERROR
16489
16490 @end itemize
16491
16492 Multiple filters can be defined in a single filters statement, they just
16493 need to be separated by spaces.
16494
16495 Defaults to @samp{"3:remote 4:event"}.
16496
16497 @end deftypevr
16498
16499 @deftypevr {@code{virtlog-configuration} parameter} string log-outputs
16500 Logging outputs.
16501
16502 An output is one of the places to save logging information The format
16503 for an output can be:
16504
16505 @table @code
16506 @item x:stderr
16507 output goes to stderr
16508
16509 @item x:syslog:name
16510 use syslog for the output and use the given name as the ident
16511
16512 @item x:file:file_path
16513 output to a file, with the given filepath
16514
16515 @item x:journald
16516 output to journald logging system
16517
16518 @end table
16519
16520 In all case the x prefix is the minimal level, acting as a filter
16521
16522 @itemize @bullet
16523 @item
16524 1: DEBUG
16525
16526 @item
16527 2: INFO
16528
16529 @item
16530 3: WARNING
16531
16532 @item
16533 4: ERROR
16534
16535 @end itemize
16536
16537 Multiple outputs can be defined, they just need to be separated by
16538 spaces.
16539
16540 Defaults to @samp{"3:stderr"}.
16541
16542 @end deftypevr
16543
16544 @deftypevr {@code{virtlog-configuration} parameter} integer max-clients
16545 Maximum number of concurrent client connections to allow over all
16546 sockets combined.
16547
16548 Defaults to @samp{1024}.
16549
16550 @end deftypevr
16551
16552 @deftypevr {@code{virtlog-configuration} parameter} integer max-size
16553 Maximum file size before rolling over.
16554
16555 Defaults to @samp{2MB}
16556
16557 @end deftypevr
16558
16559 @deftypevr {@code{virtlog-configuration} parameter} integer max-backups
16560 Maximum number of backup files to keep.
16561
16562 Defaults to @samp{3}
16563
16564 @end deftypevr
16565
16566
16567 @node Miscellaneous Services
16568 @subsubsection Miscellaneous Services
16569
16570 @cindex sysctl
16571 @subsubheading System Control Service
16572
16573 The @code{(gnu services sysctl)} provides a service to configure kernel
16574 parameters at boot.
16575
16576 @defvr {Scheme Variable} sysctl-service-type
16577 The service type for @command{sysctl}, which modifies kernel parameters
16578 under @file{/proc/sys/}. To enable IPv4 forwarding, it can be
16579 instantiated as:
16580
16581 @example
16582 (service sysctl-service-type
16583 (sysctl-configuration
16584 (settings '(("net.ipv4.ip_forward" . "1")))))
16585 @end example
16586 @end defvr
16587
16588 @deftp {Data Type} sysctl-configuration
16589 The data type representing the configuration of @command{sysctl}.
16590
16591 @table @asis
16592 @item @code{sysctl} (default: @code{(file-append procps "/sbin/sysctl"})
16593 The @command{sysctl} executable to use.
16594
16595 @item @code{settings} (default: @code{'()})
16596 An association list specifies kernel parameters and their values.
16597 @end table
16598 @end deftp
16599
16600 @cindex lirc
16601 @subsubheading Lirc Service
16602
16603 The @code{(gnu services lirc)} module provides the following service.
16604
16605 @deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
16606 [#:device #f] [#:driver #f] [#:config-file #f] @
16607 [#:extra-options '()]
16608 Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
16609 decodes infrared signals from remote controls.
16610
16611 Optionally, @var{device}, @var{driver} and @var{config-file}
16612 (configuration file name) may be specified. See @command{lircd} manual
16613 for details.
16614
16615 Finally, @var{extra-options} is a list of additional command-line options
16616 passed to @command{lircd}.
16617 @end deffn
16618
16619 @cindex spice
16620 @subsubheading Spice Service
16621
16622 The @code{(gnu services spice)} module provides the following service.
16623
16624 @deffn {Scheme Procedure} spice-vdagent-service [#:spice-vdagent]
16625 Returns a service that runs @url{http://www.spice-space.org,VDAGENT}, a daemon
16626 that enables sharing the clipboard with a vm and setting the guest display
16627 resolution when the graphical console window resizes.
16628 @end deffn
16629
16630 @subsubsection Dictionary Services
16631 @cindex dictionary
16632 The @code{(gnu services dict)} module provides the following service:
16633
16634 @deffn {Scheme Procedure} dicod-service [#:config (dicod-configuration)]
16635 Return a service that runs the @command{dicod} daemon, an implementation
16636 of DICT server (@pxref{Dicod,,, dico, GNU Dico Manual}).
16637
16638 The optional @var{config} argument specifies the configuration for
16639 @command{dicod}, which should be a @code{<dicod-configuration>} object, by
16640 default it serves the GNU Collaborative International Dictonary of English.
16641
16642 You can add @command{open localhost} to your @file{~/.dico} file to make
16643 @code{localhost} the default server for @command{dico} client
16644 (@pxref{Initialization File,,, dico, GNU Dico Manual}).
16645 @end deffn
16646
16647 @deftp {Data Type} dicod-configuration
16648 Data type representing the configuration of dicod.
16649
16650 @table @asis
16651 @item @code{dico} (default: @var{dico})
16652 Package object of the GNU Dico dictionary server.
16653
16654 @item @code{interfaces} (default: @var{'("localhost")})
16655 This is the list of IP addresses and ports and possibly socket file
16656 names to listen to (@pxref{Server Settings, @code{listen} directive,,
16657 dico, GNU Dico Manual}).
16658
16659 @item @code{handlers} (default: @var{'()})
16660 List of @code{<dicod-handler>} objects denoting handlers (module instances).
16661
16662 @item @code{databases} (default: @var{(list %dicod-database:gcide)})
16663 List of @code{<dicod-database>} objects denoting dictionaries to be served.
16664 @end table
16665 @end deftp
16666
16667 @deftp {Data Type} dicod-handler
16668 Data type representing a dictionary handler (module instance).
16669
16670 @table @asis
16671 @item @code{name}
16672 Name of the handler (module instance).
16673
16674 @item @code{module} (default: @var{#f})
16675 Name of the dicod module of the handler (instance). If it is @code{#f},
16676 the module has the same name as the handler.
16677 (@pxref{Modules,,, dico, GNU Dico Manual}).
16678
16679 @item @code{options}
16680 List of strings or gexps representing the arguments for the module handler
16681 @end table
16682 @end deftp
16683
16684 @deftp {Data Type} dicod-database
16685 Data type representing a dictionary database.
16686
16687 @table @asis
16688 @item @code{name}
16689 Name of the database, will be used in DICT commands.
16690
16691 @item @code{handler}
16692 Name of the dicod handler (module instance) used by this database
16693 (@pxref{Handlers,,, dico, GNU Dico Manual}).
16694
16695 @item @code{complex?} (default: @var{#f})
16696 Whether the database configuration complex. The complex configuration
16697 will need a corresponding @code{<dicod-handler>} object, otherwise not.
16698
16699 @item @code{options}
16700 List of strings or gexps representing the arguments for the database
16701 (@pxref{Databases,,, dico, GNU Dico Manual}).
16702 @end table
16703 @end deftp
16704
16705 @defvr {Scheme Variable} %dicod-database:gcide
16706 A @code{<dicod-database>} object serving the GNU Collaborative International
16707 Dictionary of English using the @code{gcide} package.
16708 @end defvr
16709
16710 The following is an example @code{dicod-service} configuration.
16711
16712 @example
16713 (dicod-service #:config
16714 (dicod-configuration
16715 (handlers (list (dicod-handler
16716 (name "wordnet")
16717 (module "dictorg")
16718 (options
16719 (list #~(string-append "dbdir=" #$wordnet))))))
16720 (databases (list (dicod-database
16721 (name "wordnet")
16722 (complex? #t)
16723 (handler "wordnet")
16724 (options '("database=wn")))
16725 %dicod-database:gcide))))
16726 @end example
16727
16728 @subsubsection Version Control
16729
16730 The @code{(gnu services version-control)} module provides the following services:
16731
16732 @subsubheading Git daemon service
16733
16734 @deffn {Scheme Procedure} git-daemon-service [#:config (git-daemon-configuration)]
16735
16736 Return a service that runs @command{git daemon}, a simple TCP server to
16737 expose repositories over the Git protocol for anonymous access.
16738
16739 The optional @var{config} argument should be a
16740 @code{<git-daemon-configuration>} object, by default it allows read-only
16741 access to exported@footnote{By creating the magic file
16742 "git-daemon-export-ok" in the repository directory.} repositories under
16743 @file{/srv/git}.
16744
16745 @end deffn
16746
16747 @deftp {Data Type} git-daemon-configuration
16748 Data type representing the configuration for @code{git-daemon-service}.
16749
16750 @table @asis
16751 @item @code{package} (default: @var{git})
16752 Package object of the Git distributed version control system.
16753
16754 @item @code{export-all?} (default: @var{#f})
16755 Whether to allow access for all Git repositories, even if they do not
16756 have the @file{git-daemon-export-ok} file.
16757
16758 @item @code{base-path} (default: @file{/srv/git})
16759 Whether to remap all the path requests as relative to the given path.
16760 If you run git daemon with @var{(base-path "/srv/git")} on example.com,
16761 then if you later try to pull @code{git://example.com/hello.git}, git
16762 daemon will interpret the path as @code{/srv/git/hello.git}.
16763
16764 @item @code{user-path} (default: @var{#f})
16765 Whether to allow @code{~user} notation to be used in requests. When
16766 specified with empty string, requests to @code{git://host/~alice/foo} is
16767 taken as a request to access @code{foo} repository in the home directory
16768 of user @code{alice}. If @var{(user-path "path")} is specified, the
16769 same request is taken as a request to access @code{path/foo} repository
16770 in the home directory of user @code{alice}.
16771
16772 @item @code{listen} (default: @var{'()})
16773 Whether to listen on specific IP addresses or hostnames, defaults to
16774 all.
16775
16776 @item @code{port} (default: @var{#f})
16777 Whether to listen on an alternative port, which defaults to 9418.
16778
16779 @item @code{whitelist} (default: @var{'()})
16780 If not empty, only allow access to this list of directories.
16781
16782 @item @code{extra-options} (default: @var{'()})
16783 Extra options will be passed to @code{git daemon}, please run
16784 @command{man git-daemon} for more information.
16785
16786 @end table
16787 @end deftp
16788
16789 @node Setuid Programs
16790 @subsection Setuid Programs
16791
16792 @cindex setuid programs
16793 Some programs need to run with ``root'' privileges, even when they are
16794 launched by unprivileged users. A notorious example is the
16795 @command{passwd} program, which users can run to change their
16796 password, and which needs to access the @file{/etc/passwd} and
16797 @file{/etc/shadow} files---something normally restricted to root, for
16798 obvious security reasons. To address that, these executables are
16799 @dfn{setuid-root}, meaning that they always run with root privileges
16800 (@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
16801 for more info about the setuid mechanism.)
16802
16803 The store itself @emph{cannot} contain setuid programs: that would be a
16804 security issue since any user on the system can write derivations that
16805 populate the store (@pxref{The Store}). Thus, a different mechanism is
16806 used: instead of changing the setuid bit directly on files that are in
16807 the store, we let the system administrator @emph{declare} which programs
16808 should be setuid root.
16809
16810 The @code{setuid-programs} field of an @code{operating-system}
16811 declaration contains a list of G-expressions denoting the names of
16812 programs to be setuid-root (@pxref{Using the Configuration System}).
16813 For instance, the @command{passwd} program, which is part of the Shadow
16814 package, can be designated by this G-expression (@pxref{G-Expressions}):
16815
16816 @example
16817 #~(string-append #$shadow "/bin/passwd")
16818 @end example
16819
16820 A default set of setuid programs is defined by the
16821 @code{%setuid-programs} variable of the @code{(gnu system)} module.
16822
16823 @defvr {Scheme Variable} %setuid-programs
16824 A list of G-expressions denoting common programs that are setuid-root.
16825
16826 The list includes commands such as @command{passwd}, @command{ping},
16827 @command{su}, and @command{sudo}.
16828 @end defvr
16829
16830 Under the hood, the actual setuid programs are created in the
16831 @file{/run/setuid-programs} directory at system activation time. The
16832 files in this directory refer to the ``real'' binaries, which are in the
16833 store.
16834
16835 @node X.509 Certificates
16836 @subsection X.509 Certificates
16837
16838 @cindex HTTPS, certificates
16839 @cindex X.509 certificates
16840 @cindex TLS
16841 Web servers available over HTTPS (that is, HTTP over the transport-layer
16842 security mechanism, TLS) send client programs an @dfn{X.509 certificate}
16843 that the client can then use to @emph{authenticate} the server. To do
16844 that, clients verify that the server's certificate is signed by a
16845 so-called @dfn{certificate authority} (CA). But to verify the CA's
16846 signature, clients must have first acquired the CA's certificate.
16847
16848 Web browsers such as GNU@tie{}IceCat include their own set of CA
16849 certificates, such that they are able to verify CA signatures
16850 out-of-the-box.
16851
16852 However, most other programs that can talk HTTPS---@command{wget},
16853 @command{git}, @command{w3m}, etc.---need to be told where CA
16854 certificates can be found.
16855
16856 @cindex @code{nss-certs}
16857 In GuixSD, this is done by adding a package that provides certificates
16858 to the @code{packages} field of the @code{operating-system} declaration
16859 (@pxref{operating-system Reference}). GuixSD includes one such package,
16860 @code{nss-certs}, which is a set of CA certificates provided as part of
16861 Mozilla's Network Security Services.
16862
16863 Note that it is @emph{not} part of @var{%base-packages}, so you need to
16864 explicitly add it. The @file{/etc/ssl/certs} directory, which is where
16865 most applications and libraries look for certificates by default, points
16866 to the certificates installed globally.
16867
16868 Unprivileged users, including users of Guix on a foreign distro,
16869 can also install their own certificate package in
16870 their profile. A number of environment variables need to be defined so
16871 that applications and libraries know where to find them. Namely, the
16872 OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
16873 variables. Some applications add their own environment variables; for
16874 instance, the Git version control system honors the certificate bundle
16875 pointed to by the @code{GIT_SSL_CAINFO} environment variable. Thus, you
16876 would typically run something like:
16877
16878 @example
16879 $ guix package -i nss-certs
16880 $ export SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs"
16881 $ export SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt"
16882 $ export GIT_SSL_CAINFO="$SSL_CERT_FILE"
16883 @end example
16884
16885 As another example, R requires the @code{CURL_CA_BUNDLE} environment
16886 variable to point to a certificate bundle, so you would have to run
16887 something like this:
16888
16889 @example
16890 $ guix package -i nss-certs
16891 $ export CURL_CA_BUNDLE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt"
16892 @end example
16893
16894 For other applications you may want to look up the required environment
16895 variable in the relevant documentation.
16896
16897
16898 @node Name Service Switch
16899 @subsection Name Service Switch
16900
16901 @cindex name service switch
16902 @cindex NSS
16903 The @code{(gnu system nss)} module provides bindings to the
16904 configuration file of the libc @dfn{name service switch} or @dfn{NSS}
16905 (@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
16906 Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
16907 extended with new ``name'' lookup methods for system databases, which
16908 includes host names, service names, user accounts, and more (@pxref{Name
16909 Service Switch, System Databases and Name Service Switch,, libc, The GNU
16910 C Library Reference Manual}).
16911
16912 The NSS configuration specifies, for each system database, which lookup
16913 method is to be used, and how the various methods are chained
16914 together---for instance, under which circumstances NSS should try the
16915 next method in the list. The NSS configuration is given in the
16916 @code{name-service-switch} field of @code{operating-system} declarations
16917 (@pxref{operating-system Reference, @code{name-service-switch}}).
16918
16919 @cindex nss-mdns
16920 @cindex .local, host name lookup
16921 As an example, the declaration below configures the NSS to use the
16922 @uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
16923 back-end}, which supports host name lookups over multicast DNS (mDNS)
16924 for host names ending in @code{.local}:
16925
16926 @example
16927 (name-service-switch
16928 (hosts (list %files ;first, check /etc/hosts
16929
16930 ;; If the above did not succeed, try
16931 ;; with 'mdns_minimal'.
16932 (name-service
16933 (name "mdns_minimal")
16934
16935 ;; 'mdns_minimal' is authoritative for
16936 ;; '.local'. When it returns "not found",
16937 ;; no need to try the next methods.
16938 (reaction (lookup-specification
16939 (not-found => return))))
16940
16941 ;; Then fall back to DNS.
16942 (name-service
16943 (name "dns"))
16944
16945 ;; Finally, try with the "full" 'mdns'.
16946 (name-service
16947 (name "mdns")))))
16948 @end example
16949
16950 Do not worry: the @code{%mdns-host-lookup-nss} variable (see below)
16951 contains this configuration, so you will not have to type it if all you
16952 want is to have @code{.local} host lookup working.
16953
16954 Note that, in this case, in addition to setting the
16955 @code{name-service-switch} of the @code{operating-system} declaration,
16956 you also need to use @code{avahi-service} (@pxref{Networking Services,
16957 @code{avahi-service}}), or @var{%desktop-services}, which includes it
16958 (@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
16959 to the name service cache daemon (@pxref{Base Services,
16960 @code{nscd-service}}).
16961
16962 For convenience, the following variables provide typical NSS
16963 configurations.
16964
16965 @defvr {Scheme Variable} %default-nss
16966 This is the default name service switch configuration, a
16967 @code{name-service-switch} object.
16968 @end defvr
16969
16970 @defvr {Scheme Variable} %mdns-host-lookup-nss
16971 This is the name service switch configuration with support for host name
16972 lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
16973 @end defvr
16974
16975 The reference for name service switch configuration is given below. It
16976 is a direct mapping of the configuration file format of the C library , so
16977 please refer to the C library manual for more information (@pxref{NSS
16978 Configuration File,,, libc, The GNU C Library Reference Manual}).
16979 Compared to the configuration file format of libc NSS, it has the advantage
16980 not only of adding this warm parenthetic feel that we like, but also
16981 static checks: you will know about syntax errors and typos as soon as you
16982 run @command{guix system}.
16983
16984 @deftp {Data Type} name-service-switch
16985
16986 This is the data type representation the configuration of libc's name
16987 service switch (NSS). Each field below represents one of the supported
16988 system databases.
16989
16990 @table @code
16991 @item aliases
16992 @itemx ethers
16993 @itemx group
16994 @itemx gshadow
16995 @itemx hosts
16996 @itemx initgroups
16997 @itemx netgroup
16998 @itemx networks
16999 @itemx password
17000 @itemx public-key
17001 @itemx rpc
17002 @itemx services
17003 @itemx shadow
17004 The system databases handled by the NSS. Each of these fields must be a
17005 list of @code{<name-service>} objects (see below).
17006 @end table
17007 @end deftp
17008
17009 @deftp {Data Type} name-service
17010
17011 This is the data type representing an actual name service and the
17012 associated lookup action.
17013
17014 @table @code
17015 @item name
17016 A string denoting the name service (@pxref{Services in the NSS
17017 configuration,,, libc, The GNU C Library Reference Manual}).
17018
17019 Note that name services listed here must be visible to nscd. This is
17020 achieved by passing the @code{#:name-services} argument to
17021 @code{nscd-service} the list of packages providing the needed name
17022 services (@pxref{Base Services, @code{nscd-service}}).
17023
17024 @item reaction
17025 An action specified using the @code{lookup-specification} macro
17026 (@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
17027 Reference Manual}). For example:
17028
17029 @example
17030 (lookup-specification (unavailable => continue)
17031 (success => return))
17032 @end example
17033 @end table
17034 @end deftp
17035
17036 @node Initial RAM Disk
17037 @subsection Initial RAM Disk
17038
17039 @cindex initrd
17040 @cindex initial RAM disk
17041 For bootstrapping purposes, the Linux-Libre kernel is passed an
17042 @dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
17043 root file system as well as an initialization script. The latter is
17044 responsible for mounting the real root file system, and for loading any
17045 kernel modules that may be needed to achieve that.
17046
17047 The @code{initrd} field of an @code{operating-system} declaration allows
17048 you to specify which initrd you would like to use. The @code{(gnu
17049 system linux-initrd)} module provides three ways to build an initrd: the
17050 high-level @code{base-initrd} procedure and the low-level
17051 @code{raw-initrd} and @code{expression->initrd} procedures.
17052
17053 The @code{base-initrd} procedure is intended to cover most common uses.
17054 For example, if you want to add a bunch of kernel modules to be loaded
17055 at boot time, you can define the @code{initrd} field of the operating
17056 system declaration like this:
17057
17058 @example
17059 (initrd (lambda (file-systems . rest)
17060 ;; Create a standard initrd that has modules "foo.ko"
17061 ;; and "bar.ko", as well as their dependencies, in
17062 ;; addition to the modules available by default.
17063 (apply base-initrd file-systems
17064 #:extra-modules '("foo" "bar")
17065 rest)))
17066 @end example
17067
17068 The @code{base-initrd} procedure also handles common use cases that
17069 involves using the system as a QEMU guest, or as a ``live'' system with
17070 volatile root file system.
17071
17072 The @code{base-initrd} procedure is built from @code{raw-initrd} procedure.
17073 Unlike @code{base-initrd}, @code{raw-initrd} doesn't do anything high-level,
17074 such as trying to guess which kernel modules and packages should be included
17075 to the initrd. An example use of @code{raw-initrd} is when a user has
17076 a custom Linux kernel configuration and default kernel modules included by
17077 @code{base-initrd} are not available.
17078
17079 The initial RAM disk produced by @code{base-initrd} or @code{raw-initrd}
17080 honors several options passed on the Linux kernel command line
17081 (that is, arguments passed @i{via} the @code{linux} command of GRUB, or the
17082 @code{-append} option of QEMU), notably:
17083
17084 @table @code
17085 @item --load=@var{boot}
17086 Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
17087 program, once it has mounted the root file system.
17088
17089 GuixSD uses this option to yield control to a boot program that runs the
17090 service activation programs and then spawns the GNU@tie{}Shepherd, the
17091 initialization system.
17092
17093 @item --root=@var{root}
17094 Mount @var{root} as the root file system. @var{root} can be a
17095 device name like @code{/dev/sda1}, a partition label, or a partition
17096 UUID.
17097
17098 @item --system=@var{system}
17099 Have @file{/run/booted-system} and @file{/run/current-system} point to
17100 @var{system}.
17101
17102 @item modprobe.blacklist=@var{modules}@dots{}
17103 @cindex module, black-listing
17104 @cindex black list, of kernel modules
17105 Instruct the initial RAM disk as well as the @command{modprobe} command
17106 (from the kmod package) to refuse to load @var{modules}. @var{modules}
17107 must be a comma-separated list of module names---e.g.,
17108 @code{usbkbd,9pnet}.
17109
17110 @item --repl
17111 Start a read-eval-print loop (REPL) from the initial RAM disk before it
17112 tries to load kernel modules and to mount the root file system. Our
17113 marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
17114 love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
17115 Manual}, for more information on Guile's REPL.
17116
17117 @end table
17118
17119 Now that you know all the features that initial RAM disks produced by
17120 @code{base-initrd} and @code{raw-initrd} provide,
17121 here is how to use it and customize it further.
17122
17123 @cindex initrd
17124 @cindex initial RAM disk
17125 @deffn {Monadic Procedure} raw-initrd @var{file-systems} @
17126 [#:linux-modules '()] [#:mapped-devices '()] @
17127 [#:helper-packages '()] [#:qemu-networking? #f] [#:volatile-root? #f]
17128 Return a monadic derivation that builds a raw initrd. @var{file-systems} is
17129 a list of file systems to be mounted by the initrd, possibly in addition to
17130 the root file system specified on the kernel command line via @code{--root}.
17131 @var{linux-modules} is a list of kernel modules to be loaded at boot time.
17132 @var{mapped-devices} is a list of device mappings to realize before
17133 @var{file-systems} are mounted (@pxref{Mapped Devices}).
17134 @var{helper-packages} is a list of packages to be copied in the initrd. It may
17135 include @code{e2fsck/static} or other packages needed by the initrd to check
17136 root partition.
17137
17138 When @var{qemu-networking?} is true, set up networking with the standard QEMU
17139 parameters. When @var{virtio?} is true, load additional modules so that the
17140 initrd can be used as a QEMU guest with para-virtualized I/O drivers.
17141
17142 When @var{volatile-root?} is true, the root file system is writable but any changes
17143 to it are lost.
17144 @end deffn
17145
17146 @deffn {Monadic Procedure} base-initrd @var{file-systems} @
17147 [#:mapped-devices '()] [#:qemu-networking? #f] [#:volatile-root? #f]@
17148 [#:virtio? #t] [#:extra-modules '()]
17149 Return a monadic derivation that builds a generic initrd. @var{file-systems} is
17150 a list of file systems to be mounted by the initrd like for @code{raw-initrd}.
17151 @var{mapped-devices}, @var{qemu-networking?} and @var{volatile-root?}
17152 also behaves as in @code{raw-initrd}.
17153
17154 When @var{virtio?} is true, load additional modules so that the
17155 initrd can be used as a QEMU guest with para-virtualized I/O drivers.
17156
17157 The initrd is automatically populated with all the kernel modules necessary
17158 for @var{file-systems} and for the given options. However, additional kernel
17159 modules can be listed in @var{extra-modules}. They will be added to the initrd, and
17160 loaded at boot time in the order in which they appear.
17161 @end deffn
17162
17163 Needless to say, the initrds we produce and use embed a
17164 statically-linked Guile, and the initialization program is a Guile
17165 program. That gives a lot of flexibility. The
17166 @code{expression->initrd} procedure builds such an initrd, given the
17167 program to run in that initrd.
17168
17169 @deffn {Monadic Procedure} expression->initrd @var{exp} @
17170 [#:guile %guile-static-stripped] [#:name "guile-initrd"]
17171 Return a derivation that builds a Linux initrd (a gzipped cpio archive)
17172 containing @var{guile} and that evaluates @var{exp}, a G-expression,
17173 upon booting. All the derivations referenced by @var{exp} are
17174 automatically copied to the initrd.
17175 @end deffn
17176
17177 @node Bootloader Configuration
17178 @subsection Bootloader Configuration
17179
17180 @cindex bootloader
17181 @cindex boot loader
17182
17183 The operating system supports multiple bootloaders. The bootloader is
17184 configured using @code{bootloader-configuration} declaration. All the
17185 fields of this structure are bootloader agnostic except for one field,
17186 @code{bootloader} that indicates the bootloader to be configured and
17187 installed.
17188
17189 Some of the bootloaders do not honor every field of
17190 @code{bootloader-configuration}. For instance, the extlinux
17191 bootloader does not support themes and thus ignores the @code{theme}
17192 field.
17193
17194 @deftp {Data Type} bootloader-configuration
17195 The type of a bootloader configuration declaration.
17196
17197 @table @asis
17198
17199 @item @code{bootloader}
17200 @cindex EFI, bootloader
17201 @cindex UEFI, bootloader
17202 @cindex BIOS, bootloader
17203 The bootloader to use, as a @code{bootloader} object. For now
17204 @code{grub-bootloader}, @code{grub-efi-bootloader},
17205 @code{extlinux-bootloader} and @code{u-boot-bootloader} are supported.
17206 @code{grub-efi-bootloader} allows to boot on modern systems using the
17207 @dfn{Unified Extensible Firmware Interface} (UEFI).
17208
17209 Available bootloaders are described in @code{(gnu bootloader @dots{})}
17210 modules.
17211
17212 @item @code{target}
17213 This is a string denoting the target onto which to install the
17214 bootloader. The exact interpretation depends on the bootloader in
17215 question; for @code{grub-bootloader}, for example, it should be a device
17216 name understood by the bootloader @command{installer} command, such as
17217 @code{/dev/sda} or @code{(hd0)} (for GRUB, @pxref{Invoking
17218 grub-install,,, grub, GNU GRUB Manual}). For
17219 @code{grub-efi-bootloader}, it should be the path to a mounted EFI file
17220 system.
17221
17222 @item @code{menu-entries} (default: @code{()})
17223 A possibly empty list of @code{menu-entry} objects (see below), denoting
17224 entries to appear in the bootloader menu, in addition to the current
17225 system entry and the entry pointing to previous system generations.
17226 generations.
17227
17228 @item @code{default-entry} (default: @code{0})
17229 The index of the default boot menu entry. Index 0 is for the entry of the
17230 current system.
17231
17232 @item @code{timeout} (default: @code{5})
17233 The number of seconds to wait for keyboard input before booting. Set to
17234 0 to boot immediately, and to -1 to wait indefinitely.
17235
17236 @item @code{theme} (default: @var{#f})
17237 The bootloader theme object describing the theme to use. If no theme
17238 is provided, some bootloaders might use a default theme, that's true
17239 for GRUB.
17240
17241 @item @code{terminal-outputs} (default: @code{'gfxterm})
17242 The output terminals used for the bootloader boot menu, as a list of
17243 symbols. GRUB accepts the values: @code{console}, @code{serial},
17244 @code{serial_@{0-3@}}, @code{gfxterm}, @code{vga_text},
17245 @code{mda_text}, @code{morse}, and @code{pkmodem}. This field
17246 corresponds to the GRUB variable GRUB_TERMINAL_OUTPUT (@pxref{Simple
17247 configuration,,, grub,GNU GRUB manual}).
17248
17249 @item @code{terminal-inputs} (default: @code{'()})
17250 The input terminals used for the bootloader boot menu, as a list of
17251 symbols. For GRUB, the default is the native platform terminal as
17252 determined at run-time. GRUB accepts the values: @code{console},
17253 @code{serial}, @code{serial_@{0-3@}}, @code{at_keyboard}, and
17254 @code{usb_keyboard}. This field corresponds to the GRUB variable
17255 GRUB_TERMINAL_INPUT (@pxref{Simple configuration,,, grub,GNU GRUB
17256 manual}).
17257
17258 @item @code{serial-unit} (default: @code{#f})
17259 The serial unit used by the bootloader, as an integer from 0 to 3.
17260 For GRUB it is choosen at run-time; currently GRUB chooses 0, which
17261 corresponds to COM1 (@pxref{Serial terminal,,, grub,GNU GRUB manual}).
17262
17263 @item @code{serial-speed} (default: @code{#f})
17264 The speed of the serial interface, as an integer. For GRUB, the
17265 default value is chosen at run-time; currently GRUB chooses
17266 9600@tie{}bps (@pxref{Serial terminal,,, grub,GNU GRUB manual}).
17267 @end table
17268
17269 @end deftp
17270
17271 @cindex dual boot
17272 @cindex boot menu
17273 Should you want to list additional boot menu entries @i{via} the
17274 @code{menu-entries} field above, you will need to create them with the
17275 @code{menu-entry} form. For example, imagine you want to be able to
17276 boot another distro (hard to imagine!), you can define a menu entry
17277 along these lines:
17278
17279 @example
17280 (menu-entry
17281 (label "The Other Distro")
17282 (linux "/boot/old/vmlinux-2.6.32")
17283 (linux-arguments '("root=/dev/sda2"))
17284 (initrd "/boot/old/initrd"))
17285 @end example
17286
17287 Details below.
17288
17289 @deftp {Data Type} menu-entry
17290 The type of an entry in the bootloader menu.
17291
17292 @table @asis
17293
17294 @item @code{label}
17295 The label to show in the menu---e.g., @code{"GNU"}.
17296
17297 @item @code{linux}
17298 The Linux kernel image to boot, for example:
17299
17300 @example
17301 (file-append linux-libre "/bzImage")
17302 @end example
17303
17304 For GRUB, it is also possible to specify a device explicitly in the
17305 file path using GRUB's device naming convention (@pxref{Naming
17306 convention,,, grub, GNU GRUB manual}), for example:
17307
17308 @example
17309 "(hd0,msdos1)/boot/vmlinuz"
17310 @end example
17311
17312 If the device is specified explicitly as above, then the @code{device}
17313 field is ignored entirely.
17314
17315 @item @code{linux-arguments} (default: @code{()})
17316 The list of extra Linux kernel command-line arguments---e.g.,
17317 @code{("console=ttyS0")}.
17318
17319 @item @code{initrd}
17320 A G-Expression or string denoting the file name of the initial RAM disk
17321 to use (@pxref{G-Expressions}).
17322 @item @code{device} (default: @code{#f})
17323 The device where the kernel and initrd are to be found---i.e., for GRUB,
17324 @dfn{root} for this menu entry (@pxref{root,,, grub, GNU GRUB manual}).
17325
17326 This may be a file system label (a string), a file system UUID (a
17327 bytevector, @pxref{File Systems}), or @code{#f}, in which case
17328 the bootloader will search the device containing the file specified by
17329 the @code{linux} field (@pxref{search,,, grub, GNU GRUB manual}). It
17330 must @emph{not} be an OS device name such as @file{/dev/sda1}.
17331
17332 @end table
17333 @end deftp
17334
17335 @c FIXME: Write documentation once it's stable.
17336 Fow now only GRUB has theme support. GRUB themes are created using
17337 the @code{grub-theme} form, which is not documented yet.
17338
17339 @defvr {Scheme Variable} %default-theme
17340 This is the default GRUB theme used by the operating system if no
17341 @code{theme} field is specified in @code{bootloader-configuration}
17342 record.
17343
17344 It comes with a fancy background image displaying the GNU and Guix
17345 logos.
17346 @end defvr
17347
17348
17349 @node Invoking guix system
17350 @subsection Invoking @code{guix system}
17351
17352 Once you have written an operating system declaration as seen in the
17353 previous section, it can be @dfn{instantiated} using the @command{guix
17354 system} command. The synopsis is:
17355
17356 @example
17357 guix system @var{options}@dots{} @var{action} @var{file}
17358 @end example
17359
17360 @var{file} must be the name of a file containing an
17361 @code{operating-system} declaration. @var{action} specifies how the
17362 operating system is instantiated. Currently the following values are
17363 supported:
17364
17365 @table @code
17366 @item reconfigure
17367 Build the operating system described in @var{file}, activate it, and
17368 switch to it@footnote{This action (and the related actions
17369 @code{switch-generation} and @code{roll-back}) are usable only on
17370 systems already running GuixSD.}.
17371
17372 This effects all the configuration specified in @var{file}: user
17373 accounts, system services, global package list, setuid programs, etc.
17374 The command starts system services specified in @var{file} that are not
17375 currently running; if a service is currently running, it does not
17376 attempt to upgrade it since this would not be possible without stopping it
17377 first.
17378
17379 This command creates a new generation whose number is one greater than
17380 the current generation (as reported by @command{guix system
17381 list-generations}). If that generation already exists, it will be
17382 overwritten. This behavior mirrors that of @command{guix package}
17383 (@pxref{Invoking guix package}).
17384
17385 It also adds a bootloader menu entry for the new OS configuration,
17386 ---unless @option{--no-bootloader} is passed. For GRUB, it moves
17387 entries for older configurations to a submenu, allowing you to choose
17388 an older system generation at boot time should you need it.
17389
17390 @quotation Note
17391 @c The paragraph below refers to the problem discussed at
17392 @c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
17393 It is highly recommended to run @command{guix pull} once before you run
17394 @command{guix system reconfigure} for the first time (@pxref{Invoking
17395 guix pull}). Failing to do that you would see an older version of Guix
17396 once @command{reconfigure} has completed.
17397 @end quotation
17398
17399 @item switch-generation
17400 @cindex generations
17401 Switch to an existing system generation. This action atomically
17402 switches the system profile to the specified system generation. It
17403 also rearranges the system's existing bootloader menu entries. It
17404 makes the menu entry for the specified system generation the default,
17405 and it moves the entries for the other generatiors to a submenu, if
17406 supported by the bootloader being used. The next time the system
17407 boots, it will use the specified system generation.
17408
17409 The bootloader itself is not being reinstalled when using this
17410 command. Thus, the installed bootloader is used with an updated
17411 configuration file.
17412
17413 The target generation can be specified explicitly by its generation
17414 number. For example, the following invocation would switch to system
17415 generation 7:
17416
17417 @example
17418 guix system switch-generation 7
17419 @end example
17420
17421 The target generation can also be specified relative to the current
17422 generation with the form @code{+N} or @code{-N}, where @code{+3} means
17423 ``3 generations ahead of the current generation,'' and @code{-1} means
17424 ``1 generation prior to the current generation.'' When specifying a
17425 negative value such as @code{-1}, you must precede it with @code{--} to
17426 prevent it from being parsed as an option. For example:
17427
17428 @example
17429 guix system switch-generation -- -1
17430 @end example
17431
17432 Currently, the effect of invoking this action is @emph{only} to switch
17433 the system profile to an existing generation and rearrange the
17434 bootloader menu entries. To actually start using the target system
17435 generation, you must reboot after running this action. In the future,
17436 it will be updated to do the same things as @command{reconfigure},
17437 like activating and deactivating services.
17438
17439 This action will fail if the specified generation does not exist.
17440
17441 @item roll-back
17442 @cindex rolling back
17443 Switch to the preceding system generation. The next time the system
17444 boots, it will use the preceding system generation. This is the inverse
17445 of @command{reconfigure}, and it is exactly the same as invoking
17446 @command{switch-generation} with an argument of @code{-1}.
17447
17448 Currently, as with @command{switch-generation}, you must reboot after
17449 running this action to actually start using the preceding system
17450 generation.
17451
17452 @item build
17453 Build the derivation of the operating system, which includes all the
17454 configuration files and programs needed to boot and run the system.
17455 This action does not actually install anything.
17456
17457 @item init
17458 Populate the given directory with all the files necessary to run the
17459 operating system specified in @var{file}. This is useful for first-time
17460 installations of GuixSD. For instance:
17461
17462 @example
17463 guix system init my-os-config.scm /mnt
17464 @end example
17465
17466 copies to @file{/mnt} all the store items required by the configuration
17467 specified in @file{my-os-config.scm}. This includes configuration
17468 files, packages, and so on. It also creates other essential files
17469 needed for the system to operate correctly---e.g., the @file{/etc},
17470 @file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
17471
17472 This command also installs bootloader on the target specified in
17473 @file{my-os-config}, unless the @option{--no-bootloader} option was
17474 passed.
17475
17476 @item vm
17477 @cindex virtual machine
17478 @cindex VM
17479 @anchor{guix system vm}
17480 Build a virtual machine that contains the operating system declared in
17481 @var{file}, and return a script to run that virtual machine (VM).
17482 Arguments given to the script are passed to QEMU as in the example
17483 below, which enables networking and requests 1@tie{}GiB of RAM for the
17484 emulated machine:
17485
17486 @example
17487 $ /gnu/store/@dots{}-run-vm.sh -m 1024 -net user
17488 @end example
17489
17490 The VM shares its store with the host system.
17491
17492 Additional file systems can be shared between the host and the VM using
17493 the @code{--share} and @code{--expose} command-line options: the former
17494 specifies a directory to be shared with write access, while the latter
17495 provides read-only access to the shared directory.
17496
17497 The example below creates a VM in which the user's home directory is
17498 accessible read-only, and where the @file{/exchange} directory is a
17499 read-write mapping of @file{$HOME/tmp} on the host:
17500
17501 @example
17502 guix system vm my-config.scm \
17503 --expose=$HOME --share=$HOME/tmp=/exchange
17504 @end example
17505
17506 On GNU/Linux, the default is to boot directly to the kernel; this has
17507 the advantage of requiring only a very tiny root disk image since the
17508 store of the host can then be mounted.
17509
17510 The @code{--full-boot} option forces a complete boot sequence, starting
17511 with the bootloader. This requires more disk space since a root image
17512 containing at least the kernel, initrd, and bootloader data files must
17513 be created. The @code{--image-size} option can be used to specify the
17514 size of the image.
17515
17516 @item vm-image
17517 @itemx disk-image
17518 Return a virtual machine or disk image of the operating system declared
17519 in @var{file} that stands alone. By default, @command{guix system}
17520 estimates the size of the image needed to store the system, but you can
17521 use the @option{--image-size} option to specify a value.
17522
17523 You can specify the root file system type by using the
17524 @option{--file-system-type} option. It defaults to @code{ext4}.
17525
17526 When using @code{vm-image}, the returned image is in qcow2 format, which
17527 the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
17528 for more information on how to run the image in a virtual machine.
17529
17530 When using @code{disk-image}, a raw disk image is produced; it can be
17531 copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
17532 the device corresponding to a USB stick, one can copy the image to it
17533 using the following command:
17534
17535 @example
17536 # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
17537 @end example
17538
17539 @item container
17540 Return a script to run the operating system declared in @var{file}
17541 within a container. Containers are a set of lightweight isolation
17542 mechanisms provided by the kernel Linux-libre. Containers are
17543 substantially less resource-demanding than full virtual machines since
17544 the kernel, shared objects, and other resources can be shared with the
17545 host system; this also means they provide thinner isolation.
17546
17547 Currently, the script must be run as root in order to support more than
17548 a single user and group. The container shares its store with the host
17549 system.
17550
17551 As with the @code{vm} action (@pxref{guix system vm}), additional file
17552 systems to be shared between the host and container can be specified
17553 using the @option{--share} and @option{--expose} options:
17554
17555 @example
17556 guix system container my-config.scm \
17557 --expose=$HOME --share=$HOME/tmp=/exchange
17558 @end example
17559
17560 @quotation Note
17561 This option requires Linux-libre 3.19 or newer.
17562 @end quotation
17563
17564 @end table
17565
17566 @var{options} can contain any of the common build options (@pxref{Common
17567 Build Options}). In addition, @var{options} can contain one of the
17568 following:
17569
17570 @table @option
17571 @item --system=@var{system}
17572 @itemx -s @var{system}
17573 Attempt to build for @var{system} instead of the host system type.
17574 This works as per @command{guix build} (@pxref{Invoking guix build}).
17575
17576 @item --derivation
17577 @itemx -d
17578 Return the derivation file name of the given operating system without
17579 building anything.
17580
17581 @item --file-system-type=@var{type}
17582 @itemx -t @var{type}
17583 For the @code{disk-image} action, create a file system of the given
17584 @var{type} on the image.
17585
17586 When this option is omitted, @command{guix system} uses @code{ext4}.
17587
17588 @cindex ISO-9660 format
17589 @cindex CD image format
17590 @cindex DVD image format
17591 @code{--file-system-type=iso9660} produces an ISO-9660 image, suitable
17592 for burning on CDs and DVDs.
17593
17594 @item --image-size=@var{size}
17595 For the @code{vm-image} and @code{disk-image} actions, create an image
17596 of the given @var{size}. @var{size} may be a number of bytes, or it may
17597 include a unit as a suffix (@pxref{Block size, size specifications,,
17598 coreutils, GNU Coreutils}).
17599
17600 When this option is omitted, @command{guix system} computes an estimate
17601 of the image size as a function of the size of the system declared in
17602 @var{file}.
17603
17604 @item --root=@var{file}
17605 @itemx -r @var{file}
17606 Make @var{file} a symlink to the result, and register it as a garbage
17607 collector root.
17608
17609 @item --on-error=@var{strategy}
17610 Apply @var{strategy} when an error occurs when reading @var{file}.
17611 @var{strategy} may be one of the following:
17612
17613 @table @code
17614 @item nothing-special
17615 Report the error concisely and exit. This is the default strategy.
17616
17617 @item backtrace
17618 Likewise, but also display a backtrace.
17619
17620 @item debug
17621 Report the error and enter Guile's debugger. From there, you can run
17622 commands such as @code{,bt} to get a backtrace, @code{,locals} to
17623 display local variable values, and more generally inspect the state of the
17624 program. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
17625 a list of available debugging commands.
17626 @end table
17627 @end table
17628
17629 @quotation Note
17630 All the actions above, except @code{build} and @code{init},
17631 can use KVM support in the Linux-libre kernel. Specifically, if the
17632 machine has hardware virtualization support, the corresponding
17633 KVM kernel module should be loaded, and the @file{/dev/kvm} device node
17634 must exist and be readable and writable by the user and by the
17635 build users of the daemon (@pxref{Build Environment Setup}).
17636 @end quotation
17637
17638 Once you have built, configured, re-configured, and re-re-configured
17639 your GuixSD installation, you may find it useful to list the operating
17640 system generations available on disk---and that you can choose from the
17641 bootloader boot menu:
17642
17643 @table @code
17644
17645 @item list-generations
17646 List a summary of each generation of the operating system available on
17647 disk, in a human-readable way. This is similar to the
17648 @option{--list-generations} option of @command{guix package}
17649 (@pxref{Invoking guix package}).
17650
17651 Optionally, one can specify a pattern, with the same syntax that is used
17652 in @command{guix package --list-generations}, to restrict the list of
17653 generations displayed. For instance, the following command displays
17654 generations that are up to 10 days old:
17655
17656 @example
17657 $ guix system list-generations 10d
17658 @end example
17659
17660 @end table
17661
17662 The @command{guix system} command has even more to offer! The following
17663 sub-commands allow you to visualize how your system services relate to
17664 each other:
17665
17666 @anchor{system-extension-graph}
17667 @table @code
17668
17669 @item extension-graph
17670 Emit in Dot/Graphviz format to standard output the @dfn{service
17671 extension graph} of the operating system defined in @var{file}
17672 (@pxref{Service Composition}, for more information on service
17673 extensions.)
17674
17675 The command:
17676
17677 @example
17678 $ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
17679 @end example
17680
17681 produces a PDF file showing the extension relations among services.
17682
17683 @anchor{system-shepherd-graph}
17684 @item shepherd-graph
17685 Emit in Dot/Graphviz format to standard output the @dfn{dependency
17686 graph} of shepherd services of the operating system defined in
17687 @var{file}. @xref{Shepherd Services}, for more information and for an
17688 example graph.
17689
17690 @end table
17691
17692 @node Running GuixSD in a VM
17693 @subsection Running GuixSD in a Virtual Machine
17694
17695 @cindex virtual machine
17696 To run GuixSD in a virtual machine (VM), one can either use the
17697 pre-built GuixSD VM image distributed at
17698 @indicateurl{ftp://alpha.gnu.org/guix/guixsd-vm-image-@value{VERSION}.@var{system}.tar.xz}
17699 , or build their own virtual machine image using @command{guix system
17700 vm-image} (@pxref{Invoking guix system}). The returned image is in
17701 qcow2 format, which the @uref{http://qemu.org/, QEMU emulator} can
17702 efficiently use.
17703
17704 @cindex QEMU
17705 If you built your own image, you must copy it out of the store
17706 (@pxref{The Store}) and give yourself permission to write to the copy
17707 before you can use it. When invoking QEMU, you must choose a system
17708 emulator that is suitable for your hardware platform. Here is a minimal
17709 QEMU invocation that will boot the result of @command{guix system
17710 vm-image} on x86_64 hardware:
17711
17712 @example
17713 $ qemu-system-x86_64 \
17714 -net user -net nic,model=virtio \
17715 -enable-kvm -m 256 /tmp/qemu-image
17716 @end example
17717
17718 Here is what each of these options means:
17719
17720 @table @code
17721 @item qemu-system-x86_64
17722 This specifies the hardware platform to emulate. This should match the
17723 host.
17724
17725 @item -net user
17726 Enable the unprivileged user-mode network stack. The guest OS can
17727 access the host but not vice versa. This is the simplest way to get the
17728 guest OS online.
17729
17730 @item -net nic,model=virtio
17731 You must create a network interface of a given model. If you do not
17732 create a NIC, the boot will fail. Assuming your hardware platform is
17733 x86_64, you can get a list of available NIC models by running
17734 @command{qemu-system-x86_64 -net nic,model=help}.
17735
17736 @item -enable-kvm
17737 If your system has hardware virtualization extensions, enabling the
17738 virtual machine support (KVM) of the Linux kernel will make things run
17739 faster.
17740
17741 @item -m 256
17742 RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
17743 which may be insufficient for some operations.
17744
17745 @item /tmp/qemu-image
17746 The file name of the qcow2 image.
17747 @end table
17748
17749 The default @command{run-vm.sh} script that is returned by an invocation of
17750 @command{guix system vm} does not add a @command{-net user} flag by default.
17751 To get network access from within the vm add the @code{(dhcp-client-service)}
17752 to your system definition and start the VM using
17753 @command{`guix system vm config.scm` -net user}. An important caveat of using
17754 @command{-net user} for networking is that @command{ping} will not work, because
17755 it uses the ICMP protocol. You'll have to use a different command to check for
17756 network connectivity, for example @command{guix download}.
17757
17758 @subsubsection Connecting Through SSH
17759
17760 @cindex SSH
17761 @cindex SSH server
17762 To enable SSH inside a VM you need to add a SSH server like @code{(dropbear-service)}
17763 or @code{(lsh-service)} to your VM. The @code{(lsh-service}) doesn't currently
17764 boot unsupervised. It requires you to type some characters to initialize the
17765 randomness generator. In addition you need to forward the SSH port, 22 by
17766 default, to the host. You can do this with
17767
17768 @example
17769 `guix system vm config.scm` -net user,hostfwd=tcp::10022-:22
17770 @end example
17771
17772 To connect to the VM you can run
17773
17774 @example
17775 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022
17776 @end example
17777
17778 The @command{-p} tells @command{ssh} the port you want to connect to.
17779 @command{-o UserKnownHostsFile=/dev/null} prevents @command{ssh} from complaining
17780 every time you modify your @command{config.scm} file and the
17781 @command{-o StrictHostKeyChecking=no} prevents you from having to allow a
17782 connection to an unknown host every time you connect.
17783
17784 @subsubsection Using @command{virt-viewer} with Spice
17785
17786 As an alternative to the default @command{qemu} graphical client you can
17787 use the @command{remote-viewer} from the @command{virt-viewer} package. To
17788 connect pass the @command{-spice port=5930,disable-ticketing} flag to
17789 @command{qemu}. See previous section for further information on how to do this.
17790
17791 Spice also allows you to do some nice stuff like share your clipboard with your
17792 VM. To enable that you'll also have to pass the following flags to @command{qemu}:
17793
17794 @example
17795 -device virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0,addr=0x5
17796 -chardev spicevmc,name=vdagent,id=vdagent
17797 -device virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,
17798 name=com.redhat.spice.0
17799 @end example
17800
17801 You'll also need to add the @pxref{Miscellaneous Services, Spice service}.
17802
17803 @node Defining Services
17804 @subsection Defining Services
17805
17806 The previous sections show the available services and how one can combine
17807 them in an @code{operating-system} declaration. But how do we define
17808 them in the first place? And what is a service anyway?
17809
17810 @menu
17811 * Service Composition:: The model for composing services.
17812 * Service Types and Services:: Types and services.
17813 * Service Reference:: API reference.
17814 * Shepherd Services:: A particular type of service.
17815 @end menu
17816
17817 @node Service Composition
17818 @subsubsection Service Composition
17819
17820 @cindex services
17821 @cindex daemons
17822 Here we define a @dfn{service} as, broadly, something that extends the
17823 functionality of the operating system. Often a service is a process---a
17824 @dfn{daemon}---started when the system boots: a secure shell server, a
17825 Web server, the Guix build daemon, etc. Sometimes a service is a daemon
17826 whose execution can be triggered by another daemon---e.g., an FTP server
17827 started by @command{inetd} or a D-Bus service activated by
17828 @command{dbus-daemon}. Occasionally, a service does not map to a
17829 daemon. For instance, the ``account'' service collects user accounts
17830 and makes sure they exist when the system runs; the ``udev'' service
17831 collects device management rules and makes them available to the eudev
17832 daemon; the @file{/etc} service populates the @file{/etc} directory
17833 of the system.
17834
17835 @cindex service extensions
17836 GuixSD services are connected by @dfn{extensions}. For instance, the
17837 secure shell service @emph{extends} the Shepherd---the GuixSD
17838 initialization system, running as PID@tie{}1---by giving it the command
17839 lines to start and stop the secure shell daemon (@pxref{Networking
17840 Services, @code{lsh-service}}); the UPower service extends the D-Bus
17841 service by passing it its @file{.service} specification, and extends the
17842 udev service by passing it device management rules (@pxref{Desktop
17843 Services, @code{upower-service}}); the Guix daemon service extends the
17844 Shepherd by passing it the command lines to start and stop the daemon,
17845 and extends the account service by passing it a list of required build
17846 user accounts (@pxref{Base Services}).
17847
17848 All in all, services and their ``extends'' relations form a directed
17849 acyclic graph (DAG). If we represent services as boxes and extensions
17850 as arrows, a typical system might provide something like this:
17851
17852 @image{images/service-graph,,5in,Typical service extension graph.}
17853
17854 @cindex system service
17855 At the bottom, we see the @dfn{system service}, which produces the
17856 directory containing everything to run and boot the system, as returned
17857 by the @command{guix system build} command. @xref{Service Reference},
17858 to learn about the other service types shown here.
17859 @xref{system-extension-graph, the @command{guix system extension-graph}
17860 command}, for information on how to generate this representation for a
17861 particular operating system definition.
17862
17863 @cindex service types
17864 Technically, developers can define @dfn{service types} to express these
17865 relations. There can be any number of services of a given type on the
17866 system---for instance, a system running two instances of the GNU secure
17867 shell server (lsh) has two instances of @var{lsh-service-type}, with
17868 different parameters.
17869
17870 The following section describes the programming interface for service
17871 types and services.
17872
17873 @node Service Types and Services
17874 @subsubsection Service Types and Services
17875
17876 A @dfn{service type} is a node in the DAG described above. Let us start
17877 with a simple example, the service type for the Guix build daemon
17878 (@pxref{Invoking guix-daemon}):
17879
17880 @example
17881 (define guix-service-type
17882 (service-type
17883 (name 'guix)
17884 (extensions
17885 (list (service-extension shepherd-root-service-type guix-shepherd-service)
17886 (service-extension account-service-type guix-accounts)
17887 (service-extension activation-service-type guix-activation)))
17888 (default-value (guix-configuration))))
17889 @end example
17890
17891 @noindent
17892 It defines three things:
17893
17894 @enumerate
17895 @item
17896 A name, whose sole purpose is to make inspection and debugging easier.
17897
17898 @item
17899 A list of @dfn{service extensions}, where each extension designates the
17900 target service type and a procedure that, given the parameters of the
17901 service, returns a list of objects to extend the service of that type.
17902
17903 Every service type has at least one service extension. The only
17904 exception is the @dfn{boot service type}, which is the ultimate service.
17905
17906 @item
17907 Optionally, a default value for instances of this type.
17908 @end enumerate
17909
17910 In this example, @var{guix-service-type} extends three services:
17911
17912 @table @var
17913 @item shepherd-root-service-type
17914 The @var{guix-shepherd-service} procedure defines how the Shepherd
17915 service is extended. Namely, it returns a @code{<shepherd-service>}
17916 object that defines how @command{guix-daemon} is started and stopped
17917 (@pxref{Shepherd Services}).
17918
17919 @item account-service-type
17920 This extension for this service is computed by @var{guix-accounts},
17921 which returns a list of @code{user-group} and @code{user-account}
17922 objects representing the build user accounts (@pxref{Invoking
17923 guix-daemon}).
17924
17925 @item activation-service-type
17926 Here @var{guix-activation} is a procedure that returns a gexp, which is
17927 a code snippet to run at ``activation time''---e.g., when the service is
17928 booted.
17929 @end table
17930
17931 A service of this type is instantiated like this:
17932
17933 @example
17934 (service guix-service-type
17935 (guix-configuration
17936 (build-accounts 5)
17937 (use-substitutes? #f)))
17938 @end example
17939
17940 The second argument to the @code{service} form is a value representing
17941 the parameters of this specific service instance.
17942 @xref{guix-configuration-type, @code{guix-configuration}}, for
17943 information about the @code{guix-configuration} data type. When the
17944 value is omitted, the default value specified by
17945 @code{guix-service-type} is used:
17946
17947 @example
17948 (service guix-service-type)
17949 @end example
17950
17951 @var{guix-service-type} is quite simple because it extends other
17952 services but is not extensible itself.
17953
17954 @c @subsubsubsection Extensible Service Types
17955
17956 The service type for an @emph{extensible} service looks like this:
17957
17958 @example
17959 (define udev-service-type
17960 (service-type (name 'udev)
17961 (extensions
17962 (list (service-extension shepherd-root-service-type
17963 udev-shepherd-service)))
17964
17965 (compose concatenate) ;concatenate the list of rules
17966 (extend (lambda (config rules)
17967 (match config
17968 (($ <udev-configuration> udev initial-rules)
17969 (udev-configuration
17970 (udev udev) ;the udev package to use
17971 (rules (append initial-rules rules)))))))))
17972 @end example
17973
17974 This is the service type for the
17975 @uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
17976 management daemon}. Compared to the previous example, in addition to an
17977 extension of @var{shepherd-root-service-type}, we see two new fields:
17978
17979 @table @code
17980 @item compose
17981 This is the procedure to @dfn{compose} the list of extensions to
17982 services of this type.
17983
17984 Services can extend the udev service by passing it lists of rules; we
17985 compose those extensions simply by concatenating them.
17986
17987 @item extend
17988 This procedure defines how the value of the service is @dfn{extended} with
17989 the composition of the extensions.
17990
17991 Udev extensions are composed into a list of rules, but the udev service
17992 value is itself a @code{<udev-configuration>} record. So here, we
17993 extend that record by appending the list of rules it contains to the
17994 list of contributed rules.
17995 @end table
17996
17997 There can be only one instance of an extensible service type such as
17998 @var{udev-service-type}. If there were more, the
17999 @code{service-extension} specifications would be ambiguous.
18000
18001 Still here? The next section provides a reference of the programming
18002 interface for services.
18003
18004 @node Service Reference
18005 @subsubsection Service Reference
18006
18007 We have seen an overview of service types (@pxref{Service Types and
18008 Services}). This section provides a reference on how to manipulate
18009 services and service types. This interface is provided by the
18010 @code{(gnu services)} module.
18011
18012 @deffn {Scheme Procedure} service @var{type} [@var{value}]
18013 Return a new service of @var{type}, a @code{<service-type>} object (see
18014 below.) @var{value} can be any object; it represents the parameters of
18015 this particular service instance.
18016
18017 When @var{value} is omitted, the default value specified by @var{type}
18018 is used; if @var{type} does not specify a default value, an error is
18019 raised.
18020
18021 For instance, this:
18022
18023 @example
18024 (service openssh-service-type)
18025 @end example
18026
18027 @noindent
18028 is equivalent to this:
18029
18030 @example
18031 (service openssh-service-type
18032 (openssh-configuration))
18033 @end example
18034
18035 In both cases the result is an instance of @code{openssh-service-type}
18036 with the default configuration.
18037 @end deffn
18038
18039 @deffn {Scheme Procedure} service? @var{obj}
18040 Return true if @var{obj} is a service.
18041 @end deffn
18042
18043 @deffn {Scheme Procedure} service-kind @var{service}
18044 Return the type of @var{service}---i.e., a @code{<service-type>} object.
18045 @end deffn
18046
18047 @deffn {Scheme Procedure} service-value @var{service}
18048 Return the value associated with @var{service}. It represents its
18049 parameters.
18050 @end deffn
18051
18052 Here is an example of how a service is created and manipulated:
18053
18054 @example
18055 (define s
18056 (service nginx-service-type
18057 (nginx-configuration
18058 (nginx nginx)
18059 (log-directory log-directory)
18060 (run-directory run-directory)
18061 (file config-file))))
18062
18063 (service? s)
18064 @result{} #t
18065
18066 (eq? (service-kind s) nginx-service-type)
18067 @result{} #t
18068 @end example
18069
18070 The @code{modify-services} form provides a handy way to change the
18071 parameters of some of the services of a list such as
18072 @var{%base-services} (@pxref{Base Services, @code{%base-services}}). It
18073 evaluates to a list of services. Of course, you could always use
18074 standard list combinators such as @code{map} and @code{fold} to do that
18075 (@pxref{SRFI-1, List Library,, guile, GNU Guile Reference Manual});
18076 @code{modify-services} simply provides a more concise form for this
18077 common pattern.
18078
18079 @deffn {Scheme Syntax} modify-services @var{services} @
18080 (@var{type} @var{variable} => @var{body}) @dots{}
18081
18082 Modify the services listed in @var{services} according to the given
18083 clauses. Each clause has the form:
18084
18085 @example
18086 (@var{type} @var{variable} => @var{body})
18087 @end example
18088
18089 where @var{type} is a service type---e.g.,
18090 @code{guix-service-type}---and @var{variable} is an identifier that is
18091 bound within the @var{body} to the service parameters---e.g., a
18092 @code{guix-configuration} instance---of the original service of that
18093 @var{type}.
18094
18095 The @var{body} should evaluate to the new service parameters, which will
18096 be used to configure the new service. This new service will replace the
18097 original in the resulting list. Because a service's service parameters
18098 are created using @code{define-record-type*}, you can write a succinct
18099 @var{body} that evaluates to the new service parameters by using the
18100 @code{inherit} feature that @code{define-record-type*} provides.
18101
18102 @xref{Using the Configuration System}, for example usage.
18103
18104 @end deffn
18105
18106 Next comes the programming interface for service types. This is
18107 something you want to know when writing new service definitions, but not
18108 necessarily when simply looking for ways to customize your
18109 @code{operating-system} declaration.
18110
18111 @deftp {Data Type} service-type
18112 @cindex service type
18113 This is the representation of a @dfn{service type} (@pxref{Service Types
18114 and Services}).
18115
18116 @table @asis
18117 @item @code{name}
18118 This is a symbol, used only to simplify inspection and debugging.
18119
18120 @item @code{extensions}
18121 A non-empty list of @code{<service-extension>} objects (see below).
18122
18123 @item @code{compose} (default: @code{#f})
18124 If this is @code{#f}, then the service type denotes services that cannot
18125 be extended---i.e., services that do not receive ``values'' from other
18126 services.
18127
18128 Otherwise, it must be a one-argument procedure. The procedure is called
18129 by @code{fold-services} and is passed a list of values collected from
18130 extensions. It must return a value that is a valid parameter value for
18131 the service instance.
18132
18133 @item @code{extend} (default: @code{#f})
18134 If this is @code{#f}, services of this type cannot be extended.
18135
18136 Otherwise, it must be a two-argument procedure: @code{fold-services}
18137 calls it, passing it the initial value of the service as the first argument
18138 and the result of applying @code{compose} to the extension values as the
18139 second argument.
18140 @end table
18141
18142 @xref{Service Types and Services}, for examples.
18143 @end deftp
18144
18145 @deffn {Scheme Procedure} service-extension @var{target-type} @
18146 @var{compute}
18147 Return a new extension for services of type @var{target-type}.
18148 @var{compute} must be a one-argument procedure: @code{fold-services}
18149 calls it, passing it the value associated with the service that provides
18150 the extension; it must return a valid value for the target service.
18151 @end deffn
18152
18153 @deffn {Scheme Procedure} service-extension? @var{obj}
18154 Return true if @var{obj} is a service extension.
18155 @end deffn
18156
18157 Occasionally, you might want to simply extend an existing service. This
18158 involves creating a new service type and specifying the extension of
18159 interest, which can be verbose; the @code{simple-service} procedure
18160 provides a shorthand for this.
18161
18162 @deffn {Scheme Procedure} simple-service @var{name} @var{target} @var{value}
18163 Return a service that extends @var{target} with @var{value}. This works
18164 by creating a singleton service type @var{name}, of which the returned
18165 service is an instance.
18166
18167 For example, this extends mcron (@pxref{Scheduled Job Execution}) with
18168 an additional job:
18169
18170 @example
18171 (simple-service 'my-mcron-job mcron-service-type
18172 #~(job '(next-hour (3)) "guix gc -F 2G"))
18173 @end example
18174 @end deffn
18175
18176 At the core of the service abstraction lies the @code{fold-services}
18177 procedure, which is responsible for ``compiling'' a list of services
18178 down to a single directory that contains everything needed to boot and
18179 run the system---the directory shown by the @command{guix system build}
18180 command (@pxref{Invoking guix system}). In essence, it propagates
18181 service extensions down the service graph, updating each node parameters
18182 on the way, until it reaches the root node.
18183
18184 @deffn {Scheme Procedure} fold-services @var{services} @
18185 [#:target-type @var{system-service-type}]
18186 Fold @var{services} by propagating their extensions down to the root of
18187 type @var{target-type}; return the root service adjusted accordingly.
18188 @end deffn
18189
18190 Lastly, the @code{(gnu services)} module also defines several essential
18191 service types, some of which are listed below.
18192
18193 @defvr {Scheme Variable} system-service-type
18194 This is the root of the service graph. It produces the system directory
18195 as returned by the @command{guix system build} command.
18196 @end defvr
18197
18198 @defvr {Scheme Variable} boot-service-type
18199 The type of the ``boot service'', which produces the @dfn{boot script}.
18200 The boot script is what the initial RAM disk runs when booting.
18201 @end defvr
18202
18203 @defvr {Scheme Variable} etc-service-type
18204 The type of the @file{/etc} service. This service can be extended by
18205 passing it name/file tuples such as:
18206
18207 @example
18208 (list `("issue" ,(plain-file "issue" "Welcome!\n")))
18209 @end example
18210
18211 In this example, the effect would be to add an @file{/etc/issue} file
18212 pointing to the given file.
18213 @end defvr
18214
18215 @defvr {Scheme Variable} setuid-program-service-type
18216 Type for the ``setuid-program service''. This service collects lists of
18217 executable file names, passed as gexps, and adds them to the set of
18218 setuid-root programs on the system (@pxref{Setuid Programs}).
18219 @end defvr
18220
18221 @defvr {Scheme Variable} profile-service-type
18222 Type of the service that populates the @dfn{system profile}---i.e., the
18223 programs under @file{/run/current-system/profile}. Other services can
18224 extend it by passing it lists of packages to add to the system profile.
18225 @end defvr
18226
18227
18228 @node Shepherd Services
18229 @subsubsection Shepherd Services
18230
18231 @cindex shepherd services
18232 @cindex PID 1
18233 @cindex init system
18234 The @code{(gnu services shepherd)} module provides a way to define
18235 services managed by the GNU@tie{}Shepherd, which is the GuixSD
18236 initialization system---the first process that is started when the
18237 system boots, also known as PID@tie{}1
18238 (@pxref{Introduction,,, shepherd, The GNU Shepherd Manual}).
18239
18240 Services in the Shepherd can depend on each other. For instance, the
18241 SSH daemon may need to be started after the syslog daemon has been
18242 started, which in turn can only happen once all the file systems have
18243 been mounted. The simple operating system defined earlier (@pxref{Using
18244 the Configuration System}) results in a service graph like this:
18245
18246 @image{images/shepherd-graph,,5in,Typical shepherd service graph.}
18247
18248 You can actually generate such a graph for any operating system
18249 definition using the @command{guix system shepherd-graph} command
18250 (@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
18251
18252 The @var{%shepherd-root-service} is a service object representing
18253 PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
18254 by passing it lists of @code{<shepherd-service>} objects.
18255
18256 @deftp {Data Type} shepherd-service
18257 The data type representing a service managed by the Shepherd.
18258
18259 @table @asis
18260 @item @code{provision}
18261 This is a list of symbols denoting what the service provides.
18262
18263 These are the names that may be passed to @command{herd start},
18264 @command{herd status}, and similar commands (@pxref{Invoking herd,,,
18265 shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
18266 @code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
18267
18268 @item @code{requirements} (default: @code{'()})
18269 List of symbols denoting the Shepherd services this one depends on.
18270
18271 @item @code{respawn?} (default: @code{#t})
18272 Whether to restart the service when it stops, for instance when the
18273 underlying process dies.
18274
18275 @item @code{start}
18276 @itemx @code{stop} (default: @code{#~(const #f)})
18277 The @code{start} and @code{stop} fields refer to the Shepherd's
18278 facilities to start and stop processes (@pxref{Service De- and
18279 Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
18280 G-expressions that get expanded in the Shepherd configuration file
18281 (@pxref{G-Expressions}).
18282
18283 @item @code{documentation}
18284 A documentation string, as shown when running:
18285
18286 @example
18287 herd doc @var{service-name}
18288 @end example
18289
18290 where @var{service-name} is one of the symbols in @var{provision}
18291 (@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
18292
18293 @item @code{modules} (default: @var{%default-modules})
18294 This is the list of modules that must be in scope when @code{start} and
18295 @code{stop} are evaluated.
18296
18297 @end table
18298 @end deftp
18299
18300 @defvr {Scheme Variable} shepherd-root-service-type
18301 The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
18302
18303 This is the service type that extensions target when they want to create
18304 shepherd services (@pxref{Service Types and Services}, for an example).
18305 Each extension must pass a list of @code{<shepherd-service>}.
18306 @end defvr
18307
18308 @defvr {Scheme Variable} %shepherd-root-service
18309 This service represents PID@tie{}1.
18310 @end defvr
18311
18312
18313 @node Documentation
18314 @section Documentation
18315
18316 @cindex documentation, searching for
18317 @cindex searching for documentation
18318 @cindex Info, documentation format
18319 @cindex man pages
18320 @cindex manual pages
18321 In most cases packages installed with Guix come with documentation.
18322 There are two main documentation formats: ``Info'', a browseable
18323 hypertext format used for GNU software, and ``manual pages'' (or ``man
18324 pages''), the linear documentation format traditionally found on Unix.
18325 Info manuals are accessed with the @command{info} command or with Emacs,
18326 and man pages are accessed using @command{man}.
18327
18328 You can look for documentation of software installed on your system by
18329 keyword. For example, the following command searches for information
18330 about ``TLS'' in Info manuals:
18331
18332 @example
18333 $ info -k TLS
18334 "(emacs)Network Security" -- STARTTLS
18335 "(emacs)Network Security" -- TLS
18336 "(gnutls)Core TLS API" -- gnutls_certificate_set_verify_flags
18337 "(gnutls)Core TLS API" -- gnutls_certificate_set_verify_function
18338 @dots{}
18339 @end example
18340
18341 @noindent
18342 The command below searches for the same keyword in man pages:
18343
18344 @example
18345 $ man -k TLS
18346 SSL (7) - OpenSSL SSL/TLS library
18347 certtool (1) - GnuTLS certificate tool
18348 @dots {}
18349 @end example
18350
18351 These searches are purely local to your computer so you have the
18352 guarantee that documentation you find corresponds to what you have
18353 actually installed, you can access it off-line, and your privacy is
18354 respected.
18355
18356 Once you have these results, you can view the relevant documentation by
18357 running, say:
18358
18359 @example
18360 $ info "(gnutls)Core TLS API"
18361 @end example
18362
18363 @noindent
18364 or:
18365
18366 @example
18367 $ man certtool
18368 @end example
18369
18370 Info manuals contain sections and indices as well as hyperlinks like
18371 those found in Web pages. The @command{info} reader (@pxref{Top, Info
18372 reader,, info-stnd, Stand-alone GNU Info}) and its Emacs counterpart
18373 (@pxref{Misc Help,,, emacs, The GNU Emacs Manual}) provide intuitive key
18374 bindings to navigate manuals. @xref{Getting Started,,, info, Info: An
18375 Introduction}, for an introduction to Info navigation.
18376
18377 @node Installing Debugging Files
18378 @section Installing Debugging Files
18379
18380 @cindex debugging files
18381 Program binaries, as produced by the GCC compilers for instance, are
18382 typically written in the ELF format, with a section containing
18383 @dfn{debugging information}. Debugging information is what allows the
18384 debugger, GDB, to map binary code to source code; it is required to
18385 debug a compiled program in good conditions.
18386
18387 The problem with debugging information is that is takes up a fair amount
18388 of disk space. For example, debugging information for the GNU C Library
18389 weighs in at more than 60 MiB. Thus, as a user, keeping all the
18390 debugging info of all the installed programs is usually not an option.
18391 Yet, space savings should not come at the cost of an impediment to
18392 debugging---especially in the GNU system, which should make it easier
18393 for users to exert their computing freedom (@pxref{GNU Distribution}).
18394
18395 Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
18396 mechanism that allows users to get the best of both worlds: debugging
18397 information can be stripped from the binaries and stored in separate
18398 files. GDB is then able to load debugging information from those files,
18399 when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
18400 with GDB}).
18401
18402 The GNU distribution takes advantage of this by storing debugging
18403 information in the @code{lib/debug} sub-directory of a separate package
18404 output unimaginatively called @code{debug} (@pxref{Packages with
18405 Multiple Outputs}). Users can choose to install the @code{debug} output
18406 of a package when they need it. For instance, the following command
18407 installs the debugging information for the GNU C Library and for GNU
18408 Guile:
18409
18410 @example
18411 guix package -i glibc:debug guile:debug
18412 @end example
18413
18414 GDB must then be told to look for debug files in the user's profile, by
18415 setting the @code{debug-file-directory} variable (consider setting it
18416 from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
18417 GDB}):
18418
18419 @example
18420 (gdb) set debug-file-directory ~/.guix-profile/lib/debug
18421 @end example
18422
18423 From there on, GDB will pick up debugging information from the
18424 @code{.debug} files under @file{~/.guix-profile/lib/debug}.
18425
18426 In addition, you will most likely want GDB to be able to show the source
18427 code being debugged. To do that, you will have to unpack the source
18428 code of the package of interest (obtained with @code{guix build
18429 --source}, @pxref{Invoking guix build}), and to point GDB to that source
18430 directory using the @code{directory} command (@pxref{Source Path,
18431 @code{directory},, gdb, Debugging with GDB}).
18432
18433 @c XXX: keep me up-to-date
18434 The @code{debug} output mechanism in Guix is implemented by the
18435 @code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
18436 opt-in---debugging information is available only for the packages
18437 with definitions explicitly declaring a @code{debug} output. This may be
18438 changed to opt-out in the future if our build farm servers can handle
18439 the load. To check whether a package has a @code{debug} output, use
18440 @command{guix package --list-available} (@pxref{Invoking guix package}).
18441
18442
18443 @node Security Updates
18444 @section Security Updates
18445
18446 @cindex security updates
18447 @cindex security vulnerabilities
18448 Occasionally, important security vulnerabilities are discovered in software
18449 packages and must be patched. Guix developers try hard to keep track of
18450 known vulnerabilities and to apply fixes as soon as possible in the
18451 @code{master} branch of Guix (we do not yet provide a ``stable'' branch
18452 containing only security updates.) The @command{guix lint} tool helps
18453 developers find out about vulnerable versions of software packages in the
18454 distribution:
18455
18456 @smallexample
18457 $ guix lint -c cve
18458 gnu/packages/base.scm:652:2: glibc@@2.21: probably vulnerable to CVE-2015-1781, CVE-2015-7547
18459 gnu/packages/gcc.scm:334:2: gcc@@4.9.3: probably vulnerable to CVE-2015-5276
18460 gnu/packages/image.scm:312:2: openjpeg@@2.1.0: probably vulnerable to CVE-2016-1923, CVE-2016-1924
18461 @dots{}
18462 @end smallexample
18463
18464 @xref{Invoking guix lint}, for more information.
18465
18466 @quotation Note
18467 As of version @value{VERSION}, the feature described below is considered
18468 ``beta''.
18469 @end quotation
18470
18471 Guix follows a functional
18472 package management discipline (@pxref{Introduction}), which implies
18473 that, when a package is changed, @emph{every package that depends on it}
18474 must be rebuilt. This can significantly slow down the deployment of
18475 fixes in core packages such as libc or Bash, since basically the whole
18476 distribution would need to be rebuilt. Using pre-built binaries helps
18477 (@pxref{Substitutes}), but deployment may still take more time than
18478 desired.
18479
18480 @cindex grafts
18481 To address this, Guix implements @dfn{grafts}, a mechanism that allows
18482 for fast deployment of critical updates without the costs associated
18483 with a whole-distribution rebuild. The idea is to rebuild only the
18484 package that needs to be patched, and then to ``graft'' it onto packages
18485 explicitly installed by the user and that were previously referring to
18486 the original package. The cost of grafting is typically very low, and
18487 order of magnitudes lower than a full rebuild of the dependency chain.
18488
18489 @cindex replacements of packages, for grafts
18490 For instance, suppose a security update needs to be applied to Bash.
18491 Guix developers will provide a package definition for the ``fixed''
18492 Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
18493 Packages}). Then, the original package definition is augmented with a
18494 @code{replacement} field pointing to the package containing the bug fix:
18495
18496 @example
18497 (define bash
18498 (package
18499 (name "bash")
18500 ;; @dots{}
18501 (replacement bash-fixed)))
18502 @end example
18503
18504 From there on, any package depending directly or indirectly on Bash---as
18505 reported by @command{guix gc --requisites} (@pxref{Invoking guix
18506 gc})---that is installed is automatically ``rewritten'' to refer to
18507 @var{bash-fixed} instead of @var{bash}. This grafting process takes
18508 time proportional to the size of the package, usually less than a
18509 minute for an ``average'' package on a recent machine. Grafting is
18510 recursive: when an indirect dependency requires grafting, then grafting
18511 ``propagates'' up to the package that the user is installing.
18512
18513 Currently, the length of the name and version of the graft and that of
18514 the package it replaces (@var{bash-fixed} and @var{bash} in the example
18515 above) must be equal. This restriction mostly comes from the fact that
18516 grafting works by patching files, including binary files, directly.
18517 Other restrictions may apply: for instance, when adding a graft to a
18518 package providing a shared library, the original shared library and its
18519 replacement must have the same @code{SONAME} and be binary-compatible.
18520
18521 The @option{--no-grafts} command-line option allows you to forcefully
18522 avoid grafting (@pxref{Common Build Options, @option{--no-grafts}}).
18523 Thus, the command:
18524
18525 @example
18526 guix build bash --no-grafts
18527 @end example
18528
18529 @noindent
18530 returns the store file name of the original Bash, whereas:
18531
18532 @example
18533 guix build bash
18534 @end example
18535
18536 @noindent
18537 returns the store file name of the ``fixed'', replacement Bash. This
18538 allows you to distinguish between the two variants of Bash.
18539
18540 To verify which Bash your whole profile refers to, you can run
18541 (@pxref{Invoking guix gc}):
18542
18543 @example
18544 guix gc -R `readlink -f ~/.guix-profile` | grep bash
18545 @end example
18546
18547 @noindent
18548 @dots{} and compare the store file names that you get with those above.
18549 Likewise for a complete GuixSD system generation:
18550
18551 @example
18552 guix gc -R `guix system build my-config.scm` | grep bash
18553 @end example
18554
18555 Lastly, to check which Bash running processes are using, you can use the
18556 @command{lsof} command:
18557
18558 @example
18559 lsof | grep /gnu/store/.*bash
18560 @end example
18561
18562
18563 @node Package Modules
18564 @section Package Modules
18565
18566 From a programming viewpoint, the package definitions of the
18567 GNU distribution are provided by Guile modules in the @code{(gnu packages
18568 @dots{})} name space@footnote{Note that packages under the @code{(gnu
18569 packages @dots{})} module name space are not necessarily ``GNU
18570 packages''. This module naming scheme follows the usual Guile module
18571 naming convention: @code{gnu} means that these modules are distributed
18572 as part of the GNU system, and @code{packages} identifies modules that
18573 define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
18574 Reference Manual}). For instance, the @code{(gnu packages emacs)}
18575 module exports a variable named @code{emacs}, which is bound to a
18576 @code{<package>} object (@pxref{Defining Packages}).
18577
18578 The @code{(gnu packages @dots{})} module name space is
18579 automatically scanned for packages by the command-line tools. For
18580 instance, when running @code{guix package -i emacs}, all the @code{(gnu
18581 packages @dots{})} modules are scanned until one that exports a package
18582 object whose name is @code{emacs} is found. This package search
18583 facility is implemented in the @code{(gnu packages)} module.
18584
18585 @cindex customization, of packages
18586 @cindex package module search path
18587 Users can store package definitions in modules with different
18588 names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
18589 name and module name must match. For instance, the @code{(my-packages
18590 emacs)} module must be stored in a @file{my-packages/emacs.scm} file
18591 relative to the load path specified with @option{--load-path} or
18592 @code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
18593 guile, GNU Guile Reference Manual}, for details.}. These package definitions
18594 will not be visible by default. Users can invoke commands such as
18595 @command{guix package} and @command{guix build} with the
18596 @code{-e} option so that they know where to find the package. Better
18597 yet, they can use the
18598 @code{-L} option of these commands to make those modules visible
18599 (@pxref{Invoking guix build, @code{--load-path}}), or define the
18600 @code{GUIX_PACKAGE_PATH} environment variable. This environment
18601 variable makes it easy to extend or customize the distribution and is
18602 honored by all the user interfaces.
18603
18604 @defvr {Environment Variable} GUIX_PACKAGE_PATH
18605 This is a colon-separated list of directories to search for additional
18606 package modules. Directories listed in this variable take precedence
18607 over the own modules of the distribution.
18608 @end defvr
18609
18610 The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
18611 each package is built based solely on other packages in the
18612 distribution. The root of this dependency graph is a small set of
18613 @dfn{bootstrap binaries}, provided by the @code{(gnu packages
18614 bootstrap)} module. For more information on bootstrapping,
18615 @pxref{Bootstrapping}.
18616
18617 @node Packaging Guidelines
18618 @section Packaging Guidelines
18619
18620 @cindex packages, creating
18621 The GNU distribution is nascent and may well lack some of your favorite
18622 packages. This section describes how you can help make the distribution
18623 grow. @xref{Contributing}, for additional information on how you can
18624 help.
18625
18626 Free software packages are usually distributed in the form of
18627 @dfn{source code tarballs}---typically @file{tar.gz} files that contain
18628 all the source files. Adding a package to the distribution means
18629 essentially two things: adding a @dfn{recipe} that describes how to
18630 build the package, including a list of other packages required to build
18631 it, and adding @dfn{package metadata} along with that recipe, such as a
18632 description and licensing information.
18633
18634 In Guix all this information is embodied in @dfn{package definitions}.
18635 Package definitions provide a high-level view of the package. They are
18636 written using the syntax of the Scheme programming language; in fact,
18637 for each package we define a variable bound to the package definition,
18638 and export that variable from a module (@pxref{Package Modules}).
18639 However, in-depth Scheme knowledge is @emph{not} a prerequisite for
18640 creating packages. For more information on package definitions,
18641 @pxref{Defining Packages}.
18642
18643 Once a package definition is in place, stored in a file in the Guix
18644 source tree, it can be tested using the @command{guix build} command
18645 (@pxref{Invoking guix build}). For example, assuming the new package is
18646 called @code{gnew}, you may run this command from the Guix build tree
18647 (@pxref{Running Guix Before It Is Installed}):
18648
18649 @example
18650 ./pre-inst-env guix build gnew --keep-failed
18651 @end example
18652
18653 Using @code{--keep-failed} makes it easier to debug build failures since
18654 it provides access to the failed build tree. Another useful
18655 command-line option when debugging is @code{--log-file}, to access the
18656 build log.
18657
18658 If the package is unknown to the @command{guix} command, it may be that
18659 the source file contains a syntax error, or lacks a @code{define-public}
18660 clause to export the package variable. To figure it out, you may load
18661 the module from Guile to get more information about the actual error:
18662
18663 @example
18664 ./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
18665 @end example
18666
18667 Once your package builds correctly, please send us a patch
18668 (@pxref{Contributing}). Well, if you need help, we will be happy to
18669 help you too. Once the patch is committed in the Guix repository, the
18670 new package automatically gets built on the supported platforms by
18671 @url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
18672 system}.
18673
18674 @cindex substituter
18675 Users can obtain the new package definition simply by running
18676 @command{guix pull} (@pxref{Invoking guix pull}). When
18677 @code{hydra.gnu.org} is done building the package, installing the
18678 package automatically downloads binaries from there
18679 (@pxref{Substitutes}). The only place where human intervention is
18680 needed is to review and apply the patch.
18681
18682
18683 @menu
18684 * Software Freedom:: What may go into the distribution.
18685 * Package Naming:: What's in a name?
18686 * Version Numbers:: When the name is not enough.
18687 * Synopses and Descriptions:: Helping users find the right package.
18688 * Python Modules:: A touch of British comedy.
18689 * Perl Modules:: Little pearls.
18690 * Java Packages:: Coffee break.
18691 * Fonts:: Fond of fonts.
18692 @end menu
18693
18694 @node Software Freedom
18695 @subsection Software Freedom
18696
18697 @c Adapted from http://www.gnu.org/philosophy/philosophy.html.
18698 @cindex free software
18699 The GNU operating system has been developed so that users can have
18700 freedom in their computing. GNU is @dfn{free software}, meaning that
18701 users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
18702 essential freedoms}: to run the program, to study and change the program
18703 in source code form, to redistribute exact copies, and to distribute
18704 modified versions. Packages found in the GNU distribution provide only
18705 software that conveys these four freedoms.
18706
18707 In addition, the GNU distribution follow the
18708 @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
18709 software distribution guidelines}. Among other things, these guidelines
18710 reject non-free firmware, recommendations of non-free software, and
18711 discuss ways to deal with trademarks and patents.
18712
18713 Some otherwise free upstream package sources contain a small and optional
18714 subset that violates the above guidelines, for instance because this subset
18715 is itself non-free code. When that happens, the offending items are removed
18716 with appropriate patches or code snippets in the @code{origin} form of the
18717 package (@pxref{Defining Packages}). This way, @code{guix
18718 build --source} returns the ``freed'' source rather than the unmodified
18719 upstream source.
18720
18721
18722 @node Package Naming
18723 @subsection Package Naming
18724
18725 @cindex package name
18726 A package has actually two names associated with it:
18727 First, there is the name of the @emph{Scheme variable}, the one following
18728 @code{define-public}. By this name, the package can be made known in the
18729 Scheme code, for instance as input to another package. Second, there is
18730 the string in the @code{name} field of a package definition. This name
18731 is used by package management commands such as
18732 @command{guix package} and @command{guix build}.
18733
18734 Both are usually the same and correspond to the lowercase conversion of
18735 the project name chosen upstream, with underscores replaced with
18736 hyphens. For instance, GNUnet is available as @code{gnunet}, and
18737 SDL_net as @code{sdl-net}.
18738
18739 We do not add @code{lib} prefixes for library packages, unless these are
18740 already part of the official project name. But @pxref{Python
18741 Modules} and @ref{Perl Modules} for special rules concerning modules for
18742 the Python and Perl languages.
18743
18744 Font package names are handled differently, @pxref{Fonts}.
18745
18746
18747 @node Version Numbers
18748 @subsection Version Numbers
18749
18750 @cindex package version
18751 We usually package only the latest version of a given free software
18752 project. But sometimes, for instance for incompatible library versions,
18753 two (or more) versions of the same package are needed. These require
18754 different Scheme variable names. We use the name as defined
18755 in @ref{Package Naming}
18756 for the most recent version; previous versions use the same name, suffixed
18757 by @code{-} and the smallest prefix of the version number that may
18758 distinguish the two versions.
18759
18760 The name inside the package definition is the same for all versions of a
18761 package and does not contain any version number.
18762
18763 For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
18764
18765 @example
18766 (define-public gtk+
18767 (package
18768 (name "gtk+")
18769 (version "3.9.12")
18770 ...))
18771 (define-public gtk+-2
18772 (package
18773 (name "gtk+")
18774 (version "2.24.20")
18775 ...))
18776 @end example
18777 If we also wanted GTK+ 3.8.2, this would be packaged as
18778 @example
18779 (define-public gtk+-3.8
18780 (package
18781 (name "gtk+")
18782 (version "3.8.2")
18783 ...))
18784 @end example
18785
18786 @c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
18787 @c for a discussion of what follows.
18788 @cindex version number, for VCS snapshots
18789 Occasionally, we package snapshots of upstream's version control system
18790 (VCS) instead of formal releases. This should remain exceptional,
18791 because it is up to upstream developers to clarify what the stable
18792 release is. Yet, it is sometimes necessary. So, what should we put in
18793 the @code{version} field?
18794
18795 Clearly, we need to make the commit identifier of the VCS snapshot
18796 visible in the version string, but we also need to make sure that the
18797 version string is monotonically increasing so that @command{guix package
18798 --upgrade} can determine which version is newer. Since commit
18799 identifiers, notably with Git, are not monotonically increasing, we add
18800 a revision number that we increase each time we upgrade to a newer
18801 snapshot. The resulting version string looks like this:
18802
18803 @example
18804 2.0.11-3.cabba9e
18805 ^ ^ ^
18806 | | `-- upstream commit ID
18807 | |
18808 | `--- Guix package revision
18809 |
18810 latest upstream version
18811 @end example
18812
18813 It is a good idea to strip commit identifiers in the @code{version}
18814 field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
18815 aesthetics have a role to play here) as well as problems related to OS
18816 limits such as the maximum shebang length (127 bytes for the Linux
18817 kernel.) It is best to use the full commit identifiers in
18818 @code{origin}s, though, to avoid ambiguities. A typical package
18819 definition may look like this:
18820
18821 @example
18822 (define my-package
18823 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7")
18824 (revision "1")) ;Guix package revision
18825 (package
18826 (version (string-append "0.9-" revision "."
18827 (string-take commit 7)))
18828 (source (origin
18829 (method git-fetch)
18830 (uri (git-reference
18831 (url "git://example.org/my-package.git")
18832 (commit commit)))
18833 (sha256 (base32 "1mbikn@dots{}"))
18834 (file-name (string-append "my-package-" version
18835 "-checkout"))))
18836 ;; @dots{}
18837 )))
18838 @end example
18839
18840 @node Synopses and Descriptions
18841 @subsection Synopses and Descriptions
18842
18843 @cindex package description
18844 @cindex package synopsis
18845 As we have seen before, each package in GNU@tie{}Guix includes a
18846 synopsis and a description (@pxref{Defining Packages}). Synopses and
18847 descriptions are important: They are what @command{guix package
18848 --search} searches, and a crucial piece of information to help users
18849 determine whether a given package suits their needs. Consequently,
18850 packagers should pay attention to what goes into them.
18851
18852 Synopses must start with a capital letter and must not end with a
18853 period. They must not start with ``a'' or ``the'', which usually does
18854 not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
18855 tool that frobs files''. The synopsis should say what the package
18856 is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
18857 used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
18858 matching a pattern''.
18859
18860 Keep in mind that the synopsis must be meaningful for a very wide
18861 audience. For example, ``Manipulate alignments in the SAM format''
18862 might make sense for a seasoned bioinformatics researcher, but might be
18863 fairly unhelpful or even misleading to a non-specialized audience. It
18864 is a good idea to come up with a synopsis that gives an idea of the
18865 application domain of the package. In this example, this might give
18866 something like ``Manipulate nucleotide sequence alignments'', which
18867 hopefully gives the user a better idea of whether this is what they are
18868 looking for.
18869
18870 Descriptions should take between five and ten lines. Use full
18871 sentences, and avoid using acronyms without first introducing them.
18872 Please avoid marketing phrases such as ``world-leading'',
18873 ``industrial-strength'', and ``next-generation'', and avoid superlatives
18874 like ``the most advanced''---they are not helpful to users looking for a
18875 package and may even sound suspicious. Instead, try to be factual,
18876 mentioning use cases and features.
18877
18878 @cindex Texinfo markup, in package descriptions
18879 Descriptions can include Texinfo markup, which is useful to introduce
18880 ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
18881 hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
18882 should be careful when using some characters for example @samp{@@} and
18883 curly braces which are the basic special characters in Texinfo
18884 (@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
18885 such as @command{guix package --show} take care of rendering it
18886 appropriately.
18887
18888 Synopses and descriptions are translated by volunteers
18889 @uref{http://translationproject.org/domain/guix-packages.html, at the
18890 Translation Project} so that as many users as possible can read them in
18891 their native language. User interfaces search them and display them in
18892 the language specified by the current locale.
18893
18894 Translation is a lot of work so, as a packager, please pay even more
18895 attention to your synopses and descriptions as every change may entail
18896 additional work for translators. In order to help them, it is possible
18897 to make recommendations or instructions visible to them by inserting
18898 special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
18899 Gettext}):
18900
18901 @example
18902 ;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
18903 (description "ARandR is designed to provide a simple visual front end
18904 for the X11 resize-and-rotate (RandR) extension. @dots{}")
18905 @end example
18906
18907
18908 @node Python Modules
18909 @subsection Python Modules
18910
18911 @cindex python
18912 We currently package Python 2 and Python 3, under the Scheme variable names
18913 @code{python-2} and @code{python} as explained in @ref{Version Numbers}.
18914 To avoid confusion and naming clashes with other programming languages, it
18915 seems desirable that the name of a package for a Python module contains
18916 the word @code{python}.
18917
18918 Some modules are compatible with only one version of Python, others with both.
18919 If the package Foo compiles only with Python 3, we name it
18920 @code{python-foo}; if it compiles only with Python 2, we name it
18921 @code{python2-foo}. If it is compatible with both versions, we create two
18922 packages with the corresponding names.
18923
18924 If a project already contains the word @code{python}, we drop this;
18925 for instance, the module python-dateutil is packaged under the names
18926 @code{python-dateutil} and @code{python2-dateutil}. If the project name
18927 starts with @code{py} (e.g. @code{pytz}), we keep it and prefix it as
18928 described above.
18929
18930 @subsubsection Specifying Dependencies
18931 @cindex inputs, for Python packages
18932
18933 Dependency information for Python packages is usually available in the
18934 package source tree, with varying degrees of accuracy: in the
18935 @file{setup.py} file, in @file{requirements.txt}, or in @file{tox.ini}.
18936
18937 Your mission, when writing a recipe for a Python package, is to map
18938 these dependencies to the appropriate type of ``input'' (@pxref{package
18939 Reference, inputs}). Although the @code{pypi} importer normally does a
18940 good job (@pxref{Invoking guix import}), you may want to check the
18941 following check list to determine which dependency goes where.
18942
18943 @itemize
18944
18945 @item
18946 We currently package Python 2 with @code{setuptools} and @code{pip}
18947 installed like Python 3.4 has per default. Thus you don't need to
18948 specify either of these as an input. @command{guix lint} will warn you
18949 if you do.
18950
18951 @item
18952 Python dependencies required at run time go into
18953 @code{propagated-inputs}. They are typically defined with the
18954 @code{install_requires} keyword in @file{setup.py}, or in the
18955 @file{requirements.txt} file.
18956
18957 @item
18958 Python packages required only at build time---e.g., those listed with
18959 the @code{setup_requires} keyword in @file{setup.py}---or only for
18960 testing---e.g., those in @code{tests_require}---go into
18961 @code{native-inputs}. The rationale is that (1) they do not need to be
18962 propagated because they are not needed at run time, and (2) in a
18963 cross-compilation context, it's the ``native'' input that we'd want.
18964
18965 Examples are the @code{pytest}, @code{mock}, and @code{nose} test
18966 frameworks. Of course if any of these packages is also required at
18967 run-time, it needs to go to @code{propagated-inputs}.
18968
18969 @item
18970 Anything that does not fall in the previous categories goes to
18971 @code{inputs}, for example programs or C libraries required for building
18972 Python packages containing C extensions.
18973
18974 @item
18975 If a Python package has optional dependencies (@code{extras_require}),
18976 it is up to you to decide whether to add them or not, based on their
18977 usefulness/overhead ratio (@pxref{Submitting Patches, @command{guix
18978 size}}).
18979
18980 @end itemize
18981
18982
18983 @node Perl Modules
18984 @subsection Perl Modules
18985
18986 @cindex perl
18987 Perl programs standing for themselves are named as any other package,
18988 using the lowercase upstream name.
18989 For Perl packages containing a single class, we use the lowercase class name,
18990 replace all occurrences of @code{::} by dashes and prepend the prefix
18991 @code{perl-}.
18992 So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
18993 Modules containing several classes keep their lowercase upstream name and
18994 are also prepended by @code{perl-}. Such modules tend to have the word
18995 @code{perl} somewhere in their name, which gets dropped in favor of the
18996 prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
18997
18998
18999 @node Java Packages
19000 @subsection Java Packages
19001
19002 @cindex java
19003 Java programs standing for themselves are named as any other package,
19004 using the lowercase upstream name.
19005
19006 To avoid confusion and naming clashes with other programming languages,
19007 it is desirable that the name of a package for a Java package is
19008 prefixed with @code{java-}. If a project already contains the word
19009 @code{java}, we drop this; for instance, the package @code{ngsjava} is
19010 packaged under the name @code{java-ngs}.
19011
19012 For Java packages containing a single class or a small class hierarchy,
19013 we use the lowercase class name, replace all occurrences of @code{.} by
19014 dashes and prepend the prefix @code{java-}. So the class
19015 @code{apache.commons.cli} becomes package
19016 @code{java-apache-commons-cli}.
19017
19018
19019 @node Fonts
19020 @subsection Fonts
19021
19022 @cindex fonts
19023 For fonts that are in general not installed by a user for typesetting
19024 purposes, or that are distributed as part of a larger software package,
19025 we rely on the general packaging rules for software; for instance, this
19026 applies to the fonts delivered as part of the X.Org system or fonts that
19027 are part of TeX Live.
19028
19029 To make it easier for a user to search for fonts, names for other packages
19030 containing only fonts are constructed as follows, independently of the
19031 upstream package name.
19032
19033 The name of a package containing only one font family starts with
19034 @code{font-}; it is followed by the foundry name and a dash @code{-}
19035 if the foundry is known, and the font family name, in which spaces are
19036 replaced by dashes (and as usual, all upper case letters are transformed
19037 to lower case).
19038 For example, the Gentium font family by SIL is packaged under the name
19039 @code{font-sil-gentium}.
19040
19041 For a package containing several font families, the name of the collection
19042 is used in the place of the font family name.
19043 For instance, the Liberation fonts consist of three families,
19044 Liberation Sans, Liberation Serif and Liberation Mono.
19045 These could be packaged separately under the names
19046 @code{font-liberation-sans} and so on; but as they are distributed together
19047 under a common name, we prefer to package them together as
19048 @code{font-liberation}.
19049
19050 In the case where several formats of the same font family or font collection
19051 are packaged separately, a short form of the format, prepended by a dash,
19052 is added to the package name. We use @code{-ttf} for TrueType fonts,
19053 @code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
19054 fonts.
19055
19056
19057
19058 @node Bootstrapping
19059 @section Bootstrapping
19060
19061 @c Adapted from the ELS 2013 paper.
19062
19063 @cindex bootstrapping
19064
19065 Bootstrapping in our context refers to how the distribution gets built
19066 ``from nothing''. Remember that the build environment of a derivation
19067 contains nothing but its declared inputs (@pxref{Introduction}). So
19068 there's an obvious chicken-and-egg problem: how does the first package
19069 get built? How does the first compiler get compiled? Note that this is
19070 a question of interest only to the curious hacker, not to the regular
19071 user, so you can shamelessly skip this section if you consider yourself
19072 a ``regular user''.
19073
19074 @cindex bootstrap binaries
19075 The GNU system is primarily made of C code, with libc at its core. The
19076 GNU build system itself assumes the availability of a Bourne shell and
19077 command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
19078 `grep'. Furthermore, build programs---programs that run
19079 @code{./configure}, @code{make}, etc.---are written in Guile Scheme
19080 (@pxref{Derivations}). Consequently, to be able to build anything at
19081 all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
19082 Binutils, libc, and the other packages mentioned above---the
19083 @dfn{bootstrap binaries}.
19084
19085 These bootstrap binaries are ``taken for granted'', though we can also
19086 re-create them if needed (more on that later).
19087
19088 @unnumberedsubsec Preparing to Use the Bootstrap Binaries
19089
19090 @c As of Emacs 24.3, Info-mode displays the image, but since it's a
19091 @c large image, it's hard to scroll. Oh well.
19092 @image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
19093
19094 The figure above shows the very beginning of the dependency graph of the
19095 distribution, corresponding to the package definitions of the @code{(gnu
19096 packages bootstrap)} module. A similar figure can be generated with
19097 @command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
19098
19099 @example
19100 guix graph -t derivation \
19101 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
19102 | dot -Tps > t.ps
19103 @end example
19104
19105 At this level of detail, things are
19106 slightly complex. First, Guile itself consists of an ELF executable,
19107 along with many source and compiled Scheme files that are dynamically
19108 loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
19109 tarball shown in this graph. This tarball is part of Guix's ``source''
19110 distribution, and gets inserted into the store with @code{add-to-store}
19111 (@pxref{The Store}).
19112
19113 But how do we write a derivation that unpacks this tarball and adds it
19114 to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
19115 derivation---the first one that gets built---uses @code{bash} as its
19116 builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
19117 @code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
19118 @file{xz}, and @file{mkdir} are statically-linked binaries, also part of
19119 the Guix source distribution, whose sole purpose is to allow the Guile
19120 tarball to be unpacked.
19121
19122 Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
19123 Guile that can be used to run subsequent build programs. Its first task
19124 is to download tarballs containing the other pre-built binaries---this
19125 is what the @code{.tar.xz.drv} derivations do. Guix modules such as
19126 @code{ftp-client.scm} are used for this purpose. The
19127 @code{module-import.drv} derivations import those modules in a directory
19128 in the store, using the original layout. The
19129 @code{module-import-compiled.drv} derivations compile those modules, and
19130 write them in an output directory with the right layout. This
19131 corresponds to the @code{#:modules} argument of
19132 @code{build-expression->derivation} (@pxref{Derivations}).
19133
19134 Finally, the various tarballs are unpacked by the
19135 derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
19136 etc., at which point we have a working C tool chain.
19137
19138
19139 @unnumberedsubsec Building the Build Tools
19140
19141 Bootstrapping is complete when we have a full tool chain that does not
19142 depend on the pre-built bootstrap tools discussed above. This
19143 no-dependency requirement is verified by checking whether the files of
19144 the final tool chain contain references to the @file{/gnu/store}
19145 directories of the bootstrap inputs. The process that leads to this
19146 ``final'' tool chain is described by the package definitions found in
19147 the @code{(gnu packages commencement)} module.
19148
19149 The @command{guix graph} command allows us to ``zoom out'' compared to
19150 the graph above, by looking at the level of package objects instead of
19151 individual derivations---remember that a package may translate to
19152 several derivations, typically one derivation to download its source,
19153 one to build the Guile modules it needs, and one to actually build the
19154 package from source. The command:
19155
19156 @example
19157 guix graph -t bag \
19158 -e '(@@@@ (gnu packages commencement)
19159 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
19160 @end example
19161
19162 @noindent
19163 produces the dependency graph leading to the ``final'' C
19164 library@footnote{You may notice the @code{glibc-intermediate} label,
19165 suggesting that it is not @emph{quite} final, but as a good
19166 approximation, we will consider it final.}, depicted below.
19167
19168 @image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
19169
19170 @c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
19171 The first tool that gets built with the bootstrap binaries is
19172 GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
19173 for all the following packages. From there Findutils and Diffutils get
19174 built.
19175
19176 Then come the first-stage Binutils and GCC, built as pseudo cross
19177 tools---i.e., with @code{--target} equal to @code{--host}. They are
19178 used to build libc. Thanks to this cross-build trick, this libc is
19179 guaranteed not to hold any reference to the initial tool chain.
19180
19181 From there the final Binutils and GCC (not shown above) are built.
19182 GCC uses @code{ld}
19183 from the final Binutils, and links programs against the just-built libc.
19184 This tool chain is used to build the other packages used by Guix and by
19185 the GNU Build System: Guile, Bash, Coreutils, etc.
19186
19187 And voilà! At this point we have the complete set of build tools that
19188 the GNU Build System expects. These are in the @code{%final-inputs}
19189 variable of the @code{(gnu packages commencement)} module, and are
19190 implicitly used by any package that uses @code{gnu-build-system}
19191 (@pxref{Build Systems, @code{gnu-build-system}}).
19192
19193
19194 @unnumberedsubsec Building the Bootstrap Binaries
19195
19196 @cindex bootstrap binaries
19197 Because the final tool chain does not depend on the bootstrap binaries,
19198 those rarely need to be updated. Nevertheless, it is useful to have an
19199 automated way to produce them, should an update occur, and this is what
19200 the @code{(gnu packages make-bootstrap)} module provides.
19201
19202 The following command builds the tarballs containing the bootstrap
19203 binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
19204 of Coreutils and other basic command-line tools):
19205
19206 @example
19207 guix build bootstrap-tarballs
19208 @end example
19209
19210 The generated tarballs are those that should be referred to in the
19211 @code{(gnu packages bootstrap)} module mentioned at the beginning of
19212 this section.
19213
19214 Still here? Then perhaps by now you've started to wonder: when do we
19215 reach a fixed point? That is an interesting question! The answer is
19216 unknown, but if you would like to investigate further (and have
19217 significant computational and storage resources to do so), then let us
19218 know.
19219
19220 @node Porting
19221 @section Porting to a New Platform
19222
19223 As discussed above, the GNU distribution is self-contained, and
19224 self-containment is achieved by relying on pre-built ``bootstrap
19225 binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
19226 operating system kernel, CPU architecture, and application binary
19227 interface (ABI). Thus, to port the distribution to a platform that is
19228 not yet supported, one must build those bootstrap binaries, and update
19229 the @code{(gnu packages bootstrap)} module to use them on that platform.
19230
19231 Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
19232 When everything goes well, and assuming the GNU tool chain supports the
19233 target platform, this can be as simple as running a command like this
19234 one:
19235
19236 @example
19237 guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
19238 @end example
19239
19240 For this to work, the @code{glibc-dynamic-linker} procedure in
19241 @code{(gnu packages bootstrap)} must be augmented to return the right
19242 file name for libc's dynamic linker on that platform; likewise,
19243 @code{system->linux-architecture} in @code{(gnu packages linux)} must be
19244 taught about the new platform.
19245
19246 Once these are built, the @code{(gnu packages bootstrap)} module needs
19247 to be updated to refer to these binaries on the target platform. That
19248 is, the hashes and URLs of the bootstrap tarballs for the new platform
19249 must be added alongside those of the currently supported platforms. The
19250 bootstrap Guile tarball is treated specially: it is expected to be
19251 available locally, and @file{gnu/local.mk} has rules do download it for
19252 the supported architectures; a rule for the new platform must be added
19253 as well.
19254
19255 In practice, there may be some complications. First, it may be that the
19256 extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
19257 above) is not recognized by all the GNU tools. Typically, glibc
19258 recognizes some of these, whereas GCC uses an extra @code{--with-abi}
19259 configure flag (see @code{gcc.scm} for examples of how to handle this).
19260 Second, some of the required packages could fail to build for that
19261 platform. Lastly, the generated binaries could be broken for some
19262 reason.
19263
19264 @c *********************************************************************
19265 @include contributing.texi
19266
19267 @c *********************************************************************
19268 @node Acknowledgments
19269 @chapter Acknowledgments
19270
19271 Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
19272 which was designed and
19273 implemented by Eelco Dolstra, with contributions from other people (see
19274 the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
19275 management, and promoted unprecedented features, such as transactional
19276 package upgrades and rollbacks, per-user profiles, and referentially
19277 transparent build processes. Without this work, Guix would not exist.
19278
19279 The Nix-based software distributions, Nixpkgs and NixOS, have also been
19280 an inspiration for Guix.
19281
19282 GNU@tie{}Guix itself is a collective work with contributions from a
19283 number of people. See the @file{AUTHORS} file in Guix for more
19284 information on these fine people. The @file{THANKS} file lists people
19285 who have helped by reporting bugs, taking care of the infrastructure,
19286 providing artwork and themes, making suggestions, and more---thank you!
19287
19288
19289 @c *********************************************************************
19290 @node GNU Free Documentation License
19291 @appendix GNU Free Documentation License
19292 @cindex license, GNU Free Documentation License
19293 @include fdl-1.3.texi
19294
19295 @c *********************************************************************
19296 @node Concept Index
19297 @unnumbered Concept Index
19298 @printindex cp
19299
19300 @node Programming Index
19301 @unnumbered Programming Index
19302 @syncodeindex tp fn
19303 @syncodeindex vr fn
19304 @printindex fn
19305
19306 @bye
19307
19308 @c Local Variables:
19309 @c ispell-local-dictionary: "american";
19310 @c End: