Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / doc / guix.texi
1 \input texinfo
2 @c -*-texinfo-*-
3
4 @c %**start of header
5 @setfilename guix.info
6 @documentencoding UTF-8
7 @settitle GNU Guix Reference Manual
8 @c %**end of header
9
10 @include version.texi
11
12 @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, 2016 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 Copyright @copyright{} 2015, 2016 Ricardo Wurmus@*
21 Copyright @copyright{} 2016 Ben Woodcroft@*
22 Copyright @copyright{} 2016 Chris Marusich@*
23 Copyright @copyright{} 2016 Efraim Flashner
24
25 Permission is granted to copy, distribute and/or modify this document
26 under the terms of the GNU Free Documentation License, Version 1.3 or
27 any later version published by the Free Software Foundation; with no
28 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
29 copy of the license is included in the section entitled ``GNU Free
30 Documentation License''.
31 @end copying
32
33 @dircategory System administration
34 @direntry
35 * Guix: (guix). Manage installed software and system configuration.
36 * guix package: (guix)Invoking guix package. Installing, removing, and upgrading packages.
37 * guix build: (guix)Invoking guix build. Building packages.
38 * guix gc: (guix)Invoking guix gc. Reclaiming unused disk space.
39 * guix pull: (guix)Invoking guix pull. Update the list of available packages.
40 * guix system: (guix)Invoking guix system. Manage the operating system configuration.
41 @end direntry
42
43 @dircategory Software development
44 @direntry
45 * guix environment: (guix)Invoking guix environment. Building development environments with Guix.
46 @end direntry
47
48 @dircategory Emacs
49 @direntry
50 * Guix user interface: (guix)Emacs Interface. Package management from the comfort of Emacs.
51 @end direntry
52
53
54 @titlepage
55 @title GNU Guix Reference Manual
56 @subtitle Using the GNU Guix Functional Package Manager
57 @author The GNU Guix Developers
58
59 @page
60 @vskip 0pt plus 1filll
61 Edition @value{EDITION} @*
62 @value{UPDATED} @*
63
64 @insertcopying
65 @end titlepage
66
67 @contents
68
69 @c *********************************************************************
70 @node Top
71 @top GNU Guix
72
73 This document describes GNU Guix version @value{VERSION}, a functional
74 package management tool written for the GNU system.
75
76 @menu
77 * Introduction:: What is Guix about?
78 * Installation:: Installing Guix.
79 * Package Management:: Package installation, upgrade, etc.
80 * Emacs Interface:: Using Guix from Emacs.
81 * Programming Interface:: Using Guix in Scheme.
82 * Utilities:: Package management commands.
83 * GNU Distribution:: Software for your friendly GNU system.
84 * Contributing:: Your help needed!
85
86 * Acknowledgments:: Thanks!
87 * GNU Free Documentation License:: The license of this manual.
88 * Concept Index:: Concepts.
89 * Programming Index:: Data types, functions, and variables.
90
91 @detailmenu
92 --- The Detailed Node Listing ---
93
94 Installation
95
96 * Binary Installation:: Getting Guix running in no time!
97 * Requirements:: Software needed to build and run Guix.
98 * Running the Test Suite:: Testing Guix.
99 * Setting Up the Daemon:: Preparing the build daemon's environment.
100 * Invoking guix-daemon:: Running the build daemon.
101 * Application Setup:: Application-specific setup.
102
103 Setting Up the Daemon
104
105 * Build Environment Setup:: Preparing the isolated build environment.
106 * Daemon Offload Setup:: Offloading builds to remote machines.
107
108 Package Management
109
110 * Features:: How Guix will make your life brighter.
111 * Invoking guix package:: Package installation, removal, etc.
112 * Substitutes:: Downloading pre-built binaries.
113 * Packages with Multiple Outputs:: Single source package, multiple outputs.
114 * Invoking guix gc:: Running the garbage collector.
115 * Invoking guix pull:: Fetching the latest Guix and distribution.
116 * Invoking guix archive:: Exporting and importing store files.
117
118 Emacs Interface
119
120 * Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
121 * Package Management: Emacs Package Management. Managing packages and generations.
122 * Licenses: Emacs Licenses. Interface for licenses of Guix packages.
123 * Package Source Locations: Emacs Package Locations. Interface for package location files.
124 * Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
125 * Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
126 * Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
127 * Completions: Emacs Completions. Completing @command{guix} shell command.
128 * Development: Emacs Development. Tools for Guix developers.
129 * Hydra: Emacs Hydra. Interface for Guix build farm.
130
131 Programming Interface
132
133 * Defining Packages:: Defining new packages.
134 * Build Systems:: Specifying how packages are built.
135 * The Store:: Manipulating the package store.
136 * Derivations:: Low-level interface to package derivations.
137 * The Store Monad:: Purely functional interface to the store.
138 * G-Expressions:: Manipulating build expressions.
139
140 Defining Packages
141
142 * package Reference:: The package data type.
143 * origin Reference:: The origin data type.
144
145 Utilities
146
147 * Invoking guix build:: Building packages from the command line.
148 * Invoking guix edit:: Editing package definitions.
149 * Invoking guix download:: Downloading a file and printing its hash.
150 * Invoking guix hash:: Computing the cryptographic hash of a file.
151 * Invoking guix import:: Importing package definitions.
152 * Invoking guix refresh:: Updating package definitions.
153 * Invoking guix lint:: Finding errors in package definitions.
154 * Invoking guix size:: Profiling disk usage.
155 * Invoking guix graph:: Visualizing the graph of packages.
156 * Invoking guix environment:: Setting up development environments.
157 * Invoking guix publish:: Sharing substitutes.
158 * Invoking guix challenge:: Challenging substitute servers.
159 * Invoking guix container:: Process isolation.
160
161 Invoking @command{guix build}
162
163 * Common Build Options:: Build options for most commands.
164 * Package Transformation Options:: Creating variants of packages.
165 * Additional Build Options:: Options specific to 'guix build'.
166
167 GNU Distribution
168
169 * System Installation:: Installing the whole operating system.
170 * System Configuration:: Configuring the operating system.
171 * Installing Debugging Files:: Feeding the debugger.
172 * Security Updates:: Deploying security fixes quickly.
173 * Package Modules:: Packages from the programmer's viewpoint.
174 * Packaging Guidelines:: Growing the distribution.
175 * Bootstrapping:: GNU/Linux built from scratch.
176 * Porting:: Targeting another platform or kernel.
177
178 System Installation
179
180 * Limitations:: What you can expect.
181 * Hardware Considerations:: Supported hardware.
182 * USB Stick Installation:: Preparing the installation medium.
183 * Preparing for Installation:: Networking, partitioning, etc.
184 * Proceeding with the Installation:: The real thing.
185 * Building the Installation Image:: How this comes to be.
186
187 System Configuration
188
189 * Using the Configuration System:: Customizing your GNU system.
190 * operating-system Reference:: Detail of operating-system declarations.
191 * File Systems:: Configuring file system mounts.
192 * Mapped Devices:: Block device extra processing.
193 * User Accounts:: Specifying user accounts.
194 * Locales:: Language and cultural convention settings.
195 * Services:: Specifying system services.
196 * Setuid Programs:: Programs running with root privileges.
197 * X.509 Certificates:: Authenticating HTTPS servers.
198 * Name Service Switch:: Configuring libc's name service switch.
199 * Initial RAM Disk:: Linux-Libre bootstrapping.
200 * GRUB Configuration:: Configuring the boot loader.
201 * Invoking guix system:: Instantiating a system configuration.
202 * Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
203 * Defining Services:: Adding new service definitions.
204
205 Services
206
207 * Base Services:: Essential system services.
208 * Scheduled Job Execution:: The mcron service.
209 * Networking Services:: Network setup, SSH daemon, etc.
210 * X Window:: Graphical display.
211 * Desktop Services:: D-Bus and desktop services.
212 * Database Services:: SQL databases.
213 * Mail Services:: IMAP, POP3, SMTP, and all that.
214 * Web Services:: Web servers.
215 * Various Services:: Other services.
216
217 Defining Services
218
219 * Service Composition:: The model for composing services.
220 * Service Types and Services:: Types and services.
221 * Service Reference:: API reference.
222 * Shepherd Services:: A particular type of service.
223
224 Packaging Guidelines
225
226 * Software Freedom:: What may go into the distribution.
227 * Package Naming:: What's in a name?
228 * Version Numbers:: When the name is not enough.
229 * Synopses and Descriptions:: Helping users find the right package.
230 * Python Modules:: Taming the snake.
231 * Perl Modules:: Little pearls.
232 * Java Packages:: Coffee break.
233 * Fonts:: Fond of fonts.
234
235 Contributing
236
237 * Building from Git:: The latest and greatest.
238 * Running Guix Before It Is Installed:: Hacker tricks.
239 * The Perfect Setup:: The right tools.
240 * Coding Style:: Hygiene of the contributor.
241 * Submitting Patches:: Share your work.
242
243 Coding Style
244
245 * Programming Paradigm:: How to compose your elements.
246 * Modules:: Where to store your code?
247 * Data Types and Pattern Matching:: Implementing data structures.
248 * Formatting Code:: Writing conventions.
249
250 @end detailmenu
251 @end menu
252
253 @c *********************************************************************
254 @node Introduction
255 @chapter Introduction
256
257 @cindex purpose
258 GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
259 using the international phonetic alphabet (IPA).} is a package
260 management tool for the GNU system. Guix makes it easy for unprivileged
261 users to install, upgrade, or remove packages, to roll back to a
262 previous package set, to build packages from source, and generally
263 assists with the creation and maintenance of software environments.
264
265 @cindex user interfaces
266 Guix provides a command-line package management interface
267 (@pxref{Invoking guix package}), a set of command-line utilities
268 (@pxref{Utilities}), a visual user interface in Emacs (@pxref{Emacs
269 Interface}), as well as Scheme programming interfaces
270 (@pxref{Programming Interface}).
271 @cindex build daemon
272 Its @dfn{build daemon} is responsible for building packages on behalf of
273 users (@pxref{Setting Up the Daemon}) and for downloading pre-built
274 binaries from authorized sources (@pxref{Substitutes}).
275
276 @cindex extensibility of the distribution
277 @cindex customization of packages
278 Guix includes package definitions for many GNU and non-GNU packages, all
279 of which @uref{https://www.gnu.org/philosophy/free-sw.html, respect the
280 user's computing freedom}. It is @emph{extensible}: users can write
281 their own package definitions (@pxref{Defining Packages}) and make them
282 available as independent package modules (@pxref{Package Modules}). It
283 is also @emph{customizable}: users can @emph{derive} specialized package
284 definitions from existing ones, including from the command line
285 (@pxref{Package Transformation Options}).
286
287 @cindex Guix System Distribution
288 @cindex GuixSD
289 You can install GNU@tie{}Guix on top of an existing GNU/Linux system
290 where it complements the available tools without interference
291 (@pxref{Installation}), or you can use it as part of the standalone
292 @dfn{Guix System Distribution} or GuixSD (@pxref{GNU Distribution}).
293 With GNU@tie{}GuixSD, you @emph{declare} all aspects of the operating
294 system configuration and Guix takes care of instantiating the
295 configuration in a transactional, reproducible, and stateless fashion
296 (@pxref{System Configuration}).
297
298 @cindex functional package management
299 Under the hood, Guix implements the @dfn{functional package management}
300 discipline pioneered by Nix (@pxref{Acknowledgments}).
301 In Guix, the package build and installation process is seen
302 as a @emph{function}, in the mathematical sense. That function takes inputs,
303 such as build scripts, a compiler, and libraries, and
304 returns an installed package. As a pure function, its result depends
305 solely on its inputs---for instance, it cannot refer to software or
306 scripts that were not explicitly passed as inputs. A build function
307 always produces the same result when passed a given set of inputs. It
308 cannot alter the environment of the running system in
309 any way; for instance, it cannot create, modify, or delete files outside
310 of its build and installation directories. This is achieved by running
311 build processes in isolated environments (or @dfn{containers}), where only their
312 explicit inputs are visible.
313
314 @cindex store
315 The result of package build functions is @dfn{cached} in the file
316 system, in a special directory called @dfn{the store} (@pxref{The
317 Store}). Each package is installed in a directory of its own in the
318 store---by default under @file{/gnu/store}. The directory name contains
319 a hash of all the inputs used to build that package; thus, changing an
320 input yields a different directory name.
321
322 This approach is the foundation for the salient features of Guix: support
323 for transactional package upgrade and rollback, per-user installation, and
324 garbage collection of packages (@pxref{Features}).
325
326
327 @c *********************************************************************
328 @node Installation
329 @chapter Installation
330
331 GNU Guix is available for download from its website at
332 @url{http://www.gnu.org/software/guix/}. This section describes the
333 software requirements of Guix, as well as how to install it and get
334 ready to use it.
335
336 Note that this section is concerned with the installation of the package
337 manager, which can be done on top of a running GNU/Linux system. If,
338 instead, you want to install the complete GNU operating system,
339 @pxref{System Installation}.
340
341 @cindex foreign distro
342 When installed on a running GNU/Linux system---thereafter called a
343 @dfn{foreign distro}---GNU@tie{}Guix complements the available tools
344 without interference. Its data lives exclusively in two directories,
345 usually @file{/gnu/store} and @file{/var/guix}; other files on your
346 system, such as @file{/etc}, are left untouched.
347
348 @menu
349 * Binary Installation:: Getting Guix running in no time!
350 * Requirements:: Software needed to build and run Guix.
351 * Running the Test Suite:: Testing Guix.
352 * Setting Up the Daemon:: Preparing the build daemon's environment.
353 * Invoking guix-daemon:: Running the build daemon.
354 * Application Setup:: Application-specific setup.
355 @end menu
356
357 @node Binary Installation
358 @section Binary Installation
359
360 This section describes how to install Guix on an arbitrary system from a
361 self-contained tarball providing binaries for Guix and for all its
362 dependencies. This is often quicker than installing from source, which
363 is described in the next sections. The only requirement is to have
364 GNU@tie{}tar and Xz.
365
366 Installing goes along these lines:
367
368 @enumerate
369 @item
370 Download the binary tarball from
371 @indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz},
372 where @var{system} is @code{x86_64-linux} for an @code{x86_64} machine
373 already running the kernel Linux, and so on.
374
375 Make sure to download the associated @file{.sig} file and to verify the
376 authenticity of the tarball against it, along these lines:
377
378 @example
379 $ wget ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
380 $ gpg --verify guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
381 @end example
382
383 If that command fails because you do not have the required public key,
384 then run this command to import it:
385
386 @example
387 $ gpg --keyserver pgp.mit.edu --recv-keys 090B11993D9AEBB5
388 @end example
389
390 @noindent
391 and rerun the @code{gpg --verify} command.
392
393 @item
394 As @code{root}, run:
395
396 @example
397 # cd /tmp
398 # tar --warning=no-timestamp -xf \
399 guix-binary-@value{VERSION}.@var{system}.tar.xz
400 # mv var/guix /var/ && mv gnu /
401 @end example
402
403 This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
404 The latter contains a ready-to-use profile for @code{root} (see next
405 step.)
406
407 Do @emph{not} unpack the tarball on a working Guix system since that
408 would overwrite its own essential files.
409
410 The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
411 not emit warnings about ``implausibly old time stamps'' (such
412 warnings were triggered by GNU@tie{}tar 1.26 and older; recent
413 versions are fine.)
414 They stem from the fact that all the
415 files in the archive have their modification time set to zero (which
416 means January 1st, 1970.) This is done on purpose to make sure the
417 archive content is independent of its creation time, thus making it
418 reproducible.
419
420 @item
421 Make @code{root}'s profile available under @file{~/.guix-profile}:
422
423 @example
424 # ln -sf /var/guix/profiles/per-user/root/guix-profile \
425 ~root/.guix-profile
426 @end example
427
428 @item
429 Create the group and user accounts for build users as explained below
430 (@pxref{Build Environment Setup}).
431
432 @item
433 Run the daemon, and set it to automatically start on boot.
434
435 If your host distro uses the systemd init system, this can be achieved
436 with these commands:
437
438 @example
439 # cp ~root/.guix-profile/lib/systemd/system/guix-daemon.service \
440 /etc/systemd/system/
441 # systemctl start guix-daemon && systemctl enable guix-daemon
442 @end example
443
444 If your host distro uses the Upstart init system:
445
446 @example
447 # cp ~root/.guix-profile/lib/upstart/system/guix-daemon.conf /etc/init/
448 # start guix-daemon
449 @end example
450
451 Otherwise, you can still start the daemon manually with:
452
453 @example
454 # ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
455 @end example
456
457 @item
458 Make the @command{guix} command available to other users on the machine,
459 for instance with:
460
461 @example
462 # mkdir -p /usr/local/bin
463 # cd /usr/local/bin
464 # ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
465 @end example
466
467 It is also a good idea to make the Info version of this manual available
468 there:
469
470 @example
471 # mkdir -p /usr/local/share/info
472 # cd /usr/local/share/info
473 # for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
474 do ln -s $i ; done
475 @end example
476
477 That way, assuming @file{/usr/local/share/info} is in the search path,
478 running @command{info guix} will open this manual (@pxref{Other Info
479 Directories,,, texinfo, GNU Texinfo}, for more details on changing the
480 Info search path.)
481
482 @item
483 To use substitutes from @code{hydra.gnu.org} or one of its mirrors
484 (@pxref{Substitutes}), authorize them:
485
486 @example
487 # guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
488 @end example
489 @end enumerate
490
491 This completes root-level install of Guix. Each user will need to
492 perform additional steps to make their Guix envionment ready for use,
493 @pxref{Application Setup}.
494
495 You can confirm that Guix is working by installing a sample package into
496 the root profile:
497
498 @example
499 # guix package -i hello
500 @end example
501
502 The @code{guix} package must remain available in @code{root}'s profile,
503 or it would become subject to garbage collection---in which case you
504 would find yourself badly handicapped by the lack of the @command{guix}
505 command. In other words, do not remove @code{guix} by running
506 @code{guix package -r guix}.
507
508 The binary installation tarball can be (re)produced and verified simply
509 by running the following command in the Guix source tree:
510
511 @example
512 make guix-binary.@var{system}.tar.xz
513 @end example
514
515
516 @node Requirements
517 @section Requirements
518
519 This section lists requirements when building Guix from source. The
520 build procedure for Guix is the same as for other GNU software, and is
521 not covered here. Please see the files @file{README} and @file{INSTALL}
522 in the Guix source tree for additional details.
523
524 GNU Guix depends on the following packages:
525
526 @itemize
527 @item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
528 @item @url{http://gnupg.org/, GNU libgcrypt};
529 @item @url{http://www.gnu.org/software/make/, GNU Make}.
530 @end itemize
531
532 The following dependencies are optional:
533
534 @itemize
535 @item
536 Installing @uref{http://gnutls.org/, GnuTLS-Guile} will allow you to
537 access @code{https} URLs for substitutes, which is highly recommended
538 (@pxref{Substitutes}). It also allows you to access HTTPS URLs with the
539 @command{guix download} command (@pxref{Invoking guix download}), the
540 @command{guix import pypi} command, and the @command{guix import cpan}
541 command. @xref{Guile Preparations, how to install the GnuTLS bindings
542 for Guile,, gnutls-guile, GnuTLS-Guile}.
543
544 @item
545 Installing
546 @url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
547 allow you to use the @command{guix import pypi} command (@pxref{Invoking
548 guix import}). It is of
549 interest primarily for developers and not for casual users.
550
551 @item
552 When @url{http://zlib.net, zlib} is available, @command{guix publish}
553 can compress build byproducts (@pxref{Invoking guix publish}).
554 @end itemize
555
556 Unless @code{--disable-daemon} was passed to @command{configure}, the
557 following packages are also needed:
558
559 @itemize
560 @item @url{http://sqlite.org, SQLite 3};
561 @item @url{http://www.bzip.org, libbz2};
562 @item @url{http://gcc.gnu.org, GCC's g++}, with support for the
563 C++11 standard.
564 @end itemize
565
566 When configuring Guix on a system that already has a Guix installation,
567 be sure to specify the same state directory as the existing installation
568 using the @code{--localstatedir} option of the @command{configure}
569 script (@pxref{Directory Variables, @code{localstatedir},, standards,
570 GNU Coding Standards}). The @command{configure} script protects against
571 unintended misconfiguration of @var{localstatedir} so you do not
572 inadvertently corrupt your store (@pxref{The Store}).
573
574 When a working installation of @url{http://nixos.org/nix/, the Nix package
575 manager} is available, you
576 can instead configure Guix with @code{--disable-daemon}. In that case,
577 Nix replaces the three dependencies above.
578
579 Guix is compatible with Nix, so it is possible to share the same store
580 between both. To do so, you must pass @command{configure} not only the
581 same @code{--with-store-dir} value, but also the same
582 @code{--localstatedir} value. The latter is essential because it
583 specifies where the database that stores metadata about the store is
584 located, among other things. The default values for Nix are
585 @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
586 Note that @code{--disable-daemon} is not required if
587 your goal is to share the store with Nix.
588
589 @node Running the Test Suite
590 @section Running the Test Suite
591
592 After a successful @command{configure} and @code{make} run, it is a good
593 idea to run the test suite. It can help catch issues with the setup or
594 environment, or bugs in Guix itself---and really, reporting test
595 failures is a good way to help improve the software. To run the test
596 suite, type:
597
598 @example
599 make check
600 @end example
601
602 Test cases can run in parallel: you can use the @code{-j} option of
603 GNU@tie{}make to speed things up. The first run may take a few minutes
604 on a recent machine; subsequent runs will be faster because the store
605 that is created for test purposes will already have various things in
606 cache.
607
608 It is also possible to run a subset of the tests by defining the
609 @code{TESTS} makefile variable as in this example:
610
611 @example
612 make check TESTS="tests/store.scm tests/cpio.scm"
613 @end example
614
615 By default, tests results are displayed at a file level. In order to
616 see the details of every individual test cases, it is possible to define
617 the @code{SCM_LOG_DRIVER_FLAGS} makefile variable as in this example:
618
619 @example
620 make check TESTS="tests/base64.scm" SCM_LOG_DRIVER_FLAGS="--brief=no"
621 @end example
622
623 Upon failure, please email @email{bug-guix@@gnu.org} and attach the
624 @file{test-suite.log} file. Please specify the Guix version being used
625 as well as version numbers of the dependencies (@pxref{Requirements}) in
626 your message.
627
628 Guix also comes with a whole-system test suite that tests complete
629 GuixSD operating system instances. It can only run on systems where
630 Guix is already installed, using:
631
632 @example
633 make check-system
634 @end example
635
636 @noindent
637 or, again, by defining @code{TESTS} to select a subset of tests to run:
638
639 @example
640 make check-system TESTS="basic mcron"
641 @end example
642
643 These system tests are defined in the @code{(gnu tests @dots{})}
644 modules. They work by running the operating systems under test with
645 lightweight instrumentation in a virtual machine (VM). They can be
646 computationally intensive or rather cheap, depending on whether
647 substitutes are available for their dependencies (@pxref{Substitutes}).
648 Some of them require a lot of storage space to hold VM images.
649
650 Again in case of test failures, please send @email{bug-guix@@gnu.org}
651 all the details.
652
653 @node Setting Up the Daemon
654 @section Setting Up the Daemon
655
656 @cindex daemon
657 Operations such as building a package or running the garbage collector
658 are all performed by a specialized process, the @dfn{build daemon}, on
659 behalf of clients. Only the daemon may access the store and its
660 associated database. Thus, any operation that manipulates the store
661 goes through the daemon. For instance, command-line tools such as
662 @command{guix package} and @command{guix build} communicate with the
663 daemon (@i{via} remote procedure calls) to instruct it what to do.
664
665 The following sections explain how to prepare the build daemon's
666 environment. See also @ref{Substitutes}, for information on how to allow
667 the daemon to download pre-built binaries.
668
669 @menu
670 * Build Environment Setup:: Preparing the isolated build environment.
671 * Daemon Offload Setup:: Offloading builds to remote machines.
672 @end menu
673
674 @node Build Environment Setup
675 @subsection Build Environment Setup
676
677 In a standard multi-user setup, Guix and its daemon---the
678 @command{guix-daemon} program---are installed by the system
679 administrator; @file{/gnu/store} is owned by @code{root} and
680 @command{guix-daemon} runs as @code{root}. Unprivileged users may use
681 Guix tools to build packages or otherwise access the store, and the
682 daemon will do it on their behalf, ensuring that the store is kept in a
683 consistent state, and allowing built packages to be shared among users.
684
685 @cindex build users
686 When @command{guix-daemon} runs as @code{root}, you may not want package
687 build processes themselves to run as @code{root} too, for obvious
688 security reasons. To avoid that, a special pool of @dfn{build users}
689 should be created for use by build processes started by the daemon.
690 These build users need not have a shell and a home directory: they will
691 just be used when the daemon drops @code{root} privileges in build
692 processes. Having several such users allows the daemon to launch
693 distinct build processes under separate UIDs, which guarantees that they
694 do not interfere with each other---an essential feature since builds are
695 regarded as pure functions (@pxref{Introduction}).
696
697 On a GNU/Linux system, a build user pool may be created like this (using
698 Bash syntax and the @code{shadow} commands):
699
700 @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
701 @c for why `-G' is needed.
702 @example
703 # groupadd --system guixbuild
704 # for i in `seq -w 1 10`;
705 do
706 useradd -g guixbuild -G guixbuild \
707 -d /var/empty -s `which nologin` \
708 -c "Guix build user $i" --system \
709 guixbuilder$i;
710 done
711 @end example
712
713 @noindent
714 The number of build users determines how many build jobs may run in
715 parallel, as specified by the @option{--max-jobs} option
716 (@pxref{Invoking guix-daemon, @option{--max-jobs}}). To use
717 @command{guix system vm} and related commands, you may need to add the
718 build users to the @code{kvm} group so they can access @file{/dev/kvm},
719 using @code{-G guixbuild,kvm} instead of @code{-G guixbuild}
720 (@pxref{Invoking guix system}).
721
722 The @code{guix-daemon} program may then be run as @code{root} with the
723 following command@footnote{If your machine uses the systemd init system,
724 dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
725 file in @file{/etc/systemd/system} will ensure that
726 @command{guix-daemon} is automatically started. Similarly, if your
727 machine uses the Upstart init system, drop the
728 @file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
729 file in @file{/etc/init}.}:
730
731 @example
732 # guix-daemon --build-users-group=guixbuild
733 @end example
734
735 @cindex chroot
736 @noindent
737 This way, the daemon starts build processes in a chroot, under one of
738 the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
739 environment contains nothing but:
740
741 @c Keep this list in sync with libstore/build.cc! -----------------------
742 @itemize
743 @item
744 a minimal @code{/dev} directory, created mostly independently from the
745 host @code{/dev}@footnote{``Mostly'', because while the set of files
746 that appear in the chroot's @code{/dev} is fixed, most of these files
747 can only be created if the host has them.};
748
749 @item
750 the @code{/proc} directory; it only shows the processes of the container
751 since a separate PID name space is used;
752
753 @item
754 @file{/etc/passwd} with an entry for the current user and an entry for
755 user @file{nobody};
756
757 @item
758 @file{/etc/group} with an entry for the user's group;
759
760 @item
761 @file{/etc/hosts} with an entry that maps @code{localhost} to
762 @code{127.0.0.1};
763
764 @item
765 a writable @file{/tmp} directory.
766 @end itemize
767
768 You can influence the directory where the daemon stores build trees
769 @i{via} the @code{TMPDIR} environment variable. However, the build tree
770 within the chroot is always called @file{/tmp/guix-build-@var{name}.drv-0},
771 where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
772 This way, the value of @code{TMPDIR} does not leak inside build
773 environments, which avoids discrepancies in cases where build processes
774 capture the name of their build tree.
775
776 @vindex http_proxy
777 The daemon also honors the @code{http_proxy} environment variable for
778 HTTP downloads it performs, be it for fixed-output derivations
779 (@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
780
781 If you are installing Guix as an unprivileged user, it is still possible
782 to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
783 However, build processes will not be isolated from one another, and not
784 from the rest of the system. Thus, build processes may interfere with
785 each other, and may access programs, libraries, and other files
786 available on the system---making it much harder to view them as
787 @emph{pure} functions.
788
789
790 @node Daemon Offload Setup
791 @subsection Using the Offload Facility
792
793 @cindex offloading
794 @cindex build hook
795 When desired, the build daemon can @dfn{offload}
796 derivation builds to other machines
797 running Guix, using the @code{offload} @dfn{build hook}. When that
798 feature is enabled, a list of user-specified build machines is read from
799 @file{/etc/guix/machines.scm}; every time a build is requested, for
800 instance via @code{guix build}, the daemon attempts to offload it to one
801 of the machines that satisfy the constraints of the derivation, in
802 particular its system type---e.g., @file{x86_64-linux}. Missing
803 prerequisites for the build are copied over SSH to the target machine,
804 which then proceeds with the build; upon success the output(s) of the
805 build are copied back to the initial machine.
806
807 The @file{/etc/guix/machines.scm} file typically looks like this:
808
809 @example
810 (list (build-machine
811 (name "eightysix.example.org")
812 (system "x86_64-linux")
813 (user "bob")
814 (speed 2.)) ; incredibly fast!
815
816 (build-machine
817 (name "meeps.example.org")
818 (system "mips64el-linux")
819 (user "alice")
820 (private-key
821 (string-append (getenv "HOME")
822 "/.lsh/identity-for-guix"))))
823 @end example
824
825 @noindent
826 In the example above we specify a list of two build machines, one for
827 the @code{x86_64} architecture and one for the @code{mips64el}
828 architecture.
829
830 In fact, this file is---not surprisingly!---a Scheme file that is
831 evaluated when the @code{offload} hook is started. Its return value
832 must be a list of @code{build-machine} objects. While this example
833 shows a fixed list of build machines, one could imagine, say, using
834 DNS-SD to return a list of potential build machines discovered in the
835 local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
836 Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
837 detailed below.
838
839 @deftp {Data Type} build-machine
840 This data type represents build machines to which the daemon may offload
841 builds. The important fields are:
842
843 @table @code
844
845 @item name
846 The host name of the remote machine.
847
848 @item system
849 The system type of the remote machine---e.g., @code{"x86_64-linux"}.
850
851 @item user
852 The user account to use when connecting to the remote machine over SSH.
853 Note that the SSH key pair must @emph{not} be passphrase-protected, to
854 allow non-interactive logins.
855
856 @end table
857
858 A number of optional fields may be specified:
859
860 @table @code
861
862 @item port
863 Port number of SSH server on the machine (default: 22).
864
865 @item private-key
866 The SSH private key file to use when connecting to the machine.
867
868 Currently offloading uses GNU@tie{}lsh as its SSH client
869 (@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must
870 be an lsh key file. This may change in the future, though.
871
872 @item parallel-builds
873 The number of builds that may run in parallel on the machine (1 by
874 default.)
875
876 @item speed
877 A ``relative speed factor''. The offload scheduler will tend to prefer
878 machines with a higher speed factor.
879
880 @item features
881 A list of strings denoting specific features supported by the machine.
882 An example is @code{"kvm"} for machines that have the KVM Linux modules
883 and corresponding hardware support. Derivations can request features by
884 name, and they will be scheduled on matching build machines.
885
886 @end table
887 @end deftp
888
889 The @code{guix} command must be in the search path on the build
890 machines, since offloading works by invoking the @code{guix archive} and
891 @code{guix build} commands. In addition, the Guix modules must be in
892 @code{$GUILE_LOAD_PATH} on the build machine---you can check whether
893 this is the case by running:
894
895 @example
896 lsh build-machine guile -c "'(use-modules (guix config))'"
897 @end example
898
899 There is one last thing to do once @file{machines.scm} is in place. As
900 explained above, when offloading, files are transferred back and forth
901 between the machine stores. For this to work, you first need to
902 generate a key pair on each machine to allow the daemon to export signed
903 archives of files from the store (@pxref{Invoking guix archive}):
904
905 @example
906 # guix archive --generate-key
907 @end example
908
909 @noindent
910 Each build machine must authorize the key of the master machine so that
911 it accepts store items it receives from the master:
912
913 @example
914 # guix archive --authorize < master-public-key.txt
915 @end example
916
917 @noindent
918 Likewise, the master machine must authorize the key of each build machine.
919
920 All the fuss with keys is here to express pairwise mutual trust
921 relations between the master and the build machines. Concretely, when
922 the master receives files from a build machine (and @i{vice versa}), its
923 build daemon can make sure they are genuine, have not been tampered
924 with, and that they are signed by an authorized key.
925
926
927 @node Invoking guix-daemon
928 @section Invoking @command{guix-daemon}
929
930 The @command{guix-daemon} program implements all the functionality to
931 access the store. This includes launching build processes, running the
932 garbage collector, querying the availability of a build result, etc. It
933 is normally run as @code{root} like this:
934
935 @example
936 # guix-daemon --build-users-group=guixbuild
937 @end example
938
939 @noindent
940 For details on how to set it up, @pxref{Setting Up the Daemon}.
941
942 @cindex chroot
943 @cindex container, build environment
944 @cindex build environment
945 @cindex reproducible builds
946 By default, @command{guix-daemon} launches build processes under
947 different UIDs, taken from the build group specified with
948 @code{--build-users-group}. In addition, each build process is run in a
949 chroot environment that only contains the subset of the store that the
950 build process depends on, as specified by its derivation
951 (@pxref{Programming Interface, derivation}), plus a set of specific
952 system directories. By default, the latter contains @file{/dev} and
953 @file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
954 @dfn{container}: in addition to having its own file system tree, it has
955 a separate mount name space, its own PID name space, network name space,
956 etc. This helps achieve reproducible builds (@pxref{Features}).
957
958 When the daemon performs a build on behalf of the user, it creates a
959 build directory under @file{/tmp} or under the directory specified by
960 its @code{TMPDIR} environment variable; this directory is shared with
961 the container for the duration of the build. Be aware that using a
962 directory other than @file{/tmp} can affect build results---for example,
963 with a longer directory name, a build process that uses Unix-domain
964 sockets might hit the name length limitation for @code{sun_path}, which
965 it would otherwise not hit.
966
967 The build directory is automatically deleted upon completion, unless the
968 build failed and the client specified @option{--keep-failed}
969 (@pxref{Invoking guix build, @option{--keep-failed}}).
970
971 The following command-line options are supported:
972
973 @table @code
974 @item --build-users-group=@var{group}
975 Take users from @var{group} to run build processes (@pxref{Setting Up
976 the Daemon, build users}).
977
978 @item --no-substitutes
979 @cindex substitutes
980 Do not use substitutes for build products. That is, always build things
981 locally instead of allowing downloads of pre-built binaries
982 (@pxref{Substitutes}).
983
984 By default substitutes are used, unless the client---such as the
985 @command{guix package} command---is explicitly invoked with
986 @code{--no-substitutes}.
987
988 When the daemon runs with @code{--no-substitutes}, clients can still
989 explicitly enable substitution @i{via} the @code{set-build-options}
990 remote procedure call (@pxref{The Store}).
991
992 @item --substitute-urls=@var{urls}
993 @anchor{daemon-substitute-urls}
994 Consider @var{urls} the default whitespace-separated list of substitute
995 source URLs. When this option is omitted,
996 @indicateurl{https://mirror.hydra.gnu.org https://hydra.gnu.org} is used
997 (@code{mirror.hydra.gnu.org} is a mirror of @code{hydra.gnu.org}).
998
999 This means that substitutes may be downloaded from @var{urls}, as long
1000 as they are signed by a trusted signature (@pxref{Substitutes}).
1001
1002 @cindex build hook
1003 @item --no-build-hook
1004 Do not use the @dfn{build hook}.
1005
1006 The build hook is a helper program that the daemon can start and to
1007 which it submits build requests. This mechanism is used to offload
1008 builds to other machines (@pxref{Daemon Offload Setup}).
1009
1010 @item --cache-failures
1011 Cache build failures. By default, only successful builds are cached.
1012
1013 When this option is used, @command{guix gc --list-failures} can be used
1014 to query the set of store items marked as failed; @command{guix gc
1015 --clear-failures} removes store items from the set of cached failures.
1016 @xref{Invoking guix gc}.
1017
1018 @item --cores=@var{n}
1019 @itemx -c @var{n}
1020 Use @var{n} CPU cores to build each derivation; @code{0} means as many
1021 as available.
1022
1023 The default value is @code{0}, but it may be overridden by clients, such
1024 as the @code{--cores} option of @command{guix build} (@pxref{Invoking
1025 guix build}).
1026
1027 The effect is to define the @code{NIX_BUILD_CORES} environment variable
1028 in the build process, which can then use it to exploit internal
1029 parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
1030
1031 @item --max-jobs=@var{n}
1032 @itemx -M @var{n}
1033 Allow at most @var{n} build jobs in parallel. The default value is
1034 @code{1}. Setting it to @code{0} means that no builds will be performed
1035 locally; instead, the daemon will offload builds (@pxref{Daemon Offload
1036 Setup}), or simply fail.
1037
1038 @item --rounds=@var{N}
1039 Build each derivation @var{n} times in a row, and raise an error if
1040 consecutive build results are not bit-for-bit identical. Note that this
1041 setting can be overridden by clients such as @command{guix build}
1042 (@pxref{Invoking guix build}).
1043
1044 When used in conjunction with @option{--keep-failed}, the differing
1045 output is kept in the store, under @file{/gnu/store/@dots{}-check}.
1046 This makes it easy to look for differences between the two results.
1047
1048 @item --debug
1049 Produce debugging output.
1050
1051 This is useful to debug daemon start-up issues, but then it may be
1052 overridden by clients, for example the @code{--verbosity} option of
1053 @command{guix build} (@pxref{Invoking guix build}).
1054
1055 @item --chroot-directory=@var{dir}
1056 Add @var{dir} to the build chroot.
1057
1058 Doing this may change the result of build processes---for instance if
1059 they use optional dependencies found in @var{dir} when it is available,
1060 and not otherwise. For that reason, it is not recommended to do so.
1061 Instead, make sure that each derivation declares all the inputs that it
1062 needs.
1063
1064 @item --disable-chroot
1065 Disable chroot builds.
1066
1067 Using this option is not recommended since, again, it would allow build
1068 processes to gain access to undeclared dependencies. It is necessary,
1069 though, when @command{guix-daemon} is running under an unprivileged user
1070 account.
1071
1072 @item --disable-log-compression
1073 Disable compression of the build logs.
1074
1075 Unless @code{--lose-logs} is used, all the build logs are kept in the
1076 @var{localstatedir}. To save space, the daemon automatically compresses
1077 them with bzip2 by default. This option disables that.
1078
1079 @item --disable-deduplication
1080 @cindex deduplication
1081 Disable automatic file ``deduplication'' in the store.
1082
1083 By default, files added to the store are automatically ``deduplicated'':
1084 if a newly added file is identical to another one found in the store,
1085 the daemon makes the new file a hard link to the other file. This can
1086 noticeably reduce disk usage, at the expense of slightly increased
1087 input/output load at the end of a build process. This option disables
1088 this optimization.
1089
1090 @item --gc-keep-outputs[=yes|no]
1091 Tell whether the garbage collector (GC) must keep outputs of live
1092 derivations.
1093
1094 When set to ``yes'', the GC will keep the outputs of any live derivation
1095 available in the store---the @code{.drv} files. The default is ``no'',
1096 meaning that derivation outputs are kept only if they are GC roots.
1097
1098 @item --gc-keep-derivations[=yes|no]
1099 Tell whether the garbage collector (GC) must keep derivations
1100 corresponding to live outputs.
1101
1102 When set to ``yes'', as is the case by default, the GC keeps
1103 derivations---i.e., @code{.drv} files---as long as at least one of their
1104 outputs is live. This allows users to keep track of the origins of
1105 items in their store. Setting it to ``no'' saves a bit of disk space.
1106
1107 Note that when both @code{--gc-keep-derivations} and
1108 @code{--gc-keep-outputs} are used, the effect is to keep all the build
1109 prerequisites (the sources, compiler, libraries, and other build-time
1110 tools) of live objects in the store, regardless of whether these
1111 prerequisites are live. This is convenient for developers since it
1112 saves rebuilds or downloads.
1113
1114 @item --impersonate-linux-2.6
1115 On Linux-based systems, impersonate Linux 2.6. This means that the
1116 kernel's @code{uname} system call will report 2.6 as the release number.
1117
1118 This might be helpful to build programs that (usually wrongfully) depend
1119 on the kernel version number.
1120
1121 @item --lose-logs
1122 Do not keep build logs. By default they are kept under
1123 @code{@var{localstatedir}/guix/log}.
1124
1125 @item --system=@var{system}
1126 Assume @var{system} as the current system type. By default it is the
1127 architecture/kernel pair found at configure time, such as
1128 @code{x86_64-linux}.
1129
1130 @item --listen=@var{socket}
1131 Listen for connections on @var{socket}, the file name of a Unix-domain
1132 socket. The default socket is
1133 @file{@var{localstatedir}/daemon-socket/socket}. This option is only
1134 useful in exceptional circumstances, such as if you need to run several
1135 daemons on the same machine.
1136 @end table
1137
1138
1139 @node Application Setup
1140 @section Application Setup
1141
1142 @cindex foreign distro
1143 When using Guix on top of GNU/Linux distribution other than GuixSD---a
1144 so-called @dfn{foreign distro}---a few additional steps are needed to
1145 get everything in place. Here are some of them.
1146
1147 @subsection Locales
1148
1149 @anchor{locales-and-locpath}
1150 @cindex locales, when not on GuixSD
1151 @vindex LOCPATH
1152 @vindex GUIX_LOCPATH
1153 Packages installed @i{via} Guix will not use the locale data of the
1154 host system. Instead, you must first install one of the locale packages
1155 available with Guix and then define the @code{GUIX_LOCPATH} environment
1156 variable:
1157
1158 @example
1159 $ guix package -i glibc-locales
1160 $ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
1161 @end example
1162
1163 Note that the @code{glibc-locales} package contains data for all the
1164 locales supported by the GNU@tie{}libc and weighs in at around
1165 110@tie{}MiB. Alternatively, the @code{glibc-utf8-locales} is smaller but
1166 limited to a few UTF-8 locales.
1167
1168 The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1169 (@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1170 Manual}). There are two important differences though:
1171
1172 @enumerate
1173 @item
1174 @code{GUIX_LOCPATH} is honored only by the libc in Guix, and not by the libc
1175 provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
1176 to make sure the programs of the foreign distro will not end up loading
1177 incompatible locale data.
1178
1179 @item
1180 libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1181 @code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1182 should your Guix profile contain a mixture of programs linked against
1183 different libc version, each libc version will only try to load locale
1184 data in the right format.
1185 @end enumerate
1186
1187 This is important because the locale data format used by different libc
1188 versions may be incompatible.
1189
1190 @subsection X11 Fonts
1191
1192 The majority of graphical applications use Fontconfig to locate and
1193 load fonts and perform X11-client-side rendering. The @code{fontconfig}
1194 package in Guix looks for fonts in @file{$HOME/.guix-profile}
1195 by default. Thus, to allow graphical applications installed with Guix
1196 to display fonts, you have to install fonts with Guix as well.
1197 Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
1198 @code{font-gnu-freefont-ttf}.
1199
1200 To display text written in Chinese languages, Japanese, or Korean in
1201 graphical applications, consider installing
1202 @code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1203 has multiple outputs, one per language family (@pxref{Packages with
1204 Multiple Outputs}). For instance, the following command installs fonts
1205 for Chinese languages:
1206
1207 @example
1208 guix package -i font-adobe-source-han-sans:cn
1209 @end example
1210
1211 @subsection X.509 Certificates
1212
1213 The @code{nss-certs} package provides X.509 certificates, which allow
1214 programs to authenticate Web servers accessed over HTTPS.
1215
1216 When using Guix on a foreign distro, you can install this package and
1217 define the relevant environment variables so that packages know where to
1218 look for certificates. @pxref{X.509 Certificates}, for detailed
1219 information.
1220
1221 @subsection Emacs Packages
1222
1223 When you install Emacs packages with Guix, the elisp files may be placed
1224 either in @file{$HOME/.guix-profile/share/emacs/site-lisp/} or in
1225 sub-directories of
1226 @file{$HOME/.guix-profile/share/emacs/site-lisp/guix.d/}. The latter
1227 directory exists because potentially there may exist thousands of Emacs
1228 packages and storing all their files in a single directory may be not
1229 reliable (because of name conflicts). So we think using a separate
1230 directory for each package is a good idea. It is very similar to how
1231 the Emacs package system organizes the file structure (@pxref{Package
1232 Files,,, emacs, The GNU Emacs Manual}).
1233
1234 By default, Emacs (installed with Guix) ``knows'' where these packages
1235 are placed, so you do not need to perform any configuration. If, for
1236 some reason, you want to avoid auto-loading Emacs packages installed
1237 with Guix, you can do so by running Emacs with @code{--no-site-file}
1238 option (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
1239
1240 @c TODO What else?
1241
1242 @c *********************************************************************
1243 @node Package Management
1244 @chapter Package Management
1245
1246 The purpose of GNU Guix is to allow users to easily install, upgrade, and
1247 remove software packages, without having to know about their build
1248 procedures or dependencies. Guix also goes beyond this obvious set of
1249 features.
1250
1251 This chapter describes the main features of Guix, as well as the package
1252 management tools it provides. Two user interfaces are provided for
1253 routine package management tasks: A command-line interface described below
1254 (@pxref{Invoking guix package, @code{guix package}}), as well as a visual user
1255 interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}).
1256
1257 @menu
1258 * Features:: How Guix will make your life brighter.
1259 * Invoking guix package:: Package installation, removal, etc.
1260 * Substitutes:: Downloading pre-built binaries.
1261 * Packages with Multiple Outputs:: Single source package, multiple outputs.
1262 * Invoking guix gc:: Running the garbage collector.
1263 * Invoking guix pull:: Fetching the latest Guix and distribution.
1264 * Invoking guix archive:: Exporting and importing store files.
1265 @end menu
1266
1267 @node Features
1268 @section Features
1269
1270 When using Guix, each package ends up in the @dfn{package store}, in its
1271 own directory---something that resembles
1272 @file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
1273 (note that Guix comes with an Emacs extension to shorten those file
1274 names, @pxref{Emacs Prettify}.)
1275
1276 Instead of referring to these directories, users have their own
1277 @dfn{profile}, which points to the packages that they actually want to
1278 use. These profiles are stored within each user's home directory, at
1279 @code{$HOME/.guix-profile}.
1280
1281 For example, @code{alice} installs GCC 4.7.2. As a result,
1282 @file{/home/alice/.guix-profile/bin/gcc} points to
1283 @file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
1284 @code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1285 simply continues to point to
1286 @file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
1287 coexist on the same system without any interference.
1288
1289 The @command{guix package} command is the central tool to manage
1290 packages (@pxref{Invoking guix package}). It operates on the per-user
1291 profiles, and can be used @emph{with normal user privileges}.
1292
1293 The command provides the obvious install, remove, and upgrade
1294 operations. Each invocation is actually a @emph{transaction}: either
1295 the specified operation succeeds, or nothing happens. Thus, if the
1296 @command{guix package} process is terminated during the transaction,
1297 or if a power outage occurs during the transaction, then the user's
1298 profile remains in its previous state, and remains usable.
1299
1300 In addition, any package transaction may be @emph{rolled back}. So, if,
1301 for example, an upgrade installs a new version of a package that turns
1302 out to have a serious bug, users may roll back to the previous instance
1303 of their profile, which was known to work well. Similarly, the global
1304 system configuration on GuixSD is subject to
1305 transactional upgrades and roll-back
1306 (@pxref{Using the Configuration System}).
1307
1308 All packages in the package store may be @emph{garbage-collected}.
1309 Guix can determine which packages are still referenced by user
1310 profiles, and remove those that are provably no longer referenced
1311 (@pxref{Invoking guix gc}). Users may also explicitly remove old
1312 generations of their profile so that the packages they refer to can be
1313 collected.
1314
1315 @cindex reproducibility
1316 @cindex reproducible builds
1317 Finally, Guix takes a @dfn{purely functional} approach to package
1318 management, as described in the introduction (@pxref{Introduction}).
1319 Each @file{/gnu/store} package directory name contains a hash of all the
1320 inputs that were used to build that package---compiler, libraries, build
1321 scripts, etc. This direct correspondence allows users to make sure a
1322 given package installation matches the current state of their
1323 distribution. It also helps maximize @dfn{build reproducibility}:
1324 thanks to the isolated build environments that are used, a given build
1325 is likely to yield bit-identical files when performed on different
1326 machines (@pxref{Invoking guix-daemon, container}).
1327
1328 @cindex substitutes
1329 This foundation allows Guix to support @dfn{transparent binary/source
1330 deployment}. When a pre-built binary for a @file{/gnu/store} item is
1331 available from an external source---a @dfn{substitute}, Guix just
1332 downloads it and unpacks it;
1333 otherwise, it builds the package from source, locally
1334 (@pxref{Substitutes}). Because build results are usually bit-for-bit
1335 reproducible, users do not have to trust servers that provide
1336 substitutes: they can force a local build and @emph{challenge} providers
1337 (@pxref{Invoking guix challenge}).
1338
1339 Control over the build environment is a feature that is also useful for
1340 developers. The @command{guix environment} command allows developers of
1341 a package to quickly set up the right development environment for their
1342 package, without having to manually install the dependencies of the
1343 package into their profile (@pxref{Invoking guix environment}).
1344
1345 @node Invoking guix package
1346 @section Invoking @command{guix package}
1347
1348 The @command{guix package} command is the tool that allows users to
1349 install, upgrade, and remove packages, as well as rolling back to
1350 previous configurations. It operates only on the user's own profile,
1351 and works with normal user privileges (@pxref{Features}). Its syntax
1352 is:
1353
1354 @example
1355 guix package @var{options}
1356 @end example
1357
1358 Primarily, @var{options} specifies the operations to be performed during
1359 the transaction. Upon completion, a new profile is created, but
1360 previous @dfn{generations} of the profile remain available, should the user
1361 want to roll back.
1362
1363 For example, to remove @code{lua} and install @code{guile} and
1364 @code{guile-cairo} in a single transaction:
1365
1366 @example
1367 guix package -r lua -i guile guile-cairo
1368 @end example
1369
1370 @command{guix package} also supports a @dfn{declarative approach}
1371 whereby the user specifies the exact set of packages to be available and
1372 passes it @i{via} the @option{--manifest} option
1373 (@pxref{profile-manifest, @option{--manifest}}).
1374
1375 For each user, a symlink to the user's default profile is automatically
1376 created in @file{$HOME/.guix-profile}. This symlink always points to the
1377 current generation of the user's default profile. Thus, users can add
1378 @file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1379 variable, and so on.
1380 @cindex search paths
1381 If you are not using the Guix System Distribution, consider adding the
1382 following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1383 Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1384 shells get all the right environment variable definitions:
1385
1386 @example
1387 GUIX_PROFILE="$HOME/.guix-profile" \
1388 source "$HOME/.guix-profile/etc/profile"
1389 @end example
1390
1391 In a multi-user setup, user profiles are stored in a place registered as
1392 a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1393 to (@pxref{Invoking guix gc}). That directory is normally
1394 @code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1395 @var{localstatedir} is the value passed to @code{configure} as
1396 @code{--localstatedir}, and @var{user} is the user name. The
1397 @file{per-user} directory is created when @command{guix-daemon} is
1398 started, and the @var{user} sub-directory is created by @command{guix
1399 package}.
1400
1401 The @var{options} can be among the following:
1402
1403 @table @code
1404
1405 @item --install=@var{package} @dots{}
1406 @itemx -i @var{package} @dots{}
1407 Install the specified @var{package}s.
1408
1409 Each @var{package} may specify either a simple package name, such as
1410 @code{guile}, or a package name followed by an at-sign and version number,
1411 such as @code{guile@@1.8.8} or simply @code{guile@@1.8} (in the latter
1412 case, the newest version prefixed by @code{1.8} is selected.)
1413
1414 If no version number is specified, the
1415 newest available version will be selected. In addition, @var{package}
1416 may contain a colon, followed by the name of one of the outputs of the
1417 package, as in @code{gcc:doc} or @code{binutils@@2.22:lib}
1418 (@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1419 name (and optionally version) are searched for among the GNU
1420 distribution modules (@pxref{Package Modules}).
1421
1422 @cindex propagated inputs
1423 Sometimes packages have @dfn{propagated inputs}: these are dependencies
1424 that automatically get installed along with the required package
1425 (@pxref{package-propagated-inputs, @code{propagated-inputs} in
1426 @code{package} objects}, for information about propagated inputs in
1427 package definitions).
1428
1429 @anchor{package-cmd-propagated-inputs}
1430 An example is the GNU MPC library: its C header files refer to those of
1431 the GNU MPFR library, which in turn refer to those of the GMP library.
1432 Thus, when installing MPC, the MPFR and GMP libraries also get installed
1433 in the profile; removing MPC also removes MPFR and GMP---unless they had
1434 also been explicitly installed by the user.
1435
1436 Besides, packages sometimes rely on the definition of environment
1437 variables for their search paths (see explanation of
1438 @code{--search-paths} below). Any missing or possibly incorrect
1439 environment variable definitions are reported here.
1440
1441 @item --install-from-expression=@var{exp}
1442 @itemx -e @var{exp}
1443 Install the package @var{exp} evaluates to.
1444
1445 @var{exp} must be a Scheme expression that evaluates to a
1446 @code{<package>} object. This option is notably useful to disambiguate
1447 between same-named variants of a package, with expressions such as
1448 @code{(@@ (gnu packages base) guile-final)}.
1449
1450 Note that this option installs the first output of the specified
1451 package, which may be insufficient when needing a specific output of a
1452 multiple-output package.
1453
1454 @item --install-from-file=@var{file}
1455 @itemx -f @var{file}
1456 Install the package that the code within @var{file} evaluates to.
1457
1458 As an example, @var{file} might contain a definition like this
1459 (@pxref{Defining Packages}):
1460
1461 @example
1462 @verbatiminclude package-hello.scm
1463 @end example
1464
1465 Developers may find it useful to include such a @file{guix.scm} file
1466 in the root of their project source tree that can be used to test
1467 development snapshots and create reproducible development environments
1468 (@pxref{Invoking guix environment}).
1469
1470 @item --remove=@var{package} @dots{}
1471 @itemx -r @var{package} @dots{}
1472 Remove the specified @var{package}s.
1473
1474 As for @code{--install}, each @var{package} may specify a version number
1475 and/or output name in addition to the package name. For instance,
1476 @code{-r glibc:debug} would remove the @code{debug} output of
1477 @code{glibc}.
1478
1479 @item --upgrade[=@var{regexp} @dots{}]
1480 @itemx -u [@var{regexp} @dots{}]
1481 Upgrade all the installed packages. If one or more @var{regexp}s are
1482 specified, upgrade only installed packages whose name matches a
1483 @var{regexp}. Also see the @code{--do-not-upgrade} option below.
1484
1485 Note that this upgrades package to the latest version of packages found
1486 in the distribution currently installed. To update your distribution,
1487 you should regularly run @command{guix pull} (@pxref{Invoking guix
1488 pull}).
1489
1490 @item --do-not-upgrade[=@var{regexp} @dots{}]
1491 When used together with the @code{--upgrade} option, do @emph{not}
1492 upgrade any packages whose name matches a @var{regexp}. For example, to
1493 upgrade all packages in the current profile except those containing the
1494 substring ``emacs'':
1495
1496 @example
1497 $ guix package --upgrade . --do-not-upgrade emacs
1498 @end example
1499
1500 @item @anchor{profile-manifest}--manifest=@var{file}
1501 @itemx -m @var{file}
1502 @cindex profile declaration
1503 @cindex profile manifest
1504 Create a new generation of the profile from the manifest object
1505 returned by the Scheme code in @var{file}.
1506
1507 This allows you to @emph{declare} the profile's contents rather than
1508 constructing it through a sequence of @code{--install} and similar
1509 commands. The advantage is that @var{file} can be put under version
1510 control, copied to different machines to reproduce the same profile, and
1511 so on.
1512
1513 @c FIXME: Add reference to (guix profile) documentation when available.
1514 @var{file} must return a @dfn{manifest} object, which is roughly a list
1515 of packages:
1516
1517 @findex packages->manifest
1518 @example
1519 (use-package-modules guile emacs)
1520
1521 (packages->manifest
1522 (list emacs
1523 guile-2.0
1524 ;; Use a specific package output.
1525 (list guile-2.0 "debug")))
1526 @end example
1527
1528 @item --roll-back
1529 Roll back to the previous @dfn{generation} of the profile---i.e., undo
1530 the last transaction.
1531
1532 When combined with options such as @code{--install}, roll back occurs
1533 before any other actions.
1534
1535 When rolling back from the first generation that actually contains
1536 installed packages, the profile is made to point to the @dfn{zeroth
1537 generation}, which contains no files apart from its own metadata.
1538
1539 After having rolled back, installing, removing, or upgrading packages
1540 overwrites previous future generations. Thus, the history of the
1541 generations in a profile is always linear.
1542
1543 @item --switch-generation=@var{pattern}
1544 @itemx -S @var{pattern}
1545 Switch to a particular generation defined by @var{pattern}.
1546
1547 @var{pattern} may be either a generation number or a number prefixed
1548 with ``+'' or ``-''. The latter means: move forward/backward by a
1549 specified number of generations. For example, if you want to return to
1550 the latest generation after @code{--roll-back}, use
1551 @code{--switch-generation=+1}.
1552
1553 The difference between @code{--roll-back} and
1554 @code{--switch-generation=-1} is that @code{--switch-generation} will
1555 not make a zeroth generation, so if a specified generation does not
1556 exist, the current generation will not be changed.
1557
1558 @item --search-paths[=@var{kind}]
1559 @cindex search paths
1560 Report environment variable definitions, in Bash syntax, that may be
1561 needed in order to use the set of installed packages. These environment
1562 variables are used to specify @dfn{search paths} for files used by some
1563 of the installed packages.
1564
1565 For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1566 environment variables to be defined so it can look for headers and
1567 libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1568 Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1569 library are installed in the profile, then @code{--search-paths} will
1570 suggest setting these variables to @code{@var{profile}/include} and
1571 @code{@var{profile}/lib}, respectively.
1572
1573 The typical use case is to define these environment variables in the
1574 shell:
1575
1576 @example
1577 $ eval `guix package --search-paths`
1578 @end example
1579
1580 @var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1581 meaning that the returned environment variable definitions will either
1582 be exact settings, or prefixes or suffixes of the current value of these
1583 variables. When omitted, @var{kind} defaults to @code{exact}.
1584
1585 This option can also be used to compute the @emph{combined} search paths
1586 of several profiles. Consider this example:
1587
1588 @example
1589 $ guix package -p foo -i guile
1590 $ guix package -p bar -i guile-json
1591 $ guix package -p foo -p bar --search-paths
1592 @end example
1593
1594 The last command above reports about the @code{GUILE_LOAD_PATH}
1595 variable, even though, taken individually, neither @file{foo} nor
1596 @file{bar} would lead to that recommendation.
1597
1598
1599 @item --profile=@var{profile}
1600 @itemx -p @var{profile}
1601 Use @var{profile} instead of the user's default profile.
1602
1603 @item --verbose
1604 Produce verbose output. In particular, emit the build log of the
1605 environment on the standard error port.
1606
1607 @item --bootstrap
1608 Use the bootstrap Guile to build the profile. This option is only
1609 useful to distribution developers.
1610
1611 @end table
1612
1613 In addition to these actions, @command{guix package} supports the
1614 following options to query the current state of a profile, or the
1615 availability of packages:
1616
1617 @table @option
1618
1619 @item --search=@var{regexp}
1620 @itemx -s @var{regexp}
1621 @cindex searching for packages
1622 List the available packages whose name, synopsis, or description matches
1623 @var{regexp}. Print all the metadata of matching packages in
1624 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1625 GNU recutils manual}).
1626
1627 This allows specific fields to be extracted using the @command{recsel}
1628 command, for instance:
1629
1630 @example
1631 $ guix package -s malloc | recsel -p name,version
1632 name: glibc
1633 version: 2.17
1634
1635 name: libgc
1636 version: 7.2alpha6
1637 @end example
1638
1639 Similarly, to show the name of all the packages available under the
1640 terms of the GNU@tie{}LGPL version 3:
1641
1642 @example
1643 $ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1644 name: elfutils
1645
1646 name: gmp
1647 @dots{}
1648 @end example
1649
1650 It is also possible to refine search results using several @code{-s}
1651 flags. For example, the following command returns a list of board
1652 games:
1653
1654 @example
1655 $ guix package -s '\<board\>' -s game | recsel -p name
1656 name: gnubg
1657 @dots{}
1658 @end example
1659
1660 If we were to omit @code{-s game}, we would also get software packages
1661 that deal with printed circuit boards; removing the angle brackets
1662 around @code{board} would further add packages that have to do with
1663 keyboards.
1664
1665 And now for a more elaborate example. The following command searches
1666 for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1667 libraries, and prints the name and synopsis of the matching packages:
1668
1669 @example
1670 $ guix package -s crypto -s library | \
1671 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1672 @end example
1673
1674 @noindent
1675 @xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1676 information on @dfn{selection expressions} for @code{recsel -e}.
1677
1678 @item --show=@var{package}
1679 Show details about @var{package}, taken from the list of available packages, in
1680 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1681 recutils manual}).
1682
1683 @example
1684 $ guix package --show=python | recsel -p name,version
1685 name: python
1686 version: 2.7.6
1687
1688 name: python
1689 version: 3.3.5
1690 @end example
1691
1692 You may also specify the full name of a package to only get details about a
1693 specific version of it:
1694 @example
1695 $ guix package --show=python-3.3.5 | recsel -p name,version
1696 name: python
1697 version: 3.3.5
1698 @end example
1699
1700
1701
1702 @item --list-installed[=@var{regexp}]
1703 @itemx -I [@var{regexp}]
1704 List the currently installed packages in the specified profile, with the
1705 most recently installed packages shown last. When @var{regexp} is
1706 specified, list only installed packages whose name matches @var{regexp}.
1707
1708 For each installed package, print the following items, separated by
1709 tabs: the package name, its version string, the part of the package that
1710 is installed (for instance, @code{out} for the default output,
1711 @code{include} for its headers, etc.), and the path of this package in
1712 the store.
1713
1714 @item --list-available[=@var{regexp}]
1715 @itemx -A [@var{regexp}]
1716 List packages currently available in the distribution for this system
1717 (@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1718 installed packages whose name matches @var{regexp}.
1719
1720 For each package, print the following items separated by tabs: its name,
1721 its version string, the parts of the package (@pxref{Packages with
1722 Multiple Outputs}), and the source location of its definition.
1723
1724 @item --list-generations[=@var{pattern}]
1725 @itemx -l [@var{pattern}]
1726 Return a list of generations along with their creation dates; for each
1727 generation, show the installed packages, with the most recently
1728 installed packages shown last. Note that the zeroth generation is never
1729 shown.
1730
1731 For each installed package, print the following items, separated by
1732 tabs: the name of a package, its version string, the part of the package
1733 that is installed (@pxref{Packages with Multiple Outputs}), and the
1734 location of this package in the store.
1735
1736 When @var{pattern} is used, the command returns only matching
1737 generations. Valid patterns include:
1738
1739 @itemize
1740 @item @emph{Integers and comma-separated integers}. Both patterns denote
1741 generation numbers. For instance, @code{--list-generations=1} returns
1742 the first one.
1743
1744 And @code{--list-generations=1,8,2} outputs three generations in the
1745 specified order. Neither spaces nor trailing commas are allowed.
1746
1747 @item @emph{Ranges}. @code{--list-generations=2..9} prints the
1748 specified generations and everything in between. Note that the start of
1749 a range must be smaller than its end.
1750
1751 It is also possible to omit the endpoint. For example,
1752 @code{--list-generations=2..}, returns all generations starting from the
1753 second one.
1754
1755 @item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1756 or months by passing an integer along with the first letter of the
1757 duration. For example, @code{--list-generations=20d} lists generations
1758 that are up to 20 days old.
1759 @end itemize
1760
1761 @item --delete-generations[=@var{pattern}]
1762 @itemx -d [@var{pattern}]
1763 When @var{pattern} is omitted, delete all generations except the current
1764 one.
1765
1766 This command accepts the same patterns as @option{--list-generations}.
1767 When @var{pattern} is specified, delete the matching generations. When
1768 @var{pattern} specifies a duration, generations @emph{older} than the
1769 specified duration match. For instance, @code{--delete-generations=1m}
1770 deletes generations that are more than one month old.
1771
1772 If the current generation matches, it is @emph{not} deleted. Also, the
1773 zeroth generation is never deleted.
1774
1775 Note that deleting generations prevents rolling back to them.
1776 Consequently, this command must be used with care.
1777
1778 @end table
1779
1780 Finally, since @command{guix package} may actually start build
1781 processes, it supports all the common build options (@pxref{Common Build
1782 Options}). It also supports package transformation options, such as
1783 @option{--with-source} (@pxref{Package Transformation Options}).
1784 However, note that package transformations are lost when upgrading; to
1785 preserve transformations across upgrades, you should define your own
1786 package variant in a Guile module and add it to @code{GUIX_PACKAGE_PATH}
1787 (@pxref{Defining Packages}).
1788
1789
1790 @node Substitutes
1791 @section Substitutes
1792
1793 @cindex substitutes
1794 @cindex pre-built binaries
1795 Guix supports transparent source/binary deployment, which means that it
1796 can either build things locally, or download pre-built items from a
1797 server. We call these pre-built items @dfn{substitutes}---they are
1798 substitutes for local build results. In many cases, downloading a
1799 substitute is much faster than building things locally.
1800
1801 Substitutes can be anything resulting from a derivation build
1802 (@pxref{Derivations}). Of course, in the common case, they are
1803 pre-built package binaries, but source tarballs, for instance, which
1804 also result from derivation builds, can be available as substitutes.
1805
1806 The @code{hydra.gnu.org} server is a front-end to a build farm that
1807 builds packages from the GNU distribution continuously for some
1808 architectures, and makes them available as substitutes (@pxref{Emacs
1809 Hydra}, for information on how to query the continuous integration
1810 server). This is the
1811 default source of substitutes; it can be overridden by passing the
1812 @option{--substitute-urls} option either to @command{guix-daemon}
1813 (@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1814 or to client tools such as @command{guix package}
1815 (@pxref{client-substitute-urls,, client @option{--substitute-urls}
1816 option}).
1817
1818 Substitute URLs can be either HTTP or HTTPS@footnote{For HTTPS access,
1819 the Guile bindings of GnuTLS must be installed. @xref{Requirements}.}
1820 HTTPS is recommended because communications are encrypted; conversely,
1821 using HTTP makes all communications visible to an eavesdropper, who
1822 could use the information gathered to determine, for instance, whether
1823 your system has unpatched security vulnerabilities.
1824
1825 @cindex security
1826 @cindex digital signatures
1827 To allow Guix to download substitutes from @code{hydra.gnu.org} or a
1828 mirror thereof, you
1829 must add its public key to the access control list (ACL) of archive
1830 imports, using the @command{guix archive} command (@pxref{Invoking guix
1831 archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1832 be compromised and to serve genuine substitutes.
1833
1834 This public key is installed along with Guix, in
1835 @code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1836 the installation prefix of Guix. If you installed Guix from source,
1837 make sure you checked the GPG signature of
1838 @file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1839 Then, you can run something like this:
1840
1841 @example
1842 # guix archive --authorize < hydra.gnu.org.pub
1843 @end example
1844
1845 Once this is in place, the output of a command like @code{guix build}
1846 should change from something like:
1847
1848 @example
1849 $ guix build emacs --dry-run
1850 The following derivations would be built:
1851 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1852 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1853 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1854 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1855 @dots{}
1856 @end example
1857
1858 @noindent
1859 to something like:
1860
1861 @example
1862 $ guix build emacs --dry-run
1863 The following files would be downloaded:
1864 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1865 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1866 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1867 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1868 @dots{}
1869 @end example
1870
1871 @noindent
1872 This indicates that substitutes from @code{hydra.gnu.org} are usable and
1873 will be downloaded, when possible, for future builds.
1874
1875 Guix ignores substitutes that are not signed, or that are not signed by
1876 one of the keys listed in the ACL. It also detects and raises an error
1877 when attempting to use a substitute that has been tampered with.
1878
1879 @vindex http_proxy
1880 Substitutes are downloaded over HTTP or HTTPS.
1881 The @code{http_proxy} environment
1882 variable can be set in the environment of @command{guix-daemon} and is
1883 honored for downloads of substitutes. Note that the value of
1884 @code{http_proxy} in the environment where @command{guix build},
1885 @command{guix package}, and other client commands are run has
1886 @emph{absolutely no effect}.
1887
1888 When using HTTPS, the server's X.509 certificate is @emph{not} validated
1889 (in other words, the server is not authenticated), contrary to what
1890 HTTPS clients such as Web browsers usually do. This is because Guix
1891 authenticates substitute information itself, as explained above, which
1892 is what we care about (whereas X.509 certificates are about
1893 authenticating bindings between domain names and public keys.)
1894
1895 The substitute mechanism can be disabled globally by running
1896 @code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1897 guix-daemon}). It can also be disabled temporarily by passing the
1898 @code{--no-substitutes} option to @command{guix package}, @command{guix
1899 build}, and other command-line tools.
1900
1901
1902 @unnumberedsubsec On Trusting Binaries
1903
1904 Today, each individual's control over their own computing is at the
1905 mercy of institutions, corporations, and groups with enough power and
1906 determination to subvert the computing infrastructure and exploit its
1907 weaknesses. While using @code{hydra.gnu.org} substitutes can be
1908 convenient, we encourage users to also build on their own, or even run
1909 their own build farm, such that @code{hydra.gnu.org} is less of an
1910 interesting target. One way to help is by publishing the software you
1911 build using @command{guix publish} so that others have one more choice
1912 of server to download substitutes from (@pxref{Invoking guix publish}).
1913
1914 Guix has the foundations to maximize build reproducibility
1915 (@pxref{Features}). In most cases, independent builds of a given
1916 package or derivation should yield bit-identical results. Thus, through
1917 a diverse set of independent package builds, we can strengthen the
1918 integrity of our systems. The @command{guix challenge} command aims to
1919 help users assess substitute servers, and to assist developers in
1920 finding out about non-deterministic package builds (@pxref{Invoking guix
1921 challenge}). Similarly, the @option{--check} option of @command{guix
1922 build} allows users to check whether previously-installed substitutes
1923 are genuine by rebuilding them locally (@pxref{build-check,
1924 @command{guix build --check}}).
1925
1926 In the future, we want Guix to have support to publish and retrieve
1927 binaries to/from other users, in a peer-to-peer fashion. If you would
1928 like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1929
1930
1931 @node Packages with Multiple Outputs
1932 @section Packages with Multiple Outputs
1933
1934 @cindex multiple-output packages
1935 @cindex package outputs
1936
1937 Often, packages defined in Guix have a single @dfn{output}---i.e., the
1938 source package leads to exactly one directory in the store. When running
1939 @command{guix package -i glibc}, one installs the default output of the
1940 GNU libc package; the default output is called @code{out}, but its name
1941 can be omitted as shown in this command. In this particular case, the
1942 default output of @code{glibc} contains all the C header files, shared
1943 libraries, static libraries, Info documentation, and other supporting
1944 files.
1945
1946 Sometimes it is more appropriate to separate the various types of files
1947 produced from a single source package into separate outputs. For
1948 instance, the GLib C library (used by GTK+ and related packages)
1949 installs more than 20 MiB of reference documentation as HTML pages.
1950 To save space for users who do not need it, the documentation goes to a
1951 separate output, called @code{doc}. To install the main GLib output,
1952 which contains everything but the documentation, one would run:
1953
1954 @example
1955 guix package -i glib
1956 @end example
1957
1958 The command to install its documentation is:
1959
1960 @example
1961 guix package -i glib:doc
1962 @end example
1963
1964 Some packages install programs with different ``dependency footprints''.
1965 For instance, the WordNet package installs both command-line tools and
1966 graphical user interfaces (GUIs). The former depend solely on the C
1967 library, whereas the latter depend on Tcl/Tk and the underlying X
1968 libraries. In this case, we leave the command-line tools in the default
1969 output, whereas the GUIs are in a separate output. This allows users
1970 who do not need the GUIs to save space. The @command{guix size} command
1971 can help find out about such situations (@pxref{Invoking guix size}).
1972 @command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
1973
1974 There are several such multiple-output packages in the GNU distribution.
1975 Other conventional output names include @code{lib} for libraries and
1976 possibly header files, @code{bin} for stand-alone programs, and
1977 @code{debug} for debugging information (@pxref{Installing Debugging
1978 Files}). The outputs of a packages are listed in the third column of
1979 the output of @command{guix package --list-available} (@pxref{Invoking
1980 guix package}).
1981
1982
1983 @node Invoking guix gc
1984 @section Invoking @command{guix gc}
1985
1986 @cindex garbage collector
1987 Packages that are installed, but not used, may be @dfn{garbage-collected}.
1988 The @command{guix gc} command allows users to explicitly run the garbage
1989 collector to reclaim space from the @file{/gnu/store} directory. It is
1990 the @emph{only} way to remove files from @file{/gnu/store}---removing
1991 files or directories manually may break it beyond repair!
1992
1993 The garbage collector has a set of known @dfn{roots}: any file under
1994 @file{/gnu/store} reachable from a root is considered @dfn{live} and
1995 cannot be deleted; any other file is considered @dfn{dead} and may be
1996 deleted. The set of garbage collector roots includes default user
1997 profiles, and may be augmented with @command{guix build --root}, for
1998 example (@pxref{Invoking guix build}).
1999
2000 Prior to running @code{guix gc --collect-garbage} to make space, it is
2001 often useful to remove old generations from user profiles; that way, old
2002 package builds referenced by those generations can be reclaimed. This
2003 is achieved by running @code{guix package --delete-generations}
2004 (@pxref{Invoking guix package}).
2005
2006 The @command{guix gc} command has three modes of operation: it can be
2007 used to garbage-collect any dead files (the default), to delete specific
2008 files (the @code{--delete} option), to print garbage-collector
2009 information, or for more advanced queries. The garbage collection
2010 options are as follows:
2011
2012 @table @code
2013 @item --collect-garbage[=@var{min}]
2014 @itemx -C [@var{min}]
2015 Collect garbage---i.e., unreachable @file{/gnu/store} files and
2016 sub-directories. This is the default operation when no option is
2017 specified.
2018
2019 When @var{min} is given, stop once @var{min} bytes have been collected.
2020 @var{min} may be a number of bytes, or it may include a unit as a
2021 suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
2022 (@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
2023
2024 When @var{min} is omitted, collect all the garbage.
2025
2026 @item --free-space=@var{free}
2027 @itemx -F @var{free}
2028 Collect garbage until @var{free} space is available under
2029 @file{/gnu/store}, if possible; @var{free} denotes storage space, such
2030 as @code{500MiB}, as described above.
2031
2032 When @var{free} or more is already available in @file{/gnu/store}, do
2033 nothing and exit immediately.
2034
2035 @item --delete
2036 @itemx -d
2037 Attempt to delete all the store files and directories specified as
2038 arguments. This fails if some of the files are not in the store, or if
2039 they are still live.
2040
2041 @item --list-failures
2042 List store items corresponding to cached build failures.
2043
2044 This prints nothing unless the daemon was started with
2045 @option{--cache-failures} (@pxref{Invoking guix-daemon,
2046 @option{--cache-failures}}).
2047
2048 @item --clear-failures
2049 Remove the specified store items from the failed-build cache.
2050
2051 Again, this option only makes sense when the daemon is started with
2052 @option{--cache-failures}. Otherwise, it does nothing.
2053
2054 @item --list-dead
2055 Show the list of dead files and directories still present in the
2056 store---i.e., files and directories no longer reachable from any root.
2057
2058 @item --list-live
2059 Show the list of live store files and directories.
2060
2061 @end table
2062
2063 In addition, the references among existing store files can be queried:
2064
2065 @table @code
2066
2067 @item --references
2068 @itemx --referrers
2069 List the references (respectively, the referrers) of store files given
2070 as arguments.
2071
2072 @item --requisites
2073 @itemx -R
2074 @cindex closure
2075 List the requisites of the store files passed as arguments. Requisites
2076 include the store files themselves, their references, and the references
2077 of these, recursively. In other words, the returned list is the
2078 @dfn{transitive closure} of the store files.
2079
2080 @xref{Invoking guix size}, for a tool to profile the size of the closure
2081 of an element. @xref{Invoking guix graph}, for a tool to visualize
2082 the graph of references.
2083
2084 @end table
2085
2086 Lastly, the following options allow you to check the integrity of the
2087 store and to control disk usage.
2088
2089 @table @option
2090
2091 @item --verify[=@var{options}]
2092 @cindex integrity, of the store
2093 @cindex integrity checking
2094 Verify the integrity of the store.
2095
2096 By default, make sure that all the store items marked as valid in the
2097 database of the daemon actually exist in @file{/gnu/store}.
2098
2099 When provided, @var{options} must be a comma-separated list containing one
2100 or more of @code{contents} and @code{repair}.
2101
2102 When passing @option{--verify=contents}, the daemon computse the
2103 content hash of each store item and compares it against its hash in the
2104 database. Hash mismatches are reported as data corruptions. Because it
2105 traverses @emph{all the files in the store}, this command can take a
2106 long time, especially on systems with a slow disk drive.
2107
2108 @cindex repairing the store
2109 Using @option{--verify=repair} or @option{--verify=contents,repair}
2110 causes the daemon to try to repair corrupt store items by fetching
2111 substitutes for them (@pxref{Substitutes}). Because repairing is not
2112 atomic, and thus potentially dangerous, it is available only to the
2113 system administrator.
2114
2115 @item --optimize
2116 @cindex deduplication
2117 Optimize the store by hard-linking identical files---this is
2118 @dfn{deduplication}.
2119
2120 The daemon performs deduplication after each successful build or archive
2121 import, unless it was started with @code{--disable-deduplication}
2122 (@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
2123 this option is primarily useful when the daemon was running with
2124 @code{--disable-deduplication}.
2125
2126 @end table
2127
2128 @node Invoking guix pull
2129 @section Invoking @command{guix pull}
2130
2131 Packages are installed or upgraded to the latest version available in
2132 the distribution currently available on your local machine. To update
2133 that distribution, along with the Guix tools, you must run @command{guix
2134 pull}: the command downloads the latest Guix source code and package
2135 descriptions, and deploys it.
2136
2137 On completion, @command{guix package} will use packages and package
2138 versions from this just-retrieved copy of Guix. Not only that, but all
2139 the Guix commands and Scheme modules will also be taken from that latest
2140 version. New @command{guix} sub-commands added by the update also
2141 become available.
2142
2143 Any user can update their Guix copy using @command{guix pull}, and the
2144 effect is limited to the user who run @command{guix pull}. For
2145 instance, when user @code{root} runs @command{guix pull}, this has no
2146 effect on the version of Guix that user @code{alice} sees, and vice
2147 versa@footnote{Under the hood, @command{guix pull} updates the
2148 @file{~/.config/guix/latest} symbolic link to point to the latest Guix,
2149 and the @command{guix} command loads code from there.}.
2150
2151 The @command{guix pull} command is usually invoked with no arguments,
2152 but it supports the following options:
2153
2154 @table @code
2155 @item --verbose
2156 Produce verbose output, writing build logs to the standard error output.
2157
2158 @item --url=@var{url}
2159 Download the source tarball of Guix from @var{url}.
2160
2161 By default, the tarball is taken from its canonical address at
2162 @code{gnu.org}, for the stable branch of Guix.
2163
2164 @item --bootstrap
2165 Use the bootstrap Guile to build the latest Guix. This option is only
2166 useful to Guix developers.
2167 @end table
2168
2169
2170 @node Invoking guix archive
2171 @section Invoking @command{guix archive}
2172
2173 The @command{guix archive} command allows users to @dfn{export} files
2174 from the store into a single archive, and to later @dfn{import} them.
2175 In particular, it allows store files to be transferred from one machine
2176 to the store on another machine.
2177
2178 To export store files as an archive to standard output, run:
2179
2180 @example
2181 guix archive --export @var{options} @var{specifications}...
2182 @end example
2183
2184 @var{specifications} may be either store file names or package
2185 specifications, as for @command{guix package} (@pxref{Invoking guix
2186 package}). For instance, the following command creates an archive
2187 containing the @code{gui} output of the @code{git} package and the main
2188 output of @code{emacs}:
2189
2190 @example
2191 guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
2192 @end example
2193
2194 If the specified packages are not built yet, @command{guix archive}
2195 automatically builds them. The build process may be controlled with the
2196 common build options (@pxref{Common Build Options}).
2197
2198 To transfer the @code{emacs} package to a machine connected over SSH,
2199 one would run:
2200
2201 @example
2202 guix archive --export -r emacs | ssh the-machine guix archive --import
2203 @end example
2204
2205 @noindent
2206 Similarly, a complete user profile may be transferred from one machine
2207 to another like this:
2208
2209 @example
2210 guix archive --export -r $(readlink -f ~/.guix-profile) | \
2211 ssh the-machine guix-archive --import
2212 @end example
2213
2214 @noindent
2215 However, note that, in both examples, all of @code{emacs} and the
2216 profile as well as all of their dependencies are transferred (due to
2217 @code{-r}), regardless of what is already available in the store on the
2218 target machine. The @code{--missing} option can help figure out which
2219 items are missing from the target store.
2220
2221 Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
2222 comparable in spirit to `tar', but with a few noteworthy differences
2223 that make it more appropriate for our purposes. First, rather than
2224 recording all Unix metadata for each file, the Nar format only mentions
2225 the file type (regular, directory, or symbolic link); Unix permissions
2226 and owner/group are dismissed. Second, the order in which directory
2227 entries are stored always follows the order of file names according to
2228 the C locale collation order. This makes archive production fully
2229 deterministic.
2230
2231 When exporting, the daemon digitally signs the contents of the archive,
2232 and that digital signature is appended. When importing, the daemon
2233 verifies the signature and rejects the import in case of an invalid
2234 signature or if the signing key is not authorized.
2235 @c FIXME: Add xref to daemon doc about signatures.
2236
2237 The main options are:
2238
2239 @table @code
2240 @item --export
2241 Export the specified store files or packages (see below.) Write the
2242 resulting archive to the standard output.
2243
2244 Dependencies are @emph{not} included in the output, unless
2245 @code{--recursive} is passed.
2246
2247 @item -r
2248 @itemx --recursive
2249 When combined with @code{--export}, this instructs @command{guix
2250 archive} to include dependencies of the given items in the archive.
2251 Thus, the resulting archive is self-contained: it contains the closure
2252 of the exported store items.
2253
2254 @item --import
2255 Read an archive from the standard input, and import the files listed
2256 therein into the store. Abort if the archive has an invalid digital
2257 signature, or if it is signed by a public key not among the authorized
2258 keys (see @code{--authorize} below.)
2259
2260 @item --missing
2261 Read a list of store file names from the standard input, one per line,
2262 and write on the standard output the subset of these files missing from
2263 the store.
2264
2265 @item --generate-key[=@var{parameters}]
2266 @cindex signing, archives
2267 Generate a new key pair for the daemon. This is a prerequisite before
2268 archives can be exported with @code{--export}. Note that this operation
2269 usually takes time, because it needs to gather enough entropy to
2270 generate the key pair.
2271
2272 The generated key pair is typically stored under @file{/etc/guix}, in
2273 @file{signing-key.pub} (public key) and @file{signing-key.sec} (private
2274 key, which must be kept secret.) When @var{parameters} is omitted,
2275 an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2276 versions before 1.6.0, it is a 4096-bit RSA key.
2277 Alternatively, @var{parameters} can specify
2278 @code{genkey} parameters suitable for Libgcrypt (@pxref{General
2279 public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2280 Libgcrypt Reference Manual}).
2281
2282 @item --authorize
2283 @cindex authorizing, archives
2284 Authorize imports signed by the public key passed on standard input.
2285 The public key must be in ``s-expression advanced format''---i.e., the
2286 same format as the @file{signing-key.pub} file.
2287
2288 The list of authorized keys is kept in the human-editable file
2289 @file{/etc/guix/acl}. The file contains
2290 @url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2291 s-expressions''} and is structured as an access-control list in the
2292 @url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2293 (SPKI)}.
2294
2295 @item --extract=@var{directory}
2296 @itemx -x @var{directory}
2297 Read a single-item archive as served by substitute servers
2298 (@pxref{Substitutes}) and extract it to @var{directory}. This is a
2299 low-level operation needed in only very narrow use cases; see below.
2300
2301 For example, the following command extracts the substitute for Emacs
2302 served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2303
2304 @example
2305 $ wget -O - \
2306 https://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
2307 | bunzip2 | guix archive -x /tmp/emacs
2308 @end example
2309
2310 Single-item archives are different from multiple-item archives produced
2311 by @command{guix archive --export}; they contain a single store item,
2312 and they do @emph{not} embed a signature. Thus this operation does
2313 @emph{no} signature verification and its output should be considered
2314 unsafe.
2315
2316 The primary purpose of this operation is to facilitate inspection of
2317 archive contents coming from possibly untrusted substitute servers.
2318
2319 @end table
2320
2321 @c *********************************************************************
2322 @include emacs.texi
2323
2324 @c *********************************************************************
2325 @node Programming Interface
2326 @chapter Programming Interface
2327
2328 GNU Guix provides several Scheme programming interfaces (APIs) to
2329 define, build, and query packages. The first interface allows users to
2330 write high-level package definitions. These definitions refer to
2331 familiar packaging concepts, such as the name and version of a package,
2332 its build system, and its dependencies. These definitions can then be
2333 turned into concrete build actions.
2334
2335 Build actions are performed by the Guix daemon, on behalf of users. In a
2336 standard setup, the daemon has write access to the store---the
2337 @file{/gnu/store} directory---whereas users do not. The recommended
2338 setup also has the daemon perform builds in chroots, under a specific
2339 build users, to minimize interference with the rest of the system.
2340
2341 @cindex derivation
2342 Lower-level APIs are available to interact with the daemon and the
2343 store. To instruct the daemon to perform a build action, users actually
2344 provide it with a @dfn{derivation}. A derivation is a low-level
2345 representation of the build actions to be taken, and the environment in
2346 which they should occur---derivations are to package definitions what
2347 assembly is to C programs. The term ``derivation'' comes from the fact
2348 that build results @emph{derive} from them.
2349
2350 This chapter describes all these APIs in turn, starting from high-level
2351 package definitions.
2352
2353 @menu
2354 * Defining Packages:: Defining new packages.
2355 * Build Systems:: Specifying how packages are built.
2356 * The Store:: Manipulating the package store.
2357 * Derivations:: Low-level interface to package derivations.
2358 * The Store Monad:: Purely functional interface to the store.
2359 * G-Expressions:: Manipulating build expressions.
2360 @end menu
2361
2362 @node Defining Packages
2363 @section Defining Packages
2364
2365 The high-level interface to package definitions is implemented in the
2366 @code{(guix packages)} and @code{(guix build-system)} modules. As an
2367 example, the package definition, or @dfn{recipe}, for the GNU Hello
2368 package looks like this:
2369
2370 @example
2371 (define-module (gnu packages hello)
2372 #:use-module (guix packages)
2373 #:use-module (guix download)
2374 #:use-module (guix build-system gnu)
2375 #:use-module (guix licenses)
2376 #:use-module (gnu packages gawk))
2377
2378 (define-public hello
2379 (package
2380 (name "hello")
2381 (version "2.10")
2382 (source (origin
2383 (method url-fetch)
2384 (uri (string-append "mirror://gnu/hello/hello-" version
2385 ".tar.gz"))
2386 (sha256
2387 (base32
2388 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
2389 (build-system gnu-build-system)
2390 (arguments '(#:configure-flags '("--enable-silent-rules")))
2391 (inputs `(("gawk" ,gawk)))
2392 (synopsis "Hello, GNU world: An example GNU package")
2393 (description "Guess what GNU Hello prints!")
2394 (home-page "http://www.gnu.org/software/hello/")
2395 (license gpl3+)))
2396 @end example
2397
2398 @noindent
2399 Without being a Scheme expert, the reader may have guessed the meaning
2400 of the various fields here. This expression binds the variable
2401 @code{hello} to a @code{<package>} object, which is essentially a record
2402 (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2403 This package object can be inspected using procedures found in the
2404 @code{(guix packages)} module; for instance, @code{(package-name hello)}
2405 returns---surprise!---@code{"hello"}.
2406
2407 With luck, you may be able to import part or all of the definition of
2408 the package you are interested in from another repository, using the
2409 @code{guix import} command (@pxref{Invoking guix import}).
2410
2411 In the example above, @var{hello} is defined in a module of its own,
2412 @code{(gnu packages hello)}. Technically, this is not strictly
2413 necessary, but it is convenient to do so: all the packages defined in
2414 modules under @code{(gnu packages @dots{})} are automatically known to
2415 the command-line tools (@pxref{Package Modules}).
2416
2417 There are a few points worth noting in the above package definition:
2418
2419 @itemize
2420 @item
2421 The @code{source} field of the package is an @code{<origin>} object
2422 (@pxref{origin Reference}, for the complete reference).
2423 Here, the @code{url-fetch} method from @code{(guix download)} is used,
2424 meaning that the source is a file to be downloaded over FTP or HTTP.
2425
2426 The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2427 the GNU mirrors defined in @code{(guix download)}.
2428
2429 The @code{sha256} field specifies the expected SHA256 hash of the file
2430 being downloaded. It is mandatory, and allows Guix to check the
2431 integrity of the file. The @code{(base32 @dots{})} form introduces the
2432 base32 representation of the hash. You can obtain this information with
2433 @code{guix download} (@pxref{Invoking guix download}) and @code{guix
2434 hash} (@pxref{Invoking guix hash}).
2435
2436 @cindex patches
2437 When needed, the @code{origin} form can also have a @code{patches} field
2438 listing patches to be applied, and a @code{snippet} field giving a
2439 Scheme expression to modify the source code.
2440
2441 @item
2442 @cindex GNU Build System
2443 The @code{build-system} field specifies the procedure to build the
2444 package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2445 represents the familiar GNU Build System, where packages may be
2446 configured, built, and installed with the usual @code{./configure &&
2447 make && make check && make install} command sequence.
2448
2449 @item
2450 The @code{arguments} field specifies options for the build system
2451 (@pxref{Build Systems}). Here it is interpreted by
2452 @var{gnu-build-system} as a request run @file{configure} with the
2453 @code{--enable-silent-rules} flag.
2454
2455 @cindex quote
2456 @cindex quoting
2457 @findex '
2458 @findex quote
2459 What about these quote (@code{'}) characters? They are Scheme syntax to
2460 introduce a literal list; @code{'} is synonymous with @code{quote}.
2461 @xref{Expression Syntax, quoting,, guile, GNU Guile Reference Manual},
2462 for details. Here the value of the @code{arguments} field is a list of
2463 arguments passed to the build system down the road, as with @code{apply}
2464 (@pxref{Fly Evaluation, @code{apply},, guile, GNU Guile Reference
2465 Manual}).
2466
2467 The hash-colon (@code{#:}) sequence defines a Scheme @dfn{keyword}
2468 (@pxref{Keywords,,, guile, GNU Guile Reference Manual}), and
2469 @code{#:configure-flags} is a keyword used to pass a keyword argument
2470 to the build system (@pxref{Coding With Keywords,,, guile, GNU Guile
2471 Reference Manual}).
2472
2473 @item
2474 The @code{inputs} field specifies inputs to the build process---i.e.,
2475 build-time or run-time dependencies of the package. Here, we define an
2476 input called @code{"gawk"} whose value is that of the @var{gawk}
2477 variable; @var{gawk} is itself bound to a @code{<package>} object.
2478
2479 @cindex backquote (quasiquote)
2480 @findex `
2481 @findex quasiquote
2482 @cindex comma (unquote)
2483 @findex ,
2484 @findex unquote
2485 @findex ,@@
2486 @findex unquote-splicing
2487 Again, @code{`} (a backquote, synonymous with @code{quasiquote}) allows
2488 us to introduce a literal list in the @code{inputs} field, while
2489 @code{,} (a comma, synonymous with @code{unquote}) allows us to insert a
2490 value in that list (@pxref{Expression Syntax, unquote,, guile, GNU Guile
2491 Reference Manual}).
2492
2493 Note that GCC, Coreutils, Bash, and other essential tools do not need to
2494 be specified as inputs here. Instead, @var{gnu-build-system} takes care
2495 of ensuring that they are present (@pxref{Build Systems}).
2496
2497 However, any other dependencies need to be specified in the
2498 @code{inputs} field. Any dependency not specified here will simply be
2499 unavailable to the build process, possibly leading to a build failure.
2500 @end itemize
2501
2502 @xref{package Reference}, for a full description of possible fields.
2503
2504 Once a package definition is in place, the
2505 package may actually be built using the @code{guix build} command-line
2506 tool (@pxref{Invoking guix build}). You can easily jump back to the
2507 package definition using the @command{guix edit} command
2508 (@pxref{Invoking guix edit}).
2509 @xref{Packaging Guidelines}, for
2510 more information on how to test package definitions, and
2511 @ref{Invoking guix lint}, for information on how to check a definition
2512 for style conformance.
2513
2514 Finally, updating the package definition to a new upstream version
2515 can be partly automated by the @command{guix refresh} command
2516 (@pxref{Invoking guix refresh}).
2517
2518 Behind the scenes, a derivation corresponding to the @code{<package>}
2519 object is first computed by the @code{package-derivation} procedure.
2520 That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
2521 The build actions it prescribes may then be realized by using the
2522 @code{build-derivations} procedure (@pxref{The Store}).
2523
2524 @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
2525 Return the @code{<derivation>} object of @var{package} for @var{system}
2526 (@pxref{Derivations}).
2527
2528 @var{package} must be a valid @code{<package>} object, and @var{system}
2529 must be a string denoting the target system type---e.g.,
2530 @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2531 must be a connection to the daemon, which operates on the store
2532 (@pxref{The Store}).
2533 @end deffn
2534
2535 @noindent
2536 @cindex cross-compilation
2537 Similarly, it is possible to compute a derivation that cross-builds a
2538 package for some other system:
2539
2540 @deffn {Scheme Procedure} package-cross-derivation @var{store} @
2541 @var{package} @var{target} [@var{system}]
2542 Return the @code{<derivation>} object of @var{package} cross-built from
2543 @var{system} to @var{target}.
2544
2545 @var{target} must be a valid GNU triplet denoting the target hardware
2546 and operating system, such as @code{"mips64el-linux-gnu"}
2547 (@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2548 Configure and Build System}).
2549 @end deffn
2550
2551 @menu
2552 * package Reference :: The package data type.
2553 * origin Reference:: The origin data type.
2554 @end menu
2555
2556
2557 @node package Reference
2558 @subsection @code{package} Reference
2559
2560 This section summarizes all the options available in @code{package}
2561 declarations (@pxref{Defining Packages}).
2562
2563 @deftp {Data Type} package
2564 This is the data type representing a package recipe.
2565
2566 @table @asis
2567 @item @code{name}
2568 The name of the package, as a string.
2569
2570 @item @code{version}
2571 The version of the package, as a string.
2572
2573 @item @code{source}
2574 An object telling how the source code for the package should be
2575 acquired. Most of the time, this is an @code{origin} object, which
2576 denotes a file fetched from the Internet (@pxref{origin Reference}). It
2577 can also be any other ``file-like'' object such as a @code{local-file},
2578 which denotes a file from the local file system (@pxref{G-Expressions,
2579 @code{local-file}}).
2580
2581 @item @code{build-system}
2582 The build system that should be used to build the package (@pxref{Build
2583 Systems}).
2584
2585 @item @code{arguments} (default: @code{'()})
2586 The arguments that should be passed to the build system. This is a
2587 list, typically containing sequential keyword-value pairs.
2588
2589 @item @code{inputs} (default: @code{'()})
2590 @itemx @code{native-inputs} (default: @code{'()})
2591 @itemx @code{propagated-inputs} (default: @code{'()})
2592 @cindex inputs, of packages
2593 These fields list dependencies of the package. Each one is a list of
2594 tuples, where each tuple has a label for the input (a string) as its
2595 first element, a package, origin, or derivation as its second element,
2596 and optionally the name of the output thereof that should be used, which
2597 defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
2598 more on package outputs). For example, the list below specifies three
2599 inputs:
2600
2601 @example
2602 `(("libffi" ,libffi)
2603 ("libunistring" ,libunistring)
2604 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
2605 @end example
2606
2607 @cindex cross compilation, package dependencies
2608 The distinction between @code{native-inputs} and @code{inputs} is
2609 necessary when considering cross-compilation. When cross-compiling,
2610 dependencies listed in @code{inputs} are built for the @emph{target}
2611 architecture; conversely, dependencies listed in @code{native-inputs}
2612 are built for the architecture of the @emph{build} machine.
2613
2614 @code{native-inputs} is typically used to list tools needed at
2615 build time, but not at run time, such as Autoconf, Automake, pkg-config,
2616 Gettext, or Bison. @command{guix lint} can report likely mistakes in
2617 this area (@pxref{Invoking guix lint}).
2618
2619 @anchor{package-propagated-inputs}
2620 Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
2621 specified packages will be automatically installed alongside the package
2622 they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
2623 package}}, for information on how @command{guix package} deals with
2624 propagated inputs.)
2625
2626 For example this is necessary when a C/C++ library needs headers of
2627 another library to compile, or when a pkg-config file refers to another
2628 one @i{via} its @code{Requires} field.
2629
2630 Another example where @code{propagated-inputs} is useful is for languages
2631 that lack a facility to record the run-time search path akin to the
2632 @code{RUNPATH} of ELF files; this includes Guile, Python, Perl, GHC, and
2633 more. To ensure that libraries written in those languages can find
2634 library code they depend on at run time, run-time dependencies must be
2635 listed in @code{propagated-inputs} rather than @code{inputs}.
2636
2637 @item @code{self-native-input?} (default: @code{#f})
2638 This is a Boolean field telling whether the package should use itself as
2639 a native input when cross-compiling.
2640
2641 @item @code{outputs} (default: @code{'("out")})
2642 The list of output names of the package. @xref{Packages with Multiple
2643 Outputs}, for typical uses of additional outputs.
2644
2645 @item @code{native-search-paths} (default: @code{'()})
2646 @itemx @code{search-paths} (default: @code{'()})
2647 A list of @code{search-path-specification} objects describing
2648 search-path environment variables honored by the package.
2649
2650 @item @code{replacement} (default: @code{#f})
2651 This must be either @code{#f} or a package object that will be used as a
2652 @dfn{replacement} for this package. @xref{Security Updates, grafts},
2653 for details.
2654
2655 @item @code{synopsis}
2656 A one-line description of the package.
2657
2658 @item @code{description}
2659 A more elaborate description of the package.
2660
2661 @item @code{license}
2662 The license of the package; a value from @code{(guix licenses)},
2663 or a list of such values.
2664
2665 @item @code{home-page}
2666 The URL to the home-page of the package, as a string.
2667
2668 @item @code{supported-systems} (default: @var{%supported-systems})
2669 The list of systems supported by the package, as strings of the form
2670 @code{architecture-kernel}, for example @code{"x86_64-linux"}.
2671
2672 @item @code{maintainers} (default: @code{'()})
2673 The list of maintainers of the package, as @code{maintainer} objects.
2674
2675 @item @code{location} (default: source location of the @code{package} form)
2676 The source location of the package. It is useful to override this when
2677 inheriting from another package, in which case this field is not
2678 automatically corrected.
2679 @end table
2680 @end deftp
2681
2682
2683 @node origin Reference
2684 @subsection @code{origin} Reference
2685
2686 This section summarizes all the options available in @code{origin}
2687 declarations (@pxref{Defining Packages}).
2688
2689 @deftp {Data Type} origin
2690 This is the data type representing a source code origin.
2691
2692 @table @asis
2693 @item @code{uri}
2694 An object containing the URI of the source. The object type depends on
2695 the @code{method} (see below). For example, when using the
2696 @var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2697 values are: a URL represented as a string, or a list thereof.
2698
2699 @item @code{method}
2700 A procedure that handles the URI.
2701
2702 Examples include:
2703
2704 @table @asis
2705 @item @var{url-fetch} from @code{(guix download)}
2706 download a file from the HTTP, HTTPS, or FTP URL specified in the
2707 @code{uri} field;
2708
2709 @vindex git-fetch
2710 @item @var{git-fetch} from @code{(guix git-download)}
2711 clone the Git version control repository, and check out the revision
2712 specified in the @code{uri} field as a @code{git-reference} object; a
2713 @code{git-reference} looks like this:
2714
2715 @example
2716 (git-reference
2717 (url "git://git.debian.org/git/pkg-shadow/shadow")
2718 (commit "v4.1.5.1"))
2719 @end example
2720 @end table
2721
2722 @item @code{sha256}
2723 A bytevector containing the SHA-256 hash of the source. Typically the
2724 @code{base32} form is used here to generate the bytevector from a
2725 base-32 string.
2726
2727 You can obtain this information using @code{guix download}
2728 (@pxref{Invoking guix download}) or @code{guix hash} (@pxref{Invoking
2729 guix hash}).
2730
2731 @item @code{file-name} (default: @code{#f})
2732 The file name under which the source code should be saved. When this is
2733 @code{#f}, a sensible default value will be used in most cases. In case
2734 the source is fetched from a URL, the file name from the URL will be
2735 used. For version control checkouts, it is recommended to provide the
2736 file name explicitly because the default is not very descriptive.
2737
2738 @item @code{patches} (default: @code{'()})
2739 A list of file names containing patches to be applied to the source.
2740
2741 @item @code{snippet} (default: @code{#f})
2742 A G-expression (@pxref{G-Expressions}) or S-expression that will be run
2743 in the source directory. This is a convenient way to modify the source,
2744 sometimes more convenient than a patch.
2745
2746 @item @code{patch-flags} (default: @code{'("-p1")})
2747 A list of command-line flags that should be passed to the @code{patch}
2748 command.
2749
2750 @item @code{patch-inputs} (default: @code{#f})
2751 Input packages or derivations to the patching process. When this is
2752 @code{#f}, the usual set of inputs necessary for patching are provided,
2753 such as GNU@tie{}Patch.
2754
2755 @item @code{modules} (default: @code{'()})
2756 A list of Guile modules that should be loaded during the patching
2757 process and while running the code in the @code{snippet} field.
2758
2759 @item @code{patch-guile} (default: @code{#f})
2760 The Guile package that should be used in the patching process. When
2761 this is @code{#f}, a sensible default is used.
2762 @end table
2763 @end deftp
2764
2765
2766 @node Build Systems
2767 @section Build Systems
2768
2769 @cindex build system
2770 Each package definition specifies a @dfn{build system} and arguments for
2771 that build system (@pxref{Defining Packages}). This @code{build-system}
2772 field represents the build procedure of the package, as well as implicit
2773 dependencies of that build procedure.
2774
2775 Build systems are @code{<build-system>} objects. The interface to
2776 create and manipulate them is provided by the @code{(guix build-system)}
2777 module, and actual build systems are exported by specific modules.
2778
2779 @cindex bag (low-level package representation)
2780 Under the hood, build systems first compile package objects to
2781 @dfn{bags}. A @dfn{bag} is like a package, but with less
2782 ornamentation---in other words, a bag is a lower-level representation of
2783 a package, which includes all the inputs of that package, including some
2784 that were implicitly added by the build system. This intermediate
2785 representation is then compiled to a derivation (@pxref{Derivations}).
2786
2787 Build systems accept an optional list of @dfn{arguments}. In package
2788 definitions, these are passed @i{via} the @code{arguments} field
2789 (@pxref{Defining Packages}). They are typically keyword arguments
2790 (@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
2791 Guile Reference Manual}). The value of these arguments is usually
2792 evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
2793 by the daemon (@pxref{Derivations}).
2794
2795 The main build system is @var{gnu-build-system}, which implements the
2796 standard build procedure for GNU and many other packages. It
2797 is provided by the @code{(guix build-system gnu)} module.
2798
2799 @defvr {Scheme Variable} gnu-build-system
2800 @var{gnu-build-system} represents the GNU Build System, and variants
2801 thereof (@pxref{Configuration, configuration and makefile conventions,,
2802 standards, GNU Coding Standards}).
2803
2804 @cindex build phases
2805 In a nutshell, packages using it are configured, built, and installed with
2806 the usual @code{./configure && make && make check && make install}
2807 command sequence. In practice, a few additional steps are often needed.
2808 All these steps are split up in separate @dfn{phases},
2809 notably@footnote{Please see the @code{(guix build gnu-build-system)}
2810 modules for more details about the build phases.}:
2811
2812 @table @code
2813 @item unpack
2814 Unpack the source tarball, and change the current directory to the
2815 extracted source tree. If the source is actually a directory, copy it
2816 to the build tree, and enter that directory.
2817
2818 @item patch-source-shebangs
2819 Patch shebangs encountered in source files so they refer to the right
2820 store file names. For instance, this changes @code{#!/bin/sh} to
2821 @code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
2822
2823 @item configure
2824 Run the @file{configure} script with a number of default options, such
2825 as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
2826 by the @code{#:configure-flags} argument.
2827
2828 @item build
2829 Run @code{make} with the list of flags specified with
2830 @code{#:make-flags}. If the @code{#:parallel-build?} argument is true
2831 (the default), build with @code{make -j}.
2832
2833 @item check
2834 Run @code{make check}, or some other target specified with
2835 @code{#:test-target}, unless @code{#:tests? #f} is passed. If the
2836 @code{#:parallel-tests?} argument is true (the default), run @code{make
2837 check -j}.
2838
2839 @item install
2840 Run @code{make install} with the flags listed in @code{#:make-flags}.
2841
2842 @item patch-shebangs
2843 Patch shebangs on the installed executable files.
2844
2845 @item strip
2846 Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
2847 is false), copying them to the @code{debug} output when available
2848 (@pxref{Installing Debugging Files}).
2849 @end table
2850
2851 @vindex %standard-phases
2852 The build-side module @code{(guix build gnu-build-system)} defines
2853 @var{%standard-phases} as the default list of build phases.
2854 @var{%standard-phases} is a list of symbol/procedure pairs, where the
2855 procedure implements the actual phase.
2856
2857 The list of phases used for a particular package can be changed with the
2858 @code{#:phases} parameter. For instance, passing:
2859
2860 @example
2861 #:phases (modify-phases %standard-phases (delete 'configure))
2862 @end example
2863
2864 means that all the phases described above will be used, except the
2865 @code{configure} phase.
2866
2867 In addition, this build system ensures that the ``standard'' environment
2868 for GNU packages is available. This includes tools such as GCC, libc,
2869 Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
2870 build-system gnu)} module for a complete list). We call these the
2871 @dfn{implicit inputs} of a package, because package definitions do not
2872 have to mention them.
2873 @end defvr
2874
2875 Other @code{<build-system>} objects are defined to support other
2876 conventions and tools used by free software packages. They inherit most
2877 of @var{gnu-build-system}, and differ mainly in the set of inputs
2878 implicitly added to the build process, and in the list of phases
2879 executed. Some of these build systems are listed below.
2880
2881 @defvr {Scheme Variable} ant-build-system
2882 This variable is exported by @code{(guix build-system ant)}. It
2883 implements the build procedure for Java packages that can be built with
2884 @url{http://ant.apache.org/, Ant build tool}.
2885
2886 It adds both @code{ant} and the @dfn{Java Development Kit} (JDK) as
2887 provided by the @code{icedtea} package to the set of inputs. Different
2888 packages can be specified with the @code{#:ant} and @code{#:jdk}
2889 parameters, respectively.
2890
2891 When the original package does not provide a suitable Ant build file,
2892 the parameter @code{#:jar-name} can be used to generate a minimal Ant
2893 build file @file{build.xml} with tasks to build the specified jar
2894 archive.
2895
2896 The parameter @code{#:build-target} can be used to specify the Ant task
2897 that should be run during the @code{build} phase. By default the
2898 ``jar'' task will be run.
2899
2900 @end defvr
2901
2902 @defvr {Scheme Variable} cmake-build-system
2903 This variable is exported by @code{(guix build-system cmake)}. It
2904 implements the build procedure for packages using the
2905 @url{http://www.cmake.org, CMake build tool}.
2906
2907 It automatically adds the @code{cmake} package to the set of inputs.
2908 Which package is used can be specified with the @code{#:cmake}
2909 parameter.
2910
2911 The @code{#:configure-flags} parameter is taken as a list of flags
2912 passed to the @command{cmake} command. The @code{#:build-type}
2913 parameter specifies in abstract terms the flags passed to the compiler;
2914 it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
2915 debugging information''), which roughly means that code is compiled with
2916 @code{-O2 -g}, as is the case for Autoconf-based packages by default.
2917 @end defvr
2918
2919 @defvr {Scheme Variable} glib-or-gtk-build-system
2920 This variable is exported by @code{(guix build-system glib-or-gtk)}. It
2921 is intended for use with packages making use of GLib or GTK+.
2922
2923 This build system adds the following two phases to the ones defined by
2924 @var{gnu-build-system}:
2925
2926 @table @code
2927 @item glib-or-gtk-wrap
2928 The phase @code{glib-or-gtk-wrap} ensures that programs in
2929 @file{bin/} are able to find GLib ``schemas'' and
2930 @uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
2931 modules}. This is achieved by wrapping the programs in launch scripts
2932 that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
2933 environment variables.
2934
2935 It is possible to exclude specific package outputs from that wrapping
2936 process by listing their names in the
2937 @code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
2938 when an output is known not to contain any GLib or GTK+ binaries, and
2939 where wrapping would gratuitously add a dependency of that output on
2940 GLib and GTK+.
2941
2942 @item glib-or-gtk-compile-schemas
2943 The phase @code{glib-or-gtk-compile-schemas} makes sure that all
2944 @uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
2945 GSettings schemas} of GLib are compiled. Compilation is performed by the
2946 @command{glib-compile-schemas} program. It is provided by the package
2947 @code{glib:bin} which is automatically imported by the build system.
2948 The @code{glib} package providing @command{glib-compile-schemas} can be
2949 specified with the @code{#:glib} parameter.
2950 @end table
2951
2952 Both phases are executed after the @code{install} phase.
2953 @end defvr
2954
2955 @defvr {Scheme Variable} python-build-system
2956 This variable is exported by @code{(guix build-system python)}. It
2957 implements the more or less standard build procedure used by Python
2958 packages, which consists in running @code{python setup.py build} and
2959 then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
2960
2961 For packages that install stand-alone Python programs under @code{bin/},
2962 it takes care of wrapping these programs so that their @code{PYTHONPATH}
2963 environment variable points to all the Python libraries they depend on.
2964
2965 Which Python package is used to perform the build can be specified with
2966 the @code{#:python} parameter. This is a useful way to force a package
2967 to be built for a specific version of the Python interpreter, which
2968 might be necessary if the package is only compatible with a single
2969 interpreter version.
2970 @end defvr
2971
2972 @defvr {Scheme Variable} perl-build-system
2973 This variable is exported by @code{(guix build-system perl)}. It
2974 implements the standard build procedure for Perl packages, which either
2975 consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
2976 followed by @code{Build} and @code{Build install}; or in running
2977 @code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
2978 @code{make} and @code{make install}, depending on which of
2979 @code{Build.PL} or @code{Makefile.PL} is present in the package
2980 distribution. Preference is given to the former if both @code{Build.PL}
2981 and @code{Makefile.PL} exist in the package distribution. This
2982 preference can be reversed by specifying @code{#t} for the
2983 @code{#:make-maker?} parameter.
2984
2985 The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
2986 passes flags specified by the @code{#:make-maker-flags} or
2987 @code{#:module-build-flags} parameter, respectively.
2988
2989 Which Perl package is used can be specified with @code{#:perl}.
2990 @end defvr
2991
2992 @defvr {Scheme Variable} r-build-system
2993 This variable is exported by @code{(guix build-system r)}. It
2994 implements the build procedure used by @uref{http://r-project.org, R}
2995 packages, which essentially is little more than running @code{R CMD
2996 INSTALL --library=/gnu/store/@dots{}} in an environment where
2997 @code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
2998 are run after installation using the R function
2999 @code{tools::testInstalledPackage}.
3000 @end defvr
3001
3002 @defvr {Scheme Variable} ruby-build-system
3003 This variable is exported by @code{(guix build-system ruby)}. It
3004 implements the RubyGems build procedure used by Ruby packages, which
3005 involves running @code{gem build} followed by @code{gem install}.
3006
3007 The @code{source} field of a package that uses this build system
3008 typically references a gem archive, since this is the format that Ruby
3009 developers use when releasing their software. The build system unpacks
3010 the gem archive, potentially patches the source, runs the test suite,
3011 repackages the gem, and installs it. Additionally, directories and
3012 tarballs may be referenced to allow building unreleased gems from Git or
3013 a traditional source release tarball.
3014
3015 Which Ruby package is used can be specified with the @code{#:ruby}
3016 parameter. A list of additional flags to be passed to the @command{gem}
3017 command can be specified with the @code{#:gem-flags} parameter.
3018 @end defvr
3019
3020 @defvr {Scheme Variable} waf-build-system
3021 This variable is exported by @code{(guix build-system waf)}. It
3022 implements a build procedure around the @code{waf} script. The common
3023 phases---@code{configure}, @code{build}, and @code{install}---are
3024 implemented by passing their names as arguments to the @code{waf}
3025 script.
3026
3027 The @code{waf} script is executed by the Python interpreter. Which
3028 Python package is used to run the script can be specified with the
3029 @code{#:python} parameter.
3030 @end defvr
3031
3032 @defvr {Scheme Variable} haskell-build-system
3033 This variable is exported by @code{(guix build-system haskell)}. It
3034 implements the Cabal build procedure used by Haskell packages, which
3035 involves running @code{runhaskell Setup.hs configure
3036 --prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
3037 Instead of installing the package by running @code{runhaskell Setup.hs
3038 install}, to avoid trying to register libraries in the read-only
3039 compiler store directory, the build system uses @code{runhaskell
3040 Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
3041 addition, the build system generates the package documentation by
3042 running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
3043 is passed. Optional Haddock parameters can be passed with the help of
3044 the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
3045 not found, the build system looks for @code{Setup.lhs} instead.
3046
3047 Which Haskell compiler is used can be specified with the @code{#:haskell}
3048 parameter which defaults to @code{ghc}.
3049 @end defvr
3050
3051 @defvr {Scheme Variable} emacs-build-system
3052 This variable is exported by @code{(guix build-system emacs)}. It
3053 implements an installation procedure similar to the packaging system
3054 of Emacs itself (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
3055
3056 It first creates the @code{@var{package}-autoloads.el} file, then it
3057 byte compiles all Emacs Lisp files. Differently from the Emacs
3058 packaging system, the Info documentation files are moved to the standard
3059 documentation directory and the @file{dir} file is deleted. Each
3060 package is installed in its own directory under
3061 @file{share/emacs/site-lisp/guix.d}.
3062 @end defvr
3063
3064 Lastly, for packages that do not need anything as sophisticated, a
3065 ``trivial'' build system is provided. It is trivial in the sense that
3066 it provides basically no support: it does not pull any implicit inputs,
3067 and does not have a notion of build phases.
3068
3069 @defvr {Scheme Variable} trivial-build-system
3070 This variable is exported by @code{(guix build-system trivial)}.
3071
3072 This build system requires a @code{#:builder} argument. This argument
3073 must be a Scheme expression that builds the package output(s)---as
3074 with @code{build-expression->derivation} (@pxref{Derivations,
3075 @code{build-expression->derivation}}).
3076 @end defvr
3077
3078 @node The Store
3079 @section The Store
3080
3081 @cindex store
3082 @cindex store items
3083 @cindex store paths
3084
3085 Conceptually, the @dfn{store} is the place where derivations that have
3086 been built successfully are stored---by default, @file{/gnu/store}.
3087 Sub-directories in the store are referred to as @dfn{store items} or
3088 sometimes @dfn{store paths}. The store has an associated database that
3089 contains information such as the store paths referred to by each store
3090 path, and the list of @emph{valid} store items---results of successful
3091 builds. This database resides in @file{@var{localstatedir}/guix/db},
3092 where @var{localstatedir} is the state directory specified @i{via}
3093 @option{--localstatedir} at configure time, usually @file{/var}.
3094
3095 The store is @emph{always} accessed by the daemon on behalf of its clients
3096 (@pxref{Invoking guix-daemon}). To manipulate the store, clients
3097 connect to the daemon over a Unix-domain socket, send requests to it,
3098 and read the result---these are remote procedure calls, or RPCs.
3099
3100 @quotation Note
3101 Users must @emph{never} modify files under @file{/gnu/store} directly.
3102 This would lead to inconsistencies and break the immutability
3103 assumptions of Guix's functional model (@pxref{Introduction}).
3104
3105 @xref{Invoking guix gc, @command{guix gc --verify}}, for information on
3106 how to check the integrity of the store and attempt recovery from
3107 accidental modifications.
3108 @end quotation
3109
3110 The @code{(guix store)} module provides procedures to connect to the
3111 daemon, and to perform RPCs. These are described below.
3112
3113 @deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
3114 Connect to the daemon over the Unix-domain socket at @var{file}. When
3115 @var{reserve-space?} is true, instruct it to reserve a little bit of
3116 extra space on the file system so that the garbage collector can still
3117 operate should the disk become full. Return a server object.
3118
3119 @var{file} defaults to @var{%default-socket-path}, which is the normal
3120 location given the options that were passed to @command{configure}.
3121 @end deffn
3122
3123 @deffn {Scheme Procedure} close-connection @var{server}
3124 Close the connection to @var{server}.
3125 @end deffn
3126
3127 @defvr {Scheme Variable} current-build-output-port
3128 This variable is bound to a SRFI-39 parameter, which refers to the port
3129 where build and error logs sent by the daemon should be written.
3130 @end defvr
3131
3132 Procedures that make RPCs all take a server object as their first
3133 argument.
3134
3135 @deffn {Scheme Procedure} valid-path? @var{server} @var{path}
3136 @cindex invalid store items
3137 Return @code{#t} when @var{path} designates a valid store item and
3138 @code{#f} otherwise (an invalid item may exist on disk but still be
3139 invalid, for instance because it is the result of an aborted or failed
3140 build.)
3141
3142 A @code{&nix-protocol-error} condition is raised if @var{path} is not
3143 prefixed by the store directory (@file{/gnu/store}).
3144 @end deffn
3145
3146 @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
3147 Add @var{text} under file @var{name} in the store, and return its store
3148 path. @var{references} is the list of store paths referred to by the
3149 resulting store path.
3150 @end deffn
3151
3152 @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
3153 Build @var{derivations} (a list of @code{<derivation>} objects or
3154 derivation paths), and return when the worker is done building them.
3155 Return @code{#t} on success.
3156 @end deffn
3157
3158 Note that the @code{(guix monads)} module provides a monad as well as
3159 monadic versions of the above procedures, with the goal of making it
3160 more convenient to work with code that accesses the store (@pxref{The
3161 Store Monad}).
3162
3163 @c FIXME
3164 @i{This section is currently incomplete.}
3165
3166 @node Derivations
3167 @section Derivations
3168
3169 @cindex derivations
3170 Low-level build actions and the environment in which they are performed
3171 are represented by @dfn{derivations}. A derivation contains the
3172 following pieces of information:
3173
3174 @itemize
3175 @item
3176 The outputs of the derivation---derivations produce at least one file or
3177 directory in the store, but may produce more.
3178
3179 @item
3180 The inputs of the derivations, which may be other derivations or plain
3181 files in the store (patches, build scripts, etc.)
3182
3183 @item
3184 The system type targeted by the derivation---e.g., @code{x86_64-linux}.
3185
3186 @item
3187 The file name of a build script in the store, along with the arguments
3188 to be passed.
3189
3190 @item
3191 A list of environment variables to be defined.
3192
3193 @end itemize
3194
3195 @cindex derivation path
3196 Derivations allow clients of the daemon to communicate build actions to
3197 the store. They exist in two forms: as an in-memory representation,
3198 both on the client- and daemon-side, and as files in the store whose
3199 name end in @code{.drv}---these files are referred to as @dfn{derivation
3200 paths}. Derivations paths can be passed to the @code{build-derivations}
3201 procedure to perform the build actions they prescribe (@pxref{The
3202 Store}).
3203
3204 The @code{(guix derivations)} module provides a representation of
3205 derivations as Scheme objects, along with procedures to create and
3206 otherwise manipulate derivations. The lowest-level primitive to create
3207 a derivation is the @code{derivation} procedure:
3208
3209 @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
3210 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3211 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
3212 [#:system (%current-system)] [#:references-graphs #f] @
3213 [#:allowed-references #f] [#:disallowed-references #f] @
3214 [#:leaked-env-vars #f] [#:local-build? #f] @
3215 [#:substitutable? #t]
3216 Build a derivation with the given arguments, and return the resulting
3217 @code{<derivation>} object.
3218
3219 When @var{hash} and @var{hash-algo} are given, a
3220 @dfn{fixed-output derivation} is created---i.e., one whose result is
3221 known in advance, such as a file download. If, in addition,
3222 @var{recursive?} is true, then that fixed output may be an executable
3223 file or a directory and @var{hash} must be the hash of an archive
3224 containing this output.
3225
3226 When @var{references-graphs} is true, it must be a list of file
3227 name/store path pairs. In that case, the reference graph of each store
3228 path is exported in the build environment in the corresponding file, in
3229 a simple text format.
3230
3231 When @var{allowed-references} is true, it must be a list of store items
3232 or outputs that the derivation's output may refer to. Likewise,
3233 @var{disallowed-references}, if true, must be a list of things the
3234 outputs may @emph{not} refer to.
3235
3236 When @var{leaked-env-vars} is true, it must be a list of strings
3237 denoting environment variables that are allowed to ``leak'' from the
3238 daemon's environment to the build environment. This is only applicable
3239 to fixed-output derivations---i.e., when @var{hash} is true. The main
3240 use is to allow variables such as @code{http_proxy} to be passed to
3241 derivations that download files.
3242
3243 When @var{local-build?} is true, declare that the derivation is not a
3244 good candidate for offloading and should rather be built locally
3245 (@pxref{Daemon Offload Setup}). This is the case for small derivations
3246 where the costs of data transfers would outweigh the benefits.
3247
3248 When @var{substitutable?} is false, declare that substitutes of the
3249 derivation's output should not be used (@pxref{Substitutes}). This is
3250 useful, for instance, when building packages that capture details of the
3251 host CPU instruction set.
3252 @end deffn
3253
3254 @noindent
3255 Here's an example with a shell script as its builder, assuming
3256 @var{store} is an open connection to the daemon, and @var{bash} points
3257 to a Bash executable in the store:
3258
3259 @lisp
3260 (use-modules (guix utils)
3261 (guix store)
3262 (guix derivations))
3263
3264 (let ((builder ; add the Bash script to the store
3265 (add-text-to-store store "my-builder.sh"
3266 "echo hello world > $out\n" '())))
3267 (derivation store "foo"
3268 bash `("-e" ,builder)
3269 #:inputs `((,bash) (,builder))
3270 #:env-vars '(("HOME" . "/homeless"))))
3271 @result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
3272 @end lisp
3273
3274 As can be guessed, this primitive is cumbersome to use directly. A
3275 better approach is to write build scripts in Scheme, of course! The
3276 best course of action for that is to write the build code as a
3277 ``G-expression'', and to pass it to @code{gexp->derivation}. For more
3278 information, @pxref{G-Expressions}.
3279
3280 Once upon a time, @code{gexp->derivation} did not exist and constructing
3281 derivations with build code written in Scheme was achieved with
3282 @code{build-expression->derivation}, documented below. This procedure
3283 is now deprecated in favor of the much nicer @code{gexp->derivation}.
3284
3285 @deffn {Scheme Procedure} build-expression->derivation @var{store} @
3286 @var{name} @var{exp} @
3287 [#:system (%current-system)] [#:inputs '()] @
3288 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3289 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3290 [#:references-graphs #f] [#:allowed-references #f] @
3291 [#:disallowed-references #f] @
3292 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3293 Return a derivation that executes Scheme expression @var{exp} as a
3294 builder for derivation @var{name}. @var{inputs} must be a list of
3295 @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
3296 @code{"out"} is assumed. @var{modules} is a list of names of Guile
3297 modules from the current search path to be copied in the store,
3298 compiled, and made available in the load path during the execution of
3299 @var{exp}---e.g., @code{((guix build utils) (guix build
3300 gnu-build-system))}.
3301
3302 @var{exp} is evaluated in an environment where @code{%outputs} is bound
3303 to a list of output/path pairs, and where @code{%build-inputs} is bound
3304 to a list of string/output-path pairs made from @var{inputs}.
3305 Optionally, @var{env-vars} is a list of string pairs specifying the name
3306 and value of environment variables visible to the builder. The builder
3307 terminates by passing the result of @var{exp} to @code{exit}; thus, when
3308 @var{exp} returns @code{#f}, the build is considered to have failed.
3309
3310 @var{exp} is built using @var{guile-for-build} (a derivation). When
3311 @var{guile-for-build} is omitted or is @code{#f}, the value of the
3312 @code{%guile-for-build} fluid is used instead.
3313
3314 See the @code{derivation} procedure for the meaning of
3315 @var{references-graphs}, @var{allowed-references},
3316 @var{disallowed-references}, @var{local-build?}, and
3317 @var{substitutable?}.
3318 @end deffn
3319
3320 @noindent
3321 Here's an example of a single-output derivation that creates a directory
3322 containing one file:
3323
3324 @lisp
3325 (let ((builder '(let ((out (assoc-ref %outputs "out")))
3326 (mkdir out) ; create /gnu/store/@dots{}-goo
3327 (call-with-output-file (string-append out "/test")
3328 (lambda (p)
3329 (display '(hello guix) p))))))
3330 (build-expression->derivation store "goo" builder))
3331
3332 @result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
3333 @end lisp
3334
3335
3336 @node The Store Monad
3337 @section The Store Monad
3338
3339 @cindex monad
3340
3341 The procedures that operate on the store described in the previous
3342 sections all take an open connection to the build daemon as their first
3343 argument. Although the underlying model is functional, they either have
3344 side effects or depend on the current state of the store.
3345
3346 The former is inconvenient: the connection to the build daemon has to be
3347 carried around in all those functions, making it impossible to compose
3348 functions that do not take that parameter with functions that do. The
3349 latter can be problematic: since store operations have side effects
3350 and/or depend on external state, they have to be properly sequenced.
3351
3352 @cindex monadic values
3353 @cindex monadic functions
3354 This is where the @code{(guix monads)} module comes in. This module
3355 provides a framework for working with @dfn{monads}, and a particularly
3356 useful monad for our uses, the @dfn{store monad}. Monads are a
3357 construct that allows two things: associating ``context'' with values
3358 (in our case, the context is the store), and building sequences of
3359 computations (here computations include accesses to the store). Values
3360 in a monad---values that carry this additional context---are called
3361 @dfn{monadic values}; procedures that return such values are called
3362 @dfn{monadic procedures}.
3363
3364 Consider this ``normal'' procedure:
3365
3366 @example
3367 (define (sh-symlink store)
3368 ;; Return a derivation that symlinks the 'bash' executable.
3369 (let* ((drv (package-derivation store bash))
3370 (out (derivation->output-path drv))
3371 (sh (string-append out "/bin/bash")))
3372 (build-expression->derivation store "sh"
3373 `(symlink ,sh %output))))
3374 @end example
3375
3376 Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3377 as a monadic function:
3378
3379 @example
3380 (define (sh-symlink)
3381 ;; Same, but return a monadic value.
3382 (mlet %store-monad ((drv (package->derivation bash)))
3383 (gexp->derivation "sh"
3384 #~(symlink (string-append #$drv "/bin/bash")
3385 #$output))))
3386 @end example
3387
3388 There are several things to note in the second version: the @code{store}
3389 parameter is now implicit and is ``threaded'' in the calls to the
3390 @code{package->derivation} and @code{gexp->derivation} monadic
3391 procedures, and the monadic value returned by @code{package->derivation}
3392 is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3393
3394 As it turns out, the call to @code{package->derivation} can even be
3395 omitted since it will take place implicitly, as we will see later
3396 (@pxref{G-Expressions}):
3397
3398 @example
3399 (define (sh-symlink)
3400 (gexp->derivation "sh"
3401 #~(symlink (string-append #$bash "/bin/bash")
3402 #$output)))
3403 @end example
3404
3405 @c See
3406 @c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
3407 @c for the funny quote.
3408 Calling the monadic @code{sh-symlink} has no effect. As someone once
3409 said, ``you exit a monad like you exit a building on fire: by running''.
3410 So, to exit the monad and get the desired effect, one must use
3411 @code{run-with-store}:
3412
3413 @example
3414 (run-with-store (open-connection) (sh-symlink))
3415 @result{} /gnu/store/...-sh-symlink
3416 @end example
3417
3418 Note that the @code{(guix monad-repl)} module extends the Guile REPL with
3419 new ``meta-commands'' to make it easier to deal with monadic procedures:
3420 @code{run-in-store}, and @code{enter-store-monad}. The former is used
3421 to ``run'' a single monadic value through the store:
3422
3423 @example
3424 scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3425 $1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3426 @end example
3427
3428 The latter enters a recursive REPL, where all the return values are
3429 automatically run through the store:
3430
3431 @example
3432 scheme@@(guile-user)> ,enter-store-monad
3433 store-monad@@(guile-user) [1]> (package->derivation hello)
3434 $2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3435 store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3436 $3 = "/gnu/store/@dots{}-foo"
3437 store-monad@@(guile-user) [1]> ,q
3438 scheme@@(guile-user)>
3439 @end example
3440
3441 @noindent
3442 Note that non-monadic values cannot be returned in the
3443 @code{store-monad} REPL.
3444
3445 The main syntactic forms to deal with monads in general are provided by
3446 the @code{(guix monads)} module and are described below.
3447
3448 @deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3449 Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3450 in @var{monad}.
3451 @end deffn
3452
3453 @deffn {Scheme Syntax} return @var{val}
3454 Return a monadic value that encapsulates @var{val}.
3455 @end deffn
3456
3457 @deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
3458 @dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
3459 procedures @var{mproc}@dots{}@footnote{This operation is commonly
3460 referred to as ``bind'', but that name denotes an unrelated procedure in
3461 Guile. Thus we use this somewhat cryptic symbol inherited from the
3462 Haskell language.}. There can be one @var{mproc} or several of them, as
3463 in this example:
3464
3465 @example
3466 (run-with-state
3467 (with-monad %state-monad
3468 (>>= (return 1)
3469 (lambda (x) (return (+ 1 x)))
3470 (lambda (x) (return (* 2 x)))))
3471 'some-state)
3472
3473 @result{} 4
3474 @result{} some-state
3475 @end example
3476 @end deffn
3477
3478 @deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3479 @var{body} ...
3480 @deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3481 @var{body} ...
3482 Bind the variables @var{var} to the monadic values @var{mval} in
3483 @var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3484 ``normal'' value @var{val}, as per @code{let}.
3485
3486 @code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3487 (@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3488 @end deffn
3489
3490 @deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3491 Bind @var{mexp} and the following monadic expressions in sequence,
3492 returning the result of the last expression.
3493
3494 This is akin to @code{mlet}, except that the return values of the
3495 monadic expressions are ignored. In that sense, it is analogous to
3496 @code{begin}, but applied to monadic expressions.
3497 @end deffn
3498
3499 @cindex state monad
3500 The @code{(guix monads)} module provides the @dfn{state monad}, which
3501 allows an additional value---the state---to be @emph{threaded} through
3502 monadic procedure calls.
3503
3504 @defvr {Scheme Variable} %state-monad
3505 The state monad. Procedures in the state monad can access and change
3506 the state that is threaded.
3507
3508 Consider the example below. The @code{square} procedure returns a value
3509 in the state monad. It returns the square of its argument, but also
3510 increments the current state value:
3511
3512 @example
3513 (define (square x)
3514 (mlet %state-monad ((count (current-state)))
3515 (mbegin %state-monad
3516 (set-current-state (+ 1 count))
3517 (return (* x x)))))
3518
3519 (run-with-state (sequence %state-monad (map square (iota 3))) 0)
3520 @result{} (0 1 4)
3521 @result{} 3
3522 @end example
3523
3524 When ``run'' through @var{%state-monad}, we obtain that additional state
3525 value, which is the number of @code{square} calls.
3526 @end defvr
3527
3528 @deffn {Monadic Procedure} current-state
3529 Return the current state as a monadic value.
3530 @end deffn
3531
3532 @deffn {Monadic Procedure} set-current-state @var{value}
3533 Set the current state to @var{value} and return the previous state as a
3534 monadic value.
3535 @end deffn
3536
3537 @deffn {Monadic Procedure} state-push @var{value}
3538 Push @var{value} to the current state, which is assumed to be a list,
3539 and return the previous state as a monadic value.
3540 @end deffn
3541
3542 @deffn {Monadic Procedure} state-pop
3543 Pop a value from the current state and return it as a monadic value.
3544 The state is assumed to be a list.
3545 @end deffn
3546
3547 @deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3548 Run monadic value @var{mval} starting with @var{state} as the initial
3549 state. Return two values: the resulting value, and the resulting state.
3550 @end deffn
3551
3552 The main interface to the store monad, provided by the @code{(guix
3553 store)} module, is as follows.
3554
3555 @defvr {Scheme Variable} %store-monad
3556 The store monad---an alias for @var{%state-monad}.
3557
3558 Values in the store monad encapsulate accesses to the store. When its
3559 effect is needed, a value of the store monad must be ``evaluated'' by
3560 passing it to the @code{run-with-store} procedure (see below.)
3561 @end defvr
3562
3563 @deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3564 Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3565 open store connection.
3566 @end deffn
3567
3568 @deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
3569 Return as a monadic value the absolute file name in the store of the file
3570 containing @var{text}, a string. @var{references} is a list of store items that the
3571 resulting text file refers to; it defaults to the empty list.
3572 @end deffn
3573
3574 @deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
3575 [#:recursive? #t] [#:select? (const #t)]
3576 Return the name of @var{file} once interned in the store. Use
3577 @var{name} as its store name, or the basename of @var{file} if
3578 @var{name} is omitted.
3579
3580 When @var{recursive?} is true, the contents of @var{file} are added
3581 recursively; if @var{file} designates a flat file and @var{recursive?}
3582 is true, its contents are added, and its permission bits are kept.
3583
3584 When @var{recursive?} is true, call @code{(@var{select?} @var{file}
3585 @var{stat})} for each directory entry, where @var{file} is the entry's
3586 absolute file name and @var{stat} is the result of @code{lstat}; exclude
3587 entries for which @var{select?} does not return true.
3588
3589 The example below adds a file to the store, under two different names:
3590
3591 @example
3592 (run-with-store (open-connection)
3593 (mlet %store-monad ((a (interned-file "README"))
3594 (b (interned-file "README" "LEGU-MIN")))
3595 (return (list a b))))
3596
3597 @result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3598 @end example
3599
3600 @end deffn
3601
3602 The @code{(guix packages)} module exports the following package-related
3603 monadic procedures:
3604
3605 @deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
3606 [#:system (%current-system)] [#:target #f] @
3607 [#:output "out"]
3608 Return as a monadic
3609 value in the absolute file name of @var{file} within the @var{output}
3610 directory of @var{package}. When @var{file} is omitted, return the name
3611 of the @var{output} directory of @var{package}. When @var{target} is
3612 true, use it as a cross-compilation target triplet.
3613 @end deffn
3614
3615 @deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
3616 @deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3617 @var{target} [@var{system}]
3618 Monadic version of @code{package-derivation} and
3619 @code{package-cross-derivation} (@pxref{Defining Packages}).
3620 @end deffn
3621
3622
3623 @node G-Expressions
3624 @section G-Expressions
3625
3626 @cindex G-expression
3627 @cindex build code quoting
3628 So we have ``derivations'', which represent a sequence of build actions
3629 to be performed to produce an item in the store (@pxref{Derivations}).
3630 These build actions are performed when asking the daemon to actually
3631 build the derivations; they are run by the daemon in a container
3632 (@pxref{Invoking guix-daemon}).
3633
3634 @cindex strata of code
3635 It should come as no surprise that we like to write these build actions
3636 in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3637 code@footnote{The term @dfn{stratum} in this context was coined by
3638 Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3639 Kiselyov, who has written insightful
3640 @url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3641 on this topic}, refers to this kind of code generation as
3642 @dfn{staging}.}: the ``host code''---code that defines packages, talks
3643 to the daemon, etc.---and the ``build code''---code that actually
3644 performs build actions, such as making directories, invoking
3645 @command{make}, etc.
3646
3647 To describe a derivation and its build actions, one typically needs to
3648 embed build code inside host code. It boils down to manipulating build
3649 code as data, and the homoiconicity of Scheme---code has a direct
3650 representation as data---comes in handy for that. But we need more than
3651 the normal @code{quasiquote} mechanism in Scheme to construct build
3652 expressions.
3653
3654 The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3655 S-expressions adapted to build expressions. G-expressions, or
3656 @dfn{gexps}, consist essentially of three syntactic forms: @code{gexp},
3657 @code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
3658 @code{#$}, and @code{#$@@}), which are comparable to
3659 @code{quasiquote}, @code{unquote}, and @code{unquote-splicing},
3660 respectively (@pxref{Expression Syntax, @code{quasiquote},, guile,
3661 GNU Guile Reference Manual}). However, there are major differences:
3662
3663 @itemize
3664 @item
3665 Gexps are meant to be written to a file and run or manipulated by other
3666 processes.
3667
3668 @item
3669 When a high-level object such as a package or derivation is unquoted
3670 inside a gexp, the result is as if its output file name had been
3671 introduced.
3672
3673 @item
3674 Gexps carry information about the packages or derivations they refer to,
3675 and these dependencies are automatically added as inputs to the build
3676 processes that use them.
3677 @end itemize
3678
3679 @cindex lowering, of high-level objects in gexps
3680 This mechanism is not limited to package and derivation
3681 objects: @dfn{compilers} able to ``lower'' other high-level objects to
3682 derivations or files in the store can be defined,
3683 such that these objects can also be inserted
3684 into gexps. For example, a useful type of high-level objects that can be
3685 inserted in a gexp is ``file-like objects'', which make it easy to
3686 add files to the store and to refer to them in
3687 derivations and such (see @code{local-file} and @code{plain-file}
3688 below.)
3689
3690 To illustrate the idea, here is an example of a gexp:
3691
3692 @example
3693 (define build-exp
3694 #~(begin
3695 (mkdir #$output)
3696 (chdir #$output)
3697 (symlink (string-append #$coreutils "/bin/ls")
3698 "list-files")))
3699 @end example
3700
3701 This gexp can be passed to @code{gexp->derivation}; we obtain a
3702 derivation that builds a directory containing exactly one symlink to
3703 @file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3704
3705 @example
3706 (gexp->derivation "the-thing" build-exp)
3707 @end example
3708
3709 As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
3710 substituted to the reference to the @var{coreutils} package in the
3711 actual build code, and @var{coreutils} is automatically made an input to
3712 the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
3713 output)}) is replaced by a string containing the directory name of the
3714 output of the derivation.
3715
3716 @cindex cross compilation
3717 In a cross-compilation context, it is useful to distinguish between
3718 references to the @emph{native} build of a package---that can run on the
3719 host---versus references to cross builds of a package. To that end, the
3720 @code{#+} plays the same role as @code{#$}, but is a reference to a
3721 native package build:
3722
3723 @example
3724 (gexp->derivation "vi"
3725 #~(begin
3726 (mkdir #$output)
3727 (system* (string-append #+coreutils "/bin/ln")
3728 "-s"
3729 (string-append #$emacs "/bin/emacs")
3730 (string-append #$output "/bin/vi")))
3731 #:target "mips64el-linux")
3732 @end example
3733
3734 @noindent
3735 In the example above, the native build of @var{coreutils} is used, so
3736 that @command{ln} can actually run on the host; but then the
3737 cross-compiled build of @var{emacs} is referenced.
3738
3739 @cindex imported modules, for gexps
3740 @findex with-imported-modules
3741 Another gexp feature is @dfn{imported modules}: sometimes you want to be
3742 able to use certain Guile modules from the ``host environment'' in the
3743 gexp, so those modules should be imported in the ``build environment''.
3744 The @code{with-imported-modules} form allows you to express that:
3745
3746 @example
3747 (let ((build (with-imported-modules '((guix build utils))
3748 #~(begin
3749 (use-modules (guix build utils))
3750 (mkdir-p (string-append #$output "/bin"))))))
3751 (gexp->derivation "empty-dir"
3752 #~(begin
3753 #$build
3754 (display "success!\n")
3755 #t)))
3756 @end example
3757
3758 @noindent
3759 In this example, the @code{(guix build utils)} module is automatically
3760 pulled into the isolated build environment of our gexp, such that
3761 @code{(use-modules (guix build utils))} works as expected.
3762
3763 The syntactic form to construct gexps is summarized below.
3764
3765 @deffn {Scheme Syntax} #~@var{exp}
3766 @deffnx {Scheme Syntax} (gexp @var{exp})
3767 Return a G-expression containing @var{exp}. @var{exp} may contain one
3768 or more of the following forms:
3769
3770 @table @code
3771 @item #$@var{obj}
3772 @itemx (ungexp @var{obj})
3773 Introduce a reference to @var{obj}. @var{obj} may have one of the
3774 supported types, for example a package or a
3775 derivation, in which case the @code{ungexp} form is replaced by its
3776 output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
3777
3778 If @var{obj} is a list, it is traversed and references to supported
3779 objects are substituted similarly.
3780
3781 If @var{obj} is another gexp, its contents are inserted and its
3782 dependencies are added to those of the containing gexp.
3783
3784 If @var{obj} is another kind of object, it is inserted as is.
3785
3786 @item #$@var{obj}:@var{output}
3787 @itemx (ungexp @var{obj} @var{output})
3788 This is like the form above, but referring explicitly to the
3789 @var{output} of @var{obj}---this is useful when @var{obj} produces
3790 multiple outputs (@pxref{Packages with Multiple Outputs}).
3791
3792 @item #+@var{obj}
3793 @itemx #+@var{obj}:output
3794 @itemx (ungexp-native @var{obj})
3795 @itemx (ungexp-native @var{obj} @var{output})
3796 Same as @code{ungexp}, but produces a reference to the @emph{native}
3797 build of @var{obj} when used in a cross compilation context.
3798
3799 @item #$output[:@var{output}]
3800 @itemx (ungexp output [@var{output}])
3801 Insert a reference to derivation output @var{output}, or to the main
3802 output when @var{output} is omitted.
3803
3804 This only makes sense for gexps passed to @code{gexp->derivation}.
3805
3806 @item #$@@@var{lst}
3807 @itemx (ungexp-splicing @var{lst})
3808 Like the above, but splices the contents of @var{lst} inside the
3809 containing list.
3810
3811 @item #+@@@var{lst}
3812 @itemx (ungexp-native-splicing @var{lst})
3813 Like the above, but refers to native builds of the objects listed in
3814 @var{lst}.
3815
3816 @end table
3817
3818 G-expressions created by @code{gexp} or @code{#~} are run-time objects
3819 of the @code{gexp?} type (see below.)
3820 @end deffn
3821
3822 @deffn {Scheme Syntax} with-imported-modules @var{modules} @var{body}@dots{}
3823 Mark the gexps defined in @var{body}@dots{} as requiring @var{modules}
3824 in their execution environment. @var{modules} must be a list of Guile
3825 module names, such as @code{'((guix build utils) (guix build gremlin))}.
3826
3827 This form has @emph{lexical} scope: it has an effect on the gexps
3828 directly defined in @var{body}@dots{}, but not on those defined, say, in
3829 procedures called from @var{body}@dots{}.
3830 @end deffn
3831
3832 @deffn {Scheme Procedure} gexp? @var{obj}
3833 Return @code{#t} if @var{obj} is a G-expression.
3834 @end deffn
3835
3836 G-expressions are meant to be written to disk, either as code building
3837 some derivation, or as plain files in the store. The monadic procedures
3838 below allow you to do that (@pxref{The Store Monad}, for more
3839 information about monads.)
3840
3841 @deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
3842 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
3843 [#:hash #f] [#:hash-algo #f] @
3844 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3845 [#:module-path @var{%load-path}] @
3846 [#:references-graphs #f] [#:allowed-references #f] @
3847 [#:disallowed-references #f] @
3848 [#:leaked-env-vars #f] @
3849 [#:script-name (string-append @var{name} "-builder")] @
3850 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3851 Return a derivation @var{name} that runs @var{exp} (a gexp) with
3852 @var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
3853 stored in a file called @var{script-name}. When @var{target} is true,
3854 it is used as the cross-compilation target triplet for packages referred
3855 to by @var{exp}.
3856
3857 @var{modules} is deprecated in favor of @code{with-imported-modules}.
3858 Its meaning is to
3859 make @var{modules} available in the evaluation context of @var{exp};
3860 @var{modules} is a list of names of Guile modules searched in
3861 @var{module-path} to be copied in the store, compiled, and made available in
3862 the load path during the execution of @var{exp}---e.g., @code{((guix
3863 build utils) (guix build gnu-build-system))}.
3864
3865 @var{graft?} determines whether packages referred to by @var{exp} should be grafted when
3866 applicable.
3867
3868 When @var{references-graphs} is true, it must be a list of tuples of one of the
3869 following forms:
3870
3871 @example
3872 (@var{file-name} @var{package})
3873 (@var{file-name} @var{package} @var{output})
3874 (@var{file-name} @var{derivation})
3875 (@var{file-name} @var{derivation} @var{output})
3876 (@var{file-name} @var{store-item})
3877 @end example
3878
3879 The right-hand-side of each element of @var{references-graphs} is automatically made
3880 an input of the build process of @var{exp}. In the build environment, each
3881 @var{file-name} contains the reference graph of the corresponding item, in a simple
3882 text format.
3883
3884 @var{allowed-references} must be either @code{#f} or a list of output names and packages.
3885 In the latter case, the list denotes store items that the result is allowed to
3886 refer to. Any reference to another store item will lead to a build error.
3887 Similarly for @var{disallowed-references}, which can list items that must not be
3888 referenced by the outputs.
3889
3890 The other arguments are as for @code{derivation} (@pxref{Derivations}).
3891 @end deffn
3892
3893 @cindex file-like objects
3894 The @code{local-file}, @code{plain-file}, @code{computed-file},
3895 @code{program-file}, and @code{scheme-file} procedures below return
3896 @dfn{file-like objects}. That is, when unquoted in a G-expression,
3897 these objects lead to a file in the store. Consider this G-expression:
3898
3899 @example
3900 #~(system* (string-append #$glibc "/sbin/nscd") "-f"
3901 #$(local-file "/tmp/my-nscd.conf"))
3902 @end example
3903
3904 The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
3905 to the store. Once expanded, for instance @i{via}
3906 @code{gexp->derivation}, the G-expression refers to that copy under
3907 @file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
3908 does not have any effect on what the G-expression does.
3909 @code{plain-file} can be used similarly; it differs in that the file
3910 content is directly passed as a string.
3911
3912 @deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
3913 [#:recursive? #f] [#:select? (const #t)]
3914 Return an object representing local file @var{file} to add to the store; this
3915 object can be used in a gexp. If @var{file} is a relative file name, it is looked
3916 up relative to the source file where this form appears. @var{file} will be added to
3917 the store under @var{name}--by default the base name of @var{file}.
3918
3919 When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
3920 designates a flat file and @var{recursive?} is true, its contents are added, and its
3921 permission bits are kept.
3922
3923 When @var{recursive?} is true, call @code{(@var{select?} @var{file}
3924 @var{stat})} for each directory entry, where @var{file} is the entry's
3925 absolute file name and @var{stat} is the result of @code{lstat}; exclude
3926 entries for which @var{select?} does not return true.
3927
3928 This is the declarative counterpart of the @code{interned-file} monadic
3929 procedure (@pxref{The Store Monad, @code{interned-file}}).
3930 @end deffn
3931
3932 @deffn {Scheme Procedure} plain-file @var{name} @var{content}
3933 Return an object representing a text file called @var{name} with the given
3934 @var{content} (a string) to be added to the store.
3935
3936 This is the declarative counterpart of @code{text-file}.
3937 @end deffn
3938
3939 @deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
3940 [#:options '(#:local-build? #t)]
3941 Return an object representing the store item @var{name}, a file or
3942 directory computed by @var{gexp}. @var{options}
3943 is a list of additional arguments to pass to @code{gexp->derivation}.
3944
3945 This is the declarative counterpart of @code{gexp->derivation}.
3946 @end deffn
3947
3948 @deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
3949 Return an executable script @var{name} that runs @var{exp} using
3950 @var{guile}, with @var{exp}'s imported modules in its search path.
3951
3952 The example below builds a script that simply invokes the @command{ls}
3953 command:
3954
3955 @example
3956 (use-modules (guix gexp) (gnu packages base))
3957
3958 (gexp->script "list-files"
3959 #~(execl (string-append #$coreutils "/bin/ls")
3960 "ls"))
3961 @end example
3962
3963 When ``running'' it through the store (@pxref{The Store Monad,
3964 @code{run-with-store}}), we obtain a derivation that produces an
3965 executable file @file{/gnu/store/@dots{}-list-files} along these lines:
3966
3967 @example
3968 #!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
3969 !#
3970 (execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls")
3971 "ls")
3972 @end example
3973 @end deffn
3974
3975 @deffn {Scheme Procedure} program-file @var{name} @var{exp} @
3976 [#:guile #f]
3977 Return an object representing the executable store item @var{name} that
3978 runs @var{gexp}. @var{guile} is the Guile package used to execute that
3979 script.
3980
3981 This is the declarative counterpart of @code{gexp->script}.
3982 @end deffn
3983
3984 @deffn {Monadic Procedure} gexp->file @var{name} @var{exp} @
3985 [#:set-load-path? #t]
3986 Return a derivation that builds a file @var{name} containing @var{exp}.
3987 When @var{set-load-path?} is true, emit code in the resulting file to
3988 set @code{%load-path} and @code{%load-compiled-path} to honor
3989 @var{exp}'s imported modules.
3990
3991 The resulting file holds references to all the dependencies of @var{exp}
3992 or a subset thereof.
3993 @end deffn
3994
3995 @deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
3996 Return an object representing the Scheme file @var{name} that contains
3997 @var{exp}.
3998
3999 This is the declarative counterpart of @code{gexp->file}.
4000 @end deffn
4001
4002 @deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
4003 Return as a monadic value a derivation that builds a text file
4004 containing all of @var{text}. @var{text} may list, in addition to
4005 strings, objects of any type that can be used in a gexp: packages,
4006 derivations, local file objects, etc. The resulting store file holds
4007 references to all these.
4008
4009 This variant should be preferred over @code{text-file} anytime the file
4010 to create will reference items from the store. This is typically the
4011 case when building a configuration file that embeds store file names,
4012 like this:
4013
4014 @example
4015 (define (profile.sh)
4016 ;; Return the name of a shell script in the store that
4017 ;; initializes the 'PATH' environment variable.
4018 (text-file* "profile.sh"
4019 "export PATH=" coreutils "/bin:"
4020 grep "/bin:" sed "/bin\n"))
4021 @end example
4022
4023 In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
4024 will reference @var{coreutils}, @var{grep}, and @var{sed}, thereby
4025 preventing them from being garbage-collected during its lifetime.
4026 @end deffn
4027
4028 @deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
4029 Return an object representing store file @var{name} containing
4030 @var{text}. @var{text} is a sequence of strings and file-like objects,
4031 as in:
4032
4033 @example
4034 (mixed-text-file "profile"
4035 "export PATH=" coreutils "/bin:" grep "/bin")
4036 @end example
4037
4038 This is the declarative counterpart of @code{text-file*}.
4039 @end deffn
4040
4041 Of course, in addition to gexps embedded in ``host'' code, there are
4042 also modules containing build tools. To make it clear that they are
4043 meant to be used in the build stratum, these modules are kept in the
4044 @code{(guix build @dots{})} name space.
4045
4046 @cindex lowering, of high-level objects in gexps
4047 Internally, high-level objects are @dfn{lowered}, using their compiler,
4048 to either derivations or store items. For instance, lowering a package
4049 yields a derivation, and lowering a @code{plain-file} yields a store
4050 item. This is achieved using the @code{lower-object} monadic procedure.
4051
4052 @deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
4053 [#:target #f]
4054 Return as a value in @var{%store-monad} the derivation or store item
4055 corresponding to @var{obj} for @var{system}, cross-compiling for
4056 @var{target} if @var{target} is true. @var{obj} must be an object that
4057 has an associated gexp compiler, such as a @code{<package>}.
4058 @end deffn
4059
4060
4061 @c *********************************************************************
4062 @node Utilities
4063 @chapter Utilities
4064
4065 This section describes Guix command-line utilities. Some of them are
4066 primarily targeted at developers and users who write new package
4067 definitions, while others are more generally useful. They complement
4068 the Scheme programming interface of Guix in a convenient way.
4069
4070 @menu
4071 * Invoking guix build:: Building packages from the command line.
4072 * Invoking guix edit:: Editing package definitions.
4073 * Invoking guix download:: Downloading a file and printing its hash.
4074 * Invoking guix hash:: Computing the cryptographic hash of a file.
4075 * Invoking guix import:: Importing package definitions.
4076 * Invoking guix refresh:: Updating package definitions.
4077 * Invoking guix lint:: Finding errors in package definitions.
4078 * Invoking guix size:: Profiling disk usage.
4079 * Invoking guix graph:: Visualizing the graph of packages.
4080 * Invoking guix environment:: Setting up development environments.
4081 * Invoking guix publish:: Sharing substitutes.
4082 * Invoking guix challenge:: Challenging substitute servers.
4083 * Invoking guix container:: Process isolation.
4084 @end menu
4085
4086 @node Invoking guix build
4087 @section Invoking @command{guix build}
4088
4089 The @command{guix build} command builds packages or derivations and
4090 their dependencies, and prints the resulting store paths. Note that it
4091 does not modify the user's profile---this is the job of the
4092 @command{guix package} command (@pxref{Invoking guix package}). Thus,
4093 it is mainly useful for distribution developers.
4094
4095 The general syntax is:
4096
4097 @example
4098 guix build @var{options} @var{package-or-derivation}@dots{}
4099 @end example
4100
4101 As an example, the following command builds the latest versions of Emacs
4102 and of Guile, displays their build logs, and finally displays the
4103 resulting directories:
4104
4105 @example
4106 guix build emacs guile
4107 @end example
4108
4109 Similarly, the following command builds all the available packages:
4110
4111 @example
4112 guix build --quiet --keep-going \
4113 `guix package -A | cut -f1,2 --output-delimiter=@@`
4114 @end example
4115
4116 @var{package-or-derivation} may be either the name of a package found in
4117 the software distribution such as @code{coreutils} or
4118 @code{coreutils-8.20}, or a derivation such as
4119 @file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
4120 package with the corresponding name (and optionally version) is searched
4121 for among the GNU distribution modules (@pxref{Package Modules}).
4122
4123 Alternatively, the @code{--expression} option may be used to specify a
4124 Scheme expression that evaluates to a package; this is useful when
4125 disambiguating among several same-named packages or package variants is
4126 needed.
4127
4128 There may be zero or more @var{options}. The available options are
4129 described in the subsections below.
4130
4131 @menu
4132 * Common Build Options:: Build options for most commands.
4133 * Package Transformation Options:: Creating variants of packages.
4134 * Additional Build Options:: Options specific to 'guix build'.
4135 @end menu
4136
4137 @node Common Build Options
4138 @subsection Common Build Options
4139
4140 A number of options that control the build process are common to
4141 @command{guix build} and other commands that can spawn builds, such as
4142 @command{guix package} or @command{guix archive}. These are the
4143 following:
4144
4145 @table @code
4146
4147 @item --load-path=@var{directory}
4148 @itemx -L @var{directory}
4149 Add @var{directory} to the front of the package module search path
4150 (@pxref{Package Modules}).
4151
4152 This allows users to define their own packages and make them visible to
4153 the command-line tools.
4154
4155 @item --keep-failed
4156 @itemx -K
4157 Keep the build tree of failed builds. Thus, if a build fails, its build
4158 tree is kept under @file{/tmp}, in a directory whose name is shown at
4159 the end of the build log. This is useful when debugging build issues.
4160
4161 @item --keep-going
4162 @itemx -k
4163 Keep going when some of the derivations fail to build; return only once
4164 all the builds have either completed or failed.
4165
4166 The default behavior is to stop as soon as one of the specified
4167 derivations has failed.
4168
4169 @item --dry-run
4170 @itemx -n
4171 Do not build the derivations.
4172
4173 @item --fallback
4174 When substituting a pre-built binary fails, fall back to building
4175 packages locally.
4176
4177 @item --substitute-urls=@var{urls}
4178 @anchor{client-substitute-urls}
4179 Consider @var{urls} the whitespace-separated list of substitute source
4180 URLs, overriding the default list of URLs of @command{guix-daemon}
4181 (@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
4182
4183 This means that substitutes may be downloaded from @var{urls}, provided
4184 they are signed by a key authorized by the system administrator
4185 (@pxref{Substitutes}).
4186
4187 When @var{urls} is the empty string, substitutes are effectively
4188 disabled.
4189
4190 @item --no-substitutes
4191 Do not use substitutes for build products. That is, always build things
4192 locally instead of allowing downloads of pre-built binaries
4193 (@pxref{Substitutes}).
4194
4195 @item --no-grafts
4196 Do not ``graft'' packages. In practice, this means that package updates
4197 available as grafts are not applied. @xref{Security Updates}, for more
4198 information on grafts.
4199
4200 @item --rounds=@var{n}
4201 Build each derivation @var{n} times in a row, and raise an error if
4202 consecutive build results are not bit-for-bit identical.
4203
4204 This is a useful way to detect non-deterministic builds processes.
4205 Non-deterministic build processes are a problem because they make it
4206 practically impossible for users to @emph{verify} whether third-party
4207 binaries are genuine. @xref{Invoking guix challenge}, for more.
4208
4209 Note that, currently, the differing build results are not kept around,
4210 so you will have to manually investigate in case of an error---e.g., by
4211 stashing one of the build results with @code{guix archive --export}
4212 (@pxref{Invoking guix archive}), then rebuilding, and finally comparing
4213 the two results.
4214
4215 @item --no-build-hook
4216 Do not attempt to offload builds @i{via} the ``build hook'' of the daemon
4217 (@pxref{Daemon Offload Setup}). That is, always build things locally
4218 instead of offloading builds to remote machines.
4219
4220 @item --max-silent-time=@var{seconds}
4221 When the build or substitution process remains silent for more than
4222 @var{seconds}, terminate it and report a build failure.
4223
4224 @item --timeout=@var{seconds}
4225 Likewise, when the build or substitution process lasts for more than
4226 @var{seconds}, terminate it and report a build failure.
4227
4228 By default there is no timeout. This behavior can be restored with
4229 @code{--timeout=0}.
4230
4231 @item --verbosity=@var{level}
4232 Use the given verbosity level. @var{level} must be an integer between 0
4233 and 5; higher means more verbose output. Setting a level of 4 or more
4234 may be helpful when debugging setup issues with the build daemon.
4235
4236 @item --cores=@var{n}
4237 @itemx -c @var{n}
4238 Allow the use of up to @var{n} CPU cores for the build. The special
4239 value @code{0} means to use as many CPU cores as available.
4240
4241 @item --max-jobs=@var{n}
4242 @itemx -M @var{n}
4243 Allow at most @var{n} build jobs in parallel. @xref{Invoking
4244 guix-daemon, @code{--max-jobs}}, for details about this option and the
4245 equivalent @command{guix-daemon} option.
4246
4247 @end table
4248
4249 Behind the scenes, @command{guix build} is essentially an interface to
4250 the @code{package-derivation} procedure of the @code{(guix packages)}
4251 module, and to the @code{build-derivations} procedure of the @code{(guix
4252 derivations)} module.
4253
4254 In addition to options explicitly passed on the command line,
4255 @command{guix build} and other @command{guix} commands that support
4256 building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
4257
4258 @defvr {Environment Variable} GUIX_BUILD_OPTIONS
4259 Users can define this variable to a list of command line options that
4260 will automatically be used by @command{guix build} and other
4261 @command{guix} commands that can perform builds, as in the example
4262 below:
4263
4264 @example
4265 $ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
4266 @end example
4267
4268 These options are parsed independently, and the result is appended to
4269 the parsed command-line options.
4270 @end defvr
4271
4272
4273 @node Package Transformation Options
4274 @subsection Package Transformation Options
4275
4276 @cindex package variants
4277 Another set of command-line options supported by @command{guix build}
4278 and also @command{guix package} are @dfn{package transformation
4279 options}. These are options that make it possible to define @dfn{package
4280 variants}---for instance, packages built from different source code.
4281 This is a convenient way to create customized packages on the fly
4282 without having to type in the definitions of package variants
4283 (@pxref{Defining Packages}).
4284
4285 @table @code
4286
4287 @item --with-source=@var{source}
4288 Use @var{source} as the source of the corresponding package.
4289 @var{source} must be a file name or a URL, as for @command{guix
4290 download} (@pxref{Invoking guix download}).
4291
4292 The ``corresponding package'' is taken to be the one specified on the
4293 command line the name of which matches the base of @var{source}---e.g.,
4294 if @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
4295 package is @code{guile}. Likewise, the version string is inferred from
4296 @var{source}; in the previous example, it is @code{2.0.10}.
4297
4298 This option allows users to try out versions of packages other than the
4299 one provided by the distribution. The example below downloads
4300 @file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
4301 the @code{ed} package:
4302
4303 @example
4304 guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
4305 @end example
4306
4307 As a developer, @code{--with-source} makes it easy to test release
4308 candidates:
4309
4310 @example
4311 guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
4312 @end example
4313
4314 @dots{} or to build from a checkout in a pristine environment:
4315
4316 @example
4317 $ git clone git://git.sv.gnu.org/guix.git
4318 $ guix build guix --with-source=./guix
4319 @end example
4320
4321 @item --with-input=@var{package}=@var{replacement}
4322 Replace dependency on @var{package} by a dependency on
4323 @var{replacement}. @var{package} must be a package name, and
4324 @var{replacement} must be a package specification such as @code{guile}
4325 or @code{guile@@1.8}.
4326
4327 For instance, the following command builds Guix, but replaces its
4328 dependency on the current stable version of Guile with a dependency on
4329 the development version of Guile, @code{guile-next}:
4330
4331 @example
4332 guix build --with-input=guile=guile-next guix
4333 @end example
4334
4335 This is a recursive, deep replacement. So in this example, both
4336 @code{guix} and its dependency @code{guile-json} (which also depends on
4337 @code{guile}) get rebuilt against @code{guile-next}.
4338
4339 However, implicit inputs are left unchanged.
4340 @end table
4341
4342 @node Additional Build Options
4343 @subsection Additional Build Options
4344
4345 The command-line options presented below are specific to @command{guix
4346 build}.
4347
4348 @table @code
4349
4350 @item --quiet
4351 @itemx -q
4352 Build quietly, without displaying the build log. Upon completion, the
4353 build log is kept in @file{/var} (or similar) and can always be
4354 retrieved using the @option{--log-file} option.
4355
4356 @item --file=@var{file}
4357 @itemx -f @var{file}
4358
4359 Build the package or derivation that the code within @var{file}
4360 evaluates to.
4361
4362 As an example, @var{file} might contain a package definition like this
4363 (@pxref{Defining Packages}):
4364
4365 @example
4366 @verbatiminclude package-hello.scm
4367 @end example
4368
4369 @item --expression=@var{expr}
4370 @itemx -e @var{expr}
4371 Build the package or derivation @var{expr} evaluates to.
4372
4373 For example, @var{expr} may be @code{(@@ (gnu packages guile)
4374 guile-1.8)}, which unambiguously designates this specific variant of
4375 version 1.8 of Guile.
4376
4377 Alternatively, @var{expr} may be a G-expression, in which case it is used
4378 as a build program passed to @code{gexp->derivation}
4379 (@pxref{G-Expressions}).
4380
4381 Lastly, @var{expr} may refer to a zero-argument monadic procedure
4382 (@pxref{The Store Monad}). The procedure must return a derivation as a
4383 monadic value, which is then passed through @code{run-with-store}.
4384
4385 @item --source
4386 @itemx -S
4387 Build the source derivations of the packages, rather than the packages
4388 themselves.
4389
4390 For instance, @code{guix build -S gcc} returns something like
4391 @file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
4392 source tarball.
4393
4394 The returned source tarball is the result of applying any patches and
4395 code snippets specified in the package @code{origin} (@pxref{Defining
4396 Packages}).
4397
4398 @item --sources
4399 Fetch and return the source of @var{package-or-derivation} and all their
4400 dependencies, recursively. This is a handy way to obtain a local copy
4401 of all the source code needed to build @var{packages}, allowing you to
4402 eventually build them even without network access. It is an extension
4403 of the @code{--source} option and can accept one of the following
4404 optional argument values:
4405
4406 @table @code
4407 @item package
4408 This value causes the @code{--sources} option to behave in the same way
4409 as the @code{--source} option.
4410
4411 @item all
4412 Build the source derivations of all packages, including any source that
4413 might be listed as @code{inputs}. This is the default value.
4414
4415 @example
4416 $ guix build --sources tzdata
4417 The following derivations will be built:
4418 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
4419 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4420 @end example
4421
4422 @item transitive
4423 Build the source derivations of all packages, as well of all transitive
4424 inputs to the packages. This can be used e.g. to
4425 prefetch package source for later offline building.
4426
4427 @example
4428 $ guix build --sources=transitive tzdata
4429 The following derivations will be built:
4430 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4431 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
4432 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
4433 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
4434 /gnu/store/@dots{}-make-4.1.tar.xz.drv
4435 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
4436 @dots{}
4437 @end example
4438
4439 @end table
4440
4441 @item --system=@var{system}
4442 @itemx -s @var{system}
4443 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
4444 the system type of the build host.
4445
4446 An example use of this is on Linux-based systems, which can emulate
4447 different personalities. For instance, passing
4448 @code{--system=i686-linux} on an @code{x86_64-linux} system allows users
4449 to build packages in a complete 32-bit environment.
4450
4451 @item --target=@var{triplet}
4452 @cindex cross-compilation
4453 Cross-build for @var{triplet}, which must be a valid GNU triplet, such
4454 as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
4455 configuration triplets,, configure, GNU Configure and Build System}).
4456
4457 @anchor{build-check}
4458 @item --check
4459 @cindex determinism, checking
4460 @cindex reproducibility, checking
4461 Rebuild @var{package-or-derivation}, which are already available in the
4462 store, and raise an error if the build results are not bit-for-bit
4463 identical.
4464
4465 This mechanism allows you to check whether previously installed
4466 substitutes are genuine (@pxref{Substitutes}), or whether the build result
4467 of a package is deterministic. @xref{Invoking guix challenge}, for more
4468 background information and tools.
4469
4470 When used in conjunction with @option{--keep-failed}, the differing
4471 output is kept in the store, under @file{/gnu/store/@dots{}-check}.
4472 This makes it easy to look for differences between the two results.
4473
4474 @item --derivations
4475 @itemx -d
4476 Return the derivation paths, not the output paths, of the given
4477 packages.
4478
4479 @item --root=@var{file}
4480 @itemx -r @var{file}
4481 Make @var{file} a symlink to the result, and register it as a garbage
4482 collector root.
4483
4484 @item --log-file
4485 Return the build log file names or URLs for the given
4486 @var{package-or-derivation}, or raise an error if build logs are
4487 missing.
4488
4489 This works regardless of how packages or derivations are specified. For
4490 instance, the following invocations are equivalent:
4491
4492 @example
4493 guix build --log-file `guix build -d guile`
4494 guix build --log-file `guix build guile`
4495 guix build --log-file guile
4496 guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
4497 @end example
4498
4499 If a log is unavailable locally, and unless @code{--no-substitutes} is
4500 passed, the command looks for a corresponding log on one of the
4501 substitute servers (as specified with @code{--substitute-urls}.)
4502
4503 So for instance, imagine you want to see the build log of GDB on MIPS,
4504 but you are actually on an @code{x86_64} machine:
4505
4506 @example
4507 $ guix build --log-file gdb -s mips64el-linux
4508 https://hydra.gnu.org/log/@dots{}-gdb-7.10
4509 @end example
4510
4511 You can freely access a huge library of build logs!
4512 @end table
4513
4514
4515 @node Invoking guix edit
4516 @section Invoking @command{guix edit}
4517
4518 @cindex package definition, editing
4519 So many packages, so many source files! The @command{guix edit} command
4520 facilitates the life of packagers by pointing their editor at the source
4521 file containing the definition of the specified packages. For instance:
4522
4523 @example
4524 guix edit gcc@@4.9 vim
4525 @end example
4526
4527 @noindent
4528 launches the program specified in the @code{VISUAL} or in the
4529 @code{EDITOR} environment variable to edit the recipe of GCC@tie{}4.9.3
4530 and that of Vim.
4531
4532 If you are using Emacs, note that the Emacs user interface provides the
4533 @kbd{M-x guix-edit} command and a similar functionality in the ``package
4534 info'' and ``package list'' buffers created by the @kbd{M-x
4535 guix-search-by-name} and similar commands (@pxref{Emacs Commands}).
4536
4537
4538 @node Invoking guix download
4539 @section Invoking @command{guix download}
4540
4541 When writing a package definition, developers typically need to download
4542 a source tarball, compute its SHA256 hash, and write that
4543 hash in the package definition (@pxref{Defining Packages}). The
4544 @command{guix download} tool helps with this task: it downloads a file
4545 from the given URI, adds it to the store, and prints both its file name
4546 in the store and its SHA256 hash.
4547
4548 The fact that the downloaded file is added to the store saves bandwidth:
4549 when the developer eventually tries to build the newly defined package
4550 with @command{guix build}, the source tarball will not have to be
4551 downloaded again because it is already in the store. It is also a
4552 convenient way to temporarily stash files, which may be deleted
4553 eventually (@pxref{Invoking guix gc}).
4554
4555 The @command{guix download} command supports the same URIs as used in
4556 package definitions. In particular, it supports @code{mirror://} URIs.
4557 @code{https} URIs (HTTP over TLS) are supported @emph{provided} the
4558 Guile bindings for GnuTLS are available in the user's environment; when
4559 they are not available, an error is raised. @xref{Guile Preparations,
4560 how to install the GnuTLS bindings for Guile,, gnutls-guile,
4561 GnuTLS-Guile}, for more information.
4562
4563 The following option is available:
4564
4565 @table @code
4566 @item --format=@var{fmt}
4567 @itemx -f @var{fmt}
4568 Write the hash in the format specified by @var{fmt}. For more
4569 information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
4570 @end table
4571
4572 @node Invoking guix hash
4573 @section Invoking @command{guix hash}
4574
4575 The @command{guix hash} command computes the SHA256 hash of a file.
4576 It is primarily a convenience tool for anyone contributing to the
4577 distribution: it computes the cryptographic hash of a file, which can be
4578 used in the definition of a package (@pxref{Defining Packages}).
4579
4580 The general syntax is:
4581
4582 @example
4583 guix hash @var{option} @var{file}
4584 @end example
4585
4586 @command{guix hash} has the following option:
4587
4588 @table @code
4589
4590 @item --format=@var{fmt}
4591 @itemx -f @var{fmt}
4592 Write the hash in the format specified by @var{fmt}.
4593
4594 Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4595 (@code{hex} and @code{hexadecimal} can be used as well).
4596
4597 If the @option{--format} option is not specified, @command{guix hash}
4598 will output the hash in @code{nix-base32}. This representation is used
4599 in the definitions of packages.
4600
4601 @item --recursive
4602 @itemx -r
4603 Compute the hash on @var{file} recursively.
4604
4605 In this case, the hash is computed on an archive containing @var{file},
4606 including its children if it is a directory. Some of the metadata of
4607 @var{file} is part of the archive; for instance, when @var{file} is a
4608 regular file, the hash is different depending on whether @var{file} is
4609 executable or not. Metadata such as time stamps has no impact on the
4610 hash (@pxref{Invoking guix archive}).
4611 @c FIXME: Replace xref above with xref to an ``Archive'' section when
4612 @c it exists.
4613
4614 @vindex git-fetch
4615 As an example, here is how you would compute the hash of a Git checkout,
4616 which is useful when using the @code{git-fetch} method (@pxref{origin
4617 Reference}):
4618
4619 @example
4620 $ git clone http://example.org/foo.git
4621 $ cd foo
4622 $ rm -rf .git
4623 $ guix hash -r .
4624 @end example
4625 @end table
4626
4627 @node Invoking guix import
4628 @section Invoking @command{guix import}
4629
4630 @cindex importing packages
4631 @cindex package import
4632 @cindex package conversion
4633 The @command{guix import} command is useful for people who would like to
4634 add a package to the distribution with as little work as
4635 possible---a legitimate demand. The command knows of a few
4636 repositories from which it can ``import'' package metadata. The result
4637 is a package definition, or a template thereof, in the format we know
4638 (@pxref{Defining Packages}).
4639
4640 The general syntax is:
4641
4642 @example
4643 guix import @var{importer} @var{options}@dots{}
4644 @end example
4645
4646 @var{importer} specifies the source from which to import package
4647 metadata, and @var{options} specifies a package identifier and other
4648 options specific to @var{importer}. Currently, the available
4649 ``importers'' are:
4650
4651 @table @code
4652 @item gnu
4653 Import metadata for the given GNU package. This provides a template
4654 for the latest version of that GNU package, including the hash of its
4655 source tarball, and its canonical synopsis and description.
4656
4657 Additional information such as the package dependencies and its
4658 license needs to be figured out manually.
4659
4660 For example, the following command returns a package definition for
4661 GNU@tie{}Hello:
4662
4663 @example
4664 guix import gnu hello
4665 @end example
4666
4667 Specific command-line options are:
4668
4669 @table @code
4670 @item --key-download=@var{policy}
4671 As for @code{guix refresh}, specify the policy to handle missing OpenPGP
4672 keys when verifying the package signature. @xref{Invoking guix
4673 refresh, @code{--key-download}}.
4674 @end table
4675
4676 @item pypi
4677 @cindex pypi
4678 Import metadata from the @uref{https://pypi.python.org/, Python Package
4679 Index}@footnote{This functionality requires Guile-JSON to be installed.
4680 @xref{Requirements}.}. Information is taken from the JSON-formatted
4681 description available at @code{pypi.python.org} and usually includes all
4682 the relevant information, including package dependencies. For maximum
4683 efficiency, it is recommended to install the @command{unzip} utility, so
4684 that the importer can unzip Python wheels and gather data from them.
4685
4686 The command below imports metadata for the @code{itsdangerous} Python
4687 package:
4688
4689 @example
4690 guix import pypi itsdangerous
4691 @end example
4692
4693 @item gem
4694 @cindex gem
4695 Import metadata from @uref{https://rubygems.org/,
4696 RubyGems}@footnote{This functionality requires Guile-JSON to be
4697 installed. @xref{Requirements}.}. Information is taken from the
4698 JSON-formatted description available at @code{rubygems.org} and includes
4699 most relevant information, including runtime dependencies. There are
4700 some caveats, however. The metadata doesn't distinguish between
4701 synopses and descriptions, so the same string is used for both fields.
4702 Additionally, the details of non-Ruby dependencies required to build
4703 native extensions is unavailable and left as an exercise to the
4704 packager.
4705
4706 The command below imports metadata for the @code{rails} Ruby package:
4707
4708 @example
4709 guix import gem rails
4710 @end example
4711
4712 @item cpan
4713 @cindex CPAN
4714 Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}@footnote{This
4715 functionality requires Guile-JSON to be installed.
4716 @xref{Requirements}.}.
4717 Information is taken from the JSON-formatted metadata provided through
4718 @uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
4719 relevant information, such as module dependencies. License information
4720 should be checked closely. If Perl is available in the store, then the
4721 @code{corelist} utility will be used to filter core modules out of the
4722 list of dependencies.
4723
4724 The command command below imports metadata for the @code{Acme::Boolean}
4725 Perl module:
4726
4727 @example
4728 guix import cpan Acme::Boolean
4729 @end example
4730
4731 @item cran
4732 @cindex CRAN
4733 @cindex Bioconductor
4734 Import metadata from @uref{http://cran.r-project.org/, CRAN}, the
4735 central repository for the @uref{http://r-project.org, GNU@tie{}R
4736 statistical and graphical environment}.
4737
4738 Information is extracted from the @code{DESCRIPTION} file of the package.
4739
4740 The command command below imports metadata for the @code{Cairo}
4741 R package:
4742
4743 @example
4744 guix import cran Cairo
4745 @end example
4746
4747 When @code{--archive=bioconductor} is added, metadata is imported from
4748 @uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
4749 packages for for the analysis and comprehension of high-throughput
4750 genomic data in bioinformatics.
4751
4752 Information is extracted from the @code{DESCRIPTION} file of a package
4753 published on the web interface of the Bioconductor SVN repository.
4754
4755 The command below imports metadata for the @code{GenomicRanges}
4756 R package:
4757
4758 @example
4759 guix import cran --archive=bioconductor GenomicRanges
4760 @end example
4761
4762 @item nix
4763 Import metadata from a local copy of the source of the
4764 @uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
4765 relies on the @command{nix-instantiate} command of
4766 @uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
4767 typically written in a mixture of Nix-language and Bash code. This
4768 command only imports the high-level package structure that is written in
4769 the Nix language. It normally includes all the basic fields of a
4770 package definition.
4771
4772 When importing a GNU package, the synopsis and descriptions are replaced
4773 by their canonical upstream variant.
4774
4775 Usually, you will first need to do:
4776
4777 @example
4778 export NIX_REMOTE=daemon
4779 @end example
4780
4781 @noindent
4782 so that @command{nix-instantiate} does not try to open the Nix database.
4783
4784 As an example, the command below imports the package definition of
4785 LibreOffice (more precisely, it imports the definition of the package
4786 bound to the @code{libreoffice} top-level attribute):
4787
4788 @example
4789 guix import nix ~/path/to/nixpkgs libreoffice
4790 @end example
4791
4792 @item hackage
4793 @cindex hackage
4794 Import metadata from the Haskell community's central package archive
4795 @uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4796 Cabal files and includes all the relevant information, including package
4797 dependencies.
4798
4799 Specific command-line options are:
4800
4801 @table @code
4802 @item --stdin
4803 @itemx -s
4804 Read a Cabal file from standard input.
4805 @item --no-test-dependencies
4806 @itemx -t
4807 Do not include dependencies required only by the test suites.
4808 @item --cabal-environment=@var{alist}
4809 @itemx -e @var{alist}
4810 @var{alist} is a Scheme alist defining the environment in which the
4811 Cabal conditionals are evaluated. The accepted keys are: @code{os},
4812 @code{arch}, @code{impl} and a string representing the name of a flag.
4813 The value associated with a flag has to be either the symbol
4814 @code{true} or @code{false}. The value associated with other keys
4815 has to conform to the Cabal file format definition. The default value
4816 associated with the keys @code{os}, @code{arch} and @code{impl} is
4817 @samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
4818 @end table
4819
4820 The command below imports metadata for the latest version of the
4821 @code{HTTP} Haskell package without including test dependencies and
4822 specifying the value of the flag @samp{network-uri} as @code{false}:
4823
4824 @example
4825 guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
4826 @end example
4827
4828 A specific package version may optionally be specified by following the
4829 package name by an at-sign and a version number as in the following example:
4830
4831 @example
4832 guix import hackage mtl@@2.1.3.1
4833 @end example
4834
4835 @item elpa
4836 @cindex elpa
4837 Import metadata from an Emacs Lisp Package Archive (ELPA) package
4838 repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4839
4840 Specific command-line options are:
4841
4842 @table @code
4843 @item --archive=@var{repo}
4844 @itemx -a @var{repo}
4845 @var{repo} identifies the archive repository from which to retrieve the
4846 information. Currently the supported repositories and their identifiers
4847 are:
4848 @itemize -
4849 @item
4850 @uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
4851 identifier. This is the default.
4852
4853 @item
4854 @uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
4855 @code{melpa-stable} identifier.
4856
4857 @item
4858 @uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
4859 identifier.
4860 @end itemize
4861 @end table
4862 @end table
4863
4864 The structure of the @command{guix import} code is modular. It would be
4865 useful to have more importers for other package formats, and your help
4866 is welcome here (@pxref{Contributing}).
4867
4868 @node Invoking guix refresh
4869 @section Invoking @command{guix refresh}
4870
4871 The primary audience of the @command{guix refresh} command is developers
4872 of the GNU software distribution. By default, it reports any packages
4873 provided by the distribution that are outdated compared to the latest
4874 upstream version, like this:
4875
4876 @example
4877 $ guix refresh
4878 gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
4879 gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
4880 @end example
4881
4882 It does so by browsing the FTP directory of each package and determining
4883 the highest version number of the source tarballs therein. The command
4884 knows how to update specific types of packages: GNU packages, ELPA
4885 packages, etc.---see the documentation for @option{--type} below. The
4886 are many packages, though, for which it lacks a method to determine
4887 whether a new upstream release is available. However, the mechanism is
4888 extensible, so feel free to get in touch with us to add a new method!
4889
4890 When passed @code{--update}, it modifies distribution source files to
4891 update the version numbers and source tarball hashes of those package
4892 recipes (@pxref{Defining Packages}). This is achieved by downloading
4893 each package's latest source tarball and its associated OpenPGP
4894 signature, authenticating the downloaded tarball against its signature
4895 using @command{gpg}, and finally computing its hash. When the public
4896 key used to sign the tarball is missing from the user's keyring, an
4897 attempt is made to automatically retrieve it from a public key server;
4898 when this is successful, the key is added to the user's keyring; otherwise,
4899 @command{guix refresh} reports an error.
4900
4901 The following options are supported:
4902
4903 @table @code
4904
4905 @item --expression=@var{expr}
4906 @itemx -e @var{expr}
4907 Consider the package @var{expr} evaluates to.
4908
4909 This is useful to precisely refer to a package, as in this example:
4910
4911 @example
4912 guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
4913 @end example
4914
4915 This command lists the dependents of the ``final'' libc (essentially all
4916 the packages.)
4917
4918 @item --update
4919 @itemx -u
4920 Update distribution source files (package recipes) in place. This is
4921 usually run from a checkout of the Guix source tree (@pxref{Running
4922 Guix Before It Is Installed}):
4923
4924 @example
4925 $ ./pre-inst-env guix refresh -s non-core
4926 @end example
4927
4928 @xref{Defining Packages}, for more information on package definitions.
4929
4930 @item --select=[@var{subset}]
4931 @itemx -s @var{subset}
4932 Select all the packages in @var{subset}, one of @code{core} or
4933 @code{non-core}.
4934
4935 The @code{core} subset refers to all the packages at the core of the
4936 distribution---i.e., packages that are used to build ``everything
4937 else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
4938 changing one of these packages in the distribution entails a rebuild of
4939 all the others. Thus, such updates are an inconvenience to users in
4940 terms of build time or bandwidth used to achieve the upgrade.
4941
4942 The @code{non-core} subset refers to the remaining packages. It is
4943 typically useful in cases where an update of the core packages would be
4944 inconvenient.
4945
4946 @item --type=@var{updater}
4947 @itemx -t @var{updater}
4948 Select only packages handled by @var{updater} (may be a comma-separated
4949 list of updaters). Currently, @var{updater} may be one of:
4950
4951 @table @code
4952 @item gnu
4953 the updater for GNU packages;
4954 @item gnome
4955 the updater for GNOME packages;
4956 @item xorg
4957 the updater for X.org packages;
4958 @item elpa
4959 the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
4960 @item cran
4961 the updater for @uref{http://cran.r-project.org/, CRAN} packages;
4962 @item bioconductor
4963 the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
4964 @item pypi
4965 the updater for @uref{https://pypi.python.org, PyPI} packages.
4966 @item gem
4967 the updater for @uref{https://rubygems.org, RubyGems} packages.
4968 @item github
4969 the updater for @uref{https://github.com, GitHub} packages.
4970 @item hackage
4971 the updater for @uref{https://hackage.haskell.org, Hackage} packages.
4972 @end table
4973
4974 For instance, the following command only checks for updates of Emacs
4975 packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
4976
4977 @example
4978 $ guix refresh --type=elpa,cran
4979 gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
4980 gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
4981 @end example
4982
4983 @end table
4984
4985 In addition, @command{guix refresh} can be passed one or more package
4986 names, as in this example:
4987
4988 @example
4989 $ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
4990 @end example
4991
4992 @noindent
4993 The command above specifically updates the @code{emacs} and
4994 @code{idutils} packages. The @code{--select} option would have no
4995 effect in this case.
4996
4997 When considering whether to upgrade a package, it is sometimes
4998 convenient to know which packages would be affected by the upgrade and
4999 should be checked for compatibility. For this the following option may
5000 be used when passing @command{guix refresh} one or more package names:
5001
5002 @table @code
5003
5004 @item --list-updaters
5005 @itemx -L
5006 List available updaters and exit (see @option{--type} above.)
5007
5008 @item --list-dependent
5009 @itemx -l
5010 List top-level dependent packages that would need to be rebuilt as a
5011 result of upgrading one or more packages.
5012
5013 @end table
5014
5015 Be aware that the @code{--list-dependent} option only
5016 @emph{approximates} the rebuilds that would be required as a result of
5017 an upgrade. More rebuilds might be required under some circumstances.
5018
5019 @example
5020 $ guix refresh --list-dependent flex
5021 Building the following 120 packages would ensure 213 dependent packages are rebuilt:
5022 hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
5023 @end example
5024
5025 The command above lists a set of packages that could be built to check
5026 for compatibility with an upgraded @code{flex} package.
5027
5028 The following options can be used to customize GnuPG operation:
5029
5030 @table @code
5031
5032 @item --gpg=@var{command}
5033 Use @var{command} as the GnuPG 2.x command. @var{command} is searched
5034 for in @code{$PATH}.
5035
5036 @item --key-download=@var{policy}
5037 Handle missing OpenPGP keys according to @var{policy}, which may be one
5038 of:
5039
5040 @table @code
5041 @item always
5042 Always download missing OpenPGP keys from the key server, and add them
5043 to the user's GnuPG keyring.
5044
5045 @item never
5046 Never try to download missing OpenPGP keys. Instead just bail out.
5047
5048 @item interactive
5049 When a package signed with an unknown OpenPGP key is encountered, ask
5050 the user whether to download it or not. This is the default behavior.
5051 @end table
5052
5053 @item --key-server=@var{host}
5054 Use @var{host} as the OpenPGP key server when importing a public key.
5055
5056 @end table
5057
5058 The @code{github} updater uses the
5059 @uref{https://developer.github.com/v3/, GitHub API} to query for new
5060 releases. When used repeatedly e.g. when refreshing all packages,
5061 GitHub will eventually refuse to answer any further API requests. By
5062 default 60 API requests per hour are allowed, and a full refresh on all
5063 GitHub packages in Guix requires more than this. Authentication with
5064 GitHub through the use of an API token alleviates these limits. To use
5065 an API token, set the environment variable @code{GUIX_GITHUB_TOKEN} to a
5066 token procured from @uref{https://github.com/settings/tokens} or
5067 otherwise.
5068
5069
5070 @node Invoking guix lint
5071 @section Invoking @command{guix lint}
5072 The @command{guix lint} command is meant to help package developers avoid
5073 common errors and use a consistent style. It runs a number of checks on
5074 a given set of packages in order to find common mistakes in their
5075 definitions. Available @dfn{checkers} include (see
5076 @code{--list-checkers} for a complete list):
5077
5078 @table @code
5079 @item synopsis
5080 @itemx description
5081 Validate certain typographical and stylistic rules about package
5082 descriptions and synopses.
5083
5084 @item inputs-should-be-native
5085 Identify inputs that should most likely be native inputs.
5086
5087 @item source
5088 @itemx home-page
5089 @itemx source-file-name
5090 Probe @code{home-page} and @code{source} URLs and report those that are
5091 invalid. Check that the source file name is meaningful, e.g. is not
5092 just a version number or ``git-checkout'', without a declared
5093 @code{file-name} (@pxref{origin Reference}).
5094
5095 @item cve
5096 @cindex security vulnerabilities
5097 @cindex CVE, Common Vulnerabilities and Exposures
5098 Report known vulnerabilities found in the Common Vulnerabilities and
5099 Exposures (CVE) databases of the current and past year
5100 @uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
5101 NIST}.
5102
5103 To view information about a particular vulnerability, visit pages such as:
5104
5105 @itemize
5106 @item
5107 @indicateurl{https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-YYYY-ABCD}
5108 @item
5109 @indicateurl{https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-YYYY-ABCD}
5110 @end itemize
5111
5112 @noindent
5113 where @code{CVE-YYYY-ABCD} is the CVE identifier---e.g.,
5114 @code{CVE-2015-7554}.
5115
5116 Package developers can specify in package recipes the
5117 @uref{https://nvd.nist.gov/cpe.cfm,Common Platform Enumeration (CPE)}
5118 name and version of the package when they differ from the name that Guix
5119 uses, as in this example:
5120
5121 @example
5122 (package
5123 (name "grub")
5124 ;; @dots{}
5125 ;; CPE calls this package "grub2".
5126 (properties '((cpe-name . "grub2"))))
5127 @end example
5128
5129 @item formatting
5130 Warn about obvious source code formatting issues: trailing white space,
5131 use of tabulations, etc.
5132 @end table
5133
5134 The general syntax is:
5135
5136 @example
5137 guix lint @var{options} @var{package}@dots{}
5138 @end example
5139
5140 If no package is given on the command line, then all packages are checked.
5141 The @var{options} may be zero or more of the following:
5142
5143 @table @code
5144 @item --list-checkers
5145 @itemx -l
5146 List and describe all the available checkers that will be run on packages
5147 and exit.
5148
5149 @item --checkers
5150 @itemx -c
5151 Only enable the checkers specified in a comma-separated list using the
5152 names returned by @code{--list-checkers}.
5153
5154 @end table
5155
5156 @node Invoking guix size
5157 @section Invoking @command{guix size}
5158
5159 The @command{guix size} command helps package developers profile the
5160 disk usage of packages. It is easy to overlook the impact of an
5161 additional dependency added to a package, or the impact of using a
5162 single output for a package that could easily be split (@pxref{Packages
5163 with Multiple Outputs}). Such are the typical issues that
5164 @command{guix size} can highlight.
5165
5166 The command can be passed a package specification such as @code{gcc-4.8}
5167 or @code{guile:debug}, or a file name in the store. Consider this
5168 example:
5169
5170 @example
5171 $ guix size coreutils
5172 store item total self
5173 /gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
5174 /gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
5175 /gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
5176 /gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
5177 /gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
5178 /gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
5179 @end example
5180
5181 @cindex closure
5182 The store items listed here constitute the @dfn{transitive closure} of
5183 Coreutils---i.e., Coreutils and all its dependencies, recursively---as
5184 would be returned by:
5185
5186 @example
5187 $ guix gc -R /gnu/store/@dots{}-coreutils-8.23
5188 @end example
5189
5190 Here the output shows three columns next to store items. The first column,
5191 labeled ``total'', shows the size in mebibytes (MiB) of the closure of
5192 the store item---that is, its own size plus the size of all its
5193 dependencies. The next column, labeled ``self'', shows the size of the
5194 item itself. The last column shows the ratio of the size of the item
5195 itself to the space occupied by all the items listed here.
5196
5197 In this example, we see that the closure of Coreutils weighs in at
5198 70@tie{}MiB, half of which is taken by libc. (That libc represents a
5199 large fraction of the closure is not a problem @i{per se} because it is
5200 always available on the system anyway.)
5201
5202 When the package passed to @command{guix size} is available in the
5203 store, @command{guix size} queries the daemon to determine its
5204 dependencies, and measures its size in the store, similar to @command{du
5205 -ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
5206 Coreutils}).
5207
5208 When the given package is @emph{not} in the store, @command{guix size}
5209 reports information based on the available substitutes
5210 (@pxref{Substitutes}). This makes it possible it to profile disk usage of
5211 store items that are not even on disk, only available remotely.
5212
5213 You can also specify several package names:
5214
5215 @example
5216 $ guix size coreutils grep sed bash
5217 store item total self
5218 /gnu/store/@dots{}-coreutils-8.24 77.8 13.8 13.4%
5219 /gnu/store/@dots{}-grep-2.22 73.1 0.8 0.8%
5220 /gnu/store/@dots{}-bash-4.3.42 72.3 4.7 4.6%
5221 /gnu/store/@dots{}-readline-6.3 67.6 1.2 1.2%
5222 @dots{}
5223 total: 102.3 MiB
5224 @end example
5225
5226 @noindent
5227 In this example we see that the combination of the four packages takes
5228 102.3@tie{}MiB in total, which is much less than the sum of each closure
5229 since they have a lot of dependencies in common.
5230
5231 The available options are:
5232
5233 @table @option
5234
5235 @item --substitute-urls=@var{urls}
5236 Use substitute information from @var{urls}.
5237 @xref{client-substitute-urls, the same option for @code{guix build}}.
5238
5239 @item --map-file=@var{file}
5240 Write a graphical map of disk usage in PNG format to @var{file}.
5241
5242 For the example above, the map looks like this:
5243
5244 @image{images/coreutils-size-map,5in,, map of Coreutils disk usage
5245 produced by @command{guix size}}
5246
5247 This option requires that
5248 @uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
5249 installed and visible in Guile's module search path. When that is not
5250 the case, @command{guix size} fails as it tries to load it.
5251
5252 @item --system=@var{system}
5253 @itemx -s @var{system}
5254 Consider packages for @var{system}---e.g., @code{x86_64-linux}.
5255
5256 @end table
5257
5258 @node Invoking guix graph
5259 @section Invoking @command{guix graph}
5260
5261 @cindex DAG
5262 Packages and their dependencies form a @dfn{graph}, specifically a
5263 directed acyclic graph (DAG). It can quickly become difficult to have a
5264 mental model of the package DAG, so the @command{guix graph} command
5265 provides a visual representation of the DAG. @command{guix graph}
5266 emits a DAG representation in the input format of
5267 @uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
5268 directly to the @command{dot} command of Graphviz. The general
5269 syntax is:
5270
5271 @example
5272 guix graph @var{options} @var{package}@dots{}
5273 @end example
5274
5275 For example, the following command generates a PDF file representing the
5276 package DAG for the GNU@tie{}Core Utilities, showing its build-time
5277 dependencies:
5278
5279 @example
5280 guix graph coreutils | dot -Tpdf > dag.pdf
5281 @end example
5282
5283 The output looks like this:
5284
5285 @image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
5286
5287 Nice little graph, no?
5288
5289 But there is more than one graph! The one above is concise: it is the
5290 graph of package objects, omitting implicit inputs such as GCC, libc,
5291 grep, etc. It is often useful to have such a concise graph, but
5292 sometimes one may want to see more details. @command{guix graph} supports
5293 several types of graphs, allowing you to choose the level of detail:
5294
5295 @table @code
5296 @item package
5297 This is the default type used in the example above. It shows the DAG of
5298 package objects, excluding implicit dependencies. It is concise, but
5299 filters out many details.
5300
5301 @item bag-emerged
5302 This is the package DAG, @emph{including} implicit inputs.
5303
5304 For instance, the following command:
5305
5306 @example
5307 guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
5308 @end example
5309
5310 ... yields this bigger graph:
5311
5312 @image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
5313
5314 At the bottom of the graph, we see all the implicit inputs of
5315 @var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
5316
5317 Now, note that the dependencies of these implicit inputs---that is, the
5318 @dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
5319 here, for conciseness.
5320
5321 @item bag
5322 Similar to @code{bag-emerged}, but this time including all the bootstrap
5323 dependencies.
5324
5325 @item bag-with-origins
5326 Similar to @code{bag}, but also showing origins and their dependencies.
5327
5328 @item derivations
5329 This is the most detailed representation: It shows the DAG of
5330 derivations (@pxref{Derivations}) and plain store items. Compared to
5331 the above representation, many additional nodes are visible, including
5332 build scripts, patches, Guile modules, etc.
5333
5334 For this type of graph, it is also possible to pass a @file{.drv} file
5335 name instead of a package name, as in:
5336
5337 @example
5338 guix graph -t derivation `guix system build -d my-config.scm`
5339 @end example
5340 @end table
5341
5342 All the types above correspond to @emph{build-time dependencies}. The
5343 following graph type represents the @emph{run-time dependencies}:
5344
5345 @table @code
5346 @item references
5347 This is the graph of @dfn{references} of a package output, as returned
5348 by @command{guix gc --references} (@pxref{Invoking guix gc}).
5349
5350 If the given package output is not available in the store, @command{guix
5351 graph} attempts to obtain dependency information from substitutes.
5352
5353 Here you can also pass a store file name instead of a package name. For
5354 example, the command below produces the reference graph of your profile
5355 (which can be big!):
5356
5357 @example
5358 guix graph -t references `readlink -f ~/.guix-profile`
5359 @end example
5360 @end table
5361
5362 The available options are the following:
5363
5364 @table @option
5365 @item --type=@var{type}
5366 @itemx -t @var{type}
5367 Produce a graph output of @var{type}, where @var{type} must be one of
5368 the values listed above.
5369
5370 @item --list-types
5371 List the supported graph types.
5372
5373 @item --expression=@var{expr}
5374 @itemx -e @var{expr}
5375 Consider the package @var{expr} evaluates to.
5376
5377 This is useful to precisely refer to a package, as in this example:
5378
5379 @example
5380 guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
5381 @end example
5382 @end table
5383
5384
5385 @node Invoking guix environment
5386 @section Invoking @command{guix environment}
5387
5388 @cindex reproducible build environments
5389 @cindex development environments
5390 The purpose of @command{guix environment} is to assist hackers in
5391 creating reproducible development environments without polluting their
5392 package profile. The @command{guix environment} tool takes one or more
5393 packages, builds all of their inputs, and creates a shell
5394 environment to use them.
5395
5396 The general syntax is:
5397
5398 @example
5399 guix environment @var{options} @var{package}@dots{}
5400 @end example
5401
5402 The following example spawns a new shell set up for the development of
5403 GNU@tie{}Guile:
5404
5405 @example
5406 guix environment guile
5407 @end example
5408
5409 If the needed dependencies are not built yet, @command{guix environment}
5410 automatically builds them. The environment of the new shell is an augmented
5411 version of the environment that @command{guix environment} was run in.
5412 It contains the necessary search paths for building the given package
5413 added to the existing environment variables. To create a ``pure''
5414 environment, in which the original environment variables have been unset,
5415 use the @code{--pure} option@footnote{Users sometimes wrongfully augment
5416 environment variables such as @code{PATH} in their @file{~/.bashrc}
5417 file. As a consequence, when @code{guix environment} launches it, Bash
5418 may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
5419 environment variables. It is an error to define such environment
5420 variables in @file{.bashrc}; instead, they should be defined in
5421 @file{.bash_profile}, which is sourced only by log-in shells.
5422 @xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
5423 details on Bash start-up files.}.
5424
5425 @vindex GUIX_ENVIRONMENT
5426 @command{guix environment} defines the @code{GUIX_ENVIRONMENT}
5427 variable in the shell it spawns. This allows users to, say, define a
5428 specific prompt for development environments in their @file{.bashrc}
5429 (@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
5430
5431 @example
5432 if [ -n "$GUIX_ENVIRONMENT" ]
5433 then
5434 export PS1="\u@@\h \w [dev]\$ "
5435 fi
5436 @end example
5437
5438 Additionally, more than one package may be specified, in which case the
5439 union of the inputs for the given packages are used. For example, the
5440 command below spawns a shell where all of the dependencies of both Guile
5441 and Emacs are available:
5442
5443 @example
5444 guix environment guile emacs
5445 @end example
5446
5447 Sometimes an interactive shell session is not desired. An arbitrary
5448 command may be invoked by placing the @code{--} token to separate the
5449 command from the rest of the arguments:
5450
5451 @example
5452 guix environment guile -- make -j4
5453 @end example
5454
5455 In other situations, it is more convenient to specify the list of
5456 packages needed in the environment. For example, the following command
5457 runs @command{python} from an environment containing Python@tie{}2.7 and
5458 NumPy:
5459
5460 @example
5461 guix environment --ad-hoc python2-numpy python-2.7 -- python
5462 @end example
5463
5464 Furthermore, one might want the dependencies of a package and also some
5465 additional packages that are not build-time or runtime dependencies, but
5466 are useful when developing nonetheless. Because of this, the
5467 @code{--ad-hoc} flag is positional. Packages appearing before
5468 @code{--ad-hoc} are interpreted as packages whose dependencies will be
5469 added to the environment. Packages appearing after are interpreted as
5470 packages that will be added to the environment directly. For example,
5471 the following command creates a Guix development environment that
5472 additionally includes Git and strace:
5473
5474 @example
5475 guix environment guix --ad-hoc git strace
5476 @end example
5477
5478 Sometimes it is desirable to isolate the environment as much as
5479 possible, for maximal purity and reproducibility. In particular, when
5480 using Guix on a host distro that is not GuixSD, it is desirable to
5481 prevent access to @file{/usr/bin} and other system-wide resources from
5482 the development environment. For example, the following command spawns
5483 a Guile REPL in a ``container'' where only the store and the current
5484 working directory are mounted:
5485
5486 @example
5487 guix environment --ad-hoc --container guile -- guile
5488 @end example
5489
5490 @quotation Note
5491 The @code{--container} option requires Linux-libre 3.19 or newer.
5492 @end quotation
5493
5494 The available options are summarized below.
5495
5496 @table @code
5497 @item --expression=@var{expr}
5498 @itemx -e @var{expr}
5499 Create an environment for the package or list of packages that
5500 @var{expr} evaluates to.
5501
5502 For example, running:
5503
5504 @example
5505 guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
5506 @end example
5507
5508 starts a shell with the environment for this specific variant of the
5509 PETSc package.
5510
5511 Running:
5512
5513 @example
5514 guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
5515 @end example
5516
5517 starts a shell with all the GuixSD base packages available.
5518
5519 The above commands only the use default output of the given packages.
5520 To select other outputs, two element tuples can be specified:
5521
5522 @example
5523 guix environment --ad-hoc -e '(list (@ (gnu packages bash) bash) "include")'
5524 @end example
5525
5526 @item --load=@var{file}
5527 @itemx -l @var{file}
5528 Create an environment for the package or list of packages that the code
5529 within @var{file} evaluates to.
5530
5531 As an example, @var{file} might contain a definition like this
5532 (@pxref{Defining Packages}):
5533
5534 @example
5535 @verbatiminclude environment-gdb.scm
5536 @end example
5537
5538 @item --ad-hoc
5539 Include all specified packages in the resulting environment, as if an
5540 @i{ad hoc} package were defined with them as inputs. This option is
5541 useful for quickly creating an environment without having to write a
5542 package expression to contain the desired inputs.
5543
5544 For instance, the command:
5545
5546 @example
5547 guix environment --ad-hoc guile guile-sdl -- guile
5548 @end example
5549
5550 runs @command{guile} in an environment where Guile and Guile-SDL are
5551 available.
5552
5553 Note that this example implicitly asks for the default output of
5554 @code{guile} and @code{guile-sdl}, but it is possible to ask for a
5555 specific output---e.g., @code{glib:bin} asks for the @code{bin} output
5556 of @code{glib} (@pxref{Packages with Multiple Outputs}).
5557
5558 This option may be composed with the default behavior of @command{guix
5559 environment}. Packages appearing before @code{--ad-hoc} are interpreted
5560 as packages whose dependencies will be added to the environment, the
5561 default behavior. Packages appearing after are interpreted as packages
5562 that will be added to the environment directly.
5563
5564 @item --pure
5565 Unset existing environment variables when building the new environment.
5566 This has the effect of creating an environment in which search paths
5567 only contain package inputs.
5568
5569 @item --search-paths
5570 Display the environment variable definitions that make up the
5571 environment.
5572
5573 @item --system=@var{system}
5574 @itemx -s @var{system}
5575 Attempt to build for @var{system}---e.g., @code{i686-linux}.
5576
5577 @item --container
5578 @itemx -C
5579 @cindex container
5580 Run @var{command} within an isolated container. The current working
5581 directory outside the container is mapped inside the container.
5582 Additionally, a dummy home directory is created that matches the current
5583 user's home directory, and @file{/etc/passwd} is configured accordingly.
5584 The spawned process runs as the current user outside the container, but
5585 has root privileges in the context of the container.
5586
5587 @item --network
5588 @itemx -N
5589 For containers, share the network namespace with the host system.
5590 Containers created without this flag only have access to the loopback
5591 device.
5592
5593 @item --expose=@var{source}[=@var{target}]
5594 For containers, expose the file system @var{source} from the host system
5595 as the read-only file system @var{target} within the container. If
5596 @var{target} is not specified, @var{source} is used as the target mount
5597 point in the container.
5598
5599 The example below spawns a Guile REPL in a container in which the user's
5600 home directory is accessible read-only via the @file{/exchange}
5601 directory:
5602
5603 @example
5604 guix environment --container --expose=$HOME=/exchange guile -- guile
5605 @end example
5606
5607 @item --share=@var{source}[=@var{target}]
5608 For containers, share the file system @var{source} from the host system
5609 as the writable file system @var{target} within the container. If
5610 @var{target} is not specified, @var{source} is used as the target mount
5611 point in the container.
5612
5613 The example below spawns a Guile REPL in a container in which the user's
5614 home directory is accessible for both reading and writing via the
5615 @file{/exchange} directory:
5616
5617 @example
5618 guix environment --container --share=$HOME=/exchange guile -- guile
5619 @end example
5620 @end table
5621
5622 It also supports all of the common build options that @command{guix
5623 build} supports (@pxref{Common Build Options}).
5624
5625 @node Invoking guix publish
5626 @section Invoking @command{guix publish}
5627
5628 The purpose of @command{guix publish} is to enable users to easily share
5629 their store with others, who can then use it as a substitute server
5630 (@pxref{Substitutes}).
5631
5632 When @command{guix publish} runs, it spawns an HTTP server which allows
5633 anyone with network access to obtain substitutes from it. This means
5634 that any machine running Guix can also act as if it were a build farm,
5635 since the HTTP interface is compatible with Hydra, the software behind
5636 the @code{hydra.gnu.org} build farm.
5637
5638 For security, each substitute is signed, allowing recipients to check
5639 their authenticity and integrity (@pxref{Substitutes}). Because
5640 @command{guix publish} uses the signing key of the system, which is only
5641 readable by the system administrator, it must be started as root; the
5642 @code{--user} option makes it drop root privileges early on.
5643
5644 The signing key pair must be generated before @command{guix publish} is
5645 launched, using @command{guix archive --generate-key} (@pxref{Invoking
5646 guix archive}).
5647
5648 The general syntax is:
5649
5650 @example
5651 guix publish @var{options}@dots{}
5652 @end example
5653
5654 Running @command{guix publish} without any additional arguments will
5655 spawn an HTTP server on port 8080:
5656
5657 @example
5658 guix publish
5659 @end example
5660
5661 Once a publishing server has been authorized (@pxref{Invoking guix
5662 archive}), the daemon may download substitutes from it:
5663
5664 @example
5665 guix-daemon --substitute-urls=http://example.org:8080
5666 @end example
5667
5668 As a bonus, @command{guix publish} also serves as a content-addressed
5669 mirror for source files referenced in @code{origin} records
5670 (@pxref{origin Reference}). For instance, assuming @command{guix
5671 publish} is running on @code{example.org}, the following URL returns the
5672 raw @file{hello-2.10.tar.gz} file with the given SHA256 hash
5673 (represented in @code{nix-base32} format, @pxref{Invoking guix hash}):
5674
5675 @example
5676 http://example.org/file/hello-2.10.tar.gz/sha256/0ssi1@dots{}ndq1i
5677 @end example
5678
5679 Obviously, these URLs only work for files that are in the store; in
5680 other cases, they return 404 (``Not Found'').
5681
5682 The following options are available:
5683
5684 @table @code
5685 @item --port=@var{port}
5686 @itemx -p @var{port}
5687 Listen for HTTP requests on @var{port}.
5688
5689 @item --listen=@var{host}
5690 Listen on the network interface for @var{host}. The default is to
5691 accept connections from any interface.
5692
5693 @item --user=@var{user}
5694 @itemx -u @var{user}
5695 Change privileges to @var{user} as soon as possible---i.e., once the
5696 server socket is open and the signing key has been read.
5697
5698 @item --compression[=@var{level}]
5699 @itemx -C [@var{level}]
5700 Compress data using the given @var{level}. When @var{level} is zero,
5701 disable compression. The range 1 to 9 corresponds to different gzip
5702 compression levels: 1 is the fastest, and 9 is the best (CPU-intensive).
5703 The default is 3.
5704
5705 Compression occurs on the fly and the compressed streams are not
5706 cached. Thus, to reduce load on the machine that runs @command{guix
5707 publish}, it may be a good idea to choose a low compression level, or to
5708 run @command{guix publish} behind a caching proxy.
5709
5710 @item --ttl=@var{ttl}
5711 Produce @code{Cache-Control} HTTP headers that advertise a time-to-live
5712 (TTL) of @var{ttl}. @var{ttl} must denote a duration: @code{5d} means 5
5713 days, @code{1m} means 1 month, and so on.
5714
5715 This allows the user's Guix to keep substitute information in cache for
5716 @var{ttl}. However, note that @code{guix publish} does not itself
5717 guarantee that the store items it provides will indeed remain available
5718 for as long as @var{ttl}.
5719
5720 @item --repl[=@var{port}]
5721 @itemx -r [@var{port}]
5722 Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
5723 Reference Manual}) on @var{port} (37146 by default). This is used
5724 primarily for debugging a running @command{guix publish} server.
5725 @end table
5726
5727 Enabling @command{guix publish} on a GuixSD system is a one-liner: just
5728 add a call to @code{guix-publish-service} in the @code{services} field
5729 of the @code{operating-system} declaration (@pxref{guix-publish-service,
5730 @code{guix-publish-service}}).
5731
5732
5733 @node Invoking guix challenge
5734 @section Invoking @command{guix challenge}
5735
5736 @cindex reproducible builds
5737 @cindex verifiable builds
5738
5739 Do the binaries provided by this server really correspond to the source
5740 code it claims to build? Is a package build process deterministic?
5741 These are the questions the @command{guix challenge} command attempts to
5742 answer.
5743
5744 The former is obviously an important question: Before using a substitute
5745 server (@pxref{Substitutes}), one had better @emph{verify} that it
5746 provides the right binaries, and thus @emph{challenge} it. The latter
5747 is what enables the former: If package builds are deterministic, then
5748 independent builds of the package should yield the exact same result,
5749 bit for bit; if a server provides a binary different from the one
5750 obtained locally, it may be either corrupt or malicious.
5751
5752 We know that the hash that shows up in @file{/gnu/store} file names is
5753 the hash of all the inputs of the process that built the file or
5754 directory---compilers, libraries, build scripts,
5755 etc. (@pxref{Introduction}). Assuming deterministic build processes,
5756 one store file name should map to exactly one build output.
5757 @command{guix challenge} checks whether there is, indeed, a single
5758 mapping by comparing the build outputs of several independent builds of
5759 any given store item.
5760
5761 The command output looks like this:
5762
5763 @smallexample
5764 $ guix challenge --substitute-urls="https://hydra.gnu.org https://guix.example.org"
5765 updating list of substitutes from 'https://hydra.gnu.org'... 100.0%
5766 updating list of substitutes from 'https://guix.example.org'... 100.0%
5767 /gnu/store/@dots{}-openssl-1.0.2d contents differ:
5768 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5769 https://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5770 https://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
5771 /gnu/store/@dots{}-git-2.5.0 contents differ:
5772 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
5773 https://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
5774 https://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
5775 /gnu/store/@dots{}-pius-2.1.1 contents differ:
5776 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5777 https://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5778 https://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
5779 @end smallexample
5780
5781 @noindent
5782 In this example, @command{guix challenge} first scans the store to
5783 determine the set of locally-built derivations---as opposed to store
5784 items that were downloaded from a substitute server---and then queries
5785 all the substitute servers. It then reports those store items for which
5786 the servers obtained a result different from the local build.
5787
5788 @cindex non-determinism, in package builds
5789 As an example, @code{guix.example.org} always gets a different answer.
5790 Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
5791 case of Git. This might indicate that the build process of Git is
5792 non-deterministic, meaning that its output varies as a function of
5793 various things that Guix does not fully control, in spite of building
5794 packages in isolated environments (@pxref{Features}). Most common
5795 sources of non-determinism include the addition of timestamps in build
5796 results, the inclusion of random numbers, and directory listings sorted
5797 by inode number. See @uref{https://reproducible-builds.org/docs/}, for
5798 more information.
5799
5800 To find out what is wrong with this Git binary, we can do something along
5801 these lines (@pxref{Invoking guix archive}):
5802
5803 @example
5804 $ wget -q -O - https://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
5805 | guix archive -x /tmp/git
5806 $ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
5807 @end example
5808
5809 This command shows the difference between the files resulting from the
5810 local build, and the files resulting from the build on
5811 @code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
5812 diffutils, Comparing and Merging Files}). The @command{diff} command
5813 works great for text files. When binary files differ, a better option
5814 is @uref{https://diffoscope.org/, Diffoscope}, a tool that helps
5815 visualize differences for all kinds of files.
5816
5817 Once you have done that work, you can tell whether the differences are due
5818 to a non-deterministic build process or to a malicious server. We try
5819 hard to remove sources of non-determinism in packages to make it easier
5820 to verify substitutes, but of course, this is a process that
5821 involves not just Guix, but a large part of the free software community.
5822 In the meantime, @command{guix challenge} is one tool to help address
5823 the problem.
5824
5825 If you are writing packages for Guix, you are encouraged to check
5826 whether @code{hydra.gnu.org} and other substitute servers obtain the
5827 same build result as you did with:
5828
5829 @example
5830 $ guix challenge @var{package}
5831 @end example
5832
5833 @noindent
5834 where @var{package} is a package specification such as
5835 @code{guile@@2.0} or @code{glibc:debug}.
5836
5837 The general syntax is:
5838
5839 @example
5840 guix challenge @var{options} [@var{packages}@dots{}]
5841 @end example
5842
5843 When a difference is found between the hash of a locally-built item and
5844 that of a server-provided substitute, or among substitutes provided by
5845 different servers, the command displays it as in the example above and
5846 its exit code is 2 (other non-zero exit codes denote other kinds of
5847 errors.)
5848
5849 The one option that matters is:
5850
5851 @table @code
5852
5853 @item --substitute-urls=@var{urls}
5854 Consider @var{urls} the whitespace-separated list of substitute source
5855 URLs to compare to.
5856
5857 @end table
5858
5859
5860 @node Invoking guix container
5861 @section Invoking @command{guix container}
5862 @cindex container
5863
5864 @quotation Note
5865 As of version @value{VERSION}, this tool is experimental. The interface
5866 is subject to radical change in the future.
5867 @end quotation
5868
5869 The purpose of @command{guix container} is to manipulate processes
5870 running within an isolated environment, commonly known as a
5871 ``container'', typically created by the @command{guix environment}
5872 (@pxref{Invoking guix environment}) and @command{guix system container}
5873 (@pxref{Invoking guix system}) commands.
5874
5875 The general syntax is:
5876
5877 @example
5878 guix container @var{action} @var{options}@dots{}
5879 @end example
5880
5881 @var{action} specifies the operation to perform with a container, and
5882 @var{options} specifies the context-specific arguments for the action.
5883
5884 The following actions are available:
5885
5886 @table @code
5887 @item exec
5888 Execute a command within the context of a running container.
5889
5890 The syntax is:
5891
5892 @example
5893 guix container exec @var{pid} @var{program} @var{arguments}@dots{}
5894 @end example
5895
5896 @var{pid} specifies the process ID of the running container.
5897 @var{program} specifies an executable file name within the root file
5898 system of the container. @var{arguments} are the additional options that
5899 will be passed to @var{program}.
5900
5901 The following command launches an interactive login shell inside a
5902 GuixSD container, started by @command{guix system container}, and whose
5903 process ID is 9001:
5904
5905 @example
5906 guix container exec 9001 /run/current-system/profile/bin/bash --login
5907 @end example
5908
5909 Note that the @var{pid} cannot be the parent process of a container. It
5910 must be PID 1 of the container or one of its child processes.
5911
5912 @end table
5913
5914 @c *********************************************************************
5915 @node GNU Distribution
5916 @chapter GNU Distribution
5917
5918 @cindex Guix System Distribution
5919 @cindex GuixSD
5920 Guix comes with a distribution of the GNU system consisting entirely of
5921 free software@footnote{The term ``free'' here refers to the
5922 @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
5923 users of that software}.}. The
5924 distribution can be installed on its own (@pxref{System Installation}),
5925 but it is also possible to install Guix as a package manager on top of
5926 an installed GNU/Linux system (@pxref{Installation}). To distinguish
5927 between the two, we refer to the standalone distribution as the Guix
5928 System Distribution, or GuixSD.
5929
5930 The distribution provides core GNU packages such as GNU libc, GCC, and
5931 Binutils, as well as many GNU and non-GNU applications. The complete
5932 list of available packages can be browsed
5933 @url{http://www.gnu.org/software/guix/packages,on-line} or by
5934 running @command{guix package} (@pxref{Invoking guix package}):
5935
5936 @example
5937 guix package --list-available
5938 @end example
5939
5940 Our goal is to provide a practical 100% free software distribution of
5941 Linux-based and other variants of GNU, with a focus on the promotion and
5942 tight integration of GNU components, and an emphasis on programs and
5943 tools that help users exert that freedom.
5944
5945 Packages are currently available on the following platforms:
5946
5947 @table @code
5948
5949 @item x86_64-linux
5950 Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
5951
5952 @item i686-linux
5953 Intel 32-bit architecture (IA32), Linux-Libre kernel;
5954
5955 @item armhf-linux
5956 ARMv7-A architecture with hard float, Thumb-2 and NEON,
5957 using the EABI hard-float application binary interface (ABI),
5958 and Linux-Libre kernel.
5959
5960 @item mips64el-linux
5961 little-endian 64-bit MIPS processors, specifically the Loongson series,
5962 n32 ABI, and Linux-Libre kernel.
5963
5964 @end table
5965
5966 GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
5967
5968 @noindent
5969 For information on porting to other architectures or kernels,
5970 @pxref{Porting}.
5971
5972 @menu
5973 * System Installation:: Installing the whole operating system.
5974 * System Configuration:: Configuring the operating system.
5975 * Installing Debugging Files:: Feeding the debugger.
5976 * Security Updates:: Deploying security fixes quickly.
5977 * Package Modules:: Packages from the programmer's viewpoint.
5978 * Packaging Guidelines:: Growing the distribution.
5979 * Bootstrapping:: GNU/Linux built from scratch.
5980 * Porting:: Targeting another platform or kernel.
5981 @end menu
5982
5983 Building this distribution is a cooperative effort, and you are invited
5984 to join! @xref{Contributing}, for information about how you can help.
5985
5986 @node System Installation
5987 @section System Installation
5988
5989 @cindex Guix System Distribution
5990 This section explains how to install the Guix System Distribution
5991 on a machine. The Guix package manager can
5992 also be installed on top of a running GNU/Linux system,
5993 @pxref{Installation}.
5994
5995 @ifinfo
5996 @quotation Note
5997 @c This paragraph is for people reading this from tty2 of the
5998 @c installation image.
5999 You are reading this documentation with an Info reader. For details on
6000 how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
6001 link that follows: @pxref{Top, Info reader,, info-stnd, Stand-alone GNU
6002 Info}. Hit @kbd{l} afterwards to come back here.
6003
6004 Alternately, run @command{info info} in another tty to keep the manual
6005 available.
6006 @end quotation
6007 @end ifinfo
6008
6009 @menu
6010 * Limitations:: What you can expect.
6011 * Hardware Considerations:: Supported hardware.
6012 * USB Stick Installation:: Preparing the installation medium.
6013 * Preparing for Installation:: Networking, partitioning, etc.
6014 * Proceeding with the Installation:: The real thing.
6015 * Building the Installation Image:: How this comes to be.
6016 @end menu
6017
6018 @node Limitations
6019 @subsection Limitations
6020
6021 As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
6022 not production-ready. It may contain bugs and lack important
6023 features. Thus, if you are looking for a stable production system that
6024 respects your freedom as a computer user, a good solution at this point
6025 is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
6026 the more established GNU/Linux distributions}. We hope you can soon switch
6027 to the GuixSD without fear, of course. In the meantime, you can
6028 also keep using your distribution and try out the package manager on top
6029 of it (@pxref{Installation}).
6030
6031 Before you proceed with the installation, be aware of the following
6032 noteworthy limitations applicable to version @value{VERSION}:
6033
6034 @itemize
6035 @item
6036 The installation process does not include a graphical user interface and
6037 requires familiarity with GNU/Linux (see the following subsections to
6038 get a feel of what that means.)
6039
6040 @item
6041 Support for the Logical Volume Manager (LVM) is missing.
6042
6043 @item
6044 Few system services are currently supported out-of-the-box
6045 (@pxref{Services}).
6046
6047 @item
6048 More than 3,200 packages are available, but you may
6049 occasionally find that a useful package is missing.
6050
6051 @item
6052 GNOME, Xfce, and Enlightenment are available (@pxref{Desktop Services}),
6053 as well as a number of X11 window managers. However, some graphical
6054 applications may be missing, as well as KDE.
6055 @end itemize
6056
6057 You have been warned! But more than a disclaimer, this is an invitation
6058 to report issues (and success stories!), and to join us in improving it.
6059 @xref{Contributing}, for more info.
6060
6061
6062 @node Hardware Considerations
6063 @subsection Hardware Considerations
6064
6065 @cindex hardware support on GuixSD
6066 GNU@tie{}GuixSD focuses on respecting the user's computing freedom. It
6067 builds around the kernel Linux-libre, which means that only hardware for
6068 which free software drivers and firmware exist is supported. Nowadays,
6069 a wide range of off-the-shelf hardware is supported on
6070 GNU/Linux-libre---from keyboards to graphics cards to scanners and
6071 Ethernet controllers. Unfortunately, there are still areas where
6072 hardware vendors deny users control over their own computing, and such
6073 hardware is not supported on GuixSD.
6074
6075 @cindex WiFi, hardware support
6076 One of the main areas where free drivers or firmware are lacking is WiFi
6077 devices. WiFi devices known to work include those using Atheros chips
6078 (AR9271 and AR7010), which corresponds to the @code{ath9k} Linux-libre
6079 driver, and for which free firmware exists and is available
6080 out-of-the-box on GuixSD, as part of @var{%base-firmware}
6081 (@pxref{operating-system Reference, @code{firmware}}).
6082
6083 @cindex RYF, Respects Your Freedom
6084 The @uref{https://www.fsf.org/, Free Software Foundation} runs
6085 @uref{https://www.fsf.org/ryf, @dfn{Respects Your Freedom}} (RYF), a
6086 certification program for hardware products that respect your freedom
6087 and your privacy and ensure that you have control over your device. We
6088 encourage you to check the list of RYF-certified devices.
6089
6090 Another useful resource is the @uref{https://www.h-node.org/, H-Node}
6091 web site. It contains a catalog of hardware devices with information
6092 about their support in GNU/Linux.
6093
6094
6095 @node USB Stick Installation
6096 @subsection USB Stick Installation
6097
6098 An installation image for USB sticks can be downloaded from
6099 @indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
6100 where @var{system} is one of:
6101
6102 @table @code
6103 @item x86_64-linux
6104 for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
6105
6106 @item i686-linux
6107 for a 32-bit GNU/Linux system on Intel-compatible CPUs.
6108 @end table
6109
6110 This image contains a single partition with the tools necessary for an
6111 installation. It is meant to be copied @emph{as is} to a large-enough
6112 USB stick.
6113
6114 To copy the image to a USB stick, follow these steps:
6115
6116 @enumerate
6117 @item
6118 Decompress the image using the @command{xz} command:
6119
6120 @example
6121 xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
6122 @end example
6123
6124 @item
6125 Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
6126 its device name. Assuming that the USB stick is known as @file{/dev/sdX},
6127 copy the image with:
6128
6129 @example
6130 dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
6131 @end example
6132
6133 Access to @file{/dev/sdX} usually requires root privileges.
6134 @end enumerate
6135
6136 Once this is done, you should be able to reboot the system and boot from
6137 the USB stick. The latter usually requires you to get in the BIOS' boot
6138 menu, where you can choose to boot from the USB stick.
6139
6140 @node Preparing for Installation
6141 @subsection Preparing for Installation
6142
6143 Once you have successfully booted the image on the USB stick, you should
6144 end up with a root prompt. Several console TTYs are configured and can
6145 be used to run commands as root. TTY2 shows this documentation,
6146 browsable using the Info reader commands (@pxref{Top,,, info-stnd,
6147 Stand-alone GNU Info}). The installation system runs the GPM mouse
6148 daemon, which allows you to select text with the left mouse button and
6149 to paste it with the middle button.
6150
6151 @quotation Note
6152 Installation requires access to the Internet so that any missing
6153 dependencies of your system configuration can be downloaded. See the
6154 ``Networking'' section below.
6155 @end quotation
6156
6157 The installation system includes many common tools needed for this task.
6158 But it is also a full-blown GuixSD system, which means that you can
6159 install additional packages, should you need it, using @command{guix
6160 package} (@pxref{Invoking guix package}).
6161
6162 @subsubsection Keyboard Layout
6163
6164 @cindex keyboard layout
6165 The installation image uses the US qwerty keyboard layout. If you want
6166 to change it, you can use the @command{loadkeys} command. For example,
6167 the following command selects the Dvorak keyboard layout:
6168
6169 @example
6170 loadkeys dvorak
6171 @end example
6172
6173 See the files under @file{/run/current-system/profile/share/keymaps} for
6174 a list of available keyboard layouts. Run @command{man loadkeys} for
6175 more information.
6176
6177 @subsubsection Networking
6178
6179 Run the following command see what your network interfaces are called:
6180
6181 @example
6182 ifconfig -a
6183 @end example
6184
6185 @noindent
6186 @dots{} or, using the GNU/Linux-specific @command{ip} command:
6187
6188 @example
6189 ip a
6190 @end example
6191
6192 @c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
6193 Wired interfaces have a name starting with @samp{e}; for example, the
6194 interface corresponding to the first on-board Ethernet controller is
6195 called @samp{eno1}. Wireless interfaces have a name starting with
6196 @samp{w}, like @samp{w1p2s0}.
6197
6198 @table @asis
6199 @item Wired connection
6200 To configure a wired network run the following command, substituting
6201 @var{interface} with the name of the wired interface you want to use.
6202
6203 @example
6204 ifconfig @var{interface} up
6205 @end example
6206
6207 @item Wireless connection
6208 To configure wireless networking, you can create a configuration file
6209 for the @command{wpa_supplicant} configuration tool (its location is not
6210 important) using one of the available text editors such as
6211 @command{zile}:
6212
6213 @example
6214 zile wpa_supplicant.conf
6215 @end example
6216
6217 As an example, the following stanza can go to this file and will work
6218 for many wireless networks, provided you give the actual SSID and
6219 passphrase for the network you are connecting to:
6220
6221 @example
6222 network=@{
6223 ssid="@var{my-ssid}"
6224 key_mgmt=WPA-PSK
6225 psk="the network's secret passphrase"
6226 @}
6227 @end example
6228
6229 Start the wireless service and run it in the background with the
6230 following command (substitute @var{interface} with the name of the
6231 network interface you want to use):
6232
6233 @example
6234 wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
6235 @end example
6236
6237 Run @command{man wpa_supplicant} for more information.
6238 @end table
6239
6240 At this point, you need to acquire an IP address. On a network where IP
6241 addresses are automatically assigned @i{via} DHCP, you can run:
6242
6243 @example
6244 dhclient -v @var{interface}
6245 @end example
6246
6247 Try to ping a server to see if networking is up and running:
6248
6249 @example
6250 ping -c 3 gnu.org
6251 @end example
6252
6253 Setting up network access is almost always a requirement because the
6254 image does not contain all the software and tools that may be needed.
6255
6256 @subsubsection Disk Partitioning
6257
6258 Unless this has already been done, the next step is to partition, and
6259 then format the target partition(s).
6260
6261 The installation image includes several partitioning tools, including
6262 Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
6263 @command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
6264 the partition layout you want:
6265
6266 @example
6267 cfdisk
6268 @end example
6269
6270 Once you are done partitioning the target hard disk drive, you have to
6271 create a file system on the relevant partition(s)@footnote{Currently
6272 GuixSD pretty much assumes an ext4 file system. In particular, code
6273 that reads partition UUIDs and labels only works with ext4. This will
6274 be fixed in the future.}.
6275
6276 Preferably, assign partitions a label so that you can easily and
6277 reliably refer to them in @code{file-system} declarations (@pxref{File
6278 Systems}). This is typically done using the @code{-L} option of
6279 @command{mkfs.ext4} and related commands. So, assuming the target root
6280 partition lives at @file{/dev/sda1}, a file system with the label
6281 @code{my-root} can be created with:
6282
6283 @example
6284 mkfs.ext4 -L my-root /dev/sda1
6285 @end example
6286
6287 @c FIXME: Uncomment this once GRUB fully supports encrypted roots.
6288 @c A typical command sequence may be:
6289 @c
6290 @c @example
6291 @c # fdisk /dev/sdX
6292 @c @dots{} Create partitions etc.@dots{}
6293 @c # cryptsetup luksFormat /dev/sdX1
6294 @c # cryptsetup open --type luks /dev/sdX1 my-partition
6295 @c # mkfs.ext4 -L my-root /dev/mapper/my-partition
6296 @c @end example
6297
6298 In addition to e2fsprogs, the suite of tools to manipulate
6299 ext2/ext3/ext4 file systems, the installation image includes
6300 Cryptsetup/LUKS for disk encryption.
6301
6302 Once that is done, mount the target root partition under @file{/mnt}
6303 with a command like (again, assuming @file{/dev/sda1} is the root
6304 partition):
6305
6306 @example
6307 mount /dev/sda1 /mnt
6308 @end example
6309
6310 Finally, if you plan to use one or more swap partitions (@pxref{Memory
6311 Concepts, swap space,, libc, The GNU C Library Reference Manual}), make
6312 sure to initialize them with @command{mkswap}. Assuming you have one
6313 swap partition on @file{/dev/sda2}, you would run:
6314
6315 @example
6316 mkswap /dev/sda2
6317 @end example
6318
6319 @node Proceeding with the Installation
6320 @subsection Proceeding with the Installation
6321
6322 With the target partitions ready and the target root mounted on
6323 @file{/mnt}, we're ready to go. First, run:
6324
6325 @example
6326 herd start cow-store /mnt
6327 @end example
6328
6329 This makes @file{/gnu/store} copy-on-write, such that packages added to it
6330 during the installation phase are written to the target disk on @file{/mnt}
6331 rather than kept in memory. This is necessary because the first phase of
6332 the @command{guix system init} command (see below) entails downloads or
6333 builds to @file{/gnu/store} which, initially, is an in-memory file system.
6334
6335 Next, you have to edit a file and
6336 provide the declaration of the operating system to be installed. To
6337 that end, the installation system comes with two text editors: GNU nano
6338 (@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
6339 We strongly recommend storing that file on the target root file system, say,
6340 as @file{/mnt/etc/config.scm}. Failing to do that, you will have lost your
6341 configuration file once you have rebooted into the newly-installed system.
6342
6343 @xref{Using the Configuration System}, for an overview of the
6344 configuration file. The example configurations discussed in that
6345 section are available under @file{/etc/configuration} in the
6346 installation image. Thus, to get started with a system configuration
6347 providing a graphical display server (a ``desktop'' system), you can run
6348 something along these lines:
6349
6350 @example
6351 # mkdir /mnt/etc
6352 # cp /etc/configuration/desktop.scm /mnt/etc/config.scm
6353 # zile /mnt/etc/config.scm
6354 @end example
6355
6356 You should pay attention to what your configuration file contains, and
6357 in particular:
6358
6359 @itemize
6360 @item
6361 Make sure the @code{grub-configuration} form refers to the device you
6362 want to install GRUB on.
6363
6364 @item
6365 Be sure that your partition labels match the value of their respective
6366 @code{device} fields in your @code{file-system} configuration, assuming
6367 your @code{file-system} configuration sets the value of @code{title} to
6368 @code{'label}.
6369 @end itemize
6370
6371 Once you are done preparing the configuration file, the new system must
6372 be initialized (remember that the target root file system is mounted
6373 under @file{/mnt}):
6374
6375 @example
6376 guix system init /mnt/etc/config.scm /mnt
6377 @end example
6378
6379 @noindent
6380 This copies all the necessary files and installs GRUB on
6381 @file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6382 more information, @pxref{Invoking guix system}. This command may trigger
6383 downloads or builds of missing packages, which can take some time.
6384
6385 Once that command has completed---and hopefully succeeded!---you can run
6386 @command{reboot} and boot into the new system. The @code{root} password
6387 in the new system is initially empty; other users' passwords need to be
6388 initialized by running the @command{passwd} command as @code{root},
6389 unless your configuration specifies otherwise
6390 (@pxref{user-account-password, user account passwords}).
6391
6392 Join us on @code{#guix} on the Freenode IRC network or on
6393 @file{guix-devel@@gnu.org} to share your experience---good or not so
6394 good.
6395
6396 @node Building the Installation Image
6397 @subsection Building the Installation Image
6398
6399 The installation image described above was built using the @command{guix
6400 system} command, specifically:
6401
6402 @c FIXME: 1G is too much; see <http://bugs.gnu.org/23077>.
6403 @example
6404 guix system disk-image --image-size=1G gnu/system/install.scm
6405 @end example
6406
6407 Have a look at @file{gnu/system/install.scm} in the source tree,
6408 and see also @ref{Invoking guix system} for more information
6409 about the installation image.
6410
6411 @node System Configuration
6412 @section System Configuration
6413
6414 @cindex system configuration
6415 The Guix System Distribution supports a consistent whole-system configuration
6416 mechanism. By that we mean that all aspects of the global system
6417 configuration---such as the available system services, timezone and
6418 locale settings, user accounts---are declared in a single place. Such
6419 a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
6420
6421 One of the advantages of putting all the system configuration under the
6422 control of Guix is that it supports transactional system upgrades, and
6423 makes it possible to roll back to a previous system instantiation,
6424 should something go wrong with the new one (@pxref{Features}). Another
6425 advantage is that it makes it easy to replicate the exact same configuration
6426 across different machines, or at different points in time, without
6427 having to resort to additional administration tools layered on top of
6428 the own tools of the system.
6429 @c Yes, we're talking of Puppet, Chef, & co. here. ↑
6430
6431 This section describes this mechanism. First we focus on the system
6432 administrator's viewpoint---explaining how the system is configured and
6433 instantiated. Then we show how this mechanism can be extended, for
6434 instance to support new system services.
6435
6436 @menu
6437 * Using the Configuration System:: Customizing your GNU system.
6438 * operating-system Reference:: Detail of operating-system declarations.
6439 * File Systems:: Configuring file system mounts.
6440 * Mapped Devices:: Block device extra processing.
6441 * User Accounts:: Specifying user accounts.
6442 * Locales:: Language and cultural convention settings.
6443 * Services:: Specifying system services.
6444 * Setuid Programs:: Programs running with root privileges.
6445 * X.509 Certificates:: Authenticating HTTPS servers.
6446 * Name Service Switch:: Configuring libc's name service switch.
6447 * Initial RAM Disk:: Linux-Libre bootstrapping.
6448 * GRUB Configuration:: Configuring the boot loader.
6449 * Invoking guix system:: Instantiating a system configuration.
6450 * Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
6451 * Defining Services:: Adding new service definitions.
6452 @end menu
6453
6454 @node Using the Configuration System
6455 @subsection Using the Configuration System
6456
6457 The operating system is configured by providing an
6458 @code{operating-system} declaration in a file that can then be passed to
6459 the @command{guix system} command (@pxref{Invoking guix system}). A
6460 simple setup, with the default system services, the default Linux-Libre
6461 kernel, initial RAM disk, and boot loader looks like this:
6462
6463 @findex operating-system
6464 @lisp
6465 @include os-config-bare-bones.texi
6466 @end lisp
6467
6468 This example should be self-describing. Some of the fields defined
6469 above, such as @code{host-name} and @code{bootloader}, are mandatory.
6470 Others, such as @code{packages} and @code{services}, can be omitted, in
6471 which case they get a default value.
6472
6473 Below we discuss the effect of some of the most important fields
6474 (@pxref{operating-system Reference}, for details about all the available
6475 fields), and how to @dfn{instantiate} the operating system using
6476 @command{guix system}.
6477
6478 @unnumberedsubsubsec Globally-Visible Packages
6479
6480 @vindex %base-packages
6481 The @code{packages} field lists packages that will be globally visible
6482 on the system, for all user accounts---i.e., in every user's @code{PATH}
6483 environment variable---in addition to the per-user profiles
6484 (@pxref{Invoking guix package}). The @var{%base-packages} variable
6485 provides all the tools one would expect for basic user and administrator
6486 tasks---including the GNU Core Utilities, the GNU Networking Utilities,
6487 the GNU Zile lightweight text editor, @command{find}, @command{grep},
6488 etc. The example above adds tcpdump to those, taken from the @code{(gnu
6489 packages admin)} module (@pxref{Package Modules}).
6490
6491 @findex specification->package
6492 Referring to packages by variable name, like @var{tcpdump} above, has
6493 the advantage of being unambiguous; it also allows typos and such to be
6494 diagnosed right away as ``unbound variables''. The downside is that one
6495 needs to know which module defines which package, and to augment the
6496 @code{use-package-modules} line accordingly. To avoid that, one can use
6497 the @code{specification->package} procedure of the @code{(gnu packages)}
6498 module, which returns the best package for a given name or name and
6499 version:
6500
6501 @lisp
6502 (use-modules (gnu packages))
6503
6504 (operating-system
6505 ;; ...
6506 (packages (append (map specification->package
6507 '("tcpdump" "htop" "gnupg@@2.0"))
6508 %base-packages)))
6509 @end lisp
6510
6511 @unnumberedsubsubsec System Services
6512
6513 @vindex %base-services
6514 The @code{services} field lists @dfn{system services} to be made
6515 available when the system starts (@pxref{Services}).
6516 The @code{operating-system} declaration above specifies that, in
6517 addition to the basic services, we want the @command{lshd} secure shell
6518 daemon listening on port 2222 (@pxref{Networking Services,
6519 @code{lsh-service}}). Under the hood,
6520 @code{lsh-service} arranges so that @code{lshd} is started with the
6521 right command-line options, possibly with supporting configuration files
6522 generated as needed (@pxref{Defining Services}).
6523
6524 @cindex customization, of services
6525 @findex modify-services
6526 Occasionally, instead of using the base services as is, you will want to
6527 customize them. To do this, use @code{modify-services} (@pxref{Service
6528 Reference, @code{modify-services}}) to modify the list.
6529
6530 For example, suppose you want to modify @code{guix-daemon} and Mingetty
6531 (the console log-in) in the @var{%base-services} list (@pxref{Base
6532 Services, @code{%base-services}}). To do that, you can write the
6533 following in your operating system declaration:
6534
6535 @lisp
6536 (define %my-services
6537 ;; My very own list of services.
6538 (modify-services %base-services
6539 (guix-service-type config =>
6540 (guix-configuration
6541 (inherit config)
6542 (use-substitutes? #f)
6543 (extra-options '("--gc-keep-derivations"))))
6544 (mingetty-service-type config =>
6545 (mingetty-configuration
6546 (inherit config)
6547 (motd (plain-file "motd" "Howdy!"))))))
6548
6549 (operating-system
6550 ;; @dots{}
6551 (services %my-services))
6552 @end lisp
6553
6554 This changes the configuration---i.e., the service parameters---of the
6555 @code{guix-service-type} instance, and that of all the
6556 @code{mingetty-service-type} instances in the @var{%base-services} list.
6557 Observe how this is accomplished: first, we arrange for the original
6558 configuration to be bound to the identifier @code{config} in the
6559 @var{body}, and then we write the @var{body} so that it evaluates to the
6560 desired configuration. In particular, notice how we use @code{inherit}
6561 to create a new configuration which has the same values as the old
6562 configuration, but with a few modifications.
6563
6564 The configuration for a typical ``desktop'' usage, with the X11 display
6565 server, GNOME and Xfce (users can choose which of these desktop
6566 environments to use at the log-in screen by pressing @kbd{F1}), network
6567 management, power management, and more, would look like this:
6568
6569 @lisp
6570 @include os-config-desktop.texi
6571 @end lisp
6572
6573 A graphical environment with a choice of lightweight window managers
6574 instead of full-blown desktop environments would look like this:
6575
6576 @lisp
6577 @include os-config-lightweight-desktop.texi
6578 @end lisp
6579
6580 @xref{Desktop Services}, for the exact list of services provided by
6581 @var{%desktop-services}. @xref{X.509 Certificates}, for background
6582 information about the @code{nss-certs} package that is used here.
6583
6584 Again, @var{%desktop-services} is just a list of service objects. If
6585 you want to remove services from there, you can do so using the
6586 procedures for list filtering (@pxref{SRFI-1 Filtering and
6587 Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
6588 following expression returns a list that contains all the services in
6589 @var{%desktop-services} minus the Avahi service:
6590
6591 @example
6592 (remove (lambda (service)
6593 (eq? (service-kind service) avahi-service-type))
6594 %desktop-services)
6595 @end example
6596
6597 @unnumberedsubsubsec Instantiating the System
6598
6599 Assuming the @code{operating-system} declaration
6600 is stored in the @file{my-system-config.scm}
6601 file, the @command{guix system reconfigure my-system-config.scm} command
6602 instantiates that configuration, and makes it the default GRUB boot
6603 entry (@pxref{Invoking guix system}).
6604
6605 The normal way to change the system configuration is by updating this
6606 file and re-running @command{guix system reconfigure}. One should never
6607 have to touch files in @command{/etc} or to run commands that modify the
6608 system state such as @command{useradd} or @command{grub-install}. In
6609 fact, you must avoid that since that would not only void your warranty
6610 but also prevent you from rolling back to previous versions of your
6611 system, should you ever need to.
6612
6613 @cindex roll-back, of the operating system
6614 Speaking of roll-back, each time you run @command{guix system
6615 reconfigure}, a new @dfn{generation} of the system is created---without
6616 modifying or deleting previous generations. Old system generations get
6617 an entry in the GRUB boot menu, allowing you to boot them in case
6618 something went wrong with the latest generation. Reassuring, no? The
6619 @command{guix system list-generations} command lists the system
6620 generations available on disk.
6621
6622 @unnumberedsubsubsec The Programming Interface
6623
6624 At the Scheme level, the bulk of an @code{operating-system} declaration
6625 is instantiated with the following monadic procedure (@pxref{The Store
6626 Monad}):
6627
6628 @deffn {Monadic Procedure} operating-system-derivation os
6629 Return a derivation that builds @var{os}, an @code{operating-system}
6630 object (@pxref{Derivations}).
6631
6632 The output of the derivation is a single directory that refers to all
6633 the packages, configuration files, and other supporting files needed to
6634 instantiate @var{os}.
6635 @end deffn
6636
6637 This procedure is provided by the @code{(gnu system)} module. Along
6638 with @code{(gnu services)} (@pxref{Services}), this module contains the
6639 guts of GuixSD. Make sure to visit it!
6640
6641
6642 @node operating-system Reference
6643 @subsection @code{operating-system} Reference
6644
6645 This section summarizes all the options available in
6646 @code{operating-system} declarations (@pxref{Using the Configuration
6647 System}).
6648
6649 @deftp {Data Type} operating-system
6650 This is the data type representing an operating system configuration.
6651 By that, we mean all the global system configuration, not per-user
6652 configuration (@pxref{Using the Configuration System}).
6653
6654 @table @asis
6655 @item @code{kernel} (default: @var{linux-libre})
6656 The package object of the operating system kernel to use@footnote{Currently
6657 only the Linux-libre kernel is supported. In the future, it will be
6658 possible to use the GNU@tie{}Hurd.}.
6659
6660 @item @code{kernel-arguments} (default: @code{'()})
6661 List of strings or gexps representing additional arguments to pass on
6662 the command-line of the kernel---e.g., @code{("console=ttyS0")}.
6663
6664 @item @code{bootloader}
6665 The system bootloader configuration object. @xref{GRUB Configuration}.
6666
6667 @item @code{initrd} (default: @code{base-initrd})
6668 A two-argument monadic procedure that returns an initial RAM disk for
6669 the Linux kernel. @xref{Initial RAM Disk}.
6670
6671 @item @code{firmware} (default: @var{%base-firmware})
6672 @cindex firmware
6673 List of firmware packages loadable by the operating system kernel.
6674
6675 The default includes firmware needed for Atheros-based WiFi devices
6676 (Linux-libre module @code{ath9k}). @xref{Hardware Considerations}, for
6677 more info on supported hardware.
6678
6679 @item @code{host-name}
6680 The host name.
6681
6682 @item @code{hosts-file}
6683 @cindex hosts file
6684 A file-like object (@pxref{G-Expressions, file-like objects}) for use as
6685 @file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
6686 Reference Manual}). The default is a file with entries for
6687 @code{localhost} and @var{host-name}.
6688
6689 @item @code{mapped-devices} (default: @code{'()})
6690 A list of mapped devices. @xref{Mapped Devices}.
6691
6692 @item @code{file-systems}
6693 A list of file systems. @xref{File Systems}.
6694
6695 @item @code{swap-devices} (default: @code{'()})
6696 @cindex swap devices
6697 A list of strings identifying devices to be used for ``swap space''
6698 (@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
6699 For example, @code{'("/dev/sda3")}.
6700
6701 @item @code{users} (default: @code{%base-user-accounts})
6702 @itemx @code{groups} (default: @var{%base-groups})
6703 List of user accounts and groups. @xref{User Accounts}.
6704
6705 @item @code{skeletons} (default: @code{(default-skeletons)})
6706 A list target file name/file-like object tuples (@pxref{G-Expressions,
6707 file-like objects}). These are the skeleton files that will be added to
6708 the home directory of newly-created user accounts.
6709
6710 For instance, a valid value may look like this:
6711
6712 @example
6713 `((".bashrc" ,(plain-file "bashrc" "echo Hello\n"))
6714 (".guile" ,(plain-file "guile"
6715 "(use-modules (ice-9 readline))
6716 (activate-readline)")))
6717 @end example
6718
6719 @item @code{issue} (default: @var{%default-issue})
6720 A string denoting the contents of the @file{/etc/issue} file, which is
6721 displayed when users log in on a text console.
6722
6723 @item @code{packages} (default: @var{%base-packages})
6724 The set of packages installed in the global profile, which is accessible
6725 at @file{/run/current-system/profile}.
6726
6727 The default set includes core utilities and it is good practice to
6728 install non-core utilities in user profiles (@pxref{Invoking guix
6729 package}).
6730
6731 @item @code{timezone}
6732 A timezone identifying string---e.g., @code{"Europe/Paris"}.
6733
6734 You can run the @command{tzselect} command to find out which timezone
6735 string corresponds to your region. Choosing an invalid timezone name
6736 causes @command{guix system} to fail.
6737
6738 @item @code{locale} (default: @code{"en_US.utf8"})
6739 The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
6740 Library Reference Manual}). @xref{Locales}, for more information.
6741
6742 @item @code{locale-definitions} (default: @var{%default-locale-definitions})
6743 The list of locale definitions to be compiled and that may be used at
6744 run time. @xref{Locales}.
6745
6746 @item @code{locale-libcs} (default: @code{(list @var{glibc})})
6747 The list of GNU@tie{}libc packages whose locale data and tools are used
6748 to build the locale definitions. @xref{Locales}, for compatibility
6749 considerations that justify this option.
6750
6751 @item @code{name-service-switch} (default: @var{%default-nss})
6752 Configuration of the libc name service switch (NSS)---a
6753 @code{<name-service-switch>} object. @xref{Name Service Switch}, for
6754 details.
6755
6756 @item @code{services} (default: @var{%base-services})
6757 A list of service objects denoting system services. @xref{Services}.
6758
6759 @item @code{pam-services} (default: @code{(base-pam-services)})
6760 @cindex PAM
6761 @cindex pluggable authentication modules
6762 Linux @dfn{pluggable authentication module} (PAM) services.
6763 @c FIXME: Add xref to PAM services section.
6764
6765 @item @code{setuid-programs} (default: @var{%setuid-programs})
6766 List of string-valued G-expressions denoting setuid programs.
6767 @xref{Setuid Programs}.
6768
6769 @item @code{sudoers-file} (default: @var{%sudoers-specification})
6770 @cindex sudoers file
6771 The contents of the @file{/etc/sudoers} file as a file-like object
6772 (@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
6773
6774 This file specifies which users can use the @command{sudo} command, what
6775 they are allowed to do, and what privileges they may gain. The default
6776 is that only @code{root} and members of the @code{wheel} group may use
6777 @code{sudo}.
6778
6779 @end table
6780 @end deftp
6781
6782 @node File Systems
6783 @subsection File Systems
6784
6785 The list of file systems to be mounted is specified in the
6786 @code{file-systems} field of the operating system declaration
6787 (@pxref{Using the Configuration System}). Each file system is declared
6788 using the @code{file-system} form, like this:
6789
6790 @example
6791 (file-system
6792 (mount-point "/home")
6793 (device "/dev/sda3")
6794 (type "ext4"))
6795 @end example
6796
6797 As usual, some of the fields are mandatory---those shown in the example
6798 above---while others can be omitted. These are described below.
6799
6800 @deftp {Data Type} file-system
6801 Objects of this type represent file systems to be mounted. They
6802 contain the following members:
6803
6804 @table @asis
6805 @item @code{type}
6806 This is a string specifying the type of the file system---e.g.,
6807 @code{"ext4"}.
6808
6809 @item @code{mount-point}
6810 This designates the place where the file system is to be mounted.
6811
6812 @item @code{device}
6813 This names the ``source'' of the file system. By default it is the name
6814 of a node under @file{/dev}, but its meaning depends on the @code{title}
6815 field described below.
6816
6817 @item @code{title} (default: @code{'device})
6818 This is a symbol that specifies how the @code{device} field is to be
6819 interpreted.
6820
6821 When it is the symbol @code{device}, then the @code{device} field is
6822 interpreted as a file name; when it is @code{label}, then @code{device}
6823 is interpreted as a partition label name; when it is @code{uuid},
6824 @code{device} is interpreted as a partition unique identifier (UUID).
6825
6826 UUIDs may be converted from their string representation (as shown by the
6827 @command{tune2fs -l} command) using the @code{uuid} form@footnote{The
6828 @code{uuid} form expects 16-byte UUIDs as defined in
6829 @uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
6830 form of UUID used by the ext2 family of file systems and others, but it
6831 is different from ``UUIDs'' found in FAT file systems, for instance.},
6832 like this:
6833
6834 @example
6835 (file-system
6836 (mount-point "/home")
6837 (type "ext4")
6838 (title 'uuid)
6839 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
6840 @end example
6841
6842 The @code{label} and @code{uuid} options offer a way to refer to disk
6843 partitions without having to hard-code their actual device
6844 name@footnote{Note that, while it is tempting to use
6845 @file{/dev/disk/by-uuid} and similar device names to achieve the same
6846 result, this is not recommended: These special device nodes are created
6847 by the udev daemon and may be unavailable at the time the device is
6848 mounted.}.
6849
6850 However, when the source of a file system is a mapped device (@pxref{Mapped
6851 Devices}), its @code{device} field @emph{must} refer to the mapped
6852 device name---e.g., @file{/dev/mapper/root-partition}---and consequently
6853 @code{title} must be set to @code{'device}. This is required so that
6854 the system knows that mounting the file system depends on having the
6855 corresponding device mapping established.
6856
6857 @item @code{flags} (default: @code{'()})
6858 This is a list of symbols denoting mount flags. Recognized flags
6859 include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
6860 access to special files), @code{no-suid} (ignore setuid and setgid
6861 bits), and @code{no-exec} (disallow program execution.)
6862
6863 @item @code{options} (default: @code{#f})
6864 This is either @code{#f}, or a string denoting mount options.
6865
6866 @item @code{mount?} (default: @code{#t})
6867 This value indicates whether to automatically mount the file system when
6868 the system is brought up. When set to @code{#f}, the file system gets
6869 an entry in @file{/etc/fstab} (read by the @command{mount} command) but
6870 is not automatically mounted.
6871
6872 @item @code{needed-for-boot?} (default: @code{#f})
6873 This Boolean value indicates whether the file system is needed when
6874 booting. If that is true, then the file system is mounted when the
6875 initial RAM disk (initrd) is loaded. This is always the case, for
6876 instance, for the root file system.
6877
6878 @item @code{check?} (default: @code{#t})
6879 This Boolean indicates whether the file system needs to be checked for
6880 errors before being mounted.
6881
6882 @item @code{create-mount-point?} (default: @code{#f})
6883 When true, the mount point is created if it does not exist yet.
6884
6885 @item @code{dependencies} (default: @code{'()})
6886 This is a list of @code{<file-system>} objects representing file systems
6887 that must be mounted before (and unmounted after) this one.
6888
6889 As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
6890 a dependency of @file{/sys/fs/cgroup/cpu} and
6891 @file{/sys/fs/cgroup/memory}.
6892
6893 @end table
6894 @end deftp
6895
6896 The @code{(gnu system file-systems)} exports the following useful
6897 variables.
6898
6899 @defvr {Scheme Variable} %base-file-systems
6900 These are essential file systems that are required on normal systems,
6901 such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
6902 below.) Operating system declarations should always contain at least
6903 these.
6904 @end defvr
6905
6906 @defvr {Scheme Variable} %pseudo-terminal-file-system
6907 This is the file system to be mounted as @file{/dev/pts}. It supports
6908 @dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
6909 functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
6910 Manual}). Pseudo-terminals are used by terminal emulators such as
6911 @command{xterm}.
6912 @end defvr
6913
6914 @defvr {Scheme Variable} %shared-memory-file-system
6915 This file system is mounted as @file{/dev/shm} and is used to support
6916 memory sharing across processes (@pxref{Memory-mapped I/O,
6917 @code{shm_open},, libc, The GNU C Library Reference Manual}).
6918 @end defvr
6919
6920 @defvr {Scheme Variable} %immutable-store
6921 This file system performs a read-only ``bind mount'' of
6922 @file{/gnu/store}, making it read-only for all the users including
6923 @code{root}. This prevents against accidental modification by software
6924 running as @code{root} or by system administrators.
6925
6926 The daemon itself is still able to write to the store: it remounts it
6927 read-write in its own ``name space.''
6928 @end defvr
6929
6930 @defvr {Scheme Variable} %binary-format-file-system
6931 The @code{binfmt_misc} file system, which allows handling of arbitrary
6932 executable file types to be delegated to user space. This requires the
6933 @code{binfmt.ko} kernel module to be loaded.
6934 @end defvr
6935
6936 @defvr {Scheme Variable} %fuse-control-file-system
6937 The @code{fusectl} file system, which allows unprivileged users to mount
6938 and unmount user-space FUSE file systems. This requires the
6939 @code{fuse.ko} kernel module to be loaded.
6940 @end defvr
6941
6942 @node Mapped Devices
6943 @subsection Mapped Devices
6944
6945 @cindex device mapping
6946 @cindex mapped devices
6947 The Linux kernel has a notion of @dfn{device mapping}: a block device,
6948 such as a hard disk partition, can be @dfn{mapped} into another device,
6949 with additional processing over the data that flows through
6950 it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
6951 concept of a ``mapped device'' and that of a file system: both boil down
6952 to @emph{translating} input/output operations made on a file to
6953 operations on its backing store. Thus, the Hurd implements mapped
6954 devices, like file systems, using the generic @dfn{translator} mechanism
6955 (@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
6956 typical example is encryption device mapping: all writes to the mapped
6957 device are encrypted, and all reads are deciphered, transparently.
6958
6959 Mapped devices are declared using the @code{mapped-device} form:
6960
6961 @example
6962 (mapped-device
6963 (source "/dev/sda3")
6964 (target "home")
6965 (type luks-device-mapping))
6966 @end example
6967
6968 Or, better yet, like this:
6969
6970 @example
6971 (mapped-device
6972 (source (uuid "cb67fc72-0d54-4c88-9d4b-b225f30b0f44"))
6973 (target "home")
6974 (type luks-device-mapping))
6975 @end example
6976
6977 @cindex disk encryption
6978 @cindex LUKS
6979 This example specifies a mapping from @file{/dev/sda3} to
6980 @file{/dev/mapper/home} using LUKS---the
6981 @url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
6982 standard mechanism for disk encryption. In the second example, the UUID
6983 (unique identifier) is the LUKS UUID returned for the device by a
6984 command like:
6985
6986 @example
6987 cryptsetup luksUUID /dev/sdx9
6988 @end example
6989
6990 The @file{/dev/mapper/home}
6991 device can then be used as the @code{device} of a @code{file-system}
6992 declaration (@pxref{File Systems}). The @code{mapped-device} form is
6993 detailed below.
6994
6995 @deftp {Data Type} mapped-device
6996 Objects of this type represent device mappings that will be made when
6997 the system boots up.
6998
6999 @table @code
7000 @item source
7001 This string specifies the name of the block device to be mapped, such as
7002 @code{"/dev/sda3"}.
7003
7004 @item target
7005 This string specifies the name of the mapping to be established. For
7006 example, specifying @code{"my-partition"} will lead to the creation of
7007 the @code{"/dev/mapper/my-partition"} device.
7008
7009 @item type
7010 This must be a @code{mapped-device-kind} object, which specifies how
7011 @var{source} is mapped to @var{target}.
7012 @end table
7013 @end deftp
7014
7015 @defvr {Scheme Variable} luks-device-mapping
7016 This defines LUKS block device encryption using the @command{cryptsetup}
7017 command from the package with the same name. It relies on the
7018 @code{dm-crypt} Linux kernel module.
7019 @end defvr
7020
7021 @node User Accounts
7022 @subsection User Accounts
7023
7024 User accounts and groups are entirely managed through the
7025 @code{operating-system} declaration. They are specified with the
7026 @code{user-account} and @code{user-group} forms:
7027
7028 @example
7029 (user-account
7030 (name "alice")
7031 (group "users")
7032 (supplementary-groups '("wheel" ;allow use of sudo, etc.
7033 "audio" ;sound card
7034 "video" ;video devices such as webcams
7035 "cdrom")) ;the good ol' CD-ROM
7036 (comment "Bob's sister")
7037 (home-directory "/home/alice"))
7038 @end example
7039
7040 When booting or upon completion of @command{guix system reconfigure},
7041 the system ensures that only the user accounts and groups specified in
7042 the @code{operating-system} declaration exist, and with the specified
7043 properties. Thus, account or group creations or modifications made by
7044 directly invoking commands such as @command{useradd} are lost upon
7045 reconfiguration or reboot. This ensures that the system remains exactly
7046 as declared.
7047
7048 @deftp {Data Type} user-account
7049 Objects of this type represent user accounts. The following members may
7050 be specified:
7051
7052 @table @asis
7053 @item @code{name}
7054 The name of the user account.
7055
7056 @item @code{group}
7057 This is the name (a string) or identifier (a number) of the user group
7058 this account belongs to.
7059
7060 @item @code{supplementary-groups} (default: @code{'()})
7061 Optionally, this can be defined as a list of group names that this
7062 account belongs to.
7063
7064 @item @code{uid} (default: @code{#f})
7065 This is the user ID for this account (a number), or @code{#f}. In the
7066 latter case, a number is automatically chosen by the system when the
7067 account is created.
7068
7069 @item @code{comment} (default: @code{""})
7070 A comment about the account, such as the account owner's full name.
7071
7072 @item @code{home-directory}
7073 This is the name of the home directory for the account.
7074
7075 @item @code{shell} (default: Bash)
7076 This is a G-expression denoting the file name of a program to be used as
7077 the shell (@pxref{G-Expressions}).
7078
7079 @item @code{system?} (default: @code{#f})
7080 This Boolean value indicates whether the account is a ``system''
7081 account. System accounts are sometimes treated specially; for instance,
7082 graphical login managers do not list them.
7083
7084 @anchor{user-account-password}
7085 @item @code{password} (default: @code{#f})
7086 You would normally leave this field to @code{#f}, initialize user
7087 passwords as @code{root} with the @command{passwd} command, and then let
7088 users change it with @command{passwd}. Passwords set with
7089 @command{passwd} are of course preserved across reboot and
7090 reconfiguration.
7091
7092 If you @emph{do} want to have a preset password for an account, then
7093 this field must contain the encrypted password, as a string.
7094 @xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
7095 on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
7096 Manual}, for information on Guile's @code{crypt} procedure.
7097
7098 @end table
7099 @end deftp
7100
7101 User group declarations are even simpler:
7102
7103 @example
7104 (user-group (name "students"))
7105 @end example
7106
7107 @deftp {Data Type} user-group
7108 This type is for, well, user groups. There are just a few fields:
7109
7110 @table @asis
7111 @item @code{name}
7112 The name of the group.
7113
7114 @item @code{id} (default: @code{#f})
7115 The group identifier (a number). If @code{#f}, a new number is
7116 automatically allocated when the group is created.
7117
7118 @item @code{system?} (default: @code{#f})
7119 This Boolean value indicates whether the group is a ``system'' group.
7120 System groups have low numerical IDs.
7121
7122 @item @code{password} (default: @code{#f})
7123 What, user groups can have a password? Well, apparently yes. Unless
7124 @code{#f}, this field specifies the password of the group.
7125
7126 @end table
7127 @end deftp
7128
7129 For convenience, a variable lists all the basic user groups one may
7130 expect:
7131
7132 @defvr {Scheme Variable} %base-groups
7133 This is the list of basic user groups that users and/or packages expect
7134 to be present on the system. This includes groups such as ``root'',
7135 ``wheel'', and ``users'', as well as groups used to control access to
7136 specific devices such as ``audio'', ``disk'', and ``cdrom''.
7137 @end defvr
7138
7139 @defvr {Scheme Variable} %base-user-accounts
7140 This is the list of basic system accounts that programs may expect to
7141 find on a GNU/Linux system, such as the ``nobody'' account.
7142
7143 Note that the ``root'' account is not included here. It is a
7144 special-case and is automatically added whether or not it is specified.
7145 @end defvr
7146
7147 @node Locales
7148 @subsection Locales
7149
7150 @cindex locale
7151 A @dfn{locale} defines cultural conventions for a particular language
7152 and region of the world (@pxref{Locales,,, libc, The GNU C Library
7153 Reference Manual}). Each locale has a name that typically has the form
7154 @code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
7155 @code{fr_LU.utf8} designates the locale for the French language, with
7156 cultural conventions from Luxembourg, and using the UTF-8 encoding.
7157
7158 @cindex locale definition
7159 Usually, you will want to specify the default locale for the machine
7160 using the @code{locale} field of the @code{operating-system} declaration
7161 (@pxref{operating-system Reference, @code{locale}}).
7162
7163 The selected locale is automatically added to the @dfn{locale
7164 definitions} known to the system if needed, with its codeset inferred
7165 from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
7166 @code{UTF-8} codeset. Additional locale definitions can be specified in
7167 the @code{locale-definitions} slot of @code{operating-system}---this is
7168 useful, for instance, if the codeset could not be inferred from the
7169 locale name. The default set of locale definitions includes some widely
7170 used locales, but not all the available locales, in order to save space.
7171
7172 For instance, to add the North Frisian locale for Germany, the value of
7173 that field may be:
7174
7175 @example
7176 (cons (locale-definition
7177 (name "fy_DE.utf8") (source "fy_DE"))
7178 %default-locale-definitions)
7179 @end example
7180
7181 Likewise, to save space, one might want @code{locale-definitions} to
7182 list only the locales that are actually used, as in:
7183
7184 @example
7185 (list (locale-definition
7186 (name "ja_JP.eucjp") (source "ja_JP")
7187 (charset "EUC-JP")))
7188 @end example
7189
7190 @vindex LOCPATH
7191 The compiled locale definitions are available at
7192 @file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
7193 version, which is the default location where the GNU@tie{}libc provided
7194 by Guix looks for locale data. This can be overridden using the
7195 @code{LOCPATH} environment variable (@pxref{locales-and-locpath,
7196 @code{LOCPATH} and locale packages}).
7197
7198 The @code{locale-definition} form is provided by the @code{(gnu system
7199 locale)} module. Details are given below.
7200
7201 @deftp {Data Type} locale-definition
7202 This is the data type of a locale definition.
7203
7204 @table @asis
7205
7206 @item @code{name}
7207 The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
7208 Reference Manual}, for more information on locale names.
7209
7210 @item @code{source}
7211 The name of the source for that locale. This is typically the
7212 @code{@var{language}_@var{territory}} part of the locale name.
7213
7214 @item @code{charset} (default: @code{"UTF-8"})
7215 The ``character set'' or ``code set'' for that locale,
7216 @uref{http://www.iana.org/assignments/character-sets, as defined by
7217 IANA}.
7218
7219 @end table
7220 @end deftp
7221
7222 @defvr {Scheme Variable} %default-locale-definitions
7223 A list of commonly used UTF-8 locales, used as the default
7224 value of the @code{locale-definitions} field of @code{operating-system}
7225 declarations.
7226
7227 @cindex locale name
7228 @cindex normalized codeset in locale names
7229 These locale definitions use the @dfn{normalized codeset} for the part
7230 that follows the dot in the name (@pxref{Using gettextized software,
7231 normalized codeset,, libc, The GNU C Library Reference Manual}). So for
7232 instance it has @code{uk_UA.utf8} but @emph{not}, say,
7233 @code{uk_UA.UTF-8}.
7234 @end defvr
7235
7236 @subsubsection Locale Data Compatibility Considerations
7237
7238 @cindex incompatibility, of locale data
7239 @code{operating-system} declarations provide a @code{locale-libcs} field
7240 to specify the GNU@tie{}libc packages that are used to compile locale
7241 declarations (@pxref{operating-system Reference}). ``Why would I
7242 care?'', you may ask. Well, it turns out that the binary format of
7243 locale data is occasionally incompatible from one libc version to
7244 another.
7245
7246 @c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
7247 @c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
7248 For instance, a program linked against libc version 2.21 is unable to
7249 read locale data produced with libc 2.22; worse, that program
7250 @emph{aborts} instead of simply ignoring the incompatible locale
7251 data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
7252 the incompatible locale data, which is already an improvement.}.
7253 Similarly, a program linked against libc 2.22 can read most, but not
7254 all, the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
7255 data is incompatible); thus calls to @code{setlocale} may fail, but
7256 programs will not abort.
7257
7258 The ``problem'' in GuixSD is that users have a lot of freedom: They can
7259 choose whether and when to upgrade software in their profiles, and might
7260 be using a libc version different from the one the system administrator
7261 used to build the system-wide locale data.
7262
7263 Fortunately, unprivileged users can also install their own locale data
7264 and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
7265 @code{GUIX_LOCPATH} and locale packages}).
7266
7267 Still, it is best if the system-wide locale data at
7268 @file{/run/current-system/locale} is built for all the libc versions
7269 actually in use on the system, so that all the programs can access
7270 it---this is especially crucial on a multi-user system. To do that, the
7271 administrator can specify several libc packages in the
7272 @code{locale-libcs} field of @code{operating-system}:
7273
7274 @example
7275 (use-package-modules base)
7276
7277 (operating-system
7278 ;; @dots{}
7279 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
7280 @end example
7281
7282 This example would lead to a system containing locale definitions for
7283 both libc 2.21 and the current version of libc in
7284 @file{/run/current-system/locale}.
7285
7286
7287 @node Services
7288 @subsection Services
7289
7290 @cindex system services
7291 An important part of preparing an @code{operating-system} declaration is
7292 listing @dfn{system services} and their configuration (@pxref{Using the
7293 Configuration System}). System services are typically daemons launched
7294 when the system boots, or other actions needed at that time---e.g.,
7295 configuring network access.
7296
7297 Services are managed by the GNU@tie{}Shepherd (@pxref{Introduction,,,
7298 shepherd, The GNU Shepherd Manual}). On a running system, the
7299 @command{herd} command allows you to list the available services, show
7300 their status, start and stop them, or do other specific operations
7301 (@pxref{Jump Start,,, shepherd, The GNU Shepherd Manual}). For example:
7302
7303 @example
7304 # herd status
7305 @end example
7306
7307 The above command, run as @code{root}, lists the currently defined
7308 services. The @command{herd doc} command shows a synopsis of the given
7309 service:
7310
7311 @example
7312 # herd doc nscd
7313 Run libc's name service cache daemon (nscd).
7314 @end example
7315
7316 The @command{start}, @command{stop}, and @command{restart} sub-commands
7317 have the effect you would expect. For instance, the commands below stop
7318 the nscd service and restart the Xorg display server:
7319
7320 @example
7321 # herd stop nscd
7322 Service nscd has been stopped.
7323 # herd restart xorg-server
7324 Service xorg-server has been stopped.
7325 Service xorg-server has been started.
7326 @end example
7327
7328 The following sections document the available services, starting with
7329 the core services, that may be used in an @code{operating-system}
7330 declaration.
7331
7332 @menu
7333 * Base Services:: Essential system services.
7334 * Scheduled Job Execution:: The mcron service.
7335 * Networking Services:: Network setup, SSH daemon, etc.
7336 * X Window:: Graphical display.
7337 * Desktop Services:: D-Bus and desktop services.
7338 * Database Services:: SQL databases.
7339 * Mail Services:: IMAP, POP3, SMTP, and all that.
7340 * Web Services:: Web servers.
7341 * Various Services:: Other services.
7342 @end menu
7343
7344 @node Base Services
7345 @subsubsection Base Services
7346
7347 The @code{(gnu services base)} module provides definitions for the basic
7348 services that one expects from the system. The services exported by
7349 this module are listed below.
7350
7351 @defvr {Scheme Variable} %base-services
7352 This variable contains a list of basic services (@pxref{Service Types
7353 and Services}, for more information on service objects) one would
7354 expect from the system: a login service (mingetty) on each tty, syslogd,
7355 the libc name service cache daemon (nscd), the udev device manager, and
7356 more.
7357
7358 This is the default value of the @code{services} field of
7359 @code{operating-system} declarations. Usually, when customizing a
7360 system, you will want to append services to @var{%base-services}, like
7361 this:
7362
7363 @example
7364 (cons* (avahi-service) (lsh-service) %base-services)
7365 @end example
7366 @end defvr
7367
7368 @deffn {Scheme Procedure} host-name-service @var{name}
7369 Return a service that sets the host name to @var{name}.
7370 @end deffn
7371
7372 @deffn {Scheme Procedure} mingetty-service @var{config}
7373 Return a service to run mingetty according to @var{config}, a
7374 @code{<mingetty-configuration>} object, which specifies the tty to run, among
7375 other things.
7376 @end deffn
7377
7378 @deftp {Data Type} mingetty-configuration
7379 This is the data type representing the configuration of Mingetty, which
7380 implements console log-in.
7381
7382 @table @asis
7383
7384 @item @code{tty}
7385 The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
7386
7387 @item @code{motd}
7388 A file-like object containing the ``message of the day''.
7389
7390 @item @code{auto-login} (default: @code{#f})
7391 When true, this field must be a string denoting the user name under
7392 which the system automatically logs in. When it is @code{#f}, a
7393 user name and password must be entered to log in.
7394
7395 @item @code{login-program} (default: @code{#f})
7396 This must be either @code{#f}, in which case the default log-in program
7397 is used (@command{login} from the Shadow tool suite), or a gexp denoting
7398 the name of the log-in program.
7399
7400 @item @code{login-pause?} (default: @code{#f})
7401 When set to @code{#t} in conjunction with @var{auto-login}, the user
7402 will have to press a key before the log-in shell is launched.
7403
7404 @item @code{mingetty} (default: @var{mingetty})
7405 The Mingetty package to use.
7406
7407 @end table
7408 @end deftp
7409
7410 @cindex name service cache daemon
7411 @cindex nscd
7412 @deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
7413 [#:name-services '()]
7414 Return a service that runs the libc name service cache daemon (nscd) with the
7415 given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
7416 Service Switch}, for an example.
7417 @end deffn
7418
7419 @defvr {Scheme Variable} %nscd-default-configuration
7420 This is the default @code{<nscd-configuration>} value (see below) used
7421 by @code{nscd-service}. It uses the caches defined by
7422 @var{%nscd-default-caches}; see below.
7423 @end defvr
7424
7425 @deftp {Data Type} nscd-configuration
7426 This is the data type representing the name service cache daemon (nscd)
7427 configuration.
7428
7429 @table @asis
7430
7431 @item @code{name-services} (default: @code{'()})
7432 List of packages denoting @dfn{name services} that must be visible to
7433 the nscd---e.g., @code{(list @var{nss-mdns})}.
7434
7435 @item @code{glibc} (default: @var{glibc})
7436 Package object denoting the GNU C Library providing the @command{nscd}
7437 command.
7438
7439 @item @code{log-file} (default: @code{"/var/log/nscd.log"})
7440 Name of the nscd log file. This is where debugging output goes when
7441 @code{debug-level} is strictly positive.
7442
7443 @item @code{debug-level} (default: @code{0})
7444 Integer denoting the debugging levels. Higher numbers mean that more
7445 debugging output is logged.
7446
7447 @item @code{caches} (default: @var{%nscd-default-caches})
7448 List of @code{<nscd-cache>} objects denoting things to be cached; see
7449 below.
7450
7451 @end table
7452 @end deftp
7453
7454 @deftp {Data Type} nscd-cache
7455 Data type representing a cache database of nscd and its parameters.
7456
7457 @table @asis
7458
7459 @item @code{database}
7460 This is a symbol representing the name of the database to be cached.
7461 Valid values are @code{passwd}, @code{group}, @code{hosts}, and
7462 @code{services}, which designate the corresponding NSS database
7463 (@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
7464
7465 @item @code{positive-time-to-live}
7466 @itemx @code{negative-time-to-live} (default: @code{20})
7467 A number representing the number of seconds during which a positive or
7468 negative lookup result remains in cache.
7469
7470 @item @code{check-files?} (default: @code{#t})
7471 Whether to check for updates of the files corresponding to
7472 @var{database}.
7473
7474 For instance, when @var{database} is @code{hosts}, setting this flag
7475 instructs nscd to check for updates in @file{/etc/hosts} and to take
7476 them into account.
7477
7478 @item @code{persistent?} (default: @code{#t})
7479 Whether the cache should be stored persistently on disk.
7480
7481 @item @code{shared?} (default: @code{#t})
7482 Whether the cache should be shared among users.
7483
7484 @item @code{max-database-size} (default: 32@tie{}MiB)
7485 Maximum size in bytes of the database cache.
7486
7487 @c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
7488 @c settings, so leave them out.
7489
7490 @end table
7491 @end deftp
7492
7493 @defvr {Scheme Variable} %nscd-default-caches
7494 List of @code{<nscd-cache>} objects used by default by
7495 @code{nscd-configuration} (see above).
7496
7497 It enables persistent and aggressive caching of service and host name
7498 lookups. The latter provides better host name lookup performance,
7499 resilience in the face of unreliable name servers, and also better
7500 privacy---often the result of host name lookups is in local cache, so
7501 external name servers do not even need to be queried.
7502 @end defvr
7503
7504
7505 @deffn {Scheme Procedure} syslog-service @
7506 [#:config-file @var{%default-syslog.conf}]
7507 Return a service that runs @command{syslogd}. If the configuration file
7508 name @var{config-file} is not specified, use some reasonable default
7509 settings.
7510
7511 @xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
7512 information on the configuration file syntax.
7513 @end deffn
7514
7515 @anchor{guix-configuration-type}
7516 @deftp {Data Type} guix-configuration
7517 This data type represents the configuration of the Guix build daemon.
7518 @xref{Invoking guix-daemon}, for more information.
7519
7520 @table @asis
7521 @item @code{guix} (default: @var{guix})
7522 The Guix package to use.
7523
7524 @item @code{build-group} (default: @code{"guixbuild"})
7525 Name of the group for build user accounts.
7526
7527 @item @code{build-accounts} (default: @code{10})
7528 Number of build user accounts to create.
7529
7530 @item @code{authorize-key?} (default: @code{#t})
7531 Whether to authorize the substitute key for @code{hydra.gnu.org}
7532 (@pxref{Substitutes}).
7533
7534 @item @code{use-substitutes?} (default: @code{#t})
7535 Whether to use substitutes.
7536
7537 @item @code{substitute-urls} (default: @var{%default-substitute-urls})
7538 The list of URLs where to look for substitutes by default.
7539
7540 @item @code{extra-options} (default: @code{'()})
7541 List of extra command-line options for @command{guix-daemon}.
7542
7543 @item @code{lsof} (default: @var{lsof})
7544 @itemx @code{lsh} (default: @var{lsh})
7545 The lsof and lsh packages to use.
7546
7547 @end table
7548 @end deftp
7549
7550 @deffn {Scheme Procedure} guix-service @var{config}
7551 Return a service that runs the Guix build daemon according to
7552 @var{config}.
7553 @end deffn
7554
7555 @deffn {Scheme Procedure} udev-service [#:udev udev]
7556 Run @var{udev}, which populates the @file{/dev} directory dynamically.
7557 @end deffn
7558
7559 @deffn {Scheme Procedure} urandom-seed-service @var{#f}
7560 Save some entropy in @var{%random-seed-file} to seed @file{/dev/urandom}
7561 when rebooting.
7562 @end deffn
7563
7564 @defvr {Scheme Variable} %random-seed-file
7565 This is the name of the file where some random bytes are saved by
7566 @var{urandom-seed-service} to seed @file{/dev/urandom} when rebooting.
7567 It defaults to @file{/var/lib/random-seed}.
7568 @end defvr
7569
7570 @deffn {Scheme Procedure} console-keymap-service @var{files} ...
7571 @cindex keyboard layout
7572 Return a service to load console keymaps from @var{files} using
7573 @command{loadkeys} command. Most likely, you want to load some default
7574 keymap, which can be done like this:
7575
7576 @example
7577 (console-keymap-service "dvorak")
7578 @end example
7579
7580 Or, for example, for a Swedish keyboard, you may need to combine
7581 the following keymaps:
7582 @example
7583 (console-keymap-service "se-lat6" "se-fi-lat6")
7584 @end example
7585
7586 Also you can specify a full file name (or file names) of your keymap(s).
7587 See @code{man loadkeys} for details.
7588
7589 @end deffn
7590
7591 @deffn {Scheme Procedure} gpm-service [#:gpm @var{gpm}] @
7592 [#:options]
7593 Run @var{gpm}, the general-purpose mouse daemon, with the given
7594 command-line @var{options}. GPM allows users to use the mouse in the console,
7595 notably to select, copy, and paste text. The default value of @var{options}
7596 uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
7597
7598 This service is not part of @var{%base-services}.
7599 @end deffn
7600
7601 @anchor{guix-publish-service}
7602 @deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
7603 [#:port 80] [#:host "localhost"]
7604 Return a service that runs @command{guix publish} listening on @var{host}
7605 and @var{port} (@pxref{Invoking guix publish}).
7606
7607 This assumes that @file{/etc/guix} already contains a signing key pair as
7608 created by @command{guix archive --generate-key} (@pxref{Invoking guix
7609 archive}). If that is not the case, the service will fail to start.
7610 @end deffn
7611
7612 @anchor{rngd-service}
7613 @deffn {Scheme Procedure} rngd-service [#:rng-tools @var{rng-tools}] @
7614 [#:device "/dev/hwrng"]
7615 Return a service that runs the @command{rngd} program from @var{rng-tools}
7616 to add @var{device} to the kernel's entropy pool. The service will fail if
7617 @var{device} does not exist.
7618 @end deffn
7619
7620 @anchor{pam-limits-service}
7621 @cindex session limits
7622 @cindex ulimit
7623 @cindex priority
7624 @deffn {Scheme Procedure} pam-limits-service [#:limits @var{limits}]
7625
7626 Return a service that installs a configuration file for the
7627 @uref{http://linux-pam.org/Linux-PAM-html/sag-pam_limits.html,
7628 @code{pam_limits} module}. The procedure optionally takes a list of
7629 @code{pam-limits-entry} values, which can be used to specify
7630 @code{ulimit} limits and nice priority limits to user sessions.
7631
7632 The following limits definition sets two hard and soft limits for all
7633 login sessions of users in the @code{realtime} group:
7634
7635 @example
7636 (pam-limits-service
7637 (list
7638 (pam-limits-entry "@@realtime" 'both 'rtprio 99)
7639 (pam-limits-entry "@@realtime" 'both 'memlock 'unlimited)))
7640 @end example
7641
7642 The first entry increases the maximum realtime priority for
7643 non-privileged processes; the second entry lifts any restriction of the
7644 maximum address space that can be locked in memory. These settings are
7645 commonly used for real-time audio systems.
7646 @end deffn
7647
7648 @node Scheduled Job Execution
7649 @subsubsection Scheduled Job Execution
7650
7651 @cindex cron
7652 @cindex scheduling jobs
7653 The @code{(gnu services mcron)} module provides an interface to
7654 GNU@tie{}mcron, a daemon to run jobs at scheduled times (@pxref{Top,,,
7655 mcron, GNU@tie{}mcron}). GNU@tie{}mcron is similar to the traditional
7656 Unix @command{cron} daemon; the main difference is that it is
7657 implemented in Guile Scheme, which provides a lot of flexibility when
7658 specifying the scheduling of jobs and their actions.
7659
7660 The example below defines an operating system that runs the
7661 @command{updatedb} (@pxref{Invoking updatedb,,, find, Finding Files})
7662 and the @command{guix gc} commands (@pxref{Invoking guix gc}) daily, as
7663 well as the @command{mkid} command on behalf of an unprivileged user
7664 (@pxref{mkid invocation,,, idutils, ID Database Utilities}). It uses
7665 gexps to introduce job definitions that are passed to mcron
7666 (@pxref{G-Expressions}).
7667
7668 @lisp
7669 (use-modules (guix) (gnu) (gnu services mcron))
7670 (use-package-modules base idutils)
7671
7672 (define updatedb-job
7673 ;; Run 'updatedb' at 3AM every day. Here we write the
7674 ;; job's action as a Scheme procedure.
7675 #~(job '(next-hour '(3))
7676 (lambda ()
7677 (execl (string-append #$findutils "/bin/updatedb")
7678 "updatedb"
7679 "--prunepaths=/tmp /var/tmp /gnu/store"))))
7680
7681 (define garbage-collector-job
7682 ;; Collect garbage 5 minutes after midnight every day.
7683 ;; The job's action is a shell command.
7684 #~(job "5 0 * * *" ;Vixie cron syntax
7685 "guix gc -F 1G"))
7686
7687 (define idutils-jobs
7688 ;; Update the index database as user "charlie" at 12:15PM
7689 ;; and 19:15PM. This runs from the user's home directory.
7690 #~(job '(next-minute-from (next-hour '(12 19)) '(15))
7691 (string-append #$idutils "/bin/mkid src")
7692 #:user "charlie"))
7693
7694 (operating-system
7695 ;; @dots{}
7696 (services (cons (mcron-service (list garbage-collector-job
7697 updatedb-job
7698 idutils-job))
7699 %base-services)))
7700 @end lisp
7701
7702 @xref{Guile Syntax, mcron job specifications,, mcron, GNU@tie{}mcron},
7703 for more information on mcron job specifications. Below is the
7704 reference of the mcron service.
7705
7706 @deffn {Scheme Procedure} mcron-service @var{jobs} [#:mcron @var{mcron2}]
7707 Return an mcron service running @var{mcron} that schedules @var{jobs}, a
7708 list of gexps denoting mcron job specifications.
7709
7710 This is a shorthand for:
7711 @example
7712 (service mcron-service-type
7713 (mcron-configuration (mcron mcron) (jobs jobs)))
7714 @end example
7715 @end deffn
7716
7717 @defvr {Scheme Variable} mcron-service-type
7718 This is the type of the @code{mcron} service, whose value is an
7719 @code{mcron-configuration} object.
7720
7721 This service type can be the target of a service extension that provides
7722 it additional job specifications (@pxref{Service Composition}). In
7723 other words, it is possible to define services that provide addition
7724 mcron jobs to run.
7725 @end defvr
7726
7727 @deftp {Data Type} mcron-configuration
7728 Data type representing the configuration of mcron.
7729
7730 @table @asis
7731 @item @code{mcron} (default: @var{mcron2})
7732 The mcron package to use.
7733
7734 @item @code{jobs}
7735 This is a list of gexps (@pxref{G-Expressions}), where each gexp
7736 corresponds to an mcron job specification (@pxref{Syntax, mcron job
7737 specifications,, mcron, GNU@tie{}mcron}).
7738 @end table
7739 @end deftp
7740
7741
7742 @node Networking Services
7743 @subsubsection Networking Services
7744
7745 The @code{(gnu services networking)} module provides services to configure
7746 the network interface.
7747
7748 @cindex DHCP, networking service
7749 @deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
7750 Return a service that runs @var{dhcp}, a Dynamic Host Configuration
7751 Protocol (DHCP) client, on all the non-loopback network interfaces.
7752 @end deffn
7753
7754 @deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
7755 [#:gateway #f] [#:name-servers @code{'()}]
7756 Return a service that starts @var{interface} with address @var{ip}. If
7757 @var{gateway} is true, it must be a string specifying the default network
7758 gateway.
7759 @end deffn
7760
7761 @cindex wicd
7762 @cindex network management
7763 @deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
7764 Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
7765 management daemon that aims to simplify wired and wireless networking.
7766
7767 This service adds the @var{wicd} package to the global profile, providing
7768 several commands to interact with the daemon and configure networking:
7769 @command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
7770 and @command{wicd-curses} user interfaces.
7771 @end deffn
7772
7773 @cindex NetworkManager
7774 @deffn {Scheme Procedure} network-manager-service @
7775 [#:network-manager @var{network-manager}]
7776 Return a service that runs NetworkManager, a network connection manager
7777 attempting to keep network connectivity active when available.
7778 @end deffn
7779
7780 @cindex Connman
7781 @deffn {Scheme Procedure} connman-service @
7782 [#:connman @var{connman}]
7783 Return a service that runs @url{https://01.org/connman,Connman}, a network
7784 connection manager.
7785
7786 This service adds the @var{connman} package to the global profile, providing
7787 several the @command{connmanctl} command to interact with the daemon and
7788 configure networking."
7789 @end deffn
7790
7791 @deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
7792 [#:name-service @var{%ntp-servers}]
7793 Return a service that runs the daemon from @var{ntp}, the
7794 @uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
7795 keep the system clock synchronized with that of @var{servers}.
7796 @end deffn
7797
7798 @defvr {Scheme Variable} %ntp-servers
7799 List of host names used as the default NTP servers.
7800 @end defvr
7801
7802 @deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
7803 Return a service to run the @uref{https://torproject.org, Tor} anonymous
7804 networking daemon.
7805
7806 The daemon runs as the @code{tor} unprivileged user. It is passed
7807 @var{config-file}, a file-like object, with an additional @code{User tor} line
7808 and lines for hidden services added via @code{tor-hidden-service}. Run
7809 @command{man tor} for information about the configuration file.
7810 @end deffn
7811
7812 @cindex hidden service
7813 @deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
7814 Define a new Tor @dfn{hidden service} called @var{name} and implementing
7815 @var{mapping}. @var{mapping} is a list of port/host tuples, such as:
7816
7817 @example
7818 '((22 "127.0.0.1:22")
7819 (80 "127.0.0.1:8080"))
7820 @end example
7821
7822 In this example, port 22 of the hidden service is mapped to local port 22, and
7823 port 80 is mapped to local port 8080.
7824
7825 This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
7826 the @file{hostname} file contains the @code{.onion} host name for the hidden
7827 service.
7828
7829 See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
7830 project's documentation} for more information.
7831 @end deffn
7832
7833 @deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
7834 [#:interface "127.0.0.1"] [#:port 6667] @
7835 [#:extra-settings ""]
7836 Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
7837 acts as a gateway between IRC and chat networks.
7838
7839 The daemon will listen to the interface corresponding to the IP address
7840 specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
7841 local clients can connect, whereas @code{0.0.0.0} means that connections can
7842 come from any networking interface.
7843
7844 In addition, @var{extra-settings} specifies a string to append to the
7845 configuration file.
7846 @end deffn
7847
7848 Furthermore, @code{(gnu services ssh)} provides the following services.
7849
7850 @deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
7851 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
7852 [#:allow-empty-passwords? #f] [#:root-login? #f] @
7853 [#:syslog-output? #t] [#:x11-forwarding? #t] @
7854 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
7855 [#:public-key-authentication? #t] [#:initialize? #t]
7856 Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
7857 @var{host-key} must designate a file containing the host key, and readable
7858 only by root.
7859
7860 When @var{daemonic?} is true, @command{lshd} will detach from the
7861 controlling terminal and log its output to syslogd, unless one sets
7862 @var{syslog-output?} to false. Obviously, it also makes lsh-service
7863 depend on existence of syslogd service. When @var{pid-file?} is true,
7864 @command{lshd} writes its PID to the file called @var{pid-file}.
7865
7866 When @var{initialize?} is true, automatically create the seed and host key
7867 upon service activation if they do not exist yet. This may take long and
7868 require interaction.
7869
7870 When @var{initialize?} is false, it is up to the user to initialize the
7871 randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
7872 a key pair with the private key stored in file @var{host-key} (@pxref{lshd
7873 basics,,, lsh, LSH Manual}).
7874
7875 When @var{interfaces} is empty, lshd listens for connections on all the
7876 network interfaces; otherwise, @var{interfaces} must be a list of host names
7877 or addresses.
7878
7879 @var{allow-empty-passwords?} specifies whether to accept log-ins with empty
7880 passwords, and @var{root-login?} specifies whether to accept log-ins as
7881 root.
7882
7883 The other options should be self-descriptive.
7884 @end deffn
7885
7886 @deffn {Scheme Procedure} dropbear-service [@var{config}]
7887 Run the @uref{https://matt.ucc.asn.au/dropbear/dropbear.html,Dropbear SSH
7888 daemon} with the given @var{config}, a @code{<dropbear-configuration>}
7889 object.
7890
7891 For example, to specify a Dropbear service listening on port 1234, add
7892 this call to the operating system's @code{services} field:
7893
7894 @example
7895 (dropbear-service (dropbear-configuration
7896 (port-number 1234)))
7897 @end example
7898 @end deffn
7899
7900 @deftp {Data Type} dropbear-configuration
7901 This data type represents the configuration of a Dropbear SSH daemon.
7902
7903 @table @asis
7904 @item @code{dropbear} (default: @var{dropbear})
7905 The Dropbear package to use.
7906
7907 @item @code{port-number} (default: 22)
7908 The TCP port where the daemon waits for incoming connections.
7909
7910 @item @code{syslog-output?} (default: @code{#t})
7911 Whether to enable syslog output.
7912
7913 @item @code{pid-file} (default: @code{"/var/run/dropbear.pid"})
7914 File name of the daemon's PID file.
7915
7916 @item @code{root-login?} (default: @code{#f})
7917 Whether to allow @code{root} logins.
7918
7919 @item @code{allow-empty-passwords?} (default: @code{#f})
7920 Whether to allow empty passwords.
7921
7922 @item @code{password-authentication?} (default: @code{#t})
7923 Whether to enable password-based authentication.
7924 @end table
7925 @end deftp
7926
7927 @defvr {Scheme Variable} %facebook-host-aliases
7928 This variable contains a string for use in @file{/etc/hosts}
7929 (@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
7930 line contains a entry that maps a known server name of the Facebook
7931 on-line service---e.g., @code{www.facebook.com}---to the local
7932 host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
7933
7934 This variable is typically used in the @code{hosts-file} field of an
7935 @code{operating-system} declaration (@pxref{operating-system Reference,
7936 @file{/etc/hosts}}):
7937
7938 @example
7939 (use-modules (gnu) (guix))
7940
7941 (operating-system
7942 (host-name "mymachine")
7943 ;; ...
7944 (hosts-file
7945 ;; Create a /etc/hosts file with aliases for "localhost"
7946 ;; and "mymachine", as well as for Facebook servers.
7947 (plain-file "hosts"
7948 (string-append (local-host-aliases host-name)
7949 %facebook-host-aliases))))
7950 @end example
7951
7952 This mechanism can prevent programs running locally, such as Web
7953 browsers, from accessing Facebook.
7954 @end defvr
7955
7956 The @code{(gnu services avahi)} provides the following definition.
7957
7958 @deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
7959 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
7960 [#:ipv6? #t] [#:wide-area? #f] @
7961 [#:domains-to-browse '()] [#:debug? #f]
7962 Return a service that runs @command{avahi-daemon}, a system-wide
7963 mDNS/DNS-SD responder that allows for service discovery and
7964 "zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
7965 extends the name service cache daemon (nscd) so that it can resolve
7966 @code{.local} host names using
7967 @uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
7968 add the @var{avahi} package to the system profile so that commands such as
7969 @command{avahi-browse} are directly usable.
7970
7971 If @var{host-name} is different from @code{#f}, use that as the host name to
7972 publish for this machine; otherwise, use the machine's actual host name.
7973
7974 When @var{publish?} is true, publishing of host names and services is allowed;
7975 in particular, avahi-daemon will publish the machine's host name and IP
7976 address via mDNS on the local network.
7977
7978 When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
7979
7980 Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
7981 sockets.
7982 @end deffn
7983
7984
7985 @node X Window
7986 @subsubsection X Window
7987
7988 Support for the X Window graphical display system---specifically
7989 Xorg---is provided by the @code{(gnu services xorg)} module. Note that
7990 there is no @code{xorg-service} procedure. Instead, the X server is
7991 started by the @dfn{login manager}, currently SLiM.
7992
7993 @deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
7994 [#:auto-login? #f] [#:default-user ""] [#:startx] @
7995 [#:theme @var{%default-slim-theme}] @
7996 [#:theme-name @var{%default-slim-theme-name}]
7997 Return a service that spawns the SLiM graphical login manager, which in
7998 turn starts the X display server with @var{startx}, a command as returned by
7999 @code{xorg-start-command}.
8000
8001 @cindex X session
8002
8003 SLiM automatically looks for session types described by the @file{.desktop}
8004 files in @file{/run/current-system/profile/share/xsessions} and allows users
8005 to choose a session from the log-in screen using @kbd{F1}. Packages such as
8006 @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
8007 adding them to the system-wide set of packages automatically makes them
8008 available at the log-in screen.
8009
8010 In addition, @file{~/.xsession} files are honored. When available,
8011 @file{~/.xsession} must be an executable that starts a window manager
8012 and/or other X clients.
8013
8014 When @var{allow-empty-passwords?} is true, allow logins with an empty
8015 password. When @var{auto-login?} is true, log in automatically as
8016 @var{default-user}.
8017
8018 If @var{theme} is @code{#f}, use the default log-in theme; otherwise
8019 @var{theme} must be a gexp denoting the name of a directory containing the
8020 theme to use. In that case, @var{theme-name} specifies the name of the
8021 theme.
8022 @end deffn
8023
8024 @defvr {Scheme Variable} %default-theme
8025 @defvrx {Scheme Variable} %default-theme-name
8026 The G-Expression denoting the default SLiM theme and its name.
8027 @end defvr
8028
8029 @deffn {Scheme Procedure} xorg-start-command [#:guile] @
8030 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
8031 Return a derivation that builds a @var{guile} script to start the X server
8032 from @var{xorg-server}. @var{configuration-file} is the server configuration
8033 file or a derivation that builds it; when omitted, the result of
8034 @code{xorg-configuration-file} is used.
8035
8036 Usually the X server is started by a login manager.
8037 @end deffn
8038
8039 @deffn {Scheme Procedure} xorg-configuration-file @
8040 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
8041 Return a configuration file for the Xorg server containing search paths for
8042 all the common drivers.
8043
8044 @var{drivers} must be either the empty list, in which case Xorg chooses a
8045 graphics driver automatically, or a list of driver names that will be tried in
8046 this order---e.g., @code{(\"modesetting\" \"vesa\")}.
8047
8048 Likewise, when @var{resolutions} is the empty list, Xorg chooses an
8049 appropriate screen resolution; otherwise, it must be a list of
8050 resolutions---e.g., @code{((1024 768) (640 480))}.
8051
8052 Last, @var{extra-config} is a list of strings or objects appended to the
8053 @code{text-file*} argument list. It is used to pass extra text to be added
8054 verbatim to the configuration file.
8055 @end deffn
8056
8057 @deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
8058 Add @var{package}, a package for a screen-locker or screen-saver whose
8059 command is @var{program}, to the set of setuid programs and add a PAM entry
8060 for it. For example:
8061
8062 @lisp
8063 (screen-locker-service xlockmore "xlock")
8064 @end lisp
8065
8066 makes the good ol' XlockMore usable.
8067 @end deffn
8068
8069
8070 @node Desktop Services
8071 @subsubsection Desktop Services
8072
8073 The @code{(gnu services desktop)} module provides services that are
8074 usually useful in the context of a ``desktop'' setup---that is, on a
8075 machine running a graphical display server, possibly with graphical user
8076 interfaces, etc. It also defines services that provide specific desktop
8077 environments like GNOME and XFCE.
8078
8079 To simplify things, the module defines a variable containing the set of
8080 services that users typically expect on a machine with a graphical
8081 environment and networking:
8082
8083 @defvr {Scheme Variable} %desktop-services
8084 This is a list of services that builds upon @var{%base-services} and
8085 adds or adjusts services for a typical ``desktop'' setup.
8086
8087 In particular, it adds a graphical login manager (@pxref{X Window,
8088 @code{slim-service}}), screen lockers,
8089 a network management tool (@pxref{Networking
8090 Services, @code{wicd-service}}), energy and color management services,
8091 the @code{elogind} login and seat manager, the Polkit privilege service,
8092 the GeoClue location service, an NTP client (@pxref{Networking
8093 Services}), the Avahi daemon, and has the name service switch service
8094 configured to be able to use @code{nss-mdns} (@pxref{Name Service
8095 Switch, mDNS}).
8096 @end defvr
8097
8098 The @var{%desktop-services} variable can be used as the @code{services}
8099 field of an @code{operating-system} declaration (@pxref{operating-system
8100 Reference, @code{services}}).
8101
8102 Additionally, the @code{gnome-desktop-service} and
8103 @code{xfce-desktop-service} procedures can add GNOME and/or XFCE to a
8104 system. To ``add GNOME'' means that system-level services like the
8105 backlight adjustment helpers and the power management utilities are
8106 added to the system, extending @code{polkit} and @code{dbus}
8107 appropriately, allowing GNOME to operate with elevated privileges on a
8108 limited number of special-purpose system interfaces. Additionally,
8109 adding a service made by @code{gnome-desktop-service} adds the GNOME
8110 metapackage to the system profile. Likewise, adding the XFCE service
8111 not only adds the @code{xfce} metapackage to the system profile, but it
8112 also gives the Thunar file manager the ability to open a ``root-mode''
8113 file management window, if the user authenticates using the
8114 administrator's password via the standard polkit graphical interface.
8115
8116 @deffn {Scheme Procedure} gnome-desktop-service
8117 Return a service that adds the @code{gnome} package to the system
8118 profile, and extends polkit with the actions from
8119 @code{gnome-settings-daemon}.
8120 @end deffn
8121
8122 @deffn {Scheme Procedure} xfce-desktop-service
8123 Return a service that adds the @code{xfce} package to the system profile,
8124 and extends polkit with the abilit for @code{thunar} to manipulate the
8125 file system as root from within a user session, after the user has
8126 authenticated with the administrator's password.
8127 @end deffn
8128
8129 Because the GNOME and XFCE desktop services pull in so many packages,
8130 the default @code{%desktop-services} variable doesn't include either of
8131 them by default. To add GNOME or XFCE, just @code{cons} them onto
8132 @code{%desktop-services} in the @code{services} field of your
8133 @code{operating-system}:
8134
8135 @example
8136 (use-modules (gnu))
8137 (use-service-modules desktop)
8138 (operating-system
8139 ...
8140 ;; cons* adds items to the list given as its last argument.
8141 (services (cons* (gnome-desktop-service)
8142 (xfce-desktop-service)
8143 %desktop-services))
8144 ...)
8145 @end example
8146
8147 These desktop environments will then be available as options in the
8148 graphical login window.
8149
8150 The actual service definitions included in @code{%desktop-services} and
8151 provided by @code{(gnu services dbus)} and @code{(gnu services desktop)}
8152 are described below.
8153
8154 @deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
8155 Return a service that runs the ``system bus'', using @var{dbus}, with
8156 support for @var{services}.
8157
8158 @uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
8159 facility. Its system bus is used to allow system services to communicate
8160 and to be notified of system-wide events.
8161
8162 @var{services} must be a list of packages that provide an
8163 @file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
8164 and policy files. For example, to allow avahi-daemon to use the system bus,
8165 @var{services} must be equal to @code{(list avahi)}.
8166 @end deffn
8167
8168 @deffn {Scheme Procedure} elogind-service [#:config @var{config}]
8169 Return a service that runs the @code{elogind} login and
8170 seat management daemon. @uref{https://github.com/andywingo/elogind,
8171 Elogind} exposes a D-Bus interface that can be used to know which users
8172 are logged in, know what kind of sessions they have open, suspend the
8173 system, inhibit system suspend, reboot the system, and other tasks.
8174
8175 Elogind handles most system-level power events for a computer, for
8176 example suspending the system when a lid is closed, or shutting it down
8177 when the power button is pressed.
8178
8179 The @var{config} keyword argument specifies the configuration for
8180 elogind, and should be the result of an @code{(elogind-configuration
8181 (@var{parameter} @var{value})...)} invocation. Available parameters and
8182 their default values are:
8183
8184 @table @code
8185 @item kill-user-processes?
8186 @code{#f}
8187 @item kill-only-users
8188 @code{()}
8189 @item kill-exclude-users
8190 @code{("root")}
8191 @item inhibit-delay-max-seconds
8192 @code{5}
8193 @item handle-power-key
8194 @code{poweroff}
8195 @item handle-suspend-key
8196 @code{suspend}
8197 @item handle-hibernate-key
8198 @code{hibernate}
8199 @item handle-lid-switch
8200 @code{suspend}
8201 @item handle-lid-switch-docked
8202 @code{ignore}
8203 @item power-key-ignore-inhibited?
8204 @code{#f}
8205 @item suspend-key-ignore-inhibited?
8206 @code{#f}
8207 @item hibernate-key-ignore-inhibited?
8208 @code{#f}
8209 @item lid-switch-ignore-inhibited?
8210 @code{#t}
8211 @item holdoff-timeout-seconds
8212 @code{30}
8213 @item idle-action
8214 @code{ignore}
8215 @item idle-action-seconds
8216 @code{(* 30 60)}
8217 @item runtime-directory-size-percent
8218 @code{10}
8219 @item runtime-directory-size
8220 @code{#f}
8221 @item remove-ipc?
8222 @code{#t}
8223 @item suspend-state
8224 @code{("mem" "standby" "freeze")}
8225 @item suspend-mode
8226 @code{()}
8227 @item hibernate-state
8228 @code{("disk")}
8229 @item hibernate-mode
8230 @code{("platform" "shutdown")}
8231 @item hybrid-sleep-state
8232 @code{("disk")}
8233 @item hybrid-sleep-mode
8234 @code{("suspend" "platform" "shutdown")}
8235 @end table
8236 @end deffn
8237
8238 @deffn {Scheme Procedure} polkit-service @
8239 [#:polkit @var{polkit}]
8240 Return a service that runs the
8241 @uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
8242 management service}, which allows system administrators to grant access to
8243 privileged operations in a structured way. By querying the Polkit service, a
8244 privileged system component can know when it should grant additional
8245 capabilities to ordinary users. For example, an ordinary user can be granted
8246 the capability to suspend the system if the user is logged in locally.
8247 @end deffn
8248
8249 @deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
8250 [#:watts-up-pro? #f] @
8251 [#:poll-batteries? #t] @
8252 [#:ignore-lid? #f] @
8253 [#:use-percentage-for-policy? #f] @
8254 [#:percentage-low 10] @
8255 [#:percentage-critical 3] @
8256 [#:percentage-action 2] @
8257 [#:time-low 1200] @
8258 [#:time-critical 300] @
8259 [#:time-action 120] @
8260 [#:critical-power-action 'hybrid-sleep]
8261 Return a service that runs @uref{http://upower.freedesktop.org/,
8262 @command{upowerd}}, a system-wide monitor for power consumption and battery
8263 levels, with the given configuration settings. It implements the
8264 @code{org.freedesktop.UPower} D-Bus interface, and is notably used by
8265 GNOME.
8266 @end deffn
8267
8268 @deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
8269 Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
8270 UDisks}, a @dfn{disk management} daemon that provides user interfaces with
8271 notifications and ways to mount/unmount disks. Programs that talk to UDisks
8272 include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
8273 @end deffn
8274
8275 @deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
8276 Return a service that runs @command{colord}, a system service with a D-Bus
8277 interface to manage the color profiles of input and output devices such as
8278 screens and scanners. It is notably used by the GNOME Color Manager graphical
8279 tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
8280 site} for more information.
8281 @end deffn
8282
8283 @deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
8284 Return a configuration allowing an application to access GeoClue
8285 location data. @var{name} is the Desktop ID of the application, without
8286 the @code{.desktop} part. If @var{allowed?} is true, the application
8287 will have access to location information by default. The boolean
8288 @var{system?} value indicates whether an application is a system component
8289 or not. Finally @var{users} is a list of UIDs of all users for which
8290 this application is allowed location info access. An empty users list
8291 means that all users are allowed.
8292 @end deffn
8293
8294 @defvr {Scheme Variable} %standard-geoclue-applications
8295 The standard list of well-known GeoClue application configurations,
8296 granting authority to the GNOME date-and-time utility to ask for the
8297 current location in order to set the time zone, and allowing the
8298 IceCat and Epiphany web browsers to request location information.
8299 IceCat and Epiphany both query the user before allowing a web page to
8300 know the user's location.
8301 @end defvr
8302
8303 @deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
8304 [#:whitelist '()] @
8305 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
8306 [#:submit-data? #f]
8307 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
8308 [#:submission-nick "geoclue"] @
8309 [#:applications %standard-geoclue-applications]
8310 Return a service that runs the GeoClue location service. This service
8311 provides a D-Bus interface to allow applications to request access to a
8312 user's physical location, and optionally to add information to online
8313 location databases. See
8314 @uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
8315 web site} for more information.
8316 @end deffn
8317
8318 @deffn {Scheme Procedure} bluetooth-service [#:bluez @var{bluez}]
8319 Return a service that runs the @command{bluetoothd} daemon, which manages
8320 all the Bluetooth devices and provides a number of D-Bus interfaces.
8321
8322 Users need to be in the @code{lp} group to access the D-Bus service.
8323 @end deffn
8324
8325 @node Database Services
8326 @subsubsection Database Services
8327
8328 The @code{(gnu services databases)} module provides the following services.
8329
8330 @deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
8331 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
8332 Return a service that runs @var{postgresql}, the PostgreSQL database
8333 server.
8334
8335 The PostgreSQL daemon loads its runtime configuration from
8336 @var{config-file} and stores the database cluster in
8337 @var{data-directory}.
8338 @end deffn
8339
8340 @deffn {Scheme Procedure} mysql-service [#:config (mysql-configuration)]
8341 Return a service that runs @command{mysqld}, the MySQL or MariaDB
8342 database server.
8343
8344 The optional @var{config} argument specifies the configuration for
8345 @command{mysqld}, which should be a @code{<mysql-configuraiton>} object.
8346 @end deffn
8347
8348 @deftp {Data Type} mysql-configuration
8349 Data type representing the configuration of @var{mysql-service}.
8350
8351 @table @asis
8352 @item @code{mysql} (default: @var{mariadb})
8353 Package object of the MySQL database server, can be either @var{mariadb}
8354 or @var{mysql}.
8355
8356 For MySQL, a temorary root password will be displayed at activation time.
8357 For MariaDB, the root password is empty.
8358 @end table
8359 @end deftp
8360
8361 @node Mail Services
8362 @subsubsection Mail Services
8363
8364 The @code{(gnu services mail)} module provides Guix service definitions
8365 for mail services. Currently the only implemented service is Dovecot,
8366 an IMAP, POP3, and LMTP server.
8367
8368 Guix does not yet have a mail transfer agent (MTA), although for some
8369 lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
8370 is needed to properly integrate a full MTA, such as Postfix. Patches
8371 welcome!
8372
8373 To add an IMAP/POP3 server to a GuixSD system, add a
8374 @code{dovecot-service} to the operating system definition:
8375
8376 @deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
8377 Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
8378 @end deffn
8379
8380 By default, Dovecot does not need much configuration; the default
8381 configuration object created by @code{(dovecot-configuration)} will
8382 suffice if your mail is delivered to @code{~/Maildir}. A self-signed
8383 certificate will be generated for TLS-protected connections, though
8384 Dovecot will also listen on cleartext ports by default. There are a
8385 number of options, though, which mail administrators might need to change,
8386 and as is the case with other services, Guix allows the system
8387 administrator to specify these parameters via a uniform Scheme interface.
8388
8389 For example, to specify that mail is located at @code{maildir~/.mail},
8390 one would instantiate the Dovecot service like this:
8391
8392 @example
8393 (dovecot-service #:config
8394 (dovecot-configuration
8395 (mail-location "maildir:~/.mail")))
8396 @end example
8397
8398 The available configuration parameters follow. Each parameter
8399 definition is preceded by its type; for example, @samp{string-list foo}
8400 indicates that the @code{foo} parameter should be specified as a list of
8401 strings. There is also a way to specify the configuration as a string,
8402 if you have an old @code{dovecot.conf} file that you want to port over
8403 from some other system; see the end for more details.
8404
8405 @c The following documentation was initially generated by
8406 @c (generate-documentation) in (gnu services mail). Manually maintained
8407 @c documentation is better, so we shouldn't hesitate to edit below as
8408 @c needed. However if the change you want to make to this documentation
8409 @c can be done in an automated way, it's probably easier to change
8410 @c (generate-documentation) than to make it below and have to deal with
8411 @c the churn as dovecot updates.
8412
8413 Available @code{dovecot-configuration} fields are:
8414
8415 @deftypevr {@code{dovecot-configuration} parameter} package dovecot
8416 The dovecot package.
8417 @end deftypevr
8418
8419 @deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
8420 A list of IPs or hosts where to listen for connections. @samp{*}
8421 listens on all IPv4 interfaces, @samp{::} listens on all IPv6
8422 interfaces. If you want to specify non-default ports or anything more
8423 complex, customize the address and port fields of the
8424 @samp{inet-listener} of the specific services you are interested in.
8425 @end deftypevr
8426
8427 @deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
8428 List of protocols we want to serve. Available protocols include
8429 @samp{imap}, @samp{pop3}, and @samp{lmtp}.
8430
8431 Available @code{protocol-configuration} fields are:
8432
8433 @deftypevr {@code{protocol-configuration} parameter} string name
8434 The name of the protocol.
8435 @end deftypevr
8436
8437 @deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
8438 UNIX socket path to the master authentication server to find users.
8439 This is used by imap (for shared users) and lda.
8440 It defaults to @samp{"/var/run/dovecot/auth-userdb"}.
8441 @end deftypevr
8442
8443 @deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
8444 Space separated list of plugins to load.
8445 @end deftypevr
8446
8447 @deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
8448 Maximum number of IMAP connections allowed for a user from each IP
8449 address. NOTE: The username is compared case-sensitively.
8450 Defaults to @samp{10}.
8451 @end deftypevr
8452
8453 @end deftypevr
8454
8455 @deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
8456 List of services to enable. Available services include @samp{imap},
8457 @samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
8458 @samp{lmtp}.
8459
8460 Available @code{service-configuration} fields are:
8461
8462 @deftypevr {@code{service-configuration} parameter} string kind
8463 The service kind. Valid values include @code{director},
8464 @code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
8465 @code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
8466 @code{tcpwrap}, @code{quota-warning}, or anything else.
8467 @end deftypevr
8468
8469 @deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
8470 Listeners for the service. A listener is either a
8471 @code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
8472 an @code{inet-listener-configuration}.
8473 Defaults to @samp{()}.
8474
8475 Available @code{unix-listener-configuration} fields are:
8476
8477 @deftypevr {@code{unix-listener-configuration} parameter} file-name path
8478 The file name on which to listen.
8479 @end deftypevr
8480
8481 @deftypevr {@code{unix-listener-configuration} parameter} string mode
8482 The access mode for the socket.
8483 Defaults to @samp{"0600"}.
8484 @end deftypevr
8485
8486 @deftypevr {@code{unix-listener-configuration} parameter} string user
8487 The user to own the socket.
8488 Defaults to @samp{""}.
8489 @end deftypevr
8490
8491 @deftypevr {@code{unix-listener-configuration} parameter} string group
8492 The group to own the socket.
8493 Defaults to @samp{""}.
8494 @end deftypevr
8495
8496
8497 Available @code{fifo-listener-configuration} fields are:
8498
8499 @deftypevr {@code{fifo-listener-configuration} parameter} file-name path
8500 The file name on which to listen.
8501 @end deftypevr
8502
8503 @deftypevr {@code{fifo-listener-configuration} parameter} string mode
8504 The access mode for the socket.
8505 Defaults to @samp{"0600"}.
8506 @end deftypevr
8507
8508 @deftypevr {@code{fifo-listener-configuration} parameter} string user
8509 The user to own the socket.
8510 Defaults to @samp{""}.
8511 @end deftypevr
8512
8513 @deftypevr {@code{fifo-listener-configuration} parameter} string group
8514 The group to own the socket.
8515 Defaults to @samp{""}.
8516 @end deftypevr
8517
8518
8519 Available @code{inet-listener-configuration} fields are:
8520
8521 @deftypevr {@code{inet-listener-configuration} parameter} string protocol
8522 The protocol to listen for.
8523 @end deftypevr
8524
8525 @deftypevr {@code{inet-listener-configuration} parameter} string address
8526 The address on which to listen, or empty for all addresses.
8527 Defaults to @samp{""}.
8528 @end deftypevr
8529
8530 @deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
8531 The port on which to listen.
8532 @end deftypevr
8533
8534 @deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
8535 Whether to use SSL for this service; @samp{yes}, @samp{no}, or
8536 @samp{required}.
8537 Defaults to @samp{#t}.
8538 @end deftypevr
8539
8540 @end deftypevr
8541
8542 @deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
8543 Number of connections to handle before starting a new process.
8544 Typically the only useful values are 0 (unlimited) or 1. 1 is more
8545 secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
8546 Defaults to @samp{1}.
8547 @end deftypevr
8548
8549 @deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
8550 Number of processes to always keep waiting for more connections.
8551 Defaults to @samp{0}.
8552 @end deftypevr
8553
8554 @deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
8555 If you set @samp{service-count 0}, you probably need to grow
8556 this.
8557 Defaults to @samp{256000000}.
8558 @end deftypevr
8559
8560 @end deftypevr
8561
8562 @deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
8563 Dict configuration, as created by the @code{dict-configuration}
8564 constructor.
8565
8566 Available @code{dict-configuration} fields are:
8567
8568 @deftypevr {@code{dict-configuration} parameter} free-form-fields entries
8569 A list of key-value pairs that this dict should hold.
8570 Defaults to @samp{()}.
8571 @end deftypevr
8572
8573 @end deftypevr
8574
8575 @deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
8576 A list of passdb configurations, each one created by the
8577 @code{passdb-configuration} constructor.
8578
8579 Available @code{passdb-configuration} fields are:
8580
8581 @deftypevr {@code{passdb-configuration} parameter} string driver
8582 The driver that the passdb should use. Valid values include
8583 @samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
8584 @samp{static}.
8585 Defaults to @samp{"pam"}.
8586 @end deftypevr
8587
8588 @deftypevr {@code{passdb-configuration} parameter} free-form-args args
8589 A list of key-value args to the passdb driver.
8590 Defaults to @samp{()}.
8591 @end deftypevr
8592
8593 @end deftypevr
8594
8595 @deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
8596 List of userdb configurations, each one created by the
8597 @code{userdb-configuration} constructor.
8598
8599 Available @code{userdb-configuration} fields are:
8600
8601 @deftypevr {@code{userdb-configuration} parameter} string driver
8602 The driver that the userdb should use. Valid values include
8603 @samp{passwd} and @samp{static}.
8604 Defaults to @samp{"passwd"}.
8605 @end deftypevr
8606
8607 @deftypevr {@code{userdb-configuration} parameter} free-form-args args
8608 A list of key-value args to the userdb driver.
8609 Defaults to @samp{()}.
8610 @end deftypevr
8611
8612 @deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
8613 Override fields from passwd.
8614 Defaults to @samp{()}.
8615 @end deftypevr
8616
8617 @end deftypevr
8618
8619 @deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
8620 Plug-in configuration, created by the @code{plugin-configuration}
8621 constructor.
8622 @end deftypevr
8623
8624 @deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
8625 List of namespaces. Each item in the list is created by the
8626 @code{namespace-configuration} constructor.
8627
8628 Available @code{namespace-configuration} fields are:
8629
8630 @deftypevr {@code{namespace-configuration} parameter} string name
8631 Name for this namespace.
8632 @end deftypevr
8633
8634 @deftypevr {@code{namespace-configuration} parameter} string type
8635 Namespace type: @samp{private}, @samp{shared} or @samp{public}.
8636 Defaults to @samp{"private"}.
8637 @end deftypevr
8638
8639 @deftypevr {@code{namespace-configuration} parameter} string separator
8640 Hierarchy separator to use. You should use the same separator for
8641 all namespaces or some clients get confused. @samp{/} is usually a good
8642 one. The default however depends on the underlying mail storage
8643 format.
8644 Defaults to @samp{""}.
8645 @end deftypevr
8646
8647 @deftypevr {@code{namespace-configuration} parameter} string prefix
8648 Prefix required to access this namespace. This needs to be
8649 different for all namespaces. For example @samp{Public/}.
8650 Defaults to @samp{""}.
8651 @end deftypevr
8652
8653 @deftypevr {@code{namespace-configuration} parameter} string location
8654 Physical location of the mailbox. This is in the same format as
8655 mail_location, which is also the default for it.
8656 Defaults to @samp{""}.
8657 @end deftypevr
8658
8659 @deftypevr {@code{namespace-configuration} parameter} boolean inbox?
8660 There can be only one INBOX, and this setting defines which
8661 namespace has it.
8662 Defaults to @samp{#f}.
8663 @end deftypevr
8664
8665 @deftypevr {@code{namespace-configuration} parameter} boolean hidden?
8666 If namespace is hidden, it's not advertised to clients via NAMESPACE
8667 extension. You'll most likely also want to set @samp{list? #f}. This is mostly
8668 useful when converting from another server with different namespaces
8669 which you want to deprecate but still keep working. For example you can
8670 create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
8671 and @samp{mail/}.
8672 Defaults to @samp{#f}.
8673 @end deftypevr
8674
8675 @deftypevr {@code{namespace-configuration} parameter} boolean list?
8676 Show the mailboxes under this namespace with the LIST command. This
8677 makes the namespace visible for clients that do not support the NAMESPACE
8678 extension. The special @code{children} value lists child mailboxes, but
8679 hides the namespace prefix.
8680 Defaults to @samp{#t}.
8681 @end deftypevr
8682
8683 @deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
8684 Namespace handles its own subscriptions. If set to @code{#f}, the
8685 parent namespace handles them. The empty prefix should always have this
8686 as @code{#t}).
8687 Defaults to @samp{#t}.
8688 @end deftypevr
8689
8690 @deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
8691 List of predefined mailboxes in this namespace.
8692 Defaults to @samp{()}.
8693
8694 Available @code{mailbox-configuration} fields are:
8695
8696 @deftypevr {@code{mailbox-configuration} parameter} string name
8697 Name for this mailbox.
8698 @end deftypevr
8699
8700 @deftypevr {@code{mailbox-configuration} parameter} string auto
8701 @samp{create} will automatically create this mailbox.
8702 @samp{subscribe} will both create and subscribe to the mailbox.
8703 Defaults to @samp{"no"}.
8704 @end deftypevr
8705
8706 @deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
8707 List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
8708 Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
8709 @code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
8710 Defaults to @samp{()}.
8711 @end deftypevr
8712
8713 @end deftypevr
8714
8715 @end deftypevr
8716
8717 @deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
8718 Base directory where to store runtime data.
8719 Defaults to @samp{"/var/run/dovecot/"}.
8720 @end deftypevr
8721
8722 @deftypevr {@code{dovecot-configuration} parameter} string login-greeting
8723 Greeting message for clients.
8724 Defaults to @samp{"Dovecot ready."}.
8725 @end deftypevr
8726
8727 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
8728 List of trusted network ranges. Connections from these IPs are
8729 allowed to override their IP addresses and ports (for logging and for
8730 authentication checks). @samp{disable-plaintext-auth} is also ignored
8731 for these networks. Typically you would specify your IMAP proxy servers
8732 here.
8733 Defaults to @samp{()}.
8734 @end deftypevr
8735
8736 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
8737 List of login access check sockets (e.g. tcpwrap).
8738 Defaults to @samp{()}.
8739 @end deftypevr
8740
8741 @deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
8742 Show more verbose process titles (in ps). Currently shows user name
8743 and IP address. Useful for seeing who is actually using the IMAP
8744 processes (e.g. shared mailboxes or if the same uid is used for multiple
8745 accounts).
8746 Defaults to @samp{#f}.
8747 @end deftypevr
8748
8749 @deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
8750 Should all processes be killed when Dovecot master process shuts down.
8751 Setting this to @code{#f} means that Dovecot can be upgraded without
8752 forcing existing client connections to close (although that could also
8753 be a problem if the upgrade is e.g. due to a security fix).
8754 Defaults to @samp{#t}.
8755 @end deftypevr
8756
8757 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
8758 If non-zero, run mail commands via this many connections to doveadm
8759 server, instead of running them directly in the same process.
8760 Defaults to @samp{0}.
8761 @end deftypevr
8762
8763 @deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
8764 UNIX socket or host:port used for connecting to doveadm server.
8765 Defaults to @samp{"doveadm-server"}.
8766 @end deftypevr
8767
8768 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
8769 List of environment variables that are preserved on Dovecot startup
8770 and passed down to all of its child processes. You can also give
8771 key=value pairs to always set specific settings.
8772 @end deftypevr
8773
8774 @deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
8775 Disable LOGIN command and all other plaintext authentications unless
8776 SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
8777 matches the local IP (i.e. you're connecting from the same computer),
8778 the connection is considered secure and plaintext authentication is
8779 allowed. See also ssl=required setting.
8780 Defaults to @samp{#t}.
8781 @end deftypevr
8782
8783 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
8784 Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
8785 Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
8786 for caching to be used.
8787 Defaults to @samp{0}.
8788 @end deftypevr
8789
8790 @deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
8791 Time to live for cached data. After TTL expires the cached record
8792 is no longer used, *except* if the main database lookup returns internal
8793 failure. We also try to handle password changes automatically: If
8794 user's previous authentication was successful, but this one wasn't, the
8795 cache isn't used. For now this works only with plaintext
8796 authentication.
8797 Defaults to @samp{"1 hour"}.
8798 @end deftypevr
8799
8800 @deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
8801 TTL for negative hits (user not found, password mismatch).
8802 0 disables caching them completely.
8803 Defaults to @samp{"1 hour"}.
8804 @end deftypevr
8805
8806 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
8807 List of realms for SASL authentication mechanisms that need them.
8808 You can leave it empty if you don't want to support multiple realms.
8809 Many clients simply use the first one listed here, so keep the default
8810 realm first.
8811 Defaults to @samp{()}.
8812 @end deftypevr
8813
8814 @deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
8815 Default realm/domain to use if none was specified. This is used for
8816 both SASL realms and appending @@domain to username in plaintext
8817 logins.
8818 Defaults to @samp{""}.
8819 @end deftypevr
8820
8821 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
8822 List of allowed characters in username. If the user-given username
8823 contains a character not listed in here, the login automatically fails.
8824 This is just an extra check to make sure user can't exploit any
8825 potential quote escaping vulnerabilities with SQL/LDAP databases. If
8826 you want to allow all characters, set this value to empty.
8827 Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
8828 @end deftypevr
8829
8830 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
8831 Username character translations before it's looked up from
8832 databases. The value contains series of from -> to characters. For
8833 example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
8834 translated to @samp{@@}.
8835 Defaults to @samp{""}.
8836 @end deftypevr
8837
8838 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
8839 Username formatting before it's looked up from databases. You can
8840 use the standard variables here, e.g. %Lu would lowercase the username,
8841 %n would drop away the domain if it was given, or @samp{%n-AT-%d} would
8842 change the @samp{@@} into @samp{-AT-}. This translation is done after
8843 @samp{auth-username-translation} changes.
8844 Defaults to @samp{"%Lu"}.
8845 @end deftypevr
8846
8847 @deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
8848 If you want to allow master users to log in by specifying the master
8849 username within the normal username string (i.e. not using SASL
8850 mechanism's support for it), you can specify the separator character
8851 here. The format is then <username><separator><master username>.
8852 UW-IMAP uses @samp{*} as the separator, so that could be a good
8853 choice.
8854 Defaults to @samp{""}.
8855 @end deftypevr
8856
8857 @deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
8858 Username to use for users logging in with ANONYMOUS SASL
8859 mechanism.
8860 Defaults to @samp{"anonymous"}.
8861 @end deftypevr
8862
8863 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
8864 Maximum number of dovecot-auth worker processes. They're used to
8865 execute blocking passdb and userdb queries (e.g. MySQL and PAM).
8866 They're automatically created and destroyed as needed.
8867 Defaults to @samp{30}.
8868 @end deftypevr
8869
8870 @deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
8871 Host name to use in GSSAPI principal names. The default is to use
8872 the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
8873 allow all keytab entries.
8874 Defaults to @samp{""}.
8875 @end deftypevr
8876
8877 @deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
8878 Kerberos keytab to use for the GSSAPI mechanism. Will use the
8879 system default (usually /etc/krb5.keytab) if not specified. You may
8880 need to change the auth service to run as root to be able to read this
8881 file.
8882 Defaults to @samp{""}.
8883 @end deftypevr
8884
8885 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
8886 Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
8887 and @samp{ntlm-auth} helper.
8888 <doc/wiki/Authentication/Mechanisms/Winbind.txt>.
8889 Defaults to @samp{#f}.
8890 @end deftypevr
8891
8892 @deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
8893 Path for Samba's @samp{ntlm-auth} helper binary.
8894 Defaults to @samp{"/usr/bin/ntlm_auth"}.
8895 @end deftypevr
8896
8897 @deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
8898 Time to delay before replying to failed authentications.
8899 Defaults to @samp{"2 secs"}.
8900 @end deftypevr
8901
8902 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
8903 Require a valid SSL client certificate or the authentication
8904 fails.
8905 Defaults to @samp{#f}.
8906 @end deftypevr
8907
8908 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
8909 Take the username from client's SSL certificate, using
8910 @code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
8911 CommonName.
8912 Defaults to @samp{#f}.
8913 @end deftypevr
8914
8915 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
8916 List of wanted authentication mechanisms. Supported mechanisms are:
8917 @samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
8918 @samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
8919 @samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
8920 @samp{disable-plaintext-auth} setting.
8921 @end deftypevr
8922
8923 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
8924 List of IPs or hostnames to all director servers, including ourself.
8925 Ports can be specified as ip:port. The default port is the same as what
8926 director service's @samp{inet-listener} is using.
8927 Defaults to @samp{()}.
8928 @end deftypevr
8929
8930 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
8931 List of IPs or hostnames to all backend mail servers. Ranges are
8932 allowed too, like 10.0.0.10-10.0.0.30.
8933 Defaults to @samp{()}.
8934 @end deftypevr
8935
8936 @deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
8937 How long to redirect users to a specific server after it no longer
8938 has any connections.
8939 Defaults to @samp{"15 min"}.
8940 @end deftypevr
8941
8942 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
8943 TCP/IP port that accepts doveadm connections (instead of director
8944 connections) If you enable this, you'll also need to add
8945 @samp{inet-listener} for the port.
8946 Defaults to @samp{0}.
8947 @end deftypevr
8948
8949 @deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
8950 How the username is translated before being hashed. Useful values
8951 include %Ln if user can log in with or without @@domain, %Ld if mailboxes
8952 are shared within domain.
8953 Defaults to @samp{"%Lu"}.
8954 @end deftypevr
8955
8956 @deftypevr {@code{dovecot-configuration} parameter} string log-path
8957 Log file to use for error messages. @samp{syslog} logs to syslog,
8958 @samp{/dev/stderr} logs to stderr.
8959 Defaults to @samp{"syslog"}.
8960 @end deftypevr
8961
8962 @deftypevr {@code{dovecot-configuration} parameter} string info-log-path
8963 Log file to use for informational messages. Defaults to
8964 @samp{log-path}.
8965 Defaults to @samp{""}.
8966 @end deftypevr
8967
8968 @deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
8969 Log file to use for debug messages. Defaults to
8970 @samp{info-log-path}.
8971 Defaults to @samp{""}.
8972 @end deftypevr
8973
8974 @deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
8975 Syslog facility to use if you're logging to syslog. Usually if you
8976 don't want to use @samp{mail}, you'll use local0..local7. Also other
8977 standard facilities are supported.
8978 Defaults to @samp{"mail"}.
8979 @end deftypevr
8980
8981 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
8982 Log unsuccessful authentication attempts and the reasons why they
8983 failed.
8984 Defaults to @samp{#f}.
8985 @end deftypevr
8986
8987 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
8988 In case of password mismatches, log the attempted password. Valid
8989 values are no, plain and sha1. sha1 can be useful for detecting brute
8990 force password attempts vs. user simply trying the same password over
8991 and over again. You can also truncate the value to n chars by appending
8992 ":n" (e.g. sha1:6).
8993 Defaults to @samp{#f}.
8994 @end deftypevr
8995
8996 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
8997 Even more verbose logging for debugging purposes. Shows for example
8998 SQL queries.
8999 Defaults to @samp{#f}.
9000 @end deftypevr
9001
9002 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
9003 In case of password mismatches, log the passwords and used scheme so
9004 the problem can be debugged. Enabling this also enables
9005 @samp{auth-debug}.
9006 Defaults to @samp{#f}.
9007 @end deftypevr
9008
9009 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
9010 Enable mail process debugging. This can help you figure out why
9011 Dovecot isn't finding your mails.
9012 Defaults to @samp{#f}.
9013 @end deftypevr
9014
9015 @deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
9016 Show protocol level SSL errors.
9017 Defaults to @samp{#f}.
9018 @end deftypevr
9019
9020 @deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
9021 Prefix for each line written to log file. % codes are in
9022 strftime(3) format.
9023 Defaults to @samp{"\"%b %d %H:%M:%S \""}.
9024 @end deftypevr
9025
9026 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
9027 List of elements we want to log. The elements which have a
9028 non-empty variable value are joined together to form a comma-separated
9029 string.
9030 @end deftypevr
9031
9032 @deftypevr {@code{dovecot-configuration} parameter} string login-log-format
9033 Login log format. %s contains @samp{login-log-format-elements}
9034 string, %$ contains the data we want to log.
9035 Defaults to @samp{"%$: %s"}.
9036 @end deftypevr
9037
9038 @deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
9039 Log prefix for mail processes. See doc/wiki/Variables.txt for list
9040 of possible variables you can use.
9041 Defaults to @samp{"\"%s(%u): \""}.
9042 @end deftypevr
9043
9044 @deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
9045 Format to use for logging mail deliveries. You can use variables:
9046 @table @code
9047 @item %$
9048 Delivery status message (e.g. @samp{saved to INBOX})
9049 @item %m
9050 Message-ID
9051 @item %s
9052 Subject
9053 @item %f
9054 From address
9055 @item %p
9056 Physical size
9057 @item %w
9058 Virtual size.
9059 @end table
9060 Defaults to @samp{"msgid=%m: %$"}.
9061 @end deftypevr
9062
9063 @deftypevr {@code{dovecot-configuration} parameter} string mail-location
9064 Location for users' mailboxes. The default is empty, which means
9065 that Dovecot tries to find the mailboxes automatically. This won't work
9066 if the user doesn't yet have any mail, so you should explicitly tell
9067 Dovecot the full location.
9068
9069 If you're using mbox, giving a path to the INBOX
9070 file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
9071 where the other mailboxes are kept. This is called the "root mail
9072 directory", and it must be the first path given in the
9073 @samp{mail-location} setting.
9074
9075 There are a few special variables you can use, eg.:
9076
9077 @table @samp
9078 @item %u
9079 username
9080 @item %n
9081 user part in user@@domain, same as %u if there's no domain
9082 @item %d
9083 domain part in user@@domain, empty if there's no domain
9084 @item %h
9085 home director
9086 @end table
9087
9088 See doc/wiki/Variables.txt for full list. Some examples:
9089 @table @samp
9090 @item maildir:~/Maildir
9091 @item mbox:~/mail:INBOX=/var/mail/%u
9092 @item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
9093 @end table
9094 Defaults to @samp{""}.
9095 @end deftypevr
9096
9097 @deftypevr {@code{dovecot-configuration} parameter} string mail-uid
9098 System user and group used to access mails. If you use multiple,
9099 userdb can override these by returning uid or gid fields. You can use
9100 either numbers or names. <doc/wiki/UserIds.txt>.
9101 Defaults to @samp{""}.
9102 @end deftypevr
9103
9104 @deftypevr {@code{dovecot-configuration} parameter} string mail-gid
9105
9106 Defaults to @samp{""}.
9107 @end deftypevr
9108
9109 @deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
9110 Group to enable temporarily for privileged operations. Currently
9111 this is used only with INBOX when either its initial creation or
9112 dotlocking fails. Typically this is set to "mail" to give access to
9113 /var/mail.
9114 Defaults to @samp{""}.
9115 @end deftypevr
9116
9117 @deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
9118 Grant access to these supplementary groups for mail processes.
9119 Typically these are used to set up access to shared mailboxes. Note
9120 that it may be dangerous to set these if users can create
9121 symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
9122 could allow a user to delete others' mailboxes, or ln -s
9123 /secret/shared/box ~/mail/mybox would allow reading it).
9124 Defaults to @samp{""}.
9125 @end deftypevr
9126
9127 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
9128 Allow full filesystem access to clients. There's no access checks
9129 other than what the operating system does for the active UID/GID. It
9130 works with both maildir and mboxes, allowing you to prefix mailboxes
9131 names with e.g. /path/ or ~user/.
9132 Defaults to @samp{#f}.
9133 @end deftypevr
9134
9135 @deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
9136 Don't use mmap() at all. This is required if you store indexes to
9137 shared filesystems (NFS or clustered filesystem).
9138 Defaults to @samp{#f}.
9139 @end deftypevr
9140
9141 @deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
9142 Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
9143 supports @samp{O_EXCL} since version 3, so this should be safe to use
9144 nowadays by default.
9145 Defaults to @samp{#t}.
9146 @end deftypevr
9147
9148 @deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
9149 When to use fsync() or fdatasync() calls:
9150 @table @code
9151 @item optimized
9152 Whenever necessary to avoid losing important data
9153 @item always
9154 Useful with e.g. NFS when write()s are delayed
9155 @item never
9156 Never use it (best performance, but crashes can lose data).
9157 @end table
9158 Defaults to @samp{"optimized"}.
9159 @end deftypevr
9160
9161 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
9162 Mail storage exists in NFS. Set this to yes to make Dovecot flush
9163 NFS caches whenever needed. If you're using only a single mail server
9164 this isn't needed.
9165 Defaults to @samp{#f}.
9166 @end deftypevr
9167
9168 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
9169 Mail index files also exist in NFS. Setting this to yes requires
9170 @samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
9171 Defaults to @samp{#f}.
9172 @end deftypevr
9173
9174 @deftypevr {@code{dovecot-configuration} parameter} string lock-method
9175 Locking method for index files. Alternatives are fcntl, flock and
9176 dotlock. Dotlocking uses some tricks which may create more disk I/O
9177 than other locking methods. NFS users: flock doesn't work, remember to
9178 change @samp{mmap-disable}.
9179 Defaults to @samp{"fcntl"}.
9180 @end deftypevr
9181
9182 @deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
9183 Directory in which LDA/LMTP temporarily stores incoming mails >128
9184 kB.
9185 Defaults to @samp{"/tmp"}.
9186 @end deftypevr
9187
9188 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
9189 Valid UID range for users. This is mostly to make sure that users can't
9190 log in as daemons or other system users. Note that denying root logins is
9191 hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
9192 is set to 0.
9193 Defaults to @samp{500}.
9194 @end deftypevr
9195
9196 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
9197
9198 Defaults to @samp{0}.
9199 @end deftypevr
9200
9201 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
9202 Valid GID range for users. Users having non-valid GID as primary group ID
9203 aren't allowed to log in. If user belongs to supplementary groups with
9204 non-valid GIDs, those groups are not set.
9205 Defaults to @samp{1}.
9206 @end deftypevr
9207
9208 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
9209
9210 Defaults to @samp{0}.
9211 @end deftypevr
9212
9213 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
9214 Maximum allowed length for mail keyword name. It's only forced when
9215 trying to create new keywords.
9216 Defaults to @samp{50}.
9217 @end deftypevr
9218
9219 @deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
9220 List of directories under which chrooting is allowed for mail
9221 processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
9222 too). This setting doesn't affect @samp{login-chroot}
9223 @samp{mail-chroot} or auth chroot settings. If this setting is empty,
9224 "/./" in home dirs are ignored. WARNING: Never add directories here
9225 which local users can modify, that may lead to root exploit. Usually
9226 this should be done only if you don't allow shell access for users.
9227 <doc/wiki/Chrooting.txt>.
9228 Defaults to @samp{()}.
9229 @end deftypevr
9230
9231 @deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
9232 Default chroot directory for mail processes. This can be overridden
9233 for specific users in user database by giving /./ in user's home
9234 directory (e.g. /home/./user chroots into /home). Note that usually
9235 there is no real need to do chrooting, Dovecot doesn't allow users to
9236 access files outside their mail directory anyway. If your home
9237 directories are prefixed with the chroot directory, append "/." to
9238 @samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
9239 Defaults to @samp{""}.
9240 @end deftypevr
9241
9242 @deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
9243 UNIX socket path to master authentication server to find users.
9244 This is used by imap (for shared users) and lda.
9245 Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
9246 @end deftypevr
9247
9248 @deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
9249 Directory where to look up mail plugins.
9250 Defaults to @samp{"/usr/lib/dovecot"}.
9251 @end deftypevr
9252
9253 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
9254 List of plugins to load for all services. Plugins specific to IMAP,
9255 LDA, etc. are added to this list in their own .conf files.
9256 Defaults to @samp{()}.
9257 @end deftypevr
9258
9259 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
9260 The minimum number of mails in a mailbox before updates are done to
9261 cache file. This allows optimizing Dovecot's behavior to do less disk
9262 writes at the cost of more disk reads.
9263 Defaults to @samp{0}.
9264 @end deftypevr
9265
9266 @deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
9267 When IDLE command is running, mailbox is checked once in a while to
9268 see if there are any new mails or other changes. This setting defines
9269 the minimum time to wait between those checks. Dovecot can also use
9270 dnotify, inotify and kqueue to find out immediately when changes
9271 occur.
9272 Defaults to @samp{"30 secs"}.
9273 @end deftypevr
9274
9275 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
9276 Save mails with CR+LF instead of plain LF. This makes sending those
9277 mails take less CPU, especially with sendfile() syscall with Linux and
9278 FreeBSD. But it also creates a bit more disk I/O which may just make it
9279 slower. Also note that if other software reads the mboxes/maildirs,
9280 they may handle the extra CRs wrong and cause problems.
9281 Defaults to @samp{#f}.
9282 @end deftypevr
9283
9284 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
9285 By default LIST command returns all entries in maildir beginning
9286 with a dot. Enabling this option makes Dovecot return only entries
9287 which are directories. This is done by stat()ing each entry, so it
9288 causes more disk I/O.
9289 (For systems setting struct @samp{dirent->d_type} this check is free
9290 and it's done always regardless of this setting).
9291 Defaults to @samp{#f}.
9292 @end deftypevr
9293
9294 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
9295 When copying a message, do it with hard links whenever possible.
9296 This makes the performance much better, and it's unlikely to have any
9297 side effects.
9298 Defaults to @samp{#t}.
9299 @end deftypevr
9300
9301 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
9302 Assume Dovecot is the only MUA accessing Maildir: Scan cur/
9303 directory only when its mtime changes unexpectedly or when we can't find
9304 the mail otherwise.
9305 Defaults to @samp{#f}.
9306 @end deftypevr
9307
9308 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
9309 Which locking methods to use for locking mbox. There are four
9310 available:
9311
9312 @table @code
9313 @item dotlock
9314 Create <mailbox>.lock file. This is the oldest and most NFS-safe
9315 solution. If you want to use /var/mail/ like directory, the users will
9316 need write access to that directory.
9317 @item dotlock-try
9318 Same as dotlock, but if it fails because of permissions or because there
9319 isn't enough disk space, just skip it.
9320 @item fcntl
9321 Use this if possible. Works with NFS too if lockd is used.
9322 @item flock
9323 May not exist in all systems. Doesn't work with NFS.
9324 @item lockf
9325 May not exist in all systems. Doesn't work with NFS.
9326 @end table
9327
9328 You can use multiple locking methods; if you do the order they're declared
9329 in is important to avoid deadlocks if other MTAs/MUAs are using multiple
9330 locking methods as well. Some operating systems don't allow using some of
9331 them simultaneously.
9332 @end deftypevr
9333
9334 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
9335
9336 @end deftypevr
9337
9338 @deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
9339 Maximum time to wait for lock (all of them) before aborting.
9340 Defaults to @samp{"5 mins"}.
9341 @end deftypevr
9342
9343 @deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
9344 If dotlock exists but the mailbox isn't modified in any way,
9345 override the lock file after this much time.
9346 Defaults to @samp{"2 mins"}.
9347 @end deftypevr
9348
9349 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
9350 When mbox changes unexpectedly we have to fully read it to find out
9351 what changed. If the mbox is large this can take a long time. Since
9352 the change is usually just a newly appended mail, it'd be faster to
9353 simply read the new mails. If this setting is enabled, Dovecot does
9354 this but still safely fallbacks to re-reading the whole mbox file
9355 whenever something in mbox isn't how it's expected to be. The only real
9356 downside to this setting is that if some other MUA changes message
9357 flags, Dovecot doesn't notice it immediately. Note that a full sync is
9358 done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
9359 Defaults to @samp{#t}.
9360 @end deftypevr
9361
9362 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
9363 Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
9364 EXAMINE, EXPUNGE or CHECK commands. If this is set,
9365 @samp{mbox-dirty-syncs} is ignored.
9366 Defaults to @samp{#f}.
9367 @end deftypevr
9368
9369 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
9370 Delay writing mbox headers until doing a full write sync (EXPUNGE
9371 and CHECK commands and when closing the mailbox). This is especially
9372 useful for POP3 where clients often delete all mails. The downside is
9373 that our changes aren't immediately visible to other MUAs.
9374 Defaults to @samp{#t}.
9375 @end deftypevr
9376
9377 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
9378 If mbox size is smaller than this (e.g. 100k), don't write index
9379 files. If an index file already exists it's still read, just not
9380 updated.
9381 Defaults to @samp{0}.
9382 @end deftypevr
9383
9384 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
9385 Maximum dbox file size until it's rotated.
9386 Defaults to @samp{2000000}.
9387 @end deftypevr
9388
9389 @deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
9390 Maximum dbox file age until it's rotated. Typically in days. Day
9391 begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
9392 disabled.
9393 Defaults to @samp{"1d"}.
9394 @end deftypevr
9395
9396 @deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
9397 When creating new mdbox files, immediately preallocate their size to
9398 @samp{mdbox-rotate-size}. This setting currently works only in Linux
9399 with some filesystems (ext4, xfs).
9400 Defaults to @samp{#f}.
9401 @end deftypevr
9402
9403 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
9404 sdbox and mdbox support saving mail attachments to external files,
9405 which also allows single instance storage for them. Other backends
9406 don't support this for now.
9407
9408 WARNING: This feature hasn't been tested much yet. Use at your own risk.
9409
9410 Directory root where to store mail attachments. Disabled, if empty.
9411 Defaults to @samp{""}.
9412 @end deftypevr
9413
9414 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
9415 Attachments smaller than this aren't saved externally. It's also
9416 possible to write a plugin to disable saving specific attachments
9417 externally.
9418 Defaults to @samp{128000}.
9419 @end deftypevr
9420
9421 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
9422 Filesystem backend to use for saving attachments:
9423 @table @code
9424 @item posix
9425 No SiS done by Dovecot (but this might help FS's own deduplication)
9426 @item sis posix
9427 SiS with immediate byte-by-byte comparison during saving
9428 @item sis-queue posix
9429 SiS with delayed comparison and deduplication.
9430 @end table
9431 Defaults to @samp{"sis posix"}.
9432 @end deftypevr
9433
9434 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
9435 Hash format to use in attachment filenames. You can add any text and
9436 variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
9437 @code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
9438 truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
9439 Defaults to @samp{"%@{sha1@}"}.
9440 @end deftypevr
9441
9442 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
9443
9444 Defaults to @samp{100}.
9445 @end deftypevr
9446
9447 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
9448
9449 Defaults to @samp{1000}.
9450 @end deftypevr
9451
9452 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
9453 Default VSZ (virtual memory size) limit for service processes.
9454 This is mainly intended to catch and kill processes that leak memory
9455 before they eat up everything.
9456 Defaults to @samp{256000000}.
9457 @end deftypevr
9458
9459 @deftypevr {@code{dovecot-configuration} parameter} string default-login-user
9460 Login user is internally used by login processes. This is the most
9461 untrusted user in Dovecot system. It shouldn't have access to anything
9462 at all.
9463 Defaults to @samp{"dovenull"}.
9464 @end deftypevr
9465
9466 @deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
9467 Internal user is used by unprivileged processes. It should be
9468 separate from login user, so that login processes can't disturb other
9469 processes.
9470 Defaults to @samp{"dovecot"}.
9471 @end deftypevr
9472
9473 @deftypevr {@code{dovecot-configuration} parameter} string ssl?
9474 SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
9475 Defaults to @samp{"required"}.
9476 @end deftypevr
9477
9478 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
9479 PEM encoded X.509 SSL/TLS certificate (public key).
9480 Defaults to @samp{"</etc/dovecot/default.pem"}.
9481 @end deftypevr
9482
9483 @deftypevr {@code{dovecot-configuration} parameter} string ssl-key
9484 PEM encoded SSL/TLS private key. The key is opened before
9485 dropping root privileges, so keep the key file unreadable by anyone but
9486 root.
9487 Defaults to @samp{"</etc/dovecot/private/default.pem"}.
9488 @end deftypevr
9489
9490 @deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
9491 If key file is password protected, give the password here.
9492 Alternatively give it when starting dovecot with -p parameter. Since
9493 this file is often world-readable, you may want to place this setting
9494 instead to a different.
9495 Defaults to @samp{""}.
9496 @end deftypevr
9497
9498 @deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
9499 PEM encoded trusted certificate authority. Set this only if you
9500 intend to use @samp{ssl-verify-client-cert? #t}. The file should
9501 contain the CA certificate(s) followed by the matching
9502 CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
9503 Defaults to @samp{""}.
9504 @end deftypevr
9505
9506 @deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
9507 Require that CRL check succeeds for client certificates.
9508 Defaults to @samp{#t}.
9509 @end deftypevr
9510
9511 @deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
9512 Request client to send a certificate. If you also want to require
9513 it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
9514 Defaults to @samp{#f}.
9515 @end deftypevr
9516
9517 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
9518 Which field from certificate to use for username. commonName and
9519 x500UniqueIdentifier are the usual choices. You'll also need to set
9520 @samp{auth-ssl-username-from-cert? #t}.
9521 Defaults to @samp{"commonName"}.
9522 @end deftypevr
9523
9524 @deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
9525 How often to regenerate the SSL parameters file. Generation is
9526 quite CPU intensive operation. The value is in hours, 0 disables
9527 regeneration entirely.
9528 Defaults to @samp{168}.
9529 @end deftypevr
9530
9531 @deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
9532 SSL protocols to use.
9533 Defaults to @samp{"!SSLv2"}.
9534 @end deftypevr
9535
9536 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
9537 SSL ciphers to use.
9538 Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
9539 @end deftypevr
9540
9541 @deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
9542 SSL crypto device to use, for valid values run "openssl engine".
9543 Defaults to @samp{""}.
9544 @end deftypevr
9545
9546 @deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
9547 Address to use when sending rejection mails.
9548 Default is postmaster@@<your domain>. %d expands to recipient domain.
9549 Defaults to @samp{""}.
9550 @end deftypevr
9551
9552 @deftypevr {@code{dovecot-configuration} parameter} string hostname
9553 Hostname to use in various parts of sent mails (e.g. in Message-Id)
9554 and in LMTP replies. Default is the system's real hostname@@domain.
9555 Defaults to @samp{""}.
9556 @end deftypevr
9557
9558 @deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
9559 If user is over quota, return with temporary failure instead of
9560 bouncing the mail.
9561 Defaults to @samp{#f}.
9562 @end deftypevr
9563
9564 @deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
9565 Binary to use for sending mails.
9566 Defaults to @samp{"/usr/sbin/sendmail"}.
9567 @end deftypevr
9568
9569 @deftypevr {@code{dovecot-configuration} parameter} string submission-host
9570 If non-empty, send mails via this SMTP host[:port] instead of
9571 sendmail.
9572 Defaults to @samp{""}.
9573 @end deftypevr
9574
9575 @deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
9576 Subject: header to use for rejection mails. You can use the same
9577 variables as for @samp{rejection-reason} below.
9578 Defaults to @samp{"Rejected: %s"}.
9579 @end deftypevr
9580
9581 @deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
9582 Human readable error message for rejection mails. You can use
9583 variables:
9584
9585 @table @code
9586 @item %n
9587 CRLF
9588 @item %r
9589 reason
9590 @item %s
9591 original subject
9592 @item %t
9593 recipient
9594 @end table
9595 Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
9596 @end deftypevr
9597
9598 @deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
9599 Delimiter character between local-part and detail in email
9600 address.
9601 Defaults to @samp{"+"}.
9602 @end deftypevr
9603
9604 @deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
9605 Header where the original recipient address (SMTP's RCPT TO:
9606 address) is taken from if not available elsewhere. With dovecot-lda -a
9607 parameter overrides this. A commonly used header for this is
9608 X-Original-To.
9609 Defaults to @samp{""}.
9610 @end deftypevr
9611
9612 @deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
9613 Should saving a mail to a nonexistent mailbox automatically create
9614 it?.
9615 Defaults to @samp{#f}.
9616 @end deftypevr
9617
9618 @deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
9619 Should automatically created mailboxes be also automatically
9620 subscribed?.
9621 Defaults to @samp{#f}.
9622 @end deftypevr
9623
9624 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
9625 Maximum IMAP command line length. Some clients generate very long
9626 command lines with huge mailboxes, so you may need to raise this if you
9627 get "Too long argument" or "IMAP command line too large" errors
9628 often.
9629 Defaults to @samp{64000}.
9630 @end deftypevr
9631
9632 @deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
9633 IMAP logout format string:
9634 @table @code
9635 @item %i
9636 total number of bytes read from client
9637 @item %o
9638 total number of bytes sent to client.
9639 @end table
9640 Defaults to @samp{"in=%i out=%o"}.
9641 @end deftypevr
9642
9643 @deftypevr {@code{dovecot-configuration} parameter} string imap-capability
9644 Override the IMAP CAPABILITY response. If the value begins with '+',
9645 add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
9646 Defaults to @samp{""}.
9647 @end deftypevr
9648
9649 @deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
9650 How long to wait between "OK Still here" notifications when client
9651 is IDLEing.
9652 Defaults to @samp{"2 mins"}.
9653 @end deftypevr
9654
9655 @deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
9656 ID field names and values to send to clients. Using * as the value
9657 makes Dovecot use the default value. The following fields have default
9658 values currently: name, version, os, os-version, support-url,
9659 support-email.
9660 Defaults to @samp{""}.
9661 @end deftypevr
9662
9663 @deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
9664 ID fields sent by client to log. * means everything.
9665 Defaults to @samp{""}.
9666 @end deftypevr
9667
9668 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
9669 Workarounds for various client bugs:
9670
9671 @table @code
9672 @item delay-newmail
9673 Send EXISTS/RECENT new mail notifications only when replying to NOOP and
9674 CHECK commands. Some clients ignore them otherwise, for example OSX
9675 Mail (<v2.1). Outlook Express breaks more badly though, without this it
9676 may show user "Message no longer in server" errors. Note that OE6
9677 still breaks even with this workaround if synchronization is set to
9678 "Headers Only".
9679
9680 @item tb-extra-mailbox-sep
9681 Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
9682 adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
9683 ignore the extra @samp{/} instead of treating it as invalid mailbox name.
9684
9685 @item tb-lsub-flags
9686 Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
9687 This makes Thunderbird realize they aren't selectable and show them
9688 greyed out, instead of only later giving "not selectable" popup error.
9689 @end table
9690 Defaults to @samp{()}.
9691 @end deftypevr
9692
9693 @deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
9694 Host allowed in URLAUTH URLs sent by client. "*" allows all.
9695 Defaults to @samp{""}.
9696 @end deftypevr
9697
9698
9699 Whew! Lots of configuration options. The nice thing about it though is
9700 that GuixSD has a complete interface to Dovecot's configuration
9701 language. This allows not only a nice way to declare configurations,
9702 but also offers reflective capabilities as well: users can write code to
9703 inspect and transform configurations from within Scheme.
9704
9705 However, it could be that you just want to get a @code{dovecot.conf} up
9706 and running. In that case, you can pass an
9707 @code{opaque-dovecot-configuration} as the @code{#:config} paramter to
9708 @code{dovecot-service}. As its name indicates, an opaque configuration
9709 does not have easy reflective capabilities.
9710
9711 Available @code{opaque-dovecot-configuration} fields are:
9712
9713 @deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
9714 The dovecot package.
9715 @end deftypevr
9716
9717 @deftypevr {@code{opaque-dovecot-configuration} parameter} string string
9718 The contents of the @code{dovecot.conf}, as a string.
9719 @end deftypevr
9720
9721 For example, if your @code{dovecot.conf} is just the empty string, you
9722 could instantiate a dovecot service like this:
9723
9724 @example
9725 (dovecot-service #:config
9726 (opaque-dovecot-configuration
9727 (string "")))
9728 @end example
9729
9730 @node Web Services
9731 @subsubsection Web Services
9732
9733 The @code{(gnu services web)} module provides the following service:
9734
9735 @deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
9736 [#:log-directory ``/var/log/nginx''] @
9737 [#:run-directory ``/var/run/nginx''] @
9738 [#:config-file]
9739
9740 Return a service that runs @var{nginx}, the nginx web server.
9741
9742 The nginx daemon loads its runtime configuration from @var{config-file}.
9743 Log files are written to @var{log-directory} and temporary runtime data
9744 files are written to @var{run-directory}. For proper operation, these
9745 arguments should match what is in @var{config-file} to ensure that the
9746 directories are created when the service is activated.
9747
9748 @end deffn
9749
9750 @node Various Services
9751 @subsubsection Various Services
9752
9753 The @code{(gnu services lirc)} module provides the following service.
9754
9755 @deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
9756 [#:device #f] [#:driver #f] [#:config-file #f] @
9757 [#:extra-options '()]
9758 Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
9759 decodes infrared signals from remote controls.
9760
9761 Optionally, @var{device}, @var{driver} and @var{config-file}
9762 (configuration file name) may be specified. See @command{lircd} manual
9763 for details.
9764
9765 Finally, @var{extra-options} is a list of additional command-line options
9766 passed to @command{lircd}.
9767 @end deffn
9768
9769 @subsubsection Dictionary Services
9770 The @code{(gnu services dict)} module provides the following service:
9771
9772 @deffn {Scheme Procedure} dicod-service [#:config (dicod-configuration)]
9773 Return a service that runs the @command{dicod} daemon, an implementation
9774 of DICT server (@pxref{Dicod,,, dico, GNU Dico Manual}).
9775
9776 The optional @var{config} argument specifies the configuration for
9777 @command{dicod}, which should be a @code{<dicod-configuration>} object, by
9778 default it serves the GNU Collaborative International Dictonary of English.
9779
9780 You can add @command{open localhost} to your @file{~/.dico} file to make
9781 @code{localhost} the default server for @command{dico} client
9782 (@pxref{Initialization File,,, dico, GNU Dico Manual}).
9783 @end deffn
9784
9785 @deftp {Data Type} dicod-configuration
9786 Data type representing the configuration of dicod.
9787
9788 @table @asis
9789 @item @code{dico} (default: @var{dico})
9790 Package object of the GNU Dico dictionary server.
9791
9792 @item @code{interfaces} (default: @var{'("localhost")})
9793 This is the list of IP addresses and ports and possibly socket file
9794 names to listen to (@pxref{Server Settings, @code{listen} directive,,
9795 dico, GNU Dico Manual}).
9796
9797 @item @code{databases} (default: @var{(list %dicod-database:gcide)})
9798 List of @code{<dicod-database>} objects denoting dictionaries to be served.
9799 @end table
9800 @end deftp
9801
9802 @deftp {Data Type} dicod-database
9803 Data type representing a dictionary database.
9804
9805 @table @asis
9806 @item @code{name}
9807 Name of the database, will be used in DICT commands.
9808
9809 @item @code{module}
9810 Name of the dicod module used by this database
9811 (@pxref{Modules,,, dico, GNU Dico Manual}).
9812
9813 @item @code{options}
9814 List of strings or gexps representing the arguments for the module handler
9815 (@pxref{Handlers,,, dico, GNU Dico Manual}).
9816 @end table
9817 @end deftp
9818
9819 @defvr {Scheme Variable} %dicod-database:gcide
9820 A @code{<dicod-database>} object serving the GNU Collaborative International
9821 Dictonary of English using the @code{gcide} package.
9822 @end defvr
9823
9824 @node Setuid Programs
9825 @subsection Setuid Programs
9826
9827 @cindex setuid programs
9828 Some programs need to run with ``root'' privileges, even when they are
9829 launched by unprivileged users. A notorious example is the
9830 @command{passwd} program, which users can run to change their
9831 password, and which needs to access the @file{/etc/passwd} and
9832 @file{/etc/shadow} files---something normally restricted to root, for
9833 obvious security reasons. To address that, these executables are
9834 @dfn{setuid-root}, meaning that they always run with root privileges
9835 (@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
9836 for more info about the setuid mechanism.)
9837
9838 The store itself @emph{cannot} contain setuid programs: that would be a
9839 security issue since any user on the system can write derivations that
9840 populate the store (@pxref{The Store}). Thus, a different mechanism is
9841 used: instead of changing the setuid bit directly on files that are in
9842 the store, we let the system administrator @emph{declare} which programs
9843 should be setuid root.
9844
9845 The @code{setuid-programs} field of an @code{operating-system}
9846 declaration contains a list of G-expressions denoting the names of
9847 programs to be setuid-root (@pxref{Using the Configuration System}).
9848 For instance, the @command{passwd} program, which is part of the Shadow
9849 package, can be designated by this G-expression (@pxref{G-Expressions}):
9850
9851 @example
9852 #~(string-append #$shadow "/bin/passwd")
9853 @end example
9854
9855 A default set of setuid programs is defined by the
9856 @code{%setuid-programs} variable of the @code{(gnu system)} module.
9857
9858 @defvr {Scheme Variable} %setuid-programs
9859 A list of G-expressions denoting common programs that are setuid-root.
9860
9861 The list includes commands such as @command{passwd}, @command{ping},
9862 @command{su}, and @command{sudo}.
9863 @end defvr
9864
9865 Under the hood, the actual setuid programs are created in the
9866 @file{/run/setuid-programs} directory at system activation time. The
9867 files in this directory refer to the ``real'' binaries, which are in the
9868 store.
9869
9870 @node X.509 Certificates
9871 @subsection X.509 Certificates
9872
9873 @cindex HTTPS, certificates
9874 @cindex X.509 certificates
9875 @cindex TLS
9876 Web servers available over HTTPS (that is, HTTP over the transport-layer
9877 security mechanism, TLS) send client programs an @dfn{X.509 certificate}
9878 that the client can then use to @emph{authenticate} the server. To do
9879 that, clients verify that the server's certificate is signed by a
9880 so-called @dfn{certificate authority} (CA). But to verify the CA's
9881 signature, clients must have first acquired the CA's certificate.
9882
9883 Web browsers such as GNU@tie{}IceCat include their own set of CA
9884 certificates, such that they are able to verify CA signatures
9885 out-of-the-box.
9886
9887 However, most other programs that can talk HTTPS---@command{wget},
9888 @command{git}, @command{w3m}, etc.---need to be told where CA
9889 certificates can be found.
9890
9891 @cindex @code{nss-certs}
9892 In GuixSD, this is done by adding a package that provides certificates
9893 to the @code{packages} field of the @code{operating-system} declaration
9894 (@pxref{operating-system Reference}). GuixSD includes one such package,
9895 @code{nss-certs}, which is a set of CA certificates provided as part of
9896 Mozilla's Network Security Services.
9897
9898 Note that it is @emph{not} part of @var{%base-packages}, so you need to
9899 explicitly add it. The @file{/etc/ssl/certs} directory, which is where
9900 most applications and libraries look for certificates by default, points
9901 to the certificates installed globally.
9902
9903 Unprivileged users, including users of Guix on a foreign distro,
9904 can also install their own certificate package in
9905 their profile. A number of environment variables need to be defined so
9906 that applications and libraries know where to find them. Namely, the
9907 OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
9908 variables. Some applications add their own environment variables; for
9909 instance, the Git version control system honors the certificate bundle
9910 pointed to by the @code{GIT_SSL_CAINFO} environment variable. Thus, you
9911 would typically run something like:
9912
9913 @example
9914 $ guix package -i nss-certs
9915 $ export SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs"
9916 $ export SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt"
9917 $ export GIT_SSL_CAINFO="$SSL_CERT_FILE"
9918 @end example
9919
9920 @node Name Service Switch
9921 @subsection Name Service Switch
9922
9923 @cindex name service switch
9924 @cindex NSS
9925 The @code{(gnu system nss)} module provides bindings to the
9926 configuration file of the libc @dfn{name service switch} or @dfn{NSS}
9927 (@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
9928 Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
9929 extended with new ``name'' lookup methods for system databases, which
9930 includes host names, service names, user accounts, and more (@pxref{Name
9931 Service Switch, System Databases and Name Service Switch,, libc, The GNU
9932 C Library Reference Manual}).
9933
9934 The NSS configuration specifies, for each system database, which lookup
9935 method is to be used, and how the various methods are chained
9936 together---for instance, under which circumstances NSS should try the
9937 next method in the list. The NSS configuration is given in the
9938 @code{name-service-switch} field of @code{operating-system} declarations
9939 (@pxref{operating-system Reference, @code{name-service-switch}}).
9940
9941 @cindex nss-mdns
9942 @cindex .local, host name lookup
9943 As an example, the declaration below configures the NSS to use the
9944 @uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
9945 back-end}, which supports host name lookups over multicast DNS (mDNS)
9946 for host names ending in @code{.local}:
9947
9948 @example
9949 (name-service-switch
9950 (hosts (list %files ;first, check /etc/hosts
9951
9952 ;; If the above did not succeed, try
9953 ;; with 'mdns_minimal'.
9954 (name-service
9955 (name "mdns_minimal")
9956
9957 ;; 'mdns_minimal' is authoritative for
9958 ;; '.local'. When it returns "not found",
9959 ;; no need to try the next methods.
9960 (reaction (lookup-specification
9961 (not-found => return))))
9962
9963 ;; Then fall back to DNS.
9964 (name-service
9965 (name "dns"))
9966
9967 ;; Finally, try with the "full" 'mdns'.
9968 (name-service
9969 (name "mdns")))))
9970 @end example
9971
9972 Do not worry: the @code{%mdns-host-lookup-nss} variable (see below)
9973 contains this configuration, so you will not have to type it if all you
9974 want is to have @code{.local} host lookup working.
9975
9976 Note that, in this case, in addition to setting the
9977 @code{name-service-switch} of the @code{operating-system} declaration,
9978 you also need to use @code{avahi-service} (@pxref{Networking Services,
9979 @code{avahi-service}}), or @var{%desktop-services}, which includes it
9980 (@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
9981 to the name service cache daemon (@pxref{Base Services,
9982 @code{nscd-service}}).
9983
9984 For convenience, the following variables provide typical NSS
9985 configurations.
9986
9987 @defvr {Scheme Variable} %default-nss
9988 This is the default name service switch configuration, a
9989 @code{name-service-switch} object.
9990 @end defvr
9991
9992 @defvr {Scheme Variable} %mdns-host-lookup-nss
9993 This is the name service switch configuration with support for host name
9994 lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
9995 @end defvr
9996
9997 The reference for name service switch configuration is given below. It
9998 is a direct mapping of the configuration file format of the C library , so
9999 please refer to the C library manual for more information (@pxref{NSS
10000 Configuration File,,, libc, The GNU C Library Reference Manual}).
10001 Compared to the configuration file format of libc NSS, it has the advantage
10002 not only of adding this warm parenthetic feel that we like, but also
10003 static checks: you will know about syntax errors and typos as soon as you
10004 run @command{guix system}.
10005
10006 @deftp {Data Type} name-service-switch
10007
10008 This is the data type representation the configuration of libc's name
10009 service switch (NSS). Each field below represents one of the supported
10010 system databases.
10011
10012 @table @code
10013 @item aliases
10014 @itemx ethers
10015 @itemx group
10016 @itemx gshadow
10017 @itemx hosts
10018 @itemx initgroups
10019 @itemx netgroup
10020 @itemx networks
10021 @itemx password
10022 @itemx public-key
10023 @itemx rpc
10024 @itemx services
10025 @itemx shadow
10026 The system databases handled by the NSS. Each of these fields must be a
10027 list of @code{<name-service>} objects (see below).
10028 @end table
10029 @end deftp
10030
10031 @deftp {Data Type} name-service
10032
10033 This is the data type representing an actual name service and the
10034 associated lookup action.
10035
10036 @table @code
10037 @item name
10038 A string denoting the name service (@pxref{Services in the NSS
10039 configuration,,, libc, The GNU C Library Reference Manual}).
10040
10041 Note that name services listed here must be visible to nscd. This is
10042 achieved by passing the @code{#:name-services} argument to
10043 @code{nscd-service} the list of packages providing the needed name
10044 services (@pxref{Base Services, @code{nscd-service}}).
10045
10046 @item reaction
10047 An action specified using the @code{lookup-specification} macro
10048 (@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
10049 Reference Manual}). For example:
10050
10051 @example
10052 (lookup-specification (unavailable => continue)
10053 (success => return))
10054 @end example
10055 @end table
10056 @end deftp
10057
10058 @node Initial RAM Disk
10059 @subsection Initial RAM Disk
10060
10061 @cindex initial RAM disk (initrd)
10062 @cindex initrd (initial RAM disk)
10063 For bootstrapping purposes, the Linux-Libre kernel is passed an
10064 @dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
10065 root file system as well as an initialization script. The latter is
10066 responsible for mounting the real root file system, and for loading any
10067 kernel modules that may be needed to achieve that.
10068
10069 The @code{initrd} field of an @code{operating-system} declaration allows
10070 you to specify which initrd you would like to use. The @code{(gnu
10071 system linux-initrd)} module provides two ways to build an initrd: the
10072 high-level @code{base-initrd} procedure, and the low-level
10073 @code{expression->initrd} procedure.
10074
10075 The @code{base-initrd} procedure is intended to cover most common uses.
10076 For example, if you want to add a bunch of kernel modules to be loaded
10077 at boot time, you can define the @code{initrd} field of the operating
10078 system declaration like this:
10079
10080 @example
10081 (initrd (lambda (file-systems . rest)
10082 ;; Create a standard initrd that has modules "foo.ko"
10083 ;; and "bar.ko", as well as their dependencies, in
10084 ;; addition to the modules available by default.
10085 (apply base-initrd file-systems
10086 #:extra-modules '("foo" "bar")
10087 rest)))
10088 @end example
10089
10090 The @code{base-initrd} procedure also handles common use cases that
10091 involves using the system as a QEMU guest, or as a ``live'' system with
10092 volatile root file system.
10093
10094 The initial RAM disk produced by @code{base-initrd} honors several
10095 options passed on the Linux kernel command line (that is, arguments
10096 passed @i{via} the @code{linux} command of GRUB, or the
10097 @code{-append} option) of QEMU, notably:
10098
10099 @table @code
10100 @item --load=@var{boot}
10101 Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
10102 program, once it has mounted the root file system.
10103
10104 GuixSD uses this option to yield control to a boot program that runs the
10105 service activation programs and then spawns the GNU@tie{}Shepherd, the
10106 initialization system.
10107
10108 @item --root=@var{root}
10109 Mount @var{root} as the root file system. @var{root} can be a
10110 device name like @code{/dev/sda1}, a partition label, or a partition
10111 UUID.
10112
10113 @item --system=@var{system}
10114 Have @file{/run/booted-system} and @file{/run/current-system} point to
10115 @var{system}.
10116
10117 @item modprobe.blacklist=@var{modules}@dots{}
10118 @cindex module, black-listing
10119 @cindex black list, of kernel modules
10120 Instruct the initial RAM disk as well as the @command{modprobe} command
10121 (from the kmod package) to refuse to load @var{modules}. @var{modules}
10122 must be a comma-separated list of module names---e.g.,
10123 @code{usbkbd,9pnet}.
10124
10125 @item --repl
10126 Start a read-eval-print loop (REPL) from the initial RAM disk before it
10127 tries to load kernel modules and to mount the root file system. Our
10128 marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
10129 love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
10130 Manual}, for more information on Guile's REPL.
10131
10132 @end table
10133
10134 Now that you know all the features that initial RAM disks produced by
10135 @code{base-initrd} provide, here is how to use it and customize it
10136 further.
10137
10138 @deffn {Monadic Procedure} base-initrd @var{file-systems} @
10139 [#:qemu-networking? #f] [#:virtio? #t] [#:volatile-root? #f] @
10140 [#:extra-modules '()] [#:mapped-devices '()]
10141 Return a monadic derivation that builds a generic initrd. @var{file-systems} is
10142 a list of file systems to be mounted by the initrd, possibly in addition to
10143 the root file system specified on the kernel command line via @code{--root}.
10144 @var{mapped-devices} is a list of device mappings to realize before
10145 @var{file-systems} are mounted (@pxref{Mapped Devices}).
10146
10147 When @var{qemu-networking?} is true, set up networking with the standard QEMU
10148 parameters. When @var{virtio?} is true, load additional modules so that the
10149 initrd can be used as a QEMU guest with para-virtualized I/O drivers.
10150
10151 When @var{volatile-root?} is true, the root file system is writable but any changes
10152 to it are lost.
10153
10154 The initrd is automatically populated with all the kernel modules necessary
10155 for @var{file-systems} and for the given options. However, additional kernel
10156 modules can be listed in @var{extra-modules}. They will be added to the initrd, and
10157 loaded at boot time in the order in which they appear.
10158 @end deffn
10159
10160 Needless to say, the initrds we produce and use embed a
10161 statically-linked Guile, and the initialization program is a Guile
10162 program. That gives a lot of flexibility. The
10163 @code{expression->initrd} procedure builds such an initrd, given the
10164 program to run in that initrd.
10165
10166 @deffn {Monadic Procedure} expression->initrd @var{exp} @
10167 [#:guile %guile-static-stripped] [#:name "guile-initrd"]
10168 Return a derivation that builds a Linux initrd (a gzipped cpio archive)
10169 containing @var{guile} and that evaluates @var{exp}, a G-expression,
10170 upon booting. All the derivations referenced by @var{exp} are
10171 automatically copied to the initrd.
10172 @end deffn
10173
10174 @node GRUB Configuration
10175 @subsection GRUB Configuration
10176
10177 @cindex GRUB
10178 @cindex boot loader
10179
10180 The operating system uses GNU@tie{}GRUB as its boot loader
10181 (@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
10182 configured using a @code{grub-configuration} declaration. This data type
10183 is exported by the @code{(gnu system grub)} module and described below.
10184
10185 @deftp {Data Type} grub-configuration
10186 The type of a GRUB configuration declaration.
10187
10188 @table @asis
10189
10190 @item @code{device}
10191 This is a string denoting the boot device. It must be a device name
10192 understood by the @command{grub-install} command, such as
10193 @code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
10194 GNU GRUB Manual}).
10195
10196 @item @code{menu-entries} (default: @code{()})
10197 A possibly empty list of @code{menu-entry} objects (see below), denoting
10198 entries to appear in the GRUB boot menu, in addition to the current
10199 system entry and the entry pointing to previous system generations.
10200
10201 @item @code{default-entry} (default: @code{0})
10202 The index of the default boot menu entry. Index 0 is for the entry of the
10203 current system.
10204
10205 @item @code{timeout} (default: @code{5})
10206 The number of seconds to wait for keyboard input before booting. Set to
10207 0 to boot immediately, and to -1 to wait indefinitely.
10208
10209 @item @code{theme} (default: @var{%default-theme})
10210 The @code{grub-theme} object describing the theme to use.
10211 @end table
10212
10213 @end deftp
10214
10215 Should you want to list additional boot menu entries @i{via} the
10216 @code{menu-entries} field above, you will need to create them with the
10217 @code{menu-entry} form:
10218
10219 @deftp {Data Type} menu-entry
10220 The type of an entry in the GRUB boot menu.
10221
10222 @table @asis
10223
10224 @item @code{label}
10225 The label to show in the menu---e.g., @code{"GNU"}.
10226
10227 @item @code{linux}
10228 The Linux kernel to boot.
10229
10230 @item @code{linux-arguments} (default: @code{()})
10231 The list of extra Linux kernel command-line arguments---e.g.,
10232 @code{("console=ttyS0")}.
10233
10234 @item @code{initrd}
10235 A G-Expression or string denoting the file name of the initial RAM disk
10236 to use (@pxref{G-Expressions}).
10237
10238 @end table
10239 @end deftp
10240
10241 @c FIXME: Write documentation once it's stable.
10242 Themes are created using the @code{grub-theme} form, which is not
10243 documented yet.
10244
10245 @defvr {Scheme Variable} %default-theme
10246 This is the default GRUB theme used by the operating system, with a
10247 fancy background image displaying the GNU and Guix logos.
10248 @end defvr
10249
10250
10251 @node Invoking guix system
10252 @subsection Invoking @code{guix system}
10253
10254 Once you have written an operating system declaration as seen in the
10255 previous section, it can be @dfn{instantiated} using the @command{guix
10256 system} command. The synopsis is:
10257
10258 @example
10259 guix system @var{options}@dots{} @var{action} @var{file}
10260 @end example
10261
10262 @var{file} must be the name of a file containing an
10263 @code{operating-system} declaration. @var{action} specifies how the
10264 operating system is instantiated. Currently the following values are
10265 supported:
10266
10267 @table @code
10268 @item reconfigure
10269 Build the operating system described in @var{file}, activate it, and
10270 switch to it@footnote{This action is usable only on systems already
10271 running GuixSD.}.
10272
10273 This effects all the configuration specified in @var{file}: user
10274 accounts, system services, global package list, setuid programs, etc.
10275 The command starts system services specified in @var{file} that are not
10276 currently running; if a service is currently running, it does not
10277 attempt to upgrade it since this would not be possible without stopping it
10278 first.
10279
10280 It also adds a GRUB menu entry for the new OS configuration, and moves
10281 entries for older configurations to a submenu---unless
10282 @option{--no-grub} is passed.
10283
10284 @quotation Note
10285 @c The paragraph below refers to the problem discussed at
10286 @c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
10287 It is highly recommended to run @command{guix pull} once before you run
10288 @command{guix system reconfigure} for the first time (@pxref{Invoking
10289 guix pull}). Failing to do that you would see an older version of Guix
10290 once @command{reconfigure} has completed.
10291 @end quotation
10292
10293 @item build
10294 Build the derivation of the operating system, which includes all the
10295 configuration files and programs needed to boot and run the system.
10296 This action does not actually install anything.
10297
10298 @item init
10299 Populate the given directory with all the files necessary to run the
10300 operating system specified in @var{file}. This is useful for first-time
10301 installations of GuixSD. For instance:
10302
10303 @example
10304 guix system init my-os-config.scm /mnt
10305 @end example
10306
10307 copies to @file{/mnt} all the store items required by the configuration
10308 specified in @file{my-os-config.scm}. This includes configuration
10309 files, packages, and so on. It also creates other essential files
10310 needed for the system to operate correctly---e.g., the @file{/etc},
10311 @file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
10312
10313 This command also installs GRUB on the device specified in
10314 @file{my-os-config}, unless the @option{--no-grub} option was passed.
10315
10316 @item vm
10317 @cindex virtual machine
10318 @cindex VM
10319 @anchor{guix system vm}
10320 Build a virtual machine that contains the operating system declared in
10321 @var{file}, and return a script to run that virtual machine (VM).
10322 Arguments given to the script are passed to QEMU.
10323
10324 The VM shares its store with the host system.
10325
10326 Additional file systems can be shared between the host and the VM using
10327 the @code{--share} and @code{--expose} command-line options: the former
10328 specifies a directory to be shared with write access, while the latter
10329 provides read-only access to the shared directory.
10330
10331 The example below creates a VM in which the user's home directory is
10332 accessible read-only, and where the @file{/exchange} directory is a
10333 read-write mapping of @file{$HOME/tmp} on the host:
10334
10335 @example
10336 guix system vm my-config.scm \
10337 --expose=$HOME --share=$HOME/tmp=/exchange
10338 @end example
10339
10340 On GNU/Linux, the default is to boot directly to the kernel; this has
10341 the advantage of requiring only a very tiny root disk image since the
10342 store of the host can then be mounted.
10343
10344 The @code{--full-boot} option forces a complete boot sequence, starting
10345 with the bootloader. This requires more disk space since a root image
10346 containing at least the kernel, initrd, and bootloader data files must
10347 be created. The @code{--image-size} option can be used to specify the
10348 size of the image.
10349
10350 @item vm-image
10351 @itemx disk-image
10352 Return a virtual machine or disk image of the operating system declared
10353 in @var{file} that stands alone. Use the @option{--image-size} option
10354 to specify the size of the image.
10355
10356 When using @code{vm-image}, the returned image is in qcow2 format, which
10357 the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
10358 for more information on how to run the image in a virtual machine.
10359
10360 When using @code{disk-image}, a raw disk image is produced; it can be
10361 copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
10362 the device corresponding to a USB stick, one can copy the image to it
10363 using the following command:
10364
10365 @example
10366 # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
10367 @end example
10368
10369 @item container
10370 Return a script to run the operating system declared in @var{file}
10371 within a container. Containers are a set of lightweight isolation
10372 mechanisms provided by the kernel Linux-libre. Containers are
10373 substantially less resource-demanding than full virtual machines since
10374 the kernel, shared objects, and other resources can be shared with the
10375 host system; this also means they provide thinner isolation.
10376
10377 Currently, the script must be run as root in order to support more than
10378 a single user and group. The container shares its store with the host
10379 system.
10380
10381 As with the @code{vm} action (@pxref{guix system vm}), additional file
10382 systems to be shared between the host and container can be specified
10383 using the @option{--share} and @option{--expose} options:
10384
10385 @example
10386 guix system container my-config.scm \
10387 --expose=$HOME --share=$HOME/tmp=/exchange
10388 @end example
10389
10390 @quotation Note
10391 This option requires Linux-libre 3.19 or newer.
10392 @end quotation
10393
10394 @end table
10395
10396 @var{options} can contain any of the common build options (@pxref{Common
10397 Build Options}). In addition, @var{options} can contain one of the
10398 following:
10399
10400 @table @option
10401 @item --system=@var{system}
10402 @itemx -s @var{system}
10403 Attempt to build for @var{system} instead of the host system type.
10404 This works as per @command{guix build} (@pxref{Invoking guix build}).
10405
10406 @item --derivation
10407 @itemx -d
10408 Return the derivation file name of the given operating system without
10409 building anything.
10410
10411 @item --image-size=@var{size}
10412 For the @code{vm-image} and @code{disk-image} actions, create an image
10413 of the given @var{size}. @var{size} may be a number of bytes, or it may
10414 include a unit as a suffix (@pxref{Block size, size specifications,,
10415 coreutils, GNU Coreutils}).
10416
10417 @item --on-error=@var{strategy}
10418 Apply @var{strategy} when an error occurs when reading @var{file}.
10419 @var{strategy} may be one of the following:
10420
10421 @table @code
10422 @item nothing-special
10423 Report the error concisely and exit. This is the default strategy.
10424
10425 @item backtrace
10426 Likewise, but also display a backtrace.
10427
10428 @item debug
10429 Report the error and enter Guile's debugger. From there, you can run
10430 commands such as @code{,bt} to get a backtrace, @code{,locals} to
10431 display local variable values, and more generally inspect the state of the
10432 program. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
10433 a list of available debugging commands.
10434 @end table
10435 @end table
10436
10437 @quotation Note
10438 All the actions above, except @code{build} and @code{init},
10439 can use KVM support in the Linux-libre kernel. Specifically, if the
10440 machine has hardware virtualization support, the corresponding
10441 KVM kernel module should be loaded, and the @file{/dev/kvm} device node
10442 must exist and be readable and writable by the user and by the
10443 build users of the daemon (@pxref{Build Environment Setup}).
10444 @end quotation
10445
10446 Once you have built, configured, re-configured, and re-re-configured
10447 your GuixSD installation, you may find it useful to list the operating
10448 system generations available on disk---and that you can choose from the
10449 GRUB boot menu:
10450
10451 @table @code
10452
10453 @item list-generations
10454 List a summary of each generation of the operating system available on
10455 disk, in a human-readable way. This is similar to the
10456 @option{--list-generations} option of @command{guix package}
10457 (@pxref{Invoking guix package}).
10458
10459 Optionally, one can specify a pattern, with the same syntax that is used
10460 in @command{guix package --list-generations}, to restrict the list of
10461 generations displayed. For instance, the following command displays
10462 generations that are up to 10 days old:
10463
10464 @example
10465 $ guix system list-generations 10d
10466 @end example
10467
10468 @end table
10469
10470 The @command{guix system} command has even more to offer! The following
10471 sub-commands allow you to visualize how your system services relate to
10472 each other:
10473
10474 @anchor{system-extension-graph}
10475 @table @code
10476
10477 @item extension-graph
10478 Emit in Dot/Graphviz format to standard output the @dfn{service
10479 extension graph} of the operating system defined in @var{file}
10480 (@pxref{Service Composition}, for more information on service
10481 extensions.)
10482
10483 The command:
10484
10485 @example
10486 $ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
10487 @end example
10488
10489 produces a PDF file showing the extension relations among services.
10490
10491 @anchor{system-shepherd-graph}
10492 @item shepherd-graph
10493 Emit in Dot/Graphviz format to standard output the @dfn{dependency
10494 graph} of shepherd services of the operating system defined in
10495 @var{file}. @xref{Shepherd Services}, for more information and for an
10496 example graph.
10497
10498 @end table
10499
10500 @node Running GuixSD in a VM
10501 @subsection Running GuixSD in a Virtual Machine
10502
10503 One way to run GuixSD in a virtual machine (VM) is to build a GuixSD
10504 virtual machine image using @command{guix system vm-image}
10505 (@pxref{Invoking guix system}). The returned image is in qcow2 format,
10506 which the @uref{http://qemu.org/, QEMU emulator} can efficiently use.
10507
10508 To run the image in QEMU, copy it out of the store (@pxref{The Store})
10509 and give yourself permission to write to the copy. When invoking QEMU,
10510 you must choose a system emulator that is suitable for your hardware
10511 platform. Here is a minimal QEMU invocation that will boot the result
10512 of @command{guix system vm-image} on x86_64 hardware:
10513
10514 @example
10515 $ qemu-system-x86_64 \
10516 -net user -net nic,model=virtio \
10517 -enable-kvm -m 256 /tmp/qemu-image
10518 @end example
10519
10520 Here is what each of these options means:
10521
10522 @table @code
10523 @item qemu-system-x86_64
10524 This specifies the hardware platform to emulate. This should match the
10525 host.
10526
10527 @item -net user
10528 Enable the unprivileged user-mode network stack. The guest OS can
10529 access the host but not vice versa. This is the simplest way to get the
10530 guest OS online. If you do not choose a network stack, the boot will
10531 fail.
10532
10533 @item -net nic,model=virtio
10534 You must create a network interface of a given model. If you do not
10535 create a NIC, the boot will fail. Assuming your hardware platform is
10536 x86_64, you can get a list of available NIC models by running
10537 @command{qemu-system-x86_64 -net nic,model=help}.
10538
10539 @item -enable-kvm
10540 If your system has hardware virtualization extensions, enabling the
10541 virtual machine support (KVM) of the Linux kernel will make things run
10542 faster.
10543
10544 @item -m 256
10545 RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
10546 which may be insufficent for some operations.
10547
10548 @item /tmp/qemu-image
10549 The file name of the qcow2 image.
10550 @end table
10551
10552 @node Defining Services
10553 @subsection Defining Services
10554
10555 The previous sections show the available services and how one can combine
10556 them in an @code{operating-system} declaration. But how do we define
10557 them in the first place? And what is a service anyway?
10558
10559 @menu
10560 * Service Composition:: The model for composing services.
10561 * Service Types and Services:: Types and services.
10562 * Service Reference:: API reference.
10563 * Shepherd Services:: A particular type of service.
10564 @end menu
10565
10566 @node Service Composition
10567 @subsubsection Service Composition
10568
10569 @cindex services
10570 @cindex daemons
10571 Here we define a @dfn{service} as, broadly, something that extends the
10572 functionality of the operating system. Often a service is a process---a
10573 @dfn{daemon}---started when the system boots: a secure shell server, a
10574 Web server, the Guix build daemon, etc. Sometimes a service is a daemon
10575 whose execution can be triggered by another daemon---e.g., an FTP server
10576 started by @command{inetd} or a D-Bus service activated by
10577 @command{dbus-daemon}. Occasionally, a service does not map to a
10578 daemon. For instance, the ``account'' service collects user accounts
10579 and makes sure they exist when the system runs; the ``udev'' service
10580 collects device management rules and makes them available to the eudev
10581 daemon; the @file{/etc} service populates the @file{/etc} directory
10582 of the system.
10583
10584 @cindex service extensions
10585 GuixSD services are connected by @dfn{extensions}. For instance, the
10586 secure shell service @emph{extends} the Shepherd---the GuixSD
10587 initialization system, running as PID@tie{}1---by giving it the command
10588 lines to start and stop the secure shell daemon (@pxref{Networking
10589 Services, @code{lsh-service}}); the UPower service extends the D-Bus
10590 service by passing it its @file{.service} specification, and extends the
10591 udev service by passing it device management rules (@pxref{Desktop
10592 Services, @code{upower-service}}); the Guix daemon service extends the
10593 Shepherd by passing it the command lines to start and stop the daemon,
10594 and extends the account service by passing it a list of required build
10595 user accounts (@pxref{Base Services}).
10596
10597 All in all, services and their ``extends'' relations form a directed
10598 acyclic graph (DAG). If we represent services as boxes and extensions
10599 as arrows, a typical system might provide something like this:
10600
10601 @image{images/service-graph,,5in,Typical service extension graph.}
10602
10603 @cindex system service
10604 At the bottom, we see the @dfn{system service}, which produces the
10605 directory containing everything to run and boot the system, as returned
10606 by the @command{guix system build} command. @xref{Service Reference},
10607 to learn about the other service types shown here.
10608 @xref{system-extension-graph, the @command{guix system extension-graph}
10609 command}, for information on how to generate this representation for a
10610 particular operating system definition.
10611
10612 @cindex service types
10613 Technically, developers can define @dfn{service types} to express these
10614 relations. There can be any number of services of a given type on the
10615 system---for instance, a system running two instances of the GNU secure
10616 shell server (lsh) has two instances of @var{lsh-service-type}, with
10617 different parameters.
10618
10619 The following section describes the programming interface for service
10620 types and services.
10621
10622 @node Service Types and Services
10623 @subsubsection Service Types and Services
10624
10625 A @dfn{service type} is a node in the DAG described above. Let us start
10626 with a simple example, the service type for the Guix build daemon
10627 (@pxref{Invoking guix-daemon}):
10628
10629 @example
10630 (define guix-service-type
10631 (service-type
10632 (name 'guix)
10633 (extensions
10634 (list (service-extension shepherd-root-service-type guix-shepherd-service)
10635 (service-extension account-service-type guix-accounts)
10636 (service-extension activation-service-type guix-activation)))))
10637 @end example
10638
10639 @noindent
10640 It defines two things:
10641
10642 @enumerate
10643 @item
10644 A name, whose sole purpose is to make inspection and debugging easier.
10645
10646 @item
10647 A list of @dfn{service extensions}, where each extension designates the
10648 target service type and a procedure that, given the parameters of the
10649 service, returns a list of objects to extend the service of that type.
10650
10651 Every service type has at least one service extension. The only
10652 exception is the @dfn{boot service type}, which is the ultimate service.
10653 @end enumerate
10654
10655 In this example, @var{guix-service-type} extends three services:
10656
10657 @table @var
10658 @item shepherd-root-service-type
10659 The @var{guix-shepherd-service} procedure defines how the Shepherd
10660 service is extended. Namely, it returns a @code{<shepherd-service>}
10661 object that defines how @command{guix-daemon} is started and stopped
10662 (@pxref{Shepherd Services}).
10663
10664 @item account-service-type
10665 This extension for this service is computed by @var{guix-accounts},
10666 which returns a list of @code{user-group} and @code{user-account}
10667 objects representing the build user accounts (@pxref{Invoking
10668 guix-daemon}).
10669
10670 @item activation-service-type
10671 Here @var{guix-activation} is a procedure that returns a gexp, which is
10672 a code snippet to run at ``activation time''---e.g., when the service is
10673 booted.
10674 @end table
10675
10676 A service of this type is instantiated like this:
10677
10678 @example
10679 (service guix-service-type
10680 (guix-configuration
10681 (build-accounts 5)
10682 (use-substitutes? #f)))
10683 @end example
10684
10685 The second argument to the @code{service} form is a value representing
10686 the parameters of this specific service instance.
10687 @xref{guix-configuration-type, @code{guix-configuration}}, for
10688 information about the @code{guix-configuration} data type.
10689
10690 @var{guix-service-type} is quite simple because it extends other
10691 services but is not extensible itself.
10692
10693 @c @subsubsubsection Extensible Service Types
10694
10695 The service type for an @emph{extensible} service looks like this:
10696
10697 @example
10698 (define udev-service-type
10699 (service-type (name 'udev)
10700 (extensions
10701 (list (service-extension shepherd-root-service-type
10702 udev-shepherd-service)))
10703
10704 (compose concatenate) ;concatenate the list of rules
10705 (extend (lambda (config rules)
10706 (match config
10707 (($ <udev-configuration> udev initial-rules)
10708 (udev-configuration
10709 (udev udev) ;the udev package to use
10710 (rules (append initial-rules rules)))))))))
10711 @end example
10712
10713 This is the service type for the
10714 @uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
10715 management daemon}. Compared to the previous example, in addition to an
10716 extension of @var{shepherd-root-service-type}, we see two new fields:
10717
10718 @table @code
10719 @item compose
10720 This is the procedure to @dfn{compose} the list of extensions to
10721 services of this type.
10722
10723 Services can extend the udev service by passing it lists of rules; we
10724 compose those extensions simply by concatenating them.
10725
10726 @item extend
10727 This procedure defines how the value of the service is @dfn{extended} with
10728 the composition of the extensions.
10729
10730 Udev extensions are composed into a list of rules, but the udev service
10731 value is itself a @code{<udev-configuration>} record. So here, we
10732 extend that record by appending the list of rules it contains to the
10733 list of contributed rules.
10734 @end table
10735
10736 There can be only one instance of an extensible service type such as
10737 @var{udev-service-type}. If there were more, the
10738 @code{service-extension} specifications would be ambiguous.
10739
10740 Still here? The next section provides a reference of the programming
10741 interface for services.
10742
10743 @node Service Reference
10744 @subsubsection Service Reference
10745
10746 We have seen an overview of service types (@pxref{Service Types and
10747 Services}). This section provides a reference on how to manipulate
10748 services and service types. This interface is provided by the
10749 @code{(gnu services)} module.
10750
10751 @deffn {Scheme Procedure} service @var{type} @var{value}
10752 Return a new service of @var{type}, a @code{<service-type>} object (see
10753 below.) @var{value} can be any object; it represents the parameters of
10754 this particular service instance.
10755 @end deffn
10756
10757 @deffn {Scheme Procedure} service? @var{obj}
10758 Return true if @var{obj} is a service.
10759 @end deffn
10760
10761 @deffn {Scheme Procedure} service-kind @var{service}
10762 Return the type of @var{service}---i.e., a @code{<service-type>} object.
10763 @end deffn
10764
10765 @deffn {Scheme Procedure} service-parameters @var{service}
10766 Return the value associated with @var{service}. It represents its
10767 parameters.
10768 @end deffn
10769
10770 Here is an example of how a service is created and manipulated:
10771
10772 @example
10773 (define s
10774 (service nginx-service-type
10775 (nginx-configuration
10776 (nginx nginx)
10777 (log-directory log-directory)
10778 (run-directory run-directory)
10779 (file config-file))))
10780
10781 (service? s)
10782 @result{} #t
10783
10784 (eq? (service-kind s) nginx-service-type)
10785 @result{} #t
10786 @end example
10787
10788 The @code{modify-services} form provides a handy way to change the
10789 parameters of some of the services of a list such as
10790 @var{%base-services} (@pxref{Base Services, @code{%base-services}}). It
10791 evalutes to a list of services. Of course, you could always use
10792 standard list combinators such as @code{map} and @code{fold} to do that
10793 (@pxref{SRFI-1, List Library,, guile, GNU Guile Reference Manual});
10794 @code{modify-services} simply provides a more concise form for this
10795 common pattern.
10796
10797 @deffn {Scheme Syntax} modify-services @var{services} @
10798 (@var{type} @var{variable} => @var{body}) @dots{}
10799
10800 Modify the services listed in @var{services} according to the given
10801 clauses. Each clause has the form:
10802
10803 @example
10804 (@var{type} @var{variable} => @var{body})
10805 @end example
10806
10807 where @var{type} is a service type---e.g.,
10808 @code{guix-service-type}---and @var{variable} is an identifier that is
10809 bound within the @var{body} to the service parameters---e.g., a
10810 @code{guix-configuration} instance---of the original service of that
10811 @var{type}.
10812
10813 The @var{body} should evaluate to the new service parameters, which will
10814 be used to configure the new service. This new service will replace the
10815 original in the resulting list. Because a service's service parameters
10816 are created using @code{define-record-type*}, you can write a succint
10817 @var{body} that evaluates to the new service parameters by using the
10818 @code{inherit} feature that @code{define-record-type*} provides.
10819
10820 @xref{Using the Configuration System}, for example usage.
10821
10822 @end deffn
10823
10824 Next comes the programming interface for service types. This is
10825 something you want to know when writing new service definitions, but not
10826 necessarily when simply looking for ways to customize your
10827 @code{operating-system} declaration.
10828
10829 @deftp {Data Type} service-type
10830 @cindex service type
10831 This is the representation of a @dfn{service type} (@pxref{Service Types
10832 and Services}).
10833
10834 @table @asis
10835 @item @code{name}
10836 This is a symbol, used only to simplify inspection and debugging.
10837
10838 @item @code{extensions}
10839 A non-empty list of @code{<service-extension>} objects (see below).
10840
10841 @item @code{compose} (default: @code{#f})
10842 If this is @code{#f}, then the service type denotes services that cannot
10843 be extended---i.e., services that do not receive ``values'' from other
10844 services.
10845
10846 Otherwise, it must be a one-argument procedure. The procedure is called
10847 by @code{fold-services} and is passed a list of values collected from
10848 extensions. It must return a value that is a valid parameter value for
10849 the service instance.
10850
10851 @item @code{extend} (default: @code{#f})
10852 If this is @code{#f}, services of this type cannot be extended.
10853
10854 Otherwise, it must be a two-argument procedure: @code{fold-services}
10855 calls it, passing it the initial value of the service as the first argument
10856 and the result of applying @code{compose} to the extension values as the
10857 second argument.
10858 @end table
10859
10860 @xref{Service Types and Services}, for examples.
10861 @end deftp
10862
10863 @deffn {Scheme Procedure} service-extension @var{target-type} @
10864 @var{compute}
10865 Return a new extension for services of type @var{target-type}.
10866 @var{compute} must be a one-argument procedure: @code{fold-services}
10867 calls it, passing it the value associated with the service that provides
10868 the extension; it must return a valid value for the target service.
10869 @end deffn
10870
10871 @deffn {Scheme Procedure} service-extension? @var{obj}
10872 Return true if @var{obj} is a service extension.
10873 @end deffn
10874
10875 At the core of the service abstraction lies the @code{fold-services}
10876 procedure, which is responsible for ``compiling'' a list of services
10877 down to a single directory that contains everything needed to boot and
10878 run the system---the directory shown by the @command{guix system build}
10879 command (@pxref{Invoking guix system}). In essence, it propagates
10880 service extensions down the service graph, updating each node parameters
10881 on the way, until it reaches the root node.
10882
10883 @deffn {Scheme Procedure} fold-services @var{services} @
10884 [#:target-type @var{system-service-type}]
10885 Fold @var{services} by propagating their extensions down to the root of
10886 type @var{target-type}; return the root service adjusted accordingly.
10887 @end deffn
10888
10889 Lastly, the @code{(gnu services)} module also defines several essential
10890 service types, some of which are listed below.
10891
10892 @defvr {Scheme Variable} system-service-type
10893 This is the root of the service graph. It produces the system directory
10894 as returned by the @command{guix system build} command.
10895 @end defvr
10896
10897 @defvr {Scheme Variable} boot-service-type
10898 The type of the ``boot service'', which produces the @dfn{boot script}.
10899 The boot script is what the initial RAM disk runs when booting.
10900 @end defvr
10901
10902 @defvr {Scheme Variable} etc-service-type
10903 The type of the @file{/etc} service. This service can be extended by
10904 passing it name/file tuples such as:
10905
10906 @example
10907 (list `("issue" ,(plain-file "issue" "Welcome!\n")))
10908 @end example
10909
10910 In this example, the effect would be to add an @file{/etc/issue} file
10911 pointing to the given file.
10912 @end defvr
10913
10914 @defvr {Scheme Variable} setuid-program-service-type
10915 Type for the ``setuid-program service''. This service collects lists of
10916 executable file names, passed as gexps, and adds them to the set of
10917 setuid-root programs on the system (@pxref{Setuid Programs}).
10918 @end defvr
10919
10920 @defvr {Scheme Variable} profile-service-type
10921 Type of the service that populates the @dfn{system profile}---i.e., the
10922 programs under @file{/run/current-system/profile}. Other services can
10923 extend it by passing it lists of packages to add to the system profile.
10924 @end defvr
10925
10926
10927 @node Shepherd Services
10928 @subsubsection Shepherd Services
10929
10930 @cindex PID 1
10931 @cindex init system
10932 The @code{(gnu services shepherd)} module provides a way to define
10933 services managed by the GNU@tie{}Shepherd, which is the GuixSD
10934 initialization system---the first process that is started when the
10935 system boots, also known as PID@tie{}1
10936 (@pxref{Introduction,,, shepherd, The GNU Shepherd Manual}).
10937
10938 Services in the Shepherd can depend on each other. For instance, the
10939 SSH daemon may need to be started after the syslog daemon has been
10940 started, which in turn can only happen once all the file systems have
10941 been mounted. The simple operating system defined earlier (@pxref{Using
10942 the Configuration System}) results in a service graph like this:
10943
10944 @image{images/shepherd-graph,,5in,Typical shepherd service graph.}
10945
10946 You can actually generate such a graph for any operating system
10947 definition using the @command{guix system shepherd-graph} command
10948 (@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
10949
10950 The @var{%shepherd-root-service} is a service object representing
10951 PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
10952 by passing it lists of @code{<shepherd-service>} objects.
10953
10954 @deftp {Data Type} shepherd-service
10955 The data type representing a service managed by the Shepherd.
10956
10957 @table @asis
10958 @item @code{provision}
10959 This is a list of symbols denoting what the service provides.
10960
10961 These are the names that may be passed to @command{herd start},
10962 @command{herd status}, and similar commands (@pxref{Invoking herd,,,
10963 shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
10964 @code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
10965
10966 @item @code{requirements} (default: @code{'()})
10967 List of symbols denoting the Shepherd services this one depends on.
10968
10969 @item @code{respawn?} (default: @code{#t})
10970 Whether to restart the service when it stops, for instance when the
10971 underlying process dies.
10972
10973 @item @code{start}
10974 @itemx @code{stop} (default: @code{#~(const #f)})
10975 The @code{start} and @code{stop} fields refer to the Shepherd's
10976 facilities to start and stop processes (@pxref{Service De- and
10977 Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
10978 G-expressions that get expanded in the Shepherd configuration file
10979 (@pxref{G-Expressions}).
10980
10981 @item @code{documentation}
10982 A documentation string, as shown when running:
10983
10984 @example
10985 herd doc @var{service-name}
10986 @end example
10987
10988 where @var{service-name} is one of the symbols in @var{provision}
10989 (@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
10990
10991 @item @code{modules} (default: @var{%default-modules})
10992 This is the list of modules that must be in scope when @code{start} and
10993 @code{stop} are evaluated.
10994
10995 @end table
10996 @end deftp
10997
10998 @defvr {Scheme Variable} shepherd-root-service-type
10999 The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
11000
11001 This is the service type that extensions target when they want to create
11002 shepherd services (@pxref{Service Types and Services}, for an example).
11003 Each extension must pass a list of @code{<shepherd-service>}.
11004 @end defvr
11005
11006 @defvr {Scheme Variable} %shepherd-root-service
11007 This service represents PID@tie{}1.
11008 @end defvr
11009
11010
11011 @node Installing Debugging Files
11012 @section Installing Debugging Files
11013
11014 @cindex debugging files
11015 Program binaries, as produced by the GCC compilers for instance, are
11016 typically written in the ELF format, with a section containing
11017 @dfn{debugging information}. Debugging information is what allows the
11018 debugger, GDB, to map binary code to source code; it is required to
11019 debug a compiled program in good conditions.
11020
11021 The problem with debugging information is that is takes up a fair amount
11022 of disk space. For example, debugging information for the GNU C Library
11023 weighs in at more than 60 MiB. Thus, as a user, keeping all the
11024 debugging info of all the installed programs is usually not an option.
11025 Yet, space savings should not come at the cost of an impediment to
11026 debugging---especially in the GNU system, which should make it easier
11027 for users to exert their computing freedom (@pxref{GNU Distribution}).
11028
11029 Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
11030 mechanism that allows users to get the best of both worlds: debugging
11031 information can be stripped from the binaries and stored in separate
11032 files. GDB is then able to load debugging information from those files,
11033 when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
11034 with GDB}).
11035
11036 The GNU distribution takes advantage of this by storing debugging
11037 information in the @code{lib/debug} sub-directory of a separate package
11038 output unimaginatively called @code{debug} (@pxref{Packages with
11039 Multiple Outputs}). Users can choose to install the @code{debug} output
11040 of a package when they need it. For instance, the following command
11041 installs the debugging information for the GNU C Library and for GNU
11042 Guile:
11043
11044 @example
11045 guix package -i glibc:debug guile:debug
11046 @end example
11047
11048 GDB must then be told to look for debug files in the user's profile, by
11049 setting the @code{debug-file-directory} variable (consider setting it
11050 from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
11051 GDB}):
11052
11053 @example
11054 (gdb) set debug-file-directory ~/.guix-profile/lib/debug
11055 @end example
11056
11057 From there on, GDB will pick up debugging information from the
11058 @code{.debug} files under @file{~/.guix-profile/lib/debug}.
11059
11060 In addition, you will most likely want GDB to be able to show the source
11061 code being debugged. To do that, you will have to unpack the source
11062 code of the package of interest (obtained with @code{guix build
11063 --source}, @pxref{Invoking guix build}), and to point GDB to that source
11064 directory using the @code{directory} command (@pxref{Source Path,
11065 @code{directory},, gdb, Debugging with GDB}).
11066
11067 @c XXX: keep me up-to-date
11068 The @code{debug} output mechanism in Guix is implemented by the
11069 @code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
11070 opt-in---debugging information is available only for the packages
11071 with definitions explicitly declaring a @code{debug} output. This may be
11072 changed to opt-out in the future if our build farm servers can handle
11073 the load. To check whether a package has a @code{debug} output, use
11074 @command{guix package --list-available} (@pxref{Invoking guix package}).
11075
11076
11077 @node Security Updates
11078 @section Security Updates
11079
11080 @cindex security updates
11081 @cindex security vulnerabilities
11082 Occasionally, important security vulnerabilities are discovered in software
11083 packages and must be patched. Guix developers try hard to keep track of
11084 known vulnerabilities and to apply fixes as soon as possible in the
11085 @code{master} branch of Guix (we do not yet provide a ``stable'' branch
11086 containing only security updates.) The @command{guix lint} tool helps
11087 developers find out about vulnerable versions of software packages in the
11088 distribution:
11089
11090 @smallexample
11091 $ guix lint -c cve
11092 gnu/packages/base.scm:652:2: glibc-2.21: probably vulnerable to CVE-2015-1781, CVE-2015-7547
11093 gnu/packages/gcc.scm:334:2: gcc-4.9.3: probably vulnerable to CVE-2015-5276
11094 gnu/packages/image.scm:312:2: openjpeg-2.1.0: probably vulnerable to CVE-2016-1923, CVE-2016-1924
11095 @dots{}
11096 @end smallexample
11097
11098 @xref{Invoking guix lint}, for more information.
11099
11100 @quotation Note
11101 As of version @value{VERSION}, the feature described below is considered
11102 ``beta''.
11103 @end quotation
11104
11105 Guix follows a functional
11106 package management discipline (@pxref{Introduction}), which implies
11107 that, when a package is changed, @emph{every package that depends on it}
11108 must be rebuilt. This can significantly slow down the deployment of
11109 fixes in core packages such as libc or Bash, since basically the whole
11110 distribution would need to be rebuilt. Using pre-built binaries helps
11111 (@pxref{Substitutes}), but deployment may still take more time than
11112 desired.
11113
11114 @cindex grafts
11115 To address this, Guix implements @dfn{grafts}, a mechanism that allows
11116 for fast deployment of critical updates without the costs associated
11117 with a whole-distribution rebuild. The idea is to rebuild only the
11118 package that needs to be patched, and then to ``graft'' it onto packages
11119 explicitly installed by the user and that were previously referring to
11120 the original package. The cost of grafting is typically very low, and
11121 order of magnitudes lower than a full rebuild of the dependency chain.
11122
11123 @cindex replacements of packages, for grafts
11124 For instance, suppose a security update needs to be applied to Bash.
11125 Guix developers will provide a package definition for the ``fixed''
11126 Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
11127 Packages}). Then, the original package definition is augmented with a
11128 @code{replacement} field pointing to the package containing the bug fix:
11129
11130 @example
11131 (define bash
11132 (package
11133 (name "bash")
11134 ;; @dots{}
11135 (replacement bash-fixed)))
11136 @end example
11137
11138 From there on, any package depending directly or indirectly on Bash---as
11139 reported by @command{guix gc --requisites} (@pxref{Invoking guix
11140 gc})---that is installed is automatically ``rewritten'' to refer to
11141 @var{bash-fixed} instead of @var{bash}. This grafting process takes
11142 time proportional to the size of the package, usually less than a
11143 minute for an ``average'' package on a recent machine. Grafting is
11144 recursive: when an indirect dependency requires grafting, then grafting
11145 ``propagates'' up to the package that the user is installing.
11146
11147 Currently, the graft and the package it replaces (@var{bash-fixed} and
11148 @var{bash} in the example above) must have the exact same @code{name}
11149 and @code{version} fields. This restriction mostly comes from the fact
11150 that grafting works by patching files, including binary files, directly.
11151 Other restrictions may apply: for instance, when adding a graft to a
11152 package providing a shared library, the original shared library and its
11153 replacement must have the same @code{SONAME} and be binary-compatible.
11154
11155 The @option{--no-grafts} command-line option allows you to forcefully
11156 avoid grafting (@pxref{Common Build Options, @option{--no-grafts}}).
11157 Thus, the command:
11158
11159 @example
11160 guix build bash --no-grafts
11161 @end example
11162
11163 @noindent
11164 returns the store file name of the original Bash, whereas:
11165
11166 @example
11167 guix build bash
11168 @end example
11169
11170 @noindent
11171 returns the store file name of the ``fixed'', replacement Bash. This
11172 allows you to distinguish between the two variants of Bash.
11173
11174 To verify which Bash your whole profile refers to, you can run
11175 (@pxref{Invoking guix gc}):
11176
11177 @example
11178 guix gc -R `readlink -f ~/.guix-profile` | grep bash
11179 @end example
11180
11181 @noindent
11182 @dots{} and compare the store file names that you get with those above.
11183 Likewise for a complete GuixSD system generation:
11184
11185 @example
11186 guix gc -R `guix system build my-config.scm` | grep bash
11187 @end example
11188
11189 Lastly, to check which Bash running processes are using, you can use the
11190 @command{lsof} command:
11191
11192 @example
11193 lsof | grep /gnu/store/.*bash
11194 @end example
11195
11196
11197 @node Package Modules
11198 @section Package Modules
11199
11200 From a programming viewpoint, the package definitions of the
11201 GNU distribution are provided by Guile modules in the @code{(gnu packages
11202 @dots{})} name space@footnote{Note that packages under the @code{(gnu
11203 packages @dots{})} module name space are not necessarily ``GNU
11204 packages''. This module naming scheme follows the usual Guile module
11205 naming convention: @code{gnu} means that these modules are distributed
11206 as part of the GNU system, and @code{packages} identifies modules that
11207 define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
11208 Reference Manual}). For instance, the @code{(gnu packages emacs)}
11209 module exports a variable named @code{emacs}, which is bound to a
11210 @code{<package>} object (@pxref{Defining Packages}).
11211
11212 The @code{(gnu packages @dots{})} module name space is
11213 automatically scanned for packages by the command-line tools. For
11214 instance, when running @code{guix package -i emacs}, all the @code{(gnu
11215 packages @dots{})} modules are scanned until one that exports a package
11216 object whose name is @code{emacs} is found. This package search
11217 facility is implemented in the @code{(gnu packages)} module.
11218
11219 @cindex customization, of packages
11220 @cindex package module search path
11221 Users can store package definitions in modules with different
11222 names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
11223 name and module name must match. For instance, the @code{(my-packages
11224 emacs)} module must be stored in a @file{my-packages/emacs.scm} file
11225 relative to the load path specified with @option{--load-path} or
11226 @code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
11227 guile, GNU Guile Reference Manual}, for details.}. These package definitions
11228 will not be visible by default. Users can invoke commands such as
11229 @command{guix package} and @command{guix build} with the
11230 @code{-e} option so that they know where to find the package. Better
11231 yet, they can use the
11232 @code{-L} option of these commands to make those modules visible
11233 (@pxref{Invoking guix build, @code{--load-path}}), or define the
11234 @code{GUIX_PACKAGE_PATH} environment variable. This environment
11235 variable makes it easy to extend or customize the distribution and is
11236 honored by all the user interfaces.
11237
11238 @defvr {Environment Variable} GUIX_PACKAGE_PATH
11239 This is a colon-separated list of directories to search for additional
11240 package modules. Directories listed in this variable take precedence
11241 over the own modules of the distribution.
11242 @end defvr
11243
11244 The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
11245 each package is built based solely on other packages in the
11246 distribution. The root of this dependency graph is a small set of
11247 @dfn{bootstrap binaries}, provided by the @code{(gnu packages
11248 bootstrap)} module. For more information on bootstrapping,
11249 @pxref{Bootstrapping}.
11250
11251 @node Packaging Guidelines
11252 @section Packaging Guidelines
11253
11254 The GNU distribution is nascent and may well lack some of your favorite
11255 packages. This section describes how you can help make the distribution
11256 grow. @xref{Contributing}, for additional information on how you can
11257 help.
11258
11259 Free software packages are usually distributed in the form of
11260 @dfn{source code tarballs}---typically @file{tar.gz} files that contain
11261 all the source files. Adding a package to the distribution means
11262 essentially two things: adding a @dfn{recipe} that describes how to
11263 build the package, including a list of other packages required to build
11264 it, and adding @dfn{package metadata} along with that recipe, such as a
11265 description and licensing information.
11266
11267 In Guix all this information is embodied in @dfn{package definitions}.
11268 Package definitions provide a high-level view of the package. They are
11269 written using the syntax of the Scheme programming language; in fact,
11270 for each package we define a variable bound to the package definition,
11271 and export that variable from a module (@pxref{Package Modules}).
11272 However, in-depth Scheme knowledge is @emph{not} a prerequisite for
11273 creating packages. For more information on package definitions,
11274 @pxref{Defining Packages}.
11275
11276 Once a package definition is in place, stored in a file in the Guix
11277 source tree, it can be tested using the @command{guix build} command
11278 (@pxref{Invoking guix build}). For example, assuming the new package is
11279 called @code{gnew}, you may run this command from the Guix build tree
11280 (@pxref{Running Guix Before It Is Installed}):
11281
11282 @example
11283 ./pre-inst-env guix build gnew --keep-failed
11284 @end example
11285
11286 Using @code{--keep-failed} makes it easier to debug build failures since
11287 it provides access to the failed build tree. Another useful
11288 command-line option when debugging is @code{--log-file}, to access the
11289 build log.
11290
11291 If the package is unknown to the @command{guix} command, it may be that
11292 the source file contains a syntax error, or lacks a @code{define-public}
11293 clause to export the package variable. To figure it out, you may load
11294 the module from Guile to get more information about the actual error:
11295
11296 @example
11297 ./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
11298 @end example
11299
11300 Once your package builds correctly, please send us a patch
11301 (@pxref{Contributing}). Well, if you need help, we will be happy to
11302 help you too. Once the patch is committed in the Guix repository, the
11303 new package automatically gets built on the supported platforms by
11304 @url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
11305 system}.
11306
11307 @cindex substituter
11308 Users can obtain the new package definition simply by running
11309 @command{guix pull} (@pxref{Invoking guix pull}). When
11310 @code{hydra.gnu.org} is done building the package, installing the
11311 package automatically downloads binaries from there
11312 (@pxref{Substitutes}). The only place where human intervention is
11313 needed is to review and apply the patch.
11314
11315
11316 @menu
11317 * Software Freedom:: What may go into the distribution.
11318 * Package Naming:: What's in a name?
11319 * Version Numbers:: When the name is not enough.
11320 * Synopses and Descriptions:: Helping users find the right package.
11321 * Python Modules:: Taming the snake.
11322 * Perl Modules:: Little pearls.
11323 * Java Packages:: Coffee break.
11324 * Fonts:: Fond of fonts.
11325 @end menu
11326
11327 @node Software Freedom
11328 @subsection Software Freedom
11329
11330 @c Adapted from http://www.gnu.org/philosophy/philosophy.html.
11331
11332 The GNU operating system has been developed so that users can have
11333 freedom in their computing. GNU is @dfn{free software}, meaning that
11334 users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
11335 essential freedoms}: to run the program, to study and change the program
11336 in source code form, to redistribute exact copies, and to distribute
11337 modified versions. Packages found in the GNU distribution provide only
11338 software that conveys these four freedoms.
11339
11340 In addition, the GNU distribution follow the
11341 @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
11342 software distribution guidelines}. Among other things, these guidelines
11343 reject non-free firmware, recommendations of non-free software, and
11344 discuss ways to deal with trademarks and patents.
11345
11346 Some otherwise free upstream package sources contain a small and optional
11347 subset that violates the above guidelines, for instance because this subset
11348 is itself non-free code. When that happens, the offending items are removed
11349 with appropriate patches or code snippets in the @code{origin} form of the
11350 package (@pxref{Defining Packages}). This way, @code{guix
11351 build --source} returns the ``freed'' source rather than the unmodified
11352 upstream source.
11353
11354
11355 @node Package Naming
11356 @subsection Package Naming
11357
11358 A package has actually two names associated with it:
11359 First, there is the name of the @emph{Scheme variable}, the one following
11360 @code{define-public}. By this name, the package can be made known in the
11361 Scheme code, for instance as input to another package. Second, there is
11362 the string in the @code{name} field of a package definition. This name
11363 is used by package management commands such as
11364 @command{guix package} and @command{guix build}.
11365
11366 Both are usually the same and correspond to the lowercase conversion of
11367 the project name chosen upstream, with underscores replaced with
11368 hyphens. For instance, GNUnet is available as @code{gnunet}, and
11369 SDL_net as @code{sdl-net}.
11370
11371 We do not add @code{lib} prefixes for library packages, unless these are
11372 already part of the official project name. But @pxref{Python
11373 Modules} and @ref{Perl Modules} for special rules concerning modules for
11374 the Python and Perl languages.
11375
11376 Font package names are handled differently, @pxref{Fonts}.
11377
11378
11379 @node Version Numbers
11380 @subsection Version Numbers
11381
11382 We usually package only the latest version of a given free software
11383 project. But sometimes, for instance for incompatible library versions,
11384 two (or more) versions of the same package are needed. These require
11385 different Scheme variable names. We use the name as defined
11386 in @ref{Package Naming}
11387 for the most recent version; previous versions use the same name, suffixed
11388 by @code{-} and the smallest prefix of the version number that may
11389 distinguish the two versions.
11390
11391 The name inside the package definition is the same for all versions of a
11392 package and does not contain any version number.
11393
11394 For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
11395
11396 @example
11397 (define-public gtk+
11398 (package
11399 (name "gtk+")
11400 (version "3.9.12")
11401 ...))
11402 (define-public gtk+-2
11403 (package
11404 (name "gtk+")
11405 (version "2.24.20")
11406 ...))
11407 @end example
11408 If we also wanted GTK+ 3.8.2, this would be packaged as
11409 @example
11410 (define-public gtk+-3.8
11411 (package
11412 (name "gtk+")
11413 (version "3.8.2")
11414 ...))
11415 @end example
11416
11417 @c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
11418 @c for a discussion of what follows.
11419 @cindex version number, for VCS snapshots
11420 Occasionally, we package snapshots of upstream's version control system
11421 (VCS) instead of formal releases. This should remain exceptional,
11422 because it is up to upstream developers to clarify what the stable
11423 release is. Yet, it is sometimes necessary. So, what should we put in
11424 the @code{version} field?
11425
11426 Clearly, we need to make the commit identifier of the VCS snapshot
11427 visible in the version string, but we also need to make sure that the
11428 version string is monotonically increasing so that @command{guix package
11429 --upgrade} can determine which version is newer. Since commit
11430 identifiers, notably with Git, are not monotonically increasing, we add
11431 a revision number that we increase each time we upgrade to a newer
11432 snapshot. The resulting version string looks like this:
11433
11434 @example
11435 2.0.11-3.cabba9e
11436 ^ ^ ^
11437 | | `-- upstream commit ID
11438 | |
11439 | `--- Guix package revision
11440 |
11441 latest upstream version
11442 @end example
11443
11444 It is a good idea to strip commit identifiers in the @code{version}
11445 field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
11446 aesthetics have a role to play here) as well as problems related to OS
11447 limits such as the maximum shebang length (127 bytes for the Linux
11448 kernel.) It is best to use the full commit identifiers in
11449 @code{origin}s, though, to avoid ambiguities. A typical package
11450 definition may look like this:
11451
11452 @example
11453 (define my-package
11454 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7"))
11455 (package
11456 (version (string-append "0.9-1."
11457 (string-take commit 7)))
11458 (source (origin
11459 (method git-fetch)
11460 (uri (git-reference
11461 (url "git://example.org/my-package.git")
11462 (commit commit)))
11463 (sha256 (base32 "1mbikn@dots{}"))
11464 (file-name (string-append "my-package-" version
11465 "-checkout"))))
11466 ;; @dots{}
11467 )))
11468 @end example
11469
11470 @node Synopses and Descriptions
11471 @subsection Synopses and Descriptions
11472
11473 As we have seen before, each package in GNU@tie{}Guix includes a
11474 synopsis and a description (@pxref{Defining Packages}). Synopses and
11475 descriptions are important: They are what @command{guix package
11476 --search} searches, and a crucial piece of information to help users
11477 determine whether a given package suits their needs. Consequently,
11478 packagers should pay attention to what goes into them.
11479
11480 Synopses must start with a capital letter and must not end with a
11481 period. They must not start with ``a'' or ``the'', which usually does
11482 not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
11483 tool that frobs files''. The synopsis should say what the package
11484 is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
11485 used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
11486 matching a pattern''.
11487
11488 Keep in mind that the synopsis must be meaningful for a very wide
11489 audience. For example, ``Manipulate alignments in the SAM format''
11490 might make sense for a seasoned bioinformatics researcher, but might be
11491 fairly unhelpful or even misleading to a non-specialized audience. It
11492 is a good idea to come up with a synopsis that gives an idea of the
11493 application domain of the package. In this example, this might give
11494 something like ``Manipulate nucleotide sequence alignments'', which
11495 hopefully gives the user a better idea of whether this is what they are
11496 looking for.
11497
11498 Descriptions should take between five and ten lines. Use full
11499 sentences, and avoid using acronyms without first introducing them.
11500 Please avoid marketing phrases such as ``world-leading'',
11501 ``industrial-strength'', and ``next-generation'', and avoid superlatives
11502 like ``the most advanced''---they are not helpful to users looking for a
11503 package and may even sound suspicious. Instead, try to be factual,
11504 mentioning use cases and features.
11505
11506 @cindex Texinfo markup, in package descriptions
11507 Descriptions can include Texinfo markup, which is useful to introduce
11508 ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
11509 hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
11510 should be careful when using some characters for example @samp{@@} and
11511 curly braces which are the basic special characters in Texinfo
11512 (@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
11513 such as @command{guix package --show} take care of rendering it
11514 appropriately.
11515
11516 Synopses and descriptions are translated by volunteers
11517 @uref{http://translationproject.org/domain/guix-packages.html, at the
11518 Translation Project} so that as many users as possible can read them in
11519 their native language. User interfaces search them and display them in
11520 the language specified by the current locale.
11521
11522 Translation is a lot of work so, as a packager, please pay even more
11523 attention to your synopses and descriptions as every change may entail
11524 additional work for translators. In order to help them, it is possible
11525 to make recommendations or instructions visible to them by inserting
11526 special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
11527 Gettext}):
11528
11529 @example
11530 ;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
11531 (description "ARandR is designed to provide a simple visual front end
11532 for the X11 resize-and-rotate (RandR) extension. @dots{}")
11533 @end example
11534
11535
11536 @node Python Modules
11537 @subsection Python Modules
11538
11539 We currently package Python 2 and Python 3, under the Scheme variable names
11540 @code{python-2} and @code{python} as explained in @ref{Version Numbers}.
11541 To avoid confusion and naming clashes with other programming languages, it
11542 seems desirable that the name of a package for a Python module contains
11543 the word @code{python}.
11544
11545 Some modules are compatible with only one version of Python, others with both.
11546 If the package Foo compiles only with Python 3, we name it
11547 @code{python-foo}; if it compiles only with Python 2, we name it
11548 @code{python2-foo}. If it is compatible with both versions, we create two
11549 packages with the corresponding names.
11550
11551 If a project already contains the word @code{python}, we drop this;
11552 for instance, the module python-dateutil is packaged under the names
11553 @code{python-dateutil} and @code{python2-dateutil}. If the project name
11554 starts with @code{py} (e.g. @code{pytz}), we keep it and prefix it as
11555 described above.
11556
11557
11558 @node Perl Modules
11559 @subsection Perl Modules
11560
11561 Perl programs standing for themselves are named as any other package,
11562 using the lowercase upstream name.
11563 For Perl packages containing a single class, we use the lowercase class name,
11564 replace all occurrences of @code{::} by dashes and prepend the prefix
11565 @code{perl-}.
11566 So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
11567 Modules containing several classes keep their lowercase upstream name and
11568 are also prepended by @code{perl-}. Such modules tend to have the word
11569 @code{perl} somewhere in their name, which gets dropped in favor of the
11570 prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
11571
11572
11573 @node Java Packages
11574 @subsection Java Packages
11575
11576 Java programs standing for themselves are named as any other package,
11577 using the lowercase upstream name.
11578
11579 To avoid confusion and naming clashes with other programming languages,
11580 it is desirable that the name of a package for a Java package is
11581 prefixed with @code{java-}. If a project already contains the word
11582 @code{java}, we drop this; for instance, the package @code{ngsjava} is
11583 packaged under the name @code{java-ngs}.
11584
11585 For Java packages containing a single class or a small class hierarchy,
11586 we use the lowercase class name, replace all occurrences of @code{.} by
11587 dashes and prepend the prefix @code{java-}. So the class
11588 @code{apache.commons.cli} becomes package
11589 @code{java-apache-commons-cli}.
11590
11591
11592 @node Fonts
11593 @subsection Fonts
11594
11595 For fonts that are in general not installed by a user for typesetting
11596 purposes, or that are distributed as part of a larger software package,
11597 we rely on the general packaging rules for software; for instance, this
11598 applies to the fonts delivered as part of the X.Org system or fonts that
11599 are part of TeX Live.
11600
11601 To make it easier for a user to search for fonts, names for other packages
11602 containing only fonts are constructed as follows, independently of the
11603 upstream package name.
11604
11605 The name of a package containing only one font family starts with
11606 @code{font-}; it is followed by the foundry name and a dash @code{-}
11607 if the foundry is known, and the font family name, in which spaces are
11608 replaced by dashes (and as usual, all upper case letters are transformed
11609 to lower case).
11610 For example, the Gentium font family by SIL is packaged under the name
11611 @code{font-sil-gentium}.
11612
11613 For a package containing several font families, the name of the collection
11614 is used in the place of the font family name.
11615 For instance, the Liberation fonts consist of three families,
11616 Liberation Sans, Liberation Serif and Liberation Mono.
11617 These could be packaged separately under the names
11618 @code{font-liberation-sans} and so on; but as they are distributed together
11619 under a common name, we prefer to package them together as
11620 @code{font-liberation}.
11621
11622 In the case where several formats of the same font family or font collection
11623 are packaged separately, a short form of the format, prepended by a dash,
11624 is added to the package name. We use @code{-ttf} for TrueType fonts,
11625 @code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
11626 fonts.
11627
11628
11629
11630 @node Bootstrapping
11631 @section Bootstrapping
11632
11633 @c Adapted from the ELS 2013 paper.
11634
11635 @cindex bootstrapping
11636
11637 Bootstrapping in our context refers to how the distribution gets built
11638 ``from nothing''. Remember that the build environment of a derivation
11639 contains nothing but its declared inputs (@pxref{Introduction}). So
11640 there's an obvious chicken-and-egg problem: how does the first package
11641 get built? How does the first compiler get compiled? Note that this is
11642 a question of interest only to the curious hacker, not to the regular
11643 user, so you can shamelessly skip this section if you consider yourself
11644 a ``regular user''.
11645
11646 @cindex bootstrap binaries
11647 The GNU system is primarily made of C code, with libc at its core. The
11648 GNU build system itself assumes the availability of a Bourne shell and
11649 command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
11650 `grep'. Furthermore, build programs---programs that run
11651 @code{./configure}, @code{make}, etc.---are written in Guile Scheme
11652 (@pxref{Derivations}). Consequently, to be able to build anything at
11653 all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
11654 Binutils, libc, and the other packages mentioned above---the
11655 @dfn{bootstrap binaries}.
11656
11657 These bootstrap binaries are ``taken for granted'', though we can also
11658 re-create them if needed (more on that later).
11659
11660 @unnumberedsubsec Preparing to Use the Bootstrap Binaries
11661
11662 @c As of Emacs 24.3, Info-mode displays the image, but since it's a
11663 @c large image, it's hard to scroll. Oh well.
11664 @image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
11665
11666 The figure above shows the very beginning of the dependency graph of the
11667 distribution, corresponding to the package definitions of the @code{(gnu
11668 packages bootstrap)} module. A similar figure can be generated with
11669 @command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
11670
11671 @example
11672 guix graph -t derivation \
11673 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
11674 | dot -Tps > t.ps
11675 @end example
11676
11677 At this level of detail, things are
11678 slightly complex. First, Guile itself consists of an ELF executable,
11679 along with many source and compiled Scheme files that are dynamically
11680 loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
11681 tarball shown in this graph. This tarball is part of Guix's ``source''
11682 distribution, and gets inserted into the store with @code{add-to-store}
11683 (@pxref{The Store}).
11684
11685 But how do we write a derivation that unpacks this tarball and adds it
11686 to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
11687 derivation---the first one that gets built---uses @code{bash} as its
11688 builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
11689 @code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
11690 @file{xz}, and @file{mkdir} are statically-linked binaries, also part of
11691 the Guix source distribution, whose sole purpose is to allow the Guile
11692 tarball to be unpacked.
11693
11694 Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
11695 Guile that can be used to run subsequent build programs. Its first task
11696 is to download tarballs containing the other pre-built binaries---this
11697 is what the @code{.tar.xz.drv} derivations do. Guix modules such as
11698 @code{ftp-client.scm} are used for this purpose. The
11699 @code{module-import.drv} derivations import those modules in a directory
11700 in the store, using the original layout. The
11701 @code{module-import-compiled.drv} derivations compile those modules, and
11702 write them in an output directory with the right layout. This
11703 corresponds to the @code{#:modules} argument of
11704 @code{build-expression->derivation} (@pxref{Derivations}).
11705
11706 Finally, the various tarballs are unpacked by the
11707 derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
11708 etc., at which point we have a working C tool chain.
11709
11710
11711 @unnumberedsubsec Building the Build Tools
11712
11713 Bootstrapping is complete when we have a full tool chain that does not
11714 depend on the pre-built bootstrap tools discussed above. This
11715 no-dependency requirement is verified by checking whether the files of
11716 the final tool chain contain references to the @file{/gnu/store}
11717 directories of the bootstrap inputs. The process that leads to this
11718 ``final'' tool chain is described by the package definitions found in
11719 the @code{(gnu packages commencement)} module.
11720
11721 The @command{guix graph} command allows us to ``zoom out'' compared to
11722 the graph above, by looking at the level of package objects instead of
11723 individual derivations---remember that a package may translate to
11724 several derivations, typically one derivation to download its source,
11725 one to build the Guile modules it needs, and one to actually build the
11726 package from source. The command:
11727
11728 @example
11729 guix graph -t bag \
11730 -e '(@@@@ (gnu packages commencement)
11731 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
11732 @end example
11733
11734 @noindent
11735 produces the dependency graph leading to the ``final'' C
11736 library@footnote{You may notice the @code{glibc-intermediate} label,
11737 suggesting that it is not @emph{quite} final, but as a good
11738 approximation, we will consider it final.}, depicted below.
11739
11740 @image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
11741
11742 @c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
11743 The first tool that gets built with the bootstrap binaries is
11744 GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
11745 for all the following packages. From there Findutils and Diffutils get
11746 built.
11747
11748 Then come the first-stage Binutils and GCC, built as pseudo cross
11749 tools---i.e., with @code{--target} equal to @code{--host}. They are
11750 used to build libc. Thanks to this cross-build trick, this libc is
11751 guaranteed not to hold any reference to the initial tool chain.
11752
11753 From there the final Binutils and GCC (not shown above) are built.
11754 GCC uses @code{ld}
11755 from the final Binutils, and links programs against the just-built libc.
11756 This tool chain is used to build the other packages used by Guix and by
11757 the GNU Build System: Guile, Bash, Coreutils, etc.
11758
11759 And voilà! At this point we have the complete set of build tools that
11760 the GNU Build System expects. These are in the @code{%final-inputs}
11761 variable of the @code{(gnu packages commencement)} module, and are
11762 implicitly used by any package that uses @code{gnu-build-system}
11763 (@pxref{Build Systems, @code{gnu-build-system}}).
11764
11765
11766 @unnumberedsubsec Building the Bootstrap Binaries
11767
11768 Because the final tool chain does not depend on the bootstrap binaries,
11769 those rarely need to be updated. Nevertheless, it is useful to have an
11770 automated way to produce them, should an update occur, and this is what
11771 the @code{(gnu packages make-bootstrap)} module provides.
11772
11773 The following command builds the tarballs containing the bootstrap
11774 binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
11775 of Coreutils and other basic command-line tools):
11776
11777 @example
11778 guix build bootstrap-tarballs
11779 @end example
11780
11781 The generated tarballs are those that should be referred to in the
11782 @code{(gnu packages bootstrap)} module mentioned at the beginning of
11783 this section.
11784
11785 Still here? Then perhaps by now you've started to wonder: when do we
11786 reach a fixed point? That is an interesting question! The answer is
11787 unknown, but if you would like to investigate further (and have
11788 significant computational and storage resources to do so), then let us
11789 know.
11790
11791 @node Porting
11792 @section Porting to a New Platform
11793
11794 As discussed above, the GNU distribution is self-contained, and
11795 self-containment is achieved by relying on pre-built ``bootstrap
11796 binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
11797 operating system kernel, CPU architecture, and application binary
11798 interface (ABI). Thus, to port the distribution to a platform that is
11799 not yet supported, one must build those bootstrap binaries, and update
11800 the @code{(gnu packages bootstrap)} module to use them on that platform.
11801
11802 Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
11803 When everything goes well, and assuming the GNU tool chain supports the
11804 target platform, this can be as simple as running a command like this
11805 one:
11806
11807 @example
11808 guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
11809 @end example
11810
11811 For this to work, the @code{glibc-dynamic-linker} procedure in
11812 @code{(gnu packages bootstrap)} must be augmented to return the right
11813 file name for libc's dynamic linker on that platform; likewise,
11814 @code{system->linux-architecture} in @code{(gnu packages linux)} must be
11815 taught about the new platform.
11816
11817 Once these are built, the @code{(gnu packages bootstrap)} module needs
11818 to be updated to refer to these binaries on the target platform. That
11819 is, the hashes and URLs of the bootstrap tarballs for the new platform
11820 must be added alongside those of the currently supported platforms. The
11821 bootstrap Guile tarball is treated specially: it is expected to be
11822 available locally, and @file{gnu/local.mk} has rules do download it for
11823 the supported architectures; a rule for the new platform must be added
11824 as well.
11825
11826 In practice, there may be some complications. First, it may be that the
11827 extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
11828 above) is not recognized by all the GNU tools. Typically, glibc
11829 recognizes some of these, whereas GCC uses an extra @code{--with-abi}
11830 configure flag (see @code{gcc.scm} for examples of how to handle this).
11831 Second, some of the required packages could fail to build for that
11832 platform. Lastly, the generated binaries could be broken for some
11833 reason.
11834
11835 @c *********************************************************************
11836 @include contributing.texi
11837
11838 @c *********************************************************************
11839 @node Acknowledgments
11840 @chapter Acknowledgments
11841
11842 Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
11843 which was designed and
11844 implemented by Eelco Dolstra, with contributions from other people (see
11845 the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
11846 management, and promoted unprecedented features, such as transactional
11847 package upgrades and rollbacks, per-user profiles, and referentially
11848 transparent build processes. Without this work, Guix would not exist.
11849
11850 The Nix-based software distributions, Nixpkgs and NixOS, have also been
11851 an inspiration for Guix.
11852
11853 GNU@tie{}Guix itself is a collective work with contributions from a
11854 number of people. See the @file{AUTHORS} file in Guix for more
11855 information on these fine people. The @file{THANKS} file lists people
11856 who have helped by reporting bugs, taking care of the infrastructure,
11857 providing artwork and themes, making suggestions, and more---thank you!
11858
11859
11860 @c *********************************************************************
11861 @node GNU Free Documentation License
11862 @appendix GNU Free Documentation License
11863
11864 @include fdl-1.3.texi
11865
11866 @c *********************************************************************
11867 @node Concept Index
11868 @unnumbered Concept Index
11869 @printindex cp
11870
11871 @node Programming Index
11872 @unnumbered Programming Index
11873 @syncodeindex tp fn
11874 @syncodeindex vr fn
11875 @printindex fn
11876
11877 @bye
11878
11879 @c Local Variables:
11880 @c ispell-local-dictionary: "american";
11881 @c End: