e70fed2f1c104fa6e0314512a368fa242729e77b
[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 @set KEY-SERVER pool.sks-keyservers.net
15
16 @c The official substitute server used by default.
17 @set SUBSTITUTE-SERVER ci.guix.info
18
19 @copying
20 Copyright @copyright{} 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès@*
21 Copyright @copyright{} 2013, 2014, 2016 Andreas Enge@*
22 Copyright @copyright{} 2013 Nikita Karetnikov@*
23 Copyright @copyright{} 2014, 2015, 2016 Alex Kost@*
24 Copyright @copyright{} 2015, 2016 Mathieu Lirzin@*
25 Copyright @copyright{} 2014 Pierre-Antoine Rault@*
26 Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer@*
27 Copyright @copyright{} 2015, 2016, 2017 Leo Famulari@*
28 Copyright @copyright{} 2015, 2016, 2017, 2018, 2019 Ricardo Wurmus@*
29 Copyright @copyright{} 2016 Ben Woodcroft@*
30 Copyright @copyright{} 2016, 2017, 2018 Chris Marusich@*
31 Copyright @copyright{} 2016, 2017, 2018 Efraim Flashner@*
32 Copyright @copyright{} 2016 John Darrington@*
33 Copyright @copyright{} 2016, 2017 Nils Gillmann@*
34 Copyright @copyright{} 2016, 2017, 2018 Jan Nieuwenhuizen@*
35 Copyright @copyright{} 2016 Julien Lepiller@*
36 Copyright @copyright{} 2016 Alex ter Weele@*
37 Copyright @copyright{} 2017, 2018 Clément Lassieur@*
38 Copyright @copyright{} 2017, 2018 Mathieu Othacehe@*
39 Copyright @copyright{} 2017 Federico Beffa@*
40 Copyright @copyright{} 2017, 2018 Carlo Zancanaro@*
41 Copyright @copyright{} 2017 Thomas Danckaert@*
42 Copyright @copyright{} 2017 humanitiesNerd@*
43 Copyright @copyright{} 2017 Christopher Allan Webber@*
44 Copyright @copyright{} 2017, 2018 Marius Bakke@*
45 Copyright @copyright{} 2017 Hartmut Goebel@*
46 Copyright @copyright{} 2017 Maxim Cournoyer@*
47 Copyright @copyright{} 2017, 2018 Tobias Geerinckx-Rice@*
48 Copyright @copyright{} 2017 George Clemmer@*
49 Copyright @copyright{} 2017 Andy Wingo@*
50 Copyright @copyright{} 2017, 2018 Arun Isaac@*
51 Copyright @copyright{} 2017 nee@*
52 Copyright @copyright{} 2018 Rutger Helling@*
53 Copyright @copyright{} 2018 Oleg Pykhalov@*
54 Copyright @copyright{} 2018 Mike Gerwitz@*
55 Copyright @copyright{} 2018 Pierre-Antoine Rouby@*
56 Copyright @copyright{} 2018 Gábor Boskovits@*
57 Copyright @copyright{} 2018 Florian Pelz@*
58 Copyright @copyright{} 2018 Laura Lazzati@*
59 Copyright @copyright{} 2018 Alex Vong@*
60
61 Permission is granted to copy, distribute and/or modify this document
62 under the terms of the GNU Free Documentation License, Version 1.3 or
63 any later version published by the Free Software Foundation; with no
64 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
65 copy of the license is included in the section entitled ``GNU Free
66 Documentation License''.
67 @end copying
68
69 @dircategory System administration
70 @direntry
71 * Guix: (guix). Manage installed software and system configuration.
72 * guix package: (guix)Invoking guix package. Installing, removing, and upgrading packages.
73 * guix gc: (guix)Invoking guix gc. Reclaiming unused disk space.
74 * guix pull: (guix)Invoking guix pull. Update the list of available packages.
75 * guix system: (guix)Invoking guix system. Manage the operating system configuration.
76 @end direntry
77
78 @dircategory Software development
79 @direntry
80 * guix environment: (guix)Invoking guix environment. Building development environments with Guix.
81 * guix build: (guix)Invoking guix build. Building packages.
82 * guix pack: (guix)Invoking guix pack. Creating binary bundles.
83 @end direntry
84
85 @titlepage
86 @title GNU Guix Reference Manual
87 @subtitle Using the GNU Guix Functional Package Manager
88 @author The GNU Guix Developers
89
90 @page
91 @vskip 0pt plus 1filll
92 Edition @value{EDITION} @*
93 @value{UPDATED} @*
94
95 @insertcopying
96 @end titlepage
97
98 @contents
99
100 @c *********************************************************************
101 @node Top
102 @top GNU Guix
103
104 This document describes GNU Guix version @value{VERSION}, a functional
105 package management tool written for the GNU system.
106
107 @c TRANSLATORS: You can replace the following paragraph with information on
108 @c how to join your own translation team and how to report issues with the
109 @c translation.
110 This manual is also available in French (@pxref{Top,,, guix.fr, Manuel de
111 référence de GNU Guix}) and German (@pxref{Top,,, guix.de, Referenzhandbuch
112 zu GNU Guix}). If you would like to translate it in your native language,
113 consider joining the
114 @uref{https://translationproject.org/domain/guix-manual.html, Translation
115 Project}.
116
117 @menu
118 * Introduction:: What is Guix about?
119 * Installation:: Installing Guix.
120 * Package Management:: Package installation, upgrade, etc.
121 * Programming Interface:: Using Guix in Scheme.
122 * Utilities:: Package management commands.
123 * GNU Distribution:: Software for your friendly GNU system.
124 * Contributing:: Your help needed!
125
126 * Acknowledgments:: Thanks!
127 * GNU Free Documentation License:: The license of this manual.
128 * Concept Index:: Concepts.
129 * Programming Index:: Data types, functions, and variables.
130
131 @detailmenu
132 --- The Detailed Node Listing ---
133
134 Installation
135
136 * Binary Installation:: Getting Guix running in no time!
137 * Requirements:: Software needed to build and run Guix.
138 * Running the Test Suite:: Testing Guix.
139 * Setting Up the Daemon:: Preparing the build daemon's environment.
140 * Invoking guix-daemon:: Running the build daemon.
141 * Application Setup:: Application-specific setup.
142
143 Setting Up the Daemon
144
145 * Build Environment Setup:: Preparing the isolated build environment.
146 * Daemon Offload Setup:: Offloading builds to remote machines.
147 * SELinux Support:: Using an SELinux policy for the daemon.
148
149 Package Management
150
151 * Features:: How Guix will make your life brighter.
152 * Invoking guix package:: Package installation, removal, etc.
153 * Substitutes:: Downloading pre-built binaries.
154 * Packages with Multiple Outputs:: Single source package, multiple outputs.
155 * Invoking guix gc:: Running the garbage collector.
156 * Invoking guix pull:: Fetching the latest Guix and distribution.
157 * Channels:: Customizing the package collection.
158 * Inferiors:: Interacting with another revision of Guix.
159 * Invoking guix describe:: Display information about your Guix revision.
160 * Invoking guix pack:: Creating software bundles.
161 * Invoking guix archive:: Exporting and importing store files.
162
163 Substitutes
164
165 * Official Substitute Server:: One particular source of substitutes.
166 * Substitute Server Authorization:: How to enable or disable substitutes.
167 * Substitute Authentication:: How Guix verifies substitutes.
168 * Proxy Settings:: How to get substitutes via proxy.
169 * Substitution Failure:: What happens when substitution fails.
170 * On Trusting Binaries:: How can you trust that binary blob?
171
172 Programming Interface
173
174 * Defining Packages:: Defining new packages.
175 * Build Systems:: Specifying how packages are built.
176 * The Store:: Manipulating the package store.
177 * Derivations:: Low-level interface to package derivations.
178 * The Store Monad:: Purely functional interface to the store.
179 * G-Expressions:: Manipulating build expressions.
180 * Invoking guix repl:: Fiddling with Guix interactively.
181
182 Defining Packages
183
184 * package Reference:: The package data type.
185 * origin Reference:: The origin data type.
186
187 Utilities
188
189 * Invoking guix build:: Building packages from the command line.
190 * Invoking guix edit:: Editing package definitions.
191 * Invoking guix download:: Downloading a file and printing its hash.
192 * Invoking guix hash:: Computing the cryptographic hash of a file.
193 * Invoking guix import:: Importing package definitions.
194 * Invoking guix refresh:: Updating package definitions.
195 * Invoking guix lint:: Finding errors in package definitions.
196 * Invoking guix size:: Profiling disk usage.
197 * Invoking guix graph:: Visualizing the graph of packages.
198 * Invoking guix environment:: Setting up development environments.
199 * Invoking guix publish:: Sharing substitutes.
200 * Invoking guix challenge:: Challenging substitute servers.
201 * Invoking guix copy:: Copying to and from a remote store.
202 * Invoking guix container:: Process isolation.
203 * Invoking guix weather:: Assessing substitute availability.
204 * Invoking guix processes:: Listing client processes.
205
206 Invoking @command{guix build}
207
208 * Common Build Options:: Build options for most commands.
209 * Package Transformation Options:: Creating variants of packages.
210 * Additional Build Options:: Options specific to 'guix build'.
211 * Debugging Build Failures:: Real life packaging experience.
212
213 GNU Distribution
214
215 * System Installation:: Installing the whole operating system.
216 * System Configuration:: Configuring the operating system.
217 * Documentation:: Browsing software user manuals.
218 * Installing Debugging Files:: Feeding the debugger.
219 * Security Updates:: Deploying security fixes quickly.
220 * Package Modules:: Packages from the programmer's viewpoint.
221 * Packaging Guidelines:: Growing the distribution.
222 * Bootstrapping:: GNU/Linux built from scratch.
223 * Porting:: Targeting another platform or kernel.
224
225 System Installation
226
227 * Limitations:: What you can expect.
228 * Hardware Considerations:: Supported hardware.
229 * USB Stick and DVD Installation:: Preparing the installation medium.
230 * Preparing for Installation:: Networking, partitioning, etc.
231 * Proceeding with the Installation:: The real thing.
232 * Installing GuixSD in a VM:: GuixSD playground.
233 * Building the Installation Image:: How this comes to be.
234
235 System Configuration
236
237 * Using the Configuration System:: Customizing your GNU system.
238 * operating-system Reference:: Detail of operating-system declarations.
239 * File Systems:: Configuring file system mounts.
240 * Mapped Devices:: Block device extra processing.
241 * User Accounts:: Specifying user accounts.
242 * Locales:: Language and cultural convention settings.
243 * Services:: Specifying system services.
244 * Setuid Programs:: Programs running with root privileges.
245 * X.509 Certificates:: Authenticating HTTPS servers.
246 * Name Service Switch:: Configuring libc's name service switch.
247 * Initial RAM Disk:: Linux-Libre bootstrapping.
248 * Bootloader Configuration:: Configuring the boot loader.
249 * Invoking guix system:: Instantiating a system configuration.
250 * Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
251 * Defining Services:: Adding new service definitions.
252
253 Services
254
255 * Base Services:: Essential system services.
256 * Scheduled Job Execution:: The mcron service.
257 * Log Rotation:: The rottlog service.
258 * Networking Services:: Network setup, SSH daemon, etc.
259 * X Window:: Graphical display.
260 * Printing Services:: Local and remote printer support.
261 * Desktop Services:: D-Bus and desktop services.
262 * Sound Services:: ALSA and Pulseaudio services.
263 * Database Services:: SQL databases, key-value stores, etc.
264 * Mail Services:: IMAP, POP3, SMTP, and all that.
265 * Messaging Services:: Messaging services.
266 * Telephony Services:: Telephony services.
267 * Monitoring Services:: Monitoring services.
268 * Kerberos Services:: Kerberos services.
269 * Web Services:: Web servers.
270 * Certificate Services:: TLS certificates via Let's Encrypt.
271 * DNS Services:: DNS daemons.
272 * VPN Services:: VPN daemons.
273 * Network File System:: NFS related services.
274 * Continuous Integration:: The Cuirass service.
275 * Power Management Services:: Extending battery life.
276 * Audio Services:: The MPD.
277 * Virtualization Services:: Virtualization services.
278 * Version Control Services:: Providing remote access to Git repositories.
279 * Game Services:: Game servers.
280 * Miscellaneous Services:: Other services.
281
282 Defining Services
283
284 * Service Composition:: The model for composing services.
285 * Service Types and Services:: Types and services.
286 * Service Reference:: API reference.
287 * Shepherd Services:: A particular type of service.
288
289 Packaging Guidelines
290
291 * Software Freedom:: What may go into the distribution.
292 * Package Naming:: What's in a name?
293 * Version Numbers:: When the name is not enough.
294 * Synopses and Descriptions:: Helping users find the right package.
295 * Python Modules:: A touch of British comedy.
296 * Perl Modules:: Little pearls.
297 * Java Packages:: Coffee break.
298 * Fonts:: Fond of fonts.
299
300 Contributing
301
302 * Building from Git:: The latest and greatest.
303 * Running Guix Before It Is Installed:: Hacker tricks.
304 * The Perfect Setup:: The right tools.
305 * Coding Style:: Hygiene of the contributor.
306 * Submitting Patches:: Share your work.
307
308 Coding Style
309
310 * Programming Paradigm:: How to compose your elements.
311 * Modules:: Where to store your code?
312 * Data Types and Pattern Matching:: Implementing data structures.
313 * Formatting Code:: Writing conventions.
314
315 @end detailmenu
316 @end menu
317
318 @c *********************************************************************
319 @node Introduction
320 @chapter Introduction
321
322 @cindex purpose
323 GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
324 using the international phonetic alphabet (IPA).} is a package
325 management tool for the GNU system. Guix makes it easy for unprivileged
326 users to install, upgrade, or remove packages, to roll back to a
327 previous package set, to build packages from source, and generally
328 assists with the creation and maintenance of software environments.
329
330 @cindex user interfaces
331 Guix provides a command-line package management interface
332 (@pxref{Invoking guix package}), a set of command-line utilities
333 (@pxref{Utilities}), as well as Scheme programming interfaces
334 (@pxref{Programming Interface}).
335 @cindex build daemon
336 Its @dfn{build daemon} is responsible for building packages on behalf of
337 users (@pxref{Setting Up the Daemon}) and for downloading pre-built
338 binaries from authorized sources (@pxref{Substitutes}).
339
340 @cindex extensibility of the distribution
341 @cindex customization, of packages
342 Guix includes package definitions for many GNU and non-GNU packages, all
343 of which @uref{https://www.gnu.org/philosophy/free-sw.html, respect the
344 user's computing freedom}. It is @emph{extensible}: users can write
345 their own package definitions (@pxref{Defining Packages}) and make them
346 available as independent package modules (@pxref{Package Modules}). It
347 is also @emph{customizable}: users can @emph{derive} specialized package
348 definitions from existing ones, including from the command line
349 (@pxref{Package Transformation Options}).
350
351 @cindex Guix System Distribution
352 @cindex GuixSD
353 You can install GNU@tie{}Guix on top of an existing GNU/Linux system
354 where it complements the available tools without interference
355 (@pxref{Installation}), or you can use it as part of the standalone
356 @dfn{Guix System Distribution} or GuixSD (@pxref{GNU Distribution}).
357 With GNU@tie{}GuixSD, you @emph{declare} all aspects of the operating
358 system configuration and Guix takes care of instantiating the
359 configuration in a transactional, reproducible, and stateless fashion
360 (@pxref{System Configuration}).
361
362 @cindex functional package management
363 @cindex isolation
364 Under the hood, Guix implements the @dfn{functional package management}
365 discipline pioneered by Nix (@pxref{Acknowledgments}).
366 In Guix, the package build and installation process is seen
367 as a @emph{function}, in the mathematical sense. That function takes inputs,
368 such as build scripts, a compiler, and libraries, and
369 returns an installed package. As a pure function, its result depends
370 solely on its inputs---for instance, it cannot refer to software or
371 scripts that were not explicitly passed as inputs. A build function
372 always produces the same result when passed a given set of inputs. It
373 cannot alter the environment of the running system in
374 any way; for instance, it cannot create, modify, or delete files outside
375 of its build and installation directories. This is achieved by running
376 build processes in isolated environments (or @dfn{containers}), where only their
377 explicit inputs are visible.
378
379 @cindex store
380 The result of package build functions is @dfn{cached} in the file
381 system, in a special directory called @dfn{the store} (@pxref{The
382 Store}). Each package is installed in a directory of its own in the
383 store---by default under @file{/gnu/store}. The directory name contains
384 a hash of all the inputs used to build that package; thus, changing an
385 input yields a different directory name.
386
387 This approach is the foundation for the salient features of Guix: support
388 for transactional package upgrade and rollback, per-user installation, and
389 garbage collection of packages (@pxref{Features}).
390
391
392 @c *********************************************************************
393 @node Installation
394 @chapter Installation
395
396 @cindex installing Guix
397
398 @quotation Note
399 We recommend the use of this
400 @uref{https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh,
401 shell installer script} to install Guix on top of a running GNU/Linux system,
402 thereafter called a @dfn{foreign distro}.@footnote{This section is concerned
403 with the installation of the package manager, which can be done on top of a
404 running GNU/Linux system. If, instead, you want to install the complete GNU
405 operating system, @pxref{System Installation}.} The script automates the
406 download, installation, and initial configuration of Guix. It should be run
407 as the root user.
408 @end quotation
409
410 @cindex foreign distro
411 @cindex directories related to foreign distro
412 When installed on a foreign distro, GNU@tie{}Guix complements the available
413 tools without interference. Its data lives exclusively in two directories,
414 usually @file{/gnu/store} and @file{/var/guix}; other files on your system,
415 such as @file{/etc}, are left untouched.
416
417 Once installed, Guix can be updated by running @command{guix pull}
418 (@pxref{Invoking guix pull}).
419
420 If you prefer to perform the installation steps manually or want to tweak
421 them, you may find the following subsections useful. They describe the
422 software requirements of Guix, as well as how to install it manually and get
423 ready to use it.
424
425 @menu
426 * Binary Installation:: Getting Guix running in no time!
427 * Requirements:: Software needed to build and run Guix.
428 * Running the Test Suite:: Testing Guix.
429 * Setting Up the Daemon:: Preparing the build daemon's environment.
430 * Invoking guix-daemon:: Running the build daemon.
431 * Application Setup:: Application-specific setup.
432 @end menu
433
434 @node Binary Installation
435 @section Binary Installation
436
437 @cindex installing Guix from binaries
438 @cindex installer script
439 This section describes how to install Guix on an arbitrary system from a
440 self-contained tarball providing binaries for Guix and for all its
441 dependencies. This is often quicker than installing from source, which
442 is described in the next sections. The only requirement is to have
443 GNU@tie{}tar and Xz.
444
445 Installing goes along these lines:
446
447 @enumerate
448 @item
449 @cindex downloading Guix binary
450 Download the binary tarball from
451 @indicateurl{https://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz},
452 where @var{system} is @code{x86_64-linux} for an @code{x86_64} machine
453 already running the kernel Linux, and so on.
454
455 @c The following is somewhat duplicated in ``System Installation''.
456 Make sure to download the associated @file{.sig} file and to verify the
457 authenticity of the tarball against it, along these lines:
458
459 @example
460 $ wget https://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
461 $ gpg --verify guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
462 @end example
463
464 If that command fails because you do not have the required public key,
465 then run this command to import it:
466
467 @example
468 $ gpg --keyserver @value{KEY-SERVER} \
469 --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
470 @end example
471
472 @noindent
473 and rerun the @code{gpg --verify} command.
474 @c end authentication part
475
476 @item
477 Now, you need to become the @code{root} user. Depending on your distribution,
478 you may have to run @code{su -} or @code{sudo -i}. As @code{root}, run:
479
480 @example
481 # cd /tmp
482 # tar --warning=no-timestamp -xf \
483 guix-binary-@value{VERSION}.@var{system}.tar.xz
484 # mv var/guix /var/ && mv gnu /
485 @end example
486
487 This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
488 The latter contains a ready-to-use profile for @code{root} (see next
489 step.)
490
491 Do @emph{not} unpack the tarball on a working Guix system since that
492 would overwrite its own essential files.
493
494 The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
495 not emit warnings about ``implausibly old time stamps'' (such
496 warnings were triggered by GNU@tie{}tar 1.26 and older; recent
497 versions are fine.)
498 They stem from the fact that all the
499 files in the archive have their modification time set to zero (which
500 means January 1st, 1970.) This is done on purpose to make sure the
501 archive content is independent of its creation time, thus making it
502 reproducible.
503
504 @item
505 Make the profile available under @file{~root/.config/guix/current}, which is
506 where @command{guix pull} will install updates (@pxref{Invoking guix pull}):
507
508 @example
509 # mkdir -p ~root/.config/guix
510 # ln -sf /var/guix/profiles/per-user/root/current-guix \
511 ~root/.config/guix/current
512 @end example
513
514 Source @file{etc/profile} to augment @code{PATH} and other relevant
515 environment variables:
516
517 @example
518 # GUIX_PROFILE="`echo ~root`/.config/guix/current" ; \
519 source $GUIX_PROFILE/etc/profile
520 @end example
521
522 @item
523 Create the group and user accounts for build users as explained below
524 (@pxref{Build Environment Setup}).
525
526 @item
527 Run the daemon, and set it to automatically start on boot.
528
529 If your host distro uses the systemd init system, this can be achieved
530 with these commands:
531
532 @c Versions of systemd that supported symlinked service files are not
533 @c yet widely deployed, so we should suggest that users copy the service
534 @c files into place.
535 @c
536 @c See this thread for more information:
537 @c http://lists.gnu.org/archive/html/guix-devel/2017-01/msg01199.html
538
539 @example
540 # cp ~root/.config/guix/current/lib/systemd/system/guix-daemon.service \
541 /etc/systemd/system/
542 # systemctl start guix-daemon && systemctl enable guix-daemon
543 @end example
544
545 If your host distro uses the Upstart init system:
546
547 @example
548 # initctl reload-configuration
549 # cp ~root/.config/guix/current/lib/upstart/system/guix-daemon.conf \
550 /etc/init/
551 # start guix-daemon
552 @end example
553
554 Otherwise, you can still start the daemon manually with:
555
556 @example
557 # ~root/.config/guix/current/bin/guix-daemon \
558 --build-users-group=guixbuild
559 @end example
560
561 @item
562 Make the @command{guix} command available to other users on the machine,
563 for instance with:
564
565 @example
566 # mkdir -p /usr/local/bin
567 # cd /usr/local/bin
568 # ln -s /var/guix/profiles/per-user/root/current-guix/bin/guix
569 @end example
570
571 It is also a good idea to make the Info version of this manual available
572 there:
573
574 @example
575 # mkdir -p /usr/local/share/info
576 # cd /usr/local/share/info
577 # for i in /var/guix/profiles/per-user/root/current-guix/share/info/* ;
578 do ln -s $i ; done
579 @end example
580
581 That way, assuming @file{/usr/local/share/info} is in the search path,
582 running @command{info guix} will open this manual (@pxref{Other Info
583 Directories,,, texinfo, GNU Texinfo}, for more details on changing the
584 Info search path.)
585
586 @item
587 @cindex substitutes, authorization thereof
588 To use substitutes from @code{@value{SUBSTITUTE-SERVER}} or one of its mirrors
589 (@pxref{Substitutes}), authorize them:
590
591 @example
592 # guix archive --authorize < \
593 ~root/.config/guix/current/share/guix/@value{SUBSTITUTE-SERVER}.pub
594 @end example
595
596 @item
597 Each user may need to perform a few additional steps to make their Guix
598 environment ready for use, @pxref{Application Setup}.
599 @end enumerate
600
601 Voilà, the installation is complete!
602
603 You can confirm that Guix is working by installing a sample package into
604 the root profile:
605
606 @example
607 # guix package -i hello
608 @end example
609
610 The @code{guix} package must remain available in @code{root}'s profile,
611 or it would become subject to garbage collection---in which case you
612 would find yourself badly handicapped by the lack of the @command{guix}
613 command. In other words, do not remove @code{guix} by running
614 @code{guix package -r guix}.
615
616 The binary installation tarball can be (re)produced and verified simply
617 by running the following command in the Guix source tree:
618
619 @example
620 make guix-binary.@var{system}.tar.xz
621 @end example
622
623 @noindent
624 ...@: which, in turn, runs:
625
626 @example
627 guix pack -s @var{system} --localstatedir \
628 --profile-name=current-guix guix
629 @end example
630
631 @xref{Invoking guix pack}, for more info on this handy tool.
632
633 @node Requirements
634 @section Requirements
635
636 This section lists requirements when building Guix from source. The
637 build procedure for Guix is the same as for other GNU software, and is
638 not covered here. Please see the files @file{README} and @file{INSTALL}
639 in the Guix source tree for additional details.
640
641 @cindex official website
642 GNU Guix is available for download from its website at
643 @url{https://www.gnu.org/software/guix/}.
644
645 GNU Guix depends on the following packages:
646
647 @itemize
648 @item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.2.x;
649 @item @url{https://notabug.org/cwebber/guile-gcrypt, Guile-Gcrypt}, version
650 0.1.0 or later;
651 @item
652 @uref{http://gnutls.org/, GnuTLS}, specifically its Guile bindings
653 (@pxref{Guile Preparations, how to install the GnuTLS bindings for
654 Guile,, gnutls-guile, GnuTLS-Guile});
655 @item
656 @uref{https://notabug.org/guile-sqlite3/guile-sqlite3, Guile-SQLite3}, version 0.1.0
657 or later;
658 @item
659 @c FIXME: Specify a version number once a release has been made.
660 @uref{https://gitlab.com/guile-git/guile-git, Guile-Git}, from August
661 2017 or later;
662 @item @uref{https://savannah.nongnu.org/projects/guile-json/, Guile-JSON};
663 @item @url{http://zlib.net, zlib};
664 @item @url{http://www.gnu.org/software/make/, GNU Make}.
665 @end itemize
666
667 The following dependencies are optional:
668
669 @itemize
670 @item
671 @c Note: We need at least 0.10.2 for 'channel-send-eof'.
672 Support for build offloading (@pxref{Daemon Offload Setup}) and
673 @command{guix copy} (@pxref{Invoking guix copy}) depends on
674 @uref{https://github.com/artyom-poptsov/guile-ssh, Guile-SSH},
675 version 0.10.2 or later.
676
677 @item
678 When @url{http://www.bzip.org, libbz2} is available,
679 @command{guix-daemon} can use it to compress build logs.
680 @end itemize
681
682 Unless @code{--disable-daemon} was passed to @command{configure}, the
683 following packages are also needed:
684
685 @itemize
686 @item @url{http://gnupg.org/, GNU libgcrypt};
687 @item @url{http://sqlite.org, SQLite 3};
688 @item @url{http://gcc.gnu.org, GCC's g++}, with support for the
689 C++11 standard.
690 @end itemize
691
692 @cindex state directory
693 When configuring Guix on a system that already has a Guix installation,
694 be sure to specify the same state directory as the existing installation
695 using the @code{--localstatedir} option of the @command{configure}
696 script (@pxref{Directory Variables, @code{localstatedir},, standards,
697 GNU Coding Standards}). The @command{configure} script protects against
698 unintended misconfiguration of @var{localstatedir} so you do not
699 inadvertently corrupt your store (@pxref{The Store}).
700
701 @cindex Nix, compatibility
702 When a working installation of @url{http://nixos.org/nix/, the Nix package
703 manager} is available, you
704 can instead configure Guix with @code{--disable-daemon}. In that case,
705 Nix replaces the three dependencies above.
706
707 Guix is compatible with Nix, so it is possible to share the same store
708 between both. To do so, you must pass @command{configure} not only the
709 same @code{--with-store-dir} value, but also the same
710 @code{--localstatedir} value. The latter is essential because it
711 specifies where the database that stores metadata about the store is
712 located, among other things. The default values for Nix are
713 @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
714 Note that @code{--disable-daemon} is not required if
715 your goal is to share the store with Nix.
716
717 @node Running the Test Suite
718 @section Running the Test Suite
719
720 @cindex test suite
721 After a successful @command{configure} and @code{make} run, it is a good
722 idea to run the test suite. It can help catch issues with the setup or
723 environment, or bugs in Guix itself---and really, reporting test
724 failures is a good way to help improve the software. To run the test
725 suite, type:
726
727 @example
728 make check
729 @end example
730
731 Test cases can run in parallel: you can use the @code{-j} option of
732 GNU@tie{}make to speed things up. The first run may take a few minutes
733 on a recent machine; subsequent runs will be faster because the store
734 that is created for test purposes will already have various things in
735 cache.
736
737 It is also possible to run a subset of the tests by defining the
738 @code{TESTS} makefile variable as in this example:
739
740 @example
741 make check TESTS="tests/store.scm tests/cpio.scm"
742 @end example
743
744 By default, tests results are displayed at a file level. In order to
745 see the details of every individual test cases, it is possible to define
746 the @code{SCM_LOG_DRIVER_FLAGS} makefile variable as in this example:
747
748 @example
749 make check TESTS="tests/base64.scm" SCM_LOG_DRIVER_FLAGS="--brief=no"
750 @end example
751
752 Upon failure, please email @email{bug-guix@@gnu.org} and attach the
753 @file{test-suite.log} file. Please specify the Guix version being used
754 as well as version numbers of the dependencies (@pxref{Requirements}) in
755 your message.
756
757 Guix also comes with a whole-system test suite that tests complete
758 GuixSD operating system instances. It can only run on systems where
759 Guix is already installed, using:
760
761 @example
762 make check-system
763 @end example
764
765 @noindent
766 or, again, by defining @code{TESTS} to select a subset of tests to run:
767
768 @example
769 make check-system TESTS="basic mcron"
770 @end example
771
772 These system tests are defined in the @code{(gnu tests @dots{})}
773 modules. They work by running the operating systems under test with
774 lightweight instrumentation in a virtual machine (VM). They can be
775 computationally intensive or rather cheap, depending on whether
776 substitutes are available for their dependencies (@pxref{Substitutes}).
777 Some of them require a lot of storage space to hold VM images.
778
779 Again in case of test failures, please send @email{bug-guix@@gnu.org}
780 all the details.
781
782 @node Setting Up the Daemon
783 @section Setting Up the Daemon
784
785 @cindex daemon
786 Operations such as building a package or running the garbage collector
787 are all performed by a specialized process, the @dfn{build daemon}, on
788 behalf of clients. Only the daemon may access the store and its
789 associated database. Thus, any operation that manipulates the store
790 goes through the daemon. For instance, command-line tools such as
791 @command{guix package} and @command{guix build} communicate with the
792 daemon (@i{via} remote procedure calls) to instruct it what to do.
793
794 The following sections explain how to prepare the build daemon's
795 environment. See also @ref{Substitutes}, for information on how to allow
796 the daemon to download pre-built binaries.
797
798 @menu
799 * Build Environment Setup:: Preparing the isolated build environment.
800 * Daemon Offload Setup:: Offloading builds to remote machines.
801 * SELinux Support:: Using an SELinux policy for the daemon.
802 @end menu
803
804 @node Build Environment Setup
805 @subsection Build Environment Setup
806
807 @cindex build environment
808 In a standard multi-user setup, Guix and its daemon---the
809 @command{guix-daemon} program---are installed by the system
810 administrator; @file{/gnu/store} is owned by @code{root} and
811 @command{guix-daemon} runs as @code{root}. Unprivileged users may use
812 Guix tools to build packages or otherwise access the store, and the
813 daemon will do it on their behalf, ensuring that the store is kept in a
814 consistent state, and allowing built packages to be shared among users.
815
816 @cindex build users
817 When @command{guix-daemon} runs as @code{root}, you may not want package
818 build processes themselves to run as @code{root} too, for obvious
819 security reasons. To avoid that, a special pool of @dfn{build users}
820 should be created for use by build processes started by the daemon.
821 These build users need not have a shell and a home directory: they will
822 just be used when the daemon drops @code{root} privileges in build
823 processes. Having several such users allows the daemon to launch
824 distinct build processes under separate UIDs, which guarantees that they
825 do not interfere with each other---an essential feature since builds are
826 regarded as pure functions (@pxref{Introduction}).
827
828 On a GNU/Linux system, a build user pool may be created like this (using
829 Bash syntax and the @code{shadow} commands):
830
831 @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
832 @c for why `-G' is needed.
833 @example
834 # groupadd --system guixbuild
835 # for i in `seq -w 1 10`;
836 do
837 useradd -g guixbuild -G guixbuild \
838 -d /var/empty -s `which nologin` \
839 -c "Guix build user $i" --system \
840 guixbuilder$i;
841 done
842 @end example
843
844 @noindent
845 The number of build users determines how many build jobs may run in
846 parallel, as specified by the @option{--max-jobs} option
847 (@pxref{Invoking guix-daemon, @option{--max-jobs}}). To use
848 @command{guix system vm} and related commands, you may need to add the
849 build users to the @code{kvm} group so they can access @file{/dev/kvm},
850 using @code{-G guixbuild,kvm} instead of @code{-G guixbuild}
851 (@pxref{Invoking guix system}).
852
853 The @code{guix-daemon} program may then be run as @code{root} with the
854 following command@footnote{If your machine uses the systemd init system,
855 dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
856 file in @file{/etc/systemd/system} will ensure that
857 @command{guix-daemon} is automatically started. Similarly, if your
858 machine uses the Upstart init system, drop the
859 @file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
860 file in @file{/etc/init}.}:
861
862 @example
863 # guix-daemon --build-users-group=guixbuild
864 @end example
865
866 @cindex chroot
867 @noindent
868 This way, the daemon starts build processes in a chroot, under one of
869 the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
870 environment contains nothing but:
871
872 @c Keep this list in sync with libstore/build.cc! -----------------------
873 @itemize
874 @item
875 a minimal @code{/dev} directory, created mostly independently from the
876 host @code{/dev}@footnote{``Mostly'', because while the set of files
877 that appear in the chroot's @code{/dev} is fixed, most of these files
878 can only be created if the host has them.};
879
880 @item
881 the @code{/proc} directory; it only shows the processes of the container
882 since a separate PID name space is used;
883
884 @item
885 @file{/etc/passwd} with an entry for the current user and an entry for
886 user @file{nobody};
887
888 @item
889 @file{/etc/group} with an entry for the user's group;
890
891 @item
892 @file{/etc/hosts} with an entry that maps @code{localhost} to
893 @code{127.0.0.1};
894
895 @item
896 a writable @file{/tmp} directory.
897 @end itemize
898
899 You can influence the directory where the daemon stores build trees
900 @i{via} the @code{TMPDIR} environment variable. However, the build tree
901 within the chroot is always called @file{/tmp/guix-build-@var{name}.drv-0},
902 where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
903 This way, the value of @code{TMPDIR} does not leak inside build
904 environments, which avoids discrepancies in cases where build processes
905 capture the name of their build tree.
906
907 @vindex http_proxy
908 The daemon also honors the @code{http_proxy} environment variable for
909 HTTP downloads it performs, be it for fixed-output derivations
910 (@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
911
912 If you are installing Guix as an unprivileged user, it is still possible
913 to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
914 However, build processes will not be isolated from one another, and not
915 from the rest of the system. Thus, build processes may interfere with
916 each other, and may access programs, libraries, and other files
917 available on the system---making it much harder to view them as
918 @emph{pure} functions.
919
920
921 @node Daemon Offload Setup
922 @subsection Using the Offload Facility
923
924 @cindex offloading
925 @cindex build hook
926 When desired, the build daemon can @dfn{offload} derivation builds to
927 other machines running Guix, using the @code{offload} @dfn{build
928 hook}@footnote{This feature is available only when
929 @uref{https://github.com/artyom-poptsov/guile-ssh, Guile-SSH} is
930 present.}. When that
931 feature is enabled, a list of user-specified build machines is read from
932 @file{/etc/guix/machines.scm}; every time a build is requested, for
933 instance via @code{guix build}, the daemon attempts to offload it to one
934 of the machines that satisfy the constraints of the derivation, in
935 particular its system type---e.g., @file{x86_64-linux}. Missing
936 prerequisites for the build are copied over SSH to the target machine,
937 which then proceeds with the build; upon success the output(s) of the
938 build are copied back to the initial machine.
939
940 The @file{/etc/guix/machines.scm} file typically looks like this:
941
942 @example
943 (list (build-machine
944 (name "eightysix.example.org")
945 (system "x86_64-linux")
946 (host-key "ssh-ed25519 AAAAC3Nza@dots{}")
947 (user "bob")
948 (speed 2.)) ;incredibly fast!
949
950 (build-machine
951 (name "meeps.example.org")
952 (system "mips64el-linux")
953 (host-key "ssh-rsa AAAAB3Nza@dots{}")
954 (user "alice")
955 (private-key
956 (string-append (getenv "HOME")
957 "/.ssh/identity-for-guix"))))
958 @end example
959
960 @noindent
961 In the example above we specify a list of two build machines, one for
962 the @code{x86_64} architecture and one for the @code{mips64el}
963 architecture.
964
965 In fact, this file is---not surprisingly!---a Scheme file that is
966 evaluated when the @code{offload} hook is started. Its return value
967 must be a list of @code{build-machine} objects. While this example
968 shows a fixed list of build machines, one could imagine, say, using
969 DNS-SD to return a list of potential build machines discovered in the
970 local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
971 Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
972 detailed below.
973
974 @deftp {Data Type} build-machine
975 This data type represents build machines to which the daemon may offload
976 builds. The important fields are:
977
978 @table @code
979
980 @item name
981 The host name of the remote machine.
982
983 @item system
984 The system type of the remote machine---e.g., @code{"x86_64-linux"}.
985
986 @item user
987 The user account to use when connecting to the remote machine over SSH.
988 Note that the SSH key pair must @emph{not} be passphrase-protected, to
989 allow non-interactive logins.
990
991 @item host-key
992 This must be the machine's SSH @dfn{public host key} in OpenSSH format.
993 This is used to authenticate the machine when we connect to it. It is a
994 long string that looks like this:
995
996 @example
997 ssh-ed25519 AAAAC3NzaC@dots{}mde+UhL hint@@example.org
998 @end example
999
1000 If the machine is running the OpenSSH daemon, @command{sshd}, the host
1001 key can be found in a file such as
1002 @file{/etc/ssh/ssh_host_ed25519_key.pub}.
1003
1004 If the machine is running the SSH daemon of GNU@tie{}lsh,
1005 @command{lshd}, the host key is in @file{/etc/lsh/host-key.pub} or a
1006 similar file. It can be converted to the OpenSSH format using
1007 @command{lsh-export-key} (@pxref{Converting keys,,, lsh, LSH Manual}):
1008
1009 @example
1010 $ lsh-export-key --openssh < /etc/lsh/host-key.pub
1011 ssh-rsa AAAAB3NzaC1yc2EAAAAEOp8FoQAAAQEAs1eB46LV@dots{}
1012 @end example
1013
1014 @end table
1015
1016 A number of optional fields may be specified:
1017
1018 @table @asis
1019
1020 @item @code{port} (default: @code{22})
1021 Port number of SSH server on the machine.
1022
1023 @item @code{private-key} (default: @file{~root/.ssh/id_rsa})
1024 The SSH private key file to use when connecting to the machine, in
1025 OpenSSH format. This key must not be protected with a passphrase.
1026
1027 Note that the default value is the private key @emph{of the root
1028 account}. Make sure it exists if you use the default.
1029
1030 @item @code{compression} (default: @code{"zlib@@openssh.com,zlib"})
1031 @itemx @code{compression-level} (default: @code{3})
1032 The SSH-level compression methods and compression level requested.
1033
1034 Note that offloading relies on SSH compression to reduce bandwidth usage
1035 when transferring files to and from build machines.
1036
1037 @item @code{daemon-socket} (default: @code{"/var/guix/daemon-socket/socket"})
1038 File name of the Unix-domain socket @command{guix-daemon} is listening
1039 to on that machine.
1040
1041 @item @code{parallel-builds} (default: @code{1})
1042 The number of builds that may run in parallel on the machine.
1043
1044 @item @code{speed} (default: @code{1.0})
1045 A ``relative speed factor''. The offload scheduler will tend to prefer
1046 machines with a higher speed factor.
1047
1048 @item @code{features} (default: @code{'()})
1049 A list of strings denoting specific features supported by the machine.
1050 An example is @code{"kvm"} for machines that have the KVM Linux modules
1051 and corresponding hardware support. Derivations can request features by
1052 name, and they will be scheduled on matching build machines.
1053
1054 @end table
1055 @end deftp
1056
1057 The @command{guix} command must be in the search path on the build
1058 machines. You can check whether this is the case by running:
1059
1060 @example
1061 ssh build-machine guix repl --version
1062 @end example
1063
1064 There is one last thing to do once @file{machines.scm} is in place. As
1065 explained above, when offloading, files are transferred back and forth
1066 between the machine stores. For this to work, you first need to
1067 generate a key pair on each machine to allow the daemon to export signed
1068 archives of files from the store (@pxref{Invoking guix archive}):
1069
1070 @example
1071 # guix archive --generate-key
1072 @end example
1073
1074 @noindent
1075 Each build machine must authorize the key of the master machine so that
1076 it accepts store items it receives from the master:
1077
1078 @example
1079 # guix archive --authorize < master-public-key.txt
1080 @end example
1081
1082 @noindent
1083 Likewise, the master machine must authorize the key of each build machine.
1084
1085 All the fuss with keys is here to express pairwise mutual trust
1086 relations between the master and the build machines. Concretely, when
1087 the master receives files from a build machine (and @i{vice versa}), its
1088 build daemon can make sure they are genuine, have not been tampered
1089 with, and that they are signed by an authorized key.
1090
1091 @cindex offload test
1092 To test whether your setup is operational, run this command on the
1093 master node:
1094
1095 @example
1096 # guix offload test
1097 @end example
1098
1099 This will attempt to connect to each of the build machines specified in
1100 @file{/etc/guix/machines.scm}, make sure Guile and the Guix modules are
1101 available on each machine, attempt to export to the machine and import
1102 from it, and report any error in the process.
1103
1104 If you want to test a different machine file, just specify it on the
1105 command line:
1106
1107 @example
1108 # guix offload test machines-qualif.scm
1109 @end example
1110
1111 Last, you can test the subset of the machines whose name matches a
1112 regular expression like this:
1113
1114 @example
1115 # guix offload test machines.scm '\.gnu\.org$'
1116 @end example
1117
1118 @cindex offload status
1119 To display the current load of all build hosts, run this command on the
1120 main node:
1121
1122 @example
1123 # guix offload status
1124 @end example
1125
1126
1127 @node SELinux Support
1128 @subsection SELinux Support
1129
1130 @cindex SELinux, daemon policy
1131 @cindex mandatory access control, SELinux
1132 @cindex security, guix-daemon
1133 Guix includes an SELinux policy file at @file{etc/guix-daemon.cil} that
1134 can be installed on a system where SELinux is enabled, in order to label
1135 Guix files and to specify the expected behavior of the daemon. Since
1136 GuixSD does not provide an SELinux base policy, the daemon policy cannot
1137 be used on GuixSD.
1138
1139 @subsubsection Installing the SELinux policy
1140 @cindex SELinux, policy installation
1141 To install the policy run this command as root:
1142
1143 @example
1144 semodule -i etc/guix-daemon.cil
1145 @end example
1146
1147 Then relabel the file system with @code{restorecon} or by a different
1148 mechanism provided by your system.
1149
1150 Once the policy is installed, the file system has been relabeled, and
1151 the daemon has been restarted, it should be running in the
1152 @code{guix_daemon_t} context. You can confirm this with the following
1153 command:
1154
1155 @example
1156 ps -Zax | grep guix-daemon
1157 @end example
1158
1159 Monitor the SELinux log files as you run a command like @code{guix build
1160 hello} to convince yourself that SELinux permits all necessary
1161 operations.
1162
1163 @subsubsection Limitations
1164 @cindex SELinux, limitations
1165
1166 This policy is not perfect. Here is a list of limitations or quirks
1167 that should be considered when deploying the provided SELinux policy for
1168 the Guix daemon.
1169
1170 @enumerate
1171 @item
1172 @code{guix_daemon_socket_t} isn’t actually used. None of the socket
1173 operations involve contexts that have anything to do with
1174 @code{guix_daemon_socket_t}. It doesn’t hurt to have this unused label,
1175 but it would be preferrable to define socket rules for only this label.
1176
1177 @item
1178 @code{guix gc} cannot access arbitrary links to profiles. By design,
1179 the file label of the destination of a symlink is independent of the
1180 file label of the link itself. Although all profiles under
1181 $localstatedir are labelled, the links to these profiles inherit the
1182 label of the directory they are in. For links in the user’s home
1183 directory this will be @code{user_home_t}. But for links from the root
1184 user’s home directory, or @file{/tmp}, or the HTTP server’s working
1185 directory, etc, this won’t work. @code{guix gc} would be prevented from
1186 reading and following these links.
1187
1188 @item
1189 The daemon’s feature to listen for TCP connections might no longer work.
1190 This might require extra rules, because SELinux treats network sockets
1191 differently from files.
1192
1193 @item
1194 Currently all files with a name matching the regular expression
1195 @code{/gnu/store/.+-(guix-.+|profile)/bin/guix-daemon} are assigned the
1196 label @code{guix_daemon_exec_t}; this means that @emph{any} file with
1197 that name in any profile would be permitted to run in the
1198 @code{guix_daemon_t} domain. This is not ideal. An attacker could
1199 build a package that provides this executable and convince a user to
1200 install and run it, which lifts it into the @code{guix_daemon_t} domain.
1201 At that point SELinux could not prevent it from accessing files that are
1202 allowed for processes in that domain.
1203
1204 We could generate a much more restrictive policy at installation time,
1205 so that only the @emph{exact} file name of the currently installed
1206 @code{guix-daemon} executable would be labelled with
1207 @code{guix_daemon_exec_t}, instead of using a broad regular expression.
1208 The downside is that root would have to install or upgrade the policy at
1209 installation time whenever the Guix package that provides the
1210 effectively running @code{guix-daemon} executable is upgraded.
1211 @end enumerate
1212
1213 @node Invoking guix-daemon
1214 @section Invoking @command{guix-daemon}
1215
1216 The @command{guix-daemon} program implements all the functionality to
1217 access the store. This includes launching build processes, running the
1218 garbage collector, querying the availability of a build result, etc. It
1219 is normally run as @code{root} like this:
1220
1221 @example
1222 # guix-daemon --build-users-group=guixbuild
1223 @end example
1224
1225 @noindent
1226 For details on how to set it up, @pxref{Setting Up the Daemon}.
1227
1228 @cindex chroot
1229 @cindex container, build environment
1230 @cindex build environment
1231 @cindex reproducible builds
1232 By default, @command{guix-daemon} launches build processes under
1233 different UIDs, taken from the build group specified with
1234 @code{--build-users-group}. In addition, each build process is run in a
1235 chroot environment that only contains the subset of the store that the
1236 build process depends on, as specified by its derivation
1237 (@pxref{Programming Interface, derivation}), plus a set of specific
1238 system directories. By default, the latter contains @file{/dev} and
1239 @file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
1240 @dfn{container}: in addition to having its own file system tree, it has
1241 a separate mount name space, its own PID name space, network name space,
1242 etc. This helps achieve reproducible builds (@pxref{Features}).
1243
1244 When the daemon performs a build on behalf of the user, it creates a
1245 build directory under @file{/tmp} or under the directory specified by
1246 its @code{TMPDIR} environment variable. This directory is shared with
1247 the container for the duration of the build, though within the container,
1248 the build tree is always called @file{/tmp/guix-build-@var{name}.drv-0}.
1249
1250 The build directory is automatically deleted upon completion, unless the
1251 build failed and the client specified @option{--keep-failed}
1252 (@pxref{Invoking guix build, @option{--keep-failed}}).
1253
1254 The daemon listens for connections and spawns one sub-process for each session
1255 started by a client (one of the @command{guix} sub-commands.) The
1256 @command{guix processes} command allows you to get an overview of the activity
1257 on your system by viewing each of the active sessions and clients.
1258 @xref{Invoking guix processes}, for more information.
1259
1260 The following command-line options are supported:
1261
1262 @table @code
1263 @item --build-users-group=@var{group}
1264 Take users from @var{group} to run build processes (@pxref{Setting Up
1265 the Daemon, build users}).
1266
1267 @item --no-substitutes
1268 @cindex substitutes
1269 Do not use substitutes for build products. That is, always build things
1270 locally instead of allowing downloads of pre-built binaries
1271 (@pxref{Substitutes}).
1272
1273 When the daemon runs with @code{--no-substitutes}, clients can still
1274 explicitly enable substitution @i{via} the @code{set-build-options}
1275 remote procedure call (@pxref{The Store}).
1276
1277 @item --substitute-urls=@var{urls}
1278 @anchor{daemon-substitute-urls}
1279 Consider @var{urls} the default whitespace-separated list of substitute
1280 source URLs. When this option is omitted,
1281 @indicateurl{https://@value{SUBSTITUTE-SERVER}} is used.
1282
1283 This means that substitutes may be downloaded from @var{urls}, as long
1284 as they are signed by a trusted signature (@pxref{Substitutes}).
1285
1286 @cindex build hook
1287 @item --no-build-hook
1288 Do not use the @dfn{build hook}.
1289
1290 The build hook is a helper program that the daemon can start and to
1291 which it submits build requests. This mechanism is used to offload
1292 builds to other machines (@pxref{Daemon Offload Setup}).
1293
1294 @item --cache-failures
1295 Cache build failures. By default, only successful builds are cached.
1296
1297 When this option is used, @command{guix gc --list-failures} can be used
1298 to query the set of store items marked as failed; @command{guix gc
1299 --clear-failures} removes store items from the set of cached failures.
1300 @xref{Invoking guix gc}.
1301
1302 @item --cores=@var{n}
1303 @itemx -c @var{n}
1304 Use @var{n} CPU cores to build each derivation; @code{0} means as many
1305 as available.
1306
1307 The default value is @code{0}, but it may be overridden by clients, such
1308 as the @code{--cores} option of @command{guix build} (@pxref{Invoking
1309 guix build}).
1310
1311 The effect is to define the @code{NIX_BUILD_CORES} environment variable
1312 in the build process, which can then use it to exploit internal
1313 parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
1314
1315 @item --max-jobs=@var{n}
1316 @itemx -M @var{n}
1317 Allow at most @var{n} build jobs in parallel. The default value is
1318 @code{1}. Setting it to @code{0} means that no builds will be performed
1319 locally; instead, the daemon will offload builds (@pxref{Daemon Offload
1320 Setup}), or simply fail.
1321
1322 @item --max-silent-time=@var{seconds}
1323 When the build or substitution process remains silent for more than
1324 @var{seconds}, terminate it and report a build failure.
1325
1326 The default value is @code{0}, which disables the timeout.
1327
1328 The value specified here can be overridden by clients (@pxref{Common
1329 Build Options, @code{--max-silent-time}}).
1330
1331 @item --timeout=@var{seconds}
1332 Likewise, when the build or substitution process lasts for more than
1333 @var{seconds}, terminate it and report a build failure.
1334
1335 The default value is @code{0}, which disables the timeout.
1336
1337 The value specified here can be overridden by clients (@pxref{Common
1338 Build Options, @code{--timeout}}).
1339
1340 @item --rounds=@var{N}
1341 Build each derivation @var{n} times in a row, and raise an error if
1342 consecutive build results are not bit-for-bit identical. Note that this
1343 setting can be overridden by clients such as @command{guix build}
1344 (@pxref{Invoking guix build}).
1345
1346 When used in conjunction with @option{--keep-failed}, the differing
1347 output is kept in the store, under @file{/gnu/store/@dots{}-check}.
1348 This makes it easy to look for differences between the two results.
1349
1350 @item --debug
1351 Produce debugging output.
1352
1353 This is useful to debug daemon start-up issues, but then it may be
1354 overridden by clients, for example the @code{--verbosity} option of
1355 @command{guix build} (@pxref{Invoking guix build}).
1356
1357 @item --chroot-directory=@var{dir}
1358 Add @var{dir} to the build chroot.
1359
1360 Doing this may change the result of build processes---for instance if
1361 they use optional dependencies found in @var{dir} when it is available,
1362 and not otherwise. For that reason, it is not recommended to do so.
1363 Instead, make sure that each derivation declares all the inputs that it
1364 needs.
1365
1366 @item --disable-chroot
1367 Disable chroot builds.
1368
1369 Using this option is not recommended since, again, it would allow build
1370 processes to gain access to undeclared dependencies. It is necessary,
1371 though, when @command{guix-daemon} is running under an unprivileged user
1372 account.
1373
1374 @item --log-compression=@var{type}
1375 Compress build logs according to @var{type}, one of @code{gzip},
1376 @code{bzip2}, or @code{none}.
1377
1378 Unless @code{--lose-logs} is used, all the build logs are kept in the
1379 @var{localstatedir}. To save space, the daemon automatically compresses
1380 them with bzip2 by default.
1381
1382 @item --disable-deduplication
1383 @cindex deduplication
1384 Disable automatic file ``deduplication'' in the store.
1385
1386 By default, files added to the store are automatically ``deduplicated'':
1387 if a newly added file is identical to another one found in the store,
1388 the daemon makes the new file a hard link to the other file. This can
1389 noticeably reduce disk usage, at the expense of slightly increased
1390 input/output load at the end of a build process. This option disables
1391 this optimization.
1392
1393 @item --gc-keep-outputs[=yes|no]
1394 Tell whether the garbage collector (GC) must keep outputs of live
1395 derivations.
1396
1397 @cindex GC roots
1398 @cindex garbage collector roots
1399 When set to ``yes'', the GC will keep the outputs of any live derivation
1400 available in the store---the @code{.drv} files. The default is ``no'',
1401 meaning that derivation outputs are kept only if they are reachable from a GC
1402 root. @xref{Invoking guix gc}, for more on GC roots.
1403
1404 @item --gc-keep-derivations[=yes|no]
1405 Tell whether the garbage collector (GC) must keep derivations
1406 corresponding to live outputs.
1407
1408 When set to ``yes'', as is the case by default, the GC keeps
1409 derivations---i.e., @code{.drv} files---as long as at least one of their
1410 outputs is live. This allows users to keep track of the origins of
1411 items in their store. Setting it to ``no'' saves a bit of disk space.
1412
1413 In this way, setting @code{--gc-keep-derivations} to ``yes'' causes liveness
1414 to flow from outputs to derivations, and setting @code{--gc-keep-outputs} to
1415 ``yes'' causes liveness to flow from derivations to outputs. When both are
1416 set to ``yes'', the effect is to keep all the build prerequisites (the
1417 sources, compiler, libraries, and other build-time tools) of live objects in
1418 the store, regardless of whether these prerequisites are reachable from a GC
1419 root. This is convenient for developers since it saves rebuilds or downloads.
1420
1421 @item --impersonate-linux-2.6
1422 On Linux-based systems, impersonate Linux 2.6. This means that the
1423 kernel's @code{uname} system call will report 2.6 as the release number.
1424
1425 This might be helpful to build programs that (usually wrongfully) depend
1426 on the kernel version number.
1427
1428 @item --lose-logs
1429 Do not keep build logs. By default they are kept under
1430 @code{@var{localstatedir}/guix/log}.
1431
1432 @item --system=@var{system}
1433 Assume @var{system} as the current system type. By default it is the
1434 architecture/kernel pair found at configure time, such as
1435 @code{x86_64-linux}.
1436
1437 @item --listen=@var{endpoint}
1438 Listen for connections on @var{endpoint}. @var{endpoint} is interpreted
1439 as the file name of a Unix-domain socket if it starts with
1440 @code{/} (slash sign). Otherwise, @var{endpoint} is interpreted as a
1441 host name or host name and port to listen to. Here are a few examples:
1442
1443 @table @code
1444 @item --listen=/gnu/var/daemon
1445 Listen for connections on the @file{/gnu/var/daemon} Unix-domain socket,
1446 creating it if needed.
1447
1448 @item --listen=localhost
1449 @cindex daemon, remote access
1450 @cindex remote access to the daemon
1451 @cindex daemon, cluster setup
1452 @cindex clusters, daemon setup
1453 Listen for TCP connections on the network interface corresponding to
1454 @code{localhost}, on port 44146.
1455
1456 @item --listen=128.0.0.42:1234
1457 Listen for TCP connections on the network interface corresponding to
1458 @code{128.0.0.42}, on port 1234.
1459 @end table
1460
1461 This option can be repeated multiple times, in which case
1462 @command{guix-daemon} accepts connections on all the specified
1463 endpoints. Users can tell client commands what endpoint to connect to
1464 by setting the @code{GUIX_DAEMON_SOCKET} environment variable
1465 (@pxref{The Store, @code{GUIX_DAEMON_SOCKET}}).
1466
1467 @quotation Note
1468 The daemon protocol is @emph{unauthenticated and unencrypted}. Using
1469 @code{--listen=@var{host}} is suitable on local networks, such as
1470 clusters, where only trusted nodes may connect to the build daemon. In
1471 other cases where remote access to the daemon is needed, we recommend
1472 using Unix-domain sockets along with SSH.
1473 @end quotation
1474
1475 When @code{--listen} is omitted, @command{guix-daemon} listens for
1476 connections on the Unix-domain socket located at
1477 @file{@var{localstatedir}/guix/daemon-socket/socket}.
1478 @end table
1479
1480
1481 @node Application Setup
1482 @section Application Setup
1483
1484 @cindex foreign distro
1485 When using Guix on top of GNU/Linux distribution other than GuixSD---a
1486 so-called @dfn{foreign distro}---a few additional steps are needed to
1487 get everything in place. Here are some of them.
1488
1489 @subsection Locales
1490
1491 @anchor{locales-and-locpath}
1492 @cindex locales, when not on GuixSD
1493 @vindex LOCPATH
1494 @vindex GUIX_LOCPATH
1495 Packages installed @i{via} Guix will not use the locale data of the
1496 host system. Instead, you must first install one of the locale packages
1497 available with Guix and then define the @code{GUIX_LOCPATH} environment
1498 variable:
1499
1500 @example
1501 $ guix package -i glibc-locales
1502 $ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
1503 @end example
1504
1505 Note that the @code{glibc-locales} package contains data for all the
1506 locales supported by the GNU@tie{}libc and weighs in at around
1507 110@tie{}MiB. Alternatively, the @code{glibc-utf8-locales} is smaller but
1508 limited to a few UTF-8 locales.
1509
1510 The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1511 (@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1512 Manual}). There are two important differences though:
1513
1514 @enumerate
1515 @item
1516 @code{GUIX_LOCPATH} is honored only by the libc in Guix, and not by the libc
1517 provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
1518 to make sure the programs of the foreign distro will not end up loading
1519 incompatible locale data.
1520
1521 @item
1522 libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1523 @code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1524 should your Guix profile contain a mixture of programs linked against
1525 different libc version, each libc version will only try to load locale
1526 data in the right format.
1527 @end enumerate
1528
1529 This is important because the locale data format used by different libc
1530 versions may be incompatible.
1531
1532 @subsection Name Service Switch
1533
1534 @cindex name service switch, glibc
1535 @cindex NSS (name service switch), glibc
1536 @cindex nscd (name service caching daemon)
1537 @cindex name service caching daemon (nscd)
1538 When using Guix on a foreign distro, we @emph{strongly recommend} that
1539 the system run the GNU C library's @dfn{name service cache daemon},
1540 @command{nscd}, which should be listening on the
1541 @file{/var/run/nscd/socket} socket. Failing to do that, applications
1542 installed with Guix may fail to look up host names or user accounts, or
1543 may even crash. The next paragraphs explain why.
1544
1545 @cindex @file{nsswitch.conf}
1546 The GNU C library implements a @dfn{name service switch} (NSS), which is
1547 an extensible mechanism for ``name lookups'' in general: host name
1548 resolution, user accounts, and more (@pxref{Name Service Switch,,, libc,
1549 The GNU C Library Reference Manual}).
1550
1551 @cindex Network information service (NIS)
1552 @cindex NIS (Network information service)
1553 Being extensible, the NSS supports @dfn{plugins}, which provide new name
1554 lookup implementations: for example, the @code{nss-mdns} plugin allow
1555 resolution of @code{.local} host names, the @code{nis} plugin allows
1556 user account lookup using the Network information service (NIS), and so
1557 on. These extra ``lookup services'' are configured system-wide in
1558 @file{/etc/nsswitch.conf}, and all the programs running on the system
1559 honor those settings (@pxref{NSS Configuration File,,, libc, The GNU C
1560 Reference Manual}).
1561
1562 When they perform a name lookup---for instance by calling the
1563 @code{getaddrinfo} function in C---applications first try to connect to
1564 the nscd; on success, nscd performs name lookups on their behalf. If
1565 the nscd is not running, then they perform the name lookup by
1566 themselves, by loading the name lookup services into their own address
1567 space and running it. These name lookup services---the
1568 @file{libnss_*.so} files---are @code{dlopen}'d, but they may come from
1569 the host system's C library, rather than from the C library the
1570 application is linked against (the C library coming from Guix).
1571
1572 And this is where the problem is: if your application is linked against
1573 Guix's C library (say, glibc 2.24) and tries to load NSS plugins from
1574 another C library (say, @code{libnss_mdns.so} for glibc 2.22), it will
1575 likely crash or have its name lookups fail unexpectedly.
1576
1577 Running @command{nscd} on the system, among other advantages, eliminates
1578 this binary incompatibility problem because those @code{libnss_*.so}
1579 files are loaded in the @command{nscd} process, not in applications
1580 themselves.
1581
1582 @subsection X11 Fonts
1583
1584 @cindex fonts
1585 The majority of graphical applications use Fontconfig to locate and
1586 load fonts and perform X11-client-side rendering. The @code{fontconfig}
1587 package in Guix looks for fonts in @file{$HOME/.guix-profile}
1588 by default. Thus, to allow graphical applications installed with Guix
1589 to display fonts, you have to install fonts with Guix as well.
1590 Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
1591 @code{font-gnu-freefont-ttf}.
1592
1593 To display text written in Chinese languages, Japanese, or Korean in
1594 graphical applications, consider installing
1595 @code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1596 has multiple outputs, one per language family (@pxref{Packages with
1597 Multiple Outputs}). For instance, the following command installs fonts
1598 for Chinese languages:
1599
1600 @example
1601 guix package -i font-adobe-source-han-sans:cn
1602 @end example
1603
1604 @cindex @code{xterm}
1605 Older programs such as @command{xterm} do not use Fontconfig and instead
1606 rely on server-side font rendering. Such programs require to specify a
1607 full name of a font using XLFD (X Logical Font Description), like this:
1608
1609 @example
1610 -*-dejavu sans-medium-r-normal-*-*-100-*-*-*-*-*-1
1611 @end example
1612
1613 To be able to use such full names for the TrueType fonts installed in
1614 your Guix profile, you need to extend the font path of the X server:
1615
1616 @c Note: 'xset' does not accept symlinks so the trick below arranges to
1617 @c get at the real directory. See <https://bugs.gnu.org/30655>.
1618 @example
1619 xset +fp $(dirname $(readlink -f ~/.guix-profile/share/fonts/truetype/fonts.dir))
1620 @end example
1621
1622 @cindex @code{xlsfonts}
1623 After that, you can run @code{xlsfonts} (from @code{xlsfonts} package)
1624 to make sure your TrueType fonts are listed there.
1625
1626 @cindex @code{fc-cache}
1627 @cindex font cache
1628 After installing fonts you may have to refresh the font cache to use
1629 them in applications. The same applies when applications installed via
1630 Guix do not seem to find fonts. To force rebuilding of the font cache
1631 run @code{fc-cache -f}. The @code{fc-cache} command is provided by the
1632 @code{fontconfig} package.
1633
1634 @subsection X.509 Certificates
1635
1636 @cindex @code{nss-certs}
1637 The @code{nss-certs} package provides X.509 certificates, which allow
1638 programs to authenticate Web servers accessed over HTTPS.
1639
1640 When using Guix on a foreign distro, you can install this package and
1641 define the relevant environment variables so that packages know where to
1642 look for certificates. @xref{X.509 Certificates}, for detailed
1643 information.
1644
1645 @subsection Emacs Packages
1646
1647 @cindex @code{emacs}
1648 When you install Emacs packages with Guix, the elisp files may be placed
1649 either in @file{$HOME/.guix-profile/share/emacs/site-lisp/} or in
1650 sub-directories of
1651 @file{$HOME/.guix-profile/share/emacs/site-lisp/guix.d/}. The latter
1652 directory exists because potentially there may exist thousands of Emacs
1653 packages and storing all their files in a single directory may not be
1654 reliable (because of name conflicts). So we think using a separate
1655 directory for each package is a good idea. It is very similar to how
1656 the Emacs package system organizes the file structure (@pxref{Package
1657 Files,,, emacs, The GNU Emacs Manual}).
1658
1659 By default, Emacs (installed with Guix) ``knows'' where these packages
1660 are placed, so you do not need to perform any configuration. If, for
1661 some reason, you want to avoid auto-loading Emacs packages installed
1662 with Guix, you can do so by running Emacs with @code{--no-site-file}
1663 option (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
1664
1665 @subsection The GCC toolchain
1666
1667 @cindex GCC
1668 @cindex ld-wrapper
1669
1670 Guix offers individual compiler packages such as @code{gcc} but if you
1671 are in need of a complete toolchain for compiling and linking source
1672 code what you really want is the @code{gcc-toolchain} package. This
1673 package provides a complete GCC toolchain for C/C++ development,
1674 including GCC itself, the GNU C Library (headers and binaries, plus
1675 debugging symbols in the @code{debug} output), Binutils, and a linker
1676 wrapper.
1677
1678 @cindex attempt to use impure library, error message
1679
1680 The wrapper's purpose is to inspect the @code{-L} and @code{-l} switches
1681 passed to the linker, add corresponding @code{-rpath} arguments, and
1682 invoke the actual linker with this new set of arguments. By default,
1683 the linker wrapper refuses to link to libraries outside the store to
1684 ensure ``purity''. This can be annoying when using the toolchain to
1685 link with local libraries. To allow references to libraries outside the
1686 store you need to define the environment variable
1687 @code{GUIX_LD_WRAPPER_ALLOW_IMPURITIES}.
1688
1689 @c TODO What else?
1690
1691 @c *********************************************************************
1692 @node Package Management
1693 @chapter Package Management
1694
1695 @cindex packages
1696 The purpose of GNU Guix is to allow users to easily install, upgrade, and
1697 remove software packages, without having to know about their build
1698 procedures or dependencies. Guix also goes beyond this obvious set of
1699 features.
1700
1701 This chapter describes the main features of Guix, as well as the
1702 package management tools it provides. Along with the command-line
1703 interface described below (@pxref{Invoking guix package, @code{guix
1704 package}}), you may also use the Emacs-Guix interface (@pxref{Top,,,
1705 emacs-guix, The Emacs-Guix Reference Manual}), after installing
1706 @code{emacs-guix} package (run @kbd{M-x guix-help} command to start
1707 with it):
1708
1709 @example
1710 guix package -i emacs-guix
1711 @end example
1712
1713 @menu
1714 * Features:: How Guix will make your life brighter.
1715 * Invoking guix package:: Package installation, removal, etc.
1716 * Substitutes:: Downloading pre-built binaries.
1717 * Packages with Multiple Outputs:: Single source package, multiple outputs.
1718 * Invoking guix gc:: Running the garbage collector.
1719 * Invoking guix pull:: Fetching the latest Guix and distribution.
1720 * Channels:: Customizing the package collection.
1721 * Inferiors:: Interacting with another revision of Guix.
1722 * Invoking guix describe:: Display information about your Guix revision.
1723 * Invoking guix pack:: Creating software bundles.
1724 * Invoking guix archive:: Exporting and importing store files.
1725 @end menu
1726
1727 @node Features
1728 @section Features
1729
1730 When using Guix, each package ends up in the @dfn{package store}, in its
1731 own directory---something that resembles
1732 @file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string.
1733
1734 Instead of referring to these directories, users have their own
1735 @dfn{profile}, which points to the packages that they actually want to
1736 use. These profiles are stored within each user's home directory, at
1737 @code{$HOME/.guix-profile}.
1738
1739 For example, @code{alice} installs GCC 4.7.2. As a result,
1740 @file{/home/alice/.guix-profile/bin/gcc} points to
1741 @file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
1742 @code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1743 simply continues to point to
1744 @file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
1745 coexist on the same system without any interference.
1746
1747 The @command{guix package} command is the central tool to manage
1748 packages (@pxref{Invoking guix package}). It operates on the per-user
1749 profiles, and can be used @emph{with normal user privileges}.
1750
1751 @cindex transactions
1752 The command provides the obvious install, remove, and upgrade
1753 operations. Each invocation is actually a @emph{transaction}: either
1754 the specified operation succeeds, or nothing happens. Thus, if the
1755 @command{guix package} process is terminated during the transaction,
1756 or if a power outage occurs during the transaction, then the user's
1757 profile remains in its previous state, and remains usable.
1758
1759 In addition, any package transaction may be @emph{rolled back}. So, if,
1760 for example, an upgrade installs a new version of a package that turns
1761 out to have a serious bug, users may roll back to the previous instance
1762 of their profile, which was known to work well. Similarly, the global
1763 system configuration on GuixSD is subject to
1764 transactional upgrades and roll-back
1765 (@pxref{Using the Configuration System}).
1766
1767 All packages in the package store may be @emph{garbage-collected}.
1768 Guix can determine which packages are still referenced by user
1769 profiles, and remove those that are provably no longer referenced
1770 (@pxref{Invoking guix gc}). Users may also explicitly remove old
1771 generations of their profile so that the packages they refer to can be
1772 collected.
1773
1774 @cindex reproducibility
1775 @cindex reproducible builds
1776 Guix takes a @dfn{purely functional} approach to package
1777 management, as described in the introduction (@pxref{Introduction}).
1778 Each @file{/gnu/store} package directory name contains a hash of all the
1779 inputs that were used to build that package---compiler, libraries, build
1780 scripts, etc. This direct correspondence allows users to make sure a
1781 given package installation matches the current state of their
1782 distribution. It also helps maximize @dfn{build reproducibility}:
1783 thanks to the isolated build environments that are used, a given build
1784 is likely to yield bit-identical files when performed on different
1785 machines (@pxref{Invoking guix-daemon, container}).
1786
1787 @cindex substitutes
1788 This foundation allows Guix to support @dfn{transparent binary/source
1789 deployment}. When a pre-built binary for a @file{/gnu/store} item is
1790 available from an external source---a @dfn{substitute}, Guix just
1791 downloads it and unpacks it;
1792 otherwise, it builds the package from source, locally
1793 (@pxref{Substitutes}). Because build results are usually bit-for-bit
1794 reproducible, users do not have to trust servers that provide
1795 substitutes: they can force a local build and @emph{challenge} providers
1796 (@pxref{Invoking guix challenge}).
1797
1798 Control over the build environment is a feature that is also useful for
1799 developers. The @command{guix environment} command allows developers of
1800 a package to quickly set up the right development environment for their
1801 package, without having to manually install the dependencies of the
1802 package into their profile (@pxref{Invoking guix environment}).
1803
1804 @cindex replication, of software environments
1805 @cindex provenance tracking, of software artifacts
1806 All of Guix and its package definitions is version-controlled, and
1807 @command{guix pull} allows you to ``travel in time'' on the history of Guix
1808 itself (@pxref{Invoking guix pull}). This makes it possible to replicate a
1809 Guix instance on a different machine or at a later point in time, which in
1810 turn allows you to @emph{replicate complete software environments}, while
1811 retaining precise @dfn{provenance tracking} of the software.
1812
1813 @node Invoking guix package
1814 @section Invoking @command{guix package}
1815
1816 @cindex installing packages
1817 @cindex removing packages
1818 @cindex package installation
1819 @cindex package removal
1820 The @command{guix package} command is the tool that allows users to
1821 install, upgrade, and remove packages, as well as rolling back to
1822 previous configurations. It operates only on the user's own profile,
1823 and works with normal user privileges (@pxref{Features}). Its syntax
1824 is:
1825
1826 @example
1827 guix package @var{options}
1828 @end example
1829 @cindex transactions
1830 Primarily, @var{options} specifies the operations to be performed during
1831 the transaction. Upon completion, a new profile is created, but
1832 previous @dfn{generations} of the profile remain available, should the user
1833 want to roll back.
1834
1835 For example, to remove @code{lua} and install @code{guile} and
1836 @code{guile-cairo} in a single transaction:
1837
1838 @example
1839 guix package -r lua -i guile guile-cairo
1840 @end example
1841
1842 @command{guix package} also supports a @dfn{declarative approach}
1843 whereby the user specifies the exact set of packages to be available and
1844 passes it @i{via} the @option{--manifest} option
1845 (@pxref{profile-manifest, @option{--manifest}}).
1846
1847 @cindex profile
1848 For each user, a symlink to the user's default profile is automatically
1849 created in @file{$HOME/.guix-profile}. This symlink always points to the
1850 current generation of the user's default profile. Thus, users can add
1851 @file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1852 variable, and so on.
1853 @cindex search paths
1854 If you are not using the Guix System Distribution, consider adding the
1855 following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1856 Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1857 shells get all the right environment variable definitions:
1858
1859 @example
1860 GUIX_PROFILE="$HOME/.guix-profile" ; \
1861 source "$HOME/.guix-profile/etc/profile"
1862 @end example
1863
1864 In a multi-user setup, user profiles are stored in a place registered as
1865 a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1866 to (@pxref{Invoking guix gc}). That directory is normally
1867 @code{@var{localstatedir}/guix/profiles/per-user/@var{user}}, where
1868 @var{localstatedir} is the value passed to @code{configure} as
1869 @code{--localstatedir}, and @var{user} is the user name. The
1870 @file{per-user} directory is created when @command{guix-daemon} is
1871 started, and the @var{user} sub-directory is created by @command{guix
1872 package}.
1873
1874 The @var{options} can be among the following:
1875
1876 @table @code
1877
1878 @item --install=@var{package} @dots{}
1879 @itemx -i @var{package} @dots{}
1880 Install the specified @var{package}s.
1881
1882 Each @var{package} may specify either a simple package name, such as
1883 @code{guile}, or a package name followed by an at-sign and version number,
1884 such as @code{guile@@1.8.8} or simply @code{guile@@1.8} (in the latter
1885 case, the newest version prefixed by @code{1.8} is selected.)
1886
1887 If no version number is specified, the
1888 newest available version will be selected. In addition, @var{package}
1889 may contain a colon, followed by the name of one of the outputs of the
1890 package, as in @code{gcc:doc} or @code{binutils@@2.22:lib}
1891 (@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1892 name (and optionally version) are searched for among the GNU
1893 distribution modules (@pxref{Package Modules}).
1894
1895 @cindex propagated inputs
1896 Sometimes packages have @dfn{propagated inputs}: these are dependencies
1897 that automatically get installed along with the required package
1898 (@pxref{package-propagated-inputs, @code{propagated-inputs} in
1899 @code{package} objects}, for information about propagated inputs in
1900 package definitions).
1901
1902 @anchor{package-cmd-propagated-inputs}
1903 An example is the GNU MPC library: its C header files refer to those of
1904 the GNU MPFR library, which in turn refer to those of the GMP library.
1905 Thus, when installing MPC, the MPFR and GMP libraries also get installed
1906 in the profile; removing MPC also removes MPFR and GMP---unless they had
1907 also been explicitly installed by the user.
1908
1909 Besides, packages sometimes rely on the definition of environment
1910 variables for their search paths (see explanation of
1911 @code{--search-paths} below). Any missing or possibly incorrect
1912 environment variable definitions are reported here.
1913
1914 @item --install-from-expression=@var{exp}
1915 @itemx -e @var{exp}
1916 Install the package @var{exp} evaluates to.
1917
1918 @var{exp} must be a Scheme expression that evaluates to a
1919 @code{<package>} object. This option is notably useful to disambiguate
1920 between same-named variants of a package, with expressions such as
1921 @code{(@@ (gnu packages base) guile-final)}.
1922
1923 Note that this option installs the first output of the specified
1924 package, which may be insufficient when needing a specific output of a
1925 multiple-output package.
1926
1927 @item --install-from-file=@var{file}
1928 @itemx -f @var{file}
1929 Install the package that the code within @var{file} evaluates to.
1930
1931 As an example, @var{file} might contain a definition like this
1932 (@pxref{Defining Packages}):
1933
1934 @example
1935 @verbatiminclude package-hello.scm
1936 @end example
1937
1938 Developers may find it useful to include such a @file{guix.scm} file
1939 in the root of their project source tree that can be used to test
1940 development snapshots and create reproducible development environments
1941 (@pxref{Invoking guix environment}).
1942
1943 @item --remove=@var{package} @dots{}
1944 @itemx -r @var{package} @dots{}
1945 Remove the specified @var{package}s.
1946
1947 As for @code{--install}, each @var{package} may specify a version number
1948 and/or output name in addition to the package name. For instance,
1949 @code{-r glibc:debug} would remove the @code{debug} output of
1950 @code{glibc}.
1951
1952 @item --upgrade[=@var{regexp} @dots{}]
1953 @itemx -u [@var{regexp} @dots{}]
1954 @cindex upgrading packages
1955 Upgrade all the installed packages. If one or more @var{regexp}s are
1956 specified, upgrade only installed packages whose name matches a
1957 @var{regexp}. Also see the @code{--do-not-upgrade} option below.
1958
1959 Note that this upgrades package to the latest version of packages found
1960 in the distribution currently installed. To update your distribution,
1961 you should regularly run @command{guix pull} (@pxref{Invoking guix
1962 pull}).
1963
1964 @item --do-not-upgrade[=@var{regexp} @dots{}]
1965 When used together with the @code{--upgrade} option, do @emph{not}
1966 upgrade any packages whose name matches a @var{regexp}. For example, to
1967 upgrade all packages in the current profile except those containing the
1968 substring ``emacs'':
1969
1970 @example
1971 $ guix package --upgrade . --do-not-upgrade emacs
1972 @end example
1973
1974 @item @anchor{profile-manifest}--manifest=@var{file}
1975 @itemx -m @var{file}
1976 @cindex profile declaration
1977 @cindex profile manifest
1978 Create a new generation of the profile from the manifest object
1979 returned by the Scheme code in @var{file}.
1980
1981 This allows you to @emph{declare} the profile's contents rather than
1982 constructing it through a sequence of @code{--install} and similar
1983 commands. The advantage is that @var{file} can be put under version
1984 control, copied to different machines to reproduce the same profile, and
1985 so on.
1986
1987 @c FIXME: Add reference to (guix profile) documentation when available.
1988 @var{file} must return a @dfn{manifest} object, which is roughly a list
1989 of packages:
1990
1991 @findex packages->manifest
1992 @example
1993 (use-package-modules guile emacs)
1994
1995 (packages->manifest
1996 (list emacs
1997 guile-2.0
1998 ;; Use a specific package output.
1999 (list guile-2.0 "debug")))
2000 @end example
2001
2002 @findex specifications->manifest
2003 In this example we have to know which modules define the @code{emacs}
2004 and @code{guile-2.0} variables to provide the right
2005 @code{use-package-modules} line, which can be cumbersome. We can
2006 instead provide regular package specifications and let
2007 @code{specifications->manifest} look up the corresponding package
2008 objects, like this:
2009
2010 @example
2011 (specifications->manifest
2012 '("emacs" "guile@@2.2" "guile@@2.2:debug"))
2013 @end example
2014
2015 @item --roll-back
2016 @cindex rolling back
2017 @cindex undoing transactions
2018 @cindex transactions, undoing
2019 Roll back to the previous @dfn{generation} of the profile---i.e., undo
2020 the last transaction.
2021
2022 When combined with options such as @code{--install}, roll back occurs
2023 before any other actions.
2024
2025 When rolling back from the first generation that actually contains
2026 installed packages, the profile is made to point to the @dfn{zeroth
2027 generation}, which contains no files apart from its own metadata.
2028
2029 After having rolled back, installing, removing, or upgrading packages
2030 overwrites previous future generations. Thus, the history of the
2031 generations in a profile is always linear.
2032
2033 @item --switch-generation=@var{pattern}
2034 @itemx -S @var{pattern}
2035 @cindex generations
2036 Switch to a particular generation defined by @var{pattern}.
2037
2038 @var{pattern} may be either a generation number or a number prefixed
2039 with ``+'' or ``-''. The latter means: move forward/backward by a
2040 specified number of generations. For example, if you want to return to
2041 the latest generation after @code{--roll-back}, use
2042 @code{--switch-generation=+1}.
2043
2044 The difference between @code{--roll-back} and
2045 @code{--switch-generation=-1} is that @code{--switch-generation} will
2046 not make a zeroth generation, so if a specified generation does not
2047 exist, the current generation will not be changed.
2048
2049 @item --search-paths[=@var{kind}]
2050 @cindex search paths
2051 Report environment variable definitions, in Bash syntax, that may be
2052 needed in order to use the set of installed packages. These environment
2053 variables are used to specify @dfn{search paths} for files used by some
2054 of the installed packages.
2055
2056 For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
2057 environment variables to be defined so it can look for headers and
2058 libraries in the user's profile (@pxref{Environment Variables,,, gcc,
2059 Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
2060 library are installed in the profile, then @code{--search-paths} will
2061 suggest setting these variables to @code{@var{profile}/include} and
2062 @code{@var{profile}/lib}, respectively.
2063
2064 The typical use case is to define these environment variables in the
2065 shell:
2066
2067 @example
2068 $ eval `guix package --search-paths`
2069 @end example
2070
2071 @var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
2072 meaning that the returned environment variable definitions will either
2073 be exact settings, or prefixes or suffixes of the current value of these
2074 variables. When omitted, @var{kind} defaults to @code{exact}.
2075
2076 This option can also be used to compute the @emph{combined} search paths
2077 of several profiles. Consider this example:
2078
2079 @example
2080 $ guix package -p foo -i guile
2081 $ guix package -p bar -i guile-json
2082 $ guix package -p foo -p bar --search-paths
2083 @end example
2084
2085 The last command above reports about the @code{GUILE_LOAD_PATH}
2086 variable, even though, taken individually, neither @file{foo} nor
2087 @file{bar} would lead to that recommendation.
2088
2089
2090 @item --profile=@var{profile}
2091 @itemx -p @var{profile}
2092 Use @var{profile} instead of the user's default profile.
2093
2094 @cindex collisions, in a profile
2095 @cindex colliding packages in profiles
2096 @cindex profile collisions
2097 @item --allow-collisions
2098 Allow colliding packages in the new profile. Use at your own risk!
2099
2100 By default, @command{guix package} reports as an error @dfn{collisions}
2101 in the profile. Collisions happen when two or more different versions
2102 or variants of a given package end up in the profile.
2103
2104 @item --bootstrap
2105 Use the bootstrap Guile to build the profile. This option is only
2106 useful to distribution developers.
2107
2108 @end table
2109
2110 In addition to these actions, @command{guix package} supports the
2111 following options to query the current state of a profile, or the
2112 availability of packages:
2113
2114 @table @option
2115
2116 @item --search=@var{regexp}
2117 @itemx -s @var{regexp}
2118 @cindex searching for packages
2119 List the available packages whose name, synopsis, or description matches
2120 @var{regexp} (in a case-insensitive fashion), sorted by relevance.
2121 Print all the metadata of matching packages in
2122 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
2123 GNU recutils manual}).
2124
2125 This allows specific fields to be extracted using the @command{recsel}
2126 command, for instance:
2127
2128 @example
2129 $ guix package -s malloc | recsel -p name,version,relevance
2130 name: jemalloc
2131 version: 4.5.0
2132 relevance: 6
2133
2134 name: glibc
2135 version: 2.25
2136 relevance: 1
2137
2138 name: libgc
2139 version: 7.6.0
2140 relevance: 1
2141 @end example
2142
2143 Similarly, to show the name of all the packages available under the
2144 terms of the GNU@tie{}LGPL version 3:
2145
2146 @example
2147 $ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
2148 name: elfutils
2149
2150 name: gmp
2151 @dots{}
2152 @end example
2153
2154 It is also possible to refine search results using several @code{-s}
2155 flags. For example, the following command returns a list of board
2156 games:
2157
2158 @example
2159 $ guix package -s '\<board\>' -s game | recsel -p name
2160 name: gnubg
2161 @dots{}
2162 @end example
2163
2164 If we were to omit @code{-s game}, we would also get software packages
2165 that deal with printed circuit boards; removing the angle brackets
2166 around @code{board} would further add packages that have to do with
2167 keyboards.
2168
2169 And now for a more elaborate example. The following command searches
2170 for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
2171 libraries, and prints the name and synopsis of the matching packages:
2172
2173 @example
2174 $ guix package -s crypto -s library | \
2175 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
2176 @end example
2177
2178 @noindent
2179 @xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
2180 information on @dfn{selection expressions} for @code{recsel -e}.
2181
2182 @item --show=@var{package}
2183 Show details about @var{package}, taken from the list of available packages, in
2184 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
2185 recutils manual}).
2186
2187 @example
2188 $ guix package --show=python | recsel -p name,version
2189 name: python
2190 version: 2.7.6
2191
2192 name: python
2193 version: 3.3.5
2194 @end example
2195
2196 You may also specify the full name of a package to only get details about a
2197 specific version of it:
2198 @example
2199 $ guix package --show=python@@3.4 | recsel -p name,version
2200 name: python
2201 version: 3.4.3
2202 @end example
2203
2204
2205
2206 @item --list-installed[=@var{regexp}]
2207 @itemx -I [@var{regexp}]
2208 List the currently installed packages in the specified profile, with the
2209 most recently installed packages shown last. When @var{regexp} is
2210 specified, list only installed packages whose name matches @var{regexp}.
2211
2212 For each installed package, print the following items, separated by
2213 tabs: the package name, its version string, the part of the package that
2214 is installed (for instance, @code{out} for the default output,
2215 @code{include} for its headers, etc.), and the path of this package in
2216 the store.
2217
2218 @item --list-available[=@var{regexp}]
2219 @itemx -A [@var{regexp}]
2220 List packages currently available in the distribution for this system
2221 (@pxref{GNU Distribution}). When @var{regexp} is specified, list only
2222 installed packages whose name matches @var{regexp}.
2223
2224 For each package, print the following items separated by tabs: its name,
2225 its version string, the parts of the package (@pxref{Packages with
2226 Multiple Outputs}), and the source location of its definition.
2227
2228 @item --list-generations[=@var{pattern}]
2229 @itemx -l [@var{pattern}]
2230 @cindex generations
2231 Return a list of generations along with their creation dates; for each
2232 generation, show the installed packages, with the most recently
2233 installed packages shown last. Note that the zeroth generation is never
2234 shown.
2235
2236 For each installed package, print the following items, separated by
2237 tabs: the name of a package, its version string, the part of the package
2238 that is installed (@pxref{Packages with Multiple Outputs}), and the
2239 location of this package in the store.
2240
2241 When @var{pattern} is used, the command returns only matching
2242 generations. Valid patterns include:
2243
2244 @itemize
2245 @item @emph{Integers and comma-separated integers}. Both patterns denote
2246 generation numbers. For instance, @code{--list-generations=1} returns
2247 the first one.
2248
2249 And @code{--list-generations=1,8,2} outputs three generations in the
2250 specified order. Neither spaces nor trailing commas are allowed.
2251
2252 @item @emph{Ranges}. @code{--list-generations=2..9} prints the
2253 specified generations and everything in between. Note that the start of
2254 a range must be smaller than its end.
2255
2256 It is also possible to omit the endpoint. For example,
2257 @code{--list-generations=2..}, returns all generations starting from the
2258 second one.
2259
2260 @item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
2261 or months by passing an integer along with the first letter of the
2262 duration. For example, @code{--list-generations=20d} lists generations
2263 that are up to 20 days old.
2264 @end itemize
2265
2266 @item --delete-generations[=@var{pattern}]
2267 @itemx -d [@var{pattern}]
2268 When @var{pattern} is omitted, delete all generations except the current
2269 one.
2270
2271 This command accepts the same patterns as @option{--list-generations}.
2272 When @var{pattern} is specified, delete the matching generations. When
2273 @var{pattern} specifies a duration, generations @emph{older} than the
2274 specified duration match. For instance, @code{--delete-generations=1m}
2275 deletes generations that are more than one month old.
2276
2277 If the current generation matches, it is @emph{not} deleted. Also, the
2278 zeroth generation is never deleted.
2279
2280 Note that deleting generations prevents rolling back to them.
2281 Consequently, this command must be used with care.
2282
2283 @end table
2284
2285 Finally, since @command{guix package} may actually start build
2286 processes, it supports all the common build options (@pxref{Common Build
2287 Options}). It also supports package transformation options, such as
2288 @option{--with-source} (@pxref{Package Transformation Options}).
2289 However, note that package transformations are lost when upgrading; to
2290 preserve transformations across upgrades, you should define your own
2291 package variant in a Guile module and add it to @code{GUIX_PACKAGE_PATH}
2292 (@pxref{Defining Packages}).
2293
2294 @node Substitutes
2295 @section Substitutes
2296
2297 @cindex substitutes
2298 @cindex pre-built binaries
2299 Guix supports transparent source/binary deployment, which means that it
2300 can either build things locally, or download pre-built items from a
2301 server, or both. We call these pre-built items @dfn{substitutes}---they
2302 are substitutes for local build results. In many cases, downloading a
2303 substitute is much faster than building things locally.
2304
2305 Substitutes can be anything resulting from a derivation build
2306 (@pxref{Derivations}). Of course, in the common case, they are
2307 pre-built package binaries, but source tarballs, for instance, which
2308 also result from derivation builds, can be available as substitutes.
2309
2310 @menu
2311 * Official Substitute Server:: One particular source of substitutes.
2312 * Substitute Server Authorization:: How to enable or disable substitutes.
2313 * Substitute Authentication:: How Guix verifies substitutes.
2314 * Proxy Settings:: How to get substitutes via proxy.
2315 * Substitution Failure:: What happens when substitution fails.
2316 * On Trusting Binaries:: How can you trust that binary blob?
2317 @end menu
2318
2319 @node Official Substitute Server
2320 @subsection Official Substitute Server
2321
2322 @cindex hydra
2323 @cindex build farm
2324 The @code{@value{SUBSTITUTE-SERVER}} server is a front-end to an official build farm
2325 that builds packages from Guix continuously for some
2326 architectures, and makes them available as substitutes. This is the
2327 default source of substitutes; it can be overridden by passing the
2328 @option{--substitute-urls} option either to @command{guix-daemon}
2329 (@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
2330 or to client tools such as @command{guix package}
2331 (@pxref{client-substitute-urls,, client @option{--substitute-urls}
2332 option}).
2333
2334 Substitute URLs can be either HTTP or HTTPS.
2335 HTTPS is recommended because communications are encrypted; conversely,
2336 using HTTP makes all communications visible to an eavesdropper, who
2337 could use the information gathered to determine, for instance, whether
2338 your system has unpatched security vulnerabilities.
2339
2340 Substitutes from the official build farm are enabled by default when
2341 using the Guix System Distribution (@pxref{GNU Distribution}). However,
2342 they are disabled by default when using Guix on a foreign distribution,
2343 unless you have explicitly enabled them via one of the recommended
2344 installation steps (@pxref{Installation}). The following paragraphs
2345 describe how to enable or disable substitutes for the official build
2346 farm; the same procedure can also be used to enable substitutes for any
2347 other substitute server.
2348
2349 @node Substitute Server Authorization
2350 @subsection Substitute Server Authorization
2351
2352 @cindex security
2353 @cindex substitutes, authorization thereof
2354 @cindex access control list (ACL), for substitutes
2355 @cindex ACL (access control list), for substitutes
2356 To allow Guix to download substitutes from @code{@value{SUBSTITUTE-SERVER}} or a
2357 mirror thereof, you
2358 must add its public key to the access control list (ACL) of archive
2359 imports, using the @command{guix archive} command (@pxref{Invoking guix
2360 archive}). Doing so implies that you trust @code{@value{SUBSTITUTE-SERVER}} to not
2361 be compromised and to serve genuine substitutes.
2362
2363 The public key for @code{@value{SUBSTITUTE-SERVER}} is installed along with Guix, in
2364 @code{@var{prefix}/share/guix/@value{SUBSTITUTE-SERVER}.pub}, where @var{prefix} is
2365 the installation prefix of Guix. If you installed Guix from source,
2366 make sure you checked the GPG signature of
2367 @file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
2368 Then, you can run something like this:
2369
2370 @example
2371 # guix archive --authorize < @var{prefix}/share/guix/@value{SUBSTITUTE-SERVER}.pub
2372 @end example
2373
2374 @quotation Note
2375 Similarly, the @file{hydra.gnu.org.pub} file contains the public key
2376 of an independent build farm also run by the project, reachable at
2377 @indicateurl{https://mirror.hydra.gnu.org}.
2378 @end quotation
2379
2380 Once this is in place, the output of a command like @code{guix build}
2381 should change from something like:
2382
2383 @example
2384 $ guix build emacs --dry-run
2385 The following derivations would be built:
2386 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
2387 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
2388 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
2389 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
2390 @dots{}
2391 @end example
2392
2393 @noindent
2394 to something like:
2395
2396 @example
2397 $ guix build emacs --dry-run
2398 112.3 MB would be downloaded:
2399 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
2400 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
2401 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
2402 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
2403 @dots{}
2404 @end example
2405
2406 @noindent
2407 This indicates that substitutes from @code{@value{SUBSTITUTE-SERVER}} are usable and
2408 will be downloaded, when possible, for future builds.
2409
2410 @cindex substitutes, how to disable
2411 The substitute mechanism can be disabled globally by running
2412 @code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
2413 guix-daemon}). It can also be disabled temporarily by passing the
2414 @code{--no-substitutes} option to @command{guix package}, @command{guix
2415 build}, and other command-line tools.
2416
2417 @node Substitute Authentication
2418 @subsection Substitute Authentication
2419
2420 @cindex digital signatures
2421 Guix detects and raises an error when attempting to use a substitute
2422 that has been tampered with. Likewise, it ignores substitutes that are
2423 not signed, or that are not signed by one of the keys listed in the ACL.
2424
2425 There is one exception though: if an unauthorized server provides
2426 substitutes that are @emph{bit-for-bit identical} to those provided by
2427 an authorized server, then the unauthorized server becomes eligible for
2428 downloads. For example, assume we have chosen two substitute servers
2429 with this option:
2430
2431 @example
2432 --substitute-urls="https://a.example.org https://b.example.org"
2433 @end example
2434
2435 @noindent
2436 @cindex reproducible builds
2437 If the ACL contains only the key for @code{b.example.org}, and if
2438 @code{a.example.org} happens to serve the @emph{exact same} substitutes,
2439 then Guix will download substitutes from @code{a.example.org} because it
2440 comes first in the list and can be considered a mirror of
2441 @code{b.example.org}. In practice, independent build machines usually
2442 produce the same binaries, thanks to bit-reproducible builds (see
2443 below).
2444
2445 When using HTTPS, the server's X.509 certificate is @emph{not} validated
2446 (in other words, the server is not authenticated), contrary to what
2447 HTTPS clients such as Web browsers usually do. This is because Guix
2448 authenticates substitute information itself, as explained above, which
2449 is what we care about (whereas X.509 certificates are about
2450 authenticating bindings between domain names and public keys.)
2451
2452 @node Proxy Settings
2453 @subsection Proxy Settings
2454
2455 @vindex http_proxy
2456 Substitutes are downloaded over HTTP or HTTPS.
2457 The @code{http_proxy} environment
2458 variable can be set in the environment of @command{guix-daemon} and is
2459 honored for downloads of substitutes. Note that the value of
2460 @code{http_proxy} in the environment where @command{guix build},
2461 @command{guix package}, and other client commands are run has
2462 @emph{absolutely no effect}.
2463
2464 @node Substitution Failure
2465 @subsection Substitution Failure
2466
2467 Even when a substitute for a derivation is available, sometimes the
2468 substitution attempt will fail. This can happen for a variety of
2469 reasons: the substitute server might be offline, the substitute may
2470 recently have been deleted, the connection might have been interrupted,
2471 etc.
2472
2473 When substitutes are enabled and a substitute for a derivation is
2474 available, but the substitution attempt fails, Guix will attempt to
2475 build the derivation locally depending on whether or not
2476 @code{--fallback} was given (@pxref{fallback-option,, common build
2477 option @code{--fallback}}). Specifically, if @code{--fallback} was
2478 omitted, then no local build will be performed, and the derivation is
2479 considered to have failed. However, if @code{--fallback} was given,
2480 then Guix will attempt to build the derivation locally, and the success
2481 or failure of the derivation depends on the success or failure of the
2482 local build. Note that when substitutes are disabled or no substitute
2483 is available for the derivation in question, a local build will
2484 @emph{always} be performed, regardless of whether or not
2485 @code{--fallback} was given.
2486
2487 To get an idea of how many substitutes are available right now, you can
2488 try running the @command{guix weather} command (@pxref{Invoking guix
2489 weather}). This command provides statistics on the substitutes provided
2490 by a server.
2491
2492 @node On Trusting Binaries
2493 @subsection On Trusting Binaries
2494
2495 @cindex trust, of pre-built binaries
2496 Today, each individual's control over their own computing is at the
2497 mercy of institutions, corporations, and groups with enough power and
2498 determination to subvert the computing infrastructure and exploit its
2499 weaknesses. While using @code{@value{SUBSTITUTE-SERVER}} substitutes can be
2500 convenient, we encourage users to also build on their own, or even run
2501 their own build farm, such that @code{@value{SUBSTITUTE-SERVER}} is less of an
2502 interesting target. One way to help is by publishing the software you
2503 build using @command{guix publish} so that others have one more choice
2504 of server to download substitutes from (@pxref{Invoking guix publish}).
2505
2506 Guix has the foundations to maximize build reproducibility
2507 (@pxref{Features}). In most cases, independent builds of a given
2508 package or derivation should yield bit-identical results. Thus, through
2509 a diverse set of independent package builds, we can strengthen the
2510 integrity of our systems. The @command{guix challenge} command aims to
2511 help users assess substitute servers, and to assist developers in
2512 finding out about non-deterministic package builds (@pxref{Invoking guix
2513 challenge}). Similarly, the @option{--check} option of @command{guix
2514 build} allows users to check whether previously-installed substitutes
2515 are genuine by rebuilding them locally (@pxref{build-check,
2516 @command{guix build --check}}).
2517
2518 In the future, we want Guix to have support to publish and retrieve
2519 binaries to/from other users, in a peer-to-peer fashion. If you would
2520 like to discuss this project, join us on @email{guix-devel@@gnu.org}.
2521
2522 @node Packages with Multiple Outputs
2523 @section Packages with Multiple Outputs
2524
2525 @cindex multiple-output packages
2526 @cindex package outputs
2527 @cindex outputs
2528
2529 Often, packages defined in Guix have a single @dfn{output}---i.e., the
2530 source package leads to exactly one directory in the store. When running
2531 @command{guix package -i glibc}, one installs the default output of the
2532 GNU libc package; the default output is called @code{out}, but its name
2533 can be omitted as shown in this command. In this particular case, the
2534 default output of @code{glibc} contains all the C header files, shared
2535 libraries, static libraries, Info documentation, and other supporting
2536 files.
2537
2538 Sometimes it is more appropriate to separate the various types of files
2539 produced from a single source package into separate outputs. For
2540 instance, the GLib C library (used by GTK+ and related packages)
2541 installs more than 20 MiB of reference documentation as HTML pages.
2542 To save space for users who do not need it, the documentation goes to a
2543 separate output, called @code{doc}. To install the main GLib output,
2544 which contains everything but the documentation, one would run:
2545
2546 @example
2547 guix package -i glib
2548 @end example
2549
2550 @cindex documentation
2551 The command to install its documentation is:
2552
2553 @example
2554 guix package -i glib:doc
2555 @end example
2556
2557 Some packages install programs with different ``dependency footprints''.
2558 For instance, the WordNet package installs both command-line tools and
2559 graphical user interfaces (GUIs). The former depend solely on the C
2560 library, whereas the latter depend on Tcl/Tk and the underlying X
2561 libraries. In this case, we leave the command-line tools in the default
2562 output, whereas the GUIs are in a separate output. This allows users
2563 who do not need the GUIs to save space. The @command{guix size} command
2564 can help find out about such situations (@pxref{Invoking guix size}).
2565 @command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
2566
2567 There are several such multiple-output packages in the GNU distribution.
2568 Other conventional output names include @code{lib} for libraries and
2569 possibly header files, @code{bin} for stand-alone programs, and
2570 @code{debug} for debugging information (@pxref{Installing Debugging
2571 Files}). The outputs of a packages are listed in the third column of
2572 the output of @command{guix package --list-available} (@pxref{Invoking
2573 guix package}).
2574
2575
2576 @node Invoking guix gc
2577 @section Invoking @command{guix gc}
2578
2579 @cindex garbage collector
2580 @cindex disk space
2581 Packages that are installed, but not used, may be @dfn{garbage-collected}.
2582 The @command{guix gc} command allows users to explicitly run the garbage
2583 collector to reclaim space from the @file{/gnu/store} directory. It is
2584 the @emph{only} way to remove files from @file{/gnu/store}---removing
2585 files or directories manually may break it beyond repair!
2586
2587 @cindex GC roots
2588 @cindex garbage collector roots
2589 The garbage collector has a set of known @dfn{roots}: any file under
2590 @file{/gnu/store} reachable from a root is considered @dfn{live} and
2591 cannot be deleted; any other file is considered @dfn{dead} and may be
2592 deleted. The set of garbage collector roots (``GC roots'' for short)
2593 includes default user profiles; by default, the symlinks under
2594 @file{/var/guix/gcroots} represent these GC roots. New GC roots can be
2595 added with @command{guix build --root}, for example (@pxref{Invoking
2596 guix build}).
2597
2598 Prior to running @code{guix gc --collect-garbage} to make space, it is
2599 often useful to remove old generations from user profiles; that way, old
2600 package builds referenced by those generations can be reclaimed. This
2601 is achieved by running @code{guix package --delete-generations}
2602 (@pxref{Invoking guix package}).
2603
2604 Our recommendation is to run a garbage collection periodically, or when
2605 you are short on disk space. For instance, to guarantee that at least
2606 5@tie{}GB are available on your disk, simply run:
2607
2608 @example
2609 guix gc -F 5G
2610 @end example
2611
2612 It is perfectly safe to run as a non-interactive periodic job
2613 (@pxref{Scheduled Job Execution}, for how to set up such a job on
2614 GuixSD). Running @command{guix gc} with no arguments will collect as
2615 much garbage as it can, but that is often inconvenient: you may find
2616 yourself having to rebuild or re-download software that is ``dead'' from
2617 the GC viewpoint but that is necessary to build other pieces of
2618 software---e.g., the compiler tool chain.
2619
2620 The @command{guix gc} command has three modes of operation: it can be
2621 used to garbage-collect any dead files (the default), to delete specific
2622 files (the @code{--delete} option), to print garbage-collector
2623 information, or for more advanced queries. The garbage collection
2624 options are as follows:
2625
2626 @table @code
2627 @item --collect-garbage[=@var{min}]
2628 @itemx -C [@var{min}]
2629 Collect garbage---i.e., unreachable @file{/gnu/store} files and
2630 sub-directories. This is the default operation when no option is
2631 specified.
2632
2633 When @var{min} is given, stop once @var{min} bytes have been collected.
2634 @var{min} may be a number of bytes, or it may include a unit as a
2635 suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
2636 (@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
2637
2638 When @var{min} is omitted, collect all the garbage.
2639
2640 @item --free-space=@var{free}
2641 @itemx -F @var{free}
2642 Collect garbage until @var{free} space is available under
2643 @file{/gnu/store}, if possible; @var{free} denotes storage space, such
2644 as @code{500MiB}, as described above.
2645
2646 When @var{free} or more is already available in @file{/gnu/store}, do
2647 nothing and exit immediately.
2648
2649 @item --delete
2650 @itemx -d
2651 Attempt to delete all the store files and directories specified as
2652 arguments. This fails if some of the files are not in the store, or if
2653 they are still live.
2654
2655 @item --list-failures
2656 List store items corresponding to cached build failures.
2657
2658 This prints nothing unless the daemon was started with
2659 @option{--cache-failures} (@pxref{Invoking guix-daemon,
2660 @option{--cache-failures}}).
2661
2662 @item --clear-failures
2663 Remove the specified store items from the failed-build cache.
2664
2665 Again, this option only makes sense when the daemon is started with
2666 @option{--cache-failures}. Otherwise, it does nothing.
2667
2668 @item --list-dead
2669 Show the list of dead files and directories still present in the
2670 store---i.e., files and directories no longer reachable from any root.
2671
2672 @item --list-live
2673 Show the list of live store files and directories.
2674
2675 @end table
2676
2677 In addition, the references among existing store files can be queried:
2678
2679 @table @code
2680
2681 @item --references
2682 @itemx --referrers
2683 @cindex package dependencies
2684 List the references (respectively, the referrers) of store files given
2685 as arguments.
2686
2687 @item --requisites
2688 @itemx -R
2689 @cindex closure
2690 List the requisites of the store files passed as arguments. Requisites
2691 include the store files themselves, their references, and the references
2692 of these, recursively. In other words, the returned list is the
2693 @dfn{transitive closure} of the store files.
2694
2695 @xref{Invoking guix size}, for a tool to profile the size of the closure
2696 of an element. @xref{Invoking guix graph}, for a tool to visualize
2697 the graph of references.
2698
2699 @item --derivers
2700 @cindex derivation
2701 Return the derivation(s) leading to the given store items
2702 (@pxref{Derivations}).
2703
2704 For example, this command:
2705
2706 @example
2707 guix gc --derivers `guix package -I ^emacs$ | cut -f4`
2708 @end example
2709
2710 @noindent
2711 returns the @file{.drv} file(s) leading to the @code{emacs} package
2712 installed in your profile.
2713
2714 Note that there may be zero matching @file{.drv} files, for instance
2715 because these files have been garbage-collected. There can also be more
2716 than one matching @file{.drv} due to fixed-output derivations.
2717 @end table
2718
2719 Lastly, the following options allow you to check the integrity of the
2720 store and to control disk usage.
2721
2722 @table @option
2723
2724 @item --verify[=@var{options}]
2725 @cindex integrity, of the store
2726 @cindex integrity checking
2727 Verify the integrity of the store.
2728
2729 By default, make sure that all the store items marked as valid in the
2730 database of the daemon actually exist in @file{/gnu/store}.
2731
2732 When provided, @var{options} must be a comma-separated list containing one
2733 or more of @code{contents} and @code{repair}.
2734
2735 When passing @option{--verify=contents}, the daemon computes the
2736 content hash of each store item and compares it against its hash in the
2737 database. Hash mismatches are reported as data corruptions. Because it
2738 traverses @emph{all the files in the store}, this command can take a
2739 long time, especially on systems with a slow disk drive.
2740
2741 @cindex repairing the store
2742 @cindex corruption, recovering from
2743 Using @option{--verify=repair} or @option{--verify=contents,repair}
2744 causes the daemon to try to repair corrupt store items by fetching
2745 substitutes for them (@pxref{Substitutes}). Because repairing is not
2746 atomic, and thus potentially dangerous, it is available only to the
2747 system administrator. A lightweight alternative, when you know exactly
2748 which items in the store are corrupt, is @command{guix build --repair}
2749 (@pxref{Invoking guix build}).
2750
2751 @item --optimize
2752 @cindex deduplication
2753 Optimize the store by hard-linking identical files---this is
2754 @dfn{deduplication}.
2755
2756 The daemon performs deduplication after each successful build or archive
2757 import, unless it was started with @code{--disable-deduplication}
2758 (@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
2759 this option is primarily useful when the daemon was running with
2760 @code{--disable-deduplication}.
2761
2762 @end table
2763
2764 @node Invoking guix pull
2765 @section Invoking @command{guix pull}
2766
2767 @cindex upgrading Guix
2768 @cindex updating Guix
2769 @cindex @command{guix pull}
2770 @cindex pull
2771 Packages are installed or upgraded to the latest version available in
2772 the distribution currently available on your local machine. To update
2773 that distribution, along with the Guix tools, you must run @command{guix
2774 pull}: the command downloads the latest Guix source code and package
2775 descriptions, and deploys it. Source code is downloaded from a
2776 @uref{https://git-scm.com, Git} repository, by default the official
2777 GNU@tie{}Guix repository, though this can be customized.
2778
2779 On completion, @command{guix package} will use packages and package
2780 versions from this just-retrieved copy of Guix. Not only that, but all
2781 the Guix commands and Scheme modules will also be taken from that latest
2782 version. New @command{guix} sub-commands added by the update also
2783 become available.
2784
2785 Any user can update their Guix copy using @command{guix pull}, and the
2786 effect is limited to the user who run @command{guix pull}. For
2787 instance, when user @code{root} runs @command{guix pull}, this has no
2788 effect on the version of Guix that user @code{alice} sees, and vice
2789 versa.
2790
2791 The result of running @command{guix pull} is a @dfn{profile} available
2792 under @file{~/.config/guix/current} containing the latest Guix. Thus,
2793 make sure to add it to the beginning of your search path so that you use
2794 the latest version, and similarly for the Info manual
2795 (@pxref{Documentation}):
2796
2797 @example
2798 export PATH="$HOME/.config/guix/current/bin:$PATH"
2799 export INFOPATH="$HOME/.config/guix/current/share/info:$INFOPATH"
2800 @end example
2801
2802 The @code{--list-generations} or @code{-l} option lists past generations
2803 produced by @command{guix pull}, along with details about their provenance:
2804
2805 @example
2806 $ guix pull -l
2807 Generation 1 Jun 10 2018 00:18:18
2808 guix 65956ad
2809 repository URL: https://git.savannah.gnu.org/git/guix.git
2810 branch: origin/master
2811 commit: 65956ad3526ba09e1f7a40722c96c6ef7c0936fe
2812
2813 Generation 2 Jun 11 2018 11:02:49
2814 guix e0cc7f6
2815 repository URL: https://git.savannah.gnu.org/git/guix.git
2816 branch: origin/master
2817 commit: e0cc7f669bec22c37481dd03a7941c7d11a64f1d
2818 2 new packages: keepalived, libnfnetlink
2819 6 packages upgraded: emacs-nix-mode@@2.0.4,
2820 guile2.0-guix@@0.14.0-12.77a1aac, guix@@0.14.0-12.77a1aac,
2821 heimdal@@7.5.0, milkytracker@@1.02.00, nix@@2.0.4
2822
2823 Generation 3 Jun 13 2018 23:31:07 (current)
2824 guix 844cc1c
2825 repository URL: https://git.savannah.gnu.org/git/guix.git
2826 branch: origin/master
2827 commit: 844cc1c8f394f03b404c5bb3aee086922373490c
2828 28 new packages: emacs-helm-ls-git, emacs-helm-mu, @dots{}
2829 69 packages upgraded: borg@@1.1.6, cheese@@3.28.0, @dots{}
2830 @end example
2831
2832 @ref{Invoking guix describe, @command{guix describe}}, for other ways to
2833 describe the current status of Guix.
2834
2835 This @code{~/.config/guix/current} profile works like any other profile
2836 created by @command{guix package} (@pxref{Invoking guix package}). That
2837 is, you can list generations, roll back to the previous
2838 generation---i.e., the previous Guix---and so on:
2839
2840 @example
2841 $ guix package -p ~/.config/guix/current --roll-back
2842 switched from generation 3 to 2
2843 $ guix package -p ~/.config/guix/current --delete-generations=1
2844 deleting /var/guix/profiles/per-user/charlie/current-guix-1-link
2845 @end example
2846
2847 The @command{guix pull} command is usually invoked with no arguments,
2848 but it supports the following options:
2849
2850 @table @code
2851 @item --url=@var{url}
2852 @itemx --commit=@var{commit}
2853 @itemx --branch=@var{branch}
2854 Download code from the specified @var{url}, at the given @var{commit} (a valid
2855 Git commit ID represented as a hexadecimal string), or @var{branch}.
2856
2857 @cindex @file{channels.scm}, configuration file
2858 @cindex configuration file for channels
2859 These options are provided for convenience, but you can also specify your
2860 configuration in the @file{~/.config/guix/channels.scm} file or using the
2861 @option{--channels} option (see below).
2862
2863 @item --channels=@var{file}
2864 @itemx -C @var{file}
2865 Read the list of channels from @var{file} instead of
2866 @file{~/.config/guix/channels.scm}. @var{file} must contain Scheme code that
2867 evaluates to a list of channel objects. @xref{Channels}, for more
2868 information.
2869
2870 @item --list-generations[=@var{pattern}]
2871 @itemx -l [@var{pattern}]
2872 List all the generations of @file{~/.config/guix/current} or, if @var{pattern}
2873 is provided, the subset of generations that match @var{pattern}.
2874 The syntax of @var{pattern} is the same as with @code{guix package
2875 --list-generations} (@pxref{Invoking guix package}).
2876
2877 @ref{Invoking guix describe}, for a way to display information about the
2878 current generation only.
2879
2880 @item --profile=@var{profile}
2881 @itemx -p @var{profile}
2882 Use @var{profile} instead of @file{~/.config/guix/current}.
2883
2884 @item --dry-run
2885 @itemx -n
2886 Show which channel commit(s) would be used and what would be built or
2887 substituted but do not actually do it.
2888
2889 @item --system=@var{system}
2890 @itemx -s @var{system}
2891 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
2892 the system type of the build host.
2893
2894 @item --verbose
2895 Produce verbose output, writing build logs to the standard error output.
2896
2897 @item --bootstrap
2898 Use the bootstrap Guile to build the latest Guix. This option is only
2899 useful to Guix developers.
2900 @end table
2901
2902 The @dfn{channel} mechanism allows you to instruct @command{guix pull} which
2903 repository and branch to pull from, as well as @emph{additional} repositories
2904 containing package modules that should be deployed. @xref{Channels}, for more
2905 information.
2906
2907 In addition, @command{guix pull} supports all the common build options
2908 (@pxref{Common Build Options}).
2909
2910 @node Channels
2911 @section Channels
2912
2913 @cindex channels
2914 @cindex @file{channels.scm}, configuration file
2915 @cindex configuration file for channels
2916 @cindex @command{guix pull}, configuration file
2917 @cindex configuration of @command{guix pull}
2918 Guix and its package collection are updated by running @command{guix pull}
2919 (@pxref{Invoking guix pull}). By default @command{guix pull} downloads and
2920 deploys Guix itself from the official GNU@tie{}Guix repository. This can be
2921 customized by defining @dfn{channels} in the
2922 @file{~/.config/guix/channels.scm} file. A channel specifies a URL and branch
2923 of a Git repository to be deployed, and @command{guix pull} can be instructed
2924 to pull from one or more channels. In other words, channels can be used to
2925 @emph{customize} and to @emph{extend} Guix, as we will see below.
2926
2927 @subsection Using a Custom Guix Channel
2928
2929 The channel called @code{guix} specifies where Guix itself---its command-line
2930 tools as well as its package collection---should be downloaded. For instance,
2931 suppose you want to update from your own copy of the Guix repository at
2932 @code{example.org}, and specifically the @code{super-hacks} branch, you can
2933 write in @code{~/.config/guix/channels.scm} this specification:
2934
2935 @lisp
2936 ;; Tell 'guix pull' to use my own repo.
2937 (list (channel
2938 (name 'guix)
2939 (url "https://example.org/my-guix.git")
2940 (branch "super-hacks")))
2941 @end lisp
2942
2943 @noindent
2944 From there on, @command{guix pull} will fetch code from the @code{super-hacks}
2945 branch of the repository at @code{example.org}.
2946
2947 @subsection Specifying Additional Channels
2948
2949 @cindex extending the package collection (channels)
2950 @cindex personal packages (channels)
2951 @cindex channels, for personal packages
2952 You can also specify @emph{additional channels} to pull from. Let's say you
2953 have a bunch of custom package variants or personal packages that you think
2954 would make little sense to contribute to the Guix project, but would like to
2955 have these packages transparently available to you at the command line. You
2956 would first write modules containing those package definitions (@pxref{Package
2957 Modules}), maintain them in a Git repository, and then you and anyone else can
2958 use it as an additional channel to get packages from. Neat, no?
2959
2960 @c What follows stems from discussions at
2961 @c <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=22629#134> as well as
2962 @c earlier discussions on guix-devel@gnu.org.
2963 @quotation Warning
2964 Before you, dear user, shout---``woow this is @emph{soooo coool}!''---and
2965 publish your personal channel to the world, we would like to share a few words
2966 of caution:
2967
2968 @itemize
2969 @item
2970 Before publishing a channel, please consider contributing your package
2971 definitions to Guix proper (@pxref{Contributing}). Guix as a project is open
2972 to free software of all sorts, and packages in Guix proper are readily
2973 available to all Guix users and benefit from the project's quality assurance
2974 process.
2975
2976 @item
2977 When you maintain package definitions outside Guix, we, Guix developers,
2978 consider that @emph{the compatibility burden is on you}. Remember that
2979 package modules and package definitions are just Scheme code that uses various
2980 programming interfaces (APIs). We want to remain free to change these APIs to
2981 keep improving Guix, possibly in ways that break your channel. We never
2982 change APIs gratuitously, but we will @emph{not} commit to freezing APIs
2983 either.
2984
2985 @item
2986 Corollary: if you're using an external channel and that channel breaks, please
2987 @emph{report the issue to the channel authors}, not to the Guix project.
2988 @end itemize
2989
2990 You've been warned! Having said this, we believe external channels are a
2991 practical way to exert your freedom to augment Guix' package collection and to
2992 share your improvements, which are basic tenets of
2993 @uref{https://www.gnu.org/philosophy/free-sw.html, free software}. Please
2994 email us at @email{guix-devel@@gnu.org} if you'd like to discuss this.
2995 @end quotation
2996
2997 Once you have a Git repository containing your own package modules, you can
2998 write @code{~/.config/guix/channels.scm} to instruct @command{guix pull} to
2999 pull from your personal channel @emph{in addition} to the default Guix
3000 channel(s):
3001
3002 @vindex %default-channels
3003 @lisp
3004 ;; Add my personal packages to those Guix provides.
3005 (cons (channel
3006 (name 'my-personal-packages)
3007 (url "https://example.org/personal-packages.git"))
3008 %default-channels)
3009 @end lisp
3010
3011 @noindent
3012 Note that the snippet above is (as always!)@: Scheme code; we use @code{cons} to
3013 add a channel the list of channels that the variable @code{%default-channels}
3014 is bound to (@pxref{Pairs, @code{cons} and lists,, guile, GNU Guile Reference
3015 Manual}). With this file in place, @command{guix pull} builds not only Guix
3016 but also the package modules from your own repository. The result in
3017 @file{~/.config/guix/current} is the union of Guix with your own package
3018 modules:
3019
3020 @example
3021 $ guix pull --list-generations
3022 @dots{}
3023 Generation 19 Aug 27 2018 16:20:48
3024 guix d894ab8
3025 repository URL: https://git.savannah.gnu.org/git/guix.git
3026 branch: master
3027 commit: d894ab8e9bfabcefa6c49d9ba2e834dd5a73a300
3028 my-personal-packages dd3df5e
3029 repository URL: https://example.org/personal-packages.git
3030 branch: master
3031 commit: dd3df5e2c8818760a8fc0bd699e55d3b69fef2bb
3032 11 new packages: my-gimp, my-emacs-with-cool-features, @dots{}
3033 4 packages upgraded: emacs-racket-mode@@0.0.2-2.1b78827, @dots{}
3034 @end example
3035
3036 @noindent
3037 The output of @command{guix pull} above shows that Generation@tie{}19 includes
3038 both Guix and packages from the @code{my-personal-packages} channel. Among
3039 the new and upgraded packages that are listed, some like @code{my-gimp} and
3040 @code{my-emacs-with-cool-features} might come from
3041 @code{my-personal-packages}, while others come from the Guix default channel.
3042
3043 @cindex dependencies, channels
3044 @cindex meta-data, channels
3045 @subsection Declaring Channel Dependencies
3046
3047 Channel authors may decide to augment a package collection provided by other
3048 channels. They can declare their channel to be dependent on other channels in
3049 a meta-data file @file{.guix-channel}, which is to be placed in the root of
3050 the channel repository.
3051
3052 The meta-data file should contain a simple S-expression like this:
3053
3054 @lisp
3055 (channel
3056 (version 0)
3057 (dependencies
3058 (channel
3059 (name some-collection)
3060 (url "https://example.org/first-collection.git"))
3061 (channel
3062 (name some-other-collection)
3063 (url "https://example.org/second-collection.git")
3064 (branch "testing"))))
3065 @end lisp
3066
3067 In the above example this channel is declared to depend on two other channels,
3068 which will both be fetched automatically. The modules provided by the channel
3069 will be compiled in an environment where the modules of all these declared
3070 channels are available.
3071
3072 For the sake of reliability and maintainability, you should avoid dependencies
3073 on channels that you don't control, and you should aim to keep the number of
3074 dependencies to a minimum.
3075
3076 @subsection Replicating Guix
3077
3078 @cindex pinning, channels
3079 @cindex replicating Guix
3080 @cindex reproducibility, of Guix
3081 The @command{guix pull --list-generations} output above shows precisely which
3082 commits were used to build this instance of Guix. We can thus replicate it,
3083 say, on another machine, by providing a channel specification in
3084 @file{~/.config/guix/channels.scm} that is ``pinned'' to these commits:
3085
3086 @lisp
3087 ;; Deploy specific commits of my channels of interest.
3088 (list (channel
3089 (name 'guix)
3090 (url "https://git.savannah.gnu.org/git/guix.git")
3091 (commit "d894ab8e9bfabcefa6c49d9ba2e834dd5a73a300"))
3092 (channel
3093 (name 'my-personal-packages)
3094 (url "https://example.org/personal-packages.git")
3095 (branch "dd3df5e2c8818760a8fc0bd699e55d3b69fef2bb")))
3096 @end lisp
3097
3098 The @command{guix describe --format=channels} command can even generate this
3099 list of channels directly (@pxref{Invoking guix describe}).
3100
3101 At this point the two machines run the @emph{exact same Guix}, with access to
3102 the @emph{exact same packages}. The output of @command{guix build gimp} on
3103 one machine will be exactly the same, bit for bit, as the output of the same
3104 command on the other machine. It also means both machines have access to all
3105 the source code of Guix and, transitively, to all the source code of every
3106 package it defines.
3107
3108 This gives you super powers, allowing you to track the provenance of binary
3109 artifacts with very fine grain, and to reproduce software environments at
3110 will---some sort of ``meta reproducibility'' capabilities, if you will.
3111 @xref{Inferiors}, for another way to take advantage of these super powers.
3112
3113 @node Inferiors
3114 @section Inferiors
3115
3116 @c TODO: Remove this once we're more confident about API stability.
3117 @quotation Note
3118 The functionality described here is a ``technology preview'' as of version
3119 @value{VERSION}. As such, the interface is subject to change.
3120 @end quotation
3121
3122 @cindex inferiors
3123 @cindex composition of Guix revisions
3124 Sometimes you might need to mix packages from the revision of Guix you're
3125 currently running with packages available in a different revision of Guix.
3126 Guix @dfn{inferiors} allow you to achieve that by composing different Guix
3127 revisions in arbitrary ways.
3128
3129 @cindex inferior packages
3130 Technically, an ``inferior'' is essentially a separate Guix process connected
3131 to your main Guix process through a REPL (@pxref{Invoking guix repl}). The
3132 @code{(guix inferior)} module allows you to create inferiors and to
3133 communicate with them. It also provides a high-level interface to browse and
3134 manipulate the packages that an inferior provides---@dfn{inferior packages}.
3135
3136 When combined with channels (@pxref{Channels}), inferiors provide a simple way
3137 to interact with a separate revision of Guix. For example, let's assume you
3138 want to install in your profile the current @code{guile} package, along with
3139 the @code{guile-json} as it existed in an older revision of Guix---perhaps
3140 because the newer @code{guile-json} has an incompatible API and you want to
3141 run your code against the old API@. To do that, you could write a manifest for
3142 use by @code{guix package --manifest} (@pxref{Invoking guix package}); in that
3143 manifest, you would create an inferior for that old Guix revision you care
3144 about, and you would look up the @code{guile-json} package in the inferior:
3145
3146 @lisp
3147 (use-modules (guix inferior) (guix channels)
3148 (srfi srfi-1)) ;for 'first'
3149
3150 (define channels
3151 ;; This is the old revision from which we want to
3152 ;; extract guile-json.
3153 (list (channel
3154 (name 'guix)
3155 (url "https://git.savannah.gnu.org/git/guix.git")
3156 (commit
3157 "65956ad3526ba09e1f7a40722c96c6ef7c0936fe"))))
3158
3159 (define inferior
3160 ;; An inferior representing the above revision.
3161 (inferior-for-channels channels))
3162
3163 ;; Now create a manifest with the current "guile" package
3164 ;; and the old "guile-json" package.
3165 (packages->manifest
3166 (list (first (lookup-inferior-packages inferior "guile-json"))
3167 (specification->package "guile")))
3168 @end lisp
3169
3170 On its first run, @command{guix package --manifest} might have to build the
3171 channel you specified before it can create the inferior; subsequent runs will
3172 be much faster because the Guix revision will be cached.
3173
3174 The @code{(guix inferior)} module provides the following procedures to open an
3175 inferior:
3176
3177 @deffn {Scheme Procedure} inferior-for-channels @var{channels} @
3178 [#:cache-directory] [#:ttl]
3179 Return an inferior for @var{channels}, a list of channels. Use the cache at
3180 @var{cache-directory}, where entries can be reclaimed after @var{ttl} seconds.
3181 This procedure opens a new connection to the build daemon.
3182
3183 As a side effect, this procedure may build or substitute binaries for
3184 @var{channels}, which can take time.
3185 @end deffn
3186
3187 @deffn {Scheme Procedure} open-inferior @var{directory} @
3188 [#:command "bin/guix"]
3189 Open the inferior Guix in @var{directory}, running
3190 @code{@var{directory}/@var{command} repl} or equivalent. Return @code{#f} if
3191 the inferior could not be launched.
3192 @end deffn
3193
3194 @cindex inferior packages
3195 The procedures listed below allow you to obtain and manipulate inferior
3196 packages.
3197
3198 @deffn {Scheme Procedure} inferior-packages @var{inferior}
3199 Return the list of packages known to @var{inferior}.
3200 @end deffn
3201
3202 @deffn {Scheme Procedure} lookup-inferior-packages @var{inferior} @var{name} @
3203 [@var{version}]
3204 Return the sorted list of inferior packages matching @var{name} in
3205 @var{inferior}, with highest version numbers first. If @var{version} is true,
3206 return only packages with a version number prefixed by @var{version}.
3207 @end deffn
3208
3209 @deffn {Scheme Procedure} inferior-package? @var{obj}
3210 Return true if @var{obj} is an inferior package.
3211 @end deffn
3212
3213 @deffn {Scheme Procedure} inferior-package-name @var{package}
3214 @deffnx {Scheme Procedure} inferior-package-version @var{package}
3215 @deffnx {Scheme Procedure} inferior-package-synopsis @var{package}
3216 @deffnx {Scheme Procedure} inferior-package-description @var{package}
3217 @deffnx {Scheme Procedure} inferior-package-home-page @var{package}
3218 @deffnx {Scheme Procedure} inferior-package-location @var{package}
3219 @deffnx {Scheme Procedure} inferior-package-inputs @var{package}
3220 @deffnx {Scheme Procedure} inferior-package-native-inputs @var{package}
3221 @deffnx {Scheme Procedure} inferior-package-propagated-inputs @var{package}
3222 @deffnx {Scheme Procedure} inferior-package-transitive-propagated-inputs @var{package}
3223 @deffnx {Scheme Procedure} inferior-package-native-search-paths @var{package}
3224 @deffnx {Scheme Procedure} inferior-package-transitive-native-search-paths @var{package}
3225 @deffnx {Scheme Procedure} inferior-package-search-paths @var{package}
3226 These procedures are the counterpart of package record accessors
3227 (@pxref{package Reference}). Most of them work by querying the inferior
3228 @var{package} comes from, so the inferior must still be live when you call
3229 these procedures.
3230 @end deffn
3231
3232 Inferior packages can be used transparently like any other package or
3233 file-like object in G-expressions (@pxref{G-Expressions}). They are also
3234 transparently handled by the @code{packages->manifest} procedure, which is
3235 commonly use in manifests (@pxref{Invoking guix package, the
3236 @option{--manifest} option of @command{guix package}}). Thus you can insert
3237 an inferior package pretty much anywhere you would insert a regular package:
3238 in manifests, in the @code{packages} field of your @code{operating-system}
3239 declaration, and so on.
3240
3241 @node Invoking guix describe
3242 @section Invoking @command{guix describe}
3243
3244 @cindex reproducibility
3245 @cindex replicating Guix
3246 Often you may want to answer questions like: ``Which revision of Guix am I
3247 using?'' or ``Which channels am I using?'' This is useful information in many
3248 situations: if you want to @emph{replicate} an environment on a different
3249 machine or user account, if you want to report a bug or to determine what
3250 change in the channels you are using caused it, or if you want to record your
3251 system state for reproducibility purposes. The @command{guix describe}
3252 command answers these questions.
3253
3254 When run from a @command{guix pull}ed @command{guix}, @command{guix describe}
3255 displays the channel(s) that it was built from, including their repository URL
3256 and commit IDs (@pxref{Channels}):
3257
3258 @example
3259 $ guix describe
3260 Generation 10 Sep 03 2018 17:32:44 (current)
3261 guix e0fa68c
3262 repository URL: https://git.savannah.gnu.org/git/guix.git
3263 branch: master
3264 commit: e0fa68c7718fffd33d81af415279d6ddb518f727
3265 @end example
3266
3267 If you're familiar with the Git version control system, this is similar in
3268 spirit to @command{git describe}; the output is also similar to that of
3269 @command{guix pull --list-generations}, but limited to the current generation
3270 (@pxref{Invoking guix pull, the @option{--list-generations} option}). Because
3271 the Git commit ID shown above unambiguously refers to a snapshot of Guix, this
3272 information is all it takes to describe the revision of Guix you're using, and
3273 also to replicate it.
3274
3275 To make it easier to replicate Guix, @command{guix describe} can also be asked
3276 to return a list of channels instead of the human-readable description above:
3277
3278 @example
3279 $ guix describe -f channels
3280 (list (channel
3281 (name 'guix)
3282 (url "https://git.savannah.gnu.org/git/guix.git")
3283 (commit
3284 "e0fa68c7718fffd33d81af415279d6ddb518f727")))
3285 @end example
3286
3287 @noindent
3288 You can save this to a file and feed it to @command{guix pull -C} on some
3289 other machine or at a later point in time, which will instantiate @emph{this
3290 exact Guix revision} (@pxref{Invoking guix pull, the @option{-C} option}).
3291 From there on, since you're able to deploy the same revision of Guix, you can
3292 just as well @emph{replicate a complete software environment}. We humbly
3293 think that this is @emph{awesome}, and we hope you'll like it too!
3294
3295 The details of the options supported by @command{guix describe} are as
3296 follows:
3297
3298 @table @code
3299 @item --format=@var{format}
3300 @itemx -f @var{format}
3301 Produce output in the specified @var{format}, one of:
3302
3303 @table @code
3304 @item human
3305 produce human-readable output;
3306 @item channels
3307 produce a list of channel specifications that can be passed to @command{guix
3308 pull -C} or installed as @file{~/.config/guix/channels.scm} (@pxref{Invoking
3309 guix pull});
3310 @item json
3311 @cindex JSON
3312 produce a list of channel specifications in JSON format;
3313 @item recutils
3314 produce a list of channel specifications in Recutils format.
3315 @end table
3316
3317 @item --profile=@var{profile}
3318 @itemx -p @var{profile}
3319 Display information about @var{profile}.
3320 @end table
3321
3322 @node Invoking guix pack
3323 @section Invoking @command{guix pack}
3324
3325 Occasionally you want to pass software to people who are not (yet!)
3326 lucky enough to be using Guix. You'd tell them to run @command{guix
3327 package -i @var{something}}, but that's not possible in this case. This
3328 is where @command{guix pack} comes in.
3329
3330 @quotation Note
3331 If you are looking for ways to exchange binaries among machines that
3332 already run Guix, @pxref{Invoking guix copy}, @ref{Invoking guix
3333 publish}, and @ref{Invoking guix archive}.
3334 @end quotation
3335
3336 @cindex pack
3337 @cindex bundle
3338 @cindex application bundle
3339 @cindex software bundle
3340 The @command{guix pack} command creates a shrink-wrapped @dfn{pack} or
3341 @dfn{software bundle}: it creates a tarball or some other archive
3342 containing the binaries of the software you're interested in, and all
3343 its dependencies. The resulting archive can be used on any machine that
3344 does not have Guix, and people can run the exact same binaries as those
3345 you have with Guix. The pack itself is created in a bit-reproducible
3346 fashion, so anyone can verify that it really contains the build results
3347 that you pretend to be shipping.
3348
3349 For example, to create a bundle containing Guile, Emacs, Geiser, and all
3350 their dependencies, you can run:
3351
3352 @example
3353 $ guix pack guile emacs geiser
3354 @dots{}
3355 /gnu/store/@dots{}-pack.tar.gz
3356 @end example
3357
3358 The result here is a tarball containing a @file{/gnu/store} directory
3359 with all the relevant packages. The resulting tarball contains a
3360 @dfn{profile} with the three packages of interest; the profile is the
3361 same as would be created by @command{guix package -i}. It is this
3362 mechanism that is used to create Guix's own standalone binary tarball
3363 (@pxref{Binary Installation}).
3364
3365 Users of this pack would have to run
3366 @file{/gnu/store/@dots{}-profile/bin/guile} to run Guile, which you may
3367 find inconvenient. To work around it, you can create, say, a
3368 @file{/opt/gnu/bin} symlink to the profile:
3369
3370 @example
3371 guix pack -S /opt/gnu/bin=bin guile emacs geiser
3372 @end example
3373
3374 @noindent
3375 That way, users can happily type @file{/opt/gnu/bin/guile} and enjoy.
3376
3377 @cindex relocatable binaries, with @command{guix pack}
3378 What if the recipient of your pack does not have root privileges on
3379 their machine, and thus cannot unpack it in the root file system? In
3380 that case, you will want to use the @code{--relocatable} option (see
3381 below). This option produces @dfn{relocatable binaries}, meaning they
3382 they can be placed anywhere in the file system hierarchy: in the example
3383 above, users can unpack your tarball in their home directory and
3384 directly run @file{./opt/gnu/bin/guile}.
3385
3386 @cindex Docker, build an image with guix pack
3387 Alternatively, you can produce a pack in the Docker image format using
3388 the following command:
3389
3390 @example
3391 guix pack -f docker guile emacs geiser
3392 @end example
3393
3394 @noindent
3395 The result is a tarball that can be passed to the @command{docker load}
3396 command. See the
3397 @uref{https://docs.docker.com/engine/reference/commandline/load/, Docker
3398 documentation} for more information.
3399
3400 @cindex Singularity, build an image with guix pack
3401 @cindex SquashFS, build an image with guix pack
3402 Yet another option is to produce a SquashFS image with the following
3403 command:
3404
3405 @example
3406 guix pack -f squashfs guile emacs geiser
3407 @end example
3408
3409 @noindent
3410 The result is a SquashFS file system image that can either be mounted or
3411 directly be used as a file system container image with the
3412 @uref{http://singularity.lbl.gov, Singularity container execution
3413 environment}, using commands like @command{singularity shell} or
3414 @command{singularity exec}.
3415
3416 Several command-line options allow you to customize your pack:
3417
3418 @table @code
3419 @item --format=@var{format}
3420 @itemx -f @var{format}
3421 Produce a pack in the given @var{format}.
3422
3423 The available formats are:
3424
3425 @table @code
3426 @item tarball
3427 This is the default format. It produces a tarball containing all the
3428 specified binaries and symlinks.
3429
3430 @item docker
3431 This produces a tarball that follows the
3432 @uref{https://github.com/docker/docker/blob/master/image/spec/v1.2.md,
3433 Docker Image Specification}.
3434
3435 @item squashfs
3436 This produces a SquashFS image containing all the specified binaries and
3437 symlinks, as well as empty mount points for virtual file systems like
3438 procfs.
3439 @end table
3440
3441 @item --relocatable
3442 @itemx -R
3443 Produce @dfn{relocatable binaries}---i.e., binaries that can be placed
3444 anywhere in the file system hierarchy and run from there. For example,
3445 if you create a pack containing Bash with:
3446
3447 @example
3448 guix pack -R -S /mybin=bin bash
3449 @end example
3450
3451 @noindent
3452 ...@: you can copy that pack to a machine that lacks Guix, and from your
3453 home directory as a normal user, run:
3454
3455 @example
3456 tar xf pack.tar.gz
3457 ./mybin/sh
3458 @end example
3459
3460 @noindent
3461 In that shell, if you type @code{ls /gnu/store}, you'll notice that
3462 @file{/gnu/store} shows up and contains all the dependencies of
3463 @code{bash}, even though the machine actually lacks @file{/gnu/store}
3464 altogether! That is probably the simplest way to deploy Guix-built
3465 software on a non-Guix machine.
3466
3467 There's a gotcha though: this technique relies on the @dfn{user
3468 namespace} feature of the kernel Linux, which allows unprivileged users
3469 to mount or change root. Old versions of Linux did not support it, and
3470 some GNU/Linux distributions turn it off; on these systems, programs
3471 from the pack @emph{will fail to run}, unless they are unpacked in the
3472 root file system.
3473
3474 @item --expression=@var{expr}
3475 @itemx -e @var{expr}
3476 Consider the package @var{expr} evaluates to.
3477
3478 This has the same purpose as the same-named option in @command{guix
3479 build} (@pxref{Additional Build Options, @code{--expression} in
3480 @command{guix build}}).
3481
3482 @item --manifest=@var{file}
3483 @itemx -m @var{file}
3484 Use the packages contained in the manifest object returned by the Scheme
3485 code in @var{file}.
3486
3487 This has a similar purpose as the same-named option in @command{guix
3488 package} (@pxref{profile-manifest, @option{--manifest}}) and uses the
3489 same manifest files. It allows you to define a collection of packages
3490 once and use it both for creating profiles and for creating archives
3491 for use on machines that do not have Guix installed. Note that you can
3492 specify @emph{either} a manifest file @emph{or} a list of packages,
3493 but not both.
3494
3495 @item --system=@var{system}
3496 @itemx -s @var{system}
3497 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
3498 the system type of the build host.
3499
3500 @item --target=@var{triplet}
3501 @cindex cross-compilation
3502 Cross-build for @var{triplet}, which must be a valid GNU triplet, such
3503 as @code{"mips64el-linux-gnu"} (@pxref{Specifying target triplets, GNU
3504 configuration triplets,, autoconf, Autoconf}).
3505
3506 @item --compression=@var{tool}
3507 @itemx -C @var{tool}
3508 Compress the resulting tarball using @var{tool}---one of @code{gzip},
3509 @code{bzip2}, @code{xz}, @code{lzip}, or @code{none} for no compression.
3510
3511 @item --symlink=@var{spec}
3512 @itemx -S @var{spec}
3513 Add the symlinks specified by @var{spec} to the pack. This option can
3514 appear several times.
3515
3516 @var{spec} has the form @code{@var{source}=@var{target}}, where
3517 @var{source} is the symlink that will be created and @var{target} is the
3518 symlink target.
3519
3520 For instance, @code{-S /opt/gnu/bin=bin} creates a @file{/opt/gnu/bin}
3521 symlink pointing to the @file{bin} sub-directory of the profile.
3522
3523 @item --localstatedir
3524 @itemx --profile-name=@var{name}
3525 Include the ``local state directory'', @file{/var/guix}, in the resulting
3526 pack, and notably the @file{/var/guix/profiles/per-user/root/@var{name}}
3527 profile---by default @var{name} is @code{guix-profile}, which corresponds to
3528 @file{~root/.guix-profile}.
3529
3530 @file{/var/guix} contains the store database (@pxref{The Store}) as well
3531 as garbage-collector roots (@pxref{Invoking guix gc}). Providing it in
3532 the pack means that the store is ``complete'' and manageable by Guix;
3533 not providing it pack means that the store is ``dead'': items cannot be
3534 added to it or removed from it after extraction of the pack.
3535
3536 One use case for this is the Guix self-contained binary tarball
3537 (@pxref{Binary Installation}).
3538
3539 @item --bootstrap
3540 Use the bootstrap binaries to build the pack. This option is only
3541 useful to Guix developers.
3542 @end table
3543
3544 In addition, @command{guix pack} supports all the common build options
3545 (@pxref{Common Build Options}) and all the package transformation
3546 options (@pxref{Package Transformation Options}).
3547
3548
3549 @node Invoking guix archive
3550 @section Invoking @command{guix archive}
3551
3552 @cindex @command{guix archive}
3553 @cindex archive
3554 The @command{guix archive} command allows users to @dfn{export} files
3555 from the store into a single archive, and to later @dfn{import} them on
3556 a machine that runs Guix.
3557 In particular, it allows store files to be transferred from one machine
3558 to the store on another machine.
3559
3560 @quotation Note
3561 If you're looking for a way to produce archives in a format suitable for
3562 tools other than Guix, @pxref{Invoking guix pack}.
3563 @end quotation
3564
3565 @cindex exporting store items
3566 To export store files as an archive to standard output, run:
3567
3568 @example
3569 guix archive --export @var{options} @var{specifications}...
3570 @end example
3571
3572 @var{specifications} may be either store file names or package
3573 specifications, as for @command{guix package} (@pxref{Invoking guix
3574 package}). For instance, the following command creates an archive
3575 containing the @code{gui} output of the @code{git} package and the main
3576 output of @code{emacs}:
3577
3578 @example
3579 guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
3580 @end example
3581
3582 If the specified packages are not built yet, @command{guix archive}
3583 automatically builds them. The build process may be controlled with the
3584 common build options (@pxref{Common Build Options}).
3585
3586 To transfer the @code{emacs} package to a machine connected over SSH,
3587 one would run:
3588
3589 @example
3590 guix archive --export -r emacs | ssh the-machine guix archive --import
3591 @end example
3592
3593 @noindent
3594 Similarly, a complete user profile may be transferred from one machine
3595 to another like this:
3596
3597 @example
3598 guix archive --export -r $(readlink -f ~/.guix-profile) | \
3599 ssh the-machine guix-archive --import
3600 @end example
3601
3602 @noindent
3603 However, note that, in both examples, all of @code{emacs} and the
3604 profile as well as all of their dependencies are transferred (due to
3605 @code{-r}), regardless of what is already available in the store on the
3606 target machine. The @code{--missing} option can help figure out which
3607 items are missing from the target store. The @command{guix copy}
3608 command simplifies and optimizes this whole process, so this is probably
3609 what you should use in this case (@pxref{Invoking guix copy}).
3610
3611 @cindex nar, archive format
3612 @cindex normalized archive (nar)
3613 Archives are stored in the ``normalized archive'' or ``nar'' format, which is
3614 comparable in spirit to `tar', but with differences
3615 that make it more appropriate for our purposes. First, rather than
3616 recording all Unix metadata for each file, the nar format only mentions
3617 the file type (regular, directory, or symbolic link); Unix permissions
3618 and owner/group are dismissed. Second, the order in which directory
3619 entries are stored always follows the order of file names according to
3620 the C locale collation order. This makes archive production fully
3621 deterministic.
3622
3623 When exporting, the daemon digitally signs the contents of the archive,
3624 and that digital signature is appended. When importing, the daemon
3625 verifies the signature and rejects the import in case of an invalid
3626 signature or if the signing key is not authorized.
3627 @c FIXME: Add xref to daemon doc about signatures.
3628
3629 The main options are:
3630
3631 @table @code
3632 @item --export
3633 Export the specified store files or packages (see below.) Write the
3634 resulting archive to the standard output.
3635
3636 Dependencies are @emph{not} included in the output, unless
3637 @code{--recursive} is passed.
3638
3639 @item -r
3640 @itemx --recursive
3641 When combined with @code{--export}, this instructs @command{guix
3642 archive} to include dependencies of the given items in the archive.
3643 Thus, the resulting archive is self-contained: it contains the closure
3644 of the exported store items.
3645
3646 @item --import
3647 Read an archive from the standard input, and import the files listed
3648 therein into the store. Abort if the archive has an invalid digital
3649 signature, or if it is signed by a public key not among the authorized
3650 keys (see @code{--authorize} below.)
3651
3652 @item --missing
3653 Read a list of store file names from the standard input, one per line,
3654 and write on the standard output the subset of these files missing from
3655 the store.
3656
3657 @item --generate-key[=@var{parameters}]
3658 @cindex signing, archives
3659 Generate a new key pair for the daemon. This is a prerequisite before
3660 archives can be exported with @code{--export}. Note that this operation
3661 usually takes time, because it needs to gather enough entropy to
3662 generate the key pair.
3663
3664 The generated key pair is typically stored under @file{/etc/guix}, in
3665 @file{signing-key.pub} (public key) and @file{signing-key.sec} (private
3666 key, which must be kept secret.) When @var{parameters} is omitted,
3667 an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
3668 versions before 1.6.0, it is a 4096-bit RSA key.
3669 Alternatively, @var{parameters} can specify
3670 @code{genkey} parameters suitable for Libgcrypt (@pxref{General
3671 public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
3672 Libgcrypt Reference Manual}).
3673
3674 @item --authorize
3675 @cindex authorizing, archives
3676 Authorize imports signed by the public key passed on standard input.
3677 The public key must be in ``s-expression advanced format''---i.e., the
3678 same format as the @file{signing-key.pub} file.
3679
3680 The list of authorized keys is kept in the human-editable file
3681 @file{/etc/guix/acl}. The file contains
3682 @url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
3683 s-expressions''} and is structured as an access-control list in the
3684 @url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
3685 (SPKI)}.
3686
3687 @item --extract=@var{directory}
3688 @itemx -x @var{directory}
3689 Read a single-item archive as served by substitute servers
3690 (@pxref{Substitutes}) and extract it to @var{directory}. This is a
3691 low-level operation needed in only very narrow use cases; see below.
3692
3693 For example, the following command extracts the substitute for Emacs
3694 served by @code{@value{SUBSTITUTE-SERVER}} to @file{/tmp/emacs}:
3695
3696 @example
3697 $ wget -O - \
3698 https://@value{SUBSTITUTE-SERVER}/nar/@dots{}-emacs-24.5 \
3699 | bunzip2 | guix archive -x /tmp/emacs
3700 @end example
3701
3702 Single-item archives are different from multiple-item archives produced
3703 by @command{guix archive --export}; they contain a single store item,
3704 and they do @emph{not} embed a signature. Thus this operation does
3705 @emph{no} signature verification and its output should be considered
3706 unsafe.
3707
3708 The primary purpose of this operation is to facilitate inspection of
3709 archive contents coming from possibly untrusted substitute servers.
3710
3711 @end table
3712
3713 @c *********************************************************************
3714 @node Programming Interface
3715 @chapter Programming Interface
3716
3717 GNU Guix provides several Scheme programming interfaces (APIs) to
3718 define, build, and query packages. The first interface allows users to
3719 write high-level package definitions. These definitions refer to
3720 familiar packaging concepts, such as the name and version of a package,
3721 its build system, and its dependencies. These definitions can then be
3722 turned into concrete build actions.
3723
3724 Build actions are performed by the Guix daemon, on behalf of users. In a
3725 standard setup, the daemon has write access to the store---the
3726 @file{/gnu/store} directory---whereas users do not. The recommended
3727 setup also has the daemon perform builds in chroots, under a specific
3728 build users, to minimize interference with the rest of the system.
3729
3730 @cindex derivation
3731 Lower-level APIs are available to interact with the daemon and the
3732 store. To instruct the daemon to perform a build action, users actually
3733 provide it with a @dfn{derivation}. A derivation is a low-level
3734 representation of the build actions to be taken, and the environment in
3735 which they should occur---derivations are to package definitions what
3736 assembly is to C programs. The term ``derivation'' comes from the fact
3737 that build results @emph{derive} from them.
3738
3739 This chapter describes all these APIs in turn, starting from high-level
3740 package definitions.
3741
3742 @menu
3743 * Defining Packages:: Defining new packages.
3744 * Build Systems:: Specifying how packages are built.
3745 * The Store:: Manipulating the package store.
3746 * Derivations:: Low-level interface to package derivations.
3747 * The Store Monad:: Purely functional interface to the store.
3748 * G-Expressions:: Manipulating build expressions.
3749 * Invoking guix repl:: Fiddling with Guix interactively.
3750 @end menu
3751
3752 @node Defining Packages
3753 @section Defining Packages
3754
3755 The high-level interface to package definitions is implemented in the
3756 @code{(guix packages)} and @code{(guix build-system)} modules. As an
3757 example, the package definition, or @dfn{recipe}, for the GNU Hello
3758 package looks like this:
3759
3760 @example
3761 (define-module (gnu packages hello)
3762 #:use-module (guix packages)
3763 #:use-module (guix download)
3764 #:use-module (guix build-system gnu)
3765 #:use-module (guix licenses)
3766 #:use-module (gnu packages gawk))
3767
3768 (define-public hello
3769 (package
3770 (name "hello")
3771 (version "2.10")
3772 (source (origin
3773 (method url-fetch)
3774 (uri (string-append "mirror://gnu/hello/hello-" version
3775 ".tar.gz"))
3776 (sha256
3777 (base32
3778 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
3779 (build-system gnu-build-system)
3780 (arguments '(#:configure-flags '("--enable-silent-rules")))
3781 (inputs `(("gawk" ,gawk)))
3782 (synopsis "Hello, GNU world: An example GNU package")
3783 (description "Guess what GNU Hello prints!")
3784 (home-page "http://www.gnu.org/software/hello/")
3785 (license gpl3+)))
3786 @end example
3787
3788 @noindent
3789 Without being a Scheme expert, the reader may have guessed the meaning
3790 of the various fields here. This expression binds the variable
3791 @code{hello} to a @code{<package>} object, which is essentially a record
3792 (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
3793 This package object can be inspected using procedures found in the
3794 @code{(guix packages)} module; for instance, @code{(package-name hello)}
3795 returns---surprise!---@code{"hello"}.
3796
3797 With luck, you may be able to import part or all of the definition of
3798 the package you are interested in from another repository, using the
3799 @code{guix import} command (@pxref{Invoking guix import}).
3800
3801 In the example above, @var{hello} is defined in a module of its own,
3802 @code{(gnu packages hello)}. Technically, this is not strictly
3803 necessary, but it is convenient to do so: all the packages defined in
3804 modules under @code{(gnu packages @dots{})} are automatically known to
3805 the command-line tools (@pxref{Package Modules}).
3806
3807 There are a few points worth noting in the above package definition:
3808
3809 @itemize
3810 @item
3811 The @code{source} field of the package is an @code{<origin>} object
3812 (@pxref{origin Reference}, for the complete reference).
3813 Here, the @code{url-fetch} method from @code{(guix download)} is used,
3814 meaning that the source is a file to be downloaded over FTP or HTTP.
3815
3816 The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
3817 the GNU mirrors defined in @code{(guix download)}.
3818
3819 The @code{sha256} field specifies the expected SHA256 hash of the file
3820 being downloaded. It is mandatory, and allows Guix to check the
3821 integrity of the file. The @code{(base32 @dots{})} form introduces the
3822 base32 representation of the hash. You can obtain this information with
3823 @code{guix download} (@pxref{Invoking guix download}) and @code{guix
3824 hash} (@pxref{Invoking guix hash}).
3825
3826 @cindex patches
3827 When needed, the @code{origin} form can also have a @code{patches} field
3828 listing patches to be applied, and a @code{snippet} field giving a
3829 Scheme expression to modify the source code.
3830
3831 @item
3832 @cindex GNU Build System
3833 The @code{build-system} field specifies the procedure to build the
3834 package (@pxref{Build Systems}). Here, @var{gnu-build-system}
3835 represents the familiar GNU Build System, where packages may be
3836 configured, built, and installed with the usual @code{./configure &&
3837 make && make check && make install} command sequence.
3838
3839 @item
3840 The @code{arguments} field specifies options for the build system
3841 (@pxref{Build Systems}). Here it is interpreted by
3842 @var{gnu-build-system} as a request run @file{configure} with the
3843 @code{--enable-silent-rules} flag.
3844
3845 @cindex quote
3846 @cindex quoting
3847 @findex '
3848 @findex quote
3849 What about these quote (@code{'}) characters? They are Scheme syntax to
3850 introduce a literal list; @code{'} is synonymous with @code{quote}.
3851 @xref{Expression Syntax, quoting,, guile, GNU Guile Reference Manual},
3852 for details. Here the value of the @code{arguments} field is a list of
3853 arguments passed to the build system down the road, as with @code{apply}
3854 (@pxref{Fly Evaluation, @code{apply},, guile, GNU Guile Reference
3855 Manual}).
3856
3857 The hash-colon (@code{#:}) sequence defines a Scheme @dfn{keyword}
3858 (@pxref{Keywords,,, guile, GNU Guile Reference Manual}), and
3859 @code{#:configure-flags} is a keyword used to pass a keyword argument
3860 to the build system (@pxref{Coding With Keywords,,, guile, GNU Guile
3861 Reference Manual}).
3862
3863 @item
3864 The @code{inputs} field specifies inputs to the build process---i.e.,
3865 build-time or run-time dependencies of the package. Here, we define an
3866 input called @code{"gawk"} whose value is that of the @var{gawk}
3867 variable; @var{gawk} is itself bound to a @code{<package>} object.
3868
3869 @cindex backquote (quasiquote)
3870 @findex `
3871 @findex quasiquote
3872 @cindex comma (unquote)
3873 @findex ,
3874 @findex unquote
3875 @findex ,@@
3876 @findex unquote-splicing
3877 Again, @code{`} (a backquote, synonymous with @code{quasiquote}) allows
3878 us to introduce a literal list in the @code{inputs} field, while
3879 @code{,} (a comma, synonymous with @code{unquote}) allows us to insert a
3880 value in that list (@pxref{Expression Syntax, unquote,, guile, GNU Guile
3881 Reference Manual}).
3882
3883 Note that GCC, Coreutils, Bash, and other essential tools do not need to
3884 be specified as inputs here. Instead, @var{gnu-build-system} takes care
3885 of ensuring that they are present (@pxref{Build Systems}).
3886
3887 However, any other dependencies need to be specified in the
3888 @code{inputs} field. Any dependency not specified here will simply be
3889 unavailable to the build process, possibly leading to a build failure.
3890 @end itemize
3891
3892 @xref{package Reference}, for a full description of possible fields.
3893
3894 Once a package definition is in place, the
3895 package may actually be built using the @code{guix build} command-line
3896 tool (@pxref{Invoking guix build}), troubleshooting any build failures
3897 you encounter (@pxref{Debugging Build Failures}). You can easily jump back to the
3898 package definition using the @command{guix edit} command
3899 (@pxref{Invoking guix edit}).
3900 @xref{Packaging Guidelines}, for
3901 more information on how to test package definitions, and
3902 @ref{Invoking guix lint}, for information on how to check a definition
3903 for style conformance.
3904 @vindex GUIX_PACKAGE_PATH
3905 Lastly, @pxref{Channels}, for information
3906 on how to extend the distribution by adding your own package definitions
3907 in a ``channel''.
3908
3909 Finally, updating the package definition to a new upstream version
3910 can be partly automated by the @command{guix refresh} command
3911 (@pxref{Invoking guix refresh}).
3912
3913 Behind the scenes, a derivation corresponding to the @code{<package>}
3914 object is first computed by the @code{package-derivation} procedure.
3915 That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
3916 The build actions it prescribes may then be realized by using the
3917 @code{build-derivations} procedure (@pxref{The Store}).
3918
3919 @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
3920 Return the @code{<derivation>} object of @var{package} for @var{system}
3921 (@pxref{Derivations}).
3922
3923 @var{package} must be a valid @code{<package>} object, and @var{system}
3924 must be a string denoting the target system type---e.g.,
3925 @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
3926 must be a connection to the daemon, which operates on the store
3927 (@pxref{The Store}).
3928 @end deffn
3929
3930 @noindent
3931 @cindex cross-compilation
3932 Similarly, it is possible to compute a derivation that cross-builds a
3933 package for some other system:
3934
3935 @deffn {Scheme Procedure} package-cross-derivation @var{store} @
3936 @var{package} @var{target} [@var{system}]
3937 Return the @code{<derivation>} object of @var{package} cross-built from
3938 @var{system} to @var{target}.
3939
3940 @var{target} must be a valid GNU triplet denoting the target hardware
3941 and operating system, such as @code{"mips64el-linux-gnu"}
3942 (@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
3943 Configure and Build System}).
3944 @end deffn
3945
3946 @cindex package transformations
3947 @cindex input rewriting
3948 @cindex dependency tree rewriting
3949 Packages can be manipulated in arbitrary ways. An example of a useful
3950 transformation is @dfn{input rewriting}, whereby the dependency tree of
3951 a package is rewritten by replacing specific inputs by others:
3952
3953 @deffn {Scheme Procedure} package-input-rewriting @var{replacements} @
3954 [@var{rewrite-name}]
3955 Return a procedure that, when passed a package, replaces its direct and
3956 indirect dependencies (but not its implicit inputs) according to
3957 @var{replacements}. @var{replacements} is a list of package pairs; the
3958 first element of each pair is the package to replace, and the second one
3959 is the replacement.
3960
3961 Optionally, @var{rewrite-name} is a one-argument procedure that takes
3962 the name of a package and returns its new name after rewrite.
3963 @end deffn
3964
3965 @noindent
3966 Consider this example:
3967
3968 @example
3969 (define libressl-instead-of-openssl
3970 ;; This is a procedure to replace OPENSSL by LIBRESSL,
3971 ;; recursively.
3972 (package-input-rewriting `((,openssl . ,libressl))))
3973
3974 (define git-with-libressl
3975 (libressl-instead-of-openssl git))
3976 @end example
3977
3978 @noindent
3979 Here we first define a rewriting procedure that replaces @var{openssl}
3980 with @var{libressl}. Then we use it to define a @dfn{variant} of the
3981 @var{git} package that uses @var{libressl} instead of @var{openssl}.
3982 This is exactly what the @option{--with-input} command-line option does
3983 (@pxref{Package Transformation Options, @option{--with-input}}).
3984
3985 A more generic procedure to rewrite a package dependency graph is
3986 @code{package-mapping}: it supports arbitrary changes to nodes in the
3987 graph.
3988
3989 @deffn {Scheme Procedure} package-mapping @var{proc} [@var{cut?}]
3990 Return a procedure that, given a package, applies @var{proc} to all the packages
3991 depended on and returns the resulting package. The procedure stops recursion
3992 when @var{cut?} returns true for a given package.
3993 @end deffn
3994
3995 @menu
3996 * package Reference:: The package data type.
3997 * origin Reference:: The origin data type.
3998 @end menu
3999
4000
4001 @node package Reference
4002 @subsection @code{package} Reference
4003
4004 This section summarizes all the options available in @code{package}
4005 declarations (@pxref{Defining Packages}).
4006
4007 @deftp {Data Type} package
4008 This is the data type representing a package recipe.
4009
4010 @table @asis
4011 @item @code{name}
4012 The name of the package, as a string.
4013
4014 @item @code{version}
4015 The version of the package, as a string.
4016
4017 @item @code{source}
4018 An object telling how the source code for the package should be
4019 acquired. Most of the time, this is an @code{origin} object, which
4020 denotes a file fetched from the Internet (@pxref{origin Reference}). It
4021 can also be any other ``file-like'' object such as a @code{local-file},
4022 which denotes a file from the local file system (@pxref{G-Expressions,
4023 @code{local-file}}).
4024
4025 @item @code{build-system}
4026 The build system that should be used to build the package (@pxref{Build
4027 Systems}).
4028
4029 @item @code{arguments} (default: @code{'()})
4030 The arguments that should be passed to the build system. This is a
4031 list, typically containing sequential keyword-value pairs.
4032
4033 @item @code{inputs} (default: @code{'()})
4034 @itemx @code{native-inputs} (default: @code{'()})
4035 @itemx @code{propagated-inputs} (default: @code{'()})
4036 @cindex inputs, of packages
4037 These fields list dependencies of the package. Each one is a list of
4038 tuples, where each tuple has a label for the input (a string) as its
4039 first element, a package, origin, or derivation as its second element,
4040 and optionally the name of the output thereof that should be used, which
4041 defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
4042 more on package outputs). For example, the list below specifies three
4043 inputs:
4044
4045 @example
4046 `(("libffi" ,libffi)
4047 ("libunistring" ,libunistring)
4048 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
4049 @end example
4050
4051 @cindex cross compilation, package dependencies
4052 The distinction between @code{native-inputs} and @code{inputs} is
4053 necessary when considering cross-compilation. When cross-compiling,
4054 dependencies listed in @code{inputs} are built for the @emph{target}
4055 architecture; conversely, dependencies listed in @code{native-inputs}
4056 are built for the architecture of the @emph{build} machine.
4057
4058 @code{native-inputs} is typically used to list tools needed at
4059 build time, but not at run time, such as Autoconf, Automake, pkg-config,
4060 Gettext, or Bison. @command{guix lint} can report likely mistakes in
4061 this area (@pxref{Invoking guix lint}).
4062
4063 @anchor{package-propagated-inputs}
4064 Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
4065 specified packages will be automatically installed alongside the package
4066 they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
4067 package}}, for information on how @command{guix package} deals with
4068 propagated inputs.)
4069
4070 For example this is necessary when a C/C++ library needs headers of
4071 another library to compile, or when a pkg-config file refers to another
4072 one @i{via} its @code{Requires} field.
4073
4074 Another example where @code{propagated-inputs} is useful is for languages
4075 that lack a facility to record the run-time search path akin to the
4076 @code{RUNPATH} of ELF files; this includes Guile, Python, Perl, and
4077 more. To ensure that libraries written in those languages can find
4078 library code they depend on at run time, run-time dependencies must be
4079 listed in @code{propagated-inputs} rather than @code{inputs}.
4080
4081 @item @code{self-native-input?} (default: @code{#f})
4082 This is a Boolean field telling whether the package should use itself as
4083 a native input when cross-compiling.
4084
4085 @item @code{outputs} (default: @code{'("out")})
4086 The list of output names of the package. @xref{Packages with Multiple
4087 Outputs}, for typical uses of additional outputs.
4088
4089 @item @code{native-search-paths} (default: @code{'()})
4090 @itemx @code{search-paths} (default: @code{'()})
4091 A list of @code{search-path-specification} objects describing
4092 search-path environment variables honored by the package.
4093
4094 @item @code{replacement} (default: @code{#f})
4095 This must be either @code{#f} or a package object that will be used as a
4096 @dfn{replacement} for this package. @xref{Security Updates, grafts},
4097 for details.
4098
4099 @item @code{synopsis}
4100 A one-line description of the package.
4101
4102 @item @code{description}
4103 A more elaborate description of the package.
4104
4105 @item @code{license}
4106 @cindex license, of packages
4107 The license of the package; a value from @code{(guix licenses)},
4108 or a list of such values.
4109
4110 @item @code{home-page}
4111 The URL to the home-page of the package, as a string.
4112
4113 @item @code{supported-systems} (default: @var{%supported-systems})
4114 The list of systems supported by the package, as strings of the form
4115 @code{architecture-kernel}, for example @code{"x86_64-linux"}.
4116
4117 @item @code{maintainers} (default: @code{'()})
4118 The list of maintainers of the package, as @code{maintainer} objects.
4119
4120 @item @code{location} (default: source location of the @code{package} form)
4121 The source location of the package. It is useful to override this when
4122 inheriting from another package, in which case this field is not
4123 automatically corrected.
4124 @end table
4125 @end deftp
4126
4127
4128 @node origin Reference
4129 @subsection @code{origin} Reference
4130
4131 This section summarizes all the options available in @code{origin}
4132 declarations (@pxref{Defining Packages}).
4133
4134 @deftp {Data Type} origin
4135 This is the data type representing a source code origin.
4136
4137 @table @asis
4138 @item @code{uri}
4139 An object containing the URI of the source. The object type depends on
4140 the @code{method} (see below). For example, when using the
4141 @var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
4142 values are: a URL represented as a string, or a list thereof.
4143
4144 @item @code{method}
4145 A procedure that handles the URI.
4146
4147 Examples include:
4148
4149 @table @asis
4150 @item @var{url-fetch} from @code{(guix download)}
4151 download a file from the HTTP, HTTPS, or FTP URL specified in the
4152 @code{uri} field;
4153
4154 @vindex git-fetch
4155 @item @var{git-fetch} from @code{(guix git-download)}
4156 clone the Git version control repository, and check out the revision
4157 specified in the @code{uri} field as a @code{git-reference} object; a
4158 @code{git-reference} looks like this:
4159
4160 @example
4161 (git-reference
4162 (url "git://git.debian.org/git/pkg-shadow/shadow")
4163 (commit "v4.1.5.1"))
4164 @end example
4165 @end table
4166
4167 @item @code{sha256}
4168 A bytevector containing the SHA-256 hash of the source. Typically the
4169 @code{base32} form is used here to generate the bytevector from a
4170 base-32 string.
4171
4172 You can obtain this information using @code{guix download}
4173 (@pxref{Invoking guix download}) or @code{guix hash} (@pxref{Invoking
4174 guix hash}).
4175
4176 @item @code{file-name} (default: @code{#f})
4177 The file name under which the source code should be saved. When this is
4178 @code{#f}, a sensible default value will be used in most cases. In case
4179 the source is fetched from a URL, the file name from the URL will be
4180 used. For version control checkouts, it is recommended to provide the
4181 file name explicitly because the default is not very descriptive.
4182
4183 @item @code{patches} (default: @code{'()})
4184 A list of file names, origins, or file-like objects (@pxref{G-Expressions,
4185 file-like objects}) pointing to patches to be applied to the source.
4186
4187 This list of patches must be unconditional. In particular, it cannot
4188 depend on the value of @code{%current-system} or
4189 @code{%current-target-system}.
4190
4191 @item @code{snippet} (default: @code{#f})
4192 A G-expression (@pxref{G-Expressions}) or S-expression that will be run
4193 in the source directory. This is a convenient way to modify the source,
4194 sometimes more convenient than a patch.
4195
4196 @item @code{patch-flags} (default: @code{'("-p1")})
4197 A list of command-line flags that should be passed to the @code{patch}
4198 command.
4199
4200 @item @code{patch-inputs} (default: @code{#f})
4201 Input packages or derivations to the patching process. When this is
4202 @code{#f}, the usual set of inputs necessary for patching are provided,
4203 such as GNU@tie{}Patch.
4204
4205 @item @code{modules} (default: @code{'()})
4206 A list of Guile modules that should be loaded during the patching
4207 process and while running the code in the @code{snippet} field.
4208
4209 @item @code{patch-guile} (default: @code{#f})
4210 The Guile package that should be used in the patching process. When
4211 this is @code{#f}, a sensible default is used.
4212 @end table
4213 @end deftp
4214
4215
4216 @node Build Systems
4217 @section Build Systems
4218
4219 @cindex build system
4220 Each package definition specifies a @dfn{build system} and arguments for
4221 that build system (@pxref{Defining Packages}). This @code{build-system}
4222 field represents the build procedure of the package, as well as implicit
4223 dependencies of that build procedure.
4224
4225 Build systems are @code{<build-system>} objects. The interface to
4226 create and manipulate them is provided by the @code{(guix build-system)}
4227 module, and actual build systems are exported by specific modules.
4228
4229 @cindex bag (low-level package representation)
4230 Under the hood, build systems first compile package objects to
4231 @dfn{bags}. A @dfn{bag} is like a package, but with less
4232 ornamentation---in other words, a bag is a lower-level representation of
4233 a package, which includes all the inputs of that package, including some
4234 that were implicitly added by the build system. This intermediate
4235 representation is then compiled to a derivation (@pxref{Derivations}).
4236
4237 Build systems accept an optional list of @dfn{arguments}. In package
4238 definitions, these are passed @i{via} the @code{arguments} field
4239 (@pxref{Defining Packages}). They are typically keyword arguments
4240 (@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
4241 Guile Reference Manual}). The value of these arguments is usually
4242 evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
4243 by the daemon (@pxref{Derivations}).
4244
4245 The main build system is @var{gnu-build-system}, which implements the
4246 standard build procedure for GNU and many other packages. It
4247 is provided by the @code{(guix build-system gnu)} module.
4248
4249 @defvr {Scheme Variable} gnu-build-system
4250 @var{gnu-build-system} represents the GNU Build System, and variants
4251 thereof (@pxref{Configuration, configuration and makefile conventions,,
4252 standards, GNU Coding Standards}).
4253
4254 @cindex build phases
4255 In a nutshell, packages using it are configured, built, and installed with
4256 the usual @code{./configure && make && make check && make install}
4257 command sequence. In practice, a few additional steps are often needed.
4258 All these steps are split up in separate @dfn{phases},
4259 notably@footnote{Please see the @code{(guix build gnu-build-system)}
4260 modules for more details about the build phases.}:
4261
4262 @table @code
4263 @item unpack
4264 Unpack the source tarball, and change the current directory to the
4265 extracted source tree. If the source is actually a directory, copy it
4266 to the build tree, and enter that directory.
4267
4268 @item patch-source-shebangs
4269 Patch shebangs encountered in source files so they refer to the right
4270 store file names. For instance, this changes @code{#!/bin/sh} to
4271 @code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
4272
4273 @item configure
4274 Run the @file{configure} script with a number of default options, such
4275 as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
4276 by the @code{#:configure-flags} argument.
4277
4278 @item build
4279 Run @code{make} with the list of flags specified with
4280 @code{#:make-flags}. If the @code{#:parallel-build?} argument is true
4281 (the default), build with @code{make -j}.
4282
4283 @item check
4284 Run @code{make check}, or some other target specified with
4285 @code{#:test-target}, unless @code{#:tests? #f} is passed. If the
4286 @code{#:parallel-tests?} argument is true (the default), run @code{make
4287 check -j}.
4288
4289 @item install
4290 Run @code{make install} with the flags listed in @code{#:make-flags}.
4291
4292 @item patch-shebangs
4293 Patch shebangs on the installed executable files.
4294
4295 @item strip
4296 Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
4297 is false), copying them to the @code{debug} output when available
4298 (@pxref{Installing Debugging Files}).
4299 @end table
4300
4301 @vindex %standard-phases
4302 The build-side module @code{(guix build gnu-build-system)} defines
4303 @var{%standard-phases} as the default list of build phases.
4304 @var{%standard-phases} is a list of symbol/procedure pairs, where the
4305 procedure implements the actual phase.
4306
4307 The list of phases used for a particular package can be changed with the
4308 @code{#:phases} parameter. For instance, passing:
4309
4310 @example
4311 #:phases (modify-phases %standard-phases (delete 'configure))
4312 @end example
4313
4314 means that all the phases described above will be used, except the
4315 @code{configure} phase.
4316
4317 In addition, this build system ensures that the ``standard'' environment
4318 for GNU packages is available. This includes tools such as GCC, libc,
4319 Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
4320 build-system gnu)} module for a complete list). We call these the
4321 @dfn{implicit inputs} of a package, because package definitions do not
4322 have to mention them.
4323 @end defvr
4324
4325 Other @code{<build-system>} objects are defined to support other
4326 conventions and tools used by free software packages. They inherit most
4327 of @var{gnu-build-system}, and differ mainly in the set of inputs
4328 implicitly added to the build process, and in the list of phases
4329 executed. Some of these build systems are listed below.
4330
4331 @defvr {Scheme Variable} ant-build-system
4332 This variable is exported by @code{(guix build-system ant)}. It
4333 implements the build procedure for Java packages that can be built with
4334 @url{http://ant.apache.org/, Ant build tool}.
4335
4336 It adds both @code{ant} and the @dfn{Java Development Kit} (JDK) as
4337 provided by the @code{icedtea} package to the set of inputs. Different
4338 packages can be specified with the @code{#:ant} and @code{#:jdk}
4339 parameters, respectively.
4340
4341 When the original package does not provide a suitable Ant build file,
4342 the parameter @code{#:jar-name} can be used to generate a minimal Ant
4343 build file @file{build.xml} with tasks to build the specified jar
4344 archive. In this case the parameter @code{#:source-dir} can be used to
4345 specify the source sub-directory, defaulting to ``src''.
4346
4347 The @code{#:main-class} parameter can be used with the minimal ant
4348 buildfile to specify the main class of the resulting jar. This makes the
4349 jar file executable. The @code{#:test-include} parameter can be used to
4350 specify the list of junit tests to run. It defaults to
4351 @code{(list "**/*Test.java")}. The @code{#:test-exclude} can be used to
4352 disable some tests. It defaults to @code{(list "**/Abstract*.java")},
4353 because abstract classes cannot be run as tests.
4354
4355 The parameter @code{#:build-target} can be used to specify the Ant task
4356 that should be run during the @code{build} phase. By default the
4357 ``jar'' task will be run.
4358
4359 @end defvr
4360
4361 @defvr {Scheme Variable} android-ndk-build-system
4362 @cindex Android distribution
4363 @cindex Android NDK build system
4364 This variable is exported by @code{(guix build-system android-ndk)}. It
4365 implements a build procedure for Android NDK (native development kit)
4366 packages using a Guix-specific build process.
4367
4368 The build system assumes that packages install their public interface
4369 (header) files to the subdirectory "include" of the "out" output and
4370 their libraries to the subdirectory "lib" of the "out" output.
4371
4372 It's also assumed that the union of all the dependencies of a package
4373 has no conflicting files.
4374
4375 For the time being, cross-compilation is not supported - so right now
4376 the libraries and header files are assumed to be host tools.
4377
4378 @end defvr
4379
4380 @defvr {Scheme Variable} asdf-build-system/source
4381 @defvrx {Scheme Variable} asdf-build-system/sbcl
4382 @defvrx {Scheme Variable} asdf-build-system/ecl
4383
4384 These variables, exported by @code{(guix build-system asdf)}, implement
4385 build procedures for Common Lisp packages using
4386 @url{https://common-lisp.net/project/asdf/, ``ASDF''}. ASDF is a system
4387 definition facility for Common Lisp programs and libraries.
4388
4389 The @code{asdf-build-system/source} system installs the packages in
4390 source form, and can be loaded using any common lisp implementation, via
4391 ASDF. The others, such as @code{asdf-build-system/sbcl}, install binary
4392 systems in the format which a particular implementation understands.
4393 These build systems can also be used to produce executable programs, or
4394 lisp images which contain a set of packages pre-loaded.
4395
4396 The build system uses naming conventions. For binary packages, the
4397 package name should be prefixed with the lisp implementation, such as
4398 @code{sbcl-} for @code{asdf-build-system/sbcl}.
4399
4400 Additionally, the corresponding source package should be labeled using
4401 the same convention as python packages (see @ref{Python Modules}), using
4402 the @code{cl-} prefix.
4403
4404 For binary packages, each system should be defined as a Guix package.
4405 If one package @code{origin} contains several systems, package variants
4406 can be created in order to build all the systems. Source packages,
4407 which use @code{asdf-build-system/source}, may contain several systems.
4408
4409 In order to create executable programs and images, the build-side
4410 procedures @code{build-program} and @code{build-image} can be used.
4411 They should be called in a build phase after the @code{create-symlinks}
4412 phase, so that the system which was just built can be used within the
4413 resulting image. @code{build-program} requires a list of Common Lisp
4414 expressions to be passed as the @code{#:entry-program} argument.
4415
4416 If the system is not defined within its own @code{.asd} file of the same
4417 name, then the @code{#:asd-file} parameter should be used to specify
4418 which file the system is defined in. Furthermore, if the package
4419 defines a system for its tests in a separate file, it will be loaded
4420 before the tests are run if it is specified by the
4421 @code{#:test-asd-file} parameter. If it is not set, the files
4422 @code{<system>-tests.asd}, @code{<system>-test.asd}, @code{tests.asd},
4423 and @code{test.asd} will be tried if they exist.
4424
4425 If for some reason the package must be named in a different way than the
4426 naming conventions suggest, the @code{#:asd-system-name} parameter can
4427 be used to specify the name of the system.
4428
4429 @end defvr
4430
4431 @defvr {Scheme Variable} cargo-build-system
4432 @cindex Rust programming language
4433 @cindex Cargo (Rust build system)
4434 This variable is exported by @code{(guix build-system cargo)}. It
4435 supports builds of packages using Cargo, the build tool of the
4436 @uref{https://www.rust-lang.org, Rust programming language}.
4437
4438 In its @code{configure} phase, this build system replaces dependencies
4439 specified in the @file{Carto.toml} file with inputs to the Guix package.
4440 The @code{install} phase installs the binaries, and it also installs the
4441 source code and @file{Cargo.toml} file.
4442 @end defvr
4443
4444 @cindex Clojure (programming language)
4445 @cindex simple Clojure build system
4446 @defvr {Scheme Variable} clojure-build-system
4447 This variable is exported by @code{(guix build-system clojure)}. It implements
4448 a simple build procedure for @uref{https://clojure.org/, Clojure} packages
4449 using plain old @code{compile} in Clojure. Cross-compilation is not supported
4450 yet.
4451
4452 It adds @code{clojure}, @code{icedtea} and @code{zip} to the set of inputs.
4453 Different packages can be specified with the @code{#:clojure}, @code{#:jdk} and
4454 @code{#:zip} parameters, respectively.
4455
4456 A list of source directories, test directories and jar names can be specified
4457 with the @code{#:source-dirs}, @code{#:test-dirs} and @code{#:jar-names}
4458 parameters, respectively. Compile directory and main class can be specified
4459 with the @code{#:compile-dir} and @code{#:main-class} parameters, respectively.
4460 Other parameters are documented below.
4461
4462 This build system is an extension of @var{ant-build-system}, but with the
4463 following phases changed:
4464
4465 @table @code
4466
4467 @item build
4468 This phase calls @code{compile} in Clojure to compile source files and runs
4469 @command{jar} to create jars from both source files and compiled files
4470 according to the include list and exclude list specified in
4471 @code{#:aot-include} and @code{#:aot-exclude}, respectively. The exclude list
4472 has priority over the include list. These lists consist of symbols
4473 representing Clojure libraries or the special keyword @code{#:all} representing
4474 all Clojure libraries found under the source directories. The parameter
4475 @code{#:omit-source?} decides if source should be included into the jars.
4476
4477 @item check
4478 This phase runs tests according to the include list and exclude list specified
4479 in @code{#:test-include} and @code{#:test-exclude}, respectively. Their
4480 meanings are analogous to that of @code{#:aot-include} and
4481 @code{#:aot-exclude}, except that the special keyword @code{#:all} now
4482 stands for all Clojure libraries found under the test directories. The
4483 parameter @code{#:tests?} decides if tests should be run.
4484
4485 @item install
4486 This phase installs all jars built previously.
4487 @end table
4488
4489 Apart from the above, this build system also contains an additional phase:
4490
4491 @table @code
4492
4493 @item install-doc
4494 This phase installs all top-level files with base name matching
4495 @var{%doc-regex}. A different regex can be specified with the
4496 @code{#:doc-regex} parameter. All files (recursively) inside the documentation
4497 directories specified in @code{#:doc-dirs} are installed as well.
4498 @end table
4499 @end defvr
4500
4501 @defvr {Scheme Variable} cmake-build-system
4502 This variable is exported by @code{(guix build-system cmake)}. It
4503 implements the build procedure for packages using the
4504 @url{http://www.cmake.org, CMake build tool}.
4505
4506 It automatically adds the @code{cmake} package to the set of inputs.
4507 Which package is used can be specified with the @code{#:cmake}
4508 parameter.
4509
4510 The @code{#:configure-flags} parameter is taken as a list of flags
4511 passed to the @command{cmake} command. The @code{#:build-type}
4512 parameter specifies in abstract terms the flags passed to the compiler;
4513 it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
4514 debugging information''), which roughly means that code is compiled with
4515 @code{-O2 -g}, as is the case for Autoconf-based packages by default.
4516 @end defvr
4517
4518 @defvr {Scheme Variable} dune-build-system
4519 This variable is exported by @code{(guix build-system dune)}. It
4520 supports builds of packages using @uref{https://dune.build/, Dune}, a build
4521 tool for the OCaml programming language. It is implemented as an extension
4522 of the @code{ocaml-build-system} which is described below. As such, the
4523 @code{#:ocaml} and @code{#:findlib} parameters can be passed to this build
4524 system.
4525
4526 It automatically adds the @code{dune} package to the set of inputs.
4527 Which package is used can be specified with the @code{#:dune}
4528 parameter.
4529
4530 There is no @code{configure} phase because dune packages typically don't
4531 need to be configured. The @code{#:build-flags} parameter is taken as a
4532 list of flags passed to the @code{dune} command during the build.
4533
4534 The @code{#:jbuild?} parameter can be passed to use the @code{jbuild}
4535 command instead of the more recent @code{dune} command while building
4536 a package. Its default value is @code{#f}.
4537 @end defvr
4538
4539 @defvr {Scheme Variable} go-build-system
4540 This variable is exported by @code{(guix build-system go)}. It
4541 implements a build procedure for Go packages using the standard
4542 @url{https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies,
4543 Go build mechanisms}.
4544
4545 The user is expected to provide a value for the key @code{#:import-path}
4546 and, in some cases, @code{#:unpack-path}. The
4547 @url{https://golang.org/doc/code.html#ImportPaths, import path}
4548 corresponds to the file system path expected by the package's build
4549 scripts and any referring packages, and provides a unique way to
4550 refer to a Go package. It is typically based on a combination of the
4551 package source code's remote URI and file system hierarchy structure. In
4552 some cases, you will need to unpack the package's source code to a
4553 different directory structure than the one indicated by the import path,
4554 and @code{#:unpack-path} should be used in such cases.
4555
4556 Packages that provide Go libraries should be installed along with their
4557 source code. The key @code{#:install-source?}, which defaults to
4558 @code{#t}, controls whether or not the source code is installed. It can
4559 be set to @code{#f} for packages that only provide executable files.
4560 @end defvr
4561
4562 @defvr {Scheme Variable} glib-or-gtk-build-system
4563 This variable is exported by @code{(guix build-system glib-or-gtk)}. It
4564 is intended for use with packages making use of GLib or GTK+.
4565
4566 This build system adds the following two phases to the ones defined by
4567 @var{gnu-build-system}:
4568
4569 @table @code
4570 @item glib-or-gtk-wrap
4571 The phase @code{glib-or-gtk-wrap} ensures that programs in
4572 @file{bin/} are able to find GLib ``schemas'' and
4573 @uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
4574 modules}. This is achieved by wrapping the programs in launch scripts
4575 that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
4576 environment variables.
4577
4578 It is possible to exclude specific package outputs from that wrapping
4579 process by listing their names in the
4580 @code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
4581 when an output is known not to contain any GLib or GTK+ binaries, and
4582 where wrapping would gratuitously add a dependency of that output on
4583 GLib and GTK+.
4584
4585 @item glib-or-gtk-compile-schemas
4586 The phase @code{glib-or-gtk-compile-schemas} makes sure that all
4587 @uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
4588 GSettings schemas} of GLib are compiled. Compilation is performed by the
4589 @command{glib-compile-schemas} program. It is provided by the package
4590 @code{glib:bin} which is automatically imported by the build system.
4591 The @code{glib} package providing @command{glib-compile-schemas} can be
4592 specified with the @code{#:glib} parameter.
4593 @end table
4594
4595 Both phases are executed after the @code{install} phase.
4596 @end defvr
4597
4598 @defvr {Scheme Variable} guile-build-system
4599 This build system is for Guile packages that consist exclusively of Scheme
4600 code and that are so lean that they don't even have a makefile, let alone a
4601 @file{configure} script. It compiles Scheme code using @command{guild
4602 compile} (@pxref{Compilation,,, guile, GNU Guile Reference Manual}) and
4603 installs the @file{.scm} and @file{.go} files in the right place. It also
4604 installs documentation.
4605
4606 This build system supports cross-compilation by using the @code{--target}
4607 option of @command{guild compile}.
4608
4609 Packages built with @code{guile-build-system} must provide a Guile package in
4610 their @code{native-inputs} field.
4611 @end defvr
4612
4613 @defvr {Scheme Variable} minify-build-system
4614 This variable is exported by @code{(guix build-system minify)}. It
4615 implements a minification procedure for simple JavaScript packages.
4616
4617 It adds @code{uglify-js} to the set of inputs and uses it to compress
4618 all JavaScript files in the @file{src} directory. A different minifier
4619 package can be specified with the @code{#:uglify-js} parameter, but it
4620 is expected that the package writes the minified code to the standard
4621 output.
4622
4623 When the input JavaScript files are not all located in the @file{src}
4624 directory, the parameter @code{#:javascript-files} can be used to
4625 specify a list of file names to feed to the minifier.
4626 @end defvr
4627
4628 @defvr {Scheme Variable} ocaml-build-system
4629 This variable is exported by @code{(guix build-system ocaml)}. It implements
4630 a build procedure for @uref{https://ocaml.org, OCaml} packages, which consists
4631 of choosing the correct set of commands to run for each package. OCaml
4632 packages can expect many different commands to be run. This build system will
4633 try some of them.
4634
4635 When the package has a @file{setup.ml} file present at the top-level, it will
4636 run @code{ocaml setup.ml -configure}, @code{ocaml setup.ml -build} and
4637 @code{ocaml setup.ml -install}. The build system will assume that this file
4638 was generated by @uref{http://oasis.forge.ocamlcore.org/, OASIS} and will take
4639 care of setting the prefix and enabling tests if they are not disabled. You
4640 can pass configure and build flags with the @code{#:configure-flags} and
4641 @code{#:build-flags}. The @code{#:test-flags} key can be passed to change the
4642 set of flags used to enable tests. The @code{#:use-make?} key can be used to
4643 bypass this system in the build and install phases.
4644
4645 When the package has a @file{configure} file, it is assumed that it is a
4646 hand-made configure script that requires a different argument format than
4647 in the @code{gnu-build-system}. You can add more flags with the
4648 @code{#:configure-flags} key.
4649
4650 When the package has a @file{Makefile} file (or @code{#:use-make?} is
4651 @code{#t}), it will be used and more flags can be passed to the build and
4652 install phases with the @code{#:make-flags} key.
4653
4654 Finally, some packages do not have these files and use a somewhat standard
4655 location for its build system. In that case, the build system will run
4656 @code{ocaml pkg/pkg.ml} or @code{ocaml pkg/build.ml} and take care of
4657 providing the path to the required findlib module. Additional flags can
4658 be passed via the @code{#:build-flags} key. Install is taken care of by
4659 @command{opam-installer}. In this case, the @code{opam} package must
4660 be added to the @code{native-inputs} field of the package definition.
4661
4662 Note that most OCaml packages assume they will be installed in the same
4663 directory as OCaml, which is not what we want in guix. In particular, they
4664 will install @file{.so} files in their module's directory, which is usually
4665 fine because it is in the OCaml compiler directory. In guix though, these
4666 libraries cannot be found and we use @code{CAML_LD_LIBRARY_PATH}. This
4667 variable points to @file{lib/ocaml/site-lib/stubslibs} and this is where
4668 @file{.so} libraries should be installed.
4669 @end defvr
4670
4671 @defvr {Scheme Variable} python-build-system
4672 This variable is exported by @code{(guix build-system python)}. It
4673 implements the more or less standard build procedure used by Python
4674 packages, which consists in running @code{python setup.py build} and
4675 then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
4676
4677 For packages that install stand-alone Python programs under @code{bin/},
4678 it takes care of wrapping these programs so that their @code{PYTHONPATH}
4679 environment variable points to all the Python libraries they depend on.
4680
4681 Which Python package is used to perform the build can be specified with
4682 the @code{#:python} parameter. This is a useful way to force a package
4683 to be built for a specific version of the Python interpreter, which
4684 might be necessary if the package is only compatible with a single
4685 interpreter version.
4686
4687 By default guix calls @code{setup.py} under control of
4688 @code{setuptools}, much like @command{pip} does. Some packages are not
4689 compatible with setuptools (and pip), thus you can disable this by
4690 setting the @code{#:use-setuptools} parameter to @code{#f}.
4691 @end defvr
4692
4693 @defvr {Scheme Variable} perl-build-system
4694 This variable is exported by @code{(guix build-system perl)}. It
4695 implements the standard build procedure for Perl packages, which either
4696 consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
4697 followed by @code{Build} and @code{Build install}; or in running
4698 @code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
4699 @code{make} and @code{make install}, depending on which of
4700 @code{Build.PL} or @code{Makefile.PL} is present in the package
4701 distribution. Preference is given to the former if both @code{Build.PL}
4702 and @code{Makefile.PL} exist in the package distribution. This
4703 preference can be reversed by specifying @code{#t} for the
4704 @code{#:make-maker?} parameter.
4705
4706 The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
4707 passes flags specified by the @code{#:make-maker-flags} or
4708 @code{#:module-build-flags} parameter, respectively.
4709
4710 Which Perl package is used can be specified with @code{#:perl}.
4711 @end defvr
4712
4713 @defvr {Scheme Variable} r-build-system
4714 This variable is exported by @code{(guix build-system r)}. It
4715 implements the build procedure used by @uref{http://r-project.org, R}
4716 packages, which essentially is little more than running @code{R CMD
4717 INSTALL --library=/gnu/store/@dots{}} in an environment where
4718 @code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
4719 are run after installation using the R function
4720 @code{tools::testInstalledPackage}.
4721 @end defvr
4722
4723 @defvr {Scheme Variable} texlive-build-system
4724 This variable is exported by @code{(guix build-system texlive)}. It is
4725 used to build TeX packages in batch mode with a specified engine. The
4726 build system sets the @code{TEXINPUTS} variable to find all TeX source
4727 files in the inputs.
4728
4729 By default it runs @code{luatex} on all files ending on @code{ins}. A
4730 different engine and format can be specified with the
4731 @code{#:tex-format} argument. Different build targets can be specified
4732 with the @code{#:build-targets} argument, which expects a list of file
4733 names. The build system adds only @code{texlive-bin} and
4734 @code{texlive-latex-base} (both from @code{(gnu packages tex}) to the
4735 inputs. Both can be overridden with the arguments @code{#:texlive-bin}
4736 and @code{#:texlive-latex-base}, respectively.
4737
4738 The @code{#:tex-directory} parameter tells the build system where to
4739 install the built files under the texmf tree.
4740 @end defvr
4741
4742 @defvr {Scheme Variable} ruby-build-system
4743 This variable is exported by @code{(guix build-system ruby)}. It
4744 implements the RubyGems build procedure used by Ruby packages, which
4745 involves running @code{gem build} followed by @code{gem install}.
4746
4747 The @code{source} field of a package that uses this build system
4748 typically references a gem archive, since this is the format that Ruby
4749 developers use when releasing their software. The build system unpacks
4750 the gem archive, potentially patches the source, runs the test suite,
4751 repackages the gem, and installs it. Additionally, directories and
4752 tarballs may be referenced to allow building unreleased gems from Git or
4753 a traditional source release tarball.
4754
4755 Which Ruby package is used can be specified with the @code{#:ruby}
4756 parameter. A list of additional flags to be passed to the @command{gem}
4757 command can be specified with the @code{#:gem-flags} parameter.
4758 @end defvr
4759
4760 @defvr {Scheme Variable} waf-build-system
4761 This variable is exported by @code{(guix build-system waf)}. It
4762 implements a build procedure around the @code{waf} script. The common
4763 phases---@code{configure}, @code{build}, and @code{install}---are
4764 implemented by passing their names as arguments to the @code{waf}
4765 script.
4766
4767 The @code{waf} script is executed by the Python interpreter. Which
4768 Python package is used to run the script can be specified with the
4769 @code{#:python} parameter.
4770 @end defvr
4771
4772 @defvr {Scheme Variable} scons-build-system
4773 This variable is exported by @code{(guix build-system scons)}. It
4774 implements the build procedure used by the SCons software construction
4775 tool. This build system runs @code{scons} to build the package,
4776 @code{scons test} to run tests, and then @code{scons install} to install
4777 the package.
4778
4779 Additional flags to be passed to @code{scons} can be specified with the
4780 @code{#:scons-flags} parameter. The version of Python used to run SCons
4781 can be specified by selecting the appropriate SCons package with the
4782 @code{#:scons} parameter.
4783 @end defvr
4784
4785 @defvr {Scheme Variable} haskell-build-system
4786 This variable is exported by @code{(guix build-system haskell)}. It
4787 implements the Cabal build procedure used by Haskell packages, which
4788 involves running @code{runhaskell Setup.hs configure
4789 --prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
4790 Instead of installing the package by running @code{runhaskell Setup.hs
4791 install}, to avoid trying to register libraries in the read-only
4792 compiler store directory, the build system uses @code{runhaskell
4793 Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
4794 addition, the build system generates the package documentation by
4795 running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
4796 is passed. Optional Haddock parameters can be passed with the help of
4797 the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
4798 not found, the build system looks for @code{Setup.lhs} instead.
4799
4800 Which Haskell compiler is used can be specified with the @code{#:haskell}
4801 parameter which defaults to @code{ghc}.
4802 @end defvr
4803
4804 @defvr {Scheme Variable} dub-build-system
4805 This variable is exported by @code{(guix build-system dub)}. It
4806 implements the Dub build procedure used by D packages, which
4807 involves running @code{dub build} and @code{dub run}.
4808 Installation is done by copying the files manually.
4809
4810 Which D compiler is used can be specified with the @code{#:ldc}
4811 parameter which defaults to @code{ldc}.
4812 @end defvr
4813
4814 @defvr {Scheme Variable} emacs-build-system
4815 This variable is exported by @code{(guix build-system emacs)}. It
4816 implements an installation procedure similar to the packaging system
4817 of Emacs itself (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4818
4819 It first creates the @code{@var{package}-autoloads.el} file, then it
4820 byte compiles all Emacs Lisp files. Differently from the Emacs
4821 packaging system, the Info documentation files are moved to the standard
4822 documentation directory and the @file{dir} file is deleted. Each
4823 package is installed in its own directory under
4824 @file{share/emacs/site-lisp/guix.d}.
4825 @end defvr
4826
4827 @defvr {Scheme Variable} font-build-system
4828 This variable is exported by @code{(guix build-system font)}. It
4829 implements an installation procedure for font packages where upstream
4830 provides pre-compiled TrueType, OpenType, etc.@: font files that merely
4831 need to be copied into place. It copies font files to standard
4832 locations in the output directory.
4833 @end defvr
4834
4835 @defvr {Scheme Variable} meson-build-system
4836 This variable is exported by @code{(guix build-system meson)}. It
4837 implements the build procedure for packages that use
4838 @url{http://mesonbuild.com, Meson} as their build system.
4839
4840 It adds both Meson and @uref{https://ninja-build.org/, Ninja} to the set
4841 of inputs, and they can be changed with the parameters @code{#:meson}
4842 and @code{#:ninja} if needed. The default Meson is
4843 @code{meson-for-build}, which is special because it doesn't clear the
4844 @code{RUNPATH} of binaries and libraries when they are installed.
4845
4846 This build system is an extension of @var{gnu-build-system}, but with the
4847 following phases changed to some specific for Meson:
4848
4849 @table @code
4850
4851 @item configure
4852 The phase runs @code{meson} with the flags specified in
4853 @code{#:configure-flags}. The flag @code{--build-type} is always set to
4854 @code{plain} unless something else is specified in @code{#:build-type}.
4855
4856 @item build
4857 The phase runs @code{ninja} to build the package in parallel by default, but
4858 this can be changed with @code{#:parallel-build?}.
4859
4860 @item check
4861 The phase runs @code{ninja} with the target specified in @code{#:test-target},
4862 which is @code{"test"} by default.
4863
4864 @item install
4865 The phase runs @code{ninja install} and can not be changed.
4866 @end table
4867
4868 Apart from that, the build system also adds the following phases:
4869
4870 @table @code
4871
4872 @item fix-runpath
4873 This phase ensures that all binaries can find the libraries they need.
4874 It searches for required libraries in subdirectories of the package being
4875 built, and adds those to @code{RUNPATH} where needed. It also removes
4876 references to libraries left over from the build phase by
4877 @code{meson-for-build}, such as test dependencies, that aren't actually
4878 required for the program to run.
4879
4880 @item glib-or-gtk-wrap
4881 This phase is the phase provided by @code{glib-or-gtk-build-system}, and it
4882 is not enabled by default. It can be enabled with @code{#:glib-or-gtk?}.
4883
4884 @item glib-or-gtk-compile-schemas
4885 This phase is the phase provided by @code{glib-or-gtk-build-system}, and it
4886 is not enabled by default. It can be enabled with @code{#:glib-or-gtk?}.
4887 @end table
4888 @end defvr
4889
4890 Lastly, for packages that do not need anything as sophisticated, a
4891 ``trivial'' build system is provided. It is trivial in the sense that
4892 it provides basically no support: it does not pull any implicit inputs,
4893 and does not have a notion of build phases.
4894
4895 @defvr {Scheme Variable} trivial-build-system
4896 This variable is exported by @code{(guix build-system trivial)}.
4897
4898 This build system requires a @code{#:builder} argument. This argument
4899 must be a Scheme expression that builds the package output(s)---as
4900 with @code{build-expression->derivation} (@pxref{Derivations,
4901 @code{build-expression->derivation}}).
4902 @end defvr
4903
4904 @node The Store
4905 @section The Store
4906
4907 @cindex store
4908 @cindex store items
4909 @cindex store paths
4910
4911 Conceptually, the @dfn{store} is the place where derivations that have
4912 been built successfully are stored---by default, @file{/gnu/store}.
4913 Sub-directories in the store are referred to as @dfn{store items} or
4914 sometimes @dfn{store paths}. The store has an associated database that
4915 contains information such as the store paths referred to by each store
4916 path, and the list of @emph{valid} store items---results of successful
4917 builds. This database resides in @file{@var{localstatedir}/guix/db},
4918 where @var{localstatedir} is the state directory specified @i{via}
4919 @option{--localstatedir} at configure time, usually @file{/var}.
4920
4921 The store is @emph{always} accessed by the daemon on behalf of its clients
4922 (@pxref{Invoking guix-daemon}). To manipulate the store, clients
4923 connect to the daemon over a Unix-domain socket, send requests to it,
4924 and read the result---these are remote procedure calls, or RPCs.
4925
4926 @quotation Note
4927 Users must @emph{never} modify files under @file{/gnu/store} directly.
4928 This would lead to inconsistencies and break the immutability
4929 assumptions of Guix's functional model (@pxref{Introduction}).
4930
4931 @xref{Invoking guix gc, @command{guix gc --verify}}, for information on
4932 how to check the integrity of the store and attempt recovery from
4933 accidental modifications.
4934 @end quotation
4935
4936 The @code{(guix store)} module provides procedures to connect to the
4937 daemon, and to perform RPCs. These are described below. By default,
4938 @code{open-connection}, and thus all the @command{guix} commands,
4939 connect to the local daemon or to the URI specified by the
4940 @code{GUIX_DAEMON_SOCKET} environment variable.
4941
4942 @defvr {Environment Variable} GUIX_DAEMON_SOCKET
4943 When set, the value of this variable should be a file name or a URI
4944 designating the daemon endpoint. When it is a file name, it denotes a
4945 Unix-domain socket to connect to. In addition to file names, the
4946 supported URI schemes are:
4947
4948 @table @code
4949 @item file
4950 @itemx unix
4951 These are for Unix-domain sockets.
4952 @code{file:///var/guix/daemon-socket/socket} is equivalent to
4953 @file{/var/guix/daemon-socket/socket}.
4954
4955 @item guix
4956 @cindex daemon, remote access
4957 @cindex remote access to the daemon
4958 @cindex daemon, cluster setup
4959 @cindex clusters, daemon setup
4960 These URIs denote connections over TCP/IP, without encryption nor
4961 authentication of the remote host. The URI must specify the host name
4962 and optionally a port number (by default port 44146 is used):
4963
4964 @example
4965 guix://master.guix.example.org:1234
4966 @end example
4967
4968 This setup is suitable on local networks, such as clusters, where only
4969 trusted nodes may connect to the build daemon at
4970 @code{master.guix.example.org}.
4971
4972 The @code{--listen} option of @command{guix-daemon} can be used to
4973 instruct it to listen for TCP connections (@pxref{Invoking guix-daemon,
4974 @code{--listen}}).
4975
4976 @item ssh
4977 @cindex SSH access to build daemons
4978 These URIs allow you to connect to a remote daemon over
4979 SSH@footnote{This feature requires Guile-SSH (@pxref{Requirements}).}.
4980 A typical URL might look like this:
4981
4982 @example
4983 ssh://charlie@@guix.example.org:22
4984 @end example
4985
4986 As for @command{guix copy}, the usual OpenSSH client configuration files
4987 are honored (@pxref{Invoking guix copy}).
4988 @end table
4989
4990 Additional URI schemes may be supported in the future.
4991
4992 @c XXX: Remove this note when the protocol incurs fewer round trips
4993 @c and when (guix derivations) no longer relies on file system access.
4994 @quotation Note
4995 The ability to connect to remote build daemons is considered
4996 experimental as of @value{VERSION}. Please get in touch with us to
4997 share any problems or suggestions you may have (@pxref{Contributing}).
4998 @end quotation
4999 @end defvr
5000
5001 @deffn {Scheme Procedure} open-connection [@var{uri}] [#:reserve-space? #t]
5002 Connect to the daemon over the Unix-domain socket at @var{uri} (a string). When
5003 @var{reserve-space?} is true, instruct it to reserve a little bit of
5004 extra space on the file system so that the garbage collector can still
5005 operate should the disk become full. Return a server object.
5006
5007 @var{file} defaults to @var{%default-socket-path}, which is the normal
5008 location given the options that were passed to @command{configure}.
5009 @end deffn
5010
5011 @deffn {Scheme Procedure} close-connection @var{server}
5012 Close the connection to @var{server}.
5013 @end deffn
5014
5015 @defvr {Scheme Variable} current-build-output-port
5016 This variable is bound to a SRFI-39 parameter, which refers to the port
5017 where build and error logs sent by the daemon should be written.
5018 @end defvr
5019
5020 Procedures that make RPCs all take a server object as their first
5021 argument.
5022
5023 @deffn {Scheme Procedure} valid-path? @var{server} @var{path}
5024 @cindex invalid store items
5025 Return @code{#t} when @var{path} designates a valid store item and
5026 @code{#f} otherwise (an invalid item may exist on disk but still be
5027 invalid, for instance because it is the result of an aborted or failed
5028 build.)
5029
5030 A @code{&store-protocol-error} condition is raised if @var{path} is not
5031 prefixed by the store directory (@file{/gnu/store}).
5032 @end deffn
5033
5034 @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
5035 Add @var{text} under file @var{name} in the store, and return its store
5036 path. @var{references} is the list of store paths referred to by the
5037 resulting store path.
5038 @end deffn
5039
5040 @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
5041 Build @var{derivations} (a list of @code{<derivation>} objects or
5042 derivation paths), and return when the worker is done building them.
5043 Return @code{#t} on success.
5044 @end deffn
5045
5046 Note that the @code{(guix monads)} module provides a monad as well as
5047 monadic versions of the above procedures, with the goal of making it
5048 more convenient to work with code that accesses the store (@pxref{The
5049 Store Monad}).
5050
5051 @c FIXME
5052 @i{This section is currently incomplete.}
5053
5054 @node Derivations
5055 @section Derivations
5056
5057 @cindex derivations
5058 Low-level build actions and the environment in which they are performed
5059 are represented by @dfn{derivations}. A derivation contains the
5060 following pieces of information:
5061
5062 @itemize
5063 @item
5064 The outputs of the derivation---derivations produce at least one file or
5065 directory in the store, but may produce more.
5066
5067 @item
5068 The inputs of the derivations, which may be other derivations or plain
5069 files in the store (patches, build scripts, etc.)
5070
5071 @item
5072 The system type targeted by the derivation---e.g., @code{x86_64-linux}.
5073
5074 @item
5075 The file name of a build script in the store, along with the arguments
5076 to be passed.
5077
5078 @item
5079 A list of environment variables to be defined.
5080
5081 @end itemize
5082
5083 @cindex derivation path
5084 Derivations allow clients of the daemon to communicate build actions to
5085 the store. They exist in two forms: as an in-memory representation,
5086 both on the client- and daemon-side, and as files in the store whose
5087 name end in @code{.drv}---these files are referred to as @dfn{derivation
5088 paths}. Derivations paths can be passed to the @code{build-derivations}
5089 procedure to perform the build actions they prescribe (@pxref{The
5090 Store}).
5091
5092 @cindex fixed-output derivations
5093 Operations such as file downloads and version-control checkouts for
5094 which the expected content hash is known in advance are modeled as
5095 @dfn{fixed-output derivations}. Unlike regular derivations, the outputs
5096 of a fixed-output derivation are independent of its inputs---e.g., a
5097 source code download produces the same result regardless of the download
5098 method and tools being used.
5099
5100 The @code{(guix derivations)} module provides a representation of
5101 derivations as Scheme objects, along with procedures to create and
5102 otherwise manipulate derivations. The lowest-level primitive to create
5103 a derivation is the @code{derivation} procedure:
5104
5105 @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
5106 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
5107 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
5108 [#:system (%current-system)] [#:references-graphs #f] @
5109 [#:allowed-references #f] [#:disallowed-references #f] @
5110 [#:leaked-env-vars #f] [#:local-build? #f] @
5111 [#:substitutable? #t] [#:properties '()]
5112 Build a derivation with the given arguments, and return the resulting
5113 @code{<derivation>} object.
5114
5115 When @var{hash} and @var{hash-algo} are given, a
5116 @dfn{fixed-output derivation} is created---i.e., one whose result is
5117 known in advance, such as a file download. If, in addition,
5118 @var{recursive?} is true, then that fixed output may be an executable
5119 file or a directory and @var{hash} must be the hash of an archive
5120 containing this output.
5121
5122 When @var{references-graphs} is true, it must be a list of file
5123 name/store path pairs. In that case, the reference graph of each store
5124 path is exported in the build environment in the corresponding file, in
5125 a simple text format.
5126
5127 When @var{allowed-references} is true, it must be a list of store items
5128 or outputs that the derivation's output may refer to. Likewise,
5129 @var{disallowed-references}, if true, must be a list of things the
5130 outputs may @emph{not} refer to.
5131
5132 When @var{leaked-env-vars} is true, it must be a list of strings
5133 denoting environment variables that are allowed to ``leak'' from the
5134 daemon's environment to the build environment. This is only applicable
5135 to fixed-output derivations---i.e., when @var{hash} is true. The main
5136 use is to allow variables such as @code{http_proxy} to be passed to
5137 derivations that download files.
5138
5139 When @var{local-build?} is true, declare that the derivation is not a
5140 good candidate for offloading and should rather be built locally
5141 (@pxref{Daemon Offload Setup}). This is the case for small derivations
5142 where the costs of data transfers would outweigh the benefits.
5143
5144 When @var{substitutable?} is false, declare that substitutes of the
5145 derivation's output should not be used (@pxref{Substitutes}). This is
5146 useful, for instance, when building packages that capture details of the
5147 host CPU instruction set.
5148
5149 @var{properties} must be an association list describing ``properties'' of the
5150 derivation. It is kept as-is, uninterpreted, in the derivation.
5151 @end deffn
5152
5153 @noindent
5154 Here's an example with a shell script as its builder, assuming
5155 @var{store} is an open connection to the daemon, and @var{bash} points
5156 to a Bash executable in the store:
5157
5158 @lisp
5159 (use-modules (guix utils)
5160 (guix store)
5161 (guix derivations))
5162
5163 (let ((builder ; add the Bash script to the store
5164 (add-text-to-store store "my-builder.sh"
5165 "echo hello world > $out\n" '())))
5166 (derivation store "foo"
5167 bash `("-e" ,builder)
5168 #:inputs `((,bash) (,builder))
5169 #:env-vars '(("HOME" . "/homeless"))))
5170 @result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
5171 @end lisp
5172
5173 As can be guessed, this primitive is cumbersome to use directly. A
5174 better approach is to write build scripts in Scheme, of course! The
5175 best course of action for that is to write the build code as a
5176 ``G-expression'', and to pass it to @code{gexp->derivation}. For more
5177 information, @pxref{G-Expressions}.
5178
5179 Once upon a time, @code{gexp->derivation} did not exist and constructing
5180 derivations with build code written in Scheme was achieved with
5181 @code{build-expression->derivation}, documented below. This procedure
5182 is now deprecated in favor of the much nicer @code{gexp->derivation}.
5183
5184 @deffn {Scheme Procedure} build-expression->derivation @var{store} @
5185 @var{name} @var{exp} @
5186 [#:system (%current-system)] [#:inputs '()] @
5187 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
5188 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
5189 [#:references-graphs #f] [#:allowed-references #f] @
5190 [#:disallowed-references #f] @
5191 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
5192 Return a derivation that executes Scheme expression @var{exp} as a
5193 builder for derivation @var{name}. @var{inputs} must be a list of
5194 @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
5195 @code{"out"} is assumed. @var{modules} is a list of names of Guile
5196 modules from the current search path to be copied in the store,
5197 compiled, and made available in the load path during the execution of
5198 @var{exp}---e.g., @code{((guix build utils) (guix build
5199 gnu-build-system))}.
5200
5201 @var{exp} is evaluated in an environment where @code{%outputs} is bound
5202 to a list of output/path pairs, and where @code{%build-inputs} is bound
5203 to a list of string/output-path pairs made from @var{inputs}.
5204 Optionally, @var{env-vars} is a list of string pairs specifying the name
5205 and value of environment variables visible to the builder. The builder
5206 terminates by passing the result of @var{exp} to @code{exit}; thus, when
5207 @var{exp} returns @code{#f}, the build is considered to have failed.
5208
5209 @var{exp} is built using @var{guile-for-build} (a derivation). When
5210 @var{guile-for-build} is omitted or is @code{#f}, the value of the
5211 @code{%guile-for-build} fluid is used instead.
5212
5213 See the @code{derivation} procedure for the meaning of
5214 @var{references-graphs}, @var{allowed-references},
5215 @var{disallowed-references}, @var{local-build?}, and
5216 @var{substitutable?}.
5217 @end deffn
5218
5219 @noindent
5220 Here's an example of a single-output derivation that creates a directory
5221 containing one file:
5222
5223 @lisp
5224 (let ((builder '(let ((out (assoc-ref %outputs "out")))
5225 (mkdir out) ; create /gnu/store/@dots{}-goo
5226 (call-with-output-file (string-append out "/test")
5227 (lambda (p)
5228 (display '(hello guix) p))))))
5229 (build-expression->derivation store "goo" builder))
5230
5231 @result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
5232 @end lisp
5233
5234
5235 @node The Store Monad
5236 @section The Store Monad
5237
5238 @cindex monad
5239
5240 The procedures that operate on the store described in the previous
5241 sections all take an open connection to the build daemon as their first
5242 argument. Although the underlying model is functional, they either have
5243 side effects or depend on the current state of the store.
5244
5245 The former is inconvenient: the connection to the build daemon has to be
5246 carried around in all those functions, making it impossible to compose
5247 functions that do not take that parameter with functions that do. The
5248 latter can be problematic: since store operations have side effects
5249 and/or depend on external state, they have to be properly sequenced.
5250
5251 @cindex monadic values
5252 @cindex monadic functions
5253 This is where the @code{(guix monads)} module comes in. This module
5254 provides a framework for working with @dfn{monads}, and a particularly
5255 useful monad for our uses, the @dfn{store monad}. Monads are a
5256 construct that allows two things: associating ``context'' with values
5257 (in our case, the context is the store), and building sequences of
5258 computations (here computations include accesses to the store). Values
5259 in a monad---values that carry this additional context---are called
5260 @dfn{monadic values}; procedures that return such values are called
5261 @dfn{monadic procedures}.
5262
5263 Consider this ``normal'' procedure:
5264
5265 @example
5266 (define (sh-symlink store)
5267 ;; Return a derivation that symlinks the 'bash' executable.
5268 (let* ((drv (package-derivation store bash))
5269 (out (derivation->output-path drv))
5270 (sh (string-append out "/bin/bash")))
5271 (build-expression->derivation store "sh"
5272 `(symlink ,sh %output))))
5273 @end example
5274
5275 Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
5276 as a monadic function:
5277
5278 @example
5279 (define (sh-symlink)
5280 ;; Same, but return a monadic value.
5281 (mlet %store-monad ((drv (package->derivation bash)))
5282 (gexp->derivation "sh"
5283 #~(symlink (string-append #$drv "/bin/bash")
5284 #$output))))
5285 @end example
5286
5287 There are several things to note in the second version: the @code{store}
5288 parameter is now implicit and is ``threaded'' in the calls to the
5289 @code{package->derivation} and @code{gexp->derivation} monadic
5290 procedures, and the monadic value returned by @code{package->derivation}
5291 is @dfn{bound} using @code{mlet} instead of plain @code{let}.
5292
5293 As it turns out, the call to @code{package->derivation} can even be
5294 omitted since it will take place implicitly, as we will see later
5295 (@pxref{G-Expressions}):
5296
5297 @example
5298 (define (sh-symlink)
5299 (gexp->derivation "sh"
5300 #~(symlink (string-append #$bash "/bin/bash")
5301 #$output)))
5302 @end example
5303
5304 @c See
5305 @c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
5306 @c for the funny quote.
5307 Calling the monadic @code{sh-symlink} has no effect. As someone once
5308 said, ``you exit a monad like you exit a building on fire: by running''.
5309 So, to exit the monad and get the desired effect, one must use
5310 @code{run-with-store}:
5311
5312 @example
5313 (run-with-store (open-connection) (sh-symlink))
5314 @result{} /gnu/store/...-sh-symlink
5315 @end example
5316
5317 Note that the @code{(guix monad-repl)} module extends the Guile REPL with
5318 new ``meta-commands'' to make it easier to deal with monadic procedures:
5319 @code{run-in-store}, and @code{enter-store-monad}. The former is used
5320 to ``run'' a single monadic value through the store:
5321
5322 @example
5323 scheme@@(guile-user)> ,run-in-store (package->derivation hello)
5324 $1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
5325 @end example
5326
5327 The latter enters a recursive REPL, where all the return values are
5328 automatically run through the store:
5329
5330 @example
5331 scheme@@(guile-user)> ,enter-store-monad
5332 store-monad@@(guile-user) [1]> (package->derivation hello)
5333 $2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
5334 store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
5335 $3 = "/gnu/store/@dots{}-foo"
5336 store-monad@@(guile-user) [1]> ,q
5337 scheme@@(guile-user)>
5338 @end example
5339
5340 @noindent
5341 Note that non-monadic values cannot be returned in the
5342 @code{store-monad} REPL.
5343
5344 The main syntactic forms to deal with monads in general are provided by
5345 the @code{(guix monads)} module and are described below.
5346
5347 @deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
5348 Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
5349 in @var{monad}.
5350 @end deffn
5351
5352 @deffn {Scheme Syntax} return @var{val}
5353 Return a monadic value that encapsulates @var{val}.
5354 @end deffn
5355
5356 @deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
5357 @dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
5358 procedures @var{mproc}@dots{}@footnote{This operation is commonly
5359 referred to as ``bind'', but that name denotes an unrelated procedure in
5360 Guile. Thus we use this somewhat cryptic symbol inherited from the
5361 Haskell language.}. There can be one @var{mproc} or several of them, as
5362 in this example:
5363
5364 @example
5365 (run-with-state
5366 (with-monad %state-monad
5367 (>>= (return 1)
5368 (lambda (x) (return (+ 1 x)))
5369 (lambda (x) (return (* 2 x)))))
5370 'some-state)
5371
5372 @result{} 4
5373 @result{} some-state
5374 @end example
5375 @end deffn
5376
5377 @deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
5378 @var{body} ...
5379 @deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
5380 @var{body} ...
5381 Bind the variables @var{var} to the monadic values @var{mval} in
5382 @var{body}, which is a sequence of expressions. As with the bind
5383 operator, this can be thought of as ``unpacking'' the raw, non-monadic
5384 value ``contained'' in @var{mval} and making @var{var} refer to that
5385 raw, non-monadic value within the scope of the @var{body}. The form
5386 (@var{var} -> @var{val}) binds @var{var} to the ``normal'' value
5387 @var{val}, as per @code{let}. The binding operations occur in sequence
5388 from left to right. The last expression of @var{body} must be a monadic
5389 expression, and its result will become the result of the @code{mlet} or
5390 @code{mlet*} when run in the @var{monad}.
5391
5392 @code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
5393 (@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
5394 @end deffn
5395
5396 @deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
5397 Bind @var{mexp} and the following monadic expressions in sequence,
5398 returning the result of the last expression. Every expression in the
5399 sequence must be a monadic expression.
5400
5401 This is akin to @code{mlet}, except that the return values of the
5402 monadic expressions are ignored. In that sense, it is analogous to
5403 @code{begin}, but applied to monadic expressions.
5404 @end deffn
5405
5406 @deffn {Scheme System} mwhen @var{condition} @var{mexp0} @var{mexp*} ...
5407 When @var{condition} is true, evaluate the sequence of monadic
5408 expressions @var{mexp0}..@var{mexp*} as in an @code{mbegin}. When
5409 @var{condition} is false, return @code{*unspecified*} in the current
5410 monad. Every expression in the sequence must be a monadic expression.
5411 @end deffn
5412
5413 @deffn {Scheme System} munless @var{condition} @var{mexp0} @var{mexp*} ...
5414 When @var{condition} is false, evaluate the sequence of monadic
5415 expressions @var{mexp0}..@var{mexp*} as in an @code{mbegin}. When
5416 @var{condition} is true, return @code{*unspecified*} in the current
5417 monad. Every expression in the sequence must be a monadic expression.
5418 @end deffn
5419
5420 @cindex state monad
5421 The @code{(guix monads)} module provides the @dfn{state monad}, which
5422 allows an additional value---the state---to be @emph{threaded} through
5423 monadic procedure calls.
5424
5425 @defvr {Scheme Variable} %state-monad
5426 The state monad. Procedures in the state monad can access and change
5427 the state that is threaded.
5428
5429 Consider the example below. The @code{square} procedure returns a value
5430 in the state monad. It returns the square of its argument, but also
5431 increments the current state value:
5432
5433 @example
5434 (define (square x)
5435 (mlet %state-monad ((count (current-state)))
5436 (mbegin %state-monad
5437 (set-current-state (+ 1 count))
5438 (return (* x x)))))
5439
5440 (run-with-state (sequence %state-monad (map square (iota 3))) 0)
5441 @result{} (0 1 4)
5442 @result{} 3
5443 @end example
5444
5445 When ``run'' through @var{%state-monad}, we obtain that additional state
5446 value, which is the number of @code{square} calls.
5447 @end defvr
5448
5449 @deffn {Monadic Procedure} current-state
5450 Return the current state as a monadic value.
5451 @end deffn
5452
5453 @deffn {Monadic Procedure} set-current-state @var{value}
5454 Set the current state to @var{value} and return the previous state as a
5455 monadic value.
5456 @end deffn
5457
5458 @deffn {Monadic Procedure} state-push @var{value}
5459 Push @var{value} to the current state, which is assumed to be a list,
5460 and return the previous state as a monadic value.
5461 @end deffn
5462
5463 @deffn {Monadic Procedure} state-pop
5464 Pop a value from the current state and return it as a monadic value.
5465 The state is assumed to be a list.
5466 @end deffn
5467
5468 @deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
5469 Run monadic value @var{mval} starting with @var{state} as the initial
5470 state. Return two values: the resulting value, and the resulting state.
5471 @end deffn
5472
5473 The main interface to the store monad, provided by the @code{(guix
5474 store)} module, is as follows.
5475
5476 @defvr {Scheme Variable} %store-monad
5477 The store monad---an alias for @var{%state-monad}.
5478
5479 Values in the store monad encapsulate accesses to the store. When its
5480 effect is needed, a value of the store monad must be ``evaluated'' by
5481 passing it to the @code{run-with-store} procedure (see below.)
5482 @end defvr
5483
5484 @deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
5485 Run @var{mval}, a monadic value in the store monad, in @var{store}, an
5486 open store connection.
5487 @end deffn
5488
5489 @deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
5490 Return as a monadic value the absolute file name in the store of the file
5491 containing @var{text}, a string. @var{references} is a list of store items that the
5492 resulting text file refers to; it defaults to the empty list.
5493 @end deffn
5494
5495 @deffn {Monadic Procedure} binary-file @var{name} @var{data} [@var{references}]
5496 Return as a monadic value the absolute file name in the store of the file
5497 containing @var{data}, a bytevector. @var{references} is a list of store
5498 items that the resulting binary file refers to; it defaults to the empty list.
5499 @end deffn
5500
5501 @deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
5502 [#:recursive? #t] [#:select? (const #t)]
5503 Return the name of @var{file} once interned in the store. Use
5504 @var{name} as its store name, or the basename of @var{file} if
5505 @var{name} is omitted.
5506
5507 When @var{recursive?} is true, the contents of @var{file} are added
5508 recursively; if @var{file} designates a flat file and @var{recursive?}
5509 is true, its contents are added, and its permission bits are kept.
5510
5511 When @var{recursive?} is true, call @code{(@var{select?} @var{file}
5512 @var{stat})} for each directory entry, where @var{file} is the entry's
5513 absolute file name and @var{stat} is the result of @code{lstat}; exclude
5514 entries for which @var{select?} does not return true.
5515
5516 The example below adds a file to the store, under two different names:
5517
5518 @example
5519 (run-with-store (open-connection)
5520 (mlet %store-monad ((a (interned-file "README"))
5521 (b (interned-file "README" "LEGU-MIN")))
5522 (return (list a b))))
5523
5524 @result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
5525 @end example
5526
5527 @end deffn
5528
5529 The @code{(guix packages)} module exports the following package-related
5530 monadic procedures:
5531
5532 @deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
5533 [#:system (%current-system)] [#:target #f] @
5534 [#:output "out"]
5535 Return as a monadic
5536 value in the absolute file name of @var{file} within the @var{output}
5537 directory of @var{package}. When @var{file} is omitted, return the name
5538 of the @var{output} directory of @var{package}. When @var{target} is
5539 true, use it as a cross-compilation target triplet.
5540 @end deffn
5541
5542 @deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
5543 @deffnx {Monadic Procedure} package->cross-derivation @var{package} @
5544 @var{target} [@var{system}]
5545 Monadic version of @code{package-derivation} and
5546 @code{package-cross-derivation} (@pxref{Defining Packages}).
5547 @end deffn
5548
5549
5550 @node G-Expressions
5551 @section G-Expressions
5552
5553 @cindex G-expression
5554 @cindex build code quoting
5555 So we have ``derivations'', which represent a sequence of build actions
5556 to be performed to produce an item in the store (@pxref{Derivations}).
5557 These build actions are performed when asking the daemon to actually
5558 build the derivations; they are run by the daemon in a container
5559 (@pxref{Invoking guix-daemon}).
5560
5561 @cindex strata of code
5562 It should come as no surprise that we like to write these build actions
5563 in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
5564 code@footnote{The term @dfn{stratum} in this context was coined by
5565 Manuel Serrano et al.@: in the context of their work on Hop. Oleg
5566 Kiselyov, who has written insightful
5567 @url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
5568 on this topic}, refers to this kind of code generation as
5569 @dfn{staging}.}: the ``host code''---code that defines packages, talks
5570 to the daemon, etc.---and the ``build code''---code that actually
5571 performs build actions, such as making directories, invoking
5572 @command{make}, etc.
5573
5574 To describe a derivation and its build actions, one typically needs to
5575 embed build code inside host code. It boils down to manipulating build
5576 code as data, and the homoiconicity of Scheme---code has a direct
5577 representation as data---comes in handy for that. But we need more than
5578 the normal @code{quasiquote} mechanism in Scheme to construct build
5579 expressions.
5580
5581 The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
5582 S-expressions adapted to build expressions. G-expressions, or
5583 @dfn{gexps}, consist essentially of three syntactic forms: @code{gexp},
5584 @code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
5585 @code{#$}, and @code{#$@@}), which are comparable to
5586 @code{quasiquote}, @code{unquote}, and @code{unquote-splicing},
5587 respectively (@pxref{Expression Syntax, @code{quasiquote},, guile,
5588 GNU Guile Reference Manual}). However, there are major differences:
5589
5590 @itemize
5591 @item
5592 Gexps are meant to be written to a file and run or manipulated by other
5593 processes.
5594
5595 @item
5596 When a high-level object such as a package or derivation is unquoted
5597 inside a gexp, the result is as if its output file name had been
5598 introduced.
5599
5600 @item
5601 Gexps carry information about the packages or derivations they refer to,
5602 and these dependencies are automatically added as inputs to the build
5603 processes that use them.
5604 @end itemize
5605
5606 @cindex lowering, of high-level objects in gexps
5607 This mechanism is not limited to package and derivation
5608 objects: @dfn{compilers} able to ``lower'' other high-level objects to
5609 derivations or files in the store can be defined,
5610 such that these objects can also be inserted
5611 into gexps. For example, a useful type of high-level objects that can be
5612 inserted in a gexp is ``file-like objects'', which make it easy to
5613 add files to the store and to refer to them in
5614 derivations and such (see @code{local-file} and @code{plain-file}
5615 below.)
5616
5617 To illustrate the idea, here is an example of a gexp:
5618
5619 @example
5620 (define build-exp
5621 #~(begin
5622 (mkdir #$output)
5623 (chdir #$output)
5624 (symlink (string-append #$coreutils "/bin/ls")
5625 "list-files")))
5626 @end example
5627
5628 This gexp can be passed to @code{gexp->derivation}; we obtain a
5629 derivation that builds a directory containing exactly one symlink to
5630 @file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
5631
5632 @example
5633 (gexp->derivation "the-thing" build-exp)
5634 @end example
5635
5636 As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
5637 substituted to the reference to the @var{coreutils} package in the
5638 actual build code, and @var{coreutils} is automatically made an input to
5639 the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
5640 output)}) is replaced by a string containing the directory name of the
5641 output of the derivation.
5642
5643 @cindex cross compilation
5644 In a cross-compilation context, it is useful to distinguish between
5645 references to the @emph{native} build of a package---that can run on the
5646 host---versus references to cross builds of a package. To that end, the
5647 @code{#+} plays the same role as @code{#$}, but is a reference to a
5648 native package build:
5649
5650 @example
5651 (gexp->derivation "vi"
5652 #~(begin
5653 (mkdir #$output)
5654 (system* (string-append #+coreutils "/bin/ln")
5655 "-s"
5656 (string-append #$emacs "/bin/emacs")
5657 (string-append #$output "/bin/vi")))
5658 #:target "mips64el-linux-gnu")
5659 @end example
5660
5661 @noindent
5662 In the example above, the native build of @var{coreutils} is used, so
5663 that @command{ln} can actually run on the host; but then the
5664 cross-compiled build of @var{emacs} is referenced.
5665
5666 @cindex imported modules, for gexps
5667 @findex with-imported-modules
5668 Another gexp feature is @dfn{imported modules}: sometimes you want to be
5669 able to use certain Guile modules from the ``host environment'' in the
5670 gexp, so those modules should be imported in the ``build environment''.
5671 The @code{with-imported-modules} form allows you to express that:
5672
5673 @example
5674 (let ((build (with-imported-modules '((guix build utils))
5675 #~(begin
5676 (use-modules (guix build utils))
5677 (mkdir-p (string-append #$output "/bin"))))))
5678 (gexp->derivation "empty-dir"
5679 #~(begin
5680 #$build
5681 (display "success!\n")
5682 #t)))
5683 @end example
5684
5685 @noindent
5686 In this example, the @code{(guix build utils)} module is automatically
5687 pulled into the isolated build environment of our gexp, such that
5688 @code{(use-modules (guix build utils))} works as expected.
5689
5690 @cindex module closure
5691 @findex source-module-closure
5692 Usually you want the @emph{closure} of the module to be imported---i.e.,
5693 the module itself and all the modules it depends on---rather than just
5694 the module; failing to do that, attempts to use the module will fail
5695 because of missing dependent modules. The @code{source-module-closure}
5696 procedure computes the closure of a module by looking at its source file
5697 headers, which comes in handy in this case:
5698
5699 @example
5700 (use-modules (guix modules)) ;for 'source-module-closure'
5701
5702 (with-imported-modules (source-module-closure
5703 '((guix build utils)
5704 (gnu build vm)))
5705 (gexp->derivation "something-with-vms"
5706 #~(begin
5707 (use-modules (guix build utils)
5708 (gnu build vm))
5709 @dots{})))
5710 @end example
5711
5712 @cindex extensions, for gexps
5713 @findex with-extensions
5714 In the same vein, sometimes you want to import not just pure-Scheme
5715 modules, but also ``extensions'' such as Guile bindings to C libraries
5716 or other ``full-blown'' packages. Say you need the @code{guile-json}
5717 package available on the build side, here's how you would do it:
5718
5719 @example
5720 (use-modules (gnu packages guile)) ;for 'guile-json'
5721
5722 (with-extensions (list guile-json)
5723 (gexp->derivation "something-with-json"
5724 #~(begin
5725 (use-modules (json))
5726 @dots{})))
5727 @end example
5728
5729 The syntactic form to construct gexps is summarized below.
5730
5731 @deffn {Scheme Syntax} #~@var{exp}
5732 @deffnx {Scheme Syntax} (gexp @var{exp})
5733 Return a G-expression containing @var{exp}. @var{exp} may contain one
5734 or more of the following forms:
5735
5736 @table @code
5737 @item #$@var{obj}
5738 @itemx (ungexp @var{obj})
5739 Introduce a reference to @var{obj}. @var{obj} may have one of the
5740 supported types, for example a package or a
5741 derivation, in which case the @code{ungexp} form is replaced by its
5742 output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
5743
5744 If @var{obj} is a list, it is traversed and references to supported
5745 objects are substituted similarly.
5746
5747 If @var{obj} is another gexp, its contents are inserted and its
5748 dependencies are added to those of the containing gexp.
5749
5750 If @var{obj} is another kind of object, it is inserted as is.
5751
5752 @item #$@var{obj}:@var{output}
5753 @itemx (ungexp @var{obj} @var{output})
5754 This is like the form above, but referring explicitly to the
5755 @var{output} of @var{obj}---this is useful when @var{obj} produces
5756 multiple outputs (@pxref{Packages with Multiple Outputs}).
5757
5758 @item #+@var{obj}
5759 @itemx #+@var{obj}:output
5760 @itemx (ungexp-native @var{obj})
5761 @itemx (ungexp-native @var{obj} @var{output})
5762 Same as @code{ungexp}, but produces a reference to the @emph{native}
5763 build of @var{obj} when used in a cross compilation context.
5764
5765 @item #$output[:@var{output}]
5766 @itemx (ungexp output [@var{output}])
5767 Insert a reference to derivation output @var{output}, or to the main
5768 output when @var{output} is omitted.
5769
5770 This only makes sense for gexps passed to @code{gexp->derivation}.
5771
5772 @item #$@@@var{lst}
5773 @itemx (ungexp-splicing @var{lst})
5774 Like the above, but splices the contents of @var{lst} inside the
5775 containing list.
5776
5777 @item #+@@@var{lst}
5778 @itemx (ungexp-native-splicing @var{lst})
5779 Like the above, but refers to native builds of the objects listed in
5780 @var{lst}.
5781
5782 @end table
5783
5784 G-expressions created by @code{gexp} or @code{#~} are run-time objects
5785 of the @code{gexp?} type (see below.)
5786 @end deffn
5787
5788 @deffn {Scheme Syntax} with-imported-modules @var{modules} @var{body}@dots{}
5789 Mark the gexps defined in @var{body}@dots{} as requiring @var{modules}
5790 in their execution environment.
5791
5792 Each item in @var{modules} can be the name of a module, such as
5793 @code{(guix build utils)}, or it can be a module name, followed by an
5794 arrow, followed by a file-like object:
5795
5796 @example
5797 `((guix build utils)
5798 (guix gcrypt)
5799 ((guix config) => ,(scheme-file "config.scm"
5800 #~(define-module @dots{}))))
5801 @end example
5802
5803 @noindent
5804 In the example above, the first two modules are taken from the search
5805 path, and the last one is created from the given file-like object.
5806
5807 This form has @emph{lexical} scope: it has an effect on the gexps
5808 directly defined in @var{body}@dots{}, but not on those defined, say, in
5809 procedures called from @var{body}@dots{}.
5810 @end deffn
5811
5812 @deffn {Scheme Syntax} with-extensions @var{extensions} @var{body}@dots{}
5813 Mark the gexps defined in @var{body}@dots{} as requiring
5814 @var{extensions} in their build and execution environment.
5815 @var{extensions} is typically a list of package objects such as those
5816 defined in the @code{(gnu packages guile)} module.
5817
5818 Concretely, the packages listed in @var{extensions} are added to the
5819 load path while compiling imported modules in @var{body}@dots{}; they
5820 are also added to the load path of the gexp returned by
5821 @var{body}@dots{}.
5822 @end deffn
5823
5824 @deffn {Scheme Procedure} gexp? @var{obj}
5825 Return @code{#t} if @var{obj} is a G-expression.
5826 @end deffn
5827
5828 G-expressions are meant to be written to disk, either as code building
5829 some derivation, or as plain files in the store. The monadic procedures
5830 below allow you to do that (@pxref{The Store Monad}, for more
5831 information about monads.)
5832
5833 @deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
5834 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
5835 [#:hash #f] [#:hash-algo #f] @
5836 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
5837 [#:module-path @var{%load-path}] @
5838 [#:effective-version "2.2"] @
5839 [#:references-graphs #f] [#:allowed-references #f] @
5840 [#:disallowed-references #f] @
5841 [#:leaked-env-vars #f] @
5842 [#:script-name (string-append @var{name} "-builder")] @
5843 [#:deprecation-warnings #f] @
5844 [#:local-build? #f] [#:substitutable? #t] @
5845 [#:properties '()] [#:guile-for-build #f]
5846 Return a derivation @var{name} that runs @var{exp} (a gexp) with
5847 @var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
5848 stored in a file called @var{script-name}. When @var{target} is true,
5849 it is used as the cross-compilation target triplet for packages referred
5850 to by @var{exp}.
5851
5852 @var{modules} is deprecated in favor of @code{with-imported-modules}.
5853 Its meaning is to
5854 make @var{modules} available in the evaluation context of @var{exp};
5855 @var{modules} is a list of names of Guile modules searched in
5856 @var{module-path} to be copied in the store, compiled, and made available in
5857 the load path during the execution of @var{exp}---e.g., @code{((guix
5858 build utils) (guix build gnu-build-system))}.
5859
5860 @var{effective-version} determines the string to use when adding extensions of
5861 @var{exp} (see @code{with-extensions}) to the search path---e.g., @code{"2.2"}.
5862
5863 @var{graft?} determines whether packages referred to by @var{exp} should be grafted when
5864 applicable.
5865
5866 When @var{references-graphs} is true, it must be a list of tuples of one of the
5867 following forms:
5868
5869 @example
5870 (@var{file-name} @var{package})
5871 (@var{file-name} @var{package} @var{output})
5872 (@var{file-name} @var{derivation})
5873 (@var{file-name} @var{derivation} @var{output})
5874 (@var{file-name} @var{store-item})
5875 @end example
5876
5877 The right-hand-side of each element of @var{references-graphs} is automatically made
5878 an input of the build process of @var{exp}. In the build environment, each
5879 @var{file-name} contains the reference graph of the corresponding item, in a simple
5880 text format.
5881
5882 @var{allowed-references} must be either @code{#f} or a list of output names and packages.
5883 In the latter case, the list denotes store items that the result is allowed to
5884 refer to. Any reference to another store item will lead to a build error.
5885 Similarly for @var{disallowed-references}, which can list items that must not be
5886 referenced by the outputs.
5887
5888 @var{deprecation-warnings} determines whether to show deprecation warnings while
5889 compiling modules. It can be @code{#f}, @code{#t}, or @code{'detailed}.
5890
5891 The other arguments are as for @code{derivation} (@pxref{Derivations}).
5892 @end deffn
5893
5894 @cindex file-like objects
5895 The @code{local-file}, @code{plain-file}, @code{computed-file},
5896 @code{program-file}, and @code{scheme-file} procedures below return
5897 @dfn{file-like objects}. That is, when unquoted in a G-expression,
5898 these objects lead to a file in the store. Consider this G-expression:
5899
5900 @example
5901 #~(system* #$(file-append glibc "/sbin/nscd") "-f"
5902 #$(local-file "/tmp/my-nscd.conf"))
5903 @end example
5904
5905 The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
5906 to the store. Once expanded, for instance @i{via}
5907 @code{gexp->derivation}, the G-expression refers to that copy under
5908 @file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
5909 does not have any effect on what the G-expression does.
5910 @code{plain-file} can be used similarly; it differs in that the file
5911 content is directly passed as a string.
5912
5913 @deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
5914 [#:recursive? #f] [#:select? (const #t)]
5915 Return an object representing local file @var{file} to add to the store; this
5916 object can be used in a gexp. If @var{file} is a relative file name, it is looked
5917 up relative to the source file where this form appears. @var{file} will be added to
5918 the store under @var{name}--by default the base name of @var{file}.
5919
5920 When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
5921 designates a flat file and @var{recursive?} is true, its contents are added, and its
5922 permission bits are kept.
5923
5924 When @var{recursive?} is true, call @code{(@var{select?} @var{file}
5925 @var{stat})} for each directory entry, where @var{file} is the entry's
5926 absolute file name and @var{stat} is the result of @code{lstat}; exclude
5927 entries for which @var{select?} does not return true.
5928
5929 This is the declarative counterpart of the @code{interned-file} monadic
5930 procedure (@pxref{The Store Monad, @code{interned-file}}).
5931 @end deffn
5932
5933 @deffn {Scheme Procedure} plain-file @var{name} @var{content}
5934 Return an object representing a text file called @var{name} with the given
5935 @var{content} (a string or a bytevector) to be added to the store.
5936
5937 This is the declarative counterpart of @code{text-file}.
5938 @end deffn
5939
5940 @deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
5941 [#:options '(#:local-build? #t)]
5942 Return an object representing the store item @var{name}, a file or
5943 directory computed by @var{gexp}. @var{options}
5944 is a list of additional arguments to pass to @code{gexp->derivation}.
5945
5946 This is the declarative counterpart of @code{gexp->derivation}.
5947 @end deffn
5948
5949 @deffn {Monadic Procedure} gexp->script @var{name} @var{exp} @
5950 [#:guile (default-guile)] [#:module-path %load-path]
5951 Return an executable script @var{name} that runs @var{exp} using
5952 @var{guile}, with @var{exp}'s imported modules in its search path.
5953 Look up @var{exp}'s modules in @var{module-path}.
5954
5955 The example below builds a script that simply invokes the @command{ls}
5956 command:
5957
5958 @example
5959 (use-modules (guix gexp) (gnu packages base))
5960
5961 (gexp->script "list-files"
5962 #~(execl #$(file-append coreutils "/bin/ls")
5963 "ls"))
5964 @end example
5965
5966 When ``running'' it through the store (@pxref{The Store Monad,
5967 @code{run-with-store}}), we obtain a derivation that produces an
5968 executable file @file{/gnu/store/@dots{}-list-files} along these lines:
5969
5970 @example
5971 #!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
5972 !#
5973 (execl "/gnu/store/@dots{}-coreutils-8.22"/bin/ls" "ls")
5974 @end example
5975 @end deffn
5976
5977 @deffn {Scheme Procedure} program-file @var{name} @var{exp} @
5978 [#:guile #f] [#:module-path %load-path]
5979 Return an object representing the executable store item @var{name} that
5980 runs @var{gexp}. @var{guile} is the Guile package used to execute that
5981 script. Imported modules of @var{gexp} are looked up in @var{module-path}.
5982
5983 This is the declarative counterpart of @code{gexp->script}.
5984 @end deffn
5985
5986 @deffn {Monadic Procedure} gexp->file @var{name} @var{exp} @
5987 [#:set-load-path? #t] [#:module-path %load-path] @
5988 [#:splice? #f] @
5989 [#:guile (default-guile)]
5990 Return a derivation that builds a file @var{name} containing @var{exp}.
5991 When @var{splice?} is true, @var{exp} is considered to be a list of
5992 expressions that will be spliced in the resulting file.
5993
5994 When @var{set-load-path?} is true, emit code in the resulting file to
5995 set @code{%load-path} and @code{%load-compiled-path} to honor
5996 @var{exp}'s imported modules. Look up @var{exp}'s modules in
5997 @var{module-path}.
5998
5999 The resulting file holds references to all the dependencies of @var{exp}
6000 or a subset thereof.
6001 @end deffn
6002
6003 @deffn {Scheme Procedure} scheme-file @var{name} @var{exp} [#:splice? #f]
6004 Return an object representing the Scheme file @var{name} that contains
6005 @var{exp}.
6006
6007 This is the declarative counterpart of @code{gexp->file}.
6008 @end deffn
6009
6010 @deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
6011 Return as a monadic value a derivation that builds a text file
6012 containing all of @var{text}. @var{text} may list, in addition to
6013 strings, objects of any type that can be used in a gexp: packages,
6014 derivations, local file objects, etc. The resulting store file holds
6015 references to all these.
6016
6017 This variant should be preferred over @code{text-file} anytime the file
6018 to create will reference items from the store. This is typically the
6019 case when building a configuration file that embeds store file names,
6020 like this:
6021
6022 @example
6023 (define (profile.sh)
6024 ;; Return the name of a shell script in the store that
6025 ;; initializes the 'PATH' environment variable.
6026 (text-file* "profile.sh"
6027 "export PATH=" coreutils "/bin:"
6028 grep "/bin:" sed "/bin\n"))
6029 @end example
6030
6031 In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
6032 will reference @var{coreutils}, @var{grep}, and @var{sed}, thereby
6033 preventing them from being garbage-collected during its lifetime.
6034 @end deffn
6035
6036 @deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
6037 Return an object representing store file @var{name} containing
6038 @var{text}. @var{text} is a sequence of strings and file-like objects,
6039 as in:
6040
6041 @example
6042 (mixed-text-file "profile"
6043 "export PATH=" coreutils "/bin:" grep "/bin")
6044 @end example
6045
6046 This is the declarative counterpart of @code{text-file*}.
6047 @end deffn
6048
6049 @deffn {Scheme Procedure} file-union @var{name} @var{files}
6050 Return a @code{<computed-file>} that builds a directory containing all of @var{files}.
6051 Each item in @var{files} must be a two-element list where the first element is the
6052 file name to use in the new directory, and the second element is a gexp
6053 denoting the target file. Here's an example:
6054
6055 @example
6056 (file-union "etc"
6057 `(("hosts" ,(plain-file "hosts"
6058 "127.0.0.1 localhost"))
6059 ("bashrc" ,(plain-file "bashrc"
6060 "alias ls='ls --color=auto'"))))
6061 @end example
6062
6063 This yields an @code{etc} directory containing these two files.
6064 @end deffn
6065
6066 @deffn {Scheme Procedure} directory-union @var{name} @var{things}
6067 Return a directory that is the union of @var{things}, where @var{things} is a list of
6068 file-like objects denoting directories. For example:
6069
6070 @example
6071 (directory-union "guile+emacs" (list guile emacs))
6072 @end example
6073
6074 yields a directory that is the union of the @code{guile} and @code{emacs} packages.
6075 @end deffn
6076
6077 @deffn {Scheme Procedure} file-append @var{obj} @var{suffix} @dots{}
6078 Return a file-like object that expands to the concatenation of @var{obj}
6079 and @var{suffix}, where @var{obj} is a lowerable object and each
6080 @var{suffix} is a string.
6081
6082 As an example, consider this gexp:
6083
6084 @example
6085 (gexp->script "run-uname"
6086 #~(system* #$(file-append coreutils
6087 "/bin/uname")))
6088 @end example
6089
6090 The same effect could be achieved with:
6091
6092 @example
6093 (gexp->script "run-uname"
6094 #~(system* (string-append #$coreutils
6095 "/bin/uname")))
6096 @end example
6097
6098 There is one difference though: in the @code{file-append} case, the
6099 resulting script contains the absolute file name as a string, whereas in
6100 the second case, the resulting script contains a @code{(string-append
6101 @dots{})} expression to construct the file name @emph{at run time}.
6102 @end deffn
6103
6104
6105 Of course, in addition to gexps embedded in ``host'' code, there are
6106 also modules containing build tools. To make it clear that they are
6107 meant to be used in the build stratum, these modules are kept in the
6108 @code{(guix build @dots{})} name space.
6109
6110 @cindex lowering, of high-level objects in gexps
6111 Internally, high-level objects are @dfn{lowered}, using their compiler,
6112 to either derivations or store items. For instance, lowering a package
6113 yields a derivation, and lowering a @code{plain-file} yields a store
6114 item. This is achieved using the @code{lower-object} monadic procedure.
6115
6116 @deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
6117 [#:target #f]
6118 Return as a value in @var{%store-monad} the derivation or store item
6119 corresponding to @var{obj} for @var{system}, cross-compiling for
6120 @var{target} if @var{target} is true. @var{obj} must be an object that
6121 has an associated gexp compiler, such as a @code{<package>}.
6122 @end deffn
6123
6124 @node Invoking guix repl
6125 @section Invoking @command{guix repl}
6126
6127 @cindex REPL, read-eval-print loop
6128 The @command{guix repl} command spawns a Guile @dfn{read-eval-print loop}
6129 (REPL) for interactive programming (@pxref{Using Guile Interactively,,, guile,
6130 GNU Guile Reference Manual}). Compared to just launching the @command{guile}
6131 command, @command{guix repl} guarantees that all the Guix modules and all its
6132 dependencies are available in the search path. You can use it this way:
6133
6134 @example
6135 $ guix repl
6136 scheme@@(guile-user)> ,use (gnu packages base)
6137 scheme@@(guile-user)> coreutils
6138 $1 = #<package coreutils@@8.29 gnu/packages/base.scm:327 3e28300>
6139 @end example
6140
6141 @cindex inferiors
6142 In addition, @command{guix repl} implements a simple machine-readable REPL
6143 protocol for use by @code{(guix inferior)}, a facility to interact with
6144 @dfn{inferiors}, separate processes running a potentially different revision
6145 of Guix.
6146
6147 The available options are as follows:
6148
6149 @table @code
6150 @item --type=@var{type}
6151 @itemx -t @var{type}
6152 Start a REPL of the given @var{TYPE}, which can be one of the following:
6153
6154 @table @code
6155 @item guile
6156 This is default, and it spawns a standard full-featured Guile REPL.
6157 @item machine
6158 Spawn a REPL that uses the machine-readable protocol. This is the protocol
6159 that the @code{(guix inferior)} module speaks.
6160 @end table
6161
6162 @item --listen=@var{endpoint}
6163 By default, @command{guix repl} reads from standard input and writes to
6164 standard output. When this option is passed, it will instead listen for
6165 connections on @var{endpoint}. Here are examples of valid options:
6166
6167 @table @code
6168 @item --listen=tcp:37146
6169 Accept connections on localhost on port 37146.
6170
6171 @item --listen=unix:/tmp/socket
6172 Accept connections on the Unix-domain socket @file{/tmp/socket}.
6173 @end table
6174 @end table
6175
6176 @c *********************************************************************
6177 @node Utilities
6178 @chapter Utilities
6179
6180 This section describes Guix command-line utilities. Some of them are
6181 primarily targeted at developers and users who write new package
6182 definitions, while others are more generally useful. They complement
6183 the Scheme programming interface of Guix in a convenient way.
6184
6185 @menu
6186 * Invoking guix build:: Building packages from the command line.
6187 * Invoking guix edit:: Editing package definitions.
6188 * Invoking guix download:: Downloading a file and printing its hash.
6189 * Invoking guix hash:: Computing the cryptographic hash of a file.
6190 * Invoking guix import:: Importing package definitions.
6191 * Invoking guix refresh:: Updating package definitions.
6192 * Invoking guix lint:: Finding errors in package definitions.
6193 * Invoking guix size:: Profiling disk usage.
6194 * Invoking guix graph:: Visualizing the graph of packages.
6195 * Invoking guix environment:: Setting up development environments.
6196 * Invoking guix publish:: Sharing substitutes.
6197 * Invoking guix challenge:: Challenging substitute servers.
6198 * Invoking guix copy:: Copying to and from a remote store.
6199 * Invoking guix container:: Process isolation.
6200 * Invoking guix weather:: Assessing substitute availability.
6201 * Invoking guix processes:: Listing client processes.
6202 @end menu
6203
6204 @node Invoking guix build
6205 @section Invoking @command{guix build}
6206
6207 @cindex package building
6208 @cindex @command{guix build}
6209 The @command{guix build} command builds packages or derivations and
6210 their dependencies, and prints the resulting store paths. Note that it
6211 does not modify the user's profile---this is the job of the
6212 @command{guix package} command (@pxref{Invoking guix package}). Thus,
6213 it is mainly useful for distribution developers.
6214
6215 The general syntax is:
6216
6217 @example
6218 guix build @var{options} @var{package-or-derivation}@dots{}
6219 @end example
6220
6221 As an example, the following command builds the latest versions of Emacs
6222 and of Guile, displays their build logs, and finally displays the
6223 resulting directories:
6224
6225 @example
6226 guix build emacs guile
6227 @end example
6228
6229 Similarly, the following command builds all the available packages:
6230
6231 @example
6232 guix build --quiet --keep-going \
6233 `guix package -A | cut -f1,2 --output-delimiter=@@`
6234 @end example
6235
6236 @var{package-or-derivation} may be either the name of a package found in
6237 the software distribution such as @code{coreutils} or
6238 @code{coreutils@@8.20}, or a derivation such as
6239 @file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
6240 package with the corresponding name (and optionally version) is searched
6241 for among the GNU distribution modules (@pxref{Package Modules}).
6242
6243 Alternatively, the @code{--expression} option may be used to specify a
6244 Scheme expression that evaluates to a package; this is useful when
6245 disambiguating among several same-named packages or package variants is
6246 needed.
6247
6248 There may be zero or more @var{options}. The available options are
6249 described in the subsections below.
6250
6251 @menu
6252 * Common Build Options:: Build options for most commands.
6253 * Package Transformation Options:: Creating variants of packages.
6254 * Additional Build Options:: Options specific to 'guix build'.
6255 * Debugging Build Failures:: Real life packaging experience.
6256 @end menu
6257
6258 @node Common Build Options
6259 @subsection Common Build Options
6260
6261 A number of options that control the build process are common to
6262 @command{guix build} and other commands that can spawn builds, such as
6263 @command{guix package} or @command{guix archive}. These are the
6264 following:
6265
6266 @table @code
6267
6268 @item --load-path=@var{directory}
6269 @itemx -L @var{directory}
6270 Add @var{directory} to the front of the package module search path
6271 (@pxref{Package Modules}).
6272
6273 This allows users to define their own packages and make them visible to
6274 the command-line tools.
6275
6276 @item --keep-failed
6277 @itemx -K
6278 Keep the build tree of failed builds. Thus, if a build fails, its build
6279 tree is kept under @file{/tmp}, in a directory whose name is shown at
6280 the end of the build log. This is useful when debugging build issues.
6281 @xref{Debugging Build Failures}, for tips and tricks on how to debug
6282 build issues.
6283
6284 This option has no effect when connecting to a remote daemon with a
6285 @code{guix://} URI (@pxref{The Store, the @code{GUIX_DAEMON_SOCKET}
6286 variable}).
6287
6288 @item --keep-going
6289 @itemx -k
6290 Keep going when some of the derivations fail to build; return only once
6291 all the builds have either completed or failed.
6292
6293 The default behavior is to stop as soon as one of the specified
6294 derivations has failed.
6295
6296 @item --dry-run
6297 @itemx -n
6298 Do not build the derivations.
6299
6300 @anchor{fallback-option}
6301 @item --fallback
6302 When substituting a pre-built binary fails, fall back to building
6303 packages locally (@pxref{Substitution Failure}).
6304
6305 @item --substitute-urls=@var{urls}
6306 @anchor{client-substitute-urls}
6307 Consider @var{urls} the whitespace-separated list of substitute source
6308 URLs, overriding the default list of URLs of @command{guix-daemon}
6309 (@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
6310
6311 This means that substitutes may be downloaded from @var{urls}, provided
6312 they are signed by a key authorized by the system administrator
6313 (@pxref{Substitutes}).
6314
6315 When @var{urls} is the empty string, substitutes are effectively
6316 disabled.
6317
6318 @item --no-substitutes
6319 Do not use substitutes for build products. That is, always build things
6320 locally instead of allowing downloads of pre-built binaries
6321 (@pxref{Substitutes}).
6322
6323 @item --no-grafts
6324 Do not ``graft'' packages. In practice, this means that package updates
6325 available as grafts are not applied. @xref{Security Updates}, for more
6326 information on grafts.
6327
6328 @item --rounds=@var{n}
6329 Build each derivation @var{n} times in a row, and raise an error if
6330 consecutive build results are not bit-for-bit identical.
6331
6332 This is a useful way to detect non-deterministic builds processes.
6333 Non-deterministic build processes are a problem because they make it
6334 practically impossible for users to @emph{verify} whether third-party
6335 binaries are genuine. @xref{Invoking guix challenge}, for more.
6336
6337 Note that, currently, the differing build results are not kept around,
6338 so you will have to manually investigate in case of an error---e.g., by
6339 stashing one of the build results with @code{guix archive --export}
6340 (@pxref{Invoking guix archive}), then rebuilding, and finally comparing
6341 the two results.
6342
6343 @item --no-build-hook
6344 Do not attempt to offload builds @i{via} the ``build hook'' of the daemon
6345 (@pxref{Daemon Offload Setup}). That is, always build things locally
6346 instead of offloading builds to remote machines.
6347
6348 @item --max-silent-time=@var{seconds}
6349 When the build or substitution process remains silent for more than
6350 @var{seconds}, terminate it and report a build failure.
6351
6352 By default, the daemon's setting is honored (@pxref{Invoking
6353 guix-daemon, @code{--max-silent-time}}).
6354
6355 @item --timeout=@var{seconds}
6356 Likewise, when the build or substitution process lasts for more than
6357 @var{seconds}, terminate it and report a build failure.
6358
6359 By default, the daemon's setting is honored (@pxref{Invoking
6360 guix-daemon, @code{--timeout}}).
6361
6362 @c Note: This option is actually not part of %standard-build-options but
6363 @c most programs honor it.
6364 @cindex verbosity, of the command-line tools
6365 @cindex build logs, verbosity
6366 @item -v @var{level}
6367 @itemx --verbosity=@var{level}
6368 Use the given verbosity @var{level}, an integer. Choosing 0 means that no
6369 output is produced, 1 is for quiet output, and 2 shows all the build log
6370 output on standard error.
6371
6372 @item --cores=@var{n}
6373 @itemx -c @var{n}
6374 Allow the use of up to @var{n} CPU cores for the build. The special
6375 value @code{0} means to use as many CPU cores as available.
6376
6377 @item --max-jobs=@var{n}
6378 @itemx -M @var{n}
6379 Allow at most @var{n} build jobs in parallel. @xref{Invoking
6380 guix-daemon, @code{--max-jobs}}, for details about this option and the
6381 equivalent @command{guix-daemon} option.
6382
6383 @item --debug=@var{level}
6384 Produce debugging output coming from the build daemon. @var{level} must be an
6385 integer between 0 and 5; higher means more verbose output. Setting a level of
6386 4 or more may be helpful when debugging setup issues with the build daemon.
6387
6388 @end table
6389
6390 Behind the scenes, @command{guix build} is essentially an interface to
6391 the @code{package-derivation} procedure of the @code{(guix packages)}
6392 module, and to the @code{build-derivations} procedure of the @code{(guix
6393 derivations)} module.
6394
6395 In addition to options explicitly passed on the command line,
6396 @command{guix build} and other @command{guix} commands that support
6397 building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
6398
6399 @defvr {Environment Variable} GUIX_BUILD_OPTIONS
6400 Users can define this variable to a list of command line options that
6401 will automatically be used by @command{guix build} and other
6402 @command{guix} commands that can perform builds, as in the example
6403 below:
6404
6405 @example
6406 $ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
6407 @end example
6408
6409 These options are parsed independently, and the result is appended to
6410 the parsed command-line options.
6411 @end defvr
6412
6413
6414 @node Package Transformation Options
6415 @subsection Package Transformation Options
6416
6417 @cindex package variants
6418 Another set of command-line options supported by @command{guix build}
6419 and also @command{guix package} are @dfn{package transformation
6420 options}. These are options that make it possible to define @dfn{package
6421 variants}---for instance, packages built from different source code.
6422 This is a convenient way to create customized packages on the fly
6423 without having to type in the definitions of package variants
6424 (@pxref{Defining Packages}).
6425
6426 @table @code
6427
6428 @item --with-source=@var{source}
6429 @itemx --with-source=@var{package}=@var{source}
6430 @itemx --with-source=@var{package}@@@var{version}=@var{source}
6431 Use @var{source} as the source of @var{package}, and @var{version} as
6432 its version number.
6433 @var{source} must be a file name or a URL, as for @command{guix
6434 download} (@pxref{Invoking guix download}).
6435
6436 When @var{package} is omitted,
6437 it is taken to be the package name specified on the
6438 command line that matches the base of @var{source}---e.g.,
6439 if @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
6440 package is @code{guile}.
6441
6442 Likewise, when @var{version} is omitted, the version string is inferred from
6443 @var{source}; in the previous example, it is @code{2.0.10}.
6444
6445 This option allows users to try out versions of packages other than the
6446 one provided by the distribution. The example below downloads
6447 @file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
6448 the @code{ed} package:
6449
6450 @example
6451 guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
6452 @end example
6453
6454 As a developer, @code{--with-source} makes it easy to test release
6455 candidates:
6456
6457 @example
6458 guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
6459 @end example
6460
6461 @dots{} or to build from a checkout in a pristine environment:
6462
6463 @example
6464 $ git clone git://git.sv.gnu.org/guix.git
6465 $ guix build guix --with-source=guix@@1.0=./guix
6466 @end example
6467
6468 @item --with-input=@var{package}=@var{replacement}
6469 Replace dependency on @var{package} by a dependency on
6470 @var{replacement}. @var{package} must be a package name, and
6471 @var{replacement} must be a package specification such as @code{guile}
6472 or @code{guile@@1.8}.
6473
6474 For instance, the following command builds Guix, but replaces its
6475 dependency on the current stable version of Guile with a dependency on
6476 the legacy version of Guile, @code{guile@@2.0}:
6477
6478 @example
6479 guix build --with-input=guile=guile@@2.0 guix
6480 @end example
6481
6482 This is a recursive, deep replacement. So in this example, both
6483 @code{guix} and its dependency @code{guile-json} (which also depends on
6484 @code{guile}) get rebuilt against @code{guile@@2.0}.
6485
6486 This is implemented using the @code{package-input-rewriting} Scheme
6487 procedure (@pxref{Defining Packages, @code{package-input-rewriting}}).
6488
6489 @item --with-graft=@var{package}=@var{replacement}
6490 This is similar to @code{--with-input} but with an important difference:
6491 instead of rebuilding the whole dependency chain, @var{replacement} is
6492 built and then @dfn{grafted} onto the binaries that were initially
6493 referring to @var{package}. @xref{Security Updates}, for more
6494 information on grafts.
6495
6496 For example, the command below grafts version 3.5.4 of GnuTLS onto Wget
6497 and all its dependencies, replacing references to the version of GnuTLS
6498 they currently refer to:
6499
6500 @example
6501 guix build --with-graft=gnutls=gnutls@@3.5.4 wget
6502 @end example
6503
6504 This has the advantage of being much faster than rebuilding everything.
6505 But there is a caveat: it works if and only if @var{package} and
6506 @var{replacement} are strictly compatible---for example, if they provide
6507 a library, the application binary interface (ABI) of those libraries
6508 must be compatible. If @var{replacement} is somehow incompatible with
6509 @var{package}, then the resulting package may be unusable. Use with
6510 care!
6511
6512 @item --with-branch=@var{package}=@var{branch}
6513 @cindex Git, using the latest commit
6514 @cindex latest commit, building
6515 Build @var{package} from the latest commit of @var{branch}. The @code{source}
6516 field of @var{package} must be an origin with the @code{git-fetch} method
6517 (@pxref{origin Reference}) or a @code{git-checkout} object; the repository URL
6518 is taken from that @code{source}.
6519
6520 For instance, the following command builds @code{guile-sqlite3} from the
6521 latest commit of its @code{master} branch, and then builds @code{guix} (which
6522 depends on it) and @code{cuirass} (which depends on @code{guix}) against this
6523 specific @code{guile-sqlite3} build:
6524
6525 @example
6526 guix build --with-branch=guile-sqlite3=master cuirass
6527 @end example
6528
6529 @cindex continuous integration
6530 Obviously, since it uses the latest commit of the given branch, the result of
6531 such a command varies over time. Nevertheless it is a convenient way to
6532 rebuild entire software stacks against the latest commit of one or more
6533 packages. This is particularly useful in the context of continuous
6534 integration (CI).
6535
6536 Checkouts are kept in a cache under @file{~/.cache/guix/checkouts} to speed up
6537 consecutive accesses to the same repository. You may want to clean it up once
6538 in a while to save disk space.
6539
6540 @item --with-commit=@var{package}=@var{commit}
6541 This is similar to @code{--with-branch}, except that it builds from
6542 @var{commit} rather than the tip of a branch. @var{commit} must be a valid
6543 Git commit SHA1 identifier.
6544 @end table
6545
6546 @node Additional Build Options
6547 @subsection Additional Build Options
6548
6549 The command-line options presented below are specific to @command{guix
6550 build}.
6551
6552 @table @code
6553
6554 @item --quiet
6555 @itemx -q
6556 Build quietly, without displaying the build log; this is equivalent to
6557 @code{--verbosity=0}. Upon completion, the build log is kept in @file{/var}
6558 (or similar) and can always be retrieved using the @option{--log-file} option.
6559
6560 @item --file=@var{file}
6561 @itemx -f @var{file}
6562 Build the package, derivation, or other file-like object that the code within
6563 @var{file} evaluates to (@pxref{G-Expressions, file-like objects}).
6564
6565 As an example, @var{file} might contain a package definition like this
6566 (@pxref{Defining Packages}):
6567
6568 @example
6569 @verbatiminclude package-hello.scm
6570 @end example
6571
6572 @item --expression=@var{expr}
6573 @itemx -e @var{expr}
6574 Build the package or derivation @var{expr} evaluates to.
6575
6576 For example, @var{expr} may be @code{(@@ (gnu packages guile)
6577 guile-1.8)}, which unambiguously designates this specific variant of
6578 version 1.8 of Guile.
6579
6580 Alternatively, @var{expr} may be a G-expression, in which case it is used
6581 as a build program passed to @code{gexp->derivation}
6582 (@pxref{G-Expressions}).
6583
6584 Lastly, @var{expr} may refer to a zero-argument monadic procedure
6585 (@pxref{The Store Monad}). The procedure must return a derivation as a
6586 monadic value, which is then passed through @code{run-with-store}.
6587
6588 @item --source
6589 @itemx -S
6590 Build the source derivations of the packages, rather than the packages
6591 themselves.
6592
6593 For instance, @code{guix build -S gcc} returns something like
6594 @file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
6595 source tarball.
6596
6597 The returned source tarball is the result of applying any patches and
6598 code snippets specified in the package @code{origin} (@pxref{Defining
6599 Packages}).
6600
6601 @item --sources
6602 Fetch and return the source of @var{package-or-derivation} and all their
6603 dependencies, recursively. This is a handy way to obtain a local copy
6604 of all the source code needed to build @var{packages}, allowing you to
6605 eventually build them even without network access. It is an extension
6606 of the @code{--source} option and can accept one of the following
6607 optional argument values:
6608
6609 @table @code
6610 @item package
6611 This value causes the @code{--sources} option to behave in the same way
6612 as the @code{--source} option.
6613
6614 @item all
6615 Build the source derivations of all packages, including any source that
6616 might be listed as @code{inputs}. This is the default value.
6617
6618 @example
6619 $ guix build --sources tzdata
6620 The following derivations will be built:
6621 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
6622 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
6623 @end example
6624
6625 @item transitive
6626 Build the source derivations of all packages, as well of all transitive
6627 inputs to the packages. This can be used e.g.@: to
6628 prefetch package source for later offline building.
6629
6630 @example
6631 $ guix build --sources=transitive tzdata
6632 The following derivations will be built:
6633 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
6634 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
6635 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
6636 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
6637 /gnu/store/@dots{}-make-4.1.tar.xz.drv
6638 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
6639 @dots{}
6640 @end example
6641
6642 @end table
6643
6644 @item --system=@var{system}
6645 @itemx -s @var{system}
6646 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
6647 the system type of the build host.
6648
6649 @quotation Note
6650 The @code{--system} flag is for @emph{native} compilation and must not
6651 be confused with cross-compilation. See @code{--target} below for
6652 information on cross-compilation.
6653 @end quotation
6654
6655 An example use of this is on Linux-based systems, which can emulate
6656 different personalities. For instance, passing
6657 @code{--system=i686-linux} on an @code{x86_64-linux} system or
6658 @code{--system=armhf-linux} on an @code{aarch64-linux} system allows you
6659 to build packages in a complete 32-bit environment.
6660
6661 @quotation Note
6662 Building for an @code{armhf-linux} system is unconditionally enabled on
6663 @code{aarch64-linux} machines, although certain aarch64 chipsets do not
6664 allow for this functionality, notably the ThunderX.
6665 @end quotation
6666
6667 Similarly, when transparent emulation with QEMU and @code{binfmt_misc}
6668 is enabled (@pxref{Virtualization Services,
6669 @code{qemu-binfmt-service-type}}), you can build for any system for
6670 which a QEMU @code{binfmt_misc} handler is installed.
6671
6672 Builds for a system other than that of the machine you are using can
6673 also be offloaded to a remote machine of the right architecture.
6674 @xref{Daemon Offload Setup}, for more information on offloading.
6675
6676 @item --target=@var{triplet}
6677 @cindex cross-compilation
6678 Cross-build for @var{triplet}, which must be a valid GNU triplet, such
6679 as @code{"mips64el-linux-gnu"} (@pxref{Specifying target triplets, GNU
6680 configuration triplets,, autoconf, Autoconf}).
6681
6682 @anchor{build-check}
6683 @item --check
6684 @cindex determinism, checking
6685 @cindex reproducibility, checking
6686 Rebuild @var{package-or-derivation}, which are already available in the
6687 store, and raise an error if the build results are not bit-for-bit
6688 identical.
6689
6690 This mechanism allows you to check whether previously installed
6691 substitutes are genuine (@pxref{Substitutes}), or whether the build result
6692 of a package is deterministic. @xref{Invoking guix challenge}, for more
6693 background information and tools.
6694
6695 When used in conjunction with @option{--keep-failed}, the differing
6696 output is kept in the store, under @file{/gnu/store/@dots{}-check}.
6697 This makes it easy to look for differences between the two results.
6698
6699 @item --repair
6700 @cindex repairing store items
6701 @cindex corruption, recovering from
6702 Attempt to repair the specified store items, if they are corrupt, by
6703 re-downloading or rebuilding them.
6704
6705 This operation is not atomic and thus restricted to @code{root}.
6706
6707 @item --derivations
6708 @itemx -d
6709 Return the derivation paths, not the output paths, of the given
6710 packages.
6711
6712 @item --root=@var{file}
6713 @itemx -r @var{file}
6714 @cindex GC roots, adding
6715 @cindex garbage collector roots, adding
6716 Make @var{file} a symlink to the result, and register it as a garbage
6717 collector root.
6718
6719 Consequently, the results of this @command{guix build} invocation are
6720 protected from garbage collection until @var{file} is removed. When
6721 that option is omitted, build results are eligible for garbage
6722 collection as soon as the build completes. @xref{Invoking guix gc}, for
6723 more on GC roots.
6724
6725 @item --log-file
6726 @cindex build logs, access
6727 Return the build log file names or URLs for the given
6728 @var{package-or-derivation}, or raise an error if build logs are
6729 missing.
6730
6731 This works regardless of how packages or derivations are specified. For
6732 instance, the following invocations are equivalent:
6733
6734 @example
6735 guix build --log-file `guix build -d guile`
6736 guix build --log-file `guix build guile`
6737 guix build --log-file guile
6738 guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
6739 @end example
6740
6741 If a log is unavailable locally, and unless @code{--no-substitutes} is
6742 passed, the command looks for a corresponding log on one of the
6743 substitute servers (as specified with @code{--substitute-urls}.)
6744
6745 So for instance, imagine you want to see the build log of GDB on MIPS,
6746 but you are actually on an @code{x86_64} machine:
6747
6748 @example
6749 $ guix build --log-file gdb -s mips64el-linux
6750 https://@value{SUBSTITUTE-SERVER}/log/@dots{}-gdb-7.10
6751 @end example
6752
6753 You can freely access a huge library of build logs!
6754 @end table
6755
6756 @node Debugging Build Failures
6757 @subsection Debugging Build Failures
6758
6759 @cindex build failures, debugging
6760 When defining a new package (@pxref{Defining Packages}), you will
6761 probably find yourself spending some time debugging and tweaking the
6762 build until it succeeds. To do that, you need to operate the build
6763 commands yourself in an environment as close as possible to the one the
6764 build daemon uses.
6765
6766 To that end, the first thing to do is to use the @option{--keep-failed}
6767 or @option{-K} option of @command{guix build}, which will keep the
6768 failed build tree in @file{/tmp} or whatever directory you specified as
6769 @code{TMPDIR} (@pxref{Invoking guix build, @code{--keep-failed}}).
6770
6771 From there on, you can @command{cd} to the failed build tree and source
6772 the @file{environment-variables} file, which contains all the
6773 environment variable definitions that were in place when the build
6774 failed. So let's say you're debugging a build failure in package
6775 @code{foo}; a typical session would look like this:
6776
6777 @example
6778 $ guix build foo -K
6779 @dots{} @i{build fails}
6780 $ cd /tmp/guix-build-foo.drv-0
6781 $ source ./environment-variables
6782 $ cd foo-1.2
6783 @end example
6784
6785 Now, you can invoke commands as if you were the daemon (almost) and
6786 troubleshoot your build process.
6787
6788 Sometimes it happens that, for example, a package's tests pass when you
6789 run them manually but they fail when the daemon runs them. This can
6790 happen because the daemon runs builds in containers where, unlike in our
6791 environment above, network access is missing, @file{/bin/sh} does not
6792 exist, etc. (@pxref{Build Environment Setup}).
6793
6794 In such cases, you may need to run inspect the build process from within
6795 a container similar to the one the build daemon creates:
6796
6797 @example
6798 $ guix build -K foo
6799 @dots{}
6800 $ cd /tmp/guix-build-foo.drv-0
6801 $ guix environment --no-grafts -C foo --ad-hoc strace gdb
6802 [env]# source ./environment-variables
6803 [env]# cd foo-1.2
6804 @end example
6805
6806 Here, @command{guix environment -C} creates a container and spawns a new
6807 shell in it (@pxref{Invoking guix environment}). The @command{--ad-hoc
6808 strace gdb} part adds the @command{strace} and @command{gdb} commands to
6809 the container, which would may find handy while debugging. The
6810 @option{--no-grafts} option makes sure we get the exact same
6811 environment, with ungrafted packages (@pxref{Security Updates}, for more
6812 info on grafts).
6813
6814 To get closer to a container like that used by the build daemon, we can
6815 remove @file{/bin/sh}:
6816
6817 @example
6818 [env]# rm /bin/sh
6819 @end example
6820
6821 (Don't worry, this is harmless: this is all happening in the throw-away
6822 container created by @command{guix environment}.)
6823
6824 The @command{strace} command is probably not in the search path, but we
6825 can run:
6826
6827 @example
6828 [env]# $GUIX_ENVIRONMENT/bin/strace -f -o log make check
6829 @end example
6830
6831 In this way, not only you will have reproduced the environment variables
6832 the daemon uses, you will also be running the build process in a container
6833 similar to the one the daemon uses.
6834
6835
6836 @node Invoking guix edit
6837 @section Invoking @command{guix edit}
6838
6839 @cindex @command{guix edit}
6840 @cindex package definition, editing
6841 So many packages, so many source files! The @command{guix edit} command
6842 facilitates the life of users and packagers by pointing their editor at
6843 the source file containing the definition of the specified packages.
6844 For instance:
6845
6846 @example
6847 guix edit gcc@@4.9 vim
6848 @end example
6849
6850 @noindent
6851 launches the program specified in the @code{VISUAL} or in the
6852 @code{EDITOR} environment variable to view the recipe of GCC@tie{}4.9.3
6853 and that of Vim.
6854
6855 If you are using a Guix Git checkout (@pxref{Building from Git}), or
6856 have created your own packages on @code{GUIX_PACKAGE_PATH}
6857 (@pxref{Package Modules}), you will be able to edit the package
6858 recipes. In other cases, you will be able to examine the read-only recipes
6859 for packages currently in the store.
6860
6861
6862 @node Invoking guix download
6863 @section Invoking @command{guix download}
6864
6865 @cindex @command{guix download}
6866 @cindex downloading package sources
6867 When writing a package definition, developers typically need to download
6868 a source tarball, compute its SHA256 hash, and write that
6869 hash in the package definition (@pxref{Defining Packages}). The
6870 @command{guix download} tool helps with this task: it downloads a file
6871 from the given URI, adds it to the store, and prints both its file name
6872 in the store and its SHA256 hash.
6873
6874 The fact that the downloaded file is added to the store saves bandwidth:
6875 when the developer eventually tries to build the newly defined package
6876 with @command{guix build}, the source tarball will not have to be
6877 downloaded again because it is already in the store. It is also a
6878 convenient way to temporarily stash files, which may be deleted
6879 eventually (@pxref{Invoking guix gc}).
6880
6881 The @command{guix download} command supports the same URIs as used in
6882 package definitions. In particular, it supports @code{mirror://} URIs.
6883 @code{https} URIs (HTTP over TLS) are supported @emph{provided} the
6884 Guile bindings for GnuTLS are available in the user's environment; when
6885 they are not available, an error is raised. @xref{Guile Preparations,
6886 how to install the GnuTLS bindings for Guile,, gnutls-guile,
6887 GnuTLS-Guile}, for more information.
6888
6889 @command{guix download} verifies HTTPS server certificates by loading
6890 the certificates of X.509 authorities from the directory pointed to by
6891 the @code{SSL_CERT_DIR} environment variable (@pxref{X.509
6892 Certificates}), unless @option{--no-check-certificate} is used.
6893
6894 The following options are available:
6895
6896 @table @code
6897 @item --format=@var{fmt}
6898 @itemx -f @var{fmt}
6899 Write the hash in the format specified by @var{fmt}. For more
6900 information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
6901
6902 @item --no-check-certificate
6903 Do not validate the X.509 certificates of HTTPS servers.
6904
6905 When using this option, you have @emph{absolutely no guarantee} that you
6906 are communicating with the authentic server responsible for the given
6907 URL, which makes you vulnerable to ``man-in-the-middle'' attacks.
6908
6909 @item --output=@var{file}
6910 @itemx -o @var{file}
6911 Save the downloaded file to @var{file} instead of adding it to the
6912 store.
6913 @end table
6914
6915 @node Invoking guix hash
6916 @section Invoking @command{guix hash}
6917
6918 @cindex @command{guix hash}
6919 The @command{guix hash} command computes the SHA256 hash of a file.
6920 It is primarily a convenience tool for anyone contributing to the
6921 distribution: it computes the cryptographic hash of a file, which can be
6922 used in the definition of a package (@pxref{Defining Packages}).
6923
6924 The general syntax is:
6925
6926 @example
6927 guix hash @var{option} @var{file}
6928 @end example
6929
6930 When @var{file} is @code{-} (a hyphen), @command{guix hash} computes the
6931 hash of data read from standard input. @command{guix hash} has the
6932 following options:
6933
6934 @table @code
6935
6936 @item --format=@var{fmt}
6937 @itemx -f @var{fmt}
6938 Write the hash in the format specified by @var{fmt}.
6939
6940 Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
6941 (@code{hex} and @code{hexadecimal} can be used as well).
6942
6943 If the @option{--format} option is not specified, @command{guix hash}
6944 will output the hash in @code{nix-base32}. This representation is used
6945 in the definitions of packages.
6946
6947 @item --recursive
6948 @itemx -r
6949 Compute the hash on @var{file} recursively.
6950
6951 In this case, the hash is computed on an archive containing @var{file},
6952 including its children if it is a directory. Some of the metadata of
6953 @var{file} is part of the archive; for instance, when @var{file} is a
6954 regular file, the hash is different depending on whether @var{file} is
6955 executable or not. Metadata such as time stamps has no impact on the
6956 hash (@pxref{Invoking guix archive}).
6957 @c FIXME: Replace xref above with xref to an ``Archive'' section when
6958 @c it exists.
6959
6960 @item --exclude-vcs
6961 @itemx -x
6962 When combined with @option{--recursive}, exclude version control system
6963 directories (@file{.bzr}, @file{.git}, @file{.hg}, etc.)
6964
6965 @vindex git-fetch
6966 As an example, here is how you would compute the hash of a Git checkout,
6967 which is useful when using the @code{git-fetch} method (@pxref{origin
6968 Reference}):
6969
6970 @example
6971 $ git clone http://example.org/foo.git
6972 $ cd foo
6973 $ guix hash -rx .
6974 @end example
6975 @end table
6976
6977 @node Invoking guix import
6978 @section Invoking @command{guix import}
6979
6980 @cindex importing packages
6981 @cindex package import
6982 @cindex package conversion
6983 @cindex Invoking @command{guix import}
6984 The @command{guix import} command is useful for people who would like to
6985 add a package to the distribution with as little work as
6986 possible---a legitimate demand. The command knows of a few
6987 repositories from which it can ``import'' package metadata. The result
6988 is a package definition, or a template thereof, in the format we know
6989 (@pxref{Defining Packages}).
6990
6991 The general syntax is:
6992
6993 @example
6994 guix import @var{importer} @var{options}@dots{}
6995 @end example
6996
6997 @var{importer} specifies the source from which to import package
6998 metadata, and @var{options} specifies a package identifier and other
6999 options specific to @var{importer}. Currently, the available
7000 ``importers'' are:
7001
7002 @table @code
7003 @item gnu
7004 Import metadata for the given GNU package. This provides a template
7005 for the latest version of that GNU package, including the hash of its
7006 source tarball, and its canonical synopsis and description.
7007
7008 Additional information such as the package dependencies and its
7009 license needs to be figured out manually.
7010
7011 For example, the following command returns a package definition for
7012 GNU@tie{}Hello:
7013
7014 @example
7015 guix import gnu hello
7016 @end example
7017
7018 Specific command-line options are:
7019
7020 @table @code
7021 @item --key-download=@var{policy}
7022 As for @code{guix refresh}, specify the policy to handle missing OpenPGP
7023 keys when verifying the package signature. @xref{Invoking guix
7024 refresh, @code{--key-download}}.
7025 @end table
7026
7027 @item pypi
7028 @cindex pypi
7029 Import metadata from the @uref{https://pypi.python.org/, Python Package
7030 Index}. Information is taken from the JSON-formatted description
7031 available at @code{pypi.python.org} and usually includes all the relevant
7032 information, including package dependencies. For maximum efficiency, it
7033 is recommended to install the @command{unzip} utility, so that the
7034 importer can unzip Python wheels and gather data from them.
7035
7036 The command below imports metadata for the @code{itsdangerous} Python
7037 package:
7038
7039 @example
7040 guix import pypi itsdangerous
7041 @end example
7042
7043 @table @code
7044 @item --recursive
7045 @itemx -r
7046 Traverse the dependency graph of the given upstream package recursively
7047 and generate package expressions for all those packages that are not yet
7048 in Guix.
7049 @end table
7050
7051 @item gem
7052 @cindex gem
7053 Import metadata from @uref{https://rubygems.org/, RubyGems}. Information
7054 is taken from the JSON-formatted description available at
7055 @code{rubygems.org} and includes most relevant information, including
7056 runtime dependencies. There are some caveats, however. The metadata
7057 doesn't distinguish between synopses and descriptions, so the same string
7058 is used for both fields. Additionally, the details of non-Ruby
7059 dependencies required to build native extensions is unavailable and left
7060 as an exercise to the packager.
7061
7062 The command below imports metadata for the @code{rails} Ruby package:
7063
7064 @example
7065 guix import gem rails
7066 @end example
7067
7068 @table @code
7069 @item --recursive
7070 @itemx -r
7071 Traverse the dependency graph of the given upstream package recursively
7072 and generate package expressions for all those packages that are not yet
7073 in Guix.
7074 @end table
7075
7076 @item cpan
7077 @cindex CPAN
7078 Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}.
7079 Information is taken from the JSON-formatted metadata provided through
7080 @uref{https://fastapi.metacpan.org/, MetaCPAN's API} and includes most
7081 relevant information, such as module dependencies. License information
7082 should be checked closely. If Perl is available in the store, then the
7083 @code{corelist} utility will be used to filter core modules out of the
7084 list of dependencies.
7085
7086 The command command below imports metadata for the @code{Acme::Boolean}
7087 Perl module:
7088
7089 @example
7090 guix import cpan Acme::Boolean
7091 @end example
7092
7093 @item cran
7094 @cindex CRAN
7095 @cindex Bioconductor
7096 Import metadata from @uref{https://cran.r-project.org/, CRAN}, the
7097 central repository for the @uref{http://r-project.org, GNU@tie{}R
7098 statistical and graphical environment}.
7099
7100 Information is extracted from the @code{DESCRIPTION} file of the package.
7101
7102 The command command below imports metadata for the @code{Cairo}
7103 R package:
7104
7105 @example
7106 guix import cran Cairo
7107 @end example
7108
7109 When @code{--recursive} is added, the importer will traverse the
7110 dependency graph of the given upstream package recursively and generate
7111 package expressions for all those packages that are not yet in Guix.
7112
7113 When @code{--archive=bioconductor} is added, metadata is imported from
7114 @uref{https://www.bioconductor.org/, Bioconductor}, a repository of R
7115 packages for for the analysis and comprehension of high-throughput
7116 genomic data in bioinformatics.
7117
7118 Information is extracted from the @code{DESCRIPTION} file of a package
7119 published on the web interface of the Bioconductor SVN repository.
7120
7121 The command below imports metadata for the @code{GenomicRanges}
7122 R package:
7123
7124 @example
7125 guix import cran --archive=bioconductor GenomicRanges
7126 @end example
7127
7128 @item texlive
7129 @cindex TeX Live
7130 @cindex CTAN
7131 Import metadata from @uref{http://www.ctan.org/, CTAN}, the
7132 comprehensive TeX archive network for TeX packages that are part of the
7133 @uref{https://www.tug.org/texlive/, TeX Live distribution}.
7134
7135 Information about the package is obtained through the XML API provided
7136 by CTAN, while the source code is downloaded from the SVN repository of
7137 the Tex Live project. This is done because the CTAN does not keep
7138 versioned archives.
7139
7140 The command command below imports metadata for the @code{fontspec}
7141 TeX package:
7142
7143 @example
7144 guix import texlive fontspec
7145 @end example
7146
7147 When @code{--archive=DIRECTORY} is added, the source code is downloaded
7148 not from the @file{latex} sub-directory of the @file{texmf-dist/source}
7149 tree in the TeX Live SVN repository, but from the specified sibling
7150 directory under the same root.
7151
7152 The command below imports metadata for the @code{ifxetex} package from
7153 CTAN while fetching the sources from the directory
7154 @file{texmf/source/generic}:
7155
7156 @example
7157 guix import texlive --archive=generic ifxetex
7158 @end example
7159
7160 @item json
7161 @cindex JSON, import
7162 Import package metadata from a local JSON file. Consider the following
7163 example package definition in JSON format:
7164
7165 @example
7166 @{
7167 "name": "hello",
7168 "version": "2.10",
7169 "source": "mirror://gnu/hello/hello-2.10.tar.gz",
7170 "build-system": "gnu",
7171 "home-page": "https://www.gnu.org/software/hello/",
7172 "synopsis": "Hello, GNU world: An example GNU package",
7173 "description": "GNU Hello prints a greeting.",
7174 "license": "GPL-3.0+",
7175 "native-inputs": ["gcc@@6"]
7176 @}
7177 @end example
7178
7179 The field names are the same as for the @code{<package>} record
7180 (@xref{Defining Packages}). References to other packages are provided
7181 as JSON lists of quoted package specification strings such as
7182 @code{guile} or @code{guile@@2.0}.
7183
7184 The importer also supports a more explicit source definition using the
7185 common fields for @code{<origin>} records:
7186
7187 @example
7188 @{
7189 @dots{}
7190 "source": @{
7191 "method": "url-fetch",
7192 "uri": "mirror://gnu/hello/hello-2.10.tar.gz",
7193 "sha256": @{
7194 "base32": "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"
7195 @}
7196 @}
7197 @dots{}
7198 @}
7199 @end example
7200
7201 The command below reads metadata from the JSON file @code{hello.json}
7202 and outputs a package expression:
7203
7204 @example
7205 guix import json hello.json
7206 @end example
7207
7208 @item nix
7209 Import metadata from a local copy of the source of the
7210 @uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
7211 relies on the @command{nix-instantiate} command of
7212 @uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
7213 typically written in a mixture of Nix-language and Bash code. This
7214 command only imports the high-level package structure that is written in
7215 the Nix language. It normally includes all the basic fields of a
7216 package definition.
7217
7218 When importing a GNU package, the synopsis and descriptions are replaced
7219 by their canonical upstream variant.
7220
7221 Usually, you will first need to do:
7222
7223 @example
7224 export NIX_REMOTE=daemon
7225 @end example
7226
7227 @noindent
7228 so that @command{nix-instantiate} does not try to open the Nix database.
7229
7230 As an example, the command below imports the package definition of
7231 LibreOffice (more precisely, it imports the definition of the package
7232 bound to the @code{libreoffice} top-level attribute):
7233
7234 @example
7235 guix import nix ~/path/to/nixpkgs libreoffice
7236 @end example
7237
7238 @item hackage
7239 @cindex hackage
7240 Import metadata from the Haskell community's central package archive
7241 @uref{https://hackage.haskell.org/, Hackage}. Information is taken from
7242 Cabal files and includes all the relevant information, including package
7243 dependencies.
7244
7245 Specific command-line options are:
7246
7247 @table @code
7248 @item --stdin
7249 @itemx -s
7250 Read a Cabal file from standard input.
7251 @item --no-test-dependencies
7252 @itemx -t
7253 Do not include dependencies required only by the test suites.
7254 @item --cabal-environment=@var{alist}
7255 @itemx -e @var{alist}
7256 @var{alist} is a Scheme alist defining the environment in which the
7257 Cabal conditionals are evaluated. The accepted keys are: @code{os},
7258 @code{arch}, @code{impl} and a string representing the name of a flag.
7259 The value associated with a flag has to be either the symbol
7260 @code{true} or @code{false}. The value associated with other keys
7261 has to conform to the Cabal file format definition. The default value
7262 associated with the keys @code{os}, @code{arch} and @code{impl} is
7263 @samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
7264 @item --recursive
7265 @itemx -r
7266 Traverse the dependency graph of the given upstream package recursively
7267 and generate package expressions for all those packages that are not yet
7268 in Guix.
7269 @end table
7270
7271 The command below imports metadata for the latest version of the
7272 @code{HTTP} Haskell package without including test dependencies and
7273 specifying the value of the flag @samp{network-uri} as @code{false}:
7274
7275 @example
7276 guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
7277 @end example
7278
7279 A specific package version may optionally be specified by following the
7280 package name by an at-sign and a version number as in the following example:
7281
7282 @example
7283 guix import hackage mtl@@2.1.3.1
7284 @end example
7285
7286 @item stackage
7287 @cindex stackage
7288 The @code{stackage} importer is a wrapper around the @code{hackage} one.
7289 It takes a package name, looks up the package version included in a
7290 long-term support (LTS) @uref{https://www.stackage.org, Stackage}
7291 release and uses the @code{hackage} importer to retrieve its metadata.
7292 Note that it is up to you to select an LTS release compatible with the
7293 GHC compiler used by Guix.
7294
7295 Specific command-line options are:
7296
7297 @table @code
7298 @item --no-test-dependencies
7299 @itemx -t
7300 Do not include dependencies required only by the test suites.
7301 @item --lts-version=@var{version}
7302 @itemx -l @var{version}
7303 @var{version} is the desired LTS release version. If omitted the latest
7304 release is used.
7305 @item --recursive
7306 @itemx -r
7307 Traverse the dependency graph of the given upstream package recursively
7308 and generate package expressions for all those packages that are not yet
7309 in Guix.
7310 @end table
7311
7312 The command below imports metadata for the @code{HTTP} Haskell package
7313 included in the LTS Stackage release version 7.18:
7314
7315 @example
7316 guix import stackage --lts-version=7.18 HTTP
7317 @end example
7318
7319 @item elpa
7320 @cindex elpa
7321 Import metadata from an Emacs Lisp Package Archive (ELPA) package
7322 repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
7323
7324 Specific command-line options are:
7325
7326 @table @code
7327 @item --archive=@var{repo}
7328 @itemx -a @var{repo}
7329 @var{repo} identifies the archive repository from which to retrieve the
7330 information. Currently the supported repositories and their identifiers
7331 are:
7332 @itemize -
7333 @item
7334 @uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7335 identifier. This is the default.
7336
7337 Packages from @code{elpa.gnu.org} are signed with one of the keys
7338 contained in the GnuPG keyring at
7339 @file{share/emacs/25.1/etc/package-keyring.gpg} (or similar) in the
7340 @code{emacs} package (@pxref{Package Installation, ELPA package
7341 signatures,, emacs, The GNU Emacs Manual}).
7342
7343 @item
7344 @uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7345 @code{melpa-stable} identifier.
7346
7347 @item
7348 @uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7349 identifier.
7350 @end itemize
7351
7352 @item --recursive
7353 @itemx -r
7354 Traverse the dependency graph of the given upstream package recursively
7355 and generate package expressions for all those packages that are not yet
7356 in Guix.
7357 @end table
7358
7359 @item crate
7360 @cindex crate
7361 Import metadata from the crates.io Rust package repository
7362 @uref{https://crates.io, crates.io}.
7363
7364 @item opam
7365 @cindex OPAM
7366 @cindex OCaml
7367 Import metadata from the @uref{https://opam.ocaml.org/, OPAM} package
7368 repository used by the OCaml community.
7369 @end table
7370
7371 The structure of the @command{guix import} code is modular. It would be
7372 useful to have more importers for other package formats, and your help
7373 is welcome here (@pxref{Contributing}).
7374
7375 @node Invoking guix refresh
7376 @section Invoking @command{guix refresh}
7377
7378 @cindex @command {guix refresh}
7379 The primary audience of the @command{guix refresh} command is developers
7380 of the GNU software distribution. By default, it reports any packages
7381 provided by the distribution that are outdated compared to the latest
7382 upstream version, like this:
7383
7384 @example
7385 $ guix refresh
7386 gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
7387 gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
7388 @end example
7389
7390 Alternately, one can specify packages to consider, in which case a
7391 warning is emitted for packages that lack an updater:
7392
7393 @example
7394 $ guix refresh coreutils guile guile-ssh
7395 gnu/packages/ssh.scm:205:2: warning: no updater for guile-ssh
7396 gnu/packages/guile.scm:136:12: guile would be upgraded from 2.0.12 to 2.0.13
7397 @end example
7398
7399 @command{guix refresh} browses the upstream repository of each package and determines
7400 the highest version number of the releases therein. The command
7401 knows how to update specific types of packages: GNU packages, ELPA
7402 packages, etc.---see the documentation for @option{--type} below. There
7403 are many packages, though, for which it lacks a method to determine
7404 whether a new upstream release is available. However, the mechanism is
7405 extensible, so feel free to get in touch with us to add a new method!
7406
7407 @table @code
7408
7409 @item --recursive
7410 Consider the packages specified, and all the packages upon which they depend.
7411
7412 @example
7413 $ guix refresh --recursive coreutils
7414 gnu/packages/acl.scm:35:2: warning: no updater for acl
7415 gnu/packages/m4.scm:30:12: info: 1.4.18 is already the latest version of m4
7416 gnu/packages/xml.scm:68:2: warning: no updater for expat
7417 gnu/packages/multiprecision.scm:40:12: info: 6.1.2 is already the latest version of gmp
7418 @dots{}
7419 @end example
7420
7421 @end table
7422
7423 Sometimes the upstream name differs from the package name used in Guix,
7424 and @command{guix refresh} needs a little help. Most updaters honor the
7425 @code{upstream-name} property in package definitions, which can be used
7426 to that effect:
7427
7428 @example
7429 (define-public network-manager
7430 (package
7431 (name "network-manager")
7432 ;; @dots{}
7433 (properties '((upstream-name . "NetworkManager")))))
7434 @end example
7435
7436 When passed @code{--update}, it modifies distribution source files to
7437 update the version numbers and source tarball hashes of those package
7438 recipes (@pxref{Defining Packages}). This is achieved by downloading
7439 each package's latest source tarball and its associated OpenPGP
7440 signature, authenticating the downloaded tarball against its signature
7441 using @command{gpg}, and finally computing its hash. When the public
7442 key used to sign the tarball is missing from the user's keyring, an
7443 attempt is made to automatically retrieve it from a public key server;
7444 when this is successful, the key is added to the user's keyring; otherwise,
7445 @command{guix refresh} reports an error.
7446
7447 The following options are supported:
7448
7449 @table @code
7450
7451 @item --expression=@var{expr}
7452 @itemx -e @var{expr}
7453 Consider the package @var{expr} evaluates to.
7454
7455 This is useful to precisely refer to a package, as in this example:
7456
7457 @example
7458 guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
7459 @end example
7460
7461 This command lists the dependents of the ``final'' libc (essentially all
7462 the packages.)
7463
7464 @item --update
7465 @itemx -u
7466 Update distribution source files (package recipes) in place. This is
7467 usually run from a checkout of the Guix source tree (@pxref{Running
7468 Guix Before It Is Installed}):
7469
7470 @example
7471 $ ./pre-inst-env guix refresh -s non-core -u
7472 @end example
7473
7474 @xref{Defining Packages}, for more information on package definitions.
7475
7476 @item --select=[@var{subset}]
7477 @itemx -s @var{subset}
7478 Select all the packages in @var{subset}, one of @code{core} or
7479 @code{non-core}.
7480
7481 The @code{core} subset refers to all the packages at the core of the
7482 distribution---i.e., packages that are used to build ``everything
7483 else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
7484 changing one of these packages in the distribution entails a rebuild of
7485 all the others. Thus, such updates are an inconvenience to users in
7486 terms of build time or bandwidth used to achieve the upgrade.
7487
7488 The @code{non-core} subset refers to the remaining packages. It is
7489 typically useful in cases where an update of the core packages would be
7490 inconvenient.
7491
7492 @item --manifest=@var{file}
7493 @itemx -m @var{file}
7494 Select all the packages from the manifest in @var{file}. This is useful to
7495 check if any packages of the user manifest can be updated.
7496
7497 @item --type=@var{updater}
7498 @itemx -t @var{updater}
7499 Select only packages handled by @var{updater} (may be a comma-separated
7500 list of updaters). Currently, @var{updater} may be one of:
7501
7502 @table @code
7503 @item gnu
7504 the updater for GNU packages;
7505 @item gnome
7506 the updater for GNOME packages;
7507 @item kde
7508 the updater for KDE packages;
7509 @item xorg
7510 the updater for X.org packages;
7511 @item kernel.org
7512 the updater for packages hosted on kernel.org;
7513 @item elpa
7514 the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
7515 @item cran
7516 the updater for @uref{https://cran.r-project.org/, CRAN} packages;
7517 @item bioconductor
7518 the updater for @uref{https://www.bioconductor.org/, Bioconductor} R packages;
7519 @item cpan
7520 the updater for @uref{http://www.cpan.org/, CPAN} packages;
7521 @item pypi
7522 the updater for @uref{https://pypi.python.org, PyPI} packages.
7523 @item gem
7524 the updater for @uref{https://rubygems.org, RubyGems} packages.
7525 @item github
7526 the updater for @uref{https://github.com, GitHub} packages.
7527 @item hackage
7528 the updater for @uref{https://hackage.haskell.org, Hackage} packages.
7529 @item stackage
7530 the updater for @uref{https://www.stackage.org, Stackage} packages.
7531 @item crate
7532 the updater for @uref{https://crates.io, Crates} packages.
7533 @end table
7534
7535 For instance, the following command only checks for updates of Emacs
7536 packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
7537
7538 @example
7539 $ guix refresh --type=elpa,cran
7540 gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
7541 gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
7542 @end example
7543
7544 @end table
7545
7546 In addition, @command{guix refresh} can be passed one or more package
7547 names, as in this example:
7548
7549 @example
7550 $ ./pre-inst-env guix refresh -u emacs idutils gcc@@4.8
7551 @end example
7552
7553 @noindent
7554 The command above specifically updates the @code{emacs} and
7555 @code{idutils} packages. The @code{--select} option would have no
7556 effect in this case.
7557
7558 When considering whether to upgrade a package, it is sometimes
7559 convenient to know which packages would be affected by the upgrade and
7560 should be checked for compatibility. For this the following option may
7561 be used when passing @command{guix refresh} one or more package names:
7562
7563 @table @code
7564
7565 @item --list-updaters
7566 @itemx -L
7567 List available updaters and exit (see @option{--type} above.)
7568
7569 For each updater, display the fraction of packages it covers; at the
7570 end, display the fraction of packages covered by all these updaters.
7571
7572 @item --list-dependent
7573 @itemx -l
7574 List top-level dependent packages that would need to be rebuilt as a
7575 result of upgrading one or more packages.
7576
7577 @xref{Invoking guix graph, the @code{reverse-package} type of
7578 @command{guix graph}}, for information on how to visualize the list of
7579 dependents of a package.
7580
7581 @end table
7582
7583 Be aware that the @code{--list-dependent} option only
7584 @emph{approximates} the rebuilds that would be required as a result of
7585 an upgrade. More rebuilds might be required under some circumstances.
7586
7587 @example
7588 $ guix refresh --list-dependent flex
7589 Building the following 120 packages would ensure 213 dependent packages are rebuilt:
7590 hop@@2.4.0 geiser@@0.4 notmuch@@0.18 mu@@0.9.9.5 cflow@@1.4 idutils@@4.6 @dots{}
7591 @end example
7592
7593 The command above lists a set of packages that could be built to check
7594 for compatibility with an upgraded @code{flex} package.
7595
7596 @table @code
7597
7598 @item --list-transitive
7599 List all the packages which one or more packages depend upon.
7600
7601 @example
7602 $ guix refresh --list-transitive flex
7603 flex@@2.6.4 depends on the following 25 packages: perl@@5.28.0 help2man@@1.47.6
7604 bison@@3.0.5 indent@@2.2.10 tar@@1.30 gzip@@1.9 bzip2@@1.0.6 xz@@5.2.4 file@@5.33 @dots{}
7605 @end example
7606
7607 @end table
7608
7609 The command above lists a set of packages which, when changed, would cause
7610 @code{flex} to be rebuilt.
7611
7612 The following options can be used to customize GnuPG operation:
7613
7614 @table @code
7615
7616 @item --gpg=@var{command}
7617 Use @var{command} as the GnuPG 2.x command. @var{command} is searched
7618 for in @code{$PATH}.
7619
7620 @item --keyring=@var{file}
7621 Use @var{file} as the keyring for upstream keys. @var{file} must be in the
7622 @dfn{keybox format}. Keybox files usually have a name ending in @file{.kbx}
7623 and the GNU@tie{}Privacy Guard (GPG) can manipulate these files
7624 (@pxref{kbxutil, @command{kbxutil},, gnupg, Using the GNU Privacy Guard}, for
7625 information on a tool to manipulate keybox files).
7626
7627 When this option is omitted, @command{guix refresh} uses
7628 @file{~/.config/guix/upstream/trustedkeys.kbx} as the keyring for upstream
7629 signing keys. OpenPGP signatures are checked against keys from this keyring;
7630 missing keys are downloaded to this keyring as well (see
7631 @option{--key-download} below.)
7632
7633 You can export keys from your default GPG keyring into a keybox file using
7634 commands like this one:
7635
7636 @example
7637 gpg --export rms@@gnu.org | kbxutil --import-openpgp >> mykeyring.kbx
7638 @end example
7639
7640 Likewise, you can fetch keys to a specific keybox file like this:
7641
7642 @example
7643 gpg --no-default-keyring --keyring mykeyring.kbx \
7644 --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
7645 @end example
7646
7647 @ref{GPG Configuration Options, @option{--keyring},, gnupg, Using the GNU
7648 Privacy Guard}, for more information on GPG's @option{--keyring} option.
7649
7650 @item --key-download=@var{policy}
7651 Handle missing OpenPGP keys according to @var{policy}, which may be one
7652 of:
7653
7654 @table @code
7655 @item always
7656 Always download missing OpenPGP keys from the key server, and add them
7657 to the user's GnuPG keyring.
7658
7659 @item never
7660 Never try to download missing OpenPGP keys. Instead just bail out.
7661
7662 @item interactive
7663 When a package signed with an unknown OpenPGP key is encountered, ask
7664 the user whether to download it or not. This is the default behavior.
7665 @end table
7666
7667 @item --key-server=@var{host}
7668 Use @var{host} as the OpenPGP key server when importing a public key.
7669
7670 @end table
7671
7672 The @code{github} updater uses the
7673 @uref{https://developer.github.com/v3/, GitHub API} to query for new
7674 releases. When used repeatedly e.g.@: when refreshing all packages,
7675 GitHub will eventually refuse to answer any further API requests. By
7676 default 60 API requests per hour are allowed, and a full refresh on all
7677 GitHub packages in Guix requires more than this. Authentication with
7678 GitHub through the use of an API token alleviates these limits. To use
7679 an API token, set the environment variable @code{GUIX_GITHUB_TOKEN} to a
7680 token procured from @uref{https://github.com/settings/tokens} or
7681 otherwise.
7682
7683
7684 @node Invoking guix lint
7685 @section Invoking @command{guix lint}
7686
7687 @cindex @command{guix lint}
7688 @cindex package, checking for errors
7689 The @command{guix lint} command is meant to help package developers avoid
7690 common errors and use a consistent style. It runs a number of checks on
7691 a given set of packages in order to find common mistakes in their
7692 definitions. Available @dfn{checkers} include (see
7693 @code{--list-checkers} for a complete list):
7694
7695 @table @code
7696 @item synopsis
7697 @itemx description
7698 Validate certain typographical and stylistic rules about package
7699 descriptions and synopses.
7700
7701 @item inputs-should-be-native
7702 Identify inputs that should most likely be native inputs.
7703
7704 @item source
7705 @itemx home-page
7706 @itemx mirror-url
7707 @itemx github-url
7708 @itemx source-file-name
7709 Probe @code{home-page} and @code{source} URLs and report those that are
7710 invalid. Suggest a @code{mirror://} URL when applicable. If the
7711 @code{source} URL redirects to a GitHub URL, recommend usage of the GitHub
7712 URL. Check that the source file name is meaningful, e.g.@: is not just a
7713 version number or ``git-checkout'', without a declared @code{file-name}
7714 (@pxref{origin Reference}).
7715
7716 @item source-unstable-tarball
7717 Parse the @code{source} URL to determine if a tarball from GitHub is
7718 autogenerated or if it is a release tarball. Unfortunately GitHub's
7719 autogenerated tarballs are sometimes regenerated.
7720
7721 @item cve
7722 @cindex security vulnerabilities
7723 @cindex CVE, Common Vulnerabilities and Exposures
7724 Report known vulnerabilities found in the Common Vulnerabilities and
7725 Exposures (CVE) databases of the current and past year
7726 @uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
7727 NIST}.
7728
7729 To view information about a particular vulnerability, visit pages such as:
7730
7731 @itemize
7732 @item
7733 @indicateurl{https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-YYYY-ABCD}
7734 @item
7735 @indicateurl{https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-YYYY-ABCD}
7736 @end itemize
7737
7738 @noindent
7739 where @code{CVE-YYYY-ABCD} is the CVE identifier---e.g.,
7740 @code{CVE-2015-7554}.
7741
7742 Package developers can specify in package recipes the
7743 @uref{https://nvd.nist.gov/cpe.cfm,Common Platform Enumeration (CPE)}
7744 name and version of the package when they differ from the name or version
7745 that Guix uses, as in this example:
7746
7747 @example
7748 (package
7749 (name "grub")
7750 ;; @dots{}
7751 ;; CPE calls this package "grub2".
7752 (properties '((cpe-name . "grub2")
7753 (cpe-version . "2.3")))
7754 @end example
7755
7756 @c See <http://www.openwall.com/lists/oss-security/2017/03/15/3>.
7757 Some entries in the CVE database do not specify which version of a
7758 package they apply to, and would thus ``stick around'' forever. Package
7759 developers who found CVE alerts and verified they can be ignored can
7760 declare them as in this example:
7761
7762 @example
7763 (package
7764 (name "t1lib")
7765 ;; @dots{}
7766 ;; These CVEs no longer apply and can be safely ignored.
7767 (properties `((lint-hidden-cve . ("CVE-2011-0433"
7768 "CVE-2011-1553"
7769 "CVE-2011-1554"
7770 "CVE-2011-5244")))))
7771 @end example
7772
7773 @item formatting
7774 Warn about obvious source code formatting issues: trailing white space,
7775 use of tabulations, etc.
7776 @end table
7777
7778 The general syntax is:
7779
7780 @example
7781 guix lint @var{options} @var{package}@dots{}
7782 @end example
7783
7784 If no package is given on the command line, then all packages are checked.
7785 The @var{options} may be zero or more of the following:
7786
7787 @table @code
7788 @item --list-checkers
7789 @itemx -l
7790 List and describe all the available checkers that will be run on packages
7791 and exit.
7792
7793 @item --checkers
7794 @itemx -c
7795 Only enable the checkers specified in a comma-separated list using the
7796 names returned by @code{--list-checkers}.
7797
7798 @end table
7799
7800 @node Invoking guix size
7801 @section Invoking @command{guix size}
7802
7803 @cindex size
7804 @cindex package size
7805 @cindex closure
7806 @cindex @command{guix size}
7807 The @command{guix size} command helps package developers profile the
7808 disk usage of packages. It is easy to overlook the impact of an
7809 additional dependency added to a package, or the impact of using a
7810 single output for a package that could easily be split (@pxref{Packages
7811 with Multiple Outputs}). Such are the typical issues that
7812 @command{guix size} can highlight.
7813
7814 The command can be passed one or more package specifications
7815 such as @code{gcc@@4.8}
7816 or @code{guile:debug}, or a file name in the store. Consider this
7817 example:
7818
7819 @example
7820 $ guix size coreutils
7821 store item total self
7822 /gnu/store/@dots{}-gcc-5.5.0-lib 60.4 30.1 38.1%
7823 /gnu/store/@dots{}-glibc-2.27 30.3 28.8 36.6%
7824 /gnu/store/@dots{}-coreutils-8.28 78.9 15.0 19.0%
7825 /gnu/store/@dots{}-gmp-6.1.2 63.1 2.7 3.4%
7826 /gnu/store/@dots{}-bash-static-4.4.12 1.5 1.5 1.9%
7827 /gnu/store/@dots{}-acl-2.2.52 61.1 0.4 0.5%
7828 /gnu/store/@dots{}-attr-2.4.47 60.6 0.2 0.3%
7829 /gnu/store/@dots{}-libcap-2.25 60.5 0.2 0.2%
7830 total: 78.9 MiB
7831 @end example
7832
7833 @cindex closure
7834 The store items listed here constitute the @dfn{transitive closure} of
7835 Coreutils---i.e., Coreutils and all its dependencies, recursively---as
7836 would be returned by:
7837
7838 @example
7839 $ guix gc -R /gnu/store/@dots{}-coreutils-8.23
7840 @end example
7841
7842 Here the output shows three columns next to store items. The first column,
7843 labeled ``total'', shows the size in mebibytes (MiB) of the closure of
7844 the store item---that is, its own size plus the size of all its
7845 dependencies. The next column, labeled ``self'', shows the size of the
7846 item itself. The last column shows the ratio of the size of the item
7847 itself to the space occupied by all the items listed here.
7848
7849 In this example, we see that the closure of Coreutils weighs in at
7850 79@tie{}MiB, most of which is taken by libc and GCC's run-time support
7851 libraries. (That libc and GCC's libraries represent a large fraction of
7852 the closure is not a problem @i{per se} because they are always available
7853 on the system anyway.)
7854
7855 When the package(s) passed to @command{guix size} are available in the
7856 store@footnote{More precisely, @command{guix size} looks for the
7857 @emph{ungrafted} variant of the given package(s), as returned by
7858 @code{guix build @var{package} --no-grafts}. @xref{Security Updates},
7859 for information on grafts.}, @command{guix size} queries the daemon to determine its
7860 dependencies, and measures its size in the store, similar to @command{du
7861 -ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
7862 Coreutils}).
7863
7864 When the given packages are @emph{not} in the store, @command{guix size}
7865 reports information based on the available substitutes
7866 (@pxref{Substitutes}). This makes it possible it to profile disk usage of
7867 store items that are not even on disk, only available remotely.
7868
7869 You can also specify several package names:
7870
7871 @example
7872 $ guix size coreutils grep sed bash
7873 store item total self
7874 /gnu/store/@dots{}-coreutils-8.24 77.8 13.8 13.4%
7875 /gnu/store/@dots{}-grep-2.22 73.1 0.8 0.8%
7876 /gnu/store/@dots{}-bash-4.3.42 72.3 4.7 4.6%
7877 /gnu/store/@dots{}-readline-6.3 67.6 1.2 1.2%
7878 @dots{}
7879 total: 102.3 MiB
7880 @end example
7881
7882 @noindent
7883 In this example we see that the combination of the four packages takes
7884 102.3@tie{}MiB in total, which is much less than the sum of each closure
7885 since they have a lot of dependencies in common.
7886
7887 The available options are:
7888
7889 @table @option
7890
7891 @item --substitute-urls=@var{urls}
7892 Use substitute information from @var{urls}.
7893 @xref{client-substitute-urls, the same option for @code{guix build}}.
7894
7895 @item --sort=@var{key}
7896 Sort lines according to @var{key}, one of the following options:
7897
7898 @table @code
7899 @item self
7900 the size of each item (the default);
7901 @item closure
7902 the total size of the item's closure.
7903 @end table
7904
7905 @item --map-file=@var{file}
7906 Write a graphical map of disk usage in PNG format to @var{file}.
7907
7908 For the example above, the map looks like this:
7909
7910 @image{images/coreutils-size-map,5in,, map of Coreutils disk usage
7911 produced by @command{guix size}}
7912
7913 This option requires that
7914 @uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
7915 installed and visible in Guile's module search path. When that is not
7916 the case, @command{guix size} fails as it tries to load it.
7917
7918 @item --system=@var{system}
7919 @itemx -s @var{system}
7920 Consider packages for @var{system}---e.g., @code{x86_64-linux}.
7921
7922 @end table
7923
7924 @node Invoking guix graph
7925 @section Invoking @command{guix graph}
7926
7927 @cindex DAG
7928 @cindex @command{guix graph}
7929 @cindex package dependencies
7930 Packages and their dependencies form a @dfn{graph}, specifically a
7931 directed acyclic graph (DAG). It can quickly become difficult to have a
7932 mental model of the package DAG, so the @command{guix graph} command
7933 provides a visual representation of the DAG. By default,
7934 @command{guix graph} emits a DAG representation in the input format of
7935 @uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
7936 directly to the @command{dot} command of Graphviz. It can also emit an
7937 HTML page with embedded JavaScript code to display a ``chord diagram''
7938 in a Web browser, using the @uref{https://d3js.org/, d3.js} library, or
7939 emit Cypher queries to construct a graph in a graph database supporting
7940 the @uref{http://www.opencypher.org/, openCypher} query language.
7941 The general syntax is:
7942
7943 @example
7944 guix graph @var{options} @var{package}@dots{}
7945 @end example
7946
7947 For example, the following command generates a PDF file representing the
7948 package DAG for the GNU@tie{}Core Utilities, showing its build-time
7949 dependencies:
7950
7951 @example
7952 guix graph coreutils | dot -Tpdf > dag.pdf
7953 @end example
7954
7955 The output looks like this:
7956
7957 @image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
7958
7959 Nice little graph, no?
7960
7961 But there is more than one graph! The one above is concise: it is the
7962 graph of package objects, omitting implicit inputs such as GCC, libc,
7963 grep, etc. It is often useful to have such a concise graph, but
7964 sometimes one may want to see more details. @command{guix graph} supports
7965 several types of graphs, allowing you to choose the level of detail:
7966
7967 @table @code
7968 @item package
7969 This is the default type used in the example above. It shows the DAG of
7970 package objects, excluding implicit dependencies. It is concise, but
7971 filters out many details.
7972
7973 @item reverse-package
7974 This shows the @emph{reverse} DAG of packages. For example:
7975
7976 @example
7977 guix graph --type=reverse-package ocaml
7978 @end example
7979
7980 ...@: yields the graph of packages that depend on OCaml.
7981
7982 Note that for core packages this can yield huge graphs. If all you want
7983 is to know the number of packages that depend on a given package, use
7984 @command{guix refresh --list-dependent} (@pxref{Invoking guix refresh,
7985 @option{--list-dependent}}).
7986
7987 @item bag-emerged
7988 This is the package DAG, @emph{including} implicit inputs.
7989
7990 For instance, the following command:
7991
7992 @example
7993 guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
7994 @end example
7995
7996 ...@: yields this bigger graph:
7997
7998 @image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
7999
8000 At the bottom of the graph, we see all the implicit inputs of
8001 @var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
8002
8003 Now, note that the dependencies of these implicit inputs---that is, the
8004 @dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
8005 here, for conciseness.
8006
8007 @item bag
8008 Similar to @code{bag-emerged}, but this time including all the bootstrap
8009 dependencies.
8010
8011 @item bag-with-origins
8012 Similar to @code{bag}, but also showing origins and their dependencies.
8013
8014 @item derivation
8015 This is the most detailed representation: It shows the DAG of
8016 derivations (@pxref{Derivations}) and plain store items. Compared to
8017 the above representation, many additional nodes are visible, including
8018 build scripts, patches, Guile modules, etc.
8019
8020 For this type of graph, it is also possible to pass a @file{.drv} file
8021 name instead of a package name, as in:
8022
8023 @example
8024 guix graph -t derivation `guix system build -d my-config.scm`
8025 @end example
8026
8027 @item module
8028 This is the graph of @dfn{package modules} (@pxref{Package Modules}).
8029 For example, the following command shows the graph for the package
8030 module that defines the @code{guile} package:
8031
8032 @example
8033 guix graph -t module guile | dot -Tpdf > module-graph.pdf
8034 @end example
8035 @end table
8036
8037 All the types above correspond to @emph{build-time dependencies}. The
8038 following graph type represents the @emph{run-time dependencies}:
8039
8040 @table @code
8041 @item references
8042 This is the graph of @dfn{references} of a package output, as returned
8043 by @command{guix gc --references} (@pxref{Invoking guix gc}).
8044
8045 If the given package output is not available in the store, @command{guix
8046 graph} attempts to obtain dependency information from substitutes.
8047
8048 Here you can also pass a store file name instead of a package name. For
8049 example, the command below produces the reference graph of your profile
8050 (which can be big!):
8051
8052 @example
8053 guix graph -t references `readlink -f ~/.guix-profile`
8054 @end example
8055
8056 @item referrers
8057 This is the graph of the @dfn{referrers} of a store item, as returned by
8058 @command{guix gc --referrers} (@pxref{Invoking guix gc}).
8059
8060 This relies exclusively on local information from your store. For
8061 instance, let us suppose that the current Inkscape is available in 10
8062 profiles on your machine; @command{guix graph -t referrers inkscape}
8063 will show a graph rooted at Inkscape and with those 10 profiles linked
8064 to it.
8065
8066 It can help determine what is preventing a store item from being garbage
8067 collected.
8068
8069 @end table
8070
8071 The available options are the following:
8072
8073 @table @option
8074 @item --type=@var{type}
8075 @itemx -t @var{type}
8076 Produce a graph output of @var{type}, where @var{type} must be one of
8077 the values listed above.
8078
8079 @item --list-types
8080 List the supported graph types.
8081
8082 @item --backend=@var{backend}
8083 @itemx -b @var{backend}
8084 Produce a graph using the selected @var{backend}.
8085
8086 @item --list-backends
8087 List the supported graph backends.
8088
8089 Currently, the available backends are Graphviz and d3.js.
8090
8091 @item --expression=@var{expr}
8092 @itemx -e @var{expr}
8093 Consider the package @var{expr} evaluates to.
8094
8095 This is useful to precisely refer to a package, as in this example:
8096
8097 @example
8098 guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
8099 @end example
8100
8101 @item --system=@var{system}
8102 @itemx -s @var{system}
8103 Display the graph for @var{system}---e.g., @code{i686-linux}.
8104
8105 The package dependency graph is largely architecture-independent, but there
8106 are some architecture-dependent bits that this option allows you to visualize.
8107 @end table
8108
8109
8110 @node Invoking guix environment
8111 @section Invoking @command{guix environment}
8112
8113 @cindex reproducible build environments
8114 @cindex development environments
8115 @cindex @command{guix environment}
8116 @cindex environment, package build environment
8117 The purpose of @command{guix environment} is to assist hackers in
8118 creating reproducible development environments without polluting their
8119 package profile. The @command{guix environment} tool takes one or more
8120 packages, builds all of their inputs, and creates a shell
8121 environment to use them.
8122
8123 The general syntax is:
8124
8125 @example
8126 guix environment @var{options} @var{package}@dots{}
8127 @end example
8128
8129 The following example spawns a new shell set up for the development of
8130 GNU@tie{}Guile:
8131
8132 @example
8133 guix environment guile
8134 @end example
8135
8136 If the needed dependencies are not built yet, @command{guix environment}
8137 automatically builds them. The environment of the new shell is an augmented
8138 version of the environment that @command{guix environment} was run in.
8139 It contains the necessary search paths for building the given package
8140 added to the existing environment variables. To create a ``pure''
8141 environment, in which the original environment variables have been unset,
8142 use the @code{--pure} option@footnote{Users sometimes wrongfully augment
8143 environment variables such as @code{PATH} in their @file{~/.bashrc}
8144 file. As a consequence, when @code{guix environment} launches it, Bash
8145 may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
8146 environment variables. It is an error to define such environment
8147 variables in @file{.bashrc}; instead, they should be defined in
8148 @file{.bash_profile}, which is sourced only by log-in shells.
8149 @xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
8150 details on Bash start-up files.}.
8151
8152 @vindex GUIX_ENVIRONMENT
8153 @command{guix environment} defines the @code{GUIX_ENVIRONMENT}
8154 variable in the shell it spawns; its value is the file name of the
8155 profile of this environment. This allows users to, say, define a
8156 specific prompt for development environments in their @file{.bashrc}
8157 (@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
8158
8159 @example
8160 if [ -n "$GUIX_ENVIRONMENT" ]
8161 then
8162 export PS1="\u@@\h \w [dev]\$ "
8163 fi
8164 @end example
8165
8166 @noindent
8167 ...@: or to browse the profile:
8168
8169 @example
8170 $ ls "$GUIX_ENVIRONMENT/bin"
8171 @end example
8172
8173 Additionally, more than one package may be specified, in which case the
8174 union of the inputs for the given packages are used. For example, the
8175 command below spawns a shell where all of the dependencies of both Guile
8176 and Emacs are available:
8177
8178 @example
8179 guix environment guile emacs
8180 @end example
8181
8182 Sometimes an interactive shell session is not desired. An arbitrary
8183 command may be invoked by placing the @code{--} token to separate the
8184 command from the rest of the arguments:
8185
8186 @example
8187 guix environment guile -- make -j4
8188 @end example
8189
8190 In other situations, it is more convenient to specify the list of
8191 packages needed in the environment. For example, the following command
8192 runs @command{python} from an environment containing Python@tie{}2.7 and
8193 NumPy:
8194
8195 @example
8196 guix environment --ad-hoc python2-numpy python-2.7 -- python
8197 @end example
8198
8199 Furthermore, one might want the dependencies of a package and also some
8200 additional packages that are not build-time or runtime dependencies, but
8201 are useful when developing nonetheless. Because of this, the
8202 @code{--ad-hoc} flag is positional. Packages appearing before
8203 @code{--ad-hoc} are interpreted as packages whose dependencies will be
8204 added to the environment. Packages appearing after are interpreted as
8205 packages that will be added to the environment directly. For example,
8206 the following command creates a Guix development environment that
8207 additionally includes Git and strace:
8208
8209 @example
8210 guix environment guix --ad-hoc git strace
8211 @end example
8212
8213 Sometimes it is desirable to isolate the environment as much as
8214 possible, for maximal purity and reproducibility. In particular, when
8215 using Guix on a host distro that is not GuixSD, it is desirable to
8216 prevent access to @file{/usr/bin} and other system-wide resources from
8217 the development environment. For example, the following command spawns
8218 a Guile REPL in a ``container'' where only the store and the current
8219 working directory are mounted:
8220
8221 @example
8222 guix environment --ad-hoc --container guile -- guile
8223 @end example
8224
8225 @quotation Note
8226 The @code{--container} option requires Linux-libre 3.19 or newer.
8227 @end quotation
8228
8229 The available options are summarized below.
8230
8231 @table @code
8232 @item --root=@var{file}
8233 @itemx -r @var{file}
8234 @cindex persistent environment
8235 @cindex garbage collector root, for environments
8236 Make @var{file} a symlink to the profile for this environment, and
8237 register it as a garbage collector root.
8238
8239 This is useful if you want to protect your environment from garbage
8240 collection, to make it ``persistent''.
8241
8242 When this option is omitted, the environment is protected from garbage
8243 collection only for the duration of the @command{guix environment}
8244 session. This means that next time you recreate the same environment,
8245 you could have to rebuild or re-download packages. @xref{Invoking guix
8246 gc}, for more on GC roots.
8247
8248 @item --expression=@var{expr}
8249 @itemx -e @var{expr}
8250 Create an environment for the package or list of packages that
8251 @var{expr} evaluates to.
8252
8253 For example, running:
8254
8255 @example
8256 guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
8257 @end example
8258
8259 starts a shell with the environment for this specific variant of the
8260 PETSc package.
8261
8262 Running:
8263
8264 @example
8265 guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
8266 @end example
8267
8268 starts a shell with all the GuixSD base packages available.
8269
8270 The above commands only use the default output of the given packages.
8271 To select other outputs, two element tuples can be specified:
8272
8273 @example
8274 guix environment --ad-hoc -e '(list (@@ (gnu packages bash) bash) "include")'
8275 @end example
8276
8277 @item --load=@var{file}
8278 @itemx -l @var{file}
8279 Create an environment for the package or list of packages that the code
8280 within @var{file} evaluates to.
8281
8282 As an example, @var{file} might contain a definition like this
8283 (@pxref{Defining Packages}):
8284
8285 @example
8286 @verbatiminclude environment-gdb.scm
8287 @end example
8288
8289 @item --manifest=@var{file}
8290 @itemx -m @var{file}
8291 Create an environment for the packages contained in the manifest object
8292 returned by the Scheme code in @var{file}.
8293
8294 This is similar to the same-named option in @command{guix package}
8295 (@pxref{profile-manifest, @option{--manifest}}) and uses the same
8296 manifest files.
8297
8298 @item --ad-hoc
8299 Include all specified packages in the resulting environment, as if an
8300 @i{ad hoc} package were defined with them as inputs. This option is
8301 useful for quickly creating an environment without having to write a
8302 package expression to contain the desired inputs.
8303
8304 For instance, the command:
8305
8306 @example
8307 guix environment --ad-hoc guile guile-sdl -- guile
8308 @end example
8309
8310 runs @command{guile} in an environment where Guile and Guile-SDL are
8311 available.
8312
8313 Note that this example implicitly asks for the default output of
8314 @code{guile} and @code{guile-sdl}, but it is possible to ask for a
8315 specific output---e.g., @code{glib:bin} asks for the @code{bin} output
8316 of @code{glib} (@pxref{Packages with Multiple Outputs}).
8317
8318 This option may be composed with the default behavior of @command{guix
8319 environment}. Packages appearing before @code{--ad-hoc} are interpreted
8320 as packages whose dependencies will be added to the environment, the
8321 default behavior. Packages appearing after are interpreted as packages
8322 that will be added to the environment directly.
8323
8324 @item --pure
8325 Unset existing environment variables when building the new environment.
8326 This has the effect of creating an environment in which search paths
8327 only contain package inputs.
8328
8329 @item --search-paths
8330 Display the environment variable definitions that make up the
8331 environment.
8332
8333 @item --system=@var{system}
8334 @itemx -s @var{system}
8335 Attempt to build for @var{system}---e.g., @code{i686-linux}.
8336
8337 @item --container
8338 @itemx -C
8339 @cindex container
8340 Run @var{command} within an isolated container. The current working
8341 directory outside the container is mapped inside the container.
8342 Additionally, unless overridden with @code{--user}, a dummy home
8343 directory is created that matches the current user's home directory, and
8344 @file{/etc/passwd} is configured accordingly. The spawned process runs
8345 as the current user outside the container, but has root privileges in
8346 the context of the container.
8347
8348 @item --network
8349 @itemx -N
8350 For containers, share the network namespace with the host system.
8351 Containers created without this flag only have access to the loopback
8352 device.
8353
8354 @item --link-profile
8355 @itemx -P
8356 For containers, link the environment profile to
8357 @file{~/.guix-profile} within the container. This is equivalent to
8358 running the command @command{ln -s $GUIX_ENVIRONMENT ~/.guix-profile}
8359 within the container. Linking will fail and abort the environment if
8360 the directory already exists, which will certainly be the case if
8361 @command{guix environment} was invoked in the user's home directory.
8362
8363 Certain packages are configured to look in
8364 @code{~/.guix-profile} for configuration files and data;@footnote{For
8365 example, the @code{fontconfig} package inspects
8366 @file{~/.guix-profile/share/fonts} for additional fonts.}
8367 @code{--link-profile} allows these programs to behave as expected within
8368 the environment.
8369
8370 @item --user=@var{user}
8371 @itemx -u @var{user}
8372 For containers, use the username @var{user} in place of the current
8373 user. The generated @file{/etc/passwd} entry within the container will
8374 contain the name @var{user}; the home directory will be
8375 @file{/home/USER}; and no user GECOS data will be copied. @var{user}
8376 need not exist on the system.
8377
8378 Additionally, any shared or exposed path (see @code{--share} and
8379 @code{--expose} respectively) whose target is within the current user's
8380 home directory will be remapped relative to @file{/home/USER}; this
8381 includes the automatic mapping of the current working directory.
8382
8383 @example
8384 # will expose paths as /home/foo/wd, /home/foo/test, and /home/foo/target
8385 cd $HOME/wd
8386 guix environment --container --user=foo \
8387 --expose=$HOME/test \
8388 --expose=/tmp/target=$HOME/target
8389 @end example
8390
8391 While this will limit the leaking of user identity through home paths
8392 and each of the user fields, this is only one useful component of a
8393 broader privacy/anonymity solution---not one in and of itself.
8394
8395 @item --expose=@var{source}[=@var{target}]
8396 For containers, expose the file system @var{source} from the host system
8397 as the read-only file system @var{target} within the container. If
8398 @var{target} is not specified, @var{source} is used as the target mount
8399 point in the container.
8400
8401 The example below spawns a Guile REPL in a container in which the user's
8402 home directory is accessible read-only via the @file{/exchange}
8403 directory:
8404
8405 @example
8406 guix environment --container --expose=$HOME=/exchange --ad-hoc guile -- guile
8407 @end example
8408
8409 @item --share=@var{source}[=@var{target}]
8410 For containers, share the file system @var{source} from the host system
8411 as the writable file system @var{target} within the container. If
8412 @var{target} is not specified, @var{source} is used as the target mount
8413 point in the container.
8414
8415 The example below spawns a Guile REPL in a container in which the user's
8416 home directory is accessible for both reading and writing via the
8417 @file{/exchange} directory:
8418
8419 @example
8420 guix environment --container --share=$HOME=/exchange --ad-hoc guile -- guile
8421 @end example
8422 @end table
8423
8424 @command{guix environment}
8425 also supports all of the common build options that @command{guix
8426 build} supports (@pxref{Common Build Options}) as well as package
8427 transformation options (@pxref{Package Transformation Options}).
8428
8429
8430 @node Invoking guix publish
8431 @section Invoking @command{guix publish}
8432
8433 @cindex @command{guix publish}
8434 The purpose of @command{guix publish} is to enable users to easily share
8435 their store with others, who can then use it as a substitute server
8436 (@pxref{Substitutes}).
8437
8438 When @command{guix publish} runs, it spawns an HTTP server which allows
8439 anyone with network access to obtain substitutes from it. This means
8440 that any machine running Guix can also act as if it were a build farm,
8441 since the HTTP interface is compatible with Hydra, the software behind
8442 the @code{@value{SUBSTITUTE-SERVER}} build farm.
8443
8444 For security, each substitute is signed, allowing recipients to check
8445 their authenticity and integrity (@pxref{Substitutes}). Because
8446 @command{guix publish} uses the signing key of the system, which is only
8447 readable by the system administrator, it must be started as root; the
8448 @code{--user} option makes it drop root privileges early on.
8449
8450 The signing key pair must be generated before @command{guix publish} is
8451 launched, using @command{guix archive --generate-key} (@pxref{Invoking
8452 guix archive}).
8453
8454 The general syntax is:
8455
8456 @example
8457 guix publish @var{options}@dots{}
8458 @end example
8459
8460 Running @command{guix publish} without any additional arguments will
8461 spawn an HTTP server on port 8080:
8462
8463 @example
8464 guix publish
8465 @end example
8466
8467 Once a publishing server has been authorized (@pxref{Invoking guix
8468 archive}), the daemon may download substitutes from it:
8469
8470 @example
8471 guix-daemon --substitute-urls=http://example.org:8080
8472 @end example
8473
8474 By default, @command{guix publish} compresses archives on the fly as it
8475 serves them. This ``on-the-fly'' mode is convenient in that it requires
8476 no setup and is immediately available. However, when serving lots of
8477 clients, we recommend using the @option{--cache} option, which enables
8478 caching of the archives before they are sent to clients---see below for
8479 details. The @command{guix weather} command provides a handy way to
8480 check what a server provides (@pxref{Invoking guix weather}).
8481
8482 As a bonus, @command{guix publish} also serves as a content-addressed
8483 mirror for source files referenced in @code{origin} records
8484 (@pxref{origin Reference}). For instance, assuming @command{guix
8485 publish} is running on @code{example.org}, the following URL returns the
8486 raw @file{hello-2.10.tar.gz} file with the given SHA256 hash
8487 (represented in @code{nix-base32} format, @pxref{Invoking guix hash}):
8488
8489 @example
8490 http://example.org/file/hello-2.10.tar.gz/sha256/0ssi1@dots{}ndq1i
8491 @end example
8492
8493 Obviously, these URLs only work for files that are in the store; in
8494 other cases, they return 404 (``Not Found'').
8495
8496 @cindex build logs, publication
8497 Build logs are available from @code{/log} URLs like:
8498
8499 @example
8500 http://example.org/log/gwspk@dots{}-guile-2.2.3
8501 @end example
8502
8503 @noindent
8504 When @command{guix-daemon} is configured to save compressed build logs,
8505 as is the case by default (@pxref{Invoking guix-daemon}), @code{/log}
8506 URLs return the compressed log as-is, with an appropriate
8507 @code{Content-Type} and/or @code{Content-Encoding} header. We recommend
8508 running @command{guix-daemon} with @code{--log-compression=gzip} since
8509 Web browsers can automatically decompress it, which is not the case with
8510 bzip2 compression.
8511
8512 The following options are available:
8513
8514 @table @code
8515 @item --port=@var{port}
8516 @itemx -p @var{port}
8517 Listen for HTTP requests on @var{port}.
8518
8519 @item --listen=@var{host}
8520 Listen on the network interface for @var{host}. The default is to
8521 accept connections from any interface.
8522
8523 @item --user=@var{user}
8524 @itemx -u @var{user}
8525 Change privileges to @var{user} as soon as possible---i.e., once the
8526 server socket is open and the signing key has been read.
8527
8528 @item --compression[=@var{level}]
8529 @itemx -C [@var{level}]
8530 Compress data using the given @var{level}. When @var{level} is zero,
8531 disable compression. The range 1 to 9 corresponds to different gzip
8532 compression levels: 1 is the fastest, and 9 is the best (CPU-intensive).
8533 The default is 3.
8534
8535 Unless @option{--cache} is used, compression occurs on the fly and
8536 the compressed streams are not
8537 cached. Thus, to reduce load on the machine that runs @command{guix
8538 publish}, it may be a good idea to choose a low compression level, to
8539 run @command{guix publish} behind a caching proxy, or to use
8540 @option{--cache}. Using @option{--cache} has the advantage that it
8541 allows @command{guix publish} to add @code{Content-Length} HTTP header
8542 to its responses.
8543
8544 @item --cache=@var{directory}
8545 @itemx -c @var{directory}
8546 Cache archives and meta-data (@code{.narinfo} URLs) to @var{directory}
8547 and only serve archives that are in cache.
8548
8549 When this option is omitted, archives and meta-data are created
8550 on-the-fly. This can reduce the available bandwidth, especially when
8551 compression is enabled, since this may become CPU-bound. Another
8552 drawback of the default mode is that the length of archives is not known
8553 in advance, so @command{guix publish} does not add a
8554 @code{Content-Length} HTTP header to its responses, which in turn
8555 prevents clients from knowing the amount of data being downloaded.
8556
8557 Conversely, when @option{--cache} is used, the first request for a store
8558 item (@i{via} a @code{.narinfo} URL) returns 404 and triggers a
8559 background process to @dfn{bake} the archive---computing its
8560 @code{.narinfo} and compressing the archive, if needed. Once the
8561 archive is cached in @var{directory}, subsequent requests succeed and
8562 are served directly from the cache, which guarantees that clients get
8563 the best possible bandwidth.
8564
8565 The ``baking'' process is performed by worker threads. By default, one
8566 thread per CPU core is created, but this can be customized. See
8567 @option{--workers} below.
8568
8569 When @option{--ttl} is used, cached entries are automatically deleted
8570 when they have expired.
8571
8572 @item --workers=@var{N}
8573 When @option{--cache} is used, request the allocation of @var{N} worker
8574 threads to ``bake'' archives.
8575
8576 @item --ttl=@var{ttl}
8577 Produce @code{Cache-Control} HTTP headers that advertise a time-to-live
8578 (TTL) of @var{ttl}. @var{ttl} must denote a duration: @code{5d} means 5
8579 days, @code{1m} means 1 month, and so on.
8580
8581 This allows the user's Guix to keep substitute information in cache for
8582 @var{ttl}. However, note that @code{guix publish} does not itself
8583 guarantee that the store items it provides will indeed remain available
8584 for as long as @var{ttl}.
8585
8586 Additionally, when @option{--cache} is used, cached entries that have
8587 not been accessed for @var{ttl} and that no longer have a corresponding
8588 item in the store, may be deleted.
8589
8590 @item --nar-path=@var{path}
8591 Use @var{path} as the prefix for the URLs of ``nar'' files
8592 (@pxref{Invoking guix archive, normalized archives}).
8593
8594 By default, nars are served at a URL such as
8595 @code{/nar/gzip/@dots{}-coreutils-8.25}. This option allows you to
8596 change the @code{/nar} part to @var{path}.
8597
8598 @item --public-key=@var{file}
8599 @itemx --private-key=@var{file}
8600 Use the specific @var{file}s as the public/private key pair used to sign
8601 the store items being published.
8602
8603 The files must correspond to the same key pair (the private key is used
8604 for signing and the public key is merely advertised in the signature
8605 metadata). They must contain keys in the canonical s-expression format
8606 as produced by @command{guix archive --generate-key} (@pxref{Invoking
8607 guix archive}). By default, @file{/etc/guix/signing-key.pub} and
8608 @file{/etc/guix/signing-key.sec} are used.
8609
8610 @item --repl[=@var{port}]
8611 @itemx -r [@var{port}]
8612 Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8613 Reference Manual}) on @var{port} (37146 by default). This is used
8614 primarily for debugging a running @command{guix publish} server.
8615 @end table
8616
8617 Enabling @command{guix publish} on a GuixSD system is a one-liner: just
8618 instantiate a @code{guix-publish-service-type} service in the @code{services} field
8619 of the @code{operating-system} declaration (@pxref{guix-publish-service-type,
8620 @code{guix-publish-service-type}}).
8621
8622 If you are instead running Guix on a ``foreign distro'', follow these
8623 instructions:”
8624
8625 @itemize
8626 @item
8627 If your host distro uses the systemd init system:
8628
8629 @example
8630 # ln -s ~root/.guix-profile/lib/systemd/system/guix-publish.service \
8631 /etc/systemd/system/
8632 # systemctl start guix-publish && systemctl enable guix-publish
8633 @end example
8634
8635 @item
8636 If your host distro uses the Upstart init system:
8637
8638 @example
8639 # ln -s ~root/.guix-profile/lib/upstart/system/guix-publish.conf /etc/init/
8640 # start guix-publish
8641 @end example
8642
8643 @item
8644 Otherwise, proceed similarly with your distro's init system.
8645 @end itemize
8646
8647 @node Invoking guix challenge
8648 @section Invoking @command{guix challenge}
8649
8650 @cindex reproducible builds
8651 @cindex verifiable builds
8652 @cindex @command{guix challenge}
8653 @cindex challenge
8654 Do the binaries provided by this server really correspond to the source
8655 code it claims to build? Is a package build process deterministic?
8656 These are the questions the @command{guix challenge} command attempts to
8657 answer.
8658
8659 The former is obviously an important question: Before using a substitute
8660 server (@pxref{Substitutes}), one had better @emph{verify} that it
8661 provides the right binaries, and thus @emph{challenge} it. The latter
8662 is what enables the former: If package builds are deterministic, then
8663 independent builds of the package should yield the exact same result,
8664 bit for bit; if a server provides a binary different from the one
8665 obtained locally, it may be either corrupt or malicious.
8666
8667 We know that the hash that shows up in @file{/gnu/store} file names is
8668 the hash of all the inputs of the process that built the file or
8669 directory---compilers, libraries, build scripts,
8670 etc. (@pxref{Introduction}). Assuming deterministic build processes,
8671 one store file name should map to exactly one build output.
8672 @command{guix challenge} checks whether there is, indeed, a single
8673 mapping by comparing the build outputs of several independent builds of
8674 any given store item.
8675
8676 The command output looks like this:
8677
8678 @smallexample
8679 $ guix challenge --substitute-urls="https://@value{SUBSTITUTE-SERVER} https://guix.example.org"
8680 updating list of substitutes from 'https://@value{SUBSTITUTE-SERVER}'... 100.0%
8681 updating list of substitutes from 'https://guix.example.org'... 100.0%
8682 /gnu/store/@dots{}-openssl-1.0.2d contents differ:
8683 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
8684 https://@value{SUBSTITUTE-SERVER}/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
8685 https://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
8686 /gnu/store/@dots{}-git-2.5.0 contents differ:
8687 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
8688 https://@value{SUBSTITUTE-SERVER}/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
8689 https://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
8690 /gnu/store/@dots{}-pius-2.1.1 contents differ:
8691 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
8692 https://@value{SUBSTITUTE-SERVER}/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
8693 https://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
8694
8695 @dots{}
8696
8697 6,406 store items were analyzed:
8698 - 4,749 (74.1%) were identical
8699 - 525 (8.2%) differed
8700 - 1,132 (17.7%) were inconclusive
8701 @end smallexample
8702
8703 @noindent
8704 In this example, @command{guix challenge} first scans the store to
8705 determine the set of locally-built derivations---as opposed to store
8706 items that were downloaded from a substitute server---and then queries
8707 all the substitute servers. It then reports those store items for which
8708 the servers obtained a result different from the local build.
8709
8710 @cindex non-determinism, in package builds
8711 As an example, @code{guix.example.org} always gets a different answer.
8712 Conversely, @code{@value{SUBSTITUTE-SERVER}} agrees with local builds, except in the
8713 case of Git. This might indicate that the build process of Git is
8714 non-deterministic, meaning that its output varies as a function of
8715 various things that Guix does not fully control, in spite of building
8716 packages in isolated environments (@pxref{Features}). Most common
8717 sources of non-determinism include the addition of timestamps in build
8718 results, the inclusion of random numbers, and directory listings sorted
8719 by inode number. See @uref{https://reproducible-builds.org/docs/}, for
8720 more information.
8721
8722 To find out what is wrong with this Git binary, we can do something along
8723 these lines (@pxref{Invoking guix archive}):
8724
8725 @example
8726 $ wget -q -O - https://@value{SUBSTITUTE-SERVER}/nar/@dots{}-git-2.5.0 \
8727 | guix archive -x /tmp/git
8728 $ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
8729 @end example
8730
8731 This command shows the difference between the files resulting from the
8732 local build, and the files resulting from the build on
8733 @code{@value{SUBSTITUTE-SERVER}} (@pxref{Overview, Comparing and Merging Files,,
8734 diffutils, Comparing and Merging Files}). The @command{diff} command
8735 works great for text files. When binary files differ, a better option
8736 is @uref{https://diffoscope.org/, Diffoscope}, a tool that helps
8737 visualize differences for all kinds of files.
8738
8739 Once you have done that work, you can tell whether the differences are due
8740 to a non-deterministic build process or to a malicious server. We try
8741 hard to remove sources of non-determinism in packages to make it easier
8742 to verify substitutes, but of course, this is a process that
8743 involves not just Guix, but a large part of the free software community.
8744 In the meantime, @command{guix challenge} is one tool to help address
8745 the problem.
8746
8747 If you are writing packages for Guix, you are encouraged to check
8748 whether @code{@value{SUBSTITUTE-SERVER}} and other substitute servers obtain the
8749 same build result as you did with:
8750
8751 @example
8752 $ guix challenge @var{package}
8753 @end example
8754
8755 @noindent
8756 where @var{package} is a package specification such as
8757 @code{guile@@2.0} or @code{glibc:debug}.
8758
8759 The general syntax is:
8760
8761 @example
8762 guix challenge @var{options} [@var{packages}@dots{}]
8763 @end example
8764
8765 When a difference is found between the hash of a locally-built item and
8766 that of a server-provided substitute, or among substitutes provided by
8767 different servers, the command displays it as in the example above and
8768 its exit code is 2 (other non-zero exit codes denote other kinds of
8769 errors.)
8770
8771 The one option that matters is:
8772
8773 @table @code
8774
8775 @item --substitute-urls=@var{urls}
8776 Consider @var{urls} the whitespace-separated list of substitute source
8777 URLs to compare to.
8778
8779 @item --verbose
8780 @itemx -v
8781 Show details about matches (identical contents) in addition to
8782 information about mismatches.
8783
8784 @end table
8785
8786 @node Invoking guix copy
8787 @section Invoking @command{guix copy}
8788
8789 @cindex copy, of store items, over SSH
8790 @cindex SSH, copy of store items
8791 @cindex sharing store items across machines
8792 @cindex transferring store items across machines
8793 The @command{guix copy} command copies items from the store of one
8794 machine to that of another machine over a secure shell (SSH)
8795 connection@footnote{This command is available only when Guile-SSH was
8796 found. @xref{Requirements}, for details.}. For example, the following
8797 command copies the @code{coreutils} package, the user's profile, and all
8798 their dependencies over to @var{host}, logged in as @var{user}:
8799
8800 @example
8801 guix copy --to=@var{user}@@@var{host} \
8802 coreutils `readlink -f ~/.guix-profile`
8803 @end example
8804
8805 If some of the items to be copied are already present on @var{host},
8806 they are not actually sent.
8807
8808 The command below retrieves @code{libreoffice} and @code{gimp} from
8809 @var{host}, assuming they are available there:
8810
8811 @example
8812 guix copy --from=@var{host} libreoffice gimp
8813 @end example
8814
8815 The SSH connection is established using the Guile-SSH client, which is
8816 compatible with OpenSSH: it honors @file{~/.ssh/known_hosts} and
8817 @file{~/.ssh/config}, and uses the SSH agent for authentication.
8818
8819 The key used to sign items that are sent must be accepted by the remote
8820 machine. Likewise, the key used by the remote machine to sign items you
8821 are retrieving must be in @file{/etc/guix/acl} so it is accepted by your
8822 own daemon. @xref{Invoking guix archive}, for more information about
8823 store item authentication.
8824
8825 The general syntax is:
8826
8827 @example
8828 guix copy [--to=@var{spec}|--from=@var{spec}] @var{items}@dots{}
8829 @end example
8830
8831 You must always specify one of the following options:
8832
8833 @table @code
8834 @item --to=@var{spec}
8835 @itemx --from=@var{spec}
8836 Specify the host to send to or receive from. @var{spec} must be an SSH
8837 spec such as @code{example.org}, @code{charlie@@example.org}, or
8838 @code{charlie@@example.org:2222}.
8839 @end table
8840
8841 The @var{items} can be either package names, such as @code{gimp}, or
8842 store items, such as @file{/gnu/store/@dots{}-idutils-4.6}.
8843
8844 When specifying the name of a package to send, it is first built if
8845 needed, unless @option{--dry-run} was specified. Common build options
8846 are supported (@pxref{Common Build Options}).
8847
8848
8849 @node Invoking guix container
8850 @section Invoking @command{guix container}
8851 @cindex container
8852 @cindex @command{guix container}
8853 @quotation Note
8854 As of version @value{VERSION}, this tool is experimental. The interface
8855 is subject to radical change in the future.
8856 @end quotation
8857
8858 The purpose of @command{guix container} is to manipulate processes
8859 running within an isolated environment, commonly known as a
8860 ``container'', typically created by the @command{guix environment}
8861 (@pxref{Invoking guix environment}) and @command{guix system container}
8862 (@pxref{Invoking guix system}) commands.
8863
8864 The general syntax is:
8865
8866 @example
8867 guix container @var{action} @var{options}@dots{}
8868 @end example
8869
8870 @var{action} specifies the operation to perform with a container, and
8871 @var{options} specifies the context-specific arguments for the action.
8872
8873 The following actions are available:
8874
8875 @table @code
8876 @item exec
8877 Execute a command within the context of a running container.
8878
8879 The syntax is:
8880
8881 @example
8882 guix container exec @var{pid} @var{program} @var{arguments}@dots{}
8883 @end example
8884
8885 @var{pid} specifies the process ID of the running container.
8886 @var{program} specifies an executable file name within the root file
8887 system of the container. @var{arguments} are the additional options that
8888 will be passed to @var{program}.
8889
8890 The following command launches an interactive login shell inside a
8891 GuixSD container, started by @command{guix system container}, and whose
8892 process ID is 9001:
8893
8894 @example
8895 guix container exec 9001 /run/current-system/profile/bin/bash --login
8896 @end example
8897
8898 Note that the @var{pid} cannot be the parent process of a container. It
8899 must be PID 1 of the container or one of its child processes.
8900
8901 @end table
8902
8903 @node Invoking guix weather
8904 @section Invoking @command{guix weather}
8905
8906 Occasionally you're grumpy because substitutes are lacking and you end
8907 up building packages by yourself (@pxref{Substitutes}). The
8908 @command{guix weather} command reports on substitute availability on the
8909 specified servers so you can have an idea of whether you'll be grumpy
8910 today. It can sometimes be useful info as a user, but it is primarily
8911 useful to people running @command{guix publish} (@pxref{Invoking guix
8912 publish}).
8913
8914 @cindex statistics, for substitutes
8915 @cindex availability of substitutes
8916 @cindex substitute availability
8917 @cindex weather, substitute availability
8918 Here's a sample run:
8919
8920 @example
8921 $ guix weather --substitute-urls=https://guix.example.org
8922 computing 5,872 package derivations for x86_64-linux...
8923 looking for 6,128 store items on https://guix.example.org..
8924 updating list of substitutes from 'https://guix.example.org'... 100.0%
8925 https://guix.example.org
8926 43.4% substitutes available (2,658 out of 6,128)
8927 7,032.5 MiB of nars (compressed)
8928 19,824.2 MiB on disk (uncompressed)
8929 0.030 seconds per request (182.9 seconds in total)
8930 33.5 requests per second
8931
8932 9.8% (342 out of 3,470) of the missing items are queued
8933 867 queued builds
8934 x86_64-linux: 518 (59.7%)
8935 i686-linux: 221 (25.5%)
8936 aarch64-linux: 128 (14.8%)
8937 build rate: 23.41 builds per hour
8938 x86_64-linux: 11.16 builds per hour
8939 i686-linux: 6.03 builds per hour
8940 aarch64-linux: 6.41 builds per hour
8941 @end example
8942
8943 @cindex continuous integration, statistics
8944 As you can see, it reports the fraction of all the packages for which
8945 substitutes are available on the server---regardless of whether
8946 substitutes are enabled, and regardless of whether this server's signing
8947 key is authorized. It also reports the size of the compressed archives
8948 (``nars'') provided by the server, the size the corresponding store
8949 items occupy in the store (assuming deduplication is turned off), and
8950 the server's throughput. The second part gives continuous integration
8951 (CI) statistics, if the server supports it.
8952
8953 To achieve that, @command{guix weather} queries over HTTP(S) meta-data
8954 (@dfn{narinfos}) for all the relevant store items. Like @command{guix
8955 challenge}, it ignores signatures on those substitutes, which is
8956 innocuous since the command only gathers statistics and cannot install
8957 those substitutes.
8958
8959 Among other things, it is possible to query specific system types and
8960 specific package sets. The available options are listed below.
8961
8962 @table @code
8963 @item --substitute-urls=@var{urls}
8964 @var{urls} is the space-separated list of substitute server URLs to
8965 query. When this option is omitted, the default set of substitute
8966 servers is queried.
8967
8968 @item --system=@var{system}
8969 @itemx -s @var{system}
8970 Query substitutes for @var{system}---e.g., @code{aarch64-linux}. This
8971 option can be repeated, in which case @command{guix weather} will query
8972 substitutes for several system types.
8973
8974 @item --manifest=@var{file}
8975 Instead of querying substitutes for all the packages, only ask for those
8976 specified in @var{file}. @var{file} must contain a @dfn{manifest}, as
8977 with the @code{-m} option of @command{guix package} (@pxref{Invoking
8978 guix package}).
8979 @end table
8980
8981 @node Invoking guix processes
8982 @section Invoking @command{guix processes}
8983
8984 The @command{guix processes} command can be useful to developers and system
8985 administrators, especially on multi-user machines and on build farms: it lists
8986 the current sessions (connections to the daemon), as well as information about
8987 the processes involved@footnote{Remote sessions, when @command{guix-daemon} is
8988 started with @option{--listen} specifying a TCP endpoint, are @emph{not}
8989 listed.}. Here's an example of the information it returns:
8990
8991 @example
8992 $ sudo guix processes
8993 SessionPID: 19002
8994 ClientPID: 19090
8995 ClientCommand: guix environment --ad-hoc python
8996
8997 SessionPID: 19402
8998 ClientPID: 19367
8999 ClientCommand: guix publish -u guix-publish -p 3000 -C 9 @dots{}
9000
9001 SessionPID: 19444
9002 ClientPID: 19419
9003 ClientCommand: cuirass --cache-directory /var/cache/cuirass @dots{}
9004 LockHeld: /gnu/store/@dots{}-perl-ipc-cmd-0.96.lock
9005 LockHeld: /gnu/store/@dots{}-python-six-bootstrap-1.11.0.lock
9006 LockHeld: /gnu/store/@dots{}-libjpeg-turbo-2.0.0.lock
9007 ChildProcess: 20495: guix offload x86_64-linux 7200 1 28800
9008 ChildProcess: 27733: guix offload x86_64-linux 7200 1 28800
9009 ChildProcess: 27793: guix offload x86_64-linux 7200 1 28800
9010 @end example
9011
9012 In this example we see that @command{guix-daemon} has three clients:
9013 @command{guix environment}, @command{guix publish}, and the Cuirass continuous
9014 integration tool; their process identifier (PID) is given by the
9015 @code{ClientPID} field. The @code{SessionPID} field gives the PID of the
9016 @command{guix-daemon} sub-process of this particular session.
9017
9018 The @code{LockHeld} fields show which store items are currently locked by this
9019 session, which corresponds to store items being built or substituted (the
9020 @code{LockHeld} field is not displayed when @command{guix processes} is not
9021 running as root.) Last, by looking at the @code{ChildProcess} field, we
9022 understand that these three builds are being offloaded (@pxref{Daemon Offload
9023 Setup}).
9024
9025 The output is in Recutils format so we can use the handy @command{recsel}
9026 command to select sessions of interest (@pxref{Selection Expressions,,,
9027 recutils, GNU recutils manual}). As an example, the command shows the command
9028 line and PID of the client that triggered the build of a Perl package:
9029
9030 @example
9031 $ sudo guix processes | \
9032 recsel -p ClientPID,ClientCommand -e 'LockHeld ~ "perl"'
9033 ClientPID: 19419
9034 ClientCommand: cuirass --cache-directory /var/cache/cuirass @dots{}
9035 @end example
9036
9037 @c *********************************************************************
9038 @node GNU Distribution
9039 @chapter GNU Distribution
9040
9041 @cindex Guix System Distribution
9042 @cindex GuixSD
9043 Guix comes with a distribution of the GNU system consisting entirely of
9044 free software@footnote{The term ``free'' here refers to the
9045 @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
9046 users of that software}.}. The
9047 distribution can be installed on its own (@pxref{System Installation}),
9048 but it is also possible to install Guix as a package manager on top of
9049 an installed GNU/Linux system (@pxref{Installation}). To distinguish
9050 between the two, we refer to the standalone distribution as the Guix
9051 System Distribution, or GuixSD.
9052
9053 The distribution provides core GNU packages such as GNU libc, GCC, and
9054 Binutils, as well as many GNU and non-GNU applications. The complete
9055 list of available packages can be browsed
9056 @url{http://www.gnu.org/software/guix/packages,on-line} or by
9057 running @command{guix package} (@pxref{Invoking guix package}):
9058
9059 @example
9060 guix package --list-available
9061 @end example
9062
9063 Our goal is to provide a practical 100% free software distribution of
9064 Linux-based and other variants of GNU, with a focus on the promotion and
9065 tight integration of GNU components, and an emphasis on programs and
9066 tools that help users exert that freedom.
9067
9068 Packages are currently available on the following platforms:
9069
9070 @table @code
9071
9072 @item x86_64-linux
9073 Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
9074
9075 @item i686-linux
9076 Intel 32-bit architecture (IA32), Linux-Libre kernel;
9077
9078 @item armhf-linux
9079 ARMv7-A architecture with hard float, Thumb-2 and NEON,
9080 using the EABI hard-float application binary interface (ABI),
9081 and Linux-Libre kernel.
9082
9083 @item aarch64-linux
9084 little-endian 64-bit ARMv8-A processors, Linux-Libre kernel. This is
9085 currently in an experimental stage, with limited support.
9086 @xref{Contributing}, for how to help!
9087
9088 @item mips64el-linux
9089 little-endian 64-bit MIPS processors, specifically the Loongson series,
9090 n32 ABI, and Linux-Libre kernel.
9091
9092 @end table
9093
9094 GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
9095
9096 @noindent
9097 For information on porting to other architectures or kernels,
9098 @pxref{Porting}.
9099
9100 @menu
9101 * System Installation:: Installing the whole operating system.
9102 * System Configuration:: Configuring the operating system.
9103 * Documentation:: Browsing software user manuals.
9104 * Installing Debugging Files:: Feeding the debugger.
9105 * Security Updates:: Deploying security fixes quickly.
9106 * Package Modules:: Packages from the programmer's viewpoint.
9107 * Packaging Guidelines:: Growing the distribution.
9108 * Bootstrapping:: GNU/Linux built from scratch.
9109 * Porting:: Targeting another platform or kernel.
9110 @end menu
9111
9112 Building this distribution is a cooperative effort, and you are invited
9113 to join! @xref{Contributing}, for information about how you can help.
9114
9115 @node System Installation
9116 @section System Installation
9117
9118 @cindex installing GuixSD
9119 @cindex Guix System Distribution
9120 This section explains how to install the Guix System Distribution (GuixSD)
9121 on a machine. The Guix package manager can
9122 also be installed on top of a running GNU/Linux system,
9123 @pxref{Installation}.
9124
9125 @ifinfo
9126 @quotation Note
9127 @c This paragraph is for people reading this from tty2 of the
9128 @c installation image.
9129 You are reading this documentation with an Info reader. For details on
9130 how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
9131 link that follows: @pxref{Top, Info reader,, info-stnd, Stand-alone GNU
9132 Info}. Hit @kbd{l} afterwards to come back here.
9133
9134 Alternately, run @command{info info} in another tty to keep the manual
9135 available.
9136 @end quotation
9137 @end ifinfo
9138
9139 @menu
9140 * Limitations:: What you can expect.
9141 * Hardware Considerations:: Supported hardware.
9142 * USB Stick and DVD Installation:: Preparing the installation medium.
9143 * Preparing for Installation:: Networking, partitioning, etc.
9144 * Proceeding with the Installation:: The real thing.
9145 * Installing GuixSD in a VM:: GuixSD playground.
9146 * Building the Installation Image:: How this comes to be.
9147 @end menu
9148
9149 @node Limitations
9150 @subsection Limitations
9151
9152 As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
9153 not production-ready. It may contain bugs and lack important
9154 features. Thus, if you are looking for a stable production system that
9155 respects your freedom as a computer user, a good solution at this point
9156 is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
9157 the more established GNU/Linux distributions}. We hope you can soon switch
9158 to the GuixSD without fear, of course. In the meantime, you can
9159 also keep using your distribution and try out the package manager on top
9160 of it (@pxref{Installation}).
9161
9162 Before you proceed with the installation, be aware of the following
9163 noteworthy limitations applicable to version @value{VERSION}:
9164
9165 @itemize
9166 @item
9167 The installation process does not include a graphical user interface and
9168 requires familiarity with GNU/Linux (see the following subsections to
9169 get a feel of what that means.)
9170
9171 @item
9172 Support for the Logical Volume Manager (LVM) is missing.
9173
9174 @item
9175 More and more system services are provided (@pxref{Services}), but some
9176 may be missing.
9177
9178 @item
9179 More than 8,500 packages are available, but you might
9180 occasionally find that a useful package is missing.
9181
9182 @item
9183 GNOME, Xfce, LXDE, and Enlightenment are available (@pxref{Desktop Services}),
9184 as well as a number of X11 window managers. However, some graphical
9185 applications may be missing, as well as KDE.
9186 @end itemize
9187
9188 You have been warned! But more than a disclaimer, this is an invitation
9189 to report issues (and success stories!), and to join us in improving it.
9190 @xref{Contributing}, for more info.
9191
9192
9193 @node Hardware Considerations
9194 @subsection Hardware Considerations
9195
9196 @cindex hardware support on GuixSD
9197 GNU@tie{}GuixSD focuses on respecting the user's computing freedom. It
9198 builds around the kernel Linux-libre, which means that only hardware for
9199 which free software drivers and firmware exist is supported. Nowadays,
9200 a wide range of off-the-shelf hardware is supported on
9201 GNU/Linux-libre---from keyboards to graphics cards to scanners and
9202 Ethernet controllers. Unfortunately, there are still areas where
9203 hardware vendors deny users control over their own computing, and such
9204 hardware is not supported on GuixSD.
9205
9206 @cindex WiFi, hardware support
9207 One of the main areas where free drivers or firmware are lacking is WiFi
9208 devices. WiFi devices known to work include those using Atheros chips
9209 (AR9271 and AR7010), which corresponds to the @code{ath9k} Linux-libre
9210 driver, and those using Broadcom/AirForce chips (BCM43xx with
9211 Wireless-Core Revision 5), which corresponds to the @code{b43-open}
9212 Linux-libre driver. Free firmware exists for both and is available
9213 out-of-the-box on GuixSD, as part of @var{%base-firmware}
9214 (@pxref{operating-system Reference, @code{firmware}}).
9215
9216 @cindex RYF, Respects Your Freedom
9217 The @uref{https://www.fsf.org/, Free Software Foundation} runs
9218 @uref{https://www.fsf.org/ryf, @dfn{Respects Your Freedom}} (RYF), a
9219 certification program for hardware products that respect your freedom
9220 and your privacy and ensure that you have control over your device. We
9221 encourage you to check the list of RYF-certified devices.
9222
9223 Another useful resource is the @uref{https://www.h-node.org/, H-Node}
9224 web site. It contains a catalog of hardware devices with information
9225 about their support in GNU/Linux.
9226
9227
9228 @node USB Stick and DVD Installation
9229 @subsection USB Stick and DVD Installation
9230
9231 An ISO-9660 installation image that can be written to a USB stick or
9232 burnt to a DVD can be downloaded from
9233 @indicateurl{https://alpha.gnu.org/gnu/guix/guixsd-install-@value{VERSION}.@var{system}.iso.xz},
9234 where @var{system} is one of:
9235
9236 @table @code
9237 @item x86_64-linux
9238 for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
9239
9240 @item i686-linux
9241 for a 32-bit GNU/Linux system on Intel-compatible CPUs.
9242 @end table
9243
9244 @c start duplication of authentication part from ``Binary Installation''
9245 Make sure to download the associated @file{.sig} file and to verify the
9246 authenticity of the image against it, along these lines:
9247
9248 @example
9249 $ wget https://alpha.gnu.org/gnu/guix/guixsd-install-@value{VERSION}.@var{system}.iso.xz.sig
9250 $ gpg --verify guixsd-install-@value{VERSION}.@var{system}.iso.xz.sig
9251 @end example
9252
9253 If that command fails because you do not have the required public key,
9254 then run this command to import it:
9255
9256 @example
9257 $ gpg --keyserver @value{KEY-SERVER} \
9258 --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
9259 @end example
9260
9261 @noindent
9262 and rerun the @code{gpg --verify} command.
9263 @c end duplication
9264
9265 This image contains the tools necessary for an installation.
9266 It is meant to be copied @emph{as is} to a large-enough USB stick or DVD.
9267
9268 @unnumberedsubsubsec Copying to a USB Stick
9269
9270 To copy the image to a USB stick, follow these steps:
9271
9272 @enumerate
9273 @item
9274 Decompress the image using the @command{xz} command:
9275
9276 @example
9277 xz -d guixsd-install-@value{VERSION}.@var{system}.iso.xz
9278 @end example
9279
9280 @item
9281 Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
9282 its device name. Assuming that the USB stick is known as @file{/dev/sdX},
9283 copy the image with:
9284
9285 @example
9286 dd if=guixsd-install-@value{VERSION}.@var{system}.iso of=/dev/sdX
9287 sync
9288 @end example
9289
9290 Access to @file{/dev/sdX} usually requires root privileges.
9291 @end enumerate
9292
9293 @unnumberedsubsubsec Burning on a DVD
9294
9295 To copy the image to a DVD, follow these steps:
9296
9297 @enumerate
9298 @item
9299 Decompress the image using the @command{xz} command:
9300
9301 @example
9302 xz -d guixsd-install-@value{VERSION}.@var{system}.iso.xz
9303 @end example
9304
9305 @item
9306 Insert a blank DVD into your machine, and determine
9307 its device name. Assuming that the DVD drive is known as @file{/dev/srX},
9308 copy the image with:
9309
9310 @example
9311 growisofs -dvd-compat -Z /dev/srX=guixsd-install-@value{VERSION}.@var{system}.iso
9312 @end example
9313
9314 Access to @file{/dev/srX} usually requires root privileges.
9315 @end enumerate
9316
9317 @unnumberedsubsubsec Booting
9318
9319 Once this is done, you should be able to reboot the system and boot from
9320 the USB stick or DVD. The latter usually requires you to get in the
9321 BIOS or UEFI boot menu, where you can choose to boot from the USB stick.
9322
9323 @xref{Installing GuixSD in a VM}, if, instead, you would like to install
9324 GuixSD in a virtual machine (VM).
9325
9326
9327 @node Preparing for Installation
9328 @subsection Preparing for Installation
9329
9330 Once you have successfully booted your computer using the installation medium,
9331 you should end up with the welcome page of the graphical installer. The
9332 graphical installer is a text-based user interface built upon the newt
9333 library. It shall guide you through all the different steps needed to install
9334 GNU GuixSD. However, as the graphical installer is still under heavy
9335 development, you might want to fallback to the original, shell based install
9336 process, by switching to TTYs 3 to 6 with the shortcuts CTRL-ALT-F[3-6]. The
9337 following sections describe the installation procedure assuming you're using
9338 one of those TTYs. They are configured and can be used to run commands as
9339 root.
9340
9341 TTY2 shows this documentation, browsable using the Info reader commands
9342 (@pxref{Top,,, info-stnd, Stand-alone GNU Info}). The installation system
9343 runs the GPM mouse daemon, which allows you to select text with the left mouse
9344 button and to paste it with the middle button.
9345
9346 @quotation Note
9347 Installation requires access to the Internet so that any missing
9348 dependencies of your system configuration can be downloaded. See the
9349 ``Networking'' section below.
9350 @end quotation
9351
9352 The installation system includes many common tools needed for this task.
9353 But it is also a full-blown GuixSD system, which means that you can
9354 install additional packages, should you need it, using @command{guix
9355 package} (@pxref{Invoking guix package}).
9356
9357 @subsubsection Keyboard Layout
9358
9359 @cindex keyboard layout
9360 The installation image uses the US qwerty keyboard layout. If you want
9361 to change it, you can use the @command{loadkeys} command. For example,
9362 the following command selects the Dvorak keyboard layout:
9363
9364 @example
9365 loadkeys dvorak
9366 @end example
9367
9368 See the files under @file{/run/current-system/profile/share/keymaps} for
9369 a list of available keyboard layouts. Run @command{man loadkeys} for
9370 more information.
9371
9372 @subsubsection Networking
9373
9374 Run the following command to see what your network interfaces are called:
9375
9376 @example
9377 ifconfig -a
9378 @end example
9379
9380 @noindent
9381 @dots{} or, using the GNU/Linux-specific @command{ip} command:
9382
9383 @example
9384 ip a
9385 @end example
9386
9387 @c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
9388 Wired interfaces have a name starting with @samp{e}; for example, the
9389 interface corresponding to the first on-board Ethernet controller is
9390 called @samp{eno1}. Wireless interfaces have a name starting with
9391 @samp{w}, like @samp{w1p2s0}.
9392
9393 @table @asis
9394 @item Wired connection
9395 To configure a wired network run the following command, substituting
9396 @var{interface} with the name of the wired interface you want to use.
9397
9398 @example
9399 ifconfig @var{interface} up
9400 @end example
9401
9402 @item Wireless connection
9403 @cindex wireless
9404 @cindex WiFi
9405 To configure wireless networking, you can create a configuration file
9406 for the @command{wpa_supplicant} configuration tool (its location is not
9407 important) using one of the available text editors such as
9408 @command{nano}:
9409
9410 @example
9411 nano wpa_supplicant.conf
9412 @end example
9413
9414 As an example, the following stanza can go to this file and will work
9415 for many wireless networks, provided you give the actual SSID and
9416 passphrase for the network you are connecting to:
9417
9418 @example
9419 network=@{
9420 ssid="@var{my-ssid}"
9421 key_mgmt=WPA-PSK
9422 psk="the network's secret passphrase"
9423 @}
9424 @end example
9425
9426 Start the wireless service and run it in the background with the
9427 following command (substitute @var{interface} with the name of the
9428 network interface you want to use):
9429
9430 @example
9431 wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
9432 @end example
9433
9434 Run @command{man wpa_supplicant} for more information.
9435 @end table
9436
9437 @cindex DHCP
9438 At this point, you need to acquire an IP address. On a network where IP
9439 addresses are automatically assigned @i{via} DHCP, you can run:
9440
9441 @example
9442 dhclient -v @var{interface}
9443 @end example
9444
9445 Try to ping a server to see if networking is up and running:
9446
9447 @example
9448 ping -c 3 gnu.org
9449 @end example
9450
9451 Setting up network access is almost always a requirement because the
9452 image does not contain all the software and tools that may be needed.
9453
9454 @cindex installing over SSH
9455 If you want to, you can continue the installation remotely by starting
9456 an SSH server:
9457
9458 @example
9459 herd start ssh-daemon
9460 @end example
9461
9462 Make sure to either set a password with @command{passwd}, or configure
9463 OpenSSH public key authentication before logging in.
9464
9465 @subsubsection Disk Partitioning
9466
9467 Unless this has already been done, the next step is to partition, and
9468 then format the target partition(s).
9469
9470 The installation image includes several partitioning tools, including
9471 Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
9472 @command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
9473 the partition layout you want:
9474
9475 @example
9476 cfdisk
9477 @end example
9478
9479 If your disk uses the GUID Partition Table (GPT) format and you plan to
9480 install BIOS-based GRUB (which is the default), make sure a BIOS Boot
9481 Partition is available (@pxref{BIOS installation,,, grub, GNU GRUB
9482 manual}).
9483
9484 @cindex EFI, installation
9485 @cindex UEFI, installation
9486 @cindex ESP, EFI system partition
9487 If you instead wish to use EFI-based GRUB, a FAT32 @dfn{EFI System Partition}
9488 (ESP) is required. This partition should be mounted at @file{/boot/efi} and
9489 must have the @code{esp} flag set. E.g., for @command{parted}:
9490
9491 @example
9492 parted /dev/sda set 1 esp on
9493 @end example
9494
9495 @quotation Note
9496 @vindex grub-bootloader
9497 @vindex grub-efi-bootloader
9498 Unsure whether to use EFI- or BIOS-based GRUB? If the directory
9499 @file{/sys/firmware/efi} exists in the installation image, then you should
9500 probably perform an EFI installation, using @code{grub-efi-bootloader}.
9501 Otherwise you should use the BIOS-based GRUB, known as
9502 @code{grub-bootloader}. @xref{Bootloader Configuration}, for more info on
9503 bootloaders.
9504 @end quotation
9505
9506 Once you are done partitioning the target hard disk drive, you have to
9507 create a file system on the relevant partition(s)@footnote{Currently
9508 GuixSD only supports ext4 and btrfs file systems. In particular, code
9509 that reads file system UUIDs and labels only works for these file system
9510 types.}. For the ESP, if you have one and assuming it is
9511 @file{/dev/sda1}, run:
9512
9513 @example
9514 mkfs.fat -F32 /dev/sda1
9515 @end example
9516
9517 Preferably, assign file systems a label so that you can easily and
9518 reliably refer to them in @code{file-system} declarations (@pxref{File
9519 Systems}). This is typically done using the @code{-L} option of
9520 @command{mkfs.ext4} and related commands. So, assuming the target root
9521 partition lives at @file{/dev/sda2}, a file system with the label
9522 @code{my-root} can be created with:
9523
9524 @example
9525 mkfs.ext4 -L my-root /dev/sda2
9526 @end example
9527
9528 @cindex encrypted disk
9529 If you are instead planning to encrypt the root partition, you can use
9530 the Cryptsetup/LUKS utilities to do that (see @inlinefmtifelse{html,
9531 @uref{https://linux.die.net/man/8/cryptsetup, @code{man cryptsetup}},
9532 @code{man cryptsetup}} for more information.) Assuming you want to
9533 store the root partition on @file{/dev/sda2}, the command sequence would
9534 be along these lines:
9535
9536 @example
9537 cryptsetup luksFormat /dev/sda2
9538 cryptsetup open --type luks /dev/sda2 my-partition
9539 mkfs.ext4 -L my-root /dev/mapper/my-partition
9540 @end example
9541
9542 Once that is done, mount the target file system under @file{/mnt}
9543 with a command like (again, assuming @code{my-root} is the label of the
9544 root file system):
9545
9546 @example
9547 mount LABEL=my-root /mnt
9548 @end example
9549
9550 Also mount any other file systems you would like to use on the target
9551 system relative to this path. If you have @file{/boot} on a separate
9552 partition for example, mount it at @file{/mnt/boot} now so it is found
9553 by @code{guix system init} afterwards.
9554
9555 Finally, if you plan to use one or more swap partitions (@pxref{Memory
9556 Concepts, swap space,, libc, The GNU C Library Reference Manual}), make
9557 sure to initialize them with @command{mkswap}. Assuming you have one
9558 swap partition on @file{/dev/sda3}, you would run:
9559
9560 @example
9561 mkswap /dev/sda3
9562 swapon /dev/sda3
9563 @end example
9564
9565 Alternatively, you may use a swap file. For example, assuming that in
9566 the new system you want to use the file @file{/swapfile} as a swap file,
9567 you would run@footnote{This example will work for many types of file
9568 systems (e.g., ext4). However, for copy-on-write file systems (e.g.,
9569 btrfs), the required steps may be different. For details, see the
9570 manual pages for @command{mkswap} and @command{swapon}.}:
9571
9572 @example
9573 # This is 10 GiB of swap space. Adjust "count" to change the size.
9574 dd if=/dev/zero of=/mnt/swapfile bs=1MiB count=10240
9575 # For security, make the file readable and writable only by root.
9576 chmod 600 /mnt/swapfile
9577 mkswap /mnt/swapfile
9578 swapon /mnt/swapfile
9579 @end example
9580
9581 Note that if you have encrypted the root partition and created a swap
9582 file in its file system as described above, then the encryption also
9583 protects the swap file, just like any other file in that file system.
9584
9585 @node Proceeding with the Installation
9586 @subsection Proceeding with the Installation
9587
9588 With the target partitions ready and the target root mounted on
9589 @file{/mnt}, we're ready to go. First, run:
9590
9591 @example
9592 herd start cow-store /mnt
9593 @end example
9594
9595 This makes @file{/gnu/store} copy-on-write, such that packages added to it
9596 during the installation phase are written to the target disk on @file{/mnt}
9597 rather than kept in memory. This is necessary because the first phase of
9598 the @command{guix system init} command (see below) entails downloads or
9599 builds to @file{/gnu/store} which, initially, is an in-memory file system.
9600
9601 Next, you have to edit a file and
9602 provide the declaration of the operating system to be installed. To
9603 that end, the installation system comes with three text editors. We
9604 recommend GNU nano (@pxref{Top,,, nano, GNU nano Manual}), which
9605 supports syntax highlighting and parentheses matching; other editors
9606 include GNU Zile (an Emacs clone), and
9607 nvi (a clone of the original BSD @command{vi} editor).
9608 We strongly recommend storing that file on the target root file system, say,
9609 as @file{/mnt/etc/config.scm}. Failing to do that, you will have lost your
9610 configuration file once you have rebooted into the newly-installed system.
9611
9612 @xref{Using the Configuration System}, for an overview of the
9613 configuration file. The example configurations discussed in that
9614 section are available under @file{/etc/configuration} in the
9615 installation image. Thus, to get started with a system configuration
9616 providing a graphical display server (a ``desktop'' system), you can run
9617 something along these lines:
9618
9619 @example
9620 # mkdir /mnt/etc
9621 # cp /etc/configuration/desktop.scm /mnt/etc/config.scm
9622 # nano /mnt/etc/config.scm
9623 @end example
9624
9625 You should pay attention to what your configuration file contains, and
9626 in particular:
9627
9628 @itemize
9629 @item
9630 Make sure the @code{bootloader-configuration} form refers to the target
9631 you want to install GRUB on. It should mention @code{grub-bootloader} if
9632 you are installing GRUB in the legacy way, or @code{grub-efi-bootloader}
9633 for newer UEFI systems. For legacy systems, the @code{target} field
9634 names a device, like @code{/dev/sda}; for UEFI systems it names a path
9635 to a mounted EFI partition, like @code{/boot/efi}, and do make sure the
9636 path is actually mounted.
9637
9638 @item
9639 Be sure that your file system labels match the value of their respective
9640 @code{device} fields in your @code{file-system} configuration, assuming
9641 your @code{file-system} configuration uses the @code{file-system-label}
9642 procedure in its @code{device} field.
9643
9644 @item
9645 If there are encrypted or RAID partitions, make sure to add a
9646 @code{mapped-devices} field to describe them (@pxref{Mapped Devices}).
9647 @end itemize
9648
9649 Once you are done preparing the configuration file, the new system must
9650 be initialized (remember that the target root file system is mounted
9651 under @file{/mnt}):
9652
9653 @example
9654 guix system init /mnt/etc/config.scm /mnt
9655 @end example
9656
9657 @noindent
9658 This copies all the necessary files and installs GRUB on
9659 @file{/dev/sdX}, unless you pass the @option{--no-bootloader} option. For
9660 more information, @pxref{Invoking guix system}. This command may trigger
9661 downloads or builds of missing packages, which can take some time.
9662
9663 Once that command has completed---and hopefully succeeded!---you can run
9664 @command{reboot} and boot into the new system. The @code{root} password
9665 in the new system is initially empty; other users' passwords need to be
9666 initialized by running the @command{passwd} command as @code{root},
9667 unless your configuration specifies otherwise
9668 (@pxref{user-account-password, user account passwords}).
9669
9670 @cindex upgrading GuixSD
9671 From then on, you can update GuixSD whenever you want by running @command{guix
9672 pull} as @code{root} (@pxref{Invoking guix pull}), and then running
9673 @command{guix system reconfigure /etc/config.scm}, as @code{root} too, to
9674 build a new system generation with the latest packages and services
9675 (@pxref{Invoking guix system}). We recommend doing that regularly so that
9676 your system includes the latest security updates (@pxref{Security Updates}).
9677
9678 Join us on @code{#guix} on the Freenode IRC network or on
9679 @email{guix-devel@@gnu.org} to share your experience---good or not so
9680 good.
9681
9682 @node Installing GuixSD in a VM
9683 @subsection Installing GuixSD in a Virtual Machine
9684
9685 @cindex virtual machine, GuixSD installation
9686 @cindex virtual private server (VPS)
9687 @cindex VPS (virtual private server)
9688 If you'd like to install GuixSD in a virtual machine (VM) or on a
9689 virtual private server (VPS) rather than on your beloved machine, this
9690 section is for you.
9691
9692 To boot a @uref{http://qemu.org/,QEMU} VM for installing GuixSD in a
9693 disk image, follow these steps:
9694
9695 @enumerate
9696 @item
9697 First, retrieve and decompress the GuixSD installation image as
9698 described previously (@pxref{USB Stick and DVD Installation}).
9699
9700 @item
9701 Create a disk image that will hold the installed system. To make a
9702 qcow2-formatted disk image, use the @command{qemu-img} command:
9703
9704 @example
9705 qemu-img create -f qcow2 guixsd.img 50G
9706 @end example
9707
9708 The resulting file will be much smaller than 50 GB (typically less than
9709 1 MB), but it will grow as the virtualized storage device is filled up.
9710
9711 @item
9712 Boot the USB installation image in an VM:
9713
9714 @example
9715 qemu-system-x86_64 -m 1024 -smp 1 \
9716 -net user -net nic,model=virtio -boot menu=on \
9717 -drive file=guixsd-install-@value{VERSION}.@var{system}.iso \
9718 -drive file=guixsd.img
9719 @end example
9720
9721 The ordering of the drives matters.
9722
9723 In the VM console, quickly press the @kbd{F12} key to enter the boot
9724 menu. Then press the @kbd{2} key and the @kbd{RET} key to validate your
9725 selection.
9726
9727 @item
9728 You're now root in the VM, proceed with the installation process.
9729 @xref{Preparing for Installation}, and follow the instructions.
9730 @end enumerate
9731
9732 Once installation is complete, you can boot the system that's on your
9733 @file{guixsd.img} image. @xref{Running GuixSD in a VM}, for how to do
9734 that.
9735
9736 @node Building the Installation Image
9737 @subsection Building the Installation Image
9738
9739 @cindex installation image
9740 The installation image described above was built using the @command{guix
9741 system} command, specifically:
9742
9743 @example
9744 guix system disk-image gnu/system/install.scm
9745 @end example
9746
9747 Have a look at @file{gnu/system/install.scm} in the source tree,
9748 and see also @ref{Invoking guix system} for more information
9749 about the installation image.
9750
9751 @subsection Building the Installation Image for ARM Boards
9752
9753 Many ARM boards require a specific variant of the
9754 @uref{http://www.denx.de/wiki/U-Boot/, U-Boot} bootloader.
9755
9756 If you build a disk image and the bootloader is not available otherwise
9757 (on another boot drive etc), it's advisable to build an image that
9758 includes the bootloader, specifically:
9759
9760 @example
9761 guix system disk-image --system=armhf-linux -e '((@@ (gnu system install) os-with-u-boot) (@@ (gnu system install) installation-os) "A20-OLinuXino-Lime2")'
9762 @end example
9763
9764 @code{A20-OLinuXino-Lime2} is the name of the board. If you specify an invalid
9765 board, a list of possible boards will be printed.
9766
9767 @node System Configuration
9768 @section System Configuration
9769
9770 @cindex system configuration
9771 The Guix System Distribution supports a consistent whole-system configuration
9772 mechanism. By that we mean that all aspects of the global system
9773 configuration---such as the available system services, timezone and
9774 locale settings, user accounts---are declared in a single place. Such
9775 a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
9776
9777 One of the advantages of putting all the system configuration under the
9778 control of Guix is that it supports transactional system upgrades, and
9779 makes it possible to roll back to a previous system instantiation,
9780 should something go wrong with the new one (@pxref{Features}). Another
9781 advantage is that it makes it easy to replicate the exact same configuration
9782 across different machines, or at different points in time, without
9783 having to resort to additional administration tools layered on top of
9784 the own tools of the system.
9785 @c Yes, we're talking of Puppet, Chef, & co. here. ↑
9786
9787 This section describes this mechanism. First we focus on the system
9788 administrator's viewpoint---explaining how the system is configured and
9789 instantiated. Then we show how this mechanism can be extended, for
9790 instance to support new system services.
9791
9792 @menu
9793 * Using the Configuration System:: Customizing your GNU system.
9794 * operating-system Reference:: Detail of operating-system declarations.
9795 * File Systems:: Configuring file system mounts.
9796 * Mapped Devices:: Block device extra processing.
9797 * User Accounts:: Specifying user accounts.
9798 * Locales:: Language and cultural convention settings.
9799 * Services:: Specifying system services.
9800 * Setuid Programs:: Programs running with root privileges.
9801 * X.509 Certificates:: Authenticating HTTPS servers.
9802 * Name Service Switch:: Configuring libc's name service switch.
9803 * Initial RAM Disk:: Linux-Libre bootstrapping.
9804 * Bootloader Configuration:: Configuring the boot loader.
9805 * Invoking guix system:: Instantiating a system configuration.
9806 * Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
9807 * Defining Services:: Adding new service definitions.
9808 @end menu
9809
9810 @node Using the Configuration System
9811 @subsection Using the Configuration System
9812
9813 The operating system is configured by providing an
9814 @code{operating-system} declaration in a file that can then be passed to
9815 the @command{guix system} command (@pxref{Invoking guix system}). A
9816 simple setup, with the default system services, the default Linux-Libre
9817 kernel, initial RAM disk, and boot loader looks like this:
9818
9819 @findex operating-system
9820 @lisp
9821 @include os-config-bare-bones.texi
9822 @end lisp
9823
9824 This example should be self-describing. Some of the fields defined
9825 above, such as @code{host-name} and @code{bootloader}, are mandatory.
9826 Others, such as @code{packages} and @code{services}, can be omitted, in
9827 which case they get a default value.
9828
9829 Below we discuss the effect of some of the most important fields
9830 (@pxref{operating-system Reference}, for details about all the available
9831 fields), and how to @dfn{instantiate} the operating system using
9832 @command{guix system}.
9833
9834 @unnumberedsubsubsec Bootloader
9835
9836 @cindex legacy boot, on Intel machines
9837 @cindex BIOS boot, on Intel machines
9838 @cindex UEFI boot
9839 @cindex EFI boot
9840 The @code{bootloader} field describes the method that will be used to boot
9841 your system. Machines based on Intel processors can boot in ``legacy'' BIOS
9842 mode, as in the example above. However, more recent machines rely instead on
9843 the @dfn{Unified Extensible Firmware Interface} (UEFI) to boot. In that case,
9844 the @code{bootloader} field should contain something along these lines:
9845
9846 @example
9847 (bootloader-configuration
9848 (bootloader grub-efi-bootloader)
9849 (target "/boot/efi"))
9850 @end example
9851
9852 @xref{Bootloader Configuration}, for more information on the available
9853 configuration options.
9854
9855 @unnumberedsubsubsec Globally-Visible Packages
9856
9857 @vindex %base-packages
9858 The @code{packages} field lists packages that will be globally visible
9859 on the system, for all user accounts---i.e., in every user's @code{PATH}
9860 environment variable---in addition to the per-user profiles
9861 (@pxref{Invoking guix package}). The @var{%base-packages} variable
9862 provides all the tools one would expect for basic user and administrator
9863 tasks---including the GNU Core Utilities, the GNU Networking Utilities,
9864 the GNU Zile lightweight text editor, @command{find}, @command{grep},
9865 etc. The example above adds GNU@tie{}Screen to those,
9866 taken from the @code{(gnu packages screen)}
9867 module (@pxref{Package Modules}). The
9868 @code{(list package output)} syntax can be used to add a specific output
9869 of a package:
9870
9871 @lisp
9872 (use-modules (gnu packages))
9873 (use-modules (gnu packages dns))
9874
9875 (operating-system
9876 ;; ...
9877 (packages (cons (list bind "utils")
9878 %base-packages)))
9879 @end lisp
9880
9881 @findex specification->package
9882 Referring to packages by variable name, like @code{bind} above, has
9883 the advantage of being unambiguous; it also allows typos and such to be
9884 diagnosed right away as ``unbound variables''. The downside is that one
9885 needs to know which module defines which package, and to augment the
9886 @code{use-package-modules} line accordingly. To avoid that, one can use
9887 the @code{specification->package} procedure of the @code{(gnu packages)}
9888 module, which returns the best package for a given name or name and
9889 version:
9890
9891 @lisp
9892 (use-modules (gnu packages))
9893
9894 (operating-system
9895 ;; ...
9896 (packages (append (map specification->package
9897 '("tcpdump" "htop" "gnupg@@2.0"))
9898 %base-packages)))
9899 @end lisp
9900
9901 @unnumberedsubsubsec System Services
9902
9903 @cindex services
9904 @vindex %base-services
9905 The @code{services} field lists @dfn{system services} to be made
9906 available when the system starts (@pxref{Services}).
9907 The @code{operating-system} declaration above specifies that, in
9908 addition to the basic services, we want the @command{lshd} secure shell
9909 daemon listening on port 2222 (@pxref{Networking Services,
9910 @code{lsh-service}}). Under the hood,
9911 @code{lsh-service} arranges so that @code{lshd} is started with the
9912 right command-line options, possibly with supporting configuration files
9913 generated as needed (@pxref{Defining Services}).
9914
9915 @cindex customization, of services
9916 @findex modify-services
9917 Occasionally, instead of using the base services as is, you will want to
9918 customize them. To do this, use @code{modify-services} (@pxref{Service
9919 Reference, @code{modify-services}}) to modify the list.
9920
9921 For example, suppose you want to modify @code{guix-daemon} and Mingetty
9922 (the console log-in) in the @var{%base-services} list (@pxref{Base
9923 Services, @code{%base-services}}). To do that, you can write the
9924 following in your operating system declaration:
9925
9926 @lisp
9927 (define %my-services
9928 ;; My very own list of services.
9929 (modify-services %base-services
9930 (guix-service-type config =>
9931 (guix-configuration
9932 (inherit config)
9933 (use-substitutes? #f)
9934 (extra-options '("--gc-keep-derivations"))))
9935 (mingetty-service-type config =>
9936 (mingetty-configuration
9937 (inherit config)))))
9938
9939 (operating-system
9940 ;; @dots{}
9941 (services %my-services))
9942 @end lisp
9943
9944 This changes the configuration---i.e., the service parameters---of the
9945 @code{guix-service-type} instance, and that of all the
9946 @code{mingetty-service-type} instances in the @var{%base-services} list.
9947 Observe how this is accomplished: first, we arrange for the original
9948 configuration to be bound to the identifier @code{config} in the
9949 @var{body}, and then we write the @var{body} so that it evaluates to the
9950 desired configuration. In particular, notice how we use @code{inherit}
9951 to create a new configuration which has the same values as the old
9952 configuration, but with a few modifications.
9953
9954 @cindex encrypted disk
9955 The configuration for a typical ``desktop'' usage, with an encrypted
9956 root partition, the X11 display
9957 server, GNOME and Xfce (users can choose which of these desktop
9958 environments to use at the log-in screen by pressing @kbd{F1}), network
9959 management, power management, and more, would look like this:
9960
9961 @lisp
9962 @include os-config-desktop.texi
9963 @end lisp
9964
9965 A graphical system with a choice of lightweight window managers
9966 instead of full-blown desktop environments would look like this:
9967
9968 @lisp
9969 @include os-config-lightweight-desktop.texi
9970 @end lisp
9971
9972 This example refers to the @file{/boot/efi} file system by its UUID,
9973 @code{1234-ABCD}. Replace this UUID with the right UUID on your system,
9974 as returned by the @command{blkid} command.
9975
9976 @xref{Desktop Services}, for the exact list of services provided by
9977 @var{%desktop-services}. @xref{X.509 Certificates}, for background
9978 information about the @code{nss-certs} package that is used here.
9979
9980 Again, @var{%desktop-services} is just a list of service objects. If
9981 you want to remove services from there, you can do so using the
9982 procedures for list filtering (@pxref{SRFI-1 Filtering and
9983 Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
9984 following expression returns a list that contains all the services in
9985 @var{%desktop-services} minus the Avahi service:
9986
9987 @example
9988 (remove (lambda (service)
9989 (eq? (service-kind service) avahi-service-type))
9990 %desktop-services)
9991 @end example
9992
9993 @unnumberedsubsubsec Instantiating the System
9994
9995 Assuming the @code{operating-system} declaration
9996 is stored in the @file{my-system-config.scm}
9997 file, the @command{guix system reconfigure my-system-config.scm} command
9998 instantiates that configuration, and makes it the default GRUB boot
9999 entry (@pxref{Invoking guix system}).
10000
10001 The normal way to change the system configuration is by updating this
10002 file and re-running @command{guix system reconfigure}. One should never
10003 have to touch files in @file{/etc} or to run commands that modify the
10004 system state such as @command{useradd} or @command{grub-install}. In
10005 fact, you must avoid that since that would not only void your warranty
10006 but also prevent you from rolling back to previous versions of your
10007 system, should you ever need to.
10008
10009 @cindex roll-back, of the operating system
10010 Speaking of roll-back, each time you run @command{guix system
10011 reconfigure}, a new @dfn{generation} of the system is created---without
10012 modifying or deleting previous generations. Old system generations get
10013 an entry in the bootloader boot menu, allowing you to boot them in case
10014 something went wrong with the latest generation. Reassuring, no? The
10015 @command{guix system list-generations} command lists the system
10016 generations available on disk. It is also possible to roll back the
10017 system via the commands @command{guix system roll-back} and
10018 @command{guix system switch-generation}.
10019
10020 Although the @command{guix system reconfigure} command will not modify
10021 previous generations, you must take care when the current generation is not
10022 the latest (e.g., after invoking @command{guix system roll-back}), since
10023 the operation might overwrite a later generation (@pxref{Invoking guix
10024 system}).
10025
10026 @unnumberedsubsubsec The Programming Interface
10027
10028 At the Scheme level, the bulk of an @code{operating-system} declaration
10029 is instantiated with the following monadic procedure (@pxref{The Store
10030 Monad}):
10031
10032 @deffn {Monadic Procedure} operating-system-derivation os
10033 Return a derivation that builds @var{os}, an @code{operating-system}
10034 object (@pxref{Derivations}).
10035
10036 The output of the derivation is a single directory that refers to all
10037 the packages, configuration files, and other supporting files needed to
10038 instantiate @var{os}.
10039 @end deffn
10040
10041 This procedure is provided by the @code{(gnu system)} module. Along
10042 with @code{(gnu services)} (@pxref{Services}), this module contains the
10043 guts of GuixSD. Make sure to visit it!
10044
10045
10046 @node operating-system Reference
10047 @subsection @code{operating-system} Reference
10048
10049 This section summarizes all the options available in
10050 @code{operating-system} declarations (@pxref{Using the Configuration
10051 System}).
10052
10053 @deftp {Data Type} operating-system
10054 This is the data type representing an operating system configuration.
10055 By that, we mean all the global system configuration, not per-user
10056 configuration (@pxref{Using the Configuration System}).
10057
10058 @table @asis
10059 @item @code{kernel} (default: @var{linux-libre})
10060 The package object of the operating system kernel to use@footnote{Currently
10061 only the Linux-libre kernel is supported. In the future, it will be
10062 possible to use the GNU@tie{}Hurd.}.
10063
10064 @item @code{kernel-arguments} (default: @code{'()})
10065 List of strings or gexps representing additional arguments to pass on
10066 the command-line of the kernel---e.g., @code{("console=ttyS0")}.
10067
10068 @item @code{bootloader}
10069 The system bootloader configuration object. @xref{Bootloader Configuration}.
10070
10071 @item @code{initrd-modules} (default: @code{%base-initrd-modules})
10072 @cindex initrd
10073 @cindex initial RAM disk
10074 The list of Linux kernel modules that need to be available in the
10075 initial RAM disk. @xref{Initial RAM Disk}.
10076
10077 @item @code{initrd} (default: @code{base-initrd})
10078 A procedure that returns an initial RAM disk for the Linux
10079 kernel. This field is provided to support low-level customization and
10080 should rarely be needed for casual use. @xref{Initial RAM Disk}.
10081
10082 @item @code{firmware} (default: @var{%base-firmware})
10083 @cindex firmware
10084 List of firmware packages loadable by the operating system kernel.
10085
10086 The default includes firmware needed for Atheros- and Broadcom-based
10087 WiFi devices (Linux-libre modules @code{ath9k} and @code{b43-open},
10088 respectively). @xref{Hardware Considerations}, for more info on
10089 supported hardware.
10090
10091 @item @code{host-name}
10092 The host name.
10093
10094 @item @code{hosts-file}
10095 @cindex hosts file
10096 A file-like object (@pxref{G-Expressions, file-like objects}) for use as
10097 @file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
10098 Reference Manual}). The default is a file with entries for
10099 @code{localhost} and @var{host-name}.
10100
10101 @item @code{mapped-devices} (default: @code{'()})
10102 A list of mapped devices. @xref{Mapped Devices}.
10103
10104 @item @code{file-systems}
10105 A list of file systems. @xref{File Systems}.
10106
10107 @item @code{swap-devices} (default: @code{'()})
10108 @cindex swap devices
10109 A list of strings identifying devices or files to be used for ``swap
10110 space'' (@pxref{Memory Concepts,,, libc, The GNU C Library Reference
10111 Manual}). For example, @code{'("/dev/sda3")} or @code{'("/swapfile")}.
10112 It is possible to specify a swap file in a file system on a mapped
10113 device, provided that the necessary device mapping and file system are
10114 also specified. @xref{Mapped Devices} and @ref{File Systems}.
10115
10116 @item @code{users} (default: @code{%base-user-accounts})
10117 @itemx @code{groups} (default: @var{%base-groups})
10118 List of user accounts and groups. @xref{User Accounts}.
10119
10120 If the @code{users} list lacks a user account with UID@tie{}0, a
10121 ``root'' account with UID@tie{}0 is automatically added.
10122
10123 @item @code{skeletons} (default: @code{(default-skeletons)})
10124 A list target file name/file-like object tuples (@pxref{G-Expressions,
10125 file-like objects}). These are the skeleton files that will be added to
10126 the home directory of newly-created user accounts.
10127
10128 For instance, a valid value may look like this:
10129
10130 @example
10131 `((".bashrc" ,(plain-file "bashrc" "echo Hello\n"))
10132 (".guile" ,(plain-file "guile"
10133 "(use-modules (ice-9 readline))
10134 (activate-readline)")))
10135 @end example
10136
10137 @item @code{issue} (default: @var{%default-issue})
10138 A string denoting the contents of the @file{/etc/issue} file, which is
10139 displayed when users log in on a text console.
10140
10141 @item @code{packages} (default: @var{%base-packages})
10142 The set of packages installed in the global profile, which is accessible
10143 at @file{/run/current-system/profile}.
10144
10145 The default set includes core utilities and it is good practice to
10146 install non-core utilities in user profiles (@pxref{Invoking guix
10147 package}).
10148
10149 @item @code{timezone}
10150 A timezone identifying string---e.g., @code{"Europe/Paris"}.
10151
10152 You can run the @command{tzselect} command to find out which timezone
10153 string corresponds to your region. Choosing an invalid timezone name
10154 causes @command{guix system} to fail.
10155
10156 @item @code{locale} (default: @code{"en_US.utf8"})
10157 The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
10158 Library Reference Manual}). @xref{Locales}, for more information.
10159
10160 @item @code{locale-definitions} (default: @var{%default-locale-definitions})
10161 The list of locale definitions to be compiled and that may be used at
10162 run time. @xref{Locales}.
10163
10164 @item @code{locale-libcs} (default: @code{(list @var{glibc})})
10165 The list of GNU@tie{}libc packages whose locale data and tools are used
10166 to build the locale definitions. @xref{Locales}, for compatibility
10167 considerations that justify this option.
10168
10169 @item @code{name-service-switch} (default: @var{%default-nss})
10170 Configuration of the libc name service switch (NSS)---a
10171 @code{<name-service-switch>} object. @xref{Name Service Switch}, for
10172 details.
10173
10174 @item @code{services} (default: @var{%base-services})
10175 A list of service objects denoting system services. @xref{Services}.
10176
10177 @item @code{pam-services} (default: @code{(base-pam-services)})
10178 @cindex PAM
10179 @cindex pluggable authentication modules
10180 Linux @dfn{pluggable authentication module} (PAM) services.
10181 @c FIXME: Add xref to PAM services section.
10182
10183 @item @code{setuid-programs} (default: @var{%setuid-programs})
10184 List of string-valued G-expressions denoting setuid programs.
10185 @xref{Setuid Programs}.
10186
10187 @item @code{sudoers-file} (default: @var{%sudoers-specification})
10188 @cindex sudoers file
10189 The contents of the @file{/etc/sudoers} file as a file-like object
10190 (@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
10191
10192 This file specifies which users can use the @command{sudo} command, what
10193 they are allowed to do, and what privileges they may gain. The default
10194 is that only @code{root} and members of the @code{wheel} group may use
10195 @code{sudo}.
10196
10197 @end table
10198 @end deftp
10199
10200 @node File Systems
10201 @subsection File Systems
10202
10203 The list of file systems to be mounted is specified in the
10204 @code{file-systems} field of the operating system declaration
10205 (@pxref{Using the Configuration System}). Each file system is declared
10206 using the @code{file-system} form, like this:
10207
10208 @example
10209 (file-system
10210 (mount-point "/home")
10211 (device "/dev/sda3")
10212 (type "ext4"))
10213 @end example
10214
10215 As usual, some of the fields are mandatory---those shown in the example
10216 above---while others can be omitted. These are described below.
10217
10218 @deftp {Data Type} file-system
10219 Objects of this type represent file systems to be mounted. They
10220 contain the following members:
10221
10222 @table @asis
10223 @item @code{type}
10224 This is a string specifying the type of the file system---e.g.,
10225 @code{"ext4"}.
10226
10227 @item @code{mount-point}
10228 This designates the place where the file system is to be mounted.
10229
10230 @item @code{device}
10231 This names the ``source'' of the file system. It can be one of three
10232 things: a file system label, a file system UUID, or the name of a
10233 @file{/dev} node. Labels and UUIDs offer a way to refer to file
10234 systems without having to hard-code their actual device
10235 name@footnote{Note that, while it is tempting to use
10236 @file{/dev/disk/by-uuid} and similar device names to achieve the same
10237 result, this is not recommended: These special device nodes are created
10238 by the udev daemon and may be unavailable at the time the device is
10239 mounted.}.
10240
10241 @findex file-system-label
10242 File system labels are created using the @code{file-system-label}
10243 procedure, UUIDs are created using @code{uuid}, and @file{/dev} node are
10244 plain strings. Here's an example of a file system referred to by its
10245 label, as shown by the @command{e2label} command:
10246
10247 @example
10248 (file-system
10249 (mount-point "/home")
10250 (type "ext4")
10251 (device (file-system-label "my-home")))
10252 @end example
10253
10254 @findex uuid
10255 UUIDs are converted from their string representation (as shown by the
10256 @command{tune2fs -l} command) using the @code{uuid} form@footnote{The
10257 @code{uuid} form expects 16-byte UUIDs as defined in
10258 @uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
10259 form of UUID used by the ext2 family of file systems and others, but it
10260 is different from ``UUIDs'' found in FAT file systems, for instance.},
10261 like this:
10262
10263 @example
10264 (file-system
10265 (mount-point "/home")
10266 (type "ext4")
10267 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
10268 @end example
10269
10270 When the source of a file system is a mapped device (@pxref{Mapped
10271 Devices}), its @code{device} field @emph{must} refer to the mapped
10272 device name---e.g., @file{"/dev/mapper/root-partition"}.
10273 This is required so that
10274 the system knows that mounting the file system depends on having the
10275 corresponding device mapping established.
10276
10277 @item @code{flags} (default: @code{'()})
10278 This is a list of symbols denoting mount flags. Recognized flags
10279 include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
10280 access to special files), @code{no-suid} (ignore setuid and setgid
10281 bits), and @code{no-exec} (disallow program execution.)
10282
10283 @item @code{options} (default: @code{#f})
10284 This is either @code{#f}, or a string denoting mount options.
10285
10286 @item @code{mount?} (default: @code{#t})
10287 This value indicates whether to automatically mount the file system when
10288 the system is brought up. When set to @code{#f}, the file system gets
10289 an entry in @file{/etc/fstab} (read by the @command{mount} command) but
10290 is not automatically mounted.
10291
10292 @item @code{needed-for-boot?} (default: @code{#f})
10293 This Boolean value indicates whether the file system is needed when
10294 booting. If that is true, then the file system is mounted when the
10295 initial RAM disk (initrd) is loaded. This is always the case, for
10296 instance, for the root file system.
10297
10298 @item @code{check?} (default: @code{#t})
10299 This Boolean indicates whether the file system needs to be checked for
10300 errors before being mounted.
10301
10302 @item @code{create-mount-point?} (default: @code{#f})
10303 When true, the mount point is created if it does not exist yet.
10304
10305 @item @code{dependencies} (default: @code{'()})
10306 This is a list of @code{<file-system>} or @code{<mapped-device>} objects
10307 representing file systems that must be mounted or mapped devices that
10308 must be opened before (and unmounted or closed after) this one.
10309
10310 As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
10311 a dependency of @file{/sys/fs/cgroup/cpu} and
10312 @file{/sys/fs/cgroup/memory}.
10313
10314 Another example is a file system that depends on a mapped device, for
10315 example for an encrypted partition (@pxref{Mapped Devices}).
10316 @end table
10317 @end deftp
10318
10319 The @code{(gnu system file-systems)} exports the following useful
10320 variables.
10321
10322 @defvr {Scheme Variable} %base-file-systems
10323 These are essential file systems that are required on normal systems,
10324 such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
10325 below.) Operating system declarations should always contain at least
10326 these.
10327 @end defvr
10328
10329 @defvr {Scheme Variable} %pseudo-terminal-file-system
10330 This is the file system to be mounted as @file{/dev/pts}. It supports
10331 @dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
10332 functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
10333 Manual}). Pseudo-terminals are used by terminal emulators such as
10334 @command{xterm}.
10335 @end defvr
10336
10337 @defvr {Scheme Variable} %shared-memory-file-system
10338 This file system is mounted as @file{/dev/shm} and is used to support
10339 memory sharing across processes (@pxref{Memory-mapped I/O,
10340 @code{shm_open},, libc, The GNU C Library Reference Manual}).
10341 @end defvr
10342
10343 @defvr {Scheme Variable} %immutable-store
10344 This file system performs a read-only ``bind mount'' of
10345 @file{/gnu/store}, making it read-only for all the users including
10346 @code{root}. This prevents against accidental modification by software
10347 running as @code{root} or by system administrators.
10348
10349 The daemon itself is still able to write to the store: it remounts it
10350 read-write in its own ``name space.''
10351 @end defvr
10352
10353 @defvr {Scheme Variable} %binary-format-file-system
10354 The @code{binfmt_misc} file system, which allows handling of arbitrary
10355 executable file types to be delegated to user space. This requires the
10356 @code{binfmt.ko} kernel module to be loaded.
10357 @end defvr
10358
10359 @defvr {Scheme Variable} %fuse-control-file-system
10360 The @code{fusectl} file system, which allows unprivileged users to mount
10361 and unmount user-space FUSE file systems. This requires the
10362 @code{fuse.ko} kernel module to be loaded.
10363 @end defvr
10364
10365 @node Mapped Devices
10366 @subsection Mapped Devices
10367
10368 @cindex device mapping
10369 @cindex mapped devices
10370 The Linux kernel has a notion of @dfn{device mapping}: a block device,
10371 such as a hard disk partition, can be @dfn{mapped} into another device,
10372 usually in @code{/dev/mapper/},
10373 with additional processing over the data that flows through
10374 it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
10375 concept of a ``mapped device'' and that of a file system: both boil down
10376 to @emph{translating} input/output operations made on a file to
10377 operations on its backing store. Thus, the Hurd implements mapped
10378 devices, like file systems, using the generic @dfn{translator} mechanism
10379 (@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
10380 typical example is encryption device mapping: all writes to the mapped
10381 device are encrypted, and all reads are deciphered, transparently.
10382 Guix extends this notion by considering any device or set of devices that
10383 are @dfn{transformed} in some way to create a new device; for instance,
10384 RAID devices are obtained by @dfn{assembling} several other devices, such
10385 as hard disks or partitions, into a new one that behaves as one partition.
10386 Other examples, not yet implemented, are LVM logical volumes.
10387
10388 Mapped devices are declared using the @code{mapped-device} form,
10389 defined as follows; for examples, see below.
10390
10391 @deftp {Data Type} mapped-device
10392 Objects of this type represent device mappings that will be made when
10393 the system boots up.
10394
10395 @table @code
10396 @item source
10397 This is either a string specifying the name of the block device to be mapped,
10398 such as @code{"/dev/sda3"}, or a list of such strings when several devices
10399 need to be assembled for creating a new one.
10400
10401 @item target
10402 This string specifies the name of the resulting mapped device. For
10403 kernel mappers such as encrypted devices of type @code{luks-device-mapping},
10404 specifying @code{"my-partition"} leads to the creation of
10405 the @code{"/dev/mapper/my-partition"} device.
10406 For RAID devices of type @code{raid-device-mapping}, the full device name
10407 such as @code{"/dev/md0"} needs to be given.
10408
10409 @item type
10410 This must be a @code{mapped-device-kind} object, which specifies how
10411 @var{source} is mapped to @var{target}.
10412 @end table
10413 @end deftp
10414
10415 @defvr {Scheme Variable} luks-device-mapping
10416 This defines LUKS block device encryption using the @command{cryptsetup}
10417 command from the package with the same name. It relies on the
10418 @code{dm-crypt} Linux kernel module.
10419 @end defvr
10420
10421 @defvr {Scheme Variable} raid-device-mapping
10422 This defines a RAID device, which is assembled using the @code{mdadm}
10423 command from the package with the same name. It requires a Linux kernel
10424 module for the appropriate RAID level to be loaded, such as @code{raid456}
10425 for RAID-4, RAID-5 or RAID-6, or @code{raid10} for RAID-10.
10426 @end defvr
10427
10428 @cindex disk encryption
10429 @cindex LUKS
10430 The following example specifies a mapping from @file{/dev/sda3} to
10431 @file{/dev/mapper/home} using LUKS---the
10432 @url{https://gitlab.com/cryptsetup/cryptsetup,Linux Unified Key Setup}, a
10433 standard mechanism for disk encryption.
10434 The @file{/dev/mapper/home}
10435 device can then be used as the @code{device} of a @code{file-system}
10436 declaration (@pxref{File Systems}).
10437
10438 @example
10439 (mapped-device
10440 (source "/dev/sda3")
10441 (target "home")
10442 (type luks-device-mapping))
10443 @end example
10444
10445 Alternatively, to become independent of device numbering, one may obtain
10446 the LUKS UUID (@dfn{unique identifier}) of the source device by a
10447 command like:
10448
10449 @example
10450 cryptsetup luksUUID /dev/sda3
10451 @end example
10452
10453 and use it as follows:
10454
10455 @example
10456 (mapped-device
10457 (source (uuid "cb67fc72-0d54-4c88-9d4b-b225f30b0f44"))
10458 (target "home")
10459 (type luks-device-mapping))
10460 @end example
10461
10462 @cindex swap encryption
10463 It is also desirable to encrypt swap space, since swap space may contain
10464 sensitive data. One way to accomplish that is to use a swap file in a
10465 file system on a device mapped via LUKS encryption. In this way, the
10466 swap file is encrypted because the entire device is encrypted.
10467 @xref{Preparing for Installation,,Disk Partitioning}, for an example.
10468
10469 A RAID device formed of the partitions @file{/dev/sda1} and @file{/dev/sdb1}
10470 may be declared as follows:
10471
10472 @example
10473 (mapped-device
10474 (source (list "/dev/sda1" "/dev/sdb1"))
10475 (target "/dev/md0")
10476 (type raid-device-mapping))
10477 @end example
10478
10479 The @file{/dev/md0} device can then be used as the @code{device} of a
10480 @code{file-system} declaration (@pxref{File Systems}).
10481 Note that the RAID level need not be given; it is chosen during the
10482 initial creation and formatting of the RAID device and is determined
10483 automatically later.
10484
10485
10486 @node User Accounts
10487 @subsection User Accounts
10488
10489 @cindex users
10490 @cindex accounts
10491 @cindex user accounts
10492 User accounts and groups are entirely managed through the
10493 @code{operating-system} declaration. They are specified with the
10494 @code{user-account} and @code{user-group} forms:
10495
10496 @example
10497 (user-account
10498 (name "alice")
10499 (group "users")
10500 (supplementary-groups '("wheel" ;allow use of sudo, etc.
10501 "audio" ;sound card
10502 "video" ;video devices such as webcams
10503 "cdrom")) ;the good ol' CD-ROM
10504 (comment "Bob's sister")
10505 (home-directory "/home/alice"))
10506 @end example
10507
10508 When booting or upon completion of @command{guix system reconfigure},
10509 the system ensures that only the user accounts and groups specified in
10510 the @code{operating-system} declaration exist, and with the specified
10511 properties. Thus, account or group creations or modifications made by
10512 directly invoking commands such as @command{useradd} are lost upon
10513 reconfiguration or reboot. This ensures that the system remains exactly
10514 as declared.
10515
10516 @deftp {Data Type} user-account
10517 Objects of this type represent user accounts. The following members may
10518 be specified:
10519
10520 @table @asis
10521 @item @code{name}
10522 The name of the user account.
10523
10524 @item @code{group}
10525 @cindex groups
10526 This is the name (a string) or identifier (a number) of the user group
10527 this account belongs to.
10528
10529 @item @code{supplementary-groups} (default: @code{'()})
10530 Optionally, this can be defined as a list of group names that this
10531 account belongs to.
10532
10533 @item @code{uid} (default: @code{#f})
10534 This is the user ID for this account (a number), or @code{#f}. In the
10535 latter case, a number is automatically chosen by the system when the
10536 account is created.
10537
10538 @item @code{comment} (default: @code{""})
10539 A comment about the account, such as the account owner's full name.
10540
10541 @item @code{home-directory}
10542 This is the name of the home directory for the account.
10543
10544 @item @code{create-home-directory?} (default: @code{#t})
10545 Indicates whether the home directory of this account should be created
10546 if it does not exist yet.
10547
10548 @item @code{shell} (default: Bash)
10549 This is a G-expression denoting the file name of a program to be used as
10550 the shell (@pxref{G-Expressions}).
10551
10552 @item @code{system?} (default: @code{#f})
10553 This Boolean value indicates whether the account is a ``system''
10554 account. System accounts are sometimes treated specially; for instance,
10555 graphical login managers do not list them.
10556
10557 @anchor{user-account-password}
10558 @item @code{password} (default: @code{#f})
10559 You would normally leave this field to @code{#f}, initialize user
10560 passwords as @code{root} with the @command{passwd} command, and then let
10561 users change it with @command{passwd}. Passwords set with
10562 @command{passwd} are of course preserved across reboot and
10563 reconfiguration.
10564
10565 If you @emph{do} want to have a preset password for an account, then
10566 this field must contain the encrypted password, as a string.
10567 @xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
10568 on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
10569 Manual}, for information on Guile's @code{crypt} procedure.
10570
10571 @end table
10572 @end deftp
10573
10574 @cindex groups
10575 User group declarations are even simpler:
10576
10577 @example
10578 (user-group (name "students"))
10579 @end example
10580
10581 @deftp {Data Type} user-group
10582 This type is for, well, user groups. There are just a few fields:
10583
10584 @table @asis
10585 @item @code{name}
10586 The name of the group.
10587
10588 @item @code{id} (default: @code{#f})
10589 The group identifier (a number). If @code{#f}, a new number is
10590 automatically allocated when the group is created.
10591
10592 @item @code{system?} (default: @code{#f})
10593 This Boolean value indicates whether the group is a ``system'' group.
10594 System groups have low numerical IDs.
10595
10596 @item @code{password} (default: @code{#f})
10597 What, user groups can have a password? Well, apparently yes. Unless
10598 @code{#f}, this field specifies the password of the group.
10599
10600 @end table
10601 @end deftp
10602
10603 For convenience, a variable lists all the basic user groups one may
10604 expect:
10605
10606 @defvr {Scheme Variable} %base-groups
10607 This is the list of basic user groups that users and/or packages expect
10608 to be present on the system. This includes groups such as ``root'',
10609 ``wheel'', and ``users'', as well as groups used to control access to
10610 specific devices such as ``audio'', ``disk'', and ``cdrom''.
10611 @end defvr
10612
10613 @defvr {Scheme Variable} %base-user-accounts
10614 This is the list of basic system accounts that programs may expect to
10615 find on a GNU/Linux system, such as the ``nobody'' account.
10616
10617 Note that the ``root'' account is not included here. It is a
10618 special-case and is automatically added whether or not it is specified.
10619 @end defvr
10620
10621 @node Locales
10622 @subsection Locales
10623
10624 @cindex locale
10625 A @dfn{locale} defines cultural conventions for a particular language
10626 and region of the world (@pxref{Locales,,, libc, The GNU C Library
10627 Reference Manual}). Each locale has a name that typically has the form
10628 @code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
10629 @code{fr_LU.utf8} designates the locale for the French language, with
10630 cultural conventions from Luxembourg, and using the UTF-8 encoding.
10631
10632 @cindex locale definition
10633 Usually, you will want to specify the default locale for the machine
10634 using the @code{locale} field of the @code{operating-system} declaration
10635 (@pxref{operating-system Reference, @code{locale}}).
10636
10637 The selected locale is automatically added to the @dfn{locale
10638 definitions} known to the system if needed, with its codeset inferred
10639 from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
10640 @code{UTF-8} codeset. Additional locale definitions can be specified in
10641 the @code{locale-definitions} slot of @code{operating-system}---this is
10642 useful, for instance, if the codeset could not be inferred from the
10643 locale name. The default set of locale definitions includes some widely
10644 used locales, but not all the available locales, in order to save space.
10645
10646 For instance, to add the North Frisian locale for Germany, the value of
10647 that field may be:
10648
10649 @example
10650 (cons (locale-definition
10651 (name "fy_DE.utf8") (source "fy_DE"))
10652 %default-locale-definitions)
10653 @end example
10654
10655 Likewise, to save space, one might want @code{locale-definitions} to
10656 list only the locales that are actually used, as in:
10657
10658 @example
10659 (list (locale-definition
10660 (name "ja_JP.eucjp") (source "ja_JP")
10661 (charset "EUC-JP")))
10662 @end example
10663
10664 @vindex LOCPATH
10665 The compiled locale definitions are available at
10666 @file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
10667 version, which is the default location where the GNU@tie{}libc provided
10668 by Guix looks for locale data. This can be overridden using the
10669 @code{LOCPATH} environment variable (@pxref{locales-and-locpath,
10670 @code{LOCPATH} and locale packages}).
10671
10672 The @code{locale-definition} form is provided by the @code{(gnu system
10673 locale)} module. Details are given below.
10674
10675 @deftp {Data Type} locale-definition
10676 This is the data type of a locale definition.
10677
10678 @table @asis
10679
10680 @item @code{name}
10681 The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
10682 Reference Manual}, for more information on locale names.
10683
10684 @item @code{source}
10685 The name of the source for that locale. This is typically the
10686 @code{@var{language}_@var{territory}} part of the locale name.
10687
10688 @item @code{charset} (default: @code{"UTF-8"})
10689 The ``character set'' or ``code set'' for that locale,
10690 @uref{http://www.iana.org/assignments/character-sets, as defined by
10691 IANA}.
10692
10693 @end table
10694 @end deftp
10695
10696 @defvr {Scheme Variable} %default-locale-definitions
10697 A list of commonly used UTF-8 locales, used as the default
10698 value of the @code{locale-definitions} field of @code{operating-system}
10699 declarations.
10700
10701 @cindex locale name
10702 @cindex normalized codeset in locale names
10703 These locale definitions use the @dfn{normalized codeset} for the part
10704 that follows the dot in the name (@pxref{Using gettextized software,
10705 normalized codeset,, libc, The GNU C Library Reference Manual}). So for
10706 instance it has @code{uk_UA.utf8} but @emph{not}, say,
10707 @code{uk_UA.UTF-8}.
10708 @end defvr
10709
10710 @subsubsection Locale Data Compatibility Considerations
10711
10712 @cindex incompatibility, of locale data
10713 @code{operating-system} declarations provide a @code{locale-libcs} field
10714 to specify the GNU@tie{}libc packages that are used to compile locale
10715 declarations (@pxref{operating-system Reference}). ``Why would I
10716 care?'', you may ask. Well, it turns out that the binary format of
10717 locale data is occasionally incompatible from one libc version to
10718 another.
10719
10720 @c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
10721 @c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
10722 For instance, a program linked against libc version 2.21 is unable to
10723 read locale data produced with libc 2.22; worse, that program
10724 @emph{aborts} instead of simply ignoring the incompatible locale
10725 data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
10726 the incompatible locale data, which is already an improvement.}.
10727 Similarly, a program linked against libc 2.22 can read most, but not
10728 all, of the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
10729 data is incompatible); thus calls to @code{setlocale} may fail, but
10730 programs will not abort.
10731
10732 The ``problem'' in GuixSD is that users have a lot of freedom: They can
10733 choose whether and when to upgrade software in their profiles, and might
10734 be using a libc version different from the one the system administrator
10735 used to build the system-wide locale data.
10736
10737 Fortunately, unprivileged users can also install their own locale data
10738 and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
10739 @code{GUIX_LOCPATH} and locale packages}).
10740
10741 Still, it is best if the system-wide locale data at
10742 @file{/run/current-system/locale} is built for all the libc versions
10743 actually in use on the system, so that all the programs can access
10744 it---this is especially crucial on a multi-user system. To do that, the
10745 administrator can specify several libc packages in the
10746 @code{locale-libcs} field of @code{operating-system}:
10747
10748 @example
10749 (use-package-modules base)
10750
10751 (operating-system
10752 ;; @dots{}
10753 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
10754 @end example
10755
10756 This example would lead to a system containing locale definitions for
10757 both libc 2.21 and the current version of libc in
10758 @file{/run/current-system/locale}.
10759
10760
10761 @node Services
10762 @subsection Services
10763
10764 @cindex system services
10765 An important part of preparing an @code{operating-system} declaration is
10766 listing @dfn{system services} and their configuration (@pxref{Using the
10767 Configuration System}). System services are typically daemons launched
10768 when the system boots, or other actions needed at that time---e.g.,
10769 configuring network access.
10770
10771 GuixSD has a broad definition of ``service'' (@pxref{Service
10772 Composition}), but many services are managed by the GNU@tie{}Shepherd
10773 (@pxref{Shepherd Services}). On a running system, the @command{herd}
10774 command allows you to list the available services, show their status,
10775 start and stop them, or do other specific operations (@pxref{Jump
10776 Start,,, shepherd, The GNU Shepherd Manual}). For example:
10777
10778 @example
10779 # herd status
10780 @end example
10781
10782 The above command, run as @code{root}, lists the currently defined
10783 services. The @command{herd doc} command shows a synopsis of the given
10784 service and its associated actions:
10785
10786 @example
10787 # herd doc nscd
10788 Run libc's name service cache daemon (nscd).
10789
10790 # herd doc nscd action invalidate
10791 invalidate: Invalidate the given cache--e.g., 'hosts' for host name lookups.
10792 @end example
10793
10794 The @command{start}, @command{stop}, and @command{restart} sub-commands
10795 have the effect you would expect. For instance, the commands below stop
10796 the nscd service and restart the Xorg display server:
10797
10798 @example
10799 # herd stop nscd
10800 Service nscd has been stopped.
10801 # herd restart xorg-server
10802 Service xorg-server has been stopped.
10803 Service xorg-server has been started.
10804 @end example
10805
10806 The following sections document the available services, starting with
10807 the core services, that may be used in an @code{operating-system}
10808 declaration.
10809
10810 @menu
10811 * Base Services:: Essential system services.
10812 * Scheduled Job Execution:: The mcron service.
10813 * Log Rotation:: The rottlog service.
10814 * Networking Services:: Network setup, SSH daemon, etc.
10815 * X Window:: Graphical display.
10816 * Printing Services:: Local and remote printer support.
10817 * Desktop Services:: D-Bus and desktop services.
10818 * Sound Services:: ALSA and Pulseaudio services.
10819 * Database Services:: SQL databases, key-value stores, etc.
10820 * Mail Services:: IMAP, POP3, SMTP, and all that.
10821 * Messaging Services:: Messaging services.
10822 * Telephony Services:: Telephony services.
10823 * Monitoring Services:: Monitoring services.
10824 * Kerberos Services:: Kerberos services.
10825 * Web Services:: Web servers.
10826 * Certificate Services:: TLS certificates via Let's Encrypt.
10827 * DNS Services:: DNS daemons.
10828 * VPN Services:: VPN daemons.
10829 * Network File System:: NFS related services.
10830 * Continuous Integration:: The Cuirass service.
10831 * Power Management Services:: Extending battery life.
10832 * Audio Services:: The MPD.
10833 * Virtualization Services:: Virtualization services.
10834 * Version Control Services:: Providing remote access to Git repositories.
10835 * Game Services:: Game servers.
10836 * Miscellaneous Services:: Other services.
10837 @end menu
10838
10839 @node Base Services
10840 @subsubsection Base Services
10841
10842 The @code{(gnu services base)} module provides definitions for the basic
10843 services that one expects from the system. The services exported by
10844 this module are listed below.
10845
10846 @defvr {Scheme Variable} %base-services
10847 This variable contains a list of basic services (@pxref{Service Types
10848 and Services}, for more information on service objects) one would
10849 expect from the system: a login service (mingetty) on each tty, syslogd,
10850 the libc name service cache daemon (nscd), the udev device manager, and
10851 more.
10852
10853 This is the default value of the @code{services} field of
10854 @code{operating-system} declarations. Usually, when customizing a
10855 system, you will want to append services to @var{%base-services}, like
10856 this:
10857
10858 @example
10859 (cons* (service avahi-service-type)
10860 (service openssh-service-type)
10861 %base-services)
10862 @end example
10863 @end defvr
10864
10865 @defvr {Scheme Variable} special-files-service-type
10866 This is the service that sets up ``special files'' such as
10867 @file{/bin/sh}; an instance of it is part of @code{%base-services}.
10868
10869 The value associated with @code{special-files-service-type} services
10870 must be a list of tuples where the first element is the ``special file''
10871 and the second element is its target. By default it is:
10872
10873 @cindex @file{/bin/sh}
10874 @cindex @file{sh}, in @file{/bin}
10875 @example
10876 `(("/bin/sh" ,(file-append @var{bash} "/bin/sh")))
10877 @end example
10878
10879 @cindex @file{/usr/bin/env}
10880 @cindex @file{env}, in @file{/usr/bin}
10881 If you want to add, say, @code{/usr/bin/env} to your system, you can
10882 change it to:
10883
10884 @example
10885 `(("/bin/sh" ,(file-append @var{bash} "/bin/sh"))
10886 ("/usr/bin/env" ,(file-append @var{coreutils} "/bin/env")))
10887 @end example
10888
10889 Since this is part of @code{%base-services}, you can use
10890 @code{modify-services} to customize the set of special files
10891 (@pxref{Service Reference, @code{modify-services}}). But the simple way
10892 to add a special file is @i{via} the @code{extra-special-file} procedure
10893 (see below.)
10894 @end defvr
10895
10896 @deffn {Scheme Procedure} extra-special-file @var{file} @var{target}
10897 Use @var{target} as the ``special file'' @var{file}.
10898
10899 For example, adding the following lines to the @code{services} field of
10900 your operating system declaration leads to a @file{/usr/bin/env}
10901 symlink:
10902
10903 @example
10904 (extra-special-file "/usr/bin/env"
10905 (file-append coreutils "/bin/env"))
10906 @end example
10907 @end deffn
10908
10909 @deffn {Scheme Procedure} host-name-service @var{name}
10910 Return a service that sets the host name to @var{name}.
10911 @end deffn
10912
10913 @deffn {Scheme Procedure} login-service @var{config}
10914 Return a service to run login according to @var{config}, a
10915 @code{<login-configuration>} object, which specifies the message of the day,
10916 among other things.
10917 @end deffn
10918
10919 @deftp {Data Type} login-configuration
10920 This is the data type representing the configuration of login.
10921
10922 @table @asis
10923
10924 @item @code{motd}
10925 @cindex message of the day
10926 A file-like object containing the ``message of the day''.
10927
10928 @item @code{allow-empty-passwords?} (default: @code{#t})
10929 Allow empty passwords by default so that first-time users can log in when
10930 the 'root' account has just been created.
10931
10932 @end table
10933 @end deftp
10934
10935 @deffn {Scheme Procedure} mingetty-service @var{config}
10936 Return a service to run mingetty according to @var{config}, a
10937 @code{<mingetty-configuration>} object, which specifies the tty to run, among
10938 other things.
10939 @end deffn
10940
10941 @deftp {Data Type} mingetty-configuration
10942 This is the data type representing the configuration of Mingetty, which
10943 provides the default implementation of virtual console log-in.
10944
10945 @table @asis
10946
10947 @item @code{tty}
10948 The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
10949
10950 @item @code{auto-login} (default: @code{#f})
10951 When true, this field must be a string denoting the user name under
10952 which the system automatically logs in. When it is @code{#f}, a
10953 user name and password must be entered to log in.
10954
10955 @item @code{login-program} (default: @code{#f})
10956 This must be either @code{#f}, in which case the default log-in program
10957 is used (@command{login} from the Shadow tool suite), or a gexp denoting
10958 the name of the log-in program.
10959
10960 @item @code{login-pause?} (default: @code{#f})
10961 When set to @code{#t} in conjunction with @var{auto-login}, the user
10962 will have to press a key before the log-in shell is launched.
10963
10964 @item @code{mingetty} (default: @var{mingetty})
10965 The Mingetty package to use.
10966
10967 @end table
10968 @end deftp
10969
10970 @deffn {Scheme Procedure} agetty-service @var{config}
10971 Return a service to run agetty according to @var{config}, an
10972 @code{<agetty-configuration>} object, which specifies the tty to run,
10973 among other things.
10974 @end deffn
10975
10976 @deftp {Data Type} agetty-configuration
10977 This is the data type representing the configuration of agetty, which
10978 implements virtual and serial console log-in. See the @code{agetty(8)}
10979 man page for more information.
10980
10981 @table @asis
10982
10983 @item @code{tty}
10984 The name of the console this agetty runs on, as a string---e.g.,
10985 @code{"ttyS0"}. This argument is optional, it will default to
10986 a reasonable default serial port used by the kernel Linux.
10987
10988 For this, if there is a value for an option @code{agetty.tty} in the kernel
10989 command line, agetty will extract the device name of the serial port
10990 from it and use that.
10991
10992 If not and if there is a value for an option @code{console} with a tty in
10993 the Linux command line, agetty will extract the device name of the
10994 serial port from it and use that.
10995
10996 In both cases, agetty will leave the other serial device settings
10997 (baud rate etc.)@: alone---in the hope that Linux pinned them to the
10998 correct values.
10999
11000 @item @code{baud-rate} (default: @code{#f})
11001 A string containing a comma-separated list of one or more baud rates, in
11002 descending order.
11003
11004 @item @code{term} (default: @code{#f})
11005 A string containing the value used for the @code{TERM} environment
11006 variable.
11007
11008 @item @code{eight-bits?} (default: @code{#f})
11009 When @code{#t}, the tty is assumed to be 8-bit clean, and parity detection is
11010 disabled.
11011
11012 @item @code{auto-login} (default: @code{#f})
11013 When passed a login name, as a string, the specified user will be logged
11014 in automatically without prompting for their login name or password.
11015
11016 @item @code{no-reset?} (default: @code{#f})
11017 When @code{#t}, don't reset terminal cflags (control modes).
11018
11019 @item @code{host} (default: @code{#f})
11020 This accepts a string containing the "login_host", which will be written
11021 into the @file{/var/run/utmpx} file.
11022
11023 @item @code{remote?} (default: @code{#f})
11024 When set to @code{#t} in conjunction with @var{host}, this will add an
11025 @code{-r} fakehost option to the command line of the login program
11026 specified in @var{login-program}.
11027
11028 @item @code{flow-control?} (default: @code{#f})
11029 When set to @code{#t}, enable hardware (RTS/CTS) flow control.
11030
11031 @item @code{no-issue?} (default: @code{#f})
11032 When set to @code{#t}, the contents of the @file{/etc/issue} file will
11033 not be displayed before presenting the login prompt.
11034
11035 @item @code{init-string} (default: @code{#f})
11036 This accepts a string that will be sent to the tty or modem before
11037 sending anything else. It can be used to initialize a modem.
11038
11039 @item @code{no-clear?} (default: @code{#f})
11040 When set to @code{#t}, agetty will not clear the screen before showing
11041 the login prompt.
11042
11043 @item @code{login-program} (default: (file-append shadow "/bin/login"))
11044 This must be either a gexp denoting the name of a log-in program, or
11045 unset, in which case the default value is the @command{login} from the
11046 Shadow tool suite.
11047
11048 @item @code{local-line} (default: @code{#f})
11049 Control the CLOCAL line flag. This accepts one of three symbols as
11050 arguments, @code{'auto}, @code{'always}, or @code{'never}. If @code{#f},
11051 the default value chosen by agetty is @code{'auto}.
11052
11053 @item @code{extract-baud?} (default: @code{#f})
11054 When set to @code{#t}, instruct agetty to try to extract the baud rate
11055 from the status messages produced by certain types of modems.
11056
11057 @item @code{skip-login?} (default: @code{#f})
11058 When set to @code{#t}, do not prompt the user for a login name. This
11059 can be used with @var{login-program} field to use non-standard login
11060 systems.
11061
11062 @item @code{no-newline?} (default: @code{#f})
11063 When set to @code{#t}, do not print a newline before printing the
11064 @file{/etc/issue} file.
11065
11066 @c Is this dangerous only when used with login-program, or always?
11067 @item @code{login-options} (default: @code{#f})
11068 This option accepts a string containing options that are passed to the
11069 login program. When used with the @var{login-program}, be aware that a
11070 malicious user could try to enter a login name containing embedded
11071 options that could be parsed by the login program.
11072
11073 @item @code{login-pause} (default: @code{#f})
11074 When set to @code{#t}, wait for any key before showing the login prompt.
11075 This can be used in conjunction with @var{auto-login} to save memory by
11076 lazily spawning shells.
11077
11078 @item @code{chroot} (default: @code{#f})
11079 Change root to the specified directory. This option accepts a directory
11080 path as a string.
11081
11082 @item @code{hangup?} (default: @code{#f})
11083 Use the Linux system call @code{vhangup} to do a virtual hangup of the
11084 specified terminal.
11085
11086 @item @code{keep-baud?} (default: @code{#f})
11087 When set to @code{#t}, try to keep the existing baud rate. The baud
11088 rates from @var{baud-rate} are used when agetty receives a @key{BREAK}
11089 character.
11090
11091 @item @code{timeout} (default: @code{#f})
11092 When set to an integer value, terminate if no user name could be read
11093 within @var{timeout} seconds.
11094
11095 @item @code{detect-case?} (default: @code{#f})
11096 When set to @code{#t}, turn on support for detecting an uppercase-only
11097 terminal. This setting will detect a login name containing only
11098 uppercase letters as indicating an uppercase-only terminal and turn on
11099 some upper-to-lower case conversions. Note that this will not support
11100 Unicode characters.
11101
11102 @item @code{wait-cr?} (default: @code{#f})
11103 When set to @code{#t}, wait for the user or modem to send a
11104 carriage-return or linefeed character before displaying
11105 @file{/etc/issue} or login prompt. This is typically used with the
11106 @var{init-string} option.
11107
11108 @item @code{no-hints?} (default: @code{#f})
11109 When set to @code{#t}, do not print hints about Num, Caps, and Scroll
11110 locks.
11111
11112 @item @code{no-hostname?} (default: @code{#f})
11113 By default, the hostname is printed. When this option is set to
11114 @code{#t}, no hostname will be shown at all.
11115
11116 @item @code{long-hostname?} (default: @code{#f})
11117 By default, the hostname is only printed until the first dot. When this
11118 option is set to @code{#t}, the fully qualified hostname by
11119 @code{gethostname} or @code{getaddrinfo} is shown.
11120
11121 @item @code{erase-characters} (default: @code{#f})
11122 This option accepts a string of additional characters that should be
11123 interpreted as backspace when the user types their login name.
11124
11125 @item @code{kill-characters} (default: @code{#f})
11126 This option accepts a string that should be interpreted to mean "ignore
11127 all previous characters" (also called a "kill" character) when the types
11128 their login name.
11129
11130 @item @code{chdir} (default: @code{#f})
11131 This option accepts, as a string, a directory path that will be changed
11132 to before login.
11133
11134 @item @code{delay} (default: @code{#f})
11135 This options accepts, as an integer, the number of seconds to sleep
11136 before opening the tty and displaying the login prompt.
11137
11138 @item @code{nice} (default: @code{#f})
11139 This option accepts, as an integer, the nice value with which to run the
11140 @command{login} program.
11141
11142 @item @code{extra-options} (default: @code{'()})
11143 This option provides an "escape hatch" for the user to provide arbitrary
11144 command-line arguments to @command{agetty} as a list of strings.
11145
11146 @end table
11147 @end deftp
11148
11149 @deffn {Scheme Procedure} kmscon-service-type @var{config}
11150 Return a service to run @uref{https://www.freedesktop.org/wiki/Software/kmscon,kmscon}
11151 according to @var{config}, a @code{<kmscon-configuration>} object, which
11152 specifies the tty to run, among other things.
11153 @end deffn
11154
11155 @deftp {Data Type} kmscon-configuration
11156 This is the data type representing the configuration of Kmscon, which
11157 implements virtual console log-in.
11158
11159 @table @asis
11160
11161 @item @code{virtual-terminal}
11162 The name of the console this Kmscon runs on---e.g., @code{"tty1"}.
11163
11164 @item @code{login-program} (default: @code{#~(string-append #$shadow "/bin/login")})
11165 A gexp denoting the name of the log-in program. The default log-in program is
11166 @command{login} from the Shadow tool suite.
11167
11168 @item @code{login-arguments} (default: @code{'("-p")})
11169 A list of arguments to pass to @command{login}.
11170
11171 @item @code{auto-login} (default: @code{#f})
11172 When passed a login name, as a string, the specified user will be logged
11173 in automatically without prompting for their login name or password.
11174
11175 @item @code{hardware-acceleration?} (default: #f)
11176 Whether to use hardware acceleration.
11177
11178 @item @code{kmscon} (default: @var{kmscon})
11179 The Kmscon package to use.
11180
11181 @end table
11182 @end deftp
11183
11184 @cindex name service cache daemon
11185 @cindex nscd
11186 @deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
11187 [#:name-services '()]
11188 Return a service that runs the libc name service cache daemon (nscd) with the
11189 given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
11190 Service Switch}, for an example.
11191
11192 For convenience, the Shepherd service for nscd provides the following actions:
11193
11194 @table @code
11195 @item invalidate
11196 @cindex cache invalidation, nscd
11197 @cindex nscd, cache invalidation
11198 This invalidate the given cache. For instance, running:
11199
11200 @example
11201 herd invalidate nscd hosts
11202 @end example
11203
11204 @noindent
11205 invalidates the host name lookup cache of nscd.
11206
11207 @item statistics
11208 Running @command{herd statistics nscd} displays information about nscd usage
11209 and caches.
11210 @end table
11211
11212 @end deffn
11213
11214 @defvr {Scheme Variable} %nscd-default-configuration
11215 This is the default @code{<nscd-configuration>} value (see below) used
11216 by @code{nscd-service}. It uses the caches defined by
11217 @var{%nscd-default-caches}; see below.
11218 @end defvr
11219
11220 @deftp {Data Type} nscd-configuration
11221 This is the data type representing the name service cache daemon (nscd)
11222 configuration.
11223
11224 @table @asis
11225
11226 @item @code{name-services} (default: @code{'()})
11227 List of packages denoting @dfn{name services} that must be visible to
11228 the nscd---e.g., @code{(list @var{nss-mdns})}.
11229
11230 @item @code{glibc} (default: @var{glibc})
11231 Package object denoting the GNU C Library providing the @command{nscd}
11232 command.
11233
11234 @item @code{log-file} (default: @code{"/var/log/nscd.log"})
11235 Name of the nscd log file. This is where debugging output goes when
11236 @code{debug-level} is strictly positive.
11237
11238 @item @code{debug-level} (default: @code{0})
11239 Integer denoting the debugging levels. Higher numbers mean that more
11240 debugging output is logged.
11241
11242 @item @code{caches} (default: @var{%nscd-default-caches})
11243 List of @code{<nscd-cache>} objects denoting things to be cached; see
11244 below.
11245
11246 @end table
11247 @end deftp
11248
11249 @deftp {Data Type} nscd-cache
11250 Data type representing a cache database of nscd and its parameters.
11251
11252 @table @asis
11253
11254 @item @code{database}
11255 This is a symbol representing the name of the database to be cached.
11256 Valid values are @code{passwd}, @code{group}, @code{hosts}, and
11257 @code{services}, which designate the corresponding NSS database
11258 (@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
11259
11260 @item @code{positive-time-to-live}
11261 @itemx @code{negative-time-to-live} (default: @code{20})
11262 A number representing the number of seconds during which a positive or
11263 negative lookup result remains in cache.
11264
11265 @item @code{check-files?} (default: @code{#t})
11266 Whether to check for updates of the files corresponding to
11267 @var{database}.
11268
11269 For instance, when @var{database} is @code{hosts}, setting this flag
11270 instructs nscd to check for updates in @file{/etc/hosts} and to take
11271 them into account.
11272
11273 @item @code{persistent?} (default: @code{#t})
11274 Whether the cache should be stored persistently on disk.
11275
11276 @item @code{shared?} (default: @code{#t})
11277 Whether the cache should be shared among users.
11278
11279 @item @code{max-database-size} (default: 32@tie{}MiB)
11280 Maximum size in bytes of the database cache.
11281
11282 @c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
11283 @c settings, so leave them out.
11284
11285 @end table
11286 @end deftp
11287
11288 @defvr {Scheme Variable} %nscd-default-caches
11289 List of @code{<nscd-cache>} objects used by default by
11290 @code{nscd-configuration} (see above).
11291
11292 It enables persistent and aggressive caching of service and host name
11293 lookups. The latter provides better host name lookup performance,
11294 resilience in the face of unreliable name servers, and also better
11295 privacy---often the result of host name lookups is in local cache, so
11296 external name servers do not even need to be queried.
11297 @end defvr
11298
11299 @anchor{syslog-configuration-type}
11300 @cindex syslog
11301 @cindex logging
11302 @deftp {Data Type} syslog-configuration
11303 This data type represents the configuration of the syslog daemon.
11304
11305 @table @asis
11306 @item @code{syslogd} (default: @code{#~(string-append #$inetutils "/libexec/syslogd")})
11307 The syslog daemon to use.
11308
11309 @item @code{config-file} (default: @code{%default-syslog.conf})
11310 The syslog configuration file to use.
11311
11312 @end table
11313 @end deftp
11314
11315 @anchor{syslog-service}
11316 @cindex syslog
11317 @deffn {Scheme Procedure} syslog-service @var{config}
11318 Return a service that runs a syslog daemon according to @var{config}.
11319
11320 @xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
11321 information on the configuration file syntax.
11322 @end deffn
11323
11324 @defvr {Scheme Variable} guix-service-type
11325 This is the type of the service that runs the build daemon,
11326 @command{guix-daemon} (@pxref{Invoking guix-daemon}). Its value must be a
11327 @code{guix-configuration} record as described below.
11328 @end defvr
11329
11330 @anchor{guix-configuration-type}
11331 @deftp {Data Type} guix-configuration
11332 This data type represents the configuration of the Guix build daemon.
11333 @xref{Invoking guix-daemon}, for more information.
11334
11335 @table @asis
11336 @item @code{guix} (default: @var{guix})
11337 The Guix package to use.
11338
11339 @item @code{build-group} (default: @code{"guixbuild"})
11340 Name of the group for build user accounts.
11341
11342 @item @code{build-accounts} (default: @code{10})
11343 Number of build user accounts to create.
11344
11345 @item @code{authorize-key?} (default: @code{#t})
11346 @cindex substitutes, authorization thereof
11347 Whether to authorize the substitute keys listed in
11348 @code{authorized-keys}---by default that of @code{@value{SUBSTITUTE-SERVER}}
11349 (@pxref{Substitutes}).
11350
11351 @vindex %default-authorized-guix-keys
11352 @item @code{authorized-keys} (default: @var{%default-authorized-guix-keys})
11353 The list of authorized key files for archive imports, as a list of
11354 string-valued gexps (@pxref{Invoking guix archive}). By default, it
11355 contains that of @code{@value{SUBSTITUTE-SERVER}} (@pxref{Substitutes}).
11356
11357 @item @code{use-substitutes?} (default: @code{#t})
11358 Whether to use substitutes.
11359
11360 @item @code{substitute-urls} (default: @var{%default-substitute-urls})
11361 The list of URLs where to look for substitutes by default.
11362
11363 @item @code{max-silent-time} (default: @code{0})
11364 @itemx @code{timeout} (default: @code{0})
11365 The number of seconds of silence and the number of seconds of activity,
11366 respectively, after which a build process times out. A value of zero
11367 disables the timeout.
11368
11369 @item @code{log-compression} (default: @code{'bzip2})
11370 The type of compression used for build logs---one of @code{gzip},
11371 @code{bzip2}, or @code{none}.
11372
11373 @item @code{extra-options} (default: @code{'()})
11374 List of extra command-line options for @command{guix-daemon}.
11375
11376 @item @code{log-file} (default: @code{"/var/log/guix-daemon.log"})
11377 File where @command{guix-daemon}'s standard output and standard error
11378 are written.
11379
11380 @item @code{http-proxy} (default: @code{#f})
11381 The HTTP proxy used for downloading fixed-output derivations and
11382 substitutes.
11383
11384 @item @code{tmpdir} (default: @code{#f})
11385 A directory path where the @command{guix-daemon} will perform builds.
11386
11387 @end table
11388 @end deftp
11389
11390 @deffn {Scheme Procedure} udev-service [#:udev @var{eudev} #:rules @code{'()}]
11391 Run @var{udev}, which populates the @file{/dev} directory dynamically.
11392 udev rules can be provided as a list of files through the @var{rules}
11393 variable. The procedures @var{udev-rule} and @var{file->udev-rule} from
11394 @code{(gnu services base)} simplify the creation of such rule files.
11395 @end deffn
11396
11397 @deffn {Scheme Procedure} udev-rule [@var{file-name} @var{contents}]
11398 Return a udev-rule file named @var{file-name} containing the rules
11399 defined by the @var{contents} literal.
11400
11401 In the following example, a rule for a USB device is defined to be
11402 stored in the file @file{90-usb-thing.rules}. The rule runs a script
11403 upon detecting a USB device with a given product identifier.
11404
11405 @example
11406 (define %example-udev-rule
11407 (udev-rule
11408 "90-usb-thing.rules"
11409 (string-append "ACTION==\"add\", SUBSYSTEM==\"usb\", "
11410 "ATTR@{product@}==\"Example\", "
11411 "RUN+=\"/path/to/script\"")))
11412 @end example
11413
11414 The @command{herd rules udev} command, as root, returns the name of the
11415 directory containing all the active udev rules.
11416 @end deffn
11417
11418 Here we show how the default @var{udev-service} can be extended with it.
11419
11420 @example
11421 (operating-system
11422 ;; @dots{}
11423 (services
11424 (modify-services %desktop-services
11425 (udev-service-type config =>
11426 (udev-configuration (inherit config)
11427 (rules (append (udev-configuration-rules config)
11428 (list %example-udev-rule))))))))
11429 @end example
11430
11431 @deffn {Scheme Procedure} file->udev-rule [@var{file-name} @var{file}]
11432 Return a udev file named @var{file-name} containing the rules defined
11433 within @var{file}, a file-like object.
11434
11435 The following example showcases how we can use an existing rule file.
11436
11437 @example
11438 (use-modules (guix download) ;for url-fetch
11439 (guix packages) ;for origin
11440 ;; @dots{})
11441
11442 (define %android-udev-rules
11443 (file->udev-rule
11444 "51-android-udev.rules"
11445 (let ((version "20170910"))
11446 (origin
11447 (method url-fetch)
11448 (uri (string-append "https://raw.githubusercontent.com/M0Rf30/"
11449 "android-udev-rules/" version "/51-android.rules"))
11450 (sha256
11451 (base32 "0lmmagpyb6xsq6zcr2w1cyx9qmjqmajkvrdbhjx32gqf1d9is003"))))))
11452 @end example
11453 @end deffn
11454
11455 Additionally, Guix package definitions can be included in @var{rules} in
11456 order to extend the udev rules with the definitions found under their
11457 @file{lib/udev/rules.d} sub-directory. In lieu of the previous
11458 @var{file->udev-rule} example, we could have used the
11459 @var{android-udev-rules} package which exists in Guix in the @code{(gnu
11460 packages android)} module.
11461
11462 The following example shows how to use the @var{android-udev-rules}
11463 package so that the Android tool @command{adb} can detect devices
11464 without root privileges. It also details how to create the
11465 @code{adbusers} group, which is required for the proper functioning of
11466 the rules defined within the @var{android-udev-rules} package. To
11467 create such a group, we must define it both as part of the
11468 @var{supplementary-groups} of our @var{user-account} declaration, as
11469 well as in the @var{groups} field of the @var{operating-system} record.
11470
11471 @example
11472 (use-modules (gnu packages android) ;for android-udev-rules
11473 (gnu system shadow) ;for user-group
11474 ;; @dots{})
11475
11476 (operating-system
11477 ;; @dots{}
11478 (users (cons (user-acount
11479 ;; @dots{}
11480 (supplementary-groups
11481 '("adbusers" ;for adb
11482 "wheel" "netdev" "audio" "video"))
11483 ;; @dots{})))
11484
11485 (groups (cons (user-group (system? #t) (name "adbusers"))
11486 %base-groups))
11487
11488 ;; @dots{}
11489
11490 (services
11491 (modify-services %desktop-services
11492 (udev-service-type config =>
11493 (udev-configuration (inherit config)
11494 (rules (cons* android-udev-rules
11495 (udev-configuration-rules config))))))))
11496 @end example
11497
11498 @defvr {Scheme Variable} urandom-seed-service-type
11499 Save some entropy in @var{%random-seed-file} to seed @file{/dev/urandom}
11500 when rebooting. It also tries to seed @file{/dev/urandom} from
11501 @file{/dev/hwrng} while booting, if @file{/dev/hwrng} exists and is
11502 readable.
11503 @end defvr
11504
11505 @defvr {Scheme Variable} %random-seed-file
11506 This is the name of the file where some random bytes are saved by
11507 @var{urandom-seed-service} to seed @file{/dev/urandom} when rebooting.
11508 It defaults to @file{/var/lib/random-seed}.
11509 @end defvr
11510
11511 @cindex keymap
11512 @cindex keyboard
11513 @deffn {Scheme Procedure} console-keymap-service @var{files} ...
11514 @cindex keyboard layout
11515 Return a service to load console keymaps from @var{files} using
11516 @command{loadkeys} command. Most likely, you want to load some default
11517 keymap, which can be done like this:
11518
11519 @example
11520 (console-keymap-service "dvorak")
11521 @end example
11522
11523 Or, for example, for a Swedish keyboard, you may need to combine
11524 the following keymaps:
11525 @example
11526 (console-keymap-service "se-lat6" "se-fi-lat6")
11527 @end example
11528
11529 Also you can specify a full file name (or file names) of your keymap(s).
11530 See @code{man loadkeys} for details.
11531
11532 @end deffn
11533
11534 @cindex mouse
11535 @cindex gpm
11536 @defvr {Scheme Variable} gpm-service-type
11537 This is the type of the service that runs GPM, the @dfn{general-purpose
11538 mouse daemon}, which provides mouse support to the Linux console. GPM
11539 allows users to use the mouse in the console, notably to select, copy,
11540 and paste text.
11541
11542 The value for services of this type must be a @code{gpm-configuration}
11543 (see below). This service is not part of @var{%base-services}.
11544 @end defvr
11545
11546 @deftp {Data Type} gpm-configuration
11547 Data type representing the configuration of GPM.
11548
11549 @table @asis
11550 @item @code{options} (default: @code{%default-gpm-options})
11551 Command-line options passed to @command{gpm}. The default set of
11552 options instruct @command{gpm} to listen to mouse events on
11553 @file{/dev/input/mice}. @xref{Command Line,,, gpm, gpm manual}, for
11554 more information.
11555
11556 @item @code{gpm} (default: @code{gpm})
11557 The GPM package to use.
11558
11559 @end table
11560 @end deftp
11561
11562 @anchor{guix-publish-service-type}
11563 @deffn {Scheme Variable} guix-publish-service-type
11564 This is the service type for @command{guix publish} (@pxref{Invoking
11565 guix publish}). Its value must be a @code{guix-configuration}
11566 object, as described below.
11567
11568 This assumes that @file{/etc/guix} already contains a signing key pair as
11569 created by @command{guix archive --generate-key} (@pxref{Invoking guix
11570 archive}). If that is not the case, the service will fail to start.
11571 @end deffn
11572
11573 @deftp {Data Type} guix-publish-configuration
11574 Data type representing the configuration of the @code{guix publish}
11575 service.
11576
11577 @table @asis
11578 @item @code{guix} (default: @code{guix})
11579 The Guix package to use.
11580
11581 @item @code{port} (default: @code{80})
11582 The TCP port to listen for connections.
11583
11584 @item @code{host} (default: @code{"localhost"})
11585 The host (and thus, network interface) to listen to. Use
11586 @code{"0.0.0.0"} to listen on all the network interfaces.
11587
11588 @item @code{compression-level} (default: @code{3})
11589 The gzip compression level at which substitutes are compressed. Use
11590 @code{0} to disable compression altogether, and @code{9} to get the best
11591 compression ratio at the expense of increased CPU usage.
11592
11593 @item @code{nar-path} (default: @code{"nar"})
11594 The URL path at which ``nars'' can be fetched. @xref{Invoking guix
11595 publish, @code{--nar-path}}, for details.
11596
11597 @item @code{cache} (default: @code{#f})
11598 When it is @code{#f}, disable caching and instead generate archives on
11599 demand. Otherwise, this should be the name of a directory---e.g.,
11600 @code{"/var/cache/guix/publish"}---where @command{guix publish} caches
11601 archives and meta-data ready to be sent. @xref{Invoking guix publish,
11602 @option{--cache}}, for more information on the tradeoffs involved.
11603
11604 @item @code{workers} (default: @code{#f})
11605 When it is an integer, this is the number of worker threads used for
11606 caching; when @code{#f}, the number of processors is used.
11607 @xref{Invoking guix publish, @option{--workers}}, for more information.
11608
11609 @item @code{ttl} (default: @code{#f})
11610 When it is an integer, this denotes the @dfn{time-to-live} in seconds
11611 of the published archives. @xref{Invoking guix publish, @option{--ttl}},
11612 for more information.
11613 @end table
11614 @end deftp
11615
11616 @anchor{rngd-service}
11617 @deffn {Scheme Procedure} rngd-service [#:rng-tools @var{rng-tools}] @
11618 [#:device "/dev/hwrng"]
11619 Return a service that runs the @command{rngd} program from @var{rng-tools}
11620 to add @var{device} to the kernel's entropy pool. The service will fail if
11621 @var{device} does not exist.
11622 @end deffn
11623
11624 @anchor{pam-limits-service}
11625 @cindex session limits
11626 @cindex ulimit
11627 @cindex priority
11628 @cindex realtime
11629 @cindex jackd
11630 @deffn {Scheme Procedure} pam-limits-service [#:limits @code{'()}]
11631
11632 Return a service that installs a configuration file for the
11633 @uref{http://linux-pam.org/Linux-PAM-html/sag-pam_limits.html,
11634 @code{pam_limits} module}. The procedure optionally takes a list of
11635 @code{pam-limits-entry} values, which can be used to specify
11636 @code{ulimit} limits and nice priority limits to user sessions.
11637
11638 The following limits definition sets two hard and soft limits for all
11639 login sessions of users in the @code{realtime} group:
11640
11641 @example
11642 (pam-limits-service
11643 (list
11644 (pam-limits-entry "@@realtime" 'both 'rtprio 99)
11645 (pam-limits-entry "@@realtime" 'both 'memlock 'unlimited)))
11646 @end example
11647
11648 The first entry increases the maximum realtime priority for
11649 non-privileged processes; the second entry lifts any restriction of the
11650 maximum address space that can be locked in memory. These settings are
11651 commonly used for real-time audio systems.
11652 @end deffn
11653
11654 @node Scheduled Job Execution
11655 @subsubsection Scheduled Job Execution
11656
11657 @cindex cron
11658 @cindex mcron
11659 @cindex scheduling jobs
11660 The @code{(gnu services mcron)} module provides an interface to
11661 GNU@tie{}mcron, a daemon to run jobs at scheduled times (@pxref{Top,,,
11662 mcron, GNU@tie{}mcron}). GNU@tie{}mcron is similar to the traditional
11663 Unix @command{cron} daemon; the main difference is that it is
11664 implemented in Guile Scheme, which provides a lot of flexibility when
11665 specifying the scheduling of jobs and their actions.
11666
11667 The example below defines an operating system that runs the
11668 @command{updatedb} (@pxref{Invoking updatedb,,, find, Finding Files})
11669 and the @command{guix gc} commands (@pxref{Invoking guix gc}) daily, as
11670 well as the @command{mkid} command on behalf of an unprivileged user
11671 (@pxref{mkid invocation,,, idutils, ID Database Utilities}). It uses
11672 gexps to introduce job definitions that are passed to mcron
11673 (@pxref{G-Expressions}).
11674
11675 @lisp
11676 (use-modules (guix) (gnu) (gnu services mcron))
11677 (use-package-modules base idutils)
11678
11679 (define updatedb-job
11680 ;; Run 'updatedb' at 3AM every day. Here we write the
11681 ;; job's action as a Scheme procedure.
11682 #~(job '(next-hour '(3))
11683 (lambda ()
11684 (execl (string-append #$findutils "/bin/updatedb")
11685 "updatedb"
11686 "--prunepaths=/tmp /var/tmp /gnu/store"))))
11687
11688 (define garbage-collector-job
11689 ;; Collect garbage 5 minutes after midnight every day.
11690 ;; The job's action is a shell command.
11691 #~(job "5 0 * * *" ;Vixie cron syntax
11692 "guix gc -F 1G"))
11693
11694 (define idutils-job
11695 ;; Update the index database as user "charlie" at 12:15PM
11696 ;; and 19:15PM. This runs from the user's home directory.
11697 #~(job '(next-minute-from (next-hour '(12 19)) '(15))
11698 (string-append #$idutils "/bin/mkid src")
11699 #:user "charlie"))
11700
11701 (operating-system
11702 ;; @dots{}
11703 (services (cons (service mcron-service-type
11704 (mcron-configuration
11705 (jobs (list garbage-collector-job
11706 updatedb-job
11707 idutils-job))))
11708 %base-services)))
11709 @end lisp
11710
11711 @xref{Guile Syntax, mcron job specifications,, mcron, GNU@tie{}mcron},
11712 for more information on mcron job specifications. Below is the
11713 reference of the mcron service.
11714
11715 On a running system, you can use the @code{schedule} action of the service to
11716 visualize the mcron jobs that will be executed next:
11717
11718 @example
11719 # herd schedule mcron
11720 @end example
11721
11722 @noindent
11723 The example above lists the next five tasks that will be executed, but you can
11724 also specify the number of tasks to display:
11725
11726 @example
11727 # herd schedule mcron 10
11728 @end example
11729
11730 @defvr {Scheme Variable} mcron-service-type
11731 This is the type of the @code{mcron} service, whose value is an
11732 @code{mcron-configuration} object.
11733
11734 This service type can be the target of a service extension that provides
11735 it additional job specifications (@pxref{Service Composition}). In
11736 other words, it is possible to define services that provide additional
11737 mcron jobs to run.
11738 @end defvr
11739
11740 @deftp {Data Type} mcron-configuration
11741 Data type representing the configuration of mcron.
11742
11743 @table @asis
11744 @item @code{mcron} (default: @var{mcron})
11745 The mcron package to use.
11746
11747 @item @code{jobs}
11748 This is a list of gexps (@pxref{G-Expressions}), where each gexp
11749 corresponds to an mcron job specification (@pxref{Syntax, mcron job
11750 specifications,, mcron, GNU@tie{}mcron}).
11751 @end table
11752 @end deftp
11753
11754
11755 @node Log Rotation
11756 @subsubsection Log Rotation
11757
11758 @cindex rottlog
11759 @cindex log rotation
11760 @cindex logging
11761 Log files such as those found in @file{/var/log} tend to grow endlessly,
11762 so it's a good idea to @dfn{rotate} them once in a while---i.e., archive
11763 their contents in separate files, possibly compressed. The @code{(gnu
11764 services admin)} module provides an interface to GNU@tie{}Rot[t]log, a
11765 log rotation tool (@pxref{Top,,, rottlog, GNU Rot[t]log Manual}).
11766
11767 The example below defines an operating system that provides log rotation
11768 with the default settings, for commonly encountered log files.
11769
11770 @lisp
11771 (use-modules (guix) (gnu))
11772 (use-service-modules admin mcron)
11773 (use-package-modules base idutils)
11774
11775 (operating-system
11776 ;; @dots{}
11777 (services (cons (service rottlog-service-type)
11778 %base-services)))
11779 @end lisp
11780
11781 @defvr {Scheme Variable} rottlog-service-type
11782 This is the type of the Rottlog service, whose value is a
11783 @code{rottlog-configuration} object.
11784
11785 Other services can extend this one with new @code{log-rotation} objects
11786 (see below), thereby augmenting the set of files to be rotated.
11787
11788 This service type can define mcron jobs (@pxref{Scheduled Job
11789 Execution}) to run the rottlog service.
11790 @end defvr
11791
11792 @deftp {Data Type} rottlog-configuration
11793 Data type representing the configuration of rottlog.
11794
11795 @table @asis
11796 @item @code{rottlog} (default: @code{rottlog})
11797 The Rottlog package to use.
11798
11799 @item @code{rc-file} (default: @code{(file-append rottlog "/etc/rc")})
11800 The Rottlog configuration file to use (@pxref{Mandatory RC Variables,,,
11801 rottlog, GNU Rot[t]log Manual}).
11802
11803 @item @code{rotations} (default: @code{%default-rotations})
11804 A list of @code{log-rotation} objects as defined below.
11805
11806 @item @code{jobs}
11807 This is a list of gexps where each gexp corresponds to an mcron job
11808 specification (@pxref{Scheduled Job Execution}).
11809 @end table
11810 @end deftp
11811
11812 @deftp {Data Type} log-rotation
11813 Data type representing the rotation of a group of log files.
11814
11815 Taking an example from the Rottlog manual (@pxref{Period Related File
11816 Examples,,, rottlog, GNU Rot[t]log Manual}), a log rotation might be
11817 defined like this:
11818
11819 @example
11820 (log-rotation
11821 (frequency 'daily)
11822 (files '("/var/log/apache/*"))
11823 (options '("storedir apache-archives"
11824 "rotate 6"
11825 "notifempty"
11826 "nocompress")))
11827 @end example
11828
11829 The list of fields is as follows:
11830
11831 @table @asis
11832 @item @code{frequency} (default: @code{'weekly})
11833 The log rotation frequency, a symbol.
11834
11835 @item @code{files}
11836 The list of files or file glob patterns to rotate.
11837
11838 @item @code{options} (default: @code{'()})
11839 The list of rottlog options for this rotation (@pxref{Configuration
11840 parameters,,, rottlog, GNU Rot[t]lg Manual}).
11841
11842 @item @code{post-rotate} (default: @code{#f})
11843 Either @code{#f} or a gexp to execute once the rotation has completed.
11844 @end table
11845 @end deftp
11846
11847 @defvr {Scheme Variable} %default-rotations
11848 Specifies weekly rotation of @var{%rotated-files} and
11849 a couple of other files.
11850 @end defvr
11851
11852 @defvr {Scheme Variable} %rotated-files
11853 The list of syslog-controlled files to be rotated. By default it is:
11854 @code{'("/var/log/messages" "/var/log/secure")}.
11855 @end defvr
11856
11857 @node Networking Services
11858 @subsubsection Networking Services
11859
11860 The @code{(gnu services networking)} module provides services to configure
11861 the network interface.
11862
11863 @cindex DHCP, networking service
11864 @defvr {Scheme Variable} dhcp-client-service-type
11865 This is the type of services that run @var{dhcp}, a Dynamic Host Configuration
11866 Protocol (DHCP) client, on all the non-loopback network interfaces. Its value
11867 is the DHCP client package to use, @code{isc-dhcp} by default.
11868 @end defvr
11869
11870 @deffn {Scheme Procedure} dhcpd-service-type
11871 This type defines a service that runs a DHCP daemon. To create a
11872 service of this type, you must supply a @code{<dhcpd-configuration>}.
11873 For example:
11874
11875 @example
11876 (service dhcpd-service-type
11877 (dhcpd-configuration
11878 (config-file (local-file "my-dhcpd.conf"))
11879 (interfaces '("enp0s25"))))
11880 @end example
11881 @end deffn
11882
11883 @deftp {Data Type} dhcpd-configuration
11884 @table @asis
11885 @item @code{package} (default: @code{isc-dhcp})
11886 The package that provides the DHCP daemon. This package is expected to
11887 provide the daemon at @file{sbin/dhcpd} relative to its output
11888 directory. The default package is the
11889 @uref{http://www.isc.org/products/DHCP, ISC's DHCP server}.
11890 @item @code{config-file} (default: @code{#f})
11891 The configuration file to use. This is required. It will be passed to
11892 @code{dhcpd} via its @code{-cf} option. This may be any ``file-like''
11893 object (@pxref{G-Expressions, file-like objects}). See @code{man
11894 dhcpd.conf} for details on the configuration file syntax.
11895 @item @code{version} (default: @code{"4"})
11896 The DHCP version to use. The ISC DHCP server supports the values ``4'',
11897 ``6'', and ``4o6''. These correspond to the @code{dhcpd} program
11898 options @code{-4}, @code{-6}, and @code{-4o6}. See @code{man dhcpd} for
11899 details.
11900 @item @code{run-directory} (default: @code{"/run/dhcpd"})
11901 The run directory to use. At service activation time, this directory
11902 will be created if it does not exist.
11903 @item @code{pid-file} (default: @code{"/run/dhcpd/dhcpd.pid"})
11904 The PID file to use. This corresponds to the @code{-pf} option of
11905 @code{dhcpd}. See @code{man dhcpd} for details.
11906 @item @code{interfaces} (default: @code{'()})
11907 The names of the network interfaces on which dhcpd should listen for
11908 broadcasts. If this list is not empty, then its elements (which must be
11909 strings) will be appended to the @code{dhcpd} invocation when starting
11910 the daemon. It may not be necessary to explicitly specify any
11911 interfaces here; see @code{man dhcpd} for details.
11912 @end table
11913 @end deftp
11914
11915 @defvr {Scheme Variable} static-networking-service-type
11916 This is the type for statically-configured network interfaces.
11917 @c TODO Document <static-networking> data structures.
11918 @end defvr
11919
11920 @deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
11921 [#:netmask #f] [#:gateway #f] [#:name-servers @code{'()}] @
11922 [#:requirement @code{'(udev)}]
11923 Return a service that starts @var{interface} with address @var{ip}. If
11924 @var{netmask} is true, use it as the network mask. If @var{gateway} is true,
11925 it must be a string specifying the default network gateway. @var{requirement}
11926 can be used to declare a dependency on another service before configuring the
11927 interface.
11928
11929 This procedure can be called several times, one for each network
11930 interface of interest. Behind the scenes what it does is extend
11931 @code{static-networking-service-type} with additional network interfaces
11932 to handle.
11933
11934 For example:
11935
11936 @example
11937 (static-networking-service "eno1" "192.168.1.82"
11938 #:gateway "192.168.1.2"
11939 #:name-servers '("192.168.1.2"))
11940 @end example
11941 @end deffn
11942
11943 @cindex wicd
11944 @cindex wireless
11945 @cindex WiFi
11946 @cindex network management
11947 @deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
11948 Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
11949 management daemon that aims to simplify wired and wireless networking.
11950
11951 This service adds the @var{wicd} package to the global profile, providing
11952 several commands to interact with the daemon and configure networking:
11953 @command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
11954 and @command{wicd-curses} user interfaces.
11955 @end deffn
11956
11957 @cindex ModemManager
11958
11959 @defvr {Scheme Variable} modem-manager-service-type
11960 This is the service type for the
11961 @uref{https://wiki.gnome.org/Projects/ModemManager, ModemManager}
11962 service. The value for this service type is a
11963 @code{modem-manager-configuration} record.
11964
11965 This service is part of @code{%desktop-services} (@pxref{Desktop
11966 Services}).
11967 @end defvr
11968
11969 @deftp {Data Type} modem-manager-configuration
11970 Data type representing the configuration of ModemManager.
11971
11972 @table @asis
11973 @item @code{modem-manager} (default: @code{modem-manager})
11974 The ModemManager package to use.
11975
11976 @end table
11977 @end deftp
11978
11979 @cindex NetworkManager
11980
11981 @defvr {Scheme Variable} network-manager-service-type
11982 This is the service type for the
11983 @uref{https://wiki.gnome.org/Projects/NetworkManager, NetworkManager}
11984 service. The value for this service type is a
11985 @code{network-manager-configuration} record.
11986
11987 This service is part of @code{%desktop-services} (@pxref{Desktop
11988 Services}).
11989 @end defvr
11990
11991 @deftp {Data Type} network-manager-configuration
11992 Data type representing the configuration of NetworkManager.
11993
11994 @table @asis
11995 @item @code{network-manager} (default: @code{network-manager})
11996 The NetworkManager package to use.
11997
11998 @item @code{dns} (default: @code{"default"})
11999 Processing mode for DNS, which affects how NetworkManager uses the
12000 @code{resolv.conf} configuration file.
12001
12002 @table @samp
12003 @item default
12004 NetworkManager will update @code{resolv.conf} to reflect the nameservers
12005 provided by currently active connections.
12006
12007 @item dnsmasq
12008 NetworkManager will run @code{dnsmasq} as a local caching nameserver,
12009 using a "split DNS" configuration if you are connected to a VPN, and
12010 then update @code{resolv.conf} to point to the local nameserver.
12011
12012 @item none
12013 NetworkManager will not modify @code{resolv.conf}.
12014 @end table
12015
12016 @item @code{vpn-plugins} (default: @code{'()})
12017 This is the list of available plugins for virtual private networks
12018 (VPNs). An example of this is the @code{network-manager-openvpn}
12019 package, which allows NetworkManager to manage VPNs @i{via} OpenVPN.
12020
12021 @end table
12022 @end deftp
12023
12024 @cindex Connman
12025 @deffn {Scheme Variable} connman-service-type
12026 This is the service type to run @url{https://01.org/connman,Connman},
12027 a network connection manager.
12028
12029 Its value must be an
12030 @code{connman-configuration} record as in this example:
12031
12032 @example
12033 (service connman-service-type
12034 (connman-configuration
12035 (disable-vpn? #t)))
12036 @end example
12037
12038 See below for details about @code{connman-configuration}.
12039 @end deffn
12040
12041 @deftp {Data Type} connman-configuration
12042 Data Type representing the configuration of connman.
12043
12044 @table @asis
12045 @item @code{connman} (default: @var{connman})
12046 The connman package to use.
12047
12048 @item @code{disable-vpn?} (default: @code{#f})
12049 When true, disable connman's vpn plugin.
12050 @end table
12051 @end deftp
12052
12053 @cindex WPA Supplicant
12054 @defvr {Scheme Variable} wpa-supplicant-service-type
12055 This is the service type to run @url{https://w1.fi/wpa_supplicant/,WPA
12056 supplicant}, an authentication daemon required to authenticate against
12057 encrypted WiFi or ethernet networks.
12058 @end defvr
12059
12060 @deftp {Data Type} wpa-supplicant-configuration
12061 Data type representing the configuration of WPA Supplicant.
12062
12063 It takes the following parameters:
12064
12065 @table @asis
12066 @item @code{wpa-supplicant} (default: @code{wpa-supplicant})
12067 The WPA Supplicant package to use.
12068
12069 @item @code{dbus?} (default: @code{#t})
12070 Whether to listen for requests on D-Bus.
12071
12072 @item @code{pid-file} (default: @code{"/var/run/wpa_supplicant.pid"})
12073 Where to store the PID file.
12074
12075 @item @code{interface} (default: @code{#f})
12076 If this is set, it must specify the name of a network interface that
12077 WPA supplicant will control.
12078
12079 @item @code{config-file} (default: @code{#f})
12080 Optional configuration file to use.
12081
12082 @item @code{extra-options} (default: @code{'()})
12083 List of additional command-line arguments to pass to the daemon.
12084 @end table
12085 @end deftp
12086
12087 @cindex iptables
12088 @defvr {Scheme Variable} iptables-service-type
12089 This is the service type to set up an iptables configuration. iptables is a
12090 packet filtering framework supported by the Linux kernel. This service
12091 supports configuring iptables for both IPv4 and IPv6. A simple example
12092 configuration rejecting all incoming connections except those to the ssh port
12093 22 is shown below.
12094
12095 @lisp
12096 (service iptables-service-type
12097 (iptables-configuration
12098 (ipv4-rules (plain-file "iptables.rules" "*filter
12099 :INPUT ACCEPT
12100 :FORWARD ACCEPT
12101 :OUTPUT ACCEPT
12102 -A INPUT -p tcp --dport 22 -j ACCEPT
12103 -A INPUT -j REJECT --reject-with icmp-port-unreachable
12104 COMMIT
12105 "))
12106 (ipv6-rules (plain-file "ip6tables.rules" "*filter
12107 :INPUT ACCEPT
12108 :FORWARD ACCEPT
12109 :OUTPUT ACCEPT
12110 -A INPUT -p tcp --dport 22 -j ACCEPT
12111 -A INPUT -j REJECT --reject-with icmp6-port-unreachable
12112 COMMIT
12113 "))))
12114 @end lisp
12115 @end defvr
12116
12117 @deftp {Data Type} iptables-configuration
12118 The data type representing the configuration of iptables.
12119
12120 @table @asis
12121 @item @code{iptables} (default: @code{iptables})
12122 The iptables package that provides @code{iptables-restore} and
12123 @code{ip6tables-restore}.
12124 @item @code{ipv4-rules} (default: @code{%iptables-accept-all-rules})
12125 The iptables rules to use. It will be passed to @code{iptables-restore}.
12126 This may be any ``file-like'' object (@pxref{G-Expressions, file-like
12127 objects}).
12128 @item @code{ipv6-rules} (default: @code{%iptables-accept-all-rules})
12129 The ip6tables rules to use. It will be passed to @code{ip6tables-restore}.
12130 This may be any ``file-like'' object (@pxref{G-Expressions, file-like
12131 objects}).
12132 @end table
12133 @end deftp
12134
12135 @cindex NTP (Network Time Protocol), service
12136 @cindex real time clock
12137 @defvr {Scheme Variable} ntp-service-type
12138 This is the type of the service running the @uref{http://www.ntp.org,
12139 Network Time Protocol (NTP)} daemon, @command{ntpd}. The daemon will keep the
12140 system clock synchronized with that of the specified NTP servers.
12141
12142 The value of this service is an @code{ntpd-configuration} object, as described
12143 below.
12144 @end defvr
12145
12146 @deftp {Data Type} ntp-configuration
12147 This is the data type for the NTP service configuration.
12148
12149 @table @asis
12150 @item @code{servers} (default: @code{%ntp-servers})
12151 This is the list of servers (host names) with which @command{ntpd} will be
12152 synchronized.
12153
12154 @item @code{allow-large-adjustment?} (default: @code{#f})
12155 This determines whether @command{ntpd} is allowed to make an initial
12156 adjustment of more than 1,000 seconds.
12157
12158 @item @code{ntp} (default: @code{ntp})
12159 The NTP package to use.
12160 @end table
12161 @end deftp
12162
12163 @defvr {Scheme Variable} %ntp-servers
12164 List of host names used as the default NTP servers. These are servers of the
12165 @uref{https://www.ntppool.org/en/, NTP Pool Project}.
12166 @end defvr
12167
12168 @cindex OpenNTPD
12169 @deffn {Scheme Procedure} openntpd-service-type
12170 Run the @command{ntpd}, the Network Time Protocol (NTP) daemon, as implemented
12171 by @uref{http://www.openntpd.org, OpenNTPD}. The daemon will keep the system
12172 clock synchronized with that of the given servers.
12173
12174 @example
12175 (service
12176 openntpd-service-type
12177 (openntpd-configuration
12178 (listen-on '("127.0.0.1" "::1"))
12179 (sensor '("udcf0 correction 70000"))
12180 (constraint-from '("www.gnu.org"))
12181 (constraints-from '("https://www.google.com/"))
12182 (allow-large-adjustment? #t)))
12183
12184 @end example
12185 @end deffn
12186
12187 @deftp {Data Type} openntpd-configuration
12188 @table @asis
12189 @item @code{openntpd} (default: @code{(file-append openntpd "/sbin/ntpd")})
12190 The openntpd executable to use.
12191 @item @code{listen-on} (default: @code{'("127.0.0.1" "::1")})
12192 A list of local IP addresses or hostnames the ntpd daemon should listen on.
12193 @item @code{query-from} (default: @code{'()})
12194 A list of local IP address the ntpd daemon should use for outgoing queries.
12195 @item @code{sensor} (default: @code{'()})
12196 Specify a list of timedelta sensor devices ntpd should use. @code{ntpd}
12197 will listen to each sensor that acutally exists and ignore non-existant ones.
12198 See @uref{https://man.openbsd.org/ntpd.conf, upstream documentation} for more
12199 information.
12200 @item @code{server} (default: @var{%ntp-servers})
12201 Specify a list of IP addresses or hostnames of NTP servers to synchronize to.
12202 @item @code{servers} (default: @code{'()})
12203 Specify a list of IP addresses or hostnames of NTP pools to synchronize to.
12204 @item @code{constraint-from} (default: @code{'()})
12205 @code{ntpd} can be configured to query the ‘Date’ from trusted HTTPS servers via TLS.
12206 This time information is not used for precision but acts as an authenticated
12207 constraint, thereby reducing the impact of unauthenticated NTP
12208 man-in-the-middle attacks.
12209 Specify a list of URLs, IP addresses or hostnames of HTTPS servers to provide
12210 a constraint.
12211 @item @code{constraints-from} (default: @code{'()})
12212 As with constraint from, specify a list of URLs, IP addresses or hostnames of
12213 HTTPS servers to provide a constraint. Should the hostname resolve to multiple
12214 IP addresses, @code{ntpd} will calculate a median constraint from all of them.
12215 @item @code{allow-large-adjustment?} (default: @code{#f})
12216 Determines if @code{ntpd} is allowed to make an initial adjustment of more
12217 than 180 seconds.
12218 @end table
12219 @end deftp
12220
12221 @cindex inetd
12222 @deffn {Scheme variable} inetd-service-type
12223 This service runs the @command{inetd} (@pxref{inetd invocation,,,
12224 inetutils, GNU Inetutils}) daemon. @command{inetd} listens for
12225 connections on internet sockets, and lazily starts the specified server
12226 program when a connection is made on one of these sockets.
12227
12228 The value of this service is an @code{inetd-configuration} object. The
12229 following example configures the @command{inetd} daemon to provide the
12230 built-in @command{echo} service, as well as an smtp service which
12231 forwards smtp traffic over ssh to a server @code{smtp-server} behind a
12232 gateway @code{hostname}:
12233
12234 @example
12235 (service
12236 inetd-service-type
12237 (inetd-configuration
12238 (entries (list
12239 (inetd-entry
12240 (name "echo")
12241 (socket-type 'stream)
12242 (protocol "tcp")
12243 (wait? #f)
12244 (user "root"))
12245 (inetd-entry
12246 (node "127.0.0.1")
12247 (name "smtp")
12248 (socket-type 'stream)
12249 (protocol "tcp")
12250 (wait? #f)
12251 (user "root")
12252 (program (file-append openssh "/bin/ssh"))
12253 (arguments
12254 '("ssh" "-qT" "-i" "/path/to/ssh_key"
12255 "-W" "smtp-server:25" "user@@hostname")))))
12256 @end example
12257
12258 See below for more details about @code{inetd-configuration}.
12259 @end deffn
12260
12261 @deftp {Data Type} inetd-configuration
12262 Data type representing the configuration of @command{inetd}.
12263
12264 @table @asis
12265 @item @code{program} (default: @code{(file-append inetutils "/libexec/inetd")})
12266 The @command{inetd} executable to use.
12267
12268 @item @code{entries} (default: @code{'()})
12269 A list of @command{inetd} service entries. Each entry should be created
12270 by the @code{inetd-entry} constructor.
12271 @end table
12272 @end deftp
12273
12274 @deftp {Data Type} inetd-entry
12275 Data type representing an entry in the @command{inetd} configuration.
12276 Each entry corresponds to a socket where @command{inetd} will listen for
12277 requests.
12278
12279 @table @asis
12280 @item @code{node} (default: @code{#f})
12281 Optional string, a comma-separated list of local addresses
12282 @command{inetd} should use when listening for this service.
12283 @xref{Configuration file,,, inetutils, GNU Inetutils} for a complete
12284 description of all options.
12285 @item @code{name}
12286 A string, the name must correspond to an entry in @code{/etc/services}.
12287 @item @code{socket-type}
12288 One of @code{'stream}, @code{'dgram}, @code{'raw}, @code{'rdm} or
12289 @code{'seqpacket}.
12290 @item @code{protocol}
12291 A string, must correspond to an entry in @code{/etc/protocols}.
12292 @item @code{wait?} (default: @code{#t})
12293 Whether @command{inetd} should wait for the server to exit before
12294 listening to new service requests.
12295 @item @code{user}
12296 A string containing the user (and, optionally, group) name of the user
12297 as whom the server should run. The group name can be specified in a
12298 suffix, separated by a colon or period, i.e.@: @code{"user"},
12299 @code{"user:group"} or @code{"user.group"}.
12300 @item @code{program} (default: @code{"internal"})
12301 The server program which will serve the requests, or @code{"internal"}
12302 if @command{inetd} should use a built-in service.
12303 @item @code{arguments} (default: @code{'()})
12304 A list strings or file-like objects, which are the server program's
12305 arguments, starting with the zeroth argument, i.e.@: the name of the
12306 program itself. For @command{inetd}'s internal services, this entry
12307 must be @code{'()} or @code{'("internal")}.
12308 @end table
12309
12310 @xref{Configuration file,,, inetutils, GNU Inetutils} for a more
12311 detailed discussion of each configuration field.
12312 @end deftp
12313
12314 @cindex Tor
12315 @defvr {Scheme Variable} tor-service-type
12316 This is the type for a service that runs the @uref{https://torproject.org,
12317 Tor} anonymous networking daemon. The service is configured using a
12318 @code{<tor-configuration>} record. By default, the Tor daemon runs as the
12319 @code{tor} unprivileged user, which is a member of the @code{tor} group.
12320
12321 @end defvr
12322
12323 @deftp {Data Type} tor-configuration
12324 @table @asis
12325 @item @code{tor} (default: @code{tor})
12326 The package that provides the Tor daemon. This package is expected to provide
12327 the daemon at @file{bin/tor} relative to its output directory. The default
12328 package is the @uref{https://www.torproject.org, Tor Project's}
12329 implementation.
12330
12331 @item @code{config-file} (default: @code{(plain-file "empty" "")})
12332 The configuration file to use. It will be appended to a default configuration
12333 file, and the final configuration file will be passed to @code{tor} via its
12334 @code{-f} option. This may be any ``file-like'' object (@pxref{G-Expressions,
12335 file-like objects}). See @code{man tor} for details on the configuration file
12336 syntax.
12337
12338 @item @code{hidden-services} (default: @code{'()})
12339 The list of @code{<hidden-service>} records to use. For any hidden service
12340 you include in this list, appropriate configuration to enable the hidden
12341 service will be automatically added to the default configuration file. You
12342 may conveniently create @code{<hidden-service>} records using the
12343 @code{tor-hidden-service} procedure described below.
12344
12345 @item @code{socks-socket-type} (default: @code{'tcp})
12346 The default socket type that Tor should use for its SOCKS socket. This must
12347 be either @code{'tcp} or @code{'unix}. If it is @code{'tcp}, then by default
12348 Tor will listen on TCP port 9050 on the loopback interface (i.e., localhost).
12349 If it is @code{'unix}, then Tor will listen on the UNIX domain socket
12350 @file{/var/run/tor/socks-sock}, which will be made writable by members of the
12351 @code{tor} group.
12352
12353 If you want to customize the SOCKS socket in more detail, leave
12354 @code{socks-socket-type} at its default value of @code{'tcp} and use
12355 @code{config-file} to override the default by providing your own
12356 @code{SocksPort} option.
12357 @end table
12358 @end deftp
12359
12360 @cindex hidden service
12361 @deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
12362 Define a new Tor @dfn{hidden service} called @var{name} and implementing
12363 @var{mapping}. @var{mapping} is a list of port/host tuples, such as:
12364
12365 @example
12366 '((22 "127.0.0.1:22")
12367 (80 "127.0.0.1:8080"))
12368 @end example
12369
12370 In this example, port 22 of the hidden service is mapped to local port 22, and
12371 port 80 is mapped to local port 8080.
12372
12373 This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
12374 the @file{hostname} file contains the @code{.onion} host name for the hidden
12375 service.
12376
12377 See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
12378 project's documentation} for more information.
12379 @end deffn
12380
12381 The @code{(gnu services rsync)} module provides the following services:
12382
12383 You might want an rsync daemon if you have files that you want available
12384 so anyone (or just yourself) can download existing files or upload new
12385 files.
12386
12387 @deffn {Scheme Variable} rsync-service-type
12388 This is the type for the @uref{https://rsync.samba.org, rsync} rsync daemon,
12389 @command{rsync-configuration} record as in this example:
12390
12391 @example
12392 (service rsync-service-type)
12393 @end example
12394
12395 See below for details about @code{rsync-configuration}.
12396 @end deffn
12397
12398 @deftp {Data Type} rsync-configuration
12399 Data type representing the configuration for @code{rsync-service}.
12400
12401 @table @asis
12402 @item @code{package} (default: @var{rsync})
12403 @code{rsync} package to use.
12404
12405 @item @code{port-number} (default: @code{873})
12406 TCP port on which @command{rsync} listens for incoming connections. If port
12407 is less than @code{1024} @command{rsync} needs to be started as the
12408 @code{root} user and group.
12409
12410 @item @code{pid-file} (default: @code{"/var/run/rsyncd/rsyncd.pid"})
12411 Name of the file where @command{rsync} writes its PID.
12412
12413 @item @code{lock-file} (default: @code{"/var/run/rsyncd/rsyncd.lock"})
12414 Name of the file where @command{rsync} writes its lock file.
12415
12416 @item @code{log-file} (default: @code{"/var/log/rsyncd.log"})
12417 Name of the file where @command{rsync} writes its log file.
12418
12419 @item @code{use-chroot?} (default: @var{#t})
12420 Whether to use chroot for @command{rsync} shared directory.
12421
12422 @item @code{share-path} (default: @file{/srv/rsync})
12423 Location of the @command{rsync} shared directory.
12424
12425 @item @code{share-comment} (default: @code{"Rsync share"})
12426 Comment of the @command{rsync} shared directory.
12427
12428 @item @code{read-only?} (default: @var{#f})
12429 Read-write permissions to shared directory.
12430
12431 @item @code{timeout} (default: @code{300})
12432 I/O timeout in seconds.
12433
12434 @item @code{user} (default: @var{"root"})
12435 Owner of the @code{rsync} process.
12436
12437 @item @code{group} (default: @var{"root"})
12438 Group of the @code{rsync} process.
12439
12440 @item @code{uid} (default: @var{"rsyncd"})
12441 User name or user ID that file transfers to and from that module should take
12442 place as when the daemon was run as @code{root}.
12443
12444 @item @code{gid} (default: @var{"rsyncd"})
12445 Group name or group ID that will be used when accessing the module.
12446
12447 @end table
12448 @end deftp
12449
12450 Furthermore, @code{(gnu services ssh)} provides the following services.
12451 @cindex SSH
12452 @cindex SSH server
12453
12454 @deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
12455 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
12456 [#:allow-empty-passwords? #f] [#:root-login? #f] @
12457 [#:syslog-output? #t] [#:x11-forwarding? #t] @
12458 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
12459 [#:public-key-authentication? #t] [#:initialize? #t]
12460 Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
12461 @var{host-key} must designate a file containing the host key, and readable
12462 only by root.
12463
12464 When @var{daemonic?} is true, @command{lshd} will detach from the
12465 controlling terminal and log its output to syslogd, unless one sets
12466 @var{syslog-output?} to false. Obviously, it also makes lsh-service
12467 depend on existence of syslogd service. When @var{pid-file?} is true,
12468 @command{lshd} writes its PID to the file called @var{pid-file}.
12469
12470 When @var{initialize?} is true, automatically create the seed and host key
12471 upon service activation if they do not exist yet. This may take long and
12472 require interaction.
12473
12474 When @var{initialize?} is false, it is up to the user to initialize the
12475 randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
12476 a key pair with the private key stored in file @var{host-key} (@pxref{lshd
12477 basics,,, lsh, LSH Manual}).
12478
12479 When @var{interfaces} is empty, lshd listens for connections on all the
12480 network interfaces; otherwise, @var{interfaces} must be a list of host names
12481 or addresses.
12482
12483 @var{allow-empty-passwords?} specifies whether to accept log-ins with empty
12484 passwords, and @var{root-login?} specifies whether to accept log-ins as
12485 root.
12486
12487 The other options should be self-descriptive.
12488 @end deffn
12489
12490 @cindex SSH
12491 @cindex SSH server
12492 @deffn {Scheme Variable} openssh-service-type
12493 This is the type for the @uref{http://www.openssh.org, OpenSSH} secure
12494 shell daemon, @command{sshd}. Its value must be an
12495 @code{openssh-configuration} record as in this example:
12496
12497 @example
12498 (service openssh-service-type
12499 (openssh-configuration
12500 (x11-forwarding? #t)
12501 (permit-root-login 'without-password)
12502 (authorized-keys
12503 `(("alice" ,(local-file "alice.pub"))
12504 ("bob" ,(local-file "bob.pub"))))))
12505 @end example
12506
12507 See below for details about @code{openssh-configuration}.
12508
12509 This service can be extended with extra authorized keys, as in this
12510 example:
12511
12512 @example
12513 (service-extension openssh-service-type
12514 (const `(("charlie"
12515 ,(local-file "charlie.pub")))))
12516 @end example
12517 @end deffn
12518
12519 @deftp {Data Type} openssh-configuration
12520 This is the configuration record for OpenSSH's @command{sshd}.
12521
12522 @table @asis
12523 @item @code{pid-file} (default: @code{"/var/run/sshd.pid"})
12524 Name of the file where @command{sshd} writes its PID.
12525
12526 @item @code{port-number} (default: @code{22})
12527 TCP port on which @command{sshd} listens for incoming connections.
12528
12529 @item @code{permit-root-login} (default: @code{#f})
12530 This field determines whether and when to allow logins as root. If
12531 @code{#f}, root logins are disallowed; if @code{#t}, they are allowed.
12532 If it's the symbol @code{'without-password}, then root logins are
12533 permitted but not with password-based authentication.
12534
12535 @item @code{allow-empty-passwords?} (default: @code{#f})
12536 When true, users with empty passwords may log in. When false, they may
12537 not.
12538
12539 @item @code{password-authentication?} (default: @code{#t})
12540 When true, users may log in with their password. When false, they have
12541 other authentication methods.
12542
12543 @item @code{public-key-authentication?} (default: @code{#t})
12544 When true, users may log in using public key authentication. When
12545 false, users have to use other authentication method.
12546
12547 Authorized public keys are stored in @file{~/.ssh/authorized_keys}.
12548 This is used only by protocol version 2.
12549
12550 @item @code{x11-forwarding?} (default: @code{#f})
12551 When true, forwarding of X11 graphical client connections is
12552 enabled---in other words, @command{ssh} options @option{-X} and
12553 @option{-Y} will work.
12554
12555 @item @code{allow-agent-forwarding?} (default: @code{#t})
12556 Whether to allow agent forwarding.
12557
12558 @item @code{allow-tcp-forwarding?} (default: @code{#t})
12559 Whether to allow TCP forwarding.
12560
12561 @item @code{gateway-ports?} (default: @code{#f})
12562 Whether to allow gateway ports.
12563
12564 @item @code{challenge-response-authentication?} (default: @code{#f})
12565 Specifies whether challenge response authentication is allowed (e.g.@: via
12566 PAM).
12567
12568 @item @code{use-pam?} (default: @code{#t})
12569 Enables the Pluggable Authentication Module interface. If set to
12570 @code{#t}, this will enable PAM authentication using
12571 @code{challenge-response-authentication?} and
12572 @code{password-authentication?}, in addition to PAM account and session
12573 module processing for all authentication types.
12574
12575 Because PAM challenge response authentication usually serves an
12576 equivalent role to password authentication, you should disable either
12577 @code{challenge-response-authentication?} or
12578 @code{password-authentication?}.
12579
12580 @item @code{print-last-log?} (default: @code{#t})
12581 Specifies whether @command{sshd} should print the date and time of the
12582 last user login when a user logs in interactively.
12583
12584 @item @code{subsystems} (default: @code{'(("sftp" "internal-sftp"))})
12585 Configures external subsystems (e.g.@: file transfer daemon).
12586
12587 This is a list of two-element lists, each of which containing the
12588 subsystem name and a command (with optional arguments) to execute upon
12589 subsystem request.
12590
12591 The command @command{internal-sftp} implements an in-process SFTP
12592 server. Alternately, one can specify the @command{sftp-server} command:
12593 @example
12594 (service openssh-service-type
12595 (openssh-configuration
12596 (subsystems
12597 `(("sftp" ,(file-append openssh "/libexec/sftp-server"))))))
12598 @end example
12599
12600 @item @code{accepted-environment} (default: @code{'()})
12601 List of strings describing which environment variables may be exported.
12602
12603 Each string gets on its own line. See the @code{AcceptEnv} option in
12604 @code{man sshd_config}.
12605
12606 This example allows ssh-clients to export the @code{COLORTERM} variable.
12607 It is set by terminal emulators, which support colors. You can use it in
12608 your shell's ressource file to enable colors for the prompt and commands
12609 if this variable is set.
12610
12611 @example
12612 (service openssh-service-type
12613 (openssh-configuration
12614 (accepted-environment '("COLORTERM"))))
12615 @end example
12616
12617 @item @code{authorized-keys} (default: @code{'()})
12618 @cindex authorized keys, SSH
12619 @cindex SSH authorized keys
12620 This is the list of authorized keys. Each element of the list is a user
12621 name followed by one or more file-like objects that represent SSH public
12622 keys. For example:
12623
12624 @example
12625 (openssh-configuration
12626 (authorized-keys
12627 `(("rekado" ,(local-file "rekado.pub"))
12628 ("chris" ,(local-file "chris.pub"))
12629 ("root" ,(local-file "rekado.pub") ,(local-file "chris.pub")))))
12630 @end example
12631
12632 @noindent
12633 registers the specified public keys for user accounts @code{rekado},
12634 @code{chris}, and @code{root}.
12635
12636 Additional authorized keys can be specified @i{via}
12637 @code{service-extension}.
12638
12639 Note that this does @emph{not} interfere with the use of
12640 @file{~/.ssh/authorized_keys}.
12641
12642 @item @code{log-level} (default: @code{'info})
12643 This is a symbol specifying the logging level: @code{quiet}, @code{fatal},
12644 @code{error}, @code{info}, @code{verbose}, @code{debug}, etc. See the man
12645 page for @file{sshd_config} for the full list of level names.
12646
12647 @item @code{extra-content} (default: @code{""})
12648 This field can be used to append arbitrary text to the configuration file. It
12649 is especially useful for elaborate configurations that cannot be expressed
12650 otherwise. This configuration, for example, would generally disable root
12651 logins, but permit them from one specific IP address:
12652
12653 @example
12654 (openssh-configuration
12655 (extra-content "\
12656 Match Address 192.168.0.1
12657 PermitRootLogin yes"))
12658 @end example
12659
12660 @end table
12661 @end deftp
12662
12663 @deffn {Scheme Procedure} dropbear-service [@var{config}]
12664 Run the @uref{https://matt.ucc.asn.au/dropbear/dropbear.html,Dropbear SSH
12665 daemon} with the given @var{config}, a @code{<dropbear-configuration>}
12666 object.
12667
12668 For example, to specify a Dropbear service listening on port 1234, add
12669 this call to the operating system's @code{services} field:
12670
12671 @example
12672 (dropbear-service (dropbear-configuration
12673 (port-number 1234)))
12674 @end example
12675 @end deffn
12676
12677 @deftp {Data Type} dropbear-configuration
12678 This data type represents the configuration of a Dropbear SSH daemon.
12679
12680 @table @asis
12681 @item @code{dropbear} (default: @var{dropbear})
12682 The Dropbear package to use.
12683
12684 @item @code{port-number} (default: 22)
12685 The TCP port where the daemon waits for incoming connections.
12686
12687 @item @code{syslog-output?} (default: @code{#t})
12688 Whether to enable syslog output.
12689
12690 @item @code{pid-file} (default: @code{"/var/run/dropbear.pid"})
12691 File name of the daemon's PID file.
12692
12693 @item @code{root-login?} (default: @code{#f})
12694 Whether to allow @code{root} logins.
12695
12696 @item @code{allow-empty-passwords?} (default: @code{#f})
12697 Whether to allow empty passwords.
12698
12699 @item @code{password-authentication?} (default: @code{#t})
12700 Whether to enable password-based authentication.
12701 @end table
12702 @end deftp
12703
12704 @defvr {Scheme Variable} %facebook-host-aliases
12705 This variable contains a string for use in @file{/etc/hosts}
12706 (@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
12707 line contains a entry that maps a known server name of the Facebook
12708 on-line service---e.g., @code{www.facebook.com}---to the local
12709 host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
12710
12711 This variable is typically used in the @code{hosts-file} field of an
12712 @code{operating-system} declaration (@pxref{operating-system Reference,
12713 @file{/etc/hosts}}):
12714
12715 @example
12716 (use-modules (gnu) (guix))
12717
12718 (operating-system
12719 (host-name "mymachine")
12720 ;; ...
12721 (hosts-file
12722 ;; Create a /etc/hosts file with aliases for "localhost"
12723 ;; and "mymachine", as well as for Facebook servers.
12724 (plain-file "hosts"
12725 (string-append (local-host-aliases host-name)
12726 %facebook-host-aliases))))
12727 @end example
12728
12729 This mechanism can prevent programs running locally, such as Web
12730 browsers, from accessing Facebook.
12731 @end defvr
12732
12733 The @code{(gnu services avahi)} provides the following definition.
12734
12735 @defvr {Scheme Variable} avahi-service-type
12736 This is the service that runs @command{avahi-daemon}, a system-wide
12737 mDNS/DNS-SD responder that allows for service discovery and
12738 ``zero-configuration'' host name lookups (see @uref{http://avahi.org/}).
12739 Its value must be a @code{zero-configuration} record---see below.
12740
12741 This service extends the name service cache daemon (nscd) so that it can
12742 resolve @code{.local} host names using
12743 @uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. @xref{Name
12744 Service Switch}, for information on host name resolution.
12745
12746 Additionally, add the @var{avahi} package to the system profile so that
12747 commands such as @command{avahi-browse} are directly usable.
12748 @end defvr
12749
12750 @deftp {Data Type} avahi-configuration
12751 Data type representation the configuration for Avahi.
12752
12753 @table @asis
12754
12755 @item @code{host-name} (default: @code{#f})
12756 If different from @code{#f}, use that as the host name to
12757 publish for this machine; otherwise, use the machine's actual host name.
12758
12759 @item @code{publish?} (default: @code{#t})
12760 When true, allow host names and services to be published (broadcast) over the
12761 network.
12762
12763 @item @code{publish-workstation?} (default: @code{#t})
12764 When true, @command{avahi-daemon} publishes the machine's host name and IP
12765 address via mDNS on the local network. To view the host names published on
12766 your local network, you can run:
12767
12768 @example
12769 avahi-browse _workstation._tcp
12770 @end example
12771
12772 @item @code{wide-area?} (default: @code{#f})
12773 When true, DNS-SD over unicast DNS is enabled.
12774
12775 @item @code{ipv4?} (default: @code{#t})
12776 @itemx @code{ipv6?} (default: @code{#t})
12777 These fields determine whether to use IPv4/IPv6 sockets.
12778
12779 @item @code{domains-to-browse} (default: @code{'()})
12780 This is a list of domains to browse.
12781 @end table
12782 @end deftp
12783
12784 @deffn {Scheme Variable} openvswitch-service-type
12785 This is the type of the @uref{http://www.openvswitch.org, Open vSwitch}
12786 service, whose value should be an @code{openvswitch-configuration}
12787 object.
12788 @end deffn
12789
12790 @deftp {Data Type} openvswitch-configuration
12791 Data type representing the configuration of Open vSwitch, a multilayer
12792 virtual switch which is designed to enable massive network automation
12793 through programmatic extension.
12794
12795 @table @asis
12796 @item @code{package} (default: @var{openvswitch})
12797 Package object of the Open vSwitch.
12798
12799 @end table
12800 @end deftp
12801
12802 @node X Window
12803 @subsubsection X Window
12804
12805 @cindex X11
12806 @cindex X Window System
12807 @cindex login manager
12808 Support for the X Window graphical display system---specifically
12809 Xorg---is provided by the @code{(gnu services xorg)} module. Note that
12810 there is no @code{xorg-service} procedure. Instead, the X server is
12811 started by the @dfn{login manager}, by default SLiM.
12812
12813 @cindex window manager
12814 To use X11, you must install at least one @dfn{window manager}---for
12815 example the @code{windowmaker} or @code{openbox} packages---preferably
12816 by adding it to the @code{packages} field of your operating system
12817 definition (@pxref{operating-system Reference, system-wide packages}).
12818
12819 @defvr {Scheme Variable} slim-service-type
12820 This is the type for the SLiM graphical login manager for X11.
12821
12822 @cindex session types (X11)
12823 @cindex X11 session types
12824 SLiM looks for @dfn{session types} described by the @file{.desktop} files in
12825 @file{/run/current-system/profile/share/xsessions} and allows users to
12826 choose a session from the log-in screen using @kbd{F1}. Packages such
12827 as @code{xfce}, @code{sawfish}, and @code{ratpoison} provide
12828 @file{.desktop} files; adding them to the system-wide set of packages
12829 automatically makes them available at the log-in screen.
12830
12831 In addition, @file{~/.xsession} files are honored. When available,
12832 @file{~/.xsession} must be an executable that starts a window manager
12833 and/or other X clients.
12834 @end defvr
12835
12836 @deftp {Data Type} slim-configuration
12837 Data type representing the configuration of @code{slim-service-type}.
12838
12839 @table @asis
12840 @item @code{allow-empty-passwords?} (default: @code{#t})
12841 Whether to allow logins with empty passwords.
12842
12843 @item @code{auto-login?} (default: @code{#f})
12844 @itemx @code{default-user} (default: @code{""})
12845 When @code{auto-login?} is false, SLiM presents a log-in screen.
12846
12847 When @code{auto-login?} is true, SLiM logs in directly as
12848 @code{default-user}.
12849
12850 @item @code{theme} (default: @code{%default-slim-theme})
12851 @itemx @code{theme-name} (default: @code{%default-slim-theme-name})
12852 The graphical theme to use and its name.
12853
12854 @item @code{auto-login-session} (default: @code{#f})
12855 If true, this must be the name of the executable to start as the default
12856 session---e.g., @code{(file-append windowmaker "/bin/windowmaker")}.
12857
12858 If false, a session described by one of the available @file{.desktop}
12859 files in @code{/run/current-system/profile} and @code{~/.guix-profile}
12860 will be used.
12861
12862 @quotation Note
12863 You must install at least one window manager in the system profile or in
12864 your user profile. Failing to do that, if @code{auto-login-session} is
12865 false, you will be unable to log in.
12866 @end quotation
12867
12868 @item @code{startx} (default: @code{(xorg-start-command)})
12869 The command used to start the X11 graphical server.
12870
12871 @item @code{xauth} (default: @code{xauth})
12872 The XAuth package to use.
12873
12874 @item @code{shepherd} (default: @code{shepherd})
12875 The Shepherd package used when invoking @command{halt} and
12876 @command{reboot}.
12877
12878 @item @code{sessreg} (default: @code{sessreg})
12879 The sessreg package used in order to register the session.
12880
12881 @item @code{slim} (default: @code{slim})
12882 The SLiM package to use.
12883 @end table
12884 @end deftp
12885
12886 @defvr {Scheme Variable} %default-theme
12887 @defvrx {Scheme Variable} %default-theme-name
12888 The default SLiM theme and its name.
12889 @end defvr
12890
12891
12892 @deftp {Data Type} sddm-configuration
12893 This is the data type representing the sddm service configuration.
12894
12895 @table @asis
12896 @item @code{display-server} (default: "x11")
12897 Select display server to use for the greeter. Valid values are "x11"
12898 or "wayland".
12899
12900 @item @code{numlock} (default: "on")
12901 Valid values are "on", "off" or "none".
12902
12903 @item @code{halt-command} (default @code{#~(string-apppend #$shepherd "/sbin/halt")})
12904 Command to run when halting.
12905
12906 @item @code{reboot-command} (default @code{#~(string-append #$shepherd "/sbin/reboot")})
12907 Command to run when rebooting.
12908
12909 @item @code{theme} (default "maldives")
12910 Theme to use. Default themes provided by SDDM are "elarun" or "maldives".
12911
12912 @item @code{themes-directory} (default "/run/current-system/profile/share/sddm/themes")
12913 Directory to look for themes.
12914
12915 @item @code{faces-directory} (default "/run/current-system/profile/share/sddm/faces")
12916 Directory to look for faces.
12917
12918 @item @code{default-path} (default "/run/current-system/profile/bin")
12919 Default PATH to use.
12920
12921 @item @code{minimum-uid} (default 1000)
12922 Minimum UID to display in SDDM.
12923
12924 @item @code{maximum-uid} (default 2000)
12925 Maximum UID to display in SDDM
12926
12927 @item @code{remember-last-user?} (default #t)
12928 Remember last user.
12929
12930 @item @code{remember-last-session?} (default #t)
12931 Remember last session.
12932
12933 @item @code{hide-users} (default "")
12934 Usernames to hide from SDDM greeter.
12935
12936 @item @code{hide-shells} (default @code{#~(string-append #$shadow "/sbin/nologin")})
12937 Users with shells listed will be hidden from the SDDM greeter.
12938
12939 @item @code{session-command} (default @code{#~(string-append #$sddm "/share/sddm/scripts/wayland-session")})
12940 Script to run before starting a wayland session.
12941
12942 @item @code{sessions-directory} (default "/run/current-system/profile/share/wayland-sessions")
12943 Directory to look for desktop files starting wayland sessions.
12944
12945 @item @code{xorg-server-path} (default @code{xorg-start-command})
12946 Path to xorg-server.
12947
12948 @item @code{xauth-path} (default @code{#~(string-append #$xauth "/bin/xauth")})
12949 Path to xauth.
12950
12951 @item @code{xephyr-path} (default @code{#~(string-append #$xorg-server "/bin/Xephyr")})
12952 Path to Xephyr.
12953
12954 @item @code{xdisplay-start} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xsetup")})
12955 Script to run after starting xorg-server.
12956
12957 @item @code{xdisplay-stop} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xstop")})
12958 Script to run before stopping xorg-server.
12959
12960 @item @code{xsession-command} (default: @code{xinitrc})
12961 Script to run before starting a X session.
12962
12963 @item @code{xsessions-directory} (default: "/run/current-system/profile/share/xsessions")
12964 Directory to look for desktop files starting X sessions.
12965
12966 @item @code{minimum-vt} (default: 7)
12967 Minimum VT to use.
12968
12969 @item @code{xserver-arguments} (default "-nolisten tcp")
12970 Arguments to pass to xorg-server.
12971
12972 @item @code{auto-login-user} (default "")
12973 User to use for auto-login.
12974
12975 @item @code{auto-login-session} (default "")
12976 Desktop file to use for auto-login.
12977
12978 @item @code{relogin?} (default #f)
12979 Relogin after logout.
12980
12981 @end table
12982 @end deftp
12983
12984 @cindex login manager
12985 @cindex X11 login
12986 @deffn {Scheme Procedure} sddm-service config
12987 Return a service that spawns the SDDM graphical login manager for config of
12988 type @code{<sddm-configuration>}.
12989
12990 @example
12991 (sddm-service (sddm-configuration
12992 (auto-login-user "Alice")
12993 (auto-login-session "xfce.desktop")))
12994 @end example
12995 @end deffn
12996
12997 @deffn {Scheme Procedure} xorg-start-command [#:guile] @
12998 [#:modules %default-xorg-modules] @
12999 [#:fonts %default-xorg-fonts] @
13000 [#:configuration-file (xorg-configuration-file @dots{})] @
13001 [#:xorg-server @var{xorg-server}]
13002 Return a @code{startx} script in which @var{modules}, a list of X module
13003 packages, and @var{fonts}, a list of X font directories, are available. See
13004 @code{xorg-wrapper} for more details on the arguments. The result should be
13005 used in place of @code{startx}.
13006
13007 Usually the X server is started by a login manager.
13008 @end deffn
13009
13010 @deffn {Scheme Procedure} xorg-configuration-file @
13011 [#:modules %default-xorg-modules] @
13012 [#:fonts %default-xorg-fonts] @
13013 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
13014 Return a configuration file for the Xorg server containing search paths for
13015 all the common drivers.
13016
13017 @var{modules} must be a list of @dfn{module packages} loaded by the Xorg
13018 server---e.g., @code{xf86-video-vesa}, @code{xf86-input-keyboard}, and so on.
13019 @var{fonts} must be a list of font directories to add to the server's
13020 @dfn{font path}.
13021
13022 @var{drivers} must be either the empty list, in which case Xorg chooses a
13023 graphics driver automatically, or a list of driver names that will be tried in
13024 this order---e.g., @code{("modesetting" "vesa")}.
13025
13026 Likewise, when @var{resolutions} is the empty list, Xorg chooses an
13027 appropriate screen resolution; otherwise, it must be a list of
13028 resolutions---e.g., @code{((1024 768) (640 480))}.
13029
13030 Last, @var{extra-config} is a list of strings or objects appended to the
13031 configuration file. It is used to pass extra text to be
13032 added verbatim to the configuration file.
13033
13034 @cindex keymap
13035 @cindex keyboard layout
13036 This procedure is especially useful to configure a different keyboard layout
13037 than the default US keymap. For instance, to use the ``bépo'' keymap by
13038 default on the display manager:
13039
13040 @example
13041 (define bepo-evdev
13042 "Section \"InputClass\"
13043 Identifier \"evdev keyboard catchall\"
13044 Driver \"evdev\"
13045 MatchIsKeyboard \"on\"
13046 Option \"xkb_layout\" \"fr\"
13047 Option \"xkb_variant\" \"bepo\"
13048 EndSection")
13049
13050 (operating-system
13051 ...
13052 (services
13053 (modify-services %desktop-services
13054 (slim-service-type config =>
13055 (slim-configuration
13056 (inherit config)
13057 (startx (xorg-start-command
13058 #:configuration-file
13059 (xorg-configuration-file
13060 #:extra-config
13061 (list bepo-evdev)))))))))
13062 @end example
13063
13064 The @code{MatchIsKeyboard} line specifies that we only apply the configuration
13065 to keyboards. Without this line, other devices such as touchpad may not work
13066 correctly because they will be attached to the wrong driver. In this example,
13067 the user typically used @code{setxkbmap fr bepo} to set their favorite keymap
13068 once logged in. The first argument corresponds to the layout, while the second
13069 argument corresponds to the variant. The @code{xkb_variant} line can be omitted
13070 to select the default variant.
13071 @end deffn
13072
13073 @deffn {Scheme Procedure} screen-locker-service @var{package} [@var{program}]
13074 Add @var{package}, a package for a screen locker or screen saver whose
13075 command is @var{program}, to the set of setuid programs and add a PAM entry
13076 for it. For example:
13077
13078 @lisp
13079 (screen-locker-service xlockmore "xlock")
13080 @end lisp
13081
13082 makes the good ol' XlockMore usable.
13083 @end deffn
13084
13085
13086 @node Printing Services
13087 @subsubsection Printing Services
13088
13089 @cindex printer support with CUPS
13090 The @code{(gnu services cups)} module provides a Guix service definition
13091 for the CUPS printing service. To add printer support to a GuixSD
13092 system, add a @code{cups-service} to the operating system definition:
13093
13094 @deffn {Scheme Variable} cups-service-type
13095 The service type for the CUPS print server. Its value should be a valid
13096 CUPS configuration (see below). To use the default settings, simply
13097 write:
13098 @example
13099 (service cups-service-type)
13100 @end example
13101 @end deffn
13102
13103 The CUPS configuration controls the basic things about your CUPS
13104 installation: what interfaces it listens on, what to do if a print job
13105 fails, how much logging to do, and so on. To actually add a printer,
13106 you have to visit the @url{http://localhost:631} URL, or use a tool such
13107 as GNOME's printer configuration services. By default, configuring a
13108 CUPS service will generate a self-signed certificate if needed, for
13109 secure connections to the print server.
13110
13111 Suppose you want to enable the Web interface of CUPS and also add
13112 support for Epson printers @i{via} the @code{escpr} package and for HP
13113 printers @i{via} the @code{hplip-minimal} package. You can do that directly,
13114 like this (you need to use the @code{(gnu packages cups)} module):
13115
13116 @example
13117 (service cups-service-type
13118 (cups-configuration
13119 (web-interface? #t)
13120 (extensions
13121 (list cups-filters escpr hplip-minimal))))
13122 @end example
13123
13124 Note: If you wish to use the Qt5 based GUI which comes with the hplip
13125 package then it is suggested that you install the @code{hplip} package,
13126 either in your OS configuration file or as your user.
13127
13128 The available configuration parameters follow. Each parameter
13129 definition is preceded by its type; for example, @samp{string-list foo}
13130 indicates that the @code{foo} parameter should be specified as a list of
13131 strings. There is also a way to specify the configuration as a string,
13132 if you have an old @code{cupsd.conf} file that you want to port over
13133 from some other system; see the end for more details.
13134
13135 @c The following documentation was initially generated by
13136 @c (generate-documentation) in (gnu services cups). Manually maintained
13137 @c documentation is better, so we shouldn't hesitate to edit below as
13138 @c needed. However if the change you want to make to this documentation
13139 @c can be done in an automated way, it's probably easier to change
13140 @c (generate-documentation) than to make it below and have to deal with
13141 @c the churn as CUPS updates.
13142
13143
13144 Available @code{cups-configuration} fields are:
13145
13146 @deftypevr {@code{cups-configuration} parameter} package cups
13147 The CUPS package.
13148 @end deftypevr
13149
13150 @deftypevr {@code{cups-configuration} parameter} package-list extensions
13151 Drivers and other extensions to the CUPS package.
13152 @end deftypevr
13153
13154 @deftypevr {@code{cups-configuration} parameter} files-configuration files-configuration
13155 Configuration of where to write logs, what directories to use for print
13156 spools, and related privileged configuration parameters.
13157
13158 Available @code{files-configuration} fields are:
13159
13160 @deftypevr {@code{files-configuration} parameter} log-location access-log
13161 Defines the access log filename. Specifying a blank filename disables
13162 access log generation. The value @code{stderr} causes log entries to be
13163 sent to the standard error file when the scheduler is running in the
13164 foreground, or to the system log daemon when run in the background. The
13165 value @code{syslog} causes log entries to be sent to the system log
13166 daemon. The server name may be included in filenames using the string
13167 @code{%s}, as in @code{/var/log/cups/%s-access_log}.
13168
13169 Defaults to @samp{"/var/log/cups/access_log"}.
13170 @end deftypevr
13171
13172 @deftypevr {@code{files-configuration} parameter} file-name cache-dir
13173 Where CUPS should cache data.
13174
13175 Defaults to @samp{"/var/cache/cups"}.
13176 @end deftypevr
13177
13178 @deftypevr {@code{files-configuration} parameter} string config-file-perm
13179 Specifies the permissions for all configuration files that the scheduler
13180 writes.
13181
13182 Note that the permissions for the printers.conf file are currently
13183 masked to only allow access from the scheduler user (typically root).
13184 This is done because printer device URIs sometimes contain sensitive
13185 authentication information that should not be generally known on the
13186 system. There is no way to disable this security feature.
13187
13188 Defaults to @samp{"0640"}.
13189 @end deftypevr
13190
13191 @deftypevr {@code{files-configuration} parameter} log-location error-log
13192 Defines the error log filename. Specifying a blank filename disables
13193 access log generation. The value @code{stderr} causes log entries to be
13194 sent to the standard error file when the scheduler is running in the
13195 foreground, or to the system log daemon when run in the background. The
13196 value @code{syslog} causes log entries to be sent to the system log
13197 daemon. The server name may be included in filenames using the string
13198 @code{%s}, as in @code{/var/log/cups/%s-error_log}.
13199
13200 Defaults to @samp{"/var/log/cups/error_log"}.
13201 @end deftypevr
13202
13203 @deftypevr {@code{files-configuration} parameter} string fatal-errors
13204 Specifies which errors are fatal, causing the scheduler to exit. The
13205 kind strings are:
13206
13207 @table @code
13208 @item none
13209 No errors are fatal.
13210
13211 @item all
13212 All of the errors below are fatal.
13213
13214 @item browse
13215 Browsing initialization errors are fatal, for example failed connections
13216 to the DNS-SD daemon.
13217
13218 @item config
13219 Configuration file syntax errors are fatal.
13220
13221 @item listen
13222 Listen or Port errors are fatal, except for IPv6 failures on the
13223 loopback or @code{any} addresses.
13224
13225 @item log
13226 Log file creation or write errors are fatal.
13227
13228 @item permissions
13229 Bad startup file permissions are fatal, for example shared TLS
13230 certificate and key files with world-read permissions.
13231 @end table
13232
13233 Defaults to @samp{"all -browse"}.
13234 @end deftypevr
13235
13236 @deftypevr {@code{files-configuration} parameter} boolean file-device?
13237 Specifies whether the file pseudo-device can be used for new printer
13238 queues. The URI @uref{file:///dev/null} is always allowed.
13239
13240 Defaults to @samp{#f}.
13241 @end deftypevr
13242
13243 @deftypevr {@code{files-configuration} parameter} string group
13244 Specifies the group name or ID that will be used when executing external
13245 programs.
13246
13247 Defaults to @samp{"lp"}.
13248 @end deftypevr
13249
13250 @deftypevr {@code{files-configuration} parameter} string log-file-perm
13251 Specifies the permissions for all log files that the scheduler writes.
13252
13253 Defaults to @samp{"0644"}.
13254 @end deftypevr
13255
13256 @deftypevr {@code{files-configuration} parameter} log-location page-log
13257 Defines the page log filename. Specifying a blank filename disables
13258 access log generation. The value @code{stderr} causes log entries to be
13259 sent to the standard error file when the scheduler is running in the
13260 foreground, or to the system log daemon when run in the background. The
13261 value @code{syslog} causes log entries to be sent to the system log
13262 daemon. The server name may be included in filenames using the string
13263 @code{%s}, as in @code{/var/log/cups/%s-page_log}.
13264
13265 Defaults to @samp{"/var/log/cups/page_log"}.
13266 @end deftypevr
13267
13268 @deftypevr {@code{files-configuration} parameter} string remote-root
13269 Specifies the username that is associated with unauthenticated accesses
13270 by clients claiming to be the root user. The default is @code{remroot}.
13271
13272 Defaults to @samp{"remroot"}.
13273 @end deftypevr
13274
13275 @deftypevr {@code{files-configuration} parameter} file-name request-root
13276 Specifies the directory that contains print jobs and other HTTP request
13277 data.
13278
13279 Defaults to @samp{"/var/spool/cups"}.
13280 @end deftypevr
13281
13282 @deftypevr {@code{files-configuration} parameter} sandboxing sandboxing
13283 Specifies the level of security sandboxing that is applied to print
13284 filters, backends, and other child processes of the scheduler; either
13285 @code{relaxed} or @code{strict}. This directive is currently only
13286 used/supported on macOS.
13287
13288 Defaults to @samp{strict}.
13289 @end deftypevr
13290
13291 @deftypevr {@code{files-configuration} parameter} file-name server-keychain
13292 Specifies the location of TLS certificates and private keys. CUPS will
13293 look for public and private keys in this directory: a @code{.crt} files
13294 for PEM-encoded certificates and corresponding @code{.key} files for
13295 PEM-encoded private keys.
13296
13297 Defaults to @samp{"/etc/cups/ssl"}.
13298 @end deftypevr
13299
13300 @deftypevr {@code{files-configuration} parameter} file-name server-root
13301 Specifies the directory containing the server configuration files.
13302
13303 Defaults to @samp{"/etc/cups"}.
13304 @end deftypevr
13305
13306 @deftypevr {@code{files-configuration} parameter} boolean sync-on-close?
13307 Specifies whether the scheduler calls fsync(2) after writing
13308 configuration or state files.
13309
13310 Defaults to @samp{#f}.
13311 @end deftypevr
13312
13313 @deftypevr {@code{files-configuration} parameter} space-separated-string-list system-group
13314 Specifies the group(s) to use for @code{@@SYSTEM} group authentication.
13315 @end deftypevr
13316
13317 @deftypevr {@code{files-configuration} parameter} file-name temp-dir
13318 Specifies the directory where temporary files are stored.
13319
13320 Defaults to @samp{"/var/spool/cups/tmp"}.
13321 @end deftypevr
13322
13323 @deftypevr {@code{files-configuration} parameter} string user
13324 Specifies the user name or ID that is used when running external
13325 programs.
13326
13327 Defaults to @samp{"lp"}.
13328 @end deftypevr
13329 @end deftypevr
13330
13331 @deftypevr {@code{cups-configuration} parameter} access-log-level access-log-level
13332 Specifies the logging level for the AccessLog file. The @code{config}
13333 level logs when printers and classes are added, deleted, or modified and
13334 when configuration files are accessed or updated. The @code{actions}
13335 level logs when print jobs are submitted, held, released, modified, or
13336 canceled, and any of the conditions for @code{config}. The @code{all}
13337 level logs all requests.
13338
13339 Defaults to @samp{actions}.
13340 @end deftypevr
13341
13342 @deftypevr {@code{cups-configuration} parameter} boolean auto-purge-jobs?
13343 Specifies whether to purge job history data automatically when it is no
13344 longer required for quotas.
13345
13346 Defaults to @samp{#f}.
13347 @end deftypevr
13348
13349 @deftypevr {@code{cups-configuration} parameter} browse-local-protocols browse-local-protocols
13350 Specifies which protocols to use for local printer sharing.
13351
13352 Defaults to @samp{dnssd}.
13353 @end deftypevr
13354
13355 @deftypevr {@code{cups-configuration} parameter} boolean browse-web-if?
13356 Specifies whether the CUPS web interface is advertised.
13357
13358 Defaults to @samp{#f}.
13359 @end deftypevr
13360
13361 @deftypevr {@code{cups-configuration} parameter} boolean browsing?
13362 Specifies whether shared printers are advertised.
13363
13364 Defaults to @samp{#f}.
13365 @end deftypevr
13366
13367 @deftypevr {@code{cups-configuration} parameter} string classification
13368 Specifies the security classification of the server. Any valid banner
13369 name can be used, including "classified", "confidential", "secret",
13370 "topsecret", and "unclassified", or the banner can be omitted to disable
13371 secure printing functions.
13372
13373 Defaults to @samp{""}.
13374 @end deftypevr
13375
13376 @deftypevr {@code{cups-configuration} parameter} boolean classify-override?
13377 Specifies whether users may override the classification (cover page) of
13378 individual print jobs using the @code{job-sheets} option.
13379
13380 Defaults to @samp{#f}.
13381 @end deftypevr
13382
13383 @deftypevr {@code{cups-configuration} parameter} default-auth-type default-auth-type
13384 Specifies the default type of authentication to use.
13385
13386 Defaults to @samp{Basic}.
13387 @end deftypevr
13388
13389 @deftypevr {@code{cups-configuration} parameter} default-encryption default-encryption
13390 Specifies whether encryption will be used for authenticated requests.
13391
13392 Defaults to @samp{Required}.
13393 @end deftypevr
13394
13395 @deftypevr {@code{cups-configuration} parameter} string default-language
13396 Specifies the default language to use for text and web content.
13397
13398 Defaults to @samp{"en"}.
13399 @end deftypevr
13400
13401 @deftypevr {@code{cups-configuration} parameter} string default-paper-size
13402 Specifies the default paper size for new print queues. @samp{"Auto"}
13403 uses a locale-specific default, while @samp{"None"} specifies there is
13404 no default paper size. Specific size names are typically
13405 @samp{"Letter"} or @samp{"A4"}.
13406
13407 Defaults to @samp{"Auto"}.
13408 @end deftypevr
13409
13410 @deftypevr {@code{cups-configuration} parameter} string default-policy
13411 Specifies the default access policy to use.
13412
13413 Defaults to @samp{"default"}.
13414 @end deftypevr
13415
13416 @deftypevr {@code{cups-configuration} parameter} boolean default-shared?
13417 Specifies whether local printers are shared by default.
13418
13419 Defaults to @samp{#t}.
13420 @end deftypevr
13421
13422 @deftypevr {@code{cups-configuration} parameter} non-negative-integer dirty-clean-interval
13423 Specifies the delay for updating of configuration and state files, in
13424 seconds. A value of 0 causes the update to happen as soon as possible,
13425 typically within a few milliseconds.
13426
13427 Defaults to @samp{30}.
13428 @end deftypevr
13429
13430 @deftypevr {@code{cups-configuration} parameter} error-policy error-policy
13431 Specifies what to do when an error occurs. Possible values are
13432 @code{abort-job}, which will discard the failed print job;
13433 @code{retry-job}, which will retry the job at a later time;
13434 @code{retry-this-job}, which retries the failed job immediately; and
13435 @code{stop-printer}, which stops the printer.
13436
13437 Defaults to @samp{stop-printer}.
13438 @end deftypevr
13439
13440 @deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-limit
13441 Specifies the maximum cost of filters that are run concurrently, which
13442 can be used to minimize disk, memory, and CPU resource problems. A
13443 limit of 0 disables filter limiting. An average print to a
13444 non-PostScript printer needs a filter limit of about 200. A PostScript
13445 printer needs about half that (100). Setting the limit below these
13446 thresholds will effectively limit the scheduler to printing a single job
13447 at any time.
13448
13449 Defaults to @samp{0}.
13450 @end deftypevr
13451
13452 @deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-nice
13453 Specifies the scheduling priority of filters that are run to print a
13454 job. The nice value ranges from 0, the highest priority, to 19, the
13455 lowest priority.
13456
13457 Defaults to @samp{0}.
13458 @end deftypevr
13459
13460 @deftypevr {@code{cups-configuration} parameter} host-name-lookups host-name-lookups
13461 Specifies whether to do reverse lookups on connecting clients. The
13462 @code{double} setting causes @code{cupsd} to verify that the hostname
13463 resolved from the address matches one of the addresses returned for that
13464 hostname. Double lookups also prevent clients with unregistered
13465 addresses from connecting to your server. Only set this option to
13466 @code{#t} or @code{double} if absolutely required.
13467
13468 Defaults to @samp{#f}.
13469 @end deftypevr
13470
13471 @deftypevr {@code{cups-configuration} parameter} non-negative-integer job-kill-delay
13472 Specifies the number of seconds to wait before killing the filters and
13473 backend associated with a canceled or held job.
13474
13475 Defaults to @samp{30}.
13476 @end deftypevr
13477
13478 @deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-interval
13479 Specifies the interval between retries of jobs in seconds. This is
13480 typically used for fax queues but can also be used with normal print
13481 queues whose error policy is @code{retry-job} or
13482 @code{retry-current-job}.
13483
13484 Defaults to @samp{30}.
13485 @end deftypevr
13486
13487 @deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-limit
13488 Specifies the number of retries that are done for jobs. This is
13489 typically used for fax queues but can also be used with normal print
13490 queues whose error policy is @code{retry-job} or
13491 @code{retry-current-job}.
13492
13493 Defaults to @samp{5}.
13494 @end deftypevr
13495
13496 @deftypevr {@code{cups-configuration} parameter} boolean keep-alive?
13497 Specifies whether to support HTTP keep-alive connections.
13498
13499 Defaults to @samp{#t}.
13500 @end deftypevr
13501
13502 @deftypevr {@code{cups-configuration} parameter} non-negative-integer keep-alive-timeout
13503 Specifies how long an idle client connection remains open, in seconds.
13504
13505 Defaults to @samp{30}.
13506 @end deftypevr
13507
13508 @deftypevr {@code{cups-configuration} parameter} non-negative-integer limit-request-body
13509 Specifies the maximum size of print files, IPP requests, and HTML form
13510 data. A limit of 0 disables the limit check.
13511
13512 Defaults to @samp{0}.
13513 @end deftypevr
13514
13515 @deftypevr {@code{cups-configuration} parameter} multiline-string-list listen
13516 Listens on the specified interfaces for connections. Valid values are
13517 of the form @var{address}:@var{port}, where @var{address} is either an
13518 IPv6 address enclosed in brackets, an IPv4 address, or @code{*} to
13519 indicate all addresses. Values can also be file names of local UNIX
13520 domain sockets. The Listen directive is similar to the Port directive
13521 but allows you to restrict access to specific interfaces or networks.
13522 @end deftypevr
13523
13524 @deftypevr {@code{cups-configuration} parameter} non-negative-integer listen-back-log
13525 Specifies the number of pending connections that will be allowed. This
13526 normally only affects very busy servers that have reached the MaxClients
13527 limit, but can also be triggered by large numbers of simultaneous
13528 connections. When the limit is reached, the operating system will
13529 refuse additional connections until the scheduler can accept the pending
13530 ones.
13531
13532 Defaults to @samp{128}.
13533 @end deftypevr
13534
13535 @deftypevr {@code{cups-configuration} parameter} location-access-control-list location-access-controls
13536 Specifies a set of additional access controls.
13537
13538 Available @code{location-access-controls} fields are:
13539
13540 @deftypevr {@code{location-access-controls} parameter} file-name path
13541 Specifies the URI path to which the access control applies.
13542 @end deftypevr
13543
13544 @deftypevr {@code{location-access-controls} parameter} access-control-list access-controls
13545 Access controls for all access to this path, in the same format as the
13546 @code{access-controls} of @code{operation-access-control}.
13547
13548 Defaults to @samp{()}.
13549 @end deftypevr
13550
13551 @deftypevr {@code{location-access-controls} parameter} method-access-control-list method-access-controls
13552 Access controls for method-specific access to this path.
13553
13554 Defaults to @samp{()}.
13555
13556 Available @code{method-access-controls} fields are:
13557
13558 @deftypevr {@code{method-access-controls} parameter} boolean reverse?
13559 If @code{#t}, apply access controls to all methods except the listed
13560 methods. Otherwise apply to only the listed methods.
13561
13562 Defaults to @samp{#f}.
13563 @end deftypevr
13564
13565 @deftypevr {@code{method-access-controls} parameter} method-list methods
13566 Methods to which this access control applies.
13567
13568 Defaults to @samp{()}.
13569 @end deftypevr
13570
13571 @deftypevr {@code{method-access-controls} parameter} access-control-list access-controls
13572 Access control directives, as a list of strings. Each string should be
13573 one directive, such as "Order allow,deny".
13574
13575 Defaults to @samp{()}.
13576 @end deftypevr
13577 @end deftypevr
13578 @end deftypevr
13579
13580 @deftypevr {@code{cups-configuration} parameter} non-negative-integer log-debug-history
13581 Specifies the number of debugging messages that are retained for logging
13582 if an error occurs in a print job. Debug messages are logged regardless
13583 of the LogLevel setting.
13584
13585 Defaults to @samp{100}.
13586 @end deftypevr
13587
13588 @deftypevr {@code{cups-configuration} parameter} log-level log-level
13589 Specifies the level of logging for the ErrorLog file. The value
13590 @code{none} stops all logging while @code{debug2} logs everything.
13591
13592 Defaults to @samp{info}.
13593 @end deftypevr
13594
13595 @deftypevr {@code{cups-configuration} parameter} log-time-format log-time-format
13596 Specifies the format of the date and time in the log files. The value
13597 @code{standard} logs whole seconds while @code{usecs} logs microseconds.
13598
13599 Defaults to @samp{standard}.
13600 @end deftypevr
13601
13602 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients
13603 Specifies the maximum number of simultaneous clients that are allowed by
13604 the scheduler.
13605
13606 Defaults to @samp{100}.
13607 @end deftypevr
13608
13609 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients-per-host
13610 Specifies the maximum number of simultaneous clients that are allowed
13611 from a single address.
13612
13613 Defaults to @samp{100}.
13614 @end deftypevr
13615
13616 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-copies
13617 Specifies the maximum number of copies that a user can print of each
13618 job.
13619
13620 Defaults to @samp{9999}.
13621 @end deftypevr
13622
13623 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-hold-time
13624 Specifies the maximum time a job may remain in the @code{indefinite}
13625 hold state before it is canceled. A value of 0 disables cancellation of
13626 held jobs.
13627
13628 Defaults to @samp{0}.
13629 @end deftypevr
13630
13631 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs
13632 Specifies the maximum number of simultaneous jobs that are allowed. Set
13633 to 0 to allow an unlimited number of jobs.
13634
13635 Defaults to @samp{500}.
13636 @end deftypevr
13637
13638 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-printer
13639 Specifies the maximum number of simultaneous jobs that are allowed per
13640 printer. A value of 0 allows up to MaxJobs jobs per printer.
13641
13642 Defaults to @samp{0}.
13643 @end deftypevr
13644
13645 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-user
13646 Specifies the maximum number of simultaneous jobs that are allowed per
13647 user. A value of 0 allows up to MaxJobs jobs per user.
13648
13649 Defaults to @samp{0}.
13650 @end deftypevr
13651
13652 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-job-time
13653 Specifies the maximum time a job may take to print before it is
13654 canceled, in seconds. Set to 0 to disable cancellation of "stuck" jobs.
13655
13656 Defaults to @samp{10800}.
13657 @end deftypevr
13658
13659 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-log-size
13660 Specifies the maximum size of the log files before they are rotated, in
13661 bytes. The value 0 disables log rotation.
13662
13663 Defaults to @samp{1048576}.
13664 @end deftypevr
13665
13666 @deftypevr {@code{cups-configuration} parameter} non-negative-integer multiple-operation-timeout
13667 Specifies the maximum amount of time to allow between files in a
13668 multiple file print job, in seconds.
13669
13670 Defaults to @samp{300}.
13671 @end deftypevr
13672
13673 @deftypevr {@code{cups-configuration} parameter} string page-log-format
13674 Specifies the format of PageLog lines. Sequences beginning with percent
13675 (@samp{%}) characters are replaced with the corresponding information,
13676 while all other characters are copied literally. The following percent
13677 sequences are recognized:
13678
13679 @table @samp
13680 @item %%
13681 insert a single percent character
13682
13683 @item %@{name@}
13684 insert the value of the specified IPP attribute
13685
13686 @item %C
13687 insert the number of copies for the current page
13688
13689 @item %P
13690 insert the current page number
13691
13692 @item %T
13693 insert the current date and time in common log format
13694
13695 @item %j
13696 insert the job ID
13697
13698 @item %p
13699 insert the printer name
13700
13701 @item %u
13702 insert the username
13703 @end table
13704
13705 A value of the empty string disables page logging. The string @code{%p
13706 %u %j %T %P %C %@{job-billing@} %@{job-originating-host-name@}
13707 %@{job-name@} %@{media@} %@{sides@}} creates a page log with the
13708 standard items.
13709
13710 Defaults to @samp{""}.
13711 @end deftypevr
13712
13713 @deftypevr {@code{cups-configuration} parameter} environment-variables environment-variables
13714 Passes the specified environment variable(s) to child processes; a list
13715 of strings.
13716
13717 Defaults to @samp{()}.
13718 @end deftypevr
13719
13720 @deftypevr {@code{cups-configuration} parameter} policy-configuration-list policies
13721 Specifies named access control policies.
13722
13723 Available @code{policy-configuration} fields are:
13724
13725 @deftypevr {@code{policy-configuration} parameter} string name
13726 Name of the policy.
13727 @end deftypevr
13728
13729 @deftypevr {@code{policy-configuration} parameter} string job-private-access
13730 Specifies an access list for a job's private values. @code{@@ACL} maps
13731 to the printer's requesting-user-name-allowed or
13732 requesting-user-name-denied values. @code{@@OWNER} maps to the job's
13733 owner. @code{@@SYSTEM} maps to the groups listed for the
13734 @code{system-group} field of the @code{files-config} configuration,
13735 which is reified into the @code{cups-files.conf(5)} file. Other
13736 possible elements of the access list include specific user names, and
13737 @code{@@@var{group}} to indicate members of a specific group. The
13738 access list may also be simply @code{all} or @code{default}.
13739
13740 Defaults to @samp{"@@OWNER @@SYSTEM"}.
13741 @end deftypevr
13742
13743 @deftypevr {@code{policy-configuration} parameter} string job-private-values
13744 Specifies the list of job values to make private, or @code{all},
13745 @code{default}, or @code{none}.
13746
13747 Defaults to @samp{"job-name job-originating-host-name
13748 job-originating-user-name phone"}.
13749 @end deftypevr
13750
13751 @deftypevr {@code{policy-configuration} parameter} string subscription-private-access
13752 Specifies an access list for a subscription's private values.
13753 @code{@@ACL} maps to the printer's requesting-user-name-allowed or
13754 requesting-user-name-denied values. @code{@@OWNER} maps to the job's
13755 owner. @code{@@SYSTEM} maps to the groups listed for the
13756 @code{system-group} field of the @code{files-config} configuration,
13757 which is reified into the @code{cups-files.conf(5)} file. Other
13758 possible elements of the access list include specific user names, and
13759 @code{@@@var{group}} to indicate members of a specific group. The
13760 access list may also be simply @code{all} or @code{default}.
13761
13762 Defaults to @samp{"@@OWNER @@SYSTEM"}.
13763 @end deftypevr
13764
13765 @deftypevr {@code{policy-configuration} parameter} string subscription-private-values
13766 Specifies the list of job values to make private, or @code{all},
13767 @code{default}, or @code{none}.
13768
13769 Defaults to @samp{"notify-events notify-pull-method notify-recipient-uri
13770 notify-subscriber-user-name notify-user-data"}.
13771 @end deftypevr
13772
13773 @deftypevr {@code{policy-configuration} parameter} operation-access-control-list access-controls
13774 Access control by IPP operation.
13775
13776 Defaults to @samp{()}.
13777 @end deftypevr
13778 @end deftypevr
13779
13780 @deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-files
13781 Specifies whether job files (documents) are preserved after a job is
13782 printed. If a numeric value is specified, job files are preserved for
13783 the indicated number of seconds after printing. Otherwise a boolean
13784 value applies indefinitely.
13785
13786 Defaults to @samp{86400}.
13787 @end deftypevr
13788
13789 @deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-history
13790 Specifies whether the job history is preserved after a job is printed.
13791 If a numeric value is specified, the job history is preserved for the
13792 indicated number of seconds after printing. If @code{#t}, the job
13793 history is preserved until the MaxJobs limit is reached.
13794
13795 Defaults to @samp{#t}.
13796 @end deftypevr
13797
13798 @deftypevr {@code{cups-configuration} parameter} non-negative-integer reload-timeout
13799 Specifies the amount of time to wait for job completion before
13800 restarting the scheduler.
13801
13802 Defaults to @samp{30}.
13803 @end deftypevr
13804
13805 @deftypevr {@code{cups-configuration} parameter} string rip-cache
13806 Specifies the maximum amount of memory to use when converting documents
13807 into bitmaps for a printer.
13808
13809 Defaults to @samp{"128m"}.
13810 @end deftypevr
13811
13812 @deftypevr {@code{cups-configuration} parameter} string server-admin
13813 Specifies the email address of the server administrator.
13814
13815 Defaults to @samp{"root@@localhost.localdomain"}.
13816 @end deftypevr
13817
13818 @deftypevr {@code{cups-configuration} parameter} host-name-list-or-* server-alias
13819 The ServerAlias directive is used for HTTP Host header validation when
13820 clients connect to the scheduler from external interfaces. Using the
13821 special name @code{*} can expose your system to known browser-based DNS
13822 rebinding attacks, even when accessing sites through a firewall. If the
13823 auto-discovery of alternate names does not work, we recommend listing
13824 each alternate name with a ServerAlias directive instead of using
13825 @code{*}.
13826
13827 Defaults to @samp{*}.
13828 @end deftypevr
13829
13830 @deftypevr {@code{cups-configuration} parameter} string server-name
13831 Specifies the fully-qualified host name of the server.
13832
13833 Defaults to @samp{"localhost"}.
13834 @end deftypevr
13835
13836 @deftypevr {@code{cups-configuration} parameter} server-tokens server-tokens
13837 Specifies what information is included in the Server header of HTTP
13838 responses. @code{None} disables the Server header. @code{ProductOnly}
13839 reports @code{CUPS}. @code{Major} reports @code{CUPS 2}. @code{Minor}
13840 reports @code{CUPS 2.0}. @code{Minimal} reports @code{CUPS 2.0.0}.
13841 @code{OS} reports @code{CUPS 2.0.0 (@var{uname})} where @var{uname} is
13842 the output of the @code{uname} command. @code{Full} reports @code{CUPS
13843 2.0.0 (@var{uname}) IPP/2.0}.
13844
13845 Defaults to @samp{Minimal}.
13846 @end deftypevr
13847
13848 @deftypevr {@code{cups-configuration} parameter} string set-env
13849 Set the specified environment variable to be passed to child processes.
13850
13851 Defaults to @samp{"variable value"}.
13852 @end deftypevr
13853
13854 @deftypevr {@code{cups-configuration} parameter} multiline-string-list ssl-listen
13855 Listens on the specified interfaces for encrypted connections. Valid
13856 values are of the form @var{address}:@var{port}, where @var{address} is
13857 either an IPv6 address enclosed in brackets, an IPv4 address, or
13858 @code{*} to indicate all addresses.
13859
13860 Defaults to @samp{()}.
13861 @end deftypevr
13862
13863 @deftypevr {@code{cups-configuration} parameter} ssl-options ssl-options
13864 Sets encryption options. By default, CUPS only supports encryption
13865 using TLS v1.0 or higher using known secure cipher suites. The
13866 @code{AllowRC4} option enables the 128-bit RC4 cipher suites, which are
13867 required for some older clients that do not implement newer ones. The
13868 @code{AllowSSL3} option enables SSL v3.0, which is required for some
13869 older clients that do not support TLS v1.0.
13870
13871 Defaults to @samp{()}.
13872 @end deftypevr
13873
13874 @deftypevr {@code{cups-configuration} parameter} boolean strict-conformance?
13875 Specifies whether the scheduler requires clients to strictly adhere to
13876 the IPP specifications.
13877
13878 Defaults to @samp{#f}.
13879 @end deftypevr
13880
13881 @deftypevr {@code{cups-configuration} parameter} non-negative-integer timeout
13882 Specifies the HTTP request timeout, in seconds.
13883
13884 Defaults to @samp{300}.
13885
13886 @end deftypevr
13887
13888 @deftypevr {@code{cups-configuration} parameter} boolean web-interface?
13889 Specifies whether the web interface is enabled.
13890
13891 Defaults to @samp{#f}.
13892 @end deftypevr
13893
13894 At this point you're probably thinking ``oh dear, Guix manual, I like
13895 you but you can stop already with the configuration options''. Indeed.
13896 However, one more point: it could be that you have an existing
13897 @code{cupsd.conf} that you want to use. In that case, you can pass an
13898 @code{opaque-cups-configuration} as the configuration of a
13899 @code{cups-service-type}.
13900
13901 Available @code{opaque-cups-configuration} fields are:
13902
13903 @deftypevr {@code{opaque-cups-configuration} parameter} package cups
13904 The CUPS package.
13905 @end deftypevr
13906
13907 @deftypevr {@code{opaque-cups-configuration} parameter} string cupsd.conf
13908 The contents of the @code{cupsd.conf}, as a string.
13909 @end deftypevr
13910
13911 @deftypevr {@code{opaque-cups-configuration} parameter} string cups-files.conf
13912 The contents of the @code{cups-files.conf} file, as a string.
13913 @end deftypevr
13914
13915 For example, if your @code{cupsd.conf} and @code{cups-files.conf} are in
13916 strings of the same name, you could instantiate a CUPS service like
13917 this:
13918
13919 @example
13920 (service cups-service-type
13921 (opaque-cups-configuration
13922 (cupsd.conf cupsd.conf)
13923 (cups-files.conf cups-files.conf)))
13924 @end example
13925
13926
13927 @node Desktop Services
13928 @subsubsection Desktop Services
13929
13930 The @code{(gnu services desktop)} module provides services that are
13931 usually useful in the context of a ``desktop'' setup---that is, on a
13932 machine running a graphical display server, possibly with graphical user
13933 interfaces, etc. It also defines services that provide specific desktop
13934 environments like GNOME, XFCE or MATE.
13935
13936 To simplify things, the module defines a variable containing the set of
13937 services that users typically expect on a machine with a graphical
13938 environment and networking:
13939
13940 @defvr {Scheme Variable} %desktop-services
13941 This is a list of services that builds upon @var{%base-services} and
13942 adds or adjusts services for a typical ``desktop'' setup.
13943
13944 In particular, it adds a graphical login manager (@pxref{X Window,
13945 @code{slim-service}}), screen lockers, a network management tool
13946 (@pxref{Networking Services, @code{network-manager-service-type}}), energy and color
13947 management services, the @code{elogind} login and seat manager, the
13948 Polkit privilege service, the GeoClue location service, the
13949 AccountsService daemon that allows authorized users change system
13950 passwords, an NTP client (@pxref{Networking Services}), the Avahi
13951 daemon, and has the name service switch service configured to be able to
13952 use @code{nss-mdns} (@pxref{Name Service Switch, mDNS}).
13953 @end defvr
13954
13955 The @var{%desktop-services} variable can be used as the @code{services}
13956 field of an @code{operating-system} declaration (@pxref{operating-system
13957 Reference, @code{services}}).
13958
13959 Additionally, the @code{gnome-desktop-service},
13960 @code{xfce-desktop-service}, @code{mate-desktop-service} and
13961 @code{enlightenment-desktop-service-type} procedures can add GNOME, XFCE, MATE
13962 and/or Enlightenment to a system. To ``add GNOME'' means that system-level
13963 services like the backlight adjustment helpers and the power management
13964 utilities are added to the system, extending @code{polkit} and @code{dbus}
13965 appropriately, allowing GNOME to operate with elevated privileges on a
13966 limited number of special-purpose system interfaces. Additionally,
13967 adding a service made by @code{gnome-desktop-service} adds the GNOME
13968 metapackage to the system profile. Likewise, adding the XFCE service
13969 not only adds the @code{xfce} metapackage to the system profile, but it
13970 also gives the Thunar file manager the ability to open a ``root-mode''
13971 file management window, if the user authenticates using the
13972 administrator's password via the standard polkit graphical interface.
13973 To ``add MATE'' means that @code{polkit} and @code{dbus} are extended
13974 appropriately, allowing MATE to operate with elevated privileges on a
13975 limited number of special-purpose system interfaces. Additionally,
13976 adding a service made by @code{mate-desktop-service} adds the MATE
13977 metapackage to the system profile. ``Adding ENLIGHTENMENT'' means that
13978 @code{dbus} is extended appropriately, and several of Enlightenment's binaries
13979 are set as setuid, allowing Enlightenment's screen locker and other
13980 functionality to work as expetected.
13981
13982 The desktop environments in Guix use the Xorg display server by
13983 default. If you'd like to use the newer display server protocol
13984 called Wayland, you need to use the @code{sddm-service} instead of the
13985 @code{slim-service} for the graphical login manager. You should then
13986 select the ``GNOME (Wayland)'' session in SDDM. Alternatively you can
13987 also try starting GNOME on Wayland manually from a TTY with the
13988 command ``XDG_SESSION_TYPE=wayland exec dbus-run-session
13989 gnome-session``. Currently only GNOME has support for Wayland.
13990
13991 @deffn {Scheme Procedure} gnome-desktop-service
13992 Return a service that adds the @code{gnome} package to the system
13993 profile, and extends polkit with the actions from
13994 @code{gnome-settings-daemon}.
13995 @end deffn
13996
13997 @deffn {Scheme Procedure} xfce-desktop-service
13998 Return a service that adds the @code{xfce} package to the system profile,
13999 and extends polkit with the ability for @code{thunar} to manipulate the
14000 file system as root from within a user session, after the user has
14001 authenticated with the administrator's password.
14002 @end deffn
14003
14004 @deffn {Scheme Procedure} mate-desktop-service
14005 Return a service that adds the @code{mate} package to the system
14006 profile, and extends polkit with the actions from
14007 @code{mate-settings-daemon}.
14008 @end deffn
14009
14010 @deffn {Scheme Procedure} enlightenment-desktop-service-type
14011 Return a service that adds the @code{enlightenment} package to the system
14012 profile, and extends dbus with actions from @code{efl}.
14013 @end deffn
14014
14015 @deftp {Data Type} enlightenment-desktop-service-configuration
14016 @table @asis
14017 @item @code{enlightenment} (default @code{enlightenment})
14018 The enlightenment package to use.
14019 @end table
14020 @end deftp
14021
14022 Because the GNOME, XFCE and MATE desktop services pull in so many packages,
14023 the default @code{%desktop-services} variable doesn't include any of
14024 them by default. To add GNOME, XFCE or MATE, just @code{cons} them onto
14025 @code{%desktop-services} in the @code{services} field of your
14026 @code{operating-system}:
14027
14028 @example
14029 (use-modules (gnu))
14030 (use-service-modules desktop)
14031 (operating-system
14032 ...
14033 ;; cons* adds items to the list given as its last argument.
14034 (services (cons* (gnome-desktop-service)
14035 (xfce-desktop-service)
14036 %desktop-services))
14037 ...)
14038 @end example
14039
14040 These desktop environments will then be available as options in the
14041 graphical login window.
14042
14043 The actual service definitions included in @code{%desktop-services} and
14044 provided by @code{(gnu services dbus)} and @code{(gnu services desktop)}
14045 are described below.
14046
14047 @deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
14048 Return a service that runs the ``system bus'', using @var{dbus}, with
14049 support for @var{services}.
14050
14051 @uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
14052 facility. Its system bus is used to allow system services to communicate
14053 and to be notified of system-wide events.
14054
14055 @var{services} must be a list of packages that provide an
14056 @file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
14057 and policy files. For example, to allow avahi-daemon to use the system bus,
14058 @var{services} must be equal to @code{(list avahi)}.
14059 @end deffn
14060
14061 @deffn {Scheme Procedure} elogind-service [#:config @var{config}]
14062 Return a service that runs the @code{elogind} login and
14063 seat management daemon. @uref{https://github.com/elogind/elogind,
14064 Elogind} exposes a D-Bus interface that can be used to know which users
14065 are logged in, know what kind of sessions they have open, suspend the
14066 system, inhibit system suspend, reboot the system, and other tasks.
14067
14068 Elogind handles most system-level power events for a computer, for
14069 example suspending the system when a lid is closed, or shutting it down
14070 when the power button is pressed.
14071
14072 The @var{config} keyword argument specifies the configuration for
14073 elogind, and should be the result of an @code{(elogind-configuration
14074 (@var{parameter} @var{value})...)} invocation. Available parameters and
14075 their default values are:
14076
14077 @table @code
14078 @item kill-user-processes?
14079 @code{#f}
14080 @item kill-only-users
14081 @code{()}
14082 @item kill-exclude-users
14083 @code{("root")}
14084 @item inhibit-delay-max-seconds
14085 @code{5}
14086 @item handle-power-key
14087 @code{poweroff}
14088 @item handle-suspend-key
14089 @code{suspend}
14090 @item handle-hibernate-key
14091 @code{hibernate}
14092 @item handle-lid-switch
14093 @code{suspend}
14094 @item handle-lid-switch-docked
14095 @code{ignore}
14096 @item power-key-ignore-inhibited?
14097 @code{#f}
14098 @item suspend-key-ignore-inhibited?
14099 @code{#f}
14100 @item hibernate-key-ignore-inhibited?
14101 @code{#f}
14102 @item lid-switch-ignore-inhibited?
14103 @code{#t}
14104 @item holdoff-timeout-seconds
14105 @code{30}
14106 @item idle-action
14107 @code{ignore}
14108 @item idle-action-seconds
14109 @code{(* 30 60)}
14110 @item runtime-directory-size-percent
14111 @code{10}
14112 @item runtime-directory-size
14113 @code{#f}
14114 @item remove-ipc?
14115 @code{#t}
14116 @item suspend-state
14117 @code{("mem" "standby" "freeze")}
14118 @item suspend-mode
14119 @code{()}
14120 @item hibernate-state
14121 @code{("disk")}
14122 @item hibernate-mode
14123 @code{("platform" "shutdown")}
14124 @item hybrid-sleep-state
14125 @code{("disk")}
14126 @item hybrid-sleep-mode
14127 @code{("suspend" "platform" "shutdown")}
14128 @end table
14129 @end deffn
14130
14131 @deffn {Scheme Procedure} accountsservice-service @
14132 [#:accountsservice @var{accountsservice}]
14133 Return a service that runs AccountsService, a system service that can
14134 list available accounts, change their passwords, and so on.
14135 AccountsService integrates with PolicyKit to enable unprivileged users
14136 to acquire the capability to modify their system configuration.
14137 @uref{https://www.freedesktop.org/wiki/Software/AccountsService/, the
14138 accountsservice web site} for more information.
14139
14140 The @var{accountsservice} keyword argument is the @code{accountsservice}
14141 package to expose as a service.
14142 @end deffn
14143
14144 @deffn {Scheme Procedure} polkit-service @
14145 [#:polkit @var{polkit}]
14146 Return a service that runs the
14147 @uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
14148 management service}, which allows system administrators to grant access to
14149 privileged operations in a structured way. By querying the Polkit service, a
14150 privileged system component can know when it should grant additional
14151 capabilities to ordinary users. For example, an ordinary user can be granted
14152 the capability to suspend the system if the user is logged in locally.
14153 @end deffn
14154
14155 @deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
14156 [#:watts-up-pro? #f] @
14157 [#:poll-batteries? #t] @
14158 [#:ignore-lid? #f] @
14159 [#:use-percentage-for-policy? #f] @
14160 [#:percentage-low 10] @
14161 [#:percentage-critical 3] @
14162 [#:percentage-action 2] @
14163 [#:time-low 1200] @
14164 [#:time-critical 300] @
14165 [#:time-action 120] @
14166 [#:critical-power-action 'hybrid-sleep]
14167 Return a service that runs @uref{http://upower.freedesktop.org/,
14168 @command{upowerd}}, a system-wide monitor for power consumption and battery
14169 levels, with the given configuration settings. It implements the
14170 @code{org.freedesktop.UPower} D-Bus interface, and is notably used by
14171 GNOME.
14172 @end deffn
14173
14174 @deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
14175 Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
14176 UDisks}, a @dfn{disk management} daemon that provides user interfaces with
14177 notifications and ways to mount/unmount disks. Programs that talk to UDisks
14178 include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
14179 @end deffn
14180
14181 @deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
14182 Return a service that runs @command{colord}, a system service with a D-Bus
14183 interface to manage the color profiles of input and output devices such as
14184 screens and scanners. It is notably used by the GNOME Color Manager graphical
14185 tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
14186 site} for more information.
14187 @end deffn
14188
14189 @deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
14190 Return a configuration allowing an application to access GeoClue
14191 location data. @var{name} is the Desktop ID of the application, without
14192 the @code{.desktop} part. If @var{allowed?} is true, the application
14193 will have access to location information by default. The boolean
14194 @var{system?} value indicates whether an application is a system component
14195 or not. Finally @var{users} is a list of UIDs of all users for which
14196 this application is allowed location info access. An empty users list
14197 means that all users are allowed.
14198 @end deffn
14199
14200 @defvr {Scheme Variable} %standard-geoclue-applications
14201 The standard list of well-known GeoClue application configurations,
14202 granting authority to the GNOME date-and-time utility to ask for the
14203 current location in order to set the time zone, and allowing the
14204 IceCat and Epiphany web browsers to request location information.
14205 IceCat and Epiphany both query the user before allowing a web page to
14206 know the user's location.
14207 @end defvr
14208
14209 @deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
14210 [#:whitelist '()] @
14211 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
14212 [#:submit-data? #f]
14213 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
14214 [#:submission-nick "geoclue"] @
14215 [#:applications %standard-geoclue-applications]
14216 Return a service that runs the GeoClue location service. This service
14217 provides a D-Bus interface to allow applications to request access to a
14218 user's physical location, and optionally to add information to online
14219 location databases. See
14220 @uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
14221 web site} for more information.
14222 @end deffn
14223
14224 @deffn {Scheme Procedure} bluetooth-service [#:bluez @var{bluez}] @
14225 [@w{#:auto-enable? #f}]
14226 Return a service that runs the @command{bluetoothd} daemon, which
14227 manages all the Bluetooth devices and provides a number of D-Bus
14228 interfaces. When AUTO-ENABLE? is true, the bluetooth controller is
14229 powered automatically at boot, which can be useful when using a
14230 bluetooth keyboard or mouse.
14231
14232 Users need to be in the @code{lp} group to access the D-Bus service.
14233 @end deffn
14234
14235 @node Sound Services
14236 @subsubsection Sound Services
14237
14238 @cindex sound support
14239 @cindex ALSA
14240 @cindex PulseAudio, sound support
14241
14242 The @code{(gnu services sound)} module provides a service to configure the
14243 Advanced Linux Sound Architecture (ALSA) system, which makes PulseAudio the
14244 preferred ALSA output driver.
14245
14246 @deffn {Scheme Variable} alsa-service-type
14247 This is the type for the @uref{https://alsa-project.org/, Advanced Linux Sound
14248 Architecture} (ALSA) system, which generates the @file{/etc/asound.conf}
14249 configuration file. The value for this type is a @command{alsa-configuration}
14250 record as in this example:
14251
14252 @example
14253 (service alsa-service-type)
14254 @end example
14255
14256 See below for details about @code{alsa-configuration}.
14257 @end deffn
14258
14259 @deftp {Data Type} alsa-configuration
14260 Data type representing the configuration for @code{alsa-service}.
14261
14262 @table @asis
14263 @item @code{alsa-plugins} (default: @var{alsa-plugins})
14264 @code{alsa-plugins} package to use.
14265
14266 @item @code{pulseaudio?} (default: @var{#t})
14267 Whether ALSA applications should transparently be made to use the
14268 @uref{http://www.pulseaudio.org/, PulseAudio} sound server.
14269
14270 Using PulseAudio allows you to run several sound-producing applications
14271 at the same time and to individual control them @i{via}
14272 @command{pavucontrol}, among other things.
14273
14274 @item @code{extra-options} (default: @var{""})
14275 String to append to the @file{/etc/asound.conf} file.
14276
14277 @end table
14278 @end deftp
14279
14280 Individual users who want to override the system configuration of ALSA can do
14281 it with the @file{~/.asoundrc} file:
14282
14283 @example
14284 # In guix, we have to specify the absolute path for plugins.
14285 pcm_type.jack @{
14286 lib "/home/alice/.guix-profile/lib/alsa-lib/libasound_module_pcm_jack.so"
14287 @}
14288
14289 # Routing ALSA to jack:
14290 # <http://jackaudio.org/faq/routing_alsa.html>.
14291 pcm.rawjack @{
14292 type jack
14293 playback_ports @{
14294 0 system:playback_1
14295 1 system:playback_2
14296 @}
14297
14298 capture_ports @{
14299 0 system:capture_1
14300 1 system:capture_2
14301 @}
14302 @}
14303
14304 pcm.!default @{
14305 type plug
14306 slave @{
14307 pcm "rawjack"
14308 @}
14309 @}
14310 @end example
14311
14312 See @uref{https://www.alsa-project.org/main/index.php/Asoundrc} for the
14313 details.
14314
14315
14316 @node Database Services
14317 @subsubsection Database Services
14318
14319 @cindex database
14320 @cindex SQL
14321 The @code{(gnu services databases)} module provides the following services.
14322
14323 @deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
14324 [#:config-file] [#:data-directory ``/var/lib/postgresql/data''] @
14325 [#:port 5432] [#:locale ``en_US.utf8'']
14326 Return a service that runs @var{postgresql}, the PostgreSQL database
14327 server.
14328
14329 The PostgreSQL daemon loads its runtime configuration from @var{config-file},
14330 creates a database cluster with @var{locale} as the default
14331 locale, stored in @var{data-directory}. It then listens on @var{port}.
14332 @end deffn
14333
14334 @deffn {Scheme Procedure} mysql-service [#:config (mysql-configuration)]
14335 Return a service that runs @command{mysqld}, the MySQL or MariaDB
14336 database server.
14337
14338 The optional @var{config} argument specifies the configuration for
14339 @command{mysqld}, which should be a @code{<mysql-configuration>} object.
14340 @end deffn
14341
14342 @deftp {Data Type} mysql-configuration
14343 Data type representing the configuration of @var{mysql-service}.
14344
14345 @table @asis
14346 @item @code{mysql} (default: @var{mariadb})
14347 Package object of the MySQL database server, can be either @var{mariadb}
14348 or @var{mysql}.
14349
14350 For MySQL, a temporary root password will be displayed at activation time.
14351 For MariaDB, the root password is empty.
14352
14353 @item @code{port} (default: @code{3306})
14354 TCP port on which the database server listens for incoming connections.
14355 @end table
14356 @end deftp
14357
14358 @defvr {Scheme Variable} memcached-service-type
14359 This is the service type for the @uref{https://memcached.org/,
14360 Memcached} service, which provides a distributed in memory cache. The
14361 value for the service type is a @code{memcached-configuration} object.
14362 @end defvr
14363
14364 @example
14365 (service memcached-service-type)
14366 @end example
14367
14368 @deftp {Data Type} memcached-configuration
14369 Data type representing the configuration of memcached.
14370
14371 @table @asis
14372 @item @code{memcached} (default: @code{memcached})
14373 The Memcached package to use.
14374
14375 @item @code{interfaces} (default: @code{'("0.0.0.0")})
14376 Network interfaces on which to listen.
14377
14378 @item @code{tcp-port} (default: @code{11211})
14379 Port on which to accept connections on,
14380
14381 @item @code{udp-port} (default: @code{11211})
14382 Port on which to accept UDP connections on, a value of 0 will disable
14383 listening on a UDP socket.
14384
14385 @item @code{additional-options} (default: @code{'()})
14386 Additional command line options to pass to @code{memcached}.
14387 @end table
14388 @end deftp
14389
14390 @defvr {Scheme Variable} mongodb-service-type
14391 This is the service type for @uref{https://www.mongodb.com/, MongoDB}.
14392 The value for the service type is a @code{mongodb-configuration} object.
14393 @end defvr
14394
14395 @example
14396 (service mongodb-service-type)
14397 @end example
14398
14399 @deftp {Data Type} mongodb-configuration
14400 Data type representing the configuration of mongodb.
14401
14402 @table @asis
14403 @item @code{mongodb} (default: @code{mongodb})
14404 The MongoDB package to use.
14405
14406 @item @code{config-file} (default: @code{%default-mongodb-configuration-file})
14407 The configuration file for MongoDB.
14408
14409 @item @code{data-directory} (default: @code{"/var/lib/mongodb"})
14410 This value is used to create the directory, so that it exists and is
14411 owned by the mongodb user. It should match the data-directory which
14412 MongoDB is configured to use through the configuration file.
14413 @end table
14414 @end deftp
14415
14416 @defvr {Scheme Variable} redis-service-type
14417 This is the service type for the @uref{https://redis.io/, Redis}
14418 key/value store, whose value is a @code{redis-configuration} object.
14419 @end defvr
14420
14421 @deftp {Data Type} redis-configuration
14422 Data type representing the configuration of redis.
14423
14424 @table @asis
14425 @item @code{redis} (default: @code{redis})
14426 The Redis package to use.
14427
14428 @item @code{bind} (default: @code{"127.0.0.1"})
14429 Network interface on which to listen.
14430
14431 @item @code{port} (default: @code{6379})
14432 Port on which to accept connections on, a value of 0 will disable
14433 listening on a TCP socket.
14434
14435 @item @code{working-directory} (default: @code{"/var/lib/redis"})
14436 Directory in which to store the database and related files.
14437 @end table
14438 @end deftp
14439
14440 @node Mail Services
14441 @subsubsection Mail Services
14442
14443 @cindex mail
14444 @cindex email
14445 The @code{(gnu services mail)} module provides Guix service definitions
14446 for email services: IMAP, POP3, and LMTP servers, as well as mail
14447 transport agents (MTAs). Lots of acronyms! These services are detailed
14448 in the subsections below.
14449
14450 @subsubheading Dovecot Service
14451
14452 @deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
14453 Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
14454 @end deffn
14455
14456 By default, Dovecot does not need much configuration; the default
14457 configuration object created by @code{(dovecot-configuration)} will
14458 suffice if your mail is delivered to @code{~/Maildir}. A self-signed
14459 certificate will be generated for TLS-protected connections, though
14460 Dovecot will also listen on cleartext ports by default. There are a
14461 number of options, though, which mail administrators might need to change,
14462 and as is the case with other services, Guix allows the system
14463 administrator to specify these parameters via a uniform Scheme interface.
14464
14465 For example, to specify that mail is located at @code{maildir~/.mail},
14466 one would instantiate the Dovecot service like this:
14467
14468 @example
14469 (dovecot-service #:config
14470 (dovecot-configuration
14471 (mail-location "maildir:~/.mail")))
14472 @end example
14473
14474 The available configuration parameters follow. Each parameter
14475 definition is preceded by its type; for example, @samp{string-list foo}
14476 indicates that the @code{foo} parameter should be specified as a list of
14477 strings. There is also a way to specify the configuration as a string,
14478 if you have an old @code{dovecot.conf} file that you want to port over
14479 from some other system; see the end for more details.
14480
14481 @c The following documentation was initially generated by
14482 @c (generate-documentation) in (gnu services mail). Manually maintained
14483 @c documentation is better, so we shouldn't hesitate to edit below as
14484 @c needed. However if the change you want to make to this documentation
14485 @c can be done in an automated way, it's probably easier to change
14486 @c (generate-documentation) than to make it below and have to deal with
14487 @c the churn as dovecot updates.
14488
14489 Available @code{dovecot-configuration} fields are:
14490
14491 @deftypevr {@code{dovecot-configuration} parameter} package dovecot
14492 The dovecot package.
14493 @end deftypevr
14494
14495 @deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
14496 A list of IPs or hosts where to listen for connections. @samp{*}
14497 listens on all IPv4 interfaces, @samp{::} listens on all IPv6
14498 interfaces. If you want to specify non-default ports or anything more
14499 complex, customize the address and port fields of the
14500 @samp{inet-listener} of the specific services you are interested in.
14501 @end deftypevr
14502
14503 @deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
14504 List of protocols we want to serve. Available protocols include
14505 @samp{imap}, @samp{pop3}, and @samp{lmtp}.
14506
14507 Available @code{protocol-configuration} fields are:
14508
14509 @deftypevr {@code{protocol-configuration} parameter} string name
14510 The name of the protocol.
14511 @end deftypevr
14512
14513 @deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
14514 UNIX socket path to the master authentication server to find users.
14515 This is used by imap (for shared users) and lda.
14516 It defaults to @samp{"/var/run/dovecot/auth-userdb"}.
14517 @end deftypevr
14518
14519 @deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
14520 Space separated list of plugins to load.
14521 @end deftypevr
14522
14523 @deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
14524 Maximum number of IMAP connections allowed for a user from each IP
14525 address. NOTE: The username is compared case-sensitively.
14526 Defaults to @samp{10}.
14527 @end deftypevr
14528
14529 @end deftypevr
14530
14531 @deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
14532 List of services to enable. Available services include @samp{imap},
14533 @samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
14534 @samp{lmtp}.
14535
14536 Available @code{service-configuration} fields are:
14537
14538 @deftypevr {@code{service-configuration} parameter} string kind
14539 The service kind. Valid values include @code{director},
14540 @code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
14541 @code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
14542 @code{tcpwrap}, @code{quota-warning}, or anything else.
14543 @end deftypevr
14544
14545 @deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
14546 Listeners for the service. A listener is either a
14547 @code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
14548 an @code{inet-listener-configuration}.
14549 Defaults to @samp{()}.
14550
14551 Available @code{unix-listener-configuration} fields are:
14552
14553 @deftypevr {@code{unix-listener-configuration} parameter} string path
14554 Path to the file, relative to @code{base-dir} field. This is also used as
14555 the section name.
14556 @end deftypevr
14557
14558 @deftypevr {@code{unix-listener-configuration} parameter} string mode
14559 The access mode for the socket.
14560 Defaults to @samp{"0600"}.
14561 @end deftypevr
14562
14563 @deftypevr {@code{unix-listener-configuration} parameter} string user
14564 The user to own the socket.
14565 Defaults to @samp{""}.
14566 @end deftypevr
14567
14568 @deftypevr {@code{unix-listener-configuration} parameter} string group
14569 The group to own the socket.
14570 Defaults to @samp{""}.
14571 @end deftypevr
14572
14573
14574 Available @code{fifo-listener-configuration} fields are:
14575
14576 @deftypevr {@code{fifo-listener-configuration} parameter} string path
14577 Path to the file, relative to @code{base-dir} field. This is also used as
14578 the section name.
14579 @end deftypevr
14580
14581 @deftypevr {@code{fifo-listener-configuration} parameter} string mode
14582 The access mode for the socket.
14583 Defaults to @samp{"0600"}.
14584 @end deftypevr
14585
14586 @deftypevr {@code{fifo-listener-configuration} parameter} string user
14587 The user to own the socket.
14588 Defaults to @samp{""}.
14589 @end deftypevr
14590
14591 @deftypevr {@code{fifo-listener-configuration} parameter} string group
14592 The group to own the socket.
14593 Defaults to @samp{""}.
14594 @end deftypevr
14595
14596
14597 Available @code{inet-listener-configuration} fields are:
14598
14599 @deftypevr {@code{inet-listener-configuration} parameter} string protocol
14600 The protocol to listen for.
14601 @end deftypevr
14602
14603 @deftypevr {@code{inet-listener-configuration} parameter} string address
14604 The address on which to listen, or empty for all addresses.
14605 Defaults to @samp{""}.
14606 @end deftypevr
14607
14608 @deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
14609 The port on which to listen.
14610 @end deftypevr
14611
14612 @deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
14613 Whether to use SSL for this service; @samp{yes}, @samp{no}, or
14614 @samp{required}.
14615 Defaults to @samp{#t}.
14616 @end deftypevr
14617
14618 @end deftypevr
14619
14620 @deftypevr {@code{service-configuration} parameter} non-negative-integer client-limit
14621 Maximum number of simultaneous client connections per process. Once
14622 this number of connections is received, the next incoming connection
14623 will prompt Dovecot to spawn another process. If set to 0,
14624 @code{default-client-limit} is used instead.
14625
14626 Defaults to @samp{0}.
14627
14628 @end deftypevr
14629
14630 @deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
14631 Number of connections to handle before starting a new process.
14632 Typically the only useful values are 0 (unlimited) or 1. 1 is more
14633 secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
14634 Defaults to @samp{1}.
14635
14636 @end deftypevr
14637
14638 @deftypevr {@code{service-configuration} parameter} non-negative-integer process-limit
14639 Maximum number of processes that can exist for this service. If set to
14640 0, @code{default-process-limit} is used instead.
14641
14642 Defaults to @samp{0}.
14643
14644 @end deftypevr
14645
14646 @deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
14647 Number of processes to always keep waiting for more connections.
14648 Defaults to @samp{0}.
14649 @end deftypevr
14650
14651 @deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
14652 If you set @samp{service-count 0}, you probably need to grow
14653 this.
14654 Defaults to @samp{256000000}.
14655 @end deftypevr
14656
14657 @end deftypevr
14658
14659 @deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
14660 Dict configuration, as created by the @code{dict-configuration}
14661 constructor.
14662
14663 Available @code{dict-configuration} fields are:
14664
14665 @deftypevr {@code{dict-configuration} parameter} free-form-fields entries
14666 A list of key-value pairs that this dict should hold.
14667 Defaults to @samp{()}.
14668 @end deftypevr
14669
14670 @end deftypevr
14671
14672 @deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
14673 A list of passdb configurations, each one created by the
14674 @code{passdb-configuration} constructor.
14675
14676 Available @code{passdb-configuration} fields are:
14677
14678 @deftypevr {@code{passdb-configuration} parameter} string driver
14679 The driver that the passdb should use. Valid values include
14680 @samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
14681 @samp{static}.
14682 Defaults to @samp{"pam"}.
14683 @end deftypevr
14684
14685 @deftypevr {@code{passdb-configuration} parameter} space-separated-string-list args
14686 Space separated list of arguments to the passdb driver.
14687 Defaults to @samp{""}.
14688 @end deftypevr
14689
14690 @end deftypevr
14691
14692 @deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
14693 List of userdb configurations, each one created by the
14694 @code{userdb-configuration} constructor.
14695
14696 Available @code{userdb-configuration} fields are:
14697
14698 @deftypevr {@code{userdb-configuration} parameter} string driver
14699 The driver that the userdb should use. Valid values include
14700 @samp{passwd} and @samp{static}.
14701 Defaults to @samp{"passwd"}.
14702 @end deftypevr
14703
14704 @deftypevr {@code{userdb-configuration} parameter} space-separated-string-list args
14705 Space separated list of arguments to the userdb driver.
14706 Defaults to @samp{""}.
14707 @end deftypevr
14708
14709 @deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
14710 Override fields from passwd.
14711 Defaults to @samp{()}.
14712 @end deftypevr
14713
14714 @end deftypevr
14715
14716 @deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
14717 Plug-in configuration, created by the @code{plugin-configuration}
14718 constructor.
14719 @end deftypevr
14720
14721 @deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
14722 List of namespaces. Each item in the list is created by the
14723 @code{namespace-configuration} constructor.
14724
14725 Available @code{namespace-configuration} fields are:
14726
14727 @deftypevr {@code{namespace-configuration} parameter} string name
14728 Name for this namespace.
14729 @end deftypevr
14730
14731 @deftypevr {@code{namespace-configuration} parameter} string type
14732 Namespace type: @samp{private}, @samp{shared} or @samp{public}.
14733 Defaults to @samp{"private"}.
14734 @end deftypevr
14735
14736 @deftypevr {@code{namespace-configuration} parameter} string separator
14737 Hierarchy separator to use. You should use the same separator for
14738 all namespaces or some clients get confused. @samp{/} is usually a good
14739 one. The default however depends on the underlying mail storage
14740 format.
14741 Defaults to @samp{""}.
14742 @end deftypevr
14743
14744 @deftypevr {@code{namespace-configuration} parameter} string prefix
14745 Prefix required to access this namespace. This needs to be
14746 different for all namespaces. For example @samp{Public/}.
14747 Defaults to @samp{""}.
14748 @end deftypevr
14749
14750 @deftypevr {@code{namespace-configuration} parameter} string location
14751 Physical location of the mailbox. This is in the same format as
14752 mail_location, which is also the default for it.
14753 Defaults to @samp{""}.
14754 @end deftypevr
14755
14756 @deftypevr {@code{namespace-configuration} parameter} boolean inbox?
14757 There can be only one INBOX, and this setting defines which
14758 namespace has it.
14759 Defaults to @samp{#f}.
14760 @end deftypevr
14761
14762 @deftypevr {@code{namespace-configuration} parameter} boolean hidden?
14763 If namespace is hidden, it's not advertised to clients via NAMESPACE
14764 extension. You'll most likely also want to set @samp{list? #f}. This is mostly
14765 useful when converting from another server with different namespaces
14766 which you want to deprecate but still keep working. For example you can
14767 create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
14768 and @samp{mail/}.
14769 Defaults to @samp{#f}.
14770 @end deftypevr
14771
14772 @deftypevr {@code{namespace-configuration} parameter} boolean list?
14773 Show the mailboxes under this namespace with the LIST command. This
14774 makes the namespace visible for clients that do not support the NAMESPACE
14775 extension. The special @code{children} value lists child mailboxes, but
14776 hides the namespace prefix.
14777 Defaults to @samp{#t}.
14778 @end deftypevr
14779
14780 @deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
14781 Namespace handles its own subscriptions. If set to @code{#f}, the
14782 parent namespace handles them. The empty prefix should always have this
14783 as @code{#t}).
14784 Defaults to @samp{#t}.
14785 @end deftypevr
14786
14787 @deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
14788 List of predefined mailboxes in this namespace.
14789 Defaults to @samp{()}.
14790
14791 Available @code{mailbox-configuration} fields are:
14792
14793 @deftypevr {@code{mailbox-configuration} parameter} string name
14794 Name for this mailbox.
14795 @end deftypevr
14796
14797 @deftypevr {@code{mailbox-configuration} parameter} string auto
14798 @samp{create} will automatically create this mailbox.
14799 @samp{subscribe} will both create and subscribe to the mailbox.
14800 Defaults to @samp{"no"}.
14801 @end deftypevr
14802
14803 @deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
14804 List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
14805 Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
14806 @code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
14807 Defaults to @samp{()}.
14808 @end deftypevr
14809
14810 @end deftypevr
14811
14812 @end deftypevr
14813
14814 @deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
14815 Base directory where to store runtime data.
14816 Defaults to @samp{"/var/run/dovecot/"}.
14817 @end deftypevr
14818
14819 @deftypevr {@code{dovecot-configuration} parameter} string login-greeting
14820 Greeting message for clients.
14821 Defaults to @samp{"Dovecot ready."}.
14822 @end deftypevr
14823
14824 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
14825 List of trusted network ranges. Connections from these IPs are
14826 allowed to override their IP addresses and ports (for logging and for
14827 authentication checks). @samp{disable-plaintext-auth} is also ignored
14828 for these networks. Typically you would specify your IMAP proxy servers
14829 here.
14830 Defaults to @samp{()}.
14831 @end deftypevr
14832
14833 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
14834 List of login access check sockets (e.g.@: tcpwrap).
14835 Defaults to @samp{()}.
14836 @end deftypevr
14837
14838 @deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
14839 Show more verbose process titles (in ps). Currently shows user name
14840 and IP address. Useful for seeing who is actually using the IMAP
14841 processes (e.g.@: shared mailboxes or if the same uid is used for multiple
14842 accounts).
14843 Defaults to @samp{#f}.
14844 @end deftypevr
14845
14846 @deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
14847 Should all processes be killed when Dovecot master process shuts down.
14848 Setting this to @code{#f} means that Dovecot can be upgraded without
14849 forcing existing client connections to close (although that could also
14850 be a problem if the upgrade is e.g.@: due to a security fix).
14851 Defaults to @samp{#t}.
14852 @end deftypevr
14853
14854 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
14855 If non-zero, run mail commands via this many connections to doveadm
14856 server, instead of running them directly in the same process.
14857 Defaults to @samp{0}.
14858 @end deftypevr
14859
14860 @deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
14861 UNIX socket or host:port used for connecting to doveadm server.
14862 Defaults to @samp{"doveadm-server"}.
14863 @end deftypevr
14864
14865 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
14866 List of environment variables that are preserved on Dovecot startup
14867 and passed down to all of its child processes. You can also give
14868 key=value pairs to always set specific settings.
14869 @end deftypevr
14870
14871 @deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
14872 Disable LOGIN command and all other plaintext authentications unless
14873 SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
14874 matches the local IP (i.e.@: you're connecting from the same computer),
14875 the connection is considered secure and plaintext authentication is
14876 allowed. See also ssl=required setting.
14877 Defaults to @samp{#t}.
14878 @end deftypevr
14879
14880 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
14881 Authentication cache size (e.g.@: @samp{#e10e6}). 0 means it's disabled.
14882 Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
14883 for caching to be used.
14884 Defaults to @samp{0}.
14885 @end deftypevr
14886
14887 @deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
14888 Time to live for cached data. After TTL expires the cached record
14889 is no longer used, *except* if the main database lookup returns internal
14890 failure. We also try to handle password changes automatically: If
14891 user's previous authentication was successful, but this one wasn't, the
14892 cache isn't used. For now this works only with plaintext
14893 authentication.
14894 Defaults to @samp{"1 hour"}.
14895 @end deftypevr
14896
14897 @deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
14898 TTL for negative hits (user not found, password mismatch).
14899 0 disables caching them completely.
14900 Defaults to @samp{"1 hour"}.
14901 @end deftypevr
14902
14903 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
14904 List of realms for SASL authentication mechanisms that need them.
14905 You can leave it empty if you don't want to support multiple realms.
14906 Many clients simply use the first one listed here, so keep the default
14907 realm first.
14908 Defaults to @samp{()}.
14909 @end deftypevr
14910
14911 @deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
14912 Default realm/domain to use if none was specified. This is used for
14913 both SASL realms and appending @@domain to username in plaintext
14914 logins.
14915 Defaults to @samp{""}.
14916 @end deftypevr
14917
14918 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
14919 List of allowed characters in username. If the user-given username
14920 contains a character not listed in here, the login automatically fails.
14921 This is just an extra check to make sure user can't exploit any
14922 potential quote escaping vulnerabilities with SQL/LDAP databases. If
14923 you want to allow all characters, set this value to empty.
14924 Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
14925 @end deftypevr
14926
14927 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
14928 Username character translations before it's looked up from
14929 databases. The value contains series of from -> to characters. For
14930 example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
14931 translated to @samp{@@}.
14932 Defaults to @samp{""}.
14933 @end deftypevr
14934
14935 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
14936 Username formatting before it's looked up from databases. You can
14937 use the standard variables here, e.g.@: %Lu would lowercase the username,
14938 %n would drop away the domain if it was given, or @samp{%n-AT-%d} would
14939 change the @samp{@@} into @samp{-AT-}. This translation is done after
14940 @samp{auth-username-translation} changes.
14941 Defaults to @samp{"%Lu"}.
14942 @end deftypevr
14943
14944 @deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
14945 If you want to allow master users to log in by specifying the master
14946 username within the normal username string (i.e.@: not using SASL
14947 mechanism's support for it), you can specify the separator character
14948 here. The format is then <username><separator><master username>.
14949 UW-IMAP uses @samp{*} as the separator, so that could be a good
14950 choice.
14951 Defaults to @samp{""}.
14952 @end deftypevr
14953
14954 @deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
14955 Username to use for users logging in with ANONYMOUS SASL
14956 mechanism.
14957 Defaults to @samp{"anonymous"}.
14958 @end deftypevr
14959
14960 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
14961 Maximum number of dovecot-auth worker processes. They're used to
14962 execute blocking passdb and userdb queries (e.g.@: MySQL and PAM).
14963 They're automatically created and destroyed as needed.
14964 Defaults to @samp{30}.
14965 @end deftypevr
14966
14967 @deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
14968 Host name to use in GSSAPI principal names. The default is to use
14969 the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
14970 allow all keytab entries.
14971 Defaults to @samp{""}.
14972 @end deftypevr
14973
14974 @deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
14975 Kerberos keytab to use for the GSSAPI mechanism. Will use the
14976 system default (usually @file{/etc/krb5.keytab}) if not specified. You may
14977 need to change the auth service to run as root to be able to read this
14978 file.
14979 Defaults to @samp{""}.
14980 @end deftypevr
14981
14982 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
14983 Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
14984 and @samp{ntlm-auth} helper.
14985 <doc/wiki/Authentication/Mechanisms/Winbind.txt>.
14986 Defaults to @samp{#f}.
14987 @end deftypevr
14988
14989 @deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
14990 Path for Samba's @samp{ntlm-auth} helper binary.
14991 Defaults to @samp{"/usr/bin/ntlm_auth"}.
14992 @end deftypevr
14993
14994 @deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
14995 Time to delay before replying to failed authentications.
14996 Defaults to @samp{"2 secs"}.
14997 @end deftypevr
14998
14999 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
15000 Require a valid SSL client certificate or the authentication
15001 fails.
15002 Defaults to @samp{#f}.
15003 @end deftypevr
15004
15005 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
15006 Take the username from client's SSL certificate, using
15007 @code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
15008 CommonName.
15009 Defaults to @samp{#f}.
15010 @end deftypevr
15011
15012 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
15013 List of wanted authentication mechanisms. Supported mechanisms are:
15014 @samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
15015 @samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
15016 @samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
15017 @samp{disable-plaintext-auth} setting.
15018 @end deftypevr
15019
15020 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
15021 List of IPs or hostnames to all director servers, including ourself.
15022 Ports can be specified as ip:port. The default port is the same as what
15023 director service's @samp{inet-listener} is using.
15024 Defaults to @samp{()}.
15025 @end deftypevr
15026
15027 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
15028 List of IPs or hostnames to all backend mail servers. Ranges are
15029 allowed too, like 10.0.0.10-10.0.0.30.
15030 Defaults to @samp{()}.
15031 @end deftypevr
15032
15033 @deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
15034 How long to redirect users to a specific server after it no longer
15035 has any connections.
15036 Defaults to @samp{"15 min"}.
15037 @end deftypevr
15038
15039 @deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
15040 How the username is translated before being hashed. Useful values
15041 include %Ln if user can log in with or without @@domain, %Ld if mailboxes
15042 are shared within domain.
15043 Defaults to @samp{"%Lu"}.
15044 @end deftypevr
15045
15046 @deftypevr {@code{dovecot-configuration} parameter} string log-path
15047 Log file to use for error messages. @samp{syslog} logs to syslog,
15048 @samp{/dev/stderr} logs to stderr.
15049 Defaults to @samp{"syslog"}.
15050 @end deftypevr
15051
15052 @deftypevr {@code{dovecot-configuration} parameter} string info-log-path
15053 Log file to use for informational messages. Defaults to
15054 @samp{log-path}.
15055 Defaults to @samp{""}.
15056 @end deftypevr
15057
15058 @deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
15059 Log file to use for debug messages. Defaults to
15060 @samp{info-log-path}.
15061 Defaults to @samp{""}.
15062 @end deftypevr
15063
15064 @deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
15065 Syslog facility to use if you're logging to syslog. Usually if you
15066 don't want to use @samp{mail}, you'll use local0..local7. Also other
15067 standard facilities are supported.
15068 Defaults to @samp{"mail"}.
15069 @end deftypevr
15070
15071 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
15072 Log unsuccessful authentication attempts and the reasons why they
15073 failed.
15074 Defaults to @samp{#f}.
15075 @end deftypevr
15076
15077 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
15078 In case of password mismatches, log the attempted password. Valid
15079 values are no, plain and sha1. sha1 can be useful for detecting brute
15080 force password attempts vs. user simply trying the same password over
15081 and over again. You can also truncate the value to n chars by appending
15082 ":n" (e.g.@: sha1:6).
15083 Defaults to @samp{#f}.
15084 @end deftypevr
15085
15086 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
15087 Even more verbose logging for debugging purposes. Shows for example
15088 SQL queries.
15089 Defaults to @samp{#f}.
15090 @end deftypevr
15091
15092 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
15093 In case of password mismatches, log the passwords and used scheme so
15094 the problem can be debugged. Enabling this also enables
15095 @samp{auth-debug}.
15096 Defaults to @samp{#f}.
15097 @end deftypevr
15098
15099 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
15100 Enable mail process debugging. This can help you figure out why
15101 Dovecot isn't finding your mails.
15102 Defaults to @samp{#f}.
15103 @end deftypevr
15104
15105 @deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
15106 Show protocol level SSL errors.
15107 Defaults to @samp{#f}.
15108 @end deftypevr
15109
15110 @deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
15111 Prefix for each line written to log file. % codes are in
15112 strftime(3) format.
15113 Defaults to @samp{"\"%b %d %H:%M:%S \""}.
15114 @end deftypevr
15115
15116 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
15117 List of elements we want to log. The elements which have a
15118 non-empty variable value are joined together to form a comma-separated
15119 string.
15120 @end deftypevr
15121
15122 @deftypevr {@code{dovecot-configuration} parameter} string login-log-format
15123 Login log format. %s contains @samp{login-log-format-elements}
15124 string, %$ contains the data we want to log.
15125 Defaults to @samp{"%$: %s"}.
15126 @end deftypevr
15127
15128 @deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
15129 Log prefix for mail processes. See doc/wiki/Variables.txt for list
15130 of possible variables you can use.
15131 Defaults to @samp{"\"%s(%u)<%@{pid@}><%@{session@}>: \""}.
15132 @end deftypevr
15133
15134 @deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
15135 Format to use for logging mail deliveries. You can use variables:
15136 @table @code
15137 @item %$
15138 Delivery status message (e.g.@: @samp{saved to INBOX})
15139 @item %m
15140 Message-ID
15141 @item %s
15142 Subject
15143 @item %f
15144 From address
15145 @item %p
15146 Physical size
15147 @item %w
15148 Virtual size.
15149 @end table
15150 Defaults to @samp{"msgid=%m: %$"}.
15151 @end deftypevr
15152
15153 @deftypevr {@code{dovecot-configuration} parameter} string mail-location
15154 Location for users' mailboxes. The default is empty, which means
15155 that Dovecot tries to find the mailboxes automatically. This won't work
15156 if the user doesn't yet have any mail, so you should explicitly tell
15157 Dovecot the full location.
15158
15159 If you're using mbox, giving a path to the INBOX
15160 file (e.g.@: /var/mail/%u) isn't enough. You'll also need to tell Dovecot
15161 where the other mailboxes are kept. This is called the "root mail
15162 directory", and it must be the first path given in the
15163 @samp{mail-location} setting.
15164
15165 There are a few special variables you can use, eg.:
15166
15167 @table @samp
15168 @item %u
15169 username
15170 @item %n
15171 user part in user@@domain, same as %u if there's no domain
15172 @item %d
15173 domain part in user@@domain, empty if there's no domain
15174 @item %h
15175 home director
15176 @end table
15177
15178 See doc/wiki/Variables.txt for full list. Some examples:
15179 @table @samp
15180 @item maildir:~/Maildir
15181 @item mbox:~/mail:INBOX=/var/mail/%u
15182 @item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
15183 @end table
15184 Defaults to @samp{""}.
15185 @end deftypevr
15186
15187 @deftypevr {@code{dovecot-configuration} parameter} string mail-uid
15188 System user and group used to access mails. If you use multiple,
15189 userdb can override these by returning uid or gid fields. You can use
15190 either numbers or names. <doc/wiki/UserIds.txt>.
15191 Defaults to @samp{""}.
15192 @end deftypevr
15193
15194 @deftypevr {@code{dovecot-configuration} parameter} string mail-gid
15195
15196 Defaults to @samp{""}.
15197 @end deftypevr
15198
15199 @deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
15200 Group to enable temporarily for privileged operations. Currently
15201 this is used only with INBOX when either its initial creation or
15202 dotlocking fails. Typically this is set to "mail" to give access to
15203 /var/mail.
15204 Defaults to @samp{""}.
15205 @end deftypevr
15206
15207 @deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
15208 Grant access to these supplementary groups for mail processes.
15209 Typically these are used to set up access to shared mailboxes. Note
15210 that it may be dangerous to set these if users can create
15211 symlinks (e.g.@: if "mail" group is set here, ln -s /var/mail ~/mail/var
15212 could allow a user to delete others' mailboxes, or ln -s
15213 /secret/shared/box ~/mail/mybox would allow reading it).
15214 Defaults to @samp{""}.
15215 @end deftypevr
15216
15217 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
15218 Allow full file system access to clients. There's no access checks
15219 other than what the operating system does for the active UID/GID. It
15220 works with both maildir and mboxes, allowing you to prefix mailboxes
15221 names with e.g.@: /path/ or ~user/.
15222 Defaults to @samp{#f}.
15223 @end deftypevr
15224
15225 @deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
15226 Don't use mmap() at all. This is required if you store indexes to
15227 shared file systems (NFS or clustered file system).
15228 Defaults to @samp{#f}.
15229 @end deftypevr
15230
15231 @deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
15232 Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
15233 supports @samp{O_EXCL} since version 3, so this should be safe to use
15234 nowadays by default.
15235 Defaults to @samp{#t}.
15236 @end deftypevr
15237
15238 @deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
15239 When to use fsync() or fdatasync() calls:
15240 @table @code
15241 @item optimized
15242 Whenever necessary to avoid losing important data
15243 @item always
15244 Useful with e.g.@: NFS when write()s are delayed
15245 @item never
15246 Never use it (best performance, but crashes can lose data).
15247 @end table
15248 Defaults to @samp{"optimized"}.
15249 @end deftypevr
15250
15251 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
15252 Mail storage exists in NFS. Set this to yes to make Dovecot flush
15253 NFS caches whenever needed. If you're using only a single mail server
15254 this isn't needed.
15255 Defaults to @samp{#f}.
15256 @end deftypevr
15257
15258 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
15259 Mail index files also exist in NFS. Setting this to yes requires
15260 @samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
15261 Defaults to @samp{#f}.
15262 @end deftypevr
15263
15264 @deftypevr {@code{dovecot-configuration} parameter} string lock-method
15265 Locking method for index files. Alternatives are fcntl, flock and
15266 dotlock. Dotlocking uses some tricks which may create more disk I/O
15267 than other locking methods. NFS users: flock doesn't work, remember to
15268 change @samp{mmap-disable}.
15269 Defaults to @samp{"fcntl"}.
15270 @end deftypevr
15271
15272 @deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
15273 Directory in which LDA/LMTP temporarily stores incoming mails >128
15274 kB.
15275 Defaults to @samp{"/tmp"}.
15276 @end deftypevr
15277
15278 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
15279 Valid UID range for users. This is mostly to make sure that users can't
15280 log in as daemons or other system users. Note that denying root logins is
15281 hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
15282 is set to 0.
15283 Defaults to @samp{500}.
15284 @end deftypevr
15285
15286 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
15287
15288 Defaults to @samp{0}.
15289 @end deftypevr
15290
15291 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
15292 Valid GID range for users. Users having non-valid GID as primary group ID
15293 aren't allowed to log in. If user belongs to supplementary groups with
15294 non-valid GIDs, those groups are not set.
15295 Defaults to @samp{1}.
15296 @end deftypevr
15297
15298 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
15299
15300 Defaults to @samp{0}.
15301 @end deftypevr
15302
15303 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
15304 Maximum allowed length for mail keyword name. It's only forced when
15305 trying to create new keywords.
15306 Defaults to @samp{50}.
15307 @end deftypevr
15308
15309 @deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
15310 List of directories under which chrooting is allowed for mail
15311 processes (i.e.@: /var/mail will allow chrooting to /var/mail/foo/bar
15312 too). This setting doesn't affect @samp{login-chroot}
15313 @samp{mail-chroot} or auth chroot settings. If this setting is empty,
15314 "/./" in home dirs are ignored. WARNING: Never add directories here
15315 which local users can modify, that may lead to root exploit. Usually
15316 this should be done only if you don't allow shell access for users.
15317 <doc/wiki/Chrooting.txt>.
15318 Defaults to @samp{()}.
15319 @end deftypevr
15320
15321 @deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
15322 Default chroot directory for mail processes. This can be overridden
15323 for specific users in user database by giving /./ in user's home
15324 directory (e.g.@: /home/./user chroots into /home). Note that usually
15325 there is no real need to do chrooting, Dovecot doesn't allow users to
15326 access files outside their mail directory anyway. If your home
15327 directories are prefixed with the chroot directory, append "/."@: to
15328 @samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
15329 Defaults to @samp{""}.
15330 @end deftypevr
15331
15332 @deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
15333 UNIX socket path to master authentication server to find users.
15334 This is used by imap (for shared users) and lda.
15335 Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
15336 @end deftypevr
15337
15338 @deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
15339 Directory where to look up mail plugins.
15340 Defaults to @samp{"/usr/lib/dovecot"}.
15341 @end deftypevr
15342
15343 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
15344 List of plugins to load for all services. Plugins specific to IMAP,
15345 LDA, etc.@: are added to this list in their own .conf files.
15346 Defaults to @samp{()}.
15347 @end deftypevr
15348
15349 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
15350 The minimum number of mails in a mailbox before updates are done to
15351 cache file. This allows optimizing Dovecot's behavior to do less disk
15352 writes at the cost of more disk reads.
15353 Defaults to @samp{0}.
15354 @end deftypevr
15355
15356 @deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
15357 When IDLE command is running, mailbox is checked once in a while to
15358 see if there are any new mails or other changes. This setting defines
15359 the minimum time to wait between those checks. Dovecot can also use
15360 dnotify, inotify and kqueue to find out immediately when changes
15361 occur.
15362 Defaults to @samp{"30 secs"}.
15363 @end deftypevr
15364
15365 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
15366 Save mails with CR+LF instead of plain LF. This makes sending those
15367 mails take less CPU, especially with sendfile() syscall with Linux and
15368 FreeBSD. But it also creates a bit more disk I/O which may just make it
15369 slower. Also note that if other software reads the mboxes/maildirs,
15370 they may handle the extra CRs wrong and cause problems.
15371 Defaults to @samp{#f}.
15372 @end deftypevr
15373
15374 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
15375 By default LIST command returns all entries in maildir beginning
15376 with a dot. Enabling this option makes Dovecot return only entries
15377 which are directories. This is done by stat()ing each entry, so it
15378 causes more disk I/O.
15379 (For systems setting struct @samp{dirent->d_type} this check is free
15380 and it's done always regardless of this setting).
15381 Defaults to @samp{#f}.
15382 @end deftypevr
15383
15384 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
15385 When copying a message, do it with hard links whenever possible.
15386 This makes the performance much better, and it's unlikely to have any
15387 side effects.
15388 Defaults to @samp{#t}.
15389 @end deftypevr
15390
15391 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
15392 Assume Dovecot is the only MUA accessing Maildir: Scan cur/
15393 directory only when its mtime changes unexpectedly or when we can't find
15394 the mail otherwise.
15395 Defaults to @samp{#f}.
15396 @end deftypevr
15397
15398 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
15399 Which locking methods to use for locking mbox. There are four
15400 available:
15401
15402 @table @code
15403 @item dotlock
15404 Create <mailbox>.lock file. This is the oldest and most NFS-safe
15405 solution. If you want to use /var/mail/ like directory, the users will
15406 need write access to that directory.
15407 @item dotlock-try
15408 Same as dotlock, but if it fails because of permissions or because there
15409 isn't enough disk space, just skip it.
15410 @item fcntl
15411 Use this if possible. Works with NFS too if lockd is used.
15412 @item flock
15413 May not exist in all systems. Doesn't work with NFS.
15414 @item lockf
15415 May not exist in all systems. Doesn't work with NFS.
15416 @end table
15417
15418 You can use multiple locking methods; if you do the order they're declared
15419 in is important to avoid deadlocks if other MTAs/MUAs are using multiple
15420 locking methods as well. Some operating systems don't allow using some of
15421 them simultaneously.
15422 @end deftypevr
15423
15424 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
15425
15426 @end deftypevr
15427
15428 @deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
15429 Maximum time to wait for lock (all of them) before aborting.
15430 Defaults to @samp{"5 mins"}.
15431 @end deftypevr
15432
15433 @deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
15434 If dotlock exists but the mailbox isn't modified in any way,
15435 override the lock file after this much time.
15436 Defaults to @samp{"2 mins"}.
15437 @end deftypevr
15438
15439 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
15440 When mbox changes unexpectedly we have to fully read it to find out
15441 what changed. If the mbox is large this can take a long time. Since
15442 the change is usually just a newly appended mail, it'd be faster to
15443 simply read the new mails. If this setting is enabled, Dovecot does
15444 this but still safely fallbacks to re-reading the whole mbox file
15445 whenever something in mbox isn't how it's expected to be. The only real
15446 downside to this setting is that if some other MUA changes message
15447 flags, Dovecot doesn't notice it immediately. Note that a full sync is
15448 done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
15449 Defaults to @samp{#t}.
15450 @end deftypevr
15451
15452 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
15453 Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
15454 EXAMINE, EXPUNGE or CHECK commands. If this is set,
15455 @samp{mbox-dirty-syncs} is ignored.
15456 Defaults to @samp{#f}.
15457 @end deftypevr
15458
15459 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
15460 Delay writing mbox headers until doing a full write sync (EXPUNGE
15461 and CHECK commands and when closing the mailbox). This is especially
15462 useful for POP3 where clients often delete all mails. The downside is
15463 that our changes aren't immediately visible to other MUAs.
15464 Defaults to @samp{#t}.
15465 @end deftypevr
15466
15467 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
15468 If mbox size is smaller than this (e.g.@: 100k), don't write index
15469 files. If an index file already exists it's still read, just not
15470 updated.
15471 Defaults to @samp{0}.
15472 @end deftypevr
15473
15474 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
15475 Maximum dbox file size until it's rotated.
15476 Defaults to @samp{10000000}.
15477 @end deftypevr
15478
15479 @deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
15480 Maximum dbox file age until it's rotated. Typically in days. Day
15481 begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
15482 disabled.
15483 Defaults to @samp{"1d"}.
15484 @end deftypevr
15485
15486 @deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
15487 When creating new mdbox files, immediately preallocate their size to
15488 @samp{mdbox-rotate-size}. This setting currently works only in Linux
15489 with some file systems (ext4, xfs).
15490 Defaults to @samp{#f}.
15491 @end deftypevr
15492
15493 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
15494 sdbox and mdbox support saving mail attachments to external files,
15495 which also allows single instance storage for them. Other backends
15496 don't support this for now.
15497
15498 WARNING: This feature hasn't been tested much yet. Use at your own risk.
15499
15500 Directory root where to store mail attachments. Disabled, if empty.
15501 Defaults to @samp{""}.
15502 @end deftypevr
15503
15504 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
15505 Attachments smaller than this aren't saved externally. It's also
15506 possible to write a plugin to disable saving specific attachments
15507 externally.
15508 Defaults to @samp{128000}.
15509 @end deftypevr
15510
15511 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
15512 File system backend to use for saving attachments:
15513 @table @code
15514 @item posix
15515 No SiS done by Dovecot (but this might help FS's own deduplication)
15516 @item sis posix
15517 SiS with immediate byte-by-byte comparison during saving
15518 @item sis-queue posix
15519 SiS with delayed comparison and deduplication.
15520 @end table
15521 Defaults to @samp{"sis posix"}.
15522 @end deftypevr
15523
15524 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
15525 Hash format to use in attachment filenames. You can add any text and
15526 variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
15527 @code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
15528 truncated, e.g.@: @code{%@{sha256:80@}} returns only first 80 bits.
15529 Defaults to @samp{"%@{sha1@}"}.
15530 @end deftypevr
15531
15532 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
15533
15534 Defaults to @samp{100}.
15535 @end deftypevr
15536
15537 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
15538
15539 Defaults to @samp{1000}.
15540 @end deftypevr
15541
15542 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
15543 Default VSZ (virtual memory size) limit for service processes.
15544 This is mainly intended to catch and kill processes that leak memory
15545 before they eat up everything.
15546 Defaults to @samp{256000000}.
15547 @end deftypevr
15548
15549 @deftypevr {@code{dovecot-configuration} parameter} string default-login-user
15550 Login user is internally used by login processes. This is the most
15551 untrusted user in Dovecot system. It shouldn't have access to anything
15552 at all.
15553 Defaults to @samp{"dovenull"}.
15554 @end deftypevr
15555
15556 @deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
15557 Internal user is used by unprivileged processes. It should be
15558 separate from login user, so that login processes can't disturb other
15559 processes.
15560 Defaults to @samp{"dovecot"}.
15561 @end deftypevr
15562
15563 @deftypevr {@code{dovecot-configuration} parameter} string ssl?
15564 SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
15565 Defaults to @samp{"required"}.
15566 @end deftypevr
15567
15568 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
15569 PEM encoded X.509 SSL/TLS certificate (public key).
15570 Defaults to @samp{"</etc/dovecot/default.pem"}.
15571 @end deftypevr
15572
15573 @deftypevr {@code{dovecot-configuration} parameter} string ssl-key
15574 PEM encoded SSL/TLS private key. The key is opened before
15575 dropping root privileges, so keep the key file unreadable by anyone but
15576 root.
15577 Defaults to @samp{"</etc/dovecot/private/default.pem"}.
15578 @end deftypevr
15579
15580 @deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
15581 If key file is password protected, give the password here.
15582 Alternatively give it when starting dovecot with -p parameter. Since
15583 this file is often world-readable, you may want to place this setting
15584 instead to a different.
15585 Defaults to @samp{""}.
15586 @end deftypevr
15587
15588 @deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
15589 PEM encoded trusted certificate authority. Set this only if you
15590 intend to use @samp{ssl-verify-client-cert? #t}. The file should
15591 contain the CA certificate(s) followed by the matching
15592 CRL(s). (e.g.@: @samp{ssl-ca </etc/ssl/certs/ca.pem}).
15593 Defaults to @samp{""}.
15594 @end deftypevr
15595
15596 @deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
15597 Require that CRL check succeeds for client certificates.
15598 Defaults to @samp{#t}.
15599 @end deftypevr
15600
15601 @deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
15602 Request client to send a certificate. If you also want to require
15603 it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
15604 Defaults to @samp{#f}.
15605 @end deftypevr
15606
15607 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
15608 Which field from certificate to use for username. commonName and
15609 x500UniqueIdentifier are the usual choices. You'll also need to set
15610 @samp{auth-ssl-username-from-cert? #t}.
15611 Defaults to @samp{"commonName"}.
15612 @end deftypevr
15613
15614 @deftypevr {@code{dovecot-configuration} parameter} string ssl-min-protocol
15615 Minimum SSL protocol version to accept.
15616 Defaults to @samp{"TLSv1"}.
15617 @end deftypevr
15618
15619 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
15620 SSL ciphers to use.
15621 Defaults to @samp{"ALL:!kRSA:!SRP:!kDHd:!DSS:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK:!RC4:!ADH:!LOW@@STRENGTH"}.
15622 @end deftypevr
15623
15624 @deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
15625 SSL crypto device to use, for valid values run "openssl engine".
15626 Defaults to @samp{""}.
15627 @end deftypevr
15628
15629 @deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
15630 Address to use when sending rejection mails.
15631 %d expands to recipient domain.
15632 Defaults to @samp{"postmaster@@%d"}.
15633 @end deftypevr
15634
15635 @deftypevr {@code{dovecot-configuration} parameter} string hostname
15636 Hostname to use in various parts of sent mails (e.g.@: in Message-Id)
15637 and in LMTP replies. Default is the system's real hostname@@domain.
15638 Defaults to @samp{""}.
15639 @end deftypevr
15640
15641 @deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
15642 If user is over quota, return with temporary failure instead of
15643 bouncing the mail.
15644 Defaults to @samp{#f}.
15645 @end deftypevr
15646
15647 @deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
15648 Binary to use for sending mails.
15649 Defaults to @samp{"/usr/sbin/sendmail"}.
15650 @end deftypevr
15651
15652 @deftypevr {@code{dovecot-configuration} parameter} string submission-host
15653 If non-empty, send mails via this SMTP host[:port] instead of
15654 sendmail.
15655 Defaults to @samp{""}.
15656 @end deftypevr
15657
15658 @deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
15659 Subject: header to use for rejection mails. You can use the same
15660 variables as for @samp{rejection-reason} below.
15661 Defaults to @samp{"Rejected: %s"}.
15662 @end deftypevr
15663
15664 @deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
15665 Human readable error message for rejection mails. You can use
15666 variables:
15667
15668 @table @code
15669 @item %n
15670 CRLF
15671 @item %r
15672 reason
15673 @item %s
15674 original subject
15675 @item %t
15676 recipient
15677 @end table
15678 Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
15679 @end deftypevr
15680
15681 @deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
15682 Delimiter character between local-part and detail in email
15683 address.
15684 Defaults to @samp{"+"}.
15685 @end deftypevr
15686
15687 @deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
15688 Header where the original recipient address (SMTP's RCPT TO:
15689 address) is taken from if not available elsewhere. With dovecot-lda -a
15690 parameter overrides this. A commonly used header for this is
15691 X-Original-To.
15692 Defaults to @samp{""}.
15693 @end deftypevr
15694
15695 @deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
15696 Should saving a mail to a nonexistent mailbox automatically create
15697 it?.
15698 Defaults to @samp{#f}.
15699 @end deftypevr
15700
15701 @deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
15702 Should automatically created mailboxes be also automatically
15703 subscribed?.
15704 Defaults to @samp{#f}.
15705 @end deftypevr
15706
15707 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
15708 Maximum IMAP command line length. Some clients generate very long
15709 command lines with huge mailboxes, so you may need to raise this if you
15710 get "Too long argument" or "IMAP command line too large" errors
15711 often.
15712 Defaults to @samp{64000}.
15713 @end deftypevr
15714
15715 @deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
15716 IMAP logout format string:
15717 @table @code
15718 @item %i
15719 total number of bytes read from client
15720 @item %o
15721 total number of bytes sent to client.
15722 @end table
15723 See @file{doc/wiki/Variables.txt} for a list of all the variables you can use.
15724 Defaults to @samp{"in=%i out=%o deleted=%@{deleted@} expunged=%@{expunged@} trashed=%@{trashed@} hdr_count=%@{fetch_hdr_count@} hdr_bytes=%@{fetch_hdr_bytes@} body_count=%@{fetch_body_count@} body_bytes=%@{fetch_body_bytes@}"}.
15725 @end deftypevr
15726
15727 @deftypevr {@code{dovecot-configuration} parameter} string imap-capability
15728 Override the IMAP CAPABILITY response. If the value begins with '+',
15729 add the given capabilities on top of the defaults (e.g.@: +XFOO XBAR).
15730 Defaults to @samp{""}.
15731 @end deftypevr
15732
15733 @deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
15734 How long to wait between "OK Still here" notifications when client
15735 is IDLEing.
15736 Defaults to @samp{"2 mins"}.
15737 @end deftypevr
15738
15739 @deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
15740 ID field names and values to send to clients. Using * as the value
15741 makes Dovecot use the default value. The following fields have default
15742 values currently: name, version, os, os-version, support-url,
15743 support-email.
15744 Defaults to @samp{""}.
15745 @end deftypevr
15746
15747 @deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
15748 ID fields sent by client to log. * means everything.
15749 Defaults to @samp{""}.
15750 @end deftypevr
15751
15752 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
15753 Workarounds for various client bugs:
15754
15755 @table @code
15756 @item delay-newmail
15757 Send EXISTS/RECENT new mail notifications only when replying to NOOP and
15758 CHECK commands. Some clients ignore them otherwise, for example OSX
15759 Mail (<v2.1). Outlook Express breaks more badly though, without this it
15760 may show user "Message no longer in server" errors. Note that OE6
15761 still breaks even with this workaround if synchronization is set to
15762 "Headers Only".
15763
15764 @item tb-extra-mailbox-sep
15765 Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
15766 adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
15767 ignore the extra @samp{/} instead of treating it as invalid mailbox name.
15768
15769 @item tb-lsub-flags
15770 Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g.@: mbox).
15771 This makes Thunderbird realize they aren't selectable and show them
15772 greyed out, instead of only later giving "not selectable" popup error.
15773 @end table
15774 Defaults to @samp{()}.
15775 @end deftypevr
15776
15777 @deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
15778 Host allowed in URLAUTH URLs sent by client. "*" allows all.
15779 Defaults to @samp{""}.
15780 @end deftypevr
15781
15782
15783 Whew! Lots of configuration options. The nice thing about it though is
15784 that GuixSD has a complete interface to Dovecot's configuration
15785 language. This allows not only a nice way to declare configurations,
15786 but also offers reflective capabilities as well: users can write code to
15787 inspect and transform configurations from within Scheme.
15788
15789 However, it could be that you just want to get a @code{dovecot.conf} up
15790 and running. In that case, you can pass an
15791 @code{opaque-dovecot-configuration} as the @code{#:config} parameter to
15792 @code{dovecot-service}. As its name indicates, an opaque configuration
15793 does not have easy reflective capabilities.
15794
15795 Available @code{opaque-dovecot-configuration} fields are:
15796
15797 @deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
15798 The dovecot package.
15799 @end deftypevr
15800
15801 @deftypevr {@code{opaque-dovecot-configuration} parameter} string string
15802 The contents of the @code{dovecot.conf}, as a string.
15803 @end deftypevr
15804
15805 For example, if your @code{dovecot.conf} is just the empty string, you
15806 could instantiate a dovecot service like this:
15807
15808 @example
15809 (dovecot-service #:config
15810 (opaque-dovecot-configuration
15811 (string "")))
15812 @end example
15813
15814 @subsubheading OpenSMTPD Service
15815
15816 @deffn {Scheme Variable} opensmtpd-service-type
15817 This is the type of the @uref{https://www.opensmtpd.org, OpenSMTPD}
15818 service, whose value should be an @code{opensmtpd-configuration} object
15819 as in this example:
15820
15821 @example
15822 (service opensmtpd-service-type
15823 (opensmtpd-configuration
15824 (config-file (local-file "./my-smtpd.conf"))))
15825 @end example
15826 @end deffn
15827
15828 @deftp {Data Type} opensmtpd-configuration
15829 Data type representing the configuration of opensmtpd.
15830
15831 @table @asis
15832 @item @code{package} (default: @var{opensmtpd})
15833 Package object of the OpenSMTPD SMTP server.
15834
15835 @item @code{config-file} (default: @var{%default-opensmtpd-file})
15836 File-like object of the OpenSMTPD configuration file to use. By default
15837 it listens on the loopback network interface, and allows for mail from
15838 users and daemons on the local machine, as well as permitting email to
15839 remote servers. Run @command{man smtpd.conf} for more information.
15840
15841 @end table
15842 @end deftp
15843
15844 @subsubheading Exim Service
15845
15846 @cindex mail transfer agent (MTA)
15847 @cindex MTA (mail transfer agent)
15848 @cindex SMTP
15849
15850 @deffn {Scheme Variable} exim-service-type
15851 This is the type of the @uref{https://exim.org, Exim} mail transfer
15852 agent (MTA), whose value should be an @code{exim-configuration} object
15853 as in this example:
15854
15855 @example
15856 (service exim-service-type
15857 (exim-configuration
15858 (config-file (local-file "./my-exim.conf"))))
15859 @end example
15860 @end deffn
15861
15862 In order to use an @code{exim-service-type} service you must also have a
15863 @code{mail-aliases-service-type} service present in your
15864 @code{operating-system} (even if it has no aliases).
15865
15866 @deftp {Data Type} exim-configuration
15867 Data type representing the configuration of exim.
15868
15869 @table @asis
15870 @item @code{package} (default: @var{exim})
15871 Package object of the Exim server.
15872
15873 @item @code{config-file} (default: @code{#f})
15874 File-like object of the Exim configuration file to use. If its value is
15875 @code{#f} then use the default configuration file from the package
15876 provided in @code{package}. The resulting configuration file is loaded
15877 after setting the @code{exim_user} and @code{exim_group} configuration
15878 variables.
15879
15880 @end table
15881 @end deftp
15882
15883 @subsubheading Mail Aliases Service
15884
15885 @cindex email aliases
15886 @cindex aliases, for email addresses
15887
15888 @deffn {Scheme Variable} mail-aliases-service-type
15889 This is the type of the service which provides @code{/etc/aliases},
15890 specifying how to deliver mail to users on this system.
15891
15892 @example
15893 (service mail-aliases-service-type
15894 '(("postmaster" "bob")
15895 ("bob" "bob@@example.com" "bob@@example2.com")))
15896 @end example
15897 @end deffn
15898
15899 The configuration for a @code{mail-aliases-service-type} service is an
15900 association list denoting how to deliver mail that comes to this
15901 system. Each entry is of the form @code{(alias addresses ...)}, with
15902 @code{alias} specifying the local alias and @code{addresses} specifying
15903 where to deliver this user's mail.
15904
15905 The aliases aren't required to exist as users on the local system. In
15906 the above example, there doesn't need to be a @code{postmaster} entry in
15907 the @code{operating-system}'s @code{user-accounts} in order to deliver
15908 the @code{postmaster} mail to @code{bob} (which subsequently would
15909 deliver mail to @code{bob@@example.com} and @code{bob@@example2.com}).
15910
15911 @node Messaging Services
15912 @subsubsection Messaging Services
15913
15914 @cindex messaging
15915 @cindex jabber
15916 @cindex XMPP
15917 The @code{(gnu services messaging)} module provides Guix service
15918 definitions for messaging services: currently only Prosody is supported.
15919
15920 @subsubheading Prosody Service
15921
15922 @deffn {Scheme Variable} prosody-service-type
15923 This is the type for the @uref{https://prosody.im, Prosody XMPP
15924 communication server}. Its value must be a @code{prosody-configuration}
15925 record as in this example:
15926
15927 @example
15928 (service prosody-service-type
15929 (prosody-configuration
15930 (modules-enabled (cons "groups" "mam" %default-modules-enabled))
15931 (int-components
15932 (list
15933 (int-component-configuration
15934 (hostname "conference.example.net")
15935 (plugin "muc")
15936 (mod-muc (mod-muc-configuration)))))
15937 (virtualhosts
15938 (list
15939 (virtualhost-configuration
15940 (domain "example.net"))))))
15941 @end example
15942
15943 See below for details about @code{prosody-configuration}.
15944
15945 @end deffn
15946
15947 By default, Prosody does not need much configuration. Only one
15948 @code{virtualhosts} field is needed: it specifies the domain you wish
15949 Prosody to serve.
15950
15951 You can perform various sanity checks on the generated configuration
15952 with the @code{prosodyctl check} command.
15953
15954 Prosodyctl will also help you to import certificates from the
15955 @code{letsencrypt} directory so that the @code{prosody} user can access
15956 them. See @url{https://prosody.im/doc/letsencrypt}.
15957
15958 @example
15959 prosodyctl --root cert import /etc/letsencrypt/live
15960 @end example
15961
15962 The available configuration parameters follow. Each parameter
15963 definition is preceded by its type; for example, @samp{string-list foo}
15964 indicates that the @code{foo} parameter should be specified as a list of
15965 strings. Types starting with @code{maybe-} denote parameters that won't
15966 show up in @code{prosody.cfg.lua} when their value is @code{'disabled}.
15967
15968 There is also a way to specify the configuration as a string, if you
15969 have an old @code{prosody.cfg.lua} file that you want to port over from
15970 some other system; see the end for more details.
15971
15972 The @code{file-object} type designates either a file-like object
15973 (@pxref{G-Expressions, file-like objects}) or a file name.
15974
15975 @c The following documentation was initially generated by
15976 @c (generate-documentation) in (gnu services messaging). Manually maintained
15977 @c documentation is better, so we shouldn't hesitate to edit below as
15978 @c needed. However if the change you want to make to this documentation
15979 @c can be done in an automated way, it's probably easier to change
15980 @c (generate-documentation) than to make it below and have to deal with
15981 @c the churn as Prosody updates.
15982
15983 Available @code{prosody-configuration} fields are:
15984
15985 @deftypevr {@code{prosody-configuration} parameter} package prosody
15986 The Prosody package.
15987 @end deftypevr
15988
15989 @deftypevr {@code{prosody-configuration} parameter} file-name data-path
15990 Location of the Prosody data storage directory. See
15991 @url{https://prosody.im/doc/configure}.
15992 Defaults to @samp{"/var/lib/prosody"}.
15993 @end deftypevr
15994
15995 @deftypevr {@code{prosody-configuration} parameter} file-object-list plugin-paths
15996 Additional plugin directories. They are searched in all the specified
15997 paths in order. See @url{https://prosody.im/doc/plugins_directory}.
15998 Defaults to @samp{()}.
15999 @end deftypevr
16000
16001 @deftypevr {@code{prosody-configuration} parameter} file-name certificates
16002 Every virtual host and component needs a certificate so that clients and
16003 servers can securely verify its identity. Prosody will automatically load
16004 certificates/keys from the directory specified here.
16005 Defaults to @samp{"/etc/prosody/certs"}.
16006 @end deftypevr
16007
16008 @deftypevr {@code{prosody-configuration} parameter} string-list admins
16009 This is a list of accounts that are admins for the server. Note that you
16010 must create the accounts separately. See @url{https://prosody.im/doc/admins} and
16011 @url{https://prosody.im/doc/creating_accounts}.
16012 Example: @code{(admins '("user1@@example.com" "user2@@example.net"))}
16013 Defaults to @samp{()}.
16014 @end deftypevr
16015
16016 @deftypevr {@code{prosody-configuration} parameter} boolean use-libevent?
16017 Enable use of libevent for better performance under high load. See
16018 @url{https://prosody.im/doc/libevent}.
16019 Defaults to @samp{#f}.
16020 @end deftypevr
16021
16022 @deftypevr {@code{prosody-configuration} parameter} module-list modules-enabled
16023 This is the list of modules Prosody will load on startup. It looks for
16024 @code{mod_modulename.lua} in the plugins folder, so make sure that exists too.
16025 Documentation on modules can be found at:
16026 @url{https://prosody.im/doc/modules}.
16027 Defaults to @samp{("roster" "saslauth" "tls" "dialback" "disco" "carbons" "private" "blocklist" "vcard" "version" "uptime" "time" "ping" "pep" "register" "admin_adhoc")}.
16028 @end deftypevr
16029
16030 @deftypevr {@code{prosody-configuration} parameter} string-list modules-disabled
16031 @samp{"offline"}, @samp{"c2s"} and @samp{"s2s"} are auto-loaded, but
16032 should you want to disable them then add them to this list.
16033 Defaults to @samp{()}.
16034 @end deftypevr
16035
16036 @deftypevr {@code{prosody-configuration} parameter} file-object groups-file
16037 Path to a text file where the shared groups are defined. If this path is
16038 empty then @samp{mod_groups} does nothing. See
16039 @url{https://prosody.im/doc/modules/mod_groups}.
16040 Defaults to @samp{"/var/lib/prosody/sharedgroups.txt"}.
16041 @end deftypevr
16042
16043 @deftypevr {@code{prosody-configuration} parameter} boolean allow-registration?
16044 Disable account creation by default, for security. See
16045 @url{https://prosody.im/doc/creating_accounts}.
16046 Defaults to @samp{#f}.
16047 @end deftypevr
16048
16049 @deftypevr {@code{prosody-configuration} parameter} maybe-ssl-configuration ssl
16050 These are the SSL/TLS-related settings. Most of them are disabled so to
16051 use Prosody's defaults. If you do not completely understand these options, do
16052 not add them to your config, it is easy to lower the security of your server
16053 using them. See @url{https://prosody.im/doc/advanced_ssl_config}.
16054
16055 Available @code{ssl-configuration} fields are:
16056
16057 @deftypevr {@code{ssl-configuration} parameter} maybe-string protocol
16058 This determines what handshake to use.
16059 @end deftypevr
16060
16061 @deftypevr {@code{ssl-configuration} parameter} maybe-file-name key
16062 Path to your private key file.
16063 @end deftypevr
16064
16065 @deftypevr {@code{ssl-configuration} parameter} maybe-file-name certificate
16066 Path to your certificate file.
16067 @end deftypevr
16068
16069 @deftypevr {@code{ssl-configuration} parameter} file-object capath
16070 Path to directory containing root certificates that you wish Prosody to
16071 trust when verifying the certificates of remote servers.
16072 Defaults to @samp{"/etc/ssl/certs"}.
16073 @end deftypevr
16074
16075 @deftypevr {@code{ssl-configuration} parameter} maybe-file-object cafile
16076 Path to a file containing root certificates that you wish Prosody to trust.
16077 Similar to @code{capath} but with all certificates concatenated together.
16078 @end deftypevr
16079
16080 @deftypevr {@code{ssl-configuration} parameter} maybe-string-list verify
16081 A list of verification options (these mostly map to OpenSSL's
16082 @code{set_verify()} flags).
16083 @end deftypevr
16084
16085 @deftypevr {@code{ssl-configuration} parameter} maybe-string-list options
16086 A list of general options relating to SSL/TLS. These map to OpenSSL's
16087 @code{set_options()}. For a full list of options available in LuaSec, see the
16088 LuaSec source.
16089 @end deftypevr
16090
16091 @deftypevr {@code{ssl-configuration} parameter} maybe-non-negative-integer depth
16092 How long a chain of certificate authorities to check when looking for a
16093 trusted root certificate.
16094 @end deftypevr
16095
16096 @deftypevr {@code{ssl-configuration} parameter} maybe-string ciphers
16097 An OpenSSL cipher string. This selects what ciphers Prosody will offer to
16098 clients, and in what order.
16099 @end deftypevr
16100
16101 @deftypevr {@code{ssl-configuration} parameter} maybe-file-name dhparam
16102 A path to a file containing parameters for Diffie-Hellman key exchange. You
16103 can create such a file with:
16104 @code{openssl dhparam -out /etc/prosody/certs/dh-2048.pem 2048}
16105 @end deftypevr
16106
16107 @deftypevr {@code{ssl-configuration} parameter} maybe-string curve
16108 Curve for Elliptic curve Diffie-Hellman. Prosody's default is
16109 @samp{"secp384r1"}.
16110 @end deftypevr
16111
16112 @deftypevr {@code{ssl-configuration} parameter} maybe-string-list verifyext
16113 A list of "extra" verification options.
16114 @end deftypevr
16115
16116 @deftypevr {@code{ssl-configuration} parameter} maybe-string password
16117 Password for encrypted private keys.
16118 @end deftypevr
16119
16120 @end deftypevr
16121
16122 @deftypevr {@code{prosody-configuration} parameter} boolean c2s-require-encryption?
16123 Whether to force all client-to-server connections to be encrypted or not.
16124 See @url{https://prosody.im/doc/modules/mod_tls}.
16125 Defaults to @samp{#f}.
16126 @end deftypevr
16127
16128 @deftypevr {@code{prosody-configuration} parameter} string-list disable-sasl-mechanisms
16129 Set of mechanisms that will never be offered. See
16130 @url{https://prosody.im/doc/modules/mod_saslauth}.
16131 Defaults to @samp{("DIGEST-MD5")}.
16132 @end deftypevr
16133
16134 @deftypevr {@code{prosody-configuration} parameter} boolean s2s-require-encryption?
16135 Whether to force all server-to-server connections to be encrypted or not.
16136 See @url{https://prosody.im/doc/modules/mod_tls}.
16137 Defaults to @samp{#f}.
16138 @end deftypevr
16139
16140 @deftypevr {@code{prosody-configuration} parameter} boolean s2s-secure-auth?
16141 Whether to require encryption and certificate authentication. This
16142 provides ideal security, but requires servers you communicate with to support
16143 encryption AND present valid, trusted certificates. See
16144 @url{https://prosody.im/doc/s2s#security}.
16145 Defaults to @samp{#f}.
16146 @end deftypevr
16147
16148 @deftypevr {@code{prosody-configuration} parameter} string-list s2s-insecure-domains
16149 Many servers don't support encryption or have invalid or self-signed
16150 certificates. You can list domains here that will not be required to
16151 authenticate using certificates. They will be authenticated using DNS. See
16152 @url{https://prosody.im/doc/s2s#security}.
16153 Defaults to @samp{()}.
16154 @end deftypevr
16155
16156 @deftypevr {@code{prosody-configuration} parameter} string-list s2s-secure-domains
16157 Even if you leave @code{s2s-secure-auth?} disabled, you can still require
16158 valid certificates for some domains by specifying a list here. See
16159 @url{https://prosody.im/doc/s2s#security}.
16160 Defaults to @samp{()}.
16161 @end deftypevr
16162
16163 @deftypevr {@code{prosody-configuration} parameter} string authentication
16164 Select the authentication backend to use. The default provider stores
16165 passwords in plaintext and uses Prosody's configured data storage to store the
16166 authentication data. If you do not trust your server please see
16167 @url{https://prosody.im/doc/modules/mod_auth_internal_hashed} for information
16168 about using the hashed backend. See also
16169 @url{https://prosody.im/doc/authentication}
16170 Defaults to @samp{"internal_plain"}.
16171 @end deftypevr
16172
16173 @deftypevr {@code{prosody-configuration} parameter} maybe-string log
16174 Set logging options. Advanced logging configuration is not yet supported
16175 by the GuixSD Prosody Service. See @url{https://prosody.im/doc/logging}.
16176 Defaults to @samp{"*syslog"}.
16177 @end deftypevr
16178
16179 @deftypevr {@code{prosody-configuration} parameter} file-name pidfile
16180 File to write pid in. See @url{https://prosody.im/doc/modules/mod_posix}.
16181 Defaults to @samp{"/var/run/prosody/prosody.pid"}.
16182 @end deftypevr
16183
16184 @deftypevr {@code{prosody-configuration} parameter} maybe-non-negative-integer http-max-content-size
16185 Maximum allowed size of the HTTP body (in bytes).
16186 @end deftypevr
16187
16188 @deftypevr {@code{prosody-configuration} parameter} maybe-string http-external-url
16189 Some modules expose their own URL in various ways. This URL is built
16190 from the protocol, host and port used. If Prosody sits behind a proxy, the
16191 public URL will be @code{http-external-url} instead. See
16192 @url{https://prosody.im/doc/http#external_url}.
16193 @end deftypevr
16194
16195 @deftypevr {@code{prosody-configuration} parameter} virtualhost-configuration-list virtualhosts
16196 A host in Prosody is a domain on which user accounts can be created. For
16197 example if you want your users to have addresses like
16198 @samp{"john.smith@@example.com"} then you need to add a host
16199 @samp{"example.com"}. All options in this list will apply only to this host.
16200
16201 Note: the name "virtual" host is used in configuration to avoid confusion with
16202 the actual physical host that Prosody is installed on. A single Prosody
16203 instance can serve many domains, each one defined as a VirtualHost entry in
16204 Prosody's configuration. Conversely a server that hosts a single domain would
16205 have just one VirtualHost entry.
16206
16207 See @url{https://prosody.im/doc/configure#virtual_host_settings}.
16208
16209 Available @code{virtualhost-configuration} fields are:
16210
16211 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{disable-sasl-mechanisms}, @code{s2s-require-encryption?}, @code{s2s-secure-auth?}, @code{s2s-insecure-domains}, @code{s2s-secure-domains}, @code{authentication}, @code{log}, @code{http-max-content-size}, @code{http-external-url}, @code{raw-content}, plus:
16212 @deftypevr {@code{virtualhost-configuration} parameter} string domain
16213 Domain you wish Prosody to serve.
16214 @end deftypevr
16215
16216 @end deftypevr
16217
16218 @deftypevr {@code{prosody-configuration} parameter} int-component-configuration-list int-components
16219 Components are extra services on a server which are available to clients,
16220 usually on a subdomain of the main server (such as
16221 @samp{"mycomponent.example.com"}). Example components might be chatroom
16222 servers, user directories, or gateways to other protocols.
16223
16224 Internal components are implemented with Prosody-specific plugins. To add an
16225 internal component, you simply fill the hostname field, and the plugin you wish
16226 to use for the component.
16227
16228 See @url{https://prosody.im/doc/components}.
16229 Defaults to @samp{()}.
16230
16231 Available @code{int-component-configuration} fields are:
16232
16233 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{disable-sasl-mechanisms}, @code{s2s-require-encryption?}, @code{s2s-secure-auth?}, @code{s2s-insecure-domains}, @code{s2s-secure-domains}, @code{authentication}, @code{log}, @code{http-max-content-size}, @code{http-external-url}, @code{raw-content}, plus:
16234 @deftypevr {@code{int-component-configuration} parameter} string hostname
16235 Hostname of the component.
16236 @end deftypevr
16237
16238 @deftypevr {@code{int-component-configuration} parameter} string plugin
16239 Plugin you wish to use for the component.
16240 @end deftypevr
16241
16242 @deftypevr {@code{int-component-configuration} parameter} maybe-mod-muc-configuration mod-muc
16243 Multi-user chat (MUC) is Prosody's module for allowing you to create
16244 hosted chatrooms/conferences for XMPP users.
16245
16246 General information on setting up and using multi-user chatrooms can be found
16247 in the "Chatrooms" documentation (@url{https://prosody.im/doc/chatrooms}),
16248 which you should read if you are new to XMPP chatrooms.
16249
16250 See also @url{https://prosody.im/doc/modules/mod_muc}.
16251
16252 Available @code{mod-muc-configuration} fields are:
16253
16254 @deftypevr {@code{mod-muc-configuration} parameter} string name
16255 The name to return in service discovery responses.
16256 Defaults to @samp{"Prosody Chatrooms"}.
16257 @end deftypevr
16258
16259 @deftypevr {@code{mod-muc-configuration} parameter} string-or-boolean restrict-room-creation
16260 If @samp{#t}, this will only allow admins to create new chatrooms.
16261 Otherwise anyone can create a room. The value @samp{"local"} restricts room
16262 creation to users on the service's parent domain. E.g.@: @samp{user@@example.com}
16263 can create rooms on @samp{rooms.example.com}. The value @samp{"admin"}
16264 restricts to service administrators only.
16265 Defaults to @samp{#f}.
16266 @end deftypevr
16267
16268 @deftypevr {@code{mod-muc-configuration} parameter} non-negative-integer max-history-messages
16269 Maximum number of history messages that will be sent to the member that has
16270 just joined the room.
16271 Defaults to @samp{20}.
16272 @end deftypevr
16273
16274 @end deftypevr
16275
16276 @end deftypevr
16277
16278 @deftypevr {@code{prosody-configuration} parameter} ext-component-configuration-list ext-components
16279 External components use XEP-0114, which most standalone components
16280 support. To add an external component, you simply fill the hostname field. See
16281 @url{https://prosody.im/doc/components}.
16282 Defaults to @samp{()}.
16283
16284 Available @code{ext-component-configuration} fields are:
16285
16286 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{disable-sasl-mechanisms}, @code{s2s-require-encryption?}, @code{s2s-secure-auth?}, @code{s2s-insecure-domains}, @code{s2s-secure-domains}, @code{authentication}, @code{log}, @code{http-max-content-size}, @code{http-external-url}, @code{raw-content}, plus:
16287 @deftypevr {@code{ext-component-configuration} parameter} string component-secret
16288 Password which the component will use to log in.
16289 @end deftypevr
16290
16291 @deftypevr {@code{ext-component-configuration} parameter} string hostname
16292 Hostname of the component.
16293 @end deftypevr
16294
16295 @end deftypevr
16296
16297 @deftypevr {@code{prosody-configuration} parameter} non-negative-integer-list component-ports
16298 Port(s) Prosody listens on for component connections.
16299 Defaults to @samp{(5347)}.
16300 @end deftypevr
16301
16302 @deftypevr {@code{prosody-configuration} parameter} string component-interface
16303 Interface Prosody listens on for component connections.
16304 Defaults to @samp{"127.0.0.1"}.
16305 @end deftypevr
16306
16307 @deftypevr {@code{prosody-configuration} parameter} maybe-raw-content raw-content
16308 Raw content that will be added to the configuration file.
16309 @end deftypevr
16310
16311 It could be that you just want to get a @code{prosody.cfg.lua}
16312 up and running. In that case, you can pass an
16313 @code{opaque-prosody-configuration} record as the value of
16314 @code{prosody-service-type}. As its name indicates, an opaque configuration
16315 does not have easy reflective capabilities.
16316 Available @code{opaque-prosody-configuration} fields are:
16317
16318 @deftypevr {@code{opaque-prosody-configuration} parameter} package prosody
16319 The prosody package.
16320 @end deftypevr
16321
16322 @deftypevr {@code{opaque-prosody-configuration} parameter} string prosody.cfg.lua
16323 The contents of the @code{prosody.cfg.lua} to use.
16324 @end deftypevr
16325
16326 For example, if your @code{prosody.cfg.lua} is just the empty
16327 string, you could instantiate a prosody service like this:
16328
16329 @example
16330 (service prosody-service-type
16331 (opaque-prosody-configuration
16332 (prosody.cfg.lua "")))
16333 @end example
16334
16335 @c end of Prosody auto-generated documentation
16336
16337 @subsubheading BitlBee Service
16338
16339 @cindex IRC (Internet Relay Chat)
16340 @cindex IRC gateway
16341 @url{http://bitlbee.org,BitlBee} is a gateway that provides an IRC
16342 interface to a variety of messaging protocols such as XMPP.
16343
16344 @defvr {Scheme Variable} bitlbee-service-type
16345 This is the service type for the @url{http://bitlbee.org,BitlBee} IRC
16346 gateway daemon. Its value is a @code{bitlbee-configuration} (see
16347 below).
16348
16349 To have BitlBee listen on port 6667 on localhost, add this line to your
16350 services:
16351
16352 @example
16353 (service bitlbee-service-type)
16354 @end example
16355 @end defvr
16356
16357 @deftp {Data Type} bitlbee-configuration
16358 This is the configuration for BitlBee, with the following fields:
16359
16360 @table @asis
16361 @item @code{interface} (default: @code{"127.0.0.1"})
16362 @itemx @code{port} (default: @code{6667})
16363 Listen on the network interface corresponding to the IP address
16364 specified in @var{interface}, on @var{port}.
16365
16366 When @var{interface} is @code{127.0.0.1}, only local clients can
16367 connect; when it is @code{0.0.0.0}, connections can come from any
16368 networking interface.
16369
16370 @item @code{package} (default: @code{bitlbee})
16371 The BitlBee package to use.
16372
16373 @item @code{plugins} (default: @code{'()})
16374 List of plugin packages to use---e.g., @code{bitlbee-discord}.
16375
16376 @item @code{extra-settings} (default: @code{""})
16377 Configuration snippet added as-is to the BitlBee configuration file.
16378 @end table
16379 @end deftp
16380
16381 @subsubheading Quassel Service
16382
16383 @cindex IRC (Internet Relay Chat)
16384 @url{https://quassel-irc.org/,Quassel} is a distributed IRC client,
16385 meaning that one or more clients can attach to and detach from the
16386 central core.
16387
16388 @defvr {Scheme Variable} quassel-service-type
16389 This is the service type for the @url{https://quassel-irc.org/,Quassel}
16390 IRC backend daemon. Its value is a @code{quassel-configuration}
16391 (see below).
16392 @end defvr
16393
16394 @deftp {Data Type} quassel-configuration
16395 This is the configuration for Quassel, with the following fields:
16396
16397 @table @asis
16398 @item @code{quassel} (default: @code{quassel})
16399 The Quassel package to use.
16400
16401 @item @code{interface} (default: @code{"::,0.0.0.0"})
16402 @item @code{port} (default: @code{4242})
16403 Listen on the network interface(s) corresponding to the IPv4 or IPv6
16404 interfaces specified in the comma delimited @var{interface}, on
16405 @var{port}.
16406
16407 @item @code{loglevel} (default: @code{"Info"})
16408 The level of logging desired. Accepted values are Debug, Info, Warning
16409 and Error.
16410 @end table
16411 @end deftp
16412
16413 @node Telephony Services
16414 @subsubsection Telephony Services
16415
16416 @cindex Murmur (VoIP server)
16417 @cindex VoIP server
16418 This section describes how to set up and run a Murmur server. Murmur is
16419 the server of the @uref{https://mumble.info, Mumble} voice-over-IP
16420 (VoIP) suite.
16421
16422 @deftp {Data Type} murmur-configuration
16423 The service type for the Murmur server. An example configuration can
16424 look like this:
16425
16426 @example
16427 (service murmur-service-type
16428 (murmur-configuration
16429 (welcome-text
16430 "Welcome to this Mumble server running on GuixSD!")
16431 (cert-required? #t) ;disallow text password logins
16432 (ssl-cert "/etc/letsencrypt/live/mumble.example.com/fullchain.pem")
16433 (ssl-key "/etc/letsencrypt/live/mumble.example.com/privkey.pem")))
16434 @end example
16435
16436 After reconfiguring your system, you can manually set the murmur @code{SuperUser}
16437 password with the command that is printed during the activation phase.
16438
16439 It is recommended to register a normal Mumble user account
16440 and grant it admin or moderator rights.
16441 You can use the @code{mumble} client to
16442 login as new normal user, register yourself, and log out.
16443 For the next step login with the name @code{SuperUser} use
16444 the @code{SuperUser} password that you set previously,
16445 and grant your newly registered mumble user administrator or moderator
16446 rights and create some channels.
16447
16448 Available @code{murmur-configuration} fields are:
16449
16450 @table @asis
16451 @item @code{package} (default: @code{mumble})
16452 Package that contains @code{bin/murmurd}.
16453
16454 @item @code{user} (default: @code{"murmur"})
16455 User who will run the Murmur server.
16456
16457 @item @code{group} (default: @code{"murmur"})
16458 Group of the user who will run the murmur server.
16459
16460 @item @code{port} (default: @code{64738})
16461 Port on which the server will listen.
16462
16463 @item @code{welcome-text} (default: @code{""})
16464 Welcome text sent to clients when they connect.
16465
16466 @item @code{server-password} (default: @code{""})
16467 Password the clients have to enter in order to connect.
16468
16469 @item @code{max-users} (default: @code{100})
16470 Maximum of users that can be connected to the server at once.
16471
16472 @item @code{max-user-bandwidth} (default: @code{#f})
16473 Maximum voice traffic a user can send per second.
16474
16475 @item @code{database-file} (default: @code{"/var/lib/murmur/db.sqlite"})
16476 File name of the sqlite database.
16477 The service's user will become the owner of the directory.
16478
16479 @item @code{log-file} (default: @code{"/var/log/murmur/murmur.log"})
16480 File name of the log file.
16481 The service's user will become the owner of the directory.
16482
16483 @item @code{autoban-attempts} (default: @code{10})
16484 Maximum number of logins a user can make in @code{autoban-timeframe}
16485 without getting auto banned for @code{autoban-time}.
16486
16487 @item @code{autoban-timeframe} (default: @code{120})
16488 Timeframe for autoban in seconds.
16489
16490 @item @code{autoban-time} (default: @code{300})
16491 Amount of time in seconds for which a client gets banned
16492 when violating the autoban limits.
16493
16494 @item @code{opus-threshold} (default: @code{100})
16495 Percentage of clients that need to support opus
16496 before switching over to opus audio codec.
16497
16498 @item @code{channel-nesting-limit} (default: @code{10})
16499 How deep channels can be nested at maximum.
16500
16501 @item @code{channelname-regex} (default: @code{#f})
16502 A string in form of a Qt regular expression that channel names must conform to.
16503
16504 @item @code{username-regex} (default: @code{#f})
16505 A string in form of a Qt regular expression that user names must conform to.
16506
16507 @item @code{text-message-length} (default: @code{5000})
16508 Maximum size in bytes that a user can send in one text chat message.
16509
16510 @item @code{image-message-length} (default: @code{(* 128 1024)})
16511 Maximum size in bytes that a user can send in one image message.
16512
16513 @item @code{cert-required?} (default: @code{#f})
16514 If it is set to @code{#t} clients that use weak password authentification
16515 will not be accepted. Users must have completed the certificate wizard to join.
16516
16517 @item @code{remember-channel?} (default: @code{#f})
16518 Should murmur remember the last channel each user was in when they disconnected
16519 and put them into the remembered channel when they rejoin.
16520
16521 @item @code{allow-html?} (default: @code{#f})
16522 Should html be allowed in text messages, user comments, and channel descriptions.
16523
16524 @item @code{allow-ping?} (default: @code{#f})
16525 Setting to true exposes the current user count, the maximum user count, and
16526 the server's maximum bandwidth per client to unauthenticated users. In the
16527 Mumble client, this information is shown in the Connect dialog.
16528
16529 Disabling this setting will prevent public listing of the server.
16530
16531 @item @code{bonjour?} (default: @code{#f})
16532 Should the server advertise itself in the local network through the bonjour protocol.
16533
16534 @item @code{send-version?} (default: @code{#f})
16535 Should the murmur server version be exposed in ping requests.
16536
16537 @item @code{log-days} (default: @code{31})
16538 Murmur also stores logs in the database, which are accessible via RPC.
16539 The default is 31 days of months, but you can set this setting to 0 to keep logs forever,
16540 or -1 to disable logging to the database.
16541
16542 @item @code{obfuscate-ips?} (default: @code{#t})
16543 Should logged ips be obfuscated to protect the privacy of users.
16544
16545 @item @code{ssl-cert} (default: @code{#f})
16546 File name of the SSL/TLS certificate used for encrypted connections.
16547
16548 @example
16549 (ssl-cert "/etc/letsencrypt/live/example.com/fullchain.pem")
16550 @end example
16551 @item @code{ssl-key} (default: @code{#f})
16552 Filepath to the ssl private key used for encrypted connections.
16553 @example
16554 (ssl-key "/etc/letsencrypt/live/example.com/privkey.pem")
16555 @end example
16556
16557 @item @code{ssl-dh-params} (default: @code{#f})
16558 File name of a PEM-encoded file with Diffie-Hellman parameters
16559 for the SSL/TLS encryption. Alternatively you set it to
16560 @code{"@@ffdhe2048"}, @code{"@@ffdhe3072"}, @code{"@@ffdhe4096"}, @code{"@@ffdhe6144"}
16561 or @code{"@@ffdhe8192"} to use bundled parameters from RFC 7919.
16562
16563 @item @code{ssl-ciphers} (default: @code{#f})
16564 The @code{ssl-ciphers} option chooses the cipher suites to make available for use
16565 in SSL/TLS.
16566
16567 This option is specified using
16568 @uref{https://www.openssl.org/docs/apps/ciphers.html#CIPHER-LIST-FORMAT,
16569 OpenSSL cipher list notation}.
16570
16571 It is recommended that you try your cipher string using 'openssl ciphers <string>'
16572 before setting it here, to get a feel for which cipher suites you will get.
16573 After setting this option, it is recommend that you inspect your Murmur log
16574 to ensure that Murmur is using the cipher suites that you expected it to.
16575
16576 Note: Changing this option may impact the backwards compatibility of your
16577 Murmur server, and can remove the ability for older Mumble clients to be able
16578 to connect to it.
16579
16580 @item @code{public-registration} (default: @code{#f})
16581 Must be a @code{<murmur-public-registration-configuration>} record or @code{#f}.
16582
16583 You can optionally register your server in the public server list that the
16584 @code{mumble} client shows on startup.
16585 You cannot register your server if you have set a @code{server-password},
16586 or set @code{allow-ping} to @code{#f}.
16587
16588 It might take a few hours until it shows up in the public list.
16589
16590 @item @code{file} (default: @code{#f})
16591 Optional alternative override for this configuration.
16592 @end table
16593 @end deftp
16594
16595 @deftp {Data Type} murmur-public-registration-configuration
16596 Configuration for public registration of a murmur service.
16597
16598 @table @asis
16599 @item @code{name}
16600 This is a display name for your server. Not to be confused with the hostname.
16601
16602 @item @code{password}
16603 A password to identify your registration.
16604 Subsequent updates will need the same password. Don't lose your password.
16605
16606 @item @code{url}
16607 This should be a @code{http://} or @code{https://} link to your web
16608 site.
16609
16610 @item @code{hostname} (default: @code{#f})
16611 By default your server will be listed by its IP address.
16612 If it is set your server will be linked by this host name instead.
16613 @end table
16614 @end deftp
16615
16616
16617
16618 @node Monitoring Services
16619 @subsubsection Monitoring Services
16620
16621 @subsubheading Tailon Service
16622
16623 @uref{https://tailon.readthedocs.io/, Tailon} is a web application for
16624 viewing and searching log files.
16625
16626 The following example will configure the service with default values.
16627 By default, Tailon can be accessed on port 8080 (@code{http://localhost:8080}).
16628
16629 @example
16630 (service tailon-service-type)
16631 @end example
16632
16633 The following example customises more of the Tailon configuration,
16634 adding @command{sed} to the list of allowed commands.
16635
16636 @example
16637 (service tailon-service-type
16638 (tailon-configuration
16639 (config-file
16640 (tailon-configuration-file
16641 (allowed-commands '("tail" "grep" "awk" "sed"))))))
16642 @end example
16643
16644
16645 @deftp {Data Type} tailon-configuration
16646 Data type representing the configuration of Tailon.
16647 This type has the following parameters:
16648
16649 @table @asis
16650 @item @code{config-file} (default: @code{(tailon-configuration-file)})
16651 The configuration file to use for Tailon. This can be set to a
16652 @dfn{tailon-configuration-file} record value, or any gexp
16653 (@pxref{G-Expressions}).
16654
16655 For example, to instead use a local file, the @code{local-file} function
16656 can be used:
16657
16658 @example
16659 (service tailon-service-type
16660 (tailon-configuration
16661 (config-file (local-file "./my-tailon.conf"))))
16662 @end example
16663
16664 @item @code{package} (default: @code{tailon})
16665 The tailon package to use.
16666
16667 @end table
16668 @end deftp
16669
16670 @deftp {Data Type} tailon-configuration-file
16671 Data type representing the configuration options for Tailon.
16672 This type has the following parameters:
16673
16674 @table @asis
16675 @item @code{files} (default: @code{(list "/var/log")})
16676 List of files to display. The list can include strings for a single file
16677 or directory, or a list, where the first item is the name of a
16678 subsection, and the remaining items are the files or directories in that
16679 subsection.
16680
16681 @item @code{bind} (default: @code{"localhost:8080"})
16682 Address and port to which Tailon should bind on.
16683
16684 @item @code{relative-root} (default: @code{#f})
16685 URL path to use for Tailon, set to @code{#f} to not use a path.
16686
16687 @item @code{allow-transfers?} (default: @code{#t})
16688 Allow downloading the log files in the web interface.
16689
16690 @item @code{follow-names?} (default: @code{#t})
16691 Allow tailing of not-yet existent files.
16692
16693 @item @code{tail-lines} (default: @code{200})
16694 Number of lines to read initially from each file.
16695
16696 @item @code{allowed-commands} (default: @code{(list "tail" "grep" "awk")})
16697 Commands to allow running. By default, @code{sed} is disabled.
16698
16699 @item @code{debug?} (default: @code{#f})
16700 Set @code{debug?} to @code{#t} to show debug messages.
16701
16702 @item @code{wrap-lines} (default: @code{#t})
16703 Initial line wrapping state in the web interface. Set to @code{#t} to
16704 initially wrap lines (the default), or to @code{#f} to initially not
16705 wrap lines.
16706
16707 @item @code{http-auth} (default: @code{#f})
16708 HTTP authentication type to use. Set to @code{#f} to disable
16709 authentication (the default). Supported values are @code{"digest"} or
16710 @code{"basic"}.
16711
16712 @item @code{users} (default: @code{#f})
16713 If HTTP authentication is enabled (see @code{http-auth}), access will be
16714 restricted to the credentials provided here. To configure users, use a
16715 list of pairs, where the first element of the pair is the username, and
16716 the 2nd element of the pair is the password.
16717
16718 @example
16719 (tailon-configuration-file
16720 (http-auth "basic")
16721 (users '(("user1" . "password1")
16722 ("user2" . "password2"))))
16723 @end example
16724
16725 @end table
16726 @end deftp
16727
16728
16729 @subsubheading Darkstat Service
16730 @cindex darkstat
16731 Darkstat is a packet sniffer that captures network traffic, calculates
16732 statistics about usage, and serves reports over HTTP.
16733
16734 @defvar {Scheme Variable} darkstat-service-type
16735 This is the service type for the
16736 @uref{https://unix4lyfe.org/darkstat/, darkstat}
16737 service, its value must be a @code{darkstat-configuration} record as in
16738 this example:
16739
16740 @example
16741 (service darkstat-service-type
16742 (darkstat-configuration
16743 (interface "eno1")))
16744 @end example
16745 @end defvar
16746
16747 @deftp {Data Type} darkstat-configuration
16748 Data type representing the configuration of @command{darkstat}.
16749
16750 @table @asis
16751 @item @code{package} (default: @code{darkstat})
16752 The darkstat package to use.
16753
16754 @item @code{interface}
16755 Capture traffic on the specified network interface.
16756
16757 @item @code{port} (default: @code{"667"})
16758 Bind the web interface to the specified port.
16759
16760 @item @code{bind-address} (default: @code{"127.0.0.1"})
16761 Bind the web interface to the specified address.
16762
16763 @item @code{base} (default: @code{"/"})
16764 Specify the path of the base URL. This can be useful if
16765 @command{darkstat} is accessed via a reverse proxy.
16766
16767 @end table
16768 @end deftp
16769
16770 @subsubheading Prometheus Node Exporter Service
16771
16772 @cindex prometheus-node-exporter
16773 The Prometheus ``node exporter'' makes hardware and operating system statistics
16774 provided by the Linux kernel available for the Prometheus monitoring system.
16775 This service should be deployed on all physical nodes and virtual machines,
16776 where monitoring these statistics is desirable.
16777
16778 @defvar {Scheme variable} prometheus-node-exporter-service-type
16779 This is the service type for the
16780 @uref{https://github.com/prometheus/node_exporter/, prometheus-node-exporter}
16781 service, its value must be a @code{prometheus-node-exporter-configuration}
16782 record as in this example:
16783
16784 @example
16785 (service prometheus-node-exporter-service-type
16786 (prometheus-node-exporter-configuration
16787 (web-listen-address ":9100")))
16788 @end example
16789 @end defvar
16790
16791 @deftp {Data Type} prometheus-node-exporter-configuration
16792 Data type representing the configuration of @command{node_exporter}.
16793
16794 @table @asis
16795 @item @code{package} (default: @code{go-github-com-prometheus-node-exporter})
16796 The prometheus-node-exporter package to use.
16797
16798 @item @code{web-listen-address} (default: @code{":9100"})
16799 Bind the web interface to the specified address.
16800
16801 @end table
16802 @end deftp
16803
16804 @subsubheading Zabbix server
16805 @cindex zabbix zabbix-server
16806 Zabbix provides monitoring metrics, among others network utilization, CPU load
16807 and disk space consumption:
16808
16809 @itemize
16810 @item High performance, high capacity (able to monitor hundreds of thousands of devices).
16811 @item Auto-discovery of servers and network devices and interfaces.
16812 @item Low-level discovery, allows to automatically start monitoring new items, file systems or network interfaces among others.
16813 @item Distributed monitoring with centralized web administration.
16814 @item Native high performance agents.
16815 @item SLA, and ITIL KPI metrics on reporting.
16816 @item High-level (business) view of monitored resources through user-defined visual console screens and dashboards.
16817 @item Remote command execution through Zabbix proxies.
16818 @end itemize
16819
16820 @c %start of fragment
16821
16822 Available @code{zabbix-server-configuration} fields are:
16823
16824 @deftypevr {@code{zabbix-server-configuration} parameter} package zabbix-server
16825 The zabbix-server package.
16826
16827 @end deftypevr
16828
16829 @deftypevr {@code{zabbix-server-configuration} parameter} string user
16830 User who will run the Zabbix server.
16831
16832 Defaults to @samp{"zabbix"}.
16833
16834 @end deftypevr
16835
16836 @deftypevr {@code{zabbix-server-configuration} parameter} group group
16837 Group who will run the Zabbix server.
16838
16839 Defaults to @samp{"zabbix"}.
16840
16841 @end deftypevr
16842
16843 @deftypevr {@code{zabbix-server-configuration} parameter} string db-host
16844 Database host name.
16845
16846 Defaults to @samp{"127.0.0.1"}.
16847
16848 @end deftypevr
16849
16850 @deftypevr {@code{zabbix-server-configuration} parameter} string db-name
16851 Database name.
16852
16853 Defaults to @samp{"zabbix"}.
16854
16855 @end deftypevr
16856
16857 @deftypevr {@code{zabbix-server-configuration} parameter} string db-user
16858 Database user.
16859
16860 Defaults to @samp{"zabbix"}.
16861
16862 @end deftypevr
16863
16864 @deftypevr {@code{zabbix-server-configuration} parameter} string db-password
16865 Database password. Please, use @code{include-files} with
16866 @code{DBPassword=SECRET} inside a specified file instead.
16867
16868 Defaults to @samp{""}.
16869
16870 @end deftypevr
16871
16872 @deftypevr {@code{zabbix-server-configuration} parameter} number db-port
16873 Database port.
16874
16875 Defaults to @samp{5432}.
16876
16877 @end deftypevr
16878
16879 @deftypevr {@code{zabbix-server-configuration} parameter} string log-type
16880 Specifies where log messages are written to:
16881
16882 @itemize @bullet
16883 @item
16884 @code{system} - syslog.
16885
16886 @item
16887 @code{file} - file specified with @code{log-file} parameter.
16888
16889 @item
16890 @code{console} - standard output.
16891
16892 @end itemize
16893
16894 Defaults to @samp{""}.
16895
16896 @end deftypevr
16897
16898 @deftypevr {@code{zabbix-server-configuration} parameter} string log-file
16899 Log file name for @code{log-type} @code{file} parameter.
16900
16901 Defaults to @samp{"/var/log/zabbix/server.log"}.
16902
16903 @end deftypevr
16904
16905 @deftypevr {@code{zabbix-server-configuration} parameter} string pid-file
16906 Name of PID file.
16907
16908 Defaults to @samp{"/var/run/zabbix/zabbix_server.pid"}.
16909
16910 @end deftypevr
16911
16912 @deftypevr {@code{zabbix-server-configuration} parameter} string ssl-ca-location
16913 The location of certificate authority (CA) files for SSL server
16914 certificate verification.
16915
16916 Defaults to @samp{"/etc/ssl/certs/ca-certificates.crt"}.
16917
16918 @end deftypevr
16919
16920 @deftypevr {@code{zabbix-server-configuration} parameter} string ssl-cert-location
16921 Location of SSL client certificates.
16922
16923 Defaults to @samp{"/etc/ssl/certs"}.
16924
16925 @end deftypevr
16926
16927 @deftypevr {@code{zabbix-server-configuration} parameter} string extra-options
16928 Extra options will be appended to Zabbix server configuration file.
16929
16930 Defaults to @samp{""}.
16931
16932 @end deftypevr
16933
16934 @deftypevr {@code{zabbix-server-configuration} parameter} include-files include-files
16935 You may include individual files or all files in a directory in the
16936 configuration file.
16937
16938 Defaults to @samp{()}.
16939
16940 @end deftypevr
16941
16942 @c %end of fragment
16943
16944 @subsubheading Zabbix agent
16945 @cindex zabbix zabbix-agent
16946
16947 Zabbix agent gathers information for Zabbix server.
16948
16949 @c %start of fragment
16950
16951 Available @code{zabbix-agent-configuration} fields are:
16952
16953 @deftypevr {@code{zabbix-agent-configuration} parameter} package zabbix-agent
16954 The zabbix-agent package.
16955
16956 @end deftypevr
16957
16958 @deftypevr {@code{zabbix-agent-configuration} parameter} string user
16959 User who will run the Zabbix agent.
16960
16961 Defaults to @samp{"zabbix"}.
16962
16963 @end deftypevr
16964
16965 @deftypevr {@code{zabbix-agent-configuration} parameter} group group
16966 Group who will run the Zabbix agent.
16967
16968 Defaults to @samp{"zabbix"}.
16969
16970 @end deftypevr
16971
16972 @deftypevr {@code{zabbix-agent-configuration} parameter} string hostname
16973 Unique, case sensitive hostname which is required for active checks and
16974 must match hostname as configured on the server.
16975
16976 Defaults to @samp{"Zabbix server"}.
16977
16978 @end deftypevr
16979
16980 @deftypevr {@code{zabbix-agent-configuration} parameter} string log-type
16981 Specifies where log messages are written to:
16982
16983 @itemize @bullet
16984 @item
16985 @code{system} - syslog.
16986
16987 @item
16988 @code{file} - file specified with @code{log-file} parameter.
16989
16990 @item
16991 @code{console} - standard output.
16992
16993 @end itemize
16994
16995 Defaults to @samp{""}.
16996
16997 @end deftypevr
16998
16999 @deftypevr {@code{zabbix-agent-configuration} parameter} string log-file
17000 Log file name for @code{log-type} @code{file} parameter.
17001
17002 Defaults to @samp{"/var/log/zabbix/agent.log"}.
17003
17004 @end deftypevr
17005
17006 @deftypevr {@code{zabbix-agent-configuration} parameter} string pid-file
17007 Name of PID file.
17008
17009 Defaults to @samp{"/var/run/zabbix/zabbix_agent.pid"}.
17010
17011 @end deftypevr
17012
17013 @deftypevr {@code{zabbix-agent-configuration} parameter} list server
17014 List of IP addresses, optionally in CIDR notation, or hostnames of
17015 Zabbix servers and Zabbix proxies. Incoming connections will be
17016 accepted only from the hosts listed here.
17017
17018 Defaults to @samp{("127.0.0.1")}.
17019
17020 @end deftypevr
17021
17022 @deftypevr {@code{zabbix-agent-configuration} parameter} list server-active
17023 List of IP:port (or hostname:port) pairs of Zabbix servers and Zabbix
17024 proxies for active checks. If port is not specified, default port is
17025 used. If this parameter is not specified, active checks are disabled.
17026
17027 Defaults to @samp{("127.0.0.1")}.
17028
17029 @end deftypevr
17030
17031 @deftypevr {@code{zabbix-agent-configuration} parameter} string extra-options
17032 Extra options will be appended to Zabbix server configuration file.
17033
17034 Defaults to @samp{""}.
17035
17036 @end deftypevr
17037
17038 @deftypevr {@code{zabbix-agent-configuration} parameter} include-files include-files
17039 You may include individual files or all files in a directory in the
17040 configuration file.
17041
17042 Defaults to @samp{()}.
17043
17044 @end deftypevr
17045
17046 @c %end of fragment
17047
17048 @subsubheading Zabbix front-end
17049 @cindex zabbix zabbix-front-end
17050
17051 This service provides a WEB interface to Zabbix server.
17052
17053 @c %start of fragment
17054
17055 Available @code{zabbix-front-end-configuration} fields are:
17056
17057 @deftypevr {@code{zabbix-front-end-configuration} parameter} nginx-server-configuration-list nginx
17058 NGINX configuration.
17059
17060 @end deftypevr
17061
17062 @deftypevr {@code{zabbix-front-end-configuration} parameter} string db-host
17063 Database host name.
17064
17065 Defaults to @samp{"localhost"}.
17066
17067 @end deftypevr
17068
17069 @deftypevr {@code{zabbix-front-end-configuration} parameter} number db-port
17070 Database port.
17071
17072 Defaults to @samp{5432}.
17073
17074 @end deftypevr
17075
17076 @deftypevr {@code{zabbix-front-end-configuration} parameter} string db-name
17077 Database name.
17078
17079 Defaults to @samp{"zabbix"}.
17080
17081 @end deftypevr
17082
17083 @deftypevr {@code{zabbix-front-end-configuration} parameter} string db-user
17084 Database user.
17085
17086 Defaults to @samp{"zabbix"}.
17087
17088 @end deftypevr
17089
17090 @deftypevr {@code{zabbix-front-end-configuration} parameter} string db-password
17091 Database password. Please, use @code{db-secret-file} instead.
17092
17093 Defaults to @samp{""}.
17094
17095 @end deftypevr
17096
17097 @deftypevr {@code{zabbix-front-end-configuration} parameter} string db-secret-file
17098 Secret file which will be appended to @file{zabbix.conf.php} file. This
17099 file contains credentials for use by Zabbix front-end. You are expected
17100 to create it manually.
17101
17102 Defaults to @samp{""}.
17103
17104 @end deftypevr
17105
17106 @deftypevr {@code{zabbix-front-end-configuration} parameter} string zabbix-host
17107 Zabbix server hostname.
17108
17109 Defaults to @samp{"localhost"}.
17110
17111 @end deftypevr
17112
17113 @deftypevr {@code{zabbix-front-end-configuration} parameter} number zabbix-port
17114 Zabbix server port.
17115
17116 Defaults to @samp{10051}.
17117
17118 @end deftypevr
17119
17120
17121 @c %end of fragment
17122
17123 @node Kerberos Services
17124 @subsubsection Kerberos Services
17125 @cindex Kerberos
17126
17127 The @code{(gnu services kerberos)} module provides services relating to
17128 the authentication protocol @dfn{Kerberos}.
17129
17130 @subsubheading Krb5 Service
17131
17132 Programs using a Kerberos client library normally
17133 expect a configuration file in @file{/etc/krb5.conf}.
17134 This service generates such a file from a definition provided in the
17135 operating system declaration.
17136 It does not cause any daemon to be started.
17137
17138 No ``keytab'' files are provided by this service---you must explicitly create them.
17139 This service is known to work with the MIT client library, @code{mit-krb5}.
17140 Other implementations have not been tested.
17141
17142 @defvr {Scheme Variable} krb5-service-type
17143 A service type for Kerberos 5 clients.
17144 @end defvr
17145
17146 @noindent
17147 Here is an example of its use:
17148 @lisp
17149 (service krb5-service-type
17150 (krb5-configuration
17151 (default-realm "EXAMPLE.COM")
17152 (allow-weak-crypto? #t)
17153 (realms (list
17154 (krb5-realm
17155 (name "EXAMPLE.COM")
17156 (admin-server "groucho.example.com")
17157 (kdc "karl.example.com"))
17158 (krb5-realm
17159 (name "ARGRX.EDU")
17160 (admin-server "kerb-admin.argrx.edu")
17161 (kdc "keys.argrx.edu"))))))
17162 @end lisp
17163
17164 @noindent
17165 This example provides a Kerberos@tie{}5 client configuration which:
17166 @itemize
17167 @item Recognizes two realms, @i{viz:} ``EXAMPLE.COM'' and ``ARGRX.EDU'', both
17168 of which have distinct administration servers and key distribution centers;
17169 @item Will default to the realm ``EXAMPLE.COM'' if the realm is not explicitly
17170 specified by clients;
17171 @item Accepts services which only support encryption types known to be weak.
17172 @end itemize
17173
17174 The @code{krb5-realm} and @code{krb5-configuration} types have many fields.
17175 Only the most commonly used ones are described here.
17176 For a full list, and more detailed explanation of each, see the MIT
17177 @uref{http://web.mit.edu/kerberos/krb5-devel/doc/admin/conf_files/krb5_conf.html,,krb5.conf}
17178 documentation.
17179
17180
17181 @deftp {Data Type} krb5-realm
17182 @cindex realm, kerberos
17183 @table @asis
17184 @item @code{name}
17185 This field is a string identifying the name of the realm.
17186 A common convention is to use the fully qualified DNS name of your organization,
17187 converted to upper case.
17188
17189 @item @code{admin-server}
17190 This field is a string identifying the host where the administration server is
17191 running.
17192
17193 @item @code{kdc}
17194 This field is a string identifying the key distribution center
17195 for the realm.
17196 @end table
17197 @end deftp
17198
17199 @deftp {Data Type} krb5-configuration
17200
17201 @table @asis
17202 @item @code{allow-weak-crypto?} (default: @code{#f})
17203 If this flag is @code{#t} then services which only offer encryption algorithms
17204 known to be weak will be accepted.
17205
17206 @item @code{default-realm} (default: @code{#f})
17207 This field should be a string identifying the default Kerberos
17208 realm for the client.
17209 You should set this field to the name of your Kerberos realm.
17210 If this value is @code{#f}
17211 then a realm must be specified with every Kerberos principal when invoking programs
17212 such as @command{kinit}.
17213
17214 @item @code{realms}
17215 This should be a non-empty list of @code{krb5-realm} objects, which clients may
17216 access.
17217 Normally, one of them will have a @code{name} field matching the @code{default-realm}
17218 field.
17219 @end table
17220 @end deftp
17221
17222
17223 @subsubheading PAM krb5 Service
17224 @cindex pam-krb5
17225
17226 The @code{pam-krb5} service allows for login authentication and password
17227 management via Kerberos.
17228 You will need this service if you want PAM enabled applications to authenticate
17229 users using Kerberos.
17230
17231 @defvr {Scheme Variable} pam-krb5-service-type
17232 A service type for the Kerberos 5 PAM module.
17233 @end defvr
17234
17235 @deftp {Data Type} pam-krb5-configuration
17236 Data type representing the configuration of the Kerberos 5 PAM module
17237 This type has the following parameters:
17238 @table @asis
17239 @item @code{pam-krb5} (default: @code{pam-krb5})
17240 The pam-krb5 package to use.
17241
17242 @item @code{minimum-uid} (default: @code{1000})
17243 The smallest user ID for which Kerberos authentications should be attempted.
17244 Local accounts with lower values will silently fail to authenticate.
17245 @end table
17246 @end deftp
17247
17248
17249 @node Web Services
17250 @subsubsection Web Services
17251
17252 @cindex web
17253 @cindex www
17254 @cindex HTTP
17255 The @code{(gnu services web)} module provides the Apache HTTP Server,
17256 the nginx web server, and also a fastcgi wrapper daemon.
17257
17258 @subsubheading Apache HTTP Server
17259
17260 @deffn {Scheme Variable} httpd-service-type
17261 Service type for the @uref{https://httpd.apache.org/,Apache HTTP} server
17262 (@dfn{httpd}). The value for this service type is a
17263 @code{httpd-configuration} record.
17264
17265 A simple example configuration is given below.
17266
17267 @example
17268 (service httpd-service-type
17269 (httpd-configuration
17270 (config
17271 (httpd-config-file
17272 (server-name "www.example.com")
17273 (document-root "/srv/http/www.example.com")))))
17274 @end example
17275
17276 Other services can also extend the @code{httpd-service-type} to add to
17277 the configuration.
17278
17279 @example
17280 (simple-service 'my-extra-server httpd-service-type
17281 (list
17282 (httpd-virtualhost
17283 "*:80"
17284 (list (string-append
17285 "ServerName "www.example.com
17286 DocumentRoot \"/srv/http/www.example.com\"")))))
17287 @end example
17288 @end deffn
17289
17290 The details for the @code{httpd-configuration}, @code{httpd-module},
17291 @code{httpd-config-file} and @code{httpd-virtualhost} record types are
17292 given below.
17293
17294 @deffn {Data Type} httpd-configuration
17295 This data type represents the configuration for the httpd service.
17296
17297 @table @asis
17298 @item @code{package} (default: @code{httpd})
17299 The httpd package to use.
17300
17301 @item @code{pid-file} (default: @code{"/var/run/httpd"})
17302 The pid file used by the shepherd-service.
17303
17304 @item @code{config} (default: @code{(httpd-config-file)})
17305 The configuration file to use with the httpd service. The default value
17306 is a @code{httpd-config-file} record, but this can also be a different
17307 G-expression that generates a file, for example a @code{plain-file}. A
17308 file outside of the store can also be specified through a string.
17309
17310 @end table
17311 @end deffn
17312
17313 @deffn {Data Type} httpd-module
17314 This data type represents a module for the httpd service.
17315
17316 @table @asis
17317 @item @code{name}
17318 The name of the module.
17319
17320 @item @code{file}
17321 The file for the module. This can be relative to the httpd package being
17322 used, the absolute location of a file, or a G-expression for a file
17323 within the store, for example @code{(file-append mod-wsgi
17324 "/modules/mod_wsgi.so")}.
17325
17326 @end table
17327 @end deffn
17328
17329 @defvr {Scheme Variable} %default-httpd-modules
17330 A default list of @code{httpd-module} objects.
17331 @end defvr
17332
17333 @deffn {Data Type} httpd-config-file
17334 This data type represents a configuration file for the httpd service.
17335
17336 @table @asis
17337 @item @code{modules} (default: @code{%default-httpd-modules})
17338 The modules to load. Additional modules can be added here, or loaded by
17339 additional configuration.
17340
17341 For example, in order to handle requests for PHP files, you can use Apache’s
17342 @code{mod_proxy_fcgi} module along with @code{php-fpm-service-type}:
17343
17344 @example
17345 (service httpd-service-type
17346 (httpd-configuration
17347 (config
17348 (httpd-config-file
17349 (modules (cons*
17350 (httpd-module
17351 (name "proxy_module")
17352 (file "modules/mod_proxy.so"))
17353 (httpd-module
17354 (name "proxy_fcgi_module")
17355 (file "modules/mod_proxy_fcgi.so"))
17356 %default-httpd-modules))
17357 (extra-config (list "\
17358 <FilesMatch \\.php$>
17359 SetHandler \"proxy:unix:/var/run/php-fpm.sock|fcgi://localhost/\"
17360 </FilesMatch>"))))))
17361 (service php-fpm-service-type
17362 (php-fpm-configuration
17363 (socket "/var/run/php-fpm.sock")
17364 (socket-group "httpd")))
17365 @end example
17366
17367 @item @code{server-root} (default: @code{httpd})
17368 The @code{ServerRoot} in the configuration file, defaults to the httpd
17369 package. Directives including @code{Include} and @code{LoadModule} are
17370 taken as relative to the server root.
17371
17372 @item @code{server-name} (default: @code{#f})
17373 The @code{ServerName} in the configuration file, used to specify the
17374 request scheme, hostname and port that the server uses to identify
17375 itself.
17376
17377 This doesn't need to be set in the server config, and can be specifyed
17378 in virtual hosts. The default is @code{#f} to not specify a
17379 @code{ServerName}.
17380
17381 @item @code{document-root} (default: @code{"/srv/http"})
17382 The @code{DocumentRoot} from which files will be served.
17383
17384 @item @code{listen} (default: @code{'("80")})
17385 The list of values for the @code{Listen} directives in the config
17386 file. The value should be a list of strings, when each string can
17387 specify the port number to listen on, and optionally the IP address and
17388 protocol to use.
17389
17390 @item @code{pid-file} (default: @code{"/var/run/httpd"})
17391 The @code{PidFile} to use. This should match the @code{pid-file} set in
17392 the @code{httpd-configuration} so that the Shepherd service is
17393 configured correctly.
17394
17395 @item @code{error-log} (default: @code{"/var/log/httpd/error_log"})
17396 The @code{ErrorLog} to which the server will log errors.
17397
17398 @item @code{user} (default: @code{"httpd"})
17399 The @code{User} which the server will answer requests as.
17400
17401 @item @code{group} (default: @code{"httpd"})
17402 The @code{Group} which the server will answer requests as.
17403
17404 @item @code{extra-config} (default: @code{(list "TypesConfig etc/httpd/mime.types")})
17405 A flat list of strings and G-expressions which will be added to the end
17406 of the configuration file.
17407
17408 Any values which the service is extended with will be appended to this
17409 list.
17410
17411 @end table
17412 @end deffn
17413
17414 @deffn {Data Type} httpd-virtualhost
17415 This data type represents a virtualhost configuration block for the httpd service.
17416
17417 These should be added to the extra-config for the httpd-service.
17418
17419 @example
17420 (simple-service 'my-extra-server httpd-service-type
17421 (list
17422 (httpd-virtualhost
17423 "*:80"
17424 (list (string-append
17425 "ServerName "www.example.com
17426 DocumentRoot \"/srv/http/www.example.com\"")))))
17427 @end example
17428
17429 @table @asis
17430 @item @code{addresses-and-ports}
17431 The addresses and ports for the @code{VirtualHost} directive.
17432
17433 @item @code{contents}
17434 The contents of the @code{VirtualHost} directive, this should be a list
17435 of strings and G-expressions.
17436
17437 @end table
17438 @end deffn
17439
17440 @subsubheading NGINX
17441
17442 @deffn {Scheme Variable} nginx-service-type
17443 Service type for the @uref{https://nginx.org/,NGinx} web server. The
17444 value for this service type is a @code{<nginx-configuration>} record.
17445
17446 A simple example configuration is given below.
17447
17448 @example
17449 (service nginx-service-type
17450 (nginx-configuration
17451 (server-blocks
17452 (list (nginx-server-configuration
17453 (server-name '("www.example.com"))
17454 (root "/srv/http/www.example.com"))))))
17455 @end example
17456
17457 In addition to adding server blocks to the service configuration
17458 directly, this service can be extended by other services to add server
17459 blocks, as in this example:
17460
17461 @example
17462 (simple-service 'my-extra-server nginx-service-type
17463 (list (nginx-server-configuration
17464 (root "/srv/http/extra-website")
17465 (try-files (list "$uri" "$uri/index.html")))))
17466 @end example
17467 @end deffn
17468
17469 At startup, @command{nginx} has not yet read its configuration file, so
17470 it uses a default file to log error messages. If it fails to load its
17471 configuration file, that is where error messages are logged. After the
17472 configuration file is loaded, the default error log file changes as per
17473 configuration. In our case, startup error messages can be found in
17474 @file{/var/run/nginx/logs/error.log}, and after configuration in
17475 @file{/var/log/nginx/error.log}. The second location can be changed
17476 with the @var{log-directory} configuration option.
17477
17478 @deffn {Data Type} nginx-configuration
17479 This data type represents the configuration for NGinx. Some
17480 configuration can be done through this and the other provided record
17481 types, or alternatively, a config file can be provided.
17482
17483 @table @asis
17484 @item @code{nginx} (default: @code{nginx})
17485 The nginx package to use.
17486
17487 @item @code{log-directory} (default: @code{"/var/log/nginx"})
17488 The directory to which NGinx will write log files.
17489
17490 @item @code{run-directory} (default: @code{"/var/run/nginx"})
17491 The directory in which NGinx will create a pid file, and write temporary
17492 files.
17493
17494 @item @code{server-blocks} (default: @code{'()})
17495 A list of @dfn{server blocks} to create in the generated configuration
17496 file, the elements should be of type
17497 @code{<nginx-server-configuration>}.
17498
17499 The following example would setup NGinx to serve @code{www.example.com}
17500 from the @code{/srv/http/www.example.com} directory, without using
17501 HTTPS.
17502 @example
17503 (service nginx-service-type
17504 (nginx-configuration
17505 (server-blocks
17506 (list (nginx-server-configuration
17507 (server-name '("www.example.com"))
17508 (root "/srv/http/www.example.com"))))))
17509 @end example
17510
17511 @item @code{upstream-blocks} (default: @code{'()})
17512 A list of @dfn{upstream blocks} to create in the generated configuration
17513 file, the elements should be of type
17514 @code{<nginx-upstream-configuration>}.
17515
17516 Configuring upstreams through the @code{upstream-blocks} can be useful
17517 when combined with @code{locations} in the
17518 @code{<nginx-server-configuration>} records. The following example
17519 creates a server configuration with one location configuration, that
17520 will proxy requests to a upstream configuration, which will handle
17521 requests with two servers.
17522
17523 @example
17524 (service
17525 nginx-service-type
17526 (nginx-configuration
17527 (server-blocks
17528 (list (nginx-server-configuration
17529 (server-name '("www.example.com"))
17530 (root "/srv/http/www.example.com")
17531 (locations
17532 (list
17533 (nginx-location-configuration
17534 (uri "/path1")
17535 (body '("proxy_pass http://server-proxy;"))))))))
17536 (upstream-blocks
17537 (list (nginx-upstream-configuration
17538 (name "server-proxy")
17539 (servers (list "server1.example.com"
17540 "server2.example.com")))))))
17541 @end example
17542
17543 @item @code{file} (default: @code{#f})
17544 If a configuration @var{file} is provided, this will be used, rather than
17545 generating a configuration file from the provided @code{log-directory},
17546 @code{run-directory}, @code{server-blocks} and @code{upstream-blocks}. For
17547 proper operation, these arguments should match what is in @var{file} to ensure
17548 that the directories are created when the service is activated.
17549
17550 This can be useful if you have an existing configuration file, or it's
17551 not possible to do what is required through the other parts of the
17552 nginx-configuration record.
17553
17554 @item @code{server-names-hash-bucket-size} (default: @code{#f})
17555 Bucket size for the server names hash tables, defaults to @code{#f} to
17556 use the size of the processors cache line.
17557
17558 @item @code{server-names-hash-bucket-max-size} (default: @code{#f})
17559 Maximum bucket size for the server names hash tables.
17560
17561 @item @code{extra-content} (default: @code{""})
17562 Extra content for the @code{http} block. Should be string or a string
17563 valued G-expression.
17564
17565 @end table
17566 @end deffn
17567
17568 @deftp {Data Type} nginx-server-configuration
17569 Data type representing the configuration of an nginx server block.
17570 This type has the following parameters:
17571
17572 @table @asis
17573 @item @code{listen} (default: @code{'("80" "443 ssl")})
17574 Each @code{listen} directive sets the address and port for IP, or the
17575 path for a UNIX-domain socket on which the server will accept requests.
17576 Both address and port, or only address or only port can be specified.
17577 An address may also be a hostname, for example:
17578
17579 @example
17580 '("127.0.0.1:8000" "127.0.0.1" "8000" "*:8000" "localhost:8000")
17581 @end example
17582
17583 @item @code{server-name} (default: @code{(list 'default)})
17584 A list of server names this server represents. @code{'default} represents the
17585 default server for connections matching no other server.
17586
17587 @item @code{root} (default: @code{"/srv/http"})
17588 Root of the website nginx will serve.
17589
17590 @item @code{locations} (default: @code{'()})
17591 A list of @dfn{nginx-location-configuration} or
17592 @dfn{nginx-named-location-configuration} records to use within this
17593 server block.
17594
17595 @item @code{index} (default: @code{(list "index.html")})
17596 Index files to look for when clients ask for a directory. If it cannot be found,
17597 Nginx will send the list of files in the directory.
17598
17599 @item @code{try-files} (default: @code{'()})
17600 A list of files whose existence is checked in the specified order.
17601 @code{nginx} will use the first file it finds to process the request.
17602
17603 @item @code{ssl-certificate} (default: @code{#f})
17604 Where to find the certificate for secure connections. Set it to @code{#f} if
17605 you don't have a certificate or you don't want to use HTTPS.
17606
17607 @item @code{ssl-certificate-key} (default: @code{#f})
17608 Where to find the private key for secure connections. Set it to @code{#f} if
17609 you don't have a key or you don't want to use HTTPS.
17610
17611 @item @code{server-tokens?} (default: @code{#f})
17612 Whether the server should add its configuration to response.
17613
17614 @item @code{raw-content} (default: @code{'()})
17615 A list of raw lines added to the server block.
17616
17617 @end table
17618 @end deftp
17619
17620 @deftp {Data Type} nginx-upstream-configuration
17621 Data type representing the configuration of an nginx @code{upstream}
17622 block. This type has the following parameters:
17623
17624 @table @asis
17625 @item @code{name}
17626 Name for this group of servers.
17627
17628 @item @code{servers}
17629 Specify the addresses of the servers in the group. The address can be
17630 specified as a IP address (e.g.@: @samp{127.0.0.1}), domain name
17631 (e.g.@: @samp{backend1.example.com}) or a path to a UNIX socket using the
17632 prefix @samp{unix:}. For addresses using an IP address or domain name,
17633 the default port is 80, and a different port can be specified
17634 explicitly.
17635
17636 @end table
17637 @end deftp
17638
17639 @deftp {Data Type} nginx-location-configuration
17640 Data type representing the configuration of an nginx @code{location}
17641 block. This type has the following parameters:
17642
17643 @table @asis
17644 @item @code{uri}
17645 URI which this location block matches.
17646
17647 @anchor{nginx-location-configuration body}
17648 @item @code{body}
17649 Body of the location block, specified as a list of strings. This can contain
17650 many
17651 configuration directives. For example, to pass requests to a upstream
17652 server group defined using an @code{nginx-upstream-configuration} block,
17653 the following directive would be specified in the body @samp{(list "proxy_pass
17654 http://upstream-name;")}.
17655
17656 @end table
17657 @end deftp
17658
17659 @deftp {Data Type} nginx-named-location-configuration
17660 Data type representing the configuration of an nginx named location
17661 block. Named location blocks are used for request redirection, and not
17662 used for regular request processing. This type has the following
17663 parameters:
17664
17665 @table @asis
17666 @item @code{name}
17667 Name to identify this location block.
17668
17669 @item @code{body}
17670 @xref{nginx-location-configuration body}, as the body for named location
17671 blocks can be used in a similar way to the
17672 @code{nginx-location-configuration body}. One restriction is that the
17673 body of a named location block cannot contain location blocks.
17674
17675 @end table
17676 @end deftp
17677
17678 @subsubheading Varnish Cache
17679 @cindex Varnish
17680 Varnish is a fast cache server that sits in between web applications
17681 and end users. It proxies requests from clients and caches the
17682 accessed URLs such that multiple requests for the same resource only
17683 creates one request to the back-end.
17684
17685 @defvr {Scheme Variable} varnish-service-type
17686 Service type for the Varnish daemon.
17687 @end defvr
17688
17689 @deftp {Data Type} varnish-configuration
17690 Data type representing the @code{varnish} service configuration.
17691 This type has the following parameters:
17692
17693 @table @asis
17694 @item @code{package} (default: @code{varnish})
17695 The Varnish package to use.
17696
17697 @item @code{name} (default: @code{"default"})
17698 A name for this Varnish instance. Varnish will create a directory in
17699 @file{/var/varnish/} with this name and keep temporary files there. If
17700 the name starts with a forward slash, it is interpreted as an absolute
17701 directory name.
17702
17703 Pass the @code{-n} argument to other Varnish programs to connect to the
17704 named instance, e.g.@: @command{varnishncsa -n default}.
17705
17706 @item @code{backend} (default: @code{"localhost:8080"})
17707 The backend to use. This option has no effect if @code{vcl} is set.
17708
17709 @item @code{vcl} (default: #f)
17710 The @dfn{VCL} (Varnish Configuration Language) program to run. If this
17711 is @code{#f}, Varnish will proxy @code{backend} using the default
17712 configuration. Otherwise this must be a file-like object with valid
17713 VCL syntax.
17714
17715 @c Varnish does not support HTTPS, so keep this URL to avoid confusion.
17716 For example, to mirror @url{http://www.gnu.org,www.gnu.org} with VCL you
17717 can do something along these lines:
17718
17719 @example
17720 (define %gnu-mirror
17721 (plain-file
17722 "gnu.vcl"
17723 "vcl 4.1;
17724 backend gnu @{ .host = "www.gnu.org"; @}"))
17725
17726 (operating-system
17727 ...
17728 (services (cons (service varnish-service-type
17729 (varnish-configuration
17730 (listen '(":80"))
17731 (vcl %gnu-mirror)))
17732 %base-services)))
17733 @end example
17734
17735 The configuration of an already running Varnish instance can be inspected
17736 and changed using the @command{varnishadm} program.
17737
17738 Consult the @url{https://varnish-cache.org/docs/,Varnish User Guide} and
17739 @url{https://book.varnish-software.com/4.0/,Varnish Book} for
17740 comprehensive documentation on Varnish and its configuration language.
17741
17742 @item @code{listen} (default: @code{'("localhost:80")})
17743 List of addresses Varnish will listen on.
17744
17745 @item @code{storage} (default: @code{'("malloc,128m")})
17746 List of storage backends that will be available in VCL.
17747
17748 @item @code{parameters} (default: @code{'()})
17749 List of run-time parameters in the form @code{'(("parameter" . "value"))}.
17750
17751 @item @code{extra-options} (default: @code{'()})
17752 Additional arguments to pass to the @command{varnishd} process.
17753
17754 @end table
17755 @end deftp
17756
17757 @subsubheading FastCGI
17758 @cindex fastcgi
17759 @cindex fcgiwrap
17760 FastCGI is an interface between the front-end and the back-end of a web
17761 service. It is a somewhat legacy facility; new web services should
17762 generally just talk HTTP between the front-end and the back-end.
17763 However there are a number of back-end services such as PHP or the
17764 optimized HTTP Git repository access that use FastCGI, so we have
17765 support for it in Guix.
17766
17767 To use FastCGI, you configure the front-end web server (e.g., nginx) to
17768 dispatch some subset of its requests to the fastcgi backend, which
17769 listens on a local TCP or UNIX socket. There is an intermediary
17770 @code{fcgiwrap} program that sits between the actual backend process and
17771 the web server. The front-end indicates which backend program to run,
17772 passing that information to the @code{fcgiwrap} process.
17773
17774 @defvr {Scheme Variable} fcgiwrap-service-type
17775 A service type for the @code{fcgiwrap} FastCGI proxy.
17776 @end defvr
17777
17778 @deftp {Data Type} fcgiwrap-configuration
17779 Data type representing the configuration of the @code{fcgiwrap} service.
17780 This type has the following parameters:
17781 @table @asis
17782 @item @code{package} (default: @code{fcgiwrap})
17783 The fcgiwrap package to use.
17784
17785 @item @code{socket} (default: @code{tcp:127.0.0.1:9000})
17786 The socket on which the @code{fcgiwrap} process should listen, as a
17787 string. Valid @var{socket} values include
17788 @code{unix:@var{/path/to/unix/socket}},
17789 @code{tcp:@var{dot.ted.qu.ad}:@var{port}} and
17790 @code{tcp6:[@var{ipv6_addr}]:port}.
17791
17792 @item @code{user} (default: @code{fcgiwrap})
17793 @itemx @code{group} (default: @code{fcgiwrap})
17794 The user and group names, as strings, under which to run the
17795 @code{fcgiwrap} process. The @code{fastcgi} service will ensure that if
17796 the user asks for the specific user or group names @code{fcgiwrap} that
17797 the corresponding user and/or group is present on the system.
17798
17799 It is possible to configure a FastCGI-backed web service to pass HTTP
17800 authentication information from the front-end to the back-end, and to
17801 allow @code{fcgiwrap} to run the back-end process as a corresponding
17802 local user. To enable this capability on the back-end., run
17803 @code{fcgiwrap} as the @code{root} user and group. Note that this
17804 capability also has to be configured on the front-end as well.
17805 @end table
17806 @end deftp
17807
17808 @cindex php-fpm
17809 PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation
17810 with some additional features useful for sites of any size.
17811
17812 These features include:
17813 @itemize @bullet
17814 @item Adaptive process spawning
17815 @item Basic statistics (similar to Apache's mod_status)
17816 @item Advanced process management with graceful stop/start
17817 @item Ability to start workers with different uid/gid/chroot/environment
17818 and different php.ini (replaces safe_mode)
17819 @item Stdout & stderr logging
17820 @item Emergency restart in case of accidental opcode cache destruction
17821 @item Accelerated upload support
17822 @item Support for a "slowlog"
17823 @item Enhancements to FastCGI, such as fastcgi_finish_request() -
17824 a special function to finish request & flush all data while continuing to do
17825 something time-consuming (video converting, stats processing, etc.)
17826 @end itemize
17827 ...@: and much more.
17828
17829 @defvr {Scheme Variable} php-fpm-service-type
17830 A Service type for @code{php-fpm}.
17831 @end defvr
17832
17833 @deftp {Data Type} php-fpm-configuration
17834 Data Type for php-fpm service configuration.
17835 @table @asis
17836 @item @code{php} (default: @code{php})
17837 The php package to use.
17838 @item @code{socket} (default: @code{(string-append "/var/run/php" (version-major (package-version php)) "-fpm.sock")})
17839 The address on which to accept FastCGI requests. Valid syntaxes are:
17840 @table @asis
17841 @item @code{"ip.add.re.ss:port"}
17842 Listen on a TCP socket to a specific address on a specific port.
17843 @item @code{"port"}
17844 Listen on a TCP socket to all addresses on a specific port.
17845 @item @code{"/path/to/unix/socket"}
17846 Listen on a unix socket.
17847 @end table
17848
17849 @item @code{user} (default: @code{php-fpm})
17850 User who will own the php worker processes.
17851 @item @code{group} (default: @code{php-fpm})
17852 Group of the worker processes.
17853 @item @code{socket-user} (default: @code{php-fpm})
17854 User who can speak to the php-fpm socket.
17855 @item @code{socket-group} (default: @code{php-fpm})
17856 Group that can speak to the php-fpm socket.
17857 @item @code{pid-file} (default: @code{(string-append "/var/run/php" (version-major (package-version php)) "-fpm.pid")})
17858 The process id of the php-fpm process is written to this file
17859 once the service has started.
17860 @item @code{log-file} (default: @code{(string-append "/var/log/php" (version-major (package-version php)) "-fpm.log")})
17861 Log for the php-fpm master process.
17862 @item @code{process-manager} (default: @code{(php-fpm-dynamic-process-manager-configuration)})
17863 Detailed settings for the php-fpm process manager.
17864 Must be either:
17865 @table @asis
17866 @item @code{<php-fpm-dynamic-process-manager-configuration>}
17867 @item @code{<php-fpm-static-process-manager-configuration>}
17868 @item @code{<php-fpm-on-demand-process-manager-configuration>}
17869 @end table
17870 @item @code{display-errors} (default @code{#f})
17871 Determines whether php errors and warning should be sent to clients
17872 and displayed in their browsers.
17873 This is useful for local php development, but a security risk for public sites,
17874 as error messages can reveal passwords and personal data.
17875 @item @code{timezone} (default @code{#f})
17876 Specifies @code{php_admin_value[date.timezone]} parameter.
17877 @item @code{workers-logfile} (default @code{(string-append "/var/log/php" (version-major (package-version php)) "-fpm.www.log")})
17878 This file will log the @code{stderr} outputs of php worker processes.
17879 Can be set to @code{#f} to disable logging.
17880 @item @code{file} (default @code{#f})
17881 An optional override of the whole configuration.
17882 You can use the @code{mixed-text-file} function or an absolute filepath for it.
17883 @end table
17884 @end deftp
17885
17886 @deftp {Data type} php-fpm-dynamic-process-manager-configuration
17887 Data Type for the @code{dynamic} php-fpm process manager. With the
17888 @code{dynamic} process manager, spare worker processes are kept around
17889 based on it's configured limits.
17890 @table @asis
17891 @item @code{max-children} (default: @code{5})
17892 Maximum of worker processes.
17893 @item @code{start-servers} (default: @code{2})
17894 How many worker processes should be started on start-up.
17895 @item @code{min-spare-servers} (default: @code{1})
17896 How many spare worker processes should be kept around at minimum.
17897 @item @code{max-spare-servers} (default: @code{3})
17898 How many spare worker processes should be kept around at maximum.
17899 @end table
17900 @end deftp
17901
17902 @deftp {Data type} php-fpm-static-process-manager-configuration
17903 Data Type for the @code{static} php-fpm process manager. With the
17904 @code{static} process manager, an unchanging number of worker processes
17905 are created.
17906 @table @asis
17907 @item @code{max-children} (default: @code{5})
17908 Maximum of worker processes.
17909 @end table
17910 @end deftp
17911
17912 @deftp {Data type} php-fpm-on-demand-process-manager-configuration
17913 Data Type for the @code{on-demand} php-fpm process manager. With the
17914 @code{on-demand} process manager, worker processes are only created as
17915 requests arrive.
17916 @table @asis
17917 @item @code{max-children} (default: @code{5})
17918 Maximum of worker processes.
17919 @item @code{process-idle-timeout} (default: @code{10})
17920 The time in seconds after which a process with no requests is killed.
17921 @end table
17922 @end deftp
17923
17924
17925 @deffn {Scheme Procedure} nginx-php-fpm-location @
17926 [#:nginx-package nginx] @
17927 [socket (string-append "/var/run/php" @
17928 (version-major (package-version php)) @
17929 "-fpm.sock")]
17930 A helper function to quickly add php to an @code{nginx-server-configuration}.
17931 @end deffn
17932
17933 A simple services setup for nginx with php can look like this:
17934 @example
17935 (services (cons* (service dhcp-client-service-type)
17936 (service php-fpm-service-type)
17937 (service nginx-service-type
17938 (nginx-server-configuration
17939 (server-name '("example.com"))
17940 (root "/srv/http/")
17941 (locations
17942 (list (nginx-php-location)))
17943 (listen '("80"))
17944 (ssl-certificate #f)
17945 (ssl-certificate-key #f)))
17946 %base-services))
17947 @end example
17948
17949 @cindex cat-avatar-generator
17950 The cat avatar generator is a simple service to demonstrate the use of php-fpm
17951 in @code{Nginx}. It is used to generate cat avatar from a seed, for instance
17952 the hash of a user's email address.
17953
17954 @deffn {Scheme Procedure} cat-avatar-generator-service @
17955 [#:cache-dir "/var/cache/cat-avatar-generator"] @
17956 [#:package cat-avatar-generator] @
17957 [#:configuration (nginx-server-configuration)]
17958 Returns an nginx-server-configuration that inherits @code{configuration}. It
17959 extends the nginx configuration to add a server block that serves @code{package},
17960 a version of cat-avatar-generator. During execution, cat-avatar-generator will
17961 be able to use @code{cache-dir} as its cache directory.
17962 @end deffn
17963
17964 A simple setup for cat-avatar-generator can look like this:
17965 @example
17966 (services (cons* (cat-avatar-generator-service
17967 #:configuration
17968 (nginx-server-configuration
17969 (server-name '("example.com"))))
17970 ...
17971 %base-services))
17972 @end example
17973
17974 @subsubheading Hpcguix-web
17975
17976 @cindex hpcguix-web
17977 The @uref{hpcguix-web, https://github.com/UMCUGenetics/hpcguix-web/}
17978 program is a customizable web interface to browse Guix packages,
17979 initially designed for users of high-performance computing (HPC)
17980 clusters.
17981
17982 @defvr {Scheme Variable} hpcguix-web-service-type
17983 The service type for @code{hpcguix-web}.
17984 @end defvr
17985
17986 @deftp {Data Type} hpcguix-web-configuration
17987 Data type for the hpcguix-web service configuration.
17988
17989 @table @asis
17990 @item @code{specs}
17991 A gexp (@pxref{G-Expressions}) specifying the hpcguix-web service
17992 configuration. The main items available in this spec are:
17993
17994 @table @asis
17995 @item @code{title-prefix} (default: @code{"hpcguix | "})
17996 The page title prefix.
17997
17998 @item @code{guix-command} (default: @code{"guix"})
17999 The @command{guix} command.
18000
18001 @item @code{package-filter-proc} (default: @code{(const #t)})
18002 A procedure specifying how to filter packages that are displayed.
18003
18004 @item @code{package-page-extension-proc} (default: @code{(const '())})
18005 Extension package for @code{hpcguix-web}.
18006
18007 @item @code{menu} (default: @code{'()})
18008 Additional entry in page @code{menu}.
18009
18010 @item @code{channels} (default: @code{%default-channels})
18011 List of channels from which the package list is built (@pxref{Channels}).
18012
18013 @item @code{package-list-expiration} (default: @code{(* 12 3600)})
18014 The expiration time, in seconds, after which the package list is rebuilt from
18015 the latest instances of the given channels.
18016 @end table
18017
18018 See the hpcguix-web repository for a
18019 @uref{https://github.com/UMCUGenetics/hpcguix-web/blob/master/hpcweb-configuration.scm,
18020 complete example}.
18021
18022 @item @code{package} (default: @code{hpcguix-web})
18023 The hpcguix-web package to use.
18024 @end table
18025 @end deftp
18026
18027 A typical hpcguix-web service declaration looks like this:
18028
18029 @example
18030 (service hpcguix-web-service-type
18031 (hpcguix-web-configuration
18032 (specs
18033 #~(define site-config
18034 (hpcweb-configuration
18035 (title-prefix "Guix-HPC - ")
18036 (menu '(("/about" "ABOUT"))))))))
18037 @end example
18038
18039 @quotation Note
18040 The hpcguix-web service periodically updates the package list it publishes by
18041 pulling channels from Git. To that end, it needs to access X.509 certificates
18042 so that it can authenticate Git servers when communicating over HTTPS, and it
18043 assumes that @file{/etc/ssl/certs} contains those certificates.
18044
18045 Thus, make sure to add @code{nss-certs} or another certificate package to the
18046 @code{packages} field of your configuration. @ref{X.509 Certificates}, for
18047 more information on X.509 certificates.
18048 @end quotation
18049
18050 @node Certificate Services
18051 @subsubsection Certificate Services
18052
18053 @cindex Web
18054 @cindex HTTP, HTTPS
18055 @cindex Let's Encrypt
18056 @cindex TLS certificates
18057 The @code{(gnu services certbot)} module provides a service to
18058 automatically obtain a valid TLS certificate from the Let's Encrypt
18059 certificate authority. These certificates can then be used to serve
18060 content securely over HTTPS or other TLS-based protocols, with the
18061 knowledge that the client will be able to verify the server's
18062 authenticity.
18063
18064 @url{https://letsencrypt.org/, Let's Encrypt} provides the
18065 @code{certbot} tool to automate the certification process. This tool
18066 first securely generates a key on the server. It then makes a request
18067 to the Let's Encrypt certificate authority (CA) to sign the key. The CA
18068 checks that the request originates from the host in question by using a
18069 challenge-response protocol, requiring the server to provide its
18070 response over HTTP. If that protocol completes successfully, the CA
18071 signs the key, resulting in a certificate. That certificate is valid
18072 for a limited period of time, and therefore to continue to provide TLS
18073 services, the server needs to periodically ask the CA to renew its
18074 signature.
18075
18076 The certbot service automates this process: the initial key
18077 generation, the initial certification request to the Let's Encrypt
18078 service, the web server challenge/response integration, writing the
18079 certificate to disk, the automated periodic renewals, and the deployment
18080 tasks associated with the renewal (e.g.@: reloading services, copying keys
18081 with different permissions).
18082
18083 Certbot is run twice a day, at a random minute within the hour. It
18084 won't do anything until your certificates are due for renewal or
18085 revoked, but running it regularly would give your service a chance of
18086 staying online in case a Let's Encrypt-initiated revocation happened for
18087 some reason.
18088
18089 By using this service, you agree to the ACME Subscriber Agreement, which
18090 can be found there:
18091 @url{https://acme-v01.api.letsencrypt.org/directory}.
18092
18093 @defvr {Scheme Variable} certbot-service-type
18094 A service type for the @code{certbot} Let's Encrypt client. Its value
18095 must be a @code{certbot-configuration} record as in this example:
18096
18097 @example
18098 (define %nginx-deploy-hook
18099 (program-file
18100 "nginx-deploy-hook"
18101 #~(let ((pid (call-with-input-file "/var/run/nginx/pid" read)))
18102 (kill pid SIGHUP))))
18103
18104 (service certbot-service-type
18105 (certbot-configuration
18106 (email "foo@@example.net")
18107 (certificates
18108 (list
18109 (certificate-configuration
18110 (domains '("example.net" "www.example.net"))
18111 (deploy-hook %nginx-deploy-hook))
18112 (certificate-configuration
18113 (domains '("bar.example.net")))))))
18114 @end example
18115
18116 See below for details about @code{certbot-configuration}.
18117 @end defvr
18118
18119 @deftp {Data Type} certbot-configuration
18120 Data type representing the configuration of the @code{certbot} service.
18121 This type has the following parameters:
18122
18123 @table @asis
18124 @item @code{package} (default: @code{certbot})
18125 The certbot package to use.
18126
18127 @item @code{webroot} (default: @code{/var/www})
18128 The directory from which to serve the Let's Encrypt challenge/response
18129 files.
18130
18131 @item @code{certificates} (default: @code{()})
18132 A list of @code{certificates-configuration}s for which to generate
18133 certificates and request signatures. Each certificate has a @code{name}
18134 and several @code{domains}.
18135
18136 @item @code{email}
18137 Mandatory email used for registration, recovery contact, and important
18138 account notifications.
18139
18140 @item @code{rsa-key-size} (default: @code{2048})
18141 Size of the RSA key.
18142
18143 @item @code{default-location} (default: @i{see below})
18144 The default @code{nginx-location-configuration}. Because @code{certbot}
18145 needs to be able to serve challenges and responses, it needs to be able
18146 to run a web server. It does so by extending the @code{nginx} web
18147 service with an @code{nginx-server-configuration} listening on the
18148 @var{domains} on port 80, and which has a
18149 @code{nginx-location-configuration} for the @code{/.well-known/} URI
18150 path subspace used by Let's Encrypt. @xref{Web Services}, for more on
18151 these nginx configuration data types.
18152
18153 Requests to other URL paths will be matched by the
18154 @code{default-location}, which if present is added to all
18155 @code{nginx-server-configuration}s.
18156
18157 By default, the @code{default-location} will issue a redirect from
18158 @code{http://@var{domain}/...} to @code{https://@var{domain}/...}, leaving
18159 you to define what to serve on your site via @code{https}.
18160
18161 Pass @code{#f} to not issue a default location.
18162 @end table
18163 @end deftp
18164
18165 @deftp {Data Type} certificate-configuration
18166 Data type representing the configuration of a certificate.
18167 This type has the following parameters:
18168
18169 @table @asis
18170 @item @code{name} (default: @i{see below})
18171 This name is used by Certbot for housekeeping and in file paths; it
18172 doesn't affect the content of the certificate itself. To see
18173 certificate names, run @code{certbot certificates}.
18174
18175 Its default is the first provided domain.
18176
18177 @item @code{domains} (default: @code{()})
18178 The first domain provided will be the subject CN of the certificate, and
18179 all domains will be Subject Alternative Names on the certificate.
18180
18181 @item @code{deploy-hook} (default: @code{#f})
18182 Command to be run in a shell once for each successfully issued
18183 certificate. For this command, the shell variable
18184 @code{$RENEWED_LINEAGE} will point to the config live subdirectory (for
18185 example, @samp{"/etc/letsencrypt/live/example.com"}) containing the new
18186 certificates and keys; the shell variable @code{$RENEWED_DOMAINS} will
18187 contain a space-delimited list of renewed certificate domains (for
18188 example, @samp{"example.com www.example.com"}.
18189
18190 @end table
18191 @end deftp
18192
18193 For each @code{certificate-configuration}, the certificate is saved to
18194 @code{/etc/letsencrypt/live/@var{name}/fullchain.pem} and the key is
18195 saved to @code{/etc/letsencrypt/live/@var{name}/privkey.pem}.
18196 @node DNS Services
18197 @subsubsection DNS Services
18198 @cindex DNS (domain name system)
18199 @cindex domain name system (DNS)
18200
18201 The @code{(gnu services dns)} module provides services related to the
18202 @dfn{domain name system} (DNS). It provides a server service for hosting
18203 an @emph{authoritative} DNS server for multiple zones, slave or master.
18204 This service uses @uref{https://www.knot-dns.cz/, Knot DNS}. And also a
18205 caching and forwarding DNS server for the LAN, which uses
18206 @uref{http://www.thekelleys.org.uk/dnsmasq/doc.html, dnsmasq}.
18207
18208 @subsubheading Knot Service
18209
18210 An example configuration of an authoritative server for two zones, one master
18211 and one slave, is:
18212
18213 @lisp
18214 (define-zone-entries example.org.zone
18215 ;; Name TTL Class Type Data
18216 ("@@" "" "IN" "A" "127.0.0.1")
18217 ("@@" "" "IN" "NS" "ns")
18218 ("ns" "" "IN" "A" "127.0.0.1"))
18219
18220 (define master-zone
18221 (knot-zone-configuration
18222 (domain "example.org")
18223 (zone (zone-file
18224 (origin "example.org")
18225 (entries example.org.zone)))))
18226
18227 (define slave-zone
18228 (knot-zone-configuration
18229 (domain "plop.org")
18230 (dnssec-policy "default")
18231 (master (list "plop-master"))))
18232
18233 (define plop-master
18234 (knot-remote-configuration
18235 (id "plop-master")
18236 (address (list "208.76.58.171"))))
18237
18238 (operating-system
18239 ;; ...
18240 (services (cons* (service knot-service-type
18241 (knot-configuration
18242 (remotes (list plop-master))
18243 (zones (list master-zone slave-zone))))
18244 ;; ...
18245 %base-services)))
18246 @end lisp
18247
18248 @deffn {Scheme Variable} knot-service-type
18249 This is the type for the Knot DNS server.
18250
18251 Knot DNS is an authoritative DNS server, meaning that it can serve multiple
18252 zones, that is to say domain names you would buy from a registrar. This server
18253 is not a resolver, meaning that it can only resolve names for which it is
18254 authoritative. This server can be configured to serve zones as a master server
18255 or a slave server as a per-zone basis. Slave zones will get their data from
18256 masters, and will serve it as an authoritative server. From the point of view
18257 of a resolver, there is no difference between master and slave.
18258
18259 The following data types are used to configure the Knot DNS server:
18260 @end deffn
18261
18262 @deftp {Data Type} knot-key-configuration
18263 Data type representing a key.
18264 This type has the following parameters:
18265
18266 @table @asis
18267 @item @code{id} (default: @code{""})
18268 An identifier for other configuration fields to refer to this key. IDs must
18269 be unique and must not be empty.
18270
18271 @item @code{algorithm} (default: @code{#f})
18272 The algorithm to use. Choose between @code{#f}, @code{'hmac-md5},
18273 @code{'hmac-sha1}, @code{'hmac-sha224}, @code{'hmac-sha256}, @code{'hmac-sha384}
18274 and @code{'hmac-sha512}.
18275
18276 @item @code{secret} (default: @code{""})
18277 The secret key itself.
18278
18279 @end table
18280 @end deftp
18281
18282 @deftp {Data Type} knot-acl-configuration
18283 Data type representing an Access Control List (ACL) configuration.
18284 This type has the following parameters:
18285
18286 @table @asis
18287 @item @code{id} (default: @code{""})
18288 An identifier for ether configuration fields to refer to this key. IDs must be
18289 unique and must not be empty.
18290
18291 @item @code{address} (default: @code{'()})
18292 An ordered list of IP addresses, network subnets, or network ranges represented
18293 with strings. The query must match one of them. Empty value means that
18294 address match is not required.
18295
18296 @item @code{key} (default: @code{'()})
18297 An ordered list of references to keys represented with strings. The string
18298 must match a key ID defined in a @code{knot-key-configuration}. No key means
18299 that a key is not require to match that ACL.
18300
18301 @item @code{action} (default: @code{'()})
18302 An ordered list of actions that are permitted or forbidden by this ACL. Possible
18303 values are lists of zero or more elements from @code{'transfer}, @code{'notify}
18304 and @code{'update}.
18305
18306 @item @code{deny?} (default: @code{#f})
18307 When true, the ACL defines restrictions. Listed actions are forbidden. When
18308 false, listed actions are allowed.
18309
18310 @end table
18311 @end deftp
18312
18313 @deftp {Data Type} zone-entry
18314 Data type represnting a record entry in a zone file.
18315 This type has the following parameters:
18316
18317 @table @asis
18318 @item @code{name} (default: @code{"@@"})
18319 The name of the record. @code{"@@"} refers to the origin of the zone. Names
18320 are relative to the origin of the zone. For example, in the @code{example.org}
18321 zone, @code{"ns.example.org"} actually refers to @code{ns.example.org.example.org}.
18322 Names ending with a dot are absolute, which means that @code{"ns.example.org."}
18323 refers to @code{ns.example.org}.
18324
18325 @item @code{ttl} (default: @code{""})
18326 The Time-To-Live (TTL) of this record. If not set, the default TTL is used.
18327
18328 @item @code{class} (default: @code{"IN"})
18329 The class of the record. Knot currently supports only @code{"IN"} and
18330 partially @code{"CH"}.
18331
18332 @item @code{type} (default: @code{"A"})
18333 The type of the record. Common types include A (IPv4 address), AAAA (IPv6
18334 address), NS (Name Server) and MX (Mail eXchange). Many other types are
18335 defined.
18336
18337 @item @code{data} (default: @code{""})
18338 The data contained in the record. For instance an IP address associated with
18339 an A record, or a domain name associated with an NS record. Remember that
18340 domain names are relative to the origin unless they end with a dot.
18341
18342 @end table
18343 @end deftp
18344
18345 @deftp {Data Type} zone-file
18346 Data type representing the content of a zone file.
18347 This type has the following parameters:
18348
18349 @table @asis
18350 @item @code{entries} (default: @code{'()})
18351 The list of entries. The SOA record is taken care of, so you don't need to
18352 put it in the list of entries. This list should probably contain an entry
18353 for your primary authoritative DNS server. Other than using a list of entries
18354 directly, you can use @code{define-zone-entries} to define a object containing
18355 the list of entries more easily, that you can later pass to the @code{entries}
18356 field of the @code{zone-file}.
18357
18358 @item @code{origin} (default: @code{""})
18359 The name of your zone. This parameter cannot be empty.
18360
18361 @item @code{ns} (default: @code{"ns"})
18362 The domain of your primary authoritative DNS server. The name is relative to
18363 the origin, unless it ends with a dot. It is mandatory that this primary
18364 DNS server corresponds to an NS record in the zone and that it is associated
18365 to an IP address in the list of entries.
18366
18367 @item @code{mail} (default: @code{"hostmaster"})
18368 An email address people can contact you at, as the owner of the zone. This
18369 is translated as @code{<mail>@@<origin>}.
18370
18371 @item @code{serial} (default: @code{1})
18372 The serial number of the zone. As this is used to keep track of changes by
18373 both slaves and resolvers, it is mandatory that it @emph{never} decreases.
18374 Always increment it when you make a change in your zone.
18375
18376 @item @code{refresh} (default: @code{(* 2 24 3600)})
18377 The frequency at which slaves will do a zone transfer. This value is a number
18378 of seconds. It can be computed by multiplications or with
18379 @code{(string->duration)}.
18380
18381 @item @code{retry} (default: @code{(* 15 60)})
18382 The period after which a slave will retry to contact its master when it fails
18383 to do so a first time.
18384
18385 @item @code{expiry} (default: @code{(* 14 24 3600)})
18386 Default TTL of records. Existing records are considered correct for at most
18387 this amount of time. After this period, resolvers will invalidate their cache
18388 and check again that it still exists.
18389
18390 @item @code{nx} (default: @code{3600})
18391 Default TTL of inexistant records. This delay is usually short because you want
18392 your new domains to reach everyone quickly.
18393
18394 @end table
18395 @end deftp
18396
18397 @deftp {Data Type} knot-remote-configuration
18398 Data type representing a remote configuration.
18399 This type has the following parameters:
18400
18401 @table @asis
18402 @item @code{id} (default: @code{""})
18403 An identifier for other configuration fields to refer to this remote. IDs must
18404 be unique and must not be empty.
18405
18406 @item @code{address} (default: @code{'()})
18407 An ordered list of destination IP addresses. Addresses are tried in sequence.
18408 An optional port can be given with the @@ separator. For instance:
18409 @code{(list "1.2.3.4" "2.3.4.5@@53")}. Default port is 53.
18410
18411 @item @code{via} (default: @code{'()})
18412 An ordered list of source IP addresses. An empty list will have Knot choose
18413 an appropriate source IP. An optional port can be given with the @@ separator.
18414 The default is to choose at random.
18415
18416 @item @code{key} (default: @code{#f})
18417 A reference to a key, that is a string containing the identifier of a key
18418 defined in a @code{knot-key-configuration} field.
18419
18420 @end table
18421 @end deftp
18422
18423 @deftp {Data Type} knot-keystore-configuration
18424 Data type representing a keystore to hold dnssec keys.
18425 This type has the following parameters:
18426
18427 @table @asis
18428 @item @code{id} (default: @code{""})
18429 The id of the keystore. It must not be empty.
18430
18431 @item @code{backend} (default: @code{'pem})
18432 The backend to store the keys in. Can be @code{'pem} or @code{'pkcs11}.
18433
18434 @item @code{config} (default: @code{"/var/lib/knot/keys/keys"})
18435 The configuration string of the backend. An example for the PKCS#11 is:
18436 @code{"pkcs11:token=knot;pin-value=1234 /gnu/store/.../lib/pkcs11/libsofthsm2.so"}.
18437 For the pem backend, the string reprensents a path in the file system.
18438
18439 @end table
18440 @end deftp
18441
18442 @deftp {Data Type} knot-policy-configuration
18443 Data type representing a dnssec policy. Knot DNS is able to automatically
18444 sign your zones. It can either generate and manage your keys automatically or
18445 use keys that you generate.
18446
18447 Dnssec is usually implemented using two keys: a Key Signing Key (KSK) that is
18448 used to sign the second, and a Zone Signing Key (ZSK) that is used to sign the
18449 zone. In order to be trusted, the KSK needs to be present in the parent zone
18450 (usually a top-level domain). If your registrar supports dnssec, you will
18451 have to send them your KSK's hash so they can add a DS record in their zone.
18452 This is not automated and need to be done each time you change your KSK.
18453
18454 The policy also defines the lifetime of keys. Usually, ZSK can be changed
18455 easily and use weaker cryptographic functions (they use lower parameters) in
18456 order to sign records quickly, so they are changed often. The KSK however
18457 requires manual interaction with the registrar, so they are changed less often
18458 and use stronger parameters because they sign only one record.
18459
18460 This type has the following parameters:
18461
18462 @table @asis
18463 @item @code{id} (default: @code{""})
18464 The id of the policy. It must not be empty.
18465
18466 @item @code{keystore} (default: @code{"default"})
18467 A reference to a keystore, that is a string containing the identifier of a
18468 keystore defined in a @code{knot-keystore-configuration} field. The
18469 @code{"default"} identifier means the default keystore (a kasp database that
18470 was setup by this service).
18471
18472 @item @code{manual?} (default: @code{#f})
18473 Whether the key management is manual or automatic.
18474
18475 @item @code{single-type-signing?} (default: @code{#f})
18476 When @code{#t}, use the Single-Type Signing Scheme.
18477
18478 @item @code{algorithm} (default: @code{"ecdsap256sha256"})
18479 An algorithm of signing keys and issued signatures.
18480
18481 @item @code{ksk-size} (default: @code{256})
18482 The length of the KSK. Note that this value is correct for the default
18483 algorithm, but would be unsecure for other algorithms.
18484
18485 @item @code{zsk-size} (default: @code{256})
18486 The length of the ZSK. Note that this value is correct for the default
18487 algorithm, but would be unsecure for other algorithms.
18488
18489 @item @code{dnskey-ttl} (default: @code{'default})
18490 The TTL value for DNSKEY records added into zone apex. The special
18491 @code{'default} value means same as the zone SOA TTL.
18492
18493 @item @code{zsk-lifetime} (default: @code{(* 30 24 3600)})
18494 The period between ZSK publication and the next rollover initiation.
18495
18496 @item @code{propagation-delay} (default: @code{(* 24 3600)})
18497 An extra delay added for each key rollover step. This value should be high
18498 enough to cover propagation of data from the master server to all slaves.
18499
18500 @item @code{rrsig-lifetime} (default: @code{(* 14 24 3600)})
18501 A validity period of newly issued signatures.
18502
18503 @item @code{rrsig-refresh} (default: @code{(* 7 24 3600)})
18504 A period how long before a signature expiration the signature will be refreshed.
18505
18506 @item @code{nsec3?} (default: @code{#f})
18507 When @code{#t}, NSEC3 will be used instead of NSEC.
18508
18509 @item @code{nsec3-iterations} (default: @code{5})
18510 The number of additional times the hashing is performed.
18511
18512 @item @code{nsec3-salt-length} (default: @code{8})
18513 The length of a salt field in octets, which is appended to the original owner
18514 name before hashing.
18515
18516 @item @code{nsec3-salt-lifetime} (default: @code{(* 30 24 3600)})
18517 The validity period of newly issued salt field.
18518
18519 @end table
18520 @end deftp
18521
18522 @deftp {Data Type} knot-zone-configuration
18523 Data type representing a zone served by Knot.
18524 This type has the following parameters:
18525
18526 @table @asis
18527 @item @code{domain} (default: @code{""})
18528 The domain served by this configuration. It must not be empty.
18529
18530 @item @code{file} (default: @code{""})
18531 The file where this zone is saved. This parameter is ignored by master zones.
18532 Empty means default location that depends on the domain name.
18533
18534 @item @code{zone} (default: @code{(zone-file)})
18535 The content of the zone file. This parameter is ignored by slave zones. It
18536 must contain a zone-file record.
18537
18538 @item @code{master} (default: @code{'()})
18539 A list of master remotes. When empty, this zone is a master. When set, this
18540 zone is a slave. This is a list of remotes identifiers.
18541
18542 @item @code{ddns-master} (default: @code{#f})
18543 The main master. When empty, it defaults to the first master in the list of
18544 masters.
18545
18546 @item @code{notify} (default: @code{'()})
18547 A list of slave remote identifiers.
18548
18549 @item @code{acl} (default: @code{'()})
18550 A list of acl identifiers.
18551
18552 @item @code{semantic-checks?} (default: @code{#f})
18553 When set, this adds more semantic checks to the zone.
18554
18555 @item @code{disable-any?} (default: @code{#f})
18556 When set, this forbids queries of the ANY type.
18557
18558 @item @code{zonefile-sync} (default: @code{0})
18559 The delay between a modification in memory and on disk. 0 means immediate
18560 synchronization.
18561
18562 @item @code{serial-policy} (default: @code{'increment})
18563 A policy between @code{'increment} and @code{'unixtime}.
18564
18565 @end table
18566 @end deftp
18567
18568 @deftp {Data Type} knot-configuration
18569 Data type representing the Knot configuration.
18570 This type has the following parameters:
18571
18572 @table @asis
18573 @item @code{knot} (default: @code{knot})
18574 The Knot package.
18575
18576 @item @code{run-directory} (default: @code{"/var/run/knot"})
18577 The run directory. This directory will be used for pid file and sockets.
18578
18579 @item @code{listen-v4} (default: @code{"0.0.0.0"})
18580 An ip address on which to listen.
18581
18582 @item @code{listen-v6} (default: @code{"::"})
18583 An ip address on which to listen.
18584
18585 @item @code{listen-port} (default: @code{53})
18586 A port on which to listen.
18587
18588 @item @code{keys} (default: @code{'()})
18589 The list of knot-key-configuration used by this configuration.
18590
18591 @item @code{acls} (default: @code{'()})
18592 The list of knot-acl-configuration used by this configuration.
18593
18594 @item @code{remotes} (default: @code{'()})
18595 The list of knot-remote-configuration used by this configuration.
18596
18597 @item @code{zones} (default: @code{'()})
18598 The list of knot-zone-configuration used by this configuration.
18599
18600 @end table
18601 @end deftp
18602
18603 @subsubheading Dnsmasq Service
18604
18605 @deffn {Scheme Variable} dnsmasq-service-type
18606 This is the type of the dnsmasq service, whose value should be an
18607 @code{dnsmasq-configuration} object as in this example:
18608
18609 @example
18610 (service dnsmasq-service-type
18611 (dnsmasq-configuration
18612 (no-resolv? #t)
18613 (servers '("192.168.1.1"))))
18614 @end example
18615 @end deffn
18616
18617 @deftp {Data Type} dnsmasq-configuration
18618 Data type representing the configuration of dnsmasq.
18619
18620 @table @asis
18621 @item @code{package} (default: @var{dnsmasq})
18622 Package object of the dnsmasq server.
18623
18624 @item @code{no-hosts?} (default: @code{#f})
18625 When true, don't read the hostnames in /etc/hosts.
18626
18627 @item @code{port} (default: @code{53})
18628 The port to listen on. Setting this to zero completely disables DNS
18629 responses, leaving only DHCP and/or TFTP functions.
18630
18631 @item @code{local-service?} (default: @code{#t})
18632 Accept DNS queries only from hosts whose address is on a local subnet,
18633 ie a subnet for which an interface exists on the server.
18634
18635 @item @code{listen-addresses} (default: @code{'()})
18636 Listen on the given IP addresses.
18637
18638 @item @code{resolv-file} (default: @code{"/etc/resolv.conf"})
18639 The file to read the IP address of the upstream nameservers from.
18640
18641 @item @code{no-resolv?} (default: @code{#f})
18642 When true, don't read @var{resolv-file}.
18643
18644 @item @code{servers} (default: @code{'()})
18645 Specify IP address of upstream servers directly.
18646
18647 @item @code{cache-size} (default: @code{150})
18648 Set the size of dnsmasq's cache. Setting the cache size to zero
18649 disables caching.
18650
18651 @item @code{negative-cache?} (default: @code{#t})
18652 When false, disable negative caching.
18653
18654 @end table
18655 @end deftp
18656
18657 @subsubheading ddclient Service
18658
18659 @cindex ddclient
18660 The ddclient service described below runs the ddclient daemon, which takes
18661 care of automatically updating DNS entries for service providers such as
18662 @uref{https://dyn.com/dns/, Dyn}.
18663
18664 The following example show instantiates the service with its default
18665 configuration:
18666
18667 @example
18668 (service ddclient-service-type)
18669 @end example
18670
18671 Note that ddclient needs to access credentials that are stored in a
18672 @dfn{secret file}, by default @file{/etc/ddclient/secrets} (see
18673 @code{secret-file} below.) You are expected to create this file manually, in
18674 an ``out-of-band'' fashion (you @emph{could} make this file part of the
18675 service configuration, for instance by using @code{plain-file}, but it will be
18676 world-readable @i{via} @file{/gnu/store}.) See the examples in the
18677 @file{share/ddclient} directory of the @code{ddclient} package.
18678
18679 @c %start of fragment
18680
18681 Available @code{ddclient-configuration} fields are:
18682
18683 @deftypevr {@code{ddclient-configuration} parameter} package ddclient
18684 The ddclient package.
18685
18686 @end deftypevr
18687
18688 @deftypevr {@code{ddclient-configuration} parameter} integer daemon
18689 The period after which ddclient will retry to check IP and domain name.
18690
18691 Defaults to @samp{300}.
18692
18693 @end deftypevr
18694
18695 @deftypevr {@code{ddclient-configuration} parameter} boolean syslog
18696 Use syslog for the output.
18697
18698 Defaults to @samp{#t}.
18699
18700 @end deftypevr
18701
18702 @deftypevr {@code{ddclient-configuration} parameter} string mail
18703 Mail to user.
18704
18705 Defaults to @samp{"root"}.
18706
18707 @end deftypevr
18708
18709 @deftypevr {@code{ddclient-configuration} parameter} string mail-failure
18710 Mail failed update to user.
18711
18712 Defaults to @samp{"root"}.
18713
18714 @end deftypevr
18715
18716 @deftypevr {@code{ddclient-configuration} parameter} string pid
18717 The ddclient PID file.
18718
18719 Defaults to @samp{"/var/run/ddclient/ddclient.pid"}.
18720
18721 @end deftypevr
18722
18723 @deftypevr {@code{ddclient-configuration} parameter} boolean ssl
18724 Enable SSL support.
18725
18726 Defaults to @samp{#t}.
18727
18728 @end deftypevr
18729
18730 @deftypevr {@code{ddclient-configuration} parameter} string user
18731 Specifies the user name or ID that is used when running ddclient
18732 program.
18733
18734 Defaults to @samp{"ddclient"}.
18735
18736 @end deftypevr
18737
18738 @deftypevr {@code{ddclient-configuration} parameter} string group
18739 Group of the user who will run the ddclient program.
18740
18741 Defaults to @samp{"ddclient"}.
18742
18743 @end deftypevr
18744
18745 @deftypevr {@code{ddclient-configuration} parameter} string secret-file
18746 Secret file which will be appended to @file{ddclient.conf} file. This
18747 file contains credentials for use by ddclient. You are expected to
18748 create it manually.
18749
18750 Defaults to @samp{"/etc/ddclient/secrets.conf"}.
18751
18752 @end deftypevr
18753
18754 @deftypevr {@code{ddclient-configuration} parameter} list extra-options
18755 Extra options will be appended to @file{ddclient.conf} file.
18756
18757 Defaults to @samp{()}.
18758
18759 @end deftypevr
18760
18761
18762 @c %end of fragment
18763
18764
18765 @node VPN Services
18766 @subsubsection VPN Services
18767 @cindex VPN (virtual private network)
18768 @cindex virtual private network (VPN)
18769
18770 The @code{(gnu services vpn)} module provides services related to
18771 @dfn{virtual private networks} (VPNs). It provides a @emph{client} service for
18772 your machine to connect to a VPN, and a @emph{servire} service for your machine
18773 to host a VPN. Both services use @uref{https://openvpn.net/, OpenVPN}.
18774
18775 @deffn {Scheme Procedure} openvpn-client-service @
18776 [#:config (openvpn-client-configuration)]
18777
18778 Return a service that runs @command{openvpn}, a VPN daemon, as a client.
18779 @end deffn
18780
18781 @deffn {Scheme Procedure} openvpn-server-service @
18782 [#:config (openvpn-server-configuration)]
18783
18784 Return a service that runs @command{openvpn}, a VPN daemon, as a server.
18785
18786 Both can be run simultaneously.
18787 @end deffn
18788
18789 @c %automatically generated documentation
18790
18791 Available @code{openvpn-client-configuration} fields are:
18792
18793 @deftypevr {@code{openvpn-client-configuration} parameter} package openvpn
18794 The OpenVPN package.
18795
18796 @end deftypevr
18797
18798 @deftypevr {@code{openvpn-client-configuration} parameter} string pid-file
18799 The OpenVPN pid file.
18800
18801 Defaults to @samp{"/var/run/openvpn/openvpn.pid"}.
18802
18803 @end deftypevr
18804
18805 @deftypevr {@code{openvpn-client-configuration} parameter} proto proto
18806 The protocol (UDP or TCP) used to open a channel between clients and
18807 servers.
18808
18809 Defaults to @samp{udp}.
18810
18811 @end deftypevr
18812
18813 @deftypevr {@code{openvpn-client-configuration} parameter} dev dev
18814 The device type used to represent the VPN connection.
18815
18816 Defaults to @samp{tun}.
18817
18818 @end deftypevr
18819
18820 @deftypevr {@code{openvpn-client-configuration} parameter} string ca
18821 The certificate authority to check connections against.
18822
18823 Defaults to @samp{"/etc/openvpn/ca.crt"}.
18824
18825 @end deftypevr
18826
18827 @deftypevr {@code{openvpn-client-configuration} parameter} string cert
18828 The certificate of the machine the daemon is running on. It should be
18829 signed by the authority given in @code{ca}.
18830
18831 Defaults to @samp{"/etc/openvpn/client.crt"}.
18832
18833 @end deftypevr
18834
18835 @deftypevr {@code{openvpn-client-configuration} parameter} string key
18836 The key of the machine the daemon is running on. It must be the key whose
18837 certificate is @code{cert}.
18838
18839 Defaults to @samp{"/etc/openvpn/client.key"}.
18840
18841 @end deftypevr
18842
18843 @deftypevr {@code{openvpn-client-configuration} parameter} boolean comp-lzo?
18844 Whether to use the lzo compression algorithm.
18845
18846 Defaults to @samp{#t}.
18847
18848 @end deftypevr
18849
18850 @deftypevr {@code{openvpn-client-configuration} parameter} boolean persist-key?
18851 Don't re-read key files across SIGUSR1 or --ping-restart.
18852
18853 Defaults to @samp{#t}.
18854
18855 @end deftypevr
18856
18857 @deftypevr {@code{openvpn-client-configuration} parameter} boolean persist-tun?
18858 Don't close and reopen TUN/TAP device or run up/down scripts across
18859 SIGUSR1 or --ping-restart restarts.
18860
18861 Defaults to @samp{#t}.
18862
18863 @end deftypevr
18864
18865 @deftypevr {@code{openvpn-client-configuration} parameter} number verbosity
18866 Verbosity level.
18867
18868 Defaults to @samp{3}.
18869
18870 @end deftypevr
18871
18872 @deftypevr {@code{openvpn-client-configuration} parameter} tls-auth-client tls-auth
18873 Add an additional layer of HMAC authentication on top of the TLS control
18874 channel to protect against DoS attacks.
18875
18876 Defaults to @samp{#f}.
18877
18878 @end deftypevr
18879
18880 @deftypevr {@code{openvpn-client-configuration} parameter} key-usage verify-key-usage?
18881 Whether to check the server certificate has server usage extension.
18882
18883 Defaults to @samp{#t}.
18884
18885 @end deftypevr
18886
18887 @deftypevr {@code{openvpn-client-configuration} parameter} bind bind?
18888 Bind to a specific local port number.
18889
18890 Defaults to @samp{#f}.
18891
18892 @end deftypevr
18893
18894 @deftypevr {@code{openvpn-client-configuration} parameter} resolv-retry resolv-retry?
18895 Retry resolving server address.
18896
18897 Defaults to @samp{#t}.
18898
18899 @end deftypevr
18900
18901 @deftypevr {@code{openvpn-client-configuration} parameter} openvpn-remote-list remote
18902 A list of remote servers to connect to.
18903
18904 Defaults to @samp{()}.
18905
18906 Available @code{openvpn-remote-configuration} fields are:
18907
18908 @deftypevr {@code{openvpn-remote-configuration} parameter} string name
18909 Server name.
18910
18911 Defaults to @samp{"my-server"}.
18912
18913 @end deftypevr
18914
18915 @deftypevr {@code{openvpn-remote-configuration} parameter} number port
18916 Port number the server listens to.
18917
18918 Defaults to @samp{1194}.
18919
18920 @end deftypevr
18921
18922 @end deftypevr
18923 @c %end of automatic openvpn-client documentation
18924
18925 @c %automatically generated documentation
18926
18927 Available @code{openvpn-server-configuration} fields are:
18928
18929 @deftypevr {@code{openvpn-server-configuration} parameter} package openvpn
18930 The OpenVPN package.
18931
18932 @end deftypevr
18933
18934 @deftypevr {@code{openvpn-server-configuration} parameter} string pid-file
18935 The OpenVPN pid file.
18936
18937 Defaults to @samp{"/var/run/openvpn/openvpn.pid"}.
18938
18939 @end deftypevr
18940
18941 @deftypevr {@code{openvpn-server-configuration} parameter} proto proto
18942 The protocol (UDP or TCP) used to open a channel between clients and
18943 servers.
18944
18945 Defaults to @samp{udp}.
18946
18947 @end deftypevr
18948
18949 @deftypevr {@code{openvpn-server-configuration} parameter} dev dev
18950 The device type used to represent the VPN connection.
18951
18952 Defaults to @samp{tun}.
18953
18954 @end deftypevr
18955
18956 @deftypevr {@code{openvpn-server-configuration} parameter} string ca
18957 The certificate authority to check connections against.
18958
18959 Defaults to @samp{"/etc/openvpn/ca.crt"}.
18960
18961 @end deftypevr
18962
18963 @deftypevr {@code{openvpn-server-configuration} parameter} string cert
18964 The certificate of the machine the daemon is running on. It should be
18965 signed by the authority given in @code{ca}.
18966
18967 Defaults to @samp{"/etc/openvpn/client.crt"}.
18968
18969 @end deftypevr
18970
18971 @deftypevr {@code{openvpn-server-configuration} parameter} string key
18972 The key of the machine the daemon is running on. It must be the key whose
18973 certificate is @code{cert}.
18974
18975 Defaults to @samp{"/etc/openvpn/client.key"}.
18976
18977 @end deftypevr
18978
18979 @deftypevr {@code{openvpn-server-configuration} parameter} boolean comp-lzo?
18980 Whether to use the lzo compression algorithm.
18981
18982 Defaults to @samp{#t}.
18983
18984 @end deftypevr
18985
18986 @deftypevr {@code{openvpn-server-configuration} parameter} boolean persist-key?
18987 Don't re-read key files across SIGUSR1 or --ping-restart.
18988
18989 Defaults to @samp{#t}.
18990
18991 @end deftypevr
18992
18993 @deftypevr {@code{openvpn-server-configuration} parameter} boolean persist-tun?
18994 Don't close and reopen TUN/TAP device or run up/down scripts across
18995 SIGUSR1 or --ping-restart restarts.
18996
18997 Defaults to @samp{#t}.
18998
18999 @end deftypevr
19000
19001 @deftypevr {@code{openvpn-server-configuration} parameter} number verbosity
19002 Verbosity level.
19003
19004 Defaults to @samp{3}.
19005
19006 @end deftypevr
19007
19008 @deftypevr {@code{openvpn-server-configuration} parameter} tls-auth-server tls-auth
19009 Add an additional layer of HMAC authentication on top of the TLS control
19010 channel to protect against DoS attacks.
19011
19012 Defaults to @samp{#f}.
19013
19014 @end deftypevr
19015
19016 @deftypevr {@code{openvpn-server-configuration} parameter} number port
19017 Specifies the port number on which the server listens.
19018
19019 Defaults to @samp{1194}.
19020
19021 @end deftypevr
19022
19023 @deftypevr {@code{openvpn-server-configuration} parameter} ip-mask server
19024 An ip and mask specifying the subnet inside the virtual network.
19025
19026 Defaults to @samp{"10.8.0.0 255.255.255.0"}.
19027
19028 @end deftypevr
19029
19030 @deftypevr {@code{openvpn-server-configuration} parameter} cidr6 server-ipv6
19031 A CIDR notation specifying the IPv6 subnet inside the virtual network.
19032
19033 Defaults to @samp{#f}.
19034
19035 @end deftypevr
19036
19037 @deftypevr {@code{openvpn-server-configuration} parameter} string dh
19038 The Diffie-Hellman parameters file.
19039
19040 Defaults to @samp{"/etc/openvpn/dh2048.pem"}.
19041
19042 @end deftypevr
19043
19044 @deftypevr {@code{openvpn-server-configuration} parameter} string ifconfig-pool-persist
19045 The file that records client IPs.
19046
19047 Defaults to @samp{"/etc/openvpn/ipp.txt"}.
19048
19049 @end deftypevr
19050
19051 @deftypevr {@code{openvpn-server-configuration} parameter} gateway redirect-gateway?
19052 When true, the server will act as a gateway for its clients.
19053
19054 Defaults to @samp{#f}.
19055
19056 @end deftypevr
19057
19058 @deftypevr {@code{openvpn-server-configuration} parameter} boolean client-to-client?
19059 When true, clients are allowed to talk to each other inside the VPN.
19060
19061 Defaults to @samp{#f}.
19062
19063 @end deftypevr
19064
19065 @deftypevr {@code{openvpn-server-configuration} parameter} keepalive keepalive
19066 Causes ping-like messages to be sent back and forth over the link so
19067 that each side knows when the other side has gone down. @code{keepalive}
19068 requires a pair. The first element is the period of the ping sending,
19069 and the second element is the timeout before considering the other side
19070 down.
19071
19072 @end deftypevr
19073
19074 @deftypevr {@code{openvpn-server-configuration} parameter} number max-clients
19075 The maximum number of clients.
19076
19077 Defaults to @samp{100}.
19078
19079 @end deftypevr
19080
19081 @deftypevr {@code{openvpn-server-configuration} parameter} string status
19082 The status file. This file shows a small report on current connection.
19083 It is truncated and rewritten every minute.
19084
19085 Defaults to @samp{"/var/run/openvpn/status"}.
19086
19087 @end deftypevr
19088
19089 @deftypevr {@code{openvpn-server-configuration} parameter} openvpn-ccd-list client-config-dir
19090 The list of configuration for some clients.
19091
19092 Defaults to @samp{()}.
19093
19094 Available @code{openvpn-ccd-configuration} fields are:
19095
19096 @deftypevr {@code{openvpn-ccd-configuration} parameter} string name
19097 Client name.
19098
19099 Defaults to @samp{"client"}.
19100
19101 @end deftypevr
19102
19103 @deftypevr {@code{openvpn-ccd-configuration} parameter} ip-mask iroute
19104 Client own network
19105
19106 Defaults to @samp{#f}.
19107
19108 @end deftypevr
19109
19110 @deftypevr {@code{openvpn-ccd-configuration} parameter} ip-mask ifconfig-push
19111 Client VPN IP.
19112
19113 Defaults to @samp{#f}.
19114
19115 @end deftypevr
19116
19117 @end deftypevr
19118
19119
19120 @c %end of automatic openvpn-server documentation
19121
19122
19123 @node Network File System
19124 @subsubsection Network File System
19125 @cindex NFS
19126
19127 The @code{(gnu services nfs)} module provides the following services,
19128 which are most commonly used in relation to mounting or exporting
19129 directory trees as @dfn{network file systems} (NFS).
19130
19131 @subsubheading RPC Bind Service
19132 @cindex rpcbind
19133
19134 The RPC Bind service provides a facility to map program numbers into
19135 universal addresses.
19136 Many NFS related services use this facility. Hence it is automatically
19137 started when a dependent service starts.
19138
19139 @defvr {Scheme Variable} rpcbind-service-type
19140 A service type for the RPC portmapper daemon.
19141 @end defvr
19142
19143
19144 @deftp {Data Type} rpcbind-configuration
19145 Data type representing the configuration of the RPC Bind Service.
19146 This type has the following parameters:
19147 @table @asis
19148 @item @code{rpcbind} (default: @code{rpcbind})
19149 The rpcbind package to use.
19150
19151 @item @code{warm-start?} (default: @code{#t})
19152 If this parameter is @code{#t}, then the daemon will read a
19153 state file on startup thus reloading state information saved by a previous
19154 instance.
19155 @end table
19156 @end deftp
19157
19158
19159 @subsubheading Pipefs Pseudo File System
19160 @cindex pipefs
19161 @cindex rpc_pipefs
19162
19163 The pipefs file system is used to transfer NFS related data
19164 between the kernel and user space programs.
19165
19166 @defvr {Scheme Variable} pipefs-service-type
19167 A service type for the pipefs pseudo file system.
19168 @end defvr
19169
19170 @deftp {Data Type} pipefs-configuration
19171 Data type representing the configuration of the pipefs pseudo file system service.
19172 This type has the following parameters:
19173 @table @asis
19174 @item @code{mount-point} (default: @code{"/var/lib/nfs/rpc_pipefs"})
19175 The directory to which the file system is to be attached.
19176 @end table
19177 @end deftp
19178
19179
19180 @subsubheading GSS Daemon Service
19181 @cindex GSSD
19182 @cindex GSS
19183 @cindex global security system
19184
19185 The @dfn{global security system} (GSS) daemon provides strong security for RPC
19186 based protocols.
19187 Before exchanging RPC requests an RPC client must establish a security
19188 context. Typically this is done using the Kerberos command @command{kinit}
19189 or automatically at login time using PAM services (@pxref{Kerberos Services}).
19190
19191 @defvr {Scheme Variable} gss-service-type
19192 A service type for the Global Security System (GSS) daemon.
19193 @end defvr
19194
19195 @deftp {Data Type} gss-configuration
19196 Data type representing the configuration of the GSS daemon service.
19197 This type has the following parameters:
19198 @table @asis
19199 @item @code{nfs-utils} (default: @code{nfs-utils})
19200 The package in which the @command{rpc.gssd} command is to be found.
19201
19202 @item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
19203 The directory where the pipefs file system is mounted.
19204
19205 @end table
19206 @end deftp
19207
19208
19209 @subsubheading IDMAP Daemon Service
19210 @cindex idmapd
19211 @cindex name mapper
19212
19213 The idmap daemon service provides mapping between user IDs and user names.
19214 Typically it is required in order to access file systems mounted via NFSv4.
19215
19216 @defvr {Scheme Variable} idmap-service-type
19217 A service type for the Identity Mapper (IDMAP) daemon.
19218 @end defvr
19219
19220 @deftp {Data Type} idmap-configuration
19221 Data type representing the configuration of the IDMAP daemon service.
19222 This type has the following parameters:
19223 @table @asis
19224 @item @code{nfs-utils} (default: @code{nfs-utils})
19225 The package in which the @command{rpc.idmapd} command is to be found.
19226
19227 @item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
19228 The directory where the pipefs file system is mounted.
19229
19230 @item @code{domain} (default: @code{#f})
19231 The local NFSv4 domain name.
19232 This must be a string or @code{#f}.
19233 If it is @code{#f} then the daemon will use the host's fully qualified domain name.
19234
19235 @end table
19236 @end deftp
19237
19238 @node Continuous Integration
19239 @subsubsection Continuous Integration
19240
19241 @cindex continuous integration
19242 @uref{https://git.savannah.gnu.org/cgit/guix/guix-cuirass.git, Cuirass} is a
19243 continuous integration tool for Guix. It can be used both for development and
19244 for providing substitutes to others (@pxref{Substitutes}).
19245
19246 The @code{(gnu services cuirass)} module provides the following service.
19247
19248 @defvr {Scheme Procedure} cuirass-service-type
19249 The type of the Cuirass service. Its value must be a
19250 @code{cuirass-configuration} object, as described below.
19251 @end defvr
19252
19253 To add build jobs, you have to set the @code{specifications} field of the
19254 configuration. Here is an example of a service that polls the Guix repository
19255 and builds the packages from a manifest. Some of the packages are defined in
19256 the @code{"custom-packages"} input, which is the equivalent of
19257 @code{GUIX_PACKAGE_PATH}.
19258
19259 @example
19260 (define %cuirass-specs
19261 #~(list
19262 '((#:name . "my-manifest")
19263 (#:load-path-inputs . ("guix"))
19264 (#:package-path-inputs . ("custom-packages"))
19265 (#:proc-input . "guix")
19266 (#:proc-file . "build-aux/cuirass/gnu-system.scm")
19267 (#:proc . cuirass-jobs)
19268 (#:proc-args . ((subset . "manifests")
19269 (systems . ("x86_64-linux"))
19270 (manifests . (("config" . "guix/manifest.scm")))))
19271 (#:inputs . (((#:name . "guix")
19272 (#:url . "git://git.savannah.gnu.org/guix.git")
19273 (#:load-path . ".")
19274 (#:branch . "master")
19275 (#:no-compile? . #t))
19276 ((#:name . "config")
19277 (#:url . "git://git.example.org/config.git")
19278 (#:load-path . ".")
19279 (#:branch . "master")
19280 (#:no-compile? . #t))
19281 ((#:name . "custom-packages")
19282 (#:url . "git://git.example.org/custom-packages.git")
19283 (#:load-path . ".")
19284 (#:branch . "master")
19285 (#:no-compile? . #t)))))))
19286
19287 (service cuirass-service-type
19288 (cuirass-configuration
19289 (specifications %cuirass-specs)))
19290 @end example
19291
19292 While information related to build jobs is located directly in the
19293 specifications, global settings for the @command{cuirass} process are
19294 accessible in other @code{cuirass-configuration} fields.
19295
19296 @deftp {Data Type} cuirass-configuration
19297 Data type representing the configuration of Cuirass.
19298
19299 @table @asis
19300 @item @code{log-file} (default: @code{"/var/log/cuirass.log"})
19301 Location of the log file.
19302
19303 @item @code{cache-directory} (default: @code{"/var/cache/cuirass"})
19304 Location of the repository cache.
19305
19306 @item @code{user} (default: @code{"cuirass"})
19307 Owner of the @code{cuirass} process.
19308
19309 @item @code{group} (default: @code{"cuirass"})
19310 Owner's group of the @code{cuirass} process.
19311
19312 @item @code{interval} (default: @code{60})
19313 Number of seconds between the poll of the repositories followed by the
19314 Cuirass jobs.
19315
19316 @item @code{database} (default: @code{"/var/lib/cuirass/cuirass.db"})
19317 Location of sqlite database which contains the build results and previously
19318 added specifications.
19319
19320 @item @code{ttl} (default: @code{(* 30 24 3600)})
19321 Specifies the time-to-live (TTL) in seconds of garbage collector roots that
19322 are registered for build results. This means that build results are protected
19323 from garbage collection for at least @var{ttl} seconds.
19324
19325 @item @code{port} (default: @code{8081})
19326 Port number used by the HTTP server.
19327
19328 @item --listen=@var{host}
19329 Listen on the network interface for @var{host}. The default is to
19330 accept connections from localhost.
19331
19332 @item @code{specifications} (default: @code{#~'()})
19333 A gexp (@pxref{G-Expressions}) that evaluates to a list of specifications,
19334 where a specification is an association list
19335 (@pxref{Associations Lists,,, guile, GNU Guile Reference Manual}) whose
19336 keys are keywords (@code{#:keyword-example}) as shown in the example
19337 above.
19338
19339 @item @code{use-substitutes?} (default: @code{#f})
19340 This allows using substitutes to avoid building every dependencies of a job
19341 from source.
19342
19343 @item @code{one-shot?} (default: @code{#f})
19344 Only evaluate specifications and build derivations once.
19345
19346 @item @code{fallback?} (default: @code{#f})
19347 When substituting a pre-built binary fails, fall back to building
19348 packages locally.
19349
19350 @item @code{cuirass} (default: @code{cuirass})
19351 The Cuirass package to use.
19352 @end table
19353 @end deftp
19354
19355 @node Power Management Services
19356 @subsubsection Power Management Services
19357
19358 @cindex tlp
19359 @cindex power management with TLP
19360 @subsubheading TLP daemon
19361
19362 The @code{(gnu services pm)} module provides a Guix service definition
19363 for the Linux power management tool TLP.
19364
19365 TLP enables various powersaving modes in userspace and kernel.
19366 Contrary to @code{upower-service}, it is not a passive,
19367 monitoring tool, as it will apply custom settings each time a new power
19368 source is detected. More information can be found at
19369 @uref{http://linrunner.de/en/tlp/tlp.html, TLP home page}.
19370
19371 @deffn {Scheme Variable} tlp-service-type
19372 The service type for the TLP tool. Its value should be a valid
19373 TLP configuration (see below). To use the default settings, simply
19374 write:
19375 @example
19376 (service tlp-service-type)
19377 @end example
19378 @end deffn
19379
19380 By default TLP does not need much configuration but most TLP parameters
19381 can be tweaked using @code{tlp-configuration}.
19382
19383 Each parameter definition is preceded by its type; for example,
19384 @samp{boolean foo} indicates that the @code{foo} parameter
19385 should be specified as a boolean. Types starting with
19386 @code{maybe-} denote parameters that won't show up in TLP config file
19387 when their value is @code{'disabled}.
19388
19389 @c The following documentation was initially generated by
19390 @c (generate-tlp-documentation) in (gnu services pm). Manually maintained
19391 @c documentation is better, so we shouldn't hesitate to edit below as
19392 @c needed. However if the change you want to make to this documentation
19393 @c can be done in an automated way, it's probably easier to change
19394 @c (generate-documentation) than to make it below and have to deal with
19395 @c the churn as TLP updates.
19396
19397 Available @code{tlp-configuration} fields are:
19398
19399 @deftypevr {@code{tlp-configuration} parameter} package tlp
19400 The TLP package.
19401
19402 @end deftypevr
19403
19404 @deftypevr {@code{tlp-configuration} parameter} boolean tlp-enable?
19405 Set to true if you wish to enable TLP.
19406
19407 Defaults to @samp{#t}.
19408
19409 @end deftypevr
19410
19411 @deftypevr {@code{tlp-configuration} parameter} string tlp-default-mode
19412 Default mode when no power supply can be detected. Alternatives are AC
19413 and BAT.
19414
19415 Defaults to @samp{"AC"}.
19416
19417 @end deftypevr
19418
19419 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer disk-idle-secs-on-ac
19420 Number of seconds Linux kernel has to wait after the disk goes idle,
19421 before syncing on AC.
19422
19423 Defaults to @samp{0}.
19424
19425 @end deftypevr
19426
19427 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer disk-idle-secs-on-bat
19428 Same as @code{disk-idle-ac} but on BAT mode.
19429
19430 Defaults to @samp{2}.
19431
19432 @end deftypevr
19433
19434 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer max-lost-work-secs-on-ac
19435 Dirty pages flushing periodicity, expressed in seconds.
19436
19437 Defaults to @samp{15}.
19438
19439 @end deftypevr
19440
19441 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer max-lost-work-secs-on-bat
19442 Same as @code{max-lost-work-secs-on-ac} but on BAT mode.
19443
19444 Defaults to @samp{60}.
19445
19446 @end deftypevr
19447
19448 @deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list cpu-scaling-governor-on-ac
19449 CPU frequency scaling governor on AC mode. With intel_pstate driver,
19450 alternatives are powersave and performance. With acpi-cpufreq driver,
19451 alternatives are ondemand, powersave, performance and conservative.
19452
19453 Defaults to @samp{disabled}.
19454
19455 @end deftypevr
19456
19457 @deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list cpu-scaling-governor-on-bat
19458 Same as @code{cpu-scaling-governor-on-ac} but on BAT mode.
19459
19460 Defaults to @samp{disabled}.
19461
19462 @end deftypevr
19463
19464 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-min-freq-on-ac
19465 Set the min available frequency for the scaling governor on AC.
19466
19467 Defaults to @samp{disabled}.
19468
19469 @end deftypevr
19470
19471 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-max-freq-on-ac
19472 Set the max available frequency for the scaling governor on AC.
19473
19474 Defaults to @samp{disabled}.
19475
19476 @end deftypevr
19477
19478 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-min-freq-on-bat
19479 Set the min available frequency for the scaling governor on BAT.
19480
19481 Defaults to @samp{disabled}.
19482
19483 @end deftypevr
19484
19485 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-max-freq-on-bat
19486 Set the max available frequency for the scaling governor on BAT.
19487
19488 Defaults to @samp{disabled}.
19489
19490 @end deftypevr
19491
19492 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-min-perf-on-ac
19493 Limit the min P-state to control the power dissipation of the CPU, in AC
19494 mode. Values are stated as a percentage of the available performance.
19495
19496 Defaults to @samp{disabled}.
19497
19498 @end deftypevr
19499
19500 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-max-perf-on-ac
19501 Limit the max P-state to control the power dissipation of the CPU, in AC
19502 mode. Values are stated as a percentage of the available performance.
19503
19504 Defaults to @samp{disabled}.
19505
19506 @end deftypevr
19507
19508 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-min-perf-on-bat
19509 Same as @code{cpu-min-perf-on-ac} on BAT mode.
19510
19511 Defaults to @samp{disabled}.
19512
19513 @end deftypevr
19514
19515 @deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-max-perf-on-bat
19516 Same as @code{cpu-max-perf-on-ac} on BAT mode.
19517
19518 Defaults to @samp{disabled}.
19519
19520 @end deftypevr
19521
19522 @deftypevr {@code{tlp-configuration} parameter} maybe-boolean cpu-boost-on-ac?
19523 Enable CPU turbo boost feature on AC mode.
19524
19525 Defaults to @samp{disabled}.
19526
19527 @end deftypevr
19528
19529 @deftypevr {@code{tlp-configuration} parameter} maybe-boolean cpu-boost-on-bat?
19530 Same as @code{cpu-boost-on-ac?} on BAT mode.
19531
19532 Defaults to @samp{disabled}.
19533
19534 @end deftypevr
19535
19536 @deftypevr {@code{tlp-configuration} parameter} boolean sched-powersave-on-ac?
19537 Allow Linux kernel to minimize the number of CPU cores/hyper-threads
19538 used under light load conditions.
19539
19540 Defaults to @samp{#f}.
19541
19542 @end deftypevr
19543
19544 @deftypevr {@code{tlp-configuration} parameter} boolean sched-powersave-on-bat?
19545 Same as @code{sched-powersave-on-ac?} but on BAT mode.
19546
19547 Defaults to @samp{#t}.
19548
19549 @end deftypevr
19550
19551 @deftypevr {@code{tlp-configuration} parameter} boolean nmi-watchdog?
19552 Enable Linux kernel NMI watchdog.
19553
19554 Defaults to @samp{#f}.
19555
19556 @end deftypevr
19557
19558 @deftypevr {@code{tlp-configuration} parameter} maybe-string phc-controls
19559 For Linux kernels with PHC patch applied, change CPU voltages. An
19560 example value would be @samp{"F:V F:V F:V F:V"}.
19561
19562 Defaults to @samp{disabled}.
19563
19564 @end deftypevr
19565
19566 @deftypevr {@code{tlp-configuration} parameter} string energy-perf-policy-on-ac
19567 Set CPU performance versus energy saving policy on AC. Alternatives are
19568 performance, normal, powersave.
19569
19570 Defaults to @samp{"performance"}.
19571
19572 @end deftypevr
19573
19574 @deftypevr {@code{tlp-configuration} parameter} string energy-perf-policy-on-bat
19575 Same as @code{energy-perf-policy-ac} but on BAT mode.
19576
19577 Defaults to @samp{"powersave"}.
19578
19579 @end deftypevr
19580
19581 @deftypevr {@code{tlp-configuration} parameter} space-separated-string-list disks-devices
19582 Hard disk devices.
19583
19584 @end deftypevr
19585
19586 @deftypevr {@code{tlp-configuration} parameter} space-separated-string-list disk-apm-level-on-ac
19587 Hard disk advanced power management level.
19588
19589 @end deftypevr
19590
19591 @deftypevr {@code{tlp-configuration} parameter} space-separated-string-list disk-apm-level-on-bat
19592 Same as @code{disk-apm-bat} but on BAT mode.
19593
19594 @end deftypevr
19595
19596 @deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list disk-spindown-timeout-on-ac
19597 Hard disk spin down timeout. One value has to be specified for each
19598 declared hard disk.
19599
19600 Defaults to @samp{disabled}.
19601
19602 @end deftypevr
19603
19604 @deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list disk-spindown-timeout-on-bat
19605 Same as @code{disk-spindown-timeout-on-ac} but on BAT mode.
19606
19607 Defaults to @samp{disabled}.
19608
19609 @end deftypevr
19610
19611 @deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list disk-iosched
19612 Select IO scheduler for disk devices. One value has to be specified for
19613 each declared hard disk. Example alternatives are cfq, deadline and
19614 noop.
19615
19616 Defaults to @samp{disabled}.
19617
19618 @end deftypevr
19619
19620 @deftypevr {@code{tlp-configuration} parameter} string sata-linkpwr-on-ac
19621 SATA aggressive link power management (ALPM) level. Alternatives are
19622 min_power, medium_power, max_performance.
19623
19624 Defaults to @samp{"max_performance"}.
19625
19626 @end deftypevr
19627
19628 @deftypevr {@code{tlp-configuration} parameter} string sata-linkpwr-on-bat
19629 Same as @code{sata-linkpwr-ac} but on BAT mode.
19630
19631 Defaults to @samp{"min_power"}.
19632
19633 @end deftypevr
19634
19635 @deftypevr {@code{tlp-configuration} parameter} maybe-string sata-linkpwr-blacklist
19636 Exclude specified SATA host devices for link power management.
19637
19638 Defaults to @samp{disabled}.
19639
19640 @end deftypevr
19641
19642 @deftypevr {@code{tlp-configuration} parameter} maybe-on-off-boolean ahci-runtime-pm-on-ac?
19643 Enable Runtime Power Management for AHCI controller and disks on AC
19644 mode.
19645
19646 Defaults to @samp{disabled}.
19647
19648 @end deftypevr
19649
19650 @deftypevr {@code{tlp-configuration} parameter} maybe-on-off-boolean ahci-runtime-pm-on-bat?
19651 Same as @code{ahci-runtime-pm-on-ac} on BAT mode.
19652
19653 Defaults to @samp{disabled}.
19654
19655 @end deftypevr
19656
19657 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer ahci-runtime-pm-timeout
19658 Seconds of inactivity before disk is suspended.
19659
19660 Defaults to @samp{15}.
19661
19662 @end deftypevr
19663
19664 @deftypevr {@code{tlp-configuration} parameter} string pcie-aspm-on-ac
19665 PCI Express Active State Power Management level. Alternatives are
19666 default, performance, powersave.
19667
19668 Defaults to @samp{"performance"}.
19669
19670 @end deftypevr
19671
19672 @deftypevr {@code{tlp-configuration} parameter} string pcie-aspm-on-bat
19673 Same as @code{pcie-aspm-ac} but on BAT mode.
19674
19675 Defaults to @samp{"powersave"}.
19676
19677 @end deftypevr
19678
19679 @deftypevr {@code{tlp-configuration} parameter} string radeon-power-profile-on-ac
19680 Radeon graphics clock speed level. Alternatives are low, mid, high,
19681 auto, default.
19682
19683 Defaults to @samp{"high"}.
19684
19685 @end deftypevr
19686
19687 @deftypevr {@code{tlp-configuration} parameter} string radeon-power-profile-on-bat
19688 Same as @code{radeon-power-ac} but on BAT mode.
19689
19690 Defaults to @samp{"low"}.
19691
19692 @end deftypevr
19693
19694 @deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-state-on-ac
19695 Radeon dynamic power management method (DPM). Alternatives are battery,
19696 performance.
19697
19698 Defaults to @samp{"performance"}.
19699
19700 @end deftypevr
19701
19702 @deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-state-on-bat
19703 Same as @code{radeon-dpm-state-ac} but on BAT mode.
19704
19705 Defaults to @samp{"battery"}.
19706
19707 @end deftypevr
19708
19709 @deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-perf-level-on-ac
19710 Radeon DPM performance level. Alternatives are auto, low, high.
19711
19712 Defaults to @samp{"auto"}.
19713
19714 @end deftypevr
19715
19716 @deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-perf-level-on-bat
19717 Same as @code{radeon-dpm-perf-ac} but on BAT mode.
19718
19719 Defaults to @samp{"auto"}.
19720
19721 @end deftypevr
19722
19723 @deftypevr {@code{tlp-configuration} parameter} on-off-boolean wifi-pwr-on-ac?
19724 Wifi power saving mode.
19725
19726 Defaults to @samp{#f}.
19727
19728 @end deftypevr
19729
19730 @deftypevr {@code{tlp-configuration} parameter} on-off-boolean wifi-pwr-on-bat?
19731 Same as @code{wifi-power-ac?} but on BAT mode.
19732
19733 Defaults to @samp{#t}.
19734
19735 @end deftypevr
19736
19737 @deftypevr {@code{tlp-configuration} parameter} y-n-boolean wol-disable?
19738 Disable wake on LAN.
19739
19740 Defaults to @samp{#t}.
19741
19742 @end deftypevr
19743
19744 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer sound-power-save-on-ac
19745 Timeout duration in seconds before activating audio power saving on
19746 Intel HDA and AC97 devices. A value of 0 disables power saving.
19747
19748 Defaults to @samp{0}.
19749
19750 @end deftypevr
19751
19752 @deftypevr {@code{tlp-configuration} parameter} non-negative-integer sound-power-save-on-bat
19753 Same as @code{sound-powersave-ac} but on BAT mode.
19754
19755 Defaults to @samp{1}.
19756
19757 @end deftypevr
19758
19759 @deftypevr {@code{tlp-configuration} parameter} y-n-boolean sound-power-save-controller?
19760 Disable controller in powersaving mode on Intel HDA devices.
19761
19762 Defaults to @samp{#t}.
19763
19764 @end deftypevr
19765
19766 @deftypevr {@code{tlp-configuration} parameter} boolean bay-poweroff-on-bat?
19767 Enable optical drive in UltraBay/MediaBay on BAT mode. Drive can be
19768 powered on again by releasing (and reinserting) the eject lever or by
19769 pressing the disc eject button on newer models.
19770
19771 Defaults to @samp{#f}.
19772
19773 @end deftypevr
19774
19775 @deftypevr {@code{tlp-configuration} parameter} string bay-device
19776 Name of the optical drive device to power off.
19777
19778 Defaults to @samp{"sr0"}.
19779
19780 @end deftypevr
19781
19782 @deftypevr {@code{tlp-configuration} parameter} string runtime-pm-on-ac
19783 Runtime Power Management for PCI(e) bus devices. Alternatives are on
19784 and auto.
19785
19786 Defaults to @samp{"on"}.
19787
19788 @end deftypevr
19789
19790 @deftypevr {@code{tlp-configuration} parameter} string runtime-pm-on-bat
19791 Same as @code{runtime-pm-ac} but on BAT mode.
19792
19793 Defaults to @samp{"auto"}.
19794
19795 @end deftypevr
19796
19797 @deftypevr {@code{tlp-configuration} parameter} boolean runtime-pm-all?
19798 Runtime Power Management for all PCI(e) bus devices, except blacklisted
19799 ones.
19800
19801 Defaults to @samp{#t}.
19802
19803 @end deftypevr
19804
19805 @deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list runtime-pm-blacklist
19806 Exclude specified PCI(e) device addresses from Runtime Power Management.
19807
19808 Defaults to @samp{disabled}.
19809
19810 @end deftypevr
19811
19812 @deftypevr {@code{tlp-configuration} parameter} space-separated-string-list runtime-pm-driver-blacklist
19813 Exclude PCI(e) devices assigned to the specified drivers from Runtime
19814 Power Management.
19815
19816 @end deftypevr
19817
19818 @deftypevr {@code{tlp-configuration} parameter} boolean usb-autosuspend?
19819 Enable USB autosuspend feature.
19820
19821 Defaults to @samp{#t}.
19822
19823 @end deftypevr
19824
19825 @deftypevr {@code{tlp-configuration} parameter} maybe-string usb-blacklist
19826 Exclude specified devices from USB autosuspend.
19827
19828 Defaults to @samp{disabled}.
19829
19830 @end deftypevr
19831
19832 @deftypevr {@code{tlp-configuration} parameter} boolean usb-blacklist-wwan?
19833 Exclude WWAN devices from USB autosuspend.
19834
19835 Defaults to @samp{#t}.
19836
19837 @end deftypevr
19838
19839 @deftypevr {@code{tlp-configuration} parameter} maybe-string usb-whitelist
19840 Include specified devices into USB autosuspend, even if they are already
19841 excluded by the driver or via @code{usb-blacklist-wwan?}.
19842
19843 Defaults to @samp{disabled}.
19844
19845 @end deftypevr
19846
19847 @deftypevr {@code{tlp-configuration} parameter} maybe-boolean usb-autosuspend-disable-on-shutdown?
19848 Enable USB autosuspend before shutdown.
19849
19850 Defaults to @samp{disabled}.
19851
19852 @end deftypevr
19853
19854 @deftypevr {@code{tlp-configuration} parameter} boolean restore-device-state-on-startup?
19855 Restore radio device state (bluetooth, wifi, wwan) from previous
19856 shutdown on system startup.
19857
19858 Defaults to @samp{#f}.
19859
19860 @end deftypevr
19861
19862 @cindex thermald
19863 @cindex CPU frequency scaling with thermald
19864 @subsubheading Thermald daemon
19865
19866 The @code{(gnu services pm)} module provides an interface to
19867 thermald, a CPU frequency scaling service which helps prevent overheating.
19868
19869 @defvr {Scheme Variable} thermald-service-type
19870 This is the service type for
19871 @uref{https://01.org/linux-thermal-daemon/, thermald}, the Linux
19872 Thermal Daemon, which is responsible for controlling the thermal state
19873 of processors and preventing overheating.
19874 @end defvr
19875
19876 @deftp {Data Type} thermald-configuration
19877 Data type representing the configuration of @code{thermald-service-type}.
19878
19879 @table @asis
19880 @item @code{ignore-cpuid-check?} (default: @code{#f})
19881 Ignore cpuid check for supported CPU models.
19882
19883 @item @code{thermald} (default: @var{thermald})
19884 Package object of thermald.
19885
19886 @end table
19887 @end deftp
19888
19889 @node Audio Services
19890 @subsubsection Audio Services
19891
19892 The @code{(gnu services audio)} module provides a service to start MPD
19893 (the Music Player Daemon).
19894
19895 @cindex mpd
19896 @subsubheading Music Player Daemon
19897
19898 The Music Player Daemon (MPD) is a service that can play music while
19899 being controlled from the local machine or over the network by a variety
19900 of clients.
19901
19902 The following example shows how one might run @code{mpd} as user
19903 @code{"bob"} on port @code{6666}. It uses pulseaudio for output.
19904
19905 @example
19906 (service mpd-service-type
19907 (mpd-configuration
19908 (user "bob")
19909 (port "6666")))
19910 @end example
19911
19912 @defvr {Scheme Variable} mpd-service-type
19913 The service type for @command{mpd}
19914 @end defvr
19915
19916 @deftp {Data Type} mpd-configuration
19917 Data type representing the configuration of @command{mpd}.
19918
19919 @table @asis
19920 @item @code{user} (default: @code{"mpd"})
19921 The user to run mpd as.
19922
19923 @item @code{music-dir} (default: @code{"~/Music"})
19924 The directory to scan for music files.
19925
19926 @item @code{playlist-dir} (default: @code{"~/.mpd/playlists"})
19927 The directory to store playlists.
19928
19929 @item @code{port} (default: @code{"6600"})
19930 The port to run mpd on.
19931
19932 @item @code{address} (default: @code{"any"})
19933 The address that mpd will bind to. To use a Unix domain socket,
19934 an absolute path can be specified here.
19935
19936 @end table
19937 @end deftp
19938
19939 @node Virtualization Services
19940 @subsubsection Virtualization services
19941
19942 The @code{(gnu services virtualization)} module provides services for
19943 the libvirt and virtlog daemons, as well as other virtualization-related
19944 services.
19945
19946 @subsubheading Libvirt daemon
19947 @code{libvirtd} is the server side daemon component of the libvirt
19948 virtualization management system. This daemon runs on host servers
19949 and performs required management tasks for virtualized guests.
19950
19951 @deffn {Scheme Variable} libvirt-service-type
19952 This is the type of the @uref{https://libvirt.org, libvirt daemon}.
19953 Its value must be a @code{libvirt-configuration}.
19954
19955 @example
19956 (service libvirt-service-type
19957 (libvirt-configuration
19958 (unix-sock-group "libvirt")
19959 (tls-port "16555")))
19960 @end example
19961 @end deffn
19962
19963 @c Auto-generated with (generate-libvirt-documentation)
19964 Available @code{libvirt-configuration} fields are:
19965
19966 @deftypevr {@code{libvirt-configuration} parameter} package libvirt
19967 Libvirt package.
19968
19969 @end deftypevr
19970
19971 @deftypevr {@code{libvirt-configuration} parameter} boolean listen-tls?
19972 Flag listening for secure TLS connections on the public TCP/IP port.
19973 must set @code{listen} for this to have any effect.
19974
19975 It is necessary to setup a CA and issue server certificates before using
19976 this capability.
19977
19978 Defaults to @samp{#t}.
19979
19980 @end deftypevr
19981
19982 @deftypevr {@code{libvirt-configuration} parameter} boolean listen-tcp?
19983 Listen for unencrypted TCP connections on the public TCP/IP port. must
19984 set @code{listen} for this to have any effect.
19985
19986 Using the TCP socket requires SASL authentication by default. Only SASL
19987 mechanisms which support data encryption are allowed. This is
19988 DIGEST_MD5 and GSSAPI (Kerberos5)
19989
19990 Defaults to @samp{#f}.
19991
19992 @end deftypevr
19993
19994 @deftypevr {@code{libvirt-configuration} parameter} string tls-port
19995 Port for accepting secure TLS connections This can be a port number, or
19996 service name
19997
19998 Defaults to @samp{"16514"}.
19999
20000 @end deftypevr
20001
20002 @deftypevr {@code{libvirt-configuration} parameter} string tcp-port
20003 Port for accepting insecure TCP connections This can be a port number,
20004 or service name
20005
20006 Defaults to @samp{"16509"}.
20007
20008 @end deftypevr
20009
20010 @deftypevr {@code{libvirt-configuration} parameter} string listen-addr
20011 IP address or hostname used for client connections.
20012
20013 Defaults to @samp{"0.0.0.0"}.
20014
20015 @end deftypevr
20016
20017 @deftypevr {@code{libvirt-configuration} parameter} boolean mdns-adv?
20018 Flag toggling mDNS advertisement of the libvirt service.
20019
20020 Alternatively can disable for all services on a host by stopping the
20021 Avahi daemon.
20022
20023 Defaults to @samp{#f}.
20024
20025 @end deftypevr
20026
20027 @deftypevr {@code{libvirt-configuration} parameter} string mdns-name
20028 Default mDNS advertisement name. This must be unique on the immediate
20029 broadcast network.
20030
20031 Defaults to @samp{"Virtualization Host <hostname>"}.
20032
20033 @end deftypevr
20034
20035 @deftypevr {@code{libvirt-configuration} parameter} string unix-sock-group
20036 UNIX domain socket group ownership. This can be used to allow a
20037 'trusted' set of users access to management capabilities without
20038 becoming root.
20039
20040 Defaults to @samp{"root"}.
20041
20042 @end deftypevr
20043
20044 @deftypevr {@code{libvirt-configuration} parameter} string unix-sock-ro-perms
20045 UNIX socket permissions for the R/O socket. This is used for monitoring
20046 VM status only.
20047
20048 Defaults to @samp{"0777"}.
20049
20050 @end deftypevr
20051
20052 @deftypevr {@code{libvirt-configuration} parameter} string unix-sock-rw-perms
20053 UNIX socket permissions for the R/W socket. Default allows only root.
20054 If PolicyKit is enabled on the socket, the default will change to allow
20055 everyone (eg, 0777)
20056
20057 Defaults to @samp{"0770"}.
20058
20059 @end deftypevr
20060
20061 @deftypevr {@code{libvirt-configuration} parameter} string unix-sock-admin-perms
20062 UNIX socket permissions for the admin socket. Default allows only owner
20063 (root), do not change it unless you are sure to whom you are exposing
20064 the access to.
20065
20066 Defaults to @samp{"0777"}.
20067
20068 @end deftypevr
20069
20070 @deftypevr {@code{libvirt-configuration} parameter} string unix-sock-dir
20071 The directory in which sockets will be found/created.
20072
20073 Defaults to @samp{"/var/run/libvirt"}.
20074
20075 @end deftypevr
20076
20077 @deftypevr {@code{libvirt-configuration} parameter} string auth-unix-ro
20078 Authentication scheme for UNIX read-only sockets. By default socket
20079 permissions allow anyone to connect
20080
20081 Defaults to @samp{"polkit"}.
20082
20083 @end deftypevr
20084
20085 @deftypevr {@code{libvirt-configuration} parameter} string auth-unix-rw
20086 Authentication scheme for UNIX read-write sockets. By default socket
20087 permissions only allow root. If PolicyKit support was compiled into
20088 libvirt, the default will be to use 'polkit' auth.
20089
20090 Defaults to @samp{"polkit"}.
20091
20092 @end deftypevr
20093
20094 @deftypevr {@code{libvirt-configuration} parameter} string auth-tcp
20095 Authentication scheme for TCP sockets. If you don't enable SASL, then
20096 all TCP traffic is cleartext. Don't do this outside of a dev/test
20097 scenario.
20098
20099 Defaults to @samp{"sasl"}.
20100
20101 @end deftypevr
20102
20103 @deftypevr {@code{libvirt-configuration} parameter} string auth-tls
20104 Authentication scheme for TLS sockets. TLS sockets already have
20105 encryption provided by the TLS layer, and limited authentication is done
20106 by certificates.
20107
20108 It is possible to make use of any SASL authentication mechanism as well,
20109 by using 'sasl' for this option
20110
20111 Defaults to @samp{"none"}.
20112
20113 @end deftypevr
20114
20115 @deftypevr {@code{libvirt-configuration} parameter} optional-list access-drivers
20116 API access control scheme.
20117
20118 By default an authenticated user is allowed access to all APIs. Access
20119 drivers can place restrictions on this.
20120
20121 Defaults to @samp{()}.
20122
20123 @end deftypevr
20124
20125 @deftypevr {@code{libvirt-configuration} parameter} string key-file
20126 Server key file path. If set to an empty string, then no private key is
20127 loaded.
20128
20129 Defaults to @samp{""}.
20130
20131 @end deftypevr
20132
20133 @deftypevr {@code{libvirt-configuration} parameter} string cert-file
20134 Server key file path. If set to an empty string, then no certificate is
20135 loaded.
20136
20137 Defaults to @samp{""}.
20138
20139 @end deftypevr
20140
20141 @deftypevr {@code{libvirt-configuration} parameter} string ca-file
20142 Server key file path. If set to an empty string, then no CA certificate
20143 is loaded.
20144
20145 Defaults to @samp{""}.
20146
20147 @end deftypevr
20148
20149 @deftypevr {@code{libvirt-configuration} parameter} string crl-file
20150 Certificate revocation list path. If set to an empty string, then no
20151 CRL is loaded.
20152
20153 Defaults to @samp{""}.
20154
20155 @end deftypevr
20156
20157 @deftypevr {@code{libvirt-configuration} parameter} boolean tls-no-sanity-cert
20158 Disable verification of our own server certificates.
20159
20160 When libvirtd starts it performs some sanity checks against its own
20161 certificates.
20162
20163 Defaults to @samp{#f}.
20164
20165 @end deftypevr
20166
20167 @deftypevr {@code{libvirt-configuration} parameter} boolean tls-no-verify-cert
20168 Disable verification of client certificates.
20169
20170 Client certificate verification is the primary authentication mechanism.
20171 Any client which does not present a certificate signed by the CA will be
20172 rejected.
20173
20174 Defaults to @samp{#f}.
20175
20176 @end deftypevr
20177
20178 @deftypevr {@code{libvirt-configuration} parameter} optional-list tls-allowed-dn-list
20179 Whitelist of allowed x509 Distinguished Name.
20180
20181 Defaults to @samp{()}.
20182
20183 @end deftypevr
20184
20185 @deftypevr {@code{libvirt-configuration} parameter} optional-list sasl-allowed-usernames
20186 Whitelist of allowed SASL usernames. The format for username depends on
20187 the SASL authentication mechanism.
20188
20189 Defaults to @samp{()}.
20190
20191 @end deftypevr
20192
20193 @deftypevr {@code{libvirt-configuration} parameter} string tls-priority
20194 Override the compile time default TLS priority string. The default is
20195 usually "NORMAL" unless overridden at build time. Only set this is it
20196 is desired for libvirt to deviate from the global default settings.
20197
20198 Defaults to @samp{"NORMAL"}.
20199
20200 @end deftypevr
20201
20202 @deftypevr {@code{libvirt-configuration} parameter} integer max-clients
20203 Maximum number of concurrent client connections to allow over all
20204 sockets combined.
20205
20206 Defaults to @samp{5000}.
20207
20208 @end deftypevr
20209
20210 @deftypevr {@code{libvirt-configuration} parameter} integer max-queued-clients
20211 Maximum length of queue of connections waiting to be accepted by the
20212 daemon. Note, that some protocols supporting retransmission may obey
20213 this so that a later reattempt at connection succeeds.
20214
20215 Defaults to @samp{1000}.
20216
20217 @end deftypevr
20218
20219 @deftypevr {@code{libvirt-configuration} parameter} integer max-anonymous-clients
20220 Maximum length of queue of accepted but not yet authenticated clients.
20221 Set this to zero to turn this feature off
20222
20223 Defaults to @samp{20}.
20224
20225 @end deftypevr
20226
20227 @deftypevr {@code{libvirt-configuration} parameter} integer min-workers
20228 Number of workers to start up initially.
20229
20230 Defaults to @samp{5}.
20231
20232 @end deftypevr
20233
20234 @deftypevr {@code{libvirt-configuration} parameter} integer max-workers
20235 Maximum number of worker threads.
20236
20237 If the number of active clients exceeds @code{min-workers}, then more
20238 threads are spawned, up to max_workers limit. Typically you'd want
20239 max_workers to equal maximum number of clients allowed.
20240
20241 Defaults to @samp{20}.
20242
20243 @end deftypevr
20244
20245 @deftypevr {@code{libvirt-configuration} parameter} integer prio-workers
20246 Number of priority workers. If all workers from above pool are stuck,
20247 some calls marked as high priority (notably domainDestroy) can be
20248 executed in this pool.
20249
20250 Defaults to @samp{5}.
20251
20252 @end deftypevr
20253
20254 @deftypevr {@code{libvirt-configuration} parameter} integer max-requests
20255 Total global limit on concurrent RPC calls.
20256
20257 Defaults to @samp{20}.
20258
20259 @end deftypevr
20260
20261 @deftypevr {@code{libvirt-configuration} parameter} integer max-client-requests
20262 Limit on concurrent requests from a single client connection. To avoid
20263 one client monopolizing the server this should be a small fraction of
20264 the global max_requests and max_workers parameter.
20265
20266 Defaults to @samp{5}.
20267
20268 @end deftypevr
20269
20270 @deftypevr {@code{libvirt-configuration} parameter} integer admin-min-workers
20271 Same as @code{min-workers} but for the admin interface.
20272
20273 Defaults to @samp{1}.
20274
20275 @end deftypevr
20276
20277 @deftypevr {@code{libvirt-configuration} parameter} integer admin-max-workers
20278 Same as @code{max-workers} but for the admin interface.
20279
20280 Defaults to @samp{5}.
20281
20282 @end deftypevr
20283
20284 @deftypevr {@code{libvirt-configuration} parameter} integer admin-max-clients
20285 Same as @code{max-clients} but for the admin interface.
20286
20287 Defaults to @samp{5}.
20288
20289 @end deftypevr
20290
20291 @deftypevr {@code{libvirt-configuration} parameter} integer admin-max-queued-clients
20292 Same as @code{max-queued-clients} but for the admin interface.
20293
20294 Defaults to @samp{5}.
20295
20296 @end deftypevr
20297
20298 @deftypevr {@code{libvirt-configuration} parameter} integer admin-max-client-requests
20299 Same as @code{max-client-requests} but for the admin interface.
20300
20301 Defaults to @samp{5}.
20302
20303 @end deftypevr
20304
20305 @deftypevr {@code{libvirt-configuration} parameter} integer log-level
20306 Logging level. 4 errors, 3 warnings, 2 information, 1 debug.
20307
20308 Defaults to @samp{3}.
20309
20310 @end deftypevr
20311
20312 @deftypevr {@code{libvirt-configuration} parameter} string log-filters
20313 Logging filters.
20314
20315 A filter allows to select a different logging level for a given category
20316 of logs The format for a filter is one of:
20317
20318 @itemize @bullet
20319 @item
20320 x:name
20321
20322 @item
20323 x:+name
20324
20325 @end itemize
20326
20327 where @code{name} is a string which is matched against the category
20328 given in the @code{VIR_LOG_INIT()} at the top of each libvirt source
20329 file, e.g., "remote", "qemu", or "util.json" (the name in the filter can
20330 be a substring of the full category name, in order to match multiple
20331 similar categories), the optional "+" prefix tells libvirt to log stack
20332 trace for each message matching name, and @code{x} is the minimal level
20333 where matching messages should be logged:
20334
20335 @itemize @bullet
20336 @item
20337 1: DEBUG
20338
20339 @item
20340 2: INFO
20341
20342 @item
20343 3: WARNING
20344
20345 @item
20346 4: ERROR
20347
20348 @end itemize
20349
20350 Multiple filters can be defined in a single filters statement, they just
20351 need to be separated by spaces.
20352
20353 Defaults to @samp{"3:remote 4:event"}.
20354
20355 @end deftypevr
20356
20357 @deftypevr {@code{libvirt-configuration} parameter} string log-outputs
20358 Logging outputs.
20359
20360 An output is one of the places to save logging information The format
20361 for an output can be:
20362
20363 @table @code
20364 @item x:stderr
20365 output goes to stderr
20366
20367 @item x:syslog:name
20368 use syslog for the output and use the given name as the ident
20369
20370 @item x:file:file_path
20371 output to a file, with the given filepath
20372
20373 @item x:journald
20374 output to journald logging system
20375
20376 @end table
20377
20378 In all case the x prefix is the minimal level, acting as a filter
20379
20380 @itemize @bullet
20381 @item
20382 1: DEBUG
20383
20384 @item
20385 2: INFO
20386
20387 @item
20388 3: WARNING
20389
20390 @item
20391 4: ERROR
20392
20393 @end itemize
20394
20395 Multiple outputs can be defined, they just need to be separated by
20396 spaces.
20397
20398 Defaults to @samp{"3:stderr"}.
20399
20400 @end deftypevr
20401
20402 @deftypevr {@code{libvirt-configuration} parameter} integer audit-level
20403 Allows usage of the auditing subsystem to be altered
20404
20405 @itemize @bullet
20406 @item
20407 0: disable all auditing
20408
20409 @item
20410 1: enable auditing, only if enabled on host
20411
20412 @item
20413 2: enable auditing, and exit if disabled on host.
20414
20415 @end itemize
20416
20417 Defaults to @samp{1}.
20418
20419 @end deftypevr
20420
20421 @deftypevr {@code{libvirt-configuration} parameter} boolean audit-logging
20422 Send audit messages via libvirt logging infrastructure.
20423
20424 Defaults to @samp{#f}.
20425
20426 @end deftypevr
20427
20428 @deftypevr {@code{libvirt-configuration} parameter} optional-string host-uuid
20429 Host UUID. UUID must not have all digits be the same.
20430
20431 Defaults to @samp{""}.
20432
20433 @end deftypevr
20434
20435 @deftypevr {@code{libvirt-configuration} parameter} string host-uuid-source
20436 Source to read host UUID.
20437
20438 @itemize @bullet
20439 @item
20440 @code{smbios}: fetch the UUID from @code{dmidecode -s system-uuid}
20441
20442 @item
20443 @code{machine-id}: fetch the UUID from @code{/etc/machine-id}
20444
20445 @end itemize
20446
20447 If @code{dmidecode} does not provide a valid UUID a temporary UUID will
20448 be generated.
20449
20450 Defaults to @samp{"smbios"}.
20451
20452 @end deftypevr
20453
20454 @deftypevr {@code{libvirt-configuration} parameter} integer keepalive-interval
20455 A keepalive message is sent to a client after @code{keepalive_interval}
20456 seconds of inactivity to check if the client is still responding. If
20457 set to -1, libvirtd will never send keepalive requests; however clients
20458 can still send them and the daemon will send responses.
20459
20460 Defaults to @samp{5}.
20461
20462 @end deftypevr
20463
20464 @deftypevr {@code{libvirt-configuration} parameter} integer keepalive-count
20465 Maximum number of keepalive messages that are allowed to be sent to the
20466 client without getting any response before the connection is considered
20467 broken.
20468
20469 In other words, the connection is automatically closed approximately
20470 after @code{keepalive_interval * (keepalive_count + 1)} seconds since
20471 the last message received from the client. When @code{keepalive-count}
20472 is set to 0, connections will be automatically closed after
20473 @code{keepalive-interval} seconds of inactivity without sending any
20474 keepalive messages.
20475
20476 Defaults to @samp{5}.
20477
20478 @end deftypevr
20479
20480 @deftypevr {@code{libvirt-configuration} parameter} integer admin-keepalive-interval
20481 Same as above but for admin interface.
20482
20483 Defaults to @samp{5}.
20484
20485 @end deftypevr
20486
20487 @deftypevr {@code{libvirt-configuration} parameter} integer admin-keepalive-count
20488 Same as above but for admin interface.
20489
20490 Defaults to @samp{5}.
20491
20492 @end deftypevr
20493
20494 @deftypevr {@code{libvirt-configuration} parameter} integer ovs-timeout
20495 Timeout for Open vSwitch calls.
20496
20497 The @code{ovs-vsctl} utility is used for the configuration and its
20498 timeout option is set by default to 5 seconds to avoid potential
20499 infinite waits blocking libvirt.
20500
20501 Defaults to @samp{5}.
20502
20503 @end deftypevr
20504
20505 @c %end of autogenerated docs
20506
20507 @subsubheading Virtlog daemon
20508 The virtlogd service is a server side daemon component of libvirt that is
20509 used to manage logs from virtual machine consoles.
20510
20511 This daemon is not used directly by libvirt client applications, rather it
20512 is called on their behalf by @code{libvirtd}. By maintaining the logs in a
20513 standalone daemon, the main @code{libvirtd} daemon can be restarted without
20514 risk of losing logs. The @code{virtlogd} daemon has the ability to re-exec()
20515 itself upon receiving @code{SIGUSR1}, to allow live upgrades without downtime.
20516
20517 @deffn {Scheme Variable} virtlog-service-type
20518 This is the type of the virtlog daemon.
20519 Its value must be a @code{virtlog-configuration}.
20520
20521 @example
20522 (service virtlog-service-type
20523 (virtlog-configuration
20524 (max-clients 1000)))
20525 @end example
20526 @end deffn
20527
20528 @deftypevr {@code{virtlog-configuration} parameter} integer log-level
20529 Logging level. 4 errors, 3 warnings, 2 information, 1 debug.
20530
20531 Defaults to @samp{3}.
20532
20533 @end deftypevr
20534
20535 @deftypevr {@code{virtlog-configuration} parameter} string log-filters
20536 Logging filters.
20537
20538 A filter allows to select a different logging level for a given category
20539 of logs The format for a filter is one of:
20540
20541 @itemize @bullet
20542 @item
20543 x:name
20544
20545 @item
20546 x:+name
20547
20548 @end itemize
20549
20550 where @code{name} is a string which is matched against the category
20551 given in the @code{VIR_LOG_INIT()} at the top of each libvirt source
20552 file, e.g., "remote", "qemu", or "util.json" (the name in the filter can
20553 be a substring of the full category name, in order to match multiple
20554 similar categories), the optional "+" prefix tells libvirt to log stack
20555 trace for each message matching name, and @code{x} is the minimal level
20556 where matching messages should be logged:
20557
20558 @itemize @bullet
20559 @item
20560 1: DEBUG
20561
20562 @item
20563 2: INFO
20564
20565 @item
20566 3: WARNING
20567
20568 @item
20569 4: ERROR
20570
20571 @end itemize
20572
20573 Multiple filters can be defined in a single filters statement, they just
20574 need to be separated by spaces.
20575
20576 Defaults to @samp{"3:remote 4:event"}.
20577
20578 @end deftypevr
20579
20580 @deftypevr {@code{virtlog-configuration} parameter} string log-outputs
20581 Logging outputs.
20582
20583 An output is one of the places to save logging information The format
20584 for an output can be:
20585
20586 @table @code
20587 @item x:stderr
20588 output goes to stderr
20589
20590 @item x:syslog:name
20591 use syslog for the output and use the given name as the ident
20592
20593 @item x:file:file_path
20594 output to a file, with the given filepath
20595
20596 @item x:journald
20597 output to journald logging system
20598
20599 @end table
20600
20601 In all case the x prefix is the minimal level, acting as a filter
20602
20603 @itemize @bullet
20604 @item
20605 1: DEBUG
20606
20607 @item
20608 2: INFO
20609
20610 @item
20611 3: WARNING
20612
20613 @item
20614 4: ERROR
20615
20616 @end itemize
20617
20618 Multiple outputs can be defined, they just need to be separated by
20619 spaces.
20620
20621 Defaults to @samp{"3:stderr"}.
20622
20623 @end deftypevr
20624
20625 @deftypevr {@code{virtlog-configuration} parameter} integer max-clients
20626 Maximum number of concurrent client connections to allow over all
20627 sockets combined.
20628
20629 Defaults to @samp{1024}.
20630
20631 @end deftypevr
20632
20633 @deftypevr {@code{virtlog-configuration} parameter} integer max-size
20634 Maximum file size before rolling over.
20635
20636 Defaults to @samp{2MB}
20637
20638 @end deftypevr
20639
20640 @deftypevr {@code{virtlog-configuration} parameter} integer max-backups
20641 Maximum number of backup files to keep.
20642
20643 Defaults to @samp{3}
20644
20645 @end deftypevr
20646
20647 @subsubheading Transparent Emulation with QEMU
20648
20649 @cindex emulation
20650 @cindex @code{binfmt_misc}
20651 @code{qemu-binfmt-service-type} provides support for transparent
20652 emulation of program binaries built for different architectures---e.g.,
20653 it allows you to transparently execute an ARMv7 program on an x86_64
20654 machine. It achieves this by combining the @uref{https://www.qemu.org,
20655 QEMU} emulator and the @code{binfmt_misc} feature of the kernel Linux.
20656
20657 @defvr {Scheme Variable} qemu-binfmt-service-type
20658 This is the type of the QEMU/binfmt service for transparent emulation.
20659 Its value must be a @code{qemu-binfmt-configuration} object, which
20660 specifies the QEMU package to use as well as the architecture we want to
20661 emulated:
20662
20663 @example
20664 (service qemu-binfmt-service-type
20665 (qemu-binfmt-configuration
20666 (platforms (lookup-qemu-platforms "arm" "aarch64" "ppc"))))
20667 @end example
20668
20669 In this example, we enable transparent emulation for the ARM and aarch64
20670 platforms. Running @code{herd stop qemu-binfmt} turns it off, and
20671 running @code{herd start qemu-binfmt} turns it back on (@pxref{Invoking
20672 herd, the @command{herd} command,, shepherd, The GNU Shepherd Manual}).
20673 @end defvr
20674
20675 @deftp {Data Type} qemu-binfmt-configuration
20676 This is the configuration for the @code{qemu-binfmt} service.
20677
20678 @table @asis
20679 @item @code{platforms} (default: @code{'()})
20680 The list of emulated QEMU platforms. Each item must be a @dfn{platform
20681 object} as returned by @code{lookup-qemu-platforms} (see below).
20682
20683 @item @code{guix-support?} (default: @code{#f})
20684 When it is true, QEMU and all its dependencies are added to the build
20685 environment of @command{guix-daemon} (@pxref{Invoking guix-daemon,
20686 @code{--chroot-directory} option}). This allows the @code{binfmt_misc}
20687 handlers to be used within the build environment, which in turn means
20688 that you can transparently build programs for another architecture.
20689
20690 For example, let's suppose you're on an x86_64 machine and you have this
20691 service:
20692
20693 @example
20694 (service qemu-binfmt-service-type
20695 (qemu-binfmt-configuration
20696 (platforms (lookup-qemu-platforms "arm"))
20697 (guix-support? #t)))
20698 @end example
20699
20700 You can run:
20701
20702 @example
20703 guix build -s armhf-linux inkscape
20704 @end example
20705
20706 @noindent
20707 and it will build Inkscape for ARMv7 @emph{as if it were a native
20708 build}, transparently using QEMU to emulate the ARMv7 CPU. Pretty handy
20709 if you'd like to test a package build for an architecture you don't have
20710 access to!
20711
20712 @item @code{qemu} (default: @code{qemu})
20713 The QEMU package to use.
20714 @end table
20715 @end deftp
20716
20717 @deffn {Scheme Procedure} lookup-qemu-platforms @var{platforms}@dots{}
20718 Return the list of QEMU platform objects corresponding to
20719 @var{platforms}@dots{}. @var{platforms} must be a list of strings
20720 corresponding to platform names, such as @code{"arm"}, @code{"sparc"},
20721 @code{"mips64el"}, and so on.
20722 @end deffn
20723
20724 @deffn {Scheme Procedure} qemu-platform? @var{obj}
20725 Return true if @var{obj} is a platform object.
20726 @end deffn
20727
20728 @deffn {Scheme Procedure} qemu-platform-name @var{platform}
20729 Return the name of @var{platform}---a string such as @code{"arm"}.
20730 @end deffn
20731
20732 @node Version Control Services
20733 @subsubsection Version Control Services
20734
20735 The @code{(gnu services version-control)} module provides a service to
20736 allow remote access to local Git repositories. There are three options:
20737 the @code{git-daemon-service}, which provides access to repositories via
20738 the @code{git://} unsecured TCP-based protocol, extending the
20739 @code{nginx} web server to proxy some requests to
20740 @code{git-http-backend}, or providing a web interface with
20741 @code{cgit-service-type}.
20742
20743 @deffn {Scheme Procedure} git-daemon-service [#:config (git-daemon-configuration)]
20744
20745 Return a service that runs @command{git daemon}, a simple TCP server to
20746 expose repositories over the Git protocol for anonymous access.
20747
20748 The optional @var{config} argument should be a
20749 @code{<git-daemon-configuration>} object, by default it allows read-only
20750 access to exported@footnote{By creating the magic file
20751 "git-daemon-export-ok" in the repository directory.} repositories under
20752 @file{/srv/git}.
20753
20754 @end deffn
20755
20756 @deftp {Data Type} git-daemon-configuration
20757 Data type representing the configuration for @code{git-daemon-service}.
20758
20759 @table @asis
20760 @item @code{package} (default: @var{git})
20761 Package object of the Git distributed version control system.
20762
20763 @item @code{export-all?} (default: @var{#f})
20764 Whether to allow access for all Git repositories, even if they do not
20765 have the @file{git-daemon-export-ok} file.
20766
20767 @item @code{base-path} (default: @file{/srv/git})
20768 Whether to remap all the path requests as relative to the given path.
20769 If you run git daemon with @var{(base-path "/srv/git")} on example.com,
20770 then if you later try to pull @code{git://example.com/hello.git}, git
20771 daemon will interpret the path as @code{/srv/git/hello.git}.
20772
20773 @item @code{user-path} (default: @var{#f})
20774 Whether to allow @code{~user} notation to be used in requests. When
20775 specified with empty string, requests to @code{git://host/~alice/foo} is
20776 taken as a request to access @code{foo} repository in the home directory
20777 of user @code{alice}. If @var{(user-path "path")} is specified, the
20778 same request is taken as a request to access @code{path/foo} repository
20779 in the home directory of user @code{alice}.
20780
20781 @item @code{listen} (default: @var{'()})
20782 Whether to listen on specific IP addresses or hostnames, defaults to
20783 all.
20784
20785 @item @code{port} (default: @var{#f})
20786 Whether to listen on an alternative port, which defaults to 9418.
20787
20788 @item @code{whitelist} (default: @var{'()})
20789 If not empty, only allow access to this list of directories.
20790
20791 @item @code{extra-options} (default: @var{'()})
20792 Extra options will be passed to @code{git daemon}, please run
20793 @command{man git-daemon} for more information.
20794
20795 @end table
20796 @end deftp
20797
20798 The @code{git://} protocol lacks authentication. When you pull from a
20799 repository fetched via @code{git://}, you don't know that the data you
20800 receive was modified is really coming from the specified host, and you
20801 have your connection is subject to eavesdropping. It's better to use an
20802 authenticated and encrypted transport, such as @code{https}. Although Git allows you
20803 to serve repositories using unsophisticated file-based web servers,
20804 there is a faster protocol implemented by the @code{git-http-backend}
20805 program. This program is the back-end of a proper Git web service. It
20806 is designed to sit behind a FastCGI proxy. @xref{Web Services}, for more
20807 on running the necessary @code{fcgiwrap} daemon.
20808
20809 Guix has a separate configuration data type for serving Git repositories
20810 over HTTP.
20811
20812 @deftp {Data Type} git-http-configuration
20813 Data type representing the configuration for @code{git-http-service}.
20814
20815 @table @asis
20816 @item @code{package} (default: @var{git})
20817 Package object of the Git distributed version control system.
20818
20819 @item @code{git-root} (default: @file{/srv/git})
20820 Directory containing the Git repositories to expose to the world.
20821
20822 @item @code{export-all?} (default: @var{#f})
20823 Whether to expose access for all Git repositories in @var{git-root},
20824 even if they do not have the @file{git-daemon-export-ok} file.
20825
20826 @item @code{uri-path} (default: @file{/git/})
20827 Path prefix for Git access. With the default @code{/git/} prefix, this
20828 will map @code{http://@var{server}/git/@var{repo}.git} to
20829 @code{/srv/git/@var{repo}.git}. Requests whose URI paths do not begin
20830 with this prefix are not passed on to this Git instance.
20831
20832 @item @code{fcgiwrap-socket} (default: @code{127.0.0.1:9000})
20833 The socket on which the @code{fcgiwrap} daemon is listening. @xref{Web
20834 Services}.
20835 @end table
20836 @end deftp
20837
20838 There is no @code{git-http-service-type}, currently; instead you can
20839 create an @code{nginx-location-configuration} from a
20840 @code{git-http-configuration} and then add that location to a web
20841 server.
20842
20843 @deffn {Scheme Procedure} git-http-nginx-location-configuration @
20844 [config=(git-http-configuration)]
20845 Compute an @code{nginx-location-configuration} that corresponds to the
20846 given Git http configuration. An example nginx service definition to
20847 serve the default @file{/srv/git} over HTTPS might be:
20848
20849 @example
20850 (service nginx-service-type
20851 (nginx-configuration
20852 (server-blocks
20853 (list
20854 (nginx-server-configuration
20855 (listen '("443 ssl"))
20856 (server-name "git.my-host.org")
20857 (ssl-certificate
20858 "/etc/letsencrypt/live/git.my-host.org/fullchain.pem")
20859 (ssl-certificate-key
20860 "/etc/letsencrypt/live/git.my-host.org/privkey.pem")
20861 (locations
20862 (list
20863 (git-http-nginx-location-configuration
20864 (git-http-configuration (uri-path "/"))))))))))
20865 @end example
20866
20867 This example assumes that you are using Let's Encrypt to get your TLS
20868 certificate. @xref{Certificate Services}. The default @code{certbot}
20869 service will redirect all HTTP traffic on @code{git.my-host.org} to
20870 HTTPS. You will also need to add an @code{fcgiwrap} proxy to your
20871 system services. @xref{Web Services}.
20872 @end deffn
20873
20874 @subsubheading Cgit Service
20875
20876 @cindex Cgit service
20877 @cindex Git, web interface
20878 @uref{https://git.zx2c4.com/cgit/, Cgit} is a web frontend for Git
20879 repositories written in C.
20880
20881 The following example will configure the service with default values.
20882 By default, Cgit can be accessed on port 80 (@code{http://localhost:80}).
20883
20884 @example
20885 (service cgit-service-type)
20886 @end example
20887
20888 The @code{file-object} type designates either a file-like object
20889 (@pxref{G-Expressions, file-like objects}) or a string.
20890
20891 @c %start of fragment
20892
20893 Available @code{cgit-configuration} fields are:
20894
20895 @deftypevr {@code{cgit-configuration} parameter} package package
20896 The CGIT package.
20897
20898 @end deftypevr
20899
20900 @deftypevr {@code{cgit-configuration} parameter} nginx-server-configuration-list nginx
20901 NGINX configuration.
20902
20903 @end deftypevr
20904
20905 @deftypevr {@code{cgit-configuration} parameter} file-object about-filter
20906 Specifies a command which will be invoked to format the content of about
20907 pages (both top-level and for each repository).
20908
20909 Defaults to @samp{""}.
20910
20911 @end deftypevr
20912
20913 @deftypevr {@code{cgit-configuration} parameter} string agefile
20914 Specifies a path, relative to each repository path, which can be used to
20915 specify the date and time of the youngest commit in the repository.
20916
20917 Defaults to @samp{""}.
20918
20919 @end deftypevr
20920
20921 @deftypevr {@code{cgit-configuration} parameter} file-object auth-filter
20922 Specifies a command that will be invoked for authenticating repository
20923 access.
20924
20925 Defaults to @samp{""}.
20926
20927 @end deftypevr
20928
20929 @deftypevr {@code{cgit-configuration} parameter} string branch-sort
20930 Flag which, when set to @samp{age}, enables date ordering in the branch
20931 ref list, and when set @samp{name} enables ordering by branch name.
20932
20933 Defaults to @samp{"name"}.
20934
20935 @end deftypevr
20936
20937 @deftypevr {@code{cgit-configuration} parameter} string cache-root
20938 Path used to store the cgit cache entries.
20939
20940 Defaults to @samp{"/var/cache/cgit"}.
20941
20942 @end deftypevr
20943
20944 @deftypevr {@code{cgit-configuration} parameter} integer cache-static-ttl
20945 Number which specifies the time-to-live, in minutes, for the cached
20946 version of repository pages accessed with a fixed SHA1.
20947
20948 Defaults to @samp{-1}.
20949
20950 @end deftypevr
20951
20952 @deftypevr {@code{cgit-configuration} parameter} integer cache-dynamic-ttl
20953 Number which specifies the time-to-live, in minutes, for the cached
20954 version of repository pages accessed without a fixed SHA1.
20955
20956 Defaults to @samp{5}.
20957
20958 @end deftypevr
20959
20960 @deftypevr {@code{cgit-configuration} parameter} integer cache-repo-ttl
20961 Number which specifies the time-to-live, in minutes, for the cached
20962 version of the repository summary page.
20963
20964 Defaults to @samp{5}.
20965
20966 @end deftypevr
20967
20968 @deftypevr {@code{cgit-configuration} parameter} integer cache-root-ttl
20969 Number which specifies the time-to-live, in minutes, for the cached
20970 version of the repository index page.
20971
20972 Defaults to @samp{5}.
20973
20974 @end deftypevr
20975
20976 @deftypevr {@code{cgit-configuration} parameter} integer cache-scanrc-ttl
20977 Number which specifies the time-to-live, in minutes, for the result of
20978 scanning a path for Git repositories.
20979
20980 Defaults to @samp{15}.
20981
20982 @end deftypevr
20983
20984 @deftypevr {@code{cgit-configuration} parameter} integer cache-about-ttl
20985 Number which specifies the time-to-live, in minutes, for the cached
20986 version of the repository about page.
20987
20988 Defaults to @samp{15}.
20989
20990 @end deftypevr
20991
20992 @deftypevr {@code{cgit-configuration} parameter} integer cache-snapshot-ttl
20993 Number which specifies the time-to-live, in minutes, for the cached
20994 version of snapshots.
20995
20996 Defaults to @samp{5}.
20997
20998 @end deftypevr
20999
21000 @deftypevr {@code{cgit-configuration} parameter} integer cache-size
21001 The maximum number of entries in the cgit cache. When set to @samp{0},
21002 caching is disabled.
21003
21004 Defaults to @samp{0}.
21005
21006 @end deftypevr
21007
21008 @deftypevr {@code{cgit-configuration} parameter} boolean case-sensitive-sort?
21009 Sort items in the repo list case sensitively.
21010
21011 Defaults to @samp{#t}.
21012
21013 @end deftypevr
21014
21015 @deftypevr {@code{cgit-configuration} parameter} list clone-prefix
21016 List of common prefixes which, when combined with a repository URL,
21017 generates valid clone URLs for the repository.
21018
21019 Defaults to @samp{()}.
21020
21021 @end deftypevr
21022
21023 @deftypevr {@code{cgit-configuration} parameter} list clone-url
21024 List of @code{clone-url} templates.
21025
21026 Defaults to @samp{()}.
21027
21028 @end deftypevr
21029
21030 @deftypevr {@code{cgit-configuration} parameter} file-object commit-filter
21031 Command which will be invoked to format commit messages.
21032
21033 Defaults to @samp{""}.
21034
21035 @end deftypevr
21036
21037 @deftypevr {@code{cgit-configuration} parameter} string commit-sort
21038 Flag which, when set to @samp{date}, enables strict date ordering in the
21039 commit log, and when set to @samp{topo} enables strict topological
21040 ordering.
21041
21042 Defaults to @samp{"git log"}.
21043
21044 @end deftypevr
21045
21046 @deftypevr {@code{cgit-configuration} parameter} file-object css
21047 URL which specifies the css document to include in all cgit pages.
21048
21049 Defaults to @samp{"/share/cgit/cgit.css"}.
21050
21051 @end deftypevr
21052
21053 @deftypevr {@code{cgit-configuration} parameter} file-object email-filter
21054 Specifies a command which will be invoked to format names and email
21055 address of committers, authors, and taggers, as represented in various
21056 places throughout the cgit interface.
21057
21058 Defaults to @samp{""}.
21059
21060 @end deftypevr
21061
21062 @deftypevr {@code{cgit-configuration} parameter} boolean embedded?
21063 Flag which, when set to @samp{#t}, will make cgit generate a HTML
21064 fragment suitable for embedding in other HTML pages.
21065
21066 Defaults to @samp{#f}.
21067
21068 @end deftypevr
21069
21070 @deftypevr {@code{cgit-configuration} parameter} boolean enable-commit-graph?
21071 Flag which, when set to @samp{#t}, will make cgit print an ASCII-art
21072 commit history graph to the left of the commit messages in the
21073 repository log page.
21074
21075 Defaults to @samp{#f}.
21076
21077 @end deftypevr
21078
21079 @deftypevr {@code{cgit-configuration} parameter} boolean enable-filter-overrides?
21080 Flag which, when set to @samp{#t}, allows all filter settings to be
21081 overridden in repository-specific cgitrc files.
21082
21083 Defaults to @samp{#f}.
21084
21085 @end deftypevr
21086
21087 @deftypevr {@code{cgit-configuration} parameter} boolean enable-follow-links?
21088 Flag which, when set to @samp{#t}, allows users to follow a file in the
21089 log view.
21090
21091 Defaults to @samp{#f}.
21092
21093 @end deftypevr
21094
21095 @deftypevr {@code{cgit-configuration} parameter} boolean enable-http-clone?
21096 If set to @samp{#t}, cgit will act as an dumb HTTP endpoint for Git
21097 clones.
21098
21099 Defaults to @samp{#t}.
21100
21101 @end deftypevr
21102
21103 @deftypevr {@code{cgit-configuration} parameter} boolean enable-index-links?
21104 Flag which, when set to @samp{#t}, will make cgit generate extra links
21105 "summary", "commit", "tree" for each repo in the repository index.
21106
21107 Defaults to @samp{#f}.
21108
21109 @end deftypevr
21110
21111 @deftypevr {@code{cgit-configuration} parameter} boolean enable-index-owner?
21112 Flag which, when set to @samp{#t}, will make cgit display the owner of
21113 each repo in the repository index.
21114
21115 Defaults to @samp{#t}.
21116
21117 @end deftypevr
21118
21119 @deftypevr {@code{cgit-configuration} parameter} boolean enable-log-filecount?
21120 Flag which, when set to @samp{#t}, will make cgit print the number of
21121 modified files for each commit on the repository log page.
21122
21123 Defaults to @samp{#f}.
21124
21125 @end deftypevr
21126
21127 @deftypevr {@code{cgit-configuration} parameter} boolean enable-log-linecount?
21128 Flag which, when set to @samp{#t}, will make cgit print the number of
21129 added and removed lines for each commit on the repository log page.
21130
21131 Defaults to @samp{#f}.
21132
21133 @end deftypevr
21134
21135 @deftypevr {@code{cgit-configuration} parameter} boolean enable-remote-branches?
21136 Flag which, when set to @code{#t}, will make cgit display remote
21137 branches in the summary and refs views.
21138
21139 Defaults to @samp{#f}.
21140
21141 @end deftypevr
21142
21143 @deftypevr {@code{cgit-configuration} parameter} boolean enable-subject-links?
21144 Flag which, when set to @code{1}, will make cgit use the subject of the
21145 parent commit as link text when generating links to parent commits in
21146 commit view.
21147
21148 Defaults to @samp{#f}.
21149
21150 @end deftypevr
21151
21152 @deftypevr {@code{cgit-configuration} parameter} boolean enable-html-serving?
21153 Flag which, when set to @samp{#t}, will make cgit use the subject of the
21154 parent commit as link text when generating links to parent commits in
21155 commit view.
21156
21157 Defaults to @samp{#f}.
21158
21159 @end deftypevr
21160
21161 @deftypevr {@code{cgit-configuration} parameter} boolean enable-tree-linenumbers?
21162 Flag which, when set to @samp{#t}, will make cgit generate linenumber
21163 links for plaintext blobs printed in the tree view.
21164
21165 Defaults to @samp{#t}.
21166
21167 @end deftypevr
21168
21169 @deftypevr {@code{cgit-configuration} parameter} boolean enable-git-config?
21170 Flag which, when set to @samp{#f}, will allow cgit to use Git config to
21171 set any repo specific settings.
21172
21173 Defaults to @samp{#f}.
21174
21175 @end deftypevr
21176
21177 @deftypevr {@code{cgit-configuration} parameter} file-object favicon
21178 URL used as link to a shortcut icon for cgit.
21179
21180 Defaults to @samp{"/favicon.ico"}.
21181
21182 @end deftypevr
21183
21184 @deftypevr {@code{cgit-configuration} parameter} string footer
21185 The content of the file specified with this option will be included
21186 verbatim at the bottom of all pages (i.e.@: it replaces the standard
21187 "generated by..."@: message).
21188
21189 Defaults to @samp{""}.
21190
21191 @end deftypevr
21192
21193 @deftypevr {@code{cgit-configuration} parameter} string head-include
21194 The content of the file specified with this option will be included
21195 verbatim in the HTML HEAD section on all pages.
21196
21197 Defaults to @samp{""}.
21198
21199 @end deftypevr
21200
21201 @deftypevr {@code{cgit-configuration} parameter} string header
21202 The content of the file specified with this option will be included
21203 verbatim at the top of all pages.
21204
21205 Defaults to @samp{""}.
21206
21207 @end deftypevr
21208
21209 @deftypevr {@code{cgit-configuration} parameter} file-object include
21210 Name of a configfile to include before the rest of the current config-
21211 file is parsed.
21212
21213 Defaults to @samp{""}.
21214
21215 @end deftypevr
21216
21217 @deftypevr {@code{cgit-configuration} parameter} string index-header
21218 The content of the file specified with this option will be included
21219 verbatim above the repository index.
21220
21221 Defaults to @samp{""}.
21222
21223 @end deftypevr
21224
21225 @deftypevr {@code{cgit-configuration} parameter} string index-info
21226 The content of the file specified with this option will be included
21227 verbatim below the heading on the repository index page.
21228
21229 Defaults to @samp{""}.
21230
21231 @end deftypevr
21232
21233 @deftypevr {@code{cgit-configuration} parameter} boolean local-time?
21234 Flag which, if set to @samp{#t}, makes cgit print commit and tag times
21235 in the servers timezone.
21236
21237 Defaults to @samp{#f}.
21238
21239 @end deftypevr
21240
21241 @deftypevr {@code{cgit-configuration} parameter} file-object logo
21242 URL which specifies the source of an image which will be used as a logo
21243 on all cgit pages.
21244
21245 Defaults to @samp{"/share/cgit/cgit.png"}.
21246
21247 @end deftypevr
21248
21249 @deftypevr {@code{cgit-configuration} parameter} string logo-link
21250 URL loaded when clicking on the cgit logo image.
21251
21252 Defaults to @samp{""}.
21253
21254 @end deftypevr
21255
21256 @deftypevr {@code{cgit-configuration} parameter} file-object owner-filter
21257 Command which will be invoked to format the Owner column of the main
21258 page.
21259
21260 Defaults to @samp{""}.
21261
21262 @end deftypevr
21263
21264 @deftypevr {@code{cgit-configuration} parameter} integer max-atom-items
21265 Number of items to display in atom feeds view.
21266
21267 Defaults to @samp{10}.
21268
21269 @end deftypevr
21270
21271 @deftypevr {@code{cgit-configuration} parameter} integer max-commit-count
21272 Number of entries to list per page in "log" view.
21273
21274 Defaults to @samp{50}.
21275
21276 @end deftypevr
21277
21278 @deftypevr {@code{cgit-configuration} parameter} integer max-message-length
21279 Number of commit message characters to display in "log" view.
21280
21281 Defaults to @samp{80}.
21282
21283 @end deftypevr
21284
21285 @deftypevr {@code{cgit-configuration} parameter} integer max-repo-count
21286 Specifies the number of entries to list per page on the repository index
21287 page.
21288
21289 Defaults to @samp{50}.
21290
21291 @end deftypevr
21292
21293 @deftypevr {@code{cgit-configuration} parameter} integer max-repodesc-length
21294 Specifies the maximum number of repo description characters to display
21295 on the repository index page.
21296
21297 Defaults to @samp{80}.
21298
21299 @end deftypevr
21300
21301 @deftypevr {@code{cgit-configuration} parameter} integer max-blob-size
21302 Specifies the maximum size of a blob to display HTML for in KBytes.
21303
21304 Defaults to @samp{0}.
21305
21306 @end deftypevr
21307
21308 @deftypevr {@code{cgit-configuration} parameter} string max-stats
21309 Maximum statistics period. Valid values are @samp{week},@samp{month},
21310 @samp{quarter} and @samp{year}.
21311
21312 Defaults to @samp{""}.
21313
21314 @end deftypevr
21315
21316 @deftypevr {@code{cgit-configuration} parameter} mimetype-alist mimetype
21317 Mimetype for the specified filename extension.
21318
21319 Defaults to @samp{((gif "image/gif") (html "text/html") (jpg
21320 "image/jpeg") (jpeg "image/jpeg") (pdf "application/pdf") (png
21321 "image/png") (svg "image/svg+xml"))}.
21322
21323 @end deftypevr
21324
21325 @deftypevr {@code{cgit-configuration} parameter} file-object mimetype-file
21326 Specifies the file to use for automatic mimetype lookup.
21327
21328 Defaults to @samp{""}.
21329
21330 @end deftypevr
21331
21332 @deftypevr {@code{cgit-configuration} parameter} string module-link
21333 Text which will be used as the formatstring for a hyperlink when a
21334 submodule is printed in a directory listing.
21335
21336 Defaults to @samp{""}.
21337
21338 @end deftypevr
21339
21340 @deftypevr {@code{cgit-configuration} parameter} boolean nocache?
21341 If set to the value @samp{#t} caching will be disabled.
21342
21343 Defaults to @samp{#f}.
21344
21345 @end deftypevr
21346
21347 @deftypevr {@code{cgit-configuration} parameter} boolean noplainemail?
21348 If set to @samp{#t} showing full author email addresses will be
21349 disabled.
21350
21351 Defaults to @samp{#f}.
21352
21353 @end deftypevr
21354
21355 @deftypevr {@code{cgit-configuration} parameter} boolean noheader?
21356 Flag which, when set to @samp{#t}, will make cgit omit the standard
21357 header on all pages.
21358
21359 Defaults to @samp{#f}.
21360
21361 @end deftypevr
21362
21363 @deftypevr {@code{cgit-configuration} parameter} project-list project-list
21364 A list of subdirectories inside of @code{repository-directory}, relative
21365 to it, that should loaded as Git repositories. An empty list means that
21366 all subdirectories will be loaded.
21367
21368 Defaults to @samp{()}.
21369
21370 @end deftypevr
21371
21372 @deftypevr {@code{cgit-configuration} parameter} file-object readme
21373 Text which will be used as default value for @code{cgit-repo-readme}.
21374
21375 Defaults to @samp{""}.
21376
21377 @end deftypevr
21378
21379 @deftypevr {@code{cgit-configuration} parameter} boolean remove-suffix?
21380 If set to @code{#t} and @code{repository-directory} is enabled, if any
21381 repositories are found with a suffix of @code{.git}, this suffix will be
21382 removed for the URL and name.
21383
21384 Defaults to @samp{#f}.
21385
21386 @end deftypevr
21387
21388 @deftypevr {@code{cgit-configuration} parameter} integer renamelimit
21389 Maximum number of files to consider when detecting renames.
21390
21391 Defaults to @samp{-1}.
21392
21393 @end deftypevr
21394
21395 @deftypevr {@code{cgit-configuration} parameter} string repository-sort
21396 The way in which repositories in each section are sorted.
21397
21398 Defaults to @samp{""}.
21399
21400 @end deftypevr
21401
21402 @deftypevr {@code{cgit-configuration} parameter} robots-list robots
21403 Text used as content for the @code{robots} meta-tag.
21404
21405 Defaults to @samp{("noindex" "nofollow")}.
21406
21407 @end deftypevr
21408
21409 @deftypevr {@code{cgit-configuration} parameter} string root-desc
21410 Text printed below the heading on the repository index page.
21411
21412 Defaults to @samp{"a fast webinterface for the git dscm"}.
21413
21414 @end deftypevr
21415
21416 @deftypevr {@code{cgit-configuration} parameter} string root-readme
21417 The content of the file specified with this option will be included
21418 verbatim below thef "about" link on the repository index page.
21419
21420 Defaults to @samp{""}.
21421
21422 @end deftypevr
21423
21424 @deftypevr {@code{cgit-configuration} parameter} string root-title
21425 Text printed as heading on the repository index page.
21426
21427 Defaults to @samp{""}.
21428
21429 @end deftypevr
21430
21431 @deftypevr {@code{cgit-configuration} parameter} boolean scan-hidden-path
21432 If set to @samp{#t} and repository-directory is enabled,
21433 repository-directory will recurse into directories whose name starts
21434 with a period. Otherwise, repository-directory will stay away from such
21435 directories, considered as "hidden". Note that this does not apply to
21436 the ".git" directory in non-bare repos.
21437
21438 Defaults to @samp{#f}.
21439
21440 @end deftypevr
21441
21442 @deftypevr {@code{cgit-configuration} parameter} list snapshots
21443 Text which specifies the default set of snapshot formats that cgit
21444 generates links for.
21445
21446 Defaults to @samp{()}.
21447
21448 @end deftypevr
21449
21450 @deftypevr {@code{cgit-configuration} parameter} repository-directory repository-directory
21451 Name of the directory to scan for repositories (represents
21452 @code{scan-path}).
21453
21454 Defaults to @samp{"/srv/git"}.
21455
21456 @end deftypevr
21457
21458 @deftypevr {@code{cgit-configuration} parameter} string section
21459 The name of the current repository section - all repositories defined
21460 after this option will inherit the current section name.
21461
21462 Defaults to @samp{""}.
21463
21464 @end deftypevr
21465
21466 @deftypevr {@code{cgit-configuration} parameter} string section-sort
21467 Flag which, when set to @samp{1}, will sort the sections on the
21468 repository listing by name.
21469
21470 Defaults to @samp{""}.
21471
21472 @end deftypevr
21473
21474 @deftypevr {@code{cgit-configuration} parameter} integer section-from-path
21475 A number which, if defined prior to repository-directory, specifies how
21476 many path elements from each repo path to use as a default section name.
21477
21478 Defaults to @samp{0}.
21479
21480 @end deftypevr
21481
21482 @deftypevr {@code{cgit-configuration} parameter} boolean side-by-side-diffs?
21483 If set to @samp{#t} shows side-by-side diffs instead of unidiffs per
21484 default.
21485
21486 Defaults to @samp{#f}.
21487
21488 @end deftypevr
21489
21490 @deftypevr {@code{cgit-configuration} parameter} file-object source-filter
21491 Specifies a command which will be invoked to format plaintext blobs in
21492 the tree view.
21493
21494 Defaults to @samp{""}.
21495
21496 @end deftypevr
21497
21498 @deftypevr {@code{cgit-configuration} parameter} integer summary-branches
21499 Specifies the number of branches to display in the repository "summary"
21500 view.
21501
21502 Defaults to @samp{10}.
21503
21504 @end deftypevr
21505
21506 @deftypevr {@code{cgit-configuration} parameter} integer summary-log
21507 Specifies the number of log entries to display in the repository
21508 "summary" view.
21509
21510 Defaults to @samp{10}.
21511
21512 @end deftypevr
21513
21514 @deftypevr {@code{cgit-configuration} parameter} integer summary-tags
21515 Specifies the number of tags to display in the repository "summary"
21516 view.
21517
21518 Defaults to @samp{10}.
21519
21520 @end deftypevr
21521
21522 @deftypevr {@code{cgit-configuration} parameter} string strict-export
21523 Filename which, if specified, needs to be present within the repository
21524 for cgit to allow access to that repository.
21525
21526 Defaults to @samp{""}.
21527
21528 @end deftypevr
21529
21530 @deftypevr {@code{cgit-configuration} parameter} string virtual-root
21531 URL which, if specified, will be used as root for all cgit links.
21532
21533 Defaults to @samp{"/"}.
21534
21535 @end deftypevr
21536
21537 @deftypevr {@code{cgit-configuration} parameter} repository-cgit-configuration-list repositories
21538 A list of @dfn{cgit-repo} records to use with config.
21539
21540 Defaults to @samp{()}.
21541
21542 Available @code{repository-cgit-configuration} fields are:
21543
21544 @deftypevr {@code{repository-cgit-configuration} parameter} repo-list snapshots
21545 A mask of snapshot formats for this repo that cgit generates links for,
21546 restricted by the global @code{snapshots} setting.
21547
21548 Defaults to @samp{()}.
21549
21550 @end deftypevr
21551
21552 @deftypevr {@code{repository-cgit-configuration} parameter} repo-file-object source-filter
21553 Override the default @code{source-filter}.
21554
21555 Defaults to @samp{""}.
21556
21557 @end deftypevr
21558
21559 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string url
21560 The relative URL used to access the repository.
21561
21562 Defaults to @samp{""}.
21563
21564 @end deftypevr
21565
21566 @deftypevr {@code{repository-cgit-configuration} parameter} repo-file-object about-filter
21567 Override the default @code{about-filter}.
21568
21569 Defaults to @samp{""}.
21570
21571 @end deftypevr
21572
21573 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string branch-sort
21574 Flag which, when set to @samp{age}, enables date ordering in the branch
21575 ref list, and when set to @samp{name} enables ordering by branch name.
21576
21577 Defaults to @samp{""}.
21578
21579 @end deftypevr
21580
21581 @deftypevr {@code{repository-cgit-configuration} parameter} repo-list clone-url
21582 A list of URLs which can be used to clone repo.
21583
21584 Defaults to @samp{()}.
21585
21586 @end deftypevr
21587
21588 @deftypevr {@code{repository-cgit-configuration} parameter} repo-file-object commit-filter
21589 Override the default @code{commit-filter}.
21590
21591 Defaults to @samp{""}.
21592
21593 @end deftypevr
21594
21595 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string commit-sort
21596 Flag which, when set to @samp{date}, enables strict date ordering in the
21597 commit log, and when set to @samp{topo} enables strict topological
21598 ordering.
21599
21600 Defaults to @samp{""}.
21601
21602 @end deftypevr
21603
21604 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string defbranch
21605 The name of the default branch for this repository. If no such branch
21606 exists in the repository, the first branch name (when sorted) is used as
21607 default instead. By default branch pointed to by HEAD, or "master" if
21608 there is no suitable HEAD.
21609
21610 Defaults to @samp{""}.
21611
21612 @end deftypevr
21613
21614 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string desc
21615 The value to show as repository description.
21616
21617 Defaults to @samp{""}.
21618
21619 @end deftypevr
21620
21621 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string homepage
21622 The value to show as repository homepage.
21623
21624 Defaults to @samp{""}.
21625
21626 @end deftypevr
21627
21628 @deftypevr {@code{repository-cgit-configuration} parameter} repo-file-object email-filter
21629 Override the default @code{email-filter}.
21630
21631 Defaults to @samp{""}.
21632
21633 @end deftypevr
21634
21635 @deftypevr {@code{repository-cgit-configuration} parameter} maybe-repo-boolean enable-commit-graph?
21636 A flag which can be used to disable the global setting
21637 @code{enable-commit-graph?}.
21638
21639 Defaults to @samp{disabled}.
21640
21641 @end deftypevr
21642
21643 @deftypevr {@code{repository-cgit-configuration} parameter} maybe-repo-boolean enable-log-filecount?
21644 A flag which can be used to disable the global setting
21645 @code{enable-log-filecount?}.
21646
21647 Defaults to @samp{disabled}.
21648
21649 @end deftypevr
21650
21651 @deftypevr {@code{repository-cgit-configuration} parameter} maybe-repo-boolean enable-log-linecount?
21652 A flag which can be used to disable the global setting
21653 @code{enable-log-linecount?}.
21654
21655 Defaults to @samp{disabled}.
21656
21657 @end deftypevr
21658
21659 @deftypevr {@code{repository-cgit-configuration} parameter} maybe-repo-boolean enable-remote-branches?
21660 Flag which, when set to @code{#t}, will make cgit display remote
21661 branches in the summary and refs views.
21662
21663 Defaults to @samp{disabled}.
21664
21665 @end deftypevr
21666
21667 @deftypevr {@code{repository-cgit-configuration} parameter} maybe-repo-boolean enable-subject-links?
21668 A flag which can be used to override the global setting
21669 @code{enable-subject-links?}.
21670
21671 Defaults to @samp{disabled}.
21672
21673 @end deftypevr
21674
21675 @deftypevr {@code{repository-cgit-configuration} parameter} maybe-repo-boolean enable-html-serving?
21676 A flag which can be used to override the global setting
21677 @code{enable-html-serving?}.
21678
21679 Defaults to @samp{disabled}.
21680
21681 @end deftypevr
21682
21683 @deftypevr {@code{repository-cgit-configuration} parameter} repo-boolean hide?
21684 Flag which, when set to @code{#t}, hides the repository from the
21685 repository index.
21686
21687 Defaults to @samp{#f}.
21688
21689 @end deftypevr
21690
21691 @deftypevr {@code{repository-cgit-configuration} parameter} repo-boolean ignore?
21692 Flag which, when set to @samp{#t}, ignores the repository.
21693
21694 Defaults to @samp{#f}.
21695
21696 @end deftypevr
21697
21698 @deftypevr {@code{repository-cgit-configuration} parameter} repo-file-object logo
21699 URL which specifies the source of an image which will be used as a logo
21700 on this repo’s pages.
21701
21702 Defaults to @samp{""}.
21703
21704 @end deftypevr
21705
21706 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string logo-link
21707 URL loaded when clicking on the cgit logo image.
21708
21709 Defaults to @samp{""}.
21710
21711 @end deftypevr
21712
21713 @deftypevr {@code{repository-cgit-configuration} parameter} repo-file-object owner-filter
21714 Override the default @code{owner-filter}.
21715
21716 Defaults to @samp{""}.
21717
21718 @end deftypevr
21719
21720 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string module-link
21721 Text which will be used as the formatstring for a hyperlink when a
21722 submodule is printed in a directory listing. The arguments for the
21723 formatstring are the path and SHA1 of the submodule commit.
21724
21725 Defaults to @samp{""}.
21726
21727 @end deftypevr
21728
21729 @deftypevr {@code{repository-cgit-configuration} parameter} module-link-path module-link-path
21730 Text which will be used as the formatstring for a hyperlink when a
21731 submodule with the specified subdirectory path is printed in a directory
21732 listing.
21733
21734 Defaults to @samp{()}.
21735
21736 @end deftypevr
21737
21738 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string max-stats
21739 Override the default maximum statistics period.
21740
21741 Defaults to @samp{""}.
21742
21743 @end deftypevr
21744
21745 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string name
21746 The value to show as repository name.
21747
21748 Defaults to @samp{""}.
21749
21750 @end deftypevr
21751
21752 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string owner
21753 A value used to identify the owner of the repository.
21754
21755 Defaults to @samp{""}.
21756
21757 @end deftypevr
21758
21759 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string path
21760 An absolute path to the repository directory.
21761
21762 Defaults to @samp{""}.
21763
21764 @end deftypevr
21765
21766 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string readme
21767 A path (relative to repo) which specifies a file to include verbatim as
21768 the "About" page for this repo.
21769
21770 Defaults to @samp{""}.
21771
21772 @end deftypevr
21773
21774 @deftypevr {@code{repository-cgit-configuration} parameter} repo-string section
21775 The name of the current repository section - all repositories defined
21776 after this option will inherit the current section name.
21777
21778 Defaults to @samp{""}.
21779
21780 @end deftypevr
21781
21782 @deftypevr {@code{repository-cgit-configuration} parameter} repo-list extra-options
21783 Extra options will be appended to cgitrc file.
21784
21785 Defaults to @samp{()}.
21786
21787 @end deftypevr
21788
21789 @end deftypevr
21790
21791 @deftypevr {@code{cgit-configuration} parameter} list extra-options
21792 Extra options will be appended to cgitrc file.
21793
21794 Defaults to @samp{()}.
21795
21796 @end deftypevr
21797
21798
21799 @c %end of fragment
21800
21801 However, it could be that you just want to get a @code{cgitrc} up and
21802 running. In that case, you can pass an @code{opaque-cgit-configuration}
21803 as a record to @code{cgit-service-type}. As its name indicates, an
21804 opaque configuration does not have easy reflective capabilities.
21805
21806 Available @code{opaque-cgit-configuration} fields are:
21807
21808 @deftypevr {@code{opaque-cgit-configuration} parameter} package cgit
21809 The cgit package.
21810 @end deftypevr
21811
21812 @deftypevr {@code{opaque-cgit-configuration} parameter} string string
21813 The contents of the @code{cgitrc}, as a string.
21814 @end deftypevr
21815
21816 For example, if your @code{cgitrc} is just the empty string, you
21817 could instantiate a cgit service like this:
21818
21819 @example
21820 (service cgit-service-type
21821 (opaque-cgit-configuration
21822 (cgitrc "")))
21823 @end example
21824
21825 @subsubheading Gitolite Service
21826
21827 @cindex Gitolite service
21828 @cindex Git, hosting
21829 @uref{http://gitolite.com/gitolite/, Gitolite} is a tool for hosting Git
21830 repositories on a central server.
21831
21832 Gitolite can handle multiple repositories and users, and supports flexible
21833 configuration of the permissions for the users on the repositories.
21834
21835 The following example will configure Gitolite using the default @code{git}
21836 user, and the provided SSH public key.
21837
21838 @example
21839 (service gitolite-service-type
21840 (gitolite-configuration
21841 (admin-pubkey (plain-file
21842 "yourname.pub"
21843 "ssh-rsa AAAA... guix@@example.com"))))
21844 @end example
21845
21846 Gitolite is configured through a special admin repository which you can clone,
21847 for example, if you setup Gitolite on @code{example.com}, you would run the
21848 following command to clone the admin repository.
21849
21850 @example
21851 git clone git@@example.com:gitolite-admin
21852 @end example
21853
21854 When the Gitolite service is activated, the provided @code{admin-pubkey} will
21855 be inserted in to the @file{keydir} directory in the gitolite-admin
21856 repository. If this results in a change in the repository, it will be
21857 committed using the message ``gitolite setup by GNU Guix''.
21858
21859 @deftp {Data Type} gitolite-configuration
21860 Data type representing the configuration for @code{gitolite-service-type}.
21861
21862 @table @asis
21863 @item @code{package} (default: @var{gitolite})
21864 Gitolite package to use.
21865
21866 @item @code{user} (default: @var{git})
21867 User to use for Gitolite. This will be user that you use when accessing
21868 Gitolite over SSH.
21869
21870 @item @code{group} (default: @var{git})
21871 Group to use for Gitolite.
21872
21873 @item @code{home-directory} (default: @var{"/var/lib/gitolite"})
21874 Directory in which to store the Gitolite configuration and repositories.
21875
21876 @item @code{rc-file} (default: @var{(gitolite-rc-file)})
21877 A ``file-like'' object (@pxref{G-Expressions, file-like objects}),
21878 representing the configuration for Gitolite.
21879
21880 @item @code{admin-pubkey} (default: @var{#f})
21881 A ``file-like'' object (@pxref{G-Expressions, file-like objects}) used to
21882 setup Gitolite. This will be inserted in to the @file{keydir} directory
21883 within the gitolite-admin repository.
21884
21885 To specify the SSH key as a string, use the @code{plain-file} function.
21886
21887 @example
21888 (plain-file "yourname.pub" "ssh-rsa AAAA... guix@@example.com")
21889 @end example
21890
21891 @end table
21892 @end deftp
21893
21894 @deftp {Data Type} gitolite-rc-file
21895 Data type representing the Gitolite RC file.
21896
21897 @table @asis
21898 @item @code{umask} (default: @code{#o0077})
21899 This controls the permissions Gitolite sets on the repositories and their
21900 contents.
21901
21902 A value like @code{#o0027} will give read access to the group used by Gitolite
21903 (by default: @code{git}). This is necessary when using Gitolite with software
21904 like cgit or gitweb.
21905
21906 @item @code{git-config-keys} (default: @code{""})
21907 Gitolite allows you to set git config values using the "config" keyword. This
21908 setting allows control over the config keys to accept.
21909
21910 @item @code{roles} (default: @code{'(("READERS" . 1) ("WRITERS" . ))})
21911 Set the role names allowed to be used by users running the perms command.
21912
21913 @item @code{enable} (default: @code{'("help" "desc" "info" "perms" "writable" "ssh-authkeys" "git-config" "daemon" "gitweb")})
21914 This setting controls the commands and features to enable within Gitolite.
21915
21916 @end table
21917 @end deftp
21918
21919
21920 @node Game Services
21921 @subsubsection Game Services
21922
21923 @subsubheading The Battle for Wesnoth Service
21924 @cindex wesnothd
21925 @uref{https://wesnoth.org, The Battle for Wesnoth} is a fantasy, turn
21926 based tactical strategy game, with several single player campaigns, and
21927 multiplayer games (both networked and local).
21928
21929 @defvar {Scheme Variable} wesnothd-service-type
21930 Service type for the wesnothd service. Its value must be a
21931 @code{wesnothd-configuration} object. To run wesnothd in the default
21932 configuration, instantiate it as:
21933
21934 @example
21935 (service wesnothd-service-type)
21936 @end example
21937 @end defvar
21938
21939 @deftp {Data Type} wesnothd-configuration
21940 Data type representing the configuration of @command{wesnothd}.
21941
21942 @table @asis
21943 @item @code{package} (default: @code{wesnoth-server})
21944 The wesnoth server package to use.
21945
21946 @item @code{port} (default: @code{15000})
21947 The port to bind the server to.
21948 @end table
21949 @end deftp
21950
21951 @node Miscellaneous Services
21952 @subsubsection Miscellaneous Services
21953
21954 @cindex fingerprint
21955 @subsubheading Fingerprint Service
21956
21957 The @code{(gnu services fingerprint)} module provides a DBus service to
21958 read and identify fingerprints via a fingerprint sensor.
21959
21960 @defvr {Scheme Variable} fprintd-service-type
21961 The service type for @command{fprintd}, which provides the fingerprint
21962 reading capability.
21963
21964 @example
21965 (service fprintd-service-type)
21966 @end example
21967 @end defvr
21968
21969 @cindex sysctl
21970 @subsubheading System Control Service
21971
21972 The @code{(gnu services sysctl)} provides a service to configure kernel
21973 parameters at boot.
21974
21975 @defvr {Scheme Variable} sysctl-service-type
21976 The service type for @command{sysctl}, which modifies kernel parameters
21977 under @file{/proc/sys/}. To enable IPv4 forwarding, it can be
21978 instantiated as:
21979
21980 @example
21981 (service sysctl-service-type
21982 (sysctl-configuration
21983 (settings '(("net.ipv4.ip_forward" . "1")))))
21984 @end example
21985 @end defvr
21986
21987 @deftp {Data Type} sysctl-configuration
21988 The data type representing the configuration of @command{sysctl}.
21989
21990 @table @asis
21991 @item @code{sysctl} (default: @code{(file-append procps "/sbin/sysctl"})
21992 The @command{sysctl} executable to use.
21993
21994 @item @code{settings} (default: @code{'()})
21995 An association list specifies kernel parameters and their values.
21996 @end table
21997 @end deftp
21998
21999 @cindex pcscd
22000 @subsubheading PC/SC Smart Card Daemon Service
22001
22002 The @code{(gnu services security-token)} module provides the following service
22003 to run @command{pcscd}, the PC/SC Smart Card Daemon. @command{pcscd} is the
22004 daemon program for pcsc-lite and the MuscleCard framework. It is a resource
22005 manager that coordinates communications with smart card readers, smart cards
22006 and cryptographic tokens that are connected to the system.
22007
22008 @defvr {Scheme Variable} pcscd-service-type
22009 Service type for the @command{pcscd} service. Its value must be a
22010 @code{pcscd-configuration} object. To run pcscd in the default
22011 configuration, instantiate it as:
22012
22013 @example
22014 (service pcscd-service-type)
22015 @end example
22016 @end defvr
22017
22018 @deftp {Data Type} pcscd-configuration
22019 The data type representing the configuration of @command{pcscd}.
22020
22021 @table @asis
22022 @item @code{pcsc-lite} (default: @code{pcsc-lite})
22023 The pcsc-lite package that provides pcscd.
22024 @item @code{usb-drivers} (default: @code{(list ccid)})
22025 List of packages that provide USB drivers to pcscd. Drivers are expected to be
22026 under @file{pcsc/drivers} in the store directory of the package.
22027 @end table
22028 @end deftp
22029
22030 @cindex lirc
22031 @subsubheading Lirc Service
22032
22033 The @code{(gnu services lirc)} module provides the following service.
22034
22035 @deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
22036 [#:device #f] [#:driver #f] [#:config-file #f] @
22037 [#:extra-options '()]
22038 Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
22039 decodes infrared signals from remote controls.
22040
22041 Optionally, @var{device}, @var{driver} and @var{config-file}
22042 (configuration file name) may be specified. See @command{lircd} manual
22043 for details.
22044
22045 Finally, @var{extra-options} is a list of additional command-line options
22046 passed to @command{lircd}.
22047 @end deffn
22048
22049 @cindex spice
22050 @subsubheading Spice Service
22051
22052 The @code{(gnu services spice)} module provides the following service.
22053
22054 @deffn {Scheme Procedure} spice-vdagent-service [#:spice-vdagent]
22055 Returns a service that runs @url{http://www.spice-space.org,VDAGENT}, a daemon
22056 that enables sharing the clipboard with a vm and setting the guest display
22057 resolution when the graphical console window resizes.
22058 @end deffn
22059
22060 @subsubsection Dictionary Services
22061 @cindex dictionary
22062 The @code{(gnu services dict)} module provides the following service:
22063
22064 @deffn {Scheme Procedure} dicod-service [#:config (dicod-configuration)]
22065 Return a service that runs the @command{dicod} daemon, an implementation
22066 of DICT server (@pxref{Dicod,,, dico, GNU Dico Manual}).
22067
22068 The optional @var{config} argument specifies the configuration for
22069 @command{dicod}, which should be a @code{<dicod-configuration>} object, by
22070 default it serves the GNU Collaborative International Dictonary of English.
22071
22072 You can add @command{open localhost} to your @file{~/.dico} file to make
22073 @code{localhost} the default server for @command{dico} client
22074 (@pxref{Initialization File,,, dico, GNU Dico Manual}).
22075 @end deffn
22076
22077 @deftp {Data Type} dicod-configuration
22078 Data type representing the configuration of dicod.
22079
22080 @table @asis
22081 @item @code{dico} (default: @var{dico})
22082 Package object of the GNU Dico dictionary server.
22083
22084 @item @code{interfaces} (default: @var{'("localhost")})
22085 This is the list of IP addresses and ports and possibly socket file
22086 names to listen to (@pxref{Server Settings, @code{listen} directive,,
22087 dico, GNU Dico Manual}).
22088
22089 @item @code{handlers} (default: @var{'()})
22090 List of @code{<dicod-handler>} objects denoting handlers (module instances).
22091
22092 @item @code{databases} (default: @var{(list %dicod-database:gcide)})
22093 List of @code{<dicod-database>} objects denoting dictionaries to be served.
22094 @end table
22095 @end deftp
22096
22097 @deftp {Data Type} dicod-handler
22098 Data type representing a dictionary handler (module instance).
22099
22100 @table @asis
22101 @item @code{name}
22102 Name of the handler (module instance).
22103
22104 @item @code{module} (default: @var{#f})
22105 Name of the dicod module of the handler (instance). If it is @code{#f},
22106 the module has the same name as the handler.
22107 (@pxref{Modules,,, dico, GNU Dico Manual}).
22108
22109 @item @code{options}
22110 List of strings or gexps representing the arguments for the module handler
22111 @end table
22112 @end deftp
22113
22114 @deftp {Data Type} dicod-database
22115 Data type representing a dictionary database.
22116
22117 @table @asis
22118 @item @code{name}
22119 Name of the database, will be used in DICT commands.
22120
22121 @item @code{handler}
22122 Name of the dicod handler (module instance) used by this database
22123 (@pxref{Handlers,,, dico, GNU Dico Manual}).
22124
22125 @item @code{complex?} (default: @var{#f})
22126 Whether the database configuration complex. The complex configuration
22127 will need a corresponding @code{<dicod-handler>} object, otherwise not.
22128
22129 @item @code{options}
22130 List of strings or gexps representing the arguments for the database
22131 (@pxref{Databases,,, dico, GNU Dico Manual}).
22132 @end table
22133 @end deftp
22134
22135 @defvr {Scheme Variable} %dicod-database:gcide
22136 A @code{<dicod-database>} object serving the GNU Collaborative International
22137 Dictionary of English using the @code{gcide} package.
22138 @end defvr
22139
22140 The following is an example @code{dicod-service} configuration.
22141
22142 @example
22143 (dicod-service #:config
22144 (dicod-configuration
22145 (handlers (list (dicod-handler
22146 (name "wordnet")
22147 (module "dictorg")
22148 (options
22149 (list #~(string-append "dbdir=" #$wordnet))))))
22150 (databases (list (dicod-database
22151 (name "wordnet")
22152 (complex? #t)
22153 (handler "wordnet")
22154 (options '("database=wn")))
22155 %dicod-database:gcide))))
22156 @end example
22157
22158 @cindex Docker
22159 @subsubheading Docker Service
22160
22161 The @code{(gnu services docker)} module provides the following service.
22162
22163 @defvr {Scheme Variable} docker-service-type
22164
22165 This is the type of the service that runs @url{http://www.docker.com,Docker},
22166 a daemon that can execute application bundles (sometimes referred to as
22167 ``containers'') in isolated environments.
22168
22169 @end defvr
22170
22171 @deftp {Data Type} docker-configuration
22172 This is the data type representing the configuration of Docker and Containerd.
22173
22174 @table @asis
22175
22176 @item @code{package} (default: @code{docker})
22177 The Docker package to use.
22178
22179 @item @code{containerd} (default: @var{containerd})
22180 The Containerd package to use.
22181
22182 @end table
22183 @end deftp
22184
22185 @node Setuid Programs
22186 @subsection Setuid Programs
22187
22188 @cindex setuid programs
22189 Some programs need to run with ``root'' privileges, even when they are
22190 launched by unprivileged users. A notorious example is the
22191 @command{passwd} program, which users can run to change their
22192 password, and which needs to access the @file{/etc/passwd} and
22193 @file{/etc/shadow} files---something normally restricted to root, for
22194 obvious security reasons. To address that, these executables are
22195 @dfn{setuid-root}, meaning that they always run with root privileges
22196 (@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
22197 for more info about the setuid mechanism.)
22198
22199 The store itself @emph{cannot} contain setuid programs: that would be a
22200 security issue since any user on the system can write derivations that
22201 populate the store (@pxref{The Store}). Thus, a different mechanism is
22202 used: instead of changing the setuid bit directly on files that are in
22203 the store, we let the system administrator @emph{declare} which programs
22204 should be setuid root.
22205
22206 The @code{setuid-programs} field of an @code{operating-system}
22207 declaration contains a list of G-expressions denoting the names of
22208 programs to be setuid-root (@pxref{Using the Configuration System}).
22209 For instance, the @command{passwd} program, which is part of the Shadow
22210 package, can be designated by this G-expression (@pxref{G-Expressions}):
22211
22212 @example
22213 #~(string-append #$shadow "/bin/passwd")
22214 @end example
22215
22216 A default set of setuid programs is defined by the
22217 @code{%setuid-programs} variable of the @code{(gnu system)} module.
22218
22219 @defvr {Scheme Variable} %setuid-programs
22220 A list of G-expressions denoting common programs that are setuid-root.
22221
22222 The list includes commands such as @command{passwd}, @command{ping},
22223 @command{su}, and @command{sudo}.
22224 @end defvr
22225
22226 Under the hood, the actual setuid programs are created in the
22227 @file{/run/setuid-programs} directory at system activation time. The
22228 files in this directory refer to the ``real'' binaries, which are in the
22229 store.
22230
22231 @node X.509 Certificates
22232 @subsection X.509 Certificates
22233
22234 @cindex HTTPS, certificates
22235 @cindex X.509 certificates
22236 @cindex TLS
22237 Web servers available over HTTPS (that is, HTTP over the transport-layer
22238 security mechanism, TLS) send client programs an @dfn{X.509 certificate}
22239 that the client can then use to @emph{authenticate} the server. To do
22240 that, clients verify that the server's certificate is signed by a
22241 so-called @dfn{certificate authority} (CA). But to verify the CA's
22242 signature, clients must have first acquired the CA's certificate.
22243
22244 Web browsers such as GNU@tie{}IceCat include their own set of CA
22245 certificates, such that they are able to verify CA signatures
22246 out-of-the-box.
22247
22248 However, most other programs that can talk HTTPS---@command{wget},
22249 @command{git}, @command{w3m}, etc.---need to be told where CA
22250 certificates can be found.
22251
22252 @cindex @code{nss-certs}
22253 In GuixSD, this is done by adding a package that provides certificates
22254 to the @code{packages} field of the @code{operating-system} declaration
22255 (@pxref{operating-system Reference}). GuixSD includes one such package,
22256 @code{nss-certs}, which is a set of CA certificates provided as part of
22257 Mozilla's Network Security Services.
22258
22259 Note that it is @emph{not} part of @var{%base-packages}, so you need to
22260 explicitly add it. The @file{/etc/ssl/certs} directory, which is where
22261 most applications and libraries look for certificates by default, points
22262 to the certificates installed globally.
22263
22264 Unprivileged users, including users of Guix on a foreign distro,
22265 can also install their own certificate package in
22266 their profile. A number of environment variables need to be defined so
22267 that applications and libraries know where to find them. Namely, the
22268 OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
22269 variables. Some applications add their own environment variables; for
22270 instance, the Git version control system honors the certificate bundle
22271 pointed to by the @code{GIT_SSL_CAINFO} environment variable. Thus, you
22272 would typically run something like:
22273
22274 @example
22275 $ guix package -i nss-certs
22276 $ export SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs"
22277 $ export SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt"
22278 $ export GIT_SSL_CAINFO="$SSL_CERT_FILE"
22279 @end example
22280
22281 As another example, R requires the @code{CURL_CA_BUNDLE} environment
22282 variable to point to a certificate bundle, so you would have to run
22283 something like this:
22284
22285 @example
22286 $ guix package -i nss-certs
22287 $ export CURL_CA_BUNDLE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt"
22288 @end example
22289
22290 For other applications you may want to look up the required environment
22291 variable in the relevant documentation.
22292
22293
22294 @node Name Service Switch
22295 @subsection Name Service Switch
22296
22297 @cindex name service switch
22298 @cindex NSS
22299 The @code{(gnu system nss)} module provides bindings to the
22300 configuration file of the libc @dfn{name service switch} or @dfn{NSS}
22301 (@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
22302 Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
22303 extended with new ``name'' lookup methods for system databases, which
22304 includes host names, service names, user accounts, and more (@pxref{Name
22305 Service Switch, System Databases and Name Service Switch,, libc, The GNU
22306 C Library Reference Manual}).
22307
22308 The NSS configuration specifies, for each system database, which lookup
22309 method is to be used, and how the various methods are chained
22310 together---for instance, under which circumstances NSS should try the
22311 next method in the list. The NSS configuration is given in the
22312 @code{name-service-switch} field of @code{operating-system} declarations
22313 (@pxref{operating-system Reference, @code{name-service-switch}}).
22314
22315 @cindex nss-mdns
22316 @cindex .local, host name lookup
22317 As an example, the declaration below configures the NSS to use the
22318 @uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
22319 back-end}, which supports host name lookups over multicast DNS (mDNS)
22320 for host names ending in @code{.local}:
22321
22322 @example
22323 (name-service-switch
22324 (hosts (list %files ;first, check /etc/hosts
22325
22326 ;; If the above did not succeed, try
22327 ;; with 'mdns_minimal'.
22328 (name-service
22329 (name "mdns_minimal")
22330
22331 ;; 'mdns_minimal' is authoritative for
22332 ;; '.local'. When it returns "not found",
22333 ;; no need to try the next methods.
22334 (reaction (lookup-specification
22335 (not-found => return))))
22336
22337 ;; Then fall back to DNS.
22338 (name-service
22339 (name "dns"))
22340
22341 ;; Finally, try with the "full" 'mdns'.
22342 (name-service
22343 (name "mdns")))))
22344 @end example
22345
22346 Do not worry: the @code{%mdns-host-lookup-nss} variable (see below)
22347 contains this configuration, so you will not have to type it if all you
22348 want is to have @code{.local} host lookup working.
22349
22350 Note that, in this case, in addition to setting the
22351 @code{name-service-switch} of the @code{operating-system} declaration,
22352 you also need to use @code{avahi-service-type} (@pxref{Networking Services,
22353 @code{avahi-service-type}}), or @var{%desktop-services}, which includes it
22354 (@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
22355 to the name service cache daemon (@pxref{Base Services,
22356 @code{nscd-service}}).
22357
22358 For convenience, the following variables provide typical NSS
22359 configurations.
22360
22361 @defvr {Scheme Variable} %default-nss
22362 This is the default name service switch configuration, a
22363 @code{name-service-switch} object.
22364 @end defvr
22365
22366 @defvr {Scheme Variable} %mdns-host-lookup-nss
22367 This is the name service switch configuration with support for host name
22368 lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
22369 @end defvr
22370
22371 The reference for name service switch configuration is given below. It
22372 is a direct mapping of the configuration file format of the C library , so
22373 please refer to the C library manual for more information (@pxref{NSS
22374 Configuration File,,, libc, The GNU C Library Reference Manual}).
22375 Compared to the configuration file format of libc NSS, it has the advantage
22376 not only of adding this warm parenthetic feel that we like, but also
22377 static checks: you will know about syntax errors and typos as soon as you
22378 run @command{guix system}.
22379
22380 @deftp {Data Type} name-service-switch
22381
22382 This is the data type representation the configuration of libc's name
22383 service switch (NSS). Each field below represents one of the supported
22384 system databases.
22385
22386 @table @code
22387 @item aliases
22388 @itemx ethers
22389 @itemx group
22390 @itemx gshadow
22391 @itemx hosts
22392 @itemx initgroups
22393 @itemx netgroup
22394 @itemx networks
22395 @itemx password
22396 @itemx public-key
22397 @itemx rpc
22398 @itemx services
22399 @itemx shadow
22400 The system databases handled by the NSS. Each of these fields must be a
22401 list of @code{<name-service>} objects (see below).
22402 @end table
22403 @end deftp
22404
22405 @deftp {Data Type} name-service
22406
22407 This is the data type representing an actual name service and the
22408 associated lookup action.
22409
22410 @table @code
22411 @item name
22412 A string denoting the name service (@pxref{Services in the NSS
22413 configuration,,, libc, The GNU C Library Reference Manual}).
22414
22415 Note that name services listed here must be visible to nscd. This is
22416 achieved by passing the @code{#:name-services} argument to
22417 @code{nscd-service} the list of packages providing the needed name
22418 services (@pxref{Base Services, @code{nscd-service}}).
22419
22420 @item reaction
22421 An action specified using the @code{lookup-specification} macro
22422 (@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
22423 Reference Manual}). For example:
22424
22425 @example
22426 (lookup-specification (unavailable => continue)
22427 (success => return))
22428 @end example
22429 @end table
22430 @end deftp
22431
22432 @node Initial RAM Disk
22433 @subsection Initial RAM Disk
22434
22435 @cindex initrd
22436 @cindex initial RAM disk
22437 For bootstrapping purposes, the Linux-Libre kernel is passed an
22438 @dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
22439 root file system as well as an initialization script. The latter is
22440 responsible for mounting the real root file system, and for loading any
22441 kernel modules that may be needed to achieve that.
22442
22443 The @code{initrd-modules} field of an @code{operating-system}
22444 declaration allows you to specify Linux-libre kernel modules that must
22445 be available in the initrd. In particular, this is where you would list
22446 modules needed to actually drive the hard disk where your root partition
22447 is---although the default value of @code{initrd-modules} should cover
22448 most use cases. For example, assuming you need the @code{megaraid_sas}
22449 module in addition to the default modules to be able to access your root
22450 file system, you would write:
22451
22452 @example
22453 (operating-system
22454 ;; @dots{}
22455 (initrd-modules (cons "megaraid_sas" %base-initrd-modules)))
22456 @end example
22457
22458 @defvr {Scheme Variable} %base-initrd-modules
22459 This is the list of kernel modules included in the initrd by default.
22460 @end defvr
22461
22462 Furthermore, if you need lower-level customization, the @code{initrd}
22463 field of an @code{operating-system} declaration allows
22464 you to specify which initrd you would like to use. The @code{(gnu
22465 system linux-initrd)} module provides three ways to build an initrd: the
22466 high-level @code{base-initrd} procedure and the low-level
22467 @code{raw-initrd} and @code{expression->initrd} procedures.
22468
22469 The @code{base-initrd} procedure is intended to cover most common uses.
22470 For example, if you want to add a bunch of kernel modules to be loaded
22471 at boot time, you can define the @code{initrd} field of the operating
22472 system declaration like this:
22473
22474 @example
22475 (initrd (lambda (file-systems . rest)
22476 ;; Create a standard initrd but set up networking
22477 ;; with the parameters QEMU expects by default.
22478 (apply base-initrd file-systems
22479 #:qemu-networking? #t
22480 rest)))
22481 @end example
22482
22483 The @code{base-initrd} procedure also handles common use cases that
22484 involves using the system as a QEMU guest, or as a ``live'' system with
22485 volatile root file system.
22486
22487 The @code{base-initrd} procedure is built from @code{raw-initrd} procedure.
22488 Unlike @code{base-initrd}, @code{raw-initrd} doesn't do anything high-level,
22489 such as trying to guess which kernel modules and packages should be included
22490 to the initrd. An example use of @code{raw-initrd} is when a user has
22491 a custom Linux kernel configuration and default kernel modules included by
22492 @code{base-initrd} are not available.
22493
22494 The initial RAM disk produced by @code{base-initrd} or @code{raw-initrd}
22495 honors several options passed on the Linux kernel command line
22496 (that is, arguments passed @i{via} the @code{linux} command of GRUB, or the
22497 @code{-append} option of QEMU), notably:
22498
22499 @table @code
22500 @item --load=@var{boot}
22501 Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
22502 program, once it has mounted the root file system.
22503
22504 GuixSD uses this option to yield control to a boot program that runs the
22505 service activation programs and then spawns the GNU@tie{}Shepherd, the
22506 initialization system.
22507
22508 @item --root=@var{root}
22509 Mount @var{root} as the root file system. @var{root} can be a
22510 device name like @code{/dev/sda1}, a file system label, or a file system
22511 UUID.
22512
22513 @item --system=@var{system}
22514 Have @file{/run/booted-system} and @file{/run/current-system} point to
22515 @var{system}.
22516
22517 @item modprobe.blacklist=@var{modules}@dots{}
22518 @cindex module, black-listing
22519 @cindex black list, of kernel modules
22520 Instruct the initial RAM disk as well as the @command{modprobe} command
22521 (from the kmod package) to refuse to load @var{modules}. @var{modules}
22522 must be a comma-separated list of module names---e.g.,
22523 @code{usbkbd,9pnet}.
22524
22525 @item --repl
22526 Start a read-eval-print loop (REPL) from the initial RAM disk before it
22527 tries to load kernel modules and to mount the root file system. Our
22528 marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
22529 love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
22530 Manual}, for more information on Guile's REPL.
22531
22532 @end table
22533
22534 Now that you know all the features that initial RAM disks produced by
22535 @code{base-initrd} and @code{raw-initrd} provide,
22536 here is how to use it and customize it further.
22537
22538 @cindex initrd
22539 @cindex initial RAM disk
22540 @deffn {Scheme Procedure} raw-initrd @var{file-systems} @
22541 [#:linux-modules '()] [#:mapped-devices '()] @
22542 [#:helper-packages '()] [#:qemu-networking? #f] [#:volatile-root? #f]
22543 Return a derivation that builds a raw initrd. @var{file-systems} is
22544 a list of file systems to be mounted by the initrd, possibly in addition to
22545 the root file system specified on the kernel command line via @code{--root}.
22546 @var{linux-modules} is a list of kernel modules to be loaded at boot time.
22547 @var{mapped-devices} is a list of device mappings to realize before
22548 @var{file-systems} are mounted (@pxref{Mapped Devices}).
22549 @var{helper-packages} is a list of packages to be copied in the initrd. It may
22550 include @code{e2fsck/static} or other packages needed by the initrd to check
22551 the root file system.
22552
22553 When @var{qemu-networking?} is true, set up networking with the standard QEMU
22554 parameters. When @var{virtio?} is true, load additional modules so that the
22555 initrd can be used as a QEMU guest with para-virtualized I/O drivers.
22556
22557 When @var{volatile-root?} is true, the root file system is writable but any changes
22558 to it are lost.
22559 @end deffn
22560
22561 @deffn {Scheme Procedure} base-initrd @var{file-systems} @
22562 [#:mapped-devices '()] [#:qemu-networking? #f] [#:volatile-root? #f]@
22563 [#:linux-modules '()]
22564 Return as a file-like object a generic initrd, with kernel
22565 modules taken from @var{linux}. @var{file-systems} is a list of file-systems to be
22566 mounted by the initrd, possibly in addition to the root file system specified
22567 on the kernel command line via @code{--root}. @var{mapped-devices} is a list of device
22568 mappings to realize before @var{file-systems} are mounted.
22569
22570 @var{qemu-networking?} and @var{volatile-root?} behaves as in @code{raw-initrd}.
22571
22572 The initrd is automatically populated with all the kernel modules necessary
22573 for @var{file-systems} and for the given options. Additional kernel
22574 modules can be listed in @var{linux-modules}. They will be added to the initrd, and
22575 loaded at boot time in the order in which they appear.
22576 @end deffn
22577
22578 Needless to say, the initrds we produce and use embed a
22579 statically-linked Guile, and the initialization program is a Guile
22580 program. That gives a lot of flexibility. The
22581 @code{expression->initrd} procedure builds such an initrd, given the
22582 program to run in that initrd.
22583
22584 @deffn {Scheme Procedure} expression->initrd @var{exp} @
22585 [#:guile %guile-static-stripped] [#:name "guile-initrd"]
22586 Return as a file-like object a Linux initrd (a gzipped cpio archive)
22587 containing @var{guile} and that evaluates @var{exp}, a G-expression,
22588 upon booting. All the derivations referenced by @var{exp} are
22589 automatically copied to the initrd.
22590 @end deffn
22591
22592 @node Bootloader Configuration
22593 @subsection Bootloader Configuration
22594
22595 @cindex bootloader
22596 @cindex boot loader
22597
22598 The operating system supports multiple bootloaders. The bootloader is
22599 configured using @code{bootloader-configuration} declaration. All the
22600 fields of this structure are bootloader agnostic except for one field,
22601 @code{bootloader} that indicates the bootloader to be configured and
22602 installed.
22603
22604 Some of the bootloaders do not honor every field of
22605 @code{bootloader-configuration}. For instance, the extlinux
22606 bootloader does not support themes and thus ignores the @code{theme}
22607 field.
22608
22609 @deftp {Data Type} bootloader-configuration
22610 The type of a bootloader configuration declaration.
22611
22612 @table @asis
22613
22614 @item @code{bootloader}
22615 @cindex EFI, bootloader
22616 @cindex UEFI, bootloader
22617 @cindex BIOS, bootloader
22618 The bootloader to use, as a @code{bootloader} object. For now
22619 @code{grub-bootloader}, @code{grub-efi-bootloader},
22620 @code{extlinux-bootloader} and @code{u-boot-bootloader} are supported.
22621
22622 @vindex grub-efi-bootloader
22623 @code{grub-efi-bootloader} allows to boot on modern systems using the
22624 @dfn{Unified Extensible Firmware Interface} (UEFI). This is what you should
22625 use if the installation image contains a @file{/sys/firmware/efi} directory
22626 when you boot it on your system.
22627
22628 @vindex grub-bootloader
22629 @code{grub-bootloader} allows you to boot in particular Intel-based machines
22630 in ``legacy'' BIOS mode.
22631
22632 @cindex ARM, bootloaders
22633 @cindex AArch64, bootloaders
22634 Available bootloaders are described in @code{(gnu bootloader @dots{})}
22635 modules. In particular, @code{(gnu bootloader u-boot)} contains definitions
22636 of bootloaders for a wide range of ARM and AArch64 systems, using the
22637 @uref{http://www.denx.de/wiki/U-Boot/, U-Boot bootloader}.
22638
22639 @item @code{target}
22640 This is a string denoting the target onto which to install the
22641 bootloader.
22642
22643 The interpretation depends on the bootloader in question. For
22644 @code{grub-bootloader}, for example, it should be a device name understood by
22645 the bootloader @command{installer} command, such as @code{/dev/sda} or
22646 @code{(hd0)} (@pxref{Invoking grub-install,,, grub, GNU GRUB Manual}). For
22647 @code{grub-efi-bootloader}, it should be the mount point of the EFI file
22648 system, usually @file{/boot/efi}.
22649
22650 @item @code{menu-entries} (default: @code{()})
22651 A possibly empty list of @code{menu-entry} objects (see below), denoting
22652 entries to appear in the bootloader menu, in addition to the current
22653 system entry and the entry pointing to previous system generations.
22654
22655 @item @code{default-entry} (default: @code{0})
22656 The index of the default boot menu entry. Index 0 is for the entry of the
22657 current system.
22658
22659 @item @code{timeout} (default: @code{5})
22660 The number of seconds to wait for keyboard input before booting. Set to
22661 0 to boot immediately, and to -1 to wait indefinitely.
22662
22663 @item @code{theme} (default: @var{#f})
22664 The bootloader theme object describing the theme to use. If no theme
22665 is provided, some bootloaders might use a default theme, that's true
22666 for GRUB.
22667
22668 @item @code{terminal-outputs} (default: @code{'gfxterm})
22669 The output terminals used for the bootloader boot menu, as a list of
22670 symbols. GRUB accepts the values: @code{console}, @code{serial},
22671 @code{serial_@{0-3@}}, @code{gfxterm}, @code{vga_text},
22672 @code{mda_text}, @code{morse}, and @code{pkmodem}. This field
22673 corresponds to the GRUB variable @code{GRUB_TERMINAL_OUTPUT} (@pxref{Simple
22674 configuration,,, grub,GNU GRUB manual}).
22675
22676 @item @code{terminal-inputs} (default: @code{'()})
22677 The input terminals used for the bootloader boot menu, as a list of
22678 symbols. For GRUB, the default is the native platform terminal as
22679 determined at run-time. GRUB accepts the values: @code{console},
22680 @code{serial}, @code{serial_@{0-3@}}, @code{at_keyboard}, and
22681 @code{usb_keyboard}. This field corresponds to the GRUB variable
22682 @code{GRUB_TERMINAL_INPUT} (@pxref{Simple configuration,,, grub,GNU GRUB
22683 manual}).
22684
22685 @item @code{serial-unit} (default: @code{#f})
22686 The serial unit used by the bootloader, as an integer from 0 to 3.
22687 For GRUB, it is chosen at run-time; currently GRUB chooses 0, which
22688 corresponds to COM1 (@pxref{Serial terminal,,, grub,GNU GRUB manual}).
22689
22690 @item @code{serial-speed} (default: @code{#f})
22691 The speed of the serial interface, as an integer. For GRUB, the
22692 default value is chosen at run-time; currently GRUB chooses
22693 9600@tie{}bps (@pxref{Serial terminal,,, grub,GNU GRUB manual}).
22694 @end table
22695
22696 @end deftp
22697
22698 @cindex dual boot
22699 @cindex boot menu
22700 Should you want to list additional boot menu entries @i{via} the
22701 @code{menu-entries} field above, you will need to create them with the
22702 @code{menu-entry} form. For example, imagine you want to be able to
22703 boot another distro (hard to imagine!), you can define a menu entry
22704 along these lines:
22705
22706 @example
22707 (menu-entry
22708 (label "The Other Distro")
22709 (linux "/boot/old/vmlinux-2.6.32")
22710 (linux-arguments '("root=/dev/sda2"))
22711 (initrd "/boot/old/initrd"))
22712 @end example
22713
22714 Details below.
22715
22716 @deftp {Data Type} menu-entry
22717 The type of an entry in the bootloader menu.
22718
22719 @table @asis
22720
22721 @item @code{label}
22722 The label to show in the menu---e.g., @code{"GNU"}.
22723
22724 @item @code{linux}
22725 The Linux kernel image to boot, for example:
22726
22727 @example
22728 (file-append linux-libre "/bzImage")
22729 @end example
22730
22731 For GRUB, it is also possible to specify a device explicitly in the
22732 file path using GRUB's device naming convention (@pxref{Naming
22733 convention,,, grub, GNU GRUB manual}), for example:
22734
22735 @example
22736 "(hd0,msdos1)/boot/vmlinuz"
22737 @end example
22738
22739 If the device is specified explicitly as above, then the @code{device}
22740 field is ignored entirely.
22741
22742 @item @code{linux-arguments} (default: @code{()})
22743 The list of extra Linux kernel command-line arguments---e.g.,
22744 @code{("console=ttyS0")}.
22745
22746 @item @code{initrd}
22747 A G-Expression or string denoting the file name of the initial RAM disk
22748 to use (@pxref{G-Expressions}).
22749 @item @code{device} (default: @code{#f})
22750 The device where the kernel and initrd are to be found---i.e., for GRUB,
22751 @dfn{root} for this menu entry (@pxref{root,,, grub, GNU GRUB manual}).
22752
22753 This may be a file system label (a string), a file system UUID (a
22754 bytevector, @pxref{File Systems}), or @code{#f}, in which case
22755 the bootloader will search the device containing the file specified by
22756 the @code{linux} field (@pxref{search,,, grub, GNU GRUB manual}). It
22757 must @emph{not} be an OS device name such as @file{/dev/sda1}.
22758
22759 @end table
22760 @end deftp
22761
22762 @c FIXME: Write documentation once it's stable.
22763 Fow now only GRUB has theme support. GRUB themes are created using
22764 the @code{grub-theme} form, which is not documented yet.
22765
22766 @defvr {Scheme Variable} %default-theme
22767 This is the default GRUB theme used by the operating system if no
22768 @code{theme} field is specified in @code{bootloader-configuration}
22769 record.
22770
22771 It comes with a fancy background image displaying the GNU and Guix
22772 logos.
22773 @end defvr
22774
22775
22776 @node Invoking guix system
22777 @subsection Invoking @code{guix system}
22778
22779 Once you have written an operating system declaration as seen in the
22780 previous section, it can be @dfn{instantiated} using the @command{guix
22781 system} command. The synopsis is:
22782
22783 @example
22784 guix system @var{options}@dots{} @var{action} @var{file}
22785 @end example
22786
22787 @var{file} must be the name of a file containing an
22788 @code{operating-system} declaration. @var{action} specifies how the
22789 operating system is instantiated. Currently the following values are
22790 supported:
22791
22792 @table @code
22793 @item search
22794 Display available service type definitions that match the given regular
22795 expressions, sorted by relevance:
22796
22797 @example
22798 $ guix system search console font
22799 name: console-fonts
22800 location: gnu/services/base.scm:729:2
22801 extends: shepherd-root
22802 description: Install the given fonts on the specified ttys (fonts are
22803 + per virtual console on GNU/Linux). The value of this service is a list
22804 + of tty/font pairs like:
22805 +
22806 + '(("tty1" . "LatGrkCyr-8x16"))
22807 relevance: 20
22808
22809 name: mingetty
22810 location: gnu/services/base.scm:1048:2
22811 extends: shepherd-root
22812 description: Provide console login using the `mingetty' program.
22813 relevance: 2
22814
22815 name: login
22816 location: gnu/services/base.scm:775:2
22817 extends: pam
22818 description: Provide a console log-in service as specified by its
22819 + configuration value, a `login-configuration' object.
22820 relevance: 2
22821
22822 @dots{}
22823 @end example
22824
22825 As for @command{guix package --search}, the result is written in
22826 @code{recutils} format, which makes it easy to filter the output
22827 (@pxref{Top, GNU recutils databases,, recutils, GNU recutils manual}).
22828
22829 @item reconfigure
22830 Build the operating system described in @var{file}, activate it, and
22831 switch to it@footnote{This action (and the related actions
22832 @code{switch-generation} and @code{roll-back}) are usable only on
22833 systems already running GuixSD.}.
22834
22835 This effects all the configuration specified in @var{file}: user
22836 accounts, system services, global package list, setuid programs, etc.
22837 The command starts system services specified in @var{file} that are not
22838 currently running; if a service is currently running this command will
22839 arrange for it to be upgraded the next time it is stopped (e.g.@: by
22840 @code{herd stop X} or @code{herd restart X}).
22841
22842 This command creates a new generation whose number is one greater than
22843 the current generation (as reported by @command{guix system
22844 list-generations}). If that generation already exists, it will be
22845 overwritten. This behavior mirrors that of @command{guix package}
22846 (@pxref{Invoking guix package}).
22847
22848 It also adds a bootloader menu entry for the new OS configuration,
22849 ---unless @option{--no-bootloader} is passed. For GRUB, it moves
22850 entries for older configurations to a submenu, allowing you to choose
22851 an older system generation at boot time should you need it.
22852
22853 @quotation Note
22854 @c The paragraph below refers to the problem discussed at
22855 @c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
22856 It is highly recommended to run @command{guix pull} once before you run
22857 @command{guix system reconfigure} for the first time (@pxref{Invoking
22858 guix pull}). Failing to do that you would see an older version of Guix
22859 once @command{reconfigure} has completed.
22860 @end quotation
22861
22862 @item switch-generation
22863 @cindex generations
22864 Switch to an existing system generation. This action atomically
22865 switches the system profile to the specified system generation. It
22866 also rearranges the system's existing bootloader menu entries. It
22867 makes the menu entry for the specified system generation the default,
22868 and it moves the entries for the other generatiors to a submenu, if
22869 supported by the bootloader being used. The next time the system
22870 boots, it will use the specified system generation.
22871
22872 The bootloader itself is not being reinstalled when using this
22873 command. Thus, the installed bootloader is used with an updated
22874 configuration file.
22875
22876 The target generation can be specified explicitly by its generation
22877 number. For example, the following invocation would switch to system
22878 generation 7:
22879
22880 @example
22881 guix system switch-generation 7
22882 @end example
22883
22884 The target generation can also be specified relative to the current
22885 generation with the form @code{+N} or @code{-N}, where @code{+3} means
22886 ``3 generations ahead of the current generation,'' and @code{-1} means
22887 ``1 generation prior to the current generation.'' When specifying a
22888 negative value such as @code{-1}, you must precede it with @code{--} to
22889 prevent it from being parsed as an option. For example:
22890
22891 @example
22892 guix system switch-generation -- -1
22893 @end example
22894
22895 Currently, the effect of invoking this action is @emph{only} to switch
22896 the system profile to an existing generation and rearrange the
22897 bootloader menu entries. To actually start using the target system
22898 generation, you must reboot after running this action. In the future,
22899 it will be updated to do the same things as @command{reconfigure},
22900 like activating and deactivating services.
22901
22902 This action will fail if the specified generation does not exist.
22903
22904 @item roll-back
22905 @cindex rolling back
22906 Switch to the preceding system generation. The next time the system
22907 boots, it will use the preceding system generation. This is the inverse
22908 of @command{reconfigure}, and it is exactly the same as invoking
22909 @command{switch-generation} with an argument of @code{-1}.
22910
22911 Currently, as with @command{switch-generation}, you must reboot after
22912 running this action to actually start using the preceding system
22913 generation.
22914
22915 @item build
22916 Build the derivation of the operating system, which includes all the
22917 configuration files and programs needed to boot and run the system.
22918 This action does not actually install anything.
22919
22920 @item init
22921 Populate the given directory with all the files necessary to run the
22922 operating system specified in @var{file}. This is useful for first-time
22923 installations of GuixSD. For instance:
22924
22925 @example
22926 guix system init my-os-config.scm /mnt
22927 @end example
22928
22929 copies to @file{/mnt} all the store items required by the configuration
22930 specified in @file{my-os-config.scm}. This includes configuration
22931 files, packages, and so on. It also creates other essential files
22932 needed for the system to operate correctly---e.g., the @file{/etc},
22933 @file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
22934
22935 This command also installs bootloader on the target specified in
22936 @file{my-os-config}, unless the @option{--no-bootloader} option was
22937 passed.
22938
22939 @item vm
22940 @cindex virtual machine
22941 @cindex VM
22942 @anchor{guix system vm}
22943 Build a virtual machine that contains the operating system declared in
22944 @var{file}, and return a script to run that virtual machine (VM).
22945 Arguments given to the script are passed to QEMU as in the example
22946 below, which enables networking and requests 1@tie{}GiB of RAM for the
22947 emulated machine:
22948
22949 @example
22950 $ /gnu/store/@dots{}-run-vm.sh -m 1024 -net user
22951 @end example
22952
22953 The VM shares its store with the host system.
22954
22955 Additional file systems can be shared between the host and the VM using
22956 the @code{--share} and @code{--expose} command-line options: the former
22957 specifies a directory to be shared with write access, while the latter
22958 provides read-only access to the shared directory.
22959
22960 The example below creates a VM in which the user's home directory is
22961 accessible read-only, and where the @file{/exchange} directory is a
22962 read-write mapping of @file{$HOME/tmp} on the host:
22963
22964 @example
22965 guix system vm my-config.scm \
22966 --expose=$HOME --share=$HOME/tmp=/exchange
22967 @end example
22968
22969 On GNU/Linux, the default is to boot directly to the kernel; this has
22970 the advantage of requiring only a very tiny root disk image since the
22971 store of the host can then be mounted.
22972
22973 The @code{--full-boot} option forces a complete boot sequence, starting
22974 with the bootloader. This requires more disk space since a root image
22975 containing at least the kernel, initrd, and bootloader data files must
22976 be created. The @code{--image-size} option can be used to specify the
22977 size of the image.
22978
22979 @cindex System images, creation in various formats
22980 @cindex Creating system images in various formats
22981 @item vm-image
22982 @itemx disk-image
22983 @itemx docker-image
22984 Return a virtual machine, disk image, or Docker image of the operating
22985 system declared in @var{file} that stands alone. By default,
22986 @command{guix system} estimates the size of the image needed to store
22987 the system, but you can use the @option{--image-size} option to specify
22988 a value. Docker images are built to contain exactly what they need, so
22989 the @option{--image-size} option is ignored in the case of
22990 @code{docker-image}.
22991
22992 You can specify the root file system type by using the
22993 @option{--file-system-type} option. It defaults to @code{ext4}.
22994
22995 When using @code{vm-image}, the returned image is in qcow2 format, which
22996 the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
22997 for more information on how to run the image in a virtual machine.
22998
22999 When using @code{disk-image}, a raw disk image is produced; it can be
23000 copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
23001 the device corresponding to a USB stick, one can copy the image to it
23002 using the following command:
23003
23004 @example
23005 # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
23006 @end example
23007
23008 When using @code{docker-image}, a Docker image is produced. Guix builds
23009 the image from scratch, not from a pre-existing Docker base image. As a
23010 result, it contains @emph{exactly} what you define in the operating
23011 system configuration file. You can then load the image and launch a
23012 Docker container using commands like the following:
23013
23014 @example
23015 image_id="$(docker load < guixsd-docker-image.tar.gz)"
23016 docker run -e GUIX_NEW_SYSTEM=/var/guix/profiles/system \\
23017 --entrypoint /var/guix/profiles/system/profile/bin/guile \\
23018 $image_id /var/guix/profiles/system/boot
23019 @end example
23020
23021 This command starts a new Docker container from the specified image. It
23022 will boot the GuixSD system in the usual manner, which means it will
23023 start any services you have defined in the operating system
23024 configuration. Depending on what you run in the Docker container, it
23025 may be necessary to give the container additional permissions. For
23026 example, if you intend to build software using Guix inside of the Docker
23027 container, you may need to pass the @option{--privileged} option to
23028 @code{docker run}.
23029
23030 @item container
23031 Return a script to run the operating system declared in @var{file}
23032 within a container. Containers are a set of lightweight isolation
23033 mechanisms provided by the kernel Linux-libre. Containers are
23034 substantially less resource-demanding than full virtual machines since
23035 the kernel, shared objects, and other resources can be shared with the
23036 host system; this also means they provide thinner isolation.
23037
23038 Currently, the script must be run as root in order to support more than
23039 a single user and group. The container shares its store with the host
23040 system.
23041
23042 As with the @code{vm} action (@pxref{guix system vm}), additional file
23043 systems to be shared between the host and container can be specified
23044 using the @option{--share} and @option{--expose} options:
23045
23046 @example
23047 guix system container my-config.scm \
23048 --expose=$HOME --share=$HOME/tmp=/exchange
23049 @end example
23050
23051 @quotation Note
23052 This option requires Linux-libre 3.19 or newer.
23053 @end quotation
23054
23055 @end table
23056
23057 @var{options} can contain any of the common build options (@pxref{Common
23058 Build Options}). In addition, @var{options} can contain one of the
23059 following:
23060
23061 @table @option
23062 @item --expression=@var{expr}
23063 @itemx -e @var{expr}
23064 Consider the operating-system @var{expr} evaluates to.
23065 This is an alternative to specifying a file which evaluates to an
23066 operating system.
23067 This is used to generate the GuixSD installer @pxref{Building the
23068 Installation Image}).
23069
23070 @item --system=@var{system}
23071 @itemx -s @var{system}
23072 Attempt to build for @var{system} instead of the host system type.
23073 This works as per @command{guix build} (@pxref{Invoking guix build}).
23074
23075 @item --derivation
23076 @itemx -d
23077 Return the derivation file name of the given operating system without
23078 building anything.
23079
23080 @item --file-system-type=@var{type}
23081 @itemx -t @var{type}
23082 For the @code{disk-image} action, create a file system of the given
23083 @var{type} on the image.
23084
23085 When this option is omitted, @command{guix system} uses @code{ext4}.
23086
23087 @cindex ISO-9660 format
23088 @cindex CD image format
23089 @cindex DVD image format
23090 @code{--file-system-type=iso9660} produces an ISO-9660 image, suitable
23091 for burning on CDs and DVDs.
23092
23093 @item --image-size=@var{size}
23094 For the @code{vm-image} and @code{disk-image} actions, create an image
23095 of the given @var{size}. @var{size} may be a number of bytes, or it may
23096 include a unit as a suffix (@pxref{Block size, size specifications,,
23097 coreutils, GNU Coreutils}).
23098
23099 When this option is omitted, @command{guix system} computes an estimate
23100 of the image size as a function of the size of the system declared in
23101 @var{file}.
23102
23103 @item --root=@var{file}
23104 @itemx -r @var{file}
23105 Make @var{file} a symlink to the result, and register it as a garbage
23106 collector root.
23107
23108 @item --skip-checks
23109 Skip pre-installation safety checks.
23110
23111 By default, @command{guix system init} and @command{guix system
23112 reconfigure} perform safety checks: they make sure the file systems that
23113 appear in the @code{operating-system} declaration actually exist
23114 (@pxref{File Systems}), and that any Linux kernel modules that may be
23115 needed at boot time are listed in @code{initrd-modules} (@pxref{Initial
23116 RAM Disk}). Passing this option skips these tests altogether.
23117
23118 @cindex on-error
23119 @cindex on-error strategy
23120 @cindex error strategy
23121 @item --on-error=@var{strategy}
23122 Apply @var{strategy} when an error occurs when reading @var{file}.
23123 @var{strategy} may be one of the following:
23124
23125 @table @code
23126 @item nothing-special
23127 Report the error concisely and exit. This is the default strategy.
23128
23129 @item backtrace
23130 Likewise, but also display a backtrace.
23131
23132 @item debug
23133 Report the error and enter Guile's debugger. From there, you can run
23134 commands such as @code{,bt} to get a backtrace, @code{,locals} to
23135 display local variable values, and more generally inspect the state of the
23136 program. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
23137 a list of available debugging commands.
23138 @end table
23139 @end table
23140
23141 @quotation Note
23142 All the actions above, except @code{build} and @code{init},
23143 can use KVM support in the Linux-libre kernel. Specifically, if the
23144 machine has hardware virtualization support, the corresponding
23145 KVM kernel module should be loaded, and the @file{/dev/kvm} device node
23146 must exist and be readable and writable by the user and by the
23147 build users of the daemon (@pxref{Build Environment Setup}).
23148 @end quotation
23149
23150 Once you have built, configured, re-configured, and re-re-configured
23151 your GuixSD installation, you may find it useful to list the operating
23152 system generations available on disk---and that you can choose from the
23153 bootloader boot menu:
23154
23155 @table @code
23156
23157 @item list-generations
23158 List a summary of each generation of the operating system available on
23159 disk, in a human-readable way. This is similar to the
23160 @option{--list-generations} option of @command{guix package}
23161 (@pxref{Invoking guix package}).
23162
23163 Optionally, one can specify a pattern, with the same syntax that is used
23164 in @command{guix package --list-generations}, to restrict the list of
23165 generations displayed. For instance, the following command displays
23166 generations that are up to 10 days old:
23167
23168 @example
23169 $ guix system list-generations 10d
23170 @end example
23171
23172 @end table
23173
23174 The @command{guix system} command has even more to offer! The following
23175 sub-commands allow you to visualize how your system services relate to
23176 each other:
23177
23178 @anchor{system-extension-graph}
23179 @table @code
23180
23181 @item extension-graph
23182 Emit in Dot/Graphviz format to standard output the @dfn{service
23183 extension graph} of the operating system defined in @var{file}
23184 (@pxref{Service Composition}, for more information on service
23185 extensions.)
23186
23187 The command:
23188
23189 @example
23190 $ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
23191 @end example
23192
23193 produces a PDF file showing the extension relations among services.
23194
23195 @anchor{system-shepherd-graph}
23196 @item shepherd-graph
23197 Emit in Dot/Graphviz format to standard output the @dfn{dependency
23198 graph} of shepherd services of the operating system defined in
23199 @var{file}. @xref{Shepherd Services}, for more information and for an
23200 example graph.
23201
23202 @end table
23203
23204 @node Running GuixSD in a VM
23205 @subsection Running GuixSD in a Virtual Machine
23206
23207 @cindex virtual machine
23208 To run GuixSD in a virtual machine (VM), one can either use the
23209 pre-built GuixSD VM image distributed at
23210 @indicateurl{https://alpha.gnu.org/gnu/guix/guixsd-vm-image-@value{VERSION}.@var{system}.xz}
23211 , or build their own virtual machine image using @command{guix system
23212 vm-image} (@pxref{Invoking guix system}). The returned image is in
23213 qcow2 format, which the @uref{http://qemu.org/, QEMU emulator} can
23214 efficiently use.
23215
23216 @cindex QEMU
23217 If you built your own image, you must copy it out of the store
23218 (@pxref{The Store}) and give yourself permission to write to the copy
23219 before you can use it. When invoking QEMU, you must choose a system
23220 emulator that is suitable for your hardware platform. Here is a minimal
23221 QEMU invocation that will boot the result of @command{guix system
23222 vm-image} on x86_64 hardware:
23223
23224 @example
23225 $ qemu-system-x86_64 \
23226 -net user -net nic,model=virtio \
23227 -enable-kvm -m 256 /tmp/qemu-image
23228 @end example
23229
23230 Here is what each of these options means:
23231
23232 @table @code
23233 @item qemu-system-x86_64
23234 This specifies the hardware platform to emulate. This should match the
23235 host.
23236
23237 @item -net user
23238 Enable the unprivileged user-mode network stack. The guest OS can
23239 access the host but not vice versa. This is the simplest way to get the
23240 guest OS online.
23241
23242 @item -net nic,model=virtio
23243 You must create a network interface of a given model. If you do not
23244 create a NIC, the boot will fail. Assuming your hardware platform is
23245 x86_64, you can get a list of available NIC models by running
23246 @command{qemu-system-x86_64 -net nic,model=help}.
23247
23248 @item -enable-kvm
23249 If your system has hardware virtualization extensions, enabling the
23250 virtual machine support (KVM) of the Linux kernel will make things run
23251 faster.
23252
23253 @item -m 256
23254 RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
23255 which may be insufficient for some operations.
23256
23257 @item /tmp/qemu-image
23258 The file name of the qcow2 image.
23259 @end table
23260
23261 The default @command{run-vm.sh} script that is returned by an invocation of
23262 @command{guix system vm} does not add a @command{-net user} flag by default.
23263 To get network access from within the vm add the @code{(dhcp-client-service)}
23264 to your system definition and start the VM using
23265 @command{`guix system vm config.scm` -net user}. An important caveat of using
23266 @command{-net user} for networking is that @command{ping} will not work, because
23267 it uses the ICMP protocol. You'll have to use a different command to check for
23268 network connectivity, for example @command{guix download}.
23269
23270 @subsubsection Connecting Through SSH
23271
23272 @cindex SSH
23273 @cindex SSH server
23274 To enable SSH inside a VM you need to add a SSH server like @code{(dropbear-service)}
23275 or @code{(lsh-service)} to your VM. The @code{(lsh-service}) doesn't currently
23276 boot unsupervised. It requires you to type some characters to initialize the
23277 randomness generator. In addition you need to forward the SSH port, 22 by
23278 default, to the host. You can do this with
23279
23280 @example
23281 `guix system vm config.scm` -net user,hostfwd=tcp::10022-:22
23282 @end example
23283
23284 To connect to the VM you can run
23285
23286 @example
23287 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022
23288 @end example
23289
23290 The @command{-p} tells @command{ssh} the port you want to connect to.
23291 @command{-o UserKnownHostsFile=/dev/null} prevents @command{ssh} from complaining
23292 every time you modify your @command{config.scm} file and the
23293 @command{-o StrictHostKeyChecking=no} prevents you from having to allow a
23294 connection to an unknown host every time you connect.
23295
23296 @subsubsection Using @command{virt-viewer} with Spice
23297
23298 As an alternative to the default @command{qemu} graphical client you can
23299 use the @command{remote-viewer} from the @command{virt-viewer} package. To
23300 connect pass the @command{-spice port=5930,disable-ticketing} flag to
23301 @command{qemu}. See previous section for further information on how to do this.
23302
23303 Spice also allows you to do some nice stuff like share your clipboard with your
23304 VM. To enable that you'll also have to pass the following flags to @command{qemu}:
23305
23306 @example
23307 -device virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0,addr=0x5
23308 -chardev spicevmc,name=vdagent,id=vdagent
23309 -device virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,
23310 name=com.redhat.spice.0
23311 @end example
23312
23313 You'll also need to add the @pxref{Miscellaneous Services, Spice service}.
23314
23315 @node Defining Services
23316 @subsection Defining Services
23317
23318 The previous sections show the available services and how one can combine
23319 them in an @code{operating-system} declaration. But how do we define
23320 them in the first place? And what is a service anyway?
23321
23322 @menu
23323 * Service Composition:: The model for composing services.
23324 * Service Types and Services:: Types and services.
23325 * Service Reference:: API reference.
23326 * Shepherd Services:: A particular type of service.
23327 @end menu
23328
23329 @node Service Composition
23330 @subsubsection Service Composition
23331
23332 @cindex services
23333 @cindex daemons
23334 Here we define a @dfn{service} as, broadly, something that extends the
23335 functionality of the operating system. Often a service is a process---a
23336 @dfn{daemon}---started when the system boots: a secure shell server, a
23337 Web server, the Guix build daemon, etc. Sometimes a service is a daemon
23338 whose execution can be triggered by another daemon---e.g., an FTP server
23339 started by @command{inetd} or a D-Bus service activated by
23340 @command{dbus-daemon}. Occasionally, a service does not map to a
23341 daemon. For instance, the ``account'' service collects user accounts
23342 and makes sure they exist when the system runs; the ``udev'' service
23343 collects device management rules and makes them available to the eudev
23344 daemon; the @file{/etc} service populates the @file{/etc} directory
23345 of the system.
23346
23347 @cindex service extensions
23348 GuixSD services are connected by @dfn{extensions}. For instance, the
23349 secure shell service @emph{extends} the Shepherd---the GuixSD
23350 initialization system, running as PID@tie{}1---by giving it the command
23351 lines to start and stop the secure shell daemon (@pxref{Networking
23352 Services, @code{lsh-service}}); the UPower service extends the D-Bus
23353 service by passing it its @file{.service} specification, and extends the
23354 udev service by passing it device management rules (@pxref{Desktop
23355 Services, @code{upower-service}}); the Guix daemon service extends the
23356 Shepherd by passing it the command lines to start and stop the daemon,
23357 and extends the account service by passing it a list of required build
23358 user accounts (@pxref{Base Services}).
23359
23360 All in all, services and their ``extends'' relations form a directed
23361 acyclic graph (DAG). If we represent services as boxes and extensions
23362 as arrows, a typical system might provide something like this:
23363
23364 @image{images/service-graph,,5in,Typical service extension graph.}
23365
23366 @cindex system service
23367 At the bottom, we see the @dfn{system service}, which produces the
23368 directory containing everything to run and boot the system, as returned
23369 by the @command{guix system build} command. @xref{Service Reference},
23370 to learn about the other service types shown here.
23371 @xref{system-extension-graph, the @command{guix system extension-graph}
23372 command}, for information on how to generate this representation for a
23373 particular operating system definition.
23374
23375 @cindex service types
23376 Technically, developers can define @dfn{service types} to express these
23377 relations. There can be any number of services of a given type on the
23378 system---for instance, a system running two instances of the GNU secure
23379 shell server (lsh) has two instances of @var{lsh-service-type}, with
23380 different parameters.
23381
23382 The following section describes the programming interface for service
23383 types and services.
23384
23385 @node Service Types and Services
23386 @subsubsection Service Types and Services
23387
23388 A @dfn{service type} is a node in the DAG described above. Let us start
23389 with a simple example, the service type for the Guix build daemon
23390 (@pxref{Invoking guix-daemon}):
23391
23392 @example
23393 (define guix-service-type
23394 (service-type
23395 (name 'guix)
23396 (extensions
23397 (list (service-extension shepherd-root-service-type guix-shepherd-service)
23398 (service-extension account-service-type guix-accounts)
23399 (service-extension activation-service-type guix-activation)))
23400 (default-value (guix-configuration))))
23401 @end example
23402
23403 @noindent
23404 It defines three things:
23405
23406 @enumerate
23407 @item
23408 A name, whose sole purpose is to make inspection and debugging easier.
23409
23410 @item
23411 A list of @dfn{service extensions}, where each extension designates the
23412 target service type and a procedure that, given the parameters of the
23413 service, returns a list of objects to extend the service of that type.
23414
23415 Every service type has at least one service extension. The only
23416 exception is the @dfn{boot service type}, which is the ultimate service.
23417
23418 @item
23419 Optionally, a default value for instances of this type.
23420 @end enumerate
23421
23422 In this example, @var{guix-service-type} extends three services:
23423
23424 @table @var
23425 @item shepherd-root-service-type
23426 The @var{guix-shepherd-service} procedure defines how the Shepherd
23427 service is extended. Namely, it returns a @code{<shepherd-service>}
23428 object that defines how @command{guix-daemon} is started and stopped
23429 (@pxref{Shepherd Services}).
23430
23431 @item account-service-type
23432 This extension for this service is computed by @var{guix-accounts},
23433 which returns a list of @code{user-group} and @code{user-account}
23434 objects representing the build user accounts (@pxref{Invoking
23435 guix-daemon}).
23436
23437 @item activation-service-type
23438 Here @var{guix-activation} is a procedure that returns a gexp, which is
23439 a code snippet to run at ``activation time''---e.g., when the service is
23440 booted.
23441 @end table
23442
23443 A service of this type is instantiated like this:
23444
23445 @example
23446 (service guix-service-type
23447 (guix-configuration
23448 (build-accounts 5)
23449 (use-substitutes? #f)))
23450 @end example
23451
23452 The second argument to the @code{service} form is a value representing
23453 the parameters of this specific service instance.
23454 @xref{guix-configuration-type, @code{guix-configuration}}, for
23455 information about the @code{guix-configuration} data type. When the
23456 value is omitted, the default value specified by
23457 @code{guix-service-type} is used:
23458
23459 @example
23460 (service guix-service-type)
23461 @end example
23462
23463 @var{guix-service-type} is quite simple because it extends other
23464 services but is not extensible itself.
23465
23466 @c @subsubsubsection Extensible Service Types
23467
23468 The service type for an @emph{extensible} service looks like this:
23469
23470 @example
23471 (define udev-service-type
23472 (service-type (name 'udev)
23473 (extensions
23474 (list (service-extension shepherd-root-service-type
23475 udev-shepherd-service)))
23476
23477 (compose concatenate) ;concatenate the list of rules
23478 (extend (lambda (config rules)
23479 (match config
23480 (($ <udev-configuration> udev initial-rules)
23481 (udev-configuration
23482 (udev udev) ;the udev package to use
23483 (rules (append initial-rules rules)))))))))
23484 @end example
23485
23486 This is the service type for the
23487 @uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
23488 management daemon}. Compared to the previous example, in addition to an
23489 extension of @var{shepherd-root-service-type}, we see two new fields:
23490
23491 @table @code
23492 @item compose
23493 This is the procedure to @dfn{compose} the list of extensions to
23494 services of this type.
23495
23496 Services can extend the udev service by passing it lists of rules; we
23497 compose those extensions simply by concatenating them.
23498
23499 @item extend
23500 This procedure defines how the value of the service is @dfn{extended} with
23501 the composition of the extensions.
23502
23503 Udev extensions are composed into a list of rules, but the udev service
23504 value is itself a @code{<udev-configuration>} record. So here, we
23505 extend that record by appending the list of rules it contains to the
23506 list of contributed rules.
23507
23508 @item description
23509 This is a string giving an overview of the service type. The string can
23510 contain Texinfo markup (@pxref{Overview,,, texinfo, GNU Texinfo}). The
23511 @command{guix system search} command searches these strings and displays
23512 them (@pxref{Invoking guix system}).
23513 @end table
23514
23515 There can be only one instance of an extensible service type such as
23516 @var{udev-service-type}. If there were more, the
23517 @code{service-extension} specifications would be ambiguous.
23518
23519 Still here? The next section provides a reference of the programming
23520 interface for services.
23521
23522 @node Service Reference
23523 @subsubsection Service Reference
23524
23525 We have seen an overview of service types (@pxref{Service Types and
23526 Services}). This section provides a reference on how to manipulate
23527 services and service types. This interface is provided by the
23528 @code{(gnu services)} module.
23529
23530 @deffn {Scheme Procedure} service @var{type} [@var{value}]
23531 Return a new service of @var{type}, a @code{<service-type>} object (see
23532 below.) @var{value} can be any object; it represents the parameters of
23533 this particular service instance.
23534
23535 When @var{value} is omitted, the default value specified by @var{type}
23536 is used; if @var{type} does not specify a default value, an error is
23537 raised.
23538
23539 For instance, this:
23540
23541 @example
23542 (service openssh-service-type)
23543 @end example
23544
23545 @noindent
23546 is equivalent to this:
23547
23548 @example
23549 (service openssh-service-type
23550 (openssh-configuration))
23551 @end example
23552
23553 In both cases the result is an instance of @code{openssh-service-type}
23554 with the default configuration.
23555 @end deffn
23556
23557 @deffn {Scheme Procedure} service? @var{obj}
23558 Return true if @var{obj} is a service.
23559 @end deffn
23560
23561 @deffn {Scheme Procedure} service-kind @var{service}
23562 Return the type of @var{service}---i.e., a @code{<service-type>} object.
23563 @end deffn
23564
23565 @deffn {Scheme Procedure} service-value @var{service}
23566 Return the value associated with @var{service}. It represents its
23567 parameters.
23568 @end deffn
23569
23570 Here is an example of how a service is created and manipulated:
23571
23572 @example
23573 (define s
23574 (service nginx-service-type
23575 (nginx-configuration
23576 (nginx nginx)
23577 (log-directory log-directory)
23578 (run-directory run-directory)
23579 (file config-file))))
23580
23581 (service? s)
23582 @result{} #t
23583
23584 (eq? (service-kind s) nginx-service-type)
23585 @result{} #t
23586 @end example
23587
23588 The @code{modify-services} form provides a handy way to change the
23589 parameters of some of the services of a list such as
23590 @var{%base-services} (@pxref{Base Services, @code{%base-services}}). It
23591 evaluates to a list of services. Of course, you could always use
23592 standard list combinators such as @code{map} and @code{fold} to do that
23593 (@pxref{SRFI-1, List Library,, guile, GNU Guile Reference Manual});
23594 @code{modify-services} simply provides a more concise form for this
23595 common pattern.
23596
23597 @deffn {Scheme Syntax} modify-services @var{services} @
23598 (@var{type} @var{variable} => @var{body}) @dots{}
23599
23600 Modify the services listed in @var{services} according to the given
23601 clauses. Each clause has the form:
23602
23603 @example
23604 (@var{type} @var{variable} => @var{body})
23605 @end example
23606
23607 where @var{type} is a service type---e.g.,
23608 @code{guix-service-type}---and @var{variable} is an identifier that is
23609 bound within the @var{body} to the service parameters---e.g., a
23610 @code{guix-configuration} instance---of the original service of that
23611 @var{type}.
23612
23613 The @var{body} should evaluate to the new service parameters, which will
23614 be used to configure the new service. This new service will replace the
23615 original in the resulting list. Because a service's service parameters
23616 are created using @code{define-record-type*}, you can write a succinct
23617 @var{body} that evaluates to the new service parameters by using the
23618 @code{inherit} feature that @code{define-record-type*} provides.
23619
23620 @xref{Using the Configuration System}, for example usage.
23621
23622 @end deffn
23623
23624 Next comes the programming interface for service types. This is
23625 something you want to know when writing new service definitions, but not
23626 necessarily when simply looking for ways to customize your
23627 @code{operating-system} declaration.
23628
23629 @deftp {Data Type} service-type
23630 @cindex service type
23631 This is the representation of a @dfn{service type} (@pxref{Service Types
23632 and Services}).
23633
23634 @table @asis
23635 @item @code{name}
23636 This is a symbol, used only to simplify inspection and debugging.
23637
23638 @item @code{extensions}
23639 A non-empty list of @code{<service-extension>} objects (see below).
23640
23641 @item @code{compose} (default: @code{#f})
23642 If this is @code{#f}, then the service type denotes services that cannot
23643 be extended---i.e., services that do not receive ``values'' from other
23644 services.
23645
23646 Otherwise, it must be a one-argument procedure. The procedure is called
23647 by @code{fold-services} and is passed a list of values collected from
23648 extensions. It may return any single value.
23649
23650 @item @code{extend} (default: @code{#f})
23651 If this is @code{#f}, services of this type cannot be extended.
23652
23653 Otherwise, it must be a two-argument procedure: @code{fold-services}
23654 calls it, passing it the initial value of the service as the first
23655 argument and the result of applying @code{compose} to the extension
23656 values as the second argument. It must return a value that is a valid
23657 parameter value for the service instance.
23658 @end table
23659
23660 @xref{Service Types and Services}, for examples.
23661 @end deftp
23662
23663 @deffn {Scheme Procedure} service-extension @var{target-type} @
23664 @var{compute}
23665 Return a new extension for services of type @var{target-type}.
23666 @var{compute} must be a one-argument procedure: @code{fold-services}
23667 calls it, passing it the value associated with the service that provides
23668 the extension; it must return a valid value for the target service.
23669 @end deffn
23670
23671 @deffn {Scheme Procedure} service-extension? @var{obj}
23672 Return true if @var{obj} is a service extension.
23673 @end deffn
23674
23675 Occasionally, you might want to simply extend an existing service. This
23676 involves creating a new service type and specifying the extension of
23677 interest, which can be verbose; the @code{simple-service} procedure
23678 provides a shorthand for this.
23679
23680 @deffn {Scheme Procedure} simple-service @var{name} @var{target} @var{value}
23681 Return a service that extends @var{target} with @var{value}. This works
23682 by creating a singleton service type @var{name}, of which the returned
23683 service is an instance.
23684
23685 For example, this extends mcron (@pxref{Scheduled Job Execution}) with
23686 an additional job:
23687
23688 @example
23689 (simple-service 'my-mcron-job mcron-service-type
23690 #~(job '(next-hour (3)) "guix gc -F 2G"))
23691 @end example
23692 @end deffn
23693
23694 At the core of the service abstraction lies the @code{fold-services}
23695 procedure, which is responsible for ``compiling'' a list of services
23696 down to a single directory that contains everything needed to boot and
23697 run the system---the directory shown by the @command{guix system build}
23698 command (@pxref{Invoking guix system}). In essence, it propagates
23699 service extensions down the service graph, updating each node parameters
23700 on the way, until it reaches the root node.
23701
23702 @deffn {Scheme Procedure} fold-services @var{services} @
23703 [#:target-type @var{system-service-type}]
23704 Fold @var{services} by propagating their extensions down to the root of
23705 type @var{target-type}; return the root service adjusted accordingly.
23706 @end deffn
23707
23708 Lastly, the @code{(gnu services)} module also defines several essential
23709 service types, some of which are listed below.
23710
23711 @defvr {Scheme Variable} system-service-type
23712 This is the root of the service graph. It produces the system directory
23713 as returned by the @command{guix system build} command.
23714 @end defvr
23715
23716 @defvr {Scheme Variable} boot-service-type
23717 The type of the ``boot service'', which produces the @dfn{boot script}.
23718 The boot script is what the initial RAM disk runs when booting.
23719 @end defvr
23720
23721 @defvr {Scheme Variable} etc-service-type
23722 The type of the @file{/etc} service. This service is used to create
23723 files under @file{/etc} and can be extended by
23724 passing it name/file tuples such as:
23725
23726 @example
23727 (list `("issue" ,(plain-file "issue" "Welcome!\n")))
23728 @end example
23729
23730 In this example, the effect would be to add an @file{/etc/issue} file
23731 pointing to the given file.
23732 @end defvr
23733
23734 @defvr {Scheme Variable} setuid-program-service-type
23735 Type for the ``setuid-program service''. This service collects lists of
23736 executable file names, passed as gexps, and adds them to the set of
23737 setuid-root programs on the system (@pxref{Setuid Programs}).
23738 @end defvr
23739
23740 @defvr {Scheme Variable} profile-service-type
23741 Type of the service that populates the @dfn{system profile}---i.e., the
23742 programs under @file{/run/current-system/profile}. Other services can
23743 extend it by passing it lists of packages to add to the system profile.
23744 @end defvr
23745
23746
23747 @node Shepherd Services
23748 @subsubsection Shepherd Services
23749
23750 @cindex shepherd services
23751 @cindex PID 1
23752 @cindex init system
23753 The @code{(gnu services shepherd)} module provides a way to define
23754 services managed by the GNU@tie{}Shepherd, which is the GuixSD
23755 initialization system---the first process that is started when the
23756 system boots, also known as PID@tie{}1
23757 (@pxref{Introduction,,, shepherd, The GNU Shepherd Manual}).
23758
23759 Services in the Shepherd can depend on each other. For instance, the
23760 SSH daemon may need to be started after the syslog daemon has been
23761 started, which in turn can only happen once all the file systems have
23762 been mounted. The simple operating system defined earlier (@pxref{Using
23763 the Configuration System}) results in a service graph like this:
23764
23765 @image{images/shepherd-graph,,5in,Typical shepherd service graph.}
23766
23767 You can actually generate such a graph for any operating system
23768 definition using the @command{guix system shepherd-graph} command
23769 (@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
23770
23771 The @var{%shepherd-root-service} is a service object representing
23772 PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
23773 by passing it lists of @code{<shepherd-service>} objects.
23774
23775 @deftp {Data Type} shepherd-service
23776 The data type representing a service managed by the Shepherd.
23777
23778 @table @asis
23779 @item @code{provision}
23780 This is a list of symbols denoting what the service provides.
23781
23782 These are the names that may be passed to @command{herd start},
23783 @command{herd status}, and similar commands (@pxref{Invoking herd,,,
23784 shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
23785 @code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
23786
23787 @item @code{requirements} (default: @code{'()})
23788 List of symbols denoting the Shepherd services this one depends on.
23789
23790 @item @code{respawn?} (default: @code{#t})
23791 Whether to restart the service when it stops, for instance when the
23792 underlying process dies.
23793
23794 @item @code{start}
23795 @itemx @code{stop} (default: @code{#~(const #f)})
23796 The @code{start} and @code{stop} fields refer to the Shepherd's
23797 facilities to start and stop processes (@pxref{Service De- and
23798 Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
23799 G-expressions that get expanded in the Shepherd configuration file
23800 (@pxref{G-Expressions}).
23801
23802 @item @code{actions} (default: @code{'()})
23803 @cindex actions, of Shepherd services
23804 This is a list of @code{shepherd-action} objects (see below) defining
23805 @dfn{actions} supported by the service, in addition to the standard
23806 @code{start} and @code{stop} actions. Actions listed here become available as
23807 @command{herd} sub-commands:
23808
23809 @example
23810 herd @var{action} @var{service} [@var{arguments}@dots{}]
23811 @end example
23812
23813 @item @code{documentation}
23814 A documentation string, as shown when running:
23815
23816 @example
23817 herd doc @var{service-name}
23818 @end example
23819
23820 where @var{service-name} is one of the symbols in @var{provision}
23821 (@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
23822
23823 @item @code{modules} (default: @var{%default-modules})
23824 This is the list of modules that must be in scope when @code{start} and
23825 @code{stop} are evaluated.
23826
23827 @end table
23828 @end deftp
23829
23830 @deftp {Data Type} shepherd-action
23831 This is the data type that defines additional actions implemented by a
23832 Shepherd service (see above).
23833
23834 @table @code
23835 @item name
23836 Symbol naming the action.
23837
23838 @item documentation
23839 This is a documentation string for the action. It can be viewed by running:
23840
23841 @example
23842 herd doc @var{service} action @var{action}
23843 @end example
23844
23845 @item procedure
23846 This should be a gexp that evaluates to a procedure of at least one argument,
23847 which is the ``running value'' of the service (@pxref{Slots of services,,,
23848 shepherd, The GNU Shepherd Manual}).
23849 @end table
23850
23851 The following example defines an action called @code{say-hello} that kindly
23852 greets the user:
23853
23854 @example
23855 (shepherd-action
23856 (name 'say-hello)
23857 (documentation "Say hi!")
23858 (procedure #~(lambda (running . args)
23859 (format #t "Hello, friend! arguments: ~s\n"
23860 args)
23861 #t)))
23862 @end example
23863
23864 Assuming this action is added to the @code{example} service, then you can do:
23865
23866 @example
23867 # herd say-hello example
23868 Hello, friend! arguments: ()
23869 # herd say-hello example a b c
23870 Hello, friend! arguments: ("a" "b" "c")
23871 @end example
23872
23873 This, as you can see, is a fairly sophisticated way to say hello.
23874 @xref{Service Convenience,,, shepherd, The GNU Shepherd Manual}, for more
23875 info on actions.
23876 @end deftp
23877
23878 @defvr {Scheme Variable} shepherd-root-service-type
23879 The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
23880
23881 This is the service type that extensions target when they want to create
23882 shepherd services (@pxref{Service Types and Services}, for an example).
23883 Each extension must pass a list of @code{<shepherd-service>}.
23884 @end defvr
23885
23886 @defvr {Scheme Variable} %shepherd-root-service
23887 This service represents PID@tie{}1.
23888 @end defvr
23889
23890
23891 @node Documentation
23892 @section Documentation
23893
23894 @cindex documentation, searching for
23895 @cindex searching for documentation
23896 @cindex Info, documentation format
23897 @cindex man pages
23898 @cindex manual pages
23899 In most cases packages installed with Guix come with documentation.
23900 There are two main documentation formats: ``Info'', a browseable
23901 hypertext format used for GNU software, and ``manual pages'' (or ``man
23902 pages''), the linear documentation format traditionally found on Unix.
23903 Info manuals are accessed with the @command{info} command or with Emacs,
23904 and man pages are accessed using @command{man}.
23905
23906 You can look for documentation of software installed on your system by
23907 keyword. For example, the following command searches for information
23908 about ``TLS'' in Info manuals:
23909
23910 @example
23911 $ info -k TLS
23912 "(emacs)Network Security" -- STARTTLS
23913 "(emacs)Network Security" -- TLS
23914 "(gnutls)Core TLS API" -- gnutls_certificate_set_verify_flags
23915 "(gnutls)Core TLS API" -- gnutls_certificate_set_verify_function
23916 @dots{}
23917 @end example
23918
23919 @noindent
23920 The command below searches for the same keyword in man pages:
23921
23922 @example
23923 $ man -k TLS
23924 SSL (7) - OpenSSL SSL/TLS library
23925 certtool (1) - GnuTLS certificate tool
23926 @dots {}
23927 @end example
23928
23929 These searches are purely local to your computer so you have the
23930 guarantee that documentation you find corresponds to what you have
23931 actually installed, you can access it off-line, and your privacy is
23932 respected.
23933
23934 Once you have these results, you can view the relevant documentation by
23935 running, say:
23936
23937 @example
23938 $ info "(gnutls)Core TLS API"
23939 @end example
23940
23941 @noindent
23942 or:
23943
23944 @example
23945 $ man certtool
23946 @end example
23947
23948 Info manuals contain sections and indices as well as hyperlinks like
23949 those found in Web pages. The @command{info} reader (@pxref{Top, Info
23950 reader,, info-stnd, Stand-alone GNU Info}) and its Emacs counterpart
23951 (@pxref{Misc Help,,, emacs, The GNU Emacs Manual}) provide intuitive key
23952 bindings to navigate manuals. @xref{Getting Started,,, info, Info: An
23953 Introduction}, for an introduction to Info navigation.
23954
23955 @node Installing Debugging Files
23956 @section Installing Debugging Files
23957
23958 @cindex debugging files
23959 Program binaries, as produced by the GCC compilers for instance, are
23960 typically written in the ELF format, with a section containing
23961 @dfn{debugging information}. Debugging information is what allows the
23962 debugger, GDB, to map binary code to source code; it is required to
23963 debug a compiled program in good conditions.
23964
23965 The problem with debugging information is that is takes up a fair amount
23966 of disk space. For example, debugging information for the GNU C Library
23967 weighs in at more than 60 MiB. Thus, as a user, keeping all the
23968 debugging info of all the installed programs is usually not an option.
23969 Yet, space savings should not come at the cost of an impediment to
23970 debugging---especially in the GNU system, which should make it easier
23971 for users to exert their computing freedom (@pxref{GNU Distribution}).
23972
23973 Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
23974 mechanism that allows users to get the best of both worlds: debugging
23975 information can be stripped from the binaries and stored in separate
23976 files. GDB is then able to load debugging information from those files,
23977 when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
23978 with GDB}).
23979
23980 The GNU distribution takes advantage of this by storing debugging
23981 information in the @code{lib/debug} sub-directory of a separate package
23982 output unimaginatively called @code{debug} (@pxref{Packages with
23983 Multiple Outputs}). Users can choose to install the @code{debug} output
23984 of a package when they need it. For instance, the following command
23985 installs the debugging information for the GNU C Library and for GNU
23986 Guile:
23987
23988 @example
23989 guix package -i glibc:debug guile:debug
23990 @end example
23991
23992 GDB must then be told to look for debug files in the user's profile, by
23993 setting the @code{debug-file-directory} variable (consider setting it
23994 from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
23995 GDB}):
23996
23997 @example
23998 (gdb) set debug-file-directory ~/.guix-profile/lib/debug
23999 @end example
24000
24001 From there on, GDB will pick up debugging information from the
24002 @code{.debug} files under @file{~/.guix-profile/lib/debug}.
24003
24004 In addition, you will most likely want GDB to be able to show the source
24005 code being debugged. To do that, you will have to unpack the source
24006 code of the package of interest (obtained with @code{guix build
24007 --source}, @pxref{Invoking guix build}), and to point GDB to that source
24008 directory using the @code{directory} command (@pxref{Source Path,
24009 @code{directory},, gdb, Debugging with GDB}).
24010
24011 @c XXX: keep me up-to-date
24012 The @code{debug} output mechanism in Guix is implemented by the
24013 @code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
24014 opt-in---debugging information is available only for the packages
24015 with definitions explicitly declaring a @code{debug} output. This may be
24016 changed to opt-out in the future if our build farm servers can handle
24017 the load. To check whether a package has a @code{debug} output, use
24018 @command{guix package --list-available} (@pxref{Invoking guix package}).
24019
24020
24021 @node Security Updates
24022 @section Security Updates
24023
24024 @cindex security updates
24025 @cindex security vulnerabilities
24026 Occasionally, important security vulnerabilities are discovered in software
24027 packages and must be patched. Guix developers try hard to keep track of
24028 known vulnerabilities and to apply fixes as soon as possible in the
24029 @code{master} branch of Guix (we do not yet provide a ``stable'' branch
24030 containing only security updates.) The @command{guix lint} tool helps
24031 developers find out about vulnerable versions of software packages in the
24032 distribution:
24033
24034 @smallexample
24035 $ guix lint -c cve
24036 gnu/packages/base.scm:652:2: glibc@@2.21: probably vulnerable to CVE-2015-1781, CVE-2015-7547
24037 gnu/packages/gcc.scm:334:2: gcc@@4.9.3: probably vulnerable to CVE-2015-5276
24038 gnu/packages/image.scm:312:2: openjpeg@@2.1.0: probably vulnerable to CVE-2016-1923, CVE-2016-1924
24039 @dots{}
24040 @end smallexample
24041
24042 @xref{Invoking guix lint}, for more information.
24043
24044 @quotation Note
24045 As of version @value{VERSION}, the feature described below is considered
24046 ``beta''.
24047 @end quotation
24048
24049 Guix follows a functional
24050 package management discipline (@pxref{Introduction}), which implies
24051 that, when a package is changed, @emph{every package that depends on it}
24052 must be rebuilt. This can significantly slow down the deployment of
24053 fixes in core packages such as libc or Bash, since basically the whole
24054 distribution would need to be rebuilt. Using pre-built binaries helps
24055 (@pxref{Substitutes}), but deployment may still take more time than
24056 desired.
24057
24058 @cindex grafts
24059 To address this, Guix implements @dfn{grafts}, a mechanism that allows
24060 for fast deployment of critical updates without the costs associated
24061 with a whole-distribution rebuild. The idea is to rebuild only the
24062 package that needs to be patched, and then to ``graft'' it onto packages
24063 explicitly installed by the user and that were previously referring to
24064 the original package. The cost of grafting is typically very low, and
24065 order of magnitudes lower than a full rebuild of the dependency chain.
24066
24067 @cindex replacements of packages, for grafts
24068 For instance, suppose a security update needs to be applied to Bash.
24069 Guix developers will provide a package definition for the ``fixed''
24070 Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
24071 Packages}). Then, the original package definition is augmented with a
24072 @code{replacement} field pointing to the package containing the bug fix:
24073
24074 @example
24075 (define bash
24076 (package
24077 (name "bash")
24078 ;; @dots{}
24079 (replacement bash-fixed)))
24080 @end example
24081
24082 From there on, any package depending directly or indirectly on Bash---as
24083 reported by @command{guix gc --requisites} (@pxref{Invoking guix
24084 gc})---that is installed is automatically ``rewritten'' to refer to
24085 @var{bash-fixed} instead of @var{bash}. This grafting process takes
24086 time proportional to the size of the package, usually less than a
24087 minute for an ``average'' package on a recent machine. Grafting is
24088 recursive: when an indirect dependency requires grafting, then grafting
24089 ``propagates'' up to the package that the user is installing.
24090
24091 Currently, the length of the name and version of the graft and that of
24092 the package it replaces (@var{bash-fixed} and @var{bash} in the example
24093 above) must be equal. This restriction mostly comes from the fact that
24094 grafting works by patching files, including binary files, directly.
24095 Other restrictions may apply: for instance, when adding a graft to a
24096 package providing a shared library, the original shared library and its
24097 replacement must have the same @code{SONAME} and be binary-compatible.
24098
24099 The @option{--no-grafts} command-line option allows you to forcefully
24100 avoid grafting (@pxref{Common Build Options, @option{--no-grafts}}).
24101 Thus, the command:
24102
24103 @example
24104 guix build bash --no-grafts
24105 @end example
24106
24107 @noindent
24108 returns the store file name of the original Bash, whereas:
24109
24110 @example
24111 guix build bash
24112 @end example
24113
24114 @noindent
24115 returns the store file name of the ``fixed'', replacement Bash. This
24116 allows you to distinguish between the two variants of Bash.
24117
24118 To verify which Bash your whole profile refers to, you can run
24119 (@pxref{Invoking guix gc}):
24120
24121 @example
24122 guix gc -R `readlink -f ~/.guix-profile` | grep bash
24123 @end example
24124
24125 @noindent
24126 @dots{} and compare the store file names that you get with those above.
24127 Likewise for a complete GuixSD system generation:
24128
24129 @example
24130 guix gc -R `guix system build my-config.scm` | grep bash
24131 @end example
24132
24133 Lastly, to check which Bash running processes are using, you can use the
24134 @command{lsof} command:
24135
24136 @example
24137 lsof | grep /gnu/store/.*bash
24138 @end example
24139
24140
24141 @node Package Modules
24142 @section Package Modules
24143
24144 From a programming viewpoint, the package definitions of the
24145 GNU distribution are provided by Guile modules in the @code{(gnu packages
24146 @dots{})} name space@footnote{Note that packages under the @code{(gnu
24147 packages @dots{})} module name space are not necessarily ``GNU
24148 packages''. This module naming scheme follows the usual Guile module
24149 naming convention: @code{gnu} means that these modules are distributed
24150 as part of the GNU system, and @code{packages} identifies modules that
24151 define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
24152 Reference Manual}). For instance, the @code{(gnu packages emacs)}
24153 module exports a variable named @code{emacs}, which is bound to a
24154 @code{<package>} object (@pxref{Defining Packages}).
24155
24156 The @code{(gnu packages @dots{})} module name space is
24157 automatically scanned for packages by the command-line tools. For
24158 instance, when running @code{guix package -i emacs}, all the @code{(gnu
24159 packages @dots{})} modules are scanned until one that exports a package
24160 object whose name is @code{emacs} is found. This package search
24161 facility is implemented in the @code{(gnu packages)} module.
24162
24163 @cindex customization, of packages
24164 @cindex package module search path
24165 Users can store package definitions in modules with different
24166 names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
24167 name and module name must match. For instance, the @code{(my-packages
24168 emacs)} module must be stored in a @file{my-packages/emacs.scm} file
24169 relative to the load path specified with @option{--load-path} or
24170 @code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
24171 guile, GNU Guile Reference Manual}, for details.}. There are two ways to make
24172 these package definitions visible to the user interfaces:
24173
24174 @enumerate
24175 @item
24176 By adding the directory containing your package modules to the search path
24177 with the @code{-L} flag of @command{guix package} and other commands
24178 (@pxref{Common Build Options}), or by setting the @code{GUIX_PACKAGE_PATH}
24179 environment variable described below.
24180
24181 @item
24182 By defining a @dfn{channel} and configuring @command{guix pull} so that it
24183 pulls from it. A channel is essentially a Git repository containing package
24184 modules. @xref{Channels}, for more information on how to define and use
24185 channels.
24186 @end enumerate
24187
24188 @code{GUIX_PACKAGE_PATH} works similarly to other search path variables:
24189
24190 @defvr {Environment Variable} GUIX_PACKAGE_PATH
24191 This is a colon-separated list of directories to search for additional
24192 package modules. Directories listed in this variable take precedence
24193 over the own modules of the distribution.
24194 @end defvr
24195
24196 The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
24197 each package is built based solely on other packages in the
24198 distribution. The root of this dependency graph is a small set of
24199 @dfn{bootstrap binaries}, provided by the @code{(gnu packages
24200 bootstrap)} module. For more information on bootstrapping,
24201 @pxref{Bootstrapping}.
24202
24203 @node Packaging Guidelines
24204 @section Packaging Guidelines
24205
24206 @cindex packages, creating
24207 The GNU distribution is nascent and may well lack some of your favorite
24208 packages. This section describes how you can help make the distribution
24209 grow. @xref{Contributing}, for additional information on how you can
24210 help.
24211
24212 Free software packages are usually distributed in the form of
24213 @dfn{source code tarballs}---typically @file{tar.gz} files that contain
24214 all the source files. Adding a package to the distribution means
24215 essentially two things: adding a @dfn{recipe} that describes how to
24216 build the package, including a list of other packages required to build
24217 it, and adding @dfn{package metadata} along with that recipe, such as a
24218 description and licensing information.
24219
24220 In Guix all this information is embodied in @dfn{package definitions}.
24221 Package definitions provide a high-level view of the package. They are
24222 written using the syntax of the Scheme programming language; in fact,
24223 for each package we define a variable bound to the package definition,
24224 and export that variable from a module (@pxref{Package Modules}).
24225 However, in-depth Scheme knowledge is @emph{not} a prerequisite for
24226 creating packages. For more information on package definitions,
24227 @pxref{Defining Packages}.
24228
24229 Once a package definition is in place, stored in a file in the Guix
24230 source tree, it can be tested using the @command{guix build} command
24231 (@pxref{Invoking guix build}). For example, assuming the new package is
24232 called @code{gnew}, you may run this command from the Guix build tree
24233 (@pxref{Running Guix Before It Is Installed}):
24234
24235 @example
24236 ./pre-inst-env guix build gnew --keep-failed
24237 @end example
24238
24239 Using @code{--keep-failed} makes it easier to debug build failures since
24240 it provides access to the failed build tree. Another useful
24241 command-line option when debugging is @code{--log-file}, to access the
24242 build log.
24243
24244 If the package is unknown to the @command{guix} command, it may be that
24245 the source file contains a syntax error, or lacks a @code{define-public}
24246 clause to export the package variable. To figure it out, you may load
24247 the module from Guile to get more information about the actual error:
24248
24249 @example
24250 ./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
24251 @end example
24252
24253 Once your package builds correctly, please send us a patch
24254 (@pxref{Contributing}). Well, if you need help, we will be happy to
24255 help you too. Once the patch is committed in the Guix repository, the
24256 new package automatically gets built on the supported platforms by
24257 @url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
24258 system}.
24259
24260 @cindex substituter
24261 Users can obtain the new package definition simply by running
24262 @command{guix pull} (@pxref{Invoking guix pull}). When
24263 @code{@value{SUBSTITUTE-SERVER}} is done building the package, installing the
24264 package automatically downloads binaries from there
24265 (@pxref{Substitutes}). The only place where human intervention is
24266 needed is to review and apply the patch.
24267
24268
24269 @menu
24270 * Software Freedom:: What may go into the distribution.
24271 * Package Naming:: What's in a name?
24272 * Version Numbers:: When the name is not enough.
24273 * Synopses and Descriptions:: Helping users find the right package.
24274 * Python Modules:: A touch of British comedy.
24275 * Perl Modules:: Little pearls.
24276 * Java Packages:: Coffee break.
24277 * Fonts:: Fond of fonts.
24278 @end menu
24279
24280 @node Software Freedom
24281 @subsection Software Freedom
24282
24283 @c Adapted from http://www.gnu.org/philosophy/philosophy.html.
24284 @cindex free software
24285 The GNU operating system has been developed so that users can have
24286 freedom in their computing. GNU is @dfn{free software}, meaning that
24287 users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
24288 essential freedoms}: to run the program, to study and change the program
24289 in source code form, to redistribute exact copies, and to distribute
24290 modified versions. Packages found in the GNU distribution provide only
24291 software that conveys these four freedoms.
24292
24293 In addition, the GNU distribution follow the
24294 @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
24295 software distribution guidelines}. Among other things, these guidelines
24296 reject non-free firmware, recommendations of non-free software, and
24297 discuss ways to deal with trademarks and patents.
24298
24299 Some otherwise free upstream package sources contain a small and optional
24300 subset that violates the above guidelines, for instance because this subset
24301 is itself non-free code. When that happens, the offending items are removed
24302 with appropriate patches or code snippets in the @code{origin} form of the
24303 package (@pxref{Defining Packages}). This way, @code{guix
24304 build --source} returns the ``freed'' source rather than the unmodified
24305 upstream source.
24306
24307
24308 @node Package Naming
24309 @subsection Package Naming
24310
24311 @cindex package name
24312 A package has actually two names associated with it:
24313 First, there is the name of the @emph{Scheme variable}, the one following
24314 @code{define-public}. By this name, the package can be made known in the
24315 Scheme code, for instance as input to another package. Second, there is
24316 the string in the @code{name} field of a package definition. This name
24317 is used by package management commands such as
24318 @command{guix package} and @command{guix build}.
24319
24320 Both are usually the same and correspond to the lowercase conversion of
24321 the project name chosen upstream, with underscores replaced with
24322 hyphens. For instance, GNUnet is available as @code{gnunet}, and
24323 SDL_net as @code{sdl-net}.
24324
24325 We do not add @code{lib} prefixes for library packages, unless these are
24326 already part of the official project name. But @pxref{Python
24327 Modules} and @ref{Perl Modules} for special rules concerning modules for
24328 the Python and Perl languages.
24329
24330 Font package names are handled differently, @pxref{Fonts}.
24331
24332
24333 @node Version Numbers
24334 @subsection Version Numbers
24335
24336 @cindex package version
24337 We usually package only the latest version of a given free software
24338 project. But sometimes, for instance for incompatible library versions,
24339 two (or more) versions of the same package are needed. These require
24340 different Scheme variable names. We use the name as defined
24341 in @ref{Package Naming}
24342 for the most recent version; previous versions use the same name, suffixed
24343 by @code{-} and the smallest prefix of the version number that may
24344 distinguish the two versions.
24345
24346 The name inside the package definition is the same for all versions of a
24347 package and does not contain any version number.
24348
24349 For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
24350
24351 @example
24352 (define-public gtk+
24353 (package
24354 (name "gtk+")
24355 (version "3.9.12")
24356 ...))
24357 (define-public gtk+-2
24358 (package
24359 (name "gtk+")
24360 (version "2.24.20")
24361 ...))
24362 @end example
24363 If we also wanted GTK+ 3.8.2, this would be packaged as
24364 @example
24365 (define-public gtk+-3.8
24366 (package
24367 (name "gtk+")
24368 (version "3.8.2")
24369 ...))
24370 @end example
24371
24372 @c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
24373 @c for a discussion of what follows.
24374 @cindex version number, for VCS snapshots
24375 Occasionally, we package snapshots of upstream's version control system
24376 (VCS) instead of formal releases. This should remain exceptional,
24377 because it is up to upstream developers to clarify what the stable
24378 release is. Yet, it is sometimes necessary. So, what should we put in
24379 the @code{version} field?
24380
24381 Clearly, we need to make the commit identifier of the VCS snapshot
24382 visible in the version string, but we also need to make sure that the
24383 version string is monotonically increasing so that @command{guix package
24384 --upgrade} can determine which version is newer. Since commit
24385 identifiers, notably with Git, are not monotonically increasing, we add
24386 a revision number that we increase each time we upgrade to a newer
24387 snapshot. The resulting version string looks like this:
24388
24389 @example
24390 2.0.11-3.cabba9e
24391 ^ ^ ^
24392 | | `-- upstream commit ID
24393 | |
24394 | `--- Guix package revision
24395 |
24396 latest upstream version
24397 @end example
24398
24399 It is a good idea to strip commit identifiers in the @code{version}
24400 field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
24401 aesthetics have a role to play here) as well as problems related to OS
24402 limits such as the maximum shebang length (127 bytes for the Linux
24403 kernel.) It is best to use the full commit identifiers in
24404 @code{origin}s, though, to avoid ambiguities. A typical package
24405 definition may look like this:
24406
24407 @example
24408 (define my-package
24409 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7")
24410 (revision "1")) ;Guix package revision
24411 (package
24412 (version (git-version "0.9" revision commit))
24413 (source (origin
24414 (method git-fetch)
24415 (uri (git-reference
24416 (url "git://example.org/my-package.git")
24417 (commit commit)))
24418 (sha256 (base32 "1mbikn@dots{}"))
24419 (file-name (git-file-name name version))))
24420 ;; @dots{}
24421 )))
24422 @end example
24423
24424 @node Synopses and Descriptions
24425 @subsection Synopses and Descriptions
24426
24427 @cindex package description
24428 @cindex package synopsis
24429 As we have seen before, each package in GNU@tie{}Guix includes a
24430 synopsis and a description (@pxref{Defining Packages}). Synopses and
24431 descriptions are important: They are what @command{guix package
24432 --search} searches, and a crucial piece of information to help users
24433 determine whether a given package suits their needs. Consequently,
24434 packagers should pay attention to what goes into them.
24435
24436 Synopses must start with a capital letter and must not end with a
24437 period. They must not start with ``a'' or ``the'', which usually does
24438 not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
24439 tool that frobs files''. The synopsis should say what the package
24440 is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
24441 used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
24442 matching a pattern''.
24443
24444 Keep in mind that the synopsis must be meaningful for a very wide
24445 audience. For example, ``Manipulate alignments in the SAM format''
24446 might make sense for a seasoned bioinformatics researcher, but might be
24447 fairly unhelpful or even misleading to a non-specialized audience. It
24448 is a good idea to come up with a synopsis that gives an idea of the
24449 application domain of the package. In this example, this might give
24450 something like ``Manipulate nucleotide sequence alignments'', which
24451 hopefully gives the user a better idea of whether this is what they are
24452 looking for.
24453
24454 Descriptions should take between five and ten lines. Use full
24455 sentences, and avoid using acronyms without first introducing them.
24456 Please avoid marketing phrases such as ``world-leading'',
24457 ``industrial-strength'', and ``next-generation'', and avoid superlatives
24458 like ``the most advanced''---they are not helpful to users looking for a
24459 package and may even sound suspicious. Instead, try to be factual,
24460 mentioning use cases and features.
24461
24462 @cindex Texinfo markup, in package descriptions
24463 Descriptions can include Texinfo markup, which is useful to introduce
24464 ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
24465 hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
24466 should be careful when using some characters for example @samp{@@} and
24467 curly braces which are the basic special characters in Texinfo
24468 (@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
24469 such as @command{guix package --show} take care of rendering it
24470 appropriately.
24471
24472 Synopses and descriptions are translated by volunteers
24473 @uref{http://translationproject.org/domain/guix-packages.html, at the
24474 Translation Project} so that as many users as possible can read them in
24475 their native language. User interfaces search them and display them in
24476 the language specified by the current locale.
24477
24478 To allow @command{xgettext} to extract them as translatable strings,
24479 synopses and descriptions @emph{must be literal strings}. This means
24480 that you cannot use @code{string-append} or @code{format} to construct
24481 these strings:
24482
24483 @lisp
24484 (package
24485 ;; @dots{}
24486 (synopsis "This is translatable")
24487 (description (string-append "This is " "*not*" " translatable.")))
24488 @end lisp
24489
24490 Translation is a lot of work so, as a packager, please pay even more
24491 attention to your synopses and descriptions as every change may entail
24492 additional work for translators. In order to help them, it is possible
24493 to make recommendations or instructions visible to them by inserting
24494 special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
24495 Gettext}):
24496
24497 @example
24498 ;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
24499 (description "ARandR is designed to provide a simple visual front end
24500 for the X11 resize-and-rotate (RandR) extension. @dots{}")
24501 @end example
24502
24503
24504 @node Python Modules
24505 @subsection Python Modules
24506
24507 @cindex python
24508 We currently package Python 2 and Python 3, under the Scheme variable names
24509 @code{python-2} and @code{python} as explained in @ref{Version Numbers}.
24510 To avoid confusion and naming clashes with other programming languages, it
24511 seems desirable that the name of a package for a Python module contains
24512 the word @code{python}.
24513
24514 Some modules are compatible with only one version of Python, others with both.
24515 If the package Foo compiles only with Python 3, we name it
24516 @code{python-foo}; if it compiles only with Python 2, we name it
24517 @code{python2-foo}. If it is compatible with both versions, we create two
24518 packages with the corresponding names.
24519
24520 If a project already contains the word @code{python}, we drop this;
24521 for instance, the module python-dateutil is packaged under the names
24522 @code{python-dateutil} and @code{python2-dateutil}. If the project name
24523 starts with @code{py} (e.g.@: @code{pytz}), we keep it and prefix it as
24524 described above.
24525
24526 @subsubsection Specifying Dependencies
24527 @cindex inputs, for Python packages
24528
24529 Dependency information for Python packages is usually available in the
24530 package source tree, with varying degrees of accuracy: in the
24531 @file{setup.py} file, in @file{requirements.txt}, or in @file{tox.ini}.
24532
24533 Your mission, when writing a recipe for a Python package, is to map
24534 these dependencies to the appropriate type of ``input'' (@pxref{package
24535 Reference, inputs}). Although the @code{pypi} importer normally does a
24536 good job (@pxref{Invoking guix import}), you may want to check the
24537 following check list to determine which dependency goes where.
24538
24539 @itemize
24540
24541 @item
24542 We currently package Python 2 with @code{setuptools} and @code{pip}
24543 installed like Python 3.4 has per default. Thus you don't need to
24544 specify either of these as an input. @command{guix lint} will warn you
24545 if you do.
24546
24547 @item
24548 Python dependencies required at run time go into
24549 @code{propagated-inputs}. They are typically defined with the
24550 @code{install_requires} keyword in @file{setup.py}, or in the
24551 @file{requirements.txt} file.
24552
24553 @item
24554 Python packages required only at build time---e.g., those listed with
24555 the @code{setup_requires} keyword in @file{setup.py}---or only for
24556 testing---e.g., those in @code{tests_require}---go into
24557 @code{native-inputs}. The rationale is that (1) they do not need to be
24558 propagated because they are not needed at run time, and (2) in a
24559 cross-compilation context, it's the ``native'' input that we'd want.
24560
24561 Examples are the @code{pytest}, @code{mock}, and @code{nose} test
24562 frameworks. Of course if any of these packages is also required at
24563 run-time, it needs to go to @code{propagated-inputs}.
24564
24565 @item
24566 Anything that does not fall in the previous categories goes to
24567 @code{inputs}, for example programs or C libraries required for building
24568 Python packages containing C extensions.
24569
24570 @item
24571 If a Python package has optional dependencies (@code{extras_require}),
24572 it is up to you to decide whether to add them or not, based on their
24573 usefulness/overhead ratio (@pxref{Submitting Patches, @command{guix
24574 size}}).
24575
24576 @end itemize
24577
24578
24579 @node Perl Modules
24580 @subsection Perl Modules
24581
24582 @cindex perl
24583 Perl programs standing for themselves are named as any other package,
24584 using the lowercase upstream name.
24585 For Perl packages containing a single class, we use the lowercase class name,
24586 replace all occurrences of @code{::} by dashes and prepend the prefix
24587 @code{perl-}.
24588 So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
24589 Modules containing several classes keep their lowercase upstream name and
24590 are also prepended by @code{perl-}. Such modules tend to have the word
24591 @code{perl} somewhere in their name, which gets dropped in favor of the
24592 prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
24593
24594
24595 @node Java Packages
24596 @subsection Java Packages
24597
24598 @cindex java
24599 Java programs standing for themselves are named as any other package,
24600 using the lowercase upstream name.
24601
24602 To avoid confusion and naming clashes with other programming languages,
24603 it is desirable that the name of a package for a Java package is
24604 prefixed with @code{java-}. If a project already contains the word
24605 @code{java}, we drop this; for instance, the package @code{ngsjava} is
24606 packaged under the name @code{java-ngs}.
24607
24608 For Java packages containing a single class or a small class hierarchy,
24609 we use the lowercase class name, replace all occurrences of @code{.} by
24610 dashes and prepend the prefix @code{java-}. So the class
24611 @code{apache.commons.cli} becomes package
24612 @code{java-apache-commons-cli}.
24613
24614
24615 @node Fonts
24616 @subsection Fonts
24617
24618 @cindex fonts
24619 For fonts that are in general not installed by a user for typesetting
24620 purposes, or that are distributed as part of a larger software package,
24621 we rely on the general packaging rules for software; for instance, this
24622 applies to the fonts delivered as part of the X.Org system or fonts that
24623 are part of TeX Live.
24624
24625 To make it easier for a user to search for fonts, names for other packages
24626 containing only fonts are constructed as follows, independently of the
24627 upstream package name.
24628
24629 The name of a package containing only one font family starts with
24630 @code{font-}; it is followed by the foundry name and a dash @code{-}
24631 if the foundry is known, and the font family name, in which spaces are
24632 replaced by dashes (and as usual, all upper case letters are transformed
24633 to lower case).
24634 For example, the Gentium font family by SIL is packaged under the name
24635 @code{font-sil-gentium}.
24636
24637 For a package containing several font families, the name of the collection
24638 is used in the place of the font family name.
24639 For instance, the Liberation fonts consist of three families,
24640 Liberation Sans, Liberation Serif and Liberation Mono.
24641 These could be packaged separately under the names
24642 @code{font-liberation-sans} and so on; but as they are distributed together
24643 under a common name, we prefer to package them together as
24644 @code{font-liberation}.
24645
24646 In the case where several formats of the same font family or font collection
24647 are packaged separately, a short form of the format, prepended by a dash,
24648 is added to the package name. We use @code{-ttf} for TrueType fonts,
24649 @code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
24650 fonts.
24651
24652
24653
24654 @node Bootstrapping
24655 @section Bootstrapping
24656
24657 @c Adapted from the ELS 2013 paper.
24658
24659 @cindex bootstrapping
24660
24661 Bootstrapping in our context refers to how the distribution gets built
24662 ``from nothing''. Remember that the build environment of a derivation
24663 contains nothing but its declared inputs (@pxref{Introduction}). So
24664 there's an obvious chicken-and-egg problem: how does the first package
24665 get built? How does the first compiler get compiled? Note that this is
24666 a question of interest only to the curious hacker, not to the regular
24667 user, so you can shamelessly skip this section if you consider yourself
24668 a ``regular user''.
24669
24670 @cindex bootstrap binaries
24671 The GNU system is primarily made of C code, with libc at its core. The
24672 GNU build system itself assumes the availability of a Bourne shell and
24673 command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
24674 `grep'. Furthermore, build programs---programs that run
24675 @code{./configure}, @code{make}, etc.---are written in Guile Scheme
24676 (@pxref{Derivations}). Consequently, to be able to build anything at
24677 all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
24678 Binutils, libc, and the other packages mentioned above---the
24679 @dfn{bootstrap binaries}.
24680
24681 These bootstrap binaries are ``taken for granted'', though we can also
24682 re-create them if needed (more on that later).
24683
24684 @unnumberedsubsec Preparing to Use the Bootstrap Binaries
24685
24686 @c As of Emacs 24.3, Info-mode displays the image, but since it's a
24687 @c large image, it's hard to scroll. Oh well.
24688 @image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
24689
24690 The figure above shows the very beginning of the dependency graph of the
24691 distribution, corresponding to the package definitions of the @code{(gnu
24692 packages bootstrap)} module. A similar figure can be generated with
24693 @command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
24694
24695 @example
24696 guix graph -t derivation \
24697 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
24698 | dot -Tps > t.ps
24699 @end example
24700
24701 At this level of detail, things are
24702 slightly complex. First, Guile itself consists of an ELF executable,
24703 along with many source and compiled Scheme files that are dynamically
24704 loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
24705 tarball shown in this graph. This tarball is part of Guix's ``source''
24706 distribution, and gets inserted into the store with @code{add-to-store}
24707 (@pxref{The Store}).
24708
24709 But how do we write a derivation that unpacks this tarball and adds it
24710 to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
24711 derivation---the first one that gets built---uses @code{bash} as its
24712 builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
24713 @code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
24714 @file{xz}, and @file{mkdir} are statically-linked binaries, also part of
24715 the Guix source distribution, whose sole purpose is to allow the Guile
24716 tarball to be unpacked.
24717
24718 Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
24719 Guile that can be used to run subsequent build programs. Its first task
24720 is to download tarballs containing the other pre-built binaries---this
24721 is what the @code{.tar.xz.drv} derivations do. Guix modules such as
24722 @code{ftp-client.scm} are used for this purpose. The
24723 @code{module-import.drv} derivations import those modules in a directory
24724 in the store, using the original layout. The
24725 @code{module-import-compiled.drv} derivations compile those modules, and
24726 write them in an output directory with the right layout. This
24727 corresponds to the @code{#:modules} argument of
24728 @code{build-expression->derivation} (@pxref{Derivations}).
24729
24730 Finally, the various tarballs are unpacked by the
24731 derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
24732 etc., at which point we have a working C tool chain.
24733
24734
24735 @unnumberedsubsec Building the Build Tools
24736
24737 Bootstrapping is complete when we have a full tool chain that does not
24738 depend on the pre-built bootstrap tools discussed above. This
24739 no-dependency requirement is verified by checking whether the files of
24740 the final tool chain contain references to the @file{/gnu/store}
24741 directories of the bootstrap inputs. The process that leads to this
24742 ``final'' tool chain is described by the package definitions found in
24743 the @code{(gnu packages commencement)} module.
24744
24745 The @command{guix graph} command allows us to ``zoom out'' compared to
24746 the graph above, by looking at the level of package objects instead of
24747 individual derivations---remember that a package may translate to
24748 several derivations, typically one derivation to download its source,
24749 one to build the Guile modules it needs, and one to actually build the
24750 package from source. The command:
24751
24752 @example
24753 guix graph -t bag \
24754 -e '(@@@@ (gnu packages commencement)
24755 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
24756 @end example
24757
24758 @noindent
24759 produces the dependency graph leading to the ``final'' C
24760 library@footnote{You may notice the @code{glibc-intermediate} label,
24761 suggesting that it is not @emph{quite} final, but as a good
24762 approximation, we will consider it final.}, depicted below.
24763
24764 @image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
24765
24766 @c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
24767 The first tool that gets built with the bootstrap binaries is
24768 GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
24769 for all the following packages. From there Findutils and Diffutils get
24770 built.
24771
24772 Then come the first-stage Binutils and GCC, built as pseudo cross
24773 tools---i.e., with @code{--target} equal to @code{--host}. They are
24774 used to build libc. Thanks to this cross-build trick, this libc is
24775 guaranteed not to hold any reference to the initial tool chain.
24776
24777 From there the final Binutils and GCC (not shown above) are built.
24778 GCC uses @code{ld}
24779 from the final Binutils, and links programs against the just-built libc.
24780 This tool chain is used to build the other packages used by Guix and by
24781 the GNU Build System: Guile, Bash, Coreutils, etc.
24782
24783 And voilà! At this point we have the complete set of build tools that
24784 the GNU Build System expects. These are in the @code{%final-inputs}
24785 variable of the @code{(gnu packages commencement)} module, and are
24786 implicitly used by any package that uses @code{gnu-build-system}
24787 (@pxref{Build Systems, @code{gnu-build-system}}).
24788
24789
24790 @unnumberedsubsec Building the Bootstrap Binaries
24791
24792 @cindex bootstrap binaries
24793 Because the final tool chain does not depend on the bootstrap binaries,
24794 those rarely need to be updated. Nevertheless, it is useful to have an
24795 automated way to produce them, should an update occur, and this is what
24796 the @code{(gnu packages make-bootstrap)} module provides.
24797
24798 The following command builds the tarballs containing the bootstrap
24799 binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
24800 of Coreutils and other basic command-line tools):
24801
24802 @example
24803 guix build bootstrap-tarballs
24804 @end example
24805
24806 The generated tarballs are those that should be referred to in the
24807 @code{(gnu packages bootstrap)} module mentioned at the beginning of
24808 this section.
24809
24810 Still here? Then perhaps by now you've started to wonder: when do we
24811 reach a fixed point? That is an interesting question! The answer is
24812 unknown, but if you would like to investigate further (and have
24813 significant computational and storage resources to do so), then let us
24814 know.
24815
24816 @unnumberedsubsec Reducing the Set of Bootstrap Binaries
24817
24818 Our bootstrap binaries currently include GCC, Guile, etc. That's a lot
24819 of binary code! Why is that a problem? It's a problem because these
24820 big chunks of binary code are practically non-auditable, which makes it
24821 hard to establish what source code produced them. Every unauditable
24822 binary also leaves us vulnerable to compiler backdoors as described by
24823 Ken Thompson in the 1984 paper @emph{Reflections on Trusting Trust}.
24824
24825 This is mitigated by the fact that our bootstrap binaries were generated
24826 from an earlier Guix revision. Nevertheless it lacks the level of
24827 transparency that we get in the rest of the package dependency graph,
24828 where Guix always gives us a source-to-binary mapping. Thus, our goal
24829 is to reduce the set of bootstrap binaries to the bare minimum.
24830
24831 The @uref{http://bootstrappable.org, Bootstrappable.org web site} lists
24832 on-going projects to do that. One of these is about replacing the
24833 bootstrap GCC with a sequence of assemblers, interpreters, and compilers
24834 of increasing complexity, which could be built from source starting from
24835 a simple and auditable assembler. Your help is welcome!
24836
24837
24838 @node Porting
24839 @section Porting to a New Platform
24840
24841 As discussed above, the GNU distribution is self-contained, and
24842 self-containment is achieved by relying on pre-built ``bootstrap
24843 binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
24844 operating system kernel, CPU architecture, and application binary
24845 interface (ABI). Thus, to port the distribution to a platform that is
24846 not yet supported, one must build those bootstrap binaries, and update
24847 the @code{(gnu packages bootstrap)} module to use them on that platform.
24848
24849 Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
24850 When everything goes well, and assuming the GNU tool chain supports the
24851 target platform, this can be as simple as running a command like this
24852 one:
24853
24854 @example
24855 guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
24856 @end example
24857
24858 For this to work, the @code{glibc-dynamic-linker} procedure in
24859 @code{(gnu packages bootstrap)} must be augmented to return the right
24860 file name for libc's dynamic linker on that platform; likewise,
24861 @code{system->linux-architecture} in @code{(gnu packages linux)} must be
24862 taught about the new platform.
24863
24864 Once these are built, the @code{(gnu packages bootstrap)} module needs
24865 to be updated to refer to these binaries on the target platform. That
24866 is, the hashes and URLs of the bootstrap tarballs for the new platform
24867 must be added alongside those of the currently supported platforms. The
24868 bootstrap Guile tarball is treated specially: it is expected to be
24869 available locally, and @file{gnu/local.mk} has rules to download it for
24870 the supported architectures; a rule for the new platform must be added
24871 as well.
24872
24873 In practice, there may be some complications. First, it may be that the
24874 extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
24875 above) is not recognized by all the GNU tools. Typically, glibc
24876 recognizes some of these, whereas GCC uses an extra @code{--with-abi}
24877 configure flag (see @code{gcc.scm} for examples of how to handle this).
24878 Second, some of the required packages could fail to build for that
24879 platform. Lastly, the generated binaries could be broken for some
24880 reason.
24881
24882 @c *********************************************************************
24883 @include contributing.texi
24884
24885 @c *********************************************************************
24886 @node Acknowledgments
24887 @chapter Acknowledgments
24888
24889 Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
24890 which was designed and
24891 implemented by Eelco Dolstra, with contributions from other people (see
24892 the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
24893 management, and promoted unprecedented features, such as transactional
24894 package upgrades and rollbacks, per-user profiles, and referentially
24895 transparent build processes. Without this work, Guix would not exist.
24896
24897 The Nix-based software distributions, Nixpkgs and NixOS, have also been
24898 an inspiration for Guix.
24899
24900 GNU@tie{}Guix itself is a collective work with contributions from a
24901 number of people. See the @file{AUTHORS} file in Guix for more
24902 information on these fine people. The @file{THANKS} file lists people
24903 who have helped by reporting bugs, taking care of the infrastructure,
24904 providing artwork and themes, making suggestions, and more---thank you!
24905
24906
24907 @c *********************************************************************
24908 @node GNU Free Documentation License
24909 @appendix GNU Free Documentation License
24910 @cindex license, GNU Free Documentation License
24911 @include fdl-1.3.texi
24912
24913 @c *********************************************************************
24914 @node Concept Index
24915 @unnumbered Concept Index
24916 @printindex cp
24917
24918 @node Programming Index
24919 @unnumbered Programming Index
24920 @syncodeindex tp fn
24921 @syncodeindex vr fn
24922 @printindex fn
24923
24924 @bye
24925
24926 @c Local Variables:
24927 @c ispell-local-dictionary: "american";
24928 @c End: