Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / doc / guix.texi
1 \input texinfo
2 @c -*-texinfo-*-
3
4 @c %**start of header
5 @setfilename guix.info
6 @documentencoding UTF-8
7 @settitle GNU Guix Reference Manual
8 @c %**end of header
9
10 @include version.texi
11
12 @c Identifier of the OpenPGP key used to sign tarballs and such.
13 @set OPENPGP-SIGNING-KEY-ID 3CE464558A84FDC69DB40CFB090B11993D9AEBB5
14
15 @copying
16 Copyright @copyright{} 2012, 2013, 2014, 2015, 2016 Ludovic Courtès@*
17 Copyright @copyright{} 2013, 2014, 2016 Andreas Enge@*
18 Copyright @copyright{} 2013 Nikita Karetnikov@*
19 Copyright @copyright{} 2014, 2015, 2016 Alex Kost@*
20 Copyright @copyright{} 2015, 2016 Mathieu Lirzin@*
21 Copyright @copyright{} 2014 Pierre-Antoine Rault@*
22 Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer@*
23 Copyright @copyright{} 2015, 2016 Leo Famulari@*
24 Copyright @copyright{} 2015, 2016 Ricardo Wurmus@*
25 Copyright @copyright{} 2016 Ben Woodcroft@*
26 Copyright @copyright{} 2016 Chris Marusich@*
27 Copyright @copyright{} 2016 Efraim Flashner@*
28 Copyright @copyright{} 2016 John Darrington@*
29 Copyright @copyright{} 2016 ng0@*
30 Copyright @copyright{} 2016 Jan Nieuwenhuizen
31
32 Permission is granted to copy, distribute and/or modify this document
33 under the terms of the GNU Free Documentation License, Version 1.3 or
34 any later version published by the Free Software Foundation; with no
35 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
36 copy of the license is included in the section entitled ``GNU Free
37 Documentation License''.
38 @end copying
39
40 @dircategory System administration
41 @direntry
42 * Guix: (guix). Manage installed software and system configuration.
43 * guix package: (guix)Invoking guix package. Installing, removing, and upgrading packages.
44 * guix build: (guix)Invoking guix build. Building packages.
45 * guix gc: (guix)Invoking guix gc. Reclaiming unused disk space.
46 * guix pull: (guix)Invoking guix pull. Update the list of available packages.
47 * guix system: (guix)Invoking guix system. Manage the operating system configuration.
48 @end direntry
49
50 @dircategory Software development
51 @direntry
52 * guix environment: (guix)Invoking guix environment. Building development environments with Guix.
53 @end direntry
54
55 @dircategory Emacs
56 @direntry
57 * Guix user interface: (guix)Emacs Interface. Package management from the comfort of Emacs.
58 @end direntry
59
60
61 @titlepage
62 @title GNU Guix Reference Manual
63 @subtitle Using the GNU Guix Functional Package Manager
64 @author The GNU Guix Developers
65
66 @page
67 @vskip 0pt plus 1filll
68 Edition @value{EDITION} @*
69 @value{UPDATED} @*
70
71 @insertcopying
72 @end titlepage
73
74 @contents
75
76 @c *********************************************************************
77 @node Top
78 @top GNU Guix
79
80 This document describes GNU Guix version @value{VERSION}, a functional
81 package management tool written for the GNU system.
82
83 @menu
84 * Introduction:: What is Guix about?
85 * Installation:: Installing Guix.
86 * Package Management:: Package installation, upgrade, etc.
87 * Emacs Interface:: Using Guix from Emacs.
88 * Programming Interface:: Using Guix in Scheme.
89 * Utilities:: Package management commands.
90 * GNU Distribution:: Software for your friendly GNU system.
91 * Contributing:: Your help needed!
92
93 * Acknowledgments:: Thanks!
94 * GNU Free Documentation License:: The license of this manual.
95 * Concept Index:: Concepts.
96 * Programming Index:: Data types, functions, and variables.
97
98 @detailmenu
99 --- The Detailed Node Listing ---
100
101 Installation
102
103 * Binary Installation:: Getting Guix running in no time!
104 * Requirements:: Software needed to build and run Guix.
105 * Running the Test Suite:: Testing Guix.
106 * Setting Up the Daemon:: Preparing the build daemon's environment.
107 * Invoking guix-daemon:: Running the build daemon.
108 * Application Setup:: Application-specific setup.
109
110 Setting Up the Daemon
111
112 * Build Environment Setup:: Preparing the isolated build environment.
113 * Daemon Offload Setup:: Offloading builds to remote machines.
114
115 Package Management
116
117 * Features:: How Guix will make your life brighter.
118 * Invoking guix package:: Package installation, removal, etc.
119 * Substitutes:: Downloading pre-built binaries.
120 * Packages with Multiple Outputs:: Single source package, multiple outputs.
121 * Invoking guix gc:: Running the garbage collector.
122 * Invoking guix pull:: Fetching the latest Guix and distribution.
123 * Invoking guix archive:: Exporting and importing store files.
124
125 Emacs Interface
126
127 * Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
128 * Package Management: Emacs Package Management. Managing packages and generations.
129 * Licenses: Emacs Licenses. Interface for licenses of Guix packages.
130 * Package Source Locations: Emacs Package Locations. Interface for package location files.
131 * Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
132 * Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
133 * Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
134 * Completions: Emacs Completions. Completing @command{guix} shell command.
135 * Development: Emacs Development. Tools for Guix developers.
136 * Hydra: Emacs Hydra. Interface for Guix build farm.
137
138 Programming Interface
139
140 * Defining Packages:: Defining new packages.
141 * Build Systems:: Specifying how packages are built.
142 * The Store:: Manipulating the package store.
143 * Derivations:: Low-level interface to package derivations.
144 * The Store Monad:: Purely functional interface to the store.
145 * G-Expressions:: Manipulating build expressions.
146
147 Defining Packages
148
149 * package Reference:: The package data type.
150 * origin Reference:: The origin data type.
151
152 Utilities
153
154 * Invoking guix build:: Building packages from the command line.
155 * Invoking guix edit:: Editing package definitions.
156 * Invoking guix download:: Downloading a file and printing its hash.
157 * Invoking guix hash:: Computing the cryptographic hash of a file.
158 * Invoking guix import:: Importing package definitions.
159 * Invoking guix refresh:: Updating package definitions.
160 * Invoking guix lint:: Finding errors in package definitions.
161 * Invoking guix size:: Profiling disk usage.
162 * Invoking guix graph:: Visualizing the graph of packages.
163 * Invoking guix environment:: Setting up development environments.
164 * Invoking guix publish:: Sharing substitutes.
165 * Invoking guix challenge:: Challenging substitute servers.
166 * Invoking guix container:: Process isolation.
167
168 Invoking @command{guix build}
169
170 * Common Build Options:: Build options for most commands.
171 * Package Transformation Options:: Creating variants of packages.
172 * Additional Build Options:: Options specific to 'guix build'.
173
174 GNU Distribution
175
176 * System Installation:: Installing the whole operating system.
177 * System Configuration:: Configuring the operating system.
178 * Installing Debugging Files:: Feeding the debugger.
179 * Security Updates:: Deploying security fixes quickly.
180 * Package Modules:: Packages from the programmer's viewpoint.
181 * Packaging Guidelines:: Growing the distribution.
182 * Bootstrapping:: GNU/Linux built from scratch.
183 * Porting:: Targeting another platform or kernel.
184
185 System Installation
186
187 * Limitations:: What you can expect.
188 * Hardware Considerations:: Supported hardware.
189 * USB Stick Installation:: Preparing the installation medium.
190 * Preparing for Installation:: Networking, partitioning, etc.
191 * Proceeding with the Installation:: The real thing.
192 * Installing GuixSD in a VM:: GuixSD playground.
193 * Building the Installation Image:: How this comes to be.
194
195 System Configuration
196
197 * Using the Configuration System:: Customizing your GNU system.
198 * operating-system Reference:: Detail of operating-system declarations.
199 * File Systems:: Configuring file system mounts.
200 * Mapped Devices:: Block device extra processing.
201 * User Accounts:: Specifying user accounts.
202 * Locales:: Language and cultural convention settings.
203 * Services:: Specifying system services.
204 * Setuid Programs:: Programs running with root privileges.
205 * X.509 Certificates:: Authenticating HTTPS servers.
206 * Name Service Switch:: Configuring libc's name service switch.
207 * Initial RAM Disk:: Linux-Libre bootstrapping.
208 * GRUB Configuration:: Configuring the boot loader.
209 * Invoking guix system:: Instantiating a system configuration.
210 * Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
211 * Defining Services:: Adding new service definitions.
212
213 Services
214
215 * Base Services:: Essential system services.
216 * Scheduled Job Execution:: The mcron service.
217 * Log Rotation:: The rottlog service.
218 * Networking Services:: Network setup, SSH daemon, etc.
219 * X Window:: Graphical display.
220 * Desktop Services:: D-Bus and desktop services.
221 * Database Services:: SQL databases.
222 * Mail Services:: IMAP, POP3, SMTP, and all that.
223 * Web Services:: Web servers.
224 * Network File System:: NFS related services.
225 * Miscellaneous Services:: Other services.
226
227 Defining Services
228
229 * Service Composition:: The model for composing services.
230 * Service Types and Services:: Types and services.
231 * Service Reference:: API reference.
232 * Shepherd Services:: A particular type of service.
233
234 Packaging Guidelines
235
236 * Software Freedom:: What may go into the distribution.
237 * Package Naming:: What's in a name?
238 * Version Numbers:: When the name is not enough.
239 * Synopses and Descriptions:: Helping users find the right package.
240 * Python Modules:: Taming the snake.
241 * Perl Modules:: Little pearls.
242 * Java Packages:: Coffee break.
243 * Fonts:: Fond of fonts.
244
245 Contributing
246
247 * Building from Git:: The latest and greatest.
248 * Running Guix Before It Is Installed:: Hacker tricks.
249 * The Perfect Setup:: The right tools.
250 * Coding Style:: Hygiene of the contributor.
251 * Submitting Patches:: Share your work.
252
253 Coding Style
254
255 * Programming Paradigm:: How to compose your elements.
256 * Modules:: Where to store your code?
257 * Data Types and Pattern Matching:: Implementing data structures.
258 * Formatting Code:: Writing conventions.
259
260 @end detailmenu
261 @end menu
262
263 @c *********************************************************************
264 @node Introduction
265 @chapter Introduction
266
267 @cindex purpose
268 GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
269 using the international phonetic alphabet (IPA).} is a package
270 management tool for the GNU system. Guix makes it easy for unprivileged
271 users to install, upgrade, or remove packages, to roll back to a
272 previous package set, to build packages from source, and generally
273 assists with the creation and maintenance of software environments.
274
275 @cindex user interfaces
276 Guix provides a command-line package management interface
277 (@pxref{Invoking guix package}), a set of command-line utilities
278 (@pxref{Utilities}), a visual user interface in Emacs (@pxref{Emacs
279 Interface}), as well as Scheme programming interfaces
280 (@pxref{Programming Interface}).
281 @cindex build daemon
282 Its @dfn{build daemon} is responsible for building packages on behalf of
283 users (@pxref{Setting Up the Daemon}) and for downloading pre-built
284 binaries from authorized sources (@pxref{Substitutes}).
285
286 @cindex extensibility of the distribution
287 @cindex customization of packages
288 Guix includes package definitions for many GNU and non-GNU packages, all
289 of which @uref{https://www.gnu.org/philosophy/free-sw.html, respect the
290 user's computing freedom}. It is @emph{extensible}: users can write
291 their own package definitions (@pxref{Defining Packages}) and make them
292 available as independent package modules (@pxref{Package Modules}). It
293 is also @emph{customizable}: users can @emph{derive} specialized package
294 definitions from existing ones, including from the command line
295 (@pxref{Package Transformation Options}).
296
297 @cindex Guix System Distribution
298 @cindex GuixSD
299 You can install GNU@tie{}Guix on top of an existing GNU/Linux system
300 where it complements the available tools without interference
301 (@pxref{Installation}), or you can use it as part of the standalone
302 @dfn{Guix System Distribution} or GuixSD (@pxref{GNU Distribution}).
303 With GNU@tie{}GuixSD, you @emph{declare} all aspects of the operating
304 system configuration and Guix takes care of instantiating the
305 configuration in a transactional, reproducible, and stateless fashion
306 (@pxref{System Configuration}).
307
308 @cindex functional package management
309 Under the hood, Guix implements the @dfn{functional package management}
310 discipline pioneered by Nix (@pxref{Acknowledgments}).
311 In Guix, the package build and installation process is seen
312 as a @emph{function}, in the mathematical sense. That function takes inputs,
313 such as build scripts, a compiler, and libraries, and
314 returns an installed package. As a pure function, its result depends
315 solely on its inputs---for instance, it cannot refer to software or
316 scripts that were not explicitly passed as inputs. A build function
317 always produces the same result when passed a given set of inputs. It
318 cannot alter the environment of the running system in
319 any way; for instance, it cannot create, modify, or delete files outside
320 of its build and installation directories. This is achieved by running
321 build processes in isolated environments (or @dfn{containers}), where only their
322 explicit inputs are visible.
323
324 @cindex store
325 The result of package build functions is @dfn{cached} in the file
326 system, in a special directory called @dfn{the store} (@pxref{The
327 Store}). Each package is installed in a directory of its own in the
328 store---by default under @file{/gnu/store}. The directory name contains
329 a hash of all the inputs used to build that package; thus, changing an
330 input yields a different directory name.
331
332 This approach is the foundation for the salient features of Guix: support
333 for transactional package upgrade and rollback, per-user installation, and
334 garbage collection of packages (@pxref{Features}).
335
336
337 @c *********************************************************************
338 @node Installation
339 @chapter Installation
340
341 GNU Guix is available for download from its website at
342 @url{http://www.gnu.org/software/guix/}. This section describes the
343 software requirements of Guix, as well as how to install it and get
344 ready to use it.
345
346 Note that this section is concerned with the installation of the package
347 manager, which can be done on top of a running GNU/Linux system. If,
348 instead, you want to install the complete GNU operating system,
349 @pxref{System Installation}.
350
351 @cindex foreign distro
352 When installed on a running GNU/Linux system---thereafter called a
353 @dfn{foreign distro}---GNU@tie{}Guix complements the available tools
354 without interference. Its data lives exclusively in two directories,
355 usually @file{/gnu/store} and @file{/var/guix}; other files on your
356 system, such as @file{/etc}, are left untouched.
357
358 @menu
359 * Binary Installation:: Getting Guix running in no time!
360 * Requirements:: Software needed to build and run Guix.
361 * Running the Test Suite:: Testing Guix.
362 * Setting Up the Daemon:: Preparing the build daemon's environment.
363 * Invoking guix-daemon:: Running the build daemon.
364 * Application Setup:: Application-specific setup.
365 @end menu
366
367 @node Binary Installation
368 @section Binary Installation
369
370 This section describes how to install Guix on an arbitrary system from a
371 self-contained tarball providing binaries for Guix and for all its
372 dependencies. This is often quicker than installing from source, which
373 is described in the next sections. The only requirement is to have
374 GNU@tie{}tar and Xz.
375
376 Installing goes along these lines:
377
378 @enumerate
379 @item
380 Download the binary tarball from
381 @indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz},
382 where @var{system} is @code{x86_64-linux} for an @code{x86_64} machine
383 already running the kernel Linux, and so on.
384
385 @c The following is somewhat duplicated in ``System Installation''.
386 Make sure to download the associated @file{.sig} file and to verify the
387 authenticity of the tarball against it, along these lines:
388
389 @example
390 $ wget ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
391 $ gpg --verify guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
392 @end example
393
394 If that command fails because you do not have the required public key,
395 then run this command to import it:
396
397 @example
398 $ gpg --keyserver pgp.mit.edu --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
399 @end example
400
401 @noindent
402 and rerun the @code{gpg --verify} command.
403 @c end authentication part
404
405 @item
406 As @code{root}, run:
407
408 @example
409 # cd /tmp
410 # tar --warning=no-timestamp -xf \
411 guix-binary-@value{VERSION}.@var{system}.tar.xz
412 # mv var/guix /var/ && mv gnu /
413 @end example
414
415 This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
416 The latter contains a ready-to-use profile for @code{root} (see next
417 step.)
418
419 Do @emph{not} unpack the tarball on a working Guix system since that
420 would overwrite its own essential files.
421
422 The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
423 not emit warnings about ``implausibly old time stamps'' (such
424 warnings were triggered by GNU@tie{}tar 1.26 and older; recent
425 versions are fine.)
426 They stem from the fact that all the
427 files in the archive have their modification time set to zero (which
428 means January 1st, 1970.) This is done on purpose to make sure the
429 archive content is independent of its creation time, thus making it
430 reproducible.
431
432 @item
433 Make @code{root}'s profile available under @file{~/.guix-profile}:
434
435 @example
436 # ln -sf /var/guix/profiles/per-user/root/guix-profile \
437 ~root/.guix-profile
438 @end example
439
440 @item
441 Create the group and user accounts for build users as explained below
442 (@pxref{Build Environment Setup}).
443
444 @item
445 Run the daemon, and set it to automatically start on boot.
446
447 If your host distro uses the systemd init system, this can be achieved
448 with these commands:
449
450 @example
451 # cp ~root/.guix-profile/lib/systemd/system/guix-daemon.service \
452 /etc/systemd/system/
453 # systemctl start guix-daemon && systemctl enable guix-daemon
454 @end example
455
456 If your host distro uses the Upstart init system:
457
458 @example
459 # cp ~root/.guix-profile/lib/upstart/system/guix-daemon.conf /etc/init/
460 # start guix-daemon
461 @end example
462
463 Otherwise, you can still start the daemon manually with:
464
465 @example
466 # ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
467 @end example
468
469 @item
470 Make the @command{guix} command available to other users on the machine,
471 for instance with:
472
473 @example
474 # mkdir -p /usr/local/bin
475 # cd /usr/local/bin
476 # ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
477 @end example
478
479 It is also a good idea to make the Info version of this manual available
480 there:
481
482 @example
483 # mkdir -p /usr/local/share/info
484 # cd /usr/local/share/info
485 # for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
486 do ln -s $i ; done
487 @end example
488
489 That way, assuming @file{/usr/local/share/info} is in the search path,
490 running @command{info guix} will open this manual (@pxref{Other Info
491 Directories,,, texinfo, GNU Texinfo}, for more details on changing the
492 Info search path.)
493
494 @item
495 To use substitutes from @code{hydra.gnu.org} or one of its mirrors
496 (@pxref{Substitutes}), authorize them:
497
498 @example
499 # guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
500 @end example
501 @end enumerate
502
503 This completes root-level install of Guix. Each user will need to
504 perform additional steps to make their Guix environment ready for use,
505 @pxref{Application Setup}.
506
507 You can confirm that Guix is working by installing a sample package into
508 the root profile:
509
510 @example
511 # guix package -i hello
512 @end example
513
514 The @code{guix} package must remain available in @code{root}'s profile,
515 or it would become subject to garbage collection---in which case you
516 would find yourself badly handicapped by the lack of the @command{guix}
517 command. In other words, do not remove @code{guix} by running
518 @code{guix package -r guix}.
519
520 The binary installation tarball can be (re)produced and verified simply
521 by running the following command in the Guix source tree:
522
523 @example
524 make guix-binary.@var{system}.tar.xz
525 @end example
526
527
528 @node Requirements
529 @section Requirements
530
531 This section lists requirements when building Guix from source. The
532 build procedure for Guix is the same as for other GNU software, and is
533 not covered here. Please see the files @file{README} and @file{INSTALL}
534 in the Guix source tree for additional details.
535
536 GNU Guix depends on the following packages:
537
538 @itemize
539 @item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
540 @item @url{http://gnupg.org/, GNU libgcrypt};
541 @item @url{http://www.gnu.org/software/make/, GNU Make}.
542 @end itemize
543
544 The following dependencies are optional:
545
546 @itemize
547 @item
548 Installing @uref{http://gnutls.org/, GnuTLS-Guile} will allow you to
549 access @code{https} URLs for substitutes, which is highly recommended
550 (@pxref{Substitutes}). It also allows you to access HTTPS URLs with the
551 @command{guix download} command (@pxref{Invoking guix download}), the
552 @command{guix import pypi} command, and the @command{guix import cpan}
553 command. @xref{Guile Preparations, how to install the GnuTLS bindings
554 for Guile,, gnutls-guile, GnuTLS-Guile}.
555
556 @item
557 Installing
558 @url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
559 allow you to use the @command{guix import pypi} command (@pxref{Invoking
560 guix import}). It is of
561 interest primarily for developers and not for casual users.
562
563 @item
564 When @url{http://zlib.net, zlib} is available, @command{guix publish}
565 can compress build byproducts (@pxref{Invoking guix publish}).
566 @end itemize
567
568 Unless @code{--disable-daemon} was passed to @command{configure}, the
569 following packages are also needed:
570
571 @itemize
572 @item @url{http://sqlite.org, SQLite 3};
573 @item @url{http://www.bzip.org, libbz2};
574 @item @url{http://gcc.gnu.org, GCC's g++}, with support for the
575 C++11 standard.
576 @end itemize
577
578 When configuring Guix on a system that already has a Guix installation,
579 be sure to specify the same state directory as the existing installation
580 using the @code{--localstatedir} option of the @command{configure}
581 script (@pxref{Directory Variables, @code{localstatedir},, standards,
582 GNU Coding Standards}). The @command{configure} script protects against
583 unintended misconfiguration of @var{localstatedir} so you do not
584 inadvertently corrupt your store (@pxref{The Store}).
585
586 When a working installation of @url{http://nixos.org/nix/, the Nix package
587 manager} is available, you
588 can instead configure Guix with @code{--disable-daemon}. In that case,
589 Nix replaces the three dependencies above.
590
591 Guix is compatible with Nix, so it is possible to share the same store
592 between both. To do so, you must pass @command{configure} not only the
593 same @code{--with-store-dir} value, but also the same
594 @code{--localstatedir} value. The latter is essential because it
595 specifies where the database that stores metadata about the store is
596 located, among other things. The default values for Nix are
597 @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
598 Note that @code{--disable-daemon} is not required if
599 your goal is to share the store with Nix.
600
601 @node Running the Test Suite
602 @section Running the Test Suite
603
604 After a successful @command{configure} and @code{make} run, it is a good
605 idea to run the test suite. It can help catch issues with the setup or
606 environment, or bugs in Guix itself---and really, reporting test
607 failures is a good way to help improve the software. To run the test
608 suite, type:
609
610 @example
611 make check
612 @end example
613
614 Test cases can run in parallel: you can use the @code{-j} option of
615 GNU@tie{}make to speed things up. The first run may take a few minutes
616 on a recent machine; subsequent runs will be faster because the store
617 that is created for test purposes will already have various things in
618 cache.
619
620 It is also possible to run a subset of the tests by defining the
621 @code{TESTS} makefile variable as in this example:
622
623 @example
624 make check TESTS="tests/store.scm tests/cpio.scm"
625 @end example
626
627 By default, tests results are displayed at a file level. In order to
628 see the details of every individual test cases, it is possible to define
629 the @code{SCM_LOG_DRIVER_FLAGS} makefile variable as in this example:
630
631 @example
632 make check TESTS="tests/base64.scm" SCM_LOG_DRIVER_FLAGS="--brief=no"
633 @end example
634
635 Upon failure, please email @email{bug-guix@@gnu.org} and attach the
636 @file{test-suite.log} file. Please specify the Guix version being used
637 as well as version numbers of the dependencies (@pxref{Requirements}) in
638 your message.
639
640 Guix also comes with a whole-system test suite that tests complete
641 GuixSD operating system instances. It can only run on systems where
642 Guix is already installed, using:
643
644 @example
645 make check-system
646 @end example
647
648 @noindent
649 or, again, by defining @code{TESTS} to select a subset of tests to run:
650
651 @example
652 make check-system TESTS="basic mcron"
653 @end example
654
655 These system tests are defined in the @code{(gnu tests @dots{})}
656 modules. They work by running the operating systems under test with
657 lightweight instrumentation in a virtual machine (VM). They can be
658 computationally intensive or rather cheap, depending on whether
659 substitutes are available for their dependencies (@pxref{Substitutes}).
660 Some of them require a lot of storage space to hold VM images.
661
662 Again in case of test failures, please send @email{bug-guix@@gnu.org}
663 all the details.
664
665 @node Setting Up the Daemon
666 @section Setting Up the Daemon
667
668 @cindex daemon
669 Operations such as building a package or running the garbage collector
670 are all performed by a specialized process, the @dfn{build daemon}, on
671 behalf of clients. Only the daemon may access the store and its
672 associated database. Thus, any operation that manipulates the store
673 goes through the daemon. For instance, command-line tools such as
674 @command{guix package} and @command{guix build} communicate with the
675 daemon (@i{via} remote procedure calls) to instruct it what to do.
676
677 The following sections explain how to prepare the build daemon's
678 environment. See also @ref{Substitutes}, for information on how to allow
679 the daemon to download pre-built binaries.
680
681 @menu
682 * Build Environment Setup:: Preparing the isolated build environment.
683 * Daemon Offload Setup:: Offloading builds to remote machines.
684 @end menu
685
686 @node Build Environment Setup
687 @subsection Build Environment Setup
688
689 In a standard multi-user setup, Guix and its daemon---the
690 @command{guix-daemon} program---are installed by the system
691 administrator; @file{/gnu/store} is owned by @code{root} and
692 @command{guix-daemon} runs as @code{root}. Unprivileged users may use
693 Guix tools to build packages or otherwise access the store, and the
694 daemon will do it on their behalf, ensuring that the store is kept in a
695 consistent state, and allowing built packages to be shared among users.
696
697 @cindex build users
698 When @command{guix-daemon} runs as @code{root}, you may not want package
699 build processes themselves to run as @code{root} too, for obvious
700 security reasons. To avoid that, a special pool of @dfn{build users}
701 should be created for use by build processes started by the daemon.
702 These build users need not have a shell and a home directory: they will
703 just be used when the daemon drops @code{root} privileges in build
704 processes. Having several such users allows the daemon to launch
705 distinct build processes under separate UIDs, which guarantees that they
706 do not interfere with each other---an essential feature since builds are
707 regarded as pure functions (@pxref{Introduction}).
708
709 On a GNU/Linux system, a build user pool may be created like this (using
710 Bash syntax and the @code{shadow} commands):
711
712 @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
713 @c for why `-G' is needed.
714 @example
715 # groupadd --system guixbuild
716 # for i in `seq -w 1 10`;
717 do
718 useradd -g guixbuild -G guixbuild \
719 -d /var/empty -s `which nologin` \
720 -c "Guix build user $i" --system \
721 guixbuilder$i;
722 done
723 @end example
724
725 @noindent
726 The number of build users determines how many build jobs may run in
727 parallel, as specified by the @option{--max-jobs} option
728 (@pxref{Invoking guix-daemon, @option{--max-jobs}}). To use
729 @command{guix system vm} and related commands, you may need to add the
730 build users to the @code{kvm} group so they can access @file{/dev/kvm},
731 using @code{-G guixbuild,kvm} instead of @code{-G guixbuild}
732 (@pxref{Invoking guix system}).
733
734 The @code{guix-daemon} program may then be run as @code{root} with the
735 following command@footnote{If your machine uses the systemd init system,
736 dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
737 file in @file{/etc/systemd/system} will ensure that
738 @command{guix-daemon} is automatically started. Similarly, if your
739 machine uses the Upstart init system, drop the
740 @file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
741 file in @file{/etc/init}.}:
742
743 @example
744 # guix-daemon --build-users-group=guixbuild
745 @end example
746
747 @cindex chroot
748 @noindent
749 This way, the daemon starts build processes in a chroot, under one of
750 the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
751 environment contains nothing but:
752
753 @c Keep this list in sync with libstore/build.cc! -----------------------
754 @itemize
755 @item
756 a minimal @code{/dev} directory, created mostly independently from the
757 host @code{/dev}@footnote{``Mostly'', because while the set of files
758 that appear in the chroot's @code{/dev} is fixed, most of these files
759 can only be created if the host has them.};
760
761 @item
762 the @code{/proc} directory; it only shows the processes of the container
763 since a separate PID name space is used;
764
765 @item
766 @file{/etc/passwd} with an entry for the current user and an entry for
767 user @file{nobody};
768
769 @item
770 @file{/etc/group} with an entry for the user's group;
771
772 @item
773 @file{/etc/hosts} with an entry that maps @code{localhost} to
774 @code{127.0.0.1};
775
776 @item
777 a writable @file{/tmp} directory.
778 @end itemize
779
780 You can influence the directory where the daemon stores build trees
781 @i{via} the @code{TMPDIR} environment variable. However, the build tree
782 within the chroot is always called @file{/tmp/guix-build-@var{name}.drv-0},
783 where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
784 This way, the value of @code{TMPDIR} does not leak inside build
785 environments, which avoids discrepancies in cases where build processes
786 capture the name of their build tree.
787
788 @vindex http_proxy
789 The daemon also honors the @code{http_proxy} environment variable for
790 HTTP downloads it performs, be it for fixed-output derivations
791 (@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
792
793 If you are installing Guix as an unprivileged user, it is still possible
794 to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
795 However, build processes will not be isolated from one another, and not
796 from the rest of the system. Thus, build processes may interfere with
797 each other, and may access programs, libraries, and other files
798 available on the system---making it much harder to view them as
799 @emph{pure} functions.
800
801
802 @node Daemon Offload Setup
803 @subsection Using the Offload Facility
804
805 @cindex offloading
806 @cindex build hook
807 When desired, the build daemon can @dfn{offload}
808 derivation builds to other machines
809 running Guix, using the @code{offload} @dfn{build hook}. When that
810 feature is enabled, a list of user-specified build machines is read from
811 @file{/etc/guix/machines.scm}; every time a build is requested, for
812 instance via @code{guix build}, the daemon attempts to offload it to one
813 of the machines that satisfy the constraints of the derivation, in
814 particular its system type---e.g., @file{x86_64-linux}. Missing
815 prerequisites for the build are copied over SSH to the target machine,
816 which then proceeds with the build; upon success the output(s) of the
817 build are copied back to the initial machine.
818
819 The @file{/etc/guix/machines.scm} file typically looks like this:
820
821 @example
822 (list (build-machine
823 (name "eightysix.example.org")
824 (system "x86_64-linux")
825 (user "bob")
826 (speed 2.)) ; incredibly fast!
827
828 (build-machine
829 (name "meeps.example.org")
830 (system "mips64el-linux")
831 (user "alice")
832 (private-key
833 (string-append (getenv "HOME")
834 "/.lsh/identity-for-guix"))))
835 @end example
836
837 @noindent
838 In the example above we specify a list of two build machines, one for
839 the @code{x86_64} architecture and one for the @code{mips64el}
840 architecture.
841
842 In fact, this file is---not surprisingly!---a Scheme file that is
843 evaluated when the @code{offload} hook is started. Its return value
844 must be a list of @code{build-machine} objects. While this example
845 shows a fixed list of build machines, one could imagine, say, using
846 DNS-SD to return a list of potential build machines discovered in the
847 local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
848 Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
849 detailed below.
850
851 @deftp {Data Type} build-machine
852 This data type represents build machines to which the daemon may offload
853 builds. The important fields are:
854
855 @table @code
856
857 @item name
858 The host name of the remote machine.
859
860 @item system
861 The system type of the remote machine---e.g., @code{"x86_64-linux"}.
862
863 @item user
864 The user account to use when connecting to the remote machine over SSH.
865 Note that the SSH key pair must @emph{not} be passphrase-protected, to
866 allow non-interactive logins.
867
868 @end table
869
870 A number of optional fields may be specified:
871
872 @table @code
873
874 @item port
875 Port number of SSH server on the machine (default: 22).
876
877 @item private-key
878 The SSH private key file to use when connecting to the machine.
879
880 Currently offloading uses GNU@tie{}lsh as its SSH client
881 (@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must
882 be an lsh key file. This may change in the future, though.
883
884 @item parallel-builds
885 The number of builds that may run in parallel on the machine (1 by
886 default.)
887
888 @item speed
889 A ``relative speed factor''. The offload scheduler will tend to prefer
890 machines with a higher speed factor.
891
892 @item features
893 A list of strings denoting specific features supported by the machine.
894 An example is @code{"kvm"} for machines that have the KVM Linux modules
895 and corresponding hardware support. Derivations can request features by
896 name, and they will be scheduled on matching build machines.
897
898 @end table
899 @end deftp
900
901 The @code{guix} command must be in the search path on the build
902 machines, since offloading works by invoking the @code{guix archive} and
903 @code{guix build} commands. In addition, the Guix modules must be in
904 @code{$GUILE_LOAD_PATH} on the build machine---you can check whether
905 this is the case by running:
906
907 @example
908 lsh build-machine guile -c "'(use-modules (guix config))'"
909 @end example
910
911 There is one last thing to do once @file{machines.scm} is in place. As
912 explained above, when offloading, files are transferred back and forth
913 between the machine stores. For this to work, you first need to
914 generate a key pair on each machine to allow the daemon to export signed
915 archives of files from the store (@pxref{Invoking guix archive}):
916
917 @example
918 # guix archive --generate-key
919 @end example
920
921 @noindent
922 Each build machine must authorize the key of the master machine so that
923 it accepts store items it receives from the master:
924
925 @example
926 # guix archive --authorize < master-public-key.txt
927 @end example
928
929 @noindent
930 Likewise, the master machine must authorize the key of each build machine.
931
932 All the fuss with keys is here to express pairwise mutual trust
933 relations between the master and the build machines. Concretely, when
934 the master receives files from a build machine (and @i{vice versa}), its
935 build daemon can make sure they are genuine, have not been tampered
936 with, and that they are signed by an authorized key.
937
938
939 @node Invoking guix-daemon
940 @section Invoking @command{guix-daemon}
941
942 The @command{guix-daemon} program implements all the functionality to
943 access the store. This includes launching build processes, running the
944 garbage collector, querying the availability of a build result, etc. It
945 is normally run as @code{root} like this:
946
947 @example
948 # guix-daemon --build-users-group=guixbuild
949 @end example
950
951 @noindent
952 For details on how to set it up, @pxref{Setting Up the Daemon}.
953
954 @cindex chroot
955 @cindex container, build environment
956 @cindex build environment
957 @cindex reproducible builds
958 By default, @command{guix-daemon} launches build processes under
959 different UIDs, taken from the build group specified with
960 @code{--build-users-group}. In addition, each build process is run in a
961 chroot environment that only contains the subset of the store that the
962 build process depends on, as specified by its derivation
963 (@pxref{Programming Interface, derivation}), plus a set of specific
964 system directories. By default, the latter contains @file{/dev} and
965 @file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
966 @dfn{container}: in addition to having its own file system tree, it has
967 a separate mount name space, its own PID name space, network name space,
968 etc. This helps achieve reproducible builds (@pxref{Features}).
969
970 When the daemon performs a build on behalf of the user, it creates a
971 build directory under @file{/tmp} or under the directory specified by
972 its @code{TMPDIR} environment variable; this directory is shared with
973 the container for the duration of the build. Be aware that using a
974 directory other than @file{/tmp} can affect build results---for example,
975 with a longer directory name, a build process that uses Unix-domain
976 sockets might hit the name length limitation for @code{sun_path}, which
977 it would otherwise not hit.
978
979 The build directory is automatically deleted upon completion, unless the
980 build failed and the client specified @option{--keep-failed}
981 (@pxref{Invoking guix build, @option{--keep-failed}}).
982
983 The following command-line options are supported:
984
985 @table @code
986 @item --build-users-group=@var{group}
987 Take users from @var{group} to run build processes (@pxref{Setting Up
988 the Daemon, build users}).
989
990 @item --no-substitutes
991 @cindex substitutes
992 Do not use substitutes for build products. That is, always build things
993 locally instead of allowing downloads of pre-built binaries
994 (@pxref{Substitutes}).
995
996 By default substitutes are used, unless the client---such as the
997 @command{guix package} command---is explicitly invoked with
998 @code{--no-substitutes}.
999
1000 When the daemon runs with @code{--no-substitutes}, clients can still
1001 explicitly enable substitution @i{via} the @code{set-build-options}
1002 remote procedure call (@pxref{The Store}).
1003
1004 @item --substitute-urls=@var{urls}
1005 @anchor{daemon-substitute-urls}
1006 Consider @var{urls} the default whitespace-separated list of substitute
1007 source URLs. When this option is omitted,
1008 @indicateurl{https://mirror.hydra.gnu.org https://hydra.gnu.org} is used
1009 (@code{mirror.hydra.gnu.org} is a mirror of @code{hydra.gnu.org}).
1010
1011 This means that substitutes may be downloaded from @var{urls}, as long
1012 as they are signed by a trusted signature (@pxref{Substitutes}).
1013
1014 @cindex build hook
1015 @item --no-build-hook
1016 Do not use the @dfn{build hook}.
1017
1018 The build hook is a helper program that the daemon can start and to
1019 which it submits build requests. This mechanism is used to offload
1020 builds to other machines (@pxref{Daemon Offload Setup}).
1021
1022 @item --cache-failures
1023 Cache build failures. By default, only successful builds are cached.
1024
1025 When this option is used, @command{guix gc --list-failures} can be used
1026 to query the set of store items marked as failed; @command{guix gc
1027 --clear-failures} removes store items from the set of cached failures.
1028 @xref{Invoking guix gc}.
1029
1030 @item --cores=@var{n}
1031 @itemx -c @var{n}
1032 Use @var{n} CPU cores to build each derivation; @code{0} means as many
1033 as available.
1034
1035 The default value is @code{0}, but it may be overridden by clients, such
1036 as the @code{--cores} option of @command{guix build} (@pxref{Invoking
1037 guix build}).
1038
1039 The effect is to define the @code{NIX_BUILD_CORES} environment variable
1040 in the build process, which can then use it to exploit internal
1041 parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
1042
1043 @item --max-jobs=@var{n}
1044 @itemx -M @var{n}
1045 Allow at most @var{n} build jobs in parallel. The default value is
1046 @code{1}. Setting it to @code{0} means that no builds will be performed
1047 locally; instead, the daemon will offload builds (@pxref{Daemon Offload
1048 Setup}), or simply fail.
1049
1050 @item --rounds=@var{N}
1051 Build each derivation @var{n} times in a row, and raise an error if
1052 consecutive build results are not bit-for-bit identical. Note that this
1053 setting can be overridden by clients such as @command{guix build}
1054 (@pxref{Invoking guix build}).
1055
1056 When used in conjunction with @option{--keep-failed}, the differing
1057 output is kept in the store, under @file{/gnu/store/@dots{}-check}.
1058 This makes it easy to look for differences between the two results.
1059
1060 @item --debug
1061 Produce debugging output.
1062
1063 This is useful to debug daemon start-up issues, but then it may be
1064 overridden by clients, for example the @code{--verbosity} option of
1065 @command{guix build} (@pxref{Invoking guix build}).
1066
1067 @item --chroot-directory=@var{dir}
1068 Add @var{dir} to the build chroot.
1069
1070 Doing this may change the result of build processes---for instance if
1071 they use optional dependencies found in @var{dir} when it is available,
1072 and not otherwise. For that reason, it is not recommended to do so.
1073 Instead, make sure that each derivation declares all the inputs that it
1074 needs.
1075
1076 @item --disable-chroot
1077 Disable chroot builds.
1078
1079 Using this option is not recommended since, again, it would allow build
1080 processes to gain access to undeclared dependencies. It is necessary,
1081 though, when @command{guix-daemon} is running under an unprivileged user
1082 account.
1083
1084 @item --disable-log-compression
1085 Disable compression of the build logs.
1086
1087 Unless @code{--lose-logs} is used, all the build logs are kept in the
1088 @var{localstatedir}. To save space, the daemon automatically compresses
1089 them with bzip2 by default. This option disables that.
1090
1091 @item --disable-deduplication
1092 @cindex deduplication
1093 Disable automatic file ``deduplication'' in the store.
1094
1095 By default, files added to the store are automatically ``deduplicated'':
1096 if a newly added file is identical to another one found in the store,
1097 the daemon makes the new file a hard link to the other file. This can
1098 noticeably reduce disk usage, at the expense of slightly increased
1099 input/output load at the end of a build process. This option disables
1100 this optimization.
1101
1102 @item --gc-keep-outputs[=yes|no]
1103 Tell whether the garbage collector (GC) must keep outputs of live
1104 derivations.
1105
1106 When set to ``yes'', the GC will keep the outputs of any live derivation
1107 available in the store---the @code{.drv} files. The default is ``no'',
1108 meaning that derivation outputs are kept only if they are GC roots.
1109
1110 @item --gc-keep-derivations[=yes|no]
1111 Tell whether the garbage collector (GC) must keep derivations
1112 corresponding to live outputs.
1113
1114 When set to ``yes'', as is the case by default, the GC keeps
1115 derivations---i.e., @code{.drv} files---as long as at least one of their
1116 outputs is live. This allows users to keep track of the origins of
1117 items in their store. Setting it to ``no'' saves a bit of disk space.
1118
1119 Note that when both @code{--gc-keep-derivations} and
1120 @code{--gc-keep-outputs} are used, the effect is to keep all the build
1121 prerequisites (the sources, compiler, libraries, and other build-time
1122 tools) of live objects in the store, regardless of whether these
1123 prerequisites are live. This is convenient for developers since it
1124 saves rebuilds or downloads.
1125
1126 @item --impersonate-linux-2.6
1127 On Linux-based systems, impersonate Linux 2.6. This means that the
1128 kernel's @code{uname} system call will report 2.6 as the release number.
1129
1130 This might be helpful to build programs that (usually wrongfully) depend
1131 on the kernel version number.
1132
1133 @item --lose-logs
1134 Do not keep build logs. By default they are kept under
1135 @code{@var{localstatedir}/guix/log}.
1136
1137 @item --system=@var{system}
1138 Assume @var{system} as the current system type. By default it is the
1139 architecture/kernel pair found at configure time, such as
1140 @code{x86_64-linux}.
1141
1142 @item --listen=@var{socket}
1143 Listen for connections on @var{socket}, the file name of a Unix-domain
1144 socket. The default socket is
1145 @file{@var{localstatedir}/daemon-socket/socket}. This option is only
1146 useful in exceptional circumstances, such as if you need to run several
1147 daemons on the same machine.
1148 @end table
1149
1150
1151 @node Application Setup
1152 @section Application Setup
1153
1154 @cindex foreign distro
1155 When using Guix on top of GNU/Linux distribution other than GuixSD---a
1156 so-called @dfn{foreign distro}---a few additional steps are needed to
1157 get everything in place. Here are some of them.
1158
1159 @subsection Locales
1160
1161 @anchor{locales-and-locpath}
1162 @cindex locales, when not on GuixSD
1163 @vindex LOCPATH
1164 @vindex GUIX_LOCPATH
1165 Packages installed @i{via} Guix will not use the locale data of the
1166 host system. Instead, you must first install one of the locale packages
1167 available with Guix and then define the @code{GUIX_LOCPATH} environment
1168 variable:
1169
1170 @example
1171 $ guix package -i glibc-locales
1172 $ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
1173 @end example
1174
1175 Note that the @code{glibc-locales} package contains data for all the
1176 locales supported by the GNU@tie{}libc and weighs in at around
1177 110@tie{}MiB. Alternatively, the @code{glibc-utf8-locales} is smaller but
1178 limited to a few UTF-8 locales.
1179
1180 The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1181 (@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1182 Manual}). There are two important differences though:
1183
1184 @enumerate
1185 @item
1186 @code{GUIX_LOCPATH} is honored only by the libc in Guix, and not by the libc
1187 provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
1188 to make sure the programs of the foreign distro will not end up loading
1189 incompatible locale data.
1190
1191 @item
1192 libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1193 @code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1194 should your Guix profile contain a mixture of programs linked against
1195 different libc version, each libc version will only try to load locale
1196 data in the right format.
1197 @end enumerate
1198
1199 This is important because the locale data format used by different libc
1200 versions may be incompatible.
1201
1202 @subsection X11 Fonts
1203
1204 The majority of graphical applications use Fontconfig to locate and
1205 load fonts and perform X11-client-side rendering. The @code{fontconfig}
1206 package in Guix looks for fonts in @file{$HOME/.guix-profile}
1207 by default. Thus, to allow graphical applications installed with Guix
1208 to display fonts, you have to install fonts with Guix as well.
1209 Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
1210 @code{font-gnu-freefont-ttf}.
1211
1212 To display text written in Chinese languages, Japanese, or Korean in
1213 graphical applications, consider installing
1214 @code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1215 has multiple outputs, one per language family (@pxref{Packages with
1216 Multiple Outputs}). For instance, the following command installs fonts
1217 for Chinese languages:
1218
1219 @example
1220 guix package -i font-adobe-source-han-sans:cn
1221 @end example
1222
1223 Older programs such as @command{xterm} do not use Fontconfig and instead
1224 rely on server-side font rendering. Such programs require to specify a
1225 full name of a font using XLFD (X Logical Font Description), like this:
1226
1227 @example
1228 -*-dejavu sans-medium-r-normal-*-*-100-*-*-*-*-*-1
1229 @end example
1230
1231 To be able to use such full names for the TrueType fonts installed in
1232 your Guix profile, you need to extend the font path of the X server:
1233
1234 @example
1235 xset +fp ~/.guix-profile/share/fonts/truetype
1236 @end example
1237
1238 After that, you can run @code{xlsfonts} (from @code{xlsfonts} package)
1239 to make sure your TrueType fonts are listed there.
1240
1241 @subsection X.509 Certificates
1242
1243 The @code{nss-certs} package provides X.509 certificates, which allow
1244 programs to authenticate Web servers accessed over HTTPS.
1245
1246 When using Guix on a foreign distro, you can install this package and
1247 define the relevant environment variables so that packages know where to
1248 look for certificates. @xref{X.509 Certificates}, for detailed
1249 information.
1250
1251 @subsection Emacs Packages
1252
1253 When you install Emacs packages with Guix, the elisp files may be placed
1254 either in @file{$HOME/.guix-profile/share/emacs/site-lisp/} or in
1255 sub-directories of
1256 @file{$HOME/.guix-profile/share/emacs/site-lisp/guix.d/}. The latter
1257 directory exists because potentially there may exist thousands of Emacs
1258 packages and storing all their files in a single directory may be not
1259 reliable (because of name conflicts). So we think using a separate
1260 directory for each package is a good idea. It is very similar to how
1261 the Emacs package system organizes the file structure (@pxref{Package
1262 Files,,, emacs, The GNU Emacs Manual}).
1263
1264 By default, Emacs (installed with Guix) ``knows'' where these packages
1265 are placed, so you do not need to perform any configuration. If, for
1266 some reason, you want to avoid auto-loading Emacs packages installed
1267 with Guix, you can do so by running Emacs with @code{--no-site-file}
1268 option (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
1269
1270 @c TODO What else?
1271
1272 @c *********************************************************************
1273 @node Package Management
1274 @chapter Package Management
1275
1276 The purpose of GNU Guix is to allow users to easily install, upgrade, and
1277 remove software packages, without having to know about their build
1278 procedures or dependencies. Guix also goes beyond this obvious set of
1279 features.
1280
1281 This chapter describes the main features of Guix, as well as the package
1282 management tools it provides. Two user interfaces are provided for
1283 routine package management tasks: A command-line interface described below
1284 (@pxref{Invoking guix package, @code{guix package}}), as well as a visual user
1285 interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}).
1286
1287 @menu
1288 * Features:: How Guix will make your life brighter.
1289 * Invoking guix package:: Package installation, removal, etc.
1290 * Substitutes:: Downloading pre-built binaries.
1291 * Packages with Multiple Outputs:: Single source package, multiple outputs.
1292 * Invoking guix gc:: Running the garbage collector.
1293 * Invoking guix pull:: Fetching the latest Guix and distribution.
1294 * Invoking guix archive:: Exporting and importing store files.
1295 @end menu
1296
1297 @node Features
1298 @section Features
1299
1300 When using Guix, each package ends up in the @dfn{package store}, in its
1301 own directory---something that resembles
1302 @file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
1303 (note that Guix comes with an Emacs extension to shorten those file
1304 names, @pxref{Emacs Prettify}.)
1305
1306 Instead of referring to these directories, users have their own
1307 @dfn{profile}, which points to the packages that they actually want to
1308 use. These profiles are stored within each user's home directory, at
1309 @code{$HOME/.guix-profile}.
1310
1311 For example, @code{alice} installs GCC 4.7.2. As a result,
1312 @file{/home/alice/.guix-profile/bin/gcc} points to
1313 @file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
1314 @code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1315 simply continues to point to
1316 @file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
1317 coexist on the same system without any interference.
1318
1319 The @command{guix package} command is the central tool to manage
1320 packages (@pxref{Invoking guix package}). It operates on the per-user
1321 profiles, and can be used @emph{with normal user privileges}.
1322
1323 The command provides the obvious install, remove, and upgrade
1324 operations. Each invocation is actually a @emph{transaction}: either
1325 the specified operation succeeds, or nothing happens. Thus, if the
1326 @command{guix package} process is terminated during the transaction,
1327 or if a power outage occurs during the transaction, then the user's
1328 profile remains in its previous state, and remains usable.
1329
1330 In addition, any package transaction may be @emph{rolled back}. So, if,
1331 for example, an upgrade installs a new version of a package that turns
1332 out to have a serious bug, users may roll back to the previous instance
1333 of their profile, which was known to work well. Similarly, the global
1334 system configuration on GuixSD is subject to
1335 transactional upgrades and roll-back
1336 (@pxref{Using the Configuration System}).
1337
1338 All packages in the package store may be @emph{garbage-collected}.
1339 Guix can determine which packages are still referenced by user
1340 profiles, and remove those that are provably no longer referenced
1341 (@pxref{Invoking guix gc}). Users may also explicitly remove old
1342 generations of their profile so that the packages they refer to can be
1343 collected.
1344
1345 @cindex reproducibility
1346 @cindex reproducible builds
1347 Finally, Guix takes a @dfn{purely functional} approach to package
1348 management, as described in the introduction (@pxref{Introduction}).
1349 Each @file{/gnu/store} package directory name contains a hash of all the
1350 inputs that were used to build that package---compiler, libraries, build
1351 scripts, etc. This direct correspondence allows users to make sure a
1352 given package installation matches the current state of their
1353 distribution. It also helps maximize @dfn{build reproducibility}:
1354 thanks to the isolated build environments that are used, a given build
1355 is likely to yield bit-identical files when performed on different
1356 machines (@pxref{Invoking guix-daemon, container}).
1357
1358 @cindex substitutes
1359 This foundation allows Guix to support @dfn{transparent binary/source
1360 deployment}. When a pre-built binary for a @file{/gnu/store} item is
1361 available from an external source---a @dfn{substitute}, Guix just
1362 downloads it and unpacks it;
1363 otherwise, it builds the package from source, locally
1364 (@pxref{Substitutes}). Because build results are usually bit-for-bit
1365 reproducible, users do not have to trust servers that provide
1366 substitutes: they can force a local build and @emph{challenge} providers
1367 (@pxref{Invoking guix challenge}).
1368
1369 Control over the build environment is a feature that is also useful for
1370 developers. The @command{guix environment} command allows developers of
1371 a package to quickly set up the right development environment for their
1372 package, without having to manually install the dependencies of the
1373 package into their profile (@pxref{Invoking guix environment}).
1374
1375 @node Invoking guix package
1376 @section Invoking @command{guix package}
1377
1378 The @command{guix package} command is the tool that allows users to
1379 install, upgrade, and remove packages, as well as rolling back to
1380 previous configurations. It operates only on the user's own profile,
1381 and works with normal user privileges (@pxref{Features}). Its syntax
1382 is:
1383
1384 @example
1385 guix package @var{options}
1386 @end example
1387
1388 Primarily, @var{options} specifies the operations to be performed during
1389 the transaction. Upon completion, a new profile is created, but
1390 previous @dfn{generations} of the profile remain available, should the user
1391 want to roll back.
1392
1393 For example, to remove @code{lua} and install @code{guile} and
1394 @code{guile-cairo} in a single transaction:
1395
1396 @example
1397 guix package -r lua -i guile guile-cairo
1398 @end example
1399
1400 @command{guix package} also supports a @dfn{declarative approach}
1401 whereby the user specifies the exact set of packages to be available and
1402 passes it @i{via} the @option{--manifest} option
1403 (@pxref{profile-manifest, @option{--manifest}}).
1404
1405 For each user, a symlink to the user's default profile is automatically
1406 created in @file{$HOME/.guix-profile}. This symlink always points to the
1407 current generation of the user's default profile. Thus, users can add
1408 @file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1409 variable, and so on.
1410 @cindex search paths
1411 If you are not using the Guix System Distribution, consider adding the
1412 following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1413 Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1414 shells get all the right environment variable definitions:
1415
1416 @example
1417 GUIX_PROFILE="$HOME/.guix-profile" \
1418 source "$HOME/.guix-profile/etc/profile"
1419 @end example
1420
1421 In a multi-user setup, user profiles are stored in a place registered as
1422 a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1423 to (@pxref{Invoking guix gc}). That directory is normally
1424 @code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1425 @var{localstatedir} is the value passed to @code{configure} as
1426 @code{--localstatedir}, and @var{user} is the user name. The
1427 @file{per-user} directory is created when @command{guix-daemon} is
1428 started, and the @var{user} sub-directory is created by @command{guix
1429 package}.
1430
1431 The @var{options} can be among the following:
1432
1433 @table @code
1434
1435 @item --install=@var{package} @dots{}
1436 @itemx -i @var{package} @dots{}
1437 Install the specified @var{package}s.
1438
1439 Each @var{package} may specify either a simple package name, such as
1440 @code{guile}, or a package name followed by an at-sign and version number,
1441 such as @code{guile@@1.8.8} or simply @code{guile@@1.8} (in the latter
1442 case, the newest version prefixed by @code{1.8} is selected.)
1443
1444 If no version number is specified, the
1445 newest available version will be selected. In addition, @var{package}
1446 may contain a colon, followed by the name of one of the outputs of the
1447 package, as in @code{gcc:doc} or @code{binutils@@2.22:lib}
1448 (@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1449 name (and optionally version) are searched for among the GNU
1450 distribution modules (@pxref{Package Modules}).
1451
1452 @cindex propagated inputs
1453 Sometimes packages have @dfn{propagated inputs}: these are dependencies
1454 that automatically get installed along with the required package
1455 (@pxref{package-propagated-inputs, @code{propagated-inputs} in
1456 @code{package} objects}, for information about propagated inputs in
1457 package definitions).
1458
1459 @anchor{package-cmd-propagated-inputs}
1460 An example is the GNU MPC library: its C header files refer to those of
1461 the GNU MPFR library, which in turn refer to those of the GMP library.
1462 Thus, when installing MPC, the MPFR and GMP libraries also get installed
1463 in the profile; removing MPC also removes MPFR and GMP---unless they had
1464 also been explicitly installed by the user.
1465
1466 Besides, packages sometimes rely on the definition of environment
1467 variables for their search paths (see explanation of
1468 @code{--search-paths} below). Any missing or possibly incorrect
1469 environment variable definitions are reported here.
1470
1471 @item --install-from-expression=@var{exp}
1472 @itemx -e @var{exp}
1473 Install the package @var{exp} evaluates to.
1474
1475 @var{exp} must be a Scheme expression that evaluates to a
1476 @code{<package>} object. This option is notably useful to disambiguate
1477 between same-named variants of a package, with expressions such as
1478 @code{(@@ (gnu packages base) guile-final)}.
1479
1480 Note that this option installs the first output of the specified
1481 package, which may be insufficient when needing a specific output of a
1482 multiple-output package.
1483
1484 @item --install-from-file=@var{file}
1485 @itemx -f @var{file}
1486 Install the package that the code within @var{file} evaluates to.
1487
1488 As an example, @var{file} might contain a definition like this
1489 (@pxref{Defining Packages}):
1490
1491 @example
1492 @verbatiminclude package-hello.scm
1493 @end example
1494
1495 Developers may find it useful to include such a @file{guix.scm} file
1496 in the root of their project source tree that can be used to test
1497 development snapshots and create reproducible development environments
1498 (@pxref{Invoking guix environment}).
1499
1500 @item --remove=@var{package} @dots{}
1501 @itemx -r @var{package} @dots{}
1502 Remove the specified @var{package}s.
1503
1504 As for @code{--install}, each @var{package} may specify a version number
1505 and/or output name in addition to the package name. For instance,
1506 @code{-r glibc:debug} would remove the @code{debug} output of
1507 @code{glibc}.
1508
1509 @item --upgrade[=@var{regexp} @dots{}]
1510 @itemx -u [@var{regexp} @dots{}]
1511 Upgrade all the installed packages. If one or more @var{regexp}s are
1512 specified, upgrade only installed packages whose name matches a
1513 @var{regexp}. Also see the @code{--do-not-upgrade} option below.
1514
1515 Note that this upgrades package to the latest version of packages found
1516 in the distribution currently installed. To update your distribution,
1517 you should regularly run @command{guix pull} (@pxref{Invoking guix
1518 pull}).
1519
1520 @item --do-not-upgrade[=@var{regexp} @dots{}]
1521 When used together with the @code{--upgrade} option, do @emph{not}
1522 upgrade any packages whose name matches a @var{regexp}. For example, to
1523 upgrade all packages in the current profile except those containing the
1524 substring ``emacs'':
1525
1526 @example
1527 $ guix package --upgrade . --do-not-upgrade emacs
1528 @end example
1529
1530 @item @anchor{profile-manifest}--manifest=@var{file}
1531 @itemx -m @var{file}
1532 @cindex profile declaration
1533 @cindex profile manifest
1534 Create a new generation of the profile from the manifest object
1535 returned by the Scheme code in @var{file}.
1536
1537 This allows you to @emph{declare} the profile's contents rather than
1538 constructing it through a sequence of @code{--install} and similar
1539 commands. The advantage is that @var{file} can be put under version
1540 control, copied to different machines to reproduce the same profile, and
1541 so on.
1542
1543 @c FIXME: Add reference to (guix profile) documentation when available.
1544 @var{file} must return a @dfn{manifest} object, which is roughly a list
1545 of packages:
1546
1547 @findex packages->manifest
1548 @example
1549 (use-package-modules guile emacs)
1550
1551 (packages->manifest
1552 (list emacs
1553 guile-2.0
1554 ;; Use a specific package output.
1555 (list guile-2.0 "debug")))
1556 @end example
1557
1558 @item --roll-back
1559 Roll back to the previous @dfn{generation} of the profile---i.e., undo
1560 the last transaction.
1561
1562 When combined with options such as @code{--install}, roll back occurs
1563 before any other actions.
1564
1565 When rolling back from the first generation that actually contains
1566 installed packages, the profile is made to point to the @dfn{zeroth
1567 generation}, which contains no files apart from its own metadata.
1568
1569 After having rolled back, installing, removing, or upgrading packages
1570 overwrites previous future generations. Thus, the history of the
1571 generations in a profile is always linear.
1572
1573 @item --switch-generation=@var{pattern}
1574 @itemx -S @var{pattern}
1575 Switch to a particular generation defined by @var{pattern}.
1576
1577 @var{pattern} may be either a generation number or a number prefixed
1578 with ``+'' or ``-''. The latter means: move forward/backward by a
1579 specified number of generations. For example, if you want to return to
1580 the latest generation after @code{--roll-back}, use
1581 @code{--switch-generation=+1}.
1582
1583 The difference between @code{--roll-back} and
1584 @code{--switch-generation=-1} is that @code{--switch-generation} will
1585 not make a zeroth generation, so if a specified generation does not
1586 exist, the current generation will not be changed.
1587
1588 @item --search-paths[=@var{kind}]
1589 @cindex search paths
1590 Report environment variable definitions, in Bash syntax, that may be
1591 needed in order to use the set of installed packages. These environment
1592 variables are used to specify @dfn{search paths} for files used by some
1593 of the installed packages.
1594
1595 For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1596 environment variables to be defined so it can look for headers and
1597 libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1598 Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1599 library are installed in the profile, then @code{--search-paths} will
1600 suggest setting these variables to @code{@var{profile}/include} and
1601 @code{@var{profile}/lib}, respectively.
1602
1603 The typical use case is to define these environment variables in the
1604 shell:
1605
1606 @example
1607 $ eval `guix package --search-paths`
1608 @end example
1609
1610 @var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1611 meaning that the returned environment variable definitions will either
1612 be exact settings, or prefixes or suffixes of the current value of these
1613 variables. When omitted, @var{kind} defaults to @code{exact}.
1614
1615 This option can also be used to compute the @emph{combined} search paths
1616 of several profiles. Consider this example:
1617
1618 @example
1619 $ guix package -p foo -i guile
1620 $ guix package -p bar -i guile-json
1621 $ guix package -p foo -p bar --search-paths
1622 @end example
1623
1624 The last command above reports about the @code{GUILE_LOAD_PATH}
1625 variable, even though, taken individually, neither @file{foo} nor
1626 @file{bar} would lead to that recommendation.
1627
1628
1629 @item --profile=@var{profile}
1630 @itemx -p @var{profile}
1631 Use @var{profile} instead of the user's default profile.
1632
1633 @item --verbose
1634 Produce verbose output. In particular, emit the build log of the
1635 environment on the standard error port.
1636
1637 @item --bootstrap
1638 Use the bootstrap Guile to build the profile. This option is only
1639 useful to distribution developers.
1640
1641 @end table
1642
1643 In addition to these actions, @command{guix package} supports the
1644 following options to query the current state of a profile, or the
1645 availability of packages:
1646
1647 @table @option
1648
1649 @item --search=@var{regexp}
1650 @itemx -s @var{regexp}
1651 @cindex searching for packages
1652 List the available packages whose name, synopsis, or description matches
1653 @var{regexp}. Print all the metadata of matching packages in
1654 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1655 GNU recutils manual}).
1656
1657 This allows specific fields to be extracted using the @command{recsel}
1658 command, for instance:
1659
1660 @example
1661 $ guix package -s malloc | recsel -p name,version
1662 name: glibc
1663 version: 2.17
1664
1665 name: libgc
1666 version: 7.2alpha6
1667 @end example
1668
1669 Similarly, to show the name of all the packages available under the
1670 terms of the GNU@tie{}LGPL version 3:
1671
1672 @example
1673 $ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1674 name: elfutils
1675
1676 name: gmp
1677 @dots{}
1678 @end example
1679
1680 It is also possible to refine search results using several @code{-s}
1681 flags. For example, the following command returns a list of board
1682 games:
1683
1684 @example
1685 $ guix package -s '\<board\>' -s game | recsel -p name
1686 name: gnubg
1687 @dots{}
1688 @end example
1689
1690 If we were to omit @code{-s game}, we would also get software packages
1691 that deal with printed circuit boards; removing the angle brackets
1692 around @code{board} would further add packages that have to do with
1693 keyboards.
1694
1695 And now for a more elaborate example. The following command searches
1696 for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1697 libraries, and prints the name and synopsis of the matching packages:
1698
1699 @example
1700 $ guix package -s crypto -s library | \
1701 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1702 @end example
1703
1704 @noindent
1705 @xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1706 information on @dfn{selection expressions} for @code{recsel -e}.
1707
1708 @item --show=@var{package}
1709 Show details about @var{package}, taken from the list of available packages, in
1710 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1711 recutils manual}).
1712
1713 @example
1714 $ guix package --show=python | recsel -p name,version
1715 name: python
1716 version: 2.7.6
1717
1718 name: python
1719 version: 3.3.5
1720 @end example
1721
1722 You may also specify the full name of a package to only get details about a
1723 specific version of it:
1724 @example
1725 $ guix package --show=python@@3.4 | recsel -p name,version
1726 name: python
1727 version: 3.4.3
1728 @end example
1729
1730
1731
1732 @item --list-installed[=@var{regexp}]
1733 @itemx -I [@var{regexp}]
1734 List the currently installed packages in the specified profile, with the
1735 most recently installed packages shown last. When @var{regexp} is
1736 specified, list only installed packages whose name matches @var{regexp}.
1737
1738 For each installed package, print the following items, separated by
1739 tabs: the package name, its version string, the part of the package that
1740 is installed (for instance, @code{out} for the default output,
1741 @code{include} for its headers, etc.), and the path of this package in
1742 the store.
1743
1744 @item --list-available[=@var{regexp}]
1745 @itemx -A [@var{regexp}]
1746 List packages currently available in the distribution for this system
1747 (@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1748 installed packages whose name matches @var{regexp}.
1749
1750 For each package, print the following items separated by tabs: its name,
1751 its version string, the parts of the package (@pxref{Packages with
1752 Multiple Outputs}), and the source location of its definition.
1753
1754 @item --list-generations[=@var{pattern}]
1755 @itemx -l [@var{pattern}]
1756 Return a list of generations along with their creation dates; for each
1757 generation, show the installed packages, with the most recently
1758 installed packages shown last. Note that the zeroth generation is never
1759 shown.
1760
1761 For each installed package, print the following items, separated by
1762 tabs: the name of a package, its version string, the part of the package
1763 that is installed (@pxref{Packages with Multiple Outputs}), and the
1764 location of this package in the store.
1765
1766 When @var{pattern} is used, the command returns only matching
1767 generations. Valid patterns include:
1768
1769 @itemize
1770 @item @emph{Integers and comma-separated integers}. Both patterns denote
1771 generation numbers. For instance, @code{--list-generations=1} returns
1772 the first one.
1773
1774 And @code{--list-generations=1,8,2} outputs three generations in the
1775 specified order. Neither spaces nor trailing commas are allowed.
1776
1777 @item @emph{Ranges}. @code{--list-generations=2..9} prints the
1778 specified generations and everything in between. Note that the start of
1779 a range must be smaller than its end.
1780
1781 It is also possible to omit the endpoint. For example,
1782 @code{--list-generations=2..}, returns all generations starting from the
1783 second one.
1784
1785 @item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1786 or months by passing an integer along with the first letter of the
1787 duration. For example, @code{--list-generations=20d} lists generations
1788 that are up to 20 days old.
1789 @end itemize
1790
1791 @item --delete-generations[=@var{pattern}]
1792 @itemx -d [@var{pattern}]
1793 When @var{pattern} is omitted, delete all generations except the current
1794 one.
1795
1796 This command accepts the same patterns as @option{--list-generations}.
1797 When @var{pattern} is specified, delete the matching generations. When
1798 @var{pattern} specifies a duration, generations @emph{older} than the
1799 specified duration match. For instance, @code{--delete-generations=1m}
1800 deletes generations that are more than one month old.
1801
1802 If the current generation matches, it is @emph{not} deleted. Also, the
1803 zeroth generation is never deleted.
1804
1805 Note that deleting generations prevents rolling back to them.
1806 Consequently, this command must be used with care.
1807
1808 @end table
1809
1810 Finally, since @command{guix package} may actually start build
1811 processes, it supports all the common build options (@pxref{Common Build
1812 Options}). It also supports package transformation options, such as
1813 @option{--with-source} (@pxref{Package Transformation Options}).
1814 However, note that package transformations are lost when upgrading; to
1815 preserve transformations across upgrades, you should define your own
1816 package variant in a Guile module and add it to @code{GUIX_PACKAGE_PATH}
1817 (@pxref{Defining Packages}).
1818
1819
1820 @node Substitutes
1821 @section Substitutes
1822
1823 @cindex substitutes
1824 @cindex pre-built binaries
1825 Guix supports transparent source/binary deployment, which means that it
1826 can either build things locally, or download pre-built items from a
1827 server. We call these pre-built items @dfn{substitutes}---they are
1828 substitutes for local build results. In many cases, downloading a
1829 substitute is much faster than building things locally.
1830
1831 Substitutes can be anything resulting from a derivation build
1832 (@pxref{Derivations}). Of course, in the common case, they are
1833 pre-built package binaries, but source tarballs, for instance, which
1834 also result from derivation builds, can be available as substitutes.
1835
1836 The @code{hydra.gnu.org} server is a front-end to a build farm that
1837 builds packages from the GNU distribution continuously for some
1838 architectures, and makes them available as substitutes (@pxref{Emacs
1839 Hydra}, for information on how to query the continuous integration
1840 server). This is the
1841 default source of substitutes; it can be overridden by passing the
1842 @option{--substitute-urls} option either to @command{guix-daemon}
1843 (@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1844 or to client tools such as @command{guix package}
1845 (@pxref{client-substitute-urls,, client @option{--substitute-urls}
1846 option}).
1847
1848 Substitute URLs can be either HTTP or HTTPS@footnote{For HTTPS access,
1849 the Guile bindings of GnuTLS must be installed. @xref{Requirements}.}
1850 HTTPS is recommended because communications are encrypted; conversely,
1851 using HTTP makes all communications visible to an eavesdropper, who
1852 could use the information gathered to determine, for instance, whether
1853 your system has unpatched security vulnerabilities.
1854
1855 @cindex security
1856 @cindex digital signatures
1857 To allow Guix to download substitutes from @code{hydra.gnu.org} or a
1858 mirror thereof, you
1859 must add its public key to the access control list (ACL) of archive
1860 imports, using the @command{guix archive} command (@pxref{Invoking guix
1861 archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1862 be compromised and to serve genuine substitutes.
1863
1864 This public key is installed along with Guix, in
1865 @code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1866 the installation prefix of Guix. If you installed Guix from source,
1867 make sure you checked the GPG signature of
1868 @file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1869 Then, you can run something like this:
1870
1871 @example
1872 # guix archive --authorize < hydra.gnu.org.pub
1873 @end example
1874
1875 Once this is in place, the output of a command like @code{guix build}
1876 should change from something like:
1877
1878 @example
1879 $ guix build emacs --dry-run
1880 The following derivations would be built:
1881 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1882 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1883 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1884 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1885 @dots{}
1886 @end example
1887
1888 @noindent
1889 to something like:
1890
1891 @example
1892 $ guix build emacs --dry-run
1893 The following files would be downloaded:
1894 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1895 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1896 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1897 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1898 @dots{}
1899 @end example
1900
1901 @noindent
1902 This indicates that substitutes from @code{hydra.gnu.org} are usable and
1903 will be downloaded, when possible, for future builds.
1904
1905 Guix ignores substitutes that are not signed, or that are not signed by
1906 one of the keys listed in the ACL. It also detects and raises an error
1907 when attempting to use a substitute that has been tampered with.
1908
1909 @vindex http_proxy
1910 Substitutes are downloaded over HTTP or HTTPS.
1911 The @code{http_proxy} environment
1912 variable can be set in the environment of @command{guix-daemon} and is
1913 honored for downloads of substitutes. Note that the value of
1914 @code{http_proxy} in the environment where @command{guix build},
1915 @command{guix package}, and other client commands are run has
1916 @emph{absolutely no effect}.
1917
1918 When using HTTPS, the server's X.509 certificate is @emph{not} validated
1919 (in other words, the server is not authenticated), contrary to what
1920 HTTPS clients such as Web browsers usually do. This is because Guix
1921 authenticates substitute information itself, as explained above, which
1922 is what we care about (whereas X.509 certificates are about
1923 authenticating bindings between domain names and public keys.)
1924
1925 The substitute mechanism can be disabled globally by running
1926 @code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1927 guix-daemon}). It can also be disabled temporarily by passing the
1928 @code{--no-substitutes} option to @command{guix package}, @command{guix
1929 build}, and other command-line tools.
1930
1931
1932 @unnumberedsubsec On Trusting Binaries
1933
1934 Today, each individual's control over their own computing is at the
1935 mercy of institutions, corporations, and groups with enough power and
1936 determination to subvert the computing infrastructure and exploit its
1937 weaknesses. While using @code{hydra.gnu.org} substitutes can be
1938 convenient, we encourage users to also build on their own, or even run
1939 their own build farm, such that @code{hydra.gnu.org} is less of an
1940 interesting target. One way to help is by publishing the software you
1941 build using @command{guix publish} so that others have one more choice
1942 of server to download substitutes from (@pxref{Invoking guix publish}).
1943
1944 Guix has the foundations to maximize build reproducibility
1945 (@pxref{Features}). In most cases, independent builds of a given
1946 package or derivation should yield bit-identical results. Thus, through
1947 a diverse set of independent package builds, we can strengthen the
1948 integrity of our systems. The @command{guix challenge} command aims to
1949 help users assess substitute servers, and to assist developers in
1950 finding out about non-deterministic package builds (@pxref{Invoking guix
1951 challenge}). Similarly, the @option{--check} option of @command{guix
1952 build} allows users to check whether previously-installed substitutes
1953 are genuine by rebuilding them locally (@pxref{build-check,
1954 @command{guix build --check}}).
1955
1956 In the future, we want Guix to have support to publish and retrieve
1957 binaries to/from other users, in a peer-to-peer fashion. If you would
1958 like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1959
1960
1961 @node Packages with Multiple Outputs
1962 @section Packages with Multiple Outputs
1963
1964 @cindex multiple-output packages
1965 @cindex package outputs
1966
1967 Often, packages defined in Guix have a single @dfn{output}---i.e., the
1968 source package leads to exactly one directory in the store. When running
1969 @command{guix package -i glibc}, one installs the default output of the
1970 GNU libc package; the default output is called @code{out}, but its name
1971 can be omitted as shown in this command. In this particular case, the
1972 default output of @code{glibc} contains all the C header files, shared
1973 libraries, static libraries, Info documentation, and other supporting
1974 files.
1975
1976 Sometimes it is more appropriate to separate the various types of files
1977 produced from a single source package into separate outputs. For
1978 instance, the GLib C library (used by GTK+ and related packages)
1979 installs more than 20 MiB of reference documentation as HTML pages.
1980 To save space for users who do not need it, the documentation goes to a
1981 separate output, called @code{doc}. To install the main GLib output,
1982 which contains everything but the documentation, one would run:
1983
1984 @example
1985 guix package -i glib
1986 @end example
1987
1988 The command to install its documentation is:
1989
1990 @example
1991 guix package -i glib:doc
1992 @end example
1993
1994 Some packages install programs with different ``dependency footprints''.
1995 For instance, the WordNet package installs both command-line tools and
1996 graphical user interfaces (GUIs). The former depend solely on the C
1997 library, whereas the latter depend on Tcl/Tk and the underlying X
1998 libraries. In this case, we leave the command-line tools in the default
1999 output, whereas the GUIs are in a separate output. This allows users
2000 who do not need the GUIs to save space. The @command{guix size} command
2001 can help find out about such situations (@pxref{Invoking guix size}).
2002 @command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
2003
2004 There are several such multiple-output packages in the GNU distribution.
2005 Other conventional output names include @code{lib} for libraries and
2006 possibly header files, @code{bin} for stand-alone programs, and
2007 @code{debug} for debugging information (@pxref{Installing Debugging
2008 Files}). The outputs of a packages are listed in the third column of
2009 the output of @command{guix package --list-available} (@pxref{Invoking
2010 guix package}).
2011
2012
2013 @node Invoking guix gc
2014 @section Invoking @command{guix gc}
2015
2016 @cindex garbage collector
2017 Packages that are installed, but not used, may be @dfn{garbage-collected}.
2018 The @command{guix gc} command allows users to explicitly run the garbage
2019 collector to reclaim space from the @file{/gnu/store} directory. It is
2020 the @emph{only} way to remove files from @file{/gnu/store}---removing
2021 files or directories manually may break it beyond repair!
2022
2023 The garbage collector has a set of known @dfn{roots}: any file under
2024 @file{/gnu/store} reachable from a root is considered @dfn{live} and
2025 cannot be deleted; any other file is considered @dfn{dead} and may be
2026 deleted. The set of garbage collector roots includes default user
2027 profiles, and may be augmented with @command{guix build --root}, for
2028 example (@pxref{Invoking guix build}).
2029
2030 Prior to running @code{guix gc --collect-garbage} to make space, it is
2031 often useful to remove old generations from user profiles; that way, old
2032 package builds referenced by those generations can be reclaimed. This
2033 is achieved by running @code{guix package --delete-generations}
2034 (@pxref{Invoking guix package}).
2035
2036 The @command{guix gc} command has three modes of operation: it can be
2037 used to garbage-collect any dead files (the default), to delete specific
2038 files (the @code{--delete} option), to print garbage-collector
2039 information, or for more advanced queries. The garbage collection
2040 options are as follows:
2041
2042 @table @code
2043 @item --collect-garbage[=@var{min}]
2044 @itemx -C [@var{min}]
2045 Collect garbage---i.e., unreachable @file{/gnu/store} files and
2046 sub-directories. This is the default operation when no option is
2047 specified.
2048
2049 When @var{min} is given, stop once @var{min} bytes have been collected.
2050 @var{min} may be a number of bytes, or it may include a unit as a
2051 suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
2052 (@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
2053
2054 When @var{min} is omitted, collect all the garbage.
2055
2056 @item --free-space=@var{free}
2057 @itemx -F @var{free}
2058 Collect garbage until @var{free} space is available under
2059 @file{/gnu/store}, if possible; @var{free} denotes storage space, such
2060 as @code{500MiB}, as described above.
2061
2062 When @var{free} or more is already available in @file{/gnu/store}, do
2063 nothing and exit immediately.
2064
2065 @item --delete
2066 @itemx -d
2067 Attempt to delete all the store files and directories specified as
2068 arguments. This fails if some of the files are not in the store, or if
2069 they are still live.
2070
2071 @item --list-failures
2072 List store items corresponding to cached build failures.
2073
2074 This prints nothing unless the daemon was started with
2075 @option{--cache-failures} (@pxref{Invoking guix-daemon,
2076 @option{--cache-failures}}).
2077
2078 @item --clear-failures
2079 Remove the specified store items from the failed-build cache.
2080
2081 Again, this option only makes sense when the daemon is started with
2082 @option{--cache-failures}. Otherwise, it does nothing.
2083
2084 @item --list-dead
2085 Show the list of dead files and directories still present in the
2086 store---i.e., files and directories no longer reachable from any root.
2087
2088 @item --list-live
2089 Show the list of live store files and directories.
2090
2091 @end table
2092
2093 In addition, the references among existing store files can be queried:
2094
2095 @table @code
2096
2097 @item --references
2098 @itemx --referrers
2099 List the references (respectively, the referrers) of store files given
2100 as arguments.
2101
2102 @item --requisites
2103 @itemx -R
2104 @cindex closure
2105 List the requisites of the store files passed as arguments. Requisites
2106 include the store files themselves, their references, and the references
2107 of these, recursively. In other words, the returned list is the
2108 @dfn{transitive closure} of the store files.
2109
2110 @xref{Invoking guix size}, for a tool to profile the size of the closure
2111 of an element. @xref{Invoking guix graph}, for a tool to visualize
2112 the graph of references.
2113
2114 @end table
2115
2116 Lastly, the following options allow you to check the integrity of the
2117 store and to control disk usage.
2118
2119 @table @option
2120
2121 @item --verify[=@var{options}]
2122 @cindex integrity, of the store
2123 @cindex integrity checking
2124 Verify the integrity of the store.
2125
2126 By default, make sure that all the store items marked as valid in the
2127 database of the daemon actually exist in @file{/gnu/store}.
2128
2129 When provided, @var{options} must be a comma-separated list containing one
2130 or more of @code{contents} and @code{repair}.
2131
2132 When passing @option{--verify=contents}, the daemon computes the
2133 content hash of each store item and compares it against its hash in the
2134 database. Hash mismatches are reported as data corruptions. Because it
2135 traverses @emph{all the files in the store}, this command can take a
2136 long time, especially on systems with a slow disk drive.
2137
2138 @cindex repairing the store
2139 Using @option{--verify=repair} or @option{--verify=contents,repair}
2140 causes the daemon to try to repair corrupt store items by fetching
2141 substitutes for them (@pxref{Substitutes}). Because repairing is not
2142 atomic, and thus potentially dangerous, it is available only to the
2143 system administrator.
2144
2145 @item --optimize
2146 @cindex deduplication
2147 Optimize the store by hard-linking identical files---this is
2148 @dfn{deduplication}.
2149
2150 The daemon performs deduplication after each successful build or archive
2151 import, unless it was started with @code{--disable-deduplication}
2152 (@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
2153 this option is primarily useful when the daemon was running with
2154 @code{--disable-deduplication}.
2155
2156 @end table
2157
2158 @node Invoking guix pull
2159 @section Invoking @command{guix pull}
2160
2161 Packages are installed or upgraded to the latest version available in
2162 the distribution currently available on your local machine. To update
2163 that distribution, along with the Guix tools, you must run @command{guix
2164 pull}: the command downloads the latest Guix source code and package
2165 descriptions, and deploys it.
2166
2167 On completion, @command{guix package} will use packages and package
2168 versions from this just-retrieved copy of Guix. Not only that, but all
2169 the Guix commands and Scheme modules will also be taken from that latest
2170 version. New @command{guix} sub-commands added by the update also
2171 become available.
2172
2173 Any user can update their Guix copy using @command{guix pull}, and the
2174 effect is limited to the user who run @command{guix pull}. For
2175 instance, when user @code{root} runs @command{guix pull}, this has no
2176 effect on the version of Guix that user @code{alice} sees, and vice
2177 versa@footnote{Under the hood, @command{guix pull} updates the
2178 @file{~/.config/guix/latest} symbolic link to point to the latest Guix,
2179 and the @command{guix} command loads code from there.}.
2180
2181 The @command{guix pull} command is usually invoked with no arguments,
2182 but it supports the following options:
2183
2184 @table @code
2185 @item --verbose
2186 Produce verbose output, writing build logs to the standard error output.
2187
2188 @item --url=@var{url}
2189 Download the source tarball of Guix from @var{url}.
2190
2191 By default, the tarball is taken from its canonical address at
2192 @code{gnu.org}, for the stable branch of Guix.
2193
2194 @item --bootstrap
2195 Use the bootstrap Guile to build the latest Guix. This option is only
2196 useful to Guix developers.
2197 @end table
2198
2199
2200 @node Invoking guix archive
2201 @section Invoking @command{guix archive}
2202
2203 The @command{guix archive} command allows users to @dfn{export} files
2204 from the store into a single archive, and to later @dfn{import} them.
2205 In particular, it allows store files to be transferred from one machine
2206 to the store on another machine.
2207
2208 To export store files as an archive to standard output, run:
2209
2210 @example
2211 guix archive --export @var{options} @var{specifications}...
2212 @end example
2213
2214 @var{specifications} may be either store file names or package
2215 specifications, as for @command{guix package} (@pxref{Invoking guix
2216 package}). For instance, the following command creates an archive
2217 containing the @code{gui} output of the @code{git} package and the main
2218 output of @code{emacs}:
2219
2220 @example
2221 guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
2222 @end example
2223
2224 If the specified packages are not built yet, @command{guix archive}
2225 automatically builds them. The build process may be controlled with the
2226 common build options (@pxref{Common Build Options}).
2227
2228 To transfer the @code{emacs} package to a machine connected over SSH,
2229 one would run:
2230
2231 @example
2232 guix archive --export -r emacs | ssh the-machine guix archive --import
2233 @end example
2234
2235 @noindent
2236 Similarly, a complete user profile may be transferred from one machine
2237 to another like this:
2238
2239 @example
2240 guix archive --export -r $(readlink -f ~/.guix-profile) | \
2241 ssh the-machine guix-archive --import
2242 @end example
2243
2244 @noindent
2245 However, note that, in both examples, all of @code{emacs} and the
2246 profile as well as all of their dependencies are transferred (due to
2247 @code{-r}), regardless of what is already available in the store on the
2248 target machine. The @code{--missing} option can help figure out which
2249 items are missing from the target store.
2250
2251 Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
2252 comparable in spirit to `tar', but with a few noteworthy differences
2253 that make it more appropriate for our purposes. First, rather than
2254 recording all Unix metadata for each file, the Nar format only mentions
2255 the file type (regular, directory, or symbolic link); Unix permissions
2256 and owner/group are dismissed. Second, the order in which directory
2257 entries are stored always follows the order of file names according to
2258 the C locale collation order. This makes archive production fully
2259 deterministic.
2260
2261 When exporting, the daemon digitally signs the contents of the archive,
2262 and that digital signature is appended. When importing, the daemon
2263 verifies the signature and rejects the import in case of an invalid
2264 signature or if the signing key is not authorized.
2265 @c FIXME: Add xref to daemon doc about signatures.
2266
2267 The main options are:
2268
2269 @table @code
2270 @item --export
2271 Export the specified store files or packages (see below.) Write the
2272 resulting archive to the standard output.
2273
2274 Dependencies are @emph{not} included in the output, unless
2275 @code{--recursive} is passed.
2276
2277 @item -r
2278 @itemx --recursive
2279 When combined with @code{--export}, this instructs @command{guix
2280 archive} to include dependencies of the given items in the archive.
2281 Thus, the resulting archive is self-contained: it contains the closure
2282 of the exported store items.
2283
2284 @item --import
2285 Read an archive from the standard input, and import the files listed
2286 therein into the store. Abort if the archive has an invalid digital
2287 signature, or if it is signed by a public key not among the authorized
2288 keys (see @code{--authorize} below.)
2289
2290 @item --missing
2291 Read a list of store file names from the standard input, one per line,
2292 and write on the standard output the subset of these files missing from
2293 the store.
2294
2295 @item --generate-key[=@var{parameters}]
2296 @cindex signing, archives
2297 Generate a new key pair for the daemon. This is a prerequisite before
2298 archives can be exported with @code{--export}. Note that this operation
2299 usually takes time, because it needs to gather enough entropy to
2300 generate the key pair.
2301
2302 The generated key pair is typically stored under @file{/etc/guix}, in
2303 @file{signing-key.pub} (public key) and @file{signing-key.sec} (private
2304 key, which must be kept secret.) When @var{parameters} is omitted,
2305 an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2306 versions before 1.6.0, it is a 4096-bit RSA key.
2307 Alternatively, @var{parameters} can specify
2308 @code{genkey} parameters suitable for Libgcrypt (@pxref{General
2309 public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2310 Libgcrypt Reference Manual}).
2311
2312 @item --authorize
2313 @cindex authorizing, archives
2314 Authorize imports signed by the public key passed on standard input.
2315 The public key must be in ``s-expression advanced format''---i.e., the
2316 same format as the @file{signing-key.pub} file.
2317
2318 The list of authorized keys is kept in the human-editable file
2319 @file{/etc/guix/acl}. The file contains
2320 @url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2321 s-expressions''} and is structured as an access-control list in the
2322 @url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2323 (SPKI)}.
2324
2325 @item --extract=@var{directory}
2326 @itemx -x @var{directory}
2327 Read a single-item archive as served by substitute servers
2328 (@pxref{Substitutes}) and extract it to @var{directory}. This is a
2329 low-level operation needed in only very narrow use cases; see below.
2330
2331 For example, the following command extracts the substitute for Emacs
2332 served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2333
2334 @example
2335 $ wget -O - \
2336 https://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
2337 | bunzip2 | guix archive -x /tmp/emacs
2338 @end example
2339
2340 Single-item archives are different from multiple-item archives produced
2341 by @command{guix archive --export}; they contain a single store item,
2342 and they do @emph{not} embed a signature. Thus this operation does
2343 @emph{no} signature verification and its output should be considered
2344 unsafe.
2345
2346 The primary purpose of this operation is to facilitate inspection of
2347 archive contents coming from possibly untrusted substitute servers.
2348
2349 @end table
2350
2351 @c *********************************************************************
2352 @include emacs.texi
2353
2354 @c *********************************************************************
2355 @node Programming Interface
2356 @chapter Programming Interface
2357
2358 GNU Guix provides several Scheme programming interfaces (APIs) to
2359 define, build, and query packages. The first interface allows users to
2360 write high-level package definitions. These definitions refer to
2361 familiar packaging concepts, such as the name and version of a package,
2362 its build system, and its dependencies. These definitions can then be
2363 turned into concrete build actions.
2364
2365 Build actions are performed by the Guix daemon, on behalf of users. In a
2366 standard setup, the daemon has write access to the store---the
2367 @file{/gnu/store} directory---whereas users do not. The recommended
2368 setup also has the daemon perform builds in chroots, under a specific
2369 build users, to minimize interference with the rest of the system.
2370
2371 @cindex derivation
2372 Lower-level APIs are available to interact with the daemon and the
2373 store. To instruct the daemon to perform a build action, users actually
2374 provide it with a @dfn{derivation}. A derivation is a low-level
2375 representation of the build actions to be taken, and the environment in
2376 which they should occur---derivations are to package definitions what
2377 assembly is to C programs. The term ``derivation'' comes from the fact
2378 that build results @emph{derive} from them.
2379
2380 This chapter describes all these APIs in turn, starting from high-level
2381 package definitions.
2382
2383 @menu
2384 * Defining Packages:: Defining new packages.
2385 * Build Systems:: Specifying how packages are built.
2386 * The Store:: Manipulating the package store.
2387 * Derivations:: Low-level interface to package derivations.
2388 * The Store Monad:: Purely functional interface to the store.
2389 * G-Expressions:: Manipulating build expressions.
2390 @end menu
2391
2392 @node Defining Packages
2393 @section Defining Packages
2394
2395 The high-level interface to package definitions is implemented in the
2396 @code{(guix packages)} and @code{(guix build-system)} modules. As an
2397 example, the package definition, or @dfn{recipe}, for the GNU Hello
2398 package looks like this:
2399
2400 @example
2401 (define-module (gnu packages hello)
2402 #:use-module (guix packages)
2403 #:use-module (guix download)
2404 #:use-module (guix build-system gnu)
2405 #:use-module (guix licenses)
2406 #:use-module (gnu packages gawk))
2407
2408 (define-public hello
2409 (package
2410 (name "hello")
2411 (version "2.10")
2412 (source (origin
2413 (method url-fetch)
2414 (uri (string-append "mirror://gnu/hello/hello-" version
2415 ".tar.gz"))
2416 (sha256
2417 (base32
2418 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
2419 (build-system gnu-build-system)
2420 (arguments '(#:configure-flags '("--enable-silent-rules")))
2421 (inputs `(("gawk" ,gawk)))
2422 (synopsis "Hello, GNU world: An example GNU package")
2423 (description "Guess what GNU Hello prints!")
2424 (home-page "http://www.gnu.org/software/hello/")
2425 (license gpl3+)))
2426 @end example
2427
2428 @noindent
2429 Without being a Scheme expert, the reader may have guessed the meaning
2430 of the various fields here. This expression binds the variable
2431 @code{hello} to a @code{<package>} object, which is essentially a record
2432 (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2433 This package object can be inspected using procedures found in the
2434 @code{(guix packages)} module; for instance, @code{(package-name hello)}
2435 returns---surprise!---@code{"hello"}.
2436
2437 With luck, you may be able to import part or all of the definition of
2438 the package you are interested in from another repository, using the
2439 @code{guix import} command (@pxref{Invoking guix import}).
2440
2441 In the example above, @var{hello} is defined in a module of its own,
2442 @code{(gnu packages hello)}. Technically, this is not strictly
2443 necessary, but it is convenient to do so: all the packages defined in
2444 modules under @code{(gnu packages @dots{})} are automatically known to
2445 the command-line tools (@pxref{Package Modules}).
2446
2447 There are a few points worth noting in the above package definition:
2448
2449 @itemize
2450 @item
2451 The @code{source} field of the package is an @code{<origin>} object
2452 (@pxref{origin Reference}, for the complete reference).
2453 Here, the @code{url-fetch} method from @code{(guix download)} is used,
2454 meaning that the source is a file to be downloaded over FTP or HTTP.
2455
2456 The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2457 the GNU mirrors defined in @code{(guix download)}.
2458
2459 The @code{sha256} field specifies the expected SHA256 hash of the file
2460 being downloaded. It is mandatory, and allows Guix to check the
2461 integrity of the file. The @code{(base32 @dots{})} form introduces the
2462 base32 representation of the hash. You can obtain this information with
2463 @code{guix download} (@pxref{Invoking guix download}) and @code{guix
2464 hash} (@pxref{Invoking guix hash}).
2465
2466 @cindex patches
2467 When needed, the @code{origin} form can also have a @code{patches} field
2468 listing patches to be applied, and a @code{snippet} field giving a
2469 Scheme expression to modify the source code.
2470
2471 @item
2472 @cindex GNU Build System
2473 The @code{build-system} field specifies the procedure to build the
2474 package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2475 represents the familiar GNU Build System, where packages may be
2476 configured, built, and installed with the usual @code{./configure &&
2477 make && make check && make install} command sequence.
2478
2479 @item
2480 The @code{arguments} field specifies options for the build system
2481 (@pxref{Build Systems}). Here it is interpreted by
2482 @var{gnu-build-system} as a request run @file{configure} with the
2483 @code{--enable-silent-rules} flag.
2484
2485 @cindex quote
2486 @cindex quoting
2487 @findex '
2488 @findex quote
2489 What about these quote (@code{'}) characters? They are Scheme syntax to
2490 introduce a literal list; @code{'} is synonymous with @code{quote}.
2491 @xref{Expression Syntax, quoting,, guile, GNU Guile Reference Manual},
2492 for details. Here the value of the @code{arguments} field is a list of
2493 arguments passed to the build system down the road, as with @code{apply}
2494 (@pxref{Fly Evaluation, @code{apply},, guile, GNU Guile Reference
2495 Manual}).
2496
2497 The hash-colon (@code{#:}) sequence defines a Scheme @dfn{keyword}
2498 (@pxref{Keywords,,, guile, GNU Guile Reference Manual}), and
2499 @code{#:configure-flags} is a keyword used to pass a keyword argument
2500 to the build system (@pxref{Coding With Keywords,,, guile, GNU Guile
2501 Reference Manual}).
2502
2503 @item
2504 The @code{inputs} field specifies inputs to the build process---i.e.,
2505 build-time or run-time dependencies of the package. Here, we define an
2506 input called @code{"gawk"} whose value is that of the @var{gawk}
2507 variable; @var{gawk} is itself bound to a @code{<package>} object.
2508
2509 @cindex backquote (quasiquote)
2510 @findex `
2511 @findex quasiquote
2512 @cindex comma (unquote)
2513 @findex ,
2514 @findex unquote
2515 @findex ,@@
2516 @findex unquote-splicing
2517 Again, @code{`} (a backquote, synonymous with @code{quasiquote}) allows
2518 us to introduce a literal list in the @code{inputs} field, while
2519 @code{,} (a comma, synonymous with @code{unquote}) allows us to insert a
2520 value in that list (@pxref{Expression Syntax, unquote,, guile, GNU Guile
2521 Reference Manual}).
2522
2523 Note that GCC, Coreutils, Bash, and other essential tools do not need to
2524 be specified as inputs here. Instead, @var{gnu-build-system} takes care
2525 of ensuring that they are present (@pxref{Build Systems}).
2526
2527 However, any other dependencies need to be specified in the
2528 @code{inputs} field. Any dependency not specified here will simply be
2529 unavailable to the build process, possibly leading to a build failure.
2530 @end itemize
2531
2532 @xref{package Reference}, for a full description of possible fields.
2533
2534 Once a package definition is in place, the
2535 package may actually be built using the @code{guix build} command-line
2536 tool (@pxref{Invoking guix build}). You can easily jump back to the
2537 package definition using the @command{guix edit} command
2538 (@pxref{Invoking guix edit}).
2539 @xref{Packaging Guidelines}, for
2540 more information on how to test package definitions, and
2541 @ref{Invoking guix lint}, for information on how to check a definition
2542 for style conformance.
2543
2544 Finally, updating the package definition to a new upstream version
2545 can be partly automated by the @command{guix refresh} command
2546 (@pxref{Invoking guix refresh}).
2547
2548 Behind the scenes, a derivation corresponding to the @code{<package>}
2549 object is first computed by the @code{package-derivation} procedure.
2550 That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
2551 The build actions it prescribes may then be realized by using the
2552 @code{build-derivations} procedure (@pxref{The Store}).
2553
2554 @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
2555 Return the @code{<derivation>} object of @var{package} for @var{system}
2556 (@pxref{Derivations}).
2557
2558 @var{package} must be a valid @code{<package>} object, and @var{system}
2559 must be a string denoting the target system type---e.g.,
2560 @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2561 must be a connection to the daemon, which operates on the store
2562 (@pxref{The Store}).
2563 @end deffn
2564
2565 @noindent
2566 @cindex cross-compilation
2567 Similarly, it is possible to compute a derivation that cross-builds a
2568 package for some other system:
2569
2570 @deffn {Scheme Procedure} package-cross-derivation @var{store} @
2571 @var{package} @var{target} [@var{system}]
2572 Return the @code{<derivation>} object of @var{package} cross-built from
2573 @var{system} to @var{target}.
2574
2575 @var{target} must be a valid GNU triplet denoting the target hardware
2576 and operating system, such as @code{"mips64el-linux-gnu"}
2577 (@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2578 Configure and Build System}).
2579 @end deffn
2580
2581 @cindex package transformations
2582 @cindex input rewriting
2583 @cindex dependency tree rewriting
2584 Packages can be manipulated in arbitrary ways. An example of a useful
2585 transformation is @dfn{input rewriting}, whereby the dependency tree of
2586 a package is rewritten by replacing specific inputs by others:
2587
2588 @deffn {Scheme Procedure} package-input-rewriting @var{replacements} @
2589 [@var{rewrite-name}]
2590 Return a procedure that, when passed a package, replaces its direct and
2591 indirect dependencies (but not its implicit inputs) according to
2592 @var{replacements}. @var{replacements} is a list of package pairs; the
2593 first element of each pair is the package to replace, and the second one
2594 is the replacement.
2595
2596 Optionally, @var{rewrite-name} is a one-argument procedure that takes
2597 the name of a package and returns its new name after rewrite.
2598 @end deffn
2599
2600 @noindent
2601 Consider this example:
2602
2603 @example
2604 (define libressl-instead-of-openssl
2605 ;; This is a procedure to replace OPENSSL by LIBRESSL,
2606 ;; recursively.
2607 (package-input-rewriting `((,openssl . ,libressl))))
2608
2609 (define git-with-libressl
2610 (libressl-instead-of-openssl git))
2611 @end example
2612
2613 @noindent
2614 Here we first define a rewriting procedure that replaces @var{openssl}
2615 with @var{libressl}. Then we use it to define a @dfn{variant} of the
2616 @var{git} package that uses @var{libressl} instead of @var{openssl}.
2617 This is exactly what the @option{--with-input} command-line option does
2618 (@pxref{Package Transformation Options, @option{--with-input}}).
2619
2620 @menu
2621 * package Reference :: The package data type.
2622 * origin Reference:: The origin data type.
2623 @end menu
2624
2625
2626 @node package Reference
2627 @subsection @code{package} Reference
2628
2629 This section summarizes all the options available in @code{package}
2630 declarations (@pxref{Defining Packages}).
2631
2632 @deftp {Data Type} package
2633 This is the data type representing a package recipe.
2634
2635 @table @asis
2636 @item @code{name}
2637 The name of the package, as a string.
2638
2639 @item @code{version}
2640 The version of the package, as a string.
2641
2642 @item @code{source}
2643 An object telling how the source code for the package should be
2644 acquired. Most of the time, this is an @code{origin} object, which
2645 denotes a file fetched from the Internet (@pxref{origin Reference}). It
2646 can also be any other ``file-like'' object such as a @code{local-file},
2647 which denotes a file from the local file system (@pxref{G-Expressions,
2648 @code{local-file}}).
2649
2650 @item @code{build-system}
2651 The build system that should be used to build the package (@pxref{Build
2652 Systems}).
2653
2654 @item @code{arguments} (default: @code{'()})
2655 The arguments that should be passed to the build system. This is a
2656 list, typically containing sequential keyword-value pairs.
2657
2658 @item @code{inputs} (default: @code{'()})
2659 @itemx @code{native-inputs} (default: @code{'()})
2660 @itemx @code{propagated-inputs} (default: @code{'()})
2661 @cindex inputs, of packages
2662 These fields list dependencies of the package. Each one is a list of
2663 tuples, where each tuple has a label for the input (a string) as its
2664 first element, a package, origin, or derivation as its second element,
2665 and optionally the name of the output thereof that should be used, which
2666 defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
2667 more on package outputs). For example, the list below specifies three
2668 inputs:
2669
2670 @example
2671 `(("libffi" ,libffi)
2672 ("libunistring" ,libunistring)
2673 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
2674 @end example
2675
2676 @cindex cross compilation, package dependencies
2677 The distinction between @code{native-inputs} and @code{inputs} is
2678 necessary when considering cross-compilation. When cross-compiling,
2679 dependencies listed in @code{inputs} are built for the @emph{target}
2680 architecture; conversely, dependencies listed in @code{native-inputs}
2681 are built for the architecture of the @emph{build} machine.
2682
2683 @code{native-inputs} is typically used to list tools needed at
2684 build time, but not at run time, such as Autoconf, Automake, pkg-config,
2685 Gettext, or Bison. @command{guix lint} can report likely mistakes in
2686 this area (@pxref{Invoking guix lint}).
2687
2688 @anchor{package-propagated-inputs}
2689 Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
2690 specified packages will be automatically installed alongside the package
2691 they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
2692 package}}, for information on how @command{guix package} deals with
2693 propagated inputs.)
2694
2695 For example this is necessary when a C/C++ library needs headers of
2696 another library to compile, or when a pkg-config file refers to another
2697 one @i{via} its @code{Requires} field.
2698
2699 Another example where @code{propagated-inputs} is useful is for languages
2700 that lack a facility to record the run-time search path akin to the
2701 @code{RUNPATH} of ELF files; this includes Guile, Python, Perl, and
2702 more. To ensure that libraries written in those languages can find
2703 library code they depend on at run time, run-time dependencies must be
2704 listed in @code{propagated-inputs} rather than @code{inputs}.
2705
2706 @item @code{self-native-input?} (default: @code{#f})
2707 This is a Boolean field telling whether the package should use itself as
2708 a native input when cross-compiling.
2709
2710 @item @code{outputs} (default: @code{'("out")})
2711 The list of output names of the package. @xref{Packages with Multiple
2712 Outputs}, for typical uses of additional outputs.
2713
2714 @item @code{native-search-paths} (default: @code{'()})
2715 @itemx @code{search-paths} (default: @code{'()})
2716 A list of @code{search-path-specification} objects describing
2717 search-path environment variables honored by the package.
2718
2719 @item @code{replacement} (default: @code{#f})
2720 This must be either @code{#f} or a package object that will be used as a
2721 @dfn{replacement} for this package. @xref{Security Updates, grafts},
2722 for details.
2723
2724 @item @code{synopsis}
2725 A one-line description of the package.
2726
2727 @item @code{description}
2728 A more elaborate description of the package.
2729
2730 @item @code{license}
2731 The license of the package; a value from @code{(guix licenses)},
2732 or a list of such values.
2733
2734 @item @code{home-page}
2735 The URL to the home-page of the package, as a string.
2736
2737 @item @code{supported-systems} (default: @var{%supported-systems})
2738 The list of systems supported by the package, as strings of the form
2739 @code{architecture-kernel}, for example @code{"x86_64-linux"}.
2740
2741 @item @code{maintainers} (default: @code{'()})
2742 The list of maintainers of the package, as @code{maintainer} objects.
2743
2744 @item @code{location} (default: source location of the @code{package} form)
2745 The source location of the package. It is useful to override this when
2746 inheriting from another package, in which case this field is not
2747 automatically corrected.
2748 @end table
2749 @end deftp
2750
2751
2752 @node origin Reference
2753 @subsection @code{origin} Reference
2754
2755 This section summarizes all the options available in @code{origin}
2756 declarations (@pxref{Defining Packages}).
2757
2758 @deftp {Data Type} origin
2759 This is the data type representing a source code origin.
2760
2761 @table @asis
2762 @item @code{uri}
2763 An object containing the URI of the source. The object type depends on
2764 the @code{method} (see below). For example, when using the
2765 @var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2766 values are: a URL represented as a string, or a list thereof.
2767
2768 @item @code{method}
2769 A procedure that handles the URI.
2770
2771 Examples include:
2772
2773 @table @asis
2774 @item @var{url-fetch} from @code{(guix download)}
2775 download a file from the HTTP, HTTPS, or FTP URL specified in the
2776 @code{uri} field;
2777
2778 @vindex git-fetch
2779 @item @var{git-fetch} from @code{(guix git-download)}
2780 clone the Git version control repository, and check out the revision
2781 specified in the @code{uri} field as a @code{git-reference} object; a
2782 @code{git-reference} looks like this:
2783
2784 @example
2785 (git-reference
2786 (url "git://git.debian.org/git/pkg-shadow/shadow")
2787 (commit "v4.1.5.1"))
2788 @end example
2789 @end table
2790
2791 @item @code{sha256}
2792 A bytevector containing the SHA-256 hash of the source. Typically the
2793 @code{base32} form is used here to generate the bytevector from a
2794 base-32 string.
2795
2796 You can obtain this information using @code{guix download}
2797 (@pxref{Invoking guix download}) or @code{guix hash} (@pxref{Invoking
2798 guix hash}).
2799
2800 @item @code{file-name} (default: @code{#f})
2801 The file name under which the source code should be saved. When this is
2802 @code{#f}, a sensible default value will be used in most cases. In case
2803 the source is fetched from a URL, the file name from the URL will be
2804 used. For version control checkouts, it is recommended to provide the
2805 file name explicitly because the default is not very descriptive.
2806
2807 @item @code{patches} (default: @code{'()})
2808 A list of file names containing patches to be applied to the source.
2809
2810 @item @code{snippet} (default: @code{#f})
2811 A G-expression (@pxref{G-Expressions}) or S-expression that will be run
2812 in the source directory. This is a convenient way to modify the source,
2813 sometimes more convenient than a patch.
2814
2815 @item @code{patch-flags} (default: @code{'("-p1")})
2816 A list of command-line flags that should be passed to the @code{patch}
2817 command.
2818
2819 @item @code{patch-inputs} (default: @code{#f})
2820 Input packages or derivations to the patching process. When this is
2821 @code{#f}, the usual set of inputs necessary for patching are provided,
2822 such as GNU@tie{}Patch.
2823
2824 @item @code{modules} (default: @code{'()})
2825 A list of Guile modules that should be loaded during the patching
2826 process and while running the code in the @code{snippet} field.
2827
2828 @item @code{patch-guile} (default: @code{#f})
2829 The Guile package that should be used in the patching process. When
2830 this is @code{#f}, a sensible default is used.
2831 @end table
2832 @end deftp
2833
2834
2835 @node Build Systems
2836 @section Build Systems
2837
2838 @cindex build system
2839 Each package definition specifies a @dfn{build system} and arguments for
2840 that build system (@pxref{Defining Packages}). This @code{build-system}
2841 field represents the build procedure of the package, as well as implicit
2842 dependencies of that build procedure.
2843
2844 Build systems are @code{<build-system>} objects. The interface to
2845 create and manipulate them is provided by the @code{(guix build-system)}
2846 module, and actual build systems are exported by specific modules.
2847
2848 @cindex bag (low-level package representation)
2849 Under the hood, build systems first compile package objects to
2850 @dfn{bags}. A @dfn{bag} is like a package, but with less
2851 ornamentation---in other words, a bag is a lower-level representation of
2852 a package, which includes all the inputs of that package, including some
2853 that were implicitly added by the build system. This intermediate
2854 representation is then compiled to a derivation (@pxref{Derivations}).
2855
2856 Build systems accept an optional list of @dfn{arguments}. In package
2857 definitions, these are passed @i{via} the @code{arguments} field
2858 (@pxref{Defining Packages}). They are typically keyword arguments
2859 (@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
2860 Guile Reference Manual}). The value of these arguments is usually
2861 evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
2862 by the daemon (@pxref{Derivations}).
2863
2864 The main build system is @var{gnu-build-system}, which implements the
2865 standard build procedure for GNU and many other packages. It
2866 is provided by the @code{(guix build-system gnu)} module.
2867
2868 @defvr {Scheme Variable} gnu-build-system
2869 @var{gnu-build-system} represents the GNU Build System, and variants
2870 thereof (@pxref{Configuration, configuration and makefile conventions,,
2871 standards, GNU Coding Standards}).
2872
2873 @cindex build phases
2874 In a nutshell, packages using it are configured, built, and installed with
2875 the usual @code{./configure && make && make check && make install}
2876 command sequence. In practice, a few additional steps are often needed.
2877 All these steps are split up in separate @dfn{phases},
2878 notably@footnote{Please see the @code{(guix build gnu-build-system)}
2879 modules for more details about the build phases.}:
2880
2881 @table @code
2882 @item unpack
2883 Unpack the source tarball, and change the current directory to the
2884 extracted source tree. If the source is actually a directory, copy it
2885 to the build tree, and enter that directory.
2886
2887 @item patch-source-shebangs
2888 Patch shebangs encountered in source files so they refer to the right
2889 store file names. For instance, this changes @code{#!/bin/sh} to
2890 @code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
2891
2892 @item configure
2893 Run the @file{configure} script with a number of default options, such
2894 as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
2895 by the @code{#:configure-flags} argument.
2896
2897 @item build
2898 Run @code{make} with the list of flags specified with
2899 @code{#:make-flags}. If the @code{#:parallel-build?} argument is true
2900 (the default), build with @code{make -j}.
2901
2902 @item check
2903 Run @code{make check}, or some other target specified with
2904 @code{#:test-target}, unless @code{#:tests? #f} is passed. If the
2905 @code{#:parallel-tests?} argument is true (the default), run @code{make
2906 check -j}.
2907
2908 @item install
2909 Run @code{make install} with the flags listed in @code{#:make-flags}.
2910
2911 @item patch-shebangs
2912 Patch shebangs on the installed executable files.
2913
2914 @item strip
2915 Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
2916 is false), copying them to the @code{debug} output when available
2917 (@pxref{Installing Debugging Files}).
2918 @end table
2919
2920 @vindex %standard-phases
2921 The build-side module @code{(guix build gnu-build-system)} defines
2922 @var{%standard-phases} as the default list of build phases.
2923 @var{%standard-phases} is a list of symbol/procedure pairs, where the
2924 procedure implements the actual phase.
2925
2926 The list of phases used for a particular package can be changed with the
2927 @code{#:phases} parameter. For instance, passing:
2928
2929 @example
2930 #:phases (modify-phases %standard-phases (delete 'configure))
2931 @end example
2932
2933 means that all the phases described above will be used, except the
2934 @code{configure} phase.
2935
2936 In addition, this build system ensures that the ``standard'' environment
2937 for GNU packages is available. This includes tools such as GCC, libc,
2938 Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
2939 build-system gnu)} module for a complete list). We call these the
2940 @dfn{implicit inputs} of a package, because package definitions do not
2941 have to mention them.
2942 @end defvr
2943
2944 Other @code{<build-system>} objects are defined to support other
2945 conventions and tools used by free software packages. They inherit most
2946 of @var{gnu-build-system}, and differ mainly in the set of inputs
2947 implicitly added to the build process, and in the list of phases
2948 executed. Some of these build systems are listed below.
2949
2950 @defvr {Scheme Variable} ant-build-system
2951 This variable is exported by @code{(guix build-system ant)}. It
2952 implements the build procedure for Java packages that can be built with
2953 @url{http://ant.apache.org/, Ant build tool}.
2954
2955 It adds both @code{ant} and the @dfn{Java Development Kit} (JDK) as
2956 provided by the @code{icedtea} package to the set of inputs. Different
2957 packages can be specified with the @code{#:ant} and @code{#:jdk}
2958 parameters, respectively.
2959
2960 When the original package does not provide a suitable Ant build file,
2961 the parameter @code{#:jar-name} can be used to generate a minimal Ant
2962 build file @file{build.xml} with tasks to build the specified jar
2963 archive.
2964
2965 The parameter @code{#:build-target} can be used to specify the Ant task
2966 that should be run during the @code{build} phase. By default the
2967 ``jar'' task will be run.
2968
2969 @end defvr
2970
2971 @defvr {Scheme Variable} asdf-build-system/source
2972 @defvrx {Scheme Variable} asdf-build-system/sbcl
2973 @defvrx {Scheme Variable} asdf-build-system/ecl
2974
2975 These variables, exported by @code{(guix build-system asdf)}, implement
2976 build procedures for Common Lisp packages using
2977 @url{https://common-lisp.net/project/asdf/, ``ASDF''}. ASDF is a system
2978 definition facility for Common Lisp programs and libraries.
2979
2980 The @code{asdf-build-system/source} system installs the packages in
2981 source form, and can be loaded using any common lisp implementation, via
2982 ASDF. The others, such as @code{asdf-build-system/sbcl}, install binary
2983 systems in the format which a particular implementation understands.
2984 These build systems can also be used to produce executable programs, or
2985 lisp images which contain a set of packages pre-loaded.
2986
2987 The build system uses naming conventions. For binary packages, the
2988 package itself as well as its run-time dependencies should begin their
2989 name with the lisp implementation, such as @code{sbcl-} for
2990 @code{asdf-build-system/sbcl}. Beginning the input name with this
2991 prefix will allow the build system to encode its location into the
2992 resulting library, so that the input can be found at run-time.
2993
2994 If dependencies are used only for tests, it is convenient to use a
2995 different prefix in order to avoid having a run-time dependency on such
2996 systems. For example,
2997
2998 @example
2999 (define-public sbcl-bordeaux-threads
3000 (package
3001 ...
3002 (native-inputs `(("tests:cl-fiveam" ,sbcl-fiveam)))
3003 ...))
3004 @end example
3005
3006 Additionally, the corresponding source package should be labeled using
3007 the same convention as python packages (see @ref{Python Modules}), using
3008 the @code{cl-} prefix.
3009
3010 For binary packages, each system should be defined as a Guix package.
3011 If one package @code{origin} contains several systems, package variants
3012 can be created in order to build all the systems. Source packages,
3013 which use @code{asdf-build-system/source}, may contain several systems.
3014
3015 In order to create executable programs and images, the build-side
3016 procedures @code{build-program} and @code{build-image} can be used.
3017 They should be called in a build phase after the @code{create-symlinks}
3018 phase, so that the system which was just built can be used within the
3019 resulting image. @code{build-program} requires a list of Common Lisp
3020 expressions to be passed as the @code{#:entry-program} argument.
3021
3022 If the system is not defined within its own @code{.asd} file of the same
3023 name, then the @code{#:asd-file} parameter should be used to specify
3024 which file the system is defined in.
3025
3026 @end defvr
3027
3028 @defvr {Scheme Variable} cmake-build-system
3029 This variable is exported by @code{(guix build-system cmake)}. It
3030 implements the build procedure for packages using the
3031 @url{http://www.cmake.org, CMake build tool}.
3032
3033 It automatically adds the @code{cmake} package to the set of inputs.
3034 Which package is used can be specified with the @code{#:cmake}
3035 parameter.
3036
3037 The @code{#:configure-flags} parameter is taken as a list of flags
3038 passed to the @command{cmake} command. The @code{#:build-type}
3039 parameter specifies in abstract terms the flags passed to the compiler;
3040 it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
3041 debugging information''), which roughly means that code is compiled with
3042 @code{-O2 -g}, as is the case for Autoconf-based packages by default.
3043 @end defvr
3044
3045 @defvr {Scheme Variable} glib-or-gtk-build-system
3046 This variable is exported by @code{(guix build-system glib-or-gtk)}. It
3047 is intended for use with packages making use of GLib or GTK+.
3048
3049 This build system adds the following two phases to the ones defined by
3050 @var{gnu-build-system}:
3051
3052 @table @code
3053 @item glib-or-gtk-wrap
3054 The phase @code{glib-or-gtk-wrap} ensures that programs in
3055 @file{bin/} are able to find GLib ``schemas'' and
3056 @uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
3057 modules}. This is achieved by wrapping the programs in launch scripts
3058 that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
3059 environment variables.
3060
3061 It is possible to exclude specific package outputs from that wrapping
3062 process by listing their names in the
3063 @code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
3064 when an output is known not to contain any GLib or GTK+ binaries, and
3065 where wrapping would gratuitously add a dependency of that output on
3066 GLib and GTK+.
3067
3068 @item glib-or-gtk-compile-schemas
3069 The phase @code{glib-or-gtk-compile-schemas} makes sure that all
3070 @uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
3071 GSettings schemas} of GLib are compiled. Compilation is performed by the
3072 @command{glib-compile-schemas} program. It is provided by the package
3073 @code{glib:bin} which is automatically imported by the build system.
3074 The @code{glib} package providing @command{glib-compile-schemas} can be
3075 specified with the @code{#:glib} parameter.
3076 @end table
3077
3078 Both phases are executed after the @code{install} phase.
3079 @end defvr
3080
3081 @defvr {Scheme Variable} python-build-system
3082 This variable is exported by @code{(guix build-system python)}. It
3083 implements the more or less standard build procedure used by Python
3084 packages, which consists in running @code{python setup.py build} and
3085 then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
3086
3087 For packages that install stand-alone Python programs under @code{bin/},
3088 it takes care of wrapping these programs so that their @code{PYTHONPATH}
3089 environment variable points to all the Python libraries they depend on.
3090
3091 Which Python package is used to perform the build can be specified with
3092 the @code{#:python} parameter. This is a useful way to force a package
3093 to be built for a specific version of the Python interpreter, which
3094 might be necessary if the package is only compatible with a single
3095 interpreter version.
3096 @end defvr
3097
3098 @defvr {Scheme Variable} perl-build-system
3099 This variable is exported by @code{(guix build-system perl)}. It
3100 implements the standard build procedure for Perl packages, which either
3101 consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
3102 followed by @code{Build} and @code{Build install}; or in running
3103 @code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
3104 @code{make} and @code{make install}, depending on which of
3105 @code{Build.PL} or @code{Makefile.PL} is present in the package
3106 distribution. Preference is given to the former if both @code{Build.PL}
3107 and @code{Makefile.PL} exist in the package distribution. This
3108 preference can be reversed by specifying @code{#t} for the
3109 @code{#:make-maker?} parameter.
3110
3111 The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
3112 passes flags specified by the @code{#:make-maker-flags} or
3113 @code{#:module-build-flags} parameter, respectively.
3114
3115 Which Perl package is used can be specified with @code{#:perl}.
3116 @end defvr
3117
3118 @defvr {Scheme Variable} r-build-system
3119 This variable is exported by @code{(guix build-system r)}. It
3120 implements the build procedure used by @uref{http://r-project.org, R}
3121 packages, which essentially is little more than running @code{R CMD
3122 INSTALL --library=/gnu/store/@dots{}} in an environment where
3123 @code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
3124 are run after installation using the R function
3125 @code{tools::testInstalledPackage}.
3126 @end defvr
3127
3128 @defvr {Scheme Variable} ruby-build-system
3129 This variable is exported by @code{(guix build-system ruby)}. It
3130 implements the RubyGems build procedure used by Ruby packages, which
3131 involves running @code{gem build} followed by @code{gem install}.
3132
3133 The @code{source} field of a package that uses this build system
3134 typically references a gem archive, since this is the format that Ruby
3135 developers use when releasing their software. The build system unpacks
3136 the gem archive, potentially patches the source, runs the test suite,
3137 repackages the gem, and installs it. Additionally, directories and
3138 tarballs may be referenced to allow building unreleased gems from Git or
3139 a traditional source release tarball.
3140
3141 Which Ruby package is used can be specified with the @code{#:ruby}
3142 parameter. A list of additional flags to be passed to the @command{gem}
3143 command can be specified with the @code{#:gem-flags} parameter.
3144 @end defvr
3145
3146 @defvr {Scheme Variable} waf-build-system
3147 This variable is exported by @code{(guix build-system waf)}. It
3148 implements a build procedure around the @code{waf} script. The common
3149 phases---@code{configure}, @code{build}, and @code{install}---are
3150 implemented by passing their names as arguments to the @code{waf}
3151 script.
3152
3153 The @code{waf} script is executed by the Python interpreter. Which
3154 Python package is used to run the script can be specified with the
3155 @code{#:python} parameter.
3156 @end defvr
3157
3158 @defvr {Scheme Variable} haskell-build-system
3159 This variable is exported by @code{(guix build-system haskell)}. It
3160 implements the Cabal build procedure used by Haskell packages, which
3161 involves running @code{runhaskell Setup.hs configure
3162 --prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
3163 Instead of installing the package by running @code{runhaskell Setup.hs
3164 install}, to avoid trying to register libraries in the read-only
3165 compiler store directory, the build system uses @code{runhaskell
3166 Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
3167 addition, the build system generates the package documentation by
3168 running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
3169 is passed. Optional Haddock parameters can be passed with the help of
3170 the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
3171 not found, the build system looks for @code{Setup.lhs} instead.
3172
3173 Which Haskell compiler is used can be specified with the @code{#:haskell}
3174 parameter which defaults to @code{ghc}.
3175 @end defvr
3176
3177 @defvr {Scheme Variable} emacs-build-system
3178 This variable is exported by @code{(guix build-system emacs)}. It
3179 implements an installation procedure similar to the packaging system
3180 of Emacs itself (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
3181
3182 It first creates the @code{@var{package}-autoloads.el} file, then it
3183 byte compiles all Emacs Lisp files. Differently from the Emacs
3184 packaging system, the Info documentation files are moved to the standard
3185 documentation directory and the @file{dir} file is deleted. Each
3186 package is installed in its own directory under
3187 @file{share/emacs/site-lisp/guix.d}.
3188 @end defvr
3189
3190 Lastly, for packages that do not need anything as sophisticated, a
3191 ``trivial'' build system is provided. It is trivial in the sense that
3192 it provides basically no support: it does not pull any implicit inputs,
3193 and does not have a notion of build phases.
3194
3195 @defvr {Scheme Variable} trivial-build-system
3196 This variable is exported by @code{(guix build-system trivial)}.
3197
3198 This build system requires a @code{#:builder} argument. This argument
3199 must be a Scheme expression that builds the package output(s)---as
3200 with @code{build-expression->derivation} (@pxref{Derivations,
3201 @code{build-expression->derivation}}).
3202 @end defvr
3203
3204 @node The Store
3205 @section The Store
3206
3207 @cindex store
3208 @cindex store items
3209 @cindex store paths
3210
3211 Conceptually, the @dfn{store} is the place where derivations that have
3212 been built successfully are stored---by default, @file{/gnu/store}.
3213 Sub-directories in the store are referred to as @dfn{store items} or
3214 sometimes @dfn{store paths}. The store has an associated database that
3215 contains information such as the store paths referred to by each store
3216 path, and the list of @emph{valid} store items---results of successful
3217 builds. This database resides in @file{@var{localstatedir}/guix/db},
3218 where @var{localstatedir} is the state directory specified @i{via}
3219 @option{--localstatedir} at configure time, usually @file{/var}.
3220
3221 The store is @emph{always} accessed by the daemon on behalf of its clients
3222 (@pxref{Invoking guix-daemon}). To manipulate the store, clients
3223 connect to the daemon over a Unix-domain socket, send requests to it,
3224 and read the result---these are remote procedure calls, or RPCs.
3225
3226 @quotation Note
3227 Users must @emph{never} modify files under @file{/gnu/store} directly.
3228 This would lead to inconsistencies and break the immutability
3229 assumptions of Guix's functional model (@pxref{Introduction}).
3230
3231 @xref{Invoking guix gc, @command{guix gc --verify}}, for information on
3232 how to check the integrity of the store and attempt recovery from
3233 accidental modifications.
3234 @end quotation
3235
3236 The @code{(guix store)} module provides procedures to connect to the
3237 daemon, and to perform RPCs. These are described below.
3238
3239 @deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
3240 Connect to the daemon over the Unix-domain socket at @var{file}. When
3241 @var{reserve-space?} is true, instruct it to reserve a little bit of
3242 extra space on the file system so that the garbage collector can still
3243 operate should the disk become full. Return a server object.
3244
3245 @var{file} defaults to @var{%default-socket-path}, which is the normal
3246 location given the options that were passed to @command{configure}.
3247 @end deffn
3248
3249 @deffn {Scheme Procedure} close-connection @var{server}
3250 Close the connection to @var{server}.
3251 @end deffn
3252
3253 @defvr {Scheme Variable} current-build-output-port
3254 This variable is bound to a SRFI-39 parameter, which refers to the port
3255 where build and error logs sent by the daemon should be written.
3256 @end defvr
3257
3258 Procedures that make RPCs all take a server object as their first
3259 argument.
3260
3261 @deffn {Scheme Procedure} valid-path? @var{server} @var{path}
3262 @cindex invalid store items
3263 Return @code{#t} when @var{path} designates a valid store item and
3264 @code{#f} otherwise (an invalid item may exist on disk but still be
3265 invalid, for instance because it is the result of an aborted or failed
3266 build.)
3267
3268 A @code{&nix-protocol-error} condition is raised if @var{path} is not
3269 prefixed by the store directory (@file{/gnu/store}).
3270 @end deffn
3271
3272 @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
3273 Add @var{text} under file @var{name} in the store, and return its store
3274 path. @var{references} is the list of store paths referred to by the
3275 resulting store path.
3276 @end deffn
3277
3278 @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
3279 Build @var{derivations} (a list of @code{<derivation>} objects or
3280 derivation paths), and return when the worker is done building them.
3281 Return @code{#t} on success.
3282 @end deffn
3283
3284 Note that the @code{(guix monads)} module provides a monad as well as
3285 monadic versions of the above procedures, with the goal of making it
3286 more convenient to work with code that accesses the store (@pxref{The
3287 Store Monad}).
3288
3289 @c FIXME
3290 @i{This section is currently incomplete.}
3291
3292 @node Derivations
3293 @section Derivations
3294
3295 @cindex derivations
3296 Low-level build actions and the environment in which they are performed
3297 are represented by @dfn{derivations}. A derivation contains the
3298 following pieces of information:
3299
3300 @itemize
3301 @item
3302 The outputs of the derivation---derivations produce at least one file or
3303 directory in the store, but may produce more.
3304
3305 @item
3306 The inputs of the derivations, which may be other derivations or plain
3307 files in the store (patches, build scripts, etc.)
3308
3309 @item
3310 The system type targeted by the derivation---e.g., @code{x86_64-linux}.
3311
3312 @item
3313 The file name of a build script in the store, along with the arguments
3314 to be passed.
3315
3316 @item
3317 A list of environment variables to be defined.
3318
3319 @end itemize
3320
3321 @cindex derivation path
3322 Derivations allow clients of the daemon to communicate build actions to
3323 the store. They exist in two forms: as an in-memory representation,
3324 both on the client- and daemon-side, and as files in the store whose
3325 name end in @code{.drv}---these files are referred to as @dfn{derivation
3326 paths}. Derivations paths can be passed to the @code{build-derivations}
3327 procedure to perform the build actions they prescribe (@pxref{The
3328 Store}).
3329
3330 The @code{(guix derivations)} module provides a representation of
3331 derivations as Scheme objects, along with procedures to create and
3332 otherwise manipulate derivations. The lowest-level primitive to create
3333 a derivation is the @code{derivation} procedure:
3334
3335 @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
3336 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3337 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
3338 [#:system (%current-system)] [#:references-graphs #f] @
3339 [#:allowed-references #f] [#:disallowed-references #f] @
3340 [#:leaked-env-vars #f] [#:local-build? #f] @
3341 [#:substitutable? #t]
3342 Build a derivation with the given arguments, and return the resulting
3343 @code{<derivation>} object.
3344
3345 When @var{hash} and @var{hash-algo} are given, a
3346 @dfn{fixed-output derivation} is created---i.e., one whose result is
3347 known in advance, such as a file download. If, in addition,
3348 @var{recursive?} is true, then that fixed output may be an executable
3349 file or a directory and @var{hash} must be the hash of an archive
3350 containing this output.
3351
3352 When @var{references-graphs} is true, it must be a list of file
3353 name/store path pairs. In that case, the reference graph of each store
3354 path is exported in the build environment in the corresponding file, in
3355 a simple text format.
3356
3357 When @var{allowed-references} is true, it must be a list of store items
3358 or outputs that the derivation's output may refer to. Likewise,
3359 @var{disallowed-references}, if true, must be a list of things the
3360 outputs may @emph{not} refer to.
3361
3362 When @var{leaked-env-vars} is true, it must be a list of strings
3363 denoting environment variables that are allowed to ``leak'' from the
3364 daemon's environment to the build environment. This is only applicable
3365 to fixed-output derivations---i.e., when @var{hash} is true. The main
3366 use is to allow variables such as @code{http_proxy} to be passed to
3367 derivations that download files.
3368
3369 When @var{local-build?} is true, declare that the derivation is not a
3370 good candidate for offloading and should rather be built locally
3371 (@pxref{Daemon Offload Setup}). This is the case for small derivations
3372 where the costs of data transfers would outweigh the benefits.
3373
3374 When @var{substitutable?} is false, declare that substitutes of the
3375 derivation's output should not be used (@pxref{Substitutes}). This is
3376 useful, for instance, when building packages that capture details of the
3377 host CPU instruction set.
3378 @end deffn
3379
3380 @noindent
3381 Here's an example with a shell script as its builder, assuming
3382 @var{store} is an open connection to the daemon, and @var{bash} points
3383 to a Bash executable in the store:
3384
3385 @lisp
3386 (use-modules (guix utils)
3387 (guix store)
3388 (guix derivations))
3389
3390 (let ((builder ; add the Bash script to the store
3391 (add-text-to-store store "my-builder.sh"
3392 "echo hello world > $out\n" '())))
3393 (derivation store "foo"
3394 bash `("-e" ,builder)
3395 #:inputs `((,bash) (,builder))
3396 #:env-vars '(("HOME" . "/homeless"))))
3397 @result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
3398 @end lisp
3399
3400 As can be guessed, this primitive is cumbersome to use directly. A
3401 better approach is to write build scripts in Scheme, of course! The
3402 best course of action for that is to write the build code as a
3403 ``G-expression'', and to pass it to @code{gexp->derivation}. For more
3404 information, @pxref{G-Expressions}.
3405
3406 Once upon a time, @code{gexp->derivation} did not exist and constructing
3407 derivations with build code written in Scheme was achieved with
3408 @code{build-expression->derivation}, documented below. This procedure
3409 is now deprecated in favor of the much nicer @code{gexp->derivation}.
3410
3411 @deffn {Scheme Procedure} build-expression->derivation @var{store} @
3412 @var{name} @var{exp} @
3413 [#:system (%current-system)] [#:inputs '()] @
3414 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3415 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3416 [#:references-graphs #f] [#:allowed-references #f] @
3417 [#:disallowed-references #f] @
3418 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3419 Return a derivation that executes Scheme expression @var{exp} as a
3420 builder for derivation @var{name}. @var{inputs} must be a list of
3421 @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
3422 @code{"out"} is assumed. @var{modules} is a list of names of Guile
3423 modules from the current search path to be copied in the store,
3424 compiled, and made available in the load path during the execution of
3425 @var{exp}---e.g., @code{((guix build utils) (guix build
3426 gnu-build-system))}.
3427
3428 @var{exp} is evaluated in an environment where @code{%outputs} is bound
3429 to a list of output/path pairs, and where @code{%build-inputs} is bound
3430 to a list of string/output-path pairs made from @var{inputs}.
3431 Optionally, @var{env-vars} is a list of string pairs specifying the name
3432 and value of environment variables visible to the builder. The builder
3433 terminates by passing the result of @var{exp} to @code{exit}; thus, when
3434 @var{exp} returns @code{#f}, the build is considered to have failed.
3435
3436 @var{exp} is built using @var{guile-for-build} (a derivation). When
3437 @var{guile-for-build} is omitted or is @code{#f}, the value of the
3438 @code{%guile-for-build} fluid is used instead.
3439
3440 See the @code{derivation} procedure for the meaning of
3441 @var{references-graphs}, @var{allowed-references},
3442 @var{disallowed-references}, @var{local-build?}, and
3443 @var{substitutable?}.
3444 @end deffn
3445
3446 @noindent
3447 Here's an example of a single-output derivation that creates a directory
3448 containing one file:
3449
3450 @lisp
3451 (let ((builder '(let ((out (assoc-ref %outputs "out")))
3452 (mkdir out) ; create /gnu/store/@dots{}-goo
3453 (call-with-output-file (string-append out "/test")
3454 (lambda (p)
3455 (display '(hello guix) p))))))
3456 (build-expression->derivation store "goo" builder))
3457
3458 @result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
3459 @end lisp
3460
3461
3462 @node The Store Monad
3463 @section The Store Monad
3464
3465 @cindex monad
3466
3467 The procedures that operate on the store described in the previous
3468 sections all take an open connection to the build daemon as their first
3469 argument. Although the underlying model is functional, they either have
3470 side effects or depend on the current state of the store.
3471
3472 The former is inconvenient: the connection to the build daemon has to be
3473 carried around in all those functions, making it impossible to compose
3474 functions that do not take that parameter with functions that do. The
3475 latter can be problematic: since store operations have side effects
3476 and/or depend on external state, they have to be properly sequenced.
3477
3478 @cindex monadic values
3479 @cindex monadic functions
3480 This is where the @code{(guix monads)} module comes in. This module
3481 provides a framework for working with @dfn{monads}, and a particularly
3482 useful monad for our uses, the @dfn{store monad}. Monads are a
3483 construct that allows two things: associating ``context'' with values
3484 (in our case, the context is the store), and building sequences of
3485 computations (here computations include accesses to the store). Values
3486 in a monad---values that carry this additional context---are called
3487 @dfn{monadic values}; procedures that return such values are called
3488 @dfn{monadic procedures}.
3489
3490 Consider this ``normal'' procedure:
3491
3492 @example
3493 (define (sh-symlink store)
3494 ;; Return a derivation that symlinks the 'bash' executable.
3495 (let* ((drv (package-derivation store bash))
3496 (out (derivation->output-path drv))
3497 (sh (string-append out "/bin/bash")))
3498 (build-expression->derivation store "sh"
3499 `(symlink ,sh %output))))
3500 @end example
3501
3502 Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3503 as a monadic function:
3504
3505 @example
3506 (define (sh-symlink)
3507 ;; Same, but return a monadic value.
3508 (mlet %store-monad ((drv (package->derivation bash)))
3509 (gexp->derivation "sh"
3510 #~(symlink (string-append #$drv "/bin/bash")
3511 #$output))))
3512 @end example
3513
3514 There are several things to note in the second version: the @code{store}
3515 parameter is now implicit and is ``threaded'' in the calls to the
3516 @code{package->derivation} and @code{gexp->derivation} monadic
3517 procedures, and the monadic value returned by @code{package->derivation}
3518 is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3519
3520 As it turns out, the call to @code{package->derivation} can even be
3521 omitted since it will take place implicitly, as we will see later
3522 (@pxref{G-Expressions}):
3523
3524 @example
3525 (define (sh-symlink)
3526 (gexp->derivation "sh"
3527 #~(symlink (string-append #$bash "/bin/bash")
3528 #$output)))
3529 @end example
3530
3531 @c See
3532 @c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
3533 @c for the funny quote.
3534 Calling the monadic @code{sh-symlink} has no effect. As someone once
3535 said, ``you exit a monad like you exit a building on fire: by running''.
3536 So, to exit the monad and get the desired effect, one must use
3537 @code{run-with-store}:
3538
3539 @example
3540 (run-with-store (open-connection) (sh-symlink))
3541 @result{} /gnu/store/...-sh-symlink
3542 @end example
3543
3544 Note that the @code{(guix monad-repl)} module extends the Guile REPL with
3545 new ``meta-commands'' to make it easier to deal with monadic procedures:
3546 @code{run-in-store}, and @code{enter-store-monad}. The former is used
3547 to ``run'' a single monadic value through the store:
3548
3549 @example
3550 scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3551 $1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3552 @end example
3553
3554 The latter enters a recursive REPL, where all the return values are
3555 automatically run through the store:
3556
3557 @example
3558 scheme@@(guile-user)> ,enter-store-monad
3559 store-monad@@(guile-user) [1]> (package->derivation hello)
3560 $2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3561 store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3562 $3 = "/gnu/store/@dots{}-foo"
3563 store-monad@@(guile-user) [1]> ,q
3564 scheme@@(guile-user)>
3565 @end example
3566
3567 @noindent
3568 Note that non-monadic values cannot be returned in the
3569 @code{store-monad} REPL.
3570
3571 The main syntactic forms to deal with monads in general are provided by
3572 the @code{(guix monads)} module and are described below.
3573
3574 @deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3575 Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3576 in @var{monad}.
3577 @end deffn
3578
3579 @deffn {Scheme Syntax} return @var{val}
3580 Return a monadic value that encapsulates @var{val}.
3581 @end deffn
3582
3583 @deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
3584 @dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
3585 procedures @var{mproc}@dots{}@footnote{This operation is commonly
3586 referred to as ``bind'', but that name denotes an unrelated procedure in
3587 Guile. Thus we use this somewhat cryptic symbol inherited from the
3588 Haskell language.}. There can be one @var{mproc} or several of them, as
3589 in this example:
3590
3591 @example
3592 (run-with-state
3593 (with-monad %state-monad
3594 (>>= (return 1)
3595 (lambda (x) (return (+ 1 x)))
3596 (lambda (x) (return (* 2 x)))))
3597 'some-state)
3598
3599 @result{} 4
3600 @result{} some-state
3601 @end example
3602 @end deffn
3603
3604 @deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3605 @var{body} ...
3606 @deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3607 @var{body} ...
3608 Bind the variables @var{var} to the monadic values @var{mval} in
3609 @var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3610 ``normal'' value @var{val}, as per @code{let}.
3611
3612 @code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3613 (@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3614 @end deffn
3615
3616 @deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3617 Bind @var{mexp} and the following monadic expressions in sequence,
3618 returning the result of the last expression.
3619
3620 This is akin to @code{mlet}, except that the return values of the
3621 monadic expressions are ignored. In that sense, it is analogous to
3622 @code{begin}, but applied to monadic expressions.
3623 @end deffn
3624
3625 @cindex state monad
3626 The @code{(guix monads)} module provides the @dfn{state monad}, which
3627 allows an additional value---the state---to be @emph{threaded} through
3628 monadic procedure calls.
3629
3630 @defvr {Scheme Variable} %state-monad
3631 The state monad. Procedures in the state monad can access and change
3632 the state that is threaded.
3633
3634 Consider the example below. The @code{square} procedure returns a value
3635 in the state monad. It returns the square of its argument, but also
3636 increments the current state value:
3637
3638 @example
3639 (define (square x)
3640 (mlet %state-monad ((count (current-state)))
3641 (mbegin %state-monad
3642 (set-current-state (+ 1 count))
3643 (return (* x x)))))
3644
3645 (run-with-state (sequence %state-monad (map square (iota 3))) 0)
3646 @result{} (0 1 4)
3647 @result{} 3
3648 @end example
3649
3650 When ``run'' through @var{%state-monad}, we obtain that additional state
3651 value, which is the number of @code{square} calls.
3652 @end defvr
3653
3654 @deffn {Monadic Procedure} current-state
3655 Return the current state as a monadic value.
3656 @end deffn
3657
3658 @deffn {Monadic Procedure} set-current-state @var{value}
3659 Set the current state to @var{value} and return the previous state as a
3660 monadic value.
3661 @end deffn
3662
3663 @deffn {Monadic Procedure} state-push @var{value}
3664 Push @var{value} to the current state, which is assumed to be a list,
3665 and return the previous state as a monadic value.
3666 @end deffn
3667
3668 @deffn {Monadic Procedure} state-pop
3669 Pop a value from the current state and return it as a monadic value.
3670 The state is assumed to be a list.
3671 @end deffn
3672
3673 @deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3674 Run monadic value @var{mval} starting with @var{state} as the initial
3675 state. Return two values: the resulting value, and the resulting state.
3676 @end deffn
3677
3678 The main interface to the store monad, provided by the @code{(guix
3679 store)} module, is as follows.
3680
3681 @defvr {Scheme Variable} %store-monad
3682 The store monad---an alias for @var{%state-monad}.
3683
3684 Values in the store monad encapsulate accesses to the store. When its
3685 effect is needed, a value of the store monad must be ``evaluated'' by
3686 passing it to the @code{run-with-store} procedure (see below.)
3687 @end defvr
3688
3689 @deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3690 Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3691 open store connection.
3692 @end deffn
3693
3694 @deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
3695 Return as a monadic value the absolute file name in the store of the file
3696 containing @var{text}, a string. @var{references} is a list of store items that the
3697 resulting text file refers to; it defaults to the empty list.
3698 @end deffn
3699
3700 @deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
3701 [#:recursive? #t] [#:select? (const #t)]
3702 Return the name of @var{file} once interned in the store. Use
3703 @var{name} as its store name, or the basename of @var{file} if
3704 @var{name} is omitted.
3705
3706 When @var{recursive?} is true, the contents of @var{file} are added
3707 recursively; if @var{file} designates a flat file and @var{recursive?}
3708 is true, its contents are added, and its permission bits are kept.
3709
3710 When @var{recursive?} is true, call @code{(@var{select?} @var{file}
3711 @var{stat})} for each directory entry, where @var{file} is the entry's
3712 absolute file name and @var{stat} is the result of @code{lstat}; exclude
3713 entries for which @var{select?} does not return true.
3714
3715 The example below adds a file to the store, under two different names:
3716
3717 @example
3718 (run-with-store (open-connection)
3719 (mlet %store-monad ((a (interned-file "README"))
3720 (b (interned-file "README" "LEGU-MIN")))
3721 (return (list a b))))
3722
3723 @result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3724 @end example
3725
3726 @end deffn
3727
3728 The @code{(guix packages)} module exports the following package-related
3729 monadic procedures:
3730
3731 @deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
3732 [#:system (%current-system)] [#:target #f] @
3733 [#:output "out"]
3734 Return as a monadic
3735 value in the absolute file name of @var{file} within the @var{output}
3736 directory of @var{package}. When @var{file} is omitted, return the name
3737 of the @var{output} directory of @var{package}. When @var{target} is
3738 true, use it as a cross-compilation target triplet.
3739 @end deffn
3740
3741 @deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
3742 @deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3743 @var{target} [@var{system}]
3744 Monadic version of @code{package-derivation} and
3745 @code{package-cross-derivation} (@pxref{Defining Packages}).
3746 @end deffn
3747
3748
3749 @node G-Expressions
3750 @section G-Expressions
3751
3752 @cindex G-expression
3753 @cindex build code quoting
3754 So we have ``derivations'', which represent a sequence of build actions
3755 to be performed to produce an item in the store (@pxref{Derivations}).
3756 These build actions are performed when asking the daemon to actually
3757 build the derivations; they are run by the daemon in a container
3758 (@pxref{Invoking guix-daemon}).
3759
3760 @cindex strata of code
3761 It should come as no surprise that we like to write these build actions
3762 in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3763 code@footnote{The term @dfn{stratum} in this context was coined by
3764 Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3765 Kiselyov, who has written insightful
3766 @url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3767 on this topic}, refers to this kind of code generation as
3768 @dfn{staging}.}: the ``host code''---code that defines packages, talks
3769 to the daemon, etc.---and the ``build code''---code that actually
3770 performs build actions, such as making directories, invoking
3771 @command{make}, etc.
3772
3773 To describe a derivation and its build actions, one typically needs to
3774 embed build code inside host code. It boils down to manipulating build
3775 code as data, and the homoiconicity of Scheme---code has a direct
3776 representation as data---comes in handy for that. But we need more than
3777 the normal @code{quasiquote} mechanism in Scheme to construct build
3778 expressions.
3779
3780 The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3781 S-expressions adapted to build expressions. G-expressions, or
3782 @dfn{gexps}, consist essentially of three syntactic forms: @code{gexp},
3783 @code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
3784 @code{#$}, and @code{#$@@}), which are comparable to
3785 @code{quasiquote}, @code{unquote}, and @code{unquote-splicing},
3786 respectively (@pxref{Expression Syntax, @code{quasiquote},, guile,
3787 GNU Guile Reference Manual}). However, there are major differences:
3788
3789 @itemize
3790 @item
3791 Gexps are meant to be written to a file and run or manipulated by other
3792 processes.
3793
3794 @item
3795 When a high-level object such as a package or derivation is unquoted
3796 inside a gexp, the result is as if its output file name had been
3797 introduced.
3798
3799 @item
3800 Gexps carry information about the packages or derivations they refer to,
3801 and these dependencies are automatically added as inputs to the build
3802 processes that use them.
3803 @end itemize
3804
3805 @cindex lowering, of high-level objects in gexps
3806 This mechanism is not limited to package and derivation
3807 objects: @dfn{compilers} able to ``lower'' other high-level objects to
3808 derivations or files in the store can be defined,
3809 such that these objects can also be inserted
3810 into gexps. For example, a useful type of high-level objects that can be
3811 inserted in a gexp is ``file-like objects'', which make it easy to
3812 add files to the store and to refer to them in
3813 derivations and such (see @code{local-file} and @code{plain-file}
3814 below.)
3815
3816 To illustrate the idea, here is an example of a gexp:
3817
3818 @example
3819 (define build-exp
3820 #~(begin
3821 (mkdir #$output)
3822 (chdir #$output)
3823 (symlink (string-append #$coreutils "/bin/ls")
3824 "list-files")))
3825 @end example
3826
3827 This gexp can be passed to @code{gexp->derivation}; we obtain a
3828 derivation that builds a directory containing exactly one symlink to
3829 @file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3830
3831 @example
3832 (gexp->derivation "the-thing" build-exp)
3833 @end example
3834
3835 As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
3836 substituted to the reference to the @var{coreutils} package in the
3837 actual build code, and @var{coreutils} is automatically made an input to
3838 the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
3839 output)}) is replaced by a string containing the directory name of the
3840 output of the derivation.
3841
3842 @cindex cross compilation
3843 In a cross-compilation context, it is useful to distinguish between
3844 references to the @emph{native} build of a package---that can run on the
3845 host---versus references to cross builds of a package. To that end, the
3846 @code{#+} plays the same role as @code{#$}, but is a reference to a
3847 native package build:
3848
3849 @example
3850 (gexp->derivation "vi"
3851 #~(begin
3852 (mkdir #$output)
3853 (system* (string-append #+coreutils "/bin/ln")
3854 "-s"
3855 (string-append #$emacs "/bin/emacs")
3856 (string-append #$output "/bin/vi")))
3857 #:target "mips64el-linux-gnu")
3858 @end example
3859
3860 @noindent
3861 In the example above, the native build of @var{coreutils} is used, so
3862 that @command{ln} can actually run on the host; but then the
3863 cross-compiled build of @var{emacs} is referenced.
3864
3865 @cindex imported modules, for gexps
3866 @findex with-imported-modules
3867 Another gexp feature is @dfn{imported modules}: sometimes you want to be
3868 able to use certain Guile modules from the ``host environment'' in the
3869 gexp, so those modules should be imported in the ``build environment''.
3870 The @code{with-imported-modules} form allows you to express that:
3871
3872 @example
3873 (let ((build (with-imported-modules '((guix build utils))
3874 #~(begin
3875 (use-modules (guix build utils))
3876 (mkdir-p (string-append #$output "/bin"))))))
3877 (gexp->derivation "empty-dir"
3878 #~(begin
3879 #$build
3880 (display "success!\n")
3881 #t)))
3882 @end example
3883
3884 @noindent
3885 In this example, the @code{(guix build utils)} module is automatically
3886 pulled into the isolated build environment of our gexp, such that
3887 @code{(use-modules (guix build utils))} works as expected.
3888
3889 @cindex module closure
3890 @findex source-module-closure
3891 Usually you want the @emph{closure} of the module to be imported---i.e.,
3892 the module itself and all the modules it depends on---rather than just
3893 the module; failing to do that, attempts to use the module will fail
3894 because of missing dependent modules. The @code{source-module-closure}
3895 procedure computes the closure of a module by looking at its source file
3896 headers, which comes in handy in this case:
3897
3898 @example
3899 (use-modules (guix modules)) ;for 'source-module-closure'
3900
3901 (with-imported-modules (source-module-closure
3902 '((guix build utils)
3903 (gnu build vm)))
3904 (gexp->derivation "something-with-vms"
3905 #~(begin
3906 (use-modules (guix build utils)
3907 (gnu build vm))
3908 @dots{})))
3909 @end example
3910
3911 The syntactic form to construct gexps is summarized below.
3912
3913 @deffn {Scheme Syntax} #~@var{exp}
3914 @deffnx {Scheme Syntax} (gexp @var{exp})
3915 Return a G-expression containing @var{exp}. @var{exp} may contain one
3916 or more of the following forms:
3917
3918 @table @code
3919 @item #$@var{obj}
3920 @itemx (ungexp @var{obj})
3921 Introduce a reference to @var{obj}. @var{obj} may have one of the
3922 supported types, for example a package or a
3923 derivation, in which case the @code{ungexp} form is replaced by its
3924 output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
3925
3926 If @var{obj} is a list, it is traversed and references to supported
3927 objects are substituted similarly.
3928
3929 If @var{obj} is another gexp, its contents are inserted and its
3930 dependencies are added to those of the containing gexp.
3931
3932 If @var{obj} is another kind of object, it is inserted as is.
3933
3934 @item #$@var{obj}:@var{output}
3935 @itemx (ungexp @var{obj} @var{output})
3936 This is like the form above, but referring explicitly to the
3937 @var{output} of @var{obj}---this is useful when @var{obj} produces
3938 multiple outputs (@pxref{Packages with Multiple Outputs}).
3939
3940 @item #+@var{obj}
3941 @itemx #+@var{obj}:output
3942 @itemx (ungexp-native @var{obj})
3943 @itemx (ungexp-native @var{obj} @var{output})
3944 Same as @code{ungexp}, but produces a reference to the @emph{native}
3945 build of @var{obj} when used in a cross compilation context.
3946
3947 @item #$output[:@var{output}]
3948 @itemx (ungexp output [@var{output}])
3949 Insert a reference to derivation output @var{output}, or to the main
3950 output when @var{output} is omitted.
3951
3952 This only makes sense for gexps passed to @code{gexp->derivation}.
3953
3954 @item #$@@@var{lst}
3955 @itemx (ungexp-splicing @var{lst})
3956 Like the above, but splices the contents of @var{lst} inside the
3957 containing list.
3958
3959 @item #+@@@var{lst}
3960 @itemx (ungexp-native-splicing @var{lst})
3961 Like the above, but refers to native builds of the objects listed in
3962 @var{lst}.
3963
3964 @end table
3965
3966 G-expressions created by @code{gexp} or @code{#~} are run-time objects
3967 of the @code{gexp?} type (see below.)
3968 @end deffn
3969
3970 @deffn {Scheme Syntax} with-imported-modules @var{modules} @var{body}@dots{}
3971 Mark the gexps defined in @var{body}@dots{} as requiring @var{modules}
3972 in their execution environment. @var{modules} must be a list of Guile
3973 module names, such as @code{'((guix build utils) (guix build gremlin))}.
3974
3975 This form has @emph{lexical} scope: it has an effect on the gexps
3976 directly defined in @var{body}@dots{}, but not on those defined, say, in
3977 procedures called from @var{body}@dots{}.
3978 @end deffn
3979
3980 @deffn {Scheme Procedure} gexp? @var{obj}
3981 Return @code{#t} if @var{obj} is a G-expression.
3982 @end deffn
3983
3984 G-expressions are meant to be written to disk, either as code building
3985 some derivation, or as plain files in the store. The monadic procedures
3986 below allow you to do that (@pxref{The Store Monad}, for more
3987 information about monads.)
3988
3989 @deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
3990 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
3991 [#:hash #f] [#:hash-algo #f] @
3992 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3993 [#:module-path @var{%load-path}] @
3994 [#:references-graphs #f] [#:allowed-references #f] @
3995 [#:disallowed-references #f] @
3996 [#:leaked-env-vars #f] @
3997 [#:script-name (string-append @var{name} "-builder")] @
3998 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3999 Return a derivation @var{name} that runs @var{exp} (a gexp) with
4000 @var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
4001 stored in a file called @var{script-name}. When @var{target} is true,
4002 it is used as the cross-compilation target triplet for packages referred
4003 to by @var{exp}.
4004
4005 @var{modules} is deprecated in favor of @code{with-imported-modules}.
4006 Its meaning is to
4007 make @var{modules} available in the evaluation context of @var{exp};
4008 @var{modules} is a list of names of Guile modules searched in
4009 @var{module-path} to be copied in the store, compiled, and made available in
4010 the load path during the execution of @var{exp}---e.g., @code{((guix
4011 build utils) (guix build gnu-build-system))}.
4012
4013 @var{graft?} determines whether packages referred to by @var{exp} should be grafted when
4014 applicable.
4015
4016 When @var{references-graphs} is true, it must be a list of tuples of one of the
4017 following forms:
4018
4019 @example
4020 (@var{file-name} @var{package})
4021 (@var{file-name} @var{package} @var{output})
4022 (@var{file-name} @var{derivation})
4023 (@var{file-name} @var{derivation} @var{output})
4024 (@var{file-name} @var{store-item})
4025 @end example
4026
4027 The right-hand-side of each element of @var{references-graphs} is automatically made
4028 an input of the build process of @var{exp}. In the build environment, each
4029 @var{file-name} contains the reference graph of the corresponding item, in a simple
4030 text format.
4031
4032 @var{allowed-references} must be either @code{#f} or a list of output names and packages.
4033 In the latter case, the list denotes store items that the result is allowed to
4034 refer to. Any reference to another store item will lead to a build error.
4035 Similarly for @var{disallowed-references}, which can list items that must not be
4036 referenced by the outputs.
4037
4038 The other arguments are as for @code{derivation} (@pxref{Derivations}).
4039 @end deffn
4040
4041 @cindex file-like objects
4042 The @code{local-file}, @code{plain-file}, @code{computed-file},
4043 @code{program-file}, and @code{scheme-file} procedures below return
4044 @dfn{file-like objects}. That is, when unquoted in a G-expression,
4045 these objects lead to a file in the store. Consider this G-expression:
4046
4047 @example
4048 #~(system* #$(file-append glibc "/sbin/nscd") "-f"
4049 #$(local-file "/tmp/my-nscd.conf"))
4050 @end example
4051
4052 The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
4053 to the store. Once expanded, for instance @i{via}
4054 @code{gexp->derivation}, the G-expression refers to that copy under
4055 @file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
4056 does not have any effect on what the G-expression does.
4057 @code{plain-file} can be used similarly; it differs in that the file
4058 content is directly passed as a string.
4059
4060 @deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
4061 [#:recursive? #f] [#:select? (const #t)]
4062 Return an object representing local file @var{file} to add to the store; this
4063 object can be used in a gexp. If @var{file} is a relative file name, it is looked
4064 up relative to the source file where this form appears. @var{file} will be added to
4065 the store under @var{name}--by default the base name of @var{file}.
4066
4067 When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
4068 designates a flat file and @var{recursive?} is true, its contents are added, and its
4069 permission bits are kept.
4070
4071 When @var{recursive?} is true, call @code{(@var{select?} @var{file}
4072 @var{stat})} for each directory entry, where @var{file} is the entry's
4073 absolute file name and @var{stat} is the result of @code{lstat}; exclude
4074 entries for which @var{select?} does not return true.
4075
4076 This is the declarative counterpart of the @code{interned-file} monadic
4077 procedure (@pxref{The Store Monad, @code{interned-file}}).
4078 @end deffn
4079
4080 @deffn {Scheme Procedure} plain-file @var{name} @var{content}
4081 Return an object representing a text file called @var{name} with the given
4082 @var{content} (a string) to be added to the store.
4083
4084 This is the declarative counterpart of @code{text-file}.
4085 @end deffn
4086
4087 @deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
4088 [#:options '(#:local-build? #t)]
4089 Return an object representing the store item @var{name}, a file or
4090 directory computed by @var{gexp}. @var{options}
4091 is a list of additional arguments to pass to @code{gexp->derivation}.
4092
4093 This is the declarative counterpart of @code{gexp->derivation}.
4094 @end deffn
4095
4096 @deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
4097 Return an executable script @var{name} that runs @var{exp} using
4098 @var{guile}, with @var{exp}'s imported modules in its search path.
4099
4100 The example below builds a script that simply invokes the @command{ls}
4101 command:
4102
4103 @example
4104 (use-modules (guix gexp) (gnu packages base))
4105
4106 (gexp->script "list-files"
4107 #~(execl #$(file-append coreutils "/bin/ls")
4108 "ls"))
4109 @end example
4110
4111 When ``running'' it through the store (@pxref{The Store Monad,
4112 @code{run-with-store}}), we obtain a derivation that produces an
4113 executable file @file{/gnu/store/@dots{}-list-files} along these lines:
4114
4115 @example
4116 #!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
4117 !#
4118 (execl "/gnu/store/@dots{}-coreutils-8.22"/bin/ls" "ls")
4119 @end example
4120 @end deffn
4121
4122 @deffn {Scheme Procedure} program-file @var{name} @var{exp} @
4123 [#:guile #f]
4124 Return an object representing the executable store item @var{name} that
4125 runs @var{gexp}. @var{guile} is the Guile package used to execute that
4126 script.
4127
4128 This is the declarative counterpart of @code{gexp->script}.
4129 @end deffn
4130
4131 @deffn {Monadic Procedure} gexp->file @var{name} @var{exp} @
4132 [#:set-load-path? #t]
4133 Return a derivation that builds a file @var{name} containing @var{exp}.
4134 When @var{set-load-path?} is true, emit code in the resulting file to
4135 set @code{%load-path} and @code{%load-compiled-path} to honor
4136 @var{exp}'s imported modules.
4137
4138 The resulting file holds references to all the dependencies of @var{exp}
4139 or a subset thereof.
4140 @end deffn
4141
4142 @deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
4143 Return an object representing the Scheme file @var{name} that contains
4144 @var{exp}.
4145
4146 This is the declarative counterpart of @code{gexp->file}.
4147 @end deffn
4148
4149 @deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
4150 Return as a monadic value a derivation that builds a text file
4151 containing all of @var{text}. @var{text} may list, in addition to
4152 strings, objects of any type that can be used in a gexp: packages,
4153 derivations, local file objects, etc. The resulting store file holds
4154 references to all these.
4155
4156 This variant should be preferred over @code{text-file} anytime the file
4157 to create will reference items from the store. This is typically the
4158 case when building a configuration file that embeds store file names,
4159 like this:
4160
4161 @example
4162 (define (profile.sh)
4163 ;; Return the name of a shell script in the store that
4164 ;; initializes the 'PATH' environment variable.
4165 (text-file* "profile.sh"
4166 "export PATH=" coreutils "/bin:"
4167 grep "/bin:" sed "/bin\n"))
4168 @end example
4169
4170 In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
4171 will reference @var{coreutils}, @var{grep}, and @var{sed}, thereby
4172 preventing them from being garbage-collected during its lifetime.
4173 @end deffn
4174
4175 @deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
4176 Return an object representing store file @var{name} containing
4177 @var{text}. @var{text} is a sequence of strings and file-like objects,
4178 as in:
4179
4180 @example
4181 (mixed-text-file "profile"
4182 "export PATH=" coreutils "/bin:" grep "/bin")
4183 @end example
4184
4185 This is the declarative counterpart of @code{text-file*}.
4186 @end deffn
4187
4188 @deffn {Scheme Procedure} file-append @var{obj} @var{suffix} @dots{}
4189 Return a file-like object that expands to the concatenation of @var{obj}
4190 and @var{suffix}, where @var{obj} is a lowerable object and each
4191 @var{suffix} is a string.
4192
4193 As an example, consider this gexp:
4194
4195 @example
4196 (gexp->script "run-uname"
4197 #~(system* #$(file-append coreutils
4198 "/bin/uname")))
4199 @end example
4200
4201 The same effect could be achieved with:
4202
4203 @example
4204 (gexp->script "run-uname"
4205 #~(system* (string-append #$coreutils
4206 "/bin/uname")))
4207 @end example
4208
4209 There is one difference though: in the @code{file-append} case, the
4210 resulting script contains the absolute file name as a string, whereas in
4211 the second case, the resulting script contains a @code{(string-append
4212 @dots{})} expression to construct the file name @emph{at run time}.
4213 @end deffn
4214
4215
4216 Of course, in addition to gexps embedded in ``host'' code, there are
4217 also modules containing build tools. To make it clear that they are
4218 meant to be used in the build stratum, these modules are kept in the
4219 @code{(guix build @dots{})} name space.
4220
4221 @cindex lowering, of high-level objects in gexps
4222 Internally, high-level objects are @dfn{lowered}, using their compiler,
4223 to either derivations or store items. For instance, lowering a package
4224 yields a derivation, and lowering a @code{plain-file} yields a store
4225 item. This is achieved using the @code{lower-object} monadic procedure.
4226
4227 @deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
4228 [#:target #f]
4229 Return as a value in @var{%store-monad} the derivation or store item
4230 corresponding to @var{obj} for @var{system}, cross-compiling for
4231 @var{target} if @var{target} is true. @var{obj} must be an object that
4232 has an associated gexp compiler, such as a @code{<package>}.
4233 @end deffn
4234
4235
4236 @c *********************************************************************
4237 @node Utilities
4238 @chapter Utilities
4239
4240 This section describes Guix command-line utilities. Some of them are
4241 primarily targeted at developers and users who write new package
4242 definitions, while others are more generally useful. They complement
4243 the Scheme programming interface of Guix in a convenient way.
4244
4245 @menu
4246 * Invoking guix build:: Building packages from the command line.
4247 * Invoking guix edit:: Editing package definitions.
4248 * Invoking guix download:: Downloading a file and printing its hash.
4249 * Invoking guix hash:: Computing the cryptographic hash of a file.
4250 * Invoking guix import:: Importing package definitions.
4251 * Invoking guix refresh:: Updating package definitions.
4252 * Invoking guix lint:: Finding errors in package definitions.
4253 * Invoking guix size:: Profiling disk usage.
4254 * Invoking guix graph:: Visualizing the graph of packages.
4255 * Invoking guix environment:: Setting up development environments.
4256 * Invoking guix publish:: Sharing substitutes.
4257 * Invoking guix challenge:: Challenging substitute servers.
4258 * Invoking guix container:: Process isolation.
4259 @end menu
4260
4261 @node Invoking guix build
4262 @section Invoking @command{guix build}
4263
4264 The @command{guix build} command builds packages or derivations and
4265 their dependencies, and prints the resulting store paths. Note that it
4266 does not modify the user's profile---this is the job of the
4267 @command{guix package} command (@pxref{Invoking guix package}). Thus,
4268 it is mainly useful for distribution developers.
4269
4270 The general syntax is:
4271
4272 @example
4273 guix build @var{options} @var{package-or-derivation}@dots{}
4274 @end example
4275
4276 As an example, the following command builds the latest versions of Emacs
4277 and of Guile, displays their build logs, and finally displays the
4278 resulting directories:
4279
4280 @example
4281 guix build emacs guile
4282 @end example
4283
4284 Similarly, the following command builds all the available packages:
4285
4286 @example
4287 guix build --quiet --keep-going \
4288 `guix package -A | cut -f1,2 --output-delimiter=@@`
4289 @end example
4290
4291 @var{package-or-derivation} may be either the name of a package found in
4292 the software distribution such as @code{coreutils} or
4293 @code{coreutils-8.20}, or a derivation such as
4294 @file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
4295 package with the corresponding name (and optionally version) is searched
4296 for among the GNU distribution modules (@pxref{Package Modules}).
4297
4298 Alternatively, the @code{--expression} option may be used to specify a
4299 Scheme expression that evaluates to a package; this is useful when
4300 disambiguating among several same-named packages or package variants is
4301 needed.
4302
4303 There may be zero or more @var{options}. The available options are
4304 described in the subsections below.
4305
4306 @menu
4307 * Common Build Options:: Build options for most commands.
4308 * Package Transformation Options:: Creating variants of packages.
4309 * Additional Build Options:: Options specific to 'guix build'.
4310 @end menu
4311
4312 @node Common Build Options
4313 @subsection Common Build Options
4314
4315 A number of options that control the build process are common to
4316 @command{guix build} and other commands that can spawn builds, such as
4317 @command{guix package} or @command{guix archive}. These are the
4318 following:
4319
4320 @table @code
4321
4322 @item --load-path=@var{directory}
4323 @itemx -L @var{directory}
4324 Add @var{directory} to the front of the package module search path
4325 (@pxref{Package Modules}).
4326
4327 This allows users to define their own packages and make them visible to
4328 the command-line tools.
4329
4330 @item --keep-failed
4331 @itemx -K
4332 Keep the build tree of failed builds. Thus, if a build fails, its build
4333 tree is kept under @file{/tmp}, in a directory whose name is shown at
4334 the end of the build log. This is useful when debugging build issues.
4335
4336 @item --keep-going
4337 @itemx -k
4338 Keep going when some of the derivations fail to build; return only once
4339 all the builds have either completed or failed.
4340
4341 The default behavior is to stop as soon as one of the specified
4342 derivations has failed.
4343
4344 @item --dry-run
4345 @itemx -n
4346 Do not build the derivations.
4347
4348 @item --fallback
4349 When substituting a pre-built binary fails, fall back to building
4350 packages locally.
4351
4352 @item --substitute-urls=@var{urls}
4353 @anchor{client-substitute-urls}
4354 Consider @var{urls} the whitespace-separated list of substitute source
4355 URLs, overriding the default list of URLs of @command{guix-daemon}
4356 (@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
4357
4358 This means that substitutes may be downloaded from @var{urls}, provided
4359 they are signed by a key authorized by the system administrator
4360 (@pxref{Substitutes}).
4361
4362 When @var{urls} is the empty string, substitutes are effectively
4363 disabled.
4364
4365 @item --no-substitutes
4366 Do not use substitutes for build products. That is, always build things
4367 locally instead of allowing downloads of pre-built binaries
4368 (@pxref{Substitutes}).
4369
4370 @item --no-grafts
4371 Do not ``graft'' packages. In practice, this means that package updates
4372 available as grafts are not applied. @xref{Security Updates}, for more
4373 information on grafts.
4374
4375 @item --rounds=@var{n}
4376 Build each derivation @var{n} times in a row, and raise an error if
4377 consecutive build results are not bit-for-bit identical.
4378
4379 This is a useful way to detect non-deterministic builds processes.
4380 Non-deterministic build processes are a problem because they make it
4381 practically impossible for users to @emph{verify} whether third-party
4382 binaries are genuine. @xref{Invoking guix challenge}, for more.
4383
4384 Note that, currently, the differing build results are not kept around,
4385 so you will have to manually investigate in case of an error---e.g., by
4386 stashing one of the build results with @code{guix archive --export}
4387 (@pxref{Invoking guix archive}), then rebuilding, and finally comparing
4388 the two results.
4389
4390 @item --no-build-hook
4391 Do not attempt to offload builds @i{via} the ``build hook'' of the daemon
4392 (@pxref{Daemon Offload Setup}). That is, always build things locally
4393 instead of offloading builds to remote machines.
4394
4395 @item --max-silent-time=@var{seconds}
4396 When the build or substitution process remains silent for more than
4397 @var{seconds}, terminate it and report a build failure.
4398
4399 @item --timeout=@var{seconds}
4400 Likewise, when the build or substitution process lasts for more than
4401 @var{seconds}, terminate it and report a build failure.
4402
4403 By default there is no timeout. This behavior can be restored with
4404 @code{--timeout=0}.
4405
4406 @item --verbosity=@var{level}
4407 Use the given verbosity level. @var{level} must be an integer between 0
4408 and 5; higher means more verbose output. Setting a level of 4 or more
4409 may be helpful when debugging setup issues with the build daemon.
4410
4411 @item --cores=@var{n}
4412 @itemx -c @var{n}
4413 Allow the use of up to @var{n} CPU cores for the build. The special
4414 value @code{0} means to use as many CPU cores as available.
4415
4416 @item --max-jobs=@var{n}
4417 @itemx -M @var{n}
4418 Allow at most @var{n} build jobs in parallel. @xref{Invoking
4419 guix-daemon, @code{--max-jobs}}, for details about this option and the
4420 equivalent @command{guix-daemon} option.
4421
4422 @end table
4423
4424 Behind the scenes, @command{guix build} is essentially an interface to
4425 the @code{package-derivation} procedure of the @code{(guix packages)}
4426 module, and to the @code{build-derivations} procedure of the @code{(guix
4427 derivations)} module.
4428
4429 In addition to options explicitly passed on the command line,
4430 @command{guix build} and other @command{guix} commands that support
4431 building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
4432
4433 @defvr {Environment Variable} GUIX_BUILD_OPTIONS
4434 Users can define this variable to a list of command line options that
4435 will automatically be used by @command{guix build} and other
4436 @command{guix} commands that can perform builds, as in the example
4437 below:
4438
4439 @example
4440 $ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
4441 @end example
4442
4443 These options are parsed independently, and the result is appended to
4444 the parsed command-line options.
4445 @end defvr
4446
4447
4448 @node Package Transformation Options
4449 @subsection Package Transformation Options
4450
4451 @cindex package variants
4452 Another set of command-line options supported by @command{guix build}
4453 and also @command{guix package} are @dfn{package transformation
4454 options}. These are options that make it possible to define @dfn{package
4455 variants}---for instance, packages built from different source code.
4456 This is a convenient way to create customized packages on the fly
4457 without having to type in the definitions of package variants
4458 (@pxref{Defining Packages}).
4459
4460 @table @code
4461
4462 @item --with-source=@var{source}
4463 Use @var{source} as the source of the corresponding package.
4464 @var{source} must be a file name or a URL, as for @command{guix
4465 download} (@pxref{Invoking guix download}).
4466
4467 The ``corresponding package'' is taken to be the one specified on the
4468 command line the name of which matches the base of @var{source}---e.g.,
4469 if @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
4470 package is @code{guile}. Likewise, the version string is inferred from
4471 @var{source}; in the previous example, it is @code{2.0.10}.
4472
4473 This option allows users to try out versions of packages other than the
4474 one provided by the distribution. The example below downloads
4475 @file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
4476 the @code{ed} package:
4477
4478 @example
4479 guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
4480 @end example
4481
4482 As a developer, @code{--with-source} makes it easy to test release
4483 candidates:
4484
4485 @example
4486 guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
4487 @end example
4488
4489 @dots{} or to build from a checkout in a pristine environment:
4490
4491 @example
4492 $ git clone git://git.sv.gnu.org/guix.git
4493 $ guix build guix --with-source=./guix
4494 @end example
4495
4496 @item --with-input=@var{package}=@var{replacement}
4497 Replace dependency on @var{package} by a dependency on
4498 @var{replacement}. @var{package} must be a package name, and
4499 @var{replacement} must be a package specification such as @code{guile}
4500 or @code{guile@@1.8}.
4501
4502 For instance, the following command builds Guix, but replaces its
4503 dependency on the current stable version of Guile with a dependency on
4504 the development version of Guile, @code{guile-next}:
4505
4506 @example
4507 guix build --with-input=guile=guile-next guix
4508 @end example
4509
4510 This is a recursive, deep replacement. So in this example, both
4511 @code{guix} and its dependency @code{guile-json} (which also depends on
4512 @code{guile}) get rebuilt against @code{guile-next}.
4513
4514 This is implemented using the @code{package-input-rewriting} Scheme
4515 procedure (@pxref{Defining Packages, @code{package-input-rewriting}}).
4516 @end table
4517
4518 @node Additional Build Options
4519 @subsection Additional Build Options
4520
4521 The command-line options presented below are specific to @command{guix
4522 build}.
4523
4524 @table @code
4525
4526 @item --quiet
4527 @itemx -q
4528 Build quietly, without displaying the build log. Upon completion, the
4529 build log is kept in @file{/var} (or similar) and can always be
4530 retrieved using the @option{--log-file} option.
4531
4532 @item --file=@var{file}
4533 @itemx -f @var{file}
4534
4535 Build the package or derivation that the code within @var{file}
4536 evaluates to.
4537
4538 As an example, @var{file} might contain a package definition like this
4539 (@pxref{Defining Packages}):
4540
4541 @example
4542 @verbatiminclude package-hello.scm
4543 @end example
4544
4545 @item --expression=@var{expr}
4546 @itemx -e @var{expr}
4547 Build the package or derivation @var{expr} evaluates to.
4548
4549 For example, @var{expr} may be @code{(@@ (gnu packages guile)
4550 guile-1.8)}, which unambiguously designates this specific variant of
4551 version 1.8 of Guile.
4552
4553 Alternatively, @var{expr} may be a G-expression, in which case it is used
4554 as a build program passed to @code{gexp->derivation}
4555 (@pxref{G-Expressions}).
4556
4557 Lastly, @var{expr} may refer to a zero-argument monadic procedure
4558 (@pxref{The Store Monad}). The procedure must return a derivation as a
4559 monadic value, which is then passed through @code{run-with-store}.
4560
4561 @item --source
4562 @itemx -S
4563 Build the source derivations of the packages, rather than the packages
4564 themselves.
4565
4566 For instance, @code{guix build -S gcc} returns something like
4567 @file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
4568 source tarball.
4569
4570 The returned source tarball is the result of applying any patches and
4571 code snippets specified in the package @code{origin} (@pxref{Defining
4572 Packages}).
4573
4574 @item --sources
4575 Fetch and return the source of @var{package-or-derivation} and all their
4576 dependencies, recursively. This is a handy way to obtain a local copy
4577 of all the source code needed to build @var{packages}, allowing you to
4578 eventually build them even without network access. It is an extension
4579 of the @code{--source} option and can accept one of the following
4580 optional argument values:
4581
4582 @table @code
4583 @item package
4584 This value causes the @code{--sources} option to behave in the same way
4585 as the @code{--source} option.
4586
4587 @item all
4588 Build the source derivations of all packages, including any source that
4589 might be listed as @code{inputs}. This is the default value.
4590
4591 @example
4592 $ guix build --sources tzdata
4593 The following derivations will be built:
4594 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
4595 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4596 @end example
4597
4598 @item transitive
4599 Build the source derivations of all packages, as well of all transitive
4600 inputs to the packages. This can be used e.g. to
4601 prefetch package source for later offline building.
4602
4603 @example
4604 $ guix build --sources=transitive tzdata
4605 The following derivations will be built:
4606 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4607 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
4608 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
4609 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
4610 /gnu/store/@dots{}-make-4.1.tar.xz.drv
4611 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
4612 @dots{}
4613 @end example
4614
4615 @end table
4616
4617 @item --system=@var{system}
4618 @itemx -s @var{system}
4619 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
4620 the system type of the build host.
4621
4622 An example use of this is on Linux-based systems, which can emulate
4623 different personalities. For instance, passing
4624 @code{--system=i686-linux} on an @code{x86_64-linux} system allows users
4625 to build packages in a complete 32-bit environment.
4626
4627 @item --target=@var{triplet}
4628 @cindex cross-compilation
4629 Cross-build for @var{triplet}, which must be a valid GNU triplet, such
4630 as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
4631 configuration triplets,, configure, GNU Configure and Build System}).
4632
4633 @anchor{build-check}
4634 @item --check
4635 @cindex determinism, checking
4636 @cindex reproducibility, checking
4637 Rebuild @var{package-or-derivation}, which are already available in the
4638 store, and raise an error if the build results are not bit-for-bit
4639 identical.
4640
4641 This mechanism allows you to check whether previously installed
4642 substitutes are genuine (@pxref{Substitutes}), or whether the build result
4643 of a package is deterministic. @xref{Invoking guix challenge}, for more
4644 background information and tools.
4645
4646 When used in conjunction with @option{--keep-failed}, the differing
4647 output is kept in the store, under @file{/gnu/store/@dots{}-check}.
4648 This makes it easy to look for differences between the two results.
4649
4650 @item --derivations
4651 @itemx -d
4652 Return the derivation paths, not the output paths, of the given
4653 packages.
4654
4655 @item --root=@var{file}
4656 @itemx -r @var{file}
4657 Make @var{file} a symlink to the result, and register it as a garbage
4658 collector root.
4659
4660 @item --log-file
4661 Return the build log file names or URLs for the given
4662 @var{package-or-derivation}, or raise an error if build logs are
4663 missing.
4664
4665 This works regardless of how packages or derivations are specified. For
4666 instance, the following invocations are equivalent:
4667
4668 @example
4669 guix build --log-file `guix build -d guile`
4670 guix build --log-file `guix build guile`
4671 guix build --log-file guile
4672 guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
4673 @end example
4674
4675 If a log is unavailable locally, and unless @code{--no-substitutes} is
4676 passed, the command looks for a corresponding log on one of the
4677 substitute servers (as specified with @code{--substitute-urls}.)
4678
4679 So for instance, imagine you want to see the build log of GDB on MIPS,
4680 but you are actually on an @code{x86_64} machine:
4681
4682 @example
4683 $ guix build --log-file gdb -s mips64el-linux
4684 https://hydra.gnu.org/log/@dots{}-gdb-7.10
4685 @end example
4686
4687 You can freely access a huge library of build logs!
4688 @end table
4689
4690
4691 @node Invoking guix edit
4692 @section Invoking @command{guix edit}
4693
4694 @cindex package definition, editing
4695 So many packages, so many source files! The @command{guix edit} command
4696 facilitates the life of users and packagers by pointing their editor at
4697 the source file containing the definition of the specified packages.
4698 For instance:
4699
4700 @example
4701 guix edit gcc@@4.9 vim
4702 @end example
4703
4704 @noindent
4705 launches the program specified in the @code{VISUAL} or in the
4706 @code{EDITOR} environment variable to view the recipe of GCC@tie{}4.9.3
4707 and that of Vim.
4708
4709 If you are using a Guix Git checkout (@pxref{Building from Git}), or
4710 have created your own packages on @code{GUIX_PACKAGE_PATH}
4711 (@pxref{Defining Packages}), you will be able to edit the package
4712 recipes. Otherwise, you will be able to examine the read-only recipes
4713 for packages currently in the store.
4714
4715 If you are using Emacs, note that the Emacs user interface provides the
4716 @kbd{M-x guix-edit} command and a similar functionality in the ``package
4717 info'' and ``package list'' buffers created by the @kbd{M-x
4718 guix-search-by-name} and similar commands (@pxref{Emacs Commands}).
4719
4720
4721 @node Invoking guix download
4722 @section Invoking @command{guix download}
4723
4724 When writing a package definition, developers typically need to download
4725 a source tarball, compute its SHA256 hash, and write that
4726 hash in the package definition (@pxref{Defining Packages}). The
4727 @command{guix download} tool helps with this task: it downloads a file
4728 from the given URI, adds it to the store, and prints both its file name
4729 in the store and its SHA256 hash.
4730
4731 The fact that the downloaded file is added to the store saves bandwidth:
4732 when the developer eventually tries to build the newly defined package
4733 with @command{guix build}, the source tarball will not have to be
4734 downloaded again because it is already in the store. It is also a
4735 convenient way to temporarily stash files, which may be deleted
4736 eventually (@pxref{Invoking guix gc}).
4737
4738 The @command{guix download} command supports the same URIs as used in
4739 package definitions. In particular, it supports @code{mirror://} URIs.
4740 @code{https} URIs (HTTP over TLS) are supported @emph{provided} the
4741 Guile bindings for GnuTLS are available in the user's environment; when
4742 they are not available, an error is raised. @xref{Guile Preparations,
4743 how to install the GnuTLS bindings for Guile,, gnutls-guile,
4744 GnuTLS-Guile}, for more information.
4745
4746 The following option is available:
4747
4748 @table @code
4749 @item --format=@var{fmt}
4750 @itemx -f @var{fmt}
4751 Write the hash in the format specified by @var{fmt}. For more
4752 information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
4753 @end table
4754
4755 @node Invoking guix hash
4756 @section Invoking @command{guix hash}
4757
4758 The @command{guix hash} command computes the SHA256 hash of a file.
4759 It is primarily a convenience tool for anyone contributing to the
4760 distribution: it computes the cryptographic hash of a file, which can be
4761 used in the definition of a package (@pxref{Defining Packages}).
4762
4763 The general syntax is:
4764
4765 @example
4766 guix hash @var{option} @var{file}
4767 @end example
4768
4769 @command{guix hash} has the following options:
4770
4771 @table @code
4772
4773 @item --format=@var{fmt}
4774 @itemx -f @var{fmt}
4775 Write the hash in the format specified by @var{fmt}.
4776
4777 Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4778 (@code{hex} and @code{hexadecimal} can be used as well).
4779
4780 If the @option{--format} option is not specified, @command{guix hash}
4781 will output the hash in @code{nix-base32}. This representation is used
4782 in the definitions of packages.
4783
4784 @item --recursive
4785 @itemx -r
4786 Compute the hash on @var{file} recursively.
4787
4788 In this case, the hash is computed on an archive containing @var{file},
4789 including its children if it is a directory. Some of the metadata of
4790 @var{file} is part of the archive; for instance, when @var{file} is a
4791 regular file, the hash is different depending on whether @var{file} is
4792 executable or not. Metadata such as time stamps has no impact on the
4793 hash (@pxref{Invoking guix archive}).
4794 @c FIXME: Replace xref above with xref to an ``Archive'' section when
4795 @c it exists.
4796
4797 @item --exclude-vcs
4798 @itemx -x
4799 When combined with @option{--recursive}, exclude version control system
4800 directories (@file{.bzr}, @file{.git}, @file{.hg}, etc.)
4801
4802 @vindex git-fetch
4803 As an example, here is how you would compute the hash of a Git checkout,
4804 which is useful when using the @code{git-fetch} method (@pxref{origin
4805 Reference}):
4806
4807 @example
4808 $ git clone http://example.org/foo.git
4809 $ cd foo
4810 $ guix hash -rx .
4811 @end example
4812 @end table
4813
4814 @node Invoking guix import
4815 @section Invoking @command{guix import}
4816
4817 @cindex importing packages
4818 @cindex package import
4819 @cindex package conversion
4820 The @command{guix import} command is useful for people who would like to
4821 add a package to the distribution with as little work as
4822 possible---a legitimate demand. The command knows of a few
4823 repositories from which it can ``import'' package metadata. The result
4824 is a package definition, or a template thereof, in the format we know
4825 (@pxref{Defining Packages}).
4826
4827 The general syntax is:
4828
4829 @example
4830 guix import @var{importer} @var{options}@dots{}
4831 @end example
4832
4833 @var{importer} specifies the source from which to import package
4834 metadata, and @var{options} specifies a package identifier and other
4835 options specific to @var{importer}. Currently, the available
4836 ``importers'' are:
4837
4838 @table @code
4839 @item gnu
4840 Import metadata for the given GNU package. This provides a template
4841 for the latest version of that GNU package, including the hash of its
4842 source tarball, and its canonical synopsis and description.
4843
4844 Additional information such as the package dependencies and its
4845 license needs to be figured out manually.
4846
4847 For example, the following command returns a package definition for
4848 GNU@tie{}Hello:
4849
4850 @example
4851 guix import gnu hello
4852 @end example
4853
4854 Specific command-line options are:
4855
4856 @table @code
4857 @item --key-download=@var{policy}
4858 As for @code{guix refresh}, specify the policy to handle missing OpenPGP
4859 keys when verifying the package signature. @xref{Invoking guix
4860 refresh, @code{--key-download}}.
4861 @end table
4862
4863 @item pypi
4864 @cindex pypi
4865 Import metadata from the @uref{https://pypi.python.org/, Python Package
4866 Index}@footnote{This functionality requires Guile-JSON to be installed.
4867 @xref{Requirements}.}. Information is taken from the JSON-formatted
4868 description available at @code{pypi.python.org} and usually includes all
4869 the relevant information, including package dependencies. For maximum
4870 efficiency, it is recommended to install the @command{unzip} utility, so
4871 that the importer can unzip Python wheels and gather data from them.
4872
4873 The command below imports metadata for the @code{itsdangerous} Python
4874 package:
4875
4876 @example
4877 guix import pypi itsdangerous
4878 @end example
4879
4880 @item gem
4881 @cindex gem
4882 Import metadata from @uref{https://rubygems.org/,
4883 RubyGems}@footnote{This functionality requires Guile-JSON to be
4884 installed. @xref{Requirements}.}. Information is taken from the
4885 JSON-formatted description available at @code{rubygems.org} and includes
4886 most relevant information, including runtime dependencies. There are
4887 some caveats, however. The metadata doesn't distinguish between
4888 synopses and descriptions, so the same string is used for both fields.
4889 Additionally, the details of non-Ruby dependencies required to build
4890 native extensions is unavailable and left as an exercise to the
4891 packager.
4892
4893 The command below imports metadata for the @code{rails} Ruby package:
4894
4895 @example
4896 guix import gem rails
4897 @end example
4898
4899 @item cpan
4900 @cindex CPAN
4901 Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}@footnote{This
4902 functionality requires Guile-JSON to be installed.
4903 @xref{Requirements}.}.
4904 Information is taken from the JSON-formatted metadata provided through
4905 @uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
4906 relevant information, such as module dependencies. License information
4907 should be checked closely. If Perl is available in the store, then the
4908 @code{corelist} utility will be used to filter core modules out of the
4909 list of dependencies.
4910
4911 The command command below imports metadata for the @code{Acme::Boolean}
4912 Perl module:
4913
4914 @example
4915 guix import cpan Acme::Boolean
4916 @end example
4917
4918 @item cran
4919 @cindex CRAN
4920 @cindex Bioconductor
4921 Import metadata from @uref{http://cran.r-project.org/, CRAN}, the
4922 central repository for the @uref{http://r-project.org, GNU@tie{}R
4923 statistical and graphical environment}.
4924
4925 Information is extracted from the @code{DESCRIPTION} file of the package.
4926
4927 The command command below imports metadata for the @code{Cairo}
4928 R package:
4929
4930 @example
4931 guix import cran Cairo
4932 @end example
4933
4934 When @code{--archive=bioconductor} is added, metadata is imported from
4935 @uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
4936 packages for for the analysis and comprehension of high-throughput
4937 genomic data in bioinformatics.
4938
4939 Information is extracted from the @code{DESCRIPTION} file of a package
4940 published on the web interface of the Bioconductor SVN repository.
4941
4942 The command below imports metadata for the @code{GenomicRanges}
4943 R package:
4944
4945 @example
4946 guix import cran --archive=bioconductor GenomicRanges
4947 @end example
4948
4949 @item nix
4950 Import metadata from a local copy of the source of the
4951 @uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
4952 relies on the @command{nix-instantiate} command of
4953 @uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
4954 typically written in a mixture of Nix-language and Bash code. This
4955 command only imports the high-level package structure that is written in
4956 the Nix language. It normally includes all the basic fields of a
4957 package definition.
4958
4959 When importing a GNU package, the synopsis and descriptions are replaced
4960 by their canonical upstream variant.
4961
4962 Usually, you will first need to do:
4963
4964 @example
4965 export NIX_REMOTE=daemon
4966 @end example
4967
4968 @noindent
4969 so that @command{nix-instantiate} does not try to open the Nix database.
4970
4971 As an example, the command below imports the package definition of
4972 LibreOffice (more precisely, it imports the definition of the package
4973 bound to the @code{libreoffice} top-level attribute):
4974
4975 @example
4976 guix import nix ~/path/to/nixpkgs libreoffice
4977 @end example
4978
4979 @item hackage
4980 @cindex hackage
4981 Import metadata from the Haskell community's central package archive
4982 @uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4983 Cabal files and includes all the relevant information, including package
4984 dependencies.
4985
4986 Specific command-line options are:
4987
4988 @table @code
4989 @item --stdin
4990 @itemx -s
4991 Read a Cabal file from standard input.
4992 @item --no-test-dependencies
4993 @itemx -t
4994 Do not include dependencies required only by the test suites.
4995 @item --cabal-environment=@var{alist}
4996 @itemx -e @var{alist}
4997 @var{alist} is a Scheme alist defining the environment in which the
4998 Cabal conditionals are evaluated. The accepted keys are: @code{os},
4999 @code{arch}, @code{impl} and a string representing the name of a flag.
5000 The value associated with a flag has to be either the symbol
5001 @code{true} or @code{false}. The value associated with other keys
5002 has to conform to the Cabal file format definition. The default value
5003 associated with the keys @code{os}, @code{arch} and @code{impl} is
5004 @samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
5005 @end table
5006
5007 The command below imports metadata for the latest version of the
5008 @code{HTTP} Haskell package without including test dependencies and
5009 specifying the value of the flag @samp{network-uri} as @code{false}:
5010
5011 @example
5012 guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
5013 @end example
5014
5015 A specific package version may optionally be specified by following the
5016 package name by an at-sign and a version number as in the following example:
5017
5018 @example
5019 guix import hackage mtl@@2.1.3.1
5020 @end example
5021
5022 @item elpa
5023 @cindex elpa
5024 Import metadata from an Emacs Lisp Package Archive (ELPA) package
5025 repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
5026
5027 Specific command-line options are:
5028
5029 @table @code
5030 @item --archive=@var{repo}
5031 @itemx -a @var{repo}
5032 @var{repo} identifies the archive repository from which to retrieve the
5033 information. Currently the supported repositories and their identifiers
5034 are:
5035 @itemize -
5036 @item
5037 @uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
5038 identifier. This is the default.
5039
5040 @item
5041 @uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
5042 @code{melpa-stable} identifier.
5043
5044 @item
5045 @uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
5046 identifier.
5047 @end itemize
5048 @end table
5049 @end table
5050
5051 The structure of the @command{guix import} code is modular. It would be
5052 useful to have more importers for other package formats, and your help
5053 is welcome here (@pxref{Contributing}).
5054
5055 @node Invoking guix refresh
5056 @section Invoking @command{guix refresh}
5057
5058 The primary audience of the @command{guix refresh} command is developers
5059 of the GNU software distribution. By default, it reports any packages
5060 provided by the distribution that are outdated compared to the latest
5061 upstream version, like this:
5062
5063 @example
5064 $ guix refresh
5065 gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
5066 gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
5067 @end example
5068
5069 It does so by browsing the FTP directory of each package and determining
5070 the highest version number of the source tarballs therein. The command
5071 knows how to update specific types of packages: GNU packages, ELPA
5072 packages, etc.---see the documentation for @option{--type} below. The
5073 are many packages, though, for which it lacks a method to determine
5074 whether a new upstream release is available. However, the mechanism is
5075 extensible, so feel free to get in touch with us to add a new method!
5076
5077 When passed @code{--update}, it modifies distribution source files to
5078 update the version numbers and source tarball hashes of those package
5079 recipes (@pxref{Defining Packages}). This is achieved by downloading
5080 each package's latest source tarball and its associated OpenPGP
5081 signature, authenticating the downloaded tarball against its signature
5082 using @command{gpg}, and finally computing its hash. When the public
5083 key used to sign the tarball is missing from the user's keyring, an
5084 attempt is made to automatically retrieve it from a public key server;
5085 when this is successful, the key is added to the user's keyring; otherwise,
5086 @command{guix refresh} reports an error.
5087
5088 The following options are supported:
5089
5090 @table @code
5091
5092 @item --expression=@var{expr}
5093 @itemx -e @var{expr}
5094 Consider the package @var{expr} evaluates to.
5095
5096 This is useful to precisely refer to a package, as in this example:
5097
5098 @example
5099 guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
5100 @end example
5101
5102 This command lists the dependents of the ``final'' libc (essentially all
5103 the packages.)
5104
5105 @item --update
5106 @itemx -u
5107 Update distribution source files (package recipes) in place. This is
5108 usually run from a checkout of the Guix source tree (@pxref{Running
5109 Guix Before It Is Installed}):
5110
5111 @example
5112 $ ./pre-inst-env guix refresh -s non-core
5113 @end example
5114
5115 @xref{Defining Packages}, for more information on package definitions.
5116
5117 @item --select=[@var{subset}]
5118 @itemx -s @var{subset}
5119 Select all the packages in @var{subset}, one of @code{core} or
5120 @code{non-core}.
5121
5122 The @code{core} subset refers to all the packages at the core of the
5123 distribution---i.e., packages that are used to build ``everything
5124 else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
5125 changing one of these packages in the distribution entails a rebuild of
5126 all the others. Thus, such updates are an inconvenience to users in
5127 terms of build time or bandwidth used to achieve the upgrade.
5128
5129 The @code{non-core} subset refers to the remaining packages. It is
5130 typically useful in cases where an update of the core packages would be
5131 inconvenient.
5132
5133 @item --type=@var{updater}
5134 @itemx -t @var{updater}
5135 Select only packages handled by @var{updater} (may be a comma-separated
5136 list of updaters). Currently, @var{updater} may be one of:
5137
5138 @table @code
5139 @item gnu
5140 the updater for GNU packages;
5141 @item gnome
5142 the updater for GNOME packages;
5143 @item kde
5144 the updater for KDE packages;
5145 @item xorg
5146 the updater for X.org packages;
5147 @item elpa
5148 the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
5149 @item cran
5150 the updater for @uref{http://cran.r-project.org/, CRAN} packages;
5151 @item bioconductor
5152 the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
5153 @item pypi
5154 the updater for @uref{https://pypi.python.org, PyPI} packages.
5155 @item gem
5156 the updater for @uref{https://rubygems.org, RubyGems} packages.
5157 @item github
5158 the updater for @uref{https://github.com, GitHub} packages.
5159 @item hackage
5160 the updater for @uref{https://hackage.haskell.org, Hackage} packages.
5161 @end table
5162
5163 For instance, the following command only checks for updates of Emacs
5164 packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
5165
5166 @example
5167 $ guix refresh --type=elpa,cran
5168 gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
5169 gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
5170 @end example
5171
5172 @end table
5173
5174 In addition, @command{guix refresh} can be passed one or more package
5175 names, as in this example:
5176
5177 @example
5178 $ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
5179 @end example
5180
5181 @noindent
5182 The command above specifically updates the @code{emacs} and
5183 @code{idutils} packages. The @code{--select} option would have no
5184 effect in this case.
5185
5186 When considering whether to upgrade a package, it is sometimes
5187 convenient to know which packages would be affected by the upgrade and
5188 should be checked for compatibility. For this the following option may
5189 be used when passing @command{guix refresh} one or more package names:
5190
5191 @table @code
5192
5193 @item --list-updaters
5194 @itemx -L
5195 List available updaters and exit (see @option{--type} above.)
5196
5197 @item --list-dependent
5198 @itemx -l
5199 List top-level dependent packages that would need to be rebuilt as a
5200 result of upgrading one or more packages.
5201
5202 @end table
5203
5204 Be aware that the @code{--list-dependent} option only
5205 @emph{approximates} the rebuilds that would be required as a result of
5206 an upgrade. More rebuilds might be required under some circumstances.
5207
5208 @example
5209 $ guix refresh --list-dependent flex
5210 Building the following 120 packages would ensure 213 dependent packages are rebuilt:
5211 hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
5212 @end example
5213
5214 The command above lists a set of packages that could be built to check
5215 for compatibility with an upgraded @code{flex} package.
5216
5217 The following options can be used to customize GnuPG operation:
5218
5219 @table @code
5220
5221 @item --gpg=@var{command}
5222 Use @var{command} as the GnuPG 2.x command. @var{command} is searched
5223 for in @code{$PATH}.
5224
5225 @item --key-download=@var{policy}
5226 Handle missing OpenPGP keys according to @var{policy}, which may be one
5227 of:
5228
5229 @table @code
5230 @item always
5231 Always download missing OpenPGP keys from the key server, and add them
5232 to the user's GnuPG keyring.
5233
5234 @item never
5235 Never try to download missing OpenPGP keys. Instead just bail out.
5236
5237 @item interactive
5238 When a package signed with an unknown OpenPGP key is encountered, ask
5239 the user whether to download it or not. This is the default behavior.
5240 @end table
5241
5242 @item --key-server=@var{host}
5243 Use @var{host} as the OpenPGP key server when importing a public key.
5244
5245 @end table
5246
5247 The @code{github} updater uses the
5248 @uref{https://developer.github.com/v3/, GitHub API} to query for new
5249 releases. When used repeatedly e.g. when refreshing all packages,
5250 GitHub will eventually refuse to answer any further API requests. By
5251 default 60 API requests per hour are allowed, and a full refresh on all
5252 GitHub packages in Guix requires more than this. Authentication with
5253 GitHub through the use of an API token alleviates these limits. To use
5254 an API token, set the environment variable @code{GUIX_GITHUB_TOKEN} to a
5255 token procured from @uref{https://github.com/settings/tokens} or
5256 otherwise.
5257
5258
5259 @node Invoking guix lint
5260 @section Invoking @command{guix lint}
5261 The @command{guix lint} command is meant to help package developers avoid
5262 common errors and use a consistent style. It runs a number of checks on
5263 a given set of packages in order to find common mistakes in their
5264 definitions. Available @dfn{checkers} include (see
5265 @code{--list-checkers} for a complete list):
5266
5267 @table @code
5268 @item synopsis
5269 @itemx description
5270 Validate certain typographical and stylistic rules about package
5271 descriptions and synopses.
5272
5273 @item inputs-should-be-native
5274 Identify inputs that should most likely be native inputs.
5275
5276 @item source
5277 @itemx home-page
5278 @itemx source-file-name
5279 Probe @code{home-page} and @code{source} URLs and report those that are
5280 invalid. Check that the source file name is meaningful, e.g. is not
5281 just a version number or ``git-checkout'', without a declared
5282 @code{file-name} (@pxref{origin Reference}).
5283
5284 @item cve
5285 @cindex security vulnerabilities
5286 @cindex CVE, Common Vulnerabilities and Exposures
5287 Report known vulnerabilities found in the Common Vulnerabilities and
5288 Exposures (CVE) databases of the current and past year
5289 @uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
5290 NIST}.
5291
5292 To view information about a particular vulnerability, visit pages such as:
5293
5294 @itemize
5295 @item
5296 @indicateurl{https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-YYYY-ABCD}
5297 @item
5298 @indicateurl{https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-YYYY-ABCD}
5299 @end itemize
5300
5301 @noindent
5302 where @code{CVE-YYYY-ABCD} is the CVE identifier---e.g.,
5303 @code{CVE-2015-7554}.
5304
5305 Package developers can specify in package recipes the
5306 @uref{https://nvd.nist.gov/cpe.cfm,Common Platform Enumeration (CPE)}
5307 name and version of the package when they differ from the name that Guix
5308 uses, as in this example:
5309
5310 @example
5311 (package
5312 (name "grub")
5313 ;; @dots{}
5314 ;; CPE calls this package "grub2".
5315 (properties '((cpe-name . "grub2"))))
5316 @end example
5317
5318 @item formatting
5319 Warn about obvious source code formatting issues: trailing white space,
5320 use of tabulations, etc.
5321 @end table
5322
5323 The general syntax is:
5324
5325 @example
5326 guix lint @var{options} @var{package}@dots{}
5327 @end example
5328
5329 If no package is given on the command line, then all packages are checked.
5330 The @var{options} may be zero or more of the following:
5331
5332 @table @code
5333 @item --list-checkers
5334 @itemx -l
5335 List and describe all the available checkers that will be run on packages
5336 and exit.
5337
5338 @item --checkers
5339 @itemx -c
5340 Only enable the checkers specified in a comma-separated list using the
5341 names returned by @code{--list-checkers}.
5342
5343 @end table
5344
5345 @node Invoking guix size
5346 @section Invoking @command{guix size}
5347
5348 The @command{guix size} command helps package developers profile the
5349 disk usage of packages. It is easy to overlook the impact of an
5350 additional dependency added to a package, or the impact of using a
5351 single output for a package that could easily be split (@pxref{Packages
5352 with Multiple Outputs}). Such are the typical issues that
5353 @command{guix size} can highlight.
5354
5355 The command can be passed a package specification such as @code{gcc-4.8}
5356 or @code{guile:debug}, or a file name in the store. Consider this
5357 example:
5358
5359 @example
5360 $ guix size coreutils
5361 store item total self
5362 /gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
5363 /gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
5364 /gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
5365 /gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
5366 /gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
5367 /gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
5368 @end example
5369
5370 @cindex closure
5371 The store items listed here constitute the @dfn{transitive closure} of
5372 Coreutils---i.e., Coreutils and all its dependencies, recursively---as
5373 would be returned by:
5374
5375 @example
5376 $ guix gc -R /gnu/store/@dots{}-coreutils-8.23
5377 @end example
5378
5379 Here the output shows three columns next to store items. The first column,
5380 labeled ``total'', shows the size in mebibytes (MiB) of the closure of
5381 the store item---that is, its own size plus the size of all its
5382 dependencies. The next column, labeled ``self'', shows the size of the
5383 item itself. The last column shows the ratio of the size of the item
5384 itself to the space occupied by all the items listed here.
5385
5386 In this example, we see that the closure of Coreutils weighs in at
5387 70@tie{}MiB, half of which is taken by libc. (That libc represents a
5388 large fraction of the closure is not a problem @i{per se} because it is
5389 always available on the system anyway.)
5390
5391 When the package passed to @command{guix size} is available in the
5392 store, @command{guix size} queries the daemon to determine its
5393 dependencies, and measures its size in the store, similar to @command{du
5394 -ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
5395 Coreutils}).
5396
5397 When the given package is @emph{not} in the store, @command{guix size}
5398 reports information based on the available substitutes
5399 (@pxref{Substitutes}). This makes it possible it to profile disk usage of
5400 store items that are not even on disk, only available remotely.
5401
5402 You can also specify several package names:
5403
5404 @example
5405 $ guix size coreutils grep sed bash
5406 store item total self
5407 /gnu/store/@dots{}-coreutils-8.24 77.8 13.8 13.4%
5408 /gnu/store/@dots{}-grep-2.22 73.1 0.8 0.8%
5409 /gnu/store/@dots{}-bash-4.3.42 72.3 4.7 4.6%
5410 /gnu/store/@dots{}-readline-6.3 67.6 1.2 1.2%
5411 @dots{}
5412 total: 102.3 MiB
5413 @end example
5414
5415 @noindent
5416 In this example we see that the combination of the four packages takes
5417 102.3@tie{}MiB in total, which is much less than the sum of each closure
5418 since they have a lot of dependencies in common.
5419
5420 The available options are:
5421
5422 @table @option
5423
5424 @item --substitute-urls=@var{urls}
5425 Use substitute information from @var{urls}.
5426 @xref{client-substitute-urls, the same option for @code{guix build}}.
5427
5428 @item --map-file=@var{file}
5429 Write a graphical map of disk usage in PNG format to @var{file}.
5430
5431 For the example above, the map looks like this:
5432
5433 @image{images/coreutils-size-map,5in,, map of Coreutils disk usage
5434 produced by @command{guix size}}
5435
5436 This option requires that
5437 @uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
5438 installed and visible in Guile's module search path. When that is not
5439 the case, @command{guix size} fails as it tries to load it.
5440
5441 @item --system=@var{system}
5442 @itemx -s @var{system}
5443 Consider packages for @var{system}---e.g., @code{x86_64-linux}.
5444
5445 @end table
5446
5447 @node Invoking guix graph
5448 @section Invoking @command{guix graph}
5449
5450 @cindex DAG
5451 Packages and their dependencies form a @dfn{graph}, specifically a
5452 directed acyclic graph (DAG). It can quickly become difficult to have a
5453 mental model of the package DAG, so the @command{guix graph} command
5454 provides a visual representation of the DAG. @command{guix graph}
5455 emits a DAG representation in the input format of
5456 @uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
5457 directly to the @command{dot} command of Graphviz. The general
5458 syntax is:
5459
5460 @example
5461 guix graph @var{options} @var{package}@dots{}
5462 @end example
5463
5464 For example, the following command generates a PDF file representing the
5465 package DAG for the GNU@tie{}Core Utilities, showing its build-time
5466 dependencies:
5467
5468 @example
5469 guix graph coreutils | dot -Tpdf > dag.pdf
5470 @end example
5471
5472 The output looks like this:
5473
5474 @image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
5475
5476 Nice little graph, no?
5477
5478 But there is more than one graph! The one above is concise: it is the
5479 graph of package objects, omitting implicit inputs such as GCC, libc,
5480 grep, etc. It is often useful to have such a concise graph, but
5481 sometimes one may want to see more details. @command{guix graph} supports
5482 several types of graphs, allowing you to choose the level of detail:
5483
5484 @table @code
5485 @item package
5486 This is the default type used in the example above. It shows the DAG of
5487 package objects, excluding implicit dependencies. It is concise, but
5488 filters out many details.
5489
5490 @item bag-emerged
5491 This is the package DAG, @emph{including} implicit inputs.
5492
5493 For instance, the following command:
5494
5495 @example
5496 guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
5497 @end example
5498
5499 ... yields this bigger graph:
5500
5501 @image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
5502
5503 At the bottom of the graph, we see all the implicit inputs of
5504 @var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
5505
5506 Now, note that the dependencies of these implicit inputs---that is, the
5507 @dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
5508 here, for conciseness.
5509
5510 @item bag
5511 Similar to @code{bag-emerged}, but this time including all the bootstrap
5512 dependencies.
5513
5514 @item bag-with-origins
5515 Similar to @code{bag}, but also showing origins and their dependencies.
5516
5517 @item derivations
5518 This is the most detailed representation: It shows the DAG of
5519 derivations (@pxref{Derivations}) and plain store items. Compared to
5520 the above representation, many additional nodes are visible, including
5521 build scripts, patches, Guile modules, etc.
5522
5523 For this type of graph, it is also possible to pass a @file{.drv} file
5524 name instead of a package name, as in:
5525
5526 @example
5527 guix graph -t derivation `guix system build -d my-config.scm`
5528 @end example
5529 @end table
5530
5531 All the types above correspond to @emph{build-time dependencies}. The
5532 following graph type represents the @emph{run-time dependencies}:
5533
5534 @table @code
5535 @item references
5536 This is the graph of @dfn{references} of a package output, as returned
5537 by @command{guix gc --references} (@pxref{Invoking guix gc}).
5538
5539 If the given package output is not available in the store, @command{guix
5540 graph} attempts to obtain dependency information from substitutes.
5541
5542 Here you can also pass a store file name instead of a package name. For
5543 example, the command below produces the reference graph of your profile
5544 (which can be big!):
5545
5546 @example
5547 guix graph -t references `readlink -f ~/.guix-profile`
5548 @end example
5549
5550 @item referrers
5551 This is the graph of the @dfn{referrers} of a store item, as returned by
5552 @command{guix gc --referrers} (@pxref{Invoking guix gc}).
5553
5554 This relies exclusively on local information from your store. For
5555 instance, let us suppose that the current Inkscape is available in 10
5556 profiles on your machine; @command{guix graph -t referrers inkscape}
5557 will show a graph rooted at Inkscape and with those 10 profiles linked
5558 to it.
5559
5560 It can help determine what is preventing a store item from being garbage
5561 collected.
5562
5563 @end table
5564
5565 The available options are the following:
5566
5567 @table @option
5568 @item --type=@var{type}
5569 @itemx -t @var{type}
5570 Produce a graph output of @var{type}, where @var{type} must be one of
5571 the values listed above.
5572
5573 @item --list-types
5574 List the supported graph types.
5575
5576 @item --expression=@var{expr}
5577 @itemx -e @var{expr}
5578 Consider the package @var{expr} evaluates to.
5579
5580 This is useful to precisely refer to a package, as in this example:
5581
5582 @example
5583 guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
5584 @end example
5585 @end table
5586
5587
5588 @node Invoking guix environment
5589 @section Invoking @command{guix environment}
5590
5591 @cindex reproducible build environments
5592 @cindex development environments
5593 The purpose of @command{guix environment} is to assist hackers in
5594 creating reproducible development environments without polluting their
5595 package profile. The @command{guix environment} tool takes one or more
5596 packages, builds all of their inputs, and creates a shell
5597 environment to use them.
5598
5599 The general syntax is:
5600
5601 @example
5602 guix environment @var{options} @var{package}@dots{}
5603 @end example
5604
5605 The following example spawns a new shell set up for the development of
5606 GNU@tie{}Guile:
5607
5608 @example
5609 guix environment guile
5610 @end example
5611
5612 If the needed dependencies are not built yet, @command{guix environment}
5613 automatically builds them. The environment of the new shell is an augmented
5614 version of the environment that @command{guix environment} was run in.
5615 It contains the necessary search paths for building the given package
5616 added to the existing environment variables. To create a ``pure''
5617 environment, in which the original environment variables have been unset,
5618 use the @code{--pure} option@footnote{Users sometimes wrongfully augment
5619 environment variables such as @code{PATH} in their @file{~/.bashrc}
5620 file. As a consequence, when @code{guix environment} launches it, Bash
5621 may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
5622 environment variables. It is an error to define such environment
5623 variables in @file{.bashrc}; instead, they should be defined in
5624 @file{.bash_profile}, which is sourced only by log-in shells.
5625 @xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
5626 details on Bash start-up files.}.
5627
5628 @vindex GUIX_ENVIRONMENT
5629 @command{guix environment} defines the @code{GUIX_ENVIRONMENT}
5630 variable in the shell it spawns; its value is the file name of the
5631 profile of this environment. This allows users to, say, define a
5632 specific prompt for development environments in their @file{.bashrc}
5633 (@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
5634
5635 @example
5636 if [ -n "$GUIX_ENVIRONMENT" ]
5637 then
5638 export PS1="\u@@\h \w [dev]\$ "
5639 fi
5640 @end example
5641
5642 @noindent
5643 ... or to browse the profile:
5644
5645 @example
5646 $ ls "$GUIX_ENVIRONMENT/bin"
5647 @end example
5648
5649 Additionally, more than one package may be specified, in which case the
5650 union of the inputs for the given packages are used. For example, the
5651 command below spawns a shell where all of the dependencies of both Guile
5652 and Emacs are available:
5653
5654 @example
5655 guix environment guile emacs
5656 @end example
5657
5658 Sometimes an interactive shell session is not desired. An arbitrary
5659 command may be invoked by placing the @code{--} token to separate the
5660 command from the rest of the arguments:
5661
5662 @example
5663 guix environment guile -- make -j4
5664 @end example
5665
5666 In other situations, it is more convenient to specify the list of
5667 packages needed in the environment. For example, the following command
5668 runs @command{python} from an environment containing Python@tie{}2.7 and
5669 NumPy:
5670
5671 @example
5672 guix environment --ad-hoc python2-numpy python-2.7 -- python
5673 @end example
5674
5675 Furthermore, one might want the dependencies of a package and also some
5676 additional packages that are not build-time or runtime dependencies, but
5677 are useful when developing nonetheless. Because of this, the
5678 @code{--ad-hoc} flag is positional. Packages appearing before
5679 @code{--ad-hoc} are interpreted as packages whose dependencies will be
5680 added to the environment. Packages appearing after are interpreted as
5681 packages that will be added to the environment directly. For example,
5682 the following command creates a Guix development environment that
5683 additionally includes Git and strace:
5684
5685 @example
5686 guix environment guix --ad-hoc git strace
5687 @end example
5688
5689 Sometimes it is desirable to isolate the environment as much as
5690 possible, for maximal purity and reproducibility. In particular, when
5691 using Guix on a host distro that is not GuixSD, it is desirable to
5692 prevent access to @file{/usr/bin} and other system-wide resources from
5693 the development environment. For example, the following command spawns
5694 a Guile REPL in a ``container'' where only the store and the current
5695 working directory are mounted:
5696
5697 @example
5698 guix environment --ad-hoc --container guile -- guile
5699 @end example
5700
5701 @quotation Note
5702 The @code{--container} option requires Linux-libre 3.19 or newer.
5703 @end quotation
5704
5705 The available options are summarized below.
5706
5707 @table @code
5708 @item --expression=@var{expr}
5709 @itemx -e @var{expr}
5710 Create an environment for the package or list of packages that
5711 @var{expr} evaluates to.
5712
5713 For example, running:
5714
5715 @example
5716 guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
5717 @end example
5718
5719 starts a shell with the environment for this specific variant of the
5720 PETSc package.
5721
5722 Running:
5723
5724 @example
5725 guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
5726 @end example
5727
5728 starts a shell with all the GuixSD base packages available.
5729
5730 The above commands only the use default output of the given packages.
5731 To select other outputs, two element tuples can be specified:
5732
5733 @example
5734 guix environment --ad-hoc -e '(list (@ (gnu packages bash) bash) "include")'
5735 @end example
5736
5737 @item --load=@var{file}
5738 @itemx -l @var{file}
5739 Create an environment for the package or list of packages that the code
5740 within @var{file} evaluates to.
5741
5742 As an example, @var{file} might contain a definition like this
5743 (@pxref{Defining Packages}):
5744
5745 @example
5746 @verbatiminclude environment-gdb.scm
5747 @end example
5748
5749 @item --ad-hoc
5750 Include all specified packages in the resulting environment, as if an
5751 @i{ad hoc} package were defined with them as inputs. This option is
5752 useful for quickly creating an environment without having to write a
5753 package expression to contain the desired inputs.
5754
5755 For instance, the command:
5756
5757 @example
5758 guix environment --ad-hoc guile guile-sdl -- guile
5759 @end example
5760
5761 runs @command{guile} in an environment where Guile and Guile-SDL are
5762 available.
5763
5764 Note that this example implicitly asks for the default output of
5765 @code{guile} and @code{guile-sdl}, but it is possible to ask for a
5766 specific output---e.g., @code{glib:bin} asks for the @code{bin} output
5767 of @code{glib} (@pxref{Packages with Multiple Outputs}).
5768
5769 This option may be composed with the default behavior of @command{guix
5770 environment}. Packages appearing before @code{--ad-hoc} are interpreted
5771 as packages whose dependencies will be added to the environment, the
5772 default behavior. Packages appearing after are interpreted as packages
5773 that will be added to the environment directly.
5774
5775 @item --pure
5776 Unset existing environment variables when building the new environment.
5777 This has the effect of creating an environment in which search paths
5778 only contain package inputs.
5779
5780 @item --search-paths
5781 Display the environment variable definitions that make up the
5782 environment.
5783
5784 @item --system=@var{system}
5785 @itemx -s @var{system}
5786 Attempt to build for @var{system}---e.g., @code{i686-linux}.
5787
5788 @item --container
5789 @itemx -C
5790 @cindex container
5791 Run @var{command} within an isolated container. The current working
5792 directory outside the container is mapped inside the container.
5793 Additionally, a dummy home directory is created that matches the current
5794 user's home directory, and @file{/etc/passwd} is configured accordingly.
5795 The spawned process runs as the current user outside the container, but
5796 has root privileges in the context of the container.
5797
5798 @item --network
5799 @itemx -N
5800 For containers, share the network namespace with the host system.
5801 Containers created without this flag only have access to the loopback
5802 device.
5803
5804 @item --expose=@var{source}[=@var{target}]
5805 For containers, expose the file system @var{source} from the host system
5806 as the read-only file system @var{target} within the container. If
5807 @var{target} is not specified, @var{source} is used as the target mount
5808 point in the container.
5809
5810 The example below spawns a Guile REPL in a container in which the user's
5811 home directory is accessible read-only via the @file{/exchange}
5812 directory:
5813
5814 @example
5815 guix environment --container --expose=$HOME=/exchange guile -- guile
5816 @end example
5817
5818 @item --share=@var{source}[=@var{target}]
5819 For containers, share the file system @var{source} from the host system
5820 as the writable file system @var{target} within the container. If
5821 @var{target} is not specified, @var{source} is used as the target mount
5822 point in the container.
5823
5824 The example below spawns a Guile REPL in a container in which the user's
5825 home directory is accessible for both reading and writing via the
5826 @file{/exchange} directory:
5827
5828 @example
5829 guix environment --container --share=$HOME=/exchange guile -- guile
5830 @end example
5831 @end table
5832
5833 It also supports all of the common build options that @command{guix
5834 build} supports (@pxref{Common Build Options}).
5835
5836 @node Invoking guix publish
5837 @section Invoking @command{guix publish}
5838
5839 The purpose of @command{guix publish} is to enable users to easily share
5840 their store with others, who can then use it as a substitute server
5841 (@pxref{Substitutes}).
5842
5843 When @command{guix publish} runs, it spawns an HTTP server which allows
5844 anyone with network access to obtain substitutes from it. This means
5845 that any machine running Guix can also act as if it were a build farm,
5846 since the HTTP interface is compatible with Hydra, the software behind
5847 the @code{hydra.gnu.org} build farm.
5848
5849 For security, each substitute is signed, allowing recipients to check
5850 their authenticity and integrity (@pxref{Substitutes}). Because
5851 @command{guix publish} uses the signing key of the system, which is only
5852 readable by the system administrator, it must be started as root; the
5853 @code{--user} option makes it drop root privileges early on.
5854
5855 The signing key pair must be generated before @command{guix publish} is
5856 launched, using @command{guix archive --generate-key} (@pxref{Invoking
5857 guix archive}).
5858
5859 The general syntax is:
5860
5861 @example
5862 guix publish @var{options}@dots{}
5863 @end example
5864
5865 Running @command{guix publish} without any additional arguments will
5866 spawn an HTTP server on port 8080:
5867
5868 @example
5869 guix publish
5870 @end example
5871
5872 Once a publishing server has been authorized (@pxref{Invoking guix
5873 archive}), the daemon may download substitutes from it:
5874
5875 @example
5876 guix-daemon --substitute-urls=http://example.org:8080
5877 @end example
5878
5879 As a bonus, @command{guix publish} also serves as a content-addressed
5880 mirror for source files referenced in @code{origin} records
5881 (@pxref{origin Reference}). For instance, assuming @command{guix
5882 publish} is running on @code{example.org}, the following URL returns the
5883 raw @file{hello-2.10.tar.gz} file with the given SHA256 hash
5884 (represented in @code{nix-base32} format, @pxref{Invoking guix hash}):
5885
5886 @example
5887 http://example.org/file/hello-2.10.tar.gz/sha256/0ssi1@dots{}ndq1i
5888 @end example
5889
5890 Obviously, these URLs only work for files that are in the store; in
5891 other cases, they return 404 (``Not Found'').
5892
5893 The following options are available:
5894
5895 @table @code
5896 @item --port=@var{port}
5897 @itemx -p @var{port}
5898 Listen for HTTP requests on @var{port}.
5899
5900 @item --listen=@var{host}
5901 Listen on the network interface for @var{host}. The default is to
5902 accept connections from any interface.
5903
5904 @item --user=@var{user}
5905 @itemx -u @var{user}
5906 Change privileges to @var{user} as soon as possible---i.e., once the
5907 server socket is open and the signing key has been read.
5908
5909 @item --compression[=@var{level}]
5910 @itemx -C [@var{level}]
5911 Compress data using the given @var{level}. When @var{level} is zero,
5912 disable compression. The range 1 to 9 corresponds to different gzip
5913 compression levels: 1 is the fastest, and 9 is the best (CPU-intensive).
5914 The default is 3.
5915
5916 Compression occurs on the fly and the compressed streams are not
5917 cached. Thus, to reduce load on the machine that runs @command{guix
5918 publish}, it may be a good idea to choose a low compression level, or to
5919 run @command{guix publish} behind a caching proxy.
5920
5921 @item --ttl=@var{ttl}
5922 Produce @code{Cache-Control} HTTP headers that advertise a time-to-live
5923 (TTL) of @var{ttl}. @var{ttl} must denote a duration: @code{5d} means 5
5924 days, @code{1m} means 1 month, and so on.
5925
5926 This allows the user's Guix to keep substitute information in cache for
5927 @var{ttl}. However, note that @code{guix publish} does not itself
5928 guarantee that the store items it provides will indeed remain available
5929 for as long as @var{ttl}.
5930
5931 @item --repl[=@var{port}]
5932 @itemx -r [@var{port}]
5933 Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
5934 Reference Manual}) on @var{port} (37146 by default). This is used
5935 primarily for debugging a running @command{guix publish} server.
5936 @end table
5937
5938 Enabling @command{guix publish} on a GuixSD system is a one-liner: just
5939 add a call to @code{guix-publish-service} in the @code{services} field
5940 of the @code{operating-system} declaration (@pxref{guix-publish-service,
5941 @code{guix-publish-service}}).
5942
5943
5944 @node Invoking guix challenge
5945 @section Invoking @command{guix challenge}
5946
5947 @cindex reproducible builds
5948 @cindex verifiable builds
5949
5950 Do the binaries provided by this server really correspond to the source
5951 code it claims to build? Is a package build process deterministic?
5952 These are the questions the @command{guix challenge} command attempts to
5953 answer.
5954
5955 The former is obviously an important question: Before using a substitute
5956 server (@pxref{Substitutes}), one had better @emph{verify} that it
5957 provides the right binaries, and thus @emph{challenge} it. The latter
5958 is what enables the former: If package builds are deterministic, then
5959 independent builds of the package should yield the exact same result,
5960 bit for bit; if a server provides a binary different from the one
5961 obtained locally, it may be either corrupt or malicious.
5962
5963 We know that the hash that shows up in @file{/gnu/store} file names is
5964 the hash of all the inputs of the process that built the file or
5965 directory---compilers, libraries, build scripts,
5966 etc. (@pxref{Introduction}). Assuming deterministic build processes,
5967 one store file name should map to exactly one build output.
5968 @command{guix challenge} checks whether there is, indeed, a single
5969 mapping by comparing the build outputs of several independent builds of
5970 any given store item.
5971
5972 The command output looks like this:
5973
5974 @smallexample
5975 $ guix challenge --substitute-urls="https://hydra.gnu.org https://guix.example.org"
5976 updating list of substitutes from 'https://hydra.gnu.org'... 100.0%
5977 updating list of substitutes from 'https://guix.example.org'... 100.0%
5978 /gnu/store/@dots{}-openssl-1.0.2d contents differ:
5979 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5980 https://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5981 https://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
5982 /gnu/store/@dots{}-git-2.5.0 contents differ:
5983 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
5984 https://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
5985 https://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
5986 /gnu/store/@dots{}-pius-2.1.1 contents differ:
5987 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5988 https://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5989 https://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
5990 @end smallexample
5991
5992 @noindent
5993 In this example, @command{guix challenge} first scans the store to
5994 determine the set of locally-built derivations---as opposed to store
5995 items that were downloaded from a substitute server---and then queries
5996 all the substitute servers. It then reports those store items for which
5997 the servers obtained a result different from the local build.
5998
5999 @cindex non-determinism, in package builds
6000 As an example, @code{guix.example.org} always gets a different answer.
6001 Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
6002 case of Git. This might indicate that the build process of Git is
6003 non-deterministic, meaning that its output varies as a function of
6004 various things that Guix does not fully control, in spite of building
6005 packages in isolated environments (@pxref{Features}). Most common
6006 sources of non-determinism include the addition of timestamps in build
6007 results, the inclusion of random numbers, and directory listings sorted
6008 by inode number. See @uref{https://reproducible-builds.org/docs/}, for
6009 more information.
6010
6011 To find out what is wrong with this Git binary, we can do something along
6012 these lines (@pxref{Invoking guix archive}):
6013
6014 @example
6015 $ wget -q -O - https://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
6016 | guix archive -x /tmp/git
6017 $ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
6018 @end example
6019
6020 This command shows the difference between the files resulting from the
6021 local build, and the files resulting from the build on
6022 @code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
6023 diffutils, Comparing and Merging Files}). The @command{diff} command
6024 works great for text files. When binary files differ, a better option
6025 is @uref{https://diffoscope.org/, Diffoscope}, a tool that helps
6026 visualize differences for all kinds of files.
6027
6028 Once you have done that work, you can tell whether the differences are due
6029 to a non-deterministic build process or to a malicious server. We try
6030 hard to remove sources of non-determinism in packages to make it easier
6031 to verify substitutes, but of course, this is a process that
6032 involves not just Guix, but a large part of the free software community.
6033 In the meantime, @command{guix challenge} is one tool to help address
6034 the problem.
6035
6036 If you are writing packages for Guix, you are encouraged to check
6037 whether @code{hydra.gnu.org} and other substitute servers obtain the
6038 same build result as you did with:
6039
6040 @example
6041 $ guix challenge @var{package}
6042 @end example
6043
6044 @noindent
6045 where @var{package} is a package specification such as
6046 @code{guile@@2.0} or @code{glibc:debug}.
6047
6048 The general syntax is:
6049
6050 @example
6051 guix challenge @var{options} [@var{packages}@dots{}]
6052 @end example
6053
6054 When a difference is found between the hash of a locally-built item and
6055 that of a server-provided substitute, or among substitutes provided by
6056 different servers, the command displays it as in the example above and
6057 its exit code is 2 (other non-zero exit codes denote other kinds of
6058 errors.)
6059
6060 The one option that matters is:
6061
6062 @table @code
6063
6064 @item --substitute-urls=@var{urls}
6065 Consider @var{urls} the whitespace-separated list of substitute source
6066 URLs to compare to.
6067
6068 @end table
6069
6070
6071 @node Invoking guix container
6072 @section Invoking @command{guix container}
6073 @cindex container
6074
6075 @quotation Note
6076 As of version @value{VERSION}, this tool is experimental. The interface
6077 is subject to radical change in the future.
6078 @end quotation
6079
6080 The purpose of @command{guix container} is to manipulate processes
6081 running within an isolated environment, commonly known as a
6082 ``container'', typically created by the @command{guix environment}
6083 (@pxref{Invoking guix environment}) and @command{guix system container}
6084 (@pxref{Invoking guix system}) commands.
6085
6086 The general syntax is:
6087
6088 @example
6089 guix container @var{action} @var{options}@dots{}
6090 @end example
6091
6092 @var{action} specifies the operation to perform with a container, and
6093 @var{options} specifies the context-specific arguments for the action.
6094
6095 The following actions are available:
6096
6097 @table @code
6098 @item exec
6099 Execute a command within the context of a running container.
6100
6101 The syntax is:
6102
6103 @example
6104 guix container exec @var{pid} @var{program} @var{arguments}@dots{}
6105 @end example
6106
6107 @var{pid} specifies the process ID of the running container.
6108 @var{program} specifies an executable file name within the root file
6109 system of the container. @var{arguments} are the additional options that
6110 will be passed to @var{program}.
6111
6112 The following command launches an interactive login shell inside a
6113 GuixSD container, started by @command{guix system container}, and whose
6114 process ID is 9001:
6115
6116 @example
6117 guix container exec 9001 /run/current-system/profile/bin/bash --login
6118 @end example
6119
6120 Note that the @var{pid} cannot be the parent process of a container. It
6121 must be PID 1 of the container or one of its child processes.
6122
6123 @end table
6124
6125 @c *********************************************************************
6126 @node GNU Distribution
6127 @chapter GNU Distribution
6128
6129 @cindex Guix System Distribution
6130 @cindex GuixSD
6131 Guix comes with a distribution of the GNU system consisting entirely of
6132 free software@footnote{The term ``free'' here refers to the
6133 @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
6134 users of that software}.}. The
6135 distribution can be installed on its own (@pxref{System Installation}),
6136 but it is also possible to install Guix as a package manager on top of
6137 an installed GNU/Linux system (@pxref{Installation}). To distinguish
6138 between the two, we refer to the standalone distribution as the Guix
6139 System Distribution, or GuixSD.
6140
6141 The distribution provides core GNU packages such as GNU libc, GCC, and
6142 Binutils, as well as many GNU and non-GNU applications. The complete
6143 list of available packages can be browsed
6144 @url{http://www.gnu.org/software/guix/packages,on-line} or by
6145 running @command{guix package} (@pxref{Invoking guix package}):
6146
6147 @example
6148 guix package --list-available
6149 @end example
6150
6151 Our goal is to provide a practical 100% free software distribution of
6152 Linux-based and other variants of GNU, with a focus on the promotion and
6153 tight integration of GNU components, and an emphasis on programs and
6154 tools that help users exert that freedom.
6155
6156 Packages are currently available on the following platforms:
6157
6158 @table @code
6159
6160 @item x86_64-linux
6161 Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
6162
6163 @item i686-linux
6164 Intel 32-bit architecture (IA32), Linux-Libre kernel;
6165
6166 @item armhf-linux
6167 ARMv7-A architecture with hard float, Thumb-2 and NEON,
6168 using the EABI hard-float application binary interface (ABI),
6169 and Linux-Libre kernel.
6170
6171 @item mips64el-linux
6172 little-endian 64-bit MIPS processors, specifically the Loongson series,
6173 n32 ABI, and Linux-Libre kernel.
6174
6175 @end table
6176
6177 GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
6178
6179 @noindent
6180 For information on porting to other architectures or kernels,
6181 @pxref{Porting}.
6182
6183 @menu
6184 * System Installation:: Installing the whole operating system.
6185 * System Configuration:: Configuring the operating system.
6186 * Installing Debugging Files:: Feeding the debugger.
6187 * Security Updates:: Deploying security fixes quickly.
6188 * Package Modules:: Packages from the programmer's viewpoint.
6189 * Packaging Guidelines:: Growing the distribution.
6190 * Bootstrapping:: GNU/Linux built from scratch.
6191 * Porting:: Targeting another platform or kernel.
6192 @end menu
6193
6194 Building this distribution is a cooperative effort, and you are invited
6195 to join! @xref{Contributing}, for information about how you can help.
6196
6197 @node System Installation
6198 @section System Installation
6199
6200 @cindex Guix System Distribution
6201 This section explains how to install the Guix System Distribution (GuixSD)
6202 on a machine. The Guix package manager can
6203 also be installed on top of a running GNU/Linux system,
6204 @pxref{Installation}.
6205
6206 @ifinfo
6207 @quotation Note
6208 @c This paragraph is for people reading this from tty2 of the
6209 @c installation image.
6210 You are reading this documentation with an Info reader. For details on
6211 how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
6212 link that follows: @pxref{Top, Info reader,, info-stnd, Stand-alone GNU
6213 Info}. Hit @kbd{l} afterwards to come back here.
6214
6215 Alternately, run @command{info info} in another tty to keep the manual
6216 available.
6217 @end quotation
6218 @end ifinfo
6219
6220 @menu
6221 * Limitations:: What you can expect.
6222 * Hardware Considerations:: Supported hardware.
6223 * USB Stick Installation:: Preparing the installation medium.
6224 * Preparing for Installation:: Networking, partitioning, etc.
6225 * Proceeding with the Installation:: The real thing.
6226 * Installing GuixSD in a VM:: GuixSD playground.
6227 * Building the Installation Image:: How this comes to be.
6228 @end menu
6229
6230 @node Limitations
6231 @subsection Limitations
6232
6233 As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
6234 not production-ready. It may contain bugs and lack important
6235 features. Thus, if you are looking for a stable production system that
6236 respects your freedom as a computer user, a good solution at this point
6237 is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
6238 the more established GNU/Linux distributions}. We hope you can soon switch
6239 to the GuixSD without fear, of course. In the meantime, you can
6240 also keep using your distribution and try out the package manager on top
6241 of it (@pxref{Installation}).
6242
6243 Before you proceed with the installation, be aware of the following
6244 noteworthy limitations applicable to version @value{VERSION}:
6245
6246 @itemize
6247 @item
6248 The installation process does not include a graphical user interface and
6249 requires familiarity with GNU/Linux (see the following subsections to
6250 get a feel of what that means.)
6251
6252 @item
6253 Support for the Logical Volume Manager (LVM) is missing.
6254
6255 @item
6256 Few system services are currently supported out-of-the-box
6257 (@pxref{Services}).
6258
6259 @item
6260 More than 4,000 packages are available, but you may
6261 occasionally find that a useful package is missing.
6262
6263 @item
6264 GNOME, Xfce, and Enlightenment are available (@pxref{Desktop Services}),
6265 as well as a number of X11 window managers. However, some graphical
6266 applications may be missing, as well as KDE.
6267 @end itemize
6268
6269 You have been warned! But more than a disclaimer, this is an invitation
6270 to report issues (and success stories!), and to join us in improving it.
6271 @xref{Contributing}, for more info.
6272
6273
6274 @node Hardware Considerations
6275 @subsection Hardware Considerations
6276
6277 @cindex hardware support on GuixSD
6278 GNU@tie{}GuixSD focuses on respecting the user's computing freedom. It
6279 builds around the kernel Linux-libre, which means that only hardware for
6280 which free software drivers and firmware exist is supported. Nowadays,
6281 a wide range of off-the-shelf hardware is supported on
6282 GNU/Linux-libre---from keyboards to graphics cards to scanners and
6283 Ethernet controllers. Unfortunately, there are still areas where
6284 hardware vendors deny users control over their own computing, and such
6285 hardware is not supported on GuixSD.
6286
6287 @cindex WiFi, hardware support
6288 One of the main areas where free drivers or firmware are lacking is WiFi
6289 devices. WiFi devices known to work include those using Atheros chips
6290 (AR9271 and AR7010), which corresponds to the @code{ath9k} Linux-libre
6291 driver, and for which free firmware exists and is available
6292 out-of-the-box on GuixSD, as part of @var{%base-firmware}
6293 (@pxref{operating-system Reference, @code{firmware}}).
6294
6295 @cindex RYF, Respects Your Freedom
6296 The @uref{https://www.fsf.org/, Free Software Foundation} runs
6297 @uref{https://www.fsf.org/ryf, @dfn{Respects Your Freedom}} (RYF), a
6298 certification program for hardware products that respect your freedom
6299 and your privacy and ensure that you have control over your device. We
6300 encourage you to check the list of RYF-certified devices.
6301
6302 Another useful resource is the @uref{https://www.h-node.org/, H-Node}
6303 web site. It contains a catalog of hardware devices with information
6304 about their support in GNU/Linux.
6305
6306
6307 @node USB Stick Installation
6308 @subsection USB Stick Installation
6309
6310 An installation image for USB sticks can be downloaded from
6311 @indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
6312 where @var{system} is one of:
6313
6314 @table @code
6315 @item x86_64-linux
6316 for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
6317
6318 @item i686-linux
6319 for a 32-bit GNU/Linux system on Intel-compatible CPUs.
6320 @end table
6321
6322 @c start duplication of authentication part from ``Binary Installation''
6323 Make sure to download the associated @file{.sig} file and to verify the
6324 authenticity of the image against it, along these lines:
6325
6326 @example
6327 $ wget ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz.sig
6328 $ gpg --verify guixsd-usb-install-@value{VERSION}.@var{system}.xz.sig
6329 @end example
6330
6331 If that command fails because you do not have the required public key,
6332 then run this command to import it:
6333
6334 @example
6335 $ gpg --keyserver pgp.mit.edu --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
6336 @end example
6337
6338 @noindent
6339 and rerun the @code{gpg --verify} command.
6340 @c end duplication
6341
6342 This image contains a single partition with the tools necessary for an
6343 installation. It is meant to be copied @emph{as is} to a large-enough
6344 USB stick.
6345
6346 To copy the image to a USB stick, follow these steps:
6347
6348 @enumerate
6349 @item
6350 Decompress the image using the @command{xz} command:
6351
6352 @example
6353 xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
6354 @end example
6355
6356 @item
6357 Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
6358 its device name. Assuming that the USB stick is known as @file{/dev/sdX},
6359 copy the image with:
6360
6361 @example
6362 dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
6363 @end example
6364
6365 Access to @file{/dev/sdX} usually requires root privileges.
6366 @end enumerate
6367
6368 Once this is done, you should be able to reboot the system and boot from
6369 the USB stick. The latter usually requires you to get in the BIOS' boot
6370 menu, where you can choose to boot from the USB stick.
6371
6372 @xref{Installing GuixSD in a VM}, if, instead, you would like to install
6373 GuixSD in a virtual machine (VM).
6374
6375 @node Preparing for Installation
6376 @subsection Preparing for Installation
6377
6378 Once you have successfully booted the image on the USB stick, you should
6379 end up with a root prompt. Several console TTYs are configured and can
6380 be used to run commands as root. TTY2 shows this documentation,
6381 browsable using the Info reader commands (@pxref{Top,,, info-stnd,
6382 Stand-alone GNU Info}). The installation system runs the GPM mouse
6383 daemon, which allows you to select text with the left mouse button and
6384 to paste it with the middle button.
6385
6386 @quotation Note
6387 Installation requires access to the Internet so that any missing
6388 dependencies of your system configuration can be downloaded. See the
6389 ``Networking'' section below.
6390 @end quotation
6391
6392 The installation system includes many common tools needed for this task.
6393 But it is also a full-blown GuixSD system, which means that you can
6394 install additional packages, should you need it, using @command{guix
6395 package} (@pxref{Invoking guix package}).
6396
6397 @subsubsection Keyboard Layout
6398
6399 @cindex keyboard layout
6400 The installation image uses the US qwerty keyboard layout. If you want
6401 to change it, you can use the @command{loadkeys} command. For example,
6402 the following command selects the Dvorak keyboard layout:
6403
6404 @example
6405 loadkeys dvorak
6406 @end example
6407
6408 See the files under @file{/run/current-system/profile/share/keymaps} for
6409 a list of available keyboard layouts. Run @command{man loadkeys} for
6410 more information.
6411
6412 @subsubsection Networking
6413
6414 Run the following command see what your network interfaces are called:
6415
6416 @example
6417 ifconfig -a
6418 @end example
6419
6420 @noindent
6421 @dots{} or, using the GNU/Linux-specific @command{ip} command:
6422
6423 @example
6424 ip a
6425 @end example
6426
6427 @c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
6428 Wired interfaces have a name starting with @samp{e}; for example, the
6429 interface corresponding to the first on-board Ethernet controller is
6430 called @samp{eno1}. Wireless interfaces have a name starting with
6431 @samp{w}, like @samp{w1p2s0}.
6432
6433 @table @asis
6434 @item Wired connection
6435 To configure a wired network run the following command, substituting
6436 @var{interface} with the name of the wired interface you want to use.
6437
6438 @example
6439 ifconfig @var{interface} up
6440 @end example
6441
6442 @item Wireless connection
6443 To configure wireless networking, you can create a configuration file
6444 for the @command{wpa_supplicant} configuration tool (its location is not
6445 important) using one of the available text editors such as
6446 @command{zile}:
6447
6448 @example
6449 zile wpa_supplicant.conf
6450 @end example
6451
6452 As an example, the following stanza can go to this file and will work
6453 for many wireless networks, provided you give the actual SSID and
6454 passphrase for the network you are connecting to:
6455
6456 @example
6457 network=@{
6458 ssid="@var{my-ssid}"
6459 key_mgmt=WPA-PSK
6460 psk="the network's secret passphrase"
6461 @}
6462 @end example
6463
6464 Start the wireless service and run it in the background with the
6465 following command (substitute @var{interface} with the name of the
6466 network interface you want to use):
6467
6468 @example
6469 wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
6470 @end example
6471
6472 Run @command{man wpa_supplicant} for more information.
6473 @end table
6474
6475 At this point, you need to acquire an IP address. On a network where IP
6476 addresses are automatically assigned @i{via} DHCP, you can run:
6477
6478 @example
6479 dhclient -v @var{interface}
6480 @end example
6481
6482 Try to ping a server to see if networking is up and running:
6483
6484 @example
6485 ping -c 3 gnu.org
6486 @end example
6487
6488 Setting up network access is almost always a requirement because the
6489 image does not contain all the software and tools that may be needed.
6490
6491 @subsubsection Disk Partitioning
6492
6493 Unless this has already been done, the next step is to partition, and
6494 then format the target partition(s).
6495
6496 The installation image includes several partitioning tools, including
6497 Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
6498 @command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
6499 the partition layout you want:
6500
6501 @example
6502 cfdisk
6503 @end example
6504
6505 Once you are done partitioning the target hard disk drive, you have to
6506 create a file system on the relevant partition(s)@footnote{Currently
6507 GuixSD pretty much assumes an ext4 file system. In particular, code
6508 that reads partition UUIDs and labels only works with ext4. This will
6509 be fixed in the future.}.
6510
6511 Preferably, assign partitions a label so that you can easily and
6512 reliably refer to them in @code{file-system} declarations (@pxref{File
6513 Systems}). This is typically done using the @code{-L} option of
6514 @command{mkfs.ext4} and related commands. So, assuming the target root
6515 partition lives at @file{/dev/sda1}, a file system with the label
6516 @code{my-root} can be created with:
6517
6518 @example
6519 mkfs.ext4 -L my-root /dev/sda1
6520 @end example
6521
6522 @c FIXME: Uncomment this once GRUB fully supports encrypted roots.
6523 @c A typical command sequence may be:
6524 @c
6525 @c @example
6526 @c # fdisk /dev/sdX
6527 @c @dots{} Create partitions etc.@dots{}
6528 @c # cryptsetup luksFormat /dev/sdX1
6529 @c # cryptsetup open --type luks /dev/sdX1 my-partition
6530 @c # mkfs.ext4 -L my-root /dev/mapper/my-partition
6531 @c @end example
6532
6533 In addition to e2fsprogs, the suite of tools to manipulate
6534 ext2/ext3/ext4 file systems, the installation image includes
6535 Cryptsetup/LUKS for disk encryption.
6536
6537 Once that is done, mount the target root partition under @file{/mnt}
6538 with a command like (again, assuming @file{/dev/sda1} is the root
6539 partition):
6540
6541 @example
6542 mount /dev/sda1 /mnt
6543 @end example
6544
6545 Finally, if you plan to use one or more swap partitions (@pxref{Memory
6546 Concepts, swap space,, libc, The GNU C Library Reference Manual}), make
6547 sure to initialize them with @command{mkswap}. Assuming you have one
6548 swap partition on @file{/dev/sda2}, you would run:
6549
6550 @example
6551 mkswap /dev/sda2
6552 @end example
6553
6554 @node Proceeding with the Installation
6555 @subsection Proceeding with the Installation
6556
6557 With the target partitions ready and the target root mounted on
6558 @file{/mnt}, we're ready to go. First, run:
6559
6560 @example
6561 herd start cow-store /mnt
6562 @end example
6563
6564 This makes @file{/gnu/store} copy-on-write, such that packages added to it
6565 during the installation phase are written to the target disk on @file{/mnt}
6566 rather than kept in memory. This is necessary because the first phase of
6567 the @command{guix system init} command (see below) entails downloads or
6568 builds to @file{/gnu/store} which, initially, is an in-memory file system.
6569
6570 Next, you have to edit a file and
6571 provide the declaration of the operating system to be installed. To
6572 that end, the installation system comes with three text editors: GNU nano
6573 (@pxref{Top,,, nano, GNU nano Manual}), GNU Zile (an Emacs clone), and
6574 nvi (a clone of the original BSD @command{vi} editor).
6575 We strongly recommend storing that file on the target root file system, say,
6576 as @file{/mnt/etc/config.scm}. Failing to do that, you will have lost your
6577 configuration file once you have rebooted into the newly-installed system.
6578
6579 @xref{Using the Configuration System}, for an overview of the
6580 configuration file. The example configurations discussed in that
6581 section are available under @file{/etc/configuration} in the
6582 installation image. Thus, to get started with a system configuration
6583 providing a graphical display server (a ``desktop'' system), you can run
6584 something along these lines:
6585
6586 @example
6587 # mkdir /mnt/etc
6588 # cp /etc/configuration/desktop.scm /mnt/etc/config.scm
6589 # zile /mnt/etc/config.scm
6590 @end example
6591
6592 You should pay attention to what your configuration file contains, and
6593 in particular:
6594
6595 @itemize
6596 @item
6597 Make sure the @code{grub-configuration} form refers to the device you
6598 want to install GRUB on.
6599
6600 @item
6601 Be sure that your partition labels match the value of their respective
6602 @code{device} fields in your @code{file-system} configuration, assuming
6603 your @code{file-system} configuration sets the value of @code{title} to
6604 @code{'label}.
6605 @end itemize
6606
6607 Once you are done preparing the configuration file, the new system must
6608 be initialized (remember that the target root file system is mounted
6609 under @file{/mnt}):
6610
6611 @example
6612 guix system init /mnt/etc/config.scm /mnt
6613 @end example
6614
6615 @noindent
6616 This copies all the necessary files and installs GRUB on
6617 @file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6618 more information, @pxref{Invoking guix system}. This command may trigger
6619 downloads or builds of missing packages, which can take some time.
6620
6621 Once that command has completed---and hopefully succeeded!---you can run
6622 @command{reboot} and boot into the new system. The @code{root} password
6623 in the new system is initially empty; other users' passwords need to be
6624 initialized by running the @command{passwd} command as @code{root},
6625 unless your configuration specifies otherwise
6626 (@pxref{user-account-password, user account passwords}).
6627
6628 Join us on @code{#guix} on the Freenode IRC network or on
6629 @file{guix-devel@@gnu.org} to share your experience---good or not so
6630 good.
6631
6632 @node Installing GuixSD in a VM
6633 @subsection Installing GuixSD in a Virtual Machine
6634
6635 @cindex virtual machine, GuixSD installation
6636 If you'd like to install GuixSD in a virtual machine (VM) rather than on
6637 your beloved machine, this section is for you.
6638
6639 To boot a @uref{http://qemu.org/,QEMU} VM for installing GuixSD in a
6640 disk image, follow these steps:
6641
6642 @enumerate
6643 @item
6644 First, retrieve the GuixSD installation image as described previously
6645 (@pxref{USB Stick Installation}).
6646
6647 @item
6648 Create a disk image that will hold the installed system. To make a
6649 qcow2-formatted disk image, use the @command{qemu-img} command:
6650
6651 @example
6652 qemu-img create -f qcow2 guixsd.img 5G
6653 @end example
6654
6655 This will create a 5GB file.
6656
6657 @item
6658 Boot the USB installation image in an VM:
6659
6660 @example
6661 qemu-system-x86_64 -m 1024 -smp 1 \
6662 -net default -net nic,model=virtio -boot menu=on \
6663 -drive file=guixsd.img \
6664 -drive file=guixsd-usb-install-@value{VERSION}.@var{system}
6665 @end example
6666
6667 In the VM console, quickly press the @kbd{F12} key to enter the boot
6668 menu. Then press the @kbd{2} key and the @kbd{RET} key to validate your
6669 selection.
6670
6671 @item
6672 You're now root in the VM, proceed with the installation process.
6673 @xref{Preparing for Installation}, and follow the instructions.
6674 @end enumerate
6675
6676 Once installation is complete, you can boot the system that's on your
6677 @file{guixsd.img} image. @xref{Running GuixSD in a VM}, for how to do
6678 that.
6679
6680 @node Building the Installation Image
6681 @subsection Building the Installation Image
6682
6683 The installation image described above was built using the @command{guix
6684 system} command, specifically:
6685
6686 @c FIXME: 1G is too much; see <http://bugs.gnu.org/23077>.
6687 @example
6688 guix system disk-image --image-size=1G gnu/system/install.scm
6689 @end example
6690
6691 Have a look at @file{gnu/system/install.scm} in the source tree,
6692 and see also @ref{Invoking guix system} for more information
6693 about the installation image.
6694
6695 @node System Configuration
6696 @section System Configuration
6697
6698 @cindex system configuration
6699 The Guix System Distribution supports a consistent whole-system configuration
6700 mechanism. By that we mean that all aspects of the global system
6701 configuration---such as the available system services, timezone and
6702 locale settings, user accounts---are declared in a single place. Such
6703 a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
6704
6705 One of the advantages of putting all the system configuration under the
6706 control of Guix is that it supports transactional system upgrades, and
6707 makes it possible to roll back to a previous system instantiation,
6708 should something go wrong with the new one (@pxref{Features}). Another
6709 advantage is that it makes it easy to replicate the exact same configuration
6710 across different machines, or at different points in time, without
6711 having to resort to additional administration tools layered on top of
6712 the own tools of the system.
6713 @c Yes, we're talking of Puppet, Chef, & co. here. ↑
6714
6715 This section describes this mechanism. First we focus on the system
6716 administrator's viewpoint---explaining how the system is configured and
6717 instantiated. Then we show how this mechanism can be extended, for
6718 instance to support new system services.
6719
6720 @menu
6721 * Using the Configuration System:: Customizing your GNU system.
6722 * operating-system Reference:: Detail of operating-system declarations.
6723 * File Systems:: Configuring file system mounts.
6724 * Mapped Devices:: Block device extra processing.
6725 * User Accounts:: Specifying user accounts.
6726 * Locales:: Language and cultural convention settings.
6727 * Services:: Specifying system services.
6728 * Setuid Programs:: Programs running with root privileges.
6729 * X.509 Certificates:: Authenticating HTTPS servers.
6730 * Name Service Switch:: Configuring libc's name service switch.
6731 * Initial RAM Disk:: Linux-Libre bootstrapping.
6732 * GRUB Configuration:: Configuring the boot loader.
6733 * Invoking guix system:: Instantiating a system configuration.
6734 * Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
6735 * Defining Services:: Adding new service definitions.
6736 @end menu
6737
6738 @node Using the Configuration System
6739 @subsection Using the Configuration System
6740
6741 The operating system is configured by providing an
6742 @code{operating-system} declaration in a file that can then be passed to
6743 the @command{guix system} command (@pxref{Invoking guix system}). A
6744 simple setup, with the default system services, the default Linux-Libre
6745 kernel, initial RAM disk, and boot loader looks like this:
6746
6747 @findex operating-system
6748 @lisp
6749 @include os-config-bare-bones.texi
6750 @end lisp
6751
6752 This example should be self-describing. Some of the fields defined
6753 above, such as @code{host-name} and @code{bootloader}, are mandatory.
6754 Others, such as @code{packages} and @code{services}, can be omitted, in
6755 which case they get a default value.
6756
6757 Below we discuss the effect of some of the most important fields
6758 (@pxref{operating-system Reference}, for details about all the available
6759 fields), and how to @dfn{instantiate} the operating system using
6760 @command{guix system}.
6761
6762 @unnumberedsubsubsec Globally-Visible Packages
6763
6764 @vindex %base-packages
6765 The @code{packages} field lists packages that will be globally visible
6766 on the system, for all user accounts---i.e., in every user's @code{PATH}
6767 environment variable---in addition to the per-user profiles
6768 (@pxref{Invoking guix package}). The @var{%base-packages} variable
6769 provides all the tools one would expect for basic user and administrator
6770 tasks---including the GNU Core Utilities, the GNU Networking Utilities,
6771 the GNU Zile lightweight text editor, @command{find}, @command{grep},
6772 etc. The example above adds tcpdump to those, taken from the @code{(gnu
6773 packages admin)} module (@pxref{Package Modules}).
6774
6775 @findex specification->package
6776 Referring to packages by variable name, like @var{tcpdump} above, has
6777 the advantage of being unambiguous; it also allows typos and such to be
6778 diagnosed right away as ``unbound variables''. The downside is that one
6779 needs to know which module defines which package, and to augment the
6780 @code{use-package-modules} line accordingly. To avoid that, one can use
6781 the @code{specification->package} procedure of the @code{(gnu packages)}
6782 module, which returns the best package for a given name or name and
6783 version:
6784
6785 @lisp
6786 (use-modules (gnu packages))
6787
6788 (operating-system
6789 ;; ...
6790 (packages (append (map specification->package
6791 '("tcpdump" "htop" "gnupg@@2.0"))
6792 %base-packages)))
6793 @end lisp
6794
6795 @unnumberedsubsubsec System Services
6796
6797 @vindex %base-services
6798 The @code{services} field lists @dfn{system services} to be made
6799 available when the system starts (@pxref{Services}).
6800 The @code{operating-system} declaration above specifies that, in
6801 addition to the basic services, we want the @command{lshd} secure shell
6802 daemon listening on port 2222 (@pxref{Networking Services,
6803 @code{lsh-service}}). Under the hood,
6804 @code{lsh-service} arranges so that @code{lshd} is started with the
6805 right command-line options, possibly with supporting configuration files
6806 generated as needed (@pxref{Defining Services}).
6807
6808 @cindex customization, of services
6809 @findex modify-services
6810 Occasionally, instead of using the base services as is, you will want to
6811 customize them. To do this, use @code{modify-services} (@pxref{Service
6812 Reference, @code{modify-services}}) to modify the list.
6813
6814 For example, suppose you want to modify @code{guix-daemon} and Mingetty
6815 (the console log-in) in the @var{%base-services} list (@pxref{Base
6816 Services, @code{%base-services}}). To do that, you can write the
6817 following in your operating system declaration:
6818
6819 @lisp
6820 (define %my-services
6821 ;; My very own list of services.
6822 (modify-services %base-services
6823 (guix-service-type config =>
6824 (guix-configuration
6825 (inherit config)
6826 (use-substitutes? #f)
6827 (extra-options '("--gc-keep-derivations"))))
6828 (mingetty-service-type config =>
6829 (mingetty-configuration
6830 (inherit config)))))
6831
6832 (operating-system
6833 ;; @dots{}
6834 (services %my-services))
6835 @end lisp
6836
6837 This changes the configuration---i.e., the service parameters---of the
6838 @code{guix-service-type} instance, and that of all the
6839 @code{mingetty-service-type} instances in the @var{%base-services} list.
6840 Observe how this is accomplished: first, we arrange for the original
6841 configuration to be bound to the identifier @code{config} in the
6842 @var{body}, and then we write the @var{body} so that it evaluates to the
6843 desired configuration. In particular, notice how we use @code{inherit}
6844 to create a new configuration which has the same values as the old
6845 configuration, but with a few modifications.
6846
6847 The configuration for a typical ``desktop'' usage, with the X11 display
6848 server, GNOME and Xfce (users can choose which of these desktop
6849 environments to use at the log-in screen by pressing @kbd{F1}), network
6850 management, power management, and more, would look like this:
6851
6852 @lisp
6853 @include os-config-desktop.texi
6854 @end lisp
6855
6856 A graphical environment with a choice of lightweight window managers
6857 instead of full-blown desktop environments would look like this:
6858
6859 @lisp
6860 @include os-config-lightweight-desktop.texi
6861 @end lisp
6862
6863 @xref{Desktop Services}, for the exact list of services provided by
6864 @var{%desktop-services}. @xref{X.509 Certificates}, for background
6865 information about the @code{nss-certs} package that is used here.
6866
6867 Again, @var{%desktop-services} is just a list of service objects. If
6868 you want to remove services from there, you can do so using the
6869 procedures for list filtering (@pxref{SRFI-1 Filtering and
6870 Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
6871 following expression returns a list that contains all the services in
6872 @var{%desktop-services} minus the Avahi service:
6873
6874 @example
6875 (remove (lambda (service)
6876 (eq? (service-kind service) avahi-service-type))
6877 %desktop-services)
6878 @end example
6879
6880 @unnumberedsubsubsec Instantiating the System
6881
6882 Assuming the @code{operating-system} declaration
6883 is stored in the @file{my-system-config.scm}
6884 file, the @command{guix system reconfigure my-system-config.scm} command
6885 instantiates that configuration, and makes it the default GRUB boot
6886 entry (@pxref{Invoking guix system}).
6887
6888 The normal way to change the system configuration is by updating this
6889 file and re-running @command{guix system reconfigure}. One should never
6890 have to touch files in @command{/etc} or to run commands that modify the
6891 system state such as @command{useradd} or @command{grub-install}. In
6892 fact, you must avoid that since that would not only void your warranty
6893 but also prevent you from rolling back to previous versions of your
6894 system, should you ever need to.
6895
6896 @cindex roll-back, of the operating system
6897 Speaking of roll-back, each time you run @command{guix system
6898 reconfigure}, a new @dfn{generation} of the system is created---without
6899 modifying or deleting previous generations. Old system generations get
6900 an entry in the GRUB boot menu, allowing you to boot them in case
6901 something went wrong with the latest generation. Reassuring, no? The
6902 @command{guix system list-generations} command lists the system
6903 generations available on disk.
6904
6905 @unnumberedsubsubsec The Programming Interface
6906
6907 At the Scheme level, the bulk of an @code{operating-system} declaration
6908 is instantiated with the following monadic procedure (@pxref{The Store
6909 Monad}):
6910
6911 @deffn {Monadic Procedure} operating-system-derivation os
6912 Return a derivation that builds @var{os}, an @code{operating-system}
6913 object (@pxref{Derivations}).
6914
6915 The output of the derivation is a single directory that refers to all
6916 the packages, configuration files, and other supporting files needed to
6917 instantiate @var{os}.
6918 @end deffn
6919
6920 This procedure is provided by the @code{(gnu system)} module. Along
6921 with @code{(gnu services)} (@pxref{Services}), this module contains the
6922 guts of GuixSD. Make sure to visit it!
6923
6924
6925 @node operating-system Reference
6926 @subsection @code{operating-system} Reference
6927
6928 This section summarizes all the options available in
6929 @code{operating-system} declarations (@pxref{Using the Configuration
6930 System}).
6931
6932 @deftp {Data Type} operating-system
6933 This is the data type representing an operating system configuration.
6934 By that, we mean all the global system configuration, not per-user
6935 configuration (@pxref{Using the Configuration System}).
6936
6937 @table @asis
6938 @item @code{kernel} (default: @var{linux-libre})
6939 The package object of the operating system kernel to use@footnote{Currently
6940 only the Linux-libre kernel is supported. In the future, it will be
6941 possible to use the GNU@tie{}Hurd.}.
6942
6943 @item @code{kernel-arguments} (default: @code{'()})
6944 List of strings or gexps representing additional arguments to pass on
6945 the command-line of the kernel---e.g., @code{("console=ttyS0")}.
6946
6947 @item @code{bootloader}
6948 The system bootloader configuration object. @xref{GRUB Configuration}.
6949
6950 @item @code{initrd} (default: @code{base-initrd})
6951 A two-argument monadic procedure that returns an initial RAM disk for
6952 the Linux kernel. @xref{Initial RAM Disk}.
6953
6954 @item @code{firmware} (default: @var{%base-firmware})
6955 @cindex firmware
6956 List of firmware packages loadable by the operating system kernel.
6957
6958 The default includes firmware needed for Atheros-based WiFi devices
6959 (Linux-libre module @code{ath9k}). @xref{Hardware Considerations}, for
6960 more info on supported hardware.
6961
6962 @item @code{host-name}
6963 The host name.
6964
6965 @item @code{hosts-file}
6966 @cindex hosts file
6967 A file-like object (@pxref{G-Expressions, file-like objects}) for use as
6968 @file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
6969 Reference Manual}). The default is a file with entries for
6970 @code{localhost} and @var{host-name}.
6971
6972 @item @code{mapped-devices} (default: @code{'()})
6973 A list of mapped devices. @xref{Mapped Devices}.
6974
6975 @item @code{file-systems}
6976 A list of file systems. @xref{File Systems}.
6977
6978 @item @code{swap-devices} (default: @code{'()})
6979 @cindex swap devices
6980 A list of strings identifying devices to be used for ``swap space''
6981 (@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
6982 For example, @code{'("/dev/sda3")}.
6983
6984 @item @code{users} (default: @code{%base-user-accounts})
6985 @itemx @code{groups} (default: @var{%base-groups})
6986 List of user accounts and groups. @xref{User Accounts}.
6987
6988 @item @code{skeletons} (default: @code{(default-skeletons)})
6989 A list target file name/file-like object tuples (@pxref{G-Expressions,
6990 file-like objects}). These are the skeleton files that will be added to
6991 the home directory of newly-created user accounts.
6992
6993 For instance, a valid value may look like this:
6994
6995 @example
6996 `((".bashrc" ,(plain-file "bashrc" "echo Hello\n"))
6997 (".guile" ,(plain-file "guile"
6998 "(use-modules (ice-9 readline))
6999 (activate-readline)")))
7000 @end example
7001
7002 @item @code{issue} (default: @var{%default-issue})
7003 A string denoting the contents of the @file{/etc/issue} file, which is
7004 displayed when users log in on a text console.
7005
7006 @item @code{packages} (default: @var{%base-packages})
7007 The set of packages installed in the global profile, which is accessible
7008 at @file{/run/current-system/profile}.
7009
7010 The default set includes core utilities and it is good practice to
7011 install non-core utilities in user profiles (@pxref{Invoking guix
7012 package}).
7013
7014 @item @code{timezone}
7015 A timezone identifying string---e.g., @code{"Europe/Paris"}.
7016
7017 You can run the @command{tzselect} command to find out which timezone
7018 string corresponds to your region. Choosing an invalid timezone name
7019 causes @command{guix system} to fail.
7020
7021 @item @code{locale} (default: @code{"en_US.utf8"})
7022 The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
7023 Library Reference Manual}). @xref{Locales}, for more information.
7024
7025 @item @code{locale-definitions} (default: @var{%default-locale-definitions})
7026 The list of locale definitions to be compiled and that may be used at
7027 run time. @xref{Locales}.
7028
7029 @item @code{locale-libcs} (default: @code{(list @var{glibc})})
7030 The list of GNU@tie{}libc packages whose locale data and tools are used
7031 to build the locale definitions. @xref{Locales}, for compatibility
7032 considerations that justify this option.
7033
7034 @item @code{name-service-switch} (default: @var{%default-nss})
7035 Configuration of the libc name service switch (NSS)---a
7036 @code{<name-service-switch>} object. @xref{Name Service Switch}, for
7037 details.
7038
7039 @item @code{services} (default: @var{%base-services})
7040 A list of service objects denoting system services. @xref{Services}.
7041
7042 @item @code{pam-services} (default: @code{(base-pam-services)})
7043 @cindex PAM
7044 @cindex pluggable authentication modules
7045 Linux @dfn{pluggable authentication module} (PAM) services.
7046 @c FIXME: Add xref to PAM services section.
7047
7048 @item @code{setuid-programs} (default: @var{%setuid-programs})
7049 List of string-valued G-expressions denoting setuid programs.
7050 @xref{Setuid Programs}.
7051
7052 @item @code{sudoers-file} (default: @var{%sudoers-specification})
7053 @cindex sudoers file
7054 The contents of the @file{/etc/sudoers} file as a file-like object
7055 (@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7056
7057 This file specifies which users can use the @command{sudo} command, what
7058 they are allowed to do, and what privileges they may gain. The default
7059 is that only @code{root} and members of the @code{wheel} group may use
7060 @code{sudo}.
7061
7062 @end table
7063 @end deftp
7064
7065 @node File Systems
7066 @subsection File Systems
7067
7068 The list of file systems to be mounted is specified in the
7069 @code{file-systems} field of the operating system declaration
7070 (@pxref{Using the Configuration System}). Each file system is declared
7071 using the @code{file-system} form, like this:
7072
7073 @example
7074 (file-system
7075 (mount-point "/home")
7076 (device "/dev/sda3")
7077 (type "ext4"))
7078 @end example
7079
7080 As usual, some of the fields are mandatory---those shown in the example
7081 above---while others can be omitted. These are described below.
7082
7083 @deftp {Data Type} file-system
7084 Objects of this type represent file systems to be mounted. They
7085 contain the following members:
7086
7087 @table @asis
7088 @item @code{type}
7089 This is a string specifying the type of the file system---e.g.,
7090 @code{"ext4"}.
7091
7092 @item @code{mount-point}
7093 This designates the place where the file system is to be mounted.
7094
7095 @item @code{device}
7096 This names the ``source'' of the file system. By default it is the name
7097 of a node under @file{/dev}, but its meaning depends on the @code{title}
7098 field described below.
7099
7100 @item @code{title} (default: @code{'device})
7101 This is a symbol that specifies how the @code{device} field is to be
7102 interpreted.
7103
7104 When it is the symbol @code{device}, then the @code{device} field is
7105 interpreted as a file name; when it is @code{label}, then @code{device}
7106 is interpreted as a partition label name; when it is @code{uuid},
7107 @code{device} is interpreted as a partition unique identifier (UUID).
7108
7109 UUIDs may be converted from their string representation (as shown by the
7110 @command{tune2fs -l} command) using the @code{uuid} form@footnote{The
7111 @code{uuid} form expects 16-byte UUIDs as defined in
7112 @uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
7113 form of UUID used by the ext2 family of file systems and others, but it
7114 is different from ``UUIDs'' found in FAT file systems, for instance.},
7115 like this:
7116
7117 @example
7118 (file-system
7119 (mount-point "/home")
7120 (type "ext4")
7121 (title 'uuid)
7122 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
7123 @end example
7124
7125 The @code{label} and @code{uuid} options offer a way to refer to disk
7126 partitions without having to hard-code their actual device
7127 name@footnote{Note that, while it is tempting to use
7128 @file{/dev/disk/by-uuid} and similar device names to achieve the same
7129 result, this is not recommended: These special device nodes are created
7130 by the udev daemon and may be unavailable at the time the device is
7131 mounted.}.
7132
7133 However, when the source of a file system is a mapped device (@pxref{Mapped
7134 Devices}), its @code{device} field @emph{must} refer to the mapped
7135 device name---e.g., @file{/dev/mapper/root-partition}---and consequently
7136 @code{title} must be set to @code{'device}. This is required so that
7137 the system knows that mounting the file system depends on having the
7138 corresponding device mapping established.
7139
7140 @item @code{flags} (default: @code{'()})
7141 This is a list of symbols denoting mount flags. Recognized flags
7142 include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
7143 access to special files), @code{no-suid} (ignore setuid and setgid
7144 bits), and @code{no-exec} (disallow program execution.)
7145
7146 @item @code{options} (default: @code{#f})
7147 This is either @code{#f}, or a string denoting mount options.
7148
7149 @item @code{mount?} (default: @code{#t})
7150 This value indicates whether to automatically mount the file system when
7151 the system is brought up. When set to @code{#f}, the file system gets
7152 an entry in @file{/etc/fstab} (read by the @command{mount} command) but
7153 is not automatically mounted.
7154
7155 @item @code{needed-for-boot?} (default: @code{#f})
7156 This Boolean value indicates whether the file system is needed when
7157 booting. If that is true, then the file system is mounted when the
7158 initial RAM disk (initrd) is loaded. This is always the case, for
7159 instance, for the root file system.
7160
7161 @item @code{check?} (default: @code{#t})
7162 This Boolean indicates whether the file system needs to be checked for
7163 errors before being mounted.
7164
7165 @item @code{create-mount-point?} (default: @code{#f})
7166 When true, the mount point is created if it does not exist yet.
7167
7168 @item @code{dependencies} (default: @code{'()})
7169 This is a list of @code{<file-system>} objects representing file systems
7170 that must be mounted before (and unmounted after) this one.
7171
7172 As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
7173 a dependency of @file{/sys/fs/cgroup/cpu} and
7174 @file{/sys/fs/cgroup/memory}.
7175
7176 @end table
7177 @end deftp
7178
7179 The @code{(gnu system file-systems)} exports the following useful
7180 variables.
7181
7182 @defvr {Scheme Variable} %base-file-systems
7183 These are essential file systems that are required on normal systems,
7184 such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
7185 below.) Operating system declarations should always contain at least
7186 these.
7187 @end defvr
7188
7189 @defvr {Scheme Variable} %pseudo-terminal-file-system
7190 This is the file system to be mounted as @file{/dev/pts}. It supports
7191 @dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
7192 functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
7193 Manual}). Pseudo-terminals are used by terminal emulators such as
7194 @command{xterm}.
7195 @end defvr
7196
7197 @defvr {Scheme Variable} %shared-memory-file-system
7198 This file system is mounted as @file{/dev/shm} and is used to support
7199 memory sharing across processes (@pxref{Memory-mapped I/O,
7200 @code{shm_open},, libc, The GNU C Library Reference Manual}).
7201 @end defvr
7202
7203 @defvr {Scheme Variable} %immutable-store
7204 This file system performs a read-only ``bind mount'' of
7205 @file{/gnu/store}, making it read-only for all the users including
7206 @code{root}. This prevents against accidental modification by software
7207 running as @code{root} or by system administrators.
7208
7209 The daemon itself is still able to write to the store: it remounts it
7210 read-write in its own ``name space.''
7211 @end defvr
7212
7213 @defvr {Scheme Variable} %binary-format-file-system
7214 The @code{binfmt_misc} file system, which allows handling of arbitrary
7215 executable file types to be delegated to user space. This requires the
7216 @code{binfmt.ko} kernel module to be loaded.
7217 @end defvr
7218
7219 @defvr {Scheme Variable} %fuse-control-file-system
7220 The @code{fusectl} file system, which allows unprivileged users to mount
7221 and unmount user-space FUSE file systems. This requires the
7222 @code{fuse.ko} kernel module to be loaded.
7223 @end defvr
7224
7225 @node Mapped Devices
7226 @subsection Mapped Devices
7227
7228 @cindex device mapping
7229 @cindex mapped devices
7230 The Linux kernel has a notion of @dfn{device mapping}: a block device,
7231 such as a hard disk partition, can be @dfn{mapped} into another device,
7232 usually in @code{/dev/mapper/},
7233 with additional processing over the data that flows through
7234 it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
7235 concept of a ``mapped device'' and that of a file system: both boil down
7236 to @emph{translating} input/output operations made on a file to
7237 operations on its backing store. Thus, the Hurd implements mapped
7238 devices, like file systems, using the generic @dfn{translator} mechanism
7239 (@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
7240 typical example is encryption device mapping: all writes to the mapped
7241 device are encrypted, and all reads are deciphered, transparently.
7242 Guix extends this notion by considering any device or set of devices that
7243 are @dfn{transformed} in some way to create a new device; for instance,
7244 RAID devices are obtained by @dfn{assembling} several other devices, such
7245 as hard disks or partitions, into a new one that behaves as one partition.
7246 Other examples, not yet implemented, are LVM logical volumes.
7247
7248 Mapped devices are declared using the @code{mapped-device} form,
7249 defined as follows; for examples, see below.
7250
7251 @deftp {Data Type} mapped-device
7252 Objects of this type represent device mappings that will be made when
7253 the system boots up.
7254
7255 @table @code
7256 @item source
7257 This is either a string specifying the name of the block device to be mapped,
7258 such as @code{"/dev/sda3"}, or a list of such strings when several devices
7259 need to be assembled for creating a new one.
7260
7261 @item target
7262 This string specifies the name of the resulting mapped device. For
7263 kernel mappers such as encrypted devices of type @code{luks-device-mapping},
7264 specifying @code{"my-partition"} leads to the creation of
7265 the @code{"/dev/mapper/my-partition"} device.
7266 For RAID devices of type @code{raid-device-mapping}, the full device name
7267 such as @code{"/dev/md0"} needs to be given.
7268
7269 @item type
7270 This must be a @code{mapped-device-kind} object, which specifies how
7271 @var{source} is mapped to @var{target}.
7272 @end table
7273 @end deftp
7274
7275 @defvr {Scheme Variable} luks-device-mapping
7276 This defines LUKS block device encryption using the @command{cryptsetup}
7277 command from the package with the same name. It relies on the
7278 @code{dm-crypt} Linux kernel module.
7279 @end defvr
7280
7281 @defvr {Scheme Variable} raid-device-mapping
7282 This defines a RAID device, which is assembled using the @code{mdadm}
7283 command from the package with the same name. It requires a Linux kernel
7284 module for the appropriate RAID level to be loaded, such as @code{raid456}
7285 for RAID-4, RAID-5 or RAID-6, or @code{raid10} for RAID-10.
7286 @end defvr
7287
7288 @cindex disk encryption
7289 @cindex LUKS
7290 The following example specifies a mapping from @file{/dev/sda3} to
7291 @file{/dev/mapper/home} using LUKS---the
7292 @url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
7293 standard mechanism for disk encryption.
7294 The @file{/dev/mapper/home}
7295 device can then be used as the @code{device} of a @code{file-system}
7296 declaration (@pxref{File Systems}).
7297
7298 @example
7299 (mapped-device
7300 (source "/dev/sda3")
7301 (target "home")
7302 (type luks-device-mapping))
7303 @end example
7304
7305 Alternatively, to become independent of device numbering, one may obtain
7306 the LUKS UUID (@dfn{unique identifier}) of the source device by a
7307 command like:
7308
7309 @example
7310 cryptsetup luksUUID /dev/sda3
7311 @end example
7312
7313 and use it as follows:
7314
7315 @example
7316 (mapped-device
7317 (source (uuid "cb67fc72-0d54-4c88-9d4b-b225f30b0f44"))
7318 (target "home")
7319 (type luks-device-mapping))
7320 @end example
7321
7322 A RAID device formed of the partitions @file{/dev/sda1} and @file{/dev/sdb1}
7323 may be declared as follows:
7324
7325 @example
7326 (mapped-device
7327 (source (list "/dev/sda1" "/dev/sdb1"))
7328 (target "/dev/md0")
7329 (type raid-device-mapping))
7330 @end example
7331
7332 The @file{/dev/md0} device can then be used as the @code{device} of a
7333 @code{file-system} declaration (@pxref{File Systems}).
7334 Note that the RAID level need not be given; it is chosen during the
7335 initial creation and formatting of the RAID device and is determined
7336 automatically later.
7337
7338
7339 @node User Accounts
7340 @subsection User Accounts
7341
7342 User accounts and groups are entirely managed through the
7343 @code{operating-system} declaration. They are specified with the
7344 @code{user-account} and @code{user-group} forms:
7345
7346 @example
7347 (user-account
7348 (name "alice")
7349 (group "users")
7350 (supplementary-groups '("wheel" ;allow use of sudo, etc.
7351 "audio" ;sound card
7352 "video" ;video devices such as webcams
7353 "cdrom")) ;the good ol' CD-ROM
7354 (comment "Bob's sister")
7355 (home-directory "/home/alice"))
7356 @end example
7357
7358 When booting or upon completion of @command{guix system reconfigure},
7359 the system ensures that only the user accounts and groups specified in
7360 the @code{operating-system} declaration exist, and with the specified
7361 properties. Thus, account or group creations or modifications made by
7362 directly invoking commands such as @command{useradd} are lost upon
7363 reconfiguration or reboot. This ensures that the system remains exactly
7364 as declared.
7365
7366 @deftp {Data Type} user-account
7367 Objects of this type represent user accounts. The following members may
7368 be specified:
7369
7370 @table @asis
7371 @item @code{name}
7372 The name of the user account.
7373
7374 @item @code{group}
7375 This is the name (a string) or identifier (a number) of the user group
7376 this account belongs to.
7377
7378 @item @code{supplementary-groups} (default: @code{'()})
7379 Optionally, this can be defined as a list of group names that this
7380 account belongs to.
7381
7382 @item @code{uid} (default: @code{#f})
7383 This is the user ID for this account (a number), or @code{#f}. In the
7384 latter case, a number is automatically chosen by the system when the
7385 account is created.
7386
7387 @item @code{comment} (default: @code{""})
7388 A comment about the account, such as the account owner's full name.
7389
7390 @item @code{home-directory}
7391 This is the name of the home directory for the account.
7392
7393 @item @code{create-home-directory?} (default: @code{#t})
7394 Indicates whether the home directory of this account should be created
7395 if it does not exist yet.
7396
7397 @item @code{shell} (default: Bash)
7398 This is a G-expression denoting the file name of a program to be used as
7399 the shell (@pxref{G-Expressions}).
7400
7401 @item @code{system?} (default: @code{#f})
7402 This Boolean value indicates whether the account is a ``system''
7403 account. System accounts are sometimes treated specially; for instance,
7404 graphical login managers do not list them.
7405
7406 @anchor{user-account-password}
7407 @item @code{password} (default: @code{#f})
7408 You would normally leave this field to @code{#f}, initialize user
7409 passwords as @code{root} with the @command{passwd} command, and then let
7410 users change it with @command{passwd}. Passwords set with
7411 @command{passwd} are of course preserved across reboot and
7412 reconfiguration.
7413
7414 If you @emph{do} want to have a preset password for an account, then
7415 this field must contain the encrypted password, as a string.
7416 @xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
7417 on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
7418 Manual}, for information on Guile's @code{crypt} procedure.
7419
7420 @end table
7421 @end deftp
7422
7423 User group declarations are even simpler:
7424
7425 @example
7426 (user-group (name "students"))
7427 @end example
7428
7429 @deftp {Data Type} user-group
7430 This type is for, well, user groups. There are just a few fields:
7431
7432 @table @asis
7433 @item @code{name}
7434 The name of the group.
7435
7436 @item @code{id} (default: @code{#f})
7437 The group identifier (a number). If @code{#f}, a new number is
7438 automatically allocated when the group is created.
7439
7440 @item @code{system?} (default: @code{#f})
7441 This Boolean value indicates whether the group is a ``system'' group.
7442 System groups have low numerical IDs.
7443
7444 @item @code{password} (default: @code{#f})
7445 What, user groups can have a password? Well, apparently yes. Unless
7446 @code{#f}, this field specifies the password of the group.
7447
7448 @end table
7449 @end deftp
7450
7451 For convenience, a variable lists all the basic user groups one may
7452 expect:
7453
7454 @defvr {Scheme Variable} %base-groups
7455 This is the list of basic user groups that users and/or packages expect
7456 to be present on the system. This includes groups such as ``root'',
7457 ``wheel'', and ``users'', as well as groups used to control access to
7458 specific devices such as ``audio'', ``disk'', and ``cdrom''.
7459 @end defvr
7460
7461 @defvr {Scheme Variable} %base-user-accounts
7462 This is the list of basic system accounts that programs may expect to
7463 find on a GNU/Linux system, such as the ``nobody'' account.
7464
7465 Note that the ``root'' account is not included here. It is a
7466 special-case and is automatically added whether or not it is specified.
7467 @end defvr
7468
7469 @node Locales
7470 @subsection Locales
7471
7472 @cindex locale
7473 A @dfn{locale} defines cultural conventions for a particular language
7474 and region of the world (@pxref{Locales,,, libc, The GNU C Library
7475 Reference Manual}). Each locale has a name that typically has the form
7476 @code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
7477 @code{fr_LU.utf8} designates the locale for the French language, with
7478 cultural conventions from Luxembourg, and using the UTF-8 encoding.
7479
7480 @cindex locale definition
7481 Usually, you will want to specify the default locale for the machine
7482 using the @code{locale} field of the @code{operating-system} declaration
7483 (@pxref{operating-system Reference, @code{locale}}).
7484
7485 The selected locale is automatically added to the @dfn{locale
7486 definitions} known to the system if needed, with its codeset inferred
7487 from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
7488 @code{UTF-8} codeset. Additional locale definitions can be specified in
7489 the @code{locale-definitions} slot of @code{operating-system}---this is
7490 useful, for instance, if the codeset could not be inferred from the
7491 locale name. The default set of locale definitions includes some widely
7492 used locales, but not all the available locales, in order to save space.
7493
7494 For instance, to add the North Frisian locale for Germany, the value of
7495 that field may be:
7496
7497 @example
7498 (cons (locale-definition
7499 (name "fy_DE.utf8") (source "fy_DE"))
7500 %default-locale-definitions)
7501 @end example
7502
7503 Likewise, to save space, one might want @code{locale-definitions} to
7504 list only the locales that are actually used, as in:
7505
7506 @example
7507 (list (locale-definition
7508 (name "ja_JP.eucjp") (source "ja_JP")
7509 (charset "EUC-JP")))
7510 @end example
7511
7512 @vindex LOCPATH
7513 The compiled locale definitions are available at
7514 @file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
7515 version, which is the default location where the GNU@tie{}libc provided
7516 by Guix looks for locale data. This can be overridden using the
7517 @code{LOCPATH} environment variable (@pxref{locales-and-locpath,
7518 @code{LOCPATH} and locale packages}).
7519
7520 The @code{locale-definition} form is provided by the @code{(gnu system
7521 locale)} module. Details are given below.
7522
7523 @deftp {Data Type} locale-definition
7524 This is the data type of a locale definition.
7525
7526 @table @asis
7527
7528 @item @code{name}
7529 The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
7530 Reference Manual}, for more information on locale names.
7531
7532 @item @code{source}
7533 The name of the source for that locale. This is typically the
7534 @code{@var{language}_@var{territory}} part of the locale name.
7535
7536 @item @code{charset} (default: @code{"UTF-8"})
7537 The ``character set'' or ``code set'' for that locale,
7538 @uref{http://www.iana.org/assignments/character-sets, as defined by
7539 IANA}.
7540
7541 @end table
7542 @end deftp
7543
7544 @defvr {Scheme Variable} %default-locale-definitions
7545 A list of commonly used UTF-8 locales, used as the default
7546 value of the @code{locale-definitions} field of @code{operating-system}
7547 declarations.
7548
7549 @cindex locale name
7550 @cindex normalized codeset in locale names
7551 These locale definitions use the @dfn{normalized codeset} for the part
7552 that follows the dot in the name (@pxref{Using gettextized software,
7553 normalized codeset,, libc, The GNU C Library Reference Manual}). So for
7554 instance it has @code{uk_UA.utf8} but @emph{not}, say,
7555 @code{uk_UA.UTF-8}.
7556 @end defvr
7557
7558 @subsubsection Locale Data Compatibility Considerations
7559
7560 @cindex incompatibility, of locale data
7561 @code{operating-system} declarations provide a @code{locale-libcs} field
7562 to specify the GNU@tie{}libc packages that are used to compile locale
7563 declarations (@pxref{operating-system Reference}). ``Why would I
7564 care?'', you may ask. Well, it turns out that the binary format of
7565 locale data is occasionally incompatible from one libc version to
7566 another.
7567
7568 @c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
7569 @c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
7570 For instance, a program linked against libc version 2.21 is unable to
7571 read locale data produced with libc 2.22; worse, that program
7572 @emph{aborts} instead of simply ignoring the incompatible locale
7573 data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
7574 the incompatible locale data, which is already an improvement.}.
7575 Similarly, a program linked against libc 2.22 can read most, but not
7576 all, of the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
7577 data is incompatible); thus calls to @code{setlocale} may fail, but
7578 programs will not abort.
7579
7580 The ``problem'' in GuixSD is that users have a lot of freedom: They can
7581 choose whether and when to upgrade software in their profiles, and might
7582 be using a libc version different from the one the system administrator
7583 used to build the system-wide locale data.
7584
7585 Fortunately, unprivileged users can also install their own locale data
7586 and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
7587 @code{GUIX_LOCPATH} and locale packages}).
7588
7589 Still, it is best if the system-wide locale data at
7590 @file{/run/current-system/locale} is built for all the libc versions
7591 actually in use on the system, so that all the programs can access
7592 it---this is especially crucial on a multi-user system. To do that, the
7593 administrator can specify several libc packages in the
7594 @code{locale-libcs} field of @code{operating-system}:
7595
7596 @example
7597 (use-package-modules base)
7598
7599 (operating-system
7600 ;; @dots{}
7601 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
7602 @end example
7603
7604 This example would lead to a system containing locale definitions for
7605 both libc 2.21 and the current version of libc in
7606 @file{/run/current-system/locale}.
7607
7608
7609 @node Services
7610 @subsection Services
7611
7612 @cindex system services
7613 An important part of preparing an @code{operating-system} declaration is
7614 listing @dfn{system services} and their configuration (@pxref{Using the
7615 Configuration System}). System services are typically daemons launched
7616 when the system boots, or other actions needed at that time---e.g.,
7617 configuring network access.
7618
7619 GuixSD has a broad definition of ``service'' (@pxref{Service
7620 Composition}), but many services are managed by the GNU@tie{}Shepherd
7621 (@pxref{Shepherd Services}). On a running system, the @command{herd}
7622 command allows you to list the available services, show their status,
7623 start and stop them, or do other specific operations (@pxref{Jump
7624 Start,,, shepherd, The GNU Shepherd Manual}). For example:
7625
7626 @example
7627 # herd status
7628 @end example
7629
7630 The above command, run as @code{root}, lists the currently defined
7631 services. The @command{herd doc} command shows a synopsis of the given
7632 service:
7633
7634 @example
7635 # herd doc nscd
7636 Run libc's name service cache daemon (nscd).
7637 @end example
7638
7639 The @command{start}, @command{stop}, and @command{restart} sub-commands
7640 have the effect you would expect. For instance, the commands below stop
7641 the nscd service and restart the Xorg display server:
7642
7643 @example
7644 # herd stop nscd
7645 Service nscd has been stopped.
7646 # herd restart xorg-server
7647 Service xorg-server has been stopped.
7648 Service xorg-server has been started.
7649 @end example
7650
7651 The following sections document the available services, starting with
7652 the core services, that may be used in an @code{operating-system}
7653 declaration.
7654
7655 @menu
7656 * Base Services:: Essential system services.
7657 * Scheduled Job Execution:: The mcron service.
7658 * Log Rotation:: The rottlog service.
7659 * Networking Services:: Network setup, SSH daemon, etc.
7660 * X Window:: Graphical display.
7661 * Printing Services:: Local and remote printer support.
7662 * Desktop Services:: D-Bus and desktop services.
7663 * Database Services:: SQL databases.
7664 * Mail Services:: IMAP, POP3, SMTP, and all that.
7665 * Web Services:: Web servers.
7666 * Network File System:: NFS related services.
7667 * Miscellaneous Services:: Other services.
7668 @end menu
7669
7670 @node Base Services
7671 @subsubsection Base Services
7672
7673 The @code{(gnu services base)} module provides definitions for the basic
7674 services that one expects from the system. The services exported by
7675 this module are listed below.
7676
7677 @defvr {Scheme Variable} %base-services
7678 This variable contains a list of basic services (@pxref{Service Types
7679 and Services}, for more information on service objects) one would
7680 expect from the system: a login service (mingetty) on each tty, syslogd,
7681 the libc name service cache daemon (nscd), the udev device manager, and
7682 more.
7683
7684 This is the default value of the @code{services} field of
7685 @code{operating-system} declarations. Usually, when customizing a
7686 system, you will want to append services to @var{%base-services}, like
7687 this:
7688
7689 @example
7690 (cons* (avahi-service) (lsh-service) %base-services)
7691 @end example
7692 @end defvr
7693
7694 @deffn {Scheme Procedure} host-name-service @var{name}
7695 Return a service that sets the host name to @var{name}.
7696 @end deffn
7697
7698 @deffn {Scheme Procedure} login-service @var{config}
7699 Return a service to run login according to @var{config}, a
7700 @code{<login-configuration>} object, which specifies the message of the day,
7701 among other things.
7702 @end deffn
7703
7704 @deftp {Data Type} login-configuration
7705 This is the data type representing the configuration of login.
7706
7707 @table @asis
7708
7709 @item @code{motd}
7710 A file-like object containing the ``message of the day''.
7711
7712 @item @code{allow-empty-passwords?} (default: @code{#t})
7713 Allow empty passwords by default so that first-time users can log in when
7714 the 'root' account has just been created.
7715
7716 @end table
7717 @end deftp
7718
7719 @deffn {Scheme Procedure} mingetty-service @var{config}
7720 Return a service to run mingetty according to @var{config}, a
7721 @code{<mingetty-configuration>} object, which specifies the tty to run, among
7722 other things.
7723 @end deffn
7724
7725 @deftp {Data Type} mingetty-configuration
7726 This is the data type representing the configuration of Mingetty, which
7727 implements console log-in.
7728
7729 @table @asis
7730
7731 @item @code{tty}
7732 The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
7733
7734 @item @code{auto-login} (default: @code{#f})
7735 When true, this field must be a string denoting the user name under
7736 which the system automatically logs in. When it is @code{#f}, a
7737 user name and password must be entered to log in.
7738
7739 @item @code{login-program} (default: @code{#f})
7740 This must be either @code{#f}, in which case the default log-in program
7741 is used (@command{login} from the Shadow tool suite), or a gexp denoting
7742 the name of the log-in program.
7743
7744 @item @code{login-pause?} (default: @code{#f})
7745 When set to @code{#t} in conjunction with @var{auto-login}, the user
7746 will have to press a key before the log-in shell is launched.
7747
7748 @item @code{mingetty} (default: @var{mingetty})
7749 The Mingetty package to use.
7750
7751 @end table
7752 @end deftp
7753
7754 @deffn {Scheme Procedure} kmscon-service-type @var{config}
7755 Return a service to run @uref{https://www.freedesktop.org/wiki/Software/kmscon,kmscon}
7756 according to @var{config}, a @code{<kmscon-configuration>} object, which
7757 specifies the tty to run, among other things.
7758 @end deffn
7759
7760 @deftp {Data Type} kmscon-configuration
7761 This is the data type representing the configuration of Kmscon, which
7762 implements console log-in.
7763
7764 @table @asis
7765
7766 @item @code{virtual-terminal}
7767 The name of the console this Kmscon runs on---e.g., @code{"tty1"}.
7768
7769 @item @code{login-program} (default: @code{#~(string-append #$shadow "/bin/login")})
7770 A gexp denoting the name of the log-in program. The default log-in program is
7771 @command{login} from the Shadow tool suite.
7772
7773 @item @code{login-arguments} (default: @code{'("-p")})
7774 A list of arguments to pass to @command{login}.
7775
7776 @item @code{hardware-acceleration?} (default: #f)
7777 Whether to use hardware acceleration.
7778
7779 @item @code{kmscon} (default: @var{kmscon})
7780 The Kmscon package to use.
7781
7782 @end table
7783 @end deftp
7784
7785 @cindex name service cache daemon
7786 @cindex nscd
7787 @deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
7788 [#:name-services '()]
7789 Return a service that runs the libc name service cache daemon (nscd) with the
7790 given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
7791 Service Switch}, for an example.
7792 @end deffn
7793
7794 @defvr {Scheme Variable} %nscd-default-configuration
7795 This is the default @code{<nscd-configuration>} value (see below) used
7796 by @code{nscd-service}. It uses the caches defined by
7797 @var{%nscd-default-caches}; see below.
7798 @end defvr
7799
7800 @deftp {Data Type} nscd-configuration
7801 This is the data type representing the name service cache daemon (nscd)
7802 configuration.
7803
7804 @table @asis
7805
7806 @item @code{name-services} (default: @code{'()})
7807 List of packages denoting @dfn{name services} that must be visible to
7808 the nscd---e.g., @code{(list @var{nss-mdns})}.
7809
7810 @item @code{glibc} (default: @var{glibc})
7811 Package object denoting the GNU C Library providing the @command{nscd}
7812 command.
7813
7814 @item @code{log-file} (default: @code{"/var/log/nscd.log"})
7815 Name of the nscd log file. This is where debugging output goes when
7816 @code{debug-level} is strictly positive.
7817
7818 @item @code{debug-level} (default: @code{0})
7819 Integer denoting the debugging levels. Higher numbers mean that more
7820 debugging output is logged.
7821
7822 @item @code{caches} (default: @var{%nscd-default-caches})
7823 List of @code{<nscd-cache>} objects denoting things to be cached; see
7824 below.
7825
7826 @end table
7827 @end deftp
7828
7829 @deftp {Data Type} nscd-cache
7830 Data type representing a cache database of nscd and its parameters.
7831
7832 @table @asis
7833
7834 @item @code{database}
7835 This is a symbol representing the name of the database to be cached.
7836 Valid values are @code{passwd}, @code{group}, @code{hosts}, and
7837 @code{services}, which designate the corresponding NSS database
7838 (@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
7839
7840 @item @code{positive-time-to-live}
7841 @itemx @code{negative-time-to-live} (default: @code{20})
7842 A number representing the number of seconds during which a positive or
7843 negative lookup result remains in cache.
7844
7845 @item @code{check-files?} (default: @code{#t})
7846 Whether to check for updates of the files corresponding to
7847 @var{database}.
7848
7849 For instance, when @var{database} is @code{hosts}, setting this flag
7850 instructs nscd to check for updates in @file{/etc/hosts} and to take
7851 them into account.
7852
7853 @item @code{persistent?} (default: @code{#t})
7854 Whether the cache should be stored persistently on disk.
7855
7856 @item @code{shared?} (default: @code{#t})
7857 Whether the cache should be shared among users.
7858
7859 @item @code{max-database-size} (default: 32@tie{}MiB)
7860 Maximum size in bytes of the database cache.
7861
7862 @c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
7863 @c settings, so leave them out.
7864
7865 @end table
7866 @end deftp
7867
7868 @defvr {Scheme Variable} %nscd-default-caches
7869 List of @code{<nscd-cache>} objects used by default by
7870 @code{nscd-configuration} (see above).
7871
7872 It enables persistent and aggressive caching of service and host name
7873 lookups. The latter provides better host name lookup performance,
7874 resilience in the face of unreliable name servers, and also better
7875 privacy---often the result of host name lookups is in local cache, so
7876 external name servers do not even need to be queried.
7877 @end defvr
7878
7879 @anchor{syslog-configuration-type}
7880 @deftp {Data Type} syslog-configuration
7881 This data type represents the configuration of the syslog daemon.
7882
7883 @table @asis
7884 @item @code{syslogd} (default: @code{#~(string-append #$inetutils "/libexec/syslogd")})
7885 The syslog daemon to use.
7886
7887 @item @code{config-file} (default: @code{%default-syslog.conf})
7888 The syslog configuration file to use.
7889
7890 @end table
7891 @end deftp
7892
7893 @anchor{syslog-service}
7894 @deffn {Scheme Procedure} syslog-service @var{config}
7895 Return a service that runs a syslog daemon according to @var{config}.
7896
7897 @xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
7898 information on the configuration file syntax.
7899 @end deffn
7900
7901 @anchor{guix-configuration-type}
7902 @deftp {Data Type} guix-configuration
7903 This data type represents the configuration of the Guix build daemon.
7904 @xref{Invoking guix-daemon}, for more information.
7905
7906 @table @asis
7907 @item @code{guix} (default: @var{guix})
7908 The Guix package to use.
7909
7910 @item @code{build-group} (default: @code{"guixbuild"})
7911 Name of the group for build user accounts.
7912
7913 @item @code{build-accounts} (default: @code{10})
7914 Number of build user accounts to create.
7915
7916 @item @code{authorize-key?} (default: @code{#t})
7917 Whether to authorize the substitute keys listed in
7918 @code{authorized-keys}---by default that of @code{hydra.gnu.org}
7919 (@pxref{Substitutes}).
7920
7921 @vindex %default-authorized-guix-keys
7922 @item @code{authorized-keys} (default: @var{%default-authorized-guix-keys})
7923 The list of authorized key files for archive imports, as a list of
7924 string-valued gexps (@pxref{Invoking guix archive}). By default, it
7925 contains that of @code{hydra.gnu.org} (@pxref{Substitutes}).
7926
7927 @item @code{use-substitutes?} (default: @code{#t})
7928 Whether to use substitutes.
7929
7930 @item @code{substitute-urls} (default: @var{%default-substitute-urls})
7931 The list of URLs where to look for substitutes by default.
7932
7933 @item @code{extra-options} (default: @code{'()})
7934 List of extra command-line options for @command{guix-daemon}.
7935
7936 @item @code{lsof} (default: @var{lsof})
7937 @itemx @code{lsh} (default: @var{lsh})
7938 The lsof and lsh packages to use.
7939
7940 @end table
7941 @end deftp
7942
7943 @deffn {Scheme Procedure} guix-service @var{config}
7944 Return a service that runs the Guix build daemon according to
7945 @var{config}.
7946 @end deffn
7947
7948 @deffn {Scheme Procedure} udev-service [#:udev udev]
7949 Run @var{udev}, which populates the @file{/dev} directory dynamically.
7950 @end deffn
7951
7952 @deffn {Scheme Procedure} urandom-seed-service @var{#f}
7953 Save some entropy in @var{%random-seed-file} to seed @file{/dev/urandom}
7954 when rebooting.
7955 @end deffn
7956
7957 @defvr {Scheme Variable} %random-seed-file
7958 This is the name of the file where some random bytes are saved by
7959 @var{urandom-seed-service} to seed @file{/dev/urandom} when rebooting.
7960 It defaults to @file{/var/lib/random-seed}.
7961 @end defvr
7962
7963 @deffn {Scheme Procedure} console-keymap-service @var{files} ...
7964 @cindex keyboard layout
7965 Return a service to load console keymaps from @var{files} using
7966 @command{loadkeys} command. Most likely, you want to load some default
7967 keymap, which can be done like this:
7968
7969 @example
7970 (console-keymap-service "dvorak")
7971 @end example
7972
7973 Or, for example, for a Swedish keyboard, you may need to combine
7974 the following keymaps:
7975 @example
7976 (console-keymap-service "se-lat6" "se-fi-lat6")
7977 @end example
7978
7979 Also you can specify a full file name (or file names) of your keymap(s).
7980 See @code{man loadkeys} for details.
7981
7982 @end deffn
7983
7984 @deffn {Scheme Procedure} gpm-service [#:gpm @var{gpm}] @
7985 [#:options]
7986 Run @var{gpm}, the general-purpose mouse daemon, with the given
7987 command-line @var{options}. GPM allows users to use the mouse in the console,
7988 notably to select, copy, and paste text. The default value of @var{options}
7989 uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
7990
7991 This service is not part of @var{%base-services}.
7992 @end deffn
7993
7994 @anchor{guix-publish-service}
7995 @deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
7996 [#:port 80] [#:host "localhost"]
7997 Return a service that runs @command{guix publish} listening on @var{host}
7998 and @var{port} (@pxref{Invoking guix publish}).
7999
8000 This assumes that @file{/etc/guix} already contains a signing key pair as
8001 created by @command{guix archive --generate-key} (@pxref{Invoking guix
8002 archive}). If that is not the case, the service will fail to start.
8003 @end deffn
8004
8005 @anchor{rngd-service}
8006 @deffn {Scheme Procedure} rngd-service [#:rng-tools @var{rng-tools}] @
8007 [#:device "/dev/hwrng"]
8008 Return a service that runs the @command{rngd} program from @var{rng-tools}
8009 to add @var{device} to the kernel's entropy pool. The service will fail if
8010 @var{device} does not exist.
8011 @end deffn
8012
8013 @anchor{pam-limits-service}
8014 @cindex session limits
8015 @cindex ulimit
8016 @cindex priority
8017 @deffn {Scheme Procedure} pam-limits-service [#:limits @var{limits}]
8018
8019 Return a service that installs a configuration file for the
8020 @uref{http://linux-pam.org/Linux-PAM-html/sag-pam_limits.html,
8021 @code{pam_limits} module}. The procedure optionally takes a list of
8022 @code{pam-limits-entry} values, which can be used to specify
8023 @code{ulimit} limits and nice priority limits to user sessions.
8024
8025 The following limits definition sets two hard and soft limits for all
8026 login sessions of users in the @code{realtime} group:
8027
8028 @example
8029 (pam-limits-service
8030 (list
8031 (pam-limits-entry "@@realtime" 'both 'rtprio 99)
8032 (pam-limits-entry "@@realtime" 'both 'memlock 'unlimited)))
8033 @end example
8034
8035 The first entry increases the maximum realtime priority for
8036 non-privileged processes; the second entry lifts any restriction of the
8037 maximum address space that can be locked in memory. These settings are
8038 commonly used for real-time audio systems.
8039 @end deffn
8040
8041 @node Scheduled Job Execution
8042 @subsubsection Scheduled Job Execution
8043
8044 @cindex cron
8045 @cindex scheduling jobs
8046 The @code{(gnu services mcron)} module provides an interface to
8047 GNU@tie{}mcron, a daemon to run jobs at scheduled times (@pxref{Top,,,
8048 mcron, GNU@tie{}mcron}). GNU@tie{}mcron is similar to the traditional
8049 Unix @command{cron} daemon; the main difference is that it is
8050 implemented in Guile Scheme, which provides a lot of flexibility when
8051 specifying the scheduling of jobs and their actions.
8052
8053 The example below defines an operating system that runs the
8054 @command{updatedb} (@pxref{Invoking updatedb,,, find, Finding Files})
8055 and the @command{guix gc} commands (@pxref{Invoking guix gc}) daily, as
8056 well as the @command{mkid} command on behalf of an unprivileged user
8057 (@pxref{mkid invocation,,, idutils, ID Database Utilities}). It uses
8058 gexps to introduce job definitions that are passed to mcron
8059 (@pxref{G-Expressions}).
8060
8061 @lisp
8062 (use-modules (guix) (gnu) (gnu services mcron))
8063 (use-package-modules base idutils)
8064
8065 (define updatedb-job
8066 ;; Run 'updatedb' at 3AM every day. Here we write the
8067 ;; job's action as a Scheme procedure.
8068 #~(job '(next-hour '(3))
8069 (lambda ()
8070 (execl (string-append #$findutils "/bin/updatedb")
8071 "updatedb"
8072 "--prunepaths=/tmp /var/tmp /gnu/store"))))
8073
8074 (define garbage-collector-job
8075 ;; Collect garbage 5 minutes after midnight every day.
8076 ;; The job's action is a shell command.
8077 #~(job "5 0 * * *" ;Vixie cron syntax
8078 "guix gc -F 1G"))
8079
8080 (define idutils-job
8081 ;; Update the index database as user "charlie" at 12:15PM
8082 ;; and 19:15PM. This runs from the user's home directory.
8083 #~(job '(next-minute-from (next-hour '(12 19)) '(15))
8084 (string-append #$idutils "/bin/mkid src")
8085 #:user "charlie"))
8086
8087 (operating-system
8088 ;; @dots{}
8089 (services (cons (mcron-service (list garbage-collector-job
8090 updatedb-job
8091 idutils-job))
8092 %base-services)))
8093 @end lisp
8094
8095 @xref{Guile Syntax, mcron job specifications,, mcron, GNU@tie{}mcron},
8096 for more information on mcron job specifications. Below is the
8097 reference of the mcron service.
8098
8099 @deffn {Scheme Procedure} mcron-service @var{jobs} [#:mcron @var{mcron2}]
8100 Return an mcron service running @var{mcron} that schedules @var{jobs}, a
8101 list of gexps denoting mcron job specifications.
8102
8103 This is a shorthand for:
8104 @example
8105 (service mcron-service-type
8106 (mcron-configuration (mcron mcron) (jobs jobs)))
8107 @end example
8108 @end deffn
8109
8110 @defvr {Scheme Variable} mcron-service-type
8111 This is the type of the @code{mcron} service, whose value is an
8112 @code{mcron-configuration} object.
8113
8114 This service type can be the target of a service extension that provides
8115 it additional job specifications (@pxref{Service Composition}). In
8116 other words, it is possible to define services that provide additional
8117 mcron jobs to run.
8118 @end defvr
8119
8120 @deftp {Data Type} mcron-configuration
8121 Data type representing the configuration of mcron.
8122
8123 @table @asis
8124 @item @code{mcron} (default: @var{mcron2})
8125 The mcron package to use.
8126
8127 @item @code{jobs}
8128 This is a list of gexps (@pxref{G-Expressions}), where each gexp
8129 corresponds to an mcron job specification (@pxref{Syntax, mcron job
8130 specifications,, mcron, GNU@tie{}mcron}).
8131 @end table
8132 @end deftp
8133
8134
8135 @node Log Rotation
8136 @subsubsection Log Rotation
8137
8138 @cindex rottlog
8139 @cindex log rotation
8140 Log files such as those found in @file{/var/log} tend to grow endlessly,
8141 so it's a good idea to @dfn{rotate} them once in a while---i.e., archive
8142 their contents in separate files, possibly compressed. The @code{(gnu
8143 services admin)} module provides an interface to GNU@tie{}Rot[t]log, a
8144 log rotation tool (@pxref{Top,,, rottlog, GNU Rot[t]log Manual}).
8145
8146 The example below defines an operating system that provides log rotation
8147 with the default settings.
8148
8149 @lisp
8150 (use-modules (guix) (gnu))
8151 (use-service-modules admin mcron)
8152 (use-package-modules base idutils)
8153
8154 (operating-system
8155 ;; @dots{}
8156 (services (cons* (mcron-service)
8157 (service rottlog-service-type (rottlog-configuration))
8158 %base-services)))
8159 @end lisp
8160
8161 @defvr {Scheme Variable} rottlog-service-type
8162 This is the type of the Rottlog service, whose value is a
8163 @code{rottlog-configuration} object.
8164
8165 This service type can define mcron jobs (@pxref{Scheduled Job
8166 Execution}) to run the rottlog service.
8167 @end defvr
8168
8169 @deftp {Data Type} rottlog-configuration
8170 Data type representing the configuration of rottlog.
8171
8172 @table @asis
8173 @item @code{rottlog} (default: @code{rottlog})
8174 The Rottlog package to use.
8175
8176 @item @code{rc-file} (default: @code{(file-append rottlog "/etc/rc")})
8177 The Rottlog configuration file to use (@pxref{Mandatory RC Variables,,,
8178 rottlog, GNU Rot[t]log Manual}).
8179
8180 @item @code{periodic-rotations} (default: @code{`(("weekly" %default-rotatations))})
8181 A list of Rottlog period-name/period-config tuples.
8182
8183 For example, taking an example from the Rottlog manual (@pxref{Period
8184 Related File Examples,,, rottlog, GNU Rot[t]log Manual}), a valid tuple
8185 might be:
8186
8187 @example
8188 ("daily" ,(plain-file "daily"
8189 "\
8190 /var/log/apache/* @{
8191 storedir apache-archives
8192 rotate 6
8193 notifempty
8194 nocompress
8195 @}"))
8196 @end example
8197
8198 @item @code{jobs}
8199 This is a list of gexps where each gexp corresponds to an mcron job
8200 specification (@pxref{Scheduled Job Execution}).
8201 @end table
8202 @end deftp
8203
8204 @defvr {Scheme Variable} %default-rotations
8205 Specifies weekly rotation of @var{%rotated-files} and
8206 @code{"/var/log/shepherd.log"}.
8207 @end defvr
8208
8209 @defvr {Scheme Variable} %rotated-files
8210 The list of syslog-controlled files to be rotated. By default it is:
8211 @code{'("/var/log/messages" "/var/log/secure")}.
8212 @end defvr
8213
8214 @node Networking Services
8215 @subsubsection Networking Services
8216
8217 The @code{(gnu services networking)} module provides services to configure
8218 the network interface.
8219
8220 @cindex DHCP, networking service
8221 @deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
8222 Return a service that runs @var{dhcp}, a Dynamic Host Configuration
8223 Protocol (DHCP) client, on all the non-loopback network interfaces.
8224 @end deffn
8225
8226 @deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
8227 [#:gateway #f] [#:name-servers @code{'()}]
8228 Return a service that starts @var{interface} with address @var{ip}. If
8229 @var{gateway} is true, it must be a string specifying the default network
8230 gateway.
8231 @end deffn
8232
8233 @cindex wicd
8234 @cindex network management
8235 @deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
8236 Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
8237 management daemon that aims to simplify wired and wireless networking.
8238
8239 This service adds the @var{wicd} package to the global profile, providing
8240 several commands to interact with the daemon and configure networking:
8241 @command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
8242 and @command{wicd-curses} user interfaces.
8243 @end deffn
8244
8245 @cindex NetworkManager
8246 @deffn {Scheme Procedure} network-manager-service @
8247 [#:network-manager @var{network-manager}]
8248 Return a service that runs NetworkManager, a network connection manager
8249 attempting to keep network connectivity active when available.
8250 @end deffn
8251
8252 @cindex Connman
8253 @deffn {Scheme Procedure} connman-service @
8254 [#:connman @var{connman}]
8255 Return a service that runs @url{https://01.org/connman,Connman}, a network
8256 connection manager.
8257
8258 This service adds the @var{connman} package to the global profile, providing
8259 several the @command{connmanctl} command to interact with the daemon and
8260 configure networking."
8261 @end deffn
8262
8263 @deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
8264 [#:servers @var{%ntp-servers}]
8265 Return a service that runs the daemon from @var{ntp}, the
8266 @uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
8267 keep the system clock synchronized with that of @var{servers}.
8268 @end deffn
8269
8270 @defvr {Scheme Variable} %ntp-servers
8271 List of host names used as the default NTP servers.
8272 @end defvr
8273
8274 @deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
8275 Return a service to run the @uref{https://torproject.org, Tor} anonymous
8276 networking daemon.
8277
8278 The daemon runs as the @code{tor} unprivileged user. It is passed
8279 @var{config-file}, a file-like object, with an additional @code{User tor} line
8280 and lines for hidden services added via @code{tor-hidden-service}. Run
8281 @command{man tor} for information about the configuration file.
8282 @end deffn
8283
8284 @cindex hidden service
8285 @deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
8286 Define a new Tor @dfn{hidden service} called @var{name} and implementing
8287 @var{mapping}. @var{mapping} is a list of port/host tuples, such as:
8288
8289 @example
8290 '((22 "127.0.0.1:22")
8291 (80 "127.0.0.1:8080"))
8292 @end example
8293
8294 In this example, port 22 of the hidden service is mapped to local port 22, and
8295 port 80 is mapped to local port 8080.
8296
8297 This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
8298 the @file{hostname} file contains the @code{.onion} host name for the hidden
8299 service.
8300
8301 See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
8302 project's documentation} for more information.
8303 @end deffn
8304
8305 @deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
8306 [#:interface "127.0.0.1"] [#:port 6667] @
8307 [#:extra-settings ""]
8308 Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
8309 acts as a gateway between IRC and chat networks.
8310
8311 The daemon will listen to the interface corresponding to the IP address
8312 specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
8313 local clients can connect, whereas @code{0.0.0.0} means that connections can
8314 come from any networking interface.
8315
8316 In addition, @var{extra-settings} specifies a string to append to the
8317 configuration file.
8318 @end deffn
8319
8320 Furthermore, @code{(gnu services ssh)} provides the following services.
8321
8322 @deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
8323 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
8324 [#:allow-empty-passwords? #f] [#:root-login? #f] @
8325 [#:syslog-output? #t] [#:x11-forwarding? #t] @
8326 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
8327 [#:public-key-authentication? #t] [#:initialize? #t]
8328 Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
8329 @var{host-key} must designate a file containing the host key, and readable
8330 only by root.
8331
8332 When @var{daemonic?} is true, @command{lshd} will detach from the
8333 controlling terminal and log its output to syslogd, unless one sets
8334 @var{syslog-output?} to false. Obviously, it also makes lsh-service
8335 depend on existence of syslogd service. When @var{pid-file?} is true,
8336 @command{lshd} writes its PID to the file called @var{pid-file}.
8337
8338 When @var{initialize?} is true, automatically create the seed and host key
8339 upon service activation if they do not exist yet. This may take long and
8340 require interaction.
8341
8342 When @var{initialize?} is false, it is up to the user to initialize the
8343 randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
8344 a key pair with the private key stored in file @var{host-key} (@pxref{lshd
8345 basics,,, lsh, LSH Manual}).
8346
8347 When @var{interfaces} is empty, lshd listens for connections on all the
8348 network interfaces; otherwise, @var{interfaces} must be a list of host names
8349 or addresses.
8350
8351 @var{allow-empty-passwords?} specifies whether to accept log-ins with empty
8352 passwords, and @var{root-login?} specifies whether to accept log-ins as
8353 root.
8354
8355 The other options should be self-descriptive.
8356 @end deffn
8357
8358 @deffn {Scheme Variable} openssh-service-type
8359 This is the type for the @uref{http://www.openssh.org, OpenSSH} secure
8360 shell daemon, @command{sshd}. Its value must be an
8361 @code{openssh-configuration} record as in this example:
8362
8363 @example
8364 (service openssh-service-type
8365 (openssh-configuration
8366 (x11-forwarding? #t)
8367 (permit-root-login 'without-password)))
8368 @end example
8369
8370 See below for details about @code{openssh-configuration}.
8371 @end deffn
8372
8373 @deftp {Data Type} openssh-configuration
8374 This is the configuration record for OpenSSH's @command{sshd}.
8375
8376 @table @asis
8377 @item @code{pid-file} (default: @code{"/var/run/sshd.pid"})
8378 Name of the file where @command{sshd} writes its PID.
8379
8380 @item @code{port-number} (default: @code{22})
8381 TCP port on which @command{sshd} listens for incoming connections.
8382
8383 @item @code{permit-root-login} (default: @code{#f})
8384 This field determines whether and when to allow logins as root. If
8385 @code{#f}, root logins are disallowed; if @code{#t}, they are allowed.
8386 If it's the symbol @code{'without-password}, then root logins are
8387 permitted but not with password-based authentication.
8388
8389 @item @code{allow-empty-passwords?} (default: @code{#f})
8390 When true, users with empty passwords may log in. When false, they may
8391 not.
8392
8393 @item @code{password-authentication?} (default: @code{#t})
8394 When true, users may log in with their password. When false, they have
8395 other authentication methods.
8396
8397 @item @code{public-key-authentication?} (default: @code{#t})
8398 When true, users may log in using public key authentication. When
8399 false, users have to use other authentication method.
8400
8401 Authorized public keys are stored in @file{~/.ssh/authorized_keys}.
8402 This is used only by protocol version 2.
8403
8404 @item @code{rsa-authentication?} (default: @code{#t})
8405 When true, users may log in using pure RSA authentication. When false,
8406 users have to use other means of authentication. This is used only by
8407 protocol 1.
8408
8409 @item @code{x11-forwarding?} (default: @code{#f})
8410 When true, forwarding of X11 graphical client connections is
8411 enabled---in other words, @command{ssh} options @option{-X} and
8412 @option{-Y} will work.
8413
8414 @item @code{protocol-number} (default: @code{2})
8415 The SSH protocol number to use.
8416 @end table
8417 @end deftp
8418
8419 @deffn {Scheme Procedure} dropbear-service [@var{config}]
8420 Run the @uref{https://matt.ucc.asn.au/dropbear/dropbear.html,Dropbear SSH
8421 daemon} with the given @var{config}, a @code{<dropbear-configuration>}
8422 object.
8423
8424 For example, to specify a Dropbear service listening on port 1234, add
8425 this call to the operating system's @code{services} field:
8426
8427 @example
8428 (dropbear-service (dropbear-configuration
8429 (port-number 1234)))
8430 @end example
8431 @end deffn
8432
8433 @deftp {Data Type} dropbear-configuration
8434 This data type represents the configuration of a Dropbear SSH daemon.
8435
8436 @table @asis
8437 @item @code{dropbear} (default: @var{dropbear})
8438 The Dropbear package to use.
8439
8440 @item @code{port-number} (default: 22)
8441 The TCP port where the daemon waits for incoming connections.
8442
8443 @item @code{syslog-output?} (default: @code{#t})
8444 Whether to enable syslog output.
8445
8446 @item @code{pid-file} (default: @code{"/var/run/dropbear.pid"})
8447 File name of the daemon's PID file.
8448
8449 @item @code{root-login?} (default: @code{#f})
8450 Whether to allow @code{root} logins.
8451
8452 @item @code{allow-empty-passwords?} (default: @code{#f})
8453 Whether to allow empty passwords.
8454
8455 @item @code{password-authentication?} (default: @code{#t})
8456 Whether to enable password-based authentication.
8457 @end table
8458 @end deftp
8459
8460 @defvr {Scheme Variable} %facebook-host-aliases
8461 This variable contains a string for use in @file{/etc/hosts}
8462 (@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
8463 line contains a entry that maps a known server name of the Facebook
8464 on-line service---e.g., @code{www.facebook.com}---to the local
8465 host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
8466
8467 This variable is typically used in the @code{hosts-file} field of an
8468 @code{operating-system} declaration (@pxref{operating-system Reference,
8469 @file{/etc/hosts}}):
8470
8471 @example
8472 (use-modules (gnu) (guix))
8473
8474 (operating-system
8475 (host-name "mymachine")
8476 ;; ...
8477 (hosts-file
8478 ;; Create a /etc/hosts file with aliases for "localhost"
8479 ;; and "mymachine", as well as for Facebook servers.
8480 (plain-file "hosts"
8481 (string-append (local-host-aliases host-name)
8482 %facebook-host-aliases))))
8483 @end example
8484
8485 This mechanism can prevent programs running locally, such as Web
8486 browsers, from accessing Facebook.
8487 @end defvr
8488
8489 The @code{(gnu services avahi)} provides the following definition.
8490
8491 @deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
8492 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
8493 [#:ipv6? #t] [#:wide-area? #f] @
8494 [#:domains-to-browse '()] [#:debug? #f]
8495 Return a service that runs @command{avahi-daemon}, a system-wide
8496 mDNS/DNS-SD responder that allows for service discovery and
8497 "zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
8498 extends the name service cache daemon (nscd) so that it can resolve
8499 @code{.local} host names using
8500 @uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
8501 add the @var{avahi} package to the system profile so that commands such as
8502 @command{avahi-browse} are directly usable.
8503
8504 If @var{host-name} is different from @code{#f}, use that as the host name to
8505 publish for this machine; otherwise, use the machine's actual host name.
8506
8507 When @var{publish?} is true, publishing of host names and services is allowed;
8508 in particular, avahi-daemon will publish the machine's host name and IP
8509 address via mDNS on the local network.
8510
8511 When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
8512
8513 Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
8514 sockets.
8515 @end deffn
8516
8517
8518 @node X Window
8519 @subsubsection X Window
8520
8521 Support for the X Window graphical display system---specifically
8522 Xorg---is provided by the @code{(gnu services xorg)} module. Note that
8523 there is no @code{xorg-service} procedure. Instead, the X server is
8524 started by the @dfn{login manager}, currently SLiM.
8525
8526 @deftp {Data Type} sddm-configuration
8527 This is the data type representing the sddm service configuration.
8528
8529 @table @asis
8530 @item @code{display-server} (default: "x11")
8531 Select display server to use for the greeter. Valid values are "x11"
8532 or "wayland".
8533
8534 @item @code{numlock} (default: "on")
8535 Valid values are "on", "off" or "none".
8536
8537 @item @code{halt-command} (default @code{#~(string-apppend #$shepherd "/sbin/halt")})
8538 Command to run when halting.
8539
8540 @item @code{reboot-command} (default @code{#~(string-append #$shepherd "/sbin/reboot")})
8541 Command to run when rebooting.
8542
8543 @item @code{theme} (default "maldives")
8544 Theme to use. Default themes provided by SDDM are "elarun" or "maldives".
8545
8546 @item @code{themes-directory} (default "/run/current-system/profile/share/sddm/themes")
8547 Directory to look for themes.
8548
8549 @item @code{faces-directory} (default "/run/current-system/profile/share/sddm/faces")
8550 Directory to look for faces.
8551
8552 @item @code{default-path} (default "/run/current-system/profile/bin")
8553 Default PATH to use.
8554
8555 @item @code{minimum-uid} (default 1000)
8556 Minimum UID to display in SDDM.
8557
8558 @item @code{maximum-uid} (default 2000)
8559 Maximum UID to display in SDDM
8560
8561 @item @code{remember-last-user?} (default #t)
8562 Remember last user.
8563
8564 @item @code{remember-last-session?} (default #t)
8565 Remember last session.
8566
8567 @item @code{hide-users} (default "")
8568 Usernames to hide from SDDM greeter.
8569
8570 @item @code{hide-shells} (default @code{#~(string-append #$shadow "/sbin/nologin")})
8571 Users with shells listed will be hidden from the SDDM greeter.
8572
8573 @item @code{session-command} (default @code{#~(string-append #$sddm "/share/sddm/scripts/wayland-session")})
8574 Script to run before starting a wayland session.
8575
8576 @item @code{sessions-directory} (default "/run/current-system/profile/share/wayland-sessions")
8577 Directory to look for desktop files starting wayland sessions.
8578
8579 @item @code{xorg-server-path} (default @code{xorg-start-command})
8580 Path to xorg-server.
8581
8582 @item @code{xauth-path} (default @code{#~(string-append #$xauth "/bin/xauth")})
8583 Path to xauth.
8584
8585 @item @code{xephyr-path} (default @code{#~(string-append #$xorg-server "/bin/Xephyr")})
8586 Path to Xephyr.
8587
8588 @item @code{xdisplay-start} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xsetup")})
8589 Script to run after starting xorg-server.
8590
8591 @item @code{xdisplay-stop} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xstop")})
8592 Script to run before stopping xorg-server.
8593
8594 @item @code{xsession-command} (default: @code{xinitr })
8595 Script to run before starting a X session.
8596
8597 @item @code{xsessions-directory} (default: "/run/current-system/profile/share/xsessions")
8598 Directory to look for desktop files starting X sessions.
8599
8600 @item @code{minimum-vt} (default: 7)
8601 Minimum VT to use.
8602
8603 @item @code{xserver-arguments} (default "-nolisten tcp")
8604 Arguments to pass to xorg-server.
8605
8606 @item @code{auto-login-user} (default "")
8607 User to use for auto-login.
8608
8609 @item @code{auto-login-session} (default "")
8610 Desktop file to use for auto-login.
8611
8612 @item @code{relogin?} (default #f)
8613 Relogin after logout.
8614
8615 @end table
8616 @end deftp
8617
8618 @deffn {Scheme Procedure} sddm-service config
8619 Return a service that spawns the SDDM graphical login manager for config of
8620 type @code{<sddm-configuration>}.
8621
8622 @example
8623 (sddm-service (sddm-configuration
8624 (auto-login-user "Alice")
8625 (auto-login-session "xfce.desktop")))
8626 @end example
8627 @end deffn
8628
8629 @deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
8630 [#:auto-login? #f] [#:default-user ""] [#:startx] @
8631 [#:theme @var{%default-slim-theme}] @
8632 [#:theme-name @var{%default-slim-theme-name}]
8633 Return a service that spawns the SLiM graphical login manager, which in
8634 turn starts the X display server with @var{startx}, a command as returned by
8635 @code{xorg-start-command}.
8636
8637 @cindex X session
8638
8639 SLiM automatically looks for session types described by the @file{.desktop}
8640 files in @file{/run/current-system/profile/share/xsessions} and allows users
8641 to choose a session from the log-in screen using @kbd{F1}. Packages such as
8642 @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
8643 adding them to the system-wide set of packages automatically makes them
8644 available at the log-in screen.
8645
8646 In addition, @file{~/.xsession} files are honored. When available,
8647 @file{~/.xsession} must be an executable that starts a window manager
8648 and/or other X clients.
8649
8650 When @var{allow-empty-passwords?} is true, allow logins with an empty
8651 password. When @var{auto-login?} is true, log in automatically as
8652 @var{default-user}.
8653
8654 If @var{theme} is @code{#f}, use the default log-in theme; otherwise
8655 @var{theme} must be a gexp denoting the name of a directory containing the
8656 theme to use. In that case, @var{theme-name} specifies the name of the
8657 theme.
8658 @end deffn
8659
8660 @defvr {Scheme Variable} %default-theme
8661 @defvrx {Scheme Variable} %default-theme-name
8662 The G-Expression denoting the default SLiM theme and its name.
8663 @end defvr
8664
8665 @deffn {Scheme Procedure} xorg-start-command [#:guile] @
8666 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
8667 Return a derivation that builds a @var{guile} script to start the X server
8668 from @var{xorg-server}. @var{configuration-file} is the server configuration
8669 file or a derivation that builds it; when omitted, the result of
8670 @code{xorg-configuration-file} is used.
8671
8672 Usually the X server is started by a login manager.
8673 @end deffn
8674
8675 @deffn {Scheme Procedure} xorg-configuration-file @
8676 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
8677 Return a configuration file for the Xorg server containing search paths for
8678 all the common drivers.
8679
8680 @var{drivers} must be either the empty list, in which case Xorg chooses a
8681 graphics driver automatically, or a list of driver names that will be tried in
8682 this order---e.g., @code{(\"modesetting\" \"vesa\")}.
8683
8684 Likewise, when @var{resolutions} is the empty list, Xorg chooses an
8685 appropriate screen resolution; otherwise, it must be a list of
8686 resolutions---e.g., @code{((1024 768) (640 480))}.
8687
8688 Last, @var{extra-config} is a list of strings or objects appended to the
8689 @code{text-file*} argument list. It is used to pass extra text to be added
8690 verbatim to the configuration file.
8691 @end deffn
8692
8693 @deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
8694 Add @var{package}, a package for a screen-locker or screen-saver whose
8695 command is @var{program}, to the set of setuid programs and add a PAM entry
8696 for it. For example:
8697
8698 @lisp
8699 (screen-locker-service xlockmore "xlock")
8700 @end lisp
8701
8702 makes the good ol' XlockMore usable.
8703 @end deffn
8704
8705
8706 @node Printing Services
8707 @subsubsection Printing Services
8708
8709 The @code{(gnu services cups)} module provides a Guix service definition
8710 for the CUPS printing service. To add printer support to a GuixSD
8711 system, add a @code{cups-service} to the operating system definition:
8712
8713 @deffn {Scheme Variable} cups-service-type
8714 The service type for the CUPS print server. Its value should be a valid
8715 CUPS configuration (see below). For example:
8716 @example
8717 (service cups-service-type (cups-configuration))
8718 @end example
8719 @end deffn
8720
8721 The CUPS configuration controls the basic things about your CUPS
8722 installation: what interfaces it listens on, what to do if a print job
8723 fails, how much logging to do, and so on. To actually add a printer,
8724 you have to visit the @url{http://localhost:631} URL, or use a tool such
8725 as GNOME's printer configuration services. By default, configuring a
8726 CUPS service will generate a self-signed certificate if needed, for
8727 secure connections to the print server.
8728
8729 One way you might want to customize CUPS is to enable or disable the web
8730 interface. You can do that directly, like this:
8731
8732 @example
8733 (service cups-service-type
8734 (cups-configuration
8735 (web-interface? #f)))
8736 @end example
8737
8738 The available configuration parameters follow. Each parameter
8739 definition is preceded by its type; for example, @samp{string-list foo}
8740 indicates that the @code{foo} parameter should be specified as a list of
8741 strings. There is also a way to specify the configuration as a string,
8742 if you have an old @code{cupsd.conf} file that you want to port over
8743 from some other system; see the end for more details.
8744
8745 @c The following documentation was initially generated by
8746 @c (generate-documentation) in (gnu services cups). Manually maintained
8747 @c documentation is better, so we shouldn't hesitate to edit below as
8748 @c needed. However if the change you want to make to this documentation
8749 @c can be done in an automated way, it's probably easier to change
8750 @c (generate-documentation) than to make it below and have to deal with
8751 @c the churn as CUPS updates.
8752
8753
8754 Available @code{cups-configuration} fields are:
8755
8756 @deftypevr {@code{cups-configuration} parameter} package cups
8757 The CUPS package.
8758 @end deftypevr
8759
8760 @deftypevr {@code{cups-configuration} parameter} package-list extensions
8761 Drivers and other extensions to the CUPS package.
8762 @end deftypevr
8763
8764 @deftypevr {@code{cups-configuration} parameter} files-configuration files-configuration
8765 Configuration of where to write logs, what directories to use for print
8766 spools, and related privileged configuration parameters.
8767
8768 Available @code{files-configuration} fields are:
8769
8770 @deftypevr {@code{files-configuration} parameter} log-location access-log
8771 Defines the access log filename. Specifying a blank filename disables
8772 access log generation. The value @code{stderr} causes log entries to be
8773 sent to the standard error file when the scheduler is running in the
8774 foreground, or to the system log daemon when run in the background. The
8775 value @code{syslog} causes log entries to be sent to the system log
8776 daemon. The server name may be included in filenames using the string
8777 @code{%s}, as in @code{/var/log/cups/%s-access_log}.
8778
8779 Defaults to @samp{"/var/log/cups/access_log"}.
8780 @end deftypevr
8781
8782 @deftypevr {@code{files-configuration} parameter} file-name cache-dir
8783 Where CUPS should cache data.
8784
8785 Defaults to @samp{"/var/cache/cups"}.
8786 @end deftypevr
8787
8788 @deftypevr {@code{files-configuration} parameter} string config-file-perm
8789 Specifies the permissions for all configuration files that the scheduler
8790 writes.
8791
8792 Note that the permissions for the printers.conf file are currently
8793 masked to only allow access from the scheduler user (typically root).
8794 This is done because printer device URIs sometimes contain sensitive
8795 authentication information that should not be generally known on the
8796 system. There is no way to disable this security feature.
8797
8798 Defaults to @samp{"0640"}.
8799 @end deftypevr
8800
8801 @deftypevr {@code{files-configuration} parameter} log-location error-log
8802 Defines the error log filename. Specifying a blank filename disables
8803 access log generation. The value @code{stderr} causes log entries to be
8804 sent to the standard error file when the scheduler is running in the
8805 foreground, or to the system log daemon when run in the background. The
8806 value @code{syslog} causes log entries to be sent to the system log
8807 daemon. The server name may be included in filenames using the string
8808 @code{%s}, as in @code{/var/log/cups/%s-error_log}.
8809
8810 Defaults to @samp{"/var/log/cups/error_log"}.
8811 @end deftypevr
8812
8813 @deftypevr {@code{files-configuration} parameter} string fatal-errors
8814 Specifies which errors are fatal, causing the scheduler to exit. The
8815 kind strings are:
8816
8817 @table @code
8818 @item none
8819 No errors are fatal.
8820
8821 @item all
8822 All of the errors below are fatal.
8823
8824 @item browse
8825 Browsing initialization errors are fatal, for example failed connections
8826 to the DNS-SD daemon.
8827
8828 @item config
8829 Configuration file syntax errors are fatal.
8830
8831 @item listen
8832 Listen or Port errors are fatal, except for IPv6 failures on the
8833 loopback or @code{any} addresses.
8834
8835 @item log
8836 Log file creation or write errors are fatal.
8837
8838 @item permissions
8839 Bad startup file permissions are fatal, for example shared TLS
8840 certificate and key files with world-read permissions.
8841 @end table
8842
8843 Defaults to @samp{"all -browse"}.
8844 @end deftypevr
8845
8846 @deftypevr {@code{files-configuration} parameter} boolean file-device?
8847 Specifies whether the file pseudo-device can be used for new printer
8848 queues. The URI @uref{file:///dev/null} is always allowed.
8849
8850 Defaults to @samp{#f}.
8851 @end deftypevr
8852
8853 @deftypevr {@code{files-configuration} parameter} string group
8854 Specifies the group name or ID that will be used when executing external
8855 programs.
8856
8857 Defaults to @samp{"lp"}.
8858 @end deftypevr
8859
8860 @deftypevr {@code{files-configuration} parameter} string log-file-perm
8861 Specifies the permissions for all log files that the scheduler writes.
8862
8863 Defaults to @samp{"0644"}.
8864 @end deftypevr
8865
8866 @deftypevr {@code{files-configuration} parameter} log-location page-log
8867 Defines the page log filename. Specifying a blank filename disables
8868 access log generation. The value @code{stderr} causes log entries to be
8869 sent to the standard error file when the scheduler is running in the
8870 foreground, or to the system log daemon when run in the background. The
8871 value @code{syslog} causes log entries to be sent to the system log
8872 daemon. The server name may be included in filenames using the string
8873 @code{%s}, as in @code{/var/log/cups/%s-page_log}.
8874
8875 Defaults to @samp{"/var/log/cups/page_log"}.
8876 @end deftypevr
8877
8878 @deftypevr {@code{files-configuration} parameter} string remote-root
8879 Specifies the username that is associated with unauthenticated accesses
8880 by clients claiming to be the root user. The default is @code{remroot}.
8881
8882 Defaults to @samp{"remroot"}.
8883 @end deftypevr
8884
8885 @deftypevr {@code{files-configuration} parameter} file-name request-root
8886 Specifies the directory that contains print jobs and other HTTP request
8887 data.
8888
8889 Defaults to @samp{"/var/spool/cups"}.
8890 @end deftypevr
8891
8892 @deftypevr {@code{files-configuration} parameter} sandboxing sandboxing
8893 Specifies the level of security sandboxing that is applied to print
8894 filters, backends, and other child processes of the scheduler; either
8895 @code{relaxed} or @code{strict}. This directive is currently only
8896 used/supported on macOS.
8897
8898 Defaults to @samp{strict}.
8899 @end deftypevr
8900
8901 @deftypevr {@code{files-configuration} parameter} file-name server-keychain
8902 Specifies the location of TLS certificates and private keys. CUPS will
8903 look for public and private keys in this directory: a @code{.crt} files
8904 for PEM-encoded certificates and corresponding @code{.key} files for
8905 PEM-encoded private keys.
8906
8907 Defaults to @samp{"/etc/cups/ssl"}.
8908 @end deftypevr
8909
8910 @deftypevr {@code{files-configuration} parameter} file-name server-root
8911 Specifies the directory containing the server configuration files.
8912
8913 Defaults to @samp{"/etc/cups"}.
8914 @end deftypevr
8915
8916 @deftypevr {@code{files-configuration} parameter} boolean sync-on-close?
8917 Specifies whether the scheduler calls fsync(2) after writing
8918 configuration or state files.
8919
8920 Defaults to @samp{#f}.
8921 @end deftypevr
8922
8923 @deftypevr {@code{files-configuration} parameter} space-separated-string-list system-group
8924 Specifies the group(s) to use for @code{@@SYSTEM} group authentication.
8925 @end deftypevr
8926
8927 @deftypevr {@code{files-configuration} parameter} file-name temp-dir
8928 Specifies the directory where temporary files are stored.
8929
8930 Defaults to @samp{"/var/spool/cups/tmp"}.
8931 @end deftypevr
8932
8933 @deftypevr {@code{files-configuration} parameter} string user
8934 Specifies the user name or ID that is used when running external
8935 programs.
8936
8937 Defaults to @samp{"lp"}.
8938 @end deftypevr
8939 @end deftypevr
8940
8941 @deftypevr {@code{cups-configuration} parameter} access-log-level access-log-level
8942 Specifies the logging level for the AccessLog file. The @code{config}
8943 level logs when printers and classes are added, deleted, or modified and
8944 when configuration files are accessed or updated. The @code{actions}
8945 level logs when print jobs are submitted, held, released, modified, or
8946 canceled, and any of the conditions for @code{config}. The @code{all}
8947 level logs all requests.
8948
8949 Defaults to @samp{actions}.
8950 @end deftypevr
8951
8952 @deftypevr {@code{cups-configuration} parameter} boolean auto-purge-jobs?
8953 Specifies whether to purge job history data automatically when it is no
8954 longer required for quotas.
8955
8956 Defaults to @samp{#f}.
8957 @end deftypevr
8958
8959 @deftypevr {@code{cups-configuration} parameter} browse-local-protocols browse-local-protocols
8960 Specifies which protocols to use for local printer sharing.
8961
8962 Defaults to @samp{dnssd}.
8963 @end deftypevr
8964
8965 @deftypevr {@code{cups-configuration} parameter} boolean browse-web-if?
8966 Specifies whether the CUPS web interface is advertised.
8967
8968 Defaults to @samp{#f}.
8969 @end deftypevr
8970
8971 @deftypevr {@code{cups-configuration} parameter} boolean browsing?
8972 Specifies whether shared printers are advertised.
8973
8974 Defaults to @samp{#f}.
8975 @end deftypevr
8976
8977 @deftypevr {@code{cups-configuration} parameter} string classification
8978 Specifies the security classification of the server. Any valid banner
8979 name can be used, including "classified", "confidential", "secret",
8980 "topsecret", and "unclassified", or the banner can be omitted to disable
8981 secure printing functions.
8982
8983 Defaults to @samp{""}.
8984 @end deftypevr
8985
8986 @deftypevr {@code{cups-configuration} parameter} boolean classify-override?
8987 Specifies whether users may override the classification (cover page) of
8988 individual print jobs using the @code{job-sheets} option.
8989
8990 Defaults to @samp{#f}.
8991 @end deftypevr
8992
8993 @deftypevr {@code{cups-configuration} parameter} default-auth-type default-auth-type
8994 Specifies the default type of authentication to use.
8995
8996 Defaults to @samp{Basic}.
8997 @end deftypevr
8998
8999 @deftypevr {@code{cups-configuration} parameter} default-encryption default-encryption
9000 Specifies whether encryption will be used for authenticated requests.
9001
9002 Defaults to @samp{Required}.
9003 @end deftypevr
9004
9005 @deftypevr {@code{cups-configuration} parameter} string default-language
9006 Specifies the default language to use for text and web content.
9007
9008 Defaults to @samp{"en"}.
9009 @end deftypevr
9010
9011 @deftypevr {@code{cups-configuration} parameter} string default-paper-size
9012 Specifies the default paper size for new print queues. @samp{"Auto"}
9013 uses a locale-specific default, while @samp{"None"} specifies there is
9014 no default paper size. Specific size names are typically
9015 @samp{"Letter"} or @samp{"A4"}.
9016
9017 Defaults to @samp{"Auto"}.
9018 @end deftypevr
9019
9020 @deftypevr {@code{cups-configuration} parameter} string default-policy
9021 Specifies the default access policy to use.
9022
9023 Defaults to @samp{"default"}.
9024 @end deftypevr
9025
9026 @deftypevr {@code{cups-configuration} parameter} boolean default-shared?
9027 Specifies whether local printers are shared by default.
9028
9029 Defaults to @samp{#t}.
9030 @end deftypevr
9031
9032 @deftypevr {@code{cups-configuration} parameter} non-negative-integer dirty-clean-interval
9033 Specifies the delay for updating of configuration and state files, in
9034 seconds. A value of 0 causes the update to happen as soon as possible,
9035 typically within a few milliseconds.
9036
9037 Defaults to @samp{30}.
9038 @end deftypevr
9039
9040 @deftypevr {@code{cups-configuration} parameter} error-policy error-policy
9041 Specifies what to do when an error occurs. Possible values are
9042 @code{abort-job}, which will discard the failed print job;
9043 @code{retry-job}, which will retry the job at a later time;
9044 @code{retry-this-job}, which retries the failed job immediately; and
9045 @code{stop-printer}, which stops the printer.
9046
9047 Defaults to @samp{stop-printer}.
9048 @end deftypevr
9049
9050 @deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-limit
9051 Specifies the maximum cost of filters that are run concurrently, which
9052 can be used to minimize disk, memory, and CPU resource problems. A
9053 limit of 0 disables filter limiting. An average print to a
9054 non-PostScript printer needs a filter limit of about 200. A PostScript
9055 printer needs about half that (100). Setting the limit below these
9056 thresholds will effectively limit the scheduler to printing a single job
9057 at any time.
9058
9059 Defaults to @samp{0}.
9060 @end deftypevr
9061
9062 @deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-nice
9063 Specifies the scheduling priority of filters that are run to print a
9064 job. The nice value ranges from 0, the highest priority, to 19, the
9065 lowest priority.
9066
9067 Defaults to @samp{0}.
9068 @end deftypevr
9069
9070 @deftypevr {@code{cups-configuration} parameter} host-name-lookups host-name-lookups
9071 Specifies whether to do reverse lookups on connecting clients. The
9072 @code{double} setting causes @code{cupsd} to verify that the hostname
9073 resolved from the address matches one of the addresses returned for that
9074 hostname. Double lookups also prevent clients with unregistered
9075 addresses from connecting to your server. Only set this option to
9076 @code{#t} or @code{double} if absolutely required.
9077
9078 Defaults to @samp{#f}.
9079 @end deftypevr
9080
9081 @deftypevr {@code{cups-configuration} parameter} non-negative-integer job-kill-delay
9082 Specifies the number of seconds to wait before killing the filters and
9083 backend associated with a canceled or held job.
9084
9085 Defaults to @samp{30}.
9086 @end deftypevr
9087
9088 @deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-interval
9089 Specifies the interval between retries of jobs in seconds. This is
9090 typically used for fax queues but can also be used with normal print
9091 queues whose error policy is @code{retry-job} or
9092 @code{retry-current-job}.
9093
9094 Defaults to @samp{30}.
9095 @end deftypevr
9096
9097 @deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-limit
9098 Specifies the number of retries that are done for jobs. This is
9099 typically used for fax queues but can also be used with normal print
9100 queues whose error policy is @code{retry-job} or
9101 @code{retry-current-job}.
9102
9103 Defaults to @samp{5}.
9104 @end deftypevr
9105
9106 @deftypevr {@code{cups-configuration} parameter} boolean keep-alive?
9107 Specifies whether to support HTTP keep-alive connections.
9108
9109 Defaults to @samp{#t}.
9110 @end deftypevr
9111
9112 @deftypevr {@code{cups-configuration} parameter} non-negative-integer keep-alive-timeout
9113 Specifies how long an idle client connection remains open, in seconds.
9114
9115 Defaults to @samp{30}.
9116 @end deftypevr
9117
9118 @deftypevr {@code{cups-configuration} parameter} non-negative-integer limit-request-body
9119 Specifies the maximum size of print files, IPP requests, and HTML form
9120 data. A limit of 0 disables the limit check.
9121
9122 Defaults to @samp{0}.
9123 @end deftypevr
9124
9125 @deftypevr {@code{cups-configuration} parameter} multiline-string-list listen
9126 Listens on the specified interfaces for connections. Valid values are
9127 of the form @var{address}:@var{port}, where @var{address} is either an
9128 IPv6 address enclosed in brackets, an IPv4 address, or @code{*} to
9129 indicate all addresses. Values can also be file names of local UNIX
9130 domain sockets. The Listen directive is similar to the Port directive
9131 but allows you to restrict access to specific interfaces or networks.
9132 @end deftypevr
9133
9134 @deftypevr {@code{cups-configuration} parameter} non-negative-integer listen-back-log
9135 Specifies the number of pending connections that will be allowed. This
9136 normally only affects very busy servers that have reached the MaxClients
9137 limit, but can also be triggered by large numbers of simultaneous
9138 connections. When the limit is reached, the operating system will
9139 refuse additional connections until the scheduler can accept the pending
9140 ones.
9141
9142 Defaults to @samp{128}.
9143 @end deftypevr
9144
9145 @deftypevr {@code{cups-configuration} parameter} location-access-control-list location-access-controls
9146 Specifies a set of additional access controls.
9147
9148 Available @code{location-access-controls} fields are:
9149
9150 @deftypevr {@code{location-access-controls} parameter} file-name path
9151 Specifies the URI path to which the access control applies.
9152 @end deftypevr
9153
9154 @deftypevr {@code{location-access-controls} parameter} access-control-list access-controls
9155 Access controls for all access to this path, in the same format as the
9156 @code{access-controls} of @code{operation-access-control}.
9157
9158 Defaults to @samp{()}.
9159 @end deftypevr
9160
9161 @deftypevr {@code{location-access-controls} parameter} method-access-control-list method-access-controls
9162 Access controls for method-specific access to this path.
9163
9164 Defaults to @samp{()}.
9165
9166 Available @code{method-access-controls} fields are:
9167
9168 @deftypevr {@code{method-access-controls} parameter} boolean reverse?
9169 If @code{#t}, apply access controls to all methods except the listed
9170 methods. Otherwise apply to only the listed methods.
9171
9172 Defaults to @samp{#f}.
9173 @end deftypevr
9174
9175 @deftypevr {@code{method-access-controls} parameter} method-list methods
9176 Methods to which this access control applies.
9177
9178 Defaults to @samp{()}.
9179 @end deftypevr
9180
9181 @deftypevr {@code{method-access-controls} parameter} access-control-list access-controls
9182 Access control directives, as a list of strings. Each string should be
9183 one directive, such as "Order allow,deny".
9184
9185 Defaults to @samp{()}.
9186 @end deftypevr
9187 @end deftypevr
9188 @end deftypevr
9189
9190 @deftypevr {@code{cups-configuration} parameter} non-negative-integer log-debug-history
9191 Specifies the number of debugging messages that are retained for logging
9192 if an error occurs in a print job. Debug messages are logged regardless
9193 of the LogLevel setting.
9194
9195 Defaults to @samp{100}.
9196 @end deftypevr
9197
9198 @deftypevr {@code{cups-configuration} parameter} log-level log-level
9199 Specifies the level of logging for the ErrorLog file. The value
9200 @code{none} stops all logging while @code{debug2} logs everything.
9201
9202 Defaults to @samp{info}.
9203 @end deftypevr
9204
9205 @deftypevr {@code{cups-configuration} parameter} log-time-format log-time-format
9206 Specifies the format of the date and time in the log files. The value
9207 @code{standard} logs whole seconds while @code{usecs} logs microseconds.
9208
9209 Defaults to @samp{standard}.
9210 @end deftypevr
9211
9212 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients
9213 Specifies the maximum number of simultaneous clients that are allowed by
9214 the scheduler.
9215
9216 Defaults to @samp{100}.
9217 @end deftypevr
9218
9219 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients-per-host
9220 Specifies the maximum number of simultaneous clients that are allowed
9221 from a single address.
9222
9223 Defaults to @samp{100}.
9224 @end deftypevr
9225
9226 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-copies
9227 Specifies the maximum number of copies that a user can print of each
9228 job.
9229
9230 Defaults to @samp{9999}.
9231 @end deftypevr
9232
9233 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-hold-time
9234 Specifies the maximum time a job may remain in the @code{indefinite}
9235 hold state before it is canceled. A value of 0 disables cancellation of
9236 held jobs.
9237
9238 Defaults to @samp{0}.
9239 @end deftypevr
9240
9241 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs
9242 Specifies the maximum number of simultaneous jobs that are allowed. Set
9243 to 0 to allow an unlimited number of jobs.
9244
9245 Defaults to @samp{500}.
9246 @end deftypevr
9247
9248 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-printer
9249 Specifies the maximum number of simultaneous jobs that are allowed per
9250 printer. A value of 0 allows up to MaxJobs jobs per printer.
9251
9252 Defaults to @samp{0}.
9253 @end deftypevr
9254
9255 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-user
9256 Specifies the maximum number of simultaneous jobs that are allowed per
9257 user. A value of 0 allows up to MaxJobs jobs per user.
9258
9259 Defaults to @samp{0}.
9260 @end deftypevr
9261
9262 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-job-time
9263 Specifies the maximum time a job may take to print before it is
9264 canceled, in seconds. Set to 0 to disable cancellation of "stuck" jobs.
9265
9266 Defaults to @samp{10800}.
9267 @end deftypevr
9268
9269 @deftypevr {@code{cups-configuration} parameter} non-negative-integer max-log-size
9270 Specifies the maximum size of the log files before they are rotated, in
9271 bytes. The value 0 disables log rotation.
9272
9273 Defaults to @samp{1048576}.
9274 @end deftypevr
9275
9276 @deftypevr {@code{cups-configuration} parameter} non-negative-integer multiple-operation-timeout
9277 Specifies the maximum amount of time to allow between files in a
9278 multiple file print job, in seconds.
9279
9280 Defaults to @samp{300}.
9281 @end deftypevr
9282
9283 @deftypevr {@code{cups-configuration} parameter} string page-log-format
9284 Specifies the format of PageLog lines. Sequences beginning with percent
9285 (@samp{%}) characters are replaced with the corresponding information,
9286 while all other characters are copied literally. The following percent
9287 sequences are recognized:
9288
9289 @table @samp
9290 @item %%
9291 insert a single percent character
9292
9293 @item %@{name@}
9294 insert the value of the specified IPP attribute
9295
9296 @item %C
9297 insert the number of copies for the current page
9298
9299 @item %P
9300 insert the current page number
9301
9302 @item %T
9303 insert the current date and time in common log format
9304
9305 @item %j
9306 insert the job ID
9307
9308 @item %p
9309 insert the printer name
9310
9311 @item %u
9312 insert the username
9313 @end table
9314
9315 A value of the empty string disables page logging. The string @code{%p
9316 %u %j %T %P %C %@{job-billing@} %@{job-originating-host-name@}
9317 %@{job-name@} %@{media@} %@{sides@}} creates a page log with the
9318 standard items.
9319
9320 Defaults to @samp{""}.
9321 @end deftypevr
9322
9323 @deftypevr {@code{cups-configuration} parameter} environment-variables environment-variables
9324 Passes the specified environment variable(s) to child processes; a list
9325 of strings.
9326
9327 Defaults to @samp{()}.
9328 @end deftypevr
9329
9330 @deftypevr {@code{cups-configuration} parameter} policy-configuration-list policies
9331 Specifies named access control policies.
9332
9333 Available @code{policy-configuration} fields are:
9334
9335 @deftypevr {@code{policy-configuration} parameter} string name
9336 Name of the policy.
9337 @end deftypevr
9338
9339 @deftypevr {@code{policy-configuration} parameter} string job-private-access
9340 Specifies an access list for a job's private values. @code{@@ACL} maps
9341 to the printer's requesting-user-name-allowed or
9342 requesting-user-name-denied values. @code{@@OWNER} maps to the job's
9343 owner. @code{@@SYSTEM} maps to the groups listed for the
9344 @code{system-group} field of the @code{files-config} configuration,
9345 which is reified into the @code{cups-files.conf(5)} file. Other
9346 possible elements of the access list include specific user names, and
9347 @code{@@@var{group}} to indicate members of a specific group. The
9348 access list may also be simply @code{all} or @code{default}.
9349
9350 Defaults to @samp{"@@OWNER @@SYSTEM"}.
9351 @end deftypevr
9352
9353 @deftypevr {@code{policy-configuration} parameter} string job-private-values
9354 Specifies the list of job values to make private, or @code{all},
9355 @code{default}, or @code{none}.
9356
9357 Defaults to @samp{"job-name job-originating-host-name
9358 job-originating-user-name phone"}.
9359 @end deftypevr
9360
9361 @deftypevr {@code{policy-configuration} parameter} string subscription-private-access
9362 Specifies an access list for a subscription's private values.
9363 @code{@@ACL} maps to the printer's requesting-user-name-allowed or
9364 requesting-user-name-denied values. @code{@@OWNER} maps to the job's
9365 owner. @code{@@SYSTEM} maps to the groups listed for the
9366 @code{system-group} field of the @code{files-config} configuration,
9367 which is reified into the @code{cups-files.conf(5)} file. Other
9368 possible elements of the access list include specific user names, and
9369 @code{@@@var{group}} to indicate members of a specific group. The
9370 access list may also be simply @code{all} or @code{default}.
9371
9372 Defaults to @samp{"@@OWNER @@SYSTEM"}.
9373 @end deftypevr
9374
9375 @deftypevr {@code{policy-configuration} parameter} string subscription-private-values
9376 Specifies the list of job values to make private, or @code{all},
9377 @code{default}, or @code{none}.
9378
9379 Defaults to @samp{"notify-events notify-pull-method notify-recipient-uri
9380 notify-subscriber-user-name notify-user-data"}.
9381 @end deftypevr
9382
9383 @deftypevr {@code{policy-configuration} parameter} operation-access-control-list access-controls
9384 Access control by IPP operation.
9385
9386 Defaults to @samp{()}.
9387 @end deftypevr
9388 @end deftypevr
9389
9390 @deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-files
9391 Specifies whether job files (documents) are preserved after a job is
9392 printed. If a numeric value is specified, job files are preserved for
9393 the indicated number of seconds after printing. Otherwise a boolean
9394 value applies indefinitely.
9395
9396 Defaults to @samp{86400}.
9397 @end deftypevr
9398
9399 @deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-history
9400 Specifies whether the job history is preserved after a job is printed.
9401 If a numeric value is specified, the job history is preserved for the
9402 indicated number of seconds after printing. If @code{#t}, the job
9403 history is preserved until the MaxJobs limit is reached.
9404
9405 Defaults to @samp{#t}.
9406 @end deftypevr
9407
9408 @deftypevr {@code{cups-configuration} parameter} non-negative-integer reload-timeout
9409 Specifies the amount of time to wait for job completion before
9410 restarting the scheduler.
9411
9412 Defaults to @samp{30}.
9413 @end deftypevr
9414
9415 @deftypevr {@code{cups-configuration} parameter} string rip-cache
9416 Specifies the maximum amount of memory to use when converting documents
9417 into bitmaps for a printer.
9418
9419 Defaults to @samp{"128m"}.
9420 @end deftypevr
9421
9422 @deftypevr {@code{cups-configuration} parameter} string server-admin
9423 Specifies the email address of the server administrator.
9424
9425 Defaults to @samp{"root@@localhost.localdomain"}.
9426 @end deftypevr
9427
9428 @deftypevr {@code{cups-configuration} parameter} host-name-list-or-* server-alias
9429 The ServerAlias directive is used for HTTP Host header validation when
9430 clients connect to the scheduler from external interfaces. Using the
9431 special name @code{*} can expose your system to known browser-based DNS
9432 rebinding attacks, even when accessing sites through a firewall. If the
9433 auto-discovery of alternate names does not work, we recommend listing
9434 each alternate name with a ServerAlias directive instead of using
9435 @code{*}.
9436
9437 Defaults to @samp{*}.
9438 @end deftypevr
9439
9440 @deftypevr {@code{cups-configuration} parameter} string server-name
9441 Specifies the fully-qualified host name of the server.
9442
9443 Defaults to @samp{"localhost"}.
9444 @end deftypevr
9445
9446 @deftypevr {@code{cups-configuration} parameter} server-tokens server-tokens
9447 Specifies what information is included in the Server header of HTTP
9448 responses. @code{None} disables the Server header. @code{ProductOnly}
9449 reports @code{CUPS}. @code{Major} reports @code{CUPS 2}. @code{Minor}
9450 reports @code{CUPS 2.0}. @code{Minimal} reports @code{CUPS 2.0.0}.
9451 @code{OS} reports @code{CUPS 2.0.0 (@var{uname})} where @var{uname} is
9452 the output of the @code{uname} command. @code{Full} reports @code{CUPS
9453 2.0.0 (@var{uname}) IPP/2.0}.
9454
9455 Defaults to @samp{Minimal}.
9456 @end deftypevr
9457
9458 @deftypevr {@code{cups-configuration} parameter} string set-env
9459 Set the specified environment variable to be passed to child processes.
9460
9461 Defaults to @samp{"variable value"}.
9462 @end deftypevr
9463
9464 @deftypevr {@code{cups-configuration} parameter} multiline-string-list ssl-listen
9465 Listens on the specified interfaces for encrypted connections. Valid
9466 values are of the form @var{address}:@var{port}, where @var{address} is
9467 either an IPv6 address enclosed in brackets, an IPv4 address, or
9468 @code{*} to indicate all addresses.
9469
9470 Defaults to @samp{()}.
9471 @end deftypevr
9472
9473 @deftypevr {@code{cups-configuration} parameter} ssl-options ssl-options
9474 Sets encryption options. By default, CUPS only supports encryption
9475 using TLS v1.0 or higher using known secure cipher suites. The
9476 @code{AllowRC4} option enables the 128-bit RC4 cipher suites, which are
9477 required for some older clients that do not implement newer ones. The
9478 @code{AllowSSL3} option enables SSL v3.0, which is required for some
9479 older clients that do not support TLS v1.0.
9480
9481 Defaults to @samp{()}.
9482 @end deftypevr
9483
9484 @deftypevr {@code{cups-configuration} parameter} boolean strict-conformance?
9485 Specifies whether the scheduler requires clients to strictly adhere to
9486 the IPP specifications.
9487
9488 Defaults to @samp{#f}.
9489 @end deftypevr
9490
9491 @deftypevr {@code{cups-configuration} parameter} non-negative-integer timeout
9492 Specifies the HTTP request timeout, in seconds.
9493
9494 Defaults to @samp{300}.
9495
9496 @end deftypevr
9497
9498 @deftypevr {@code{cups-configuration} parameter} boolean web-interface?
9499 Specifies whether the web interface is enabled.
9500
9501 Defaults to @samp{#f}.
9502 @end deftypevr
9503
9504 At this point you're probably thinking ``oh dear, Guix manual, I like
9505 you but you can stop already with the configuration options''. Indeed.
9506 However, one more point: it could be that you have an existing
9507 @code{cupsd.conf} that you want to use. In that case, you can pass an
9508 @code{opaque-cups-configuration} as the configuration of a
9509 @code{cups-service-type}.
9510
9511 Available @code{opaque-cups-configuration} fields are:
9512
9513 @deftypevr {@code{opaque-cups-configuration} parameter} package cups
9514 The CUPS package.
9515 @end deftypevr
9516
9517 @deftypevr {@code{opaque-cups-configuration} parameter} string cupsd.conf
9518 The contents of the @code{cupsd.conf}, as a string.
9519 @end deftypevr
9520
9521 @deftypevr {@code{opaque-cups-configuration} parameter} string cups-files.conf
9522 The contents of the @code{cups-files.conf} file, as a string.
9523 @end deftypevr
9524
9525 For example, if your @code{cupsd.conf} and @code{cups-files.conf} are in
9526 strings of the same name, you could instantiate a CUPS service like
9527 this:
9528
9529 @example
9530 (service cups-service-type
9531 (opaque-cups-configuration
9532 (cupsd.conf cupsd.conf)
9533 (cups-files.conf cups-files.conf)))
9534 @end example
9535
9536
9537 @node Desktop Services
9538 @subsubsection Desktop Services
9539
9540 The @code{(gnu services desktop)} module provides services that are
9541 usually useful in the context of a ``desktop'' setup---that is, on a
9542 machine running a graphical display server, possibly with graphical user
9543 interfaces, etc. It also defines services that provide specific desktop
9544 environments like GNOME and XFCE.
9545
9546 To simplify things, the module defines a variable containing the set of
9547 services that users typically expect on a machine with a graphical
9548 environment and networking:
9549
9550 @defvr {Scheme Variable} %desktop-services
9551 This is a list of services that builds upon @var{%base-services} and
9552 adds or adjusts services for a typical ``desktop'' setup.
9553
9554 In particular, it adds a graphical login manager (@pxref{X Window,
9555 @code{slim-service}}), screen lockers,
9556 a network management tool (@pxref{Networking
9557 Services, @code{wicd-service}}), energy and color management services,
9558 the @code{elogind} login and seat manager, the Polkit privilege service,
9559 the GeoClue location service, an NTP client (@pxref{Networking
9560 Services}), the Avahi daemon, and has the name service switch service
9561 configured to be able to use @code{nss-mdns} (@pxref{Name Service
9562 Switch, mDNS}).
9563 @end defvr
9564
9565 The @var{%desktop-services} variable can be used as the @code{services}
9566 field of an @code{operating-system} declaration (@pxref{operating-system
9567 Reference, @code{services}}).
9568
9569 Additionally, the @code{gnome-desktop-service} and
9570 @code{xfce-desktop-service} procedures can add GNOME and/or XFCE to a
9571 system. To ``add GNOME'' means that system-level services like the
9572 backlight adjustment helpers and the power management utilities are
9573 added to the system, extending @code{polkit} and @code{dbus}
9574 appropriately, allowing GNOME to operate with elevated privileges on a
9575 limited number of special-purpose system interfaces. Additionally,
9576 adding a service made by @code{gnome-desktop-service} adds the GNOME
9577 metapackage to the system profile. Likewise, adding the XFCE service
9578 not only adds the @code{xfce} metapackage to the system profile, but it
9579 also gives the Thunar file manager the ability to open a ``root-mode''
9580 file management window, if the user authenticates using the
9581 administrator's password via the standard polkit graphical interface.
9582
9583 @deffn {Scheme Procedure} gnome-desktop-service
9584 Return a service that adds the @code{gnome} package to the system
9585 profile, and extends polkit with the actions from
9586 @code{gnome-settings-daemon}.
9587 @end deffn
9588
9589 @deffn {Scheme Procedure} xfce-desktop-service
9590 Return a service that adds the @code{xfce} package to the system profile,
9591 and extends polkit with the ability for @code{thunar} to manipulate the
9592 file system as root from within a user session, after the user has
9593 authenticated with the administrator's password.
9594 @end deffn
9595
9596 Because the GNOME and XFCE desktop services pull in so many packages,
9597 the default @code{%desktop-services} variable doesn't include either of
9598 them by default. To add GNOME or XFCE, just @code{cons} them onto
9599 @code{%desktop-services} in the @code{services} field of your
9600 @code{operating-system}:
9601
9602 @example
9603 (use-modules (gnu))
9604 (use-service-modules desktop)
9605 (operating-system
9606 ...
9607 ;; cons* adds items to the list given as its last argument.
9608 (services (cons* (gnome-desktop-service)
9609 (xfce-desktop-service)
9610 %desktop-services))
9611 ...)
9612 @end example
9613
9614 These desktop environments will then be available as options in the
9615 graphical login window.
9616
9617 The actual service definitions included in @code{%desktop-services} and
9618 provided by @code{(gnu services dbus)} and @code{(gnu services desktop)}
9619 are described below.
9620
9621 @deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
9622 Return a service that runs the ``system bus'', using @var{dbus}, with
9623 support for @var{services}.
9624
9625 @uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
9626 facility. Its system bus is used to allow system services to communicate
9627 and to be notified of system-wide events.
9628
9629 @var{services} must be a list of packages that provide an
9630 @file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
9631 and policy files. For example, to allow avahi-daemon to use the system bus,
9632 @var{services} must be equal to @code{(list avahi)}.
9633 @end deffn
9634
9635 @deffn {Scheme Procedure} elogind-service [#:config @var{config}]
9636 Return a service that runs the @code{elogind} login and
9637 seat management daemon. @uref{https://github.com/andywingo/elogind,
9638 Elogind} exposes a D-Bus interface that can be used to know which users
9639 are logged in, know what kind of sessions they have open, suspend the
9640 system, inhibit system suspend, reboot the system, and other tasks.
9641
9642 Elogind handles most system-level power events for a computer, for
9643 example suspending the system when a lid is closed, or shutting it down
9644 when the power button is pressed.
9645
9646 The @var{config} keyword argument specifies the configuration for
9647 elogind, and should be the result of an @code{(elogind-configuration
9648 (@var{parameter} @var{value})...)} invocation. Available parameters and
9649 their default values are:
9650
9651 @table @code
9652 @item kill-user-processes?
9653 @code{#f}
9654 @item kill-only-users
9655 @code{()}
9656 @item kill-exclude-users
9657 @code{("root")}
9658 @item inhibit-delay-max-seconds
9659 @code{5}
9660 @item handle-power-key
9661 @code{poweroff}
9662 @item handle-suspend-key
9663 @code{suspend}
9664 @item handle-hibernate-key
9665 @code{hibernate}
9666 @item handle-lid-switch
9667 @code{suspend}
9668 @item handle-lid-switch-docked
9669 @code{ignore}
9670 @item power-key-ignore-inhibited?
9671 @code{#f}
9672 @item suspend-key-ignore-inhibited?
9673 @code{#f}
9674 @item hibernate-key-ignore-inhibited?
9675 @code{#f}
9676 @item lid-switch-ignore-inhibited?
9677 @code{#t}
9678 @item holdoff-timeout-seconds
9679 @code{30}
9680 @item idle-action
9681 @code{ignore}
9682 @item idle-action-seconds
9683 @code{(* 30 60)}
9684 @item runtime-directory-size-percent
9685 @code{10}
9686 @item runtime-directory-size
9687 @code{#f}
9688 @item remove-ipc?
9689 @code{#t}
9690 @item suspend-state
9691 @code{("mem" "standby" "freeze")}
9692 @item suspend-mode
9693 @code{()}
9694 @item hibernate-state
9695 @code{("disk")}
9696 @item hibernate-mode
9697 @code{("platform" "shutdown")}
9698 @item hybrid-sleep-state
9699 @code{("disk")}
9700 @item hybrid-sleep-mode
9701 @code{("suspend" "platform" "shutdown")}
9702 @end table
9703 @end deffn
9704
9705 @deffn {Scheme Procedure} polkit-service @
9706 [#:polkit @var{polkit}]
9707 Return a service that runs the
9708 @uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
9709 management service}, which allows system administrators to grant access to
9710 privileged operations in a structured way. By querying the Polkit service, a
9711 privileged system component can know when it should grant additional
9712 capabilities to ordinary users. For example, an ordinary user can be granted
9713 the capability to suspend the system if the user is logged in locally.
9714 @end deffn
9715
9716 @deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
9717 [#:watts-up-pro? #f] @
9718 [#:poll-batteries? #t] @
9719 [#:ignore-lid? #f] @
9720 [#:use-percentage-for-policy? #f] @
9721 [#:percentage-low 10] @
9722 [#:percentage-critical 3] @
9723 [#:percentage-action 2] @
9724 [#:time-low 1200] @
9725 [#:time-critical 300] @
9726 [#:time-action 120] @
9727 [#:critical-power-action 'hybrid-sleep]
9728 Return a service that runs @uref{http://upower.freedesktop.org/,
9729 @command{upowerd}}, a system-wide monitor for power consumption and battery
9730 levels, with the given configuration settings. It implements the
9731 @code{org.freedesktop.UPower} D-Bus interface, and is notably used by
9732 GNOME.
9733 @end deffn
9734
9735 @deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
9736 Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
9737 UDisks}, a @dfn{disk management} daemon that provides user interfaces with
9738 notifications and ways to mount/unmount disks. Programs that talk to UDisks
9739 include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
9740 @end deffn
9741
9742 @deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
9743 Return a service that runs @command{colord}, a system service with a D-Bus
9744 interface to manage the color profiles of input and output devices such as
9745 screens and scanners. It is notably used by the GNOME Color Manager graphical
9746 tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
9747 site} for more information.
9748 @end deffn
9749
9750 @deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
9751 Return a configuration allowing an application to access GeoClue
9752 location data. @var{name} is the Desktop ID of the application, without
9753 the @code{.desktop} part. If @var{allowed?} is true, the application
9754 will have access to location information by default. The boolean
9755 @var{system?} value indicates whether an application is a system component
9756 or not. Finally @var{users} is a list of UIDs of all users for which
9757 this application is allowed location info access. An empty users list
9758 means that all users are allowed.
9759 @end deffn
9760
9761 @defvr {Scheme Variable} %standard-geoclue-applications
9762 The standard list of well-known GeoClue application configurations,
9763 granting authority to the GNOME date-and-time utility to ask for the
9764 current location in order to set the time zone, and allowing the
9765 IceCat and Epiphany web browsers to request location information.
9766 IceCat and Epiphany both query the user before allowing a web page to
9767 know the user's location.
9768 @end defvr
9769
9770 @deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
9771 [#:whitelist '()] @
9772 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
9773 [#:submit-data? #f]
9774 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
9775 [#:submission-nick "geoclue"] @
9776 [#:applications %standard-geoclue-applications]
9777 Return a service that runs the GeoClue location service. This service
9778 provides a D-Bus interface to allow applications to request access to a
9779 user's physical location, and optionally to add information to online
9780 location databases. See
9781 @uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
9782 web site} for more information.
9783 @end deffn
9784
9785 @deffn {Scheme Procedure} bluetooth-service [#:bluez @var{bluez}]
9786 Return a service that runs the @command{bluetoothd} daemon, which manages
9787 all the Bluetooth devices and provides a number of D-Bus interfaces.
9788
9789 Users need to be in the @code{lp} group to access the D-Bus service.
9790 @end deffn
9791
9792 @node Database Services
9793 @subsubsection Database Services
9794
9795 The @code{(gnu services databases)} module provides the following services.
9796
9797 @deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
9798 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
9799 Return a service that runs @var{postgresql}, the PostgreSQL database
9800 server.
9801
9802 The PostgreSQL daemon loads its runtime configuration from
9803 @var{config-file} and stores the database cluster in
9804 @var{data-directory}.
9805 @end deffn
9806
9807 @deffn {Scheme Procedure} mysql-service [#:config (mysql-configuration)]
9808 Return a service that runs @command{mysqld}, the MySQL or MariaDB
9809 database server.
9810
9811 The optional @var{config} argument specifies the configuration for
9812 @command{mysqld}, which should be a @code{<mysql-configuraiton>} object.
9813 @end deffn
9814
9815 @deftp {Data Type} mysql-configuration
9816 Data type representing the configuration of @var{mysql-service}.
9817
9818 @table @asis
9819 @item @code{mysql} (default: @var{mariadb})
9820 Package object of the MySQL database server, can be either @var{mariadb}
9821 or @var{mysql}.
9822
9823 For MySQL, a temporary root password will be displayed at activation time.
9824 For MariaDB, the root password is empty.
9825 @end table
9826 @end deftp
9827
9828 @node Mail Services
9829 @subsubsection Mail Services
9830
9831 The @code{(gnu services mail)} module provides Guix service definitions
9832 for mail services. Currently the only implemented service is Dovecot,
9833 an IMAP, POP3, and LMTP server.
9834
9835 Guix does not yet have a mail transfer agent (MTA), although for some
9836 lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
9837 is needed to properly integrate a full MTA, such as Postfix. Patches
9838 welcome!
9839
9840 To add an IMAP/POP3 server to a GuixSD system, add a
9841 @code{dovecot-service} to the operating system definition:
9842
9843 @deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
9844 Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
9845 @end deffn
9846
9847 By default, Dovecot does not need much configuration; the default
9848 configuration object created by @code{(dovecot-configuration)} will
9849 suffice if your mail is delivered to @code{~/Maildir}. A self-signed
9850 certificate will be generated for TLS-protected connections, though
9851 Dovecot will also listen on cleartext ports by default. There are a
9852 number of options, though, which mail administrators might need to change,
9853 and as is the case with other services, Guix allows the system
9854 administrator to specify these parameters via a uniform Scheme interface.
9855
9856 For example, to specify that mail is located at @code{maildir~/.mail},
9857 one would instantiate the Dovecot service like this:
9858
9859 @example
9860 (dovecot-service #:config
9861 (dovecot-configuration
9862 (mail-location "maildir:~/.mail")))
9863 @end example
9864
9865 The available configuration parameters follow. Each parameter
9866 definition is preceded by its type; for example, @samp{string-list foo}
9867 indicates that the @code{foo} parameter should be specified as a list of
9868 strings. There is also a way to specify the configuration as a string,
9869 if you have an old @code{dovecot.conf} file that you want to port over
9870 from some other system; see the end for more details.
9871
9872 @c The following documentation was initially generated by
9873 @c (generate-documentation) in (gnu services mail). Manually maintained
9874 @c documentation is better, so we shouldn't hesitate to edit below as
9875 @c needed. However if the change you want to make to this documentation
9876 @c can be done in an automated way, it's probably easier to change
9877 @c (generate-documentation) than to make it below and have to deal with
9878 @c the churn as dovecot updates.
9879
9880 Available @code{dovecot-configuration} fields are:
9881
9882 @deftypevr {@code{dovecot-configuration} parameter} package dovecot
9883 The dovecot package.
9884 @end deftypevr
9885
9886 @deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
9887 A list of IPs or hosts where to listen for connections. @samp{*}
9888 listens on all IPv4 interfaces, @samp{::} listens on all IPv6
9889 interfaces. If you want to specify non-default ports or anything more
9890 complex, customize the address and port fields of the
9891 @samp{inet-listener} of the specific services you are interested in.
9892 @end deftypevr
9893
9894 @deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
9895 List of protocols we want to serve. Available protocols include
9896 @samp{imap}, @samp{pop3}, and @samp{lmtp}.
9897
9898 Available @code{protocol-configuration} fields are:
9899
9900 @deftypevr {@code{protocol-configuration} parameter} string name
9901 The name of the protocol.
9902 @end deftypevr
9903
9904 @deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
9905 UNIX socket path to the master authentication server to find users.
9906 This is used by imap (for shared users) and lda.
9907 It defaults to @samp{"/var/run/dovecot/auth-userdb"}.
9908 @end deftypevr
9909
9910 @deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
9911 Space separated list of plugins to load.
9912 @end deftypevr
9913
9914 @deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
9915 Maximum number of IMAP connections allowed for a user from each IP
9916 address. NOTE: The username is compared case-sensitively.
9917 Defaults to @samp{10}.
9918 @end deftypevr
9919
9920 @end deftypevr
9921
9922 @deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
9923 List of services to enable. Available services include @samp{imap},
9924 @samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
9925 @samp{lmtp}.
9926
9927 Available @code{service-configuration} fields are:
9928
9929 @deftypevr {@code{service-configuration} parameter} string kind
9930 The service kind. Valid values include @code{director},
9931 @code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
9932 @code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
9933 @code{tcpwrap}, @code{quota-warning}, or anything else.
9934 @end deftypevr
9935
9936 @deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
9937 Listeners for the service. A listener is either a
9938 @code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
9939 an @code{inet-listener-configuration}.
9940 Defaults to @samp{()}.
9941
9942 Available @code{unix-listener-configuration} fields are:
9943
9944 @deftypevr {@code{unix-listener-configuration} parameter} file-name path
9945 The file name on which to listen.
9946 @end deftypevr
9947
9948 @deftypevr {@code{unix-listener-configuration} parameter} string mode
9949 The access mode for the socket.
9950 Defaults to @samp{"0600"}.
9951 @end deftypevr
9952
9953 @deftypevr {@code{unix-listener-configuration} parameter} string user
9954 The user to own the socket.
9955 Defaults to @samp{""}.
9956 @end deftypevr
9957
9958 @deftypevr {@code{unix-listener-configuration} parameter} string group
9959 The group to own the socket.
9960 Defaults to @samp{""}.
9961 @end deftypevr
9962
9963
9964 Available @code{fifo-listener-configuration} fields are:
9965
9966 @deftypevr {@code{fifo-listener-configuration} parameter} file-name path
9967 The file name on which to listen.
9968 @end deftypevr
9969
9970 @deftypevr {@code{fifo-listener-configuration} parameter} string mode
9971 The access mode for the socket.
9972 Defaults to @samp{"0600"}.
9973 @end deftypevr
9974
9975 @deftypevr {@code{fifo-listener-configuration} parameter} string user
9976 The user to own the socket.
9977 Defaults to @samp{""}.
9978 @end deftypevr
9979
9980 @deftypevr {@code{fifo-listener-configuration} parameter} string group
9981 The group to own the socket.
9982 Defaults to @samp{""}.
9983 @end deftypevr
9984
9985
9986 Available @code{inet-listener-configuration} fields are:
9987
9988 @deftypevr {@code{inet-listener-configuration} parameter} string protocol
9989 The protocol to listen for.
9990 @end deftypevr
9991
9992 @deftypevr {@code{inet-listener-configuration} parameter} string address
9993 The address on which to listen, or empty for all addresses.
9994 Defaults to @samp{""}.
9995 @end deftypevr
9996
9997 @deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
9998 The port on which to listen.
9999 @end deftypevr
10000
10001 @deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
10002 Whether to use SSL for this service; @samp{yes}, @samp{no}, or
10003 @samp{required}.
10004 Defaults to @samp{#t}.
10005 @end deftypevr
10006
10007 @end deftypevr
10008
10009 @deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
10010 Number of connections to handle before starting a new process.
10011 Typically the only useful values are 0 (unlimited) or 1. 1 is more
10012 secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
10013 Defaults to @samp{1}.
10014 @end deftypevr
10015
10016 @deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
10017 Number of processes to always keep waiting for more connections.
10018 Defaults to @samp{0}.
10019 @end deftypevr
10020
10021 @deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
10022 If you set @samp{service-count 0}, you probably need to grow
10023 this.
10024 Defaults to @samp{256000000}.
10025 @end deftypevr
10026
10027 @end deftypevr
10028
10029 @deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
10030 Dict configuration, as created by the @code{dict-configuration}
10031 constructor.
10032
10033 Available @code{dict-configuration} fields are:
10034
10035 @deftypevr {@code{dict-configuration} parameter} free-form-fields entries
10036 A list of key-value pairs that this dict should hold.
10037 Defaults to @samp{()}.
10038 @end deftypevr
10039
10040 @end deftypevr
10041
10042 @deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
10043 A list of passdb configurations, each one created by the
10044 @code{passdb-configuration} constructor.
10045
10046 Available @code{passdb-configuration} fields are:
10047
10048 @deftypevr {@code{passdb-configuration} parameter} string driver
10049 The driver that the passdb should use. Valid values include
10050 @samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
10051 @samp{static}.
10052 Defaults to @samp{"pam"}.
10053 @end deftypevr
10054
10055 @deftypevr {@code{passdb-configuration} parameter} free-form-args args
10056 A list of key-value args to the passdb driver.
10057 Defaults to @samp{()}.
10058 @end deftypevr
10059
10060 @end deftypevr
10061
10062 @deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
10063 List of userdb configurations, each one created by the
10064 @code{userdb-configuration} constructor.
10065
10066 Available @code{userdb-configuration} fields are:
10067
10068 @deftypevr {@code{userdb-configuration} parameter} string driver
10069 The driver that the userdb should use. Valid values include
10070 @samp{passwd} and @samp{static}.
10071 Defaults to @samp{"passwd"}.
10072 @end deftypevr
10073
10074 @deftypevr {@code{userdb-configuration} parameter} free-form-args args
10075 A list of key-value args to the userdb driver.
10076 Defaults to @samp{()}.
10077 @end deftypevr
10078
10079 @deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
10080 Override fields from passwd.
10081 Defaults to @samp{()}.
10082 @end deftypevr
10083
10084 @end deftypevr
10085
10086 @deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
10087 Plug-in configuration, created by the @code{plugin-configuration}
10088 constructor.
10089 @end deftypevr
10090
10091 @deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
10092 List of namespaces. Each item in the list is created by the
10093 @code{namespace-configuration} constructor.
10094
10095 Available @code{namespace-configuration} fields are:
10096
10097 @deftypevr {@code{namespace-configuration} parameter} string name
10098 Name for this namespace.
10099 @end deftypevr
10100
10101 @deftypevr {@code{namespace-configuration} parameter} string type
10102 Namespace type: @samp{private}, @samp{shared} or @samp{public}.
10103 Defaults to @samp{"private"}.
10104 @end deftypevr
10105
10106 @deftypevr {@code{namespace-configuration} parameter} string separator
10107 Hierarchy separator to use. You should use the same separator for
10108 all namespaces or some clients get confused. @samp{/} is usually a good
10109 one. The default however depends on the underlying mail storage
10110 format.
10111 Defaults to @samp{""}.
10112 @end deftypevr
10113
10114 @deftypevr {@code{namespace-configuration} parameter} string prefix
10115 Prefix required to access this namespace. This needs to be
10116 different for all namespaces. For example @samp{Public/}.
10117 Defaults to @samp{""}.
10118 @end deftypevr
10119
10120 @deftypevr {@code{namespace-configuration} parameter} string location
10121 Physical location of the mailbox. This is in the same format as
10122 mail_location, which is also the default for it.
10123 Defaults to @samp{""}.
10124 @end deftypevr
10125
10126 @deftypevr {@code{namespace-configuration} parameter} boolean inbox?
10127 There can be only one INBOX, and this setting defines which
10128 namespace has it.
10129 Defaults to @samp{#f}.
10130 @end deftypevr
10131
10132 @deftypevr {@code{namespace-configuration} parameter} boolean hidden?
10133 If namespace is hidden, it's not advertised to clients via NAMESPACE
10134 extension. You'll most likely also want to set @samp{list? #f}. This is mostly
10135 useful when converting from another server with different namespaces
10136 which you want to deprecate but still keep working. For example you can
10137 create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
10138 and @samp{mail/}.
10139 Defaults to @samp{#f}.
10140 @end deftypevr
10141
10142 @deftypevr {@code{namespace-configuration} parameter} boolean list?
10143 Show the mailboxes under this namespace with the LIST command. This
10144 makes the namespace visible for clients that do not support the NAMESPACE
10145 extension. The special @code{children} value lists child mailboxes, but
10146 hides the namespace prefix.
10147 Defaults to @samp{#t}.
10148 @end deftypevr
10149
10150 @deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
10151 Namespace handles its own subscriptions. If set to @code{#f}, the
10152 parent namespace handles them. The empty prefix should always have this
10153 as @code{#t}).
10154 Defaults to @samp{#t}.
10155 @end deftypevr
10156
10157 @deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
10158 List of predefined mailboxes in this namespace.
10159 Defaults to @samp{()}.
10160
10161 Available @code{mailbox-configuration} fields are:
10162
10163 @deftypevr {@code{mailbox-configuration} parameter} string name
10164 Name for this mailbox.
10165 @end deftypevr
10166
10167 @deftypevr {@code{mailbox-configuration} parameter} string auto
10168 @samp{create} will automatically create this mailbox.
10169 @samp{subscribe} will both create and subscribe to the mailbox.
10170 Defaults to @samp{"no"}.
10171 @end deftypevr
10172
10173 @deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
10174 List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
10175 Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
10176 @code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
10177 Defaults to @samp{()}.
10178 @end deftypevr
10179
10180 @end deftypevr
10181
10182 @end deftypevr
10183
10184 @deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
10185 Base directory where to store runtime data.
10186 Defaults to @samp{"/var/run/dovecot/"}.
10187 @end deftypevr
10188
10189 @deftypevr {@code{dovecot-configuration} parameter} string login-greeting
10190 Greeting message for clients.
10191 Defaults to @samp{"Dovecot ready."}.
10192 @end deftypevr
10193
10194 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
10195 List of trusted network ranges. Connections from these IPs are
10196 allowed to override their IP addresses and ports (for logging and for
10197 authentication checks). @samp{disable-plaintext-auth} is also ignored
10198 for these networks. Typically you would specify your IMAP proxy servers
10199 here.
10200 Defaults to @samp{()}.
10201 @end deftypevr
10202
10203 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
10204 List of login access check sockets (e.g. tcpwrap).
10205 Defaults to @samp{()}.
10206 @end deftypevr
10207
10208 @deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
10209 Show more verbose process titles (in ps). Currently shows user name
10210 and IP address. Useful for seeing who is actually using the IMAP
10211 processes (e.g. shared mailboxes or if the same uid is used for multiple
10212 accounts).
10213 Defaults to @samp{#f}.
10214 @end deftypevr
10215
10216 @deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
10217 Should all processes be killed when Dovecot master process shuts down.
10218 Setting this to @code{#f} means that Dovecot can be upgraded without
10219 forcing existing client connections to close (although that could also
10220 be a problem if the upgrade is e.g. due to a security fix).
10221 Defaults to @samp{#t}.
10222 @end deftypevr
10223
10224 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
10225 If non-zero, run mail commands via this many connections to doveadm
10226 server, instead of running them directly in the same process.
10227 Defaults to @samp{0}.
10228 @end deftypevr
10229
10230 @deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
10231 UNIX socket or host:port used for connecting to doveadm server.
10232 Defaults to @samp{"doveadm-server"}.
10233 @end deftypevr
10234
10235 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
10236 List of environment variables that are preserved on Dovecot startup
10237 and passed down to all of its child processes. You can also give
10238 key=value pairs to always set specific settings.
10239 @end deftypevr
10240
10241 @deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
10242 Disable LOGIN command and all other plaintext authentications unless
10243 SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
10244 matches the local IP (i.e. you're connecting from the same computer),
10245 the connection is considered secure and plaintext authentication is
10246 allowed. See also ssl=required setting.
10247 Defaults to @samp{#t}.
10248 @end deftypevr
10249
10250 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
10251 Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
10252 Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
10253 for caching to be used.
10254 Defaults to @samp{0}.
10255 @end deftypevr
10256
10257 @deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
10258 Time to live for cached data. After TTL expires the cached record
10259 is no longer used, *except* if the main database lookup returns internal
10260 failure. We also try to handle password changes automatically: If
10261 user's previous authentication was successful, but this one wasn't, the
10262 cache isn't used. For now this works only with plaintext
10263 authentication.
10264 Defaults to @samp{"1 hour"}.
10265 @end deftypevr
10266
10267 @deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
10268 TTL for negative hits (user not found, password mismatch).
10269 0 disables caching them completely.
10270 Defaults to @samp{"1 hour"}.
10271 @end deftypevr
10272
10273 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
10274 List of realms for SASL authentication mechanisms that need them.
10275 You can leave it empty if you don't want to support multiple realms.
10276 Many clients simply use the first one listed here, so keep the default
10277 realm first.
10278 Defaults to @samp{()}.
10279 @end deftypevr
10280
10281 @deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
10282 Default realm/domain to use if none was specified. This is used for
10283 both SASL realms and appending @@domain to username in plaintext
10284 logins.
10285 Defaults to @samp{""}.
10286 @end deftypevr
10287
10288 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
10289 List of allowed characters in username. If the user-given username
10290 contains a character not listed in here, the login automatically fails.
10291 This is just an extra check to make sure user can't exploit any
10292 potential quote escaping vulnerabilities with SQL/LDAP databases. If
10293 you want to allow all characters, set this value to empty.
10294 Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
10295 @end deftypevr
10296
10297 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
10298 Username character translations before it's looked up from
10299 databases. The value contains series of from -> to characters. For
10300 example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
10301 translated to @samp{@@}.
10302 Defaults to @samp{""}.
10303 @end deftypevr
10304
10305 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
10306 Username formatting before it's looked up from databases. You can
10307 use the standard variables here, e.g. %Lu would lowercase the username,
10308 %n would drop away the domain if it was given, or @samp{%n-AT-%d} would
10309 change the @samp{@@} into @samp{-AT-}. This translation is done after
10310 @samp{auth-username-translation} changes.
10311 Defaults to @samp{"%Lu"}.
10312 @end deftypevr
10313
10314 @deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
10315 If you want to allow master users to log in by specifying the master
10316 username within the normal username string (i.e. not using SASL
10317 mechanism's support for it), you can specify the separator character
10318 here. The format is then <username><separator><master username>.
10319 UW-IMAP uses @samp{*} as the separator, so that could be a good
10320 choice.
10321 Defaults to @samp{""}.
10322 @end deftypevr
10323
10324 @deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
10325 Username to use for users logging in with ANONYMOUS SASL
10326 mechanism.
10327 Defaults to @samp{"anonymous"}.
10328 @end deftypevr
10329
10330 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
10331 Maximum number of dovecot-auth worker processes. They're used to
10332 execute blocking passdb and userdb queries (e.g. MySQL and PAM).
10333 They're automatically created and destroyed as needed.
10334 Defaults to @samp{30}.
10335 @end deftypevr
10336
10337 @deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
10338 Host name to use in GSSAPI principal names. The default is to use
10339 the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
10340 allow all keytab entries.
10341 Defaults to @samp{""}.
10342 @end deftypevr
10343
10344 @deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
10345 Kerberos keytab to use for the GSSAPI mechanism. Will use the
10346 system default (usually /etc/krb5.keytab) if not specified. You may
10347 need to change the auth service to run as root to be able to read this
10348 file.
10349 Defaults to @samp{""}.
10350 @end deftypevr
10351
10352 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
10353 Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
10354 and @samp{ntlm-auth} helper.
10355 <doc/wiki/Authentication/Mechanisms/Winbind.txt>.
10356 Defaults to @samp{#f}.
10357 @end deftypevr
10358
10359 @deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
10360 Path for Samba's @samp{ntlm-auth} helper binary.
10361 Defaults to @samp{"/usr/bin/ntlm_auth"}.
10362 @end deftypevr
10363
10364 @deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
10365 Time to delay before replying to failed authentications.
10366 Defaults to @samp{"2 secs"}.
10367 @end deftypevr
10368
10369 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
10370 Require a valid SSL client certificate or the authentication
10371 fails.
10372 Defaults to @samp{#f}.
10373 @end deftypevr
10374
10375 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
10376 Take the username from client's SSL certificate, using
10377 @code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
10378 CommonName.
10379 Defaults to @samp{#f}.
10380 @end deftypevr
10381
10382 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
10383 List of wanted authentication mechanisms. Supported mechanisms are:
10384 @samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
10385 @samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
10386 @samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
10387 @samp{disable-plaintext-auth} setting.
10388 @end deftypevr
10389
10390 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
10391 List of IPs or hostnames to all director servers, including ourself.
10392 Ports can be specified as ip:port. The default port is the same as what
10393 director service's @samp{inet-listener} is using.
10394 Defaults to @samp{()}.
10395 @end deftypevr
10396
10397 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
10398 List of IPs or hostnames to all backend mail servers. Ranges are
10399 allowed too, like 10.0.0.10-10.0.0.30.
10400 Defaults to @samp{()}.
10401 @end deftypevr
10402
10403 @deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
10404 How long to redirect users to a specific server after it no longer
10405 has any connections.
10406 Defaults to @samp{"15 min"}.
10407 @end deftypevr
10408
10409 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
10410 TCP/IP port that accepts doveadm connections (instead of director
10411 connections) If you enable this, you'll also need to add
10412 @samp{inet-listener} for the port.
10413 Defaults to @samp{0}.
10414 @end deftypevr
10415
10416 @deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
10417 How the username is translated before being hashed. Useful values
10418 include %Ln if user can log in with or without @@domain, %Ld if mailboxes
10419 are shared within domain.
10420 Defaults to @samp{"%Lu"}.
10421 @end deftypevr
10422
10423 @deftypevr {@code{dovecot-configuration} parameter} string log-path
10424 Log file to use for error messages. @samp{syslog} logs to syslog,
10425 @samp{/dev/stderr} logs to stderr.
10426 Defaults to @samp{"syslog"}.
10427 @end deftypevr
10428
10429 @deftypevr {@code{dovecot-configuration} parameter} string info-log-path
10430 Log file to use for informational messages. Defaults to
10431 @samp{log-path}.
10432 Defaults to @samp{""}.
10433 @end deftypevr
10434
10435 @deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
10436 Log file to use for debug messages. Defaults to
10437 @samp{info-log-path}.
10438 Defaults to @samp{""}.
10439 @end deftypevr
10440
10441 @deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
10442 Syslog facility to use if you're logging to syslog. Usually if you
10443 don't want to use @samp{mail}, you'll use local0..local7. Also other
10444 standard facilities are supported.
10445 Defaults to @samp{"mail"}.
10446 @end deftypevr
10447
10448 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
10449 Log unsuccessful authentication attempts and the reasons why they
10450 failed.
10451 Defaults to @samp{#f}.
10452 @end deftypevr
10453
10454 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
10455 In case of password mismatches, log the attempted password. Valid
10456 values are no, plain and sha1. sha1 can be useful for detecting brute
10457 force password attempts vs. user simply trying the same password over
10458 and over again. You can also truncate the value to n chars by appending
10459 ":n" (e.g. sha1:6).
10460 Defaults to @samp{#f}.
10461 @end deftypevr
10462
10463 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
10464 Even more verbose logging for debugging purposes. Shows for example
10465 SQL queries.
10466 Defaults to @samp{#f}.
10467 @end deftypevr
10468
10469 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
10470 In case of password mismatches, log the passwords and used scheme so
10471 the problem can be debugged. Enabling this also enables
10472 @samp{auth-debug}.
10473 Defaults to @samp{#f}.
10474 @end deftypevr
10475
10476 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
10477 Enable mail process debugging. This can help you figure out why
10478 Dovecot isn't finding your mails.
10479 Defaults to @samp{#f}.
10480 @end deftypevr
10481
10482 @deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
10483 Show protocol level SSL errors.
10484 Defaults to @samp{#f}.
10485 @end deftypevr
10486
10487 @deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
10488 Prefix for each line written to log file. % codes are in
10489 strftime(3) format.
10490 Defaults to @samp{"\"%b %d %H:%M:%S \""}.
10491 @end deftypevr
10492
10493 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
10494 List of elements we want to log. The elements which have a
10495 non-empty variable value are joined together to form a comma-separated
10496 string.
10497 @end deftypevr
10498
10499 @deftypevr {@code{dovecot-configuration} parameter} string login-log-format
10500 Login log format. %s contains @samp{login-log-format-elements}
10501 string, %$ contains the data we want to log.
10502 Defaults to @samp{"%$: %s"}.
10503 @end deftypevr
10504
10505 @deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
10506 Log prefix for mail processes. See doc/wiki/Variables.txt for list
10507 of possible variables you can use.
10508 Defaults to @samp{"\"%s(%u): \""}.
10509 @end deftypevr
10510
10511 @deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
10512 Format to use for logging mail deliveries. You can use variables:
10513 @table @code
10514 @item %$
10515 Delivery status message (e.g. @samp{saved to INBOX})
10516 @item %m
10517 Message-ID
10518 @item %s
10519 Subject
10520 @item %f
10521 From address
10522 @item %p
10523 Physical size
10524 @item %w
10525 Virtual size.
10526 @end table
10527 Defaults to @samp{"msgid=%m: %$"}.
10528 @end deftypevr
10529
10530 @deftypevr {@code{dovecot-configuration} parameter} string mail-location
10531 Location for users' mailboxes. The default is empty, which means
10532 that Dovecot tries to find the mailboxes automatically. This won't work
10533 if the user doesn't yet have any mail, so you should explicitly tell
10534 Dovecot the full location.
10535
10536 If you're using mbox, giving a path to the INBOX
10537 file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
10538 where the other mailboxes are kept. This is called the "root mail
10539 directory", and it must be the first path given in the
10540 @samp{mail-location} setting.
10541
10542 There are a few special variables you can use, eg.:
10543
10544 @table @samp
10545 @item %u
10546 username
10547 @item %n
10548 user part in user@@domain, same as %u if there's no domain
10549 @item %d
10550 domain part in user@@domain, empty if there's no domain
10551 @item %h
10552 home director
10553 @end table
10554
10555 See doc/wiki/Variables.txt for full list. Some examples:
10556 @table @samp
10557 @item maildir:~/Maildir
10558 @item mbox:~/mail:INBOX=/var/mail/%u
10559 @item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
10560 @end table
10561 Defaults to @samp{""}.
10562 @end deftypevr
10563
10564 @deftypevr {@code{dovecot-configuration} parameter} string mail-uid
10565 System user and group used to access mails. If you use multiple,
10566 userdb can override these by returning uid or gid fields. You can use
10567 either numbers or names. <doc/wiki/UserIds.txt>.
10568 Defaults to @samp{""}.
10569 @end deftypevr
10570
10571 @deftypevr {@code{dovecot-configuration} parameter} string mail-gid
10572
10573 Defaults to @samp{""}.
10574 @end deftypevr
10575
10576 @deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
10577 Group to enable temporarily for privileged operations. Currently
10578 this is used only with INBOX when either its initial creation or
10579 dotlocking fails. Typically this is set to "mail" to give access to
10580 /var/mail.
10581 Defaults to @samp{""}.
10582 @end deftypevr
10583
10584 @deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
10585 Grant access to these supplementary groups for mail processes.
10586 Typically these are used to set up access to shared mailboxes. Note
10587 that it may be dangerous to set these if users can create
10588 symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
10589 could allow a user to delete others' mailboxes, or ln -s
10590 /secret/shared/box ~/mail/mybox would allow reading it).
10591 Defaults to @samp{""}.
10592 @end deftypevr
10593
10594 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
10595 Allow full file system access to clients. There's no access checks
10596 other than what the operating system does for the active UID/GID. It
10597 works with both maildir and mboxes, allowing you to prefix mailboxes
10598 names with e.g. /path/ or ~user/.
10599 Defaults to @samp{#f}.
10600 @end deftypevr
10601
10602 @deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
10603 Don't use mmap() at all. This is required if you store indexes to
10604 shared file systems (NFS or clustered file system).
10605 Defaults to @samp{#f}.
10606 @end deftypevr
10607
10608 @deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
10609 Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
10610 supports @samp{O_EXCL} since version 3, so this should be safe to use
10611 nowadays by default.
10612 Defaults to @samp{#t}.
10613 @end deftypevr
10614
10615 @deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
10616 When to use fsync() or fdatasync() calls:
10617 @table @code
10618 @item optimized
10619 Whenever necessary to avoid losing important data
10620 @item always
10621 Useful with e.g. NFS when write()s are delayed
10622 @item never
10623 Never use it (best performance, but crashes can lose data).
10624 @end table
10625 Defaults to @samp{"optimized"}.
10626 @end deftypevr
10627
10628 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
10629 Mail storage exists in NFS. Set this to yes to make Dovecot flush
10630 NFS caches whenever needed. If you're using only a single mail server
10631 this isn't needed.
10632 Defaults to @samp{#f}.
10633 @end deftypevr
10634
10635 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
10636 Mail index files also exist in NFS. Setting this to yes requires
10637 @samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
10638 Defaults to @samp{#f}.
10639 @end deftypevr
10640
10641 @deftypevr {@code{dovecot-configuration} parameter} string lock-method
10642 Locking method for index files. Alternatives are fcntl, flock and
10643 dotlock. Dotlocking uses some tricks which may create more disk I/O
10644 than other locking methods. NFS users: flock doesn't work, remember to
10645 change @samp{mmap-disable}.
10646 Defaults to @samp{"fcntl"}.
10647 @end deftypevr
10648
10649 @deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
10650 Directory in which LDA/LMTP temporarily stores incoming mails >128
10651 kB.
10652 Defaults to @samp{"/tmp"}.
10653 @end deftypevr
10654
10655 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
10656 Valid UID range for users. This is mostly to make sure that users can't
10657 log in as daemons or other system users. Note that denying root logins is
10658 hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
10659 is set to 0.
10660 Defaults to @samp{500}.
10661 @end deftypevr
10662
10663 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
10664
10665 Defaults to @samp{0}.
10666 @end deftypevr
10667
10668 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
10669 Valid GID range for users. Users having non-valid GID as primary group ID
10670 aren't allowed to log in. If user belongs to supplementary groups with
10671 non-valid GIDs, those groups are not set.
10672 Defaults to @samp{1}.
10673 @end deftypevr
10674
10675 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
10676
10677 Defaults to @samp{0}.
10678 @end deftypevr
10679
10680 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
10681 Maximum allowed length for mail keyword name. It's only forced when
10682 trying to create new keywords.
10683 Defaults to @samp{50}.
10684 @end deftypevr
10685
10686 @deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
10687 List of directories under which chrooting is allowed for mail
10688 processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
10689 too). This setting doesn't affect @samp{login-chroot}
10690 @samp{mail-chroot} or auth chroot settings. If this setting is empty,
10691 "/./" in home dirs are ignored. WARNING: Never add directories here
10692 which local users can modify, that may lead to root exploit. Usually
10693 this should be done only if you don't allow shell access for users.
10694 <doc/wiki/Chrooting.txt>.
10695 Defaults to @samp{()}.
10696 @end deftypevr
10697
10698 @deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
10699 Default chroot directory for mail processes. This can be overridden
10700 for specific users in user database by giving /./ in user's home
10701 directory (e.g. /home/./user chroots into /home). Note that usually
10702 there is no real need to do chrooting, Dovecot doesn't allow users to
10703 access files outside their mail directory anyway. If your home
10704 directories are prefixed with the chroot directory, append "/." to
10705 @samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
10706 Defaults to @samp{""}.
10707 @end deftypevr
10708
10709 @deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
10710 UNIX socket path to master authentication server to find users.
10711 This is used by imap (for shared users) and lda.
10712 Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
10713 @end deftypevr
10714
10715 @deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
10716 Directory where to look up mail plugins.
10717 Defaults to @samp{"/usr/lib/dovecot"}.
10718 @end deftypevr
10719
10720 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
10721 List of plugins to load for all services. Plugins specific to IMAP,
10722 LDA, etc. are added to this list in their own .conf files.
10723 Defaults to @samp{()}.
10724 @end deftypevr
10725
10726 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
10727 The minimum number of mails in a mailbox before updates are done to
10728 cache file. This allows optimizing Dovecot's behavior to do less disk
10729 writes at the cost of more disk reads.
10730 Defaults to @samp{0}.
10731 @end deftypevr
10732
10733 @deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
10734 When IDLE command is running, mailbox is checked once in a while to
10735 see if there are any new mails or other changes. This setting defines
10736 the minimum time to wait between those checks. Dovecot can also use
10737 dnotify, inotify and kqueue to find out immediately when changes
10738 occur.
10739 Defaults to @samp{"30 secs"}.
10740 @end deftypevr
10741
10742 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
10743 Save mails with CR+LF instead of plain LF. This makes sending those
10744 mails take less CPU, especially with sendfile() syscall with Linux and
10745 FreeBSD. But it also creates a bit more disk I/O which may just make it
10746 slower. Also note that if other software reads the mboxes/maildirs,
10747 they may handle the extra CRs wrong and cause problems.
10748 Defaults to @samp{#f}.
10749 @end deftypevr
10750
10751 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
10752 By default LIST command returns all entries in maildir beginning
10753 with a dot. Enabling this option makes Dovecot return only entries
10754 which are directories. This is done by stat()ing each entry, so it
10755 causes more disk I/O.
10756 (For systems setting struct @samp{dirent->d_type} this check is free
10757 and it's done always regardless of this setting).
10758 Defaults to @samp{#f}.
10759 @end deftypevr
10760
10761 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
10762 When copying a message, do it with hard links whenever possible.
10763 This makes the performance much better, and it's unlikely to have any
10764 side effects.
10765 Defaults to @samp{#t}.
10766 @end deftypevr
10767
10768 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
10769 Assume Dovecot is the only MUA accessing Maildir: Scan cur/
10770 directory only when its mtime changes unexpectedly or when we can't find
10771 the mail otherwise.
10772 Defaults to @samp{#f}.
10773 @end deftypevr
10774
10775 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
10776 Which locking methods to use for locking mbox. There are four
10777 available:
10778
10779 @table @code
10780 @item dotlock
10781 Create <mailbox>.lock file. This is the oldest and most NFS-safe
10782 solution. If you want to use /var/mail/ like directory, the users will
10783 need write access to that directory.
10784 @item dotlock-try
10785 Same as dotlock, but if it fails because of permissions or because there
10786 isn't enough disk space, just skip it.
10787 @item fcntl
10788 Use this if possible. Works with NFS too if lockd is used.
10789 @item flock
10790 May not exist in all systems. Doesn't work with NFS.
10791 @item lockf
10792 May not exist in all systems. Doesn't work with NFS.
10793 @end table
10794
10795 You can use multiple locking methods; if you do the order they're declared
10796 in is important to avoid deadlocks if other MTAs/MUAs are using multiple
10797 locking methods as well. Some operating systems don't allow using some of
10798 them simultaneously.
10799 @end deftypevr
10800
10801 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
10802
10803 @end deftypevr
10804
10805 @deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
10806 Maximum time to wait for lock (all of them) before aborting.
10807 Defaults to @samp{"5 mins"}.
10808 @end deftypevr
10809
10810 @deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
10811 If dotlock exists but the mailbox isn't modified in any way,
10812 override the lock file after this much time.
10813 Defaults to @samp{"2 mins"}.
10814 @end deftypevr
10815
10816 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
10817 When mbox changes unexpectedly we have to fully read it to find out
10818 what changed. If the mbox is large this can take a long time. Since
10819 the change is usually just a newly appended mail, it'd be faster to
10820 simply read the new mails. If this setting is enabled, Dovecot does
10821 this but still safely fallbacks to re-reading the whole mbox file
10822 whenever something in mbox isn't how it's expected to be. The only real
10823 downside to this setting is that if some other MUA changes message
10824 flags, Dovecot doesn't notice it immediately. Note that a full sync is
10825 done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
10826 Defaults to @samp{#t}.
10827 @end deftypevr
10828
10829 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
10830 Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
10831 EXAMINE, EXPUNGE or CHECK commands. If this is set,
10832 @samp{mbox-dirty-syncs} is ignored.
10833 Defaults to @samp{#f}.
10834 @end deftypevr
10835
10836 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
10837 Delay writing mbox headers until doing a full write sync (EXPUNGE
10838 and CHECK commands and when closing the mailbox). This is especially
10839 useful for POP3 where clients often delete all mails. The downside is
10840 that our changes aren't immediately visible to other MUAs.
10841 Defaults to @samp{#t}.
10842 @end deftypevr
10843
10844 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
10845 If mbox size is smaller than this (e.g. 100k), don't write index
10846 files. If an index file already exists it's still read, just not
10847 updated.
10848 Defaults to @samp{0}.
10849 @end deftypevr
10850
10851 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
10852 Maximum dbox file size until it's rotated.
10853 Defaults to @samp{2000000}.
10854 @end deftypevr
10855
10856 @deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
10857 Maximum dbox file age until it's rotated. Typically in days. Day
10858 begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
10859 disabled.
10860 Defaults to @samp{"1d"}.
10861 @end deftypevr
10862
10863 @deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
10864 When creating new mdbox files, immediately preallocate their size to
10865 @samp{mdbox-rotate-size}. This setting currently works only in Linux
10866 with some file systems (ext4, xfs).
10867 Defaults to @samp{#f}.
10868 @end deftypevr
10869
10870 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
10871 sdbox and mdbox support saving mail attachments to external files,
10872 which also allows single instance storage for them. Other backends
10873 don't support this for now.
10874
10875 WARNING: This feature hasn't been tested much yet. Use at your own risk.
10876
10877 Directory root where to store mail attachments. Disabled, if empty.
10878 Defaults to @samp{""}.
10879 @end deftypevr
10880
10881 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
10882 Attachments smaller than this aren't saved externally. It's also
10883 possible to write a plugin to disable saving specific attachments
10884 externally.
10885 Defaults to @samp{128000}.
10886 @end deftypevr
10887
10888 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
10889 File system backend to use for saving attachments:
10890 @table @code
10891 @item posix
10892 No SiS done by Dovecot (but this might help FS's own deduplication)
10893 @item sis posix
10894 SiS with immediate byte-by-byte comparison during saving
10895 @item sis-queue posix
10896 SiS with delayed comparison and deduplication.
10897 @end table
10898 Defaults to @samp{"sis posix"}.
10899 @end deftypevr
10900
10901 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
10902 Hash format to use in attachment filenames. You can add any text and
10903 variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
10904 @code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
10905 truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
10906 Defaults to @samp{"%@{sha1@}"}.
10907 @end deftypevr
10908
10909 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
10910
10911 Defaults to @samp{100}.
10912 @end deftypevr
10913
10914 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
10915
10916 Defaults to @samp{1000}.
10917 @end deftypevr
10918
10919 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
10920 Default VSZ (virtual memory size) limit for service processes.
10921 This is mainly intended to catch and kill processes that leak memory
10922 before they eat up everything.
10923 Defaults to @samp{256000000}.
10924 @end deftypevr
10925
10926 @deftypevr {@code{dovecot-configuration} parameter} string default-login-user
10927 Login user is internally used by login processes. This is the most
10928 untrusted user in Dovecot system. It shouldn't have access to anything
10929 at all.
10930 Defaults to @samp{"dovenull"}.
10931 @end deftypevr
10932
10933 @deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
10934 Internal user is used by unprivileged processes. It should be
10935 separate from login user, so that login processes can't disturb other
10936 processes.
10937 Defaults to @samp{"dovecot"}.
10938 @end deftypevr
10939
10940 @deftypevr {@code{dovecot-configuration} parameter} string ssl?
10941 SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
10942 Defaults to @samp{"required"}.
10943 @end deftypevr
10944
10945 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
10946 PEM encoded X.509 SSL/TLS certificate (public key).
10947 Defaults to @samp{"</etc/dovecot/default.pem"}.
10948 @end deftypevr
10949
10950 @deftypevr {@code{dovecot-configuration} parameter} string ssl-key
10951 PEM encoded SSL/TLS private key. The key is opened before
10952 dropping root privileges, so keep the key file unreadable by anyone but
10953 root.
10954 Defaults to @samp{"</etc/dovecot/private/default.pem"}.
10955 @end deftypevr
10956
10957 @deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
10958 If key file is password protected, give the password here.
10959 Alternatively give it when starting dovecot with -p parameter. Since
10960 this file is often world-readable, you may want to place this setting
10961 instead to a different.
10962 Defaults to @samp{""}.
10963 @end deftypevr
10964
10965 @deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
10966 PEM encoded trusted certificate authority. Set this only if you
10967 intend to use @samp{ssl-verify-client-cert? #t}. The file should
10968 contain the CA certificate(s) followed by the matching
10969 CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
10970 Defaults to @samp{""}.
10971 @end deftypevr
10972
10973 @deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
10974 Require that CRL check succeeds for client certificates.
10975 Defaults to @samp{#t}.
10976 @end deftypevr
10977
10978 @deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
10979 Request client to send a certificate. If you also want to require
10980 it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
10981 Defaults to @samp{#f}.
10982 @end deftypevr
10983
10984 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
10985 Which field from certificate to use for username. commonName and
10986 x500UniqueIdentifier are the usual choices. You'll also need to set
10987 @samp{auth-ssl-username-from-cert? #t}.
10988 Defaults to @samp{"commonName"}.
10989 @end deftypevr
10990
10991 @deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
10992 How often to regenerate the SSL parameters file. Generation is
10993 quite CPU intensive operation. The value is in hours, 0 disables
10994 regeneration entirely.
10995 Defaults to @samp{168}.
10996 @end deftypevr
10997
10998 @deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
10999 SSL protocols to use.
11000 Defaults to @samp{"!SSLv2"}.
11001 @end deftypevr
11002
11003 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
11004 SSL ciphers to use.
11005 Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
11006 @end deftypevr
11007
11008 @deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
11009 SSL crypto device to use, for valid values run "openssl engine".
11010 Defaults to @samp{""}.
11011 @end deftypevr
11012
11013 @deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
11014 Address to use when sending rejection mails.
11015 %d expands to recipient domain.
11016 Defaults to @samp{"postmaster@@%d"}.
11017 @end deftypevr
11018
11019 @deftypevr {@code{dovecot-configuration} parameter} string hostname
11020 Hostname to use in various parts of sent mails (e.g. in Message-Id)
11021 and in LMTP replies. Default is the system's real hostname@@domain.
11022 Defaults to @samp{""}.
11023 @end deftypevr
11024
11025 @deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
11026 If user is over quota, return with temporary failure instead of
11027 bouncing the mail.
11028 Defaults to @samp{#f}.
11029 @end deftypevr
11030
11031 @deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
11032 Binary to use for sending mails.
11033 Defaults to @samp{"/usr/sbin/sendmail"}.
11034 @end deftypevr
11035
11036 @deftypevr {@code{dovecot-configuration} parameter} string submission-host
11037 If non-empty, send mails via this SMTP host[:port] instead of
11038 sendmail.
11039 Defaults to @samp{""}.
11040 @end deftypevr
11041
11042 @deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
11043 Subject: header to use for rejection mails. You can use the same
11044 variables as for @samp{rejection-reason} below.
11045 Defaults to @samp{"Rejected: %s"}.
11046 @end deftypevr
11047
11048 @deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
11049 Human readable error message for rejection mails. You can use
11050 variables:
11051
11052 @table @code
11053 @item %n
11054 CRLF
11055 @item %r
11056 reason
11057 @item %s
11058 original subject
11059 @item %t
11060 recipient
11061 @end table
11062 Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
11063 @end deftypevr
11064
11065 @deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
11066 Delimiter character between local-part and detail in email
11067 address.
11068 Defaults to @samp{"+"}.
11069 @end deftypevr
11070
11071 @deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
11072 Header where the original recipient address (SMTP's RCPT TO:
11073 address) is taken from if not available elsewhere. With dovecot-lda -a
11074 parameter overrides this. A commonly used header for this is
11075 X-Original-To.
11076 Defaults to @samp{""}.
11077 @end deftypevr
11078
11079 @deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
11080 Should saving a mail to a nonexistent mailbox automatically create
11081 it?.
11082 Defaults to @samp{#f}.
11083 @end deftypevr
11084
11085 @deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
11086 Should automatically created mailboxes be also automatically
11087 subscribed?.
11088 Defaults to @samp{#f}.
11089 @end deftypevr
11090
11091 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
11092 Maximum IMAP command line length. Some clients generate very long
11093 command lines with huge mailboxes, so you may need to raise this if you
11094 get "Too long argument" or "IMAP command line too large" errors
11095 often.
11096 Defaults to @samp{64000}.
11097 @end deftypevr
11098
11099 @deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
11100 IMAP logout format string:
11101 @table @code
11102 @item %i
11103 total number of bytes read from client
11104 @item %o
11105 total number of bytes sent to client.
11106 @end table
11107 Defaults to @samp{"in=%i out=%o"}.
11108 @end deftypevr
11109
11110 @deftypevr {@code{dovecot-configuration} parameter} string imap-capability
11111 Override the IMAP CAPABILITY response. If the value begins with '+',
11112 add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
11113 Defaults to @samp{""}.
11114 @end deftypevr
11115
11116 @deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
11117 How long to wait between "OK Still here" notifications when client
11118 is IDLEing.
11119 Defaults to @samp{"2 mins"}.
11120 @end deftypevr
11121
11122 @deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
11123 ID field names and values to send to clients. Using * as the value
11124 makes Dovecot use the default value. The following fields have default
11125 values currently: name, version, os, os-version, support-url,
11126 support-email.
11127 Defaults to @samp{""}.
11128 @end deftypevr
11129
11130 @deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
11131 ID fields sent by client to log. * means everything.
11132 Defaults to @samp{""}.
11133 @end deftypevr
11134
11135 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
11136 Workarounds for various client bugs:
11137
11138 @table @code
11139 @item delay-newmail
11140 Send EXISTS/RECENT new mail notifications only when replying to NOOP and
11141 CHECK commands. Some clients ignore them otherwise, for example OSX
11142 Mail (<v2.1). Outlook Express breaks more badly though, without this it
11143 may show user "Message no longer in server" errors. Note that OE6
11144 still breaks even with this workaround if synchronization is set to
11145 "Headers Only".
11146
11147 @item tb-extra-mailbox-sep
11148 Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
11149 adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
11150 ignore the extra @samp{/} instead of treating it as invalid mailbox name.
11151
11152 @item tb-lsub-flags
11153 Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
11154 This makes Thunderbird realize they aren't selectable and show them
11155 greyed out, instead of only later giving "not selectable" popup error.
11156 @end table
11157 Defaults to @samp{()}.
11158 @end deftypevr
11159
11160 @deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
11161 Host allowed in URLAUTH URLs sent by client. "*" allows all.
11162 Defaults to @samp{""}.
11163 @end deftypevr
11164
11165
11166 Whew! Lots of configuration options. The nice thing about it though is
11167 that GuixSD has a complete interface to Dovecot's configuration
11168 language. This allows not only a nice way to declare configurations,
11169 but also offers reflective capabilities as well: users can write code to
11170 inspect and transform configurations from within Scheme.
11171
11172 However, it could be that you just want to get a @code{dovecot.conf} up
11173 and running. In that case, you can pass an
11174 @code{opaque-dovecot-configuration} as the @code{#:config} parameter to
11175 @code{dovecot-service}. As its name indicates, an opaque configuration
11176 does not have easy reflective capabilities.
11177
11178 Available @code{opaque-dovecot-configuration} fields are:
11179
11180 @deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
11181 The dovecot package.
11182 @end deftypevr
11183
11184 @deftypevr {@code{opaque-dovecot-configuration} parameter} string string
11185 The contents of the @code{dovecot.conf}, as a string.
11186 @end deftypevr
11187
11188 For example, if your @code{dovecot.conf} is just the empty string, you
11189 could instantiate a dovecot service like this:
11190
11191 @example
11192 (dovecot-service #:config
11193 (opaque-dovecot-configuration
11194 (string "")))
11195 @end example
11196
11197 @node Web Services
11198 @subsubsection Web Services
11199
11200 The @code{(gnu services web)} module provides the following service:
11201
11202 @deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
11203 [#:log-directory ``/var/log/nginx''] @
11204 [#:run-directory ``/var/run/nginx''] @
11205 [#:config-file]
11206
11207 Return a service that runs @var{nginx}, the nginx web server.
11208
11209 The nginx daemon loads its runtime configuration from @var{config-file}.
11210 Log files are written to @var{log-directory} and temporary runtime data
11211 files are written to @var{run-directory}. For proper operation, these
11212 arguments should match what is in @var{config-file} to ensure that the
11213 directories are created when the service is activated.
11214
11215 @end deffn
11216
11217 @node Network File System
11218 @subsubsection Network File System
11219 @cindex NFS
11220
11221 The @code{(gnu services nfs)} module provides the following services,
11222 which are most commonly used in relation to mounting or exporting
11223 directory trees as @dfn{network file systems} (NFS).
11224
11225 @subsubheading RPC Bind Service
11226 @cindex rpcbind
11227
11228 The RPC Bind service provides a facility to map program numbers into
11229 universal addresses.
11230 Many NFS related services use this facility. Hence it is automatically
11231 started when a dependent service starts.
11232
11233 @defvr {Scheme Variable} rpcbind-service-type
11234 A service type for the RPC portmapper daemon.
11235 @end defvr
11236
11237
11238 @deftp {Data Type} rpcbind-configuration
11239 Data type representing the configuration of the RPC Bind Service.
11240 This type has the following parameters:
11241 @table @asis
11242 @item @code{rpcbind} (default: @code{rpcbind})
11243 The rpcbind package to use.
11244
11245 @item @code{warm-start?} (default: @code{#t})
11246 If this parameter is @code{#t}, then the daemon will read a
11247 state file on startup thus reloading state information saved by a previous
11248 instance.
11249 @end table
11250 @end deftp
11251
11252
11253 @subsubheading Pipefs Pseudo File System
11254 @cindex pipefs
11255 @cindex rpc_pipefs
11256
11257 The pipefs file system is used to transfer NFS related data
11258 between the kernel and user space programs.
11259
11260 @defvr {Scheme Variable} pipefs-service-type
11261 A service type for the pipefs pseudo file system.
11262 @end defvr
11263
11264 @deftp {Data Type} pipefs-configuration
11265 Data type representing the configuration of the pipefs pseudo file system service.
11266 This type has the following parameters:
11267 @table @asis
11268 @item @code{mount-point} (default: @code{"/var/lib/nfs/rpc_pipefs"})
11269 The directory to which the file system is to be attached.
11270 @end table
11271 @end deftp
11272
11273
11274 @subsubheading GSS Daemon Service
11275 @cindex GSSD
11276 @cindex GSS
11277 @cindex global security system
11278
11279 The @dfn{global security system} (GSS) daemon provides strong security for RPC
11280 based protocols.
11281 Before exchanging RPC requests an RPC client must establish a security
11282 context. Typically this is done using the Kerberos command @command{kinit}
11283 or automatically at login time using PAM services.
11284
11285 @defvr {Scheme Variable} gss-service-type
11286 A service type for the Global Security System (GSS) daemon.
11287 @end defvr
11288
11289 @deftp {Data Type} gss-configuration
11290 Data type representing the configuration of the GSS daemon service.
11291 This type has the following parameters:
11292 @table @asis
11293 @item @code{nfs-utils} (default: @code{nfs-utils})
11294 The package in which the @command{rpc.gssd} command is to be found.
11295
11296 @item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
11297 The directory where the pipefs file system is mounted.
11298
11299 @end table
11300 @end deftp
11301
11302
11303 @subsubheading IDMAP Daemon Service
11304 @cindex idmapd
11305 @cindex name mapper
11306
11307 The idmap daemon service provides mapping between user IDs and user names.
11308 Typically it is required in order to access file systems mounted via NFSv4.
11309
11310 @defvr {Scheme Variable} idmap-service-type
11311 A service type for the Identity Mapper (IDMAP) daemon.
11312 @end defvr
11313
11314 @deftp {Data Type} idmap-configuration
11315 Data type representing the configuration of the IDMAP daemon service.
11316 This type has the following parameters:
11317 @table @asis
11318 @item @code{nfs-utils} (default: @code{nfs-utils})
11319 The package in which the @command{rpc.idmapd} command is to be found.
11320
11321 @item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
11322 The directory where the pipefs file system is mounted.
11323
11324 @item @code{domain} (default: @code{#f})
11325 The local NFSv4 domain name.
11326 This must be a string or @code{#f}.
11327 If it is @code{#f} then the daemon will use the host's fully qualified domain name.
11328
11329 @end table
11330 @end deftp
11331
11332
11333 @node Miscellaneous Services
11334 @subsubsection Miscellaneous Services
11335
11336
11337 @cindex lirc
11338 @subsubheading Lirc Service
11339
11340 The @code{(gnu services lirc)} module provides the following service.
11341
11342 @deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
11343 [#:device #f] [#:driver #f] [#:config-file #f] @
11344 [#:extra-options '()]
11345 Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
11346 decodes infrared signals from remote controls.
11347
11348 Optionally, @var{device}, @var{driver} and @var{config-file}
11349 (configuration file name) may be specified. See @command{lircd} manual
11350 for details.
11351
11352 Finally, @var{extra-options} is a list of additional command-line options
11353 passed to @command{lircd}.
11354 @end deffn
11355
11356 @cindex spice
11357 @subsubheading Spice Service
11358
11359 The @code{(gnu services spice)} module provides the following service.
11360
11361 @deffn {Scheme Procedure} spice-vdagent-service [#:spice-vdagent]
11362 Returns a service that runs @url{http://www.spice-space.org,VDAGENT}, a daemon
11363 that enables sharing the clipboard with a vm and setting the guest display
11364 resolution when the graphical console window resizes.
11365 @end deffn
11366
11367 @subsubsection Dictionary Services
11368 The @code{(gnu services dict)} module provides the following service:
11369
11370 @deffn {Scheme Procedure} dicod-service [#:config (dicod-configuration)]
11371 Return a service that runs the @command{dicod} daemon, an implementation
11372 of DICT server (@pxref{Dicod,,, dico, GNU Dico Manual}).
11373
11374 The optional @var{config} argument specifies the configuration for
11375 @command{dicod}, which should be a @code{<dicod-configuration>} object, by
11376 default it serves the GNU Collaborative International Dictonary of English.
11377
11378 You can add @command{open localhost} to your @file{~/.dico} file to make
11379 @code{localhost} the default server for @command{dico} client
11380 (@pxref{Initialization File,,, dico, GNU Dico Manual}).
11381 @end deffn
11382
11383 @deftp {Data Type} dicod-configuration
11384 Data type representing the configuration of dicod.
11385
11386 @table @asis
11387 @item @code{dico} (default: @var{dico})
11388 Package object of the GNU Dico dictionary server.
11389
11390 @item @code{interfaces} (default: @var{'("localhost")})
11391 This is the list of IP addresses and ports and possibly socket file
11392 names to listen to (@pxref{Server Settings, @code{listen} directive,,
11393 dico, GNU Dico Manual}).
11394
11395 @item @code{databases} (default: @var{(list %dicod-database:gcide)})
11396 List of @code{<dicod-database>} objects denoting dictionaries to be served.
11397 @end table
11398 @end deftp
11399
11400 @deftp {Data Type} dicod-database
11401 Data type representing a dictionary database.
11402
11403 @table @asis
11404 @item @code{name}
11405 Name of the database, will be used in DICT commands.
11406
11407 @item @code{module}
11408 Name of the dicod module used by this database
11409 (@pxref{Modules,,, dico, GNU Dico Manual}).
11410
11411 @item @code{options}
11412 List of strings or gexps representing the arguments for the module handler
11413 (@pxref{Handlers,,, dico, GNU Dico Manual}).
11414 @end table
11415 @end deftp
11416
11417 @defvr {Scheme Variable} %dicod-database:gcide
11418 A @code{<dicod-database>} object serving the GNU Collaborative International
11419 Dictonary of English using the @code{gcide} package.
11420 @end defvr
11421
11422 @node Setuid Programs
11423 @subsection Setuid Programs
11424
11425 @cindex setuid programs
11426 Some programs need to run with ``root'' privileges, even when they are
11427 launched by unprivileged users. A notorious example is the
11428 @command{passwd} program, which users can run to change their
11429 password, and which needs to access the @file{/etc/passwd} and
11430 @file{/etc/shadow} files---something normally restricted to root, for
11431 obvious security reasons. To address that, these executables are
11432 @dfn{setuid-root}, meaning that they always run with root privileges
11433 (@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
11434 for more info about the setuid mechanism.)
11435
11436 The store itself @emph{cannot} contain setuid programs: that would be a
11437 security issue since any user on the system can write derivations that
11438 populate the store (@pxref{The Store}). Thus, a different mechanism is
11439 used: instead of changing the setuid bit directly on files that are in
11440 the store, we let the system administrator @emph{declare} which programs
11441 should be setuid root.
11442
11443 The @code{setuid-programs} field of an @code{operating-system}
11444 declaration contains a list of G-expressions denoting the names of
11445 programs to be setuid-root (@pxref{Using the Configuration System}).
11446 For instance, the @command{passwd} program, which is part of the Shadow
11447 package, can be designated by this G-expression (@pxref{G-Expressions}):
11448
11449 @example
11450 #~(string-append #$shadow "/bin/passwd")
11451 @end example
11452
11453 A default set of setuid programs is defined by the
11454 @code{%setuid-programs} variable of the @code{(gnu system)} module.
11455
11456 @defvr {Scheme Variable} %setuid-programs
11457 A list of G-expressions denoting common programs that are setuid-root.
11458
11459 The list includes commands such as @command{passwd}, @command{ping},
11460 @command{su}, and @command{sudo}.
11461 @end defvr
11462
11463 Under the hood, the actual setuid programs are created in the
11464 @file{/run/setuid-programs} directory at system activation time. The
11465 files in this directory refer to the ``real'' binaries, which are in the
11466 store.
11467
11468 @node X.509 Certificates
11469 @subsection X.509 Certificates
11470
11471 @cindex HTTPS, certificates
11472 @cindex X.509 certificates
11473 @cindex TLS
11474 Web servers available over HTTPS (that is, HTTP over the transport-layer
11475 security mechanism, TLS) send client programs an @dfn{X.509 certificate}
11476 that the client can then use to @emph{authenticate} the server. To do
11477 that, clients verify that the server's certificate is signed by a
11478 so-called @dfn{certificate authority} (CA). But to verify the CA's
11479 signature, clients must have first acquired the CA's certificate.
11480
11481 Web browsers such as GNU@tie{}IceCat include their own set of CA
11482 certificates, such that they are able to verify CA signatures
11483 out-of-the-box.
11484
11485 However, most other programs that can talk HTTPS---@command{wget},
11486 @command{git}, @command{w3m}, etc.---need to be told where CA
11487 certificates can be found.
11488
11489 @cindex @code{nss-certs}
11490 In GuixSD, this is done by adding a package that provides certificates
11491 to the @code{packages} field of the @code{operating-system} declaration
11492 (@pxref{operating-system Reference}). GuixSD includes one such package,
11493 @code{nss-certs}, which is a set of CA certificates provided as part of
11494 Mozilla's Network Security Services.
11495
11496 Note that it is @emph{not} part of @var{%base-packages}, so you need to
11497 explicitly add it. The @file{/etc/ssl/certs} directory, which is where
11498 most applications and libraries look for certificates by default, points
11499 to the certificates installed globally.
11500
11501 Unprivileged users, including users of Guix on a foreign distro,
11502 can also install their own certificate package in
11503 their profile. A number of environment variables need to be defined so
11504 that applications and libraries know where to find them. Namely, the
11505 OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
11506 variables. Some applications add their own environment variables; for
11507 instance, the Git version control system honors the certificate bundle
11508 pointed to by the @code{GIT_SSL_CAINFO} environment variable. Thus, you
11509 would typically run something like:
11510
11511 @example
11512 $ guix package -i nss-certs
11513 $ export SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs"
11514 $ export SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt"
11515 $ export GIT_SSL_CAINFO="$SSL_CERT_FILE"
11516 @end example
11517
11518 @node Name Service Switch
11519 @subsection Name Service Switch
11520
11521 @cindex name service switch
11522 @cindex NSS
11523 The @code{(gnu system nss)} module provides bindings to the
11524 configuration file of the libc @dfn{name service switch} or @dfn{NSS}
11525 (@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
11526 Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
11527 extended with new ``name'' lookup methods for system databases, which
11528 includes host names, service names, user accounts, and more (@pxref{Name
11529 Service Switch, System Databases and Name Service Switch,, libc, The GNU
11530 C Library Reference Manual}).
11531
11532 The NSS configuration specifies, for each system database, which lookup
11533 method is to be used, and how the various methods are chained
11534 together---for instance, under which circumstances NSS should try the
11535 next method in the list. The NSS configuration is given in the
11536 @code{name-service-switch} field of @code{operating-system} declarations
11537 (@pxref{operating-system Reference, @code{name-service-switch}}).
11538
11539 @cindex nss-mdns
11540 @cindex .local, host name lookup
11541 As an example, the declaration below configures the NSS to use the
11542 @uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
11543 back-end}, which supports host name lookups over multicast DNS (mDNS)
11544 for host names ending in @code{.local}:
11545
11546 @example
11547 (name-service-switch
11548 (hosts (list %files ;first, check /etc/hosts
11549
11550 ;; If the above did not succeed, try
11551 ;; with 'mdns_minimal'.
11552 (name-service
11553 (name "mdns_minimal")
11554
11555 ;; 'mdns_minimal' is authoritative for
11556 ;; '.local'. When it returns "not found",
11557 ;; no need to try the next methods.
11558 (reaction (lookup-specification
11559 (not-found => return))))
11560
11561 ;; Then fall back to DNS.
11562 (name-service
11563 (name "dns"))
11564
11565 ;; Finally, try with the "full" 'mdns'.
11566 (name-service
11567 (name "mdns")))))
11568 @end example
11569
11570 Do not worry: the @code{%mdns-host-lookup-nss} variable (see below)
11571 contains this configuration, so you will not have to type it if all you
11572 want is to have @code{.local} host lookup working.
11573
11574 Note that, in this case, in addition to setting the
11575 @code{name-service-switch} of the @code{operating-system} declaration,
11576 you also need to use @code{avahi-service} (@pxref{Networking Services,
11577 @code{avahi-service}}), or @var{%desktop-services}, which includes it
11578 (@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
11579 to the name service cache daemon (@pxref{Base Services,
11580 @code{nscd-service}}).
11581
11582 For convenience, the following variables provide typical NSS
11583 configurations.
11584
11585 @defvr {Scheme Variable} %default-nss
11586 This is the default name service switch configuration, a
11587 @code{name-service-switch} object.
11588 @end defvr
11589
11590 @defvr {Scheme Variable} %mdns-host-lookup-nss
11591 This is the name service switch configuration with support for host name
11592 lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
11593 @end defvr
11594
11595 The reference for name service switch configuration is given below. It
11596 is a direct mapping of the configuration file format of the C library , so
11597 please refer to the C library manual for more information (@pxref{NSS
11598 Configuration File,,, libc, The GNU C Library Reference Manual}).
11599 Compared to the configuration file format of libc NSS, it has the advantage
11600 not only of adding this warm parenthetic feel that we like, but also
11601 static checks: you will know about syntax errors and typos as soon as you
11602 run @command{guix system}.
11603
11604 @deftp {Data Type} name-service-switch
11605
11606 This is the data type representation the configuration of libc's name
11607 service switch (NSS). Each field below represents one of the supported
11608 system databases.
11609
11610 @table @code
11611 @item aliases
11612 @itemx ethers
11613 @itemx group
11614 @itemx gshadow
11615 @itemx hosts
11616 @itemx initgroups
11617 @itemx netgroup
11618 @itemx networks
11619 @itemx password
11620 @itemx public-key
11621 @itemx rpc
11622 @itemx services
11623 @itemx shadow
11624 The system databases handled by the NSS. Each of these fields must be a
11625 list of @code{<name-service>} objects (see below).
11626 @end table
11627 @end deftp
11628
11629 @deftp {Data Type} name-service
11630
11631 This is the data type representing an actual name service and the
11632 associated lookup action.
11633
11634 @table @code
11635 @item name
11636 A string denoting the name service (@pxref{Services in the NSS
11637 configuration,,, libc, The GNU C Library Reference Manual}).
11638
11639 Note that name services listed here must be visible to nscd. This is
11640 achieved by passing the @code{#:name-services} argument to
11641 @code{nscd-service} the list of packages providing the needed name
11642 services (@pxref{Base Services, @code{nscd-service}}).
11643
11644 @item reaction
11645 An action specified using the @code{lookup-specification} macro
11646 (@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
11647 Reference Manual}). For example:
11648
11649 @example
11650 (lookup-specification (unavailable => continue)
11651 (success => return))
11652 @end example
11653 @end table
11654 @end deftp
11655
11656 @node Initial RAM Disk
11657 @subsection Initial RAM Disk
11658
11659 @cindex initial RAM disk (initrd)
11660 @cindex initrd (initial RAM disk)
11661 For bootstrapping purposes, the Linux-Libre kernel is passed an
11662 @dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
11663 root file system as well as an initialization script. The latter is
11664 responsible for mounting the real root file system, and for loading any
11665 kernel modules that may be needed to achieve that.
11666
11667 The @code{initrd} field of an @code{operating-system} declaration allows
11668 you to specify which initrd you would like to use. The @code{(gnu
11669 system linux-initrd)} module provides two ways to build an initrd: the
11670 high-level @code{base-initrd} procedure, and the low-level
11671 @code{expression->initrd} procedure.
11672
11673 The @code{base-initrd} procedure is intended to cover most common uses.
11674 For example, if you want to add a bunch of kernel modules to be loaded
11675 at boot time, you can define the @code{initrd} field of the operating
11676 system declaration like this:
11677
11678 @example
11679 (initrd (lambda (file-systems . rest)
11680 ;; Create a standard initrd that has modules "foo.ko"
11681 ;; and "bar.ko", as well as their dependencies, in
11682 ;; addition to the modules available by default.
11683 (apply base-initrd file-systems
11684 #:extra-modules '("foo" "bar")
11685 rest)))
11686 @end example
11687
11688 The @code{base-initrd} procedure also handles common use cases that
11689 involves using the system as a QEMU guest, or as a ``live'' system with
11690 volatile root file system.
11691
11692 The initial RAM disk produced by @code{base-initrd} honors several
11693 options passed on the Linux kernel command line (that is, arguments
11694 passed @i{via} the @code{linux} command of GRUB, or the
11695 @code{-append} option) of QEMU, notably:
11696
11697 @table @code
11698 @item --load=@var{boot}
11699 Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
11700 program, once it has mounted the root file system.
11701
11702 GuixSD uses this option to yield control to a boot program that runs the
11703 service activation programs and then spawns the GNU@tie{}Shepherd, the
11704 initialization system.
11705
11706 @item --root=@var{root}
11707 Mount @var{root} as the root file system. @var{root} can be a
11708 device name like @code{/dev/sda1}, a partition label, or a partition
11709 UUID.
11710
11711 @item --system=@var{system}
11712 Have @file{/run/booted-system} and @file{/run/current-system} point to
11713 @var{system}.
11714
11715 @item modprobe.blacklist=@var{modules}@dots{}
11716 @cindex module, black-listing
11717 @cindex black list, of kernel modules
11718 Instruct the initial RAM disk as well as the @command{modprobe} command
11719 (from the kmod package) to refuse to load @var{modules}. @var{modules}
11720 must be a comma-separated list of module names---e.g.,
11721 @code{usbkbd,9pnet}.
11722
11723 @item --repl
11724 Start a read-eval-print loop (REPL) from the initial RAM disk before it
11725 tries to load kernel modules and to mount the root file system. Our
11726 marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
11727 love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
11728 Manual}, for more information on Guile's REPL.
11729
11730 @end table
11731
11732 Now that you know all the features that initial RAM disks produced by
11733 @code{base-initrd} provide, here is how to use it and customize it
11734 further.
11735
11736 @deffn {Monadic Procedure} base-initrd @var{file-systems} @
11737 [#:qemu-networking? #f] [#:virtio? #t] [#:volatile-root? #f] @
11738 [#:extra-modules '()] [#:mapped-devices '()]
11739 Return a monadic derivation that builds a generic initrd. @var{file-systems} is
11740 a list of file systems to be mounted by the initrd, possibly in addition to
11741 the root file system specified on the kernel command line via @code{--root}.
11742 @var{mapped-devices} is a list of device mappings to realize before
11743 @var{file-systems} are mounted (@pxref{Mapped Devices}).
11744
11745 When @var{qemu-networking?} is true, set up networking with the standard QEMU
11746 parameters. When @var{virtio?} is true, load additional modules so that the
11747 initrd can be used as a QEMU guest with para-virtualized I/O drivers.
11748
11749 When @var{volatile-root?} is true, the root file system is writable but any changes
11750 to it are lost.
11751
11752 The initrd is automatically populated with all the kernel modules necessary
11753 for @var{file-systems} and for the given options. However, additional kernel
11754 modules can be listed in @var{extra-modules}. They will be added to the initrd, and
11755 loaded at boot time in the order in which they appear.
11756 @end deffn
11757
11758 Needless to say, the initrds we produce and use embed a
11759 statically-linked Guile, and the initialization program is a Guile
11760 program. That gives a lot of flexibility. The
11761 @code{expression->initrd} procedure builds such an initrd, given the
11762 program to run in that initrd.
11763
11764 @deffn {Monadic Procedure} expression->initrd @var{exp} @
11765 [#:guile %guile-static-stripped] [#:name "guile-initrd"]
11766 Return a derivation that builds a Linux initrd (a gzipped cpio archive)
11767 containing @var{guile} and that evaluates @var{exp}, a G-expression,
11768 upon booting. All the derivations referenced by @var{exp} are
11769 automatically copied to the initrd.
11770 @end deffn
11771
11772 @node GRUB Configuration
11773 @subsection GRUB Configuration
11774
11775 @cindex GRUB
11776 @cindex boot loader
11777
11778 The operating system uses GNU@tie{}GRUB as its boot loader
11779 (@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
11780 configured using a @code{grub-configuration} declaration. This data type
11781 is exported by the @code{(gnu system grub)} module and described below.
11782
11783 @deftp {Data Type} grub-configuration
11784 The type of a GRUB configuration declaration.
11785
11786 @table @asis
11787
11788 @item @code{device}
11789 This is a string denoting the boot device. It must be a device name
11790 understood by the @command{grub-install} command, such as
11791 @code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
11792 GNU GRUB Manual}).
11793
11794 @item @code{menu-entries} (default: @code{()})
11795 A possibly empty list of @code{menu-entry} objects (see below), denoting
11796 entries to appear in the GRUB boot menu, in addition to the current
11797 system entry and the entry pointing to previous system generations.
11798
11799 @item @code{default-entry} (default: @code{0})
11800 The index of the default boot menu entry. Index 0 is for the entry of the
11801 current system.
11802
11803 @item @code{timeout} (default: @code{5})
11804 The number of seconds to wait for keyboard input before booting. Set to
11805 0 to boot immediately, and to -1 to wait indefinitely.
11806
11807 @item @code{theme} (default: @var{%default-theme})
11808 The @code{grub-theme} object describing the theme to use.
11809 @end table
11810
11811 @end deftp
11812
11813 @cindex dual boot
11814 @cindex boot menu
11815 Should you want to list additional boot menu entries @i{via} the
11816 @code{menu-entries} field above, you will need to create them with the
11817 @code{menu-entry} form. For example, imagine you want to be able to
11818 boot another distro (hard to imagine!), you can define a menu entry
11819 along these lines:
11820
11821 @example
11822 (menu-entry
11823 (label "The Other Distro")
11824 (linux "/boot/old/vmlinux-2.6.32")
11825 (linux-arguments '("root=/dev/sda2"))
11826 (initrd "/boot/old/initrd"))
11827 @end example
11828
11829 Details below.
11830
11831 @deftp {Data Type} menu-entry
11832 The type of an entry in the GRUB boot menu.
11833
11834 @table @asis
11835
11836 @item @code{label}
11837 The label to show in the menu---e.g., @code{"GNU"}.
11838
11839 @item @code{linux}
11840 The Linux kernel image to boot, for example:
11841
11842 @example
11843 (file-append linux-libre "/bzImage")
11844 @end example
11845
11846 @item @code{linux-arguments} (default: @code{()})
11847 The list of extra Linux kernel command-line arguments---e.g.,
11848 @code{("console=ttyS0")}.
11849
11850 @item @code{initrd}
11851 A G-Expression or string denoting the file name of the initial RAM disk
11852 to use (@pxref{G-Expressions}).
11853
11854 @end table
11855 @end deftp
11856
11857 @c FIXME: Write documentation once it's stable.
11858 Themes are created using the @code{grub-theme} form, which is not
11859 documented yet.
11860
11861 @defvr {Scheme Variable} %default-theme
11862 This is the default GRUB theme used by the operating system, with a
11863 fancy background image displaying the GNU and Guix logos.
11864 @end defvr
11865
11866
11867 @node Invoking guix system
11868 @subsection Invoking @code{guix system}
11869
11870 Once you have written an operating system declaration as seen in the
11871 previous section, it can be @dfn{instantiated} using the @command{guix
11872 system} command. The synopsis is:
11873
11874 @example
11875 guix system @var{options}@dots{} @var{action} @var{file}
11876 @end example
11877
11878 @var{file} must be the name of a file containing an
11879 @code{operating-system} declaration. @var{action} specifies how the
11880 operating system is instantiated. Currently the following values are
11881 supported:
11882
11883 @table @code
11884 @item reconfigure
11885 Build the operating system described in @var{file}, activate it, and
11886 switch to it@footnote{This action is usable only on systems already
11887 running GuixSD.}.
11888
11889 This effects all the configuration specified in @var{file}: user
11890 accounts, system services, global package list, setuid programs, etc.
11891 The command starts system services specified in @var{file} that are not
11892 currently running; if a service is currently running, it does not
11893 attempt to upgrade it since this would not be possible without stopping it
11894 first.
11895
11896 It also adds a GRUB menu entry for the new OS configuration, and moves
11897 entries for older configurations to a submenu---unless
11898 @option{--no-grub} is passed.
11899
11900 @quotation Note
11901 @c The paragraph below refers to the problem discussed at
11902 @c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
11903 It is highly recommended to run @command{guix pull} once before you run
11904 @command{guix system reconfigure} for the first time (@pxref{Invoking
11905 guix pull}). Failing to do that you would see an older version of Guix
11906 once @command{reconfigure} has completed.
11907 @end quotation
11908
11909 @item build
11910 Build the derivation of the operating system, which includes all the
11911 configuration files and programs needed to boot and run the system.
11912 This action does not actually install anything.
11913
11914 @item init
11915 Populate the given directory with all the files necessary to run the
11916 operating system specified in @var{file}. This is useful for first-time
11917 installations of GuixSD. For instance:
11918
11919 @example
11920 guix system init my-os-config.scm /mnt
11921 @end example
11922
11923 copies to @file{/mnt} all the store items required by the configuration
11924 specified in @file{my-os-config.scm}. This includes configuration
11925 files, packages, and so on. It also creates other essential files
11926 needed for the system to operate correctly---e.g., the @file{/etc},
11927 @file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
11928
11929 This command also installs GRUB on the device specified in
11930 @file{my-os-config}, unless the @option{--no-grub} option was passed.
11931
11932 @item vm
11933 @cindex virtual machine
11934 @cindex VM
11935 @anchor{guix system vm}
11936 Build a virtual machine that contains the operating system declared in
11937 @var{file}, and return a script to run that virtual machine (VM).
11938 Arguments given to the script are passed to QEMU.
11939
11940 The VM shares its store with the host system.
11941
11942 Additional file systems can be shared between the host and the VM using
11943 the @code{--share} and @code{--expose} command-line options: the former
11944 specifies a directory to be shared with write access, while the latter
11945 provides read-only access to the shared directory.
11946
11947 The example below creates a VM in which the user's home directory is
11948 accessible read-only, and where the @file{/exchange} directory is a
11949 read-write mapping of @file{$HOME/tmp} on the host:
11950
11951 @example
11952 guix system vm my-config.scm \
11953 --expose=$HOME --share=$HOME/tmp=/exchange
11954 @end example
11955
11956 On GNU/Linux, the default is to boot directly to the kernel; this has
11957 the advantage of requiring only a very tiny root disk image since the
11958 store of the host can then be mounted.
11959
11960 The @code{--full-boot} option forces a complete boot sequence, starting
11961 with the bootloader. This requires more disk space since a root image
11962 containing at least the kernel, initrd, and bootloader data files must
11963 be created. The @code{--image-size} option can be used to specify the
11964 size of the image.
11965
11966 @item vm-image
11967 @itemx disk-image
11968 Return a virtual machine or disk image of the operating system declared
11969 in @var{file} that stands alone. Use the @option{--image-size} option
11970 to specify the size of the image.
11971
11972 When using @code{vm-image}, the returned image is in qcow2 format, which
11973 the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
11974 for more information on how to run the image in a virtual machine.
11975
11976 When using @code{disk-image}, a raw disk image is produced; it can be
11977 copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
11978 the device corresponding to a USB stick, one can copy the image to it
11979 using the following command:
11980
11981 @example
11982 # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
11983 @end example
11984
11985 @item container
11986 Return a script to run the operating system declared in @var{file}
11987 within a container. Containers are a set of lightweight isolation
11988 mechanisms provided by the kernel Linux-libre. Containers are
11989 substantially less resource-demanding than full virtual machines since
11990 the kernel, shared objects, and other resources can be shared with the
11991 host system; this also means they provide thinner isolation.
11992
11993 Currently, the script must be run as root in order to support more than
11994 a single user and group. The container shares its store with the host
11995 system.
11996
11997 As with the @code{vm} action (@pxref{guix system vm}), additional file
11998 systems to be shared between the host and container can be specified
11999 using the @option{--share} and @option{--expose} options:
12000
12001 @example
12002 guix system container my-config.scm \
12003 --expose=$HOME --share=$HOME/tmp=/exchange
12004 @end example
12005
12006 @quotation Note
12007 This option requires Linux-libre 3.19 or newer.
12008 @end quotation
12009
12010 @end table
12011
12012 @var{options} can contain any of the common build options (@pxref{Common
12013 Build Options}). In addition, @var{options} can contain one of the
12014 following:
12015
12016 @table @option
12017 @item --system=@var{system}
12018 @itemx -s @var{system}
12019 Attempt to build for @var{system} instead of the host system type.
12020 This works as per @command{guix build} (@pxref{Invoking guix build}).
12021
12022 @item --derivation
12023 @itemx -d
12024 Return the derivation file name of the given operating system without
12025 building anything.
12026
12027 @item --image-size=@var{size}
12028 For the @code{vm-image} and @code{disk-image} actions, create an image
12029 of the given @var{size}. @var{size} may be a number of bytes, or it may
12030 include a unit as a suffix (@pxref{Block size, size specifications,,
12031 coreutils, GNU Coreutils}).
12032
12033 @item --on-error=@var{strategy}
12034 Apply @var{strategy} when an error occurs when reading @var{file}.
12035 @var{strategy} may be one of the following:
12036
12037 @table @code
12038 @item nothing-special
12039 Report the error concisely and exit. This is the default strategy.
12040
12041 @item backtrace
12042 Likewise, but also display a backtrace.
12043
12044 @item debug
12045 Report the error and enter Guile's debugger. From there, you can run
12046 commands such as @code{,bt} to get a backtrace, @code{,locals} to
12047 display local variable values, and more generally inspect the state of the
12048 program. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
12049 a list of available debugging commands.
12050 @end table
12051 @end table
12052
12053 @quotation Note
12054 All the actions above, except @code{build} and @code{init},
12055 can use KVM support in the Linux-libre kernel. Specifically, if the
12056 machine has hardware virtualization support, the corresponding
12057 KVM kernel module should be loaded, and the @file{/dev/kvm} device node
12058 must exist and be readable and writable by the user and by the
12059 build users of the daemon (@pxref{Build Environment Setup}).
12060 @end quotation
12061
12062 Once you have built, configured, re-configured, and re-re-configured
12063 your GuixSD installation, you may find it useful to list the operating
12064 system generations available on disk---and that you can choose from the
12065 GRUB boot menu:
12066
12067 @table @code
12068
12069 @item list-generations
12070 List a summary of each generation of the operating system available on
12071 disk, in a human-readable way. This is similar to the
12072 @option{--list-generations} option of @command{guix package}
12073 (@pxref{Invoking guix package}).
12074
12075 Optionally, one can specify a pattern, with the same syntax that is used
12076 in @command{guix package --list-generations}, to restrict the list of
12077 generations displayed. For instance, the following command displays
12078 generations that are up to 10 days old:
12079
12080 @example
12081 $ guix system list-generations 10d
12082 @end example
12083
12084 @end table
12085
12086 The @command{guix system} command has even more to offer! The following
12087 sub-commands allow you to visualize how your system services relate to
12088 each other:
12089
12090 @anchor{system-extension-graph}
12091 @table @code
12092
12093 @item extension-graph
12094 Emit in Dot/Graphviz format to standard output the @dfn{service
12095 extension graph} of the operating system defined in @var{file}
12096 (@pxref{Service Composition}, for more information on service
12097 extensions.)
12098
12099 The command:
12100
12101 @example
12102 $ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
12103 @end example
12104
12105 produces a PDF file showing the extension relations among services.
12106
12107 @anchor{system-shepherd-graph}
12108 @item shepherd-graph
12109 Emit in Dot/Graphviz format to standard output the @dfn{dependency
12110 graph} of shepherd services of the operating system defined in
12111 @var{file}. @xref{Shepherd Services}, for more information and for an
12112 example graph.
12113
12114 @end table
12115
12116 @node Running GuixSD in a VM
12117 @subsection Running GuixSD in a Virtual Machine
12118
12119 One way to run GuixSD in a virtual machine (VM) is to build a GuixSD
12120 virtual machine image using @command{guix system vm-image}
12121 (@pxref{Invoking guix system}). The returned image is in qcow2 format,
12122 which the @uref{http://qemu.org/, QEMU emulator} can efficiently use.
12123
12124 To run the image in QEMU, copy it out of the store (@pxref{The Store})
12125 and give yourself permission to write to the copy. When invoking QEMU,
12126 you must choose a system emulator that is suitable for your hardware
12127 platform. Here is a minimal QEMU invocation that will boot the result
12128 of @command{guix system vm-image} on x86_64 hardware:
12129
12130 @example
12131 $ qemu-system-x86_64 \
12132 -net user -net nic,model=virtio \
12133 -enable-kvm -m 256 /tmp/qemu-image
12134 @end example
12135
12136 Here is what each of these options means:
12137
12138 @table @code
12139 @item qemu-system-x86_64
12140 This specifies the hardware platform to emulate. This should match the
12141 host.
12142
12143 @item -net user
12144 Enable the unprivileged user-mode network stack. The guest OS can
12145 access the host but not vice versa. This is the simplest way to get the
12146 guest OS online. If you do not choose a network stack, the boot will
12147 fail.
12148
12149 @item -net nic,model=virtio
12150 You must create a network interface of a given model. If you do not
12151 create a NIC, the boot will fail. Assuming your hardware platform is
12152 x86_64, you can get a list of available NIC models by running
12153 @command{qemu-system-x86_64 -net nic,model=help}.
12154
12155 @item -enable-kvm
12156 If your system has hardware virtualization extensions, enabling the
12157 virtual machine support (KVM) of the Linux kernel will make things run
12158 faster.
12159
12160 @item -m 256
12161 RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
12162 which may be insufficient for some operations.
12163
12164 @item /tmp/qemu-image
12165 The file name of the qcow2 image.
12166 @end table
12167
12168 @node Defining Services
12169 @subsection Defining Services
12170
12171 The previous sections show the available services and how one can combine
12172 them in an @code{operating-system} declaration. But how do we define
12173 them in the first place? And what is a service anyway?
12174
12175 @menu
12176 * Service Composition:: The model for composing services.
12177 * Service Types and Services:: Types and services.
12178 * Service Reference:: API reference.
12179 * Shepherd Services:: A particular type of service.
12180 @end menu
12181
12182 @node Service Composition
12183 @subsubsection Service Composition
12184
12185 @cindex services
12186 @cindex daemons
12187 Here we define a @dfn{service} as, broadly, something that extends the
12188 functionality of the operating system. Often a service is a process---a
12189 @dfn{daemon}---started when the system boots: a secure shell server, a
12190 Web server, the Guix build daemon, etc. Sometimes a service is a daemon
12191 whose execution can be triggered by another daemon---e.g., an FTP server
12192 started by @command{inetd} or a D-Bus service activated by
12193 @command{dbus-daemon}. Occasionally, a service does not map to a
12194 daemon. For instance, the ``account'' service collects user accounts
12195 and makes sure they exist when the system runs; the ``udev'' service
12196 collects device management rules and makes them available to the eudev
12197 daemon; the @file{/etc} service populates the @file{/etc} directory
12198 of the system.
12199
12200 @cindex service extensions
12201 GuixSD services are connected by @dfn{extensions}. For instance, the
12202 secure shell service @emph{extends} the Shepherd---the GuixSD
12203 initialization system, running as PID@tie{}1---by giving it the command
12204 lines to start and stop the secure shell daemon (@pxref{Networking
12205 Services, @code{lsh-service}}); the UPower service extends the D-Bus
12206 service by passing it its @file{.service} specification, and extends the
12207 udev service by passing it device management rules (@pxref{Desktop
12208 Services, @code{upower-service}}); the Guix daemon service extends the
12209 Shepherd by passing it the command lines to start and stop the daemon,
12210 and extends the account service by passing it a list of required build
12211 user accounts (@pxref{Base Services}).
12212
12213 All in all, services and their ``extends'' relations form a directed
12214 acyclic graph (DAG). If we represent services as boxes and extensions
12215 as arrows, a typical system might provide something like this:
12216
12217 @image{images/service-graph,,5in,Typical service extension graph.}
12218
12219 @cindex system service
12220 At the bottom, we see the @dfn{system service}, which produces the
12221 directory containing everything to run and boot the system, as returned
12222 by the @command{guix system build} command. @xref{Service Reference},
12223 to learn about the other service types shown here.
12224 @xref{system-extension-graph, the @command{guix system extension-graph}
12225 command}, for information on how to generate this representation for a
12226 particular operating system definition.
12227
12228 @cindex service types
12229 Technically, developers can define @dfn{service types} to express these
12230 relations. There can be any number of services of a given type on the
12231 system---for instance, a system running two instances of the GNU secure
12232 shell server (lsh) has two instances of @var{lsh-service-type}, with
12233 different parameters.
12234
12235 The following section describes the programming interface for service
12236 types and services.
12237
12238 @node Service Types and Services
12239 @subsubsection Service Types and Services
12240
12241 A @dfn{service type} is a node in the DAG described above. Let us start
12242 with a simple example, the service type for the Guix build daemon
12243 (@pxref{Invoking guix-daemon}):
12244
12245 @example
12246 (define guix-service-type
12247 (service-type
12248 (name 'guix)
12249 (extensions
12250 (list (service-extension shepherd-root-service-type guix-shepherd-service)
12251 (service-extension account-service-type guix-accounts)
12252 (service-extension activation-service-type guix-activation)))))
12253 @end example
12254
12255 @noindent
12256 It defines two things:
12257
12258 @enumerate
12259 @item
12260 A name, whose sole purpose is to make inspection and debugging easier.
12261
12262 @item
12263 A list of @dfn{service extensions}, where each extension designates the
12264 target service type and a procedure that, given the parameters of the
12265 service, returns a list of objects to extend the service of that type.
12266
12267 Every service type has at least one service extension. The only
12268 exception is the @dfn{boot service type}, which is the ultimate service.
12269 @end enumerate
12270
12271 In this example, @var{guix-service-type} extends three services:
12272
12273 @table @var
12274 @item shepherd-root-service-type
12275 The @var{guix-shepherd-service} procedure defines how the Shepherd
12276 service is extended. Namely, it returns a @code{<shepherd-service>}
12277 object that defines how @command{guix-daemon} is started and stopped
12278 (@pxref{Shepherd Services}).
12279
12280 @item account-service-type
12281 This extension for this service is computed by @var{guix-accounts},
12282 which returns a list of @code{user-group} and @code{user-account}
12283 objects representing the build user accounts (@pxref{Invoking
12284 guix-daemon}).
12285
12286 @item activation-service-type
12287 Here @var{guix-activation} is a procedure that returns a gexp, which is
12288 a code snippet to run at ``activation time''---e.g., when the service is
12289 booted.
12290 @end table
12291
12292 A service of this type is instantiated like this:
12293
12294 @example
12295 (service guix-service-type
12296 (guix-configuration
12297 (build-accounts 5)
12298 (use-substitutes? #f)))
12299 @end example
12300
12301 The second argument to the @code{service} form is a value representing
12302 the parameters of this specific service instance.
12303 @xref{guix-configuration-type, @code{guix-configuration}}, for
12304 information about the @code{guix-configuration} data type.
12305
12306 @var{guix-service-type} is quite simple because it extends other
12307 services but is not extensible itself.
12308
12309 @c @subsubsubsection Extensible Service Types
12310
12311 The service type for an @emph{extensible} service looks like this:
12312
12313 @example
12314 (define udev-service-type
12315 (service-type (name 'udev)
12316 (extensions
12317 (list (service-extension shepherd-root-service-type
12318 udev-shepherd-service)))
12319
12320 (compose concatenate) ;concatenate the list of rules
12321 (extend (lambda (config rules)
12322 (match config
12323 (($ <udev-configuration> udev initial-rules)
12324 (udev-configuration
12325 (udev udev) ;the udev package to use
12326 (rules (append initial-rules rules)))))))))
12327 @end example
12328
12329 This is the service type for the
12330 @uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
12331 management daemon}. Compared to the previous example, in addition to an
12332 extension of @var{shepherd-root-service-type}, we see two new fields:
12333
12334 @table @code
12335 @item compose
12336 This is the procedure to @dfn{compose} the list of extensions to
12337 services of this type.
12338
12339 Services can extend the udev service by passing it lists of rules; we
12340 compose those extensions simply by concatenating them.
12341
12342 @item extend
12343 This procedure defines how the value of the service is @dfn{extended} with
12344 the composition of the extensions.
12345
12346 Udev extensions are composed into a list of rules, but the udev service
12347 value is itself a @code{<udev-configuration>} record. So here, we
12348 extend that record by appending the list of rules it contains to the
12349 list of contributed rules.
12350 @end table
12351
12352 There can be only one instance of an extensible service type such as
12353 @var{udev-service-type}. If there were more, the
12354 @code{service-extension} specifications would be ambiguous.
12355
12356 Still here? The next section provides a reference of the programming
12357 interface for services.
12358
12359 @node Service Reference
12360 @subsubsection Service Reference
12361
12362 We have seen an overview of service types (@pxref{Service Types and
12363 Services}). This section provides a reference on how to manipulate
12364 services and service types. This interface is provided by the
12365 @code{(gnu services)} module.
12366
12367 @deffn {Scheme Procedure} service @var{type} @var{value}
12368 Return a new service of @var{type}, a @code{<service-type>} object (see
12369 below.) @var{value} can be any object; it represents the parameters of
12370 this particular service instance.
12371 @end deffn
12372
12373 @deffn {Scheme Procedure} service? @var{obj}
12374 Return true if @var{obj} is a service.
12375 @end deffn
12376
12377 @deffn {Scheme Procedure} service-kind @var{service}
12378 Return the type of @var{service}---i.e., a @code{<service-type>} object.
12379 @end deffn
12380
12381 @deffn {Scheme Procedure} service-parameters @var{service}
12382 Return the value associated with @var{service}. It represents its
12383 parameters.
12384 @end deffn
12385
12386 Here is an example of how a service is created and manipulated:
12387
12388 @example
12389 (define s
12390 (service nginx-service-type
12391 (nginx-configuration
12392 (nginx nginx)
12393 (log-directory log-directory)
12394 (run-directory run-directory)
12395 (file config-file))))
12396
12397 (service? s)
12398 @result{} #t
12399
12400 (eq? (service-kind s) nginx-service-type)
12401 @result{} #t
12402 @end example
12403
12404 The @code{modify-services} form provides a handy way to change the
12405 parameters of some of the services of a list such as
12406 @var{%base-services} (@pxref{Base Services, @code{%base-services}}). It
12407 evaluates to a list of services. Of course, you could always use
12408 standard list combinators such as @code{map} and @code{fold} to do that
12409 (@pxref{SRFI-1, List Library,, guile, GNU Guile Reference Manual});
12410 @code{modify-services} simply provides a more concise form for this
12411 common pattern.
12412
12413 @deffn {Scheme Syntax} modify-services @var{services} @
12414 (@var{type} @var{variable} => @var{body}) @dots{}
12415
12416 Modify the services listed in @var{services} according to the given
12417 clauses. Each clause has the form:
12418
12419 @example
12420 (@var{type} @var{variable} => @var{body})
12421 @end example
12422
12423 where @var{type} is a service type---e.g.,
12424 @code{guix-service-type}---and @var{variable} is an identifier that is
12425 bound within the @var{body} to the service parameters---e.g., a
12426 @code{guix-configuration} instance---of the original service of that
12427 @var{type}.
12428
12429 The @var{body} should evaluate to the new service parameters, which will
12430 be used to configure the new service. This new service will replace the
12431 original in the resulting list. Because a service's service parameters
12432 are created using @code{define-record-type*}, you can write a succinct
12433 @var{body} that evaluates to the new service parameters by using the
12434 @code{inherit} feature that @code{define-record-type*} provides.
12435
12436 @xref{Using the Configuration System}, for example usage.
12437
12438 @end deffn
12439
12440 Next comes the programming interface for service types. This is
12441 something you want to know when writing new service definitions, but not
12442 necessarily when simply looking for ways to customize your
12443 @code{operating-system} declaration.
12444
12445 @deftp {Data Type} service-type
12446 @cindex service type
12447 This is the representation of a @dfn{service type} (@pxref{Service Types
12448 and Services}).
12449
12450 @table @asis
12451 @item @code{name}
12452 This is a symbol, used only to simplify inspection and debugging.
12453
12454 @item @code{extensions}
12455 A non-empty list of @code{<service-extension>} objects (see below).
12456
12457 @item @code{compose} (default: @code{#f})
12458 If this is @code{#f}, then the service type denotes services that cannot
12459 be extended---i.e., services that do not receive ``values'' from other
12460 services.
12461
12462 Otherwise, it must be a one-argument procedure. The procedure is called
12463 by @code{fold-services} and is passed a list of values collected from
12464 extensions. It must return a value that is a valid parameter value for
12465 the service instance.
12466
12467 @item @code{extend} (default: @code{#f})
12468 If this is @code{#f}, services of this type cannot be extended.
12469
12470 Otherwise, it must be a two-argument procedure: @code{fold-services}
12471 calls it, passing it the initial value of the service as the first argument
12472 and the result of applying @code{compose} to the extension values as the
12473 second argument.
12474 @end table
12475
12476 @xref{Service Types and Services}, for examples.
12477 @end deftp
12478
12479 @deffn {Scheme Procedure} service-extension @var{target-type} @
12480 @var{compute}
12481 Return a new extension for services of type @var{target-type}.
12482 @var{compute} must be a one-argument procedure: @code{fold-services}
12483 calls it, passing it the value associated with the service that provides
12484 the extension; it must return a valid value for the target service.
12485 @end deffn
12486
12487 @deffn {Scheme Procedure} service-extension? @var{obj}
12488 Return true if @var{obj} is a service extension.
12489 @end deffn
12490
12491 Occasionally, you might want to simply extend an existing service. This
12492 involves creating a new service type and specifying the extension of
12493 interest, which can be verbose; the @code{simple-service} procedure
12494 provides a shorthand for this.
12495
12496 @deffn {Scheme Procedure} simple-service @var{name} @var{target} @var{value}
12497 Return a service that extends @var{target} with @var{value}. This works
12498 by creating a singleton service type @var{name}, of which the returned
12499 service is an instance.
12500
12501 For example, this extends mcron (@pxref{Scheduled Job Execution}) with
12502 an additional job:
12503
12504 @example
12505 (simple-service 'my-mcron-job mcron-service-type
12506 #~(job '(next-hour (3)) "guix gc -F 2G"))
12507 @end example
12508 @end deffn
12509
12510 At the core of the service abstraction lies the @code{fold-services}
12511 procedure, which is responsible for ``compiling'' a list of services
12512 down to a single directory that contains everything needed to boot and
12513 run the system---the directory shown by the @command{guix system build}
12514 command (@pxref{Invoking guix system}). In essence, it propagates
12515 service extensions down the service graph, updating each node parameters
12516 on the way, until it reaches the root node.
12517
12518 @deffn {Scheme Procedure} fold-services @var{services} @
12519 [#:target-type @var{system-service-type}]
12520 Fold @var{services} by propagating their extensions down to the root of
12521 type @var{target-type}; return the root service adjusted accordingly.
12522 @end deffn
12523
12524 Lastly, the @code{(gnu services)} module also defines several essential
12525 service types, some of which are listed below.
12526
12527 @defvr {Scheme Variable} system-service-type
12528 This is the root of the service graph. It produces the system directory
12529 as returned by the @command{guix system build} command.
12530 @end defvr
12531
12532 @defvr {Scheme Variable} boot-service-type
12533 The type of the ``boot service'', which produces the @dfn{boot script}.
12534 The boot script is what the initial RAM disk runs when booting.
12535 @end defvr
12536
12537 @defvr {Scheme Variable} etc-service-type
12538 The type of the @file{/etc} service. This service can be extended by
12539 passing it name/file tuples such as:
12540
12541 @example
12542 (list `("issue" ,(plain-file "issue" "Welcome!\n")))
12543 @end example
12544
12545 In this example, the effect would be to add an @file{/etc/issue} file
12546 pointing to the given file.
12547 @end defvr
12548
12549 @defvr {Scheme Variable} setuid-program-service-type
12550 Type for the ``setuid-program service''. This service collects lists of
12551 executable file names, passed as gexps, and adds them to the set of
12552 setuid-root programs on the system (@pxref{Setuid Programs}).
12553 @end defvr
12554
12555 @defvr {Scheme Variable} profile-service-type
12556 Type of the service that populates the @dfn{system profile}---i.e., the
12557 programs under @file{/run/current-system/profile}. Other services can
12558 extend it by passing it lists of packages to add to the system profile.
12559 @end defvr
12560
12561
12562 @node Shepherd Services
12563 @subsubsection Shepherd Services
12564
12565 @cindex PID 1
12566 @cindex init system
12567 The @code{(gnu services shepherd)} module provides a way to define
12568 services managed by the GNU@tie{}Shepherd, which is the GuixSD
12569 initialization system---the first process that is started when the
12570 system boots, also known as PID@tie{}1
12571 (@pxref{Introduction,,, shepherd, The GNU Shepherd Manual}).
12572
12573 Services in the Shepherd can depend on each other. For instance, the
12574 SSH daemon may need to be started after the syslog daemon has been
12575 started, which in turn can only happen once all the file systems have
12576 been mounted. The simple operating system defined earlier (@pxref{Using
12577 the Configuration System}) results in a service graph like this:
12578
12579 @image{images/shepherd-graph,,5in,Typical shepherd service graph.}
12580
12581 You can actually generate such a graph for any operating system
12582 definition using the @command{guix system shepherd-graph} command
12583 (@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
12584
12585 The @var{%shepherd-root-service} is a service object representing
12586 PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
12587 by passing it lists of @code{<shepherd-service>} objects.
12588
12589 @deftp {Data Type} shepherd-service
12590 The data type representing a service managed by the Shepherd.
12591
12592 @table @asis
12593 @item @code{provision}
12594 This is a list of symbols denoting what the service provides.
12595
12596 These are the names that may be passed to @command{herd start},
12597 @command{herd status}, and similar commands (@pxref{Invoking herd,,,
12598 shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
12599 @code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
12600
12601 @item @code{requirements} (default: @code{'()})
12602 List of symbols denoting the Shepherd services this one depends on.
12603
12604 @item @code{respawn?} (default: @code{#t})
12605 Whether to restart the service when it stops, for instance when the
12606 underlying process dies.
12607
12608 @item @code{start}
12609 @itemx @code{stop} (default: @code{#~(const #f)})
12610 The @code{start} and @code{stop} fields refer to the Shepherd's
12611 facilities to start and stop processes (@pxref{Service De- and
12612 Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
12613 G-expressions that get expanded in the Shepherd configuration file
12614 (@pxref{G-Expressions}).
12615
12616 @item @code{documentation}
12617 A documentation string, as shown when running:
12618
12619 @example
12620 herd doc @var{service-name}
12621 @end example
12622
12623 where @var{service-name} is one of the symbols in @var{provision}
12624 (@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
12625
12626 @item @code{modules} (default: @var{%default-modules})
12627 This is the list of modules that must be in scope when @code{start} and
12628 @code{stop} are evaluated.
12629
12630 @end table
12631 @end deftp
12632
12633 @defvr {Scheme Variable} shepherd-root-service-type
12634 The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
12635
12636 This is the service type that extensions target when they want to create
12637 shepherd services (@pxref{Service Types and Services}, for an example).
12638 Each extension must pass a list of @code{<shepherd-service>}.
12639 @end defvr
12640
12641 @defvr {Scheme Variable} %shepherd-root-service
12642 This service represents PID@tie{}1.
12643 @end defvr
12644
12645
12646 @node Installing Debugging Files
12647 @section Installing Debugging Files
12648
12649 @cindex debugging files
12650 Program binaries, as produced by the GCC compilers for instance, are
12651 typically written in the ELF format, with a section containing
12652 @dfn{debugging information}. Debugging information is what allows the
12653 debugger, GDB, to map binary code to source code; it is required to
12654 debug a compiled program in good conditions.
12655
12656 The problem with debugging information is that is takes up a fair amount
12657 of disk space. For example, debugging information for the GNU C Library
12658 weighs in at more than 60 MiB. Thus, as a user, keeping all the
12659 debugging info of all the installed programs is usually not an option.
12660 Yet, space savings should not come at the cost of an impediment to
12661 debugging---especially in the GNU system, which should make it easier
12662 for users to exert their computing freedom (@pxref{GNU Distribution}).
12663
12664 Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
12665 mechanism that allows users to get the best of both worlds: debugging
12666 information can be stripped from the binaries and stored in separate
12667 files. GDB is then able to load debugging information from those files,
12668 when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
12669 with GDB}).
12670
12671 The GNU distribution takes advantage of this by storing debugging
12672 information in the @code{lib/debug} sub-directory of a separate package
12673 output unimaginatively called @code{debug} (@pxref{Packages with
12674 Multiple Outputs}). Users can choose to install the @code{debug} output
12675 of a package when they need it. For instance, the following command
12676 installs the debugging information for the GNU C Library and for GNU
12677 Guile:
12678
12679 @example
12680 guix package -i glibc:debug guile:debug
12681 @end example
12682
12683 GDB must then be told to look for debug files in the user's profile, by
12684 setting the @code{debug-file-directory} variable (consider setting it
12685 from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
12686 GDB}):
12687
12688 @example
12689 (gdb) set debug-file-directory ~/.guix-profile/lib/debug
12690 @end example
12691
12692 From there on, GDB will pick up debugging information from the
12693 @code{.debug} files under @file{~/.guix-profile/lib/debug}.
12694
12695 In addition, you will most likely want GDB to be able to show the source
12696 code being debugged. To do that, you will have to unpack the source
12697 code of the package of interest (obtained with @code{guix build
12698 --source}, @pxref{Invoking guix build}), and to point GDB to that source
12699 directory using the @code{directory} command (@pxref{Source Path,
12700 @code{directory},, gdb, Debugging with GDB}).
12701
12702 @c XXX: keep me up-to-date
12703 The @code{debug} output mechanism in Guix is implemented by the
12704 @code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
12705 opt-in---debugging information is available only for the packages
12706 with definitions explicitly declaring a @code{debug} output. This may be
12707 changed to opt-out in the future if our build farm servers can handle
12708 the load. To check whether a package has a @code{debug} output, use
12709 @command{guix package --list-available} (@pxref{Invoking guix package}).
12710
12711
12712 @node Security Updates
12713 @section Security Updates
12714
12715 @cindex security updates
12716 @cindex security vulnerabilities
12717 Occasionally, important security vulnerabilities are discovered in software
12718 packages and must be patched. Guix developers try hard to keep track of
12719 known vulnerabilities and to apply fixes as soon as possible in the
12720 @code{master} branch of Guix (we do not yet provide a ``stable'' branch
12721 containing only security updates.) The @command{guix lint} tool helps
12722 developers find out about vulnerable versions of software packages in the
12723 distribution:
12724
12725 @smallexample
12726 $ guix lint -c cve
12727 gnu/packages/base.scm:652:2: glibc-2.21: probably vulnerable to CVE-2015-1781, CVE-2015-7547
12728 gnu/packages/gcc.scm:334:2: gcc-4.9.3: probably vulnerable to CVE-2015-5276
12729 gnu/packages/image.scm:312:2: openjpeg-2.1.0: probably vulnerable to CVE-2016-1923, CVE-2016-1924
12730 @dots{}
12731 @end smallexample
12732
12733 @xref{Invoking guix lint}, for more information.
12734
12735 @quotation Note
12736 As of version @value{VERSION}, the feature described below is considered
12737 ``beta''.
12738 @end quotation
12739
12740 Guix follows a functional
12741 package management discipline (@pxref{Introduction}), which implies
12742 that, when a package is changed, @emph{every package that depends on it}
12743 must be rebuilt. This can significantly slow down the deployment of
12744 fixes in core packages such as libc or Bash, since basically the whole
12745 distribution would need to be rebuilt. Using pre-built binaries helps
12746 (@pxref{Substitutes}), but deployment may still take more time than
12747 desired.
12748
12749 @cindex grafts
12750 To address this, Guix implements @dfn{grafts}, a mechanism that allows
12751 for fast deployment of critical updates without the costs associated
12752 with a whole-distribution rebuild. The idea is to rebuild only the
12753 package that needs to be patched, and then to ``graft'' it onto packages
12754 explicitly installed by the user and that were previously referring to
12755 the original package. The cost of grafting is typically very low, and
12756 order of magnitudes lower than a full rebuild of the dependency chain.
12757
12758 @cindex replacements of packages, for grafts
12759 For instance, suppose a security update needs to be applied to Bash.
12760 Guix developers will provide a package definition for the ``fixed''
12761 Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
12762 Packages}). Then, the original package definition is augmented with a
12763 @code{replacement} field pointing to the package containing the bug fix:
12764
12765 @example
12766 (define bash
12767 (package
12768 (name "bash")
12769 ;; @dots{}
12770 (replacement bash-fixed)))
12771 @end example
12772
12773 From there on, any package depending directly or indirectly on Bash---as
12774 reported by @command{guix gc --requisites} (@pxref{Invoking guix
12775 gc})---that is installed is automatically ``rewritten'' to refer to
12776 @var{bash-fixed} instead of @var{bash}. This grafting process takes
12777 time proportional to the size of the package, usually less than a
12778 minute for an ``average'' package on a recent machine. Grafting is
12779 recursive: when an indirect dependency requires grafting, then grafting
12780 ``propagates'' up to the package that the user is installing.
12781
12782 Currently, the length of the name and version of the graft and that of
12783 the package it replaces (@var{bash-fixed} and @var{bash} in the example
12784 above) must be equal. This restriction mostly comes from the fact that
12785 grafting works by patching files, including binary files, directly.
12786 Other restrictions may apply: for instance, when adding a graft to a
12787 package providing a shared library, the original shared library and its
12788 replacement must have the same @code{SONAME} and be binary-compatible.
12789
12790 The @option{--no-grafts} command-line option allows you to forcefully
12791 avoid grafting (@pxref{Common Build Options, @option{--no-grafts}}).
12792 Thus, the command:
12793
12794 @example
12795 guix build bash --no-grafts
12796 @end example
12797
12798 @noindent
12799 returns the store file name of the original Bash, whereas:
12800
12801 @example
12802 guix build bash
12803 @end example
12804
12805 @noindent
12806 returns the store file name of the ``fixed'', replacement Bash. This
12807 allows you to distinguish between the two variants of Bash.
12808
12809 To verify which Bash your whole profile refers to, you can run
12810 (@pxref{Invoking guix gc}):
12811
12812 @example
12813 guix gc -R `readlink -f ~/.guix-profile` | grep bash
12814 @end example
12815
12816 @noindent
12817 @dots{} and compare the store file names that you get with those above.
12818 Likewise for a complete GuixSD system generation:
12819
12820 @example
12821 guix gc -R `guix system build my-config.scm` | grep bash
12822 @end example
12823
12824 Lastly, to check which Bash running processes are using, you can use the
12825 @command{lsof} command:
12826
12827 @example
12828 lsof | grep /gnu/store/.*bash
12829 @end example
12830
12831
12832 @node Package Modules
12833 @section Package Modules
12834
12835 From a programming viewpoint, the package definitions of the
12836 GNU distribution are provided by Guile modules in the @code{(gnu packages
12837 @dots{})} name space@footnote{Note that packages under the @code{(gnu
12838 packages @dots{})} module name space are not necessarily ``GNU
12839 packages''. This module naming scheme follows the usual Guile module
12840 naming convention: @code{gnu} means that these modules are distributed
12841 as part of the GNU system, and @code{packages} identifies modules that
12842 define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
12843 Reference Manual}). For instance, the @code{(gnu packages emacs)}
12844 module exports a variable named @code{emacs}, which is bound to a
12845 @code{<package>} object (@pxref{Defining Packages}).
12846
12847 The @code{(gnu packages @dots{})} module name space is
12848 automatically scanned for packages by the command-line tools. For
12849 instance, when running @code{guix package -i emacs}, all the @code{(gnu
12850 packages @dots{})} modules are scanned until one that exports a package
12851 object whose name is @code{emacs} is found. This package search
12852 facility is implemented in the @code{(gnu packages)} module.
12853
12854 @cindex customization, of packages
12855 @cindex package module search path
12856 Users can store package definitions in modules with different
12857 names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
12858 name and module name must match. For instance, the @code{(my-packages
12859 emacs)} module must be stored in a @file{my-packages/emacs.scm} file
12860 relative to the load path specified with @option{--load-path} or
12861 @code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
12862 guile, GNU Guile Reference Manual}, for details.}. These package definitions
12863 will not be visible by default. Users can invoke commands such as
12864 @command{guix package} and @command{guix build} with the
12865 @code{-e} option so that they know where to find the package. Better
12866 yet, they can use the
12867 @code{-L} option of these commands to make those modules visible
12868 (@pxref{Invoking guix build, @code{--load-path}}), or define the
12869 @code{GUIX_PACKAGE_PATH} environment variable. This environment
12870 variable makes it easy to extend or customize the distribution and is
12871 honored by all the user interfaces.
12872
12873 @defvr {Environment Variable} GUIX_PACKAGE_PATH
12874 This is a colon-separated list of directories to search for additional
12875 package modules. Directories listed in this variable take precedence
12876 over the own modules of the distribution.
12877 @end defvr
12878
12879 The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
12880 each package is built based solely on other packages in the
12881 distribution. The root of this dependency graph is a small set of
12882 @dfn{bootstrap binaries}, provided by the @code{(gnu packages
12883 bootstrap)} module. For more information on bootstrapping,
12884 @pxref{Bootstrapping}.
12885
12886 @node Packaging Guidelines
12887 @section Packaging Guidelines
12888
12889 The GNU distribution is nascent and may well lack some of your favorite
12890 packages. This section describes how you can help make the distribution
12891 grow. @xref{Contributing}, for additional information on how you can
12892 help.
12893
12894 Free software packages are usually distributed in the form of
12895 @dfn{source code tarballs}---typically @file{tar.gz} files that contain
12896 all the source files. Adding a package to the distribution means
12897 essentially two things: adding a @dfn{recipe} that describes how to
12898 build the package, including a list of other packages required to build
12899 it, and adding @dfn{package metadata} along with that recipe, such as a
12900 description and licensing information.
12901
12902 In Guix all this information is embodied in @dfn{package definitions}.
12903 Package definitions provide a high-level view of the package. They are
12904 written using the syntax of the Scheme programming language; in fact,
12905 for each package we define a variable bound to the package definition,
12906 and export that variable from a module (@pxref{Package Modules}).
12907 However, in-depth Scheme knowledge is @emph{not} a prerequisite for
12908 creating packages. For more information on package definitions,
12909 @pxref{Defining Packages}.
12910
12911 Once a package definition is in place, stored in a file in the Guix
12912 source tree, it can be tested using the @command{guix build} command
12913 (@pxref{Invoking guix build}). For example, assuming the new package is
12914 called @code{gnew}, you may run this command from the Guix build tree
12915 (@pxref{Running Guix Before It Is Installed}):
12916
12917 @example
12918 ./pre-inst-env guix build gnew --keep-failed
12919 @end example
12920
12921 Using @code{--keep-failed} makes it easier to debug build failures since
12922 it provides access to the failed build tree. Another useful
12923 command-line option when debugging is @code{--log-file}, to access the
12924 build log.
12925
12926 If the package is unknown to the @command{guix} command, it may be that
12927 the source file contains a syntax error, or lacks a @code{define-public}
12928 clause to export the package variable. To figure it out, you may load
12929 the module from Guile to get more information about the actual error:
12930
12931 @example
12932 ./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
12933 @end example
12934
12935 Once your package builds correctly, please send us a patch
12936 (@pxref{Contributing}). Well, if you need help, we will be happy to
12937 help you too. Once the patch is committed in the Guix repository, the
12938 new package automatically gets built on the supported platforms by
12939 @url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
12940 system}.
12941
12942 @cindex substituter
12943 Users can obtain the new package definition simply by running
12944 @command{guix pull} (@pxref{Invoking guix pull}). When
12945 @code{hydra.gnu.org} is done building the package, installing the
12946 package automatically downloads binaries from there
12947 (@pxref{Substitutes}). The only place where human intervention is
12948 needed is to review and apply the patch.
12949
12950
12951 @menu
12952 * Software Freedom:: What may go into the distribution.
12953 * Package Naming:: What's in a name?
12954 * Version Numbers:: When the name is not enough.
12955 * Synopses and Descriptions:: Helping users find the right package.
12956 * Python Modules:: Taming the snake.
12957 * Perl Modules:: Little pearls.
12958 * Java Packages:: Coffee break.
12959 * Fonts:: Fond of fonts.
12960 @end menu
12961
12962 @node Software Freedom
12963 @subsection Software Freedom
12964
12965 @c Adapted from http://www.gnu.org/philosophy/philosophy.html.
12966
12967 The GNU operating system has been developed so that users can have
12968 freedom in their computing. GNU is @dfn{free software}, meaning that
12969 users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
12970 essential freedoms}: to run the program, to study and change the program
12971 in source code form, to redistribute exact copies, and to distribute
12972 modified versions. Packages found in the GNU distribution provide only
12973 software that conveys these four freedoms.
12974
12975 In addition, the GNU distribution follow the
12976 @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
12977 software distribution guidelines}. Among other things, these guidelines
12978 reject non-free firmware, recommendations of non-free software, and
12979 discuss ways to deal with trademarks and patents.
12980
12981 Some otherwise free upstream package sources contain a small and optional
12982 subset that violates the above guidelines, for instance because this subset
12983 is itself non-free code. When that happens, the offending items are removed
12984 with appropriate patches or code snippets in the @code{origin} form of the
12985 package (@pxref{Defining Packages}). This way, @code{guix
12986 build --source} returns the ``freed'' source rather than the unmodified
12987 upstream source.
12988
12989
12990 @node Package Naming
12991 @subsection Package Naming
12992
12993 A package has actually two names associated with it:
12994 First, there is the name of the @emph{Scheme variable}, the one following
12995 @code{define-public}. By this name, the package can be made known in the
12996 Scheme code, for instance as input to another package. Second, there is
12997 the string in the @code{name} field of a package definition. This name
12998 is used by package management commands such as
12999 @command{guix package} and @command{guix build}.
13000
13001 Both are usually the same and correspond to the lowercase conversion of
13002 the project name chosen upstream, with underscores replaced with
13003 hyphens. For instance, GNUnet is available as @code{gnunet}, and
13004 SDL_net as @code{sdl-net}.
13005
13006 We do not add @code{lib} prefixes for library packages, unless these are
13007 already part of the official project name. But @pxref{Python
13008 Modules} and @ref{Perl Modules} for special rules concerning modules for
13009 the Python and Perl languages.
13010
13011 Font package names are handled differently, @pxref{Fonts}.
13012
13013
13014 @node Version Numbers
13015 @subsection Version Numbers
13016
13017 We usually package only the latest version of a given free software
13018 project. But sometimes, for instance for incompatible library versions,
13019 two (or more) versions of the same package are needed. These require
13020 different Scheme variable names. We use the name as defined
13021 in @ref{Package Naming}
13022 for the most recent version; previous versions use the same name, suffixed
13023 by @code{-} and the smallest prefix of the version number that may
13024 distinguish the two versions.
13025
13026 The name inside the package definition is the same for all versions of a
13027 package and does not contain any version number.
13028
13029 For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
13030
13031 @example
13032 (define-public gtk+
13033 (package
13034 (name "gtk+")
13035 (version "3.9.12")
13036 ...))
13037 (define-public gtk+-2
13038 (package
13039 (name "gtk+")
13040 (version "2.24.20")
13041 ...))
13042 @end example
13043 If we also wanted GTK+ 3.8.2, this would be packaged as
13044 @example
13045 (define-public gtk+-3.8
13046 (package
13047 (name "gtk+")
13048 (version "3.8.2")
13049 ...))
13050 @end example
13051
13052 @c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
13053 @c for a discussion of what follows.
13054 @cindex version number, for VCS snapshots
13055 Occasionally, we package snapshots of upstream's version control system
13056 (VCS) instead of formal releases. This should remain exceptional,
13057 because it is up to upstream developers to clarify what the stable
13058 release is. Yet, it is sometimes necessary. So, what should we put in
13059 the @code{version} field?
13060
13061 Clearly, we need to make the commit identifier of the VCS snapshot
13062 visible in the version string, but we also need to make sure that the
13063 version string is monotonically increasing so that @command{guix package
13064 --upgrade} can determine which version is newer. Since commit
13065 identifiers, notably with Git, are not monotonically increasing, we add
13066 a revision number that we increase each time we upgrade to a newer
13067 snapshot. The resulting version string looks like this:
13068
13069 @example
13070 2.0.11-3.cabba9e
13071 ^ ^ ^
13072 | | `-- upstream commit ID
13073 | |
13074 | `--- Guix package revision
13075 |
13076 latest upstream version
13077 @end example
13078
13079 It is a good idea to strip commit identifiers in the @code{version}
13080 field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
13081 aesthetics have a role to play here) as well as problems related to OS
13082 limits such as the maximum shebang length (127 bytes for the Linux
13083 kernel.) It is best to use the full commit identifiers in
13084 @code{origin}s, though, to avoid ambiguities. A typical package
13085 definition may look like this:
13086
13087 @example
13088 (define my-package
13089 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7")
13090 (revision "1")) ;Guix package revision
13091 (package
13092 (version (string-append "0.9-" revision "."
13093 (string-take commit 7)))
13094 (source (origin
13095 (method git-fetch)
13096 (uri (git-reference
13097 (url "git://example.org/my-package.git")
13098 (commit commit)))
13099 (sha256 (base32 "1mbikn@dots{}"))
13100 (file-name (string-append "my-package-" version
13101 "-checkout"))))
13102 ;; @dots{}
13103 )))
13104 @end example
13105
13106 @node Synopses and Descriptions
13107 @subsection Synopses and Descriptions
13108
13109 As we have seen before, each package in GNU@tie{}Guix includes a
13110 synopsis and a description (@pxref{Defining Packages}). Synopses and
13111 descriptions are important: They are what @command{guix package
13112 --search} searches, and a crucial piece of information to help users
13113 determine whether a given package suits their needs. Consequently,
13114 packagers should pay attention to what goes into them.
13115
13116 Synopses must start with a capital letter and must not end with a
13117 period. They must not start with ``a'' or ``the'', which usually does
13118 not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
13119 tool that frobs files''. The synopsis should say what the package
13120 is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
13121 used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
13122 matching a pattern''.
13123
13124 Keep in mind that the synopsis must be meaningful for a very wide
13125 audience. For example, ``Manipulate alignments in the SAM format''
13126 might make sense for a seasoned bioinformatics researcher, but might be
13127 fairly unhelpful or even misleading to a non-specialized audience. It
13128 is a good idea to come up with a synopsis that gives an idea of the
13129 application domain of the package. In this example, this might give
13130 something like ``Manipulate nucleotide sequence alignments'', which
13131 hopefully gives the user a better idea of whether this is what they are
13132 looking for.
13133
13134 Descriptions should take between five and ten lines. Use full
13135 sentences, and avoid using acronyms without first introducing them.
13136 Please avoid marketing phrases such as ``world-leading'',
13137 ``industrial-strength'', and ``next-generation'', and avoid superlatives
13138 like ``the most advanced''---they are not helpful to users looking for a
13139 package and may even sound suspicious. Instead, try to be factual,
13140 mentioning use cases and features.
13141
13142 @cindex Texinfo markup, in package descriptions
13143 Descriptions can include Texinfo markup, which is useful to introduce
13144 ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
13145 hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
13146 should be careful when using some characters for example @samp{@@} and
13147 curly braces which are the basic special characters in Texinfo
13148 (@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
13149 such as @command{guix package --show} take care of rendering it
13150 appropriately.
13151
13152 Synopses and descriptions are translated by volunteers
13153 @uref{http://translationproject.org/domain/guix-packages.html, at the
13154 Translation Project} so that as many users as possible can read them in
13155 their native language. User interfaces search them and display them in
13156 the language specified by the current locale.
13157
13158 Translation is a lot of work so, as a packager, please pay even more
13159 attention to your synopses and descriptions as every change may entail
13160 additional work for translators. In order to help them, it is possible
13161 to make recommendations or instructions visible to them by inserting
13162 special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
13163 Gettext}):
13164
13165 @example
13166 ;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
13167 (description "ARandR is designed to provide a simple visual front end
13168 for the X11 resize-and-rotate (RandR) extension. @dots{}")
13169 @end example
13170
13171
13172 @node Python Modules
13173 @subsection Python Modules
13174
13175 We currently package Python 2 and Python 3, under the Scheme variable names
13176 @code{python-2} and @code{python} as explained in @ref{Version Numbers}.
13177 To avoid confusion and naming clashes with other programming languages, it
13178 seems desirable that the name of a package for a Python module contains
13179 the word @code{python}.
13180
13181 Some modules are compatible with only one version of Python, others with both.
13182 If the package Foo compiles only with Python 3, we name it
13183 @code{python-foo}; if it compiles only with Python 2, we name it
13184 @code{python2-foo}. If it is compatible with both versions, we create two
13185 packages with the corresponding names.
13186
13187 If a project already contains the word @code{python}, we drop this;
13188 for instance, the module python-dateutil is packaged under the names
13189 @code{python-dateutil} and @code{python2-dateutil}. If the project name
13190 starts with @code{py} (e.g. @code{pytz}), we keep it and prefix it as
13191 described above.
13192
13193
13194 @subsubsection Specifying Dependencies
13195 @cindex inputs, for Python packages
13196
13197 Dependency information for Python packages is usually available in the
13198 package source tree, with varying degrees of accuracy: in the
13199 @file{setup.py} file, in @file{requirements.txt}, or in @file{tox.ini}.
13200
13201 Your mission, when writing a recipe for a Python package, is to map
13202 these dependencies to the appropriate type of ``input'' (@pxref{package
13203 Reference, inputs}). Although the @code{pypi} importer normally does a
13204 good job (@pxref{Invoking guix import}), you may want to check the
13205 following check list to determine which dependency goes where.
13206
13207 @itemize
13208
13209 @item
13210 Python dependencies required at run time go into
13211 @code{propagated-inputs}. They are typically defined with the
13212 @code{install_requires} keyword in @file{setup.py}, or in the
13213 @file{requirements.txt} file.
13214
13215 @item
13216 Python packages required only at build time---e.g., those listed with
13217 the @code{setup_requires} keyword in @file{setup.py}---or only for
13218 testing---e.g., those in @code{tests_require}---go into
13219 @code{native-inputs}. The rationale is that (1) they do not need to be
13220 propagated because they are not needed at run time, and (2) in a
13221 cross-compilation context, it's the ``native'' input that we'd want.
13222
13223 Examples are @code{setuptools}, which is usually needed only at build
13224 time, or the @code{pytest}, @code{mock}, and @code{nose} test
13225 frameworks. Of course if any of these packages is also required at
13226 run-time, it needs to go to @code{propagated-inputs}.
13227
13228 @item
13229 Anything that does not fall in the previous categories goes to
13230 @code{inputs}, for example programs or C libraries required for building
13231 Python packages containing C extensions.
13232
13233 @item
13234 If a Python package has optional dependencies (@code{extras_require}),
13235 it is up to you to decide whether to add them or not, based on their
13236 usefulness/overhead ratio (@pxref{Submitting Patches, @command{guix
13237 size}}).
13238
13239 @end itemize
13240
13241
13242 @node Perl Modules
13243 @subsection Perl Modules
13244
13245 Perl programs standing for themselves are named as any other package,
13246 using the lowercase upstream name.
13247 For Perl packages containing a single class, we use the lowercase class name,
13248 replace all occurrences of @code{::} by dashes and prepend the prefix
13249 @code{perl-}.
13250 So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
13251 Modules containing several classes keep their lowercase upstream name and
13252 are also prepended by @code{perl-}. Such modules tend to have the word
13253 @code{perl} somewhere in their name, which gets dropped in favor of the
13254 prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
13255
13256
13257 @node Java Packages
13258 @subsection Java Packages
13259
13260 Java programs standing for themselves are named as any other package,
13261 using the lowercase upstream name.
13262
13263 To avoid confusion and naming clashes with other programming languages,
13264 it is desirable that the name of a package for a Java package is
13265 prefixed with @code{java-}. If a project already contains the word
13266 @code{java}, we drop this; for instance, the package @code{ngsjava} is
13267 packaged under the name @code{java-ngs}.
13268
13269 For Java packages containing a single class or a small class hierarchy,
13270 we use the lowercase class name, replace all occurrences of @code{.} by
13271 dashes and prepend the prefix @code{java-}. So the class
13272 @code{apache.commons.cli} becomes package
13273 @code{java-apache-commons-cli}.
13274
13275
13276 @node Fonts
13277 @subsection Fonts
13278
13279 For fonts that are in general not installed by a user for typesetting
13280 purposes, or that are distributed as part of a larger software package,
13281 we rely on the general packaging rules for software; for instance, this
13282 applies to the fonts delivered as part of the X.Org system or fonts that
13283 are part of TeX Live.
13284
13285 To make it easier for a user to search for fonts, names for other packages
13286 containing only fonts are constructed as follows, independently of the
13287 upstream package name.
13288
13289 The name of a package containing only one font family starts with
13290 @code{font-}; it is followed by the foundry name and a dash @code{-}
13291 if the foundry is known, and the font family name, in which spaces are
13292 replaced by dashes (and as usual, all upper case letters are transformed
13293 to lower case).
13294 For example, the Gentium font family by SIL is packaged under the name
13295 @code{font-sil-gentium}.
13296
13297 For a package containing several font families, the name of the collection
13298 is used in the place of the font family name.
13299 For instance, the Liberation fonts consist of three families,
13300 Liberation Sans, Liberation Serif and Liberation Mono.
13301 These could be packaged separately under the names
13302 @code{font-liberation-sans} and so on; but as they are distributed together
13303 under a common name, we prefer to package them together as
13304 @code{font-liberation}.
13305
13306 In the case where several formats of the same font family or font collection
13307 are packaged separately, a short form of the format, prepended by a dash,
13308 is added to the package name. We use @code{-ttf} for TrueType fonts,
13309 @code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
13310 fonts.
13311
13312
13313
13314 @node Bootstrapping
13315 @section Bootstrapping
13316
13317 @c Adapted from the ELS 2013 paper.
13318
13319 @cindex bootstrapping
13320
13321 Bootstrapping in our context refers to how the distribution gets built
13322 ``from nothing''. Remember that the build environment of a derivation
13323 contains nothing but its declared inputs (@pxref{Introduction}). So
13324 there's an obvious chicken-and-egg problem: how does the first package
13325 get built? How does the first compiler get compiled? Note that this is
13326 a question of interest only to the curious hacker, not to the regular
13327 user, so you can shamelessly skip this section if you consider yourself
13328 a ``regular user''.
13329
13330 @cindex bootstrap binaries
13331 The GNU system is primarily made of C code, with libc at its core. The
13332 GNU build system itself assumes the availability of a Bourne shell and
13333 command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
13334 `grep'. Furthermore, build programs---programs that run
13335 @code{./configure}, @code{make}, etc.---are written in Guile Scheme
13336 (@pxref{Derivations}). Consequently, to be able to build anything at
13337 all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
13338 Binutils, libc, and the other packages mentioned above---the
13339 @dfn{bootstrap binaries}.
13340
13341 These bootstrap binaries are ``taken for granted'', though we can also
13342 re-create them if needed (more on that later).
13343
13344 @unnumberedsubsec Preparing to Use the Bootstrap Binaries
13345
13346 @c As of Emacs 24.3, Info-mode displays the image, but since it's a
13347 @c large image, it's hard to scroll. Oh well.
13348 @image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
13349
13350 The figure above shows the very beginning of the dependency graph of the
13351 distribution, corresponding to the package definitions of the @code{(gnu
13352 packages bootstrap)} module. A similar figure can be generated with
13353 @command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
13354
13355 @example
13356 guix graph -t derivation \
13357 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
13358 | dot -Tps > t.ps
13359 @end example
13360
13361 At this level of detail, things are
13362 slightly complex. First, Guile itself consists of an ELF executable,
13363 along with many source and compiled Scheme files that are dynamically
13364 loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
13365 tarball shown in this graph. This tarball is part of Guix's ``source''
13366 distribution, and gets inserted into the store with @code{add-to-store}
13367 (@pxref{The Store}).
13368
13369 But how do we write a derivation that unpacks this tarball and adds it
13370 to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
13371 derivation---the first one that gets built---uses @code{bash} as its
13372 builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
13373 @code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
13374 @file{xz}, and @file{mkdir} are statically-linked binaries, also part of
13375 the Guix source distribution, whose sole purpose is to allow the Guile
13376 tarball to be unpacked.
13377
13378 Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
13379 Guile that can be used to run subsequent build programs. Its first task
13380 is to download tarballs containing the other pre-built binaries---this
13381 is what the @code{.tar.xz.drv} derivations do. Guix modules such as
13382 @code{ftp-client.scm} are used for this purpose. The
13383 @code{module-import.drv} derivations import those modules in a directory
13384 in the store, using the original layout. The
13385 @code{module-import-compiled.drv} derivations compile those modules, and
13386 write them in an output directory with the right layout. This
13387 corresponds to the @code{#:modules} argument of
13388 @code{build-expression->derivation} (@pxref{Derivations}).
13389
13390 Finally, the various tarballs are unpacked by the
13391 derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
13392 etc., at which point we have a working C tool chain.
13393
13394
13395 @unnumberedsubsec Building the Build Tools
13396
13397 Bootstrapping is complete when we have a full tool chain that does not
13398 depend on the pre-built bootstrap tools discussed above. This
13399 no-dependency requirement is verified by checking whether the files of
13400 the final tool chain contain references to the @file{/gnu/store}
13401 directories of the bootstrap inputs. The process that leads to this
13402 ``final'' tool chain is described by the package definitions found in
13403 the @code{(gnu packages commencement)} module.
13404
13405 The @command{guix graph} command allows us to ``zoom out'' compared to
13406 the graph above, by looking at the level of package objects instead of
13407 individual derivations---remember that a package may translate to
13408 several derivations, typically one derivation to download its source,
13409 one to build the Guile modules it needs, and one to actually build the
13410 package from source. The command:
13411
13412 @example
13413 guix graph -t bag \
13414 -e '(@@@@ (gnu packages commencement)
13415 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
13416 @end example
13417
13418 @noindent
13419 produces the dependency graph leading to the ``final'' C
13420 library@footnote{You may notice the @code{glibc-intermediate} label,
13421 suggesting that it is not @emph{quite} final, but as a good
13422 approximation, we will consider it final.}, depicted below.
13423
13424 @image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
13425
13426 @c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
13427 The first tool that gets built with the bootstrap binaries is
13428 GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
13429 for all the following packages. From there Findutils and Diffutils get
13430 built.
13431
13432 Then come the first-stage Binutils and GCC, built as pseudo cross
13433 tools---i.e., with @code{--target} equal to @code{--host}. They are
13434 used to build libc. Thanks to this cross-build trick, this libc is
13435 guaranteed not to hold any reference to the initial tool chain.
13436
13437 From there the final Binutils and GCC (not shown above) are built.
13438 GCC uses @code{ld}
13439 from the final Binutils, and links programs against the just-built libc.
13440 This tool chain is used to build the other packages used by Guix and by
13441 the GNU Build System: Guile, Bash, Coreutils, etc.
13442
13443 And voilà! At this point we have the complete set of build tools that
13444 the GNU Build System expects. These are in the @code{%final-inputs}
13445 variable of the @code{(gnu packages commencement)} module, and are
13446 implicitly used by any package that uses @code{gnu-build-system}
13447 (@pxref{Build Systems, @code{gnu-build-system}}).
13448
13449
13450 @unnumberedsubsec Building the Bootstrap Binaries
13451
13452 Because the final tool chain does not depend on the bootstrap binaries,
13453 those rarely need to be updated. Nevertheless, it is useful to have an
13454 automated way to produce them, should an update occur, and this is what
13455 the @code{(gnu packages make-bootstrap)} module provides.
13456
13457 The following command builds the tarballs containing the bootstrap
13458 binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
13459 of Coreutils and other basic command-line tools):
13460
13461 @example
13462 guix build bootstrap-tarballs
13463 @end example
13464
13465 The generated tarballs are those that should be referred to in the
13466 @code{(gnu packages bootstrap)} module mentioned at the beginning of
13467 this section.
13468
13469 Still here? Then perhaps by now you've started to wonder: when do we
13470 reach a fixed point? That is an interesting question! The answer is
13471 unknown, but if you would like to investigate further (and have
13472 significant computational and storage resources to do so), then let us
13473 know.
13474
13475 @node Porting
13476 @section Porting to a New Platform
13477
13478 As discussed above, the GNU distribution is self-contained, and
13479 self-containment is achieved by relying on pre-built ``bootstrap
13480 binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
13481 operating system kernel, CPU architecture, and application binary
13482 interface (ABI). Thus, to port the distribution to a platform that is
13483 not yet supported, one must build those bootstrap binaries, and update
13484 the @code{(gnu packages bootstrap)} module to use them on that platform.
13485
13486 Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
13487 When everything goes well, and assuming the GNU tool chain supports the
13488 target platform, this can be as simple as running a command like this
13489 one:
13490
13491 @example
13492 guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
13493 @end example
13494
13495 For this to work, the @code{glibc-dynamic-linker} procedure in
13496 @code{(gnu packages bootstrap)} must be augmented to return the right
13497 file name for libc's dynamic linker on that platform; likewise,
13498 @code{system->linux-architecture} in @code{(gnu packages linux)} must be
13499 taught about the new platform.
13500
13501 Once these are built, the @code{(gnu packages bootstrap)} module needs
13502 to be updated to refer to these binaries on the target platform. That
13503 is, the hashes and URLs of the bootstrap tarballs for the new platform
13504 must be added alongside those of the currently supported platforms. The
13505 bootstrap Guile tarball is treated specially: it is expected to be
13506 available locally, and @file{gnu/local.mk} has rules do download it for
13507 the supported architectures; a rule for the new platform must be added
13508 as well.
13509
13510 In practice, there may be some complications. First, it may be that the
13511 extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
13512 above) is not recognized by all the GNU tools. Typically, glibc
13513 recognizes some of these, whereas GCC uses an extra @code{--with-abi}
13514 configure flag (see @code{gcc.scm} for examples of how to handle this).
13515 Second, some of the required packages could fail to build for that
13516 platform. Lastly, the generated binaries could be broken for some
13517 reason.
13518
13519 @c *********************************************************************
13520 @include contributing.texi
13521
13522 @c *********************************************************************
13523 @node Acknowledgments
13524 @chapter Acknowledgments
13525
13526 Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
13527 which was designed and
13528 implemented by Eelco Dolstra, with contributions from other people (see
13529 the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
13530 management, and promoted unprecedented features, such as transactional
13531 package upgrades and rollbacks, per-user profiles, and referentially
13532 transparent build processes. Without this work, Guix would not exist.
13533
13534 The Nix-based software distributions, Nixpkgs and NixOS, have also been
13535 an inspiration for Guix.
13536
13537 GNU@tie{}Guix itself is a collective work with contributions from a
13538 number of people. See the @file{AUTHORS} file in Guix for more
13539 information on these fine people. The @file{THANKS} file lists people
13540 who have helped by reporting bugs, taking care of the infrastructure,
13541 providing artwork and themes, making suggestions, and more---thank you!
13542
13543
13544 @c *********************************************************************
13545 @node GNU Free Documentation License
13546 @appendix GNU Free Documentation License
13547
13548 @include fdl-1.3.texi
13549
13550 @c *********************************************************************
13551 @node Concept Index
13552 @unnumbered Concept Index
13553 @printindex cp
13554
13555 @node Programming Index
13556 @unnumbered Programming Index
13557 @syncodeindex tp fn
13558 @syncodeindex vr fn
13559 @printindex fn
13560
13561 @bye
13562
13563 @c Local Variables:
13564 @c ispell-local-dictionary: "american";
13565 @c End: