c111b0ffbf36872710bec4a6535f0e19401d4059
[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 @copying
13 Copyright @copyright{} 2012, 2013, 2014, 2015, 2016 Ludovic Courtès@*
14 Copyright @copyright{} 2013, 2014, 2016 Andreas Enge@*
15 Copyright @copyright{} 2013 Nikita Karetnikov@*
16 Copyright @copyright{} 2015 Mathieu Lirzin@*
17 Copyright @copyright{} 2014 Pierre-Antoine Rault@*
18 Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer@*
19 Copyright @copyright{} 2015, 2016 Leo Famulari
20
21 Permission is granted to copy, distribute and/or modify this document
22 under the terms of the GNU Free Documentation License, Version 1.3 or
23 any later version published by the Free Software Foundation; with no
24 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
25 copy of the license is included in the section entitled ``GNU Free
26 Documentation License''.
27 @end copying
28
29 @dircategory Package management
30 @direntry
31 * guix: (guix). Guix, the functional package manager.
32 * guix package: (guix)Invoking guix package
33 Managing packages with Guix.
34 * guix build: (guix)Invoking guix build
35 Building packages with Guix.
36 * guix system: (guix)Invoking guix system
37 Managing the operating system configuration.
38 @end direntry
39
40 @dircategory Software development
41 @direntry
42 * guix environment: (guix)Invoking guix environment
43 Building development environments with Guix.
44 @end direntry
45
46 @titlepage
47 @title GNU Guix Reference Manual
48 @subtitle Using the GNU Guix Functional Package Manager
49 @author The GNU Guix Developers
50
51 @page
52 @vskip 0pt plus 1filll
53 Edition @value{EDITION} @*
54 @value{UPDATED} @*
55
56 @insertcopying
57 @end titlepage
58
59 @contents
60
61 @c *********************************************************************
62 @node Top
63 @top GNU Guix
64
65 This document describes GNU Guix version @value{VERSION}, a functional
66 package management tool written for the GNU system.
67
68 @menu
69 * Introduction:: What is Guix about?
70 * Installation:: Installing Guix.
71 * Package Management:: Package installation, upgrade, etc.
72 * Emacs Interface:: Using Guix from Emacs.
73 * Programming Interface:: Using Guix in Scheme.
74 * Utilities:: Package management commands.
75 * GNU Distribution:: Software for your friendly GNU system.
76 * Contributing:: Your help needed!
77
78 * Acknowledgments:: Thanks!
79 * GNU Free Documentation License:: The license of this manual.
80 * Concept Index:: Concepts.
81 * Programming Index:: Data types, functions, and variables.
82
83 @detailmenu
84 --- The Detailed Node Listing ---
85
86 Installation
87
88 * Binary Installation:: Getting Guix running in no time!
89 * Requirements:: Software needed to build and run Guix.
90 * Running the Test Suite:: Testing Guix.
91 * Setting Up the Daemon:: Preparing the build daemon's environment.
92 * Invoking guix-daemon:: Running the build daemon.
93 * Application Setup:: Application-specific setup.
94
95 Setting Up the Daemon
96
97 * Build Environment Setup:: Preparing the isolated build environment.
98 * Daemon Offload Setup:: Offloading builds to remote machines.
99
100 Package Management
101
102 * Features:: How Guix will make your life brighter.
103 * Invoking guix package:: Package installation, removal, etc.
104 * Substitutes:: Downloading pre-built binaries.
105 * Packages with Multiple Outputs:: Single source package, multiple outputs.
106 * Invoking guix gc:: Running the garbage collector.
107 * Invoking guix pull:: Fetching the latest Guix and distribution.
108 * Invoking guix archive:: Exporting and importing store files.
109
110 Emacs Interface
111
112 * Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
113 * Package Management: Emacs Package Management. Managing packages and generations.
114 * Licenses: Emacs Licenses. Interface for licenses of Guix packages.
115 * Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
116 * Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
117 * Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
118 * Completions: Emacs Completions. Completing @command{guix} shell command.
119 * Development: Emacs Development. Tools for Guix developers.
120 * Hydra: Emacs Hydra. Interface for Guix build farm.
121
122 Programming Interface
123
124 * Defining Packages:: Defining new packages.
125 * Build Systems:: Specifying how packages are built.
126 * The Store:: Manipulating the package store.
127 * Derivations:: Low-level interface to package derivations.
128 * The Store Monad:: Purely functional interface to the store.
129 * G-Expressions:: Manipulating build expressions.
130
131 Defining Packages
132
133 * package Reference:: The package data type.
134 * origin Reference:: The origin data type.
135
136 Utilities
137
138 * Invoking guix build:: Building packages from the command line.
139 * Invoking guix edit:: Editing package definitions.
140 * Invoking guix download:: Downloading a file and printing its hash.
141 * Invoking guix hash:: Computing the cryptographic hash of a file.
142 * Invoking guix import:: Importing package definitions.
143 * Invoking guix refresh:: Updating package definitions.
144 * Invoking guix lint:: Finding errors in package definitions.
145 * Invoking guix size:: Profiling disk usage.
146 * Invoking guix graph:: Visualizing the graph of packages.
147 * Invoking guix environment:: Setting up development environments.
148 * Invoking guix publish:: Sharing substitutes.
149 * Invoking guix challenge:: Challenging substitute servers.
150 * Invoking guix container:: Process isolation.
151
152 GNU Distribution
153
154 * System Installation:: Installing the whole operating system.
155 * System Configuration:: Configuring the operating system.
156 * Installing Debugging Files:: Feeding the debugger.
157 * Security Updates:: Deploying security fixes quickly.
158 * Package Modules:: Packages from the programmer's viewpoint.
159 * Packaging Guidelines:: Growing the distribution.
160 * Bootstrapping:: GNU/Linux built from scratch.
161 * Porting:: Targeting another platform or kernel.
162
163 System Configuration
164
165 * Using the Configuration System:: Customizing your GNU system.
166 * operating-system Reference:: Detail of operating-system declarations.
167 * File Systems:: Configuring file system mounts.
168 * Mapped Devices:: Block device extra processing.
169 * User Accounts:: Specifying user accounts.
170 * Locales:: Language and cultural convention settings.
171 * Services:: Specifying system services.
172 * Setuid Programs:: Programs running with root privileges.
173 * X.509 Certificates:: Authenticating HTTPS servers.
174 * Name Service Switch:: Configuring libc's name service switch.
175 * Initial RAM Disk:: Linux-Libre bootstrapping.
176 * GRUB Configuration:: Configuring the boot loader.
177 * Invoking guix system:: Instantiating a system configuration.
178 * Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
179 * Defining Services:: Adding new service definitions.
180
181 Services
182
183 * Base Services:: Essential system services.
184 * Networking Services:: Network setup, SSH daemon, etc.
185 * X Window:: Graphical display.
186 * Desktop Services:: D-Bus and desktop services.
187 * Database Services:: SQL databases.
188 * Mail Services:: IMAP, POP3, SMTP, and all that.
189 * Web Services:: Web servers.
190 * Various Services:: Other services.
191
192 Defining Services
193
194 * Service Composition:: The model for composing services.
195 * Service Types and Services:: Types and services.
196 * Service Reference:: API reference.
197 * Shepherd Services:: A particular type of service.
198
199 Packaging Guidelines
200
201 * Software Freedom:: What may go into the distribution.
202 * Package Naming:: What's in a name?
203 * Version Numbers:: When the name is not enough.
204 * Synopses and Descriptions:: Helping users find the right package.
205 * Python Modules:: Taming the snake.
206 * Perl Modules:: Little pearls.
207 * Fonts:: Fond of fonts.
208
209 Contributing
210
211 * Building from Git:: The latest and greatest.
212 * Running Guix Before It Is Installed:: Hacker tricks.
213 * The Perfect Setup:: The right tools.
214 * Coding Style:: Hygiene of the contributor.
215 * Submitting Patches:: Share your work.
216
217 Coding Style
218
219 * Programming Paradigm:: How to compose your elements.
220 * Modules:: Where to store your code?
221 * Data Types and Pattern Matching:: Implementing data structures.
222 * Formatting Code:: Writing conventions.
223
224 @end detailmenu
225 @end menu
226
227 @c *********************************************************************
228 @node Introduction
229 @chapter Introduction
230
231 GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
232 using the international phonetic alphabet (IPA).} is a functional
233 package management tool for the GNU system. Package management consists
234 of all activities that relate to building packages from sources,
235 honoring their build-time and run-time dependencies,
236 installing packages in user environments, upgrading installed packages
237 to new versions or rolling back to a previous set, removing unused
238 software packages, etc.
239
240 @cindex functional package management
241 The term @dfn{functional} refers to a specific package management
242 discipline pioneered by Nix (@pxref{Acknowledgments}).
243 In Guix, the package build and installation process is seen
244 as a function, in the mathematical sense. That function takes inputs,
245 such as build scripts, a compiler, and libraries, and
246 returns an installed package. As a pure function, its result depends
247 solely on its inputs---for instance, it cannot refer to software or
248 scripts that were not explicitly passed as inputs. A build function
249 always produces the same result when passed a given set of inputs. It
250 cannot alter the environment of the running system in
251 any way; for instance, it cannot create, modify, or delete files outside
252 of its build and installation directories. This is achieved by running
253 build processes in isolated environments (or @dfn{containers}), where only their
254 explicit inputs are visible.
255
256 @cindex store
257 The result of package build functions is @dfn{cached} in the file
258 system, in a special directory called @dfn{the store} (@pxref{The
259 Store}). Each package is installed in a directory of its own in the
260 store---by default under @file{/gnu/store}. The directory name contains
261 a hash of all the inputs used to build that package; thus, changing an
262 input yields a different directory name.
263
264 This approach is the foundation for the salient features of Guix: support
265 for transactional package upgrade and rollback, per-user installation, and
266 garbage collection of packages (@pxref{Features}).
267
268 Guix has a command-line interface, which allows users to build, install,
269 upgrade, and remove packages, as well as a Scheme programming interface.
270
271 @cindex Guix System Distribution
272 @cindex GuixSD
273 Last but not least, Guix is used to build a distribution of the GNU
274 system, with many GNU and non-GNU free software packages. The Guix
275 System Distribution, or GNU@tie{}GuixSD, takes advantage of the core
276 properties of Guix at the system level. With GuixSD, users
277 @emph{declare} all aspects of the operating system configuration, and
278 Guix takes care of instantiating that configuration in a reproducible,
279 stateless fashion. @xref{GNU Distribution}.
280
281 @c *********************************************************************
282 @node Installation
283 @chapter Installation
284
285 GNU Guix is available for download from its website at
286 @url{http://www.gnu.org/software/guix/}. This section describes the
287 software requirements of Guix, as well as how to install it and get
288 ready to use it.
289
290 Note that this section is concerned with the installation of the package
291 manager, which can be done on top of a running GNU/Linux system. If,
292 instead, you want to install the complete GNU operating system,
293 @pxref{System Installation}.
294
295 @menu
296 * Binary Installation:: Getting Guix running in no time!
297 * Requirements:: Software needed to build and run Guix.
298 * Running the Test Suite:: Testing Guix.
299 * Setting Up the Daemon:: Preparing the build daemon's environment.
300 * Invoking guix-daemon:: Running the build daemon.
301 * Application Setup:: Application-specific setup.
302 @end menu
303
304 @node Binary Installation
305 @section Binary Installation
306
307 This section describes how to install Guix on an arbitrary system from a
308 self-contained tarball providing binaries for Guix and for all its
309 dependencies. This is often quicker than installing from source, which
310 is described in the next sections. The only requirement is to have
311 GNU@tie{}tar and Xz.
312
313 Installing goes along these lines:
314
315 @enumerate
316 @item
317 Download the binary tarball from
318 @indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz},
319 where @var{system} is @code{x86_64-linux} for an @code{x86_64} machine
320 already running the kernel Linux, and so on.
321
322 Make sure to download the associated @file{.sig} file and to verify the
323 authenticity of the tarball against it, along these lines:
324
325 @example
326 $ wget ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
327 $ gpg --verify guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
328 @end example
329
330 If that command fails because you do not have the required public key,
331 then run this command to import it:
332
333 @example
334 $ gpg --keyserver keys.gnupg.net --recv-keys 3D9AEBB5
335 @end example
336
337 @noindent
338 and rerun the @code{gpg --verify} command.
339
340 @item
341 As @code{root}, run:
342
343 @example
344 # cd /tmp
345 # tar --warning=no-timestamp -xf \
346 guix-binary-@value{VERSION}.@var{system}.tar.xz
347 # mv var/guix /var/ && mv gnu /
348 @end example
349
350 This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
351 The latter contains a ready-to-use profile for @code{root} (see next
352 step.)
353
354 Do @emph{not} unpack the tarball on a working Guix system since that
355 would overwrite its own essential files.
356
357 The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
358 not emit warnings about ``implausibly old time stamps'' (such
359 warnings were triggered by GNU@tie{}tar 1.26 and older; recent
360 versions are fine.)
361 They stem from the fact that all the
362 files in the archive have their modification time set to zero (which
363 means January 1st, 1970.) This is done on purpose to make sure the
364 archive content is independent of its creation time, thus making it
365 reproducible.
366
367 @item
368 Make @code{root}'s profile available under @file{~/.guix-profile}:
369
370 @example
371 # ln -sf /var/guix/profiles/per-user/root/guix-profile \
372 ~root/.guix-profile
373 @end example
374
375 @item
376 Create the group and user accounts for build users as explained below
377 (@pxref{Build Environment Setup}).
378
379 @item
380 Run the daemon, and set it to automatically start on boot.
381
382 If your host distro uses the systemd init system, this can be achieved
383 with these commands:
384
385 @example
386 # cp ~root/.guix-profile/lib/systemd/system/guix-daemon.service \
387 /etc/systemd/system/
388 # systemctl start guix-daemon && systemctl enable guix-daemon
389 @end example
390
391 If your host distro uses the Upstart init system:
392
393 @example
394 # cp ~root/.guix-profile/lib/upstart/system/guix-daemon.conf /etc/init/
395 # start guix-daemon
396 @end example
397
398 Otherwise, you can still start the daemon manually with:
399
400 @example
401 # ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
402 @end example
403
404 @item
405 Make the @command{guix} command available to other users on the machine,
406 for instance with:
407
408 @example
409 # mkdir -p /usr/local/bin
410 # cd /usr/local/bin
411 # ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
412 @end example
413
414 It is also a good idea to make the Info version of this manual available
415 there:
416
417 @example
418 # mkdir -p /usr/local/share/info
419 # cd /usr/local/share/info
420 # for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
421 do ln -s $i ; done
422 @end example
423
424 That way, assuming @file{/usr/local/share/info} is in the search path,
425 running @command{info guix} will open this manual (@pxref{Other Info
426 Directories,,, texinfo, GNU Texinfo}, for more details on changing the
427 Info search path.)
428
429 @item
430 To use substitutes from @code{hydra.gnu.org} (@pxref{Substitutes}),
431 authorize them:
432
433 @example
434 # guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
435 @end example
436 @end enumerate
437
438 This completes root-level install of Guix. Each user will need to
439 perform additional steps to make their Guix envionment ready for use,
440 @pxref{Application Setup}.
441
442 You can confirm that Guix is working by installing a sample package into
443 the root profile:
444
445 @example
446 # guix package -i hello
447 @end example
448
449 The @code{guix} package must remain available in @code{root}'s profile,
450 or it would become subject to garbage collection---in which case you
451 would find yourself badly handicapped by the lack of the @command{guix}
452 command. In other words, do not remove @code{guix} by running
453 @code{guix package -r guix}.
454
455 The binary installation tarball can be (re)produced and verified simply
456 by running the following command in the Guix source tree:
457
458 @example
459 make guix-binary.@var{system}.tar.xz
460 @end example
461
462
463 @node Requirements
464 @section Requirements
465
466 This section lists requirements when building Guix from source. The
467 build procedure for Guix is the same as for other GNU software, and is
468 not covered here. Please see the files @file{README} and @file{INSTALL}
469 in the Guix source tree for additional details.
470
471 GNU Guix depends on the following packages:
472
473 @itemize
474 @item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
475 @item @url{http://gnupg.org/, GNU libgcrypt};
476 @item @url{http://www.gnu.org/software/make/, GNU Make}.
477 @end itemize
478
479 The following dependencies are optional:
480
481 @itemize
482 @item
483 Installing
484 @url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
485 allow you to use the @command{guix import pypi} command (@pxref{Invoking
486 guix import}). It is of
487 interest primarily for developers and not for casual users.
488 @item
489 Installing @uref{http://gnutls.org/, GnuTLS-Guile} will
490 allow you to access @code{https} URLs with the @command{guix download}
491 command (@pxref{Invoking guix download}), the @command{guix import pypi}
492 command, and the @command{guix import cpan} command. This is primarily
493 of interest to developers. @xref{Guile Preparations, how to install the
494 GnuTLS bindings for Guile,, gnutls-guile, GnuTLS-Guile}.
495 @end itemize
496
497 Unless @code{--disable-daemon} was passed to @command{configure}, the
498 following packages are also needed:
499
500 @itemize
501 @item @url{http://sqlite.org, SQLite 3};
502 @item @url{http://www.bzip.org, libbz2};
503 @item @url{http://gcc.gnu.org, GCC's g++}, with support for the
504 C++11 standard.
505 @end itemize
506
507 When a working installation of @url{http://nixos.org/nix/, the Nix package
508 manager} is available, you
509 can instead configure Guix with @code{--disable-daemon}. In that case,
510 Nix replaces the three dependencies above.
511
512 Guix is compatible with Nix, so it is possible to share the same store
513 between both. To do so, you must pass @command{configure} not only the
514 same @code{--with-store-dir} value, but also the same
515 @code{--localstatedir} value. The latter is essential because it
516 specifies where the database that stores metadata about the store is
517 located, among other things. The default values for Nix are
518 @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
519 Note that @code{--disable-daemon} is not required if
520 your goal is to share the store with Nix.
521
522 @node Running the Test Suite
523 @section Running the Test Suite
524
525 After a successful @command{configure} and @code{make} run, it is a good
526 idea to run the test suite. It can help catch issues with the setup or
527 environment, or bugs in Guix itself---and really, reporting test
528 failures is a good way to help improve the software. To run the test
529 suite, type:
530
531 @example
532 make check
533 @end example
534
535 Test cases can run in parallel: you can use the @code{-j} option of
536 GNU@tie{}make to speed things up. The first run may take a few minutes
537 on a recent machine; subsequent runs will be faster because the store
538 that is created for test purposes will already have various things in
539 cache.
540
541 It is also possible to run a subset of the tests by defining the
542 @code{TESTS} makefile variable as in this example:
543
544 @example
545 make check TESTS="tests/store.scm tests/cpio.scm"
546 @end example
547
548 Upon failure, please email @email{bug-guix@@gnu.org} and attach the
549 @file{test-suite.log} file. When @file{tests/@var{something}.scm}
550 fails, please also attach the @file{@var{something}.log} file available
551 in the top-level build directory. Please specify the Guix version being
552 used as well as version numbers of the dependencies
553 (@pxref{Requirements}) in your message.
554
555 @node Setting Up the Daemon
556 @section Setting Up the Daemon
557
558 @cindex daemon
559 Operations such as building a package or running the garbage collector
560 are all performed by a specialized process, the @dfn{build daemon}, on
561 behalf of clients. Only the daemon may access the store and its
562 associated database. Thus, any operation that manipulates the store
563 goes through the daemon. For instance, command-line tools such as
564 @command{guix package} and @command{guix build} communicate with the
565 daemon (@i{via} remote procedure calls) to instruct it what to do.
566
567 The following sections explain how to prepare the build daemon's
568 environment. See also @ref{Substitutes}, for information on how to allow
569 the daemon to download pre-built binaries.
570
571 @menu
572 * Build Environment Setup:: Preparing the isolated build environment.
573 * Daemon Offload Setup:: Offloading builds to remote machines.
574 @end menu
575
576 @node Build Environment Setup
577 @subsection Build Environment Setup
578
579 In a standard multi-user setup, Guix and its daemon---the
580 @command{guix-daemon} program---are installed by the system
581 administrator; @file{/gnu/store} is owned by @code{root} and
582 @command{guix-daemon} runs as @code{root}. Unprivileged users may use
583 Guix tools to build packages or otherwise access the store, and the
584 daemon will do it on their behalf, ensuring that the store is kept in a
585 consistent state, and allowing built packages to be shared among users.
586
587 @cindex build users
588 When @command{guix-daemon} runs as @code{root}, you may not want package
589 build processes themselves to run as @code{root} too, for obvious
590 security reasons. To avoid that, a special pool of @dfn{build users}
591 should be created for use by build processes started by the daemon.
592 These build users need not have a shell and a home directory: they will
593 just be used when the daemon drops @code{root} privileges in build
594 processes. Having several such users allows the daemon to launch
595 distinct build processes under separate UIDs, which guarantees that they
596 do not interfere with each other---an essential feature since builds are
597 regarded as pure functions (@pxref{Introduction}).
598
599 On a GNU/Linux system, a build user pool may be created like this (using
600 Bash syntax and the @code{shadow} commands):
601
602 @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
603 @c for why `-G' is needed.
604 @example
605 # groupadd --system guixbuild
606 # for i in `seq -w 1 10`;
607 do
608 useradd -g guixbuild -G guixbuild \
609 -d /var/empty -s `which nologin` \
610 -c "Guix build user $i" --system \
611 guixbuilder$i;
612 done
613 @end example
614
615 @noindent
616 The number of build users determines how many build jobs may run in
617 parallel, as specified by the @option{--max-jobs} option
618 (@pxref{Invoking guix-daemon, @option{--max-jobs}}). The
619 @code{guix-daemon} program may then be run as @code{root} with the
620 following command@footnote{If your machine uses the systemd init system,
621 dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
622 file in @file{/etc/systemd/system} will ensure that
623 @command{guix-daemon} is automatically started. Similarly, if your
624 machine uses the Upstart init system, drop the
625 @file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
626 file in @file{/etc/init}.}:
627
628 @example
629 # guix-daemon --build-users-group=guixbuild
630 @end example
631
632 @cindex chroot
633 @noindent
634 This way, the daemon starts build processes in a chroot, under one of
635 the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
636 environment contains nothing but:
637
638 @c Keep this list in sync with libstore/build.cc! -----------------------
639 @itemize
640 @item
641 a minimal @code{/dev} directory, created mostly independently from the
642 host @code{/dev}@footnote{``Mostly'', because while the set of files
643 that appear in the chroot's @code{/dev} is fixed, most of these files
644 can only be created if the host has them.};
645
646 @item
647 the @code{/proc} directory; it only shows the processes of the container
648 since a separate PID name space is used;
649
650 @item
651 @file{/etc/passwd} with an entry for the current user and an entry for
652 user @file{nobody};
653
654 @item
655 @file{/etc/group} with an entry for the user's group;
656
657 @item
658 @file{/etc/hosts} with an entry that maps @code{localhost} to
659 @code{127.0.0.1};
660
661 @item
662 a writable @file{/tmp} directory.
663 @end itemize
664
665 You can influence the directory where the daemon stores build trees
666 @i{via} the @code{TMPDIR} environment variable. However, the build tree
667 within the chroot is always called @file{/tmp/guix-build-@var{name}.drv-0},
668 where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
669 This way, the value of @code{TMPDIR} does not leak inside build
670 environments, which avoids discrepancies in cases where build processes
671 capture the name of their build tree.
672
673 @vindex http_proxy
674 The daemon also honors the @code{http_proxy} environment variable for
675 HTTP downloads it performs, be it for fixed-output derivations
676 (@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
677
678 If you are installing Guix as an unprivileged user, it is still possible
679 to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
680 However, build processes will not be isolated from one another, and not
681 from the rest of the system. Thus, build processes may interfere with
682 each other, and may access programs, libraries, and other files
683 available on the system---making it much harder to view them as
684 @emph{pure} functions.
685
686
687 @node Daemon Offload Setup
688 @subsection Using the Offload Facility
689
690 @cindex offloading
691 @cindex build hook
692 When desired, the build daemon can @dfn{offload}
693 derivation builds to other machines
694 running Guix, using the @code{offload} @dfn{build hook}. When that
695 feature is enabled, a list of user-specified build machines is read from
696 @file{/etc/guix/machines.scm}; every time a build is requested, for
697 instance via @code{guix build}, the daemon attempts to offload it to one
698 of the machines that satisfy the constraints of the derivation, in
699 particular its system type---e.g., @file{x86_64-linux}. Missing
700 prerequisites for the build are copied over SSH to the target machine,
701 which then proceeds with the build; upon success the output(s) of the
702 build are copied back to the initial machine.
703
704 The @file{/etc/guix/machines.scm} file typically looks like this:
705
706 @example
707 (list (build-machine
708 (name "eightysix.example.org")
709 (system "x86_64-linux")
710 (user "bob")
711 (speed 2.)) ; incredibly fast!
712
713 (build-machine
714 (name "meeps.example.org")
715 (system "mips64el-linux")
716 (user "alice")
717 (private-key
718 (string-append (getenv "HOME")
719 "/.lsh/identity-for-guix"))))
720 @end example
721
722 @noindent
723 In the example above we specify a list of two build machines, one for
724 the @code{x86_64} architecture and one for the @code{mips64el}
725 architecture.
726
727 In fact, this file is---not surprisingly!---a Scheme file that is
728 evaluated when the @code{offload} hook is started. Its return value
729 must be a list of @code{build-machine} objects. While this example
730 shows a fixed list of build machines, one could imagine, say, using
731 DNS-SD to return a list of potential build machines discovered in the
732 local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
733 Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
734 detailed below.
735
736 @deftp {Data Type} build-machine
737 This data type represents build machines to which the daemon may offload
738 builds. The important fields are:
739
740 @table @code
741
742 @item name
743 The host name of the remote machine.
744
745 @item system
746 The system type of the remote machine---e.g., @code{"x86_64-linux"}.
747
748 @item user
749 The user account to use when connecting to the remote machine over SSH.
750 Note that the SSH key pair must @emph{not} be passphrase-protected, to
751 allow non-interactive logins.
752
753 @end table
754
755 A number of optional fields may be specified:
756
757 @table @code
758
759 @item port
760 Port number of SSH server on the machine (default: 22).
761
762 @item private-key
763 The SSH private key file to use when connecting to the machine.
764
765 Currently offloading uses GNU@tie{}lsh as its SSH client
766 (@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must
767 be an lsh key file. This may change in the future, though.
768
769 @item parallel-builds
770 The number of builds that may run in parallel on the machine (1 by
771 default.)
772
773 @item speed
774 A ``relative speed factor''. The offload scheduler will tend to prefer
775 machines with a higher speed factor.
776
777 @item features
778 A list of strings denoting specific features supported by the machine.
779 An example is @code{"kvm"} for machines that have the KVM Linux modules
780 and corresponding hardware support. Derivations can request features by
781 name, and they will be scheduled on matching build machines.
782
783 @end table
784 @end deftp
785
786 The @code{guix} command must be in the search path on the build
787 machines, since offloading works by invoking the @code{guix archive} and
788 @code{guix build} commands. In addition, the Guix modules must be in
789 @code{$GUILE_LOAD_PATH} on the build machine---you can check whether
790 this is the case by running:
791
792 @example
793 lsh build-machine guile -c "'(use-modules (guix config))'"
794 @end example
795
796 There is one last thing to do once @file{machines.scm} is in place. As
797 explained above, when offloading, files are transferred back and forth
798 between the machine stores. For this to work, you first need to
799 generate a key pair on each machine to allow the daemon to export signed
800 archives of files from the store (@pxref{Invoking guix archive}):
801
802 @example
803 # guix archive --generate-key
804 @end example
805
806 @noindent
807 Each build machine must authorize the key of the master machine so that
808 it accepts store items it receives from the master:
809
810 @example
811 # guix archive --authorize < master-public-key.txt
812 @end example
813
814 @noindent
815 Likewise, the master machine must authorize the key of each build machine.
816
817 All the fuss with keys is here to express pairwise mutual trust
818 relations between the master and the build machines. Concretely, when
819 the master receives files from a build machine (and @i{vice versa}), its
820 build daemon can make sure they are genuine, have not been tampered
821 with, and that they are signed by an authorized key.
822
823
824 @node Invoking guix-daemon
825 @section Invoking @command{guix-daemon}
826
827 The @command{guix-daemon} program implements all the functionality to
828 access the store. This includes launching build processes, running the
829 garbage collector, querying the availability of a build result, etc. It
830 is normally run as @code{root} like this:
831
832 @example
833 # guix-daemon --build-users-group=guixbuild
834 @end example
835
836 @noindent
837 For details on how to set it up, @pxref{Setting Up the Daemon}.
838
839 @cindex chroot
840 @cindex container, build environment
841 @cindex build environment
842 @cindex reproducible builds
843 By default, @command{guix-daemon} launches build processes under
844 different UIDs, taken from the build group specified with
845 @code{--build-users-group}. In addition, each build process is run in a
846 chroot environment that only contains the subset of the store that the
847 build process depends on, as specified by its derivation
848 (@pxref{Programming Interface, derivation}), plus a set of specific
849 system directories. By default, the latter contains @file{/dev} and
850 @file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
851 @dfn{container}: in addition to having its own file system tree, it has
852 a separate mount name space, its own PID name space, network name space,
853 etc. This helps achieve reproducible builds (@pxref{Features}).
854
855 When the daemon performs a build on behalf of the user, it creates a
856 build directory under @file{/tmp} or under the directory specified by
857 its @code{TMPDIR} environment variable; this directory is shared with
858 the container for the duration of the build. Be aware that using a
859 directory other than @file{/tmp} can affect build results---for example,
860 with a longer directory name, a build process that uses Unix-domain
861 sockets might hit the name length limitation for @code{sun_path}, which
862 it would otherwise not hit.
863
864 The build directory is automatically deleted upon completion, unless the
865 build failed and the client specified @option{--keep-failed}
866 (@pxref{Invoking guix build, @option{--keep-failed}}).
867
868 The following command-line options are supported:
869
870 @table @code
871 @item --build-users-group=@var{group}
872 Take users from @var{group} to run build processes (@pxref{Setting Up
873 the Daemon, build users}).
874
875 @item --no-substitutes
876 @cindex substitutes
877 Do not use substitutes for build products. That is, always build things
878 locally instead of allowing downloads of pre-built binaries
879 (@pxref{Substitutes}).
880
881 By default substitutes are used, unless the client---such as the
882 @command{guix package} command---is explicitly invoked with
883 @code{--no-substitutes}.
884
885 When the daemon runs with @code{--no-substitutes}, clients can still
886 explicitly enable substitution @i{via} the @code{set-build-options}
887 remote procedure call (@pxref{The Store}).
888
889 @item --substitute-urls=@var{urls}
890 @anchor{daemon-substitute-urls}
891 Consider @var{urls} the default whitespace-separated list of substitute
892 source URLs. When this option is omitted, @indicateurl{http://hydra.gnu.org}
893 is used.
894
895 This means that substitutes may be downloaded from @var{urls}, as long
896 as they are signed by a trusted signature (@pxref{Substitutes}).
897
898 @cindex build hook
899 @item --no-build-hook
900 Do not use the @dfn{build hook}.
901
902 The build hook is a helper program that the daemon can start and to
903 which it submits build requests. This mechanism is used to offload
904 builds to other machines (@pxref{Daemon Offload Setup}).
905
906 @item --cache-failures
907 Cache build failures. By default, only successful builds are cached.
908
909 When this option is used, @command{guix gc --list-failures} can be used
910 to query the set of store items marked as failed; @command{guix gc
911 --clear-failures} removes store items from the set of cached failures.
912 @xref{Invoking guix gc}.
913
914 @item --cores=@var{n}
915 @itemx -c @var{n}
916 Use @var{n} CPU cores to build each derivation; @code{0} means as many
917 as available.
918
919 The default value is @code{0}, but it may be overridden by clients, such
920 as the @code{--cores} option of @command{guix build} (@pxref{Invoking
921 guix build}).
922
923 The effect is to define the @code{NIX_BUILD_CORES} environment variable
924 in the build process, which can then use it to exploit internal
925 parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
926
927 @item --max-jobs=@var{n}
928 @itemx -M @var{n}
929 Allow at most @var{n} build jobs in parallel. The default value is
930 @code{1}. Setting it to @code{0} means that no builds will be performed
931 locally; instead, the daemon will offload builds (@pxref{Daemon Offload
932 Setup}), or simply fail.
933
934 @item --rounds=@var{N}
935 Build each derivation @var{n} times in a row, and raise an error if
936 consecutive build results are not bit-for-bit identical. Note that this
937 setting can be overridden by clients such as @command{guix build}
938 (@pxref{Invoking guix build}).
939
940 @item --debug
941 Produce debugging output.
942
943 This is useful to debug daemon start-up issues, but then it may be
944 overridden by clients, for example the @code{--verbosity} option of
945 @command{guix build} (@pxref{Invoking guix build}).
946
947 @item --chroot-directory=@var{dir}
948 Add @var{dir} to the build chroot.
949
950 Doing this may change the result of build processes---for instance if
951 they use optional dependencies found in @var{dir} when it is available,
952 and not otherwise. For that reason, it is not recommended to do so.
953 Instead, make sure that each derivation declares all the inputs that it
954 needs.
955
956 @item --disable-chroot
957 Disable chroot builds.
958
959 Using this option is not recommended since, again, it would allow build
960 processes to gain access to undeclared dependencies. It is necessary,
961 though, when @command{guix-daemon} is running under an unprivileged user
962 account.
963
964 @item --disable-log-compression
965 Disable compression of the build logs.
966
967 Unless @code{--lose-logs} is used, all the build logs are kept in the
968 @var{localstatedir}. To save space, the daemon automatically compresses
969 them with bzip2 by default. This option disables that.
970
971 @item --disable-deduplication
972 @cindex deduplication
973 Disable automatic file ``deduplication'' in the store.
974
975 By default, files added to the store are automatically ``deduplicated'':
976 if a newly added file is identical to another one found in the store,
977 the daemon makes the new file a hard link to the other file. This can
978 noticeably reduce disk usage, at the expense of slightly increased
979 input/output load at the end of a build process. This option disables
980 this optimization.
981
982 @item --gc-keep-outputs[=yes|no]
983 Tell whether the garbage collector (GC) must keep outputs of live
984 derivations.
985
986 When set to ``yes'', the GC will keep the outputs of any live derivation
987 available in the store---the @code{.drv} files. The default is ``no'',
988 meaning that derivation outputs are kept only if they are GC roots.
989
990 @item --gc-keep-derivations[=yes|no]
991 Tell whether the garbage collector (GC) must keep derivations
992 corresponding to live outputs.
993
994 When set to ``yes'', as is the case by default, the GC keeps
995 derivations---i.e., @code{.drv} files---as long as at least one of their
996 outputs is live. This allows users to keep track of the origins of
997 items in their store. Setting it to ``no'' saves a bit of disk space.
998
999 Note that when both @code{--gc-keep-derivations} and
1000 @code{--gc-keep-outputs} are used, the effect is to keep all the build
1001 prerequisites (the sources, compiler, libraries, and other build-time
1002 tools) of live objects in the store, regardless of whether these
1003 prerequisites are live. This is convenient for developers since it
1004 saves rebuilds or downloads.
1005
1006 @item --impersonate-linux-2.6
1007 On Linux-based systems, impersonate Linux 2.6. This means that the
1008 kernel's @code{uname} system call will report 2.6 as the release number.
1009
1010 This might be helpful to build programs that (usually wrongfully) depend
1011 on the kernel version number.
1012
1013 @item --lose-logs
1014 Do not keep build logs. By default they are kept under
1015 @code{@var{localstatedir}/guix/log}.
1016
1017 @item --system=@var{system}
1018 Assume @var{system} as the current system type. By default it is the
1019 architecture/kernel pair found at configure time, such as
1020 @code{x86_64-linux}.
1021
1022 @item --listen=@var{socket}
1023 Listen for connections on @var{socket}, the file name of a Unix-domain
1024 socket. The default socket is
1025 @file{@var{localstatedir}/daemon-socket/socket}. This option is only
1026 useful in exceptional circumstances, such as if you need to run several
1027 daemons on the same machine.
1028 @end table
1029
1030
1031 @node Application Setup
1032 @section Application Setup
1033
1034 When using Guix on top of GNU/Linux distribution other than GuixSD---a
1035 so-called @dfn{foreign distro}---a few additional steps are needed to
1036 get everything in place. Here are some of them.
1037
1038 @subsection Locales
1039
1040 @anchor{locales-and-locpath}
1041 @cindex locales, when not on GuixSD
1042 @vindex LOCPATH
1043 @vindex GUIX_LOCPATH
1044 Packages installed @i{via} Guix will not use the locale data of the
1045 host system. Instead, you must first install one of the locale packages
1046 available with Guix and then define the @code{GUIX_LOCPATH} environment
1047 variable:
1048
1049 @example
1050 $ guix package -i glibc-locales
1051 $ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
1052 @end example
1053
1054 Note that the @code{glibc-locales} package contains data for all the
1055 locales supported by the GNU@tie{}libc and weighs in at around
1056 110@tie{}MiB. Alternatively, the @code{glibc-utf8-locales} is smaller but
1057 limited to a few UTF-8 locales.
1058
1059 The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1060 (@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1061 Manual}). There are two important differences though:
1062
1063 @enumerate
1064 @item
1065 @code{GUIX_LOCPATH} is honored only by the libc in Guix, and not by the libc
1066 provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
1067 to make sure the programs of the foreign distro will not end up loading
1068 incompatible locale data.
1069
1070 @item
1071 libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1072 @code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1073 should your Guix profile contain a mixture of programs linked against
1074 different libc version, each libc version will only try to load locale
1075 data in the right format.
1076 @end enumerate
1077
1078 This is important because the locale data format used by different libc
1079 versions may be incompatible.
1080
1081 @subsection X11 Fonts
1082
1083 The majority of graphical applications use Fontconfig to locate and
1084 load fonts and perform X11-client-side rendering. The @code{fontconfig}
1085 package in Guix looks for fonts in @file{$HOME/.guix-profile}
1086 by default. Thus, to allow graphical applications installed with Guix
1087 to display fonts, you have to install fonts with Guix as well.
1088 Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
1089 @code{font-gnu-freefont-ttf}.
1090
1091 To display text written in Chinese languages, Japanese, or Korean in
1092 graphical applications, consider installing
1093 @code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1094 has multiple outputs, one per language family (@pxref{Packages with
1095 Multiple Outputs}). For instance, the following command installs fonts
1096 for Chinese languages:
1097
1098 @example
1099 guix package -i font-adobe-source-han-sans:cn
1100 @end example
1101
1102 @subsection Emacs Packages
1103
1104 When you install Emacs packages with Guix, the elisp files may be placed
1105 either in @file{$HOME/.guix-profile/share/emacs/site-lisp/} or in
1106 sub-directories of
1107 @file{$HOME/.guix-profile/share/emacs/site-lisp/guix.d/}. The latter
1108 directory exists because potentially there may exist thousands of Emacs
1109 packages and storing all their files in a single directory may be not
1110 reliable (because of name conflicts). So we think using a separate
1111 directory for each package is a good idea. It is very similar to how
1112 the Emacs package system organizes the file structure (@pxref{Package
1113 Files,,, emacs, The GNU Emacs Manual}).
1114
1115 By default, Emacs (installed with Guix) ``knows'' where these packages
1116 are placed, so you do not need to perform any configuration. If, for
1117 some reason, you want to avoid auto-loading Emacs packages installed
1118 with Guix, you can do so by running Emacs with @code{--no-site-file}
1119 option (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
1120
1121 @c TODO What else?
1122
1123 @c *********************************************************************
1124 @node Package Management
1125 @chapter Package Management
1126
1127 The purpose of GNU Guix is to allow users to easily install, upgrade, and
1128 remove software packages, without having to know about their build
1129 procedures or dependencies. Guix also goes beyond this obvious set of
1130 features.
1131
1132 This chapter describes the main features of Guix, as well as the package
1133 management tools it provides. Two user interfaces are provided for
1134 routine package management tasks: A command-line interface described below
1135 (@pxref{Invoking guix package, @code{guix package}}), as well as a visual user
1136 interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}).
1137
1138 @menu
1139 * Features:: How Guix will make your life brighter.
1140 * Invoking guix package:: Package installation, removal, etc.
1141 * Substitutes:: Downloading pre-built binaries.
1142 * Packages with Multiple Outputs:: Single source package, multiple outputs.
1143 * Invoking guix gc:: Running the garbage collector.
1144 * Invoking guix pull:: Fetching the latest Guix and distribution.
1145 * Invoking guix archive:: Exporting and importing store files.
1146 @end menu
1147
1148 @node Features
1149 @section Features
1150
1151 When using Guix, each package ends up in the @dfn{package store}, in its
1152 own directory---something that resembles
1153 @file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
1154 (note that Guix comes with an Emacs extension to shorten those file
1155 names, @pxref{Emacs Prettify}.)
1156
1157 Instead of referring to these directories, users have their own
1158 @dfn{profile}, which points to the packages that they actually want to
1159 use. These profiles are stored within each user's home directory, at
1160 @code{$HOME/.guix-profile}.
1161
1162 For example, @code{alice} installs GCC 4.7.2. As a result,
1163 @file{/home/alice/.guix-profile/bin/gcc} points to
1164 @file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
1165 @code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1166 simply continues to point to
1167 @file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
1168 coexist on the same system without any interference.
1169
1170 The @command{guix package} command is the central tool to manage
1171 packages (@pxref{Invoking guix package}). It operates on the per-user
1172 profiles, and can be used @emph{with normal user privileges}.
1173
1174 The command provides the obvious install, remove, and upgrade
1175 operations. Each invocation is actually a @emph{transaction}: either
1176 the specified operation succeeds, or nothing happens. Thus, if the
1177 @command{guix package} process is terminated during the transaction,
1178 or if a power outage occurs during the transaction, then the user's
1179 profile remains in its previous state, and remains usable.
1180
1181 In addition, any package transaction may be @emph{rolled back}. So, if,
1182 for example, an upgrade installs a new version of a package that turns
1183 out to have a serious bug, users may roll back to the previous instance
1184 of their profile, which was known to work well. Similarly, the global
1185 system configuration is subject to transactional upgrades and roll-back
1186 (@pxref{Using the Configuration System}).
1187
1188 All packages in the package store may be @emph{garbage-collected}.
1189 Guix can determine which packages are still referenced by user
1190 profiles, and remove those that are provably no longer referenced
1191 (@pxref{Invoking guix gc}). Users may also explicitly remove old
1192 generations of their profile so that the packages they refer to can be
1193 collected.
1194
1195 @cindex reproducibility
1196 @cindex reproducible builds
1197 Finally, Guix takes a @dfn{purely functional} approach to package
1198 management, as described in the introduction (@pxref{Introduction}).
1199 Each @file{/gnu/store} package directory name contains a hash of all the
1200 inputs that were used to build that package---compiler, libraries, build
1201 scripts, etc. This direct correspondence allows users to make sure a
1202 given package installation matches the current state of their
1203 distribution. It also helps maximize @dfn{build reproducibility}:
1204 thanks to the isolated build environments that are used, a given build
1205 is likely to yield bit-identical files when performed on different
1206 machines (@pxref{Invoking guix-daemon, container}).
1207
1208 @cindex substitutes
1209 This foundation allows Guix to support @dfn{transparent binary/source
1210 deployment}. When a pre-built binary for a @file{/gnu/store} item is
1211 available from an external source---a @dfn{substitute}, Guix just
1212 downloads it and unpacks it;
1213 otherwise, it builds the package from source, locally
1214 (@pxref{Substitutes}).
1215
1216 Control over the build environment is a feature that is also useful for
1217 developers. The @command{guix environment} command allows developers of
1218 a package to quickly set up the right development environment for their
1219 package, without having to manually install the dependencies of the
1220 package into their profile (@pxref{Invoking guix environment}).
1221
1222 @node Invoking guix package
1223 @section Invoking @command{guix package}
1224
1225 The @command{guix package} command is the tool that allows users to
1226 install, upgrade, and remove packages, as well as rolling back to
1227 previous configurations. It operates only on the user's own profile,
1228 and works with normal user privileges (@pxref{Features}). Its syntax
1229 is:
1230
1231 @example
1232 guix package @var{options}
1233 @end example
1234
1235 Primarily, @var{options} specifies the operations to be performed during
1236 the transaction. Upon completion, a new profile is created, but
1237 previous @dfn{generations} of the profile remain available, should the user
1238 want to roll back.
1239
1240 For example, to remove @code{lua} and install @code{guile} and
1241 @code{guile-cairo} in a single transaction:
1242
1243 @example
1244 guix package -r lua -i guile guile-cairo
1245 @end example
1246
1247 @command{guix package} also supports a @dfn{declarative approach}
1248 whereby the user specifies the exact set of packages to be available and
1249 passes it @i{via} the @option{--manifest} option
1250 (@pxref{profile-manifest, @option{--manifest}}).
1251
1252 For each user, a symlink to the user's default profile is automatically
1253 created in @file{$HOME/.guix-profile}. This symlink always points to the
1254 current generation of the user's default profile. Thus, users can add
1255 @file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1256 variable, and so on.
1257 @cindex search paths
1258 If you are not using the Guix System Distribution, consider adding the
1259 following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1260 Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1261 shells get all the right environment variable definitions:
1262
1263 @example
1264 GUIX_PROFILE="$HOME/.guix-profile" \
1265 source "$HOME/.guix-profile/etc/profile"
1266 @end example
1267
1268 In a multi-user setup, user profiles are stored in a place registered as
1269 a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1270 to (@pxref{Invoking guix gc}). That directory is normally
1271 @code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1272 @var{localstatedir} is the value passed to @code{configure} as
1273 @code{--localstatedir}, and @var{user} is the user name. The
1274 @file{per-user} directory is created when @command{guix-daemon} is
1275 started, and the @var{user} sub-directory is created by @command{guix
1276 package}.
1277
1278 The @var{options} can be among the following:
1279
1280 @table @code
1281
1282 @item --install=@var{package} @dots{}
1283 @itemx -i @var{package} @dots{}
1284 Install the specified @var{package}s.
1285
1286 Each @var{package} may specify either a simple package name, such as
1287 @code{guile}, or a package name followed by a hyphen and version number,
1288 such as @code{guile-1.8.8} or simply @code{guile-1.8} (in the latter
1289 case, the newest version prefixed by @code{1.8} is selected.)
1290
1291 If no version number is specified, the
1292 newest available version will be selected. In addition, @var{package}
1293 may contain a colon, followed by the name of one of the outputs of the
1294 package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
1295 (@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1296 name (and optionally version) are searched for among the GNU
1297 distribution modules (@pxref{Package Modules}).
1298
1299 @cindex propagated inputs
1300 Sometimes packages have @dfn{propagated inputs}: these are dependencies
1301 that automatically get installed along with the required package
1302 (@pxref{package-propagated-inputs, @code{propagated-inputs} in
1303 @code{package} objects}, for information about propagated inputs in
1304 package definitions).
1305
1306 @anchor{package-cmd-propagated-inputs}
1307 An example is the GNU MPC library: its C header files refer to those of
1308 the GNU MPFR library, which in turn refer to those of the GMP library.
1309 Thus, when installing MPC, the MPFR and GMP libraries also get installed
1310 in the profile; removing MPC also removes MPFR and GMP---unless they had
1311 also been explicitly installed by the user.
1312
1313 Besides, packages sometimes rely on the definition of environment
1314 variables for their search paths (see explanation of
1315 @code{--search-paths} below). Any missing or possibly incorrect
1316 environment variable definitions are reported here.
1317
1318 @c XXX: keep me up-to-date
1319 Finally, when installing a GNU package, the tool reports the
1320 availability of a newer upstream version. In the future, it may provide
1321 the option of installing directly from the upstream version, even if
1322 that version is not yet in the distribution.
1323
1324 @item --install-from-expression=@var{exp}
1325 @itemx -e @var{exp}
1326 Install the package @var{exp} evaluates to.
1327
1328 @var{exp} must be a Scheme expression that evaluates to a
1329 @code{<package>} object. This option is notably useful to disambiguate
1330 between same-named variants of a package, with expressions such as
1331 @code{(@@ (gnu packages base) guile-final)}.
1332
1333 Note that this option installs the first output of the specified
1334 package, which may be insufficient when needing a specific output of a
1335 multiple-output package.
1336
1337 @item --install-from-file=@var{file}
1338 @itemx -f @var{file}
1339 Install the package that the code within @var{file} evaluates to.
1340
1341 As an example, @var{file} might contain a definition like this
1342 (@pxref{Defining Packages}):
1343
1344 @example
1345 @verbatiminclude package-hello.scm
1346 @end example
1347
1348 Developers may find it useful to include such a @file{package.scm} file
1349 in the root of their project source tree that can be used to test
1350 development snapshots and create reproducible development environments
1351 (@pxref{Invoking guix environment}).
1352
1353 @item --remove=@var{package} @dots{}
1354 @itemx -r @var{package} @dots{}
1355 Remove the specified @var{package}s.
1356
1357 As for @code{--install}, each @var{package} may specify a version number
1358 and/or output name in addition to the package name. For instance,
1359 @code{-r glibc:debug} would remove the @code{debug} output of
1360 @code{glibc}.
1361
1362 @item --upgrade[=@var{regexp} @dots{}]
1363 @itemx -u [@var{regexp} @dots{}]
1364 Upgrade all the installed packages. If one or more @var{regexp}s are
1365 specified, upgrade only installed packages whose name matches a
1366 @var{regexp}. Also see the @code{--do-not-upgrade} option below.
1367
1368 Note that this upgrades package to the latest version of packages found
1369 in the distribution currently installed. To update your distribution,
1370 you should regularly run @command{guix pull} (@pxref{Invoking guix
1371 pull}).
1372
1373 @item --do-not-upgrade[=@var{regexp} @dots{}]
1374 When used together with the @code{--upgrade} option, do @emph{not}
1375 upgrade any packages whose name matches a @var{regexp}. For example, to
1376 upgrade all packages in the current profile except those containing the
1377 substring ``emacs'':
1378
1379 @example
1380 $ guix package --upgrade . --do-not-upgrade emacs
1381 @end example
1382
1383 @item @anchor{profile-manifest}--manifest=@var{file}
1384 @itemx -m @var{file}
1385 @cindex profile declaration
1386 @cindex profile manifest
1387 Create a new generation of the profile from the manifest object
1388 returned by the Scheme code in @var{file}.
1389
1390 This allows you to @emph{declare} the profile's contents rather than
1391 constructing it through a sequence of @code{--install} and similar
1392 commands. The advantage is that @var{file} can be put under version
1393 control, copied to different machines to reproduce the same profile, and
1394 so on.
1395
1396 @c FIXME: Add reference to (guix profile) documentation when available.
1397 @var{file} must return a @dfn{manifest} object, which is roughly a list
1398 of packages:
1399
1400 @findex packages->manifest
1401 @example
1402 (use-package-modules guile emacs)
1403
1404 (packages->manifest
1405 (list emacs
1406 guile-2.0
1407 ;; Use a specific package output.
1408 (list guile-2.0 "debug")))
1409 @end example
1410
1411 @item --roll-back
1412 Roll back to the previous @dfn{generation} of the profile---i.e., undo
1413 the last transaction.
1414
1415 When combined with options such as @code{--install}, roll back occurs
1416 before any other actions.
1417
1418 When rolling back from the first generation that actually contains
1419 installed packages, the profile is made to point to the @dfn{zeroth
1420 generation}, which contains no files apart from its own metadata.
1421
1422 After having rolled back, installing, removing, or upgrading packages
1423 overwrites previous future generations. Thus, the history of the
1424 generations in a profile is always linear.
1425
1426 @item --switch-generation=@var{pattern}
1427 @itemx -S @var{pattern}
1428 Switch to a particular generation defined by @var{pattern}.
1429
1430 @var{pattern} may be either a generation number or a number prefixed
1431 with ``+'' or ``-''. The latter means: move forward/backward by a
1432 specified number of generations. For example, if you want to return to
1433 the latest generation after @code{--roll-back}, use
1434 @code{--switch-generation=+1}.
1435
1436 The difference between @code{--roll-back} and
1437 @code{--switch-generation=-1} is that @code{--switch-generation} will
1438 not make a zeroth generation, so if a specified generation does not
1439 exist, the current generation will not be changed.
1440
1441 @item --search-paths[=@var{kind}]
1442 @cindex search paths
1443 Report environment variable definitions, in Bash syntax, that may be
1444 needed in order to use the set of installed packages. These environment
1445 variables are used to specify @dfn{search paths} for files used by some
1446 of the installed packages.
1447
1448 For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1449 environment variables to be defined so it can look for headers and
1450 libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1451 Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1452 library are installed in the profile, then @code{--search-paths} will
1453 suggest setting these variables to @code{@var{profile}/include} and
1454 @code{@var{profile}/lib}, respectively.
1455
1456 The typical use case is to define these environment variables in the
1457 shell:
1458
1459 @example
1460 $ eval `guix package --search-paths`
1461 @end example
1462
1463 @var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1464 meaning that the returned environment variable definitions will either
1465 be exact settings, or prefixes or suffixes of the current value of these
1466 variables. When omitted, @var{kind} defaults to @code{exact}.
1467
1468 This option can also be used to compute the @emph{combined} search paths
1469 of several profiles. Consider this example:
1470
1471 @example
1472 $ guix package -p foo -i guile
1473 $ guix package -p bar -i guile-json
1474 $ guix package -p foo -p bar --search-paths
1475 @end example
1476
1477 The last command above reports about the @code{GUILE_LOAD_PATH}
1478 variable, even though, taken individually, neither @file{foo} nor
1479 @file{bar} would lead to that recommendation.
1480
1481
1482 @item --profile=@var{profile}
1483 @itemx -p @var{profile}
1484 Use @var{profile} instead of the user's default profile.
1485
1486 @item --verbose
1487 Produce verbose output. In particular, emit the build log of the
1488 environment on the standard error port.
1489
1490 @item --bootstrap
1491 Use the bootstrap Guile to build the profile. This option is only
1492 useful to distribution developers.
1493
1494 @end table
1495
1496 In addition to these actions, @command{guix package} supports the
1497 following options to query the current state of a profile, or the
1498 availability of packages:
1499
1500 @table @option
1501
1502 @item --search=@var{regexp}
1503 @itemx -s @var{regexp}
1504 @cindex searching for packages
1505 List the available packages whose name, synopsis, or description matches
1506 @var{regexp}. Print all the metadata of matching packages in
1507 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1508 GNU recutils manual}).
1509
1510 This allows specific fields to be extracted using the @command{recsel}
1511 command, for instance:
1512
1513 @example
1514 $ guix package -s malloc | recsel -p name,version
1515 name: glibc
1516 version: 2.17
1517
1518 name: libgc
1519 version: 7.2alpha6
1520 @end example
1521
1522 Similarly, to show the name of all the packages available under the
1523 terms of the GNU@tie{}LGPL version 3:
1524
1525 @example
1526 $ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1527 name: elfutils
1528
1529 name: gmp
1530 @dots{}
1531 @end example
1532
1533 It is also possible to refine search results using several @code{-s}
1534 flags. For example, the following command returns a list of board
1535 games:
1536
1537 @example
1538 $ guix package -s '\<board\>' -s game | recsel -p name
1539 name: gnubg
1540 @dots{}
1541 @end example
1542
1543 If we were to omit @code{-s game}, we would also get software packages
1544 that deal with printed circuit boards; removing the angle brackets
1545 around @code{board} would further add packages that have to do with
1546 keyboards.
1547
1548 And now for a more elaborate example. The following command searches
1549 for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1550 libraries, and prints the name and synopsis of the matching packages:
1551
1552 @example
1553 $ guix package -s crypto -s library | \
1554 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1555 @end example
1556
1557 @noindent
1558 @xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1559 information on @dfn{selection expressions} for @code{recsel -e}.
1560
1561 @item --show=@var{package}
1562 Show details about @var{package}, taken from the list of available packages, in
1563 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1564 recutils manual}).
1565
1566 @example
1567 $ guix package --show=python | recsel -p name,version
1568 name: python
1569 version: 2.7.6
1570
1571 name: python
1572 version: 3.3.5
1573 @end example
1574
1575 You may also specify the full name of a package to only get details about a
1576 specific version of it:
1577 @example
1578 $ guix package --show=python-3.3.5 | recsel -p name,version
1579 name: python
1580 version: 3.3.5
1581 @end example
1582
1583
1584
1585 @item --list-installed[=@var{regexp}]
1586 @itemx -I [@var{regexp}]
1587 List the currently installed packages in the specified profile, with the
1588 most recently installed packages shown last. When @var{regexp} is
1589 specified, list only installed packages whose name matches @var{regexp}.
1590
1591 For each installed package, print the following items, separated by
1592 tabs: the package name, its version string, the part of the package that
1593 is installed (for instance, @code{out} for the default output,
1594 @code{include} for its headers, etc.), and the path of this package in
1595 the store.
1596
1597 @item --list-available[=@var{regexp}]
1598 @itemx -A [@var{regexp}]
1599 List packages currently available in the distribution for this system
1600 (@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1601 installed packages whose name matches @var{regexp}.
1602
1603 For each package, print the following items separated by tabs: its name,
1604 its version string, the parts of the package (@pxref{Packages with
1605 Multiple Outputs}), and the source location of its definition.
1606
1607 @item --list-generations[=@var{pattern}]
1608 @itemx -l [@var{pattern}]
1609 Return a list of generations along with their creation dates; for each
1610 generation, show the installed packages, with the most recently
1611 installed packages shown last. Note that the zeroth generation is never
1612 shown.
1613
1614 For each installed package, print the following items, separated by
1615 tabs: the name of a package, its version string, the part of the package
1616 that is installed (@pxref{Packages with Multiple Outputs}), and the
1617 location of this package in the store.
1618
1619 When @var{pattern} is used, the command returns only matching
1620 generations. Valid patterns include:
1621
1622 @itemize
1623 @item @emph{Integers and comma-separated integers}. Both patterns denote
1624 generation numbers. For instance, @code{--list-generations=1} returns
1625 the first one.
1626
1627 And @code{--list-generations=1,8,2} outputs three generations in the
1628 specified order. Neither spaces nor trailing commas are allowed.
1629
1630 @item @emph{Ranges}. @code{--list-generations=2..9} prints the
1631 specified generations and everything in between. Note that the start of
1632 a range must be smaller than its end.
1633
1634 It is also possible to omit the endpoint. For example,
1635 @code{--list-generations=2..}, returns all generations starting from the
1636 second one.
1637
1638 @item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1639 or months by passing an integer along with the first letter of the
1640 duration. For example, @code{--list-generations=20d} lists generations
1641 that are up to 20 days old.
1642 @end itemize
1643
1644 @item --delete-generations[=@var{pattern}]
1645 @itemx -d [@var{pattern}]
1646 When @var{pattern} is omitted, delete all generations except the current
1647 one.
1648
1649 This command accepts the same patterns as @option{--list-generations}.
1650 When @var{pattern} is specified, delete the matching generations. When
1651 @var{pattern} specifies a duration, generations @emph{older} than the
1652 specified duration match. For instance, @code{--delete-generations=1m}
1653 deletes generations that are more than one month old.
1654
1655 If the current generation matches, it is @emph{not} deleted. Also, the
1656 zeroth generation is never deleted.
1657
1658 Note that deleting generations prevents rolling back to them.
1659 Consequently, this command must be used with care.
1660
1661 @end table
1662
1663 Finally, since @command{guix package} may actually start build
1664 processes, it supports all the common build options (@pxref{Common Build
1665 Options}). It also supports package transformation options, such as
1666 @option{--with-source} (@pxref{Package Transformation Options}).
1667 However, note that package transformations are lost when upgrading; to
1668 preserve transformations across upgrades, you should define your own
1669 package variant in a Guile module and add it to @code{GUIX_PACKAGE_PATH}
1670 (@pxref{Defining Packages}).
1671
1672
1673 @node Substitutes
1674 @section Substitutes
1675
1676 @cindex substitutes
1677 @cindex pre-built binaries
1678 Guix supports transparent source/binary deployment, which means that it
1679 can either build things locally, or download pre-built items from a
1680 server. We call these pre-built items @dfn{substitutes}---they are
1681 substitutes for local build results. In many cases, downloading a
1682 substitute is much faster than building things locally.
1683
1684 Substitutes can be anything resulting from a derivation build
1685 (@pxref{Derivations}). Of course, in the common case, they are
1686 pre-built package binaries, but source tarballs, for instance, which
1687 also result from derivation builds, can be available as substitutes.
1688
1689 The @code{hydra.gnu.org} server is a front-end to a build farm that
1690 builds packages from the GNU distribution continuously for some
1691 architectures, and makes them available as substitutes (@pxref{Emacs
1692 Hydra}, for information on how to query the continuous integration
1693 server). This is the
1694 default source of substitutes; it can be overridden by passing the
1695 @option{--substitute-urls} option either to @command{guix-daemon}
1696 (@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1697 or to client tools such as @command{guix package}
1698 (@pxref{client-substitute-urls,, client @option{--substitute-urls}
1699 option}).
1700
1701 @cindex security
1702 @cindex digital signatures
1703 To allow Guix to download substitutes from @code{hydra.gnu.org}, you
1704 must add its public key to the access control list (ACL) of archive
1705 imports, using the @command{guix archive} command (@pxref{Invoking guix
1706 archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1707 be compromised and to serve genuine substitutes.
1708
1709 This public key is installed along with Guix, in
1710 @code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1711 the installation prefix of Guix. If you installed Guix from source,
1712 make sure you checked the GPG signature of
1713 @file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1714 Then, you can run something like this:
1715
1716 @example
1717 # guix archive --authorize < hydra.gnu.org.pub
1718 @end example
1719
1720 Once this is in place, the output of a command like @code{guix build}
1721 should change from something like:
1722
1723 @example
1724 $ guix build emacs --dry-run
1725 The following derivations would be built:
1726 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1727 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1728 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1729 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1730 @dots{}
1731 @end example
1732
1733 @noindent
1734 to something like:
1735
1736 @example
1737 $ guix build emacs --dry-run
1738 The following files would be downloaded:
1739 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1740 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1741 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1742 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1743 @dots{}
1744 @end example
1745
1746 @noindent
1747 This indicates that substitutes from @code{hydra.gnu.org} are usable and
1748 will be downloaded, when possible, for future builds.
1749
1750 Guix ignores substitutes that are not signed, or that are not signed by
1751 one of the keys listed in the ACL. It also detects and raises an error
1752 when attempting to use a substitute that has been tampered with.
1753
1754 @vindex http_proxy
1755 Substitutes are downloaded over HTTP. The @code{http_proxy} environment
1756 variable can be set in the environment of @command{guix-daemon} and is
1757 honored for downloads of substitutes. Note that the value of
1758 @code{http_proxy} in the environment where @command{guix build},
1759 @command{guix package}, and other client commands are run has
1760 @emph{absolutely no effect}.
1761
1762 The substitute mechanism can be disabled globally by running
1763 @code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1764 guix-daemon}). It can also be disabled temporarily by passing the
1765 @code{--no-substitutes} option to @command{guix package}, @command{guix
1766 build}, and other command-line tools.
1767
1768
1769 Today, each individual's control over their own computing is at the
1770 mercy of institutions, corporations, and groups with enough power and
1771 determination to subvert the computing infrastructure and exploit its
1772 weaknesses. While using @code{hydra.gnu.org} substitutes can be
1773 convenient, we encourage users to also build on their own, or even run
1774 their own build farm, such that @code{hydra.gnu.org} is less of an
1775 interesting target. One way to help is by publishing the software you
1776 build using @command{guix publish} so that others have one more choice
1777 of server to download substitutes from (@pxref{Invoking guix publish}).
1778
1779 Guix has the foundations to maximize build reproducibility
1780 (@pxref{Features}). In most cases, independent builds of a given
1781 package or derivation should yield bit-identical results. Thus, through
1782 a diverse set of independent package builds, we can strengthen the
1783 integrity of our systems. The @command{guix challenge} command aims to
1784 help users assess substitute servers, and to assist developers in
1785 finding out about non-deterministic package builds (@pxref{Invoking guix
1786 challenge}). Similarly, the @option{--check} option of @command{guix
1787 build} allows users to check whether previously-installed substitutes
1788 are genuine by rebuilding them locally (@pxref{build-check,
1789 @command{guix build --check}}).
1790
1791 In the future, we want Guix to have support to publish and retrieve
1792 binaries to/from other users, in a peer-to-peer fashion. If you would
1793 like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1794
1795
1796 @node Packages with Multiple Outputs
1797 @section Packages with Multiple Outputs
1798
1799 @cindex multiple-output packages
1800 @cindex package outputs
1801
1802 Often, packages defined in Guix have a single @dfn{output}---i.e., the
1803 source package leads to exactly one directory in the store. When running
1804 @command{guix package -i glibc}, one installs the default output of the
1805 GNU libc package; the default output is called @code{out}, but its name
1806 can be omitted as shown in this command. In this particular case, the
1807 default output of @code{glibc} contains all the C header files, shared
1808 libraries, static libraries, Info documentation, and other supporting
1809 files.
1810
1811 Sometimes it is more appropriate to separate the various types of files
1812 produced from a single source package into separate outputs. For
1813 instance, the GLib C library (used by GTK+ and related packages)
1814 installs more than 20 MiB of reference documentation as HTML pages.
1815 To save space for users who do not need it, the documentation goes to a
1816 separate output, called @code{doc}. To install the main GLib output,
1817 which contains everything but the documentation, one would run:
1818
1819 @example
1820 guix package -i glib
1821 @end example
1822
1823 The command to install its documentation is:
1824
1825 @example
1826 guix package -i glib:doc
1827 @end example
1828
1829 Some packages install programs with different ``dependency footprints''.
1830 For instance, the WordNet package installs both command-line tools and
1831 graphical user interfaces (GUIs). The former depend solely on the C
1832 library, whereas the latter depend on Tcl/Tk and the underlying X
1833 libraries. In this case, we leave the command-line tools in the default
1834 output, whereas the GUIs are in a separate output. This allows users
1835 who do not need the GUIs to save space. The @command{guix size} command
1836 can help find out about such situations (@pxref{Invoking guix size}).
1837 @command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
1838
1839 There are several such multiple-output packages in the GNU distribution.
1840 Other conventional output names include @code{lib} for libraries and
1841 possibly header files, @code{bin} for stand-alone programs, and
1842 @code{debug} for debugging information (@pxref{Installing Debugging
1843 Files}). The outputs of a packages are listed in the third column of
1844 the output of @command{guix package --list-available} (@pxref{Invoking
1845 guix package}).
1846
1847
1848 @node Invoking guix gc
1849 @section Invoking @command{guix gc}
1850
1851 @cindex garbage collector
1852 Packages that are installed, but not used, may be @dfn{garbage-collected}.
1853 The @command{guix gc} command allows users to explicitly run the garbage
1854 collector to reclaim space from the @file{/gnu/store} directory. It is
1855 the @emph{only} way to remove files from @file{/gnu/store}---removing
1856 files or directories manually may break it beyond repair!
1857
1858 The garbage collector has a set of known @dfn{roots}: any file under
1859 @file{/gnu/store} reachable from a root is considered @dfn{live} and
1860 cannot be deleted; any other file is considered @dfn{dead} and may be
1861 deleted. The set of garbage collector roots includes default user
1862 profiles, and may be augmented with @command{guix build --root}, for
1863 example (@pxref{Invoking guix build}).
1864
1865 Prior to running @code{guix gc --collect-garbage} to make space, it is
1866 often useful to remove old generations from user profiles; that way, old
1867 package builds referenced by those generations can be reclaimed. This
1868 is achieved by running @code{guix package --delete-generations}
1869 (@pxref{Invoking guix package}).
1870
1871 The @command{guix gc} command has three modes of operation: it can be
1872 used to garbage-collect any dead files (the default), to delete specific
1873 files (the @code{--delete} option), to print garbage-collector
1874 information, or for more advanced queries. The garbage collection
1875 options are as follows:
1876
1877 @table @code
1878 @item --collect-garbage[=@var{min}]
1879 @itemx -C [@var{min}]
1880 Collect garbage---i.e., unreachable @file{/gnu/store} files and
1881 sub-directories. This is the default operation when no option is
1882 specified.
1883
1884 When @var{min} is given, stop once @var{min} bytes have been collected.
1885 @var{min} may be a number of bytes, or it may include a unit as a
1886 suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
1887 (@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
1888
1889 When @var{min} is omitted, collect all the garbage.
1890
1891 @item --delete
1892 @itemx -d
1893 Attempt to delete all the store files and directories specified as
1894 arguments. This fails if some of the files are not in the store, or if
1895 they are still live.
1896
1897 @item --list-failures
1898 List store items corresponding to cached build failures.
1899
1900 This prints nothing unless the daemon was started with
1901 @option{--cache-failures} (@pxref{Invoking guix-daemon,
1902 @option{--cache-failures}}).
1903
1904 @item --clear-failures
1905 Remove the specified store items from the failed-build cache.
1906
1907 Again, this option only makes sense when the daemon is started with
1908 @option{--cache-failures}. Otherwise, it does nothing.
1909
1910 @item --list-dead
1911 Show the list of dead files and directories still present in the
1912 store---i.e., files and directories no longer reachable from any root.
1913
1914 @item --list-live
1915 Show the list of live store files and directories.
1916
1917 @end table
1918
1919 In addition, the references among existing store files can be queried:
1920
1921 @table @code
1922
1923 @item --references
1924 @itemx --referrers
1925 List the references (respectively, the referrers) of store files given
1926 as arguments.
1927
1928 @item --requisites
1929 @itemx -R
1930 @cindex closure
1931 List the requisites of the store files passed as arguments. Requisites
1932 include the store files themselves, their references, and the references
1933 of these, recursively. In other words, the returned list is the
1934 @dfn{transitive closure} of the store files.
1935
1936 @xref{Invoking guix size}, for a tool to profile the size of the closure
1937 of an element. @xref{Invoking guix graph}, for a tool to visualize
1938 the graph of references.
1939
1940 @end table
1941
1942 Lastly, the following options allow you to check the integrity of the
1943 store and to control disk usage.
1944
1945 @table @option
1946
1947 @item --verify[=@var{options}]
1948 @cindex integrity, of the store
1949 @cindex integrity checking
1950 Verify the integrity of the store.
1951
1952 By default, make sure that all the store items marked as valid in the
1953 database of the daemon actually exist in @file{/gnu/store}.
1954
1955 When provided, @var{options} must be a comma-separated list containing one
1956 or more of @code{contents} and @code{repair}.
1957
1958 When passing @option{--verify=contents}, the daemon computse the
1959 content hash of each store item and compares it against its hash in the
1960 database. Hash mismatches are reported as data corruptions. Because it
1961 traverses @emph{all the files in the store}, this command can take a
1962 long time, especially on systems with a slow disk drive.
1963
1964 @cindex repairing the store
1965 Using @option{--verify=repair} or @option{--verify=contents,repair}
1966 causes the daemon to try to repair corrupt store items by fetching
1967 substitutes for them (@pxref{Substitutes}). Because repairing is not
1968 atomic, and thus potentially dangerous, it is available only to the
1969 system administrator.
1970
1971 @item --optimize
1972 @cindex deduplication
1973 Optimize the store by hard-linking identical files---this is
1974 @dfn{deduplication}.
1975
1976 The daemon performs deduplication after each successful build or archive
1977 import, unless it was started with @code{--disable-deduplication}
1978 (@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
1979 this option is primarily useful when the daemon was running with
1980 @code{--disable-deduplication}.
1981
1982 @end table
1983
1984 @node Invoking guix pull
1985 @section Invoking @command{guix pull}
1986
1987 Packages are installed or upgraded to the latest version available in
1988 the distribution currently available on your local machine. To update
1989 that distribution, along with the Guix tools, you must run @command{guix
1990 pull}: the command downloads the latest Guix source code and package
1991 descriptions, and deploys it.
1992
1993 On completion, @command{guix package} will use packages and package
1994 versions from this just-retrieved copy of Guix. Not only that, but all
1995 the Guix commands and Scheme modules will also be taken from that latest
1996 version. New @command{guix} sub-commands added by the update also
1997 become available.
1998
1999 Any user can update their Guix copy using @command{guix pull}, and the
2000 effect is limited to the user who run @command{guix pull}. For
2001 instance, when user @code{root} runs @command{guix pull}, this has no
2002 effect on the version of Guix that user @code{alice} sees, and vice
2003 versa@footnote{Under the hood, @command{guix pull} updates the
2004 @file{~/.config/guix/latest} symbolic link to point to the latest Guix,
2005 and the @command{guix} command loads code from there.}.
2006
2007 The @command{guix pull} command is usually invoked with no arguments,
2008 but it supports the following options:
2009
2010 @table @code
2011 @item --verbose
2012 Produce verbose output, writing build logs to the standard error output.
2013
2014 @item --url=@var{url}
2015 Download the source tarball of Guix from @var{url}.
2016
2017 By default, the tarball is taken from its canonical address at
2018 @code{gnu.org}, for the stable branch of Guix.
2019
2020 @item --bootstrap
2021 Use the bootstrap Guile to build the latest Guix. This option is only
2022 useful to Guix developers.
2023 @end table
2024
2025
2026 @node Invoking guix archive
2027 @section Invoking @command{guix archive}
2028
2029 The @command{guix archive} command allows users to @dfn{export} files
2030 from the store into a single archive, and to later @dfn{import} them.
2031 In particular, it allows store files to be transferred from one machine
2032 to the store on another machine.
2033
2034 To export store files as an archive to standard output, run:
2035
2036 @example
2037 guix archive --export @var{options} @var{specifications}...
2038 @end example
2039
2040 @var{specifications} may be either store file names or package
2041 specifications, as for @command{guix package} (@pxref{Invoking guix
2042 package}). For instance, the following command creates an archive
2043 containing the @code{gui} output of the @code{git} package and the main
2044 output of @code{emacs}:
2045
2046 @example
2047 guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
2048 @end example
2049
2050 If the specified packages are not built yet, @command{guix archive}
2051 automatically builds them. The build process may be controlled with the
2052 common build options (@pxref{Common Build Options}).
2053
2054 To transfer the @code{emacs} package to a machine connected over SSH,
2055 one would run:
2056
2057 @example
2058 guix archive --export -r emacs | ssh the-machine guix archive --import
2059 @end example
2060
2061 @noindent
2062 Similarly, a complete user profile may be transferred from one machine
2063 to another like this:
2064
2065 @example
2066 guix archive --export -r $(readlink -f ~/.guix-profile) | \
2067 ssh the-machine guix-archive --import
2068 @end example
2069
2070 @noindent
2071 However, note that, in both examples, all of @code{emacs} and the
2072 profile as well as all of their dependencies are transferred (due to
2073 @code{-r}), regardless of what is already available in the store on the
2074 target machine. The @code{--missing} option can help figure out which
2075 items are missing from the target store.
2076
2077 Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
2078 comparable in spirit to `tar', but with a few noteworthy differences
2079 that make it more appropriate for our purposes. First, rather than
2080 recording all Unix metadata for each file, the Nar format only mentions
2081 the file type (regular, directory, or symbolic link); Unix permissions
2082 and owner/group are dismissed. Second, the order in which directory
2083 entries are stored always follows the order of file names according to
2084 the C locale collation order. This makes archive production fully
2085 deterministic.
2086
2087 When exporting, the daemon digitally signs the contents of the archive,
2088 and that digital signature is appended. When importing, the daemon
2089 verifies the signature and rejects the import in case of an invalid
2090 signature or if the signing key is not authorized.
2091 @c FIXME: Add xref to daemon doc about signatures.
2092
2093 The main options are:
2094
2095 @table @code
2096 @item --export
2097 Export the specified store files or packages (see below.) Write the
2098 resulting archive to the standard output.
2099
2100 Dependencies are @emph{not} included in the output, unless
2101 @code{--recursive} is passed.
2102
2103 @item -r
2104 @itemx --recursive
2105 When combined with @code{--export}, this instructs @command{guix
2106 archive} to include dependencies of the given items in the archive.
2107 Thus, the resulting archive is self-contained: it contains the closure
2108 of the exported store items.
2109
2110 @item --import
2111 Read an archive from the standard input, and import the files listed
2112 therein into the store. Abort if the archive has an invalid digital
2113 signature, or if it is signed by a public key not among the authorized
2114 keys (see @code{--authorize} below.)
2115
2116 @item --missing
2117 Read a list of store file names from the standard input, one per line,
2118 and write on the standard output the subset of these files missing from
2119 the store.
2120
2121 @item --generate-key[=@var{parameters}]
2122 @cindex signing, archives
2123 Generate a new key pair for the daemon. This is a prerequisite before
2124 archives can be exported with @code{--export}. Note that this operation
2125 usually takes time, because it needs to gather enough entropy to
2126 generate the key pair.
2127
2128 The generated key pair is typically stored under @file{/etc/guix}, in
2129 @file{signing-key.pub} (public key) and @file{signing-key.sec} (private
2130 key, which must be kept secret.) When @var{parameters} is omitted,
2131 an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2132 versions before 1.6.0, it is a 4096-bit RSA key.
2133 Alternatively, @var{parameters} can specify
2134 @code{genkey} parameters suitable for Libgcrypt (@pxref{General
2135 public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2136 Libgcrypt Reference Manual}).
2137
2138 @item --authorize
2139 @cindex authorizing, archives
2140 Authorize imports signed by the public key passed on standard input.
2141 The public key must be in ``s-expression advanced format''---i.e., the
2142 same format as the @file{signing-key.pub} file.
2143
2144 The list of authorized keys is kept in the human-editable file
2145 @file{/etc/guix/acl}. The file contains
2146 @url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2147 s-expressions''} and is structured as an access-control list in the
2148 @url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2149 (SPKI)}.
2150
2151 @item --extract=@var{directory}
2152 @itemx -x @var{directory}
2153 Read a single-item archive as served by substitute servers
2154 (@pxref{Substitutes}) and extract it to @var{directory}. This is a
2155 low-level operation needed in only very narrow use cases; see below.
2156
2157 For example, the following command extracts the substitute for Emacs
2158 served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2159
2160 @example
2161 $ wget -O - \
2162 http://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
2163 | bunzip2 | guix archive -x /tmp/emacs
2164 @end example
2165
2166 Single-item archives are different from multiple-item archives produced
2167 by @command{guix archive --export}; they contain a single store item,
2168 and they do @emph{not} embed a signature. Thus this operation does
2169 @emph{no} signature verification and its output should be considered
2170 unsafe.
2171
2172 The primary purpose of this operation is to facilitate inspection of
2173 archive contents coming from possibly untrusted substitute servers.
2174
2175 @end table
2176
2177 @c *********************************************************************
2178 @include emacs.texi
2179
2180 @c *********************************************************************
2181 @node Programming Interface
2182 @chapter Programming Interface
2183
2184 GNU Guix provides several Scheme programming interfaces (APIs) to
2185 define, build, and query packages. The first interface allows users to
2186 write high-level package definitions. These definitions refer to
2187 familiar packaging concepts, such as the name and version of a package,
2188 its build system, and its dependencies. These definitions can then be
2189 turned into concrete build actions.
2190
2191 Build actions are performed by the Guix daemon, on behalf of users. In a
2192 standard setup, the daemon has write access to the store---the
2193 @file{/gnu/store} directory---whereas users do not. The recommended
2194 setup also has the daemon perform builds in chroots, under a specific
2195 build users, to minimize interference with the rest of the system.
2196
2197 @cindex derivation
2198 Lower-level APIs are available to interact with the daemon and the
2199 store. To instruct the daemon to perform a build action, users actually
2200 provide it with a @dfn{derivation}. A derivation is a low-level
2201 representation of the build actions to be taken, and the environment in
2202 which they should occur---derivations are to package definitions what
2203 assembly is to C programs. The term ``derivation'' comes from the fact
2204 that build results @emph{derive} from them.
2205
2206 This chapter describes all these APIs in turn, starting from high-level
2207 package definitions.
2208
2209 @menu
2210 * Defining Packages:: Defining new packages.
2211 * Build Systems:: Specifying how packages are built.
2212 * The Store:: Manipulating the package store.
2213 * Derivations:: Low-level interface to package derivations.
2214 * The Store Monad:: Purely functional interface to the store.
2215 * G-Expressions:: Manipulating build expressions.
2216 @end menu
2217
2218 @node Defining Packages
2219 @section Defining Packages
2220
2221 The high-level interface to package definitions is implemented in the
2222 @code{(guix packages)} and @code{(guix build-system)} modules. As an
2223 example, the package definition, or @dfn{recipe}, for the GNU Hello
2224 package looks like this:
2225
2226 @example
2227 (define-module (gnu packages hello)
2228 #:use-module (guix packages)
2229 #:use-module (guix download)
2230 #:use-module (guix build-system gnu)
2231 #:use-module (guix licenses)
2232 #:use-module (gnu packages gawk))
2233
2234 (define-public hello
2235 (package
2236 (name "hello")
2237 (version "2.10")
2238 (source (origin
2239 (method url-fetch)
2240 (uri (string-append "mirror://gnu/hello/hello-" version
2241 ".tar.gz"))
2242 (sha256
2243 (base32
2244 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
2245 (build-system gnu-build-system)
2246 (arguments `(#:configure-flags '("--enable-silent-rules")))
2247 (inputs `(("gawk" ,gawk)))
2248 (synopsis "Hello, GNU world: An example GNU package")
2249 (description "Guess what GNU Hello prints!")
2250 (home-page "http://www.gnu.org/software/hello/")
2251 (license gpl3+)))
2252 @end example
2253
2254 @noindent
2255 Without being a Scheme expert, the reader may have guessed the meaning
2256 of the various fields here. This expression binds the variable
2257 @code{hello} to a @code{<package>} object, which is essentially a record
2258 (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2259 This package object can be inspected using procedures found in the
2260 @code{(guix packages)} module; for instance, @code{(package-name hello)}
2261 returns---surprise!---@code{"hello"}.
2262
2263 With luck, you may be able to import part or all of the definition of
2264 the package you are interested in from another repository, using the
2265 @code{guix import} command (@pxref{Invoking guix import}).
2266
2267 In the example above, @var{hello} is defined in a module of its own,
2268 @code{(gnu packages hello)}. Technically, this is not strictly
2269 necessary, but it is convenient to do so: all the packages defined in
2270 modules under @code{(gnu packages @dots{})} are automatically known to
2271 the command-line tools (@pxref{Package Modules}).
2272
2273 There are a few points worth noting in the above package definition:
2274
2275 @itemize
2276 @item
2277 The @code{source} field of the package is an @code{<origin>} object
2278 (@pxref{origin Reference}, for the complete reference).
2279 Here, the @code{url-fetch} method from @code{(guix download)} is used,
2280 meaning that the source is a file to be downloaded over FTP or HTTP.
2281
2282 The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2283 the GNU mirrors defined in @code{(guix download)}.
2284
2285 The @code{sha256} field specifies the expected SHA256 hash of the file
2286 being downloaded. It is mandatory, and allows Guix to check the
2287 integrity of the file. The @code{(base32 @dots{})} form introduces the
2288 base32 representation of the hash. You can obtain this information with
2289 @code{guix download} (@pxref{Invoking guix download}) and @code{guix
2290 hash} (@pxref{Invoking guix hash}).
2291
2292 @cindex patches
2293 When needed, the @code{origin} form can also have a @code{patches} field
2294 listing patches to be applied, and a @code{snippet} field giving a
2295 Scheme expression to modify the source code.
2296
2297 @item
2298 @cindex GNU Build System
2299 The @code{build-system} field specifies the procedure to build the
2300 package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2301 represents the familiar GNU Build System, where packages may be
2302 configured, built, and installed with the usual @code{./configure &&
2303 make && make check && make install} command sequence.
2304
2305 @item
2306 The @code{arguments} field specifies options for the build system
2307 (@pxref{Build Systems}). Here it is interpreted by
2308 @var{gnu-build-system} as a request run @file{configure} with the
2309 @code{--enable-silent-rules} flag.
2310
2311 @item
2312 The @code{inputs} field specifies inputs to the build process---i.e.,
2313 build-time or run-time dependencies of the package. Here, we define an
2314 input called @code{"gawk"} whose value is that of the @var{gawk}
2315 variable; @var{gawk} is itself bound to a @code{<package>} object.
2316
2317 Note that GCC, Coreutils, Bash, and other essential tools do not need to
2318 be specified as inputs here. Instead, @var{gnu-build-system} takes care
2319 of ensuring that they are present (@pxref{Build Systems}).
2320
2321 However, any other dependencies need to be specified in the
2322 @code{inputs} field. Any dependency not specified here will simply be
2323 unavailable to the build process, possibly leading to a build failure.
2324 @end itemize
2325
2326 @xref{package Reference}, for a full description of possible fields.
2327
2328 Once a package definition is in place, the
2329 package may actually be built using the @code{guix build} command-line
2330 tool (@pxref{Invoking guix build}). You can easily jump back to the
2331 package definition using the @command{guix edit} command
2332 (@pxref{Invoking guix edit}).
2333 @xref{Packaging Guidelines}, for
2334 more information on how to test package definitions, and
2335 @ref{Invoking guix lint}, for information on how to check a definition
2336 for style conformance.
2337
2338 Finally, updating the package definition to a new upstream version
2339 can be partly automated by the @command{guix refresh} command
2340 (@pxref{Invoking guix refresh}).
2341
2342 Behind the scenes, a derivation corresponding to the @code{<package>}
2343 object is first computed by the @code{package-derivation} procedure.
2344 That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
2345 The build actions it prescribes may then be realized by using the
2346 @code{build-derivations} procedure (@pxref{The Store}).
2347
2348 @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
2349 Return the @code{<derivation>} object of @var{package} for @var{system}
2350 (@pxref{Derivations}).
2351
2352 @var{package} must be a valid @code{<package>} object, and @var{system}
2353 must be a string denoting the target system type---e.g.,
2354 @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2355 must be a connection to the daemon, which operates on the store
2356 (@pxref{The Store}).
2357 @end deffn
2358
2359 @noindent
2360 @cindex cross-compilation
2361 Similarly, it is possible to compute a derivation that cross-builds a
2362 package for some other system:
2363
2364 @deffn {Scheme Procedure} package-cross-derivation @var{store} @
2365 @var{package} @var{target} [@var{system}]
2366 Return the @code{<derivation>} object of @var{package} cross-built from
2367 @var{system} to @var{target}.
2368
2369 @var{target} must be a valid GNU triplet denoting the target hardware
2370 and operating system, such as @code{"mips64el-linux-gnu"}
2371 (@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2372 Configure and Build System}).
2373 @end deffn
2374
2375 @menu
2376 * package Reference :: The package data type.
2377 * origin Reference:: The origin data type.
2378 @end menu
2379
2380
2381 @node package Reference
2382 @subsection @code{package} Reference
2383
2384 This section summarizes all the options available in @code{package}
2385 declarations (@pxref{Defining Packages}).
2386
2387 @deftp {Data Type} package
2388 This is the data type representing a package recipe.
2389
2390 @table @asis
2391 @item @code{name}
2392 The name of the package, as a string.
2393
2394 @item @code{version}
2395 The version of the package, as a string.
2396
2397 @item @code{source}
2398 An origin object telling how the source code for the package should be
2399 acquired (@pxref{origin Reference}).
2400
2401 @item @code{build-system}
2402 The build system that should be used to build the package (@pxref{Build
2403 Systems}).
2404
2405 @item @code{arguments} (default: @code{'()})
2406 The arguments that should be passed to the build system. This is a
2407 list, typically containing sequential keyword-value pairs.
2408
2409 @item @code{inputs} (default: @code{'()})
2410 @itemx @code{native-inputs} (default: @code{'()})
2411 @itemx @code{propagated-inputs} (default: @code{'()})
2412 @cindex inputs, of packages
2413 These fields list dependencies of the package. Each one is a list of
2414 tuples, where each tuple has a label for the input (a string) as its
2415 first element, a package, origin, or derivation as its second element,
2416 and optionally the name of the output thereof that should be used, which
2417 defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
2418 more on package outputs). For example, the list below specifies three
2419 inputs:
2420
2421 @example
2422 `(("libffi" ,libffi)
2423 ("libunistring" ,libunistring)
2424 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
2425 @end example
2426
2427 @cindex cross compilation, package dependencies
2428 The distinction between @code{native-inputs} and @code{inputs} is
2429 necessary when considering cross-compilation. When cross-compiling,
2430 dependencies listed in @code{inputs} are built for the @emph{target}
2431 architecture; conversely, dependencies listed in @code{native-inputs}
2432 are built for the architecture of the @emph{build} machine.
2433
2434 @code{native-inputs} is typically used to list tools needed at
2435 build time, but not at run time, such as Autoconf, Automake, pkg-config,
2436 Gettext, or Bison. @command{guix lint} can report likely mistakes in
2437 this area (@pxref{Invoking guix lint}).
2438
2439 @anchor{package-propagated-inputs}
2440 Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
2441 specified packages will be automatically installed alongside the package
2442 they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
2443 package}}, for information on how @command{guix package} deals with
2444 propagated inputs.)
2445
2446 For example this is necessary when a C/C++ library needs headers of
2447 another library to compile, or when a pkg-config file refers to another
2448 one @i{via} its @code{Requires} field.
2449
2450 Another example where @code{propagated-inputs} is useful is for languages
2451 that lack a facility to record the run-time search path akin to the
2452 @code{RUNPATH}of ELF files; this includes Guile, Python, Perl, GHC, and
2453 more. To ensure that libraries written in those languages can find
2454 library code they depend on at run time, run-time dependencies must be
2455 listed in @code{propagated-inputs} rather than @code{inputs}.
2456
2457 @item @code{self-native-input?} (default: @code{#f})
2458 This is a Boolean field telling whether the package should use itself as
2459 a native input when cross-compiling.
2460
2461 @item @code{outputs} (default: @code{'("out")})
2462 The list of output names of the package. @xref{Packages with Multiple
2463 Outputs}, for typical uses of additional outputs.
2464
2465 @item @code{native-search-paths} (default: @code{'()})
2466 @itemx @code{search-paths} (default: @code{'()})
2467 A list of @code{search-path-specification} objects describing
2468 search-path environment variables honored by the package.
2469
2470 @item @code{replacement} (default: @code{#f})
2471 This must be either @code{#f} or a package object that will be used as a
2472 @dfn{replacement} for this package. @xref{Security Updates, grafts},
2473 for details.
2474
2475 @item @code{synopsis}
2476 A one-line description of the package.
2477
2478 @item @code{description}
2479 A more elaborate description of the package.
2480
2481 @item @code{license}
2482 The license of the package; a value from @code{(guix licenses)},
2483 or a list of such values.
2484
2485 @item @code{home-page}
2486 The URL to the home-page of the package, as a string.
2487
2488 @item @code{supported-systems} (default: @var{%supported-systems})
2489 The list of systems supported by the package, as strings of the form
2490 @code{architecture-kernel}, for example @code{"x86_64-linux"}.
2491
2492 @item @code{maintainers} (default: @code{'()})
2493 The list of maintainers of the package, as @code{maintainer} objects.
2494
2495 @item @code{location} (default: source location of the @code{package} form)
2496 The source location of the package. It is useful to override this when
2497 inheriting from another package, in which case this field is not
2498 automatically corrected.
2499 @end table
2500 @end deftp
2501
2502
2503 @node origin Reference
2504 @subsection @code{origin} Reference
2505
2506 This section summarizes all the options available in @code{origin}
2507 declarations (@pxref{Defining Packages}).
2508
2509 @deftp {Data Type} origin
2510 This is the data type representing a source code origin.
2511
2512 @table @asis
2513 @item @code{uri}
2514 An object containing the URI of the source. The object type depends on
2515 the @code{method} (see below). For example, when using the
2516 @var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2517 values are: a URL represented as a string, or a list thereof.
2518
2519 @item @code{method}
2520 A procedure that handles the URI.
2521
2522 Examples include:
2523
2524 @table @asis
2525 @item @var{url-fetch} from @code{(guix download)}
2526 download a file from the HTTP, HTTPS, or FTP URL specified in the
2527 @code{uri} field;
2528
2529 @item @var{git-fetch} from @code{(guix git-download)}
2530 clone the Git version control repository, and check out the revision
2531 specified in the @code{uri} field as a @code{git-reference} object; a
2532 @code{git-reference} looks like this:
2533
2534 @example
2535 (git-reference
2536 (url "git://git.debian.org/git/pkg-shadow/shadow")
2537 (commit "v4.1.5.1"))
2538 @end example
2539 @end table
2540
2541 @item @code{sha256}
2542 A bytevector containing the SHA-256 hash of the source. Typically the
2543 @code{base32} form is used here to generate the bytevector from a
2544 base-32 string.
2545
2546 @item @code{file-name} (default: @code{#f})
2547 The file name under which the source code should be saved. When this is
2548 @code{#f}, a sensible default value will be used in most cases. In case
2549 the source is fetched from a URL, the file name from the URL will be
2550 used. For version control checkouts, it is recommended to provide the
2551 file name explicitly because the default is not very descriptive.
2552
2553 @item @code{patches} (default: @code{'()})
2554 A list of file names containing patches to be applied to the source.
2555
2556 @item @code{snippet} (default: @code{#f})
2557 A quoted piece of code that will be run in the source directory to make
2558 any modifications, which is sometimes more convenient than a patch.
2559
2560 @item @code{patch-flags} (default: @code{'("-p1")})
2561 A list of command-line flags that should be passed to the @code{patch}
2562 command.
2563
2564 @item @code{patch-inputs} (default: @code{#f})
2565 Input packages or derivations to the patching process. When this is
2566 @code{#f}, the usual set of inputs necessary for patching are provided,
2567 such as GNU@tie{}Patch.
2568
2569 @item @code{modules} (default: @code{'()})
2570 A list of Guile modules that should be loaded during the patching
2571 process and while running the code in the @code{snippet} field.
2572
2573 @item @code{imported-modules} (default: @code{'()})
2574 The list of Guile modules to import in the patch derivation, for use by
2575 the @code{snippet}.
2576
2577 @item @code{patch-guile} (default: @code{#f})
2578 The Guile package that should be used in the patching process. When
2579 this is @code{#f}, a sensible default is used.
2580 @end table
2581 @end deftp
2582
2583
2584 @node Build Systems
2585 @section Build Systems
2586
2587 @cindex build system
2588 Each package definition specifies a @dfn{build system} and arguments for
2589 that build system (@pxref{Defining Packages}). This @code{build-system}
2590 field represents the build procedure of the package, as well as implicit
2591 dependencies of that build procedure.
2592
2593 Build systems are @code{<build-system>} objects. The interface to
2594 create and manipulate them is provided by the @code{(guix build-system)}
2595 module, and actual build systems are exported by specific modules.
2596
2597 @cindex bag (low-level package representation)
2598 Under the hood, build systems first compile package objects to
2599 @dfn{bags}. A @dfn{bag} is like a package, but with less
2600 ornamentation---in other words, a bag is a lower-level representation of
2601 a package, which includes all the inputs of that package, including some
2602 that were implicitly added by the build system. This intermediate
2603 representation is then compiled to a derivation (@pxref{Derivations}).
2604
2605 Build systems accept an optional list of @dfn{arguments}. In package
2606 definitions, these are passed @i{via} the @code{arguments} field
2607 (@pxref{Defining Packages}). They are typically keyword arguments
2608 (@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
2609 Guile Reference Manual}). The value of these arguments is usually
2610 evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
2611 by the daemon (@pxref{Derivations}).
2612
2613 The main build system is @var{gnu-build-system}, which implements the
2614 standard build procedure for GNU and many other packages. It
2615 is provided by the @code{(guix build-system gnu)} module.
2616
2617 @defvr {Scheme Variable} gnu-build-system
2618 @var{gnu-build-system} represents the GNU Build System, and variants
2619 thereof (@pxref{Configuration, configuration and makefile conventions,,
2620 standards, GNU Coding Standards}).
2621
2622 @cindex build phases
2623 In a nutshell, packages using it are configured, built, and installed with
2624 the usual @code{./configure && make && make check && make install}
2625 command sequence. In practice, a few additional steps are often needed.
2626 All these steps are split up in separate @dfn{phases},
2627 notably@footnote{Please see the @code{(guix build gnu-build-system)}
2628 modules for more details about the build phases.}:
2629
2630 @table @code
2631 @item unpack
2632 Unpack the source tarball, and change the current directory to the
2633 extracted source tree. If the source is actually a directory, copy it
2634 to the build tree, and enter that directory.
2635
2636 @item patch-source-shebangs
2637 Patch shebangs encountered in source files so they refer to the right
2638 store file names. For instance, this changes @code{#!/bin/sh} to
2639 @code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
2640
2641 @item configure
2642 Run the @file{configure} script with a number of default options, such
2643 as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
2644 by the @code{#:configure-flags} argument.
2645
2646 @item build
2647 Run @code{make} with the list of flags specified with
2648 @code{#:make-flags}. If the @code{#:parallel-build?} argument is true
2649 (the default), build with @code{make -j}.
2650
2651 @item check
2652 Run @code{make check}, or some other target specified with
2653 @code{#:test-target}, unless @code{#:tests? #f} is passed. If the
2654 @code{#:parallel-tests?} argument is true (the default), run @code{make
2655 check -j}.
2656
2657 @item install
2658 Run @code{make install} with the flags listed in @code{#:make-flags}.
2659
2660 @item patch-shebangs
2661 Patch shebangs on the installed executable files.
2662
2663 @item strip
2664 Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
2665 is false), copying them to the @code{debug} output when available
2666 (@pxref{Installing Debugging Files}).
2667 @end table
2668
2669 @vindex %standard-phases
2670 The build-side module @code{(guix build gnu-build-system)} defines
2671 @var{%standard-phases} as the default list of build phases.
2672 @var{%standard-phases} is a list of symbol/procedure pairs, where the
2673 procedure implements the actual phase.
2674
2675 The list of phases used for a particular package can be changed with the
2676 @code{#:phases} parameter. For instance, passing:
2677
2678 @example
2679 #:phases (modify-phases %standard-phases (delete 'configure))
2680 @end example
2681
2682 means that all the phases described above will be used, except the
2683 @code{configure} phase.
2684
2685 In addition, this build system ensures that the ``standard'' environment
2686 for GNU packages is available. This includes tools such as GCC, libc,
2687 Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
2688 build-system gnu)} module for a complete list). We call these the
2689 @dfn{implicit inputs} of a package, because package definitions do not
2690 have to mention them.
2691 @end defvr
2692
2693 Other @code{<build-system>} objects are defined to support other
2694 conventions and tools used by free software packages. They inherit most
2695 of @var{gnu-build-system}, and differ mainly in the set of inputs
2696 implicitly added to the build process, and in the list of phases
2697 executed. Some of these build systems are listed below.
2698
2699 @defvr {Scheme Variable} cmake-build-system
2700 This variable is exported by @code{(guix build-system cmake)}. It
2701 implements the build procedure for packages using the
2702 @url{http://www.cmake.org, CMake build tool}.
2703
2704 It automatically adds the @code{cmake} package to the set of inputs.
2705 Which package is used can be specified with the @code{#:cmake}
2706 parameter.
2707
2708 The @code{#:configure-flags} parameter is taken as a list of flags
2709 passed to the @command{cmake} command. The @code{#:build-type}
2710 parameter specifies in abstract terms the flags passed to the compiler;
2711 it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
2712 debugging information''), which roughly means that code is compiled with
2713 @code{-O2 -g}, as is the case for Autoconf-based packages by default.
2714 @end defvr
2715
2716 @defvr {Scheme Variable} glib-or-gtk-build-system
2717 This variable is exported by @code{(guix build-system glib-or-gtk)}. It
2718 is intended for use with packages making use of GLib or GTK+.
2719
2720 This build system adds the following two phases to the ones defined by
2721 @var{gnu-build-system}:
2722
2723 @table @code
2724 @item glib-or-gtk-wrap
2725 The phase @code{glib-or-gtk-wrap} ensures that programs in
2726 @file{bin/} are able to find GLib ``schemas'' and
2727 @uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
2728 modules}. This is achieved by wrapping the programs in launch scripts
2729 that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
2730 environment variables.
2731
2732 It is possible to exclude specific package outputs from that wrapping
2733 process by listing their names in the
2734 @code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
2735 when an output is known not to contain any GLib or GTK+ binaries, and
2736 where wrapping would gratuitously add a dependency of that output on
2737 GLib and GTK+.
2738
2739 @item glib-or-gtk-compile-schemas
2740 The phase @code{glib-or-gtk-compile-schemas} makes sure that all
2741 @uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
2742 GSettings schemas} of GLib are compiled. Compilation is performed by the
2743 @command{glib-compile-schemas} program. It is provided by the package
2744 @code{glib:bin} which is automatically imported by the build system.
2745 The @code{glib} package providing @command{glib-compile-schemas} can be
2746 specified with the @code{#:glib} parameter.
2747 @end table
2748
2749 Both phases are executed after the @code{install} phase.
2750 @end defvr
2751
2752 @defvr {Scheme Variable} python-build-system
2753 This variable is exported by @code{(guix build-system python)}. It
2754 implements the more or less standard build procedure used by Python
2755 packages, which consists in running @code{python setup.py build} and
2756 then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
2757
2758 For packages that install stand-alone Python programs under @code{bin/},
2759 it takes care of wrapping these programs so that their @code{PYTHONPATH}
2760 environment variable points to all the Python libraries they depend on.
2761
2762 Which Python package is used can be specified with the @code{#:python}
2763 parameter.
2764 @end defvr
2765
2766 @defvr {Scheme Variable} perl-build-system
2767 This variable is exported by @code{(guix build-system perl)}. It
2768 implements the standard build procedure for Perl packages, which either
2769 consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
2770 followed by @code{Build} and @code{Build install}; or in running
2771 @code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
2772 @code{make} and @code{make install}, depending on which of
2773 @code{Build.PL} or @code{Makefile.PL} is present in the package
2774 distribution. Preference is given to the former if both @code{Build.PL}
2775 and @code{Makefile.PL} exist in the package distribution. This
2776 preference can be reversed by specifying @code{#t} for the
2777 @code{#:make-maker?} parameter.
2778
2779 The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
2780 passes flags specified by the @code{#:make-maker-flags} or
2781 @code{#:module-build-flags} parameter, respectively.
2782
2783 Which Perl package is used can be specified with @code{#:perl}.
2784 @end defvr
2785
2786 @defvr {Scheme Variable} r-build-system
2787 This variable is exported by @code{(guix build-system r)}. It
2788 implements the build procedure used by @uref{http://r-project.org, R}
2789 packages, which essentially is little more than running @code{R CMD
2790 INSTALL --library=/gnu/store/@dots{}} in an environment where
2791 @code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
2792 are run after installation using the R function
2793 @code{tools::testInstalledPackage}.
2794 @end defvr
2795
2796 @defvr {Scheme Variable} ruby-build-system
2797 This variable is exported by @code{(guix build-system ruby)}. It
2798 implements the RubyGems build procedure used by Ruby packages, which
2799 involves running @code{gem build} followed by @code{gem install}.
2800
2801 The @code{source} field of a package that uses this build system
2802 typically references a gem archive, since this is the format that Ruby
2803 developers use when releasing their software. The build system unpacks
2804 the gem archive, potentially patches the source, runs the test suite,
2805 repackages the gem, and installs it. Additionally, directories and
2806 tarballs may be referenced to allow building unreleased gems from Git or
2807 a traditional source release tarball.
2808
2809 Which Ruby package is used can be specified with the @code{#:ruby}
2810 parameter. A list of additional flags to be passed to the @command{gem}
2811 command can be specified with the @code{#:gem-flags} parameter.
2812 @end defvr
2813
2814 @defvr {Scheme Variable} waf-build-system
2815 This variable is exported by @code{(guix build-system waf)}. It
2816 implements a build procedure around the @code{waf} script. The common
2817 phases---@code{configure}, @code{build}, and @code{install}---are
2818 implemented by passing their names as arguments to the @code{waf}
2819 script.
2820
2821 The @code{waf} script is executed by the Python interpreter. Which
2822 Python package is used to run the script can be specified with the
2823 @code{#:python} parameter.
2824 @end defvr
2825
2826 @defvr {Scheme Variable} haskell-build-system
2827 This variable is exported by @code{(guix build-system haskell)}. It
2828 implements the Cabal build procedure used by Haskell packages, which
2829 involves running @code{runhaskell Setup.hs configure
2830 --prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
2831 Instead of installing the package by running @code{runhaskell Setup.hs
2832 install}, to avoid trying to register libraries in the read-only
2833 compiler store directory, the build system uses @code{runhaskell
2834 Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
2835 addition, the build system generates the package documentation by
2836 running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
2837 is passed. Optional Haddock parameters can be passed with the help of
2838 the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
2839 not found, the build system looks for @code{Setup.lhs} instead.
2840
2841 Which Haskell compiler is used can be specified with the @code{#:haskell}
2842 parameter which defaults to @code{ghc}.
2843 @end defvr
2844
2845 @defvr {Scheme Variable} emacs-build-system
2846 This variable is exported by @code{(guix build-system emacs)}. It
2847 implements an installation procedure similar to the packaging system
2848 of Emacs itself (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
2849
2850 It first creates the @code{@var{package}-autoloads.el} file, then it
2851 byte compiles all Emacs Lisp files. Differently from the Emacs
2852 packaging system, the Info documentation files are moved to the standard
2853 documentation directory and the @file{dir} file is deleted. Each
2854 package is installed in its own directory under
2855 @file{share/emacs/site-lisp/guix.d}.
2856 @end defvr
2857
2858 Lastly, for packages that do not need anything as sophisticated, a
2859 ``trivial'' build system is provided. It is trivial in the sense that
2860 it provides basically no support: it does not pull any implicit inputs,
2861 and does not have a notion of build phases.
2862
2863 @defvr {Scheme Variable} trivial-build-system
2864 This variable is exported by @code{(guix build-system trivial)}.
2865
2866 This build system requires a @code{#:builder} argument. This argument
2867 must be a Scheme expression that builds the package output(s)---as
2868 with @code{build-expression->derivation} (@pxref{Derivations,
2869 @code{build-expression->derivation}}).
2870 @end defvr
2871
2872 @node The Store
2873 @section The Store
2874
2875 @cindex store
2876 @cindex store paths
2877
2878 Conceptually, the @dfn{store} is the place where derivations that have
2879 been built successfully are stored---by default, @file{/gnu/store}.
2880 Sub-directories in the store are referred to as @dfn{store paths}. The
2881 store has an associated database that contains information such as the
2882 store paths referred to by each store path, and the list of @emph{valid}
2883 store paths---paths that result from a successful build.
2884
2885 The store is always accessed by the daemon on behalf of its clients
2886 (@pxref{Invoking guix-daemon}). To manipulate the store, clients
2887 connect to the daemon over a Unix-domain socket, send requests to it,
2888 and read the result---these are remote procedure calls, or RPCs.
2889
2890 The @code{(guix store)} module provides procedures to connect to the
2891 daemon, and to perform RPCs. These are described below.
2892
2893 @deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
2894 Connect to the daemon over the Unix-domain socket at @var{file}. When
2895 @var{reserve-space?} is true, instruct it to reserve a little bit of
2896 extra space on the file system so that the garbage collector can still
2897 operate should the disk become full. Return a server object.
2898
2899 @var{file} defaults to @var{%default-socket-path}, which is the normal
2900 location given the options that were passed to @command{configure}.
2901 @end deffn
2902
2903 @deffn {Scheme Procedure} close-connection @var{server}
2904 Close the connection to @var{server}.
2905 @end deffn
2906
2907 @defvr {Scheme Variable} current-build-output-port
2908 This variable is bound to a SRFI-39 parameter, which refers to the port
2909 where build and error logs sent by the daemon should be written.
2910 @end defvr
2911
2912 Procedures that make RPCs all take a server object as their first
2913 argument.
2914
2915 @deffn {Scheme Procedure} valid-path? @var{server} @var{path}
2916 @cindex invalid store items
2917 Return @code{#t} when @var{path} designates a valid store item and
2918 @code{#f} otherwise (an invalid item may exist on disk but still be
2919 invalid, for instance because it is the result of an aborted or failed
2920 build.)
2921
2922 A @code{&nix-protocol-error} condition is raised if @var{path} is not
2923 prefixed by the store directory (@file{/gnu/store}).
2924 @end deffn
2925
2926 @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
2927 Add @var{text} under file @var{name} in the store, and return its store
2928 path. @var{references} is the list of store paths referred to by the
2929 resulting store path.
2930 @end deffn
2931
2932 @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
2933 Build @var{derivations} (a list of @code{<derivation>} objects or
2934 derivation paths), and return when the worker is done building them.
2935 Return @code{#t} on success.
2936 @end deffn
2937
2938 Note that the @code{(guix monads)} module provides a monad as well as
2939 monadic versions of the above procedures, with the goal of making it
2940 more convenient to work with code that accesses the store (@pxref{The
2941 Store Monad}).
2942
2943 @c FIXME
2944 @i{This section is currently incomplete.}
2945
2946 @node Derivations
2947 @section Derivations
2948
2949 @cindex derivations
2950 Low-level build actions and the environment in which they are performed
2951 are represented by @dfn{derivations}. A derivation contain the
2952 following pieces of information:
2953
2954 @itemize
2955 @item
2956 The outputs of the derivation---derivations produce at least one file or
2957 directory in the store, but may produce more.
2958
2959 @item
2960 The inputs of the derivations, which may be other derivations or plain
2961 files in the store (patches, build scripts, etc.)
2962
2963 @item
2964 The system type targeted by the derivation---e.g., @code{x86_64-linux}.
2965
2966 @item
2967 The file name of a build script in the store, along with the arguments
2968 to be passed.
2969
2970 @item
2971 A list of environment variables to be defined.
2972
2973 @end itemize
2974
2975 @cindex derivation path
2976 Derivations allow clients of the daemon to communicate build actions to
2977 the store. They exist in two forms: as an in-memory representation,
2978 both on the client- and daemon-side, and as files in the store whose
2979 name end in @code{.drv}---these files are referred to as @dfn{derivation
2980 paths}. Derivations paths can be passed to the @code{build-derivations}
2981 procedure to perform the build actions they prescribe (@pxref{The
2982 Store}).
2983
2984 The @code{(guix derivations)} module provides a representation of
2985 derivations as Scheme objects, along with procedures to create and
2986 otherwise manipulate derivations. The lowest-level primitive to create
2987 a derivation is the @code{derivation} procedure:
2988
2989 @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
2990 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2991 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
2992 [#:system (%current-system)] [#:references-graphs #f] @
2993 [#:allowed-references #f] [#:leaked-env-vars #f] [#:local-build? #f] @
2994 [#:substitutable? #t]
2995 Build a derivation with the given arguments, and return the resulting
2996 @code{<derivation>} object.
2997
2998 When @var{hash} and @var{hash-algo} are given, a
2999 @dfn{fixed-output derivation} is created---i.e., one whose result is
3000 known in advance, such as a file download. If, in addition,
3001 @var{recursive?} is true, then that fixed output may be an executable
3002 file or a directory and @var{hash} must be the hash of an archive
3003 containing this output.
3004
3005 When @var{references-graphs} is true, it must be a list of file
3006 name/store path pairs. In that case, the reference graph of each store
3007 path is exported in the build environment in the corresponding file, in
3008 a simple text format.
3009
3010 When @var{allowed-references} is true, it must be a list of store items
3011 or outputs that the derivation's output may refer to.
3012
3013 When @var{leaked-env-vars} is true, it must be a list of strings
3014 denoting environment variables that are allowed to ``leak'' from the
3015 daemon's environment to the build environment. This is only applicable
3016 to fixed-output derivations---i.e., when @var{hash} is true. The main
3017 use is to allow variables such as @code{http_proxy} to be passed to
3018 derivations that download files.
3019
3020 When @var{local-build?} is true, declare that the derivation is not a
3021 good candidate for offloading and should rather be built locally
3022 (@pxref{Daemon Offload Setup}). This is the case for small derivations
3023 where the costs of data transfers would outweigh the benefits.
3024
3025 When @var{substitutable?} is false, declare that substitutes of the
3026 derivation's output should not be used (@pxref{Substitutes}). This is
3027 useful, for instance, when building packages that capture details of the
3028 host CPU instruction set.
3029 @end deffn
3030
3031 @noindent
3032 Here's an example with a shell script as its builder, assuming
3033 @var{store} is an open connection to the daemon, and @var{bash} points
3034 to a Bash executable in the store:
3035
3036 @lisp
3037 (use-modules (guix utils)
3038 (guix store)
3039 (guix derivations))
3040
3041 (let ((builder ; add the Bash script to the store
3042 (add-text-to-store store "my-builder.sh"
3043 "echo hello world > $out\n" '())))
3044 (derivation store "foo"
3045 bash `("-e" ,builder)
3046 #:inputs `((,bash) (,builder))
3047 #:env-vars '(("HOME" . "/homeless"))))
3048 @result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
3049 @end lisp
3050
3051 As can be guessed, this primitive is cumbersome to use directly. A
3052 better approach is to write build scripts in Scheme, of course! The
3053 best course of action for that is to write the build code as a
3054 ``G-expression'', and to pass it to @code{gexp->derivation}. For more
3055 information, @pxref{G-Expressions}.
3056
3057 Once upon a time, @code{gexp->derivation} did not exist and constructing
3058 derivations with build code written in Scheme was achieved with
3059 @code{build-expression->derivation}, documented below. This procedure
3060 is now deprecated in favor of the much nicer @code{gexp->derivation}.
3061
3062 @deffn {Scheme Procedure} build-expression->derivation @var{store} @
3063 @var{name} @var{exp} @
3064 [#:system (%current-system)] [#:inputs '()] @
3065 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3066 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3067 [#:references-graphs #f] [#:allowed-references #f] @
3068 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3069 Return a derivation that executes Scheme expression @var{exp} as a
3070 builder for derivation @var{name}. @var{inputs} must be a list of
3071 @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
3072 @code{"out"} is assumed. @var{modules} is a list of names of Guile
3073 modules from the current search path to be copied in the store,
3074 compiled, and made available in the load path during the execution of
3075 @var{exp}---e.g., @code{((guix build utils) (guix build
3076 gnu-build-system))}.
3077
3078 @var{exp} is evaluated in an environment where @code{%outputs} is bound
3079 to a list of output/path pairs, and where @code{%build-inputs} is bound
3080 to a list of string/output-path pairs made from @var{inputs}.
3081 Optionally, @var{env-vars} is a list of string pairs specifying the name
3082 and value of environment variables visible to the builder. The builder
3083 terminates by passing the result of @var{exp} to @code{exit}; thus, when
3084 @var{exp} returns @code{#f}, the build is considered to have failed.
3085
3086 @var{exp} is built using @var{guile-for-build} (a derivation). When
3087 @var{guile-for-build} is omitted or is @code{#f}, the value of the
3088 @code{%guile-for-build} fluid is used instead.
3089
3090 See the @code{derivation} procedure for the meaning of
3091 @var{references-graphs}, @var{allowed-references}, @var{local-build?},
3092 and @var{substitutable?}.
3093 @end deffn
3094
3095 @noindent
3096 Here's an example of a single-output derivation that creates a directory
3097 containing one file:
3098
3099 @lisp
3100 (let ((builder '(let ((out (assoc-ref %outputs "out")))
3101 (mkdir out) ; create /gnu/store/@dots{}-goo
3102 (call-with-output-file (string-append out "/test")
3103 (lambda (p)
3104 (display '(hello guix) p))))))
3105 (build-expression->derivation store "goo" builder))
3106
3107 @result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
3108 @end lisp
3109
3110
3111 @node The Store Monad
3112 @section The Store Monad
3113
3114 @cindex monad
3115
3116 The procedures that operate on the store described in the previous
3117 sections all take an open connection to the build daemon as their first
3118 argument. Although the underlying model is functional, they either have
3119 side effects or depend on the current state of the store.
3120
3121 The former is inconvenient: the connection to the build daemon has to be
3122 carried around in all those functions, making it impossible to compose
3123 functions that do not take that parameter with functions that do. The
3124 latter can be problematic: since store operations have side effects
3125 and/or depend on external state, they have to be properly sequenced.
3126
3127 @cindex monadic values
3128 @cindex monadic functions
3129 This is where the @code{(guix monads)} module comes in. This module
3130 provides a framework for working with @dfn{monads}, and a particularly
3131 useful monad for our uses, the @dfn{store monad}. Monads are a
3132 construct that allows two things: associating ``context'' with values
3133 (in our case, the context is the store), and building sequences of
3134 computations (here computations include accesses to the store.) Values
3135 in a monad---values that carry this additional context---are called
3136 @dfn{monadic values}; procedures that return such values are called
3137 @dfn{monadic procedures}.
3138
3139 Consider this ``normal'' procedure:
3140
3141 @example
3142 (define (sh-symlink store)
3143 ;; Return a derivation that symlinks the 'bash' executable.
3144 (let* ((drv (package-derivation store bash))
3145 (out (derivation->output-path drv))
3146 (sh (string-append out "/bin/bash")))
3147 (build-expression->derivation store "sh"
3148 `(symlink ,sh %output))))
3149 @end example
3150
3151 Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3152 as a monadic function:
3153
3154 @example
3155 (define (sh-symlink)
3156 ;; Same, but return a monadic value.
3157 (mlet %store-monad ((drv (package->derivation bash)))
3158 (gexp->derivation "sh"
3159 #~(symlink (string-append #$drv "/bin/bash")
3160 #$output))))
3161 @end example
3162
3163 There several things to note in the second version: the @code{store}
3164 parameter is now implicit and is ``threaded'' in the calls to the
3165 @code{package->derivation} and @code{gexp->derivation} monadic
3166 procedures, and the monadic value returned by @code{package->derivation}
3167 is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3168
3169 As it turns out, the call to @code{package->derivation} can even be
3170 omitted since it will take place implicitly, as we will see later
3171 (@pxref{G-Expressions}):
3172
3173 @example
3174 (define (sh-symlink)
3175 (gexp->derivation "sh"
3176 #~(symlink (string-append #$bash "/bin/bash")
3177 #$output)))
3178 @end example
3179
3180 @c See
3181 @c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
3182 @c for the funny quote.
3183 Calling the monadic @code{sh-symlink} has no effect. As someone once
3184 said, ``you exit a monad like you exit a building on fire: by running''.
3185 So, to exit the monad and get the desired effect, one must use
3186 @code{run-with-store}:
3187
3188 @example
3189 (run-with-store (open-connection) (sh-symlink))
3190 @result{} /gnu/store/...-sh-symlink
3191 @end example
3192
3193 Note that the @code{(guix monad-repl)} module extends the Guile REPL with
3194 new ``meta-commands'' to make it easier to deal with monadic procedures:
3195 @code{run-in-store}, and @code{enter-store-monad}. The former is used
3196 to ``run'' a single monadic value through the store:
3197
3198 @example
3199 scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3200 $1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3201 @end example
3202
3203 The latter enters a recursive REPL, where all the return values are
3204 automatically run through the store:
3205
3206 @example
3207 scheme@@(guile-user)> ,enter-store-monad
3208 store-monad@@(guile-user) [1]> (package->derivation hello)
3209 $2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3210 store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3211 $3 = "/gnu/store/@dots{}-foo"
3212 store-monad@@(guile-user) [1]> ,q
3213 scheme@@(guile-user)>
3214 @end example
3215
3216 @noindent
3217 Note that non-monadic values cannot be returned in the
3218 @code{store-monad} REPL.
3219
3220 The main syntactic forms to deal with monads in general are provided by
3221 the @code{(guix monads)} module and are described below.
3222
3223 @deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3224 Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3225 in @var{monad}.
3226 @end deffn
3227
3228 @deffn {Scheme Syntax} return @var{val}
3229 Return a monadic value that encapsulates @var{val}.
3230 @end deffn
3231
3232 @deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
3233 @dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
3234 procedures @var{mproc}@dots{}@footnote{This operation is commonly
3235 referred to as ``bind'', but that name denotes an unrelated procedure in
3236 Guile. Thus we use this somewhat cryptic symbol inherited from the
3237 Haskell language.}. There can be one @var{mproc} or several of them, as
3238 in this example:
3239
3240 @example
3241 (run-with-state
3242 (with-monad %state-monad
3243 (>>= (return 1)
3244 (lambda (x) (return (+ 1 x)))
3245 (lambda (x) (return (* 2 x)))))
3246 'some-state)
3247
3248 @result{} 4
3249 @result{} some-state
3250 @end example
3251 @end deffn
3252
3253 @deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3254 @var{body} ...
3255 @deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3256 @var{body} ...
3257 Bind the variables @var{var} to the monadic values @var{mval} in
3258 @var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3259 ``normal'' value @var{val}, as per @code{let}.
3260
3261 @code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3262 (@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3263 @end deffn
3264
3265 @deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3266 Bind @var{mexp} and the following monadic expressions in sequence,
3267 returning the result of the last expression.
3268
3269 This is akin to @code{mlet}, except that the return values of the
3270 monadic expressions are ignored. In that sense, it is analogous to
3271 @code{begin}, but applied to monadic expressions.
3272 @end deffn
3273
3274 @cindex state monad
3275 The @code{(guix monads)} module provides the @dfn{state monad}, which
3276 allows an additional value---the state---to be @emph{threaded} through
3277 monadic procedure calls.
3278
3279 @defvr {Scheme Variable} %state-monad
3280 The state monad. Procedures in the state monad can access and change
3281 the state that is threaded.
3282
3283 Consider the example below. The @code{square} procedure returns a value
3284 in the state monad. It returns the square of its argument, but also
3285 increments the current state value:
3286
3287 @example
3288 (define (square x)
3289 (mlet %state-monad ((count (current-state)))
3290 (mbegin %state-monad
3291 (set-current-state (+ 1 count))
3292 (return (* x x)))))
3293
3294 (run-with-state (sequence %state-monad (map square (iota 3))) 0)
3295 @result{} (0 1 4)
3296 @result{} 3
3297 @end example
3298
3299 When ``run'' through @var{%state-monad}, we obtain that additional state
3300 value, which is the number of @code{square} calls.
3301 @end defvr
3302
3303 @deffn {Monadic Procedure} current-state
3304 Return the current state as a monadic value.
3305 @end deffn
3306
3307 @deffn {Monadic Procedure} set-current-state @var{value}
3308 Set the current state to @var{value} and return the previous state as a
3309 monadic value.
3310 @end deffn
3311
3312 @deffn {Monadic Procedure} state-push @var{value}
3313 Push @var{value} to the current state, which is assumed to be a list,
3314 and return the previous state as a monadic value.
3315 @end deffn
3316
3317 @deffn {Monadic Procedure} state-pop
3318 Pop a value from the current state and return it as a monadic value.
3319 The state is assumed to be a list.
3320 @end deffn
3321
3322 @deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3323 Run monadic value @var{mval} starting with @var{state} as the initial
3324 state. Return two values: the resulting value, and the resulting state.
3325 @end deffn
3326
3327 The main interface to the store monad, provided by the @code{(guix
3328 store)} module, is as follows.
3329
3330 @defvr {Scheme Variable} %store-monad
3331 The store monad---an alias for @var{%state-monad}.
3332
3333 Values in the store monad encapsulate accesses to the store. When its
3334 effect is needed, a value of the store monad must be ``evaluated'' by
3335 passing it to the @code{run-with-store} procedure (see below.)
3336 @end defvr
3337
3338 @deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3339 Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3340 open store connection.
3341 @end deffn
3342
3343 @deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
3344 Return as a monadic value the absolute file name in the store of the file
3345 containing @var{text}, a string. @var{references} is a list of store items that the
3346 resulting text file refers to; it defaults to the empty list.
3347 @end deffn
3348
3349 @deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
3350 [#:recursive? #t]
3351 Return the name of @var{file} once interned in the store. Use
3352 @var{name} as its store name, or the basename of @var{file} if
3353 @var{name} is omitted.
3354
3355 When @var{recursive?} is true, the contents of @var{file} are added
3356 recursively; if @var{file} designates a flat file and @var{recursive?}
3357 is true, its contents are added, and its permission bits are kept.
3358
3359 The example below adds a file to the store, under two different names:
3360
3361 @example
3362 (run-with-store (open-connection)
3363 (mlet %store-monad ((a (interned-file "README"))
3364 (b (interned-file "README" "LEGU-MIN")))
3365 (return (list a b))))
3366
3367 @result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3368 @end example
3369
3370 @end deffn
3371
3372 The @code{(guix packages)} module exports the following package-related
3373 monadic procedures:
3374
3375 @deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
3376 [#:system (%current-system)] [#:target #f] @
3377 [#:output "out"]
3378 Return as a monadic
3379 value in the absolute file name of @var{file} within the @var{output}
3380 directory of @var{package}. When @var{file} is omitted, return the name
3381 of the @var{output} directory of @var{package}. When @var{target} is
3382 true, use it as a cross-compilation target triplet.
3383 @end deffn
3384
3385 @deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
3386 @deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3387 @var{target} [@var{system}]
3388 Monadic version of @code{package-derivation} and
3389 @code{package-cross-derivation} (@pxref{Defining Packages}).
3390 @end deffn
3391
3392
3393 @node G-Expressions
3394 @section G-Expressions
3395
3396 @cindex G-expression
3397 @cindex build code quoting
3398 So we have ``derivations'', which represent a sequence of build actions
3399 to be performed to produce an item in the store (@pxref{Derivations}).
3400 These build actions are performed when asking the daemon to actually
3401 build the derivations; they are run by the daemon in a container
3402 (@pxref{Invoking guix-daemon}).
3403
3404 @cindex strata of code
3405 It should come as no surprise that we like to write these build actions
3406 in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3407 code@footnote{The term @dfn{stratum} in this context was coined by
3408 Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3409 Kiselyov, who has written insightful
3410 @url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3411 on this topic}, refers to this kind of code generation as
3412 @dfn{staging}.}: the ``host code''---code that defines packages, talks
3413 to the daemon, etc.---and the ``build code''---code that actually
3414 performs build actions, such as making directories, invoking
3415 @command{make}, etc.
3416
3417 To describe a derivation and its build actions, one typically needs to
3418 embed build code inside host code. It boils down to manipulating build
3419 code as data, and the homoiconicity of Scheme---code has a direct
3420 representation as data---comes in handy for that. But we need more than
3421 the normal @code{quasiquote} mechanism in Scheme to construct build
3422 expressions.
3423
3424 The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3425 S-expressions adapted to build expressions. G-expressions, or
3426 @dfn{gexps}, consist essentially of three syntactic forms: @code{gexp},
3427 @code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
3428 @code{#$}, and @code{#$@@}), which are comparable to
3429 @code{quasiquote}, @code{unquote}, and @code{unquote-splicing},
3430 respectivel (@pxref{Expression Syntax, @code{quasiquote},, guile,
3431 GNU Guile Reference Manual}). However, there are major differences:
3432
3433 @itemize
3434 @item
3435 Gexps are meant to be written to a file and run or manipulated by other
3436 processes.
3437
3438 @item
3439 When a high-level object such as a package or derivation is unquoted
3440 inside a gexp, the result is as if its output file name had been
3441 introduced.
3442
3443 @item
3444 Gexps carry information about the packages or derivations they refer to,
3445 and these dependencies are automatically added as inputs to the build
3446 processes that use them.
3447 @end itemize
3448
3449 @cindex lowering, of high-level objects in gexps
3450 This mechanism is not limited to package and derivation
3451 objects: @dfn{compilers} able to ``lower'' other high-level objects to
3452 derivations or files in the store can be defined,
3453 such that these objects can also be inserted
3454 into gexps. For example, a useful type of high-level objects that can be
3455 inserted in a gexp is ``file-like objects'', which make it easy to
3456 add files to the store and to refer to them in
3457 derivations and such (see @code{local-file} and @code{plain-file}
3458 below.)
3459
3460 To illustrate the idea, here is an example of a gexp:
3461
3462 @example
3463 (define build-exp
3464 #~(begin
3465 (mkdir #$output)
3466 (chdir #$output)
3467 (symlink (string-append #$coreutils "/bin/ls")
3468 "list-files")))
3469 @end example
3470
3471 This gexp can be passed to @code{gexp->derivation}; we obtain a
3472 derivation that builds a directory containing exactly one symlink to
3473 @file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3474
3475 @example
3476 (gexp->derivation "the-thing" build-exp)
3477 @end example
3478
3479 As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
3480 substituted to the reference to the @var{coreutils} package in the
3481 actual build code, and @var{coreutils} is automatically made an input to
3482 the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
3483 output)}) is replaced by a string containing the directory name of the
3484 output of the derivation.
3485
3486 @cindex cross compilation
3487 In a cross-compilation context, it is useful to distinguish between
3488 references to the @emph{native} build of a package---that can run on the
3489 host---versus references to cross builds of a package. To that end, the
3490 @code{#+} plays the same role as @code{#$}, but is a reference to a
3491 native package build:
3492
3493 @example
3494 (gexp->derivation "vi"
3495 #~(begin
3496 (mkdir #$output)
3497 (system* (string-append #+coreutils "/bin/ln")
3498 "-s"
3499 (string-append #$emacs "/bin/emacs")
3500 (string-append #$output "/bin/vi")))
3501 #:target "mips64el-linux")
3502 @end example
3503
3504 @noindent
3505 In the example above, the native build of @var{coreutils} is used, so
3506 that @command{ln} can actually run on the host; but then the
3507 cross-compiled build of @var{emacs} is referenced.
3508
3509 The syntactic form to construct gexps is summarized below.
3510
3511 @deffn {Scheme Syntax} #~@var{exp}
3512 @deffnx {Scheme Syntax} (gexp @var{exp})
3513 Return a G-expression containing @var{exp}. @var{exp} may contain one
3514 or more of the following forms:
3515
3516 @table @code
3517 @item #$@var{obj}
3518 @itemx (ungexp @var{obj})
3519 Introduce a reference to @var{obj}. @var{obj} may have one of the
3520 supported types, for example a package or a
3521 derivation, in which case the @code{ungexp} form is replaced by its
3522 output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
3523
3524 If @var{obj} is a list, it is traversed and references to supported
3525 objects are substituted similarly.
3526
3527 If @var{obj} is another gexp, its contents are inserted and its
3528 dependencies are added to those of the containing gexp.
3529
3530 If @var{obj} is another kind of object, it is inserted as is.
3531
3532 @item #$@var{obj}:@var{output}
3533 @itemx (ungexp @var{obj} @var{output})
3534 This is like the form above, but referring explicitly to the
3535 @var{output} of @var{obj}---this is useful when @var{obj} produces
3536 multiple outputs (@pxref{Packages with Multiple Outputs}).
3537
3538 @item #+@var{obj}
3539 @itemx #+@var{obj}:output
3540 @itemx (ungexp-native @var{obj})
3541 @itemx (ungexp-native @var{obj} @var{output})
3542 Same as @code{ungexp}, but produces a reference to the @emph{native}
3543 build of @var{obj} when used in a cross compilation context.
3544
3545 @item #$output[:@var{output}]
3546 @itemx (ungexp output [@var{output}])
3547 Insert a reference to derivation output @var{output}, or to the main
3548 output when @var{output} is omitted.
3549
3550 This only makes sense for gexps passed to @code{gexp->derivation}.
3551
3552 @item #$@@@var{lst}
3553 @itemx (ungexp-splicing @var{lst})
3554 Like the above, but splices the contents of @var{lst} inside the
3555 containing list.
3556
3557 @item #+@@@var{lst}
3558 @itemx (ungexp-native-splicing @var{lst})
3559 Like the above, but refers to native builds of the objects listed in
3560 @var{lst}.
3561
3562 @end table
3563
3564 G-expressions created by @code{gexp} or @code{#~} are run-time objects
3565 of the @code{gexp?} type (see below.)
3566 @end deffn
3567
3568 @deffn {Scheme Procedure} gexp? @var{obj}
3569 Return @code{#t} if @var{obj} is a G-expression.
3570 @end deffn
3571
3572 G-expressions are meant to be written to disk, either as code building
3573 some derivation, or as plain files in the store. The monadic procedures
3574 below allow you to do that (@pxref{The Store Monad}, for more
3575 information about monads.)
3576
3577 @deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
3578 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
3579 [#:hash #f] [#:hash-algo #f] @
3580 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3581 [#:module-path @var{%load-path}] @
3582 [#:references-graphs #f] [#:allowed-references #f] @
3583 [#:leaked-env-vars #f] @
3584 [#:script-name (string-append @var{name} "-builder")] @
3585 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3586 Return a derivation @var{name} that runs @var{exp} (a gexp) with
3587 @var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
3588 stored in a file called @var{script-name}. When @var{target} is true,
3589 it is used as the cross-compilation target triplet for packages referred
3590 to by @var{exp}.
3591
3592 Make @var{modules} available in the evaluation context of @var{exp};
3593 @var{modules} is a list of names of Guile modules searched in
3594 @var{module-path} to be copied in the store, compiled, and made available in
3595 the load path during the execution of @var{exp}---e.g., @code{((guix
3596 build utils) (guix build gnu-build-system))}.
3597
3598 @var{graft?} determines whether packages referred to by @var{exp} should be grafted when
3599 applicable.
3600
3601 When @var{references-graphs} is true, it must be a list of tuples of one of the
3602 following forms:
3603
3604 @example
3605 (@var{file-name} @var{package})
3606 (@var{file-name} @var{package} @var{output})
3607 (@var{file-name} @var{derivation})
3608 (@var{file-name} @var{derivation} @var{output})
3609 (@var{file-name} @var{store-item})
3610 @end example
3611
3612 The right-hand-side of each element of @var{references-graphs} is automatically made
3613 an input of the build process of @var{exp}. In the build environment, each
3614 @var{file-name} contains the reference graph of the corresponding item, in a simple
3615 text format.
3616
3617 @var{allowed-references} must be either @code{#f} or a list of output names and packages.
3618 In the latter case, the list denotes store items that the result is allowed to
3619 refer to. Any reference to another store item will lead to a build error.
3620
3621 The other arguments are as for @code{derivation} (@pxref{Derivations}).
3622 @end deffn
3623
3624 @cindex file-like objects
3625 The @code{local-file}, @code{plain-file}, @code{computed-file},
3626 @code{program-file}, and @code{scheme-file} procedures below return
3627 @dfn{file-like objects}. That is, when unquoted in a G-expression,
3628 these objects lead to a file in the store. Consider this G-expression:
3629
3630 @example
3631 #~(system* (string-append #$glibc "/sbin/nscd") "-f"
3632 #$(local-file "/tmp/my-nscd.conf"))
3633 @end example
3634
3635 The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
3636 to the store. Once expanded, for instance @i{via}
3637 @code{gexp->derivation}, the G-expression refers to that copy under
3638 @file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
3639 does not have any effect on what the G-expression does.
3640 @code{plain-file} can be used similarly; it differs in that the file
3641 content is directly passed as a string.
3642
3643 @deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
3644 [#:recursive? #t]
3645 Return an object representing local file @var{file} to add to the store; this
3646 object can be used in a gexp. If @var{file} is a relative file name, it is looked
3647 up relative to the source file where this form appears. @var{file} will be added to
3648 the store under @var{name}--by default the base name of @var{file}.
3649
3650 When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
3651 designates a flat file and @var{recursive?} is true, its contents are added, and its
3652 permission bits are kept.
3653
3654 This is the declarative counterpart of the @code{interned-file} monadic
3655 procedure (@pxref{The Store Monad, @code{interned-file}}).
3656 @end deffn
3657
3658 @deffn {Scheme Procedure} plain-file @var{name} @var{content}
3659 Return an object representing a text file called @var{name} with the given
3660 @var{content} (a string) to be added to the store.
3661
3662 This is the declarative counterpart of @code{text-file}.
3663 @end deffn
3664
3665 @deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
3666 [#:modules '()] [#:options '(#:local-build? #t)]
3667 Return an object representing the store item @var{name}, a file or
3668 directory computed by @var{gexp}. @var{modules} specifies the set of
3669 modules visible in the execution context of @var{gexp}. @var{options}
3670 is a list of additional arguments to pass to @code{gexp->derivation}.
3671
3672 This is the declarative counterpart of @code{gexp->derivation}.
3673 @end deffn
3674
3675 @deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
3676 Return an executable script @var{name} that runs @var{exp} using
3677 @var{guile} with @var{modules} in its search path.
3678
3679 The example below builds a script that simply invokes the @command{ls}
3680 command:
3681
3682 @example
3683 (use-modules (guix gexp) (gnu packages base))
3684
3685 (gexp->script "list-files"
3686 #~(execl (string-append #$coreutils "/bin/ls")
3687 "ls"))
3688 @end example
3689
3690 When ``running'' it through the store (@pxref{The Store Monad,
3691 @code{run-with-store}}), we obtain a derivation that produces an
3692 executable file @file{/gnu/store/@dots{}-list-files} along these lines:
3693
3694 @example
3695 #!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
3696 !#
3697 (execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls")
3698 "ls")
3699 @end example
3700 @end deffn
3701
3702 @deffn {Scheme Procedure} program-file @var{name} @var{exp} @
3703 [#:modules '()] [#:guile #f]
3704 Return an object representing the executable store item @var{name} that
3705 runs @var{gexp}. @var{guile} is the Guile package used to execute that
3706 script, and @var{modules} is the list of modules visible to that script.
3707
3708 This is the declarative counterpart of @code{gexp->script}.
3709 @end deffn
3710
3711 @deffn {Monadic Procedure} gexp->file @var{name} @var{exp}
3712 Return a derivation that builds a file @var{name} containing @var{exp}.
3713
3714 The resulting file holds references to all the dependencies of @var{exp}
3715 or a subset thereof.
3716 @end deffn
3717
3718 @deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
3719 Return an object representing the Scheme file @var{name} that contains
3720 @var{exp}.
3721
3722 This is the declarative counterpart of @code{gexp->file}.
3723 @end deffn
3724
3725 @deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
3726 Return as a monadic value a derivation that builds a text file
3727 containing all of @var{text}. @var{text} may list, in addition to
3728 strings, objects of any type that can be used in a gexp: packages,
3729 derivations, local file objects, etc. The resulting store file holds
3730 references to all these.
3731
3732 This variant should be preferred over @code{text-file} anytime the file
3733 to create will reference items from the store. This is typically the
3734 case when building a configuration file that embeds store file names,
3735 like this:
3736
3737 @example
3738 (define (profile.sh)
3739 ;; Return the name of a shell script in the store that
3740 ;; initializes the 'PATH' environment variable.
3741 (text-file* "profile.sh"
3742 "export PATH=" coreutils "/bin:"
3743 grep "/bin:" sed "/bin\n"))
3744 @end example
3745
3746 In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
3747 will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
3748 preventing them from being garbage-collected during its lifetime.
3749 @end deffn
3750
3751 @deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
3752 Return an object representing store file @var{name} containing
3753 @var{text}. @var{text} is a sequence of strings and file-like objects,
3754 as in:
3755
3756 @example
3757 (mixed-text-file "profile"
3758 "export PATH=" coreutils "/bin:" grep "/bin")
3759 @end example
3760
3761 This is the declarative counterpart of @code{text-file*}.
3762 @end deffn
3763
3764 Of course, in addition to gexps embedded in ``host'' code, there are
3765 also modules containing build tools. To make it clear that they are
3766 meant to be used in the build stratum, these modules are kept in the
3767 @code{(guix build @dots{})} name space.
3768
3769 @cindex lowering, of high-level objects in gexps
3770 Internally, high-level objects are @dfn{lowered}, using their compiler,
3771 to either derivations or store items. For instance, lowering a package
3772 yields a derivation, and lowering a @code{plain-file} yields a store
3773 item. This is achieved using the @code{lower-object} monadic procedure.
3774
3775 @deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
3776 [#:target #f]
3777 Return as a value in @var{%store-monad} the derivation or store item
3778 corresponding to @var{obj} for @var{system}, cross-compiling for
3779 @var{target} if @var{target} is true. @var{obj} must be an object that
3780 has an associated gexp compiler, such as a @code{<package>}.
3781 @end deffn
3782
3783
3784 @c *********************************************************************
3785 @node Utilities
3786 @chapter Utilities
3787
3788 This section describes tools primarily targeted at developers and users
3789 who write new package definitions. They complement the Scheme
3790 programming interface of Guix in a convenient way.
3791
3792 @menu
3793 * Invoking guix build:: Building packages from the command line.
3794 * Invoking guix edit:: Editing package definitions.
3795 * Invoking guix download:: Downloading a file and printing its hash.
3796 * Invoking guix hash:: Computing the cryptographic hash of a file.
3797 * Invoking guix import:: Importing package definitions.
3798 * Invoking guix refresh:: Updating package definitions.
3799 * Invoking guix lint:: Finding errors in package definitions.
3800 * Invoking guix size:: Profiling disk usage.
3801 * Invoking guix graph:: Visualizing the graph of packages.
3802 * Invoking guix environment:: Setting up development environments.
3803 * Invoking guix publish:: Sharing substitutes.
3804 * Invoking guix challenge:: Challenging substitute servers.
3805 * Invoking guix container:: Process isolation.
3806 @end menu
3807
3808 @node Invoking guix build
3809 @section Invoking @command{guix build}
3810
3811 The @command{guix build} command builds packages or derivations and
3812 their dependencies, and prints the resulting store paths. Note that it
3813 does not modify the user's profile---this is the job of the
3814 @command{guix package} command (@pxref{Invoking guix package}). Thus,
3815 it is mainly useful for distribution developers.
3816
3817 The general syntax is:
3818
3819 @example
3820 guix build @var{options} @var{package-or-derivation}@dots{}
3821 @end example
3822
3823 As an example, the following command builds the latest versions of Emacs
3824 and of Guile, displays their build logs, and finally displays the
3825 resulting directories:
3826
3827 @example
3828 guix build emacs guile
3829 @end example
3830
3831 Similarly, the following command builds all the available packages:
3832
3833 @example
3834 guix build --keep-going \
3835 `guix package -A | cut -f1,2 --output-delimiter=@@`
3836 @end example
3837
3838 @var{package-or-derivation} may be either the name of a package found in
3839 the software distribution such as @code{coreutils} or
3840 @code{coreutils-8.20}, or a derivation such as
3841 @file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
3842 package with the corresponding name (and optionally version) is searched
3843 for among the GNU distribution modules (@pxref{Package Modules}).
3844
3845 Alternatively, the @code{--expression} option may be used to specify a
3846 Scheme expression that evaluates to a package; this is useful when
3847 disambiguation among several same-named packages or package variants is
3848 needed.
3849
3850 There may be zero or more @var{options}. The available options are
3851 described in the subsections below.
3852
3853 @menu
3854 * Common Build Options:: Build options for most commands.
3855 * Package Transformation Options:: Creating variants of packages.
3856 * Additional Build Options:: Options specific to 'guix build'.
3857 @end menu
3858
3859 @node Common Build Options
3860 @subsection Common Build Options
3861
3862 A number of options that control the build process are common to
3863 @command{guix build} and other commands that can spawn builds, such as
3864 @command{guix package} or @command{guix archive}. These are the
3865 following:
3866
3867 @table @code
3868
3869 @item --load-path=@var{directory}
3870 @itemx -L @var{directory}
3871 Add @var{directory} to the front of the package module search path
3872 (@pxref{Package Modules}).
3873
3874 This allows users to define their own packages and make them visible to
3875 the command-line tools.
3876
3877 @item --keep-failed
3878 @itemx -K
3879 Keep the build tree of failed builds. Thus, if a build fail, its build
3880 tree is kept under @file{/tmp}, in a directory whose name is shown at
3881 the end of the build log. This is useful when debugging build issues.
3882
3883 @item --keep-going
3884 @itemx -k
3885 Keep going when some of the derivations fail to build; return only once
3886 all the builds have either completed or failed.
3887
3888 The default behavior is to stop as soon as one of the specified
3889 derivations has failed.
3890
3891 @item --dry-run
3892 @itemx -n
3893 Do not build the derivations.
3894
3895 @item --fallback
3896 When substituting a pre-built binary fails, fall back to building
3897 packages locally.
3898
3899 @item --substitute-urls=@var{urls}
3900 @anchor{client-substitute-urls}
3901 Consider @var{urls} the whitespace-separated list of substitute source
3902 URLs, overriding the default list of URLs of @command{guix-daemon}
3903 (@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
3904
3905 This means that substitutes may be downloaded from @var{urls}, provided
3906 they are signed by a key authorized by the system administrator
3907 (@pxref{Substitutes}).
3908
3909 @item --no-substitutes
3910 Do not use substitutes for build products. That is, always build things
3911 locally instead of allowing downloads of pre-built binaries
3912 (@pxref{Substitutes}).
3913
3914 @item --rounds=@var{n}
3915 Build each derivation @var{n} times in a row, and raise an error if
3916 consecutive build results are not bit-for-bit identical.
3917
3918 This is a useful way to detect non-deterministic builds processes.
3919 Non-deterministic build processes are a problem because they make it
3920 practically impossible for users to @emph{verify} whether third-party
3921 binaries are genuine. @xref{Invoking guix challenge}, for more.
3922
3923 Note that, currently, the differing build results are not kept around,
3924 so you will have to manually investigate in case of an error---e.g., by
3925 stashing one of the build results with @code{guix archive --export},
3926 then rebuilding, and finally comparing the two results.
3927
3928 @item --no-build-hook
3929 Do not attempt to offload builds @i{via} the ``build hook'' of the daemon
3930 (@pxref{Daemon Offload Setup}). That is, always build things locally
3931 instead of offloading builds to remote machines.
3932
3933 @item --max-silent-time=@var{seconds}
3934 When the build or substitution process remains silent for more than
3935 @var{seconds}, terminate it and report a build failure.
3936
3937 @item --timeout=@var{seconds}
3938 Likewise, when the build or substitution process lasts for more than
3939 @var{seconds}, terminate it and report a build failure.
3940
3941 By default there is no timeout. This behavior can be restored with
3942 @code{--timeout=0}.
3943
3944 @item --verbosity=@var{level}
3945 Use the given verbosity level. @var{level} must be an integer between 0
3946 and 5; higher means more verbose output. Setting a level of 4 or more
3947 may be helpful when debugging setup issues with the build daemon.
3948
3949 @item --cores=@var{n}
3950 @itemx -c @var{n}
3951 Allow the use of up to @var{n} CPU cores for the build. The special
3952 value @code{0} means to use as many CPU cores as available.
3953
3954 @item --max-jobs=@var{n}
3955 @itemx -M @var{n}
3956 Allow at most @var{n} build jobs in parallel. @xref{Invoking
3957 guix-daemon, @code{--max-jobs}}, for details about this option and the
3958 equivalent @command{guix-daemon} option.
3959
3960 @end table
3961
3962 Behind the scenes, @command{guix build} is essentially an interface to
3963 the @code{package-derivation} procedure of the @code{(guix packages)}
3964 module, and to the @code{build-derivations} procedure of the @code{(guix
3965 derivations)} module.
3966
3967 In addition to options explicitly passed on the command line,
3968 @command{guix build} and other @command{guix} commands that support
3969 building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
3970
3971 @defvr {Environment Variable} GUIX_BUILD_OPTIONS
3972 Users can define this variable to a list of command line options that
3973 will automatically be used by @command{guix build} and other
3974 @command{guix} commands that can perform builds, as in the example
3975 below:
3976
3977 @example
3978 $ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
3979 @end example
3980
3981 These options are parsed independently, and the result is appended to
3982 the parsed command-line options.
3983 @end defvr
3984
3985
3986 @node Package Transformation Options
3987 @subsection Package Transformation Options
3988
3989 @cindex package variants
3990 Another set of command-line options supported by @command{guix build}
3991 and also @command{guix package} are @dfn{package transformation
3992 options}. These are options that make it possible to define @dfn{package
3993 variants}---for instance, packages built from different source code.
3994 This is a convenient way to create customized packages on the fly
3995 without having to type in the definitions of package variants
3996 (@pxref{Defining Packages}).
3997
3998 @table @code
3999
4000 @item --with-source=@var{source}
4001 Use @var{source} as the source of the corresponding package.
4002 @var{source} must be a file name or a URL, as for @command{guix
4003 download} (@pxref{Invoking guix download}).
4004
4005 The ``corresponding package'' is taken to be the one specified on the
4006 command line the name of which matches the base of @var{source}---e.g.,
4007 if @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
4008 package is @code{guile}. Likewise, the version string is inferred from
4009 @var{source}; in the previous example, it is @code{2.0.10}.
4010
4011 This option allows users to try out versions of packages other than the
4012 one provided by the distribution. The example below downloads
4013 @file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
4014 the @code{ed} package:
4015
4016 @example
4017 guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
4018 @end example
4019
4020 As a developer, @code{--with-source} makes it easy to test release
4021 candidates:
4022
4023 @example
4024 guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
4025 @end example
4026
4027 @dots{} or to build from a checkout in a pristine environment:
4028
4029 @example
4030 $ git clone git://git.sv.gnu.org/guix.git
4031 $ guix build guix --with-source=./guix
4032 @end example
4033
4034 @item --with-input=@var{package}=@var{replacement}
4035 Replace dependency on @var{package} by a dependency on
4036 @var{replacement}. @var{package} must be a package name, and
4037 @var{replacement} must be a package specification such as @code{guile}
4038 or @code{guile@@1.8}.
4039
4040 For instance, the following command builds Guix, but replaces its
4041 dependency on the current stable version of Guile with a dependency on
4042 the development version of Guile, @code{guile-next}:
4043
4044 @example
4045 guix build --with-input=guile=guile-next guix
4046 @end example
4047
4048 This is a recursive, deep replacement. So in this example, both
4049 @code{guix} and its dependency @code{guile-json} (which also depends on
4050 @code{guile}) get rebuilt against @code{guile-next}.
4051
4052 However, implicit inputs are left unchanged.
4053 @end table
4054
4055 @node Additional Build Options
4056 @subsection Additional Build Options
4057
4058 The command-line options presented below are specific to @command{guix
4059 build}.
4060
4061 @table @code
4062
4063 @item --file=@var{file}
4064 @itemx -f @var{file}
4065
4066 Build the package or derivation that the code within @var{file}
4067 evaluates to.
4068
4069 As an example, @var{file} might contain a package definition like this
4070 (@pxref{Defining Packages}):
4071
4072 @example
4073 @verbatiminclude package-hello.scm
4074 @end example
4075
4076 @item --expression=@var{expr}
4077 @itemx -e @var{expr}
4078 Build the package or derivation @var{expr} evaluates to.
4079
4080 For example, @var{expr} may be @code{(@@ (gnu packages guile)
4081 guile-1.8)}, which unambiguously designates this specific variant of
4082 version 1.8 of Guile.
4083
4084 Alternatively, @var{expr} may be a G-expression, in which case it is used
4085 as a build program passed to @code{gexp->derivation}
4086 (@pxref{G-Expressions}).
4087
4088 Lastly, @var{expr} may refer to a zero-argument monadic procedure
4089 (@pxref{The Store Monad}). The procedure must return a derivation as a
4090 monadic value, which is then passed through @code{run-with-store}.
4091
4092 @item --source
4093 @itemx -S
4094 Build the source derivations of the packages, rather than the packages
4095 themselves.
4096
4097 For instance, @code{guix build -S gcc} returns something like
4098 @file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
4099 source tarball.
4100
4101 The returned source tarball is the result of applying any patches and
4102 code snippets specified in the package @code{origin} (@pxref{Defining
4103 Packages}).
4104
4105 @item --sources
4106 Fetch and return the source of @var{package-or-derivation} and all their
4107 dependencies, recursively. This is a handy way to obtain a local copy
4108 of all the source code needed to build @var{packages}, allowing you to
4109 eventually build them even without network access. It is an extension
4110 of the @code{--source} option and can accept one of the following
4111 optional argument values:
4112
4113 @table @code
4114 @item package
4115 This value causes the @code{--sources} option to behave in the same way
4116 as the @code{--source} option.
4117
4118 @item all
4119 Build the source derivations of all packages, including any source that
4120 might be listed as @code{inputs}. This is the default value.
4121
4122 @example
4123 $ guix build --sources tzdata
4124 The following derivations will be built:
4125 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
4126 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4127 @end example
4128
4129 @item transitive
4130 Build the source derivations of all packages, as well of all transitive
4131 inputs to the packages. This can be used e.g. to
4132 prefetch package source for later offline building.
4133
4134 @example
4135 $ guix build --sources=transitive tzdata
4136 The following derivations will be built:
4137 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4138 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
4139 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
4140 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
4141 /gnu/store/@dots{}-make-4.1.tar.xz.drv
4142 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
4143 @dots{}
4144 @end example
4145
4146 @end table
4147
4148 @item --system=@var{system}
4149 @itemx -s @var{system}
4150 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
4151 the system type of the build host.
4152
4153 An example use of this is on Linux-based systems, which can emulate
4154 different personalities. For instance, passing
4155 @code{--system=i686-linux} on an @code{x86_64-linux} system allows users
4156 to build packages in a complete 32-bit environment.
4157
4158 @item --target=@var{triplet}
4159 @cindex cross-compilation
4160 Cross-build for @var{triplet}, which must be a valid GNU triplet, such
4161 as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
4162 configuration triplets,, configure, GNU Configure and Build System}).
4163
4164 @anchor{build-check}
4165 @item --check
4166 @cindex determinism, checking
4167 @cindex reproducibility, checking
4168 Rebuild @var{package-or-derivation}, which are already available in the
4169 store, and raise an error if the build results are not bit-for-bit
4170 identical.
4171
4172 This mechanism allows you to check whether previously installed
4173 substitutes are genuine (@pxref{Substitutes}), or whether the build result
4174 of a package is deterministic. @xref{Invoking guix challenge}, for more
4175 background information and tools.
4176
4177 @item --no-grafts
4178 Do not ``graft'' packages. In practice, this means that package updates
4179 available as grafts are not applied. @xref{Security Updates}, for more
4180 information on grafts.
4181
4182 @item --derivations
4183 @itemx -d
4184 Return the derivation paths, not the output paths, of the given
4185 packages.
4186
4187 @item --root=@var{file}
4188 @itemx -r @var{file}
4189 Make @var{file} a symlink to the result, and register it as a garbage
4190 collector root.
4191
4192 @item --log-file
4193 Return the build log file names or URLs for the given
4194 @var{package-or-derivation}, or raise an error if build logs are
4195 missing.
4196
4197 This works regardless of how packages or derivations are specified. For
4198 instance, the following invocations are equivalent:
4199
4200 @example
4201 guix build --log-file `guix build -d guile`
4202 guix build --log-file `guix build guile`
4203 guix build --log-file guile
4204 guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
4205 @end example
4206
4207 If a log is unavailable locally, and unless @code{--no-substitutes} is
4208 passed, the command looks for a corresponding log on one of the
4209 substitute servers (as specified with @code{--substitute-urls}.)
4210
4211 So for instance, imagine you want to see the build log of GDB on MIPS,
4212 but you are actually on an @code{x86_64} machine:
4213
4214 @example
4215 $ guix build --log-file gdb -s mips64el-linux
4216 http://hydra.gnu.org/log/@dots{}-gdb-7.10
4217 @end example
4218
4219 You can freely access a huge library of build logs!
4220 @end table
4221
4222
4223 @node Invoking guix edit
4224 @section Invoking @command{guix edit}
4225
4226 @cindex package definition, editing
4227 So many packages, so many source files! The @command{guix edit} command
4228 facilitates the life of packagers by pointing their editor at the source
4229 file containing the definition of the specified packages. For instance:
4230
4231 @example
4232 guix edit gcc-4.8 vim
4233 @end example
4234
4235 @noindent
4236 launches the program specified in the @code{VISUAL} or in the
4237 @code{EDITOR} environment variable to edit the recipe of GCC@tie{}4.8.4
4238 and that of Vim.
4239
4240 If you are using Emacs, note that the Emacs user interface provides the
4241 @kbd{M-x guix-edit} command and a similar functionality in the ``package
4242 info'' and ``package list'' buffers created by the @kbd{M-x
4243 guix-search-by-name} and similar commands (@pxref{Emacs Commands}).
4244
4245
4246 @node Invoking guix download
4247 @section Invoking @command{guix download}
4248
4249 When writing a package definition, developers typically need to download
4250 a source tarball, compute its SHA256 hash, and write that
4251 hash in the package definition (@pxref{Defining Packages}). The
4252 @command{guix download} tool helps with this task: it downloads a file
4253 from the given URI, adds it to the store, and prints both its file name
4254 in the store and its SHA256 hash.
4255
4256 The fact that the downloaded file is added to the store saves bandwidth:
4257 when the developer eventually tries to build the newly defined package
4258 with @command{guix build}, the source tarball will not have to be
4259 downloaded again because it is already in the store. It is also a
4260 convenient way to temporarily stash files, which may be deleted
4261 eventually (@pxref{Invoking guix gc}).
4262
4263 The @command{guix download} command supports the same URIs as used in
4264 package definitions. In particular, it supports @code{mirror://} URIs.
4265 @code{https} URIs (HTTP over TLS) are supported @emph{provided} the
4266 Guile bindings for GnuTLS are available in the user's environment; when
4267 they are not available, an error is raised. @xref{Guile Preparations,
4268 how to install the GnuTLS bindings for Guile,, gnutls-guile,
4269 GnuTLS-Guile}, for more information.
4270
4271 The following option is available:
4272
4273 @table @code
4274 @item --format=@var{fmt}
4275 @itemx -f @var{fmt}
4276 Write the hash in the format specified by @var{fmt}. For more
4277 information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
4278 @end table
4279
4280 @node Invoking guix hash
4281 @section Invoking @command{guix hash}
4282
4283 The @command{guix hash} command computes the SHA256 hash of a file.
4284 It is primarily a convenience tool for anyone contributing to the
4285 distribution: it computes the cryptographic hash of a file, which can be
4286 used in the definition of a package (@pxref{Defining Packages}).
4287
4288 The general syntax is:
4289
4290 @example
4291 guix hash @var{option} @var{file}
4292 @end example
4293
4294 @command{guix hash} has the following option:
4295
4296 @table @code
4297
4298 @item --format=@var{fmt}
4299 @itemx -f @var{fmt}
4300 Write the hash in the format specified by @var{fmt}.
4301
4302 Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4303 (@code{hex} and @code{hexadecimal} can be used as well).
4304
4305 If the @option{--format} option is not specified, @command{guix hash}
4306 will output the hash in @code{nix-base32}. This representation is used
4307 in the definitions of packages.
4308
4309 @item --recursive
4310 @itemx -r
4311 Compute the hash on @var{file} recursively.
4312
4313 In this case, the hash is computed on an archive containing @var{file},
4314 including its children if it is a directory. Some of the metadata of
4315 @var{file} is part of the archive; for instance, when @var{file} is a
4316 regular file, the hash is different depending on whether @var{file} is
4317 executable or not. Metadata such as time stamps has no impact on the
4318 hash (@pxref{Invoking guix archive}).
4319 @c FIXME: Replace xref above with xref to an ``Archive'' section when
4320 @c it exists.
4321
4322 @end table
4323
4324 @node Invoking guix import
4325 @section Invoking @command{guix import}
4326
4327 @cindex importing packages
4328 @cindex package import
4329 @cindex package conversion
4330 The @command{guix import} command is useful for people who would like to
4331 add a package to the distribution with as little work as
4332 possible---a legitimate demand. The command knows of a few
4333 repositories from which it can ``import'' package metadata. The result
4334 is a package definition, or a template thereof, in the format we know
4335 (@pxref{Defining Packages}).
4336
4337 The general syntax is:
4338
4339 @example
4340 guix import @var{importer} @var{options}@dots{}
4341 @end example
4342
4343 @var{importer} specifies the source from which to import package
4344 metadata, and @var{options} specifies a package identifier and other
4345 options specific to @var{importer}. Currently, the available
4346 ``importers'' are:
4347
4348 @table @code
4349 @item gnu
4350 Import metadata for the given GNU package. This provides a template
4351 for the latest version of that GNU package, including the hash of its
4352 source tarball, and its canonical synopsis and description.
4353
4354 Additional information such as the package dependencies and its
4355 license needs to be figured out manually.
4356
4357 For example, the following command returns a package definition for
4358 GNU@tie{}Hello:
4359
4360 @example
4361 guix import gnu hello
4362 @end example
4363
4364 Specific command-line options are:
4365
4366 @table @code
4367 @item --key-download=@var{policy}
4368 As for @code{guix refresh}, specify the policy to handle missing OpenPGP
4369 keys when verifying the package signature. @xref{Invoking guix
4370 refresh, @code{--key-download}}.
4371 @end table
4372
4373 @item pypi
4374 @cindex pypi
4375 Import metadata from the @uref{https://pypi.python.org/, Python Package
4376 Index}@footnote{This functionality requires Guile-JSON to be installed.
4377 @xref{Requirements}.}. Information is taken from the JSON-formatted
4378 description available at @code{pypi.python.org} and usually includes all
4379 the relevant information, including package dependencies.
4380
4381 The command below imports metadata for the @code{itsdangerous} Python
4382 package:
4383
4384 @example
4385 guix import pypi itsdangerous
4386 @end example
4387
4388 @item gem
4389 @cindex gem
4390 Import metadata from @uref{https://rubygems.org/,
4391 RubyGems}@footnote{This functionality requires Guile-JSON to be
4392 installed. @xref{Requirements}.}. Information is taken from the
4393 JSON-formatted description available at @code{rubygems.org} and includes
4394 most relevant information, including runtime dependencies. There are
4395 some caveats, however. The metadata doesn't distinguish between
4396 synopses and descriptions, so the same string is used for both fields.
4397 Additionally, the details of non-Ruby dependencies required to build
4398 native extensions is unavailable and left as an exercise to the
4399 packager.
4400
4401 The command below imports metadata for the @code{rails} Ruby package:
4402
4403 @example
4404 guix import gem rails
4405 @end example
4406
4407 @item cpan
4408 @cindex CPAN
4409 Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}@footnote{This
4410 functionality requires Guile-JSON to be installed.
4411 @xref{Requirements}.}.
4412 Information is taken from the JSON-formatted metadata provided through
4413 @uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
4414 relevant information, such as module dependencies. License information
4415 should be checked closely. If Perl is available in the store, then the
4416 @code{corelist} utility will be used to filter core modules out of the
4417 list of dependencies.
4418
4419 The command command below imports metadata for the @code{Acme::Boolean}
4420 Perl module:
4421
4422 @example
4423 guix import cpan Acme::Boolean
4424 @end example
4425
4426 @item cran
4427 @cindex CRAN
4428 @cindex Bioconductor
4429 Import metadata from @uref{http://cran.r-project.org/, CRAN}, the
4430 central repository for the @uref{http://r-project.org, GNU@tie{}R
4431 statistical and graphical environment}.
4432
4433 Information is extracted from the @code{DESCRIPTION} file of the package.
4434
4435 The command command below imports metadata for the @code{Cairo}
4436 R package:
4437
4438 @example
4439 guix import cran Cairo
4440 @end example
4441
4442 When @code{--archive=bioconductor} is added, metadata is imported from
4443 @uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
4444 packages for for the analysis and comprehension of high-throughput
4445 genomic data in bioinformatics.
4446
4447 Information is extracted from the @code{DESCRIPTION} file of a package
4448 published on the web interface of the Bioconductor SVN repository.
4449
4450 The command below imports metadata for the @code{GenomicRanges}
4451 R package:
4452
4453 @example
4454 guix import cran --archive=bioconductor GenomicRanges
4455 @end example
4456
4457 @item nix
4458 Import metadata from a local copy of the source of the
4459 @uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
4460 relies on the @command{nix-instantiate} command of
4461 @uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
4462 typically written in a mixture of Nix-language and Bash code. This
4463 command only imports the high-level package structure that is written in
4464 the Nix language. It normally includes all the basic fields of a
4465 package definition.
4466
4467 When importing a GNU package, the synopsis and descriptions are replaced
4468 by their canonical upstream variant.
4469
4470 Usually, you will first need to do:
4471
4472 @example
4473 export NIX_REMOTE=daemon
4474 @end example
4475
4476 @noindent
4477 so that @command{nix-instantiate} does not try to open the Nix database.
4478
4479 As an example, the command below imports the package definition of
4480 LibreOffice (more precisely, it imports the definition of the package
4481 bound to the @code{libreoffice} top-level attribute):
4482
4483 @example
4484 guix import nix ~/path/to/nixpkgs libreoffice
4485 @end example
4486
4487 @item hackage
4488 @cindex hackage
4489 Import metadata from the Haskell community's central package archive
4490 @uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4491 Cabal files and includes all the relevant information, including package
4492 dependencies.
4493
4494 Specific command-line options are:
4495
4496 @table @code
4497 @item --stdin
4498 @itemx -s
4499 Read a Cabal file from standard input.
4500 @item --no-test-dependencies
4501 @itemx -t
4502 Do not include dependencies required only by the test suites.
4503 @item --cabal-environment=@var{alist}
4504 @itemx -e @var{alist}
4505 @var{alist} is a Scheme alist defining the environment in which the
4506 Cabal conditionals are evaluated. The accepted keys are: @code{os},
4507 @code{arch}, @code{impl} and a string representing the name of a flag.
4508 The value associated with a flag has to be either the symbol
4509 @code{true} or @code{false}. The value associated with other keys
4510 has to conform to the Cabal file format definition. The default value
4511 associated with the keys @code{os}, @code{arch} and @code{impl} is
4512 @samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
4513 @end table
4514
4515 The command below imports metadata for the latest version of the
4516 @code{HTTP} Haskell package without including test dependencies and
4517 specifying the value of the flag @samp{network-uri} as @code{false}:
4518
4519 @example
4520 guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
4521 @end example
4522
4523 A specific package version may optionally be specified by following the
4524 package name by a hyphen and a version number as in the following example:
4525
4526 @example
4527 guix import hackage mtl-2.1.3.1
4528 @end example
4529
4530 @item elpa
4531 @cindex elpa
4532 Import metadata from an Emacs Lisp Package Archive (ELPA) package
4533 repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4534
4535 Specific command-line options are:
4536
4537 @table @code
4538 @item --archive=@var{repo}
4539 @itemx -a @var{repo}
4540 @var{repo} identifies the archive repository from which to retrieve the
4541 information. Currently the supported repositories and their identifiers
4542 are:
4543 @itemize -
4544 @item
4545 @uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
4546 identifier. This is the default.
4547
4548 @item
4549 @uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
4550 @code{melpa-stable} identifier.
4551
4552 @item
4553 @uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
4554 identifier.
4555 @end itemize
4556 @end table
4557 @end table
4558
4559 The structure of the @command{guix import} code is modular. It would be
4560 useful to have more importers for other package formats, and your help
4561 is welcome here (@pxref{Contributing}).
4562
4563 @node Invoking guix refresh
4564 @section Invoking @command{guix refresh}
4565
4566 The primary audience of the @command{guix refresh} command is developers
4567 of the GNU software distribution. By default, it reports any packages
4568 provided by the distribution that are outdated compared to the latest
4569 upstream version, like this:
4570
4571 @example
4572 $ guix refresh
4573 gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
4574 gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
4575 @end example
4576
4577 It does so by browsing the FTP directory of each package and determining
4578 the highest version number of the source tarballs therein. The command
4579 knows how to update specific types of packages: GNU packages, ELPA
4580 packages, etc.---see the documentation for @option{--type} below. The
4581 are many packages, though, for which it lacks a method to determine
4582 whether a new upstream release is available. However, the mechanism is
4583 extensible, so feel free to get in touch with us to add a new method!
4584
4585 When passed @code{--update}, it modifies distribution source files to
4586 update the version numbers and source tarball hashes of those package
4587 recipes (@pxref{Defining Packages}). This is achieved by downloading
4588 each package's latest source tarball and its associated OpenPGP
4589 signature, authenticating the downloaded tarball against its signature
4590 using @command{gpg}, and finally computing its hash. When the public
4591 key used to sign the tarball is missing from the user's keyring, an
4592 attempt is made to automatically retrieve it from a public key server;
4593 when this is successful, the key is added to the user's keyring; otherwise,
4594 @command{guix refresh} reports an error.
4595
4596 The following options are supported:
4597
4598 @table @code
4599
4600 @item --expression=@var{expr}
4601 @itemx -e @var{expr}
4602 Consider the package @var{expr} evaluates to.
4603
4604 This is useful to precisely refer to a package, as in this example:
4605
4606 @example
4607 guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
4608 @end example
4609
4610 This command lists the dependents of the ``final'' libc (essentially all
4611 the packages.)
4612
4613 @item --update
4614 @itemx -u
4615 Update distribution source files (package recipes) in place. This is
4616 usually run from a checkout of the Guix source tree (@pxref{Running
4617 Guix Before It Is Installed}):
4618
4619 @example
4620 $ ./pre-inst-env guix refresh -s non-core
4621 @end example
4622
4623 @xref{Defining Packages}, for more information on package definitions.
4624
4625 @item --select=[@var{subset}]
4626 @itemx -s @var{subset}
4627 Select all the packages in @var{subset}, one of @code{core} or
4628 @code{non-core}.
4629
4630 The @code{core} subset refers to all the packages at the core of the
4631 distribution---i.e., packages that are used to build ``everything
4632 else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
4633 changing one of these packages in the distribution entails a rebuild of
4634 all the others. Thus, such updates are an inconvenience to users in
4635 terms of build time or bandwidth used to achieve the upgrade.
4636
4637 The @code{non-core} subset refers to the remaining packages. It is
4638 typically useful in cases where an update of the core packages would be
4639 inconvenient.
4640
4641 @item --type=@var{updater}
4642 @itemx -t @var{updater}
4643 Select only packages handled by @var{updater} (may be a comma-separated
4644 list of updaters). Currently, @var{updater} may be one of:
4645
4646 @table @code
4647 @item gnu
4648 the updater for GNU packages;
4649 @item gnome
4650 the updater for GNOME packages;
4651 @item xorg
4652 the updater for X.org packages;
4653 @item elpa
4654 the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
4655 @item cran
4656 the updater for @uref{http://cran.r-project.org/, CRAN} packages;
4657 @item bioconductor
4658 the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
4659 @item pypi
4660 the updater for @uref{https://pypi.python.org, PyPI} packages.
4661 @item gem
4662 the updater for @uref{https://rubygems.org, RubyGems} packages.
4663 @end table
4664
4665 For instance, the following command only checks for updates of Emacs
4666 packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
4667
4668 @example
4669 $ guix refresh --type=elpa,cran
4670 gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
4671 gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
4672 @end example
4673
4674 @end table
4675
4676 In addition, @command{guix refresh} can be passed one or more package
4677 names, as in this example:
4678
4679 @example
4680 $ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
4681 @end example
4682
4683 @noindent
4684 The command above specifically updates the @code{emacs} and
4685 @code{idutils} packages. The @code{--select} option would have no
4686 effect in this case.
4687
4688 When considering whether to upgrade a package, it is sometimes
4689 convenient to know which packages would be affected by the upgrade and
4690 should be checked for compatibility. For this the following option may
4691 be used when passing @command{guix refresh} one or more package names:
4692
4693 @table @code
4694
4695 @item --list-updaters
4696 @itemx -L
4697 List available updaters and exit (see @option{--type} above.)
4698
4699 @item --list-dependent
4700 @itemx -l
4701 List top-level dependent packages that would need to be rebuilt as a
4702 result of upgrading one or more packages.
4703
4704 @end table
4705
4706 Be aware that the @code{--list-dependent} option only
4707 @emph{approximates} the rebuilds that would be required as a result of
4708 an upgrade. More rebuilds might be required under some circumstances.
4709
4710 @example
4711 $ guix refresh --list-dependent flex
4712 Building the following 120 packages would ensure 213 dependent packages are rebuilt:
4713 hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
4714 @end example
4715
4716 The command above lists a set of packages that could be built to check
4717 for compatibility with an upgraded @code{flex} package.
4718
4719 The following options can be used to customize GnuPG operation:
4720
4721 @table @code
4722
4723 @item --gpg=@var{command}
4724 Use @var{command} as the GnuPG 2.x command. @var{command} is searched
4725 for in @code{$PATH}.
4726
4727 @item --key-download=@var{policy}
4728 Handle missing OpenPGP keys according to @var{policy}, which may be one
4729 of:
4730
4731 @table @code
4732 @item always
4733 Always download missing OpenPGP keys from the key server, and add them
4734 to the user's GnuPG keyring.
4735
4736 @item never
4737 Never try to download missing OpenPGP keys. Instead just bail out.
4738
4739 @item interactive
4740 When a package signed with an unknown OpenPGP key is encountered, ask
4741 the user whether to download it or not. This is the default behavior.
4742 @end table
4743
4744 @item --key-server=@var{host}
4745 Use @var{host} as the OpenPGP key server when importing a public key.
4746
4747 @end table
4748
4749 @node Invoking guix lint
4750 @section Invoking @command{guix lint}
4751 The @command{guix lint} command is meant to help package developers avoid
4752 common errors and use a consistent style. It runs a number of checks on
4753 a given set of packages in order to find common mistakes in their
4754 definitions. Available @dfn{checkers} include (see
4755 @code{--list-checkers} for a complete list):
4756
4757 @table @code
4758 @item synopsis
4759 @itemx description
4760 Validate certain typographical and stylistic rules about package
4761 descriptions and synopses.
4762
4763 @item inputs-should-be-native
4764 Identify inputs that should most likely be native inputs.
4765
4766 @item source
4767 @itemx home-page
4768 @itemx source-file-name
4769 Probe @code{home-page} and @code{source} URLs and report those that are
4770 invalid. Check that the source file name is meaningful, e.g. is not
4771 just a version number or ``git-checkout'', without a declared
4772 @code{file-name} (@pxref{origin Reference}).
4773
4774 @item cve
4775 Report known vulnerabilities found in the Common Vulnerabilities and
4776 Exposures (CVE) database
4777 @uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
4778 NIST}.
4779
4780 @item formatting
4781 Warn about obvious source code formatting issues: trailing white space,
4782 use of tabulations, etc.
4783 @end table
4784
4785 The general syntax is:
4786
4787 @example
4788 guix lint @var{options} @var{package}@dots{}
4789 @end example
4790
4791 If no package is given on the command line, then all packages are checked.
4792 The @var{options} may be zero or more of the following:
4793
4794 @table @code
4795 @item --list-checkers
4796 @itemx -l
4797 List and describe all the available checkers that will be run on packages
4798 and exit.
4799
4800 @item --checkers
4801 @itemx -c
4802 Only enable the checkers specified in a comma-separated list using the
4803 names returned by @code{--list-checkers}.
4804
4805 @end table
4806
4807 @node Invoking guix size
4808 @section Invoking @command{guix size}
4809
4810 The @command{guix size} command helps package developers profile the
4811 disk usage of packages. It is easy to overlook the impact of an
4812 additional dependency added to a package, or the impact of using a
4813 single output for a package that could easily be split (@pxref{Packages
4814 with Multiple Outputs}). Such are the typical issues that
4815 @command{guix size} can highlight.
4816
4817 The command can be passed a package specification such as @code{gcc-4.8}
4818 or @code{guile:debug}, or a file name in the store. Consider this
4819 example:
4820
4821 @example
4822 $ guix size coreutils
4823 store item total self
4824 /gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
4825 /gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
4826 /gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
4827 /gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
4828 /gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
4829 /gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
4830 @end example
4831
4832 @cindex closure
4833 The store items listed here constitute the @dfn{transitive closure} of
4834 Coreutils---i.e., Coreutils and all its dependencies, recursively---as
4835 would be returned by:
4836
4837 @example
4838 $ guix gc -R /gnu/store/@dots{}-coreutils-8.23
4839 @end example
4840
4841 Here the output shows three columns next to store items. The first column,
4842 labeled ``total'', shows the size in mebibytes (MiB) of the closure of
4843 the store item---that is, its own size plus the size of all its
4844 dependencies. The next column, labeled ``self'', shows the size of the
4845 item itself. The last column shows the ratio of the size of the item
4846 itself to the space occupied by all the items listed here.
4847
4848 In this example, we see that the closure of Coreutils weighs in at
4849 70@tie{}MiB, half of which is taken by libc. (That libc represents a
4850 large fraction of the closure is not a problem @i{per se} because it is
4851 always available on the system anyway.)
4852
4853 When the package passed to @command{guix size} is available in the
4854 store, @command{guix size} queries the daemon to determine its
4855 dependencies, and measures its size in the store, similar to @command{du
4856 -ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
4857 Coreutils}).
4858
4859 When the given package is @emph{not} in the store, @command{guix size}
4860 reports information based on the available substitutes
4861 (@pxref{Substitutes}). This makes it possible it to profile disk usage of
4862 store items that are not even on disk, only available remotely.
4863
4864 The available options are:
4865
4866 @table @option
4867
4868 @item --substitute-urls=@var{urls}
4869 Use substitute information from @var{urls}.
4870 @xref{client-substitute-urls, the same option for @code{guix build}}.
4871
4872 @item --map-file=@var{file}
4873 Write a graphical map of disk usage in PNG format to @var{file}.
4874
4875 For the example above, the map looks like this:
4876
4877 @image{images/coreutils-size-map,5in,, map of Coreutils disk usage
4878 produced by @command{guix size}}
4879
4880 This option requires that
4881 @uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
4882 installed and visible in Guile's module search path. When that is not
4883 the case, @command{guix size} fails as it tries to load it.
4884
4885 @item --system=@var{system}
4886 @itemx -s @var{system}
4887 Consider packages for @var{system}---e.g., @code{x86_64-linux}.
4888
4889 @end table
4890
4891 @node Invoking guix graph
4892 @section Invoking @command{guix graph}
4893
4894 @cindex DAG
4895 Packages and their dependencies form a @dfn{graph}, specifically a
4896 directed acyclic graph (DAG). It can quickly become difficult to have a
4897 mental model of the package DAG, so the @command{guix graph} command
4898 provides a visual representation of the DAG. @command{guix graph}
4899 emits a DAG representation in the input format of
4900 @uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
4901 directly to the @command{dot} command of Graphviz. The general
4902 syntax is:
4903
4904 @example
4905 guix graph @var{options} @var{package}@dots{}
4906 @end example
4907
4908 For example, the following command generates a PDF file representing the
4909 package DAG for the GNU@tie{}Core Utilities, showing its build-time
4910 dependencies:
4911
4912 @example
4913 guix graph coreutils | dot -Tpdf > dag.pdf
4914 @end example
4915
4916 The output looks like this:
4917
4918 @image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
4919
4920 Nice little graph, no?
4921
4922 But there is more than one graph! The one above is concise: it is the
4923 graph of package objects, omitting implicit inputs such as GCC, libc,
4924 grep, etc. It is often useful to have such a concise graph, but
4925 sometimes one may want to see more details. @command{guix graph} supports
4926 several types of graphs, allowing you to choose the level of detail:
4927
4928 @table @code
4929 @item package
4930 This is the default type used in the example above. It shows the DAG of
4931 package objects, excluding implicit dependencies. It is concise, but
4932 filters out many details.
4933
4934 @item bag-emerged
4935 This is the package DAG, @emph{including} implicit inputs.
4936
4937 For instance, the following command:
4938
4939 @example
4940 guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
4941 @end example
4942
4943 ... yields this bigger graph:
4944
4945 @image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
4946
4947 At the bottom of the graph, we see all the implicit inputs of
4948 @var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
4949
4950 Now, note that the dependencies of these implicit inputs---that is, the
4951 @dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
4952 here, for conciseness.
4953
4954 @item bag
4955 Similar to @code{bag-emerged}, but this time including all the bootstrap
4956 dependencies.
4957
4958 @item bag-with-origins
4959 Similar to @code{bag}, but also showing origins and their dependencies.
4960
4961 @item derivations
4962 This is the most detailed representation: It shows the DAG of
4963 derivations (@pxref{Derivations}) and plain store items. Compared to
4964 the above representation, many additional nodes are visible, including
4965 build scripts, patches, Guile modules, etc.
4966
4967 @end table
4968
4969 All the types above correspond to @emph{build-time dependencies}. The
4970 following graph type represents the @emph{run-time dependencies}:
4971
4972 @table @code
4973 @item references
4974 This is the graph of @dfn{references} of a package output, as returned
4975 by @command{guix gc --references} (@pxref{Invoking guix gc}).
4976
4977 If the given package output is not available in the store, @command{guix
4978 graph} attempts to obtain dependency information from substitutes.
4979 @end table
4980
4981 The available options are the following:
4982
4983 @table @option
4984 @item --type=@var{type}
4985 @itemx -t @var{type}
4986 Produce a graph output of @var{type}, where @var{type} must be one of
4987 the values listed above.
4988
4989 @item --list-types
4990 List the supported graph types.
4991
4992 @item --expression=@var{expr}
4993 @itemx -e @var{expr}
4994 Consider the package @var{expr} evaluates to.
4995
4996 This is useful to precisely refer to a package, as in this example:
4997
4998 @example
4999 guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
5000 @end example
5001 @end table
5002
5003
5004 @node Invoking guix environment
5005 @section Invoking @command{guix environment}
5006
5007 @cindex reproducible build environments
5008 @cindex development environments
5009 The purpose of @command{guix environment} is to assist hackers in
5010 creating reproducible development environments without polluting their
5011 package profile. The @command{guix environment} tool takes one or more
5012 packages, builds all of their inputs, and creates a shell
5013 environment to use them.
5014
5015 The general syntax is:
5016
5017 @example
5018 guix environment @var{options} @var{package}@dots{}
5019 @end example
5020
5021 The following example spawns a new shell set up for the development of
5022 GNU@tie{}Guile:
5023
5024 @example
5025 guix environment guile
5026 @end example
5027
5028 If the needed dependencies are not built yet, @command{guix environment}
5029 automatically builds them. The environment of the new shell is an augmented
5030 version of the environment that @command{guix environment} was run in.
5031 It contains the necessary search paths for building the given package
5032 added to the existing environment variables. To create a ``pure''
5033 environment, in which the original environment variables have been unset,
5034 use the @code{--pure} option@footnote{Users sometimes wrongfully augment
5035 environment variables such as @code{PATH} in their @file{~/.bashrc}
5036 file. As a consequence, when @code{guix environment} launches it, Bash
5037 may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
5038 environment variables. It is an error to define such environment
5039 variables in @file{.bashrc}; instead, they should be defined in
5040 @file{.bash_profile}, which is sourced only by log-in shells.
5041 @xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
5042 details on Bash start-up files.}.
5043
5044 @vindex GUIX_ENVIRONMENT
5045 @command{guix environment} defines the @code{GUIX_ENVIRONMENT}
5046 variable in the shell it spawns. This allows users to, say, define a
5047 specific prompt for development environments in their @file{.bashrc}
5048 (@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
5049
5050 @example
5051 if [ -n "$GUIX_ENVIRONMENT" ]
5052 then
5053 export PS1="\u@@\h \w [dev]\$ "
5054 fi
5055 @end example
5056
5057 Additionally, more than one package may be specified, in which case the
5058 union of the inputs for the given packages are used. For example, the
5059 command below spawns a shell where all of the dependencies of both Guile
5060 and Emacs are available:
5061
5062 @example
5063 guix environment guile emacs
5064 @end example
5065
5066 Sometimes an interactive shell session is not desired. An arbitrary
5067 command may be invoked by placing the @code{--} token to separate the
5068 command from the rest of the arguments:
5069
5070 @example
5071 guix environment guile -- make -j4
5072 @end example
5073
5074 In other situations, it is more convenient to specify the list of
5075 packages needed in the environment. For example, the following command
5076 runs @command{python} from an environment containing Python@tie{}2.7 and
5077 NumPy:
5078
5079 @example
5080 guix environment --ad-hoc python2-numpy python-2.7 -- python
5081 @end example
5082
5083 Furthermore, one might want the dependencies of a package and also some
5084 additional packages that are not build-time or runtime dependencies, but
5085 are useful when developing nonetheless. Because of this, the
5086 @code{--ad-hoc} flag is positional. Packages appearing before
5087 @code{--ad-hoc} are interpreted as packages whose dependencies will be
5088 added to the environment. Packages appearing after are interpreted as
5089 packages that will be added to the environment directly. For example,
5090 the following command creates a Guix development environment that
5091 additionally includes Git and strace:
5092
5093 @example
5094 guix environment guix --ad-hoc git strace
5095 @end example
5096
5097 Sometimes it is desirable to isolate the environment as much as
5098 possible, for maximal purity and reproducibility. In particular, when
5099 using Guix on a host distro that is not GuixSD, it is desirable to
5100 prevent access to @file{/usr/bin} and other system-wide resources from
5101 the development environment. For example, the following command spawns
5102 a Guile REPL in a ``container'' where only the store and the current
5103 working directory are mounted:
5104
5105 @example
5106 guix environment --ad-hoc --container guile -- guile
5107 @end example
5108
5109 @quotation Note
5110 The @code{--container} option requires Linux-libre 3.19 or newer.
5111 @end quotation
5112
5113 The available options are summarized below.
5114
5115 @table @code
5116 @item --expression=@var{expr}
5117 @itemx -e @var{expr}
5118 Create an environment for the package or list of packages that
5119 @var{expr} evaluates to.
5120
5121 For example, running:
5122
5123 @example
5124 guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
5125 @end example
5126
5127 starts a shell with the environment for this specific variant of the
5128 PETSc package.
5129
5130 Running:
5131
5132 @example
5133 guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
5134 @end example
5135
5136 starts a shell with all the GuixSD base packages available.
5137
5138 The above commands only the use default output of the given packages.
5139 To select other outputs, two element tuples can be specified:
5140
5141 @example
5142 guix environment --ad-hoc -e '(list (@ (gnu packages bash) bash) "include")'
5143 @end example
5144
5145 @item --load=@var{file}
5146 @itemx -l @var{file}
5147 Create an environment for the package or list of packages that the code
5148 within @var{file} evaluates to.
5149
5150 As an example, @var{file} might contain a definition like this
5151 (@pxref{Defining Packages}):
5152
5153 @example
5154 @verbatiminclude environment-gdb.scm
5155 @end example
5156
5157 @item --ad-hoc
5158 Include all specified packages in the resulting environment, as if an
5159 @i{ad hoc} package were defined with them as inputs. This option is
5160 useful for quickly creating an environment without having to write a
5161 package expression to contain the desired inputs.
5162
5163 For instance, the command:
5164
5165 @example
5166 guix environment --ad-hoc guile guile-sdl -- guile
5167 @end example
5168
5169 runs @command{guile} in an environment where Guile and Guile-SDL are
5170 available.
5171
5172 Note that this example implicitly asks for the default output of
5173 @code{guile} and @code{guile-sdl}, but it is possible to ask for a
5174 specific output---e.g., @code{glib:bin} asks for the @code{bin} output
5175 of @code{glib} (@pxref{Packages with Multiple Outputs}).
5176
5177 This option may be composed with the default behavior of @command{guix
5178 environment}. Packages appearing before @code{--ad-hoc} are interpreted
5179 as packages whose dependencies will be added to the environment, the
5180 default behavior. Packages appearing after are interpreted as packages
5181 that will be added to the environment directly.
5182
5183 @item --pure
5184 Unset existing environment variables when building the new environment.
5185 This has the effect of creating an environment in which search paths
5186 only contain package inputs.
5187
5188 @item --search-paths
5189 Display the environment variable definitions that make up the
5190 environment.
5191
5192 @item --system=@var{system}
5193 @itemx -s @var{system}
5194 Attempt to build for @var{system}---e.g., @code{i686-linux}.
5195
5196 @item --container
5197 @itemx -C
5198 @cindex container
5199 Run @var{command} within an isolated container. The current working
5200 directory outside the container is mapped inside the
5201 container. Additionally, the spawned process runs as the current user
5202 outside the container, but has root privileges in the context of the
5203 container.
5204
5205 @item --network
5206 @itemx -N
5207 For containers, share the network namespace with the host system.
5208 Containers created without this flag only have access to the loopback
5209 device.
5210
5211 @item --expose=@var{source}[=@var{target}]
5212 For containers, expose the file system @var{source} from the host system
5213 as the read-only file system @var{target} within the container. If
5214 @var{target} is not specified, @var{source} is used as the target mount
5215 point in the container.
5216
5217 The example below spawns a Guile REPL in a container in which the user's
5218 home directory is accessible read-only via the @file{/exchange}
5219 directory:
5220
5221 @example
5222 guix environment --container --expose=$HOME=/exchange guile -- guile
5223 @end example
5224
5225 @item --share=@var{source}[=@var{target}]
5226 For containers, share the file system @var{source} from the host system
5227 as the writable file system @var{target} within the container. If
5228 @var{target} is not specified, @var{source} is used as the target mount
5229 point in the container.
5230
5231 The example below spawns a Guile REPL in a container in which the user's
5232 home directory is accessible for both reading and writing via the
5233 @file{/exchange} directory:
5234
5235 @example
5236 guix environment --container --share=$HOME=/exchange guile -- guile
5237 @end example
5238 @end table
5239
5240 It also supports all of the common build options that @command{guix
5241 build} supports (@pxref{Common Build Options}).
5242
5243 @node Invoking guix publish
5244 @section Invoking @command{guix publish}
5245
5246 The purpose of @command{guix publish} is to enable users to easily share
5247 their store with others, who can then use it as a substitute server
5248 (@pxref{Substitutes}).
5249
5250 When @command{guix publish} runs, it spawns an HTTP server which allows
5251 anyone with network access to obtain substitutes from it. This means
5252 that any machine running Guix can also act as if it were a build farm,
5253 since the HTTP interface is compatible with Hydra, the software behind
5254 the @code{hydra.gnu.org} build farm.
5255
5256 For security, each substitute is signed, allowing recipients to check
5257 their authenticity and integrity (@pxref{Substitutes}). Because
5258 @command{guix publish} uses the signing key of the system, which is only
5259 readable by the system administrator, it must be started as root; the
5260 @code{--user} option makes it drop root privileges early on.
5261
5262 The signing key pair must be generated before @command{guix publish} is
5263 launched, using @command{guix archive --generate-key} (@pxref{Invoking
5264 guix archive}).
5265
5266 The general syntax is:
5267
5268 @example
5269 guix publish @var{options}@dots{}
5270 @end example
5271
5272 Running @command{guix publish} without any additional arguments will
5273 spawn an HTTP server on port 8080:
5274
5275 @example
5276 guix publish
5277 @end example
5278
5279 Once a publishing server has been authorized (@pxref{Invoking guix
5280 archive}), the daemon may download substitutes from it:
5281
5282 @example
5283 guix-daemon --substitute-urls=http://example.org:8080
5284 @end example
5285
5286 The following options are available:
5287
5288 @table @code
5289 @item --port=@var{port}
5290 @itemx -p @var{port}
5291 Listen for HTTP requests on @var{port}.
5292
5293 @item --listen=@var{host}
5294 Listen on the network interface for @var{host}. The default is to
5295 accept connections from any interface.
5296
5297 @item --user=@var{user}
5298 @itemx -u @var{user}
5299 Change privileges to @var{user} as soon as possible---i.e., once the
5300 server socket is open and the signing key has been read.
5301
5302 @item --repl[=@var{port}]
5303 @itemx -r [@var{port}]
5304 Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
5305 Reference Manual}) on @var{port} (37146 by default). This is used
5306 primarily for debugging a running @command{guix publish} server.
5307 @end table
5308
5309 Enabling @command{guix publish} on a GuixSD system is a one-liner: just
5310 add a call to @code{guix-publish-service} in the @code{services} field
5311 of the @code{operating-system} declaration (@pxref{guix-publish-service,
5312 @code{guix-publish-service}}).
5313
5314
5315 @node Invoking guix challenge
5316 @section Invoking @command{guix challenge}
5317
5318 @cindex reproducible builds
5319 @cindex verifiable builds
5320
5321 Do the binaries provided by this server really correspond to the source
5322 code it claims to build? Is a package build process deterministic?
5323 These are the questions the @command{guix challenge} command attempts to
5324 answer.
5325
5326 The former is obviously an important question: Before using a substitute
5327 server (@pxref{Substitutes}), one had better @emph{verify} that it
5328 provides the right binaries, and thus @emph{challenge} it. The latter
5329 is what enables the former: If package builds are deterministic, then
5330 independent builds of the package should yield the exact same result,
5331 bit for bit; if a server provides a binary different from the one
5332 obtained locally, it may be either corrupt or malicious.
5333
5334 We know that the hash that shows up in @file{/gnu/store} file names is
5335 the hash of all the inputs of the process that built the file or
5336 directory---compilers, libraries, build scripts,
5337 etc. (@pxref{Introduction}). Assuming deterministic build processes,
5338 one store file name should map to exactly one build output.
5339 @command{guix challenge} checks whether there is, indeed, a single
5340 mapping by comparing the build outputs of several independent builds of
5341 any given store item.
5342
5343 The command output looks like this:
5344
5345 @smallexample
5346 $ guix challenge --substitute-urls="http://hydra.gnu.org http://guix.example.org"
5347 updating list of substitutes from 'http://hydra.gnu.org'... 100.0%
5348 updating list of substitutes from 'http://guix.example.org'... 100.0%
5349 /gnu/store/@dots{}-openssl-1.0.2d contents differ:
5350 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5351 http://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5352 http://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
5353 /gnu/store/@dots{}-git-2.5.0 contents differ:
5354 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
5355 http://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
5356 http://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
5357 /gnu/store/@dots{}-pius-2.1.1 contents differ:
5358 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5359 http://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5360 http://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
5361 @end smallexample
5362
5363 @noindent
5364 In this example, @command{guix challenge} first scans the store to
5365 determine the set of locally-built derivations---as opposed to store
5366 items that were downloaded from a substitute server---and then queries
5367 all the substitute servers. It then reports those store items for which
5368 the servers obtained a result different from the local build.
5369
5370 @cindex non-determinism, in package builds
5371 As an example, @code{guix.example.org} always gets a different answer.
5372 Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
5373 case of Git. This might indicate that the build process of Git is
5374 non-deterministic, meaning that its output varies as a function of
5375 various things that Guix does not fully control, in spite of building
5376 packages in isolated environments (@pxref{Features}). Most common
5377 sources of non-determinism include the addition of timestamps in build
5378 results, the inclusion of random numbers, and directory listings sorted
5379 by inode number. See @uref{http://reproducible.debian.net/howto/}, for
5380 more information.
5381
5382 To find out what is wrong with this Git binary, we can do something along
5383 these lines (@pxref{Invoking guix archive}):
5384
5385 @example
5386 $ wget -q -O - http://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
5387 | guix archive -x /tmp/git
5388 $ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
5389 @end example
5390
5391 This command shows the difference between the files resulting from the
5392 local build, and the files resulting from the build on
5393 @code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
5394 diffutils, Comparing and Merging Files}). The @command{diff} command
5395 works great for text files. When binary files differ, a better option
5396 is @uref{http://diffoscope.org/, Diffoscope}, a tool that helps
5397 visualize differences for all kinds of files.
5398
5399 Once you have done that work, you can tell whether the differences are due
5400 to a non-deterministic build process or to a malicious server. We try
5401 hard to remove sources of non-determinism in packages to make it easier
5402 to verify substitutes, but of course, this is a process that
5403 involves not just Guix, but a large part of the free software community.
5404 In the meantime, @command{guix challenge} is one tool to help address
5405 the problem.
5406
5407 If you are writing packages for Guix, you are encouraged to check
5408 whether @code{hydra.gnu.org} and other substitute servers obtain the
5409 same build result as you did with:
5410
5411 @example
5412 $ guix challenge @var{package}
5413 @end example
5414
5415 @noindent
5416 where @var{package} is a package specification such as
5417 @code{guile-2.0} or @code{glibc:debug}.
5418
5419 The general syntax is:
5420
5421 @example
5422 guix challenge @var{options} [@var{packages}@dots{}]
5423 @end example
5424
5425 The one option that matters is:
5426
5427 @table @code
5428
5429 @item --substitute-urls=@var{urls}
5430 Consider @var{urls} the whitespace-separated list of substitute source
5431 URLs to compare to.
5432
5433 @end table
5434
5435
5436 @node Invoking guix container
5437 @section Invoking @command{guix container}
5438 @cindex container
5439
5440 @quotation Note
5441 As of version @value{VERSION}, this tool is experimental. The interface
5442 is subject to radical change in the future.
5443 @end quotation
5444
5445 The purpose of @command{guix container} is to manipulate processes
5446 running within an isolated environment, commonly known as a
5447 ``container'', typically created by the @command{guix environment}
5448 (@pxref{Invoking guix environment}) and @command{guix system container}
5449 (@pxref{Invoking guix system}) commands.
5450
5451 The general syntax is:
5452
5453 @example
5454 guix container @var{action} @var{options}@dots{}
5455 @end example
5456
5457 @var{action} specifies the operation to perform with a container, and
5458 @var{options} specifies the context-specific arguments for the action.
5459
5460 The following actions are available:
5461
5462 @table @code
5463 @item exec
5464 Execute a command within the context of a running container.
5465
5466 The syntax is:
5467
5468 @example
5469 guix container exec @var{pid} @var{program} @var{arguments}@dots{}
5470 @end example
5471
5472 @var{pid} specifies the process ID of the running container.
5473 @var{program} specifies an executable file name within the root file
5474 system of the container. @var{arguments} are the additional options that
5475 will be passed to @var{program}.
5476
5477 The following command launches an interactive login shell inside a
5478 GuixSD container, started by @command{guix system container}, and whose
5479 process ID is 9001:
5480
5481 @example
5482 guix container exec 9001 /run/current-system/profile/bin/bash --login
5483 @end example
5484
5485 Note that the @var{pid} cannot be the parent process of a container. It
5486 must be PID 1 of the container or one of its child processes.
5487
5488 @end table
5489
5490 @c *********************************************************************
5491 @node GNU Distribution
5492 @chapter GNU Distribution
5493
5494 @cindex Guix System Distribution
5495 @cindex GuixSD
5496 Guix comes with a distribution of the GNU system consisting entirely of
5497 free software@footnote{The term ``free'' here refers to the
5498 @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
5499 users of that software}.}. The
5500 distribution can be installed on its own (@pxref{System Installation}),
5501 but it is also possible to install Guix as a package manager on top of
5502 an installed GNU/Linux system (@pxref{Installation}). To distinguish
5503 between the two, we refer to the standalone distribution as the Guix
5504 System Distribution, or GuixSD.
5505
5506 The distribution provides core GNU packages such as GNU libc, GCC, and
5507 Binutils, as well as many GNU and non-GNU applications. The complete
5508 list of available packages can be browsed
5509 @url{http://www.gnu.org/software/guix/packages,on-line} or by
5510 running @command{guix package} (@pxref{Invoking guix package}):
5511
5512 @example
5513 guix package --list-available
5514 @end example
5515
5516 Our goal is to provide a practical 100% free software distribution of
5517 Linux-based and other variants of GNU, with a focus on the promotion and
5518 tight integration of GNU components, and an emphasis on programs and
5519 tools that help users exert that freedom.
5520
5521 Packages are currently available on the following platforms:
5522
5523 @table @code
5524
5525 @item x86_64-linux
5526 Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
5527
5528 @item i686-linux
5529 Intel 32-bit architecture (IA32), Linux-Libre kernel;
5530
5531 @item armhf-linux
5532 ARMv7-A architecture with hard float, Thumb-2 and NEON,
5533 using the EABI hard-float application binary interface (ABI),
5534 and Linux-Libre kernel.
5535
5536 @item mips64el-linux
5537 little-endian 64-bit MIPS processors, specifically the Loongson series,
5538 n32 ABI, and Linux-Libre kernel.
5539
5540 @end table
5541
5542 GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
5543
5544 @noindent
5545 For information on porting to other architectures or kernels,
5546 @pxref{Porting}.
5547
5548 @menu
5549 * System Installation:: Installing the whole operating system.
5550 * System Configuration:: Configuring the operating system.
5551 * Installing Debugging Files:: Feeding the debugger.
5552 * Security Updates:: Deploying security fixes quickly.
5553 * Package Modules:: Packages from the programmer's viewpoint.
5554 * Packaging Guidelines:: Growing the distribution.
5555 * Bootstrapping:: GNU/Linux built from scratch.
5556 * Porting:: Targeting another platform or kernel.
5557 @end menu
5558
5559 Building this distribution is a cooperative effort, and you are invited
5560 to join! @xref{Contributing}, for information about how you can help.
5561
5562 @node System Installation
5563 @section System Installation
5564
5565 @cindex Guix System Distribution
5566 This section explains how to install the Guix System Distribution
5567 on a machine. The Guix package manager can
5568 also be installed on top of a running GNU/Linux system,
5569 @pxref{Installation}.
5570
5571 @ifinfo
5572 @c This paragraph is for people reading this from tty2 of the
5573 @c installation image.
5574 You're reading this documentation with an Info reader. For details on
5575 how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
5576 link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit
5577 @kbd{l} afterwards to come back here.
5578 @end ifinfo
5579
5580 @menu
5581 * Limitations:: What you can expect.
5582 * USB Stick Installation:: Preparing the installation medium.
5583 * Preparing for Installation:: Networking, partitioning, etc.
5584 * Proceeding with the Installation:: The real thing.
5585 * Building the Installation Image:: How this comes to be.
5586 @end menu
5587
5588 @node Limitations
5589 @subsection Limitations
5590
5591 As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
5592 not production-ready. It may contain bugs and lack important
5593 features. Thus, if you are looking for a stable production system that
5594 respects your freedom as a computer user, a good solution at this point
5595 is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
5596 the more established GNU/Linux distributions}. We hope you can soon switch
5597 to the GuixSD without fear, of course. In the meantime, you can
5598 also keep using your distribution and try out the package manager on top
5599 of it (@pxref{Installation}).
5600
5601 Before you proceed with the installation, be aware of the following
5602 noteworthy limitations applicable to version @value{VERSION}:
5603
5604 @itemize
5605 @item
5606 The installation process does not include a graphical user interface and
5607 requires familiarity with GNU/Linux (see the following subsections to
5608 get a feel of what that means.)
5609
5610 @item
5611 The system does not yet provide full GNOME and KDE desktops. Xfce and
5612 Enlightenment are available, though, if graphical desktop environments
5613 are your thing, as well as a number of X11 window managers.
5614
5615 @item
5616 Support for the Logical Volume Manager (LVM) is missing.
5617
5618 @item
5619 Few system services are currently supported out-of-the-box
5620 (@pxref{Services}).
5621
5622 @item
5623 More than 3,000 packages are available, but you may
5624 occasionally find that a useful package is missing.
5625 @end itemize
5626
5627 You have been warned! But more than a disclaimer, this is an invitation
5628 to report issues (and success stories!), and to join us in improving it.
5629 @xref{Contributing}, for more info.
5630
5631 @node USB Stick Installation
5632 @subsection USB Stick Installation
5633
5634 An installation image for USB sticks can be downloaded from
5635 @indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5636 where @var{system} is one of:
5637
5638 @table @code
5639 @item x86_64-linux
5640 for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
5641
5642 @item i686-linux
5643 for a 32-bit GNU/Linux system on Intel-compatible CPUs.
5644 @end table
5645
5646 This image contains a single partition with the tools necessary for an
5647 installation. It is meant to be copied @emph{as is} to a large-enough
5648 USB stick.
5649
5650 To copy the image to a USB stick, follow these steps:
5651
5652 @enumerate
5653 @item
5654 Decompress the image using the @command{xz} command:
5655
5656 @example
5657 xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5658 @end example
5659
5660 @item
5661 Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
5662 its device name. Assuming that the USB stick is known as @file{/dev/sdX},
5663 copy the image with:
5664
5665 @example
5666 dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5667 @end example
5668
5669 Access to @file{/dev/sdX} usually requires root privileges.
5670 @end enumerate
5671
5672 Once this is done, you should be able to reboot the system and boot from
5673 the USB stick. The latter usually requires you to get in the BIOS' boot
5674 menu, where you can choose to boot from the USB stick.
5675
5676 @node Preparing for Installation
5677 @subsection Preparing for Installation
5678
5679 Once you have successfully booted the image on the USB stick, you should
5680 end up with a root prompt. Several console TTYs are configured and can
5681 be used to run commands as root. TTY2 shows this documentation,
5682 browsable using the Info reader commands (@pxref{Help,,, info, Info: An
5683 Introduction}). The installation system runs the GPM mouse daemon,
5684 which allows you to select text with the left mouse button and to paste
5685 it with the middle button.
5686
5687 @subsubsection Keyboard Layout
5688
5689 @cindex keyboard layout
5690 The installation image uses the US qwerty keyboard layout. If you want
5691 to change it, you can use the @command{loadkeys} command. For example,
5692 the following command selects the Dvorak keyboard layout:
5693
5694 @example
5695 loadkeys dvorak
5696 @end example
5697
5698 See the files under @file{/run/current-system/profile/share/keymaps} for
5699 a list of available keyboard layouts. Run @command{man loadkeys} for
5700 more information.
5701
5702 @subsubsection Networking
5703
5704 Run the following command see what your network interfaces are called:
5705
5706 @example
5707 ifconfig -a
5708 @end example
5709
5710 @c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
5711 Wired interfaces have a name starting with @samp{e}; for example, the
5712 interface corresponding to the first on-board Ethernet controller is
5713 called @samp{eno1}. Wireless interfaces have a name starting with
5714 @samp{w}, like @samp{w1p2s0}.
5715
5716 @table @asis
5717 @item Wired connection
5718 To configure a wired network run the following command, substituting
5719 @var{interface} with the name of the wired interface you want to use.
5720
5721 @example
5722 ifconfig @var{interface} up
5723 @end example
5724
5725 @item Wireless connection
5726 To configure wireless networking, you can create a configuration file
5727 for the @command{wpa_supplicant} configuration tool (its location is not
5728 important) using one of the available text editors such as
5729 @command{zile}:
5730
5731 @example
5732 zile wpa_supplicant.conf
5733 @end example
5734
5735 As an example, the following stanza can go to this file and will work
5736 for many wireless networks, provided you give the actual SSID and
5737 passphrase for the network you are connecting to:
5738
5739 @example
5740 network=@{
5741 ssid=@var{my-ssid}
5742 key_mgmt=WPA-PSK
5743 psk="the network's secret passphrase"
5744 @}
5745 @end example
5746
5747 Start the wireless service and run it in the background with the
5748 following command (substitute @var{interface} with the name of the
5749 network interface you want to use):
5750
5751 @example
5752 wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
5753 @end example
5754
5755 Run @command{man wpa_supplication} for more information.
5756 @end table
5757
5758 At this point, you need to acquire an IP address. On a network where IP
5759 addresses are automatically assigned @i{via} DHCP, you can run:
5760
5761 @example
5762 dhclient @var{interface}
5763 @end example
5764
5765 Try to ping a server to see if networking is up and running:
5766
5767 @example
5768 ping -c 3 gnu.org
5769 @end example
5770
5771 Setting up network access is almost always a requirement because the
5772 image does not contain all the software and tools that may be needed.
5773
5774 @subsubsection Disk Partitioning
5775
5776 Unless this has already been done, the next step is to partition, and
5777 then format the target partition(s).
5778
5779 The installation image includes several partitioning tools, including
5780 Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
5781 @command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
5782 the partition layout you want:
5783
5784 @example
5785 cfdisk
5786 @end example
5787
5788 Once you are done partitioning the target hard disk drive, you have to
5789 create a file system on the relevant partition(s)@footnote{Currently
5790 GuixSD pretty much assumes an ext4 file system. In particular, code
5791 that reads partition UUIDs and labels only works with ext4. This will
5792 be fixed in the future.}.
5793
5794 Preferably, assign partitions a label so that you can easily and
5795 reliably refer to them in @code{file-system} declarations (@pxref{File
5796 Systems}). This is typically done using the @code{-L} option of
5797 @command{mkfs.ext4} and related commands. So, assuming the target root
5798 partition lives at @file{/dev/sda1}, a file system with the label
5799 @code{my-root} can be created with:
5800
5801 @example
5802 mkfs.ext4 -L my-root /dev/sda1
5803 @end example
5804
5805 @c FIXME: Uncomment this once GRUB fully supports encrypted roots.
5806 @c A typical command sequence may be:
5807 @c
5808 @c @example
5809 @c # fdisk /dev/sdX
5810 @c @dots{} Create partitions etc.@dots{}
5811 @c # cryptsetup luksFormat /dev/sdX1
5812 @c # cryptsetup open --type luks /dev/sdX1 my-partition
5813 @c # mkfs.ext4 -L my-root /dev/mapper/my-partition
5814 @c @end example
5815
5816 In addition to e2fsprogs, the suite of tools to manipulate
5817 ext2/ext3/ext4 file systems, the installation image includes
5818 Cryptsetup/LUKS for disk encryption.
5819
5820 Once that is done, mount the target root partition under @file{/mnt}
5821 with a command like (again, assuming @file{/dev/sda1} is the root
5822 partition):
5823
5824 @example
5825 mount /dev/sda1 /mnt
5826 @end example
5827
5828 @node Proceeding with the Installation
5829 @subsection Proceeding with the Installation
5830
5831 With the target partitions ready and the target root mounted on
5832 @file{/mnt}, we're ready to go. First, run:
5833
5834 @example
5835 herd start cow-store /mnt
5836 @end example
5837
5838 This makes @file{/gnu/store} copy-on-write, such that packages added to
5839 it during the installation phase are written to the target disk rather
5840 than kept in memory.
5841
5842 Next, you have to edit a file and
5843 provide the declaration of the operating system to be installed. To
5844 that end, the installation system comes with two text editors: GNU nano
5845 (@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
5846 It is better to store that file on the target root file system, say, as
5847 @file{/mnt/etc/config.scm}.
5848
5849 @xref{Using the Configuration System}, for an overview of the
5850 configuration file. The example configurations discussed in that
5851 section are available under @file{/etc/configuration} in the
5852 installation image. Thus, to get started with a system configuration
5853 providing a graphical display server (a ``desktop'' system), you can run
5854 something along these lines:
5855
5856 @example
5857 # mkdir /mnt/etc
5858 # cp /etc/configuration/desktop.scm /mnt/etc/config.scm
5859 # zile /mnt/etc/config.scm
5860 @end example
5861
5862 You should pay attention to what your configuration file contains, and
5863 in particular:
5864
5865 @itemize
5866 @item
5867 Make sure the @code{grub-configuration} form refers to the device you
5868 want to install GRUB on.
5869
5870 @item
5871 Be sure that your partition labels match the value of their respective
5872 @code{device} fields in your @code{file-system} configuration, assuming
5873 your @code{file-system} configuration sets the value of @code{title} to
5874 @code{'label}.
5875 @end itemize
5876
5877 Once you are done preparing the configuration file, the new system must
5878 be initialized (remember that the target root file system is mounted
5879 under @file{/mnt}):
5880
5881 @example
5882 guix system init /mnt/etc/config.scm /mnt
5883 @end example
5884
5885 @noindent
5886 This copies all the necessary files and installs GRUB on
5887 @file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
5888 more information, @pxref{Invoking guix system}. This command may trigger
5889 downloads or builds of missing packages, which can take some time.
5890
5891 Once that command has completed---and hopefully succeeded!---you can run
5892 @command{reboot} and boot into the new system. The @code{root} password
5893 in the new system is initially empty; other users' passwords need to be
5894 initialized by running the @command{passwd} command as @code{root},
5895 unless your configuration specifies otherwise
5896 (@pxref{user-account-password, user account passwords}).
5897
5898 Join us on @code{#guix} on the Freenode IRC network or on
5899 @file{guix-devel@@gnu.org} to share your experience---good or not so
5900 good.
5901
5902 @node Building the Installation Image
5903 @subsection Building the Installation Image
5904
5905 The installation image described above was built using the @command{guix
5906 system} command, specifically:
5907
5908 @example
5909 guix system disk-image --image-size=850MiB gnu/system/install.scm
5910 @end example
5911
5912 @xref{Invoking guix system}, for more information. See
5913 @file{gnu/system/install.scm} in the source tree for more information
5914 about the installation image.
5915
5916 @node System Configuration
5917 @section System Configuration
5918
5919 @cindex system configuration
5920 The Guix System Distribution supports a consistent whole-system configuration
5921 mechanism. By that we mean that all aspects of the global system
5922 configuration---such as the available system services, timezone and
5923 locale settings, user accounts---are declared in a single place. Such
5924 a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
5925
5926 One of the advantages of putting all the system configuration under the
5927 control of Guix is that it supports transactional system upgrades, and
5928 makes it possible to roll-back to a previous system instantiation,
5929 should something go wrong with the new one (@pxref{Features}). Another
5930 one is that it makes it easy to replicate the exact same configuration
5931 across different machines, or at different points in time, without
5932 having to resort to additional administration tools layered on top of
5933 the system's own tools.
5934 @c Yes, we're talking of Puppet, Chef, & co. here. ↑
5935
5936 This section describes this mechanism. First we focus on the system
5937 administrator's viewpoint---explaining how the system is configured and
5938 instantiated. Then we show how this mechanism can be extended, for
5939 instance to support new system services.
5940
5941 @menu
5942 * Using the Configuration System:: Customizing your GNU system.
5943 * operating-system Reference:: Detail of operating-system declarations.
5944 * File Systems:: Configuring file system mounts.
5945 * Mapped Devices:: Block device extra processing.
5946 * User Accounts:: Specifying user accounts.
5947 * Locales:: Language and cultural convention settings.
5948 * Services:: Specifying system services.
5949 * Setuid Programs:: Programs running with root privileges.
5950 * X.509 Certificates:: Authenticating HTTPS servers.
5951 * Name Service Switch:: Configuring libc's name service switch.
5952 * Initial RAM Disk:: Linux-Libre bootstrapping.
5953 * GRUB Configuration:: Configuring the boot loader.
5954 * Invoking guix system:: Instantiating a system configuration.
5955 * Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
5956 * Defining Services:: Adding new service definitions.
5957 @end menu
5958
5959 @node Using the Configuration System
5960 @subsection Using the Configuration System
5961
5962 The operating system is configured by providing an
5963 @code{operating-system} declaration in a file that can then be passed to
5964 the @command{guix system} command (@pxref{Invoking guix system}). A
5965 simple setup, with the default system services, the default Linux-Libre
5966 kernel, initial RAM disk, and boot loader looks like this:
5967
5968 @findex operating-system
5969 @lisp
5970 @include os-config-bare-bones.texi
5971 @end lisp
5972
5973 This example should be self-describing. Some of the fields defined
5974 above, such as @code{host-name} and @code{bootloader}, are mandatory.
5975 Others, such as @code{packages} and @code{services}, can be omitted, in
5976 which case they get a default value.
5977
5978 Below we discuss the effect of some of the most important fields
5979 (@pxref{operating-system Reference}, for details about all the available
5980 fields), and how to @dfn{instantiate} the operating system using
5981 @command{guix system}.
5982
5983 @unnumberedsubsubsec Globally-Visible Packages
5984
5985 @vindex %base-packages
5986 The @code{packages} field lists packages that will be globally visible
5987 on the system, for all user accounts---i.e., in every user's @code{PATH}
5988 environment variable---in addition to the per-user profiles
5989 (@pxref{Invoking guix package}). The @var{%base-packages} variable
5990 provides all the tools one would expect for basic user and administrator
5991 tasks---including the GNU Core Utilities, the GNU Networking Utilities,
5992 the GNU Zile lightweight text editor, @command{find}, @command{grep},
5993 etc. The example above adds tcpdump to those, taken from the @code{(gnu
5994 packages admin)} module (@pxref{Package Modules}).
5995
5996 @findex specification->package
5997 Referring to packages by variable name, like @var{tcpdump} above, has
5998 the advantage of being unambiguous; it also allows typos and such to be
5999 diagnosed right away as ``unbound variables''. The downside is that one
6000 needs to know which module defines which package, and to augment the
6001 @code{use-package-modules} line accordingly. To avoid that, one can use
6002 the @code{specification->package} procedure of the @code{(gnu packages)}
6003 module, which returns the best package for a given name or name and
6004 version:
6005
6006 @lisp
6007 (use-modules (gnu packages))
6008
6009 (operating-system
6010 ;; ...
6011 (packages (append (map specification->package
6012 '("tcpdump" "htop" "gnupg-2.0"))
6013 %base-packages)))
6014 @end lisp
6015
6016 @unnumberedsubsubsec System Services
6017
6018 @vindex %base-services
6019 The @code{services} field lists @dfn{system services} to be made
6020 available when the system starts (@pxref{Services}).
6021 The @code{operating-system} declaration above specifies that, in
6022 addition to the basic services, we want the @command{lshd} secure shell
6023 daemon listening on port 2222 (@pxref{Networking Services,
6024 @code{lsh-service}}). Under the hood,
6025 @code{lsh-service} arranges so that @code{lshd} is started with the
6026 right command-line options, possibly with supporting configuration files
6027 generated as needed (@pxref{Defining Services}).
6028
6029 @cindex customization, of services
6030 @findex modify-services
6031 Occasionally, instead of using the base services as is, you will want to
6032 customize them. For instance, to change the configuration of
6033 @code{guix-daemon} and Mingetty (the console log-in), you may write the
6034 following instead of @var{%base-services}:
6035
6036 @lisp
6037 (modify-services %base-services
6038 (guix-service-type config =>
6039 (guix-configuration
6040 (inherit config)
6041 (use-substitutes? #f)
6042 (extra-options '("--gc-keep-outputs"))))
6043 (mingetty-service-type config =>
6044 (mingetty-configuration
6045 (inherit config)
6046 (motd (plain-file "motd" "Hi there!")))))
6047 @end lisp
6048
6049 @noindent
6050 The effect here is to change the options passed to @command{guix-daemon}
6051 when it is started, as well as the ``message of the day'' that appears
6052 when logging in at the console. @xref{Service Reference,
6053 @code{modify-services}}, for more on that.
6054
6055 The configuration for a typical ``desktop'' usage, with the X11 display
6056 server, a desktop environment, network management, power management, and
6057 more, would look like this:
6058
6059 @lisp
6060 @include os-config-desktop.texi
6061 @end lisp
6062
6063 @xref{Desktop Services}, for the exact list of services provided by
6064 @var{%desktop-services}. @xref{X.509 Certificates}, for background
6065 information about the @code{nss-certs} package that is used here.
6066
6067 Again, @var{%desktop-services} is just a list of service objects. If
6068 you want to remove services from there, you can do so using the
6069 procedures for list filtering (@pxref{SRFI-1 Filtering and
6070 Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
6071 following expression returns a list that contains all the services in
6072 @var{%desktop-services} minus the Avahi service:
6073
6074 @example
6075 (remove (lambda (service)
6076 (eq? (service-kind service) avahi-service-type))
6077 %desktop-services)
6078 @end example
6079
6080 @unnumberedsubsubsec Instantiating the System
6081
6082 Assuming the @code{operating-system} declaration
6083 is stored in the @file{my-system-config.scm}
6084 file, the @command{guix system reconfigure my-system-config.scm} command
6085 instantiates that configuration, and makes it the default GRUB boot
6086 entry (@pxref{Invoking guix system}).
6087
6088 The normal way to change the system's configuration is by updating this
6089 file and re-running @command{guix system reconfigure}. One should never
6090 have to touch files in @command{/etc} or to run commands that modify the
6091 system state such as @command{useradd} or @command{grub-install}. In
6092 fact, you must avoid that since that would not only void your warranty
6093 but also prevent you from rolling back to previous versions of your
6094 system, should you ever need to.
6095
6096 @cindex roll-back, of the operating system
6097 Speaking of roll-back, each time you run @command{guix system
6098 reconfigure}, a new @dfn{generation} of the system is created---without
6099 modifying or deleting previous generations. Old system generations get
6100 an entry in the GRUB boot menu, allowing you to boot them in case
6101 something went wrong with the latest generation. Reassuring, no? The
6102 @command{guix system list-generations} command lists the system
6103 generations available on disk.
6104
6105 @unnumberedsubsubsec The Programming Interface
6106
6107 At the Scheme level, the bulk of an @code{operating-system} declaration
6108 is instantiated with the following monadic procedure (@pxref{The Store
6109 Monad}):
6110
6111 @deffn {Monadic Procedure} operating-system-derivation os
6112 Return a derivation that builds @var{os}, an @code{operating-system}
6113 object (@pxref{Derivations}).
6114
6115 The output of the derivation is a single directory that refers to all
6116 the packages, configuration files, and other supporting files needed to
6117 instantiate @var{os}.
6118 @end deffn
6119
6120 This procedure is provided by the @code{(gnu system)} module. Along
6121 with @code{(gnu services)} (@pxref{Services}), this module contains the
6122 guts of GuixSD. Make sure to visit it!
6123
6124
6125 @node operating-system Reference
6126 @subsection @code{operating-system} Reference
6127
6128 This section summarizes all the options available in
6129 @code{operating-system} declarations (@pxref{Using the Configuration
6130 System}).
6131
6132 @deftp {Data Type} operating-system
6133 This is the data type representing an operating system configuration.
6134 By that, we mean all the global system configuration, not per-user
6135 configuration (@pxref{Using the Configuration System}).
6136
6137 @table @asis
6138 @item @code{kernel} (default: @var{linux-libre})
6139 The package object of the operating system kernel to use@footnote{Currently
6140 only the Linux-libre kernel is supported. In the future, it will be
6141 possible to use the GNU@tie{}Hurd.}.
6142
6143 @item @code{kernel-arguments} (default: @code{'()})
6144 List of strings or gexps representing additional arguments to pass on
6145 the kernel's command-line---e.g., @code{("console=ttyS0")}.
6146
6147 @item @code{bootloader}
6148 The system bootloader configuration object. @xref{GRUB Configuration}.
6149
6150 @item @code{initrd} (default: @code{base-initrd})
6151 A two-argument monadic procedure that returns an initial RAM disk for
6152 the Linux kernel. @xref{Initial RAM Disk}.
6153
6154 @item @code{firmware} (default: @var{%base-firmware})
6155 @cindex firmware
6156 List of firmware packages loadable by the operating system kernel.
6157
6158 The default includes firmware needed for Atheros-based WiFi devices
6159 (Linux-libre module @code{ath9k}.)
6160
6161 @item @code{host-name}
6162 The host name.
6163
6164 @item @code{hosts-file}
6165 @cindex hosts file
6166 A file-like object (@pxref{G-Expressions, file-like objects}) for use as
6167 @file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
6168 Reference Manual}). The default is a file with entries for
6169 @code{localhost} and @var{host-name}.
6170
6171 @item @code{mapped-devices} (default: @code{'()})
6172 A list of mapped devices. @xref{Mapped Devices}.
6173
6174 @item @code{file-systems}
6175 A list of file systems. @xref{File Systems}.
6176
6177 @item @code{swap-devices} (default: @code{'()})
6178 @cindex swap devices
6179 A list of strings identifying devices to be used for ``swap space''
6180 (@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
6181 For example, @code{'("/dev/sda3")}.
6182
6183 @item @code{users} (default: @code{%base-user-accounts})
6184 @itemx @code{groups} (default: @var{%base-groups})
6185 List of user accounts and groups. @xref{User Accounts}.
6186
6187 @item @code{skeletons} (default: @code{(default-skeletons)})
6188 A monadic list of pairs of target file name and files. These are the
6189 files that will be used as skeletons as new accounts are created.
6190
6191 For instance, a valid value may look like this:
6192
6193 @example
6194 (mlet %store-monad ((bashrc (text-file "bashrc" "\
6195 export PATH=$HOME/.guix-profile/bin")))
6196 (return `((".bashrc" ,bashrc))))
6197 @end example
6198
6199 @item @code{issue} (default: @var{%default-issue})
6200 A string denoting the contents of the @file{/etc/issue} file, which is
6201 what displayed when users log in on a text console.
6202
6203 @item @code{packages} (default: @var{%base-packages})
6204 The set of packages installed in the global profile, which is accessible
6205 at @file{/run/current-system/profile}.
6206
6207 The default set includes core utilities, but it is good practice to
6208 install non-core utilities in user profiles (@pxref{Invoking guix
6209 package}).
6210
6211 @item @code{timezone}
6212 A timezone identifying string---e.g., @code{"Europe/Paris"}.
6213
6214 You can run the @command{tzselect} command to find out which timezone
6215 string corresponds to your region. Choosing an invalid timezone name
6216 causes @command{guix system} to fail.
6217
6218 @item @code{locale} (default: @code{"en_US.utf8"})
6219 The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
6220 Library Reference Manual}). @xref{Locales}, for more information.
6221
6222 @item @code{locale-definitions} (default: @var{%default-locale-definitions})
6223 The list of locale definitions to be compiled and that may be used at
6224 run time. @xref{Locales}.
6225
6226 @item @code{locale-libcs} (default: @code{(list @var{glibc})})
6227 The list of GNU@tie{}libc packages whose locale data and tools are used
6228 to build the locale definitions. @xref{Locales}, for compatibility
6229 considerations that justify this option.
6230
6231 @item @code{name-service-switch} (default: @var{%default-nss})
6232 Configuration of libc's name service switch (NSS)---a
6233 @code{<name-service-switch>} object. @xref{Name Service Switch}, for
6234 details.
6235
6236 @item @code{services} (default: @var{%base-services})
6237 A list of service objects denoting system services. @xref{Services}.
6238
6239 @item @code{pam-services} (default: @code{(base-pam-services)})
6240 @cindex PAM
6241 @cindex pluggable authentication modules
6242 Linux @dfn{pluggable authentication module} (PAM) services.
6243 @c FIXME: Add xref to PAM services section.
6244
6245 @item @code{setuid-programs} (default: @var{%setuid-programs})
6246 List of string-valued G-expressions denoting setuid programs.
6247 @xref{Setuid Programs}.
6248
6249 @item @code{sudoers-file} (default: @var{%sudoers-specification})
6250 @cindex sudoers file
6251 The contents of the @file{/etc/sudoers} file as a file-like object
6252 (@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
6253
6254 This file specifies which users can use the @command{sudo} command, what
6255 they are allowed to do, and what privileges they may gain. The default
6256 is that only @code{root} and members of the @code{wheel} group may use
6257 @code{sudo}.
6258
6259 @end table
6260 @end deftp
6261
6262 @node File Systems
6263 @subsection File Systems
6264
6265 The list of file systems to be mounted is specified in the
6266 @code{file-systems} field of the operating system's declaration
6267 (@pxref{Using the Configuration System}). Each file system is declared
6268 using the @code{file-system} form, like this:
6269
6270 @example
6271 (file-system
6272 (mount-point "/home")
6273 (device "/dev/sda3")
6274 (type "ext4"))
6275 @end example
6276
6277 As usual, some of the fields are mandatory---those shown in the example
6278 above---while others can be omitted. These are described below.
6279
6280 @deftp {Data Type} file-system
6281 Objects of this type represent file systems to be mounted. They
6282 contain the following members:
6283
6284 @table @asis
6285 @item @code{type}
6286 This is a string specifying the type of the file system---e.g.,
6287 @code{"ext4"}.
6288
6289 @item @code{mount-point}
6290 This designates the place where the file system is to be mounted.
6291
6292 @item @code{device}
6293 This names the ``source'' of the file system. By default it is the name
6294 of a node under @file{/dev}, but its meaning depends on the @code{title}
6295 field described below.
6296
6297 @item @code{title} (default: @code{'device})
6298 This is a symbol that specifies how the @code{device} field is to be
6299 interpreted.
6300
6301 When it is the symbol @code{device}, then the @code{device} field is
6302 interpreted as a file name; when it is @code{label}, then @code{device}
6303 is interpreted as a partition label name; when it is @code{uuid},
6304 @code{device} is interpreted as a partition unique identifier (UUID).
6305
6306 UUIDs may be converted from their string representation (as shown by the
6307 @command{tune2fs -l} command) using the @code{uuid} form@footnote{The
6308 @code{uuid} form expects 16-byte UUIDs as defined in
6309 @uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
6310 form of UUID used by the ext2 family of file systems and others, but it
6311 is different from ``UUIDs'' found in FAT file systems, for instance.},
6312 like this:
6313
6314 @example
6315 (file-system
6316 (mount-point "/home")
6317 (type "ext4")
6318 (title 'uuid)
6319 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
6320 @end example
6321
6322 The @code{label} and @code{uuid} options offer a way to refer to disk
6323 partitions without having to hard-code their actual device
6324 name@footnote{Note that, while it is tempting to use
6325 @file{/dev/disk/by-uuid} and similar device names to achieve the same
6326 result, this is not recommended: These special device nodes are created
6327 by the udev daemon and may be unavailable at the time the device is
6328 mounted.}.
6329
6330 However, when a file system's source is a mapped device (@pxref{Mapped
6331 Devices}), its @code{device} field @emph{must} refer to the mapped
6332 device name---e.g., @file{/dev/mapper/root-partition}---and consequently
6333 @code{title} must be set to @code{'device}. This is required so that
6334 the system knows that mounting the file system depends on having the
6335 corresponding device mapping established.
6336
6337 @item @code{flags} (default: @code{'()})
6338 This is a list of symbols denoting mount flags. Recognized flags
6339 include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
6340 access to special files), @code{no-suid} (ignore setuid and setgid
6341 bits), and @code{no-exec} (disallow program execution.)
6342
6343 @item @code{options} (default: @code{#f})
6344 This is either @code{#f}, or a string denoting mount options.
6345
6346 @item @code{mount?} (default: @code{#t})
6347 This value indicates whether to automatically mount the file system when
6348 the system is brought up. When set to @code{#f}, the file system gets
6349 an entry in @file{/etc/fstab} (read by the @command{mount} command) but
6350 is not automatically mounted.
6351
6352 @item @code{needed-for-boot?} (default: @code{#f})
6353 This Boolean value indicates whether the file system is needed when
6354 booting. If that is true, then the file system is mounted when the
6355 initial RAM disk (initrd) is loaded. This is always the case, for
6356 instance, for the root file system.
6357
6358 @item @code{check?} (default: @code{#t})
6359 This Boolean indicates whether the file system needs to be checked for
6360 errors before being mounted.
6361
6362 @item @code{create-mount-point?} (default: @code{#f})
6363 When true, the mount point is created if it does not exist yet.
6364
6365 @item @code{dependencies} (default: @code{'()})
6366 This is a list of @code{<file-system>} objects representing file systems
6367 that must be mounted before (and unmounted after) this one.
6368
6369 As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
6370 a dependency of @file{/sys/fs/cgroup/cpu} and
6371 @file{/sys/fs/cgroup/memory}.
6372
6373 @end table
6374 @end deftp
6375
6376 The @code{(gnu system file-systems)} exports the following useful
6377 variables.
6378
6379 @defvr {Scheme Variable} %base-file-systems
6380 These are essential file systems that are required on normal systems,
6381 such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
6382 below.) Operating system declarations should always contain at least
6383 these.
6384 @end defvr
6385
6386 @defvr {Scheme Variable} %pseudo-terminal-file-system
6387 This is the file system to be mounted as @file{/dev/pts}. It supports
6388 @dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
6389 functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
6390 Manual}). Pseudo-terminals are used by terminal emulators such as
6391 @command{xterm}.
6392 @end defvr
6393
6394 @defvr {Scheme Variable} %shared-memory-file-system
6395 This file system is mounted as @file{/dev/shm} and is used to support
6396 memory sharing across processes (@pxref{Memory-mapped I/O,
6397 @code{shm_open},, libc, The GNU C Library Reference Manual}).
6398 @end defvr
6399
6400 @defvr {Scheme Variable} %immutable-store
6401 This file system performs a read-only ``bind mount'' of
6402 @file{/gnu/store}, making it read-only for all the users including
6403 @code{root}. This prevents against accidental modification by software
6404 running as @code{root} or by system administrators.
6405
6406 The daemon itself is still able to write to the store: it remounts it
6407 read-write in its own ``name space.''
6408 @end defvr
6409
6410 @defvr {Scheme Variable} %binary-format-file-system
6411 The @code{binfmt_misc} file system, which allows handling of arbitrary
6412 executable file types to be delegated to user space. This requires the
6413 @code{binfmt.ko} kernel module to be loaded.
6414 @end defvr
6415
6416 @defvr {Scheme Variable} %fuse-control-file-system
6417 The @code{fusectl} file system, which allows unprivileged users to mount
6418 and unmount user-space FUSE file systems. This requires the
6419 @code{fuse.ko} kernel module to be loaded.
6420 @end defvr
6421
6422 @node Mapped Devices
6423 @subsection Mapped Devices
6424
6425 @cindex device mapping
6426 @cindex mapped devices
6427 The Linux kernel has a notion of @dfn{device mapping}: a block device,
6428 such as a hard disk partition, can be @dfn{mapped} into another device,
6429 with additional processing over the data that flows through
6430 it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
6431 concept of a ``mapped device'' and that of a file system: both boil down
6432 to @emph{translating} input/output operations made on a file to
6433 operations on its backing store. Thus, the Hurd implements mapped
6434 devices, like file systems, using the generic @dfn{translator} mechanism
6435 (@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
6436 typical example is encryption device mapping: all writes to the mapped
6437 device are encrypted, and all reads are deciphered, transparently.
6438
6439 Mapped devices are declared using the @code{mapped-device} form:
6440
6441 @example
6442 (mapped-device
6443 (source "/dev/sda3")
6444 (target "home")
6445 (type luks-device-mapping))
6446 @end example
6447
6448 @noindent
6449 @cindex disk encryption
6450 @cindex LUKS
6451 This example specifies a mapping from @file{/dev/sda3} to
6452 @file{/dev/mapper/home} using LUKS---the
6453 @url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
6454 standard mechanism for disk encryption. The @file{/dev/mapper/home}
6455 device can then be used as the @code{device} of a @code{file-system}
6456 declaration (@pxref{File Systems}). The @code{mapped-device} form is
6457 detailed below.
6458
6459 @deftp {Data Type} mapped-device
6460 Objects of this type represent device mappings that will be made when
6461 the system boots up.
6462
6463 @table @code
6464 @item source
6465 This string specifies the name of the block device to be mapped, such as
6466 @code{"/dev/sda3"}.
6467
6468 @item target
6469 This string specifies the name of the mapping to be established. For
6470 example, specifying @code{"my-partition"} will lead to the creation of
6471 the @code{"/dev/mapper/my-partition"} device.
6472
6473 @item type
6474 This must be a @code{mapped-device-kind} object, which specifies how
6475 @var{source} is mapped to @var{target}.
6476 @end table
6477 @end deftp
6478
6479 @defvr {Scheme Variable} luks-device-mapping
6480 This defines LUKS block device encryption using the @command{cryptsetup}
6481 command, from the same-named package. This relies on the
6482 @code{dm-crypt} Linux kernel module.
6483 @end defvr
6484
6485 @node User Accounts
6486 @subsection User Accounts
6487
6488 User accounts and groups are entirely managed through the
6489 @code{operating-system} declaration. They are specified with the
6490 @code{user-account} and @code{user-group} forms:
6491
6492 @example
6493 (user-account
6494 (name "alice")
6495 (group "users")
6496 (supplementary-groups '("wheel" ;allow use of sudo, etc.
6497 "audio" ;sound card
6498 "video" ;video devices such as webcams
6499 "cdrom")) ;the good ol' CD-ROM
6500 (comment "Bob's sister")
6501 (home-directory "/home/alice"))
6502 @end example
6503
6504 When booting or upon completion of @command{guix system reconfigure},
6505 the system ensures that only the user accounts and groups specified in
6506 the @code{operating-system} declaration exist, and with the specified
6507 properties. Thus, account or group creations or modifications made by
6508 directly invoking commands such as @command{useradd} are lost upon
6509 reconfiguration or reboot. This ensures that the system remains exactly
6510 as declared.
6511
6512 @deftp {Data Type} user-account
6513 Objects of this type represent user accounts. The following members may
6514 be specified:
6515
6516 @table @asis
6517 @item @code{name}
6518 The name of the user account.
6519
6520 @item @code{group}
6521 This is the name (a string) or identifier (a number) of the user group
6522 this account belongs to.
6523
6524 @item @code{supplementary-groups} (default: @code{'()})
6525 Optionally, this can be defined as a list of group names that this
6526 account belongs to.
6527
6528 @item @code{uid} (default: @code{#f})
6529 This is the user ID for this account (a number), or @code{#f}. In the
6530 latter case, a number is automatically chosen by the system when the
6531 account is created.
6532
6533 @item @code{comment} (default: @code{""})
6534 A comment about the account, such as the account's owner full name.
6535
6536 @item @code{home-directory}
6537 This is the name of the home directory for the account.
6538
6539 @item @code{shell} (default: Bash)
6540 This is a G-expression denoting the file name of a program to be used as
6541 the shell (@pxref{G-Expressions}).
6542
6543 @item @code{system?} (default: @code{#f})
6544 This Boolean value indicates whether the account is a ``system''
6545 account. System accounts are sometimes treated specially; for instance,
6546 graphical login managers do not list them.
6547
6548 @anchor{user-account-password}
6549 @item @code{password} (default: @code{#f})
6550 You would normally leave this field to @code{#f}, initialize user
6551 passwords as @code{root} with the @command{passwd} command, and then let
6552 users change it with @command{passwd}. Passwords set with
6553 @command{passwd} are of course preserved across reboot and
6554 reconfiguration.
6555
6556 If you @emph{do} want to have a preset password for an account, then
6557 this field must contain the encrypted password, as a string.
6558 @xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
6559 on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
6560 Manual}, for information on Guile's @code{crypt} procedure.
6561
6562 @end table
6563 @end deftp
6564
6565 User group declarations are even simpler:
6566
6567 @example
6568 (user-group (name "students"))
6569 @end example
6570
6571 @deftp {Data Type} user-group
6572 This type is for, well, user groups. There are just a few fields:
6573
6574 @table @asis
6575 @item @code{name}
6576 The group's name.
6577
6578 @item @code{id} (default: @code{#f})
6579 The group identifier (a number). If @code{#f}, a new number is
6580 automatically allocated when the group is created.
6581
6582 @item @code{system?} (default: @code{#f})
6583 This Boolean value indicates whether the group is a ``system'' group.
6584 System groups have low numerical IDs.
6585
6586 @item @code{password} (default: @code{#f})
6587 What, user groups can have a password? Well, apparently yes. Unless
6588 @code{#f}, this field specifies the group's password.
6589
6590 @end table
6591 @end deftp
6592
6593 For convenience, a variable lists all the basic user groups one may
6594 expect:
6595
6596 @defvr {Scheme Variable} %base-groups
6597 This is the list of basic user groups that users and/or packages expect
6598 to be present on the system. This includes groups such as ``root'',
6599 ``wheel'', and ``users'', as well as groups used to control access to
6600 specific devices such as ``audio'', ``disk'', and ``cdrom''.
6601 @end defvr
6602
6603 @defvr {Scheme Variable} %base-user-accounts
6604 This is the list of basic system accounts that programs may expect to
6605 find on a GNU/Linux system, such as the ``nobody'' account.
6606
6607 Note that the ``root'' account is not included here. It is a
6608 special-case and is automatically added whether or not it is specified.
6609 @end defvr
6610
6611 @node Locales
6612 @subsection Locales
6613
6614 @cindex locale
6615 A @dfn{locale} defines cultural conventions for a particular language
6616 and region of the world (@pxref{Locales,,, libc, The GNU C Library
6617 Reference Manual}). Each locale has a name that typically has the form
6618 @code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
6619 @code{fr_LU.utf8} designates the locale for the French language, with
6620 cultural conventions from Luxembourg, and using the UTF-8 encoding.
6621
6622 @cindex locale definition
6623 Usually, you will want to specify the default locale for the machine
6624 using the @code{locale} field of the @code{operating-system} declaration
6625 (@pxref{operating-system Reference, @code{locale}}).
6626
6627 The selected locale is automatically added to the @dfn{locale
6628 definitions} known to the system if needed, with its codeset inferred
6629 from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
6630 @code{UTF-8} codeset. Additional locale definitions can be specified in
6631 the @code{locale-definitions} slot of @code{operating-system}---this is
6632 useful, for instance, if the codeset could not be inferred from the
6633 locale name. The default set of locale definitions includes some widely
6634 used locales, but not all the available locales, in order to save space.
6635
6636 For instance, to add the North Frisian locale for Germany, the value of
6637 that field may be:
6638
6639 @example
6640 (cons (locale-definition
6641 (name "fy_DE.utf8") (source "fy_DE"))
6642 %default-locale-definitions)
6643 @end example
6644
6645 Likewise, to save space, one might want @code{locale-definitions} to
6646 list only the locales that are actually used, as in:
6647
6648 @example
6649 (list (locale-definition
6650 (name "ja_JP.eucjp") (source "ja_JP")
6651 (charset "EUC-JP")))
6652 @end example
6653
6654 @vindex LOCPATH
6655 The compiled locale definitions are available at
6656 @file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
6657 version, which is the default location where the GNU@tie{}libc provided
6658 by Guix looks for locale data. This can be overridden using the
6659 @code{LOCPATH} environment variable (@pxref{locales-and-locpath,
6660 @code{LOCPATH} and locale packages}).
6661
6662 The @code{locale-definition} form is provided by the @code{(gnu system
6663 locale)} module. Details are given below.
6664
6665 @deftp {Data Type} locale-definition
6666 This is the data type of a locale definition.
6667
6668 @table @asis
6669
6670 @item @code{name}
6671 The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
6672 Reference Manual}, for more information on locale names.
6673
6674 @item @code{source}
6675 The name of the source for that locale. This is typically the
6676 @code{@var{language}_@var{territory}} part of the locale name.
6677
6678 @item @code{charset} (default: @code{"UTF-8"})
6679 The ``character set'' or ``code set'' for that locale,
6680 @uref{http://www.iana.org/assignments/character-sets, as defined by
6681 IANA}.
6682
6683 @end table
6684 @end deftp
6685
6686 @defvr {Scheme Variable} %default-locale-definitions
6687 An arbitrary list of commonly used UTF-8 locales, used as the default
6688 value of the @code{locale-definitions} field of @code{operating-system}
6689 declarations.
6690
6691 @cindex locale name
6692 @cindex normalized codeset in locale names
6693 These locale definitions use the @dfn{normalized codeset} for the part
6694 that follows the dot in the name (@pxref{Using gettextized software,
6695 normalized codeset,, libc, The GNU C Library Reference Manual}). So for
6696 instance it has @code{uk_UA.utf8} but @emph{not}, say,
6697 @code{uk_UA.UTF-8}.
6698 @end defvr
6699
6700 @subsubsection Locale Data Compatibility Considerations
6701
6702 @cindex incompatibility, of locale data
6703 @code{operating-system} declarations provide a @code{locale-libcs} field
6704 to specify the GNU@tie{}libc packages that are used to compile locale
6705 declarations (@pxref{operating-system Reference}). ``Why would I
6706 care?'', you may ask. Well, it turns out that the binary format of
6707 locale data is occasionally incompatible from one libc version to
6708 another.
6709
6710 @c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
6711 @c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
6712 For instance, a program linked against libc version 2.21 is unable to
6713 read locale data produced with libc 2.22; worse, that program
6714 @emph{aborts} instead of simply ignoring the incompatible locale
6715 data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
6716 the incompatible locale data, which is already an improvement.}.
6717 Similarly, a program linked against libc 2.22 can read most, but not
6718 all, the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
6719 data is incompatible); thus calls to @code{setlocale} may fail, but
6720 programs will not abort.
6721
6722 The ``problem'' in GuixSD is that users have a lot of freedom: They can
6723 choose whether and when to upgrade software in their profiles, and might
6724 be using a libc version different from the one the system administrator
6725 used to build the system-wide locale data.
6726
6727 Fortunately, unprivileged users can also install their own locale data
6728 and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
6729 @code{GUIX_LOCPATH} and locale packages}).
6730
6731 Still, it is best if the system-wide locale data at
6732 @file{/run/current-system/locale} is built for all the libc versions
6733 actually in use on the system, so that all the programs can access
6734 it---this is especially crucial on a multi-user system. To do that, the
6735 administrator can specify several libc packages in the
6736 @code{locale-libcs} field of @code{operating-system}:
6737
6738 @example
6739 (use-package-modules base)
6740
6741 (operating-system
6742 ;; @dots{}
6743 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
6744 @end example
6745
6746 This example would lead to a system containing locale definitions for
6747 both libc 2.21 and the current version of libc in
6748 @file{/run/current-system/locale}.
6749
6750
6751 @node Services
6752 @subsection Services
6753
6754 @cindex system services
6755 An important part of preparing an @code{operating-system} declaration is
6756 listing @dfn{system services} and their configuration (@pxref{Using the
6757 Configuration System}). System services are typically daemons launched
6758 when the system boots, or other actions needed at that time---e.g.,
6759 configuring network access.
6760
6761 Services are managed by the GNU@tie{}Shepherd (@pxref{Introduction,,,
6762 shepherd, The GNU Shepherd Manual}). On a running system, the
6763 @command{herd} command allows you to list the available services, show
6764 their status, start and stop them, or do other specific operations
6765 (@pxref{Jump Start,,, shepherd, The GNU Shepherd Manual}). For example:
6766
6767 @example
6768 # herd status
6769 @end example
6770
6771 The above command, run as @code{root}, lists the currently defined
6772 services. The @command{herd doc} command shows a synopsis of the given
6773 service:
6774
6775 @example
6776 # herd doc nscd
6777 Run libc's name service cache daemon (nscd).
6778 @end example
6779
6780 The @command{start}, @command{stop}, and @command{restart} sub-commands
6781 have the effect you would expect. For instance, the commands below stop
6782 the nscd service and restart the Xorg display server:
6783
6784 @example
6785 # herd stop nscd
6786 Service nscd has been stopped.
6787 # herd restart xorg-server
6788 Service xorg-server has been stopped.
6789 Service xorg-server has been started.
6790 @end example
6791
6792 The following sections document the available services, starting with
6793 the core services, that may be used in an @code{operating-system}
6794 declaration.
6795
6796 @menu
6797 * Base Services:: Essential system services.
6798 * Networking Services:: Network setup, SSH daemon, etc.
6799 * X Window:: Graphical display.
6800 * Desktop Services:: D-Bus and desktop services.
6801 * Database Services:: SQL databases.
6802 * Mail Services:: IMAP, POP3, SMTP, and all that.
6803 * Web Services:: Web servers.
6804 * Various Services:: Other services.
6805 @end menu
6806
6807 @node Base Services
6808 @subsubsection Base Services
6809
6810 The @code{(gnu services base)} module provides definitions for the basic
6811 services that one expects from the system. The services exported by
6812 this module are listed below.
6813
6814 @defvr {Scheme Variable} %base-services
6815 This variable contains a list of basic services (@pxref{Service Types
6816 and Services}, for more information on service objects) one would
6817 expect from the system: a login service (mingetty) on each tty, syslogd,
6818 libc's name service cache daemon (nscd), the udev device manager, and
6819 more.
6820
6821 This is the default value of the @code{services} field of
6822 @code{operating-system} declarations. Usually, when customizing a
6823 system, you will want to append services to @var{%base-services}, like
6824 this:
6825
6826 @example
6827 (cons* (avahi-service) (lsh-service) %base-services)
6828 @end example
6829 @end defvr
6830
6831 @deffn {Scheme Procedure} host-name-service @var{name}
6832 Return a service that sets the host name to @var{name}.
6833 @end deffn
6834
6835 @deffn {Scheme Procedure} mingetty-service @var{config}
6836 Return a service to run mingetty according to @var{config}, a
6837 @code{<mingetty-configuration>} object, which specifies the tty to run, among
6838 other things.
6839 @end deffn
6840
6841 @deftp {Data Type} mingetty-configuration
6842 This is the data type representing the configuration of Mingetty, which
6843 implements console log-in.
6844
6845 @table @asis
6846
6847 @item @code{tty}
6848 The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
6849
6850 @item @code{motd}
6851 A file-like object containing the ``message of the day''.
6852
6853 @item @code{auto-login} (default: @code{#f})
6854 When true, this field must be a string denoting the user name under
6855 which the system automatically logs in. When it is @code{#f}, a
6856 user name and password must be entered to log in.
6857
6858 @item @code{login-program} (default: @code{#f})
6859 This must be either @code{#f}, in which case the default log-in program
6860 is used (@command{login} from the Shadow tool suite), or a gexp denoting
6861 the name of the log-in program.
6862
6863 @item @code{login-pause?} (default: @code{#f})
6864 When set to @code{#t} in conjunction with @var{auto-login}, the user
6865 will have to press a key before the log-in shell is launched.
6866
6867 @item @code{mingetty} (default: @var{mingetty})
6868 The Mingetty package to use.
6869
6870 @end table
6871 @end deftp
6872
6873 @cindex name service cache daemon
6874 @cindex nscd
6875 @deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
6876 [#:name-services '()]
6877 Return a service that runs libc's name service cache daemon (nscd) with the
6878 given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
6879 Service Switch}, for an example.
6880 @end deffn
6881
6882 @defvr {Scheme Variable} %nscd-default-configuration
6883 This is the default @code{<nscd-configuration>} value (see below) used
6884 by @code{nscd-service}. This uses the caches defined by
6885 @var{%nscd-default-caches}; see below.
6886 @end defvr
6887
6888 @deftp {Data Type} nscd-configuration
6889 This is the type representing the name service cache daemon (nscd)
6890 configuration.
6891
6892 @table @asis
6893
6894 @item @code{name-services} (default: @code{'()})
6895 List of packages denoting @dfn{name services} that must be visible to
6896 the nscd---e.g., @code{(list @var{nss-mdns})}.
6897
6898 @item @code{glibc} (default: @var{glibc})
6899 Package object denoting the GNU C Library providing the @command{nscd}
6900 command.
6901
6902 @item @code{log-file} (default: @code{"/var/log/nscd.log"})
6903 Name of nscd's log file. This is where debugging output goes when
6904 @code{debug-level} is strictly positive.
6905
6906 @item @code{debug-level} (default: @code{0})
6907 Integer denoting the debugging levels. Higher numbers mean more
6908 debugging output is logged.
6909
6910 @item @code{caches} (default: @var{%nscd-default-caches})
6911 List of @code{<nscd-cache>} objects denoting things to be cached; see
6912 below.
6913
6914 @end table
6915 @end deftp
6916
6917 @deftp {Data Type} nscd-cache
6918 Data type representing a cache database of nscd and its parameters.
6919
6920 @table @asis
6921
6922 @item @code{database}
6923 This is a symbol representing the name of the database to be cached.
6924 Valid values are @code{passwd}, @code{group}, @code{hosts}, and
6925 @code{services}, which designate the corresponding NSS database
6926 (@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
6927
6928 @item @code{positive-time-to-live}
6929 @itemx @code{negative-time-to-live} (default: @code{20})
6930 A number representing the number of seconds during which a positive or
6931 negative lookup result remains in cache.
6932
6933 @item @code{check-files?} (default: @code{#t})
6934 Whether to check for updates of the files corresponding to
6935 @var{database}.
6936
6937 For instance, when @var{database} is @code{hosts}, setting this flag
6938 instructs nscd to check for updates in @file{/etc/hosts} and to take
6939 them into account.
6940
6941 @item @code{persistent?} (default: @code{#t})
6942 Whether the cache should be stored persistently on disk.
6943
6944 @item @code{shared?} (default: @code{#t})
6945 Whether the cache should be shared among users.
6946
6947 @item @code{max-database-size} (default: 32@tie{}MiB)
6948 Maximum size in bytes of the database cache.
6949
6950 @c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
6951 @c settings, so leave them out.
6952
6953 @end table
6954 @end deftp
6955
6956 @defvr {Scheme Variable} %nscd-default-caches
6957 List of @code{<nscd-cache>} objects used by default by
6958 @code{nscd-configuration} (see above.)
6959
6960 It enables persistent and aggressive caching of service and host name
6961 lookups. The latter provides better host name lookup performance,
6962 resilience in the face of unreliable name servers, and also better
6963 privacy---often the result of host name lookups is in local cache, so
6964 external name servers do not even need to be queried.
6965 @end defvr
6966
6967
6968 @deffn {Scheme Procedure} syslog-service [#:config-file #f]
6969 Return a service that runs @code{syslogd}. If configuration file name
6970 @var{config-file} is not specified, use some reasonable default
6971 settings.
6972 @end deffn
6973
6974 @anchor{guix-configuration-type}
6975 @deftp {Data Type} guix-configuration
6976 This data type represents the configuration of the Guix build daemon.
6977 @xref{Invoking guix-daemon}, for more information.
6978
6979 @table @asis
6980 @item @code{guix} (default: @var{guix})
6981 The Guix package to use.
6982
6983 @item @code{build-group} (default: @code{"guixbuild"})
6984 Name of the group for build user accounts.
6985
6986 @item @code{build-accounts} (default: @code{10})
6987 Number of build user accounts to create.
6988
6989 @item @code{authorize-key?} (default: @code{#t})
6990 Whether to authorize the substitute key for @code{hydra.gnu.org}
6991 (@pxref{Substitutes}).
6992
6993 @item @code{use-substitutes?} (default: @code{#t})
6994 Whether to use substitutes.
6995
6996 @item @code{substitute-urls} (default: @var{%default-substitute-urls})
6997 The list of URLs where to look for substitutes by default.
6998
6999 @item @code{extra-options} (default: @code{'()})
7000 List of extra command-line options for @command{guix-daemon}.
7001
7002 @item @code{lsof} (default: @var{lsof})
7003 @itemx @code{lsh} (default: @var{lsh})
7004 The lsof and lsh packages to use.
7005
7006 @end table
7007 @end deftp
7008
7009 @deffn {Scheme Procedure} guix-service @var{config}
7010 Return a service that runs the Guix build daemon according to
7011 @var{config}.
7012 @end deffn
7013
7014 @deffn {Scheme Procedure} udev-service [#:udev udev]
7015 Run @var{udev}, which populates the @file{/dev} directory dynamically.
7016 @end deffn
7017
7018 @deffn {Scheme Procedure} console-keymap-service @var{file}
7019 @cindex keyboard layout
7020 Return a service to load console keymap from @var{file} using
7021 @command{loadkeys} command.
7022 @end deffn
7023
7024 @deffn {Scheme Procedure} gpm-service-type [#:gpm @var{gpm}] @
7025 [#:options]
7026 Run @var{gpm}, the general-purpose mouse daemon, with the given
7027 command-line @var{options}. GPM allows users to use the mouse in the console,
7028 notably to select, copy, and paste text. The default value of @var{options}
7029 uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
7030
7031 This service is not part of @var{%base-services}.
7032 @end deffn
7033
7034 @anchor{guix-publish-service}
7035 @deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
7036 [#:port 80] [#:host "localhost"]
7037 Return a service that runs @command{guix publish} listening on @var{host}
7038 and @var{port} (@pxref{Invoking guix publish}).
7039
7040 This assumes that @file{/etc/guix} already contains a signing key pair as
7041 created by @command{guix archive --generate-key} (@pxref{Invoking guix
7042 archive}). If that is not the case, the service will fail to start.
7043 @end deffn
7044
7045
7046 @node Networking Services
7047 @subsubsection Networking Services
7048
7049 The @code{(gnu services networking)} module provides services to configure
7050 the network interface.
7051
7052 @cindex DHCP, networking service
7053 @deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
7054 Return a service that runs @var{dhcp}, a Dynamic Host Configuration
7055 Protocol (DHCP) client, on all the non-loopback network interfaces.
7056 @end deffn
7057
7058 @deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
7059 [#:gateway #f] [#:name-services @code{'()}]
7060 Return a service that starts @var{interface} with address @var{ip}. If
7061 @var{gateway} is true, it must be a string specifying the default network
7062 gateway.
7063 @end deffn
7064
7065 @cindex wicd
7066 @cindex network management
7067 @deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
7068 Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
7069 management daemon that aims to simplify wired and wireless networking.
7070
7071 This service adds the @var{wicd} package to the global profile, providing
7072 several commands to interact with the daemon and configure networking:
7073 @command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
7074 and @command{wicd-curses} user interfaces.
7075 @end deffn
7076
7077 @cindex NetworkManager
7078 @deffn {Scheme Procedure} network-manager-service @
7079 [#:network-manager @var{network-manager}]
7080 Return a service that runs NetworkManager, a network connection manager
7081 that attempting to keep active network connectivity when available.
7082 @end deffn
7083
7084 @deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
7085 [#:name-service @var{%ntp-servers}]
7086 Return a service that runs the daemon from @var{ntp}, the
7087 @uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
7088 keep the system clock synchronized with that of @var{servers}.
7089 @end deffn
7090
7091 @defvr {Scheme Variable} %ntp-servers
7092 List of host names used as the default NTP servers.
7093 @end defvr
7094
7095 @deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
7096 Return a service to run the @uref{https://torproject.org, Tor} anonymous
7097 networking daemon.
7098
7099 The daemon runs as the @code{tor} unprivileged user. It is passed
7100 @var{config-file}, a file-like object, with an additional @code{User tor} line
7101 and lines for hidden services added via @code{tor-hidden-service}. Run
7102 @command{man tor} for information about the configuration file.
7103 @end deffn
7104
7105 @cindex hidden service
7106 @deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
7107 Define a new Tor @dfn{hidden service} called @var{name} and implementing
7108 @var{mapping}. @var{mapping} is a list of port/host tuples, such as:
7109
7110 @example
7111 '((22 "127.0.0.1:22")
7112 (80 "127.0.0.1:8080"))
7113 @end example
7114
7115 In this example, port 22 of the hidden service is mapped to local port 22, and
7116 port 80 is mapped to local port 8080.
7117
7118 This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
7119 the @file{hostname} file contains the @code{.onion} host name for the hidden
7120 service.
7121
7122 See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
7123 project's documentation} for more information.
7124 @end deffn
7125
7126 @deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
7127 [#:interface "127.0.0.1"] [#:port 6667] @
7128 [#:extra-settings ""]
7129 Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
7130 acts as a gateway between IRC and chat networks.
7131
7132 The daemon will listen to the interface corresponding to the IP address
7133 specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
7134 local clients can connect, whereas @code{0.0.0.0} means that connections can
7135 come from any networking interface.
7136
7137 In addition, @var{extra-settings} specifies a string to append to the
7138 configuration file.
7139 @end deffn
7140
7141 Furthermore, @code{(gnu services ssh)} provides the following service.
7142
7143 @deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
7144 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
7145 [#:allow-empty-passwords? #f] [#:root-login? #f] @
7146 [#:syslog-output? #t] [#:x11-forwarding? #t] @
7147 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
7148 [#:public-key-authentication? #t] [#:initialize? #t]
7149 Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
7150 @var{host-key} must designate a file containing the host key, and readable
7151 only by root.
7152
7153 When @var{daemonic?} is true, @command{lshd} will detach from the
7154 controlling terminal and log its output to syslogd, unless one sets
7155 @var{syslog-output?} to false. Obviously, it also makes lsh-service
7156 depend on existence of syslogd service. When @var{pid-file?} is true,
7157 @command{lshd} writes its PID to the file called @var{pid-file}.
7158
7159 When @var{initialize?} is true, automatically create the seed and host key
7160 upon service activation if they do not exist yet. This may take long and
7161 require interaction.
7162
7163 When @var{initialize?} is false, it is up to the user to initialize the
7164 randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
7165 a key pair with the private key stored in file @var{host-key} (@pxref{lshd
7166 basics,,, lsh, LSH Manual}).
7167
7168 When @var{interfaces} is empty, lshd listens for connections on all the
7169 network interfaces; otherwise, @var{interfaces} must be a list of host names
7170 or addresses.
7171
7172 @var{allow-empty-passwords?} specifies whether to accept log-ins with empty
7173 passwords, and @var{root-login?} specifies whether to accept log-ins as
7174 root.
7175
7176 The other options should be self-descriptive.
7177 @end deffn
7178
7179 @defvr {Scheme Variable} %facebook-host-aliases
7180 This variable contains a string for use in @file{/etc/hosts}
7181 (@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
7182 line contains a entry that maps a known server name of the Facebook
7183 on-line service---e.g., @code{www.facebook.com}---to the local
7184 host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
7185
7186 This variable is typically used in the @code{hosts-file} field of an
7187 @code{operating-system} declaration (@pxref{operating-system Reference,
7188 @file{/etc/hosts}}):
7189
7190 @example
7191 (use-modules (gnu) (guix))
7192
7193 (operating-system
7194 (host-name "mymachine")
7195 ;; ...
7196 (hosts-file
7197 ;; Create a /etc/hosts file with aliases for "localhost"
7198 ;; and "mymachine", as well as for Facebook servers.
7199 (plain-file "hosts"
7200 (string-append (local-host-aliases host-name)
7201 %facebook-host-aliases))))
7202 @end example
7203
7204 This mechanism can prevent programs running locally, such as Web
7205 browsers, from accessing Facebook.
7206 @end defvr
7207
7208 The @code{(gnu services avahi)} provides the following definition.
7209
7210 @deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
7211 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
7212 [#:ipv6? #t] [#:wide-area? #f] @
7213 [#:domains-to-browse '()]
7214 Return a service that runs @command{avahi-daemon}, a system-wide
7215 mDNS/DNS-SD responder that allows for service discovery and
7216 "zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
7217 extends the name service cache daemon (nscd) so that it can resolve
7218 @code{.local} host names using
7219 @uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
7220 add the @var{avahi} package to the system profile so that commands such as
7221 @command{avahi-browse} are directly usable.
7222
7223 If @var{host-name} is different from @code{#f}, use that as the host name to
7224 publish for this machine; otherwise, use the machine's actual host name.
7225
7226 When @var{publish?} is true, publishing of host names and services is allowed;
7227 in particular, avahi-daemon will publish the machine's host name and IP
7228 address via mDNS on the local network.
7229
7230 When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
7231
7232 Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
7233 sockets.
7234 @end deffn
7235
7236
7237 @node X Window
7238 @subsubsection X Window
7239
7240 Support for the X Window graphical display system---specifically
7241 Xorg---is provided by the @code{(gnu services xorg)} module. Note that
7242 there is no @code{xorg-service} procedure. Instead, the X server is
7243 started by the @dfn{login manager}, currently SLiM.
7244
7245 @deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
7246 [#:auto-login? #f] [#:default-user ""] [#:startx] @
7247 [#:theme @var{%default-slim-theme}] @
7248 [#:theme-name @var{%default-slim-theme-name}]
7249 Return a service that spawns the SLiM graphical login manager, which in
7250 turn starts the X display server with @var{startx}, a command as returned by
7251 @code{xorg-start-command}.
7252
7253 @cindex X session
7254
7255 SLiM automatically looks for session types described by the @file{.desktop}
7256 files in @file{/run/current-system/profile/share/xsessions} and allows users
7257 to choose a session from the log-in screen using @kbd{F1}. Packages such as
7258 @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
7259 adding them to the system-wide set of packages automatically makes them
7260 available at the log-in screen.
7261
7262 In addition, @file{~/.xsession} files are honored. When available,
7263 @file{~/.xsession} must be an executable that starts a window manager
7264 and/or other X clients.
7265
7266 When @var{allow-empty-passwords?} is true, allow logins with an empty
7267 password. When @var{auto-login?} is true, log in automatically as
7268 @var{default-user}.
7269
7270 If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
7271 @var{theme} must be a gexp denoting the name of a directory containing the
7272 theme to use. In that case, @var{theme-name} specifies the name of the
7273 theme.
7274 @end deffn
7275
7276 @defvr {Scheme Variable} %default-theme
7277 @defvrx {Scheme Variable} %default-theme-name
7278 The G-Expression denoting the default SLiM theme and its name.
7279 @end defvr
7280
7281 @deffn {Scheme Procedure} xorg-start-command [#:guile] @
7282 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
7283 Return a derivation that builds a @var{guile} script to start the X server
7284 from @var{xorg-server}. @var{configuration-file} is the server configuration
7285 file or a derivation that builds it; when omitted, the result of
7286 @code{xorg-configuration-file} is used.
7287
7288 Usually the X server is started by a login manager.
7289 @end deffn
7290
7291 @deffn {Scheme Procedure} xorg-configuration-file @
7292 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
7293 Return a configuration file for the Xorg server containing search paths for
7294 all the common drivers.
7295
7296 @var{drivers} must be either the empty list, in which case Xorg chooses a
7297 graphics driver automatically, or a list of driver names that will be tried in
7298 this order---e.g., @code{(\"modesetting\" \"vesa\")}.
7299
7300 Likewise, when @var{resolutions} is the empty list, Xorg chooses an
7301 appropriate screen resolution; otherwise, it must be a list of
7302 resolutions---e.g., @code{((1024 768) (640 480))}.
7303
7304 Last, @var{extra-config} is a list of strings or objects appended to the
7305 @code{text-file*} argument list. It is used to pass extra text to be added
7306 verbatim to the configuration file.
7307 @end deffn
7308
7309 @deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
7310 Add @var{package}, a package for a screen-locker or screen-saver whose
7311 command is @var{program}, to the set of setuid programs and add a PAM entry
7312 for it. For example:
7313
7314 @lisp
7315 (screen-locker-service xlockmore "xlock")
7316 @end lisp
7317
7318 makes the good ol' XlockMore usable.
7319 @end deffn
7320
7321
7322 @node Desktop Services
7323 @subsubsection Desktop Services
7324
7325 The @code{(gnu services desktop)} module provides services that are
7326 usually useful in the context of a ``desktop'' setup---that is, on a
7327 machine running a graphical display server, possibly with graphical user
7328 interfaces, etc.
7329
7330 To simplify things, the module defines a variable containing the set of
7331 services that users typically expect on a machine with a graphical
7332 environment and networking:
7333
7334 @defvr {Scheme Variable} %desktop-services
7335 This is a list of services that builds upon @var{%base-services} and
7336 adds or adjust services for a typical ``desktop'' setup.
7337
7338 In particular, it adds a graphical login manager (@pxref{X Window,
7339 @code{slim-service}}), screen lockers,
7340 a network management tool (@pxref{Networking
7341 Services, @code{wicd-service}}), energy and color management services,
7342 the @code{elogind} login and seat manager, the Polkit privilege service,
7343 the GeoClue location service, an NTP client (@pxref{Networking
7344 Services}), the Avahi daemon, and has the name service switch service
7345 configured to be able to use @code{nss-mdns} (@pxref{Name Service
7346 Switch, mDNS}).
7347 @end defvr
7348
7349 The @var{%desktop-services} variable can be used as the @code{services}
7350 field of an @code{operating-system} declaration (@pxref{operating-system
7351 Reference, @code{services}}).
7352
7353 The actual service definitions provided by @code{(gnu services dbus)}
7354 and @code{(gnu services desktop)} are described below.
7355
7356 @deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
7357 Return a service that runs the ``system bus'', using @var{dbus}, with
7358 support for @var{services}.
7359
7360 @uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
7361 facility. Its system bus is used to allow system services to communicate
7362 and be notified of system-wide events.
7363
7364 @var{services} must be a list of packages that provide an
7365 @file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
7366 and policy files. For example, to allow avahi-daemon to use the system bus,
7367 @var{services} must be equal to @code{(list avahi)}.
7368 @end deffn
7369
7370 @deffn {Scheme Procedure} elogind-service [#:config @var{config}]
7371 Return a service that runs the @code{elogind} login and
7372 seat management daemon. @uref{https://github.com/andywingo/elogind,
7373 Elogind} exposes a D-Bus interface that can be used to know which users
7374 are logged in, know what kind of sessions they have open, suspend the
7375 system, inhibit system suspend, reboot the system, and other tasks.
7376
7377 Elogind handles most system-level power events for a computer, for
7378 example suspending the system when a lid is closed, or shutting it down
7379 when the power button is pressed.
7380
7381 The @var{config} keyword argument specifies the configuration for
7382 elogind, and should be the result of a @code{(elogind-configuration
7383 (@var{parameter} @var{value})...)} invocation. Available parameters and
7384 their default values are:
7385
7386 @table @code
7387 @item kill-user-processes?
7388 @code{#f}
7389 @item kill-only-users
7390 @code{()}
7391 @item kill-exclude-users
7392 @code{("root")}
7393 @item inhibit-delay-max-seconds
7394 @code{5}
7395 @item handle-power-key
7396 @code{poweroff}
7397 @item handle-suspend-key
7398 @code{suspend}
7399 @item handle-hibernate-key
7400 @code{hibernate}
7401 @item handle-lid-switch
7402 @code{suspend}
7403 @item handle-lid-switch-docked
7404 @code{ignore}
7405 @item power-key-ignore-inhibited?
7406 @code{#f}
7407 @item suspend-key-ignore-inhibited?
7408 @code{#f}
7409 @item hibernate-key-ignore-inhibited?
7410 @code{#f}
7411 @item lid-switch-ignore-inhibited?
7412 @code{#t}
7413 @item holdoff-timeout-seconds
7414 @code{30}
7415 @item idle-action
7416 @code{ignore}
7417 @item idle-action-seconds
7418 @code{(* 30 60)}
7419 @item runtime-directory-size-percent
7420 @code{10}
7421 @item runtime-directory-size
7422 @code{#f}
7423 @item remove-ipc?
7424 @code{#t}
7425 @item suspend-state
7426 @code{("mem" "standby" "freeze")}
7427 @item suspend-mode
7428 @code{()}
7429 @item hibernate-state
7430 @code{("disk")}
7431 @item hibernate-mode
7432 @code{("platform" "shutdown")}
7433 @item hybrid-sleep-state
7434 @code{("disk")}
7435 @item hybrid-sleep-mode
7436 @code{("suspend" "platform" "shutdown")}
7437 @end table
7438 @end deffn
7439
7440 @deffn {Scheme Procedure} polkit-service @
7441 [#:polkit @var{polkit}]
7442 Return a service that runs the
7443 @uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
7444 management service}, which allows system administrators to grant access to
7445 privileged operations in a structured way. By querying the Polkit service, a
7446 privileged system component can know when it should grant additional
7447 capabilities to ordinary users. For example, an ordinary user can be granted
7448 the capability to suspend the system if the user is logged in locally.
7449 @end deffn
7450
7451 @deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
7452 [#:watts-up-pro? #f] @
7453 [#:poll-batteries? #t] @
7454 [#:ignore-lid? #f] @
7455 [#:use-percentage-for-policy? #f] @
7456 [#:percentage-low 10] @
7457 [#:percentage-critical 3] @
7458 [#:percentage-action 2] @
7459 [#:time-low 1200] @
7460 [#:time-critical 300] @
7461 [#:time-action 120] @
7462 [#:critical-power-action 'hybrid-sleep]
7463 Return a service that runs @uref{http://upower.freedesktop.org/,
7464 @command{upowerd}}, a system-wide monitor for power consumption and battery
7465 levels, with the given configuration settings. It implements the
7466 @code{org.freedesktop.UPower} D-Bus interface, and is notably used by
7467 GNOME.
7468 @end deffn
7469
7470 @deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
7471 Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
7472 UDisks}, a @dfn{disk management} daemon that provides user interfaces with
7473 notifications and ways to mount/unmount disks. Programs that talk to UDisks
7474 include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
7475 @end deffn
7476
7477 @deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7478 Return a service that runs @command{colord}, a system service with a D-Bus
7479 interface to manage the color profiles of input and output devices such as
7480 screens and scanners. It is notably used by the GNOME Color Manager graphical
7481 tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
7482 site} for more information.
7483 @end deffn
7484
7485 @deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
7486 Return an configuration allowing an application to access GeoClue
7487 location data. @var{name} is the Desktop ID of the application, without
7488 the @code{.desktop} part. If @var{allowed?} is true, the application
7489 will have access to location information by default. The boolean
7490 @var{system?} value indicates that an application is a system component
7491 or not. Finally @var{users} is a list of UIDs of all users for which
7492 this application is allowed location info access. An empty users list
7493 means that all users are allowed.
7494 @end deffn
7495
7496 @defvr {Scheme Variable} %standard-geoclue-applications
7497 The standard list of well-known GeoClue application configurations,
7498 granting authority to GNOME's date-and-time utility to ask for the
7499 current location in order to set the time zone, and allowing the Firefox
7500 (IceCat) and Epiphany web browsers to request location information.
7501 Firefox and Epiphany both query the user before allowing a web page to
7502 know the user's location.
7503 @end defvr
7504
7505 @deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
7506 [#:whitelist '()] @
7507 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
7508 [#:submit-data? #f]
7509 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
7510 [#:submission-nick "geoclue"] @
7511 [#:applications %standard-geoclue-applications]
7512 Return a service that runs the GeoClue location service. This service
7513 provides a D-Bus interface to allow applications to request access to a
7514 user's physical location, and optionally to add information to online
7515 location databases. See
7516 @uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
7517 web site} for more information.
7518 @end deffn
7519
7520 @node Database Services
7521 @subsubsection Database Services
7522
7523 The @code{(gnu services databases)} module provides the following service.
7524
7525 @deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
7526 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
7527 Return a service that runs @var{postgresql}, the PostgreSQL database
7528 server.
7529
7530 The PostgreSQL daemon loads its runtime configuration from
7531 @var{config-file} and stores the database cluster in
7532 @var{data-directory}.
7533 @end deffn
7534
7535 @node Mail Services
7536 @subsubsection Mail Services
7537
7538 The @code{(gnu services mail)} module provides Guix service definitions
7539 for mail services. Currently the only implemented service is Dovecot,
7540 an IMAP, POP3, and LMTP server.
7541
7542 Guix does not yet have a mail transfer agent (MTA), although for some
7543 lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
7544 is needed to properly integrate a full MTA, such as Postfix. Patches
7545 welcome!
7546
7547 To add an IMAP/POP3 server to a GuixSD system, add a
7548 @code{dovecot-service} to the operating system definition:
7549
7550 @deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
7551 Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
7552 @end deffn
7553
7554 By default, Dovecot doesn't need much configuration; the default
7555 configuration object created by @code{(dovecot-configuration)} will
7556 suffice if your mail is delivered to @code{~/Maildir}. A self-signed
7557 certificate will be generated for TLS-protected connections, though
7558 Dovecot will also listen on cleartext ports by default. There are a
7559 number of options though which mail administrators might need to change,
7560 and as is the case with other services, Guix allows the system
7561 administrator to specify these parameters via a uniform Scheme interface.
7562
7563 For example, to specify that mail is located at @code{maildir~/.mail},
7564 one would instantiate the Dovecot service like this:
7565
7566 @example
7567 (dovecot-service #:config
7568 (dovecot-configuration
7569 (mail-location "maildir:~/.mail")))
7570 @end example
7571
7572 The available configuration parameters follow. Each parameter
7573 definition is preceded by its type; for example, @samp{string-list foo}
7574 indicates that the @code{foo} parameter should be specified as a list of
7575 strings. There is also a way to specify the configuration as a string,
7576 if you have an old @code{dovecot.conf} file that you want to port over
7577 from some other system; see the end for more details.
7578
7579 @c The following documentation was initially generated by
7580 @c (generate-documentation) in (gnu services mail). Manually maintained
7581 @c documentation is better, so we shouldn't hesitate to edit below as
7582 @c needed. However if the change you want to make to this documentation
7583 @c can be done in an automated way, it's probably easier to change
7584 @c (generate-documentation) than to make it below and have to deal with
7585 @c the churn as dovecot updates.
7586
7587 Available @code{dovecot-configuration} fields are:
7588
7589 @deftypevr {@code{dovecot-configuration} parameter} package dovecot
7590 The dovecot package.
7591 @end deftypevr
7592
7593 @deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
7594 A list of IPs or hosts where to listen in for connections. @samp{*}
7595 listens in all IPv4 interfaces, @samp{::} listens in all IPv6
7596 interfaces. If you want to specify non-default ports or anything more
7597 complex, customize the address and port fields of the
7598 @samp{inet-listener} of the specific services you are interested in.
7599 @end deftypevr
7600
7601 @deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
7602 List of protocols we want to serve. Available protocols include
7603 @samp{imap}, @samp{pop3}, and @samp{lmtp}.
7604
7605 Available @code{protocol-configuration} fields are:
7606
7607 @deftypevr {@code{protocol-configuration} parameter} string name
7608 The name of the protocol.
7609 @end deftypevr
7610
7611 @deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
7612 UNIX socket path to master authentication server to find users.
7613 This is used by imap (for shared users) and lda.
7614 Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
7615 @end deftypevr
7616
7617 @deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
7618 Space separated list of plugins to load.
7619 @end deftypevr
7620
7621 @deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
7622 Maximum number of IMAP connections allowed for a user from each IP
7623 address. NOTE: The username is compared case-sensitively.
7624 Defaults to @samp{10}.
7625 @end deftypevr
7626
7627 @end deftypevr
7628
7629 @deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
7630 List of services to enable. Available services include @samp{imap},
7631 @samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
7632 @samp{lmtp}.
7633
7634 Available @code{service-configuration} fields are:
7635
7636 @deftypevr {@code{service-configuration} parameter} string kind
7637 The service kind. Valid values include @code{director},
7638 @code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
7639 @code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
7640 @code{tcpwrap}, @code{quota-warning}, or anything else.
7641 @end deftypevr
7642
7643 @deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
7644 Listeners for the service. A listener is either an
7645 @code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
7646 an @code{inet-listener-configuration}.
7647 Defaults to @samp{()}.
7648
7649 Available @code{unix-listener-configuration} fields are:
7650
7651 @deftypevr {@code{unix-listener-configuration} parameter} file-name path
7652 The file name on which to listen.
7653 @end deftypevr
7654
7655 @deftypevr {@code{unix-listener-configuration} parameter} string mode
7656 The access mode for the socket.
7657 Defaults to @samp{"0600"}.
7658 @end deftypevr
7659
7660 @deftypevr {@code{unix-listener-configuration} parameter} string user
7661 The user to own the socket.
7662 Defaults to @samp{""}.
7663 @end deftypevr
7664
7665 @deftypevr {@code{unix-listener-configuration} parameter} string group
7666 The group to own the socket.
7667 Defaults to @samp{""}.
7668 @end deftypevr
7669
7670
7671 Available @code{fifo-listener-configuration} fields are:
7672
7673 @deftypevr {@code{fifo-listener-configuration} parameter} file-name path
7674 The file name on which to listen.
7675 @end deftypevr
7676
7677 @deftypevr {@code{fifo-listener-configuration} parameter} string mode
7678 The access mode for the socket.
7679 Defaults to @samp{"0600"}.
7680 @end deftypevr
7681
7682 @deftypevr {@code{fifo-listener-configuration} parameter} string user
7683 The user to own the socket.
7684 Defaults to @samp{""}.
7685 @end deftypevr
7686
7687 @deftypevr {@code{fifo-listener-configuration} parameter} string group
7688 The group to own the socket.
7689 Defaults to @samp{""}.
7690 @end deftypevr
7691
7692
7693 Available @code{inet-listener-configuration} fields are:
7694
7695 @deftypevr {@code{inet-listener-configuration} parameter} string protocol
7696 The protocol to listen for.
7697 @end deftypevr
7698
7699 @deftypevr {@code{inet-listener-configuration} parameter} string address
7700 The address on which to listen, or empty for all addresses.
7701 Defaults to @samp{""}.
7702 @end deftypevr
7703
7704 @deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
7705 The port on which to listen.
7706 @end deftypevr
7707
7708 @deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
7709 Whether to use SSL for this service; @samp{yes}, @samp{no}, or
7710 @samp{required}.
7711 Defaults to @samp{#t}.
7712 @end deftypevr
7713
7714 @end deftypevr
7715
7716 @deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
7717 Number of connections to handle before starting a new process.
7718 Typically the only useful values are 0 (unlimited) or 1. 1 is more
7719 secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
7720 Defaults to @samp{1}.
7721 @end deftypevr
7722
7723 @deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
7724 Number of processes to always keep waiting for more connections.
7725 Defaults to @samp{0}.
7726 @end deftypevr
7727
7728 @deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
7729 If you set @samp{service-count 0}, you probably need to grow
7730 this.
7731 Defaults to @samp{256000000}.
7732 @end deftypevr
7733
7734 @end deftypevr
7735
7736 @deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
7737 Dict configuration, as created by the @code{dict-configuration}
7738 constructor.
7739
7740 Available @code{dict-configuration} fields are:
7741
7742 @deftypevr {@code{dict-configuration} parameter} free-form-fields entries
7743 A list of key-value pairs that this dict should hold.
7744 Defaults to @samp{()}.
7745 @end deftypevr
7746
7747 @end deftypevr
7748
7749 @deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
7750 List of passdb configurations, each one created by the
7751 @code{passdb-configuration} constructor.
7752
7753 Available @code{passdb-configuration} fields are:
7754
7755 @deftypevr {@code{passdb-configuration} parameter} string driver
7756 The driver that the passdb should use. Valid values include
7757 @samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
7758 @samp{static}.
7759 Defaults to @samp{"pam"}.
7760 @end deftypevr
7761
7762 @deftypevr {@code{passdb-configuration} parameter} free-form-args args
7763 A list of key-value args to the passdb driver.
7764 Defaults to @samp{()}.
7765 @end deftypevr
7766
7767 @end deftypevr
7768
7769 @deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
7770 List of userdb configurations, each one created by the
7771 @code{userdb-configuration} constructor.
7772
7773 Available @code{userdb-configuration} fields are:
7774
7775 @deftypevr {@code{userdb-configuration} parameter} string driver
7776 The driver that the userdb should use. Valid values include
7777 @samp{passwd} and @samp{static}.
7778 Defaults to @samp{"passwd"}.
7779 @end deftypevr
7780
7781 @deftypevr {@code{userdb-configuration} parameter} free-form-args args
7782 A list of key-value args to the userdb driver.
7783 Defaults to @samp{()}.
7784 @end deftypevr
7785
7786 @deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
7787 Override fields from passwd.
7788 Defaults to @samp{()}.
7789 @end deftypevr
7790
7791 @end deftypevr
7792
7793 @deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
7794 Plug-in configuration, created by the @code{plugin-configuration}
7795 constructor.
7796 @end deftypevr
7797
7798 @deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
7799 List of namespaces. Each item in the list is created by the
7800 @code{namespace-configuration} constructor.
7801
7802 Available @code{namespace-configuration} fields are:
7803
7804 @deftypevr {@code{namespace-configuration} parameter} string name
7805 Name for this namespace.
7806 @end deftypevr
7807
7808 @deftypevr {@code{namespace-configuration} parameter} string type
7809 Namespace type: @samp{private}, @samp{shared} or @samp{public}.
7810 Defaults to @samp{"private"}.
7811 @end deftypevr
7812
7813 @deftypevr {@code{namespace-configuration} parameter} string separator
7814 Hierarchy separator to use. You should use the same separator for
7815 all namespaces or some clients get confused. @samp{/} is usually a good
7816 one. The default however depends on the underlying mail storage
7817 format.
7818 Defaults to @samp{""}.
7819 @end deftypevr
7820
7821 @deftypevr {@code{namespace-configuration} parameter} string prefix
7822 Prefix required to access this namespace. This needs to be
7823 different for all namespaces. For example @samp{Public/}.
7824 Defaults to @samp{""}.
7825 @end deftypevr
7826
7827 @deftypevr {@code{namespace-configuration} parameter} string location
7828 Physical location of the mailbox. This is in same format as
7829 mail_location, which is also the default for it.
7830 Defaults to @samp{""}.
7831 @end deftypevr
7832
7833 @deftypevr {@code{namespace-configuration} parameter} boolean inbox?
7834 There can be only one INBOX, and this setting defines which
7835 namespace has it.
7836 Defaults to @samp{#f}.
7837 @end deftypevr
7838
7839 @deftypevr {@code{namespace-configuration} parameter} boolean hidden?
7840 If namespace is hidden, it's not advertised to clients via NAMESPACE
7841 extension. You'll most likely also want to set @samp{list? #f}. This is mostly
7842 useful when converting from another server with different namespaces
7843 which you want to deprecate but still keep working. For example you can
7844 create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
7845 and @samp{mail/}.
7846 Defaults to @samp{#f}.
7847 @end deftypevr
7848
7849 @deftypevr {@code{namespace-configuration} parameter} boolean list?
7850 Show the mailboxes under this namespace with LIST command. This
7851 makes the namespace visible for clients that don't support NAMESPACE
7852 extension. The special @code{children} value lists child mailboxes, but
7853 hides the namespace prefix.
7854 Defaults to @samp{#t}.
7855 @end deftypevr
7856
7857 @deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
7858 Namespace handles its own subscriptions. If set to @code{#f}, the
7859 parent namespace handles them. The empty prefix should always have this
7860 as @code{#t}.)
7861 Defaults to @samp{#t}.
7862 @end deftypevr
7863
7864 @deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
7865 List of predefined mailboxes in this namespace.
7866 Defaults to @samp{()}.
7867
7868 Available @code{mailbox-configuration} fields are:
7869
7870 @deftypevr {@code{mailbox-configuration} parameter} string name
7871 Name for this mailbox.
7872 @end deftypevr
7873
7874 @deftypevr {@code{mailbox-configuration} parameter} string auto
7875 @samp{create} will automatically create this mailbox.
7876 @samp{subscribe} will both create and subscribe to the mailbox.
7877 Defaults to @samp{"no"}.
7878 @end deftypevr
7879
7880 @deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
7881 List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
7882 Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
7883 @code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
7884 Defaults to @samp{()}.
7885 @end deftypevr
7886
7887 @end deftypevr
7888
7889 @end deftypevr
7890
7891 @deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
7892 Base directory where to store runtime data.
7893 Defaults to @samp{"/var/run/dovecot/"}.
7894 @end deftypevr
7895
7896 @deftypevr {@code{dovecot-configuration} parameter} string login-greeting
7897 Greeting message for clients.
7898 Defaults to @samp{"Dovecot ready."}.
7899 @end deftypevr
7900
7901 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
7902 List of trusted network ranges. Connections from these IPs are
7903 allowed to override their IP addresses and ports (for logging and for
7904 authentication checks). @samp{disable-plaintext-auth} is also ignored
7905 for these networks. Typically you'd specify your IMAP proxy servers
7906 here.
7907 Defaults to @samp{()}.
7908 @end deftypevr
7909
7910 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
7911 List of login access check sockets (e.g. tcpwrap).
7912 Defaults to @samp{()}.
7913 @end deftypevr
7914
7915 @deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
7916 Show more verbose process titles (in ps). Currently shows user name
7917 and IP address. Useful for seeing who are actually using the IMAP
7918 processes (e.g. shared mailboxes or if same uid is used for multiple
7919 accounts).
7920 Defaults to @samp{#f}.
7921 @end deftypevr
7922
7923 @deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
7924 Should all processes be killed when Dovecot master process shuts down.
7925 Setting this to @code{#f} means that Dovecot can be upgraded without
7926 forcing existing client connections to close (although that could also
7927 be a problem if the upgrade is e.g. because of a security fix).
7928 Defaults to @samp{#t}.
7929 @end deftypevr
7930
7931 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
7932 If non-zero, run mail commands via this many connections to doveadm
7933 server, instead of running them directly in the same process.
7934 Defaults to @samp{0}.
7935 @end deftypevr
7936
7937 @deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
7938 UNIX socket or host:port used for connecting to doveadm server.
7939 Defaults to @samp{"doveadm-server"}.
7940 @end deftypevr
7941
7942 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
7943 List of environment variables that are preserved on Dovecot startup
7944 and passed down to all of its child processes. You can also give
7945 key=value pairs to always set specific settings.
7946 @end deftypevr
7947
7948 @deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
7949 Disable LOGIN command and all other plaintext authentications unless
7950 SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
7951 matches the local IP (i.e. you're connecting from the same computer),
7952 the connection is considered secure and plaintext authentication is
7953 allowed. See also ssl=required setting.
7954 Defaults to @samp{#t}.
7955 @end deftypevr
7956
7957 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
7958 Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
7959 Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
7960 for caching to be used.
7961 Defaults to @samp{0}.
7962 @end deftypevr
7963
7964 @deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
7965 Time to live for cached data. After TTL expires the cached record
7966 is no longer used, *except* if the main database lookup returns internal
7967 failure. We also try to handle password changes automatically: If
7968 user's previous authentication was successful, but this one wasn't, the
7969 cache isn't used. For now this works only with plaintext
7970 authentication.
7971 Defaults to @samp{"1 hour"}.
7972 @end deftypevr
7973
7974 @deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
7975 TTL for negative hits (user not found, password mismatch).
7976 0 disables caching them completely.
7977 Defaults to @samp{"1 hour"}.
7978 @end deftypevr
7979
7980 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
7981 List of realms for SASL authentication mechanisms that need them.
7982 You can leave it empty if you don't want to support multiple realms.
7983 Many clients simply use the first one listed here, so keep the default
7984 realm first.
7985 Defaults to @samp{()}.
7986 @end deftypevr
7987
7988 @deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
7989 Default realm/domain to use if none was specified. This is used for
7990 both SASL realms and appending @@domain to username in plaintext
7991 logins.
7992 Defaults to @samp{""}.
7993 @end deftypevr
7994
7995 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
7996 List of allowed characters in username. If the user-given username
7997 contains a character not listed in here, the login automatically fails.
7998 This is just an extra check to make sure user can't exploit any
7999 potential quote escaping vulnerabilities with SQL/LDAP databases. If
8000 you want to allow all characters, set this value to empty.
8001 Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
8002 @end deftypevr
8003
8004 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
8005 Username character translations before it's looked up from
8006 databases. The value contains series of from -> to characters. For
8007 example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
8008 translated to @samp{@@}.
8009 Defaults to @samp{""}.
8010 @end deftypevr
8011
8012 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
8013 Username formatting before it's looked up from databases. You can
8014 use the standard variables here, e.g. %Lu would lowercase the username,
8015 %n would drop away the domain if it was given, or @samp{%n-AT-%d} would
8016 change the @samp{@@} into @samp{-AT-}. This translation is done after
8017 @samp{auth-username-translation} changes.
8018 Defaults to @samp{"%Lu"}.
8019 @end deftypevr
8020
8021 @deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
8022 If you want to allow master users to log in by specifying the master
8023 username within the normal username string (i.e. not using SASL
8024 mechanism's support for it), you can specify the separator character
8025 here. The format is then <username><separator><master username>.
8026 UW-IMAP uses @samp{*} as the separator, so that could be a good
8027 choice.
8028 Defaults to @samp{""}.
8029 @end deftypevr
8030
8031 @deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
8032 Username to use for users logging in with ANONYMOUS SASL
8033 mechanism.
8034 Defaults to @samp{"anonymous"}.
8035 @end deftypevr
8036
8037 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
8038 Maximum number of dovecot-auth worker processes. They're used to
8039 execute blocking passdb and userdb queries (e.g. MySQL and PAM).
8040 They're automatically created and destroyed as needed.
8041 Defaults to @samp{30}.
8042 @end deftypevr
8043
8044 @deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
8045 Host name to use in GSSAPI principal names. The default is to use
8046 the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
8047 allow all keytab entries.
8048 Defaults to @samp{""}.
8049 @end deftypevr
8050
8051 @deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
8052 Kerberos keytab to use for the GSSAPI mechanism. Will use the
8053 system default (usually /etc/krb5.keytab) if not specified. You may
8054 need to change the auth service to run as root to be able to read this
8055 file.
8056 Defaults to @samp{""}.
8057 @end deftypevr
8058
8059 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
8060 Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
8061 and @samp{ntlm-auth} helper.
8062 <doc/wiki/Authentication/Mechanisms/Winbind.txt>.
8063 Defaults to @samp{#f}.
8064 @end deftypevr
8065
8066 @deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
8067 Path for Samba's @samp{ntlm-auth} helper binary.
8068 Defaults to @samp{"/usr/bin/ntlm_auth"}.
8069 @end deftypevr
8070
8071 @deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
8072 Time to delay before replying to failed authentications.
8073 Defaults to @samp{"2 secs"}.
8074 @end deftypevr
8075
8076 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
8077 Require a valid SSL client certificate or the authentication
8078 fails.
8079 Defaults to @samp{#f}.
8080 @end deftypevr
8081
8082 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
8083 Take the username from client's SSL certificate, using
8084 @code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
8085 CommonName.
8086 Defaults to @samp{#f}.
8087 @end deftypevr
8088
8089 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
8090 List of wanted authentication mechanisms. Supported mechanisms are:
8091 @samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
8092 @samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
8093 @samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
8094 @samp{disable-plaintext-auth} setting.
8095 @end deftypevr
8096
8097 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
8098 List of IPs or hostnames to all director servers, including ourself.
8099 Ports can be specified as ip:port. The default port is the same as what
8100 director service's @samp{inet-listener} is using.
8101 Defaults to @samp{()}.
8102 @end deftypevr
8103
8104 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
8105 List of IPs or hostnames to all backend mail servers. Ranges are
8106 allowed too, like 10.0.0.10-10.0.0.30.
8107 Defaults to @samp{()}.
8108 @end deftypevr
8109
8110 @deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
8111 How long to redirect users to a specific server after it no longer
8112 has any connections.
8113 Defaults to @samp{"15 min"}.
8114 @end deftypevr
8115
8116 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
8117 TCP/IP port that accepts doveadm connections (instead of director
8118 connections) If you enable this, you'll also need to add
8119 @samp{inet-listener} for the port.
8120 Defaults to @samp{0}.
8121 @end deftypevr
8122
8123 @deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
8124 How the username is translated before being hashed. Useful values
8125 include %Ln if user can log in with or without @@domain, %Ld if mailboxes
8126 are shared within domain.
8127 Defaults to @samp{"%Lu"}.
8128 @end deftypevr
8129
8130 @deftypevr {@code{dovecot-configuration} parameter} string log-path
8131 Log file to use for error messages. @samp{syslog} logs to syslog,
8132 @samp{/dev/stderr} logs to stderr.
8133 Defaults to @samp{"syslog"}.
8134 @end deftypevr
8135
8136 @deftypevr {@code{dovecot-configuration} parameter} string info-log-path
8137 Log file to use for informational messages. Defaults to
8138 @samp{log-path}.
8139 Defaults to @samp{""}.
8140 @end deftypevr
8141
8142 @deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
8143 Log file to use for debug messages. Defaults to
8144 @samp{info-log-path}.
8145 Defaults to @samp{""}.
8146 @end deftypevr
8147
8148 @deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
8149 Syslog facility to use if you're logging to syslog. Usually if you
8150 don't want to use @samp{mail}, you'll use local0..local7. Also other
8151 standard facilities are supported.
8152 Defaults to @samp{"mail"}.
8153 @end deftypevr
8154
8155 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
8156 Log unsuccessful authentication attempts and the reasons why they
8157 failed.
8158 Defaults to @samp{#f}.
8159 @end deftypevr
8160
8161 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
8162 In case of password mismatches, log the attempted password. Valid
8163 values are no, plain and sha1. sha1 can be useful for detecting brute
8164 force password attempts vs. user simply trying the same password over
8165 and over again. You can also truncate the value to n chars by appending
8166 ":n" (e.g. sha1:6).
8167 Defaults to @samp{#f}.
8168 @end deftypevr
8169
8170 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
8171 Even more verbose logging for debugging purposes. Shows for example
8172 SQL queries.
8173 Defaults to @samp{#f}.
8174 @end deftypevr
8175
8176 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
8177 In case of password mismatches, log the passwords and used scheme so
8178 the problem can be debugged. Enabling this also enables
8179 @samp{auth-debug}.
8180 Defaults to @samp{#f}.
8181 @end deftypevr
8182
8183 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
8184 Enable mail process debugging. This can help you figure out why
8185 Dovecot isn't finding your mails.
8186 Defaults to @samp{#f}.
8187 @end deftypevr
8188
8189 @deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
8190 Show protocol level SSL errors.
8191 Defaults to @samp{#f}.
8192 @end deftypevr
8193
8194 @deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
8195 Prefix for each line written to log file. % codes are in
8196 strftime(3) format.
8197 Defaults to @samp{"\"%b %d %H:%M:%S \""}.
8198 @end deftypevr
8199
8200 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
8201 List of elements we want to log. The elements which have a
8202 non-empty variable value are joined together to form a comma-separated
8203 string.
8204 @end deftypevr
8205
8206 @deftypevr {@code{dovecot-configuration} parameter} string login-log-format
8207 Login log format. %s contains @samp{login-log-format-elements}
8208 string, %$ contains the data we want to log.
8209 Defaults to @samp{"%$: %s"}.
8210 @end deftypevr
8211
8212 @deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
8213 Log prefix for mail processes. See doc/wiki/Variables.txt for list
8214 of possible variables you can use.
8215 Defaults to @samp{"\"%s(%u): \""}.
8216 @end deftypevr
8217
8218 @deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
8219 Format to use for logging mail deliveries. You can use variables:
8220 @table @code
8221 @item %$
8222 Delivery status message (e.g. @samp{saved to INBOX})
8223 @item %m
8224 Message-ID
8225 @item %s
8226 Subject
8227 @item %f
8228 From address
8229 @item %p
8230 Physical size
8231 @item %w
8232 Virtual size.
8233 @end table
8234 Defaults to @samp{"msgid=%m: %$"}.
8235 @end deftypevr
8236
8237 @deftypevr {@code{dovecot-configuration} parameter} string mail-location
8238 Location for users' mailboxes. The default is empty, which means
8239 that Dovecot tries to find the mailboxes automatically. This won't work
8240 if the user doesn't yet have any mail, so you should explicitly tell
8241 Dovecot the full location.
8242
8243 If you're using mbox, giving a path to the INBOX
8244 file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
8245 where the other mailboxes are kept. This is called the "root mail
8246 directory", and it must be the first path given in the
8247 @samp{mail-location} setting.
8248
8249 There are a few special variables you can use, eg.:
8250
8251 @table @samp
8252 @item %u
8253 username
8254 @item %n
8255 user part in user@@domain, same as %u if there's no domain
8256 @item %d
8257 domain part in user@@domain, empty if there's no domain
8258 @item %h
8259 home director
8260 @end table
8261
8262 See doc/wiki/Variables.txt for full list. Some examples:
8263 @table @samp
8264 @item maildir:~/Maildir
8265 @item mbox:~/mail:INBOX=/var/mail/%u
8266 @item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
8267 @end table
8268 Defaults to @samp{""}.
8269 @end deftypevr
8270
8271 @deftypevr {@code{dovecot-configuration} parameter} string mail-uid
8272 System user and group used to access mails. If you use multiple,
8273 userdb can override these by returning uid or gid fields. You can use
8274 either numbers or names. <doc/wiki/UserIds.txt>.
8275 Defaults to @samp{""}.
8276 @end deftypevr
8277
8278 @deftypevr {@code{dovecot-configuration} parameter} string mail-gid
8279
8280 Defaults to @samp{""}.
8281 @end deftypevr
8282
8283 @deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
8284 Group to enable temporarily for privileged operations. Currently
8285 this is used only with INBOX when either its initial creation or
8286 dotlocking fails. Typically this is set to "mail" to give access to
8287 /var/mail.
8288 Defaults to @samp{""}.
8289 @end deftypevr
8290
8291 @deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
8292 Grant access to these supplementary groups for mail processes.
8293 Typically these are used to set up access to shared mailboxes. Note
8294 that it may be dangerous to set these if users can create
8295 symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
8296 could allow a user to delete others' mailboxes, or ln -s
8297 /secret/shared/box ~/mail/mybox would allow reading it).
8298 Defaults to @samp{""}.
8299 @end deftypevr
8300
8301 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
8302 Allow full filesystem access to clients. There's no access checks
8303 other than what the operating system does for the active UID/GID. It
8304 works with both maildir and mboxes, allowing you to prefix mailboxes
8305 names with e.g. /path/ or ~user/.
8306 Defaults to @samp{#f}.
8307 @end deftypevr
8308
8309 @deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
8310 Don't use mmap() at all. This is required if you store indexes to
8311 shared filesystems (NFS or clustered filesystem).
8312 Defaults to @samp{#f}.
8313 @end deftypevr
8314
8315 @deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
8316 Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
8317 supports @samp{O_EXCL} since version 3, so this should be safe to use
8318 nowadays by default.
8319 Defaults to @samp{#t}.
8320 @end deftypevr
8321
8322 @deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
8323 When to use fsync() or fdatasync() calls:
8324 @table @code
8325 @item optimized
8326 Whenever necessary to avoid losing important data
8327 @item always
8328 Useful with e.g. NFS when write()s are delayed
8329 @item never
8330 Never use it (best performance, but crashes can lose data).
8331 @end table
8332 Defaults to @samp{"optimized"}.
8333 @end deftypevr
8334
8335 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
8336 Mail storage exists in NFS. Set this to yes to make Dovecot flush
8337 NFS caches whenever needed. If you're using only a single mail server
8338 this isn't needed.
8339 Defaults to @samp{#f}.
8340 @end deftypevr
8341
8342 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
8343 Mail index files also exist in NFS. Setting this to yes requires
8344 @samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
8345 Defaults to @samp{#f}.
8346 @end deftypevr
8347
8348 @deftypevr {@code{dovecot-configuration} parameter} string lock-method
8349 Locking method for index files. Alternatives are fcntl, flock and
8350 dotlock. Dotlocking uses some tricks which may create more disk I/O
8351 than other locking methods. NFS users: flock doesn't work, remember to
8352 change @samp{mmap-disable}.
8353 Defaults to @samp{"fcntl"}.
8354 @end deftypevr
8355
8356 @deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
8357 Directory in which LDA/LMTP temporarily stores incoming mails >128
8358 kB.
8359 Defaults to @samp{"/tmp"}.
8360 @end deftypevr
8361
8362 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
8363 Valid UID range for users. This is mostly to make sure that users can't
8364 log in as daemons or other system users. Note that denying root logins is
8365 hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
8366 is set to 0.
8367 Defaults to @samp{500}.
8368 @end deftypevr
8369
8370 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
8371
8372 Defaults to @samp{0}.
8373 @end deftypevr
8374
8375 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
8376 Valid GID range for users. Users having non-valid GID as primary group ID
8377 aren't allowed to log in. If user belongs to supplementary groups with
8378 non-valid GIDs, those groups are not set.
8379 Defaults to @samp{1}.
8380 @end deftypevr
8381
8382 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
8383
8384 Defaults to @samp{0}.
8385 @end deftypevr
8386
8387 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
8388 Maximum allowed length for mail keyword name. It's only forced when
8389 trying to create new keywords.
8390 Defaults to @samp{50}.
8391 @end deftypevr
8392
8393 @deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
8394 List of directories under which chrooting is allowed for mail
8395 processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
8396 too). This setting doesn't affect @samp{login-chroot}
8397 @samp{mail-chroot} or auth chroot settings. If this setting is empty,
8398 "/./" in home dirs are ignored. WARNING: Never add directories here
8399 which local users can modify, that may lead to root exploit. Usually
8400 this should be done only if you don't allow shell access for users.
8401 <doc/wiki/Chrooting.txt>.
8402 Defaults to @samp{()}.
8403 @end deftypevr
8404
8405 @deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
8406 Default chroot directory for mail processes. This can be overridden
8407 for specific users in user database by giving /./ in user's home
8408 directory (e.g. /home/./user chroots into /home). Note that usually
8409 there is no real need to do chrooting, Dovecot doesn't allow users to
8410 access files outside their mail directory anyway. If your home
8411 directories are prefixed with the chroot directory, append "/." to
8412 @samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
8413 Defaults to @samp{""}.
8414 @end deftypevr
8415
8416 @deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
8417 UNIX socket path to master authentication server to find users.
8418 This is used by imap (for shared users) and lda.
8419 Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
8420 @end deftypevr
8421
8422 @deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
8423 Directory where to look up mail plugins.
8424 Defaults to @samp{"/usr/lib/dovecot"}.
8425 @end deftypevr
8426
8427 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
8428 List of plugins to load for all services. Plugins specific to IMAP,
8429 LDA, etc. are added to this list in their own .conf files.
8430 Defaults to @samp{()}.
8431 @end deftypevr
8432
8433 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
8434 The minimum number of mails in a mailbox before updates are done to
8435 cache file. This allows optimizing Dovecot's behavior to do less disk
8436 writes at the cost of more disk reads.
8437 Defaults to @samp{0}.
8438 @end deftypevr
8439
8440 @deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
8441 When IDLE command is running, mailbox is checked once in a while to
8442 see if there are any new mails or other changes. This setting defines
8443 the minimum time to wait between those checks. Dovecot can also use
8444 dnotify, inotify and kqueue to find out immediately when changes
8445 occur.
8446 Defaults to @samp{"30 secs"}.
8447 @end deftypevr
8448
8449 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
8450 Save mails with CR+LF instead of plain LF. This makes sending those
8451 mails take less CPU, especially with sendfile() syscall with Linux and
8452 FreeBSD. But it also creates a bit more disk I/O which may just make it
8453 slower. Also note that if other software reads the mboxes/maildirs,
8454 they may handle the extra CRs wrong and cause problems.
8455 Defaults to @samp{#f}.
8456 @end deftypevr
8457
8458 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
8459 By default LIST command returns all entries in maildir beginning
8460 with a dot. Enabling this option makes Dovecot return only entries
8461 which are directories. This is done by stat()ing each entry, so it
8462 causes more disk I/O.
8463 (For systems setting struct @samp{dirent->d_type} this check is free
8464 and it's done always regardless of this setting).
8465 Defaults to @samp{#f}.
8466 @end deftypevr
8467
8468 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
8469 When copying a message, do it with hard links whenever possible.
8470 This makes the performance much better, and it's unlikely to have any
8471 side effects.
8472 Defaults to @samp{#t}.
8473 @end deftypevr
8474
8475 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
8476 Assume Dovecot is the only MUA accessing Maildir: Scan cur/
8477 directory only when its mtime changes unexpectedly or when we can't find
8478 the mail otherwise.
8479 Defaults to @samp{#f}.
8480 @end deftypevr
8481
8482 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
8483 Which locking methods to use for locking mbox. There are four
8484 available:
8485
8486 @table @code
8487 @item dotlock
8488 Create <mailbox>.lock file. This is the oldest and most NFS-safe
8489 solution. If you want to use /var/mail/ like directory, the users will
8490 need write access to that directory.
8491 @item dotlock-try
8492 Same as dotlock, but if it fails because of permissions or because there
8493 isn't enough disk space, just skip it.
8494 @item fcntl
8495 Use this if possible. Works with NFS too if lockd is used.
8496 @item flock
8497 May not exist in all systems. Doesn't work with NFS.
8498 @item lockf
8499 May not exist in all systems. Doesn't work with NFS.
8500 @end table
8501
8502 You can use multiple locking methods; if you do the order they're declared
8503 in is important to avoid deadlocks if other MTAs/MUAs are using multiple
8504 locking methods as well. Some operating systems don't allow using some of
8505 them simultaneously.
8506 @end deftypevr
8507
8508 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
8509
8510 @end deftypevr
8511
8512 @deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
8513 Maximum time to wait for lock (all of them) before aborting.
8514 Defaults to @samp{"5 mins"}.
8515 @end deftypevr
8516
8517 @deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
8518 If dotlock exists but the mailbox isn't modified in any way,
8519 override the lock file after this much time.
8520 Defaults to @samp{"2 mins"}.
8521 @end deftypevr
8522
8523 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
8524 When mbox changes unexpectedly we have to fully read it to find out
8525 what changed. If the mbox is large this can take a long time. Since
8526 the change is usually just a newly appended mail, it'd be faster to
8527 simply read the new mails. If this setting is enabled, Dovecot does
8528 this but still safely fallbacks to re-reading the whole mbox file
8529 whenever something in mbox isn't how it's expected to be. The only real
8530 downside to this setting is that if some other MUA changes message
8531 flags, Dovecot doesn't notice it immediately. Note that a full sync is
8532 done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
8533 Defaults to @samp{#t}.
8534 @end deftypevr
8535
8536 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
8537 Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
8538 EXAMINE, EXPUNGE or CHECK commands. If this is set,
8539 @samp{mbox-dirty-syncs} is ignored.
8540 Defaults to @samp{#f}.
8541 @end deftypevr
8542
8543 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
8544 Delay writing mbox headers until doing a full write sync (EXPUNGE
8545 and CHECK commands and when closing the mailbox). This is especially
8546 useful for POP3 where clients often delete all mails. The downside is
8547 that our changes aren't immediately visible to other MUAs.
8548 Defaults to @samp{#t}.
8549 @end deftypevr
8550
8551 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
8552 If mbox size is smaller than this (e.g. 100k), don't write index
8553 files. If an index file already exists it's still read, just not
8554 updated.
8555 Defaults to @samp{0}.
8556 @end deftypevr
8557
8558 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
8559 Maximum dbox file size until it's rotated.
8560 Defaults to @samp{2000000}.
8561 @end deftypevr
8562
8563 @deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
8564 Maximum dbox file age until it's rotated. Typically in days. Day
8565 begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
8566 disabled.
8567 Defaults to @samp{"1d"}.
8568 @end deftypevr
8569
8570 @deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
8571 When creating new mdbox files, immediately preallocate their size to
8572 @samp{mdbox-rotate-size}. This setting currently works only in Linux
8573 with some filesystems (ext4, xfs).
8574 Defaults to @samp{#f}.
8575 @end deftypevr
8576
8577 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
8578 sdbox and mdbox support saving mail attachments to external files,
8579 which also allows single instance storage for them. Other backends
8580 don't support this for now.
8581
8582 WARNING: This feature hasn't been tested much yet. Use at your own risk.
8583
8584 Directory root where to store mail attachments. Disabled, if empty.
8585 Defaults to @samp{""}.
8586 @end deftypevr
8587
8588 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
8589 Attachments smaller than this aren't saved externally. It's also
8590 possible to write a plugin to disable saving specific attachments
8591 externally.
8592 Defaults to @samp{128000}.
8593 @end deftypevr
8594
8595 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
8596 Filesystem backend to use for saving attachments:
8597 @table @code
8598 @item posix
8599 No SiS done by Dovecot (but this might help FS's own deduplication)
8600 @item sis posix
8601 SiS with immediate byte-by-byte comparison during saving
8602 @item sis-queue posix
8603 SiS with delayed comparison and deduplication.
8604 @end table
8605 Defaults to @samp{"sis posix"}.
8606 @end deftypevr
8607
8608 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
8609 Hash format to use in attachment filenames. You can add any text and
8610 variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
8611 @code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
8612 truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
8613 Defaults to @samp{"%@{sha1@}"}.
8614 @end deftypevr
8615
8616 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
8617
8618 Defaults to @samp{100}.
8619 @end deftypevr
8620
8621 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
8622
8623 Defaults to @samp{1000}.
8624 @end deftypevr
8625
8626 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
8627 Default VSZ (virtual memory size) limit for service processes.
8628 This is mainly intended to catch and kill processes that leak memory
8629 before they eat up everything.
8630 Defaults to @samp{256000000}.
8631 @end deftypevr
8632
8633 @deftypevr {@code{dovecot-configuration} parameter} string default-login-user
8634 Login user is internally used by login processes. This is the most
8635 untrusted user in Dovecot system. It shouldn't have access to anything
8636 at all.
8637 Defaults to @samp{"dovenull"}.
8638 @end deftypevr
8639
8640 @deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
8641 Internal user is used by unprivileged processes. It should be
8642 separate from login user, so that login processes can't disturb other
8643 processes.
8644 Defaults to @samp{"dovecot"}.
8645 @end deftypevr
8646
8647 @deftypevr {@code{dovecot-configuration} parameter} string ssl?
8648 SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
8649 Defaults to @samp{"required"}.
8650 @end deftypevr
8651
8652 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
8653 PEM encoded X.509 SSL/TLS certificate (public key).
8654 Defaults to @samp{"</etc/dovecot/default.pem"}.
8655 @end deftypevr
8656
8657 @deftypevr {@code{dovecot-configuration} parameter} string ssl-key
8658 PEM encoded SSL/TLS private key. The key is opened before
8659 dropping root privileges, so keep the key file unreadable by anyone but
8660 root.
8661 Defaults to @samp{"</etc/dovecot/private/default.pem"}.
8662 @end deftypevr
8663
8664 @deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
8665 If key file is password protected, give the password here.
8666 Alternatively give it when starting dovecot with -p parameter. Since
8667 this file is often world-readable, you may want to place this setting
8668 instead to a different.
8669 Defaults to @samp{""}.
8670 @end deftypevr
8671
8672 @deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
8673 PEM encoded trusted certificate authority. Set this only if you
8674 intend to use @samp{ssl-verify-client-cert? #t}. The file should
8675 contain the CA certificate(s) followed by the matching
8676 CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
8677 Defaults to @samp{""}.
8678 @end deftypevr
8679
8680 @deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
8681 Require that CRL check succeeds for client certificates.
8682 Defaults to @samp{#t}.
8683 @end deftypevr
8684
8685 @deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
8686 Request client to send a certificate. If you also want to require
8687 it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
8688 Defaults to @samp{#f}.
8689 @end deftypevr
8690
8691 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
8692 Which field from certificate to use for username. commonName and
8693 x500UniqueIdentifier are the usual choices. You'll also need to set
8694 @samp{auth-ssl-username-from-cert? #t}.
8695 Defaults to @samp{"commonName"}.
8696 @end deftypevr
8697
8698 @deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
8699 How often to regenerate the SSL parameters file. Generation is
8700 quite CPU intensive operation. The value is in hours, 0 disables
8701 regeneration entirely.
8702 Defaults to @samp{168}.
8703 @end deftypevr
8704
8705 @deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
8706 SSL protocols to use.
8707 Defaults to @samp{"!SSLv2"}.
8708 @end deftypevr
8709
8710 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
8711 SSL ciphers to use.
8712 Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
8713 @end deftypevr
8714
8715 @deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
8716 SSL crypto device to use, for valid values run "openssl engine".
8717 Defaults to @samp{""}.
8718 @end deftypevr
8719
8720 @deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
8721 Address to use when sending rejection mails.
8722 Default is postmaster@@<your domain>. %d expands to recipient domain.
8723 Defaults to @samp{""}.
8724 @end deftypevr
8725
8726 @deftypevr {@code{dovecot-configuration} parameter} string hostname
8727 Hostname to use in various parts of sent mails (e.g. in Message-Id)
8728 and in LMTP replies. Default is the system's real hostname@@domain.
8729 Defaults to @samp{""}.
8730 @end deftypevr
8731
8732 @deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
8733 If user is over quota, return with temporary failure instead of
8734 bouncing the mail.
8735 Defaults to @samp{#f}.
8736 @end deftypevr
8737
8738 @deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
8739 Binary to use for sending mails.
8740 Defaults to @samp{"/usr/sbin/sendmail"}.
8741 @end deftypevr
8742
8743 @deftypevr {@code{dovecot-configuration} parameter} string submission-host
8744 If non-empty, send mails via this SMTP host[:port] instead of
8745 sendmail.
8746 Defaults to @samp{""}.
8747 @end deftypevr
8748
8749 @deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
8750 Subject: header to use for rejection mails. You can use the same
8751 variables as for @samp{rejection-reason} below.
8752 Defaults to @samp{"Rejected: %s"}.
8753 @end deftypevr
8754
8755 @deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
8756 Human readable error message for rejection mails. You can use
8757 variables:
8758
8759 @table @code
8760 @item %n
8761 CRLF
8762 @item %r
8763 reason
8764 @item %s
8765 original subject
8766 @item %t
8767 recipient
8768 @end table
8769 Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
8770 @end deftypevr
8771
8772 @deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
8773 Delimiter character between local-part and detail in email
8774 address.
8775 Defaults to @samp{"+"}.
8776 @end deftypevr
8777
8778 @deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
8779 Header where the original recipient address (SMTP's RCPT TO:
8780 address) is taken from if not available elsewhere. With dovecot-lda -a
8781 parameter overrides this. A commonly used header for this is
8782 X-Original-To.
8783 Defaults to @samp{""}.
8784 @end deftypevr
8785
8786 @deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
8787 Should saving a mail to a nonexistent mailbox automatically create
8788 it?.
8789 Defaults to @samp{#f}.
8790 @end deftypevr
8791
8792 @deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
8793 Should automatically created mailboxes be also automatically
8794 subscribed?.
8795 Defaults to @samp{#f}.
8796 @end deftypevr
8797
8798 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
8799 Maximum IMAP command line length. Some clients generate very long
8800 command lines with huge mailboxes, so you may need to raise this if you
8801 get "Too long argument" or "IMAP command line too large" errors
8802 often.
8803 Defaults to @samp{64000}.
8804 @end deftypevr
8805
8806 @deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
8807 IMAP logout format string:
8808 @table @code
8809 @item %i
8810 total number of bytes read from client
8811 @item %o
8812 total number of bytes sent to client.
8813 @end table
8814 Defaults to @samp{"in=%i out=%o"}.
8815 @end deftypevr
8816
8817 @deftypevr {@code{dovecot-configuration} parameter} string imap-capability
8818 Override the IMAP CAPABILITY response. If the value begins with '+',
8819 add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
8820 Defaults to @samp{""}.
8821 @end deftypevr
8822
8823 @deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
8824 How long to wait between "OK Still here" notifications when client
8825 is IDLEing.
8826 Defaults to @samp{"2 mins"}.
8827 @end deftypevr
8828
8829 @deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
8830 ID field names and values to send to clients. Using * as the value
8831 makes Dovecot use the default value. The following fields have default
8832 values currently: name, version, os, os-version, support-url,
8833 support-email.
8834 Defaults to @samp{""}.
8835 @end deftypevr
8836
8837 @deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
8838 ID fields sent by client to log. * means everything.
8839 Defaults to @samp{""}.
8840 @end deftypevr
8841
8842 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
8843 Workarounds for various client bugs:
8844
8845 @table @code
8846 @item delay-newmail
8847 Send EXISTS/RECENT new mail notifications only when replying to NOOP and
8848 CHECK commands. Some clients ignore them otherwise, for example OSX
8849 Mail (<v2.1). Outlook Express breaks more badly though, without this it
8850 may show user "Message no longer in server" errors. Note that OE6
8851 still breaks even with this workaround if synchronization is set to
8852 "Headers Only".
8853
8854 @item tb-extra-mailbox-sep
8855 Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
8856 adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
8857 ignore the extra @samp{/} instead of treating it as invalid mailbox name.
8858
8859 @item tb-lsub-flags
8860 Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
8861 This makes Thunderbird realize they aren't selectable and show them
8862 greyed out, instead of only later giving "not selectable" popup error.
8863 @end table
8864 Defaults to @samp{()}.
8865 @end deftypevr
8866
8867 @deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
8868 Host allowed in URLAUTH URLs sent by client. "*" allows all.
8869 Defaults to @samp{""}.
8870 @end deftypevr
8871
8872
8873 Whew! Lots of configuration options. The nice thing about it though is
8874 that GuixSD has a complete interface to Dovecot's configuration
8875 language. This allows not only a nice way to declare configurations,
8876 but also offers reflective capabilities as well: users can write code to
8877 inspect and transform configurations from within Scheme.
8878
8879 However, it could be that you just want to get a @code{dovecot.conf} up
8880 and running. In that case, you can pass an
8881 @code{opaque-dovecot-configuration} as the @code{#:config} paramter to
8882 @code{dovecot-service}. As its name indicates, an opaque configuration
8883 does not have easy reflective capabilities.
8884
8885 Available @code{opaque-dovecot-configuration} fields are:
8886
8887 @deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
8888 The dovecot package.
8889 @end deftypevr
8890
8891 @deftypevr {@code{opaque-dovecot-configuration} parameter} string string
8892 The contents of the @code{dovecot.conf}, as a string.
8893 @end deftypevr
8894
8895 For example, if your @code{dovecot.conf} is just the empty string, you
8896 could instantiate a dovecot service like this:
8897
8898 @example
8899 (dovecot-service #:config
8900 (opaque-dovecot-configuration
8901 (string "")))
8902 @end example
8903
8904 @node Web Services
8905 @subsubsection Web Services
8906
8907 The @code{(gnu services web)} module provides the following service:
8908
8909 @deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
8910 [#:log-directory ``/var/log/nginx''] @
8911 [#:run-directory ``/var/run/nginx''] @
8912 [#:config-file]
8913
8914 Return a service that runs @var{nginx}, the nginx web server.
8915
8916 The nginx daemon loads its runtime configuration from @var{config-file}.
8917 Log files are written to @var{log-directory} and temporary runtime data
8918 files are written to @var{run-directory}. For proper operation, these
8919 arguments should match what is in @var{config-file} to ensure that the
8920 directories are created when the service is activated.
8921
8922 @end deffn
8923
8924 @node Various Services
8925 @subsubsection Various Services
8926
8927 The @code{(gnu services lirc)} module provides the following service.
8928
8929 @deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
8930 [#:device #f] [#:driver #f] [#:config-file #f] @
8931 [#:extra-options '()]
8932 Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
8933 decodes infrared signals from remote controls.
8934
8935 Optionally, @var{device}, @var{driver} and @var{config-file}
8936 (configuration file name) may be specified. See @command{lircd} manual
8937 for details.
8938
8939 Finally, @var{extra-options} is a list of additional command-line options
8940 passed to @command{lircd}.
8941 @end deffn
8942
8943
8944 @node Setuid Programs
8945 @subsection Setuid Programs
8946
8947 @cindex setuid programs
8948 Some programs need to run with ``root'' privileges, even when they are
8949 launched by unprivileged users. A notorious example is the
8950 @command{passwd} program, which users can run to change their
8951 password, and which needs to access the @file{/etc/passwd} and
8952 @file{/etc/shadow} files---something normally restricted to root, for
8953 obvious security reasons. To address that, these executables are
8954 @dfn{setuid-root}, meaning that they always run with root privileges
8955 (@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
8956 for more info about the setuid mechanism.)
8957
8958 The store itself @emph{cannot} contain setuid programs: that would be a
8959 security issue since any user on the system can write derivations that
8960 populate the store (@pxref{The Store}). Thus, a different mechanism is
8961 used: instead of changing the setuid bit directly on files that are in
8962 the store, we let the system administrator @emph{declare} which programs
8963 should be setuid root.
8964
8965 The @code{setuid-programs} field of an @code{operating-system}
8966 declaration contains a list of G-expressions denoting the names of
8967 programs to be setuid-root (@pxref{Using the Configuration System}).
8968 For instance, the @command{passwd} program, which is part of the Shadow
8969 package, can be designated by this G-expression (@pxref{G-Expressions}):
8970
8971 @example
8972 #~(string-append #$shadow "/bin/passwd")
8973 @end example
8974
8975 A default set of setuid programs is defined by the
8976 @code{%setuid-programs} variable of the @code{(gnu system)} module.
8977
8978 @defvr {Scheme Variable} %setuid-programs
8979 A list of G-expressions denoting common programs that are setuid-root.
8980
8981 The list includes commands such as @command{passwd}, @command{ping},
8982 @command{su}, and @command{sudo}.
8983 @end defvr
8984
8985 Under the hood, the actual setuid programs are created in the
8986 @file{/run/setuid-programs} directory at system activation time. The
8987 files in this directory refer to the ``real'' binaries, which are in the
8988 store.
8989
8990 @node X.509 Certificates
8991 @subsection X.509 Certificates
8992
8993 @cindex HTTPS, certificates
8994 @cindex X.509 certificates
8995 @cindex TLS
8996 Web servers available over HTTPS (that is, HTTP over the transport-layer
8997 security mechanism, TLS) send client programs an @dfn{X.509 certificate}
8998 that the client can then use to @emph{authenticate} the server. To do
8999 that, clients verify that the server's certificate is signed by a
9000 so-called @dfn{certificate authority} (CA). But to verify the CA's
9001 signature, clients must have first acquired the CA's certificate.
9002
9003 Web browsers such as GNU@tie{}IceCat include their own set of CA
9004 certificates, such that they are able to verify CA signatures
9005 out-of-the-box.
9006
9007 However, most other programs that can talk HTTPS---@command{wget},
9008 @command{git}, @command{w3m}, etc.---need to be told where CA
9009 certificates can be found.
9010
9011 @cindex @code{nss-certs}
9012 In GuixSD, this is done by adding a package that provides certificates
9013 to the @code{packages} field of the @code{operating-system} declaration
9014 (@pxref{operating-system Reference}). GuixSD includes one such package,
9015 @code{nss-certs}, which is a set of CA certificates provided as part of
9016 Mozilla's Network Security Services.
9017
9018 Note that it is @emph{not} part of @var{%base-packages}, so you need to
9019 explicitly add it. The @file{/etc/ssl/certs} directory, which is where
9020 most applications and libraries look for certificates by default, points
9021 to the certificates installed globally.
9022
9023 Unprivileged users can also install their own certificate package in
9024 their profile. A number of environment variables need to be defined so
9025 that applications and libraries know where to find them. Namely, the
9026 OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
9027 variables. Some applications add their own environment variables; for
9028 instance, the Git version control system honors the certificate bundle
9029 pointed to by the @code{GIT_SSL_CAINFO} environment variable.
9030
9031
9032 @node Name Service Switch
9033 @subsection Name Service Switch
9034
9035 @cindex name service switch
9036 @cindex NSS
9037 The @code{(gnu system nss)} module provides bindings to the
9038 configuration file of libc's @dfn{name service switch} or @dfn{NSS}
9039 (@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
9040 Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
9041 extended with new ``name'' lookup methods for system databases, which
9042 includes host names, service names, user accounts, and more (@pxref{Name
9043 Service Switch, System Databases and Name Service Switch,, libc, The GNU
9044 C Library Reference Manual}).
9045
9046 The NSS configuration specifies, for each system database, which lookup
9047 method is to be used, and how the various methods are chained
9048 together---for instance, under which circumstances NSS should try the
9049 next method in the list. The NSS configuration is given in the
9050 @code{name-service-switch} field of @code{operating-system} declarations
9051 (@pxref{operating-system Reference, @code{name-service-switch}}).
9052
9053 @cindex nss-mdns
9054 @cindex .local, host name lookup
9055 As an example, the declaration below configures the NSS to use the
9056 @uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
9057 back-end}, which supports host name lookups over multicast DNS (mDNS)
9058 for host names ending in @code{.local}:
9059
9060 @example
9061 (name-service-switch
9062 (hosts (list %files ;first, check /etc/hosts
9063
9064 ;; If the above did not succeed, try
9065 ;; with 'mdns_minimal'.
9066 (name-service
9067 (name "mdns_minimal")
9068
9069 ;; 'mdns_minimal' is authoritative for
9070 ;; '.local'. When it returns "not found",
9071 ;; no need to try the next methods.
9072 (reaction (lookup-specification
9073 (not-found => return))))
9074
9075 ;; Then fall back to DNS.
9076 (name-service
9077 (name "dns"))
9078
9079 ;; Finally, try with the "full" 'mdns'.
9080 (name-service
9081 (name "mdns")))))
9082 @end example
9083
9084 Don't worry: the @code{%mdns-host-lookup-nss} variable (see below)
9085 contains this configuration, so you won't have to type it if all you
9086 want is to have @code{.local} host lookup working.
9087
9088 Note that, in this case, in addition to setting the
9089 @code{name-service-switch} of the @code{operating-system} declaration,
9090 you also need to use @code{avahi-service} (@pxref{Networking Services,
9091 @code{avahi-service}}), or @var{%desktop-services}, which includes it
9092 (@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
9093 to the name service cache daemon (@pxref{Base Services,
9094 @code{nscd-service}}).
9095
9096 For convenience, the following variables provide typical NSS
9097 configurations.
9098
9099 @defvr {Scheme Variable} %default-nss
9100 This is the default name service switch configuration, a
9101 @code{name-service-switch} object.
9102 @end defvr
9103
9104 @defvr {Scheme Variable} %mdns-host-lookup-nss
9105 This is the name service switch configuration with support for host name
9106 lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
9107 @end defvr
9108
9109 The reference for name service switch configuration is given below. It
9110 is a direct mapping of the C library's configuration file format, so
9111 please refer to the C library manual for more information (@pxref{NSS
9112 Configuration File,,, libc, The GNU C Library Reference Manual}).
9113 Compared to libc's NSS configuration file format, it has the advantage
9114 not only of adding this warm parenthetic feel that we like, but also
9115 static checks: you'll know about syntax errors and typos as soon as you
9116 run @command{guix system}.
9117
9118 @deftp {Data Type} name-service-switch
9119
9120 This is the data type representation the configuration of libc's name
9121 service switch (NSS). Each field below represents one of the supported
9122 system databases.
9123
9124 @table @code
9125 @item aliases
9126 @itemx ethers
9127 @itemx group
9128 @itemx gshadow
9129 @itemx hosts
9130 @itemx initgroups
9131 @itemx netgroup
9132 @itemx networks
9133 @itemx password
9134 @itemx public-key
9135 @itemx rpc
9136 @itemx services
9137 @itemx shadow
9138 The system databases handled by the NSS. Each of these fields must be a
9139 list of @code{<name-service>} objects (see below.)
9140 @end table
9141 @end deftp
9142
9143 @deftp {Data Type} name-service
9144
9145 This is the data type representing an actual name service and the
9146 associated lookup action.
9147
9148 @table @code
9149 @item name
9150 A string denoting the name service (@pxref{Services in the NSS
9151 configuration,,, libc, The GNU C Library Reference Manual}).
9152
9153 Note that name services listed here must be visible to nscd. This is
9154 achieved by passing the @code{#:name-services} argument to
9155 @code{nscd-service} the list of packages providing the needed name
9156 services (@pxref{Base Services, @code{nscd-service}}).
9157
9158 @item reaction
9159 An action specified using the @code{lookup-specification} macro
9160 (@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
9161 Reference Manual}). For example:
9162
9163 @example
9164 (lookup-specification (unavailable => continue)
9165 (success => return))
9166 @end example
9167 @end table
9168 @end deftp
9169
9170 @node Initial RAM Disk
9171 @subsection Initial RAM Disk
9172
9173 @cindex initial RAM disk (initrd)
9174 @cindex initrd (initial RAM disk)
9175 For bootstrapping purposes, the Linux-Libre kernel is passed an
9176 @dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
9177 root file system, as well as an initialization script. The latter is
9178 responsible for mounting the real root file system, and for loading any
9179 kernel modules that may be needed to achieve that.
9180
9181 The @code{initrd} field of an @code{operating-system} declaration allows
9182 you to specify which initrd you would like to use. The @code{(gnu
9183 system linux-initrd)} module provides two ways to build an initrd: the
9184 high-level @code{base-initrd} procedure, and the low-level
9185 @code{expression->initrd} procedure.
9186
9187 The @code{base-initrd} procedure is intended to cover most common uses.
9188 For example, if you want to add a bunch of kernel modules to be loaded
9189 at boot time, you can define the @code{initrd} field of the operating
9190 system declaration like this:
9191
9192 @example
9193 (initrd (lambda (file-systems . rest)
9194 ;; Create a standard initrd that has modules "foo.ko"
9195 ;; and "bar.ko", as well as their dependencies, in
9196 ;; addition to the modules available by default.
9197 (apply base-initrd file-systems
9198 #:extra-modules '("foo" "bar")
9199 rest)))
9200 @end example
9201
9202 The @code{base-initrd} procedure also handles common use cases that
9203 involves using the system as a QEMU guest, or as a ``live'' system whose
9204 root file system is volatile.
9205
9206 The initial RAM disk produced by @code{base-initrd} honors several
9207 options passed on the Linux kernel command line (that is, arguments
9208 passed @i{via} GRUB's @code{linux} command, or with QEMU's
9209 @code{-append} option), notably:
9210
9211 @table @code
9212 @item --load=@var{boot}
9213 Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
9214 program, once it has mounted the root file system.
9215
9216 GuixSD uses this option to yield control to a boot program that runs the
9217 service activation programs and then spawns the GNU@tie{}Shepherd, the
9218 initialization system.
9219
9220 @item --root=@var{root}
9221 Mount @var{root} as the root file system. @var{root} can be a device
9222 device name like @code{/dev/sda1}, a partition label, or a partition
9223 UUID.
9224
9225 @item --system=@var{system}
9226 Have @file{/run/booted-system} and @file{/run/current-system} point to
9227 @var{system}.
9228
9229 @item modprobe.blacklist=@var{modules}@dots{}
9230 @cindex module, black-listing
9231 @cindex black list, of kernel modules
9232 Instruct the initial RAM disk as well as the @command{modprobe} command
9233 (from the kmod package) to refuse to load @var{modules}. @var{modules}
9234 must be a comma-separated list of module names---e.g.,
9235 @code{usbkbd,9pnet}.
9236
9237 @item --repl
9238 Start a read-eval-print loop (REPL) from the initial RAM disk before it
9239 tries to load kernel modules and to mount the root file system. Our
9240 marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
9241 love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
9242 Manual}, for more information on Guile's REPL.
9243
9244 @end table
9245
9246 Now that you know all the features that initial RAM disks produced by
9247 @code{base-initrd} provide, here is how to use it and customize it
9248 further.
9249
9250 @deffn {Monadic Procedure} base-initrd @var{file-systems} @
9251 [#:qemu-networking? #f] [#:virtio? #t] [#:volatile-root? #f] @
9252 [#:extra-modules '()] [#:mapped-devices '()]
9253 Return a monadic derivation that builds a generic initrd. @var{file-systems} is
9254 a list of file-systems to be mounted by the initrd, possibly in addition to
9255 the root file system specified on the kernel command line via @code{--root}.
9256 @var{mapped-devices} is a list of device mappings to realize before
9257 @var{file-systems} are mounted (@pxref{Mapped Devices}).
9258
9259 When @var{qemu-networking?} is true, set up networking with the standard QEMU
9260 parameters. When @var{virtio?} is true, load additional modules so the initrd can
9261 be used as a QEMU guest with para-virtualized I/O drivers.
9262
9263 When @var{volatile-root?} is true, the root file system is writable but any changes
9264 to it are lost.
9265
9266 The initrd is automatically populated with all the kernel modules necessary
9267 for @var{file-systems} and for the given options. However, additional kernel
9268 modules can be listed in @var{extra-modules}. They will be added to the initrd, and
9269 loaded at boot time in the order in which they appear.
9270 @end deffn
9271
9272 Needless to say, the initrds we produce and use embed a
9273 statically-linked Guile, and the initialization program is a Guile
9274 program. That gives a lot of flexibility. The
9275 @code{expression->initrd} procedure builds such an initrd, given the
9276 program to run in that initrd.
9277
9278 @deffn {Monadic Procedure} expression->initrd @var{exp} @
9279 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
9280 [#:modules '()]
9281 Return a derivation that builds a Linux initrd (a gzipped cpio archive)
9282 containing @var{guile} and that evaluates @var{exp}, a G-expression,
9283 upon booting. All the derivations referenced by @var{exp} are
9284 automatically copied to the initrd.
9285
9286 @var{modules} is a list of Guile module names to be embedded in the
9287 initrd.
9288 @end deffn
9289
9290 @node GRUB Configuration
9291 @subsection GRUB Configuration
9292
9293 @cindex GRUB
9294 @cindex boot loader
9295
9296 The operating system uses GNU@tie{}GRUB as its boot loader
9297 (@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
9298 configured using @code{grub-configuration} declarations. This data type
9299 is exported by the @code{(gnu system grub)} module, and described below.
9300
9301 @deftp {Data Type} grub-configuration
9302 The type of a GRUB configuration declaration.
9303
9304 @table @asis
9305
9306 @item @code{device}
9307 This is a string denoting the boot device. It must be a device name
9308 understood by the @command{grub-install} command, such as
9309 @code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
9310 GNU GRUB Manual}).
9311
9312 @item @code{menu-entries} (default: @code{()})
9313 A possibly empty list of @code{menu-entry} objects (see below), denoting
9314 entries to appear in the GRUB boot menu, in addition to the current
9315 system entry and the entry pointing to previous system generations.
9316
9317 @item @code{default-entry} (default: @code{0})
9318 The index of the default boot menu entry. Index 0 is for the current
9319 system's entry.
9320
9321 @item @code{timeout} (default: @code{5})
9322 The number of seconds to wait for keyboard input before booting. Set to
9323 0 to boot immediately, and to -1 to wait indefinitely.
9324
9325 @item @code{theme} (default: @var{%default-theme})
9326 The @code{grub-theme} object describing the theme to use.
9327 @end table
9328
9329 @end deftp
9330
9331 Should you want to list additional boot menu entries @i{via} the
9332 @code{menu-entries} field above, you will need to create them with the
9333 @code{menu-entry} form:
9334
9335 @deftp {Data Type} menu-entry
9336 The type of an entry in the GRUB boot menu.
9337
9338 @table @asis
9339
9340 @item @code{label}
9341 The label to show in the menu---e.g., @code{"GNU"}.
9342
9343 @item @code{linux}
9344 The Linux kernel to boot.
9345
9346 @item @code{linux-arguments} (default: @code{()})
9347 The list of extra Linux kernel command-line arguments---e.g.,
9348 @code{("console=ttyS0")}.
9349
9350 @item @code{initrd}
9351 A G-Expression or string denoting the file name of the initial RAM disk
9352 to use (@pxref{G-Expressions}).
9353
9354 @end table
9355 @end deftp
9356
9357 @c FIXME: Write documentation once it's stable.
9358 Themes are created using the @code{grub-theme} form, which is not
9359 documented yet.
9360
9361 @defvr {Scheme Variable} %default-theme
9362 This is the default GRUB theme used by the operating system, with a
9363 fancy background image displaying the GNU and Guix logos.
9364 @end defvr
9365
9366
9367 @node Invoking guix system
9368 @subsection Invoking @code{guix system}
9369
9370 Once you have written an operating system declaration, as seen in the
9371 previous section, it can be @dfn{instantiated} using the @command{guix
9372 system} command. The synopsis is:
9373
9374 @example
9375 guix system @var{options}@dots{} @var{action} @var{file}
9376 @end example
9377
9378 @var{file} must be the name of a file containing an
9379 @code{operating-system} declaration. @var{action} specifies how the
9380 operating system is instantiated. Currently the following values are
9381 supported:
9382
9383 @table @code
9384 @item reconfigure
9385 Build the operating system described in @var{file}, activate it, and
9386 switch to it@footnote{This action is usable only on systems already
9387 running GuixSD.}.
9388
9389 This effects all the configuration specified in @var{file}: user
9390 accounts, system services, global package list, setuid programs, etc.
9391 The command starts system services specified in @var{file} that are not
9392 currently running; if a service is currently running, it does not
9393 attempt to upgrade it since it would not be possible without stopping it
9394 first.
9395
9396 It also adds a GRUB menu entry for the new OS configuration, and moves
9397 entries for older configurations to a submenu---unless
9398 @option{--no-grub} is passed.
9399
9400 @quotation Note
9401 @c The paragraph below refers to the problem discussed at
9402 @c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
9403 It is highly recommended to run @command{guix pull} once before you run
9404 @command{guix system reconfigure} for the first time (@pxref{Invoking
9405 guix pull}). Failing to do that you would see an older version of Guix
9406 once @command{reconfigure} has completed.
9407 @end quotation
9408
9409 @item build
9410 Build the operating system's derivation, which includes all the
9411 configuration files and programs needed to boot and run the system.
9412 This action does not actually install anything.
9413
9414 @item init
9415 Populate the given directory with all the files necessary to run the
9416 operating system specified in @var{file}. This is useful for first-time
9417 installations of GuixSD. For instance:
9418
9419 @example
9420 guix system init my-os-config.scm /mnt
9421 @end example
9422
9423 copies to @file{/mnt} all the store items required by the configuration
9424 specified in @file{my-os-config.scm}. This includes configuration
9425 files, packages, and so on. It also creates other essential files
9426 needed for the system to operate correctly---e.g., the @file{/etc},
9427 @file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
9428
9429 This command also installs GRUB on the device specified in
9430 @file{my-os-config}, unless the @option{--no-grub} option was passed.
9431
9432 @item vm
9433 @cindex virtual machine
9434 @cindex VM
9435 @anchor{guix system vm}
9436 Build a virtual machine that contain the operating system declared in
9437 @var{file}, and return a script to run that virtual machine (VM).
9438 Arguments given to the script are passed as is to QEMU.
9439
9440 The VM shares its store with the host system.
9441
9442 Additional file systems can be shared between the host and the VM using
9443 the @code{--share} and @code{--expose} command-line options: the former
9444 specifies a directory to be shared with write access, while the latter
9445 provides read-only access to the shared directory.
9446
9447 The example below creates a VM in which the user's home directory is
9448 accessible read-only, and where the @file{/exchange} directory is a
9449 read-write mapping of the host's @file{$HOME/tmp}:
9450
9451 @example
9452 guix system vm my-config.scm \
9453 --expose=$HOME --share=$HOME/tmp=/exchange
9454 @end example
9455
9456 On GNU/Linux, the default is to boot directly to the kernel; this has
9457 the advantage of requiring only a very tiny root disk image since the
9458 host's store can then be mounted.
9459
9460 The @code{--full-boot} option forces a complete boot sequence, starting
9461 with the bootloader. This requires more disk space since a root image
9462 containing at least the kernel, initrd, and bootloader data files must
9463 be created. The @code{--image-size} option can be used to specify the
9464 image's size.
9465
9466 @item vm-image
9467 @itemx disk-image
9468 Return a virtual machine or disk image of the operating system declared
9469 in @var{file} that stands alone. Use the @option{--image-size} option
9470 to specify the size of the image.
9471
9472 When using @code{vm-image}, the returned image is in qcow2 format, which
9473 the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
9474 for more information on how to run the image in a virtual machine.
9475
9476 When using @code{disk-image}, a raw disk image is produced; it can be
9477 copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
9478 the device corresponding to a USB stick, one can copy the image on it
9479 using the following command:
9480
9481 @example
9482 # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
9483 @end example
9484
9485 @item container
9486 Return a script to run the operating system declared in @var{file}
9487 within a container. Containers are a set of lightweight isolation
9488 mechanisms provided by the kernel Linux-libre. Containers are
9489 substantially less resource-demanding than full virtual machines since
9490 the kernel, shared objects, and other resources can be shared with the
9491 host system; this also means they provide thinner isolation.
9492
9493 Currently, the script must be run as root in order to support more than
9494 a single user and group. The container shares its store with the host
9495 system.
9496
9497 As with the @code{vm} action (@pxref{guix system vm}), additional file
9498 systems to be shared between the host and container can be specified
9499 using the @option{--share} and @option{--expose} options:
9500
9501 @example
9502 guix system container my-config.scm \
9503 --expose=$HOME --share=$HOME/tmp=/exchange
9504 @end example
9505
9506 @quotation Note
9507 This option requires Linux-libre 3.19 or newer.
9508 @end quotation
9509
9510 @end table
9511
9512 @var{options} can contain any of the common build options (@pxref{Common
9513 Build Options}). In addition, @var{options} can contain one of the
9514 following:
9515
9516 @table @option
9517 @item --system=@var{system}
9518 @itemx -s @var{system}
9519 Attempt to build for @var{system} instead of the host's system type.
9520 This works as per @command{guix build} (@pxref{Invoking guix build}).
9521
9522 @item --derivation
9523 @itemx -d
9524 Return the derivation file name of the given operating system without
9525 building anything.
9526
9527 @item --image-size=@var{size}
9528 For the @code{vm-image} and @code{disk-image} actions, create an image
9529 of the given @var{size}. @var{size} may be a number of bytes, or it may
9530 include a unit as a suffix (@pxref{Block size, size specifications,,
9531 coreutils, GNU Coreutils}).
9532
9533 @item --on-error=@var{strategy}
9534 Apply @var{strategy} when an error occurs when reading @var{file}.
9535 @var{strategy} may be one of the following:
9536
9537 @table @code
9538 @item nothing-special
9539 Report the error concisely and exit. This is the default strategy.
9540
9541 @item backtrace
9542 Likewise, but also display a backtrace.
9543
9544 @item debug
9545 Report the error and enter Guile's debugger. From there, you can run
9546 commands such as @code{,bt} to get a backtrace, @code{,locals} to
9547 display local variable values, and more generally inspect the program's
9548 state. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
9549 a list of available debugging commands.
9550 @end table
9551 @end table
9552
9553 Note that all the actions above, except @code{build} and @code{init},
9554 rely on KVM support in the Linux-Libre kernel. Specifically, the
9555 machine should have hardware virtualization support, the corresponding
9556 KVM kernel module should be loaded, and the @file{/dev/kvm} device node
9557 must exist and be readable and writable by the user and by the daemon's
9558 build users.
9559
9560 Once you have built, configured, re-configured, and re-re-configured
9561 your GuixSD installation, you may find it useful to list the operating
9562 system generations available on disk---and that you can choose from the
9563 GRUB boot menu:
9564
9565 @table @code
9566
9567 @item list-generations
9568 List a summary of each generation of the operating system available on
9569 disk, in a human-readable way. This is similar to the
9570 @option{--list-generations} option of @command{guix package}
9571 (@pxref{Invoking guix package}).
9572
9573 Optionally, one can specify a pattern, with the same syntax that is used
9574 in @command{guix package --list-generations}, to restrict the list of
9575 generations displayed. For instance, the following command displays
9576 generations up to 10-day old:
9577
9578 @example
9579 $ guix system list-generations 10d
9580 @end example
9581
9582 @end table
9583
9584 The @command{guix system} command has even more to offer! The following
9585 sub-commands allow you to visualize how your system services relate to
9586 each other:
9587
9588 @anchor{system-extension-graph}
9589 @table @code
9590
9591 @item extension-graph
9592 Emit in Dot/Graphviz format to standard output the @dfn{service
9593 extension graph} of the operating system defined in @var{file}
9594 (@pxref{Service Composition}, for more information on service
9595 extensions.)
9596
9597 The command:
9598
9599 @example
9600 $ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
9601 @end example
9602
9603 produces a PDF file showing the extension relations among services.
9604
9605 @anchor{system-shepherd-graph}
9606 @item shepherd-graph
9607 Emit in Dot/Graphviz format to standard output the @dfn{dependency
9608 graph} of shepherd services of the operating system defined in
9609 @var{file}. @xref{Shepherd Services}, for more information and for an
9610 example graph.
9611
9612 @end table
9613
9614 @node Running GuixSD in a VM
9615 @subsection Running GuixSD in a Virtual Machine
9616
9617 One way to run GuixSD in a virtual machine (VM) is to build a GuixSD
9618 virtual machine image using @command{guix system vm-image}
9619 (@pxref{Invoking guix system}). The returned image is in qcow2 format,
9620 which the @uref{http://qemu.org/, QEMU emulator} can efficiently use.
9621
9622 To run the image in QEMU, copy it out of the store (@pxref{The Store})
9623 and give yourself permission to write to the copy. When invoking QEMU,
9624 you must choose a system emulator that is suitable for your hardware
9625 platform. Here is a minimal QEMU invocation that will boot the result
9626 of @command{guix system vm-image} on x86_64 hardware:
9627
9628 @example
9629 $ qemu-system-x86_64 \
9630 -net user -net nic,model=virtio \
9631 -enable-kvm -m 256 /tmp/qemu-image
9632 @end example
9633
9634 Here is what each of these options means:
9635
9636 @table @code
9637 @item qemu-system-x86_64
9638 This specifies the hardware platform to emulate. This should match the
9639 host.
9640
9641 @item -net user
9642 Enable the unprivileged user-mode network stack. The guest OS can
9643 access the host but not vice versa. This is the simplest way to get the
9644 guest OS online. If you don't choose a network stack, the boot will
9645 fail.
9646
9647 @item -net nic,model=virtio
9648 You must create a network interface of a given model. If you don't
9649 create a NIC, the boot will fail. Assuming your hardware platform is
9650 x86_64, you can get a list of available NIC models by running
9651 @command{qemu-system-x86_64 -net nic,model=help}.
9652
9653 @item -enable-kvm
9654 If your system has hardware virtualization extensions, enabling the
9655 Linux kernel's virtual machine support (KVM) will make things run
9656 faster.
9657
9658 @item -m 256
9659 RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
9660 which may be insufficent for some operations.
9661
9662 @item /tmp/qemu-image
9663 The file name of the qcow2 image.
9664 @end table
9665
9666 @node Defining Services
9667 @subsection Defining Services
9668
9669 The previous sections show the available services and how one can combine
9670 them in an @code{operating-system} declaration. But how do we define
9671 them in the first place? And what is a service anyway?
9672
9673 @menu
9674 * Service Composition:: The model for composing services.
9675 * Service Types and Services:: Types and services.
9676 * Service Reference:: API reference.
9677 * Shepherd Services:: A particular type of service.
9678 @end menu
9679
9680 @node Service Composition
9681 @subsubsection Service Composition
9682
9683 @cindex services
9684 @cindex daemons
9685 Here we define a @dfn{service} as, broadly, something that extends the
9686 operating system's functionality. Often a service is a process---a
9687 @dfn{daemon}---started when the system boots: a secure shell server, a
9688 Web server, the Guix build daemon, etc. Sometimes a service is a daemon
9689 whose execution can be triggered by another daemon---e.g., an FTP server
9690 started by @command{inetd} or a D-Bus service activated by
9691 @command{dbus-daemon}. Occasionally, a service does not map to a
9692 daemon. For instance, the ``account'' service collects user accounts
9693 and makes sure they exist when the system runs; the ``udev'' service
9694 collects device management rules and makes them available to the eudev
9695 daemon; the @file{/etc} service populates the system's @file{/etc}
9696 directory.
9697
9698 @cindex service extensions
9699 GuixSD services are connected by @dfn{extensions}. For instance, the
9700 secure shell service @emph{extends} the Shepherd---GuixSD's
9701 initialization system, running as PID@tie{}1---by giving it the command
9702 lines to start and stop the secure shell daemon (@pxref{Networking
9703 Services, @code{lsh-service}}); the UPower service extends the D-Bus
9704 service by passing it its @file{.service} specification, and extends the
9705 udev service by passing it device management rules (@pxref{Desktop
9706 Services, @code{upower-service}}); the Guix daemon service extends the
9707 Shepherd by passing it the command lines to start and stop the daemon,
9708 and extends the account service by passing it a list of required build
9709 user accounts (@pxref{Base Services}).
9710
9711 All in all, services and their ``extends'' relations form a directed
9712 acyclic graph (DAG). If we represent services as boxes and extensions
9713 as arrows, a typical system might provide something like this:
9714
9715 @image{images/service-graph,,5in,Typical service extension graph.}
9716
9717 @cindex system service
9718 At the bottom, we see the @dfn{system service}, which produces the
9719 directory containing everything to run and boot the system, as returned
9720 by the @command{guix system build} command. @xref{Service Reference},
9721 to learn about the other service types shown here.
9722 @xref{system-extension-graph, the @command{guix system extension-graph}
9723 command}, for information on how to generate this representation for a
9724 particular operating system definition.
9725
9726 @cindex service types
9727 Technically, developers can define @dfn{service types} to express these
9728 relations. There can be any number of services of a given type on the
9729 system---for instance, a system running two instances of the GNU secure
9730 shell server (lsh) has two instances of @var{lsh-service-type}, with
9731 different parameters.
9732
9733 The following section describes the programming interface for service
9734 types and services.
9735
9736 @node Service Types and Services
9737 @subsubsection Service Types and Services
9738
9739 A @dfn{service type} is a node in the DAG described above. Let us start
9740 with a simple example, the service type for the Guix build daemon
9741 (@pxref{Invoking guix-daemon}):
9742
9743 @example
9744 (define guix-service-type
9745 (service-type
9746 (name 'guix)
9747 (extensions
9748 (list (service-extension shepherd-root-service-type guix-shepherd-service)
9749 (service-extension account-service-type guix-accounts)
9750 (service-extension activation-service-type guix-activation)))))
9751 @end example
9752
9753 @noindent
9754 It defines a two things:
9755
9756 @enumerate
9757 @item
9758 A name, whose sole purpose is to make inspection and debugging easier.
9759
9760 @item
9761 A list of @dfn{service extensions}, where each extension designates the
9762 target service type and a procedure that, given the service's
9763 parameters, returns a list of object to extend the service of that type.
9764
9765 Every service type has at least one service extension. The only
9766 exception is the @dfn{boot service type}, which is the ultimate service.
9767 @end enumerate
9768
9769 In this example, @var{guix-service-type} extends three services:
9770
9771 @table @var
9772 @item shepherd-root-service-type
9773 The @var{guix-shepherd-service} procedure defines how the Shepherd
9774 service is extended. Namely, it returns a @code{<shepherd-service>}
9775 object that defines how @command{guix-daemon} is started and stopped
9776 (@pxref{Shepherd Services}).
9777
9778 @item account-service-type
9779 This extension for this service is computed by @var{guix-accounts},
9780 which returns a list of @code{user-group} and @code{user-account}
9781 objects representing the build user accounts (@pxref{Invoking
9782 guix-daemon}).
9783
9784 @item activation-service-type
9785 Here @var{guix-activation} is a procedure that returns a gexp, which is
9786 a code snippet to run at ``activation time''---e.g., when the service is
9787 booted.
9788 @end table
9789
9790 A service of this type is instantiated like this:
9791
9792 @example
9793 (service guix-service-type
9794 (guix-configuration
9795 (build-accounts 5)
9796 (use-substitutes? #f)))
9797 @end example
9798
9799 The second argument to the @code{service} form is a value representing
9800 the parameters of this specific service instance.
9801 @xref{guix-configuration-type, @code{guix-configuration}}, for
9802 information about the @code{guix-configuration} data type.
9803
9804 @var{guix-service-type} is quite simple because it extends other
9805 services but is not extensible itself.
9806
9807 @c @subsubsubsection Extensible Service Types
9808
9809 The service type for an @emph{extensible} service looks like this:
9810
9811 @example
9812 (define udev-service-type
9813 (service-type (name 'udev)
9814 (extensions
9815 (list (service-extension shepherd-root-service-type
9816 udev-shepherd-service)))
9817
9818 (compose concatenate) ;concatenate the list of rules
9819 (extend (lambda (config rules)
9820 (match config
9821 (($ <udev-configuration> udev initial-rules)
9822 (udev-configuration
9823 (udev udev) ;the udev package to use
9824 (rules (append initial-rules rules)))))))))
9825 @end example
9826
9827 This is the service type for the
9828 @uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
9829 management daemon}. Compared to the previous example, in addition to an
9830 extension of @var{shepherd-root-service-type}, we see two new fields:
9831
9832 @table @code
9833 @item compose
9834 This is the procedure to @dfn{compose} the list of extensions to
9835 services of this type.
9836
9837 Services can extend the udev service by passing it lists of rules; we
9838 compose those extensions simply by concatenating them.
9839
9840 @item extend
9841 This procedure defines how the service's value is @dfn{extended} with
9842 the composition of the extensions.
9843
9844 Udev extensions are composed into a list of rules, but the udev service
9845 value is itself a @code{<udev-configuration>} record. So here, we
9846 extend that record by appending the list of rules it contains to the
9847 list of contributed rules.
9848 @end table
9849
9850 There can be only one instance of an extensible service type such as
9851 @var{udev-service-type}. If there were more, the
9852 @code{service-extension} specifications would be ambiguous.
9853
9854 Still here? The next section provides a reference of the programming
9855 interface for services.
9856
9857 @node Service Reference
9858 @subsubsection Service Reference
9859
9860 We have seen an overview of service types (@pxref{Service Types and
9861 Services}). This section provides a reference on how to manipulate
9862 services and service types. This interface is provided by the
9863 @code{(gnu services)} module.
9864
9865 @deffn {Scheme Procedure} service @var{type} @var{value}
9866 Return a new service of @var{type}, a @code{<service-type>} object (see
9867 below.) @var{value} can be any object; it represents the parameters of
9868 this particular service instance.
9869 @end deffn
9870
9871 @deffn {Scheme Procedure} service? @var{obj}
9872 Return true if @var{obj} is a service.
9873 @end deffn
9874
9875 @deffn {Scheme Procedure} service-kind @var{service}
9876 Return the type of @var{service}---i.e., a @code{<service-type>} object.
9877 @end deffn
9878
9879 @deffn {Scheme Procedure} service-parameters @var{service}
9880 Return the value associated with @var{service}. It represents its
9881 parameters.
9882 @end deffn
9883
9884 Here is an example of how a service is created and manipulated:
9885
9886 @example
9887 (define s
9888 (service nginx-service-type
9889 (nginx-configuration
9890 (nginx nginx)
9891 (log-directory log-directory)
9892 (run-directory run-directory)
9893 (file config-file))))
9894
9895 (service? s)
9896 @result{} #t
9897
9898 (eq? (service-kind s) nginx-service-type)
9899 @result{} #t
9900 @end example
9901
9902 The @code{modify-services} form provides a handy way to change the
9903 parameters of some of the services of a list such as
9904 @var{%base-services} (@pxref{Base Services, @code{%base-services}}). Of
9905 course, you could always use standard list combinators such as
9906 @code{map} and @code{fold} to do that (@pxref{SRFI-1, List Library,,
9907 guile, GNU Guile Reference Manual}); @code{modify-services} simply
9908 provides a more concise form for this common pattern.
9909
9910 @deffn {Scheme Syntax} modify-services @var{services} @
9911 (@var{type} @var{variable} => @var{body}) @dots{}
9912
9913 Modify the services listed in @var{services} according to the given
9914 clauses. Each clause has the form:
9915
9916 @example
9917 (@var{type} @var{variable} => @var{body})
9918 @end example
9919
9920 where @var{type} is a service type, such as @var{guix-service-type}, and
9921 @var{variable} is an identifier that is bound within @var{body} to the
9922 value of the service of that @var{type}. @xref{Using the Configuration
9923 System}, for an example.
9924
9925 This is a shorthand for:
9926
9927 @example
9928 (map (lambda (service) @dots{}) @var{services})
9929 @end example
9930 @end deffn
9931
9932 Next comes the programming interface for service types. This is
9933 something you want to know when writing new service definitions, but not
9934 necessarily when simply looking for ways to customize your
9935 @code{operating-system} declaration.
9936
9937 @deftp {Data Type} service-type
9938 @cindex service type
9939 This is the representation of a @dfn{service type} (@pxref{Service Types
9940 and Services}).
9941
9942 @table @asis
9943 @item @code{name}
9944 This is a symbol, used only to simplify inspection and debugging.
9945
9946 @item @code{extensions}
9947 A non-empty list of @code{<service-extension>} objects (see below.)
9948
9949 @item @code{compose} (default: @code{#f})
9950 If this is @code{#f}, then the service type denotes services that cannot
9951 be extended---i.e., services that do not receive ``values'' from other
9952 services.
9953
9954 Otherwise, it must be a one-argument procedure. The procedure is called
9955 by @code{fold-services} and is passed a list of values collected from
9956 extensions. It must return a value that is a valid parameter value for
9957 the service instance.
9958
9959 @item @code{extend} (default: @code{#f})
9960 If this is @code{#f}, services of this type cannot be extended.
9961
9962 Otherwise, it must be a two-argument procedure: @code{fold-services}
9963 calls it, passing it the service's initial value as the first argument
9964 and the result of applying @code{compose} to the extension values as the
9965 second argument.
9966 @end table
9967
9968 @xref{Service Types and Services}, for examples.
9969 @end deftp
9970
9971 @deffn {Scheme Procedure} service-extension @var{target-type} @
9972 @var{compute}
9973 Return a new extension for services of type @var{target-type}.
9974 @var{compute} must be a one-argument procedure: @code{fold-services}
9975 calls it, passing it the value associated with the service that provides
9976 the extension; it must return a valid value for the target service.
9977 @end deffn
9978
9979 @deffn {Scheme Procedure} service-extension? @var{obj}
9980 Return true if @var{obj} is a service extension.
9981 @end deffn
9982
9983 At the core of the service abstraction lies the @code{fold-services}
9984 procedure, which is responsible for ``compiling'' a list of services
9985 down to a single directory that contains everything needed to boot and
9986 run the system---the directory shown by the @command{guix system build}
9987 command (@pxref{Invoking guix system}). In essence, it propagates
9988 service extensions down the service graph, updating each node parameters
9989 on the way, until it reaches the root node.
9990
9991 @deffn {Scheme Procedure} fold-services @var{services} @
9992 [#:target-type @var{system-service-type}]
9993 Fold @var{services} by propagating their extensions down to the root of
9994 type @var{target-type}; return the root service adjusted accordingly.
9995 @end deffn
9996
9997 Lastly, the @code{(gnu services)} module also defines several essential
9998 service types, some of which are listed below.
9999
10000 @defvr {Scheme Variable} system-service-type
10001 This is the root of the service graph. It produces the system directory
10002 as returned by the @command{guix system build} command.
10003 @end defvr
10004
10005 @defvr {Scheme Variable} boot-service-type
10006 The type of the ``boot service'', which produces the @dfn{boot script}.
10007 The boot script is what the initial RAM disk runs when booting.
10008 @end defvr
10009
10010 @defvr {Scheme Variable} etc-service-type
10011 The type of the @file{/etc} service. This service can be extended by
10012 passing it name/file tuples such as:
10013
10014 @example
10015 (list `("issue" ,(plain-file "issue" "Welcome!\n")))
10016 @end example
10017
10018 In this example, the effect would be to add an @file{/etc/issue} file
10019 pointing to the given file.
10020 @end defvr
10021
10022 @defvr {Scheme Variable} setuid-program-service-type
10023 Type for the ``setuid-program service''. This service collects lists of
10024 executable file names, passed as gexps, and adds them to the set of
10025 setuid-root programs on the system (@pxref{Setuid Programs}).
10026 @end defvr
10027
10028 @defvr {Scheme Variable} profile-service-type
10029 Type of the service that populates the @dfn{system profile}---i.e., the
10030 programs under @file{/run/current-system/profile}. Other services can
10031 extend it by passing it lists of packages to add to the system profile.
10032 @end defvr
10033
10034
10035 @node Shepherd Services
10036 @subsubsection Shepherd Services
10037
10038 @cindex PID 1
10039 @cindex init system
10040 The @code{(gnu services shepherd)} module provides a way to define
10041 services managed by the GNU@tie{}Shepherd, which is the GuixSD
10042 initialization system---the first process that is started when the
10043 system boots, aka. PID@tie{}1 (@pxref{Introduction,,, shepherd, The GNU
10044 Shepherd Manual}).
10045
10046 Services in the Shepherd can depend on each other. For instance, the
10047 SSH daemon may need to be started after the syslog daemon has been
10048 started, which in turn can only happen once all the file systems have
10049 been mounted. The simple operating system defined earlier (@pxref{Using
10050 the Configuration System}) results in a service graph like this:
10051
10052 @image{images/shepherd-graph,,5in,Typical shepherd service graph.}
10053
10054 You can actually generate such a graph for any operating system
10055 definition using the @command{guix system shepherd-graph} command
10056 (@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
10057
10058 The @var{%shepherd-root-service} is a service object representing
10059 PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
10060 by passing it lists of @code{<shepherd-service>} objects.
10061
10062 @deftp {Data Type} shepherd-service
10063 The data type representing a service managed by the Shepherd.
10064
10065 @table @asis
10066 @item @code{provision}
10067 This is a list of symbols denoting what the service provides.
10068
10069 These are the names that may be passed to @command{herd start},
10070 @command{herd status}, and similar commands (@pxref{Invoking herd,,,
10071 shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
10072 @code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
10073
10074 @item @code{requirements} (default: @code{'()})
10075 List of symbols denoting the Shepherd services this one depends on.
10076
10077 @item @code{respawn?} (default: @code{#t})
10078 Whether to restart the service when it stops, for instance when the
10079 underlying process dies.
10080
10081 @item @code{start}
10082 @itemx @code{stop} (default: @code{#~(const #f)})
10083 The @code{start} and @code{stop} fields refer to the Shepherd's
10084 facilities to start and stop processes (@pxref{Service De- and
10085 Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
10086 G-expressions that get expanded in the Shepherd configuration file
10087 (@pxref{G-Expressions}).
10088
10089 @item @code{documentation}
10090 A documentation string, as shown when running:
10091
10092 @example
10093 herd doc @var{service-name}
10094 @end example
10095
10096 where @var{service-name} is one of the symbols in @var{provision}
10097 (@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
10098
10099 @item @code{modules} (default: @var{%default-modules})
10100 This is the list of modules that must be in scope when @code{start} and
10101 @code{stop} are evaluated.
10102
10103 @item @code{imported-modules} (default: @var{%default-imported-modules})
10104 This is the list of modules to import in the execution environment of
10105 the Shepherd.
10106
10107 @end table
10108 @end deftp
10109
10110 @defvr {Scheme Variable} shepherd-root-service-type
10111 The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
10112
10113 This is the service type that extensions target when they want to create
10114 shepherd services (@pxref{Service Types and Services}, for an example).
10115 Each extension must pass a list of @code{<shepherd-service>}.
10116 @end defvr
10117
10118 @defvr {Scheme Variable} %shepherd-root-service
10119 This service represents PID@tie{}1.
10120 @end defvr
10121
10122
10123 @node Installing Debugging Files
10124 @section Installing Debugging Files
10125
10126 @cindex debugging files
10127 Program binaries, as produced by the GCC compilers for instance, are
10128 typically written in the ELF format, with a section containing
10129 @dfn{debugging information}. Debugging information is what allows the
10130 debugger, GDB, to map binary code to source code; it is required to
10131 debug a compiled program in good conditions.
10132
10133 The problem with debugging information is that is takes up a fair amount
10134 of disk space. For example, debugging information for the GNU C Library
10135 weighs in at more than 60 MiB. Thus, as a user, keeping all the
10136 debugging info of all the installed programs is usually not an option.
10137 Yet, space savings should not come at the cost of an impediment to
10138 debugging---especially in the GNU system, which should make it easier
10139 for users to exert their computing freedom (@pxref{GNU Distribution}).
10140
10141 Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
10142 mechanism that allows users to get the best of both worlds: debugging
10143 information can be stripped from the binaries and stored in separate
10144 files. GDB is then able to load debugging information from those files,
10145 when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
10146 with GDB}).
10147
10148 The GNU distribution takes advantage of this by storing debugging
10149 information in the @code{lib/debug} sub-directory of a separate package
10150 output unimaginatively called @code{debug} (@pxref{Packages with
10151 Multiple Outputs}). Users can choose to install the @code{debug} output
10152 of a package when they need it. For instance, the following command
10153 installs the debugging information for the GNU C Library and for GNU
10154 Guile:
10155
10156 @example
10157 guix package -i glibc:debug guile:debug
10158 @end example
10159
10160 GDB must then be told to look for debug files in the user's profile, by
10161 setting the @code{debug-file-directory} variable (consider setting it
10162 from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
10163 GDB}):
10164
10165 @example
10166 (gdb) set debug-file-directory ~/.guix-profile/lib/debug
10167 @end example
10168
10169 From there on, GDB will pick up debugging information from the
10170 @code{.debug} files under @file{~/.guix-profile/lib/debug}.
10171
10172 In addition, you will most likely want GDB to be able to show the source
10173 code being debugged. To do that, you will have to unpack the source
10174 code of the package of interest (obtained with @code{guix build
10175 --source}, @pxref{Invoking guix build}), and to point GDB to that source
10176 directory using the @code{directory} command (@pxref{Source Path,
10177 @code{directory},, gdb, Debugging with GDB}).
10178
10179 @c XXX: keep me up-to-date
10180 The @code{debug} output mechanism in Guix is implemented by the
10181 @code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
10182 opt-in---debugging information is available only for those packages
10183 whose definition explicitly declares a @code{debug} output. This may be
10184 changed to opt-out in the future, if our build farm servers can handle
10185 the load. To check whether a package has a @code{debug} output, use
10186 @command{guix package --list-available} (@pxref{Invoking guix package}).
10187
10188
10189 @node Security Updates
10190 @section Security Updates
10191
10192 @quotation Note
10193 As of version @value{VERSION}, the feature described in this section is
10194 experimental.
10195 @end quotation
10196
10197 @cindex security updates
10198 Occasionally, important security vulnerabilities are discovered in core
10199 software packages and must be patched. Guix follows a functional
10200 package management discipline (@pxref{Introduction}), which implies
10201 that, when a package is changed, @emph{every package that depends on it}
10202 must be rebuilt. This can significantly slow down the deployment of
10203 fixes in core packages such as libc or Bash, since basically the whole
10204 distribution would need to be rebuilt. Using pre-built binaries helps
10205 (@pxref{Substitutes}), but deployment may still take more time than
10206 desired.
10207
10208 @cindex grafts
10209 To address that, Guix implements @dfn{grafts}, a mechanism that allows
10210 for fast deployment of critical updates without the costs associated
10211 with a whole-distribution rebuild. The idea is to rebuild only the
10212 package that needs to be patched, and then to ``graft'' it onto packages
10213 explicitly installed by the user and that were previously referring to
10214 the original package. The cost of grafting is typically very low, and
10215 order of magnitudes lower than a full rebuild of the dependency chain.
10216
10217 @cindex replacements of packages, for grafts
10218 For instance, suppose a security update needs to be applied to Bash.
10219 Guix developers will provide a package definition for the ``fixed''
10220 Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
10221 Packages}). Then, the original package definition is augmented with a
10222 @code{replacement} field pointing to the package containing the bug fix:
10223
10224 @example
10225 (define bash
10226 (package
10227 (name "bash")
10228 ;; @dots{}
10229 (replacement bash-fixed)))
10230 @end example
10231
10232 From there on, any package depending directly or indirectly on Bash that
10233 is installed will automatically be ``rewritten'' to refer to
10234 @var{bash-fixed} instead of @var{bash}. This grafting process takes
10235 time proportional to the size of the package, but expect less than a
10236 minute for an ``average'' package on a recent machine.
10237
10238 Currently, the graft and the package it replaces (@var{bash-fixed} and
10239 @var{bash} in the example above) must have the exact same @code{name}
10240 and @code{version} fields. This restriction mostly comes from the fact
10241 that grafting works by patching files, including binary files, directly.
10242 Other restrictions may apply: for instance, when adding a graft to a
10243 package providing a shared library, the original shared library and its
10244 replacement must have the same @code{SONAME} and be binary-compatible.
10245
10246
10247 @node Package Modules
10248 @section Package Modules
10249
10250 From a programming viewpoint, the package definitions of the
10251 GNU distribution are provided by Guile modules in the @code{(gnu packages
10252 @dots{})} name space@footnote{Note that packages under the @code{(gnu
10253 packages @dots{})} module name space are not necessarily ``GNU
10254 packages''. This module naming scheme follows the usual Guile module
10255 naming convention: @code{gnu} means that these modules are distributed
10256 as part of the GNU system, and @code{packages} identifies modules that
10257 define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
10258 Reference Manual}). For instance, the @code{(gnu packages emacs)}
10259 module exports a variable named @code{emacs}, which is bound to a
10260 @code{<package>} object (@pxref{Defining Packages}).
10261
10262 The @code{(gnu packages @dots{})} module name space is
10263 automatically scanned for packages by the command-line tools. For
10264 instance, when running @code{guix package -i emacs}, all the @code{(gnu
10265 packages @dots{})} modules are scanned until one that exports a package
10266 object whose name is @code{emacs} is found. This package search
10267 facility is implemented in the @code{(gnu packages)} module.
10268
10269 @cindex customization, of packages
10270 @cindex package module search path
10271 Users can store package definitions in modules with different
10272 names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
10273 name and module name must match. For instance, the @code{(my-packages
10274 emacs)} module must be stored in a @file{my-packages/emacs.scm} file
10275 relative to the load path specified with @option{--load-path} or
10276 @code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
10277 guile, GNU Guile Reference Manual}, for details.}. These package definitions
10278 will not be visible by default. Thus, users can invoke commands such as
10279 @command{guix package} and @command{guix build} have to be used with the
10280 @code{-e} option so that they know where to find the package. Better
10281 yet, they can use the
10282 @code{-L} option of these commands to make those modules visible
10283 (@pxref{Invoking guix build, @code{--load-path}}), or define the
10284 @code{GUIX_PACKAGE_PATH} environment variable. This environment
10285 variable makes it easy to extend or customize the distribution and is
10286 honored by all the user interfaces.
10287
10288 @defvr {Environment Variable} GUIX_PACKAGE_PATH
10289 This is a colon-separated list of directories to search for package
10290 modules. Directories listed in this variable take precedence over the
10291 distribution's own modules.
10292 @end defvr
10293
10294 The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
10295 each package is built based solely on other packages in the
10296 distribution. The root of this dependency graph is a small set of
10297 @dfn{bootstrap binaries}, provided by the @code{(gnu packages
10298 bootstrap)} module. For more information on bootstrapping,
10299 @pxref{Bootstrapping}.
10300
10301 @node Packaging Guidelines
10302 @section Packaging Guidelines
10303
10304 The GNU distribution is nascent and may well lack some of your favorite
10305 packages. This section describes how you can help make the distribution
10306 grow. @xref{Contributing}, for additional information on how you can
10307 help.
10308
10309 Free software packages are usually distributed in the form of
10310 @dfn{source code tarballs}---typically @file{tar.gz} files that contain
10311 all the source files. Adding a package to the distribution means
10312 essentially two things: adding a @dfn{recipe} that describes how to
10313 build the package, including a list of other packages required to build
10314 it, and adding @dfn{package metadata} along with that recipe, such as a
10315 description and licensing information.
10316
10317 In Guix all this information is embodied in @dfn{package definitions}.
10318 Package definitions provide a high-level view of the package. They are
10319 written using the syntax of the Scheme programming language; in fact,
10320 for each package we define a variable bound to the package definition,
10321 and export that variable from a module (@pxref{Package Modules}).
10322 However, in-depth Scheme knowledge is @emph{not} a prerequisite for
10323 creating packages. For more information on package definitions,
10324 @pxref{Defining Packages}.
10325
10326 Once a package definition is in place, stored in a file in the Guix
10327 source tree, it can be tested using the @command{guix build} command
10328 (@pxref{Invoking guix build}). For example, assuming the new package is
10329 called @code{gnew}, you may run this command from the Guix build tree
10330 (@pxref{Running Guix Before It Is Installed}):
10331
10332 @example
10333 ./pre-inst-env guix build gnew --keep-failed
10334 @end example
10335
10336 Using @code{--keep-failed} makes it easier to debug build failures since
10337 it provides access to the failed build tree. Another useful
10338 command-line option when debugging is @code{--log-file}, to access the
10339 build log.
10340
10341 If the package is unknown to the @command{guix} command, it may be that
10342 the source file contains a syntax error, or lacks a @code{define-public}
10343 clause to export the package variable. To figure it out, you may load
10344 the module from Guile to get more information about the actual error:
10345
10346 @example
10347 ./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
10348 @end example
10349
10350 Once your package builds correctly, please send us a patch
10351 (@pxref{Contributing}). Well, if you need help, we will be happy to
10352 help you too. Once the patch is committed in the Guix repository, the
10353 new package automatically gets built on the supported platforms by
10354 @url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
10355 system}.
10356
10357 @cindex substituter
10358 Users can obtain the new package definition simply by running
10359 @command{guix pull} (@pxref{Invoking guix pull}). When
10360 @code{hydra.gnu.org} is done building the package, installing the
10361 package automatically downloads binaries from there
10362 (@pxref{Substitutes}). The only place where human intervention is
10363 needed is to review and apply the patch.
10364
10365
10366 @menu
10367 * Software Freedom:: What may go into the distribution.
10368 * Package Naming:: What's in a name?
10369 * Version Numbers:: When the name is not enough.
10370 * Synopses and Descriptions:: Helping users find the right package.
10371 * Python Modules:: Taming the snake.
10372 * Perl Modules:: Little pearls.
10373 * Fonts:: Fond of fonts.
10374 @end menu
10375
10376 @node Software Freedom
10377 @subsection Software Freedom
10378
10379 @c Adapted from http://www.gnu.org/philosophy/philosophy.html.
10380
10381 The GNU operating system has been developed so that users can have
10382 freedom in their computing. GNU is @dfn{free software}, meaning that
10383 users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
10384 essential freedoms}: to run the program, to study and change the program
10385 in source code form, to redistribute exact copies, and to distribute
10386 modified versions. Packages found in the GNU distribution provide only
10387 software that conveys these four freedoms.
10388
10389 In addition, the GNU distribution follow the
10390 @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
10391 software distribution guidelines}. Among other things, these guidelines
10392 reject non-free firmware, recommendations of non-free software, and
10393 discuss ways to deal with trademarks and patents.
10394
10395 Some packages contain a small and optional subset that violates the
10396 above guidelines, for instance because this subset is itself non-free
10397 code. When that happens, the offending items are removed with
10398 appropriate patches or code snippets in the package definition's
10399 @code{origin} form (@pxref{Defining Packages}). That way, @code{guix
10400 build --source} returns the ``freed'' source rather than the unmodified
10401 upstream source.
10402
10403
10404 @node Package Naming
10405 @subsection Package Naming
10406
10407 A package has actually two names associated with it:
10408 First, there is the name of the @emph{Scheme variable}, the one following
10409 @code{define-public}. By this name, the package can be made known in the
10410 Scheme code, for instance as input to another package. Second, there is
10411 the string in the @code{name} field of a package definition. This name
10412 is used by package management commands such as
10413 @command{guix package} and @command{guix build}.
10414
10415 Both are usually the same and correspond to the lowercase conversion of
10416 the project name chosen upstream, with underscores replaced with
10417 hyphens. For instance, GNUnet is available as @code{gnunet}, and
10418 SDL_net as @code{sdl-net}.
10419
10420 We do not add @code{lib} prefixes for library packages, unless these are
10421 already part of the official project name. But @pxref{Python
10422 Modules} and @ref{Perl Modules} for special rules concerning modules for
10423 the Python and Perl languages.
10424
10425 Font package names are handled differently, @pxref{Fonts}.
10426
10427
10428 @node Version Numbers
10429 @subsection Version Numbers
10430
10431 We usually package only the latest version of a given free software
10432 project. But sometimes, for instance for incompatible library versions,
10433 two (or more) versions of the same package are needed. These require
10434 different Scheme variable names. We use the name as defined
10435 in @ref{Package Naming}
10436 for the most recent version; previous versions use the same name, suffixed
10437 by @code{-} and the smallest prefix of the version number that may
10438 distinguish the two versions.
10439
10440 The name inside the package definition is the same for all versions of a
10441 package and does not contain any version number.
10442
10443 For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
10444
10445 @example
10446 (define-public gtk+
10447 (package
10448 (name "gtk+")
10449 (version "3.9.12")
10450 ...))
10451 (define-public gtk+-2
10452 (package
10453 (name "gtk+")
10454 (version "2.24.20")
10455 ...))
10456 @end example
10457 If we also wanted GTK+ 3.8.2, this would be packaged as
10458 @example
10459 (define-public gtk+-3.8
10460 (package
10461 (name "gtk+")
10462 (version "3.8.2")
10463 ...))
10464 @end example
10465
10466 @c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
10467 @c for a discussion of what follows.
10468 @cindex version number, for VCS snapshots
10469 Occasionally, we package snapshots of upstream's version control system
10470 (VCS) instead of formal releases. This should remain exceptional,
10471 because it is up to upstream developers to clarify what the stable
10472 release is. Yet, it is sometimes necessary. So, what should we put in
10473 the @code{version} field?
10474
10475 Clearly, we need to make the commit identifier of the VCS snapshot
10476 visible in the version string, but we also need to make sure that the
10477 version string is monotonically increasing so that @command{guix package
10478 --upgrade} can determine which version is newer. Since commit
10479 identifiers, notably with Git, are not monotonically increasing, we add
10480 a revision number that we increase each time we upgrade to a newer
10481 snapshot. The resulting version string looks like this:
10482
10483 @example
10484 2.0.11-3.cabba9e
10485 ^ ^ ^
10486 | | `-- upstream commit ID
10487 | |
10488 | `--- Guix package revision
10489 |
10490 latest upstream version
10491 @end example
10492
10493 It is a good idea to strip commit identifiers in the @code{version}
10494 field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
10495 aesthetics have a role to play here) as well as problems related to OS
10496 limits such as the maximum shebang length (127 bytes for the Linux
10497 kernel.) It is best to use the full commit identifiers in
10498 @code{origin}s, though, to avoid ambiguities. A typical package
10499 definition may look like this:
10500
10501 @example
10502 (define my-package
10503 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7"))
10504 (package
10505 (version (string-append "0.9-1."
10506 (string-take commit 7)))
10507 (source (origin
10508 (method git-fetch)
10509 (uri (git-reference
10510 (url "git://example.org/my-package.git")
10511 (commit commit)))
10512 (sha256 (base32 "1mbikn@dots{}"))
10513 (file-name (string-append "my-package-" version
10514 "-checkout"))))
10515 ;; @dots{}
10516 )))
10517 @end example
10518
10519 @node Synopses and Descriptions
10520 @subsection Synopses and Descriptions
10521
10522 As we have seen before, each package in GNU@tie{}Guix includes a
10523 synopsis and a description (@pxref{Defining Packages}). Synopses and
10524 descriptions are important: They are what @command{guix package
10525 --search} searches, and a crucial piece of information to help users
10526 determine whether a given package suits their needs. Consequently,
10527 packagers should pay attention to what goes into them.
10528
10529 Synopses must start with a capital letter and must not end with a
10530 period. They must not start with ``a'' or ``the'', which usually does
10531 not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
10532 tool that frobs files''. The synopsis should say what the package
10533 is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
10534 used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
10535 matching a pattern''.
10536
10537 Keep in mind that the synopsis must be meaningful for a very wide
10538 audience. For example, ``Manipulate alignments in the SAM format''
10539 might make sense for a seasoned bioinformatics researcher, but might be
10540 fairly unhelpful or even misleading to a non-specialized audience. It
10541 is a good idea to come up with a synopsis that gives an idea of the
10542 application domain of the package. In this example, this might give
10543 something like ``Manipulate nucleotide sequence alignments'', which
10544 hopefully gives the user a better idea of whether this is what they are
10545 looking for.
10546
10547 @cindex Texinfo markup, in package descriptions
10548 Descriptions should take between five and ten lines. Use full
10549 sentences, and avoid using acronyms without first introducing them.
10550 Descriptions can include Texinfo markup, which is useful to introduce
10551 ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
10552 hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
10553 should be careful when using some characters for example @samp{@@} and
10554 curly braces which are the basic special characters in Texinfo
10555 (@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
10556 such as @command{guix package --show} take care of rendering it
10557 appropriately.
10558
10559 Synopses and descriptions are translated by volunteers
10560 @uref{http://translationproject.org/domain/guix-packages.html, at the
10561 Translation Project} so that as many users as possible can read them in
10562 their native language. User interfaces search them and display them in
10563 the language specified by the current locale.
10564
10565 Translation is a lot of work so, as a packager, please pay even more
10566 attention to your synopses and descriptions as every change may entail
10567 additional work for translators. In order to help them, it is possible
10568 to make recommendations or instructions visible to them by inserting
10569 special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
10570 Gettext}):
10571
10572 @example
10573 ;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
10574 (description "ARandR is designed to provide a simple visual front end
10575 for the X11 resize-and-rotate (RandR) extension. @dots{}")
10576 @end example
10577
10578
10579 @node Python Modules
10580 @subsection Python Modules
10581
10582 We currently package Python 2 and Python 3, under the Scheme variable names
10583 @code{python-2} and @code{python} as explained in @ref{Version Numbers}.
10584 To avoid confusion and naming clashes with other programming languages, it
10585 seems desirable that the name of a package for a Python module contains
10586 the word @code{python}.
10587
10588 Some modules are compatible with only one version of Python, others with both.
10589 If the package Foo compiles only with Python 3, we name it
10590 @code{python-foo}; if it compiles only with Python 2, we name it
10591 @code{python2-foo}. If it is compatible with both versions, we create two
10592 packages with the corresponding names.
10593
10594 If a project already contains the word @code{python}, we drop this;
10595 for instance, the module python-dateutil is packaged under the names
10596 @code{python-dateutil} and @code{python2-dateutil}.
10597
10598
10599 @node Perl Modules
10600 @subsection Perl Modules
10601
10602 Perl programs standing for themselves are named as any other package,
10603 using the lowercase upstream name.
10604 For Perl packages containing a single class, we use the lowercase class name,
10605 replace all occurrences of @code{::} by dashes and prepend the prefix
10606 @code{perl-}.
10607 So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
10608 Modules containing several classes keep their lowercase upstream name and
10609 are also prepended by @code{perl-}. Such modules tend to have the word
10610 @code{perl} somewhere in their name, which gets dropped in favor of the
10611 prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
10612
10613
10614 @node Fonts
10615 @subsection Fonts
10616
10617 For fonts that are in general not installed by a user for typesetting
10618 purposes, or that are distributed as part of a larger software package,
10619 we rely on the general packaging rules for software; for instance, this
10620 applies to the fonts delivered as part of the X.Org system or fonts that
10621 are part of TeX Live.
10622
10623 To make it easier for a user to search for fonts, names for other packages
10624 containing only fonts are constructed as follows, independently of the
10625 upstream package name.
10626
10627 The name of a package containing only one font family starts with
10628 @code{font-}; it is followed by the foundry name and a dash @code{-}
10629 if the foundry is known, and the font family name, in which spaces are
10630 replaced by dashes (and as usual, all upper case letters are transformed
10631 to lower case).
10632 For example, the Gentium font family by SIL is packaged under the name
10633 @code{font-sil-gentium}.
10634
10635 For a package containing several font families, the name of the collection
10636 is used in the place of the font family name.
10637 For instance, the Liberation fonts consist of three families,
10638 Liberation Sans, Liberation Serif and Liberation Mono.
10639 These could be packaged separately under the names
10640 @code{font-liberation-sans} and so on; but as they are distributed together
10641 under a common name, we prefer to package them together as
10642 @code{font-liberation}.
10643
10644 In the case where several formats of the same font family or font collection
10645 are packaged separately, a short form of the format, prepended by a dash,
10646 is added to the package name. We use @code{-ttf} for TrueType fonts,
10647 @code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
10648 fonts.
10649
10650
10651
10652 @node Bootstrapping
10653 @section Bootstrapping
10654
10655 @c Adapted from the ELS 2013 paper.
10656
10657 @cindex bootstrapping
10658
10659 Bootstrapping in our context refers to how the distribution gets built
10660 ``from nothing''. Remember that the build environment of a derivation
10661 contains nothing but its declared inputs (@pxref{Introduction}). So
10662 there's an obvious chicken-and-egg problem: how does the first package
10663 get built? How does the first compiler get compiled? Note that this is
10664 a question of interest only to the curious hacker, not to the regular
10665 user, so you can shamelessly skip this section if you consider yourself
10666 a ``regular user''.
10667
10668 @cindex bootstrap binaries
10669 The GNU system is primarily made of C code, with libc at its core. The
10670 GNU build system itself assumes the availability of a Bourne shell and
10671 command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
10672 `grep'. Furthermore, build programs---programs that run
10673 @code{./configure}, @code{make}, etc.---are written in Guile Scheme
10674 (@pxref{Derivations}). Consequently, to be able to build anything at
10675 all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
10676 Binutils, libc, and the other packages mentioned above---the
10677 @dfn{bootstrap binaries}.
10678
10679 These bootstrap binaries are ``taken for granted'', though we can also
10680 re-create them if needed (more on that later).
10681
10682 @unnumberedsubsec Preparing to Use the Bootstrap Binaries
10683
10684 @c As of Emacs 24.3, Info-mode displays the image, but since it's a
10685 @c large image, it's hard to scroll. Oh well.
10686 @image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
10687
10688 The figure above shows the very beginning of the dependency graph of the
10689 distribution, corresponding to the package definitions of the @code{(gnu
10690 packages bootstrap)} module. A similar figure can be generated with
10691 @command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
10692
10693 @example
10694 guix graph -t derivation \
10695 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
10696 | dot -Tps > t.ps
10697 @end example
10698
10699 At this level of detail, things are
10700 slightly complex. First, Guile itself consists of an ELF executable,
10701 along with many source and compiled Scheme files that are dynamically
10702 loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
10703 tarball shown in this graph. This tarball is part of Guix's ``source''
10704 distribution, and gets inserted into the store with @code{add-to-store}
10705 (@pxref{The Store}).
10706
10707 But how do we write a derivation that unpacks this tarball and adds it
10708 to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
10709 derivation---the first one that gets built---uses @code{bash} as its
10710 builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
10711 @code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
10712 @file{xz}, and @file{mkdir} are statically-linked binaries, also part of
10713 the Guix source distribution, whose sole purpose is to allow the Guile
10714 tarball to be unpacked.
10715
10716 Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
10717 Guile that can be used to run subsequent build programs. Its first task
10718 is to download tarballs containing the other pre-built binaries---this
10719 is what the @code{.tar.xz.drv} derivations do. Guix modules such as
10720 @code{ftp-client.scm} are used for this purpose. The
10721 @code{module-import.drv} derivations import those modules in a directory
10722 in the store, using the original layout. The
10723 @code{module-import-compiled.drv} derivations compile those modules, and
10724 write them in an output directory with the right layout. This
10725 corresponds to the @code{#:modules} argument of
10726 @code{build-expression->derivation} (@pxref{Derivations}).
10727
10728 Finally, the various tarballs are unpacked by the
10729 derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
10730 etc., at which point we have a working C tool chain.
10731
10732
10733 @unnumberedsubsec Building the Build Tools
10734
10735 Bootstrapping is complete when we have a full tool chain that does not
10736 depend on the pre-built bootstrap tools discussed above. This
10737 no-dependency requirement is verified by checking whether the files of
10738 the final tool chain contain references to the @file{/gnu/store}
10739 directories of the bootstrap inputs. The process that leads to this
10740 ``final'' tool chain is described by the package definitions found in
10741 the @code{(gnu packages commencement)} module.
10742
10743 The @command{guix graph} command allows us to ``zoom out'' compared to
10744 the graph above, by looking at the level of package objects instead of
10745 individual derivations---remember that a package may translate to
10746 several derivations, typically one derivation to download its source,
10747 one to build the Guile modules it needs, and one to actually build the
10748 package from source. The command:
10749
10750 @example
10751 guix graph -t bag \
10752 -e '(@@@@ (gnu packages commencement)
10753 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
10754 @end example
10755
10756 @noindent
10757 produces the dependency graph leading to the ``final'' C
10758 library@footnote{You may notice the @code{glibc-intermediate} label,
10759 suggesting that it is not @emph{quite} final, but as a good
10760 approximation, we will consider it final.}, depicted below.
10761
10762 @image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
10763
10764 @c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
10765 The first tool that gets built with the bootstrap binaries is
10766 GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
10767 for all the following packages. From there Findutils and Diffutils get
10768 built.
10769
10770 Then come the first-stage Binutils and GCC, built as pseudo cross
10771 tools---i.e., with @code{--target} equal to @code{--host}. They are
10772 used to build libc. Thanks to this cross-build trick, this libc is
10773 guaranteed not to hold any reference to the initial tool chain.
10774
10775 From there the final Binutils and GCC (not shown above) are built.
10776 GCC uses @code{ld}
10777 from the final Binutils, and links programs against the just-built libc.
10778 This tool chain is used to build the other packages used by Guix and by
10779 the GNU Build System: Guile, Bash, Coreutils, etc.
10780
10781 And voilà! At this point we have the complete set of build tools that
10782 the GNU Build System expects. These are in the @code{%final-inputs}
10783 variable of the @code{(gnu packages commencement)} module, and are
10784 implicitly used by any package that uses @code{gnu-build-system}
10785 (@pxref{Build Systems, @code{gnu-build-system}}).
10786
10787
10788 @unnumberedsubsec Building the Bootstrap Binaries
10789
10790 Because the final tool chain does not depend on the bootstrap binaries,
10791 those rarely need to be updated. Nevertheless, it is useful to have an
10792 automated way to produce them, should an update occur, and this is what
10793 the @code{(gnu packages make-bootstrap)} module provides.
10794
10795 The following command builds the tarballs containing the bootstrap
10796 binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
10797 of Coreutils and other basic command-line tools):
10798
10799 @example
10800 guix build bootstrap-tarballs
10801 @end example
10802
10803 The generated tarballs are those that should be referred to in the
10804 @code{(gnu packages bootstrap)} module mentioned at the beginning of
10805 this section.
10806
10807 Still here? Then perhaps by now you've started to wonder: when do we
10808 reach a fixed point? That is an interesting question! The answer is
10809 unknown, but if you would like to investigate further (and have
10810 significant computational and storage resources to do so), then let us
10811 know.
10812
10813 @node Porting
10814 @section Porting to a New Platform
10815
10816 As discussed above, the GNU distribution is self-contained, and
10817 self-containment is achieved by relying on pre-built ``bootstrap
10818 binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
10819 operating system kernel, CPU architecture, and application binary
10820 interface (ABI). Thus, to port the distribution to a platform that is
10821 not yet supported, one must build those bootstrap binaries, and update
10822 the @code{(gnu packages bootstrap)} module to use them on that platform.
10823
10824 Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
10825 When everything goes well, and assuming the GNU tool chain supports the
10826 target platform, this can be as simple as running a command like this
10827 one:
10828
10829 @example
10830 guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
10831 @end example
10832
10833 For this to work, the @code{glibc-dynamic-linker} procedure in
10834 @code{(gnu packages bootstrap)} must be augmented to return the right
10835 file name for libc's dynamic linker on that platform; likewise,
10836 @code{system->linux-architecture} in @code{(gnu packages linux)} must be
10837 taught about the new platform.
10838
10839 Once these are built, the @code{(gnu packages bootstrap)} module needs
10840 to be updated to refer to these binaries on the target platform. That
10841 is, the hashes and URLs of the bootstrap tarballs for the new platform
10842 must be added alongside those of the currently supported platforms. The
10843 bootstrap Guile tarball is treated specially: it is expected to be
10844 available locally, and @file{gnu-system.am} has rules do download it for
10845 the supported architectures; a rule for the new platform must be added
10846 as well.
10847
10848 In practice, there may be some complications. First, it may be that the
10849 extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
10850 above) is not recognized by all the GNU tools. Typically, glibc
10851 recognizes some of these, whereas GCC uses an extra @code{--with-abi}
10852 configure flag (see @code{gcc.scm} for examples of how to handle this).
10853 Second, some of the required packages could fail to build for that
10854 platform. Lastly, the generated binaries could be broken for some
10855 reason.
10856
10857 @c *********************************************************************
10858 @include contributing.texi
10859
10860 @c *********************************************************************
10861 @node Acknowledgments
10862 @chapter Acknowledgments
10863
10864 Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
10865 which was designed and
10866 implemented by Eelco Dolstra, with contributions from other people (see
10867 the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
10868 management, and promoted unprecedented features, such as transactional
10869 package upgrades and rollbacks, per-user profiles, and referentially
10870 transparent build processes. Without this work, Guix would not exist.
10871
10872 The Nix-based software distributions, Nixpkgs and NixOS, have also been
10873 an inspiration for Guix.
10874
10875 GNU@tie{}Guix itself is a collective work with contributions from a
10876 number of people. See the @file{AUTHORS} file in Guix for more
10877 information on these fine people. The @file{THANKS} file lists people
10878 who have helped by reporting bugs, taking care of the infrastructure,
10879 providing artwork and themes, making suggestions, and more---thank you!
10880
10881
10882 @c *********************************************************************
10883 @node GNU Free Documentation License
10884 @appendix GNU Free Documentation License
10885
10886 @include fdl-1.3.texi
10887
10888 @c *********************************************************************
10889 @node Concept Index
10890 @unnumbered Concept Index
10891 @printindex cp
10892
10893 @node Programming Index
10894 @unnumbered Programming Index
10895 @syncodeindex tp fn
10896 @syncodeindex vr fn
10897 @printindex fn
10898
10899 @bye
10900
10901 @c Local Variables:
10902 @c ispell-local-dictionary: "american";
10903 @c End: